Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.89
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.89! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.88 2015/03/11 01:55:41 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.1075.2.86 raeburn 3680: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 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.1075.2.86 raeburn 3702: =item * $usec: section of the desired student
3703:
3704: =item * $identifier: counter for student (multiple students one problem) or
3705: problem (one student; whole sequence).
3706:
1.112 bowersj2 3707: =back
1.14 harris41 3708:
1.112 bowersj2 3709: The output string is a table containing all desired attempts, if any.
1.16 harris41 3710:
1.112 bowersj2 3711: =cut
1.1 albertel 3712:
3713: sub get_previous_attempt {
1.1075.2.86 raeburn 3714: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 3715: my $prevattempts='';
1.43 ng 3716: no strict 'refs';
1.1 albertel 3717: if ($symb) {
1.3 albertel 3718: my (%returnhash)=
3719: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3720: if ($returnhash{'version'}) {
3721: my %lasthash=();
3722: my $version;
3723: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3724: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3725: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3726: }
1.1 albertel 3727: }
1.596 albertel 3728: $prevattempts=&start_data_table().&start_data_table_header_row();
3729: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 3730: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 3731: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3732: foreach my $key (sort(keys(%lasthash))) {
3733: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3734: if ($#parts > 0) {
1.31 albertel 3735: my $data=$parts[-1];
1.989 raeburn 3736: next if ($data eq 'foilorder');
1.31 albertel 3737: pop(@parts);
1.1010 www 3738: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3739: if ($data eq 'type') {
3740: unless ($showsurv) {
3741: my $id = join(',',@parts);
3742: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3743: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3744: $lasthidden{$ign.'.'.$id} = 1;
3745: }
1.945 raeburn 3746: }
1.1075.2.86 raeburn 3747: if ($identifier ne '') {
3748: my $id = join(',',@parts);
3749: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
3750: $domain,$username,$usec,undef,$course) =~ /^no/) {
3751: $hidestatus{$ign.'.'.$id} = 1;
3752: }
3753: }
3754: } elsif ($data eq 'regrader') {
3755: if (($identifier ne '') && (@parts)) {
3756: my $id = join(',',@parts);
3757: $regraded{$ign.'.'.$id} = 1;
3758: }
1.1010 www 3759: }
1.31 albertel 3760: } else {
1.41 ng 3761: if ($#parts == 0) {
3762: $prevattempts.='<th>'.$parts[0].'</th>';
3763: } else {
3764: $prevattempts.='<th>'.$ign.'</th>';
3765: }
1.31 albertel 3766: }
1.16 harris41 3767: }
1.596 albertel 3768: $prevattempts.=&end_data_table_header_row();
1.40 ng 3769: if ($getattempt eq '') {
1.1075.2.86 raeburn 3770: my (%solved,%resets,%probstatus);
3771: if (($identifier ne '') && (keys(%regraded) > 0)) {
3772: for ($version=1;$version<=$returnhash{'version'};$version++) {
3773: foreach my $id (keys(%regraded)) {
3774: if (($returnhash{$version.':'.$id.'.regrader'}) &&
3775: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
3776: ($returnhash{$version.':'.$id.'.award'} eq '')) {
3777: push(@{$resets{$id}},$version);
3778: }
3779: }
3780: }
3781: }
1.40 ng 3782: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 3783: my (@hidden,@unsolved);
1.945 raeburn 3784: if (%typeparts) {
3785: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 3786: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
3787: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 3788: push(@hidden,$id);
1.1075.2.86 raeburn 3789: } elsif ($identifier ne '') {
3790: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
3791: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
3792: ($hidestatus{$id})) {
3793: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
3794: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
3795: push(@{$solved{$id}},$version);
3796: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
3797: (ref($solved{$id}) eq 'ARRAY')) {
3798: my $skip;
3799: if (ref($resets{$id}) eq 'ARRAY') {
3800: foreach my $reset (@{$resets{$id}}) {
3801: if ($reset > $solved{$id}[-1]) {
3802: $skip=1;
3803: last;
3804: }
3805: }
3806: }
3807: unless ($skip) {
3808: my ($ign,$partslist) = split(/\./,$id,2);
3809: push(@unsolved,$partslist);
3810: }
3811: }
3812: }
1.945 raeburn 3813: }
3814: }
3815: }
3816: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 3817: '<td>'.&mt('Transaction [_1]',$version);
3818: if (@unsolved) {
3819: $prevattempts .= '<span class="LC_nobreak"><label>'.
3820: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
3821: &mt('Hide').'</label></span>';
3822: }
3823: $prevattempts .= '</td>';
1.945 raeburn 3824: if (@hidden) {
3825: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3826: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3827: my $hide;
3828: foreach my $id (@hidden) {
3829: if ($key =~ /^\Q$id\E/) {
3830: $hide = 1;
3831: last;
3832: }
3833: }
3834: if ($hide) {
3835: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3836: if (($data eq 'award') || ($data eq 'awarddetail')) {
3837: my $value = &format_previous_attempt_value($key,
3838: $returnhash{$version.':'.$key});
3839: $prevattempts.='<td>'.$value.' </td>';
3840: } else {
3841: $prevattempts.='<td> </td>';
3842: }
3843: } else {
3844: if ($key =~ /\./) {
3845: my $value = &format_previous_attempt_value($key,
3846: $returnhash{$version.':'.$key});
3847: $prevattempts.='<td>'.$value.' </td>';
3848: } else {
3849: $prevattempts.='<td> </td>';
3850: }
3851: }
3852: }
3853: } else {
3854: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3855: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3856: my $value = &format_previous_attempt_value($key,
3857: $returnhash{$version.':'.$key});
3858: $prevattempts.='<td>'.$value.' </td>';
3859: }
3860: }
3861: $prevattempts.=&end_data_table_row();
1.40 ng 3862: }
1.1 albertel 3863: }
1.945 raeburn 3864: my @currhidden = keys(%lasthidden);
1.596 albertel 3865: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3866: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3867: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3868: if (%typeparts) {
3869: my $hidden;
3870: foreach my $id (@currhidden) {
3871: if ($key =~ /^\Q$id\E/) {
3872: $hidden = 1;
3873: last;
3874: }
3875: }
3876: if ($hidden) {
3877: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3878: if (($data eq 'award') || ($data eq 'awarddetail')) {
3879: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3880: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3881: $value = &$gradesub($value);
3882: }
3883: $prevattempts.='<td>'.$value.' </td>';
3884: } else {
3885: $prevattempts.='<td> </td>';
3886: }
3887: } else {
3888: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3889: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3890: $value = &$gradesub($value);
3891: }
3892: $prevattempts.='<td>'.$value.' </td>';
3893: }
3894: } else {
3895: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3896: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3897: $value = &$gradesub($value);
3898: }
3899: $prevattempts.='<td>'.$value.' </td>';
3900: }
1.16 harris41 3901: }
1.596 albertel 3902: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3903: } else {
1.596 albertel 3904: $prevattempts=
3905: &start_data_table().&start_data_table_row().
3906: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3907: &end_data_table_row().&end_data_table();
1.1 albertel 3908: }
3909: } else {
1.596 albertel 3910: $prevattempts=
3911: &start_data_table().&start_data_table_row().
3912: '<td>'.&mt('No data.').'</td>'.
3913: &end_data_table_row().&end_data_table();
1.1 albertel 3914: }
1.10 albertel 3915: }
3916:
1.581 albertel 3917: sub format_previous_attempt_value {
3918: my ($key,$value) = @_;
1.1011 www 3919: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3920: $value = &Apache::lonlocal::locallocaltime($value);
3921: } elsif (ref($value) eq 'ARRAY') {
3922: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3923: } elsif ($key =~ /answerstring$/) {
3924: my %answers = &Apache::lonnet::str2hash($value);
3925: my @anskeys = sort(keys(%answers));
3926: if (@anskeys == 1) {
3927: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3928: if ($answer =~ m{\0}) {
3929: $answer =~ s{\0}{,}g;
1.988 raeburn 3930: }
3931: my $tag_internal_answer_name = 'INTERNAL';
3932: if ($anskeys[0] eq $tag_internal_answer_name) {
3933: $value = $answer;
3934: } else {
3935: $value = $anskeys[0].'='.$answer;
3936: }
3937: } else {
3938: foreach my $ans (@anskeys) {
3939: my $answer = $answers{$ans};
1.1001 raeburn 3940: if ($answer =~ m{\0}) {
3941: $answer =~ s{\0}{,}g;
1.988 raeburn 3942: }
3943: $value .= $ans.'='.$answer.'<br />';;
3944: }
3945: }
1.581 albertel 3946: } else {
3947: $value = &unescape($value);
3948: }
3949: return $value;
3950: }
3951:
3952:
1.107 albertel 3953: sub relative_to_absolute {
3954: my ($url,$output)=@_;
3955: my $parser=HTML::TokeParser->new(\$output);
3956: my $token;
3957: my $thisdir=$url;
3958: my @rlinks=();
3959: while ($token=$parser->get_token) {
3960: if ($token->[0] eq 'S') {
3961: if ($token->[1] eq 'a') {
3962: if ($token->[2]->{'href'}) {
3963: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3964: }
3965: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3966: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3967: } elsif ($token->[1] eq 'base') {
3968: $thisdir=$token->[2]->{'href'};
3969: }
3970: }
3971: }
3972: $thisdir=~s-/[^/]*$--;
1.356 albertel 3973: foreach my $link (@rlinks) {
1.726 raeburn 3974: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3975: ($link=~/^\//) ||
3976: ($link=~/^javascript:/i) ||
3977: ($link=~/^mailto:/i) ||
3978: ($link=~/^\#/)) {
3979: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3980: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3981: }
3982: }
3983: # -------------------------------------------------- Deal with Applet codebases
3984: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3985: return $output;
3986: }
3987:
1.112 bowersj2 3988: =pod
3989:
1.648 raeburn 3990: =item * &get_student_view()
1.112 bowersj2 3991:
3992: show a snapshot of what student was looking at
3993:
3994: =cut
3995:
1.10 albertel 3996: sub get_student_view {
1.186 albertel 3997: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3998: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3999: my (%form);
1.10 albertel 4000: my @elements=('symb','courseid','domain','username');
4001: foreach my $element (@elements) {
1.186 albertel 4002: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4003: }
1.186 albertel 4004: if (defined($moreenv)) {
4005: %form=(%form,%{$moreenv});
4006: }
1.236 albertel 4007: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4008: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4009: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4010: $userview=~s/\<body[^\>]*\>//gi;
4011: $userview=~s/\<\/body\>//gi;
4012: $userview=~s/\<html\>//gi;
4013: $userview=~s/\<\/html\>//gi;
4014: $userview=~s/\<head\>//gi;
4015: $userview=~s/\<\/head\>//gi;
4016: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4017: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4018: if (wantarray) {
4019: return ($userview,$response);
4020: } else {
4021: return $userview;
4022: }
4023: }
4024:
4025: sub get_student_view_with_retries {
4026: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4027:
4028: my $ok = 0; # True if we got a good response.
4029: my $content;
4030: my $response;
4031:
4032: # Try to get the student_view done. within the retries count:
4033:
4034: do {
4035: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4036: $ok = $response->is_success;
4037: if (!$ok) {
4038: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4039: }
4040: $retries--;
4041: } while (!$ok && ($retries > 0));
4042:
4043: if (!$ok) {
4044: $content = ''; # On error return an empty content.
4045: }
1.651 www 4046: if (wantarray) {
4047: return ($content, $response);
4048: } else {
4049: return $content;
4050: }
1.11 albertel 4051: }
4052:
1.112 bowersj2 4053: =pod
4054:
1.648 raeburn 4055: =item * &get_student_answers()
1.112 bowersj2 4056:
4057: show a snapshot of how student was answering problem
4058:
4059: =cut
4060:
1.11 albertel 4061: sub get_student_answers {
1.100 sakharuk 4062: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4063: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4064: my (%moreenv);
1.11 albertel 4065: my @elements=('symb','courseid','domain','username');
4066: foreach my $element (@elements) {
1.186 albertel 4067: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4068: }
1.186 albertel 4069: $moreenv{'grade_target'}='answer';
4070: %moreenv=(%form,%moreenv);
1.497 raeburn 4071: $feedurl = &Apache::lonnet::clutter($feedurl);
4072: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4073: return $userview;
1.1 albertel 4074: }
1.116 albertel 4075:
4076: =pod
4077:
4078: =item * &submlink()
4079:
1.242 albertel 4080: Inputs: $text $uname $udom $symb $target
1.116 albertel 4081:
4082: Returns: A link to grades.pm such as to see the SUBM view of a student
4083:
4084: =cut
4085:
4086: ###############################################
4087: sub submlink {
1.242 albertel 4088: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4089: if (!($uname && $udom)) {
4090: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4091: &Apache::lonnet::whichuser($symb);
1.116 albertel 4092: if (!$symb) { $symb=$cursymb; }
4093: }
1.254 matthew 4094: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4095: $symb=&escape($symb);
1.960 bisitz 4096: if ($target) { $target=" target=\"$target\""; }
4097: return
4098: '<a href="/adm/grades?command=submission'.
4099: '&symb='.$symb.
4100: '&student='.$uname.
4101: '&userdom='.$udom.'"'.
4102: $target.'>'.$text.'</a>';
1.242 albertel 4103: }
4104: ##############################################
4105:
4106: =pod
4107:
4108: =item * &pgrdlink()
4109:
4110: Inputs: $text $uname $udom $symb $target
4111:
4112: Returns: A link to grades.pm such as to see the PGRD view of a student
4113:
4114: =cut
4115:
4116: ###############################################
4117: sub pgrdlink {
4118: my $link=&submlink(@_);
4119: $link=~s/(&command=submission)/$1&showgrading=yes/;
4120: return $link;
4121: }
4122: ##############################################
4123:
4124: =pod
4125:
4126: =item * &pprmlink()
4127:
4128: Inputs: $text $uname $udom $symb $target
4129:
4130: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4131: student and a specific resource
1.242 albertel 4132:
4133: =cut
4134:
4135: ###############################################
4136: sub pprmlink {
4137: my ($text,$uname,$udom,$symb,$target)=@_;
4138: if (!($uname && $udom)) {
4139: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4140: &Apache::lonnet::whichuser($symb);
1.242 albertel 4141: if (!$symb) { $symb=$cursymb; }
4142: }
1.254 matthew 4143: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4144: $symb=&escape($symb);
1.242 albertel 4145: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4146: return '<a href="/adm/parmset?command=set&'.
4147: 'symb='.$symb.'&uname='.$uname.
4148: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4149: }
4150: ##############################################
1.37 matthew 4151:
1.112 bowersj2 4152: =pod
4153:
4154: =back
4155:
4156: =cut
4157:
1.37 matthew 4158: ###############################################
1.51 www 4159:
4160:
4161: sub timehash {
1.687 raeburn 4162: my ($thistime) = @_;
4163: my $timezone = &Apache::lonlocal::gettimezone();
4164: my $dt = DateTime->from_epoch(epoch => $thistime)
4165: ->set_time_zone($timezone);
4166: my $wday = $dt->day_of_week();
4167: if ($wday == 7) { $wday = 0; }
4168: return ( 'second' => $dt->second(),
4169: 'minute' => $dt->minute(),
4170: 'hour' => $dt->hour(),
4171: 'day' => $dt->day_of_month(),
4172: 'month' => $dt->month(),
4173: 'year' => $dt->year(),
4174: 'weekday' => $wday,
4175: 'dayyear' => $dt->day_of_year(),
4176: 'dlsav' => $dt->is_dst() );
1.51 www 4177: }
4178:
1.370 www 4179: sub utc_string {
4180: my ($date)=@_;
1.371 www 4181: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4182: }
4183:
1.51 www 4184: sub maketime {
4185: my %th=@_;
1.687 raeburn 4186: my ($epoch_time,$timezone,$dt);
4187: $timezone = &Apache::lonlocal::gettimezone();
4188: eval {
4189: $dt = DateTime->new( year => $th{'year'},
4190: month => $th{'month'},
4191: day => $th{'day'},
4192: hour => $th{'hour'},
4193: minute => $th{'minute'},
4194: second => $th{'second'},
4195: time_zone => $timezone,
4196: );
4197: };
4198: if (!$@) {
4199: $epoch_time = $dt->epoch;
4200: if ($epoch_time) {
4201: return $epoch_time;
4202: }
4203: }
1.51 www 4204: return POSIX::mktime(
4205: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4206: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4207: }
4208:
4209: #########################################
1.51 www 4210:
4211: sub findallcourses {
1.482 raeburn 4212: my ($roles,$uname,$udom) = @_;
1.355 albertel 4213: my %roles;
4214: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4215: my %courses;
1.51 www 4216: my $now=time;
1.482 raeburn 4217: if (!defined($uname)) {
4218: $uname = $env{'user.name'};
4219: }
4220: if (!defined($udom)) {
4221: $udom = $env{'user.domain'};
4222: }
4223: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4224: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4225: if (!%roles) {
4226: %roles = (
4227: cc => 1,
1.907 raeburn 4228: co => 1,
1.482 raeburn 4229: in => 1,
4230: ep => 1,
4231: ta => 1,
4232: cr => 1,
4233: st => 1,
4234: );
4235: }
4236: foreach my $entry (keys(%roleshash)) {
4237: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4238: if ($trole =~ /^cr/) {
4239: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4240: } else {
4241: next if (!exists($roles{$trole}));
4242: }
4243: if ($tend) {
4244: next if ($tend < $now);
4245: }
4246: if ($tstart) {
4247: next if ($tstart > $now);
4248: }
1.1058 raeburn 4249: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4250: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4251: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4252: if ($secpart eq '') {
4253: ($cnum,$role) = split(/_/,$cnumpart);
4254: $sec = 'none';
1.1058 raeburn 4255: $value .= $cnum.'/';
1.482 raeburn 4256: } else {
4257: $cnum = $cnumpart;
4258: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4259: $value .= $cnum.'/'.$sec;
4260: }
4261: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4262: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4263: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4264: }
4265: } else {
4266: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4267: }
1.482 raeburn 4268: }
4269: } else {
4270: foreach my $key (keys(%env)) {
1.483 albertel 4271: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4272: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4273: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4274: next if ($role eq 'ca' || $role eq 'aa');
4275: next if (%roles && !exists($roles{$role}));
4276: my ($starttime,$endtime)=split(/\./,$env{$key});
4277: my $active=1;
4278: if ($starttime) {
4279: if ($now<$starttime) { $active=0; }
4280: }
4281: if ($endtime) {
4282: if ($now>$endtime) { $active=0; }
4283: }
4284: if ($active) {
1.1058 raeburn 4285: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4286: if ($sec eq '') {
4287: $sec = 'none';
1.1058 raeburn 4288: } else {
4289: $value .= $sec;
4290: }
4291: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4292: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4293: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4294: }
4295: } else {
4296: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4297: }
1.474 raeburn 4298: }
4299: }
1.51 www 4300: }
4301: }
1.474 raeburn 4302: return %courses;
1.51 www 4303: }
1.37 matthew 4304:
1.54 www 4305: ###############################################
1.474 raeburn 4306:
4307: sub blockcheck {
1.1075.2.73 raeburn 4308: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4309:
1.1075.2.73 raeburn 4310: if (defined($udom) && defined($uname)) {
4311: # If uname and udom are for a course, check for blocks in the course.
4312: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4313: my ($startblock,$endblock,$triggerblock) =
4314: &get_blocks($setters,$activity,$udom,$uname,$url);
4315: return ($startblock,$endblock,$triggerblock);
4316: }
4317: } else {
1.490 raeburn 4318: $udom = $env{'user.domain'};
4319: $uname = $env{'user.name'};
4320: }
4321:
1.502 raeburn 4322: my $startblock = 0;
4323: my $endblock = 0;
1.1062 raeburn 4324: my $triggerblock = '';
1.482 raeburn 4325: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4326:
1.490 raeburn 4327: # If uname is for a user, and activity is course-specific, i.e.,
4328: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4329:
1.490 raeburn 4330: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.73 raeburn 4331: $activity eq 'groups' || $activity eq 'printout') &&
4332: ($env{'request.course.id'})) {
1.490 raeburn 4333: foreach my $key (keys(%live_courses)) {
4334: if ($key ne $env{'request.course.id'}) {
4335: delete($live_courses{$key});
4336: }
4337: }
4338: }
4339:
4340: my $otheruser = 0;
4341: my %own_courses;
4342: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4343: # Resource belongs to user other than current user.
4344: $otheruser = 1;
4345: # Gather courses for current user
4346: %own_courses =
4347: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4348: }
4349:
4350: # Gather active course roles - course coordinator, instructor,
4351: # exam proctor, ta, student, or custom role.
1.474 raeburn 4352:
4353: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4354: my ($cdom,$cnum);
4355: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4356: $cdom = $env{'course.'.$course.'.domain'};
4357: $cnum = $env{'course.'.$course.'.num'};
4358: } else {
1.490 raeburn 4359: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4360: }
4361: my $no_ownblock = 0;
4362: my $no_userblock = 0;
1.533 raeburn 4363: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4364: # Check if current user has 'evb' priv for this
4365: if (defined($own_courses{$course})) {
4366: foreach my $sec (keys(%{$own_courses{$course}})) {
4367: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4368: if ($sec ne 'none') {
4369: $checkrole .= '/'.$sec;
4370: }
4371: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4372: $no_ownblock = 1;
4373: last;
4374: }
4375: }
4376: }
4377: # if they have 'evb' priv and are currently not playing student
4378: next if (($no_ownblock) &&
4379: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4380: }
1.474 raeburn 4381: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4382: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4383: if ($sec ne 'none') {
1.482 raeburn 4384: $checkrole .= '/'.$sec;
1.474 raeburn 4385: }
1.490 raeburn 4386: if ($otheruser) {
4387: # Resource belongs to user other than current user.
4388: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4389: my (%allroles,%userroles);
4390: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4391: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4392: my ($trole,$tdom,$tnum,$tsec);
4393: if ($entry =~ /^cr/) {
4394: ($trole,$tdom,$tnum,$tsec) =
4395: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4396: } else {
4397: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4398: }
4399: my ($spec,$area,$trest);
4400: $area = '/'.$tdom.'/'.$tnum;
4401: $trest = $tnum;
4402: if ($tsec ne '') {
4403: $area .= '/'.$tsec;
4404: $trest .= '/'.$tsec;
4405: }
4406: $spec = $trole.'.'.$area;
4407: if ($trole =~ /^cr/) {
4408: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4409: $tdom,$spec,$trest,$area);
4410: } else {
4411: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4412: $tdom,$spec,$trest,$area);
4413: }
4414: }
4415: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4416: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4417: if ($1) {
4418: $no_userblock = 1;
4419: last;
4420: }
1.486 raeburn 4421: }
4422: }
1.490 raeburn 4423: } else {
4424: # Resource belongs to current user
4425: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4426: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4427: $no_ownblock = 1;
4428: last;
4429: }
1.474 raeburn 4430: }
4431: }
4432: # if they have the evb priv and are currently not playing student
1.482 raeburn 4433: next if (($no_ownblock) &&
1.491 albertel 4434: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4435: next if ($no_userblock);
1.474 raeburn 4436:
1.866 kalberla 4437: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4438: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4439:
1.1062 raeburn 4440: my ($start,$end,$trigger) =
4441: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4442: if (($start != 0) &&
4443: (($startblock == 0) || ($startblock > $start))) {
4444: $startblock = $start;
1.1062 raeburn 4445: if ($trigger ne '') {
4446: $triggerblock = $trigger;
4447: }
1.502 raeburn 4448: }
4449: if (($end != 0) &&
4450: (($endblock == 0) || ($endblock < $end))) {
4451: $endblock = $end;
1.1062 raeburn 4452: if ($trigger ne '') {
4453: $triggerblock = $trigger;
4454: }
1.502 raeburn 4455: }
1.490 raeburn 4456: }
1.1062 raeburn 4457: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4458: }
4459:
4460: sub get_blocks {
1.1062 raeburn 4461: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4462: my $startblock = 0;
4463: my $endblock = 0;
1.1062 raeburn 4464: my $triggerblock = '';
1.490 raeburn 4465: my $course = $cdom.'_'.$cnum;
4466: $setters->{$course} = {};
4467: $setters->{$course}{'staff'} = [];
4468: $setters->{$course}{'times'} = [];
1.1062 raeburn 4469: $setters->{$course}{'triggers'} = [];
4470: my (@blockers,%triggered);
4471: my $now = time;
4472: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4473: if ($activity eq 'docs') {
4474: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4475: foreach my $block (@blockers) {
4476: if ($block =~ /^firstaccess____(.+)$/) {
4477: my $item = $1;
4478: my $type = 'map';
4479: my $timersymb = $item;
4480: if ($item eq 'course') {
4481: $type = 'course';
4482: } elsif ($item =~ /___\d+___/) {
4483: $type = 'resource';
4484: } else {
4485: $timersymb = &Apache::lonnet::symbread($item);
4486: }
4487: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4488: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4489: $triggered{$block} = {
4490: start => $start,
4491: end => $end,
4492: type => $type,
4493: };
4494: }
4495: }
4496: } else {
4497: foreach my $block (keys(%commblocks)) {
4498: if ($block =~ m/^(\d+)____(\d+)$/) {
4499: my ($start,$end) = ($1,$2);
4500: if ($start <= time && $end >= time) {
4501: if (ref($commblocks{$block}) eq 'HASH') {
4502: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4503: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4504: unless(grep(/^\Q$block\E$/,@blockers)) {
4505: push(@blockers,$block);
4506: }
4507: }
4508: }
4509: }
4510: }
4511: } elsif ($block =~ /^firstaccess____(.+)$/) {
4512: my $item = $1;
4513: my $timersymb = $item;
4514: my $type = 'map';
4515: if ($item eq 'course') {
4516: $type = 'course';
4517: } elsif ($item =~ /___\d+___/) {
4518: $type = 'resource';
4519: } else {
4520: $timersymb = &Apache::lonnet::symbread($item);
4521: }
4522: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4523: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4524: if ($start && $end) {
4525: if (($start <= time) && ($end >= time)) {
4526: unless (grep(/^\Q$block\E$/,@blockers)) {
4527: push(@blockers,$block);
4528: $triggered{$block} = {
4529: start => $start,
4530: end => $end,
4531: type => $type,
4532: };
4533: }
4534: }
1.490 raeburn 4535: }
1.1062 raeburn 4536: }
4537: }
4538: }
4539: foreach my $blocker (@blockers) {
4540: my ($staff_name,$staff_dom,$title,$blocks) =
4541: &parse_block_record($commblocks{$blocker});
4542: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4543: my ($start,$end,$triggertype);
4544: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4545: ($start,$end) = ($1,$2);
4546: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4547: $start = $triggered{$blocker}{'start'};
4548: $end = $triggered{$blocker}{'end'};
4549: $triggertype = $triggered{$blocker}{'type'};
4550: }
4551: if ($start) {
4552: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4553: if ($triggertype) {
4554: push(@{$$setters{$course}{'triggers'}},$triggertype);
4555: } else {
4556: push(@{$$setters{$course}{'triggers'}},0);
4557: }
4558: if ( ($startblock == 0) || ($startblock > $start) ) {
4559: $startblock = $start;
4560: if ($triggertype) {
4561: $triggerblock = $blocker;
1.474 raeburn 4562: }
4563: }
1.1062 raeburn 4564: if ( ($endblock == 0) || ($endblock < $end) ) {
4565: $endblock = $end;
4566: if ($triggertype) {
4567: $triggerblock = $blocker;
4568: }
4569: }
1.474 raeburn 4570: }
4571: }
1.1062 raeburn 4572: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4573: }
4574:
4575: sub parse_block_record {
4576: my ($record) = @_;
4577: my ($setuname,$setudom,$title,$blocks);
4578: if (ref($record) eq 'HASH') {
4579: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4580: $title = &unescape($record->{'event'});
4581: $blocks = $record->{'blocks'};
4582: } else {
4583: my @data = split(/:/,$record,3);
4584: if (scalar(@data) eq 2) {
4585: $title = $data[1];
4586: ($setuname,$setudom) = split(/@/,$data[0]);
4587: } else {
4588: ($setuname,$setudom,$title) = @data;
4589: }
4590: $blocks = { 'com' => 'on' };
4591: }
4592: return ($setuname,$setudom,$title,$blocks);
4593: }
4594:
1.854 kalberla 4595: sub blocking_status {
1.1075.2.73 raeburn 4596: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4597: my %setters;
1.890 droeschl 4598:
1.1061 raeburn 4599: # check for active blocking
1.1062 raeburn 4600: my ($startblock,$endblock,$triggerblock) =
1.1075.2.73 raeburn 4601: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4602: my $blocked = 0;
4603: if ($startblock && $endblock) {
4604: $blocked = 1;
4605: }
1.890 droeschl 4606:
1.1061 raeburn 4607: # caller just wants to know whether a block is active
4608: if (!wantarray) { return $blocked; }
4609:
4610: # build a link to a popup window containing the details
4611: my $querystring = "?activity=$activity";
4612: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4613: if ($activity eq 'port') {
4614: $querystring .= "&udom=$udom" if $udom;
4615: $querystring .= "&uname=$uname" if $uname;
4616: } elsif ($activity eq 'docs') {
4617: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4618: }
1.1061 raeburn 4619:
4620: my $output .= <<'END_MYBLOCK';
4621: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4622: var options = "width=" + w + ",height=" + h + ",";
4623: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4624: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4625: var newWin = window.open(url, wdwName, options);
4626: newWin.focus();
4627: }
1.890 droeschl 4628: END_MYBLOCK
1.854 kalberla 4629:
1.1061 raeburn 4630: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4631:
1.1061 raeburn 4632: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4633: my $text = &mt('Communication Blocked');
4634: if ($activity eq 'docs') {
4635: $text = &mt('Content Access Blocked');
1.1063 raeburn 4636: } elsif ($activity eq 'printout') {
4637: $text = &mt('Printing Blocked');
1.1062 raeburn 4638: }
1.1061 raeburn 4639: $output .= <<"END_BLOCK";
1.867 kalberla 4640: <div class='LC_comblock'>
1.869 kalberla 4641: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4642: title='$text'>
4643: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4644: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4645: title='$text'>$text</a>
1.867 kalberla 4646: </div>
4647:
4648: END_BLOCK
1.474 raeburn 4649:
1.1061 raeburn 4650: return ($blocked, $output);
1.854 kalberla 4651: }
1.490 raeburn 4652:
1.60 matthew 4653: ###############################################
4654:
1.682 raeburn 4655: sub check_ip_acc {
4656: my ($acc)=@_;
4657: &Apache::lonxml::debug("acc is $acc");
4658: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4659: return 1;
4660: }
4661: my $allowed=0;
4662: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4663:
4664: my $name;
4665: foreach my $pattern (split(',',$acc)) {
4666: $pattern =~ s/^\s*//;
4667: $pattern =~ s/\s*$//;
4668: if ($pattern =~ /\*$/) {
4669: #35.8.*
4670: $pattern=~s/\*//;
4671: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4672: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4673: #35.8.3.[34-56]
4674: my $low=$2;
4675: my $high=$3;
4676: $pattern=$1;
4677: if ($ip =~ /^\Q$pattern\E/) {
4678: my $last=(split(/\./,$ip))[3];
4679: if ($last <=$high && $last >=$low) { $allowed=1; }
4680: }
4681: } elsif ($pattern =~ /^\*/) {
4682: #*.msu.edu
4683: $pattern=~s/\*//;
4684: if (!defined($name)) {
4685: use Socket;
4686: my $netaddr=inet_aton($ip);
4687: ($name)=gethostbyaddr($netaddr,AF_INET);
4688: }
4689: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4690: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4691: #127.0.0.1
4692: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4693: } else {
4694: #some.name.com
4695: if (!defined($name)) {
4696: use Socket;
4697: my $netaddr=inet_aton($ip);
4698: ($name)=gethostbyaddr($netaddr,AF_INET);
4699: }
4700: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4701: }
4702: if ($allowed) { last; }
4703: }
4704: return $allowed;
4705: }
4706:
4707: ###############################################
4708:
1.60 matthew 4709: =pod
4710:
1.112 bowersj2 4711: =head1 Domain Template Functions
4712:
4713: =over 4
4714:
4715: =item * &determinedomain()
1.60 matthew 4716:
4717: Inputs: $domain (usually will be undef)
4718:
1.63 www 4719: Returns: Determines which domain should be used for designs
1.60 matthew 4720:
4721: =cut
1.54 www 4722:
1.60 matthew 4723: ###############################################
1.63 www 4724: sub determinedomain {
4725: my $domain=shift;
1.531 albertel 4726: if (! $domain) {
1.60 matthew 4727: # Determine domain if we have not been given one
1.893 raeburn 4728: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4729: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4730: if ($env{'request.role.domain'}) {
4731: $domain=$env{'request.role.domain'};
1.60 matthew 4732: }
4733: }
1.63 www 4734: return $domain;
4735: }
4736: ###############################################
1.517 raeburn 4737:
1.518 albertel 4738: sub devalidate_domconfig_cache {
4739: my ($udom)=@_;
4740: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4741: }
4742:
4743: # ---------------------- Get domain configuration for a domain
4744: sub get_domainconf {
4745: my ($udom) = @_;
4746: my $cachetime=1800;
4747: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4748: if (defined($cached)) { return %{$result}; }
4749:
4750: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4751: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4752: my (%designhash,%legacy);
1.518 albertel 4753: if (keys(%domconfig) > 0) {
4754: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4755: if (keys(%{$domconfig{'login'}})) {
4756: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4757: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 4758: if (($key eq 'loginvia') || ($key eq 'headtag')) {
4759: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4760: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
4761: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
4762: if ($key eq 'loginvia') {
4763: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4764: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4765: $designhash{$udom.'.login.loginvia'} = $server;
4766: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4767: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4768: } else {
4769: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
4770: }
1.948 raeburn 4771: }
1.1075.2.87 raeburn 4772: } elsif ($key eq 'headtag') {
4773: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
4774: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 4775: }
1.946 raeburn 4776: }
1.1075.2.87 raeburn 4777: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
4778: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
4779: }
1.946 raeburn 4780: }
4781: }
4782: }
4783: } else {
4784: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4785: $designhash{$udom.'.login.'.$key.'_'.$img} =
4786: $domconfig{'login'}{$key}{$img};
4787: }
1.699 raeburn 4788: }
4789: } else {
4790: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4791: }
1.632 raeburn 4792: }
4793: } else {
4794: $legacy{'login'} = 1;
1.518 albertel 4795: }
1.632 raeburn 4796: } else {
4797: $legacy{'login'} = 1;
1.518 albertel 4798: }
4799: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4800: if (keys(%{$domconfig{'rolecolors'}})) {
4801: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4802: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4803: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4804: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4805: }
1.518 albertel 4806: }
4807: }
1.632 raeburn 4808: } else {
4809: $legacy{'rolecolors'} = 1;
1.518 albertel 4810: }
1.632 raeburn 4811: } else {
4812: $legacy{'rolecolors'} = 1;
1.518 albertel 4813: }
1.948 raeburn 4814: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4815: if ($domconfig{'autoenroll'}{'co-owners'}) {
4816: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4817: }
4818: }
1.632 raeburn 4819: if (keys(%legacy) > 0) {
4820: my %legacyhash = &get_legacy_domconf($udom);
4821: foreach my $item (keys(%legacyhash)) {
4822: if ($item =~ /^\Q$udom\E\.login/) {
4823: if ($legacy{'login'}) {
4824: $designhash{$item} = $legacyhash{$item};
4825: }
4826: } else {
4827: if ($legacy{'rolecolors'}) {
4828: $designhash{$item} = $legacyhash{$item};
4829: }
1.518 albertel 4830: }
4831: }
4832: }
1.632 raeburn 4833: } else {
4834: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4835: }
4836: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4837: $cachetime);
4838: return %designhash;
4839: }
4840:
1.632 raeburn 4841: sub get_legacy_domconf {
4842: my ($udom) = @_;
4843: my %legacyhash;
4844: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4845: my $designfile = $designdir.'/'.$udom.'.tab';
4846: if (-e $designfile) {
4847: if ( open (my $fh,"<$designfile") ) {
4848: while (my $line = <$fh>) {
4849: next if ($line =~ /^\#/);
4850: chomp($line);
4851: my ($key,$val)=(split(/\=/,$line));
4852: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4853: }
4854: close($fh);
4855: }
4856: }
1.1026 raeburn 4857: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4858: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4859: }
4860: return %legacyhash;
4861: }
4862:
1.63 www 4863: =pod
4864:
1.112 bowersj2 4865: =item * &domainlogo()
1.63 www 4866:
4867: Inputs: $domain (usually will be undef)
4868:
4869: Returns: A link to a domain logo, if the domain logo exists.
4870: If the domain logo does not exist, a description of the domain.
4871:
4872: =cut
1.112 bowersj2 4873:
1.63 www 4874: ###############################################
4875: sub domainlogo {
1.517 raeburn 4876: my $domain = &determinedomain(shift);
1.518 albertel 4877: my %designhash = &get_domainconf($domain);
1.517 raeburn 4878: # See if there is a logo
4879: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4880: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4881: if ($imgsrc =~ m{^/(adm|res)/}) {
4882: if ($imgsrc =~ m{^/res/}) {
4883: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4884: &Apache::lonnet::repcopy($local_name);
4885: }
4886: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4887: }
4888: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4889: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4890: return &Apache::lonnet::domain($domain,'description');
1.59 www 4891: } else {
1.60 matthew 4892: return '';
1.59 www 4893: }
4894: }
1.63 www 4895: ##############################################
4896:
4897: =pod
4898:
1.112 bowersj2 4899: =item * &designparm()
1.63 www 4900:
4901: Inputs: $which parameter; $domain (usually will be undef)
4902:
4903: Returns: value of designparamter $which
4904:
4905: =cut
1.112 bowersj2 4906:
1.397 albertel 4907:
1.400 albertel 4908: ##############################################
1.397 albertel 4909: sub designparm {
4910: my ($which,$domain)=@_;
4911: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4912: return $env{'environment.color.'.$which};
1.96 www 4913: }
1.63 www 4914: $domain=&determinedomain($domain);
1.1016 raeburn 4915: my %domdesign;
4916: unless ($domain eq 'public') {
4917: %domdesign = &get_domainconf($domain);
4918: }
1.520 raeburn 4919: my $output;
1.517 raeburn 4920: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4921: $output = $domdesign{$domain.'.'.$which};
1.63 www 4922: } else {
1.520 raeburn 4923: $output = $defaultdesign{$which};
4924: }
4925: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4926: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4927: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4928: if ($output =~ m{^/res/}) {
4929: my $local_name = &Apache::lonnet::filelocation('',$output);
4930: &Apache::lonnet::repcopy($local_name);
4931: }
1.520 raeburn 4932: $output = &lonhttpdurl($output);
4933: }
1.63 www 4934: }
1.520 raeburn 4935: return $output;
1.63 www 4936: }
1.59 www 4937:
1.822 bisitz 4938: ##############################################
4939: =pod
4940:
1.832 bisitz 4941: =item * &authorspace()
4942:
1.1028 raeburn 4943: Inputs: $url (usually will be undef).
1.832 bisitz 4944:
1.1075.2.40 raeburn 4945: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4946: directory being viewed (or for which action is being taken).
4947: If $url is provided, and begins /priv/<domain>/<uname>
4948: the path will be that portion of the $context argument.
4949: Otherwise the path will be for the author space of the current
4950: user when the current role is author, or for that of the
4951: co-author/assistant co-author space when the current role
4952: is co-author or assistant co-author.
1.832 bisitz 4953:
4954: =cut
4955:
4956: sub authorspace {
1.1028 raeburn 4957: my ($url) = @_;
4958: if ($url ne '') {
4959: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4960: return $1;
4961: }
4962: }
1.832 bisitz 4963: my $caname = '';
1.1024 www 4964: my $cadom = '';
1.1028 raeburn 4965: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4966: ($cadom,$caname) =
1.832 bisitz 4967: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4968: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4969: $caname = $env{'user.name'};
1.1024 www 4970: $cadom = $env{'user.domain'};
1.832 bisitz 4971: }
1.1028 raeburn 4972: if (($caname ne '') && ($cadom ne '')) {
4973: return "/priv/$cadom/$caname/";
4974: }
4975: return;
1.832 bisitz 4976: }
4977:
4978: ##############################################
4979: =pod
4980:
1.822 bisitz 4981: =item * &head_subbox()
4982:
4983: Inputs: $content (contains HTML code with page functions, etc.)
4984:
4985: Returns: HTML div with $content
4986: To be included in page header
4987:
4988: =cut
4989:
4990: sub head_subbox {
4991: my ($content)=@_;
4992: my $output =
1.993 raeburn 4993: '<div class="LC_head_subbox">'
1.822 bisitz 4994: .$content
4995: .'</div>'
4996: }
4997:
4998: ##############################################
4999: =pod
5000:
5001: =item * &CSTR_pageheader()
5002:
1.1026 raeburn 5003: Input: (optional) filename from which breadcrumb trail is built.
5004: In most cases no input as needed, as $env{'request.filename'}
5005: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5006:
5007: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5008: To be included on Authoring Space pages
1.822 bisitz 5009:
5010: =cut
5011:
5012: sub CSTR_pageheader {
1.1026 raeburn 5013: my ($trailfile) = @_;
5014: if ($trailfile eq '') {
5015: $trailfile = $env{'request.filename'};
5016: }
5017:
5018: # this is for resources; directories have customtitle, and crumbs
5019: # and select recent are created in lonpubdir.pm
5020:
5021: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5022: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5023: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5024: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5025: $formaction =~ s{/+}{/}g;
1.822 bisitz 5026:
5027: my $parentpath = '';
5028: my $lastitem = '';
5029: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5030: $parentpath = $1;
5031: $lastitem = $2;
5032: } else {
5033: $lastitem = $thisdisfn;
5034: }
1.921 bisitz 5035:
5036: my $output =
1.822 bisitz 5037: '<div>'
5038: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5039: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5040: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5041: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5042: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5043:
5044: if ($lastitem) {
5045: $output .=
5046: '<span class="LC_filename">'
5047: .$lastitem
5048: .'</span>';
5049: }
5050: $output .=
5051: '<br />'
1.822 bisitz 5052: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5053: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5054: .'</form>'
5055: .&Apache::lonmenu::constspaceform()
5056: .'</div>';
1.921 bisitz 5057:
5058: return $output;
1.822 bisitz 5059: }
5060:
1.60 matthew 5061: ###############################################
5062: ###############################################
5063:
5064: =pod
5065:
1.112 bowersj2 5066: =back
5067:
1.549 albertel 5068: =head1 HTML Helpers
1.112 bowersj2 5069:
5070: =over 4
5071:
5072: =item * &bodytag()
1.60 matthew 5073:
5074: Returns a uniform header for LON-CAPA web pages.
5075:
5076: Inputs:
5077:
1.112 bowersj2 5078: =over 4
5079:
5080: =item * $title, A title to be displayed on the page.
5081:
5082: =item * $function, the current role (can be undef).
5083:
5084: =item * $addentries, extra parameters for the <body> tag.
5085:
5086: =item * $bodyonly, if defined, only return the <body> tag.
5087:
5088: =item * $domain, if defined, force a given domain.
5089:
5090: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5091: text interface only)
1.60 matthew 5092:
1.814 bisitz 5093: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5094: navigational links
1.317 albertel 5095:
1.338 albertel 5096: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5097:
1.1075.2.12 raeburn 5098: =item * $no_inline_link, if true and in remote mode, don't show the
5099: 'Switch To Inline Menu' link
5100:
1.460 albertel 5101: =item * $args, optional argument valid values are
5102: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5103: inherit_jsmath -> when creating popup window in a page,
5104: should it have jsmath forced on by the
5105: current page
1.460 albertel 5106:
1.1075.2.15 raeburn 5107: =item * $advtoolsref, optional argument, ref to an array containing
5108: inlineremote items to be added in "Functions" menu below
5109: breadcrumbs.
5110:
1.112 bowersj2 5111: =back
5112:
1.60 matthew 5113: Returns: A uniform header for LON-CAPA web pages.
5114: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5115: If $bodyonly is undef or zero, an html string containing a <body> tag and
5116: other decorations will be returned.
5117:
5118: =cut
5119:
1.54 www 5120: sub bodytag {
1.831 bisitz 5121: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5122: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5123:
1.954 raeburn 5124: my $public;
5125: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5126: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5127: $public = 1;
5128: }
1.460 albertel 5129: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5130: my $httphost = $args->{'use_absolute'};
1.339 albertel 5131:
1.183 matthew 5132: $function = &get_users_function() if (!$function);
1.339 albertel 5133: my $img = &designparm($function.'.img',$domain);
5134: my $font = &designparm($function.'.font',$domain);
5135: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5136:
1.803 bisitz 5137: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5138: 'bgcolor' => $pgbg,
1.339 albertel 5139: 'text' => $font,
5140: 'alink' => &designparm($function.'.alink',$domain),
5141: 'vlink' => &designparm($function.'.vlink',$domain),
5142: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5143: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5144:
1.63 www 5145: # role and realm
1.1075.2.68 raeburn 5146: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5147: if ($realm) {
5148: $realm = '/'.$realm;
5149: }
1.378 raeburn 5150: if ($role eq 'ca') {
1.479 albertel 5151: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5152: $realm = &plainname($rname,$rdom);
1.378 raeburn 5153: }
1.55 www 5154: # realm
1.258 albertel 5155: if ($env{'request.course.id'}) {
1.378 raeburn 5156: if ($env{'request.role'} !~ /^cr/) {
5157: $role = &Apache::lonnet::plaintext($role,&course_type());
5158: }
1.898 raeburn 5159: if ($env{'request.course.sec'}) {
5160: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5161: }
1.359 albertel 5162: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5163: } else {
5164: $role = &Apache::lonnet::plaintext($role);
1.54 www 5165: }
1.433 albertel 5166:
1.359 albertel 5167: if (!$realm) { $realm=' '; }
1.330 albertel 5168:
1.438 albertel 5169: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5170:
1.101 www 5171: # construct main body tag
1.359 albertel 5172: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5173: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5174:
1.1075.2.38 raeburn 5175: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5176:
5177: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5178: return $bodytag;
1.1075.2.38 raeburn 5179: }
1.359 albertel 5180:
1.954 raeburn 5181: if ($public) {
1.433 albertel 5182: undef($role);
5183: }
1.359 albertel 5184:
1.762 bisitz 5185: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5186: #
5187: # Extra info if you are the DC
5188: my $dc_info = '';
5189: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5190: $env{'course.'.$env{'request.course.id'}.
5191: '.domain'}.'/'})) {
5192: my $cid = $env{'request.course.id'};
1.917 raeburn 5193: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5194: $dc_info =~ s/\s+$//;
1.359 albertel 5195: }
5196:
1.898 raeburn 5197: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.903 droeschl 5198:
1.1075.2.13 raeburn 5199: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5200:
1.1075.2.38 raeburn 5201:
5202:
1.1075.2.21 raeburn 5203: my $funclist;
5204: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5205: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5206: Apache::lonmenu::serverform();
5207: my $forbodytag;
5208: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5209: $forcereg,$args->{'group'},
5210: $args->{'bread_crumbs'},
5211: $advtoolsref,'',\$forbodytag);
5212: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5213: $funclist = $forbodytag;
5214: }
5215: } else {
1.903 droeschl 5216:
5217: # if ($env{'request.state'} eq 'construct') {
5218: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5219: # }
5220:
1.1075.2.38 raeburn 5221: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5222: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5223:
1.1075.2.38 raeburn 5224: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5225:
1.916 droeschl 5226: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5227: if ($dc_info) {
5228: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5229: }
1.1075.2.38 raeburn 5230: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5231: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5232: return $bodytag;
5233: }
1.894 droeschl 5234:
1.927 raeburn 5235: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5236: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5237: }
1.916 droeschl 5238:
1.1075.2.38 raeburn 5239: $bodytag .= $right;
1.852 droeschl 5240:
1.917 raeburn 5241: if ($dc_info) {
5242: $dc_info = &dc_courseid_toggle($dc_info);
5243: }
5244: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5245:
1.1075.2.61 raeburn 5246: #if directed to not display the secondary menu, don't.
5247: if ($args->{'no_secondary_menu'}) {
5248: return $bodytag;
5249: }
1.903 droeschl 5250: #don't show menus for public users
1.954 raeburn 5251: if (!$public){
1.1075.2.52 raeburn 5252: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5253: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5254: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5255: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5256: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5257: $args->{'bread_crumbs'});
5258: } elsif ($forcereg) {
1.1075.2.22 raeburn 5259: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5260: $args->{'group'});
1.1075.2.15 raeburn 5261: } else {
1.1075.2.21 raeburn 5262: my $forbodytag;
5263: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5264: $forcereg,$args->{'group'},
5265: $args->{'bread_crumbs'},
5266: $advtoolsref,'',\$forbodytag);
5267: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5268: $bodytag .= $forbodytag;
5269: }
1.920 raeburn 5270: }
1.903 droeschl 5271: }else{
5272: # this is to seperate menu from content when there's no secondary
5273: # menu. Especially needed for public accessible ressources.
5274: $bodytag .= '<hr style="clear:both" />';
5275: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5276: }
1.903 droeschl 5277:
1.235 raeburn 5278: return $bodytag;
1.1075.2.12 raeburn 5279: }
5280:
5281: #
5282: # Top frame rendering, Remote is up
5283: #
5284:
5285: my $imgsrc = $img;
5286: if ($img =~ /^\/adm/) {
5287: $imgsrc = &lonhttpdurl($img);
5288: }
5289: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5290:
1.1075.2.60 raeburn 5291: my $help=($no_inline_link?''
5292: :&Apache::loncommon::top_nav_help('Help'));
5293:
1.1075.2.12 raeburn 5294: # Explicit link to get inline menu
5295: my $menu= ($no_inline_link?''
5296: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5297:
5298: if ($dc_info) {
5299: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5300: }
5301:
1.1075.2.38 raeburn 5302: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5303: unless ($public) {
5304: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5305: undef,'LC_menubuttons_link');
5306: }
5307:
1.1075.2.12 raeburn 5308: unless ($env{'form.inhibitmenu'}) {
5309: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5310: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5311: <li>$help</li>
1.1075.2.12 raeburn 5312: <li>$menu</li>
5313: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5314: }
1.1075.2.13 raeburn 5315: if ($env{'request.state'} eq 'construct') {
5316: if (!$public){
5317: if ($env{'request.state'} eq 'construct') {
5318: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5319: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5320: &Apache::lonhtmlcommon::scripttag('','end').
5321: &Apache::lonmenu::innerregister($forcereg,
5322: $args->{'bread_crumbs'});
5323: }
5324: }
5325: }
1.1075.2.21 raeburn 5326: return $bodytag."\n".$funclist;
1.182 matthew 5327: }
5328:
1.917 raeburn 5329: sub dc_courseid_toggle {
5330: my ($dc_info) = @_;
1.980 raeburn 5331: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5332: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5333: &mt('(More ...)').'</a></span>'.
5334: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5335: }
5336:
1.330 albertel 5337: sub make_attr_string {
5338: my ($register,$attr_ref) = @_;
5339:
5340: if ($attr_ref && !ref($attr_ref)) {
5341: die("addentries Must be a hash ref ".
5342: join(':',caller(1))." ".
5343: join(':',caller(0))." ");
5344: }
5345:
5346: if ($register) {
1.339 albertel 5347: my ($on_load,$on_unload);
5348: foreach my $key (keys(%{$attr_ref})) {
5349: if (lc($key) eq 'onload') {
5350: $on_load.=$attr_ref->{$key}.';';
5351: delete($attr_ref->{$key});
5352:
5353: } elsif (lc($key) eq 'onunload') {
5354: $on_unload.=$attr_ref->{$key}.';';
5355: delete($attr_ref->{$key});
5356: }
5357: }
1.1075.2.12 raeburn 5358: if ($env{'environment.remote'} eq 'on') {
5359: $attr_ref->{'onload'} =
5360: &Apache::lonmenu::loadevents(). $on_load;
5361: $attr_ref->{'onunload'}=
5362: &Apache::lonmenu::unloadevents().$on_unload;
5363: } else {
5364: $attr_ref->{'onload'} = $on_load;
5365: $attr_ref->{'onunload'}= $on_unload;
5366: }
1.330 albertel 5367: }
1.339 albertel 5368:
1.330 albertel 5369: my $attr_string;
1.1075.2.56 raeburn 5370: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5371: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5372: }
5373: return $attr_string;
5374: }
5375:
5376:
1.182 matthew 5377: ###############################################
1.251 albertel 5378: ###############################################
5379:
5380: =pod
5381:
5382: =item * &endbodytag()
5383:
5384: Returns a uniform footer for LON-CAPA web pages.
5385:
1.635 raeburn 5386: Inputs: 1 - optional reference to an args hash
5387: If in the hash, key for noredirectlink has a value which evaluates to true,
5388: a 'Continue' link is not displayed if the page contains an
5389: internal redirect in the <head></head> section,
5390: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5391:
5392: =cut
5393:
5394: sub endbodytag {
1.635 raeburn 5395: my ($args) = @_;
1.1075.2.6 raeburn 5396: my $endbodytag;
5397: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5398: $endbodytag='</body>';
5399: }
1.269 albertel 5400: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5401: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5402: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5403: $endbodytag=
5404: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5405: &mt('Continue').'</a>'.
5406: $endbodytag;
5407: }
1.315 albertel 5408: }
1.251 albertel 5409: return $endbodytag;
5410: }
5411:
1.352 albertel 5412: =pod
5413:
5414: =item * &standard_css()
5415:
5416: Returns a style sheet
5417:
5418: Inputs: (all optional)
5419: domain -> force to color decorate a page for a specific
5420: domain
5421: function -> force usage of a specific rolish color scheme
5422: bgcolor -> override the default page bgcolor
5423:
5424: =cut
5425:
1.343 albertel 5426: sub standard_css {
1.345 albertel 5427: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5428: $function = &get_users_function() if (!$function);
5429: my $img = &designparm($function.'.img', $domain);
5430: my $tabbg = &designparm($function.'.tabbg', $domain);
5431: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5432: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5433: #second colour for later usage
1.345 albertel 5434: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5435: my $pgbg_or_bgcolor =
5436: $bgcolor ||
1.352 albertel 5437: &designparm($function.'.pgbg', $domain);
1.382 albertel 5438: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5439: my $alink = &designparm($function.'.alink', $domain);
5440: my $vlink = &designparm($function.'.vlink', $domain);
5441: my $link = &designparm($function.'.link', $domain);
5442:
1.602 albertel 5443: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5444: my $mono = 'monospace';
1.850 bisitz 5445: my $data_table_head = $sidebg;
5446: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5447: my $data_table_dark = '#E0E0E0';
1.470 banghart 5448: my $data_table_darker = '#CCCCCC';
1.349 albertel 5449: my $data_table_highlight = '#FFFF00';
1.352 albertel 5450: my $mail_new = '#FFBB77';
5451: my $mail_new_hover = '#DD9955';
5452: my $mail_read = '#BBBB77';
5453: my $mail_read_hover = '#999944';
5454: my $mail_replied = '#AAAA88';
5455: my $mail_replied_hover = '#888855';
5456: my $mail_other = '#99BBBB';
5457: my $mail_other_hover = '#669999';
1.391 albertel 5458: my $table_header = '#DDDDDD';
1.489 raeburn 5459: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5460: my $lg_border_color = '#C8C8C8';
1.952 onken 5461: my $button_hover = '#BF2317';
1.392 albertel 5462:
1.608 albertel 5463: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5464: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5465: : '0 3px 0 4px';
1.448 albertel 5466:
1.523 albertel 5467:
1.343 albertel 5468: return <<END;
1.947 droeschl 5469:
5470: /* needed for iframe to allow 100% height in FF */
5471: body, html {
5472: margin: 0;
5473: padding: 0 0.5%;
5474: height: 99%; /* to avoid scrollbars */
5475: }
5476:
1.795 www 5477: body {
1.911 bisitz 5478: font-family: $sans;
5479: line-height:130%;
5480: font-size:0.83em;
5481: color:$font;
1.795 www 5482: }
5483:
1.959 onken 5484: a:focus,
5485: a:focus img {
1.795 www 5486: color: red;
5487: }
1.698 harmsja 5488:
1.911 bisitz 5489: form, .inline {
5490: display: inline;
1.795 www 5491: }
1.721 harmsja 5492:
1.795 www 5493: .LC_right {
1.911 bisitz 5494: text-align:right;
1.795 www 5495: }
5496:
5497: .LC_middle {
1.911 bisitz 5498: vertical-align:middle;
1.795 www 5499: }
1.721 harmsja 5500:
1.1075.2.38 raeburn 5501: .LC_floatleft {
5502: float: left;
5503: }
5504:
5505: .LC_floatright {
5506: float: right;
5507: }
5508:
1.911 bisitz 5509: .LC_400Box {
5510: width:400px;
5511: }
1.721 harmsja 5512:
1.947 droeschl 5513: .LC_iframecontainer {
5514: width: 98%;
5515: margin: 0;
5516: position: fixed;
5517: top: 8.5em;
5518: bottom: 0;
5519: }
5520:
5521: .LC_iframecontainer iframe{
5522: border: none;
5523: width: 100%;
5524: height: 100%;
5525: }
5526:
1.778 bisitz 5527: .LC_filename {
5528: font-family: $mono;
5529: white-space:pre;
1.921 bisitz 5530: font-size: 120%;
1.778 bisitz 5531: }
5532:
5533: .LC_fileicon {
5534: border: none;
5535: height: 1.3em;
5536: vertical-align: text-bottom;
5537: margin-right: 0.3em;
5538: text-decoration:none;
5539: }
5540:
1.1008 www 5541: .LC_setting {
5542: text-decoration:underline;
5543: }
5544:
1.350 albertel 5545: .LC_error {
5546: color: red;
5547: }
1.795 www 5548:
1.1075.2.15 raeburn 5549: .LC_warning {
5550: color: darkorange;
5551: }
5552:
1.457 albertel 5553: .LC_diff_removed {
1.733 bisitz 5554: color: red;
1.394 albertel 5555: }
1.532 albertel 5556:
5557: .LC_info,
1.457 albertel 5558: .LC_success,
5559: .LC_diff_added {
1.350 albertel 5560: color: green;
5561: }
1.795 www 5562:
1.802 bisitz 5563: div.LC_confirm_box {
5564: background-color: #FAFAFA;
5565: border: 1px solid $lg_border_color;
5566: margin-right: 0;
5567: padding: 5px;
5568: }
5569:
5570: div.LC_confirm_box .LC_error img,
5571: div.LC_confirm_box .LC_success img {
5572: vertical-align: middle;
5573: }
5574:
1.440 albertel 5575: .LC_icon {
1.771 droeschl 5576: border: none;
1.790 droeschl 5577: vertical-align: middle;
1.771 droeschl 5578: }
5579:
1.543 albertel 5580: .LC_docs_spacer {
5581: width: 25px;
5582: height: 1px;
1.771 droeschl 5583: border: none;
1.543 albertel 5584: }
1.346 albertel 5585:
1.532 albertel 5586: .LC_internal_info {
1.735 bisitz 5587: color: #999999;
1.532 albertel 5588: }
5589:
1.794 www 5590: .LC_discussion {
1.1050 www 5591: background: $data_table_dark;
1.911 bisitz 5592: border: 1px solid black;
5593: margin: 2px;
1.794 www 5594: }
5595:
5596: .LC_disc_action_left {
1.1050 www 5597: background: $sidebg;
1.911 bisitz 5598: text-align: left;
1.1050 www 5599: padding: 4px;
5600: margin: 2px;
1.794 www 5601: }
5602:
5603: .LC_disc_action_right {
1.1050 www 5604: background: $sidebg;
1.911 bisitz 5605: text-align: right;
1.1050 www 5606: padding: 4px;
5607: margin: 2px;
1.794 www 5608: }
5609:
5610: .LC_disc_new_item {
1.911 bisitz 5611: background: white;
5612: border: 2px solid red;
1.1050 www 5613: margin: 4px;
5614: padding: 4px;
1.794 www 5615: }
5616:
5617: .LC_disc_old_item {
1.911 bisitz 5618: background: white;
1.1050 www 5619: margin: 4px;
5620: padding: 4px;
1.794 www 5621: }
5622:
1.458 albertel 5623: table.LC_pastsubmission {
5624: border: 1px solid black;
5625: margin: 2px;
5626: }
5627:
1.924 bisitz 5628: table#LC_menubuttons {
1.345 albertel 5629: width: 100%;
5630: background: $pgbg;
1.392 albertel 5631: border: 2px;
1.402 albertel 5632: border-collapse: separate;
1.803 bisitz 5633: padding: 0;
1.345 albertel 5634: }
1.392 albertel 5635:
1.801 tempelho 5636: table#LC_title_bar a {
5637: color: $fontmenu;
5638: }
1.836 bisitz 5639:
1.807 droeschl 5640: table#LC_title_bar {
1.819 tempelho 5641: clear: both;
1.836 bisitz 5642: display: none;
1.807 droeschl 5643: }
5644:
1.795 www 5645: table#LC_title_bar,
1.933 droeschl 5646: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5647: table#LC_title_bar.LC_with_remote {
1.359 albertel 5648: width: 100%;
1.392 albertel 5649: border-color: $pgbg;
5650: border-style: solid;
5651: border-width: $border;
1.379 albertel 5652: background: $pgbg;
1.801 tempelho 5653: color: $fontmenu;
1.392 albertel 5654: border-collapse: collapse;
1.803 bisitz 5655: padding: 0;
1.819 tempelho 5656: margin: 0;
1.359 albertel 5657: }
1.795 www 5658:
1.933 droeschl 5659: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5660: margin: 0;
5661: padding: 0;
1.933 droeschl 5662: position: relative;
5663: list-style: none;
1.913 droeschl 5664: }
1.933 droeschl 5665: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5666: display: inline;
5667: }
1.933 droeschl 5668:
5669: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5670: padding: 0;
1.933 droeschl 5671: margin: 0;
5672: float: left;
1.913 droeschl 5673: }
1.933 droeschl 5674: .LC_breadcrumb_tools_tools {
5675: padding: 0;
5676: margin: 0;
1.913 droeschl 5677: float: right;
5678: }
5679:
1.359 albertel 5680: table#LC_title_bar td {
5681: background: $tabbg;
5682: }
1.795 www 5683:
1.911 bisitz 5684: table#LC_menubuttons img {
1.803 bisitz 5685: border: none;
1.346 albertel 5686: }
1.795 www 5687:
1.842 droeschl 5688: .LC_breadcrumbs_component {
1.911 bisitz 5689: float: right;
5690: margin: 0 1em;
1.357 albertel 5691: }
1.842 droeschl 5692: .LC_breadcrumbs_component img {
1.911 bisitz 5693: vertical-align: middle;
1.777 tempelho 5694: }
1.795 www 5695:
1.383 albertel 5696: td.LC_table_cell_checkbox {
5697: text-align: center;
5698: }
1.795 www 5699:
5700: .LC_fontsize_small {
1.911 bisitz 5701: font-size: 70%;
1.705 tempelho 5702: }
5703:
1.844 bisitz 5704: #LC_breadcrumbs {
1.911 bisitz 5705: clear:both;
5706: background: $sidebg;
5707: border-bottom: 1px solid $lg_border_color;
5708: line-height: 2.5em;
1.933 droeschl 5709: overflow: hidden;
1.911 bisitz 5710: margin: 0;
5711: padding: 0;
1.995 raeburn 5712: text-align: left;
1.819 tempelho 5713: }
1.862 bisitz 5714:
1.1075.2.16 raeburn 5715: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5716: clear:both;
5717: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5718: border: 1px solid $sidebg;
1.1075.2.16 raeburn 5719: margin: 0 0 10px 0;
1.966 bisitz 5720: padding: 3px;
1.995 raeburn 5721: text-align: left;
1.822 bisitz 5722: }
5723:
1.795 www 5724: .LC_fontsize_medium {
1.911 bisitz 5725: font-size: 85%;
1.705 tempelho 5726: }
5727:
1.795 www 5728: .LC_fontsize_large {
1.911 bisitz 5729: font-size: 120%;
1.705 tempelho 5730: }
5731:
1.346 albertel 5732: .LC_menubuttons_inline_text {
5733: color: $font;
1.698 harmsja 5734: font-size: 90%;
1.701 harmsja 5735: padding-left:3px;
1.346 albertel 5736: }
5737:
1.934 droeschl 5738: .LC_menubuttons_inline_text img{
5739: vertical-align: middle;
5740: }
5741:
1.1051 www 5742: li.LC_menubuttons_inline_text img {
1.951 onken 5743: cursor:pointer;
1.1002 droeschl 5744: text-decoration: none;
1.951 onken 5745: }
5746:
1.526 www 5747: .LC_menubuttons_link {
5748: text-decoration: none;
5749: }
1.795 www 5750:
1.522 albertel 5751: .LC_menubuttons_category {
1.521 www 5752: color: $font;
1.526 www 5753: background: $pgbg;
1.521 www 5754: font-size: larger;
5755: font-weight: bold;
5756: }
5757:
1.346 albertel 5758: td.LC_menubuttons_text {
1.911 bisitz 5759: color: $font;
1.346 albertel 5760: }
1.706 harmsja 5761:
1.346 albertel 5762: .LC_current_location {
5763: background: $tabbg;
5764: }
1.795 www 5765:
1.938 bisitz 5766: table.LC_data_table {
1.347 albertel 5767: border: 1px solid #000000;
1.402 albertel 5768: border-collapse: separate;
1.426 albertel 5769: border-spacing: 1px;
1.610 albertel 5770: background: $pgbg;
1.347 albertel 5771: }
1.795 www 5772:
1.422 albertel 5773: .LC_data_table_dense {
5774: font-size: small;
5775: }
1.795 www 5776:
1.507 raeburn 5777: table.LC_nested_outer {
5778: border: 1px solid #000000;
1.589 raeburn 5779: border-collapse: collapse;
1.803 bisitz 5780: border-spacing: 0;
1.507 raeburn 5781: width: 100%;
5782: }
1.795 www 5783:
1.879 raeburn 5784: table.LC_innerpickbox,
1.507 raeburn 5785: table.LC_nested {
1.803 bisitz 5786: border: none;
1.589 raeburn 5787: border-collapse: collapse;
1.803 bisitz 5788: border-spacing: 0;
1.507 raeburn 5789: width: 100%;
5790: }
1.795 www 5791:
1.911 bisitz 5792: table.LC_data_table tr th,
5793: table.LC_calendar tr th,
1.879 raeburn 5794: table.LC_prior_tries tr th,
5795: table.LC_innerpickbox tr th {
1.349 albertel 5796: font-weight: bold;
5797: background-color: $data_table_head;
1.801 tempelho 5798: color:$fontmenu;
1.701 harmsja 5799: font-size:90%;
1.347 albertel 5800: }
1.795 www 5801:
1.879 raeburn 5802: table.LC_innerpickbox tr th,
5803: table.LC_innerpickbox tr td {
5804: vertical-align: top;
5805: }
5806:
1.711 raeburn 5807: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5808: background-color: #CCCCCC;
1.711 raeburn 5809: font-weight: bold;
5810: text-align: left;
5811: }
1.795 www 5812:
1.912 bisitz 5813: table.LC_data_table tr.LC_odd_row > td {
5814: background-color: $data_table_light;
5815: padding: 2px;
5816: vertical-align: top;
5817: }
5818:
1.809 bisitz 5819: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5820: background-color: $data_table_light;
1.912 bisitz 5821: vertical-align: top;
5822: }
5823:
5824: table.LC_data_table tr.LC_even_row > td {
5825: background-color: $data_table_dark;
1.425 albertel 5826: padding: 2px;
1.900 bisitz 5827: vertical-align: top;
1.347 albertel 5828: }
1.795 www 5829:
1.809 bisitz 5830: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5831: background-color: $data_table_dark;
1.900 bisitz 5832: vertical-align: top;
1.347 albertel 5833: }
1.795 www 5834:
1.425 albertel 5835: table.LC_data_table tr.LC_data_table_highlight td {
5836: background-color: $data_table_darker;
5837: }
1.795 www 5838:
1.639 raeburn 5839: table.LC_data_table tr td.LC_leftcol_header {
5840: background-color: $data_table_head;
5841: font-weight: bold;
5842: }
1.795 www 5843:
1.451 albertel 5844: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5845: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5846: font-weight: bold;
5847: font-style: italic;
5848: text-align: center;
5849: padding: 8px;
1.347 albertel 5850: }
1.795 www 5851:
1.1075.2.30 raeburn 5852: table.LC_data_table tr.LC_empty_row td,
5853: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5854: background-color: $sidebg;
5855: }
5856:
5857: table.LC_nested tr.LC_empty_row td {
5858: background-color: #FFFFFF;
5859: }
5860:
1.890 droeschl 5861: table.LC_caption {
5862: }
5863:
1.507 raeburn 5864: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5865: padding: 4ex
5866: }
1.795 www 5867:
1.507 raeburn 5868: table.LC_nested_outer tr th {
5869: font-weight: bold;
1.801 tempelho 5870: color:$fontmenu;
1.507 raeburn 5871: background-color: $data_table_head;
1.701 harmsja 5872: font-size: small;
1.507 raeburn 5873: border-bottom: 1px solid #000000;
5874: }
1.795 www 5875:
1.507 raeburn 5876: table.LC_nested_outer tr td.LC_subheader {
5877: background-color: $data_table_head;
5878: font-weight: bold;
5879: font-size: small;
5880: border-bottom: 1px solid #000000;
5881: text-align: right;
1.451 albertel 5882: }
1.795 www 5883:
1.507 raeburn 5884: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5885: background-color: #CCCCCC;
1.451 albertel 5886: font-weight: bold;
5887: font-size: small;
1.507 raeburn 5888: text-align: center;
5889: }
1.795 www 5890:
1.589 raeburn 5891: table.LC_nested tr.LC_info_row td.LC_left_item,
5892: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5893: text-align: left;
1.451 albertel 5894: }
1.795 www 5895:
1.507 raeburn 5896: table.LC_nested td {
1.735 bisitz 5897: background-color: #FFFFFF;
1.451 albertel 5898: font-size: small;
1.507 raeburn 5899: }
1.795 www 5900:
1.507 raeburn 5901: table.LC_nested_outer tr th.LC_right_item,
5902: table.LC_nested tr.LC_info_row td.LC_right_item,
5903: table.LC_nested tr.LC_odd_row td.LC_right_item,
5904: table.LC_nested tr td.LC_right_item {
1.451 albertel 5905: text-align: right;
5906: }
5907:
1.507 raeburn 5908: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5909: background-color: #EEEEEE;
1.451 albertel 5910: }
5911:
1.473 raeburn 5912: table.LC_createuser {
5913: }
5914:
5915: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5916: font-size: small;
1.473 raeburn 5917: }
5918:
5919: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5920: background-color: #CCCCCC;
1.473 raeburn 5921: font-weight: bold;
5922: text-align: center;
5923: }
5924:
1.349 albertel 5925: table.LC_calendar {
5926: border: 1px solid #000000;
5927: border-collapse: collapse;
1.917 raeburn 5928: width: 98%;
1.349 albertel 5929: }
1.795 www 5930:
1.349 albertel 5931: table.LC_calendar_pickdate {
5932: font-size: xx-small;
5933: }
1.795 www 5934:
1.349 albertel 5935: table.LC_calendar tr td {
5936: border: 1px solid #000000;
5937: vertical-align: top;
1.917 raeburn 5938: width: 14%;
1.349 albertel 5939: }
1.795 www 5940:
1.349 albertel 5941: table.LC_calendar tr td.LC_calendar_day_empty {
5942: background-color: $data_table_dark;
5943: }
1.795 www 5944:
1.779 bisitz 5945: table.LC_calendar tr td.LC_calendar_day_current {
5946: background-color: $data_table_highlight;
1.777 tempelho 5947: }
1.795 www 5948:
1.938 bisitz 5949: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5950: background-color: $mail_new;
5951: }
1.795 www 5952:
1.938 bisitz 5953: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5954: background-color: $mail_new_hover;
5955: }
1.795 www 5956:
1.938 bisitz 5957: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5958: background-color: $mail_read;
5959: }
1.795 www 5960:
1.938 bisitz 5961: /*
5962: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5963: background-color: $mail_read_hover;
5964: }
1.938 bisitz 5965: */
1.795 www 5966:
1.938 bisitz 5967: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5968: background-color: $mail_replied;
5969: }
1.795 www 5970:
1.938 bisitz 5971: /*
5972: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5973: background-color: $mail_replied_hover;
5974: }
1.938 bisitz 5975: */
1.795 www 5976:
1.938 bisitz 5977: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5978: background-color: $mail_other;
5979: }
1.795 www 5980:
1.938 bisitz 5981: /*
5982: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5983: background-color: $mail_other_hover;
5984: }
1.938 bisitz 5985: */
1.494 raeburn 5986:
1.777 tempelho 5987: table.LC_data_table tr > td.LC_browser_file,
5988: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5989: background: #AAEE77;
1.389 albertel 5990: }
1.795 www 5991:
1.777 tempelho 5992: table.LC_data_table tr > td.LC_browser_file_locked,
5993: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5994: background: #FFAA99;
1.387 albertel 5995: }
1.795 www 5996:
1.777 tempelho 5997: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5998: background: #888888;
1.779 bisitz 5999: }
1.795 www 6000:
1.777 tempelho 6001: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6002: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6003: background: #F8F866;
1.777 tempelho 6004: }
1.795 www 6005:
1.696 bisitz 6006: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6007: background: #E0E8FF;
1.387 albertel 6008: }
1.696 bisitz 6009:
1.707 bisitz 6010: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6011: /* background: #77FF77; */
1.707 bisitz 6012: }
1.795 www 6013:
1.707 bisitz 6014: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6015: border-right: 8px solid #FFFF77;
1.707 bisitz 6016: }
1.795 www 6017:
1.707 bisitz 6018: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6019: border-right: 8px solid #FFAA77;
1.707 bisitz 6020: }
1.795 www 6021:
1.707 bisitz 6022: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6023: border-right: 8px solid #FF7777;
1.707 bisitz 6024: }
1.795 www 6025:
1.707 bisitz 6026: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6027: border-right: 8px solid #AAFF77;
1.707 bisitz 6028: }
1.795 www 6029:
1.707 bisitz 6030: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6031: border-right: 8px solid #11CC55;
1.707 bisitz 6032: }
6033:
1.388 albertel 6034: span.LC_current_location {
1.701 harmsja 6035: font-size:larger;
1.388 albertel 6036: background: $pgbg;
6037: }
1.387 albertel 6038:
1.1029 www 6039: span.LC_current_nav_location {
6040: font-weight:bold;
6041: background: $sidebg;
6042: }
6043:
1.395 albertel 6044: span.LC_parm_menu_item {
6045: font-size: larger;
6046: }
1.795 www 6047:
1.395 albertel 6048: span.LC_parm_scope_all {
6049: color: red;
6050: }
1.795 www 6051:
1.395 albertel 6052: span.LC_parm_scope_folder {
6053: color: green;
6054: }
1.795 www 6055:
1.395 albertel 6056: span.LC_parm_scope_resource {
6057: color: orange;
6058: }
1.795 www 6059:
1.395 albertel 6060: span.LC_parm_part {
6061: color: blue;
6062: }
1.795 www 6063:
1.911 bisitz 6064: span.LC_parm_folder,
6065: span.LC_parm_symb {
1.395 albertel 6066: font-size: x-small;
6067: font-family: $mono;
6068: color: #AAAAAA;
6069: }
6070:
1.977 bisitz 6071: ul.LC_parm_parmlist li {
6072: display: inline-block;
6073: padding: 0.3em 0.8em;
6074: vertical-align: top;
6075: width: 150px;
6076: border-top:1px solid $lg_border_color;
6077: }
6078:
1.795 www 6079: td.LC_parm_overview_level_menu,
6080: td.LC_parm_overview_map_menu,
6081: td.LC_parm_overview_parm_selectors,
6082: td.LC_parm_overview_restrictions {
1.396 albertel 6083: border: 1px solid black;
6084: border-collapse: collapse;
6085: }
1.795 www 6086:
1.396 albertel 6087: table.LC_parm_overview_restrictions td {
6088: border-width: 1px 4px 1px 4px;
6089: border-style: solid;
6090: border-color: $pgbg;
6091: text-align: center;
6092: }
1.795 www 6093:
1.396 albertel 6094: table.LC_parm_overview_restrictions th {
6095: background: $tabbg;
6096: border-width: 1px 4px 1px 4px;
6097: border-style: solid;
6098: border-color: $pgbg;
6099: }
1.795 www 6100:
1.398 albertel 6101: table#LC_helpmenu {
1.803 bisitz 6102: border: none;
1.398 albertel 6103: height: 55px;
1.803 bisitz 6104: border-spacing: 0;
1.398 albertel 6105: }
6106:
6107: table#LC_helpmenu fieldset legend {
6108: font-size: larger;
6109: }
1.795 www 6110:
1.397 albertel 6111: table#LC_helpmenu_links {
6112: width: 100%;
6113: border: 1px solid black;
6114: background: $pgbg;
1.803 bisitz 6115: padding: 0;
1.397 albertel 6116: border-spacing: 1px;
6117: }
1.795 www 6118:
1.397 albertel 6119: table#LC_helpmenu_links tr td {
6120: padding: 1px;
6121: background: $tabbg;
1.399 albertel 6122: text-align: center;
6123: font-weight: bold;
1.397 albertel 6124: }
1.396 albertel 6125:
1.795 www 6126: table#LC_helpmenu_links a:link,
6127: table#LC_helpmenu_links a:visited,
1.397 albertel 6128: table#LC_helpmenu_links a:active {
6129: text-decoration: none;
6130: color: $font;
6131: }
1.795 www 6132:
1.397 albertel 6133: table#LC_helpmenu_links a:hover {
6134: text-decoration: underline;
6135: color: $vlink;
6136: }
1.396 albertel 6137:
1.417 albertel 6138: .LC_chrt_popup_exists {
6139: border: 1px solid #339933;
6140: margin: -1px;
6141: }
1.795 www 6142:
1.417 albertel 6143: .LC_chrt_popup_up {
6144: border: 1px solid yellow;
6145: margin: -1px;
6146: }
1.795 www 6147:
1.417 albertel 6148: .LC_chrt_popup {
6149: border: 1px solid #8888FF;
6150: background: #CCCCFF;
6151: }
1.795 www 6152:
1.421 albertel 6153: table.LC_pick_box {
6154: border-collapse: separate;
6155: background: white;
6156: border: 1px solid black;
6157: border-spacing: 1px;
6158: }
1.795 www 6159:
1.421 albertel 6160: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6161: background: $sidebg;
1.421 albertel 6162: font-weight: bold;
1.900 bisitz 6163: text-align: left;
1.740 bisitz 6164: vertical-align: top;
1.421 albertel 6165: width: 184px;
6166: padding: 8px;
6167: }
1.795 www 6168:
1.579 raeburn 6169: table.LC_pick_box td.LC_pick_box_value {
6170: text-align: left;
6171: padding: 8px;
6172: }
1.795 www 6173:
1.579 raeburn 6174: table.LC_pick_box td.LC_pick_box_select {
6175: text-align: left;
6176: padding: 8px;
6177: }
1.795 www 6178:
1.424 albertel 6179: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6180: padding: 0;
1.421 albertel 6181: height: 1px;
6182: background: black;
6183: }
1.795 www 6184:
1.421 albertel 6185: table.LC_pick_box td.LC_pick_box_submit {
6186: text-align: right;
6187: }
1.795 www 6188:
1.579 raeburn 6189: table.LC_pick_box td.LC_evenrow_value {
6190: text-align: left;
6191: padding: 8px;
6192: background-color: $data_table_light;
6193: }
1.795 www 6194:
1.579 raeburn 6195: table.LC_pick_box td.LC_oddrow_value {
6196: text-align: left;
6197: padding: 8px;
6198: background-color: $data_table_light;
6199: }
1.795 www 6200:
1.579 raeburn 6201: span.LC_helpform_receipt_cat {
6202: font-weight: bold;
6203: }
1.795 www 6204:
1.424 albertel 6205: table.LC_group_priv_box {
6206: background: white;
6207: border: 1px solid black;
6208: border-spacing: 1px;
6209: }
1.795 www 6210:
1.424 albertel 6211: table.LC_group_priv_box td.LC_pick_box_title {
6212: background: $tabbg;
6213: font-weight: bold;
6214: text-align: right;
6215: width: 184px;
6216: }
1.795 www 6217:
1.424 albertel 6218: table.LC_group_priv_box td.LC_groups_fixed {
6219: background: $data_table_light;
6220: text-align: center;
6221: }
1.795 www 6222:
1.424 albertel 6223: table.LC_group_priv_box td.LC_groups_optional {
6224: background: $data_table_dark;
6225: text-align: center;
6226: }
1.795 www 6227:
1.424 albertel 6228: table.LC_group_priv_box td.LC_groups_functionality {
6229: background: $data_table_darker;
6230: text-align: center;
6231: font-weight: bold;
6232: }
1.795 www 6233:
1.424 albertel 6234: table.LC_group_priv td {
6235: text-align: left;
1.803 bisitz 6236: padding: 0;
1.424 albertel 6237: }
6238:
6239: .LC_navbuttons {
6240: margin: 2ex 0ex 2ex 0ex;
6241: }
1.795 www 6242:
1.423 albertel 6243: .LC_topic_bar {
6244: font-weight: bold;
6245: background: $tabbg;
1.918 wenzelju 6246: margin: 1em 0em 1em 2em;
1.805 bisitz 6247: padding: 3px;
1.918 wenzelju 6248: font-size: 1.2em;
1.423 albertel 6249: }
1.795 www 6250:
1.423 albertel 6251: .LC_topic_bar span {
1.918 wenzelju 6252: left: 0.5em;
6253: position: absolute;
1.423 albertel 6254: vertical-align: middle;
1.918 wenzelju 6255: font-size: 1.2em;
1.423 albertel 6256: }
1.795 www 6257:
1.423 albertel 6258: table.LC_course_group_status {
6259: margin: 20px;
6260: }
1.795 www 6261:
1.423 albertel 6262: table.LC_status_selector td {
6263: vertical-align: top;
6264: text-align: center;
1.424 albertel 6265: padding: 4px;
6266: }
1.795 www 6267:
1.599 albertel 6268: div.LC_feedback_link {
1.616 albertel 6269: clear: both;
1.829 kalberla 6270: background: $sidebg;
1.779 bisitz 6271: width: 100%;
1.829 kalberla 6272: padding-bottom: 10px;
6273: border: 1px $tabbg solid;
1.833 kalberla 6274: height: 22px;
6275: line-height: 22px;
6276: padding-top: 5px;
6277: }
6278:
6279: div.LC_feedback_link img {
6280: height: 22px;
1.867 kalberla 6281: vertical-align:middle;
1.829 kalberla 6282: }
6283:
1.911 bisitz 6284: div.LC_feedback_link a {
1.829 kalberla 6285: text-decoration: none;
1.489 raeburn 6286: }
1.795 www 6287:
1.867 kalberla 6288: div.LC_comblock {
1.911 bisitz 6289: display:inline;
1.867 kalberla 6290: color:$font;
6291: font-size:90%;
6292: }
6293:
6294: div.LC_feedback_link div.LC_comblock {
6295: padding-left:5px;
6296: }
6297:
6298: div.LC_feedback_link div.LC_comblock a {
6299: color:$font;
6300: }
6301:
1.489 raeburn 6302: span.LC_feedback_link {
1.858 bisitz 6303: /* background: $feedback_link_bg; */
1.599 albertel 6304: font-size: larger;
6305: }
1.795 www 6306:
1.599 albertel 6307: span.LC_message_link {
1.858 bisitz 6308: /* background: $feedback_link_bg; */
1.599 albertel 6309: font-size: larger;
6310: position: absolute;
6311: right: 1em;
1.489 raeburn 6312: }
1.421 albertel 6313:
1.515 albertel 6314: table.LC_prior_tries {
1.524 albertel 6315: border: 1px solid #000000;
6316: border-collapse: separate;
6317: border-spacing: 1px;
1.515 albertel 6318: }
1.523 albertel 6319:
1.515 albertel 6320: table.LC_prior_tries td {
1.524 albertel 6321: padding: 2px;
1.515 albertel 6322: }
1.523 albertel 6323:
6324: .LC_answer_correct {
1.795 www 6325: background: lightgreen;
6326: color: darkgreen;
6327: padding: 6px;
1.523 albertel 6328: }
1.795 www 6329:
1.523 albertel 6330: .LC_answer_charged_try {
1.797 www 6331: background: #FFAAAA;
1.795 www 6332: color: darkred;
6333: padding: 6px;
1.523 albertel 6334: }
1.795 www 6335:
1.779 bisitz 6336: .LC_answer_not_charged_try,
1.523 albertel 6337: .LC_answer_no_grade,
6338: .LC_answer_late {
1.795 www 6339: background: lightyellow;
1.523 albertel 6340: color: black;
1.795 www 6341: padding: 6px;
1.523 albertel 6342: }
1.795 www 6343:
1.523 albertel 6344: .LC_answer_previous {
1.795 www 6345: background: lightblue;
6346: color: darkblue;
6347: padding: 6px;
1.523 albertel 6348: }
1.795 www 6349:
1.779 bisitz 6350: .LC_answer_no_message {
1.777 tempelho 6351: background: #FFFFFF;
6352: color: black;
1.795 www 6353: padding: 6px;
1.779 bisitz 6354: }
1.795 www 6355:
1.779 bisitz 6356: .LC_answer_unknown {
6357: background: orange;
6358: color: black;
1.795 www 6359: padding: 6px;
1.777 tempelho 6360: }
1.795 www 6361:
1.529 albertel 6362: span.LC_prior_numerical,
6363: span.LC_prior_string,
6364: span.LC_prior_custom,
6365: span.LC_prior_reaction,
6366: span.LC_prior_math {
1.925 bisitz 6367: font-family: $mono;
1.523 albertel 6368: white-space: pre;
6369: }
6370:
1.525 albertel 6371: span.LC_prior_string {
1.925 bisitz 6372: font-family: $mono;
1.525 albertel 6373: white-space: pre;
6374: }
6375:
1.523 albertel 6376: table.LC_prior_option {
6377: width: 100%;
6378: border-collapse: collapse;
6379: }
1.795 www 6380:
1.911 bisitz 6381: table.LC_prior_rank,
1.795 www 6382: table.LC_prior_match {
1.528 albertel 6383: border-collapse: collapse;
6384: }
1.795 www 6385:
1.528 albertel 6386: table.LC_prior_option tr td,
6387: table.LC_prior_rank tr td,
6388: table.LC_prior_match tr td {
1.524 albertel 6389: border: 1px solid #000000;
1.515 albertel 6390: }
6391:
1.855 bisitz 6392: .LC_nobreak {
1.544 albertel 6393: white-space: nowrap;
1.519 raeburn 6394: }
6395:
1.576 raeburn 6396: span.LC_cusr_emph {
6397: font-style: italic;
6398: }
6399:
1.633 raeburn 6400: span.LC_cusr_subheading {
6401: font-weight: normal;
6402: font-size: 85%;
6403: }
6404:
1.861 bisitz 6405: div.LC_docs_entry_move {
1.859 bisitz 6406: border: 1px solid #BBBBBB;
1.545 albertel 6407: background: #DDDDDD;
1.861 bisitz 6408: width: 22px;
1.859 bisitz 6409: padding: 1px;
6410: margin: 0;
1.545 albertel 6411: }
6412:
1.861 bisitz 6413: table.LC_data_table tr > td.LC_docs_entry_commands,
6414: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6415: font-size: x-small;
6416: }
1.795 www 6417:
1.861 bisitz 6418: .LC_docs_entry_parameter {
6419: white-space: nowrap;
6420: }
6421:
1.544 albertel 6422: .LC_docs_copy {
1.545 albertel 6423: color: #000099;
1.544 albertel 6424: }
1.795 www 6425:
1.544 albertel 6426: .LC_docs_cut {
1.545 albertel 6427: color: #550044;
1.544 albertel 6428: }
1.795 www 6429:
1.544 albertel 6430: .LC_docs_rename {
1.545 albertel 6431: color: #009900;
1.544 albertel 6432: }
1.795 www 6433:
1.544 albertel 6434: .LC_docs_remove {
1.545 albertel 6435: color: #990000;
6436: }
6437:
1.547 albertel 6438: .LC_docs_reinit_warn,
6439: .LC_docs_ext_edit {
6440: font-size: x-small;
6441: }
6442:
1.545 albertel 6443: table.LC_docs_adddocs td,
6444: table.LC_docs_adddocs th {
6445: border: 1px solid #BBBBBB;
6446: padding: 4px;
6447: background: #DDDDDD;
1.543 albertel 6448: }
6449:
1.584 albertel 6450: table.LC_sty_begin {
6451: background: #BBFFBB;
6452: }
1.795 www 6453:
1.584 albertel 6454: table.LC_sty_end {
6455: background: #FFBBBB;
6456: }
6457:
1.589 raeburn 6458: table.LC_double_column {
1.803 bisitz 6459: border-width: 0;
1.589 raeburn 6460: border-collapse: collapse;
6461: width: 100%;
6462: padding: 2px;
6463: }
6464:
6465: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6466: top: 2px;
1.589 raeburn 6467: left: 2px;
6468: width: 47%;
6469: vertical-align: top;
6470: }
6471:
6472: table.LC_double_column tr td.LC_right_col {
6473: top: 2px;
1.779 bisitz 6474: right: 2px;
1.589 raeburn 6475: width: 47%;
6476: vertical-align: top;
6477: }
6478:
1.591 raeburn 6479: div.LC_left_float {
6480: float: left;
6481: padding-right: 5%;
1.597 albertel 6482: padding-bottom: 4px;
1.591 raeburn 6483: }
6484:
6485: div.LC_clear_float_header {
1.597 albertel 6486: padding-bottom: 2px;
1.591 raeburn 6487: }
6488:
6489: div.LC_clear_float_footer {
1.597 albertel 6490: padding-top: 10px;
1.591 raeburn 6491: clear: both;
6492: }
6493:
1.597 albertel 6494: div.LC_grade_show_user {
1.941 bisitz 6495: /* border-left: 5px solid $sidebg; */
6496: border-top: 5px solid #000000;
6497: margin: 50px 0 0 0;
1.936 bisitz 6498: padding: 15px 0 5px 10px;
1.597 albertel 6499: }
1.795 www 6500:
1.936 bisitz 6501: div.LC_grade_show_user_odd_row {
1.941 bisitz 6502: /* border-left: 5px solid #000000; */
6503: }
6504:
6505: div.LC_grade_show_user div.LC_Box {
6506: margin-right: 50px;
1.597 albertel 6507: }
6508:
6509: div.LC_grade_submissions,
6510: div.LC_grade_message_center,
1.936 bisitz 6511: div.LC_grade_info_links {
1.597 albertel 6512: margin: 5px;
6513: width: 99%;
6514: background: #FFFFFF;
6515: }
1.795 www 6516:
1.597 albertel 6517: div.LC_grade_submissions_header,
1.936 bisitz 6518: div.LC_grade_message_center_header {
1.705 tempelho 6519: font-weight: bold;
6520: font-size: large;
1.597 albertel 6521: }
1.795 www 6522:
1.597 albertel 6523: div.LC_grade_submissions_body,
1.936 bisitz 6524: div.LC_grade_message_center_body {
1.597 albertel 6525: border: 1px solid black;
6526: width: 99%;
6527: background: #FFFFFF;
6528: }
1.795 www 6529:
1.613 albertel 6530: table.LC_scantron_action {
6531: width: 100%;
6532: }
1.795 www 6533:
1.613 albertel 6534: table.LC_scantron_action tr th {
1.698 harmsja 6535: font-weight:bold;
6536: font-style:normal;
1.613 albertel 6537: }
1.795 www 6538:
1.779 bisitz 6539: .LC_edit_problem_header,
1.614 albertel 6540: div.LC_edit_problem_footer {
1.705 tempelho 6541: font-weight: normal;
6542: font-size: medium;
1.602 albertel 6543: margin: 2px;
1.1060 bisitz 6544: background-color: $sidebg;
1.600 albertel 6545: }
1.795 www 6546:
1.600 albertel 6547: div.LC_edit_problem_header,
1.602 albertel 6548: div.LC_edit_problem_header div,
1.614 albertel 6549: div.LC_edit_problem_footer,
6550: div.LC_edit_problem_footer div,
1.602 albertel 6551: div.LC_edit_problem_editxml_header,
6552: div.LC_edit_problem_editxml_header div {
1.600 albertel 6553: margin-top: 5px;
6554: }
1.795 www 6555:
1.600 albertel 6556: div.LC_edit_problem_header_title {
1.705 tempelho 6557: font-weight: bold;
6558: font-size: larger;
1.602 albertel 6559: background: $tabbg;
6560: padding: 3px;
1.1060 bisitz 6561: margin: 0 0 5px 0;
1.602 albertel 6562: }
1.795 www 6563:
1.602 albertel 6564: table.LC_edit_problem_header_title {
6565: width: 100%;
1.600 albertel 6566: background: $tabbg;
1.602 albertel 6567: }
6568:
6569: div.LC_edit_problem_discards {
6570: float: left;
6571: padding-bottom: 5px;
6572: }
1.795 www 6573:
1.602 albertel 6574: div.LC_edit_problem_saves {
6575: float: right;
6576: padding-bottom: 5px;
1.600 albertel 6577: }
1.795 www 6578:
1.1075.2.34 raeburn 6579: .LC_edit_opt {
6580: padding-left: 1em;
6581: white-space: nowrap;
6582: }
6583:
1.1075.2.57 raeburn 6584: .LC_edit_problem_latexhelper{
6585: text-align: right;
6586: }
6587:
6588: #LC_edit_problem_colorful div{
6589: margin-left: 40px;
6590: }
6591:
1.911 bisitz 6592: img.stift {
1.803 bisitz 6593: border-width: 0;
6594: vertical-align: middle;
1.677 riegler 6595: }
1.680 riegler 6596:
1.923 bisitz 6597: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6598: vertical-align: top;
1.777 tempelho 6599: }
1.795 www 6600:
1.716 raeburn 6601: div.LC_createcourse {
1.911 bisitz 6602: margin: 10px 10px 10px 10px;
1.716 raeburn 6603: }
6604:
1.917 raeburn 6605: .LC_dccid {
1.1075.2.38 raeburn 6606: float: right;
1.917 raeburn 6607: margin: 0.2em 0 0 0;
6608: padding: 0;
6609: font-size: 90%;
6610: display:none;
6611: }
6612:
1.897 wenzelju 6613: ol.LC_primary_menu a:hover,
1.721 harmsja 6614: ol#LC_MenuBreadcrumbs a:hover,
6615: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6616: ul#LC_secondary_menu a:hover,
1.721 harmsja 6617: .LC_FormSectionClearButton input:hover
1.795 www 6618: ul.LC_TabContent li:hover a {
1.952 onken 6619: color:$button_hover;
1.911 bisitz 6620: text-decoration:none;
1.693 droeschl 6621: }
6622:
1.779 bisitz 6623: h1 {
1.911 bisitz 6624: padding: 0;
6625: line-height:130%;
1.693 droeschl 6626: }
1.698 harmsja 6627:
1.911 bisitz 6628: h2,
6629: h3,
6630: h4,
6631: h5,
6632: h6 {
6633: margin: 5px 0 5px 0;
6634: padding: 0;
6635: line-height:130%;
1.693 droeschl 6636: }
1.795 www 6637:
6638: .LC_hcell {
1.911 bisitz 6639: padding:3px 15px 3px 15px;
6640: margin: 0;
6641: background-color:$tabbg;
6642: color:$fontmenu;
6643: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6644: }
1.795 www 6645:
1.840 bisitz 6646: .LC_Box > .LC_hcell {
1.911 bisitz 6647: margin: 0 -10px 10px -10px;
1.835 bisitz 6648: }
6649:
1.721 harmsja 6650: .LC_noBorder {
1.911 bisitz 6651: border: 0;
1.698 harmsja 6652: }
1.693 droeschl 6653:
1.721 harmsja 6654: .LC_FormSectionClearButton input {
1.911 bisitz 6655: background-color:transparent;
6656: border: none;
6657: cursor:pointer;
6658: text-decoration:underline;
1.693 droeschl 6659: }
1.763 bisitz 6660:
6661: .LC_help_open_topic {
1.911 bisitz 6662: color: #FFFFFF;
6663: background-color: #EEEEFF;
6664: margin: 1px;
6665: padding: 4px;
6666: border: 1px solid #000033;
6667: white-space: nowrap;
6668: /* vertical-align: middle; */
1.759 neumanie 6669: }
1.693 droeschl 6670:
1.911 bisitz 6671: dl,
6672: ul,
6673: div,
6674: fieldset {
6675: margin: 10px 10px 10px 0;
6676: /* overflow: hidden; */
1.693 droeschl 6677: }
1.795 www 6678:
1.838 bisitz 6679: fieldset > legend {
1.911 bisitz 6680: font-weight: bold;
6681: padding: 0 5px 0 5px;
1.838 bisitz 6682: }
6683:
1.813 bisitz 6684: #LC_nav_bar {
1.911 bisitz 6685: float: left;
1.995 raeburn 6686: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6687: margin: 0 0 2px 0;
1.807 droeschl 6688: }
6689:
1.916 droeschl 6690: #LC_realm {
6691: margin: 0.2em 0 0 0;
6692: padding: 0;
6693: font-weight: bold;
6694: text-align: center;
1.995 raeburn 6695: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6696: }
6697:
1.911 bisitz 6698: #LC_nav_bar em {
6699: font-weight: bold;
6700: font-style: normal;
1.807 droeschl 6701: }
6702:
1.897 wenzelju 6703: ol.LC_primary_menu {
1.934 droeschl 6704: margin: 0;
1.1075.2.2 raeburn 6705: padding: 0;
1.995 raeburn 6706: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6707: }
6708:
1.852 droeschl 6709: ol#LC_PathBreadcrumbs {
1.911 bisitz 6710: margin: 0;
1.693 droeschl 6711: }
6712:
1.897 wenzelju 6713: ol.LC_primary_menu li {
1.1075.2.2 raeburn 6714: color: RGB(80, 80, 80);
6715: vertical-align: middle;
6716: text-align: left;
6717: list-style: none;
6718: float: left;
6719: }
6720:
6721: ol.LC_primary_menu li a {
6722: display: block;
6723: margin: 0;
6724: padding: 0 5px 0 10px;
6725: text-decoration: none;
6726: }
6727:
6728: ol.LC_primary_menu li ul {
6729: display: none;
6730: width: 10em;
6731: background-color: $data_table_light;
6732: }
6733:
6734: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6735: display: block;
6736: position: absolute;
6737: margin: 0;
6738: padding: 0;
1.1075.2.5 raeburn 6739: z-index: 2;
1.1075.2.2 raeburn 6740: }
6741:
6742: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6743: font-size: 90%;
1.911 bisitz 6744: vertical-align: top;
1.1075.2.2 raeburn 6745: float: none;
1.1075.2.5 raeburn 6746: border-left: 1px solid black;
6747: border-right: 1px solid black;
1.1075.2.2 raeburn 6748: }
6749:
6750: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5 raeburn 6751: background-color:$data_table_light;
1.1075.2.2 raeburn 6752: }
6753:
6754: ol.LC_primary_menu li li a:hover {
6755: color:$button_hover;
6756: background-color:$data_table_dark;
1.693 droeschl 6757: }
6758:
1.897 wenzelju 6759: ol.LC_primary_menu li img {
1.911 bisitz 6760: vertical-align: bottom;
1.934 droeschl 6761: height: 1.1em;
1.1075.2.3 raeburn 6762: margin: 0.2em 0 0 0;
1.693 droeschl 6763: }
6764:
1.897 wenzelju 6765: ol.LC_primary_menu a {
1.911 bisitz 6766: color: RGB(80, 80, 80);
6767: text-decoration: none;
1.693 droeschl 6768: }
1.795 www 6769:
1.949 droeschl 6770: ol.LC_primary_menu a.LC_new_message {
6771: font-weight:bold;
6772: color: darkred;
6773: }
6774:
1.975 raeburn 6775: ol.LC_docs_parameters {
6776: margin-left: 0;
6777: padding: 0;
6778: list-style: none;
6779: }
6780:
6781: ol.LC_docs_parameters li {
6782: margin: 0;
6783: padding-right: 20px;
6784: display: inline;
6785: }
6786:
1.976 raeburn 6787: ol.LC_docs_parameters li:before {
6788: content: "\\002022 \\0020";
6789: }
6790:
6791: li.LC_docs_parameters_title {
6792: font-weight: bold;
6793: }
6794:
6795: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6796: content: "";
6797: }
6798:
1.897 wenzelju 6799: ul#LC_secondary_menu {
1.1075.2.23 raeburn 6800: clear: right;
1.911 bisitz 6801: color: $fontmenu;
6802: background: $tabbg;
6803: list-style: none;
6804: padding: 0;
6805: margin: 0;
6806: width: 100%;
1.995 raeburn 6807: text-align: left;
1.1075.2.4 raeburn 6808: float: left;
1.808 droeschl 6809: }
6810:
1.897 wenzelju 6811: ul#LC_secondary_menu li {
1.911 bisitz 6812: font-weight: bold;
6813: line-height: 1.8em;
6814: border-right: 1px solid black;
6815: vertical-align: middle;
1.1075.2.4 raeburn 6816: float: left;
6817: }
6818:
6819: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6820: background-color: $data_table_light;
6821: }
6822:
6823: ul#LC_secondary_menu li a {
6824: padding: 0 0.8em;
6825: }
6826:
6827: ul#LC_secondary_menu li ul {
6828: display: none;
6829: }
6830:
6831: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6832: display: block;
6833: position: absolute;
6834: margin: 0;
6835: padding: 0;
6836: list-style:none;
6837: float: none;
6838: background-color: $data_table_light;
1.1075.2.5 raeburn 6839: z-index: 2;
1.1075.2.10 raeburn 6840: margin-left: -1px;
1.1075.2.4 raeburn 6841: }
6842:
6843: ul#LC_secondary_menu li ul li {
6844: font-size: 90%;
6845: vertical-align: top;
6846: border-left: 1px solid black;
6847: border-right: 1px solid black;
1.1075.2.33 raeburn 6848: background-color: $data_table_light;
1.1075.2.4 raeburn 6849: list-style:none;
6850: float: none;
6851: }
6852:
6853: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6854: background-color: $data_table_dark;
1.807 droeschl 6855: }
6856:
1.847 tempelho 6857: ul.LC_TabContent {
1.911 bisitz 6858: display:block;
6859: background: $sidebg;
6860: border-bottom: solid 1px $lg_border_color;
6861: list-style:none;
1.1020 raeburn 6862: margin: -1px -10px 0 -10px;
1.911 bisitz 6863: padding: 0;
1.693 droeschl 6864: }
6865:
1.795 www 6866: ul.LC_TabContent li,
6867: ul.LC_TabContentBigger li {
1.911 bisitz 6868: float:left;
1.741 harmsja 6869: }
1.795 www 6870:
1.897 wenzelju 6871: ul#LC_secondary_menu li a {
1.911 bisitz 6872: color: $fontmenu;
6873: text-decoration: none;
1.693 droeschl 6874: }
1.795 www 6875:
1.721 harmsja 6876: ul.LC_TabContent {
1.952 onken 6877: min-height:20px;
1.721 harmsja 6878: }
1.795 www 6879:
6880: ul.LC_TabContent li {
1.911 bisitz 6881: vertical-align:middle;
1.959 onken 6882: padding: 0 16px 0 10px;
1.911 bisitz 6883: background-color:$tabbg;
6884: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6885: border-left: solid 1px $font;
1.721 harmsja 6886: }
1.795 www 6887:
1.847 tempelho 6888: ul.LC_TabContent .right {
1.911 bisitz 6889: float:right;
1.847 tempelho 6890: }
6891:
1.911 bisitz 6892: ul.LC_TabContent li a,
6893: ul.LC_TabContent li {
6894: color:rgb(47,47,47);
6895: text-decoration:none;
6896: font-size:95%;
6897: font-weight:bold;
1.952 onken 6898: min-height:20px;
6899: }
6900:
1.959 onken 6901: ul.LC_TabContent li a:hover,
6902: ul.LC_TabContent li a:focus {
1.952 onken 6903: color: $button_hover;
1.959 onken 6904: background:none;
6905: outline:none;
1.952 onken 6906: }
6907:
6908: ul.LC_TabContent li:hover {
6909: color: $button_hover;
6910: cursor:pointer;
1.721 harmsja 6911: }
1.795 www 6912:
1.911 bisitz 6913: ul.LC_TabContent li.active {
1.952 onken 6914: color: $font;
1.911 bisitz 6915: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6916: border-bottom:solid 1px #FFFFFF;
6917: cursor: default;
1.744 ehlerst 6918: }
1.795 www 6919:
1.959 onken 6920: ul.LC_TabContent li.active a {
6921: color:$font;
6922: background:#FFFFFF;
6923: outline: none;
6924: }
1.1047 raeburn 6925:
6926: ul.LC_TabContent li.goback {
6927: float: left;
6928: border-left: none;
6929: }
6930:
1.870 tempelho 6931: #maincoursedoc {
1.911 bisitz 6932: clear:both;
1.870 tempelho 6933: }
6934:
6935: ul.LC_TabContentBigger {
1.911 bisitz 6936: display:block;
6937: list-style:none;
6938: padding: 0;
1.870 tempelho 6939: }
6940:
1.795 www 6941: ul.LC_TabContentBigger li {
1.911 bisitz 6942: vertical-align:bottom;
6943: height: 30px;
6944: font-size:110%;
6945: font-weight:bold;
6946: color: #737373;
1.841 tempelho 6947: }
6948:
1.957 onken 6949: ul.LC_TabContentBigger li.active {
6950: position: relative;
6951: top: 1px;
6952: }
6953:
1.870 tempelho 6954: ul.LC_TabContentBigger li a {
1.911 bisitz 6955: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6956: height: 30px;
6957: line-height: 30px;
6958: text-align: center;
6959: display: block;
6960: text-decoration: none;
1.958 onken 6961: outline: none;
1.741 harmsja 6962: }
1.795 www 6963:
1.870 tempelho 6964: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6965: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6966: color:$font;
1.744 ehlerst 6967: }
1.795 www 6968:
1.870 tempelho 6969: ul.LC_TabContentBigger li b {
1.911 bisitz 6970: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6971: display: block;
6972: float: left;
6973: padding: 0 30px;
1.957 onken 6974: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6975: }
6976:
1.956 onken 6977: ul.LC_TabContentBigger li:hover b {
6978: color:$button_hover;
6979: }
6980:
1.870 tempelho 6981: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6982: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6983: color:$font;
1.957 onken 6984: border: 0;
1.741 harmsja 6985: }
1.693 droeschl 6986:
1.870 tempelho 6987:
1.862 bisitz 6988: ul.LC_CourseBreadcrumbs {
6989: background: $sidebg;
1.1020 raeburn 6990: height: 2em;
1.862 bisitz 6991: padding-left: 10px;
1.1020 raeburn 6992: margin: 0;
1.862 bisitz 6993: list-style-position: inside;
6994: }
6995:
1.911 bisitz 6996: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6997: ol#LC_PathBreadcrumbs {
1.911 bisitz 6998: padding-left: 10px;
6999: margin: 0;
1.933 droeschl 7000: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7001: }
7002:
1.911 bisitz 7003: ol#LC_MenuBreadcrumbs li,
7004: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7005: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7006: display: inline;
1.933 droeschl 7007: white-space: normal;
1.693 droeschl 7008: }
7009:
1.823 bisitz 7010: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7011: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7012: text-decoration: none;
7013: font-size:90%;
1.693 droeschl 7014: }
1.795 www 7015:
1.969 droeschl 7016: ol#LC_MenuBreadcrumbs h1 {
7017: display: inline;
7018: font-size: 90%;
7019: line-height: 2.5em;
7020: margin: 0;
7021: padding: 0;
7022: }
7023:
1.795 www 7024: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7025: text-decoration:none;
7026: font-size:100%;
7027: font-weight:bold;
1.693 droeschl 7028: }
1.795 www 7029:
1.840 bisitz 7030: .LC_Box {
1.911 bisitz 7031: border: solid 1px $lg_border_color;
7032: padding: 0 10px 10px 10px;
1.746 neumanie 7033: }
1.795 www 7034:
1.1020 raeburn 7035: .LC_DocsBox {
7036: border: solid 1px $lg_border_color;
7037: padding: 0 0 10px 10px;
7038: }
7039:
1.795 www 7040: .LC_AboutMe_Image {
1.911 bisitz 7041: float:left;
7042: margin-right:10px;
1.747 neumanie 7043: }
1.795 www 7044:
7045: .LC_Clear_AboutMe_Image {
1.911 bisitz 7046: clear:left;
1.747 neumanie 7047: }
1.795 www 7048:
1.721 harmsja 7049: dl.LC_ListStyleClean dt {
1.911 bisitz 7050: padding-right: 5px;
7051: display: table-header-group;
1.693 droeschl 7052: }
7053:
1.721 harmsja 7054: dl.LC_ListStyleClean dd {
1.911 bisitz 7055: display: table-row;
1.693 droeschl 7056: }
7057:
1.721 harmsja 7058: .LC_ListStyleClean,
7059: .LC_ListStyleSimple,
7060: .LC_ListStyleNormal,
1.795 www 7061: .LC_ListStyleSpecial {
1.911 bisitz 7062: /* display:block; */
7063: list-style-position: inside;
7064: list-style-type: none;
7065: overflow: hidden;
7066: padding: 0;
1.693 droeschl 7067: }
7068:
1.721 harmsja 7069: .LC_ListStyleSimple li,
7070: .LC_ListStyleSimple dd,
7071: .LC_ListStyleNormal li,
7072: .LC_ListStyleNormal dd,
7073: .LC_ListStyleSpecial li,
1.795 www 7074: .LC_ListStyleSpecial dd {
1.911 bisitz 7075: margin: 0;
7076: padding: 5px 5px 5px 10px;
7077: clear: both;
1.693 droeschl 7078: }
7079:
1.721 harmsja 7080: .LC_ListStyleClean li,
7081: .LC_ListStyleClean dd {
1.911 bisitz 7082: padding-top: 0;
7083: padding-bottom: 0;
1.693 droeschl 7084: }
7085:
1.721 harmsja 7086: .LC_ListStyleSimple dd,
1.795 www 7087: .LC_ListStyleSimple li {
1.911 bisitz 7088: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7089: }
7090:
1.721 harmsja 7091: .LC_ListStyleSpecial li,
7092: .LC_ListStyleSpecial dd {
1.911 bisitz 7093: list-style-type: none;
7094: background-color: RGB(220, 220, 220);
7095: margin-bottom: 4px;
1.693 droeschl 7096: }
7097:
1.721 harmsja 7098: table.LC_SimpleTable {
1.911 bisitz 7099: margin:5px;
7100: border:solid 1px $lg_border_color;
1.795 www 7101: }
1.693 droeschl 7102:
1.721 harmsja 7103: table.LC_SimpleTable tr {
1.911 bisitz 7104: padding: 0;
7105: border:solid 1px $lg_border_color;
1.693 droeschl 7106: }
1.795 www 7107:
7108: table.LC_SimpleTable thead {
1.911 bisitz 7109: background:rgb(220,220,220);
1.693 droeschl 7110: }
7111:
1.721 harmsja 7112: div.LC_columnSection {
1.911 bisitz 7113: display: block;
7114: clear: both;
7115: overflow: hidden;
7116: margin: 0;
1.693 droeschl 7117: }
7118:
1.721 harmsja 7119: div.LC_columnSection>* {
1.911 bisitz 7120: float: left;
7121: margin: 10px 20px 10px 0;
7122: overflow:hidden;
1.693 droeschl 7123: }
1.721 harmsja 7124:
1.795 www 7125: table em {
1.911 bisitz 7126: font-weight: bold;
7127: font-style: normal;
1.748 schulted 7128: }
1.795 www 7129:
1.779 bisitz 7130: table.LC_tableBrowseRes,
1.795 www 7131: table.LC_tableOfContent {
1.911 bisitz 7132: border:none;
7133: border-spacing: 1px;
7134: padding: 3px;
7135: background-color: #FFFFFF;
7136: font-size: 90%;
1.753 droeschl 7137: }
1.789 droeschl 7138:
1.911 bisitz 7139: table.LC_tableOfContent {
7140: border-collapse: collapse;
1.789 droeschl 7141: }
7142:
1.771 droeschl 7143: table.LC_tableBrowseRes a,
1.768 schulted 7144: table.LC_tableOfContent a {
1.911 bisitz 7145: background-color: transparent;
7146: text-decoration: none;
1.753 droeschl 7147: }
7148:
1.795 www 7149: table.LC_tableOfContent img {
1.911 bisitz 7150: border: none;
7151: height: 1.3em;
7152: vertical-align: text-bottom;
7153: margin-right: 0.3em;
1.753 droeschl 7154: }
1.757 schulted 7155:
1.795 www 7156: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7157: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7158: }
7159:
1.795 www 7160: a#LC_content_toolbar_everything {
1.911 bisitz 7161: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7162: }
7163:
1.795 www 7164: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7165: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7166: }
7167:
1.795 www 7168: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7169: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7170: }
7171:
1.795 www 7172: a#LC_content_toolbar_changefolder {
1.911 bisitz 7173: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7174: }
7175:
1.795 www 7176: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7177: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7178: }
7179:
1.1043 raeburn 7180: a#LC_content_toolbar_edittoplevel {
7181: background-image:url(/res/adm/pages/edittoplevel.gif);
7182: }
7183:
1.795 www 7184: ul#LC_toolbar li a:hover {
1.911 bisitz 7185: background-position: bottom center;
1.757 schulted 7186: }
7187:
1.795 www 7188: ul#LC_toolbar {
1.911 bisitz 7189: padding: 0;
7190: margin: 2px;
7191: list-style:none;
7192: position:relative;
7193: background-color:white;
1.1075.2.9 raeburn 7194: overflow: auto;
1.757 schulted 7195: }
7196:
1.795 www 7197: ul#LC_toolbar li {
1.911 bisitz 7198: border:1px solid white;
7199: padding: 0;
7200: margin: 0;
7201: float: left;
7202: display:inline;
7203: vertical-align:middle;
1.1075.2.9 raeburn 7204: white-space: nowrap;
1.911 bisitz 7205: }
1.757 schulted 7206:
1.783 amueller 7207:
1.795 www 7208: a.LC_toolbarItem {
1.911 bisitz 7209: display:block;
7210: padding: 0;
7211: margin: 0;
7212: height: 32px;
7213: width: 32px;
7214: color:white;
7215: border: none;
7216: background-repeat:no-repeat;
7217: background-color:transparent;
1.757 schulted 7218: }
7219:
1.915 droeschl 7220: ul.LC_funclist {
7221: margin: 0;
7222: padding: 0.5em 1em 0.5em 0;
7223: }
7224:
1.933 droeschl 7225: ul.LC_funclist > li:first-child {
7226: font-weight:bold;
7227: margin-left:0.8em;
7228: }
7229:
1.915 droeschl 7230: ul.LC_funclist + ul.LC_funclist {
7231: /*
7232: left border as a seperator if we have more than
7233: one list
7234: */
7235: border-left: 1px solid $sidebg;
7236: /*
7237: this hides the left border behind the border of the
7238: outer box if element is wrapped to the next 'line'
7239: */
7240: margin-left: -1px;
7241: }
7242:
1.843 bisitz 7243: ul.LC_funclist li {
1.915 droeschl 7244: display: inline;
1.782 bisitz 7245: white-space: nowrap;
1.915 droeschl 7246: margin: 0 0 0 25px;
7247: line-height: 150%;
1.782 bisitz 7248: }
7249:
1.974 wenzelju 7250: .LC_hidden {
7251: display: none;
7252: }
7253:
1.1030 www 7254: .LCmodal-overlay {
7255: position:fixed;
7256: top:0;
7257: right:0;
7258: bottom:0;
7259: left:0;
7260: height:100%;
7261: width:100%;
7262: margin:0;
7263: padding:0;
7264: background:#999;
7265: opacity:.75;
7266: filter: alpha(opacity=75);
7267: -moz-opacity: 0.75;
7268: z-index:101;
7269: }
7270:
7271: * html .LCmodal-overlay {
7272: position: absolute;
7273: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7274: }
7275:
7276: .LCmodal-window {
7277: position:fixed;
7278: top:50%;
7279: left:50%;
7280: margin:0;
7281: padding:0;
7282: z-index:102;
7283: }
7284:
7285: * html .LCmodal-window {
7286: position:absolute;
7287: }
7288:
7289: .LCclose-window {
7290: position:absolute;
7291: width:32px;
7292: height:32px;
7293: right:8px;
7294: top:8px;
7295: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7296: text-indent:-99999px;
7297: overflow:hidden;
7298: cursor:pointer;
7299: }
7300:
1.1075.2.17 raeburn 7301: /*
7302: styles used by TTH when "Default set of options to pass to tth/m
7303: when converting TeX" in course settings has been set
7304:
7305: option passed: -t
7306:
7307: */
7308:
7309: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7310: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7311: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7312: td div.norm {line-height:normal;}
7313:
7314: /*
7315: option passed -y3
7316: */
7317:
7318: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7319: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7320: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7321:
1.343 albertel 7322: END
7323: }
7324:
1.306 albertel 7325: =pod
7326:
7327: =item * &headtag()
7328:
7329: Returns a uniform footer for LON-CAPA web pages.
7330:
1.307 albertel 7331: Inputs: $title - optional title for the head
7332: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7333: $args - optional arguments
1.319 albertel 7334: force_register - if is true call registerurl so the remote is
7335: informed
1.415 albertel 7336: redirect -> array ref of
7337: 1- seconds before redirect occurs
7338: 2- url to redirect to
7339: 3- whether the side effect should occur
1.315 albertel 7340: (side effect of setting
7341: $env{'internal.head.redirect'} to the url
7342: redirected too)
1.352 albertel 7343: domain -> force to color decorate a page for a specific
7344: domain
7345: function -> force usage of a specific rolish color scheme
7346: bgcolor -> override the default page bgcolor
1.460 albertel 7347: no_auto_mt_title
7348: -> prevent &mt()ing the title arg
1.464 albertel 7349:
1.306 albertel 7350: =cut
7351:
7352: sub headtag {
1.313 albertel 7353: my ($title,$head_extra,$args) = @_;
1.306 albertel 7354:
1.363 albertel 7355: my $function = $args->{'function'} || &get_users_function();
7356: my $domain = $args->{'domain'} || &determinedomain();
7357: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7358: my $httphost = $args->{'use_absolute'};
1.418 albertel 7359: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7360: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7361: #time(),
1.418 albertel 7362: $env{'environment.color.timestamp'},
1.363 albertel 7363: $function,$domain,$bgcolor);
7364:
1.369 www 7365: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7366:
1.308 albertel 7367: my $result =
7368: '<head>'.
1.1075.2.56 raeburn 7369: &font_settings($args);
1.319 albertel 7370:
1.1075.2.72 raeburn 7371: my $inhibitprint;
7372: if ($args->{'print_suppress'}) {
7373: $inhibitprint = &print_suppression();
7374: }
1.1064 raeburn 7375:
1.461 albertel 7376: if (!$args->{'frameset'}) {
7377: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7378: }
1.1075.2.12 raeburn 7379: if ($args->{'force_register'}) {
7380: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7381: }
1.436 albertel 7382: if (!$args->{'no_nav_bar'}
7383: && !$args->{'only_body'}
7384: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7385: $result .= &help_menu_js($httphost);
1.1032 www 7386: $result.=&modal_window();
1.1038 www 7387: $result.=&togglebox_script();
1.1034 www 7388: $result.=&wishlist_window();
1.1041 www 7389: $result.=&LCprogressbarUpdate_script();
1.1034 www 7390: } else {
7391: if ($args->{'add_modal'}) {
7392: $result.=&modal_window();
7393: }
7394: if ($args->{'add_wishlist'}) {
7395: $result.=&wishlist_window();
7396: }
1.1038 www 7397: if ($args->{'add_togglebox'}) {
7398: $result.=&togglebox_script();
7399: }
1.1041 www 7400: if ($args->{'add_progressbar'}) {
7401: $result.=&LCprogressbarUpdate_script();
7402: }
1.436 albertel 7403: }
1.314 albertel 7404: if (ref($args->{'redirect'})) {
1.414 albertel 7405: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7406: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7407: if (!$inhibit_continue) {
7408: $env{'internal.head.redirect'} = $url;
7409: }
1.313 albertel 7410: $result.=<<ADDMETA
7411: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7412: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7413: ADDMETA
1.1075.2.89! raeburn 7414: } else {
! 7415: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
! 7416: my $requrl = $env{'request.uri'};
! 7417: if ($requrl eq '') {
! 7418: $requrl = $ENV{'REQUEST_URI'};
! 7419: $requrl =~ s/\?.+$//;
! 7420: }
! 7421: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
! 7422: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
! 7423: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
! 7424: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
! 7425: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
! 7426: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
! 7427: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
! 7428: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
! 7429: if ($domdefs{'offloadnow'}{$lonhost}) {
! 7430: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
! 7431: if (($newserver) && ($newserver ne $lonhost)) {
! 7432: my $numsec = 5;
! 7433: my $timeout = $numsec * 1000;
! 7434: my ($newurl,$locknum,%locks,$msg);
! 7435: if ($env{'request.role.adv'}) {
! 7436: ($locknum,%locks) = &Apache::lonnet::get_locks();
! 7437: }
! 7438: my $disable_submit = 0;
! 7439: if ($requrl =~ /$LONCAPA::assess_re/) {
! 7440: $disable_submit = 1;
! 7441: }
! 7442: if ($locknum) {
! 7443: my @lockinfo = sort(values(%locks));
! 7444: $msg = &mt('Once the following tasks are complete: ')."\\n".
! 7445: join(", ",sort(values(%locks)))."\\n".
! 7446: &mt('your session will be transferred to a different server, after you click "Roles".');
! 7447: } else {
! 7448: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
! 7449: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
! 7450: }
! 7451: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
! 7452: $newurl = '/adm/switchserver?otherserver='.$newserver;
! 7453: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
! 7454: $newurl .= '&role='.$env{'request.role'};
! 7455: }
! 7456: if ($env{'request.symb'}) {
! 7457: $newurl .= '&symb='.$env{'request.symb'};
! 7458: } else {
! 7459: $newurl .= '&origurl='.$requrl;
! 7460: }
! 7461: }
! 7462: $result.=<<OFFLOAD
! 7463: <meta http-equiv="pragma" content="no-cache" />
! 7464: <script type="text/javascript">
! 7465: function LC_Offload_Now() {
! 7466: var dest = "$newurl";
! 7467: if (dest != '') {
! 7468: window.location.href="$newurl";
! 7469: }
! 7470: }
! 7471: window.alert('$msg');
! 7472: if ($disable_submit) {
! 7473: \$(document).ready(function () {
! 7474: \$(".LC_hwk_submit").prop("disabled", true);
! 7475: \$( ".LC_textline" ).prop( "readonly", "readonly");
! 7476: });
! 7477: }
! 7478: setTimeout('LC_Offload_Now()', $timeout);
! 7479: </script>
! 7480: OFFLOAD
! 7481: }
! 7482: }
! 7483: }
! 7484: }
! 7485: }
! 7486: }
1.313 albertel 7487: }
1.306 albertel 7488: if (!defined($title)) {
7489: $title = 'The LearningOnline Network with CAPA';
7490: }
1.460 albertel 7491: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7492: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7493: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7494: if (!$args->{'frameset'}) {
7495: $result .= ' /';
7496: }
7497: $result .= '>'
1.1064 raeburn 7498: .$inhibitprint
1.414 albertel 7499: .$head_extra;
1.1075.2.42 raeburn 7500: if ($env{'browser.mobile'}) {
7501: $result .= '
7502: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7503: <meta name="apple-mobile-web-app-capable" content="yes" />';
7504: }
1.962 droeschl 7505: return $result.'</head>';
1.306 albertel 7506: }
7507:
7508: =pod
7509:
1.340 albertel 7510: =item * &font_settings()
7511:
7512: Returns neccessary <meta> to set the proper encoding
7513:
1.1075.2.56 raeburn 7514: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7515:
7516: =cut
7517:
7518: sub font_settings {
1.1075.2.56 raeburn 7519: my ($args) = @_;
1.340 albertel 7520: my $headerstring='';
1.1075.2.56 raeburn 7521: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7522: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7523: $headerstring.=
1.1075.2.61 raeburn 7524: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7525: if (!$args->{'frameset'}) {
7526: $headerstring.= ' /';
7527: }
7528: $headerstring .= '>'."\n";
1.340 albertel 7529: }
7530: return $headerstring;
7531: }
7532:
1.341 albertel 7533: =pod
7534:
1.1064 raeburn 7535: =item * &print_suppression()
7536:
7537: In course context returns css which causes the body to be blank when media="print",
7538: if printout generation is unavailable for the current resource.
7539:
7540: This could be because:
7541:
7542: (a) printstartdate is in the future
7543:
7544: (b) printenddate is in the past
7545:
7546: (c) there is an active exam block with "printout"
7547: functionality blocked
7548:
7549: Users with pav, pfo or evb privileges are exempt.
7550:
7551: Inputs: none
7552:
7553: =cut
7554:
7555:
7556: sub print_suppression {
7557: my $noprint;
7558: if ($env{'request.course.id'}) {
7559: my $scope = $env{'request.course.id'};
7560: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7561: (&Apache::lonnet::allowed('pfo',$scope))) {
7562: return;
7563: }
7564: if ($env{'request.course.sec'} ne '') {
7565: $scope .= "/$env{'request.course.sec'}";
7566: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7567: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7568: return;
1.1064 raeburn 7569: }
7570: }
7571: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7572: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 7573: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 7574: if ($blocked) {
7575: my $checkrole = "cm./$cdom/$cnum";
7576: if ($env{'request.course.sec'} ne '') {
7577: $checkrole .= "/$env{'request.course.sec'}";
7578: }
7579: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7580: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7581: $noprint = 1;
7582: }
7583: }
7584: unless ($noprint) {
7585: my $symb = &Apache::lonnet::symbread();
7586: if ($symb ne '') {
7587: my $navmap = Apache::lonnavmaps::navmap->new();
7588: if (ref($navmap)) {
7589: my $res = $navmap->getBySymb($symb);
7590: if (ref($res)) {
7591: if (!$res->resprintable()) {
7592: $noprint = 1;
7593: }
7594: }
7595: }
7596: }
7597: }
7598: if ($noprint) {
7599: return <<"ENDSTYLE";
7600: <style type="text/css" media="print">
7601: body { display:none }
7602: </style>
7603: ENDSTYLE
7604: }
7605: }
7606: return;
7607: }
7608:
7609: =pod
7610:
1.341 albertel 7611: =item * &xml_begin()
7612:
7613: Returns the needed doctype and <html>
7614:
7615: Inputs: none
7616:
7617: =cut
7618:
7619: sub xml_begin {
1.1075.2.61 raeburn 7620: my ($is_frameset) = @_;
1.341 albertel 7621: my $output='';
7622:
7623: if ($env{'browser.mathml'}) {
7624: $output='<?xml version="1.0"?>'
7625: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7626: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7627:
7628: # .'<!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">] >'
7629: .'<!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">'
7630: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7631: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 7632: } elsif ($is_frameset) {
7633: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7634: '<html>'."\n";
1.341 albertel 7635: } else {
1.1075.2.61 raeburn 7636: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7637: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7638: }
7639: return $output;
7640: }
1.340 albertel 7641:
7642: =pod
7643:
1.306 albertel 7644: =item * &start_page()
7645:
7646: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7647:
1.648 raeburn 7648: Inputs:
7649:
7650: =over 4
7651:
7652: $title - optional title for the page
7653:
7654: $head_extra - optional extra HTML to incude inside the <head>
7655:
7656: $args - additional optional args supported are:
7657:
7658: =over 8
7659:
7660: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7661: arg on
1.814 bisitz 7662: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7663: add_entries -> additional attributes to add to the <body>
7664: domain -> force to color decorate a page for a
1.317 albertel 7665: specific domain
1.648 raeburn 7666: function -> force usage of a specific rolish color
1.317 albertel 7667: scheme
1.648 raeburn 7668: redirect -> see &headtag()
7669: bgcolor -> override the default page bg color
7670: js_ready -> return a string ready for being used in
1.317 albertel 7671: a javascript writeln
1.648 raeburn 7672: html_encode -> return a string ready for being used in
1.320 albertel 7673: a html attribute
1.648 raeburn 7674: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7675: $forcereg arg
1.648 raeburn 7676: frameset -> if true will start with a <frameset>
1.330 albertel 7677: rather than <body>
1.648 raeburn 7678: skip_phases -> hash ref of
1.338 albertel 7679: head -> skip the <html><head> generation
7680: body -> skip all <body> generation
1.1075.2.12 raeburn 7681: no_inline_link -> if true and in remote mode, don't show the
7682: 'Switch To Inline Menu' link
1.648 raeburn 7683: no_auto_mt_title -> prevent &mt()ing the title arg
7684: inherit_jsmath -> when creating popup window in a page,
7685: should it have jsmath forced on by the
7686: current page
1.867 kalberla 7687: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7688: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.15 raeburn 7689: group -> includes the current group, if page is for a
7690: specific group
1.361 albertel 7691:
1.648 raeburn 7692: =back
1.460 albertel 7693:
1.648 raeburn 7694: =back
1.562 albertel 7695:
1.306 albertel 7696: =cut
7697:
7698: sub start_page {
1.309 albertel 7699: my ($title,$head_extra,$args) = @_;
1.318 albertel 7700: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7701:
1.315 albertel 7702: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 7703: my ($result,@advtools);
1.964 droeschl 7704:
1.338 albertel 7705: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 7706: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 7707: }
7708:
7709: if (! exists($args->{'skip_phases'}{'body'}) ) {
7710: if ($args->{'frameset'}) {
7711: my $attr_string = &make_attr_string($args->{'force_register'},
7712: $args->{'add_entries'});
7713: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7714: } else {
7715: $result .=
7716: &bodytag($title,
7717: $args->{'function'}, $args->{'add_entries'},
7718: $args->{'only_body'}, $args->{'domain'},
7719: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 7720: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 7721: $args, \@advtools);
1.831 bisitz 7722: }
1.330 albertel 7723: }
1.338 albertel 7724:
1.315 albertel 7725: if ($args->{'js_ready'}) {
1.713 kaisler 7726: $result = &js_ready($result);
1.315 albertel 7727: }
1.320 albertel 7728: if ($args->{'html_encode'}) {
1.713 kaisler 7729: $result = &html_encode($result);
7730: }
7731:
1.813 bisitz 7732: # Preparation for new and consistent functionlist at top of screen
7733: # if ($args->{'functionlist'}) {
7734: # $result .= &build_functionlist();
7735: #}
7736:
1.964 droeschl 7737: # Don't add anything more if only_body wanted or in const space
7738: return $result if $args->{'only_body'}
7739: || $env{'request.state'} eq 'construct';
1.813 bisitz 7740:
7741: #Breadcrumbs
1.758 kaisler 7742: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7743: &Apache::lonhtmlcommon::clear_breadcrumbs();
7744: #if any br links exists, add them to the breadcrumbs
7745: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7746: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7747: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7748: }
7749: }
1.1075.2.19 raeburn 7750: # if @advtools array contains items add then to the breadcrumbs
7751: if (@advtools > 0) {
7752: &Apache::lonmenu::advtools_crumbs(@advtools);
7753: }
1.758 kaisler 7754:
7755: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7756: if(exists($args->{'bread_crumbs_component'})){
7757: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7758: }else{
7759: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7760: }
1.1075.2.24 raeburn 7761: } elsif (($env{'environment.remote'} eq 'on') &&
7762: ($env{'form.inhibitmenu'} ne 'yes') &&
7763: ($env{'request.noversionuri'} =~ m{^/res/}) &&
7764: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 7765: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 7766: }
1.315 albertel 7767: return $result;
1.306 albertel 7768: }
7769:
7770: sub end_page {
1.315 albertel 7771: my ($args) = @_;
7772: $env{'internal.end_page'}++;
1.330 albertel 7773: my $result;
1.335 albertel 7774: if ($args->{'discussion'}) {
7775: my ($target,$parser);
7776: if (ref($args->{'discussion'})) {
7777: ($target,$parser) =($args->{'discussion'}{'target'},
7778: $args->{'discussion'}{'parser'});
7779: }
7780: $result .= &Apache::lonxml::xmlend($target,$parser);
7781: }
1.330 albertel 7782: if ($args->{'frameset'}) {
7783: $result .= '</frameset>';
7784: } else {
1.635 raeburn 7785: $result .= &endbodytag($args);
1.330 albertel 7786: }
1.1075.2.6 raeburn 7787: unless ($args->{'notbody'}) {
7788: $result .= "\n</html>";
7789: }
1.330 albertel 7790:
1.315 albertel 7791: if ($args->{'js_ready'}) {
1.317 albertel 7792: $result = &js_ready($result);
1.315 albertel 7793: }
1.335 albertel 7794:
1.320 albertel 7795: if ($args->{'html_encode'}) {
7796: $result = &html_encode($result);
7797: }
1.335 albertel 7798:
1.315 albertel 7799: return $result;
7800: }
7801:
1.1034 www 7802: sub wishlist_window {
7803: return(<<'ENDWISHLIST');
1.1046 raeburn 7804: <script type="text/javascript">
1.1034 www 7805: // <![CDATA[
7806: // <!-- BEGIN LON-CAPA Internal
7807: function set_wishlistlink(title, path) {
7808: if (!title) {
7809: title = document.title;
7810: title = title.replace(/^LON-CAPA /,'');
7811: }
1.1075.2.65 raeburn 7812: title = encodeURIComponent(title);
1.1075.2.83 raeburn 7813: title = title.replace("'","\\\'");
1.1034 www 7814: if (!path) {
7815: path = location.pathname;
7816: }
1.1075.2.65 raeburn 7817: path = encodeURIComponent(path);
1.1075.2.83 raeburn 7818: path = path.replace("'","\\\'");
1.1034 www 7819: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7820: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7821: }
7822: // END LON-CAPA Internal -->
7823: // ]]>
7824: </script>
7825: ENDWISHLIST
7826: }
7827:
1.1030 www 7828: sub modal_window {
7829: return(<<'ENDMODAL');
1.1046 raeburn 7830: <script type="text/javascript">
1.1030 www 7831: // <![CDATA[
7832: // <!-- BEGIN LON-CAPA Internal
7833: var modalWindow = {
7834: parent:"body",
7835: windowId:null,
7836: content:null,
7837: width:null,
7838: height:null,
7839: close:function()
7840: {
7841: $(".LCmodal-window").remove();
7842: $(".LCmodal-overlay").remove();
7843: },
7844: open:function()
7845: {
7846: var modal = "";
7847: modal += "<div class=\"LCmodal-overlay\"></div>";
7848: 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;\">";
7849: modal += this.content;
7850: modal += "</div>";
7851:
7852: $(this.parent).append(modal);
7853:
7854: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7855: $(".LCclose-window").click(function(){modalWindow.close();});
7856: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7857: }
7858: };
1.1075.2.42 raeburn 7859: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7860: {
1.1075.2.83 raeburn 7861: source = source.replace("'","'");
1.1030 www 7862: modalWindow.windowId = "myModal";
7863: modalWindow.width = width;
7864: modalWindow.height = height;
1.1075.2.80 raeburn 7865: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7866: modalWindow.open();
1.1075.2.87 raeburn 7867: };
1.1030 www 7868: // END LON-CAPA Internal -->
7869: // ]]>
7870: </script>
7871: ENDMODAL
7872: }
7873:
7874: sub modal_link {
1.1075.2.42 raeburn 7875: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7876: unless ($width) { $width=480; }
7877: unless ($height) { $height=400; }
1.1031 www 7878: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 7879: unless ($transparency) { $transparency='true'; }
7880:
1.1074 raeburn 7881: my $target_attr;
7882: if (defined($target)) {
7883: $target_attr = 'target="'.$target.'"';
7884: }
7885: return <<"ENDLINK";
1.1075.2.42 raeburn 7886: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7887: $linktext</a>
7888: ENDLINK
1.1030 www 7889: }
7890:
1.1032 www 7891: sub modal_adhoc_script {
7892: my ($funcname,$width,$height,$content)=@_;
7893: return (<<ENDADHOC);
1.1046 raeburn 7894: <script type="text/javascript">
1.1032 www 7895: // <![CDATA[
7896: var $funcname = function()
7897: {
7898: modalWindow.windowId = "myModal";
7899: modalWindow.width = $width;
7900: modalWindow.height = $height;
7901: modalWindow.content = '$content';
7902: modalWindow.open();
7903: };
7904: // ]]>
7905: </script>
7906: ENDADHOC
7907: }
7908:
1.1041 www 7909: sub modal_adhoc_inner {
7910: my ($funcname,$width,$height,$content)=@_;
7911: my $innerwidth=$width-20;
7912: $content=&js_ready(
1.1042 www 7913: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 7914: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7915: $content.
1.1041 www 7916: &end_scrollbox().
1.1075.2.42 raeburn 7917: &end_page()
1.1041 www 7918: );
7919: return &modal_adhoc_script($funcname,$width,$height,$content);
7920: }
7921:
7922: sub modal_adhoc_window {
7923: my ($funcname,$width,$height,$content,$linktext)=@_;
7924: return &modal_adhoc_inner($funcname,$width,$height,$content).
7925: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7926: }
7927:
7928: sub modal_adhoc_launch {
7929: my ($funcname,$width,$height,$content)=@_;
7930: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7931: <script type="text/javascript">
7932: // <![CDATA[
7933: $funcname();
7934: // ]]>
7935: </script>
7936: ENDLAUNCH
7937: }
7938:
7939: sub modal_adhoc_close {
7940: return (<<ENDCLOSE);
7941: <script type="text/javascript">
7942: // <![CDATA[
7943: modalWindow.close();
7944: // ]]>
7945: </script>
7946: ENDCLOSE
7947: }
7948:
1.1038 www 7949: sub togglebox_script {
7950: return(<<ENDTOGGLE);
7951: <script type="text/javascript">
7952: // <![CDATA[
7953: function LCtoggleDisplay(id,hidetext,showtext) {
7954: link = document.getElementById(id + "link").childNodes[0];
7955: with (document.getElementById(id).style) {
7956: if (display == "none" ) {
7957: display = "inline";
7958: link.nodeValue = hidetext;
7959: } else {
7960: display = "none";
7961: link.nodeValue = showtext;
7962: }
7963: }
7964: }
7965: // ]]>
7966: </script>
7967: ENDTOGGLE
7968: }
7969:
1.1039 www 7970: sub start_togglebox {
7971: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7972: unless ($heading) { $heading=''; } else { $heading.=' '; }
7973: unless ($showtext) { $showtext=&mt('show'); }
7974: unless ($hidetext) { $hidetext=&mt('hide'); }
7975: unless ($headerbg) { $headerbg='#FFFFFF'; }
7976: return &start_data_table().
7977: &start_data_table_header_row().
7978: '<td bgcolor="'.$headerbg.'">'.$heading.
7979: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7980: $showtext.'\')">'.$showtext.'</a>]</td>'.
7981: &end_data_table_header_row().
7982: '<tr id="'.$id.'" style="display:none""><td>';
7983: }
7984:
7985: sub end_togglebox {
7986: return '</td></tr>'.&end_data_table();
7987: }
7988:
1.1041 www 7989: sub LCprogressbar_script {
1.1045 www 7990: my ($id)=@_;
1.1041 www 7991: return(<<ENDPROGRESS);
7992: <script type="text/javascript">
7993: // <![CDATA[
1.1045 www 7994: \$('#progressbar$id').progressbar({
1.1041 www 7995: value: 0,
7996: change: function(event, ui) {
7997: var newVal = \$(this).progressbar('option', 'value');
7998: \$('.pblabel', this).text(LCprogressTxt);
7999: }
8000: });
8001: // ]]>
8002: </script>
8003: ENDPROGRESS
8004: }
8005:
8006: sub LCprogressbarUpdate_script {
8007: return(<<ENDPROGRESSUPDATE);
8008: <style type="text/css">
8009: .ui-progressbar { position:relative; }
8010: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8011: </style>
8012: <script type="text/javascript">
8013: // <![CDATA[
1.1045 www 8014: var LCprogressTxt='---';
8015:
8016: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8017: LCprogressTxt=progresstext;
1.1045 www 8018: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8019: }
8020: // ]]>
8021: </script>
8022: ENDPROGRESSUPDATE
8023: }
8024:
1.1042 www 8025: my $LClastpercent;
1.1045 www 8026: my $LCidcnt;
8027: my $LCcurrentid;
1.1042 www 8028:
1.1041 www 8029: sub LCprogressbar {
1.1042 www 8030: my ($r)=(@_);
8031: $LClastpercent=0;
1.1045 www 8032: $LCidcnt++;
8033: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8034: my $starting=&mt('Starting');
8035: my $content=(<<ENDPROGBAR);
1.1045 www 8036: <div id="progressbar$LCcurrentid">
1.1041 www 8037: <span class="pblabel">$starting</span>
8038: </div>
8039: ENDPROGBAR
1.1045 www 8040: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8041: }
8042:
8043: sub LCprogressbarUpdate {
1.1042 www 8044: my ($r,$val,$text)=@_;
8045: unless ($val) {
8046: if ($LClastpercent) {
8047: $val=$LClastpercent;
8048: } else {
8049: $val=0;
8050: }
8051: }
1.1041 www 8052: if ($val<0) { $val=0; }
8053: if ($val>100) { $val=0; }
1.1042 www 8054: $LClastpercent=$val;
1.1041 www 8055: unless ($text) { $text=$val.'%'; }
8056: $text=&js_ready($text);
1.1044 www 8057: &r_print($r,<<ENDUPDATE);
1.1041 www 8058: <script type="text/javascript">
8059: // <![CDATA[
1.1045 www 8060: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8061: // ]]>
8062: </script>
8063: ENDUPDATE
1.1035 www 8064: }
8065:
1.1042 www 8066: sub LCprogressbarClose {
8067: my ($r)=@_;
8068: $LClastpercent=0;
1.1044 www 8069: &r_print($r,<<ENDCLOSE);
1.1042 www 8070: <script type="text/javascript">
8071: // <![CDATA[
1.1045 www 8072: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8073: // ]]>
8074: </script>
8075: ENDCLOSE
1.1044 www 8076: }
8077:
8078: sub r_print {
8079: my ($r,$to_print)=@_;
8080: if ($r) {
8081: $r->print($to_print);
8082: $r->rflush();
8083: } else {
8084: print($to_print);
8085: }
1.1042 www 8086: }
8087:
1.320 albertel 8088: sub html_encode {
8089: my ($result) = @_;
8090:
1.322 albertel 8091: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8092:
8093: return $result;
8094: }
1.1044 www 8095:
1.317 albertel 8096: sub js_ready {
8097: my ($result) = @_;
8098:
1.323 albertel 8099: $result =~ s/[\n\r]/ /xmsg;
8100: $result =~ s/\\/\\\\/xmsg;
8101: $result =~ s/'/\\'/xmsg;
1.372 albertel 8102: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8103:
8104: return $result;
8105: }
8106:
1.315 albertel 8107: sub validate_page {
8108: if ( exists($env{'internal.start_page'})
1.316 albertel 8109: && $env{'internal.start_page'} > 1) {
8110: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8111: $env{'internal.start_page'}.' '.
1.316 albertel 8112: $ENV{'request.filename'});
1.315 albertel 8113: }
8114: if ( exists($env{'internal.end_page'})
1.316 albertel 8115: && $env{'internal.end_page'} > 1) {
8116: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8117: $env{'internal.end_page'}.' '.
1.316 albertel 8118: $env{'request.filename'});
1.315 albertel 8119: }
8120: if ( exists($env{'internal.start_page'})
8121: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8122: &Apache::lonnet::logthis('start_page called without end_page '.
8123: $env{'request.filename'});
1.315 albertel 8124: }
8125: if ( ! exists($env{'internal.start_page'})
8126: && exists($env{'internal.end_page'})) {
1.316 albertel 8127: &Apache::lonnet::logthis('end_page called without start_page'.
8128: $env{'request.filename'});
1.315 albertel 8129: }
1.306 albertel 8130: }
1.315 albertel 8131:
1.996 www 8132:
8133: sub start_scrollbox {
1.1075.2.56 raeburn 8134: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8135: unless ($outerwidth) { $outerwidth='520px'; }
8136: unless ($width) { $width='500px'; }
8137: unless ($height) { $height='200px'; }
1.1075 raeburn 8138: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8139: if ($id ne '') {
1.1075.2.42 raeburn 8140: $table_id = ' id="table_'.$id.'"';
8141: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8142: }
1.1075 raeburn 8143: if ($bgcolor ne '') {
8144: $tdcol = "background-color: $bgcolor;";
8145: }
1.1075.2.42 raeburn 8146: my $nicescroll_js;
8147: if ($env{'browser.mobile'}) {
8148: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8149: }
1.1075 raeburn 8150: return <<"END";
1.1075.2.42 raeburn 8151: $nicescroll_js
8152:
8153: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8154: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8155: END
1.996 www 8156: }
8157:
8158: sub end_scrollbox {
1.1036 www 8159: return '</div></td></tr></table>';
1.996 www 8160: }
8161:
1.1075.2.42 raeburn 8162: sub nicescroll_javascript {
8163: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8164: my %options;
8165: if (ref($cursor) eq 'HASH') {
8166: %options = %{$cursor};
8167: }
8168: unless ($options{'railalign'} =~ /^left|right$/) {
8169: $options{'railalign'} = 'left';
8170: }
8171: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8172: my $function = &get_users_function();
8173: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8174: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8175: $options{'cursorcolor'} = '#00F';
8176: }
8177: }
8178: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8179: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8180: $options{'cursoropacity'}='1.0';
8181: }
8182: } else {
8183: $options{'cursoropacity'}='1.0';
8184: }
8185: if ($options{'cursorfixedheight'} eq 'none') {
8186: delete($options{'cursorfixedheight'});
8187: } else {
8188: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8189: }
8190: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8191: delete($options{'railoffset'});
8192: }
8193: my @niceoptions;
8194: while (my($key,$value) = each(%options)) {
8195: if ($value =~ /^\{.+\}$/) {
8196: push(@niceoptions,$key.':'.$value);
8197: } else {
8198: push(@niceoptions,$key.':"'.$value.'"');
8199: }
8200: }
8201: my $nicescroll_js = '
8202: $(document).ready(
8203: function() {
8204: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8205: }
8206: );
8207: ';
8208: if ($framecheck) {
8209: $nicescroll_js .= '
8210: function expand_div(caller) {
8211: if (top === self) {
8212: document.getElementById("'.$id.'").style.width = "auto";
8213: document.getElementById("'.$id.'").style.height = "auto";
8214: } else {
8215: try {
8216: if (parent.frames) {
8217: if (parent.frames.length > 1) {
8218: var framesrc = parent.frames[1].location.href;
8219: var currsrc = framesrc.replace(/\#.*$/,"");
8220: if ((caller == "search") || (currsrc == "'.$location.'")) {
8221: document.getElementById("'.$id.'").style.width = "auto";
8222: document.getElementById("'.$id.'").style.height = "auto";
8223: }
8224: }
8225: }
8226: } catch (e) {
8227: return;
8228: }
8229: }
8230: return;
8231: }
8232: ';
8233: }
8234: if ($needjsready) {
8235: $nicescroll_js = '
8236: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8237: } else {
8238: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8239: }
8240: return $nicescroll_js;
8241: }
8242:
1.318 albertel 8243: sub simple_error_page {
1.1075.2.49 raeburn 8244: my ($r,$title,$msg,$args) = @_;
8245: if (ref($args) eq 'HASH') {
8246: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8247: } else {
8248: $msg = &mt($msg);
8249: }
8250:
1.318 albertel 8251: my $page =
8252: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8253: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8254: &Apache::loncommon::end_page();
8255: if (ref($r)) {
8256: $r->print($page);
1.327 albertel 8257: return;
1.318 albertel 8258: }
8259: return $page;
8260: }
1.347 albertel 8261:
8262: {
1.610 albertel 8263: my @row_count;
1.961 onken 8264:
8265: sub start_data_table_count {
8266: unshift(@row_count, 0);
8267: return;
8268: }
8269:
8270: sub end_data_table_count {
8271: shift(@row_count);
8272: return;
8273: }
8274:
1.347 albertel 8275: sub start_data_table {
1.1018 raeburn 8276: my ($add_class,$id) = @_;
1.422 albertel 8277: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8278: my $table_id;
8279: if (defined($id)) {
8280: $table_id = ' id="'.$id.'"';
8281: }
1.961 onken 8282: &start_data_table_count();
1.1018 raeburn 8283: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8284: }
8285:
8286: sub end_data_table {
1.961 onken 8287: &end_data_table_count();
1.389 albertel 8288: return '</table>'."\n";;
1.347 albertel 8289: }
8290:
8291: sub start_data_table_row {
1.974 wenzelju 8292: my ($add_class, $id) = @_;
1.610 albertel 8293: $row_count[0]++;
8294: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8295: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8296: $id = (' id="'.$id.'"') unless ($id eq '');
8297: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8298: }
1.471 banghart 8299:
8300: sub continue_data_table_row {
1.974 wenzelju 8301: my ($add_class, $id) = @_;
1.610 albertel 8302: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8303: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8304: $id = (' id="'.$id.'"') unless ($id eq '');
8305: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8306: }
1.347 albertel 8307:
8308: sub end_data_table_row {
1.389 albertel 8309: return '</tr>'."\n";;
1.347 albertel 8310: }
1.367 www 8311:
1.421 albertel 8312: sub start_data_table_empty_row {
1.707 bisitz 8313: # $row_count[0]++;
1.421 albertel 8314: return '<tr class="LC_empty_row" >'."\n";;
8315: }
8316:
8317: sub end_data_table_empty_row {
8318: return '</tr>'."\n";;
8319: }
8320:
1.367 www 8321: sub start_data_table_header_row {
1.389 albertel 8322: return '<tr class="LC_header_row">'."\n";;
1.367 www 8323: }
8324:
8325: sub end_data_table_header_row {
1.389 albertel 8326: return '</tr>'."\n";;
1.367 www 8327: }
1.890 droeschl 8328:
8329: sub data_table_caption {
8330: my $caption = shift;
8331: return "<caption class=\"LC_caption\">$caption</caption>";
8332: }
1.347 albertel 8333: }
8334:
1.548 albertel 8335: =pod
8336:
8337: =item * &inhibit_menu_check($arg)
8338:
8339: Checks for a inhibitmenu state and generates output to preserve it
8340:
8341: Inputs: $arg - can be any of
8342: - undef - in which case the return value is a string
8343: to add into arguments list of a uri
8344: - 'input' - in which case the return value is a HTML
8345: <form> <input> field of type hidden to
8346: preserve the value
8347: - a url - in which case the return value is the url with
8348: the neccesary cgi args added to preserve the
8349: inhibitmenu state
8350: - a ref to a url - no return value, but the string is
8351: updated to include the neccessary cgi
8352: args to preserve the inhibitmenu state
8353:
8354: =cut
8355:
8356: sub inhibit_menu_check {
8357: my ($arg) = @_;
8358: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8359: if ($arg eq 'input') {
8360: if ($env{'form.inhibitmenu'}) {
8361: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8362: } else {
8363: return
8364: }
8365: }
8366: if ($env{'form.inhibitmenu'}) {
8367: if (ref($arg)) {
8368: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8369: } elsif ($arg eq '') {
8370: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8371: } else {
8372: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8373: }
8374: }
8375: if (!ref($arg)) {
8376: return $arg;
8377: }
8378: }
8379:
1.251 albertel 8380: ###############################################
1.182 matthew 8381:
8382: =pod
8383:
1.549 albertel 8384: =back
8385:
8386: =head1 User Information Routines
8387:
8388: =over 4
8389:
1.405 albertel 8390: =item * &get_users_function()
1.182 matthew 8391:
8392: Used by &bodytag to determine the current users primary role.
8393: Returns either 'student','coordinator','admin', or 'author'.
8394:
8395: =cut
8396:
8397: ###############################################
8398: sub get_users_function {
1.815 tempelho 8399: my $function = 'norole';
1.818 tempelho 8400: if ($env{'request.role'}=~/^(st)/) {
8401: $function='student';
8402: }
1.907 raeburn 8403: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8404: $function='coordinator';
8405: }
1.258 albertel 8406: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8407: $function='admin';
8408: }
1.826 bisitz 8409: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8410: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8411: $function='author';
8412: }
8413: return $function;
1.54 www 8414: }
1.99 www 8415:
8416: ###############################################
8417:
1.233 raeburn 8418: =pod
8419:
1.821 raeburn 8420: =item * &show_course()
8421:
8422: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8423: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8424:
8425: Inputs:
8426: None
8427:
8428: Outputs:
8429: Scalar: 1 if 'Course' to be used, 0 otherwise.
8430:
8431: =cut
8432:
8433: ###############################################
8434: sub show_course {
8435: my $course = !$env{'user.adv'};
8436: if (!$env{'user.adv'}) {
8437: foreach my $env (keys(%env)) {
8438: next if ($env !~ m/^user\.priv\./);
8439: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8440: $course = 0;
8441: last;
8442: }
8443: }
8444: }
8445: return $course;
8446: }
8447:
8448: ###############################################
8449:
8450: =pod
8451:
1.542 raeburn 8452: =item * &check_user_status()
1.274 raeburn 8453:
8454: Determines current status of supplied role for a
8455: specific user. Roles can be active, previous or future.
8456:
8457: Inputs:
8458: user's domain, user's username, course's domain,
1.375 raeburn 8459: course's number, optional section ID.
1.274 raeburn 8460:
8461: Outputs:
8462: role status: active, previous or future.
8463:
8464: =cut
8465:
8466: sub check_user_status {
1.412 raeburn 8467: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8468: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 8469: my @uroles = keys(%userinfo);
1.274 raeburn 8470: my $srchstr;
8471: my $active_chk = 'none';
1.412 raeburn 8472: my $now = time;
1.274 raeburn 8473: if (@uroles > 0) {
1.908 raeburn 8474: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8475: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8476: } else {
1.412 raeburn 8477: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8478: }
8479: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8480: my $role_end = 0;
8481: my $role_start = 0;
8482: $active_chk = 'active';
1.412 raeburn 8483: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8484: $role_end = $1;
8485: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8486: $role_start = $1;
1.274 raeburn 8487: }
8488: }
8489: if ($role_start > 0) {
1.412 raeburn 8490: if ($now < $role_start) {
1.274 raeburn 8491: $active_chk = 'future';
8492: }
8493: }
8494: if ($role_end > 0) {
1.412 raeburn 8495: if ($now > $role_end) {
1.274 raeburn 8496: $active_chk = 'previous';
8497: }
8498: }
8499: }
8500: }
8501: return $active_chk;
8502: }
8503:
8504: ###############################################
8505:
8506: =pod
8507:
1.405 albertel 8508: =item * &get_sections()
1.233 raeburn 8509:
8510: Determines all the sections for a course including
8511: sections with students and sections containing other roles.
1.419 raeburn 8512: Incoming parameters:
8513:
8514: 1. domain
8515: 2. course number
8516: 3. reference to array containing roles for which sections should
8517: be gathered (optional).
8518: 4. reference to array containing status types for which sections
8519: should be gathered (optional).
8520:
8521: If the third argument is undefined, sections are gathered for any role.
8522: If the fourth argument is undefined, sections are gathered for any status.
8523: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8524:
1.374 raeburn 8525: Returns section hash (keys are section IDs, values are
8526: number of users in each section), subject to the
1.419 raeburn 8527: optional roles filter, optional status filter
1.233 raeburn 8528:
8529: =cut
8530:
8531: ###############################################
8532: sub get_sections {
1.419 raeburn 8533: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8534: if (!defined($cdom) || !defined($cnum)) {
8535: my $cid = $env{'request.course.id'};
8536:
8537: return if (!defined($cid));
8538:
8539: $cdom = $env{'course.'.$cid.'.domain'};
8540: $cnum = $env{'course.'.$cid.'.num'};
8541: }
8542:
8543: my %sectioncount;
1.419 raeburn 8544: my $now = time;
1.240 albertel 8545:
1.1075.2.33 raeburn 8546: my $check_students = 1;
8547: my $only_students = 0;
8548: if (ref($possible_roles) eq 'ARRAY') {
8549: if (grep(/^st$/,@{$possible_roles})) {
8550: if (@{$possible_roles} == 1) {
8551: $only_students = 1;
8552: }
8553: } else {
8554: $check_students = 0;
8555: }
8556: }
8557:
8558: if ($check_students) {
1.276 albertel 8559: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8560: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8561: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8562: my $start_index = &Apache::loncoursedata::CL_START();
8563: my $end_index = &Apache::loncoursedata::CL_END();
8564: my $status;
1.366 albertel 8565: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8566: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8567: $data->[$status_index],
8568: $data->[$start_index],
8569: $data->[$end_index]);
8570: if ($stu_status eq 'Active') {
8571: $status = 'active';
8572: } elsif ($end < $now) {
8573: $status = 'previous';
8574: } elsif ($start > $now) {
8575: $status = 'future';
8576: }
8577: if ($section ne '-1' && $section !~ /^\s*$/) {
8578: if ((!defined($possible_status)) || (($status ne '') &&
8579: (grep/^\Q$status\E$/,@{$possible_status}))) {
8580: $sectioncount{$section}++;
8581: }
1.240 albertel 8582: }
8583: }
8584: }
1.1075.2.33 raeburn 8585: if ($only_students) {
8586: return %sectioncount;
8587: }
1.240 albertel 8588: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8589: foreach my $user (sort(keys(%courseroles))) {
8590: if ($user !~ /^(\w{2})/) { next; }
8591: my ($role) = ($user =~ /^(\w{2})/);
8592: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8593: my ($section,$status);
1.240 albertel 8594: if ($role eq 'cr' &&
8595: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8596: $section=$1;
8597: }
8598: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8599: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8600: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8601: if ($end == -1 && $start == -1) {
8602: next; #deleted role
8603: }
8604: if (!defined($possible_status)) {
8605: $sectioncount{$section}++;
8606: } else {
8607: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8608: $status = 'active';
8609: } elsif ($end < $now) {
8610: $status = 'future';
8611: } elsif ($start > $now) {
8612: $status = 'previous';
8613: }
8614: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8615: $sectioncount{$section}++;
8616: }
8617: }
1.233 raeburn 8618: }
1.366 albertel 8619: return %sectioncount;
1.233 raeburn 8620: }
8621:
1.274 raeburn 8622: ###############################################
1.294 raeburn 8623:
8624: =pod
1.405 albertel 8625:
8626: =item * &get_course_users()
8627:
1.275 raeburn 8628: Retrieves usernames:domains for users in the specified course
8629: with specific role(s), and access status.
8630:
8631: Incoming parameters:
1.277 albertel 8632: 1. course domain
8633: 2. course number
8634: 3. access status: users must have - either active,
1.275 raeburn 8635: previous, future, or all.
1.277 albertel 8636: 4. reference to array of permissible roles
1.288 raeburn 8637: 5. reference to array of section restrictions (optional)
8638: 6. reference to results object (hash of hashes).
8639: 7. reference to optional userdata hash
1.609 raeburn 8640: 8. reference to optional statushash
1.630 raeburn 8641: 9. flag if privileged users (except those set to unhide in
8642: course settings) should be excluded
1.609 raeburn 8643: Keys of top level results hash are roles.
1.275 raeburn 8644: Keys of inner hashes are username:domain, with
8645: values set to access type.
1.288 raeburn 8646: Optional userdata hash returns an array with arguments in the
8647: same order as loncoursedata::get_classlist() for student data.
8648:
1.609 raeburn 8649: Optional statushash returns
8650:
1.288 raeburn 8651: Entries for end, start, section and status are blank because
8652: of the possibility of multiple values for non-student roles.
8653:
1.275 raeburn 8654: =cut
1.405 albertel 8655:
1.275 raeburn 8656: ###############################################
1.405 albertel 8657:
1.275 raeburn 8658: sub get_course_users {
1.630 raeburn 8659: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8660: my %idx = ();
1.419 raeburn 8661: my %seclists;
1.288 raeburn 8662:
8663: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8664: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8665: $idx{end} = &Apache::loncoursedata::CL_END();
8666: $idx{start} = &Apache::loncoursedata::CL_START();
8667: $idx{id} = &Apache::loncoursedata::CL_ID();
8668: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8669: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8670: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8671:
1.290 albertel 8672: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8673: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8674: my $now = time;
1.277 albertel 8675: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8676: my $match = 0;
1.412 raeburn 8677: my $secmatch = 0;
1.419 raeburn 8678: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8679: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8680: if ($section eq '') {
8681: $section = 'none';
8682: }
1.291 albertel 8683: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8684: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8685: $secmatch = 1;
8686: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8687: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8688: $secmatch = 1;
8689: }
8690: } else {
1.419 raeburn 8691: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8692: $secmatch = 1;
8693: }
1.290 albertel 8694: }
1.412 raeburn 8695: if (!$secmatch) {
8696: next;
8697: }
1.419 raeburn 8698: }
1.275 raeburn 8699: if (defined($$types{'active'})) {
1.288 raeburn 8700: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8701: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8702: $match = 1;
1.275 raeburn 8703: }
8704: }
8705: if (defined($$types{'previous'})) {
1.609 raeburn 8706: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8707: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8708: $match = 1;
1.275 raeburn 8709: }
8710: }
8711: if (defined($$types{'future'})) {
1.609 raeburn 8712: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8713: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8714: $match = 1;
1.275 raeburn 8715: }
8716: }
1.609 raeburn 8717: if ($match) {
8718: push(@{$seclists{$student}},$section);
8719: if (ref($userdata) eq 'HASH') {
8720: $$userdata{$student} = $$classlist{$student};
8721: }
8722: if (ref($statushash) eq 'HASH') {
8723: $statushash->{$student}{'st'}{$section} = $status;
8724: }
1.288 raeburn 8725: }
1.275 raeburn 8726: }
8727: }
1.412 raeburn 8728: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8729: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8730: my $now = time;
1.609 raeburn 8731: my %displaystatus = ( previous => 'Expired',
8732: active => 'Active',
8733: future => 'Future',
8734: );
1.1075.2.36 raeburn 8735: my (%nothide,@possdoms);
1.630 raeburn 8736: if ($hidepriv) {
8737: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8738: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8739: if ($user !~ /:/) {
8740: $nothide{join(':',split(/[\@]/,$user))}=1;
8741: } else {
8742: $nothide{$user} = 1;
8743: }
8744: }
1.1075.2.36 raeburn 8745: my @possdoms = ($cdom);
8746: if ($coursehash{'checkforpriv'}) {
8747: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8748: }
1.630 raeburn 8749: }
1.439 raeburn 8750: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8751: my $match = 0;
1.412 raeburn 8752: my $secmatch = 0;
1.439 raeburn 8753: my $status;
1.412 raeburn 8754: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8755: $user =~ s/:$//;
1.439 raeburn 8756: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8757: if ($end == -1 || $start == -1) {
8758: next;
8759: }
8760: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8761: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8762: my ($uname,$udom) = split(/:/,$user);
8763: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8764: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8765: $secmatch = 1;
8766: } elsif ($usec eq '') {
1.420 albertel 8767: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8768: $secmatch = 1;
8769: }
8770: } else {
8771: if (grep(/^\Q$usec\E$/,@{$sections})) {
8772: $secmatch = 1;
8773: }
8774: }
8775: if (!$secmatch) {
8776: next;
8777: }
1.288 raeburn 8778: }
1.419 raeburn 8779: if ($usec eq '') {
8780: $usec = 'none';
8781: }
1.275 raeburn 8782: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8783: if ($hidepriv) {
1.1075.2.36 raeburn 8784: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8785: (!$nothide{$uname.':'.$udom})) {
8786: next;
8787: }
8788: }
1.503 raeburn 8789: if ($end > 0 && $end < $now) {
1.439 raeburn 8790: $status = 'previous';
8791: } elsif ($start > $now) {
8792: $status = 'future';
8793: } else {
8794: $status = 'active';
8795: }
1.277 albertel 8796: foreach my $type (keys(%{$types})) {
1.275 raeburn 8797: if ($status eq $type) {
1.420 albertel 8798: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8799: push(@{$$users{$role}{$user}},$type);
8800: }
1.288 raeburn 8801: $match = 1;
8802: }
8803: }
1.419 raeburn 8804: if (($match) && (ref($userdata) eq 'HASH')) {
8805: if (!exists($$userdata{$uname.':'.$udom})) {
8806: &get_user_info($udom,$uname,\%idx,$userdata);
8807: }
1.420 albertel 8808: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8809: push(@{$seclists{$uname.':'.$udom}},$usec);
8810: }
1.609 raeburn 8811: if (ref($statushash) eq 'HASH') {
8812: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8813: }
1.275 raeburn 8814: }
8815: }
8816: }
8817: }
1.290 albertel 8818: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8819: if ((defined($cdom)) && (defined($cnum))) {
8820: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8821: if ( defined($csettings{'internal.courseowner'}) ) {
8822: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8823: next if ($owner eq '');
8824: my ($ownername,$ownerdom);
8825: if ($owner =~ /^([^:]+):([^:]+)$/) {
8826: $ownername = $1;
8827: $ownerdom = $2;
8828: } else {
8829: $ownername = $owner;
8830: $ownerdom = $cdom;
8831: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8832: }
8833: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8834: if (defined($userdata) &&
1.609 raeburn 8835: !exists($$userdata{$owner})) {
8836: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8837: if (!grep(/^none$/,@{$seclists{$owner}})) {
8838: push(@{$seclists{$owner}},'none');
8839: }
8840: if (ref($statushash) eq 'HASH') {
8841: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8842: }
1.290 albertel 8843: }
1.279 raeburn 8844: }
8845: }
8846: }
1.419 raeburn 8847: foreach my $user (keys(%seclists)) {
8848: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8849: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8850: }
1.275 raeburn 8851: }
8852: return;
8853: }
8854:
1.288 raeburn 8855: sub get_user_info {
8856: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8857: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8858: &plainname($uname,$udom,'lastname');
1.291 albertel 8859: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8860: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8861: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8862: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8863: return;
8864: }
1.275 raeburn 8865:
1.472 raeburn 8866: ###############################################
8867:
8868: =pod
8869:
8870: =item * &get_user_quota()
8871:
1.1075.2.41 raeburn 8872: Retrieves quota assigned for storage of user files.
8873: Default is to report quota for portfolio files.
1.472 raeburn 8874:
8875: Incoming parameters:
8876: 1. user's username
8877: 2. user's domain
1.1075.2.41 raeburn 8878: 3. quota name - portfolio, author, or course
8879: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 8880: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 8881: course
1.472 raeburn 8882:
8883: Returns:
1.1075.2.58 raeburn 8884: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 8885: 2. (Optional) Type of setting: custom or default
8886: (individually assigned or default for user's
8887: institutional status).
8888: 3. (Optional) - User's institutional status (e.g., faculty, staff
8889: or student - types as defined in localenroll::inst_usertypes
8890: for user's domain, which determines default quota for user.
8891: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8892:
8893: If a value has been stored in the user's environment,
1.536 raeburn 8894: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 8895: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8896:
8897: =cut
8898:
8899: ###############################################
8900:
8901:
8902: sub get_user_quota {
1.1075.2.42 raeburn 8903: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8904: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8905: if (!defined($udom)) {
8906: $udom = $env{'user.domain'};
8907: }
8908: if (!defined($uname)) {
8909: $uname = $env{'user.name'};
8910: }
8911: if (($udom eq '' || $uname eq '') ||
8912: ($udom eq 'public') && ($uname eq 'public')) {
8913: $quota = 0;
1.536 raeburn 8914: $quotatype = 'default';
8915: $defquota = 0;
1.472 raeburn 8916: } else {
1.536 raeburn 8917: my $inststatus;
1.1075.2.41 raeburn 8918: if ($quotaname eq 'course') {
8919: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8920: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8921: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8922: } else {
8923: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8924: $quota = $cenv{'internal.uploadquota'};
8925: }
1.536 raeburn 8926: } else {
1.1075.2.41 raeburn 8927: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8928: if ($quotaname eq 'author') {
8929: $quota = $env{'environment.authorquota'};
8930: } else {
8931: $quota = $env{'environment.portfolioquota'};
8932: }
8933: $inststatus = $env{'environment.inststatus'};
8934: } else {
8935: my %userenv =
8936: &Apache::lonnet::get('environment',['portfolioquota',
8937: 'authorquota','inststatus'],$udom,$uname);
8938: my ($tmp) = keys(%userenv);
8939: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8940: if ($quotaname eq 'author') {
8941: $quota = $userenv{'authorquota'};
8942: } else {
8943: $quota = $userenv{'portfolioquota'};
8944: }
8945: $inststatus = $userenv{'inststatus'};
8946: } else {
8947: undef(%userenv);
8948: }
8949: }
8950: }
8951: if ($quota eq '' || wantarray) {
8952: if ($quotaname eq 'course') {
8953: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 8954: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
8955: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 8956: $defquota = $domdefs{$crstype.'quota'};
8957: }
8958: if ($defquota eq '') {
8959: $defquota = 500;
8960: }
1.1075.2.41 raeburn 8961: } else {
8962: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8963: }
8964: if ($quota eq '') {
8965: $quota = $defquota;
8966: $quotatype = 'default';
8967: } else {
8968: $quotatype = 'custom';
8969: }
1.472 raeburn 8970: }
8971: }
1.536 raeburn 8972: if (wantarray) {
8973: return ($quota,$quotatype,$settingstatus,$defquota);
8974: } else {
8975: return $quota;
8976: }
1.472 raeburn 8977: }
8978:
8979: ###############################################
8980:
8981: =pod
8982:
8983: =item * &default_quota()
8984:
1.536 raeburn 8985: Retrieves default quota assigned for storage of user portfolio files,
8986: given an (optional) user's institutional status.
1.472 raeburn 8987:
8988: Incoming parameters:
1.1075.2.42 raeburn 8989:
1.472 raeburn 8990: 1. domain
1.536 raeburn 8991: 2. (Optional) institutional status(es). This is a : separated list of
8992: status types (e.g., faculty, staff, student etc.)
8993: which apply to the user for whom the default is being retrieved.
8994: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 8995: default quota will be returned.
8996: 3. quota name - portfolio, author, or course
8997: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8998:
8999: Returns:
1.1075.2.42 raeburn 9000:
1.1075.2.58 raeburn 9001: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9002: 2. (Optional) institutional type which determined the value of the
9003: default quota.
1.472 raeburn 9004:
9005: If a value has been stored in the domain's configuration db,
9006: it will return that, otherwise it returns 20 (for backwards
9007: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9008: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9009:
1.536 raeburn 9010: If the user's status includes multiple types (e.g., staff and student),
9011: the largest default quota which applies to the user determines the
9012: default quota returned.
9013:
1.472 raeburn 9014: =cut
9015:
9016: ###############################################
9017:
9018:
9019: sub default_quota {
1.1075.2.41 raeburn 9020: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9021: my ($defquota,$settingstatus);
9022: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9023: ['quotas'],$udom);
1.1075.2.41 raeburn 9024: my $key = 'defaultquota';
9025: if ($quotaname eq 'author') {
9026: $key = 'authorquota';
9027: }
1.622 raeburn 9028: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9029: if ($inststatus ne '') {
1.765 raeburn 9030: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9031: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9032: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9033: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9034: if ($defquota eq '') {
1.1075.2.41 raeburn 9035: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9036: $settingstatus = $item;
1.1075.2.41 raeburn 9037: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9038: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9039: $settingstatus = $item;
9040: }
9041: }
1.1075.2.41 raeburn 9042: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9043: if ($quotahash{'quotas'}{$item} ne '') {
9044: if ($defquota eq '') {
9045: $defquota = $quotahash{'quotas'}{$item};
9046: $settingstatus = $item;
9047: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9048: $defquota = $quotahash{'quotas'}{$item};
9049: $settingstatus = $item;
9050: }
1.536 raeburn 9051: }
9052: }
9053: }
9054: }
9055: if ($defquota eq '') {
1.1075.2.41 raeburn 9056: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9057: $defquota = $quotahash{'quotas'}{$key}{'default'};
9058: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9059: $defquota = $quotahash{'quotas'}{'default'};
9060: }
1.536 raeburn 9061: $settingstatus = 'default';
1.1075.2.42 raeburn 9062: if ($defquota eq '') {
9063: if ($quotaname eq 'author') {
9064: $defquota = 500;
9065: }
9066: }
1.536 raeburn 9067: }
9068: } else {
9069: $settingstatus = 'default';
1.1075.2.41 raeburn 9070: if ($quotaname eq 'author') {
9071: $defquota = 500;
9072: } else {
9073: $defquota = 20;
9074: }
1.536 raeburn 9075: }
9076: if (wantarray) {
9077: return ($defquota,$settingstatus);
1.472 raeburn 9078: } else {
1.536 raeburn 9079: return $defquota;
1.472 raeburn 9080: }
9081: }
9082:
1.1075.2.41 raeburn 9083: ###############################################
9084:
9085: =pod
9086:
1.1075.2.42 raeburn 9087: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9088:
9089: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9090: of existing file within authoring space will cause quota for the authoring
9091: space to be exceeded.
9092:
9093: Same, if upload of a file directly to a course/community via Course Editor
9094: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9095:
1.1075.2.61 raeburn 9096: Inputs: 7
1.1075.2.42 raeburn 9097: 1. username or coursenum
1.1075.2.41 raeburn 9098: 2. domain
1.1075.2.42 raeburn 9099: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9100: 4. filename of file for which action is being requested
9101: 5. filesize (kB) of file
9102: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9103: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9104:
9105: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9106: otherwise return null.
9107:
1.1075.2.42 raeburn 9108: =back
9109:
1.1075.2.41 raeburn 9110: =cut
9111:
1.1075.2.42 raeburn 9112: sub excess_filesize_warning {
1.1075.2.59 raeburn 9113: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9114: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9115: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9116: if ($context eq 'author') {
9117: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9118: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9119: } else {
9120: foreach my $subdir ('docs','supplemental') {
9121: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9122: }
9123: }
1.1075.2.41 raeburn 9124: $disk_quota = int($disk_quota * 1000);
9125: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9126: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9127: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9128: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9129: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9130: $disk_quota,$current_disk_usage).
9131: '</p>';
9132: }
9133: return;
9134: }
9135:
9136: ###############################################
9137:
9138:
1.384 raeburn 9139: sub get_secgrprole_info {
9140: my ($cdom,$cnum,$needroles,$type) = @_;
9141: my %sections_count = &get_sections($cdom,$cnum);
9142: my @sections = (sort {$a <=> $b} keys(%sections_count));
9143: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9144: my @groups = sort(keys(%curr_groups));
9145: my $allroles = [];
9146: my $rolehash;
9147: my $accesshash = {
9148: active => 'Currently has access',
9149: future => 'Will have future access',
9150: previous => 'Previously had access',
9151: };
9152: if ($needroles) {
9153: $rolehash = {'all' => 'all'};
1.385 albertel 9154: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9155: if (&Apache::lonnet::error(%user_roles)) {
9156: undef(%user_roles);
9157: }
9158: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9159: my ($role)=split(/\:/,$item,2);
9160: if ($role eq 'cr') { next; }
9161: if ($role =~ /^cr/) {
9162: $$rolehash{$role} = (split('/',$role))[3];
9163: } else {
9164: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9165: }
9166: }
9167: foreach my $key (sort(keys(%{$rolehash}))) {
9168: push(@{$allroles},$key);
9169: }
9170: push (@{$allroles},'st');
9171: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9172: }
9173: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9174: }
9175:
1.555 raeburn 9176: sub user_picker {
1.994 raeburn 9177: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9178: my $currdom = $dom;
9179: my %curr_selected = (
9180: srchin => 'dom',
1.580 raeburn 9181: srchby => 'lastname',
1.555 raeburn 9182: );
9183: my $srchterm;
1.625 raeburn 9184: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9185: if ($srch->{'srchby'} ne '') {
9186: $curr_selected{'srchby'} = $srch->{'srchby'};
9187: }
9188: if ($srch->{'srchin'} ne '') {
9189: $curr_selected{'srchin'} = $srch->{'srchin'};
9190: }
9191: if ($srch->{'srchtype'} ne '') {
9192: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9193: }
9194: if ($srch->{'srchdomain'} ne '') {
9195: $currdom = $srch->{'srchdomain'};
9196: }
9197: $srchterm = $srch->{'srchterm'};
9198: }
9199: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 9200: 'usr' => 'Search criteria',
1.563 raeburn 9201: 'doma' => 'Domain/institution to search',
1.558 albertel 9202: 'uname' => 'username',
9203: 'lastname' => 'last name',
1.555 raeburn 9204: 'lastfirst' => 'last name, first name',
1.558 albertel 9205: 'crs' => 'in this course',
1.576 raeburn 9206: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9207: 'alc' => 'all LON-CAPA',
1.573 raeburn 9208: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9209: 'exact' => 'is',
9210: 'contains' => 'contains',
1.569 raeburn 9211: 'begins' => 'begins with',
1.571 raeburn 9212: 'youm' => "You must include some text to search for.",
9213: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9214: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9215: 'yomc' => "You must choose a domain when using an institutional directory search.",
9216: 'ymcd' => "You must choose a domain when using a domain search.",
9217: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9218: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9219: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9220: );
1.563 raeburn 9221: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9222: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9223:
9224: my @srchins = ('crs','dom','alc','instd');
9225:
9226: foreach my $option (@srchins) {
9227: # FIXME 'alc' option unavailable until
9228: # loncreateuser::print_user_query_page()
9229: # has been completed.
9230: next if ($option eq 'alc');
1.880 raeburn 9231: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9232: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9233: if ($curr_selected{'srchin'} eq $option) {
9234: $srchinsel .= '
9235: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9236: } else {
9237: $srchinsel .= '
9238: <option value="'.$option.'">'.$lt{$option}.'</option>';
9239: }
1.555 raeburn 9240: }
1.563 raeburn 9241: $srchinsel .= "\n </select>\n";
1.555 raeburn 9242:
9243: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9244: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9245: if ($curr_selected{'srchby'} eq $option) {
9246: $srchbysel .= '
9247: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9248: } else {
9249: $srchbysel .= '
9250: <option value="'.$option.'">'.$lt{$option}.'</option>';
9251: }
9252: }
9253: $srchbysel .= "\n </select>\n";
9254:
9255: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9256: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9257: if ($curr_selected{'srchtype'} eq $option) {
9258: $srchtypesel .= '
9259: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9260: } else {
9261: $srchtypesel .= '
9262: <option value="'.$option.'">'.$lt{$option}.'</option>';
9263: }
9264: }
9265: $srchtypesel .= "\n </select>\n";
9266:
1.558 albertel 9267: my ($newuserscript,$new_user_create);
1.994 raeburn 9268: my $context_dom = $env{'request.role.domain'};
9269: if ($context eq 'requestcrs') {
9270: if ($env{'form.coursedom'} ne '') {
9271: $context_dom = $env{'form.coursedom'};
9272: }
9273: }
1.556 raeburn 9274: if ($forcenewuser) {
1.576 raeburn 9275: if (ref($srch) eq 'HASH') {
1.994 raeburn 9276: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9277: if ($cancreate) {
9278: $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>';
9279: } else {
1.799 bisitz 9280: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9281: my %usertypetext = (
9282: official => 'institutional',
9283: unofficial => 'non-institutional',
9284: );
1.799 bisitz 9285: $new_user_create = '<p class="LC_warning">'
9286: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9287: .' '
9288: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9289: ,'<a href="'.$helplink.'">','</a>')
9290: .'</p><br />';
1.627 raeburn 9291: }
1.576 raeburn 9292: }
9293: }
9294:
1.556 raeburn 9295: $newuserscript = <<"ENDSCRIPT";
9296:
1.570 raeburn 9297: function setSearch(createnew,callingForm) {
1.556 raeburn 9298: if (createnew == 1) {
1.570 raeburn 9299: for (var i=0; i<callingForm.srchby.length; i++) {
9300: if (callingForm.srchby.options[i].value == 'uname') {
9301: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9302: }
9303: }
1.570 raeburn 9304: for (var i=0; i<callingForm.srchin.length; i++) {
9305: if ( callingForm.srchin.options[i].value == 'dom') {
9306: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9307: }
9308: }
1.570 raeburn 9309: for (var i=0; i<callingForm.srchtype.length; i++) {
9310: if (callingForm.srchtype.options[i].value == 'exact') {
9311: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9312: }
9313: }
1.570 raeburn 9314: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9315: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9316: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9317: }
9318: }
9319: }
9320: }
9321: ENDSCRIPT
1.558 albertel 9322:
1.556 raeburn 9323: }
9324:
1.555 raeburn 9325: my $output = <<"END_BLOCK";
1.556 raeburn 9326: <script type="text/javascript">
1.824 bisitz 9327: // <![CDATA[
1.570 raeburn 9328: function validateEntry(callingForm) {
1.558 albertel 9329:
1.556 raeburn 9330: var checkok = 1;
1.558 albertel 9331: var srchin;
1.570 raeburn 9332: for (var i=0; i<callingForm.srchin.length; i++) {
9333: if ( callingForm.srchin[i].checked ) {
9334: srchin = callingForm.srchin[i].value;
1.558 albertel 9335: }
9336: }
9337:
1.570 raeburn 9338: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9339: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9340: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9341: var srchterm = callingForm.srchterm.value;
9342: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9343: var msg = "";
9344:
9345: if (srchterm == "") {
9346: checkok = 0;
1.571 raeburn 9347: msg += "$lt{'youm'}\\n";
1.556 raeburn 9348: }
9349:
1.569 raeburn 9350: if (srchtype== 'begins') {
9351: if (srchterm.length < 2) {
9352: checkok = 0;
1.571 raeburn 9353: msg += "$lt{'thte'}\\n";
1.569 raeburn 9354: }
9355: }
9356:
1.556 raeburn 9357: if (srchtype== 'contains') {
9358: if (srchterm.length < 3) {
9359: checkok = 0;
1.571 raeburn 9360: msg += "$lt{'thet'}\\n";
1.556 raeburn 9361: }
9362: }
9363: if (srchin == 'instd') {
9364: if (srchdomain == '') {
9365: checkok = 0;
1.571 raeburn 9366: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9367: }
9368: }
9369: if (srchin == 'dom') {
9370: if (srchdomain == '') {
9371: checkok = 0;
1.571 raeburn 9372: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9373: }
9374: }
9375: if (srchby == 'lastfirst') {
9376: if (srchterm.indexOf(",") == -1) {
9377: checkok = 0;
1.571 raeburn 9378: msg += "$lt{'whus'}\\n";
1.556 raeburn 9379: }
9380: if (srchterm.indexOf(",") == srchterm.length -1) {
9381: checkok = 0;
1.571 raeburn 9382: msg += "$lt{'whse'}\\n";
1.556 raeburn 9383: }
9384: }
9385: if (checkok == 0) {
1.571 raeburn 9386: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9387: return;
9388: }
9389: if (checkok == 1) {
1.570 raeburn 9390: callingForm.submit();
1.556 raeburn 9391: }
9392: }
9393:
9394: $newuserscript
9395:
1.824 bisitz 9396: // ]]>
1.556 raeburn 9397: </script>
1.558 albertel 9398:
9399: $new_user_create
9400:
1.555 raeburn 9401: END_BLOCK
1.558 albertel 9402:
1.876 raeburn 9403: $output .= &Apache::lonhtmlcommon::start_pick_box().
9404: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9405: $domform.
9406: &Apache::lonhtmlcommon::row_closure().
9407: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9408: $srchbysel.
9409: $srchtypesel.
9410: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9411: $srchinsel.
9412: &Apache::lonhtmlcommon::row_closure(1).
9413: &Apache::lonhtmlcommon::end_pick_box().
9414: '<br />';
1.555 raeburn 9415: return $output;
9416: }
9417:
1.612 raeburn 9418: sub user_rule_check {
1.615 raeburn 9419: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9420: my $response;
9421: if (ref($usershash) eq 'HASH') {
9422: foreach my $user (keys(%{$usershash})) {
9423: my ($uname,$udom) = split(/:/,$user);
9424: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9425: my ($id,$newuser);
1.612 raeburn 9426: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9427: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9428: $id = $usershash->{$user}->{'id'};
9429: }
9430: my $inst_response;
9431: if (ref($checks) eq 'HASH') {
9432: if (defined($checks->{'username'})) {
1.615 raeburn 9433: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9434: &Apache::lonnet::get_instuser($udom,$uname);
9435: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9436: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9437: &Apache::lonnet::get_instuser($udom,undef,$id);
9438: }
1.615 raeburn 9439: } else {
9440: ($inst_response,%{$inst_results->{$user}}) =
9441: &Apache::lonnet::get_instuser($udom,$uname);
9442: return;
1.612 raeburn 9443: }
1.615 raeburn 9444: if (!$got_rules->{$udom}) {
1.612 raeburn 9445: my %domconfig = &Apache::lonnet::get_dom('configuration',
9446: ['usercreation'],$udom);
9447: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9448: foreach my $item ('username','id') {
1.612 raeburn 9449: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9450: $$curr_rules{$udom}{$item} =
9451: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9452: }
9453: }
9454: }
1.615 raeburn 9455: $got_rules->{$udom} = 1;
1.585 raeburn 9456: }
1.612 raeburn 9457: foreach my $item (keys(%{$checks})) {
9458: if (ref($$curr_rules{$udom}) eq 'HASH') {
9459: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9460: if (@{$$curr_rules{$udom}{$item}} > 0) {
9461: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9462: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9463: if ($rule_check{$rule}) {
9464: $$rulematch{$user}{$item} = $rule;
9465: if ($inst_response eq 'ok') {
1.615 raeburn 9466: if (ref($inst_results) eq 'HASH') {
9467: if (ref($inst_results->{$user}) eq 'HASH') {
9468: if (keys(%{$inst_results->{$user}}) == 0) {
9469: $$alerts{$item}{$udom}{$uname} = 1;
9470: }
1.612 raeburn 9471: }
9472: }
1.615 raeburn 9473: }
9474: last;
1.585 raeburn 9475: }
9476: }
9477: }
9478: }
9479: }
9480: }
9481: }
9482: }
1.612 raeburn 9483: return;
9484: }
9485:
9486: sub user_rule_formats {
9487: my ($domain,$domdesc,$curr_rules,$check) = @_;
9488: my %text = (
9489: 'username' => 'Usernames',
9490: 'id' => 'IDs',
9491: );
9492: my $output;
9493: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9494: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9495: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 9496: $output = '<br />'.
9497: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9498: '<span class="LC_cusr_emph">','</span>',$domdesc).
9499: ' <ul>';
1.612 raeburn 9500: foreach my $rule (@{$ruleorder}) {
9501: if (ref($curr_rules) eq 'ARRAY') {
9502: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9503: if (ref($rules->{$rule}) eq 'HASH') {
9504: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9505: $rules->{$rule}{'desc'}.'</li>';
9506: }
9507: }
9508: }
9509: }
9510: $output .= '</ul>';
9511: }
9512: }
9513: return $output;
9514: }
9515:
9516: sub instrule_disallow_msg {
1.615 raeburn 9517: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9518: my $response;
9519: my %text = (
9520: item => 'username',
9521: items => 'usernames',
9522: match => 'matches',
9523: do => 'does',
9524: action => 'a username',
9525: one => 'one',
9526: );
9527: if ($count > 1) {
9528: $text{'item'} = 'usernames';
9529: $text{'match'} ='match';
9530: $text{'do'} = 'do';
9531: $text{'action'} = 'usernames',
9532: $text{'one'} = 'ones';
9533: }
9534: if ($checkitem eq 'id') {
9535: $text{'items'} = 'IDs';
9536: $text{'item'} = 'ID';
9537: $text{'action'} = 'an ID';
1.615 raeburn 9538: if ($count > 1) {
9539: $text{'item'} = 'IDs';
9540: $text{'action'} = 'IDs';
9541: }
1.612 raeburn 9542: }
1.674 bisitz 9543: $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 9544: if ($mode eq 'upload') {
9545: if ($checkitem eq 'username') {
9546: $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'}.");
9547: } elsif ($checkitem eq 'id') {
1.674 bisitz 9548: $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 9549: }
1.669 raeburn 9550: } elsif ($mode eq 'selfcreate') {
9551: if ($checkitem eq 'id') {
9552: $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.");
9553: }
1.615 raeburn 9554: } else {
9555: if ($checkitem eq 'username') {
9556: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9557: } elsif ($checkitem eq 'id') {
9558: $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.");
9559: }
1.612 raeburn 9560: }
9561: return $response;
1.585 raeburn 9562: }
9563:
1.624 raeburn 9564: sub personal_data_fieldtitles {
9565: my %fieldtitles = &Apache::lonlocal::texthash (
9566: id => 'Student/Employee ID',
9567: permanentemail => 'E-mail address',
9568: lastname => 'Last Name',
9569: firstname => 'First Name',
9570: middlename => 'Middle Name',
9571: generation => 'Generation',
9572: gen => 'Generation',
1.765 raeburn 9573: inststatus => 'Affiliation',
1.624 raeburn 9574: );
9575: return %fieldtitles;
9576: }
9577:
1.642 raeburn 9578: sub sorted_inst_types {
9579: my ($dom) = @_;
1.1075.2.70 raeburn 9580: my ($usertypes,$order);
9581: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9582: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
9583: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
9584: $order = $domdefaults{'inststatus'}{'inststatusorder'};
9585: } else {
9586: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9587: }
1.642 raeburn 9588: my $othertitle = &mt('All users');
9589: if ($env{'request.course.id'}) {
1.668 raeburn 9590: $othertitle = &mt('Any users');
1.642 raeburn 9591: }
9592: my @types;
9593: if (ref($order) eq 'ARRAY') {
9594: @types = @{$order};
9595: }
9596: if (@types == 0) {
9597: if (ref($usertypes) eq 'HASH') {
9598: @types = sort(keys(%{$usertypes}));
9599: }
9600: }
9601: if (keys(%{$usertypes}) > 0) {
9602: $othertitle = &mt('Other users');
9603: }
9604: return ($othertitle,$usertypes,\@types);
9605: }
9606:
1.645 raeburn 9607: sub get_institutional_codes {
9608: my ($settings,$allcourses,$LC_code) = @_;
9609: # Get complete list of course sections to update
9610: my @currsections = ();
9611: my @currxlists = ();
9612: my $coursecode = $$settings{'internal.coursecode'};
9613:
9614: if ($$settings{'internal.sectionnums'} ne '') {
9615: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9616: }
9617:
9618: if ($$settings{'internal.crosslistings'} ne '') {
9619: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9620: }
9621:
9622: if (@currxlists > 0) {
9623: foreach (@currxlists) {
9624: if (m/^([^:]+):(\w*)$/) {
9625: unless (grep/^$1$/,@{$allcourses}) {
9626: push @{$allcourses},$1;
9627: $$LC_code{$1} = $2;
9628: }
9629: }
9630: }
9631: }
9632:
9633: if (@currsections > 0) {
9634: foreach (@currsections) {
9635: if (m/^(\w+):(\w*)$/) {
9636: my $sec = $coursecode.$1;
9637: my $lc_sec = $2;
9638: unless (grep/^$sec$/,@{$allcourses}) {
9639: push @{$allcourses},$sec;
9640: $$LC_code{$sec} = $lc_sec;
9641: }
9642: }
9643: }
9644: }
9645: return;
9646: }
9647:
1.971 raeburn 9648: sub get_standard_codeitems {
9649: return ('Year','Semester','Department','Number','Section');
9650: }
9651:
1.112 bowersj2 9652: =pod
9653:
1.780 raeburn 9654: =head1 Slot Helpers
9655:
9656: =over 4
9657:
9658: =item * sorted_slots()
9659:
1.1040 raeburn 9660: Sorts an array of slot names in order of an optional sort key,
9661: default sort is by slot start time (earliest first).
1.780 raeburn 9662:
9663: Inputs:
9664:
9665: =over 4
9666:
9667: slotsarr - Reference to array of unsorted slot names.
9668:
9669: slots - Reference to hash of hash, where outer hash keys are slot names.
9670:
1.1040 raeburn 9671: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9672:
1.549 albertel 9673: =back
9674:
1.780 raeburn 9675: Returns:
9676:
9677: =over 4
9678:
1.1040 raeburn 9679: sorted - An array of slot names sorted by a specified sort key
9680: (default sort key is start time of the slot).
1.780 raeburn 9681:
9682: =back
9683:
9684: =cut
9685:
9686:
9687: sub sorted_slots {
1.1040 raeburn 9688: my ($slotsarr,$slots,$sortkey) = @_;
9689: if ($sortkey eq '') {
9690: $sortkey = 'starttime';
9691: }
1.780 raeburn 9692: my @sorted;
9693: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9694: @sorted =
9695: sort {
9696: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9697: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9698: }
9699: if (ref($slots->{$a})) { return -1;}
9700: if (ref($slots->{$b})) { return 1;}
9701: return 0;
9702: } @{$slotsarr};
9703: }
9704: return @sorted;
9705: }
9706:
1.1040 raeburn 9707: =pod
9708:
9709: =item * get_future_slots()
9710:
9711: Inputs:
9712:
9713: =over 4
9714:
9715: cnum - course number
9716:
9717: cdom - course domain
9718:
9719: now - current UNIX time
9720:
9721: symb - optional symb
9722:
9723: =back
9724:
9725: Returns:
9726:
9727: =over 4
9728:
9729: sorted_reservable - ref to array of student_schedulable slots currently
9730: reservable, ordered by end date of reservation period.
9731:
9732: reservable_now - ref to hash of student_schedulable slots currently
9733: reservable.
9734:
9735: Keys in inner hash are:
9736: (a) symb: either blank or symb to which slot use is restricted.
9737: (b) endreserve: end date of reservation period.
9738:
9739: sorted_future - ref to array of student_schedulable slots reservable in
9740: the future, ordered by start date of reservation period.
9741:
9742: future_reservable - ref to hash of student_schedulable slots reservable
9743: in the future.
9744:
9745: Keys in inner hash are:
9746: (a) symb: either blank or symb to which slot use is restricted.
9747: (b) startreserve: start date of reservation period.
9748:
9749: =back
9750:
9751: =cut
9752:
9753: sub get_future_slots {
9754: my ($cnum,$cdom,$now,$symb) = @_;
9755: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9756: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9757: foreach my $slot (keys(%slots)) {
9758: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9759: if ($symb) {
9760: next if (($slots{$slot}->{'symb'} ne '') &&
9761: ($slots{$slot}->{'symb'} ne $symb));
9762: }
9763: if (($slots{$slot}->{'starttime'} > $now) &&
9764: ($slots{$slot}->{'endtime'} > $now)) {
9765: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9766: my $userallowed = 0;
9767: if ($slots{$slot}->{'allowedsections'}) {
9768: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9769: if (!defined($env{'request.role.sec'})
9770: && grep(/^No section assigned$/,@allowed_sec)) {
9771: $userallowed=1;
9772: } else {
9773: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9774: $userallowed=1;
9775: }
9776: }
9777: unless ($userallowed) {
9778: if (defined($env{'request.course.groups'})) {
9779: my @groups = split(/:/,$env{'request.course.groups'});
9780: foreach my $group (@groups) {
9781: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9782: $userallowed=1;
9783: last;
9784: }
9785: }
9786: }
9787: }
9788: }
9789: if ($slots{$slot}->{'allowedusers'}) {
9790: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9791: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9792: if (grep(/^\Q$user\E$/,@allowed_users)) {
9793: $userallowed = 1;
9794: }
9795: }
9796: next unless($userallowed);
9797: }
9798: my $startreserve = $slots{$slot}->{'startreserve'};
9799: my $endreserve = $slots{$slot}->{'endreserve'};
9800: my $symb = $slots{$slot}->{'symb'};
9801: if (($startreserve < $now) &&
9802: (!$endreserve || $endreserve > $now)) {
9803: my $lastres = $endreserve;
9804: if (!$lastres) {
9805: $lastres = $slots{$slot}->{'starttime'};
9806: }
9807: $reservable_now{$slot} = {
9808: symb => $symb,
9809: endreserve => $lastres
9810: };
9811: } elsif (($startreserve > $now) &&
9812: (!$endreserve || $endreserve > $startreserve)) {
9813: $future_reservable{$slot} = {
9814: symb => $symb,
9815: startreserve => $startreserve
9816: };
9817: }
9818: }
9819: }
9820: my @unsorted_reservable = keys(%reservable_now);
9821: if (@unsorted_reservable > 0) {
9822: @sorted_reservable =
9823: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9824: }
9825: my @unsorted_future = keys(%future_reservable);
9826: if (@unsorted_future > 0) {
9827: @sorted_future =
9828: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9829: }
9830: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9831: }
1.780 raeburn 9832:
9833: =pod
9834:
1.1057 foxr 9835: =back
9836:
1.549 albertel 9837: =head1 HTTP Helpers
9838:
9839: =over 4
9840:
1.648 raeburn 9841: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9842:
1.258 albertel 9843: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9844: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9845: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9846:
9847: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9848: $possible_names is an ref to an array of form element names. As an example:
9849: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9850: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9851:
9852: =cut
1.1 albertel 9853:
1.6 albertel 9854: sub get_unprocessed_cgi {
1.25 albertel 9855: my ($query,$possible_names)= @_;
1.26 matthew 9856: # $Apache::lonxml::debug=1;
1.356 albertel 9857: foreach my $pair (split(/&/,$query)) {
9858: my ($name, $value) = split(/=/,$pair);
1.369 www 9859: $name = &unescape($name);
1.25 albertel 9860: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9861: $value =~ tr/+/ /;
9862: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9863: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9864: }
1.16 harris41 9865: }
1.6 albertel 9866: }
9867:
1.112 bowersj2 9868: =pod
9869:
1.648 raeburn 9870: =item * &cacheheader()
1.112 bowersj2 9871:
9872: returns cache-controlling header code
9873:
9874: =cut
9875:
1.7 albertel 9876: sub cacheheader {
1.258 albertel 9877: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9878: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9879: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9880: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9881: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9882: return $output;
1.7 albertel 9883: }
9884:
1.112 bowersj2 9885: =pod
9886:
1.648 raeburn 9887: =item * &no_cache($r)
1.112 bowersj2 9888:
9889: specifies header code to not have cache
9890:
9891: =cut
9892:
1.9 albertel 9893: sub no_cache {
1.216 albertel 9894: my ($r) = @_;
9895: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9896: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9897: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9898: $r->no_cache(1);
9899: $r->header_out("Expires" => $date);
9900: $r->header_out("Pragma" => "no-cache");
1.123 www 9901: }
9902:
9903: sub content_type {
1.181 albertel 9904: my ($r,$type,$charset) = @_;
1.299 foxr 9905: if ($r) {
9906: # Note that printout.pl calls this with undef for $r.
9907: &no_cache($r);
9908: }
1.258 albertel 9909: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9910: unless ($charset) {
9911: $charset=&Apache::lonlocal::current_encoding;
9912: }
9913: if ($charset) { $type.='; charset='.$charset; }
9914: if ($r) {
9915: $r->content_type($type);
9916: } else {
9917: print("Content-type: $type\n\n");
9918: }
1.9 albertel 9919: }
1.25 albertel 9920:
1.112 bowersj2 9921: =pod
9922:
1.648 raeburn 9923: =item * &add_to_env($name,$value)
1.112 bowersj2 9924:
1.258 albertel 9925: adds $name to the %env hash with value
1.112 bowersj2 9926: $value, if $name already exists, the entry is converted to an array
9927: reference and $value is added to the array.
9928:
9929: =cut
9930:
1.25 albertel 9931: sub add_to_env {
9932: my ($name,$value)=@_;
1.258 albertel 9933: if (defined($env{$name})) {
9934: if (ref($env{$name})) {
1.25 albertel 9935: #already have multiple values
1.258 albertel 9936: push(@{ $env{$name} },$value);
1.25 albertel 9937: } else {
9938: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9939: my $first=$env{$name};
9940: undef($env{$name});
9941: push(@{ $env{$name} },$first,$value);
1.25 albertel 9942: }
9943: } else {
1.258 albertel 9944: $env{$name}=$value;
1.25 albertel 9945: }
1.31 albertel 9946: }
1.149 albertel 9947:
9948: =pod
9949:
1.648 raeburn 9950: =item * &get_env_multiple($name)
1.149 albertel 9951:
1.258 albertel 9952: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9953: values may be defined and end up as an array ref.
9954:
9955: returns an array of values
9956:
9957: =cut
9958:
9959: sub get_env_multiple {
9960: my ($name) = @_;
9961: my @values;
1.258 albertel 9962: if (defined($env{$name})) {
1.149 albertel 9963: # exists is it an array
1.258 albertel 9964: if (ref($env{$name})) {
9965: @values=@{ $env{$name} };
1.149 albertel 9966: } else {
1.258 albertel 9967: $values[0]=$env{$name};
1.149 albertel 9968: }
9969: }
9970: return(@values);
9971: }
9972:
1.660 raeburn 9973: sub ask_for_embedded_content {
9974: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9975: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 9976: %currsubfile,%unused,$rem);
1.1071 raeburn 9977: my $counter = 0;
9978: my $numnew = 0;
1.987 raeburn 9979: my $numremref = 0;
9980: my $numinvalid = 0;
9981: my $numpathchg = 0;
9982: my $numexisting = 0;
1.1071 raeburn 9983: my $numunused = 0;
9984: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 9985: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 9986: my $heading = &mt('Upload embedded files');
9987: my $buttontext = &mt('Upload');
9988:
1.1075.2.11 raeburn 9989: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 9990: if ($actionurl eq '/adm/dependencies') {
9991: $navmap = Apache::lonnavmaps::navmap->new();
9992: }
9993: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9994: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 9995: }
1.1075.2.35 raeburn 9996: if (($actionurl eq '/adm/portfolio') ||
9997: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9998: my $current_path='/';
9999: if ($env{'form.currentpath'}) {
10000: $current_path = $env{'form.currentpath'};
10001: }
10002: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10003: $udom = $cdom;
10004: $uname = $cnum;
1.984 raeburn 10005: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10006: } else {
10007: $udom = $env{'user.domain'};
10008: $uname = $env{'user.name'};
10009: $url = '/userfiles/portfolio';
10010: }
1.987 raeburn 10011: $toplevel = $url.'/';
1.984 raeburn 10012: $url .= $current_path;
10013: $getpropath = 1;
1.987 raeburn 10014: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10015: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10016: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10017: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10018: $toplevel = $url;
1.984 raeburn 10019: if ($rest ne '') {
1.987 raeburn 10020: $url .= $rest;
10021: }
10022: } elsif ($actionurl eq '/adm/coursedocs') {
10023: if (ref($args) eq 'HASH') {
1.1071 raeburn 10024: $url = $args->{'docs_url'};
10025: $toplevel = $url;
1.1075.2.11 raeburn 10026: if ($args->{'context'} eq 'paste') {
10027: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10028: ($path) =
10029: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10030: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10031: $fileloc =~ s{^/}{};
10032: }
1.1071 raeburn 10033: }
10034: } elsif ($actionurl eq '/adm/dependencies') {
10035: if ($env{'request.course.id'} ne '') {
10036: if (ref($args) eq 'HASH') {
10037: $url = $args->{'docs_url'};
10038: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10039: $toplevel = $url;
10040: unless ($toplevel =~ m{^/}) {
10041: $toplevel = "/$url";
10042: }
1.1075.2.11 raeburn 10043: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10044: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10045: $path = $1;
10046: } else {
10047: ($path) =
10048: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10049: }
1.1075.2.79 raeburn 10050: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10051: $fileloc = $toplevel;
10052: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10053: my ($udom,$uname,$fname) =
10054: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10055: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10056: } else {
10057: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10058: }
1.1071 raeburn 10059: $fileloc =~ s{^/}{};
10060: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10061: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10062: }
1.987 raeburn 10063: }
1.1075.2.35 raeburn 10064: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10065: $udom = $cdom;
10066: $uname = $cnum;
10067: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10068: $toplevel = $url;
10069: $path = $url;
10070: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10071: $fileloc =~ s{^/}{};
10072: }
10073: foreach my $file (keys(%{$allfiles})) {
10074: my $embed_file;
10075: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10076: $embed_file = $1;
10077: } else {
10078: $embed_file = $file;
10079: }
1.1075.2.55 raeburn 10080: my ($absolutepath,$cleaned_file);
10081: if ($embed_file =~ m{^\w+://}) {
10082: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10083: $newfiles{$cleaned_file} = 1;
10084: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10085: } else {
1.1075.2.55 raeburn 10086: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10087: if ($embed_file =~ m{^/}) {
10088: $absolutepath = $embed_file;
10089: }
1.1075.2.47 raeburn 10090: if ($cleaned_file =~ m{/}) {
10091: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10092: $path = &check_for_traversal($path,$url,$toplevel);
10093: my $item = $fname;
10094: if ($path ne '') {
10095: $item = $path.'/'.$fname;
10096: $subdependencies{$path}{$fname} = 1;
10097: } else {
10098: $dependencies{$item} = 1;
10099: }
10100: if ($absolutepath) {
10101: $mapping{$item} = $absolutepath;
10102: } else {
10103: $mapping{$item} = $embed_file;
10104: }
10105: } else {
10106: $dependencies{$embed_file} = 1;
10107: if ($absolutepath) {
1.1075.2.47 raeburn 10108: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10109: } else {
1.1075.2.47 raeburn 10110: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10111: }
10112: }
1.984 raeburn 10113: }
10114: }
1.1071 raeburn 10115: my $dirptr = 16384;
1.984 raeburn 10116: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10117: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10118: if (($actionurl eq '/adm/portfolio') ||
10119: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10120: my ($sublistref,$listerror) =
10121: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10122: if (ref($sublistref) eq 'ARRAY') {
10123: foreach my $line (@{$sublistref}) {
10124: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10125: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10126: }
1.984 raeburn 10127: }
1.987 raeburn 10128: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10129: if (opendir(my $dir,$url.'/'.$path)) {
10130: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10131: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10132: }
1.1075.2.11 raeburn 10133: } elsif (($actionurl eq '/adm/dependencies') ||
10134: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10135: ($args->{'context'} eq 'paste')) ||
10136: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10137: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10138: my $dir;
10139: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10140: $dir = $fileloc;
10141: } else {
10142: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10143: }
1.1071 raeburn 10144: if ($dir ne '') {
10145: my ($sublistref,$listerror) =
10146: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10147: if (ref($sublistref) eq 'ARRAY') {
10148: foreach my $line (@{$sublistref}) {
10149: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10150: undef,$mtime)=split(/\&/,$line,12);
10151: unless (($testdir&$dirptr) ||
10152: ($file_name =~ /^\.\.?$/)) {
10153: $currsubfile{$path}{$file_name} = [$size,$mtime];
10154: }
10155: }
10156: }
10157: }
1.984 raeburn 10158: }
10159: }
10160: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10161: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10162: my $item = $path.'/'.$file;
10163: unless ($mapping{$item} eq $item) {
10164: $pathchanges{$item} = 1;
10165: }
10166: $existing{$item} = 1;
10167: $numexisting ++;
10168: } else {
10169: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10170: }
10171: }
1.1071 raeburn 10172: if ($actionurl eq '/adm/dependencies') {
10173: foreach my $path (keys(%currsubfile)) {
10174: if (ref($currsubfile{$path}) eq 'HASH') {
10175: foreach my $file (keys(%{$currsubfile{$path}})) {
10176: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10177: next if (($rem ne '') &&
10178: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10179: (ref($navmap) &&
10180: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10181: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10182: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10183: $unused{$path.'/'.$file} = 1;
10184: }
10185: }
10186: }
10187: }
10188: }
1.984 raeburn 10189: }
1.987 raeburn 10190: my %currfile;
1.1075.2.35 raeburn 10191: if (($actionurl eq '/adm/portfolio') ||
10192: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10193: my ($dirlistref,$listerror) =
10194: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10195: if (ref($dirlistref) eq 'ARRAY') {
10196: foreach my $line (@{$dirlistref}) {
10197: my ($file_name,$rest) = split(/\&/,$line,2);
10198: $currfile{$file_name} = 1;
10199: }
1.984 raeburn 10200: }
1.987 raeburn 10201: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10202: if (opendir(my $dir,$url)) {
1.987 raeburn 10203: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10204: map {$currfile{$_} = 1;} @dir_list;
10205: }
1.1075.2.11 raeburn 10206: } elsif (($actionurl eq '/adm/dependencies') ||
10207: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10208: ($args->{'context'} eq 'paste')) ||
10209: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10210: if ($env{'request.course.id'} ne '') {
10211: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10212: if ($dir ne '') {
10213: my ($dirlistref,$listerror) =
10214: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10215: if (ref($dirlistref) eq 'ARRAY') {
10216: foreach my $line (@{$dirlistref}) {
10217: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10218: $size,undef,$mtime)=split(/\&/,$line,12);
10219: unless (($testdir&$dirptr) ||
10220: ($file_name =~ /^\.\.?$/)) {
10221: $currfile{$file_name} = [$size,$mtime];
10222: }
10223: }
10224: }
10225: }
10226: }
1.984 raeburn 10227: }
10228: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10229: if (exists($currfile{$file})) {
1.987 raeburn 10230: unless ($mapping{$file} eq $file) {
10231: $pathchanges{$file} = 1;
10232: }
10233: $existing{$file} = 1;
10234: $numexisting ++;
10235: } else {
1.984 raeburn 10236: $newfiles{$file} = 1;
10237: }
10238: }
1.1071 raeburn 10239: foreach my $file (keys(%currfile)) {
10240: unless (($file eq $filename) ||
10241: ($file eq $filename.'.bak') ||
10242: ($dependencies{$file})) {
1.1075.2.11 raeburn 10243: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10244: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10245: next if (($rem ne '') &&
10246: (($env{"httpref.$rem".$file} ne '') ||
10247: (ref($navmap) &&
10248: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10249: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10250: ($navmap->getResourceByUrl($rem.$1)))))));
10251: }
1.1075.2.11 raeburn 10252: }
1.1071 raeburn 10253: $unused{$file} = 1;
10254: }
10255: }
1.1075.2.11 raeburn 10256: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10257: ($args->{'context'} eq 'paste')) {
10258: $counter = scalar(keys(%existing));
10259: $numpathchg = scalar(keys(%pathchanges));
10260: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10261: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10262: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10263: $counter = scalar(keys(%existing));
10264: $numpathchg = scalar(keys(%pathchanges));
10265: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10266: }
1.984 raeburn 10267: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10268: if ($actionurl eq '/adm/dependencies') {
10269: next if ($embed_file =~ m{^\w+://});
10270: }
1.660 raeburn 10271: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10272: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10273: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10274: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10275: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10276: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10277: }
1.1075.2.35 raeburn 10278: $upload_output .= '</td>';
1.1071 raeburn 10279: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10280: $upload_output.='<td align="right">'.
10281: '<span class="LC_info LC_fontsize_medium">'.
10282: &mt("URL points to web address").'</span>';
1.987 raeburn 10283: $numremref++;
1.660 raeburn 10284: } elsif ($args->{'error_on_invalid_names'}
10285: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10286: $upload_output.='<td align="right"><span class="LC_warning">'.
10287: &mt('Invalid characters').'</span>';
1.987 raeburn 10288: $numinvalid++;
1.660 raeburn 10289: } else {
1.1075.2.35 raeburn 10290: $upload_output .= '<td>'.
10291: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10292: $embed_file,\%mapping,
1.1071 raeburn 10293: $allfiles,$codebase,'upload');
10294: $counter ++;
10295: $numnew ++;
1.987 raeburn 10296: }
10297: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10298: }
10299: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10300: if ($actionurl eq '/adm/dependencies') {
10301: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10302: $modify_output .= &start_data_table_row().
10303: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10304: '<img src="'.&icon($embed_file).'" border="0" />'.
10305: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10306: '<td>'.$size.'</td>'.
10307: '<td>'.$mtime.'</td>'.
10308: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10309: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10310: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10311: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10312: &embedded_file_element('upload_embedded',$counter,
10313: $embed_file,\%mapping,
10314: $allfiles,$codebase,'modify').
10315: '</div></td>'.
10316: &end_data_table_row()."\n";
10317: $counter ++;
10318: } else {
10319: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10320: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10321: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10322: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10323: &Apache::loncommon::end_data_table_row()."\n";
10324: }
10325: }
10326: my $delidx = $counter;
10327: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10328: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10329: $delete_output .= &start_data_table_row().
10330: '<td><img src="'.&icon($oldfile).'" />'.
10331: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10332: '<td>'.$size.'</td>'.
10333: '<td>'.$mtime.'</td>'.
10334: '<td><label><input type="checkbox" name="del_upload_dep" '.
10335: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10336: &embedded_file_element('upload_embedded',$delidx,
10337: $oldfile,\%mapping,$allfiles,
10338: $codebase,'delete').'</td>'.
10339: &end_data_table_row()."\n";
10340: $numunused ++;
10341: $delidx ++;
1.987 raeburn 10342: }
10343: if ($upload_output) {
10344: $upload_output = &start_data_table().
10345: $upload_output.
10346: &end_data_table()."\n";
10347: }
1.1071 raeburn 10348: if ($modify_output) {
10349: $modify_output = &start_data_table().
10350: &start_data_table_header_row().
10351: '<th>'.&mt('File').'</th>'.
10352: '<th>'.&mt('Size (KB)').'</th>'.
10353: '<th>'.&mt('Modified').'</th>'.
10354: '<th>'.&mt('Upload replacement?').'</th>'.
10355: &end_data_table_header_row().
10356: $modify_output.
10357: &end_data_table()."\n";
10358: }
10359: if ($delete_output) {
10360: $delete_output = &start_data_table().
10361: &start_data_table_header_row().
10362: '<th>'.&mt('File').'</th>'.
10363: '<th>'.&mt('Size (KB)').'</th>'.
10364: '<th>'.&mt('Modified').'</th>'.
10365: '<th>'.&mt('Delete?').'</th>'.
10366: &end_data_table_header_row().
10367: $delete_output.
10368: &end_data_table()."\n";
10369: }
1.987 raeburn 10370: my $applies = 0;
10371: if ($numremref) {
10372: $applies ++;
10373: }
10374: if ($numinvalid) {
10375: $applies ++;
10376: }
10377: if ($numexisting) {
10378: $applies ++;
10379: }
1.1071 raeburn 10380: if ($counter || $numunused) {
1.987 raeburn 10381: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10382: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10383: $state.'<h3>'.$heading.'</h3>';
10384: if ($actionurl eq '/adm/dependencies') {
10385: if ($numnew) {
10386: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10387: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10388: $upload_output.'<br />'."\n";
10389: }
10390: if ($numexisting) {
10391: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10392: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10393: $modify_output.'<br />'."\n";
10394: $buttontext = &mt('Save changes');
10395: }
10396: if ($numunused) {
10397: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10398: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10399: $delete_output.'<br />'."\n";
10400: $buttontext = &mt('Save changes');
10401: }
10402: } else {
10403: $output .= $upload_output.'<br />'."\n";
10404: }
10405: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10406: $counter.'" />'."\n";
10407: if ($actionurl eq '/adm/dependencies') {
10408: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10409: $numnew.'" />'."\n";
10410: } elsif ($actionurl eq '') {
1.987 raeburn 10411: $output .= '<input type="hidden" name="phase" value="three" />';
10412: }
10413: } elsif ($applies) {
10414: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10415: if ($applies > 1) {
10416: $output .=
1.1075.2.35 raeburn 10417: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10418: if ($numremref) {
10419: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10420: }
10421: if ($numinvalid) {
10422: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10423: }
10424: if ($numexisting) {
10425: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10426: }
10427: $output .= '</ul><br />';
10428: } elsif ($numremref) {
10429: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10430: } elsif ($numinvalid) {
10431: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10432: } elsif ($numexisting) {
10433: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10434: }
10435: $output .= $upload_output.'<br />';
10436: }
10437: my ($pathchange_output,$chgcount);
1.1071 raeburn 10438: $chgcount = $counter;
1.987 raeburn 10439: if (keys(%pathchanges) > 0) {
10440: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10441: if ($counter) {
1.987 raeburn 10442: $output .= &embedded_file_element('pathchange',$chgcount,
10443: $embed_file,\%mapping,
1.1071 raeburn 10444: $allfiles,$codebase,'change');
1.987 raeburn 10445: } else {
10446: $pathchange_output .=
10447: &start_data_table_row().
10448: '<td><input type ="checkbox" name="namechange" value="'.
10449: $chgcount.'" checked="checked" /></td>'.
10450: '<td>'.$mapping{$embed_file}.'</td>'.
10451: '<td>'.$embed_file.
10452: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10453: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10454: '</td>'.&end_data_table_row();
1.660 raeburn 10455: }
1.987 raeburn 10456: $numpathchg ++;
10457: $chgcount ++;
1.660 raeburn 10458: }
10459: }
1.1075.2.35 raeburn 10460: if (($counter) || ($numunused)) {
1.987 raeburn 10461: if ($numpathchg) {
10462: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10463: $numpathchg.'" />'."\n";
10464: }
10465: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10466: ($actionurl eq '/adm/imsimport')) {
10467: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10468: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10469: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10470: } elsif ($actionurl eq '/adm/dependencies') {
10471: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10472: }
1.1075.2.35 raeburn 10473: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10474: } elsif ($numpathchg) {
10475: my %pathchange = ();
10476: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10477: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10478: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 10479: }
1.987 raeburn 10480: }
1.1071 raeburn 10481: return ($output,$counter,$numpathchg);
1.987 raeburn 10482: }
10483:
1.1075.2.47 raeburn 10484: =pod
10485:
10486: =item * clean_path($name)
10487:
10488: Performs clean-up of directories, subdirectories and filename in an
10489: embedded object, referenced in an HTML file which is being uploaded
10490: to a course or portfolio, where
10491: "Upload embedded images/multimedia files if HTML file" checkbox was
10492: checked.
10493:
10494: Clean-up is similar to replacements in lonnet::clean_filename()
10495: except each / between sub-directory and next level is preserved.
10496:
10497: =cut
10498:
10499: sub clean_path {
10500: my ($embed_file) = @_;
10501: $embed_file =~s{^/+}{};
10502: my @contents;
10503: if ($embed_file =~ m{/}) {
10504: @contents = split(/\//,$embed_file);
10505: } else {
10506: @contents = ($embed_file);
10507: }
10508: my $lastidx = scalar(@contents)-1;
10509: for (my $i=0; $i<=$lastidx; $i++) {
10510: $contents[$i]=~s{\\}{/}g;
10511: $contents[$i]=~s/\s+/\_/g;
10512: $contents[$i]=~s{[^/\w\.\-]}{}g;
10513: if ($i == $lastidx) {
10514: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10515: }
10516: }
10517: if ($lastidx > 0) {
10518: return join('/',@contents);
10519: } else {
10520: return $contents[0];
10521: }
10522: }
10523:
1.987 raeburn 10524: sub embedded_file_element {
1.1071 raeburn 10525: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10526: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10527: (ref($codebase) eq 'HASH'));
10528: my $output;
1.1071 raeburn 10529: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10530: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10531: }
10532: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10533: &escape($embed_file).'" />';
10534: unless (($context eq 'upload_embedded') &&
10535: ($mapping->{$embed_file} eq $embed_file)) {
10536: $output .='
10537: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10538: }
10539: my $attrib;
10540: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10541: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10542: }
10543: $output .=
10544: "\n\t\t".
10545: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10546: $attrib.'" />';
10547: if (exists($codebase->{$mapping->{$embed_file}})) {
10548: $output .=
10549: "\n\t\t".
10550: '<input name="codebase_'.$num.'" type="hidden" value="'.
10551: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10552: }
1.987 raeburn 10553: return $output;
1.660 raeburn 10554: }
10555:
1.1071 raeburn 10556: sub get_dependency_details {
10557: my ($currfile,$currsubfile,$embed_file) = @_;
10558: my ($size,$mtime,$showsize,$showmtime);
10559: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10560: if ($embed_file =~ m{/}) {
10561: my ($path,$fname) = split(/\//,$embed_file);
10562: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10563: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10564: }
10565: } else {
10566: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10567: ($size,$mtime) = @{$currfile->{$embed_file}};
10568: }
10569: }
10570: $showsize = $size/1024.0;
10571: $showsize = sprintf("%.1f",$showsize);
10572: if ($mtime > 0) {
10573: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10574: }
10575: }
10576: return ($showsize,$showmtime);
10577: }
10578:
10579: sub ask_embedded_js {
10580: return <<"END";
10581: <script type="text/javascript"">
10582: // <![CDATA[
10583: function toggleBrowse(counter) {
10584: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10585: var fileid = document.getElementById('embedded_item_'+counter);
10586: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10587: if (chkboxid.checked == true) {
10588: uploaddivid.style.display='block';
10589: } else {
10590: uploaddivid.style.display='none';
10591: fileid.value = '';
10592: }
10593: }
10594: // ]]>
10595: </script>
10596:
10597: END
10598: }
10599:
1.661 raeburn 10600: sub upload_embedded {
10601: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10602: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10603: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10604: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10605: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10606: my $orig_uploaded_filename =
10607: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10608: foreach my $type ('orig','ref','attrib','codebase') {
10609: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10610: $env{'form.embedded_'.$type.'_'.$i} =
10611: &unescape($env{'form.embedded_'.$type.'_'.$i});
10612: }
10613: }
1.661 raeburn 10614: my ($path,$fname) =
10615: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10616: # no path, whole string is fname
10617: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10618: $fname = &Apache::lonnet::clean_filename($fname);
10619: # See if there is anything left
10620: next if ($fname eq '');
10621:
10622: # Check if file already exists as a file or directory.
10623: my ($state,$msg);
10624: if ($context eq 'portfolio') {
10625: my $port_path = $dirpath;
10626: if ($group ne '') {
10627: $port_path = "groups/$group/$port_path";
10628: }
1.987 raeburn 10629: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10630: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10631: $dir_root,$port_path,$disk_quota,
10632: $current_disk_usage,$uname,$udom);
10633: if ($state eq 'will_exceed_quota'
1.984 raeburn 10634: || $state eq 'file_locked') {
1.661 raeburn 10635: $output .= $msg;
10636: next;
10637: }
10638: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10639: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10640: if ($state eq 'exists') {
10641: $output .= $msg;
10642: next;
10643: }
10644: }
10645: # Check if extension is valid
10646: if (($fname =~ /\.(\w+)$/) &&
10647: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 10648: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10649: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10650: next;
10651: } elsif (($fname =~ /\.(\w+)$/) &&
10652: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10653: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10654: next;
10655: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 10656: $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 10657: next;
10658: }
10659: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 10660: my $subdir = $path;
10661: $subdir =~ s{/+$}{};
1.661 raeburn 10662: if ($context eq 'portfolio') {
1.984 raeburn 10663: my $result;
10664: if ($state eq 'existingfile') {
10665: $result=
10666: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 10667: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10668: } else {
1.984 raeburn 10669: $result=
10670: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10671: $dirpath.
1.1075.2.35 raeburn 10672: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10673: if ($result !~ m|^/uploaded/|) {
10674: $output .= '<span class="LC_error">'
10675: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10676: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10677: .'</span><br />';
10678: next;
10679: } else {
1.987 raeburn 10680: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10681: $path.$fname.'</span>').'<br />';
1.984 raeburn 10682: }
1.661 raeburn 10683: }
1.1075.2.35 raeburn 10684: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
10685: my $extendedsubdir = $dirpath.'/'.$subdir;
10686: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10687: my $result =
1.1075.2.35 raeburn 10688: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10689: if ($result !~ m|^/uploaded/|) {
10690: $output .= '<span class="LC_error">'
10691: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10692: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10693: .'</span><br />';
10694: next;
10695: } else {
10696: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10697: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 10698: if ($context eq 'syllabus') {
10699: &Apache::lonnet::make_public_indefinitely($result);
10700: }
1.987 raeburn 10701: }
1.661 raeburn 10702: } else {
10703: # Save the file
10704: my $target = $env{'form.embedded_item_'.$i};
10705: my $fullpath = $dir_root.$dirpath.'/'.$path;
10706: my $dest = $fullpath.$fname;
10707: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10708: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10709: my $count;
10710: my $filepath = $dir_root;
1.1027 raeburn 10711: foreach my $subdir (@parts) {
10712: $filepath .= "/$subdir";
10713: if (!-e $filepath) {
1.661 raeburn 10714: mkdir($filepath,0770);
10715: }
10716: }
10717: my $fh;
10718: if (!open($fh,'>'.$dest)) {
10719: &Apache::lonnet::logthis('Failed to create '.$dest);
10720: $output .= '<span class="LC_error">'.
1.1071 raeburn 10721: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10722: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10723: '</span><br />';
10724: } else {
10725: if (!print $fh $env{'form.embedded_item_'.$i}) {
10726: &Apache::lonnet::logthis('Failed to write to '.$dest);
10727: $output .= '<span class="LC_error">'.
1.1071 raeburn 10728: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10729: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10730: '</span><br />';
10731: } else {
1.987 raeburn 10732: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10733: $url.'</span>').'<br />';
10734: unless ($context eq 'testbank') {
10735: $footer .= &mt('View embedded file: [_1]',
10736: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10737: }
10738: }
10739: close($fh);
10740: }
10741: }
10742: if ($env{'form.embedded_ref_'.$i}) {
10743: $pathchange{$i} = 1;
10744: }
10745: }
10746: if ($output) {
10747: $output = '<p>'.$output.'</p>';
10748: }
10749: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10750: $returnflag = 'ok';
1.1071 raeburn 10751: my $numpathchgs = scalar(keys(%pathchange));
10752: if ($numpathchgs > 0) {
1.987 raeburn 10753: if ($context eq 'portfolio') {
10754: $output .= '<p>'.&mt('or').'</p>';
10755: } elsif ($context eq 'testbank') {
1.1071 raeburn 10756: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10757: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10758: $returnflag = 'modify_orightml';
10759: }
10760: }
1.1071 raeburn 10761: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10762: }
10763:
10764: sub modify_html_form {
10765: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10766: my $end = 0;
10767: my $modifyform;
10768: if ($context eq 'upload_embedded') {
10769: return unless (ref($pathchange) eq 'HASH');
10770: if ($env{'form.number_embedded_items'}) {
10771: $end += $env{'form.number_embedded_items'};
10772: }
10773: if ($env{'form.number_pathchange_items'}) {
10774: $end += $env{'form.number_pathchange_items'};
10775: }
10776: if ($end) {
10777: for (my $i=0; $i<$end; $i++) {
10778: if ($i < $env{'form.number_embedded_items'}) {
10779: next unless($pathchange->{$i});
10780: }
10781: $modifyform .=
10782: &start_data_table_row().
10783: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10784: 'checked="checked" /></td>'.
10785: '<td>'.$env{'form.embedded_ref_'.$i}.
10786: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10787: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10788: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10789: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10790: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10791: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10792: '<td>'.$env{'form.embedded_orig_'.$i}.
10793: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10794: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10795: &end_data_table_row();
1.1071 raeburn 10796: }
1.987 raeburn 10797: }
10798: } else {
10799: $modifyform = $pathchgtable;
10800: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10801: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10802: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10803: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10804: }
10805: }
10806: if ($modifyform) {
1.1071 raeburn 10807: if ($actionurl eq '/adm/dependencies') {
10808: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10809: }
1.987 raeburn 10810: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10811: '<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".
10812: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10813: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10814: '</ol></p>'."\n".'<p>'.
10815: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10816: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10817: &start_data_table()."\n".
10818: &start_data_table_header_row().
10819: '<th>'.&mt('Change?').'</th>'.
10820: '<th>'.&mt('Current reference').'</th>'.
10821: '<th>'.&mt('Required reference').'</th>'.
10822: &end_data_table_header_row()."\n".
10823: $modifyform.
10824: &end_data_table().'<br />'."\n".$hiddenstate.
10825: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10826: '</form>'."\n";
10827: }
10828: return;
10829: }
10830:
10831: sub modify_html_refs {
1.1075.2.35 raeburn 10832: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10833: my $container;
10834: if ($context eq 'portfolio') {
10835: $container = $env{'form.container'};
10836: } elsif ($context eq 'coursedoc') {
10837: $container = $env{'form.primaryurl'};
1.1071 raeburn 10838: } elsif ($context eq 'manage_dependencies') {
10839: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10840: $container = "/$container";
1.1075.2.35 raeburn 10841: } elsif ($context eq 'syllabus') {
10842: $container = $url;
1.987 raeburn 10843: } else {
1.1027 raeburn 10844: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10845: }
10846: my (%allfiles,%codebase,$output,$content);
10847: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 10848: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10849: if (wantarray) {
10850: return ('',0,0);
10851: } else {
10852: return;
10853: }
10854: }
10855: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10856: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10857: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10858: if (wantarray) {
10859: return ('',0,0);
10860: } else {
10861: return;
10862: }
10863: }
1.987 raeburn 10864: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10865: if ($content eq '-1') {
10866: if (wantarray) {
10867: return ('',0,0);
10868: } else {
10869: return;
10870: }
10871: }
1.987 raeburn 10872: } else {
1.1071 raeburn 10873: unless ($container =~ /^\Q$dir_root\E/) {
10874: if (wantarray) {
10875: return ('',0,0);
10876: } else {
10877: return;
10878: }
10879: }
1.987 raeburn 10880: if (open(my $fh,"<$container")) {
10881: $content = join('', <$fh>);
10882: close($fh);
10883: } else {
1.1071 raeburn 10884: if (wantarray) {
10885: return ('',0,0);
10886: } else {
10887: return;
10888: }
1.987 raeburn 10889: }
10890: }
10891: my ($count,$codebasecount) = (0,0);
10892: my $mm = new File::MMagic;
10893: my $mime_type = $mm->checktype_contents($content);
10894: if ($mime_type eq 'text/html') {
10895: my $parse_result =
10896: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10897: \%codebase,\$content);
10898: if ($parse_result eq 'ok') {
10899: foreach my $i (@changes) {
10900: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10901: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10902: if ($allfiles{$ref}) {
10903: my $newname = $orig;
10904: my ($attrib_regexp,$codebase);
1.1006 raeburn 10905: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10906: if ($attrib_regexp =~ /:/) {
10907: $attrib_regexp =~ s/\:/|/g;
10908: }
10909: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10910: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10911: $count += $numchg;
1.1075.2.35 raeburn 10912: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 10913: delete($allfiles{$ref});
1.987 raeburn 10914: }
10915: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10916: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10917: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10918: $codebasecount ++;
10919: }
10920: }
10921: }
1.1075.2.35 raeburn 10922: my $skiprewrites;
1.987 raeburn 10923: if ($count || $codebasecount) {
10924: my $saveresult;
1.1071 raeburn 10925: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10926: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10927: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10928: if ($url eq $container) {
10929: my ($fname) = ($container =~ m{/([^/]+)$});
10930: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10931: $count,'<span class="LC_filename">'.
1.1071 raeburn 10932: $fname.'</span>').'</p>';
1.987 raeburn 10933: } else {
10934: $output = '<p class="LC_error">'.
10935: &mt('Error: update failed for: [_1].',
10936: '<span class="LC_filename">'.
10937: $container.'</span>').'</p>';
10938: }
1.1075.2.35 raeburn 10939: if ($context eq 'syllabus') {
10940: unless ($saveresult eq 'ok') {
10941: $skiprewrites = 1;
10942: }
10943: }
1.987 raeburn 10944: } else {
10945: if (open(my $fh,">$container")) {
10946: print $fh $content;
10947: close($fh);
10948: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10949: $count,'<span class="LC_filename">'.
10950: $container.'</span>').'</p>';
1.661 raeburn 10951: } else {
1.987 raeburn 10952: $output = '<p class="LC_error">'.
10953: &mt('Error: could not update [_1].',
10954: '<span class="LC_filename">'.
10955: $container.'</span>').'</p>';
1.661 raeburn 10956: }
10957: }
10958: }
1.1075.2.35 raeburn 10959: if (($context eq 'syllabus') && (!$skiprewrites)) {
10960: my ($actionurl,$state);
10961: $actionurl = "/public/$udom/$uname/syllabus";
10962: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10963: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10964: \%codebase,
10965: {'context' => 'rewrites',
10966: 'ignore_remote_references' => 1,});
10967: if (ref($mapping) eq 'HASH') {
10968: my $rewrites = 0;
10969: foreach my $key (keys(%{$mapping})) {
10970: next if ($key =~ m{^https?://});
10971: my $ref = $mapping->{$key};
10972: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10973: my $attrib;
10974: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10975: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10976: }
10977: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10978: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10979: $rewrites += $numchg;
10980: }
10981: }
10982: if ($rewrites) {
10983: my $saveresult;
10984: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10985: if ($url eq $container) {
10986: my ($fname) = ($container =~ m{/([^/]+)$});
10987: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10988: $count,'<span class="LC_filename">'.
10989: $fname.'</span>').'</p>';
10990: } else {
10991: $output .= '<p class="LC_error">'.
10992: &mt('Error: could not update links in [_1].',
10993: '<span class="LC_filename">'.
10994: $container.'</span>').'</p>';
10995:
10996: }
10997: }
10998: }
10999: }
1.987 raeburn 11000: } else {
11001: &logthis('Failed to parse '.$container.
11002: ' to modify references: '.$parse_result);
1.661 raeburn 11003: }
11004: }
1.1071 raeburn 11005: if (wantarray) {
11006: return ($output,$count,$codebasecount);
11007: } else {
11008: return $output;
11009: }
1.661 raeburn 11010: }
11011:
11012: sub check_for_existing {
11013: my ($path,$fname,$element) = @_;
11014: my ($state,$msg);
11015: if (-d $path.'/'.$fname) {
11016: $state = 'exists';
11017: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11018: } elsif (-e $path.'/'.$fname) {
11019: $state = 'exists';
11020: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11021: }
11022: if ($state eq 'exists') {
11023: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11024: }
11025: return ($state,$msg);
11026: }
11027:
11028: sub check_for_upload {
11029: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11030: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11031: my $filesize = length($env{'form.'.$element});
11032: if (!$filesize) {
11033: my $msg = '<span class="LC_error">'.
11034: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11035: '<span class="LC_filename">'.$fname.'</span>',
11036: $filesize).'<br />'.
1.1007 raeburn 11037: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11038: '</span>';
11039: return ('zero_bytes',$msg);
11040: }
11041: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11042: my $getpropath = 1;
1.1021 raeburn 11043: my ($dirlistref,$listerror) =
11044: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11045: my $found_file = 0;
11046: my $locked_file = 0;
1.991 raeburn 11047: my @lockers;
11048: my $navmap;
11049: if ($env{'request.course.id'}) {
11050: $navmap = Apache::lonnavmaps::navmap->new();
11051: }
1.1021 raeburn 11052: if (ref($dirlistref) eq 'ARRAY') {
11053: foreach my $line (@{$dirlistref}) {
11054: my ($file_name,$rest)=split(/\&/,$line,2);
11055: if ($file_name eq $fname){
11056: $file_name = $path.$file_name;
11057: if ($group ne '') {
11058: $file_name = $group.$file_name;
11059: }
11060: $found_file = 1;
11061: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11062: foreach my $lock (@lockers) {
11063: if (ref($lock) eq 'ARRAY') {
11064: my ($symb,$crsid) = @{$lock};
11065: if ($crsid eq $env{'request.course.id'}) {
11066: if (ref($navmap)) {
11067: my $res = $navmap->getBySymb($symb);
11068: foreach my $part (@{$res->parts()}) {
11069: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11070: unless (($slot_status == $res->RESERVED) ||
11071: ($slot_status == $res->RESERVED_LOCATION)) {
11072: $locked_file = 1;
11073: }
1.991 raeburn 11074: }
1.1021 raeburn 11075: } else {
11076: $locked_file = 1;
1.991 raeburn 11077: }
11078: } else {
11079: $locked_file = 1;
11080: }
11081: }
1.1021 raeburn 11082: }
11083: } else {
11084: my @info = split(/\&/,$rest);
11085: my $currsize = $info[6]/1000;
11086: if ($currsize < $filesize) {
11087: my $extra = $filesize - $currsize;
11088: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11089: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11090: &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 11091: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11092: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11093: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11094: return ('will_exceed_quota',$msg);
11095: }
1.984 raeburn 11096: }
11097: }
1.661 raeburn 11098: }
11099: }
11100: }
11101: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11102: my $msg = '<p class="LC_warning">'.
11103: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11104: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11105: return ('will_exceed_quota',$msg);
11106: } elsif ($found_file) {
11107: if ($locked_file) {
1.1075.2.69 raeburn 11108: my $msg = '<p class="LC_warning">';
1.661 raeburn 11109: $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 11110: $msg .= '</p>';
1.661 raeburn 11111: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11112: return ('file_locked',$msg);
11113: } else {
1.1075.2.69 raeburn 11114: my $msg = '<p class="LC_error">';
1.984 raeburn 11115: $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 11116: $msg .= '</p>';
1.984 raeburn 11117: return ('existingfile',$msg);
1.661 raeburn 11118: }
11119: }
11120: }
11121:
1.987 raeburn 11122: sub check_for_traversal {
11123: my ($path,$url,$toplevel) = @_;
11124: my @parts=split(/\//,$path);
11125: my $cleanpath;
11126: my $fullpath = $url;
11127: for (my $i=0;$i<@parts;$i++) {
11128: next if ($parts[$i] eq '.');
11129: if ($parts[$i] eq '..') {
11130: $fullpath =~ s{([^/]+/)$}{};
11131: } else {
11132: $fullpath .= $parts[$i].'/';
11133: }
11134: }
11135: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11136: $cleanpath = $1;
11137: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11138: my $curr_toprel = $1;
11139: my @parts = split(/\//,$curr_toprel);
11140: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11141: my @urlparts = split(/\//,$url_toprel);
11142: my $doubledots;
11143: my $startdiff = -1;
11144: for (my $i=0; $i<@urlparts; $i++) {
11145: if ($startdiff == -1) {
11146: unless ($urlparts[$i] eq $parts[$i]) {
11147: $startdiff = $i;
11148: $doubledots .= '../';
11149: }
11150: } else {
11151: $doubledots .= '../';
11152: }
11153: }
11154: if ($startdiff > -1) {
11155: $cleanpath = $doubledots;
11156: for (my $i=$startdiff; $i<@parts; $i++) {
11157: $cleanpath .= $parts[$i].'/';
11158: }
11159: }
11160: }
11161: $cleanpath =~ s{(/)$}{};
11162: return $cleanpath;
11163: }
1.31 albertel 11164:
1.1053 raeburn 11165: sub is_archive_file {
11166: my ($mimetype) = @_;
11167: if (($mimetype eq 'application/octet-stream') ||
11168: ($mimetype eq 'application/x-stuffit') ||
11169: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11170: return 1;
11171: }
11172: return;
11173: }
11174:
11175: sub decompress_form {
1.1065 raeburn 11176: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11177: my %lt = &Apache::lonlocal::texthash (
11178: this => 'This file is an archive file.',
1.1067 raeburn 11179: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11180: itsc => 'Its contents are as follows:',
1.1053 raeburn 11181: youm => 'You may wish to extract its contents.',
11182: extr => 'Extract contents',
1.1067 raeburn 11183: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11184: proa => 'Process automatically?',
1.1053 raeburn 11185: yes => 'Yes',
11186: no => 'No',
1.1067 raeburn 11187: fold => 'Title for folder containing movie',
11188: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11189: );
1.1065 raeburn 11190: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11191: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11192: my $info = &list_archive_contents($fileloc,\@paths);
11193: if (@paths) {
11194: foreach my $path (@paths) {
11195: $path =~ s{^/}{};
1.1067 raeburn 11196: if ($path =~ m{^([^/]+)/$}) {
11197: $topdir = $1;
11198: }
1.1065 raeburn 11199: if ($path =~ m{^([^/]+)/}) {
11200: $toplevel{$1} = $path;
11201: } else {
11202: $toplevel{$path} = $path;
11203: }
11204: }
11205: }
1.1067 raeburn 11206: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11207: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11208: "$topdir/media/",
11209: "$topdir/media/$topdir.mp4",
11210: "$topdir/media/FirstFrame.png",
11211: "$topdir/media/player.swf",
11212: "$topdir/media/swfobject.js",
11213: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 11214: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 11215: "$topdir/$topdir.mp4",
11216: "$topdir/$topdir\_config.xml",
11217: "$topdir/$topdir\_controller.swf",
11218: "$topdir/$topdir\_embed.css",
11219: "$topdir/$topdir\_First_Frame.png",
11220: "$topdir/$topdir\_player.html",
11221: "$topdir/$topdir\_Thumbnails.png",
11222: "$topdir/playerProductInstall.swf",
11223: "$topdir/scripts/",
11224: "$topdir/scripts/config_xml.js",
11225: "$topdir/scripts/handlebars.js",
11226: "$topdir/scripts/jquery-1.7.1.min.js",
11227: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11228: "$topdir/scripts/modernizr.js",
11229: "$topdir/scripts/player-min.js",
11230: "$topdir/scripts/swfobject.js",
11231: "$topdir/skins/",
11232: "$topdir/skins/configuration_express.xml",
11233: "$topdir/skins/express_show/",
11234: "$topdir/skins/express_show/player-min.css",
11235: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 11236: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11237: "$topdir/$topdir.mp4",
11238: "$topdir/$topdir\_config.xml",
11239: "$topdir/$topdir\_controller.swf",
11240: "$topdir/$topdir\_embed.css",
11241: "$topdir/$topdir\_First_Frame.png",
11242: "$topdir/$topdir\_player.html",
11243: "$topdir/$topdir\_Thumbnails.png",
11244: "$topdir/playerProductInstall.swf",
11245: "$topdir/scripts/",
11246: "$topdir/scripts/config_xml.js",
11247: "$topdir/scripts/techsmith-smart-player.min.js",
11248: "$topdir/skins/",
11249: "$topdir/skins/configuration_express.xml",
11250: "$topdir/skins/express_show/",
11251: "$topdir/skins/express_show/spritesheet.min.css",
11252: "$topdir/skins/express_show/spritesheet.png",
11253: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 11254: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11255: if (@diffs == 0) {
1.1075.2.59 raeburn 11256: $is_camtasia = 6;
11257: } else {
1.1075.2.81 raeburn 11258: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 11259: if (@diffs == 0) {
11260: $is_camtasia = 8;
1.1075.2.81 raeburn 11261: } else {
11262: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11263: if (@diffs == 0) {
11264: $is_camtasia = 8;
11265: }
1.1075.2.59 raeburn 11266: }
1.1067 raeburn 11267: }
11268: }
11269: my $output;
11270: if ($is_camtasia) {
11271: $output = <<"ENDCAM";
11272: <script type="text/javascript" language="Javascript">
11273: // <![CDATA[
11274:
11275: function camtasiaToggle() {
11276: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11277: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11278: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11279: document.getElementById('camtasia_titles').style.display='block';
11280: } else {
11281: document.getElementById('camtasia_titles').style.display='none';
11282: }
11283: }
11284: }
11285: return;
11286: }
11287:
11288: // ]]>
11289: </script>
11290: <p>$lt{'camt'}</p>
11291: ENDCAM
1.1065 raeburn 11292: } else {
1.1067 raeburn 11293: $output = '<p>'.$lt{'this'};
11294: if ($info eq '') {
11295: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11296: } else {
11297: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11298: '<div><pre>'.$info.'</pre></div>';
11299: }
1.1065 raeburn 11300: }
1.1067 raeburn 11301: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11302: my $duplicates;
11303: my $num = 0;
11304: if (ref($dirlist) eq 'ARRAY') {
11305: foreach my $item (@{$dirlist}) {
11306: if (ref($item) eq 'ARRAY') {
11307: if (exists($toplevel{$item->[0]})) {
11308: $duplicates .=
11309: &start_data_table_row().
11310: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11311: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11312: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11313: 'value="1" />'.&mt('Yes').'</label>'.
11314: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11315: '<td>'.$item->[0].'</td>';
11316: if ($item->[2]) {
11317: $duplicates .= '<td>'.&mt('Directory').'</td>';
11318: } else {
11319: $duplicates .= '<td>'.&mt('File').'</td>';
11320: }
11321: $duplicates .= '<td>'.$item->[3].'</td>'.
11322: '<td>'.
11323: &Apache::lonlocal::locallocaltime($item->[4]).
11324: '</td>'.
11325: &end_data_table_row();
11326: $num ++;
11327: }
11328: }
11329: }
11330: }
11331: my $itemcount;
11332: if (@paths > 0) {
11333: $itemcount = scalar(@paths);
11334: } else {
11335: $itemcount = 1;
11336: }
1.1067 raeburn 11337: if ($is_camtasia) {
11338: $output .= $lt{'auto'}.'<br />'.
11339: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 11340: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11341: $lt{'yes'}.'</label> <label>'.
11342: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11343: $lt{'no'}.'</label></span><br />'.
11344: '<div id="camtasia_titles" style="display:block">'.
11345: &Apache::lonhtmlcommon::start_pick_box().
11346: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11347: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11348: &Apache::lonhtmlcommon::row_closure().
11349: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11350: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11351: &Apache::lonhtmlcommon::row_closure(1).
11352: &Apache::lonhtmlcommon::end_pick_box().
11353: '</div>';
11354: }
1.1065 raeburn 11355: $output .=
11356: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11357: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11358: "\n";
1.1065 raeburn 11359: if ($duplicates ne '') {
11360: $output .= '<p><span class="LC_warning">'.
11361: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11362: &start_data_table().
11363: &start_data_table_header_row().
11364: '<th>'.&mt('Overwrite?').'</th>'.
11365: '<th>'.&mt('Name').'</th>'.
11366: '<th>'.&mt('Type').'</th>'.
11367: '<th>'.&mt('Size').'</th>'.
11368: '<th>'.&mt('Last modified').'</th>'.
11369: &end_data_table_header_row().
11370: $duplicates.
11371: &end_data_table().
11372: '</p>';
11373: }
1.1067 raeburn 11374: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11375: if (ref($hiddenelements) eq 'HASH') {
11376: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11377: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11378: }
11379: }
11380: $output .= <<"END";
1.1067 raeburn 11381: <br />
1.1053 raeburn 11382: <input type="submit" name="decompress" value="$lt{'extr'}" />
11383: </form>
11384: $noextract
11385: END
11386: return $output;
11387: }
11388:
1.1065 raeburn 11389: sub decompression_utility {
11390: my ($program) = @_;
11391: my @utilities = ('tar','gunzip','bunzip2','unzip');
11392: my $location;
11393: if (grep(/^\Q$program\E$/,@utilities)) {
11394: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11395: '/usr/sbin/') {
11396: if (-x $dir.$program) {
11397: $location = $dir.$program;
11398: last;
11399: }
11400: }
11401: }
11402: return $location;
11403: }
11404:
11405: sub list_archive_contents {
11406: my ($file,$pathsref) = @_;
11407: my (@cmd,$output);
11408: my $needsregexp;
11409: if ($file =~ /\.zip$/) {
11410: @cmd = (&decompression_utility('unzip'),"-l");
11411: $needsregexp = 1;
11412: } elsif (($file =~ m/\.tar\.gz$/) ||
11413: ($file =~ /\.tgz$/)) {
11414: @cmd = (&decompression_utility('tar'),"-ztf");
11415: } elsif ($file =~ /\.tar\.bz2$/) {
11416: @cmd = (&decompression_utility('tar'),"-jtf");
11417: } elsif ($file =~ m|\.tar$|) {
11418: @cmd = (&decompression_utility('tar'),"-tf");
11419: }
11420: if (@cmd) {
11421: undef($!);
11422: undef($@);
11423: if (open(my $fh,"-|", @cmd, $file)) {
11424: while (my $line = <$fh>) {
11425: $output .= $line;
11426: chomp($line);
11427: my $item;
11428: if ($needsregexp) {
11429: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11430: } else {
11431: $item = $line;
11432: }
11433: if ($item ne '') {
11434: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11435: push(@{$pathsref},$item);
11436: }
11437: }
11438: }
11439: close($fh);
11440: }
11441: }
11442: return $output;
11443: }
11444:
1.1053 raeburn 11445: sub decompress_uploaded_file {
11446: my ($file,$dir) = @_;
11447: &Apache::lonnet::appenv({'cgi.file' => $file});
11448: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11449: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11450: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11451: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11452: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11453: my $decompressed = $env{'cgi.decompressed'};
11454: &Apache::lonnet::delenv('cgi.file');
11455: &Apache::lonnet::delenv('cgi.dir');
11456: &Apache::lonnet::delenv('cgi.decompressed');
11457: return ($decompressed,$result);
11458: }
11459:
1.1055 raeburn 11460: sub process_decompression {
11461: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11462: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 11463: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 11464: $error = &mt('Filename not a supported archive file type.').
11465: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11466: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11467: } else {
11468: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11469: if ($docuhome eq 'no_host') {
11470: $error = &mt('Could not determine home server for course.');
11471: } else {
11472: my @ids=&Apache::lonnet::current_machine_ids();
11473: my $currdir = "$dir_root/$destination";
11474: if (grep(/^\Q$docuhome\E$/,@ids)) {
11475: $dir = &LONCAPA::propath($docudom,$docuname).
11476: "$dir_root/$destination";
11477: } else {
11478: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11479: "$dir_root/$docudom/$docuname/$destination";
11480: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11481: $error = &mt('Archive file not found.');
11482: }
11483: }
1.1065 raeburn 11484: my (@to_overwrite,@to_skip);
11485: if ($env{'form.archive_overwrite_total'} > 0) {
11486: my $total = $env{'form.archive_overwrite_total'};
11487: for (my $i=0; $i<$total; $i++) {
11488: if ($env{'form.archive_overwrite_'.$i} == 1) {
11489: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11490: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11491: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11492: }
11493: }
11494: }
11495: my $numskip = scalar(@to_skip);
11496: if (($numskip > 0) &&
11497: ($numskip == $env{'form.archive_itemcount'})) {
11498: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11499: } elsif ($dir eq '') {
1.1055 raeburn 11500: $error = &mt('Directory containing archive file unavailable.');
11501: } elsif (!$error) {
1.1065 raeburn 11502: my ($decompressed,$display);
11503: if ($numskip > 0) {
11504: my $tempdir = time.'_'.$$.int(rand(10000));
11505: mkdir("$dir/$tempdir",0755);
11506: system("mv $dir/$file $dir/$tempdir/$file");
11507: ($decompressed,$display) =
11508: &decompress_uploaded_file($file,"$dir/$tempdir");
11509: foreach my $item (@to_skip) {
11510: if (($item ne '') && ($item !~ /\.\./)) {
11511: if (-f "$dir/$tempdir/$item") {
11512: unlink("$dir/$tempdir/$item");
11513: } elsif (-d "$dir/$tempdir/$item") {
11514: system("rm -rf $dir/$tempdir/$item");
11515: }
11516: }
11517: }
11518: system("mv $dir/$tempdir/* $dir");
11519: rmdir("$dir/$tempdir");
11520: } else {
11521: ($decompressed,$display) =
11522: &decompress_uploaded_file($file,$dir);
11523: }
1.1055 raeburn 11524: if ($decompressed eq 'ok') {
1.1065 raeburn 11525: $output = '<p class="LC_info">'.
11526: &mt('Files extracted successfully from archive.').
11527: '</p>'."\n";
1.1055 raeburn 11528: my ($warning,$result,@contents);
11529: my ($newdirlistref,$newlisterror) =
11530: &Apache::lonnet::dirlist($currdir,$docudom,
11531: $docuname,1);
11532: my (%is_dir,%changes,@newitems);
11533: my $dirptr = 16384;
1.1065 raeburn 11534: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11535: foreach my $dir_line (@{$newdirlistref}) {
11536: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11537: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11538: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11539: push(@newitems,$item);
11540: if ($dirptr&$testdir) {
11541: $is_dir{$item} = 1;
11542: }
11543: $changes{$item} = 1;
11544: }
11545: }
11546: }
11547: if (keys(%changes) > 0) {
11548: foreach my $item (sort(@newitems)) {
11549: if ($changes{$item}) {
11550: push(@contents,$item);
11551: }
11552: }
11553: }
11554: if (@contents > 0) {
1.1067 raeburn 11555: my $wantform;
11556: unless ($env{'form.autoextract_camtasia'}) {
11557: $wantform = 1;
11558: }
1.1056 raeburn 11559: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11560: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11561: $currdir,\%is_dir,
11562: \%children,\%parent,
1.1056 raeburn 11563: \@contents,\%dirorder,
11564: \%titles,$wantform);
1.1055 raeburn 11565: if ($datatable ne '') {
11566: $output .= &archive_options_form('decompressed',$datatable,
11567: $count,$hiddenelem);
1.1065 raeburn 11568: my $startcount = 6;
1.1055 raeburn 11569: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11570: \%titles,\%children);
1.1055 raeburn 11571: }
1.1067 raeburn 11572: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 11573: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 11574: my %displayed;
11575: my $total = 1;
11576: $env{'form.archive_directory'} = [];
11577: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11578: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11579: $path =~ s{/$}{};
11580: my $item;
11581: if ($path ne '') {
11582: $item = "$path/$titles{$i}";
11583: } else {
11584: $item = $titles{$i};
11585: }
11586: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11587: if ($item eq $contents[0]) {
11588: push(@{$env{'form.archive_directory'}},$i);
11589: $env{'form.archive_'.$i} = 'display';
11590: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11591: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 11592: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
11593: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 11594: $env{'form.archive_'.$i} = 'display';
11595: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11596: $displayed{'web'} = $i;
11597: } else {
1.1075.2.59 raeburn 11598: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
11599: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
11600: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 11601: push(@{$env{'form.archive_directory'}},$i);
11602: }
11603: $env{'form.archive_'.$i} = 'dependency';
11604: }
11605: $total ++;
11606: }
11607: for (my $i=1; $i<$total; $i++) {
11608: next if ($i == $displayed{'web'});
11609: next if ($i == $displayed{'folder'});
11610: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11611: }
11612: $env{'form.phase'} = 'decompress_cleanup';
11613: $env{'form.archivedelete'} = 1;
11614: $env{'form.archive_count'} = $total-1;
11615: $output .=
11616: &process_extracted_files('coursedocs',$docudom,
11617: $docuname,$destination,
11618: $dir_root,$hiddenelem);
11619: }
1.1055 raeburn 11620: } else {
11621: $warning = &mt('No new items extracted from archive file.');
11622: }
11623: } else {
11624: $output = $display;
11625: $error = &mt('An error occurred during extraction from the archive file.');
11626: }
11627: }
11628: }
11629: }
11630: if ($error) {
11631: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11632: $error.'</p>'."\n";
11633: }
11634: if ($warning) {
11635: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11636: }
11637: return $output;
11638: }
11639:
11640: sub get_extracted {
1.1056 raeburn 11641: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11642: $titles,$wantform) = @_;
1.1055 raeburn 11643: my $count = 0;
11644: my $depth = 0;
11645: my $datatable;
1.1056 raeburn 11646: my @hierarchy;
1.1055 raeburn 11647: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11648: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11649: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11650: foreach my $item (@{$contents}) {
11651: $count ++;
1.1056 raeburn 11652: @{$dirorder->{$count}} = @hierarchy;
11653: $titles->{$count} = $item;
1.1055 raeburn 11654: &archive_hierarchy($depth,$count,$parent,$children);
11655: if ($wantform) {
11656: $datatable .= &archive_row($is_dir->{$item},$item,
11657: $currdir,$depth,$count);
11658: }
11659: if ($is_dir->{$item}) {
11660: $depth ++;
1.1056 raeburn 11661: push(@hierarchy,$count);
11662: $parent->{$depth} = $count;
1.1055 raeburn 11663: $datatable .=
11664: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11665: \$depth,\$count,\@hierarchy,$dirorder,
11666: $children,$parent,$titles,$wantform);
1.1055 raeburn 11667: $depth --;
1.1056 raeburn 11668: pop(@hierarchy);
1.1055 raeburn 11669: }
11670: }
11671: return ($count,$datatable);
11672: }
11673:
11674: sub recurse_extracted_archive {
1.1056 raeburn 11675: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11676: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11677: my $result='';
1.1056 raeburn 11678: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11679: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11680: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11681: return $result;
11682: }
11683: my $dirptr = 16384;
11684: my ($newdirlistref,$newlisterror) =
11685: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11686: if (ref($newdirlistref) eq 'ARRAY') {
11687: foreach my $dir_line (@{$newdirlistref}) {
11688: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11689: unless ($item =~ /^\.+$/) {
11690: $$count ++;
1.1056 raeburn 11691: @{$dirorder->{$$count}} = @{$hierarchy};
11692: $titles->{$$count} = $item;
1.1055 raeburn 11693: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11694:
1.1055 raeburn 11695: my $is_dir;
11696: if ($dirptr&$testdir) {
11697: $is_dir = 1;
11698: }
11699: if ($wantform) {
11700: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11701: }
11702: if ($is_dir) {
11703: $$depth ++;
1.1056 raeburn 11704: push(@{$hierarchy},$$count);
11705: $parent->{$$depth} = $$count;
1.1055 raeburn 11706: $result .=
11707: &recurse_extracted_archive("$currdir/$item",$docudom,
11708: $docuname,$depth,$count,
1.1056 raeburn 11709: $hierarchy,$dirorder,$children,
11710: $parent,$titles,$wantform);
1.1055 raeburn 11711: $$depth --;
1.1056 raeburn 11712: pop(@{$hierarchy});
1.1055 raeburn 11713: }
11714: }
11715: }
11716: }
11717: return $result;
11718: }
11719:
11720: sub archive_hierarchy {
11721: my ($depth,$count,$parent,$children) =@_;
11722: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11723: if (exists($parent->{$depth})) {
11724: $children->{$parent->{$depth}} .= $count.':';
11725: }
11726: }
11727: return;
11728: }
11729:
11730: sub archive_row {
11731: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11732: my ($name) = ($item =~ m{([^/]+)$});
11733: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11734: 'display' => 'Add as file',
1.1055 raeburn 11735: 'dependency' => 'Include as dependency',
11736: 'discard' => 'Discard',
11737: );
11738: if ($is_dir) {
1.1059 raeburn 11739: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11740: }
1.1056 raeburn 11741: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11742: my $offset = 0;
1.1055 raeburn 11743: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11744: $offset ++;
1.1065 raeburn 11745: if ($action ne 'display') {
11746: $offset ++;
11747: }
1.1055 raeburn 11748: $output .= '<td><span class="LC_nobreak">'.
11749: '<label><input type="radio" name="archive_'.$count.
11750: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11751: my $text = $choices{$action};
11752: if ($is_dir) {
11753: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11754: if ($action eq 'display') {
1.1059 raeburn 11755: $text = &mt('Add as folder');
1.1055 raeburn 11756: }
1.1056 raeburn 11757: } else {
11758: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11759:
11760: }
11761: $output .= ' /> '.$choices{$action}.'</label></span>';
11762: if ($action eq 'dependency') {
11763: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11764: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11765: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11766: '<option value=""></option>'."\n".
11767: '</select>'."\n".
11768: '</div>';
1.1059 raeburn 11769: } elsif ($action eq 'display') {
11770: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11771: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11772: '</div>';
1.1055 raeburn 11773: }
1.1056 raeburn 11774: $output .= '</td>';
1.1055 raeburn 11775: }
11776: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11777: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11778: for (my $i=0; $i<$depth; $i++) {
11779: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11780: }
11781: if ($is_dir) {
11782: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11783: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11784: } else {
11785: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11786: }
11787: $output .= ' '.$name.'</td>'."\n".
11788: &end_data_table_row();
11789: return $output;
11790: }
11791:
11792: sub archive_options_form {
1.1065 raeburn 11793: my ($form,$display,$count,$hiddenelem) = @_;
11794: my %lt = &Apache::lonlocal::texthash(
11795: perm => 'Permanently remove archive file?',
11796: hows => 'How should each extracted item be incorporated in the course?',
11797: cont => 'Content actions for all',
11798: addf => 'Add as folder/file',
11799: incd => 'Include as dependency for a displayed file',
11800: disc => 'Discard',
11801: no => 'No',
11802: yes => 'Yes',
11803: save => 'Save',
11804: );
11805: my $output = <<"END";
11806: <form name="$form" method="post" action="">
11807: <p><span class="LC_nobreak">$lt{'perm'}
11808: <label>
11809: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11810: </label>
11811:
11812: <label>
11813: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11814: </span>
11815: </p>
11816: <input type="hidden" name="phase" value="decompress_cleanup" />
11817: <br />$lt{'hows'}
11818: <div class="LC_columnSection">
11819: <fieldset>
11820: <legend>$lt{'cont'}</legend>
11821: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11822: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11823: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11824: </fieldset>
11825: </div>
11826: END
11827: return $output.
1.1055 raeburn 11828: &start_data_table()."\n".
1.1065 raeburn 11829: $display."\n".
1.1055 raeburn 11830: &end_data_table()."\n".
11831: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11832: $hiddenelem.
1.1065 raeburn 11833: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11834: '</form>';
11835: }
11836:
11837: sub archive_javascript {
1.1056 raeburn 11838: my ($startcount,$numitems,$titles,$children) = @_;
11839: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11840: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11841: my $scripttag = <<START;
11842: <script type="text/javascript">
11843: // <![CDATA[
11844:
11845: function checkAll(form,prefix) {
11846: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11847: for (var i=0; i < form.elements.length; i++) {
11848: var id = form.elements[i].id;
11849: if ((id != '') && (id != undefined)) {
11850: if (idstr.test(id)) {
11851: if (form.elements[i].type == 'radio') {
11852: form.elements[i].checked = true;
1.1056 raeburn 11853: var nostart = i-$startcount;
1.1059 raeburn 11854: var offset = nostart%7;
11855: var count = (nostart-offset)/7;
1.1056 raeburn 11856: dependencyCheck(form,count,offset);
1.1055 raeburn 11857: }
11858: }
11859: }
11860: }
11861: }
11862:
11863: function propagateCheck(form,count) {
11864: if (count > 0) {
1.1059 raeburn 11865: var startelement = $startcount + ((count-1) * 7);
11866: for (var j=1; j<6; j++) {
11867: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11868: var item = startelement + j;
11869: if (form.elements[item].type == 'radio') {
11870: if (form.elements[item].checked) {
11871: containerCheck(form,count,j);
11872: break;
11873: }
1.1055 raeburn 11874: }
11875: }
11876: }
11877: }
11878: }
11879:
11880: numitems = $numitems
1.1056 raeburn 11881: var titles = new Array(numitems);
11882: var parents = new Array(numitems);
1.1055 raeburn 11883: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11884: parents[i] = new Array;
1.1055 raeburn 11885: }
1.1059 raeburn 11886: var maintitle = '$maintitle';
1.1055 raeburn 11887:
11888: START
11889:
1.1056 raeburn 11890: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11891: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11892: for (my $i=0; $i<@contents; $i ++) {
11893: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11894: }
11895: }
11896:
1.1056 raeburn 11897: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11898: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11899: }
11900:
1.1055 raeburn 11901: $scripttag .= <<END;
11902:
11903: function containerCheck(form,count,offset) {
11904: if (count > 0) {
1.1056 raeburn 11905: dependencyCheck(form,count,offset);
1.1059 raeburn 11906: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11907: form.elements[item].checked = true;
11908: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11909: if (parents[count].length > 0) {
11910: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11911: containerCheck(form,parents[count][j],offset);
11912: }
11913: }
11914: }
11915: }
11916: }
11917:
11918: function dependencyCheck(form,count,offset) {
11919: if (count > 0) {
1.1059 raeburn 11920: var chosen = (offset+$startcount)+7*(count-1);
11921: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11922: var currtype = form.elements[depitem].type;
11923: if (form.elements[chosen].value == 'dependency') {
11924: document.getElementById('arc_depon_'+count).style.display='block';
11925: form.elements[depitem].options.length = 0;
11926: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 11927: for (var i=1; i<=numitems; i++) {
11928: if (i == count) {
11929: continue;
11930: }
1.1059 raeburn 11931: var startelement = $startcount + (i-1) * 7;
11932: for (var j=1; j<6; j++) {
11933: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11934: var item = startelement + j;
11935: if (form.elements[item].type == 'radio') {
11936: if (form.elements[item].checked) {
11937: if (form.elements[item].value == 'display') {
11938: var n = form.elements[depitem].options.length;
11939: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11940: }
11941: }
11942: }
11943: }
11944: }
11945: }
11946: } else {
11947: document.getElementById('arc_depon_'+count).style.display='none';
11948: form.elements[depitem].options.length = 0;
11949: form.elements[depitem].options[0] = new Option('Select','',true,true);
11950: }
1.1059 raeburn 11951: titleCheck(form,count,offset);
1.1056 raeburn 11952: }
11953: }
11954:
11955: function propagateSelect(form,count,offset) {
11956: if (count > 0) {
1.1065 raeburn 11957: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11958: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11959: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11960: if (parents[count].length > 0) {
11961: for (var j=0; j<parents[count].length; j++) {
11962: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11963: }
11964: }
11965: }
11966: }
11967: }
1.1056 raeburn 11968:
11969: function containerSelect(form,count,offset,picked) {
11970: if (count > 0) {
1.1065 raeburn 11971: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11972: if (form.elements[item].type == 'radio') {
11973: if (form.elements[item].value == 'dependency') {
11974: if (form.elements[item+1].type == 'select-one') {
11975: for (var i=0; i<form.elements[item+1].options.length; i++) {
11976: if (form.elements[item+1].options[i].value == picked) {
11977: form.elements[item+1].selectedIndex = i;
11978: break;
11979: }
11980: }
11981: }
11982: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11983: if (parents[count].length > 0) {
11984: for (var j=0; j<parents[count].length; j++) {
11985: containerSelect(form,parents[count][j],offset,picked);
11986: }
11987: }
11988: }
11989: }
11990: }
11991: }
11992: }
11993:
1.1059 raeburn 11994: function titleCheck(form,count,offset) {
11995: if (count > 0) {
11996: var chosen = (offset+$startcount)+7*(count-1);
11997: var depitem = $startcount + ((count-1) * 7) + 2;
11998: var currtype = form.elements[depitem].type;
11999: if (form.elements[chosen].value == 'display') {
12000: document.getElementById('arc_title_'+count).style.display='block';
12001: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12002: document.getElementById('archive_title_'+count).value=maintitle;
12003: }
12004: } else {
12005: document.getElementById('arc_title_'+count).style.display='none';
12006: if (currtype == 'text') {
12007: document.getElementById('archive_title_'+count).value='';
12008: }
12009: }
12010: }
12011: return;
12012: }
12013:
1.1055 raeburn 12014: // ]]>
12015: </script>
12016: END
12017: return $scripttag;
12018: }
12019:
12020: sub process_extracted_files {
1.1067 raeburn 12021: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12022: my $numitems = $env{'form.archive_count'};
12023: return unless ($numitems);
12024: my @ids=&Apache::lonnet::current_machine_ids();
12025: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12026: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12027: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12028: if (grep(/^\Q$docuhome\E$/,@ids)) {
12029: $prefix = &LONCAPA::propath($docudom,$docuname);
12030: $pathtocheck = "$dir_root/$destination";
12031: $dir = $dir_root;
12032: $ishome = 1;
12033: } else {
12034: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12035: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
12036: $dir = "$dir_root/$docudom/$docuname";
12037: }
12038: my $currdir = "$dir_root/$destination";
12039: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12040: if ($env{'form.folderpath'}) {
12041: my @items = split('&',$env{'form.folderpath'});
12042: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12043: if ($env{'form.folderpath'} =~ /\:1$/) {
12044: $containers{'0'}='page';
12045: } else {
12046: $containers{'0'}='sequence';
12047: }
1.1055 raeburn 12048: }
12049: my @archdirs = &get_env_multiple('form.archive_directory');
12050: if ($numitems) {
12051: for (my $i=1; $i<=$numitems; $i++) {
12052: my $path = $env{'form.archive_content_'.$i};
12053: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12054: my $item = $1;
12055: $toplevelitems{$item} = $i;
12056: if (grep(/^\Q$i\E$/,@archdirs)) {
12057: $is_dir{$item} = 1;
12058: }
12059: }
12060: }
12061: }
1.1067 raeburn 12062: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12063: if (keys(%toplevelitems) > 0) {
12064: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12065: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12066: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12067: }
1.1066 raeburn 12068: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12069: if ($numitems) {
12070: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12071: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12072: my $path = $env{'form.archive_content_'.$i};
12073: if ($path =~ /^\Q$pathtocheck\E/) {
12074: if ($env{'form.archive_'.$i} eq 'discard') {
12075: if ($prefix ne '' && $path ne '') {
12076: if (-e $prefix.$path) {
1.1066 raeburn 12077: if ((@archdirs > 0) &&
12078: (grep(/^\Q$i\E$/,@archdirs))) {
12079: $todeletedir{$prefix.$path} = 1;
12080: } else {
12081: $todelete{$prefix.$path} = 1;
12082: }
1.1055 raeburn 12083: }
12084: }
12085: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12086: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12087: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12088: $docstitle = $env{'form.archive_title_'.$i};
12089: if ($docstitle eq '') {
12090: $docstitle = $title;
12091: }
1.1055 raeburn 12092: $outer = 0;
1.1056 raeburn 12093: if (ref($dirorder{$i}) eq 'ARRAY') {
12094: if (@{$dirorder{$i}} > 0) {
12095: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12096: if ($env{'form.archive_'.$item} eq 'display') {
12097: $outer = $item;
12098: last;
12099: }
12100: }
12101: }
12102: }
12103: my ($errtext,$fatal) =
12104: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12105: '/'.$folders{$outer}.'.'.
12106: $containers{$outer});
12107: next if ($fatal);
12108: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12109: if ($context eq 'coursedocs') {
1.1056 raeburn 12110: $mapinner{$i} = time;
1.1055 raeburn 12111: $folders{$i} = 'default_'.$mapinner{$i};
12112: $containers{$i} = 'sequence';
12113: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12114: $folders{$i}.'.'.$containers{$i};
12115: my $newidx = &LONCAPA::map::getresidx();
12116: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12117: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12118: push(@LONCAPA::map::order,$newidx);
12119: my ($outtext,$errtext) =
12120: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12121: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12122: '.'.$containers{$outer},1,1);
1.1056 raeburn 12123: $newseqid{$i} = $newidx;
1.1067 raeburn 12124: unless ($errtext) {
12125: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
12126: }
1.1055 raeburn 12127: }
12128: } else {
12129: if ($context eq 'coursedocs') {
12130: my $newidx=&LONCAPA::map::getresidx();
12131: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12132: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12133: $title;
12134: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12135: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
12136: }
12137: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12138: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12139: }
12140: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12141: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 12142: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 12143: unless ($ishome) {
12144: my $fetch = "$newdest{$i}/$title";
12145: $fetch =~ s/^\Q$prefix$dir\E//;
12146: $prompttofetch{$fetch} = 1;
12147: }
1.1055 raeburn 12148: }
12149: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12150: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12151: push(@LONCAPA::map::order, $newidx);
12152: my ($outtext,$errtext)=
12153: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12154: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12155: '.'.$containers{$outer},1,1);
1.1067 raeburn 12156: unless ($errtext) {
12157: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12158: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
12159: }
12160: }
1.1055 raeburn 12161: }
12162: }
1.1075.2.11 raeburn 12163: }
12164: } else {
12165: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12166: }
12167: }
12168: for (my $i=1; $i<=$numitems; $i++) {
12169: next unless ($env{'form.archive_'.$i} eq 'dependency');
12170: my $path = $env{'form.archive_content_'.$i};
12171: if ($path =~ /^\Q$pathtocheck\E/) {
12172: my ($title) = ($path =~ m{/([^/]+)$});
12173: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12174: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12175: if (ref($dirorder{$i}) eq 'ARRAY') {
12176: my ($itemidx,$fullpath,$relpath);
12177: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12178: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12179: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12180: if ($dirorder{$i}->[$j] eq $container) {
12181: $itemidx = $j;
1.1056 raeburn 12182: }
12183: }
1.1075.2.11 raeburn 12184: }
12185: if ($itemidx eq '') {
12186: $itemidx = 0;
12187: }
12188: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12189: if ($mapinner{$referrer{$i}}) {
12190: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12191: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12192: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12193: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12194: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12195: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12196: if (!-e $fullpath) {
12197: mkdir($fullpath,0755);
1.1056 raeburn 12198: }
12199: }
1.1075.2.11 raeburn 12200: } else {
12201: last;
1.1056 raeburn 12202: }
1.1075.2.11 raeburn 12203: }
12204: }
12205: } elsif ($newdest{$referrer{$i}}) {
12206: $fullpath = $newdest{$referrer{$i}};
12207: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12208: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12209: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12210: last;
12211: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12212: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12213: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12214: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12215: if (!-e $fullpath) {
12216: mkdir($fullpath,0755);
1.1056 raeburn 12217: }
12218: }
1.1075.2.11 raeburn 12219: } else {
12220: last;
1.1056 raeburn 12221: }
1.1075.2.11 raeburn 12222: }
12223: }
12224: if ($fullpath ne '') {
12225: if (-e "$prefix$path") {
12226: system("mv $prefix$path $fullpath/$title");
12227: }
12228: if (-e "$fullpath/$title") {
12229: my $showpath;
12230: if ($relpath ne '') {
12231: $showpath = "$relpath/$title";
12232: } else {
12233: $showpath = "/$title";
1.1056 raeburn 12234: }
1.1075.2.11 raeburn 12235: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12236: }
12237: unless ($ishome) {
12238: my $fetch = "$fullpath/$title";
12239: $fetch =~ s/^\Q$prefix$dir\E//;
12240: $prompttofetch{$fetch} = 1;
1.1055 raeburn 12241: }
12242: }
12243: }
1.1075.2.11 raeburn 12244: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12245: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12246: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12247: }
12248: } else {
1.1075.2.11 raeburn 12249: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 12250: }
12251: }
12252: if (keys(%todelete)) {
12253: foreach my $key (keys(%todelete)) {
12254: unlink($key);
1.1066 raeburn 12255: }
12256: }
12257: if (keys(%todeletedir)) {
12258: foreach my $key (keys(%todeletedir)) {
12259: rmdir($key);
12260: }
12261: }
12262: foreach my $dir (sort(keys(%is_dir))) {
12263: if (($pathtocheck ne '') && ($dir ne '')) {
12264: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12265: }
12266: }
1.1067 raeburn 12267: if ($result ne '') {
12268: $output .= '<ul>'."\n".
12269: $result."\n".
12270: '</ul>';
12271: }
12272: unless ($ishome) {
12273: my $replicationfail;
12274: foreach my $item (keys(%prompttofetch)) {
12275: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12276: unless ($fetchresult eq 'ok') {
12277: $replicationfail .= '<li>'.$item.'</li>'."\n";
12278: }
12279: }
12280: if ($replicationfail) {
12281: $output .= '<p class="LC_error">'.
12282: &mt('Course home server failed to retrieve:').'<ul>'.
12283: $replicationfail.
12284: '</ul></p>';
12285: }
12286: }
1.1055 raeburn 12287: } else {
12288: $warning = &mt('No items found in archive.');
12289: }
12290: if ($error) {
12291: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12292: $error.'</p>'."\n";
12293: }
12294: if ($warning) {
12295: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12296: }
12297: return $output;
12298: }
12299:
1.1066 raeburn 12300: sub cleanup_empty_dirs {
12301: my ($path) = @_;
12302: if (($path ne '') && (-d $path)) {
12303: if (opendir(my $dirh,$path)) {
12304: my @dircontents = grep(!/^\./,readdir($dirh));
12305: my $numitems = 0;
12306: foreach my $item (@dircontents) {
12307: if (-d "$path/$item") {
1.1075.2.28 raeburn 12308: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12309: if (-e "$path/$item") {
12310: $numitems ++;
12311: }
12312: } else {
12313: $numitems ++;
12314: }
12315: }
12316: if ($numitems == 0) {
12317: rmdir($path);
12318: }
12319: closedir($dirh);
12320: }
12321: }
12322: return;
12323: }
12324:
1.41 ng 12325: =pod
1.45 matthew 12326:
1.1075.2.56 raeburn 12327: =item * &get_folder_hierarchy()
1.1068 raeburn 12328:
12329: Provides hierarchy of names of folders/sub-folders containing the current
12330: item,
12331:
12332: Inputs: 3
12333: - $navmap - navmaps object
12334:
12335: - $map - url for map (either the trigger itself, or map containing
12336: the resource, which is the trigger).
12337:
12338: - $showitem - 1 => show title for map itself; 0 => do not show.
12339:
12340: Outputs: 1 @pathitems - array of folder/subfolder names.
12341:
12342: =cut
12343:
12344: sub get_folder_hierarchy {
12345: my ($navmap,$map,$showitem) = @_;
12346: my @pathitems;
12347: if (ref($navmap)) {
12348: my $mapres = $navmap->getResourceByUrl($map);
12349: if (ref($mapres)) {
12350: my $pcslist = $mapres->map_hierarchy();
12351: if ($pcslist ne '') {
12352: my @pcs = split(/,/,$pcslist);
12353: foreach my $pc (@pcs) {
12354: if ($pc == 1) {
1.1075.2.38 raeburn 12355: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12356: } else {
12357: my $res = $navmap->getByMapPc($pc);
12358: if (ref($res)) {
12359: my $title = $res->compTitle();
12360: $title =~ s/\W+/_/g;
12361: if ($title ne '') {
12362: push(@pathitems,$title);
12363: }
12364: }
12365: }
12366: }
12367: }
1.1071 raeburn 12368: if ($showitem) {
12369: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12370: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12371: } else {
12372: my $maptitle = $mapres->compTitle();
12373: $maptitle =~ s/\W+/_/g;
12374: if ($maptitle ne '') {
12375: push(@pathitems,$maptitle);
12376: }
1.1068 raeburn 12377: }
12378: }
12379: }
12380: }
12381: return @pathitems;
12382: }
12383:
12384: =pod
12385:
1.1015 raeburn 12386: =item * &get_turnedin_filepath()
12387:
12388: Determines path in a user's portfolio file for storage of files uploaded
12389: to a specific essayresponse or dropbox item.
12390:
12391: Inputs: 3 required + 1 optional.
12392: $symb is symb for resource, $uname and $udom are for current user (required).
12393: $caller is optional (can be "submission", if routine is called when storing
12394: an upoaded file when "Submit Answer" button was pressed).
12395:
12396: Returns array containing $path and $multiresp.
12397: $path is path in portfolio. $multiresp is 1 if this resource contains more
12398: than one file upload item. Callers of routine should append partid as a
12399: subdirectory to $path in cases where $multiresp is 1.
12400:
12401: Called by: homework/essayresponse.pm and homework/structuretags.pm
12402:
12403: =cut
12404:
12405: sub get_turnedin_filepath {
12406: my ($symb,$uname,$udom,$caller) = @_;
12407: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12408: my $turnindir;
12409: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12410: $turnindir = $userhash{'turnindir'};
12411: my ($path,$multiresp);
12412: if ($turnindir eq '') {
12413: if ($caller eq 'submission') {
12414: $turnindir = &mt('turned in');
12415: $turnindir =~ s/\W+/_/g;
12416: my %newhash = (
12417: 'turnindir' => $turnindir,
12418: );
12419: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12420: }
12421: }
12422: if ($turnindir ne '') {
12423: $path = '/'.$turnindir.'/';
12424: my ($multipart,$turnin,@pathitems);
12425: my $navmap = Apache::lonnavmaps::navmap->new();
12426: if (defined($navmap)) {
12427: my $mapres = $navmap->getResourceByUrl($map);
12428: if (ref($mapres)) {
12429: my $pcslist = $mapres->map_hierarchy();
12430: if ($pcslist ne '') {
12431: foreach my $pc (split(/,/,$pcslist)) {
12432: my $res = $navmap->getByMapPc($pc);
12433: if (ref($res)) {
12434: my $title = $res->compTitle();
12435: $title =~ s/\W+/_/g;
12436: if ($title ne '') {
1.1075.2.48 raeburn 12437: if (($pc > 1) && (length($title) > 12)) {
12438: $title = substr($title,0,12);
12439: }
1.1015 raeburn 12440: push(@pathitems,$title);
12441: }
12442: }
12443: }
12444: }
12445: my $maptitle = $mapres->compTitle();
12446: $maptitle =~ s/\W+/_/g;
12447: if ($maptitle ne '') {
1.1075.2.48 raeburn 12448: if (length($maptitle) > 12) {
12449: $maptitle = substr($maptitle,0,12);
12450: }
1.1015 raeburn 12451: push(@pathitems,$maptitle);
12452: }
12453: unless ($env{'request.state'} eq 'construct') {
12454: my $res = $navmap->getBySymb($symb);
12455: if (ref($res)) {
12456: my $partlist = $res->parts();
12457: my $totaluploads = 0;
12458: if (ref($partlist) eq 'ARRAY') {
12459: foreach my $part (@{$partlist}) {
12460: my @types = $res->responseType($part);
12461: my @ids = $res->responseIds($part);
12462: for (my $i=0; $i < scalar(@ids); $i++) {
12463: if ($types[$i] eq 'essay') {
12464: my $partid = $part.'_'.$ids[$i];
12465: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12466: $totaluploads ++;
12467: }
12468: }
12469: }
12470: }
12471: if ($totaluploads > 1) {
12472: $multiresp = 1;
12473: }
12474: }
12475: }
12476: }
12477: } else {
12478: return;
12479: }
12480: } else {
12481: return;
12482: }
12483: my $restitle=&Apache::lonnet::gettitle($symb);
12484: $restitle =~ s/\W+/_/g;
12485: if ($restitle eq '') {
12486: $restitle = ($resurl =~ m{/[^/]+$});
12487: if ($restitle eq '') {
12488: $restitle = time;
12489: }
12490: }
1.1075.2.48 raeburn 12491: if (length($restitle) > 12) {
12492: $restitle = substr($restitle,0,12);
12493: }
1.1015 raeburn 12494: push(@pathitems,$restitle);
12495: $path .= join('/',@pathitems);
12496: }
12497: return ($path,$multiresp);
12498: }
12499:
12500: =pod
12501:
1.464 albertel 12502: =back
1.41 ng 12503:
1.112 bowersj2 12504: =head1 CSV Upload/Handling functions
1.38 albertel 12505:
1.41 ng 12506: =over 4
12507:
1.648 raeburn 12508: =item * &upfile_store($r)
1.41 ng 12509:
12510: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12511: needs $env{'form.upfile'}
1.41 ng 12512: returns $datatoken to be put into hidden field
12513:
12514: =cut
1.31 albertel 12515:
12516: sub upfile_store {
12517: my $r=shift;
1.258 albertel 12518: $env{'form.upfile'}=~s/\r/\n/gs;
12519: $env{'form.upfile'}=~s/\f/\n/gs;
12520: $env{'form.upfile'}=~s/\n+/\n/gs;
12521: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12522:
1.258 albertel 12523: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12524: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12525: {
1.158 raeburn 12526: my $datafile = $r->dir_config('lonDaemons').
12527: '/tmp/'.$datatoken.'.tmp';
12528: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12529: print $fh $env{'form.upfile'};
1.158 raeburn 12530: close($fh);
12531: }
1.31 albertel 12532: }
12533: return $datatoken;
12534: }
12535:
1.56 matthew 12536: =pod
12537:
1.648 raeburn 12538: =item * &load_tmp_file($r)
1.41 ng 12539:
12540: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12541: needs $env{'form.datatoken'},
12542: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12543:
12544: =cut
1.31 albertel 12545:
12546: sub load_tmp_file {
12547: my $r=shift;
12548: my @studentdata=();
12549: {
1.158 raeburn 12550: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12551: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12552: if ( open(my $fh,"<$studentfile") ) {
12553: @studentdata=<$fh>;
12554: close($fh);
12555: }
1.31 albertel 12556: }
1.258 albertel 12557: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12558: }
12559:
1.56 matthew 12560: =pod
12561:
1.648 raeburn 12562: =item * &upfile_record_sep()
1.41 ng 12563:
12564: Separate uploaded file into records
12565: returns array of records,
1.258 albertel 12566: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12567:
12568: =cut
1.31 albertel 12569:
12570: sub upfile_record_sep {
1.258 albertel 12571: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12572: } else {
1.248 albertel 12573: my @records;
1.258 albertel 12574: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12575: if ($line=~/^\s*$/) { next; }
12576: push(@records,$line);
12577: }
12578: return @records;
1.31 albertel 12579: }
12580: }
12581:
1.56 matthew 12582: =pod
12583:
1.648 raeburn 12584: =item * &record_sep($record)
1.41 ng 12585:
1.258 albertel 12586: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12587:
12588: =cut
12589:
1.263 www 12590: sub takeleft {
12591: my $index=shift;
12592: return substr('0000'.$index,-4,4);
12593: }
12594:
1.31 albertel 12595: sub record_sep {
12596: my $record=shift;
12597: my %components=();
1.258 albertel 12598: if ($env{'form.upfiletype'} eq 'xml') {
12599: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12600: my $i=0;
1.356 albertel 12601: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12602: $field=~s/^(\"|\')//;
12603: $field=~s/(\"|\')$//;
1.263 www 12604: $components{&takeleft($i)}=$field;
1.31 albertel 12605: $i++;
12606: }
1.258 albertel 12607: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12608: my $i=0;
1.356 albertel 12609: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12610: $field=~s/^(\"|\')//;
12611: $field=~s/(\"|\')$//;
1.263 www 12612: $components{&takeleft($i)}=$field;
1.31 albertel 12613: $i++;
12614: }
12615: } else {
1.561 www 12616: my $separator=',';
1.480 banghart 12617: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12618: $separator=';';
1.480 banghart 12619: }
1.31 albertel 12620: my $i=0;
1.561 www 12621: # the character we are looking for to indicate the end of a quote or a record
12622: my $looking_for=$separator;
12623: # do not add the characters to the fields
12624: my $ignore=0;
12625: # we just encountered a separator (or the beginning of the record)
12626: my $just_found_separator=1;
12627: # store the field we are working on here
12628: my $field='';
12629: # work our way through all characters in record
12630: foreach my $character ($record=~/(.)/g) {
12631: if ($character eq $looking_for) {
12632: if ($character ne $separator) {
12633: # Found the end of a quote, again looking for separator
12634: $looking_for=$separator;
12635: $ignore=1;
12636: } else {
12637: # Found a separator, store away what we got
12638: $components{&takeleft($i)}=$field;
12639: $i++;
12640: $just_found_separator=1;
12641: $ignore=0;
12642: $field='';
12643: }
12644: next;
12645: }
12646: # single or double quotation marks after a separator indicate beginning of a quote
12647: # we are now looking for the end of the quote and need to ignore separators
12648: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12649: $looking_for=$character;
12650: next;
12651: }
12652: # ignore would be true after we reached the end of a quote
12653: if ($ignore) { next; }
12654: if (($just_found_separator) && ($character=~/\s/)) { next; }
12655: $field.=$character;
12656: $just_found_separator=0;
1.31 albertel 12657: }
1.561 www 12658: # catch the very last entry, since we never encountered the separator
12659: $components{&takeleft($i)}=$field;
1.31 albertel 12660: }
12661: return %components;
12662: }
12663:
1.144 matthew 12664: ######################################################
12665: ######################################################
12666:
1.56 matthew 12667: =pod
12668:
1.648 raeburn 12669: =item * &upfile_select_html()
1.41 ng 12670:
1.144 matthew 12671: Return HTML code to select a file from the users machine and specify
12672: the file type.
1.41 ng 12673:
12674: =cut
12675:
1.144 matthew 12676: ######################################################
12677: ######################################################
1.31 albertel 12678: sub upfile_select_html {
1.144 matthew 12679: my %Types = (
12680: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12681: semisv => &mt('Semicolon separated values'),
1.144 matthew 12682: space => &mt('Space separated'),
12683: tab => &mt('Tabulator separated'),
12684: # xml => &mt('HTML/XML'),
12685: );
12686: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12687: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12688: foreach my $type (sort(keys(%Types))) {
12689: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12690: }
12691: $Str .= "</select>\n";
12692: return $Str;
1.31 albertel 12693: }
12694:
1.301 albertel 12695: sub get_samples {
12696: my ($records,$toget) = @_;
12697: my @samples=({});
12698: my $got=0;
12699: foreach my $rec (@$records) {
12700: my %temp = &record_sep($rec);
12701: if (! grep(/\S/, values(%temp))) { next; }
12702: if (%temp) {
12703: $samples[$got]=\%temp;
12704: $got++;
12705: if ($got == $toget) { last; }
12706: }
12707: }
12708: return \@samples;
12709: }
12710:
1.144 matthew 12711: ######################################################
12712: ######################################################
12713:
1.56 matthew 12714: =pod
12715:
1.648 raeburn 12716: =item * &csv_print_samples($r,$records)
1.41 ng 12717:
12718: Prints a table of sample values from each column uploaded $r is an
12719: Apache Request ref, $records is an arrayref from
12720: &Apache::loncommon::upfile_record_sep
12721:
12722: =cut
12723:
1.144 matthew 12724: ######################################################
12725: ######################################################
1.31 albertel 12726: sub csv_print_samples {
12727: my ($r,$records) = @_;
1.662 bisitz 12728: my $samples = &get_samples($records,5);
1.301 albertel 12729:
1.594 raeburn 12730: $r->print(&mt('Samples').'<br />'.&start_data_table().
12731: &start_data_table_header_row());
1.356 albertel 12732: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12733: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12734: $r->print(&end_data_table_header_row());
1.301 albertel 12735: foreach my $hash (@$samples) {
1.594 raeburn 12736: $r->print(&start_data_table_row());
1.356 albertel 12737: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12738: $r->print('<td>');
1.356 albertel 12739: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12740: $r->print('</td>');
12741: }
1.594 raeburn 12742: $r->print(&end_data_table_row());
1.31 albertel 12743: }
1.594 raeburn 12744: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12745: }
12746:
1.144 matthew 12747: ######################################################
12748: ######################################################
12749:
1.56 matthew 12750: =pod
12751:
1.648 raeburn 12752: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12753:
12754: Prints a table to create associations between values and table columns.
1.144 matthew 12755:
1.41 ng 12756: $r is an Apache Request ref,
12757: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12758: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12759:
12760: =cut
12761:
1.144 matthew 12762: ######################################################
12763: ######################################################
1.31 albertel 12764: sub csv_print_select_table {
12765: my ($r,$records,$d) = @_;
1.301 albertel 12766: my $i=0;
12767: my $samples = &get_samples($records,1);
1.144 matthew 12768: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12769: &start_data_table().&start_data_table_header_row().
1.144 matthew 12770: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12771: '<th>'.&mt('Column').'</th>'.
12772: &end_data_table_header_row()."\n");
1.356 albertel 12773: foreach my $array_ref (@$d) {
12774: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12775: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12776:
1.875 bisitz 12777: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12778: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12779: $r->print('<option value="none"></option>');
1.356 albertel 12780: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12781: $r->print('<option value="'.$sample.'"'.
12782: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12783: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12784: }
1.594 raeburn 12785: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12786: $i++;
12787: }
1.594 raeburn 12788: $r->print(&end_data_table());
1.31 albertel 12789: $i--;
12790: return $i;
12791: }
1.56 matthew 12792:
1.144 matthew 12793: ######################################################
12794: ######################################################
12795:
1.56 matthew 12796: =pod
1.31 albertel 12797:
1.648 raeburn 12798: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12799:
12800: Prints a table of sample values from the upload and can make associate samples to internal names.
12801:
12802: $r is an Apache Request ref,
12803: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12804: $d is an array of 2 element arrays (internal name, displayed name)
12805:
12806: =cut
12807:
1.144 matthew 12808: ######################################################
12809: ######################################################
1.31 albertel 12810: sub csv_samples_select_table {
12811: my ($r,$records,$d) = @_;
12812: my $i=0;
1.144 matthew 12813: #
1.662 bisitz 12814: my $max_samples = 5;
12815: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12816: $r->print(&start_data_table().
12817: &start_data_table_header_row().'<th>'.
12818: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12819: &end_data_table_header_row());
1.301 albertel 12820:
12821: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12822: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12823: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12824: foreach my $option (@$d) {
12825: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12826: $r->print('<option value="'.$value.'"'.
1.253 albertel 12827: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12828: $display.'</option>');
1.31 albertel 12829: }
12830: $r->print('</select></td><td>');
1.662 bisitz 12831: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12832: if (defined($samples->[$line]{$key})) {
12833: $r->print($samples->[$line]{$key}."<br />\n");
12834: }
12835: }
1.594 raeburn 12836: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12837: $i++;
12838: }
1.594 raeburn 12839: $r->print(&end_data_table());
1.31 albertel 12840: $i--;
12841: return($i);
1.115 matthew 12842: }
12843:
1.144 matthew 12844: ######################################################
12845: ######################################################
12846:
1.115 matthew 12847: =pod
12848:
1.648 raeburn 12849: =item * &clean_excel_name($name)
1.115 matthew 12850:
12851: Returns a replacement for $name which does not contain any illegal characters.
12852:
12853: =cut
12854:
1.144 matthew 12855: ######################################################
12856: ######################################################
1.115 matthew 12857: sub clean_excel_name {
12858: my ($name) = @_;
12859: $name =~ s/[:\*\?\/\\]//g;
12860: if (length($name) > 31) {
12861: $name = substr($name,0,31);
12862: }
12863: return $name;
1.25 albertel 12864: }
1.84 albertel 12865:
1.85 albertel 12866: =pod
12867:
1.648 raeburn 12868: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12869:
12870: Returns either 1 or undef
12871:
12872: 1 if the part is to be hidden, undef if it is to be shown
12873:
12874: Arguments are:
12875:
12876: $id the id of the part to be checked
12877: $symb, optional the symb of the resource to check
12878: $udom, optional the domain of the user to check for
12879: $uname, optional the username of the user to check for
12880:
12881: =cut
1.84 albertel 12882:
12883: sub check_if_partid_hidden {
12884: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12885: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12886: $symb,$udom,$uname);
1.141 albertel 12887: my $truth=1;
12888: #if the string starts with !, then the list is the list to show not hide
12889: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12890: my @hiddenlist=split(/,/,$hiddenparts);
12891: foreach my $checkid (@hiddenlist) {
1.141 albertel 12892: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12893: }
1.141 albertel 12894: return !$truth;
1.84 albertel 12895: }
1.127 matthew 12896:
1.138 matthew 12897:
12898: ############################################################
12899: ############################################################
12900:
12901: =pod
12902:
1.157 matthew 12903: =back
12904:
1.138 matthew 12905: =head1 cgi-bin script and graphing routines
12906:
1.157 matthew 12907: =over 4
12908:
1.648 raeburn 12909: =item * &get_cgi_id()
1.138 matthew 12910:
12911: Inputs: none
12912:
12913: Returns an id which can be used to pass environment variables
12914: to various cgi-bin scripts. These environment variables will
12915: be removed from the users environment after a given time by
12916: the routine &Apache::lonnet::transfer_profile_to_env.
12917:
12918: =cut
12919:
12920: ############################################################
12921: ############################################################
1.152 albertel 12922: my $uniq=0;
1.136 matthew 12923: sub get_cgi_id {
1.154 albertel 12924: $uniq=($uniq+1)%100000;
1.280 albertel 12925: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12926: }
12927:
1.127 matthew 12928: ############################################################
12929: ############################################################
12930:
12931: =pod
12932:
1.648 raeburn 12933: =item * &DrawBarGraph()
1.127 matthew 12934:
1.138 matthew 12935: Facilitates the plotting of data in a (stacked) bar graph.
12936: Puts plot definition data into the users environment in order for
12937: graph.png to plot it. Returns an <img> tag for the plot.
12938: The bars on the plot are labeled '1','2',...,'n'.
12939:
12940: Inputs:
12941:
12942: =over 4
12943:
12944: =item $Title: string, the title of the plot
12945:
12946: =item $xlabel: string, text describing the X-axis of the plot
12947:
12948: =item $ylabel: string, text describing the Y-axis of the plot
12949:
12950: =item $Max: scalar, the maximum Y value to use in the plot
12951: If $Max is < any data point, the graph will not be rendered.
12952:
1.140 matthew 12953: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12954: they are plotted. If undefined, default values will be used.
12955:
1.178 matthew 12956: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12957:
1.138 matthew 12958: =item @Values: An array of array references. Each array reference holds data
12959: to be plotted in a stacked bar chart.
12960:
1.239 matthew 12961: =item If the final element of @Values is a hash reference the key/value
12962: pairs will be added to the graph definition.
12963:
1.138 matthew 12964: =back
12965:
12966: Returns:
12967:
12968: An <img> tag which references graph.png and the appropriate identifying
12969: information for the plot.
12970:
1.127 matthew 12971: =cut
12972:
12973: ############################################################
12974: ############################################################
1.134 matthew 12975: sub DrawBarGraph {
1.178 matthew 12976: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12977: #
12978: if (! defined($colors)) {
12979: $colors = ['#33ff00',
12980: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12981: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12982: ];
12983: }
1.228 matthew 12984: my $extra_settings = {};
12985: if (ref($Values[-1]) eq 'HASH') {
12986: $extra_settings = pop(@Values);
12987: }
1.127 matthew 12988: #
1.136 matthew 12989: my $identifier = &get_cgi_id();
12990: my $id = 'cgi.'.$identifier;
1.129 matthew 12991: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12992: return '';
12993: }
1.225 matthew 12994: #
12995: my @Labels;
12996: if (defined($labels)) {
12997: @Labels = @$labels;
12998: } else {
12999: for (my $i=0;$i<@{$Values[0]};$i++) {
13000: push (@Labels,$i+1);
13001: }
13002: }
13003: #
1.129 matthew 13004: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13005: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13006: my %ValuesHash;
13007: my $NumSets=1;
13008: foreach my $array (@Values) {
13009: next if (! ref($array));
1.136 matthew 13010: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13011: join(',',@$array);
1.129 matthew 13012: }
1.127 matthew 13013: #
1.136 matthew 13014: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13015: if ($NumBars < 3) {
13016: $width = 120+$NumBars*32;
1.220 matthew 13017: $xskip = 1;
1.225 matthew 13018: $bar_width = 30;
13019: } elsif ($NumBars < 5) {
13020: $width = 120+$NumBars*20;
13021: $xskip = 1;
13022: $bar_width = 20;
1.220 matthew 13023: } elsif ($NumBars < 10) {
1.136 matthew 13024: $width = 120+$NumBars*15;
13025: $xskip = 1;
13026: $bar_width = 15;
13027: } elsif ($NumBars <= 25) {
13028: $width = 120+$NumBars*11;
13029: $xskip = 5;
13030: $bar_width = 8;
13031: } elsif ($NumBars <= 50) {
13032: $width = 120+$NumBars*8;
13033: $xskip = 5;
13034: $bar_width = 4;
13035: } else {
13036: $width = 120+$NumBars*8;
13037: $xskip = 5;
13038: $bar_width = 4;
13039: }
13040: #
1.137 matthew 13041: $Max = 1 if ($Max < 1);
13042: if ( int($Max) < $Max ) {
13043: $Max++;
13044: $Max = int($Max);
13045: }
1.127 matthew 13046: $Title = '' if (! defined($Title));
13047: $xlabel = '' if (! defined($xlabel));
13048: $ylabel = '' if (! defined($ylabel));
1.369 www 13049: $ValuesHash{$id.'.title'} = &escape($Title);
13050: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13051: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13052: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13053: $ValuesHash{$id.'.NumBars'} = $NumBars;
13054: $ValuesHash{$id.'.NumSets'} = $NumSets;
13055: $ValuesHash{$id.'.PlotType'} = 'bar';
13056: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13057: $ValuesHash{$id.'.height'} = $height;
13058: $ValuesHash{$id.'.width'} = $width;
13059: $ValuesHash{$id.'.xskip'} = $xskip;
13060: $ValuesHash{$id.'.bar_width'} = $bar_width;
13061: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13062: #
1.228 matthew 13063: # Deal with other parameters
13064: while (my ($key,$value) = each(%$extra_settings)) {
13065: $ValuesHash{$id.'.'.$key} = $value;
13066: }
13067: #
1.646 raeburn 13068: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13069: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13070: }
13071:
13072: ############################################################
13073: ############################################################
13074:
13075: =pod
13076:
1.648 raeburn 13077: =item * &DrawXYGraph()
1.137 matthew 13078:
1.138 matthew 13079: Facilitates the plotting of data in an XY graph.
13080: Puts plot definition data into the users environment in order for
13081: graph.png to plot it. Returns an <img> tag for the plot.
13082:
13083: Inputs:
13084:
13085: =over 4
13086:
13087: =item $Title: string, the title of the plot
13088:
13089: =item $xlabel: string, text describing the X-axis of the plot
13090:
13091: =item $ylabel: string, text describing the Y-axis of the plot
13092:
13093: =item $Max: scalar, the maximum Y value to use in the plot
13094: If $Max is < any data point, the graph will not be rendered.
13095:
13096: =item $colors: Array ref containing the hex color codes for the data to be
13097: plotted in. If undefined, default values will be used.
13098:
13099: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13100:
13101: =item $Ydata: Array ref containing Array refs.
1.185 www 13102: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13103:
13104: =item %Values: hash indicating or overriding any default values which are
13105: passed to graph.png.
13106: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13107:
13108: =back
13109:
13110: Returns:
13111:
13112: An <img> tag which references graph.png and the appropriate identifying
13113: information for the plot.
13114:
1.137 matthew 13115: =cut
13116:
13117: ############################################################
13118: ############################################################
13119: sub DrawXYGraph {
13120: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13121: #
13122: # Create the identifier for the graph
13123: my $identifier = &get_cgi_id();
13124: my $id = 'cgi.'.$identifier;
13125: #
13126: $Title = '' if (! defined($Title));
13127: $xlabel = '' if (! defined($xlabel));
13128: $ylabel = '' if (! defined($ylabel));
13129: my %ValuesHash =
13130: (
1.369 www 13131: $id.'.title' => &escape($Title),
13132: $id.'.xlabel' => &escape($xlabel),
13133: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13134: $id.'.y_max_value'=> $Max,
13135: $id.'.labels' => join(',',@$Xlabels),
13136: $id.'.PlotType' => 'XY',
13137: );
13138: #
13139: if (defined($colors) && ref($colors) eq 'ARRAY') {
13140: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13141: }
13142: #
13143: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13144: return '';
13145: }
13146: my $NumSets=1;
1.138 matthew 13147: foreach my $array (@{$Ydata}){
1.137 matthew 13148: next if (! ref($array));
13149: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13150: }
1.138 matthew 13151: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13152: #
13153: # Deal with other parameters
13154: while (my ($key,$value) = each(%Values)) {
13155: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13156: }
13157: #
1.646 raeburn 13158: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13159: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13160: }
13161:
13162: ############################################################
13163: ############################################################
13164:
13165: =pod
13166:
1.648 raeburn 13167: =item * &DrawXYYGraph()
1.138 matthew 13168:
13169: Facilitates the plotting of data in an XY graph with two Y axes.
13170: Puts plot definition data into the users environment in order for
13171: graph.png to plot it. Returns an <img> tag for the plot.
13172:
13173: Inputs:
13174:
13175: =over 4
13176:
13177: =item $Title: string, the title of the plot
13178:
13179: =item $xlabel: string, text describing the X-axis of the plot
13180:
13181: =item $ylabel: string, text describing the Y-axis of the plot
13182:
13183: =item $colors: Array ref containing the hex color codes for the data to be
13184: plotted in. If undefined, default values will be used.
13185:
13186: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13187:
13188: =item $Ydata1: The first data set
13189:
13190: =item $Min1: The minimum value of the left Y-axis
13191:
13192: =item $Max1: The maximum value of the left Y-axis
13193:
13194: =item $Ydata2: The second data set
13195:
13196: =item $Min2: The minimum value of the right Y-axis
13197:
13198: =item $Max2: The maximum value of the left Y-axis
13199:
13200: =item %Values: hash indicating or overriding any default values which are
13201: passed to graph.png.
13202: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13203:
13204: =back
13205:
13206: Returns:
13207:
13208: An <img> tag which references graph.png and the appropriate identifying
13209: information for the plot.
1.136 matthew 13210:
13211: =cut
13212:
13213: ############################################################
13214: ############################################################
1.137 matthew 13215: sub DrawXYYGraph {
13216: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13217: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13218: #
13219: # Create the identifier for the graph
13220: my $identifier = &get_cgi_id();
13221: my $id = 'cgi.'.$identifier;
13222: #
13223: $Title = '' if (! defined($Title));
13224: $xlabel = '' if (! defined($xlabel));
13225: $ylabel = '' if (! defined($ylabel));
13226: my %ValuesHash =
13227: (
1.369 www 13228: $id.'.title' => &escape($Title),
13229: $id.'.xlabel' => &escape($xlabel),
13230: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13231: $id.'.labels' => join(',',@$Xlabels),
13232: $id.'.PlotType' => 'XY',
13233: $id.'.NumSets' => 2,
1.137 matthew 13234: $id.'.two_axes' => 1,
13235: $id.'.y1_max_value' => $Max1,
13236: $id.'.y1_min_value' => $Min1,
13237: $id.'.y2_max_value' => $Max2,
13238: $id.'.y2_min_value' => $Min2,
1.136 matthew 13239: );
13240: #
1.137 matthew 13241: if (defined($colors) && ref($colors) eq 'ARRAY') {
13242: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13243: }
13244: #
13245: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13246: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13247: return '';
13248: }
13249: my $NumSets=1;
1.137 matthew 13250: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13251: next if (! ref($array));
13252: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13253: }
13254: #
13255: # Deal with other parameters
13256: while (my ($key,$value) = each(%Values)) {
13257: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13258: }
13259: #
1.646 raeburn 13260: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13261: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13262: }
13263:
13264: ############################################################
13265: ############################################################
13266:
13267: =pod
13268:
1.157 matthew 13269: =back
13270:
1.139 matthew 13271: =head1 Statistics helper routines?
13272:
13273: Bad place for them but what the hell.
13274:
1.157 matthew 13275: =over 4
13276:
1.648 raeburn 13277: =item * &chartlink()
1.139 matthew 13278:
13279: Returns a link to the chart for a specific student.
13280:
13281: Inputs:
13282:
13283: =over 4
13284:
13285: =item $linktext: The text of the link
13286:
13287: =item $sname: The students username
13288:
13289: =item $sdomain: The students domain
13290:
13291: =back
13292:
1.157 matthew 13293: =back
13294:
1.139 matthew 13295: =cut
13296:
13297: ############################################################
13298: ############################################################
13299: sub chartlink {
13300: my ($linktext, $sname, $sdomain) = @_;
13301: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13302: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13303: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13304: '">'.$linktext.'</a>';
1.153 matthew 13305: }
13306:
13307: #######################################################
13308: #######################################################
13309:
13310: =pod
13311:
13312: =head1 Course Environment Routines
1.157 matthew 13313:
13314: =over 4
1.153 matthew 13315:
1.648 raeburn 13316: =item * &restore_course_settings()
1.153 matthew 13317:
1.648 raeburn 13318: =item * &store_course_settings()
1.153 matthew 13319:
13320: Restores/Store indicated form parameters from the course environment.
13321: Will not overwrite existing values of the form parameters.
13322:
13323: Inputs:
13324: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13325:
13326: a hash ref describing the data to be stored. For example:
13327:
13328: %Save_Parameters = ('Status' => 'scalar',
13329: 'chartoutputmode' => 'scalar',
13330: 'chartoutputdata' => 'scalar',
13331: 'Section' => 'array',
1.373 raeburn 13332: 'Group' => 'array',
1.153 matthew 13333: 'StudentData' => 'array',
13334: 'Maps' => 'array');
13335:
13336: Returns: both routines return nothing
13337:
1.631 raeburn 13338: =back
13339:
1.153 matthew 13340: =cut
13341:
13342: #######################################################
13343: #######################################################
13344: sub store_course_settings {
1.496 albertel 13345: return &store_settings($env{'request.course.id'},@_);
13346: }
13347:
13348: sub store_settings {
1.153 matthew 13349: # save to the environment
13350: # appenv the same items, just to be safe
1.300 albertel 13351: my $udom = $env{'user.domain'};
13352: my $uname = $env{'user.name'};
1.496 albertel 13353: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13354: my %SaveHash;
13355: my %AppHash;
13356: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13357: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13358: my $envname = 'environment.'.$basename;
1.258 albertel 13359: if (exists($env{'form.'.$setting})) {
1.153 matthew 13360: # Save this value away
13361: if ($type eq 'scalar' &&
1.258 albertel 13362: (! exists($env{$envname}) ||
13363: $env{$envname} ne $env{'form.'.$setting})) {
13364: $SaveHash{$basename} = $env{'form.'.$setting};
13365: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13366: } elsif ($type eq 'array') {
13367: my $stored_form;
1.258 albertel 13368: if (ref($env{'form.'.$setting})) {
1.153 matthew 13369: $stored_form = join(',',
13370: map {
1.369 www 13371: &escape($_);
1.258 albertel 13372: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13373: } else {
13374: $stored_form =
1.369 www 13375: &escape($env{'form.'.$setting});
1.153 matthew 13376: }
13377: # Determine if the array contents are the same.
1.258 albertel 13378: if ($stored_form ne $env{$envname}) {
1.153 matthew 13379: $SaveHash{$basename} = $stored_form;
13380: $AppHash{$envname} = $stored_form;
13381: }
13382: }
13383: }
13384: }
13385: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13386: $udom,$uname);
1.153 matthew 13387: if ($put_result !~ /^(ok|delayed)/) {
13388: &Apache::lonnet::logthis('unable to save form parameters, '.
13389: 'got error:'.$put_result);
13390: }
13391: # Make sure these settings stick around in this session, too
1.646 raeburn 13392: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13393: return;
13394: }
13395:
13396: sub restore_course_settings {
1.499 albertel 13397: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13398: }
13399:
13400: sub restore_settings {
13401: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13402: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13403: next if (exists($env{'form.'.$setting}));
1.496 albertel 13404: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13405: '.'.$setting;
1.258 albertel 13406: if (exists($env{$envname})) {
1.153 matthew 13407: if ($type eq 'scalar') {
1.258 albertel 13408: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13409: } elsif ($type eq 'array') {
1.258 albertel 13410: $env{'form.'.$setting} = [
1.153 matthew 13411: map {
1.369 www 13412: &unescape($_);
1.258 albertel 13413: } split(',',$env{$envname})
1.153 matthew 13414: ];
13415: }
13416: }
13417: }
1.127 matthew 13418: }
13419:
1.618 raeburn 13420: #######################################################
13421: #######################################################
13422:
13423: =pod
13424:
13425: =head1 Domain E-mail Routines
13426:
13427: =over 4
13428:
1.648 raeburn 13429: =item * &build_recipient_list()
1.618 raeburn 13430:
1.1075.2.44 raeburn 13431: Build recipient lists for following types of e-mail:
1.766 raeburn 13432: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 13433: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13434: module change checking, student/employee ID conflict checks, as
13435: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13436: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13437:
13438: Inputs:
1.1075.2.44 raeburn 13439: defmail (scalar - email address of default recipient),
13440: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13441: requestsmail, updatesmail, or idconflictsmail).
13442:
1.619 raeburn 13443: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 13444:
13445: origmail (scalar - email address of recipient from loncapa.conf,
13446: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13447:
1.655 raeburn 13448: Returns: comma separated list of addresses to which to send e-mail.
13449:
13450: =back
1.618 raeburn 13451:
13452: =cut
13453:
13454: ############################################################
13455: ############################################################
13456: sub build_recipient_list {
1.619 raeburn 13457: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13458: my @recipients;
13459: my $otheremails;
13460: my %domconfig =
13461: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13462: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13463: if (exists($domconfig{'contacts'}{$mailing})) {
13464: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13465: my @contacts = ('adminemail','supportemail');
13466: foreach my $item (@contacts) {
13467: if ($domconfig{'contacts'}{$mailing}{$item}) {
13468: my $addr = $domconfig{'contacts'}{$item};
13469: if (!grep(/^\Q$addr\E$/,@recipients)) {
13470: push(@recipients,$addr);
13471: }
1.619 raeburn 13472: }
1.766 raeburn 13473: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13474: }
13475: }
1.766 raeburn 13476: } elsif ($origmail ne '') {
13477: push(@recipients,$origmail);
1.618 raeburn 13478: }
1.619 raeburn 13479: } elsif ($origmail ne '') {
13480: push(@recipients,$origmail);
1.618 raeburn 13481: }
1.688 raeburn 13482: if (defined($defmail)) {
13483: if ($defmail ne '') {
13484: push(@recipients,$defmail);
13485: }
1.618 raeburn 13486: }
13487: if ($otheremails) {
1.619 raeburn 13488: my @others;
13489: if ($otheremails =~ /,/) {
13490: @others = split(/,/,$otheremails);
1.618 raeburn 13491: } else {
1.619 raeburn 13492: push(@others,$otheremails);
13493: }
13494: foreach my $addr (@others) {
13495: if (!grep(/^\Q$addr\E$/,@recipients)) {
13496: push(@recipients,$addr);
13497: }
1.618 raeburn 13498: }
13499: }
1.619 raeburn 13500: my $recipientlist = join(',',@recipients);
1.618 raeburn 13501: return $recipientlist;
13502: }
13503:
1.127 matthew 13504: ############################################################
13505: ############################################################
1.154 albertel 13506:
1.655 raeburn 13507: =pod
13508:
13509: =head1 Course Catalog Routines
13510:
13511: =over 4
13512:
13513: =item * &gather_categories()
13514:
13515: Converts category definitions - keys of categories hash stored in
13516: coursecategories in configuration.db on the primary library server in a
13517: domain - to an array. Also generates javascript and idx hash used to
13518: generate Domain Coordinator interface for editing Course Categories.
13519:
13520: Inputs:
1.663 raeburn 13521:
1.655 raeburn 13522: categories (reference to hash of category definitions).
1.663 raeburn 13523:
1.655 raeburn 13524: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13525: categories and subcategories).
1.663 raeburn 13526:
1.655 raeburn 13527: idx (reference to hash of counters used in Domain Coordinator interface for
13528: editing Course Categories).
1.663 raeburn 13529:
1.655 raeburn 13530: jsarray (reference to array of categories used to create Javascript arrays for
13531: Domain Coordinator interface for editing Course Categories).
13532:
13533: Returns: nothing
13534:
13535: Side effects: populates cats, idx and jsarray.
13536:
13537: =cut
13538:
13539: sub gather_categories {
13540: my ($categories,$cats,$idx,$jsarray) = @_;
13541: my %counters;
13542: my $num = 0;
13543: foreach my $item (keys(%{$categories})) {
13544: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13545: if ($container eq '' && $depth == 0) {
13546: $cats->[$depth][$categories->{$item}] = $cat;
13547: } else {
13548: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13549: }
13550: my ($escitem,$tail) = split(/:/,$item,2);
13551: if ($counters{$tail} eq '') {
13552: $counters{$tail} = $num;
13553: $num ++;
13554: }
13555: if (ref($idx) eq 'HASH') {
13556: $idx->{$item} = $counters{$tail};
13557: }
13558: if (ref($jsarray) eq 'ARRAY') {
13559: push(@{$jsarray->[$counters{$tail}]},$item);
13560: }
13561: }
13562: return;
13563: }
13564:
13565: =pod
13566:
13567: =item * &extract_categories()
13568:
13569: Used to generate breadcrumb trails for course categories.
13570:
13571: Inputs:
1.663 raeburn 13572:
1.655 raeburn 13573: categories (reference to hash of category definitions).
1.663 raeburn 13574:
1.655 raeburn 13575: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13576: categories and subcategories).
1.663 raeburn 13577:
1.655 raeburn 13578: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13579:
1.655 raeburn 13580: allitems (reference to hash - key is category key
13581: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13582:
1.655 raeburn 13583: idx (reference to hash of counters used in Domain Coordinator interface for
13584: editing Course Categories).
1.663 raeburn 13585:
1.655 raeburn 13586: jsarray (reference to array of categories used to create Javascript arrays for
13587: Domain Coordinator interface for editing Course Categories).
13588:
1.665 raeburn 13589: subcats (reference to hash of arrays containing all subcategories within each
13590: category, -recursive)
13591:
1.655 raeburn 13592: Returns: nothing
13593:
13594: Side effects: populates trails and allitems hash references.
13595:
13596: =cut
13597:
13598: sub extract_categories {
1.665 raeburn 13599: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13600: if (ref($categories) eq 'HASH') {
13601: &gather_categories($categories,$cats,$idx,$jsarray);
13602: if (ref($cats->[0]) eq 'ARRAY') {
13603: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13604: my $name = $cats->[0][$i];
13605: my $item = &escape($name).'::0';
13606: my $trailstr;
13607: if ($name eq 'instcode') {
13608: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13609: } elsif ($name eq 'communities') {
13610: $trailstr = &mt('Communities');
1.655 raeburn 13611: } else {
13612: $trailstr = $name;
13613: }
13614: if ($allitems->{$item} eq '') {
13615: push(@{$trails},$trailstr);
13616: $allitems->{$item} = scalar(@{$trails})-1;
13617: }
13618: my @parents = ($name);
13619: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13620: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13621: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13622: if (ref($subcats) eq 'HASH') {
13623: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13624: }
13625: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13626: }
13627: } else {
13628: if (ref($subcats) eq 'HASH') {
13629: $subcats->{$item} = [];
1.655 raeburn 13630: }
13631: }
13632: }
13633: }
13634: }
13635: return;
13636: }
13637:
13638: =pod
13639:
1.1075.2.56 raeburn 13640: =item * &recurse_categories()
1.655 raeburn 13641:
13642: Recursively used to generate breadcrumb trails for course categories.
13643:
13644: Inputs:
1.663 raeburn 13645:
1.655 raeburn 13646: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13647: categories and subcategories).
1.663 raeburn 13648:
1.655 raeburn 13649: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13650:
13651: category (current course category, for which breadcrumb trail is being generated).
13652:
13653: trails (reference to array of breadcrumb trails for each category).
13654:
1.655 raeburn 13655: allitems (reference to hash - key is category key
13656: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13657:
1.655 raeburn 13658: parents (array containing containers directories for current category,
13659: back to top level).
13660:
13661: Returns: nothing
13662:
13663: Side effects: populates trails and allitems hash references
13664:
13665: =cut
13666:
13667: sub recurse_categories {
1.665 raeburn 13668: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13669: my $shallower = $depth - 1;
13670: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13671: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13672: my $name = $cats->[$depth]{$category}[$k];
13673: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13674: my $trailstr = join(' -> ',(@{$parents},$category));
13675: if ($allitems->{$item} eq '') {
13676: push(@{$trails},$trailstr);
13677: $allitems->{$item} = scalar(@{$trails})-1;
13678: }
13679: my $deeper = $depth+1;
13680: push(@{$parents},$category);
1.665 raeburn 13681: if (ref($subcats) eq 'HASH') {
13682: my $subcat = &escape($name).':'.$category.':'.$depth;
13683: for (my $j=@{$parents}; $j>=0; $j--) {
13684: my $higher;
13685: if ($j > 0) {
13686: $higher = &escape($parents->[$j]).':'.
13687: &escape($parents->[$j-1]).':'.$j;
13688: } else {
13689: $higher = &escape($parents->[$j]).'::'.$j;
13690: }
13691: push(@{$subcats->{$higher}},$subcat);
13692: }
13693: }
13694: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13695: $subcats);
1.655 raeburn 13696: pop(@{$parents});
13697: }
13698: } else {
13699: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13700: my $trailstr = join(' -> ',(@{$parents},$category));
13701: if ($allitems->{$item} eq '') {
13702: push(@{$trails},$trailstr);
13703: $allitems->{$item} = scalar(@{$trails})-1;
13704: }
13705: }
13706: return;
13707: }
13708:
1.663 raeburn 13709: =pod
13710:
1.1075.2.56 raeburn 13711: =item * &assign_categories_table()
1.663 raeburn 13712:
13713: Create a datatable for display of hierarchical categories in a domain,
13714: with checkboxes to allow a course to be categorized.
13715:
13716: Inputs:
13717:
13718: cathash - reference to hash of categories defined for the domain (from
13719: configuration.db)
13720:
13721: currcat - scalar with an & separated list of categories assigned to a course.
13722:
1.919 raeburn 13723: type - scalar contains course type (Course or Community).
13724:
1.663 raeburn 13725: Returns: $output (markup to be displayed)
13726:
13727: =cut
13728:
13729: sub assign_categories_table {
1.919 raeburn 13730: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13731: my $output;
13732: if (ref($cathash) eq 'HASH') {
13733: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13734: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13735: $maxdepth = scalar(@cats);
13736: if (@cats > 0) {
13737: my $itemcount = 0;
13738: if (ref($cats[0]) eq 'ARRAY') {
13739: my @currcategories;
13740: if ($currcat ne '') {
13741: @currcategories = split('&',$currcat);
13742: }
1.919 raeburn 13743: my $table;
1.663 raeburn 13744: for (my $i=0; $i<@{$cats[0]}; $i++) {
13745: my $parent = $cats[0][$i];
1.919 raeburn 13746: next if ($parent eq 'instcode');
13747: if ($type eq 'Community') {
13748: next unless ($parent eq 'communities');
13749: } else {
13750: next if ($parent eq 'communities');
13751: }
1.663 raeburn 13752: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13753: my $item = &escape($parent).'::0';
13754: my $checked = '';
13755: if (@currcategories > 0) {
13756: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13757: $checked = ' checked="checked"';
1.663 raeburn 13758: }
13759: }
1.919 raeburn 13760: my $parent_title = $parent;
13761: if ($parent eq 'communities') {
13762: $parent_title = &mt('Communities');
13763: }
13764: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13765: '<input type="checkbox" name="usecategory" value="'.
13766: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13767: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13768: my $depth = 1;
13769: push(@path,$parent);
1.919 raeburn 13770: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13771: pop(@path);
1.919 raeburn 13772: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13773: $itemcount ++;
13774: }
1.919 raeburn 13775: if ($itemcount) {
13776: $output = &Apache::loncommon::start_data_table().
13777: $table.
13778: &Apache::loncommon::end_data_table();
13779: }
1.663 raeburn 13780: }
13781: }
13782: }
13783: return $output;
13784: }
13785:
13786: =pod
13787:
1.1075.2.56 raeburn 13788: =item * &assign_category_rows()
1.663 raeburn 13789:
13790: Create a datatable row for display of nested categories in a domain,
13791: with checkboxes to allow a course to be categorized,called recursively.
13792:
13793: Inputs:
13794:
13795: itemcount - track row number for alternating colors
13796:
13797: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13798: categories and subcategories.
13799:
13800: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13801:
13802: parent - parent of current category item
13803:
13804: path - Array containing all categories back up through the hierarchy from the
13805: current category to the top level.
13806:
13807: currcategories - reference to array of current categories assigned to the course
13808:
13809: Returns: $output (markup to be displayed).
13810:
13811: =cut
13812:
13813: sub assign_category_rows {
13814: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13815: my ($text,$name,$item,$chgstr);
13816: if (ref($cats) eq 'ARRAY') {
13817: my $maxdepth = scalar(@{$cats});
13818: if (ref($cats->[$depth]) eq 'HASH') {
13819: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13820: my $numchildren = @{$cats->[$depth]{$parent}};
13821: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 13822: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13823: for (my $j=0; $j<$numchildren; $j++) {
13824: $name = $cats->[$depth]{$parent}[$j];
13825: $item = &escape($name).':'.&escape($parent).':'.$depth;
13826: my $deeper = $depth+1;
13827: my $checked = '';
13828: if (ref($currcategories) eq 'ARRAY') {
13829: if (@{$currcategories} > 0) {
13830: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13831: $checked = ' checked="checked"';
1.663 raeburn 13832: }
13833: }
13834: }
1.664 raeburn 13835: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13836: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13837: $item.'"'.$checked.' />'.$name.'</label></span>'.
13838: '<input type="hidden" name="catname" value="'.$name.'" />'.
13839: '</td><td>';
1.663 raeburn 13840: if (ref($path) eq 'ARRAY') {
13841: push(@{$path},$name);
13842: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13843: pop(@{$path});
13844: }
13845: $text .= '</td></tr>';
13846: }
13847: $text .= '</table></td>';
13848: }
13849: }
13850: }
13851: return $text;
13852: }
13853:
1.1075.2.69 raeburn 13854: =pod
13855:
13856: =back
13857:
13858: =cut
13859:
1.655 raeburn 13860: ############################################################
13861: ############################################################
13862:
13863:
1.443 albertel 13864: sub commit_customrole {
1.664 raeburn 13865: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13866: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13867: ($start?', '.&mt('starting').' '.localtime($start):'').
13868: ($end?', ending '.localtime($end):'').': <b>'.
13869: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13870: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13871: '</b><br />';
13872: return $output;
13873: }
13874:
13875: sub commit_standardrole {
1.1075.2.31 raeburn 13876: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13877: my ($output,$logmsg,$linefeed);
13878: if ($context eq 'auto') {
13879: $linefeed = "\n";
13880: } else {
13881: $linefeed = "<br />\n";
13882: }
1.443 albertel 13883: if ($three eq 'st') {
1.541 raeburn 13884: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 13885: $one,$two,$sec,$context,$credits);
1.541 raeburn 13886: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13887: ($result eq 'unknown_course') || ($result eq 'refused')) {
13888: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13889: } else {
1.541 raeburn 13890: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13891: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13892: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13893: if ($context eq 'auto') {
13894: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13895: } else {
13896: $output .= '<b>'.$result.'</b>'.$linefeed.
13897: &mt('Add to classlist').': <b>ok</b>';
13898: }
13899: $output .= $linefeed;
1.443 albertel 13900: }
13901: } else {
13902: $output = &mt('Assigning').' '.$three.' in '.$url.
13903: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13904: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13905: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13906: if ($context eq 'auto') {
13907: $output .= $result.$linefeed;
13908: } else {
13909: $output .= '<b>'.$result.'</b>'.$linefeed;
13910: }
1.443 albertel 13911: }
13912: return $output;
13913: }
13914:
13915: sub commit_studentrole {
1.1075.2.31 raeburn 13916: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13917: $credits) = @_;
1.626 raeburn 13918: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13919: if ($context eq 'auto') {
13920: $linefeed = "\n";
13921: } else {
13922: $linefeed = '<br />'."\n";
13923: }
1.443 albertel 13924: if (defined($one) && defined($two)) {
13925: my $cid=$one.'_'.$two;
13926: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13927: my $secchange = 0;
13928: my $expire_role_result;
13929: my $modify_section_result;
1.628 raeburn 13930: if ($oldsec ne '-1') {
13931: if ($oldsec ne $sec) {
1.443 albertel 13932: $secchange = 1;
1.628 raeburn 13933: my $now = time;
1.443 albertel 13934: my $uurl='/'.$cid;
13935: $uurl=~s/\_/\//g;
13936: if ($oldsec) {
13937: $uurl.='/'.$oldsec;
13938: }
1.626 raeburn 13939: $oldsecurl = $uurl;
1.628 raeburn 13940: $expire_role_result =
1.652 raeburn 13941: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13942: if ($env{'request.course.sec'} ne '') {
13943: if ($expire_role_result eq 'refused') {
13944: my @roles = ('st');
13945: my @statuses = ('previous');
13946: my @roledoms = ($one);
13947: my $withsec = 1;
13948: my %roleshash =
13949: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13950: \@statuses,\@roles,\@roledoms,$withsec);
13951: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13952: my ($oldstart,$oldend) =
13953: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13954: if ($oldend > 0 && $oldend <= $now) {
13955: $expire_role_result = 'ok';
13956: }
13957: }
13958: }
13959: }
1.443 albertel 13960: $result = $expire_role_result;
13961: }
13962: }
13963: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 13964: $modify_section_result =
13965: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13966: undef,undef,undef,$sec,
13967: $end,$start,'','',$cid,
13968: '',$context,$credits);
1.443 albertel 13969: if ($modify_section_result =~ /^ok/) {
13970: if ($secchange == 1) {
1.628 raeburn 13971: if ($sec eq '') {
13972: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13973: } else {
13974: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13975: }
1.443 albertel 13976: } elsif ($oldsec eq '-1') {
1.628 raeburn 13977: if ($sec eq '') {
13978: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13979: } else {
13980: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13981: }
1.443 albertel 13982: } else {
1.628 raeburn 13983: if ($sec eq '') {
13984: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13985: } else {
13986: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13987: }
1.443 albertel 13988: }
13989: } else {
1.628 raeburn 13990: if ($secchange) {
13991: $$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;
13992: } else {
13993: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13994: }
1.443 albertel 13995: }
13996: $result = $modify_section_result;
13997: } elsif ($secchange == 1) {
1.628 raeburn 13998: if ($oldsec eq '') {
1.1075.2.20 raeburn 13999: $$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 14000: } else {
14001: $$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;
14002: }
1.626 raeburn 14003: if ($expire_role_result eq 'refused') {
14004: my $newsecurl = '/'.$cid;
14005: $newsecurl =~ s/\_/\//g;
14006: if ($sec ne '') {
14007: $newsecurl.='/'.$sec;
14008: }
14009: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14010: if ($sec eq '') {
14011: $$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;
14012: } else {
14013: $$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;
14014: }
14015: }
14016: }
1.443 albertel 14017: }
14018: } else {
1.626 raeburn 14019: $$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 14020: $result = "error: incomplete course id\n";
14021: }
14022: return $result;
14023: }
14024:
1.1075.2.25 raeburn 14025: sub show_role_extent {
14026: my ($scope,$context,$role) = @_;
14027: $scope =~ s{^/}{};
14028: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14029: push(@courseroles,'co');
14030: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14031: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14032: $scope =~ s{/}{_};
14033: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14034: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14035: my ($audom,$auname) = split(/\//,$scope);
14036: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14037: &Apache::loncommon::plainname($auname,$audom).'</span>');
14038: } else {
14039: $scope =~ s{/$}{};
14040: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14041: &Apache::lonnet::domain($scope,'description').'</span>');
14042: }
14043: }
14044:
1.443 albertel 14045: ############################################################
14046: ############################################################
14047:
1.566 albertel 14048: sub check_clone {
1.578 raeburn 14049: my ($args,$linefeed) = @_;
1.566 albertel 14050: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14051: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14052: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14053: my $clonemsg;
14054: my $can_clone = 0;
1.944 raeburn 14055: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14056: if ($lctype ne 'community') {
14057: $lctype = 'course';
14058: }
1.566 albertel 14059: if ($clonehome eq 'no_host') {
1.944 raeburn 14060: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14061: $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'});
14062: } else {
14063: $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'});
14064: }
1.566 albertel 14065: } else {
14066: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 14067: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14068: if ($clonedesc{'type'} ne 'Community') {
14069: $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'});
14070: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14071: }
14072: }
1.882 raeburn 14073: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
14074: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 14075: $can_clone = 1;
14076: } else {
14077: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
14078: $args->{'clonedomain'},$args->{'clonecourse'});
14079: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 14080: if (grep(/^\*$/,@cloners)) {
14081: $can_clone = 1;
14082: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
14083: $can_clone = 1;
14084: } else {
1.908 raeburn 14085: my $ccrole = 'cc';
1.944 raeburn 14086: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14087: $ccrole = 'co';
14088: }
1.578 raeburn 14089: my %roleshash =
14090: &Apache::lonnet::get_my_roles($args->{'ccuname'},
14091: $args->{'ccdomain'},
1.908 raeburn 14092: 'userroles',['active'],[$ccrole],
1.578 raeburn 14093: [$args->{'clonedomain'}]);
1.908 raeburn 14094: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 14095: $can_clone = 1;
14096: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
14097: $can_clone = 1;
14098: } else {
1.944 raeburn 14099: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14100: $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'});
14101: } else {
14102: $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'});
14103: }
1.578 raeburn 14104: }
1.566 albertel 14105: }
1.578 raeburn 14106: }
1.566 albertel 14107: }
14108: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14109: }
14110:
1.444 albertel 14111: sub construct_course {
1.1075.2.59 raeburn 14112: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 14113: my $outcome;
1.541 raeburn 14114: my $linefeed = '<br />'."\n";
14115: if ($context eq 'auto') {
14116: $linefeed = "\n";
14117: }
1.566 albertel 14118:
14119: #
14120: # Are we cloning?
14121: #
14122: my ($can_clone, $clonemsg, $cloneid, $clonehome);
14123: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 14124: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 14125: if ($context ne 'auto') {
1.578 raeburn 14126: if ($clonemsg ne '') {
14127: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
14128: }
1.566 albertel 14129: }
14130: $outcome .= $clonemsg.$linefeed;
14131:
14132: if (!$can_clone) {
14133: return (0,$outcome);
14134: }
14135: }
14136:
1.444 albertel 14137: #
14138: # Open course
14139: #
14140: my $crstype = lc($args->{'crstype'});
14141: my %cenv=();
14142: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
14143: $args->{'cdescr'},
14144: $args->{'curl'},
14145: $args->{'course_home'},
14146: $args->{'nonstandard'},
14147: $args->{'crscode'},
14148: $args->{'ccuname'}.':'.
14149: $args->{'ccdomain'},
1.882 raeburn 14150: $args->{'crstype'},
1.885 raeburn 14151: $cnum,$context,$category);
1.444 albertel 14152:
14153: # Note: The testing routines depend on this being output; see
14154: # Utils::Course. This needs to at least be output as a comment
14155: # if anyone ever decides to not show this, and Utils::Course::new
14156: # will need to be suitably modified.
1.541 raeburn 14157: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 14158: if ($$courseid =~ /^error:/) {
14159: return (0,$outcome);
14160: }
14161:
1.444 albertel 14162: #
14163: # Check if created correctly
14164: #
1.479 albertel 14165: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 14166: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 14167: if ($crsuhome eq 'no_host') {
14168: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
14169: return (0,$outcome);
14170: }
1.541 raeburn 14171: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 14172:
1.444 albertel 14173: #
1.566 albertel 14174: # Do the cloning
14175: #
14176: if ($can_clone && $cloneid) {
14177: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14178: if ($context ne 'auto') {
14179: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14180: }
14181: $outcome .= $clonemsg.$linefeed;
14182: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14183: # Copy all files
1.637 www 14184: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14185: # Restore URL
1.566 albertel 14186: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14187: # Restore title
1.566 albertel 14188: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14189: # Restore creation date, creator and creation context.
14190: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14191: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14192: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14193: # Mark as cloned
1.566 albertel 14194: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14195: # Need to clone grading mode
14196: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14197: $cenv{'grading'}=$newenv{'grading'};
14198: # Do not clone these environment entries
14199: &Apache::lonnet::del('environment',
14200: ['default_enrollment_start_date',
14201: 'default_enrollment_end_date',
14202: 'question.email',
14203: 'policy.email',
14204: 'comment.email',
14205: 'pch.users.denied',
1.725 raeburn 14206: 'plc.users.denied',
14207: 'hidefromcat',
1.1075.2.36 raeburn 14208: 'checkforpriv',
1.1075.2.59 raeburn 14209: 'categories',
14210: 'internal.uniquecode'],
1.638 www 14211: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 14212: if ($args->{'textbook'}) {
14213: $cenv{'internal.textbook'} = $args->{'textbook'};
14214: }
1.444 albertel 14215: }
1.566 albertel 14216:
1.444 albertel 14217: #
14218: # Set environment (will override cloned, if existing)
14219: #
14220: my @sections = ();
14221: my @xlists = ();
14222: if ($args->{'crstype'}) {
14223: $cenv{'type'}=$args->{'crstype'};
14224: }
14225: if ($args->{'crsid'}) {
14226: $cenv{'courseid'}=$args->{'crsid'};
14227: }
14228: if ($args->{'crscode'}) {
14229: $cenv{'internal.coursecode'}=$args->{'crscode'};
14230: }
14231: if ($args->{'crsquota'} ne '') {
14232: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14233: } else {
14234: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14235: }
14236: if ($args->{'ccuname'}) {
14237: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14238: ':'.$args->{'ccdomain'};
14239: } else {
14240: $cenv{'internal.courseowner'} = $args->{'curruser'};
14241: }
1.1075.2.31 raeburn 14242: if ($args->{'defaultcredits'}) {
14243: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14244: }
1.444 albertel 14245: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14246: if ($args->{'crssections'}) {
14247: $cenv{'internal.sectionnums'} = '';
14248: if ($args->{'crssections'} =~ m/,/) {
14249: @sections = split/,/,$args->{'crssections'};
14250: } else {
14251: $sections[0] = $args->{'crssections'};
14252: }
14253: if (@sections > 0) {
14254: foreach my $item (@sections) {
14255: my ($sec,$gp) = split/:/,$item;
14256: my $class = $args->{'crscode'}.$sec;
14257: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14258: $cenv{'internal.sectionnums'} .= $item.',';
14259: unless ($addcheck eq 'ok') {
14260: push @badclasses, $class;
14261: }
14262: }
14263: $cenv{'internal.sectionnums'} =~ s/,$//;
14264: }
14265: }
14266: # do not hide course coordinator from staff listing,
14267: # even if privileged
14268: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 14269: # add course coordinator's domain to domains to check for privileged users
14270: # if different to course domain
14271: if ($$crsudom ne $args->{'ccdomain'}) {
14272: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14273: }
1.444 albertel 14274: # add crosslistings
14275: if ($args->{'crsxlist'}) {
14276: $cenv{'internal.crosslistings'}='';
14277: if ($args->{'crsxlist'} =~ m/,/) {
14278: @xlists = split/,/,$args->{'crsxlist'};
14279: } else {
14280: $xlists[0] = $args->{'crsxlist'};
14281: }
14282: if (@xlists > 0) {
14283: foreach my $item (@xlists) {
14284: my ($xl,$gp) = split/:/,$item;
14285: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14286: $cenv{'internal.crosslistings'} .= $item.',';
14287: unless ($addcheck eq 'ok') {
14288: push @badclasses, $xl;
14289: }
14290: }
14291: $cenv{'internal.crosslistings'} =~ s/,$//;
14292: }
14293: }
14294: if ($args->{'autoadds'}) {
14295: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14296: }
14297: if ($args->{'autodrops'}) {
14298: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14299: }
14300: # check for notification of enrollment changes
14301: my @notified = ();
14302: if ($args->{'notify_owner'}) {
14303: if ($args->{'ccuname'} ne '') {
14304: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14305: }
14306: }
14307: if ($args->{'notify_dc'}) {
14308: if ($uname ne '') {
1.630 raeburn 14309: push(@notified,$uname.':'.$udom);
1.444 albertel 14310: }
14311: }
14312: if (@notified > 0) {
14313: my $notifylist;
14314: if (@notified > 1) {
14315: $notifylist = join(',',@notified);
14316: } else {
14317: $notifylist = $notified[0];
14318: }
14319: $cenv{'internal.notifylist'} = $notifylist;
14320: }
14321: if (@badclasses > 0) {
14322: my %lt=&Apache::lonlocal::texthash(
14323: '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',
14324: 'dnhr' => 'does not have rights to access enrollment in these classes',
14325: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14326: );
1.541 raeburn 14327: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14328: ' ('.$lt{'adby'}.')';
14329: if ($context eq 'auto') {
14330: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14331: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14332: foreach my $item (@badclasses) {
14333: if ($context eq 'auto') {
14334: $outcome .= " - $item\n";
14335: } else {
14336: $outcome .= "<li>$item</li>\n";
14337: }
14338: }
14339: if ($context eq 'auto') {
14340: $outcome .= $linefeed;
14341: } else {
1.566 albertel 14342: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14343: }
14344: }
1.444 albertel 14345: }
14346: if ($args->{'no_end_date'}) {
14347: $args->{'endaccess'} = 0;
14348: }
14349: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14350: $cenv{'internal.autoend'}=$args->{'enrollend'};
14351: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14352: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14353: if ($args->{'showphotos'}) {
14354: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14355: }
14356: $cenv{'internal.authtype'} = $args->{'authtype'};
14357: $cenv{'internal.autharg'} = $args->{'autharg'};
14358: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14359: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14360: 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');
14361: if ($context eq 'auto') {
14362: $outcome .= $krb_msg;
14363: } else {
1.566 albertel 14364: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14365: }
14366: $outcome .= $linefeed;
1.444 albertel 14367: }
14368: }
14369: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14370: if ($args->{'setpolicy'}) {
14371: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14372: }
14373: if ($args->{'setcontent'}) {
14374: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14375: }
14376: }
14377: if ($args->{'reshome'}) {
14378: $cenv{'reshome'}=$args->{'reshome'}.'/';
14379: $cenv{'reshome'}=~s/\/+$/\//;
14380: }
14381: #
14382: # course has keyed access
14383: #
14384: if ($args->{'setkeys'}) {
14385: $cenv{'keyaccess'}='yes';
14386: }
14387: # if specified, key authority is not course, but user
14388: # only active if keyaccess is yes
14389: if ($args->{'keyauth'}) {
1.487 albertel 14390: my ($user,$domain) = split(':',$args->{'keyauth'});
14391: $user = &LONCAPA::clean_username($user);
14392: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14393: if ($user ne '' && $domain ne '') {
1.487 albertel 14394: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14395: }
14396: }
14397:
1.1075.2.59 raeburn 14398: #
14399: # generate and store uniquecode (available to course requester), if course should have one.
14400: #
14401: if ($args->{'uniquecode'}) {
14402: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14403: if ($code) {
14404: $cenv{'internal.uniquecode'} = $code;
14405: my %crsinfo =
14406: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
14407: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
14408: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
14409: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
14410: }
14411: if (ref($coderef)) {
14412: $$coderef = $code;
14413: }
14414: }
14415: }
14416:
1.444 albertel 14417: if ($args->{'disresdis'}) {
14418: $cenv{'pch.roles.denied'}='st';
14419: }
14420: if ($args->{'disablechat'}) {
14421: $cenv{'plc.roles.denied'}='st';
14422: }
14423:
14424: # Record we've not yet viewed the Course Initialization Helper for this
14425: # course
14426: $cenv{'course.helper.not.run'} = 1;
14427: #
14428: # Use new Randomseed
14429: #
14430: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14431: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14432: #
14433: # The encryption code and receipt prefix for this course
14434: #
14435: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14436: $cenv{'internal.encpref'}=100+int(9*rand(99));
14437: #
14438: # By default, use standard grading
14439: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14440:
1.541 raeburn 14441: $outcome .= $linefeed.&mt('Setting environment').': '.
14442: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14443: #
14444: # Open all assignments
14445: #
14446: if ($args->{'openall'}) {
14447: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14448: my %storecontent = ($storeunder => time,
14449: $storeunder.'.type' => 'date_start');
14450:
14451: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14452: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14453: }
14454: #
14455: # Set first page
14456: #
14457: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14458: || ($cloneid)) {
1.445 albertel 14459: use LONCAPA::map;
1.444 albertel 14460: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14461:
14462: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14463: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14464:
1.444 albertel 14465: $outcome .= ($fatal?$errtext:'read ok').' - ';
14466: my $title; my $url;
14467: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14468: $title=&mt('Syllabus');
1.444 albertel 14469: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14470: } else {
1.963 raeburn 14471: $title=&mt('Table of Contents');
1.444 albertel 14472: $url='/adm/navmaps';
14473: }
1.445 albertel 14474:
14475: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14476: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14477:
14478: if ($errtext) { $fatal=2; }
1.541 raeburn 14479: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14480: }
1.566 albertel 14481:
14482: return (1,$outcome);
1.444 albertel 14483: }
14484:
1.1075.2.59 raeburn 14485: sub make_unique_code {
14486: my ($cdom,$cnum) = @_;
14487: # get lock on uniquecodes db
14488: my $lockhash = {
14489: $cnum."\0".'uniquecodes' => $env{'user.name'}.
14490: ':'.$env{'user.domain'},
14491: };
14492: my $tries = 0;
14493: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14494: my ($code,$error);
14495:
14496: while (($gotlock ne 'ok') && ($tries<3)) {
14497: $tries ++;
14498: sleep 1;
14499: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14500: }
14501: if ($gotlock eq 'ok') {
14502: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
14503: my $gotcode;
14504: my $attempts = 0;
14505: while ((!$gotcode) && ($attempts < 100)) {
14506: $code = &generate_code();
14507: if (!exists($currcodes{$code})) {
14508: $gotcode = 1;
14509: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
14510: $error = 'nostore';
14511: }
14512: }
14513: $attempts ++;
14514: }
14515: my @del_lock = ($cnum."\0".'uniquecodes');
14516: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
14517: } else {
14518: $error = 'nolock';
14519: }
14520: return ($code,$error);
14521: }
14522:
14523: sub generate_code {
14524: my $code;
14525: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
14526: for (my $i=0; $i<6; $i++) {
14527: my $lettnum = int (rand 2);
14528: my $item = '';
14529: if ($lettnum) {
14530: $item = $letts[int( rand(18) )];
14531: } else {
14532: $item = 1+int( rand(8) );
14533: }
14534: $code .= $item;
14535: }
14536: return $code;
14537: }
14538:
1.444 albertel 14539: ############################################################
14540: ############################################################
14541:
1.953 droeschl 14542: #SD
14543: # only Community and Course, or anything else?
1.378 raeburn 14544: sub course_type {
14545: my ($cid) = @_;
14546: if (!defined($cid)) {
14547: $cid = $env{'request.course.id'};
14548: }
1.404 albertel 14549: if (defined($env{'course.'.$cid.'.type'})) {
14550: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14551: } else {
14552: return 'Course';
1.377 raeburn 14553: }
14554: }
1.156 albertel 14555:
1.406 raeburn 14556: sub group_term {
14557: my $crstype = &course_type();
14558: my %names = (
14559: 'Course' => 'group',
1.865 raeburn 14560: 'Community' => 'group',
1.406 raeburn 14561: );
14562: return $names{$crstype};
14563: }
14564:
1.902 raeburn 14565: sub course_types {
1.1075.2.59 raeburn 14566: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 14567: my %typename = (
14568: official => 'Official course',
14569: unofficial => 'Unofficial course',
14570: community => 'Community',
1.1075.2.59 raeburn 14571: textbook => 'Textbook course',
1.902 raeburn 14572: );
14573: return (\@types,\%typename);
14574: }
14575:
1.156 albertel 14576: sub icon {
14577: my ($file)=@_;
1.505 albertel 14578: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14579: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14580: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14581: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14582: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14583: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14584: $curfext.".gif") {
14585: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14586: $curfext.".gif";
14587: }
14588: }
1.249 albertel 14589: return &lonhttpdurl($iconname);
1.154 albertel 14590: }
1.84 albertel 14591:
1.575 albertel 14592: sub lonhttpdurl {
1.692 www 14593: #
14594: # Had been used for "small fry" static images on separate port 8080.
14595: # Modify here if lightweight http functionality desired again.
14596: # Currently eliminated due to increasing firewall issues.
14597: #
1.575 albertel 14598: my ($url)=@_;
1.692 www 14599: return $url;
1.215 albertel 14600: }
14601:
1.213 albertel 14602: sub connection_aborted {
14603: my ($r)=@_;
14604: $r->print(" ");$r->rflush();
14605: my $c = $r->connection;
14606: return $c->aborted();
14607: }
14608:
1.221 foxr 14609: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14610: # strings as 'strings'.
14611: sub escape_single {
1.221 foxr 14612: my ($input) = @_;
1.223 albertel 14613: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14614: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14615: return $input;
14616: }
1.223 albertel 14617:
1.222 foxr 14618: # Same as escape_single, but escape's "'s This
14619: # can be used for "strings"
14620: sub escape_double {
14621: my ($input) = @_;
14622: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14623: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14624: return $input;
14625: }
1.223 albertel 14626:
1.222 foxr 14627: # Escapes the last element of a full URL.
14628: sub escape_url {
14629: my ($url) = @_;
1.238 raeburn 14630: my @urlslices = split(/\//, $url,-1);
1.369 www 14631: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 14632: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 14633: }
1.462 albertel 14634:
1.820 raeburn 14635: sub compare_arrays {
14636: my ($arrayref1,$arrayref2) = @_;
14637: my (@difference,%count);
14638: @difference = ();
14639: %count = ();
14640: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14641: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14642: foreach my $element (keys(%count)) {
14643: if ($count{$element} == 1) {
14644: push(@difference,$element);
14645: }
14646: }
14647: }
14648: return @difference;
14649: }
14650:
1.817 bisitz 14651: # -------------------------------------------------------- Initialize user login
1.462 albertel 14652: sub init_user_environment {
1.463 albertel 14653: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14654: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14655:
14656: my $public=($username eq 'public' && $domain eq 'public');
14657:
14658: # See if old ID present, if so, remove
14659:
1.1062 raeburn 14660: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14661: my $now=time;
14662:
14663: if ($public) {
14664: my $max_public=100;
14665: my $oldest;
14666: my $oldest_time=0;
14667: for(my $next=1;$next<=$max_public;$next++) {
14668: if (-e $lonids."/publicuser_$next.id") {
14669: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14670: if ($mtime<$oldest_time || !$oldest_time) {
14671: $oldest_time=$mtime;
14672: $oldest=$next;
14673: }
14674: } else {
14675: $cookie="publicuser_$next";
14676: last;
14677: }
14678: }
14679: if (!$cookie) { $cookie="publicuser_$oldest"; }
14680: } else {
1.463 albertel 14681: # if this isn't a robot, kill any existing non-robot sessions
14682: if (!$args->{'robot'}) {
14683: opendir(DIR,$lonids);
14684: while ($filename=readdir(DIR)) {
14685: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14686: unlink($lonids.'/'.$filename);
14687: }
1.462 albertel 14688: }
1.463 albertel 14689: closedir(DIR);
1.1075.2.84 raeburn 14690: # If there is a undeleted lockfile for the user's paste buffer remove it.
14691: my $namespace = 'nohist_courseeditor';
14692: my $lockingkey = 'paste'."\0".'locked_num';
14693: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
14694: $domain,$username);
14695: if (exists($lockhash{$lockingkey})) {
14696: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
14697: unless ($delresult eq 'ok') {
14698: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
14699: }
14700: }
1.462 albertel 14701: }
14702: # Give them a new cookie
1.463 albertel 14703: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14704: : $now.$$.int(rand(10000)));
1.463 albertel 14705: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14706:
14707: # Initialize roles
14708:
1.1062 raeburn 14709: ($userroles,$firstaccenv,$timerintenv) =
14710: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14711: }
14712: # ------------------------------------ Check browser type and MathML capability
14713:
1.1075.2.77 raeburn 14714: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
14715: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 14716:
14717: # ------------------------------------------------------------- Get environment
14718:
14719: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14720: my ($tmp) = keys(%userenv);
14721: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14722: } else {
14723: undef(%userenv);
14724: }
14725: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14726: $form->{'interface'}=$userenv{'interface'};
14727: }
14728: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14729:
14730: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14731: foreach my $option ('interface','localpath','localres') {
14732: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14733: }
14734: # --------------------------------------------------------- Write first profile
14735:
14736: {
14737: my %initial_env =
14738: ("user.name" => $username,
14739: "user.domain" => $domain,
14740: "user.home" => $authhost,
14741: "browser.type" => $clientbrowser,
14742: "browser.version" => $clientversion,
14743: "browser.mathml" => $clientmathml,
14744: "browser.unicode" => $clientunicode,
14745: "browser.os" => $clientos,
1.1075.2.42 raeburn 14746: "browser.mobile" => $clientmobile,
14747: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 14748: "browser.osversion" => $clientosversion,
1.462 albertel 14749: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14750: "request.course.fn" => '',
14751: "request.course.uri" => '',
14752: "request.course.sec" => '',
14753: "request.role" => 'cm',
14754: "request.role.adv" => $env{'user.adv'},
14755: "request.host" => $ENV{'REMOTE_ADDR'},);
14756:
14757: if ($form->{'localpath'}) {
14758: $initial_env{"browser.localpath"} = $form->{'localpath'};
14759: $initial_env{"browser.localres"} = $form->{'localres'};
14760: }
14761:
14762: if ($form->{'interface'}) {
14763: $form->{'interface'}=~s/\W//gs;
14764: $initial_env{"browser.interface"} = $form->{'interface'};
14765: $env{'browser.interface'}=$form->{'interface'};
14766: }
14767:
1.1075.2.54 raeburn 14768: if ($form->{'iptoken'}) {
14769: my $lonhost = $r->dir_config('lonHostID');
14770: $initial_env{"user.noloadbalance"} = $lonhost;
14771: $env{'user.noloadbalance'} = $lonhost;
14772: }
14773:
1.981 raeburn 14774: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14775: my %domdef;
14776: unless ($domain eq 'public') {
14777: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14778: }
1.980 raeburn 14779:
1.1075.2.7 raeburn 14780: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14781: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14782: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14783: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14784: }
14785:
1.1075.2.59 raeburn 14786: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 14787: $userenv{'canrequest.'.$crstype} =
14788: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14789: 'reload','requestcourses',
14790: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14791: }
14792:
1.1075.2.14 raeburn 14793: $userenv{'canrequest.author'} =
14794: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14795: 'reload','requestauthor',
14796: \%userenv,\%domdef,\%is_adv);
14797: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14798: $domain,$username);
14799: my $reqstatus = $reqauthor{'author_status'};
14800: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14801: if (ref($reqauthor{'author'}) eq 'HASH') {
14802: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14803: $reqauthor{'author'}{'timestamp'};
14804: }
14805: }
14806:
1.462 albertel 14807: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14808:
1.462 albertel 14809: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14810: &GDBM_WRCREAT(),0640)) {
14811: &_add_to_env(\%disk_env,\%initial_env);
14812: &_add_to_env(\%disk_env,\%userenv,'environment.');
14813: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14814: if (ref($firstaccenv) eq 'HASH') {
14815: &_add_to_env(\%disk_env,$firstaccenv);
14816: }
14817: if (ref($timerintenv) eq 'HASH') {
14818: &_add_to_env(\%disk_env,$timerintenv);
14819: }
1.463 albertel 14820: if (ref($args->{'extra_env'})) {
14821: &_add_to_env(\%disk_env,$args->{'extra_env'});
14822: }
1.462 albertel 14823: untie(%disk_env);
14824: } else {
1.705 tempelho 14825: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14826: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14827: return 'error: '.$!;
14828: }
14829: }
14830: $env{'request.role'}='cm';
14831: $env{'request.role.adv'}=$env{'user.adv'};
14832: $env{'browser.type'}=$clientbrowser;
14833:
14834: return $cookie;
14835:
14836: }
14837:
14838: sub _add_to_env {
14839: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14840: if (ref($env_data) eq 'HASH') {
14841: while (my ($key,$value) = each(%$env_data)) {
14842: $idf->{$prefix.$key} = $value;
14843: $env{$prefix.$key} = $value;
14844: }
1.462 albertel 14845: }
14846: }
14847:
1.685 tempelho 14848: # --- Get the symbolic name of a problem and the url
14849: sub get_symb {
14850: my ($request,$silent) = @_;
1.726 raeburn 14851: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14852: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14853: if ($symb eq '') {
14854: if (!$silent) {
1.1071 raeburn 14855: if (ref($request)) {
14856: $request->print("Unable to handle ambiguous references:$url:.");
14857: }
1.685 tempelho 14858: return ();
14859: }
14860: }
14861: &Apache::lonenc::check_decrypt(\$symb);
14862: return ($symb);
14863: }
14864:
14865: # --------------------------------------------------------------Get annotation
14866:
14867: sub get_annotation {
14868: my ($symb,$enc) = @_;
14869:
14870: my $key = $symb;
14871: if (!$enc) {
14872: $key =
14873: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14874: }
14875: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14876: return $annotation{$key};
14877: }
14878:
14879: sub clean_symb {
1.731 raeburn 14880: my ($symb,$delete_enc) = @_;
1.685 tempelho 14881:
14882: &Apache::lonenc::check_decrypt(\$symb);
14883: my $enc = $env{'request.enc'};
1.731 raeburn 14884: if ($delete_enc) {
1.730 raeburn 14885: delete($env{'request.enc'});
14886: }
1.685 tempelho 14887:
14888: return ($symb,$enc);
14889: }
1.462 albertel 14890:
1.1075.2.69 raeburn 14891: ############################################################
14892: ############################################################
14893:
14894: =pod
14895:
14896: =head1 Routines for building display used to search for courses
14897:
14898:
14899: =over 4
14900:
14901: =item * &build_filters()
14902:
14903: Create markup for a table used to set filters to use when selecting
14904: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
14905: and quotacheck.pl
14906:
14907:
14908: Inputs:
14909:
14910: filterlist - anonymous array of fields to include as potential filters
14911:
14912: crstype - course type
14913:
14914: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
14915: to pop-open a course selector (will contain "extra element").
14916:
14917: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
14918:
14919: filter - anonymous hash of criteria and their values
14920:
14921: action - form action
14922:
14923: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
14924:
14925: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
14926:
14927: cloneruname - username of owner of new course who wants to clone
14928:
14929: clonerudom - domain of owner of new course who wants to clone
14930:
14931: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
14932:
14933: codetitlesref - reference to array of titles of components in institutional codes (official courses)
14934:
14935: codedom - domain
14936:
14937: formname - value of form element named "form".
14938:
14939: fixeddom - domain, if fixed.
14940:
14941: prevphase - value to assign to form element named "phase" when going back to the previous screen
14942:
14943: cnameelement - name of form element in form on opener page which will receive title of selected course
14944:
14945: cnumelement - name of form element in form on opener page which will receive courseID of selected course
14946:
14947: cdomelement - name of form element in form on opener page which will receive domain of selected course
14948:
14949: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
14950:
14951: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
14952:
14953: clonewarning - warning message about missing information for intended course owner when DC creates a course
14954:
14955:
14956: Returns: $output - HTML for display of search criteria, and hidden form elements.
14957:
14958:
14959: Side Effects: None
14960:
14961: =cut
14962:
14963: # ---------------------------------------------- search for courses based on last activity etc.
14964:
14965: sub build_filters {
14966: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
14967: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
14968: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
14969: $cnameelement,$cnumelement,$cdomelement,$setroles,
14970: $clonetext,$clonewarning) = @_;
14971: my ($list,$jscript);
14972: my $onchange = 'javascript:updateFilters(this)';
14973: my ($domainselectform,$sincefilterform,$createdfilterform,
14974: $ownerdomselectform,$persondomselectform,$instcodeform,
14975: $typeselectform,$instcodetitle);
14976: if ($formname eq '') {
14977: $formname = $caller;
14978: }
14979: foreach my $item (@{$filterlist}) {
14980: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
14981: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
14982: if ($item eq 'domainfilter') {
14983: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
14984: } elsif ($item eq 'coursefilter') {
14985: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
14986: } elsif ($item eq 'ownerfilter') {
14987: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
14988: } elsif ($item eq 'ownerdomfilter') {
14989: $filter->{'ownerdomfilter'} =
14990: &LONCAPA::clean_domain($filter->{$item});
14991: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
14992: 'ownerdomfilter',1);
14993: } elsif ($item eq 'personfilter') {
14994: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
14995: } elsif ($item eq 'persondomfilter') {
14996: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
14997: 'persondomfilter',1);
14998: } else {
14999: $filter->{$item} =~ s/\W//g;
15000: }
15001: if (!$filter->{$item}) {
15002: $filter->{$item} = '';
15003: }
15004: }
15005: if ($item eq 'domainfilter') {
15006: my $allow_blank = 1;
15007: if ($formname eq 'portform') {
15008: $allow_blank=0;
15009: } elsif ($formname eq 'studentform') {
15010: $allow_blank=0;
15011: }
15012: if ($fixeddom) {
15013: $domainselectform = '<input type="hidden" name="domainfilter"'.
15014: ' value="'.$codedom.'" />'.
15015: &Apache::lonnet::domain($codedom,'description');
15016: } else {
15017: $domainselectform = &select_dom_form($filter->{$item},
15018: 'domainfilter',
15019: $allow_blank,'',$onchange);
15020: }
15021: } else {
15022: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
15023: }
15024: }
15025:
15026: # last course activity filter and selection
15027: $sincefilterform = &timebased_select_form('sincefilter',$filter);
15028:
15029: # course created filter and selection
15030: if (exists($filter->{'createdfilter'})) {
15031: $createdfilterform = &timebased_select_form('createdfilter',$filter);
15032: }
15033:
15034: my %lt = &Apache::lonlocal::texthash(
15035: 'cac' => "$crstype Activity",
15036: 'ccr' => "$crstype Created",
15037: 'cde' => "$crstype Title",
15038: 'cdo' => "$crstype Domain",
15039: 'ins' => 'Institutional Code',
15040: 'inc' => 'Institutional Categorization',
15041: 'cow' => "$crstype Owner/Co-owner",
15042: 'cop' => "$crstype Personnel Includes",
15043: 'cog' => 'Type',
15044: );
15045:
15046: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15047: my $typeval = 'Course';
15048: if ($crstype eq 'Community') {
15049: $typeval = 'Community';
15050: }
15051: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
15052: } else {
15053: $typeselectform = '<select name="type" size="1"';
15054: if ($onchange) {
15055: $typeselectform .= ' onchange="'.$onchange.'"';
15056: }
15057: $typeselectform .= '>'."\n";
15058: foreach my $posstype ('Course','Community') {
15059: $typeselectform.='<option value="'.$posstype.'"'.
15060: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
15061: }
15062: $typeselectform.="</select>";
15063: }
15064:
15065: my ($cloneableonlyform,$cloneabletitle);
15066: if (exists($filter->{'cloneableonly'})) {
15067: my $cloneableon = '';
15068: my $cloneableoff = ' checked="checked"';
15069: if ($filter->{'cloneableonly'}) {
15070: $cloneableon = $cloneableoff;
15071: $cloneableoff = '';
15072: }
15073: $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>';
15074: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 15075: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 15076: } else {
15077: $cloneabletitle = &mt('Cloneable by you');
15078: }
15079: }
15080: my $officialjs;
15081: if ($crstype eq 'Course') {
15082: if (exists($filter->{'instcodefilter'})) {
15083: # if (($fixeddom) || ($formname eq 'requestcrs') ||
15084: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
15085: if ($codedom) {
15086: $officialjs = 1;
15087: ($instcodeform,$jscript,$$numtitlesref) =
15088: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
15089: $officialjs,$codetitlesref);
15090: if ($jscript) {
15091: $jscript = '<script type="text/javascript">'."\n".
15092: '// <![CDATA['."\n".
15093: $jscript."\n".
15094: '// ]]>'."\n".
15095: '</script>'."\n";
15096: }
15097: }
15098: if ($instcodeform eq '') {
15099: $instcodeform =
15100: '<input type="text" name="instcodefilter" size="10" value="'.
15101: $list->{'instcodefilter'}.'" />';
15102: $instcodetitle = $lt{'ins'};
15103: } else {
15104: $instcodetitle = $lt{'inc'};
15105: }
15106: if ($fixeddom) {
15107: $instcodetitle .= '<br />('.$codedom.')';
15108: }
15109: }
15110: }
15111: my $output = qq|
15112: <form method="post" name="filterpicker" action="$action">
15113: <input type="hidden" name="form" value="$formname" />
15114: |;
15115: if ($formname eq 'modifycourse') {
15116: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
15117: '<input type="hidden" name="prevphase" value="'.
15118: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 15119: } elsif ($formname eq 'quotacheck') {
15120: $output .= qq|
15121: <input type="hidden" name="sortby" value="" />
15122: <input type="hidden" name="sortorder" value="" />
15123: |;
15124: } else {
1.1075.2.69 raeburn 15125: my $name_input;
15126: if ($cnameelement ne '') {
15127: $name_input = '<input type="hidden" name="cnameelement" value="'.
15128: $cnameelement.'" />';
15129: }
15130: $output .= qq|
15131: <input type="hidden" name="cnumelement" value="$cnumelement" />
15132: <input type="hidden" name="cdomelement" value="$cdomelement" />
15133: $name_input
15134: $roleelement
15135: $multelement
15136: $typeelement
15137: |;
15138: if ($formname eq 'portform') {
15139: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
15140: }
15141: }
15142: if ($fixeddom) {
15143: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
15144: }
15145: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
15146: if ($sincefilterform) {
15147: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
15148: .$sincefilterform
15149: .&Apache::lonhtmlcommon::row_closure();
15150: }
15151: if ($createdfilterform) {
15152: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
15153: .$createdfilterform
15154: .&Apache::lonhtmlcommon::row_closure();
15155: }
15156: if ($domainselectform) {
15157: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
15158: .$domainselectform
15159: .&Apache::lonhtmlcommon::row_closure();
15160: }
15161: if ($typeselectform) {
15162: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15163: $output .= $typeselectform;
15164: } else {
15165: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
15166: .$typeselectform
15167: .&Apache::lonhtmlcommon::row_closure();
15168: }
15169: }
15170: if ($instcodeform) {
15171: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
15172: .$instcodeform
15173: .&Apache::lonhtmlcommon::row_closure();
15174: }
15175: if (exists($filter->{'ownerfilter'})) {
15176: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
15177: '<table><tr><td>'.&mt('Username').'<br />'.
15178: '<input type="text" name="ownerfilter" size="20" value="'.
15179: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15180: $ownerdomselectform.'</td></tr></table>'.
15181: &Apache::lonhtmlcommon::row_closure();
15182: }
15183: if (exists($filter->{'personfilter'})) {
15184: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
15185: '<table><tr><td>'.&mt('Username').'<br />'.
15186: '<input type="text" name="personfilter" size="20" value="'.
15187: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15188: $persondomselectform.'</td></tr></table>'.
15189: &Apache::lonhtmlcommon::row_closure();
15190: }
15191: if (exists($filter->{'coursefilter'})) {
15192: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15193: .'<input type="text" name="coursefilter" size="25" value="'
15194: .$list->{'coursefilter'}.'" />'
15195: .&Apache::lonhtmlcommon::row_closure();
15196: }
15197: if ($cloneableonlyform) {
15198: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15199: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15200: }
15201: if (exists($filter->{'descriptfilter'})) {
15202: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15203: .'<input type="text" name="descriptfilter" size="40" value="'
15204: .$list->{'descriptfilter'}.'" />'
15205: .&Apache::lonhtmlcommon::row_closure(1);
15206: }
15207: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15208: '<input type="hidden" name="updater" value="" />'."\n".
15209: '<input type="submit" name="gosearch" value="'.
15210: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15211: return $jscript.$clonewarning.$output;
15212: }
15213:
15214: =pod
15215:
15216: =item * &timebased_select_form()
15217:
15218: Create markup for a dropdown list used to select a time-based
15219: filter e.g., Course Activity, Course Created, when searching for courses
15220: or communities
15221:
15222: Inputs:
15223:
15224: item - name of form element (sincefilter or createdfilter)
15225:
15226: filter - anonymous hash of criteria and their values
15227:
15228: Returns: HTML for a select box contained a blank, then six time selections,
15229: with value set in incoming form variables currently selected.
15230:
15231: Side Effects: None
15232:
15233: =cut
15234:
15235: sub timebased_select_form {
15236: my ($item,$filter) = @_;
15237: if (ref($filter) eq 'HASH') {
15238: $filter->{$item} =~ s/[^\d-]//g;
15239: if (!$filter->{$item}) { $filter->{$item}=-1; }
15240: return &select_form(
15241: $filter->{$item},
15242: $item,
15243: { '-1' => '',
15244: '86400' => &mt('today'),
15245: '604800' => &mt('last week'),
15246: '2592000' => &mt('last month'),
15247: '7776000' => &mt('last three months'),
15248: '15552000' => &mt('last six months'),
15249: '31104000' => &mt('last year'),
15250: 'select_form_order' =>
15251: ['-1','86400','604800','2592000','7776000',
15252: '15552000','31104000']});
15253: }
15254: }
15255:
15256: =pod
15257:
15258: =item * &js_changer()
15259:
15260: Create script tag containing Javascript used to submit course search form
15261: when course type or domain is changed, and also to hide 'Searching ...' on
15262: page load completion for page showing search result.
15263:
15264: Inputs: None
15265:
15266: Returns: markup containing updateFilters() and hideSearching() javascript functions.
15267:
15268: Side Effects: None
15269:
15270: =cut
15271:
15272: sub js_changer {
15273: return <<ENDJS;
15274: <script type="text/javascript">
15275: // <![CDATA[
15276: function updateFilters(caller) {
15277: if (typeof(caller) != "undefined") {
15278: document.filterpicker.updater.value = caller.name;
15279: }
15280: document.filterpicker.submit();
15281: }
15282:
15283: function hideSearching() {
15284: if (document.getElementById('searching')) {
15285: document.getElementById('searching').style.display = 'none';
15286: }
15287: return;
15288: }
15289:
15290: // ]]>
15291: </script>
15292:
15293: ENDJS
15294: }
15295:
15296: =pod
15297:
15298: =item * &search_courses()
15299:
15300: Process selected filters form course search form and pass to lonnet::courseiddump
15301: to retrieve a hash for which keys are courseIDs which match the selected filters.
15302:
15303: Inputs:
15304:
15305: dom - domain being searched
15306:
15307: type - course type ('Course' or 'Community' or '.' if any).
15308:
15309: filter - anonymous hash of criteria and their values
15310:
15311: numtitles - for institutional codes - number of categories
15312:
15313: cloneruname - optional username of new course owner
15314:
15315: clonerudom - optional domain of new course owner
15316:
15317: domcloner - Optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
15318: (used when DC is using course creation form)
15319:
15320: codetitles - reference to array of titles of components in institutional codes (official courses).
15321:
15322:
15323: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
15324:
15325:
15326: Side Effects: None
15327:
15328: =cut
15329:
15330:
15331: sub search_courses {
15332: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_;
15333: my (%courses,%showcourses,$cloner);
15334: if (($filter->{'ownerfilter'} ne '') ||
15335: ($filter->{'ownerdomfilter'} ne '')) {
15336: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
15337: $filter->{'ownerdomfilter'};
15338: }
15339: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
15340: if (!$filter->{$item}) {
15341: $filter->{$item}='.';
15342: }
15343: }
15344: my $now = time;
15345: my $timefilter =
15346: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
15347: my ($createdbefore,$createdafter);
15348: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
15349: $createdbefore = $now;
15350: $createdafter = $now-$filter->{'createdfilter'};
15351: }
15352: my ($instcodefilter,$regexpok);
15353: if ($numtitles) {
15354: if ($env{'form.official'} eq 'on') {
15355: $instcodefilter =
15356: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15357: $regexpok = 1;
15358: } elsif ($env{'form.official'} eq 'off') {
15359: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15360: unless ($instcodefilter eq '') {
15361: $regexpok = -1;
15362: }
15363: }
15364: } else {
15365: $instcodefilter = $filter->{'instcodefilter'};
15366: }
15367: if ($instcodefilter eq '') { $instcodefilter = '.'; }
15368: if ($type eq '') { $type = '.'; }
15369:
15370: if (($clonerudom ne '') && ($cloneruname ne '')) {
15371: $cloner = $cloneruname.':'.$clonerudom;
15372: }
15373: %courses = &Apache::lonnet::courseiddump($dom,
15374: $filter->{'descriptfilter'},
15375: $timefilter,
15376: $instcodefilter,
15377: $filter->{'combownerfilter'},
15378: $filter->{'coursefilter'},
15379: undef,undef,$type,$regexpok,undef,undef,
15380: undef,undef,$cloner,$env{'form.cc_clone'},
15381: $filter->{'cloneableonly'},
15382: $createdbefore,$createdafter,undef,
15383: $domcloner);
15384: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
15385: my $ccrole;
15386: if ($type eq 'Community') {
15387: $ccrole = 'co';
15388: } else {
15389: $ccrole = 'cc';
15390: }
15391: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
15392: $filter->{'persondomfilter'},
15393: 'userroles',undef,
15394: [$ccrole,'in','ad','ep','ta','cr'],
15395: $dom);
15396: foreach my $role (keys(%rolehash)) {
15397: my ($cnum,$cdom,$courserole) = split(':',$role);
15398: my $cid = $cdom.'_'.$cnum;
15399: if (exists($courses{$cid})) {
15400: if (ref($courses{$cid}) eq 'HASH') {
15401: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
15402: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
15403: push (@{$courses{$cid}{roles}},$courserole);
15404: }
15405: } else {
15406: $courses{$cid}{roles} = [$courserole];
15407: }
15408: $showcourses{$cid} = $courses{$cid};
15409: }
15410: }
15411: }
15412: %courses = %showcourses;
15413: }
15414: return %courses;
15415: }
15416:
15417: =pod
15418:
15419: =back
15420:
1.1075.2.88 raeburn 15421: =head1 Routines for version requirements for current course.
15422:
15423: =over 4
15424:
15425: =item * &check_release_required()
15426:
15427: Compares required LON-CAPA version with version on server, and
15428: if required version is newer looks for a server with the required version.
15429:
15430: Looks first at servers in user's owen domain; if none suitable, looks at
15431: servers in course's domain are permitted to host sessions for user's domain.
15432:
15433: Inputs:
15434:
15435: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
15436:
15437: $courseid - Course ID of current course
15438:
15439: $rolecode - User's current role in course (for switchserver query string).
15440:
15441: $required - LON-CAPA version needed by course (format: Major.Minor).
15442:
15443:
15444: Returns:
15445:
15446: $switchserver - query string tp append to /adm/switchserver call (if
15447: current server's LON-CAPA version is too old.
15448:
15449: $warning - Message is displayed if no suitable server could be found.
15450:
15451: =cut
15452:
15453: sub check_release_required {
15454: my ($loncaparev,$courseid,$rolecode,$required) = @_;
15455: my ($switchserver,$warning);
15456: if ($required ne '') {
15457: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
15458: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
15459: if ($reqdmajor ne '' && $reqdminor ne '') {
15460: my $otherserver;
15461: if (($major eq '' && $minor eq '') ||
15462: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
15463: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
15464: my $switchlcrev =
15465: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
15466: $userdomserver);
15467: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
15468: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
15469: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
15470: my $cdom = $env{'course.'.$courseid.'.domain'};
15471: if ($cdom ne $env{'user.domain'}) {
15472: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
15473: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
15474: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
15475: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
15476: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
15477: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
15478: my $canhost =
15479: &Apache::lonnet::can_host_session($env{'user.domain'},
15480: $coursedomserver,
15481: $remoterev,
15482: $udomdefaults{'remotesessions'},
15483: $defdomdefaults{'hostedsessions'});
15484:
15485: if ($canhost) {
15486: $otherserver = $coursedomserver;
15487: } else {
15488: $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).'<br />'. &mt("No suitable server could be found amongst servers in either your own domain or in the course's domain.");
15489: }
15490: } else {
15491: $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).'<br />'.&mt("No suitable server could be found amongst servers in your own domain (which is also the course's domain).");
15492: }
15493: } else {
15494: $otherserver = $userdomserver;
15495: }
15496: }
15497: if ($otherserver ne '') {
15498: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
15499: }
15500: }
15501: }
15502: return ($switchserver,$warning);
15503: }
15504:
15505: =pod
15506:
15507: =item * &check_release_result()
15508:
15509: Inputs:
15510:
15511: $switchwarning - Warning message if no suitable server found to host session.
15512:
15513: $switchserver - query string to append to /adm/switchserver containing lonHostID
15514: and current role.
15515:
15516: Returns: HTML to display with information about requirement to switch server.
15517: Either displaying warning with link to Roles/Courses screen or
15518: display link to switchserver.
15519:
1.1075.2.69 raeburn 15520: =cut
15521:
1.1075.2.88 raeburn 15522: sub check_release_result {
15523: my ($switchwarning,$switchserver) = @_;
15524: my $output = &start_page('Selected course unavailable on this server').
15525: '<p class="LC_warning">';
15526: if ($switchwarning) {
15527: $output .= $switchwarning.'<br /><a href="/adm/roles">';
15528: if (&show_course()) {
15529: $output .= &mt('Display courses');
15530: } else {
15531: $output .= &mt('Display roles');
15532: }
15533: $output .= '</a>';
15534: } elsif ($switchserver) {
15535: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
15536: '<br />'.
15537: '<a href="/adm/switchserver?'.$switchserver.'">'.
15538: &mt('Switch Server').
15539: '</a>';
15540: }
15541: $output .= '</p>'.&end_page();
15542: return $output;
15543: }
15544:
15545: =pod
15546:
15547: =item * &needs_coursereinit()
15548:
15549: Determine if course contents stored for user's session needs to be
15550: refreshed, because content has changed since "Big Hash" last tied.
15551:
15552: Check for change is made if time last checked is more than 10 minutes ago
15553: (by default).
15554:
15555: Inputs:
15556:
15557: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
15558:
15559: $interval (optional) - Time which may elapse (in s) between last check for content
15560: change in current course. (default: 600 s).
15561:
15562: Returns: an array; first element is:
15563:
15564: =over 4
15565:
15566: 'switch' - if content updates mean user's session
15567: needs to be switched to a server running a newer LON-CAPA version
15568:
15569: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
15570: on current server hosting user's session
15571:
15572: '' - if no action required.
15573:
15574: =back
15575:
15576: If first item element is 'switch':
15577:
15578: second item is $switchwarning - Warning message if no suitable server found to host session.
15579:
15580: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
15581: and current role.
15582:
15583: otherwise: no other elements returned.
15584:
15585: =back
15586:
15587: =cut
15588:
15589: sub needs_coursereinit {
15590: my ($loncaparev,$interval) = @_;
15591: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
15592: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
15593: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
15594: my $now = time;
15595: if ($interval eq '') {
15596: $interval = 600;
15597: }
15598: if (($now-$env{'request.course.timechecked'})>$interval) {
15599: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
15600: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
15601: if ($lastchange > $env{'request.course.tied'}) {
15602: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15603: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
15604: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
15605: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
15606: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
15607: $curr_reqd_hash{'internal.releaserequired'}});
15608: my ($switchserver,$switchwarning) =
15609: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
15610: $curr_reqd_hash{'internal.releaserequired'});
15611: if ($switchwarning ne '' || $switchserver ne '') {
15612: return ('switch',$switchwarning,$switchserver);
15613: }
15614: }
15615: }
15616: return ('update');
15617: }
15618: }
15619: return ();
15620: }
1.1075.2.69 raeburn 15621:
1.1075.2.11 raeburn 15622: sub update_content_constraints {
15623: my ($cdom,$cnum,$chome,$cid) = @_;
15624: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15625: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
15626: my %checkresponsetypes;
15627: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
15628: my ($item,$name,$value) = split(/:/,$key);
15629: if ($item eq 'resourcetag') {
15630: if ($name eq 'responsetype') {
15631: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
15632: }
15633: }
15634: }
15635: my $navmap = Apache::lonnavmaps::navmap->new();
15636: if (defined($navmap)) {
15637: my %allresponses;
15638: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
15639: my %responses = $res->responseTypes();
15640: foreach my $key (keys(%responses)) {
15641: next unless(exists($checkresponsetypes{$key}));
15642: $allresponses{$key} += $responses{$key};
15643: }
15644: }
15645: foreach my $key (keys(%allresponses)) {
15646: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
15647: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
15648: ($reqdmajor,$reqdminor) = ($major,$minor);
15649: }
15650: }
15651: undef($navmap);
15652: }
15653: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
15654: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
15655: }
15656: return;
15657: }
15658:
1.1075.2.27 raeburn 15659: sub allmaps_incourse {
15660: my ($cdom,$cnum,$chome,$cid) = @_;
15661: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
15662: $cid = $env{'request.course.id'};
15663: $cdom = $env{'course.'.$cid.'.domain'};
15664: $cnum = $env{'course.'.$cid.'.num'};
15665: $chome = $env{'course.'.$cid.'.home'};
15666: }
15667: my %allmaps = ();
15668: my $lastchange =
15669: &Apache::lonnet::get_coursechange($cdom,$cnum);
15670: if ($lastchange > $env{'request.course.tied'}) {
15671: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
15672: unless ($ferr) {
15673: &update_content_constraints($cdom,$cnum,$chome,$cid);
15674: }
15675: }
15676: my $navmap = Apache::lonnavmaps::navmap->new();
15677: if (defined($navmap)) {
15678: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
15679: $allmaps{$res->src()} = 1;
15680: }
15681: }
15682: return \%allmaps;
15683: }
15684:
1.1075.2.11 raeburn 15685: sub parse_supplemental_title {
15686: my ($title) = @_;
15687:
15688: my ($foldertitle,$renametitle);
15689: if ($title =~ /&&&/) {
15690: $title = &HTML::Entites::decode($title);
15691: }
15692: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
15693: $renametitle=$4;
15694: my ($time,$uname,$udom) = ($1,$2,$3);
15695: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
15696: my $name = &plainname($uname,$udom);
15697: $name = &HTML::Entities::encode($name,'"<>&\'');
15698: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
15699: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
15700: $name.': <br />'.$foldertitle;
15701: }
15702: if (wantarray) {
15703: return ($title,$foldertitle,$renametitle);
15704: }
15705: return $title;
15706: }
15707:
1.1075.2.43 raeburn 15708: sub recurse_supplemental {
15709: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
15710: if ($suppmap) {
15711: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
15712: if ($fatal) {
15713: $errors ++;
15714: } else {
15715: if ($#LONCAPA::map::resources > 0) {
15716: foreach my $res (@LONCAPA::map::resources) {
15717: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
15718: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 15719: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
15720: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 15721: } else {
15722: $numfiles ++;
15723: }
15724: }
15725: }
15726: }
15727: }
15728: }
15729: return ($numfiles,$errors);
15730: }
15731:
1.1075.2.18 raeburn 15732: sub symb_to_docspath {
15733: my ($symb) = @_;
15734: return unless ($symb);
15735: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
15736: if ($resurl=~/\.(sequence|page)$/) {
15737: $mapurl=$resurl;
15738: } elsif ($resurl eq 'adm/navmaps') {
15739: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
15740: }
15741: my $mapresobj;
15742: my $navmap = Apache::lonnavmaps::navmap->new();
15743: if (ref($navmap)) {
15744: $mapresobj = $navmap->getResourceByUrl($mapurl);
15745: }
15746: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
15747: my $type=$2;
15748: my $path;
15749: if (ref($mapresobj)) {
15750: my $pcslist = $mapresobj->map_hierarchy();
15751: if ($pcslist ne '') {
15752: foreach my $pc (split(/,/,$pcslist)) {
15753: next if ($pc <= 1);
15754: my $res = $navmap->getByMapPc($pc);
15755: if (ref($res)) {
15756: my $thisurl = $res->src();
15757: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
15758: my $thistitle = $res->title();
15759: $path .= '&'.
15760: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 15761: &escape($thistitle).
1.1075.2.18 raeburn 15762: ':'.$res->randompick().
15763: ':'.$res->randomout().
15764: ':'.$res->encrypted().
15765: ':'.$res->randomorder().
15766: ':'.$res->is_page();
15767: }
15768: }
15769: }
15770: $path =~ s/^\&//;
15771: my $maptitle = $mapresobj->title();
15772: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 15773: $maptitle = 'Main Content';
1.1075.2.18 raeburn 15774: }
15775: $path .= (($path ne '')? '&' : '').
15776: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 15777: &escape($maptitle).
1.1075.2.18 raeburn 15778: ':'.$mapresobj->randompick().
15779: ':'.$mapresobj->randomout().
15780: ':'.$mapresobj->encrypted().
15781: ':'.$mapresobj->randomorder().
15782: ':'.$mapresobj->is_page();
15783: } else {
15784: my $maptitle = &Apache::lonnet::gettitle($mapurl);
15785: my $ispage = (($type eq 'page')? 1 : '');
15786: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 15787: $maptitle = 'Main Content';
1.1075.2.18 raeburn 15788: }
15789: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 15790: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 15791: }
15792: unless ($mapurl eq 'default') {
15793: $path = 'default&'.
1.1075.2.46 raeburn 15794: &escape('Main Content').
1.1075.2.18 raeburn 15795: ':::::&'.$path;
15796: }
15797: return $path;
15798: }
15799:
1.1075.2.14 raeburn 15800: sub captcha_display {
15801: my ($context,$lonhost) = @_;
15802: my ($output,$error);
15803: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
15804: if ($captcha eq 'original') {
15805: $output = &create_captcha();
15806: unless ($output) {
15807: $error = 'captcha';
15808: }
15809: } elsif ($captcha eq 'recaptcha') {
15810: $output = &create_recaptcha($pubkey);
15811: unless ($output) {
15812: $error = 'recaptcha';
15813: }
15814: }
1.1075.2.66 raeburn 15815: return ($output,$error,$captcha);
1.1075.2.14 raeburn 15816: }
15817:
15818: sub captcha_response {
15819: my ($context,$lonhost) = @_;
15820: my ($captcha_chk,$captcha_error);
15821: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
15822: if ($captcha eq 'original') {
15823: ($captcha_chk,$captcha_error) = &check_captcha();
15824: } elsif ($captcha eq 'recaptcha') {
15825: $captcha_chk = &check_recaptcha($privkey);
15826: } else {
15827: $captcha_chk = 1;
15828: }
15829: return ($captcha_chk,$captcha_error);
15830: }
15831:
15832: sub get_captcha_config {
15833: my ($context,$lonhost) = @_;
15834: my ($captcha,$pubkey,$privkey,$hashtocheck);
15835: my $hostname = &Apache::lonnet::hostname($lonhost);
15836: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
15837: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
15838: if ($context eq 'usercreation') {
15839: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
15840: if (ref($domconfig{$context}) eq 'HASH') {
15841: $hashtocheck = $domconfig{$context}{'cancreate'};
15842: if (ref($hashtocheck) eq 'HASH') {
15843: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
15844: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
15845: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
15846: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
15847: }
15848: if ($privkey && $pubkey) {
15849: $captcha = 'recaptcha';
15850: } else {
15851: $captcha = 'original';
15852: }
15853: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
15854: $captcha = 'original';
15855: }
15856: }
15857: } else {
15858: $captcha = 'captcha';
15859: }
15860: } elsif ($context eq 'login') {
15861: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
15862: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
15863: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
15864: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
15865: if ($privkey && $pubkey) {
15866: $captcha = 'recaptcha';
15867: } else {
15868: $captcha = 'original';
15869: }
15870: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
15871: $captcha = 'original';
15872: }
15873: }
15874: return ($captcha,$pubkey,$privkey);
15875: }
15876:
15877: sub create_captcha {
15878: my %captcha_params = &captcha_settings();
15879: my ($output,$maxtries,$tries) = ('',10,0);
15880: while ($tries < $maxtries) {
15881: $tries ++;
15882: my $captcha = Authen::Captcha->new (
15883: output_folder => $captcha_params{'output_dir'},
15884: data_folder => $captcha_params{'db_dir'},
15885: );
15886: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
15887:
15888: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
15889: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
15890: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 15891: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
15892: '<br />'.
15893: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 15894: last;
15895: }
15896: }
15897: return $output;
15898: }
15899:
15900: sub captcha_settings {
15901: my %captcha_params = (
15902: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
15903: www_output_dir => "/captchaspool",
15904: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
15905: numchars => '5',
15906: );
15907: return %captcha_params;
15908: }
15909:
15910: sub check_captcha {
15911: my ($captcha_chk,$captcha_error);
15912: my $code = $env{'form.code'};
15913: my $md5sum = $env{'form.crypt'};
15914: my %captcha_params = &captcha_settings();
15915: my $captcha = Authen::Captcha->new(
15916: output_folder => $captcha_params{'output_dir'},
15917: data_folder => $captcha_params{'db_dir'},
15918: );
1.1075.2.26 raeburn 15919: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 15920: my %captcha_hash = (
15921: 0 => 'Code not checked (file error)',
15922: -1 => 'Failed: code expired',
15923: -2 => 'Failed: invalid code (not in database)',
15924: -3 => 'Failed: invalid code (code does not match crypt)',
15925: );
15926: if ($captcha_chk != 1) {
15927: $captcha_error = $captcha_hash{$captcha_chk}
15928: }
15929: return ($captcha_chk,$captcha_error);
15930: }
15931:
15932: sub create_recaptcha {
15933: my ($pubkey) = @_;
1.1075.2.51 raeburn 15934: my $use_ssl;
15935: if ($ENV{'SERVER_PORT'} == 443) {
15936: $use_ssl = 1;
15937: }
1.1075.2.14 raeburn 15938: my $captcha = Captcha::reCAPTCHA->new;
15939: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1075.2.51 raeburn 15940: $captcha->get_html($pubkey,undef,$use_ssl).
1.1075.2.14 raeburn 15941: &mt('If either word is hard to read, [_1] will replace them.',
1.1075.2.39 raeburn 15942: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1075.2.14 raeburn 15943: '<br /><br />';
15944: }
15945:
15946: sub check_recaptcha {
15947: my ($privkey) = @_;
15948: my $captcha_chk;
15949: my $captcha = Captcha::reCAPTCHA->new;
15950: my $captcha_result =
15951: $captcha->check_answer(
15952: $privkey,
15953: $ENV{'REMOTE_ADDR'},
15954: $env{'form.recaptcha_challenge_field'},
15955: $env{'form.recaptcha_response_field'},
15956: );
15957: if ($captcha_result->{is_valid}) {
15958: $captcha_chk = 1;
15959: }
15960: return $captcha_chk;
15961: }
15962:
1.1075.2.64 raeburn 15963: sub emailusername_info {
1.1075.2.67 raeburn 15964: my @fields = ('firstname','lastname','institution','web','location','officialemail');
1.1075.2.64 raeburn 15965: my %titles = &Apache::lonlocal::texthash (
15966: lastname => 'Last Name',
15967: firstname => 'First Name',
15968: institution => 'School/college/university',
15969: location => "School's city, state/province, country",
15970: web => "School's web address",
15971: officialemail => 'E-mail address at institution (if different)',
15972: );
15973: return (\@fields,\%titles);
15974: }
15975:
1.1075.2.56 raeburn 15976: sub cleanup_html {
15977: my ($incoming) = @_;
15978: my $outgoing;
15979: if ($incoming ne '') {
15980: $outgoing = $incoming;
15981: $outgoing =~ s/;/;/g;
15982: $outgoing =~ s/\#/#/g;
15983: $outgoing =~ s/\&/&/g;
15984: $outgoing =~ s/</</g;
15985: $outgoing =~ s/>/>/g;
15986: $outgoing =~ s/\(/(/g;
15987: $outgoing =~ s/\)/)/g;
15988: $outgoing =~ s/"/"/g;
15989: $outgoing =~ s/'/'/g;
15990: $outgoing =~ s/\$/$/g;
15991: $outgoing =~ s{/}{/}g;
15992: $outgoing =~ s/=/=/g;
15993: $outgoing =~ s/\\/\/g
15994: }
15995: return $outgoing;
15996: }
15997:
1.1075.2.74 raeburn 15998: # Checks for critical messages and returns a redirect url if one exists.
15999: # $interval indicates how often to check for messages.
16000: sub critical_redirect {
16001: my ($interval) = @_;
16002: if ((time-$env{'user.criticalcheck.time'})>$interval) {
16003: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
16004: $env{'user.name'});
16005: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
16006: my $redirecturl;
16007: if ($what[0]) {
16008: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
16009: $redirecturl='/adm/email?critical=display';
16010: my $url=&Apache::lonnet::absolute_url().$redirecturl;
16011: return (1, $url);
16012: }
16013: }
16014: }
16015: return ();
16016: }
16017:
1.1075.2.64 raeburn 16018: # Use:
16019: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
16020: #
16021: ##################################################
16022: # password associated functions #
16023: ##################################################
16024: sub des_keys {
16025: # Make a new key for DES encryption.
16026: # Each key has two parts which are returned separately.
16027: # Please note: Each key must be passed through the &hex function
16028: # before it is output to the web browser. The hex versions cannot
16029: # be used to decrypt.
16030: my @hexstr=('0','1','2','3','4','5','6','7',
16031: '8','9','a','b','c','d','e','f');
16032: my $lkey='';
16033: for (0..7) {
16034: $lkey.=$hexstr[rand(15)];
16035: }
16036: my $ukey='';
16037: for (0..7) {
16038: $ukey.=$hexstr[rand(15)];
16039: }
16040: return ($lkey,$ukey);
16041: }
16042:
16043: sub des_decrypt {
16044: my ($key,$cyphertext) = @_;
16045: my $keybin=pack("H16",$key);
16046: my $cypher;
16047: if ($Crypt::DES::VERSION>=2.03) {
16048: $cypher=new Crypt::DES $keybin;
16049: } else {
16050: $cypher=new DES $keybin;
16051: }
16052: my $plaintext=
16053: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
16054: $plaintext.=
16055: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
16056: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
16057: return $plaintext;
16058: }
16059:
1.112 bowersj2 16060: 1;
16061: __END__;
1.41 ng 16062:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>