Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.78
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.78! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.77 2014/06/18 06:15:58 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1075.2.25 raeburn 70: use Apache::lonuserutils();
1.1075.2.27 raeburn 71: use Apache::lonuserstate();
1.1075.2.69 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 74: use DateTime::TimeZone;
1.687 raeburn 75: use DateTime::Locale::Catalog;
1.1075.2.14 raeburn 76: use Authen::Captcha;
77: use Captcha::reCAPTCHA;
1.1075.2.64 raeburn 78: use Crypt::DES;
79: use DynaLoader; # for Crypt::DES version
1.117 www 80:
1.517 raeburn 81: # ---------------------------------------------- Designs
82: use vars qw(%defaultdesign);
83:
1.22 www 84: my $readit;
85:
1.517 raeburn 86:
1.157 matthew 87: ##
88: ## Global Variables
89: ##
1.46 matthew 90:
1.643 foxr 91:
92: # ----------------------------------------------- SSI with retries:
93: #
94:
95: =pod
96:
1.648 raeburn 97: =head1 Server Side include with retries:
1.643 foxr 98:
99: =over 4
100:
1.648 raeburn 101: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 102:
103: Performs an ssi with some number of retries. Retries continue either
104: until the result is ok or until the retry count supplied by the
105: caller is exhausted.
106:
107: Inputs:
1.648 raeburn 108:
109: =over 4
110:
1.643 foxr 111: resource - Identifies the resource to insert.
1.648 raeburn 112:
1.643 foxr 113: retries - Count of the number of retries allowed.
1.648 raeburn 114:
1.643 foxr 115: form - Hash that identifies the rendering options.
116:
1.648 raeburn 117: =back
118:
119: Returns:
120:
121: =over 4
122:
1.643 foxr 123: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 124:
1.643 foxr 125: response - The response from the last attempt (which may or may not have been successful.
126:
1.648 raeburn 127: =back
128:
129: =back
130:
1.643 foxr 131: =cut
132:
133: sub ssi_with_retries {
134: my ($resource, $retries, %form) = @_;
135:
136:
137: my $ok = 0; # True if we got a good response.
138: my $content;
139: my $response;
140:
141: # Try to get the ssi done. within the retries count:
142:
143: do {
144: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
145: $ok = $response->is_success;
1.650 www 146: if (!$ok) {
147: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
148: }
1.643 foxr 149: $retries--;
150: } while (!$ok && ($retries > 0));
151:
152: if (!$ok) {
153: $content = ''; # On error return an empty content.
154: }
155: return ($content, $response);
156:
157: }
158:
159:
160:
1.20 www 161: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 162: my %language;
1.124 www 163: my %supported_language;
1.1048 foxr 164: my %latex_language; # For choosing hyphenation in <transl..>
165: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 166: my %cprtag;
1.192 taceyjo1 167: my %scprtag;
1.351 www 168: my %fe; my %fd; my %fm;
1.41 ng 169: my %category_extensions;
1.12 harris41 170:
1.46 matthew 171: # ---------------------------------------------- Thesaurus variables
1.144 matthew 172: #
173: # %Keywords:
174: # A hash used by &keyword to determine if a word is considered a keyword.
175: # $thesaurus_db_file
176: # Scalar containing the full path to the thesaurus database.
1.46 matthew 177:
178: my %Keywords;
179: my $thesaurus_db_file;
180:
1.144 matthew 181: #
182: # Initialize values from language.tab, copyright.tab, filetypes.tab,
183: # thesaurus.tab, and filecategories.tab.
184: #
1.18 www 185: BEGIN {
1.46 matthew 186: # Variable initialization
187: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
188: #
1.22 www 189: unless ($readit) {
1.12 harris41 190: # ------------------------------------------------------------------- languages
191: {
1.158 raeburn 192: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
193: '/language.tab';
194: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 195: while (my $line = <$fh>) {
196: next if ($line=~/^\#/);
197: chomp($line);
1.1048 foxr 198: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 199: $language{$key}=$val.' - '.$enc;
200: if ($sup) {
201: $supported_language{$key}=$sup;
202: }
1.1048 foxr 203: if ($latex) {
204: $latex_language_bykey{$key} = $latex;
205: $latex_language{$two} = $latex;
206: }
1.158 raeburn 207: }
208: close($fh);
209: }
1.12 harris41 210: }
211: # ------------------------------------------------------------------ copyrights
212: {
1.158 raeburn 213: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
214: '/copyright.tab';
215: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 216: while (my $line = <$fh>) {
217: next if ($line=~/^\#/);
218: chomp($line);
219: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 220: $cprtag{$key}=$val;
221: }
222: close($fh);
223: }
1.12 harris41 224: }
1.351 www 225: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 226: {
227: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
228: '/source_copyright.tab';
229: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 230: while (my $line = <$fh>) {
231: next if ($line =~ /^\#/);
232: chomp($line);
233: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 234: $scprtag{$key}=$val;
235: }
236: close($fh);
237: }
238: }
1.63 www 239:
1.517 raeburn 240: # -------------------------------------------------------------- default domain designs
1.63 www 241: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 242: my $designfile = $designdir.'/default.tab';
243: if ( open (my $fh,"<$designfile") ) {
244: while (my $line = <$fh>) {
245: next if ($line =~ /^\#/);
246: chomp($line);
247: my ($key,$val)=(split(/\=/,$line));
248: if ($val) { $defaultdesign{$key}=$val; }
249: }
250: close($fh);
1.63 www 251: }
252:
1.15 harris41 253: # ------------------------------------------------------------- file categories
254: {
1.158 raeburn 255: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
256: '/filecategories.tab';
257: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 258: while (my $line = <$fh>) {
259: next if ($line =~ /^\#/);
260: chomp($line);
261: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 262: push @{$category_extensions{lc($category)}},$extension;
263: }
264: close($fh);
265: }
266:
1.15 harris41 267: }
1.12 harris41 268: # ------------------------------------------------------------------ file types
269: {
1.158 raeburn 270: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
271: '/filetypes.tab';
272: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 273: while (my $line = <$fh>) {
274: next if ($line =~ /^\#/);
275: chomp($line);
276: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 277: if ($descr ne '') {
278: $fe{$ending}=lc($emb);
279: $fd{$ending}=$descr;
1.351 www 280: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 281: }
282: }
283: close($fh);
284: }
1.12 harris41 285: }
1.22 www 286: &Apache::lonnet::logthis(
1.705 tempelho 287: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 288: $readit=1;
1.46 matthew 289: } # end of unless($readit)
1.32 matthew 290:
291: }
1.112 bowersj2 292:
1.42 matthew 293: ###############################################################
294: ## HTML and Javascript Helper Functions ##
295: ###############################################################
296:
297: =pod
298:
1.112 bowersj2 299: =head1 HTML and Javascript Functions
1.42 matthew 300:
1.112 bowersj2 301: =over 4
302:
1.648 raeburn 303: =item * &browser_and_searcher_javascript()
1.112 bowersj2 304:
305: X<browsing, javascript>X<searching, javascript>Returns a string
306: containing javascript with two functions, C<openbrowser> and
307: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
308: tags.
1.42 matthew 309:
1.648 raeburn 310: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 311:
312: inputs: formname, elementname, only, omit
313:
314: formname and elementname indicate the name of the html form and name of
315: the element that the results of the browsing selection are to be placed in.
316:
317: Specifying 'only' will restrict the browser to displaying only files
1.185 www 318: with the given extension. Can be a comma separated list.
1.42 matthew 319:
320: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 321: with the given extension. Can be a comma separated list.
1.42 matthew 322:
1.648 raeburn 323: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 324:
325: Inputs: formname, elementname
326:
327: formname and elementname specify the name of the html form and the name
328: of the element the selection from the search results will be placed in.
1.542 raeburn 329:
1.42 matthew 330: =cut
331:
332: sub browser_and_searcher_javascript {
1.199 albertel 333: my ($mode)=@_;
334: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 335: my $resurl=&escape_single(&lastresurl());
1.42 matthew 336: return <<END;
1.219 albertel 337: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 338: var editbrowser = null;
1.135 albertel 339: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 340: var url = '$resurl/?';
1.42 matthew 341: if (editbrowser == null) {
342: url += 'launch=1&';
343: }
344: url += 'catalogmode=interactive&';
1.199 albertel 345: url += 'mode=$mode&';
1.611 albertel 346: url += 'inhibitmenu=yes&';
1.42 matthew 347: url += 'form=' + formname + '&';
348: if (only != null) {
349: url += 'only=' + only + '&';
1.217 albertel 350: } else {
351: url += 'only=&';
352: }
1.42 matthew 353: if (omit != null) {
354: url += 'omit=' + omit + '&';
1.217 albertel 355: } else {
356: url += 'omit=&';
357: }
1.135 albertel 358: if (titleelement != null) {
359: url += 'titleelement=' + titleelement + '&';
1.217 albertel 360: } else {
361: url += 'titleelement=&';
362: }
1.42 matthew 363: url += 'element=' + elementname + '';
364: var title = 'Browser';
1.435 albertel 365: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 366: options += ',width=700,height=600';
367: editbrowser = open(url,title,options,'1');
368: editbrowser.focus();
369: }
370: var editsearcher;
1.135 albertel 371: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 372: var url = '/adm/searchcat?';
373: if (editsearcher == null) {
374: url += 'launch=1&';
375: }
376: url += 'catalogmode=interactive&';
1.199 albertel 377: url += 'mode=$mode&';
1.42 matthew 378: url += 'form=' + formname + '&';
1.135 albertel 379: if (titleelement != null) {
380: url += 'titleelement=' + titleelement + '&';
1.217 albertel 381: } else {
382: url += 'titleelement=&';
383: }
1.42 matthew 384: url += 'element=' + elementname + '';
385: var title = 'Search';
1.435 albertel 386: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 387: options += ',width=700,height=600';
388: editsearcher = open(url,title,options,'1');
389: editsearcher.focus();
390: }
1.219 albertel 391: // END LON-CAPA Internal -->
1.42 matthew 392: END
1.170 www 393: }
394:
395: sub lastresurl {
1.258 albertel 396: if ($env{'environment.lastresurl'}) {
397: return $env{'environment.lastresurl'}
1.170 www 398: } else {
399: return '/res';
400: }
401: }
402:
403: sub storeresurl {
404: my $resurl=&Apache::lonnet::clutter(shift);
405: unless ($resurl=~/^\/res/) { return 0; }
406: $resurl=~s/\/$//;
407: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 408: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 409: return 1;
1.42 matthew 410: }
411:
1.74 www 412: sub studentbrowser_javascript {
1.111 www 413: unless (
1.258 albertel 414: (($env{'request.course.id'}) &&
1.302 albertel 415: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
416: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
417: '/'.$env{'request.course.sec'})
418: ))
1.258 albertel 419: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 420: ) { return ''; }
1.74 www 421: return (<<'ENDSTDBRW');
1.776 bisitz 422: <script type="text/javascript" language="Javascript">
1.824 bisitz 423: // <![CDATA[
1.74 www 424: var stdeditbrowser;
1.999 www 425: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 426: var url = '/adm/pickstudent?';
427: var filter;
1.558 albertel 428: if (!ignorefilter) {
429: eval('filter=document.'+formname+'.'+uname+'.value;');
430: }
1.74 www 431: if (filter != null) {
432: if (filter != '') {
433: url += 'filter='+filter+'&';
434: }
435: }
436: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 437: '&udomelement='+udom+
438: '&clicker='+clicker;
1.111 www 439: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 440: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 441: var title = 'Student_Browser';
1.74 www 442: var options = 'scrollbars=1,resizable=1,menubar=0';
443: options += ',width=700,height=600';
444: stdeditbrowser = open(url,title,options,'1');
445: stdeditbrowser.focus();
446: }
1.824 bisitz 447: // ]]>
1.74 www 448: </script>
449: ENDSTDBRW
450: }
1.42 matthew 451:
1.1003 www 452: sub resourcebrowser_javascript {
453: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 454: return (<<'ENDRESBRW');
1.1003 www 455: <script type="text/javascript" language="Javascript">
456: // <![CDATA[
457: var reseditbrowser;
1.1004 www 458: function openresbrowser(formname,reslink) {
1.1005 www 459: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 460: var title = 'Resource_Browser';
461: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 462: options += ',width=700,height=500';
1.1004 www 463: reseditbrowser = open(url,title,options,'1');
464: reseditbrowser.focus();
1.1003 www 465: }
466: // ]]>
467: </script>
1.1004 www 468: ENDRESBRW
1.1003 www 469: }
470:
1.74 www 471: sub selectstudent_link {
1.999 www 472: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
473: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
474: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
475: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 476: if ($env{'request.course.id'}) {
1.302 albertel 477: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
478: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
479: '/'.$env{'request.course.sec'})) {
1.111 www 480: return '';
481: }
1.999 www 482: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 483: if ($courseadvonly) {
484: $callargs .= ",'',1,1";
485: }
486: return '<span class="LC_nobreak">'.
487: '<a href="javascript:openstdbrowser('.$callargs.');">'.
488: &mt('Select User').'</a></span>';
1.74 www 489: }
1.258 albertel 490: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 491: $callargs .= ",'',1";
1.793 raeburn 492: return '<span class="LC_nobreak">'.
493: '<a href="javascript:openstdbrowser('.$callargs.');">'.
494: &mt('Select User').'</a></span>';
1.111 www 495: }
496: return '';
1.91 www 497: }
498:
1.1004 www 499: sub selectresource_link {
500: my ($form,$reslink,$arg)=@_;
501:
502: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
503: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
504: unless ($env{'request.course.id'}) { return $arg; }
505: return '<span class="LC_nobreak">'.
506: '<a href="javascript:openresbrowser('.$callargs.');">'.
507: $arg.'</a></span>';
508: }
509:
510:
511:
1.653 raeburn 512: sub authorbrowser_javascript {
513: return <<"ENDAUTHORBRW";
1.776 bisitz 514: <script type="text/javascript" language="JavaScript">
1.824 bisitz 515: // <![CDATA[
1.653 raeburn 516: var stdeditbrowser;
517:
518: function openauthorbrowser(formname,udom) {
519: var url = '/adm/pickauthor?';
520: url += 'form='+formname+'&roledom='+udom;
521: var title = 'Author_Browser';
522: var options = 'scrollbars=1,resizable=1,menubar=0';
523: options += ',width=700,height=600';
524: stdeditbrowser = open(url,title,options,'1');
525: stdeditbrowser.focus();
526: }
527:
1.824 bisitz 528: // ]]>
1.653 raeburn 529: </script>
530: ENDAUTHORBRW
531: }
532:
1.91 www 533: sub coursebrowser_javascript {
1.1075.2.31 raeburn 534: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
535: $credits_element) = @_;
1.932 raeburn 536: my $wintitle = 'Course_Browser';
1.931 raeburn 537: if ($crstype eq 'Community') {
1.932 raeburn 538: $wintitle = 'Community_Browser';
1.909 raeburn 539: }
1.876 raeburn 540: my $id_functions = &javascript_index_functions();
541: my $output = '
1.776 bisitz 542: <script type="text/javascript" language="JavaScript">
1.824 bisitz 543: // <![CDATA[
1.468 raeburn 544: var stdeditbrowser;'."\n";
1.876 raeburn 545:
546: $output .= <<"ENDSTDBRW";
1.909 raeburn 547: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 548: var url = '/adm/pickcourse?';
1.895 raeburn 549: var formid = getFormIdByName(formname);
1.876 raeburn 550: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 551: if (domainfilter != null) {
552: if (domainfilter != '') {
553: url += 'domainfilter='+domainfilter+'&';
554: }
555: }
1.91 www 556: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 557: '&cdomelement='+udom+
558: '&cnameelement='+desc;
1.468 raeburn 559: if (extra_element !=null && extra_element != '') {
1.594 raeburn 560: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 561: url += '&roleelement='+extra_element;
562: if (domainfilter == null || domainfilter == '') {
563: url += '&domainfilter='+extra_element;
564: }
1.234 raeburn 565: }
1.468 raeburn 566: else {
567: if (formname == 'portform') {
568: url += '&setroles='+extra_element;
1.800 raeburn 569: } else {
570: if (formname == 'rules') {
571: url += '&fixeddom='+extra_element;
572: }
1.468 raeburn 573: }
574: }
1.230 raeburn 575: }
1.909 raeburn 576: if (type != null && type != '') {
577: url += '&type='+type;
578: }
579: if (type_elem != null && type_elem != '') {
580: url += '&typeelement='+type_elem;
581: }
1.872 raeburn 582: if (formname == 'ccrs') {
583: var ownername = document.forms[formid].ccuname.value;
584: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
585: url += '&cloner='+ownername+':'+ownerdom;
586: }
1.293 raeburn 587: if (multflag !=null && multflag != '') {
588: url += '&multiple='+multflag;
589: }
1.909 raeburn 590: var title = '$wintitle';
1.91 www 591: var options = 'scrollbars=1,resizable=1,menubar=0';
592: options += ',width=700,height=600';
593: stdeditbrowser = open(url,title,options,'1');
594: stdeditbrowser.focus();
595: }
1.876 raeburn 596: $id_functions
597: ENDSTDBRW
1.1075.2.31 raeburn 598: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
599: $output .= &setsec_javascript($sec_element,$formname,$role_element,
600: $credits_element);
1.876 raeburn 601: }
602: $output .= '
603: // ]]>
604: </script>';
605: return $output;
606: }
607:
608: sub javascript_index_functions {
609: return <<"ENDJS";
610:
611: function getFormIdByName(formname) {
612: for (var i=0;i<document.forms.length;i++) {
613: if (document.forms[i].name == formname) {
614: return i;
615: }
616: }
617: return -1;
618: }
619:
620: function getIndexByName(formid,item) {
621: for (var i=0;i<document.forms[formid].elements.length;i++) {
622: if (document.forms[formid].elements[i].name == item) {
623: return i;
624: }
625: }
626: return -1;
627: }
1.468 raeburn 628:
1.876 raeburn 629: function getDomainFromSelectbox(formname,udom) {
630: var userdom;
631: var formid = getFormIdByName(formname);
632: if (formid > -1) {
633: var domid = getIndexByName(formid,udom);
634: if (domid > -1) {
635: if (document.forms[formid].elements[domid].type == 'select-one') {
636: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
637: }
638: if (document.forms[formid].elements[domid].type == 'hidden') {
639: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 640: }
641: }
642: }
1.876 raeburn 643: return userdom;
644: }
645:
646: ENDJS
1.468 raeburn 647:
1.876 raeburn 648: }
649:
1.1017 raeburn 650: sub javascript_array_indexof {
1.1018 raeburn 651: return <<ENDJS;
1.1017 raeburn 652: <script type="text/javascript" language="JavaScript">
653: // <![CDATA[
654:
655: if (!Array.prototype.indexOf) {
656: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
657: "use strict";
658: if (this === void 0 || this === null) {
659: throw new TypeError();
660: }
661: var t = Object(this);
662: var len = t.length >>> 0;
663: if (len === 0) {
664: return -1;
665: }
666: var n = 0;
667: if (arguments.length > 0) {
668: n = Number(arguments[1]);
669: if (n !== n) { // shortcut for verifying if it's NaN
670: n = 0;
671: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
672: n = (n > 0 || -1) * Math.floor(Math.abs(n));
673: }
674: }
675: if (n >= len) {
676: return -1;
677: }
678: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
679: for (; k < len; k++) {
680: if (k in t && t[k] === searchElement) {
681: return k;
682: }
683: }
684: return -1;
685: }
686: }
687:
688: // ]]>
689: </script>
690:
691: ENDJS
692:
693: }
694:
1.876 raeburn 695: sub userbrowser_javascript {
696: my $id_functions = &javascript_index_functions();
697: return <<"ENDUSERBRW";
698:
1.888 raeburn 699: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 700: var url = '/adm/pickuser?';
701: var userdom = getDomainFromSelectbox(formname,udom);
702: if (userdom != null) {
703: if (userdom != '') {
704: url += 'srchdom='+userdom+'&';
705: }
706: }
707: url += 'form=' + formname + '&unameelement='+uname+
708: '&udomelement='+udom+
709: '&ulastelement='+ulast+
710: '&ufirstelement='+ufirst+
711: '&uemailelement='+uemail+
1.881 raeburn 712: '&hideudomelement='+hideudom+
713: '&coursedom='+crsdom;
1.888 raeburn 714: if ((caller != null) && (caller != undefined)) {
715: url += '&caller='+caller;
716: }
1.876 raeburn 717: var title = 'User_Browser';
718: var options = 'scrollbars=1,resizable=1,menubar=0';
719: options += ',width=700,height=600';
720: var stdeditbrowser = open(url,title,options,'1');
721: stdeditbrowser.focus();
722: }
723:
1.888 raeburn 724: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 725: var formid = getFormIdByName(formname);
726: if (formid > -1) {
1.888 raeburn 727: var unameid = getIndexByName(formid,uname);
1.876 raeburn 728: var domid = getIndexByName(formid,udom);
729: var hidedomid = getIndexByName(formid,origdom);
730: if (hidedomid > -1) {
731: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 732: var unameval = document.forms[formid].elements[unameid].value;
733: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
734: if (domid > -1) {
735: var slct = document.forms[formid].elements[domid];
736: if (slct.type == 'select-one') {
737: var i;
738: for (i=0;i<slct.length;i++) {
739: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
740: }
741: }
742: if (slct.type == 'hidden') {
743: slct.value = fixeddom;
1.876 raeburn 744: }
745: }
1.468 raeburn 746: }
747: }
748: }
1.876 raeburn 749: return;
750: }
751:
752: $id_functions
753: ENDUSERBRW
1.468 raeburn 754: }
755:
756: sub setsec_javascript {
1.1075.2.31 raeburn 757: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 758: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
759: $communityrolestr);
760: if ($role_element ne '') {
761: my @allroles = ('st','ta','ep','in','ad');
762: foreach my $crstype ('Course','Community') {
763: if ($crstype eq 'Community') {
764: foreach my $role (@allroles) {
765: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
766: }
767: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
768: } else {
769: foreach my $role (@allroles) {
770: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
771: }
772: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
773: }
774: }
775: $rolestr = '"'.join('","',@allroles).'"';
776: $courserolestr = '"'.join('","',@courserolenames).'"';
777: $communityrolestr = '"'.join('","',@communityrolenames).'"';
778: }
1.468 raeburn 779: my $setsections = qq|
780: function setSect(sectionlist) {
1.629 raeburn 781: var sectionsArray = new Array();
782: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
783: sectionsArray = sectionlist.split(",");
784: }
1.468 raeburn 785: var numSections = sectionsArray.length;
786: document.$formname.$sec_element.length = 0;
787: if (numSections == 0) {
788: document.$formname.$sec_element.multiple=false;
789: document.$formname.$sec_element.size=1;
790: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
791: } else {
792: if (numSections == 1) {
793: document.$formname.$sec_element.multiple=false;
794: document.$formname.$sec_element.size=1;
795: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
796: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
797: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
798: } else {
799: for (var i=0; i<numSections; i++) {
800: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
801: }
802: document.$formname.$sec_element.multiple=true
803: if (numSections < 3) {
804: document.$formname.$sec_element.size=numSections;
805: } else {
806: document.$formname.$sec_element.size=3;
807: }
808: document.$formname.$sec_element.options[0].selected = false
809: }
810: }
1.91 www 811: }
1.905 raeburn 812:
813: function setRole(crstype) {
1.468 raeburn 814: |;
1.905 raeburn 815: if ($role_element eq '') {
816: $setsections .= ' return;
817: }
818: ';
819: } else {
820: $setsections .= qq|
821: var elementLength = document.$formname.$role_element.length;
822: var allroles = Array($rolestr);
823: var courserolenames = Array($courserolestr);
824: var communityrolenames = Array($communityrolestr);
825: if (elementLength != undefined) {
826: if (document.$formname.$role_element.options[5].value == 'cc') {
827: if (crstype == 'Course') {
828: return;
829: } else {
830: allroles[5] = 'co';
831: for (var i=0; i<6; i++) {
832: document.$formname.$role_element.options[i].value = allroles[i];
833: document.$formname.$role_element.options[i].text = communityrolenames[i];
834: }
835: }
836: } else {
837: if (crstype == 'Community') {
838: return;
839: } else {
840: allroles[5] = 'cc';
841: for (var i=0; i<6; i++) {
842: document.$formname.$role_element.options[i].value = allroles[i];
843: document.$formname.$role_element.options[i].text = courserolenames[i];
844: }
845: }
846: }
847: }
848: return;
849: }
850: |;
851: }
1.1075.2.31 raeburn 852: if ($credits_element) {
853: $setsections .= qq|
854: function setCredits(defaultcredits) {
855: document.$formname.$credits_element.value = defaultcredits;
856: return;
857: }
858: |;
859: }
1.468 raeburn 860: return $setsections;
861: }
862:
1.91 www 863: sub selectcourse_link {
1.909 raeburn 864: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
865: $typeelement) = @_;
866: my $type = $selecttype;
1.871 raeburn 867: my $linktext = &mt('Select Course');
868: if ($selecttype eq 'Community') {
1.909 raeburn 869: $linktext = &mt('Select Community');
1.906 raeburn 870: } elsif ($selecttype eq 'Course/Community') {
871: $linktext = &mt('Select Course/Community');
1.909 raeburn 872: $type = '';
1.1019 raeburn 873: } elsif ($selecttype eq 'Select') {
874: $linktext = &mt('Select');
875: $type = '';
1.871 raeburn 876: }
1.787 bisitz 877: return '<span class="LC_nobreak">'
878: ."<a href='"
879: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
880: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 881: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 882: ."'>".$linktext.'</a>'
1.787 bisitz 883: .'</span>';
1.74 www 884: }
1.42 matthew 885:
1.653 raeburn 886: sub selectauthor_link {
887: my ($form,$udom)=@_;
888: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
889: &mt('Select Author').'</a>';
890: }
891:
1.876 raeburn 892: sub selectuser_link {
1.881 raeburn 893: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 894: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 895: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 896: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 897: ');">'.$linktext.'</a>';
1.876 raeburn 898: }
899:
1.273 raeburn 900: sub check_uncheck_jscript {
901: my $jscript = <<"ENDSCRT";
902: function checkAll(field) {
903: if (field.length > 0) {
904: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 905: if (!field[i].disabled) {
906: field[i].checked = true;
907: }
1.273 raeburn 908: }
909: } else {
1.1075.2.14 raeburn 910: if (!field.disabled) {
911: field.checked = true;
912: }
1.273 raeburn 913: }
914: }
915:
916: function uncheckAll(field) {
917: if (field.length > 0) {
918: for (i = 0; i < field.length; i++) {
919: field[i].checked = false ;
1.543 albertel 920: }
921: } else {
1.273 raeburn 922: field.checked = false ;
923: }
924: }
925: ENDSCRT
926: return $jscript;
927: }
928:
1.656 www 929: sub select_timezone {
1.659 raeburn 930: my ($name,$selected,$onchange,$includeempty)=@_;
931: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
932: if ($includeempty) {
933: $output .= '<option value=""';
934: if (($selected eq '') || ($selected eq 'local')) {
935: $output .= ' selected="selected" ';
936: }
937: $output .= '> </option>';
938: }
1.657 raeburn 939: my @timezones = DateTime::TimeZone->all_names;
940: foreach my $tzone (@timezones) {
941: $output.= '<option value="'.$tzone.'"';
942: if ($tzone eq $selected) {
943: $output.=' selected="selected"';
944: }
945: $output.=">$tzone</option>\n";
1.656 www 946: }
947: $output.="</select>";
948: return $output;
949: }
1.273 raeburn 950:
1.687 raeburn 951: sub select_datelocale {
952: my ($name,$selected,$onchange,$includeempty)=@_;
953: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
954: if ($includeempty) {
955: $output .= '<option value=""';
956: if ($selected eq '') {
957: $output .= ' selected="selected" ';
958: }
959: $output .= '> </option>';
960: }
961: my (@possibles,%locale_names);
962: my @locales = DateTime::Locale::Catalog::Locales;
963: foreach my $locale (@locales) {
964: if (ref($locale) eq 'HASH') {
965: my $id = $locale->{'id'};
966: if ($id ne '') {
967: my $en_terr = $locale->{'en_territory'};
968: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 969: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 970: if (grep(/^en$/,@languages) || !@languages) {
971: if ($en_terr ne '') {
972: $locale_names{$id} = '('.$en_terr.')';
973: } elsif ($native_terr ne '') {
974: $locale_names{$id} = $native_terr;
975: }
976: } else {
977: if ($native_terr ne '') {
978: $locale_names{$id} = $native_terr.' ';
979: } elsif ($en_terr ne '') {
980: $locale_names{$id} = '('.$en_terr.')';
981: }
982: }
983: push (@possibles,$id);
984: }
985: }
986: }
987: foreach my $item (sort(@possibles)) {
988: $output.= '<option value="'.$item.'"';
989: if ($item eq $selected) {
990: $output.=' selected="selected"';
991: }
992: $output.=">$item";
993: if ($locale_names{$item} ne '') {
994: $output.=" $locale_names{$item}</option>\n";
995: }
996: $output.="</option>\n";
997: }
998: $output.="</select>";
999: return $output;
1000: }
1001:
1.792 raeburn 1002: sub select_language {
1003: my ($name,$selected,$includeempty) = @_;
1004: my %langchoices;
1005: if ($includeempty) {
1.1075.2.32 raeburn 1006: %langchoices = ('' => 'No language preference');
1.792 raeburn 1007: }
1008: foreach my $id (&languageids()) {
1009: my $code = &supportedlanguagecode($id);
1010: if ($code) {
1011: $langchoices{$code} = &plainlanguagedescription($id);
1012: }
1013: }
1.1075.2.32 raeburn 1014: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970 raeburn 1015: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1016: }
1017:
1.42 matthew 1018: =pod
1.36 matthew 1019:
1.648 raeburn 1020: =item * &linked_select_forms(...)
1.36 matthew 1021:
1022: linked_select_forms returns a string containing a <script></script> block
1023: and html for two <select> menus. The select menus will be linked in that
1024: changing the value of the first menu will result in new values being placed
1025: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1026: order unless a defined order is provided.
1.36 matthew 1027:
1028: linked_select_forms takes the following ordered inputs:
1029:
1030: =over 4
1031:
1.112 bowersj2 1032: =item * $formname, the name of the <form> tag
1.36 matthew 1033:
1.112 bowersj2 1034: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1035:
1.112 bowersj2 1036: =item * $firstdefault, the default value for the first menu
1.36 matthew 1037:
1.112 bowersj2 1038: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1039:
1.112 bowersj2 1040: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1041:
1.112 bowersj2 1042: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1043:
1.609 raeburn 1044: =item * $menuorder, the order of values in the first menu
1045:
1.1075.2.31 raeburn 1046: =item * $onchangefirst, additional javascript call to execute for an onchange
1047: event for the first <select> tag
1048:
1049: =item * $onchangesecond, additional javascript call to execute for an onchange
1050: event for the second <select> tag
1051:
1.41 ng 1052: =back
1053:
1.36 matthew 1054: Below is an example of such a hash. Only the 'text', 'default', and
1055: 'select2' keys must appear as stated. keys(%menu) are the possible
1056: values for the first select menu. The text that coincides with the
1.41 ng 1057: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1058: and text for the second menu are given in the hash pointed to by
1059: $menu{$choice1}->{'select2'}.
1060:
1.112 bowersj2 1061: my %menu = ( A1 => { text =>"Choice A1" ,
1062: default => "B3",
1063: select2 => {
1064: B1 => "Choice B1",
1065: B2 => "Choice B2",
1066: B3 => "Choice B3",
1067: B4 => "Choice B4"
1.609 raeburn 1068: },
1069: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1070: },
1071: A2 => { text =>"Choice A2" ,
1072: default => "C2",
1073: select2 => {
1074: C1 => "Choice C1",
1075: C2 => "Choice C2",
1076: C3 => "Choice C3"
1.609 raeburn 1077: },
1078: order => ['C2','C1','C3'],
1.112 bowersj2 1079: },
1080: A3 => { text =>"Choice A3" ,
1081: default => "D6",
1082: select2 => {
1083: D1 => "Choice D1",
1084: D2 => "Choice D2",
1085: D3 => "Choice D3",
1086: D4 => "Choice D4",
1087: D5 => "Choice D5",
1088: D6 => "Choice D6",
1089: D7 => "Choice D7"
1.609 raeburn 1090: },
1091: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1092: }
1093: );
1.36 matthew 1094:
1095: =cut
1096:
1097: sub linked_select_forms {
1098: my ($formname,
1099: $middletext,
1100: $firstdefault,
1101: $firstselectname,
1102: $secondselectname,
1.609 raeburn 1103: $hashref,
1104: $menuorder,
1.1075.2.31 raeburn 1105: $onchangefirst,
1106: $onchangesecond
1.36 matthew 1107: ) = @_;
1108: my $second = "document.$formname.$secondselectname";
1109: my $first = "document.$formname.$firstselectname";
1110: # output the javascript to do the changing
1111: my $result = '';
1.776 bisitz 1112: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1113: $result.="// <![CDATA[\n";
1.36 matthew 1114: $result.="var select2data = new Object();\n";
1115: $" = '","';
1116: my $debug = '';
1117: foreach my $s1 (sort(keys(%$hashref))) {
1118: $result.="select2data.d_$s1 = new Object();\n";
1119: $result.="select2data.d_$s1.def = new String('".
1120: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1121: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1122: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1123: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1124: @s2values = @{$hashref->{$s1}->{'order'}};
1125: }
1.36 matthew 1126: $result.="\"@s2values\");\n";
1127: $result.="select2data.d_$s1.texts = new Array(";
1128: my @s2texts;
1129: foreach my $value (@s2values) {
1130: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1131: }
1132: $result.="\"@s2texts\");\n";
1133: }
1134: $"=' ';
1135: $result.= <<"END";
1136:
1137: function select1_changed() {
1138: // Determine new choice
1139: var newvalue = "d_" + $first.value;
1140: // update select2
1141: var values = select2data[newvalue].values;
1142: var texts = select2data[newvalue].texts;
1143: var select2def = select2data[newvalue].def;
1144: var i;
1145: // out with the old
1146: for (i = 0; i < $second.options.length; i++) {
1147: $second.options[i] = null;
1148: }
1149: // in with the nuclear
1150: for (i=0;i<values.length; i++) {
1151: $second.options[i] = new Option(values[i]);
1.143 matthew 1152: $second.options[i].value = values[i];
1.36 matthew 1153: $second.options[i].text = texts[i];
1154: if (values[i] == select2def) {
1155: $second.options[i].selected = true;
1156: }
1157: }
1158: }
1.824 bisitz 1159: // ]]>
1.36 matthew 1160: </script>
1161: END
1162: # output the initial values for the selection lists
1.1075.2.31 raeburn 1163: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1164: my @order = sort(keys(%{$hashref}));
1165: if (ref($menuorder) eq 'ARRAY') {
1166: @order = @{$menuorder};
1167: }
1168: foreach my $value (@order) {
1.36 matthew 1169: $result.=" <option value=\"$value\" ";
1.253 albertel 1170: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1171: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1172: }
1173: $result .= "</select>\n";
1174: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1175: $result .= $middletext;
1.1075.2.31 raeburn 1176: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1177: if ($onchangesecond) {
1178: $result .= ' onchange="'.$onchangesecond.'"';
1179: }
1180: $result .= ">\n";
1.36 matthew 1181: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1182:
1183: my @secondorder = sort(keys(%select2));
1184: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1185: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1186: }
1187: foreach my $value (@secondorder) {
1.36 matthew 1188: $result.=" <option value=\"$value\" ";
1.253 albertel 1189: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1190: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1191: }
1192: $result .= "</select>\n";
1193: # return $debug;
1194: return $result;
1195: } # end of sub linked_select_forms {
1196:
1.45 matthew 1197: =pod
1.44 bowersj2 1198:
1.973 raeburn 1199: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1200:
1.112 bowersj2 1201: Returns a string corresponding to an HTML link to the given help
1202: $topic, where $topic corresponds to the name of a .tex file in
1203: /home/httpd/html/adm/help/tex, with underscores replaced by
1204: spaces.
1205:
1206: $text will optionally be linked to the same topic, allowing you to
1207: link text in addition to the graphic. If you do not want to link
1208: text, but wish to specify one of the later parameters, pass an
1209: empty string.
1210:
1211: $stayOnPage is a value that will be interpreted as a boolean. If true,
1212: the link will not open a new window. If false, the link will open
1213: a new window using Javascript. (Default is false.)
1214:
1215: $width and $height are optional numerical parameters that will
1216: override the width and height of the popped up window, which may
1.973 raeburn 1217: be useful for certain help topics with big pictures included.
1218:
1219: $imgid is the id of the img tag used for the help icon. This may be
1220: used in a javascript call to switch the image src. See
1221: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1222:
1223: =cut
1224:
1225: sub help_open_topic {
1.973 raeburn 1226: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1227: $text = "" if (not defined $text);
1.44 bowersj2 1228: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1229: $width = 500 if (not defined $width);
1.44 bowersj2 1230: $height = 400 if (not defined $height);
1231: my $filename = $topic;
1232: $filename =~ s/ /_/g;
1233:
1.48 bowersj2 1234: my $template = "";
1235: my $link;
1.572 banghart 1236:
1.159 www 1237: $topic=~s/\W/\_/g;
1.44 bowersj2 1238:
1.572 banghart 1239: if (!$stayOnPage) {
1.1075.2.50 raeburn 1240: if ($env{'browser.mobile'}) {
1241: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1242: } else {
1243: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1244: }
1.1037 www 1245: } elsif ($stayOnPage eq 'popup') {
1246: $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 1247: } else {
1.48 bowersj2 1248: $link = "/adm/help/${filename}.hlp";
1249: }
1250:
1251: # Add the text
1.755 neumanie 1252: if ($text ne "") {
1.763 bisitz 1253: $template.='<span class="LC_help_open_topic">'
1254: .'<a target="_top" href="'.$link.'">'
1255: .$text.'</a>';
1.48 bowersj2 1256: }
1257:
1.763 bisitz 1258: # (Always) Add the graphic
1.179 matthew 1259: my $title = &mt('Online Help');
1.667 raeburn 1260: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1261: if ($imgid ne '') {
1262: $imgid = ' id="'.$imgid.'"';
1263: }
1.763 bisitz 1264: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1265: .'<img src="'.$helpicon.'" border="0"'
1266: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1267: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1268: .' /></a>';
1269: if ($text ne "") {
1270: $template.='</span>';
1271: }
1.44 bowersj2 1272: return $template;
1273:
1.106 bowersj2 1274: }
1275:
1276: # This is a quicky function for Latex cheatsheet editing, since it
1277: # appears in at least four places
1278: sub helpLatexCheatsheet {
1.1037 www 1279: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1280: my $out;
1.106 bowersj2 1281: my $addOther = '';
1.732 raeburn 1282: if ($topic) {
1.1037 www 1283: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1284: }
1285: $out = '<span>' # Start cheatsheet
1286: .$addOther
1287: .'<span>'
1.1037 www 1288: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1289: .'</span> <span>'
1.1037 www 1290: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1291: .'</span>';
1.732 raeburn 1292: unless ($not_author) {
1.763 bisitz 1293: $out .= ' <span>'
1.1037 www 1294: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1295: .'</span> <span>'
1.1075.2.78! raeburn 1296: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1297: .'</span>';
1.732 raeburn 1298: }
1.763 bisitz 1299: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1300: return $out;
1.172 www 1301: }
1302:
1.430 albertel 1303: sub general_help {
1304: my $helptopic='Student_Intro';
1305: if ($env{'request.role'}=~/^(ca|au)/) {
1306: $helptopic='Authoring_Intro';
1.907 raeburn 1307: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1308: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1309: } elsif ($env{'request.role'}=~/^dc/) {
1310: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1311: }
1312: return $helptopic;
1313: }
1314:
1315: sub update_help_link {
1316: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1317: my $origurl = $ENV{'REQUEST_URI'};
1318: $origurl=~s|^/~|/priv/|;
1319: my $timestamp = time;
1320: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1321: $$datum = &escape($$datum);
1322: }
1323:
1324: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1325: my $output .= <<"ENDOUTPUT";
1326: <script type="text/javascript">
1.824 bisitz 1327: // <![CDATA[
1.430 albertel 1328: banner_link = '$banner_link';
1.824 bisitz 1329: // ]]>
1.430 albertel 1330: </script>
1331: ENDOUTPUT
1332: return $output;
1333: }
1334:
1335: # now just updates the help link and generates a blue icon
1.193 raeburn 1336: sub help_open_menu {
1.430 albertel 1337: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1338: = @_;
1.949 droeschl 1339: $stayOnPage = 1;
1.430 albertel 1340: my $output;
1341: if ($component_help) {
1342: if (!$text) {
1343: $output=&help_open_topic($component_help,undef,$stayOnPage,
1344: $width,$height);
1345: } else {
1346: my $help_text;
1347: $help_text=&unescape($topic);
1348: $output='<table><tr><td>'.
1349: &help_open_topic($component_help,$help_text,$stayOnPage,
1350: $width,$height).'</td></tr></table>';
1351: }
1352: }
1353: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1354: return $output.$banner_link;
1355: }
1356:
1357: sub top_nav_help {
1358: my ($text) = @_;
1.436 albertel 1359: $text = &mt($text);
1.1075.2.60 raeburn 1360: my $stay_on_page;
1361: unless ($env{'environment.remote'} eq 'on') {
1362: $stay_on_page = 1;
1363: }
1.1075.2.61 raeburn 1364: my ($link,$banner_link);
1365: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1366: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1367: : "javascript:helpMenu('open')";
1368: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1369: }
1.201 raeburn 1370: my $title = &mt('Get help');
1.1075.2.61 raeburn 1371: if ($link) {
1372: return <<"END";
1.436 albertel 1373: $banner_link
1.1075.2.56 raeburn 1374: <a href="$link" title="$title">$text</a>
1.436 albertel 1375: END
1.1075.2.61 raeburn 1376: } else {
1377: return ' '.$text.' ';
1378: }
1.436 albertel 1379: }
1380:
1381: sub help_menu_js {
1.1075.2.52 raeburn 1382: my ($httphost) = @_;
1.949 droeschl 1383: my $stayOnPage = 1;
1.436 albertel 1384: my $width = 620;
1385: my $height = 600;
1.430 albertel 1386: my $helptopic=&general_help();
1.1075.2.52 raeburn 1387: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1388: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1389: my $start_page =
1390: &Apache::loncommon::start_page('Help Menu', undef,
1391: {'frameset' => 1,
1392: 'js_ready' => 1,
1.1075.2.52 raeburn 1393: 'use_absolute' => $httphost,
1.331 albertel 1394: 'add_entries' => {
1395: 'border' => '0',
1.579 raeburn 1396: 'rows' => "110,*",},});
1.331 albertel 1397: my $end_page =
1398: &Apache::loncommon::end_page({'frameset' => 1,
1399: 'js_ready' => 1,});
1400:
1.436 albertel 1401: my $template .= <<"ENDTEMPLATE";
1402: <script type="text/javascript">
1.877 bisitz 1403: // <![CDATA[
1.253 albertel 1404: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1405: var banner_link = '';
1.243 raeburn 1406: function helpMenu(target) {
1407: var caller = this;
1408: if (target == 'open') {
1409: var newWindow = null;
1410: try {
1.262 albertel 1411: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1412: }
1413: catch(error) {
1414: writeHelp(caller);
1415: return;
1416: }
1417: if (newWindow) {
1418: caller = newWindow;
1419: }
1.193 raeburn 1420: }
1.243 raeburn 1421: writeHelp(caller);
1422: return;
1423: }
1424: function writeHelp(caller) {
1.1075.2.61 raeburn 1425: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1426: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1427: caller.document.close();
1428: caller.focus();
1.193 raeburn 1429: }
1.877 bisitz 1430: // END LON-CAPA Internal -->
1.253 albertel 1431: // ]]>
1.436 albertel 1432: </script>
1.193 raeburn 1433: ENDTEMPLATE
1434: return $template;
1435: }
1436:
1.172 www 1437: sub help_open_bug {
1438: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1439: unless ($env{'user.adv'}) { return ''; }
1.172 www 1440: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1441: $text = "" if (not defined $text);
1442: $stayOnPage=1;
1.184 albertel 1443: $width = 600 if (not defined $width);
1444: $height = 600 if (not defined $height);
1.172 www 1445:
1446: $topic=~s/\W+/\+/g;
1447: my $link='';
1448: my $template='';
1.379 albertel 1449: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1450: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1451: if (!$stayOnPage)
1452: {
1453: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1454: }
1455: else
1456: {
1457: $link = $url;
1458: }
1459: # Add the text
1460: if ($text ne "")
1461: {
1462: $template .=
1463: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1464: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1465: }
1466:
1467: # Add the graphic
1.179 matthew 1468: my $title = &mt('Report a Bug');
1.215 albertel 1469: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1470: $template .= <<"ENDTEMPLATE";
1.436 albertel 1471: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1472: ENDTEMPLATE
1473: if ($text ne '') { $template.='</td></tr></table>' };
1474: return $template;
1475:
1476: }
1477:
1478: sub help_open_faq {
1479: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1480: unless ($env{'user.adv'}) { return ''; }
1.172 www 1481: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1482: $text = "" if (not defined $text);
1483: $stayOnPage=1;
1484: $width = 350 if (not defined $width);
1485: $height = 400 if (not defined $height);
1486:
1487: $topic=~s/\W+/\+/g;
1488: my $link='';
1489: my $template='';
1490: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1491: if (!$stayOnPage)
1492: {
1493: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1494: }
1495: else
1496: {
1497: $link = $url;
1498: }
1499:
1500: # Add the text
1501: if ($text ne "")
1502: {
1503: $template .=
1.173 www 1504: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1505: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1506: }
1507:
1508: # Add the graphic
1.179 matthew 1509: my $title = &mt('View the FAQ');
1.215 albertel 1510: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1511: $template .= <<"ENDTEMPLATE";
1.436 albertel 1512: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1513: ENDTEMPLATE
1514: if ($text ne '') { $template.='</td></tr></table>' };
1515: return $template;
1516:
1.44 bowersj2 1517: }
1.37 matthew 1518:
1.180 matthew 1519: ###############################################################
1520: ###############################################################
1521:
1.45 matthew 1522: =pod
1523:
1.648 raeburn 1524: =item * &change_content_javascript():
1.256 matthew 1525:
1526: This and the next function allow you to create small sections of an
1527: otherwise static HTML page that you can update on the fly with
1528: Javascript, even in Netscape 4.
1529:
1530: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1531: must be written to the HTML page once. It will prove the Javascript
1532: function "change(name, content)". Calling the change function with the
1533: name of the section
1534: you want to update, matching the name passed to C<changable_area>, and
1535: the new content you want to put in there, will put the content into
1536: that area.
1537:
1538: B<Note>: Netscape 4 only reserves enough space for the changable area
1539: to contain room for the original contents. You need to "make space"
1540: for whatever changes you wish to make, and be B<sure> to check your
1541: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1542: it's adequate for updating a one-line status display, but little more.
1543: This script will set the space to 100% width, so you only need to
1544: worry about height in Netscape 4.
1545:
1546: Modern browsers are much less limiting, and if you can commit to the
1547: user not using Netscape 4, this feature may be used freely with
1548: pretty much any HTML.
1549:
1550: =cut
1551:
1552: sub change_content_javascript {
1553: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1554: if ($env{'browser.type'} eq 'netscape' &&
1555: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1556: return (<<NETSCAPE4);
1557: function change(name, content) {
1558: doc = document.layers[name+"___escape"].layers[0].document;
1559: doc.open();
1560: doc.write(content);
1561: doc.close();
1562: }
1563: NETSCAPE4
1564: } else {
1565: # Otherwise, we need to use semi-standards-compliant code
1566: # (technically, "innerHTML" isn't standard but the equivalent
1567: # is really scary, and every useful browser supports it
1568: return (<<DOMBASED);
1569: function change(name, content) {
1570: element = document.getElementById(name);
1571: element.innerHTML = content;
1572: }
1573: DOMBASED
1574: }
1575: }
1576:
1577: =pod
1578:
1.648 raeburn 1579: =item * &changable_area($name,$origContent):
1.256 matthew 1580:
1581: This provides a "changable area" that can be modified on the fly via
1582: the Javascript code provided in C<change_content_javascript>. $name is
1583: the name you will use to reference the area later; do not repeat the
1584: same name on a given HTML page more then once. $origContent is what
1585: the area will originally contain, which can be left blank.
1586:
1587: =cut
1588:
1589: sub changable_area {
1590: my ($name, $origContent) = @_;
1591:
1.258 albertel 1592: if ($env{'browser.type'} eq 'netscape' &&
1593: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1594: # If this is netscape 4, we need to use the Layer tag
1595: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1596: } else {
1597: return "<span id='$name'>$origContent</span>";
1598: }
1599: }
1600:
1601: =pod
1602:
1.648 raeburn 1603: =item * &viewport_geometry_js
1.590 raeburn 1604:
1605: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1606:
1607: =cut
1608:
1609:
1610: sub viewport_geometry_js {
1611: return <<"GEOMETRY";
1612: var Geometry = {};
1613: function init_geometry() {
1614: if (Geometry.init) { return };
1615: Geometry.init=1;
1616: if (window.innerHeight) {
1617: Geometry.getViewportHeight = function() { return window.innerHeight; };
1618: Geometry.getViewportWidth = function() { return window.innerWidth; };
1619: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1620: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1621: }
1622: else if (document.documentElement && document.documentElement.clientHeight) {
1623: Geometry.getViewportHeight =
1624: function() { return document.documentElement.clientHeight; };
1625: Geometry.getViewportWidth =
1626: function() { return document.documentElement.clientWidth; };
1627:
1628: Geometry.getHorizontalScroll =
1629: function() { return document.documentElement.scrollLeft; };
1630: Geometry.getVerticalScroll =
1631: function() { return document.documentElement.scrollTop; };
1632: }
1633: else if (document.body.clientHeight) {
1634: Geometry.getViewportHeight =
1635: function() { return document.body.clientHeight; };
1636: Geometry.getViewportWidth =
1637: function() { return document.body.clientWidth; };
1638: Geometry.getHorizontalScroll =
1639: function() { return document.body.scrollLeft; };
1640: Geometry.getVerticalScroll =
1641: function() { return document.body.scrollTop; };
1642: }
1643: }
1644:
1645: GEOMETRY
1646: }
1647:
1648: =pod
1649:
1.648 raeburn 1650: =item * &viewport_size_js()
1.590 raeburn 1651:
1652: 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.
1653:
1654: =cut
1655:
1656: sub viewport_size_js {
1657: my $geometry = &viewport_geometry_js();
1658: return <<"DIMS";
1659:
1660: $geometry
1661:
1662: function getViewportDims(width,height) {
1663: init_geometry();
1664: width.value = Geometry.getViewportWidth();
1665: height.value = Geometry.getViewportHeight();
1666: return;
1667: }
1668:
1669: DIMS
1670: }
1671:
1672: =pod
1673:
1.648 raeburn 1674: =item * &resize_textarea_js()
1.565 albertel 1675:
1676: emits the needed javascript to resize a textarea to be as big as possible
1677:
1678: creates a function resize_textrea that takes two IDs first should be
1679: the id of the element to resize, second should be the id of a div that
1680: surrounds everything that comes after the textarea, this routine needs
1681: to be attached to the <body> for the onload and onresize events.
1682:
1.648 raeburn 1683: =back
1.565 albertel 1684:
1685: =cut
1686:
1687: sub resize_textarea_js {
1.590 raeburn 1688: my $geometry = &viewport_geometry_js();
1.565 albertel 1689: return <<"RESIZE";
1690: <script type="text/javascript">
1.824 bisitz 1691: // <![CDATA[
1.590 raeburn 1692: $geometry
1.565 albertel 1693:
1.588 albertel 1694: function getX(element) {
1695: var x = 0;
1696: while (element) {
1697: x += element.offsetLeft;
1698: element = element.offsetParent;
1699: }
1700: return x;
1701: }
1702: function getY(element) {
1703: var y = 0;
1704: while (element) {
1705: y += element.offsetTop;
1706: element = element.offsetParent;
1707: }
1708: return y;
1709: }
1710:
1711:
1.565 albertel 1712: function resize_textarea(textarea_id,bottom_id) {
1713: init_geometry();
1714: var textarea = document.getElementById(textarea_id);
1715: //alert(textarea);
1716:
1.588 albertel 1717: var textarea_top = getY(textarea);
1.565 albertel 1718: var textarea_height = textarea.offsetHeight;
1719: var bottom = document.getElementById(bottom_id);
1.588 albertel 1720: var bottom_top = getY(bottom);
1.565 albertel 1721: var bottom_height = bottom.offsetHeight;
1722: var window_height = Geometry.getViewportHeight();
1.588 albertel 1723: var fudge = 23;
1.565 albertel 1724: var new_height = window_height-fudge-textarea_top-bottom_height;
1725: if (new_height < 300) {
1726: new_height = 300;
1727: }
1728: textarea.style.height=new_height+'px';
1729: }
1.824 bisitz 1730: // ]]>
1.565 albertel 1731: </script>
1732: RESIZE
1733:
1734: }
1735:
1736: =pod
1737:
1.256 matthew 1738: =head1 Excel and CSV file utility routines
1739:
1740: =cut
1741:
1742: ###############################################################
1743: ###############################################################
1744:
1745: =pod
1746:
1.1075.2.56 raeburn 1747: =over 4
1748:
1.648 raeburn 1749: =item * &csv_translate($text)
1.37 matthew 1750:
1.185 www 1751: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1752: format.
1753:
1754: =cut
1755:
1.180 matthew 1756: ###############################################################
1757: ###############################################################
1.37 matthew 1758: sub csv_translate {
1759: my $text = shift;
1760: $text =~ s/\"/\"\"/g;
1.209 albertel 1761: $text =~ s/\n/ /g;
1.37 matthew 1762: return $text;
1763: }
1.180 matthew 1764:
1765: ###############################################################
1766: ###############################################################
1767:
1768: =pod
1769:
1.648 raeburn 1770: =item * &define_excel_formats()
1.180 matthew 1771:
1772: Define some commonly used Excel cell formats.
1773:
1774: Currently supported formats:
1775:
1776: =over 4
1777:
1778: =item header
1779:
1780: =item bold
1781:
1782: =item h1
1783:
1784: =item h2
1785:
1786: =item h3
1787:
1.256 matthew 1788: =item h4
1789:
1790: =item i
1791:
1.180 matthew 1792: =item date
1793:
1794: =back
1795:
1796: Inputs: $workbook
1797:
1798: Returns: $format, a hash reference.
1799:
1.1057 foxr 1800:
1.180 matthew 1801: =cut
1802:
1803: ###############################################################
1804: ###############################################################
1805: sub define_excel_formats {
1806: my ($workbook) = @_;
1807: my $format;
1808: $format->{'header'} = $workbook->add_format(bold => 1,
1809: bottom => 1,
1810: align => 'center');
1811: $format->{'bold'} = $workbook->add_format(bold=>1);
1812: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1813: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1814: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1815: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1816: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1817: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1818: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1819: return $format;
1820: }
1821:
1822: ###############################################################
1823: ###############################################################
1.113 bowersj2 1824:
1825: =pod
1826:
1.648 raeburn 1827: =item * &create_workbook()
1.255 matthew 1828:
1829: Create an Excel worksheet. If it fails, output message on the
1830: request object and return undefs.
1831:
1832: Inputs: Apache request object
1833:
1834: Returns (undef) on failure,
1835: Excel worksheet object, scalar with filename, and formats
1836: from &Apache::loncommon::define_excel_formats on success
1837:
1838: =cut
1839:
1840: ###############################################################
1841: ###############################################################
1842: sub create_workbook {
1843: my ($r) = @_;
1844: #
1845: # Create the excel spreadsheet
1846: my $filename = '/prtspool/'.
1.258 albertel 1847: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1848: time.'_'.rand(1000000000).'.xls';
1849: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1850: if (! defined($workbook)) {
1851: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1852: $r->print(
1853: '<p class="LC_error">'
1854: .&mt('Problems occurred in creating the new Excel file.')
1855: .' '.&mt('This error has been logged.')
1856: .' '.&mt('Please alert your LON-CAPA administrator.')
1857: .'</p>'
1858: );
1.255 matthew 1859: return (undef);
1860: }
1861: #
1.1014 foxr 1862: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1863: #
1864: my $format = &Apache::loncommon::define_excel_formats($workbook);
1865: return ($workbook,$filename,$format);
1866: }
1867:
1868: ###############################################################
1869: ###############################################################
1870:
1871: =pod
1872:
1.648 raeburn 1873: =item * &create_text_file()
1.113 bowersj2 1874:
1.542 raeburn 1875: Create a file to write to and eventually make available to the user.
1.256 matthew 1876: If file creation fails, outputs an error message on the request object and
1877: return undefs.
1.113 bowersj2 1878:
1.256 matthew 1879: Inputs: Apache request object, and file suffix
1.113 bowersj2 1880:
1.256 matthew 1881: Returns (undef) on failure,
1882: Filehandle and filename on success.
1.113 bowersj2 1883:
1884: =cut
1885:
1.256 matthew 1886: ###############################################################
1887: ###############################################################
1888: sub create_text_file {
1889: my ($r,$suffix) = @_;
1890: if (! defined($suffix)) { $suffix = 'txt'; };
1891: my $fh;
1892: my $filename = '/prtspool/'.
1.258 albertel 1893: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1894: time.'_'.rand(1000000000).'.'.$suffix;
1895: $fh = Apache::File->new('>/home/httpd'.$filename);
1896: if (! defined($fh)) {
1897: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1898: $r->print(
1899: '<p class="LC_error">'
1900: .&mt('Problems occurred in creating the output file.')
1901: .' '.&mt('This error has been logged.')
1902: .' '.&mt('Please alert your LON-CAPA administrator.')
1903: .'</p>'
1904: );
1.113 bowersj2 1905: }
1.256 matthew 1906: return ($fh,$filename)
1.113 bowersj2 1907: }
1908:
1909:
1.256 matthew 1910: =pod
1.113 bowersj2 1911:
1912: =back
1913:
1914: =cut
1.37 matthew 1915:
1916: ###############################################################
1.33 matthew 1917: ## Home server <option> list generating code ##
1918: ###############################################################
1.35 matthew 1919:
1.169 www 1920: # ------------------------------------------
1921:
1922: sub domain_select {
1923: my ($name,$value,$multiple)=@_;
1924: my %domains=map {
1.514 albertel 1925: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1926: } &Apache::lonnet::all_domains();
1.169 www 1927: if ($multiple) {
1928: $domains{''}=&mt('Any domain');
1.550 albertel 1929: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1930: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1931: } else {
1.550 albertel 1932: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1933: return &select_form($name,$value,\%domains);
1.169 www 1934: }
1935: }
1936:
1.282 albertel 1937: #-------------------------------------------
1938:
1939: =pod
1940:
1.519 raeburn 1941: =head1 Routines for form select boxes
1942:
1943: =over 4
1944:
1.648 raeburn 1945: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1946:
1947: Returns a string containing a <select> element int multiple mode
1948:
1949:
1950: Args:
1951: $name - name of the <select> element
1.506 raeburn 1952: $value - scalar or array ref of values that should already be selected
1.282 albertel 1953: $size - number of rows long the select element is
1.283 albertel 1954: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1955: (shown text should already have been &mt())
1.506 raeburn 1956: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1957:
1.282 albertel 1958: =cut
1959:
1960: #-------------------------------------------
1.169 www 1961: sub multiple_select_form {
1.284 albertel 1962: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1963: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1964: my $output='';
1.191 matthew 1965: if (! defined($size)) {
1966: $size = 4;
1.283 albertel 1967: if (scalar(keys(%$hash))<4) {
1968: $size = scalar(keys(%$hash));
1.191 matthew 1969: }
1970: }
1.734 bisitz 1971: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1972: my @order;
1.506 raeburn 1973: if (ref($order) eq 'ARRAY') {
1974: @order = @{$order};
1975: } else {
1976: @order = sort(keys(%$hash));
1.501 banghart 1977: }
1978: if (exists($$hash{'select_form_order'})) {
1979: @order = @{$$hash{'select_form_order'}};
1980: }
1981:
1.284 albertel 1982: foreach my $key (@order) {
1.356 albertel 1983: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1984: $output.='selected="selected" ' if ($selected{$key});
1985: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1986: }
1987: $output.="</select>\n";
1988: return $output;
1989: }
1990:
1.88 www 1991: #-------------------------------------------
1992:
1993: =pod
1994:
1.970 raeburn 1995: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1996:
1997: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 1998: allow a user to select options from a ref to a hash containing:
1999: option_name => displayed text. An optional $onchange can include
2000: a javascript onchange item, e.g., onchange="this.form.submit();"
2001:
1.88 www 2002: See lonrights.pm for an example invocation and use.
2003:
2004: =cut
2005:
2006: #-------------------------------------------
2007: sub select_form {
1.970 raeburn 2008: my ($def,$name,$hashref,$onchange) = @_;
2009: return unless (ref($hashref) eq 'HASH');
2010: if ($onchange) {
2011: $onchange = ' onchange="'.$onchange.'"';
2012: }
2013: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2014: my @keys;
1.970 raeburn 2015: if (exists($hashref->{'select_form_order'})) {
2016: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2017: } else {
1.970 raeburn 2018: @keys=sort(keys(%{$hashref}));
1.128 albertel 2019: }
1.356 albertel 2020: foreach my $key (@keys) {
2021: $selectform.=
2022: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2023: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2024: ">".$hashref->{$key}."</option>\n";
1.88 www 2025: }
2026: $selectform.="</select>";
2027: return $selectform;
2028: }
2029:
1.475 www 2030: # For display filters
2031:
2032: sub display_filter {
1.1074 raeburn 2033: my ($context) = @_;
1.475 www 2034: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2035: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2036: my $phraseinput = 'hidden';
2037: my $includeinput = 'hidden';
2038: my ($checked,$includetypestext);
2039: if ($env{'form.displayfilter'} eq 'containing') {
2040: $phraseinput = 'text';
2041: if ($context eq 'parmslog') {
2042: $includeinput = 'checkbox';
2043: if ($env{'form.includetypes'}) {
2044: $checked = ' checked="checked"';
2045: }
2046: $includetypestext = &mt('Include parameter types');
2047: }
2048: } else {
2049: $includetypestext = ' ';
2050: }
2051: my ($additional,$secondid,$thirdid);
2052: if ($context eq 'parmslog') {
2053: $additional =
2054: '<label><input type="'.$includeinput.'" name="includetypes"'.
2055: $checked.' name="includetypes" value="1" id="includetypes" />'.
2056: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2057: '</label>';
2058: $secondid = 'includetypes';
2059: $thirdid = 'includetypestext';
2060: }
2061: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2062: '$secondid','$thirdid')";
2063: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2064: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2065: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2066: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2067: &mt('Filter: [_1]',
1.477 www 2068: &select_form($env{'form.displayfilter'},
2069: 'displayfilter',
1.970 raeburn 2070: {'currentfolder' => 'Current folder/page',
1.477 www 2071: 'containing' => 'Containing phrase',
1.1074 raeburn 2072: 'none' => 'None'},$onchange)).' '.
2073: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2074: &HTML::Entities::encode($env{'form.containingphrase'}).
2075: '" />'.$additional;
2076: }
2077:
2078: sub display_filter_js {
2079: my $includetext = &mt('Include parameter types');
2080: return <<"ENDJS";
2081:
2082: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2083: var firstType = 'hidden';
2084: if (setter.options[setter.selectedIndex].value == 'containing') {
2085: firstType = 'text';
2086: }
2087: firstObject = document.getElementById(firstid);
2088: if (typeof(firstObject) == 'object') {
2089: if (firstObject.type != firstType) {
2090: changeInputType(firstObject,firstType);
2091: }
2092: }
2093: if (context == 'parmslog') {
2094: var secondType = 'hidden';
2095: if (firstType == 'text') {
2096: secondType = 'checkbox';
2097: }
2098: secondObject = document.getElementById(secondid);
2099: if (typeof(secondObject) == 'object') {
2100: if (secondObject.type != secondType) {
2101: changeInputType(secondObject,secondType);
2102: }
2103: }
2104: var textItem = document.getElementById(thirdid);
2105: var currtext = textItem.innerHTML;
2106: var newtext;
2107: if (firstType == 'text') {
2108: newtext = '$includetext';
2109: } else {
2110: newtext = ' ';
2111: }
2112: if (currtext != newtext) {
2113: textItem.innerHTML = newtext;
2114: }
2115: }
2116: return;
2117: }
2118:
2119: function changeInputType(oldObject,newType) {
2120: var newObject = document.createElement('input');
2121: newObject.type = newType;
2122: if (oldObject.size) {
2123: newObject.size = oldObject.size;
2124: }
2125: if (oldObject.value) {
2126: newObject.value = oldObject.value;
2127: }
2128: if (oldObject.name) {
2129: newObject.name = oldObject.name;
2130: }
2131: if (oldObject.id) {
2132: newObject.id = oldObject.id;
2133: }
2134: oldObject.parentNode.replaceChild(newObject,oldObject);
2135: return;
2136: }
2137:
2138: ENDJS
1.475 www 2139: }
2140:
1.167 www 2141: sub gradeleveldescription {
2142: my $gradelevel=shift;
2143: my %gradelevels=(0 => 'Not specified',
2144: 1 => 'Grade 1',
2145: 2 => 'Grade 2',
2146: 3 => 'Grade 3',
2147: 4 => 'Grade 4',
2148: 5 => 'Grade 5',
2149: 6 => 'Grade 6',
2150: 7 => 'Grade 7',
2151: 8 => 'Grade 8',
2152: 9 => 'Grade 9',
2153: 10 => 'Grade 10',
2154: 11 => 'Grade 11',
2155: 12 => 'Grade 12',
2156: 13 => 'Grade 13',
2157: 14 => '100 Level',
2158: 15 => '200 Level',
2159: 16 => '300 Level',
2160: 17 => '400 Level',
2161: 18 => 'Graduate Level');
2162: return &mt($gradelevels{$gradelevel});
2163: }
2164:
1.163 www 2165: sub select_level_form {
2166: my ($deflevel,$name)=@_;
2167: unless ($deflevel) { $deflevel=0; }
1.167 www 2168: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2169: for (my $i=0; $i<=18; $i++) {
2170: $selectform.="<option value=\"$i\" ".
1.253 albertel 2171: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2172: ">".&gradeleveldescription($i)."</option>\n";
2173: }
2174: $selectform.="</select>";
2175: return $selectform;
1.163 www 2176: }
1.167 www 2177:
1.35 matthew 2178: #-------------------------------------------
2179:
1.45 matthew 2180: =pod
2181:
1.1075.2.42 raeburn 2182: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2183:
2184: Returns a string containing a <select name='$name' size='1'> form to
2185: allow a user to select the domain to preform an operation in.
2186: See loncreateuser.pm for an example invocation and use.
2187:
1.90 www 2188: If the $includeempty flag is set, it also includes an empty choice ("no domain
2189: selected");
2190:
1.743 raeburn 2191: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2192:
1.910 raeburn 2193: 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.
2194:
1.1075.2.36 raeburn 2195: The optional $incdoms is a reference to an array of domains which will be the only available options.
2196:
2197: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2198:
1.35 matthew 2199: =cut
2200:
2201: #-------------------------------------------
1.34 matthew 2202: sub select_dom_form {
1.1075.2.36 raeburn 2203: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2204: if ($onchange) {
1.874 raeburn 2205: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2206: }
1.1075.2.36 raeburn 2207: my (@domains,%exclude);
1.910 raeburn 2208: if (ref($incdoms) eq 'ARRAY') {
2209: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2210: } else {
2211: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2212: }
1.90 www 2213: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2214: if (ref($excdoms) eq 'ARRAY') {
2215: map { $exclude{$_} = 1; } @{$excdoms};
2216: }
1.743 raeburn 2217: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2218: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2219: next if ($exclude{$dom});
1.356 albertel 2220: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2221: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2222: if ($showdomdesc) {
2223: if ($dom ne '') {
2224: my $domdesc = &Apache::lonnet::domain($dom,'description');
2225: if ($domdesc ne '') {
2226: $selectdomain .= ' ('.$domdesc.')';
2227: }
2228: }
2229: }
2230: $selectdomain .= "</option>\n";
1.34 matthew 2231: }
2232: $selectdomain.="</select>";
2233: return $selectdomain;
2234: }
2235:
1.35 matthew 2236: #-------------------------------------------
2237:
1.45 matthew 2238: =pod
2239:
1.648 raeburn 2240: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2241:
1.586 raeburn 2242: input: 4 arguments (two required, two optional) -
2243: $domain - domain of new user
2244: $name - name of form element
2245: $default - Value of 'default' causes a default item to be first
2246: option, and selected by default.
2247: $hide - Value of 'hide' causes hiding of the name of the server,
2248: if 1 server found, or default, if 0 found.
1.594 raeburn 2249: output: returns 2 items:
1.586 raeburn 2250: (a) form element which contains either:
2251: (i) <select name="$name">
2252: <option value="$hostid1">$hostid $servers{$hostid}</option>
2253: <option value="$hostid2">$hostid $servers{$hostid}</option>
2254: </select>
2255: form item if there are multiple library servers in $domain, or
2256: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2257: if there is only one library server in $domain.
2258:
2259: (b) number of library servers found.
2260:
2261: See loncreateuser.pm for example of use.
1.35 matthew 2262:
2263: =cut
2264:
2265: #-------------------------------------------
1.586 raeburn 2266: sub home_server_form_item {
2267: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2268: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2269: my $result;
2270: my $numlib = keys(%servers);
2271: if ($numlib > 1) {
2272: $result .= '<select name="'.$name.'" />'."\n";
2273: if ($default) {
1.804 bisitz 2274: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2275: '</option>'."\n";
2276: }
2277: foreach my $hostid (sort(keys(%servers))) {
2278: $result.= '<option value="'.$hostid.'">'.
2279: $hostid.' '.$servers{$hostid}."</option>\n";
2280: }
2281: $result .= '</select>'."\n";
2282: } elsif ($numlib == 1) {
2283: my $hostid;
2284: foreach my $item (keys(%servers)) {
2285: $hostid = $item;
2286: }
2287: $result .= '<input type="hidden" name="'.$name.'" value="'.
2288: $hostid.'" />';
2289: if (!$hide) {
2290: $result .= $hostid.' '.$servers{$hostid};
2291: }
2292: $result .= "\n";
2293: } elsif ($default) {
2294: $result .= '<input type="hidden" name="'.$name.
2295: '" value="default" />';
2296: if (!$hide) {
2297: $result .= &mt('default');
2298: }
2299: $result .= "\n";
1.33 matthew 2300: }
1.586 raeburn 2301: return ($result,$numlib);
1.33 matthew 2302: }
1.112 bowersj2 2303:
2304: =pod
2305:
1.534 albertel 2306: =back
2307:
1.112 bowersj2 2308: =cut
1.87 matthew 2309:
2310: ###############################################################
1.112 bowersj2 2311: ## Decoding User Agent ##
1.87 matthew 2312: ###############################################################
2313:
2314: =pod
2315:
1.112 bowersj2 2316: =head1 Decoding the User Agent
2317:
2318: =over 4
2319:
2320: =item * &decode_user_agent()
1.87 matthew 2321:
2322: Inputs: $r
2323:
2324: Outputs:
2325:
2326: =over 4
2327:
1.112 bowersj2 2328: =item * $httpbrowser
1.87 matthew 2329:
1.112 bowersj2 2330: =item * $clientbrowser
1.87 matthew 2331:
1.112 bowersj2 2332: =item * $clientversion
1.87 matthew 2333:
1.112 bowersj2 2334: =item * $clientmathml
1.87 matthew 2335:
1.112 bowersj2 2336: =item * $clientunicode
1.87 matthew 2337:
1.112 bowersj2 2338: =item * $clientos
1.87 matthew 2339:
1.1075.2.42 raeburn 2340: =item * $clientmobile
2341:
2342: =item * $clientinfo
2343:
1.1075.2.77 raeburn 2344: =item * $clientosversion
2345:
1.87 matthew 2346: =back
2347:
1.157 matthew 2348: =back
2349:
1.87 matthew 2350: =cut
2351:
2352: ###############################################################
2353: ###############################################################
2354: sub decode_user_agent {
1.247 albertel 2355: my ($r)=@_;
1.87 matthew 2356: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2357: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2358: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2359: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2360: my $clientbrowser='unknown';
2361: my $clientversion='0';
2362: my $clientmathml='';
2363: my $clientunicode='0';
1.1075.2.42 raeburn 2364: my $clientmobile=0;
1.1075.2.77 raeburn 2365: my $clientosversion='';
1.87 matthew 2366: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2367: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2368: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2369: $clientbrowser=$bname;
2370: $httpbrowser=~/$vreg/i;
2371: $clientversion=$1;
2372: $clientmathml=($clientversion>=$minv);
2373: $clientunicode=($clientversion>=$univ);
2374: }
2375: }
2376: my $clientos='unknown';
1.1075.2.42 raeburn 2377: my $clientinfo;
1.87 matthew 2378: if (($httpbrowser=~/linux/i) ||
2379: ($httpbrowser=~/unix/i) ||
2380: ($httpbrowser=~/ux/i) ||
2381: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2382: if (($httpbrowser=~/vax/i) ||
2383: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2384: if ($httpbrowser=~/next/i) { $clientos='next'; }
2385: if (($httpbrowser=~/mac/i) ||
2386: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2387: if ($httpbrowser=~/win/i) {
2388: $clientos='win';
2389: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2390: $clientosversion = $1;
2391: }
2392: }
1.87 matthew 2393: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2394: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2395: $clientmobile=lc($1);
2396: }
2397: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2398: $clientinfo = 'firefox-'.$1;
2399: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2400: $clientinfo = 'chromeframe-'.$1;
2401: }
1.87 matthew 2402: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2403: $clientunicode,$clientos,$clientmobile,$clientinfo,
2404: $clientosversion);
1.87 matthew 2405: }
2406:
1.32 matthew 2407: ###############################################################
2408: ## Authentication changing form generation subroutines ##
2409: ###############################################################
2410: ##
2411: ## All of the authform_xxxxxxx subroutines take their inputs in a
2412: ## hash, and have reasonable default values.
2413: ##
2414: ## formname = the name given in the <form> tag.
1.35 matthew 2415: #-------------------------------------------
2416:
1.45 matthew 2417: =pod
2418:
1.112 bowersj2 2419: =head1 Authentication Routines
2420:
2421: =over 4
2422:
1.648 raeburn 2423: =item * &authform_xxxxxx()
1.35 matthew 2424:
2425: The authform_xxxxxx subroutines provide javascript and html forms which
2426: handle some of the conveniences required for authentication forms.
2427: This is not an optimal method, but it works.
2428:
2429: =over 4
2430:
1.112 bowersj2 2431: =item * authform_header
1.35 matthew 2432:
1.112 bowersj2 2433: =item * authform_authorwarning
1.35 matthew 2434:
1.112 bowersj2 2435: =item * authform_nochange
1.35 matthew 2436:
1.112 bowersj2 2437: =item * authform_kerberos
1.35 matthew 2438:
1.112 bowersj2 2439: =item * authform_internal
1.35 matthew 2440:
1.112 bowersj2 2441: =item * authform_filesystem
1.35 matthew 2442:
2443: =back
2444:
1.648 raeburn 2445: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2446:
1.35 matthew 2447: =cut
2448:
2449: #-------------------------------------------
1.32 matthew 2450: sub authform_header{
2451: my %in = (
2452: formname => 'cu',
1.80 albertel 2453: kerb_def_dom => '',
1.32 matthew 2454: @_,
2455: );
2456: $in{'formname'} = 'document.' . $in{'formname'};
2457: my $result='';
1.80 albertel 2458:
2459: #---------------------------------------------- Code for upper case translation
2460: my $Javascript_toUpperCase;
2461: unless ($in{kerb_def_dom}) {
2462: $Javascript_toUpperCase =<<"END";
2463: switch (choice) {
2464: case 'krb': currentform.elements[choicearg].value =
2465: currentform.elements[choicearg].value.toUpperCase();
2466: break;
2467: default:
2468: }
2469: END
2470: } else {
2471: $Javascript_toUpperCase = "";
2472: }
2473:
1.165 raeburn 2474: my $radioval = "'nochange'";
1.591 raeburn 2475: if (defined($in{'curr_authtype'})) {
2476: if ($in{'curr_authtype'} ne '') {
2477: $radioval = "'".$in{'curr_authtype'}."arg'";
2478: }
1.174 matthew 2479: }
1.165 raeburn 2480: my $argfield = 'null';
1.591 raeburn 2481: if (defined($in{'mode'})) {
1.165 raeburn 2482: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2483: if (defined($in{'curr_autharg'})) {
2484: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2485: $argfield = "'$in{'curr_autharg'}'";
2486: }
2487: }
2488: }
2489: }
2490:
1.32 matthew 2491: $result.=<<"END";
2492: var current = new Object();
1.165 raeburn 2493: current.radiovalue = $radioval;
2494: current.argfield = $argfield;
1.32 matthew 2495:
2496: function changed_radio(choice,currentform) {
2497: var choicearg = choice + 'arg';
2498: // If a radio button in changed, we need to change the argfield
2499: if (current.radiovalue != choice) {
2500: current.radiovalue = choice;
2501: if (current.argfield != null) {
2502: currentform.elements[current.argfield].value = '';
2503: }
2504: if (choice == 'nochange') {
2505: current.argfield = null;
2506: } else {
2507: current.argfield = choicearg;
2508: switch(choice) {
2509: case 'krb':
2510: currentform.elements[current.argfield].value =
2511: "$in{'kerb_def_dom'}";
2512: break;
2513: default:
2514: break;
2515: }
2516: }
2517: }
2518: return;
2519: }
1.22 www 2520:
1.32 matthew 2521: function changed_text(choice,currentform) {
2522: var choicearg = choice + 'arg';
2523: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2524: $Javascript_toUpperCase
1.32 matthew 2525: // clear old field
2526: if ((current.argfield != choicearg) && (current.argfield != null)) {
2527: currentform.elements[current.argfield].value = '';
2528: }
2529: current.argfield = choicearg;
2530: }
2531: set_auth_radio_buttons(choice,currentform);
2532: return;
1.20 www 2533: }
1.32 matthew 2534:
2535: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2536: var numauthchoices = currentform.login.length;
2537: if (typeof numauthchoices == "undefined") {
2538: return;
2539: }
1.32 matthew 2540: var i=0;
1.986 raeburn 2541: while (i < numauthchoices) {
1.32 matthew 2542: if (currentform.login[i].value == newvalue) { break; }
2543: i++;
2544: }
1.986 raeburn 2545: if (i == numauthchoices) {
1.32 matthew 2546: return;
2547: }
2548: current.radiovalue = newvalue;
2549: currentform.login[i].checked = true;
2550: return;
2551: }
2552: END
2553: return $result;
2554: }
2555:
1.1075.2.20 raeburn 2556: sub authform_authorwarning {
1.32 matthew 2557: my $result='';
1.144 matthew 2558: $result='<i>'.
2559: &mt('As a general rule, only authors or co-authors should be '.
2560: 'filesystem authenticated '.
2561: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2562: return $result;
2563: }
2564:
1.1075.2.20 raeburn 2565: sub authform_nochange {
1.32 matthew 2566: my %in = (
2567: formname => 'document.cu',
2568: kerb_def_dom => 'MSU.EDU',
2569: @_,
2570: );
1.1075.2.20 raeburn 2571: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2572: my $result;
1.1075.2.20 raeburn 2573: if (!$authnum) {
2574: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2575: } else {
2576: $result = '<label>'.&mt('[_1] Do not change login data',
2577: '<input type="radio" name="login" value="nochange" '.
2578: 'checked="checked" onclick="'.
1.281 albertel 2579: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2580: '</label>';
1.586 raeburn 2581: }
1.32 matthew 2582: return $result;
2583: }
2584:
1.591 raeburn 2585: sub authform_kerberos {
1.32 matthew 2586: my %in = (
2587: formname => 'document.cu',
2588: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2589: kerb_def_auth => 'krb4',
1.32 matthew 2590: @_,
2591: );
1.586 raeburn 2592: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2593: $autharg,$jscall);
1.1075.2.20 raeburn 2594: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2595: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2596: $check5 = ' checked="checked"';
1.80 albertel 2597: } else {
1.772 bisitz 2598: $check4 = ' checked="checked"';
1.80 albertel 2599: }
1.165 raeburn 2600: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2601: if (defined($in{'curr_authtype'})) {
2602: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2603: $krbcheck = ' checked="checked"';
1.623 raeburn 2604: if (defined($in{'mode'})) {
2605: if ($in{'mode'} eq 'modifyuser') {
2606: $krbcheck = '';
2607: }
2608: }
1.591 raeburn 2609: if (defined($in{'curr_kerb_ver'})) {
2610: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2611: $check5 = ' checked="checked"';
1.591 raeburn 2612: $check4 = '';
2613: } else {
1.772 bisitz 2614: $check4 = ' checked="checked"';
1.591 raeburn 2615: $check5 = '';
2616: }
1.586 raeburn 2617: }
1.591 raeburn 2618: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2619: $krbarg = $in{'curr_autharg'};
2620: }
1.586 raeburn 2621: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2622: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2623: $result =
2624: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2625: $in{'curr_autharg'},$krbver);
2626: } else {
2627: $result =
2628: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2629: }
2630: return $result;
2631: }
2632: }
2633: } else {
2634: if ($authnum == 1) {
1.784 bisitz 2635: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2636: }
2637: }
1.586 raeburn 2638: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2639: return;
1.587 raeburn 2640: } elsif ($authtype eq '') {
1.591 raeburn 2641: if (defined($in{'mode'})) {
1.587 raeburn 2642: if ($in{'mode'} eq 'modifycourse') {
2643: if ($authnum == 1) {
1.1075.2.20 raeburn 2644: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2645: }
2646: }
2647: }
1.586 raeburn 2648: }
2649: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2650: if ($authtype eq '') {
2651: $authtype = '<input type="radio" name="login" value="krb" '.
2652: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2653: $krbcheck.' />';
2654: }
2655: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2656: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2657: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2658: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2659: $in{'curr_authtype'} eq 'krb4')) {
2660: $result .= &mt
1.144 matthew 2661: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2662: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2663: '<label>'.$authtype,
1.281 albertel 2664: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2665: 'value="'.$krbarg.'" '.
1.144 matthew 2666: 'onchange="'.$jscall.'" />',
1.281 albertel 2667: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2668: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2669: '</label>');
1.586 raeburn 2670: } elsif ($can_assign{'krb4'}) {
2671: $result .= &mt
2672: ('[_1] Kerberos authenticated with domain [_2] '.
2673: '[_3] Version 4 [_4]',
2674: '<label>'.$authtype,
2675: '</label><input type="text" size="10" name="krbarg" '.
2676: 'value="'.$krbarg.'" '.
2677: 'onchange="'.$jscall.'" />',
2678: '<label><input type="hidden" name="krbver" value="4" />',
2679: '</label>');
2680: } elsif ($can_assign{'krb5'}) {
2681: $result .= &mt
2682: ('[_1] Kerberos authenticated with domain [_2] '.
2683: '[_3] Version 5 [_4]',
2684: '<label>'.$authtype,
2685: '</label><input type="text" size="10" name="krbarg" '.
2686: 'value="'.$krbarg.'" '.
2687: 'onchange="'.$jscall.'" />',
2688: '<label><input type="hidden" name="krbver" value="5" />',
2689: '</label>');
2690: }
1.32 matthew 2691: return $result;
2692: }
2693:
1.1075.2.20 raeburn 2694: sub authform_internal {
1.586 raeburn 2695: my %in = (
1.32 matthew 2696: formname => 'document.cu',
2697: kerb_def_dom => 'MSU.EDU',
2698: @_,
2699: );
1.586 raeburn 2700: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2701: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2702: if (defined($in{'curr_authtype'})) {
2703: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2704: if ($can_assign{'int'}) {
1.772 bisitz 2705: $intcheck = 'checked="checked" ';
1.623 raeburn 2706: if (defined($in{'mode'})) {
2707: if ($in{'mode'} eq 'modifyuser') {
2708: $intcheck = '';
2709: }
2710: }
1.591 raeburn 2711: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2712: $intarg = $in{'curr_autharg'};
2713: }
2714: } else {
2715: $result = &mt('Currently internally authenticated.');
2716: return $result;
1.165 raeburn 2717: }
2718: }
1.586 raeburn 2719: } else {
2720: if ($authnum == 1) {
1.784 bisitz 2721: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2722: }
2723: }
2724: if (!$can_assign{'int'}) {
2725: return;
1.587 raeburn 2726: } elsif ($authtype eq '') {
1.591 raeburn 2727: if (defined($in{'mode'})) {
1.587 raeburn 2728: if ($in{'mode'} eq 'modifycourse') {
2729: if ($authnum == 1) {
1.1075.2.20 raeburn 2730: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2731: }
2732: }
2733: }
1.165 raeburn 2734: }
1.586 raeburn 2735: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2736: if ($authtype eq '') {
2737: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2738: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2739: }
1.605 bisitz 2740: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2741: $intarg.'" onchange="'.$jscall.'" />';
2742: $result = &mt
1.144 matthew 2743: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2744: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2745: $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 2746: return $result;
2747: }
2748:
1.1075.2.20 raeburn 2749: sub authform_local {
1.32 matthew 2750: my %in = (
2751: formname => 'document.cu',
2752: kerb_def_dom => 'MSU.EDU',
2753: @_,
2754: );
1.586 raeburn 2755: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2756: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2757: if (defined($in{'curr_authtype'})) {
2758: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2759: if ($can_assign{'loc'}) {
1.772 bisitz 2760: $loccheck = 'checked="checked" ';
1.623 raeburn 2761: if (defined($in{'mode'})) {
2762: if ($in{'mode'} eq 'modifyuser') {
2763: $loccheck = '';
2764: }
2765: }
1.591 raeburn 2766: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2767: $locarg = $in{'curr_autharg'};
2768: }
2769: } else {
2770: $result = &mt('Currently using local (institutional) authentication.');
2771: return $result;
1.165 raeburn 2772: }
2773: }
1.586 raeburn 2774: } else {
2775: if ($authnum == 1) {
1.784 bisitz 2776: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2777: }
2778: }
2779: if (!$can_assign{'loc'}) {
2780: return;
1.587 raeburn 2781: } elsif ($authtype eq '') {
1.591 raeburn 2782: if (defined($in{'mode'})) {
1.587 raeburn 2783: if ($in{'mode'} eq 'modifycourse') {
2784: if ($authnum == 1) {
1.1075.2.20 raeburn 2785: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2786: }
2787: }
2788: }
1.165 raeburn 2789: }
1.586 raeburn 2790: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2791: if ($authtype eq '') {
2792: $authtype = '<input type="radio" name="login" value="loc" '.
2793: $loccheck.' onchange="'.$jscall.'" onclick="'.
2794: $jscall.'" />';
2795: }
2796: $autharg = '<input type="text" size="10" name="locarg" value="'.
2797: $locarg.'" onchange="'.$jscall.'" />';
2798: $result = &mt('[_1] Local Authentication with argument [_2]',
2799: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2800: return $result;
2801: }
2802:
1.1075.2.20 raeburn 2803: sub authform_filesystem {
1.32 matthew 2804: my %in = (
2805: formname => 'document.cu',
2806: kerb_def_dom => 'MSU.EDU',
2807: @_,
2808: );
1.586 raeburn 2809: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2810: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2811: if (defined($in{'curr_authtype'})) {
2812: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2813: if ($can_assign{'fsys'}) {
1.772 bisitz 2814: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2815: if (defined($in{'mode'})) {
2816: if ($in{'mode'} eq 'modifyuser') {
2817: $fsyscheck = '';
2818: }
2819: }
1.586 raeburn 2820: } else {
2821: $result = &mt('Currently Filesystem Authenticated.');
2822: return $result;
2823: }
2824: }
2825: } else {
2826: if ($authnum == 1) {
1.784 bisitz 2827: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2828: }
2829: }
2830: if (!$can_assign{'fsys'}) {
2831: return;
1.587 raeburn 2832: } elsif ($authtype eq '') {
1.591 raeburn 2833: if (defined($in{'mode'})) {
1.587 raeburn 2834: if ($in{'mode'} eq 'modifycourse') {
2835: if ($authnum == 1) {
1.1075.2.20 raeburn 2836: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2837: }
2838: }
2839: }
1.586 raeburn 2840: }
2841: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2842: if ($authtype eq '') {
2843: $authtype = '<input type="radio" name="login" value="fsys" '.
2844: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2845: $jscall.'" />';
2846: }
2847: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2848: ' onchange="'.$jscall.'" />';
2849: $result = &mt
1.144 matthew 2850: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2851: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2852: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2853: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2854: 'onchange="'.$jscall.'" />');
1.32 matthew 2855: return $result;
2856: }
2857:
1.586 raeburn 2858: sub get_assignable_auth {
2859: my ($dom) = @_;
2860: if ($dom eq '') {
2861: $dom = $env{'request.role.domain'};
2862: }
2863: my %can_assign = (
2864: krb4 => 1,
2865: krb5 => 1,
2866: int => 1,
2867: loc => 1,
2868: );
2869: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2870: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2871: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2872: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2873: my $context;
2874: if ($env{'request.role'} =~ /^au/) {
2875: $context = 'author';
2876: } elsif ($env{'request.role'} =~ /^dc/) {
2877: $context = 'domain';
2878: } elsif ($env{'request.course.id'}) {
2879: $context = 'course';
2880: }
2881: if ($context) {
2882: if (ref($authhash->{$context}) eq 'HASH') {
2883: %can_assign = %{$authhash->{$context}};
2884: }
2885: }
2886: }
2887: }
2888: my $authnum = 0;
2889: foreach my $key (keys(%can_assign)) {
2890: if ($can_assign{$key}) {
2891: $authnum ++;
2892: }
2893: }
2894: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2895: $authnum --;
2896: }
2897: return ($authnum,%can_assign);
2898: }
2899:
1.80 albertel 2900: ###############################################################
2901: ## Get Kerberos Defaults for Domain ##
2902: ###############################################################
2903: ##
2904: ## Returns default kerberos version and an associated argument
2905: ## as listed in file domain.tab. If not listed, provides
2906: ## appropriate default domain and kerberos version.
2907: ##
2908: #-------------------------------------------
2909:
2910: =pod
2911:
1.648 raeburn 2912: =item * &get_kerberos_defaults()
1.80 albertel 2913:
2914: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2915: version and domain. If not found, it defaults to version 4 and the
2916: domain of the server.
1.80 albertel 2917:
1.648 raeburn 2918: =over 4
2919:
1.80 albertel 2920: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2921:
1.648 raeburn 2922: =back
2923:
2924: =back
2925:
1.80 albertel 2926: =cut
2927:
2928: #-------------------------------------------
2929: sub get_kerberos_defaults {
2930: my $domain=shift;
1.641 raeburn 2931: my ($krbdef,$krbdefdom);
2932: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2933: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2934: $krbdef = $domdefaults{'auth_def'};
2935: $krbdefdom = $domdefaults{'auth_arg_def'};
2936: } else {
1.80 albertel 2937: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2938: my $krbdefdom=$1;
2939: $krbdefdom=~tr/a-z/A-Z/;
2940: $krbdef = "krb4";
2941: }
2942: return ($krbdef,$krbdefdom);
2943: }
1.112 bowersj2 2944:
1.32 matthew 2945:
1.46 matthew 2946: ###############################################################
2947: ## Thesaurus Functions ##
2948: ###############################################################
1.20 www 2949:
1.46 matthew 2950: =pod
1.20 www 2951:
1.112 bowersj2 2952: =head1 Thesaurus Functions
2953:
2954: =over 4
2955:
1.648 raeburn 2956: =item * &initialize_keywords()
1.46 matthew 2957:
2958: Initializes the package variable %Keywords if it is empty. Uses the
2959: package variable $thesaurus_db_file.
2960:
2961: =cut
2962:
2963: ###################################################
2964:
2965: sub initialize_keywords {
2966: return 1 if (scalar keys(%Keywords));
2967: # If we are here, %Keywords is empty, so fill it up
2968: # Make sure the file we need exists...
2969: if (! -e $thesaurus_db_file) {
2970: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2971: " failed because it does not exist");
2972: return 0;
2973: }
2974: # Set up the hash as a database
2975: my %thesaurus_db;
2976: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2977: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2978: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2979: $thesaurus_db_file);
2980: return 0;
2981: }
2982: # Get the average number of appearances of a word.
2983: my $avecount = $thesaurus_db{'average.count'};
2984: # Put keywords (those that appear > average) into %Keywords
2985: while (my ($word,$data)=each (%thesaurus_db)) {
2986: my ($count,undef) = split /:/,$data;
2987: $Keywords{$word}++ if ($count > $avecount);
2988: }
2989: untie %thesaurus_db;
2990: # Remove special values from %Keywords.
1.356 albertel 2991: foreach my $value ('total.count','average.count') {
2992: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2993: }
1.46 matthew 2994: return 1;
2995: }
2996:
2997: ###################################################
2998:
2999: =pod
3000:
1.648 raeburn 3001: =item * &keyword($word)
1.46 matthew 3002:
3003: Returns true if $word is a keyword. A keyword is a word that appears more
3004: than the average number of times in the thesaurus database. Calls
3005: &initialize_keywords
3006:
3007: =cut
3008:
3009: ###################################################
1.20 www 3010:
3011: sub keyword {
1.46 matthew 3012: return if (!&initialize_keywords());
3013: my $word=lc(shift());
3014: $word=~s/\W//g;
3015: return exists($Keywords{$word});
1.20 www 3016: }
1.46 matthew 3017:
3018: ###############################################################
3019:
3020: =pod
1.20 www 3021:
1.648 raeburn 3022: =item * &get_related_words()
1.46 matthew 3023:
1.160 matthew 3024: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3025: an array of words. If the keyword is not in the thesaurus, an empty array
3026: will be returned. The order of the words returned is determined by the
3027: database which holds them.
3028:
3029: Uses global $thesaurus_db_file.
3030:
1.1057 foxr 3031:
1.46 matthew 3032: =cut
3033:
3034: ###############################################################
3035: sub get_related_words {
3036: my $keyword = shift;
3037: my %thesaurus_db;
3038: if (! -e $thesaurus_db_file) {
3039: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3040: "failed because the file does not exist");
3041: return ();
3042: }
3043: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3044: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3045: return ();
3046: }
3047: my @Words=();
1.429 www 3048: my $count=0;
1.46 matthew 3049: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3050: # The first element is the number of times
3051: # the word appears. We do not need it now.
1.429 www 3052: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3053: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3054: my $threshold=$mostfrequentcount/10;
3055: foreach my $possibleword (@RelatedWords) {
3056: my ($word,$wordcount)=split(/\,/,$possibleword);
3057: if ($wordcount>$threshold) {
3058: push(@Words,$word);
3059: $count++;
3060: if ($count>10) { last; }
3061: }
1.20 www 3062: }
3063: }
1.46 matthew 3064: untie %thesaurus_db;
3065: return @Words;
1.14 harris41 3066: }
1.46 matthew 3067:
1.112 bowersj2 3068: =pod
3069:
3070: =back
3071:
3072: =cut
1.61 www 3073:
3074: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3075: =pod
3076:
1.112 bowersj2 3077: =head1 User Name Functions
3078:
3079: =over 4
3080:
1.648 raeburn 3081: =item * &plainname($uname,$udom,$first)
1.81 albertel 3082:
1.112 bowersj2 3083: Takes a users logon name and returns it as a string in
1.226 albertel 3084: "first middle last generation" form
3085: if $first is set to 'lastname' then it returns it as
3086: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3087:
3088: =cut
1.61 www 3089:
1.295 www 3090:
1.81 albertel 3091: ###############################################################
1.61 www 3092: sub plainname {
1.226 albertel 3093: my ($uname,$udom,$first)=@_;
1.537 albertel 3094: return if (!defined($uname) || !defined($udom));
1.295 www 3095: my %names=&getnames($uname,$udom);
1.226 albertel 3096: my $name=&Apache::lonnet::format_name($names{'firstname'},
3097: $names{'middlename'},
3098: $names{'lastname'},
3099: $names{'generation'},$first);
3100: $name=~s/^\s+//;
1.62 www 3101: $name=~s/\s+$//;
3102: $name=~s/\s+/ /g;
1.353 albertel 3103: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3104: return $name;
1.61 www 3105: }
1.66 www 3106:
3107: # -------------------------------------------------------------------- Nickname
1.81 albertel 3108: =pod
3109:
1.648 raeburn 3110: =item * &nickname($uname,$udom)
1.81 albertel 3111:
3112: Gets a users name and returns it as a string as
3113:
3114: ""nickname""
1.66 www 3115:
1.81 albertel 3116: if the user has a nickname or
3117:
3118: "first middle last generation"
3119:
3120: if the user does not
3121:
3122: =cut
1.66 www 3123:
3124: sub nickname {
3125: my ($uname,$udom)=@_;
1.537 albertel 3126: return if (!defined($uname) || !defined($udom));
1.295 www 3127: my %names=&getnames($uname,$udom);
1.68 albertel 3128: my $name=$names{'nickname'};
1.66 www 3129: if ($name) {
3130: $name='"'.$name.'"';
3131: } else {
3132: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3133: $names{'lastname'}.' '.$names{'generation'};
3134: $name=~s/\s+$//;
3135: $name=~s/\s+/ /g;
3136: }
3137: return $name;
3138: }
3139:
1.295 www 3140: sub getnames {
3141: my ($uname,$udom)=@_;
1.537 albertel 3142: return if (!defined($uname) || !defined($udom));
1.433 albertel 3143: if ($udom eq 'public' && $uname eq 'public') {
3144: return ('lastname' => &mt('Public'));
3145: }
1.295 www 3146: my $id=$uname.':'.$udom;
3147: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3148: if ($cached) {
3149: return %{$names};
3150: } else {
3151: my %loadnames=&Apache::lonnet::get('environment',
3152: ['firstname','middlename','lastname','generation','nickname'],
3153: $udom,$uname);
3154: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3155: return %loadnames;
3156: }
3157: }
1.61 www 3158:
1.542 raeburn 3159: # -------------------------------------------------------------------- getemails
1.648 raeburn 3160:
1.542 raeburn 3161: =pod
3162:
1.648 raeburn 3163: =item * &getemails($uname,$udom)
1.542 raeburn 3164:
3165: Gets a user's email information and returns it as a hash with keys:
3166: notification, critnotification, permanentemail
3167:
3168: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3169: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3170:
1.648 raeburn 3171:
1.542 raeburn 3172: =cut
3173:
1.648 raeburn 3174:
1.466 albertel 3175: sub getemails {
3176: my ($uname,$udom)=@_;
3177: if ($udom eq 'public' && $uname eq 'public') {
3178: return;
3179: }
1.467 www 3180: if (!$udom) { $udom=$env{'user.domain'}; }
3181: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3182: my $id=$uname.':'.$udom;
3183: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3184: if ($cached) {
3185: return %{$names};
3186: } else {
3187: my %loadnames=&Apache::lonnet::get('environment',
3188: ['notification','critnotification',
3189: 'permanentemail'],
3190: $udom,$uname);
3191: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3192: return %loadnames;
3193: }
3194: }
3195:
1.551 albertel 3196: sub flush_email_cache {
3197: my ($uname,$udom)=@_;
3198: if (!$udom) { $udom =$env{'user.domain'}; }
3199: if (!$uname) { $uname=$env{'user.name'}; }
3200: return if ($udom eq 'public' && $uname eq 'public');
3201: my $id=$uname.':'.$udom;
3202: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3203: }
3204:
1.728 raeburn 3205: # -------------------------------------------------------------------- getlangs
3206:
3207: =pod
3208:
3209: =item * &getlangs($uname,$udom)
3210:
3211: Gets a user's language preference and returns it as a hash with key:
3212: language.
3213:
3214: =cut
3215:
3216:
3217: sub getlangs {
3218: my ($uname,$udom) = @_;
3219: if (!$udom) { $udom =$env{'user.domain'}; }
3220: if (!$uname) { $uname=$env{'user.name'}; }
3221: my $id=$uname.':'.$udom;
3222: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3223: if ($cached) {
3224: return %{$langs};
3225: } else {
3226: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3227: $udom,$uname);
3228: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3229: return %loadlangs;
3230: }
3231: }
3232:
3233: sub flush_langs_cache {
3234: my ($uname,$udom)=@_;
3235: if (!$udom) { $udom =$env{'user.domain'}; }
3236: if (!$uname) { $uname=$env{'user.name'}; }
3237: return if ($udom eq 'public' && $uname eq 'public');
3238: my $id=$uname.':'.$udom;
3239: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3240: }
3241:
1.61 www 3242: # ------------------------------------------------------------------ Screenname
1.81 albertel 3243:
3244: =pod
3245:
1.648 raeburn 3246: =item * &screenname($uname,$udom)
1.81 albertel 3247:
3248: Gets a users screenname and returns it as a string
3249:
3250: =cut
1.61 www 3251:
3252: sub screenname {
3253: my ($uname,$udom)=@_;
1.258 albertel 3254: if ($uname eq $env{'user.name'} &&
3255: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3256: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3257: return $names{'screenname'};
1.62 www 3258: }
3259:
1.212 albertel 3260:
1.802 bisitz 3261: # ------------------------------------------------------------- Confirm Wrapper
3262: =pod
3263:
1.1075.2.42 raeburn 3264: =item * &confirmwrapper($message)
1.802 bisitz 3265:
3266: Wrap messages about completion of operation in box
3267:
3268: =cut
3269:
3270: sub confirmwrapper {
3271: my ($message)=@_;
3272: if ($message) {
3273: return "\n".'<div class="LC_confirm_box">'."\n"
3274: .$message."\n"
3275: .'</div>'."\n";
3276: } else {
3277: return $message;
3278: }
3279: }
3280:
1.62 www 3281: # ------------------------------------------------------------- Message Wrapper
3282:
3283: sub messagewrapper {
1.369 www 3284: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3285: return
1.441 albertel 3286: '<a href="/adm/email?compose=individual&'.
3287: 'recname='.$username.'&recdom='.$domain.
3288: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3289: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3290: }
1.802 bisitz 3291:
1.74 www 3292: # --------------------------------------------------------------- Notes Wrapper
3293:
3294: sub noteswrapper {
3295: my ($link,$un,$do)=@_;
3296: return
1.896 amueller 3297: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3298: }
1.802 bisitz 3299:
1.62 www 3300: # ------------------------------------------------------------- Aboutme Wrapper
3301:
3302: sub aboutmewrapper {
1.1070 raeburn 3303: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3304: if (!defined($username) && !defined($domain)) {
3305: return;
3306: }
1.1075.2.15 raeburn 3307: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3308: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3309: }
3310:
3311: # ------------------------------------------------------------ Syllabus Wrapper
3312:
3313: sub syllabuswrapper {
1.707 bisitz 3314: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3315: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3316: }
1.14 harris41 3317:
1.802 bisitz 3318: # -----------------------------------------------------------------------------
3319:
1.208 matthew 3320: sub track_student_link {
1.887 raeburn 3321: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3322: my $link ="/adm/trackstudent?";
1.208 matthew 3323: my $title = 'View recent activity';
3324: if (defined($sname) && $sname !~ /^\s*$/ &&
3325: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3326: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3327: $title .= ' of this student';
1.268 albertel 3328: }
1.208 matthew 3329: if (defined($target) && $target !~ /^\s*$/) {
3330: $target = qq{target="$target"};
3331: } else {
3332: $target = '';
3333: }
1.268 albertel 3334: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3335: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3336: $title = &mt($title);
3337: $linktext = &mt($linktext);
1.448 albertel 3338: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3339: &help_open_topic('View_recent_activity');
1.208 matthew 3340: }
3341:
1.781 raeburn 3342: sub slot_reservations_link {
3343: my ($linktext,$sname,$sdom,$target) = @_;
3344: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3345: my $title = 'View slot reservation history';
3346: if (defined($sname) && $sname !~ /^\s*$/ &&
3347: defined($sdom) && $sdom !~ /^\s*$/) {
3348: $link .= "&uname=$sname&udom=$sdom";
3349: $title .= ' of this student';
3350: }
3351: if (defined($target) && $target !~ /^\s*$/) {
3352: $target = qq{target="$target"};
3353: } else {
3354: $target = '';
3355: }
3356: $title = &mt($title);
3357: $linktext = &mt($linktext);
3358: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3359: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3360:
3361: }
3362:
1.508 www 3363: # ===================================================== Display a student photo
3364:
3365:
1.509 albertel 3366: sub student_image_tag {
1.508 www 3367: my ($domain,$user)=@_;
3368: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3369: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3370: return '<img src="'.$imgsrc.'" align="right" />';
3371: } else {
3372: return '';
3373: }
3374: }
3375:
1.112 bowersj2 3376: =pod
3377:
3378: =back
3379:
3380: =head1 Access .tab File Data
3381:
3382: =over 4
3383:
1.648 raeburn 3384: =item * &languageids()
1.112 bowersj2 3385:
3386: returns list of all language ids
3387:
3388: =cut
3389:
1.14 harris41 3390: sub languageids {
1.16 harris41 3391: return sort(keys(%language));
1.14 harris41 3392: }
3393:
1.112 bowersj2 3394: =pod
3395:
1.648 raeburn 3396: =item * &languagedescription()
1.112 bowersj2 3397:
3398: returns description of a specified language id
3399:
3400: =cut
3401:
1.14 harris41 3402: sub languagedescription {
1.125 www 3403: my $code=shift;
3404: return ($supported_language{$code}?'* ':'').
3405: $language{$code}.
1.126 www 3406: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3407: }
3408:
1.1048 foxr 3409: =pod
3410:
3411: =item * &plainlanguagedescription
3412:
3413: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3414: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3415:
3416: =cut
3417:
1.145 www 3418: sub plainlanguagedescription {
3419: my $code=shift;
3420: return $language{$code};
3421: }
3422:
1.1048 foxr 3423: =pod
3424:
3425: =item * &supportedlanguagecode
3426:
3427: Returns the supported language code (e.g. sptutf maps to pt) given a language
3428: code.
3429:
3430: =cut
3431:
1.145 www 3432: sub supportedlanguagecode {
3433: my $code=shift;
3434: return $supported_language{$code};
1.97 www 3435: }
3436:
1.112 bowersj2 3437: =pod
3438:
1.1048 foxr 3439: =item * &latexlanguage()
3440:
3441: Given a language key code returns the correspondnig language to use
3442: to select the correct hyphenation on LaTeX printouts. This is undef if there
3443: is no supported hyphenation for the language code.
3444:
3445: =cut
3446:
3447: sub latexlanguage {
3448: my $code = shift;
3449: return $latex_language{$code};
3450: }
3451:
3452: =pod
3453:
3454: =item * &latexhyphenation()
3455:
3456: Same as above but what's supplied is the language as it might be stored
3457: in the metadata.
3458:
3459: =cut
3460:
3461: sub latexhyphenation {
3462: my $key = shift;
3463: return $latex_language_bykey{$key};
3464: }
3465:
3466: =pod
3467:
1.648 raeburn 3468: =item * ©rightids()
1.112 bowersj2 3469:
3470: returns list of all copyrights
3471:
3472: =cut
3473:
3474: sub copyrightids {
3475: return sort(keys(%cprtag));
3476: }
3477:
3478: =pod
3479:
1.648 raeburn 3480: =item * ©rightdescription()
1.112 bowersj2 3481:
3482: returns description of a specified copyright id
3483:
3484: =cut
3485:
3486: sub copyrightdescription {
1.166 www 3487: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3488: }
1.197 matthew 3489:
3490: =pod
3491:
1.648 raeburn 3492: =item * &source_copyrightids()
1.192 taceyjo1 3493:
3494: returns list of all source copyrights
3495:
3496: =cut
3497:
3498: sub source_copyrightids {
3499: return sort(keys(%scprtag));
3500: }
3501:
3502: =pod
3503:
1.648 raeburn 3504: =item * &source_copyrightdescription()
1.192 taceyjo1 3505:
3506: returns description of a specified source copyright id
3507:
3508: =cut
3509:
3510: sub source_copyrightdescription {
3511: return &mt($scprtag{shift(@_)});
3512: }
1.112 bowersj2 3513:
3514: =pod
3515:
1.648 raeburn 3516: =item * &filecategories()
1.112 bowersj2 3517:
3518: returns list of all file categories
3519:
3520: =cut
3521:
3522: sub filecategories {
3523: return sort(keys(%category_extensions));
3524: }
3525:
3526: =pod
3527:
1.648 raeburn 3528: =item * &filecategorytypes()
1.112 bowersj2 3529:
3530: returns list of file types belonging to a given file
3531: category
3532:
3533: =cut
3534:
3535: sub filecategorytypes {
1.356 albertel 3536: my ($cat) = @_;
3537: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3538: }
3539:
3540: =pod
3541:
1.648 raeburn 3542: =item * &fileembstyle()
1.112 bowersj2 3543:
3544: returns embedding style for a specified file type
3545:
3546: =cut
3547:
3548: sub fileembstyle {
3549: return $fe{lc(shift(@_))};
1.169 www 3550: }
3551:
1.351 www 3552: sub filemimetype {
3553: return $fm{lc(shift(@_))};
3554: }
3555:
1.169 www 3556:
3557: sub filecategoryselect {
3558: my ($name,$value)=@_;
1.189 matthew 3559: return &select_form($value,$name,
1.970 raeburn 3560: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3561: }
3562:
3563: =pod
3564:
1.648 raeburn 3565: =item * &filedescription()
1.112 bowersj2 3566:
3567: returns description for a specified file type
3568:
3569: =cut
3570:
3571: sub filedescription {
1.188 matthew 3572: my $file_description = $fd{lc(shift())};
3573: $file_description =~ s:([\[\]]):~$1:g;
3574: return &mt($file_description);
1.112 bowersj2 3575: }
3576:
3577: =pod
3578:
1.648 raeburn 3579: =item * &filedescriptionex()
1.112 bowersj2 3580:
3581: returns description for a specified file type with
3582: extra formatting
3583:
3584: =cut
3585:
3586: sub filedescriptionex {
3587: my $ex=shift;
1.188 matthew 3588: my $file_description = $fd{lc($ex)};
3589: $file_description =~ s:([\[\]]):~$1:g;
3590: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3591: }
3592:
3593: # End of .tab access
3594: =pod
3595:
3596: =back
3597:
3598: =cut
3599:
3600: # ------------------------------------------------------------------ File Types
3601: sub fileextensions {
3602: return sort(keys(%fe));
3603: }
3604:
1.97 www 3605: # ----------------------------------------------------------- Display Languages
3606: # returns a hash with all desired display languages
3607: #
3608:
3609: sub display_languages {
3610: my %languages=();
1.695 raeburn 3611: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3612: $languages{$lang}=1;
1.97 www 3613: }
3614: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3615: if ($env{'form.displaylanguage'}) {
1.356 albertel 3616: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3617: $languages{$lang}=1;
1.97 www 3618: }
3619: }
3620: return %languages;
1.14 harris41 3621: }
3622:
1.582 albertel 3623: sub languages {
3624: my ($possible_langs) = @_;
1.695 raeburn 3625: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3626: if (!ref($possible_langs)) {
3627: if( wantarray ) {
3628: return @preferred_langs;
3629: } else {
3630: return $preferred_langs[0];
3631: }
3632: }
3633: my %possibilities = map { $_ => 1 } (@$possible_langs);
3634: my @preferred_possibilities;
3635: foreach my $preferred_lang (@preferred_langs) {
3636: if (exists($possibilities{$preferred_lang})) {
3637: push(@preferred_possibilities, $preferred_lang);
3638: }
3639: }
3640: if( wantarray ) {
3641: return @preferred_possibilities;
3642: }
3643: return $preferred_possibilities[0];
3644: }
3645:
1.742 raeburn 3646: sub user_lang {
3647: my ($touname,$toudom,$fromcid) = @_;
3648: my @userlangs;
3649: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3650: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3651: $env{'course.'.$fromcid.'.languages'}));
3652: } else {
3653: my %langhash = &getlangs($touname,$toudom);
3654: if ($langhash{'languages'} ne '') {
3655: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3656: } else {
3657: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3658: if ($domdefs{'lang_def'} ne '') {
3659: @userlangs = ($domdefs{'lang_def'});
3660: }
3661: }
3662: }
3663: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3664: my $user_lh = Apache::localize->get_handle(@languages);
3665: return $user_lh;
3666: }
3667:
3668:
1.112 bowersj2 3669: ###############################################################
3670: ## Student Answer Attempts ##
3671: ###############################################################
3672:
3673: =pod
3674:
3675: =head1 Alternate Problem Views
3676:
3677: =over 4
3678:
1.648 raeburn 3679: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3680: $getattempt, $regexp, $gradesub)
3681:
3682: Return string with previous attempt on problem. Arguments:
3683:
3684: =over 4
3685:
3686: =item * $symb: Problem, including path
3687:
3688: =item * $username: username of the desired student
3689:
3690: =item * $domain: domain of the desired student
1.14 harris41 3691:
1.112 bowersj2 3692: =item * $course: Course ID
1.14 harris41 3693:
1.112 bowersj2 3694: =item * $getattempt: Leave blank for all attempts, otherwise put
3695: something
1.14 harris41 3696:
1.112 bowersj2 3697: =item * $regexp: if string matches this regexp, the string will be
3698: sent to $gradesub
1.14 harris41 3699:
1.112 bowersj2 3700: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3701:
1.112 bowersj2 3702: =back
1.14 harris41 3703:
1.112 bowersj2 3704: The output string is a table containing all desired attempts, if any.
1.16 harris41 3705:
1.112 bowersj2 3706: =cut
1.1 albertel 3707:
3708: sub get_previous_attempt {
1.43 ng 3709: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3710: my $prevattempts='';
1.43 ng 3711: no strict 'refs';
1.1 albertel 3712: if ($symb) {
1.3 albertel 3713: my (%returnhash)=
3714: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3715: if ($returnhash{'version'}) {
3716: my %lasthash=();
3717: my $version;
3718: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3719: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3720: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3721: }
1.1 albertel 3722: }
1.596 albertel 3723: $prevattempts=&start_data_table().&start_data_table_header_row();
3724: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3725: my (%typeparts,%lasthidden);
1.945 raeburn 3726: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3727: foreach my $key (sort(keys(%lasthash))) {
3728: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3729: if ($#parts > 0) {
1.31 albertel 3730: my $data=$parts[-1];
1.989 raeburn 3731: next if ($data eq 'foilorder');
1.31 albertel 3732: pop(@parts);
1.1010 www 3733: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3734: if ($data eq 'type') {
3735: unless ($showsurv) {
3736: my $id = join(',',@parts);
3737: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3738: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3739: $lasthidden{$ign.'.'.$id} = 1;
3740: }
1.945 raeburn 3741: }
1.1010 www 3742: }
1.31 albertel 3743: } else {
1.41 ng 3744: if ($#parts == 0) {
3745: $prevattempts.='<th>'.$parts[0].'</th>';
3746: } else {
3747: $prevattempts.='<th>'.$ign.'</th>';
3748: }
1.31 albertel 3749: }
1.16 harris41 3750: }
1.596 albertel 3751: $prevattempts.=&end_data_table_header_row();
1.40 ng 3752: if ($getattempt eq '') {
3753: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3754: my @hidden;
3755: if (%typeparts) {
3756: foreach my $id (keys(%typeparts)) {
3757: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3758: push(@hidden,$id);
3759: }
3760: }
3761: }
3762: $prevattempts.=&start_data_table_row().
3763: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3764: if (@hidden) {
3765: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3766: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3767: my $hide;
3768: foreach my $id (@hidden) {
3769: if ($key =~ /^\Q$id\E/) {
3770: $hide = 1;
3771: last;
3772: }
3773: }
3774: if ($hide) {
3775: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3776: if (($data eq 'award') || ($data eq 'awarddetail')) {
3777: my $value = &format_previous_attempt_value($key,
3778: $returnhash{$version.':'.$key});
3779: $prevattempts.='<td>'.$value.' </td>';
3780: } else {
3781: $prevattempts.='<td> </td>';
3782: }
3783: } else {
3784: if ($key =~ /\./) {
3785: my $value = &format_previous_attempt_value($key,
3786: $returnhash{$version.':'.$key});
3787: $prevattempts.='<td>'.$value.' </td>';
3788: } else {
3789: $prevattempts.='<td> </td>';
3790: }
3791: }
3792: }
3793: } else {
3794: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3795: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3796: my $value = &format_previous_attempt_value($key,
3797: $returnhash{$version.':'.$key});
3798: $prevattempts.='<td>'.$value.' </td>';
3799: }
3800: }
3801: $prevattempts.=&end_data_table_row();
1.40 ng 3802: }
1.1 albertel 3803: }
1.945 raeburn 3804: my @currhidden = keys(%lasthidden);
1.596 albertel 3805: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3806: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3807: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3808: if (%typeparts) {
3809: my $hidden;
3810: foreach my $id (@currhidden) {
3811: if ($key =~ /^\Q$id\E/) {
3812: $hidden = 1;
3813: last;
3814: }
3815: }
3816: if ($hidden) {
3817: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3818: if (($data eq 'award') || ($data eq 'awarddetail')) {
3819: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3820: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3821: $value = &$gradesub($value);
3822: }
3823: $prevattempts.='<td>'.$value.' </td>';
3824: } else {
3825: $prevattempts.='<td> </td>';
3826: }
3827: } else {
3828: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3829: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3830: $value = &$gradesub($value);
3831: }
3832: $prevattempts.='<td>'.$value.' </td>';
3833: }
3834: } else {
3835: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3836: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3837: $value = &$gradesub($value);
3838: }
3839: $prevattempts.='<td>'.$value.' </td>';
3840: }
1.16 harris41 3841: }
1.596 albertel 3842: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3843: } else {
1.596 albertel 3844: $prevattempts=
3845: &start_data_table().&start_data_table_row().
3846: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3847: &end_data_table_row().&end_data_table();
1.1 albertel 3848: }
3849: } else {
1.596 albertel 3850: $prevattempts=
3851: &start_data_table().&start_data_table_row().
3852: '<td>'.&mt('No data.').'</td>'.
3853: &end_data_table_row().&end_data_table();
1.1 albertel 3854: }
1.10 albertel 3855: }
3856:
1.581 albertel 3857: sub format_previous_attempt_value {
3858: my ($key,$value) = @_;
1.1011 www 3859: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3860: $value = &Apache::lonlocal::locallocaltime($value);
3861: } elsif (ref($value) eq 'ARRAY') {
3862: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3863: } elsif ($key =~ /answerstring$/) {
3864: my %answers = &Apache::lonnet::str2hash($value);
3865: my @anskeys = sort(keys(%answers));
3866: if (@anskeys == 1) {
3867: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3868: if ($answer =~ m{\0}) {
3869: $answer =~ s{\0}{,}g;
1.988 raeburn 3870: }
3871: my $tag_internal_answer_name = 'INTERNAL';
3872: if ($anskeys[0] eq $tag_internal_answer_name) {
3873: $value = $answer;
3874: } else {
3875: $value = $anskeys[0].'='.$answer;
3876: }
3877: } else {
3878: foreach my $ans (@anskeys) {
3879: my $answer = $answers{$ans};
1.1001 raeburn 3880: if ($answer =~ m{\0}) {
3881: $answer =~ s{\0}{,}g;
1.988 raeburn 3882: }
3883: $value .= $ans.'='.$answer.'<br />';;
3884: }
3885: }
1.581 albertel 3886: } else {
3887: $value = &unescape($value);
3888: }
3889: return $value;
3890: }
3891:
3892:
1.107 albertel 3893: sub relative_to_absolute {
3894: my ($url,$output)=@_;
3895: my $parser=HTML::TokeParser->new(\$output);
3896: my $token;
3897: my $thisdir=$url;
3898: my @rlinks=();
3899: while ($token=$parser->get_token) {
3900: if ($token->[0] eq 'S') {
3901: if ($token->[1] eq 'a') {
3902: if ($token->[2]->{'href'}) {
3903: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3904: }
3905: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3906: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3907: } elsif ($token->[1] eq 'base') {
3908: $thisdir=$token->[2]->{'href'};
3909: }
3910: }
3911: }
3912: $thisdir=~s-/[^/]*$--;
1.356 albertel 3913: foreach my $link (@rlinks) {
1.726 raeburn 3914: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3915: ($link=~/^\//) ||
3916: ($link=~/^javascript:/i) ||
3917: ($link=~/^mailto:/i) ||
3918: ($link=~/^\#/)) {
3919: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3920: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3921: }
3922: }
3923: # -------------------------------------------------- Deal with Applet codebases
3924: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3925: return $output;
3926: }
3927:
1.112 bowersj2 3928: =pod
3929:
1.648 raeburn 3930: =item * &get_student_view()
1.112 bowersj2 3931:
3932: show a snapshot of what student was looking at
3933:
3934: =cut
3935:
1.10 albertel 3936: sub get_student_view {
1.186 albertel 3937: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3938: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3939: my (%form);
1.10 albertel 3940: my @elements=('symb','courseid','domain','username');
3941: foreach my $element (@elements) {
1.186 albertel 3942: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3943: }
1.186 albertel 3944: if (defined($moreenv)) {
3945: %form=(%form,%{$moreenv});
3946: }
1.236 albertel 3947: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3948: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3949: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3950: $userview=~s/\<body[^\>]*\>//gi;
3951: $userview=~s/\<\/body\>//gi;
3952: $userview=~s/\<html\>//gi;
3953: $userview=~s/\<\/html\>//gi;
3954: $userview=~s/\<head\>//gi;
3955: $userview=~s/\<\/head\>//gi;
3956: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3957: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3958: if (wantarray) {
3959: return ($userview,$response);
3960: } else {
3961: return $userview;
3962: }
3963: }
3964:
3965: sub get_student_view_with_retries {
3966: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3967:
3968: my $ok = 0; # True if we got a good response.
3969: my $content;
3970: my $response;
3971:
3972: # Try to get the student_view done. within the retries count:
3973:
3974: do {
3975: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3976: $ok = $response->is_success;
3977: if (!$ok) {
3978: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3979: }
3980: $retries--;
3981: } while (!$ok && ($retries > 0));
3982:
3983: if (!$ok) {
3984: $content = ''; # On error return an empty content.
3985: }
1.651 www 3986: if (wantarray) {
3987: return ($content, $response);
3988: } else {
3989: return $content;
3990: }
1.11 albertel 3991: }
3992:
1.112 bowersj2 3993: =pod
3994:
1.648 raeburn 3995: =item * &get_student_answers()
1.112 bowersj2 3996:
3997: show a snapshot of how student was answering problem
3998:
3999: =cut
4000:
1.11 albertel 4001: sub get_student_answers {
1.100 sakharuk 4002: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4003: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4004: my (%moreenv);
1.11 albertel 4005: my @elements=('symb','courseid','domain','username');
4006: foreach my $element (@elements) {
1.186 albertel 4007: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4008: }
1.186 albertel 4009: $moreenv{'grade_target'}='answer';
4010: %moreenv=(%form,%moreenv);
1.497 raeburn 4011: $feedurl = &Apache::lonnet::clutter($feedurl);
4012: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4013: return $userview;
1.1 albertel 4014: }
1.116 albertel 4015:
4016: =pod
4017:
4018: =item * &submlink()
4019:
1.242 albertel 4020: Inputs: $text $uname $udom $symb $target
1.116 albertel 4021:
4022: Returns: A link to grades.pm such as to see the SUBM view of a student
4023:
4024: =cut
4025:
4026: ###############################################
4027: sub submlink {
1.242 albertel 4028: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4029: if (!($uname && $udom)) {
4030: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4031: &Apache::lonnet::whichuser($symb);
1.116 albertel 4032: if (!$symb) { $symb=$cursymb; }
4033: }
1.254 matthew 4034: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4035: $symb=&escape($symb);
1.960 bisitz 4036: if ($target) { $target=" target=\"$target\""; }
4037: return
4038: '<a href="/adm/grades?command=submission'.
4039: '&symb='.$symb.
4040: '&student='.$uname.
4041: '&userdom='.$udom.'"'.
4042: $target.'>'.$text.'</a>';
1.242 albertel 4043: }
4044: ##############################################
4045:
4046: =pod
4047:
4048: =item * &pgrdlink()
4049:
4050: Inputs: $text $uname $udom $symb $target
4051:
4052: Returns: A link to grades.pm such as to see the PGRD view of a student
4053:
4054: =cut
4055:
4056: ###############################################
4057: sub pgrdlink {
4058: my $link=&submlink(@_);
4059: $link=~s/(&command=submission)/$1&showgrading=yes/;
4060: return $link;
4061: }
4062: ##############################################
4063:
4064: =pod
4065:
4066: =item * &pprmlink()
4067:
4068: Inputs: $text $uname $udom $symb $target
4069:
4070: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4071: student and a specific resource
1.242 albertel 4072:
4073: =cut
4074:
4075: ###############################################
4076: sub pprmlink {
4077: my ($text,$uname,$udom,$symb,$target)=@_;
4078: if (!($uname && $udom)) {
4079: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4080: &Apache::lonnet::whichuser($symb);
1.242 albertel 4081: if (!$symb) { $symb=$cursymb; }
4082: }
1.254 matthew 4083: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4084: $symb=&escape($symb);
1.242 albertel 4085: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4086: return '<a href="/adm/parmset?command=set&'.
4087: 'symb='.$symb.'&uname='.$uname.
4088: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4089: }
4090: ##############################################
1.37 matthew 4091:
1.112 bowersj2 4092: =pod
4093:
4094: =back
4095:
4096: =cut
4097:
1.37 matthew 4098: ###############################################
1.51 www 4099:
4100:
4101: sub timehash {
1.687 raeburn 4102: my ($thistime) = @_;
4103: my $timezone = &Apache::lonlocal::gettimezone();
4104: my $dt = DateTime->from_epoch(epoch => $thistime)
4105: ->set_time_zone($timezone);
4106: my $wday = $dt->day_of_week();
4107: if ($wday == 7) { $wday = 0; }
4108: return ( 'second' => $dt->second(),
4109: 'minute' => $dt->minute(),
4110: 'hour' => $dt->hour(),
4111: 'day' => $dt->day_of_month(),
4112: 'month' => $dt->month(),
4113: 'year' => $dt->year(),
4114: 'weekday' => $wday,
4115: 'dayyear' => $dt->day_of_year(),
4116: 'dlsav' => $dt->is_dst() );
1.51 www 4117: }
4118:
1.370 www 4119: sub utc_string {
4120: my ($date)=@_;
1.371 www 4121: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4122: }
4123:
1.51 www 4124: sub maketime {
4125: my %th=@_;
1.687 raeburn 4126: my ($epoch_time,$timezone,$dt);
4127: $timezone = &Apache::lonlocal::gettimezone();
4128: eval {
4129: $dt = DateTime->new( year => $th{'year'},
4130: month => $th{'month'},
4131: day => $th{'day'},
4132: hour => $th{'hour'},
4133: minute => $th{'minute'},
4134: second => $th{'second'},
4135: time_zone => $timezone,
4136: );
4137: };
4138: if (!$@) {
4139: $epoch_time = $dt->epoch;
4140: if ($epoch_time) {
4141: return $epoch_time;
4142: }
4143: }
1.51 www 4144: return POSIX::mktime(
4145: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4146: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4147: }
4148:
4149: #########################################
1.51 www 4150:
4151: sub findallcourses {
1.482 raeburn 4152: my ($roles,$uname,$udom) = @_;
1.355 albertel 4153: my %roles;
4154: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4155: my %courses;
1.51 www 4156: my $now=time;
1.482 raeburn 4157: if (!defined($uname)) {
4158: $uname = $env{'user.name'};
4159: }
4160: if (!defined($udom)) {
4161: $udom = $env{'user.domain'};
4162: }
4163: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4164: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4165: if (!%roles) {
4166: %roles = (
4167: cc => 1,
1.907 raeburn 4168: co => 1,
1.482 raeburn 4169: in => 1,
4170: ep => 1,
4171: ta => 1,
4172: cr => 1,
4173: st => 1,
4174: );
4175: }
4176: foreach my $entry (keys(%roleshash)) {
4177: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4178: if ($trole =~ /^cr/) {
4179: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4180: } else {
4181: next if (!exists($roles{$trole}));
4182: }
4183: if ($tend) {
4184: next if ($tend < $now);
4185: }
4186: if ($tstart) {
4187: next if ($tstart > $now);
4188: }
1.1058 raeburn 4189: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4190: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4191: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4192: if ($secpart eq '') {
4193: ($cnum,$role) = split(/_/,$cnumpart);
4194: $sec = 'none';
1.1058 raeburn 4195: $value .= $cnum.'/';
1.482 raeburn 4196: } else {
4197: $cnum = $cnumpart;
4198: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4199: $value .= $cnum.'/'.$sec;
4200: }
4201: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4202: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4203: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4204: }
4205: } else {
4206: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4207: }
1.482 raeburn 4208: }
4209: } else {
4210: foreach my $key (keys(%env)) {
1.483 albertel 4211: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4212: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4213: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4214: next if ($role eq 'ca' || $role eq 'aa');
4215: next if (%roles && !exists($roles{$role}));
4216: my ($starttime,$endtime)=split(/\./,$env{$key});
4217: my $active=1;
4218: if ($starttime) {
4219: if ($now<$starttime) { $active=0; }
4220: }
4221: if ($endtime) {
4222: if ($now>$endtime) { $active=0; }
4223: }
4224: if ($active) {
1.1058 raeburn 4225: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4226: if ($sec eq '') {
4227: $sec = 'none';
1.1058 raeburn 4228: } else {
4229: $value .= $sec;
4230: }
4231: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4232: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4233: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4234: }
4235: } else {
4236: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4237: }
1.474 raeburn 4238: }
4239: }
1.51 www 4240: }
4241: }
1.474 raeburn 4242: return %courses;
1.51 www 4243: }
1.37 matthew 4244:
1.54 www 4245: ###############################################
1.474 raeburn 4246:
4247: sub blockcheck {
1.1075.2.73 raeburn 4248: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4249:
1.1075.2.73 raeburn 4250: if (defined($udom) && defined($uname)) {
4251: # If uname and udom are for a course, check for blocks in the course.
4252: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4253: my ($startblock,$endblock,$triggerblock) =
4254: &get_blocks($setters,$activity,$udom,$uname,$url);
4255: return ($startblock,$endblock,$triggerblock);
4256: }
4257: } else {
1.490 raeburn 4258: $udom = $env{'user.domain'};
4259: $uname = $env{'user.name'};
4260: }
4261:
1.502 raeburn 4262: my $startblock = 0;
4263: my $endblock = 0;
1.1062 raeburn 4264: my $triggerblock = '';
1.482 raeburn 4265: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4266:
1.490 raeburn 4267: # If uname is for a user, and activity is course-specific, i.e.,
4268: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4269:
1.490 raeburn 4270: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.73 raeburn 4271: $activity eq 'groups' || $activity eq 'printout') &&
4272: ($env{'request.course.id'})) {
1.490 raeburn 4273: foreach my $key (keys(%live_courses)) {
4274: if ($key ne $env{'request.course.id'}) {
4275: delete($live_courses{$key});
4276: }
4277: }
4278: }
4279:
4280: my $otheruser = 0;
4281: my %own_courses;
4282: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4283: # Resource belongs to user other than current user.
4284: $otheruser = 1;
4285: # Gather courses for current user
4286: %own_courses =
4287: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4288: }
4289:
4290: # Gather active course roles - course coordinator, instructor,
4291: # exam proctor, ta, student, or custom role.
1.474 raeburn 4292:
4293: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4294: my ($cdom,$cnum);
4295: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4296: $cdom = $env{'course.'.$course.'.domain'};
4297: $cnum = $env{'course.'.$course.'.num'};
4298: } else {
1.490 raeburn 4299: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4300: }
4301: my $no_ownblock = 0;
4302: my $no_userblock = 0;
1.533 raeburn 4303: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4304: # Check if current user has 'evb' priv for this
4305: if (defined($own_courses{$course})) {
4306: foreach my $sec (keys(%{$own_courses{$course}})) {
4307: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4308: if ($sec ne 'none') {
4309: $checkrole .= '/'.$sec;
4310: }
4311: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4312: $no_ownblock = 1;
4313: last;
4314: }
4315: }
4316: }
4317: # if they have 'evb' priv and are currently not playing student
4318: next if (($no_ownblock) &&
4319: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4320: }
1.474 raeburn 4321: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4322: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4323: if ($sec ne 'none') {
1.482 raeburn 4324: $checkrole .= '/'.$sec;
1.474 raeburn 4325: }
1.490 raeburn 4326: if ($otheruser) {
4327: # Resource belongs to user other than current user.
4328: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4329: my (%allroles,%userroles);
4330: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4331: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4332: my ($trole,$tdom,$tnum,$tsec);
4333: if ($entry =~ /^cr/) {
4334: ($trole,$tdom,$tnum,$tsec) =
4335: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4336: } else {
4337: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4338: }
4339: my ($spec,$area,$trest);
4340: $area = '/'.$tdom.'/'.$tnum;
4341: $trest = $tnum;
4342: if ($tsec ne '') {
4343: $area .= '/'.$tsec;
4344: $trest .= '/'.$tsec;
4345: }
4346: $spec = $trole.'.'.$area;
4347: if ($trole =~ /^cr/) {
4348: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4349: $tdom,$spec,$trest,$area);
4350: } else {
4351: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4352: $tdom,$spec,$trest,$area);
4353: }
4354: }
4355: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4356: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4357: if ($1) {
4358: $no_userblock = 1;
4359: last;
4360: }
1.486 raeburn 4361: }
4362: }
1.490 raeburn 4363: } else {
4364: # Resource belongs to current user
4365: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4366: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4367: $no_ownblock = 1;
4368: last;
4369: }
1.474 raeburn 4370: }
4371: }
4372: # if they have the evb priv and are currently not playing student
1.482 raeburn 4373: next if (($no_ownblock) &&
1.491 albertel 4374: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4375: next if ($no_userblock);
1.474 raeburn 4376:
1.866 kalberla 4377: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4378: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4379:
1.1062 raeburn 4380: my ($start,$end,$trigger) =
4381: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4382: if (($start != 0) &&
4383: (($startblock == 0) || ($startblock > $start))) {
4384: $startblock = $start;
1.1062 raeburn 4385: if ($trigger ne '') {
4386: $triggerblock = $trigger;
4387: }
1.502 raeburn 4388: }
4389: if (($end != 0) &&
4390: (($endblock == 0) || ($endblock < $end))) {
4391: $endblock = $end;
1.1062 raeburn 4392: if ($trigger ne '') {
4393: $triggerblock = $trigger;
4394: }
1.502 raeburn 4395: }
1.490 raeburn 4396: }
1.1062 raeburn 4397: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4398: }
4399:
4400: sub get_blocks {
1.1062 raeburn 4401: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4402: my $startblock = 0;
4403: my $endblock = 0;
1.1062 raeburn 4404: my $triggerblock = '';
1.490 raeburn 4405: my $course = $cdom.'_'.$cnum;
4406: $setters->{$course} = {};
4407: $setters->{$course}{'staff'} = [];
4408: $setters->{$course}{'times'} = [];
1.1062 raeburn 4409: $setters->{$course}{'triggers'} = [];
4410: my (@blockers,%triggered);
4411: my $now = time;
4412: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4413: if ($activity eq 'docs') {
4414: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4415: foreach my $block (@blockers) {
4416: if ($block =~ /^firstaccess____(.+)$/) {
4417: my $item = $1;
4418: my $type = 'map';
4419: my $timersymb = $item;
4420: if ($item eq 'course') {
4421: $type = 'course';
4422: } elsif ($item =~ /___\d+___/) {
4423: $type = 'resource';
4424: } else {
4425: $timersymb = &Apache::lonnet::symbread($item);
4426: }
4427: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4428: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4429: $triggered{$block} = {
4430: start => $start,
4431: end => $end,
4432: type => $type,
4433: };
4434: }
4435: }
4436: } else {
4437: foreach my $block (keys(%commblocks)) {
4438: if ($block =~ m/^(\d+)____(\d+)$/) {
4439: my ($start,$end) = ($1,$2);
4440: if ($start <= time && $end >= time) {
4441: if (ref($commblocks{$block}) eq 'HASH') {
4442: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4443: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4444: unless(grep(/^\Q$block\E$/,@blockers)) {
4445: push(@blockers,$block);
4446: }
4447: }
4448: }
4449: }
4450: }
4451: } elsif ($block =~ /^firstaccess____(.+)$/) {
4452: my $item = $1;
4453: my $timersymb = $item;
4454: my $type = 'map';
4455: if ($item eq 'course') {
4456: $type = 'course';
4457: } elsif ($item =~ /___\d+___/) {
4458: $type = 'resource';
4459: } else {
4460: $timersymb = &Apache::lonnet::symbread($item);
4461: }
4462: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4463: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4464: if ($start && $end) {
4465: if (($start <= time) && ($end >= time)) {
4466: unless (grep(/^\Q$block\E$/,@blockers)) {
4467: push(@blockers,$block);
4468: $triggered{$block} = {
4469: start => $start,
4470: end => $end,
4471: type => $type,
4472: };
4473: }
4474: }
1.490 raeburn 4475: }
1.1062 raeburn 4476: }
4477: }
4478: }
4479: foreach my $blocker (@blockers) {
4480: my ($staff_name,$staff_dom,$title,$blocks) =
4481: &parse_block_record($commblocks{$blocker});
4482: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4483: my ($start,$end,$triggertype);
4484: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4485: ($start,$end) = ($1,$2);
4486: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4487: $start = $triggered{$blocker}{'start'};
4488: $end = $triggered{$blocker}{'end'};
4489: $triggertype = $triggered{$blocker}{'type'};
4490: }
4491: if ($start) {
4492: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4493: if ($triggertype) {
4494: push(@{$$setters{$course}{'triggers'}},$triggertype);
4495: } else {
4496: push(@{$$setters{$course}{'triggers'}},0);
4497: }
4498: if ( ($startblock == 0) || ($startblock > $start) ) {
4499: $startblock = $start;
4500: if ($triggertype) {
4501: $triggerblock = $blocker;
1.474 raeburn 4502: }
4503: }
1.1062 raeburn 4504: if ( ($endblock == 0) || ($endblock < $end) ) {
4505: $endblock = $end;
4506: if ($triggertype) {
4507: $triggerblock = $blocker;
4508: }
4509: }
1.474 raeburn 4510: }
4511: }
1.1062 raeburn 4512: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4513: }
4514:
4515: sub parse_block_record {
4516: my ($record) = @_;
4517: my ($setuname,$setudom,$title,$blocks);
4518: if (ref($record) eq 'HASH') {
4519: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4520: $title = &unescape($record->{'event'});
4521: $blocks = $record->{'blocks'};
4522: } else {
4523: my @data = split(/:/,$record,3);
4524: if (scalar(@data) eq 2) {
4525: $title = $data[1];
4526: ($setuname,$setudom) = split(/@/,$data[0]);
4527: } else {
4528: ($setuname,$setudom,$title) = @data;
4529: }
4530: $blocks = { 'com' => 'on' };
4531: }
4532: return ($setuname,$setudom,$title,$blocks);
4533: }
4534:
1.854 kalberla 4535: sub blocking_status {
1.1075.2.73 raeburn 4536: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4537: my %setters;
1.890 droeschl 4538:
1.1061 raeburn 4539: # check for active blocking
1.1062 raeburn 4540: my ($startblock,$endblock,$triggerblock) =
1.1075.2.73 raeburn 4541: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4542: my $blocked = 0;
4543: if ($startblock && $endblock) {
4544: $blocked = 1;
4545: }
1.890 droeschl 4546:
1.1061 raeburn 4547: # caller just wants to know whether a block is active
4548: if (!wantarray) { return $blocked; }
4549:
4550: # build a link to a popup window containing the details
4551: my $querystring = "?activity=$activity";
4552: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4553: if ($activity eq 'port') {
4554: $querystring .= "&udom=$udom" if $udom;
4555: $querystring .= "&uname=$uname" if $uname;
4556: } elsif ($activity eq 'docs') {
4557: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4558: }
1.1061 raeburn 4559:
4560: my $output .= <<'END_MYBLOCK';
4561: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4562: var options = "width=" + w + ",height=" + h + ",";
4563: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4564: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4565: var newWin = window.open(url, wdwName, options);
4566: newWin.focus();
4567: }
1.890 droeschl 4568: END_MYBLOCK
1.854 kalberla 4569:
1.1061 raeburn 4570: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4571:
1.1061 raeburn 4572: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4573: my $text = &mt('Communication Blocked');
4574: if ($activity eq 'docs') {
4575: $text = &mt('Content Access Blocked');
1.1063 raeburn 4576: } elsif ($activity eq 'printout') {
4577: $text = &mt('Printing Blocked');
1.1062 raeburn 4578: }
1.1061 raeburn 4579: $output .= <<"END_BLOCK";
1.867 kalberla 4580: <div class='LC_comblock'>
1.869 kalberla 4581: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4582: title='$text'>
4583: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4584: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4585: title='$text'>$text</a>
1.867 kalberla 4586: </div>
4587:
4588: END_BLOCK
1.474 raeburn 4589:
1.1061 raeburn 4590: return ($blocked, $output);
1.854 kalberla 4591: }
1.490 raeburn 4592:
1.60 matthew 4593: ###############################################
4594:
1.682 raeburn 4595: sub check_ip_acc {
4596: my ($acc)=@_;
4597: &Apache::lonxml::debug("acc is $acc");
4598: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4599: return 1;
4600: }
4601: my $allowed=0;
4602: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4603:
4604: my $name;
4605: foreach my $pattern (split(',',$acc)) {
4606: $pattern =~ s/^\s*//;
4607: $pattern =~ s/\s*$//;
4608: if ($pattern =~ /\*$/) {
4609: #35.8.*
4610: $pattern=~s/\*//;
4611: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4612: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4613: #35.8.3.[34-56]
4614: my $low=$2;
4615: my $high=$3;
4616: $pattern=$1;
4617: if ($ip =~ /^\Q$pattern\E/) {
4618: my $last=(split(/\./,$ip))[3];
4619: if ($last <=$high && $last >=$low) { $allowed=1; }
4620: }
4621: } elsif ($pattern =~ /^\*/) {
4622: #*.msu.edu
4623: $pattern=~s/\*//;
4624: if (!defined($name)) {
4625: use Socket;
4626: my $netaddr=inet_aton($ip);
4627: ($name)=gethostbyaddr($netaddr,AF_INET);
4628: }
4629: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4630: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4631: #127.0.0.1
4632: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4633: } else {
4634: #some.name.com
4635: if (!defined($name)) {
4636: use Socket;
4637: my $netaddr=inet_aton($ip);
4638: ($name)=gethostbyaddr($netaddr,AF_INET);
4639: }
4640: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4641: }
4642: if ($allowed) { last; }
4643: }
4644: return $allowed;
4645: }
4646:
4647: ###############################################
4648:
1.60 matthew 4649: =pod
4650:
1.112 bowersj2 4651: =head1 Domain Template Functions
4652:
4653: =over 4
4654:
4655: =item * &determinedomain()
1.60 matthew 4656:
4657: Inputs: $domain (usually will be undef)
4658:
1.63 www 4659: Returns: Determines which domain should be used for designs
1.60 matthew 4660:
4661: =cut
1.54 www 4662:
1.60 matthew 4663: ###############################################
1.63 www 4664: sub determinedomain {
4665: my $domain=shift;
1.531 albertel 4666: if (! $domain) {
1.60 matthew 4667: # Determine domain if we have not been given one
1.893 raeburn 4668: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4669: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4670: if ($env{'request.role.domain'}) {
4671: $domain=$env{'request.role.domain'};
1.60 matthew 4672: }
4673: }
1.63 www 4674: return $domain;
4675: }
4676: ###############################################
1.517 raeburn 4677:
1.518 albertel 4678: sub devalidate_domconfig_cache {
4679: my ($udom)=@_;
4680: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4681: }
4682:
4683: # ---------------------- Get domain configuration for a domain
4684: sub get_domainconf {
4685: my ($udom) = @_;
4686: my $cachetime=1800;
4687: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4688: if (defined($cached)) { return %{$result}; }
4689:
4690: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4691: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4692: my (%designhash,%legacy);
1.518 albertel 4693: if (keys(%domconfig) > 0) {
4694: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4695: if (keys(%{$domconfig{'login'}})) {
4696: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4697: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4698: if ($key eq 'loginvia') {
4699: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4700: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4701: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4702: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4703: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4704: $designhash{$udom.'.login.loginvia'} = $server;
4705: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4706:
4707: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4708: } else {
1.1013 raeburn 4709: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4710: }
4711: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4712: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4713: }
1.946 raeburn 4714: }
4715: }
4716: }
4717: }
4718: } else {
4719: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4720: $designhash{$udom.'.login.'.$key.'_'.$img} =
4721: $domconfig{'login'}{$key}{$img};
4722: }
1.699 raeburn 4723: }
4724: } else {
4725: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4726: }
1.632 raeburn 4727: }
4728: } else {
4729: $legacy{'login'} = 1;
1.518 albertel 4730: }
1.632 raeburn 4731: } else {
4732: $legacy{'login'} = 1;
1.518 albertel 4733: }
4734: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4735: if (keys(%{$domconfig{'rolecolors'}})) {
4736: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4737: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4738: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4739: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4740: }
1.518 albertel 4741: }
4742: }
1.632 raeburn 4743: } else {
4744: $legacy{'rolecolors'} = 1;
1.518 albertel 4745: }
1.632 raeburn 4746: } else {
4747: $legacy{'rolecolors'} = 1;
1.518 albertel 4748: }
1.948 raeburn 4749: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4750: if ($domconfig{'autoenroll'}{'co-owners'}) {
4751: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4752: }
4753: }
1.632 raeburn 4754: if (keys(%legacy) > 0) {
4755: my %legacyhash = &get_legacy_domconf($udom);
4756: foreach my $item (keys(%legacyhash)) {
4757: if ($item =~ /^\Q$udom\E\.login/) {
4758: if ($legacy{'login'}) {
4759: $designhash{$item} = $legacyhash{$item};
4760: }
4761: } else {
4762: if ($legacy{'rolecolors'}) {
4763: $designhash{$item} = $legacyhash{$item};
4764: }
1.518 albertel 4765: }
4766: }
4767: }
1.632 raeburn 4768: } else {
4769: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4770: }
4771: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4772: $cachetime);
4773: return %designhash;
4774: }
4775:
1.632 raeburn 4776: sub get_legacy_domconf {
4777: my ($udom) = @_;
4778: my %legacyhash;
4779: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4780: my $designfile = $designdir.'/'.$udom.'.tab';
4781: if (-e $designfile) {
4782: if ( open (my $fh,"<$designfile") ) {
4783: while (my $line = <$fh>) {
4784: next if ($line =~ /^\#/);
4785: chomp($line);
4786: my ($key,$val)=(split(/\=/,$line));
4787: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4788: }
4789: close($fh);
4790: }
4791: }
1.1026 raeburn 4792: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4793: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4794: }
4795: return %legacyhash;
4796: }
4797:
1.63 www 4798: =pod
4799:
1.112 bowersj2 4800: =item * &domainlogo()
1.63 www 4801:
4802: Inputs: $domain (usually will be undef)
4803:
4804: Returns: A link to a domain logo, if the domain logo exists.
4805: If the domain logo does not exist, a description of the domain.
4806:
4807: =cut
1.112 bowersj2 4808:
1.63 www 4809: ###############################################
4810: sub domainlogo {
1.517 raeburn 4811: my $domain = &determinedomain(shift);
1.518 albertel 4812: my %designhash = &get_domainconf($domain);
1.517 raeburn 4813: # See if there is a logo
4814: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4815: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4816: if ($imgsrc =~ m{^/(adm|res)/}) {
4817: if ($imgsrc =~ m{^/res/}) {
4818: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4819: &Apache::lonnet::repcopy($local_name);
4820: }
4821: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4822: }
4823: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4824: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4825: return &Apache::lonnet::domain($domain,'description');
1.59 www 4826: } else {
1.60 matthew 4827: return '';
1.59 www 4828: }
4829: }
1.63 www 4830: ##############################################
4831:
4832: =pod
4833:
1.112 bowersj2 4834: =item * &designparm()
1.63 www 4835:
4836: Inputs: $which parameter; $domain (usually will be undef)
4837:
4838: Returns: value of designparamter $which
4839:
4840: =cut
1.112 bowersj2 4841:
1.397 albertel 4842:
1.400 albertel 4843: ##############################################
1.397 albertel 4844: sub designparm {
4845: my ($which,$domain)=@_;
4846: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4847: return $env{'environment.color.'.$which};
1.96 www 4848: }
1.63 www 4849: $domain=&determinedomain($domain);
1.1016 raeburn 4850: my %domdesign;
4851: unless ($domain eq 'public') {
4852: %domdesign = &get_domainconf($domain);
4853: }
1.520 raeburn 4854: my $output;
1.517 raeburn 4855: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4856: $output = $domdesign{$domain.'.'.$which};
1.63 www 4857: } else {
1.520 raeburn 4858: $output = $defaultdesign{$which};
4859: }
4860: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4861: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4862: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4863: if ($output =~ m{^/res/}) {
4864: my $local_name = &Apache::lonnet::filelocation('',$output);
4865: &Apache::lonnet::repcopy($local_name);
4866: }
1.520 raeburn 4867: $output = &lonhttpdurl($output);
4868: }
1.63 www 4869: }
1.520 raeburn 4870: return $output;
1.63 www 4871: }
1.59 www 4872:
1.822 bisitz 4873: ##############################################
4874: =pod
4875:
1.832 bisitz 4876: =item * &authorspace()
4877:
1.1028 raeburn 4878: Inputs: $url (usually will be undef).
1.832 bisitz 4879:
1.1075.2.40 raeburn 4880: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4881: directory being viewed (or for which action is being taken).
4882: If $url is provided, and begins /priv/<domain>/<uname>
4883: the path will be that portion of the $context argument.
4884: Otherwise the path will be for the author space of the current
4885: user when the current role is author, or for that of the
4886: co-author/assistant co-author space when the current role
4887: is co-author or assistant co-author.
1.832 bisitz 4888:
4889: =cut
4890:
4891: sub authorspace {
1.1028 raeburn 4892: my ($url) = @_;
4893: if ($url ne '') {
4894: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4895: return $1;
4896: }
4897: }
1.832 bisitz 4898: my $caname = '';
1.1024 www 4899: my $cadom = '';
1.1028 raeburn 4900: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4901: ($cadom,$caname) =
1.832 bisitz 4902: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4903: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4904: $caname = $env{'user.name'};
1.1024 www 4905: $cadom = $env{'user.domain'};
1.832 bisitz 4906: }
1.1028 raeburn 4907: if (($caname ne '') && ($cadom ne '')) {
4908: return "/priv/$cadom/$caname/";
4909: }
4910: return;
1.832 bisitz 4911: }
4912:
4913: ##############################################
4914: =pod
4915:
1.822 bisitz 4916: =item * &head_subbox()
4917:
4918: Inputs: $content (contains HTML code with page functions, etc.)
4919:
4920: Returns: HTML div with $content
4921: To be included in page header
4922:
4923: =cut
4924:
4925: sub head_subbox {
4926: my ($content)=@_;
4927: my $output =
1.993 raeburn 4928: '<div class="LC_head_subbox">'
1.822 bisitz 4929: .$content
4930: .'</div>'
4931: }
4932:
4933: ##############################################
4934: =pod
4935:
4936: =item * &CSTR_pageheader()
4937:
1.1026 raeburn 4938: Input: (optional) filename from which breadcrumb trail is built.
4939: In most cases no input as needed, as $env{'request.filename'}
4940: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 4941:
4942: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 4943: To be included on Authoring Space pages
1.822 bisitz 4944:
4945: =cut
4946:
4947: sub CSTR_pageheader {
1.1026 raeburn 4948: my ($trailfile) = @_;
4949: if ($trailfile eq '') {
4950: $trailfile = $env{'request.filename'};
4951: }
4952:
4953: # this is for resources; directories have customtitle, and crumbs
4954: # and select recent are created in lonpubdir.pm
4955:
4956: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 4957: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 4958: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 4959: my $formaction = "/priv/$udom/$uname/$thisdisfn";
4960: $formaction =~ s{/+}{/}g;
1.822 bisitz 4961:
4962: my $parentpath = '';
4963: my $lastitem = '';
4964: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4965: $parentpath = $1;
4966: $lastitem = $2;
4967: } else {
4968: $lastitem = $thisdisfn;
4969: }
1.921 bisitz 4970:
4971: my $output =
1.822 bisitz 4972: '<div>'
4973: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 4974: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 4975: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4976: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 4977: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 4978:
4979: if ($lastitem) {
4980: $output .=
4981: '<span class="LC_filename">'
4982: .$lastitem
4983: .'</span>';
4984: }
4985: $output .=
4986: '<br />'
1.822 bisitz 4987: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4988: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4989: .'</form>'
4990: .&Apache::lonmenu::constspaceform()
4991: .'</div>';
1.921 bisitz 4992:
4993: return $output;
1.822 bisitz 4994: }
4995:
1.60 matthew 4996: ###############################################
4997: ###############################################
4998:
4999: =pod
5000:
1.112 bowersj2 5001: =back
5002:
1.549 albertel 5003: =head1 HTML Helpers
1.112 bowersj2 5004:
5005: =over 4
5006:
5007: =item * &bodytag()
1.60 matthew 5008:
5009: Returns a uniform header for LON-CAPA web pages.
5010:
5011: Inputs:
5012:
1.112 bowersj2 5013: =over 4
5014:
5015: =item * $title, A title to be displayed on the page.
5016:
5017: =item * $function, the current role (can be undef).
5018:
5019: =item * $addentries, extra parameters for the <body> tag.
5020:
5021: =item * $bodyonly, if defined, only return the <body> tag.
5022:
5023: =item * $domain, if defined, force a given domain.
5024:
5025: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5026: text interface only)
1.60 matthew 5027:
1.814 bisitz 5028: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5029: navigational links
1.317 albertel 5030:
1.338 albertel 5031: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5032:
1.1075.2.12 raeburn 5033: =item * $no_inline_link, if true and in remote mode, don't show the
5034: 'Switch To Inline Menu' link
5035:
1.460 albertel 5036: =item * $args, optional argument valid values are
5037: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5038: inherit_jsmath -> when creating popup window in a page,
5039: should it have jsmath forced on by the
5040: current page
1.460 albertel 5041:
1.1075.2.15 raeburn 5042: =item * $advtoolsref, optional argument, ref to an array containing
5043: inlineremote items to be added in "Functions" menu below
5044: breadcrumbs.
5045:
1.112 bowersj2 5046: =back
5047:
1.60 matthew 5048: Returns: A uniform header for LON-CAPA web pages.
5049: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5050: If $bodyonly is undef or zero, an html string containing a <body> tag and
5051: other decorations will be returned.
5052:
5053: =cut
5054:
1.54 www 5055: sub bodytag {
1.831 bisitz 5056: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5057: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5058:
1.954 raeburn 5059: my $public;
5060: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5061: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5062: $public = 1;
5063: }
1.460 albertel 5064: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5065: my $httphost = $args->{'use_absolute'};
1.339 albertel 5066:
1.183 matthew 5067: $function = &get_users_function() if (!$function);
1.339 albertel 5068: my $img = &designparm($function.'.img',$domain);
5069: my $font = &designparm($function.'.font',$domain);
5070: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5071:
1.803 bisitz 5072: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5073: 'bgcolor' => $pgbg,
1.339 albertel 5074: 'text' => $font,
5075: 'alink' => &designparm($function.'.alink',$domain),
5076: 'vlink' => &designparm($function.'.vlink',$domain),
5077: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5078: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5079:
1.63 www 5080: # role and realm
1.1075.2.68 raeburn 5081: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5082: if ($realm) {
5083: $realm = '/'.$realm;
5084: }
1.378 raeburn 5085: if ($role eq 'ca') {
1.479 albertel 5086: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5087: $realm = &plainname($rname,$rdom);
1.378 raeburn 5088: }
1.55 www 5089: # realm
1.258 albertel 5090: if ($env{'request.course.id'}) {
1.378 raeburn 5091: if ($env{'request.role'} !~ /^cr/) {
5092: $role = &Apache::lonnet::plaintext($role,&course_type());
5093: }
1.898 raeburn 5094: if ($env{'request.course.sec'}) {
5095: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5096: }
1.359 albertel 5097: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5098: } else {
5099: $role = &Apache::lonnet::plaintext($role);
1.54 www 5100: }
1.433 albertel 5101:
1.359 albertel 5102: if (!$realm) { $realm=' '; }
1.330 albertel 5103:
1.438 albertel 5104: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5105:
1.101 www 5106: # construct main body tag
1.359 albertel 5107: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5108: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5109:
1.1075.2.38 raeburn 5110: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5111:
5112: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5113: return $bodytag;
1.1075.2.38 raeburn 5114: }
1.359 albertel 5115:
1.954 raeburn 5116: if ($public) {
1.433 albertel 5117: undef($role);
5118: }
1.359 albertel 5119:
1.762 bisitz 5120: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5121: #
5122: # Extra info if you are the DC
5123: my $dc_info = '';
5124: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5125: $env{'course.'.$env{'request.course.id'}.
5126: '.domain'}.'/'})) {
5127: my $cid = $env{'request.course.id'};
1.917 raeburn 5128: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5129: $dc_info =~ s/\s+$//;
1.359 albertel 5130: }
5131:
1.898 raeburn 5132: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.903 droeschl 5133:
1.1075.2.13 raeburn 5134: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5135:
1.1075.2.38 raeburn 5136:
5137:
1.1075.2.21 raeburn 5138: my $funclist;
5139: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5140: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5141: Apache::lonmenu::serverform();
5142: my $forbodytag;
5143: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5144: $forcereg,$args->{'group'},
5145: $args->{'bread_crumbs'},
5146: $advtoolsref,'',\$forbodytag);
5147: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5148: $funclist = $forbodytag;
5149: }
5150: } else {
1.903 droeschl 5151:
5152: # if ($env{'request.state'} eq 'construct') {
5153: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5154: # }
5155:
1.1075.2.38 raeburn 5156: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5157: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5158:
1.1075.2.38 raeburn 5159: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5160:
1.916 droeschl 5161: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5162: if ($dc_info) {
5163: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5164: }
1.1075.2.38 raeburn 5165: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5166: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5167: return $bodytag;
5168: }
1.894 droeschl 5169:
1.927 raeburn 5170: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5171: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5172: }
1.916 droeschl 5173:
1.1075.2.38 raeburn 5174: $bodytag .= $right;
1.852 droeschl 5175:
1.917 raeburn 5176: if ($dc_info) {
5177: $dc_info = &dc_courseid_toggle($dc_info);
5178: }
5179: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5180:
1.1075.2.61 raeburn 5181: #if directed to not display the secondary menu, don't.
5182: if ($args->{'no_secondary_menu'}) {
5183: return $bodytag;
5184: }
1.903 droeschl 5185: #don't show menus for public users
1.954 raeburn 5186: if (!$public){
1.1075.2.52 raeburn 5187: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5188: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5189: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5190: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5191: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5192: $args->{'bread_crumbs'});
5193: } elsif ($forcereg) {
1.1075.2.22 raeburn 5194: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5195: $args->{'group'});
1.1075.2.15 raeburn 5196: } else {
1.1075.2.21 raeburn 5197: my $forbodytag;
5198: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5199: $forcereg,$args->{'group'},
5200: $args->{'bread_crumbs'},
5201: $advtoolsref,'',\$forbodytag);
5202: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5203: $bodytag .= $forbodytag;
5204: }
1.920 raeburn 5205: }
1.903 droeschl 5206: }else{
5207: # this is to seperate menu from content when there's no secondary
5208: # menu. Especially needed for public accessible ressources.
5209: $bodytag .= '<hr style="clear:both" />';
5210: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5211: }
1.903 droeschl 5212:
1.235 raeburn 5213: return $bodytag;
1.1075.2.12 raeburn 5214: }
5215:
5216: #
5217: # Top frame rendering, Remote is up
5218: #
5219:
5220: my $imgsrc = $img;
5221: if ($img =~ /^\/adm/) {
5222: $imgsrc = &lonhttpdurl($img);
5223: }
5224: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5225:
1.1075.2.60 raeburn 5226: my $help=($no_inline_link?''
5227: :&Apache::loncommon::top_nav_help('Help'));
5228:
1.1075.2.12 raeburn 5229: # Explicit link to get inline menu
5230: my $menu= ($no_inline_link?''
5231: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5232:
5233: if ($dc_info) {
5234: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5235: }
5236:
1.1075.2.38 raeburn 5237: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5238: unless ($public) {
5239: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5240: undef,'LC_menubuttons_link');
5241: }
5242:
1.1075.2.12 raeburn 5243: unless ($env{'form.inhibitmenu'}) {
5244: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5245: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5246: <li>$help</li>
1.1075.2.12 raeburn 5247: <li>$menu</li>
5248: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5249: }
1.1075.2.13 raeburn 5250: if ($env{'request.state'} eq 'construct') {
5251: if (!$public){
5252: if ($env{'request.state'} eq 'construct') {
5253: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5254: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5255: &Apache::lonhtmlcommon::scripttag('','end').
5256: &Apache::lonmenu::innerregister($forcereg,
5257: $args->{'bread_crumbs'});
5258: }
5259: }
5260: }
1.1075.2.21 raeburn 5261: return $bodytag."\n".$funclist;
1.182 matthew 5262: }
5263:
1.917 raeburn 5264: sub dc_courseid_toggle {
5265: my ($dc_info) = @_;
1.980 raeburn 5266: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5267: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5268: &mt('(More ...)').'</a></span>'.
5269: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5270: }
5271:
1.330 albertel 5272: sub make_attr_string {
5273: my ($register,$attr_ref) = @_;
5274:
5275: if ($attr_ref && !ref($attr_ref)) {
5276: die("addentries Must be a hash ref ".
5277: join(':',caller(1))." ".
5278: join(':',caller(0))." ");
5279: }
5280:
5281: if ($register) {
1.339 albertel 5282: my ($on_load,$on_unload);
5283: foreach my $key (keys(%{$attr_ref})) {
5284: if (lc($key) eq 'onload') {
5285: $on_load.=$attr_ref->{$key}.';';
5286: delete($attr_ref->{$key});
5287:
5288: } elsif (lc($key) eq 'onunload') {
5289: $on_unload.=$attr_ref->{$key}.';';
5290: delete($attr_ref->{$key});
5291: }
5292: }
1.1075.2.12 raeburn 5293: if ($env{'environment.remote'} eq 'on') {
5294: $attr_ref->{'onload'} =
5295: &Apache::lonmenu::loadevents(). $on_load;
5296: $attr_ref->{'onunload'}=
5297: &Apache::lonmenu::unloadevents().$on_unload;
5298: } else {
5299: $attr_ref->{'onload'} = $on_load;
5300: $attr_ref->{'onunload'}= $on_unload;
5301: }
1.330 albertel 5302: }
1.339 albertel 5303:
1.330 albertel 5304: my $attr_string;
1.1075.2.56 raeburn 5305: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5306: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5307: }
5308: return $attr_string;
5309: }
5310:
5311:
1.182 matthew 5312: ###############################################
1.251 albertel 5313: ###############################################
5314:
5315: =pod
5316:
5317: =item * &endbodytag()
5318:
5319: Returns a uniform footer for LON-CAPA web pages.
5320:
1.635 raeburn 5321: Inputs: 1 - optional reference to an args hash
5322: If in the hash, key for noredirectlink has a value which evaluates to true,
5323: a 'Continue' link is not displayed if the page contains an
5324: internal redirect in the <head></head> section,
5325: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5326:
5327: =cut
5328:
5329: sub endbodytag {
1.635 raeburn 5330: my ($args) = @_;
1.1075.2.6 raeburn 5331: my $endbodytag;
5332: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5333: $endbodytag='</body>';
5334: }
1.269 albertel 5335: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5336: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5337: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5338: $endbodytag=
5339: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5340: &mt('Continue').'</a>'.
5341: $endbodytag;
5342: }
1.315 albertel 5343: }
1.251 albertel 5344: return $endbodytag;
5345: }
5346:
1.352 albertel 5347: =pod
5348:
5349: =item * &standard_css()
5350:
5351: Returns a style sheet
5352:
5353: Inputs: (all optional)
5354: domain -> force to color decorate a page for a specific
5355: domain
5356: function -> force usage of a specific rolish color scheme
5357: bgcolor -> override the default page bgcolor
5358:
5359: =cut
5360:
1.343 albertel 5361: sub standard_css {
1.345 albertel 5362: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5363: $function = &get_users_function() if (!$function);
5364: my $img = &designparm($function.'.img', $domain);
5365: my $tabbg = &designparm($function.'.tabbg', $domain);
5366: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5367: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5368: #second colour for later usage
1.345 albertel 5369: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5370: my $pgbg_or_bgcolor =
5371: $bgcolor ||
1.352 albertel 5372: &designparm($function.'.pgbg', $domain);
1.382 albertel 5373: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5374: my $alink = &designparm($function.'.alink', $domain);
5375: my $vlink = &designparm($function.'.vlink', $domain);
5376: my $link = &designparm($function.'.link', $domain);
5377:
1.602 albertel 5378: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5379: my $mono = 'monospace';
1.850 bisitz 5380: my $data_table_head = $sidebg;
5381: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5382: my $data_table_dark = '#E0E0E0';
1.470 banghart 5383: my $data_table_darker = '#CCCCCC';
1.349 albertel 5384: my $data_table_highlight = '#FFFF00';
1.352 albertel 5385: my $mail_new = '#FFBB77';
5386: my $mail_new_hover = '#DD9955';
5387: my $mail_read = '#BBBB77';
5388: my $mail_read_hover = '#999944';
5389: my $mail_replied = '#AAAA88';
5390: my $mail_replied_hover = '#888855';
5391: my $mail_other = '#99BBBB';
5392: my $mail_other_hover = '#669999';
1.391 albertel 5393: my $table_header = '#DDDDDD';
1.489 raeburn 5394: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5395: my $lg_border_color = '#C8C8C8';
1.952 onken 5396: my $button_hover = '#BF2317';
1.392 albertel 5397:
1.608 albertel 5398: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5399: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5400: : '0 3px 0 4px';
1.448 albertel 5401:
1.523 albertel 5402:
1.343 albertel 5403: return <<END;
1.947 droeschl 5404:
5405: /* needed for iframe to allow 100% height in FF */
5406: body, html {
5407: margin: 0;
5408: padding: 0 0.5%;
5409: height: 99%; /* to avoid scrollbars */
5410: }
5411:
1.795 www 5412: body {
1.911 bisitz 5413: font-family: $sans;
5414: line-height:130%;
5415: font-size:0.83em;
5416: color:$font;
1.795 www 5417: }
5418:
1.959 onken 5419: a:focus,
5420: a:focus img {
1.795 www 5421: color: red;
5422: }
1.698 harmsja 5423:
1.911 bisitz 5424: form, .inline {
5425: display: inline;
1.795 www 5426: }
1.721 harmsja 5427:
1.795 www 5428: .LC_right {
1.911 bisitz 5429: text-align:right;
1.795 www 5430: }
5431:
5432: .LC_middle {
1.911 bisitz 5433: vertical-align:middle;
1.795 www 5434: }
1.721 harmsja 5435:
1.1075.2.38 raeburn 5436: .LC_floatleft {
5437: float: left;
5438: }
5439:
5440: .LC_floatright {
5441: float: right;
5442: }
5443:
1.911 bisitz 5444: .LC_400Box {
5445: width:400px;
5446: }
1.721 harmsja 5447:
1.947 droeschl 5448: .LC_iframecontainer {
5449: width: 98%;
5450: margin: 0;
5451: position: fixed;
5452: top: 8.5em;
5453: bottom: 0;
5454: }
5455:
5456: .LC_iframecontainer iframe{
5457: border: none;
5458: width: 100%;
5459: height: 100%;
5460: }
5461:
1.778 bisitz 5462: .LC_filename {
5463: font-family: $mono;
5464: white-space:pre;
1.921 bisitz 5465: font-size: 120%;
1.778 bisitz 5466: }
5467:
5468: .LC_fileicon {
5469: border: none;
5470: height: 1.3em;
5471: vertical-align: text-bottom;
5472: margin-right: 0.3em;
5473: text-decoration:none;
5474: }
5475:
1.1008 www 5476: .LC_setting {
5477: text-decoration:underline;
5478: }
5479:
1.350 albertel 5480: .LC_error {
5481: color: red;
5482: }
1.795 www 5483:
1.1075.2.15 raeburn 5484: .LC_warning {
5485: color: darkorange;
5486: }
5487:
1.457 albertel 5488: .LC_diff_removed {
1.733 bisitz 5489: color: red;
1.394 albertel 5490: }
1.532 albertel 5491:
5492: .LC_info,
1.457 albertel 5493: .LC_success,
5494: .LC_diff_added {
1.350 albertel 5495: color: green;
5496: }
1.795 www 5497:
1.802 bisitz 5498: div.LC_confirm_box {
5499: background-color: #FAFAFA;
5500: border: 1px solid $lg_border_color;
5501: margin-right: 0;
5502: padding: 5px;
5503: }
5504:
5505: div.LC_confirm_box .LC_error img,
5506: div.LC_confirm_box .LC_success img {
5507: vertical-align: middle;
5508: }
5509:
1.440 albertel 5510: .LC_icon {
1.771 droeschl 5511: border: none;
1.790 droeschl 5512: vertical-align: middle;
1.771 droeschl 5513: }
5514:
1.543 albertel 5515: .LC_docs_spacer {
5516: width: 25px;
5517: height: 1px;
1.771 droeschl 5518: border: none;
1.543 albertel 5519: }
1.346 albertel 5520:
1.532 albertel 5521: .LC_internal_info {
1.735 bisitz 5522: color: #999999;
1.532 albertel 5523: }
5524:
1.794 www 5525: .LC_discussion {
1.1050 www 5526: background: $data_table_dark;
1.911 bisitz 5527: border: 1px solid black;
5528: margin: 2px;
1.794 www 5529: }
5530:
5531: .LC_disc_action_left {
1.1050 www 5532: background: $sidebg;
1.911 bisitz 5533: text-align: left;
1.1050 www 5534: padding: 4px;
5535: margin: 2px;
1.794 www 5536: }
5537:
5538: .LC_disc_action_right {
1.1050 www 5539: background: $sidebg;
1.911 bisitz 5540: text-align: right;
1.1050 www 5541: padding: 4px;
5542: margin: 2px;
1.794 www 5543: }
5544:
5545: .LC_disc_new_item {
1.911 bisitz 5546: background: white;
5547: border: 2px solid red;
1.1050 www 5548: margin: 4px;
5549: padding: 4px;
1.794 www 5550: }
5551:
5552: .LC_disc_old_item {
1.911 bisitz 5553: background: white;
1.1050 www 5554: margin: 4px;
5555: padding: 4px;
1.794 www 5556: }
5557:
1.458 albertel 5558: table.LC_pastsubmission {
5559: border: 1px solid black;
5560: margin: 2px;
5561: }
5562:
1.924 bisitz 5563: table#LC_menubuttons {
1.345 albertel 5564: width: 100%;
5565: background: $pgbg;
1.392 albertel 5566: border: 2px;
1.402 albertel 5567: border-collapse: separate;
1.803 bisitz 5568: padding: 0;
1.345 albertel 5569: }
1.392 albertel 5570:
1.801 tempelho 5571: table#LC_title_bar a {
5572: color: $fontmenu;
5573: }
1.836 bisitz 5574:
1.807 droeschl 5575: table#LC_title_bar {
1.819 tempelho 5576: clear: both;
1.836 bisitz 5577: display: none;
1.807 droeschl 5578: }
5579:
1.795 www 5580: table#LC_title_bar,
1.933 droeschl 5581: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5582: table#LC_title_bar.LC_with_remote {
1.359 albertel 5583: width: 100%;
1.392 albertel 5584: border-color: $pgbg;
5585: border-style: solid;
5586: border-width: $border;
1.379 albertel 5587: background: $pgbg;
1.801 tempelho 5588: color: $fontmenu;
1.392 albertel 5589: border-collapse: collapse;
1.803 bisitz 5590: padding: 0;
1.819 tempelho 5591: margin: 0;
1.359 albertel 5592: }
1.795 www 5593:
1.933 droeschl 5594: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5595: margin: 0;
5596: padding: 0;
1.933 droeschl 5597: position: relative;
5598: list-style: none;
1.913 droeschl 5599: }
1.933 droeschl 5600: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5601: display: inline;
5602: }
1.933 droeschl 5603:
5604: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5605: padding: 0;
1.933 droeschl 5606: margin: 0;
5607: float: left;
1.913 droeschl 5608: }
1.933 droeschl 5609: .LC_breadcrumb_tools_tools {
5610: padding: 0;
5611: margin: 0;
1.913 droeschl 5612: float: right;
5613: }
5614:
1.359 albertel 5615: table#LC_title_bar td {
5616: background: $tabbg;
5617: }
1.795 www 5618:
1.911 bisitz 5619: table#LC_menubuttons img {
1.803 bisitz 5620: border: none;
1.346 albertel 5621: }
1.795 www 5622:
1.842 droeschl 5623: .LC_breadcrumbs_component {
1.911 bisitz 5624: float: right;
5625: margin: 0 1em;
1.357 albertel 5626: }
1.842 droeschl 5627: .LC_breadcrumbs_component img {
1.911 bisitz 5628: vertical-align: middle;
1.777 tempelho 5629: }
1.795 www 5630:
1.383 albertel 5631: td.LC_table_cell_checkbox {
5632: text-align: center;
5633: }
1.795 www 5634:
5635: .LC_fontsize_small {
1.911 bisitz 5636: font-size: 70%;
1.705 tempelho 5637: }
5638:
1.844 bisitz 5639: #LC_breadcrumbs {
1.911 bisitz 5640: clear:both;
5641: background: $sidebg;
5642: border-bottom: 1px solid $lg_border_color;
5643: line-height: 2.5em;
1.933 droeschl 5644: overflow: hidden;
1.911 bisitz 5645: margin: 0;
5646: padding: 0;
1.995 raeburn 5647: text-align: left;
1.819 tempelho 5648: }
1.862 bisitz 5649:
1.1075.2.16 raeburn 5650: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5651: clear:both;
5652: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5653: border: 1px solid $sidebg;
1.1075.2.16 raeburn 5654: margin: 0 0 10px 0;
1.966 bisitz 5655: padding: 3px;
1.995 raeburn 5656: text-align: left;
1.822 bisitz 5657: }
5658:
1.795 www 5659: .LC_fontsize_medium {
1.911 bisitz 5660: font-size: 85%;
1.705 tempelho 5661: }
5662:
1.795 www 5663: .LC_fontsize_large {
1.911 bisitz 5664: font-size: 120%;
1.705 tempelho 5665: }
5666:
1.346 albertel 5667: .LC_menubuttons_inline_text {
5668: color: $font;
1.698 harmsja 5669: font-size: 90%;
1.701 harmsja 5670: padding-left:3px;
1.346 albertel 5671: }
5672:
1.934 droeschl 5673: .LC_menubuttons_inline_text img{
5674: vertical-align: middle;
5675: }
5676:
1.1051 www 5677: li.LC_menubuttons_inline_text img {
1.951 onken 5678: cursor:pointer;
1.1002 droeschl 5679: text-decoration: none;
1.951 onken 5680: }
5681:
1.526 www 5682: .LC_menubuttons_link {
5683: text-decoration: none;
5684: }
1.795 www 5685:
1.522 albertel 5686: .LC_menubuttons_category {
1.521 www 5687: color: $font;
1.526 www 5688: background: $pgbg;
1.521 www 5689: font-size: larger;
5690: font-weight: bold;
5691: }
5692:
1.346 albertel 5693: td.LC_menubuttons_text {
1.911 bisitz 5694: color: $font;
1.346 albertel 5695: }
1.706 harmsja 5696:
1.346 albertel 5697: .LC_current_location {
5698: background: $tabbg;
5699: }
1.795 www 5700:
1.938 bisitz 5701: table.LC_data_table {
1.347 albertel 5702: border: 1px solid #000000;
1.402 albertel 5703: border-collapse: separate;
1.426 albertel 5704: border-spacing: 1px;
1.610 albertel 5705: background: $pgbg;
1.347 albertel 5706: }
1.795 www 5707:
1.422 albertel 5708: .LC_data_table_dense {
5709: font-size: small;
5710: }
1.795 www 5711:
1.507 raeburn 5712: table.LC_nested_outer {
5713: border: 1px solid #000000;
1.589 raeburn 5714: border-collapse: collapse;
1.803 bisitz 5715: border-spacing: 0;
1.507 raeburn 5716: width: 100%;
5717: }
1.795 www 5718:
1.879 raeburn 5719: table.LC_innerpickbox,
1.507 raeburn 5720: table.LC_nested {
1.803 bisitz 5721: border: none;
1.589 raeburn 5722: border-collapse: collapse;
1.803 bisitz 5723: border-spacing: 0;
1.507 raeburn 5724: width: 100%;
5725: }
1.795 www 5726:
1.911 bisitz 5727: table.LC_data_table tr th,
5728: table.LC_calendar tr th,
1.879 raeburn 5729: table.LC_prior_tries tr th,
5730: table.LC_innerpickbox tr th {
1.349 albertel 5731: font-weight: bold;
5732: background-color: $data_table_head;
1.801 tempelho 5733: color:$fontmenu;
1.701 harmsja 5734: font-size:90%;
1.347 albertel 5735: }
1.795 www 5736:
1.879 raeburn 5737: table.LC_innerpickbox tr th,
5738: table.LC_innerpickbox tr td {
5739: vertical-align: top;
5740: }
5741:
1.711 raeburn 5742: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5743: background-color: #CCCCCC;
1.711 raeburn 5744: font-weight: bold;
5745: text-align: left;
5746: }
1.795 www 5747:
1.912 bisitz 5748: table.LC_data_table tr.LC_odd_row > td {
5749: background-color: $data_table_light;
5750: padding: 2px;
5751: vertical-align: top;
5752: }
5753:
1.809 bisitz 5754: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5755: background-color: $data_table_light;
1.912 bisitz 5756: vertical-align: top;
5757: }
5758:
5759: table.LC_data_table tr.LC_even_row > td {
5760: background-color: $data_table_dark;
1.425 albertel 5761: padding: 2px;
1.900 bisitz 5762: vertical-align: top;
1.347 albertel 5763: }
1.795 www 5764:
1.809 bisitz 5765: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5766: background-color: $data_table_dark;
1.900 bisitz 5767: vertical-align: top;
1.347 albertel 5768: }
1.795 www 5769:
1.425 albertel 5770: table.LC_data_table tr.LC_data_table_highlight td {
5771: background-color: $data_table_darker;
5772: }
1.795 www 5773:
1.639 raeburn 5774: table.LC_data_table tr td.LC_leftcol_header {
5775: background-color: $data_table_head;
5776: font-weight: bold;
5777: }
1.795 www 5778:
1.451 albertel 5779: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5780: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5781: font-weight: bold;
5782: font-style: italic;
5783: text-align: center;
5784: padding: 8px;
1.347 albertel 5785: }
1.795 www 5786:
1.1075.2.30 raeburn 5787: table.LC_data_table tr.LC_empty_row td,
5788: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5789: background-color: $sidebg;
5790: }
5791:
5792: table.LC_nested tr.LC_empty_row td {
5793: background-color: #FFFFFF;
5794: }
5795:
1.890 droeschl 5796: table.LC_caption {
5797: }
5798:
1.507 raeburn 5799: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5800: padding: 4ex
5801: }
1.795 www 5802:
1.507 raeburn 5803: table.LC_nested_outer tr th {
5804: font-weight: bold;
1.801 tempelho 5805: color:$fontmenu;
1.507 raeburn 5806: background-color: $data_table_head;
1.701 harmsja 5807: font-size: small;
1.507 raeburn 5808: border-bottom: 1px solid #000000;
5809: }
1.795 www 5810:
1.507 raeburn 5811: table.LC_nested_outer tr td.LC_subheader {
5812: background-color: $data_table_head;
5813: font-weight: bold;
5814: font-size: small;
5815: border-bottom: 1px solid #000000;
5816: text-align: right;
1.451 albertel 5817: }
1.795 www 5818:
1.507 raeburn 5819: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5820: background-color: #CCCCCC;
1.451 albertel 5821: font-weight: bold;
5822: font-size: small;
1.507 raeburn 5823: text-align: center;
5824: }
1.795 www 5825:
1.589 raeburn 5826: table.LC_nested tr.LC_info_row td.LC_left_item,
5827: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5828: text-align: left;
1.451 albertel 5829: }
1.795 www 5830:
1.507 raeburn 5831: table.LC_nested td {
1.735 bisitz 5832: background-color: #FFFFFF;
1.451 albertel 5833: font-size: small;
1.507 raeburn 5834: }
1.795 www 5835:
1.507 raeburn 5836: table.LC_nested_outer tr th.LC_right_item,
5837: table.LC_nested tr.LC_info_row td.LC_right_item,
5838: table.LC_nested tr.LC_odd_row td.LC_right_item,
5839: table.LC_nested tr td.LC_right_item {
1.451 albertel 5840: text-align: right;
5841: }
5842:
1.507 raeburn 5843: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5844: background-color: #EEEEEE;
1.451 albertel 5845: }
5846:
1.473 raeburn 5847: table.LC_createuser {
5848: }
5849:
5850: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5851: font-size: small;
1.473 raeburn 5852: }
5853:
5854: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5855: background-color: #CCCCCC;
1.473 raeburn 5856: font-weight: bold;
5857: text-align: center;
5858: }
5859:
1.349 albertel 5860: table.LC_calendar {
5861: border: 1px solid #000000;
5862: border-collapse: collapse;
1.917 raeburn 5863: width: 98%;
1.349 albertel 5864: }
1.795 www 5865:
1.349 albertel 5866: table.LC_calendar_pickdate {
5867: font-size: xx-small;
5868: }
1.795 www 5869:
1.349 albertel 5870: table.LC_calendar tr td {
5871: border: 1px solid #000000;
5872: vertical-align: top;
1.917 raeburn 5873: width: 14%;
1.349 albertel 5874: }
1.795 www 5875:
1.349 albertel 5876: table.LC_calendar tr td.LC_calendar_day_empty {
5877: background-color: $data_table_dark;
5878: }
1.795 www 5879:
1.779 bisitz 5880: table.LC_calendar tr td.LC_calendar_day_current {
5881: background-color: $data_table_highlight;
1.777 tempelho 5882: }
1.795 www 5883:
1.938 bisitz 5884: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5885: background-color: $mail_new;
5886: }
1.795 www 5887:
1.938 bisitz 5888: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5889: background-color: $mail_new_hover;
5890: }
1.795 www 5891:
1.938 bisitz 5892: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5893: background-color: $mail_read;
5894: }
1.795 www 5895:
1.938 bisitz 5896: /*
5897: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5898: background-color: $mail_read_hover;
5899: }
1.938 bisitz 5900: */
1.795 www 5901:
1.938 bisitz 5902: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5903: background-color: $mail_replied;
5904: }
1.795 www 5905:
1.938 bisitz 5906: /*
5907: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5908: background-color: $mail_replied_hover;
5909: }
1.938 bisitz 5910: */
1.795 www 5911:
1.938 bisitz 5912: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5913: background-color: $mail_other;
5914: }
1.795 www 5915:
1.938 bisitz 5916: /*
5917: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5918: background-color: $mail_other_hover;
5919: }
1.938 bisitz 5920: */
1.494 raeburn 5921:
1.777 tempelho 5922: table.LC_data_table tr > td.LC_browser_file,
5923: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5924: background: #AAEE77;
1.389 albertel 5925: }
1.795 www 5926:
1.777 tempelho 5927: table.LC_data_table tr > td.LC_browser_file_locked,
5928: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5929: background: #FFAA99;
1.387 albertel 5930: }
1.795 www 5931:
1.777 tempelho 5932: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5933: background: #888888;
1.779 bisitz 5934: }
1.795 www 5935:
1.777 tempelho 5936: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5937: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5938: background: #F8F866;
1.777 tempelho 5939: }
1.795 www 5940:
1.696 bisitz 5941: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5942: background: #E0E8FF;
1.387 albertel 5943: }
1.696 bisitz 5944:
1.707 bisitz 5945: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5946: /* background: #77FF77; */
1.707 bisitz 5947: }
1.795 www 5948:
1.707 bisitz 5949: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5950: border-right: 8px solid #FFFF77;
1.707 bisitz 5951: }
1.795 www 5952:
1.707 bisitz 5953: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5954: border-right: 8px solid #FFAA77;
1.707 bisitz 5955: }
1.795 www 5956:
1.707 bisitz 5957: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5958: border-right: 8px solid #FF7777;
1.707 bisitz 5959: }
1.795 www 5960:
1.707 bisitz 5961: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5962: border-right: 8px solid #AAFF77;
1.707 bisitz 5963: }
1.795 www 5964:
1.707 bisitz 5965: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5966: border-right: 8px solid #11CC55;
1.707 bisitz 5967: }
5968:
1.388 albertel 5969: span.LC_current_location {
1.701 harmsja 5970: font-size:larger;
1.388 albertel 5971: background: $pgbg;
5972: }
1.387 albertel 5973:
1.1029 www 5974: span.LC_current_nav_location {
5975: font-weight:bold;
5976: background: $sidebg;
5977: }
5978:
1.395 albertel 5979: span.LC_parm_menu_item {
5980: font-size: larger;
5981: }
1.795 www 5982:
1.395 albertel 5983: span.LC_parm_scope_all {
5984: color: red;
5985: }
1.795 www 5986:
1.395 albertel 5987: span.LC_parm_scope_folder {
5988: color: green;
5989: }
1.795 www 5990:
1.395 albertel 5991: span.LC_parm_scope_resource {
5992: color: orange;
5993: }
1.795 www 5994:
1.395 albertel 5995: span.LC_parm_part {
5996: color: blue;
5997: }
1.795 www 5998:
1.911 bisitz 5999: span.LC_parm_folder,
6000: span.LC_parm_symb {
1.395 albertel 6001: font-size: x-small;
6002: font-family: $mono;
6003: color: #AAAAAA;
6004: }
6005:
1.977 bisitz 6006: ul.LC_parm_parmlist li {
6007: display: inline-block;
6008: padding: 0.3em 0.8em;
6009: vertical-align: top;
6010: width: 150px;
6011: border-top:1px solid $lg_border_color;
6012: }
6013:
1.795 www 6014: td.LC_parm_overview_level_menu,
6015: td.LC_parm_overview_map_menu,
6016: td.LC_parm_overview_parm_selectors,
6017: td.LC_parm_overview_restrictions {
1.396 albertel 6018: border: 1px solid black;
6019: border-collapse: collapse;
6020: }
1.795 www 6021:
1.396 albertel 6022: table.LC_parm_overview_restrictions td {
6023: border-width: 1px 4px 1px 4px;
6024: border-style: solid;
6025: border-color: $pgbg;
6026: text-align: center;
6027: }
1.795 www 6028:
1.396 albertel 6029: table.LC_parm_overview_restrictions th {
6030: background: $tabbg;
6031: border-width: 1px 4px 1px 4px;
6032: border-style: solid;
6033: border-color: $pgbg;
6034: }
1.795 www 6035:
1.398 albertel 6036: table#LC_helpmenu {
1.803 bisitz 6037: border: none;
1.398 albertel 6038: height: 55px;
1.803 bisitz 6039: border-spacing: 0;
1.398 albertel 6040: }
6041:
6042: table#LC_helpmenu fieldset legend {
6043: font-size: larger;
6044: }
1.795 www 6045:
1.397 albertel 6046: table#LC_helpmenu_links {
6047: width: 100%;
6048: border: 1px solid black;
6049: background: $pgbg;
1.803 bisitz 6050: padding: 0;
1.397 albertel 6051: border-spacing: 1px;
6052: }
1.795 www 6053:
1.397 albertel 6054: table#LC_helpmenu_links tr td {
6055: padding: 1px;
6056: background: $tabbg;
1.399 albertel 6057: text-align: center;
6058: font-weight: bold;
1.397 albertel 6059: }
1.396 albertel 6060:
1.795 www 6061: table#LC_helpmenu_links a:link,
6062: table#LC_helpmenu_links a:visited,
1.397 albertel 6063: table#LC_helpmenu_links a:active {
6064: text-decoration: none;
6065: color: $font;
6066: }
1.795 www 6067:
1.397 albertel 6068: table#LC_helpmenu_links a:hover {
6069: text-decoration: underline;
6070: color: $vlink;
6071: }
1.396 albertel 6072:
1.417 albertel 6073: .LC_chrt_popup_exists {
6074: border: 1px solid #339933;
6075: margin: -1px;
6076: }
1.795 www 6077:
1.417 albertel 6078: .LC_chrt_popup_up {
6079: border: 1px solid yellow;
6080: margin: -1px;
6081: }
1.795 www 6082:
1.417 albertel 6083: .LC_chrt_popup {
6084: border: 1px solid #8888FF;
6085: background: #CCCCFF;
6086: }
1.795 www 6087:
1.421 albertel 6088: table.LC_pick_box {
6089: border-collapse: separate;
6090: background: white;
6091: border: 1px solid black;
6092: border-spacing: 1px;
6093: }
1.795 www 6094:
1.421 albertel 6095: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6096: background: $sidebg;
1.421 albertel 6097: font-weight: bold;
1.900 bisitz 6098: text-align: left;
1.740 bisitz 6099: vertical-align: top;
1.421 albertel 6100: width: 184px;
6101: padding: 8px;
6102: }
1.795 www 6103:
1.579 raeburn 6104: table.LC_pick_box td.LC_pick_box_value {
6105: text-align: left;
6106: padding: 8px;
6107: }
1.795 www 6108:
1.579 raeburn 6109: table.LC_pick_box td.LC_pick_box_select {
6110: text-align: left;
6111: padding: 8px;
6112: }
1.795 www 6113:
1.424 albertel 6114: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6115: padding: 0;
1.421 albertel 6116: height: 1px;
6117: background: black;
6118: }
1.795 www 6119:
1.421 albertel 6120: table.LC_pick_box td.LC_pick_box_submit {
6121: text-align: right;
6122: }
1.795 www 6123:
1.579 raeburn 6124: table.LC_pick_box td.LC_evenrow_value {
6125: text-align: left;
6126: padding: 8px;
6127: background-color: $data_table_light;
6128: }
1.795 www 6129:
1.579 raeburn 6130: table.LC_pick_box td.LC_oddrow_value {
6131: text-align: left;
6132: padding: 8px;
6133: background-color: $data_table_light;
6134: }
1.795 www 6135:
1.579 raeburn 6136: span.LC_helpform_receipt_cat {
6137: font-weight: bold;
6138: }
1.795 www 6139:
1.424 albertel 6140: table.LC_group_priv_box {
6141: background: white;
6142: border: 1px solid black;
6143: border-spacing: 1px;
6144: }
1.795 www 6145:
1.424 albertel 6146: table.LC_group_priv_box td.LC_pick_box_title {
6147: background: $tabbg;
6148: font-weight: bold;
6149: text-align: right;
6150: width: 184px;
6151: }
1.795 www 6152:
1.424 albertel 6153: table.LC_group_priv_box td.LC_groups_fixed {
6154: background: $data_table_light;
6155: text-align: center;
6156: }
1.795 www 6157:
1.424 albertel 6158: table.LC_group_priv_box td.LC_groups_optional {
6159: background: $data_table_dark;
6160: text-align: center;
6161: }
1.795 www 6162:
1.424 albertel 6163: table.LC_group_priv_box td.LC_groups_functionality {
6164: background: $data_table_darker;
6165: text-align: center;
6166: font-weight: bold;
6167: }
1.795 www 6168:
1.424 albertel 6169: table.LC_group_priv td {
6170: text-align: left;
1.803 bisitz 6171: padding: 0;
1.424 albertel 6172: }
6173:
6174: .LC_navbuttons {
6175: margin: 2ex 0ex 2ex 0ex;
6176: }
1.795 www 6177:
1.423 albertel 6178: .LC_topic_bar {
6179: font-weight: bold;
6180: background: $tabbg;
1.918 wenzelju 6181: margin: 1em 0em 1em 2em;
1.805 bisitz 6182: padding: 3px;
1.918 wenzelju 6183: font-size: 1.2em;
1.423 albertel 6184: }
1.795 www 6185:
1.423 albertel 6186: .LC_topic_bar span {
1.918 wenzelju 6187: left: 0.5em;
6188: position: absolute;
1.423 albertel 6189: vertical-align: middle;
1.918 wenzelju 6190: font-size: 1.2em;
1.423 albertel 6191: }
1.795 www 6192:
1.423 albertel 6193: table.LC_course_group_status {
6194: margin: 20px;
6195: }
1.795 www 6196:
1.423 albertel 6197: table.LC_status_selector td {
6198: vertical-align: top;
6199: text-align: center;
1.424 albertel 6200: padding: 4px;
6201: }
1.795 www 6202:
1.599 albertel 6203: div.LC_feedback_link {
1.616 albertel 6204: clear: both;
1.829 kalberla 6205: background: $sidebg;
1.779 bisitz 6206: width: 100%;
1.829 kalberla 6207: padding-bottom: 10px;
6208: border: 1px $tabbg solid;
1.833 kalberla 6209: height: 22px;
6210: line-height: 22px;
6211: padding-top: 5px;
6212: }
6213:
6214: div.LC_feedback_link img {
6215: height: 22px;
1.867 kalberla 6216: vertical-align:middle;
1.829 kalberla 6217: }
6218:
1.911 bisitz 6219: div.LC_feedback_link a {
1.829 kalberla 6220: text-decoration: none;
1.489 raeburn 6221: }
1.795 www 6222:
1.867 kalberla 6223: div.LC_comblock {
1.911 bisitz 6224: display:inline;
1.867 kalberla 6225: color:$font;
6226: font-size:90%;
6227: }
6228:
6229: div.LC_feedback_link div.LC_comblock {
6230: padding-left:5px;
6231: }
6232:
6233: div.LC_feedback_link div.LC_comblock a {
6234: color:$font;
6235: }
6236:
1.489 raeburn 6237: span.LC_feedback_link {
1.858 bisitz 6238: /* background: $feedback_link_bg; */
1.599 albertel 6239: font-size: larger;
6240: }
1.795 www 6241:
1.599 albertel 6242: span.LC_message_link {
1.858 bisitz 6243: /* background: $feedback_link_bg; */
1.599 albertel 6244: font-size: larger;
6245: position: absolute;
6246: right: 1em;
1.489 raeburn 6247: }
1.421 albertel 6248:
1.515 albertel 6249: table.LC_prior_tries {
1.524 albertel 6250: border: 1px solid #000000;
6251: border-collapse: separate;
6252: border-spacing: 1px;
1.515 albertel 6253: }
1.523 albertel 6254:
1.515 albertel 6255: table.LC_prior_tries td {
1.524 albertel 6256: padding: 2px;
1.515 albertel 6257: }
1.523 albertel 6258:
6259: .LC_answer_correct {
1.795 www 6260: background: lightgreen;
6261: color: darkgreen;
6262: padding: 6px;
1.523 albertel 6263: }
1.795 www 6264:
1.523 albertel 6265: .LC_answer_charged_try {
1.797 www 6266: background: #FFAAAA;
1.795 www 6267: color: darkred;
6268: padding: 6px;
1.523 albertel 6269: }
1.795 www 6270:
1.779 bisitz 6271: .LC_answer_not_charged_try,
1.523 albertel 6272: .LC_answer_no_grade,
6273: .LC_answer_late {
1.795 www 6274: background: lightyellow;
1.523 albertel 6275: color: black;
1.795 www 6276: padding: 6px;
1.523 albertel 6277: }
1.795 www 6278:
1.523 albertel 6279: .LC_answer_previous {
1.795 www 6280: background: lightblue;
6281: color: darkblue;
6282: padding: 6px;
1.523 albertel 6283: }
1.795 www 6284:
1.779 bisitz 6285: .LC_answer_no_message {
1.777 tempelho 6286: background: #FFFFFF;
6287: color: black;
1.795 www 6288: padding: 6px;
1.779 bisitz 6289: }
1.795 www 6290:
1.779 bisitz 6291: .LC_answer_unknown {
6292: background: orange;
6293: color: black;
1.795 www 6294: padding: 6px;
1.777 tempelho 6295: }
1.795 www 6296:
1.529 albertel 6297: span.LC_prior_numerical,
6298: span.LC_prior_string,
6299: span.LC_prior_custom,
6300: span.LC_prior_reaction,
6301: span.LC_prior_math {
1.925 bisitz 6302: font-family: $mono;
1.523 albertel 6303: white-space: pre;
6304: }
6305:
1.525 albertel 6306: span.LC_prior_string {
1.925 bisitz 6307: font-family: $mono;
1.525 albertel 6308: white-space: pre;
6309: }
6310:
1.523 albertel 6311: table.LC_prior_option {
6312: width: 100%;
6313: border-collapse: collapse;
6314: }
1.795 www 6315:
1.911 bisitz 6316: table.LC_prior_rank,
1.795 www 6317: table.LC_prior_match {
1.528 albertel 6318: border-collapse: collapse;
6319: }
1.795 www 6320:
1.528 albertel 6321: table.LC_prior_option tr td,
6322: table.LC_prior_rank tr td,
6323: table.LC_prior_match tr td {
1.524 albertel 6324: border: 1px solid #000000;
1.515 albertel 6325: }
6326:
1.855 bisitz 6327: .LC_nobreak {
1.544 albertel 6328: white-space: nowrap;
1.519 raeburn 6329: }
6330:
1.576 raeburn 6331: span.LC_cusr_emph {
6332: font-style: italic;
6333: }
6334:
1.633 raeburn 6335: span.LC_cusr_subheading {
6336: font-weight: normal;
6337: font-size: 85%;
6338: }
6339:
1.861 bisitz 6340: div.LC_docs_entry_move {
1.859 bisitz 6341: border: 1px solid #BBBBBB;
1.545 albertel 6342: background: #DDDDDD;
1.861 bisitz 6343: width: 22px;
1.859 bisitz 6344: padding: 1px;
6345: margin: 0;
1.545 albertel 6346: }
6347:
1.861 bisitz 6348: table.LC_data_table tr > td.LC_docs_entry_commands,
6349: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6350: font-size: x-small;
6351: }
1.795 www 6352:
1.861 bisitz 6353: .LC_docs_entry_parameter {
6354: white-space: nowrap;
6355: }
6356:
1.544 albertel 6357: .LC_docs_copy {
1.545 albertel 6358: color: #000099;
1.544 albertel 6359: }
1.795 www 6360:
1.544 albertel 6361: .LC_docs_cut {
1.545 albertel 6362: color: #550044;
1.544 albertel 6363: }
1.795 www 6364:
1.544 albertel 6365: .LC_docs_rename {
1.545 albertel 6366: color: #009900;
1.544 albertel 6367: }
1.795 www 6368:
1.544 albertel 6369: .LC_docs_remove {
1.545 albertel 6370: color: #990000;
6371: }
6372:
1.547 albertel 6373: .LC_docs_reinit_warn,
6374: .LC_docs_ext_edit {
6375: font-size: x-small;
6376: }
6377:
1.545 albertel 6378: table.LC_docs_adddocs td,
6379: table.LC_docs_adddocs th {
6380: border: 1px solid #BBBBBB;
6381: padding: 4px;
6382: background: #DDDDDD;
1.543 albertel 6383: }
6384:
1.584 albertel 6385: table.LC_sty_begin {
6386: background: #BBFFBB;
6387: }
1.795 www 6388:
1.584 albertel 6389: table.LC_sty_end {
6390: background: #FFBBBB;
6391: }
6392:
1.589 raeburn 6393: table.LC_double_column {
1.803 bisitz 6394: border-width: 0;
1.589 raeburn 6395: border-collapse: collapse;
6396: width: 100%;
6397: padding: 2px;
6398: }
6399:
6400: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6401: top: 2px;
1.589 raeburn 6402: left: 2px;
6403: width: 47%;
6404: vertical-align: top;
6405: }
6406:
6407: table.LC_double_column tr td.LC_right_col {
6408: top: 2px;
1.779 bisitz 6409: right: 2px;
1.589 raeburn 6410: width: 47%;
6411: vertical-align: top;
6412: }
6413:
1.591 raeburn 6414: div.LC_left_float {
6415: float: left;
6416: padding-right: 5%;
1.597 albertel 6417: padding-bottom: 4px;
1.591 raeburn 6418: }
6419:
6420: div.LC_clear_float_header {
1.597 albertel 6421: padding-bottom: 2px;
1.591 raeburn 6422: }
6423:
6424: div.LC_clear_float_footer {
1.597 albertel 6425: padding-top: 10px;
1.591 raeburn 6426: clear: both;
6427: }
6428:
1.597 albertel 6429: div.LC_grade_show_user {
1.941 bisitz 6430: /* border-left: 5px solid $sidebg; */
6431: border-top: 5px solid #000000;
6432: margin: 50px 0 0 0;
1.936 bisitz 6433: padding: 15px 0 5px 10px;
1.597 albertel 6434: }
1.795 www 6435:
1.936 bisitz 6436: div.LC_grade_show_user_odd_row {
1.941 bisitz 6437: /* border-left: 5px solid #000000; */
6438: }
6439:
6440: div.LC_grade_show_user div.LC_Box {
6441: margin-right: 50px;
1.597 albertel 6442: }
6443:
6444: div.LC_grade_submissions,
6445: div.LC_grade_message_center,
1.936 bisitz 6446: div.LC_grade_info_links {
1.597 albertel 6447: margin: 5px;
6448: width: 99%;
6449: background: #FFFFFF;
6450: }
1.795 www 6451:
1.597 albertel 6452: div.LC_grade_submissions_header,
1.936 bisitz 6453: div.LC_grade_message_center_header {
1.705 tempelho 6454: font-weight: bold;
6455: font-size: large;
1.597 albertel 6456: }
1.795 www 6457:
1.597 albertel 6458: div.LC_grade_submissions_body,
1.936 bisitz 6459: div.LC_grade_message_center_body {
1.597 albertel 6460: border: 1px solid black;
6461: width: 99%;
6462: background: #FFFFFF;
6463: }
1.795 www 6464:
1.613 albertel 6465: table.LC_scantron_action {
6466: width: 100%;
6467: }
1.795 www 6468:
1.613 albertel 6469: table.LC_scantron_action tr th {
1.698 harmsja 6470: font-weight:bold;
6471: font-style:normal;
1.613 albertel 6472: }
1.795 www 6473:
1.779 bisitz 6474: .LC_edit_problem_header,
1.614 albertel 6475: div.LC_edit_problem_footer {
1.705 tempelho 6476: font-weight: normal;
6477: font-size: medium;
1.602 albertel 6478: margin: 2px;
1.1060 bisitz 6479: background-color: $sidebg;
1.600 albertel 6480: }
1.795 www 6481:
1.600 albertel 6482: div.LC_edit_problem_header,
1.602 albertel 6483: div.LC_edit_problem_header div,
1.614 albertel 6484: div.LC_edit_problem_footer,
6485: div.LC_edit_problem_footer div,
1.602 albertel 6486: div.LC_edit_problem_editxml_header,
6487: div.LC_edit_problem_editxml_header div {
1.600 albertel 6488: margin-top: 5px;
6489: }
1.795 www 6490:
1.600 albertel 6491: div.LC_edit_problem_header_title {
1.705 tempelho 6492: font-weight: bold;
6493: font-size: larger;
1.602 albertel 6494: background: $tabbg;
6495: padding: 3px;
1.1060 bisitz 6496: margin: 0 0 5px 0;
1.602 albertel 6497: }
1.795 www 6498:
1.602 albertel 6499: table.LC_edit_problem_header_title {
6500: width: 100%;
1.600 albertel 6501: background: $tabbg;
1.602 albertel 6502: }
6503:
6504: div.LC_edit_problem_discards {
6505: float: left;
6506: padding-bottom: 5px;
6507: }
1.795 www 6508:
1.602 albertel 6509: div.LC_edit_problem_saves {
6510: float: right;
6511: padding-bottom: 5px;
1.600 albertel 6512: }
1.795 www 6513:
1.1075.2.34 raeburn 6514: .LC_edit_opt {
6515: padding-left: 1em;
6516: white-space: nowrap;
6517: }
6518:
1.1075.2.57 raeburn 6519: .LC_edit_problem_latexhelper{
6520: text-align: right;
6521: }
6522:
6523: #LC_edit_problem_colorful div{
6524: margin-left: 40px;
6525: }
6526:
1.911 bisitz 6527: img.stift {
1.803 bisitz 6528: border-width: 0;
6529: vertical-align: middle;
1.677 riegler 6530: }
1.680 riegler 6531:
1.923 bisitz 6532: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6533: vertical-align: top;
1.777 tempelho 6534: }
1.795 www 6535:
1.716 raeburn 6536: div.LC_createcourse {
1.911 bisitz 6537: margin: 10px 10px 10px 10px;
1.716 raeburn 6538: }
6539:
1.917 raeburn 6540: .LC_dccid {
1.1075.2.38 raeburn 6541: float: right;
1.917 raeburn 6542: margin: 0.2em 0 0 0;
6543: padding: 0;
6544: font-size: 90%;
6545: display:none;
6546: }
6547:
1.897 wenzelju 6548: ol.LC_primary_menu a:hover,
1.721 harmsja 6549: ol#LC_MenuBreadcrumbs a:hover,
6550: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6551: ul#LC_secondary_menu a:hover,
1.721 harmsja 6552: .LC_FormSectionClearButton input:hover
1.795 www 6553: ul.LC_TabContent li:hover a {
1.952 onken 6554: color:$button_hover;
1.911 bisitz 6555: text-decoration:none;
1.693 droeschl 6556: }
6557:
1.779 bisitz 6558: h1 {
1.911 bisitz 6559: padding: 0;
6560: line-height:130%;
1.693 droeschl 6561: }
1.698 harmsja 6562:
1.911 bisitz 6563: h2,
6564: h3,
6565: h4,
6566: h5,
6567: h6 {
6568: margin: 5px 0 5px 0;
6569: padding: 0;
6570: line-height:130%;
1.693 droeschl 6571: }
1.795 www 6572:
6573: .LC_hcell {
1.911 bisitz 6574: padding:3px 15px 3px 15px;
6575: margin: 0;
6576: background-color:$tabbg;
6577: color:$fontmenu;
6578: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6579: }
1.795 www 6580:
1.840 bisitz 6581: .LC_Box > .LC_hcell {
1.911 bisitz 6582: margin: 0 -10px 10px -10px;
1.835 bisitz 6583: }
6584:
1.721 harmsja 6585: .LC_noBorder {
1.911 bisitz 6586: border: 0;
1.698 harmsja 6587: }
1.693 droeschl 6588:
1.721 harmsja 6589: .LC_FormSectionClearButton input {
1.911 bisitz 6590: background-color:transparent;
6591: border: none;
6592: cursor:pointer;
6593: text-decoration:underline;
1.693 droeschl 6594: }
1.763 bisitz 6595:
6596: .LC_help_open_topic {
1.911 bisitz 6597: color: #FFFFFF;
6598: background-color: #EEEEFF;
6599: margin: 1px;
6600: padding: 4px;
6601: border: 1px solid #000033;
6602: white-space: nowrap;
6603: /* vertical-align: middle; */
1.759 neumanie 6604: }
1.693 droeschl 6605:
1.911 bisitz 6606: dl,
6607: ul,
6608: div,
6609: fieldset {
6610: margin: 10px 10px 10px 0;
6611: /* overflow: hidden; */
1.693 droeschl 6612: }
1.795 www 6613:
1.838 bisitz 6614: fieldset > legend {
1.911 bisitz 6615: font-weight: bold;
6616: padding: 0 5px 0 5px;
1.838 bisitz 6617: }
6618:
1.813 bisitz 6619: #LC_nav_bar {
1.911 bisitz 6620: float: left;
1.995 raeburn 6621: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6622: margin: 0 0 2px 0;
1.807 droeschl 6623: }
6624:
1.916 droeschl 6625: #LC_realm {
6626: margin: 0.2em 0 0 0;
6627: padding: 0;
6628: font-weight: bold;
6629: text-align: center;
1.995 raeburn 6630: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6631: }
6632:
1.911 bisitz 6633: #LC_nav_bar em {
6634: font-weight: bold;
6635: font-style: normal;
1.807 droeschl 6636: }
6637:
1.897 wenzelju 6638: ol.LC_primary_menu {
1.934 droeschl 6639: margin: 0;
1.1075.2.2 raeburn 6640: padding: 0;
1.995 raeburn 6641: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6642: }
6643:
1.852 droeschl 6644: ol#LC_PathBreadcrumbs {
1.911 bisitz 6645: margin: 0;
1.693 droeschl 6646: }
6647:
1.897 wenzelju 6648: ol.LC_primary_menu li {
1.1075.2.2 raeburn 6649: color: RGB(80, 80, 80);
6650: vertical-align: middle;
6651: text-align: left;
6652: list-style: none;
6653: float: left;
6654: }
6655:
6656: ol.LC_primary_menu li a {
6657: display: block;
6658: margin: 0;
6659: padding: 0 5px 0 10px;
6660: text-decoration: none;
6661: }
6662:
6663: ol.LC_primary_menu li ul {
6664: display: none;
6665: width: 10em;
6666: background-color: $data_table_light;
6667: }
6668:
6669: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6670: display: block;
6671: position: absolute;
6672: margin: 0;
6673: padding: 0;
1.1075.2.5 raeburn 6674: z-index: 2;
1.1075.2.2 raeburn 6675: }
6676:
6677: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6678: font-size: 90%;
1.911 bisitz 6679: vertical-align: top;
1.1075.2.2 raeburn 6680: float: none;
1.1075.2.5 raeburn 6681: border-left: 1px solid black;
6682: border-right: 1px solid black;
1.1075.2.2 raeburn 6683: }
6684:
6685: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5 raeburn 6686: background-color:$data_table_light;
1.1075.2.2 raeburn 6687: }
6688:
6689: ol.LC_primary_menu li li a:hover {
6690: color:$button_hover;
6691: background-color:$data_table_dark;
1.693 droeschl 6692: }
6693:
1.897 wenzelju 6694: ol.LC_primary_menu li img {
1.911 bisitz 6695: vertical-align: bottom;
1.934 droeschl 6696: height: 1.1em;
1.1075.2.3 raeburn 6697: margin: 0.2em 0 0 0;
1.693 droeschl 6698: }
6699:
1.897 wenzelju 6700: ol.LC_primary_menu a {
1.911 bisitz 6701: color: RGB(80, 80, 80);
6702: text-decoration: none;
1.693 droeschl 6703: }
1.795 www 6704:
1.949 droeschl 6705: ol.LC_primary_menu a.LC_new_message {
6706: font-weight:bold;
6707: color: darkred;
6708: }
6709:
1.975 raeburn 6710: ol.LC_docs_parameters {
6711: margin-left: 0;
6712: padding: 0;
6713: list-style: none;
6714: }
6715:
6716: ol.LC_docs_parameters li {
6717: margin: 0;
6718: padding-right: 20px;
6719: display: inline;
6720: }
6721:
1.976 raeburn 6722: ol.LC_docs_parameters li:before {
6723: content: "\\002022 \\0020";
6724: }
6725:
6726: li.LC_docs_parameters_title {
6727: font-weight: bold;
6728: }
6729:
6730: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6731: content: "";
6732: }
6733:
1.897 wenzelju 6734: ul#LC_secondary_menu {
1.1075.2.23 raeburn 6735: clear: right;
1.911 bisitz 6736: color: $fontmenu;
6737: background: $tabbg;
6738: list-style: none;
6739: padding: 0;
6740: margin: 0;
6741: width: 100%;
1.995 raeburn 6742: text-align: left;
1.1075.2.4 raeburn 6743: float: left;
1.808 droeschl 6744: }
6745:
1.897 wenzelju 6746: ul#LC_secondary_menu li {
1.911 bisitz 6747: font-weight: bold;
6748: line-height: 1.8em;
6749: border-right: 1px solid black;
6750: vertical-align: middle;
1.1075.2.4 raeburn 6751: float: left;
6752: }
6753:
6754: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6755: background-color: $data_table_light;
6756: }
6757:
6758: ul#LC_secondary_menu li a {
6759: padding: 0 0.8em;
6760: }
6761:
6762: ul#LC_secondary_menu li ul {
6763: display: none;
6764: }
6765:
6766: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6767: display: block;
6768: position: absolute;
6769: margin: 0;
6770: padding: 0;
6771: list-style:none;
6772: float: none;
6773: background-color: $data_table_light;
1.1075.2.5 raeburn 6774: z-index: 2;
1.1075.2.10 raeburn 6775: margin-left: -1px;
1.1075.2.4 raeburn 6776: }
6777:
6778: ul#LC_secondary_menu li ul li {
6779: font-size: 90%;
6780: vertical-align: top;
6781: border-left: 1px solid black;
6782: border-right: 1px solid black;
1.1075.2.33 raeburn 6783: background-color: $data_table_light;
1.1075.2.4 raeburn 6784: list-style:none;
6785: float: none;
6786: }
6787:
6788: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6789: background-color: $data_table_dark;
1.807 droeschl 6790: }
6791:
1.847 tempelho 6792: ul.LC_TabContent {
1.911 bisitz 6793: display:block;
6794: background: $sidebg;
6795: border-bottom: solid 1px $lg_border_color;
6796: list-style:none;
1.1020 raeburn 6797: margin: -1px -10px 0 -10px;
1.911 bisitz 6798: padding: 0;
1.693 droeschl 6799: }
6800:
1.795 www 6801: ul.LC_TabContent li,
6802: ul.LC_TabContentBigger li {
1.911 bisitz 6803: float:left;
1.741 harmsja 6804: }
1.795 www 6805:
1.897 wenzelju 6806: ul#LC_secondary_menu li a {
1.911 bisitz 6807: color: $fontmenu;
6808: text-decoration: none;
1.693 droeschl 6809: }
1.795 www 6810:
1.721 harmsja 6811: ul.LC_TabContent {
1.952 onken 6812: min-height:20px;
1.721 harmsja 6813: }
1.795 www 6814:
6815: ul.LC_TabContent li {
1.911 bisitz 6816: vertical-align:middle;
1.959 onken 6817: padding: 0 16px 0 10px;
1.911 bisitz 6818: background-color:$tabbg;
6819: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6820: border-left: solid 1px $font;
1.721 harmsja 6821: }
1.795 www 6822:
1.847 tempelho 6823: ul.LC_TabContent .right {
1.911 bisitz 6824: float:right;
1.847 tempelho 6825: }
6826:
1.911 bisitz 6827: ul.LC_TabContent li a,
6828: ul.LC_TabContent li {
6829: color:rgb(47,47,47);
6830: text-decoration:none;
6831: font-size:95%;
6832: font-weight:bold;
1.952 onken 6833: min-height:20px;
6834: }
6835:
1.959 onken 6836: ul.LC_TabContent li a:hover,
6837: ul.LC_TabContent li a:focus {
1.952 onken 6838: color: $button_hover;
1.959 onken 6839: background:none;
6840: outline:none;
1.952 onken 6841: }
6842:
6843: ul.LC_TabContent li:hover {
6844: color: $button_hover;
6845: cursor:pointer;
1.721 harmsja 6846: }
1.795 www 6847:
1.911 bisitz 6848: ul.LC_TabContent li.active {
1.952 onken 6849: color: $font;
1.911 bisitz 6850: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6851: border-bottom:solid 1px #FFFFFF;
6852: cursor: default;
1.744 ehlerst 6853: }
1.795 www 6854:
1.959 onken 6855: ul.LC_TabContent li.active a {
6856: color:$font;
6857: background:#FFFFFF;
6858: outline: none;
6859: }
1.1047 raeburn 6860:
6861: ul.LC_TabContent li.goback {
6862: float: left;
6863: border-left: none;
6864: }
6865:
1.870 tempelho 6866: #maincoursedoc {
1.911 bisitz 6867: clear:both;
1.870 tempelho 6868: }
6869:
6870: ul.LC_TabContentBigger {
1.911 bisitz 6871: display:block;
6872: list-style:none;
6873: padding: 0;
1.870 tempelho 6874: }
6875:
1.795 www 6876: ul.LC_TabContentBigger li {
1.911 bisitz 6877: vertical-align:bottom;
6878: height: 30px;
6879: font-size:110%;
6880: font-weight:bold;
6881: color: #737373;
1.841 tempelho 6882: }
6883:
1.957 onken 6884: ul.LC_TabContentBigger li.active {
6885: position: relative;
6886: top: 1px;
6887: }
6888:
1.870 tempelho 6889: ul.LC_TabContentBigger li a {
1.911 bisitz 6890: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6891: height: 30px;
6892: line-height: 30px;
6893: text-align: center;
6894: display: block;
6895: text-decoration: none;
1.958 onken 6896: outline: none;
1.741 harmsja 6897: }
1.795 www 6898:
1.870 tempelho 6899: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6900: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6901: color:$font;
1.744 ehlerst 6902: }
1.795 www 6903:
1.870 tempelho 6904: ul.LC_TabContentBigger li b {
1.911 bisitz 6905: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6906: display: block;
6907: float: left;
6908: padding: 0 30px;
1.957 onken 6909: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6910: }
6911:
1.956 onken 6912: ul.LC_TabContentBigger li:hover b {
6913: color:$button_hover;
6914: }
6915:
1.870 tempelho 6916: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6917: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6918: color:$font;
1.957 onken 6919: border: 0;
1.741 harmsja 6920: }
1.693 droeschl 6921:
1.870 tempelho 6922:
1.862 bisitz 6923: ul.LC_CourseBreadcrumbs {
6924: background: $sidebg;
1.1020 raeburn 6925: height: 2em;
1.862 bisitz 6926: padding-left: 10px;
1.1020 raeburn 6927: margin: 0;
1.862 bisitz 6928: list-style-position: inside;
6929: }
6930:
1.911 bisitz 6931: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6932: ol#LC_PathBreadcrumbs {
1.911 bisitz 6933: padding-left: 10px;
6934: margin: 0;
1.933 droeschl 6935: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6936: }
6937:
1.911 bisitz 6938: ol#LC_MenuBreadcrumbs li,
6939: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6940: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6941: display: inline;
1.933 droeschl 6942: white-space: normal;
1.693 droeschl 6943: }
6944:
1.823 bisitz 6945: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6946: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6947: text-decoration: none;
6948: font-size:90%;
1.693 droeschl 6949: }
1.795 www 6950:
1.969 droeschl 6951: ol#LC_MenuBreadcrumbs h1 {
6952: display: inline;
6953: font-size: 90%;
6954: line-height: 2.5em;
6955: margin: 0;
6956: padding: 0;
6957: }
6958:
1.795 www 6959: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6960: text-decoration:none;
6961: font-size:100%;
6962: font-weight:bold;
1.693 droeschl 6963: }
1.795 www 6964:
1.840 bisitz 6965: .LC_Box {
1.911 bisitz 6966: border: solid 1px $lg_border_color;
6967: padding: 0 10px 10px 10px;
1.746 neumanie 6968: }
1.795 www 6969:
1.1020 raeburn 6970: .LC_DocsBox {
6971: border: solid 1px $lg_border_color;
6972: padding: 0 0 10px 10px;
6973: }
6974:
1.795 www 6975: .LC_AboutMe_Image {
1.911 bisitz 6976: float:left;
6977: margin-right:10px;
1.747 neumanie 6978: }
1.795 www 6979:
6980: .LC_Clear_AboutMe_Image {
1.911 bisitz 6981: clear:left;
1.747 neumanie 6982: }
1.795 www 6983:
1.721 harmsja 6984: dl.LC_ListStyleClean dt {
1.911 bisitz 6985: padding-right: 5px;
6986: display: table-header-group;
1.693 droeschl 6987: }
6988:
1.721 harmsja 6989: dl.LC_ListStyleClean dd {
1.911 bisitz 6990: display: table-row;
1.693 droeschl 6991: }
6992:
1.721 harmsja 6993: .LC_ListStyleClean,
6994: .LC_ListStyleSimple,
6995: .LC_ListStyleNormal,
1.795 www 6996: .LC_ListStyleSpecial {
1.911 bisitz 6997: /* display:block; */
6998: list-style-position: inside;
6999: list-style-type: none;
7000: overflow: hidden;
7001: padding: 0;
1.693 droeschl 7002: }
7003:
1.721 harmsja 7004: .LC_ListStyleSimple li,
7005: .LC_ListStyleSimple dd,
7006: .LC_ListStyleNormal li,
7007: .LC_ListStyleNormal dd,
7008: .LC_ListStyleSpecial li,
1.795 www 7009: .LC_ListStyleSpecial dd {
1.911 bisitz 7010: margin: 0;
7011: padding: 5px 5px 5px 10px;
7012: clear: both;
1.693 droeschl 7013: }
7014:
1.721 harmsja 7015: .LC_ListStyleClean li,
7016: .LC_ListStyleClean dd {
1.911 bisitz 7017: padding-top: 0;
7018: padding-bottom: 0;
1.693 droeschl 7019: }
7020:
1.721 harmsja 7021: .LC_ListStyleSimple dd,
1.795 www 7022: .LC_ListStyleSimple li {
1.911 bisitz 7023: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7024: }
7025:
1.721 harmsja 7026: .LC_ListStyleSpecial li,
7027: .LC_ListStyleSpecial dd {
1.911 bisitz 7028: list-style-type: none;
7029: background-color: RGB(220, 220, 220);
7030: margin-bottom: 4px;
1.693 droeschl 7031: }
7032:
1.721 harmsja 7033: table.LC_SimpleTable {
1.911 bisitz 7034: margin:5px;
7035: border:solid 1px $lg_border_color;
1.795 www 7036: }
1.693 droeschl 7037:
1.721 harmsja 7038: table.LC_SimpleTable tr {
1.911 bisitz 7039: padding: 0;
7040: border:solid 1px $lg_border_color;
1.693 droeschl 7041: }
1.795 www 7042:
7043: table.LC_SimpleTable thead {
1.911 bisitz 7044: background:rgb(220,220,220);
1.693 droeschl 7045: }
7046:
1.721 harmsja 7047: div.LC_columnSection {
1.911 bisitz 7048: display: block;
7049: clear: both;
7050: overflow: hidden;
7051: margin: 0;
1.693 droeschl 7052: }
7053:
1.721 harmsja 7054: div.LC_columnSection>* {
1.911 bisitz 7055: float: left;
7056: margin: 10px 20px 10px 0;
7057: overflow:hidden;
1.693 droeschl 7058: }
1.721 harmsja 7059:
1.795 www 7060: table em {
1.911 bisitz 7061: font-weight: bold;
7062: font-style: normal;
1.748 schulted 7063: }
1.795 www 7064:
1.779 bisitz 7065: table.LC_tableBrowseRes,
1.795 www 7066: table.LC_tableOfContent {
1.911 bisitz 7067: border:none;
7068: border-spacing: 1px;
7069: padding: 3px;
7070: background-color: #FFFFFF;
7071: font-size: 90%;
1.753 droeschl 7072: }
1.789 droeschl 7073:
1.911 bisitz 7074: table.LC_tableOfContent {
7075: border-collapse: collapse;
1.789 droeschl 7076: }
7077:
1.771 droeschl 7078: table.LC_tableBrowseRes a,
1.768 schulted 7079: table.LC_tableOfContent a {
1.911 bisitz 7080: background-color: transparent;
7081: text-decoration: none;
1.753 droeschl 7082: }
7083:
1.795 www 7084: table.LC_tableOfContent img {
1.911 bisitz 7085: border: none;
7086: height: 1.3em;
7087: vertical-align: text-bottom;
7088: margin-right: 0.3em;
1.753 droeschl 7089: }
1.757 schulted 7090:
1.795 www 7091: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7092: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7093: }
7094:
1.795 www 7095: a#LC_content_toolbar_everything {
1.911 bisitz 7096: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7097: }
7098:
1.795 www 7099: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7100: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7101: }
7102:
1.795 www 7103: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7104: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7105: }
7106:
1.795 www 7107: a#LC_content_toolbar_changefolder {
1.911 bisitz 7108: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7109: }
7110:
1.795 www 7111: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7112: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7113: }
7114:
1.1043 raeburn 7115: a#LC_content_toolbar_edittoplevel {
7116: background-image:url(/res/adm/pages/edittoplevel.gif);
7117: }
7118:
1.795 www 7119: ul#LC_toolbar li a:hover {
1.911 bisitz 7120: background-position: bottom center;
1.757 schulted 7121: }
7122:
1.795 www 7123: ul#LC_toolbar {
1.911 bisitz 7124: padding: 0;
7125: margin: 2px;
7126: list-style:none;
7127: position:relative;
7128: background-color:white;
1.1075.2.9 raeburn 7129: overflow: auto;
1.757 schulted 7130: }
7131:
1.795 www 7132: ul#LC_toolbar li {
1.911 bisitz 7133: border:1px solid white;
7134: padding: 0;
7135: margin: 0;
7136: float: left;
7137: display:inline;
7138: vertical-align:middle;
1.1075.2.9 raeburn 7139: white-space: nowrap;
1.911 bisitz 7140: }
1.757 schulted 7141:
1.783 amueller 7142:
1.795 www 7143: a.LC_toolbarItem {
1.911 bisitz 7144: display:block;
7145: padding: 0;
7146: margin: 0;
7147: height: 32px;
7148: width: 32px;
7149: color:white;
7150: border: none;
7151: background-repeat:no-repeat;
7152: background-color:transparent;
1.757 schulted 7153: }
7154:
1.915 droeschl 7155: ul.LC_funclist {
7156: margin: 0;
7157: padding: 0.5em 1em 0.5em 0;
7158: }
7159:
1.933 droeschl 7160: ul.LC_funclist > li:first-child {
7161: font-weight:bold;
7162: margin-left:0.8em;
7163: }
7164:
1.915 droeschl 7165: ul.LC_funclist + ul.LC_funclist {
7166: /*
7167: left border as a seperator if we have more than
7168: one list
7169: */
7170: border-left: 1px solid $sidebg;
7171: /*
7172: this hides the left border behind the border of the
7173: outer box if element is wrapped to the next 'line'
7174: */
7175: margin-left: -1px;
7176: }
7177:
1.843 bisitz 7178: ul.LC_funclist li {
1.915 droeschl 7179: display: inline;
1.782 bisitz 7180: white-space: nowrap;
1.915 droeschl 7181: margin: 0 0 0 25px;
7182: line-height: 150%;
1.782 bisitz 7183: }
7184:
1.974 wenzelju 7185: .LC_hidden {
7186: display: none;
7187: }
7188:
1.1030 www 7189: .LCmodal-overlay {
7190: position:fixed;
7191: top:0;
7192: right:0;
7193: bottom:0;
7194: left:0;
7195: height:100%;
7196: width:100%;
7197: margin:0;
7198: padding:0;
7199: background:#999;
7200: opacity:.75;
7201: filter: alpha(opacity=75);
7202: -moz-opacity: 0.75;
7203: z-index:101;
7204: }
7205:
7206: * html .LCmodal-overlay {
7207: position: absolute;
7208: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7209: }
7210:
7211: .LCmodal-window {
7212: position:fixed;
7213: top:50%;
7214: left:50%;
7215: margin:0;
7216: padding:0;
7217: z-index:102;
7218: }
7219:
7220: * html .LCmodal-window {
7221: position:absolute;
7222: }
7223:
7224: .LCclose-window {
7225: position:absolute;
7226: width:32px;
7227: height:32px;
7228: right:8px;
7229: top:8px;
7230: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7231: text-indent:-99999px;
7232: overflow:hidden;
7233: cursor:pointer;
7234: }
7235:
1.1075.2.17 raeburn 7236: /*
7237: styles used by TTH when "Default set of options to pass to tth/m
7238: when converting TeX" in course settings has been set
7239:
7240: option passed: -t
7241:
7242: */
7243:
7244: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7245: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7246: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7247: td div.norm {line-height:normal;}
7248:
7249: /*
7250: option passed -y3
7251: */
7252:
7253: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7254: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7255: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7256:
1.343 albertel 7257: END
7258: }
7259:
1.306 albertel 7260: =pod
7261:
7262: =item * &headtag()
7263:
7264: Returns a uniform footer for LON-CAPA web pages.
7265:
1.307 albertel 7266: Inputs: $title - optional title for the head
7267: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7268: $args - optional arguments
1.319 albertel 7269: force_register - if is true call registerurl so the remote is
7270: informed
1.415 albertel 7271: redirect -> array ref of
7272: 1- seconds before redirect occurs
7273: 2- url to redirect to
7274: 3- whether the side effect should occur
1.315 albertel 7275: (side effect of setting
7276: $env{'internal.head.redirect'} to the url
7277: redirected too)
1.352 albertel 7278: domain -> force to color decorate a page for a specific
7279: domain
7280: function -> force usage of a specific rolish color scheme
7281: bgcolor -> override the default page bgcolor
1.460 albertel 7282: no_auto_mt_title
7283: -> prevent &mt()ing the title arg
1.464 albertel 7284:
1.306 albertel 7285: =cut
7286:
7287: sub headtag {
1.313 albertel 7288: my ($title,$head_extra,$args) = @_;
1.306 albertel 7289:
1.363 albertel 7290: my $function = $args->{'function'} || &get_users_function();
7291: my $domain = $args->{'domain'} || &determinedomain();
7292: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7293: my $httphost = $args->{'use_absolute'};
1.418 albertel 7294: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7295: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7296: #time(),
1.418 albertel 7297: $env{'environment.color.timestamp'},
1.363 albertel 7298: $function,$domain,$bgcolor);
7299:
1.369 www 7300: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7301:
1.308 albertel 7302: my $result =
7303: '<head>'.
1.1075.2.56 raeburn 7304: &font_settings($args);
1.319 albertel 7305:
1.1075.2.72 raeburn 7306: my $inhibitprint;
7307: if ($args->{'print_suppress'}) {
7308: $inhibitprint = &print_suppression();
7309: }
1.1064 raeburn 7310:
1.461 albertel 7311: if (!$args->{'frameset'}) {
7312: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7313: }
1.1075.2.12 raeburn 7314: if ($args->{'force_register'}) {
7315: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7316: }
1.436 albertel 7317: if (!$args->{'no_nav_bar'}
7318: && !$args->{'only_body'}
7319: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7320: $result .= &help_menu_js($httphost);
1.1032 www 7321: $result.=&modal_window();
1.1038 www 7322: $result.=&togglebox_script();
1.1034 www 7323: $result.=&wishlist_window();
1.1041 www 7324: $result.=&LCprogressbarUpdate_script();
1.1034 www 7325: } else {
7326: if ($args->{'add_modal'}) {
7327: $result.=&modal_window();
7328: }
7329: if ($args->{'add_wishlist'}) {
7330: $result.=&wishlist_window();
7331: }
1.1038 www 7332: if ($args->{'add_togglebox'}) {
7333: $result.=&togglebox_script();
7334: }
1.1041 www 7335: if ($args->{'add_progressbar'}) {
7336: $result.=&LCprogressbarUpdate_script();
7337: }
1.436 albertel 7338: }
1.314 albertel 7339: if (ref($args->{'redirect'})) {
1.414 albertel 7340: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7341: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7342: if (!$inhibit_continue) {
7343: $env{'internal.head.redirect'} = $url;
7344: }
1.313 albertel 7345: $result.=<<ADDMETA
7346: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7347: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7348: ADDMETA
7349: }
1.306 albertel 7350: if (!defined($title)) {
7351: $title = 'The LearningOnline Network with CAPA';
7352: }
1.460 albertel 7353: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7354: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7355: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7356: if (!$args->{'frameset'}) {
7357: $result .= ' /';
7358: }
7359: $result .= '>'
1.1064 raeburn 7360: .$inhibitprint
1.414 albertel 7361: .$head_extra;
1.1075.2.42 raeburn 7362: if ($env{'browser.mobile'}) {
7363: $result .= '
7364: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7365: <meta name="apple-mobile-web-app-capable" content="yes" />';
7366: }
1.962 droeschl 7367: return $result.'</head>';
1.306 albertel 7368: }
7369:
7370: =pod
7371:
1.340 albertel 7372: =item * &font_settings()
7373:
7374: Returns neccessary <meta> to set the proper encoding
7375:
1.1075.2.56 raeburn 7376: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7377:
7378: =cut
7379:
7380: sub font_settings {
1.1075.2.56 raeburn 7381: my ($args) = @_;
1.340 albertel 7382: my $headerstring='';
1.1075.2.56 raeburn 7383: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7384: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7385: $headerstring.=
1.1075.2.61 raeburn 7386: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7387: if (!$args->{'frameset'}) {
7388: $headerstring.= ' /';
7389: }
7390: $headerstring .= '>'."\n";
1.340 albertel 7391: }
7392: return $headerstring;
7393: }
7394:
1.341 albertel 7395: =pod
7396:
1.1064 raeburn 7397: =item * &print_suppression()
7398:
7399: In course context returns css which causes the body to be blank when media="print",
7400: if printout generation is unavailable for the current resource.
7401:
7402: This could be because:
7403:
7404: (a) printstartdate is in the future
7405:
7406: (b) printenddate is in the past
7407:
7408: (c) there is an active exam block with "printout"
7409: functionality blocked
7410:
7411: Users with pav, pfo or evb privileges are exempt.
7412:
7413: Inputs: none
7414:
7415: =cut
7416:
7417:
7418: sub print_suppression {
7419: my $noprint;
7420: if ($env{'request.course.id'}) {
7421: my $scope = $env{'request.course.id'};
7422: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7423: (&Apache::lonnet::allowed('pfo',$scope))) {
7424: return;
7425: }
7426: if ($env{'request.course.sec'} ne '') {
7427: $scope .= "/$env{'request.course.sec'}";
7428: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7429: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7430: return;
1.1064 raeburn 7431: }
7432: }
7433: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7434: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 7435: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 7436: if ($blocked) {
7437: my $checkrole = "cm./$cdom/$cnum";
7438: if ($env{'request.course.sec'} ne '') {
7439: $checkrole .= "/$env{'request.course.sec'}";
7440: }
7441: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7442: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7443: $noprint = 1;
7444: }
7445: }
7446: unless ($noprint) {
7447: my $symb = &Apache::lonnet::symbread();
7448: if ($symb ne '') {
7449: my $navmap = Apache::lonnavmaps::navmap->new();
7450: if (ref($navmap)) {
7451: my $res = $navmap->getBySymb($symb);
7452: if (ref($res)) {
7453: if (!$res->resprintable()) {
7454: $noprint = 1;
7455: }
7456: }
7457: }
7458: }
7459: }
7460: if ($noprint) {
7461: return <<"ENDSTYLE";
7462: <style type="text/css" media="print">
7463: body { display:none }
7464: </style>
7465: ENDSTYLE
7466: }
7467: }
7468: return;
7469: }
7470:
7471: =pod
7472:
1.341 albertel 7473: =item * &xml_begin()
7474:
7475: Returns the needed doctype and <html>
7476:
7477: Inputs: none
7478:
7479: =cut
7480:
7481: sub xml_begin {
1.1075.2.61 raeburn 7482: my ($is_frameset) = @_;
1.341 albertel 7483: my $output='';
7484:
7485: if ($env{'browser.mathml'}) {
7486: $output='<?xml version="1.0"?>'
7487: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7488: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7489:
7490: # .'<!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">] >'
7491: .'<!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">'
7492: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7493: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 7494: } elsif ($is_frameset) {
7495: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7496: '<html>'."\n";
1.341 albertel 7497: } else {
1.1075.2.61 raeburn 7498: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7499: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7500: }
7501: return $output;
7502: }
1.340 albertel 7503:
7504: =pod
7505:
1.306 albertel 7506: =item * &start_page()
7507:
7508: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7509:
1.648 raeburn 7510: Inputs:
7511:
7512: =over 4
7513:
7514: $title - optional title for the page
7515:
7516: $head_extra - optional extra HTML to incude inside the <head>
7517:
7518: $args - additional optional args supported are:
7519:
7520: =over 8
7521:
7522: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7523: arg on
1.814 bisitz 7524: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7525: add_entries -> additional attributes to add to the <body>
7526: domain -> force to color decorate a page for a
1.317 albertel 7527: specific domain
1.648 raeburn 7528: function -> force usage of a specific rolish color
1.317 albertel 7529: scheme
1.648 raeburn 7530: redirect -> see &headtag()
7531: bgcolor -> override the default page bg color
7532: js_ready -> return a string ready for being used in
1.317 albertel 7533: a javascript writeln
1.648 raeburn 7534: html_encode -> return a string ready for being used in
1.320 albertel 7535: a html attribute
1.648 raeburn 7536: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7537: $forcereg arg
1.648 raeburn 7538: frameset -> if true will start with a <frameset>
1.330 albertel 7539: rather than <body>
1.648 raeburn 7540: skip_phases -> hash ref of
1.338 albertel 7541: head -> skip the <html><head> generation
7542: body -> skip all <body> generation
1.1075.2.12 raeburn 7543: no_inline_link -> if true and in remote mode, don't show the
7544: 'Switch To Inline Menu' link
1.648 raeburn 7545: no_auto_mt_title -> prevent &mt()ing the title arg
7546: inherit_jsmath -> when creating popup window in a page,
7547: should it have jsmath forced on by the
7548: current page
1.867 kalberla 7549: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7550: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.15 raeburn 7551: group -> includes the current group, if page is for a
7552: specific group
1.361 albertel 7553:
1.648 raeburn 7554: =back
1.460 albertel 7555:
1.648 raeburn 7556: =back
1.562 albertel 7557:
1.306 albertel 7558: =cut
7559:
7560: sub start_page {
1.309 albertel 7561: my ($title,$head_extra,$args) = @_;
1.318 albertel 7562: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7563:
1.315 albertel 7564: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 7565: my ($result,@advtools);
1.964 droeschl 7566:
1.338 albertel 7567: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 7568: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 7569: }
7570:
7571: if (! exists($args->{'skip_phases'}{'body'}) ) {
7572: if ($args->{'frameset'}) {
7573: my $attr_string = &make_attr_string($args->{'force_register'},
7574: $args->{'add_entries'});
7575: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7576: } else {
7577: $result .=
7578: &bodytag($title,
7579: $args->{'function'}, $args->{'add_entries'},
7580: $args->{'only_body'}, $args->{'domain'},
7581: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 7582: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 7583: $args, \@advtools);
1.831 bisitz 7584: }
1.330 albertel 7585: }
1.338 albertel 7586:
1.315 albertel 7587: if ($args->{'js_ready'}) {
1.713 kaisler 7588: $result = &js_ready($result);
1.315 albertel 7589: }
1.320 albertel 7590: if ($args->{'html_encode'}) {
1.713 kaisler 7591: $result = &html_encode($result);
7592: }
7593:
1.813 bisitz 7594: # Preparation for new and consistent functionlist at top of screen
7595: # if ($args->{'functionlist'}) {
7596: # $result .= &build_functionlist();
7597: #}
7598:
1.964 droeschl 7599: # Don't add anything more if only_body wanted or in const space
7600: return $result if $args->{'only_body'}
7601: || $env{'request.state'} eq 'construct';
1.813 bisitz 7602:
7603: #Breadcrumbs
1.758 kaisler 7604: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7605: &Apache::lonhtmlcommon::clear_breadcrumbs();
7606: #if any br links exists, add them to the breadcrumbs
7607: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7608: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7609: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7610: }
7611: }
1.1075.2.19 raeburn 7612: # if @advtools array contains items add then to the breadcrumbs
7613: if (@advtools > 0) {
7614: &Apache::lonmenu::advtools_crumbs(@advtools);
7615: }
1.758 kaisler 7616:
7617: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7618: if(exists($args->{'bread_crumbs_component'})){
7619: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7620: }else{
7621: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7622: }
1.1075.2.24 raeburn 7623: } elsif (($env{'environment.remote'} eq 'on') &&
7624: ($env{'form.inhibitmenu'} ne 'yes') &&
7625: ($env{'request.noversionuri'} =~ m{^/res/}) &&
7626: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 7627: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 7628: }
1.315 albertel 7629: return $result;
1.306 albertel 7630: }
7631:
7632: sub end_page {
1.315 albertel 7633: my ($args) = @_;
7634: $env{'internal.end_page'}++;
1.330 albertel 7635: my $result;
1.335 albertel 7636: if ($args->{'discussion'}) {
7637: my ($target,$parser);
7638: if (ref($args->{'discussion'})) {
7639: ($target,$parser) =($args->{'discussion'}{'target'},
7640: $args->{'discussion'}{'parser'});
7641: }
7642: $result .= &Apache::lonxml::xmlend($target,$parser);
7643: }
1.330 albertel 7644: if ($args->{'frameset'}) {
7645: $result .= '</frameset>';
7646: } else {
1.635 raeburn 7647: $result .= &endbodytag($args);
1.330 albertel 7648: }
1.1075.2.6 raeburn 7649: unless ($args->{'notbody'}) {
7650: $result .= "\n</html>";
7651: }
1.330 albertel 7652:
1.315 albertel 7653: if ($args->{'js_ready'}) {
1.317 albertel 7654: $result = &js_ready($result);
1.315 albertel 7655: }
1.335 albertel 7656:
1.320 albertel 7657: if ($args->{'html_encode'}) {
7658: $result = &html_encode($result);
7659: }
1.335 albertel 7660:
1.315 albertel 7661: return $result;
7662: }
7663:
1.1034 www 7664: sub wishlist_window {
7665: return(<<'ENDWISHLIST');
1.1046 raeburn 7666: <script type="text/javascript">
1.1034 www 7667: // <![CDATA[
7668: // <!-- BEGIN LON-CAPA Internal
7669: function set_wishlistlink(title, path) {
7670: if (!title) {
7671: title = document.title;
7672: title = title.replace(/^LON-CAPA /,'');
7673: }
1.1075.2.65 raeburn 7674: title = encodeURIComponent(title);
1.1034 www 7675: if (!path) {
7676: path = location.pathname;
7677: }
1.1075.2.65 raeburn 7678: path = encodeURIComponent(path);
1.1034 www 7679: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7680: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7681: }
7682: // END LON-CAPA Internal -->
7683: // ]]>
7684: </script>
7685: ENDWISHLIST
7686: }
7687:
1.1030 www 7688: sub modal_window {
7689: return(<<'ENDMODAL');
1.1046 raeburn 7690: <script type="text/javascript">
1.1030 www 7691: // <![CDATA[
7692: // <!-- BEGIN LON-CAPA Internal
7693: var modalWindow = {
7694: parent:"body",
7695: windowId:null,
7696: content:null,
7697: width:null,
7698: height:null,
7699: close:function()
7700: {
7701: $(".LCmodal-window").remove();
7702: $(".LCmodal-overlay").remove();
7703: },
7704: open:function()
7705: {
7706: var modal = "";
7707: modal += "<div class=\"LCmodal-overlay\"></div>";
7708: 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;\">";
7709: modal += this.content;
7710: modal += "</div>";
7711:
7712: $(this.parent).append(modal);
7713:
7714: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7715: $(".LCclose-window").click(function(){modalWindow.close();});
7716: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7717: }
7718: };
1.1075.2.42 raeburn 7719: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7720: {
7721: modalWindow.windowId = "myModal";
7722: modalWindow.width = width;
7723: modalWindow.height = height;
1.1075.2.42 raeburn 7724: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7725: modalWindow.open();
7726: };
7727: // END LON-CAPA Internal -->
7728: // ]]>
7729: </script>
7730: ENDMODAL
7731: }
7732:
7733: sub modal_link {
1.1075.2.42 raeburn 7734: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7735: unless ($width) { $width=480; }
7736: unless ($height) { $height=400; }
1.1031 www 7737: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 7738: unless ($transparency) { $transparency='true'; }
7739:
1.1074 raeburn 7740: my $target_attr;
7741: if (defined($target)) {
7742: $target_attr = 'target="'.$target.'"';
7743: }
7744: return <<"ENDLINK";
1.1075.2.42 raeburn 7745: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7746: $linktext</a>
7747: ENDLINK
1.1030 www 7748: }
7749:
1.1032 www 7750: sub modal_adhoc_script {
7751: my ($funcname,$width,$height,$content)=@_;
7752: return (<<ENDADHOC);
1.1046 raeburn 7753: <script type="text/javascript">
1.1032 www 7754: // <![CDATA[
7755: var $funcname = function()
7756: {
7757: modalWindow.windowId = "myModal";
7758: modalWindow.width = $width;
7759: modalWindow.height = $height;
7760: modalWindow.content = '$content';
7761: modalWindow.open();
7762: };
7763: // ]]>
7764: </script>
7765: ENDADHOC
7766: }
7767:
1.1041 www 7768: sub modal_adhoc_inner {
7769: my ($funcname,$width,$height,$content)=@_;
7770: my $innerwidth=$width-20;
7771: $content=&js_ready(
1.1042 www 7772: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 7773: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7774: $content.
1.1041 www 7775: &end_scrollbox().
1.1075.2.42 raeburn 7776: &end_page()
1.1041 www 7777: );
7778: return &modal_adhoc_script($funcname,$width,$height,$content);
7779: }
7780:
7781: sub modal_adhoc_window {
7782: my ($funcname,$width,$height,$content,$linktext)=@_;
7783: return &modal_adhoc_inner($funcname,$width,$height,$content).
7784: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7785: }
7786:
7787: sub modal_adhoc_launch {
7788: my ($funcname,$width,$height,$content)=@_;
7789: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7790: <script type="text/javascript">
7791: // <![CDATA[
7792: $funcname();
7793: // ]]>
7794: </script>
7795: ENDLAUNCH
7796: }
7797:
7798: sub modal_adhoc_close {
7799: return (<<ENDCLOSE);
7800: <script type="text/javascript">
7801: // <![CDATA[
7802: modalWindow.close();
7803: // ]]>
7804: </script>
7805: ENDCLOSE
7806: }
7807:
1.1038 www 7808: sub togglebox_script {
7809: return(<<ENDTOGGLE);
7810: <script type="text/javascript">
7811: // <![CDATA[
7812: function LCtoggleDisplay(id,hidetext,showtext) {
7813: link = document.getElementById(id + "link").childNodes[0];
7814: with (document.getElementById(id).style) {
7815: if (display == "none" ) {
7816: display = "inline";
7817: link.nodeValue = hidetext;
7818: } else {
7819: display = "none";
7820: link.nodeValue = showtext;
7821: }
7822: }
7823: }
7824: // ]]>
7825: </script>
7826: ENDTOGGLE
7827: }
7828:
1.1039 www 7829: sub start_togglebox {
7830: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7831: unless ($heading) { $heading=''; } else { $heading.=' '; }
7832: unless ($showtext) { $showtext=&mt('show'); }
7833: unless ($hidetext) { $hidetext=&mt('hide'); }
7834: unless ($headerbg) { $headerbg='#FFFFFF'; }
7835: return &start_data_table().
7836: &start_data_table_header_row().
7837: '<td bgcolor="'.$headerbg.'">'.$heading.
7838: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7839: $showtext.'\')">'.$showtext.'</a>]</td>'.
7840: &end_data_table_header_row().
7841: '<tr id="'.$id.'" style="display:none""><td>';
7842: }
7843:
7844: sub end_togglebox {
7845: return '</td></tr>'.&end_data_table();
7846: }
7847:
1.1041 www 7848: sub LCprogressbar_script {
1.1045 www 7849: my ($id)=@_;
1.1041 www 7850: return(<<ENDPROGRESS);
7851: <script type="text/javascript">
7852: // <![CDATA[
1.1045 www 7853: \$('#progressbar$id').progressbar({
1.1041 www 7854: value: 0,
7855: change: function(event, ui) {
7856: var newVal = \$(this).progressbar('option', 'value');
7857: \$('.pblabel', this).text(LCprogressTxt);
7858: }
7859: });
7860: // ]]>
7861: </script>
7862: ENDPROGRESS
7863: }
7864:
7865: sub LCprogressbarUpdate_script {
7866: return(<<ENDPROGRESSUPDATE);
7867: <style type="text/css">
7868: .ui-progressbar { position:relative; }
7869: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7870: </style>
7871: <script type="text/javascript">
7872: // <![CDATA[
1.1045 www 7873: var LCprogressTxt='---';
7874:
7875: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7876: LCprogressTxt=progresstext;
1.1045 www 7877: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7878: }
7879: // ]]>
7880: </script>
7881: ENDPROGRESSUPDATE
7882: }
7883:
1.1042 www 7884: my $LClastpercent;
1.1045 www 7885: my $LCidcnt;
7886: my $LCcurrentid;
1.1042 www 7887:
1.1041 www 7888: sub LCprogressbar {
1.1042 www 7889: my ($r)=(@_);
7890: $LClastpercent=0;
1.1045 www 7891: $LCidcnt++;
7892: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7893: my $starting=&mt('Starting');
7894: my $content=(<<ENDPROGBAR);
1.1045 www 7895: <div id="progressbar$LCcurrentid">
1.1041 www 7896: <span class="pblabel">$starting</span>
7897: </div>
7898: ENDPROGBAR
1.1045 www 7899: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7900: }
7901:
7902: sub LCprogressbarUpdate {
1.1042 www 7903: my ($r,$val,$text)=@_;
7904: unless ($val) {
7905: if ($LClastpercent) {
7906: $val=$LClastpercent;
7907: } else {
7908: $val=0;
7909: }
7910: }
1.1041 www 7911: if ($val<0) { $val=0; }
7912: if ($val>100) { $val=0; }
1.1042 www 7913: $LClastpercent=$val;
1.1041 www 7914: unless ($text) { $text=$val.'%'; }
7915: $text=&js_ready($text);
1.1044 www 7916: &r_print($r,<<ENDUPDATE);
1.1041 www 7917: <script type="text/javascript">
7918: // <![CDATA[
1.1045 www 7919: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7920: // ]]>
7921: </script>
7922: ENDUPDATE
1.1035 www 7923: }
7924:
1.1042 www 7925: sub LCprogressbarClose {
7926: my ($r)=@_;
7927: $LClastpercent=0;
1.1044 www 7928: &r_print($r,<<ENDCLOSE);
1.1042 www 7929: <script type="text/javascript">
7930: // <![CDATA[
1.1045 www 7931: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7932: // ]]>
7933: </script>
7934: ENDCLOSE
1.1044 www 7935: }
7936:
7937: sub r_print {
7938: my ($r,$to_print)=@_;
7939: if ($r) {
7940: $r->print($to_print);
7941: $r->rflush();
7942: } else {
7943: print($to_print);
7944: }
1.1042 www 7945: }
7946:
1.320 albertel 7947: sub html_encode {
7948: my ($result) = @_;
7949:
1.322 albertel 7950: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7951:
7952: return $result;
7953: }
1.1044 www 7954:
1.317 albertel 7955: sub js_ready {
7956: my ($result) = @_;
7957:
1.323 albertel 7958: $result =~ s/[\n\r]/ /xmsg;
7959: $result =~ s/\\/\\\\/xmsg;
7960: $result =~ s/'/\\'/xmsg;
1.372 albertel 7961: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7962:
7963: return $result;
7964: }
7965:
1.315 albertel 7966: sub validate_page {
7967: if ( exists($env{'internal.start_page'})
1.316 albertel 7968: && $env{'internal.start_page'} > 1) {
7969: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7970: $env{'internal.start_page'}.' '.
1.316 albertel 7971: $ENV{'request.filename'});
1.315 albertel 7972: }
7973: if ( exists($env{'internal.end_page'})
1.316 albertel 7974: && $env{'internal.end_page'} > 1) {
7975: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7976: $env{'internal.end_page'}.' '.
1.316 albertel 7977: $env{'request.filename'});
1.315 albertel 7978: }
7979: if ( exists($env{'internal.start_page'})
7980: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7981: &Apache::lonnet::logthis('start_page called without end_page '.
7982: $env{'request.filename'});
1.315 albertel 7983: }
7984: if ( ! exists($env{'internal.start_page'})
7985: && exists($env{'internal.end_page'})) {
1.316 albertel 7986: &Apache::lonnet::logthis('end_page called without start_page'.
7987: $env{'request.filename'});
1.315 albertel 7988: }
1.306 albertel 7989: }
1.315 albertel 7990:
1.996 www 7991:
7992: sub start_scrollbox {
1.1075.2.56 raeburn 7993: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 7994: unless ($outerwidth) { $outerwidth='520px'; }
7995: unless ($width) { $width='500px'; }
7996: unless ($height) { $height='200px'; }
1.1075 raeburn 7997: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7998: if ($id ne '') {
1.1075.2.42 raeburn 7999: $table_id = ' id="table_'.$id.'"';
8000: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8001: }
1.1075 raeburn 8002: if ($bgcolor ne '') {
8003: $tdcol = "background-color: $bgcolor;";
8004: }
1.1075.2.42 raeburn 8005: my $nicescroll_js;
8006: if ($env{'browser.mobile'}) {
8007: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8008: }
1.1075 raeburn 8009: return <<"END";
1.1075.2.42 raeburn 8010: $nicescroll_js
8011:
8012: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8013: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8014: END
1.996 www 8015: }
8016:
8017: sub end_scrollbox {
1.1036 www 8018: return '</div></td></tr></table>';
1.996 www 8019: }
8020:
1.1075.2.42 raeburn 8021: sub nicescroll_javascript {
8022: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8023: my %options;
8024: if (ref($cursor) eq 'HASH') {
8025: %options = %{$cursor};
8026: }
8027: unless ($options{'railalign'} =~ /^left|right$/) {
8028: $options{'railalign'} = 'left';
8029: }
8030: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8031: my $function = &get_users_function();
8032: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8033: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8034: $options{'cursorcolor'} = '#00F';
8035: }
8036: }
8037: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8038: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8039: $options{'cursoropacity'}='1.0';
8040: }
8041: } else {
8042: $options{'cursoropacity'}='1.0';
8043: }
8044: if ($options{'cursorfixedheight'} eq 'none') {
8045: delete($options{'cursorfixedheight'});
8046: } else {
8047: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8048: }
8049: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8050: delete($options{'railoffset'});
8051: }
8052: my @niceoptions;
8053: while (my($key,$value) = each(%options)) {
8054: if ($value =~ /^\{.+\}$/) {
8055: push(@niceoptions,$key.':'.$value);
8056: } else {
8057: push(@niceoptions,$key.':"'.$value.'"');
8058: }
8059: }
8060: my $nicescroll_js = '
8061: $(document).ready(
8062: function() {
8063: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8064: }
8065: );
8066: ';
8067: if ($framecheck) {
8068: $nicescroll_js .= '
8069: function expand_div(caller) {
8070: if (top === self) {
8071: document.getElementById("'.$id.'").style.width = "auto";
8072: document.getElementById("'.$id.'").style.height = "auto";
8073: } else {
8074: try {
8075: if (parent.frames) {
8076: if (parent.frames.length > 1) {
8077: var framesrc = parent.frames[1].location.href;
8078: var currsrc = framesrc.replace(/\#.*$/,"");
8079: if ((caller == "search") || (currsrc == "'.$location.'")) {
8080: document.getElementById("'.$id.'").style.width = "auto";
8081: document.getElementById("'.$id.'").style.height = "auto";
8082: }
8083: }
8084: }
8085: } catch (e) {
8086: return;
8087: }
8088: }
8089: return;
8090: }
8091: ';
8092: }
8093: if ($needjsready) {
8094: $nicescroll_js = '
8095: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8096: } else {
8097: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8098: }
8099: return $nicescroll_js;
8100: }
8101:
1.318 albertel 8102: sub simple_error_page {
1.1075.2.49 raeburn 8103: my ($r,$title,$msg,$args) = @_;
8104: if (ref($args) eq 'HASH') {
8105: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8106: } else {
8107: $msg = &mt($msg);
8108: }
8109:
1.318 albertel 8110: my $page =
8111: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8112: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8113: &Apache::loncommon::end_page();
8114: if (ref($r)) {
8115: $r->print($page);
1.327 albertel 8116: return;
1.318 albertel 8117: }
8118: return $page;
8119: }
1.347 albertel 8120:
8121: {
1.610 albertel 8122: my @row_count;
1.961 onken 8123:
8124: sub start_data_table_count {
8125: unshift(@row_count, 0);
8126: return;
8127: }
8128:
8129: sub end_data_table_count {
8130: shift(@row_count);
8131: return;
8132: }
8133:
1.347 albertel 8134: sub start_data_table {
1.1018 raeburn 8135: my ($add_class,$id) = @_;
1.422 albertel 8136: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8137: my $table_id;
8138: if (defined($id)) {
8139: $table_id = ' id="'.$id.'"';
8140: }
1.961 onken 8141: &start_data_table_count();
1.1018 raeburn 8142: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8143: }
8144:
8145: sub end_data_table {
1.961 onken 8146: &end_data_table_count();
1.389 albertel 8147: return '</table>'."\n";;
1.347 albertel 8148: }
8149:
8150: sub start_data_table_row {
1.974 wenzelju 8151: my ($add_class, $id) = @_;
1.610 albertel 8152: $row_count[0]++;
8153: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8154: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8155: $id = (' id="'.$id.'"') unless ($id eq '');
8156: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8157: }
1.471 banghart 8158:
8159: sub continue_data_table_row {
1.974 wenzelju 8160: my ($add_class, $id) = @_;
1.610 albertel 8161: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8162: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8163: $id = (' id="'.$id.'"') unless ($id eq '');
8164: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8165: }
1.347 albertel 8166:
8167: sub end_data_table_row {
1.389 albertel 8168: return '</tr>'."\n";;
1.347 albertel 8169: }
1.367 www 8170:
1.421 albertel 8171: sub start_data_table_empty_row {
1.707 bisitz 8172: # $row_count[0]++;
1.421 albertel 8173: return '<tr class="LC_empty_row" >'."\n";;
8174: }
8175:
8176: sub end_data_table_empty_row {
8177: return '</tr>'."\n";;
8178: }
8179:
1.367 www 8180: sub start_data_table_header_row {
1.389 albertel 8181: return '<tr class="LC_header_row">'."\n";;
1.367 www 8182: }
8183:
8184: sub end_data_table_header_row {
1.389 albertel 8185: return '</tr>'."\n";;
1.367 www 8186: }
1.890 droeschl 8187:
8188: sub data_table_caption {
8189: my $caption = shift;
8190: return "<caption class=\"LC_caption\">$caption</caption>";
8191: }
1.347 albertel 8192: }
8193:
1.548 albertel 8194: =pod
8195:
8196: =item * &inhibit_menu_check($arg)
8197:
8198: Checks for a inhibitmenu state and generates output to preserve it
8199:
8200: Inputs: $arg - can be any of
8201: - undef - in which case the return value is a string
8202: to add into arguments list of a uri
8203: - 'input' - in which case the return value is a HTML
8204: <form> <input> field of type hidden to
8205: preserve the value
8206: - a url - in which case the return value is the url with
8207: the neccesary cgi args added to preserve the
8208: inhibitmenu state
8209: - a ref to a url - no return value, but the string is
8210: updated to include the neccessary cgi
8211: args to preserve the inhibitmenu state
8212:
8213: =cut
8214:
8215: sub inhibit_menu_check {
8216: my ($arg) = @_;
8217: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8218: if ($arg eq 'input') {
8219: if ($env{'form.inhibitmenu'}) {
8220: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8221: } else {
8222: return
8223: }
8224: }
8225: if ($env{'form.inhibitmenu'}) {
8226: if (ref($arg)) {
8227: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8228: } elsif ($arg eq '') {
8229: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8230: } else {
8231: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8232: }
8233: }
8234: if (!ref($arg)) {
8235: return $arg;
8236: }
8237: }
8238:
1.251 albertel 8239: ###############################################
1.182 matthew 8240:
8241: =pod
8242:
1.549 albertel 8243: =back
8244:
8245: =head1 User Information Routines
8246:
8247: =over 4
8248:
1.405 albertel 8249: =item * &get_users_function()
1.182 matthew 8250:
8251: Used by &bodytag to determine the current users primary role.
8252: Returns either 'student','coordinator','admin', or 'author'.
8253:
8254: =cut
8255:
8256: ###############################################
8257: sub get_users_function {
1.815 tempelho 8258: my $function = 'norole';
1.818 tempelho 8259: if ($env{'request.role'}=~/^(st)/) {
8260: $function='student';
8261: }
1.907 raeburn 8262: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8263: $function='coordinator';
8264: }
1.258 albertel 8265: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8266: $function='admin';
8267: }
1.826 bisitz 8268: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8269: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8270: $function='author';
8271: }
8272: return $function;
1.54 www 8273: }
1.99 www 8274:
8275: ###############################################
8276:
1.233 raeburn 8277: =pod
8278:
1.821 raeburn 8279: =item * &show_course()
8280:
8281: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8282: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8283:
8284: Inputs:
8285: None
8286:
8287: Outputs:
8288: Scalar: 1 if 'Course' to be used, 0 otherwise.
8289:
8290: =cut
8291:
8292: ###############################################
8293: sub show_course {
8294: my $course = !$env{'user.adv'};
8295: if (!$env{'user.adv'}) {
8296: foreach my $env (keys(%env)) {
8297: next if ($env !~ m/^user\.priv\./);
8298: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8299: $course = 0;
8300: last;
8301: }
8302: }
8303: }
8304: return $course;
8305: }
8306:
8307: ###############################################
8308:
8309: =pod
8310:
1.542 raeburn 8311: =item * &check_user_status()
1.274 raeburn 8312:
8313: Determines current status of supplied role for a
8314: specific user. Roles can be active, previous or future.
8315:
8316: Inputs:
8317: user's domain, user's username, course's domain,
1.375 raeburn 8318: course's number, optional section ID.
1.274 raeburn 8319:
8320: Outputs:
8321: role status: active, previous or future.
8322:
8323: =cut
8324:
8325: sub check_user_status {
1.412 raeburn 8326: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8327: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8328: my @uroles = keys %userinfo;
8329: my $srchstr;
8330: my $active_chk = 'none';
1.412 raeburn 8331: my $now = time;
1.274 raeburn 8332: if (@uroles > 0) {
1.908 raeburn 8333: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8334: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8335: } else {
1.412 raeburn 8336: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8337: }
8338: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8339: my $role_end = 0;
8340: my $role_start = 0;
8341: $active_chk = 'active';
1.412 raeburn 8342: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8343: $role_end = $1;
8344: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8345: $role_start = $1;
1.274 raeburn 8346: }
8347: }
8348: if ($role_start > 0) {
1.412 raeburn 8349: if ($now < $role_start) {
1.274 raeburn 8350: $active_chk = 'future';
8351: }
8352: }
8353: if ($role_end > 0) {
1.412 raeburn 8354: if ($now > $role_end) {
1.274 raeburn 8355: $active_chk = 'previous';
8356: }
8357: }
8358: }
8359: }
8360: return $active_chk;
8361: }
8362:
8363: ###############################################
8364:
8365: =pod
8366:
1.405 albertel 8367: =item * &get_sections()
1.233 raeburn 8368:
8369: Determines all the sections for a course including
8370: sections with students and sections containing other roles.
1.419 raeburn 8371: Incoming parameters:
8372:
8373: 1. domain
8374: 2. course number
8375: 3. reference to array containing roles for which sections should
8376: be gathered (optional).
8377: 4. reference to array containing status types for which sections
8378: should be gathered (optional).
8379:
8380: If the third argument is undefined, sections are gathered for any role.
8381: If the fourth argument is undefined, sections are gathered for any status.
8382: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8383:
1.374 raeburn 8384: Returns section hash (keys are section IDs, values are
8385: number of users in each section), subject to the
1.419 raeburn 8386: optional roles filter, optional status filter
1.233 raeburn 8387:
8388: =cut
8389:
8390: ###############################################
8391: sub get_sections {
1.419 raeburn 8392: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8393: if (!defined($cdom) || !defined($cnum)) {
8394: my $cid = $env{'request.course.id'};
8395:
8396: return if (!defined($cid));
8397:
8398: $cdom = $env{'course.'.$cid.'.domain'};
8399: $cnum = $env{'course.'.$cid.'.num'};
8400: }
8401:
8402: my %sectioncount;
1.419 raeburn 8403: my $now = time;
1.240 albertel 8404:
1.1075.2.33 raeburn 8405: my $check_students = 1;
8406: my $only_students = 0;
8407: if (ref($possible_roles) eq 'ARRAY') {
8408: if (grep(/^st$/,@{$possible_roles})) {
8409: if (@{$possible_roles} == 1) {
8410: $only_students = 1;
8411: }
8412: } else {
8413: $check_students = 0;
8414: }
8415: }
8416:
8417: if ($check_students) {
1.276 albertel 8418: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8419: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8420: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8421: my $start_index = &Apache::loncoursedata::CL_START();
8422: my $end_index = &Apache::loncoursedata::CL_END();
8423: my $status;
1.366 albertel 8424: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8425: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8426: $data->[$status_index],
8427: $data->[$start_index],
8428: $data->[$end_index]);
8429: if ($stu_status eq 'Active') {
8430: $status = 'active';
8431: } elsif ($end < $now) {
8432: $status = 'previous';
8433: } elsif ($start > $now) {
8434: $status = 'future';
8435: }
8436: if ($section ne '-1' && $section !~ /^\s*$/) {
8437: if ((!defined($possible_status)) || (($status ne '') &&
8438: (grep/^\Q$status\E$/,@{$possible_status}))) {
8439: $sectioncount{$section}++;
8440: }
1.240 albertel 8441: }
8442: }
8443: }
1.1075.2.33 raeburn 8444: if ($only_students) {
8445: return %sectioncount;
8446: }
1.240 albertel 8447: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8448: foreach my $user (sort(keys(%courseroles))) {
8449: if ($user !~ /^(\w{2})/) { next; }
8450: my ($role) = ($user =~ /^(\w{2})/);
8451: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8452: my ($section,$status);
1.240 albertel 8453: if ($role eq 'cr' &&
8454: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8455: $section=$1;
8456: }
8457: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8458: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8459: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8460: if ($end == -1 && $start == -1) {
8461: next; #deleted role
8462: }
8463: if (!defined($possible_status)) {
8464: $sectioncount{$section}++;
8465: } else {
8466: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8467: $status = 'active';
8468: } elsif ($end < $now) {
8469: $status = 'future';
8470: } elsif ($start > $now) {
8471: $status = 'previous';
8472: }
8473: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8474: $sectioncount{$section}++;
8475: }
8476: }
1.233 raeburn 8477: }
1.366 albertel 8478: return %sectioncount;
1.233 raeburn 8479: }
8480:
1.274 raeburn 8481: ###############################################
1.294 raeburn 8482:
8483: =pod
1.405 albertel 8484:
8485: =item * &get_course_users()
8486:
1.275 raeburn 8487: Retrieves usernames:domains for users in the specified course
8488: with specific role(s), and access status.
8489:
8490: Incoming parameters:
1.277 albertel 8491: 1. course domain
8492: 2. course number
8493: 3. access status: users must have - either active,
1.275 raeburn 8494: previous, future, or all.
1.277 albertel 8495: 4. reference to array of permissible roles
1.288 raeburn 8496: 5. reference to array of section restrictions (optional)
8497: 6. reference to results object (hash of hashes).
8498: 7. reference to optional userdata hash
1.609 raeburn 8499: 8. reference to optional statushash
1.630 raeburn 8500: 9. flag if privileged users (except those set to unhide in
8501: course settings) should be excluded
1.609 raeburn 8502: Keys of top level results hash are roles.
1.275 raeburn 8503: Keys of inner hashes are username:domain, with
8504: values set to access type.
1.288 raeburn 8505: Optional userdata hash returns an array with arguments in the
8506: same order as loncoursedata::get_classlist() for student data.
8507:
1.609 raeburn 8508: Optional statushash returns
8509:
1.288 raeburn 8510: Entries for end, start, section and status are blank because
8511: of the possibility of multiple values for non-student roles.
8512:
1.275 raeburn 8513: =cut
1.405 albertel 8514:
1.275 raeburn 8515: ###############################################
1.405 albertel 8516:
1.275 raeburn 8517: sub get_course_users {
1.630 raeburn 8518: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8519: my %idx = ();
1.419 raeburn 8520: my %seclists;
1.288 raeburn 8521:
8522: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8523: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8524: $idx{end} = &Apache::loncoursedata::CL_END();
8525: $idx{start} = &Apache::loncoursedata::CL_START();
8526: $idx{id} = &Apache::loncoursedata::CL_ID();
8527: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8528: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8529: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8530:
1.290 albertel 8531: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8532: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8533: my $now = time;
1.277 albertel 8534: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8535: my $match = 0;
1.412 raeburn 8536: my $secmatch = 0;
1.419 raeburn 8537: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8538: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8539: if ($section eq '') {
8540: $section = 'none';
8541: }
1.291 albertel 8542: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8543: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8544: $secmatch = 1;
8545: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8546: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8547: $secmatch = 1;
8548: }
8549: } else {
1.419 raeburn 8550: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8551: $secmatch = 1;
8552: }
1.290 albertel 8553: }
1.412 raeburn 8554: if (!$secmatch) {
8555: next;
8556: }
1.419 raeburn 8557: }
1.275 raeburn 8558: if (defined($$types{'active'})) {
1.288 raeburn 8559: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8560: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8561: $match = 1;
1.275 raeburn 8562: }
8563: }
8564: if (defined($$types{'previous'})) {
1.609 raeburn 8565: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8566: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8567: $match = 1;
1.275 raeburn 8568: }
8569: }
8570: if (defined($$types{'future'})) {
1.609 raeburn 8571: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8572: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8573: $match = 1;
1.275 raeburn 8574: }
8575: }
1.609 raeburn 8576: if ($match) {
8577: push(@{$seclists{$student}},$section);
8578: if (ref($userdata) eq 'HASH') {
8579: $$userdata{$student} = $$classlist{$student};
8580: }
8581: if (ref($statushash) eq 'HASH') {
8582: $statushash->{$student}{'st'}{$section} = $status;
8583: }
1.288 raeburn 8584: }
1.275 raeburn 8585: }
8586: }
1.412 raeburn 8587: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8588: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8589: my $now = time;
1.609 raeburn 8590: my %displaystatus = ( previous => 'Expired',
8591: active => 'Active',
8592: future => 'Future',
8593: );
1.1075.2.36 raeburn 8594: my (%nothide,@possdoms);
1.630 raeburn 8595: if ($hidepriv) {
8596: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8597: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8598: if ($user !~ /:/) {
8599: $nothide{join(':',split(/[\@]/,$user))}=1;
8600: } else {
8601: $nothide{$user} = 1;
8602: }
8603: }
1.1075.2.36 raeburn 8604: my @possdoms = ($cdom);
8605: if ($coursehash{'checkforpriv'}) {
8606: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8607: }
1.630 raeburn 8608: }
1.439 raeburn 8609: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8610: my $match = 0;
1.412 raeburn 8611: my $secmatch = 0;
1.439 raeburn 8612: my $status;
1.412 raeburn 8613: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8614: $user =~ s/:$//;
1.439 raeburn 8615: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8616: if ($end == -1 || $start == -1) {
8617: next;
8618: }
8619: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8620: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8621: my ($uname,$udom) = split(/:/,$user);
8622: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8623: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8624: $secmatch = 1;
8625: } elsif ($usec eq '') {
1.420 albertel 8626: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8627: $secmatch = 1;
8628: }
8629: } else {
8630: if (grep(/^\Q$usec\E$/,@{$sections})) {
8631: $secmatch = 1;
8632: }
8633: }
8634: if (!$secmatch) {
8635: next;
8636: }
1.288 raeburn 8637: }
1.419 raeburn 8638: if ($usec eq '') {
8639: $usec = 'none';
8640: }
1.275 raeburn 8641: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8642: if ($hidepriv) {
1.1075.2.36 raeburn 8643: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8644: (!$nothide{$uname.':'.$udom})) {
8645: next;
8646: }
8647: }
1.503 raeburn 8648: if ($end > 0 && $end < $now) {
1.439 raeburn 8649: $status = 'previous';
8650: } elsif ($start > $now) {
8651: $status = 'future';
8652: } else {
8653: $status = 'active';
8654: }
1.277 albertel 8655: foreach my $type (keys(%{$types})) {
1.275 raeburn 8656: if ($status eq $type) {
1.420 albertel 8657: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8658: push(@{$$users{$role}{$user}},$type);
8659: }
1.288 raeburn 8660: $match = 1;
8661: }
8662: }
1.419 raeburn 8663: if (($match) && (ref($userdata) eq 'HASH')) {
8664: if (!exists($$userdata{$uname.':'.$udom})) {
8665: &get_user_info($udom,$uname,\%idx,$userdata);
8666: }
1.420 albertel 8667: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8668: push(@{$seclists{$uname.':'.$udom}},$usec);
8669: }
1.609 raeburn 8670: if (ref($statushash) eq 'HASH') {
8671: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8672: }
1.275 raeburn 8673: }
8674: }
8675: }
8676: }
1.290 albertel 8677: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8678: if ((defined($cdom)) && (defined($cnum))) {
8679: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8680: if ( defined($csettings{'internal.courseowner'}) ) {
8681: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8682: next if ($owner eq '');
8683: my ($ownername,$ownerdom);
8684: if ($owner =~ /^([^:]+):([^:]+)$/) {
8685: $ownername = $1;
8686: $ownerdom = $2;
8687: } else {
8688: $ownername = $owner;
8689: $ownerdom = $cdom;
8690: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8691: }
8692: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8693: if (defined($userdata) &&
1.609 raeburn 8694: !exists($$userdata{$owner})) {
8695: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8696: if (!grep(/^none$/,@{$seclists{$owner}})) {
8697: push(@{$seclists{$owner}},'none');
8698: }
8699: if (ref($statushash) eq 'HASH') {
8700: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8701: }
1.290 albertel 8702: }
1.279 raeburn 8703: }
8704: }
8705: }
1.419 raeburn 8706: foreach my $user (keys(%seclists)) {
8707: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8708: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8709: }
1.275 raeburn 8710: }
8711: return;
8712: }
8713:
1.288 raeburn 8714: sub get_user_info {
8715: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8716: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8717: &plainname($uname,$udom,'lastname');
1.291 albertel 8718: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8719: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8720: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8721: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8722: return;
8723: }
1.275 raeburn 8724:
1.472 raeburn 8725: ###############################################
8726:
8727: =pod
8728:
8729: =item * &get_user_quota()
8730:
1.1075.2.41 raeburn 8731: Retrieves quota assigned for storage of user files.
8732: Default is to report quota for portfolio files.
1.472 raeburn 8733:
8734: Incoming parameters:
8735: 1. user's username
8736: 2. user's domain
1.1075.2.41 raeburn 8737: 3. quota name - portfolio, author, or course
8738: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 8739: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 8740: course
1.472 raeburn 8741:
8742: Returns:
1.1075.2.58 raeburn 8743: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 8744: 2. (Optional) Type of setting: custom or default
8745: (individually assigned or default for user's
8746: institutional status).
8747: 3. (Optional) - User's institutional status (e.g., faculty, staff
8748: or student - types as defined in localenroll::inst_usertypes
8749: for user's domain, which determines default quota for user.
8750: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8751:
8752: If a value has been stored in the user's environment,
1.536 raeburn 8753: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 8754: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8755:
8756: =cut
8757:
8758: ###############################################
8759:
8760:
8761: sub get_user_quota {
1.1075.2.42 raeburn 8762: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8763: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8764: if (!defined($udom)) {
8765: $udom = $env{'user.domain'};
8766: }
8767: if (!defined($uname)) {
8768: $uname = $env{'user.name'};
8769: }
8770: if (($udom eq '' || $uname eq '') ||
8771: ($udom eq 'public') && ($uname eq 'public')) {
8772: $quota = 0;
1.536 raeburn 8773: $quotatype = 'default';
8774: $defquota = 0;
1.472 raeburn 8775: } else {
1.536 raeburn 8776: my $inststatus;
1.1075.2.41 raeburn 8777: if ($quotaname eq 'course') {
8778: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8779: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8780: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8781: } else {
8782: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8783: $quota = $cenv{'internal.uploadquota'};
8784: }
1.536 raeburn 8785: } else {
1.1075.2.41 raeburn 8786: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8787: if ($quotaname eq 'author') {
8788: $quota = $env{'environment.authorquota'};
8789: } else {
8790: $quota = $env{'environment.portfolioquota'};
8791: }
8792: $inststatus = $env{'environment.inststatus'};
8793: } else {
8794: my %userenv =
8795: &Apache::lonnet::get('environment',['portfolioquota',
8796: 'authorquota','inststatus'],$udom,$uname);
8797: my ($tmp) = keys(%userenv);
8798: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8799: if ($quotaname eq 'author') {
8800: $quota = $userenv{'authorquota'};
8801: } else {
8802: $quota = $userenv{'portfolioquota'};
8803: }
8804: $inststatus = $userenv{'inststatus'};
8805: } else {
8806: undef(%userenv);
8807: }
8808: }
8809: }
8810: if ($quota eq '' || wantarray) {
8811: if ($quotaname eq 'course') {
8812: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 8813: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
8814: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 8815: $defquota = $domdefs{$crstype.'quota'};
8816: }
8817: if ($defquota eq '') {
8818: $defquota = 500;
8819: }
1.1075.2.41 raeburn 8820: } else {
8821: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8822: }
8823: if ($quota eq '') {
8824: $quota = $defquota;
8825: $quotatype = 'default';
8826: } else {
8827: $quotatype = 'custom';
8828: }
1.472 raeburn 8829: }
8830: }
1.536 raeburn 8831: if (wantarray) {
8832: return ($quota,$quotatype,$settingstatus,$defquota);
8833: } else {
8834: return $quota;
8835: }
1.472 raeburn 8836: }
8837:
8838: ###############################################
8839:
8840: =pod
8841:
8842: =item * &default_quota()
8843:
1.536 raeburn 8844: Retrieves default quota assigned for storage of user portfolio files,
8845: given an (optional) user's institutional status.
1.472 raeburn 8846:
8847: Incoming parameters:
1.1075.2.42 raeburn 8848:
1.472 raeburn 8849: 1. domain
1.536 raeburn 8850: 2. (Optional) institutional status(es). This is a : separated list of
8851: status types (e.g., faculty, staff, student etc.)
8852: which apply to the user for whom the default is being retrieved.
8853: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 8854: default quota will be returned.
8855: 3. quota name - portfolio, author, or course
8856: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8857:
8858: Returns:
1.1075.2.42 raeburn 8859:
1.1075.2.58 raeburn 8860: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 8861: 2. (Optional) institutional type which determined the value of the
8862: default quota.
1.472 raeburn 8863:
8864: If a value has been stored in the domain's configuration db,
8865: it will return that, otherwise it returns 20 (for backwards
8866: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 8867: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 8868:
1.536 raeburn 8869: If the user's status includes multiple types (e.g., staff and student),
8870: the largest default quota which applies to the user determines the
8871: default quota returned.
8872:
1.472 raeburn 8873: =cut
8874:
8875: ###############################################
8876:
8877:
8878: sub default_quota {
1.1075.2.41 raeburn 8879: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8880: my ($defquota,$settingstatus);
8881: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8882: ['quotas'],$udom);
1.1075.2.41 raeburn 8883: my $key = 'defaultquota';
8884: if ($quotaname eq 'author') {
8885: $key = 'authorquota';
8886: }
1.622 raeburn 8887: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8888: if ($inststatus ne '') {
1.765 raeburn 8889: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8890: foreach my $item (@statuses) {
1.1075.2.41 raeburn 8891: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8892: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8893: if ($defquota eq '') {
1.1075.2.41 raeburn 8894: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8895: $settingstatus = $item;
1.1075.2.41 raeburn 8896: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8897: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8898: $settingstatus = $item;
8899: }
8900: }
1.1075.2.41 raeburn 8901: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8902: if ($quotahash{'quotas'}{$item} ne '') {
8903: if ($defquota eq '') {
8904: $defquota = $quotahash{'quotas'}{$item};
8905: $settingstatus = $item;
8906: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8907: $defquota = $quotahash{'quotas'}{$item};
8908: $settingstatus = $item;
8909: }
1.536 raeburn 8910: }
8911: }
8912: }
8913: }
8914: if ($defquota eq '') {
1.1075.2.41 raeburn 8915: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8916: $defquota = $quotahash{'quotas'}{$key}{'default'};
8917: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8918: $defquota = $quotahash{'quotas'}{'default'};
8919: }
1.536 raeburn 8920: $settingstatus = 'default';
1.1075.2.42 raeburn 8921: if ($defquota eq '') {
8922: if ($quotaname eq 'author') {
8923: $defquota = 500;
8924: }
8925: }
1.536 raeburn 8926: }
8927: } else {
8928: $settingstatus = 'default';
1.1075.2.41 raeburn 8929: if ($quotaname eq 'author') {
8930: $defquota = 500;
8931: } else {
8932: $defquota = 20;
8933: }
1.536 raeburn 8934: }
8935: if (wantarray) {
8936: return ($defquota,$settingstatus);
1.472 raeburn 8937: } else {
1.536 raeburn 8938: return $defquota;
1.472 raeburn 8939: }
8940: }
8941:
1.1075.2.41 raeburn 8942: ###############################################
8943:
8944: =pod
8945:
1.1075.2.42 raeburn 8946: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 8947:
8948: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 8949: of existing file within authoring space will cause quota for the authoring
8950: space to be exceeded.
8951:
8952: Same, if upload of a file directly to a course/community via Course Editor
8953: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 8954:
1.1075.2.61 raeburn 8955: Inputs: 7
1.1075.2.42 raeburn 8956: 1. username or coursenum
1.1075.2.41 raeburn 8957: 2. domain
1.1075.2.42 raeburn 8958: 3. context ('author' or 'course')
1.1075.2.41 raeburn 8959: 4. filename of file for which action is being requested
8960: 5. filesize (kB) of file
8961: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 8962: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 8963:
8964: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
8965: otherwise return null.
8966:
1.1075.2.42 raeburn 8967: =back
8968:
1.1075.2.41 raeburn 8969: =cut
8970:
1.1075.2.42 raeburn 8971: sub excess_filesize_warning {
1.1075.2.59 raeburn 8972: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 8973: my $current_disk_usage = 0;
1.1075.2.59 raeburn 8974: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 8975: if ($context eq 'author') {
8976: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8977: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8978: } else {
8979: foreach my $subdir ('docs','supplemental') {
8980: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8981: }
8982: }
1.1075.2.41 raeburn 8983: $disk_quota = int($disk_quota * 1000);
8984: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 8985: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 8986: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 8987: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
8988: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 8989: $disk_quota,$current_disk_usage).
8990: '</p>';
8991: }
8992: return;
8993: }
8994:
8995: ###############################################
8996:
8997:
1.384 raeburn 8998: sub get_secgrprole_info {
8999: my ($cdom,$cnum,$needroles,$type) = @_;
9000: my %sections_count = &get_sections($cdom,$cnum);
9001: my @sections = (sort {$a <=> $b} keys(%sections_count));
9002: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9003: my @groups = sort(keys(%curr_groups));
9004: my $allroles = [];
9005: my $rolehash;
9006: my $accesshash = {
9007: active => 'Currently has access',
9008: future => 'Will have future access',
9009: previous => 'Previously had access',
9010: };
9011: if ($needroles) {
9012: $rolehash = {'all' => 'all'};
1.385 albertel 9013: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9014: if (&Apache::lonnet::error(%user_roles)) {
9015: undef(%user_roles);
9016: }
9017: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9018: my ($role)=split(/\:/,$item,2);
9019: if ($role eq 'cr') { next; }
9020: if ($role =~ /^cr/) {
9021: $$rolehash{$role} = (split('/',$role))[3];
9022: } else {
9023: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9024: }
9025: }
9026: foreach my $key (sort(keys(%{$rolehash}))) {
9027: push(@{$allroles},$key);
9028: }
9029: push (@{$allroles},'st');
9030: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9031: }
9032: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9033: }
9034:
1.555 raeburn 9035: sub user_picker {
1.994 raeburn 9036: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9037: my $currdom = $dom;
9038: my %curr_selected = (
9039: srchin => 'dom',
1.580 raeburn 9040: srchby => 'lastname',
1.555 raeburn 9041: );
9042: my $srchterm;
1.625 raeburn 9043: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9044: if ($srch->{'srchby'} ne '') {
9045: $curr_selected{'srchby'} = $srch->{'srchby'};
9046: }
9047: if ($srch->{'srchin'} ne '') {
9048: $curr_selected{'srchin'} = $srch->{'srchin'};
9049: }
9050: if ($srch->{'srchtype'} ne '') {
9051: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9052: }
9053: if ($srch->{'srchdomain'} ne '') {
9054: $currdom = $srch->{'srchdomain'};
9055: }
9056: $srchterm = $srch->{'srchterm'};
9057: }
9058: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 9059: 'usr' => 'Search criteria',
1.563 raeburn 9060: 'doma' => 'Domain/institution to search',
1.558 albertel 9061: 'uname' => 'username',
9062: 'lastname' => 'last name',
1.555 raeburn 9063: 'lastfirst' => 'last name, first name',
1.558 albertel 9064: 'crs' => 'in this course',
1.576 raeburn 9065: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9066: 'alc' => 'all LON-CAPA',
1.573 raeburn 9067: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9068: 'exact' => 'is',
9069: 'contains' => 'contains',
1.569 raeburn 9070: 'begins' => 'begins with',
1.571 raeburn 9071: 'youm' => "You must include some text to search for.",
9072: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9073: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9074: 'yomc' => "You must choose a domain when using an institutional directory search.",
9075: 'ymcd' => "You must choose a domain when using a domain search.",
9076: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9077: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9078: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9079: );
1.563 raeburn 9080: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9081: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9082:
9083: my @srchins = ('crs','dom','alc','instd');
9084:
9085: foreach my $option (@srchins) {
9086: # FIXME 'alc' option unavailable until
9087: # loncreateuser::print_user_query_page()
9088: # has been completed.
9089: next if ($option eq 'alc');
1.880 raeburn 9090: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9091: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9092: if ($curr_selected{'srchin'} eq $option) {
9093: $srchinsel .= '
9094: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9095: } else {
9096: $srchinsel .= '
9097: <option value="'.$option.'">'.$lt{$option}.'</option>';
9098: }
1.555 raeburn 9099: }
1.563 raeburn 9100: $srchinsel .= "\n </select>\n";
1.555 raeburn 9101:
9102: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9103: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9104: if ($curr_selected{'srchby'} eq $option) {
9105: $srchbysel .= '
9106: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9107: } else {
9108: $srchbysel .= '
9109: <option value="'.$option.'">'.$lt{$option}.'</option>';
9110: }
9111: }
9112: $srchbysel .= "\n </select>\n";
9113:
9114: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9115: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9116: if ($curr_selected{'srchtype'} eq $option) {
9117: $srchtypesel .= '
9118: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9119: } else {
9120: $srchtypesel .= '
9121: <option value="'.$option.'">'.$lt{$option}.'</option>';
9122: }
9123: }
9124: $srchtypesel .= "\n </select>\n";
9125:
1.558 albertel 9126: my ($newuserscript,$new_user_create);
1.994 raeburn 9127: my $context_dom = $env{'request.role.domain'};
9128: if ($context eq 'requestcrs') {
9129: if ($env{'form.coursedom'} ne '') {
9130: $context_dom = $env{'form.coursedom'};
9131: }
9132: }
1.556 raeburn 9133: if ($forcenewuser) {
1.576 raeburn 9134: if (ref($srch) eq 'HASH') {
1.994 raeburn 9135: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9136: if ($cancreate) {
9137: $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>';
9138: } else {
1.799 bisitz 9139: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9140: my %usertypetext = (
9141: official => 'institutional',
9142: unofficial => 'non-institutional',
9143: );
1.799 bisitz 9144: $new_user_create = '<p class="LC_warning">'
9145: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9146: .' '
9147: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9148: ,'<a href="'.$helplink.'">','</a>')
9149: .'</p><br />';
1.627 raeburn 9150: }
1.576 raeburn 9151: }
9152: }
9153:
1.556 raeburn 9154: $newuserscript = <<"ENDSCRIPT";
9155:
1.570 raeburn 9156: function setSearch(createnew,callingForm) {
1.556 raeburn 9157: if (createnew == 1) {
1.570 raeburn 9158: for (var i=0; i<callingForm.srchby.length; i++) {
9159: if (callingForm.srchby.options[i].value == 'uname') {
9160: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9161: }
9162: }
1.570 raeburn 9163: for (var i=0; i<callingForm.srchin.length; i++) {
9164: if ( callingForm.srchin.options[i].value == 'dom') {
9165: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9166: }
9167: }
1.570 raeburn 9168: for (var i=0; i<callingForm.srchtype.length; i++) {
9169: if (callingForm.srchtype.options[i].value == 'exact') {
9170: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9171: }
9172: }
1.570 raeburn 9173: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9174: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9175: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9176: }
9177: }
9178: }
9179: }
9180: ENDSCRIPT
1.558 albertel 9181:
1.556 raeburn 9182: }
9183:
1.555 raeburn 9184: my $output = <<"END_BLOCK";
1.556 raeburn 9185: <script type="text/javascript">
1.824 bisitz 9186: // <![CDATA[
1.570 raeburn 9187: function validateEntry(callingForm) {
1.558 albertel 9188:
1.556 raeburn 9189: var checkok = 1;
1.558 albertel 9190: var srchin;
1.570 raeburn 9191: for (var i=0; i<callingForm.srchin.length; i++) {
9192: if ( callingForm.srchin[i].checked ) {
9193: srchin = callingForm.srchin[i].value;
1.558 albertel 9194: }
9195: }
9196:
1.570 raeburn 9197: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9198: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9199: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9200: var srchterm = callingForm.srchterm.value;
9201: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9202: var msg = "";
9203:
9204: if (srchterm == "") {
9205: checkok = 0;
1.571 raeburn 9206: msg += "$lt{'youm'}\\n";
1.556 raeburn 9207: }
9208:
1.569 raeburn 9209: if (srchtype== 'begins') {
9210: if (srchterm.length < 2) {
9211: checkok = 0;
1.571 raeburn 9212: msg += "$lt{'thte'}\\n";
1.569 raeburn 9213: }
9214: }
9215:
1.556 raeburn 9216: if (srchtype== 'contains') {
9217: if (srchterm.length < 3) {
9218: checkok = 0;
1.571 raeburn 9219: msg += "$lt{'thet'}\\n";
1.556 raeburn 9220: }
9221: }
9222: if (srchin == 'instd') {
9223: if (srchdomain == '') {
9224: checkok = 0;
1.571 raeburn 9225: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9226: }
9227: }
9228: if (srchin == 'dom') {
9229: if (srchdomain == '') {
9230: checkok = 0;
1.571 raeburn 9231: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9232: }
9233: }
9234: if (srchby == 'lastfirst') {
9235: if (srchterm.indexOf(",") == -1) {
9236: checkok = 0;
1.571 raeburn 9237: msg += "$lt{'whus'}\\n";
1.556 raeburn 9238: }
9239: if (srchterm.indexOf(",") == srchterm.length -1) {
9240: checkok = 0;
1.571 raeburn 9241: msg += "$lt{'whse'}\\n";
1.556 raeburn 9242: }
9243: }
9244: if (checkok == 0) {
1.571 raeburn 9245: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9246: return;
9247: }
9248: if (checkok == 1) {
1.570 raeburn 9249: callingForm.submit();
1.556 raeburn 9250: }
9251: }
9252:
9253: $newuserscript
9254:
1.824 bisitz 9255: // ]]>
1.556 raeburn 9256: </script>
1.558 albertel 9257:
9258: $new_user_create
9259:
1.555 raeburn 9260: END_BLOCK
1.558 albertel 9261:
1.876 raeburn 9262: $output .= &Apache::lonhtmlcommon::start_pick_box().
9263: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9264: $domform.
9265: &Apache::lonhtmlcommon::row_closure().
9266: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9267: $srchbysel.
9268: $srchtypesel.
9269: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9270: $srchinsel.
9271: &Apache::lonhtmlcommon::row_closure(1).
9272: &Apache::lonhtmlcommon::end_pick_box().
9273: '<br />';
1.555 raeburn 9274: return $output;
9275: }
9276:
1.612 raeburn 9277: sub user_rule_check {
1.615 raeburn 9278: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9279: my $response;
9280: if (ref($usershash) eq 'HASH') {
9281: foreach my $user (keys(%{$usershash})) {
9282: my ($uname,$udom) = split(/:/,$user);
9283: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9284: my ($id,$newuser);
1.612 raeburn 9285: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9286: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9287: $id = $usershash->{$user}->{'id'};
9288: }
9289: my $inst_response;
9290: if (ref($checks) eq 'HASH') {
9291: if (defined($checks->{'username'})) {
1.615 raeburn 9292: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9293: &Apache::lonnet::get_instuser($udom,$uname);
9294: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9295: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9296: &Apache::lonnet::get_instuser($udom,undef,$id);
9297: }
1.615 raeburn 9298: } else {
9299: ($inst_response,%{$inst_results->{$user}}) =
9300: &Apache::lonnet::get_instuser($udom,$uname);
9301: return;
1.612 raeburn 9302: }
1.615 raeburn 9303: if (!$got_rules->{$udom}) {
1.612 raeburn 9304: my %domconfig = &Apache::lonnet::get_dom('configuration',
9305: ['usercreation'],$udom);
9306: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9307: foreach my $item ('username','id') {
1.612 raeburn 9308: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9309: $$curr_rules{$udom}{$item} =
9310: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9311: }
9312: }
9313: }
1.615 raeburn 9314: $got_rules->{$udom} = 1;
1.585 raeburn 9315: }
1.612 raeburn 9316: foreach my $item (keys(%{$checks})) {
9317: if (ref($$curr_rules{$udom}) eq 'HASH') {
9318: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9319: if (@{$$curr_rules{$udom}{$item}} > 0) {
9320: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9321: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9322: if ($rule_check{$rule}) {
9323: $$rulematch{$user}{$item} = $rule;
9324: if ($inst_response eq 'ok') {
1.615 raeburn 9325: if (ref($inst_results) eq 'HASH') {
9326: if (ref($inst_results->{$user}) eq 'HASH') {
9327: if (keys(%{$inst_results->{$user}}) == 0) {
9328: $$alerts{$item}{$udom}{$uname} = 1;
9329: }
1.612 raeburn 9330: }
9331: }
1.615 raeburn 9332: }
9333: last;
1.585 raeburn 9334: }
9335: }
9336: }
9337: }
9338: }
9339: }
9340: }
9341: }
1.612 raeburn 9342: return;
9343: }
9344:
9345: sub user_rule_formats {
9346: my ($domain,$domdesc,$curr_rules,$check) = @_;
9347: my %text = (
9348: 'username' => 'Usernames',
9349: 'id' => 'IDs',
9350: );
9351: my $output;
9352: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9353: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9354: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 9355: $output = '<br />'.
9356: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9357: '<span class="LC_cusr_emph">','</span>',$domdesc).
9358: ' <ul>';
1.612 raeburn 9359: foreach my $rule (@{$ruleorder}) {
9360: if (ref($curr_rules) eq 'ARRAY') {
9361: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9362: if (ref($rules->{$rule}) eq 'HASH') {
9363: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9364: $rules->{$rule}{'desc'}.'</li>';
9365: }
9366: }
9367: }
9368: }
9369: $output .= '</ul>';
9370: }
9371: }
9372: return $output;
9373: }
9374:
9375: sub instrule_disallow_msg {
1.615 raeburn 9376: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9377: my $response;
9378: my %text = (
9379: item => 'username',
9380: items => 'usernames',
9381: match => 'matches',
9382: do => 'does',
9383: action => 'a username',
9384: one => 'one',
9385: );
9386: if ($count > 1) {
9387: $text{'item'} = 'usernames';
9388: $text{'match'} ='match';
9389: $text{'do'} = 'do';
9390: $text{'action'} = 'usernames',
9391: $text{'one'} = 'ones';
9392: }
9393: if ($checkitem eq 'id') {
9394: $text{'items'} = 'IDs';
9395: $text{'item'} = 'ID';
9396: $text{'action'} = 'an ID';
1.615 raeburn 9397: if ($count > 1) {
9398: $text{'item'} = 'IDs';
9399: $text{'action'} = 'IDs';
9400: }
1.612 raeburn 9401: }
1.674 bisitz 9402: $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 9403: if ($mode eq 'upload') {
9404: if ($checkitem eq 'username') {
9405: $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'}.");
9406: } elsif ($checkitem eq 'id') {
1.674 bisitz 9407: $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 9408: }
1.669 raeburn 9409: } elsif ($mode eq 'selfcreate') {
9410: if ($checkitem eq 'id') {
9411: $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.");
9412: }
1.615 raeburn 9413: } else {
9414: if ($checkitem eq 'username') {
9415: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9416: } elsif ($checkitem eq 'id') {
9417: $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.");
9418: }
1.612 raeburn 9419: }
9420: return $response;
1.585 raeburn 9421: }
9422:
1.624 raeburn 9423: sub personal_data_fieldtitles {
9424: my %fieldtitles = &Apache::lonlocal::texthash (
9425: id => 'Student/Employee ID',
9426: permanentemail => 'E-mail address',
9427: lastname => 'Last Name',
9428: firstname => 'First Name',
9429: middlename => 'Middle Name',
9430: generation => 'Generation',
9431: gen => 'Generation',
1.765 raeburn 9432: inststatus => 'Affiliation',
1.624 raeburn 9433: );
9434: return %fieldtitles;
9435: }
9436:
1.642 raeburn 9437: sub sorted_inst_types {
9438: my ($dom) = @_;
1.1075.2.70 raeburn 9439: my ($usertypes,$order);
9440: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9441: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
9442: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
9443: $order = $domdefaults{'inststatus'}{'inststatusorder'};
9444: } else {
9445: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9446: }
1.642 raeburn 9447: my $othertitle = &mt('All users');
9448: if ($env{'request.course.id'}) {
1.668 raeburn 9449: $othertitle = &mt('Any users');
1.642 raeburn 9450: }
9451: my @types;
9452: if (ref($order) eq 'ARRAY') {
9453: @types = @{$order};
9454: }
9455: if (@types == 0) {
9456: if (ref($usertypes) eq 'HASH') {
9457: @types = sort(keys(%{$usertypes}));
9458: }
9459: }
9460: if (keys(%{$usertypes}) > 0) {
9461: $othertitle = &mt('Other users');
9462: }
9463: return ($othertitle,$usertypes,\@types);
9464: }
9465:
1.645 raeburn 9466: sub get_institutional_codes {
9467: my ($settings,$allcourses,$LC_code) = @_;
9468: # Get complete list of course sections to update
9469: my @currsections = ();
9470: my @currxlists = ();
9471: my $coursecode = $$settings{'internal.coursecode'};
9472:
9473: if ($$settings{'internal.sectionnums'} ne '') {
9474: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9475: }
9476:
9477: if ($$settings{'internal.crosslistings'} ne '') {
9478: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9479: }
9480:
9481: if (@currxlists > 0) {
9482: foreach (@currxlists) {
9483: if (m/^([^:]+):(\w*)$/) {
9484: unless (grep/^$1$/,@{$allcourses}) {
9485: push @{$allcourses},$1;
9486: $$LC_code{$1} = $2;
9487: }
9488: }
9489: }
9490: }
9491:
9492: if (@currsections > 0) {
9493: foreach (@currsections) {
9494: if (m/^(\w+):(\w*)$/) {
9495: my $sec = $coursecode.$1;
9496: my $lc_sec = $2;
9497: unless (grep/^$sec$/,@{$allcourses}) {
9498: push @{$allcourses},$sec;
9499: $$LC_code{$sec} = $lc_sec;
9500: }
9501: }
9502: }
9503: }
9504: return;
9505: }
9506:
1.971 raeburn 9507: sub get_standard_codeitems {
9508: return ('Year','Semester','Department','Number','Section');
9509: }
9510:
1.112 bowersj2 9511: =pod
9512:
1.780 raeburn 9513: =head1 Slot Helpers
9514:
9515: =over 4
9516:
9517: =item * sorted_slots()
9518:
1.1040 raeburn 9519: Sorts an array of slot names in order of an optional sort key,
9520: default sort is by slot start time (earliest first).
1.780 raeburn 9521:
9522: Inputs:
9523:
9524: =over 4
9525:
9526: slotsarr - Reference to array of unsorted slot names.
9527:
9528: slots - Reference to hash of hash, where outer hash keys are slot names.
9529:
1.1040 raeburn 9530: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9531:
1.549 albertel 9532: =back
9533:
1.780 raeburn 9534: Returns:
9535:
9536: =over 4
9537:
1.1040 raeburn 9538: sorted - An array of slot names sorted by a specified sort key
9539: (default sort key is start time of the slot).
1.780 raeburn 9540:
9541: =back
9542:
9543: =cut
9544:
9545:
9546: sub sorted_slots {
1.1040 raeburn 9547: my ($slotsarr,$slots,$sortkey) = @_;
9548: if ($sortkey eq '') {
9549: $sortkey = 'starttime';
9550: }
1.780 raeburn 9551: my @sorted;
9552: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9553: @sorted =
9554: sort {
9555: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9556: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9557: }
9558: if (ref($slots->{$a})) { return -1;}
9559: if (ref($slots->{$b})) { return 1;}
9560: return 0;
9561: } @{$slotsarr};
9562: }
9563: return @sorted;
9564: }
9565:
1.1040 raeburn 9566: =pod
9567:
9568: =item * get_future_slots()
9569:
9570: Inputs:
9571:
9572: =over 4
9573:
9574: cnum - course number
9575:
9576: cdom - course domain
9577:
9578: now - current UNIX time
9579:
9580: symb - optional symb
9581:
9582: =back
9583:
9584: Returns:
9585:
9586: =over 4
9587:
9588: sorted_reservable - ref to array of student_schedulable slots currently
9589: reservable, ordered by end date of reservation period.
9590:
9591: reservable_now - ref to hash of student_schedulable slots currently
9592: reservable.
9593:
9594: Keys in inner hash are:
9595: (a) symb: either blank or symb to which slot use is restricted.
9596: (b) endreserve: end date of reservation period.
9597:
9598: sorted_future - ref to array of student_schedulable slots reservable in
9599: the future, ordered by start date of reservation period.
9600:
9601: future_reservable - ref to hash of student_schedulable slots reservable
9602: in the future.
9603:
9604: Keys in inner hash are:
9605: (a) symb: either blank or symb to which slot use is restricted.
9606: (b) startreserve: start date of reservation period.
9607:
9608: =back
9609:
9610: =cut
9611:
9612: sub get_future_slots {
9613: my ($cnum,$cdom,$now,$symb) = @_;
9614: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9615: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9616: foreach my $slot (keys(%slots)) {
9617: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9618: if ($symb) {
9619: next if (($slots{$slot}->{'symb'} ne '') &&
9620: ($slots{$slot}->{'symb'} ne $symb));
9621: }
9622: if (($slots{$slot}->{'starttime'} > $now) &&
9623: ($slots{$slot}->{'endtime'} > $now)) {
9624: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9625: my $userallowed = 0;
9626: if ($slots{$slot}->{'allowedsections'}) {
9627: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9628: if (!defined($env{'request.role.sec'})
9629: && grep(/^No section assigned$/,@allowed_sec)) {
9630: $userallowed=1;
9631: } else {
9632: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9633: $userallowed=1;
9634: }
9635: }
9636: unless ($userallowed) {
9637: if (defined($env{'request.course.groups'})) {
9638: my @groups = split(/:/,$env{'request.course.groups'});
9639: foreach my $group (@groups) {
9640: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9641: $userallowed=1;
9642: last;
9643: }
9644: }
9645: }
9646: }
9647: }
9648: if ($slots{$slot}->{'allowedusers'}) {
9649: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9650: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9651: if (grep(/^\Q$user\E$/,@allowed_users)) {
9652: $userallowed = 1;
9653: }
9654: }
9655: next unless($userallowed);
9656: }
9657: my $startreserve = $slots{$slot}->{'startreserve'};
9658: my $endreserve = $slots{$slot}->{'endreserve'};
9659: my $symb = $slots{$slot}->{'symb'};
9660: if (($startreserve < $now) &&
9661: (!$endreserve || $endreserve > $now)) {
9662: my $lastres = $endreserve;
9663: if (!$lastres) {
9664: $lastres = $slots{$slot}->{'starttime'};
9665: }
9666: $reservable_now{$slot} = {
9667: symb => $symb,
9668: endreserve => $lastres
9669: };
9670: } elsif (($startreserve > $now) &&
9671: (!$endreserve || $endreserve > $startreserve)) {
9672: $future_reservable{$slot} = {
9673: symb => $symb,
9674: startreserve => $startreserve
9675: };
9676: }
9677: }
9678: }
9679: my @unsorted_reservable = keys(%reservable_now);
9680: if (@unsorted_reservable > 0) {
9681: @sorted_reservable =
9682: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9683: }
9684: my @unsorted_future = keys(%future_reservable);
9685: if (@unsorted_future > 0) {
9686: @sorted_future =
9687: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9688: }
9689: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9690: }
1.780 raeburn 9691:
9692: =pod
9693:
1.1057 foxr 9694: =back
9695:
1.549 albertel 9696: =head1 HTTP Helpers
9697:
9698: =over 4
9699:
1.648 raeburn 9700: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9701:
1.258 albertel 9702: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9703: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9704: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9705:
9706: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9707: $possible_names is an ref to an array of form element names. As an example:
9708: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9709: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9710:
9711: =cut
1.1 albertel 9712:
1.6 albertel 9713: sub get_unprocessed_cgi {
1.25 albertel 9714: my ($query,$possible_names)= @_;
1.26 matthew 9715: # $Apache::lonxml::debug=1;
1.356 albertel 9716: foreach my $pair (split(/&/,$query)) {
9717: my ($name, $value) = split(/=/,$pair);
1.369 www 9718: $name = &unescape($name);
1.25 albertel 9719: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9720: $value =~ tr/+/ /;
9721: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9722: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9723: }
1.16 harris41 9724: }
1.6 albertel 9725: }
9726:
1.112 bowersj2 9727: =pod
9728:
1.648 raeburn 9729: =item * &cacheheader()
1.112 bowersj2 9730:
9731: returns cache-controlling header code
9732:
9733: =cut
9734:
1.7 albertel 9735: sub cacheheader {
1.258 albertel 9736: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9737: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9738: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9739: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9740: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9741: return $output;
1.7 albertel 9742: }
9743:
1.112 bowersj2 9744: =pod
9745:
1.648 raeburn 9746: =item * &no_cache($r)
1.112 bowersj2 9747:
9748: specifies header code to not have cache
9749:
9750: =cut
9751:
1.9 albertel 9752: sub no_cache {
1.216 albertel 9753: my ($r) = @_;
9754: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9755: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9756: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9757: $r->no_cache(1);
9758: $r->header_out("Expires" => $date);
9759: $r->header_out("Pragma" => "no-cache");
1.123 www 9760: }
9761:
9762: sub content_type {
1.181 albertel 9763: my ($r,$type,$charset) = @_;
1.299 foxr 9764: if ($r) {
9765: # Note that printout.pl calls this with undef for $r.
9766: &no_cache($r);
9767: }
1.258 albertel 9768: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9769: unless ($charset) {
9770: $charset=&Apache::lonlocal::current_encoding;
9771: }
9772: if ($charset) { $type.='; charset='.$charset; }
9773: if ($r) {
9774: $r->content_type($type);
9775: } else {
9776: print("Content-type: $type\n\n");
9777: }
1.9 albertel 9778: }
1.25 albertel 9779:
1.112 bowersj2 9780: =pod
9781:
1.648 raeburn 9782: =item * &add_to_env($name,$value)
1.112 bowersj2 9783:
1.258 albertel 9784: adds $name to the %env hash with value
1.112 bowersj2 9785: $value, if $name already exists, the entry is converted to an array
9786: reference and $value is added to the array.
9787:
9788: =cut
9789:
1.25 albertel 9790: sub add_to_env {
9791: my ($name,$value)=@_;
1.258 albertel 9792: if (defined($env{$name})) {
9793: if (ref($env{$name})) {
1.25 albertel 9794: #already have multiple values
1.258 albertel 9795: push(@{ $env{$name} },$value);
1.25 albertel 9796: } else {
9797: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9798: my $first=$env{$name};
9799: undef($env{$name});
9800: push(@{ $env{$name} },$first,$value);
1.25 albertel 9801: }
9802: } else {
1.258 albertel 9803: $env{$name}=$value;
1.25 albertel 9804: }
1.31 albertel 9805: }
1.149 albertel 9806:
9807: =pod
9808:
1.648 raeburn 9809: =item * &get_env_multiple($name)
1.149 albertel 9810:
1.258 albertel 9811: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9812: values may be defined and end up as an array ref.
9813:
9814: returns an array of values
9815:
9816: =cut
9817:
9818: sub get_env_multiple {
9819: my ($name) = @_;
9820: my @values;
1.258 albertel 9821: if (defined($env{$name})) {
1.149 albertel 9822: # exists is it an array
1.258 albertel 9823: if (ref($env{$name})) {
9824: @values=@{ $env{$name} };
1.149 albertel 9825: } else {
1.258 albertel 9826: $values[0]=$env{$name};
1.149 albertel 9827: }
9828: }
9829: return(@values);
9830: }
9831:
1.660 raeburn 9832: sub ask_for_embedded_content {
9833: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9834: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 9835: %currsubfile,%unused,$rem);
1.1071 raeburn 9836: my $counter = 0;
9837: my $numnew = 0;
1.987 raeburn 9838: my $numremref = 0;
9839: my $numinvalid = 0;
9840: my $numpathchg = 0;
9841: my $numexisting = 0;
1.1071 raeburn 9842: my $numunused = 0;
9843: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 9844: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 9845: my $heading = &mt('Upload embedded files');
9846: my $buttontext = &mt('Upload');
9847:
1.1075.2.11 raeburn 9848: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 9849: if ($actionurl eq '/adm/dependencies') {
9850: $navmap = Apache::lonnavmaps::navmap->new();
9851: }
9852: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9853: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 9854: }
1.1075.2.35 raeburn 9855: if (($actionurl eq '/adm/portfolio') ||
9856: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9857: my $current_path='/';
9858: if ($env{'form.currentpath'}) {
9859: $current_path = $env{'form.currentpath'};
9860: }
9861: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 9862: $udom = $cdom;
9863: $uname = $cnum;
1.984 raeburn 9864: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9865: } else {
9866: $udom = $env{'user.domain'};
9867: $uname = $env{'user.name'};
9868: $url = '/userfiles/portfolio';
9869: }
1.987 raeburn 9870: $toplevel = $url.'/';
1.984 raeburn 9871: $url .= $current_path;
9872: $getpropath = 1;
1.987 raeburn 9873: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9874: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9875: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9876: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9877: $toplevel = $url;
1.984 raeburn 9878: if ($rest ne '') {
1.987 raeburn 9879: $url .= $rest;
9880: }
9881: } elsif ($actionurl eq '/adm/coursedocs') {
9882: if (ref($args) eq 'HASH') {
1.1071 raeburn 9883: $url = $args->{'docs_url'};
9884: $toplevel = $url;
1.1075.2.11 raeburn 9885: if ($args->{'context'} eq 'paste') {
9886: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9887: ($path) =
9888: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9889: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9890: $fileloc =~ s{^/}{};
9891: }
1.1071 raeburn 9892: }
9893: } elsif ($actionurl eq '/adm/dependencies') {
9894: if ($env{'request.course.id'} ne '') {
9895: if (ref($args) eq 'HASH') {
9896: $url = $args->{'docs_url'};
9897: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 9898: $toplevel = $url;
9899: unless ($toplevel =~ m{^/}) {
9900: $toplevel = "/$url";
9901: }
1.1075.2.11 raeburn 9902: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 9903: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9904: $path = $1;
9905: } else {
9906: ($path) =
9907: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9908: }
1.1071 raeburn 9909: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9910: $fileloc =~ s{^/}{};
9911: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9912: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9913: }
1.987 raeburn 9914: }
1.1075.2.35 raeburn 9915: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9916: $udom = $cdom;
9917: $uname = $cnum;
9918: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9919: $toplevel = $url;
9920: $path = $url;
9921: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9922: $fileloc =~ s{^/}{};
9923: }
9924: foreach my $file (keys(%{$allfiles})) {
9925: my $embed_file;
9926: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9927: $embed_file = $1;
9928: } else {
9929: $embed_file = $file;
9930: }
1.1075.2.55 raeburn 9931: my ($absolutepath,$cleaned_file);
9932: if ($embed_file =~ m{^\w+://}) {
9933: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 9934: $newfiles{$cleaned_file} = 1;
9935: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9936: } else {
1.1075.2.55 raeburn 9937: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 9938: if ($embed_file =~ m{^/}) {
9939: $absolutepath = $embed_file;
9940: }
1.1075.2.47 raeburn 9941: if ($cleaned_file =~ m{/}) {
9942: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 9943: $path = &check_for_traversal($path,$url,$toplevel);
9944: my $item = $fname;
9945: if ($path ne '') {
9946: $item = $path.'/'.$fname;
9947: $subdependencies{$path}{$fname} = 1;
9948: } else {
9949: $dependencies{$item} = 1;
9950: }
9951: if ($absolutepath) {
9952: $mapping{$item} = $absolutepath;
9953: } else {
9954: $mapping{$item} = $embed_file;
9955: }
9956: } else {
9957: $dependencies{$embed_file} = 1;
9958: if ($absolutepath) {
1.1075.2.47 raeburn 9959: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 9960: } else {
1.1075.2.47 raeburn 9961: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9962: }
9963: }
1.984 raeburn 9964: }
9965: }
1.1071 raeburn 9966: my $dirptr = 16384;
1.984 raeburn 9967: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9968: $currsubfile{$path} = {};
1.1075.2.35 raeburn 9969: if (($actionurl eq '/adm/portfolio') ||
9970: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9971: my ($sublistref,$listerror) =
9972: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9973: if (ref($sublistref) eq 'ARRAY') {
9974: foreach my $line (@{$sublistref}) {
9975: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9976: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9977: }
1.984 raeburn 9978: }
1.987 raeburn 9979: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9980: if (opendir(my $dir,$url.'/'.$path)) {
9981: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9982: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9983: }
1.1075.2.11 raeburn 9984: } elsif (($actionurl eq '/adm/dependencies') ||
9985: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 9986: ($args->{'context'} eq 'paste')) ||
9987: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9988: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 9989: my $dir;
9990: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9991: $dir = $fileloc;
9992: } else {
9993: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9994: }
1.1071 raeburn 9995: if ($dir ne '') {
9996: my ($sublistref,$listerror) =
9997: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9998: if (ref($sublistref) eq 'ARRAY') {
9999: foreach my $line (@{$sublistref}) {
10000: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10001: undef,$mtime)=split(/\&/,$line,12);
10002: unless (($testdir&$dirptr) ||
10003: ($file_name =~ /^\.\.?$/)) {
10004: $currsubfile{$path}{$file_name} = [$size,$mtime];
10005: }
10006: }
10007: }
10008: }
1.984 raeburn 10009: }
10010: }
10011: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10012: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10013: my $item = $path.'/'.$file;
10014: unless ($mapping{$item} eq $item) {
10015: $pathchanges{$item} = 1;
10016: }
10017: $existing{$item} = 1;
10018: $numexisting ++;
10019: } else {
10020: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10021: }
10022: }
1.1071 raeburn 10023: if ($actionurl eq '/adm/dependencies') {
10024: foreach my $path (keys(%currsubfile)) {
10025: if (ref($currsubfile{$path}) eq 'HASH') {
10026: foreach my $file (keys(%{$currsubfile{$path}})) {
10027: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10028: next if (($rem ne '') &&
10029: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10030: (ref($navmap) &&
10031: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10032: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10033: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10034: $unused{$path.'/'.$file} = 1;
10035: }
10036: }
10037: }
10038: }
10039: }
1.984 raeburn 10040: }
1.987 raeburn 10041: my %currfile;
1.1075.2.35 raeburn 10042: if (($actionurl eq '/adm/portfolio') ||
10043: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10044: my ($dirlistref,$listerror) =
10045: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10046: if (ref($dirlistref) eq 'ARRAY') {
10047: foreach my $line (@{$dirlistref}) {
10048: my ($file_name,$rest) = split(/\&/,$line,2);
10049: $currfile{$file_name} = 1;
10050: }
1.984 raeburn 10051: }
1.987 raeburn 10052: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10053: if (opendir(my $dir,$url)) {
1.987 raeburn 10054: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10055: map {$currfile{$_} = 1;} @dir_list;
10056: }
1.1075.2.11 raeburn 10057: } elsif (($actionurl eq '/adm/dependencies') ||
10058: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10059: ($args->{'context'} eq 'paste')) ||
10060: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10061: if ($env{'request.course.id'} ne '') {
10062: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10063: if ($dir ne '') {
10064: my ($dirlistref,$listerror) =
10065: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10066: if (ref($dirlistref) eq 'ARRAY') {
10067: foreach my $line (@{$dirlistref}) {
10068: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10069: $size,undef,$mtime)=split(/\&/,$line,12);
10070: unless (($testdir&$dirptr) ||
10071: ($file_name =~ /^\.\.?$/)) {
10072: $currfile{$file_name} = [$size,$mtime];
10073: }
10074: }
10075: }
10076: }
10077: }
1.984 raeburn 10078: }
10079: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10080: if (exists($currfile{$file})) {
1.987 raeburn 10081: unless ($mapping{$file} eq $file) {
10082: $pathchanges{$file} = 1;
10083: }
10084: $existing{$file} = 1;
10085: $numexisting ++;
10086: } else {
1.984 raeburn 10087: $newfiles{$file} = 1;
10088: }
10089: }
1.1071 raeburn 10090: foreach my $file (keys(%currfile)) {
10091: unless (($file eq $filename) ||
10092: ($file eq $filename.'.bak') ||
10093: ($dependencies{$file})) {
1.1075.2.11 raeburn 10094: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10095: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10096: next if (($rem ne '') &&
10097: (($env{"httpref.$rem".$file} ne '') ||
10098: (ref($navmap) &&
10099: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10100: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10101: ($navmap->getResourceByUrl($rem.$1)))))));
10102: }
1.1075.2.11 raeburn 10103: }
1.1071 raeburn 10104: $unused{$file} = 1;
10105: }
10106: }
1.1075.2.11 raeburn 10107: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10108: ($args->{'context'} eq 'paste')) {
10109: $counter = scalar(keys(%existing));
10110: $numpathchg = scalar(keys(%pathchanges));
10111: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10112: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10113: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10114: $counter = scalar(keys(%existing));
10115: $numpathchg = scalar(keys(%pathchanges));
10116: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10117: }
1.984 raeburn 10118: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10119: if ($actionurl eq '/adm/dependencies') {
10120: next if ($embed_file =~ m{^\w+://});
10121: }
1.660 raeburn 10122: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10123: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10124: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10125: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10126: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10127: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10128: }
1.1075.2.35 raeburn 10129: $upload_output .= '</td>';
1.1071 raeburn 10130: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10131: $upload_output.='<td align="right">'.
10132: '<span class="LC_info LC_fontsize_medium">'.
10133: &mt("URL points to web address").'</span>';
1.987 raeburn 10134: $numremref++;
1.660 raeburn 10135: } elsif ($args->{'error_on_invalid_names'}
10136: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10137: $upload_output.='<td align="right"><span class="LC_warning">'.
10138: &mt('Invalid characters').'</span>';
1.987 raeburn 10139: $numinvalid++;
1.660 raeburn 10140: } else {
1.1075.2.35 raeburn 10141: $upload_output .= '<td>'.
10142: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10143: $embed_file,\%mapping,
1.1071 raeburn 10144: $allfiles,$codebase,'upload');
10145: $counter ++;
10146: $numnew ++;
1.987 raeburn 10147: }
10148: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10149: }
10150: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10151: if ($actionurl eq '/adm/dependencies') {
10152: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10153: $modify_output .= &start_data_table_row().
10154: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10155: '<img src="'.&icon($embed_file).'" border="0" />'.
10156: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10157: '<td>'.$size.'</td>'.
10158: '<td>'.$mtime.'</td>'.
10159: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10160: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10161: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10162: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10163: &embedded_file_element('upload_embedded',$counter,
10164: $embed_file,\%mapping,
10165: $allfiles,$codebase,'modify').
10166: '</div></td>'.
10167: &end_data_table_row()."\n";
10168: $counter ++;
10169: } else {
10170: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10171: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10172: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10173: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10174: &Apache::loncommon::end_data_table_row()."\n";
10175: }
10176: }
10177: my $delidx = $counter;
10178: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10179: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10180: $delete_output .= &start_data_table_row().
10181: '<td><img src="'.&icon($oldfile).'" />'.
10182: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10183: '<td>'.$size.'</td>'.
10184: '<td>'.$mtime.'</td>'.
10185: '<td><label><input type="checkbox" name="del_upload_dep" '.
10186: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10187: &embedded_file_element('upload_embedded',$delidx,
10188: $oldfile,\%mapping,$allfiles,
10189: $codebase,'delete').'</td>'.
10190: &end_data_table_row()."\n";
10191: $numunused ++;
10192: $delidx ++;
1.987 raeburn 10193: }
10194: if ($upload_output) {
10195: $upload_output = &start_data_table().
10196: $upload_output.
10197: &end_data_table()."\n";
10198: }
1.1071 raeburn 10199: if ($modify_output) {
10200: $modify_output = &start_data_table().
10201: &start_data_table_header_row().
10202: '<th>'.&mt('File').'</th>'.
10203: '<th>'.&mt('Size (KB)').'</th>'.
10204: '<th>'.&mt('Modified').'</th>'.
10205: '<th>'.&mt('Upload replacement?').'</th>'.
10206: &end_data_table_header_row().
10207: $modify_output.
10208: &end_data_table()."\n";
10209: }
10210: if ($delete_output) {
10211: $delete_output = &start_data_table().
10212: &start_data_table_header_row().
10213: '<th>'.&mt('File').'</th>'.
10214: '<th>'.&mt('Size (KB)').'</th>'.
10215: '<th>'.&mt('Modified').'</th>'.
10216: '<th>'.&mt('Delete?').'</th>'.
10217: &end_data_table_header_row().
10218: $delete_output.
10219: &end_data_table()."\n";
10220: }
1.987 raeburn 10221: my $applies = 0;
10222: if ($numremref) {
10223: $applies ++;
10224: }
10225: if ($numinvalid) {
10226: $applies ++;
10227: }
10228: if ($numexisting) {
10229: $applies ++;
10230: }
1.1071 raeburn 10231: if ($counter || $numunused) {
1.987 raeburn 10232: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10233: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10234: $state.'<h3>'.$heading.'</h3>';
10235: if ($actionurl eq '/adm/dependencies') {
10236: if ($numnew) {
10237: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10238: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10239: $upload_output.'<br />'."\n";
10240: }
10241: if ($numexisting) {
10242: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10243: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10244: $modify_output.'<br />'."\n";
10245: $buttontext = &mt('Save changes');
10246: }
10247: if ($numunused) {
10248: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10249: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10250: $delete_output.'<br />'."\n";
10251: $buttontext = &mt('Save changes');
10252: }
10253: } else {
10254: $output .= $upload_output.'<br />'."\n";
10255: }
10256: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10257: $counter.'" />'."\n";
10258: if ($actionurl eq '/adm/dependencies') {
10259: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10260: $numnew.'" />'."\n";
10261: } elsif ($actionurl eq '') {
1.987 raeburn 10262: $output .= '<input type="hidden" name="phase" value="three" />';
10263: }
10264: } elsif ($applies) {
10265: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10266: if ($applies > 1) {
10267: $output .=
1.1075.2.35 raeburn 10268: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10269: if ($numremref) {
10270: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10271: }
10272: if ($numinvalid) {
10273: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10274: }
10275: if ($numexisting) {
10276: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10277: }
10278: $output .= '</ul><br />';
10279: } elsif ($numremref) {
10280: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10281: } elsif ($numinvalid) {
10282: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10283: } elsif ($numexisting) {
10284: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10285: }
10286: $output .= $upload_output.'<br />';
10287: }
10288: my ($pathchange_output,$chgcount);
1.1071 raeburn 10289: $chgcount = $counter;
1.987 raeburn 10290: if (keys(%pathchanges) > 0) {
10291: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10292: if ($counter) {
1.987 raeburn 10293: $output .= &embedded_file_element('pathchange',$chgcount,
10294: $embed_file,\%mapping,
1.1071 raeburn 10295: $allfiles,$codebase,'change');
1.987 raeburn 10296: } else {
10297: $pathchange_output .=
10298: &start_data_table_row().
10299: '<td><input type ="checkbox" name="namechange" value="'.
10300: $chgcount.'" checked="checked" /></td>'.
10301: '<td>'.$mapping{$embed_file}.'</td>'.
10302: '<td>'.$embed_file.
10303: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10304: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10305: '</td>'.&end_data_table_row();
1.660 raeburn 10306: }
1.987 raeburn 10307: $numpathchg ++;
10308: $chgcount ++;
1.660 raeburn 10309: }
10310: }
1.1075.2.35 raeburn 10311: if (($counter) || ($numunused)) {
1.987 raeburn 10312: if ($numpathchg) {
10313: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10314: $numpathchg.'" />'."\n";
10315: }
10316: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10317: ($actionurl eq '/adm/imsimport')) {
10318: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10319: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10320: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10321: } elsif ($actionurl eq '/adm/dependencies') {
10322: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10323: }
1.1075.2.35 raeburn 10324: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10325: } elsif ($numpathchg) {
10326: my %pathchange = ();
10327: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10328: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10329: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 10330: }
1.987 raeburn 10331: }
1.1071 raeburn 10332: return ($output,$counter,$numpathchg);
1.987 raeburn 10333: }
10334:
1.1075.2.47 raeburn 10335: =pod
10336:
10337: =item * clean_path($name)
10338:
10339: Performs clean-up of directories, subdirectories and filename in an
10340: embedded object, referenced in an HTML file which is being uploaded
10341: to a course or portfolio, where
10342: "Upload embedded images/multimedia files if HTML file" checkbox was
10343: checked.
10344:
10345: Clean-up is similar to replacements in lonnet::clean_filename()
10346: except each / between sub-directory and next level is preserved.
10347:
10348: =cut
10349:
10350: sub clean_path {
10351: my ($embed_file) = @_;
10352: $embed_file =~s{^/+}{};
10353: my @contents;
10354: if ($embed_file =~ m{/}) {
10355: @contents = split(/\//,$embed_file);
10356: } else {
10357: @contents = ($embed_file);
10358: }
10359: my $lastidx = scalar(@contents)-1;
10360: for (my $i=0; $i<=$lastidx; $i++) {
10361: $contents[$i]=~s{\\}{/}g;
10362: $contents[$i]=~s/\s+/\_/g;
10363: $contents[$i]=~s{[^/\w\.\-]}{}g;
10364: if ($i == $lastidx) {
10365: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10366: }
10367: }
10368: if ($lastidx > 0) {
10369: return join('/',@contents);
10370: } else {
10371: return $contents[0];
10372: }
10373: }
10374:
1.987 raeburn 10375: sub embedded_file_element {
1.1071 raeburn 10376: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10377: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10378: (ref($codebase) eq 'HASH'));
10379: my $output;
1.1071 raeburn 10380: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10381: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10382: }
10383: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10384: &escape($embed_file).'" />';
10385: unless (($context eq 'upload_embedded') &&
10386: ($mapping->{$embed_file} eq $embed_file)) {
10387: $output .='
10388: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10389: }
10390: my $attrib;
10391: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10392: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10393: }
10394: $output .=
10395: "\n\t\t".
10396: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10397: $attrib.'" />';
10398: if (exists($codebase->{$mapping->{$embed_file}})) {
10399: $output .=
10400: "\n\t\t".
10401: '<input name="codebase_'.$num.'" type="hidden" value="'.
10402: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10403: }
1.987 raeburn 10404: return $output;
1.660 raeburn 10405: }
10406:
1.1071 raeburn 10407: sub get_dependency_details {
10408: my ($currfile,$currsubfile,$embed_file) = @_;
10409: my ($size,$mtime,$showsize,$showmtime);
10410: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10411: if ($embed_file =~ m{/}) {
10412: my ($path,$fname) = split(/\//,$embed_file);
10413: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10414: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10415: }
10416: } else {
10417: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10418: ($size,$mtime) = @{$currfile->{$embed_file}};
10419: }
10420: }
10421: $showsize = $size/1024.0;
10422: $showsize = sprintf("%.1f",$showsize);
10423: if ($mtime > 0) {
10424: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10425: }
10426: }
10427: return ($showsize,$showmtime);
10428: }
10429:
10430: sub ask_embedded_js {
10431: return <<"END";
10432: <script type="text/javascript"">
10433: // <![CDATA[
10434: function toggleBrowse(counter) {
10435: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10436: var fileid = document.getElementById('embedded_item_'+counter);
10437: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10438: if (chkboxid.checked == true) {
10439: uploaddivid.style.display='block';
10440: } else {
10441: uploaddivid.style.display='none';
10442: fileid.value = '';
10443: }
10444: }
10445: // ]]>
10446: </script>
10447:
10448: END
10449: }
10450:
1.661 raeburn 10451: sub upload_embedded {
10452: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10453: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10454: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10455: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10456: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10457: my $orig_uploaded_filename =
10458: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10459: foreach my $type ('orig','ref','attrib','codebase') {
10460: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10461: $env{'form.embedded_'.$type.'_'.$i} =
10462: &unescape($env{'form.embedded_'.$type.'_'.$i});
10463: }
10464: }
1.661 raeburn 10465: my ($path,$fname) =
10466: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10467: # no path, whole string is fname
10468: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10469: $fname = &Apache::lonnet::clean_filename($fname);
10470: # See if there is anything left
10471: next if ($fname eq '');
10472:
10473: # Check if file already exists as a file or directory.
10474: my ($state,$msg);
10475: if ($context eq 'portfolio') {
10476: my $port_path = $dirpath;
10477: if ($group ne '') {
10478: $port_path = "groups/$group/$port_path";
10479: }
1.987 raeburn 10480: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10481: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10482: $dir_root,$port_path,$disk_quota,
10483: $current_disk_usage,$uname,$udom);
10484: if ($state eq 'will_exceed_quota'
1.984 raeburn 10485: || $state eq 'file_locked') {
1.661 raeburn 10486: $output .= $msg;
10487: next;
10488: }
10489: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10490: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10491: if ($state eq 'exists') {
10492: $output .= $msg;
10493: next;
10494: }
10495: }
10496: # Check if extension is valid
10497: if (($fname =~ /\.(\w+)$/) &&
10498: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 10499: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10500: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10501: next;
10502: } elsif (($fname =~ /\.(\w+)$/) &&
10503: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10504: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10505: next;
10506: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 10507: $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 10508: next;
10509: }
10510: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 10511: my $subdir = $path;
10512: $subdir =~ s{/+$}{};
1.661 raeburn 10513: if ($context eq 'portfolio') {
1.984 raeburn 10514: my $result;
10515: if ($state eq 'existingfile') {
10516: $result=
10517: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 10518: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10519: } else {
1.984 raeburn 10520: $result=
10521: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10522: $dirpath.
1.1075.2.35 raeburn 10523: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10524: if ($result !~ m|^/uploaded/|) {
10525: $output .= '<span class="LC_error">'
10526: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10527: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10528: .'</span><br />';
10529: next;
10530: } else {
1.987 raeburn 10531: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10532: $path.$fname.'</span>').'<br />';
1.984 raeburn 10533: }
1.661 raeburn 10534: }
1.1075.2.35 raeburn 10535: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
10536: my $extendedsubdir = $dirpath.'/'.$subdir;
10537: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10538: my $result =
1.1075.2.35 raeburn 10539: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10540: if ($result !~ m|^/uploaded/|) {
10541: $output .= '<span class="LC_error">'
10542: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10543: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10544: .'</span><br />';
10545: next;
10546: } else {
10547: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10548: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 10549: if ($context eq 'syllabus') {
10550: &Apache::lonnet::make_public_indefinitely($result);
10551: }
1.987 raeburn 10552: }
1.661 raeburn 10553: } else {
10554: # Save the file
10555: my $target = $env{'form.embedded_item_'.$i};
10556: my $fullpath = $dir_root.$dirpath.'/'.$path;
10557: my $dest = $fullpath.$fname;
10558: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10559: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10560: my $count;
10561: my $filepath = $dir_root;
1.1027 raeburn 10562: foreach my $subdir (@parts) {
10563: $filepath .= "/$subdir";
10564: if (!-e $filepath) {
1.661 raeburn 10565: mkdir($filepath,0770);
10566: }
10567: }
10568: my $fh;
10569: if (!open($fh,'>'.$dest)) {
10570: &Apache::lonnet::logthis('Failed to create '.$dest);
10571: $output .= '<span class="LC_error">'.
1.1071 raeburn 10572: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10573: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10574: '</span><br />';
10575: } else {
10576: if (!print $fh $env{'form.embedded_item_'.$i}) {
10577: &Apache::lonnet::logthis('Failed to write to '.$dest);
10578: $output .= '<span class="LC_error">'.
1.1071 raeburn 10579: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10580: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10581: '</span><br />';
10582: } else {
1.987 raeburn 10583: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10584: $url.'</span>').'<br />';
10585: unless ($context eq 'testbank') {
10586: $footer .= &mt('View embedded file: [_1]',
10587: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10588: }
10589: }
10590: close($fh);
10591: }
10592: }
10593: if ($env{'form.embedded_ref_'.$i}) {
10594: $pathchange{$i} = 1;
10595: }
10596: }
10597: if ($output) {
10598: $output = '<p>'.$output.'</p>';
10599: }
10600: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10601: $returnflag = 'ok';
1.1071 raeburn 10602: my $numpathchgs = scalar(keys(%pathchange));
10603: if ($numpathchgs > 0) {
1.987 raeburn 10604: if ($context eq 'portfolio') {
10605: $output .= '<p>'.&mt('or').'</p>';
10606: } elsif ($context eq 'testbank') {
1.1071 raeburn 10607: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10608: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10609: $returnflag = 'modify_orightml';
10610: }
10611: }
1.1071 raeburn 10612: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10613: }
10614:
10615: sub modify_html_form {
10616: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10617: my $end = 0;
10618: my $modifyform;
10619: if ($context eq 'upload_embedded') {
10620: return unless (ref($pathchange) eq 'HASH');
10621: if ($env{'form.number_embedded_items'}) {
10622: $end += $env{'form.number_embedded_items'};
10623: }
10624: if ($env{'form.number_pathchange_items'}) {
10625: $end += $env{'form.number_pathchange_items'};
10626: }
10627: if ($end) {
10628: for (my $i=0; $i<$end; $i++) {
10629: if ($i < $env{'form.number_embedded_items'}) {
10630: next unless($pathchange->{$i});
10631: }
10632: $modifyform .=
10633: &start_data_table_row().
10634: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10635: 'checked="checked" /></td>'.
10636: '<td>'.$env{'form.embedded_ref_'.$i}.
10637: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10638: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10639: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10640: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10641: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10642: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10643: '<td>'.$env{'form.embedded_orig_'.$i}.
10644: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10645: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10646: &end_data_table_row();
1.1071 raeburn 10647: }
1.987 raeburn 10648: }
10649: } else {
10650: $modifyform = $pathchgtable;
10651: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10652: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10653: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10654: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10655: }
10656: }
10657: if ($modifyform) {
1.1071 raeburn 10658: if ($actionurl eq '/adm/dependencies') {
10659: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10660: }
1.987 raeburn 10661: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10662: '<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".
10663: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10664: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10665: '</ol></p>'."\n".'<p>'.
10666: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10667: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10668: &start_data_table()."\n".
10669: &start_data_table_header_row().
10670: '<th>'.&mt('Change?').'</th>'.
10671: '<th>'.&mt('Current reference').'</th>'.
10672: '<th>'.&mt('Required reference').'</th>'.
10673: &end_data_table_header_row()."\n".
10674: $modifyform.
10675: &end_data_table().'<br />'."\n".$hiddenstate.
10676: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10677: '</form>'."\n";
10678: }
10679: return;
10680: }
10681:
10682: sub modify_html_refs {
1.1075.2.35 raeburn 10683: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10684: my $container;
10685: if ($context eq 'portfolio') {
10686: $container = $env{'form.container'};
10687: } elsif ($context eq 'coursedoc') {
10688: $container = $env{'form.primaryurl'};
1.1071 raeburn 10689: } elsif ($context eq 'manage_dependencies') {
10690: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10691: $container = "/$container";
1.1075.2.35 raeburn 10692: } elsif ($context eq 'syllabus') {
10693: $container = $url;
1.987 raeburn 10694: } else {
1.1027 raeburn 10695: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10696: }
10697: my (%allfiles,%codebase,$output,$content);
10698: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 10699: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10700: if (wantarray) {
10701: return ('',0,0);
10702: } else {
10703: return;
10704: }
10705: }
10706: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10707: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10708: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10709: if (wantarray) {
10710: return ('',0,0);
10711: } else {
10712: return;
10713: }
10714: }
1.987 raeburn 10715: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10716: if ($content eq '-1') {
10717: if (wantarray) {
10718: return ('',0,0);
10719: } else {
10720: return;
10721: }
10722: }
1.987 raeburn 10723: } else {
1.1071 raeburn 10724: unless ($container =~ /^\Q$dir_root\E/) {
10725: if (wantarray) {
10726: return ('',0,0);
10727: } else {
10728: return;
10729: }
10730: }
1.987 raeburn 10731: if (open(my $fh,"<$container")) {
10732: $content = join('', <$fh>);
10733: close($fh);
10734: } else {
1.1071 raeburn 10735: if (wantarray) {
10736: return ('',0,0);
10737: } else {
10738: return;
10739: }
1.987 raeburn 10740: }
10741: }
10742: my ($count,$codebasecount) = (0,0);
10743: my $mm = new File::MMagic;
10744: my $mime_type = $mm->checktype_contents($content);
10745: if ($mime_type eq 'text/html') {
10746: my $parse_result =
10747: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10748: \%codebase,\$content);
10749: if ($parse_result eq 'ok') {
10750: foreach my $i (@changes) {
10751: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10752: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10753: if ($allfiles{$ref}) {
10754: my $newname = $orig;
10755: my ($attrib_regexp,$codebase);
1.1006 raeburn 10756: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10757: if ($attrib_regexp =~ /:/) {
10758: $attrib_regexp =~ s/\:/|/g;
10759: }
10760: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10761: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10762: $count += $numchg;
1.1075.2.35 raeburn 10763: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 10764: delete($allfiles{$ref});
1.987 raeburn 10765: }
10766: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10767: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10768: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10769: $codebasecount ++;
10770: }
10771: }
10772: }
1.1075.2.35 raeburn 10773: my $skiprewrites;
1.987 raeburn 10774: if ($count || $codebasecount) {
10775: my $saveresult;
1.1071 raeburn 10776: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10777: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10778: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10779: if ($url eq $container) {
10780: my ($fname) = ($container =~ m{/([^/]+)$});
10781: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10782: $count,'<span class="LC_filename">'.
1.1071 raeburn 10783: $fname.'</span>').'</p>';
1.987 raeburn 10784: } else {
10785: $output = '<p class="LC_error">'.
10786: &mt('Error: update failed for: [_1].',
10787: '<span class="LC_filename">'.
10788: $container.'</span>').'</p>';
10789: }
1.1075.2.35 raeburn 10790: if ($context eq 'syllabus') {
10791: unless ($saveresult eq 'ok') {
10792: $skiprewrites = 1;
10793: }
10794: }
1.987 raeburn 10795: } else {
10796: if (open(my $fh,">$container")) {
10797: print $fh $content;
10798: close($fh);
10799: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10800: $count,'<span class="LC_filename">'.
10801: $container.'</span>').'</p>';
1.661 raeburn 10802: } else {
1.987 raeburn 10803: $output = '<p class="LC_error">'.
10804: &mt('Error: could not update [_1].',
10805: '<span class="LC_filename">'.
10806: $container.'</span>').'</p>';
1.661 raeburn 10807: }
10808: }
10809: }
1.1075.2.35 raeburn 10810: if (($context eq 'syllabus') && (!$skiprewrites)) {
10811: my ($actionurl,$state);
10812: $actionurl = "/public/$udom/$uname/syllabus";
10813: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10814: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10815: \%codebase,
10816: {'context' => 'rewrites',
10817: 'ignore_remote_references' => 1,});
10818: if (ref($mapping) eq 'HASH') {
10819: my $rewrites = 0;
10820: foreach my $key (keys(%{$mapping})) {
10821: next if ($key =~ m{^https?://});
10822: my $ref = $mapping->{$key};
10823: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10824: my $attrib;
10825: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10826: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10827: }
10828: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10829: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10830: $rewrites += $numchg;
10831: }
10832: }
10833: if ($rewrites) {
10834: my $saveresult;
10835: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10836: if ($url eq $container) {
10837: my ($fname) = ($container =~ m{/([^/]+)$});
10838: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10839: $count,'<span class="LC_filename">'.
10840: $fname.'</span>').'</p>';
10841: } else {
10842: $output .= '<p class="LC_error">'.
10843: &mt('Error: could not update links in [_1].',
10844: '<span class="LC_filename">'.
10845: $container.'</span>').'</p>';
10846:
10847: }
10848: }
10849: }
10850: }
1.987 raeburn 10851: } else {
10852: &logthis('Failed to parse '.$container.
10853: ' to modify references: '.$parse_result);
1.661 raeburn 10854: }
10855: }
1.1071 raeburn 10856: if (wantarray) {
10857: return ($output,$count,$codebasecount);
10858: } else {
10859: return $output;
10860: }
1.661 raeburn 10861: }
10862:
10863: sub check_for_existing {
10864: my ($path,$fname,$element) = @_;
10865: my ($state,$msg);
10866: if (-d $path.'/'.$fname) {
10867: $state = 'exists';
10868: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10869: } elsif (-e $path.'/'.$fname) {
10870: $state = 'exists';
10871: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10872: }
10873: if ($state eq 'exists') {
10874: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10875: }
10876: return ($state,$msg);
10877: }
10878:
10879: sub check_for_upload {
10880: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10881: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10882: my $filesize = length($env{'form.'.$element});
10883: if (!$filesize) {
10884: my $msg = '<span class="LC_error">'.
10885: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10886: '<span class="LC_filename">'.$fname.'</span>',
10887: $filesize).'<br />'.
1.1007 raeburn 10888: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10889: '</span>';
10890: return ('zero_bytes',$msg);
10891: }
10892: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10893: my $getpropath = 1;
1.1021 raeburn 10894: my ($dirlistref,$listerror) =
10895: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10896: my $found_file = 0;
10897: my $locked_file = 0;
1.991 raeburn 10898: my @lockers;
10899: my $navmap;
10900: if ($env{'request.course.id'}) {
10901: $navmap = Apache::lonnavmaps::navmap->new();
10902: }
1.1021 raeburn 10903: if (ref($dirlistref) eq 'ARRAY') {
10904: foreach my $line (@{$dirlistref}) {
10905: my ($file_name,$rest)=split(/\&/,$line,2);
10906: if ($file_name eq $fname){
10907: $file_name = $path.$file_name;
10908: if ($group ne '') {
10909: $file_name = $group.$file_name;
10910: }
10911: $found_file = 1;
10912: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10913: foreach my $lock (@lockers) {
10914: if (ref($lock) eq 'ARRAY') {
10915: my ($symb,$crsid) = @{$lock};
10916: if ($crsid eq $env{'request.course.id'}) {
10917: if (ref($navmap)) {
10918: my $res = $navmap->getBySymb($symb);
10919: foreach my $part (@{$res->parts()}) {
10920: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10921: unless (($slot_status == $res->RESERVED) ||
10922: ($slot_status == $res->RESERVED_LOCATION)) {
10923: $locked_file = 1;
10924: }
1.991 raeburn 10925: }
1.1021 raeburn 10926: } else {
10927: $locked_file = 1;
1.991 raeburn 10928: }
10929: } else {
10930: $locked_file = 1;
10931: }
10932: }
1.1021 raeburn 10933: }
10934: } else {
10935: my @info = split(/\&/,$rest);
10936: my $currsize = $info[6]/1000;
10937: if ($currsize < $filesize) {
10938: my $extra = $filesize - $currsize;
10939: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 10940: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 10941: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.',
1.1075.2.69 raeburn 10942: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
10943: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10944: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 10945: return ('will_exceed_quota',$msg);
10946: }
1.984 raeburn 10947: }
10948: }
1.661 raeburn 10949: }
10950: }
10951: }
10952: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 10953: my $msg = '<p class="LC_warning">'.
10954: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
10955: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 10956: return ('will_exceed_quota',$msg);
10957: } elsif ($found_file) {
10958: if ($locked_file) {
1.1075.2.69 raeburn 10959: my $msg = '<p class="LC_warning">';
1.661 raeburn 10960: $msg .= &mt('Unable to upload [_1]. A locked file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>','<span class="LC_filename">'.$port_path.$env{'form.currentpath'}.'</span>');
1.1075.2.69 raeburn 10961: $msg .= '</p>';
1.661 raeburn 10962: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10963: return ('file_locked',$msg);
10964: } else {
1.1075.2.69 raeburn 10965: my $msg = '<p class="LC_error">';
1.984 raeburn 10966: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.1075.2.69 raeburn 10967: $msg .= '</p>';
1.984 raeburn 10968: return ('existingfile',$msg);
1.661 raeburn 10969: }
10970: }
10971: }
10972:
1.987 raeburn 10973: sub check_for_traversal {
10974: my ($path,$url,$toplevel) = @_;
10975: my @parts=split(/\//,$path);
10976: my $cleanpath;
10977: my $fullpath = $url;
10978: for (my $i=0;$i<@parts;$i++) {
10979: next if ($parts[$i] eq '.');
10980: if ($parts[$i] eq '..') {
10981: $fullpath =~ s{([^/]+/)$}{};
10982: } else {
10983: $fullpath .= $parts[$i].'/';
10984: }
10985: }
10986: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10987: $cleanpath = $1;
10988: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10989: my $curr_toprel = $1;
10990: my @parts = split(/\//,$curr_toprel);
10991: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10992: my @urlparts = split(/\//,$url_toprel);
10993: my $doubledots;
10994: my $startdiff = -1;
10995: for (my $i=0; $i<@urlparts; $i++) {
10996: if ($startdiff == -1) {
10997: unless ($urlparts[$i] eq $parts[$i]) {
10998: $startdiff = $i;
10999: $doubledots .= '../';
11000: }
11001: } else {
11002: $doubledots .= '../';
11003: }
11004: }
11005: if ($startdiff > -1) {
11006: $cleanpath = $doubledots;
11007: for (my $i=$startdiff; $i<@parts; $i++) {
11008: $cleanpath .= $parts[$i].'/';
11009: }
11010: }
11011: }
11012: $cleanpath =~ s{(/)$}{};
11013: return $cleanpath;
11014: }
1.31 albertel 11015:
1.1053 raeburn 11016: sub is_archive_file {
11017: my ($mimetype) = @_;
11018: if (($mimetype eq 'application/octet-stream') ||
11019: ($mimetype eq 'application/x-stuffit') ||
11020: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11021: return 1;
11022: }
11023: return;
11024: }
11025:
11026: sub decompress_form {
1.1065 raeburn 11027: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11028: my %lt = &Apache::lonlocal::texthash (
11029: this => 'This file is an archive file.',
1.1067 raeburn 11030: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11031: itsc => 'Its contents are as follows:',
1.1053 raeburn 11032: youm => 'You may wish to extract its contents.',
11033: extr => 'Extract contents',
1.1067 raeburn 11034: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11035: proa => 'Process automatically?',
1.1053 raeburn 11036: yes => 'Yes',
11037: no => 'No',
1.1067 raeburn 11038: fold => 'Title for folder containing movie',
11039: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11040: );
1.1065 raeburn 11041: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11042: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11043: my $info = &list_archive_contents($fileloc,\@paths);
11044: if (@paths) {
11045: foreach my $path (@paths) {
11046: $path =~ s{^/}{};
1.1067 raeburn 11047: if ($path =~ m{^([^/]+)/$}) {
11048: $topdir = $1;
11049: }
1.1065 raeburn 11050: if ($path =~ m{^([^/]+)/}) {
11051: $toplevel{$1} = $path;
11052: } else {
11053: $toplevel{$path} = $path;
11054: }
11055: }
11056: }
1.1067 raeburn 11057: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11058: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11059: "$topdir/media/",
11060: "$topdir/media/$topdir.mp4",
11061: "$topdir/media/FirstFrame.png",
11062: "$topdir/media/player.swf",
11063: "$topdir/media/swfobject.js",
11064: "$topdir/media/expressInstall.swf");
1.1075.2.59 raeburn 11065: my @camtasia8 = ("$topdir/","$topdir/$topdir.html",
11066: "$topdir/$topdir.mp4",
11067: "$topdir/$topdir\_config.xml",
11068: "$topdir/$topdir\_controller.swf",
11069: "$topdir/$topdir\_embed.css",
11070: "$topdir/$topdir\_First_Frame.png",
11071: "$topdir/$topdir\_player.html",
11072: "$topdir/$topdir\_Thumbnails.png",
11073: "$topdir/playerProductInstall.swf",
11074: "$topdir/scripts/",
11075: "$topdir/scripts/config_xml.js",
11076: "$topdir/scripts/handlebars.js",
11077: "$topdir/scripts/jquery-1.7.1.min.js",
11078: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11079: "$topdir/scripts/modernizr.js",
11080: "$topdir/scripts/player-min.js",
11081: "$topdir/scripts/swfobject.js",
11082: "$topdir/skins/",
11083: "$topdir/skins/configuration_express.xml",
11084: "$topdir/skins/express_show/",
11085: "$topdir/skins/express_show/player-min.css",
11086: "$topdir/skins/express_show/spritesheet.png");
11087: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11088: if (@diffs == 0) {
1.1075.2.59 raeburn 11089: $is_camtasia = 6;
11090: } else {
11091: @diffs = &compare_arrays(\@paths,\@camtasia8);
11092: if (@diffs == 0) {
11093: $is_camtasia = 8;
11094: }
1.1067 raeburn 11095: }
11096: }
11097: my $output;
11098: if ($is_camtasia) {
11099: $output = <<"ENDCAM";
11100: <script type="text/javascript" language="Javascript">
11101: // <![CDATA[
11102:
11103: function camtasiaToggle() {
11104: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11105: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11106: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11107: document.getElementById('camtasia_titles').style.display='block';
11108: } else {
11109: document.getElementById('camtasia_titles').style.display='none';
11110: }
11111: }
11112: }
11113: return;
11114: }
11115:
11116: // ]]>
11117: </script>
11118: <p>$lt{'camt'}</p>
11119: ENDCAM
1.1065 raeburn 11120: } else {
1.1067 raeburn 11121: $output = '<p>'.$lt{'this'};
11122: if ($info eq '') {
11123: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11124: } else {
11125: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11126: '<div><pre>'.$info.'</pre></div>';
11127: }
1.1065 raeburn 11128: }
1.1067 raeburn 11129: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11130: my $duplicates;
11131: my $num = 0;
11132: if (ref($dirlist) eq 'ARRAY') {
11133: foreach my $item (@{$dirlist}) {
11134: if (ref($item) eq 'ARRAY') {
11135: if (exists($toplevel{$item->[0]})) {
11136: $duplicates .=
11137: &start_data_table_row().
11138: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11139: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11140: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11141: 'value="1" />'.&mt('Yes').'</label>'.
11142: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11143: '<td>'.$item->[0].'</td>';
11144: if ($item->[2]) {
11145: $duplicates .= '<td>'.&mt('Directory').'</td>';
11146: } else {
11147: $duplicates .= '<td>'.&mt('File').'</td>';
11148: }
11149: $duplicates .= '<td>'.$item->[3].'</td>'.
11150: '<td>'.
11151: &Apache::lonlocal::locallocaltime($item->[4]).
11152: '</td>'.
11153: &end_data_table_row();
11154: $num ++;
11155: }
11156: }
11157: }
11158: }
11159: my $itemcount;
11160: if (@paths > 0) {
11161: $itemcount = scalar(@paths);
11162: } else {
11163: $itemcount = 1;
11164: }
1.1067 raeburn 11165: if ($is_camtasia) {
11166: $output .= $lt{'auto'}.'<br />'.
11167: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 11168: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11169: $lt{'yes'}.'</label> <label>'.
11170: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11171: $lt{'no'}.'</label></span><br />'.
11172: '<div id="camtasia_titles" style="display:block">'.
11173: &Apache::lonhtmlcommon::start_pick_box().
11174: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11175: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11176: &Apache::lonhtmlcommon::row_closure().
11177: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11178: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11179: &Apache::lonhtmlcommon::row_closure(1).
11180: &Apache::lonhtmlcommon::end_pick_box().
11181: '</div>';
11182: }
1.1065 raeburn 11183: $output .=
11184: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11185: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11186: "\n";
1.1065 raeburn 11187: if ($duplicates ne '') {
11188: $output .= '<p><span class="LC_warning">'.
11189: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11190: &start_data_table().
11191: &start_data_table_header_row().
11192: '<th>'.&mt('Overwrite?').'</th>'.
11193: '<th>'.&mt('Name').'</th>'.
11194: '<th>'.&mt('Type').'</th>'.
11195: '<th>'.&mt('Size').'</th>'.
11196: '<th>'.&mt('Last modified').'</th>'.
11197: &end_data_table_header_row().
11198: $duplicates.
11199: &end_data_table().
11200: '</p>';
11201: }
1.1067 raeburn 11202: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11203: if (ref($hiddenelements) eq 'HASH') {
11204: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11205: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11206: }
11207: }
11208: $output .= <<"END";
1.1067 raeburn 11209: <br />
1.1053 raeburn 11210: <input type="submit" name="decompress" value="$lt{'extr'}" />
11211: </form>
11212: $noextract
11213: END
11214: return $output;
11215: }
11216:
1.1065 raeburn 11217: sub decompression_utility {
11218: my ($program) = @_;
11219: my @utilities = ('tar','gunzip','bunzip2','unzip');
11220: my $location;
11221: if (grep(/^\Q$program\E$/,@utilities)) {
11222: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11223: '/usr/sbin/') {
11224: if (-x $dir.$program) {
11225: $location = $dir.$program;
11226: last;
11227: }
11228: }
11229: }
11230: return $location;
11231: }
11232:
11233: sub list_archive_contents {
11234: my ($file,$pathsref) = @_;
11235: my (@cmd,$output);
11236: my $needsregexp;
11237: if ($file =~ /\.zip$/) {
11238: @cmd = (&decompression_utility('unzip'),"-l");
11239: $needsregexp = 1;
11240: } elsif (($file =~ m/\.tar\.gz$/) ||
11241: ($file =~ /\.tgz$/)) {
11242: @cmd = (&decompression_utility('tar'),"-ztf");
11243: } elsif ($file =~ /\.tar\.bz2$/) {
11244: @cmd = (&decompression_utility('tar'),"-jtf");
11245: } elsif ($file =~ m|\.tar$|) {
11246: @cmd = (&decompression_utility('tar'),"-tf");
11247: }
11248: if (@cmd) {
11249: undef($!);
11250: undef($@);
11251: if (open(my $fh,"-|", @cmd, $file)) {
11252: while (my $line = <$fh>) {
11253: $output .= $line;
11254: chomp($line);
11255: my $item;
11256: if ($needsregexp) {
11257: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11258: } else {
11259: $item = $line;
11260: }
11261: if ($item ne '') {
11262: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11263: push(@{$pathsref},$item);
11264: }
11265: }
11266: }
11267: close($fh);
11268: }
11269: }
11270: return $output;
11271: }
11272:
1.1053 raeburn 11273: sub decompress_uploaded_file {
11274: my ($file,$dir) = @_;
11275: &Apache::lonnet::appenv({'cgi.file' => $file});
11276: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11277: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11278: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11279: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11280: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11281: my $decompressed = $env{'cgi.decompressed'};
11282: &Apache::lonnet::delenv('cgi.file');
11283: &Apache::lonnet::delenv('cgi.dir');
11284: &Apache::lonnet::delenv('cgi.decompressed');
11285: return ($decompressed,$result);
11286: }
11287:
1.1055 raeburn 11288: sub process_decompression {
11289: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11290: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 11291: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 11292: $error = &mt('Filename not a supported archive file type.').
11293: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11294: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11295: } else {
11296: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11297: if ($docuhome eq 'no_host') {
11298: $error = &mt('Could not determine home server for course.');
11299: } else {
11300: my @ids=&Apache::lonnet::current_machine_ids();
11301: my $currdir = "$dir_root/$destination";
11302: if (grep(/^\Q$docuhome\E$/,@ids)) {
11303: $dir = &LONCAPA::propath($docudom,$docuname).
11304: "$dir_root/$destination";
11305: } else {
11306: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11307: "$dir_root/$docudom/$docuname/$destination";
11308: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11309: $error = &mt('Archive file not found.');
11310: }
11311: }
1.1065 raeburn 11312: my (@to_overwrite,@to_skip);
11313: if ($env{'form.archive_overwrite_total'} > 0) {
11314: my $total = $env{'form.archive_overwrite_total'};
11315: for (my $i=0; $i<$total; $i++) {
11316: if ($env{'form.archive_overwrite_'.$i} == 1) {
11317: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11318: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11319: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11320: }
11321: }
11322: }
11323: my $numskip = scalar(@to_skip);
11324: if (($numskip > 0) &&
11325: ($numskip == $env{'form.archive_itemcount'})) {
11326: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11327: } elsif ($dir eq '') {
1.1055 raeburn 11328: $error = &mt('Directory containing archive file unavailable.');
11329: } elsif (!$error) {
1.1065 raeburn 11330: my ($decompressed,$display);
11331: if ($numskip > 0) {
11332: my $tempdir = time.'_'.$$.int(rand(10000));
11333: mkdir("$dir/$tempdir",0755);
11334: system("mv $dir/$file $dir/$tempdir/$file");
11335: ($decompressed,$display) =
11336: &decompress_uploaded_file($file,"$dir/$tempdir");
11337: foreach my $item (@to_skip) {
11338: if (($item ne '') && ($item !~ /\.\./)) {
11339: if (-f "$dir/$tempdir/$item") {
11340: unlink("$dir/$tempdir/$item");
11341: } elsif (-d "$dir/$tempdir/$item") {
11342: system("rm -rf $dir/$tempdir/$item");
11343: }
11344: }
11345: }
11346: system("mv $dir/$tempdir/* $dir");
11347: rmdir("$dir/$tempdir");
11348: } else {
11349: ($decompressed,$display) =
11350: &decompress_uploaded_file($file,$dir);
11351: }
1.1055 raeburn 11352: if ($decompressed eq 'ok') {
1.1065 raeburn 11353: $output = '<p class="LC_info">'.
11354: &mt('Files extracted successfully from archive.').
11355: '</p>'."\n";
1.1055 raeburn 11356: my ($warning,$result,@contents);
11357: my ($newdirlistref,$newlisterror) =
11358: &Apache::lonnet::dirlist($currdir,$docudom,
11359: $docuname,1);
11360: my (%is_dir,%changes,@newitems);
11361: my $dirptr = 16384;
1.1065 raeburn 11362: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11363: foreach my $dir_line (@{$newdirlistref}) {
11364: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11365: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11366: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11367: push(@newitems,$item);
11368: if ($dirptr&$testdir) {
11369: $is_dir{$item} = 1;
11370: }
11371: $changes{$item} = 1;
11372: }
11373: }
11374: }
11375: if (keys(%changes) > 0) {
11376: foreach my $item (sort(@newitems)) {
11377: if ($changes{$item}) {
11378: push(@contents,$item);
11379: }
11380: }
11381: }
11382: if (@contents > 0) {
1.1067 raeburn 11383: my $wantform;
11384: unless ($env{'form.autoextract_camtasia'}) {
11385: $wantform = 1;
11386: }
1.1056 raeburn 11387: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11388: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11389: $currdir,\%is_dir,
11390: \%children,\%parent,
1.1056 raeburn 11391: \@contents,\%dirorder,
11392: \%titles,$wantform);
1.1055 raeburn 11393: if ($datatable ne '') {
11394: $output .= &archive_options_form('decompressed',$datatable,
11395: $count,$hiddenelem);
1.1065 raeburn 11396: my $startcount = 6;
1.1055 raeburn 11397: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11398: \%titles,\%children);
1.1055 raeburn 11399: }
1.1067 raeburn 11400: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 11401: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 11402: my %displayed;
11403: my $total = 1;
11404: $env{'form.archive_directory'} = [];
11405: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11406: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11407: $path =~ s{/$}{};
11408: my $item;
11409: if ($path ne '') {
11410: $item = "$path/$titles{$i}";
11411: } else {
11412: $item = $titles{$i};
11413: }
11414: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11415: if ($item eq $contents[0]) {
11416: push(@{$env{'form.archive_directory'}},$i);
11417: $env{'form.archive_'.$i} = 'display';
11418: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11419: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 11420: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
11421: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 11422: $env{'form.archive_'.$i} = 'display';
11423: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11424: $displayed{'web'} = $i;
11425: } else {
1.1075.2.59 raeburn 11426: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
11427: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
11428: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 11429: push(@{$env{'form.archive_directory'}},$i);
11430: }
11431: $env{'form.archive_'.$i} = 'dependency';
11432: }
11433: $total ++;
11434: }
11435: for (my $i=1; $i<$total; $i++) {
11436: next if ($i == $displayed{'web'});
11437: next if ($i == $displayed{'folder'});
11438: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11439: }
11440: $env{'form.phase'} = 'decompress_cleanup';
11441: $env{'form.archivedelete'} = 1;
11442: $env{'form.archive_count'} = $total-1;
11443: $output .=
11444: &process_extracted_files('coursedocs',$docudom,
11445: $docuname,$destination,
11446: $dir_root,$hiddenelem);
11447: }
1.1055 raeburn 11448: } else {
11449: $warning = &mt('No new items extracted from archive file.');
11450: }
11451: } else {
11452: $output = $display;
11453: $error = &mt('An error occurred during extraction from the archive file.');
11454: }
11455: }
11456: }
11457: }
11458: if ($error) {
11459: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11460: $error.'</p>'."\n";
11461: }
11462: if ($warning) {
11463: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11464: }
11465: return $output;
11466: }
11467:
11468: sub get_extracted {
1.1056 raeburn 11469: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11470: $titles,$wantform) = @_;
1.1055 raeburn 11471: my $count = 0;
11472: my $depth = 0;
11473: my $datatable;
1.1056 raeburn 11474: my @hierarchy;
1.1055 raeburn 11475: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11476: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11477: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11478: foreach my $item (@{$contents}) {
11479: $count ++;
1.1056 raeburn 11480: @{$dirorder->{$count}} = @hierarchy;
11481: $titles->{$count} = $item;
1.1055 raeburn 11482: &archive_hierarchy($depth,$count,$parent,$children);
11483: if ($wantform) {
11484: $datatable .= &archive_row($is_dir->{$item},$item,
11485: $currdir,$depth,$count);
11486: }
11487: if ($is_dir->{$item}) {
11488: $depth ++;
1.1056 raeburn 11489: push(@hierarchy,$count);
11490: $parent->{$depth} = $count;
1.1055 raeburn 11491: $datatable .=
11492: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11493: \$depth,\$count,\@hierarchy,$dirorder,
11494: $children,$parent,$titles,$wantform);
1.1055 raeburn 11495: $depth --;
1.1056 raeburn 11496: pop(@hierarchy);
1.1055 raeburn 11497: }
11498: }
11499: return ($count,$datatable);
11500: }
11501:
11502: sub recurse_extracted_archive {
1.1056 raeburn 11503: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11504: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11505: my $result='';
1.1056 raeburn 11506: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11507: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11508: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11509: return $result;
11510: }
11511: my $dirptr = 16384;
11512: my ($newdirlistref,$newlisterror) =
11513: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11514: if (ref($newdirlistref) eq 'ARRAY') {
11515: foreach my $dir_line (@{$newdirlistref}) {
11516: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11517: unless ($item =~ /^\.+$/) {
11518: $$count ++;
1.1056 raeburn 11519: @{$dirorder->{$$count}} = @{$hierarchy};
11520: $titles->{$$count} = $item;
1.1055 raeburn 11521: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11522:
1.1055 raeburn 11523: my $is_dir;
11524: if ($dirptr&$testdir) {
11525: $is_dir = 1;
11526: }
11527: if ($wantform) {
11528: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11529: }
11530: if ($is_dir) {
11531: $$depth ++;
1.1056 raeburn 11532: push(@{$hierarchy},$$count);
11533: $parent->{$$depth} = $$count;
1.1055 raeburn 11534: $result .=
11535: &recurse_extracted_archive("$currdir/$item",$docudom,
11536: $docuname,$depth,$count,
1.1056 raeburn 11537: $hierarchy,$dirorder,$children,
11538: $parent,$titles,$wantform);
1.1055 raeburn 11539: $$depth --;
1.1056 raeburn 11540: pop(@{$hierarchy});
1.1055 raeburn 11541: }
11542: }
11543: }
11544: }
11545: return $result;
11546: }
11547:
11548: sub archive_hierarchy {
11549: my ($depth,$count,$parent,$children) =@_;
11550: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11551: if (exists($parent->{$depth})) {
11552: $children->{$parent->{$depth}} .= $count.':';
11553: }
11554: }
11555: return;
11556: }
11557:
11558: sub archive_row {
11559: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11560: my ($name) = ($item =~ m{([^/]+)$});
11561: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11562: 'display' => 'Add as file',
1.1055 raeburn 11563: 'dependency' => 'Include as dependency',
11564: 'discard' => 'Discard',
11565: );
11566: if ($is_dir) {
1.1059 raeburn 11567: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11568: }
1.1056 raeburn 11569: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11570: my $offset = 0;
1.1055 raeburn 11571: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11572: $offset ++;
1.1065 raeburn 11573: if ($action ne 'display') {
11574: $offset ++;
11575: }
1.1055 raeburn 11576: $output .= '<td><span class="LC_nobreak">'.
11577: '<label><input type="radio" name="archive_'.$count.
11578: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11579: my $text = $choices{$action};
11580: if ($is_dir) {
11581: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11582: if ($action eq 'display') {
1.1059 raeburn 11583: $text = &mt('Add as folder');
1.1055 raeburn 11584: }
1.1056 raeburn 11585: } else {
11586: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11587:
11588: }
11589: $output .= ' /> '.$choices{$action}.'</label></span>';
11590: if ($action eq 'dependency') {
11591: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11592: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11593: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11594: '<option value=""></option>'."\n".
11595: '</select>'."\n".
11596: '</div>';
1.1059 raeburn 11597: } elsif ($action eq 'display') {
11598: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11599: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11600: '</div>';
1.1055 raeburn 11601: }
1.1056 raeburn 11602: $output .= '</td>';
1.1055 raeburn 11603: }
11604: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11605: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11606: for (my $i=0; $i<$depth; $i++) {
11607: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11608: }
11609: if ($is_dir) {
11610: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11611: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11612: } else {
11613: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11614: }
11615: $output .= ' '.$name.'</td>'."\n".
11616: &end_data_table_row();
11617: return $output;
11618: }
11619:
11620: sub archive_options_form {
1.1065 raeburn 11621: my ($form,$display,$count,$hiddenelem) = @_;
11622: my %lt = &Apache::lonlocal::texthash(
11623: perm => 'Permanently remove archive file?',
11624: hows => 'How should each extracted item be incorporated in the course?',
11625: cont => 'Content actions for all',
11626: addf => 'Add as folder/file',
11627: incd => 'Include as dependency for a displayed file',
11628: disc => 'Discard',
11629: no => 'No',
11630: yes => 'Yes',
11631: save => 'Save',
11632: );
11633: my $output = <<"END";
11634: <form name="$form" method="post" action="">
11635: <p><span class="LC_nobreak">$lt{'perm'}
11636: <label>
11637: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11638: </label>
11639:
11640: <label>
11641: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11642: </span>
11643: </p>
11644: <input type="hidden" name="phase" value="decompress_cleanup" />
11645: <br />$lt{'hows'}
11646: <div class="LC_columnSection">
11647: <fieldset>
11648: <legend>$lt{'cont'}</legend>
11649: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11650: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11651: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11652: </fieldset>
11653: </div>
11654: END
11655: return $output.
1.1055 raeburn 11656: &start_data_table()."\n".
1.1065 raeburn 11657: $display."\n".
1.1055 raeburn 11658: &end_data_table()."\n".
11659: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11660: $hiddenelem.
1.1065 raeburn 11661: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11662: '</form>';
11663: }
11664:
11665: sub archive_javascript {
1.1056 raeburn 11666: my ($startcount,$numitems,$titles,$children) = @_;
11667: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11668: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11669: my $scripttag = <<START;
11670: <script type="text/javascript">
11671: // <![CDATA[
11672:
11673: function checkAll(form,prefix) {
11674: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11675: for (var i=0; i < form.elements.length; i++) {
11676: var id = form.elements[i].id;
11677: if ((id != '') && (id != undefined)) {
11678: if (idstr.test(id)) {
11679: if (form.elements[i].type == 'radio') {
11680: form.elements[i].checked = true;
1.1056 raeburn 11681: var nostart = i-$startcount;
1.1059 raeburn 11682: var offset = nostart%7;
11683: var count = (nostart-offset)/7;
1.1056 raeburn 11684: dependencyCheck(form,count,offset);
1.1055 raeburn 11685: }
11686: }
11687: }
11688: }
11689: }
11690:
11691: function propagateCheck(form,count) {
11692: if (count > 0) {
1.1059 raeburn 11693: var startelement = $startcount + ((count-1) * 7);
11694: for (var j=1; j<6; j++) {
11695: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11696: var item = startelement + j;
11697: if (form.elements[item].type == 'radio') {
11698: if (form.elements[item].checked) {
11699: containerCheck(form,count,j);
11700: break;
11701: }
1.1055 raeburn 11702: }
11703: }
11704: }
11705: }
11706: }
11707:
11708: numitems = $numitems
1.1056 raeburn 11709: var titles = new Array(numitems);
11710: var parents = new Array(numitems);
1.1055 raeburn 11711: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11712: parents[i] = new Array;
1.1055 raeburn 11713: }
1.1059 raeburn 11714: var maintitle = '$maintitle';
1.1055 raeburn 11715:
11716: START
11717:
1.1056 raeburn 11718: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11719: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11720: for (my $i=0; $i<@contents; $i ++) {
11721: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11722: }
11723: }
11724:
1.1056 raeburn 11725: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11726: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11727: }
11728:
1.1055 raeburn 11729: $scripttag .= <<END;
11730:
11731: function containerCheck(form,count,offset) {
11732: if (count > 0) {
1.1056 raeburn 11733: dependencyCheck(form,count,offset);
1.1059 raeburn 11734: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11735: form.elements[item].checked = true;
11736: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11737: if (parents[count].length > 0) {
11738: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11739: containerCheck(form,parents[count][j],offset);
11740: }
11741: }
11742: }
11743: }
11744: }
11745:
11746: function dependencyCheck(form,count,offset) {
11747: if (count > 0) {
1.1059 raeburn 11748: var chosen = (offset+$startcount)+7*(count-1);
11749: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11750: var currtype = form.elements[depitem].type;
11751: if (form.elements[chosen].value == 'dependency') {
11752: document.getElementById('arc_depon_'+count).style.display='block';
11753: form.elements[depitem].options.length = 0;
11754: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 11755: for (var i=1; i<=numitems; i++) {
11756: if (i == count) {
11757: continue;
11758: }
1.1059 raeburn 11759: var startelement = $startcount + (i-1) * 7;
11760: for (var j=1; j<6; j++) {
11761: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11762: var item = startelement + j;
11763: if (form.elements[item].type == 'radio') {
11764: if (form.elements[item].checked) {
11765: if (form.elements[item].value == 'display') {
11766: var n = form.elements[depitem].options.length;
11767: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11768: }
11769: }
11770: }
11771: }
11772: }
11773: }
11774: } else {
11775: document.getElementById('arc_depon_'+count).style.display='none';
11776: form.elements[depitem].options.length = 0;
11777: form.elements[depitem].options[0] = new Option('Select','',true,true);
11778: }
1.1059 raeburn 11779: titleCheck(form,count,offset);
1.1056 raeburn 11780: }
11781: }
11782:
11783: function propagateSelect(form,count,offset) {
11784: if (count > 0) {
1.1065 raeburn 11785: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11786: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11787: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11788: if (parents[count].length > 0) {
11789: for (var j=0; j<parents[count].length; j++) {
11790: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11791: }
11792: }
11793: }
11794: }
11795: }
1.1056 raeburn 11796:
11797: function containerSelect(form,count,offset,picked) {
11798: if (count > 0) {
1.1065 raeburn 11799: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11800: if (form.elements[item].type == 'radio') {
11801: if (form.elements[item].value == 'dependency') {
11802: if (form.elements[item+1].type == 'select-one') {
11803: for (var i=0; i<form.elements[item+1].options.length; i++) {
11804: if (form.elements[item+1].options[i].value == picked) {
11805: form.elements[item+1].selectedIndex = i;
11806: break;
11807: }
11808: }
11809: }
11810: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11811: if (parents[count].length > 0) {
11812: for (var j=0; j<parents[count].length; j++) {
11813: containerSelect(form,parents[count][j],offset,picked);
11814: }
11815: }
11816: }
11817: }
11818: }
11819: }
11820: }
11821:
1.1059 raeburn 11822: function titleCheck(form,count,offset) {
11823: if (count > 0) {
11824: var chosen = (offset+$startcount)+7*(count-1);
11825: var depitem = $startcount + ((count-1) * 7) + 2;
11826: var currtype = form.elements[depitem].type;
11827: if (form.elements[chosen].value == 'display') {
11828: document.getElementById('arc_title_'+count).style.display='block';
11829: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11830: document.getElementById('archive_title_'+count).value=maintitle;
11831: }
11832: } else {
11833: document.getElementById('arc_title_'+count).style.display='none';
11834: if (currtype == 'text') {
11835: document.getElementById('archive_title_'+count).value='';
11836: }
11837: }
11838: }
11839: return;
11840: }
11841:
1.1055 raeburn 11842: // ]]>
11843: </script>
11844: END
11845: return $scripttag;
11846: }
11847:
11848: sub process_extracted_files {
1.1067 raeburn 11849: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11850: my $numitems = $env{'form.archive_count'};
11851: return unless ($numitems);
11852: my @ids=&Apache::lonnet::current_machine_ids();
11853: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11854: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11855: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11856: if (grep(/^\Q$docuhome\E$/,@ids)) {
11857: $prefix = &LONCAPA::propath($docudom,$docuname);
11858: $pathtocheck = "$dir_root/$destination";
11859: $dir = $dir_root;
11860: $ishome = 1;
11861: } else {
11862: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11863: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11864: $dir = "$dir_root/$docudom/$docuname";
11865: }
11866: my $currdir = "$dir_root/$destination";
11867: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11868: if ($env{'form.folderpath'}) {
11869: my @items = split('&',$env{'form.folderpath'});
11870: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 11871: if ($env{'form.folderpath'} =~ /\:1$/) {
11872: $containers{'0'}='page';
11873: } else {
11874: $containers{'0'}='sequence';
11875: }
1.1055 raeburn 11876: }
11877: my @archdirs = &get_env_multiple('form.archive_directory');
11878: if ($numitems) {
11879: for (my $i=1; $i<=$numitems; $i++) {
11880: my $path = $env{'form.archive_content_'.$i};
11881: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11882: my $item = $1;
11883: $toplevelitems{$item} = $i;
11884: if (grep(/^\Q$i\E$/,@archdirs)) {
11885: $is_dir{$item} = 1;
11886: }
11887: }
11888: }
11889: }
1.1067 raeburn 11890: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11891: if (keys(%toplevelitems) > 0) {
11892: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11893: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11894: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11895: }
1.1066 raeburn 11896: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11897: if ($numitems) {
11898: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 11899: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11900: my $path = $env{'form.archive_content_'.$i};
11901: if ($path =~ /^\Q$pathtocheck\E/) {
11902: if ($env{'form.archive_'.$i} eq 'discard') {
11903: if ($prefix ne '' && $path ne '') {
11904: if (-e $prefix.$path) {
1.1066 raeburn 11905: if ((@archdirs > 0) &&
11906: (grep(/^\Q$i\E$/,@archdirs))) {
11907: $todeletedir{$prefix.$path} = 1;
11908: } else {
11909: $todelete{$prefix.$path} = 1;
11910: }
1.1055 raeburn 11911: }
11912: }
11913: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11914: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11915: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11916: $docstitle = $env{'form.archive_title_'.$i};
11917: if ($docstitle eq '') {
11918: $docstitle = $title;
11919: }
1.1055 raeburn 11920: $outer = 0;
1.1056 raeburn 11921: if (ref($dirorder{$i}) eq 'ARRAY') {
11922: if (@{$dirorder{$i}} > 0) {
11923: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11924: if ($env{'form.archive_'.$item} eq 'display') {
11925: $outer = $item;
11926: last;
11927: }
11928: }
11929: }
11930: }
11931: my ($errtext,$fatal) =
11932: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11933: '/'.$folders{$outer}.'.'.
11934: $containers{$outer});
11935: next if ($fatal);
11936: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11937: if ($context eq 'coursedocs') {
1.1056 raeburn 11938: $mapinner{$i} = time;
1.1055 raeburn 11939: $folders{$i} = 'default_'.$mapinner{$i};
11940: $containers{$i} = 'sequence';
11941: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11942: $folders{$i}.'.'.$containers{$i};
11943: my $newidx = &LONCAPA::map::getresidx();
11944: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11945: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11946: push(@LONCAPA::map::order,$newidx);
11947: my ($outtext,$errtext) =
11948: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11949: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11950: '.'.$containers{$outer},1,1);
1.1056 raeburn 11951: $newseqid{$i} = $newidx;
1.1067 raeburn 11952: unless ($errtext) {
11953: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11954: }
1.1055 raeburn 11955: }
11956: } else {
11957: if ($context eq 'coursedocs') {
11958: my $newidx=&LONCAPA::map::getresidx();
11959: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11960: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11961: $title;
11962: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11963: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11964: }
11965: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11966: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11967: }
11968: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11969: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11970: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11971: unless ($ishome) {
11972: my $fetch = "$newdest{$i}/$title";
11973: $fetch =~ s/^\Q$prefix$dir\E//;
11974: $prompttofetch{$fetch} = 1;
11975: }
1.1055 raeburn 11976: }
11977: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11978: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11979: push(@LONCAPA::map::order, $newidx);
11980: my ($outtext,$errtext)=
11981: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11982: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11983: '.'.$containers{$outer},1,1);
1.1067 raeburn 11984: unless ($errtext) {
11985: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11986: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11987: }
11988: }
1.1055 raeburn 11989: }
11990: }
1.1075.2.11 raeburn 11991: }
11992: } else {
11993: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11994: }
11995: }
11996: for (my $i=1; $i<=$numitems; $i++) {
11997: next unless ($env{'form.archive_'.$i} eq 'dependency');
11998: my $path = $env{'form.archive_content_'.$i};
11999: if ($path =~ /^\Q$pathtocheck\E/) {
12000: my ($title) = ($path =~ m{/([^/]+)$});
12001: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12002: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12003: if (ref($dirorder{$i}) eq 'ARRAY') {
12004: my ($itemidx,$fullpath,$relpath);
12005: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12006: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12007: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12008: if ($dirorder{$i}->[$j] eq $container) {
12009: $itemidx = $j;
1.1056 raeburn 12010: }
12011: }
1.1075.2.11 raeburn 12012: }
12013: if ($itemidx eq '') {
12014: $itemidx = 0;
12015: }
12016: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12017: if ($mapinner{$referrer{$i}}) {
12018: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12019: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12020: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12021: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12022: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12023: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12024: if (!-e $fullpath) {
12025: mkdir($fullpath,0755);
1.1056 raeburn 12026: }
12027: }
1.1075.2.11 raeburn 12028: } else {
12029: last;
1.1056 raeburn 12030: }
1.1075.2.11 raeburn 12031: }
12032: }
12033: } elsif ($newdest{$referrer{$i}}) {
12034: $fullpath = $newdest{$referrer{$i}};
12035: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12036: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12037: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12038: last;
12039: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12040: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12041: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12042: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12043: if (!-e $fullpath) {
12044: mkdir($fullpath,0755);
1.1056 raeburn 12045: }
12046: }
1.1075.2.11 raeburn 12047: } else {
12048: last;
1.1056 raeburn 12049: }
1.1075.2.11 raeburn 12050: }
12051: }
12052: if ($fullpath ne '') {
12053: if (-e "$prefix$path") {
12054: system("mv $prefix$path $fullpath/$title");
12055: }
12056: if (-e "$fullpath/$title") {
12057: my $showpath;
12058: if ($relpath ne '') {
12059: $showpath = "$relpath/$title";
12060: } else {
12061: $showpath = "/$title";
1.1056 raeburn 12062: }
1.1075.2.11 raeburn 12063: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12064: }
12065: unless ($ishome) {
12066: my $fetch = "$fullpath/$title";
12067: $fetch =~ s/^\Q$prefix$dir\E//;
12068: $prompttofetch{$fetch} = 1;
1.1055 raeburn 12069: }
12070: }
12071: }
1.1075.2.11 raeburn 12072: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12073: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12074: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12075: }
12076: } else {
1.1075.2.11 raeburn 12077: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 12078: }
12079: }
12080: if (keys(%todelete)) {
12081: foreach my $key (keys(%todelete)) {
12082: unlink($key);
1.1066 raeburn 12083: }
12084: }
12085: if (keys(%todeletedir)) {
12086: foreach my $key (keys(%todeletedir)) {
12087: rmdir($key);
12088: }
12089: }
12090: foreach my $dir (sort(keys(%is_dir))) {
12091: if (($pathtocheck ne '') && ($dir ne '')) {
12092: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12093: }
12094: }
1.1067 raeburn 12095: if ($result ne '') {
12096: $output .= '<ul>'."\n".
12097: $result."\n".
12098: '</ul>';
12099: }
12100: unless ($ishome) {
12101: my $replicationfail;
12102: foreach my $item (keys(%prompttofetch)) {
12103: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12104: unless ($fetchresult eq 'ok') {
12105: $replicationfail .= '<li>'.$item.'</li>'."\n";
12106: }
12107: }
12108: if ($replicationfail) {
12109: $output .= '<p class="LC_error">'.
12110: &mt('Course home server failed to retrieve:').'<ul>'.
12111: $replicationfail.
12112: '</ul></p>';
12113: }
12114: }
1.1055 raeburn 12115: } else {
12116: $warning = &mt('No items found in archive.');
12117: }
12118: if ($error) {
12119: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12120: $error.'</p>'."\n";
12121: }
12122: if ($warning) {
12123: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12124: }
12125: return $output;
12126: }
12127:
1.1066 raeburn 12128: sub cleanup_empty_dirs {
12129: my ($path) = @_;
12130: if (($path ne '') && (-d $path)) {
12131: if (opendir(my $dirh,$path)) {
12132: my @dircontents = grep(!/^\./,readdir($dirh));
12133: my $numitems = 0;
12134: foreach my $item (@dircontents) {
12135: if (-d "$path/$item") {
1.1075.2.28 raeburn 12136: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12137: if (-e "$path/$item") {
12138: $numitems ++;
12139: }
12140: } else {
12141: $numitems ++;
12142: }
12143: }
12144: if ($numitems == 0) {
12145: rmdir($path);
12146: }
12147: closedir($dirh);
12148: }
12149: }
12150: return;
12151: }
12152:
1.41 ng 12153: =pod
1.45 matthew 12154:
1.1075.2.56 raeburn 12155: =item * &get_folder_hierarchy()
1.1068 raeburn 12156:
12157: Provides hierarchy of names of folders/sub-folders containing the current
12158: item,
12159:
12160: Inputs: 3
12161: - $navmap - navmaps object
12162:
12163: - $map - url for map (either the trigger itself, or map containing
12164: the resource, which is the trigger).
12165:
12166: - $showitem - 1 => show title for map itself; 0 => do not show.
12167:
12168: Outputs: 1 @pathitems - array of folder/subfolder names.
12169:
12170: =cut
12171:
12172: sub get_folder_hierarchy {
12173: my ($navmap,$map,$showitem) = @_;
12174: my @pathitems;
12175: if (ref($navmap)) {
12176: my $mapres = $navmap->getResourceByUrl($map);
12177: if (ref($mapres)) {
12178: my $pcslist = $mapres->map_hierarchy();
12179: if ($pcslist ne '') {
12180: my @pcs = split(/,/,$pcslist);
12181: foreach my $pc (@pcs) {
12182: if ($pc == 1) {
1.1075.2.38 raeburn 12183: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12184: } else {
12185: my $res = $navmap->getByMapPc($pc);
12186: if (ref($res)) {
12187: my $title = $res->compTitle();
12188: $title =~ s/\W+/_/g;
12189: if ($title ne '') {
12190: push(@pathitems,$title);
12191: }
12192: }
12193: }
12194: }
12195: }
1.1071 raeburn 12196: if ($showitem) {
12197: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12198: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12199: } else {
12200: my $maptitle = $mapres->compTitle();
12201: $maptitle =~ s/\W+/_/g;
12202: if ($maptitle ne '') {
12203: push(@pathitems,$maptitle);
12204: }
1.1068 raeburn 12205: }
12206: }
12207: }
12208: }
12209: return @pathitems;
12210: }
12211:
12212: =pod
12213:
1.1015 raeburn 12214: =item * &get_turnedin_filepath()
12215:
12216: Determines path in a user's portfolio file for storage of files uploaded
12217: to a specific essayresponse or dropbox item.
12218:
12219: Inputs: 3 required + 1 optional.
12220: $symb is symb for resource, $uname and $udom are for current user (required).
12221: $caller is optional (can be "submission", if routine is called when storing
12222: an upoaded file when "Submit Answer" button was pressed).
12223:
12224: Returns array containing $path and $multiresp.
12225: $path is path in portfolio. $multiresp is 1 if this resource contains more
12226: than one file upload item. Callers of routine should append partid as a
12227: subdirectory to $path in cases where $multiresp is 1.
12228:
12229: Called by: homework/essayresponse.pm and homework/structuretags.pm
12230:
12231: =cut
12232:
12233: sub get_turnedin_filepath {
12234: my ($symb,$uname,$udom,$caller) = @_;
12235: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12236: my $turnindir;
12237: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12238: $turnindir = $userhash{'turnindir'};
12239: my ($path,$multiresp);
12240: if ($turnindir eq '') {
12241: if ($caller eq 'submission') {
12242: $turnindir = &mt('turned in');
12243: $turnindir =~ s/\W+/_/g;
12244: my %newhash = (
12245: 'turnindir' => $turnindir,
12246: );
12247: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12248: }
12249: }
12250: if ($turnindir ne '') {
12251: $path = '/'.$turnindir.'/';
12252: my ($multipart,$turnin,@pathitems);
12253: my $navmap = Apache::lonnavmaps::navmap->new();
12254: if (defined($navmap)) {
12255: my $mapres = $navmap->getResourceByUrl($map);
12256: if (ref($mapres)) {
12257: my $pcslist = $mapres->map_hierarchy();
12258: if ($pcslist ne '') {
12259: foreach my $pc (split(/,/,$pcslist)) {
12260: my $res = $navmap->getByMapPc($pc);
12261: if (ref($res)) {
12262: my $title = $res->compTitle();
12263: $title =~ s/\W+/_/g;
12264: if ($title ne '') {
1.1075.2.48 raeburn 12265: if (($pc > 1) && (length($title) > 12)) {
12266: $title = substr($title,0,12);
12267: }
1.1015 raeburn 12268: push(@pathitems,$title);
12269: }
12270: }
12271: }
12272: }
12273: my $maptitle = $mapres->compTitle();
12274: $maptitle =~ s/\W+/_/g;
12275: if ($maptitle ne '') {
1.1075.2.48 raeburn 12276: if (length($maptitle) > 12) {
12277: $maptitle = substr($maptitle,0,12);
12278: }
1.1015 raeburn 12279: push(@pathitems,$maptitle);
12280: }
12281: unless ($env{'request.state'} eq 'construct') {
12282: my $res = $navmap->getBySymb($symb);
12283: if (ref($res)) {
12284: my $partlist = $res->parts();
12285: my $totaluploads = 0;
12286: if (ref($partlist) eq 'ARRAY') {
12287: foreach my $part (@{$partlist}) {
12288: my @types = $res->responseType($part);
12289: my @ids = $res->responseIds($part);
12290: for (my $i=0; $i < scalar(@ids); $i++) {
12291: if ($types[$i] eq 'essay') {
12292: my $partid = $part.'_'.$ids[$i];
12293: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12294: $totaluploads ++;
12295: }
12296: }
12297: }
12298: }
12299: if ($totaluploads > 1) {
12300: $multiresp = 1;
12301: }
12302: }
12303: }
12304: }
12305: } else {
12306: return;
12307: }
12308: } else {
12309: return;
12310: }
12311: my $restitle=&Apache::lonnet::gettitle($symb);
12312: $restitle =~ s/\W+/_/g;
12313: if ($restitle eq '') {
12314: $restitle = ($resurl =~ m{/[^/]+$});
12315: if ($restitle eq '') {
12316: $restitle = time;
12317: }
12318: }
1.1075.2.48 raeburn 12319: if (length($restitle) > 12) {
12320: $restitle = substr($restitle,0,12);
12321: }
1.1015 raeburn 12322: push(@pathitems,$restitle);
12323: $path .= join('/',@pathitems);
12324: }
12325: return ($path,$multiresp);
12326: }
12327:
12328: =pod
12329:
1.464 albertel 12330: =back
1.41 ng 12331:
1.112 bowersj2 12332: =head1 CSV Upload/Handling functions
1.38 albertel 12333:
1.41 ng 12334: =over 4
12335:
1.648 raeburn 12336: =item * &upfile_store($r)
1.41 ng 12337:
12338: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12339: needs $env{'form.upfile'}
1.41 ng 12340: returns $datatoken to be put into hidden field
12341:
12342: =cut
1.31 albertel 12343:
12344: sub upfile_store {
12345: my $r=shift;
1.258 albertel 12346: $env{'form.upfile'}=~s/\r/\n/gs;
12347: $env{'form.upfile'}=~s/\f/\n/gs;
12348: $env{'form.upfile'}=~s/\n+/\n/gs;
12349: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12350:
1.258 albertel 12351: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12352: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12353: {
1.158 raeburn 12354: my $datafile = $r->dir_config('lonDaemons').
12355: '/tmp/'.$datatoken.'.tmp';
12356: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12357: print $fh $env{'form.upfile'};
1.158 raeburn 12358: close($fh);
12359: }
1.31 albertel 12360: }
12361: return $datatoken;
12362: }
12363:
1.56 matthew 12364: =pod
12365:
1.648 raeburn 12366: =item * &load_tmp_file($r)
1.41 ng 12367:
12368: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12369: needs $env{'form.datatoken'},
12370: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12371:
12372: =cut
1.31 albertel 12373:
12374: sub load_tmp_file {
12375: my $r=shift;
12376: my @studentdata=();
12377: {
1.158 raeburn 12378: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12379: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12380: if ( open(my $fh,"<$studentfile") ) {
12381: @studentdata=<$fh>;
12382: close($fh);
12383: }
1.31 albertel 12384: }
1.258 albertel 12385: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12386: }
12387:
1.56 matthew 12388: =pod
12389:
1.648 raeburn 12390: =item * &upfile_record_sep()
1.41 ng 12391:
12392: Separate uploaded file into records
12393: returns array of records,
1.258 albertel 12394: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12395:
12396: =cut
1.31 albertel 12397:
12398: sub upfile_record_sep {
1.258 albertel 12399: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12400: } else {
1.248 albertel 12401: my @records;
1.258 albertel 12402: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12403: if ($line=~/^\s*$/) { next; }
12404: push(@records,$line);
12405: }
12406: return @records;
1.31 albertel 12407: }
12408: }
12409:
1.56 matthew 12410: =pod
12411:
1.648 raeburn 12412: =item * &record_sep($record)
1.41 ng 12413:
1.258 albertel 12414: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12415:
12416: =cut
12417:
1.263 www 12418: sub takeleft {
12419: my $index=shift;
12420: return substr('0000'.$index,-4,4);
12421: }
12422:
1.31 albertel 12423: sub record_sep {
12424: my $record=shift;
12425: my %components=();
1.258 albertel 12426: if ($env{'form.upfiletype'} eq 'xml') {
12427: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12428: my $i=0;
1.356 albertel 12429: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12430: $field=~s/^(\"|\')//;
12431: $field=~s/(\"|\')$//;
1.263 www 12432: $components{&takeleft($i)}=$field;
1.31 albertel 12433: $i++;
12434: }
1.258 albertel 12435: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12436: my $i=0;
1.356 albertel 12437: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12438: $field=~s/^(\"|\')//;
12439: $field=~s/(\"|\')$//;
1.263 www 12440: $components{&takeleft($i)}=$field;
1.31 albertel 12441: $i++;
12442: }
12443: } else {
1.561 www 12444: my $separator=',';
1.480 banghart 12445: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12446: $separator=';';
1.480 banghart 12447: }
1.31 albertel 12448: my $i=0;
1.561 www 12449: # the character we are looking for to indicate the end of a quote or a record
12450: my $looking_for=$separator;
12451: # do not add the characters to the fields
12452: my $ignore=0;
12453: # we just encountered a separator (or the beginning of the record)
12454: my $just_found_separator=1;
12455: # store the field we are working on here
12456: my $field='';
12457: # work our way through all characters in record
12458: foreach my $character ($record=~/(.)/g) {
12459: if ($character eq $looking_for) {
12460: if ($character ne $separator) {
12461: # Found the end of a quote, again looking for separator
12462: $looking_for=$separator;
12463: $ignore=1;
12464: } else {
12465: # Found a separator, store away what we got
12466: $components{&takeleft($i)}=$field;
12467: $i++;
12468: $just_found_separator=1;
12469: $ignore=0;
12470: $field='';
12471: }
12472: next;
12473: }
12474: # single or double quotation marks after a separator indicate beginning of a quote
12475: # we are now looking for the end of the quote and need to ignore separators
12476: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12477: $looking_for=$character;
12478: next;
12479: }
12480: # ignore would be true after we reached the end of a quote
12481: if ($ignore) { next; }
12482: if (($just_found_separator) && ($character=~/\s/)) { next; }
12483: $field.=$character;
12484: $just_found_separator=0;
1.31 albertel 12485: }
1.561 www 12486: # catch the very last entry, since we never encountered the separator
12487: $components{&takeleft($i)}=$field;
1.31 albertel 12488: }
12489: return %components;
12490: }
12491:
1.144 matthew 12492: ######################################################
12493: ######################################################
12494:
1.56 matthew 12495: =pod
12496:
1.648 raeburn 12497: =item * &upfile_select_html()
1.41 ng 12498:
1.144 matthew 12499: Return HTML code to select a file from the users machine and specify
12500: the file type.
1.41 ng 12501:
12502: =cut
12503:
1.144 matthew 12504: ######################################################
12505: ######################################################
1.31 albertel 12506: sub upfile_select_html {
1.144 matthew 12507: my %Types = (
12508: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12509: semisv => &mt('Semicolon separated values'),
1.144 matthew 12510: space => &mt('Space separated'),
12511: tab => &mt('Tabulator separated'),
12512: # xml => &mt('HTML/XML'),
12513: );
12514: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12515: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12516: foreach my $type (sort(keys(%Types))) {
12517: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12518: }
12519: $Str .= "</select>\n";
12520: return $Str;
1.31 albertel 12521: }
12522:
1.301 albertel 12523: sub get_samples {
12524: my ($records,$toget) = @_;
12525: my @samples=({});
12526: my $got=0;
12527: foreach my $rec (@$records) {
12528: my %temp = &record_sep($rec);
12529: if (! grep(/\S/, values(%temp))) { next; }
12530: if (%temp) {
12531: $samples[$got]=\%temp;
12532: $got++;
12533: if ($got == $toget) { last; }
12534: }
12535: }
12536: return \@samples;
12537: }
12538:
1.144 matthew 12539: ######################################################
12540: ######################################################
12541:
1.56 matthew 12542: =pod
12543:
1.648 raeburn 12544: =item * &csv_print_samples($r,$records)
1.41 ng 12545:
12546: Prints a table of sample values from each column uploaded $r is an
12547: Apache Request ref, $records is an arrayref from
12548: &Apache::loncommon::upfile_record_sep
12549:
12550: =cut
12551:
1.144 matthew 12552: ######################################################
12553: ######################################################
1.31 albertel 12554: sub csv_print_samples {
12555: my ($r,$records) = @_;
1.662 bisitz 12556: my $samples = &get_samples($records,5);
1.301 albertel 12557:
1.594 raeburn 12558: $r->print(&mt('Samples').'<br />'.&start_data_table().
12559: &start_data_table_header_row());
1.356 albertel 12560: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12561: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12562: $r->print(&end_data_table_header_row());
1.301 albertel 12563: foreach my $hash (@$samples) {
1.594 raeburn 12564: $r->print(&start_data_table_row());
1.356 albertel 12565: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12566: $r->print('<td>');
1.356 albertel 12567: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12568: $r->print('</td>');
12569: }
1.594 raeburn 12570: $r->print(&end_data_table_row());
1.31 albertel 12571: }
1.594 raeburn 12572: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12573: }
12574:
1.144 matthew 12575: ######################################################
12576: ######################################################
12577:
1.56 matthew 12578: =pod
12579:
1.648 raeburn 12580: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12581:
12582: Prints a table to create associations between values and table columns.
1.144 matthew 12583:
1.41 ng 12584: $r is an Apache Request ref,
12585: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12586: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12587:
12588: =cut
12589:
1.144 matthew 12590: ######################################################
12591: ######################################################
1.31 albertel 12592: sub csv_print_select_table {
12593: my ($r,$records,$d) = @_;
1.301 albertel 12594: my $i=0;
12595: my $samples = &get_samples($records,1);
1.144 matthew 12596: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12597: &start_data_table().&start_data_table_header_row().
1.144 matthew 12598: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12599: '<th>'.&mt('Column').'</th>'.
12600: &end_data_table_header_row()."\n");
1.356 albertel 12601: foreach my $array_ref (@$d) {
12602: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12603: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12604:
1.875 bisitz 12605: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12606: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12607: $r->print('<option value="none"></option>');
1.356 albertel 12608: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12609: $r->print('<option value="'.$sample.'"'.
12610: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12611: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12612: }
1.594 raeburn 12613: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12614: $i++;
12615: }
1.594 raeburn 12616: $r->print(&end_data_table());
1.31 albertel 12617: $i--;
12618: return $i;
12619: }
1.56 matthew 12620:
1.144 matthew 12621: ######################################################
12622: ######################################################
12623:
1.56 matthew 12624: =pod
1.31 albertel 12625:
1.648 raeburn 12626: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12627:
12628: Prints a table of sample values from the upload and can make associate samples to internal names.
12629:
12630: $r is an Apache Request ref,
12631: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12632: $d is an array of 2 element arrays (internal name, displayed name)
12633:
12634: =cut
12635:
1.144 matthew 12636: ######################################################
12637: ######################################################
1.31 albertel 12638: sub csv_samples_select_table {
12639: my ($r,$records,$d) = @_;
12640: my $i=0;
1.144 matthew 12641: #
1.662 bisitz 12642: my $max_samples = 5;
12643: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12644: $r->print(&start_data_table().
12645: &start_data_table_header_row().'<th>'.
12646: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12647: &end_data_table_header_row());
1.301 albertel 12648:
12649: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12650: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12651: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12652: foreach my $option (@$d) {
12653: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12654: $r->print('<option value="'.$value.'"'.
1.253 albertel 12655: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12656: $display.'</option>');
1.31 albertel 12657: }
12658: $r->print('</select></td><td>');
1.662 bisitz 12659: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12660: if (defined($samples->[$line]{$key})) {
12661: $r->print($samples->[$line]{$key}."<br />\n");
12662: }
12663: }
1.594 raeburn 12664: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12665: $i++;
12666: }
1.594 raeburn 12667: $r->print(&end_data_table());
1.31 albertel 12668: $i--;
12669: return($i);
1.115 matthew 12670: }
12671:
1.144 matthew 12672: ######################################################
12673: ######################################################
12674:
1.115 matthew 12675: =pod
12676:
1.648 raeburn 12677: =item * &clean_excel_name($name)
1.115 matthew 12678:
12679: Returns a replacement for $name which does not contain any illegal characters.
12680:
12681: =cut
12682:
1.144 matthew 12683: ######################################################
12684: ######################################################
1.115 matthew 12685: sub clean_excel_name {
12686: my ($name) = @_;
12687: $name =~ s/[:\*\?\/\\]//g;
12688: if (length($name) > 31) {
12689: $name = substr($name,0,31);
12690: }
12691: return $name;
1.25 albertel 12692: }
1.84 albertel 12693:
1.85 albertel 12694: =pod
12695:
1.648 raeburn 12696: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12697:
12698: Returns either 1 or undef
12699:
12700: 1 if the part is to be hidden, undef if it is to be shown
12701:
12702: Arguments are:
12703:
12704: $id the id of the part to be checked
12705: $symb, optional the symb of the resource to check
12706: $udom, optional the domain of the user to check for
12707: $uname, optional the username of the user to check for
12708:
12709: =cut
1.84 albertel 12710:
12711: sub check_if_partid_hidden {
12712: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12713: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12714: $symb,$udom,$uname);
1.141 albertel 12715: my $truth=1;
12716: #if the string starts with !, then the list is the list to show not hide
12717: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12718: my @hiddenlist=split(/,/,$hiddenparts);
12719: foreach my $checkid (@hiddenlist) {
1.141 albertel 12720: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12721: }
1.141 albertel 12722: return !$truth;
1.84 albertel 12723: }
1.127 matthew 12724:
1.138 matthew 12725:
12726: ############################################################
12727: ############################################################
12728:
12729: =pod
12730:
1.157 matthew 12731: =back
12732:
1.138 matthew 12733: =head1 cgi-bin script and graphing routines
12734:
1.157 matthew 12735: =over 4
12736:
1.648 raeburn 12737: =item * &get_cgi_id()
1.138 matthew 12738:
12739: Inputs: none
12740:
12741: Returns an id which can be used to pass environment variables
12742: to various cgi-bin scripts. These environment variables will
12743: be removed from the users environment after a given time by
12744: the routine &Apache::lonnet::transfer_profile_to_env.
12745:
12746: =cut
12747:
12748: ############################################################
12749: ############################################################
1.152 albertel 12750: my $uniq=0;
1.136 matthew 12751: sub get_cgi_id {
1.154 albertel 12752: $uniq=($uniq+1)%100000;
1.280 albertel 12753: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12754: }
12755:
1.127 matthew 12756: ############################################################
12757: ############################################################
12758:
12759: =pod
12760:
1.648 raeburn 12761: =item * &DrawBarGraph()
1.127 matthew 12762:
1.138 matthew 12763: Facilitates the plotting of data in a (stacked) bar graph.
12764: Puts plot definition data into the users environment in order for
12765: graph.png to plot it. Returns an <img> tag for the plot.
12766: The bars on the plot are labeled '1','2',...,'n'.
12767:
12768: Inputs:
12769:
12770: =over 4
12771:
12772: =item $Title: string, the title of the plot
12773:
12774: =item $xlabel: string, text describing the X-axis of the plot
12775:
12776: =item $ylabel: string, text describing the Y-axis of the plot
12777:
12778: =item $Max: scalar, the maximum Y value to use in the plot
12779: If $Max is < any data point, the graph will not be rendered.
12780:
1.140 matthew 12781: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12782: they are plotted. If undefined, default values will be used.
12783:
1.178 matthew 12784: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12785:
1.138 matthew 12786: =item @Values: An array of array references. Each array reference holds data
12787: to be plotted in a stacked bar chart.
12788:
1.239 matthew 12789: =item If the final element of @Values is a hash reference the key/value
12790: pairs will be added to the graph definition.
12791:
1.138 matthew 12792: =back
12793:
12794: Returns:
12795:
12796: An <img> tag which references graph.png and the appropriate identifying
12797: information for the plot.
12798:
1.127 matthew 12799: =cut
12800:
12801: ############################################################
12802: ############################################################
1.134 matthew 12803: sub DrawBarGraph {
1.178 matthew 12804: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12805: #
12806: if (! defined($colors)) {
12807: $colors = ['#33ff00',
12808: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12809: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12810: ];
12811: }
1.228 matthew 12812: my $extra_settings = {};
12813: if (ref($Values[-1]) eq 'HASH') {
12814: $extra_settings = pop(@Values);
12815: }
1.127 matthew 12816: #
1.136 matthew 12817: my $identifier = &get_cgi_id();
12818: my $id = 'cgi.'.$identifier;
1.129 matthew 12819: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12820: return '';
12821: }
1.225 matthew 12822: #
12823: my @Labels;
12824: if (defined($labels)) {
12825: @Labels = @$labels;
12826: } else {
12827: for (my $i=0;$i<@{$Values[0]};$i++) {
12828: push (@Labels,$i+1);
12829: }
12830: }
12831: #
1.129 matthew 12832: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12833: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12834: my %ValuesHash;
12835: my $NumSets=1;
12836: foreach my $array (@Values) {
12837: next if (! ref($array));
1.136 matthew 12838: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12839: join(',',@$array);
1.129 matthew 12840: }
1.127 matthew 12841: #
1.136 matthew 12842: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12843: if ($NumBars < 3) {
12844: $width = 120+$NumBars*32;
1.220 matthew 12845: $xskip = 1;
1.225 matthew 12846: $bar_width = 30;
12847: } elsif ($NumBars < 5) {
12848: $width = 120+$NumBars*20;
12849: $xskip = 1;
12850: $bar_width = 20;
1.220 matthew 12851: } elsif ($NumBars < 10) {
1.136 matthew 12852: $width = 120+$NumBars*15;
12853: $xskip = 1;
12854: $bar_width = 15;
12855: } elsif ($NumBars <= 25) {
12856: $width = 120+$NumBars*11;
12857: $xskip = 5;
12858: $bar_width = 8;
12859: } elsif ($NumBars <= 50) {
12860: $width = 120+$NumBars*8;
12861: $xskip = 5;
12862: $bar_width = 4;
12863: } else {
12864: $width = 120+$NumBars*8;
12865: $xskip = 5;
12866: $bar_width = 4;
12867: }
12868: #
1.137 matthew 12869: $Max = 1 if ($Max < 1);
12870: if ( int($Max) < $Max ) {
12871: $Max++;
12872: $Max = int($Max);
12873: }
1.127 matthew 12874: $Title = '' if (! defined($Title));
12875: $xlabel = '' if (! defined($xlabel));
12876: $ylabel = '' if (! defined($ylabel));
1.369 www 12877: $ValuesHash{$id.'.title'} = &escape($Title);
12878: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12879: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12880: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12881: $ValuesHash{$id.'.NumBars'} = $NumBars;
12882: $ValuesHash{$id.'.NumSets'} = $NumSets;
12883: $ValuesHash{$id.'.PlotType'} = 'bar';
12884: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12885: $ValuesHash{$id.'.height'} = $height;
12886: $ValuesHash{$id.'.width'} = $width;
12887: $ValuesHash{$id.'.xskip'} = $xskip;
12888: $ValuesHash{$id.'.bar_width'} = $bar_width;
12889: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12890: #
1.228 matthew 12891: # Deal with other parameters
12892: while (my ($key,$value) = each(%$extra_settings)) {
12893: $ValuesHash{$id.'.'.$key} = $value;
12894: }
12895: #
1.646 raeburn 12896: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12897: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12898: }
12899:
12900: ############################################################
12901: ############################################################
12902:
12903: =pod
12904:
1.648 raeburn 12905: =item * &DrawXYGraph()
1.137 matthew 12906:
1.138 matthew 12907: Facilitates the plotting of data in an XY graph.
12908: Puts plot definition data into the users environment in order for
12909: graph.png to plot it. Returns an <img> tag for the plot.
12910:
12911: Inputs:
12912:
12913: =over 4
12914:
12915: =item $Title: string, the title of the plot
12916:
12917: =item $xlabel: string, text describing the X-axis of the plot
12918:
12919: =item $ylabel: string, text describing the Y-axis of the plot
12920:
12921: =item $Max: scalar, the maximum Y value to use in the plot
12922: If $Max is < any data point, the graph will not be rendered.
12923:
12924: =item $colors: Array ref containing the hex color codes for the data to be
12925: plotted in. If undefined, default values will be used.
12926:
12927: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12928:
12929: =item $Ydata: Array ref containing Array refs.
1.185 www 12930: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12931:
12932: =item %Values: hash indicating or overriding any default values which are
12933: passed to graph.png.
12934: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12935:
12936: =back
12937:
12938: Returns:
12939:
12940: An <img> tag which references graph.png and the appropriate identifying
12941: information for the plot.
12942:
1.137 matthew 12943: =cut
12944:
12945: ############################################################
12946: ############################################################
12947: sub DrawXYGraph {
12948: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12949: #
12950: # Create the identifier for the graph
12951: my $identifier = &get_cgi_id();
12952: my $id = 'cgi.'.$identifier;
12953: #
12954: $Title = '' if (! defined($Title));
12955: $xlabel = '' if (! defined($xlabel));
12956: $ylabel = '' if (! defined($ylabel));
12957: my %ValuesHash =
12958: (
1.369 www 12959: $id.'.title' => &escape($Title),
12960: $id.'.xlabel' => &escape($xlabel),
12961: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12962: $id.'.y_max_value'=> $Max,
12963: $id.'.labels' => join(',',@$Xlabels),
12964: $id.'.PlotType' => 'XY',
12965: );
12966: #
12967: if (defined($colors) && ref($colors) eq 'ARRAY') {
12968: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12969: }
12970: #
12971: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12972: return '';
12973: }
12974: my $NumSets=1;
1.138 matthew 12975: foreach my $array (@{$Ydata}){
1.137 matthew 12976: next if (! ref($array));
12977: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12978: }
1.138 matthew 12979: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12980: #
12981: # Deal with other parameters
12982: while (my ($key,$value) = each(%Values)) {
12983: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12984: }
12985: #
1.646 raeburn 12986: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12987: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12988: }
12989:
12990: ############################################################
12991: ############################################################
12992:
12993: =pod
12994:
1.648 raeburn 12995: =item * &DrawXYYGraph()
1.138 matthew 12996:
12997: Facilitates the plotting of data in an XY graph with two Y axes.
12998: Puts plot definition data into the users environment in order for
12999: graph.png to plot it. Returns an <img> tag for the plot.
13000:
13001: Inputs:
13002:
13003: =over 4
13004:
13005: =item $Title: string, the title of the plot
13006:
13007: =item $xlabel: string, text describing the X-axis of the plot
13008:
13009: =item $ylabel: string, text describing the Y-axis of the plot
13010:
13011: =item $colors: Array ref containing the hex color codes for the data to be
13012: plotted in. If undefined, default values will be used.
13013:
13014: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13015:
13016: =item $Ydata1: The first data set
13017:
13018: =item $Min1: The minimum value of the left Y-axis
13019:
13020: =item $Max1: The maximum value of the left Y-axis
13021:
13022: =item $Ydata2: The second data set
13023:
13024: =item $Min2: The minimum value of the right Y-axis
13025:
13026: =item $Max2: The maximum value of the left Y-axis
13027:
13028: =item %Values: hash indicating or overriding any default values which are
13029: passed to graph.png.
13030: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13031:
13032: =back
13033:
13034: Returns:
13035:
13036: An <img> tag which references graph.png and the appropriate identifying
13037: information for the plot.
1.136 matthew 13038:
13039: =cut
13040:
13041: ############################################################
13042: ############################################################
1.137 matthew 13043: sub DrawXYYGraph {
13044: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13045: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13046: #
13047: # Create the identifier for the graph
13048: my $identifier = &get_cgi_id();
13049: my $id = 'cgi.'.$identifier;
13050: #
13051: $Title = '' if (! defined($Title));
13052: $xlabel = '' if (! defined($xlabel));
13053: $ylabel = '' if (! defined($ylabel));
13054: my %ValuesHash =
13055: (
1.369 www 13056: $id.'.title' => &escape($Title),
13057: $id.'.xlabel' => &escape($xlabel),
13058: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13059: $id.'.labels' => join(',',@$Xlabels),
13060: $id.'.PlotType' => 'XY',
13061: $id.'.NumSets' => 2,
1.137 matthew 13062: $id.'.two_axes' => 1,
13063: $id.'.y1_max_value' => $Max1,
13064: $id.'.y1_min_value' => $Min1,
13065: $id.'.y2_max_value' => $Max2,
13066: $id.'.y2_min_value' => $Min2,
1.136 matthew 13067: );
13068: #
1.137 matthew 13069: if (defined($colors) && ref($colors) eq 'ARRAY') {
13070: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13071: }
13072: #
13073: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13074: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13075: return '';
13076: }
13077: my $NumSets=1;
1.137 matthew 13078: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13079: next if (! ref($array));
13080: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13081: }
13082: #
13083: # Deal with other parameters
13084: while (my ($key,$value) = each(%Values)) {
13085: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13086: }
13087: #
1.646 raeburn 13088: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13089: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13090: }
13091:
13092: ############################################################
13093: ############################################################
13094:
13095: =pod
13096:
1.157 matthew 13097: =back
13098:
1.139 matthew 13099: =head1 Statistics helper routines?
13100:
13101: Bad place for them but what the hell.
13102:
1.157 matthew 13103: =over 4
13104:
1.648 raeburn 13105: =item * &chartlink()
1.139 matthew 13106:
13107: Returns a link to the chart for a specific student.
13108:
13109: Inputs:
13110:
13111: =over 4
13112:
13113: =item $linktext: The text of the link
13114:
13115: =item $sname: The students username
13116:
13117: =item $sdomain: The students domain
13118:
13119: =back
13120:
1.157 matthew 13121: =back
13122:
1.139 matthew 13123: =cut
13124:
13125: ############################################################
13126: ############################################################
13127: sub chartlink {
13128: my ($linktext, $sname, $sdomain) = @_;
13129: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13130: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13131: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13132: '">'.$linktext.'</a>';
1.153 matthew 13133: }
13134:
13135: #######################################################
13136: #######################################################
13137:
13138: =pod
13139:
13140: =head1 Course Environment Routines
1.157 matthew 13141:
13142: =over 4
1.153 matthew 13143:
1.648 raeburn 13144: =item * &restore_course_settings()
1.153 matthew 13145:
1.648 raeburn 13146: =item * &store_course_settings()
1.153 matthew 13147:
13148: Restores/Store indicated form parameters from the course environment.
13149: Will not overwrite existing values of the form parameters.
13150:
13151: Inputs:
13152: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13153:
13154: a hash ref describing the data to be stored. For example:
13155:
13156: %Save_Parameters = ('Status' => 'scalar',
13157: 'chartoutputmode' => 'scalar',
13158: 'chartoutputdata' => 'scalar',
13159: 'Section' => 'array',
1.373 raeburn 13160: 'Group' => 'array',
1.153 matthew 13161: 'StudentData' => 'array',
13162: 'Maps' => 'array');
13163:
13164: Returns: both routines return nothing
13165:
1.631 raeburn 13166: =back
13167:
1.153 matthew 13168: =cut
13169:
13170: #######################################################
13171: #######################################################
13172: sub store_course_settings {
1.496 albertel 13173: return &store_settings($env{'request.course.id'},@_);
13174: }
13175:
13176: sub store_settings {
1.153 matthew 13177: # save to the environment
13178: # appenv the same items, just to be safe
1.300 albertel 13179: my $udom = $env{'user.domain'};
13180: my $uname = $env{'user.name'};
1.496 albertel 13181: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13182: my %SaveHash;
13183: my %AppHash;
13184: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13185: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13186: my $envname = 'environment.'.$basename;
1.258 albertel 13187: if (exists($env{'form.'.$setting})) {
1.153 matthew 13188: # Save this value away
13189: if ($type eq 'scalar' &&
1.258 albertel 13190: (! exists($env{$envname}) ||
13191: $env{$envname} ne $env{'form.'.$setting})) {
13192: $SaveHash{$basename} = $env{'form.'.$setting};
13193: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13194: } elsif ($type eq 'array') {
13195: my $stored_form;
1.258 albertel 13196: if (ref($env{'form.'.$setting})) {
1.153 matthew 13197: $stored_form = join(',',
13198: map {
1.369 www 13199: &escape($_);
1.258 albertel 13200: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13201: } else {
13202: $stored_form =
1.369 www 13203: &escape($env{'form.'.$setting});
1.153 matthew 13204: }
13205: # Determine if the array contents are the same.
1.258 albertel 13206: if ($stored_form ne $env{$envname}) {
1.153 matthew 13207: $SaveHash{$basename} = $stored_form;
13208: $AppHash{$envname} = $stored_form;
13209: }
13210: }
13211: }
13212: }
13213: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13214: $udom,$uname);
1.153 matthew 13215: if ($put_result !~ /^(ok|delayed)/) {
13216: &Apache::lonnet::logthis('unable to save form parameters, '.
13217: 'got error:'.$put_result);
13218: }
13219: # Make sure these settings stick around in this session, too
1.646 raeburn 13220: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13221: return;
13222: }
13223:
13224: sub restore_course_settings {
1.499 albertel 13225: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13226: }
13227:
13228: sub restore_settings {
13229: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13230: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13231: next if (exists($env{'form.'.$setting}));
1.496 albertel 13232: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13233: '.'.$setting;
1.258 albertel 13234: if (exists($env{$envname})) {
1.153 matthew 13235: if ($type eq 'scalar') {
1.258 albertel 13236: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13237: } elsif ($type eq 'array') {
1.258 albertel 13238: $env{'form.'.$setting} = [
1.153 matthew 13239: map {
1.369 www 13240: &unescape($_);
1.258 albertel 13241: } split(',',$env{$envname})
1.153 matthew 13242: ];
13243: }
13244: }
13245: }
1.127 matthew 13246: }
13247:
1.618 raeburn 13248: #######################################################
13249: #######################################################
13250:
13251: =pod
13252:
13253: =head1 Domain E-mail Routines
13254:
13255: =over 4
13256:
1.648 raeburn 13257: =item * &build_recipient_list()
1.618 raeburn 13258:
1.1075.2.44 raeburn 13259: Build recipient lists for following types of e-mail:
1.766 raeburn 13260: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 13261: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13262: module change checking, student/employee ID conflict checks, as
13263: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13264: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13265:
13266: Inputs:
1.1075.2.44 raeburn 13267: defmail (scalar - email address of default recipient),
13268: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13269: requestsmail, updatesmail, or idconflictsmail).
13270:
1.619 raeburn 13271: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 13272:
13273: origmail (scalar - email address of recipient from loncapa.conf,
13274: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13275:
1.655 raeburn 13276: Returns: comma separated list of addresses to which to send e-mail.
13277:
13278: =back
1.618 raeburn 13279:
13280: =cut
13281:
13282: ############################################################
13283: ############################################################
13284: sub build_recipient_list {
1.619 raeburn 13285: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13286: my @recipients;
13287: my $otheremails;
13288: my %domconfig =
13289: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13290: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13291: if (exists($domconfig{'contacts'}{$mailing})) {
13292: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13293: my @contacts = ('adminemail','supportemail');
13294: foreach my $item (@contacts) {
13295: if ($domconfig{'contacts'}{$mailing}{$item}) {
13296: my $addr = $domconfig{'contacts'}{$item};
13297: if (!grep(/^\Q$addr\E$/,@recipients)) {
13298: push(@recipients,$addr);
13299: }
1.619 raeburn 13300: }
1.766 raeburn 13301: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13302: }
13303: }
1.766 raeburn 13304: } elsif ($origmail ne '') {
13305: push(@recipients,$origmail);
1.618 raeburn 13306: }
1.619 raeburn 13307: } elsif ($origmail ne '') {
13308: push(@recipients,$origmail);
1.618 raeburn 13309: }
1.688 raeburn 13310: if (defined($defmail)) {
13311: if ($defmail ne '') {
13312: push(@recipients,$defmail);
13313: }
1.618 raeburn 13314: }
13315: if ($otheremails) {
1.619 raeburn 13316: my @others;
13317: if ($otheremails =~ /,/) {
13318: @others = split(/,/,$otheremails);
1.618 raeburn 13319: } else {
1.619 raeburn 13320: push(@others,$otheremails);
13321: }
13322: foreach my $addr (@others) {
13323: if (!grep(/^\Q$addr\E$/,@recipients)) {
13324: push(@recipients,$addr);
13325: }
1.618 raeburn 13326: }
13327: }
1.619 raeburn 13328: my $recipientlist = join(',',@recipients);
1.618 raeburn 13329: return $recipientlist;
13330: }
13331:
1.127 matthew 13332: ############################################################
13333: ############################################################
1.154 albertel 13334:
1.655 raeburn 13335: =pod
13336:
13337: =head1 Course Catalog Routines
13338:
13339: =over 4
13340:
13341: =item * &gather_categories()
13342:
13343: Converts category definitions - keys of categories hash stored in
13344: coursecategories in configuration.db on the primary library server in a
13345: domain - to an array. Also generates javascript and idx hash used to
13346: generate Domain Coordinator interface for editing Course Categories.
13347:
13348: Inputs:
1.663 raeburn 13349:
1.655 raeburn 13350: categories (reference to hash of category definitions).
1.663 raeburn 13351:
1.655 raeburn 13352: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13353: categories and subcategories).
1.663 raeburn 13354:
1.655 raeburn 13355: idx (reference to hash of counters used in Domain Coordinator interface for
13356: editing Course Categories).
1.663 raeburn 13357:
1.655 raeburn 13358: jsarray (reference to array of categories used to create Javascript arrays for
13359: Domain Coordinator interface for editing Course Categories).
13360:
13361: Returns: nothing
13362:
13363: Side effects: populates cats, idx and jsarray.
13364:
13365: =cut
13366:
13367: sub gather_categories {
13368: my ($categories,$cats,$idx,$jsarray) = @_;
13369: my %counters;
13370: my $num = 0;
13371: foreach my $item (keys(%{$categories})) {
13372: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13373: if ($container eq '' && $depth == 0) {
13374: $cats->[$depth][$categories->{$item}] = $cat;
13375: } else {
13376: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13377: }
13378: my ($escitem,$tail) = split(/:/,$item,2);
13379: if ($counters{$tail} eq '') {
13380: $counters{$tail} = $num;
13381: $num ++;
13382: }
13383: if (ref($idx) eq 'HASH') {
13384: $idx->{$item} = $counters{$tail};
13385: }
13386: if (ref($jsarray) eq 'ARRAY') {
13387: push(@{$jsarray->[$counters{$tail}]},$item);
13388: }
13389: }
13390: return;
13391: }
13392:
13393: =pod
13394:
13395: =item * &extract_categories()
13396:
13397: Used to generate breadcrumb trails for course categories.
13398:
13399: Inputs:
1.663 raeburn 13400:
1.655 raeburn 13401: categories (reference to hash of category definitions).
1.663 raeburn 13402:
1.655 raeburn 13403: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13404: categories and subcategories).
1.663 raeburn 13405:
1.655 raeburn 13406: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13407:
1.655 raeburn 13408: allitems (reference to hash - key is category key
13409: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13410:
1.655 raeburn 13411: idx (reference to hash of counters used in Domain Coordinator interface for
13412: editing Course Categories).
1.663 raeburn 13413:
1.655 raeburn 13414: jsarray (reference to array of categories used to create Javascript arrays for
13415: Domain Coordinator interface for editing Course Categories).
13416:
1.665 raeburn 13417: subcats (reference to hash of arrays containing all subcategories within each
13418: category, -recursive)
13419:
1.655 raeburn 13420: Returns: nothing
13421:
13422: Side effects: populates trails and allitems hash references.
13423:
13424: =cut
13425:
13426: sub extract_categories {
1.665 raeburn 13427: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13428: if (ref($categories) eq 'HASH') {
13429: &gather_categories($categories,$cats,$idx,$jsarray);
13430: if (ref($cats->[0]) eq 'ARRAY') {
13431: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13432: my $name = $cats->[0][$i];
13433: my $item = &escape($name).'::0';
13434: my $trailstr;
13435: if ($name eq 'instcode') {
13436: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13437: } elsif ($name eq 'communities') {
13438: $trailstr = &mt('Communities');
1.655 raeburn 13439: } else {
13440: $trailstr = $name;
13441: }
13442: if ($allitems->{$item} eq '') {
13443: push(@{$trails},$trailstr);
13444: $allitems->{$item} = scalar(@{$trails})-1;
13445: }
13446: my @parents = ($name);
13447: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13448: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13449: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13450: if (ref($subcats) eq 'HASH') {
13451: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13452: }
13453: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13454: }
13455: } else {
13456: if (ref($subcats) eq 'HASH') {
13457: $subcats->{$item} = [];
1.655 raeburn 13458: }
13459: }
13460: }
13461: }
13462: }
13463: return;
13464: }
13465:
13466: =pod
13467:
1.1075.2.56 raeburn 13468: =item * &recurse_categories()
1.655 raeburn 13469:
13470: Recursively used to generate breadcrumb trails for course categories.
13471:
13472: Inputs:
1.663 raeburn 13473:
1.655 raeburn 13474: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13475: categories and subcategories).
1.663 raeburn 13476:
1.655 raeburn 13477: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13478:
13479: category (current course category, for which breadcrumb trail is being generated).
13480:
13481: trails (reference to array of breadcrumb trails for each category).
13482:
1.655 raeburn 13483: allitems (reference to hash - key is category key
13484: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13485:
1.655 raeburn 13486: parents (array containing containers directories for current category,
13487: back to top level).
13488:
13489: Returns: nothing
13490:
13491: Side effects: populates trails and allitems hash references
13492:
13493: =cut
13494:
13495: sub recurse_categories {
1.665 raeburn 13496: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13497: my $shallower = $depth - 1;
13498: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13499: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13500: my $name = $cats->[$depth]{$category}[$k];
13501: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13502: my $trailstr = join(' -> ',(@{$parents},$category));
13503: if ($allitems->{$item} eq '') {
13504: push(@{$trails},$trailstr);
13505: $allitems->{$item} = scalar(@{$trails})-1;
13506: }
13507: my $deeper = $depth+1;
13508: push(@{$parents},$category);
1.665 raeburn 13509: if (ref($subcats) eq 'HASH') {
13510: my $subcat = &escape($name).':'.$category.':'.$depth;
13511: for (my $j=@{$parents}; $j>=0; $j--) {
13512: my $higher;
13513: if ($j > 0) {
13514: $higher = &escape($parents->[$j]).':'.
13515: &escape($parents->[$j-1]).':'.$j;
13516: } else {
13517: $higher = &escape($parents->[$j]).'::'.$j;
13518: }
13519: push(@{$subcats->{$higher}},$subcat);
13520: }
13521: }
13522: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13523: $subcats);
1.655 raeburn 13524: pop(@{$parents});
13525: }
13526: } else {
13527: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13528: my $trailstr = join(' -> ',(@{$parents},$category));
13529: if ($allitems->{$item} eq '') {
13530: push(@{$trails},$trailstr);
13531: $allitems->{$item} = scalar(@{$trails})-1;
13532: }
13533: }
13534: return;
13535: }
13536:
1.663 raeburn 13537: =pod
13538:
1.1075.2.56 raeburn 13539: =item * &assign_categories_table()
1.663 raeburn 13540:
13541: Create a datatable for display of hierarchical categories in a domain,
13542: with checkboxes to allow a course to be categorized.
13543:
13544: Inputs:
13545:
13546: cathash - reference to hash of categories defined for the domain (from
13547: configuration.db)
13548:
13549: currcat - scalar with an & separated list of categories assigned to a course.
13550:
1.919 raeburn 13551: type - scalar contains course type (Course or Community).
13552:
1.663 raeburn 13553: Returns: $output (markup to be displayed)
13554:
13555: =cut
13556:
13557: sub assign_categories_table {
1.919 raeburn 13558: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13559: my $output;
13560: if (ref($cathash) eq 'HASH') {
13561: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13562: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13563: $maxdepth = scalar(@cats);
13564: if (@cats > 0) {
13565: my $itemcount = 0;
13566: if (ref($cats[0]) eq 'ARRAY') {
13567: my @currcategories;
13568: if ($currcat ne '') {
13569: @currcategories = split('&',$currcat);
13570: }
1.919 raeburn 13571: my $table;
1.663 raeburn 13572: for (my $i=0; $i<@{$cats[0]}; $i++) {
13573: my $parent = $cats[0][$i];
1.919 raeburn 13574: next if ($parent eq 'instcode');
13575: if ($type eq 'Community') {
13576: next unless ($parent eq 'communities');
13577: } else {
13578: next if ($parent eq 'communities');
13579: }
1.663 raeburn 13580: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13581: my $item = &escape($parent).'::0';
13582: my $checked = '';
13583: if (@currcategories > 0) {
13584: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13585: $checked = ' checked="checked"';
1.663 raeburn 13586: }
13587: }
1.919 raeburn 13588: my $parent_title = $parent;
13589: if ($parent eq 'communities') {
13590: $parent_title = &mt('Communities');
13591: }
13592: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13593: '<input type="checkbox" name="usecategory" value="'.
13594: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13595: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13596: my $depth = 1;
13597: push(@path,$parent);
1.919 raeburn 13598: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13599: pop(@path);
1.919 raeburn 13600: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13601: $itemcount ++;
13602: }
1.919 raeburn 13603: if ($itemcount) {
13604: $output = &Apache::loncommon::start_data_table().
13605: $table.
13606: &Apache::loncommon::end_data_table();
13607: }
1.663 raeburn 13608: }
13609: }
13610: }
13611: return $output;
13612: }
13613:
13614: =pod
13615:
1.1075.2.56 raeburn 13616: =item * &assign_category_rows()
1.663 raeburn 13617:
13618: Create a datatable row for display of nested categories in a domain,
13619: with checkboxes to allow a course to be categorized,called recursively.
13620:
13621: Inputs:
13622:
13623: itemcount - track row number for alternating colors
13624:
13625: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13626: categories and subcategories.
13627:
13628: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13629:
13630: parent - parent of current category item
13631:
13632: path - Array containing all categories back up through the hierarchy from the
13633: current category to the top level.
13634:
13635: currcategories - reference to array of current categories assigned to the course
13636:
13637: Returns: $output (markup to be displayed).
13638:
13639: =cut
13640:
13641: sub assign_category_rows {
13642: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13643: my ($text,$name,$item,$chgstr);
13644: if (ref($cats) eq 'ARRAY') {
13645: my $maxdepth = scalar(@{$cats});
13646: if (ref($cats->[$depth]) eq 'HASH') {
13647: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13648: my $numchildren = @{$cats->[$depth]{$parent}};
13649: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 13650: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13651: for (my $j=0; $j<$numchildren; $j++) {
13652: $name = $cats->[$depth]{$parent}[$j];
13653: $item = &escape($name).':'.&escape($parent).':'.$depth;
13654: my $deeper = $depth+1;
13655: my $checked = '';
13656: if (ref($currcategories) eq 'ARRAY') {
13657: if (@{$currcategories} > 0) {
13658: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13659: $checked = ' checked="checked"';
1.663 raeburn 13660: }
13661: }
13662: }
1.664 raeburn 13663: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13664: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13665: $item.'"'.$checked.' />'.$name.'</label></span>'.
13666: '<input type="hidden" name="catname" value="'.$name.'" />'.
13667: '</td><td>';
1.663 raeburn 13668: if (ref($path) eq 'ARRAY') {
13669: push(@{$path},$name);
13670: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13671: pop(@{$path});
13672: }
13673: $text .= '</td></tr>';
13674: }
13675: $text .= '</table></td>';
13676: }
13677: }
13678: }
13679: return $text;
13680: }
13681:
1.1075.2.69 raeburn 13682: =pod
13683:
13684: =back
13685:
13686: =cut
13687:
1.655 raeburn 13688: ############################################################
13689: ############################################################
13690:
13691:
1.443 albertel 13692: sub commit_customrole {
1.664 raeburn 13693: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13694: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13695: ($start?', '.&mt('starting').' '.localtime($start):'').
13696: ($end?', ending '.localtime($end):'').': <b>'.
13697: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13698: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13699: '</b><br />';
13700: return $output;
13701: }
13702:
13703: sub commit_standardrole {
1.1075.2.31 raeburn 13704: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13705: my ($output,$logmsg,$linefeed);
13706: if ($context eq 'auto') {
13707: $linefeed = "\n";
13708: } else {
13709: $linefeed = "<br />\n";
13710: }
1.443 albertel 13711: if ($three eq 'st') {
1.541 raeburn 13712: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 13713: $one,$two,$sec,$context,$credits);
1.541 raeburn 13714: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13715: ($result eq 'unknown_course') || ($result eq 'refused')) {
13716: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13717: } else {
1.541 raeburn 13718: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13719: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13720: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13721: if ($context eq 'auto') {
13722: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13723: } else {
13724: $output .= '<b>'.$result.'</b>'.$linefeed.
13725: &mt('Add to classlist').': <b>ok</b>';
13726: }
13727: $output .= $linefeed;
1.443 albertel 13728: }
13729: } else {
13730: $output = &mt('Assigning').' '.$three.' in '.$url.
13731: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13732: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13733: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13734: if ($context eq 'auto') {
13735: $output .= $result.$linefeed;
13736: } else {
13737: $output .= '<b>'.$result.'</b>'.$linefeed;
13738: }
1.443 albertel 13739: }
13740: return $output;
13741: }
13742:
13743: sub commit_studentrole {
1.1075.2.31 raeburn 13744: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13745: $credits) = @_;
1.626 raeburn 13746: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13747: if ($context eq 'auto') {
13748: $linefeed = "\n";
13749: } else {
13750: $linefeed = '<br />'."\n";
13751: }
1.443 albertel 13752: if (defined($one) && defined($two)) {
13753: my $cid=$one.'_'.$two;
13754: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13755: my $secchange = 0;
13756: my $expire_role_result;
13757: my $modify_section_result;
1.628 raeburn 13758: if ($oldsec ne '-1') {
13759: if ($oldsec ne $sec) {
1.443 albertel 13760: $secchange = 1;
1.628 raeburn 13761: my $now = time;
1.443 albertel 13762: my $uurl='/'.$cid;
13763: $uurl=~s/\_/\//g;
13764: if ($oldsec) {
13765: $uurl.='/'.$oldsec;
13766: }
1.626 raeburn 13767: $oldsecurl = $uurl;
1.628 raeburn 13768: $expire_role_result =
1.652 raeburn 13769: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13770: if ($env{'request.course.sec'} ne '') {
13771: if ($expire_role_result eq 'refused') {
13772: my @roles = ('st');
13773: my @statuses = ('previous');
13774: my @roledoms = ($one);
13775: my $withsec = 1;
13776: my %roleshash =
13777: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13778: \@statuses,\@roles,\@roledoms,$withsec);
13779: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13780: my ($oldstart,$oldend) =
13781: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13782: if ($oldend > 0 && $oldend <= $now) {
13783: $expire_role_result = 'ok';
13784: }
13785: }
13786: }
13787: }
1.443 albertel 13788: $result = $expire_role_result;
13789: }
13790: }
13791: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 13792: $modify_section_result =
13793: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13794: undef,undef,undef,$sec,
13795: $end,$start,'','',$cid,
13796: '',$context,$credits);
1.443 albertel 13797: if ($modify_section_result =~ /^ok/) {
13798: if ($secchange == 1) {
1.628 raeburn 13799: if ($sec eq '') {
13800: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13801: } else {
13802: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13803: }
1.443 albertel 13804: } elsif ($oldsec eq '-1') {
1.628 raeburn 13805: if ($sec eq '') {
13806: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13807: } else {
13808: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13809: }
1.443 albertel 13810: } else {
1.628 raeburn 13811: if ($sec eq '') {
13812: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13813: } else {
13814: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13815: }
1.443 albertel 13816: }
13817: } else {
1.628 raeburn 13818: if ($secchange) {
13819: $$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;
13820: } else {
13821: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13822: }
1.443 albertel 13823: }
13824: $result = $modify_section_result;
13825: } elsif ($secchange == 1) {
1.628 raeburn 13826: if ($oldsec eq '') {
1.1075.2.20 raeburn 13827: $$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 13828: } else {
13829: $$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;
13830: }
1.626 raeburn 13831: if ($expire_role_result eq 'refused') {
13832: my $newsecurl = '/'.$cid;
13833: $newsecurl =~ s/\_/\//g;
13834: if ($sec ne '') {
13835: $newsecurl.='/'.$sec;
13836: }
13837: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13838: if ($sec eq '') {
13839: $$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;
13840: } else {
13841: $$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;
13842: }
13843: }
13844: }
1.443 albertel 13845: }
13846: } else {
1.626 raeburn 13847: $$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 13848: $result = "error: incomplete course id\n";
13849: }
13850: return $result;
13851: }
13852:
1.1075.2.25 raeburn 13853: sub show_role_extent {
13854: my ($scope,$context,$role) = @_;
13855: $scope =~ s{^/}{};
13856: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13857: push(@courseroles,'co');
13858: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13859: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13860: $scope =~ s{/}{_};
13861: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13862: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13863: my ($audom,$auname) = split(/\//,$scope);
13864: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13865: &Apache::loncommon::plainname($auname,$audom).'</span>');
13866: } else {
13867: $scope =~ s{/$}{};
13868: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13869: &Apache::lonnet::domain($scope,'description').'</span>');
13870: }
13871: }
13872:
1.443 albertel 13873: ############################################################
13874: ############################################################
13875:
1.566 albertel 13876: sub check_clone {
1.578 raeburn 13877: my ($args,$linefeed) = @_;
1.566 albertel 13878: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13879: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13880: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13881: my $clonemsg;
13882: my $can_clone = 0;
1.944 raeburn 13883: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13884: if ($lctype ne 'community') {
13885: $lctype = 'course';
13886: }
1.566 albertel 13887: if ($clonehome eq 'no_host') {
1.944 raeburn 13888: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13889: $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'});
13890: } else {
13891: $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'});
13892: }
1.566 albertel 13893: } else {
13894: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13895: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13896: if ($clonedesc{'type'} ne 'Community') {
13897: $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'});
13898: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13899: }
13900: }
1.882 raeburn 13901: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13902: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13903: $can_clone = 1;
13904: } else {
13905: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13906: $args->{'clonedomain'},$args->{'clonecourse'});
13907: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13908: if (grep(/^\*$/,@cloners)) {
13909: $can_clone = 1;
13910: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13911: $can_clone = 1;
13912: } else {
1.908 raeburn 13913: my $ccrole = 'cc';
1.944 raeburn 13914: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13915: $ccrole = 'co';
13916: }
1.578 raeburn 13917: my %roleshash =
13918: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13919: $args->{'ccdomain'},
1.908 raeburn 13920: 'userroles',['active'],[$ccrole],
1.578 raeburn 13921: [$args->{'clonedomain'}]);
1.908 raeburn 13922: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13923: $can_clone = 1;
13924: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13925: $can_clone = 1;
13926: } else {
1.944 raeburn 13927: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13928: $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'});
13929: } else {
13930: $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'});
13931: }
1.578 raeburn 13932: }
1.566 albertel 13933: }
1.578 raeburn 13934: }
1.566 albertel 13935: }
13936: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13937: }
13938:
1.444 albertel 13939: sub construct_course {
1.1075.2.59 raeburn 13940: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 13941: my $outcome;
1.541 raeburn 13942: my $linefeed = '<br />'."\n";
13943: if ($context eq 'auto') {
13944: $linefeed = "\n";
13945: }
1.566 albertel 13946:
13947: #
13948: # Are we cloning?
13949: #
13950: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13951: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13952: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13953: if ($context ne 'auto') {
1.578 raeburn 13954: if ($clonemsg ne '') {
13955: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13956: }
1.566 albertel 13957: }
13958: $outcome .= $clonemsg.$linefeed;
13959:
13960: if (!$can_clone) {
13961: return (0,$outcome);
13962: }
13963: }
13964:
1.444 albertel 13965: #
13966: # Open course
13967: #
13968: my $crstype = lc($args->{'crstype'});
13969: my %cenv=();
13970: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13971: $args->{'cdescr'},
13972: $args->{'curl'},
13973: $args->{'course_home'},
13974: $args->{'nonstandard'},
13975: $args->{'crscode'},
13976: $args->{'ccuname'}.':'.
13977: $args->{'ccdomain'},
1.882 raeburn 13978: $args->{'crstype'},
1.885 raeburn 13979: $cnum,$context,$category);
1.444 albertel 13980:
13981: # Note: The testing routines depend on this being output; see
13982: # Utils::Course. This needs to at least be output as a comment
13983: # if anyone ever decides to not show this, and Utils::Course::new
13984: # will need to be suitably modified.
1.541 raeburn 13985: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13986: if ($$courseid =~ /^error:/) {
13987: return (0,$outcome);
13988: }
13989:
1.444 albertel 13990: #
13991: # Check if created correctly
13992: #
1.479 albertel 13993: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13994: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13995: if ($crsuhome eq 'no_host') {
13996: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13997: return (0,$outcome);
13998: }
1.541 raeburn 13999: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 14000:
1.444 albertel 14001: #
1.566 albertel 14002: # Do the cloning
14003: #
14004: if ($can_clone && $cloneid) {
14005: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14006: if ($context ne 'auto') {
14007: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14008: }
14009: $outcome .= $clonemsg.$linefeed;
14010: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14011: # Copy all files
1.637 www 14012: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14013: # Restore URL
1.566 albertel 14014: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14015: # Restore title
1.566 albertel 14016: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14017: # Restore creation date, creator and creation context.
14018: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14019: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14020: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14021: # Mark as cloned
1.566 albertel 14022: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14023: # Need to clone grading mode
14024: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14025: $cenv{'grading'}=$newenv{'grading'};
14026: # Do not clone these environment entries
14027: &Apache::lonnet::del('environment',
14028: ['default_enrollment_start_date',
14029: 'default_enrollment_end_date',
14030: 'question.email',
14031: 'policy.email',
14032: 'comment.email',
14033: 'pch.users.denied',
1.725 raeburn 14034: 'plc.users.denied',
14035: 'hidefromcat',
1.1075.2.36 raeburn 14036: 'checkforpriv',
1.1075.2.59 raeburn 14037: 'categories',
14038: 'internal.uniquecode'],
1.638 www 14039: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 14040: if ($args->{'textbook'}) {
14041: $cenv{'internal.textbook'} = $args->{'textbook'};
14042: }
1.444 albertel 14043: }
1.566 albertel 14044:
1.444 albertel 14045: #
14046: # Set environment (will override cloned, if existing)
14047: #
14048: my @sections = ();
14049: my @xlists = ();
14050: if ($args->{'crstype'}) {
14051: $cenv{'type'}=$args->{'crstype'};
14052: }
14053: if ($args->{'crsid'}) {
14054: $cenv{'courseid'}=$args->{'crsid'};
14055: }
14056: if ($args->{'crscode'}) {
14057: $cenv{'internal.coursecode'}=$args->{'crscode'};
14058: }
14059: if ($args->{'crsquota'} ne '') {
14060: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14061: } else {
14062: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14063: }
14064: if ($args->{'ccuname'}) {
14065: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14066: ':'.$args->{'ccdomain'};
14067: } else {
14068: $cenv{'internal.courseowner'} = $args->{'curruser'};
14069: }
1.1075.2.31 raeburn 14070: if ($args->{'defaultcredits'}) {
14071: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14072: }
1.444 albertel 14073: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14074: if ($args->{'crssections'}) {
14075: $cenv{'internal.sectionnums'} = '';
14076: if ($args->{'crssections'} =~ m/,/) {
14077: @sections = split/,/,$args->{'crssections'};
14078: } else {
14079: $sections[0] = $args->{'crssections'};
14080: }
14081: if (@sections > 0) {
14082: foreach my $item (@sections) {
14083: my ($sec,$gp) = split/:/,$item;
14084: my $class = $args->{'crscode'}.$sec;
14085: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14086: $cenv{'internal.sectionnums'} .= $item.',';
14087: unless ($addcheck eq 'ok') {
14088: push @badclasses, $class;
14089: }
14090: }
14091: $cenv{'internal.sectionnums'} =~ s/,$//;
14092: }
14093: }
14094: # do not hide course coordinator from staff listing,
14095: # even if privileged
14096: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 14097: # add course coordinator's domain to domains to check for privileged users
14098: # if different to course domain
14099: if ($$crsudom ne $args->{'ccdomain'}) {
14100: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14101: }
1.444 albertel 14102: # add crosslistings
14103: if ($args->{'crsxlist'}) {
14104: $cenv{'internal.crosslistings'}='';
14105: if ($args->{'crsxlist'} =~ m/,/) {
14106: @xlists = split/,/,$args->{'crsxlist'};
14107: } else {
14108: $xlists[0] = $args->{'crsxlist'};
14109: }
14110: if (@xlists > 0) {
14111: foreach my $item (@xlists) {
14112: my ($xl,$gp) = split/:/,$item;
14113: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14114: $cenv{'internal.crosslistings'} .= $item.',';
14115: unless ($addcheck eq 'ok') {
14116: push @badclasses, $xl;
14117: }
14118: }
14119: $cenv{'internal.crosslistings'} =~ s/,$//;
14120: }
14121: }
14122: if ($args->{'autoadds'}) {
14123: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14124: }
14125: if ($args->{'autodrops'}) {
14126: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14127: }
14128: # check for notification of enrollment changes
14129: my @notified = ();
14130: if ($args->{'notify_owner'}) {
14131: if ($args->{'ccuname'} ne '') {
14132: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14133: }
14134: }
14135: if ($args->{'notify_dc'}) {
14136: if ($uname ne '') {
1.630 raeburn 14137: push(@notified,$uname.':'.$udom);
1.444 albertel 14138: }
14139: }
14140: if (@notified > 0) {
14141: my $notifylist;
14142: if (@notified > 1) {
14143: $notifylist = join(',',@notified);
14144: } else {
14145: $notifylist = $notified[0];
14146: }
14147: $cenv{'internal.notifylist'} = $notifylist;
14148: }
14149: if (@badclasses > 0) {
14150: my %lt=&Apache::lonlocal::texthash(
14151: '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',
14152: 'dnhr' => 'does not have rights to access enrollment in these classes',
14153: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14154: );
1.541 raeburn 14155: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14156: ' ('.$lt{'adby'}.')';
14157: if ($context eq 'auto') {
14158: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14159: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14160: foreach my $item (@badclasses) {
14161: if ($context eq 'auto') {
14162: $outcome .= " - $item\n";
14163: } else {
14164: $outcome .= "<li>$item</li>\n";
14165: }
14166: }
14167: if ($context eq 'auto') {
14168: $outcome .= $linefeed;
14169: } else {
1.566 albertel 14170: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14171: }
14172: }
1.444 albertel 14173: }
14174: if ($args->{'no_end_date'}) {
14175: $args->{'endaccess'} = 0;
14176: }
14177: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14178: $cenv{'internal.autoend'}=$args->{'enrollend'};
14179: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14180: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14181: if ($args->{'showphotos'}) {
14182: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14183: }
14184: $cenv{'internal.authtype'} = $args->{'authtype'};
14185: $cenv{'internal.autharg'} = $args->{'autharg'};
14186: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14187: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14188: 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');
14189: if ($context eq 'auto') {
14190: $outcome .= $krb_msg;
14191: } else {
1.566 albertel 14192: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14193: }
14194: $outcome .= $linefeed;
1.444 albertel 14195: }
14196: }
14197: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14198: if ($args->{'setpolicy'}) {
14199: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14200: }
14201: if ($args->{'setcontent'}) {
14202: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14203: }
14204: }
14205: if ($args->{'reshome'}) {
14206: $cenv{'reshome'}=$args->{'reshome'}.'/';
14207: $cenv{'reshome'}=~s/\/+$/\//;
14208: }
14209: #
14210: # course has keyed access
14211: #
14212: if ($args->{'setkeys'}) {
14213: $cenv{'keyaccess'}='yes';
14214: }
14215: # if specified, key authority is not course, but user
14216: # only active if keyaccess is yes
14217: if ($args->{'keyauth'}) {
1.487 albertel 14218: my ($user,$domain) = split(':',$args->{'keyauth'});
14219: $user = &LONCAPA::clean_username($user);
14220: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14221: if ($user ne '' && $domain ne '') {
1.487 albertel 14222: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14223: }
14224: }
14225:
1.1075.2.59 raeburn 14226: #
14227: # generate and store uniquecode (available to course requester), if course should have one.
14228: #
14229: if ($args->{'uniquecode'}) {
14230: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14231: if ($code) {
14232: $cenv{'internal.uniquecode'} = $code;
14233: my %crsinfo =
14234: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
14235: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
14236: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
14237: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
14238: }
14239: if (ref($coderef)) {
14240: $$coderef = $code;
14241: }
14242: }
14243: }
14244:
1.444 albertel 14245: if ($args->{'disresdis'}) {
14246: $cenv{'pch.roles.denied'}='st';
14247: }
14248: if ($args->{'disablechat'}) {
14249: $cenv{'plc.roles.denied'}='st';
14250: }
14251:
14252: # Record we've not yet viewed the Course Initialization Helper for this
14253: # course
14254: $cenv{'course.helper.not.run'} = 1;
14255: #
14256: # Use new Randomseed
14257: #
14258: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14259: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14260: #
14261: # The encryption code and receipt prefix for this course
14262: #
14263: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14264: $cenv{'internal.encpref'}=100+int(9*rand(99));
14265: #
14266: # By default, use standard grading
14267: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14268:
1.541 raeburn 14269: $outcome .= $linefeed.&mt('Setting environment').': '.
14270: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14271: #
14272: # Open all assignments
14273: #
14274: if ($args->{'openall'}) {
14275: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14276: my %storecontent = ($storeunder => time,
14277: $storeunder.'.type' => 'date_start');
14278:
14279: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14280: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14281: }
14282: #
14283: # Set first page
14284: #
14285: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14286: || ($cloneid)) {
1.445 albertel 14287: use LONCAPA::map;
1.444 albertel 14288: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14289:
14290: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14291: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14292:
1.444 albertel 14293: $outcome .= ($fatal?$errtext:'read ok').' - ';
14294: my $title; my $url;
14295: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14296: $title=&mt('Syllabus');
1.444 albertel 14297: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14298: } else {
1.963 raeburn 14299: $title=&mt('Table of Contents');
1.444 albertel 14300: $url='/adm/navmaps';
14301: }
1.445 albertel 14302:
14303: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14304: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14305:
14306: if ($errtext) { $fatal=2; }
1.541 raeburn 14307: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14308: }
1.566 albertel 14309:
14310: return (1,$outcome);
1.444 albertel 14311: }
14312:
1.1075.2.59 raeburn 14313: sub make_unique_code {
14314: my ($cdom,$cnum) = @_;
14315: # get lock on uniquecodes db
14316: my $lockhash = {
14317: $cnum."\0".'uniquecodes' => $env{'user.name'}.
14318: ':'.$env{'user.domain'},
14319: };
14320: my $tries = 0;
14321: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14322: my ($code,$error);
14323:
14324: while (($gotlock ne 'ok') && ($tries<3)) {
14325: $tries ++;
14326: sleep 1;
14327: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14328: }
14329: if ($gotlock eq 'ok') {
14330: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
14331: my $gotcode;
14332: my $attempts = 0;
14333: while ((!$gotcode) && ($attempts < 100)) {
14334: $code = &generate_code();
14335: if (!exists($currcodes{$code})) {
14336: $gotcode = 1;
14337: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
14338: $error = 'nostore';
14339: }
14340: }
14341: $attempts ++;
14342: }
14343: my @del_lock = ($cnum."\0".'uniquecodes');
14344: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
14345: } else {
14346: $error = 'nolock';
14347: }
14348: return ($code,$error);
14349: }
14350:
14351: sub generate_code {
14352: my $code;
14353: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
14354: for (my $i=0; $i<6; $i++) {
14355: my $lettnum = int (rand 2);
14356: my $item = '';
14357: if ($lettnum) {
14358: $item = $letts[int( rand(18) )];
14359: } else {
14360: $item = 1+int( rand(8) );
14361: }
14362: $code .= $item;
14363: }
14364: return $code;
14365: }
14366:
1.444 albertel 14367: ############################################################
14368: ############################################################
14369:
1.953 droeschl 14370: #SD
14371: # only Community and Course, or anything else?
1.378 raeburn 14372: sub course_type {
14373: my ($cid) = @_;
14374: if (!defined($cid)) {
14375: $cid = $env{'request.course.id'};
14376: }
1.404 albertel 14377: if (defined($env{'course.'.$cid.'.type'})) {
14378: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14379: } else {
14380: return 'Course';
1.377 raeburn 14381: }
14382: }
1.156 albertel 14383:
1.406 raeburn 14384: sub group_term {
14385: my $crstype = &course_type();
14386: my %names = (
14387: 'Course' => 'group',
1.865 raeburn 14388: 'Community' => 'group',
1.406 raeburn 14389: );
14390: return $names{$crstype};
14391: }
14392:
1.902 raeburn 14393: sub course_types {
1.1075.2.59 raeburn 14394: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 14395: my %typename = (
14396: official => 'Official course',
14397: unofficial => 'Unofficial course',
14398: community => 'Community',
1.1075.2.59 raeburn 14399: textbook => 'Textbook course',
1.902 raeburn 14400: );
14401: return (\@types,\%typename);
14402: }
14403:
1.156 albertel 14404: sub icon {
14405: my ($file)=@_;
1.505 albertel 14406: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14407: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14408: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14409: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14410: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14411: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14412: $curfext.".gif") {
14413: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14414: $curfext.".gif";
14415: }
14416: }
1.249 albertel 14417: return &lonhttpdurl($iconname);
1.154 albertel 14418: }
1.84 albertel 14419:
1.575 albertel 14420: sub lonhttpdurl {
1.692 www 14421: #
14422: # Had been used for "small fry" static images on separate port 8080.
14423: # Modify here if lightweight http functionality desired again.
14424: # Currently eliminated due to increasing firewall issues.
14425: #
1.575 albertel 14426: my ($url)=@_;
1.692 www 14427: return $url;
1.215 albertel 14428: }
14429:
1.213 albertel 14430: sub connection_aborted {
14431: my ($r)=@_;
14432: $r->print(" ");$r->rflush();
14433: my $c = $r->connection;
14434: return $c->aborted();
14435: }
14436:
1.221 foxr 14437: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14438: # strings as 'strings'.
14439: sub escape_single {
1.221 foxr 14440: my ($input) = @_;
1.223 albertel 14441: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14442: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14443: return $input;
14444: }
1.223 albertel 14445:
1.222 foxr 14446: # Same as escape_single, but escape's "'s This
14447: # can be used for "strings"
14448: sub escape_double {
14449: my ($input) = @_;
14450: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14451: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14452: return $input;
14453: }
1.223 albertel 14454:
1.222 foxr 14455: # Escapes the last element of a full URL.
14456: sub escape_url {
14457: my ($url) = @_;
1.238 raeburn 14458: my @urlslices = split(/\//, $url,-1);
1.369 www 14459: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14460: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14461: }
1.462 albertel 14462:
1.820 raeburn 14463: sub compare_arrays {
14464: my ($arrayref1,$arrayref2) = @_;
14465: my (@difference,%count);
14466: @difference = ();
14467: %count = ();
14468: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14469: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14470: foreach my $element (keys(%count)) {
14471: if ($count{$element} == 1) {
14472: push(@difference,$element);
14473: }
14474: }
14475: }
14476: return @difference;
14477: }
14478:
1.817 bisitz 14479: # -------------------------------------------------------- Initialize user login
1.462 albertel 14480: sub init_user_environment {
1.463 albertel 14481: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14482: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14483:
14484: my $public=($username eq 'public' && $domain eq 'public');
14485:
14486: # See if old ID present, if so, remove
14487:
1.1062 raeburn 14488: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14489: my $now=time;
14490:
14491: if ($public) {
14492: my $max_public=100;
14493: my $oldest;
14494: my $oldest_time=0;
14495: for(my $next=1;$next<=$max_public;$next++) {
14496: if (-e $lonids."/publicuser_$next.id") {
14497: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14498: if ($mtime<$oldest_time || !$oldest_time) {
14499: $oldest_time=$mtime;
14500: $oldest=$next;
14501: }
14502: } else {
14503: $cookie="publicuser_$next";
14504: last;
14505: }
14506: }
14507: if (!$cookie) { $cookie="publicuser_$oldest"; }
14508: } else {
1.463 albertel 14509: # if this isn't a robot, kill any existing non-robot sessions
14510: if (!$args->{'robot'}) {
14511: opendir(DIR,$lonids);
14512: while ($filename=readdir(DIR)) {
14513: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14514: unlink($lonids.'/'.$filename);
14515: }
1.462 albertel 14516: }
1.463 albertel 14517: closedir(DIR);
1.462 albertel 14518: }
14519: # Give them a new cookie
1.463 albertel 14520: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14521: : $now.$$.int(rand(10000)));
1.463 albertel 14522: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14523:
14524: # Initialize roles
14525:
1.1062 raeburn 14526: ($userroles,$firstaccenv,$timerintenv) =
14527: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14528: }
14529: # ------------------------------------ Check browser type and MathML capability
14530:
1.1075.2.77 raeburn 14531: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
14532: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 14533:
14534: # ------------------------------------------------------------- Get environment
14535:
14536: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14537: my ($tmp) = keys(%userenv);
14538: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14539: } else {
14540: undef(%userenv);
14541: }
14542: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14543: $form->{'interface'}=$userenv{'interface'};
14544: }
14545: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14546:
14547: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14548: foreach my $option ('interface','localpath','localres') {
14549: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14550: }
14551: # --------------------------------------------------------- Write first profile
14552:
14553: {
14554: my %initial_env =
14555: ("user.name" => $username,
14556: "user.domain" => $domain,
14557: "user.home" => $authhost,
14558: "browser.type" => $clientbrowser,
14559: "browser.version" => $clientversion,
14560: "browser.mathml" => $clientmathml,
14561: "browser.unicode" => $clientunicode,
14562: "browser.os" => $clientos,
1.1075.2.42 raeburn 14563: "browser.mobile" => $clientmobile,
14564: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 14565: "browser.osversion" => $clientosversion,
1.462 albertel 14566: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14567: "request.course.fn" => '',
14568: "request.course.uri" => '',
14569: "request.course.sec" => '',
14570: "request.role" => 'cm',
14571: "request.role.adv" => $env{'user.adv'},
14572: "request.host" => $ENV{'REMOTE_ADDR'},);
14573:
14574: if ($form->{'localpath'}) {
14575: $initial_env{"browser.localpath"} = $form->{'localpath'};
14576: $initial_env{"browser.localres"} = $form->{'localres'};
14577: }
14578:
14579: if ($form->{'interface'}) {
14580: $form->{'interface'}=~s/\W//gs;
14581: $initial_env{"browser.interface"} = $form->{'interface'};
14582: $env{'browser.interface'}=$form->{'interface'};
14583: }
14584:
1.1075.2.54 raeburn 14585: if ($form->{'iptoken'}) {
14586: my $lonhost = $r->dir_config('lonHostID');
14587: $initial_env{"user.noloadbalance"} = $lonhost;
14588: $env{'user.noloadbalance'} = $lonhost;
14589: }
14590:
1.981 raeburn 14591: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14592: my %domdef;
14593: unless ($domain eq 'public') {
14594: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14595: }
1.980 raeburn 14596:
1.1075.2.7 raeburn 14597: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14598: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14599: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14600: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14601: }
14602:
1.1075.2.59 raeburn 14603: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 14604: $userenv{'canrequest.'.$crstype} =
14605: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14606: 'reload','requestcourses',
14607: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14608: }
14609:
1.1075.2.14 raeburn 14610: $userenv{'canrequest.author'} =
14611: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14612: 'reload','requestauthor',
14613: \%userenv,\%domdef,\%is_adv);
14614: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14615: $domain,$username);
14616: my $reqstatus = $reqauthor{'author_status'};
14617: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14618: if (ref($reqauthor{'author'}) eq 'HASH') {
14619: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14620: $reqauthor{'author'}{'timestamp'};
14621: }
14622: }
14623:
1.462 albertel 14624: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14625:
1.462 albertel 14626: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14627: &GDBM_WRCREAT(),0640)) {
14628: &_add_to_env(\%disk_env,\%initial_env);
14629: &_add_to_env(\%disk_env,\%userenv,'environment.');
14630: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14631: if (ref($firstaccenv) eq 'HASH') {
14632: &_add_to_env(\%disk_env,$firstaccenv);
14633: }
14634: if (ref($timerintenv) eq 'HASH') {
14635: &_add_to_env(\%disk_env,$timerintenv);
14636: }
1.463 albertel 14637: if (ref($args->{'extra_env'})) {
14638: &_add_to_env(\%disk_env,$args->{'extra_env'});
14639: }
1.462 albertel 14640: untie(%disk_env);
14641: } else {
1.705 tempelho 14642: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14643: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14644: return 'error: '.$!;
14645: }
14646: }
14647: $env{'request.role'}='cm';
14648: $env{'request.role.adv'}=$env{'user.adv'};
14649: $env{'browser.type'}=$clientbrowser;
14650:
14651: return $cookie;
14652:
14653: }
14654:
14655: sub _add_to_env {
14656: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14657: if (ref($env_data) eq 'HASH') {
14658: while (my ($key,$value) = each(%$env_data)) {
14659: $idf->{$prefix.$key} = $value;
14660: $env{$prefix.$key} = $value;
14661: }
1.462 albertel 14662: }
14663: }
14664:
1.685 tempelho 14665: # --- Get the symbolic name of a problem and the url
14666: sub get_symb {
14667: my ($request,$silent) = @_;
1.726 raeburn 14668: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14669: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14670: if ($symb eq '') {
14671: if (!$silent) {
1.1071 raeburn 14672: if (ref($request)) {
14673: $request->print("Unable to handle ambiguous references:$url:.");
14674: }
1.685 tempelho 14675: return ();
14676: }
14677: }
14678: &Apache::lonenc::check_decrypt(\$symb);
14679: return ($symb);
14680: }
14681:
14682: # --------------------------------------------------------------Get annotation
14683:
14684: sub get_annotation {
14685: my ($symb,$enc) = @_;
14686:
14687: my $key = $symb;
14688: if (!$enc) {
14689: $key =
14690: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14691: }
14692: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14693: return $annotation{$key};
14694: }
14695:
14696: sub clean_symb {
1.731 raeburn 14697: my ($symb,$delete_enc) = @_;
1.685 tempelho 14698:
14699: &Apache::lonenc::check_decrypt(\$symb);
14700: my $enc = $env{'request.enc'};
1.731 raeburn 14701: if ($delete_enc) {
1.730 raeburn 14702: delete($env{'request.enc'});
14703: }
1.685 tempelho 14704:
14705: return ($symb,$enc);
14706: }
1.462 albertel 14707:
1.1075.2.69 raeburn 14708: ############################################################
14709: ############################################################
14710:
14711: =pod
14712:
14713: =head1 Routines for building display used to search for courses
14714:
14715:
14716: =over 4
14717:
14718: =item * &build_filters()
14719:
14720: Create markup for a table used to set filters to use when selecting
14721: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
14722: and quotacheck.pl
14723:
14724:
14725: Inputs:
14726:
14727: filterlist - anonymous array of fields to include as potential filters
14728:
14729: crstype - course type
14730:
14731: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
14732: to pop-open a course selector (will contain "extra element").
14733:
14734: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
14735:
14736: filter - anonymous hash of criteria and their values
14737:
14738: action - form action
14739:
14740: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
14741:
14742: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
14743:
14744: cloneruname - username of owner of new course who wants to clone
14745:
14746: clonerudom - domain of owner of new course who wants to clone
14747:
14748: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
14749:
14750: codetitlesref - reference to array of titles of components in institutional codes (official courses)
14751:
14752: codedom - domain
14753:
14754: formname - value of form element named "form".
14755:
14756: fixeddom - domain, if fixed.
14757:
14758: prevphase - value to assign to form element named "phase" when going back to the previous screen
14759:
14760: cnameelement - name of form element in form on opener page which will receive title of selected course
14761:
14762: cnumelement - name of form element in form on opener page which will receive courseID of selected course
14763:
14764: cdomelement - name of form element in form on opener page which will receive domain of selected course
14765:
14766: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
14767:
14768: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
14769:
14770: clonewarning - warning message about missing information for intended course owner when DC creates a course
14771:
14772:
14773: Returns: $output - HTML for display of search criteria, and hidden form elements.
14774:
14775:
14776: Side Effects: None
14777:
14778: =cut
14779:
14780: # ---------------------------------------------- search for courses based on last activity etc.
14781:
14782: sub build_filters {
14783: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
14784: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
14785: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
14786: $cnameelement,$cnumelement,$cdomelement,$setroles,
14787: $clonetext,$clonewarning) = @_;
14788: my ($list,$jscript);
14789: my $onchange = 'javascript:updateFilters(this)';
14790: my ($domainselectform,$sincefilterform,$createdfilterform,
14791: $ownerdomselectform,$persondomselectform,$instcodeform,
14792: $typeselectform,$instcodetitle);
14793: if ($formname eq '') {
14794: $formname = $caller;
14795: }
14796: foreach my $item (@{$filterlist}) {
14797: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
14798: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
14799: if ($item eq 'domainfilter') {
14800: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
14801: } elsif ($item eq 'coursefilter') {
14802: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
14803: } elsif ($item eq 'ownerfilter') {
14804: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
14805: } elsif ($item eq 'ownerdomfilter') {
14806: $filter->{'ownerdomfilter'} =
14807: &LONCAPA::clean_domain($filter->{$item});
14808: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
14809: 'ownerdomfilter',1);
14810: } elsif ($item eq 'personfilter') {
14811: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
14812: } elsif ($item eq 'persondomfilter') {
14813: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
14814: 'persondomfilter',1);
14815: } else {
14816: $filter->{$item} =~ s/\W//g;
14817: }
14818: if (!$filter->{$item}) {
14819: $filter->{$item} = '';
14820: }
14821: }
14822: if ($item eq 'domainfilter') {
14823: my $allow_blank = 1;
14824: if ($formname eq 'portform') {
14825: $allow_blank=0;
14826: } elsif ($formname eq 'studentform') {
14827: $allow_blank=0;
14828: }
14829: if ($fixeddom) {
14830: $domainselectform = '<input type="hidden" name="domainfilter"'.
14831: ' value="'.$codedom.'" />'.
14832: &Apache::lonnet::domain($codedom,'description');
14833: } else {
14834: $domainselectform = &select_dom_form($filter->{$item},
14835: 'domainfilter',
14836: $allow_blank,'',$onchange);
14837: }
14838: } else {
14839: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
14840: }
14841: }
14842:
14843: # last course activity filter and selection
14844: $sincefilterform = &timebased_select_form('sincefilter',$filter);
14845:
14846: # course created filter and selection
14847: if (exists($filter->{'createdfilter'})) {
14848: $createdfilterform = &timebased_select_form('createdfilter',$filter);
14849: }
14850:
14851: my %lt = &Apache::lonlocal::texthash(
14852: 'cac' => "$crstype Activity",
14853: 'ccr' => "$crstype Created",
14854: 'cde' => "$crstype Title",
14855: 'cdo' => "$crstype Domain",
14856: 'ins' => 'Institutional Code',
14857: 'inc' => 'Institutional Categorization',
14858: 'cow' => "$crstype Owner/Co-owner",
14859: 'cop' => "$crstype Personnel Includes",
14860: 'cog' => 'Type',
14861: );
14862:
14863: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
14864: my $typeval = 'Course';
14865: if ($crstype eq 'Community') {
14866: $typeval = 'Community';
14867: }
14868: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
14869: } else {
14870: $typeselectform = '<select name="type" size="1"';
14871: if ($onchange) {
14872: $typeselectform .= ' onchange="'.$onchange.'"';
14873: }
14874: $typeselectform .= '>'."\n";
14875: foreach my $posstype ('Course','Community') {
14876: $typeselectform.='<option value="'.$posstype.'"'.
14877: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
14878: }
14879: $typeselectform.="</select>";
14880: }
14881:
14882: my ($cloneableonlyform,$cloneabletitle);
14883: if (exists($filter->{'cloneableonly'})) {
14884: my $cloneableon = '';
14885: my $cloneableoff = ' checked="checked"';
14886: if ($filter->{'cloneableonly'}) {
14887: $cloneableon = $cloneableoff;
14888: $cloneableoff = '';
14889: }
14890: $cloneableonlyform = '<span class="LC_nobreak"><label><input type="radio" name="cloneableonly" value="1" '.$cloneableon.'/> '.&mt('Required').'</label>'.(' 'x3).'<label><input type="radio" name="cloneableonly" value="" '.$cloneableoff.' /> '.&mt('No restriction').'</label></span>';
14891: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 14892: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 14893: } else {
14894: $cloneabletitle = &mt('Cloneable by you');
14895: }
14896: }
14897: my $officialjs;
14898: if ($crstype eq 'Course') {
14899: if (exists($filter->{'instcodefilter'})) {
14900: # if (($fixeddom) || ($formname eq 'requestcrs') ||
14901: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
14902: if ($codedom) {
14903: $officialjs = 1;
14904: ($instcodeform,$jscript,$$numtitlesref) =
14905: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
14906: $officialjs,$codetitlesref);
14907: if ($jscript) {
14908: $jscript = '<script type="text/javascript">'."\n".
14909: '// <![CDATA['."\n".
14910: $jscript."\n".
14911: '// ]]>'."\n".
14912: '</script>'."\n";
14913: }
14914: }
14915: if ($instcodeform eq '') {
14916: $instcodeform =
14917: '<input type="text" name="instcodefilter" size="10" value="'.
14918: $list->{'instcodefilter'}.'" />';
14919: $instcodetitle = $lt{'ins'};
14920: } else {
14921: $instcodetitle = $lt{'inc'};
14922: }
14923: if ($fixeddom) {
14924: $instcodetitle .= '<br />('.$codedom.')';
14925: }
14926: }
14927: }
14928: my $output = qq|
14929: <form method="post" name="filterpicker" action="$action">
14930: <input type="hidden" name="form" value="$formname" />
14931: |;
14932: if ($formname eq 'modifycourse') {
14933: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
14934: '<input type="hidden" name="prevphase" value="'.
14935: $prevphase.'" />'."\n";
14936: } elsif ($formname ne 'quotacheck') {
14937: my $name_input;
14938: if ($cnameelement ne '') {
14939: $name_input = '<input type="hidden" name="cnameelement" value="'.
14940: $cnameelement.'" />';
14941: }
14942: $output .= qq|
14943: <input type="hidden" name="cnumelement" value="$cnumelement" />
14944: <input type="hidden" name="cdomelement" value="$cdomelement" />
14945: $name_input
14946: $roleelement
14947: $multelement
14948: $typeelement
14949: |;
14950: if ($formname eq 'portform') {
14951: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
14952: }
14953: }
14954: if ($fixeddom) {
14955: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
14956: }
14957: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
14958: if ($sincefilterform) {
14959: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
14960: .$sincefilterform
14961: .&Apache::lonhtmlcommon::row_closure();
14962: }
14963: if ($createdfilterform) {
14964: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
14965: .$createdfilterform
14966: .&Apache::lonhtmlcommon::row_closure();
14967: }
14968: if ($domainselectform) {
14969: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
14970: .$domainselectform
14971: .&Apache::lonhtmlcommon::row_closure();
14972: }
14973: if ($typeselectform) {
14974: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
14975: $output .= $typeselectform;
14976: } else {
14977: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
14978: .$typeselectform
14979: .&Apache::lonhtmlcommon::row_closure();
14980: }
14981: }
14982: if ($instcodeform) {
14983: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
14984: .$instcodeform
14985: .&Apache::lonhtmlcommon::row_closure();
14986: }
14987: if (exists($filter->{'ownerfilter'})) {
14988: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
14989: '<table><tr><td>'.&mt('Username').'<br />'.
14990: '<input type="text" name="ownerfilter" size="20" value="'.
14991: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
14992: $ownerdomselectform.'</td></tr></table>'.
14993: &Apache::lonhtmlcommon::row_closure();
14994: }
14995: if (exists($filter->{'personfilter'})) {
14996: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
14997: '<table><tr><td>'.&mt('Username').'<br />'.
14998: '<input type="text" name="personfilter" size="20" value="'.
14999: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15000: $persondomselectform.'</td></tr></table>'.
15001: &Apache::lonhtmlcommon::row_closure();
15002: }
15003: if (exists($filter->{'coursefilter'})) {
15004: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15005: .'<input type="text" name="coursefilter" size="25" value="'
15006: .$list->{'coursefilter'}.'" />'
15007: .&Apache::lonhtmlcommon::row_closure();
15008: }
15009: if ($cloneableonlyform) {
15010: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15011: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15012: }
15013: if (exists($filter->{'descriptfilter'})) {
15014: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15015: .'<input type="text" name="descriptfilter" size="40" value="'
15016: .$list->{'descriptfilter'}.'" />'
15017: .&Apache::lonhtmlcommon::row_closure(1);
15018: }
15019: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15020: '<input type="hidden" name="updater" value="" />'."\n".
15021: '<input type="submit" name="gosearch" value="'.
15022: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15023: return $jscript.$clonewarning.$output;
15024: }
15025:
15026: =pod
15027:
15028: =item * &timebased_select_form()
15029:
15030: Create markup for a dropdown list used to select a time-based
15031: filter e.g., Course Activity, Course Created, when searching for courses
15032: or communities
15033:
15034: Inputs:
15035:
15036: item - name of form element (sincefilter or createdfilter)
15037:
15038: filter - anonymous hash of criteria and their values
15039:
15040: Returns: HTML for a select box contained a blank, then six time selections,
15041: with value set in incoming form variables currently selected.
15042:
15043: Side Effects: None
15044:
15045: =cut
15046:
15047: sub timebased_select_form {
15048: my ($item,$filter) = @_;
15049: if (ref($filter) eq 'HASH') {
15050: $filter->{$item} =~ s/[^\d-]//g;
15051: if (!$filter->{$item}) { $filter->{$item}=-1; }
15052: return &select_form(
15053: $filter->{$item},
15054: $item,
15055: { '-1' => '',
15056: '86400' => &mt('today'),
15057: '604800' => &mt('last week'),
15058: '2592000' => &mt('last month'),
15059: '7776000' => &mt('last three months'),
15060: '15552000' => &mt('last six months'),
15061: '31104000' => &mt('last year'),
15062: 'select_form_order' =>
15063: ['-1','86400','604800','2592000','7776000',
15064: '15552000','31104000']});
15065: }
15066: }
15067:
15068: =pod
15069:
15070: =item * &js_changer()
15071:
15072: Create script tag containing Javascript used to submit course search form
15073: when course type or domain is changed, and also to hide 'Searching ...' on
15074: page load completion for page showing search result.
15075:
15076: Inputs: None
15077:
15078: Returns: markup containing updateFilters() and hideSearching() javascript functions.
15079:
15080: Side Effects: None
15081:
15082: =cut
15083:
15084: sub js_changer {
15085: return <<ENDJS;
15086: <script type="text/javascript">
15087: // <![CDATA[
15088: function updateFilters(caller) {
15089: if (typeof(caller) != "undefined") {
15090: document.filterpicker.updater.value = caller.name;
15091: }
15092: document.filterpicker.submit();
15093: }
15094:
15095: function hideSearching() {
15096: if (document.getElementById('searching')) {
15097: document.getElementById('searching').style.display = 'none';
15098: }
15099: return;
15100: }
15101:
15102: // ]]>
15103: </script>
15104:
15105: ENDJS
15106: }
15107:
15108: =pod
15109:
15110: =item * &search_courses()
15111:
15112: Process selected filters form course search form and pass to lonnet::courseiddump
15113: to retrieve a hash for which keys are courseIDs which match the selected filters.
15114:
15115: Inputs:
15116:
15117: dom - domain being searched
15118:
15119: type - course type ('Course' or 'Community' or '.' if any).
15120:
15121: filter - anonymous hash of criteria and their values
15122:
15123: numtitles - for institutional codes - number of categories
15124:
15125: cloneruname - optional username of new course owner
15126:
15127: clonerudom - optional domain of new course owner
15128:
15129: domcloner - Optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
15130: (used when DC is using course creation form)
15131:
15132: codetitles - reference to array of titles of components in institutional codes (official courses).
15133:
15134:
15135: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
15136:
15137:
15138: Side Effects: None
15139:
15140: =cut
15141:
15142:
15143: sub search_courses {
15144: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_;
15145: my (%courses,%showcourses,$cloner);
15146: if (($filter->{'ownerfilter'} ne '') ||
15147: ($filter->{'ownerdomfilter'} ne '')) {
15148: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
15149: $filter->{'ownerdomfilter'};
15150: }
15151: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
15152: if (!$filter->{$item}) {
15153: $filter->{$item}='.';
15154: }
15155: }
15156: my $now = time;
15157: my $timefilter =
15158: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
15159: my ($createdbefore,$createdafter);
15160: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
15161: $createdbefore = $now;
15162: $createdafter = $now-$filter->{'createdfilter'};
15163: }
15164: my ($instcodefilter,$regexpok);
15165: if ($numtitles) {
15166: if ($env{'form.official'} eq 'on') {
15167: $instcodefilter =
15168: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15169: $regexpok = 1;
15170: } elsif ($env{'form.official'} eq 'off') {
15171: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15172: unless ($instcodefilter eq '') {
15173: $regexpok = -1;
15174: }
15175: }
15176: } else {
15177: $instcodefilter = $filter->{'instcodefilter'};
15178: }
15179: if ($instcodefilter eq '') { $instcodefilter = '.'; }
15180: if ($type eq '') { $type = '.'; }
15181:
15182: if (($clonerudom ne '') && ($cloneruname ne '')) {
15183: $cloner = $cloneruname.':'.$clonerudom;
15184: }
15185: %courses = &Apache::lonnet::courseiddump($dom,
15186: $filter->{'descriptfilter'},
15187: $timefilter,
15188: $instcodefilter,
15189: $filter->{'combownerfilter'},
15190: $filter->{'coursefilter'},
15191: undef,undef,$type,$regexpok,undef,undef,
15192: undef,undef,$cloner,$env{'form.cc_clone'},
15193: $filter->{'cloneableonly'},
15194: $createdbefore,$createdafter,undef,
15195: $domcloner);
15196: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
15197: my $ccrole;
15198: if ($type eq 'Community') {
15199: $ccrole = 'co';
15200: } else {
15201: $ccrole = 'cc';
15202: }
15203: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
15204: $filter->{'persondomfilter'},
15205: 'userroles',undef,
15206: [$ccrole,'in','ad','ep','ta','cr'],
15207: $dom);
15208: foreach my $role (keys(%rolehash)) {
15209: my ($cnum,$cdom,$courserole) = split(':',$role);
15210: my $cid = $cdom.'_'.$cnum;
15211: if (exists($courses{$cid})) {
15212: if (ref($courses{$cid}) eq 'HASH') {
15213: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
15214: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
15215: push (@{$courses{$cid}{roles}},$courserole);
15216: }
15217: } else {
15218: $courses{$cid}{roles} = [$courserole];
15219: }
15220: $showcourses{$cid} = $courses{$cid};
15221: }
15222: }
15223: }
15224: %courses = %showcourses;
15225: }
15226: return %courses;
15227: }
15228:
15229:
15230: =pod
15231:
15232: =back
15233:
15234: =cut
15235:
15236:
1.1075.2.11 raeburn 15237: sub update_content_constraints {
15238: my ($cdom,$cnum,$chome,$cid) = @_;
15239: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15240: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
15241: my %checkresponsetypes;
15242: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
15243: my ($item,$name,$value) = split(/:/,$key);
15244: if ($item eq 'resourcetag') {
15245: if ($name eq 'responsetype') {
15246: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
15247: }
15248: }
15249: }
15250: my $navmap = Apache::lonnavmaps::navmap->new();
15251: if (defined($navmap)) {
15252: my %allresponses;
15253: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
15254: my %responses = $res->responseTypes();
15255: foreach my $key (keys(%responses)) {
15256: next unless(exists($checkresponsetypes{$key}));
15257: $allresponses{$key} += $responses{$key};
15258: }
15259: }
15260: foreach my $key (keys(%allresponses)) {
15261: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
15262: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
15263: ($reqdmajor,$reqdminor) = ($major,$minor);
15264: }
15265: }
15266: undef($navmap);
15267: }
15268: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
15269: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
15270: }
15271: return;
15272: }
15273:
1.1075.2.27 raeburn 15274: sub allmaps_incourse {
15275: my ($cdom,$cnum,$chome,$cid) = @_;
15276: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
15277: $cid = $env{'request.course.id'};
15278: $cdom = $env{'course.'.$cid.'.domain'};
15279: $cnum = $env{'course.'.$cid.'.num'};
15280: $chome = $env{'course.'.$cid.'.home'};
15281: }
15282: my %allmaps = ();
15283: my $lastchange =
15284: &Apache::lonnet::get_coursechange($cdom,$cnum);
15285: if ($lastchange > $env{'request.course.tied'}) {
15286: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
15287: unless ($ferr) {
15288: &update_content_constraints($cdom,$cnum,$chome,$cid);
15289: }
15290: }
15291: my $navmap = Apache::lonnavmaps::navmap->new();
15292: if (defined($navmap)) {
15293: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
15294: $allmaps{$res->src()} = 1;
15295: }
15296: }
15297: return \%allmaps;
15298: }
15299:
1.1075.2.11 raeburn 15300: sub parse_supplemental_title {
15301: my ($title) = @_;
15302:
15303: my ($foldertitle,$renametitle);
15304: if ($title =~ /&&&/) {
15305: $title = &HTML::Entites::decode($title);
15306: }
15307: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
15308: $renametitle=$4;
15309: my ($time,$uname,$udom) = ($1,$2,$3);
15310: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
15311: my $name = &plainname($uname,$udom);
15312: $name = &HTML::Entities::encode($name,'"<>&\'');
15313: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
15314: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
15315: $name.': <br />'.$foldertitle;
15316: }
15317: if (wantarray) {
15318: return ($title,$foldertitle,$renametitle);
15319: }
15320: return $title;
15321: }
15322:
1.1075.2.43 raeburn 15323: sub recurse_supplemental {
15324: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
15325: if ($suppmap) {
15326: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
15327: if ($fatal) {
15328: $errors ++;
15329: } else {
15330: if ($#LONCAPA::map::resources > 0) {
15331: foreach my $res (@LONCAPA::map::resources) {
15332: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
15333: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 15334: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
15335: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 15336: } else {
15337: $numfiles ++;
15338: }
15339: }
15340: }
15341: }
15342: }
15343: }
15344: return ($numfiles,$errors);
15345: }
15346:
1.1075.2.18 raeburn 15347: sub symb_to_docspath {
15348: my ($symb) = @_;
15349: return unless ($symb);
15350: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
15351: if ($resurl=~/\.(sequence|page)$/) {
15352: $mapurl=$resurl;
15353: } elsif ($resurl eq 'adm/navmaps') {
15354: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
15355: }
15356: my $mapresobj;
15357: my $navmap = Apache::lonnavmaps::navmap->new();
15358: if (ref($navmap)) {
15359: $mapresobj = $navmap->getResourceByUrl($mapurl);
15360: }
15361: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
15362: my $type=$2;
15363: my $path;
15364: if (ref($mapresobj)) {
15365: my $pcslist = $mapresobj->map_hierarchy();
15366: if ($pcslist ne '') {
15367: foreach my $pc (split(/,/,$pcslist)) {
15368: next if ($pc <= 1);
15369: my $res = $navmap->getByMapPc($pc);
15370: if (ref($res)) {
15371: my $thisurl = $res->src();
15372: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
15373: my $thistitle = $res->title();
15374: $path .= '&'.
15375: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 15376: &escape($thistitle).
1.1075.2.18 raeburn 15377: ':'.$res->randompick().
15378: ':'.$res->randomout().
15379: ':'.$res->encrypted().
15380: ':'.$res->randomorder().
15381: ':'.$res->is_page();
15382: }
15383: }
15384: }
15385: $path =~ s/^\&//;
15386: my $maptitle = $mapresobj->title();
15387: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 15388: $maptitle = 'Main Content';
1.1075.2.18 raeburn 15389: }
15390: $path .= (($path ne '')? '&' : '').
15391: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 15392: &escape($maptitle).
1.1075.2.18 raeburn 15393: ':'.$mapresobj->randompick().
15394: ':'.$mapresobj->randomout().
15395: ':'.$mapresobj->encrypted().
15396: ':'.$mapresobj->randomorder().
15397: ':'.$mapresobj->is_page();
15398: } else {
15399: my $maptitle = &Apache::lonnet::gettitle($mapurl);
15400: my $ispage = (($type eq 'page')? 1 : '');
15401: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 15402: $maptitle = 'Main Content';
1.1075.2.18 raeburn 15403: }
15404: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 15405: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 15406: }
15407: unless ($mapurl eq 'default') {
15408: $path = 'default&'.
1.1075.2.46 raeburn 15409: &escape('Main Content').
1.1075.2.18 raeburn 15410: ':::::&'.$path;
15411: }
15412: return $path;
15413: }
15414:
1.1075.2.14 raeburn 15415: sub captcha_display {
15416: my ($context,$lonhost) = @_;
15417: my ($output,$error);
15418: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
15419: if ($captcha eq 'original') {
15420: $output = &create_captcha();
15421: unless ($output) {
15422: $error = 'captcha';
15423: }
15424: } elsif ($captcha eq 'recaptcha') {
15425: $output = &create_recaptcha($pubkey);
15426: unless ($output) {
15427: $error = 'recaptcha';
15428: }
15429: }
1.1075.2.66 raeburn 15430: return ($output,$error,$captcha);
1.1075.2.14 raeburn 15431: }
15432:
15433: sub captcha_response {
15434: my ($context,$lonhost) = @_;
15435: my ($captcha_chk,$captcha_error);
15436: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
15437: if ($captcha eq 'original') {
15438: ($captcha_chk,$captcha_error) = &check_captcha();
15439: } elsif ($captcha eq 'recaptcha') {
15440: $captcha_chk = &check_recaptcha($privkey);
15441: } else {
15442: $captcha_chk = 1;
15443: }
15444: return ($captcha_chk,$captcha_error);
15445: }
15446:
15447: sub get_captcha_config {
15448: my ($context,$lonhost) = @_;
15449: my ($captcha,$pubkey,$privkey,$hashtocheck);
15450: my $hostname = &Apache::lonnet::hostname($lonhost);
15451: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
15452: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
15453: if ($context eq 'usercreation') {
15454: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
15455: if (ref($domconfig{$context}) eq 'HASH') {
15456: $hashtocheck = $domconfig{$context}{'cancreate'};
15457: if (ref($hashtocheck) eq 'HASH') {
15458: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
15459: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
15460: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
15461: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
15462: }
15463: if ($privkey && $pubkey) {
15464: $captcha = 'recaptcha';
15465: } else {
15466: $captcha = 'original';
15467: }
15468: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
15469: $captcha = 'original';
15470: }
15471: }
15472: } else {
15473: $captcha = 'captcha';
15474: }
15475: } elsif ($context eq 'login') {
15476: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
15477: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
15478: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
15479: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
15480: if ($privkey && $pubkey) {
15481: $captcha = 'recaptcha';
15482: } else {
15483: $captcha = 'original';
15484: }
15485: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
15486: $captcha = 'original';
15487: }
15488: }
15489: return ($captcha,$pubkey,$privkey);
15490: }
15491:
15492: sub create_captcha {
15493: my %captcha_params = &captcha_settings();
15494: my ($output,$maxtries,$tries) = ('',10,0);
15495: while ($tries < $maxtries) {
15496: $tries ++;
15497: my $captcha = Authen::Captcha->new (
15498: output_folder => $captcha_params{'output_dir'},
15499: data_folder => $captcha_params{'db_dir'},
15500: );
15501: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
15502:
15503: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
15504: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
15505: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 15506: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
15507: '<br />'.
15508: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 15509: last;
15510: }
15511: }
15512: return $output;
15513: }
15514:
15515: sub captcha_settings {
15516: my %captcha_params = (
15517: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
15518: www_output_dir => "/captchaspool",
15519: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
15520: numchars => '5',
15521: );
15522: return %captcha_params;
15523: }
15524:
15525: sub check_captcha {
15526: my ($captcha_chk,$captcha_error);
15527: my $code = $env{'form.code'};
15528: my $md5sum = $env{'form.crypt'};
15529: my %captcha_params = &captcha_settings();
15530: my $captcha = Authen::Captcha->new(
15531: output_folder => $captcha_params{'output_dir'},
15532: data_folder => $captcha_params{'db_dir'},
15533: );
1.1075.2.26 raeburn 15534: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 15535: my %captcha_hash = (
15536: 0 => 'Code not checked (file error)',
15537: -1 => 'Failed: code expired',
15538: -2 => 'Failed: invalid code (not in database)',
15539: -3 => 'Failed: invalid code (code does not match crypt)',
15540: );
15541: if ($captcha_chk != 1) {
15542: $captcha_error = $captcha_hash{$captcha_chk}
15543: }
15544: return ($captcha_chk,$captcha_error);
15545: }
15546:
15547: sub create_recaptcha {
15548: my ($pubkey) = @_;
1.1075.2.51 raeburn 15549: my $use_ssl;
15550: if ($ENV{'SERVER_PORT'} == 443) {
15551: $use_ssl = 1;
15552: }
1.1075.2.14 raeburn 15553: my $captcha = Captcha::reCAPTCHA->new;
15554: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1075.2.51 raeburn 15555: $captcha->get_html($pubkey,undef,$use_ssl).
1.1075.2.14 raeburn 15556: &mt('If either word is hard to read, [_1] will replace them.',
1.1075.2.39 raeburn 15557: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1075.2.14 raeburn 15558: '<br /><br />';
15559: }
15560:
15561: sub check_recaptcha {
15562: my ($privkey) = @_;
15563: my $captcha_chk;
15564: my $captcha = Captcha::reCAPTCHA->new;
15565: my $captcha_result =
15566: $captcha->check_answer(
15567: $privkey,
15568: $ENV{'REMOTE_ADDR'},
15569: $env{'form.recaptcha_challenge_field'},
15570: $env{'form.recaptcha_response_field'},
15571: );
15572: if ($captcha_result->{is_valid}) {
15573: $captcha_chk = 1;
15574: }
15575: return $captcha_chk;
15576: }
15577:
1.1075.2.64 raeburn 15578: sub emailusername_info {
1.1075.2.67 raeburn 15579: my @fields = ('firstname','lastname','institution','web','location','officialemail');
1.1075.2.64 raeburn 15580: my %titles = &Apache::lonlocal::texthash (
15581: lastname => 'Last Name',
15582: firstname => 'First Name',
15583: institution => 'School/college/university',
15584: location => "School's city, state/province, country",
15585: web => "School's web address",
15586: officialemail => 'E-mail address at institution (if different)',
15587: );
15588: return (\@fields,\%titles);
15589: }
15590:
1.1075.2.56 raeburn 15591: sub cleanup_html {
15592: my ($incoming) = @_;
15593: my $outgoing;
15594: if ($incoming ne '') {
15595: $outgoing = $incoming;
15596: $outgoing =~ s/;/;/g;
15597: $outgoing =~ s/\#/#/g;
15598: $outgoing =~ s/\&/&/g;
15599: $outgoing =~ s/</</g;
15600: $outgoing =~ s/>/>/g;
15601: $outgoing =~ s/\(/(/g;
15602: $outgoing =~ s/\)/)/g;
15603: $outgoing =~ s/"/"/g;
15604: $outgoing =~ s/'/'/g;
15605: $outgoing =~ s/\$/$/g;
15606: $outgoing =~ s{/}{/}g;
15607: $outgoing =~ s/=/=/g;
15608: $outgoing =~ s/\\/\/g
15609: }
15610: return $outgoing;
15611: }
15612:
1.1075.2.74 raeburn 15613: # Checks for critical messages and returns a redirect url if one exists.
15614: # $interval indicates how often to check for messages.
15615: sub critical_redirect {
15616: my ($interval) = @_;
15617: if ((time-$env{'user.criticalcheck.time'})>$interval) {
15618: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
15619: $env{'user.name'});
15620: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
15621: my $redirecturl;
15622: if ($what[0]) {
15623: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
15624: $redirecturl='/adm/email?critical=display';
15625: my $url=&Apache::lonnet::absolute_url().$redirecturl;
15626: return (1, $url);
15627: }
15628: }
15629: }
15630: return ();
15631: }
15632:
1.1075.2.64 raeburn 15633: # Use:
15634: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
15635: #
15636: ##################################################
15637: # password associated functions #
15638: ##################################################
15639: sub des_keys {
15640: # Make a new key for DES encryption.
15641: # Each key has two parts which are returned separately.
15642: # Please note: Each key must be passed through the &hex function
15643: # before it is output to the web browser. The hex versions cannot
15644: # be used to decrypt.
15645: my @hexstr=('0','1','2','3','4','5','6','7',
15646: '8','9','a','b','c','d','e','f');
15647: my $lkey='';
15648: for (0..7) {
15649: $lkey.=$hexstr[rand(15)];
15650: }
15651: my $ukey='';
15652: for (0..7) {
15653: $ukey.=$hexstr[rand(15)];
15654: }
15655: return ($lkey,$ukey);
15656: }
15657:
15658: sub des_decrypt {
15659: my ($key,$cyphertext) = @_;
15660: my $keybin=pack("H16",$key);
15661: my $cypher;
15662: if ($Crypt::DES::VERSION>=2.03) {
15663: $cypher=new Crypt::DES $keybin;
15664: } else {
15665: $cypher=new DES $keybin;
15666: }
15667: my $plaintext=
15668: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
15669: $plaintext.=
15670: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
15671: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
15672: return $plaintext;
15673: }
15674:
1.112 bowersj2 15675: 1;
15676: __END__;
1.41 ng 15677:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>