Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.86
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.86! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.85 2014/12/21 17:29:44 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.946 raeburn 4758: if ($key eq 'loginvia') {
4759: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4760: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4761: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4762: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4763: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4764: $designhash{$udom.'.login.loginvia'} = $server;
4765: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4766:
4767: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4768: } else {
1.1013 raeburn 4769: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4770: }
4771: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4772: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4773: }
1.946 raeburn 4774: }
4775: }
4776: }
4777: }
4778: } else {
4779: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4780: $designhash{$udom.'.login.'.$key.'_'.$img} =
4781: $domconfig{'login'}{$key}{$img};
4782: }
1.699 raeburn 4783: }
4784: } else {
4785: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4786: }
1.632 raeburn 4787: }
4788: } else {
4789: $legacy{'login'} = 1;
1.518 albertel 4790: }
1.632 raeburn 4791: } else {
4792: $legacy{'login'} = 1;
1.518 albertel 4793: }
4794: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4795: if (keys(%{$domconfig{'rolecolors'}})) {
4796: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4797: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4798: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4799: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4800: }
1.518 albertel 4801: }
4802: }
1.632 raeburn 4803: } else {
4804: $legacy{'rolecolors'} = 1;
1.518 albertel 4805: }
1.632 raeburn 4806: } else {
4807: $legacy{'rolecolors'} = 1;
1.518 albertel 4808: }
1.948 raeburn 4809: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4810: if ($domconfig{'autoenroll'}{'co-owners'}) {
4811: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4812: }
4813: }
1.632 raeburn 4814: if (keys(%legacy) > 0) {
4815: my %legacyhash = &get_legacy_domconf($udom);
4816: foreach my $item (keys(%legacyhash)) {
4817: if ($item =~ /^\Q$udom\E\.login/) {
4818: if ($legacy{'login'}) {
4819: $designhash{$item} = $legacyhash{$item};
4820: }
4821: } else {
4822: if ($legacy{'rolecolors'}) {
4823: $designhash{$item} = $legacyhash{$item};
4824: }
1.518 albertel 4825: }
4826: }
4827: }
1.632 raeburn 4828: } else {
4829: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4830: }
4831: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4832: $cachetime);
4833: return %designhash;
4834: }
4835:
1.632 raeburn 4836: sub get_legacy_domconf {
4837: my ($udom) = @_;
4838: my %legacyhash;
4839: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4840: my $designfile = $designdir.'/'.$udom.'.tab';
4841: if (-e $designfile) {
4842: if ( open (my $fh,"<$designfile") ) {
4843: while (my $line = <$fh>) {
4844: next if ($line =~ /^\#/);
4845: chomp($line);
4846: my ($key,$val)=(split(/\=/,$line));
4847: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4848: }
4849: close($fh);
4850: }
4851: }
1.1026 raeburn 4852: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4853: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4854: }
4855: return %legacyhash;
4856: }
4857:
1.63 www 4858: =pod
4859:
1.112 bowersj2 4860: =item * &domainlogo()
1.63 www 4861:
4862: Inputs: $domain (usually will be undef)
4863:
4864: Returns: A link to a domain logo, if the domain logo exists.
4865: If the domain logo does not exist, a description of the domain.
4866:
4867: =cut
1.112 bowersj2 4868:
1.63 www 4869: ###############################################
4870: sub domainlogo {
1.517 raeburn 4871: my $domain = &determinedomain(shift);
1.518 albertel 4872: my %designhash = &get_domainconf($domain);
1.517 raeburn 4873: # See if there is a logo
4874: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4875: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4876: if ($imgsrc =~ m{^/(adm|res)/}) {
4877: if ($imgsrc =~ m{^/res/}) {
4878: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4879: &Apache::lonnet::repcopy($local_name);
4880: }
4881: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4882: }
4883: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4884: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4885: return &Apache::lonnet::domain($domain,'description');
1.59 www 4886: } else {
1.60 matthew 4887: return '';
1.59 www 4888: }
4889: }
1.63 www 4890: ##############################################
4891:
4892: =pod
4893:
1.112 bowersj2 4894: =item * &designparm()
1.63 www 4895:
4896: Inputs: $which parameter; $domain (usually will be undef)
4897:
4898: Returns: value of designparamter $which
4899:
4900: =cut
1.112 bowersj2 4901:
1.397 albertel 4902:
1.400 albertel 4903: ##############################################
1.397 albertel 4904: sub designparm {
4905: my ($which,$domain)=@_;
4906: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4907: return $env{'environment.color.'.$which};
1.96 www 4908: }
1.63 www 4909: $domain=&determinedomain($domain);
1.1016 raeburn 4910: my %domdesign;
4911: unless ($domain eq 'public') {
4912: %domdesign = &get_domainconf($domain);
4913: }
1.520 raeburn 4914: my $output;
1.517 raeburn 4915: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4916: $output = $domdesign{$domain.'.'.$which};
1.63 www 4917: } else {
1.520 raeburn 4918: $output = $defaultdesign{$which};
4919: }
4920: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4921: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4922: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4923: if ($output =~ m{^/res/}) {
4924: my $local_name = &Apache::lonnet::filelocation('',$output);
4925: &Apache::lonnet::repcopy($local_name);
4926: }
1.520 raeburn 4927: $output = &lonhttpdurl($output);
4928: }
1.63 www 4929: }
1.520 raeburn 4930: return $output;
1.63 www 4931: }
1.59 www 4932:
1.822 bisitz 4933: ##############################################
4934: =pod
4935:
1.832 bisitz 4936: =item * &authorspace()
4937:
1.1028 raeburn 4938: Inputs: $url (usually will be undef).
1.832 bisitz 4939:
1.1075.2.40 raeburn 4940: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4941: directory being viewed (or for which action is being taken).
4942: If $url is provided, and begins /priv/<domain>/<uname>
4943: the path will be that portion of the $context argument.
4944: Otherwise the path will be for the author space of the current
4945: user when the current role is author, or for that of the
4946: co-author/assistant co-author space when the current role
4947: is co-author or assistant co-author.
1.832 bisitz 4948:
4949: =cut
4950:
4951: sub authorspace {
1.1028 raeburn 4952: my ($url) = @_;
4953: if ($url ne '') {
4954: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4955: return $1;
4956: }
4957: }
1.832 bisitz 4958: my $caname = '';
1.1024 www 4959: my $cadom = '';
1.1028 raeburn 4960: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4961: ($cadom,$caname) =
1.832 bisitz 4962: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4963: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4964: $caname = $env{'user.name'};
1.1024 www 4965: $cadom = $env{'user.domain'};
1.832 bisitz 4966: }
1.1028 raeburn 4967: if (($caname ne '') && ($cadom ne '')) {
4968: return "/priv/$cadom/$caname/";
4969: }
4970: return;
1.832 bisitz 4971: }
4972:
4973: ##############################################
4974: =pod
4975:
1.822 bisitz 4976: =item * &head_subbox()
4977:
4978: Inputs: $content (contains HTML code with page functions, etc.)
4979:
4980: Returns: HTML div with $content
4981: To be included in page header
4982:
4983: =cut
4984:
4985: sub head_subbox {
4986: my ($content)=@_;
4987: my $output =
1.993 raeburn 4988: '<div class="LC_head_subbox">'
1.822 bisitz 4989: .$content
4990: .'</div>'
4991: }
4992:
4993: ##############################################
4994: =pod
4995:
4996: =item * &CSTR_pageheader()
4997:
1.1026 raeburn 4998: Input: (optional) filename from which breadcrumb trail is built.
4999: In most cases no input as needed, as $env{'request.filename'}
5000: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5001:
5002: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5003: To be included on Authoring Space pages
1.822 bisitz 5004:
5005: =cut
5006:
5007: sub CSTR_pageheader {
1.1026 raeburn 5008: my ($trailfile) = @_;
5009: if ($trailfile eq '') {
5010: $trailfile = $env{'request.filename'};
5011: }
5012:
5013: # this is for resources; directories have customtitle, and crumbs
5014: # and select recent are created in lonpubdir.pm
5015:
5016: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5017: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5018: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5019: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5020: $formaction =~ s{/+}{/}g;
1.822 bisitz 5021:
5022: my $parentpath = '';
5023: my $lastitem = '';
5024: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5025: $parentpath = $1;
5026: $lastitem = $2;
5027: } else {
5028: $lastitem = $thisdisfn;
5029: }
1.921 bisitz 5030:
5031: my $output =
1.822 bisitz 5032: '<div>'
5033: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5034: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5035: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5036: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5037: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5038:
5039: if ($lastitem) {
5040: $output .=
5041: '<span class="LC_filename">'
5042: .$lastitem
5043: .'</span>';
5044: }
5045: $output .=
5046: '<br />'
1.822 bisitz 5047: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5048: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5049: .'</form>'
5050: .&Apache::lonmenu::constspaceform()
5051: .'</div>';
1.921 bisitz 5052:
5053: return $output;
1.822 bisitz 5054: }
5055:
1.60 matthew 5056: ###############################################
5057: ###############################################
5058:
5059: =pod
5060:
1.112 bowersj2 5061: =back
5062:
1.549 albertel 5063: =head1 HTML Helpers
1.112 bowersj2 5064:
5065: =over 4
5066:
5067: =item * &bodytag()
1.60 matthew 5068:
5069: Returns a uniform header for LON-CAPA web pages.
5070:
5071: Inputs:
5072:
1.112 bowersj2 5073: =over 4
5074:
5075: =item * $title, A title to be displayed on the page.
5076:
5077: =item * $function, the current role (can be undef).
5078:
5079: =item * $addentries, extra parameters for the <body> tag.
5080:
5081: =item * $bodyonly, if defined, only return the <body> tag.
5082:
5083: =item * $domain, if defined, force a given domain.
5084:
5085: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5086: text interface only)
1.60 matthew 5087:
1.814 bisitz 5088: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5089: navigational links
1.317 albertel 5090:
1.338 albertel 5091: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5092:
1.1075.2.12 raeburn 5093: =item * $no_inline_link, if true and in remote mode, don't show the
5094: 'Switch To Inline Menu' link
5095:
1.460 albertel 5096: =item * $args, optional argument valid values are
5097: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5098: inherit_jsmath -> when creating popup window in a page,
5099: should it have jsmath forced on by the
5100: current page
1.460 albertel 5101:
1.1075.2.15 raeburn 5102: =item * $advtoolsref, optional argument, ref to an array containing
5103: inlineremote items to be added in "Functions" menu below
5104: breadcrumbs.
5105:
1.112 bowersj2 5106: =back
5107:
1.60 matthew 5108: Returns: A uniform header for LON-CAPA web pages.
5109: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5110: If $bodyonly is undef or zero, an html string containing a <body> tag and
5111: other decorations will be returned.
5112:
5113: =cut
5114:
1.54 www 5115: sub bodytag {
1.831 bisitz 5116: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5117: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5118:
1.954 raeburn 5119: my $public;
5120: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5121: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5122: $public = 1;
5123: }
1.460 albertel 5124: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5125: my $httphost = $args->{'use_absolute'};
1.339 albertel 5126:
1.183 matthew 5127: $function = &get_users_function() if (!$function);
1.339 albertel 5128: my $img = &designparm($function.'.img',$domain);
5129: my $font = &designparm($function.'.font',$domain);
5130: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5131:
1.803 bisitz 5132: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5133: 'bgcolor' => $pgbg,
1.339 albertel 5134: 'text' => $font,
5135: 'alink' => &designparm($function.'.alink',$domain),
5136: 'vlink' => &designparm($function.'.vlink',$domain),
5137: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5138: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5139:
1.63 www 5140: # role and realm
1.1075.2.68 raeburn 5141: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5142: if ($realm) {
5143: $realm = '/'.$realm;
5144: }
1.378 raeburn 5145: if ($role eq 'ca') {
1.479 albertel 5146: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5147: $realm = &plainname($rname,$rdom);
1.378 raeburn 5148: }
1.55 www 5149: # realm
1.258 albertel 5150: if ($env{'request.course.id'}) {
1.378 raeburn 5151: if ($env{'request.role'} !~ /^cr/) {
5152: $role = &Apache::lonnet::plaintext($role,&course_type());
5153: }
1.898 raeburn 5154: if ($env{'request.course.sec'}) {
5155: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5156: }
1.359 albertel 5157: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5158: } else {
5159: $role = &Apache::lonnet::plaintext($role);
1.54 www 5160: }
1.433 albertel 5161:
1.359 albertel 5162: if (!$realm) { $realm=' '; }
1.330 albertel 5163:
1.438 albertel 5164: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5165:
1.101 www 5166: # construct main body tag
1.359 albertel 5167: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5168: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5169:
1.1075.2.38 raeburn 5170: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5171:
5172: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5173: return $bodytag;
1.1075.2.38 raeburn 5174: }
1.359 albertel 5175:
1.954 raeburn 5176: if ($public) {
1.433 albertel 5177: undef($role);
5178: }
1.359 albertel 5179:
1.762 bisitz 5180: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5181: #
5182: # Extra info if you are the DC
5183: my $dc_info = '';
5184: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5185: $env{'course.'.$env{'request.course.id'}.
5186: '.domain'}.'/'})) {
5187: my $cid = $env{'request.course.id'};
1.917 raeburn 5188: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5189: $dc_info =~ s/\s+$//;
1.359 albertel 5190: }
5191:
1.898 raeburn 5192: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.903 droeschl 5193:
1.1075.2.13 raeburn 5194: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5195:
1.1075.2.38 raeburn 5196:
5197:
1.1075.2.21 raeburn 5198: my $funclist;
5199: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5200: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5201: Apache::lonmenu::serverform();
5202: my $forbodytag;
5203: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5204: $forcereg,$args->{'group'},
5205: $args->{'bread_crumbs'},
5206: $advtoolsref,'',\$forbodytag);
5207: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5208: $funclist = $forbodytag;
5209: }
5210: } else {
1.903 droeschl 5211:
5212: # if ($env{'request.state'} eq 'construct') {
5213: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5214: # }
5215:
1.1075.2.38 raeburn 5216: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5217: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5218:
1.1075.2.38 raeburn 5219: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5220:
1.916 droeschl 5221: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5222: if ($dc_info) {
5223: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5224: }
1.1075.2.38 raeburn 5225: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5226: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5227: return $bodytag;
5228: }
1.894 droeschl 5229:
1.927 raeburn 5230: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5231: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5232: }
1.916 droeschl 5233:
1.1075.2.38 raeburn 5234: $bodytag .= $right;
1.852 droeschl 5235:
1.917 raeburn 5236: if ($dc_info) {
5237: $dc_info = &dc_courseid_toggle($dc_info);
5238: }
5239: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5240:
1.1075.2.61 raeburn 5241: #if directed to not display the secondary menu, don't.
5242: if ($args->{'no_secondary_menu'}) {
5243: return $bodytag;
5244: }
1.903 droeschl 5245: #don't show menus for public users
1.954 raeburn 5246: if (!$public){
1.1075.2.52 raeburn 5247: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5248: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5249: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5250: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5251: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5252: $args->{'bread_crumbs'});
5253: } elsif ($forcereg) {
1.1075.2.22 raeburn 5254: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5255: $args->{'group'});
1.1075.2.15 raeburn 5256: } else {
1.1075.2.21 raeburn 5257: my $forbodytag;
5258: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5259: $forcereg,$args->{'group'},
5260: $args->{'bread_crumbs'},
5261: $advtoolsref,'',\$forbodytag);
5262: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5263: $bodytag .= $forbodytag;
5264: }
1.920 raeburn 5265: }
1.903 droeschl 5266: }else{
5267: # this is to seperate menu from content when there's no secondary
5268: # menu. Especially needed for public accessible ressources.
5269: $bodytag .= '<hr style="clear:both" />';
5270: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5271: }
1.903 droeschl 5272:
1.235 raeburn 5273: return $bodytag;
1.1075.2.12 raeburn 5274: }
5275:
5276: #
5277: # Top frame rendering, Remote is up
5278: #
5279:
5280: my $imgsrc = $img;
5281: if ($img =~ /^\/adm/) {
5282: $imgsrc = &lonhttpdurl($img);
5283: }
5284: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5285:
1.1075.2.60 raeburn 5286: my $help=($no_inline_link?''
5287: :&Apache::loncommon::top_nav_help('Help'));
5288:
1.1075.2.12 raeburn 5289: # Explicit link to get inline menu
5290: my $menu= ($no_inline_link?''
5291: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5292:
5293: if ($dc_info) {
5294: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5295: }
5296:
1.1075.2.38 raeburn 5297: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5298: unless ($public) {
5299: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5300: undef,'LC_menubuttons_link');
5301: }
5302:
1.1075.2.12 raeburn 5303: unless ($env{'form.inhibitmenu'}) {
5304: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5305: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5306: <li>$help</li>
1.1075.2.12 raeburn 5307: <li>$menu</li>
5308: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5309: }
1.1075.2.13 raeburn 5310: if ($env{'request.state'} eq 'construct') {
5311: if (!$public){
5312: if ($env{'request.state'} eq 'construct') {
5313: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5314: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5315: &Apache::lonhtmlcommon::scripttag('','end').
5316: &Apache::lonmenu::innerregister($forcereg,
5317: $args->{'bread_crumbs'});
5318: }
5319: }
5320: }
1.1075.2.21 raeburn 5321: return $bodytag."\n".$funclist;
1.182 matthew 5322: }
5323:
1.917 raeburn 5324: sub dc_courseid_toggle {
5325: my ($dc_info) = @_;
1.980 raeburn 5326: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5327: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5328: &mt('(More ...)').'</a></span>'.
5329: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5330: }
5331:
1.330 albertel 5332: sub make_attr_string {
5333: my ($register,$attr_ref) = @_;
5334:
5335: if ($attr_ref && !ref($attr_ref)) {
5336: die("addentries Must be a hash ref ".
5337: join(':',caller(1))." ".
5338: join(':',caller(0))." ");
5339: }
5340:
5341: if ($register) {
1.339 albertel 5342: my ($on_load,$on_unload);
5343: foreach my $key (keys(%{$attr_ref})) {
5344: if (lc($key) eq 'onload') {
5345: $on_load.=$attr_ref->{$key}.';';
5346: delete($attr_ref->{$key});
5347:
5348: } elsif (lc($key) eq 'onunload') {
5349: $on_unload.=$attr_ref->{$key}.';';
5350: delete($attr_ref->{$key});
5351: }
5352: }
1.1075.2.12 raeburn 5353: if ($env{'environment.remote'} eq 'on') {
5354: $attr_ref->{'onload'} =
5355: &Apache::lonmenu::loadevents(). $on_load;
5356: $attr_ref->{'onunload'}=
5357: &Apache::lonmenu::unloadevents().$on_unload;
5358: } else {
5359: $attr_ref->{'onload'} = $on_load;
5360: $attr_ref->{'onunload'}= $on_unload;
5361: }
1.330 albertel 5362: }
1.339 albertel 5363:
1.330 albertel 5364: my $attr_string;
1.1075.2.56 raeburn 5365: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5366: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5367: }
5368: return $attr_string;
5369: }
5370:
5371:
1.182 matthew 5372: ###############################################
1.251 albertel 5373: ###############################################
5374:
5375: =pod
5376:
5377: =item * &endbodytag()
5378:
5379: Returns a uniform footer for LON-CAPA web pages.
5380:
1.635 raeburn 5381: Inputs: 1 - optional reference to an args hash
5382: If in the hash, key for noredirectlink has a value which evaluates to true,
5383: a 'Continue' link is not displayed if the page contains an
5384: internal redirect in the <head></head> section,
5385: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5386:
5387: =cut
5388:
5389: sub endbodytag {
1.635 raeburn 5390: my ($args) = @_;
1.1075.2.6 raeburn 5391: my $endbodytag;
5392: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5393: $endbodytag='</body>';
5394: }
1.269 albertel 5395: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5396: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5397: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5398: $endbodytag=
5399: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5400: &mt('Continue').'</a>'.
5401: $endbodytag;
5402: }
1.315 albertel 5403: }
1.251 albertel 5404: return $endbodytag;
5405: }
5406:
1.352 albertel 5407: =pod
5408:
5409: =item * &standard_css()
5410:
5411: Returns a style sheet
5412:
5413: Inputs: (all optional)
5414: domain -> force to color decorate a page for a specific
5415: domain
5416: function -> force usage of a specific rolish color scheme
5417: bgcolor -> override the default page bgcolor
5418:
5419: =cut
5420:
1.343 albertel 5421: sub standard_css {
1.345 albertel 5422: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5423: $function = &get_users_function() if (!$function);
5424: my $img = &designparm($function.'.img', $domain);
5425: my $tabbg = &designparm($function.'.tabbg', $domain);
5426: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5427: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5428: #second colour for later usage
1.345 albertel 5429: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5430: my $pgbg_or_bgcolor =
5431: $bgcolor ||
1.352 albertel 5432: &designparm($function.'.pgbg', $domain);
1.382 albertel 5433: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5434: my $alink = &designparm($function.'.alink', $domain);
5435: my $vlink = &designparm($function.'.vlink', $domain);
5436: my $link = &designparm($function.'.link', $domain);
5437:
1.602 albertel 5438: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5439: my $mono = 'monospace';
1.850 bisitz 5440: my $data_table_head = $sidebg;
5441: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5442: my $data_table_dark = '#E0E0E0';
1.470 banghart 5443: my $data_table_darker = '#CCCCCC';
1.349 albertel 5444: my $data_table_highlight = '#FFFF00';
1.352 albertel 5445: my $mail_new = '#FFBB77';
5446: my $mail_new_hover = '#DD9955';
5447: my $mail_read = '#BBBB77';
5448: my $mail_read_hover = '#999944';
5449: my $mail_replied = '#AAAA88';
5450: my $mail_replied_hover = '#888855';
5451: my $mail_other = '#99BBBB';
5452: my $mail_other_hover = '#669999';
1.391 albertel 5453: my $table_header = '#DDDDDD';
1.489 raeburn 5454: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5455: my $lg_border_color = '#C8C8C8';
1.952 onken 5456: my $button_hover = '#BF2317';
1.392 albertel 5457:
1.608 albertel 5458: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5459: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5460: : '0 3px 0 4px';
1.448 albertel 5461:
1.523 albertel 5462:
1.343 albertel 5463: return <<END;
1.947 droeschl 5464:
5465: /* needed for iframe to allow 100% height in FF */
5466: body, html {
5467: margin: 0;
5468: padding: 0 0.5%;
5469: height: 99%; /* to avoid scrollbars */
5470: }
5471:
1.795 www 5472: body {
1.911 bisitz 5473: font-family: $sans;
5474: line-height:130%;
5475: font-size:0.83em;
5476: color:$font;
1.795 www 5477: }
5478:
1.959 onken 5479: a:focus,
5480: a:focus img {
1.795 www 5481: color: red;
5482: }
1.698 harmsja 5483:
1.911 bisitz 5484: form, .inline {
5485: display: inline;
1.795 www 5486: }
1.721 harmsja 5487:
1.795 www 5488: .LC_right {
1.911 bisitz 5489: text-align:right;
1.795 www 5490: }
5491:
5492: .LC_middle {
1.911 bisitz 5493: vertical-align:middle;
1.795 www 5494: }
1.721 harmsja 5495:
1.1075.2.38 raeburn 5496: .LC_floatleft {
5497: float: left;
5498: }
5499:
5500: .LC_floatright {
5501: float: right;
5502: }
5503:
1.911 bisitz 5504: .LC_400Box {
5505: width:400px;
5506: }
1.721 harmsja 5507:
1.947 droeschl 5508: .LC_iframecontainer {
5509: width: 98%;
5510: margin: 0;
5511: position: fixed;
5512: top: 8.5em;
5513: bottom: 0;
5514: }
5515:
5516: .LC_iframecontainer iframe{
5517: border: none;
5518: width: 100%;
5519: height: 100%;
5520: }
5521:
1.778 bisitz 5522: .LC_filename {
5523: font-family: $mono;
5524: white-space:pre;
1.921 bisitz 5525: font-size: 120%;
1.778 bisitz 5526: }
5527:
5528: .LC_fileicon {
5529: border: none;
5530: height: 1.3em;
5531: vertical-align: text-bottom;
5532: margin-right: 0.3em;
5533: text-decoration:none;
5534: }
5535:
1.1008 www 5536: .LC_setting {
5537: text-decoration:underline;
5538: }
5539:
1.350 albertel 5540: .LC_error {
5541: color: red;
5542: }
1.795 www 5543:
1.1075.2.15 raeburn 5544: .LC_warning {
5545: color: darkorange;
5546: }
5547:
1.457 albertel 5548: .LC_diff_removed {
1.733 bisitz 5549: color: red;
1.394 albertel 5550: }
1.532 albertel 5551:
5552: .LC_info,
1.457 albertel 5553: .LC_success,
5554: .LC_diff_added {
1.350 albertel 5555: color: green;
5556: }
1.795 www 5557:
1.802 bisitz 5558: div.LC_confirm_box {
5559: background-color: #FAFAFA;
5560: border: 1px solid $lg_border_color;
5561: margin-right: 0;
5562: padding: 5px;
5563: }
5564:
5565: div.LC_confirm_box .LC_error img,
5566: div.LC_confirm_box .LC_success img {
5567: vertical-align: middle;
5568: }
5569:
1.440 albertel 5570: .LC_icon {
1.771 droeschl 5571: border: none;
1.790 droeschl 5572: vertical-align: middle;
1.771 droeschl 5573: }
5574:
1.543 albertel 5575: .LC_docs_spacer {
5576: width: 25px;
5577: height: 1px;
1.771 droeschl 5578: border: none;
1.543 albertel 5579: }
1.346 albertel 5580:
1.532 albertel 5581: .LC_internal_info {
1.735 bisitz 5582: color: #999999;
1.532 albertel 5583: }
5584:
1.794 www 5585: .LC_discussion {
1.1050 www 5586: background: $data_table_dark;
1.911 bisitz 5587: border: 1px solid black;
5588: margin: 2px;
1.794 www 5589: }
5590:
5591: .LC_disc_action_left {
1.1050 www 5592: background: $sidebg;
1.911 bisitz 5593: text-align: left;
1.1050 www 5594: padding: 4px;
5595: margin: 2px;
1.794 www 5596: }
5597:
5598: .LC_disc_action_right {
1.1050 www 5599: background: $sidebg;
1.911 bisitz 5600: text-align: right;
1.1050 www 5601: padding: 4px;
5602: margin: 2px;
1.794 www 5603: }
5604:
5605: .LC_disc_new_item {
1.911 bisitz 5606: background: white;
5607: border: 2px solid red;
1.1050 www 5608: margin: 4px;
5609: padding: 4px;
1.794 www 5610: }
5611:
5612: .LC_disc_old_item {
1.911 bisitz 5613: background: white;
1.1050 www 5614: margin: 4px;
5615: padding: 4px;
1.794 www 5616: }
5617:
1.458 albertel 5618: table.LC_pastsubmission {
5619: border: 1px solid black;
5620: margin: 2px;
5621: }
5622:
1.924 bisitz 5623: table#LC_menubuttons {
1.345 albertel 5624: width: 100%;
5625: background: $pgbg;
1.392 albertel 5626: border: 2px;
1.402 albertel 5627: border-collapse: separate;
1.803 bisitz 5628: padding: 0;
1.345 albertel 5629: }
1.392 albertel 5630:
1.801 tempelho 5631: table#LC_title_bar a {
5632: color: $fontmenu;
5633: }
1.836 bisitz 5634:
1.807 droeschl 5635: table#LC_title_bar {
1.819 tempelho 5636: clear: both;
1.836 bisitz 5637: display: none;
1.807 droeschl 5638: }
5639:
1.795 www 5640: table#LC_title_bar,
1.933 droeschl 5641: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5642: table#LC_title_bar.LC_with_remote {
1.359 albertel 5643: width: 100%;
1.392 albertel 5644: border-color: $pgbg;
5645: border-style: solid;
5646: border-width: $border;
1.379 albertel 5647: background: $pgbg;
1.801 tempelho 5648: color: $fontmenu;
1.392 albertel 5649: border-collapse: collapse;
1.803 bisitz 5650: padding: 0;
1.819 tempelho 5651: margin: 0;
1.359 albertel 5652: }
1.795 www 5653:
1.933 droeschl 5654: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5655: margin: 0;
5656: padding: 0;
1.933 droeschl 5657: position: relative;
5658: list-style: none;
1.913 droeschl 5659: }
1.933 droeschl 5660: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5661: display: inline;
5662: }
1.933 droeschl 5663:
5664: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5665: padding: 0;
1.933 droeschl 5666: margin: 0;
5667: float: left;
1.913 droeschl 5668: }
1.933 droeschl 5669: .LC_breadcrumb_tools_tools {
5670: padding: 0;
5671: margin: 0;
1.913 droeschl 5672: float: right;
5673: }
5674:
1.359 albertel 5675: table#LC_title_bar td {
5676: background: $tabbg;
5677: }
1.795 www 5678:
1.911 bisitz 5679: table#LC_menubuttons img {
1.803 bisitz 5680: border: none;
1.346 albertel 5681: }
1.795 www 5682:
1.842 droeschl 5683: .LC_breadcrumbs_component {
1.911 bisitz 5684: float: right;
5685: margin: 0 1em;
1.357 albertel 5686: }
1.842 droeschl 5687: .LC_breadcrumbs_component img {
1.911 bisitz 5688: vertical-align: middle;
1.777 tempelho 5689: }
1.795 www 5690:
1.383 albertel 5691: td.LC_table_cell_checkbox {
5692: text-align: center;
5693: }
1.795 www 5694:
5695: .LC_fontsize_small {
1.911 bisitz 5696: font-size: 70%;
1.705 tempelho 5697: }
5698:
1.844 bisitz 5699: #LC_breadcrumbs {
1.911 bisitz 5700: clear:both;
5701: background: $sidebg;
5702: border-bottom: 1px solid $lg_border_color;
5703: line-height: 2.5em;
1.933 droeschl 5704: overflow: hidden;
1.911 bisitz 5705: margin: 0;
5706: padding: 0;
1.995 raeburn 5707: text-align: left;
1.819 tempelho 5708: }
1.862 bisitz 5709:
1.1075.2.16 raeburn 5710: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5711: clear:both;
5712: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5713: border: 1px solid $sidebg;
1.1075.2.16 raeburn 5714: margin: 0 0 10px 0;
1.966 bisitz 5715: padding: 3px;
1.995 raeburn 5716: text-align: left;
1.822 bisitz 5717: }
5718:
1.795 www 5719: .LC_fontsize_medium {
1.911 bisitz 5720: font-size: 85%;
1.705 tempelho 5721: }
5722:
1.795 www 5723: .LC_fontsize_large {
1.911 bisitz 5724: font-size: 120%;
1.705 tempelho 5725: }
5726:
1.346 albertel 5727: .LC_menubuttons_inline_text {
5728: color: $font;
1.698 harmsja 5729: font-size: 90%;
1.701 harmsja 5730: padding-left:3px;
1.346 albertel 5731: }
5732:
1.934 droeschl 5733: .LC_menubuttons_inline_text img{
5734: vertical-align: middle;
5735: }
5736:
1.1051 www 5737: li.LC_menubuttons_inline_text img {
1.951 onken 5738: cursor:pointer;
1.1002 droeschl 5739: text-decoration: none;
1.951 onken 5740: }
5741:
1.526 www 5742: .LC_menubuttons_link {
5743: text-decoration: none;
5744: }
1.795 www 5745:
1.522 albertel 5746: .LC_menubuttons_category {
1.521 www 5747: color: $font;
1.526 www 5748: background: $pgbg;
1.521 www 5749: font-size: larger;
5750: font-weight: bold;
5751: }
5752:
1.346 albertel 5753: td.LC_menubuttons_text {
1.911 bisitz 5754: color: $font;
1.346 albertel 5755: }
1.706 harmsja 5756:
1.346 albertel 5757: .LC_current_location {
5758: background: $tabbg;
5759: }
1.795 www 5760:
1.938 bisitz 5761: table.LC_data_table {
1.347 albertel 5762: border: 1px solid #000000;
1.402 albertel 5763: border-collapse: separate;
1.426 albertel 5764: border-spacing: 1px;
1.610 albertel 5765: background: $pgbg;
1.347 albertel 5766: }
1.795 www 5767:
1.422 albertel 5768: .LC_data_table_dense {
5769: font-size: small;
5770: }
1.795 www 5771:
1.507 raeburn 5772: table.LC_nested_outer {
5773: border: 1px solid #000000;
1.589 raeburn 5774: border-collapse: collapse;
1.803 bisitz 5775: border-spacing: 0;
1.507 raeburn 5776: width: 100%;
5777: }
1.795 www 5778:
1.879 raeburn 5779: table.LC_innerpickbox,
1.507 raeburn 5780: table.LC_nested {
1.803 bisitz 5781: border: none;
1.589 raeburn 5782: border-collapse: collapse;
1.803 bisitz 5783: border-spacing: 0;
1.507 raeburn 5784: width: 100%;
5785: }
1.795 www 5786:
1.911 bisitz 5787: table.LC_data_table tr th,
5788: table.LC_calendar tr th,
1.879 raeburn 5789: table.LC_prior_tries tr th,
5790: table.LC_innerpickbox tr th {
1.349 albertel 5791: font-weight: bold;
5792: background-color: $data_table_head;
1.801 tempelho 5793: color:$fontmenu;
1.701 harmsja 5794: font-size:90%;
1.347 albertel 5795: }
1.795 www 5796:
1.879 raeburn 5797: table.LC_innerpickbox tr th,
5798: table.LC_innerpickbox tr td {
5799: vertical-align: top;
5800: }
5801:
1.711 raeburn 5802: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5803: background-color: #CCCCCC;
1.711 raeburn 5804: font-weight: bold;
5805: text-align: left;
5806: }
1.795 www 5807:
1.912 bisitz 5808: table.LC_data_table tr.LC_odd_row > td {
5809: background-color: $data_table_light;
5810: padding: 2px;
5811: vertical-align: top;
5812: }
5813:
1.809 bisitz 5814: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5815: background-color: $data_table_light;
1.912 bisitz 5816: vertical-align: top;
5817: }
5818:
5819: table.LC_data_table tr.LC_even_row > td {
5820: background-color: $data_table_dark;
1.425 albertel 5821: padding: 2px;
1.900 bisitz 5822: vertical-align: top;
1.347 albertel 5823: }
1.795 www 5824:
1.809 bisitz 5825: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5826: background-color: $data_table_dark;
1.900 bisitz 5827: vertical-align: top;
1.347 albertel 5828: }
1.795 www 5829:
1.425 albertel 5830: table.LC_data_table tr.LC_data_table_highlight td {
5831: background-color: $data_table_darker;
5832: }
1.795 www 5833:
1.639 raeburn 5834: table.LC_data_table tr td.LC_leftcol_header {
5835: background-color: $data_table_head;
5836: font-weight: bold;
5837: }
1.795 www 5838:
1.451 albertel 5839: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5840: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5841: font-weight: bold;
5842: font-style: italic;
5843: text-align: center;
5844: padding: 8px;
1.347 albertel 5845: }
1.795 www 5846:
1.1075.2.30 raeburn 5847: table.LC_data_table tr.LC_empty_row td,
5848: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5849: background-color: $sidebg;
5850: }
5851:
5852: table.LC_nested tr.LC_empty_row td {
5853: background-color: #FFFFFF;
5854: }
5855:
1.890 droeschl 5856: table.LC_caption {
5857: }
5858:
1.507 raeburn 5859: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5860: padding: 4ex
5861: }
1.795 www 5862:
1.507 raeburn 5863: table.LC_nested_outer tr th {
5864: font-weight: bold;
1.801 tempelho 5865: color:$fontmenu;
1.507 raeburn 5866: background-color: $data_table_head;
1.701 harmsja 5867: font-size: small;
1.507 raeburn 5868: border-bottom: 1px solid #000000;
5869: }
1.795 www 5870:
1.507 raeburn 5871: table.LC_nested_outer tr td.LC_subheader {
5872: background-color: $data_table_head;
5873: font-weight: bold;
5874: font-size: small;
5875: border-bottom: 1px solid #000000;
5876: text-align: right;
1.451 albertel 5877: }
1.795 www 5878:
1.507 raeburn 5879: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5880: background-color: #CCCCCC;
1.451 albertel 5881: font-weight: bold;
5882: font-size: small;
1.507 raeburn 5883: text-align: center;
5884: }
1.795 www 5885:
1.589 raeburn 5886: table.LC_nested tr.LC_info_row td.LC_left_item,
5887: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5888: text-align: left;
1.451 albertel 5889: }
1.795 www 5890:
1.507 raeburn 5891: table.LC_nested td {
1.735 bisitz 5892: background-color: #FFFFFF;
1.451 albertel 5893: font-size: small;
1.507 raeburn 5894: }
1.795 www 5895:
1.507 raeburn 5896: table.LC_nested_outer tr th.LC_right_item,
5897: table.LC_nested tr.LC_info_row td.LC_right_item,
5898: table.LC_nested tr.LC_odd_row td.LC_right_item,
5899: table.LC_nested tr td.LC_right_item {
1.451 albertel 5900: text-align: right;
5901: }
5902:
1.507 raeburn 5903: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5904: background-color: #EEEEEE;
1.451 albertel 5905: }
5906:
1.473 raeburn 5907: table.LC_createuser {
5908: }
5909:
5910: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5911: font-size: small;
1.473 raeburn 5912: }
5913:
5914: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5915: background-color: #CCCCCC;
1.473 raeburn 5916: font-weight: bold;
5917: text-align: center;
5918: }
5919:
1.349 albertel 5920: table.LC_calendar {
5921: border: 1px solid #000000;
5922: border-collapse: collapse;
1.917 raeburn 5923: width: 98%;
1.349 albertel 5924: }
1.795 www 5925:
1.349 albertel 5926: table.LC_calendar_pickdate {
5927: font-size: xx-small;
5928: }
1.795 www 5929:
1.349 albertel 5930: table.LC_calendar tr td {
5931: border: 1px solid #000000;
5932: vertical-align: top;
1.917 raeburn 5933: width: 14%;
1.349 albertel 5934: }
1.795 www 5935:
1.349 albertel 5936: table.LC_calendar tr td.LC_calendar_day_empty {
5937: background-color: $data_table_dark;
5938: }
1.795 www 5939:
1.779 bisitz 5940: table.LC_calendar tr td.LC_calendar_day_current {
5941: background-color: $data_table_highlight;
1.777 tempelho 5942: }
1.795 www 5943:
1.938 bisitz 5944: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5945: background-color: $mail_new;
5946: }
1.795 www 5947:
1.938 bisitz 5948: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5949: background-color: $mail_new_hover;
5950: }
1.795 www 5951:
1.938 bisitz 5952: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5953: background-color: $mail_read;
5954: }
1.795 www 5955:
1.938 bisitz 5956: /*
5957: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5958: background-color: $mail_read_hover;
5959: }
1.938 bisitz 5960: */
1.795 www 5961:
1.938 bisitz 5962: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5963: background-color: $mail_replied;
5964: }
1.795 www 5965:
1.938 bisitz 5966: /*
5967: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5968: background-color: $mail_replied_hover;
5969: }
1.938 bisitz 5970: */
1.795 www 5971:
1.938 bisitz 5972: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5973: background-color: $mail_other;
5974: }
1.795 www 5975:
1.938 bisitz 5976: /*
5977: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5978: background-color: $mail_other_hover;
5979: }
1.938 bisitz 5980: */
1.494 raeburn 5981:
1.777 tempelho 5982: table.LC_data_table tr > td.LC_browser_file,
5983: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5984: background: #AAEE77;
1.389 albertel 5985: }
1.795 www 5986:
1.777 tempelho 5987: table.LC_data_table tr > td.LC_browser_file_locked,
5988: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5989: background: #FFAA99;
1.387 albertel 5990: }
1.795 www 5991:
1.777 tempelho 5992: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5993: background: #888888;
1.779 bisitz 5994: }
1.795 www 5995:
1.777 tempelho 5996: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5997: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5998: background: #F8F866;
1.777 tempelho 5999: }
1.795 www 6000:
1.696 bisitz 6001: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6002: background: #E0E8FF;
1.387 albertel 6003: }
1.696 bisitz 6004:
1.707 bisitz 6005: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6006: /* background: #77FF77; */
1.707 bisitz 6007: }
1.795 www 6008:
1.707 bisitz 6009: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6010: border-right: 8px solid #FFFF77;
1.707 bisitz 6011: }
1.795 www 6012:
1.707 bisitz 6013: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6014: border-right: 8px solid #FFAA77;
1.707 bisitz 6015: }
1.795 www 6016:
1.707 bisitz 6017: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6018: border-right: 8px solid #FF7777;
1.707 bisitz 6019: }
1.795 www 6020:
1.707 bisitz 6021: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6022: border-right: 8px solid #AAFF77;
1.707 bisitz 6023: }
1.795 www 6024:
1.707 bisitz 6025: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6026: border-right: 8px solid #11CC55;
1.707 bisitz 6027: }
6028:
1.388 albertel 6029: span.LC_current_location {
1.701 harmsja 6030: font-size:larger;
1.388 albertel 6031: background: $pgbg;
6032: }
1.387 albertel 6033:
1.1029 www 6034: span.LC_current_nav_location {
6035: font-weight:bold;
6036: background: $sidebg;
6037: }
6038:
1.395 albertel 6039: span.LC_parm_menu_item {
6040: font-size: larger;
6041: }
1.795 www 6042:
1.395 albertel 6043: span.LC_parm_scope_all {
6044: color: red;
6045: }
1.795 www 6046:
1.395 albertel 6047: span.LC_parm_scope_folder {
6048: color: green;
6049: }
1.795 www 6050:
1.395 albertel 6051: span.LC_parm_scope_resource {
6052: color: orange;
6053: }
1.795 www 6054:
1.395 albertel 6055: span.LC_parm_part {
6056: color: blue;
6057: }
1.795 www 6058:
1.911 bisitz 6059: span.LC_parm_folder,
6060: span.LC_parm_symb {
1.395 albertel 6061: font-size: x-small;
6062: font-family: $mono;
6063: color: #AAAAAA;
6064: }
6065:
1.977 bisitz 6066: ul.LC_parm_parmlist li {
6067: display: inline-block;
6068: padding: 0.3em 0.8em;
6069: vertical-align: top;
6070: width: 150px;
6071: border-top:1px solid $lg_border_color;
6072: }
6073:
1.795 www 6074: td.LC_parm_overview_level_menu,
6075: td.LC_parm_overview_map_menu,
6076: td.LC_parm_overview_parm_selectors,
6077: td.LC_parm_overview_restrictions {
1.396 albertel 6078: border: 1px solid black;
6079: border-collapse: collapse;
6080: }
1.795 www 6081:
1.396 albertel 6082: table.LC_parm_overview_restrictions td {
6083: border-width: 1px 4px 1px 4px;
6084: border-style: solid;
6085: border-color: $pgbg;
6086: text-align: center;
6087: }
1.795 www 6088:
1.396 albertel 6089: table.LC_parm_overview_restrictions th {
6090: background: $tabbg;
6091: border-width: 1px 4px 1px 4px;
6092: border-style: solid;
6093: border-color: $pgbg;
6094: }
1.795 www 6095:
1.398 albertel 6096: table#LC_helpmenu {
1.803 bisitz 6097: border: none;
1.398 albertel 6098: height: 55px;
1.803 bisitz 6099: border-spacing: 0;
1.398 albertel 6100: }
6101:
6102: table#LC_helpmenu fieldset legend {
6103: font-size: larger;
6104: }
1.795 www 6105:
1.397 albertel 6106: table#LC_helpmenu_links {
6107: width: 100%;
6108: border: 1px solid black;
6109: background: $pgbg;
1.803 bisitz 6110: padding: 0;
1.397 albertel 6111: border-spacing: 1px;
6112: }
1.795 www 6113:
1.397 albertel 6114: table#LC_helpmenu_links tr td {
6115: padding: 1px;
6116: background: $tabbg;
1.399 albertel 6117: text-align: center;
6118: font-weight: bold;
1.397 albertel 6119: }
1.396 albertel 6120:
1.795 www 6121: table#LC_helpmenu_links a:link,
6122: table#LC_helpmenu_links a:visited,
1.397 albertel 6123: table#LC_helpmenu_links a:active {
6124: text-decoration: none;
6125: color: $font;
6126: }
1.795 www 6127:
1.397 albertel 6128: table#LC_helpmenu_links a:hover {
6129: text-decoration: underline;
6130: color: $vlink;
6131: }
1.396 albertel 6132:
1.417 albertel 6133: .LC_chrt_popup_exists {
6134: border: 1px solid #339933;
6135: margin: -1px;
6136: }
1.795 www 6137:
1.417 albertel 6138: .LC_chrt_popup_up {
6139: border: 1px solid yellow;
6140: margin: -1px;
6141: }
1.795 www 6142:
1.417 albertel 6143: .LC_chrt_popup {
6144: border: 1px solid #8888FF;
6145: background: #CCCCFF;
6146: }
1.795 www 6147:
1.421 albertel 6148: table.LC_pick_box {
6149: border-collapse: separate;
6150: background: white;
6151: border: 1px solid black;
6152: border-spacing: 1px;
6153: }
1.795 www 6154:
1.421 albertel 6155: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6156: background: $sidebg;
1.421 albertel 6157: font-weight: bold;
1.900 bisitz 6158: text-align: left;
1.740 bisitz 6159: vertical-align: top;
1.421 albertel 6160: width: 184px;
6161: padding: 8px;
6162: }
1.795 www 6163:
1.579 raeburn 6164: table.LC_pick_box td.LC_pick_box_value {
6165: text-align: left;
6166: padding: 8px;
6167: }
1.795 www 6168:
1.579 raeburn 6169: table.LC_pick_box td.LC_pick_box_select {
6170: text-align: left;
6171: padding: 8px;
6172: }
1.795 www 6173:
1.424 albertel 6174: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6175: padding: 0;
1.421 albertel 6176: height: 1px;
6177: background: black;
6178: }
1.795 www 6179:
1.421 albertel 6180: table.LC_pick_box td.LC_pick_box_submit {
6181: text-align: right;
6182: }
1.795 www 6183:
1.579 raeburn 6184: table.LC_pick_box td.LC_evenrow_value {
6185: text-align: left;
6186: padding: 8px;
6187: background-color: $data_table_light;
6188: }
1.795 www 6189:
1.579 raeburn 6190: table.LC_pick_box td.LC_oddrow_value {
6191: text-align: left;
6192: padding: 8px;
6193: background-color: $data_table_light;
6194: }
1.795 www 6195:
1.579 raeburn 6196: span.LC_helpform_receipt_cat {
6197: font-weight: bold;
6198: }
1.795 www 6199:
1.424 albertel 6200: table.LC_group_priv_box {
6201: background: white;
6202: border: 1px solid black;
6203: border-spacing: 1px;
6204: }
1.795 www 6205:
1.424 albertel 6206: table.LC_group_priv_box td.LC_pick_box_title {
6207: background: $tabbg;
6208: font-weight: bold;
6209: text-align: right;
6210: width: 184px;
6211: }
1.795 www 6212:
1.424 albertel 6213: table.LC_group_priv_box td.LC_groups_fixed {
6214: background: $data_table_light;
6215: text-align: center;
6216: }
1.795 www 6217:
1.424 albertel 6218: table.LC_group_priv_box td.LC_groups_optional {
6219: background: $data_table_dark;
6220: text-align: center;
6221: }
1.795 www 6222:
1.424 albertel 6223: table.LC_group_priv_box td.LC_groups_functionality {
6224: background: $data_table_darker;
6225: text-align: center;
6226: font-weight: bold;
6227: }
1.795 www 6228:
1.424 albertel 6229: table.LC_group_priv td {
6230: text-align: left;
1.803 bisitz 6231: padding: 0;
1.424 albertel 6232: }
6233:
6234: .LC_navbuttons {
6235: margin: 2ex 0ex 2ex 0ex;
6236: }
1.795 www 6237:
1.423 albertel 6238: .LC_topic_bar {
6239: font-weight: bold;
6240: background: $tabbg;
1.918 wenzelju 6241: margin: 1em 0em 1em 2em;
1.805 bisitz 6242: padding: 3px;
1.918 wenzelju 6243: font-size: 1.2em;
1.423 albertel 6244: }
1.795 www 6245:
1.423 albertel 6246: .LC_topic_bar span {
1.918 wenzelju 6247: left: 0.5em;
6248: position: absolute;
1.423 albertel 6249: vertical-align: middle;
1.918 wenzelju 6250: font-size: 1.2em;
1.423 albertel 6251: }
1.795 www 6252:
1.423 albertel 6253: table.LC_course_group_status {
6254: margin: 20px;
6255: }
1.795 www 6256:
1.423 albertel 6257: table.LC_status_selector td {
6258: vertical-align: top;
6259: text-align: center;
1.424 albertel 6260: padding: 4px;
6261: }
1.795 www 6262:
1.599 albertel 6263: div.LC_feedback_link {
1.616 albertel 6264: clear: both;
1.829 kalberla 6265: background: $sidebg;
1.779 bisitz 6266: width: 100%;
1.829 kalberla 6267: padding-bottom: 10px;
6268: border: 1px $tabbg solid;
1.833 kalberla 6269: height: 22px;
6270: line-height: 22px;
6271: padding-top: 5px;
6272: }
6273:
6274: div.LC_feedback_link img {
6275: height: 22px;
1.867 kalberla 6276: vertical-align:middle;
1.829 kalberla 6277: }
6278:
1.911 bisitz 6279: div.LC_feedback_link a {
1.829 kalberla 6280: text-decoration: none;
1.489 raeburn 6281: }
1.795 www 6282:
1.867 kalberla 6283: div.LC_comblock {
1.911 bisitz 6284: display:inline;
1.867 kalberla 6285: color:$font;
6286: font-size:90%;
6287: }
6288:
6289: div.LC_feedback_link div.LC_comblock {
6290: padding-left:5px;
6291: }
6292:
6293: div.LC_feedback_link div.LC_comblock a {
6294: color:$font;
6295: }
6296:
1.489 raeburn 6297: span.LC_feedback_link {
1.858 bisitz 6298: /* background: $feedback_link_bg; */
1.599 albertel 6299: font-size: larger;
6300: }
1.795 www 6301:
1.599 albertel 6302: span.LC_message_link {
1.858 bisitz 6303: /* background: $feedback_link_bg; */
1.599 albertel 6304: font-size: larger;
6305: position: absolute;
6306: right: 1em;
1.489 raeburn 6307: }
1.421 albertel 6308:
1.515 albertel 6309: table.LC_prior_tries {
1.524 albertel 6310: border: 1px solid #000000;
6311: border-collapse: separate;
6312: border-spacing: 1px;
1.515 albertel 6313: }
1.523 albertel 6314:
1.515 albertel 6315: table.LC_prior_tries td {
1.524 albertel 6316: padding: 2px;
1.515 albertel 6317: }
1.523 albertel 6318:
6319: .LC_answer_correct {
1.795 www 6320: background: lightgreen;
6321: color: darkgreen;
6322: padding: 6px;
1.523 albertel 6323: }
1.795 www 6324:
1.523 albertel 6325: .LC_answer_charged_try {
1.797 www 6326: background: #FFAAAA;
1.795 www 6327: color: darkred;
6328: padding: 6px;
1.523 albertel 6329: }
1.795 www 6330:
1.779 bisitz 6331: .LC_answer_not_charged_try,
1.523 albertel 6332: .LC_answer_no_grade,
6333: .LC_answer_late {
1.795 www 6334: background: lightyellow;
1.523 albertel 6335: color: black;
1.795 www 6336: padding: 6px;
1.523 albertel 6337: }
1.795 www 6338:
1.523 albertel 6339: .LC_answer_previous {
1.795 www 6340: background: lightblue;
6341: color: darkblue;
6342: padding: 6px;
1.523 albertel 6343: }
1.795 www 6344:
1.779 bisitz 6345: .LC_answer_no_message {
1.777 tempelho 6346: background: #FFFFFF;
6347: color: black;
1.795 www 6348: padding: 6px;
1.779 bisitz 6349: }
1.795 www 6350:
1.779 bisitz 6351: .LC_answer_unknown {
6352: background: orange;
6353: color: black;
1.795 www 6354: padding: 6px;
1.777 tempelho 6355: }
1.795 www 6356:
1.529 albertel 6357: span.LC_prior_numerical,
6358: span.LC_prior_string,
6359: span.LC_prior_custom,
6360: span.LC_prior_reaction,
6361: span.LC_prior_math {
1.925 bisitz 6362: font-family: $mono;
1.523 albertel 6363: white-space: pre;
6364: }
6365:
1.525 albertel 6366: span.LC_prior_string {
1.925 bisitz 6367: font-family: $mono;
1.525 albertel 6368: white-space: pre;
6369: }
6370:
1.523 albertel 6371: table.LC_prior_option {
6372: width: 100%;
6373: border-collapse: collapse;
6374: }
1.795 www 6375:
1.911 bisitz 6376: table.LC_prior_rank,
1.795 www 6377: table.LC_prior_match {
1.528 albertel 6378: border-collapse: collapse;
6379: }
1.795 www 6380:
1.528 albertel 6381: table.LC_prior_option tr td,
6382: table.LC_prior_rank tr td,
6383: table.LC_prior_match tr td {
1.524 albertel 6384: border: 1px solid #000000;
1.515 albertel 6385: }
6386:
1.855 bisitz 6387: .LC_nobreak {
1.544 albertel 6388: white-space: nowrap;
1.519 raeburn 6389: }
6390:
1.576 raeburn 6391: span.LC_cusr_emph {
6392: font-style: italic;
6393: }
6394:
1.633 raeburn 6395: span.LC_cusr_subheading {
6396: font-weight: normal;
6397: font-size: 85%;
6398: }
6399:
1.861 bisitz 6400: div.LC_docs_entry_move {
1.859 bisitz 6401: border: 1px solid #BBBBBB;
1.545 albertel 6402: background: #DDDDDD;
1.861 bisitz 6403: width: 22px;
1.859 bisitz 6404: padding: 1px;
6405: margin: 0;
1.545 albertel 6406: }
6407:
1.861 bisitz 6408: table.LC_data_table tr > td.LC_docs_entry_commands,
6409: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6410: font-size: x-small;
6411: }
1.795 www 6412:
1.861 bisitz 6413: .LC_docs_entry_parameter {
6414: white-space: nowrap;
6415: }
6416:
1.544 albertel 6417: .LC_docs_copy {
1.545 albertel 6418: color: #000099;
1.544 albertel 6419: }
1.795 www 6420:
1.544 albertel 6421: .LC_docs_cut {
1.545 albertel 6422: color: #550044;
1.544 albertel 6423: }
1.795 www 6424:
1.544 albertel 6425: .LC_docs_rename {
1.545 albertel 6426: color: #009900;
1.544 albertel 6427: }
1.795 www 6428:
1.544 albertel 6429: .LC_docs_remove {
1.545 albertel 6430: color: #990000;
6431: }
6432:
1.547 albertel 6433: .LC_docs_reinit_warn,
6434: .LC_docs_ext_edit {
6435: font-size: x-small;
6436: }
6437:
1.545 albertel 6438: table.LC_docs_adddocs td,
6439: table.LC_docs_adddocs th {
6440: border: 1px solid #BBBBBB;
6441: padding: 4px;
6442: background: #DDDDDD;
1.543 albertel 6443: }
6444:
1.584 albertel 6445: table.LC_sty_begin {
6446: background: #BBFFBB;
6447: }
1.795 www 6448:
1.584 albertel 6449: table.LC_sty_end {
6450: background: #FFBBBB;
6451: }
6452:
1.589 raeburn 6453: table.LC_double_column {
1.803 bisitz 6454: border-width: 0;
1.589 raeburn 6455: border-collapse: collapse;
6456: width: 100%;
6457: padding: 2px;
6458: }
6459:
6460: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6461: top: 2px;
1.589 raeburn 6462: left: 2px;
6463: width: 47%;
6464: vertical-align: top;
6465: }
6466:
6467: table.LC_double_column tr td.LC_right_col {
6468: top: 2px;
1.779 bisitz 6469: right: 2px;
1.589 raeburn 6470: width: 47%;
6471: vertical-align: top;
6472: }
6473:
1.591 raeburn 6474: div.LC_left_float {
6475: float: left;
6476: padding-right: 5%;
1.597 albertel 6477: padding-bottom: 4px;
1.591 raeburn 6478: }
6479:
6480: div.LC_clear_float_header {
1.597 albertel 6481: padding-bottom: 2px;
1.591 raeburn 6482: }
6483:
6484: div.LC_clear_float_footer {
1.597 albertel 6485: padding-top: 10px;
1.591 raeburn 6486: clear: both;
6487: }
6488:
1.597 albertel 6489: div.LC_grade_show_user {
1.941 bisitz 6490: /* border-left: 5px solid $sidebg; */
6491: border-top: 5px solid #000000;
6492: margin: 50px 0 0 0;
1.936 bisitz 6493: padding: 15px 0 5px 10px;
1.597 albertel 6494: }
1.795 www 6495:
1.936 bisitz 6496: div.LC_grade_show_user_odd_row {
1.941 bisitz 6497: /* border-left: 5px solid #000000; */
6498: }
6499:
6500: div.LC_grade_show_user div.LC_Box {
6501: margin-right: 50px;
1.597 albertel 6502: }
6503:
6504: div.LC_grade_submissions,
6505: div.LC_grade_message_center,
1.936 bisitz 6506: div.LC_grade_info_links {
1.597 albertel 6507: margin: 5px;
6508: width: 99%;
6509: background: #FFFFFF;
6510: }
1.795 www 6511:
1.597 albertel 6512: div.LC_grade_submissions_header,
1.936 bisitz 6513: div.LC_grade_message_center_header {
1.705 tempelho 6514: font-weight: bold;
6515: font-size: large;
1.597 albertel 6516: }
1.795 www 6517:
1.597 albertel 6518: div.LC_grade_submissions_body,
1.936 bisitz 6519: div.LC_grade_message_center_body {
1.597 albertel 6520: border: 1px solid black;
6521: width: 99%;
6522: background: #FFFFFF;
6523: }
1.795 www 6524:
1.613 albertel 6525: table.LC_scantron_action {
6526: width: 100%;
6527: }
1.795 www 6528:
1.613 albertel 6529: table.LC_scantron_action tr th {
1.698 harmsja 6530: font-weight:bold;
6531: font-style:normal;
1.613 albertel 6532: }
1.795 www 6533:
1.779 bisitz 6534: .LC_edit_problem_header,
1.614 albertel 6535: div.LC_edit_problem_footer {
1.705 tempelho 6536: font-weight: normal;
6537: font-size: medium;
1.602 albertel 6538: margin: 2px;
1.1060 bisitz 6539: background-color: $sidebg;
1.600 albertel 6540: }
1.795 www 6541:
1.600 albertel 6542: div.LC_edit_problem_header,
1.602 albertel 6543: div.LC_edit_problem_header div,
1.614 albertel 6544: div.LC_edit_problem_footer,
6545: div.LC_edit_problem_footer div,
1.602 albertel 6546: div.LC_edit_problem_editxml_header,
6547: div.LC_edit_problem_editxml_header div {
1.600 albertel 6548: margin-top: 5px;
6549: }
1.795 www 6550:
1.600 albertel 6551: div.LC_edit_problem_header_title {
1.705 tempelho 6552: font-weight: bold;
6553: font-size: larger;
1.602 albertel 6554: background: $tabbg;
6555: padding: 3px;
1.1060 bisitz 6556: margin: 0 0 5px 0;
1.602 albertel 6557: }
1.795 www 6558:
1.602 albertel 6559: table.LC_edit_problem_header_title {
6560: width: 100%;
1.600 albertel 6561: background: $tabbg;
1.602 albertel 6562: }
6563:
6564: div.LC_edit_problem_discards {
6565: float: left;
6566: padding-bottom: 5px;
6567: }
1.795 www 6568:
1.602 albertel 6569: div.LC_edit_problem_saves {
6570: float: right;
6571: padding-bottom: 5px;
1.600 albertel 6572: }
1.795 www 6573:
1.1075.2.34 raeburn 6574: .LC_edit_opt {
6575: padding-left: 1em;
6576: white-space: nowrap;
6577: }
6578:
1.1075.2.57 raeburn 6579: .LC_edit_problem_latexhelper{
6580: text-align: right;
6581: }
6582:
6583: #LC_edit_problem_colorful div{
6584: margin-left: 40px;
6585: }
6586:
1.911 bisitz 6587: img.stift {
1.803 bisitz 6588: border-width: 0;
6589: vertical-align: middle;
1.677 riegler 6590: }
1.680 riegler 6591:
1.923 bisitz 6592: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6593: vertical-align: top;
1.777 tempelho 6594: }
1.795 www 6595:
1.716 raeburn 6596: div.LC_createcourse {
1.911 bisitz 6597: margin: 10px 10px 10px 10px;
1.716 raeburn 6598: }
6599:
1.917 raeburn 6600: .LC_dccid {
1.1075.2.38 raeburn 6601: float: right;
1.917 raeburn 6602: margin: 0.2em 0 0 0;
6603: padding: 0;
6604: font-size: 90%;
6605: display:none;
6606: }
6607:
1.897 wenzelju 6608: ol.LC_primary_menu a:hover,
1.721 harmsja 6609: ol#LC_MenuBreadcrumbs a:hover,
6610: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6611: ul#LC_secondary_menu a:hover,
1.721 harmsja 6612: .LC_FormSectionClearButton input:hover
1.795 www 6613: ul.LC_TabContent li:hover a {
1.952 onken 6614: color:$button_hover;
1.911 bisitz 6615: text-decoration:none;
1.693 droeschl 6616: }
6617:
1.779 bisitz 6618: h1 {
1.911 bisitz 6619: padding: 0;
6620: line-height:130%;
1.693 droeschl 6621: }
1.698 harmsja 6622:
1.911 bisitz 6623: h2,
6624: h3,
6625: h4,
6626: h5,
6627: h6 {
6628: margin: 5px 0 5px 0;
6629: padding: 0;
6630: line-height:130%;
1.693 droeschl 6631: }
1.795 www 6632:
6633: .LC_hcell {
1.911 bisitz 6634: padding:3px 15px 3px 15px;
6635: margin: 0;
6636: background-color:$tabbg;
6637: color:$fontmenu;
6638: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6639: }
1.795 www 6640:
1.840 bisitz 6641: .LC_Box > .LC_hcell {
1.911 bisitz 6642: margin: 0 -10px 10px -10px;
1.835 bisitz 6643: }
6644:
1.721 harmsja 6645: .LC_noBorder {
1.911 bisitz 6646: border: 0;
1.698 harmsja 6647: }
1.693 droeschl 6648:
1.721 harmsja 6649: .LC_FormSectionClearButton input {
1.911 bisitz 6650: background-color:transparent;
6651: border: none;
6652: cursor:pointer;
6653: text-decoration:underline;
1.693 droeschl 6654: }
1.763 bisitz 6655:
6656: .LC_help_open_topic {
1.911 bisitz 6657: color: #FFFFFF;
6658: background-color: #EEEEFF;
6659: margin: 1px;
6660: padding: 4px;
6661: border: 1px solid #000033;
6662: white-space: nowrap;
6663: /* vertical-align: middle; */
1.759 neumanie 6664: }
1.693 droeschl 6665:
1.911 bisitz 6666: dl,
6667: ul,
6668: div,
6669: fieldset {
6670: margin: 10px 10px 10px 0;
6671: /* overflow: hidden; */
1.693 droeschl 6672: }
1.795 www 6673:
1.838 bisitz 6674: fieldset > legend {
1.911 bisitz 6675: font-weight: bold;
6676: padding: 0 5px 0 5px;
1.838 bisitz 6677: }
6678:
1.813 bisitz 6679: #LC_nav_bar {
1.911 bisitz 6680: float: left;
1.995 raeburn 6681: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6682: margin: 0 0 2px 0;
1.807 droeschl 6683: }
6684:
1.916 droeschl 6685: #LC_realm {
6686: margin: 0.2em 0 0 0;
6687: padding: 0;
6688: font-weight: bold;
6689: text-align: center;
1.995 raeburn 6690: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6691: }
6692:
1.911 bisitz 6693: #LC_nav_bar em {
6694: font-weight: bold;
6695: font-style: normal;
1.807 droeschl 6696: }
6697:
1.897 wenzelju 6698: ol.LC_primary_menu {
1.934 droeschl 6699: margin: 0;
1.1075.2.2 raeburn 6700: padding: 0;
1.995 raeburn 6701: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6702: }
6703:
1.852 droeschl 6704: ol#LC_PathBreadcrumbs {
1.911 bisitz 6705: margin: 0;
1.693 droeschl 6706: }
6707:
1.897 wenzelju 6708: ol.LC_primary_menu li {
1.1075.2.2 raeburn 6709: color: RGB(80, 80, 80);
6710: vertical-align: middle;
6711: text-align: left;
6712: list-style: none;
6713: float: left;
6714: }
6715:
6716: ol.LC_primary_menu li a {
6717: display: block;
6718: margin: 0;
6719: padding: 0 5px 0 10px;
6720: text-decoration: none;
6721: }
6722:
6723: ol.LC_primary_menu li ul {
6724: display: none;
6725: width: 10em;
6726: background-color: $data_table_light;
6727: }
6728:
6729: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6730: display: block;
6731: position: absolute;
6732: margin: 0;
6733: padding: 0;
1.1075.2.5 raeburn 6734: z-index: 2;
1.1075.2.2 raeburn 6735: }
6736:
6737: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6738: font-size: 90%;
1.911 bisitz 6739: vertical-align: top;
1.1075.2.2 raeburn 6740: float: none;
1.1075.2.5 raeburn 6741: border-left: 1px solid black;
6742: border-right: 1px solid black;
1.1075.2.2 raeburn 6743: }
6744:
6745: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5 raeburn 6746: background-color:$data_table_light;
1.1075.2.2 raeburn 6747: }
6748:
6749: ol.LC_primary_menu li li a:hover {
6750: color:$button_hover;
6751: background-color:$data_table_dark;
1.693 droeschl 6752: }
6753:
1.897 wenzelju 6754: ol.LC_primary_menu li img {
1.911 bisitz 6755: vertical-align: bottom;
1.934 droeschl 6756: height: 1.1em;
1.1075.2.3 raeburn 6757: margin: 0.2em 0 0 0;
1.693 droeschl 6758: }
6759:
1.897 wenzelju 6760: ol.LC_primary_menu a {
1.911 bisitz 6761: color: RGB(80, 80, 80);
6762: text-decoration: none;
1.693 droeschl 6763: }
1.795 www 6764:
1.949 droeschl 6765: ol.LC_primary_menu a.LC_new_message {
6766: font-weight:bold;
6767: color: darkred;
6768: }
6769:
1.975 raeburn 6770: ol.LC_docs_parameters {
6771: margin-left: 0;
6772: padding: 0;
6773: list-style: none;
6774: }
6775:
6776: ol.LC_docs_parameters li {
6777: margin: 0;
6778: padding-right: 20px;
6779: display: inline;
6780: }
6781:
1.976 raeburn 6782: ol.LC_docs_parameters li:before {
6783: content: "\\002022 \\0020";
6784: }
6785:
6786: li.LC_docs_parameters_title {
6787: font-weight: bold;
6788: }
6789:
6790: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6791: content: "";
6792: }
6793:
1.897 wenzelju 6794: ul#LC_secondary_menu {
1.1075.2.23 raeburn 6795: clear: right;
1.911 bisitz 6796: color: $fontmenu;
6797: background: $tabbg;
6798: list-style: none;
6799: padding: 0;
6800: margin: 0;
6801: width: 100%;
1.995 raeburn 6802: text-align: left;
1.1075.2.4 raeburn 6803: float: left;
1.808 droeschl 6804: }
6805:
1.897 wenzelju 6806: ul#LC_secondary_menu li {
1.911 bisitz 6807: font-weight: bold;
6808: line-height: 1.8em;
6809: border-right: 1px solid black;
6810: vertical-align: middle;
1.1075.2.4 raeburn 6811: float: left;
6812: }
6813:
6814: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6815: background-color: $data_table_light;
6816: }
6817:
6818: ul#LC_secondary_menu li a {
6819: padding: 0 0.8em;
6820: }
6821:
6822: ul#LC_secondary_menu li ul {
6823: display: none;
6824: }
6825:
6826: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6827: display: block;
6828: position: absolute;
6829: margin: 0;
6830: padding: 0;
6831: list-style:none;
6832: float: none;
6833: background-color: $data_table_light;
1.1075.2.5 raeburn 6834: z-index: 2;
1.1075.2.10 raeburn 6835: margin-left: -1px;
1.1075.2.4 raeburn 6836: }
6837:
6838: ul#LC_secondary_menu li ul li {
6839: font-size: 90%;
6840: vertical-align: top;
6841: border-left: 1px solid black;
6842: border-right: 1px solid black;
1.1075.2.33 raeburn 6843: background-color: $data_table_light;
1.1075.2.4 raeburn 6844: list-style:none;
6845: float: none;
6846: }
6847:
6848: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6849: background-color: $data_table_dark;
1.807 droeschl 6850: }
6851:
1.847 tempelho 6852: ul.LC_TabContent {
1.911 bisitz 6853: display:block;
6854: background: $sidebg;
6855: border-bottom: solid 1px $lg_border_color;
6856: list-style:none;
1.1020 raeburn 6857: margin: -1px -10px 0 -10px;
1.911 bisitz 6858: padding: 0;
1.693 droeschl 6859: }
6860:
1.795 www 6861: ul.LC_TabContent li,
6862: ul.LC_TabContentBigger li {
1.911 bisitz 6863: float:left;
1.741 harmsja 6864: }
1.795 www 6865:
1.897 wenzelju 6866: ul#LC_secondary_menu li a {
1.911 bisitz 6867: color: $fontmenu;
6868: text-decoration: none;
1.693 droeschl 6869: }
1.795 www 6870:
1.721 harmsja 6871: ul.LC_TabContent {
1.952 onken 6872: min-height:20px;
1.721 harmsja 6873: }
1.795 www 6874:
6875: ul.LC_TabContent li {
1.911 bisitz 6876: vertical-align:middle;
1.959 onken 6877: padding: 0 16px 0 10px;
1.911 bisitz 6878: background-color:$tabbg;
6879: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6880: border-left: solid 1px $font;
1.721 harmsja 6881: }
1.795 www 6882:
1.847 tempelho 6883: ul.LC_TabContent .right {
1.911 bisitz 6884: float:right;
1.847 tempelho 6885: }
6886:
1.911 bisitz 6887: ul.LC_TabContent li a,
6888: ul.LC_TabContent li {
6889: color:rgb(47,47,47);
6890: text-decoration:none;
6891: font-size:95%;
6892: font-weight:bold;
1.952 onken 6893: min-height:20px;
6894: }
6895:
1.959 onken 6896: ul.LC_TabContent li a:hover,
6897: ul.LC_TabContent li a:focus {
1.952 onken 6898: color: $button_hover;
1.959 onken 6899: background:none;
6900: outline:none;
1.952 onken 6901: }
6902:
6903: ul.LC_TabContent li:hover {
6904: color: $button_hover;
6905: cursor:pointer;
1.721 harmsja 6906: }
1.795 www 6907:
1.911 bisitz 6908: ul.LC_TabContent li.active {
1.952 onken 6909: color: $font;
1.911 bisitz 6910: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6911: border-bottom:solid 1px #FFFFFF;
6912: cursor: default;
1.744 ehlerst 6913: }
1.795 www 6914:
1.959 onken 6915: ul.LC_TabContent li.active a {
6916: color:$font;
6917: background:#FFFFFF;
6918: outline: none;
6919: }
1.1047 raeburn 6920:
6921: ul.LC_TabContent li.goback {
6922: float: left;
6923: border-left: none;
6924: }
6925:
1.870 tempelho 6926: #maincoursedoc {
1.911 bisitz 6927: clear:both;
1.870 tempelho 6928: }
6929:
6930: ul.LC_TabContentBigger {
1.911 bisitz 6931: display:block;
6932: list-style:none;
6933: padding: 0;
1.870 tempelho 6934: }
6935:
1.795 www 6936: ul.LC_TabContentBigger li {
1.911 bisitz 6937: vertical-align:bottom;
6938: height: 30px;
6939: font-size:110%;
6940: font-weight:bold;
6941: color: #737373;
1.841 tempelho 6942: }
6943:
1.957 onken 6944: ul.LC_TabContentBigger li.active {
6945: position: relative;
6946: top: 1px;
6947: }
6948:
1.870 tempelho 6949: ul.LC_TabContentBigger li a {
1.911 bisitz 6950: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6951: height: 30px;
6952: line-height: 30px;
6953: text-align: center;
6954: display: block;
6955: text-decoration: none;
1.958 onken 6956: outline: none;
1.741 harmsja 6957: }
1.795 www 6958:
1.870 tempelho 6959: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6960: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6961: color:$font;
1.744 ehlerst 6962: }
1.795 www 6963:
1.870 tempelho 6964: ul.LC_TabContentBigger li b {
1.911 bisitz 6965: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6966: display: block;
6967: float: left;
6968: padding: 0 30px;
1.957 onken 6969: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6970: }
6971:
1.956 onken 6972: ul.LC_TabContentBigger li:hover b {
6973: color:$button_hover;
6974: }
6975:
1.870 tempelho 6976: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6977: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6978: color:$font;
1.957 onken 6979: border: 0;
1.741 harmsja 6980: }
1.693 droeschl 6981:
1.870 tempelho 6982:
1.862 bisitz 6983: ul.LC_CourseBreadcrumbs {
6984: background: $sidebg;
1.1020 raeburn 6985: height: 2em;
1.862 bisitz 6986: padding-left: 10px;
1.1020 raeburn 6987: margin: 0;
1.862 bisitz 6988: list-style-position: inside;
6989: }
6990:
1.911 bisitz 6991: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6992: ol#LC_PathBreadcrumbs {
1.911 bisitz 6993: padding-left: 10px;
6994: margin: 0;
1.933 droeschl 6995: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6996: }
6997:
1.911 bisitz 6998: ol#LC_MenuBreadcrumbs li,
6999: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7000: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7001: display: inline;
1.933 droeschl 7002: white-space: normal;
1.693 droeschl 7003: }
7004:
1.823 bisitz 7005: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7006: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7007: text-decoration: none;
7008: font-size:90%;
1.693 droeschl 7009: }
1.795 www 7010:
1.969 droeschl 7011: ol#LC_MenuBreadcrumbs h1 {
7012: display: inline;
7013: font-size: 90%;
7014: line-height: 2.5em;
7015: margin: 0;
7016: padding: 0;
7017: }
7018:
1.795 www 7019: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7020: text-decoration:none;
7021: font-size:100%;
7022: font-weight:bold;
1.693 droeschl 7023: }
1.795 www 7024:
1.840 bisitz 7025: .LC_Box {
1.911 bisitz 7026: border: solid 1px $lg_border_color;
7027: padding: 0 10px 10px 10px;
1.746 neumanie 7028: }
1.795 www 7029:
1.1020 raeburn 7030: .LC_DocsBox {
7031: border: solid 1px $lg_border_color;
7032: padding: 0 0 10px 10px;
7033: }
7034:
1.795 www 7035: .LC_AboutMe_Image {
1.911 bisitz 7036: float:left;
7037: margin-right:10px;
1.747 neumanie 7038: }
1.795 www 7039:
7040: .LC_Clear_AboutMe_Image {
1.911 bisitz 7041: clear:left;
1.747 neumanie 7042: }
1.795 www 7043:
1.721 harmsja 7044: dl.LC_ListStyleClean dt {
1.911 bisitz 7045: padding-right: 5px;
7046: display: table-header-group;
1.693 droeschl 7047: }
7048:
1.721 harmsja 7049: dl.LC_ListStyleClean dd {
1.911 bisitz 7050: display: table-row;
1.693 droeschl 7051: }
7052:
1.721 harmsja 7053: .LC_ListStyleClean,
7054: .LC_ListStyleSimple,
7055: .LC_ListStyleNormal,
1.795 www 7056: .LC_ListStyleSpecial {
1.911 bisitz 7057: /* display:block; */
7058: list-style-position: inside;
7059: list-style-type: none;
7060: overflow: hidden;
7061: padding: 0;
1.693 droeschl 7062: }
7063:
1.721 harmsja 7064: .LC_ListStyleSimple li,
7065: .LC_ListStyleSimple dd,
7066: .LC_ListStyleNormal li,
7067: .LC_ListStyleNormal dd,
7068: .LC_ListStyleSpecial li,
1.795 www 7069: .LC_ListStyleSpecial dd {
1.911 bisitz 7070: margin: 0;
7071: padding: 5px 5px 5px 10px;
7072: clear: both;
1.693 droeschl 7073: }
7074:
1.721 harmsja 7075: .LC_ListStyleClean li,
7076: .LC_ListStyleClean dd {
1.911 bisitz 7077: padding-top: 0;
7078: padding-bottom: 0;
1.693 droeschl 7079: }
7080:
1.721 harmsja 7081: .LC_ListStyleSimple dd,
1.795 www 7082: .LC_ListStyleSimple li {
1.911 bisitz 7083: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7084: }
7085:
1.721 harmsja 7086: .LC_ListStyleSpecial li,
7087: .LC_ListStyleSpecial dd {
1.911 bisitz 7088: list-style-type: none;
7089: background-color: RGB(220, 220, 220);
7090: margin-bottom: 4px;
1.693 droeschl 7091: }
7092:
1.721 harmsja 7093: table.LC_SimpleTable {
1.911 bisitz 7094: margin:5px;
7095: border:solid 1px $lg_border_color;
1.795 www 7096: }
1.693 droeschl 7097:
1.721 harmsja 7098: table.LC_SimpleTable tr {
1.911 bisitz 7099: padding: 0;
7100: border:solid 1px $lg_border_color;
1.693 droeschl 7101: }
1.795 www 7102:
7103: table.LC_SimpleTable thead {
1.911 bisitz 7104: background:rgb(220,220,220);
1.693 droeschl 7105: }
7106:
1.721 harmsja 7107: div.LC_columnSection {
1.911 bisitz 7108: display: block;
7109: clear: both;
7110: overflow: hidden;
7111: margin: 0;
1.693 droeschl 7112: }
7113:
1.721 harmsja 7114: div.LC_columnSection>* {
1.911 bisitz 7115: float: left;
7116: margin: 10px 20px 10px 0;
7117: overflow:hidden;
1.693 droeschl 7118: }
1.721 harmsja 7119:
1.795 www 7120: table em {
1.911 bisitz 7121: font-weight: bold;
7122: font-style: normal;
1.748 schulted 7123: }
1.795 www 7124:
1.779 bisitz 7125: table.LC_tableBrowseRes,
1.795 www 7126: table.LC_tableOfContent {
1.911 bisitz 7127: border:none;
7128: border-spacing: 1px;
7129: padding: 3px;
7130: background-color: #FFFFFF;
7131: font-size: 90%;
1.753 droeschl 7132: }
1.789 droeschl 7133:
1.911 bisitz 7134: table.LC_tableOfContent {
7135: border-collapse: collapse;
1.789 droeschl 7136: }
7137:
1.771 droeschl 7138: table.LC_tableBrowseRes a,
1.768 schulted 7139: table.LC_tableOfContent a {
1.911 bisitz 7140: background-color: transparent;
7141: text-decoration: none;
1.753 droeschl 7142: }
7143:
1.795 www 7144: table.LC_tableOfContent img {
1.911 bisitz 7145: border: none;
7146: height: 1.3em;
7147: vertical-align: text-bottom;
7148: margin-right: 0.3em;
1.753 droeschl 7149: }
1.757 schulted 7150:
1.795 www 7151: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7152: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7153: }
7154:
1.795 www 7155: a#LC_content_toolbar_everything {
1.911 bisitz 7156: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7157: }
7158:
1.795 www 7159: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7160: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7161: }
7162:
1.795 www 7163: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7164: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7165: }
7166:
1.795 www 7167: a#LC_content_toolbar_changefolder {
1.911 bisitz 7168: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7169: }
7170:
1.795 www 7171: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7172: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7173: }
7174:
1.1043 raeburn 7175: a#LC_content_toolbar_edittoplevel {
7176: background-image:url(/res/adm/pages/edittoplevel.gif);
7177: }
7178:
1.795 www 7179: ul#LC_toolbar li a:hover {
1.911 bisitz 7180: background-position: bottom center;
1.757 schulted 7181: }
7182:
1.795 www 7183: ul#LC_toolbar {
1.911 bisitz 7184: padding: 0;
7185: margin: 2px;
7186: list-style:none;
7187: position:relative;
7188: background-color:white;
1.1075.2.9 raeburn 7189: overflow: auto;
1.757 schulted 7190: }
7191:
1.795 www 7192: ul#LC_toolbar li {
1.911 bisitz 7193: border:1px solid white;
7194: padding: 0;
7195: margin: 0;
7196: float: left;
7197: display:inline;
7198: vertical-align:middle;
1.1075.2.9 raeburn 7199: white-space: nowrap;
1.911 bisitz 7200: }
1.757 schulted 7201:
1.783 amueller 7202:
1.795 www 7203: a.LC_toolbarItem {
1.911 bisitz 7204: display:block;
7205: padding: 0;
7206: margin: 0;
7207: height: 32px;
7208: width: 32px;
7209: color:white;
7210: border: none;
7211: background-repeat:no-repeat;
7212: background-color:transparent;
1.757 schulted 7213: }
7214:
1.915 droeschl 7215: ul.LC_funclist {
7216: margin: 0;
7217: padding: 0.5em 1em 0.5em 0;
7218: }
7219:
1.933 droeschl 7220: ul.LC_funclist > li:first-child {
7221: font-weight:bold;
7222: margin-left:0.8em;
7223: }
7224:
1.915 droeschl 7225: ul.LC_funclist + ul.LC_funclist {
7226: /*
7227: left border as a seperator if we have more than
7228: one list
7229: */
7230: border-left: 1px solid $sidebg;
7231: /*
7232: this hides the left border behind the border of the
7233: outer box if element is wrapped to the next 'line'
7234: */
7235: margin-left: -1px;
7236: }
7237:
1.843 bisitz 7238: ul.LC_funclist li {
1.915 droeschl 7239: display: inline;
1.782 bisitz 7240: white-space: nowrap;
1.915 droeschl 7241: margin: 0 0 0 25px;
7242: line-height: 150%;
1.782 bisitz 7243: }
7244:
1.974 wenzelju 7245: .LC_hidden {
7246: display: none;
7247: }
7248:
1.1030 www 7249: .LCmodal-overlay {
7250: position:fixed;
7251: top:0;
7252: right:0;
7253: bottom:0;
7254: left:0;
7255: height:100%;
7256: width:100%;
7257: margin:0;
7258: padding:0;
7259: background:#999;
7260: opacity:.75;
7261: filter: alpha(opacity=75);
7262: -moz-opacity: 0.75;
7263: z-index:101;
7264: }
7265:
7266: * html .LCmodal-overlay {
7267: position: absolute;
7268: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7269: }
7270:
7271: .LCmodal-window {
7272: position:fixed;
7273: top:50%;
7274: left:50%;
7275: margin:0;
7276: padding:0;
7277: z-index:102;
7278: }
7279:
7280: * html .LCmodal-window {
7281: position:absolute;
7282: }
7283:
7284: .LCclose-window {
7285: position:absolute;
7286: width:32px;
7287: height:32px;
7288: right:8px;
7289: top:8px;
7290: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7291: text-indent:-99999px;
7292: overflow:hidden;
7293: cursor:pointer;
7294: }
7295:
1.1075.2.17 raeburn 7296: /*
7297: styles used by TTH when "Default set of options to pass to tth/m
7298: when converting TeX" in course settings has been set
7299:
7300: option passed: -t
7301:
7302: */
7303:
7304: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7305: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7306: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7307: td div.norm {line-height:normal;}
7308:
7309: /*
7310: option passed -y3
7311: */
7312:
7313: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7314: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7315: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7316:
1.343 albertel 7317: END
7318: }
7319:
1.306 albertel 7320: =pod
7321:
7322: =item * &headtag()
7323:
7324: Returns a uniform footer for LON-CAPA web pages.
7325:
1.307 albertel 7326: Inputs: $title - optional title for the head
7327: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7328: $args - optional arguments
1.319 albertel 7329: force_register - if is true call registerurl so the remote is
7330: informed
1.415 albertel 7331: redirect -> array ref of
7332: 1- seconds before redirect occurs
7333: 2- url to redirect to
7334: 3- whether the side effect should occur
1.315 albertel 7335: (side effect of setting
7336: $env{'internal.head.redirect'} to the url
7337: redirected too)
1.352 albertel 7338: domain -> force to color decorate a page for a specific
7339: domain
7340: function -> force usage of a specific rolish color scheme
7341: bgcolor -> override the default page bgcolor
1.460 albertel 7342: no_auto_mt_title
7343: -> prevent &mt()ing the title arg
1.464 albertel 7344:
1.306 albertel 7345: =cut
7346:
7347: sub headtag {
1.313 albertel 7348: my ($title,$head_extra,$args) = @_;
1.306 albertel 7349:
1.363 albertel 7350: my $function = $args->{'function'} || &get_users_function();
7351: my $domain = $args->{'domain'} || &determinedomain();
7352: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7353: my $httphost = $args->{'use_absolute'};
1.418 albertel 7354: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7355: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7356: #time(),
1.418 albertel 7357: $env{'environment.color.timestamp'},
1.363 albertel 7358: $function,$domain,$bgcolor);
7359:
1.369 www 7360: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7361:
1.308 albertel 7362: my $result =
7363: '<head>'.
1.1075.2.56 raeburn 7364: &font_settings($args);
1.319 albertel 7365:
1.1075.2.72 raeburn 7366: my $inhibitprint;
7367: if ($args->{'print_suppress'}) {
7368: $inhibitprint = &print_suppression();
7369: }
1.1064 raeburn 7370:
1.461 albertel 7371: if (!$args->{'frameset'}) {
7372: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7373: }
1.1075.2.12 raeburn 7374: if ($args->{'force_register'}) {
7375: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7376: }
1.436 albertel 7377: if (!$args->{'no_nav_bar'}
7378: && !$args->{'only_body'}
7379: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7380: $result .= &help_menu_js($httphost);
1.1032 www 7381: $result.=&modal_window();
1.1038 www 7382: $result.=&togglebox_script();
1.1034 www 7383: $result.=&wishlist_window();
1.1041 www 7384: $result.=&LCprogressbarUpdate_script();
1.1034 www 7385: } else {
7386: if ($args->{'add_modal'}) {
7387: $result.=&modal_window();
7388: }
7389: if ($args->{'add_wishlist'}) {
7390: $result.=&wishlist_window();
7391: }
1.1038 www 7392: if ($args->{'add_togglebox'}) {
7393: $result.=&togglebox_script();
7394: }
1.1041 www 7395: if ($args->{'add_progressbar'}) {
7396: $result.=&LCprogressbarUpdate_script();
7397: }
1.436 albertel 7398: }
1.314 albertel 7399: if (ref($args->{'redirect'})) {
1.414 albertel 7400: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7401: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7402: if (!$inhibit_continue) {
7403: $env{'internal.head.redirect'} = $url;
7404: }
1.313 albertel 7405: $result.=<<ADDMETA
7406: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7407: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7408: ADDMETA
7409: }
1.306 albertel 7410: if (!defined($title)) {
7411: $title = 'The LearningOnline Network with CAPA';
7412: }
1.460 albertel 7413: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7414: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7415: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7416: if (!$args->{'frameset'}) {
7417: $result .= ' /';
7418: }
7419: $result .= '>'
1.1064 raeburn 7420: .$inhibitprint
1.414 albertel 7421: .$head_extra;
1.1075.2.42 raeburn 7422: if ($env{'browser.mobile'}) {
7423: $result .= '
7424: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7425: <meta name="apple-mobile-web-app-capable" content="yes" />';
7426: }
1.962 droeschl 7427: return $result.'</head>';
1.306 albertel 7428: }
7429:
7430: =pod
7431:
1.340 albertel 7432: =item * &font_settings()
7433:
7434: Returns neccessary <meta> to set the proper encoding
7435:
1.1075.2.56 raeburn 7436: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7437:
7438: =cut
7439:
7440: sub font_settings {
1.1075.2.56 raeburn 7441: my ($args) = @_;
1.340 albertel 7442: my $headerstring='';
1.1075.2.56 raeburn 7443: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7444: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7445: $headerstring.=
1.1075.2.61 raeburn 7446: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7447: if (!$args->{'frameset'}) {
7448: $headerstring.= ' /';
7449: }
7450: $headerstring .= '>'."\n";
1.340 albertel 7451: }
7452: return $headerstring;
7453: }
7454:
1.341 albertel 7455: =pod
7456:
1.1064 raeburn 7457: =item * &print_suppression()
7458:
7459: In course context returns css which causes the body to be blank when media="print",
7460: if printout generation is unavailable for the current resource.
7461:
7462: This could be because:
7463:
7464: (a) printstartdate is in the future
7465:
7466: (b) printenddate is in the past
7467:
7468: (c) there is an active exam block with "printout"
7469: functionality blocked
7470:
7471: Users with pav, pfo or evb privileges are exempt.
7472:
7473: Inputs: none
7474:
7475: =cut
7476:
7477:
7478: sub print_suppression {
7479: my $noprint;
7480: if ($env{'request.course.id'}) {
7481: my $scope = $env{'request.course.id'};
7482: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7483: (&Apache::lonnet::allowed('pfo',$scope))) {
7484: return;
7485: }
7486: if ($env{'request.course.sec'} ne '') {
7487: $scope .= "/$env{'request.course.sec'}";
7488: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7489: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7490: return;
1.1064 raeburn 7491: }
7492: }
7493: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7494: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 7495: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 7496: if ($blocked) {
7497: my $checkrole = "cm./$cdom/$cnum";
7498: if ($env{'request.course.sec'} ne '') {
7499: $checkrole .= "/$env{'request.course.sec'}";
7500: }
7501: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7502: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7503: $noprint = 1;
7504: }
7505: }
7506: unless ($noprint) {
7507: my $symb = &Apache::lonnet::symbread();
7508: if ($symb ne '') {
7509: my $navmap = Apache::lonnavmaps::navmap->new();
7510: if (ref($navmap)) {
7511: my $res = $navmap->getBySymb($symb);
7512: if (ref($res)) {
7513: if (!$res->resprintable()) {
7514: $noprint = 1;
7515: }
7516: }
7517: }
7518: }
7519: }
7520: if ($noprint) {
7521: return <<"ENDSTYLE";
7522: <style type="text/css" media="print">
7523: body { display:none }
7524: </style>
7525: ENDSTYLE
7526: }
7527: }
7528: return;
7529: }
7530:
7531: =pod
7532:
1.341 albertel 7533: =item * &xml_begin()
7534:
7535: Returns the needed doctype and <html>
7536:
7537: Inputs: none
7538:
7539: =cut
7540:
7541: sub xml_begin {
1.1075.2.61 raeburn 7542: my ($is_frameset) = @_;
1.341 albertel 7543: my $output='';
7544:
7545: if ($env{'browser.mathml'}) {
7546: $output='<?xml version="1.0"?>'
7547: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7548: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7549:
7550: # .'<!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">] >'
7551: .'<!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">'
7552: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7553: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 7554: } elsif ($is_frameset) {
7555: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7556: '<html>'."\n";
1.341 albertel 7557: } else {
1.1075.2.61 raeburn 7558: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7559: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7560: }
7561: return $output;
7562: }
1.340 albertel 7563:
7564: =pod
7565:
1.306 albertel 7566: =item * &start_page()
7567:
7568: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7569:
1.648 raeburn 7570: Inputs:
7571:
7572: =over 4
7573:
7574: $title - optional title for the page
7575:
7576: $head_extra - optional extra HTML to incude inside the <head>
7577:
7578: $args - additional optional args supported are:
7579:
7580: =over 8
7581:
7582: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7583: arg on
1.814 bisitz 7584: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7585: add_entries -> additional attributes to add to the <body>
7586: domain -> force to color decorate a page for a
1.317 albertel 7587: specific domain
1.648 raeburn 7588: function -> force usage of a specific rolish color
1.317 albertel 7589: scheme
1.648 raeburn 7590: redirect -> see &headtag()
7591: bgcolor -> override the default page bg color
7592: js_ready -> return a string ready for being used in
1.317 albertel 7593: a javascript writeln
1.648 raeburn 7594: html_encode -> return a string ready for being used in
1.320 albertel 7595: a html attribute
1.648 raeburn 7596: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7597: $forcereg arg
1.648 raeburn 7598: frameset -> if true will start with a <frameset>
1.330 albertel 7599: rather than <body>
1.648 raeburn 7600: skip_phases -> hash ref of
1.338 albertel 7601: head -> skip the <html><head> generation
7602: body -> skip all <body> generation
1.1075.2.12 raeburn 7603: no_inline_link -> if true and in remote mode, don't show the
7604: 'Switch To Inline Menu' link
1.648 raeburn 7605: no_auto_mt_title -> prevent &mt()ing the title arg
7606: inherit_jsmath -> when creating popup window in a page,
7607: should it have jsmath forced on by the
7608: current page
1.867 kalberla 7609: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7610: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.15 raeburn 7611: group -> includes the current group, if page is for a
7612: specific group
1.361 albertel 7613:
1.648 raeburn 7614: =back
1.460 albertel 7615:
1.648 raeburn 7616: =back
1.562 albertel 7617:
1.306 albertel 7618: =cut
7619:
7620: sub start_page {
1.309 albertel 7621: my ($title,$head_extra,$args) = @_;
1.318 albertel 7622: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7623:
1.315 albertel 7624: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 7625: my ($result,@advtools);
1.964 droeschl 7626:
1.338 albertel 7627: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 7628: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 7629: }
7630:
7631: if (! exists($args->{'skip_phases'}{'body'}) ) {
7632: if ($args->{'frameset'}) {
7633: my $attr_string = &make_attr_string($args->{'force_register'},
7634: $args->{'add_entries'});
7635: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7636: } else {
7637: $result .=
7638: &bodytag($title,
7639: $args->{'function'}, $args->{'add_entries'},
7640: $args->{'only_body'}, $args->{'domain'},
7641: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 7642: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 7643: $args, \@advtools);
1.831 bisitz 7644: }
1.330 albertel 7645: }
1.338 albertel 7646:
1.315 albertel 7647: if ($args->{'js_ready'}) {
1.713 kaisler 7648: $result = &js_ready($result);
1.315 albertel 7649: }
1.320 albertel 7650: if ($args->{'html_encode'}) {
1.713 kaisler 7651: $result = &html_encode($result);
7652: }
7653:
1.813 bisitz 7654: # Preparation for new and consistent functionlist at top of screen
7655: # if ($args->{'functionlist'}) {
7656: # $result .= &build_functionlist();
7657: #}
7658:
1.964 droeschl 7659: # Don't add anything more if only_body wanted or in const space
7660: return $result if $args->{'only_body'}
7661: || $env{'request.state'} eq 'construct';
1.813 bisitz 7662:
7663: #Breadcrumbs
1.758 kaisler 7664: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7665: &Apache::lonhtmlcommon::clear_breadcrumbs();
7666: #if any br links exists, add them to the breadcrumbs
7667: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7668: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7669: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7670: }
7671: }
1.1075.2.19 raeburn 7672: # if @advtools array contains items add then to the breadcrumbs
7673: if (@advtools > 0) {
7674: &Apache::lonmenu::advtools_crumbs(@advtools);
7675: }
1.758 kaisler 7676:
7677: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7678: if(exists($args->{'bread_crumbs_component'})){
7679: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7680: }else{
7681: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7682: }
1.1075.2.24 raeburn 7683: } elsif (($env{'environment.remote'} eq 'on') &&
7684: ($env{'form.inhibitmenu'} ne 'yes') &&
7685: ($env{'request.noversionuri'} =~ m{^/res/}) &&
7686: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 7687: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 7688: }
1.315 albertel 7689: return $result;
1.306 albertel 7690: }
7691:
7692: sub end_page {
1.315 albertel 7693: my ($args) = @_;
7694: $env{'internal.end_page'}++;
1.330 albertel 7695: my $result;
1.335 albertel 7696: if ($args->{'discussion'}) {
7697: my ($target,$parser);
7698: if (ref($args->{'discussion'})) {
7699: ($target,$parser) =($args->{'discussion'}{'target'},
7700: $args->{'discussion'}{'parser'});
7701: }
7702: $result .= &Apache::lonxml::xmlend($target,$parser);
7703: }
1.330 albertel 7704: if ($args->{'frameset'}) {
7705: $result .= '</frameset>';
7706: } else {
1.635 raeburn 7707: $result .= &endbodytag($args);
1.330 albertel 7708: }
1.1075.2.6 raeburn 7709: unless ($args->{'notbody'}) {
7710: $result .= "\n</html>";
7711: }
1.330 albertel 7712:
1.315 albertel 7713: if ($args->{'js_ready'}) {
1.317 albertel 7714: $result = &js_ready($result);
1.315 albertel 7715: }
1.335 albertel 7716:
1.320 albertel 7717: if ($args->{'html_encode'}) {
7718: $result = &html_encode($result);
7719: }
1.335 albertel 7720:
1.315 albertel 7721: return $result;
7722: }
7723:
1.1034 www 7724: sub wishlist_window {
7725: return(<<'ENDWISHLIST');
1.1046 raeburn 7726: <script type="text/javascript">
1.1034 www 7727: // <![CDATA[
7728: // <!-- BEGIN LON-CAPA Internal
7729: function set_wishlistlink(title, path) {
7730: if (!title) {
7731: title = document.title;
7732: title = title.replace(/^LON-CAPA /,'');
7733: }
1.1075.2.65 raeburn 7734: title = encodeURIComponent(title);
1.1075.2.83 raeburn 7735: title = title.replace("'","\\\'");
1.1034 www 7736: if (!path) {
7737: path = location.pathname;
7738: }
1.1075.2.65 raeburn 7739: path = encodeURIComponent(path);
1.1075.2.83 raeburn 7740: path = path.replace("'","\\\'");
1.1034 www 7741: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7742: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7743: }
7744: // END LON-CAPA Internal -->
7745: // ]]>
7746: </script>
7747: ENDWISHLIST
7748: }
7749:
1.1030 www 7750: sub modal_window {
7751: return(<<'ENDMODAL');
1.1046 raeburn 7752: <script type="text/javascript">
1.1030 www 7753: // <![CDATA[
7754: // <!-- BEGIN LON-CAPA Internal
7755: var modalWindow = {
7756: parent:"body",
7757: windowId:null,
7758: content:null,
7759: width:null,
7760: height:null,
7761: close:function()
7762: {
7763: $(".LCmodal-window").remove();
7764: $(".LCmodal-overlay").remove();
7765: },
7766: open:function()
7767: {
7768: var modal = "";
7769: modal += "<div class=\"LCmodal-overlay\"></div>";
7770: 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;\">";
7771: modal += this.content;
7772: modal += "</div>";
7773:
7774: $(this.parent).append(modal);
7775:
7776: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7777: $(".LCclose-window").click(function(){modalWindow.close();});
7778: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7779: }
7780: };
1.1075.2.42 raeburn 7781: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7782: {
1.1075.2.83 raeburn 7783: source = source.replace("'","'");
1.1030 www 7784: modalWindow.windowId = "myModal";
7785: modalWindow.width = width;
7786: modalWindow.height = height;
1.1075.2.80 raeburn 7787: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7788: modalWindow.open();
7789: };
7790: // END LON-CAPA Internal -->
7791: // ]]>
7792: </script>
7793: ENDMODAL
7794: }
7795:
7796: sub modal_link {
1.1075.2.42 raeburn 7797: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7798: unless ($width) { $width=480; }
7799: unless ($height) { $height=400; }
1.1031 www 7800: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 7801: unless ($transparency) { $transparency='true'; }
7802:
1.1074 raeburn 7803: my $target_attr;
7804: if (defined($target)) {
7805: $target_attr = 'target="'.$target.'"';
7806: }
7807: return <<"ENDLINK";
1.1075.2.42 raeburn 7808: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7809: $linktext</a>
7810: ENDLINK
1.1030 www 7811: }
7812:
1.1032 www 7813: sub modal_adhoc_script {
7814: my ($funcname,$width,$height,$content)=@_;
7815: return (<<ENDADHOC);
1.1046 raeburn 7816: <script type="text/javascript">
1.1032 www 7817: // <![CDATA[
7818: var $funcname = function()
7819: {
7820: modalWindow.windowId = "myModal";
7821: modalWindow.width = $width;
7822: modalWindow.height = $height;
7823: modalWindow.content = '$content';
7824: modalWindow.open();
7825: };
7826: // ]]>
7827: </script>
7828: ENDADHOC
7829: }
7830:
1.1041 www 7831: sub modal_adhoc_inner {
7832: my ($funcname,$width,$height,$content)=@_;
7833: my $innerwidth=$width-20;
7834: $content=&js_ready(
1.1042 www 7835: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 7836: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7837: $content.
1.1041 www 7838: &end_scrollbox().
1.1075.2.42 raeburn 7839: &end_page()
1.1041 www 7840: );
7841: return &modal_adhoc_script($funcname,$width,$height,$content);
7842: }
7843:
7844: sub modal_adhoc_window {
7845: my ($funcname,$width,$height,$content,$linktext)=@_;
7846: return &modal_adhoc_inner($funcname,$width,$height,$content).
7847: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7848: }
7849:
7850: sub modal_adhoc_launch {
7851: my ($funcname,$width,$height,$content)=@_;
7852: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7853: <script type="text/javascript">
7854: // <![CDATA[
7855: $funcname();
7856: // ]]>
7857: </script>
7858: ENDLAUNCH
7859: }
7860:
7861: sub modal_adhoc_close {
7862: return (<<ENDCLOSE);
7863: <script type="text/javascript">
7864: // <![CDATA[
7865: modalWindow.close();
7866: // ]]>
7867: </script>
7868: ENDCLOSE
7869: }
7870:
1.1038 www 7871: sub togglebox_script {
7872: return(<<ENDTOGGLE);
7873: <script type="text/javascript">
7874: // <![CDATA[
7875: function LCtoggleDisplay(id,hidetext,showtext) {
7876: link = document.getElementById(id + "link").childNodes[0];
7877: with (document.getElementById(id).style) {
7878: if (display == "none" ) {
7879: display = "inline";
7880: link.nodeValue = hidetext;
7881: } else {
7882: display = "none";
7883: link.nodeValue = showtext;
7884: }
7885: }
7886: }
7887: // ]]>
7888: </script>
7889: ENDTOGGLE
7890: }
7891:
1.1039 www 7892: sub start_togglebox {
7893: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7894: unless ($heading) { $heading=''; } else { $heading.=' '; }
7895: unless ($showtext) { $showtext=&mt('show'); }
7896: unless ($hidetext) { $hidetext=&mt('hide'); }
7897: unless ($headerbg) { $headerbg='#FFFFFF'; }
7898: return &start_data_table().
7899: &start_data_table_header_row().
7900: '<td bgcolor="'.$headerbg.'">'.$heading.
7901: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7902: $showtext.'\')">'.$showtext.'</a>]</td>'.
7903: &end_data_table_header_row().
7904: '<tr id="'.$id.'" style="display:none""><td>';
7905: }
7906:
7907: sub end_togglebox {
7908: return '</td></tr>'.&end_data_table();
7909: }
7910:
1.1041 www 7911: sub LCprogressbar_script {
1.1045 www 7912: my ($id)=@_;
1.1041 www 7913: return(<<ENDPROGRESS);
7914: <script type="text/javascript">
7915: // <![CDATA[
1.1045 www 7916: \$('#progressbar$id').progressbar({
1.1041 www 7917: value: 0,
7918: change: function(event, ui) {
7919: var newVal = \$(this).progressbar('option', 'value');
7920: \$('.pblabel', this).text(LCprogressTxt);
7921: }
7922: });
7923: // ]]>
7924: </script>
7925: ENDPROGRESS
7926: }
7927:
7928: sub LCprogressbarUpdate_script {
7929: return(<<ENDPROGRESSUPDATE);
7930: <style type="text/css">
7931: .ui-progressbar { position:relative; }
7932: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7933: </style>
7934: <script type="text/javascript">
7935: // <![CDATA[
1.1045 www 7936: var LCprogressTxt='---';
7937:
7938: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7939: LCprogressTxt=progresstext;
1.1045 www 7940: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7941: }
7942: // ]]>
7943: </script>
7944: ENDPROGRESSUPDATE
7945: }
7946:
1.1042 www 7947: my $LClastpercent;
1.1045 www 7948: my $LCidcnt;
7949: my $LCcurrentid;
1.1042 www 7950:
1.1041 www 7951: sub LCprogressbar {
1.1042 www 7952: my ($r)=(@_);
7953: $LClastpercent=0;
1.1045 www 7954: $LCidcnt++;
7955: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7956: my $starting=&mt('Starting');
7957: my $content=(<<ENDPROGBAR);
1.1045 www 7958: <div id="progressbar$LCcurrentid">
1.1041 www 7959: <span class="pblabel">$starting</span>
7960: </div>
7961: ENDPROGBAR
1.1045 www 7962: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7963: }
7964:
7965: sub LCprogressbarUpdate {
1.1042 www 7966: my ($r,$val,$text)=@_;
7967: unless ($val) {
7968: if ($LClastpercent) {
7969: $val=$LClastpercent;
7970: } else {
7971: $val=0;
7972: }
7973: }
1.1041 www 7974: if ($val<0) { $val=0; }
7975: if ($val>100) { $val=0; }
1.1042 www 7976: $LClastpercent=$val;
1.1041 www 7977: unless ($text) { $text=$val.'%'; }
7978: $text=&js_ready($text);
1.1044 www 7979: &r_print($r,<<ENDUPDATE);
1.1041 www 7980: <script type="text/javascript">
7981: // <![CDATA[
1.1045 www 7982: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7983: // ]]>
7984: </script>
7985: ENDUPDATE
1.1035 www 7986: }
7987:
1.1042 www 7988: sub LCprogressbarClose {
7989: my ($r)=@_;
7990: $LClastpercent=0;
1.1044 www 7991: &r_print($r,<<ENDCLOSE);
1.1042 www 7992: <script type="text/javascript">
7993: // <![CDATA[
1.1045 www 7994: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7995: // ]]>
7996: </script>
7997: ENDCLOSE
1.1044 www 7998: }
7999:
8000: sub r_print {
8001: my ($r,$to_print)=@_;
8002: if ($r) {
8003: $r->print($to_print);
8004: $r->rflush();
8005: } else {
8006: print($to_print);
8007: }
1.1042 www 8008: }
8009:
1.320 albertel 8010: sub html_encode {
8011: my ($result) = @_;
8012:
1.322 albertel 8013: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8014:
8015: return $result;
8016: }
1.1044 www 8017:
1.317 albertel 8018: sub js_ready {
8019: my ($result) = @_;
8020:
1.323 albertel 8021: $result =~ s/[\n\r]/ /xmsg;
8022: $result =~ s/\\/\\\\/xmsg;
8023: $result =~ s/'/\\'/xmsg;
1.372 albertel 8024: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8025:
8026: return $result;
8027: }
8028:
1.315 albertel 8029: sub validate_page {
8030: if ( exists($env{'internal.start_page'})
1.316 albertel 8031: && $env{'internal.start_page'} > 1) {
8032: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8033: $env{'internal.start_page'}.' '.
1.316 albertel 8034: $ENV{'request.filename'});
1.315 albertel 8035: }
8036: if ( exists($env{'internal.end_page'})
1.316 albertel 8037: && $env{'internal.end_page'} > 1) {
8038: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8039: $env{'internal.end_page'}.' '.
1.316 albertel 8040: $env{'request.filename'});
1.315 albertel 8041: }
8042: if ( exists($env{'internal.start_page'})
8043: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8044: &Apache::lonnet::logthis('start_page called without end_page '.
8045: $env{'request.filename'});
1.315 albertel 8046: }
8047: if ( ! exists($env{'internal.start_page'})
8048: && exists($env{'internal.end_page'})) {
1.316 albertel 8049: &Apache::lonnet::logthis('end_page called without start_page'.
8050: $env{'request.filename'});
1.315 albertel 8051: }
1.306 albertel 8052: }
1.315 albertel 8053:
1.996 www 8054:
8055: sub start_scrollbox {
1.1075.2.56 raeburn 8056: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8057: unless ($outerwidth) { $outerwidth='520px'; }
8058: unless ($width) { $width='500px'; }
8059: unless ($height) { $height='200px'; }
1.1075 raeburn 8060: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8061: if ($id ne '') {
1.1075.2.42 raeburn 8062: $table_id = ' id="table_'.$id.'"';
8063: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8064: }
1.1075 raeburn 8065: if ($bgcolor ne '') {
8066: $tdcol = "background-color: $bgcolor;";
8067: }
1.1075.2.42 raeburn 8068: my $nicescroll_js;
8069: if ($env{'browser.mobile'}) {
8070: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8071: }
1.1075 raeburn 8072: return <<"END";
1.1075.2.42 raeburn 8073: $nicescroll_js
8074:
8075: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8076: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8077: END
1.996 www 8078: }
8079:
8080: sub end_scrollbox {
1.1036 www 8081: return '</div></td></tr></table>';
1.996 www 8082: }
8083:
1.1075.2.42 raeburn 8084: sub nicescroll_javascript {
8085: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8086: my %options;
8087: if (ref($cursor) eq 'HASH') {
8088: %options = %{$cursor};
8089: }
8090: unless ($options{'railalign'} =~ /^left|right$/) {
8091: $options{'railalign'} = 'left';
8092: }
8093: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8094: my $function = &get_users_function();
8095: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8096: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8097: $options{'cursorcolor'} = '#00F';
8098: }
8099: }
8100: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8101: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8102: $options{'cursoropacity'}='1.0';
8103: }
8104: } else {
8105: $options{'cursoropacity'}='1.0';
8106: }
8107: if ($options{'cursorfixedheight'} eq 'none') {
8108: delete($options{'cursorfixedheight'});
8109: } else {
8110: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8111: }
8112: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8113: delete($options{'railoffset'});
8114: }
8115: my @niceoptions;
8116: while (my($key,$value) = each(%options)) {
8117: if ($value =~ /^\{.+\}$/) {
8118: push(@niceoptions,$key.':'.$value);
8119: } else {
8120: push(@niceoptions,$key.':"'.$value.'"');
8121: }
8122: }
8123: my $nicescroll_js = '
8124: $(document).ready(
8125: function() {
8126: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8127: }
8128: );
8129: ';
8130: if ($framecheck) {
8131: $nicescroll_js .= '
8132: function expand_div(caller) {
8133: if (top === self) {
8134: document.getElementById("'.$id.'").style.width = "auto";
8135: document.getElementById("'.$id.'").style.height = "auto";
8136: } else {
8137: try {
8138: if (parent.frames) {
8139: if (parent.frames.length > 1) {
8140: var framesrc = parent.frames[1].location.href;
8141: var currsrc = framesrc.replace(/\#.*$/,"");
8142: if ((caller == "search") || (currsrc == "'.$location.'")) {
8143: document.getElementById("'.$id.'").style.width = "auto";
8144: document.getElementById("'.$id.'").style.height = "auto";
8145: }
8146: }
8147: }
8148: } catch (e) {
8149: return;
8150: }
8151: }
8152: return;
8153: }
8154: ';
8155: }
8156: if ($needjsready) {
8157: $nicescroll_js = '
8158: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8159: } else {
8160: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8161: }
8162: return $nicescroll_js;
8163: }
8164:
1.318 albertel 8165: sub simple_error_page {
1.1075.2.49 raeburn 8166: my ($r,$title,$msg,$args) = @_;
8167: if (ref($args) eq 'HASH') {
8168: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8169: } else {
8170: $msg = &mt($msg);
8171: }
8172:
1.318 albertel 8173: my $page =
8174: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8175: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8176: &Apache::loncommon::end_page();
8177: if (ref($r)) {
8178: $r->print($page);
1.327 albertel 8179: return;
1.318 albertel 8180: }
8181: return $page;
8182: }
1.347 albertel 8183:
8184: {
1.610 albertel 8185: my @row_count;
1.961 onken 8186:
8187: sub start_data_table_count {
8188: unshift(@row_count, 0);
8189: return;
8190: }
8191:
8192: sub end_data_table_count {
8193: shift(@row_count);
8194: return;
8195: }
8196:
1.347 albertel 8197: sub start_data_table {
1.1018 raeburn 8198: my ($add_class,$id) = @_;
1.422 albertel 8199: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8200: my $table_id;
8201: if (defined($id)) {
8202: $table_id = ' id="'.$id.'"';
8203: }
1.961 onken 8204: &start_data_table_count();
1.1018 raeburn 8205: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8206: }
8207:
8208: sub end_data_table {
1.961 onken 8209: &end_data_table_count();
1.389 albertel 8210: return '</table>'."\n";;
1.347 albertel 8211: }
8212:
8213: sub start_data_table_row {
1.974 wenzelju 8214: my ($add_class, $id) = @_;
1.610 albertel 8215: $row_count[0]++;
8216: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8217: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8218: $id = (' id="'.$id.'"') unless ($id eq '');
8219: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8220: }
1.471 banghart 8221:
8222: sub continue_data_table_row {
1.974 wenzelju 8223: my ($add_class, $id) = @_;
1.610 albertel 8224: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8225: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8226: $id = (' id="'.$id.'"') unless ($id eq '');
8227: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8228: }
1.347 albertel 8229:
8230: sub end_data_table_row {
1.389 albertel 8231: return '</tr>'."\n";;
1.347 albertel 8232: }
1.367 www 8233:
1.421 albertel 8234: sub start_data_table_empty_row {
1.707 bisitz 8235: # $row_count[0]++;
1.421 albertel 8236: return '<tr class="LC_empty_row" >'."\n";;
8237: }
8238:
8239: sub end_data_table_empty_row {
8240: return '</tr>'."\n";;
8241: }
8242:
1.367 www 8243: sub start_data_table_header_row {
1.389 albertel 8244: return '<tr class="LC_header_row">'."\n";;
1.367 www 8245: }
8246:
8247: sub end_data_table_header_row {
1.389 albertel 8248: return '</tr>'."\n";;
1.367 www 8249: }
1.890 droeschl 8250:
8251: sub data_table_caption {
8252: my $caption = shift;
8253: return "<caption class=\"LC_caption\">$caption</caption>";
8254: }
1.347 albertel 8255: }
8256:
1.548 albertel 8257: =pod
8258:
8259: =item * &inhibit_menu_check($arg)
8260:
8261: Checks for a inhibitmenu state and generates output to preserve it
8262:
8263: Inputs: $arg - can be any of
8264: - undef - in which case the return value is a string
8265: to add into arguments list of a uri
8266: - 'input' - in which case the return value is a HTML
8267: <form> <input> field of type hidden to
8268: preserve the value
8269: - a url - in which case the return value is the url with
8270: the neccesary cgi args added to preserve the
8271: inhibitmenu state
8272: - a ref to a url - no return value, but the string is
8273: updated to include the neccessary cgi
8274: args to preserve the inhibitmenu state
8275:
8276: =cut
8277:
8278: sub inhibit_menu_check {
8279: my ($arg) = @_;
8280: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8281: if ($arg eq 'input') {
8282: if ($env{'form.inhibitmenu'}) {
8283: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8284: } else {
8285: return
8286: }
8287: }
8288: if ($env{'form.inhibitmenu'}) {
8289: if (ref($arg)) {
8290: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8291: } elsif ($arg eq '') {
8292: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8293: } else {
8294: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8295: }
8296: }
8297: if (!ref($arg)) {
8298: return $arg;
8299: }
8300: }
8301:
1.251 albertel 8302: ###############################################
1.182 matthew 8303:
8304: =pod
8305:
1.549 albertel 8306: =back
8307:
8308: =head1 User Information Routines
8309:
8310: =over 4
8311:
1.405 albertel 8312: =item * &get_users_function()
1.182 matthew 8313:
8314: Used by &bodytag to determine the current users primary role.
8315: Returns either 'student','coordinator','admin', or 'author'.
8316:
8317: =cut
8318:
8319: ###############################################
8320: sub get_users_function {
1.815 tempelho 8321: my $function = 'norole';
1.818 tempelho 8322: if ($env{'request.role'}=~/^(st)/) {
8323: $function='student';
8324: }
1.907 raeburn 8325: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8326: $function='coordinator';
8327: }
1.258 albertel 8328: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8329: $function='admin';
8330: }
1.826 bisitz 8331: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8332: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8333: $function='author';
8334: }
8335: return $function;
1.54 www 8336: }
1.99 www 8337:
8338: ###############################################
8339:
1.233 raeburn 8340: =pod
8341:
1.821 raeburn 8342: =item * &show_course()
8343:
8344: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8345: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8346:
8347: Inputs:
8348: None
8349:
8350: Outputs:
8351: Scalar: 1 if 'Course' to be used, 0 otherwise.
8352:
8353: =cut
8354:
8355: ###############################################
8356: sub show_course {
8357: my $course = !$env{'user.adv'};
8358: if (!$env{'user.adv'}) {
8359: foreach my $env (keys(%env)) {
8360: next if ($env !~ m/^user\.priv\./);
8361: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8362: $course = 0;
8363: last;
8364: }
8365: }
8366: }
8367: return $course;
8368: }
8369:
8370: ###############################################
8371:
8372: =pod
8373:
1.542 raeburn 8374: =item * &check_user_status()
1.274 raeburn 8375:
8376: Determines current status of supplied role for a
8377: specific user. Roles can be active, previous or future.
8378:
8379: Inputs:
8380: user's domain, user's username, course's domain,
1.375 raeburn 8381: course's number, optional section ID.
1.274 raeburn 8382:
8383: Outputs:
8384: role status: active, previous or future.
8385:
8386: =cut
8387:
8388: sub check_user_status {
1.412 raeburn 8389: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8390: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 8391: my @uroles = keys(%userinfo);
1.274 raeburn 8392: my $srchstr;
8393: my $active_chk = 'none';
1.412 raeburn 8394: my $now = time;
1.274 raeburn 8395: if (@uroles > 0) {
1.908 raeburn 8396: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8397: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8398: } else {
1.412 raeburn 8399: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8400: }
8401: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8402: my $role_end = 0;
8403: my $role_start = 0;
8404: $active_chk = 'active';
1.412 raeburn 8405: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8406: $role_end = $1;
8407: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8408: $role_start = $1;
1.274 raeburn 8409: }
8410: }
8411: if ($role_start > 0) {
1.412 raeburn 8412: if ($now < $role_start) {
1.274 raeburn 8413: $active_chk = 'future';
8414: }
8415: }
8416: if ($role_end > 0) {
1.412 raeburn 8417: if ($now > $role_end) {
1.274 raeburn 8418: $active_chk = 'previous';
8419: }
8420: }
8421: }
8422: }
8423: return $active_chk;
8424: }
8425:
8426: ###############################################
8427:
8428: =pod
8429:
1.405 albertel 8430: =item * &get_sections()
1.233 raeburn 8431:
8432: Determines all the sections for a course including
8433: sections with students and sections containing other roles.
1.419 raeburn 8434: Incoming parameters:
8435:
8436: 1. domain
8437: 2. course number
8438: 3. reference to array containing roles for which sections should
8439: be gathered (optional).
8440: 4. reference to array containing status types for which sections
8441: should be gathered (optional).
8442:
8443: If the third argument is undefined, sections are gathered for any role.
8444: If the fourth argument is undefined, sections are gathered for any status.
8445: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8446:
1.374 raeburn 8447: Returns section hash (keys are section IDs, values are
8448: number of users in each section), subject to the
1.419 raeburn 8449: optional roles filter, optional status filter
1.233 raeburn 8450:
8451: =cut
8452:
8453: ###############################################
8454: sub get_sections {
1.419 raeburn 8455: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8456: if (!defined($cdom) || !defined($cnum)) {
8457: my $cid = $env{'request.course.id'};
8458:
8459: return if (!defined($cid));
8460:
8461: $cdom = $env{'course.'.$cid.'.domain'};
8462: $cnum = $env{'course.'.$cid.'.num'};
8463: }
8464:
8465: my %sectioncount;
1.419 raeburn 8466: my $now = time;
1.240 albertel 8467:
1.1075.2.33 raeburn 8468: my $check_students = 1;
8469: my $only_students = 0;
8470: if (ref($possible_roles) eq 'ARRAY') {
8471: if (grep(/^st$/,@{$possible_roles})) {
8472: if (@{$possible_roles} == 1) {
8473: $only_students = 1;
8474: }
8475: } else {
8476: $check_students = 0;
8477: }
8478: }
8479:
8480: if ($check_students) {
1.276 albertel 8481: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8482: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8483: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8484: my $start_index = &Apache::loncoursedata::CL_START();
8485: my $end_index = &Apache::loncoursedata::CL_END();
8486: my $status;
1.366 albertel 8487: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8488: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8489: $data->[$status_index],
8490: $data->[$start_index],
8491: $data->[$end_index]);
8492: if ($stu_status eq 'Active') {
8493: $status = 'active';
8494: } elsif ($end < $now) {
8495: $status = 'previous';
8496: } elsif ($start > $now) {
8497: $status = 'future';
8498: }
8499: if ($section ne '-1' && $section !~ /^\s*$/) {
8500: if ((!defined($possible_status)) || (($status ne '') &&
8501: (grep/^\Q$status\E$/,@{$possible_status}))) {
8502: $sectioncount{$section}++;
8503: }
1.240 albertel 8504: }
8505: }
8506: }
1.1075.2.33 raeburn 8507: if ($only_students) {
8508: return %sectioncount;
8509: }
1.240 albertel 8510: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8511: foreach my $user (sort(keys(%courseroles))) {
8512: if ($user !~ /^(\w{2})/) { next; }
8513: my ($role) = ($user =~ /^(\w{2})/);
8514: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8515: my ($section,$status);
1.240 albertel 8516: if ($role eq 'cr' &&
8517: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8518: $section=$1;
8519: }
8520: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8521: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8522: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8523: if ($end == -1 && $start == -1) {
8524: next; #deleted role
8525: }
8526: if (!defined($possible_status)) {
8527: $sectioncount{$section}++;
8528: } else {
8529: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8530: $status = 'active';
8531: } elsif ($end < $now) {
8532: $status = 'future';
8533: } elsif ($start > $now) {
8534: $status = 'previous';
8535: }
8536: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8537: $sectioncount{$section}++;
8538: }
8539: }
1.233 raeburn 8540: }
1.366 albertel 8541: return %sectioncount;
1.233 raeburn 8542: }
8543:
1.274 raeburn 8544: ###############################################
1.294 raeburn 8545:
8546: =pod
1.405 albertel 8547:
8548: =item * &get_course_users()
8549:
1.275 raeburn 8550: Retrieves usernames:domains for users in the specified course
8551: with specific role(s), and access status.
8552:
8553: Incoming parameters:
1.277 albertel 8554: 1. course domain
8555: 2. course number
8556: 3. access status: users must have - either active,
1.275 raeburn 8557: previous, future, or all.
1.277 albertel 8558: 4. reference to array of permissible roles
1.288 raeburn 8559: 5. reference to array of section restrictions (optional)
8560: 6. reference to results object (hash of hashes).
8561: 7. reference to optional userdata hash
1.609 raeburn 8562: 8. reference to optional statushash
1.630 raeburn 8563: 9. flag if privileged users (except those set to unhide in
8564: course settings) should be excluded
1.609 raeburn 8565: Keys of top level results hash are roles.
1.275 raeburn 8566: Keys of inner hashes are username:domain, with
8567: values set to access type.
1.288 raeburn 8568: Optional userdata hash returns an array with arguments in the
8569: same order as loncoursedata::get_classlist() for student data.
8570:
1.609 raeburn 8571: Optional statushash returns
8572:
1.288 raeburn 8573: Entries for end, start, section and status are blank because
8574: of the possibility of multiple values for non-student roles.
8575:
1.275 raeburn 8576: =cut
1.405 albertel 8577:
1.275 raeburn 8578: ###############################################
1.405 albertel 8579:
1.275 raeburn 8580: sub get_course_users {
1.630 raeburn 8581: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8582: my %idx = ();
1.419 raeburn 8583: my %seclists;
1.288 raeburn 8584:
8585: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8586: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8587: $idx{end} = &Apache::loncoursedata::CL_END();
8588: $idx{start} = &Apache::loncoursedata::CL_START();
8589: $idx{id} = &Apache::loncoursedata::CL_ID();
8590: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8591: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8592: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8593:
1.290 albertel 8594: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8595: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8596: my $now = time;
1.277 albertel 8597: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8598: my $match = 0;
1.412 raeburn 8599: my $secmatch = 0;
1.419 raeburn 8600: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8601: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8602: if ($section eq '') {
8603: $section = 'none';
8604: }
1.291 albertel 8605: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8606: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8607: $secmatch = 1;
8608: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8609: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8610: $secmatch = 1;
8611: }
8612: } else {
1.419 raeburn 8613: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8614: $secmatch = 1;
8615: }
1.290 albertel 8616: }
1.412 raeburn 8617: if (!$secmatch) {
8618: next;
8619: }
1.419 raeburn 8620: }
1.275 raeburn 8621: if (defined($$types{'active'})) {
1.288 raeburn 8622: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8623: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8624: $match = 1;
1.275 raeburn 8625: }
8626: }
8627: if (defined($$types{'previous'})) {
1.609 raeburn 8628: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8629: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8630: $match = 1;
1.275 raeburn 8631: }
8632: }
8633: if (defined($$types{'future'})) {
1.609 raeburn 8634: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8635: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8636: $match = 1;
1.275 raeburn 8637: }
8638: }
1.609 raeburn 8639: if ($match) {
8640: push(@{$seclists{$student}},$section);
8641: if (ref($userdata) eq 'HASH') {
8642: $$userdata{$student} = $$classlist{$student};
8643: }
8644: if (ref($statushash) eq 'HASH') {
8645: $statushash->{$student}{'st'}{$section} = $status;
8646: }
1.288 raeburn 8647: }
1.275 raeburn 8648: }
8649: }
1.412 raeburn 8650: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8651: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8652: my $now = time;
1.609 raeburn 8653: my %displaystatus = ( previous => 'Expired',
8654: active => 'Active',
8655: future => 'Future',
8656: );
1.1075.2.36 raeburn 8657: my (%nothide,@possdoms);
1.630 raeburn 8658: if ($hidepriv) {
8659: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8660: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8661: if ($user !~ /:/) {
8662: $nothide{join(':',split(/[\@]/,$user))}=1;
8663: } else {
8664: $nothide{$user} = 1;
8665: }
8666: }
1.1075.2.36 raeburn 8667: my @possdoms = ($cdom);
8668: if ($coursehash{'checkforpriv'}) {
8669: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8670: }
1.630 raeburn 8671: }
1.439 raeburn 8672: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8673: my $match = 0;
1.412 raeburn 8674: my $secmatch = 0;
1.439 raeburn 8675: my $status;
1.412 raeburn 8676: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8677: $user =~ s/:$//;
1.439 raeburn 8678: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8679: if ($end == -1 || $start == -1) {
8680: next;
8681: }
8682: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8683: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8684: my ($uname,$udom) = split(/:/,$user);
8685: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8686: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8687: $secmatch = 1;
8688: } elsif ($usec eq '') {
1.420 albertel 8689: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8690: $secmatch = 1;
8691: }
8692: } else {
8693: if (grep(/^\Q$usec\E$/,@{$sections})) {
8694: $secmatch = 1;
8695: }
8696: }
8697: if (!$secmatch) {
8698: next;
8699: }
1.288 raeburn 8700: }
1.419 raeburn 8701: if ($usec eq '') {
8702: $usec = 'none';
8703: }
1.275 raeburn 8704: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8705: if ($hidepriv) {
1.1075.2.36 raeburn 8706: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8707: (!$nothide{$uname.':'.$udom})) {
8708: next;
8709: }
8710: }
1.503 raeburn 8711: if ($end > 0 && $end < $now) {
1.439 raeburn 8712: $status = 'previous';
8713: } elsif ($start > $now) {
8714: $status = 'future';
8715: } else {
8716: $status = 'active';
8717: }
1.277 albertel 8718: foreach my $type (keys(%{$types})) {
1.275 raeburn 8719: if ($status eq $type) {
1.420 albertel 8720: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8721: push(@{$$users{$role}{$user}},$type);
8722: }
1.288 raeburn 8723: $match = 1;
8724: }
8725: }
1.419 raeburn 8726: if (($match) && (ref($userdata) eq 'HASH')) {
8727: if (!exists($$userdata{$uname.':'.$udom})) {
8728: &get_user_info($udom,$uname,\%idx,$userdata);
8729: }
1.420 albertel 8730: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8731: push(@{$seclists{$uname.':'.$udom}},$usec);
8732: }
1.609 raeburn 8733: if (ref($statushash) eq 'HASH') {
8734: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8735: }
1.275 raeburn 8736: }
8737: }
8738: }
8739: }
1.290 albertel 8740: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8741: if ((defined($cdom)) && (defined($cnum))) {
8742: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8743: if ( defined($csettings{'internal.courseowner'}) ) {
8744: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8745: next if ($owner eq '');
8746: my ($ownername,$ownerdom);
8747: if ($owner =~ /^([^:]+):([^:]+)$/) {
8748: $ownername = $1;
8749: $ownerdom = $2;
8750: } else {
8751: $ownername = $owner;
8752: $ownerdom = $cdom;
8753: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8754: }
8755: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8756: if (defined($userdata) &&
1.609 raeburn 8757: !exists($$userdata{$owner})) {
8758: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8759: if (!grep(/^none$/,@{$seclists{$owner}})) {
8760: push(@{$seclists{$owner}},'none');
8761: }
8762: if (ref($statushash) eq 'HASH') {
8763: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8764: }
1.290 albertel 8765: }
1.279 raeburn 8766: }
8767: }
8768: }
1.419 raeburn 8769: foreach my $user (keys(%seclists)) {
8770: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8771: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8772: }
1.275 raeburn 8773: }
8774: return;
8775: }
8776:
1.288 raeburn 8777: sub get_user_info {
8778: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8779: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8780: &plainname($uname,$udom,'lastname');
1.291 albertel 8781: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8782: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8783: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8784: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8785: return;
8786: }
1.275 raeburn 8787:
1.472 raeburn 8788: ###############################################
8789:
8790: =pod
8791:
8792: =item * &get_user_quota()
8793:
1.1075.2.41 raeburn 8794: Retrieves quota assigned for storage of user files.
8795: Default is to report quota for portfolio files.
1.472 raeburn 8796:
8797: Incoming parameters:
8798: 1. user's username
8799: 2. user's domain
1.1075.2.41 raeburn 8800: 3. quota name - portfolio, author, or course
8801: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 8802: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 8803: course
1.472 raeburn 8804:
8805: Returns:
1.1075.2.58 raeburn 8806: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 8807: 2. (Optional) Type of setting: custom or default
8808: (individually assigned or default for user's
8809: institutional status).
8810: 3. (Optional) - User's institutional status (e.g., faculty, staff
8811: or student - types as defined in localenroll::inst_usertypes
8812: for user's domain, which determines default quota for user.
8813: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8814:
8815: If a value has been stored in the user's environment,
1.536 raeburn 8816: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 8817: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8818:
8819: =cut
8820:
8821: ###############################################
8822:
8823:
8824: sub get_user_quota {
1.1075.2.42 raeburn 8825: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8826: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8827: if (!defined($udom)) {
8828: $udom = $env{'user.domain'};
8829: }
8830: if (!defined($uname)) {
8831: $uname = $env{'user.name'};
8832: }
8833: if (($udom eq '' || $uname eq '') ||
8834: ($udom eq 'public') && ($uname eq 'public')) {
8835: $quota = 0;
1.536 raeburn 8836: $quotatype = 'default';
8837: $defquota = 0;
1.472 raeburn 8838: } else {
1.536 raeburn 8839: my $inststatus;
1.1075.2.41 raeburn 8840: if ($quotaname eq 'course') {
8841: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8842: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8843: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8844: } else {
8845: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8846: $quota = $cenv{'internal.uploadquota'};
8847: }
1.536 raeburn 8848: } else {
1.1075.2.41 raeburn 8849: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8850: if ($quotaname eq 'author') {
8851: $quota = $env{'environment.authorquota'};
8852: } else {
8853: $quota = $env{'environment.portfolioquota'};
8854: }
8855: $inststatus = $env{'environment.inststatus'};
8856: } else {
8857: my %userenv =
8858: &Apache::lonnet::get('environment',['portfolioquota',
8859: 'authorquota','inststatus'],$udom,$uname);
8860: my ($tmp) = keys(%userenv);
8861: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8862: if ($quotaname eq 'author') {
8863: $quota = $userenv{'authorquota'};
8864: } else {
8865: $quota = $userenv{'portfolioquota'};
8866: }
8867: $inststatus = $userenv{'inststatus'};
8868: } else {
8869: undef(%userenv);
8870: }
8871: }
8872: }
8873: if ($quota eq '' || wantarray) {
8874: if ($quotaname eq 'course') {
8875: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 8876: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
8877: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 8878: $defquota = $domdefs{$crstype.'quota'};
8879: }
8880: if ($defquota eq '') {
8881: $defquota = 500;
8882: }
1.1075.2.41 raeburn 8883: } else {
8884: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8885: }
8886: if ($quota eq '') {
8887: $quota = $defquota;
8888: $quotatype = 'default';
8889: } else {
8890: $quotatype = 'custom';
8891: }
1.472 raeburn 8892: }
8893: }
1.536 raeburn 8894: if (wantarray) {
8895: return ($quota,$quotatype,$settingstatus,$defquota);
8896: } else {
8897: return $quota;
8898: }
1.472 raeburn 8899: }
8900:
8901: ###############################################
8902:
8903: =pod
8904:
8905: =item * &default_quota()
8906:
1.536 raeburn 8907: Retrieves default quota assigned for storage of user portfolio files,
8908: given an (optional) user's institutional status.
1.472 raeburn 8909:
8910: Incoming parameters:
1.1075.2.42 raeburn 8911:
1.472 raeburn 8912: 1. domain
1.536 raeburn 8913: 2. (Optional) institutional status(es). This is a : separated list of
8914: status types (e.g., faculty, staff, student etc.)
8915: which apply to the user for whom the default is being retrieved.
8916: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 8917: default quota will be returned.
8918: 3. quota name - portfolio, author, or course
8919: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8920:
8921: Returns:
1.1075.2.42 raeburn 8922:
1.1075.2.58 raeburn 8923: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 8924: 2. (Optional) institutional type which determined the value of the
8925: default quota.
1.472 raeburn 8926:
8927: If a value has been stored in the domain's configuration db,
8928: it will return that, otherwise it returns 20 (for backwards
8929: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 8930: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 8931:
1.536 raeburn 8932: If the user's status includes multiple types (e.g., staff and student),
8933: the largest default quota which applies to the user determines the
8934: default quota returned.
8935:
1.472 raeburn 8936: =cut
8937:
8938: ###############################################
8939:
8940:
8941: sub default_quota {
1.1075.2.41 raeburn 8942: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8943: my ($defquota,$settingstatus);
8944: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8945: ['quotas'],$udom);
1.1075.2.41 raeburn 8946: my $key = 'defaultquota';
8947: if ($quotaname eq 'author') {
8948: $key = 'authorquota';
8949: }
1.622 raeburn 8950: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8951: if ($inststatus ne '') {
1.765 raeburn 8952: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8953: foreach my $item (@statuses) {
1.1075.2.41 raeburn 8954: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8955: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8956: if ($defquota eq '') {
1.1075.2.41 raeburn 8957: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8958: $settingstatus = $item;
1.1075.2.41 raeburn 8959: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8960: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8961: $settingstatus = $item;
8962: }
8963: }
1.1075.2.41 raeburn 8964: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8965: if ($quotahash{'quotas'}{$item} ne '') {
8966: if ($defquota eq '') {
8967: $defquota = $quotahash{'quotas'}{$item};
8968: $settingstatus = $item;
8969: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8970: $defquota = $quotahash{'quotas'}{$item};
8971: $settingstatus = $item;
8972: }
1.536 raeburn 8973: }
8974: }
8975: }
8976: }
8977: if ($defquota eq '') {
1.1075.2.41 raeburn 8978: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8979: $defquota = $quotahash{'quotas'}{$key}{'default'};
8980: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8981: $defquota = $quotahash{'quotas'}{'default'};
8982: }
1.536 raeburn 8983: $settingstatus = 'default';
1.1075.2.42 raeburn 8984: if ($defquota eq '') {
8985: if ($quotaname eq 'author') {
8986: $defquota = 500;
8987: }
8988: }
1.536 raeburn 8989: }
8990: } else {
8991: $settingstatus = 'default';
1.1075.2.41 raeburn 8992: if ($quotaname eq 'author') {
8993: $defquota = 500;
8994: } else {
8995: $defquota = 20;
8996: }
1.536 raeburn 8997: }
8998: if (wantarray) {
8999: return ($defquota,$settingstatus);
1.472 raeburn 9000: } else {
1.536 raeburn 9001: return $defquota;
1.472 raeburn 9002: }
9003: }
9004:
1.1075.2.41 raeburn 9005: ###############################################
9006:
9007: =pod
9008:
1.1075.2.42 raeburn 9009: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9010:
9011: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9012: of existing file within authoring space will cause quota for the authoring
9013: space to be exceeded.
9014:
9015: Same, if upload of a file directly to a course/community via Course Editor
9016: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9017:
1.1075.2.61 raeburn 9018: Inputs: 7
1.1075.2.42 raeburn 9019: 1. username or coursenum
1.1075.2.41 raeburn 9020: 2. domain
1.1075.2.42 raeburn 9021: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9022: 4. filename of file for which action is being requested
9023: 5. filesize (kB) of file
9024: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9025: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9026:
9027: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9028: otherwise return null.
9029:
1.1075.2.42 raeburn 9030: =back
9031:
1.1075.2.41 raeburn 9032: =cut
9033:
1.1075.2.42 raeburn 9034: sub excess_filesize_warning {
1.1075.2.59 raeburn 9035: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9036: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9037: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9038: if ($context eq 'author') {
9039: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9040: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9041: } else {
9042: foreach my $subdir ('docs','supplemental') {
9043: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9044: }
9045: }
1.1075.2.41 raeburn 9046: $disk_quota = int($disk_quota * 1000);
9047: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9048: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9049: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9050: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9051: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9052: $disk_quota,$current_disk_usage).
9053: '</p>';
9054: }
9055: return;
9056: }
9057:
9058: ###############################################
9059:
9060:
1.384 raeburn 9061: sub get_secgrprole_info {
9062: my ($cdom,$cnum,$needroles,$type) = @_;
9063: my %sections_count = &get_sections($cdom,$cnum);
9064: my @sections = (sort {$a <=> $b} keys(%sections_count));
9065: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9066: my @groups = sort(keys(%curr_groups));
9067: my $allroles = [];
9068: my $rolehash;
9069: my $accesshash = {
9070: active => 'Currently has access',
9071: future => 'Will have future access',
9072: previous => 'Previously had access',
9073: };
9074: if ($needroles) {
9075: $rolehash = {'all' => 'all'};
1.385 albertel 9076: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9077: if (&Apache::lonnet::error(%user_roles)) {
9078: undef(%user_roles);
9079: }
9080: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9081: my ($role)=split(/\:/,$item,2);
9082: if ($role eq 'cr') { next; }
9083: if ($role =~ /^cr/) {
9084: $$rolehash{$role} = (split('/',$role))[3];
9085: } else {
9086: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9087: }
9088: }
9089: foreach my $key (sort(keys(%{$rolehash}))) {
9090: push(@{$allroles},$key);
9091: }
9092: push (@{$allroles},'st');
9093: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9094: }
9095: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9096: }
9097:
1.555 raeburn 9098: sub user_picker {
1.994 raeburn 9099: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9100: my $currdom = $dom;
9101: my %curr_selected = (
9102: srchin => 'dom',
1.580 raeburn 9103: srchby => 'lastname',
1.555 raeburn 9104: );
9105: my $srchterm;
1.625 raeburn 9106: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9107: if ($srch->{'srchby'} ne '') {
9108: $curr_selected{'srchby'} = $srch->{'srchby'};
9109: }
9110: if ($srch->{'srchin'} ne '') {
9111: $curr_selected{'srchin'} = $srch->{'srchin'};
9112: }
9113: if ($srch->{'srchtype'} ne '') {
9114: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9115: }
9116: if ($srch->{'srchdomain'} ne '') {
9117: $currdom = $srch->{'srchdomain'};
9118: }
9119: $srchterm = $srch->{'srchterm'};
9120: }
9121: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 9122: 'usr' => 'Search criteria',
1.563 raeburn 9123: 'doma' => 'Domain/institution to search',
1.558 albertel 9124: 'uname' => 'username',
9125: 'lastname' => 'last name',
1.555 raeburn 9126: 'lastfirst' => 'last name, first name',
1.558 albertel 9127: 'crs' => 'in this course',
1.576 raeburn 9128: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9129: 'alc' => 'all LON-CAPA',
1.573 raeburn 9130: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9131: 'exact' => 'is',
9132: 'contains' => 'contains',
1.569 raeburn 9133: 'begins' => 'begins with',
1.571 raeburn 9134: 'youm' => "You must include some text to search for.",
9135: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9136: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9137: 'yomc' => "You must choose a domain when using an institutional directory search.",
9138: 'ymcd' => "You must choose a domain when using a domain search.",
9139: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9140: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9141: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9142: );
1.563 raeburn 9143: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9144: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9145:
9146: my @srchins = ('crs','dom','alc','instd');
9147:
9148: foreach my $option (@srchins) {
9149: # FIXME 'alc' option unavailable until
9150: # loncreateuser::print_user_query_page()
9151: # has been completed.
9152: next if ($option eq 'alc');
1.880 raeburn 9153: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9154: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9155: if ($curr_selected{'srchin'} eq $option) {
9156: $srchinsel .= '
9157: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9158: } else {
9159: $srchinsel .= '
9160: <option value="'.$option.'">'.$lt{$option}.'</option>';
9161: }
1.555 raeburn 9162: }
1.563 raeburn 9163: $srchinsel .= "\n </select>\n";
1.555 raeburn 9164:
9165: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9166: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9167: if ($curr_selected{'srchby'} eq $option) {
9168: $srchbysel .= '
9169: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9170: } else {
9171: $srchbysel .= '
9172: <option value="'.$option.'">'.$lt{$option}.'</option>';
9173: }
9174: }
9175: $srchbysel .= "\n </select>\n";
9176:
9177: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9178: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9179: if ($curr_selected{'srchtype'} eq $option) {
9180: $srchtypesel .= '
9181: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9182: } else {
9183: $srchtypesel .= '
9184: <option value="'.$option.'">'.$lt{$option}.'</option>';
9185: }
9186: }
9187: $srchtypesel .= "\n </select>\n";
9188:
1.558 albertel 9189: my ($newuserscript,$new_user_create);
1.994 raeburn 9190: my $context_dom = $env{'request.role.domain'};
9191: if ($context eq 'requestcrs') {
9192: if ($env{'form.coursedom'} ne '') {
9193: $context_dom = $env{'form.coursedom'};
9194: }
9195: }
1.556 raeburn 9196: if ($forcenewuser) {
1.576 raeburn 9197: if (ref($srch) eq 'HASH') {
1.994 raeburn 9198: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9199: if ($cancreate) {
9200: $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>';
9201: } else {
1.799 bisitz 9202: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9203: my %usertypetext = (
9204: official => 'institutional',
9205: unofficial => 'non-institutional',
9206: );
1.799 bisitz 9207: $new_user_create = '<p class="LC_warning">'
9208: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9209: .' '
9210: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9211: ,'<a href="'.$helplink.'">','</a>')
9212: .'</p><br />';
1.627 raeburn 9213: }
1.576 raeburn 9214: }
9215: }
9216:
1.556 raeburn 9217: $newuserscript = <<"ENDSCRIPT";
9218:
1.570 raeburn 9219: function setSearch(createnew,callingForm) {
1.556 raeburn 9220: if (createnew == 1) {
1.570 raeburn 9221: for (var i=0; i<callingForm.srchby.length; i++) {
9222: if (callingForm.srchby.options[i].value == 'uname') {
9223: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9224: }
9225: }
1.570 raeburn 9226: for (var i=0; i<callingForm.srchin.length; i++) {
9227: if ( callingForm.srchin.options[i].value == 'dom') {
9228: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9229: }
9230: }
1.570 raeburn 9231: for (var i=0; i<callingForm.srchtype.length; i++) {
9232: if (callingForm.srchtype.options[i].value == 'exact') {
9233: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9234: }
9235: }
1.570 raeburn 9236: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9237: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9238: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9239: }
9240: }
9241: }
9242: }
9243: ENDSCRIPT
1.558 albertel 9244:
1.556 raeburn 9245: }
9246:
1.555 raeburn 9247: my $output = <<"END_BLOCK";
1.556 raeburn 9248: <script type="text/javascript">
1.824 bisitz 9249: // <![CDATA[
1.570 raeburn 9250: function validateEntry(callingForm) {
1.558 albertel 9251:
1.556 raeburn 9252: var checkok = 1;
1.558 albertel 9253: var srchin;
1.570 raeburn 9254: for (var i=0; i<callingForm.srchin.length; i++) {
9255: if ( callingForm.srchin[i].checked ) {
9256: srchin = callingForm.srchin[i].value;
1.558 albertel 9257: }
9258: }
9259:
1.570 raeburn 9260: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9261: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9262: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9263: var srchterm = callingForm.srchterm.value;
9264: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9265: var msg = "";
9266:
9267: if (srchterm == "") {
9268: checkok = 0;
1.571 raeburn 9269: msg += "$lt{'youm'}\\n";
1.556 raeburn 9270: }
9271:
1.569 raeburn 9272: if (srchtype== 'begins') {
9273: if (srchterm.length < 2) {
9274: checkok = 0;
1.571 raeburn 9275: msg += "$lt{'thte'}\\n";
1.569 raeburn 9276: }
9277: }
9278:
1.556 raeburn 9279: if (srchtype== 'contains') {
9280: if (srchterm.length < 3) {
9281: checkok = 0;
1.571 raeburn 9282: msg += "$lt{'thet'}\\n";
1.556 raeburn 9283: }
9284: }
9285: if (srchin == 'instd') {
9286: if (srchdomain == '') {
9287: checkok = 0;
1.571 raeburn 9288: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9289: }
9290: }
9291: if (srchin == 'dom') {
9292: if (srchdomain == '') {
9293: checkok = 0;
1.571 raeburn 9294: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9295: }
9296: }
9297: if (srchby == 'lastfirst') {
9298: if (srchterm.indexOf(",") == -1) {
9299: checkok = 0;
1.571 raeburn 9300: msg += "$lt{'whus'}\\n";
1.556 raeburn 9301: }
9302: if (srchterm.indexOf(",") == srchterm.length -1) {
9303: checkok = 0;
1.571 raeburn 9304: msg += "$lt{'whse'}\\n";
1.556 raeburn 9305: }
9306: }
9307: if (checkok == 0) {
1.571 raeburn 9308: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9309: return;
9310: }
9311: if (checkok == 1) {
1.570 raeburn 9312: callingForm.submit();
1.556 raeburn 9313: }
9314: }
9315:
9316: $newuserscript
9317:
1.824 bisitz 9318: // ]]>
1.556 raeburn 9319: </script>
1.558 albertel 9320:
9321: $new_user_create
9322:
1.555 raeburn 9323: END_BLOCK
1.558 albertel 9324:
1.876 raeburn 9325: $output .= &Apache::lonhtmlcommon::start_pick_box().
9326: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9327: $domform.
9328: &Apache::lonhtmlcommon::row_closure().
9329: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9330: $srchbysel.
9331: $srchtypesel.
9332: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9333: $srchinsel.
9334: &Apache::lonhtmlcommon::row_closure(1).
9335: &Apache::lonhtmlcommon::end_pick_box().
9336: '<br />';
1.555 raeburn 9337: return $output;
9338: }
9339:
1.612 raeburn 9340: sub user_rule_check {
1.615 raeburn 9341: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9342: my $response;
9343: if (ref($usershash) eq 'HASH') {
9344: foreach my $user (keys(%{$usershash})) {
9345: my ($uname,$udom) = split(/:/,$user);
9346: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9347: my ($id,$newuser);
1.612 raeburn 9348: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9349: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9350: $id = $usershash->{$user}->{'id'};
9351: }
9352: my $inst_response;
9353: if (ref($checks) eq 'HASH') {
9354: if (defined($checks->{'username'})) {
1.615 raeburn 9355: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9356: &Apache::lonnet::get_instuser($udom,$uname);
9357: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9358: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9359: &Apache::lonnet::get_instuser($udom,undef,$id);
9360: }
1.615 raeburn 9361: } else {
9362: ($inst_response,%{$inst_results->{$user}}) =
9363: &Apache::lonnet::get_instuser($udom,$uname);
9364: return;
1.612 raeburn 9365: }
1.615 raeburn 9366: if (!$got_rules->{$udom}) {
1.612 raeburn 9367: my %domconfig = &Apache::lonnet::get_dom('configuration',
9368: ['usercreation'],$udom);
9369: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9370: foreach my $item ('username','id') {
1.612 raeburn 9371: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9372: $$curr_rules{$udom}{$item} =
9373: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9374: }
9375: }
9376: }
1.615 raeburn 9377: $got_rules->{$udom} = 1;
1.585 raeburn 9378: }
1.612 raeburn 9379: foreach my $item (keys(%{$checks})) {
9380: if (ref($$curr_rules{$udom}) eq 'HASH') {
9381: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9382: if (@{$$curr_rules{$udom}{$item}} > 0) {
9383: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9384: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9385: if ($rule_check{$rule}) {
9386: $$rulematch{$user}{$item} = $rule;
9387: if ($inst_response eq 'ok') {
1.615 raeburn 9388: if (ref($inst_results) eq 'HASH') {
9389: if (ref($inst_results->{$user}) eq 'HASH') {
9390: if (keys(%{$inst_results->{$user}}) == 0) {
9391: $$alerts{$item}{$udom}{$uname} = 1;
9392: }
1.612 raeburn 9393: }
9394: }
1.615 raeburn 9395: }
9396: last;
1.585 raeburn 9397: }
9398: }
9399: }
9400: }
9401: }
9402: }
9403: }
9404: }
1.612 raeburn 9405: return;
9406: }
9407:
9408: sub user_rule_formats {
9409: my ($domain,$domdesc,$curr_rules,$check) = @_;
9410: my %text = (
9411: 'username' => 'Usernames',
9412: 'id' => 'IDs',
9413: );
9414: my $output;
9415: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9416: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9417: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 9418: $output = '<br />'.
9419: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9420: '<span class="LC_cusr_emph">','</span>',$domdesc).
9421: ' <ul>';
1.612 raeburn 9422: foreach my $rule (@{$ruleorder}) {
9423: if (ref($curr_rules) eq 'ARRAY') {
9424: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9425: if (ref($rules->{$rule}) eq 'HASH') {
9426: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9427: $rules->{$rule}{'desc'}.'</li>';
9428: }
9429: }
9430: }
9431: }
9432: $output .= '</ul>';
9433: }
9434: }
9435: return $output;
9436: }
9437:
9438: sub instrule_disallow_msg {
1.615 raeburn 9439: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9440: my $response;
9441: my %text = (
9442: item => 'username',
9443: items => 'usernames',
9444: match => 'matches',
9445: do => 'does',
9446: action => 'a username',
9447: one => 'one',
9448: );
9449: if ($count > 1) {
9450: $text{'item'} = 'usernames';
9451: $text{'match'} ='match';
9452: $text{'do'} = 'do';
9453: $text{'action'} = 'usernames',
9454: $text{'one'} = 'ones';
9455: }
9456: if ($checkitem eq 'id') {
9457: $text{'items'} = 'IDs';
9458: $text{'item'} = 'ID';
9459: $text{'action'} = 'an ID';
1.615 raeburn 9460: if ($count > 1) {
9461: $text{'item'} = 'IDs';
9462: $text{'action'} = 'IDs';
9463: }
1.612 raeburn 9464: }
1.674 bisitz 9465: $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 9466: if ($mode eq 'upload') {
9467: if ($checkitem eq 'username') {
9468: $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'}.");
9469: } elsif ($checkitem eq 'id') {
1.674 bisitz 9470: $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 9471: }
1.669 raeburn 9472: } elsif ($mode eq 'selfcreate') {
9473: if ($checkitem eq 'id') {
9474: $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.");
9475: }
1.615 raeburn 9476: } else {
9477: if ($checkitem eq 'username') {
9478: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9479: } elsif ($checkitem eq 'id') {
9480: $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.");
9481: }
1.612 raeburn 9482: }
9483: return $response;
1.585 raeburn 9484: }
9485:
1.624 raeburn 9486: sub personal_data_fieldtitles {
9487: my %fieldtitles = &Apache::lonlocal::texthash (
9488: id => 'Student/Employee ID',
9489: permanentemail => 'E-mail address',
9490: lastname => 'Last Name',
9491: firstname => 'First Name',
9492: middlename => 'Middle Name',
9493: generation => 'Generation',
9494: gen => 'Generation',
1.765 raeburn 9495: inststatus => 'Affiliation',
1.624 raeburn 9496: );
9497: return %fieldtitles;
9498: }
9499:
1.642 raeburn 9500: sub sorted_inst_types {
9501: my ($dom) = @_;
1.1075.2.70 raeburn 9502: my ($usertypes,$order);
9503: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9504: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
9505: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
9506: $order = $domdefaults{'inststatus'}{'inststatusorder'};
9507: } else {
9508: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9509: }
1.642 raeburn 9510: my $othertitle = &mt('All users');
9511: if ($env{'request.course.id'}) {
1.668 raeburn 9512: $othertitle = &mt('Any users');
1.642 raeburn 9513: }
9514: my @types;
9515: if (ref($order) eq 'ARRAY') {
9516: @types = @{$order};
9517: }
9518: if (@types == 0) {
9519: if (ref($usertypes) eq 'HASH') {
9520: @types = sort(keys(%{$usertypes}));
9521: }
9522: }
9523: if (keys(%{$usertypes}) > 0) {
9524: $othertitle = &mt('Other users');
9525: }
9526: return ($othertitle,$usertypes,\@types);
9527: }
9528:
1.645 raeburn 9529: sub get_institutional_codes {
9530: my ($settings,$allcourses,$LC_code) = @_;
9531: # Get complete list of course sections to update
9532: my @currsections = ();
9533: my @currxlists = ();
9534: my $coursecode = $$settings{'internal.coursecode'};
9535:
9536: if ($$settings{'internal.sectionnums'} ne '') {
9537: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9538: }
9539:
9540: if ($$settings{'internal.crosslistings'} ne '') {
9541: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9542: }
9543:
9544: if (@currxlists > 0) {
9545: foreach (@currxlists) {
9546: if (m/^([^:]+):(\w*)$/) {
9547: unless (grep/^$1$/,@{$allcourses}) {
9548: push @{$allcourses},$1;
9549: $$LC_code{$1} = $2;
9550: }
9551: }
9552: }
9553: }
9554:
9555: if (@currsections > 0) {
9556: foreach (@currsections) {
9557: if (m/^(\w+):(\w*)$/) {
9558: my $sec = $coursecode.$1;
9559: my $lc_sec = $2;
9560: unless (grep/^$sec$/,@{$allcourses}) {
9561: push @{$allcourses},$sec;
9562: $$LC_code{$sec} = $lc_sec;
9563: }
9564: }
9565: }
9566: }
9567: return;
9568: }
9569:
1.971 raeburn 9570: sub get_standard_codeitems {
9571: return ('Year','Semester','Department','Number','Section');
9572: }
9573:
1.112 bowersj2 9574: =pod
9575:
1.780 raeburn 9576: =head1 Slot Helpers
9577:
9578: =over 4
9579:
9580: =item * sorted_slots()
9581:
1.1040 raeburn 9582: Sorts an array of slot names in order of an optional sort key,
9583: default sort is by slot start time (earliest first).
1.780 raeburn 9584:
9585: Inputs:
9586:
9587: =over 4
9588:
9589: slotsarr - Reference to array of unsorted slot names.
9590:
9591: slots - Reference to hash of hash, where outer hash keys are slot names.
9592:
1.1040 raeburn 9593: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9594:
1.549 albertel 9595: =back
9596:
1.780 raeburn 9597: Returns:
9598:
9599: =over 4
9600:
1.1040 raeburn 9601: sorted - An array of slot names sorted by a specified sort key
9602: (default sort key is start time of the slot).
1.780 raeburn 9603:
9604: =back
9605:
9606: =cut
9607:
9608:
9609: sub sorted_slots {
1.1040 raeburn 9610: my ($slotsarr,$slots,$sortkey) = @_;
9611: if ($sortkey eq '') {
9612: $sortkey = 'starttime';
9613: }
1.780 raeburn 9614: my @sorted;
9615: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9616: @sorted =
9617: sort {
9618: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9619: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9620: }
9621: if (ref($slots->{$a})) { return -1;}
9622: if (ref($slots->{$b})) { return 1;}
9623: return 0;
9624: } @{$slotsarr};
9625: }
9626: return @sorted;
9627: }
9628:
1.1040 raeburn 9629: =pod
9630:
9631: =item * get_future_slots()
9632:
9633: Inputs:
9634:
9635: =over 4
9636:
9637: cnum - course number
9638:
9639: cdom - course domain
9640:
9641: now - current UNIX time
9642:
9643: symb - optional symb
9644:
9645: =back
9646:
9647: Returns:
9648:
9649: =over 4
9650:
9651: sorted_reservable - ref to array of student_schedulable slots currently
9652: reservable, ordered by end date of reservation period.
9653:
9654: reservable_now - ref to hash of student_schedulable slots currently
9655: reservable.
9656:
9657: Keys in inner hash are:
9658: (a) symb: either blank or symb to which slot use is restricted.
9659: (b) endreserve: end date of reservation period.
9660:
9661: sorted_future - ref to array of student_schedulable slots reservable in
9662: the future, ordered by start date of reservation period.
9663:
9664: future_reservable - ref to hash of student_schedulable slots reservable
9665: in the future.
9666:
9667: Keys in inner hash are:
9668: (a) symb: either blank or symb to which slot use is restricted.
9669: (b) startreserve: start date of reservation period.
9670:
9671: =back
9672:
9673: =cut
9674:
9675: sub get_future_slots {
9676: my ($cnum,$cdom,$now,$symb) = @_;
9677: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9678: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9679: foreach my $slot (keys(%slots)) {
9680: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9681: if ($symb) {
9682: next if (($slots{$slot}->{'symb'} ne '') &&
9683: ($slots{$slot}->{'symb'} ne $symb));
9684: }
9685: if (($slots{$slot}->{'starttime'} > $now) &&
9686: ($slots{$slot}->{'endtime'} > $now)) {
9687: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9688: my $userallowed = 0;
9689: if ($slots{$slot}->{'allowedsections'}) {
9690: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9691: if (!defined($env{'request.role.sec'})
9692: && grep(/^No section assigned$/,@allowed_sec)) {
9693: $userallowed=1;
9694: } else {
9695: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9696: $userallowed=1;
9697: }
9698: }
9699: unless ($userallowed) {
9700: if (defined($env{'request.course.groups'})) {
9701: my @groups = split(/:/,$env{'request.course.groups'});
9702: foreach my $group (@groups) {
9703: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9704: $userallowed=1;
9705: last;
9706: }
9707: }
9708: }
9709: }
9710: }
9711: if ($slots{$slot}->{'allowedusers'}) {
9712: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9713: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9714: if (grep(/^\Q$user\E$/,@allowed_users)) {
9715: $userallowed = 1;
9716: }
9717: }
9718: next unless($userallowed);
9719: }
9720: my $startreserve = $slots{$slot}->{'startreserve'};
9721: my $endreserve = $slots{$slot}->{'endreserve'};
9722: my $symb = $slots{$slot}->{'symb'};
9723: if (($startreserve < $now) &&
9724: (!$endreserve || $endreserve > $now)) {
9725: my $lastres = $endreserve;
9726: if (!$lastres) {
9727: $lastres = $slots{$slot}->{'starttime'};
9728: }
9729: $reservable_now{$slot} = {
9730: symb => $symb,
9731: endreserve => $lastres
9732: };
9733: } elsif (($startreserve > $now) &&
9734: (!$endreserve || $endreserve > $startreserve)) {
9735: $future_reservable{$slot} = {
9736: symb => $symb,
9737: startreserve => $startreserve
9738: };
9739: }
9740: }
9741: }
9742: my @unsorted_reservable = keys(%reservable_now);
9743: if (@unsorted_reservable > 0) {
9744: @sorted_reservable =
9745: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9746: }
9747: my @unsorted_future = keys(%future_reservable);
9748: if (@unsorted_future > 0) {
9749: @sorted_future =
9750: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9751: }
9752: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9753: }
1.780 raeburn 9754:
9755: =pod
9756:
1.1057 foxr 9757: =back
9758:
1.549 albertel 9759: =head1 HTTP Helpers
9760:
9761: =over 4
9762:
1.648 raeburn 9763: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9764:
1.258 albertel 9765: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9766: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9767: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9768:
9769: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9770: $possible_names is an ref to an array of form element names. As an example:
9771: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9772: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9773:
9774: =cut
1.1 albertel 9775:
1.6 albertel 9776: sub get_unprocessed_cgi {
1.25 albertel 9777: my ($query,$possible_names)= @_;
1.26 matthew 9778: # $Apache::lonxml::debug=1;
1.356 albertel 9779: foreach my $pair (split(/&/,$query)) {
9780: my ($name, $value) = split(/=/,$pair);
1.369 www 9781: $name = &unescape($name);
1.25 albertel 9782: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9783: $value =~ tr/+/ /;
9784: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9785: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9786: }
1.16 harris41 9787: }
1.6 albertel 9788: }
9789:
1.112 bowersj2 9790: =pod
9791:
1.648 raeburn 9792: =item * &cacheheader()
1.112 bowersj2 9793:
9794: returns cache-controlling header code
9795:
9796: =cut
9797:
1.7 albertel 9798: sub cacheheader {
1.258 albertel 9799: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9800: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9801: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9802: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9803: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9804: return $output;
1.7 albertel 9805: }
9806:
1.112 bowersj2 9807: =pod
9808:
1.648 raeburn 9809: =item * &no_cache($r)
1.112 bowersj2 9810:
9811: specifies header code to not have cache
9812:
9813: =cut
9814:
1.9 albertel 9815: sub no_cache {
1.216 albertel 9816: my ($r) = @_;
9817: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9818: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9819: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9820: $r->no_cache(1);
9821: $r->header_out("Expires" => $date);
9822: $r->header_out("Pragma" => "no-cache");
1.123 www 9823: }
9824:
9825: sub content_type {
1.181 albertel 9826: my ($r,$type,$charset) = @_;
1.299 foxr 9827: if ($r) {
9828: # Note that printout.pl calls this with undef for $r.
9829: &no_cache($r);
9830: }
1.258 albertel 9831: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9832: unless ($charset) {
9833: $charset=&Apache::lonlocal::current_encoding;
9834: }
9835: if ($charset) { $type.='; charset='.$charset; }
9836: if ($r) {
9837: $r->content_type($type);
9838: } else {
9839: print("Content-type: $type\n\n");
9840: }
1.9 albertel 9841: }
1.25 albertel 9842:
1.112 bowersj2 9843: =pod
9844:
1.648 raeburn 9845: =item * &add_to_env($name,$value)
1.112 bowersj2 9846:
1.258 albertel 9847: adds $name to the %env hash with value
1.112 bowersj2 9848: $value, if $name already exists, the entry is converted to an array
9849: reference and $value is added to the array.
9850:
9851: =cut
9852:
1.25 albertel 9853: sub add_to_env {
9854: my ($name,$value)=@_;
1.258 albertel 9855: if (defined($env{$name})) {
9856: if (ref($env{$name})) {
1.25 albertel 9857: #already have multiple values
1.258 albertel 9858: push(@{ $env{$name} },$value);
1.25 albertel 9859: } else {
9860: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9861: my $first=$env{$name};
9862: undef($env{$name});
9863: push(@{ $env{$name} },$first,$value);
1.25 albertel 9864: }
9865: } else {
1.258 albertel 9866: $env{$name}=$value;
1.25 albertel 9867: }
1.31 albertel 9868: }
1.149 albertel 9869:
9870: =pod
9871:
1.648 raeburn 9872: =item * &get_env_multiple($name)
1.149 albertel 9873:
1.258 albertel 9874: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9875: values may be defined and end up as an array ref.
9876:
9877: returns an array of values
9878:
9879: =cut
9880:
9881: sub get_env_multiple {
9882: my ($name) = @_;
9883: my @values;
1.258 albertel 9884: if (defined($env{$name})) {
1.149 albertel 9885: # exists is it an array
1.258 albertel 9886: if (ref($env{$name})) {
9887: @values=@{ $env{$name} };
1.149 albertel 9888: } else {
1.258 albertel 9889: $values[0]=$env{$name};
1.149 albertel 9890: }
9891: }
9892: return(@values);
9893: }
9894:
1.660 raeburn 9895: sub ask_for_embedded_content {
9896: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9897: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 9898: %currsubfile,%unused,$rem);
1.1071 raeburn 9899: my $counter = 0;
9900: my $numnew = 0;
1.987 raeburn 9901: my $numremref = 0;
9902: my $numinvalid = 0;
9903: my $numpathchg = 0;
9904: my $numexisting = 0;
1.1071 raeburn 9905: my $numunused = 0;
9906: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 9907: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 9908: my $heading = &mt('Upload embedded files');
9909: my $buttontext = &mt('Upload');
9910:
1.1075.2.11 raeburn 9911: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 9912: if ($actionurl eq '/adm/dependencies') {
9913: $navmap = Apache::lonnavmaps::navmap->new();
9914: }
9915: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9916: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 9917: }
1.1075.2.35 raeburn 9918: if (($actionurl eq '/adm/portfolio') ||
9919: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9920: my $current_path='/';
9921: if ($env{'form.currentpath'}) {
9922: $current_path = $env{'form.currentpath'};
9923: }
9924: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 9925: $udom = $cdom;
9926: $uname = $cnum;
1.984 raeburn 9927: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9928: } else {
9929: $udom = $env{'user.domain'};
9930: $uname = $env{'user.name'};
9931: $url = '/userfiles/portfolio';
9932: }
1.987 raeburn 9933: $toplevel = $url.'/';
1.984 raeburn 9934: $url .= $current_path;
9935: $getpropath = 1;
1.987 raeburn 9936: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9937: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9938: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9939: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9940: $toplevel = $url;
1.984 raeburn 9941: if ($rest ne '') {
1.987 raeburn 9942: $url .= $rest;
9943: }
9944: } elsif ($actionurl eq '/adm/coursedocs') {
9945: if (ref($args) eq 'HASH') {
1.1071 raeburn 9946: $url = $args->{'docs_url'};
9947: $toplevel = $url;
1.1075.2.11 raeburn 9948: if ($args->{'context'} eq 'paste') {
9949: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9950: ($path) =
9951: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9952: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9953: $fileloc =~ s{^/}{};
9954: }
1.1071 raeburn 9955: }
9956: } elsif ($actionurl eq '/adm/dependencies') {
9957: if ($env{'request.course.id'} ne '') {
9958: if (ref($args) eq 'HASH') {
9959: $url = $args->{'docs_url'};
9960: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 9961: $toplevel = $url;
9962: unless ($toplevel =~ m{^/}) {
9963: $toplevel = "/$url";
9964: }
1.1075.2.11 raeburn 9965: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 9966: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9967: $path = $1;
9968: } else {
9969: ($path) =
9970: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9971: }
1.1075.2.79 raeburn 9972: if ($toplevel=~/^\/*(uploaded|editupload)/) {
9973: $fileloc = $toplevel;
9974: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
9975: my ($udom,$uname,$fname) =
9976: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
9977: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
9978: } else {
9979: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9980: }
1.1071 raeburn 9981: $fileloc =~ s{^/}{};
9982: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9983: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9984: }
1.987 raeburn 9985: }
1.1075.2.35 raeburn 9986: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9987: $udom = $cdom;
9988: $uname = $cnum;
9989: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9990: $toplevel = $url;
9991: $path = $url;
9992: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9993: $fileloc =~ s{^/}{};
9994: }
9995: foreach my $file (keys(%{$allfiles})) {
9996: my $embed_file;
9997: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9998: $embed_file = $1;
9999: } else {
10000: $embed_file = $file;
10001: }
1.1075.2.55 raeburn 10002: my ($absolutepath,$cleaned_file);
10003: if ($embed_file =~ m{^\w+://}) {
10004: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10005: $newfiles{$cleaned_file} = 1;
10006: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10007: } else {
1.1075.2.55 raeburn 10008: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10009: if ($embed_file =~ m{^/}) {
10010: $absolutepath = $embed_file;
10011: }
1.1075.2.47 raeburn 10012: if ($cleaned_file =~ m{/}) {
10013: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10014: $path = &check_for_traversal($path,$url,$toplevel);
10015: my $item = $fname;
10016: if ($path ne '') {
10017: $item = $path.'/'.$fname;
10018: $subdependencies{$path}{$fname} = 1;
10019: } else {
10020: $dependencies{$item} = 1;
10021: }
10022: if ($absolutepath) {
10023: $mapping{$item} = $absolutepath;
10024: } else {
10025: $mapping{$item} = $embed_file;
10026: }
10027: } else {
10028: $dependencies{$embed_file} = 1;
10029: if ($absolutepath) {
1.1075.2.47 raeburn 10030: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10031: } else {
1.1075.2.47 raeburn 10032: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10033: }
10034: }
1.984 raeburn 10035: }
10036: }
1.1071 raeburn 10037: my $dirptr = 16384;
1.984 raeburn 10038: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10039: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10040: if (($actionurl eq '/adm/portfolio') ||
10041: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10042: my ($sublistref,$listerror) =
10043: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10044: if (ref($sublistref) eq 'ARRAY') {
10045: foreach my $line (@{$sublistref}) {
10046: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10047: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10048: }
1.984 raeburn 10049: }
1.987 raeburn 10050: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10051: if (opendir(my $dir,$url.'/'.$path)) {
10052: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10053: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10054: }
1.1075.2.11 raeburn 10055: } elsif (($actionurl eq '/adm/dependencies') ||
10056: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10057: ($args->{'context'} eq 'paste')) ||
10058: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10059: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10060: my $dir;
10061: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10062: $dir = $fileloc;
10063: } else {
10064: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10065: }
1.1071 raeburn 10066: if ($dir ne '') {
10067: my ($sublistref,$listerror) =
10068: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10069: if (ref($sublistref) eq 'ARRAY') {
10070: foreach my $line (@{$sublistref}) {
10071: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10072: undef,$mtime)=split(/\&/,$line,12);
10073: unless (($testdir&$dirptr) ||
10074: ($file_name =~ /^\.\.?$/)) {
10075: $currsubfile{$path}{$file_name} = [$size,$mtime];
10076: }
10077: }
10078: }
10079: }
1.984 raeburn 10080: }
10081: }
10082: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10083: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10084: my $item = $path.'/'.$file;
10085: unless ($mapping{$item} eq $item) {
10086: $pathchanges{$item} = 1;
10087: }
10088: $existing{$item} = 1;
10089: $numexisting ++;
10090: } else {
10091: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10092: }
10093: }
1.1071 raeburn 10094: if ($actionurl eq '/adm/dependencies') {
10095: foreach my $path (keys(%currsubfile)) {
10096: if (ref($currsubfile{$path}) eq 'HASH') {
10097: foreach my $file (keys(%{$currsubfile{$path}})) {
10098: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10099: next if (($rem ne '') &&
10100: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10101: (ref($navmap) &&
10102: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10103: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10104: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10105: $unused{$path.'/'.$file} = 1;
10106: }
10107: }
10108: }
10109: }
10110: }
1.984 raeburn 10111: }
1.987 raeburn 10112: my %currfile;
1.1075.2.35 raeburn 10113: if (($actionurl eq '/adm/portfolio') ||
10114: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10115: my ($dirlistref,$listerror) =
10116: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10117: if (ref($dirlistref) eq 'ARRAY') {
10118: foreach my $line (@{$dirlistref}) {
10119: my ($file_name,$rest) = split(/\&/,$line,2);
10120: $currfile{$file_name} = 1;
10121: }
1.984 raeburn 10122: }
1.987 raeburn 10123: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10124: if (opendir(my $dir,$url)) {
1.987 raeburn 10125: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10126: map {$currfile{$_} = 1;} @dir_list;
10127: }
1.1075.2.11 raeburn 10128: } elsif (($actionurl eq '/adm/dependencies') ||
10129: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10130: ($args->{'context'} eq 'paste')) ||
10131: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10132: if ($env{'request.course.id'} ne '') {
10133: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10134: if ($dir ne '') {
10135: my ($dirlistref,$listerror) =
10136: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10137: if (ref($dirlistref) eq 'ARRAY') {
10138: foreach my $line (@{$dirlistref}) {
10139: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10140: $size,undef,$mtime)=split(/\&/,$line,12);
10141: unless (($testdir&$dirptr) ||
10142: ($file_name =~ /^\.\.?$/)) {
10143: $currfile{$file_name} = [$size,$mtime];
10144: }
10145: }
10146: }
10147: }
10148: }
1.984 raeburn 10149: }
10150: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10151: if (exists($currfile{$file})) {
1.987 raeburn 10152: unless ($mapping{$file} eq $file) {
10153: $pathchanges{$file} = 1;
10154: }
10155: $existing{$file} = 1;
10156: $numexisting ++;
10157: } else {
1.984 raeburn 10158: $newfiles{$file} = 1;
10159: }
10160: }
1.1071 raeburn 10161: foreach my $file (keys(%currfile)) {
10162: unless (($file eq $filename) ||
10163: ($file eq $filename.'.bak') ||
10164: ($dependencies{$file})) {
1.1075.2.11 raeburn 10165: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10166: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10167: next if (($rem ne '') &&
10168: (($env{"httpref.$rem".$file} ne '') ||
10169: (ref($navmap) &&
10170: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10171: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10172: ($navmap->getResourceByUrl($rem.$1)))))));
10173: }
1.1075.2.11 raeburn 10174: }
1.1071 raeburn 10175: $unused{$file} = 1;
10176: }
10177: }
1.1075.2.11 raeburn 10178: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10179: ($args->{'context'} eq 'paste')) {
10180: $counter = scalar(keys(%existing));
10181: $numpathchg = scalar(keys(%pathchanges));
10182: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10183: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10184: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10185: $counter = scalar(keys(%existing));
10186: $numpathchg = scalar(keys(%pathchanges));
10187: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10188: }
1.984 raeburn 10189: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10190: if ($actionurl eq '/adm/dependencies') {
10191: next if ($embed_file =~ m{^\w+://});
10192: }
1.660 raeburn 10193: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10194: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10195: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10196: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10197: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10198: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10199: }
1.1075.2.35 raeburn 10200: $upload_output .= '</td>';
1.1071 raeburn 10201: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10202: $upload_output.='<td align="right">'.
10203: '<span class="LC_info LC_fontsize_medium">'.
10204: &mt("URL points to web address").'</span>';
1.987 raeburn 10205: $numremref++;
1.660 raeburn 10206: } elsif ($args->{'error_on_invalid_names'}
10207: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10208: $upload_output.='<td align="right"><span class="LC_warning">'.
10209: &mt('Invalid characters').'</span>';
1.987 raeburn 10210: $numinvalid++;
1.660 raeburn 10211: } else {
1.1075.2.35 raeburn 10212: $upload_output .= '<td>'.
10213: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10214: $embed_file,\%mapping,
1.1071 raeburn 10215: $allfiles,$codebase,'upload');
10216: $counter ++;
10217: $numnew ++;
1.987 raeburn 10218: }
10219: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10220: }
10221: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10222: if ($actionurl eq '/adm/dependencies') {
10223: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10224: $modify_output .= &start_data_table_row().
10225: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10226: '<img src="'.&icon($embed_file).'" border="0" />'.
10227: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10228: '<td>'.$size.'</td>'.
10229: '<td>'.$mtime.'</td>'.
10230: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10231: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10232: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10233: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10234: &embedded_file_element('upload_embedded',$counter,
10235: $embed_file,\%mapping,
10236: $allfiles,$codebase,'modify').
10237: '</div></td>'.
10238: &end_data_table_row()."\n";
10239: $counter ++;
10240: } else {
10241: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10242: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10243: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10244: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10245: &Apache::loncommon::end_data_table_row()."\n";
10246: }
10247: }
10248: my $delidx = $counter;
10249: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10250: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10251: $delete_output .= &start_data_table_row().
10252: '<td><img src="'.&icon($oldfile).'" />'.
10253: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10254: '<td>'.$size.'</td>'.
10255: '<td>'.$mtime.'</td>'.
10256: '<td><label><input type="checkbox" name="del_upload_dep" '.
10257: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10258: &embedded_file_element('upload_embedded',$delidx,
10259: $oldfile,\%mapping,$allfiles,
10260: $codebase,'delete').'</td>'.
10261: &end_data_table_row()."\n";
10262: $numunused ++;
10263: $delidx ++;
1.987 raeburn 10264: }
10265: if ($upload_output) {
10266: $upload_output = &start_data_table().
10267: $upload_output.
10268: &end_data_table()."\n";
10269: }
1.1071 raeburn 10270: if ($modify_output) {
10271: $modify_output = &start_data_table().
10272: &start_data_table_header_row().
10273: '<th>'.&mt('File').'</th>'.
10274: '<th>'.&mt('Size (KB)').'</th>'.
10275: '<th>'.&mt('Modified').'</th>'.
10276: '<th>'.&mt('Upload replacement?').'</th>'.
10277: &end_data_table_header_row().
10278: $modify_output.
10279: &end_data_table()."\n";
10280: }
10281: if ($delete_output) {
10282: $delete_output = &start_data_table().
10283: &start_data_table_header_row().
10284: '<th>'.&mt('File').'</th>'.
10285: '<th>'.&mt('Size (KB)').'</th>'.
10286: '<th>'.&mt('Modified').'</th>'.
10287: '<th>'.&mt('Delete?').'</th>'.
10288: &end_data_table_header_row().
10289: $delete_output.
10290: &end_data_table()."\n";
10291: }
1.987 raeburn 10292: my $applies = 0;
10293: if ($numremref) {
10294: $applies ++;
10295: }
10296: if ($numinvalid) {
10297: $applies ++;
10298: }
10299: if ($numexisting) {
10300: $applies ++;
10301: }
1.1071 raeburn 10302: if ($counter || $numunused) {
1.987 raeburn 10303: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10304: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10305: $state.'<h3>'.$heading.'</h3>';
10306: if ($actionurl eq '/adm/dependencies') {
10307: if ($numnew) {
10308: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10309: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10310: $upload_output.'<br />'."\n";
10311: }
10312: if ($numexisting) {
10313: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10314: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10315: $modify_output.'<br />'."\n";
10316: $buttontext = &mt('Save changes');
10317: }
10318: if ($numunused) {
10319: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10320: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10321: $delete_output.'<br />'."\n";
10322: $buttontext = &mt('Save changes');
10323: }
10324: } else {
10325: $output .= $upload_output.'<br />'."\n";
10326: }
10327: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10328: $counter.'" />'."\n";
10329: if ($actionurl eq '/adm/dependencies') {
10330: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10331: $numnew.'" />'."\n";
10332: } elsif ($actionurl eq '') {
1.987 raeburn 10333: $output .= '<input type="hidden" name="phase" value="three" />';
10334: }
10335: } elsif ($applies) {
10336: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10337: if ($applies > 1) {
10338: $output .=
1.1075.2.35 raeburn 10339: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10340: if ($numremref) {
10341: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10342: }
10343: if ($numinvalid) {
10344: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10345: }
10346: if ($numexisting) {
10347: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10348: }
10349: $output .= '</ul><br />';
10350: } elsif ($numremref) {
10351: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10352: } elsif ($numinvalid) {
10353: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10354: } elsif ($numexisting) {
10355: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10356: }
10357: $output .= $upload_output.'<br />';
10358: }
10359: my ($pathchange_output,$chgcount);
1.1071 raeburn 10360: $chgcount = $counter;
1.987 raeburn 10361: if (keys(%pathchanges) > 0) {
10362: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10363: if ($counter) {
1.987 raeburn 10364: $output .= &embedded_file_element('pathchange',$chgcount,
10365: $embed_file,\%mapping,
1.1071 raeburn 10366: $allfiles,$codebase,'change');
1.987 raeburn 10367: } else {
10368: $pathchange_output .=
10369: &start_data_table_row().
10370: '<td><input type ="checkbox" name="namechange" value="'.
10371: $chgcount.'" checked="checked" /></td>'.
10372: '<td>'.$mapping{$embed_file}.'</td>'.
10373: '<td>'.$embed_file.
10374: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10375: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10376: '</td>'.&end_data_table_row();
1.660 raeburn 10377: }
1.987 raeburn 10378: $numpathchg ++;
10379: $chgcount ++;
1.660 raeburn 10380: }
10381: }
1.1075.2.35 raeburn 10382: if (($counter) || ($numunused)) {
1.987 raeburn 10383: if ($numpathchg) {
10384: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10385: $numpathchg.'" />'."\n";
10386: }
10387: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10388: ($actionurl eq '/adm/imsimport')) {
10389: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10390: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10391: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10392: } elsif ($actionurl eq '/adm/dependencies') {
10393: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10394: }
1.1075.2.35 raeburn 10395: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10396: } elsif ($numpathchg) {
10397: my %pathchange = ();
10398: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10399: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10400: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 10401: }
1.987 raeburn 10402: }
1.1071 raeburn 10403: return ($output,$counter,$numpathchg);
1.987 raeburn 10404: }
10405:
1.1075.2.47 raeburn 10406: =pod
10407:
10408: =item * clean_path($name)
10409:
10410: Performs clean-up of directories, subdirectories and filename in an
10411: embedded object, referenced in an HTML file which is being uploaded
10412: to a course or portfolio, where
10413: "Upload embedded images/multimedia files if HTML file" checkbox was
10414: checked.
10415:
10416: Clean-up is similar to replacements in lonnet::clean_filename()
10417: except each / between sub-directory and next level is preserved.
10418:
10419: =cut
10420:
10421: sub clean_path {
10422: my ($embed_file) = @_;
10423: $embed_file =~s{^/+}{};
10424: my @contents;
10425: if ($embed_file =~ m{/}) {
10426: @contents = split(/\//,$embed_file);
10427: } else {
10428: @contents = ($embed_file);
10429: }
10430: my $lastidx = scalar(@contents)-1;
10431: for (my $i=0; $i<=$lastidx; $i++) {
10432: $contents[$i]=~s{\\}{/}g;
10433: $contents[$i]=~s/\s+/\_/g;
10434: $contents[$i]=~s{[^/\w\.\-]}{}g;
10435: if ($i == $lastidx) {
10436: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10437: }
10438: }
10439: if ($lastidx > 0) {
10440: return join('/',@contents);
10441: } else {
10442: return $contents[0];
10443: }
10444: }
10445:
1.987 raeburn 10446: sub embedded_file_element {
1.1071 raeburn 10447: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10448: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10449: (ref($codebase) eq 'HASH'));
10450: my $output;
1.1071 raeburn 10451: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10452: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10453: }
10454: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10455: &escape($embed_file).'" />';
10456: unless (($context eq 'upload_embedded') &&
10457: ($mapping->{$embed_file} eq $embed_file)) {
10458: $output .='
10459: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10460: }
10461: my $attrib;
10462: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10463: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10464: }
10465: $output .=
10466: "\n\t\t".
10467: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10468: $attrib.'" />';
10469: if (exists($codebase->{$mapping->{$embed_file}})) {
10470: $output .=
10471: "\n\t\t".
10472: '<input name="codebase_'.$num.'" type="hidden" value="'.
10473: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10474: }
1.987 raeburn 10475: return $output;
1.660 raeburn 10476: }
10477:
1.1071 raeburn 10478: sub get_dependency_details {
10479: my ($currfile,$currsubfile,$embed_file) = @_;
10480: my ($size,$mtime,$showsize,$showmtime);
10481: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10482: if ($embed_file =~ m{/}) {
10483: my ($path,$fname) = split(/\//,$embed_file);
10484: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10485: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10486: }
10487: } else {
10488: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10489: ($size,$mtime) = @{$currfile->{$embed_file}};
10490: }
10491: }
10492: $showsize = $size/1024.0;
10493: $showsize = sprintf("%.1f",$showsize);
10494: if ($mtime > 0) {
10495: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10496: }
10497: }
10498: return ($showsize,$showmtime);
10499: }
10500:
10501: sub ask_embedded_js {
10502: return <<"END";
10503: <script type="text/javascript"">
10504: // <![CDATA[
10505: function toggleBrowse(counter) {
10506: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10507: var fileid = document.getElementById('embedded_item_'+counter);
10508: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10509: if (chkboxid.checked == true) {
10510: uploaddivid.style.display='block';
10511: } else {
10512: uploaddivid.style.display='none';
10513: fileid.value = '';
10514: }
10515: }
10516: // ]]>
10517: </script>
10518:
10519: END
10520: }
10521:
1.661 raeburn 10522: sub upload_embedded {
10523: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10524: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10525: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10526: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10527: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10528: my $orig_uploaded_filename =
10529: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10530: foreach my $type ('orig','ref','attrib','codebase') {
10531: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10532: $env{'form.embedded_'.$type.'_'.$i} =
10533: &unescape($env{'form.embedded_'.$type.'_'.$i});
10534: }
10535: }
1.661 raeburn 10536: my ($path,$fname) =
10537: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10538: # no path, whole string is fname
10539: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10540: $fname = &Apache::lonnet::clean_filename($fname);
10541: # See if there is anything left
10542: next if ($fname eq '');
10543:
10544: # Check if file already exists as a file or directory.
10545: my ($state,$msg);
10546: if ($context eq 'portfolio') {
10547: my $port_path = $dirpath;
10548: if ($group ne '') {
10549: $port_path = "groups/$group/$port_path";
10550: }
1.987 raeburn 10551: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10552: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10553: $dir_root,$port_path,$disk_quota,
10554: $current_disk_usage,$uname,$udom);
10555: if ($state eq 'will_exceed_quota'
1.984 raeburn 10556: || $state eq 'file_locked') {
1.661 raeburn 10557: $output .= $msg;
10558: next;
10559: }
10560: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10561: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10562: if ($state eq 'exists') {
10563: $output .= $msg;
10564: next;
10565: }
10566: }
10567: # Check if extension is valid
10568: if (($fname =~ /\.(\w+)$/) &&
10569: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 10570: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10571: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10572: next;
10573: } elsif (($fname =~ /\.(\w+)$/) &&
10574: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10575: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10576: next;
10577: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 10578: $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 10579: next;
10580: }
10581: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 10582: my $subdir = $path;
10583: $subdir =~ s{/+$}{};
1.661 raeburn 10584: if ($context eq 'portfolio') {
1.984 raeburn 10585: my $result;
10586: if ($state eq 'existingfile') {
10587: $result=
10588: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 10589: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10590: } else {
1.984 raeburn 10591: $result=
10592: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10593: $dirpath.
1.1075.2.35 raeburn 10594: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10595: if ($result !~ m|^/uploaded/|) {
10596: $output .= '<span class="LC_error">'
10597: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10598: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10599: .'</span><br />';
10600: next;
10601: } else {
1.987 raeburn 10602: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10603: $path.$fname.'</span>').'<br />';
1.984 raeburn 10604: }
1.661 raeburn 10605: }
1.1075.2.35 raeburn 10606: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
10607: my $extendedsubdir = $dirpath.'/'.$subdir;
10608: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10609: my $result =
1.1075.2.35 raeburn 10610: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10611: if ($result !~ m|^/uploaded/|) {
10612: $output .= '<span class="LC_error">'
10613: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10614: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10615: .'</span><br />';
10616: next;
10617: } else {
10618: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10619: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 10620: if ($context eq 'syllabus') {
10621: &Apache::lonnet::make_public_indefinitely($result);
10622: }
1.987 raeburn 10623: }
1.661 raeburn 10624: } else {
10625: # Save the file
10626: my $target = $env{'form.embedded_item_'.$i};
10627: my $fullpath = $dir_root.$dirpath.'/'.$path;
10628: my $dest = $fullpath.$fname;
10629: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10630: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10631: my $count;
10632: my $filepath = $dir_root;
1.1027 raeburn 10633: foreach my $subdir (@parts) {
10634: $filepath .= "/$subdir";
10635: if (!-e $filepath) {
1.661 raeburn 10636: mkdir($filepath,0770);
10637: }
10638: }
10639: my $fh;
10640: if (!open($fh,'>'.$dest)) {
10641: &Apache::lonnet::logthis('Failed to create '.$dest);
10642: $output .= '<span class="LC_error">'.
1.1071 raeburn 10643: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10644: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10645: '</span><br />';
10646: } else {
10647: if (!print $fh $env{'form.embedded_item_'.$i}) {
10648: &Apache::lonnet::logthis('Failed to write to '.$dest);
10649: $output .= '<span class="LC_error">'.
1.1071 raeburn 10650: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10651: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10652: '</span><br />';
10653: } else {
1.987 raeburn 10654: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10655: $url.'</span>').'<br />';
10656: unless ($context eq 'testbank') {
10657: $footer .= &mt('View embedded file: [_1]',
10658: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10659: }
10660: }
10661: close($fh);
10662: }
10663: }
10664: if ($env{'form.embedded_ref_'.$i}) {
10665: $pathchange{$i} = 1;
10666: }
10667: }
10668: if ($output) {
10669: $output = '<p>'.$output.'</p>';
10670: }
10671: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10672: $returnflag = 'ok';
1.1071 raeburn 10673: my $numpathchgs = scalar(keys(%pathchange));
10674: if ($numpathchgs > 0) {
1.987 raeburn 10675: if ($context eq 'portfolio') {
10676: $output .= '<p>'.&mt('or').'</p>';
10677: } elsif ($context eq 'testbank') {
1.1071 raeburn 10678: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10679: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10680: $returnflag = 'modify_orightml';
10681: }
10682: }
1.1071 raeburn 10683: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10684: }
10685:
10686: sub modify_html_form {
10687: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10688: my $end = 0;
10689: my $modifyform;
10690: if ($context eq 'upload_embedded') {
10691: return unless (ref($pathchange) eq 'HASH');
10692: if ($env{'form.number_embedded_items'}) {
10693: $end += $env{'form.number_embedded_items'};
10694: }
10695: if ($env{'form.number_pathchange_items'}) {
10696: $end += $env{'form.number_pathchange_items'};
10697: }
10698: if ($end) {
10699: for (my $i=0; $i<$end; $i++) {
10700: if ($i < $env{'form.number_embedded_items'}) {
10701: next unless($pathchange->{$i});
10702: }
10703: $modifyform .=
10704: &start_data_table_row().
10705: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10706: 'checked="checked" /></td>'.
10707: '<td>'.$env{'form.embedded_ref_'.$i}.
10708: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10709: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10710: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10711: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10712: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10713: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10714: '<td>'.$env{'form.embedded_orig_'.$i}.
10715: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10716: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10717: &end_data_table_row();
1.1071 raeburn 10718: }
1.987 raeburn 10719: }
10720: } else {
10721: $modifyform = $pathchgtable;
10722: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10723: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10724: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10725: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10726: }
10727: }
10728: if ($modifyform) {
1.1071 raeburn 10729: if ($actionurl eq '/adm/dependencies') {
10730: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10731: }
1.987 raeburn 10732: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10733: '<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".
10734: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10735: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10736: '</ol></p>'."\n".'<p>'.
10737: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10738: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10739: &start_data_table()."\n".
10740: &start_data_table_header_row().
10741: '<th>'.&mt('Change?').'</th>'.
10742: '<th>'.&mt('Current reference').'</th>'.
10743: '<th>'.&mt('Required reference').'</th>'.
10744: &end_data_table_header_row()."\n".
10745: $modifyform.
10746: &end_data_table().'<br />'."\n".$hiddenstate.
10747: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10748: '</form>'."\n";
10749: }
10750: return;
10751: }
10752:
10753: sub modify_html_refs {
1.1075.2.35 raeburn 10754: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10755: my $container;
10756: if ($context eq 'portfolio') {
10757: $container = $env{'form.container'};
10758: } elsif ($context eq 'coursedoc') {
10759: $container = $env{'form.primaryurl'};
1.1071 raeburn 10760: } elsif ($context eq 'manage_dependencies') {
10761: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10762: $container = "/$container";
1.1075.2.35 raeburn 10763: } elsif ($context eq 'syllabus') {
10764: $container = $url;
1.987 raeburn 10765: } else {
1.1027 raeburn 10766: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10767: }
10768: my (%allfiles,%codebase,$output,$content);
10769: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 10770: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10771: if (wantarray) {
10772: return ('',0,0);
10773: } else {
10774: return;
10775: }
10776: }
10777: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10778: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10779: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10780: if (wantarray) {
10781: return ('',0,0);
10782: } else {
10783: return;
10784: }
10785: }
1.987 raeburn 10786: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10787: if ($content eq '-1') {
10788: if (wantarray) {
10789: return ('',0,0);
10790: } else {
10791: return;
10792: }
10793: }
1.987 raeburn 10794: } else {
1.1071 raeburn 10795: unless ($container =~ /^\Q$dir_root\E/) {
10796: if (wantarray) {
10797: return ('',0,0);
10798: } else {
10799: return;
10800: }
10801: }
1.987 raeburn 10802: if (open(my $fh,"<$container")) {
10803: $content = join('', <$fh>);
10804: close($fh);
10805: } else {
1.1071 raeburn 10806: if (wantarray) {
10807: return ('',0,0);
10808: } else {
10809: return;
10810: }
1.987 raeburn 10811: }
10812: }
10813: my ($count,$codebasecount) = (0,0);
10814: my $mm = new File::MMagic;
10815: my $mime_type = $mm->checktype_contents($content);
10816: if ($mime_type eq 'text/html') {
10817: my $parse_result =
10818: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10819: \%codebase,\$content);
10820: if ($parse_result eq 'ok') {
10821: foreach my $i (@changes) {
10822: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10823: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10824: if ($allfiles{$ref}) {
10825: my $newname = $orig;
10826: my ($attrib_regexp,$codebase);
1.1006 raeburn 10827: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10828: if ($attrib_regexp =~ /:/) {
10829: $attrib_regexp =~ s/\:/|/g;
10830: }
10831: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10832: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10833: $count += $numchg;
1.1075.2.35 raeburn 10834: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 10835: delete($allfiles{$ref});
1.987 raeburn 10836: }
10837: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10838: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10839: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10840: $codebasecount ++;
10841: }
10842: }
10843: }
1.1075.2.35 raeburn 10844: my $skiprewrites;
1.987 raeburn 10845: if ($count || $codebasecount) {
10846: my $saveresult;
1.1071 raeburn 10847: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10848: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10849: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10850: if ($url eq $container) {
10851: my ($fname) = ($container =~ m{/([^/]+)$});
10852: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10853: $count,'<span class="LC_filename">'.
1.1071 raeburn 10854: $fname.'</span>').'</p>';
1.987 raeburn 10855: } else {
10856: $output = '<p class="LC_error">'.
10857: &mt('Error: update failed for: [_1].',
10858: '<span class="LC_filename">'.
10859: $container.'</span>').'</p>';
10860: }
1.1075.2.35 raeburn 10861: if ($context eq 'syllabus') {
10862: unless ($saveresult eq 'ok') {
10863: $skiprewrites = 1;
10864: }
10865: }
1.987 raeburn 10866: } else {
10867: if (open(my $fh,">$container")) {
10868: print $fh $content;
10869: close($fh);
10870: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10871: $count,'<span class="LC_filename">'.
10872: $container.'</span>').'</p>';
1.661 raeburn 10873: } else {
1.987 raeburn 10874: $output = '<p class="LC_error">'.
10875: &mt('Error: could not update [_1].',
10876: '<span class="LC_filename">'.
10877: $container.'</span>').'</p>';
1.661 raeburn 10878: }
10879: }
10880: }
1.1075.2.35 raeburn 10881: if (($context eq 'syllabus') && (!$skiprewrites)) {
10882: my ($actionurl,$state);
10883: $actionurl = "/public/$udom/$uname/syllabus";
10884: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10885: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10886: \%codebase,
10887: {'context' => 'rewrites',
10888: 'ignore_remote_references' => 1,});
10889: if (ref($mapping) eq 'HASH') {
10890: my $rewrites = 0;
10891: foreach my $key (keys(%{$mapping})) {
10892: next if ($key =~ m{^https?://});
10893: my $ref = $mapping->{$key};
10894: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10895: my $attrib;
10896: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10897: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10898: }
10899: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10900: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10901: $rewrites += $numchg;
10902: }
10903: }
10904: if ($rewrites) {
10905: my $saveresult;
10906: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10907: if ($url eq $container) {
10908: my ($fname) = ($container =~ m{/([^/]+)$});
10909: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10910: $count,'<span class="LC_filename">'.
10911: $fname.'</span>').'</p>';
10912: } else {
10913: $output .= '<p class="LC_error">'.
10914: &mt('Error: could not update links in [_1].',
10915: '<span class="LC_filename">'.
10916: $container.'</span>').'</p>';
10917:
10918: }
10919: }
10920: }
10921: }
1.987 raeburn 10922: } else {
10923: &logthis('Failed to parse '.$container.
10924: ' to modify references: '.$parse_result);
1.661 raeburn 10925: }
10926: }
1.1071 raeburn 10927: if (wantarray) {
10928: return ($output,$count,$codebasecount);
10929: } else {
10930: return $output;
10931: }
1.661 raeburn 10932: }
10933:
10934: sub check_for_existing {
10935: my ($path,$fname,$element) = @_;
10936: my ($state,$msg);
10937: if (-d $path.'/'.$fname) {
10938: $state = 'exists';
10939: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10940: } elsif (-e $path.'/'.$fname) {
10941: $state = 'exists';
10942: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10943: }
10944: if ($state eq 'exists') {
10945: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10946: }
10947: return ($state,$msg);
10948: }
10949:
10950: sub check_for_upload {
10951: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10952: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10953: my $filesize = length($env{'form.'.$element});
10954: if (!$filesize) {
10955: my $msg = '<span class="LC_error">'.
10956: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10957: '<span class="LC_filename">'.$fname.'</span>',
10958: $filesize).'<br />'.
1.1007 raeburn 10959: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10960: '</span>';
10961: return ('zero_bytes',$msg);
10962: }
10963: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10964: my $getpropath = 1;
1.1021 raeburn 10965: my ($dirlistref,$listerror) =
10966: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10967: my $found_file = 0;
10968: my $locked_file = 0;
1.991 raeburn 10969: my @lockers;
10970: my $navmap;
10971: if ($env{'request.course.id'}) {
10972: $navmap = Apache::lonnavmaps::navmap->new();
10973: }
1.1021 raeburn 10974: if (ref($dirlistref) eq 'ARRAY') {
10975: foreach my $line (@{$dirlistref}) {
10976: my ($file_name,$rest)=split(/\&/,$line,2);
10977: if ($file_name eq $fname){
10978: $file_name = $path.$file_name;
10979: if ($group ne '') {
10980: $file_name = $group.$file_name;
10981: }
10982: $found_file = 1;
10983: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10984: foreach my $lock (@lockers) {
10985: if (ref($lock) eq 'ARRAY') {
10986: my ($symb,$crsid) = @{$lock};
10987: if ($crsid eq $env{'request.course.id'}) {
10988: if (ref($navmap)) {
10989: my $res = $navmap->getBySymb($symb);
10990: foreach my $part (@{$res->parts()}) {
10991: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10992: unless (($slot_status == $res->RESERVED) ||
10993: ($slot_status == $res->RESERVED_LOCATION)) {
10994: $locked_file = 1;
10995: }
1.991 raeburn 10996: }
1.1021 raeburn 10997: } else {
10998: $locked_file = 1;
1.991 raeburn 10999: }
11000: } else {
11001: $locked_file = 1;
11002: }
11003: }
1.1021 raeburn 11004: }
11005: } else {
11006: my @info = split(/\&/,$rest);
11007: my $currsize = $info[6]/1000;
11008: if ($currsize < $filesize) {
11009: my $extra = $filesize - $currsize;
11010: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11011: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11012: &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 11013: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11014: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11015: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11016: return ('will_exceed_quota',$msg);
11017: }
1.984 raeburn 11018: }
11019: }
1.661 raeburn 11020: }
11021: }
11022: }
11023: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11024: my $msg = '<p class="LC_warning">'.
11025: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11026: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11027: return ('will_exceed_quota',$msg);
11028: } elsif ($found_file) {
11029: if ($locked_file) {
1.1075.2.69 raeburn 11030: my $msg = '<p class="LC_warning">';
1.661 raeburn 11031: $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 11032: $msg .= '</p>';
1.661 raeburn 11033: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11034: return ('file_locked',$msg);
11035: } else {
1.1075.2.69 raeburn 11036: my $msg = '<p class="LC_error">';
1.984 raeburn 11037: $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 11038: $msg .= '</p>';
1.984 raeburn 11039: return ('existingfile',$msg);
1.661 raeburn 11040: }
11041: }
11042: }
11043:
1.987 raeburn 11044: sub check_for_traversal {
11045: my ($path,$url,$toplevel) = @_;
11046: my @parts=split(/\//,$path);
11047: my $cleanpath;
11048: my $fullpath = $url;
11049: for (my $i=0;$i<@parts;$i++) {
11050: next if ($parts[$i] eq '.');
11051: if ($parts[$i] eq '..') {
11052: $fullpath =~ s{([^/]+/)$}{};
11053: } else {
11054: $fullpath .= $parts[$i].'/';
11055: }
11056: }
11057: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11058: $cleanpath = $1;
11059: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11060: my $curr_toprel = $1;
11061: my @parts = split(/\//,$curr_toprel);
11062: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11063: my @urlparts = split(/\//,$url_toprel);
11064: my $doubledots;
11065: my $startdiff = -1;
11066: for (my $i=0; $i<@urlparts; $i++) {
11067: if ($startdiff == -1) {
11068: unless ($urlparts[$i] eq $parts[$i]) {
11069: $startdiff = $i;
11070: $doubledots .= '../';
11071: }
11072: } else {
11073: $doubledots .= '../';
11074: }
11075: }
11076: if ($startdiff > -1) {
11077: $cleanpath = $doubledots;
11078: for (my $i=$startdiff; $i<@parts; $i++) {
11079: $cleanpath .= $parts[$i].'/';
11080: }
11081: }
11082: }
11083: $cleanpath =~ s{(/)$}{};
11084: return $cleanpath;
11085: }
1.31 albertel 11086:
1.1053 raeburn 11087: sub is_archive_file {
11088: my ($mimetype) = @_;
11089: if (($mimetype eq 'application/octet-stream') ||
11090: ($mimetype eq 'application/x-stuffit') ||
11091: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11092: return 1;
11093: }
11094: return;
11095: }
11096:
11097: sub decompress_form {
1.1065 raeburn 11098: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11099: my %lt = &Apache::lonlocal::texthash (
11100: this => 'This file is an archive file.',
1.1067 raeburn 11101: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11102: itsc => 'Its contents are as follows:',
1.1053 raeburn 11103: youm => 'You may wish to extract its contents.',
11104: extr => 'Extract contents',
1.1067 raeburn 11105: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11106: proa => 'Process automatically?',
1.1053 raeburn 11107: yes => 'Yes',
11108: no => 'No',
1.1067 raeburn 11109: fold => 'Title for folder containing movie',
11110: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11111: );
1.1065 raeburn 11112: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11113: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11114: my $info = &list_archive_contents($fileloc,\@paths);
11115: if (@paths) {
11116: foreach my $path (@paths) {
11117: $path =~ s{^/}{};
1.1067 raeburn 11118: if ($path =~ m{^([^/]+)/$}) {
11119: $topdir = $1;
11120: }
1.1065 raeburn 11121: if ($path =~ m{^([^/]+)/}) {
11122: $toplevel{$1} = $path;
11123: } else {
11124: $toplevel{$path} = $path;
11125: }
11126: }
11127: }
1.1067 raeburn 11128: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11129: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11130: "$topdir/media/",
11131: "$topdir/media/$topdir.mp4",
11132: "$topdir/media/FirstFrame.png",
11133: "$topdir/media/player.swf",
11134: "$topdir/media/swfobject.js",
11135: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 11136: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 11137: "$topdir/$topdir.mp4",
11138: "$topdir/$topdir\_config.xml",
11139: "$topdir/$topdir\_controller.swf",
11140: "$topdir/$topdir\_embed.css",
11141: "$topdir/$topdir\_First_Frame.png",
11142: "$topdir/$topdir\_player.html",
11143: "$topdir/$topdir\_Thumbnails.png",
11144: "$topdir/playerProductInstall.swf",
11145: "$topdir/scripts/",
11146: "$topdir/scripts/config_xml.js",
11147: "$topdir/scripts/handlebars.js",
11148: "$topdir/scripts/jquery-1.7.1.min.js",
11149: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11150: "$topdir/scripts/modernizr.js",
11151: "$topdir/scripts/player-min.js",
11152: "$topdir/scripts/swfobject.js",
11153: "$topdir/skins/",
11154: "$topdir/skins/configuration_express.xml",
11155: "$topdir/skins/express_show/",
11156: "$topdir/skins/express_show/player-min.css",
11157: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 11158: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11159: "$topdir/$topdir.mp4",
11160: "$topdir/$topdir\_config.xml",
11161: "$topdir/$topdir\_controller.swf",
11162: "$topdir/$topdir\_embed.css",
11163: "$topdir/$topdir\_First_Frame.png",
11164: "$topdir/$topdir\_player.html",
11165: "$topdir/$topdir\_Thumbnails.png",
11166: "$topdir/playerProductInstall.swf",
11167: "$topdir/scripts/",
11168: "$topdir/scripts/config_xml.js",
11169: "$topdir/scripts/techsmith-smart-player.min.js",
11170: "$topdir/skins/",
11171: "$topdir/skins/configuration_express.xml",
11172: "$topdir/skins/express_show/",
11173: "$topdir/skins/express_show/spritesheet.min.css",
11174: "$topdir/skins/express_show/spritesheet.png",
11175: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 11176: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11177: if (@diffs == 0) {
1.1075.2.59 raeburn 11178: $is_camtasia = 6;
11179: } else {
1.1075.2.81 raeburn 11180: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 11181: if (@diffs == 0) {
11182: $is_camtasia = 8;
1.1075.2.81 raeburn 11183: } else {
11184: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11185: if (@diffs == 0) {
11186: $is_camtasia = 8;
11187: }
1.1075.2.59 raeburn 11188: }
1.1067 raeburn 11189: }
11190: }
11191: my $output;
11192: if ($is_camtasia) {
11193: $output = <<"ENDCAM";
11194: <script type="text/javascript" language="Javascript">
11195: // <![CDATA[
11196:
11197: function camtasiaToggle() {
11198: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11199: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11200: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11201: document.getElementById('camtasia_titles').style.display='block';
11202: } else {
11203: document.getElementById('camtasia_titles').style.display='none';
11204: }
11205: }
11206: }
11207: return;
11208: }
11209:
11210: // ]]>
11211: </script>
11212: <p>$lt{'camt'}</p>
11213: ENDCAM
1.1065 raeburn 11214: } else {
1.1067 raeburn 11215: $output = '<p>'.$lt{'this'};
11216: if ($info eq '') {
11217: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11218: } else {
11219: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11220: '<div><pre>'.$info.'</pre></div>';
11221: }
1.1065 raeburn 11222: }
1.1067 raeburn 11223: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11224: my $duplicates;
11225: my $num = 0;
11226: if (ref($dirlist) eq 'ARRAY') {
11227: foreach my $item (@{$dirlist}) {
11228: if (ref($item) eq 'ARRAY') {
11229: if (exists($toplevel{$item->[0]})) {
11230: $duplicates .=
11231: &start_data_table_row().
11232: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11233: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11234: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11235: 'value="1" />'.&mt('Yes').'</label>'.
11236: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11237: '<td>'.$item->[0].'</td>';
11238: if ($item->[2]) {
11239: $duplicates .= '<td>'.&mt('Directory').'</td>';
11240: } else {
11241: $duplicates .= '<td>'.&mt('File').'</td>';
11242: }
11243: $duplicates .= '<td>'.$item->[3].'</td>'.
11244: '<td>'.
11245: &Apache::lonlocal::locallocaltime($item->[4]).
11246: '</td>'.
11247: &end_data_table_row();
11248: $num ++;
11249: }
11250: }
11251: }
11252: }
11253: my $itemcount;
11254: if (@paths > 0) {
11255: $itemcount = scalar(@paths);
11256: } else {
11257: $itemcount = 1;
11258: }
1.1067 raeburn 11259: if ($is_camtasia) {
11260: $output .= $lt{'auto'}.'<br />'.
11261: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 11262: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11263: $lt{'yes'}.'</label> <label>'.
11264: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11265: $lt{'no'}.'</label></span><br />'.
11266: '<div id="camtasia_titles" style="display:block">'.
11267: &Apache::lonhtmlcommon::start_pick_box().
11268: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11269: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11270: &Apache::lonhtmlcommon::row_closure().
11271: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11272: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11273: &Apache::lonhtmlcommon::row_closure(1).
11274: &Apache::lonhtmlcommon::end_pick_box().
11275: '</div>';
11276: }
1.1065 raeburn 11277: $output .=
11278: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11279: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11280: "\n";
1.1065 raeburn 11281: if ($duplicates ne '') {
11282: $output .= '<p><span class="LC_warning">'.
11283: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11284: &start_data_table().
11285: &start_data_table_header_row().
11286: '<th>'.&mt('Overwrite?').'</th>'.
11287: '<th>'.&mt('Name').'</th>'.
11288: '<th>'.&mt('Type').'</th>'.
11289: '<th>'.&mt('Size').'</th>'.
11290: '<th>'.&mt('Last modified').'</th>'.
11291: &end_data_table_header_row().
11292: $duplicates.
11293: &end_data_table().
11294: '</p>';
11295: }
1.1067 raeburn 11296: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11297: if (ref($hiddenelements) eq 'HASH') {
11298: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11299: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11300: }
11301: }
11302: $output .= <<"END";
1.1067 raeburn 11303: <br />
1.1053 raeburn 11304: <input type="submit" name="decompress" value="$lt{'extr'}" />
11305: </form>
11306: $noextract
11307: END
11308: return $output;
11309: }
11310:
1.1065 raeburn 11311: sub decompression_utility {
11312: my ($program) = @_;
11313: my @utilities = ('tar','gunzip','bunzip2','unzip');
11314: my $location;
11315: if (grep(/^\Q$program\E$/,@utilities)) {
11316: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11317: '/usr/sbin/') {
11318: if (-x $dir.$program) {
11319: $location = $dir.$program;
11320: last;
11321: }
11322: }
11323: }
11324: return $location;
11325: }
11326:
11327: sub list_archive_contents {
11328: my ($file,$pathsref) = @_;
11329: my (@cmd,$output);
11330: my $needsregexp;
11331: if ($file =~ /\.zip$/) {
11332: @cmd = (&decompression_utility('unzip'),"-l");
11333: $needsregexp = 1;
11334: } elsif (($file =~ m/\.tar\.gz$/) ||
11335: ($file =~ /\.tgz$/)) {
11336: @cmd = (&decompression_utility('tar'),"-ztf");
11337: } elsif ($file =~ /\.tar\.bz2$/) {
11338: @cmd = (&decompression_utility('tar'),"-jtf");
11339: } elsif ($file =~ m|\.tar$|) {
11340: @cmd = (&decompression_utility('tar'),"-tf");
11341: }
11342: if (@cmd) {
11343: undef($!);
11344: undef($@);
11345: if (open(my $fh,"-|", @cmd, $file)) {
11346: while (my $line = <$fh>) {
11347: $output .= $line;
11348: chomp($line);
11349: my $item;
11350: if ($needsregexp) {
11351: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11352: } else {
11353: $item = $line;
11354: }
11355: if ($item ne '') {
11356: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11357: push(@{$pathsref},$item);
11358: }
11359: }
11360: }
11361: close($fh);
11362: }
11363: }
11364: return $output;
11365: }
11366:
1.1053 raeburn 11367: sub decompress_uploaded_file {
11368: my ($file,$dir) = @_;
11369: &Apache::lonnet::appenv({'cgi.file' => $file});
11370: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11371: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11372: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11373: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11374: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11375: my $decompressed = $env{'cgi.decompressed'};
11376: &Apache::lonnet::delenv('cgi.file');
11377: &Apache::lonnet::delenv('cgi.dir');
11378: &Apache::lonnet::delenv('cgi.decompressed');
11379: return ($decompressed,$result);
11380: }
11381:
1.1055 raeburn 11382: sub process_decompression {
11383: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11384: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 11385: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 11386: $error = &mt('Filename not a supported archive file type.').
11387: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11388: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11389: } else {
11390: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11391: if ($docuhome eq 'no_host') {
11392: $error = &mt('Could not determine home server for course.');
11393: } else {
11394: my @ids=&Apache::lonnet::current_machine_ids();
11395: my $currdir = "$dir_root/$destination";
11396: if (grep(/^\Q$docuhome\E$/,@ids)) {
11397: $dir = &LONCAPA::propath($docudom,$docuname).
11398: "$dir_root/$destination";
11399: } else {
11400: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11401: "$dir_root/$docudom/$docuname/$destination";
11402: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11403: $error = &mt('Archive file not found.');
11404: }
11405: }
1.1065 raeburn 11406: my (@to_overwrite,@to_skip);
11407: if ($env{'form.archive_overwrite_total'} > 0) {
11408: my $total = $env{'form.archive_overwrite_total'};
11409: for (my $i=0; $i<$total; $i++) {
11410: if ($env{'form.archive_overwrite_'.$i} == 1) {
11411: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11412: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11413: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11414: }
11415: }
11416: }
11417: my $numskip = scalar(@to_skip);
11418: if (($numskip > 0) &&
11419: ($numskip == $env{'form.archive_itemcount'})) {
11420: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11421: } elsif ($dir eq '') {
1.1055 raeburn 11422: $error = &mt('Directory containing archive file unavailable.');
11423: } elsif (!$error) {
1.1065 raeburn 11424: my ($decompressed,$display);
11425: if ($numskip > 0) {
11426: my $tempdir = time.'_'.$$.int(rand(10000));
11427: mkdir("$dir/$tempdir",0755);
11428: system("mv $dir/$file $dir/$tempdir/$file");
11429: ($decompressed,$display) =
11430: &decompress_uploaded_file($file,"$dir/$tempdir");
11431: foreach my $item (@to_skip) {
11432: if (($item ne '') && ($item !~ /\.\./)) {
11433: if (-f "$dir/$tempdir/$item") {
11434: unlink("$dir/$tempdir/$item");
11435: } elsif (-d "$dir/$tempdir/$item") {
11436: system("rm -rf $dir/$tempdir/$item");
11437: }
11438: }
11439: }
11440: system("mv $dir/$tempdir/* $dir");
11441: rmdir("$dir/$tempdir");
11442: } else {
11443: ($decompressed,$display) =
11444: &decompress_uploaded_file($file,$dir);
11445: }
1.1055 raeburn 11446: if ($decompressed eq 'ok') {
1.1065 raeburn 11447: $output = '<p class="LC_info">'.
11448: &mt('Files extracted successfully from archive.').
11449: '</p>'."\n";
1.1055 raeburn 11450: my ($warning,$result,@contents);
11451: my ($newdirlistref,$newlisterror) =
11452: &Apache::lonnet::dirlist($currdir,$docudom,
11453: $docuname,1);
11454: my (%is_dir,%changes,@newitems);
11455: my $dirptr = 16384;
1.1065 raeburn 11456: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11457: foreach my $dir_line (@{$newdirlistref}) {
11458: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11459: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11460: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11461: push(@newitems,$item);
11462: if ($dirptr&$testdir) {
11463: $is_dir{$item} = 1;
11464: }
11465: $changes{$item} = 1;
11466: }
11467: }
11468: }
11469: if (keys(%changes) > 0) {
11470: foreach my $item (sort(@newitems)) {
11471: if ($changes{$item}) {
11472: push(@contents,$item);
11473: }
11474: }
11475: }
11476: if (@contents > 0) {
1.1067 raeburn 11477: my $wantform;
11478: unless ($env{'form.autoextract_camtasia'}) {
11479: $wantform = 1;
11480: }
1.1056 raeburn 11481: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11482: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11483: $currdir,\%is_dir,
11484: \%children,\%parent,
1.1056 raeburn 11485: \@contents,\%dirorder,
11486: \%titles,$wantform);
1.1055 raeburn 11487: if ($datatable ne '') {
11488: $output .= &archive_options_form('decompressed',$datatable,
11489: $count,$hiddenelem);
1.1065 raeburn 11490: my $startcount = 6;
1.1055 raeburn 11491: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11492: \%titles,\%children);
1.1055 raeburn 11493: }
1.1067 raeburn 11494: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 11495: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 11496: my %displayed;
11497: my $total = 1;
11498: $env{'form.archive_directory'} = [];
11499: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11500: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11501: $path =~ s{/$}{};
11502: my $item;
11503: if ($path ne '') {
11504: $item = "$path/$titles{$i}";
11505: } else {
11506: $item = $titles{$i};
11507: }
11508: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11509: if ($item eq $contents[0]) {
11510: push(@{$env{'form.archive_directory'}},$i);
11511: $env{'form.archive_'.$i} = 'display';
11512: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11513: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 11514: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
11515: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 11516: $env{'form.archive_'.$i} = 'display';
11517: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11518: $displayed{'web'} = $i;
11519: } else {
1.1075.2.59 raeburn 11520: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
11521: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
11522: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 11523: push(@{$env{'form.archive_directory'}},$i);
11524: }
11525: $env{'form.archive_'.$i} = 'dependency';
11526: }
11527: $total ++;
11528: }
11529: for (my $i=1; $i<$total; $i++) {
11530: next if ($i == $displayed{'web'});
11531: next if ($i == $displayed{'folder'});
11532: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11533: }
11534: $env{'form.phase'} = 'decompress_cleanup';
11535: $env{'form.archivedelete'} = 1;
11536: $env{'form.archive_count'} = $total-1;
11537: $output .=
11538: &process_extracted_files('coursedocs',$docudom,
11539: $docuname,$destination,
11540: $dir_root,$hiddenelem);
11541: }
1.1055 raeburn 11542: } else {
11543: $warning = &mt('No new items extracted from archive file.');
11544: }
11545: } else {
11546: $output = $display;
11547: $error = &mt('An error occurred during extraction from the archive file.');
11548: }
11549: }
11550: }
11551: }
11552: if ($error) {
11553: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11554: $error.'</p>'."\n";
11555: }
11556: if ($warning) {
11557: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11558: }
11559: return $output;
11560: }
11561:
11562: sub get_extracted {
1.1056 raeburn 11563: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11564: $titles,$wantform) = @_;
1.1055 raeburn 11565: my $count = 0;
11566: my $depth = 0;
11567: my $datatable;
1.1056 raeburn 11568: my @hierarchy;
1.1055 raeburn 11569: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11570: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11571: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11572: foreach my $item (@{$contents}) {
11573: $count ++;
1.1056 raeburn 11574: @{$dirorder->{$count}} = @hierarchy;
11575: $titles->{$count} = $item;
1.1055 raeburn 11576: &archive_hierarchy($depth,$count,$parent,$children);
11577: if ($wantform) {
11578: $datatable .= &archive_row($is_dir->{$item},$item,
11579: $currdir,$depth,$count);
11580: }
11581: if ($is_dir->{$item}) {
11582: $depth ++;
1.1056 raeburn 11583: push(@hierarchy,$count);
11584: $parent->{$depth} = $count;
1.1055 raeburn 11585: $datatable .=
11586: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11587: \$depth,\$count,\@hierarchy,$dirorder,
11588: $children,$parent,$titles,$wantform);
1.1055 raeburn 11589: $depth --;
1.1056 raeburn 11590: pop(@hierarchy);
1.1055 raeburn 11591: }
11592: }
11593: return ($count,$datatable);
11594: }
11595:
11596: sub recurse_extracted_archive {
1.1056 raeburn 11597: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11598: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11599: my $result='';
1.1056 raeburn 11600: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11601: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11602: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11603: return $result;
11604: }
11605: my $dirptr = 16384;
11606: my ($newdirlistref,$newlisterror) =
11607: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11608: if (ref($newdirlistref) eq 'ARRAY') {
11609: foreach my $dir_line (@{$newdirlistref}) {
11610: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11611: unless ($item =~ /^\.+$/) {
11612: $$count ++;
1.1056 raeburn 11613: @{$dirorder->{$$count}} = @{$hierarchy};
11614: $titles->{$$count} = $item;
1.1055 raeburn 11615: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11616:
1.1055 raeburn 11617: my $is_dir;
11618: if ($dirptr&$testdir) {
11619: $is_dir = 1;
11620: }
11621: if ($wantform) {
11622: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11623: }
11624: if ($is_dir) {
11625: $$depth ++;
1.1056 raeburn 11626: push(@{$hierarchy},$$count);
11627: $parent->{$$depth} = $$count;
1.1055 raeburn 11628: $result .=
11629: &recurse_extracted_archive("$currdir/$item",$docudom,
11630: $docuname,$depth,$count,
1.1056 raeburn 11631: $hierarchy,$dirorder,$children,
11632: $parent,$titles,$wantform);
1.1055 raeburn 11633: $$depth --;
1.1056 raeburn 11634: pop(@{$hierarchy});
1.1055 raeburn 11635: }
11636: }
11637: }
11638: }
11639: return $result;
11640: }
11641:
11642: sub archive_hierarchy {
11643: my ($depth,$count,$parent,$children) =@_;
11644: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11645: if (exists($parent->{$depth})) {
11646: $children->{$parent->{$depth}} .= $count.':';
11647: }
11648: }
11649: return;
11650: }
11651:
11652: sub archive_row {
11653: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11654: my ($name) = ($item =~ m{([^/]+)$});
11655: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11656: 'display' => 'Add as file',
1.1055 raeburn 11657: 'dependency' => 'Include as dependency',
11658: 'discard' => 'Discard',
11659: );
11660: if ($is_dir) {
1.1059 raeburn 11661: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11662: }
1.1056 raeburn 11663: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11664: my $offset = 0;
1.1055 raeburn 11665: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11666: $offset ++;
1.1065 raeburn 11667: if ($action ne 'display') {
11668: $offset ++;
11669: }
1.1055 raeburn 11670: $output .= '<td><span class="LC_nobreak">'.
11671: '<label><input type="radio" name="archive_'.$count.
11672: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11673: my $text = $choices{$action};
11674: if ($is_dir) {
11675: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11676: if ($action eq 'display') {
1.1059 raeburn 11677: $text = &mt('Add as folder');
1.1055 raeburn 11678: }
1.1056 raeburn 11679: } else {
11680: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11681:
11682: }
11683: $output .= ' /> '.$choices{$action}.'</label></span>';
11684: if ($action eq 'dependency') {
11685: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11686: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11687: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11688: '<option value=""></option>'."\n".
11689: '</select>'."\n".
11690: '</div>';
1.1059 raeburn 11691: } elsif ($action eq 'display') {
11692: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11693: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11694: '</div>';
1.1055 raeburn 11695: }
1.1056 raeburn 11696: $output .= '</td>';
1.1055 raeburn 11697: }
11698: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11699: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11700: for (my $i=0; $i<$depth; $i++) {
11701: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11702: }
11703: if ($is_dir) {
11704: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11705: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11706: } else {
11707: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11708: }
11709: $output .= ' '.$name.'</td>'."\n".
11710: &end_data_table_row();
11711: return $output;
11712: }
11713:
11714: sub archive_options_form {
1.1065 raeburn 11715: my ($form,$display,$count,$hiddenelem) = @_;
11716: my %lt = &Apache::lonlocal::texthash(
11717: perm => 'Permanently remove archive file?',
11718: hows => 'How should each extracted item be incorporated in the course?',
11719: cont => 'Content actions for all',
11720: addf => 'Add as folder/file',
11721: incd => 'Include as dependency for a displayed file',
11722: disc => 'Discard',
11723: no => 'No',
11724: yes => 'Yes',
11725: save => 'Save',
11726: );
11727: my $output = <<"END";
11728: <form name="$form" method="post" action="">
11729: <p><span class="LC_nobreak">$lt{'perm'}
11730: <label>
11731: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11732: </label>
11733:
11734: <label>
11735: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11736: </span>
11737: </p>
11738: <input type="hidden" name="phase" value="decompress_cleanup" />
11739: <br />$lt{'hows'}
11740: <div class="LC_columnSection">
11741: <fieldset>
11742: <legend>$lt{'cont'}</legend>
11743: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11744: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11745: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11746: </fieldset>
11747: </div>
11748: END
11749: return $output.
1.1055 raeburn 11750: &start_data_table()."\n".
1.1065 raeburn 11751: $display."\n".
1.1055 raeburn 11752: &end_data_table()."\n".
11753: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11754: $hiddenelem.
1.1065 raeburn 11755: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11756: '</form>';
11757: }
11758:
11759: sub archive_javascript {
1.1056 raeburn 11760: my ($startcount,$numitems,$titles,$children) = @_;
11761: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11762: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11763: my $scripttag = <<START;
11764: <script type="text/javascript">
11765: // <![CDATA[
11766:
11767: function checkAll(form,prefix) {
11768: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11769: for (var i=0; i < form.elements.length; i++) {
11770: var id = form.elements[i].id;
11771: if ((id != '') && (id != undefined)) {
11772: if (idstr.test(id)) {
11773: if (form.elements[i].type == 'radio') {
11774: form.elements[i].checked = true;
1.1056 raeburn 11775: var nostart = i-$startcount;
1.1059 raeburn 11776: var offset = nostart%7;
11777: var count = (nostart-offset)/7;
1.1056 raeburn 11778: dependencyCheck(form,count,offset);
1.1055 raeburn 11779: }
11780: }
11781: }
11782: }
11783: }
11784:
11785: function propagateCheck(form,count) {
11786: if (count > 0) {
1.1059 raeburn 11787: var startelement = $startcount + ((count-1) * 7);
11788: for (var j=1; j<6; j++) {
11789: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11790: var item = startelement + j;
11791: if (form.elements[item].type == 'radio') {
11792: if (form.elements[item].checked) {
11793: containerCheck(form,count,j);
11794: break;
11795: }
1.1055 raeburn 11796: }
11797: }
11798: }
11799: }
11800: }
11801:
11802: numitems = $numitems
1.1056 raeburn 11803: var titles = new Array(numitems);
11804: var parents = new Array(numitems);
1.1055 raeburn 11805: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11806: parents[i] = new Array;
1.1055 raeburn 11807: }
1.1059 raeburn 11808: var maintitle = '$maintitle';
1.1055 raeburn 11809:
11810: START
11811:
1.1056 raeburn 11812: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11813: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11814: for (my $i=0; $i<@contents; $i ++) {
11815: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11816: }
11817: }
11818:
1.1056 raeburn 11819: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11820: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11821: }
11822:
1.1055 raeburn 11823: $scripttag .= <<END;
11824:
11825: function containerCheck(form,count,offset) {
11826: if (count > 0) {
1.1056 raeburn 11827: dependencyCheck(form,count,offset);
1.1059 raeburn 11828: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11829: form.elements[item].checked = true;
11830: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11831: if (parents[count].length > 0) {
11832: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11833: containerCheck(form,parents[count][j],offset);
11834: }
11835: }
11836: }
11837: }
11838: }
11839:
11840: function dependencyCheck(form,count,offset) {
11841: if (count > 0) {
1.1059 raeburn 11842: var chosen = (offset+$startcount)+7*(count-1);
11843: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11844: var currtype = form.elements[depitem].type;
11845: if (form.elements[chosen].value == 'dependency') {
11846: document.getElementById('arc_depon_'+count).style.display='block';
11847: form.elements[depitem].options.length = 0;
11848: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 11849: for (var i=1; i<=numitems; i++) {
11850: if (i == count) {
11851: continue;
11852: }
1.1059 raeburn 11853: var startelement = $startcount + (i-1) * 7;
11854: for (var j=1; j<6; j++) {
11855: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11856: var item = startelement + j;
11857: if (form.elements[item].type == 'radio') {
11858: if (form.elements[item].checked) {
11859: if (form.elements[item].value == 'display') {
11860: var n = form.elements[depitem].options.length;
11861: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11862: }
11863: }
11864: }
11865: }
11866: }
11867: }
11868: } else {
11869: document.getElementById('arc_depon_'+count).style.display='none';
11870: form.elements[depitem].options.length = 0;
11871: form.elements[depitem].options[0] = new Option('Select','',true,true);
11872: }
1.1059 raeburn 11873: titleCheck(form,count,offset);
1.1056 raeburn 11874: }
11875: }
11876:
11877: function propagateSelect(form,count,offset) {
11878: if (count > 0) {
1.1065 raeburn 11879: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11880: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11881: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11882: if (parents[count].length > 0) {
11883: for (var j=0; j<parents[count].length; j++) {
11884: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11885: }
11886: }
11887: }
11888: }
11889: }
1.1056 raeburn 11890:
11891: function containerSelect(form,count,offset,picked) {
11892: if (count > 0) {
1.1065 raeburn 11893: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11894: if (form.elements[item].type == 'radio') {
11895: if (form.elements[item].value == 'dependency') {
11896: if (form.elements[item+1].type == 'select-one') {
11897: for (var i=0; i<form.elements[item+1].options.length; i++) {
11898: if (form.elements[item+1].options[i].value == picked) {
11899: form.elements[item+1].selectedIndex = i;
11900: break;
11901: }
11902: }
11903: }
11904: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11905: if (parents[count].length > 0) {
11906: for (var j=0; j<parents[count].length; j++) {
11907: containerSelect(form,parents[count][j],offset,picked);
11908: }
11909: }
11910: }
11911: }
11912: }
11913: }
11914: }
11915:
1.1059 raeburn 11916: function titleCheck(form,count,offset) {
11917: if (count > 0) {
11918: var chosen = (offset+$startcount)+7*(count-1);
11919: var depitem = $startcount + ((count-1) * 7) + 2;
11920: var currtype = form.elements[depitem].type;
11921: if (form.elements[chosen].value == 'display') {
11922: document.getElementById('arc_title_'+count).style.display='block';
11923: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11924: document.getElementById('archive_title_'+count).value=maintitle;
11925: }
11926: } else {
11927: document.getElementById('arc_title_'+count).style.display='none';
11928: if (currtype == 'text') {
11929: document.getElementById('archive_title_'+count).value='';
11930: }
11931: }
11932: }
11933: return;
11934: }
11935:
1.1055 raeburn 11936: // ]]>
11937: </script>
11938: END
11939: return $scripttag;
11940: }
11941:
11942: sub process_extracted_files {
1.1067 raeburn 11943: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11944: my $numitems = $env{'form.archive_count'};
11945: return unless ($numitems);
11946: my @ids=&Apache::lonnet::current_machine_ids();
11947: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11948: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11949: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11950: if (grep(/^\Q$docuhome\E$/,@ids)) {
11951: $prefix = &LONCAPA::propath($docudom,$docuname);
11952: $pathtocheck = "$dir_root/$destination";
11953: $dir = $dir_root;
11954: $ishome = 1;
11955: } else {
11956: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11957: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11958: $dir = "$dir_root/$docudom/$docuname";
11959: }
11960: my $currdir = "$dir_root/$destination";
11961: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11962: if ($env{'form.folderpath'}) {
11963: my @items = split('&',$env{'form.folderpath'});
11964: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 11965: if ($env{'form.folderpath'} =~ /\:1$/) {
11966: $containers{'0'}='page';
11967: } else {
11968: $containers{'0'}='sequence';
11969: }
1.1055 raeburn 11970: }
11971: my @archdirs = &get_env_multiple('form.archive_directory');
11972: if ($numitems) {
11973: for (my $i=1; $i<=$numitems; $i++) {
11974: my $path = $env{'form.archive_content_'.$i};
11975: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11976: my $item = $1;
11977: $toplevelitems{$item} = $i;
11978: if (grep(/^\Q$i\E$/,@archdirs)) {
11979: $is_dir{$item} = 1;
11980: }
11981: }
11982: }
11983: }
1.1067 raeburn 11984: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11985: if (keys(%toplevelitems) > 0) {
11986: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11987: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11988: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11989: }
1.1066 raeburn 11990: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11991: if ($numitems) {
11992: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 11993: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11994: my $path = $env{'form.archive_content_'.$i};
11995: if ($path =~ /^\Q$pathtocheck\E/) {
11996: if ($env{'form.archive_'.$i} eq 'discard') {
11997: if ($prefix ne '' && $path ne '') {
11998: if (-e $prefix.$path) {
1.1066 raeburn 11999: if ((@archdirs > 0) &&
12000: (grep(/^\Q$i\E$/,@archdirs))) {
12001: $todeletedir{$prefix.$path} = 1;
12002: } else {
12003: $todelete{$prefix.$path} = 1;
12004: }
1.1055 raeburn 12005: }
12006: }
12007: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12008: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12009: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12010: $docstitle = $env{'form.archive_title_'.$i};
12011: if ($docstitle eq '') {
12012: $docstitle = $title;
12013: }
1.1055 raeburn 12014: $outer = 0;
1.1056 raeburn 12015: if (ref($dirorder{$i}) eq 'ARRAY') {
12016: if (@{$dirorder{$i}} > 0) {
12017: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12018: if ($env{'form.archive_'.$item} eq 'display') {
12019: $outer = $item;
12020: last;
12021: }
12022: }
12023: }
12024: }
12025: my ($errtext,$fatal) =
12026: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12027: '/'.$folders{$outer}.'.'.
12028: $containers{$outer});
12029: next if ($fatal);
12030: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12031: if ($context eq 'coursedocs') {
1.1056 raeburn 12032: $mapinner{$i} = time;
1.1055 raeburn 12033: $folders{$i} = 'default_'.$mapinner{$i};
12034: $containers{$i} = 'sequence';
12035: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12036: $folders{$i}.'.'.$containers{$i};
12037: my $newidx = &LONCAPA::map::getresidx();
12038: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12039: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12040: push(@LONCAPA::map::order,$newidx);
12041: my ($outtext,$errtext) =
12042: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12043: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12044: '.'.$containers{$outer},1,1);
1.1056 raeburn 12045: $newseqid{$i} = $newidx;
1.1067 raeburn 12046: unless ($errtext) {
12047: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
12048: }
1.1055 raeburn 12049: }
12050: } else {
12051: if ($context eq 'coursedocs') {
12052: my $newidx=&LONCAPA::map::getresidx();
12053: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12054: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12055: $title;
12056: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12057: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
12058: }
12059: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12060: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12061: }
12062: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12063: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 12064: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 12065: unless ($ishome) {
12066: my $fetch = "$newdest{$i}/$title";
12067: $fetch =~ s/^\Q$prefix$dir\E//;
12068: $prompttofetch{$fetch} = 1;
12069: }
1.1055 raeburn 12070: }
12071: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12072: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12073: push(@LONCAPA::map::order, $newidx);
12074: my ($outtext,$errtext)=
12075: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12076: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12077: '.'.$containers{$outer},1,1);
1.1067 raeburn 12078: unless ($errtext) {
12079: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12080: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
12081: }
12082: }
1.1055 raeburn 12083: }
12084: }
1.1075.2.11 raeburn 12085: }
12086: } else {
12087: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12088: }
12089: }
12090: for (my $i=1; $i<=$numitems; $i++) {
12091: next unless ($env{'form.archive_'.$i} eq 'dependency');
12092: my $path = $env{'form.archive_content_'.$i};
12093: if ($path =~ /^\Q$pathtocheck\E/) {
12094: my ($title) = ($path =~ m{/([^/]+)$});
12095: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12096: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12097: if (ref($dirorder{$i}) eq 'ARRAY') {
12098: my ($itemidx,$fullpath,$relpath);
12099: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12100: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12101: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12102: if ($dirorder{$i}->[$j] eq $container) {
12103: $itemidx = $j;
1.1056 raeburn 12104: }
12105: }
1.1075.2.11 raeburn 12106: }
12107: if ($itemidx eq '') {
12108: $itemidx = 0;
12109: }
12110: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12111: if ($mapinner{$referrer{$i}}) {
12112: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12113: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12114: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12115: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12116: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12117: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12118: if (!-e $fullpath) {
12119: mkdir($fullpath,0755);
1.1056 raeburn 12120: }
12121: }
1.1075.2.11 raeburn 12122: } else {
12123: last;
1.1056 raeburn 12124: }
1.1075.2.11 raeburn 12125: }
12126: }
12127: } elsif ($newdest{$referrer{$i}}) {
12128: $fullpath = $newdest{$referrer{$i}};
12129: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12130: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12131: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12132: last;
12133: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12134: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12135: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12136: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12137: if (!-e $fullpath) {
12138: mkdir($fullpath,0755);
1.1056 raeburn 12139: }
12140: }
1.1075.2.11 raeburn 12141: } else {
12142: last;
1.1056 raeburn 12143: }
1.1075.2.11 raeburn 12144: }
12145: }
12146: if ($fullpath ne '') {
12147: if (-e "$prefix$path") {
12148: system("mv $prefix$path $fullpath/$title");
12149: }
12150: if (-e "$fullpath/$title") {
12151: my $showpath;
12152: if ($relpath ne '') {
12153: $showpath = "$relpath/$title";
12154: } else {
12155: $showpath = "/$title";
1.1056 raeburn 12156: }
1.1075.2.11 raeburn 12157: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12158: }
12159: unless ($ishome) {
12160: my $fetch = "$fullpath/$title";
12161: $fetch =~ s/^\Q$prefix$dir\E//;
12162: $prompttofetch{$fetch} = 1;
1.1055 raeburn 12163: }
12164: }
12165: }
1.1075.2.11 raeburn 12166: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12167: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12168: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12169: }
12170: } else {
1.1075.2.11 raeburn 12171: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 12172: }
12173: }
12174: if (keys(%todelete)) {
12175: foreach my $key (keys(%todelete)) {
12176: unlink($key);
1.1066 raeburn 12177: }
12178: }
12179: if (keys(%todeletedir)) {
12180: foreach my $key (keys(%todeletedir)) {
12181: rmdir($key);
12182: }
12183: }
12184: foreach my $dir (sort(keys(%is_dir))) {
12185: if (($pathtocheck ne '') && ($dir ne '')) {
12186: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12187: }
12188: }
1.1067 raeburn 12189: if ($result ne '') {
12190: $output .= '<ul>'."\n".
12191: $result."\n".
12192: '</ul>';
12193: }
12194: unless ($ishome) {
12195: my $replicationfail;
12196: foreach my $item (keys(%prompttofetch)) {
12197: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12198: unless ($fetchresult eq 'ok') {
12199: $replicationfail .= '<li>'.$item.'</li>'."\n";
12200: }
12201: }
12202: if ($replicationfail) {
12203: $output .= '<p class="LC_error">'.
12204: &mt('Course home server failed to retrieve:').'<ul>'.
12205: $replicationfail.
12206: '</ul></p>';
12207: }
12208: }
1.1055 raeburn 12209: } else {
12210: $warning = &mt('No items found in archive.');
12211: }
12212: if ($error) {
12213: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12214: $error.'</p>'."\n";
12215: }
12216: if ($warning) {
12217: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12218: }
12219: return $output;
12220: }
12221:
1.1066 raeburn 12222: sub cleanup_empty_dirs {
12223: my ($path) = @_;
12224: if (($path ne '') && (-d $path)) {
12225: if (opendir(my $dirh,$path)) {
12226: my @dircontents = grep(!/^\./,readdir($dirh));
12227: my $numitems = 0;
12228: foreach my $item (@dircontents) {
12229: if (-d "$path/$item") {
1.1075.2.28 raeburn 12230: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12231: if (-e "$path/$item") {
12232: $numitems ++;
12233: }
12234: } else {
12235: $numitems ++;
12236: }
12237: }
12238: if ($numitems == 0) {
12239: rmdir($path);
12240: }
12241: closedir($dirh);
12242: }
12243: }
12244: return;
12245: }
12246:
1.41 ng 12247: =pod
1.45 matthew 12248:
1.1075.2.56 raeburn 12249: =item * &get_folder_hierarchy()
1.1068 raeburn 12250:
12251: Provides hierarchy of names of folders/sub-folders containing the current
12252: item,
12253:
12254: Inputs: 3
12255: - $navmap - navmaps object
12256:
12257: - $map - url for map (either the trigger itself, or map containing
12258: the resource, which is the trigger).
12259:
12260: - $showitem - 1 => show title for map itself; 0 => do not show.
12261:
12262: Outputs: 1 @pathitems - array of folder/subfolder names.
12263:
12264: =cut
12265:
12266: sub get_folder_hierarchy {
12267: my ($navmap,$map,$showitem) = @_;
12268: my @pathitems;
12269: if (ref($navmap)) {
12270: my $mapres = $navmap->getResourceByUrl($map);
12271: if (ref($mapres)) {
12272: my $pcslist = $mapres->map_hierarchy();
12273: if ($pcslist ne '') {
12274: my @pcs = split(/,/,$pcslist);
12275: foreach my $pc (@pcs) {
12276: if ($pc == 1) {
1.1075.2.38 raeburn 12277: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12278: } else {
12279: my $res = $navmap->getByMapPc($pc);
12280: if (ref($res)) {
12281: my $title = $res->compTitle();
12282: $title =~ s/\W+/_/g;
12283: if ($title ne '') {
12284: push(@pathitems,$title);
12285: }
12286: }
12287: }
12288: }
12289: }
1.1071 raeburn 12290: if ($showitem) {
12291: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12292: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12293: } else {
12294: my $maptitle = $mapres->compTitle();
12295: $maptitle =~ s/\W+/_/g;
12296: if ($maptitle ne '') {
12297: push(@pathitems,$maptitle);
12298: }
1.1068 raeburn 12299: }
12300: }
12301: }
12302: }
12303: return @pathitems;
12304: }
12305:
12306: =pod
12307:
1.1015 raeburn 12308: =item * &get_turnedin_filepath()
12309:
12310: Determines path in a user's portfolio file for storage of files uploaded
12311: to a specific essayresponse or dropbox item.
12312:
12313: Inputs: 3 required + 1 optional.
12314: $symb is symb for resource, $uname and $udom are for current user (required).
12315: $caller is optional (can be "submission", if routine is called when storing
12316: an upoaded file when "Submit Answer" button was pressed).
12317:
12318: Returns array containing $path and $multiresp.
12319: $path is path in portfolio. $multiresp is 1 if this resource contains more
12320: than one file upload item. Callers of routine should append partid as a
12321: subdirectory to $path in cases where $multiresp is 1.
12322:
12323: Called by: homework/essayresponse.pm and homework/structuretags.pm
12324:
12325: =cut
12326:
12327: sub get_turnedin_filepath {
12328: my ($symb,$uname,$udom,$caller) = @_;
12329: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12330: my $turnindir;
12331: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12332: $turnindir = $userhash{'turnindir'};
12333: my ($path,$multiresp);
12334: if ($turnindir eq '') {
12335: if ($caller eq 'submission') {
12336: $turnindir = &mt('turned in');
12337: $turnindir =~ s/\W+/_/g;
12338: my %newhash = (
12339: 'turnindir' => $turnindir,
12340: );
12341: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12342: }
12343: }
12344: if ($turnindir ne '') {
12345: $path = '/'.$turnindir.'/';
12346: my ($multipart,$turnin,@pathitems);
12347: my $navmap = Apache::lonnavmaps::navmap->new();
12348: if (defined($navmap)) {
12349: my $mapres = $navmap->getResourceByUrl($map);
12350: if (ref($mapres)) {
12351: my $pcslist = $mapres->map_hierarchy();
12352: if ($pcslist ne '') {
12353: foreach my $pc (split(/,/,$pcslist)) {
12354: my $res = $navmap->getByMapPc($pc);
12355: if (ref($res)) {
12356: my $title = $res->compTitle();
12357: $title =~ s/\W+/_/g;
12358: if ($title ne '') {
1.1075.2.48 raeburn 12359: if (($pc > 1) && (length($title) > 12)) {
12360: $title = substr($title,0,12);
12361: }
1.1015 raeburn 12362: push(@pathitems,$title);
12363: }
12364: }
12365: }
12366: }
12367: my $maptitle = $mapres->compTitle();
12368: $maptitle =~ s/\W+/_/g;
12369: if ($maptitle ne '') {
1.1075.2.48 raeburn 12370: if (length($maptitle) > 12) {
12371: $maptitle = substr($maptitle,0,12);
12372: }
1.1015 raeburn 12373: push(@pathitems,$maptitle);
12374: }
12375: unless ($env{'request.state'} eq 'construct') {
12376: my $res = $navmap->getBySymb($symb);
12377: if (ref($res)) {
12378: my $partlist = $res->parts();
12379: my $totaluploads = 0;
12380: if (ref($partlist) eq 'ARRAY') {
12381: foreach my $part (@{$partlist}) {
12382: my @types = $res->responseType($part);
12383: my @ids = $res->responseIds($part);
12384: for (my $i=0; $i < scalar(@ids); $i++) {
12385: if ($types[$i] eq 'essay') {
12386: my $partid = $part.'_'.$ids[$i];
12387: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12388: $totaluploads ++;
12389: }
12390: }
12391: }
12392: }
12393: if ($totaluploads > 1) {
12394: $multiresp = 1;
12395: }
12396: }
12397: }
12398: }
12399: } else {
12400: return;
12401: }
12402: } else {
12403: return;
12404: }
12405: my $restitle=&Apache::lonnet::gettitle($symb);
12406: $restitle =~ s/\W+/_/g;
12407: if ($restitle eq '') {
12408: $restitle = ($resurl =~ m{/[^/]+$});
12409: if ($restitle eq '') {
12410: $restitle = time;
12411: }
12412: }
1.1075.2.48 raeburn 12413: if (length($restitle) > 12) {
12414: $restitle = substr($restitle,0,12);
12415: }
1.1015 raeburn 12416: push(@pathitems,$restitle);
12417: $path .= join('/',@pathitems);
12418: }
12419: return ($path,$multiresp);
12420: }
12421:
12422: =pod
12423:
1.464 albertel 12424: =back
1.41 ng 12425:
1.112 bowersj2 12426: =head1 CSV Upload/Handling functions
1.38 albertel 12427:
1.41 ng 12428: =over 4
12429:
1.648 raeburn 12430: =item * &upfile_store($r)
1.41 ng 12431:
12432: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12433: needs $env{'form.upfile'}
1.41 ng 12434: returns $datatoken to be put into hidden field
12435:
12436: =cut
1.31 albertel 12437:
12438: sub upfile_store {
12439: my $r=shift;
1.258 albertel 12440: $env{'form.upfile'}=~s/\r/\n/gs;
12441: $env{'form.upfile'}=~s/\f/\n/gs;
12442: $env{'form.upfile'}=~s/\n+/\n/gs;
12443: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12444:
1.258 albertel 12445: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12446: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12447: {
1.158 raeburn 12448: my $datafile = $r->dir_config('lonDaemons').
12449: '/tmp/'.$datatoken.'.tmp';
12450: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12451: print $fh $env{'form.upfile'};
1.158 raeburn 12452: close($fh);
12453: }
1.31 albertel 12454: }
12455: return $datatoken;
12456: }
12457:
1.56 matthew 12458: =pod
12459:
1.648 raeburn 12460: =item * &load_tmp_file($r)
1.41 ng 12461:
12462: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12463: needs $env{'form.datatoken'},
12464: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12465:
12466: =cut
1.31 albertel 12467:
12468: sub load_tmp_file {
12469: my $r=shift;
12470: my @studentdata=();
12471: {
1.158 raeburn 12472: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12473: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12474: if ( open(my $fh,"<$studentfile") ) {
12475: @studentdata=<$fh>;
12476: close($fh);
12477: }
1.31 albertel 12478: }
1.258 albertel 12479: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12480: }
12481:
1.56 matthew 12482: =pod
12483:
1.648 raeburn 12484: =item * &upfile_record_sep()
1.41 ng 12485:
12486: Separate uploaded file into records
12487: returns array of records,
1.258 albertel 12488: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12489:
12490: =cut
1.31 albertel 12491:
12492: sub upfile_record_sep {
1.258 albertel 12493: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12494: } else {
1.248 albertel 12495: my @records;
1.258 albertel 12496: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12497: if ($line=~/^\s*$/) { next; }
12498: push(@records,$line);
12499: }
12500: return @records;
1.31 albertel 12501: }
12502: }
12503:
1.56 matthew 12504: =pod
12505:
1.648 raeburn 12506: =item * &record_sep($record)
1.41 ng 12507:
1.258 albertel 12508: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12509:
12510: =cut
12511:
1.263 www 12512: sub takeleft {
12513: my $index=shift;
12514: return substr('0000'.$index,-4,4);
12515: }
12516:
1.31 albertel 12517: sub record_sep {
12518: my $record=shift;
12519: my %components=();
1.258 albertel 12520: if ($env{'form.upfiletype'} eq 'xml') {
12521: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12522: my $i=0;
1.356 albertel 12523: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12524: $field=~s/^(\"|\')//;
12525: $field=~s/(\"|\')$//;
1.263 www 12526: $components{&takeleft($i)}=$field;
1.31 albertel 12527: $i++;
12528: }
1.258 albertel 12529: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12530: my $i=0;
1.356 albertel 12531: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12532: $field=~s/^(\"|\')//;
12533: $field=~s/(\"|\')$//;
1.263 www 12534: $components{&takeleft($i)}=$field;
1.31 albertel 12535: $i++;
12536: }
12537: } else {
1.561 www 12538: my $separator=',';
1.480 banghart 12539: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12540: $separator=';';
1.480 banghart 12541: }
1.31 albertel 12542: my $i=0;
1.561 www 12543: # the character we are looking for to indicate the end of a quote or a record
12544: my $looking_for=$separator;
12545: # do not add the characters to the fields
12546: my $ignore=0;
12547: # we just encountered a separator (or the beginning of the record)
12548: my $just_found_separator=1;
12549: # store the field we are working on here
12550: my $field='';
12551: # work our way through all characters in record
12552: foreach my $character ($record=~/(.)/g) {
12553: if ($character eq $looking_for) {
12554: if ($character ne $separator) {
12555: # Found the end of a quote, again looking for separator
12556: $looking_for=$separator;
12557: $ignore=1;
12558: } else {
12559: # Found a separator, store away what we got
12560: $components{&takeleft($i)}=$field;
12561: $i++;
12562: $just_found_separator=1;
12563: $ignore=0;
12564: $field='';
12565: }
12566: next;
12567: }
12568: # single or double quotation marks after a separator indicate beginning of a quote
12569: # we are now looking for the end of the quote and need to ignore separators
12570: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12571: $looking_for=$character;
12572: next;
12573: }
12574: # ignore would be true after we reached the end of a quote
12575: if ($ignore) { next; }
12576: if (($just_found_separator) && ($character=~/\s/)) { next; }
12577: $field.=$character;
12578: $just_found_separator=0;
1.31 albertel 12579: }
1.561 www 12580: # catch the very last entry, since we never encountered the separator
12581: $components{&takeleft($i)}=$field;
1.31 albertel 12582: }
12583: return %components;
12584: }
12585:
1.144 matthew 12586: ######################################################
12587: ######################################################
12588:
1.56 matthew 12589: =pod
12590:
1.648 raeburn 12591: =item * &upfile_select_html()
1.41 ng 12592:
1.144 matthew 12593: Return HTML code to select a file from the users machine and specify
12594: the file type.
1.41 ng 12595:
12596: =cut
12597:
1.144 matthew 12598: ######################################################
12599: ######################################################
1.31 albertel 12600: sub upfile_select_html {
1.144 matthew 12601: my %Types = (
12602: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12603: semisv => &mt('Semicolon separated values'),
1.144 matthew 12604: space => &mt('Space separated'),
12605: tab => &mt('Tabulator separated'),
12606: # xml => &mt('HTML/XML'),
12607: );
12608: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12609: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12610: foreach my $type (sort(keys(%Types))) {
12611: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12612: }
12613: $Str .= "</select>\n";
12614: return $Str;
1.31 albertel 12615: }
12616:
1.301 albertel 12617: sub get_samples {
12618: my ($records,$toget) = @_;
12619: my @samples=({});
12620: my $got=0;
12621: foreach my $rec (@$records) {
12622: my %temp = &record_sep($rec);
12623: if (! grep(/\S/, values(%temp))) { next; }
12624: if (%temp) {
12625: $samples[$got]=\%temp;
12626: $got++;
12627: if ($got == $toget) { last; }
12628: }
12629: }
12630: return \@samples;
12631: }
12632:
1.144 matthew 12633: ######################################################
12634: ######################################################
12635:
1.56 matthew 12636: =pod
12637:
1.648 raeburn 12638: =item * &csv_print_samples($r,$records)
1.41 ng 12639:
12640: Prints a table of sample values from each column uploaded $r is an
12641: Apache Request ref, $records is an arrayref from
12642: &Apache::loncommon::upfile_record_sep
12643:
12644: =cut
12645:
1.144 matthew 12646: ######################################################
12647: ######################################################
1.31 albertel 12648: sub csv_print_samples {
12649: my ($r,$records) = @_;
1.662 bisitz 12650: my $samples = &get_samples($records,5);
1.301 albertel 12651:
1.594 raeburn 12652: $r->print(&mt('Samples').'<br />'.&start_data_table().
12653: &start_data_table_header_row());
1.356 albertel 12654: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12655: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12656: $r->print(&end_data_table_header_row());
1.301 albertel 12657: foreach my $hash (@$samples) {
1.594 raeburn 12658: $r->print(&start_data_table_row());
1.356 albertel 12659: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12660: $r->print('<td>');
1.356 albertel 12661: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12662: $r->print('</td>');
12663: }
1.594 raeburn 12664: $r->print(&end_data_table_row());
1.31 albertel 12665: }
1.594 raeburn 12666: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12667: }
12668:
1.144 matthew 12669: ######################################################
12670: ######################################################
12671:
1.56 matthew 12672: =pod
12673:
1.648 raeburn 12674: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12675:
12676: Prints a table to create associations between values and table columns.
1.144 matthew 12677:
1.41 ng 12678: $r is an Apache Request ref,
12679: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12680: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12681:
12682: =cut
12683:
1.144 matthew 12684: ######################################################
12685: ######################################################
1.31 albertel 12686: sub csv_print_select_table {
12687: my ($r,$records,$d) = @_;
1.301 albertel 12688: my $i=0;
12689: my $samples = &get_samples($records,1);
1.144 matthew 12690: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12691: &start_data_table().&start_data_table_header_row().
1.144 matthew 12692: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12693: '<th>'.&mt('Column').'</th>'.
12694: &end_data_table_header_row()."\n");
1.356 albertel 12695: foreach my $array_ref (@$d) {
12696: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12697: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12698:
1.875 bisitz 12699: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12700: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12701: $r->print('<option value="none"></option>');
1.356 albertel 12702: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12703: $r->print('<option value="'.$sample.'"'.
12704: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12705: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12706: }
1.594 raeburn 12707: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12708: $i++;
12709: }
1.594 raeburn 12710: $r->print(&end_data_table());
1.31 albertel 12711: $i--;
12712: return $i;
12713: }
1.56 matthew 12714:
1.144 matthew 12715: ######################################################
12716: ######################################################
12717:
1.56 matthew 12718: =pod
1.31 albertel 12719:
1.648 raeburn 12720: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12721:
12722: Prints a table of sample values from the upload and can make associate samples to internal names.
12723:
12724: $r is an Apache Request ref,
12725: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12726: $d is an array of 2 element arrays (internal name, displayed name)
12727:
12728: =cut
12729:
1.144 matthew 12730: ######################################################
12731: ######################################################
1.31 albertel 12732: sub csv_samples_select_table {
12733: my ($r,$records,$d) = @_;
12734: my $i=0;
1.144 matthew 12735: #
1.662 bisitz 12736: my $max_samples = 5;
12737: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12738: $r->print(&start_data_table().
12739: &start_data_table_header_row().'<th>'.
12740: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12741: &end_data_table_header_row());
1.301 albertel 12742:
12743: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12744: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12745: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12746: foreach my $option (@$d) {
12747: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12748: $r->print('<option value="'.$value.'"'.
1.253 albertel 12749: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12750: $display.'</option>');
1.31 albertel 12751: }
12752: $r->print('</select></td><td>');
1.662 bisitz 12753: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12754: if (defined($samples->[$line]{$key})) {
12755: $r->print($samples->[$line]{$key}."<br />\n");
12756: }
12757: }
1.594 raeburn 12758: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12759: $i++;
12760: }
1.594 raeburn 12761: $r->print(&end_data_table());
1.31 albertel 12762: $i--;
12763: return($i);
1.115 matthew 12764: }
12765:
1.144 matthew 12766: ######################################################
12767: ######################################################
12768:
1.115 matthew 12769: =pod
12770:
1.648 raeburn 12771: =item * &clean_excel_name($name)
1.115 matthew 12772:
12773: Returns a replacement for $name which does not contain any illegal characters.
12774:
12775: =cut
12776:
1.144 matthew 12777: ######################################################
12778: ######################################################
1.115 matthew 12779: sub clean_excel_name {
12780: my ($name) = @_;
12781: $name =~ s/[:\*\?\/\\]//g;
12782: if (length($name) > 31) {
12783: $name = substr($name,0,31);
12784: }
12785: return $name;
1.25 albertel 12786: }
1.84 albertel 12787:
1.85 albertel 12788: =pod
12789:
1.648 raeburn 12790: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12791:
12792: Returns either 1 or undef
12793:
12794: 1 if the part is to be hidden, undef if it is to be shown
12795:
12796: Arguments are:
12797:
12798: $id the id of the part to be checked
12799: $symb, optional the symb of the resource to check
12800: $udom, optional the domain of the user to check for
12801: $uname, optional the username of the user to check for
12802:
12803: =cut
1.84 albertel 12804:
12805: sub check_if_partid_hidden {
12806: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12807: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12808: $symb,$udom,$uname);
1.141 albertel 12809: my $truth=1;
12810: #if the string starts with !, then the list is the list to show not hide
12811: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12812: my @hiddenlist=split(/,/,$hiddenparts);
12813: foreach my $checkid (@hiddenlist) {
1.141 albertel 12814: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12815: }
1.141 albertel 12816: return !$truth;
1.84 albertel 12817: }
1.127 matthew 12818:
1.138 matthew 12819:
12820: ############################################################
12821: ############################################################
12822:
12823: =pod
12824:
1.157 matthew 12825: =back
12826:
1.138 matthew 12827: =head1 cgi-bin script and graphing routines
12828:
1.157 matthew 12829: =over 4
12830:
1.648 raeburn 12831: =item * &get_cgi_id()
1.138 matthew 12832:
12833: Inputs: none
12834:
12835: Returns an id which can be used to pass environment variables
12836: to various cgi-bin scripts. These environment variables will
12837: be removed from the users environment after a given time by
12838: the routine &Apache::lonnet::transfer_profile_to_env.
12839:
12840: =cut
12841:
12842: ############################################################
12843: ############################################################
1.152 albertel 12844: my $uniq=0;
1.136 matthew 12845: sub get_cgi_id {
1.154 albertel 12846: $uniq=($uniq+1)%100000;
1.280 albertel 12847: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12848: }
12849:
1.127 matthew 12850: ############################################################
12851: ############################################################
12852:
12853: =pod
12854:
1.648 raeburn 12855: =item * &DrawBarGraph()
1.127 matthew 12856:
1.138 matthew 12857: Facilitates the plotting of data in a (stacked) bar graph.
12858: Puts plot definition data into the users environment in order for
12859: graph.png to plot it. Returns an <img> tag for the plot.
12860: The bars on the plot are labeled '1','2',...,'n'.
12861:
12862: Inputs:
12863:
12864: =over 4
12865:
12866: =item $Title: string, the title of the plot
12867:
12868: =item $xlabel: string, text describing the X-axis of the plot
12869:
12870: =item $ylabel: string, text describing the Y-axis of the plot
12871:
12872: =item $Max: scalar, the maximum Y value to use in the plot
12873: If $Max is < any data point, the graph will not be rendered.
12874:
1.140 matthew 12875: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12876: they are plotted. If undefined, default values will be used.
12877:
1.178 matthew 12878: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12879:
1.138 matthew 12880: =item @Values: An array of array references. Each array reference holds data
12881: to be plotted in a stacked bar chart.
12882:
1.239 matthew 12883: =item If the final element of @Values is a hash reference the key/value
12884: pairs will be added to the graph definition.
12885:
1.138 matthew 12886: =back
12887:
12888: Returns:
12889:
12890: An <img> tag which references graph.png and the appropriate identifying
12891: information for the plot.
12892:
1.127 matthew 12893: =cut
12894:
12895: ############################################################
12896: ############################################################
1.134 matthew 12897: sub DrawBarGraph {
1.178 matthew 12898: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12899: #
12900: if (! defined($colors)) {
12901: $colors = ['#33ff00',
12902: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12903: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12904: ];
12905: }
1.228 matthew 12906: my $extra_settings = {};
12907: if (ref($Values[-1]) eq 'HASH') {
12908: $extra_settings = pop(@Values);
12909: }
1.127 matthew 12910: #
1.136 matthew 12911: my $identifier = &get_cgi_id();
12912: my $id = 'cgi.'.$identifier;
1.129 matthew 12913: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12914: return '';
12915: }
1.225 matthew 12916: #
12917: my @Labels;
12918: if (defined($labels)) {
12919: @Labels = @$labels;
12920: } else {
12921: for (my $i=0;$i<@{$Values[0]};$i++) {
12922: push (@Labels,$i+1);
12923: }
12924: }
12925: #
1.129 matthew 12926: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12927: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12928: my %ValuesHash;
12929: my $NumSets=1;
12930: foreach my $array (@Values) {
12931: next if (! ref($array));
1.136 matthew 12932: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12933: join(',',@$array);
1.129 matthew 12934: }
1.127 matthew 12935: #
1.136 matthew 12936: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12937: if ($NumBars < 3) {
12938: $width = 120+$NumBars*32;
1.220 matthew 12939: $xskip = 1;
1.225 matthew 12940: $bar_width = 30;
12941: } elsif ($NumBars < 5) {
12942: $width = 120+$NumBars*20;
12943: $xskip = 1;
12944: $bar_width = 20;
1.220 matthew 12945: } elsif ($NumBars < 10) {
1.136 matthew 12946: $width = 120+$NumBars*15;
12947: $xskip = 1;
12948: $bar_width = 15;
12949: } elsif ($NumBars <= 25) {
12950: $width = 120+$NumBars*11;
12951: $xskip = 5;
12952: $bar_width = 8;
12953: } elsif ($NumBars <= 50) {
12954: $width = 120+$NumBars*8;
12955: $xskip = 5;
12956: $bar_width = 4;
12957: } else {
12958: $width = 120+$NumBars*8;
12959: $xskip = 5;
12960: $bar_width = 4;
12961: }
12962: #
1.137 matthew 12963: $Max = 1 if ($Max < 1);
12964: if ( int($Max) < $Max ) {
12965: $Max++;
12966: $Max = int($Max);
12967: }
1.127 matthew 12968: $Title = '' if (! defined($Title));
12969: $xlabel = '' if (! defined($xlabel));
12970: $ylabel = '' if (! defined($ylabel));
1.369 www 12971: $ValuesHash{$id.'.title'} = &escape($Title);
12972: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12973: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12974: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12975: $ValuesHash{$id.'.NumBars'} = $NumBars;
12976: $ValuesHash{$id.'.NumSets'} = $NumSets;
12977: $ValuesHash{$id.'.PlotType'} = 'bar';
12978: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12979: $ValuesHash{$id.'.height'} = $height;
12980: $ValuesHash{$id.'.width'} = $width;
12981: $ValuesHash{$id.'.xskip'} = $xskip;
12982: $ValuesHash{$id.'.bar_width'} = $bar_width;
12983: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12984: #
1.228 matthew 12985: # Deal with other parameters
12986: while (my ($key,$value) = each(%$extra_settings)) {
12987: $ValuesHash{$id.'.'.$key} = $value;
12988: }
12989: #
1.646 raeburn 12990: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12991: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12992: }
12993:
12994: ############################################################
12995: ############################################################
12996:
12997: =pod
12998:
1.648 raeburn 12999: =item * &DrawXYGraph()
1.137 matthew 13000:
1.138 matthew 13001: Facilitates the plotting of data in an XY graph.
13002: Puts plot definition data into the users environment in order for
13003: graph.png to plot it. Returns an <img> tag for the plot.
13004:
13005: Inputs:
13006:
13007: =over 4
13008:
13009: =item $Title: string, the title of the plot
13010:
13011: =item $xlabel: string, text describing the X-axis of the plot
13012:
13013: =item $ylabel: string, text describing the Y-axis of the plot
13014:
13015: =item $Max: scalar, the maximum Y value to use in the plot
13016: If $Max is < any data point, the graph will not be rendered.
13017:
13018: =item $colors: Array ref containing the hex color codes for the data to be
13019: plotted in. If undefined, default values will be used.
13020:
13021: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13022:
13023: =item $Ydata: Array ref containing Array refs.
1.185 www 13024: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13025:
13026: =item %Values: hash indicating or overriding any default values which are
13027: passed to graph.png.
13028: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13029:
13030: =back
13031:
13032: Returns:
13033:
13034: An <img> tag which references graph.png and the appropriate identifying
13035: information for the plot.
13036:
1.137 matthew 13037: =cut
13038:
13039: ############################################################
13040: ############################################################
13041: sub DrawXYGraph {
13042: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13043: #
13044: # Create the identifier for the graph
13045: my $identifier = &get_cgi_id();
13046: my $id = 'cgi.'.$identifier;
13047: #
13048: $Title = '' if (! defined($Title));
13049: $xlabel = '' if (! defined($xlabel));
13050: $ylabel = '' if (! defined($ylabel));
13051: my %ValuesHash =
13052: (
1.369 www 13053: $id.'.title' => &escape($Title),
13054: $id.'.xlabel' => &escape($xlabel),
13055: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13056: $id.'.y_max_value'=> $Max,
13057: $id.'.labels' => join(',',@$Xlabels),
13058: $id.'.PlotType' => 'XY',
13059: );
13060: #
13061: if (defined($colors) && ref($colors) eq 'ARRAY') {
13062: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13063: }
13064: #
13065: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13066: return '';
13067: }
13068: my $NumSets=1;
1.138 matthew 13069: foreach my $array (@{$Ydata}){
1.137 matthew 13070: next if (! ref($array));
13071: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13072: }
1.138 matthew 13073: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13074: #
13075: # Deal with other parameters
13076: while (my ($key,$value) = each(%Values)) {
13077: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13078: }
13079: #
1.646 raeburn 13080: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13081: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13082: }
13083:
13084: ############################################################
13085: ############################################################
13086:
13087: =pod
13088:
1.648 raeburn 13089: =item * &DrawXYYGraph()
1.138 matthew 13090:
13091: Facilitates the plotting of data in an XY graph with two Y axes.
13092: Puts plot definition data into the users environment in order for
13093: graph.png to plot it. Returns an <img> tag for the plot.
13094:
13095: Inputs:
13096:
13097: =over 4
13098:
13099: =item $Title: string, the title of the plot
13100:
13101: =item $xlabel: string, text describing the X-axis of the plot
13102:
13103: =item $ylabel: string, text describing the Y-axis of the plot
13104:
13105: =item $colors: Array ref containing the hex color codes for the data to be
13106: plotted in. If undefined, default values will be used.
13107:
13108: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13109:
13110: =item $Ydata1: The first data set
13111:
13112: =item $Min1: The minimum value of the left Y-axis
13113:
13114: =item $Max1: The maximum value of the left Y-axis
13115:
13116: =item $Ydata2: The second data set
13117:
13118: =item $Min2: The minimum value of the right Y-axis
13119:
13120: =item $Max2: The maximum value of the left Y-axis
13121:
13122: =item %Values: hash indicating or overriding any default values which are
13123: passed to graph.png.
13124: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13125:
13126: =back
13127:
13128: Returns:
13129:
13130: An <img> tag which references graph.png and the appropriate identifying
13131: information for the plot.
1.136 matthew 13132:
13133: =cut
13134:
13135: ############################################################
13136: ############################################################
1.137 matthew 13137: sub DrawXYYGraph {
13138: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13139: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13140: #
13141: # Create the identifier for the graph
13142: my $identifier = &get_cgi_id();
13143: my $id = 'cgi.'.$identifier;
13144: #
13145: $Title = '' if (! defined($Title));
13146: $xlabel = '' if (! defined($xlabel));
13147: $ylabel = '' if (! defined($ylabel));
13148: my %ValuesHash =
13149: (
1.369 www 13150: $id.'.title' => &escape($Title),
13151: $id.'.xlabel' => &escape($xlabel),
13152: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13153: $id.'.labels' => join(',',@$Xlabels),
13154: $id.'.PlotType' => 'XY',
13155: $id.'.NumSets' => 2,
1.137 matthew 13156: $id.'.two_axes' => 1,
13157: $id.'.y1_max_value' => $Max1,
13158: $id.'.y1_min_value' => $Min1,
13159: $id.'.y2_max_value' => $Max2,
13160: $id.'.y2_min_value' => $Min2,
1.136 matthew 13161: );
13162: #
1.137 matthew 13163: if (defined($colors) && ref($colors) eq 'ARRAY') {
13164: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13165: }
13166: #
13167: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13168: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13169: return '';
13170: }
13171: my $NumSets=1;
1.137 matthew 13172: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13173: next if (! ref($array));
13174: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13175: }
13176: #
13177: # Deal with other parameters
13178: while (my ($key,$value) = each(%Values)) {
13179: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13180: }
13181: #
1.646 raeburn 13182: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13183: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13184: }
13185:
13186: ############################################################
13187: ############################################################
13188:
13189: =pod
13190:
1.157 matthew 13191: =back
13192:
1.139 matthew 13193: =head1 Statistics helper routines?
13194:
13195: Bad place for them but what the hell.
13196:
1.157 matthew 13197: =over 4
13198:
1.648 raeburn 13199: =item * &chartlink()
1.139 matthew 13200:
13201: Returns a link to the chart for a specific student.
13202:
13203: Inputs:
13204:
13205: =over 4
13206:
13207: =item $linktext: The text of the link
13208:
13209: =item $sname: The students username
13210:
13211: =item $sdomain: The students domain
13212:
13213: =back
13214:
1.157 matthew 13215: =back
13216:
1.139 matthew 13217: =cut
13218:
13219: ############################################################
13220: ############################################################
13221: sub chartlink {
13222: my ($linktext, $sname, $sdomain) = @_;
13223: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13224: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13225: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13226: '">'.$linktext.'</a>';
1.153 matthew 13227: }
13228:
13229: #######################################################
13230: #######################################################
13231:
13232: =pod
13233:
13234: =head1 Course Environment Routines
1.157 matthew 13235:
13236: =over 4
1.153 matthew 13237:
1.648 raeburn 13238: =item * &restore_course_settings()
1.153 matthew 13239:
1.648 raeburn 13240: =item * &store_course_settings()
1.153 matthew 13241:
13242: Restores/Store indicated form parameters from the course environment.
13243: Will not overwrite existing values of the form parameters.
13244:
13245: Inputs:
13246: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13247:
13248: a hash ref describing the data to be stored. For example:
13249:
13250: %Save_Parameters = ('Status' => 'scalar',
13251: 'chartoutputmode' => 'scalar',
13252: 'chartoutputdata' => 'scalar',
13253: 'Section' => 'array',
1.373 raeburn 13254: 'Group' => 'array',
1.153 matthew 13255: 'StudentData' => 'array',
13256: 'Maps' => 'array');
13257:
13258: Returns: both routines return nothing
13259:
1.631 raeburn 13260: =back
13261:
1.153 matthew 13262: =cut
13263:
13264: #######################################################
13265: #######################################################
13266: sub store_course_settings {
1.496 albertel 13267: return &store_settings($env{'request.course.id'},@_);
13268: }
13269:
13270: sub store_settings {
1.153 matthew 13271: # save to the environment
13272: # appenv the same items, just to be safe
1.300 albertel 13273: my $udom = $env{'user.domain'};
13274: my $uname = $env{'user.name'};
1.496 albertel 13275: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13276: my %SaveHash;
13277: my %AppHash;
13278: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13279: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13280: my $envname = 'environment.'.$basename;
1.258 albertel 13281: if (exists($env{'form.'.$setting})) {
1.153 matthew 13282: # Save this value away
13283: if ($type eq 'scalar' &&
1.258 albertel 13284: (! exists($env{$envname}) ||
13285: $env{$envname} ne $env{'form.'.$setting})) {
13286: $SaveHash{$basename} = $env{'form.'.$setting};
13287: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13288: } elsif ($type eq 'array') {
13289: my $stored_form;
1.258 albertel 13290: if (ref($env{'form.'.$setting})) {
1.153 matthew 13291: $stored_form = join(',',
13292: map {
1.369 www 13293: &escape($_);
1.258 albertel 13294: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13295: } else {
13296: $stored_form =
1.369 www 13297: &escape($env{'form.'.$setting});
1.153 matthew 13298: }
13299: # Determine if the array contents are the same.
1.258 albertel 13300: if ($stored_form ne $env{$envname}) {
1.153 matthew 13301: $SaveHash{$basename} = $stored_form;
13302: $AppHash{$envname} = $stored_form;
13303: }
13304: }
13305: }
13306: }
13307: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13308: $udom,$uname);
1.153 matthew 13309: if ($put_result !~ /^(ok|delayed)/) {
13310: &Apache::lonnet::logthis('unable to save form parameters, '.
13311: 'got error:'.$put_result);
13312: }
13313: # Make sure these settings stick around in this session, too
1.646 raeburn 13314: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13315: return;
13316: }
13317:
13318: sub restore_course_settings {
1.499 albertel 13319: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13320: }
13321:
13322: sub restore_settings {
13323: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13324: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13325: next if (exists($env{'form.'.$setting}));
1.496 albertel 13326: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13327: '.'.$setting;
1.258 albertel 13328: if (exists($env{$envname})) {
1.153 matthew 13329: if ($type eq 'scalar') {
1.258 albertel 13330: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13331: } elsif ($type eq 'array') {
1.258 albertel 13332: $env{'form.'.$setting} = [
1.153 matthew 13333: map {
1.369 www 13334: &unescape($_);
1.258 albertel 13335: } split(',',$env{$envname})
1.153 matthew 13336: ];
13337: }
13338: }
13339: }
1.127 matthew 13340: }
13341:
1.618 raeburn 13342: #######################################################
13343: #######################################################
13344:
13345: =pod
13346:
13347: =head1 Domain E-mail Routines
13348:
13349: =over 4
13350:
1.648 raeburn 13351: =item * &build_recipient_list()
1.618 raeburn 13352:
1.1075.2.44 raeburn 13353: Build recipient lists for following types of e-mail:
1.766 raeburn 13354: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 13355: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13356: module change checking, student/employee ID conflict checks, as
13357: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13358: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13359:
13360: Inputs:
1.1075.2.44 raeburn 13361: defmail (scalar - email address of default recipient),
13362: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13363: requestsmail, updatesmail, or idconflictsmail).
13364:
1.619 raeburn 13365: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 13366:
13367: origmail (scalar - email address of recipient from loncapa.conf,
13368: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13369:
1.655 raeburn 13370: Returns: comma separated list of addresses to which to send e-mail.
13371:
13372: =back
1.618 raeburn 13373:
13374: =cut
13375:
13376: ############################################################
13377: ############################################################
13378: sub build_recipient_list {
1.619 raeburn 13379: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13380: my @recipients;
13381: my $otheremails;
13382: my %domconfig =
13383: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13384: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13385: if (exists($domconfig{'contacts'}{$mailing})) {
13386: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13387: my @contacts = ('adminemail','supportemail');
13388: foreach my $item (@contacts) {
13389: if ($domconfig{'contacts'}{$mailing}{$item}) {
13390: my $addr = $domconfig{'contacts'}{$item};
13391: if (!grep(/^\Q$addr\E$/,@recipients)) {
13392: push(@recipients,$addr);
13393: }
1.619 raeburn 13394: }
1.766 raeburn 13395: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13396: }
13397: }
1.766 raeburn 13398: } elsif ($origmail ne '') {
13399: push(@recipients,$origmail);
1.618 raeburn 13400: }
1.619 raeburn 13401: } elsif ($origmail ne '') {
13402: push(@recipients,$origmail);
1.618 raeburn 13403: }
1.688 raeburn 13404: if (defined($defmail)) {
13405: if ($defmail ne '') {
13406: push(@recipients,$defmail);
13407: }
1.618 raeburn 13408: }
13409: if ($otheremails) {
1.619 raeburn 13410: my @others;
13411: if ($otheremails =~ /,/) {
13412: @others = split(/,/,$otheremails);
1.618 raeburn 13413: } else {
1.619 raeburn 13414: push(@others,$otheremails);
13415: }
13416: foreach my $addr (@others) {
13417: if (!grep(/^\Q$addr\E$/,@recipients)) {
13418: push(@recipients,$addr);
13419: }
1.618 raeburn 13420: }
13421: }
1.619 raeburn 13422: my $recipientlist = join(',',@recipients);
1.618 raeburn 13423: return $recipientlist;
13424: }
13425:
1.127 matthew 13426: ############################################################
13427: ############################################################
1.154 albertel 13428:
1.655 raeburn 13429: =pod
13430:
13431: =head1 Course Catalog Routines
13432:
13433: =over 4
13434:
13435: =item * &gather_categories()
13436:
13437: Converts category definitions - keys of categories hash stored in
13438: coursecategories in configuration.db on the primary library server in a
13439: domain - to an array. Also generates javascript and idx hash used to
13440: generate Domain Coordinator interface for editing Course Categories.
13441:
13442: Inputs:
1.663 raeburn 13443:
1.655 raeburn 13444: categories (reference to hash of category definitions).
1.663 raeburn 13445:
1.655 raeburn 13446: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13447: categories and subcategories).
1.663 raeburn 13448:
1.655 raeburn 13449: idx (reference to hash of counters used in Domain Coordinator interface for
13450: editing Course Categories).
1.663 raeburn 13451:
1.655 raeburn 13452: jsarray (reference to array of categories used to create Javascript arrays for
13453: Domain Coordinator interface for editing Course Categories).
13454:
13455: Returns: nothing
13456:
13457: Side effects: populates cats, idx and jsarray.
13458:
13459: =cut
13460:
13461: sub gather_categories {
13462: my ($categories,$cats,$idx,$jsarray) = @_;
13463: my %counters;
13464: my $num = 0;
13465: foreach my $item (keys(%{$categories})) {
13466: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13467: if ($container eq '' && $depth == 0) {
13468: $cats->[$depth][$categories->{$item}] = $cat;
13469: } else {
13470: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13471: }
13472: my ($escitem,$tail) = split(/:/,$item,2);
13473: if ($counters{$tail} eq '') {
13474: $counters{$tail} = $num;
13475: $num ++;
13476: }
13477: if (ref($idx) eq 'HASH') {
13478: $idx->{$item} = $counters{$tail};
13479: }
13480: if (ref($jsarray) eq 'ARRAY') {
13481: push(@{$jsarray->[$counters{$tail}]},$item);
13482: }
13483: }
13484: return;
13485: }
13486:
13487: =pod
13488:
13489: =item * &extract_categories()
13490:
13491: Used to generate breadcrumb trails for course categories.
13492:
13493: Inputs:
1.663 raeburn 13494:
1.655 raeburn 13495: categories (reference to hash of category definitions).
1.663 raeburn 13496:
1.655 raeburn 13497: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13498: categories and subcategories).
1.663 raeburn 13499:
1.655 raeburn 13500: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13501:
1.655 raeburn 13502: allitems (reference to hash - key is category key
13503: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13504:
1.655 raeburn 13505: idx (reference to hash of counters used in Domain Coordinator interface for
13506: editing Course Categories).
1.663 raeburn 13507:
1.655 raeburn 13508: jsarray (reference to array of categories used to create Javascript arrays for
13509: Domain Coordinator interface for editing Course Categories).
13510:
1.665 raeburn 13511: subcats (reference to hash of arrays containing all subcategories within each
13512: category, -recursive)
13513:
1.655 raeburn 13514: Returns: nothing
13515:
13516: Side effects: populates trails and allitems hash references.
13517:
13518: =cut
13519:
13520: sub extract_categories {
1.665 raeburn 13521: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13522: if (ref($categories) eq 'HASH') {
13523: &gather_categories($categories,$cats,$idx,$jsarray);
13524: if (ref($cats->[0]) eq 'ARRAY') {
13525: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13526: my $name = $cats->[0][$i];
13527: my $item = &escape($name).'::0';
13528: my $trailstr;
13529: if ($name eq 'instcode') {
13530: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13531: } elsif ($name eq 'communities') {
13532: $trailstr = &mt('Communities');
1.655 raeburn 13533: } else {
13534: $trailstr = $name;
13535: }
13536: if ($allitems->{$item} eq '') {
13537: push(@{$trails},$trailstr);
13538: $allitems->{$item} = scalar(@{$trails})-1;
13539: }
13540: my @parents = ($name);
13541: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13542: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13543: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13544: if (ref($subcats) eq 'HASH') {
13545: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13546: }
13547: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13548: }
13549: } else {
13550: if (ref($subcats) eq 'HASH') {
13551: $subcats->{$item} = [];
1.655 raeburn 13552: }
13553: }
13554: }
13555: }
13556: }
13557: return;
13558: }
13559:
13560: =pod
13561:
1.1075.2.56 raeburn 13562: =item * &recurse_categories()
1.655 raeburn 13563:
13564: Recursively used to generate breadcrumb trails for course categories.
13565:
13566: Inputs:
1.663 raeburn 13567:
1.655 raeburn 13568: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13569: categories and subcategories).
1.663 raeburn 13570:
1.655 raeburn 13571: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13572:
13573: category (current course category, for which breadcrumb trail is being generated).
13574:
13575: trails (reference to array of breadcrumb trails for each category).
13576:
1.655 raeburn 13577: allitems (reference to hash - key is category key
13578: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13579:
1.655 raeburn 13580: parents (array containing containers directories for current category,
13581: back to top level).
13582:
13583: Returns: nothing
13584:
13585: Side effects: populates trails and allitems hash references
13586:
13587: =cut
13588:
13589: sub recurse_categories {
1.665 raeburn 13590: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13591: my $shallower = $depth - 1;
13592: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13593: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13594: my $name = $cats->[$depth]{$category}[$k];
13595: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13596: my $trailstr = join(' -> ',(@{$parents},$category));
13597: if ($allitems->{$item} eq '') {
13598: push(@{$trails},$trailstr);
13599: $allitems->{$item} = scalar(@{$trails})-1;
13600: }
13601: my $deeper = $depth+1;
13602: push(@{$parents},$category);
1.665 raeburn 13603: if (ref($subcats) eq 'HASH') {
13604: my $subcat = &escape($name).':'.$category.':'.$depth;
13605: for (my $j=@{$parents}; $j>=0; $j--) {
13606: my $higher;
13607: if ($j > 0) {
13608: $higher = &escape($parents->[$j]).':'.
13609: &escape($parents->[$j-1]).':'.$j;
13610: } else {
13611: $higher = &escape($parents->[$j]).'::'.$j;
13612: }
13613: push(@{$subcats->{$higher}},$subcat);
13614: }
13615: }
13616: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13617: $subcats);
1.655 raeburn 13618: pop(@{$parents});
13619: }
13620: } else {
13621: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13622: my $trailstr = join(' -> ',(@{$parents},$category));
13623: if ($allitems->{$item} eq '') {
13624: push(@{$trails},$trailstr);
13625: $allitems->{$item} = scalar(@{$trails})-1;
13626: }
13627: }
13628: return;
13629: }
13630:
1.663 raeburn 13631: =pod
13632:
1.1075.2.56 raeburn 13633: =item * &assign_categories_table()
1.663 raeburn 13634:
13635: Create a datatable for display of hierarchical categories in a domain,
13636: with checkboxes to allow a course to be categorized.
13637:
13638: Inputs:
13639:
13640: cathash - reference to hash of categories defined for the domain (from
13641: configuration.db)
13642:
13643: currcat - scalar with an & separated list of categories assigned to a course.
13644:
1.919 raeburn 13645: type - scalar contains course type (Course or Community).
13646:
1.663 raeburn 13647: Returns: $output (markup to be displayed)
13648:
13649: =cut
13650:
13651: sub assign_categories_table {
1.919 raeburn 13652: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13653: my $output;
13654: if (ref($cathash) eq 'HASH') {
13655: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13656: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13657: $maxdepth = scalar(@cats);
13658: if (@cats > 0) {
13659: my $itemcount = 0;
13660: if (ref($cats[0]) eq 'ARRAY') {
13661: my @currcategories;
13662: if ($currcat ne '') {
13663: @currcategories = split('&',$currcat);
13664: }
1.919 raeburn 13665: my $table;
1.663 raeburn 13666: for (my $i=0; $i<@{$cats[0]}; $i++) {
13667: my $parent = $cats[0][$i];
1.919 raeburn 13668: next if ($parent eq 'instcode');
13669: if ($type eq 'Community') {
13670: next unless ($parent eq 'communities');
13671: } else {
13672: next if ($parent eq 'communities');
13673: }
1.663 raeburn 13674: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13675: my $item = &escape($parent).'::0';
13676: my $checked = '';
13677: if (@currcategories > 0) {
13678: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13679: $checked = ' checked="checked"';
1.663 raeburn 13680: }
13681: }
1.919 raeburn 13682: my $parent_title = $parent;
13683: if ($parent eq 'communities') {
13684: $parent_title = &mt('Communities');
13685: }
13686: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13687: '<input type="checkbox" name="usecategory" value="'.
13688: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13689: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13690: my $depth = 1;
13691: push(@path,$parent);
1.919 raeburn 13692: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13693: pop(@path);
1.919 raeburn 13694: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13695: $itemcount ++;
13696: }
1.919 raeburn 13697: if ($itemcount) {
13698: $output = &Apache::loncommon::start_data_table().
13699: $table.
13700: &Apache::loncommon::end_data_table();
13701: }
1.663 raeburn 13702: }
13703: }
13704: }
13705: return $output;
13706: }
13707:
13708: =pod
13709:
1.1075.2.56 raeburn 13710: =item * &assign_category_rows()
1.663 raeburn 13711:
13712: Create a datatable row for display of nested categories in a domain,
13713: with checkboxes to allow a course to be categorized,called recursively.
13714:
13715: Inputs:
13716:
13717: itemcount - track row number for alternating colors
13718:
13719: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13720: categories and subcategories.
13721:
13722: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13723:
13724: parent - parent of current category item
13725:
13726: path - Array containing all categories back up through the hierarchy from the
13727: current category to the top level.
13728:
13729: currcategories - reference to array of current categories assigned to the course
13730:
13731: Returns: $output (markup to be displayed).
13732:
13733: =cut
13734:
13735: sub assign_category_rows {
13736: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13737: my ($text,$name,$item,$chgstr);
13738: if (ref($cats) eq 'ARRAY') {
13739: my $maxdepth = scalar(@{$cats});
13740: if (ref($cats->[$depth]) eq 'HASH') {
13741: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13742: my $numchildren = @{$cats->[$depth]{$parent}};
13743: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 13744: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13745: for (my $j=0; $j<$numchildren; $j++) {
13746: $name = $cats->[$depth]{$parent}[$j];
13747: $item = &escape($name).':'.&escape($parent).':'.$depth;
13748: my $deeper = $depth+1;
13749: my $checked = '';
13750: if (ref($currcategories) eq 'ARRAY') {
13751: if (@{$currcategories} > 0) {
13752: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13753: $checked = ' checked="checked"';
1.663 raeburn 13754: }
13755: }
13756: }
1.664 raeburn 13757: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13758: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13759: $item.'"'.$checked.' />'.$name.'</label></span>'.
13760: '<input type="hidden" name="catname" value="'.$name.'" />'.
13761: '</td><td>';
1.663 raeburn 13762: if (ref($path) eq 'ARRAY') {
13763: push(@{$path},$name);
13764: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13765: pop(@{$path});
13766: }
13767: $text .= '</td></tr>';
13768: }
13769: $text .= '</table></td>';
13770: }
13771: }
13772: }
13773: return $text;
13774: }
13775:
1.1075.2.69 raeburn 13776: =pod
13777:
13778: =back
13779:
13780: =cut
13781:
1.655 raeburn 13782: ############################################################
13783: ############################################################
13784:
13785:
1.443 albertel 13786: sub commit_customrole {
1.664 raeburn 13787: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13788: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13789: ($start?', '.&mt('starting').' '.localtime($start):'').
13790: ($end?', ending '.localtime($end):'').': <b>'.
13791: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13792: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13793: '</b><br />';
13794: return $output;
13795: }
13796:
13797: sub commit_standardrole {
1.1075.2.31 raeburn 13798: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13799: my ($output,$logmsg,$linefeed);
13800: if ($context eq 'auto') {
13801: $linefeed = "\n";
13802: } else {
13803: $linefeed = "<br />\n";
13804: }
1.443 albertel 13805: if ($three eq 'st') {
1.541 raeburn 13806: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 13807: $one,$two,$sec,$context,$credits);
1.541 raeburn 13808: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13809: ($result eq 'unknown_course') || ($result eq 'refused')) {
13810: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13811: } else {
1.541 raeburn 13812: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13813: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13814: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13815: if ($context eq 'auto') {
13816: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13817: } else {
13818: $output .= '<b>'.$result.'</b>'.$linefeed.
13819: &mt('Add to classlist').': <b>ok</b>';
13820: }
13821: $output .= $linefeed;
1.443 albertel 13822: }
13823: } else {
13824: $output = &mt('Assigning').' '.$three.' in '.$url.
13825: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13826: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13827: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13828: if ($context eq 'auto') {
13829: $output .= $result.$linefeed;
13830: } else {
13831: $output .= '<b>'.$result.'</b>'.$linefeed;
13832: }
1.443 albertel 13833: }
13834: return $output;
13835: }
13836:
13837: sub commit_studentrole {
1.1075.2.31 raeburn 13838: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13839: $credits) = @_;
1.626 raeburn 13840: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13841: if ($context eq 'auto') {
13842: $linefeed = "\n";
13843: } else {
13844: $linefeed = '<br />'."\n";
13845: }
1.443 albertel 13846: if (defined($one) && defined($two)) {
13847: my $cid=$one.'_'.$two;
13848: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13849: my $secchange = 0;
13850: my $expire_role_result;
13851: my $modify_section_result;
1.628 raeburn 13852: if ($oldsec ne '-1') {
13853: if ($oldsec ne $sec) {
1.443 albertel 13854: $secchange = 1;
1.628 raeburn 13855: my $now = time;
1.443 albertel 13856: my $uurl='/'.$cid;
13857: $uurl=~s/\_/\//g;
13858: if ($oldsec) {
13859: $uurl.='/'.$oldsec;
13860: }
1.626 raeburn 13861: $oldsecurl = $uurl;
1.628 raeburn 13862: $expire_role_result =
1.652 raeburn 13863: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13864: if ($env{'request.course.sec'} ne '') {
13865: if ($expire_role_result eq 'refused') {
13866: my @roles = ('st');
13867: my @statuses = ('previous');
13868: my @roledoms = ($one);
13869: my $withsec = 1;
13870: my %roleshash =
13871: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13872: \@statuses,\@roles,\@roledoms,$withsec);
13873: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13874: my ($oldstart,$oldend) =
13875: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13876: if ($oldend > 0 && $oldend <= $now) {
13877: $expire_role_result = 'ok';
13878: }
13879: }
13880: }
13881: }
1.443 albertel 13882: $result = $expire_role_result;
13883: }
13884: }
13885: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 13886: $modify_section_result =
13887: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13888: undef,undef,undef,$sec,
13889: $end,$start,'','',$cid,
13890: '',$context,$credits);
1.443 albertel 13891: if ($modify_section_result =~ /^ok/) {
13892: if ($secchange == 1) {
1.628 raeburn 13893: if ($sec eq '') {
13894: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13895: } else {
13896: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13897: }
1.443 albertel 13898: } elsif ($oldsec eq '-1') {
1.628 raeburn 13899: if ($sec eq '') {
13900: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13901: } else {
13902: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13903: }
1.443 albertel 13904: } else {
1.628 raeburn 13905: if ($sec eq '') {
13906: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13907: } else {
13908: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13909: }
1.443 albertel 13910: }
13911: } else {
1.628 raeburn 13912: if ($secchange) {
13913: $$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;
13914: } else {
13915: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13916: }
1.443 albertel 13917: }
13918: $result = $modify_section_result;
13919: } elsif ($secchange == 1) {
1.628 raeburn 13920: if ($oldsec eq '') {
1.1075.2.20 raeburn 13921: $$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 13922: } else {
13923: $$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;
13924: }
1.626 raeburn 13925: if ($expire_role_result eq 'refused') {
13926: my $newsecurl = '/'.$cid;
13927: $newsecurl =~ s/\_/\//g;
13928: if ($sec ne '') {
13929: $newsecurl.='/'.$sec;
13930: }
13931: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13932: if ($sec eq '') {
13933: $$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;
13934: } else {
13935: $$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;
13936: }
13937: }
13938: }
1.443 albertel 13939: }
13940: } else {
1.626 raeburn 13941: $$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 13942: $result = "error: incomplete course id\n";
13943: }
13944: return $result;
13945: }
13946:
1.1075.2.25 raeburn 13947: sub show_role_extent {
13948: my ($scope,$context,$role) = @_;
13949: $scope =~ s{^/}{};
13950: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13951: push(@courseroles,'co');
13952: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13953: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13954: $scope =~ s{/}{_};
13955: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13956: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13957: my ($audom,$auname) = split(/\//,$scope);
13958: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13959: &Apache::loncommon::plainname($auname,$audom).'</span>');
13960: } else {
13961: $scope =~ s{/$}{};
13962: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13963: &Apache::lonnet::domain($scope,'description').'</span>');
13964: }
13965: }
13966:
1.443 albertel 13967: ############################################################
13968: ############################################################
13969:
1.566 albertel 13970: sub check_clone {
1.578 raeburn 13971: my ($args,$linefeed) = @_;
1.566 albertel 13972: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13973: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13974: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13975: my $clonemsg;
13976: my $can_clone = 0;
1.944 raeburn 13977: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13978: if ($lctype ne 'community') {
13979: $lctype = 'course';
13980: }
1.566 albertel 13981: if ($clonehome eq 'no_host') {
1.944 raeburn 13982: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13983: $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'});
13984: } else {
13985: $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'});
13986: }
1.566 albertel 13987: } else {
13988: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13989: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13990: if ($clonedesc{'type'} ne 'Community') {
13991: $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'});
13992: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13993: }
13994: }
1.882 raeburn 13995: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13996: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13997: $can_clone = 1;
13998: } else {
13999: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
14000: $args->{'clonedomain'},$args->{'clonecourse'});
14001: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 14002: if (grep(/^\*$/,@cloners)) {
14003: $can_clone = 1;
14004: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
14005: $can_clone = 1;
14006: } else {
1.908 raeburn 14007: my $ccrole = 'cc';
1.944 raeburn 14008: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14009: $ccrole = 'co';
14010: }
1.578 raeburn 14011: my %roleshash =
14012: &Apache::lonnet::get_my_roles($args->{'ccuname'},
14013: $args->{'ccdomain'},
1.908 raeburn 14014: 'userroles',['active'],[$ccrole],
1.578 raeburn 14015: [$args->{'clonedomain'}]);
1.908 raeburn 14016: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 14017: $can_clone = 1;
14018: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
14019: $can_clone = 1;
14020: } else {
1.944 raeburn 14021: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14022: $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'});
14023: } else {
14024: $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'});
14025: }
1.578 raeburn 14026: }
1.566 albertel 14027: }
1.578 raeburn 14028: }
1.566 albertel 14029: }
14030: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14031: }
14032:
1.444 albertel 14033: sub construct_course {
1.1075.2.59 raeburn 14034: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 14035: my $outcome;
1.541 raeburn 14036: my $linefeed = '<br />'."\n";
14037: if ($context eq 'auto') {
14038: $linefeed = "\n";
14039: }
1.566 albertel 14040:
14041: #
14042: # Are we cloning?
14043: #
14044: my ($can_clone, $clonemsg, $cloneid, $clonehome);
14045: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 14046: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 14047: if ($context ne 'auto') {
1.578 raeburn 14048: if ($clonemsg ne '') {
14049: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
14050: }
1.566 albertel 14051: }
14052: $outcome .= $clonemsg.$linefeed;
14053:
14054: if (!$can_clone) {
14055: return (0,$outcome);
14056: }
14057: }
14058:
1.444 albertel 14059: #
14060: # Open course
14061: #
14062: my $crstype = lc($args->{'crstype'});
14063: my %cenv=();
14064: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
14065: $args->{'cdescr'},
14066: $args->{'curl'},
14067: $args->{'course_home'},
14068: $args->{'nonstandard'},
14069: $args->{'crscode'},
14070: $args->{'ccuname'}.':'.
14071: $args->{'ccdomain'},
1.882 raeburn 14072: $args->{'crstype'},
1.885 raeburn 14073: $cnum,$context,$category);
1.444 albertel 14074:
14075: # Note: The testing routines depend on this being output; see
14076: # Utils::Course. This needs to at least be output as a comment
14077: # if anyone ever decides to not show this, and Utils::Course::new
14078: # will need to be suitably modified.
1.541 raeburn 14079: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 14080: if ($$courseid =~ /^error:/) {
14081: return (0,$outcome);
14082: }
14083:
1.444 albertel 14084: #
14085: # Check if created correctly
14086: #
1.479 albertel 14087: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 14088: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 14089: if ($crsuhome eq 'no_host') {
14090: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
14091: return (0,$outcome);
14092: }
1.541 raeburn 14093: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 14094:
1.444 albertel 14095: #
1.566 albertel 14096: # Do the cloning
14097: #
14098: if ($can_clone && $cloneid) {
14099: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14100: if ($context ne 'auto') {
14101: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14102: }
14103: $outcome .= $clonemsg.$linefeed;
14104: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14105: # Copy all files
1.637 www 14106: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14107: # Restore URL
1.566 albertel 14108: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14109: # Restore title
1.566 albertel 14110: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14111: # Restore creation date, creator and creation context.
14112: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14113: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14114: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14115: # Mark as cloned
1.566 albertel 14116: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14117: # Need to clone grading mode
14118: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14119: $cenv{'grading'}=$newenv{'grading'};
14120: # Do not clone these environment entries
14121: &Apache::lonnet::del('environment',
14122: ['default_enrollment_start_date',
14123: 'default_enrollment_end_date',
14124: 'question.email',
14125: 'policy.email',
14126: 'comment.email',
14127: 'pch.users.denied',
1.725 raeburn 14128: 'plc.users.denied',
14129: 'hidefromcat',
1.1075.2.36 raeburn 14130: 'checkforpriv',
1.1075.2.59 raeburn 14131: 'categories',
14132: 'internal.uniquecode'],
1.638 www 14133: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 14134: if ($args->{'textbook'}) {
14135: $cenv{'internal.textbook'} = $args->{'textbook'};
14136: }
1.444 albertel 14137: }
1.566 albertel 14138:
1.444 albertel 14139: #
14140: # Set environment (will override cloned, if existing)
14141: #
14142: my @sections = ();
14143: my @xlists = ();
14144: if ($args->{'crstype'}) {
14145: $cenv{'type'}=$args->{'crstype'};
14146: }
14147: if ($args->{'crsid'}) {
14148: $cenv{'courseid'}=$args->{'crsid'};
14149: }
14150: if ($args->{'crscode'}) {
14151: $cenv{'internal.coursecode'}=$args->{'crscode'};
14152: }
14153: if ($args->{'crsquota'} ne '') {
14154: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14155: } else {
14156: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14157: }
14158: if ($args->{'ccuname'}) {
14159: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14160: ':'.$args->{'ccdomain'};
14161: } else {
14162: $cenv{'internal.courseowner'} = $args->{'curruser'};
14163: }
1.1075.2.31 raeburn 14164: if ($args->{'defaultcredits'}) {
14165: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14166: }
1.444 albertel 14167: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14168: if ($args->{'crssections'}) {
14169: $cenv{'internal.sectionnums'} = '';
14170: if ($args->{'crssections'} =~ m/,/) {
14171: @sections = split/,/,$args->{'crssections'};
14172: } else {
14173: $sections[0] = $args->{'crssections'};
14174: }
14175: if (@sections > 0) {
14176: foreach my $item (@sections) {
14177: my ($sec,$gp) = split/:/,$item;
14178: my $class = $args->{'crscode'}.$sec;
14179: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14180: $cenv{'internal.sectionnums'} .= $item.',';
14181: unless ($addcheck eq 'ok') {
14182: push @badclasses, $class;
14183: }
14184: }
14185: $cenv{'internal.sectionnums'} =~ s/,$//;
14186: }
14187: }
14188: # do not hide course coordinator from staff listing,
14189: # even if privileged
14190: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 14191: # add course coordinator's domain to domains to check for privileged users
14192: # if different to course domain
14193: if ($$crsudom ne $args->{'ccdomain'}) {
14194: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14195: }
1.444 albertel 14196: # add crosslistings
14197: if ($args->{'crsxlist'}) {
14198: $cenv{'internal.crosslistings'}='';
14199: if ($args->{'crsxlist'} =~ m/,/) {
14200: @xlists = split/,/,$args->{'crsxlist'};
14201: } else {
14202: $xlists[0] = $args->{'crsxlist'};
14203: }
14204: if (@xlists > 0) {
14205: foreach my $item (@xlists) {
14206: my ($xl,$gp) = split/:/,$item;
14207: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14208: $cenv{'internal.crosslistings'} .= $item.',';
14209: unless ($addcheck eq 'ok') {
14210: push @badclasses, $xl;
14211: }
14212: }
14213: $cenv{'internal.crosslistings'} =~ s/,$//;
14214: }
14215: }
14216: if ($args->{'autoadds'}) {
14217: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14218: }
14219: if ($args->{'autodrops'}) {
14220: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14221: }
14222: # check for notification of enrollment changes
14223: my @notified = ();
14224: if ($args->{'notify_owner'}) {
14225: if ($args->{'ccuname'} ne '') {
14226: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14227: }
14228: }
14229: if ($args->{'notify_dc'}) {
14230: if ($uname ne '') {
1.630 raeburn 14231: push(@notified,$uname.':'.$udom);
1.444 albertel 14232: }
14233: }
14234: if (@notified > 0) {
14235: my $notifylist;
14236: if (@notified > 1) {
14237: $notifylist = join(',',@notified);
14238: } else {
14239: $notifylist = $notified[0];
14240: }
14241: $cenv{'internal.notifylist'} = $notifylist;
14242: }
14243: if (@badclasses > 0) {
14244: my %lt=&Apache::lonlocal::texthash(
14245: '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',
14246: 'dnhr' => 'does not have rights to access enrollment in these classes',
14247: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14248: );
1.541 raeburn 14249: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14250: ' ('.$lt{'adby'}.')';
14251: if ($context eq 'auto') {
14252: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14253: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14254: foreach my $item (@badclasses) {
14255: if ($context eq 'auto') {
14256: $outcome .= " - $item\n";
14257: } else {
14258: $outcome .= "<li>$item</li>\n";
14259: }
14260: }
14261: if ($context eq 'auto') {
14262: $outcome .= $linefeed;
14263: } else {
1.566 albertel 14264: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14265: }
14266: }
1.444 albertel 14267: }
14268: if ($args->{'no_end_date'}) {
14269: $args->{'endaccess'} = 0;
14270: }
14271: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14272: $cenv{'internal.autoend'}=$args->{'enrollend'};
14273: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14274: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14275: if ($args->{'showphotos'}) {
14276: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14277: }
14278: $cenv{'internal.authtype'} = $args->{'authtype'};
14279: $cenv{'internal.autharg'} = $args->{'autharg'};
14280: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14281: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14282: 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');
14283: if ($context eq 'auto') {
14284: $outcome .= $krb_msg;
14285: } else {
1.566 albertel 14286: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14287: }
14288: $outcome .= $linefeed;
1.444 albertel 14289: }
14290: }
14291: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14292: if ($args->{'setpolicy'}) {
14293: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14294: }
14295: if ($args->{'setcontent'}) {
14296: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14297: }
14298: }
14299: if ($args->{'reshome'}) {
14300: $cenv{'reshome'}=$args->{'reshome'}.'/';
14301: $cenv{'reshome'}=~s/\/+$/\//;
14302: }
14303: #
14304: # course has keyed access
14305: #
14306: if ($args->{'setkeys'}) {
14307: $cenv{'keyaccess'}='yes';
14308: }
14309: # if specified, key authority is not course, but user
14310: # only active if keyaccess is yes
14311: if ($args->{'keyauth'}) {
1.487 albertel 14312: my ($user,$domain) = split(':',$args->{'keyauth'});
14313: $user = &LONCAPA::clean_username($user);
14314: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14315: if ($user ne '' && $domain ne '') {
1.487 albertel 14316: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14317: }
14318: }
14319:
1.1075.2.59 raeburn 14320: #
14321: # generate and store uniquecode (available to course requester), if course should have one.
14322: #
14323: if ($args->{'uniquecode'}) {
14324: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14325: if ($code) {
14326: $cenv{'internal.uniquecode'} = $code;
14327: my %crsinfo =
14328: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
14329: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
14330: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
14331: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
14332: }
14333: if (ref($coderef)) {
14334: $$coderef = $code;
14335: }
14336: }
14337: }
14338:
1.444 albertel 14339: if ($args->{'disresdis'}) {
14340: $cenv{'pch.roles.denied'}='st';
14341: }
14342: if ($args->{'disablechat'}) {
14343: $cenv{'plc.roles.denied'}='st';
14344: }
14345:
14346: # Record we've not yet viewed the Course Initialization Helper for this
14347: # course
14348: $cenv{'course.helper.not.run'} = 1;
14349: #
14350: # Use new Randomseed
14351: #
14352: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14353: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14354: #
14355: # The encryption code and receipt prefix for this course
14356: #
14357: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14358: $cenv{'internal.encpref'}=100+int(9*rand(99));
14359: #
14360: # By default, use standard grading
14361: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14362:
1.541 raeburn 14363: $outcome .= $linefeed.&mt('Setting environment').': '.
14364: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14365: #
14366: # Open all assignments
14367: #
14368: if ($args->{'openall'}) {
14369: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14370: my %storecontent = ($storeunder => time,
14371: $storeunder.'.type' => 'date_start');
14372:
14373: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14374: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14375: }
14376: #
14377: # Set first page
14378: #
14379: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14380: || ($cloneid)) {
1.445 albertel 14381: use LONCAPA::map;
1.444 albertel 14382: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14383:
14384: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14385: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14386:
1.444 albertel 14387: $outcome .= ($fatal?$errtext:'read ok').' - ';
14388: my $title; my $url;
14389: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14390: $title=&mt('Syllabus');
1.444 albertel 14391: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14392: } else {
1.963 raeburn 14393: $title=&mt('Table of Contents');
1.444 albertel 14394: $url='/adm/navmaps';
14395: }
1.445 albertel 14396:
14397: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14398: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14399:
14400: if ($errtext) { $fatal=2; }
1.541 raeburn 14401: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14402: }
1.566 albertel 14403:
14404: return (1,$outcome);
1.444 albertel 14405: }
14406:
1.1075.2.59 raeburn 14407: sub make_unique_code {
14408: my ($cdom,$cnum) = @_;
14409: # get lock on uniquecodes db
14410: my $lockhash = {
14411: $cnum."\0".'uniquecodes' => $env{'user.name'}.
14412: ':'.$env{'user.domain'},
14413: };
14414: my $tries = 0;
14415: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14416: my ($code,$error);
14417:
14418: while (($gotlock ne 'ok') && ($tries<3)) {
14419: $tries ++;
14420: sleep 1;
14421: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14422: }
14423: if ($gotlock eq 'ok') {
14424: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
14425: my $gotcode;
14426: my $attempts = 0;
14427: while ((!$gotcode) && ($attempts < 100)) {
14428: $code = &generate_code();
14429: if (!exists($currcodes{$code})) {
14430: $gotcode = 1;
14431: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
14432: $error = 'nostore';
14433: }
14434: }
14435: $attempts ++;
14436: }
14437: my @del_lock = ($cnum."\0".'uniquecodes');
14438: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
14439: } else {
14440: $error = 'nolock';
14441: }
14442: return ($code,$error);
14443: }
14444:
14445: sub generate_code {
14446: my $code;
14447: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
14448: for (my $i=0; $i<6; $i++) {
14449: my $lettnum = int (rand 2);
14450: my $item = '';
14451: if ($lettnum) {
14452: $item = $letts[int( rand(18) )];
14453: } else {
14454: $item = 1+int( rand(8) );
14455: }
14456: $code .= $item;
14457: }
14458: return $code;
14459: }
14460:
1.444 albertel 14461: ############################################################
14462: ############################################################
14463:
1.953 droeschl 14464: #SD
14465: # only Community and Course, or anything else?
1.378 raeburn 14466: sub course_type {
14467: my ($cid) = @_;
14468: if (!defined($cid)) {
14469: $cid = $env{'request.course.id'};
14470: }
1.404 albertel 14471: if (defined($env{'course.'.$cid.'.type'})) {
14472: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14473: } else {
14474: return 'Course';
1.377 raeburn 14475: }
14476: }
1.156 albertel 14477:
1.406 raeburn 14478: sub group_term {
14479: my $crstype = &course_type();
14480: my %names = (
14481: 'Course' => 'group',
1.865 raeburn 14482: 'Community' => 'group',
1.406 raeburn 14483: );
14484: return $names{$crstype};
14485: }
14486:
1.902 raeburn 14487: sub course_types {
1.1075.2.59 raeburn 14488: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 14489: my %typename = (
14490: official => 'Official course',
14491: unofficial => 'Unofficial course',
14492: community => 'Community',
1.1075.2.59 raeburn 14493: textbook => 'Textbook course',
1.902 raeburn 14494: );
14495: return (\@types,\%typename);
14496: }
14497:
1.156 albertel 14498: sub icon {
14499: my ($file)=@_;
1.505 albertel 14500: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14501: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14502: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14503: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14504: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14505: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14506: $curfext.".gif") {
14507: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14508: $curfext.".gif";
14509: }
14510: }
1.249 albertel 14511: return &lonhttpdurl($iconname);
1.154 albertel 14512: }
1.84 albertel 14513:
1.575 albertel 14514: sub lonhttpdurl {
1.692 www 14515: #
14516: # Had been used for "small fry" static images on separate port 8080.
14517: # Modify here if lightweight http functionality desired again.
14518: # Currently eliminated due to increasing firewall issues.
14519: #
1.575 albertel 14520: my ($url)=@_;
1.692 www 14521: return $url;
1.215 albertel 14522: }
14523:
1.213 albertel 14524: sub connection_aborted {
14525: my ($r)=@_;
14526: $r->print(" ");$r->rflush();
14527: my $c = $r->connection;
14528: return $c->aborted();
14529: }
14530:
1.221 foxr 14531: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14532: # strings as 'strings'.
14533: sub escape_single {
1.221 foxr 14534: my ($input) = @_;
1.223 albertel 14535: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14536: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14537: return $input;
14538: }
1.223 albertel 14539:
1.222 foxr 14540: # Same as escape_single, but escape's "'s This
14541: # can be used for "strings"
14542: sub escape_double {
14543: my ($input) = @_;
14544: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14545: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14546: return $input;
14547: }
1.223 albertel 14548:
1.222 foxr 14549: # Escapes the last element of a full URL.
14550: sub escape_url {
14551: my ($url) = @_;
1.238 raeburn 14552: my @urlslices = split(/\//, $url,-1);
1.369 www 14553: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 14554: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 14555: }
1.462 albertel 14556:
1.820 raeburn 14557: sub compare_arrays {
14558: my ($arrayref1,$arrayref2) = @_;
14559: my (@difference,%count);
14560: @difference = ();
14561: %count = ();
14562: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14563: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14564: foreach my $element (keys(%count)) {
14565: if ($count{$element} == 1) {
14566: push(@difference,$element);
14567: }
14568: }
14569: }
14570: return @difference;
14571: }
14572:
1.817 bisitz 14573: # -------------------------------------------------------- Initialize user login
1.462 albertel 14574: sub init_user_environment {
1.463 albertel 14575: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14576: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14577:
14578: my $public=($username eq 'public' && $domain eq 'public');
14579:
14580: # See if old ID present, if so, remove
14581:
1.1062 raeburn 14582: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14583: my $now=time;
14584:
14585: if ($public) {
14586: my $max_public=100;
14587: my $oldest;
14588: my $oldest_time=0;
14589: for(my $next=1;$next<=$max_public;$next++) {
14590: if (-e $lonids."/publicuser_$next.id") {
14591: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14592: if ($mtime<$oldest_time || !$oldest_time) {
14593: $oldest_time=$mtime;
14594: $oldest=$next;
14595: }
14596: } else {
14597: $cookie="publicuser_$next";
14598: last;
14599: }
14600: }
14601: if (!$cookie) { $cookie="publicuser_$oldest"; }
14602: } else {
1.463 albertel 14603: # if this isn't a robot, kill any existing non-robot sessions
14604: if (!$args->{'robot'}) {
14605: opendir(DIR,$lonids);
14606: while ($filename=readdir(DIR)) {
14607: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14608: unlink($lonids.'/'.$filename);
14609: }
1.462 albertel 14610: }
1.463 albertel 14611: closedir(DIR);
1.1075.2.84 raeburn 14612: # If there is a undeleted lockfile for the user's paste buffer remove it.
14613: my $namespace = 'nohist_courseeditor';
14614: my $lockingkey = 'paste'."\0".'locked_num';
14615: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
14616: $domain,$username);
14617: if (exists($lockhash{$lockingkey})) {
14618: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
14619: unless ($delresult eq 'ok') {
14620: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
14621: }
14622: }
1.462 albertel 14623: }
14624: # Give them a new cookie
1.463 albertel 14625: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14626: : $now.$$.int(rand(10000)));
1.463 albertel 14627: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14628:
14629: # Initialize roles
14630:
1.1062 raeburn 14631: ($userroles,$firstaccenv,$timerintenv) =
14632: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14633: }
14634: # ------------------------------------ Check browser type and MathML capability
14635:
1.1075.2.77 raeburn 14636: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
14637: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 14638:
14639: # ------------------------------------------------------------- Get environment
14640:
14641: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14642: my ($tmp) = keys(%userenv);
14643: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14644: } else {
14645: undef(%userenv);
14646: }
14647: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14648: $form->{'interface'}=$userenv{'interface'};
14649: }
14650: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14651:
14652: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14653: foreach my $option ('interface','localpath','localres') {
14654: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14655: }
14656: # --------------------------------------------------------- Write first profile
14657:
14658: {
14659: my %initial_env =
14660: ("user.name" => $username,
14661: "user.domain" => $domain,
14662: "user.home" => $authhost,
14663: "browser.type" => $clientbrowser,
14664: "browser.version" => $clientversion,
14665: "browser.mathml" => $clientmathml,
14666: "browser.unicode" => $clientunicode,
14667: "browser.os" => $clientos,
1.1075.2.42 raeburn 14668: "browser.mobile" => $clientmobile,
14669: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 14670: "browser.osversion" => $clientosversion,
1.462 albertel 14671: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14672: "request.course.fn" => '',
14673: "request.course.uri" => '',
14674: "request.course.sec" => '',
14675: "request.role" => 'cm',
14676: "request.role.adv" => $env{'user.adv'},
14677: "request.host" => $ENV{'REMOTE_ADDR'},);
14678:
14679: if ($form->{'localpath'}) {
14680: $initial_env{"browser.localpath"} = $form->{'localpath'};
14681: $initial_env{"browser.localres"} = $form->{'localres'};
14682: }
14683:
14684: if ($form->{'interface'}) {
14685: $form->{'interface'}=~s/\W//gs;
14686: $initial_env{"browser.interface"} = $form->{'interface'};
14687: $env{'browser.interface'}=$form->{'interface'};
14688: }
14689:
1.1075.2.54 raeburn 14690: if ($form->{'iptoken'}) {
14691: my $lonhost = $r->dir_config('lonHostID');
14692: $initial_env{"user.noloadbalance"} = $lonhost;
14693: $env{'user.noloadbalance'} = $lonhost;
14694: }
14695:
1.981 raeburn 14696: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14697: my %domdef;
14698: unless ($domain eq 'public') {
14699: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14700: }
1.980 raeburn 14701:
1.1075.2.7 raeburn 14702: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14703: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14704: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14705: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14706: }
14707:
1.1075.2.59 raeburn 14708: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 14709: $userenv{'canrequest.'.$crstype} =
14710: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14711: 'reload','requestcourses',
14712: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14713: }
14714:
1.1075.2.14 raeburn 14715: $userenv{'canrequest.author'} =
14716: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14717: 'reload','requestauthor',
14718: \%userenv,\%domdef,\%is_adv);
14719: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14720: $domain,$username);
14721: my $reqstatus = $reqauthor{'author_status'};
14722: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14723: if (ref($reqauthor{'author'}) eq 'HASH') {
14724: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14725: $reqauthor{'author'}{'timestamp'};
14726: }
14727: }
14728:
1.462 albertel 14729: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14730:
1.462 albertel 14731: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14732: &GDBM_WRCREAT(),0640)) {
14733: &_add_to_env(\%disk_env,\%initial_env);
14734: &_add_to_env(\%disk_env,\%userenv,'environment.');
14735: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14736: if (ref($firstaccenv) eq 'HASH') {
14737: &_add_to_env(\%disk_env,$firstaccenv);
14738: }
14739: if (ref($timerintenv) eq 'HASH') {
14740: &_add_to_env(\%disk_env,$timerintenv);
14741: }
1.463 albertel 14742: if (ref($args->{'extra_env'})) {
14743: &_add_to_env(\%disk_env,$args->{'extra_env'});
14744: }
1.462 albertel 14745: untie(%disk_env);
14746: } else {
1.705 tempelho 14747: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14748: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14749: return 'error: '.$!;
14750: }
14751: }
14752: $env{'request.role'}='cm';
14753: $env{'request.role.adv'}=$env{'user.adv'};
14754: $env{'browser.type'}=$clientbrowser;
14755:
14756: return $cookie;
14757:
14758: }
14759:
14760: sub _add_to_env {
14761: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14762: if (ref($env_data) eq 'HASH') {
14763: while (my ($key,$value) = each(%$env_data)) {
14764: $idf->{$prefix.$key} = $value;
14765: $env{$prefix.$key} = $value;
14766: }
1.462 albertel 14767: }
14768: }
14769:
1.685 tempelho 14770: # --- Get the symbolic name of a problem and the url
14771: sub get_symb {
14772: my ($request,$silent) = @_;
1.726 raeburn 14773: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14774: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14775: if ($symb eq '') {
14776: if (!$silent) {
1.1071 raeburn 14777: if (ref($request)) {
14778: $request->print("Unable to handle ambiguous references:$url:.");
14779: }
1.685 tempelho 14780: return ();
14781: }
14782: }
14783: &Apache::lonenc::check_decrypt(\$symb);
14784: return ($symb);
14785: }
14786:
14787: # --------------------------------------------------------------Get annotation
14788:
14789: sub get_annotation {
14790: my ($symb,$enc) = @_;
14791:
14792: my $key = $symb;
14793: if (!$enc) {
14794: $key =
14795: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14796: }
14797: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14798: return $annotation{$key};
14799: }
14800:
14801: sub clean_symb {
1.731 raeburn 14802: my ($symb,$delete_enc) = @_;
1.685 tempelho 14803:
14804: &Apache::lonenc::check_decrypt(\$symb);
14805: my $enc = $env{'request.enc'};
1.731 raeburn 14806: if ($delete_enc) {
1.730 raeburn 14807: delete($env{'request.enc'});
14808: }
1.685 tempelho 14809:
14810: return ($symb,$enc);
14811: }
1.462 albertel 14812:
1.1075.2.69 raeburn 14813: ############################################################
14814: ############################################################
14815:
14816: =pod
14817:
14818: =head1 Routines for building display used to search for courses
14819:
14820:
14821: =over 4
14822:
14823: =item * &build_filters()
14824:
14825: Create markup for a table used to set filters to use when selecting
14826: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
14827: and quotacheck.pl
14828:
14829:
14830: Inputs:
14831:
14832: filterlist - anonymous array of fields to include as potential filters
14833:
14834: crstype - course type
14835:
14836: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
14837: to pop-open a course selector (will contain "extra element").
14838:
14839: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
14840:
14841: filter - anonymous hash of criteria and their values
14842:
14843: action - form action
14844:
14845: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
14846:
14847: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
14848:
14849: cloneruname - username of owner of new course who wants to clone
14850:
14851: clonerudom - domain of owner of new course who wants to clone
14852:
14853: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
14854:
14855: codetitlesref - reference to array of titles of components in institutional codes (official courses)
14856:
14857: codedom - domain
14858:
14859: formname - value of form element named "form".
14860:
14861: fixeddom - domain, if fixed.
14862:
14863: prevphase - value to assign to form element named "phase" when going back to the previous screen
14864:
14865: cnameelement - name of form element in form on opener page which will receive title of selected course
14866:
14867: cnumelement - name of form element in form on opener page which will receive courseID of selected course
14868:
14869: cdomelement - name of form element in form on opener page which will receive domain of selected course
14870:
14871: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
14872:
14873: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
14874:
14875: clonewarning - warning message about missing information for intended course owner when DC creates a course
14876:
14877:
14878: Returns: $output - HTML for display of search criteria, and hidden form elements.
14879:
14880:
14881: Side Effects: None
14882:
14883: =cut
14884:
14885: # ---------------------------------------------- search for courses based on last activity etc.
14886:
14887: sub build_filters {
14888: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
14889: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
14890: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
14891: $cnameelement,$cnumelement,$cdomelement,$setroles,
14892: $clonetext,$clonewarning) = @_;
14893: my ($list,$jscript);
14894: my $onchange = 'javascript:updateFilters(this)';
14895: my ($domainselectform,$sincefilterform,$createdfilterform,
14896: $ownerdomselectform,$persondomselectform,$instcodeform,
14897: $typeselectform,$instcodetitle);
14898: if ($formname eq '') {
14899: $formname = $caller;
14900: }
14901: foreach my $item (@{$filterlist}) {
14902: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
14903: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
14904: if ($item eq 'domainfilter') {
14905: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
14906: } elsif ($item eq 'coursefilter') {
14907: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
14908: } elsif ($item eq 'ownerfilter') {
14909: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
14910: } elsif ($item eq 'ownerdomfilter') {
14911: $filter->{'ownerdomfilter'} =
14912: &LONCAPA::clean_domain($filter->{$item});
14913: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
14914: 'ownerdomfilter',1);
14915: } elsif ($item eq 'personfilter') {
14916: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
14917: } elsif ($item eq 'persondomfilter') {
14918: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
14919: 'persondomfilter',1);
14920: } else {
14921: $filter->{$item} =~ s/\W//g;
14922: }
14923: if (!$filter->{$item}) {
14924: $filter->{$item} = '';
14925: }
14926: }
14927: if ($item eq 'domainfilter') {
14928: my $allow_blank = 1;
14929: if ($formname eq 'portform') {
14930: $allow_blank=0;
14931: } elsif ($formname eq 'studentform') {
14932: $allow_blank=0;
14933: }
14934: if ($fixeddom) {
14935: $domainselectform = '<input type="hidden" name="domainfilter"'.
14936: ' value="'.$codedom.'" />'.
14937: &Apache::lonnet::domain($codedom,'description');
14938: } else {
14939: $domainselectform = &select_dom_form($filter->{$item},
14940: 'domainfilter',
14941: $allow_blank,'',$onchange);
14942: }
14943: } else {
14944: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
14945: }
14946: }
14947:
14948: # last course activity filter and selection
14949: $sincefilterform = &timebased_select_form('sincefilter',$filter);
14950:
14951: # course created filter and selection
14952: if (exists($filter->{'createdfilter'})) {
14953: $createdfilterform = &timebased_select_form('createdfilter',$filter);
14954: }
14955:
14956: my %lt = &Apache::lonlocal::texthash(
14957: 'cac' => "$crstype Activity",
14958: 'ccr' => "$crstype Created",
14959: 'cde' => "$crstype Title",
14960: 'cdo' => "$crstype Domain",
14961: 'ins' => 'Institutional Code',
14962: 'inc' => 'Institutional Categorization',
14963: 'cow' => "$crstype Owner/Co-owner",
14964: 'cop' => "$crstype Personnel Includes",
14965: 'cog' => 'Type',
14966: );
14967:
14968: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
14969: my $typeval = 'Course';
14970: if ($crstype eq 'Community') {
14971: $typeval = 'Community';
14972: }
14973: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
14974: } else {
14975: $typeselectform = '<select name="type" size="1"';
14976: if ($onchange) {
14977: $typeselectform .= ' onchange="'.$onchange.'"';
14978: }
14979: $typeselectform .= '>'."\n";
14980: foreach my $posstype ('Course','Community') {
14981: $typeselectform.='<option value="'.$posstype.'"'.
14982: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
14983: }
14984: $typeselectform.="</select>";
14985: }
14986:
14987: my ($cloneableonlyform,$cloneabletitle);
14988: if (exists($filter->{'cloneableonly'})) {
14989: my $cloneableon = '';
14990: my $cloneableoff = ' checked="checked"';
14991: if ($filter->{'cloneableonly'}) {
14992: $cloneableon = $cloneableoff;
14993: $cloneableoff = '';
14994: }
14995: $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>';
14996: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 14997: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 14998: } else {
14999: $cloneabletitle = &mt('Cloneable by you');
15000: }
15001: }
15002: my $officialjs;
15003: if ($crstype eq 'Course') {
15004: if (exists($filter->{'instcodefilter'})) {
15005: # if (($fixeddom) || ($formname eq 'requestcrs') ||
15006: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
15007: if ($codedom) {
15008: $officialjs = 1;
15009: ($instcodeform,$jscript,$$numtitlesref) =
15010: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
15011: $officialjs,$codetitlesref);
15012: if ($jscript) {
15013: $jscript = '<script type="text/javascript">'."\n".
15014: '// <![CDATA['."\n".
15015: $jscript."\n".
15016: '// ]]>'."\n".
15017: '</script>'."\n";
15018: }
15019: }
15020: if ($instcodeform eq '') {
15021: $instcodeform =
15022: '<input type="text" name="instcodefilter" size="10" value="'.
15023: $list->{'instcodefilter'}.'" />';
15024: $instcodetitle = $lt{'ins'};
15025: } else {
15026: $instcodetitle = $lt{'inc'};
15027: }
15028: if ($fixeddom) {
15029: $instcodetitle .= '<br />('.$codedom.')';
15030: }
15031: }
15032: }
15033: my $output = qq|
15034: <form method="post" name="filterpicker" action="$action">
15035: <input type="hidden" name="form" value="$formname" />
15036: |;
15037: if ($formname eq 'modifycourse') {
15038: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
15039: '<input type="hidden" name="prevphase" value="'.
15040: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 15041: } elsif ($formname eq 'quotacheck') {
15042: $output .= qq|
15043: <input type="hidden" name="sortby" value="" />
15044: <input type="hidden" name="sortorder" value="" />
15045: |;
15046: } else {
1.1075.2.69 raeburn 15047: my $name_input;
15048: if ($cnameelement ne '') {
15049: $name_input = '<input type="hidden" name="cnameelement" value="'.
15050: $cnameelement.'" />';
15051: }
15052: $output .= qq|
15053: <input type="hidden" name="cnumelement" value="$cnumelement" />
15054: <input type="hidden" name="cdomelement" value="$cdomelement" />
15055: $name_input
15056: $roleelement
15057: $multelement
15058: $typeelement
15059: |;
15060: if ($formname eq 'portform') {
15061: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
15062: }
15063: }
15064: if ($fixeddom) {
15065: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
15066: }
15067: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
15068: if ($sincefilterform) {
15069: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
15070: .$sincefilterform
15071: .&Apache::lonhtmlcommon::row_closure();
15072: }
15073: if ($createdfilterform) {
15074: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
15075: .$createdfilterform
15076: .&Apache::lonhtmlcommon::row_closure();
15077: }
15078: if ($domainselectform) {
15079: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
15080: .$domainselectform
15081: .&Apache::lonhtmlcommon::row_closure();
15082: }
15083: if ($typeselectform) {
15084: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15085: $output .= $typeselectform;
15086: } else {
15087: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
15088: .$typeselectform
15089: .&Apache::lonhtmlcommon::row_closure();
15090: }
15091: }
15092: if ($instcodeform) {
15093: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
15094: .$instcodeform
15095: .&Apache::lonhtmlcommon::row_closure();
15096: }
15097: if (exists($filter->{'ownerfilter'})) {
15098: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
15099: '<table><tr><td>'.&mt('Username').'<br />'.
15100: '<input type="text" name="ownerfilter" size="20" value="'.
15101: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15102: $ownerdomselectform.'</td></tr></table>'.
15103: &Apache::lonhtmlcommon::row_closure();
15104: }
15105: if (exists($filter->{'personfilter'})) {
15106: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
15107: '<table><tr><td>'.&mt('Username').'<br />'.
15108: '<input type="text" name="personfilter" size="20" value="'.
15109: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15110: $persondomselectform.'</td></tr></table>'.
15111: &Apache::lonhtmlcommon::row_closure();
15112: }
15113: if (exists($filter->{'coursefilter'})) {
15114: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15115: .'<input type="text" name="coursefilter" size="25" value="'
15116: .$list->{'coursefilter'}.'" />'
15117: .&Apache::lonhtmlcommon::row_closure();
15118: }
15119: if ($cloneableonlyform) {
15120: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15121: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15122: }
15123: if (exists($filter->{'descriptfilter'})) {
15124: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15125: .'<input type="text" name="descriptfilter" size="40" value="'
15126: .$list->{'descriptfilter'}.'" />'
15127: .&Apache::lonhtmlcommon::row_closure(1);
15128: }
15129: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15130: '<input type="hidden" name="updater" value="" />'."\n".
15131: '<input type="submit" name="gosearch" value="'.
15132: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15133: return $jscript.$clonewarning.$output;
15134: }
15135:
15136: =pod
15137:
15138: =item * &timebased_select_form()
15139:
15140: Create markup for a dropdown list used to select a time-based
15141: filter e.g., Course Activity, Course Created, when searching for courses
15142: or communities
15143:
15144: Inputs:
15145:
15146: item - name of form element (sincefilter or createdfilter)
15147:
15148: filter - anonymous hash of criteria and their values
15149:
15150: Returns: HTML for a select box contained a blank, then six time selections,
15151: with value set in incoming form variables currently selected.
15152:
15153: Side Effects: None
15154:
15155: =cut
15156:
15157: sub timebased_select_form {
15158: my ($item,$filter) = @_;
15159: if (ref($filter) eq 'HASH') {
15160: $filter->{$item} =~ s/[^\d-]//g;
15161: if (!$filter->{$item}) { $filter->{$item}=-1; }
15162: return &select_form(
15163: $filter->{$item},
15164: $item,
15165: { '-1' => '',
15166: '86400' => &mt('today'),
15167: '604800' => &mt('last week'),
15168: '2592000' => &mt('last month'),
15169: '7776000' => &mt('last three months'),
15170: '15552000' => &mt('last six months'),
15171: '31104000' => &mt('last year'),
15172: 'select_form_order' =>
15173: ['-1','86400','604800','2592000','7776000',
15174: '15552000','31104000']});
15175: }
15176: }
15177:
15178: =pod
15179:
15180: =item * &js_changer()
15181:
15182: Create script tag containing Javascript used to submit course search form
15183: when course type or domain is changed, and also to hide 'Searching ...' on
15184: page load completion for page showing search result.
15185:
15186: Inputs: None
15187:
15188: Returns: markup containing updateFilters() and hideSearching() javascript functions.
15189:
15190: Side Effects: None
15191:
15192: =cut
15193:
15194: sub js_changer {
15195: return <<ENDJS;
15196: <script type="text/javascript">
15197: // <![CDATA[
15198: function updateFilters(caller) {
15199: if (typeof(caller) != "undefined") {
15200: document.filterpicker.updater.value = caller.name;
15201: }
15202: document.filterpicker.submit();
15203: }
15204:
15205: function hideSearching() {
15206: if (document.getElementById('searching')) {
15207: document.getElementById('searching').style.display = 'none';
15208: }
15209: return;
15210: }
15211:
15212: // ]]>
15213: </script>
15214:
15215: ENDJS
15216: }
15217:
15218: =pod
15219:
15220: =item * &search_courses()
15221:
15222: Process selected filters form course search form and pass to lonnet::courseiddump
15223: to retrieve a hash for which keys are courseIDs which match the selected filters.
15224:
15225: Inputs:
15226:
15227: dom - domain being searched
15228:
15229: type - course type ('Course' or 'Community' or '.' if any).
15230:
15231: filter - anonymous hash of criteria and their values
15232:
15233: numtitles - for institutional codes - number of categories
15234:
15235: cloneruname - optional username of new course owner
15236:
15237: clonerudom - optional domain of new course owner
15238:
15239: domcloner - Optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
15240: (used when DC is using course creation form)
15241:
15242: codetitles - reference to array of titles of components in institutional codes (official courses).
15243:
15244:
15245: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
15246:
15247:
15248: Side Effects: None
15249:
15250: =cut
15251:
15252:
15253: sub search_courses {
15254: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_;
15255: my (%courses,%showcourses,$cloner);
15256: if (($filter->{'ownerfilter'} ne '') ||
15257: ($filter->{'ownerdomfilter'} ne '')) {
15258: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
15259: $filter->{'ownerdomfilter'};
15260: }
15261: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
15262: if (!$filter->{$item}) {
15263: $filter->{$item}='.';
15264: }
15265: }
15266: my $now = time;
15267: my $timefilter =
15268: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
15269: my ($createdbefore,$createdafter);
15270: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
15271: $createdbefore = $now;
15272: $createdafter = $now-$filter->{'createdfilter'};
15273: }
15274: my ($instcodefilter,$regexpok);
15275: if ($numtitles) {
15276: if ($env{'form.official'} eq 'on') {
15277: $instcodefilter =
15278: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15279: $regexpok = 1;
15280: } elsif ($env{'form.official'} eq 'off') {
15281: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15282: unless ($instcodefilter eq '') {
15283: $regexpok = -1;
15284: }
15285: }
15286: } else {
15287: $instcodefilter = $filter->{'instcodefilter'};
15288: }
15289: if ($instcodefilter eq '') { $instcodefilter = '.'; }
15290: if ($type eq '') { $type = '.'; }
15291:
15292: if (($clonerudom ne '') && ($cloneruname ne '')) {
15293: $cloner = $cloneruname.':'.$clonerudom;
15294: }
15295: %courses = &Apache::lonnet::courseiddump($dom,
15296: $filter->{'descriptfilter'},
15297: $timefilter,
15298: $instcodefilter,
15299: $filter->{'combownerfilter'},
15300: $filter->{'coursefilter'},
15301: undef,undef,$type,$regexpok,undef,undef,
15302: undef,undef,$cloner,$env{'form.cc_clone'},
15303: $filter->{'cloneableonly'},
15304: $createdbefore,$createdafter,undef,
15305: $domcloner);
15306: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
15307: my $ccrole;
15308: if ($type eq 'Community') {
15309: $ccrole = 'co';
15310: } else {
15311: $ccrole = 'cc';
15312: }
15313: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
15314: $filter->{'persondomfilter'},
15315: 'userroles',undef,
15316: [$ccrole,'in','ad','ep','ta','cr'],
15317: $dom);
15318: foreach my $role (keys(%rolehash)) {
15319: my ($cnum,$cdom,$courserole) = split(':',$role);
15320: my $cid = $cdom.'_'.$cnum;
15321: if (exists($courses{$cid})) {
15322: if (ref($courses{$cid}) eq 'HASH') {
15323: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
15324: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
15325: push (@{$courses{$cid}{roles}},$courserole);
15326: }
15327: } else {
15328: $courses{$cid}{roles} = [$courserole];
15329: }
15330: $showcourses{$cid} = $courses{$cid};
15331: }
15332: }
15333: }
15334: %courses = %showcourses;
15335: }
15336: return %courses;
15337: }
15338:
15339: =pod
15340:
15341: =back
15342:
15343: =cut
15344:
15345:
1.1075.2.11 raeburn 15346: sub update_content_constraints {
15347: my ($cdom,$cnum,$chome,$cid) = @_;
15348: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15349: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
15350: my %checkresponsetypes;
15351: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
15352: my ($item,$name,$value) = split(/:/,$key);
15353: if ($item eq 'resourcetag') {
15354: if ($name eq 'responsetype') {
15355: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
15356: }
15357: }
15358: }
15359: my $navmap = Apache::lonnavmaps::navmap->new();
15360: if (defined($navmap)) {
15361: my %allresponses;
15362: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
15363: my %responses = $res->responseTypes();
15364: foreach my $key (keys(%responses)) {
15365: next unless(exists($checkresponsetypes{$key}));
15366: $allresponses{$key} += $responses{$key};
15367: }
15368: }
15369: foreach my $key (keys(%allresponses)) {
15370: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
15371: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
15372: ($reqdmajor,$reqdminor) = ($major,$minor);
15373: }
15374: }
15375: undef($navmap);
15376: }
15377: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
15378: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
15379: }
15380: return;
15381: }
15382:
1.1075.2.27 raeburn 15383: sub allmaps_incourse {
15384: my ($cdom,$cnum,$chome,$cid) = @_;
15385: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
15386: $cid = $env{'request.course.id'};
15387: $cdom = $env{'course.'.$cid.'.domain'};
15388: $cnum = $env{'course.'.$cid.'.num'};
15389: $chome = $env{'course.'.$cid.'.home'};
15390: }
15391: my %allmaps = ();
15392: my $lastchange =
15393: &Apache::lonnet::get_coursechange($cdom,$cnum);
15394: if ($lastchange > $env{'request.course.tied'}) {
15395: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
15396: unless ($ferr) {
15397: &update_content_constraints($cdom,$cnum,$chome,$cid);
15398: }
15399: }
15400: my $navmap = Apache::lonnavmaps::navmap->new();
15401: if (defined($navmap)) {
15402: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
15403: $allmaps{$res->src()} = 1;
15404: }
15405: }
15406: return \%allmaps;
15407: }
15408:
1.1075.2.11 raeburn 15409: sub parse_supplemental_title {
15410: my ($title) = @_;
15411:
15412: my ($foldertitle,$renametitle);
15413: if ($title =~ /&&&/) {
15414: $title = &HTML::Entites::decode($title);
15415: }
15416: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
15417: $renametitle=$4;
15418: my ($time,$uname,$udom) = ($1,$2,$3);
15419: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
15420: my $name = &plainname($uname,$udom);
15421: $name = &HTML::Entities::encode($name,'"<>&\'');
15422: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
15423: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
15424: $name.': <br />'.$foldertitle;
15425: }
15426: if (wantarray) {
15427: return ($title,$foldertitle,$renametitle);
15428: }
15429: return $title;
15430: }
15431:
1.1075.2.43 raeburn 15432: sub recurse_supplemental {
15433: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
15434: if ($suppmap) {
15435: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
15436: if ($fatal) {
15437: $errors ++;
15438: } else {
15439: if ($#LONCAPA::map::resources > 0) {
15440: foreach my $res (@LONCAPA::map::resources) {
15441: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
15442: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 15443: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
15444: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 15445: } else {
15446: $numfiles ++;
15447: }
15448: }
15449: }
15450: }
15451: }
15452: }
15453: return ($numfiles,$errors);
15454: }
15455:
1.1075.2.18 raeburn 15456: sub symb_to_docspath {
15457: my ($symb) = @_;
15458: return unless ($symb);
15459: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
15460: if ($resurl=~/\.(sequence|page)$/) {
15461: $mapurl=$resurl;
15462: } elsif ($resurl eq 'adm/navmaps') {
15463: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
15464: }
15465: my $mapresobj;
15466: my $navmap = Apache::lonnavmaps::navmap->new();
15467: if (ref($navmap)) {
15468: $mapresobj = $navmap->getResourceByUrl($mapurl);
15469: }
15470: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
15471: my $type=$2;
15472: my $path;
15473: if (ref($mapresobj)) {
15474: my $pcslist = $mapresobj->map_hierarchy();
15475: if ($pcslist ne '') {
15476: foreach my $pc (split(/,/,$pcslist)) {
15477: next if ($pc <= 1);
15478: my $res = $navmap->getByMapPc($pc);
15479: if (ref($res)) {
15480: my $thisurl = $res->src();
15481: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
15482: my $thistitle = $res->title();
15483: $path .= '&'.
15484: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 15485: &escape($thistitle).
1.1075.2.18 raeburn 15486: ':'.$res->randompick().
15487: ':'.$res->randomout().
15488: ':'.$res->encrypted().
15489: ':'.$res->randomorder().
15490: ':'.$res->is_page();
15491: }
15492: }
15493: }
15494: $path =~ s/^\&//;
15495: my $maptitle = $mapresobj->title();
15496: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 15497: $maptitle = 'Main Content';
1.1075.2.18 raeburn 15498: }
15499: $path .= (($path ne '')? '&' : '').
15500: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 15501: &escape($maptitle).
1.1075.2.18 raeburn 15502: ':'.$mapresobj->randompick().
15503: ':'.$mapresobj->randomout().
15504: ':'.$mapresobj->encrypted().
15505: ':'.$mapresobj->randomorder().
15506: ':'.$mapresobj->is_page();
15507: } else {
15508: my $maptitle = &Apache::lonnet::gettitle($mapurl);
15509: my $ispage = (($type eq 'page')? 1 : '');
15510: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 15511: $maptitle = 'Main Content';
1.1075.2.18 raeburn 15512: }
15513: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 15514: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 15515: }
15516: unless ($mapurl eq 'default') {
15517: $path = 'default&'.
1.1075.2.46 raeburn 15518: &escape('Main Content').
1.1075.2.18 raeburn 15519: ':::::&'.$path;
15520: }
15521: return $path;
15522: }
15523:
1.1075.2.14 raeburn 15524: sub captcha_display {
15525: my ($context,$lonhost) = @_;
15526: my ($output,$error);
15527: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
15528: if ($captcha eq 'original') {
15529: $output = &create_captcha();
15530: unless ($output) {
15531: $error = 'captcha';
15532: }
15533: } elsif ($captcha eq 'recaptcha') {
15534: $output = &create_recaptcha($pubkey);
15535: unless ($output) {
15536: $error = 'recaptcha';
15537: }
15538: }
1.1075.2.66 raeburn 15539: return ($output,$error,$captcha);
1.1075.2.14 raeburn 15540: }
15541:
15542: sub captcha_response {
15543: my ($context,$lonhost) = @_;
15544: my ($captcha_chk,$captcha_error);
15545: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
15546: if ($captcha eq 'original') {
15547: ($captcha_chk,$captcha_error) = &check_captcha();
15548: } elsif ($captcha eq 'recaptcha') {
15549: $captcha_chk = &check_recaptcha($privkey);
15550: } else {
15551: $captcha_chk = 1;
15552: }
15553: return ($captcha_chk,$captcha_error);
15554: }
15555:
15556: sub get_captcha_config {
15557: my ($context,$lonhost) = @_;
15558: my ($captcha,$pubkey,$privkey,$hashtocheck);
15559: my $hostname = &Apache::lonnet::hostname($lonhost);
15560: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
15561: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
15562: if ($context eq 'usercreation') {
15563: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
15564: if (ref($domconfig{$context}) eq 'HASH') {
15565: $hashtocheck = $domconfig{$context}{'cancreate'};
15566: if (ref($hashtocheck) eq 'HASH') {
15567: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
15568: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
15569: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
15570: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
15571: }
15572: if ($privkey && $pubkey) {
15573: $captcha = 'recaptcha';
15574: } else {
15575: $captcha = 'original';
15576: }
15577: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
15578: $captcha = 'original';
15579: }
15580: }
15581: } else {
15582: $captcha = 'captcha';
15583: }
15584: } elsif ($context eq 'login') {
15585: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
15586: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
15587: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
15588: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
15589: if ($privkey && $pubkey) {
15590: $captcha = 'recaptcha';
15591: } else {
15592: $captcha = 'original';
15593: }
15594: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
15595: $captcha = 'original';
15596: }
15597: }
15598: return ($captcha,$pubkey,$privkey);
15599: }
15600:
15601: sub create_captcha {
15602: my %captcha_params = &captcha_settings();
15603: my ($output,$maxtries,$tries) = ('',10,0);
15604: while ($tries < $maxtries) {
15605: $tries ++;
15606: my $captcha = Authen::Captcha->new (
15607: output_folder => $captcha_params{'output_dir'},
15608: data_folder => $captcha_params{'db_dir'},
15609: );
15610: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
15611:
15612: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
15613: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
15614: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 15615: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
15616: '<br />'.
15617: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 15618: last;
15619: }
15620: }
15621: return $output;
15622: }
15623:
15624: sub captcha_settings {
15625: my %captcha_params = (
15626: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
15627: www_output_dir => "/captchaspool",
15628: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
15629: numchars => '5',
15630: );
15631: return %captcha_params;
15632: }
15633:
15634: sub check_captcha {
15635: my ($captcha_chk,$captcha_error);
15636: my $code = $env{'form.code'};
15637: my $md5sum = $env{'form.crypt'};
15638: my %captcha_params = &captcha_settings();
15639: my $captcha = Authen::Captcha->new(
15640: output_folder => $captcha_params{'output_dir'},
15641: data_folder => $captcha_params{'db_dir'},
15642: );
1.1075.2.26 raeburn 15643: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 15644: my %captcha_hash = (
15645: 0 => 'Code not checked (file error)',
15646: -1 => 'Failed: code expired',
15647: -2 => 'Failed: invalid code (not in database)',
15648: -3 => 'Failed: invalid code (code does not match crypt)',
15649: );
15650: if ($captcha_chk != 1) {
15651: $captcha_error = $captcha_hash{$captcha_chk}
15652: }
15653: return ($captcha_chk,$captcha_error);
15654: }
15655:
15656: sub create_recaptcha {
15657: my ($pubkey) = @_;
1.1075.2.51 raeburn 15658: my $use_ssl;
15659: if ($ENV{'SERVER_PORT'} == 443) {
15660: $use_ssl = 1;
15661: }
1.1075.2.14 raeburn 15662: my $captcha = Captcha::reCAPTCHA->new;
15663: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1075.2.51 raeburn 15664: $captcha->get_html($pubkey,undef,$use_ssl).
1.1075.2.14 raeburn 15665: &mt('If either word is hard to read, [_1] will replace them.',
1.1075.2.39 raeburn 15666: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1075.2.14 raeburn 15667: '<br /><br />';
15668: }
15669:
15670: sub check_recaptcha {
15671: my ($privkey) = @_;
15672: my $captcha_chk;
15673: my $captcha = Captcha::reCAPTCHA->new;
15674: my $captcha_result =
15675: $captcha->check_answer(
15676: $privkey,
15677: $ENV{'REMOTE_ADDR'},
15678: $env{'form.recaptcha_challenge_field'},
15679: $env{'form.recaptcha_response_field'},
15680: );
15681: if ($captcha_result->{is_valid}) {
15682: $captcha_chk = 1;
15683: }
15684: return $captcha_chk;
15685: }
15686:
1.1075.2.64 raeburn 15687: sub emailusername_info {
1.1075.2.67 raeburn 15688: my @fields = ('firstname','lastname','institution','web','location','officialemail');
1.1075.2.64 raeburn 15689: my %titles = &Apache::lonlocal::texthash (
15690: lastname => 'Last Name',
15691: firstname => 'First Name',
15692: institution => 'School/college/university',
15693: location => "School's city, state/province, country",
15694: web => "School's web address",
15695: officialemail => 'E-mail address at institution (if different)',
15696: );
15697: return (\@fields,\%titles);
15698: }
15699:
1.1075.2.56 raeburn 15700: sub cleanup_html {
15701: my ($incoming) = @_;
15702: my $outgoing;
15703: if ($incoming ne '') {
15704: $outgoing = $incoming;
15705: $outgoing =~ s/;/;/g;
15706: $outgoing =~ s/\#/#/g;
15707: $outgoing =~ s/\&/&/g;
15708: $outgoing =~ s/</</g;
15709: $outgoing =~ s/>/>/g;
15710: $outgoing =~ s/\(/(/g;
15711: $outgoing =~ s/\)/)/g;
15712: $outgoing =~ s/"/"/g;
15713: $outgoing =~ s/'/'/g;
15714: $outgoing =~ s/\$/$/g;
15715: $outgoing =~ s{/}{/}g;
15716: $outgoing =~ s/=/=/g;
15717: $outgoing =~ s/\\/\/g
15718: }
15719: return $outgoing;
15720: }
15721:
1.1075.2.74 raeburn 15722: # Checks for critical messages and returns a redirect url if one exists.
15723: # $interval indicates how often to check for messages.
15724: sub critical_redirect {
15725: my ($interval) = @_;
15726: if ((time-$env{'user.criticalcheck.time'})>$interval) {
15727: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
15728: $env{'user.name'});
15729: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
15730: my $redirecturl;
15731: if ($what[0]) {
15732: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
15733: $redirecturl='/adm/email?critical=display';
15734: my $url=&Apache::lonnet::absolute_url().$redirecturl;
15735: return (1, $url);
15736: }
15737: }
15738: }
15739: return ();
15740: }
15741:
1.1075.2.64 raeburn 15742: # Use:
15743: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
15744: #
15745: ##################################################
15746: # password associated functions #
15747: ##################################################
15748: sub des_keys {
15749: # Make a new key for DES encryption.
15750: # Each key has two parts which are returned separately.
15751: # Please note: Each key must be passed through the &hex function
15752: # before it is output to the web browser. The hex versions cannot
15753: # be used to decrypt.
15754: my @hexstr=('0','1','2','3','4','5','6','7',
15755: '8','9','a','b','c','d','e','f');
15756: my $lkey='';
15757: for (0..7) {
15758: $lkey.=$hexstr[rand(15)];
15759: }
15760: my $ukey='';
15761: for (0..7) {
15762: $ukey.=$hexstr[rand(15)];
15763: }
15764: return ($lkey,$ukey);
15765: }
15766:
15767: sub des_decrypt {
15768: my ($key,$cyphertext) = @_;
15769: my $keybin=pack("H16",$key);
15770: my $cypher;
15771: if ($Crypt::DES::VERSION>=2.03) {
15772: $cypher=new Crypt::DES $keybin;
15773: } else {
15774: $cypher=new DES $keybin;
15775: }
15776: my $plaintext=
15777: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
15778: $plaintext.=
15779: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
15780: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
15781: return $plaintext;
15782: }
15783:
1.112 bowersj2 15784: 1;
15785: __END__;
1.41 ng 15786:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>