Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.71
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.71! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.70 2014/04/23 10:33:52 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>'
! 1296: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
! 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.87 matthew 2344: =back
2345:
1.157 matthew 2346: =back
2347:
1.87 matthew 2348: =cut
2349:
2350: ###############################################################
2351: ###############################################################
2352: sub decode_user_agent {
1.247 albertel 2353: my ($r)=@_;
1.87 matthew 2354: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2355: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2356: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2357: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2358: my $clientbrowser='unknown';
2359: my $clientversion='0';
2360: my $clientmathml='';
2361: my $clientunicode='0';
1.1075.2.42 raeburn 2362: my $clientmobile=0;
1.87 matthew 2363: for (my $i=0;$i<=$#browsertype;$i++) {
2364: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2365: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2366: $clientbrowser=$bname;
2367: $httpbrowser=~/$vreg/i;
2368: $clientversion=$1;
2369: $clientmathml=($clientversion>=$minv);
2370: $clientunicode=($clientversion>=$univ);
2371: }
2372: }
2373: my $clientos='unknown';
1.1075.2.42 raeburn 2374: my $clientinfo;
1.87 matthew 2375: if (($httpbrowser=~/linux/i) ||
2376: ($httpbrowser=~/unix/i) ||
2377: ($httpbrowser=~/ux/i) ||
2378: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2379: if (($httpbrowser=~/vax/i) ||
2380: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2381: if ($httpbrowser=~/next/i) { $clientos='next'; }
2382: if (($httpbrowser=~/mac/i) ||
2383: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2384: if ($httpbrowser=~/win/i) { $clientos='win'; }
2385: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2386: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2387: $clientmobile=lc($1);
2388: }
2389: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2390: $clientinfo = 'firefox-'.$1;
2391: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2392: $clientinfo = 'chromeframe-'.$1;
2393: }
1.87 matthew 2394: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.42 raeburn 2395: $clientunicode,$clientos,$clientmobile,$clientinfo);
1.87 matthew 2396: }
2397:
1.32 matthew 2398: ###############################################################
2399: ## Authentication changing form generation subroutines ##
2400: ###############################################################
2401: ##
2402: ## All of the authform_xxxxxxx subroutines take their inputs in a
2403: ## hash, and have reasonable default values.
2404: ##
2405: ## formname = the name given in the <form> tag.
1.35 matthew 2406: #-------------------------------------------
2407:
1.45 matthew 2408: =pod
2409:
1.112 bowersj2 2410: =head1 Authentication Routines
2411:
2412: =over 4
2413:
1.648 raeburn 2414: =item * &authform_xxxxxx()
1.35 matthew 2415:
2416: The authform_xxxxxx subroutines provide javascript and html forms which
2417: handle some of the conveniences required for authentication forms.
2418: This is not an optimal method, but it works.
2419:
2420: =over 4
2421:
1.112 bowersj2 2422: =item * authform_header
1.35 matthew 2423:
1.112 bowersj2 2424: =item * authform_authorwarning
1.35 matthew 2425:
1.112 bowersj2 2426: =item * authform_nochange
1.35 matthew 2427:
1.112 bowersj2 2428: =item * authform_kerberos
1.35 matthew 2429:
1.112 bowersj2 2430: =item * authform_internal
1.35 matthew 2431:
1.112 bowersj2 2432: =item * authform_filesystem
1.35 matthew 2433:
2434: =back
2435:
1.648 raeburn 2436: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2437:
1.35 matthew 2438: =cut
2439:
2440: #-------------------------------------------
1.32 matthew 2441: sub authform_header{
2442: my %in = (
2443: formname => 'cu',
1.80 albertel 2444: kerb_def_dom => '',
1.32 matthew 2445: @_,
2446: );
2447: $in{'formname'} = 'document.' . $in{'formname'};
2448: my $result='';
1.80 albertel 2449:
2450: #---------------------------------------------- Code for upper case translation
2451: my $Javascript_toUpperCase;
2452: unless ($in{kerb_def_dom}) {
2453: $Javascript_toUpperCase =<<"END";
2454: switch (choice) {
2455: case 'krb': currentform.elements[choicearg].value =
2456: currentform.elements[choicearg].value.toUpperCase();
2457: break;
2458: default:
2459: }
2460: END
2461: } else {
2462: $Javascript_toUpperCase = "";
2463: }
2464:
1.165 raeburn 2465: my $radioval = "'nochange'";
1.591 raeburn 2466: if (defined($in{'curr_authtype'})) {
2467: if ($in{'curr_authtype'} ne '') {
2468: $radioval = "'".$in{'curr_authtype'}."arg'";
2469: }
1.174 matthew 2470: }
1.165 raeburn 2471: my $argfield = 'null';
1.591 raeburn 2472: if (defined($in{'mode'})) {
1.165 raeburn 2473: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2474: if (defined($in{'curr_autharg'})) {
2475: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2476: $argfield = "'$in{'curr_autharg'}'";
2477: }
2478: }
2479: }
2480: }
2481:
1.32 matthew 2482: $result.=<<"END";
2483: var current = new Object();
1.165 raeburn 2484: current.radiovalue = $radioval;
2485: current.argfield = $argfield;
1.32 matthew 2486:
2487: function changed_radio(choice,currentform) {
2488: var choicearg = choice + 'arg';
2489: // If a radio button in changed, we need to change the argfield
2490: if (current.radiovalue != choice) {
2491: current.radiovalue = choice;
2492: if (current.argfield != null) {
2493: currentform.elements[current.argfield].value = '';
2494: }
2495: if (choice == 'nochange') {
2496: current.argfield = null;
2497: } else {
2498: current.argfield = choicearg;
2499: switch(choice) {
2500: case 'krb':
2501: currentform.elements[current.argfield].value =
2502: "$in{'kerb_def_dom'}";
2503: break;
2504: default:
2505: break;
2506: }
2507: }
2508: }
2509: return;
2510: }
1.22 www 2511:
1.32 matthew 2512: function changed_text(choice,currentform) {
2513: var choicearg = choice + 'arg';
2514: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2515: $Javascript_toUpperCase
1.32 matthew 2516: // clear old field
2517: if ((current.argfield != choicearg) && (current.argfield != null)) {
2518: currentform.elements[current.argfield].value = '';
2519: }
2520: current.argfield = choicearg;
2521: }
2522: set_auth_radio_buttons(choice,currentform);
2523: return;
1.20 www 2524: }
1.32 matthew 2525:
2526: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2527: var numauthchoices = currentform.login.length;
2528: if (typeof numauthchoices == "undefined") {
2529: return;
2530: }
1.32 matthew 2531: var i=0;
1.986 raeburn 2532: while (i < numauthchoices) {
1.32 matthew 2533: if (currentform.login[i].value == newvalue) { break; }
2534: i++;
2535: }
1.986 raeburn 2536: if (i == numauthchoices) {
1.32 matthew 2537: return;
2538: }
2539: current.radiovalue = newvalue;
2540: currentform.login[i].checked = true;
2541: return;
2542: }
2543: END
2544: return $result;
2545: }
2546:
1.1075.2.20 raeburn 2547: sub authform_authorwarning {
1.32 matthew 2548: my $result='';
1.144 matthew 2549: $result='<i>'.
2550: &mt('As a general rule, only authors or co-authors should be '.
2551: 'filesystem authenticated '.
2552: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2553: return $result;
2554: }
2555:
1.1075.2.20 raeburn 2556: sub authform_nochange {
1.32 matthew 2557: my %in = (
2558: formname => 'document.cu',
2559: kerb_def_dom => 'MSU.EDU',
2560: @_,
2561: );
1.1075.2.20 raeburn 2562: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2563: my $result;
1.1075.2.20 raeburn 2564: if (!$authnum) {
2565: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2566: } else {
2567: $result = '<label>'.&mt('[_1] Do not change login data',
2568: '<input type="radio" name="login" value="nochange" '.
2569: 'checked="checked" onclick="'.
1.281 albertel 2570: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2571: '</label>';
1.586 raeburn 2572: }
1.32 matthew 2573: return $result;
2574: }
2575:
1.591 raeburn 2576: sub authform_kerberos {
1.32 matthew 2577: my %in = (
2578: formname => 'document.cu',
2579: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2580: kerb_def_auth => 'krb4',
1.32 matthew 2581: @_,
2582: );
1.586 raeburn 2583: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2584: $autharg,$jscall);
1.1075.2.20 raeburn 2585: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2586: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2587: $check5 = ' checked="checked"';
1.80 albertel 2588: } else {
1.772 bisitz 2589: $check4 = ' checked="checked"';
1.80 albertel 2590: }
1.165 raeburn 2591: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2592: if (defined($in{'curr_authtype'})) {
2593: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2594: $krbcheck = ' checked="checked"';
1.623 raeburn 2595: if (defined($in{'mode'})) {
2596: if ($in{'mode'} eq 'modifyuser') {
2597: $krbcheck = '';
2598: }
2599: }
1.591 raeburn 2600: if (defined($in{'curr_kerb_ver'})) {
2601: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2602: $check5 = ' checked="checked"';
1.591 raeburn 2603: $check4 = '';
2604: } else {
1.772 bisitz 2605: $check4 = ' checked="checked"';
1.591 raeburn 2606: $check5 = '';
2607: }
1.586 raeburn 2608: }
1.591 raeburn 2609: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2610: $krbarg = $in{'curr_autharg'};
2611: }
1.586 raeburn 2612: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2613: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2614: $result =
2615: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2616: $in{'curr_autharg'},$krbver);
2617: } else {
2618: $result =
2619: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2620: }
2621: return $result;
2622: }
2623: }
2624: } else {
2625: if ($authnum == 1) {
1.784 bisitz 2626: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2627: }
2628: }
1.586 raeburn 2629: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2630: return;
1.587 raeburn 2631: } elsif ($authtype eq '') {
1.591 raeburn 2632: if (defined($in{'mode'})) {
1.587 raeburn 2633: if ($in{'mode'} eq 'modifycourse') {
2634: if ($authnum == 1) {
1.1075.2.20 raeburn 2635: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2636: }
2637: }
2638: }
1.586 raeburn 2639: }
2640: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2641: if ($authtype eq '') {
2642: $authtype = '<input type="radio" name="login" value="krb" '.
2643: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2644: $krbcheck.' />';
2645: }
2646: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2647: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2648: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2649: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2650: $in{'curr_authtype'} eq 'krb4')) {
2651: $result .= &mt
1.144 matthew 2652: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2653: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2654: '<label>'.$authtype,
1.281 albertel 2655: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2656: 'value="'.$krbarg.'" '.
1.144 matthew 2657: 'onchange="'.$jscall.'" />',
1.281 albertel 2658: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2659: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2660: '</label>');
1.586 raeburn 2661: } elsif ($can_assign{'krb4'}) {
2662: $result .= &mt
2663: ('[_1] Kerberos authenticated with domain [_2] '.
2664: '[_3] Version 4 [_4]',
2665: '<label>'.$authtype,
2666: '</label><input type="text" size="10" name="krbarg" '.
2667: 'value="'.$krbarg.'" '.
2668: 'onchange="'.$jscall.'" />',
2669: '<label><input type="hidden" name="krbver" value="4" />',
2670: '</label>');
2671: } elsif ($can_assign{'krb5'}) {
2672: $result .= &mt
2673: ('[_1] Kerberos authenticated with domain [_2] '.
2674: '[_3] Version 5 [_4]',
2675: '<label>'.$authtype,
2676: '</label><input type="text" size="10" name="krbarg" '.
2677: 'value="'.$krbarg.'" '.
2678: 'onchange="'.$jscall.'" />',
2679: '<label><input type="hidden" name="krbver" value="5" />',
2680: '</label>');
2681: }
1.32 matthew 2682: return $result;
2683: }
2684:
1.1075.2.20 raeburn 2685: sub authform_internal {
1.586 raeburn 2686: my %in = (
1.32 matthew 2687: formname => 'document.cu',
2688: kerb_def_dom => 'MSU.EDU',
2689: @_,
2690: );
1.586 raeburn 2691: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2692: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2693: if (defined($in{'curr_authtype'})) {
2694: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2695: if ($can_assign{'int'}) {
1.772 bisitz 2696: $intcheck = 'checked="checked" ';
1.623 raeburn 2697: if (defined($in{'mode'})) {
2698: if ($in{'mode'} eq 'modifyuser') {
2699: $intcheck = '';
2700: }
2701: }
1.591 raeburn 2702: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2703: $intarg = $in{'curr_autharg'};
2704: }
2705: } else {
2706: $result = &mt('Currently internally authenticated.');
2707: return $result;
1.165 raeburn 2708: }
2709: }
1.586 raeburn 2710: } else {
2711: if ($authnum == 1) {
1.784 bisitz 2712: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2713: }
2714: }
2715: if (!$can_assign{'int'}) {
2716: return;
1.587 raeburn 2717: } elsif ($authtype eq '') {
1.591 raeburn 2718: if (defined($in{'mode'})) {
1.587 raeburn 2719: if ($in{'mode'} eq 'modifycourse') {
2720: if ($authnum == 1) {
1.1075.2.20 raeburn 2721: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2722: }
2723: }
2724: }
1.165 raeburn 2725: }
1.586 raeburn 2726: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2727: if ($authtype eq '') {
2728: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2729: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2730: }
1.605 bisitz 2731: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2732: $intarg.'" onchange="'.$jscall.'" />';
2733: $result = &mt
1.144 matthew 2734: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2735: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2736: $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 2737: return $result;
2738: }
2739:
1.1075.2.20 raeburn 2740: sub authform_local {
1.32 matthew 2741: my %in = (
2742: formname => 'document.cu',
2743: kerb_def_dom => 'MSU.EDU',
2744: @_,
2745: );
1.586 raeburn 2746: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2747: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2748: if (defined($in{'curr_authtype'})) {
2749: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2750: if ($can_assign{'loc'}) {
1.772 bisitz 2751: $loccheck = 'checked="checked" ';
1.623 raeburn 2752: if (defined($in{'mode'})) {
2753: if ($in{'mode'} eq 'modifyuser') {
2754: $loccheck = '';
2755: }
2756: }
1.591 raeburn 2757: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2758: $locarg = $in{'curr_autharg'};
2759: }
2760: } else {
2761: $result = &mt('Currently using local (institutional) authentication.');
2762: return $result;
1.165 raeburn 2763: }
2764: }
1.586 raeburn 2765: } else {
2766: if ($authnum == 1) {
1.784 bisitz 2767: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2768: }
2769: }
2770: if (!$can_assign{'loc'}) {
2771: return;
1.587 raeburn 2772: } elsif ($authtype eq '') {
1.591 raeburn 2773: if (defined($in{'mode'})) {
1.587 raeburn 2774: if ($in{'mode'} eq 'modifycourse') {
2775: if ($authnum == 1) {
1.1075.2.20 raeburn 2776: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2777: }
2778: }
2779: }
1.165 raeburn 2780: }
1.586 raeburn 2781: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2782: if ($authtype eq '') {
2783: $authtype = '<input type="radio" name="login" value="loc" '.
2784: $loccheck.' onchange="'.$jscall.'" onclick="'.
2785: $jscall.'" />';
2786: }
2787: $autharg = '<input type="text" size="10" name="locarg" value="'.
2788: $locarg.'" onchange="'.$jscall.'" />';
2789: $result = &mt('[_1] Local Authentication with argument [_2]',
2790: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2791: return $result;
2792: }
2793:
1.1075.2.20 raeburn 2794: sub authform_filesystem {
1.32 matthew 2795: my %in = (
2796: formname => 'document.cu',
2797: kerb_def_dom => 'MSU.EDU',
2798: @_,
2799: );
1.586 raeburn 2800: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2801: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2802: if (defined($in{'curr_authtype'})) {
2803: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2804: if ($can_assign{'fsys'}) {
1.772 bisitz 2805: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2806: if (defined($in{'mode'})) {
2807: if ($in{'mode'} eq 'modifyuser') {
2808: $fsyscheck = '';
2809: }
2810: }
1.586 raeburn 2811: } else {
2812: $result = &mt('Currently Filesystem Authenticated.');
2813: return $result;
2814: }
2815: }
2816: } else {
2817: if ($authnum == 1) {
1.784 bisitz 2818: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2819: }
2820: }
2821: if (!$can_assign{'fsys'}) {
2822: return;
1.587 raeburn 2823: } elsif ($authtype eq '') {
1.591 raeburn 2824: if (defined($in{'mode'})) {
1.587 raeburn 2825: if ($in{'mode'} eq 'modifycourse') {
2826: if ($authnum == 1) {
1.1075.2.20 raeburn 2827: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2828: }
2829: }
2830: }
1.586 raeburn 2831: }
2832: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2833: if ($authtype eq '') {
2834: $authtype = '<input type="radio" name="login" value="fsys" '.
2835: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2836: $jscall.'" />';
2837: }
2838: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2839: ' onchange="'.$jscall.'" />';
2840: $result = &mt
1.144 matthew 2841: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2842: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2843: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2844: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2845: 'onchange="'.$jscall.'" />');
1.32 matthew 2846: return $result;
2847: }
2848:
1.586 raeburn 2849: sub get_assignable_auth {
2850: my ($dom) = @_;
2851: if ($dom eq '') {
2852: $dom = $env{'request.role.domain'};
2853: }
2854: my %can_assign = (
2855: krb4 => 1,
2856: krb5 => 1,
2857: int => 1,
2858: loc => 1,
2859: );
2860: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2861: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2862: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2863: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2864: my $context;
2865: if ($env{'request.role'} =~ /^au/) {
2866: $context = 'author';
2867: } elsif ($env{'request.role'} =~ /^dc/) {
2868: $context = 'domain';
2869: } elsif ($env{'request.course.id'}) {
2870: $context = 'course';
2871: }
2872: if ($context) {
2873: if (ref($authhash->{$context}) eq 'HASH') {
2874: %can_assign = %{$authhash->{$context}};
2875: }
2876: }
2877: }
2878: }
2879: my $authnum = 0;
2880: foreach my $key (keys(%can_assign)) {
2881: if ($can_assign{$key}) {
2882: $authnum ++;
2883: }
2884: }
2885: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2886: $authnum --;
2887: }
2888: return ($authnum,%can_assign);
2889: }
2890:
1.80 albertel 2891: ###############################################################
2892: ## Get Kerberos Defaults for Domain ##
2893: ###############################################################
2894: ##
2895: ## Returns default kerberos version and an associated argument
2896: ## as listed in file domain.tab. If not listed, provides
2897: ## appropriate default domain and kerberos version.
2898: ##
2899: #-------------------------------------------
2900:
2901: =pod
2902:
1.648 raeburn 2903: =item * &get_kerberos_defaults()
1.80 albertel 2904:
2905: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2906: version and domain. If not found, it defaults to version 4 and the
2907: domain of the server.
1.80 albertel 2908:
1.648 raeburn 2909: =over 4
2910:
1.80 albertel 2911: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2912:
1.648 raeburn 2913: =back
2914:
2915: =back
2916:
1.80 albertel 2917: =cut
2918:
2919: #-------------------------------------------
2920: sub get_kerberos_defaults {
2921: my $domain=shift;
1.641 raeburn 2922: my ($krbdef,$krbdefdom);
2923: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2924: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2925: $krbdef = $domdefaults{'auth_def'};
2926: $krbdefdom = $domdefaults{'auth_arg_def'};
2927: } else {
1.80 albertel 2928: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2929: my $krbdefdom=$1;
2930: $krbdefdom=~tr/a-z/A-Z/;
2931: $krbdef = "krb4";
2932: }
2933: return ($krbdef,$krbdefdom);
2934: }
1.112 bowersj2 2935:
1.32 matthew 2936:
1.46 matthew 2937: ###############################################################
2938: ## Thesaurus Functions ##
2939: ###############################################################
1.20 www 2940:
1.46 matthew 2941: =pod
1.20 www 2942:
1.112 bowersj2 2943: =head1 Thesaurus Functions
2944:
2945: =over 4
2946:
1.648 raeburn 2947: =item * &initialize_keywords()
1.46 matthew 2948:
2949: Initializes the package variable %Keywords if it is empty. Uses the
2950: package variable $thesaurus_db_file.
2951:
2952: =cut
2953:
2954: ###################################################
2955:
2956: sub initialize_keywords {
2957: return 1 if (scalar keys(%Keywords));
2958: # If we are here, %Keywords is empty, so fill it up
2959: # Make sure the file we need exists...
2960: if (! -e $thesaurus_db_file) {
2961: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2962: " failed because it does not exist");
2963: return 0;
2964: }
2965: # Set up the hash as a database
2966: my %thesaurus_db;
2967: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2968: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2969: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2970: $thesaurus_db_file);
2971: return 0;
2972: }
2973: # Get the average number of appearances of a word.
2974: my $avecount = $thesaurus_db{'average.count'};
2975: # Put keywords (those that appear > average) into %Keywords
2976: while (my ($word,$data)=each (%thesaurus_db)) {
2977: my ($count,undef) = split /:/,$data;
2978: $Keywords{$word}++ if ($count > $avecount);
2979: }
2980: untie %thesaurus_db;
2981: # Remove special values from %Keywords.
1.356 albertel 2982: foreach my $value ('total.count','average.count') {
2983: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2984: }
1.46 matthew 2985: return 1;
2986: }
2987:
2988: ###################################################
2989:
2990: =pod
2991:
1.648 raeburn 2992: =item * &keyword($word)
1.46 matthew 2993:
2994: Returns true if $word is a keyword. A keyword is a word that appears more
2995: than the average number of times in the thesaurus database. Calls
2996: &initialize_keywords
2997:
2998: =cut
2999:
3000: ###################################################
1.20 www 3001:
3002: sub keyword {
1.46 matthew 3003: return if (!&initialize_keywords());
3004: my $word=lc(shift());
3005: $word=~s/\W//g;
3006: return exists($Keywords{$word});
1.20 www 3007: }
1.46 matthew 3008:
3009: ###############################################################
3010:
3011: =pod
1.20 www 3012:
1.648 raeburn 3013: =item * &get_related_words()
1.46 matthew 3014:
1.160 matthew 3015: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3016: an array of words. If the keyword is not in the thesaurus, an empty array
3017: will be returned. The order of the words returned is determined by the
3018: database which holds them.
3019:
3020: Uses global $thesaurus_db_file.
3021:
1.1057 foxr 3022:
1.46 matthew 3023: =cut
3024:
3025: ###############################################################
3026: sub get_related_words {
3027: my $keyword = shift;
3028: my %thesaurus_db;
3029: if (! -e $thesaurus_db_file) {
3030: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3031: "failed because the file does not exist");
3032: return ();
3033: }
3034: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3035: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3036: return ();
3037: }
3038: my @Words=();
1.429 www 3039: my $count=0;
1.46 matthew 3040: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3041: # The first element is the number of times
3042: # the word appears. We do not need it now.
1.429 www 3043: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3044: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3045: my $threshold=$mostfrequentcount/10;
3046: foreach my $possibleword (@RelatedWords) {
3047: my ($word,$wordcount)=split(/\,/,$possibleword);
3048: if ($wordcount>$threshold) {
3049: push(@Words,$word);
3050: $count++;
3051: if ($count>10) { last; }
3052: }
1.20 www 3053: }
3054: }
1.46 matthew 3055: untie %thesaurus_db;
3056: return @Words;
1.14 harris41 3057: }
1.46 matthew 3058:
1.112 bowersj2 3059: =pod
3060:
3061: =back
3062:
3063: =cut
1.61 www 3064:
3065: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3066: =pod
3067:
1.112 bowersj2 3068: =head1 User Name Functions
3069:
3070: =over 4
3071:
1.648 raeburn 3072: =item * &plainname($uname,$udom,$first)
1.81 albertel 3073:
1.112 bowersj2 3074: Takes a users logon name and returns it as a string in
1.226 albertel 3075: "first middle last generation" form
3076: if $first is set to 'lastname' then it returns it as
3077: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3078:
3079: =cut
1.61 www 3080:
1.295 www 3081:
1.81 albertel 3082: ###############################################################
1.61 www 3083: sub plainname {
1.226 albertel 3084: my ($uname,$udom,$first)=@_;
1.537 albertel 3085: return if (!defined($uname) || !defined($udom));
1.295 www 3086: my %names=&getnames($uname,$udom);
1.226 albertel 3087: my $name=&Apache::lonnet::format_name($names{'firstname'},
3088: $names{'middlename'},
3089: $names{'lastname'},
3090: $names{'generation'},$first);
3091: $name=~s/^\s+//;
1.62 www 3092: $name=~s/\s+$//;
3093: $name=~s/\s+/ /g;
1.353 albertel 3094: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3095: return $name;
1.61 www 3096: }
1.66 www 3097:
3098: # -------------------------------------------------------------------- Nickname
1.81 albertel 3099: =pod
3100:
1.648 raeburn 3101: =item * &nickname($uname,$udom)
1.81 albertel 3102:
3103: Gets a users name and returns it as a string as
3104:
3105: ""nickname""
1.66 www 3106:
1.81 albertel 3107: if the user has a nickname or
3108:
3109: "first middle last generation"
3110:
3111: if the user does not
3112:
3113: =cut
1.66 www 3114:
3115: sub nickname {
3116: my ($uname,$udom)=@_;
1.537 albertel 3117: return if (!defined($uname) || !defined($udom));
1.295 www 3118: my %names=&getnames($uname,$udom);
1.68 albertel 3119: my $name=$names{'nickname'};
1.66 www 3120: if ($name) {
3121: $name='"'.$name.'"';
3122: } else {
3123: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3124: $names{'lastname'}.' '.$names{'generation'};
3125: $name=~s/\s+$//;
3126: $name=~s/\s+/ /g;
3127: }
3128: return $name;
3129: }
3130:
1.295 www 3131: sub getnames {
3132: my ($uname,$udom)=@_;
1.537 albertel 3133: return if (!defined($uname) || !defined($udom));
1.433 albertel 3134: if ($udom eq 'public' && $uname eq 'public') {
3135: return ('lastname' => &mt('Public'));
3136: }
1.295 www 3137: my $id=$uname.':'.$udom;
3138: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3139: if ($cached) {
3140: return %{$names};
3141: } else {
3142: my %loadnames=&Apache::lonnet::get('environment',
3143: ['firstname','middlename','lastname','generation','nickname'],
3144: $udom,$uname);
3145: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3146: return %loadnames;
3147: }
3148: }
1.61 www 3149:
1.542 raeburn 3150: # -------------------------------------------------------------------- getemails
1.648 raeburn 3151:
1.542 raeburn 3152: =pod
3153:
1.648 raeburn 3154: =item * &getemails($uname,$udom)
1.542 raeburn 3155:
3156: Gets a user's email information and returns it as a hash with keys:
3157: notification, critnotification, permanentemail
3158:
3159: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3160: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3161:
1.648 raeburn 3162:
1.542 raeburn 3163: =cut
3164:
1.648 raeburn 3165:
1.466 albertel 3166: sub getemails {
3167: my ($uname,$udom)=@_;
3168: if ($udom eq 'public' && $uname eq 'public') {
3169: return;
3170: }
1.467 www 3171: if (!$udom) { $udom=$env{'user.domain'}; }
3172: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3173: my $id=$uname.':'.$udom;
3174: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3175: if ($cached) {
3176: return %{$names};
3177: } else {
3178: my %loadnames=&Apache::lonnet::get('environment',
3179: ['notification','critnotification',
3180: 'permanentemail'],
3181: $udom,$uname);
3182: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3183: return %loadnames;
3184: }
3185: }
3186:
1.551 albertel 3187: sub flush_email_cache {
3188: my ($uname,$udom)=@_;
3189: if (!$udom) { $udom =$env{'user.domain'}; }
3190: if (!$uname) { $uname=$env{'user.name'}; }
3191: return if ($udom eq 'public' && $uname eq 'public');
3192: my $id=$uname.':'.$udom;
3193: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3194: }
3195:
1.728 raeburn 3196: # -------------------------------------------------------------------- getlangs
3197:
3198: =pod
3199:
3200: =item * &getlangs($uname,$udom)
3201:
3202: Gets a user's language preference and returns it as a hash with key:
3203: language.
3204:
3205: =cut
3206:
3207:
3208: sub getlangs {
3209: my ($uname,$udom) = @_;
3210: if (!$udom) { $udom =$env{'user.domain'}; }
3211: if (!$uname) { $uname=$env{'user.name'}; }
3212: my $id=$uname.':'.$udom;
3213: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3214: if ($cached) {
3215: return %{$langs};
3216: } else {
3217: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3218: $udom,$uname);
3219: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3220: return %loadlangs;
3221: }
3222: }
3223:
3224: sub flush_langs_cache {
3225: my ($uname,$udom)=@_;
3226: if (!$udom) { $udom =$env{'user.domain'}; }
3227: if (!$uname) { $uname=$env{'user.name'}; }
3228: return if ($udom eq 'public' && $uname eq 'public');
3229: my $id=$uname.':'.$udom;
3230: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3231: }
3232:
1.61 www 3233: # ------------------------------------------------------------------ Screenname
1.81 albertel 3234:
3235: =pod
3236:
1.648 raeburn 3237: =item * &screenname($uname,$udom)
1.81 albertel 3238:
3239: Gets a users screenname and returns it as a string
3240:
3241: =cut
1.61 www 3242:
3243: sub screenname {
3244: my ($uname,$udom)=@_;
1.258 albertel 3245: if ($uname eq $env{'user.name'} &&
3246: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3247: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3248: return $names{'screenname'};
1.62 www 3249: }
3250:
1.212 albertel 3251:
1.802 bisitz 3252: # ------------------------------------------------------------- Confirm Wrapper
3253: =pod
3254:
1.1075.2.42 raeburn 3255: =item * &confirmwrapper($message)
1.802 bisitz 3256:
3257: Wrap messages about completion of operation in box
3258:
3259: =cut
3260:
3261: sub confirmwrapper {
3262: my ($message)=@_;
3263: if ($message) {
3264: return "\n".'<div class="LC_confirm_box">'."\n"
3265: .$message."\n"
3266: .'</div>'."\n";
3267: } else {
3268: return $message;
3269: }
3270: }
3271:
1.62 www 3272: # ------------------------------------------------------------- Message Wrapper
3273:
3274: sub messagewrapper {
1.369 www 3275: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3276: return
1.441 albertel 3277: '<a href="/adm/email?compose=individual&'.
3278: 'recname='.$username.'&recdom='.$domain.
3279: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3280: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3281: }
1.802 bisitz 3282:
1.74 www 3283: # --------------------------------------------------------------- Notes Wrapper
3284:
3285: sub noteswrapper {
3286: my ($link,$un,$do)=@_;
3287: return
1.896 amueller 3288: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3289: }
1.802 bisitz 3290:
1.62 www 3291: # ------------------------------------------------------------- Aboutme Wrapper
3292:
3293: sub aboutmewrapper {
1.1070 raeburn 3294: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3295: if (!defined($username) && !defined($domain)) {
3296: return;
3297: }
1.1075.2.15 raeburn 3298: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3299: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3300: }
3301:
3302: # ------------------------------------------------------------ Syllabus Wrapper
3303:
3304: sub syllabuswrapper {
1.707 bisitz 3305: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3306: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3307: }
1.14 harris41 3308:
1.802 bisitz 3309: # -----------------------------------------------------------------------------
3310:
1.208 matthew 3311: sub track_student_link {
1.887 raeburn 3312: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3313: my $link ="/adm/trackstudent?";
1.208 matthew 3314: my $title = 'View recent activity';
3315: if (defined($sname) && $sname !~ /^\s*$/ &&
3316: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3317: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3318: $title .= ' of this student';
1.268 albertel 3319: }
1.208 matthew 3320: if (defined($target) && $target !~ /^\s*$/) {
3321: $target = qq{target="$target"};
3322: } else {
3323: $target = '';
3324: }
1.268 albertel 3325: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3326: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3327: $title = &mt($title);
3328: $linktext = &mt($linktext);
1.448 albertel 3329: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3330: &help_open_topic('View_recent_activity');
1.208 matthew 3331: }
3332:
1.781 raeburn 3333: sub slot_reservations_link {
3334: my ($linktext,$sname,$sdom,$target) = @_;
3335: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3336: my $title = 'View slot reservation history';
3337: if (defined($sname) && $sname !~ /^\s*$/ &&
3338: defined($sdom) && $sdom !~ /^\s*$/) {
3339: $link .= "&uname=$sname&udom=$sdom";
3340: $title .= ' of this student';
3341: }
3342: if (defined($target) && $target !~ /^\s*$/) {
3343: $target = qq{target="$target"};
3344: } else {
3345: $target = '';
3346: }
3347: $title = &mt($title);
3348: $linktext = &mt($linktext);
3349: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3350: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3351:
3352: }
3353:
1.508 www 3354: # ===================================================== Display a student photo
3355:
3356:
1.509 albertel 3357: sub student_image_tag {
1.508 www 3358: my ($domain,$user)=@_;
3359: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3360: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3361: return '<img src="'.$imgsrc.'" align="right" />';
3362: } else {
3363: return '';
3364: }
3365: }
3366:
1.112 bowersj2 3367: =pod
3368:
3369: =back
3370:
3371: =head1 Access .tab File Data
3372:
3373: =over 4
3374:
1.648 raeburn 3375: =item * &languageids()
1.112 bowersj2 3376:
3377: returns list of all language ids
3378:
3379: =cut
3380:
1.14 harris41 3381: sub languageids {
1.16 harris41 3382: return sort(keys(%language));
1.14 harris41 3383: }
3384:
1.112 bowersj2 3385: =pod
3386:
1.648 raeburn 3387: =item * &languagedescription()
1.112 bowersj2 3388:
3389: returns description of a specified language id
3390:
3391: =cut
3392:
1.14 harris41 3393: sub languagedescription {
1.125 www 3394: my $code=shift;
3395: return ($supported_language{$code}?'* ':'').
3396: $language{$code}.
1.126 www 3397: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3398: }
3399:
1.1048 foxr 3400: =pod
3401:
3402: =item * &plainlanguagedescription
3403:
3404: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3405: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3406:
3407: =cut
3408:
1.145 www 3409: sub plainlanguagedescription {
3410: my $code=shift;
3411: return $language{$code};
3412: }
3413:
1.1048 foxr 3414: =pod
3415:
3416: =item * &supportedlanguagecode
3417:
3418: Returns the supported language code (e.g. sptutf maps to pt) given a language
3419: code.
3420:
3421: =cut
3422:
1.145 www 3423: sub supportedlanguagecode {
3424: my $code=shift;
3425: return $supported_language{$code};
1.97 www 3426: }
3427:
1.112 bowersj2 3428: =pod
3429:
1.1048 foxr 3430: =item * &latexlanguage()
3431:
3432: Given a language key code returns the correspondnig language to use
3433: to select the correct hyphenation on LaTeX printouts. This is undef if there
3434: is no supported hyphenation for the language code.
3435:
3436: =cut
3437:
3438: sub latexlanguage {
3439: my $code = shift;
3440: return $latex_language{$code};
3441: }
3442:
3443: =pod
3444:
3445: =item * &latexhyphenation()
3446:
3447: Same as above but what's supplied is the language as it might be stored
3448: in the metadata.
3449:
3450: =cut
3451:
3452: sub latexhyphenation {
3453: my $key = shift;
3454: return $latex_language_bykey{$key};
3455: }
3456:
3457: =pod
3458:
1.648 raeburn 3459: =item * ©rightids()
1.112 bowersj2 3460:
3461: returns list of all copyrights
3462:
3463: =cut
3464:
3465: sub copyrightids {
3466: return sort(keys(%cprtag));
3467: }
3468:
3469: =pod
3470:
1.648 raeburn 3471: =item * ©rightdescription()
1.112 bowersj2 3472:
3473: returns description of a specified copyright id
3474:
3475: =cut
3476:
3477: sub copyrightdescription {
1.166 www 3478: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3479: }
1.197 matthew 3480:
3481: =pod
3482:
1.648 raeburn 3483: =item * &source_copyrightids()
1.192 taceyjo1 3484:
3485: returns list of all source copyrights
3486:
3487: =cut
3488:
3489: sub source_copyrightids {
3490: return sort(keys(%scprtag));
3491: }
3492:
3493: =pod
3494:
1.648 raeburn 3495: =item * &source_copyrightdescription()
1.192 taceyjo1 3496:
3497: returns description of a specified source copyright id
3498:
3499: =cut
3500:
3501: sub source_copyrightdescription {
3502: return &mt($scprtag{shift(@_)});
3503: }
1.112 bowersj2 3504:
3505: =pod
3506:
1.648 raeburn 3507: =item * &filecategories()
1.112 bowersj2 3508:
3509: returns list of all file categories
3510:
3511: =cut
3512:
3513: sub filecategories {
3514: return sort(keys(%category_extensions));
3515: }
3516:
3517: =pod
3518:
1.648 raeburn 3519: =item * &filecategorytypes()
1.112 bowersj2 3520:
3521: returns list of file types belonging to a given file
3522: category
3523:
3524: =cut
3525:
3526: sub filecategorytypes {
1.356 albertel 3527: my ($cat) = @_;
3528: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3529: }
3530:
3531: =pod
3532:
1.648 raeburn 3533: =item * &fileembstyle()
1.112 bowersj2 3534:
3535: returns embedding style for a specified file type
3536:
3537: =cut
3538:
3539: sub fileembstyle {
3540: return $fe{lc(shift(@_))};
1.169 www 3541: }
3542:
1.351 www 3543: sub filemimetype {
3544: return $fm{lc(shift(@_))};
3545: }
3546:
1.169 www 3547:
3548: sub filecategoryselect {
3549: my ($name,$value)=@_;
1.189 matthew 3550: return &select_form($value,$name,
1.970 raeburn 3551: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3552: }
3553:
3554: =pod
3555:
1.648 raeburn 3556: =item * &filedescription()
1.112 bowersj2 3557:
3558: returns description for a specified file type
3559:
3560: =cut
3561:
3562: sub filedescription {
1.188 matthew 3563: my $file_description = $fd{lc(shift())};
3564: $file_description =~ s:([\[\]]):~$1:g;
3565: return &mt($file_description);
1.112 bowersj2 3566: }
3567:
3568: =pod
3569:
1.648 raeburn 3570: =item * &filedescriptionex()
1.112 bowersj2 3571:
3572: returns description for a specified file type with
3573: extra formatting
3574:
3575: =cut
3576:
3577: sub filedescriptionex {
3578: my $ex=shift;
1.188 matthew 3579: my $file_description = $fd{lc($ex)};
3580: $file_description =~ s:([\[\]]):~$1:g;
3581: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3582: }
3583:
3584: # End of .tab access
3585: =pod
3586:
3587: =back
3588:
3589: =cut
3590:
3591: # ------------------------------------------------------------------ File Types
3592: sub fileextensions {
3593: return sort(keys(%fe));
3594: }
3595:
1.97 www 3596: # ----------------------------------------------------------- Display Languages
3597: # returns a hash with all desired display languages
3598: #
3599:
3600: sub display_languages {
3601: my %languages=();
1.695 raeburn 3602: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3603: $languages{$lang}=1;
1.97 www 3604: }
3605: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3606: if ($env{'form.displaylanguage'}) {
1.356 albertel 3607: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3608: $languages{$lang}=1;
1.97 www 3609: }
3610: }
3611: return %languages;
1.14 harris41 3612: }
3613:
1.582 albertel 3614: sub languages {
3615: my ($possible_langs) = @_;
1.695 raeburn 3616: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3617: if (!ref($possible_langs)) {
3618: if( wantarray ) {
3619: return @preferred_langs;
3620: } else {
3621: return $preferred_langs[0];
3622: }
3623: }
3624: my %possibilities = map { $_ => 1 } (@$possible_langs);
3625: my @preferred_possibilities;
3626: foreach my $preferred_lang (@preferred_langs) {
3627: if (exists($possibilities{$preferred_lang})) {
3628: push(@preferred_possibilities, $preferred_lang);
3629: }
3630: }
3631: if( wantarray ) {
3632: return @preferred_possibilities;
3633: }
3634: return $preferred_possibilities[0];
3635: }
3636:
1.742 raeburn 3637: sub user_lang {
3638: my ($touname,$toudom,$fromcid) = @_;
3639: my @userlangs;
3640: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3641: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3642: $env{'course.'.$fromcid.'.languages'}));
3643: } else {
3644: my %langhash = &getlangs($touname,$toudom);
3645: if ($langhash{'languages'} ne '') {
3646: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3647: } else {
3648: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3649: if ($domdefs{'lang_def'} ne '') {
3650: @userlangs = ($domdefs{'lang_def'});
3651: }
3652: }
3653: }
3654: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3655: my $user_lh = Apache::localize->get_handle(@languages);
3656: return $user_lh;
3657: }
3658:
3659:
1.112 bowersj2 3660: ###############################################################
3661: ## Student Answer Attempts ##
3662: ###############################################################
3663:
3664: =pod
3665:
3666: =head1 Alternate Problem Views
3667:
3668: =over 4
3669:
1.648 raeburn 3670: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3671: $getattempt, $regexp, $gradesub)
3672:
3673: Return string with previous attempt on problem. Arguments:
3674:
3675: =over 4
3676:
3677: =item * $symb: Problem, including path
3678:
3679: =item * $username: username of the desired student
3680:
3681: =item * $domain: domain of the desired student
1.14 harris41 3682:
1.112 bowersj2 3683: =item * $course: Course ID
1.14 harris41 3684:
1.112 bowersj2 3685: =item * $getattempt: Leave blank for all attempts, otherwise put
3686: something
1.14 harris41 3687:
1.112 bowersj2 3688: =item * $regexp: if string matches this regexp, the string will be
3689: sent to $gradesub
1.14 harris41 3690:
1.112 bowersj2 3691: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3692:
1.112 bowersj2 3693: =back
1.14 harris41 3694:
1.112 bowersj2 3695: The output string is a table containing all desired attempts, if any.
1.16 harris41 3696:
1.112 bowersj2 3697: =cut
1.1 albertel 3698:
3699: sub get_previous_attempt {
1.43 ng 3700: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3701: my $prevattempts='';
1.43 ng 3702: no strict 'refs';
1.1 albertel 3703: if ($symb) {
1.3 albertel 3704: my (%returnhash)=
3705: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3706: if ($returnhash{'version'}) {
3707: my %lasthash=();
3708: my $version;
3709: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3710: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3711: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3712: }
1.1 albertel 3713: }
1.596 albertel 3714: $prevattempts=&start_data_table().&start_data_table_header_row();
3715: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3716: my (%typeparts,%lasthidden);
1.945 raeburn 3717: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3718: foreach my $key (sort(keys(%lasthash))) {
3719: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3720: if ($#parts > 0) {
1.31 albertel 3721: my $data=$parts[-1];
1.989 raeburn 3722: next if ($data eq 'foilorder');
1.31 albertel 3723: pop(@parts);
1.1010 www 3724: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3725: if ($data eq 'type') {
3726: unless ($showsurv) {
3727: my $id = join(',',@parts);
3728: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3729: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3730: $lasthidden{$ign.'.'.$id} = 1;
3731: }
1.945 raeburn 3732: }
1.1010 www 3733: }
1.31 albertel 3734: } else {
1.41 ng 3735: if ($#parts == 0) {
3736: $prevattempts.='<th>'.$parts[0].'</th>';
3737: } else {
3738: $prevattempts.='<th>'.$ign.'</th>';
3739: }
1.31 albertel 3740: }
1.16 harris41 3741: }
1.596 albertel 3742: $prevattempts.=&end_data_table_header_row();
1.40 ng 3743: if ($getattempt eq '') {
3744: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3745: my @hidden;
3746: if (%typeparts) {
3747: foreach my $id (keys(%typeparts)) {
3748: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3749: push(@hidden,$id);
3750: }
3751: }
3752: }
3753: $prevattempts.=&start_data_table_row().
3754: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3755: if (@hidden) {
3756: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3757: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3758: my $hide;
3759: foreach my $id (@hidden) {
3760: if ($key =~ /^\Q$id\E/) {
3761: $hide = 1;
3762: last;
3763: }
3764: }
3765: if ($hide) {
3766: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3767: if (($data eq 'award') || ($data eq 'awarddetail')) {
3768: my $value = &format_previous_attempt_value($key,
3769: $returnhash{$version.':'.$key});
3770: $prevattempts.='<td>'.$value.' </td>';
3771: } else {
3772: $prevattempts.='<td> </td>';
3773: }
3774: } else {
3775: if ($key =~ /\./) {
3776: my $value = &format_previous_attempt_value($key,
3777: $returnhash{$version.':'.$key});
3778: $prevattempts.='<td>'.$value.' </td>';
3779: } else {
3780: $prevattempts.='<td> </td>';
3781: }
3782: }
3783: }
3784: } else {
3785: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3786: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3787: my $value = &format_previous_attempt_value($key,
3788: $returnhash{$version.':'.$key});
3789: $prevattempts.='<td>'.$value.' </td>';
3790: }
3791: }
3792: $prevattempts.=&end_data_table_row();
1.40 ng 3793: }
1.1 albertel 3794: }
1.945 raeburn 3795: my @currhidden = keys(%lasthidden);
1.596 albertel 3796: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3797: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3798: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3799: if (%typeparts) {
3800: my $hidden;
3801: foreach my $id (@currhidden) {
3802: if ($key =~ /^\Q$id\E/) {
3803: $hidden = 1;
3804: last;
3805: }
3806: }
3807: if ($hidden) {
3808: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3809: if (($data eq 'award') || ($data eq 'awarddetail')) {
3810: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3811: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3812: $value = &$gradesub($value);
3813: }
3814: $prevattempts.='<td>'.$value.' </td>';
3815: } else {
3816: $prevattempts.='<td> </td>';
3817: }
3818: } else {
3819: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3820: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3821: $value = &$gradesub($value);
3822: }
3823: $prevattempts.='<td>'.$value.' </td>';
3824: }
3825: } else {
3826: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3827: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3828: $value = &$gradesub($value);
3829: }
3830: $prevattempts.='<td>'.$value.' </td>';
3831: }
1.16 harris41 3832: }
1.596 albertel 3833: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3834: } else {
1.596 albertel 3835: $prevattempts=
3836: &start_data_table().&start_data_table_row().
3837: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3838: &end_data_table_row().&end_data_table();
1.1 albertel 3839: }
3840: } else {
1.596 albertel 3841: $prevattempts=
3842: &start_data_table().&start_data_table_row().
3843: '<td>'.&mt('No data.').'</td>'.
3844: &end_data_table_row().&end_data_table();
1.1 albertel 3845: }
1.10 albertel 3846: }
3847:
1.581 albertel 3848: sub format_previous_attempt_value {
3849: my ($key,$value) = @_;
1.1011 www 3850: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3851: $value = &Apache::lonlocal::locallocaltime($value);
3852: } elsif (ref($value) eq 'ARRAY') {
3853: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3854: } elsif ($key =~ /answerstring$/) {
3855: my %answers = &Apache::lonnet::str2hash($value);
3856: my @anskeys = sort(keys(%answers));
3857: if (@anskeys == 1) {
3858: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3859: if ($answer =~ m{\0}) {
3860: $answer =~ s{\0}{,}g;
1.988 raeburn 3861: }
3862: my $tag_internal_answer_name = 'INTERNAL';
3863: if ($anskeys[0] eq $tag_internal_answer_name) {
3864: $value = $answer;
3865: } else {
3866: $value = $anskeys[0].'='.$answer;
3867: }
3868: } else {
3869: foreach my $ans (@anskeys) {
3870: my $answer = $answers{$ans};
1.1001 raeburn 3871: if ($answer =~ m{\0}) {
3872: $answer =~ s{\0}{,}g;
1.988 raeburn 3873: }
3874: $value .= $ans.'='.$answer.'<br />';;
3875: }
3876: }
1.581 albertel 3877: } else {
3878: $value = &unescape($value);
3879: }
3880: return $value;
3881: }
3882:
3883:
1.107 albertel 3884: sub relative_to_absolute {
3885: my ($url,$output)=@_;
3886: my $parser=HTML::TokeParser->new(\$output);
3887: my $token;
3888: my $thisdir=$url;
3889: my @rlinks=();
3890: while ($token=$parser->get_token) {
3891: if ($token->[0] eq 'S') {
3892: if ($token->[1] eq 'a') {
3893: if ($token->[2]->{'href'}) {
3894: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3895: }
3896: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3897: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3898: } elsif ($token->[1] eq 'base') {
3899: $thisdir=$token->[2]->{'href'};
3900: }
3901: }
3902: }
3903: $thisdir=~s-/[^/]*$--;
1.356 albertel 3904: foreach my $link (@rlinks) {
1.726 raeburn 3905: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3906: ($link=~/^\//) ||
3907: ($link=~/^javascript:/i) ||
3908: ($link=~/^mailto:/i) ||
3909: ($link=~/^\#/)) {
3910: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3911: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3912: }
3913: }
3914: # -------------------------------------------------- Deal with Applet codebases
3915: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3916: return $output;
3917: }
3918:
1.112 bowersj2 3919: =pod
3920:
1.648 raeburn 3921: =item * &get_student_view()
1.112 bowersj2 3922:
3923: show a snapshot of what student was looking at
3924:
3925: =cut
3926:
1.10 albertel 3927: sub get_student_view {
1.186 albertel 3928: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3929: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3930: my (%form);
1.10 albertel 3931: my @elements=('symb','courseid','domain','username');
3932: foreach my $element (@elements) {
1.186 albertel 3933: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3934: }
1.186 albertel 3935: if (defined($moreenv)) {
3936: %form=(%form,%{$moreenv});
3937: }
1.236 albertel 3938: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3939: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3940: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3941: $userview=~s/\<body[^\>]*\>//gi;
3942: $userview=~s/\<\/body\>//gi;
3943: $userview=~s/\<html\>//gi;
3944: $userview=~s/\<\/html\>//gi;
3945: $userview=~s/\<head\>//gi;
3946: $userview=~s/\<\/head\>//gi;
3947: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3948: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3949: if (wantarray) {
3950: return ($userview,$response);
3951: } else {
3952: return $userview;
3953: }
3954: }
3955:
3956: sub get_student_view_with_retries {
3957: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3958:
3959: my $ok = 0; # True if we got a good response.
3960: my $content;
3961: my $response;
3962:
3963: # Try to get the student_view done. within the retries count:
3964:
3965: do {
3966: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3967: $ok = $response->is_success;
3968: if (!$ok) {
3969: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3970: }
3971: $retries--;
3972: } while (!$ok && ($retries > 0));
3973:
3974: if (!$ok) {
3975: $content = ''; # On error return an empty content.
3976: }
1.651 www 3977: if (wantarray) {
3978: return ($content, $response);
3979: } else {
3980: return $content;
3981: }
1.11 albertel 3982: }
3983:
1.112 bowersj2 3984: =pod
3985:
1.648 raeburn 3986: =item * &get_student_answers()
1.112 bowersj2 3987:
3988: show a snapshot of how student was answering problem
3989:
3990: =cut
3991:
1.11 albertel 3992: sub get_student_answers {
1.100 sakharuk 3993: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3994: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3995: my (%moreenv);
1.11 albertel 3996: my @elements=('symb','courseid','domain','username');
3997: foreach my $element (@elements) {
1.186 albertel 3998: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3999: }
1.186 albertel 4000: $moreenv{'grade_target'}='answer';
4001: %moreenv=(%form,%moreenv);
1.497 raeburn 4002: $feedurl = &Apache::lonnet::clutter($feedurl);
4003: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4004: return $userview;
1.1 albertel 4005: }
1.116 albertel 4006:
4007: =pod
4008:
4009: =item * &submlink()
4010:
1.242 albertel 4011: Inputs: $text $uname $udom $symb $target
1.116 albertel 4012:
4013: Returns: A link to grades.pm such as to see the SUBM view of a student
4014:
4015: =cut
4016:
4017: ###############################################
4018: sub submlink {
1.242 albertel 4019: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4020: if (!($uname && $udom)) {
4021: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4022: &Apache::lonnet::whichuser($symb);
1.116 albertel 4023: if (!$symb) { $symb=$cursymb; }
4024: }
1.254 matthew 4025: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4026: $symb=&escape($symb);
1.960 bisitz 4027: if ($target) { $target=" target=\"$target\""; }
4028: return
4029: '<a href="/adm/grades?command=submission'.
4030: '&symb='.$symb.
4031: '&student='.$uname.
4032: '&userdom='.$udom.'"'.
4033: $target.'>'.$text.'</a>';
1.242 albertel 4034: }
4035: ##############################################
4036:
4037: =pod
4038:
4039: =item * &pgrdlink()
4040:
4041: Inputs: $text $uname $udom $symb $target
4042:
4043: Returns: A link to grades.pm such as to see the PGRD view of a student
4044:
4045: =cut
4046:
4047: ###############################################
4048: sub pgrdlink {
4049: my $link=&submlink(@_);
4050: $link=~s/(&command=submission)/$1&showgrading=yes/;
4051: return $link;
4052: }
4053: ##############################################
4054:
4055: =pod
4056:
4057: =item * &pprmlink()
4058:
4059: Inputs: $text $uname $udom $symb $target
4060:
4061: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4062: student and a specific resource
1.242 albertel 4063:
4064: =cut
4065:
4066: ###############################################
4067: sub pprmlink {
4068: my ($text,$uname,$udom,$symb,$target)=@_;
4069: if (!($uname && $udom)) {
4070: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4071: &Apache::lonnet::whichuser($symb);
1.242 albertel 4072: if (!$symb) { $symb=$cursymb; }
4073: }
1.254 matthew 4074: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4075: $symb=&escape($symb);
1.242 albertel 4076: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4077: return '<a href="/adm/parmset?command=set&'.
4078: 'symb='.$symb.'&uname='.$uname.
4079: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4080: }
4081: ##############################################
1.37 matthew 4082:
1.112 bowersj2 4083: =pod
4084:
4085: =back
4086:
4087: =cut
4088:
1.37 matthew 4089: ###############################################
1.51 www 4090:
4091:
4092: sub timehash {
1.687 raeburn 4093: my ($thistime) = @_;
4094: my $timezone = &Apache::lonlocal::gettimezone();
4095: my $dt = DateTime->from_epoch(epoch => $thistime)
4096: ->set_time_zone($timezone);
4097: my $wday = $dt->day_of_week();
4098: if ($wday == 7) { $wday = 0; }
4099: return ( 'second' => $dt->second(),
4100: 'minute' => $dt->minute(),
4101: 'hour' => $dt->hour(),
4102: 'day' => $dt->day_of_month(),
4103: 'month' => $dt->month(),
4104: 'year' => $dt->year(),
4105: 'weekday' => $wday,
4106: 'dayyear' => $dt->day_of_year(),
4107: 'dlsav' => $dt->is_dst() );
1.51 www 4108: }
4109:
1.370 www 4110: sub utc_string {
4111: my ($date)=@_;
1.371 www 4112: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4113: }
4114:
1.51 www 4115: sub maketime {
4116: my %th=@_;
1.687 raeburn 4117: my ($epoch_time,$timezone,$dt);
4118: $timezone = &Apache::lonlocal::gettimezone();
4119: eval {
4120: $dt = DateTime->new( year => $th{'year'},
4121: month => $th{'month'},
4122: day => $th{'day'},
4123: hour => $th{'hour'},
4124: minute => $th{'minute'},
4125: second => $th{'second'},
4126: time_zone => $timezone,
4127: );
4128: };
4129: if (!$@) {
4130: $epoch_time = $dt->epoch;
4131: if ($epoch_time) {
4132: return $epoch_time;
4133: }
4134: }
1.51 www 4135: return POSIX::mktime(
4136: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4137: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4138: }
4139:
4140: #########################################
1.51 www 4141:
4142: sub findallcourses {
1.482 raeburn 4143: my ($roles,$uname,$udom) = @_;
1.355 albertel 4144: my %roles;
4145: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4146: my %courses;
1.51 www 4147: my $now=time;
1.482 raeburn 4148: if (!defined($uname)) {
4149: $uname = $env{'user.name'};
4150: }
4151: if (!defined($udom)) {
4152: $udom = $env{'user.domain'};
4153: }
4154: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4155: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4156: if (!%roles) {
4157: %roles = (
4158: cc => 1,
1.907 raeburn 4159: co => 1,
1.482 raeburn 4160: in => 1,
4161: ep => 1,
4162: ta => 1,
4163: cr => 1,
4164: st => 1,
4165: );
4166: }
4167: foreach my $entry (keys(%roleshash)) {
4168: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4169: if ($trole =~ /^cr/) {
4170: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4171: } else {
4172: next if (!exists($roles{$trole}));
4173: }
4174: if ($tend) {
4175: next if ($tend < $now);
4176: }
4177: if ($tstart) {
4178: next if ($tstart > $now);
4179: }
1.1058 raeburn 4180: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4181: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4182: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4183: if ($secpart eq '') {
4184: ($cnum,$role) = split(/_/,$cnumpart);
4185: $sec = 'none';
1.1058 raeburn 4186: $value .= $cnum.'/';
1.482 raeburn 4187: } else {
4188: $cnum = $cnumpart;
4189: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4190: $value .= $cnum.'/'.$sec;
4191: }
4192: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4193: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4194: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4195: }
4196: } else {
4197: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4198: }
1.482 raeburn 4199: }
4200: } else {
4201: foreach my $key (keys(%env)) {
1.483 albertel 4202: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4203: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4204: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4205: next if ($role eq 'ca' || $role eq 'aa');
4206: next if (%roles && !exists($roles{$role}));
4207: my ($starttime,$endtime)=split(/\./,$env{$key});
4208: my $active=1;
4209: if ($starttime) {
4210: if ($now<$starttime) { $active=0; }
4211: }
4212: if ($endtime) {
4213: if ($now>$endtime) { $active=0; }
4214: }
4215: if ($active) {
1.1058 raeburn 4216: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4217: if ($sec eq '') {
4218: $sec = 'none';
1.1058 raeburn 4219: } else {
4220: $value .= $sec;
4221: }
4222: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4223: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4224: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4225: }
4226: } else {
4227: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4228: }
1.474 raeburn 4229: }
4230: }
1.51 www 4231: }
4232: }
1.474 raeburn 4233: return %courses;
1.51 www 4234: }
1.37 matthew 4235:
1.54 www 4236: ###############################################
1.474 raeburn 4237:
4238: sub blockcheck {
1.1062 raeburn 4239: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4240:
4241: if (!defined($udom)) {
4242: $udom = $env{'user.domain'};
4243: }
4244: if (!defined($uname)) {
4245: $uname = $env{'user.name'};
4246: }
4247:
4248: # If uname and udom are for a course, check for blocks in the course.
4249:
4250: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4251: my ($startblock,$endblock,$triggerblock) =
4252: &get_blocks($setters,$activity,$udom,$uname,$url);
4253: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4254: }
1.474 raeburn 4255:
1.502 raeburn 4256: my $startblock = 0;
4257: my $endblock = 0;
1.1062 raeburn 4258: my $triggerblock = '';
1.482 raeburn 4259: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4260:
1.490 raeburn 4261: # If uname is for a user, and activity is course-specific, i.e.,
4262: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4263:
1.490 raeburn 4264: if (($activity eq 'boards' || $activity eq 'chat' ||
4265: $activity eq 'groups') && ($env{'request.course.id'})) {
4266: foreach my $key (keys(%live_courses)) {
4267: if ($key ne $env{'request.course.id'}) {
4268: delete($live_courses{$key});
4269: }
4270: }
4271: }
4272:
4273: my $otheruser = 0;
4274: my %own_courses;
4275: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4276: # Resource belongs to user other than current user.
4277: $otheruser = 1;
4278: # Gather courses for current user
4279: %own_courses =
4280: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4281: }
4282:
4283: # Gather active course roles - course coordinator, instructor,
4284: # exam proctor, ta, student, or custom role.
1.474 raeburn 4285:
4286: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4287: my ($cdom,$cnum);
4288: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4289: $cdom = $env{'course.'.$course.'.domain'};
4290: $cnum = $env{'course.'.$course.'.num'};
4291: } else {
1.490 raeburn 4292: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4293: }
4294: my $no_ownblock = 0;
4295: my $no_userblock = 0;
1.533 raeburn 4296: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4297: # Check if current user has 'evb' priv for this
4298: if (defined($own_courses{$course})) {
4299: foreach my $sec (keys(%{$own_courses{$course}})) {
4300: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4301: if ($sec ne 'none') {
4302: $checkrole .= '/'.$sec;
4303: }
4304: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4305: $no_ownblock = 1;
4306: last;
4307: }
4308: }
4309: }
4310: # if they have 'evb' priv and are currently not playing student
4311: next if (($no_ownblock) &&
4312: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4313: }
1.474 raeburn 4314: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4315: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4316: if ($sec ne 'none') {
1.482 raeburn 4317: $checkrole .= '/'.$sec;
1.474 raeburn 4318: }
1.490 raeburn 4319: if ($otheruser) {
4320: # Resource belongs to user other than current user.
4321: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4322: my (%allroles,%userroles);
4323: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4324: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4325: my ($trole,$tdom,$tnum,$tsec);
4326: if ($entry =~ /^cr/) {
4327: ($trole,$tdom,$tnum,$tsec) =
4328: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4329: } else {
4330: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4331: }
4332: my ($spec,$area,$trest);
4333: $area = '/'.$tdom.'/'.$tnum;
4334: $trest = $tnum;
4335: if ($tsec ne '') {
4336: $area .= '/'.$tsec;
4337: $trest .= '/'.$tsec;
4338: }
4339: $spec = $trole.'.'.$area;
4340: if ($trole =~ /^cr/) {
4341: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4342: $tdom,$spec,$trest,$area);
4343: } else {
4344: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4345: $tdom,$spec,$trest,$area);
4346: }
4347: }
4348: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4349: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4350: if ($1) {
4351: $no_userblock = 1;
4352: last;
4353: }
1.486 raeburn 4354: }
4355: }
1.490 raeburn 4356: } else {
4357: # Resource belongs to current user
4358: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4359: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4360: $no_ownblock = 1;
4361: last;
4362: }
1.474 raeburn 4363: }
4364: }
4365: # if they have the evb priv and are currently not playing student
1.482 raeburn 4366: next if (($no_ownblock) &&
1.491 albertel 4367: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4368: next if ($no_userblock);
1.474 raeburn 4369:
1.866 kalberla 4370: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4371: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4372:
1.1062 raeburn 4373: my ($start,$end,$trigger) =
4374: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4375: if (($start != 0) &&
4376: (($startblock == 0) || ($startblock > $start))) {
4377: $startblock = $start;
1.1062 raeburn 4378: if ($trigger ne '') {
4379: $triggerblock = $trigger;
4380: }
1.502 raeburn 4381: }
4382: if (($end != 0) &&
4383: (($endblock == 0) || ($endblock < $end))) {
4384: $endblock = $end;
1.1062 raeburn 4385: if ($trigger ne '') {
4386: $triggerblock = $trigger;
4387: }
1.502 raeburn 4388: }
1.490 raeburn 4389: }
1.1062 raeburn 4390: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4391: }
4392:
4393: sub get_blocks {
1.1062 raeburn 4394: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4395: my $startblock = 0;
4396: my $endblock = 0;
1.1062 raeburn 4397: my $triggerblock = '';
1.490 raeburn 4398: my $course = $cdom.'_'.$cnum;
4399: $setters->{$course} = {};
4400: $setters->{$course}{'staff'} = [];
4401: $setters->{$course}{'times'} = [];
1.1062 raeburn 4402: $setters->{$course}{'triggers'} = [];
4403: my (@blockers,%triggered);
4404: my $now = time;
4405: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4406: if ($activity eq 'docs') {
4407: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4408: foreach my $block (@blockers) {
4409: if ($block =~ /^firstaccess____(.+)$/) {
4410: my $item = $1;
4411: my $type = 'map';
4412: my $timersymb = $item;
4413: if ($item eq 'course') {
4414: $type = 'course';
4415: } elsif ($item =~ /___\d+___/) {
4416: $type = 'resource';
4417: } else {
4418: $timersymb = &Apache::lonnet::symbread($item);
4419: }
4420: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4421: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4422: $triggered{$block} = {
4423: start => $start,
4424: end => $end,
4425: type => $type,
4426: };
4427: }
4428: }
4429: } else {
4430: foreach my $block (keys(%commblocks)) {
4431: if ($block =~ m/^(\d+)____(\d+)$/) {
4432: my ($start,$end) = ($1,$2);
4433: if ($start <= time && $end >= time) {
4434: if (ref($commblocks{$block}) eq 'HASH') {
4435: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4436: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4437: unless(grep(/^\Q$block\E$/,@blockers)) {
4438: push(@blockers,$block);
4439: }
4440: }
4441: }
4442: }
4443: }
4444: } elsif ($block =~ /^firstaccess____(.+)$/) {
4445: my $item = $1;
4446: my $timersymb = $item;
4447: my $type = 'map';
4448: if ($item eq 'course') {
4449: $type = 'course';
4450: } elsif ($item =~ /___\d+___/) {
4451: $type = 'resource';
4452: } else {
4453: $timersymb = &Apache::lonnet::symbread($item);
4454: }
4455: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4456: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4457: if ($start && $end) {
4458: if (($start <= time) && ($end >= time)) {
4459: unless (grep(/^\Q$block\E$/,@blockers)) {
4460: push(@blockers,$block);
4461: $triggered{$block} = {
4462: start => $start,
4463: end => $end,
4464: type => $type,
4465: };
4466: }
4467: }
1.490 raeburn 4468: }
1.1062 raeburn 4469: }
4470: }
4471: }
4472: foreach my $blocker (@blockers) {
4473: my ($staff_name,$staff_dom,$title,$blocks) =
4474: &parse_block_record($commblocks{$blocker});
4475: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4476: my ($start,$end,$triggertype);
4477: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4478: ($start,$end) = ($1,$2);
4479: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4480: $start = $triggered{$blocker}{'start'};
4481: $end = $triggered{$blocker}{'end'};
4482: $triggertype = $triggered{$blocker}{'type'};
4483: }
4484: if ($start) {
4485: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4486: if ($triggertype) {
4487: push(@{$$setters{$course}{'triggers'}},$triggertype);
4488: } else {
4489: push(@{$$setters{$course}{'triggers'}},0);
4490: }
4491: if ( ($startblock == 0) || ($startblock > $start) ) {
4492: $startblock = $start;
4493: if ($triggertype) {
4494: $triggerblock = $blocker;
1.474 raeburn 4495: }
4496: }
1.1062 raeburn 4497: if ( ($endblock == 0) || ($endblock < $end) ) {
4498: $endblock = $end;
4499: if ($triggertype) {
4500: $triggerblock = $blocker;
4501: }
4502: }
1.474 raeburn 4503: }
4504: }
1.1062 raeburn 4505: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4506: }
4507:
4508: sub parse_block_record {
4509: my ($record) = @_;
4510: my ($setuname,$setudom,$title,$blocks);
4511: if (ref($record) eq 'HASH') {
4512: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4513: $title = &unescape($record->{'event'});
4514: $blocks = $record->{'blocks'};
4515: } else {
4516: my @data = split(/:/,$record,3);
4517: if (scalar(@data) eq 2) {
4518: $title = $data[1];
4519: ($setuname,$setudom) = split(/@/,$data[0]);
4520: } else {
4521: ($setuname,$setudom,$title) = @data;
4522: }
4523: $blocks = { 'com' => 'on' };
4524: }
4525: return ($setuname,$setudom,$title,$blocks);
4526: }
4527:
1.854 kalberla 4528: sub blocking_status {
1.1062 raeburn 4529: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4530: my %setters;
1.890 droeschl 4531:
1.1061 raeburn 4532: # check for active blocking
1.1062 raeburn 4533: my ($startblock,$endblock,$triggerblock) =
4534: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4535: my $blocked = 0;
4536: if ($startblock && $endblock) {
4537: $blocked = 1;
4538: }
1.890 droeschl 4539:
1.1061 raeburn 4540: # caller just wants to know whether a block is active
4541: if (!wantarray) { return $blocked; }
4542:
4543: # build a link to a popup window containing the details
4544: my $querystring = "?activity=$activity";
4545: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4546: if ($activity eq 'port') {
4547: $querystring .= "&udom=$udom" if $udom;
4548: $querystring .= "&uname=$uname" if $uname;
4549: } elsif ($activity eq 'docs') {
4550: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4551: }
1.1061 raeburn 4552:
4553: my $output .= <<'END_MYBLOCK';
4554: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4555: var options = "width=" + w + ",height=" + h + ",";
4556: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4557: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4558: var newWin = window.open(url, wdwName, options);
4559: newWin.focus();
4560: }
1.890 droeschl 4561: END_MYBLOCK
1.854 kalberla 4562:
1.1061 raeburn 4563: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4564:
1.1061 raeburn 4565: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4566: my $text = &mt('Communication Blocked');
4567: if ($activity eq 'docs') {
4568: $text = &mt('Content Access Blocked');
1.1063 raeburn 4569: } elsif ($activity eq 'printout') {
4570: $text = &mt('Printing Blocked');
1.1062 raeburn 4571: }
1.1061 raeburn 4572: $output .= <<"END_BLOCK";
1.867 kalberla 4573: <div class='LC_comblock'>
1.869 kalberla 4574: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4575: title='$text'>
4576: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4577: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4578: title='$text'>$text</a>
1.867 kalberla 4579: </div>
4580:
4581: END_BLOCK
1.474 raeburn 4582:
1.1061 raeburn 4583: return ($blocked, $output);
1.854 kalberla 4584: }
1.490 raeburn 4585:
1.60 matthew 4586: ###############################################
4587:
1.682 raeburn 4588: sub check_ip_acc {
4589: my ($acc)=@_;
4590: &Apache::lonxml::debug("acc is $acc");
4591: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4592: return 1;
4593: }
4594: my $allowed=0;
4595: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4596:
4597: my $name;
4598: foreach my $pattern (split(',',$acc)) {
4599: $pattern =~ s/^\s*//;
4600: $pattern =~ s/\s*$//;
4601: if ($pattern =~ /\*$/) {
4602: #35.8.*
4603: $pattern=~s/\*//;
4604: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4605: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4606: #35.8.3.[34-56]
4607: my $low=$2;
4608: my $high=$3;
4609: $pattern=$1;
4610: if ($ip =~ /^\Q$pattern\E/) {
4611: my $last=(split(/\./,$ip))[3];
4612: if ($last <=$high && $last >=$low) { $allowed=1; }
4613: }
4614: } elsif ($pattern =~ /^\*/) {
4615: #*.msu.edu
4616: $pattern=~s/\*//;
4617: if (!defined($name)) {
4618: use Socket;
4619: my $netaddr=inet_aton($ip);
4620: ($name)=gethostbyaddr($netaddr,AF_INET);
4621: }
4622: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4623: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4624: #127.0.0.1
4625: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4626: } else {
4627: #some.name.com
4628: if (!defined($name)) {
4629: use Socket;
4630: my $netaddr=inet_aton($ip);
4631: ($name)=gethostbyaddr($netaddr,AF_INET);
4632: }
4633: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4634: }
4635: if ($allowed) { last; }
4636: }
4637: return $allowed;
4638: }
4639:
4640: ###############################################
4641:
1.60 matthew 4642: =pod
4643:
1.112 bowersj2 4644: =head1 Domain Template Functions
4645:
4646: =over 4
4647:
4648: =item * &determinedomain()
1.60 matthew 4649:
4650: Inputs: $domain (usually will be undef)
4651:
1.63 www 4652: Returns: Determines which domain should be used for designs
1.60 matthew 4653:
4654: =cut
1.54 www 4655:
1.60 matthew 4656: ###############################################
1.63 www 4657: sub determinedomain {
4658: my $domain=shift;
1.531 albertel 4659: if (! $domain) {
1.60 matthew 4660: # Determine domain if we have not been given one
1.893 raeburn 4661: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4662: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4663: if ($env{'request.role.domain'}) {
4664: $domain=$env{'request.role.domain'};
1.60 matthew 4665: }
4666: }
1.63 www 4667: return $domain;
4668: }
4669: ###############################################
1.517 raeburn 4670:
1.518 albertel 4671: sub devalidate_domconfig_cache {
4672: my ($udom)=@_;
4673: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4674: }
4675:
4676: # ---------------------- Get domain configuration for a domain
4677: sub get_domainconf {
4678: my ($udom) = @_;
4679: my $cachetime=1800;
4680: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4681: if (defined($cached)) { return %{$result}; }
4682:
4683: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4684: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4685: my (%designhash,%legacy);
1.518 albertel 4686: if (keys(%domconfig) > 0) {
4687: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4688: if (keys(%{$domconfig{'login'}})) {
4689: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4690: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4691: if ($key eq 'loginvia') {
4692: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4693: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4694: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4695: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4696: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4697: $designhash{$udom.'.login.loginvia'} = $server;
4698: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4699:
4700: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4701: } else {
1.1013 raeburn 4702: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4703: }
4704: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4705: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4706: }
1.946 raeburn 4707: }
4708: }
4709: }
4710: }
4711: } else {
4712: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4713: $designhash{$udom.'.login.'.$key.'_'.$img} =
4714: $domconfig{'login'}{$key}{$img};
4715: }
1.699 raeburn 4716: }
4717: } else {
4718: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4719: }
1.632 raeburn 4720: }
4721: } else {
4722: $legacy{'login'} = 1;
1.518 albertel 4723: }
1.632 raeburn 4724: } else {
4725: $legacy{'login'} = 1;
1.518 albertel 4726: }
4727: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4728: if (keys(%{$domconfig{'rolecolors'}})) {
4729: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4730: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4731: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4732: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4733: }
1.518 albertel 4734: }
4735: }
1.632 raeburn 4736: } else {
4737: $legacy{'rolecolors'} = 1;
1.518 albertel 4738: }
1.632 raeburn 4739: } else {
4740: $legacy{'rolecolors'} = 1;
1.518 albertel 4741: }
1.948 raeburn 4742: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4743: if ($domconfig{'autoenroll'}{'co-owners'}) {
4744: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4745: }
4746: }
1.632 raeburn 4747: if (keys(%legacy) > 0) {
4748: my %legacyhash = &get_legacy_domconf($udom);
4749: foreach my $item (keys(%legacyhash)) {
4750: if ($item =~ /^\Q$udom\E\.login/) {
4751: if ($legacy{'login'}) {
4752: $designhash{$item} = $legacyhash{$item};
4753: }
4754: } else {
4755: if ($legacy{'rolecolors'}) {
4756: $designhash{$item} = $legacyhash{$item};
4757: }
1.518 albertel 4758: }
4759: }
4760: }
1.632 raeburn 4761: } else {
4762: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4763: }
4764: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4765: $cachetime);
4766: return %designhash;
4767: }
4768:
1.632 raeburn 4769: sub get_legacy_domconf {
4770: my ($udom) = @_;
4771: my %legacyhash;
4772: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4773: my $designfile = $designdir.'/'.$udom.'.tab';
4774: if (-e $designfile) {
4775: if ( open (my $fh,"<$designfile") ) {
4776: while (my $line = <$fh>) {
4777: next if ($line =~ /^\#/);
4778: chomp($line);
4779: my ($key,$val)=(split(/\=/,$line));
4780: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4781: }
4782: close($fh);
4783: }
4784: }
1.1026 raeburn 4785: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4786: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4787: }
4788: return %legacyhash;
4789: }
4790:
1.63 www 4791: =pod
4792:
1.112 bowersj2 4793: =item * &domainlogo()
1.63 www 4794:
4795: Inputs: $domain (usually will be undef)
4796:
4797: Returns: A link to a domain logo, if the domain logo exists.
4798: If the domain logo does not exist, a description of the domain.
4799:
4800: =cut
1.112 bowersj2 4801:
1.63 www 4802: ###############################################
4803: sub domainlogo {
1.517 raeburn 4804: my $domain = &determinedomain(shift);
1.518 albertel 4805: my %designhash = &get_domainconf($domain);
1.517 raeburn 4806: # See if there is a logo
4807: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4808: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4809: if ($imgsrc =~ m{^/(adm|res)/}) {
4810: if ($imgsrc =~ m{^/res/}) {
4811: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4812: &Apache::lonnet::repcopy($local_name);
4813: }
4814: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4815: }
4816: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4817: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4818: return &Apache::lonnet::domain($domain,'description');
1.59 www 4819: } else {
1.60 matthew 4820: return '';
1.59 www 4821: }
4822: }
1.63 www 4823: ##############################################
4824:
4825: =pod
4826:
1.112 bowersj2 4827: =item * &designparm()
1.63 www 4828:
4829: Inputs: $which parameter; $domain (usually will be undef)
4830:
4831: Returns: value of designparamter $which
4832:
4833: =cut
1.112 bowersj2 4834:
1.397 albertel 4835:
1.400 albertel 4836: ##############################################
1.397 albertel 4837: sub designparm {
4838: my ($which,$domain)=@_;
4839: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4840: return $env{'environment.color.'.$which};
1.96 www 4841: }
1.63 www 4842: $domain=&determinedomain($domain);
1.1016 raeburn 4843: my %domdesign;
4844: unless ($domain eq 'public') {
4845: %domdesign = &get_domainconf($domain);
4846: }
1.520 raeburn 4847: my $output;
1.517 raeburn 4848: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4849: $output = $domdesign{$domain.'.'.$which};
1.63 www 4850: } else {
1.520 raeburn 4851: $output = $defaultdesign{$which};
4852: }
4853: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4854: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4855: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4856: if ($output =~ m{^/res/}) {
4857: my $local_name = &Apache::lonnet::filelocation('',$output);
4858: &Apache::lonnet::repcopy($local_name);
4859: }
1.520 raeburn 4860: $output = &lonhttpdurl($output);
4861: }
1.63 www 4862: }
1.520 raeburn 4863: return $output;
1.63 www 4864: }
1.59 www 4865:
1.822 bisitz 4866: ##############################################
4867: =pod
4868:
1.832 bisitz 4869: =item * &authorspace()
4870:
1.1028 raeburn 4871: Inputs: $url (usually will be undef).
1.832 bisitz 4872:
1.1075.2.40 raeburn 4873: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4874: directory being viewed (or for which action is being taken).
4875: If $url is provided, and begins /priv/<domain>/<uname>
4876: the path will be that portion of the $context argument.
4877: Otherwise the path will be for the author space of the current
4878: user when the current role is author, or for that of the
4879: co-author/assistant co-author space when the current role
4880: is co-author or assistant co-author.
1.832 bisitz 4881:
4882: =cut
4883:
4884: sub authorspace {
1.1028 raeburn 4885: my ($url) = @_;
4886: if ($url ne '') {
4887: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4888: return $1;
4889: }
4890: }
1.832 bisitz 4891: my $caname = '';
1.1024 www 4892: my $cadom = '';
1.1028 raeburn 4893: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4894: ($cadom,$caname) =
1.832 bisitz 4895: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4896: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4897: $caname = $env{'user.name'};
1.1024 www 4898: $cadom = $env{'user.domain'};
1.832 bisitz 4899: }
1.1028 raeburn 4900: if (($caname ne '') && ($cadom ne '')) {
4901: return "/priv/$cadom/$caname/";
4902: }
4903: return;
1.832 bisitz 4904: }
4905:
4906: ##############################################
4907: =pod
4908:
1.822 bisitz 4909: =item * &head_subbox()
4910:
4911: Inputs: $content (contains HTML code with page functions, etc.)
4912:
4913: Returns: HTML div with $content
4914: To be included in page header
4915:
4916: =cut
4917:
4918: sub head_subbox {
4919: my ($content)=@_;
4920: my $output =
1.993 raeburn 4921: '<div class="LC_head_subbox">'
1.822 bisitz 4922: .$content
4923: .'</div>'
4924: }
4925:
4926: ##############################################
4927: =pod
4928:
4929: =item * &CSTR_pageheader()
4930:
1.1026 raeburn 4931: Input: (optional) filename from which breadcrumb trail is built.
4932: In most cases no input as needed, as $env{'request.filename'}
4933: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 4934:
4935: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 4936: To be included on Authoring Space pages
1.822 bisitz 4937:
4938: =cut
4939:
4940: sub CSTR_pageheader {
1.1026 raeburn 4941: my ($trailfile) = @_;
4942: if ($trailfile eq '') {
4943: $trailfile = $env{'request.filename'};
4944: }
4945:
4946: # this is for resources; directories have customtitle, and crumbs
4947: # and select recent are created in lonpubdir.pm
4948:
4949: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 4950: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 4951: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 4952: my $formaction = "/priv/$udom/$uname/$thisdisfn";
4953: $formaction =~ s{/+}{/}g;
1.822 bisitz 4954:
4955: my $parentpath = '';
4956: my $lastitem = '';
4957: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4958: $parentpath = $1;
4959: $lastitem = $2;
4960: } else {
4961: $lastitem = $thisdisfn;
4962: }
1.921 bisitz 4963:
4964: my $output =
1.822 bisitz 4965: '<div>'
4966: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 4967: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 4968: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4969: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 4970: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 4971:
4972: if ($lastitem) {
4973: $output .=
4974: '<span class="LC_filename">'
4975: .$lastitem
4976: .'</span>';
4977: }
4978: $output .=
4979: '<br />'
1.822 bisitz 4980: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4981: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4982: .'</form>'
4983: .&Apache::lonmenu::constspaceform()
4984: .'</div>';
1.921 bisitz 4985:
4986: return $output;
1.822 bisitz 4987: }
4988:
1.60 matthew 4989: ###############################################
4990: ###############################################
4991:
4992: =pod
4993:
1.112 bowersj2 4994: =back
4995:
1.549 albertel 4996: =head1 HTML Helpers
1.112 bowersj2 4997:
4998: =over 4
4999:
5000: =item * &bodytag()
1.60 matthew 5001:
5002: Returns a uniform header for LON-CAPA web pages.
5003:
5004: Inputs:
5005:
1.112 bowersj2 5006: =over 4
5007:
5008: =item * $title, A title to be displayed on the page.
5009:
5010: =item * $function, the current role (can be undef).
5011:
5012: =item * $addentries, extra parameters for the <body> tag.
5013:
5014: =item * $bodyonly, if defined, only return the <body> tag.
5015:
5016: =item * $domain, if defined, force a given domain.
5017:
5018: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5019: text interface only)
1.60 matthew 5020:
1.814 bisitz 5021: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5022: navigational links
1.317 albertel 5023:
1.338 albertel 5024: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5025:
1.1075.2.12 raeburn 5026: =item * $no_inline_link, if true and in remote mode, don't show the
5027: 'Switch To Inline Menu' link
5028:
1.460 albertel 5029: =item * $args, optional argument valid values are
5030: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5031: inherit_jsmath -> when creating popup window in a page,
5032: should it have jsmath forced on by the
5033: current page
1.460 albertel 5034:
1.1075.2.15 raeburn 5035: =item * $advtoolsref, optional argument, ref to an array containing
5036: inlineremote items to be added in "Functions" menu below
5037: breadcrumbs.
5038:
1.112 bowersj2 5039: =back
5040:
1.60 matthew 5041: Returns: A uniform header for LON-CAPA web pages.
5042: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5043: If $bodyonly is undef or zero, an html string containing a <body> tag and
5044: other decorations will be returned.
5045:
5046: =cut
5047:
1.54 www 5048: sub bodytag {
1.831 bisitz 5049: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5050: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5051:
1.954 raeburn 5052: my $public;
5053: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5054: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5055: $public = 1;
5056: }
1.460 albertel 5057: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5058: my $httphost = $args->{'use_absolute'};
1.339 albertel 5059:
1.183 matthew 5060: $function = &get_users_function() if (!$function);
1.339 albertel 5061: my $img = &designparm($function.'.img',$domain);
5062: my $font = &designparm($function.'.font',$domain);
5063: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5064:
1.803 bisitz 5065: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5066: 'bgcolor' => $pgbg,
1.339 albertel 5067: 'text' => $font,
5068: 'alink' => &designparm($function.'.alink',$domain),
5069: 'vlink' => &designparm($function.'.vlink',$domain),
5070: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5071: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5072:
1.63 www 5073: # role and realm
1.1075.2.68 raeburn 5074: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5075: if ($realm) {
5076: $realm = '/'.$realm;
5077: }
1.378 raeburn 5078: if ($role eq 'ca') {
1.479 albertel 5079: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5080: $realm = &plainname($rname,$rdom);
1.378 raeburn 5081: }
1.55 www 5082: # realm
1.258 albertel 5083: if ($env{'request.course.id'}) {
1.378 raeburn 5084: if ($env{'request.role'} !~ /^cr/) {
5085: $role = &Apache::lonnet::plaintext($role,&course_type());
5086: }
1.898 raeburn 5087: if ($env{'request.course.sec'}) {
5088: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5089: }
1.359 albertel 5090: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5091: } else {
5092: $role = &Apache::lonnet::plaintext($role);
1.54 www 5093: }
1.433 albertel 5094:
1.359 albertel 5095: if (!$realm) { $realm=' '; }
1.330 albertel 5096:
1.438 albertel 5097: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5098:
1.101 www 5099: # construct main body tag
1.359 albertel 5100: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5101: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5102:
1.1075.2.38 raeburn 5103: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5104:
5105: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5106: return $bodytag;
1.1075.2.38 raeburn 5107: }
1.359 albertel 5108:
1.954 raeburn 5109: if ($public) {
1.433 albertel 5110: undef($role);
5111: }
1.359 albertel 5112:
1.762 bisitz 5113: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5114: #
5115: # Extra info if you are the DC
5116: my $dc_info = '';
5117: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5118: $env{'course.'.$env{'request.course.id'}.
5119: '.domain'}.'/'})) {
5120: my $cid = $env{'request.course.id'};
1.917 raeburn 5121: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5122: $dc_info =~ s/\s+$//;
1.359 albertel 5123: }
5124:
1.898 raeburn 5125: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.903 droeschl 5126:
1.1075.2.13 raeburn 5127: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5128:
1.1075.2.38 raeburn 5129:
5130:
1.1075.2.21 raeburn 5131: my $funclist;
5132: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5133: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5134: Apache::lonmenu::serverform();
5135: my $forbodytag;
5136: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5137: $forcereg,$args->{'group'},
5138: $args->{'bread_crumbs'},
5139: $advtoolsref,'',\$forbodytag);
5140: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5141: $funclist = $forbodytag;
5142: }
5143: } else {
1.903 droeschl 5144:
5145: # if ($env{'request.state'} eq 'construct') {
5146: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5147: # }
5148:
1.1075.2.38 raeburn 5149: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5150: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5151:
1.1075.2.38 raeburn 5152: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5153:
1.916 droeschl 5154: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5155: if ($dc_info) {
5156: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5157: }
1.1075.2.38 raeburn 5158: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5159: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5160: return $bodytag;
5161: }
1.894 droeschl 5162:
1.927 raeburn 5163: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5164: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5165: }
1.916 droeschl 5166:
1.1075.2.38 raeburn 5167: $bodytag .= $right;
1.852 droeschl 5168:
1.917 raeburn 5169: if ($dc_info) {
5170: $dc_info = &dc_courseid_toggle($dc_info);
5171: }
5172: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5173:
1.1075.2.61 raeburn 5174: #if directed to not display the secondary menu, don't.
5175: if ($args->{'no_secondary_menu'}) {
5176: return $bodytag;
5177: }
1.903 droeschl 5178: #don't show menus for public users
1.954 raeburn 5179: if (!$public){
1.1075.2.52 raeburn 5180: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5181: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5182: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5183: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5184: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5185: $args->{'bread_crumbs'});
5186: } elsif ($forcereg) {
1.1075.2.22 raeburn 5187: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5188: $args->{'group'});
1.1075.2.15 raeburn 5189: } else {
1.1075.2.21 raeburn 5190: my $forbodytag;
5191: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5192: $forcereg,$args->{'group'},
5193: $args->{'bread_crumbs'},
5194: $advtoolsref,'',\$forbodytag);
5195: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5196: $bodytag .= $forbodytag;
5197: }
1.920 raeburn 5198: }
1.903 droeschl 5199: }else{
5200: # this is to seperate menu from content when there's no secondary
5201: # menu. Especially needed for public accessible ressources.
5202: $bodytag .= '<hr style="clear:both" />';
5203: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5204: }
1.903 droeschl 5205:
1.235 raeburn 5206: return $bodytag;
1.1075.2.12 raeburn 5207: }
5208:
5209: #
5210: # Top frame rendering, Remote is up
5211: #
5212:
5213: my $imgsrc = $img;
5214: if ($img =~ /^\/adm/) {
5215: $imgsrc = &lonhttpdurl($img);
5216: }
5217: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5218:
1.1075.2.60 raeburn 5219: my $help=($no_inline_link?''
5220: :&Apache::loncommon::top_nav_help('Help'));
5221:
1.1075.2.12 raeburn 5222: # Explicit link to get inline menu
5223: my $menu= ($no_inline_link?''
5224: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5225:
5226: if ($dc_info) {
5227: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5228: }
5229:
1.1075.2.38 raeburn 5230: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5231: unless ($public) {
5232: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5233: undef,'LC_menubuttons_link');
5234: }
5235:
1.1075.2.12 raeburn 5236: unless ($env{'form.inhibitmenu'}) {
5237: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5238: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5239: <li>$help</li>
1.1075.2.12 raeburn 5240: <li>$menu</li>
5241: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5242: }
1.1075.2.13 raeburn 5243: if ($env{'request.state'} eq 'construct') {
5244: if (!$public){
5245: if ($env{'request.state'} eq 'construct') {
5246: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5247: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5248: &Apache::lonhtmlcommon::scripttag('','end').
5249: &Apache::lonmenu::innerregister($forcereg,
5250: $args->{'bread_crumbs'});
5251: }
5252: }
5253: }
1.1075.2.21 raeburn 5254: return $bodytag."\n".$funclist;
1.182 matthew 5255: }
5256:
1.917 raeburn 5257: sub dc_courseid_toggle {
5258: my ($dc_info) = @_;
1.980 raeburn 5259: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5260: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5261: &mt('(More ...)').'</a></span>'.
5262: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5263: }
5264:
1.330 albertel 5265: sub make_attr_string {
5266: my ($register,$attr_ref) = @_;
5267:
5268: if ($attr_ref && !ref($attr_ref)) {
5269: die("addentries Must be a hash ref ".
5270: join(':',caller(1))." ".
5271: join(':',caller(0))." ");
5272: }
5273:
5274: if ($register) {
1.339 albertel 5275: my ($on_load,$on_unload);
5276: foreach my $key (keys(%{$attr_ref})) {
5277: if (lc($key) eq 'onload') {
5278: $on_load.=$attr_ref->{$key}.';';
5279: delete($attr_ref->{$key});
5280:
5281: } elsif (lc($key) eq 'onunload') {
5282: $on_unload.=$attr_ref->{$key}.';';
5283: delete($attr_ref->{$key});
5284: }
5285: }
1.1075.2.12 raeburn 5286: if ($env{'environment.remote'} eq 'on') {
5287: $attr_ref->{'onload'} =
5288: &Apache::lonmenu::loadevents(). $on_load;
5289: $attr_ref->{'onunload'}=
5290: &Apache::lonmenu::unloadevents().$on_unload;
5291: } else {
5292: $attr_ref->{'onload'} = $on_load;
5293: $attr_ref->{'onunload'}= $on_unload;
5294: }
1.330 albertel 5295: }
1.339 albertel 5296:
1.330 albertel 5297: my $attr_string;
1.1075.2.56 raeburn 5298: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5299: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5300: }
5301: return $attr_string;
5302: }
5303:
5304:
1.182 matthew 5305: ###############################################
1.251 albertel 5306: ###############################################
5307:
5308: =pod
5309:
5310: =item * &endbodytag()
5311:
5312: Returns a uniform footer for LON-CAPA web pages.
5313:
1.635 raeburn 5314: Inputs: 1 - optional reference to an args hash
5315: If in the hash, key for noredirectlink has a value which evaluates to true,
5316: a 'Continue' link is not displayed if the page contains an
5317: internal redirect in the <head></head> section,
5318: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5319:
5320: =cut
5321:
5322: sub endbodytag {
1.635 raeburn 5323: my ($args) = @_;
1.1075.2.6 raeburn 5324: my $endbodytag;
5325: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5326: $endbodytag='</body>';
5327: }
1.269 albertel 5328: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5329: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5330: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5331: $endbodytag=
5332: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5333: &mt('Continue').'</a>'.
5334: $endbodytag;
5335: }
1.315 albertel 5336: }
1.251 albertel 5337: return $endbodytag;
5338: }
5339:
1.352 albertel 5340: =pod
5341:
5342: =item * &standard_css()
5343:
5344: Returns a style sheet
5345:
5346: Inputs: (all optional)
5347: domain -> force to color decorate a page for a specific
5348: domain
5349: function -> force usage of a specific rolish color scheme
5350: bgcolor -> override the default page bgcolor
5351:
5352: =cut
5353:
1.343 albertel 5354: sub standard_css {
1.345 albertel 5355: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5356: $function = &get_users_function() if (!$function);
5357: my $img = &designparm($function.'.img', $domain);
5358: my $tabbg = &designparm($function.'.tabbg', $domain);
5359: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5360: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5361: #second colour for later usage
1.345 albertel 5362: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5363: my $pgbg_or_bgcolor =
5364: $bgcolor ||
1.352 albertel 5365: &designparm($function.'.pgbg', $domain);
1.382 albertel 5366: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5367: my $alink = &designparm($function.'.alink', $domain);
5368: my $vlink = &designparm($function.'.vlink', $domain);
5369: my $link = &designparm($function.'.link', $domain);
5370:
1.602 albertel 5371: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5372: my $mono = 'monospace';
1.850 bisitz 5373: my $data_table_head = $sidebg;
5374: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5375: my $data_table_dark = '#E0E0E0';
1.470 banghart 5376: my $data_table_darker = '#CCCCCC';
1.349 albertel 5377: my $data_table_highlight = '#FFFF00';
1.352 albertel 5378: my $mail_new = '#FFBB77';
5379: my $mail_new_hover = '#DD9955';
5380: my $mail_read = '#BBBB77';
5381: my $mail_read_hover = '#999944';
5382: my $mail_replied = '#AAAA88';
5383: my $mail_replied_hover = '#888855';
5384: my $mail_other = '#99BBBB';
5385: my $mail_other_hover = '#669999';
1.391 albertel 5386: my $table_header = '#DDDDDD';
1.489 raeburn 5387: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5388: my $lg_border_color = '#C8C8C8';
1.952 onken 5389: my $button_hover = '#BF2317';
1.392 albertel 5390:
1.608 albertel 5391: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5392: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5393: : '0 3px 0 4px';
1.448 albertel 5394:
1.523 albertel 5395:
1.343 albertel 5396: return <<END;
1.947 droeschl 5397:
5398: /* needed for iframe to allow 100% height in FF */
5399: body, html {
5400: margin: 0;
5401: padding: 0 0.5%;
5402: height: 99%; /* to avoid scrollbars */
5403: }
5404:
1.795 www 5405: body {
1.911 bisitz 5406: font-family: $sans;
5407: line-height:130%;
5408: font-size:0.83em;
5409: color:$font;
1.795 www 5410: }
5411:
1.959 onken 5412: a:focus,
5413: a:focus img {
1.795 www 5414: color: red;
5415: }
1.698 harmsja 5416:
1.911 bisitz 5417: form, .inline {
5418: display: inline;
1.795 www 5419: }
1.721 harmsja 5420:
1.795 www 5421: .LC_right {
1.911 bisitz 5422: text-align:right;
1.795 www 5423: }
5424:
5425: .LC_middle {
1.911 bisitz 5426: vertical-align:middle;
1.795 www 5427: }
1.721 harmsja 5428:
1.1075.2.38 raeburn 5429: .LC_floatleft {
5430: float: left;
5431: }
5432:
5433: .LC_floatright {
5434: float: right;
5435: }
5436:
1.911 bisitz 5437: .LC_400Box {
5438: width:400px;
5439: }
1.721 harmsja 5440:
1.947 droeschl 5441: .LC_iframecontainer {
5442: width: 98%;
5443: margin: 0;
5444: position: fixed;
5445: top: 8.5em;
5446: bottom: 0;
5447: }
5448:
5449: .LC_iframecontainer iframe{
5450: border: none;
5451: width: 100%;
5452: height: 100%;
5453: }
5454:
1.778 bisitz 5455: .LC_filename {
5456: font-family: $mono;
5457: white-space:pre;
1.921 bisitz 5458: font-size: 120%;
1.778 bisitz 5459: }
5460:
5461: .LC_fileicon {
5462: border: none;
5463: height: 1.3em;
5464: vertical-align: text-bottom;
5465: margin-right: 0.3em;
5466: text-decoration:none;
5467: }
5468:
1.1008 www 5469: .LC_setting {
5470: text-decoration:underline;
5471: }
5472:
1.350 albertel 5473: .LC_error {
5474: color: red;
5475: }
1.795 www 5476:
1.1075.2.15 raeburn 5477: .LC_warning {
5478: color: darkorange;
5479: }
5480:
1.457 albertel 5481: .LC_diff_removed {
1.733 bisitz 5482: color: red;
1.394 albertel 5483: }
1.532 albertel 5484:
5485: .LC_info,
1.457 albertel 5486: .LC_success,
5487: .LC_diff_added {
1.350 albertel 5488: color: green;
5489: }
1.795 www 5490:
1.802 bisitz 5491: div.LC_confirm_box {
5492: background-color: #FAFAFA;
5493: border: 1px solid $lg_border_color;
5494: margin-right: 0;
5495: padding: 5px;
5496: }
5497:
5498: div.LC_confirm_box .LC_error img,
5499: div.LC_confirm_box .LC_success img {
5500: vertical-align: middle;
5501: }
5502:
1.440 albertel 5503: .LC_icon {
1.771 droeschl 5504: border: none;
1.790 droeschl 5505: vertical-align: middle;
1.771 droeschl 5506: }
5507:
1.543 albertel 5508: .LC_docs_spacer {
5509: width: 25px;
5510: height: 1px;
1.771 droeschl 5511: border: none;
1.543 albertel 5512: }
1.346 albertel 5513:
1.532 albertel 5514: .LC_internal_info {
1.735 bisitz 5515: color: #999999;
1.532 albertel 5516: }
5517:
1.794 www 5518: .LC_discussion {
1.1050 www 5519: background: $data_table_dark;
1.911 bisitz 5520: border: 1px solid black;
5521: margin: 2px;
1.794 www 5522: }
5523:
5524: .LC_disc_action_left {
1.1050 www 5525: background: $sidebg;
1.911 bisitz 5526: text-align: left;
1.1050 www 5527: padding: 4px;
5528: margin: 2px;
1.794 www 5529: }
5530:
5531: .LC_disc_action_right {
1.1050 www 5532: background: $sidebg;
1.911 bisitz 5533: text-align: right;
1.1050 www 5534: padding: 4px;
5535: margin: 2px;
1.794 www 5536: }
5537:
5538: .LC_disc_new_item {
1.911 bisitz 5539: background: white;
5540: border: 2px solid red;
1.1050 www 5541: margin: 4px;
5542: padding: 4px;
1.794 www 5543: }
5544:
5545: .LC_disc_old_item {
1.911 bisitz 5546: background: white;
1.1050 www 5547: margin: 4px;
5548: padding: 4px;
1.794 www 5549: }
5550:
1.458 albertel 5551: table.LC_pastsubmission {
5552: border: 1px solid black;
5553: margin: 2px;
5554: }
5555:
1.924 bisitz 5556: table#LC_menubuttons {
1.345 albertel 5557: width: 100%;
5558: background: $pgbg;
1.392 albertel 5559: border: 2px;
1.402 albertel 5560: border-collapse: separate;
1.803 bisitz 5561: padding: 0;
1.345 albertel 5562: }
1.392 albertel 5563:
1.801 tempelho 5564: table#LC_title_bar a {
5565: color: $fontmenu;
5566: }
1.836 bisitz 5567:
1.807 droeschl 5568: table#LC_title_bar {
1.819 tempelho 5569: clear: both;
1.836 bisitz 5570: display: none;
1.807 droeschl 5571: }
5572:
1.795 www 5573: table#LC_title_bar,
1.933 droeschl 5574: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5575: table#LC_title_bar.LC_with_remote {
1.359 albertel 5576: width: 100%;
1.392 albertel 5577: border-color: $pgbg;
5578: border-style: solid;
5579: border-width: $border;
1.379 albertel 5580: background: $pgbg;
1.801 tempelho 5581: color: $fontmenu;
1.392 albertel 5582: border-collapse: collapse;
1.803 bisitz 5583: padding: 0;
1.819 tempelho 5584: margin: 0;
1.359 albertel 5585: }
1.795 www 5586:
1.933 droeschl 5587: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5588: margin: 0;
5589: padding: 0;
1.933 droeschl 5590: position: relative;
5591: list-style: none;
1.913 droeschl 5592: }
1.933 droeschl 5593: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5594: display: inline;
5595: }
1.933 droeschl 5596:
5597: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5598: padding: 0;
1.933 droeschl 5599: margin: 0;
5600: float: left;
1.913 droeschl 5601: }
1.933 droeschl 5602: .LC_breadcrumb_tools_tools {
5603: padding: 0;
5604: margin: 0;
1.913 droeschl 5605: float: right;
5606: }
5607:
1.359 albertel 5608: table#LC_title_bar td {
5609: background: $tabbg;
5610: }
1.795 www 5611:
1.911 bisitz 5612: table#LC_menubuttons img {
1.803 bisitz 5613: border: none;
1.346 albertel 5614: }
1.795 www 5615:
1.842 droeschl 5616: .LC_breadcrumbs_component {
1.911 bisitz 5617: float: right;
5618: margin: 0 1em;
1.357 albertel 5619: }
1.842 droeschl 5620: .LC_breadcrumbs_component img {
1.911 bisitz 5621: vertical-align: middle;
1.777 tempelho 5622: }
1.795 www 5623:
1.383 albertel 5624: td.LC_table_cell_checkbox {
5625: text-align: center;
5626: }
1.795 www 5627:
5628: .LC_fontsize_small {
1.911 bisitz 5629: font-size: 70%;
1.705 tempelho 5630: }
5631:
1.844 bisitz 5632: #LC_breadcrumbs {
1.911 bisitz 5633: clear:both;
5634: background: $sidebg;
5635: border-bottom: 1px solid $lg_border_color;
5636: line-height: 2.5em;
1.933 droeschl 5637: overflow: hidden;
1.911 bisitz 5638: margin: 0;
5639: padding: 0;
1.995 raeburn 5640: text-align: left;
1.819 tempelho 5641: }
1.862 bisitz 5642:
1.1075.2.16 raeburn 5643: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5644: clear:both;
5645: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5646: border: 1px solid $sidebg;
1.1075.2.16 raeburn 5647: margin: 0 0 10px 0;
1.966 bisitz 5648: padding: 3px;
1.995 raeburn 5649: text-align: left;
1.822 bisitz 5650: }
5651:
1.795 www 5652: .LC_fontsize_medium {
1.911 bisitz 5653: font-size: 85%;
1.705 tempelho 5654: }
5655:
1.795 www 5656: .LC_fontsize_large {
1.911 bisitz 5657: font-size: 120%;
1.705 tempelho 5658: }
5659:
1.346 albertel 5660: .LC_menubuttons_inline_text {
5661: color: $font;
1.698 harmsja 5662: font-size: 90%;
1.701 harmsja 5663: padding-left:3px;
1.346 albertel 5664: }
5665:
1.934 droeschl 5666: .LC_menubuttons_inline_text img{
5667: vertical-align: middle;
5668: }
5669:
1.1051 www 5670: li.LC_menubuttons_inline_text img {
1.951 onken 5671: cursor:pointer;
1.1002 droeschl 5672: text-decoration: none;
1.951 onken 5673: }
5674:
1.526 www 5675: .LC_menubuttons_link {
5676: text-decoration: none;
5677: }
1.795 www 5678:
1.522 albertel 5679: .LC_menubuttons_category {
1.521 www 5680: color: $font;
1.526 www 5681: background: $pgbg;
1.521 www 5682: font-size: larger;
5683: font-weight: bold;
5684: }
5685:
1.346 albertel 5686: td.LC_menubuttons_text {
1.911 bisitz 5687: color: $font;
1.346 albertel 5688: }
1.706 harmsja 5689:
1.346 albertel 5690: .LC_current_location {
5691: background: $tabbg;
5692: }
1.795 www 5693:
1.938 bisitz 5694: table.LC_data_table {
1.347 albertel 5695: border: 1px solid #000000;
1.402 albertel 5696: border-collapse: separate;
1.426 albertel 5697: border-spacing: 1px;
1.610 albertel 5698: background: $pgbg;
1.347 albertel 5699: }
1.795 www 5700:
1.422 albertel 5701: .LC_data_table_dense {
5702: font-size: small;
5703: }
1.795 www 5704:
1.507 raeburn 5705: table.LC_nested_outer {
5706: border: 1px solid #000000;
1.589 raeburn 5707: border-collapse: collapse;
1.803 bisitz 5708: border-spacing: 0;
1.507 raeburn 5709: width: 100%;
5710: }
1.795 www 5711:
1.879 raeburn 5712: table.LC_innerpickbox,
1.507 raeburn 5713: table.LC_nested {
1.803 bisitz 5714: border: none;
1.589 raeburn 5715: border-collapse: collapse;
1.803 bisitz 5716: border-spacing: 0;
1.507 raeburn 5717: width: 100%;
5718: }
1.795 www 5719:
1.911 bisitz 5720: table.LC_data_table tr th,
5721: table.LC_calendar tr th,
1.879 raeburn 5722: table.LC_prior_tries tr th,
5723: table.LC_innerpickbox tr th {
1.349 albertel 5724: font-weight: bold;
5725: background-color: $data_table_head;
1.801 tempelho 5726: color:$fontmenu;
1.701 harmsja 5727: font-size:90%;
1.347 albertel 5728: }
1.795 www 5729:
1.879 raeburn 5730: table.LC_innerpickbox tr th,
5731: table.LC_innerpickbox tr td {
5732: vertical-align: top;
5733: }
5734:
1.711 raeburn 5735: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5736: background-color: #CCCCCC;
1.711 raeburn 5737: font-weight: bold;
5738: text-align: left;
5739: }
1.795 www 5740:
1.912 bisitz 5741: table.LC_data_table tr.LC_odd_row > td {
5742: background-color: $data_table_light;
5743: padding: 2px;
5744: vertical-align: top;
5745: }
5746:
1.809 bisitz 5747: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5748: background-color: $data_table_light;
1.912 bisitz 5749: vertical-align: top;
5750: }
5751:
5752: table.LC_data_table tr.LC_even_row > td {
5753: background-color: $data_table_dark;
1.425 albertel 5754: padding: 2px;
1.900 bisitz 5755: vertical-align: top;
1.347 albertel 5756: }
1.795 www 5757:
1.809 bisitz 5758: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5759: background-color: $data_table_dark;
1.900 bisitz 5760: vertical-align: top;
1.347 albertel 5761: }
1.795 www 5762:
1.425 albertel 5763: table.LC_data_table tr.LC_data_table_highlight td {
5764: background-color: $data_table_darker;
5765: }
1.795 www 5766:
1.639 raeburn 5767: table.LC_data_table tr td.LC_leftcol_header {
5768: background-color: $data_table_head;
5769: font-weight: bold;
5770: }
1.795 www 5771:
1.451 albertel 5772: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5773: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5774: font-weight: bold;
5775: font-style: italic;
5776: text-align: center;
5777: padding: 8px;
1.347 albertel 5778: }
1.795 www 5779:
1.1075.2.30 raeburn 5780: table.LC_data_table tr.LC_empty_row td,
5781: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5782: background-color: $sidebg;
5783: }
5784:
5785: table.LC_nested tr.LC_empty_row td {
5786: background-color: #FFFFFF;
5787: }
5788:
1.890 droeschl 5789: table.LC_caption {
5790: }
5791:
1.507 raeburn 5792: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5793: padding: 4ex
5794: }
1.795 www 5795:
1.507 raeburn 5796: table.LC_nested_outer tr th {
5797: font-weight: bold;
1.801 tempelho 5798: color:$fontmenu;
1.507 raeburn 5799: background-color: $data_table_head;
1.701 harmsja 5800: font-size: small;
1.507 raeburn 5801: border-bottom: 1px solid #000000;
5802: }
1.795 www 5803:
1.507 raeburn 5804: table.LC_nested_outer tr td.LC_subheader {
5805: background-color: $data_table_head;
5806: font-weight: bold;
5807: font-size: small;
5808: border-bottom: 1px solid #000000;
5809: text-align: right;
1.451 albertel 5810: }
1.795 www 5811:
1.507 raeburn 5812: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5813: background-color: #CCCCCC;
1.451 albertel 5814: font-weight: bold;
5815: font-size: small;
1.507 raeburn 5816: text-align: center;
5817: }
1.795 www 5818:
1.589 raeburn 5819: table.LC_nested tr.LC_info_row td.LC_left_item,
5820: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5821: text-align: left;
1.451 albertel 5822: }
1.795 www 5823:
1.507 raeburn 5824: table.LC_nested td {
1.735 bisitz 5825: background-color: #FFFFFF;
1.451 albertel 5826: font-size: small;
1.507 raeburn 5827: }
1.795 www 5828:
1.507 raeburn 5829: table.LC_nested_outer tr th.LC_right_item,
5830: table.LC_nested tr.LC_info_row td.LC_right_item,
5831: table.LC_nested tr.LC_odd_row td.LC_right_item,
5832: table.LC_nested tr td.LC_right_item {
1.451 albertel 5833: text-align: right;
5834: }
5835:
1.507 raeburn 5836: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5837: background-color: #EEEEEE;
1.451 albertel 5838: }
5839:
1.473 raeburn 5840: table.LC_createuser {
5841: }
5842:
5843: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5844: font-size: small;
1.473 raeburn 5845: }
5846:
5847: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5848: background-color: #CCCCCC;
1.473 raeburn 5849: font-weight: bold;
5850: text-align: center;
5851: }
5852:
1.349 albertel 5853: table.LC_calendar {
5854: border: 1px solid #000000;
5855: border-collapse: collapse;
1.917 raeburn 5856: width: 98%;
1.349 albertel 5857: }
1.795 www 5858:
1.349 albertel 5859: table.LC_calendar_pickdate {
5860: font-size: xx-small;
5861: }
1.795 www 5862:
1.349 albertel 5863: table.LC_calendar tr td {
5864: border: 1px solid #000000;
5865: vertical-align: top;
1.917 raeburn 5866: width: 14%;
1.349 albertel 5867: }
1.795 www 5868:
1.349 albertel 5869: table.LC_calendar tr td.LC_calendar_day_empty {
5870: background-color: $data_table_dark;
5871: }
1.795 www 5872:
1.779 bisitz 5873: table.LC_calendar tr td.LC_calendar_day_current {
5874: background-color: $data_table_highlight;
1.777 tempelho 5875: }
1.795 www 5876:
1.938 bisitz 5877: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5878: background-color: $mail_new;
5879: }
1.795 www 5880:
1.938 bisitz 5881: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5882: background-color: $mail_new_hover;
5883: }
1.795 www 5884:
1.938 bisitz 5885: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5886: background-color: $mail_read;
5887: }
1.795 www 5888:
1.938 bisitz 5889: /*
5890: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5891: background-color: $mail_read_hover;
5892: }
1.938 bisitz 5893: */
1.795 www 5894:
1.938 bisitz 5895: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5896: background-color: $mail_replied;
5897: }
1.795 www 5898:
1.938 bisitz 5899: /*
5900: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5901: background-color: $mail_replied_hover;
5902: }
1.938 bisitz 5903: */
1.795 www 5904:
1.938 bisitz 5905: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5906: background-color: $mail_other;
5907: }
1.795 www 5908:
1.938 bisitz 5909: /*
5910: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5911: background-color: $mail_other_hover;
5912: }
1.938 bisitz 5913: */
1.494 raeburn 5914:
1.777 tempelho 5915: table.LC_data_table tr > td.LC_browser_file,
5916: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5917: background: #AAEE77;
1.389 albertel 5918: }
1.795 www 5919:
1.777 tempelho 5920: table.LC_data_table tr > td.LC_browser_file_locked,
5921: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5922: background: #FFAA99;
1.387 albertel 5923: }
1.795 www 5924:
1.777 tempelho 5925: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5926: background: #888888;
1.779 bisitz 5927: }
1.795 www 5928:
1.777 tempelho 5929: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5930: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5931: background: #F8F866;
1.777 tempelho 5932: }
1.795 www 5933:
1.696 bisitz 5934: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5935: background: #E0E8FF;
1.387 albertel 5936: }
1.696 bisitz 5937:
1.707 bisitz 5938: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5939: /* background: #77FF77; */
1.707 bisitz 5940: }
1.795 www 5941:
1.707 bisitz 5942: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5943: border-right: 8px solid #FFFF77;
1.707 bisitz 5944: }
1.795 www 5945:
1.707 bisitz 5946: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5947: border-right: 8px solid #FFAA77;
1.707 bisitz 5948: }
1.795 www 5949:
1.707 bisitz 5950: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5951: border-right: 8px solid #FF7777;
1.707 bisitz 5952: }
1.795 www 5953:
1.707 bisitz 5954: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5955: border-right: 8px solid #AAFF77;
1.707 bisitz 5956: }
1.795 www 5957:
1.707 bisitz 5958: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5959: border-right: 8px solid #11CC55;
1.707 bisitz 5960: }
5961:
1.388 albertel 5962: span.LC_current_location {
1.701 harmsja 5963: font-size:larger;
1.388 albertel 5964: background: $pgbg;
5965: }
1.387 albertel 5966:
1.1029 www 5967: span.LC_current_nav_location {
5968: font-weight:bold;
5969: background: $sidebg;
5970: }
5971:
1.395 albertel 5972: span.LC_parm_menu_item {
5973: font-size: larger;
5974: }
1.795 www 5975:
1.395 albertel 5976: span.LC_parm_scope_all {
5977: color: red;
5978: }
1.795 www 5979:
1.395 albertel 5980: span.LC_parm_scope_folder {
5981: color: green;
5982: }
1.795 www 5983:
1.395 albertel 5984: span.LC_parm_scope_resource {
5985: color: orange;
5986: }
1.795 www 5987:
1.395 albertel 5988: span.LC_parm_part {
5989: color: blue;
5990: }
1.795 www 5991:
1.911 bisitz 5992: span.LC_parm_folder,
5993: span.LC_parm_symb {
1.395 albertel 5994: font-size: x-small;
5995: font-family: $mono;
5996: color: #AAAAAA;
5997: }
5998:
1.977 bisitz 5999: ul.LC_parm_parmlist li {
6000: display: inline-block;
6001: padding: 0.3em 0.8em;
6002: vertical-align: top;
6003: width: 150px;
6004: border-top:1px solid $lg_border_color;
6005: }
6006:
1.795 www 6007: td.LC_parm_overview_level_menu,
6008: td.LC_parm_overview_map_menu,
6009: td.LC_parm_overview_parm_selectors,
6010: td.LC_parm_overview_restrictions {
1.396 albertel 6011: border: 1px solid black;
6012: border-collapse: collapse;
6013: }
1.795 www 6014:
1.396 albertel 6015: table.LC_parm_overview_restrictions td {
6016: border-width: 1px 4px 1px 4px;
6017: border-style: solid;
6018: border-color: $pgbg;
6019: text-align: center;
6020: }
1.795 www 6021:
1.396 albertel 6022: table.LC_parm_overview_restrictions th {
6023: background: $tabbg;
6024: border-width: 1px 4px 1px 4px;
6025: border-style: solid;
6026: border-color: $pgbg;
6027: }
1.795 www 6028:
1.398 albertel 6029: table#LC_helpmenu {
1.803 bisitz 6030: border: none;
1.398 albertel 6031: height: 55px;
1.803 bisitz 6032: border-spacing: 0;
1.398 albertel 6033: }
6034:
6035: table#LC_helpmenu fieldset legend {
6036: font-size: larger;
6037: }
1.795 www 6038:
1.397 albertel 6039: table#LC_helpmenu_links {
6040: width: 100%;
6041: border: 1px solid black;
6042: background: $pgbg;
1.803 bisitz 6043: padding: 0;
1.397 albertel 6044: border-spacing: 1px;
6045: }
1.795 www 6046:
1.397 albertel 6047: table#LC_helpmenu_links tr td {
6048: padding: 1px;
6049: background: $tabbg;
1.399 albertel 6050: text-align: center;
6051: font-weight: bold;
1.397 albertel 6052: }
1.396 albertel 6053:
1.795 www 6054: table#LC_helpmenu_links a:link,
6055: table#LC_helpmenu_links a:visited,
1.397 albertel 6056: table#LC_helpmenu_links a:active {
6057: text-decoration: none;
6058: color: $font;
6059: }
1.795 www 6060:
1.397 albertel 6061: table#LC_helpmenu_links a:hover {
6062: text-decoration: underline;
6063: color: $vlink;
6064: }
1.396 albertel 6065:
1.417 albertel 6066: .LC_chrt_popup_exists {
6067: border: 1px solid #339933;
6068: margin: -1px;
6069: }
1.795 www 6070:
1.417 albertel 6071: .LC_chrt_popup_up {
6072: border: 1px solid yellow;
6073: margin: -1px;
6074: }
1.795 www 6075:
1.417 albertel 6076: .LC_chrt_popup {
6077: border: 1px solid #8888FF;
6078: background: #CCCCFF;
6079: }
1.795 www 6080:
1.421 albertel 6081: table.LC_pick_box {
6082: border-collapse: separate;
6083: background: white;
6084: border: 1px solid black;
6085: border-spacing: 1px;
6086: }
1.795 www 6087:
1.421 albertel 6088: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6089: background: $sidebg;
1.421 albertel 6090: font-weight: bold;
1.900 bisitz 6091: text-align: left;
1.740 bisitz 6092: vertical-align: top;
1.421 albertel 6093: width: 184px;
6094: padding: 8px;
6095: }
1.795 www 6096:
1.579 raeburn 6097: table.LC_pick_box td.LC_pick_box_value {
6098: text-align: left;
6099: padding: 8px;
6100: }
1.795 www 6101:
1.579 raeburn 6102: table.LC_pick_box td.LC_pick_box_select {
6103: text-align: left;
6104: padding: 8px;
6105: }
1.795 www 6106:
1.424 albertel 6107: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6108: padding: 0;
1.421 albertel 6109: height: 1px;
6110: background: black;
6111: }
1.795 www 6112:
1.421 albertel 6113: table.LC_pick_box td.LC_pick_box_submit {
6114: text-align: right;
6115: }
1.795 www 6116:
1.579 raeburn 6117: table.LC_pick_box td.LC_evenrow_value {
6118: text-align: left;
6119: padding: 8px;
6120: background-color: $data_table_light;
6121: }
1.795 www 6122:
1.579 raeburn 6123: table.LC_pick_box td.LC_oddrow_value {
6124: text-align: left;
6125: padding: 8px;
6126: background-color: $data_table_light;
6127: }
1.795 www 6128:
1.579 raeburn 6129: span.LC_helpform_receipt_cat {
6130: font-weight: bold;
6131: }
1.795 www 6132:
1.424 albertel 6133: table.LC_group_priv_box {
6134: background: white;
6135: border: 1px solid black;
6136: border-spacing: 1px;
6137: }
1.795 www 6138:
1.424 albertel 6139: table.LC_group_priv_box td.LC_pick_box_title {
6140: background: $tabbg;
6141: font-weight: bold;
6142: text-align: right;
6143: width: 184px;
6144: }
1.795 www 6145:
1.424 albertel 6146: table.LC_group_priv_box td.LC_groups_fixed {
6147: background: $data_table_light;
6148: text-align: center;
6149: }
1.795 www 6150:
1.424 albertel 6151: table.LC_group_priv_box td.LC_groups_optional {
6152: background: $data_table_dark;
6153: text-align: center;
6154: }
1.795 www 6155:
1.424 albertel 6156: table.LC_group_priv_box td.LC_groups_functionality {
6157: background: $data_table_darker;
6158: text-align: center;
6159: font-weight: bold;
6160: }
1.795 www 6161:
1.424 albertel 6162: table.LC_group_priv td {
6163: text-align: left;
1.803 bisitz 6164: padding: 0;
1.424 albertel 6165: }
6166:
6167: .LC_navbuttons {
6168: margin: 2ex 0ex 2ex 0ex;
6169: }
1.795 www 6170:
1.423 albertel 6171: .LC_topic_bar {
6172: font-weight: bold;
6173: background: $tabbg;
1.918 wenzelju 6174: margin: 1em 0em 1em 2em;
1.805 bisitz 6175: padding: 3px;
1.918 wenzelju 6176: font-size: 1.2em;
1.423 albertel 6177: }
1.795 www 6178:
1.423 albertel 6179: .LC_topic_bar span {
1.918 wenzelju 6180: left: 0.5em;
6181: position: absolute;
1.423 albertel 6182: vertical-align: middle;
1.918 wenzelju 6183: font-size: 1.2em;
1.423 albertel 6184: }
1.795 www 6185:
1.423 albertel 6186: table.LC_course_group_status {
6187: margin: 20px;
6188: }
1.795 www 6189:
1.423 albertel 6190: table.LC_status_selector td {
6191: vertical-align: top;
6192: text-align: center;
1.424 albertel 6193: padding: 4px;
6194: }
1.795 www 6195:
1.599 albertel 6196: div.LC_feedback_link {
1.616 albertel 6197: clear: both;
1.829 kalberla 6198: background: $sidebg;
1.779 bisitz 6199: width: 100%;
1.829 kalberla 6200: padding-bottom: 10px;
6201: border: 1px $tabbg solid;
1.833 kalberla 6202: height: 22px;
6203: line-height: 22px;
6204: padding-top: 5px;
6205: }
6206:
6207: div.LC_feedback_link img {
6208: height: 22px;
1.867 kalberla 6209: vertical-align:middle;
1.829 kalberla 6210: }
6211:
1.911 bisitz 6212: div.LC_feedback_link a {
1.829 kalberla 6213: text-decoration: none;
1.489 raeburn 6214: }
1.795 www 6215:
1.867 kalberla 6216: div.LC_comblock {
1.911 bisitz 6217: display:inline;
1.867 kalberla 6218: color:$font;
6219: font-size:90%;
6220: }
6221:
6222: div.LC_feedback_link div.LC_comblock {
6223: padding-left:5px;
6224: }
6225:
6226: div.LC_feedback_link div.LC_comblock a {
6227: color:$font;
6228: }
6229:
1.489 raeburn 6230: span.LC_feedback_link {
1.858 bisitz 6231: /* background: $feedback_link_bg; */
1.599 albertel 6232: font-size: larger;
6233: }
1.795 www 6234:
1.599 albertel 6235: span.LC_message_link {
1.858 bisitz 6236: /* background: $feedback_link_bg; */
1.599 albertel 6237: font-size: larger;
6238: position: absolute;
6239: right: 1em;
1.489 raeburn 6240: }
1.421 albertel 6241:
1.515 albertel 6242: table.LC_prior_tries {
1.524 albertel 6243: border: 1px solid #000000;
6244: border-collapse: separate;
6245: border-spacing: 1px;
1.515 albertel 6246: }
1.523 albertel 6247:
1.515 albertel 6248: table.LC_prior_tries td {
1.524 albertel 6249: padding: 2px;
1.515 albertel 6250: }
1.523 albertel 6251:
6252: .LC_answer_correct {
1.795 www 6253: background: lightgreen;
6254: color: darkgreen;
6255: padding: 6px;
1.523 albertel 6256: }
1.795 www 6257:
1.523 albertel 6258: .LC_answer_charged_try {
1.797 www 6259: background: #FFAAAA;
1.795 www 6260: color: darkred;
6261: padding: 6px;
1.523 albertel 6262: }
1.795 www 6263:
1.779 bisitz 6264: .LC_answer_not_charged_try,
1.523 albertel 6265: .LC_answer_no_grade,
6266: .LC_answer_late {
1.795 www 6267: background: lightyellow;
1.523 albertel 6268: color: black;
1.795 www 6269: padding: 6px;
1.523 albertel 6270: }
1.795 www 6271:
1.523 albertel 6272: .LC_answer_previous {
1.795 www 6273: background: lightblue;
6274: color: darkblue;
6275: padding: 6px;
1.523 albertel 6276: }
1.795 www 6277:
1.779 bisitz 6278: .LC_answer_no_message {
1.777 tempelho 6279: background: #FFFFFF;
6280: color: black;
1.795 www 6281: padding: 6px;
1.779 bisitz 6282: }
1.795 www 6283:
1.779 bisitz 6284: .LC_answer_unknown {
6285: background: orange;
6286: color: black;
1.795 www 6287: padding: 6px;
1.777 tempelho 6288: }
1.795 www 6289:
1.529 albertel 6290: span.LC_prior_numerical,
6291: span.LC_prior_string,
6292: span.LC_prior_custom,
6293: span.LC_prior_reaction,
6294: span.LC_prior_math {
1.925 bisitz 6295: font-family: $mono;
1.523 albertel 6296: white-space: pre;
6297: }
6298:
1.525 albertel 6299: span.LC_prior_string {
1.925 bisitz 6300: font-family: $mono;
1.525 albertel 6301: white-space: pre;
6302: }
6303:
1.523 albertel 6304: table.LC_prior_option {
6305: width: 100%;
6306: border-collapse: collapse;
6307: }
1.795 www 6308:
1.911 bisitz 6309: table.LC_prior_rank,
1.795 www 6310: table.LC_prior_match {
1.528 albertel 6311: border-collapse: collapse;
6312: }
1.795 www 6313:
1.528 albertel 6314: table.LC_prior_option tr td,
6315: table.LC_prior_rank tr td,
6316: table.LC_prior_match tr td {
1.524 albertel 6317: border: 1px solid #000000;
1.515 albertel 6318: }
6319:
1.855 bisitz 6320: .LC_nobreak {
1.544 albertel 6321: white-space: nowrap;
1.519 raeburn 6322: }
6323:
1.576 raeburn 6324: span.LC_cusr_emph {
6325: font-style: italic;
6326: }
6327:
1.633 raeburn 6328: span.LC_cusr_subheading {
6329: font-weight: normal;
6330: font-size: 85%;
6331: }
6332:
1.861 bisitz 6333: div.LC_docs_entry_move {
1.859 bisitz 6334: border: 1px solid #BBBBBB;
1.545 albertel 6335: background: #DDDDDD;
1.861 bisitz 6336: width: 22px;
1.859 bisitz 6337: padding: 1px;
6338: margin: 0;
1.545 albertel 6339: }
6340:
1.861 bisitz 6341: table.LC_data_table tr > td.LC_docs_entry_commands,
6342: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6343: font-size: x-small;
6344: }
1.795 www 6345:
1.861 bisitz 6346: .LC_docs_entry_parameter {
6347: white-space: nowrap;
6348: }
6349:
1.544 albertel 6350: .LC_docs_copy {
1.545 albertel 6351: color: #000099;
1.544 albertel 6352: }
1.795 www 6353:
1.544 albertel 6354: .LC_docs_cut {
1.545 albertel 6355: color: #550044;
1.544 albertel 6356: }
1.795 www 6357:
1.544 albertel 6358: .LC_docs_rename {
1.545 albertel 6359: color: #009900;
1.544 albertel 6360: }
1.795 www 6361:
1.544 albertel 6362: .LC_docs_remove {
1.545 albertel 6363: color: #990000;
6364: }
6365:
1.547 albertel 6366: .LC_docs_reinit_warn,
6367: .LC_docs_ext_edit {
6368: font-size: x-small;
6369: }
6370:
1.545 albertel 6371: table.LC_docs_adddocs td,
6372: table.LC_docs_adddocs th {
6373: border: 1px solid #BBBBBB;
6374: padding: 4px;
6375: background: #DDDDDD;
1.543 albertel 6376: }
6377:
1.584 albertel 6378: table.LC_sty_begin {
6379: background: #BBFFBB;
6380: }
1.795 www 6381:
1.584 albertel 6382: table.LC_sty_end {
6383: background: #FFBBBB;
6384: }
6385:
1.589 raeburn 6386: table.LC_double_column {
1.803 bisitz 6387: border-width: 0;
1.589 raeburn 6388: border-collapse: collapse;
6389: width: 100%;
6390: padding: 2px;
6391: }
6392:
6393: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6394: top: 2px;
1.589 raeburn 6395: left: 2px;
6396: width: 47%;
6397: vertical-align: top;
6398: }
6399:
6400: table.LC_double_column tr td.LC_right_col {
6401: top: 2px;
1.779 bisitz 6402: right: 2px;
1.589 raeburn 6403: width: 47%;
6404: vertical-align: top;
6405: }
6406:
1.591 raeburn 6407: div.LC_left_float {
6408: float: left;
6409: padding-right: 5%;
1.597 albertel 6410: padding-bottom: 4px;
1.591 raeburn 6411: }
6412:
6413: div.LC_clear_float_header {
1.597 albertel 6414: padding-bottom: 2px;
1.591 raeburn 6415: }
6416:
6417: div.LC_clear_float_footer {
1.597 albertel 6418: padding-top: 10px;
1.591 raeburn 6419: clear: both;
6420: }
6421:
1.597 albertel 6422: div.LC_grade_show_user {
1.941 bisitz 6423: /* border-left: 5px solid $sidebg; */
6424: border-top: 5px solid #000000;
6425: margin: 50px 0 0 0;
1.936 bisitz 6426: padding: 15px 0 5px 10px;
1.597 albertel 6427: }
1.795 www 6428:
1.936 bisitz 6429: div.LC_grade_show_user_odd_row {
1.941 bisitz 6430: /* border-left: 5px solid #000000; */
6431: }
6432:
6433: div.LC_grade_show_user div.LC_Box {
6434: margin-right: 50px;
1.597 albertel 6435: }
6436:
6437: div.LC_grade_submissions,
6438: div.LC_grade_message_center,
1.936 bisitz 6439: div.LC_grade_info_links {
1.597 albertel 6440: margin: 5px;
6441: width: 99%;
6442: background: #FFFFFF;
6443: }
1.795 www 6444:
1.597 albertel 6445: div.LC_grade_submissions_header,
1.936 bisitz 6446: div.LC_grade_message_center_header {
1.705 tempelho 6447: font-weight: bold;
6448: font-size: large;
1.597 albertel 6449: }
1.795 www 6450:
1.597 albertel 6451: div.LC_grade_submissions_body,
1.936 bisitz 6452: div.LC_grade_message_center_body {
1.597 albertel 6453: border: 1px solid black;
6454: width: 99%;
6455: background: #FFFFFF;
6456: }
1.795 www 6457:
1.613 albertel 6458: table.LC_scantron_action {
6459: width: 100%;
6460: }
1.795 www 6461:
1.613 albertel 6462: table.LC_scantron_action tr th {
1.698 harmsja 6463: font-weight:bold;
6464: font-style:normal;
1.613 albertel 6465: }
1.795 www 6466:
1.779 bisitz 6467: .LC_edit_problem_header,
1.614 albertel 6468: div.LC_edit_problem_footer {
1.705 tempelho 6469: font-weight: normal;
6470: font-size: medium;
1.602 albertel 6471: margin: 2px;
1.1060 bisitz 6472: background-color: $sidebg;
1.600 albertel 6473: }
1.795 www 6474:
1.600 albertel 6475: div.LC_edit_problem_header,
1.602 albertel 6476: div.LC_edit_problem_header div,
1.614 albertel 6477: div.LC_edit_problem_footer,
6478: div.LC_edit_problem_footer div,
1.602 albertel 6479: div.LC_edit_problem_editxml_header,
6480: div.LC_edit_problem_editxml_header div {
1.600 albertel 6481: margin-top: 5px;
6482: }
1.795 www 6483:
1.600 albertel 6484: div.LC_edit_problem_header_title {
1.705 tempelho 6485: font-weight: bold;
6486: font-size: larger;
1.602 albertel 6487: background: $tabbg;
6488: padding: 3px;
1.1060 bisitz 6489: margin: 0 0 5px 0;
1.602 albertel 6490: }
1.795 www 6491:
1.602 albertel 6492: table.LC_edit_problem_header_title {
6493: width: 100%;
1.600 albertel 6494: background: $tabbg;
1.602 albertel 6495: }
6496:
6497: div.LC_edit_problem_discards {
6498: float: left;
6499: padding-bottom: 5px;
6500: }
1.795 www 6501:
1.602 albertel 6502: div.LC_edit_problem_saves {
6503: float: right;
6504: padding-bottom: 5px;
1.600 albertel 6505: }
1.795 www 6506:
1.1075.2.34 raeburn 6507: .LC_edit_opt {
6508: padding-left: 1em;
6509: white-space: nowrap;
6510: }
6511:
1.1075.2.57 raeburn 6512: .LC_edit_problem_latexhelper{
6513: text-align: right;
6514: }
6515:
6516: #LC_edit_problem_colorful div{
6517: margin-left: 40px;
6518: }
6519:
1.911 bisitz 6520: img.stift {
1.803 bisitz 6521: border-width: 0;
6522: vertical-align: middle;
1.677 riegler 6523: }
1.680 riegler 6524:
1.923 bisitz 6525: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6526: vertical-align: top;
1.777 tempelho 6527: }
1.795 www 6528:
1.716 raeburn 6529: div.LC_createcourse {
1.911 bisitz 6530: margin: 10px 10px 10px 10px;
1.716 raeburn 6531: }
6532:
1.917 raeburn 6533: .LC_dccid {
1.1075.2.38 raeburn 6534: float: right;
1.917 raeburn 6535: margin: 0.2em 0 0 0;
6536: padding: 0;
6537: font-size: 90%;
6538: display:none;
6539: }
6540:
1.897 wenzelju 6541: ol.LC_primary_menu a:hover,
1.721 harmsja 6542: ol#LC_MenuBreadcrumbs a:hover,
6543: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6544: ul#LC_secondary_menu a:hover,
1.721 harmsja 6545: .LC_FormSectionClearButton input:hover
1.795 www 6546: ul.LC_TabContent li:hover a {
1.952 onken 6547: color:$button_hover;
1.911 bisitz 6548: text-decoration:none;
1.693 droeschl 6549: }
6550:
1.779 bisitz 6551: h1 {
1.911 bisitz 6552: padding: 0;
6553: line-height:130%;
1.693 droeschl 6554: }
1.698 harmsja 6555:
1.911 bisitz 6556: h2,
6557: h3,
6558: h4,
6559: h5,
6560: h6 {
6561: margin: 5px 0 5px 0;
6562: padding: 0;
6563: line-height:130%;
1.693 droeschl 6564: }
1.795 www 6565:
6566: .LC_hcell {
1.911 bisitz 6567: padding:3px 15px 3px 15px;
6568: margin: 0;
6569: background-color:$tabbg;
6570: color:$fontmenu;
6571: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6572: }
1.795 www 6573:
1.840 bisitz 6574: .LC_Box > .LC_hcell {
1.911 bisitz 6575: margin: 0 -10px 10px -10px;
1.835 bisitz 6576: }
6577:
1.721 harmsja 6578: .LC_noBorder {
1.911 bisitz 6579: border: 0;
1.698 harmsja 6580: }
1.693 droeschl 6581:
1.721 harmsja 6582: .LC_FormSectionClearButton input {
1.911 bisitz 6583: background-color:transparent;
6584: border: none;
6585: cursor:pointer;
6586: text-decoration:underline;
1.693 droeschl 6587: }
1.763 bisitz 6588:
6589: .LC_help_open_topic {
1.911 bisitz 6590: color: #FFFFFF;
6591: background-color: #EEEEFF;
6592: margin: 1px;
6593: padding: 4px;
6594: border: 1px solid #000033;
6595: white-space: nowrap;
6596: /* vertical-align: middle; */
1.759 neumanie 6597: }
1.693 droeschl 6598:
1.911 bisitz 6599: dl,
6600: ul,
6601: div,
6602: fieldset {
6603: margin: 10px 10px 10px 0;
6604: /* overflow: hidden; */
1.693 droeschl 6605: }
1.795 www 6606:
1.838 bisitz 6607: fieldset > legend {
1.911 bisitz 6608: font-weight: bold;
6609: padding: 0 5px 0 5px;
1.838 bisitz 6610: }
6611:
1.813 bisitz 6612: #LC_nav_bar {
1.911 bisitz 6613: float: left;
1.995 raeburn 6614: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6615: margin: 0 0 2px 0;
1.807 droeschl 6616: }
6617:
1.916 droeschl 6618: #LC_realm {
6619: margin: 0.2em 0 0 0;
6620: padding: 0;
6621: font-weight: bold;
6622: text-align: center;
1.995 raeburn 6623: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6624: }
6625:
1.911 bisitz 6626: #LC_nav_bar em {
6627: font-weight: bold;
6628: font-style: normal;
1.807 droeschl 6629: }
6630:
1.897 wenzelju 6631: ol.LC_primary_menu {
1.934 droeschl 6632: margin: 0;
1.1075.2.2 raeburn 6633: padding: 0;
1.995 raeburn 6634: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6635: }
6636:
1.852 droeschl 6637: ol#LC_PathBreadcrumbs {
1.911 bisitz 6638: margin: 0;
1.693 droeschl 6639: }
6640:
1.897 wenzelju 6641: ol.LC_primary_menu li {
1.1075.2.2 raeburn 6642: color: RGB(80, 80, 80);
6643: vertical-align: middle;
6644: text-align: left;
6645: list-style: none;
6646: float: left;
6647: }
6648:
6649: ol.LC_primary_menu li a {
6650: display: block;
6651: margin: 0;
6652: padding: 0 5px 0 10px;
6653: text-decoration: none;
6654: }
6655:
6656: ol.LC_primary_menu li ul {
6657: display: none;
6658: width: 10em;
6659: background-color: $data_table_light;
6660: }
6661:
6662: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6663: display: block;
6664: position: absolute;
6665: margin: 0;
6666: padding: 0;
1.1075.2.5 raeburn 6667: z-index: 2;
1.1075.2.2 raeburn 6668: }
6669:
6670: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6671: font-size: 90%;
1.911 bisitz 6672: vertical-align: top;
1.1075.2.2 raeburn 6673: float: none;
1.1075.2.5 raeburn 6674: border-left: 1px solid black;
6675: border-right: 1px solid black;
1.1075.2.2 raeburn 6676: }
6677:
6678: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5 raeburn 6679: background-color:$data_table_light;
1.1075.2.2 raeburn 6680: }
6681:
6682: ol.LC_primary_menu li li a:hover {
6683: color:$button_hover;
6684: background-color:$data_table_dark;
1.693 droeschl 6685: }
6686:
1.897 wenzelju 6687: ol.LC_primary_menu li img {
1.911 bisitz 6688: vertical-align: bottom;
1.934 droeschl 6689: height: 1.1em;
1.1075.2.3 raeburn 6690: margin: 0.2em 0 0 0;
1.693 droeschl 6691: }
6692:
1.897 wenzelju 6693: ol.LC_primary_menu a {
1.911 bisitz 6694: color: RGB(80, 80, 80);
6695: text-decoration: none;
1.693 droeschl 6696: }
1.795 www 6697:
1.949 droeschl 6698: ol.LC_primary_menu a.LC_new_message {
6699: font-weight:bold;
6700: color: darkred;
6701: }
6702:
1.975 raeburn 6703: ol.LC_docs_parameters {
6704: margin-left: 0;
6705: padding: 0;
6706: list-style: none;
6707: }
6708:
6709: ol.LC_docs_parameters li {
6710: margin: 0;
6711: padding-right: 20px;
6712: display: inline;
6713: }
6714:
1.976 raeburn 6715: ol.LC_docs_parameters li:before {
6716: content: "\\002022 \\0020";
6717: }
6718:
6719: li.LC_docs_parameters_title {
6720: font-weight: bold;
6721: }
6722:
6723: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6724: content: "";
6725: }
6726:
1.897 wenzelju 6727: ul#LC_secondary_menu {
1.1075.2.23 raeburn 6728: clear: right;
1.911 bisitz 6729: color: $fontmenu;
6730: background: $tabbg;
6731: list-style: none;
6732: padding: 0;
6733: margin: 0;
6734: width: 100%;
1.995 raeburn 6735: text-align: left;
1.1075.2.4 raeburn 6736: float: left;
1.808 droeschl 6737: }
6738:
1.897 wenzelju 6739: ul#LC_secondary_menu li {
1.911 bisitz 6740: font-weight: bold;
6741: line-height: 1.8em;
6742: border-right: 1px solid black;
6743: vertical-align: middle;
1.1075.2.4 raeburn 6744: float: left;
6745: }
6746:
6747: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6748: background-color: $data_table_light;
6749: }
6750:
6751: ul#LC_secondary_menu li a {
6752: padding: 0 0.8em;
6753: }
6754:
6755: ul#LC_secondary_menu li ul {
6756: display: none;
6757: }
6758:
6759: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6760: display: block;
6761: position: absolute;
6762: margin: 0;
6763: padding: 0;
6764: list-style:none;
6765: float: none;
6766: background-color: $data_table_light;
1.1075.2.5 raeburn 6767: z-index: 2;
1.1075.2.10 raeburn 6768: margin-left: -1px;
1.1075.2.4 raeburn 6769: }
6770:
6771: ul#LC_secondary_menu li ul li {
6772: font-size: 90%;
6773: vertical-align: top;
6774: border-left: 1px solid black;
6775: border-right: 1px solid black;
1.1075.2.33 raeburn 6776: background-color: $data_table_light;
1.1075.2.4 raeburn 6777: list-style:none;
6778: float: none;
6779: }
6780:
6781: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6782: background-color: $data_table_dark;
1.807 droeschl 6783: }
6784:
1.847 tempelho 6785: ul.LC_TabContent {
1.911 bisitz 6786: display:block;
6787: background: $sidebg;
6788: border-bottom: solid 1px $lg_border_color;
6789: list-style:none;
1.1020 raeburn 6790: margin: -1px -10px 0 -10px;
1.911 bisitz 6791: padding: 0;
1.693 droeschl 6792: }
6793:
1.795 www 6794: ul.LC_TabContent li,
6795: ul.LC_TabContentBigger li {
1.911 bisitz 6796: float:left;
1.741 harmsja 6797: }
1.795 www 6798:
1.897 wenzelju 6799: ul#LC_secondary_menu li a {
1.911 bisitz 6800: color: $fontmenu;
6801: text-decoration: none;
1.693 droeschl 6802: }
1.795 www 6803:
1.721 harmsja 6804: ul.LC_TabContent {
1.952 onken 6805: min-height:20px;
1.721 harmsja 6806: }
1.795 www 6807:
6808: ul.LC_TabContent li {
1.911 bisitz 6809: vertical-align:middle;
1.959 onken 6810: padding: 0 16px 0 10px;
1.911 bisitz 6811: background-color:$tabbg;
6812: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6813: border-left: solid 1px $font;
1.721 harmsja 6814: }
1.795 www 6815:
1.847 tempelho 6816: ul.LC_TabContent .right {
1.911 bisitz 6817: float:right;
1.847 tempelho 6818: }
6819:
1.911 bisitz 6820: ul.LC_TabContent li a,
6821: ul.LC_TabContent li {
6822: color:rgb(47,47,47);
6823: text-decoration:none;
6824: font-size:95%;
6825: font-weight:bold;
1.952 onken 6826: min-height:20px;
6827: }
6828:
1.959 onken 6829: ul.LC_TabContent li a:hover,
6830: ul.LC_TabContent li a:focus {
1.952 onken 6831: color: $button_hover;
1.959 onken 6832: background:none;
6833: outline:none;
1.952 onken 6834: }
6835:
6836: ul.LC_TabContent li:hover {
6837: color: $button_hover;
6838: cursor:pointer;
1.721 harmsja 6839: }
1.795 www 6840:
1.911 bisitz 6841: ul.LC_TabContent li.active {
1.952 onken 6842: color: $font;
1.911 bisitz 6843: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6844: border-bottom:solid 1px #FFFFFF;
6845: cursor: default;
1.744 ehlerst 6846: }
1.795 www 6847:
1.959 onken 6848: ul.LC_TabContent li.active a {
6849: color:$font;
6850: background:#FFFFFF;
6851: outline: none;
6852: }
1.1047 raeburn 6853:
6854: ul.LC_TabContent li.goback {
6855: float: left;
6856: border-left: none;
6857: }
6858:
1.870 tempelho 6859: #maincoursedoc {
1.911 bisitz 6860: clear:both;
1.870 tempelho 6861: }
6862:
6863: ul.LC_TabContentBigger {
1.911 bisitz 6864: display:block;
6865: list-style:none;
6866: padding: 0;
1.870 tempelho 6867: }
6868:
1.795 www 6869: ul.LC_TabContentBigger li {
1.911 bisitz 6870: vertical-align:bottom;
6871: height: 30px;
6872: font-size:110%;
6873: font-weight:bold;
6874: color: #737373;
1.841 tempelho 6875: }
6876:
1.957 onken 6877: ul.LC_TabContentBigger li.active {
6878: position: relative;
6879: top: 1px;
6880: }
6881:
1.870 tempelho 6882: ul.LC_TabContentBigger li a {
1.911 bisitz 6883: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6884: height: 30px;
6885: line-height: 30px;
6886: text-align: center;
6887: display: block;
6888: text-decoration: none;
1.958 onken 6889: outline: none;
1.741 harmsja 6890: }
1.795 www 6891:
1.870 tempelho 6892: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6893: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6894: color:$font;
1.744 ehlerst 6895: }
1.795 www 6896:
1.870 tempelho 6897: ul.LC_TabContentBigger li b {
1.911 bisitz 6898: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6899: display: block;
6900: float: left;
6901: padding: 0 30px;
1.957 onken 6902: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6903: }
6904:
1.956 onken 6905: ul.LC_TabContentBigger li:hover b {
6906: color:$button_hover;
6907: }
6908:
1.870 tempelho 6909: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6910: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6911: color:$font;
1.957 onken 6912: border: 0;
1.741 harmsja 6913: }
1.693 droeschl 6914:
1.870 tempelho 6915:
1.862 bisitz 6916: ul.LC_CourseBreadcrumbs {
6917: background: $sidebg;
1.1020 raeburn 6918: height: 2em;
1.862 bisitz 6919: padding-left: 10px;
1.1020 raeburn 6920: margin: 0;
1.862 bisitz 6921: list-style-position: inside;
6922: }
6923:
1.911 bisitz 6924: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6925: ol#LC_PathBreadcrumbs {
1.911 bisitz 6926: padding-left: 10px;
6927: margin: 0;
1.933 droeschl 6928: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6929: }
6930:
1.911 bisitz 6931: ol#LC_MenuBreadcrumbs li,
6932: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6933: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6934: display: inline;
1.933 droeschl 6935: white-space: normal;
1.693 droeschl 6936: }
6937:
1.823 bisitz 6938: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6939: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6940: text-decoration: none;
6941: font-size:90%;
1.693 droeschl 6942: }
1.795 www 6943:
1.969 droeschl 6944: ol#LC_MenuBreadcrumbs h1 {
6945: display: inline;
6946: font-size: 90%;
6947: line-height: 2.5em;
6948: margin: 0;
6949: padding: 0;
6950: }
6951:
1.795 www 6952: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6953: text-decoration:none;
6954: font-size:100%;
6955: font-weight:bold;
1.693 droeschl 6956: }
1.795 www 6957:
1.840 bisitz 6958: .LC_Box {
1.911 bisitz 6959: border: solid 1px $lg_border_color;
6960: padding: 0 10px 10px 10px;
1.746 neumanie 6961: }
1.795 www 6962:
1.1020 raeburn 6963: .LC_DocsBox {
6964: border: solid 1px $lg_border_color;
6965: padding: 0 0 10px 10px;
6966: }
6967:
1.795 www 6968: .LC_AboutMe_Image {
1.911 bisitz 6969: float:left;
6970: margin-right:10px;
1.747 neumanie 6971: }
1.795 www 6972:
6973: .LC_Clear_AboutMe_Image {
1.911 bisitz 6974: clear:left;
1.747 neumanie 6975: }
1.795 www 6976:
1.721 harmsja 6977: dl.LC_ListStyleClean dt {
1.911 bisitz 6978: padding-right: 5px;
6979: display: table-header-group;
1.693 droeschl 6980: }
6981:
1.721 harmsja 6982: dl.LC_ListStyleClean dd {
1.911 bisitz 6983: display: table-row;
1.693 droeschl 6984: }
6985:
1.721 harmsja 6986: .LC_ListStyleClean,
6987: .LC_ListStyleSimple,
6988: .LC_ListStyleNormal,
1.795 www 6989: .LC_ListStyleSpecial {
1.911 bisitz 6990: /* display:block; */
6991: list-style-position: inside;
6992: list-style-type: none;
6993: overflow: hidden;
6994: padding: 0;
1.693 droeschl 6995: }
6996:
1.721 harmsja 6997: .LC_ListStyleSimple li,
6998: .LC_ListStyleSimple dd,
6999: .LC_ListStyleNormal li,
7000: .LC_ListStyleNormal dd,
7001: .LC_ListStyleSpecial li,
1.795 www 7002: .LC_ListStyleSpecial dd {
1.911 bisitz 7003: margin: 0;
7004: padding: 5px 5px 5px 10px;
7005: clear: both;
1.693 droeschl 7006: }
7007:
1.721 harmsja 7008: .LC_ListStyleClean li,
7009: .LC_ListStyleClean dd {
1.911 bisitz 7010: padding-top: 0;
7011: padding-bottom: 0;
1.693 droeschl 7012: }
7013:
1.721 harmsja 7014: .LC_ListStyleSimple dd,
1.795 www 7015: .LC_ListStyleSimple li {
1.911 bisitz 7016: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7017: }
7018:
1.721 harmsja 7019: .LC_ListStyleSpecial li,
7020: .LC_ListStyleSpecial dd {
1.911 bisitz 7021: list-style-type: none;
7022: background-color: RGB(220, 220, 220);
7023: margin-bottom: 4px;
1.693 droeschl 7024: }
7025:
1.721 harmsja 7026: table.LC_SimpleTable {
1.911 bisitz 7027: margin:5px;
7028: border:solid 1px $lg_border_color;
1.795 www 7029: }
1.693 droeschl 7030:
1.721 harmsja 7031: table.LC_SimpleTable tr {
1.911 bisitz 7032: padding: 0;
7033: border:solid 1px $lg_border_color;
1.693 droeschl 7034: }
1.795 www 7035:
7036: table.LC_SimpleTable thead {
1.911 bisitz 7037: background:rgb(220,220,220);
1.693 droeschl 7038: }
7039:
1.721 harmsja 7040: div.LC_columnSection {
1.911 bisitz 7041: display: block;
7042: clear: both;
7043: overflow: hidden;
7044: margin: 0;
1.693 droeschl 7045: }
7046:
1.721 harmsja 7047: div.LC_columnSection>* {
1.911 bisitz 7048: float: left;
7049: margin: 10px 20px 10px 0;
7050: overflow:hidden;
1.693 droeschl 7051: }
1.721 harmsja 7052:
1.795 www 7053: table em {
1.911 bisitz 7054: font-weight: bold;
7055: font-style: normal;
1.748 schulted 7056: }
1.795 www 7057:
1.779 bisitz 7058: table.LC_tableBrowseRes,
1.795 www 7059: table.LC_tableOfContent {
1.911 bisitz 7060: border:none;
7061: border-spacing: 1px;
7062: padding: 3px;
7063: background-color: #FFFFFF;
7064: font-size: 90%;
1.753 droeschl 7065: }
1.789 droeschl 7066:
1.911 bisitz 7067: table.LC_tableOfContent {
7068: border-collapse: collapse;
1.789 droeschl 7069: }
7070:
1.771 droeschl 7071: table.LC_tableBrowseRes a,
1.768 schulted 7072: table.LC_tableOfContent a {
1.911 bisitz 7073: background-color: transparent;
7074: text-decoration: none;
1.753 droeschl 7075: }
7076:
1.795 www 7077: table.LC_tableOfContent img {
1.911 bisitz 7078: border: none;
7079: height: 1.3em;
7080: vertical-align: text-bottom;
7081: margin-right: 0.3em;
1.753 droeschl 7082: }
1.757 schulted 7083:
1.795 www 7084: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7085: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7086: }
7087:
1.795 www 7088: a#LC_content_toolbar_everything {
1.911 bisitz 7089: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7090: }
7091:
1.795 www 7092: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7093: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7094: }
7095:
1.795 www 7096: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7097: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7098: }
7099:
1.795 www 7100: a#LC_content_toolbar_changefolder {
1.911 bisitz 7101: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7102: }
7103:
1.795 www 7104: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7105: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7106: }
7107:
1.1043 raeburn 7108: a#LC_content_toolbar_edittoplevel {
7109: background-image:url(/res/adm/pages/edittoplevel.gif);
7110: }
7111:
1.795 www 7112: ul#LC_toolbar li a:hover {
1.911 bisitz 7113: background-position: bottom center;
1.757 schulted 7114: }
7115:
1.795 www 7116: ul#LC_toolbar {
1.911 bisitz 7117: padding: 0;
7118: margin: 2px;
7119: list-style:none;
7120: position:relative;
7121: background-color:white;
1.1075.2.9 raeburn 7122: overflow: auto;
1.757 schulted 7123: }
7124:
1.795 www 7125: ul#LC_toolbar li {
1.911 bisitz 7126: border:1px solid white;
7127: padding: 0;
7128: margin: 0;
7129: float: left;
7130: display:inline;
7131: vertical-align:middle;
1.1075.2.9 raeburn 7132: white-space: nowrap;
1.911 bisitz 7133: }
1.757 schulted 7134:
1.783 amueller 7135:
1.795 www 7136: a.LC_toolbarItem {
1.911 bisitz 7137: display:block;
7138: padding: 0;
7139: margin: 0;
7140: height: 32px;
7141: width: 32px;
7142: color:white;
7143: border: none;
7144: background-repeat:no-repeat;
7145: background-color:transparent;
1.757 schulted 7146: }
7147:
1.915 droeschl 7148: ul.LC_funclist {
7149: margin: 0;
7150: padding: 0.5em 1em 0.5em 0;
7151: }
7152:
1.933 droeschl 7153: ul.LC_funclist > li:first-child {
7154: font-weight:bold;
7155: margin-left:0.8em;
7156: }
7157:
1.915 droeschl 7158: ul.LC_funclist + ul.LC_funclist {
7159: /*
7160: left border as a seperator if we have more than
7161: one list
7162: */
7163: border-left: 1px solid $sidebg;
7164: /*
7165: this hides the left border behind the border of the
7166: outer box if element is wrapped to the next 'line'
7167: */
7168: margin-left: -1px;
7169: }
7170:
1.843 bisitz 7171: ul.LC_funclist li {
1.915 droeschl 7172: display: inline;
1.782 bisitz 7173: white-space: nowrap;
1.915 droeschl 7174: margin: 0 0 0 25px;
7175: line-height: 150%;
1.782 bisitz 7176: }
7177:
1.974 wenzelju 7178: .LC_hidden {
7179: display: none;
7180: }
7181:
1.1030 www 7182: .LCmodal-overlay {
7183: position:fixed;
7184: top:0;
7185: right:0;
7186: bottom:0;
7187: left:0;
7188: height:100%;
7189: width:100%;
7190: margin:0;
7191: padding:0;
7192: background:#999;
7193: opacity:.75;
7194: filter: alpha(opacity=75);
7195: -moz-opacity: 0.75;
7196: z-index:101;
7197: }
7198:
7199: * html .LCmodal-overlay {
7200: position: absolute;
7201: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7202: }
7203:
7204: .LCmodal-window {
7205: position:fixed;
7206: top:50%;
7207: left:50%;
7208: margin:0;
7209: padding:0;
7210: z-index:102;
7211: }
7212:
7213: * html .LCmodal-window {
7214: position:absolute;
7215: }
7216:
7217: .LCclose-window {
7218: position:absolute;
7219: width:32px;
7220: height:32px;
7221: right:8px;
7222: top:8px;
7223: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7224: text-indent:-99999px;
7225: overflow:hidden;
7226: cursor:pointer;
7227: }
7228:
1.1075.2.17 raeburn 7229: /*
7230: styles used by TTH when "Default set of options to pass to tth/m
7231: when converting TeX" in course settings has been set
7232:
7233: option passed: -t
7234:
7235: */
7236:
7237: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7238: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7239: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7240: td div.norm {line-height:normal;}
7241:
7242: /*
7243: option passed -y3
7244: */
7245:
7246: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7247: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7248: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7249:
1.343 albertel 7250: END
7251: }
7252:
1.306 albertel 7253: =pod
7254:
7255: =item * &headtag()
7256:
7257: Returns a uniform footer for LON-CAPA web pages.
7258:
1.307 albertel 7259: Inputs: $title - optional title for the head
7260: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7261: $args - optional arguments
1.319 albertel 7262: force_register - if is true call registerurl so the remote is
7263: informed
1.415 albertel 7264: redirect -> array ref of
7265: 1- seconds before redirect occurs
7266: 2- url to redirect to
7267: 3- whether the side effect should occur
1.315 albertel 7268: (side effect of setting
7269: $env{'internal.head.redirect'} to the url
7270: redirected too)
1.352 albertel 7271: domain -> force to color decorate a page for a specific
7272: domain
7273: function -> force usage of a specific rolish color scheme
7274: bgcolor -> override the default page bgcolor
1.460 albertel 7275: no_auto_mt_title
7276: -> prevent &mt()ing the title arg
1.464 albertel 7277:
1.306 albertel 7278: =cut
7279:
7280: sub headtag {
1.313 albertel 7281: my ($title,$head_extra,$args) = @_;
1.306 albertel 7282:
1.363 albertel 7283: my $function = $args->{'function'} || &get_users_function();
7284: my $domain = $args->{'domain'} || &determinedomain();
7285: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7286: my $httphost = $args->{'use_absolute'};
1.418 albertel 7287: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7288: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7289: #time(),
1.418 albertel 7290: $env{'environment.color.timestamp'},
1.363 albertel 7291: $function,$domain,$bgcolor);
7292:
1.369 www 7293: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7294:
1.308 albertel 7295: my $result =
7296: '<head>'.
1.1075.2.56 raeburn 7297: &font_settings($args);
1.319 albertel 7298:
1.1064 raeburn 7299: my $inhibitprint = &print_suppression();
7300:
1.461 albertel 7301: if (!$args->{'frameset'}) {
7302: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7303: }
1.1075.2.12 raeburn 7304: if ($args->{'force_register'}) {
7305: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7306: }
1.436 albertel 7307: if (!$args->{'no_nav_bar'}
7308: && !$args->{'only_body'}
7309: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7310: $result .= &help_menu_js($httphost);
1.1032 www 7311: $result.=&modal_window();
1.1038 www 7312: $result.=&togglebox_script();
1.1034 www 7313: $result.=&wishlist_window();
1.1041 www 7314: $result.=&LCprogressbarUpdate_script();
1.1034 www 7315: } else {
7316: if ($args->{'add_modal'}) {
7317: $result.=&modal_window();
7318: }
7319: if ($args->{'add_wishlist'}) {
7320: $result.=&wishlist_window();
7321: }
1.1038 www 7322: if ($args->{'add_togglebox'}) {
7323: $result.=&togglebox_script();
7324: }
1.1041 www 7325: if ($args->{'add_progressbar'}) {
7326: $result.=&LCprogressbarUpdate_script();
7327: }
1.436 albertel 7328: }
1.314 albertel 7329: if (ref($args->{'redirect'})) {
1.414 albertel 7330: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7331: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7332: if (!$inhibit_continue) {
7333: $env{'internal.head.redirect'} = $url;
7334: }
1.313 albertel 7335: $result.=<<ADDMETA
7336: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7337: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7338: ADDMETA
7339: }
1.306 albertel 7340: if (!defined($title)) {
7341: $title = 'The LearningOnline Network with CAPA';
7342: }
1.460 albertel 7343: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7344: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7345: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7346: if (!$args->{'frameset'}) {
7347: $result .= ' /';
7348: }
7349: $result .= '>'
1.1064 raeburn 7350: .$inhibitprint
1.414 albertel 7351: .$head_extra;
1.1075.2.42 raeburn 7352: if ($env{'browser.mobile'}) {
7353: $result .= '
7354: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7355: <meta name="apple-mobile-web-app-capable" content="yes" />';
7356: }
1.962 droeschl 7357: return $result.'</head>';
1.306 albertel 7358: }
7359:
7360: =pod
7361:
1.340 albertel 7362: =item * &font_settings()
7363:
7364: Returns neccessary <meta> to set the proper encoding
7365:
1.1075.2.56 raeburn 7366: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7367:
7368: =cut
7369:
7370: sub font_settings {
1.1075.2.56 raeburn 7371: my ($args) = @_;
1.340 albertel 7372: my $headerstring='';
1.1075.2.56 raeburn 7373: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7374: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7375: $headerstring.=
1.1075.2.61 raeburn 7376: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7377: if (!$args->{'frameset'}) {
7378: $headerstring.= ' /';
7379: }
7380: $headerstring .= '>'."\n";
1.340 albertel 7381: }
7382: return $headerstring;
7383: }
7384:
1.341 albertel 7385: =pod
7386:
1.1064 raeburn 7387: =item * &print_suppression()
7388:
7389: In course context returns css which causes the body to be blank when media="print",
7390: if printout generation is unavailable for the current resource.
7391:
7392: This could be because:
7393:
7394: (a) printstartdate is in the future
7395:
7396: (b) printenddate is in the past
7397:
7398: (c) there is an active exam block with "printout"
7399: functionality blocked
7400:
7401: Users with pav, pfo or evb privileges are exempt.
7402:
7403: Inputs: none
7404:
7405: =cut
7406:
7407:
7408: sub print_suppression {
7409: my $noprint;
7410: if ($env{'request.course.id'}) {
7411: my $scope = $env{'request.course.id'};
7412: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7413: (&Apache::lonnet::allowed('pfo',$scope))) {
7414: return;
7415: }
7416: if ($env{'request.course.sec'} ne '') {
7417: $scope .= "/$env{'request.course.sec'}";
7418: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7419: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7420: return;
1.1064 raeburn 7421: }
7422: }
7423: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7424: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7425: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7426: if ($blocked) {
7427: my $checkrole = "cm./$cdom/$cnum";
7428: if ($env{'request.course.sec'} ne '') {
7429: $checkrole .= "/$env{'request.course.sec'}";
7430: }
7431: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7432: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7433: $noprint = 1;
7434: }
7435: }
7436: unless ($noprint) {
7437: my $symb = &Apache::lonnet::symbread();
7438: if ($symb ne '') {
7439: my $navmap = Apache::lonnavmaps::navmap->new();
7440: if (ref($navmap)) {
7441: my $res = $navmap->getBySymb($symb);
7442: if (ref($res)) {
7443: if (!$res->resprintable()) {
7444: $noprint = 1;
7445: }
7446: }
7447: }
7448: }
7449: }
7450: if ($noprint) {
7451: return <<"ENDSTYLE";
7452: <style type="text/css" media="print">
7453: body { display:none }
7454: </style>
7455: ENDSTYLE
7456: }
7457: }
7458: return;
7459: }
7460:
7461: =pod
7462:
1.341 albertel 7463: =item * &xml_begin()
7464:
7465: Returns the needed doctype and <html>
7466:
7467: Inputs: none
7468:
7469: =cut
7470:
7471: sub xml_begin {
1.1075.2.61 raeburn 7472: my ($is_frameset) = @_;
1.341 albertel 7473: my $output='';
7474:
7475: if ($env{'browser.mathml'}) {
7476: $output='<?xml version="1.0"?>'
7477: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7478: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7479:
7480: # .'<!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">] >'
7481: .'<!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">'
7482: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7483: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 7484: } elsif ($is_frameset) {
7485: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7486: '<html>'."\n";
1.341 albertel 7487: } else {
1.1075.2.61 raeburn 7488: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7489: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7490: }
7491: return $output;
7492: }
1.340 albertel 7493:
7494: =pod
7495:
1.306 albertel 7496: =item * &start_page()
7497:
7498: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7499:
1.648 raeburn 7500: Inputs:
7501:
7502: =over 4
7503:
7504: $title - optional title for the page
7505:
7506: $head_extra - optional extra HTML to incude inside the <head>
7507:
7508: $args - additional optional args supported are:
7509:
7510: =over 8
7511:
7512: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7513: arg on
1.814 bisitz 7514: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7515: add_entries -> additional attributes to add to the <body>
7516: domain -> force to color decorate a page for a
1.317 albertel 7517: specific domain
1.648 raeburn 7518: function -> force usage of a specific rolish color
1.317 albertel 7519: scheme
1.648 raeburn 7520: redirect -> see &headtag()
7521: bgcolor -> override the default page bg color
7522: js_ready -> return a string ready for being used in
1.317 albertel 7523: a javascript writeln
1.648 raeburn 7524: html_encode -> return a string ready for being used in
1.320 albertel 7525: a html attribute
1.648 raeburn 7526: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7527: $forcereg arg
1.648 raeburn 7528: frameset -> if true will start with a <frameset>
1.330 albertel 7529: rather than <body>
1.648 raeburn 7530: skip_phases -> hash ref of
1.338 albertel 7531: head -> skip the <html><head> generation
7532: body -> skip all <body> generation
1.1075.2.12 raeburn 7533: no_inline_link -> if true and in remote mode, don't show the
7534: 'Switch To Inline Menu' link
1.648 raeburn 7535: no_auto_mt_title -> prevent &mt()ing the title arg
7536: inherit_jsmath -> when creating popup window in a page,
7537: should it have jsmath forced on by the
7538: current page
1.867 kalberla 7539: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7540: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.15 raeburn 7541: group -> includes the current group, if page is for a
7542: specific group
1.361 albertel 7543:
1.648 raeburn 7544: =back
1.460 albertel 7545:
1.648 raeburn 7546: =back
1.562 albertel 7547:
1.306 albertel 7548: =cut
7549:
7550: sub start_page {
1.309 albertel 7551: my ($title,$head_extra,$args) = @_;
1.318 albertel 7552: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7553:
1.315 albertel 7554: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 7555: my ($result,@advtools);
1.964 droeschl 7556:
1.338 albertel 7557: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 7558: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 7559: }
7560:
7561: if (! exists($args->{'skip_phases'}{'body'}) ) {
7562: if ($args->{'frameset'}) {
7563: my $attr_string = &make_attr_string($args->{'force_register'},
7564: $args->{'add_entries'});
7565: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7566: } else {
7567: $result .=
7568: &bodytag($title,
7569: $args->{'function'}, $args->{'add_entries'},
7570: $args->{'only_body'}, $args->{'domain'},
7571: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 7572: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 7573: $args, \@advtools);
1.831 bisitz 7574: }
1.330 albertel 7575: }
1.338 albertel 7576:
1.315 albertel 7577: if ($args->{'js_ready'}) {
1.713 kaisler 7578: $result = &js_ready($result);
1.315 albertel 7579: }
1.320 albertel 7580: if ($args->{'html_encode'}) {
1.713 kaisler 7581: $result = &html_encode($result);
7582: }
7583:
1.813 bisitz 7584: # Preparation for new and consistent functionlist at top of screen
7585: # if ($args->{'functionlist'}) {
7586: # $result .= &build_functionlist();
7587: #}
7588:
1.964 droeschl 7589: # Don't add anything more if only_body wanted or in const space
7590: return $result if $args->{'only_body'}
7591: || $env{'request.state'} eq 'construct';
1.813 bisitz 7592:
7593: #Breadcrumbs
1.758 kaisler 7594: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7595: &Apache::lonhtmlcommon::clear_breadcrumbs();
7596: #if any br links exists, add them to the breadcrumbs
7597: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7598: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7599: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7600: }
7601: }
1.1075.2.19 raeburn 7602: # if @advtools array contains items add then to the breadcrumbs
7603: if (@advtools > 0) {
7604: &Apache::lonmenu::advtools_crumbs(@advtools);
7605: }
1.758 kaisler 7606:
7607: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7608: if(exists($args->{'bread_crumbs_component'})){
7609: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7610: }else{
7611: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7612: }
1.1075.2.24 raeburn 7613: } elsif (($env{'environment.remote'} eq 'on') &&
7614: ($env{'form.inhibitmenu'} ne 'yes') &&
7615: ($env{'request.noversionuri'} =~ m{^/res/}) &&
7616: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 7617: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 7618: }
1.315 albertel 7619: return $result;
1.306 albertel 7620: }
7621:
7622: sub end_page {
1.315 albertel 7623: my ($args) = @_;
7624: $env{'internal.end_page'}++;
1.330 albertel 7625: my $result;
1.335 albertel 7626: if ($args->{'discussion'}) {
7627: my ($target,$parser);
7628: if (ref($args->{'discussion'})) {
7629: ($target,$parser) =($args->{'discussion'}{'target'},
7630: $args->{'discussion'}{'parser'});
7631: }
7632: $result .= &Apache::lonxml::xmlend($target,$parser);
7633: }
1.330 albertel 7634: if ($args->{'frameset'}) {
7635: $result .= '</frameset>';
7636: } else {
1.635 raeburn 7637: $result .= &endbodytag($args);
1.330 albertel 7638: }
1.1075.2.6 raeburn 7639: unless ($args->{'notbody'}) {
7640: $result .= "\n</html>";
7641: }
1.330 albertel 7642:
1.315 albertel 7643: if ($args->{'js_ready'}) {
1.317 albertel 7644: $result = &js_ready($result);
1.315 albertel 7645: }
1.335 albertel 7646:
1.320 albertel 7647: if ($args->{'html_encode'}) {
7648: $result = &html_encode($result);
7649: }
1.335 albertel 7650:
1.315 albertel 7651: return $result;
7652: }
7653:
1.1034 www 7654: sub wishlist_window {
7655: return(<<'ENDWISHLIST');
1.1046 raeburn 7656: <script type="text/javascript">
1.1034 www 7657: // <![CDATA[
7658: // <!-- BEGIN LON-CAPA Internal
7659: function set_wishlistlink(title, path) {
7660: if (!title) {
7661: title = document.title;
7662: title = title.replace(/^LON-CAPA /,'');
7663: }
1.1075.2.65 raeburn 7664: title = encodeURIComponent(title);
1.1034 www 7665: if (!path) {
7666: path = location.pathname;
7667: }
1.1075.2.65 raeburn 7668: path = encodeURIComponent(path);
1.1034 www 7669: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7670: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7671: }
7672: // END LON-CAPA Internal -->
7673: // ]]>
7674: </script>
7675: ENDWISHLIST
7676: }
7677:
1.1030 www 7678: sub modal_window {
7679: return(<<'ENDMODAL');
1.1046 raeburn 7680: <script type="text/javascript">
1.1030 www 7681: // <![CDATA[
7682: // <!-- BEGIN LON-CAPA Internal
7683: var modalWindow = {
7684: parent:"body",
7685: windowId:null,
7686: content:null,
7687: width:null,
7688: height:null,
7689: close:function()
7690: {
7691: $(".LCmodal-window").remove();
7692: $(".LCmodal-overlay").remove();
7693: },
7694: open:function()
7695: {
7696: var modal = "";
7697: modal += "<div class=\"LCmodal-overlay\"></div>";
7698: 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;\">";
7699: modal += this.content;
7700: modal += "</div>";
7701:
7702: $(this.parent).append(modal);
7703:
7704: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7705: $(".LCclose-window").click(function(){modalWindow.close();});
7706: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7707: }
7708: };
1.1075.2.42 raeburn 7709: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7710: {
7711: modalWindow.windowId = "myModal";
7712: modalWindow.width = width;
7713: modalWindow.height = height;
1.1075.2.42 raeburn 7714: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7715: modalWindow.open();
7716: };
7717: // END LON-CAPA Internal -->
7718: // ]]>
7719: </script>
7720: ENDMODAL
7721: }
7722:
7723: sub modal_link {
1.1075.2.42 raeburn 7724: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7725: unless ($width) { $width=480; }
7726: unless ($height) { $height=400; }
1.1031 www 7727: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 7728: unless ($transparency) { $transparency='true'; }
7729:
1.1074 raeburn 7730: my $target_attr;
7731: if (defined($target)) {
7732: $target_attr = 'target="'.$target.'"';
7733: }
7734: return <<"ENDLINK";
1.1075.2.42 raeburn 7735: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7736: $linktext</a>
7737: ENDLINK
1.1030 www 7738: }
7739:
1.1032 www 7740: sub modal_adhoc_script {
7741: my ($funcname,$width,$height,$content)=@_;
7742: return (<<ENDADHOC);
1.1046 raeburn 7743: <script type="text/javascript">
1.1032 www 7744: // <![CDATA[
7745: var $funcname = function()
7746: {
7747: modalWindow.windowId = "myModal";
7748: modalWindow.width = $width;
7749: modalWindow.height = $height;
7750: modalWindow.content = '$content';
7751: modalWindow.open();
7752: };
7753: // ]]>
7754: </script>
7755: ENDADHOC
7756: }
7757:
1.1041 www 7758: sub modal_adhoc_inner {
7759: my ($funcname,$width,$height,$content)=@_;
7760: my $innerwidth=$width-20;
7761: $content=&js_ready(
1.1042 www 7762: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 7763: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7764: $content.
1.1041 www 7765: &end_scrollbox().
1.1075.2.42 raeburn 7766: &end_page()
1.1041 www 7767: );
7768: return &modal_adhoc_script($funcname,$width,$height,$content);
7769: }
7770:
7771: sub modal_adhoc_window {
7772: my ($funcname,$width,$height,$content,$linktext)=@_;
7773: return &modal_adhoc_inner($funcname,$width,$height,$content).
7774: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7775: }
7776:
7777: sub modal_adhoc_launch {
7778: my ($funcname,$width,$height,$content)=@_;
7779: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7780: <script type="text/javascript">
7781: // <![CDATA[
7782: $funcname();
7783: // ]]>
7784: </script>
7785: ENDLAUNCH
7786: }
7787:
7788: sub modal_adhoc_close {
7789: return (<<ENDCLOSE);
7790: <script type="text/javascript">
7791: // <![CDATA[
7792: modalWindow.close();
7793: // ]]>
7794: </script>
7795: ENDCLOSE
7796: }
7797:
1.1038 www 7798: sub togglebox_script {
7799: return(<<ENDTOGGLE);
7800: <script type="text/javascript">
7801: // <![CDATA[
7802: function LCtoggleDisplay(id,hidetext,showtext) {
7803: link = document.getElementById(id + "link").childNodes[0];
7804: with (document.getElementById(id).style) {
7805: if (display == "none" ) {
7806: display = "inline";
7807: link.nodeValue = hidetext;
7808: } else {
7809: display = "none";
7810: link.nodeValue = showtext;
7811: }
7812: }
7813: }
7814: // ]]>
7815: </script>
7816: ENDTOGGLE
7817: }
7818:
1.1039 www 7819: sub start_togglebox {
7820: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7821: unless ($heading) { $heading=''; } else { $heading.=' '; }
7822: unless ($showtext) { $showtext=&mt('show'); }
7823: unless ($hidetext) { $hidetext=&mt('hide'); }
7824: unless ($headerbg) { $headerbg='#FFFFFF'; }
7825: return &start_data_table().
7826: &start_data_table_header_row().
7827: '<td bgcolor="'.$headerbg.'">'.$heading.
7828: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7829: $showtext.'\')">'.$showtext.'</a>]</td>'.
7830: &end_data_table_header_row().
7831: '<tr id="'.$id.'" style="display:none""><td>';
7832: }
7833:
7834: sub end_togglebox {
7835: return '</td></tr>'.&end_data_table();
7836: }
7837:
1.1041 www 7838: sub LCprogressbar_script {
1.1045 www 7839: my ($id)=@_;
1.1041 www 7840: return(<<ENDPROGRESS);
7841: <script type="text/javascript">
7842: // <![CDATA[
1.1045 www 7843: \$('#progressbar$id').progressbar({
1.1041 www 7844: value: 0,
7845: change: function(event, ui) {
7846: var newVal = \$(this).progressbar('option', 'value');
7847: \$('.pblabel', this).text(LCprogressTxt);
7848: }
7849: });
7850: // ]]>
7851: </script>
7852: ENDPROGRESS
7853: }
7854:
7855: sub LCprogressbarUpdate_script {
7856: return(<<ENDPROGRESSUPDATE);
7857: <style type="text/css">
7858: .ui-progressbar { position:relative; }
7859: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7860: </style>
7861: <script type="text/javascript">
7862: // <![CDATA[
1.1045 www 7863: var LCprogressTxt='---';
7864:
7865: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7866: LCprogressTxt=progresstext;
1.1045 www 7867: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7868: }
7869: // ]]>
7870: </script>
7871: ENDPROGRESSUPDATE
7872: }
7873:
1.1042 www 7874: my $LClastpercent;
1.1045 www 7875: my $LCidcnt;
7876: my $LCcurrentid;
1.1042 www 7877:
1.1041 www 7878: sub LCprogressbar {
1.1042 www 7879: my ($r)=(@_);
7880: $LClastpercent=0;
1.1045 www 7881: $LCidcnt++;
7882: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7883: my $starting=&mt('Starting');
7884: my $content=(<<ENDPROGBAR);
1.1045 www 7885: <div id="progressbar$LCcurrentid">
1.1041 www 7886: <span class="pblabel">$starting</span>
7887: </div>
7888: ENDPROGBAR
1.1045 www 7889: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7890: }
7891:
7892: sub LCprogressbarUpdate {
1.1042 www 7893: my ($r,$val,$text)=@_;
7894: unless ($val) {
7895: if ($LClastpercent) {
7896: $val=$LClastpercent;
7897: } else {
7898: $val=0;
7899: }
7900: }
1.1041 www 7901: if ($val<0) { $val=0; }
7902: if ($val>100) { $val=0; }
1.1042 www 7903: $LClastpercent=$val;
1.1041 www 7904: unless ($text) { $text=$val.'%'; }
7905: $text=&js_ready($text);
1.1044 www 7906: &r_print($r,<<ENDUPDATE);
1.1041 www 7907: <script type="text/javascript">
7908: // <![CDATA[
1.1045 www 7909: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7910: // ]]>
7911: </script>
7912: ENDUPDATE
1.1035 www 7913: }
7914:
1.1042 www 7915: sub LCprogressbarClose {
7916: my ($r)=@_;
7917: $LClastpercent=0;
1.1044 www 7918: &r_print($r,<<ENDCLOSE);
1.1042 www 7919: <script type="text/javascript">
7920: // <![CDATA[
1.1045 www 7921: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7922: // ]]>
7923: </script>
7924: ENDCLOSE
1.1044 www 7925: }
7926:
7927: sub r_print {
7928: my ($r,$to_print)=@_;
7929: if ($r) {
7930: $r->print($to_print);
7931: $r->rflush();
7932: } else {
7933: print($to_print);
7934: }
1.1042 www 7935: }
7936:
1.320 albertel 7937: sub html_encode {
7938: my ($result) = @_;
7939:
1.322 albertel 7940: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7941:
7942: return $result;
7943: }
1.1044 www 7944:
1.317 albertel 7945: sub js_ready {
7946: my ($result) = @_;
7947:
1.323 albertel 7948: $result =~ s/[\n\r]/ /xmsg;
7949: $result =~ s/\\/\\\\/xmsg;
7950: $result =~ s/'/\\'/xmsg;
1.372 albertel 7951: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7952:
7953: return $result;
7954: }
7955:
1.315 albertel 7956: sub validate_page {
7957: if ( exists($env{'internal.start_page'})
1.316 albertel 7958: && $env{'internal.start_page'} > 1) {
7959: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7960: $env{'internal.start_page'}.' '.
1.316 albertel 7961: $ENV{'request.filename'});
1.315 albertel 7962: }
7963: if ( exists($env{'internal.end_page'})
1.316 albertel 7964: && $env{'internal.end_page'} > 1) {
7965: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7966: $env{'internal.end_page'}.' '.
1.316 albertel 7967: $env{'request.filename'});
1.315 albertel 7968: }
7969: if ( exists($env{'internal.start_page'})
7970: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7971: &Apache::lonnet::logthis('start_page called without end_page '.
7972: $env{'request.filename'});
1.315 albertel 7973: }
7974: if ( ! exists($env{'internal.start_page'})
7975: && exists($env{'internal.end_page'})) {
1.316 albertel 7976: &Apache::lonnet::logthis('end_page called without start_page'.
7977: $env{'request.filename'});
1.315 albertel 7978: }
1.306 albertel 7979: }
1.315 albertel 7980:
1.996 www 7981:
7982: sub start_scrollbox {
1.1075.2.56 raeburn 7983: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 7984: unless ($outerwidth) { $outerwidth='520px'; }
7985: unless ($width) { $width='500px'; }
7986: unless ($height) { $height='200px'; }
1.1075 raeburn 7987: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7988: if ($id ne '') {
1.1075.2.42 raeburn 7989: $table_id = ' id="table_'.$id.'"';
7990: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 7991: }
1.1075 raeburn 7992: if ($bgcolor ne '') {
7993: $tdcol = "background-color: $bgcolor;";
7994: }
1.1075.2.42 raeburn 7995: my $nicescroll_js;
7996: if ($env{'browser.mobile'}) {
7997: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
7998: }
1.1075 raeburn 7999: return <<"END";
1.1075.2.42 raeburn 8000: $nicescroll_js
8001:
8002: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8003: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8004: END
1.996 www 8005: }
8006:
8007: sub end_scrollbox {
1.1036 www 8008: return '</div></td></tr></table>';
1.996 www 8009: }
8010:
1.1075.2.42 raeburn 8011: sub nicescroll_javascript {
8012: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8013: my %options;
8014: if (ref($cursor) eq 'HASH') {
8015: %options = %{$cursor};
8016: }
8017: unless ($options{'railalign'} =~ /^left|right$/) {
8018: $options{'railalign'} = 'left';
8019: }
8020: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8021: my $function = &get_users_function();
8022: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8023: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8024: $options{'cursorcolor'} = '#00F';
8025: }
8026: }
8027: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8028: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8029: $options{'cursoropacity'}='1.0';
8030: }
8031: } else {
8032: $options{'cursoropacity'}='1.0';
8033: }
8034: if ($options{'cursorfixedheight'} eq 'none') {
8035: delete($options{'cursorfixedheight'});
8036: } else {
8037: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8038: }
8039: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8040: delete($options{'railoffset'});
8041: }
8042: my @niceoptions;
8043: while (my($key,$value) = each(%options)) {
8044: if ($value =~ /^\{.+\}$/) {
8045: push(@niceoptions,$key.':'.$value);
8046: } else {
8047: push(@niceoptions,$key.':"'.$value.'"');
8048: }
8049: }
8050: my $nicescroll_js = '
8051: $(document).ready(
8052: function() {
8053: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8054: }
8055: );
8056: ';
8057: if ($framecheck) {
8058: $nicescroll_js .= '
8059: function expand_div(caller) {
8060: if (top === self) {
8061: document.getElementById("'.$id.'").style.width = "auto";
8062: document.getElementById("'.$id.'").style.height = "auto";
8063: } else {
8064: try {
8065: if (parent.frames) {
8066: if (parent.frames.length > 1) {
8067: var framesrc = parent.frames[1].location.href;
8068: var currsrc = framesrc.replace(/\#.*$/,"");
8069: if ((caller == "search") || (currsrc == "'.$location.'")) {
8070: document.getElementById("'.$id.'").style.width = "auto";
8071: document.getElementById("'.$id.'").style.height = "auto";
8072: }
8073: }
8074: }
8075: } catch (e) {
8076: return;
8077: }
8078: }
8079: return;
8080: }
8081: ';
8082: }
8083: if ($needjsready) {
8084: $nicescroll_js = '
8085: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8086: } else {
8087: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8088: }
8089: return $nicescroll_js;
8090: }
8091:
1.318 albertel 8092: sub simple_error_page {
1.1075.2.49 raeburn 8093: my ($r,$title,$msg,$args) = @_;
8094: if (ref($args) eq 'HASH') {
8095: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8096: } else {
8097: $msg = &mt($msg);
8098: }
8099:
1.318 albertel 8100: my $page =
8101: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8102: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8103: &Apache::loncommon::end_page();
8104: if (ref($r)) {
8105: $r->print($page);
1.327 albertel 8106: return;
1.318 albertel 8107: }
8108: return $page;
8109: }
1.347 albertel 8110:
8111: {
1.610 albertel 8112: my @row_count;
1.961 onken 8113:
8114: sub start_data_table_count {
8115: unshift(@row_count, 0);
8116: return;
8117: }
8118:
8119: sub end_data_table_count {
8120: shift(@row_count);
8121: return;
8122: }
8123:
1.347 albertel 8124: sub start_data_table {
1.1018 raeburn 8125: my ($add_class,$id) = @_;
1.422 albertel 8126: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8127: my $table_id;
8128: if (defined($id)) {
8129: $table_id = ' id="'.$id.'"';
8130: }
1.961 onken 8131: &start_data_table_count();
1.1018 raeburn 8132: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8133: }
8134:
8135: sub end_data_table {
1.961 onken 8136: &end_data_table_count();
1.389 albertel 8137: return '</table>'."\n";;
1.347 albertel 8138: }
8139:
8140: sub start_data_table_row {
1.974 wenzelju 8141: my ($add_class, $id) = @_;
1.610 albertel 8142: $row_count[0]++;
8143: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8144: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8145: $id = (' id="'.$id.'"') unless ($id eq '');
8146: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8147: }
1.471 banghart 8148:
8149: sub continue_data_table_row {
1.974 wenzelju 8150: my ($add_class, $id) = @_;
1.610 albertel 8151: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8152: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8153: $id = (' id="'.$id.'"') unless ($id eq '');
8154: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8155: }
1.347 albertel 8156:
8157: sub end_data_table_row {
1.389 albertel 8158: return '</tr>'."\n";;
1.347 albertel 8159: }
1.367 www 8160:
1.421 albertel 8161: sub start_data_table_empty_row {
1.707 bisitz 8162: # $row_count[0]++;
1.421 albertel 8163: return '<tr class="LC_empty_row" >'."\n";;
8164: }
8165:
8166: sub end_data_table_empty_row {
8167: return '</tr>'."\n";;
8168: }
8169:
1.367 www 8170: sub start_data_table_header_row {
1.389 albertel 8171: return '<tr class="LC_header_row">'."\n";;
1.367 www 8172: }
8173:
8174: sub end_data_table_header_row {
1.389 albertel 8175: return '</tr>'."\n";;
1.367 www 8176: }
1.890 droeschl 8177:
8178: sub data_table_caption {
8179: my $caption = shift;
8180: return "<caption class=\"LC_caption\">$caption</caption>";
8181: }
1.347 albertel 8182: }
8183:
1.548 albertel 8184: =pod
8185:
8186: =item * &inhibit_menu_check($arg)
8187:
8188: Checks for a inhibitmenu state and generates output to preserve it
8189:
8190: Inputs: $arg - can be any of
8191: - undef - in which case the return value is a string
8192: to add into arguments list of a uri
8193: - 'input' - in which case the return value is a HTML
8194: <form> <input> field of type hidden to
8195: preserve the value
8196: - a url - in which case the return value is the url with
8197: the neccesary cgi args added to preserve the
8198: inhibitmenu state
8199: - a ref to a url - no return value, but the string is
8200: updated to include the neccessary cgi
8201: args to preserve the inhibitmenu state
8202:
8203: =cut
8204:
8205: sub inhibit_menu_check {
8206: my ($arg) = @_;
8207: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8208: if ($arg eq 'input') {
8209: if ($env{'form.inhibitmenu'}) {
8210: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8211: } else {
8212: return
8213: }
8214: }
8215: if ($env{'form.inhibitmenu'}) {
8216: if (ref($arg)) {
8217: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8218: } elsif ($arg eq '') {
8219: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8220: } else {
8221: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8222: }
8223: }
8224: if (!ref($arg)) {
8225: return $arg;
8226: }
8227: }
8228:
1.251 albertel 8229: ###############################################
1.182 matthew 8230:
8231: =pod
8232:
1.549 albertel 8233: =back
8234:
8235: =head1 User Information Routines
8236:
8237: =over 4
8238:
1.405 albertel 8239: =item * &get_users_function()
1.182 matthew 8240:
8241: Used by &bodytag to determine the current users primary role.
8242: Returns either 'student','coordinator','admin', or 'author'.
8243:
8244: =cut
8245:
8246: ###############################################
8247: sub get_users_function {
1.815 tempelho 8248: my $function = 'norole';
1.818 tempelho 8249: if ($env{'request.role'}=~/^(st)/) {
8250: $function='student';
8251: }
1.907 raeburn 8252: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8253: $function='coordinator';
8254: }
1.258 albertel 8255: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8256: $function='admin';
8257: }
1.826 bisitz 8258: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8259: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8260: $function='author';
8261: }
8262: return $function;
1.54 www 8263: }
1.99 www 8264:
8265: ###############################################
8266:
1.233 raeburn 8267: =pod
8268:
1.821 raeburn 8269: =item * &show_course()
8270:
8271: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8272: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8273:
8274: Inputs:
8275: None
8276:
8277: Outputs:
8278: Scalar: 1 if 'Course' to be used, 0 otherwise.
8279:
8280: =cut
8281:
8282: ###############################################
8283: sub show_course {
8284: my $course = !$env{'user.adv'};
8285: if (!$env{'user.adv'}) {
8286: foreach my $env (keys(%env)) {
8287: next if ($env !~ m/^user\.priv\./);
8288: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8289: $course = 0;
8290: last;
8291: }
8292: }
8293: }
8294: return $course;
8295: }
8296:
8297: ###############################################
8298:
8299: =pod
8300:
1.542 raeburn 8301: =item * &check_user_status()
1.274 raeburn 8302:
8303: Determines current status of supplied role for a
8304: specific user. Roles can be active, previous or future.
8305:
8306: Inputs:
8307: user's domain, user's username, course's domain,
1.375 raeburn 8308: course's number, optional section ID.
1.274 raeburn 8309:
8310: Outputs:
8311: role status: active, previous or future.
8312:
8313: =cut
8314:
8315: sub check_user_status {
1.412 raeburn 8316: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8317: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8318: my @uroles = keys %userinfo;
8319: my $srchstr;
8320: my $active_chk = 'none';
1.412 raeburn 8321: my $now = time;
1.274 raeburn 8322: if (@uroles > 0) {
1.908 raeburn 8323: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8324: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8325: } else {
1.412 raeburn 8326: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8327: }
8328: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8329: my $role_end = 0;
8330: my $role_start = 0;
8331: $active_chk = 'active';
1.412 raeburn 8332: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8333: $role_end = $1;
8334: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8335: $role_start = $1;
1.274 raeburn 8336: }
8337: }
8338: if ($role_start > 0) {
1.412 raeburn 8339: if ($now < $role_start) {
1.274 raeburn 8340: $active_chk = 'future';
8341: }
8342: }
8343: if ($role_end > 0) {
1.412 raeburn 8344: if ($now > $role_end) {
1.274 raeburn 8345: $active_chk = 'previous';
8346: }
8347: }
8348: }
8349: }
8350: return $active_chk;
8351: }
8352:
8353: ###############################################
8354:
8355: =pod
8356:
1.405 albertel 8357: =item * &get_sections()
1.233 raeburn 8358:
8359: Determines all the sections for a course including
8360: sections with students and sections containing other roles.
1.419 raeburn 8361: Incoming parameters:
8362:
8363: 1. domain
8364: 2. course number
8365: 3. reference to array containing roles for which sections should
8366: be gathered (optional).
8367: 4. reference to array containing status types for which sections
8368: should be gathered (optional).
8369:
8370: If the third argument is undefined, sections are gathered for any role.
8371: If the fourth argument is undefined, sections are gathered for any status.
8372: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8373:
1.374 raeburn 8374: Returns section hash (keys are section IDs, values are
8375: number of users in each section), subject to the
1.419 raeburn 8376: optional roles filter, optional status filter
1.233 raeburn 8377:
8378: =cut
8379:
8380: ###############################################
8381: sub get_sections {
1.419 raeburn 8382: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8383: if (!defined($cdom) || !defined($cnum)) {
8384: my $cid = $env{'request.course.id'};
8385:
8386: return if (!defined($cid));
8387:
8388: $cdom = $env{'course.'.$cid.'.domain'};
8389: $cnum = $env{'course.'.$cid.'.num'};
8390: }
8391:
8392: my %sectioncount;
1.419 raeburn 8393: my $now = time;
1.240 albertel 8394:
1.1075.2.33 raeburn 8395: my $check_students = 1;
8396: my $only_students = 0;
8397: if (ref($possible_roles) eq 'ARRAY') {
8398: if (grep(/^st$/,@{$possible_roles})) {
8399: if (@{$possible_roles} == 1) {
8400: $only_students = 1;
8401: }
8402: } else {
8403: $check_students = 0;
8404: }
8405: }
8406:
8407: if ($check_students) {
1.276 albertel 8408: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8409: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8410: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8411: my $start_index = &Apache::loncoursedata::CL_START();
8412: my $end_index = &Apache::loncoursedata::CL_END();
8413: my $status;
1.366 albertel 8414: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8415: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8416: $data->[$status_index],
8417: $data->[$start_index],
8418: $data->[$end_index]);
8419: if ($stu_status eq 'Active') {
8420: $status = 'active';
8421: } elsif ($end < $now) {
8422: $status = 'previous';
8423: } elsif ($start > $now) {
8424: $status = 'future';
8425: }
8426: if ($section ne '-1' && $section !~ /^\s*$/) {
8427: if ((!defined($possible_status)) || (($status ne '') &&
8428: (grep/^\Q$status\E$/,@{$possible_status}))) {
8429: $sectioncount{$section}++;
8430: }
1.240 albertel 8431: }
8432: }
8433: }
1.1075.2.33 raeburn 8434: if ($only_students) {
8435: return %sectioncount;
8436: }
1.240 albertel 8437: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8438: foreach my $user (sort(keys(%courseroles))) {
8439: if ($user !~ /^(\w{2})/) { next; }
8440: my ($role) = ($user =~ /^(\w{2})/);
8441: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8442: my ($section,$status);
1.240 albertel 8443: if ($role eq 'cr' &&
8444: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8445: $section=$1;
8446: }
8447: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8448: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8449: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8450: if ($end == -1 && $start == -1) {
8451: next; #deleted role
8452: }
8453: if (!defined($possible_status)) {
8454: $sectioncount{$section}++;
8455: } else {
8456: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8457: $status = 'active';
8458: } elsif ($end < $now) {
8459: $status = 'future';
8460: } elsif ($start > $now) {
8461: $status = 'previous';
8462: }
8463: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8464: $sectioncount{$section}++;
8465: }
8466: }
1.233 raeburn 8467: }
1.366 albertel 8468: return %sectioncount;
1.233 raeburn 8469: }
8470:
1.274 raeburn 8471: ###############################################
1.294 raeburn 8472:
8473: =pod
1.405 albertel 8474:
8475: =item * &get_course_users()
8476:
1.275 raeburn 8477: Retrieves usernames:domains for users in the specified course
8478: with specific role(s), and access status.
8479:
8480: Incoming parameters:
1.277 albertel 8481: 1. course domain
8482: 2. course number
8483: 3. access status: users must have - either active,
1.275 raeburn 8484: previous, future, or all.
1.277 albertel 8485: 4. reference to array of permissible roles
1.288 raeburn 8486: 5. reference to array of section restrictions (optional)
8487: 6. reference to results object (hash of hashes).
8488: 7. reference to optional userdata hash
1.609 raeburn 8489: 8. reference to optional statushash
1.630 raeburn 8490: 9. flag if privileged users (except those set to unhide in
8491: course settings) should be excluded
1.609 raeburn 8492: Keys of top level results hash are roles.
1.275 raeburn 8493: Keys of inner hashes are username:domain, with
8494: values set to access type.
1.288 raeburn 8495: Optional userdata hash returns an array with arguments in the
8496: same order as loncoursedata::get_classlist() for student data.
8497:
1.609 raeburn 8498: Optional statushash returns
8499:
1.288 raeburn 8500: Entries for end, start, section and status are blank because
8501: of the possibility of multiple values for non-student roles.
8502:
1.275 raeburn 8503: =cut
1.405 albertel 8504:
1.275 raeburn 8505: ###############################################
1.405 albertel 8506:
1.275 raeburn 8507: sub get_course_users {
1.630 raeburn 8508: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8509: my %idx = ();
1.419 raeburn 8510: my %seclists;
1.288 raeburn 8511:
8512: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8513: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8514: $idx{end} = &Apache::loncoursedata::CL_END();
8515: $idx{start} = &Apache::loncoursedata::CL_START();
8516: $idx{id} = &Apache::loncoursedata::CL_ID();
8517: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8518: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8519: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8520:
1.290 albertel 8521: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8522: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8523: my $now = time;
1.277 albertel 8524: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8525: my $match = 0;
1.412 raeburn 8526: my $secmatch = 0;
1.419 raeburn 8527: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8528: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8529: if ($section eq '') {
8530: $section = 'none';
8531: }
1.291 albertel 8532: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8533: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8534: $secmatch = 1;
8535: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8536: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8537: $secmatch = 1;
8538: }
8539: } else {
1.419 raeburn 8540: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8541: $secmatch = 1;
8542: }
1.290 albertel 8543: }
1.412 raeburn 8544: if (!$secmatch) {
8545: next;
8546: }
1.419 raeburn 8547: }
1.275 raeburn 8548: if (defined($$types{'active'})) {
1.288 raeburn 8549: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8550: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8551: $match = 1;
1.275 raeburn 8552: }
8553: }
8554: if (defined($$types{'previous'})) {
1.609 raeburn 8555: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8556: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8557: $match = 1;
1.275 raeburn 8558: }
8559: }
8560: if (defined($$types{'future'})) {
1.609 raeburn 8561: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8562: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8563: $match = 1;
1.275 raeburn 8564: }
8565: }
1.609 raeburn 8566: if ($match) {
8567: push(@{$seclists{$student}},$section);
8568: if (ref($userdata) eq 'HASH') {
8569: $$userdata{$student} = $$classlist{$student};
8570: }
8571: if (ref($statushash) eq 'HASH') {
8572: $statushash->{$student}{'st'}{$section} = $status;
8573: }
1.288 raeburn 8574: }
1.275 raeburn 8575: }
8576: }
1.412 raeburn 8577: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8578: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8579: my $now = time;
1.609 raeburn 8580: my %displaystatus = ( previous => 'Expired',
8581: active => 'Active',
8582: future => 'Future',
8583: );
1.1075.2.36 raeburn 8584: my (%nothide,@possdoms);
1.630 raeburn 8585: if ($hidepriv) {
8586: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8587: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8588: if ($user !~ /:/) {
8589: $nothide{join(':',split(/[\@]/,$user))}=1;
8590: } else {
8591: $nothide{$user} = 1;
8592: }
8593: }
1.1075.2.36 raeburn 8594: my @possdoms = ($cdom);
8595: if ($coursehash{'checkforpriv'}) {
8596: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8597: }
1.630 raeburn 8598: }
1.439 raeburn 8599: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8600: my $match = 0;
1.412 raeburn 8601: my $secmatch = 0;
1.439 raeburn 8602: my $status;
1.412 raeburn 8603: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8604: $user =~ s/:$//;
1.439 raeburn 8605: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8606: if ($end == -1 || $start == -1) {
8607: next;
8608: }
8609: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8610: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8611: my ($uname,$udom) = split(/:/,$user);
8612: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8613: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8614: $secmatch = 1;
8615: } elsif ($usec eq '') {
1.420 albertel 8616: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8617: $secmatch = 1;
8618: }
8619: } else {
8620: if (grep(/^\Q$usec\E$/,@{$sections})) {
8621: $secmatch = 1;
8622: }
8623: }
8624: if (!$secmatch) {
8625: next;
8626: }
1.288 raeburn 8627: }
1.419 raeburn 8628: if ($usec eq '') {
8629: $usec = 'none';
8630: }
1.275 raeburn 8631: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8632: if ($hidepriv) {
1.1075.2.36 raeburn 8633: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8634: (!$nothide{$uname.':'.$udom})) {
8635: next;
8636: }
8637: }
1.503 raeburn 8638: if ($end > 0 && $end < $now) {
1.439 raeburn 8639: $status = 'previous';
8640: } elsif ($start > $now) {
8641: $status = 'future';
8642: } else {
8643: $status = 'active';
8644: }
1.277 albertel 8645: foreach my $type (keys(%{$types})) {
1.275 raeburn 8646: if ($status eq $type) {
1.420 albertel 8647: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8648: push(@{$$users{$role}{$user}},$type);
8649: }
1.288 raeburn 8650: $match = 1;
8651: }
8652: }
1.419 raeburn 8653: if (($match) && (ref($userdata) eq 'HASH')) {
8654: if (!exists($$userdata{$uname.':'.$udom})) {
8655: &get_user_info($udom,$uname,\%idx,$userdata);
8656: }
1.420 albertel 8657: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8658: push(@{$seclists{$uname.':'.$udom}},$usec);
8659: }
1.609 raeburn 8660: if (ref($statushash) eq 'HASH') {
8661: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8662: }
1.275 raeburn 8663: }
8664: }
8665: }
8666: }
1.290 albertel 8667: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8668: if ((defined($cdom)) && (defined($cnum))) {
8669: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8670: if ( defined($csettings{'internal.courseowner'}) ) {
8671: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8672: next if ($owner eq '');
8673: my ($ownername,$ownerdom);
8674: if ($owner =~ /^([^:]+):([^:]+)$/) {
8675: $ownername = $1;
8676: $ownerdom = $2;
8677: } else {
8678: $ownername = $owner;
8679: $ownerdom = $cdom;
8680: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8681: }
8682: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8683: if (defined($userdata) &&
1.609 raeburn 8684: !exists($$userdata{$owner})) {
8685: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8686: if (!grep(/^none$/,@{$seclists{$owner}})) {
8687: push(@{$seclists{$owner}},'none');
8688: }
8689: if (ref($statushash) eq 'HASH') {
8690: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8691: }
1.290 albertel 8692: }
1.279 raeburn 8693: }
8694: }
8695: }
1.419 raeburn 8696: foreach my $user (keys(%seclists)) {
8697: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8698: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8699: }
1.275 raeburn 8700: }
8701: return;
8702: }
8703:
1.288 raeburn 8704: sub get_user_info {
8705: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8706: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8707: &plainname($uname,$udom,'lastname');
1.291 albertel 8708: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8709: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8710: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8711: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8712: return;
8713: }
1.275 raeburn 8714:
1.472 raeburn 8715: ###############################################
8716:
8717: =pod
8718:
8719: =item * &get_user_quota()
8720:
1.1075.2.41 raeburn 8721: Retrieves quota assigned for storage of user files.
8722: Default is to report quota for portfolio files.
1.472 raeburn 8723:
8724: Incoming parameters:
8725: 1. user's username
8726: 2. user's domain
1.1075.2.41 raeburn 8727: 3. quota name - portfolio, author, or course
8728: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 8729: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 8730: course
1.472 raeburn 8731:
8732: Returns:
1.1075.2.58 raeburn 8733: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 8734: 2. (Optional) Type of setting: custom or default
8735: (individually assigned or default for user's
8736: institutional status).
8737: 3. (Optional) - User's institutional status (e.g., faculty, staff
8738: or student - types as defined in localenroll::inst_usertypes
8739: for user's domain, which determines default quota for user.
8740: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8741:
8742: If a value has been stored in the user's environment,
1.536 raeburn 8743: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 8744: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8745:
8746: =cut
8747:
8748: ###############################################
8749:
8750:
8751: sub get_user_quota {
1.1075.2.42 raeburn 8752: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8753: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8754: if (!defined($udom)) {
8755: $udom = $env{'user.domain'};
8756: }
8757: if (!defined($uname)) {
8758: $uname = $env{'user.name'};
8759: }
8760: if (($udom eq '' || $uname eq '') ||
8761: ($udom eq 'public') && ($uname eq 'public')) {
8762: $quota = 0;
1.536 raeburn 8763: $quotatype = 'default';
8764: $defquota = 0;
1.472 raeburn 8765: } else {
1.536 raeburn 8766: my $inststatus;
1.1075.2.41 raeburn 8767: if ($quotaname eq 'course') {
8768: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8769: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8770: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8771: } else {
8772: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8773: $quota = $cenv{'internal.uploadquota'};
8774: }
1.536 raeburn 8775: } else {
1.1075.2.41 raeburn 8776: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8777: if ($quotaname eq 'author') {
8778: $quota = $env{'environment.authorquota'};
8779: } else {
8780: $quota = $env{'environment.portfolioquota'};
8781: }
8782: $inststatus = $env{'environment.inststatus'};
8783: } else {
8784: my %userenv =
8785: &Apache::lonnet::get('environment',['portfolioquota',
8786: 'authorquota','inststatus'],$udom,$uname);
8787: my ($tmp) = keys(%userenv);
8788: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8789: if ($quotaname eq 'author') {
8790: $quota = $userenv{'authorquota'};
8791: } else {
8792: $quota = $userenv{'portfolioquota'};
8793: }
8794: $inststatus = $userenv{'inststatus'};
8795: } else {
8796: undef(%userenv);
8797: }
8798: }
8799: }
8800: if ($quota eq '' || wantarray) {
8801: if ($quotaname eq 'course') {
8802: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 8803: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
8804: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 8805: $defquota = $domdefs{$crstype.'quota'};
8806: }
8807: if ($defquota eq '') {
8808: $defquota = 500;
8809: }
1.1075.2.41 raeburn 8810: } else {
8811: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8812: }
8813: if ($quota eq '') {
8814: $quota = $defquota;
8815: $quotatype = 'default';
8816: } else {
8817: $quotatype = 'custom';
8818: }
1.472 raeburn 8819: }
8820: }
1.536 raeburn 8821: if (wantarray) {
8822: return ($quota,$quotatype,$settingstatus,$defquota);
8823: } else {
8824: return $quota;
8825: }
1.472 raeburn 8826: }
8827:
8828: ###############################################
8829:
8830: =pod
8831:
8832: =item * &default_quota()
8833:
1.536 raeburn 8834: Retrieves default quota assigned for storage of user portfolio files,
8835: given an (optional) user's institutional status.
1.472 raeburn 8836:
8837: Incoming parameters:
1.1075.2.42 raeburn 8838:
1.472 raeburn 8839: 1. domain
1.536 raeburn 8840: 2. (Optional) institutional status(es). This is a : separated list of
8841: status types (e.g., faculty, staff, student etc.)
8842: which apply to the user for whom the default is being retrieved.
8843: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 8844: default quota will be returned.
8845: 3. quota name - portfolio, author, or course
8846: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8847:
8848: Returns:
1.1075.2.42 raeburn 8849:
1.1075.2.58 raeburn 8850: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 8851: 2. (Optional) institutional type which determined the value of the
8852: default quota.
1.472 raeburn 8853:
8854: If a value has been stored in the domain's configuration db,
8855: it will return that, otherwise it returns 20 (for backwards
8856: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 8857: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 8858:
1.536 raeburn 8859: If the user's status includes multiple types (e.g., staff and student),
8860: the largest default quota which applies to the user determines the
8861: default quota returned.
8862:
1.472 raeburn 8863: =cut
8864:
8865: ###############################################
8866:
8867:
8868: sub default_quota {
1.1075.2.41 raeburn 8869: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8870: my ($defquota,$settingstatus);
8871: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8872: ['quotas'],$udom);
1.1075.2.41 raeburn 8873: my $key = 'defaultquota';
8874: if ($quotaname eq 'author') {
8875: $key = 'authorquota';
8876: }
1.622 raeburn 8877: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8878: if ($inststatus ne '') {
1.765 raeburn 8879: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8880: foreach my $item (@statuses) {
1.1075.2.41 raeburn 8881: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8882: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8883: if ($defquota eq '') {
1.1075.2.41 raeburn 8884: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8885: $settingstatus = $item;
1.1075.2.41 raeburn 8886: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8887: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8888: $settingstatus = $item;
8889: }
8890: }
1.1075.2.41 raeburn 8891: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8892: if ($quotahash{'quotas'}{$item} ne '') {
8893: if ($defquota eq '') {
8894: $defquota = $quotahash{'quotas'}{$item};
8895: $settingstatus = $item;
8896: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8897: $defquota = $quotahash{'quotas'}{$item};
8898: $settingstatus = $item;
8899: }
1.536 raeburn 8900: }
8901: }
8902: }
8903: }
8904: if ($defquota eq '') {
1.1075.2.41 raeburn 8905: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8906: $defquota = $quotahash{'quotas'}{$key}{'default'};
8907: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8908: $defquota = $quotahash{'quotas'}{'default'};
8909: }
1.536 raeburn 8910: $settingstatus = 'default';
1.1075.2.42 raeburn 8911: if ($defquota eq '') {
8912: if ($quotaname eq 'author') {
8913: $defquota = 500;
8914: }
8915: }
1.536 raeburn 8916: }
8917: } else {
8918: $settingstatus = 'default';
1.1075.2.41 raeburn 8919: if ($quotaname eq 'author') {
8920: $defquota = 500;
8921: } else {
8922: $defquota = 20;
8923: }
1.536 raeburn 8924: }
8925: if (wantarray) {
8926: return ($defquota,$settingstatus);
1.472 raeburn 8927: } else {
1.536 raeburn 8928: return $defquota;
1.472 raeburn 8929: }
8930: }
8931:
1.1075.2.41 raeburn 8932: ###############################################
8933:
8934: =pod
8935:
1.1075.2.42 raeburn 8936: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 8937:
8938: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 8939: of existing file within authoring space will cause quota for the authoring
8940: space to be exceeded.
8941:
8942: Same, if upload of a file directly to a course/community via Course Editor
8943: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 8944:
1.1075.2.61 raeburn 8945: Inputs: 7
1.1075.2.42 raeburn 8946: 1. username or coursenum
1.1075.2.41 raeburn 8947: 2. domain
1.1075.2.42 raeburn 8948: 3. context ('author' or 'course')
1.1075.2.41 raeburn 8949: 4. filename of file for which action is being requested
8950: 5. filesize (kB) of file
8951: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 8952: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 8953:
8954: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
8955: otherwise return null.
8956:
1.1075.2.42 raeburn 8957: =back
8958:
1.1075.2.41 raeburn 8959: =cut
8960:
1.1075.2.42 raeburn 8961: sub excess_filesize_warning {
1.1075.2.59 raeburn 8962: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 8963: my $current_disk_usage = 0;
1.1075.2.59 raeburn 8964: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 8965: if ($context eq 'author') {
8966: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8967: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8968: } else {
8969: foreach my $subdir ('docs','supplemental') {
8970: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8971: }
8972: }
1.1075.2.41 raeburn 8973: $disk_quota = int($disk_quota * 1000);
8974: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 8975: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 8976: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 8977: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
8978: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 8979: $disk_quota,$current_disk_usage).
8980: '</p>';
8981: }
8982: return;
8983: }
8984:
8985: ###############################################
8986:
8987:
1.384 raeburn 8988: sub get_secgrprole_info {
8989: my ($cdom,$cnum,$needroles,$type) = @_;
8990: my %sections_count = &get_sections($cdom,$cnum);
8991: my @sections = (sort {$a <=> $b} keys(%sections_count));
8992: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8993: my @groups = sort(keys(%curr_groups));
8994: my $allroles = [];
8995: my $rolehash;
8996: my $accesshash = {
8997: active => 'Currently has access',
8998: future => 'Will have future access',
8999: previous => 'Previously had access',
9000: };
9001: if ($needroles) {
9002: $rolehash = {'all' => 'all'};
1.385 albertel 9003: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9004: if (&Apache::lonnet::error(%user_roles)) {
9005: undef(%user_roles);
9006: }
9007: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9008: my ($role)=split(/\:/,$item,2);
9009: if ($role eq 'cr') { next; }
9010: if ($role =~ /^cr/) {
9011: $$rolehash{$role} = (split('/',$role))[3];
9012: } else {
9013: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9014: }
9015: }
9016: foreach my $key (sort(keys(%{$rolehash}))) {
9017: push(@{$allroles},$key);
9018: }
9019: push (@{$allroles},'st');
9020: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9021: }
9022: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9023: }
9024:
1.555 raeburn 9025: sub user_picker {
1.994 raeburn 9026: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9027: my $currdom = $dom;
9028: my %curr_selected = (
9029: srchin => 'dom',
1.580 raeburn 9030: srchby => 'lastname',
1.555 raeburn 9031: );
9032: my $srchterm;
1.625 raeburn 9033: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9034: if ($srch->{'srchby'} ne '') {
9035: $curr_selected{'srchby'} = $srch->{'srchby'};
9036: }
9037: if ($srch->{'srchin'} ne '') {
9038: $curr_selected{'srchin'} = $srch->{'srchin'};
9039: }
9040: if ($srch->{'srchtype'} ne '') {
9041: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9042: }
9043: if ($srch->{'srchdomain'} ne '') {
9044: $currdom = $srch->{'srchdomain'};
9045: }
9046: $srchterm = $srch->{'srchterm'};
9047: }
9048: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 9049: 'usr' => 'Search criteria',
1.563 raeburn 9050: 'doma' => 'Domain/institution to search',
1.558 albertel 9051: 'uname' => 'username',
9052: 'lastname' => 'last name',
1.555 raeburn 9053: 'lastfirst' => 'last name, first name',
1.558 albertel 9054: 'crs' => 'in this course',
1.576 raeburn 9055: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9056: 'alc' => 'all LON-CAPA',
1.573 raeburn 9057: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9058: 'exact' => 'is',
9059: 'contains' => 'contains',
1.569 raeburn 9060: 'begins' => 'begins with',
1.571 raeburn 9061: 'youm' => "You must include some text to search for.",
9062: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9063: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9064: 'yomc' => "You must choose a domain when using an institutional directory search.",
9065: 'ymcd' => "You must choose a domain when using a domain search.",
9066: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9067: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9068: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9069: );
1.563 raeburn 9070: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9071: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9072:
9073: my @srchins = ('crs','dom','alc','instd');
9074:
9075: foreach my $option (@srchins) {
9076: # FIXME 'alc' option unavailable until
9077: # loncreateuser::print_user_query_page()
9078: # has been completed.
9079: next if ($option eq 'alc');
1.880 raeburn 9080: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9081: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9082: if ($curr_selected{'srchin'} eq $option) {
9083: $srchinsel .= '
9084: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9085: } else {
9086: $srchinsel .= '
9087: <option value="'.$option.'">'.$lt{$option}.'</option>';
9088: }
1.555 raeburn 9089: }
1.563 raeburn 9090: $srchinsel .= "\n </select>\n";
1.555 raeburn 9091:
9092: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9093: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9094: if ($curr_selected{'srchby'} eq $option) {
9095: $srchbysel .= '
9096: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9097: } else {
9098: $srchbysel .= '
9099: <option value="'.$option.'">'.$lt{$option}.'</option>';
9100: }
9101: }
9102: $srchbysel .= "\n </select>\n";
9103:
9104: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9105: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9106: if ($curr_selected{'srchtype'} eq $option) {
9107: $srchtypesel .= '
9108: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9109: } else {
9110: $srchtypesel .= '
9111: <option value="'.$option.'">'.$lt{$option}.'</option>';
9112: }
9113: }
9114: $srchtypesel .= "\n </select>\n";
9115:
1.558 albertel 9116: my ($newuserscript,$new_user_create);
1.994 raeburn 9117: my $context_dom = $env{'request.role.domain'};
9118: if ($context eq 'requestcrs') {
9119: if ($env{'form.coursedom'} ne '') {
9120: $context_dom = $env{'form.coursedom'};
9121: }
9122: }
1.556 raeburn 9123: if ($forcenewuser) {
1.576 raeburn 9124: if (ref($srch) eq 'HASH') {
1.994 raeburn 9125: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9126: if ($cancreate) {
9127: $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>';
9128: } else {
1.799 bisitz 9129: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9130: my %usertypetext = (
9131: official => 'institutional',
9132: unofficial => 'non-institutional',
9133: );
1.799 bisitz 9134: $new_user_create = '<p class="LC_warning">'
9135: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9136: .' '
9137: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9138: ,'<a href="'.$helplink.'">','</a>')
9139: .'</p><br />';
1.627 raeburn 9140: }
1.576 raeburn 9141: }
9142: }
9143:
1.556 raeburn 9144: $newuserscript = <<"ENDSCRIPT";
9145:
1.570 raeburn 9146: function setSearch(createnew,callingForm) {
1.556 raeburn 9147: if (createnew == 1) {
1.570 raeburn 9148: for (var i=0; i<callingForm.srchby.length; i++) {
9149: if (callingForm.srchby.options[i].value == 'uname') {
9150: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9151: }
9152: }
1.570 raeburn 9153: for (var i=0; i<callingForm.srchin.length; i++) {
9154: if ( callingForm.srchin.options[i].value == 'dom') {
9155: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9156: }
9157: }
1.570 raeburn 9158: for (var i=0; i<callingForm.srchtype.length; i++) {
9159: if (callingForm.srchtype.options[i].value == 'exact') {
9160: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9161: }
9162: }
1.570 raeburn 9163: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9164: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9165: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9166: }
9167: }
9168: }
9169: }
9170: ENDSCRIPT
1.558 albertel 9171:
1.556 raeburn 9172: }
9173:
1.555 raeburn 9174: my $output = <<"END_BLOCK";
1.556 raeburn 9175: <script type="text/javascript">
1.824 bisitz 9176: // <![CDATA[
1.570 raeburn 9177: function validateEntry(callingForm) {
1.558 albertel 9178:
1.556 raeburn 9179: var checkok = 1;
1.558 albertel 9180: var srchin;
1.570 raeburn 9181: for (var i=0; i<callingForm.srchin.length; i++) {
9182: if ( callingForm.srchin[i].checked ) {
9183: srchin = callingForm.srchin[i].value;
1.558 albertel 9184: }
9185: }
9186:
1.570 raeburn 9187: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9188: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9189: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9190: var srchterm = callingForm.srchterm.value;
9191: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9192: var msg = "";
9193:
9194: if (srchterm == "") {
9195: checkok = 0;
1.571 raeburn 9196: msg += "$lt{'youm'}\\n";
1.556 raeburn 9197: }
9198:
1.569 raeburn 9199: if (srchtype== 'begins') {
9200: if (srchterm.length < 2) {
9201: checkok = 0;
1.571 raeburn 9202: msg += "$lt{'thte'}\\n";
1.569 raeburn 9203: }
9204: }
9205:
1.556 raeburn 9206: if (srchtype== 'contains') {
9207: if (srchterm.length < 3) {
9208: checkok = 0;
1.571 raeburn 9209: msg += "$lt{'thet'}\\n";
1.556 raeburn 9210: }
9211: }
9212: if (srchin == 'instd') {
9213: if (srchdomain == '') {
9214: checkok = 0;
1.571 raeburn 9215: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9216: }
9217: }
9218: if (srchin == 'dom') {
9219: if (srchdomain == '') {
9220: checkok = 0;
1.571 raeburn 9221: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9222: }
9223: }
9224: if (srchby == 'lastfirst') {
9225: if (srchterm.indexOf(",") == -1) {
9226: checkok = 0;
1.571 raeburn 9227: msg += "$lt{'whus'}\\n";
1.556 raeburn 9228: }
9229: if (srchterm.indexOf(",") == srchterm.length -1) {
9230: checkok = 0;
1.571 raeburn 9231: msg += "$lt{'whse'}\\n";
1.556 raeburn 9232: }
9233: }
9234: if (checkok == 0) {
1.571 raeburn 9235: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9236: return;
9237: }
9238: if (checkok == 1) {
1.570 raeburn 9239: callingForm.submit();
1.556 raeburn 9240: }
9241: }
9242:
9243: $newuserscript
9244:
1.824 bisitz 9245: // ]]>
1.556 raeburn 9246: </script>
1.558 albertel 9247:
9248: $new_user_create
9249:
1.555 raeburn 9250: END_BLOCK
1.558 albertel 9251:
1.876 raeburn 9252: $output .= &Apache::lonhtmlcommon::start_pick_box().
9253: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9254: $domform.
9255: &Apache::lonhtmlcommon::row_closure().
9256: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9257: $srchbysel.
9258: $srchtypesel.
9259: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9260: $srchinsel.
9261: &Apache::lonhtmlcommon::row_closure(1).
9262: &Apache::lonhtmlcommon::end_pick_box().
9263: '<br />';
1.555 raeburn 9264: return $output;
9265: }
9266:
1.612 raeburn 9267: sub user_rule_check {
1.615 raeburn 9268: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9269: my $response;
9270: if (ref($usershash) eq 'HASH') {
9271: foreach my $user (keys(%{$usershash})) {
9272: my ($uname,$udom) = split(/:/,$user);
9273: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9274: my ($id,$newuser);
1.612 raeburn 9275: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9276: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9277: $id = $usershash->{$user}->{'id'};
9278: }
9279: my $inst_response;
9280: if (ref($checks) eq 'HASH') {
9281: if (defined($checks->{'username'})) {
1.615 raeburn 9282: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9283: &Apache::lonnet::get_instuser($udom,$uname);
9284: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9285: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9286: &Apache::lonnet::get_instuser($udom,undef,$id);
9287: }
1.615 raeburn 9288: } else {
9289: ($inst_response,%{$inst_results->{$user}}) =
9290: &Apache::lonnet::get_instuser($udom,$uname);
9291: return;
1.612 raeburn 9292: }
1.615 raeburn 9293: if (!$got_rules->{$udom}) {
1.612 raeburn 9294: my %domconfig = &Apache::lonnet::get_dom('configuration',
9295: ['usercreation'],$udom);
9296: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9297: foreach my $item ('username','id') {
1.612 raeburn 9298: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9299: $$curr_rules{$udom}{$item} =
9300: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9301: }
9302: }
9303: }
1.615 raeburn 9304: $got_rules->{$udom} = 1;
1.585 raeburn 9305: }
1.612 raeburn 9306: foreach my $item (keys(%{$checks})) {
9307: if (ref($$curr_rules{$udom}) eq 'HASH') {
9308: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9309: if (@{$$curr_rules{$udom}{$item}} > 0) {
9310: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9311: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9312: if ($rule_check{$rule}) {
9313: $$rulematch{$user}{$item} = $rule;
9314: if ($inst_response eq 'ok') {
1.615 raeburn 9315: if (ref($inst_results) eq 'HASH') {
9316: if (ref($inst_results->{$user}) eq 'HASH') {
9317: if (keys(%{$inst_results->{$user}}) == 0) {
9318: $$alerts{$item}{$udom}{$uname} = 1;
9319: }
1.612 raeburn 9320: }
9321: }
1.615 raeburn 9322: }
9323: last;
1.585 raeburn 9324: }
9325: }
9326: }
9327: }
9328: }
9329: }
9330: }
9331: }
1.612 raeburn 9332: return;
9333: }
9334:
9335: sub user_rule_formats {
9336: my ($domain,$domdesc,$curr_rules,$check) = @_;
9337: my %text = (
9338: 'username' => 'Usernames',
9339: 'id' => 'IDs',
9340: );
9341: my $output;
9342: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9343: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9344: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 9345: $output = '<br />'.
9346: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9347: '<span class="LC_cusr_emph">','</span>',$domdesc).
9348: ' <ul>';
1.612 raeburn 9349: foreach my $rule (@{$ruleorder}) {
9350: if (ref($curr_rules) eq 'ARRAY') {
9351: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9352: if (ref($rules->{$rule}) eq 'HASH') {
9353: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9354: $rules->{$rule}{'desc'}.'</li>';
9355: }
9356: }
9357: }
9358: }
9359: $output .= '</ul>';
9360: }
9361: }
9362: return $output;
9363: }
9364:
9365: sub instrule_disallow_msg {
1.615 raeburn 9366: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9367: my $response;
9368: my %text = (
9369: item => 'username',
9370: items => 'usernames',
9371: match => 'matches',
9372: do => 'does',
9373: action => 'a username',
9374: one => 'one',
9375: );
9376: if ($count > 1) {
9377: $text{'item'} = 'usernames';
9378: $text{'match'} ='match';
9379: $text{'do'} = 'do';
9380: $text{'action'} = 'usernames',
9381: $text{'one'} = 'ones';
9382: }
9383: if ($checkitem eq 'id') {
9384: $text{'items'} = 'IDs';
9385: $text{'item'} = 'ID';
9386: $text{'action'} = 'an ID';
1.615 raeburn 9387: if ($count > 1) {
9388: $text{'item'} = 'IDs';
9389: $text{'action'} = 'IDs';
9390: }
1.612 raeburn 9391: }
1.674 bisitz 9392: $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 9393: if ($mode eq 'upload') {
9394: if ($checkitem eq 'username') {
9395: $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'}.");
9396: } elsif ($checkitem eq 'id') {
1.674 bisitz 9397: $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 9398: }
1.669 raeburn 9399: } elsif ($mode eq 'selfcreate') {
9400: if ($checkitem eq 'id') {
9401: $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.");
9402: }
1.615 raeburn 9403: } else {
9404: if ($checkitem eq 'username') {
9405: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9406: } elsif ($checkitem eq 'id') {
9407: $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.");
9408: }
1.612 raeburn 9409: }
9410: return $response;
1.585 raeburn 9411: }
9412:
1.624 raeburn 9413: sub personal_data_fieldtitles {
9414: my %fieldtitles = &Apache::lonlocal::texthash (
9415: id => 'Student/Employee ID',
9416: permanentemail => 'E-mail address',
9417: lastname => 'Last Name',
9418: firstname => 'First Name',
9419: middlename => 'Middle Name',
9420: generation => 'Generation',
9421: gen => 'Generation',
1.765 raeburn 9422: inststatus => 'Affiliation',
1.624 raeburn 9423: );
9424: return %fieldtitles;
9425: }
9426:
1.642 raeburn 9427: sub sorted_inst_types {
9428: my ($dom) = @_;
1.1075.2.70 raeburn 9429: my ($usertypes,$order);
9430: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9431: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
9432: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
9433: $order = $domdefaults{'inststatus'}{'inststatusorder'};
9434: } else {
9435: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9436: }
1.642 raeburn 9437: my $othertitle = &mt('All users');
9438: if ($env{'request.course.id'}) {
1.668 raeburn 9439: $othertitle = &mt('Any users');
1.642 raeburn 9440: }
9441: my @types;
9442: if (ref($order) eq 'ARRAY') {
9443: @types = @{$order};
9444: }
9445: if (@types == 0) {
9446: if (ref($usertypes) eq 'HASH') {
9447: @types = sort(keys(%{$usertypes}));
9448: }
9449: }
9450: if (keys(%{$usertypes}) > 0) {
9451: $othertitle = &mt('Other users');
9452: }
9453: return ($othertitle,$usertypes,\@types);
9454: }
9455:
1.645 raeburn 9456: sub get_institutional_codes {
9457: my ($settings,$allcourses,$LC_code) = @_;
9458: # Get complete list of course sections to update
9459: my @currsections = ();
9460: my @currxlists = ();
9461: my $coursecode = $$settings{'internal.coursecode'};
9462:
9463: if ($$settings{'internal.sectionnums'} ne '') {
9464: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9465: }
9466:
9467: if ($$settings{'internal.crosslistings'} ne '') {
9468: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9469: }
9470:
9471: if (@currxlists > 0) {
9472: foreach (@currxlists) {
9473: if (m/^([^:]+):(\w*)$/) {
9474: unless (grep/^$1$/,@{$allcourses}) {
9475: push @{$allcourses},$1;
9476: $$LC_code{$1} = $2;
9477: }
9478: }
9479: }
9480: }
9481:
9482: if (@currsections > 0) {
9483: foreach (@currsections) {
9484: if (m/^(\w+):(\w*)$/) {
9485: my $sec = $coursecode.$1;
9486: my $lc_sec = $2;
9487: unless (grep/^$sec$/,@{$allcourses}) {
9488: push @{$allcourses},$sec;
9489: $$LC_code{$sec} = $lc_sec;
9490: }
9491: }
9492: }
9493: }
9494: return;
9495: }
9496:
1.971 raeburn 9497: sub get_standard_codeitems {
9498: return ('Year','Semester','Department','Number','Section');
9499: }
9500:
1.112 bowersj2 9501: =pod
9502:
1.780 raeburn 9503: =head1 Slot Helpers
9504:
9505: =over 4
9506:
9507: =item * sorted_slots()
9508:
1.1040 raeburn 9509: Sorts an array of slot names in order of an optional sort key,
9510: default sort is by slot start time (earliest first).
1.780 raeburn 9511:
9512: Inputs:
9513:
9514: =over 4
9515:
9516: slotsarr - Reference to array of unsorted slot names.
9517:
9518: slots - Reference to hash of hash, where outer hash keys are slot names.
9519:
1.1040 raeburn 9520: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9521:
1.549 albertel 9522: =back
9523:
1.780 raeburn 9524: Returns:
9525:
9526: =over 4
9527:
1.1040 raeburn 9528: sorted - An array of slot names sorted by a specified sort key
9529: (default sort key is start time of the slot).
1.780 raeburn 9530:
9531: =back
9532:
9533: =cut
9534:
9535:
9536: sub sorted_slots {
1.1040 raeburn 9537: my ($slotsarr,$slots,$sortkey) = @_;
9538: if ($sortkey eq '') {
9539: $sortkey = 'starttime';
9540: }
1.780 raeburn 9541: my @sorted;
9542: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9543: @sorted =
9544: sort {
9545: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9546: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9547: }
9548: if (ref($slots->{$a})) { return -1;}
9549: if (ref($slots->{$b})) { return 1;}
9550: return 0;
9551: } @{$slotsarr};
9552: }
9553: return @sorted;
9554: }
9555:
1.1040 raeburn 9556: =pod
9557:
9558: =item * get_future_slots()
9559:
9560: Inputs:
9561:
9562: =over 4
9563:
9564: cnum - course number
9565:
9566: cdom - course domain
9567:
9568: now - current UNIX time
9569:
9570: symb - optional symb
9571:
9572: =back
9573:
9574: Returns:
9575:
9576: =over 4
9577:
9578: sorted_reservable - ref to array of student_schedulable slots currently
9579: reservable, ordered by end date of reservation period.
9580:
9581: reservable_now - ref to hash of student_schedulable slots currently
9582: reservable.
9583:
9584: Keys in inner hash are:
9585: (a) symb: either blank or symb to which slot use is restricted.
9586: (b) endreserve: end date of reservation period.
9587:
9588: sorted_future - ref to array of student_schedulable slots reservable in
9589: the future, ordered by start date of reservation period.
9590:
9591: future_reservable - ref to hash of student_schedulable slots reservable
9592: in the future.
9593:
9594: Keys in inner hash are:
9595: (a) symb: either blank or symb to which slot use is restricted.
9596: (b) startreserve: start date of reservation period.
9597:
9598: =back
9599:
9600: =cut
9601:
9602: sub get_future_slots {
9603: my ($cnum,$cdom,$now,$symb) = @_;
9604: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9605: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9606: foreach my $slot (keys(%slots)) {
9607: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9608: if ($symb) {
9609: next if (($slots{$slot}->{'symb'} ne '') &&
9610: ($slots{$slot}->{'symb'} ne $symb));
9611: }
9612: if (($slots{$slot}->{'starttime'} > $now) &&
9613: ($slots{$slot}->{'endtime'} > $now)) {
9614: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9615: my $userallowed = 0;
9616: if ($slots{$slot}->{'allowedsections'}) {
9617: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9618: if (!defined($env{'request.role.sec'})
9619: && grep(/^No section assigned$/,@allowed_sec)) {
9620: $userallowed=1;
9621: } else {
9622: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9623: $userallowed=1;
9624: }
9625: }
9626: unless ($userallowed) {
9627: if (defined($env{'request.course.groups'})) {
9628: my @groups = split(/:/,$env{'request.course.groups'});
9629: foreach my $group (@groups) {
9630: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9631: $userallowed=1;
9632: last;
9633: }
9634: }
9635: }
9636: }
9637: }
9638: if ($slots{$slot}->{'allowedusers'}) {
9639: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9640: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9641: if (grep(/^\Q$user\E$/,@allowed_users)) {
9642: $userallowed = 1;
9643: }
9644: }
9645: next unless($userallowed);
9646: }
9647: my $startreserve = $slots{$slot}->{'startreserve'};
9648: my $endreserve = $slots{$slot}->{'endreserve'};
9649: my $symb = $slots{$slot}->{'symb'};
9650: if (($startreserve < $now) &&
9651: (!$endreserve || $endreserve > $now)) {
9652: my $lastres = $endreserve;
9653: if (!$lastres) {
9654: $lastres = $slots{$slot}->{'starttime'};
9655: }
9656: $reservable_now{$slot} = {
9657: symb => $symb,
9658: endreserve => $lastres
9659: };
9660: } elsif (($startreserve > $now) &&
9661: (!$endreserve || $endreserve > $startreserve)) {
9662: $future_reservable{$slot} = {
9663: symb => $symb,
9664: startreserve => $startreserve
9665: };
9666: }
9667: }
9668: }
9669: my @unsorted_reservable = keys(%reservable_now);
9670: if (@unsorted_reservable > 0) {
9671: @sorted_reservable =
9672: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9673: }
9674: my @unsorted_future = keys(%future_reservable);
9675: if (@unsorted_future > 0) {
9676: @sorted_future =
9677: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9678: }
9679: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9680: }
1.780 raeburn 9681:
9682: =pod
9683:
1.1057 foxr 9684: =back
9685:
1.549 albertel 9686: =head1 HTTP Helpers
9687:
9688: =over 4
9689:
1.648 raeburn 9690: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9691:
1.258 albertel 9692: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9693: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9694: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9695:
9696: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9697: $possible_names is an ref to an array of form element names. As an example:
9698: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9699: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9700:
9701: =cut
1.1 albertel 9702:
1.6 albertel 9703: sub get_unprocessed_cgi {
1.25 albertel 9704: my ($query,$possible_names)= @_;
1.26 matthew 9705: # $Apache::lonxml::debug=1;
1.356 albertel 9706: foreach my $pair (split(/&/,$query)) {
9707: my ($name, $value) = split(/=/,$pair);
1.369 www 9708: $name = &unescape($name);
1.25 albertel 9709: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9710: $value =~ tr/+/ /;
9711: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9712: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9713: }
1.16 harris41 9714: }
1.6 albertel 9715: }
9716:
1.112 bowersj2 9717: =pod
9718:
1.648 raeburn 9719: =item * &cacheheader()
1.112 bowersj2 9720:
9721: returns cache-controlling header code
9722:
9723: =cut
9724:
1.7 albertel 9725: sub cacheheader {
1.258 albertel 9726: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9727: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9728: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9729: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9730: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9731: return $output;
1.7 albertel 9732: }
9733:
1.112 bowersj2 9734: =pod
9735:
1.648 raeburn 9736: =item * &no_cache($r)
1.112 bowersj2 9737:
9738: specifies header code to not have cache
9739:
9740: =cut
9741:
1.9 albertel 9742: sub no_cache {
1.216 albertel 9743: my ($r) = @_;
9744: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9745: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9746: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9747: $r->no_cache(1);
9748: $r->header_out("Expires" => $date);
9749: $r->header_out("Pragma" => "no-cache");
1.123 www 9750: }
9751:
9752: sub content_type {
1.181 albertel 9753: my ($r,$type,$charset) = @_;
1.299 foxr 9754: if ($r) {
9755: # Note that printout.pl calls this with undef for $r.
9756: &no_cache($r);
9757: }
1.258 albertel 9758: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9759: unless ($charset) {
9760: $charset=&Apache::lonlocal::current_encoding;
9761: }
9762: if ($charset) { $type.='; charset='.$charset; }
9763: if ($r) {
9764: $r->content_type($type);
9765: } else {
9766: print("Content-type: $type\n\n");
9767: }
1.9 albertel 9768: }
1.25 albertel 9769:
1.112 bowersj2 9770: =pod
9771:
1.648 raeburn 9772: =item * &add_to_env($name,$value)
1.112 bowersj2 9773:
1.258 albertel 9774: adds $name to the %env hash with value
1.112 bowersj2 9775: $value, if $name already exists, the entry is converted to an array
9776: reference and $value is added to the array.
9777:
9778: =cut
9779:
1.25 albertel 9780: sub add_to_env {
9781: my ($name,$value)=@_;
1.258 albertel 9782: if (defined($env{$name})) {
9783: if (ref($env{$name})) {
1.25 albertel 9784: #already have multiple values
1.258 albertel 9785: push(@{ $env{$name} },$value);
1.25 albertel 9786: } else {
9787: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9788: my $first=$env{$name};
9789: undef($env{$name});
9790: push(@{ $env{$name} },$first,$value);
1.25 albertel 9791: }
9792: } else {
1.258 albertel 9793: $env{$name}=$value;
1.25 albertel 9794: }
1.31 albertel 9795: }
1.149 albertel 9796:
9797: =pod
9798:
1.648 raeburn 9799: =item * &get_env_multiple($name)
1.149 albertel 9800:
1.258 albertel 9801: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9802: values may be defined and end up as an array ref.
9803:
9804: returns an array of values
9805:
9806: =cut
9807:
9808: sub get_env_multiple {
9809: my ($name) = @_;
9810: my @values;
1.258 albertel 9811: if (defined($env{$name})) {
1.149 albertel 9812: # exists is it an array
1.258 albertel 9813: if (ref($env{$name})) {
9814: @values=@{ $env{$name} };
1.149 albertel 9815: } else {
1.258 albertel 9816: $values[0]=$env{$name};
1.149 albertel 9817: }
9818: }
9819: return(@values);
9820: }
9821:
1.660 raeburn 9822: sub ask_for_embedded_content {
9823: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9824: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 9825: %currsubfile,%unused,$rem);
1.1071 raeburn 9826: my $counter = 0;
9827: my $numnew = 0;
1.987 raeburn 9828: my $numremref = 0;
9829: my $numinvalid = 0;
9830: my $numpathchg = 0;
9831: my $numexisting = 0;
1.1071 raeburn 9832: my $numunused = 0;
9833: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 9834: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 9835: my $heading = &mt('Upload embedded files');
9836: my $buttontext = &mt('Upload');
9837:
1.1075.2.11 raeburn 9838: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 9839: if ($actionurl eq '/adm/dependencies') {
9840: $navmap = Apache::lonnavmaps::navmap->new();
9841: }
9842: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9843: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 9844: }
1.1075.2.35 raeburn 9845: if (($actionurl eq '/adm/portfolio') ||
9846: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9847: my $current_path='/';
9848: if ($env{'form.currentpath'}) {
9849: $current_path = $env{'form.currentpath'};
9850: }
9851: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 9852: $udom = $cdom;
9853: $uname = $cnum;
1.984 raeburn 9854: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9855: } else {
9856: $udom = $env{'user.domain'};
9857: $uname = $env{'user.name'};
9858: $url = '/userfiles/portfolio';
9859: }
1.987 raeburn 9860: $toplevel = $url.'/';
1.984 raeburn 9861: $url .= $current_path;
9862: $getpropath = 1;
1.987 raeburn 9863: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9864: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9865: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9866: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9867: $toplevel = $url;
1.984 raeburn 9868: if ($rest ne '') {
1.987 raeburn 9869: $url .= $rest;
9870: }
9871: } elsif ($actionurl eq '/adm/coursedocs') {
9872: if (ref($args) eq 'HASH') {
1.1071 raeburn 9873: $url = $args->{'docs_url'};
9874: $toplevel = $url;
1.1075.2.11 raeburn 9875: if ($args->{'context'} eq 'paste') {
9876: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9877: ($path) =
9878: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9879: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9880: $fileloc =~ s{^/}{};
9881: }
1.1071 raeburn 9882: }
9883: } elsif ($actionurl eq '/adm/dependencies') {
9884: if ($env{'request.course.id'} ne '') {
9885: if (ref($args) eq 'HASH') {
9886: $url = $args->{'docs_url'};
9887: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 9888: $toplevel = $url;
9889: unless ($toplevel =~ m{^/}) {
9890: $toplevel = "/$url";
9891: }
1.1075.2.11 raeburn 9892: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 9893: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9894: $path = $1;
9895: } else {
9896: ($path) =
9897: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9898: }
1.1071 raeburn 9899: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9900: $fileloc =~ s{^/}{};
9901: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9902: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9903: }
1.987 raeburn 9904: }
1.1075.2.35 raeburn 9905: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9906: $udom = $cdom;
9907: $uname = $cnum;
9908: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9909: $toplevel = $url;
9910: $path = $url;
9911: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9912: $fileloc =~ s{^/}{};
9913: }
9914: foreach my $file (keys(%{$allfiles})) {
9915: my $embed_file;
9916: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9917: $embed_file = $1;
9918: } else {
9919: $embed_file = $file;
9920: }
1.1075.2.55 raeburn 9921: my ($absolutepath,$cleaned_file);
9922: if ($embed_file =~ m{^\w+://}) {
9923: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 9924: $newfiles{$cleaned_file} = 1;
9925: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9926: } else {
1.1075.2.55 raeburn 9927: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 9928: if ($embed_file =~ m{^/}) {
9929: $absolutepath = $embed_file;
9930: }
1.1075.2.47 raeburn 9931: if ($cleaned_file =~ m{/}) {
9932: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 9933: $path = &check_for_traversal($path,$url,$toplevel);
9934: my $item = $fname;
9935: if ($path ne '') {
9936: $item = $path.'/'.$fname;
9937: $subdependencies{$path}{$fname} = 1;
9938: } else {
9939: $dependencies{$item} = 1;
9940: }
9941: if ($absolutepath) {
9942: $mapping{$item} = $absolutepath;
9943: } else {
9944: $mapping{$item} = $embed_file;
9945: }
9946: } else {
9947: $dependencies{$embed_file} = 1;
9948: if ($absolutepath) {
1.1075.2.47 raeburn 9949: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 9950: } else {
1.1075.2.47 raeburn 9951: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9952: }
9953: }
1.984 raeburn 9954: }
9955: }
1.1071 raeburn 9956: my $dirptr = 16384;
1.984 raeburn 9957: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9958: $currsubfile{$path} = {};
1.1075.2.35 raeburn 9959: if (($actionurl eq '/adm/portfolio') ||
9960: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9961: my ($sublistref,$listerror) =
9962: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9963: if (ref($sublistref) eq 'ARRAY') {
9964: foreach my $line (@{$sublistref}) {
9965: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9966: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9967: }
1.984 raeburn 9968: }
1.987 raeburn 9969: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9970: if (opendir(my $dir,$url.'/'.$path)) {
9971: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9972: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9973: }
1.1075.2.11 raeburn 9974: } elsif (($actionurl eq '/adm/dependencies') ||
9975: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 9976: ($args->{'context'} eq 'paste')) ||
9977: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9978: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 9979: my $dir;
9980: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9981: $dir = $fileloc;
9982: } else {
9983: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9984: }
1.1071 raeburn 9985: if ($dir ne '') {
9986: my ($sublistref,$listerror) =
9987: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9988: if (ref($sublistref) eq 'ARRAY') {
9989: foreach my $line (@{$sublistref}) {
9990: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9991: undef,$mtime)=split(/\&/,$line,12);
9992: unless (($testdir&$dirptr) ||
9993: ($file_name =~ /^\.\.?$/)) {
9994: $currsubfile{$path}{$file_name} = [$size,$mtime];
9995: }
9996: }
9997: }
9998: }
1.984 raeburn 9999: }
10000: }
10001: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10002: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10003: my $item = $path.'/'.$file;
10004: unless ($mapping{$item} eq $item) {
10005: $pathchanges{$item} = 1;
10006: }
10007: $existing{$item} = 1;
10008: $numexisting ++;
10009: } else {
10010: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10011: }
10012: }
1.1071 raeburn 10013: if ($actionurl eq '/adm/dependencies') {
10014: foreach my $path (keys(%currsubfile)) {
10015: if (ref($currsubfile{$path}) eq 'HASH') {
10016: foreach my $file (keys(%{$currsubfile{$path}})) {
10017: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10018: next if (($rem ne '') &&
10019: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10020: (ref($navmap) &&
10021: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10022: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10023: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10024: $unused{$path.'/'.$file} = 1;
10025: }
10026: }
10027: }
10028: }
10029: }
1.984 raeburn 10030: }
1.987 raeburn 10031: my %currfile;
1.1075.2.35 raeburn 10032: if (($actionurl eq '/adm/portfolio') ||
10033: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10034: my ($dirlistref,$listerror) =
10035: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10036: if (ref($dirlistref) eq 'ARRAY') {
10037: foreach my $line (@{$dirlistref}) {
10038: my ($file_name,$rest) = split(/\&/,$line,2);
10039: $currfile{$file_name} = 1;
10040: }
1.984 raeburn 10041: }
1.987 raeburn 10042: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10043: if (opendir(my $dir,$url)) {
1.987 raeburn 10044: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10045: map {$currfile{$_} = 1;} @dir_list;
10046: }
1.1075.2.11 raeburn 10047: } elsif (($actionurl eq '/adm/dependencies') ||
10048: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10049: ($args->{'context'} eq 'paste')) ||
10050: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10051: if ($env{'request.course.id'} ne '') {
10052: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10053: if ($dir ne '') {
10054: my ($dirlistref,$listerror) =
10055: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10056: if (ref($dirlistref) eq 'ARRAY') {
10057: foreach my $line (@{$dirlistref}) {
10058: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10059: $size,undef,$mtime)=split(/\&/,$line,12);
10060: unless (($testdir&$dirptr) ||
10061: ($file_name =~ /^\.\.?$/)) {
10062: $currfile{$file_name} = [$size,$mtime];
10063: }
10064: }
10065: }
10066: }
10067: }
1.984 raeburn 10068: }
10069: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10070: if (exists($currfile{$file})) {
1.987 raeburn 10071: unless ($mapping{$file} eq $file) {
10072: $pathchanges{$file} = 1;
10073: }
10074: $existing{$file} = 1;
10075: $numexisting ++;
10076: } else {
1.984 raeburn 10077: $newfiles{$file} = 1;
10078: }
10079: }
1.1071 raeburn 10080: foreach my $file (keys(%currfile)) {
10081: unless (($file eq $filename) ||
10082: ($file eq $filename.'.bak') ||
10083: ($dependencies{$file})) {
1.1075.2.11 raeburn 10084: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10085: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10086: next if (($rem ne '') &&
10087: (($env{"httpref.$rem".$file} ne '') ||
10088: (ref($navmap) &&
10089: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10090: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10091: ($navmap->getResourceByUrl($rem.$1)))))));
10092: }
1.1075.2.11 raeburn 10093: }
1.1071 raeburn 10094: $unused{$file} = 1;
10095: }
10096: }
1.1075.2.11 raeburn 10097: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10098: ($args->{'context'} eq 'paste')) {
10099: $counter = scalar(keys(%existing));
10100: $numpathchg = scalar(keys(%pathchanges));
10101: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10102: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10103: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10104: $counter = scalar(keys(%existing));
10105: $numpathchg = scalar(keys(%pathchanges));
10106: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10107: }
1.984 raeburn 10108: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10109: if ($actionurl eq '/adm/dependencies') {
10110: next if ($embed_file =~ m{^\w+://});
10111: }
1.660 raeburn 10112: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10113: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10114: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10115: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10116: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10117: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10118: }
1.1075.2.35 raeburn 10119: $upload_output .= '</td>';
1.1071 raeburn 10120: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10121: $upload_output.='<td align="right">'.
10122: '<span class="LC_info LC_fontsize_medium">'.
10123: &mt("URL points to web address").'</span>';
1.987 raeburn 10124: $numremref++;
1.660 raeburn 10125: } elsif ($args->{'error_on_invalid_names'}
10126: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10127: $upload_output.='<td align="right"><span class="LC_warning">'.
10128: &mt('Invalid characters').'</span>';
1.987 raeburn 10129: $numinvalid++;
1.660 raeburn 10130: } else {
1.1075.2.35 raeburn 10131: $upload_output .= '<td>'.
10132: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10133: $embed_file,\%mapping,
1.1071 raeburn 10134: $allfiles,$codebase,'upload');
10135: $counter ++;
10136: $numnew ++;
1.987 raeburn 10137: }
10138: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10139: }
10140: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10141: if ($actionurl eq '/adm/dependencies') {
10142: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10143: $modify_output .= &start_data_table_row().
10144: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10145: '<img src="'.&icon($embed_file).'" border="0" />'.
10146: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10147: '<td>'.$size.'</td>'.
10148: '<td>'.$mtime.'</td>'.
10149: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10150: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10151: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10152: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10153: &embedded_file_element('upload_embedded',$counter,
10154: $embed_file,\%mapping,
10155: $allfiles,$codebase,'modify').
10156: '</div></td>'.
10157: &end_data_table_row()."\n";
10158: $counter ++;
10159: } else {
10160: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10161: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10162: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10163: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10164: &Apache::loncommon::end_data_table_row()."\n";
10165: }
10166: }
10167: my $delidx = $counter;
10168: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10169: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10170: $delete_output .= &start_data_table_row().
10171: '<td><img src="'.&icon($oldfile).'" />'.
10172: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10173: '<td>'.$size.'</td>'.
10174: '<td>'.$mtime.'</td>'.
10175: '<td><label><input type="checkbox" name="del_upload_dep" '.
10176: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10177: &embedded_file_element('upload_embedded',$delidx,
10178: $oldfile,\%mapping,$allfiles,
10179: $codebase,'delete').'</td>'.
10180: &end_data_table_row()."\n";
10181: $numunused ++;
10182: $delidx ++;
1.987 raeburn 10183: }
10184: if ($upload_output) {
10185: $upload_output = &start_data_table().
10186: $upload_output.
10187: &end_data_table()."\n";
10188: }
1.1071 raeburn 10189: if ($modify_output) {
10190: $modify_output = &start_data_table().
10191: &start_data_table_header_row().
10192: '<th>'.&mt('File').'</th>'.
10193: '<th>'.&mt('Size (KB)').'</th>'.
10194: '<th>'.&mt('Modified').'</th>'.
10195: '<th>'.&mt('Upload replacement?').'</th>'.
10196: &end_data_table_header_row().
10197: $modify_output.
10198: &end_data_table()."\n";
10199: }
10200: if ($delete_output) {
10201: $delete_output = &start_data_table().
10202: &start_data_table_header_row().
10203: '<th>'.&mt('File').'</th>'.
10204: '<th>'.&mt('Size (KB)').'</th>'.
10205: '<th>'.&mt('Modified').'</th>'.
10206: '<th>'.&mt('Delete?').'</th>'.
10207: &end_data_table_header_row().
10208: $delete_output.
10209: &end_data_table()."\n";
10210: }
1.987 raeburn 10211: my $applies = 0;
10212: if ($numremref) {
10213: $applies ++;
10214: }
10215: if ($numinvalid) {
10216: $applies ++;
10217: }
10218: if ($numexisting) {
10219: $applies ++;
10220: }
1.1071 raeburn 10221: if ($counter || $numunused) {
1.987 raeburn 10222: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10223: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10224: $state.'<h3>'.$heading.'</h3>';
10225: if ($actionurl eq '/adm/dependencies') {
10226: if ($numnew) {
10227: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10228: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10229: $upload_output.'<br />'."\n";
10230: }
10231: if ($numexisting) {
10232: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10233: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10234: $modify_output.'<br />'."\n";
10235: $buttontext = &mt('Save changes');
10236: }
10237: if ($numunused) {
10238: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10239: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10240: $delete_output.'<br />'."\n";
10241: $buttontext = &mt('Save changes');
10242: }
10243: } else {
10244: $output .= $upload_output.'<br />'."\n";
10245: }
10246: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10247: $counter.'" />'."\n";
10248: if ($actionurl eq '/adm/dependencies') {
10249: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10250: $numnew.'" />'."\n";
10251: } elsif ($actionurl eq '') {
1.987 raeburn 10252: $output .= '<input type="hidden" name="phase" value="three" />';
10253: }
10254: } elsif ($applies) {
10255: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10256: if ($applies > 1) {
10257: $output .=
1.1075.2.35 raeburn 10258: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10259: if ($numremref) {
10260: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10261: }
10262: if ($numinvalid) {
10263: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10264: }
10265: if ($numexisting) {
10266: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10267: }
10268: $output .= '</ul><br />';
10269: } elsif ($numremref) {
10270: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10271: } elsif ($numinvalid) {
10272: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10273: } elsif ($numexisting) {
10274: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10275: }
10276: $output .= $upload_output.'<br />';
10277: }
10278: my ($pathchange_output,$chgcount);
1.1071 raeburn 10279: $chgcount = $counter;
1.987 raeburn 10280: if (keys(%pathchanges) > 0) {
10281: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10282: if ($counter) {
1.987 raeburn 10283: $output .= &embedded_file_element('pathchange',$chgcount,
10284: $embed_file,\%mapping,
1.1071 raeburn 10285: $allfiles,$codebase,'change');
1.987 raeburn 10286: } else {
10287: $pathchange_output .=
10288: &start_data_table_row().
10289: '<td><input type ="checkbox" name="namechange" value="'.
10290: $chgcount.'" checked="checked" /></td>'.
10291: '<td>'.$mapping{$embed_file}.'</td>'.
10292: '<td>'.$embed_file.
10293: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10294: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10295: '</td>'.&end_data_table_row();
1.660 raeburn 10296: }
1.987 raeburn 10297: $numpathchg ++;
10298: $chgcount ++;
1.660 raeburn 10299: }
10300: }
1.1075.2.35 raeburn 10301: if (($counter) || ($numunused)) {
1.987 raeburn 10302: if ($numpathchg) {
10303: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10304: $numpathchg.'" />'."\n";
10305: }
10306: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10307: ($actionurl eq '/adm/imsimport')) {
10308: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10309: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10310: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10311: } elsif ($actionurl eq '/adm/dependencies') {
10312: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10313: }
1.1075.2.35 raeburn 10314: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10315: } elsif ($numpathchg) {
10316: my %pathchange = ();
10317: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10318: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10319: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 10320: }
1.987 raeburn 10321: }
1.1071 raeburn 10322: return ($output,$counter,$numpathchg);
1.987 raeburn 10323: }
10324:
1.1075.2.47 raeburn 10325: =pod
10326:
10327: =item * clean_path($name)
10328:
10329: Performs clean-up of directories, subdirectories and filename in an
10330: embedded object, referenced in an HTML file which is being uploaded
10331: to a course or portfolio, where
10332: "Upload embedded images/multimedia files if HTML file" checkbox was
10333: checked.
10334:
10335: Clean-up is similar to replacements in lonnet::clean_filename()
10336: except each / between sub-directory and next level is preserved.
10337:
10338: =cut
10339:
10340: sub clean_path {
10341: my ($embed_file) = @_;
10342: $embed_file =~s{^/+}{};
10343: my @contents;
10344: if ($embed_file =~ m{/}) {
10345: @contents = split(/\//,$embed_file);
10346: } else {
10347: @contents = ($embed_file);
10348: }
10349: my $lastidx = scalar(@contents)-1;
10350: for (my $i=0; $i<=$lastidx; $i++) {
10351: $contents[$i]=~s{\\}{/}g;
10352: $contents[$i]=~s/\s+/\_/g;
10353: $contents[$i]=~s{[^/\w\.\-]}{}g;
10354: if ($i == $lastidx) {
10355: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10356: }
10357: }
10358: if ($lastidx > 0) {
10359: return join('/',@contents);
10360: } else {
10361: return $contents[0];
10362: }
10363: }
10364:
1.987 raeburn 10365: sub embedded_file_element {
1.1071 raeburn 10366: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10367: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10368: (ref($codebase) eq 'HASH'));
10369: my $output;
1.1071 raeburn 10370: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10371: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10372: }
10373: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10374: &escape($embed_file).'" />';
10375: unless (($context eq 'upload_embedded') &&
10376: ($mapping->{$embed_file} eq $embed_file)) {
10377: $output .='
10378: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10379: }
10380: my $attrib;
10381: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10382: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10383: }
10384: $output .=
10385: "\n\t\t".
10386: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10387: $attrib.'" />';
10388: if (exists($codebase->{$mapping->{$embed_file}})) {
10389: $output .=
10390: "\n\t\t".
10391: '<input name="codebase_'.$num.'" type="hidden" value="'.
10392: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10393: }
1.987 raeburn 10394: return $output;
1.660 raeburn 10395: }
10396:
1.1071 raeburn 10397: sub get_dependency_details {
10398: my ($currfile,$currsubfile,$embed_file) = @_;
10399: my ($size,$mtime,$showsize,$showmtime);
10400: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10401: if ($embed_file =~ m{/}) {
10402: my ($path,$fname) = split(/\//,$embed_file);
10403: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10404: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10405: }
10406: } else {
10407: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10408: ($size,$mtime) = @{$currfile->{$embed_file}};
10409: }
10410: }
10411: $showsize = $size/1024.0;
10412: $showsize = sprintf("%.1f",$showsize);
10413: if ($mtime > 0) {
10414: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10415: }
10416: }
10417: return ($showsize,$showmtime);
10418: }
10419:
10420: sub ask_embedded_js {
10421: return <<"END";
10422: <script type="text/javascript"">
10423: // <![CDATA[
10424: function toggleBrowse(counter) {
10425: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10426: var fileid = document.getElementById('embedded_item_'+counter);
10427: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10428: if (chkboxid.checked == true) {
10429: uploaddivid.style.display='block';
10430: } else {
10431: uploaddivid.style.display='none';
10432: fileid.value = '';
10433: }
10434: }
10435: // ]]>
10436: </script>
10437:
10438: END
10439: }
10440:
1.661 raeburn 10441: sub upload_embedded {
10442: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10443: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10444: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10445: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10446: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10447: my $orig_uploaded_filename =
10448: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10449: foreach my $type ('orig','ref','attrib','codebase') {
10450: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10451: $env{'form.embedded_'.$type.'_'.$i} =
10452: &unescape($env{'form.embedded_'.$type.'_'.$i});
10453: }
10454: }
1.661 raeburn 10455: my ($path,$fname) =
10456: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10457: # no path, whole string is fname
10458: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10459: $fname = &Apache::lonnet::clean_filename($fname);
10460: # See if there is anything left
10461: next if ($fname eq '');
10462:
10463: # Check if file already exists as a file or directory.
10464: my ($state,$msg);
10465: if ($context eq 'portfolio') {
10466: my $port_path = $dirpath;
10467: if ($group ne '') {
10468: $port_path = "groups/$group/$port_path";
10469: }
1.987 raeburn 10470: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10471: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10472: $dir_root,$port_path,$disk_quota,
10473: $current_disk_usage,$uname,$udom);
10474: if ($state eq 'will_exceed_quota'
1.984 raeburn 10475: || $state eq 'file_locked') {
1.661 raeburn 10476: $output .= $msg;
10477: next;
10478: }
10479: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10480: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10481: if ($state eq 'exists') {
10482: $output .= $msg;
10483: next;
10484: }
10485: }
10486: # Check if extension is valid
10487: if (($fname =~ /\.(\w+)$/) &&
10488: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 10489: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10490: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10491: next;
10492: } elsif (($fname =~ /\.(\w+)$/) &&
10493: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10494: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10495: next;
10496: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 10497: $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 10498: next;
10499: }
10500: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 10501: my $subdir = $path;
10502: $subdir =~ s{/+$}{};
1.661 raeburn 10503: if ($context eq 'portfolio') {
1.984 raeburn 10504: my $result;
10505: if ($state eq 'existingfile') {
10506: $result=
10507: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 10508: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10509: } else {
1.984 raeburn 10510: $result=
10511: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10512: $dirpath.
1.1075.2.35 raeburn 10513: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10514: if ($result !~ m|^/uploaded/|) {
10515: $output .= '<span class="LC_error">'
10516: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10517: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10518: .'</span><br />';
10519: next;
10520: } else {
1.987 raeburn 10521: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10522: $path.$fname.'</span>').'<br />';
1.984 raeburn 10523: }
1.661 raeburn 10524: }
1.1075.2.35 raeburn 10525: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
10526: my $extendedsubdir = $dirpath.'/'.$subdir;
10527: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10528: my $result =
1.1075.2.35 raeburn 10529: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10530: if ($result !~ m|^/uploaded/|) {
10531: $output .= '<span class="LC_error">'
10532: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10533: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10534: .'</span><br />';
10535: next;
10536: } else {
10537: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10538: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 10539: if ($context eq 'syllabus') {
10540: &Apache::lonnet::make_public_indefinitely($result);
10541: }
1.987 raeburn 10542: }
1.661 raeburn 10543: } else {
10544: # Save the file
10545: my $target = $env{'form.embedded_item_'.$i};
10546: my $fullpath = $dir_root.$dirpath.'/'.$path;
10547: my $dest = $fullpath.$fname;
10548: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10549: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10550: my $count;
10551: my $filepath = $dir_root;
1.1027 raeburn 10552: foreach my $subdir (@parts) {
10553: $filepath .= "/$subdir";
10554: if (!-e $filepath) {
1.661 raeburn 10555: mkdir($filepath,0770);
10556: }
10557: }
10558: my $fh;
10559: if (!open($fh,'>'.$dest)) {
10560: &Apache::lonnet::logthis('Failed to create '.$dest);
10561: $output .= '<span class="LC_error">'.
1.1071 raeburn 10562: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10563: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10564: '</span><br />';
10565: } else {
10566: if (!print $fh $env{'form.embedded_item_'.$i}) {
10567: &Apache::lonnet::logthis('Failed to write to '.$dest);
10568: $output .= '<span class="LC_error">'.
1.1071 raeburn 10569: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10570: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10571: '</span><br />';
10572: } else {
1.987 raeburn 10573: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10574: $url.'</span>').'<br />';
10575: unless ($context eq 'testbank') {
10576: $footer .= &mt('View embedded file: [_1]',
10577: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10578: }
10579: }
10580: close($fh);
10581: }
10582: }
10583: if ($env{'form.embedded_ref_'.$i}) {
10584: $pathchange{$i} = 1;
10585: }
10586: }
10587: if ($output) {
10588: $output = '<p>'.$output.'</p>';
10589: }
10590: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10591: $returnflag = 'ok';
1.1071 raeburn 10592: my $numpathchgs = scalar(keys(%pathchange));
10593: if ($numpathchgs > 0) {
1.987 raeburn 10594: if ($context eq 'portfolio') {
10595: $output .= '<p>'.&mt('or').'</p>';
10596: } elsif ($context eq 'testbank') {
1.1071 raeburn 10597: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10598: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10599: $returnflag = 'modify_orightml';
10600: }
10601: }
1.1071 raeburn 10602: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10603: }
10604:
10605: sub modify_html_form {
10606: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10607: my $end = 0;
10608: my $modifyform;
10609: if ($context eq 'upload_embedded') {
10610: return unless (ref($pathchange) eq 'HASH');
10611: if ($env{'form.number_embedded_items'}) {
10612: $end += $env{'form.number_embedded_items'};
10613: }
10614: if ($env{'form.number_pathchange_items'}) {
10615: $end += $env{'form.number_pathchange_items'};
10616: }
10617: if ($end) {
10618: for (my $i=0; $i<$end; $i++) {
10619: if ($i < $env{'form.number_embedded_items'}) {
10620: next unless($pathchange->{$i});
10621: }
10622: $modifyform .=
10623: &start_data_table_row().
10624: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10625: 'checked="checked" /></td>'.
10626: '<td>'.$env{'form.embedded_ref_'.$i}.
10627: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10628: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10629: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10630: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10631: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10632: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10633: '<td>'.$env{'form.embedded_orig_'.$i}.
10634: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10635: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10636: &end_data_table_row();
1.1071 raeburn 10637: }
1.987 raeburn 10638: }
10639: } else {
10640: $modifyform = $pathchgtable;
10641: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10642: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10643: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10644: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10645: }
10646: }
10647: if ($modifyform) {
1.1071 raeburn 10648: if ($actionurl eq '/adm/dependencies') {
10649: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10650: }
1.987 raeburn 10651: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10652: '<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".
10653: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10654: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10655: '</ol></p>'."\n".'<p>'.
10656: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10657: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10658: &start_data_table()."\n".
10659: &start_data_table_header_row().
10660: '<th>'.&mt('Change?').'</th>'.
10661: '<th>'.&mt('Current reference').'</th>'.
10662: '<th>'.&mt('Required reference').'</th>'.
10663: &end_data_table_header_row()."\n".
10664: $modifyform.
10665: &end_data_table().'<br />'."\n".$hiddenstate.
10666: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10667: '</form>'."\n";
10668: }
10669: return;
10670: }
10671:
10672: sub modify_html_refs {
1.1075.2.35 raeburn 10673: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10674: my $container;
10675: if ($context eq 'portfolio') {
10676: $container = $env{'form.container'};
10677: } elsif ($context eq 'coursedoc') {
10678: $container = $env{'form.primaryurl'};
1.1071 raeburn 10679: } elsif ($context eq 'manage_dependencies') {
10680: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10681: $container = "/$container";
1.1075.2.35 raeburn 10682: } elsif ($context eq 'syllabus') {
10683: $container = $url;
1.987 raeburn 10684: } else {
1.1027 raeburn 10685: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10686: }
10687: my (%allfiles,%codebase,$output,$content);
10688: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 10689: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10690: if (wantarray) {
10691: return ('',0,0);
10692: } else {
10693: return;
10694: }
10695: }
10696: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10697: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10698: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10699: if (wantarray) {
10700: return ('',0,0);
10701: } else {
10702: return;
10703: }
10704: }
1.987 raeburn 10705: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10706: if ($content eq '-1') {
10707: if (wantarray) {
10708: return ('',0,0);
10709: } else {
10710: return;
10711: }
10712: }
1.987 raeburn 10713: } else {
1.1071 raeburn 10714: unless ($container =~ /^\Q$dir_root\E/) {
10715: if (wantarray) {
10716: return ('',0,0);
10717: } else {
10718: return;
10719: }
10720: }
1.987 raeburn 10721: if (open(my $fh,"<$container")) {
10722: $content = join('', <$fh>);
10723: close($fh);
10724: } else {
1.1071 raeburn 10725: if (wantarray) {
10726: return ('',0,0);
10727: } else {
10728: return;
10729: }
1.987 raeburn 10730: }
10731: }
10732: my ($count,$codebasecount) = (0,0);
10733: my $mm = new File::MMagic;
10734: my $mime_type = $mm->checktype_contents($content);
10735: if ($mime_type eq 'text/html') {
10736: my $parse_result =
10737: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10738: \%codebase,\$content);
10739: if ($parse_result eq 'ok') {
10740: foreach my $i (@changes) {
10741: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10742: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10743: if ($allfiles{$ref}) {
10744: my $newname = $orig;
10745: my ($attrib_regexp,$codebase);
1.1006 raeburn 10746: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10747: if ($attrib_regexp =~ /:/) {
10748: $attrib_regexp =~ s/\:/|/g;
10749: }
10750: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10751: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10752: $count += $numchg;
1.1075.2.35 raeburn 10753: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 10754: delete($allfiles{$ref});
1.987 raeburn 10755: }
10756: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10757: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10758: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10759: $codebasecount ++;
10760: }
10761: }
10762: }
1.1075.2.35 raeburn 10763: my $skiprewrites;
1.987 raeburn 10764: if ($count || $codebasecount) {
10765: my $saveresult;
1.1071 raeburn 10766: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10767: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10768: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10769: if ($url eq $container) {
10770: my ($fname) = ($container =~ m{/([^/]+)$});
10771: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10772: $count,'<span class="LC_filename">'.
1.1071 raeburn 10773: $fname.'</span>').'</p>';
1.987 raeburn 10774: } else {
10775: $output = '<p class="LC_error">'.
10776: &mt('Error: update failed for: [_1].',
10777: '<span class="LC_filename">'.
10778: $container.'</span>').'</p>';
10779: }
1.1075.2.35 raeburn 10780: if ($context eq 'syllabus') {
10781: unless ($saveresult eq 'ok') {
10782: $skiprewrites = 1;
10783: }
10784: }
1.987 raeburn 10785: } else {
10786: if (open(my $fh,">$container")) {
10787: print $fh $content;
10788: close($fh);
10789: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10790: $count,'<span class="LC_filename">'.
10791: $container.'</span>').'</p>';
1.661 raeburn 10792: } else {
1.987 raeburn 10793: $output = '<p class="LC_error">'.
10794: &mt('Error: could not update [_1].',
10795: '<span class="LC_filename">'.
10796: $container.'</span>').'</p>';
1.661 raeburn 10797: }
10798: }
10799: }
1.1075.2.35 raeburn 10800: if (($context eq 'syllabus') && (!$skiprewrites)) {
10801: my ($actionurl,$state);
10802: $actionurl = "/public/$udom/$uname/syllabus";
10803: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10804: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10805: \%codebase,
10806: {'context' => 'rewrites',
10807: 'ignore_remote_references' => 1,});
10808: if (ref($mapping) eq 'HASH') {
10809: my $rewrites = 0;
10810: foreach my $key (keys(%{$mapping})) {
10811: next if ($key =~ m{^https?://});
10812: my $ref = $mapping->{$key};
10813: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10814: my $attrib;
10815: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10816: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10817: }
10818: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10819: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10820: $rewrites += $numchg;
10821: }
10822: }
10823: if ($rewrites) {
10824: my $saveresult;
10825: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10826: if ($url eq $container) {
10827: my ($fname) = ($container =~ m{/([^/]+)$});
10828: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10829: $count,'<span class="LC_filename">'.
10830: $fname.'</span>').'</p>';
10831: } else {
10832: $output .= '<p class="LC_error">'.
10833: &mt('Error: could not update links in [_1].',
10834: '<span class="LC_filename">'.
10835: $container.'</span>').'</p>';
10836:
10837: }
10838: }
10839: }
10840: }
1.987 raeburn 10841: } else {
10842: &logthis('Failed to parse '.$container.
10843: ' to modify references: '.$parse_result);
1.661 raeburn 10844: }
10845: }
1.1071 raeburn 10846: if (wantarray) {
10847: return ($output,$count,$codebasecount);
10848: } else {
10849: return $output;
10850: }
1.661 raeburn 10851: }
10852:
10853: sub check_for_existing {
10854: my ($path,$fname,$element) = @_;
10855: my ($state,$msg);
10856: if (-d $path.'/'.$fname) {
10857: $state = 'exists';
10858: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10859: } elsif (-e $path.'/'.$fname) {
10860: $state = 'exists';
10861: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10862: }
10863: if ($state eq 'exists') {
10864: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10865: }
10866: return ($state,$msg);
10867: }
10868:
10869: sub check_for_upload {
10870: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10871: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10872: my $filesize = length($env{'form.'.$element});
10873: if (!$filesize) {
10874: my $msg = '<span class="LC_error">'.
10875: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10876: '<span class="LC_filename">'.$fname.'</span>',
10877: $filesize).'<br />'.
1.1007 raeburn 10878: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10879: '</span>';
10880: return ('zero_bytes',$msg);
10881: }
10882: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10883: my $getpropath = 1;
1.1021 raeburn 10884: my ($dirlistref,$listerror) =
10885: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10886: my $found_file = 0;
10887: my $locked_file = 0;
1.991 raeburn 10888: my @lockers;
10889: my $navmap;
10890: if ($env{'request.course.id'}) {
10891: $navmap = Apache::lonnavmaps::navmap->new();
10892: }
1.1021 raeburn 10893: if (ref($dirlistref) eq 'ARRAY') {
10894: foreach my $line (@{$dirlistref}) {
10895: my ($file_name,$rest)=split(/\&/,$line,2);
10896: if ($file_name eq $fname){
10897: $file_name = $path.$file_name;
10898: if ($group ne '') {
10899: $file_name = $group.$file_name;
10900: }
10901: $found_file = 1;
10902: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10903: foreach my $lock (@lockers) {
10904: if (ref($lock) eq 'ARRAY') {
10905: my ($symb,$crsid) = @{$lock};
10906: if ($crsid eq $env{'request.course.id'}) {
10907: if (ref($navmap)) {
10908: my $res = $navmap->getBySymb($symb);
10909: foreach my $part (@{$res->parts()}) {
10910: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10911: unless (($slot_status == $res->RESERVED) ||
10912: ($slot_status == $res->RESERVED_LOCATION)) {
10913: $locked_file = 1;
10914: }
1.991 raeburn 10915: }
1.1021 raeburn 10916: } else {
10917: $locked_file = 1;
1.991 raeburn 10918: }
10919: } else {
10920: $locked_file = 1;
10921: }
10922: }
1.1021 raeburn 10923: }
10924: } else {
10925: my @info = split(/\&/,$rest);
10926: my $currsize = $info[6]/1000;
10927: if ($currsize < $filesize) {
10928: my $extra = $filesize - $currsize;
10929: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 10930: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 10931: &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 10932: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
10933: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10934: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 10935: return ('will_exceed_quota',$msg);
10936: }
1.984 raeburn 10937: }
10938: }
1.661 raeburn 10939: }
10940: }
10941: }
10942: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 10943: my $msg = '<p class="LC_warning">'.
10944: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
10945: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 10946: return ('will_exceed_quota',$msg);
10947: } elsif ($found_file) {
10948: if ($locked_file) {
1.1075.2.69 raeburn 10949: my $msg = '<p class="LC_warning">';
1.661 raeburn 10950: $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 10951: $msg .= '</p>';
1.661 raeburn 10952: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10953: return ('file_locked',$msg);
10954: } else {
1.1075.2.69 raeburn 10955: my $msg = '<p class="LC_error">';
1.984 raeburn 10956: $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 10957: $msg .= '</p>';
1.984 raeburn 10958: return ('existingfile',$msg);
1.661 raeburn 10959: }
10960: }
10961: }
10962:
1.987 raeburn 10963: sub check_for_traversal {
10964: my ($path,$url,$toplevel) = @_;
10965: my @parts=split(/\//,$path);
10966: my $cleanpath;
10967: my $fullpath = $url;
10968: for (my $i=0;$i<@parts;$i++) {
10969: next if ($parts[$i] eq '.');
10970: if ($parts[$i] eq '..') {
10971: $fullpath =~ s{([^/]+/)$}{};
10972: } else {
10973: $fullpath .= $parts[$i].'/';
10974: }
10975: }
10976: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10977: $cleanpath = $1;
10978: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10979: my $curr_toprel = $1;
10980: my @parts = split(/\//,$curr_toprel);
10981: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10982: my @urlparts = split(/\//,$url_toprel);
10983: my $doubledots;
10984: my $startdiff = -1;
10985: for (my $i=0; $i<@urlparts; $i++) {
10986: if ($startdiff == -1) {
10987: unless ($urlparts[$i] eq $parts[$i]) {
10988: $startdiff = $i;
10989: $doubledots .= '../';
10990: }
10991: } else {
10992: $doubledots .= '../';
10993: }
10994: }
10995: if ($startdiff > -1) {
10996: $cleanpath = $doubledots;
10997: for (my $i=$startdiff; $i<@parts; $i++) {
10998: $cleanpath .= $parts[$i].'/';
10999: }
11000: }
11001: }
11002: $cleanpath =~ s{(/)$}{};
11003: return $cleanpath;
11004: }
1.31 albertel 11005:
1.1053 raeburn 11006: sub is_archive_file {
11007: my ($mimetype) = @_;
11008: if (($mimetype eq 'application/octet-stream') ||
11009: ($mimetype eq 'application/x-stuffit') ||
11010: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11011: return 1;
11012: }
11013: return;
11014: }
11015:
11016: sub decompress_form {
1.1065 raeburn 11017: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11018: my %lt = &Apache::lonlocal::texthash (
11019: this => 'This file is an archive file.',
1.1067 raeburn 11020: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11021: itsc => 'Its contents are as follows:',
1.1053 raeburn 11022: youm => 'You may wish to extract its contents.',
11023: extr => 'Extract contents',
1.1067 raeburn 11024: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11025: proa => 'Process automatically?',
1.1053 raeburn 11026: yes => 'Yes',
11027: no => 'No',
1.1067 raeburn 11028: fold => 'Title for folder containing movie',
11029: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11030: );
1.1065 raeburn 11031: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11032: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11033: my $info = &list_archive_contents($fileloc,\@paths);
11034: if (@paths) {
11035: foreach my $path (@paths) {
11036: $path =~ s{^/}{};
1.1067 raeburn 11037: if ($path =~ m{^([^/]+)/$}) {
11038: $topdir = $1;
11039: }
1.1065 raeburn 11040: if ($path =~ m{^([^/]+)/}) {
11041: $toplevel{$1} = $path;
11042: } else {
11043: $toplevel{$path} = $path;
11044: }
11045: }
11046: }
1.1067 raeburn 11047: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11048: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11049: "$topdir/media/",
11050: "$topdir/media/$topdir.mp4",
11051: "$topdir/media/FirstFrame.png",
11052: "$topdir/media/player.swf",
11053: "$topdir/media/swfobject.js",
11054: "$topdir/media/expressInstall.swf");
1.1075.2.59 raeburn 11055: my @camtasia8 = ("$topdir/","$topdir/$topdir.html",
11056: "$topdir/$topdir.mp4",
11057: "$topdir/$topdir\_config.xml",
11058: "$topdir/$topdir\_controller.swf",
11059: "$topdir/$topdir\_embed.css",
11060: "$topdir/$topdir\_First_Frame.png",
11061: "$topdir/$topdir\_player.html",
11062: "$topdir/$topdir\_Thumbnails.png",
11063: "$topdir/playerProductInstall.swf",
11064: "$topdir/scripts/",
11065: "$topdir/scripts/config_xml.js",
11066: "$topdir/scripts/handlebars.js",
11067: "$topdir/scripts/jquery-1.7.1.min.js",
11068: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11069: "$topdir/scripts/modernizr.js",
11070: "$topdir/scripts/player-min.js",
11071: "$topdir/scripts/swfobject.js",
11072: "$topdir/skins/",
11073: "$topdir/skins/configuration_express.xml",
11074: "$topdir/skins/express_show/",
11075: "$topdir/skins/express_show/player-min.css",
11076: "$topdir/skins/express_show/spritesheet.png");
11077: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11078: if (@diffs == 0) {
1.1075.2.59 raeburn 11079: $is_camtasia = 6;
11080: } else {
11081: @diffs = &compare_arrays(\@paths,\@camtasia8);
11082: if (@diffs == 0) {
11083: $is_camtasia = 8;
11084: }
1.1067 raeburn 11085: }
11086: }
11087: my $output;
11088: if ($is_camtasia) {
11089: $output = <<"ENDCAM";
11090: <script type="text/javascript" language="Javascript">
11091: // <![CDATA[
11092:
11093: function camtasiaToggle() {
11094: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11095: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11096: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11097: document.getElementById('camtasia_titles').style.display='block';
11098: } else {
11099: document.getElementById('camtasia_titles').style.display='none';
11100: }
11101: }
11102: }
11103: return;
11104: }
11105:
11106: // ]]>
11107: </script>
11108: <p>$lt{'camt'}</p>
11109: ENDCAM
1.1065 raeburn 11110: } else {
1.1067 raeburn 11111: $output = '<p>'.$lt{'this'};
11112: if ($info eq '') {
11113: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11114: } else {
11115: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11116: '<div><pre>'.$info.'</pre></div>';
11117: }
1.1065 raeburn 11118: }
1.1067 raeburn 11119: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11120: my $duplicates;
11121: my $num = 0;
11122: if (ref($dirlist) eq 'ARRAY') {
11123: foreach my $item (@{$dirlist}) {
11124: if (ref($item) eq 'ARRAY') {
11125: if (exists($toplevel{$item->[0]})) {
11126: $duplicates .=
11127: &start_data_table_row().
11128: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11129: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11130: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11131: 'value="1" />'.&mt('Yes').'</label>'.
11132: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11133: '<td>'.$item->[0].'</td>';
11134: if ($item->[2]) {
11135: $duplicates .= '<td>'.&mt('Directory').'</td>';
11136: } else {
11137: $duplicates .= '<td>'.&mt('File').'</td>';
11138: }
11139: $duplicates .= '<td>'.$item->[3].'</td>'.
11140: '<td>'.
11141: &Apache::lonlocal::locallocaltime($item->[4]).
11142: '</td>'.
11143: &end_data_table_row();
11144: $num ++;
11145: }
11146: }
11147: }
11148: }
11149: my $itemcount;
11150: if (@paths > 0) {
11151: $itemcount = scalar(@paths);
11152: } else {
11153: $itemcount = 1;
11154: }
1.1067 raeburn 11155: if ($is_camtasia) {
11156: $output .= $lt{'auto'}.'<br />'.
11157: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 11158: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11159: $lt{'yes'}.'</label> <label>'.
11160: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11161: $lt{'no'}.'</label></span><br />'.
11162: '<div id="camtasia_titles" style="display:block">'.
11163: &Apache::lonhtmlcommon::start_pick_box().
11164: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11165: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11166: &Apache::lonhtmlcommon::row_closure().
11167: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11168: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11169: &Apache::lonhtmlcommon::row_closure(1).
11170: &Apache::lonhtmlcommon::end_pick_box().
11171: '</div>';
11172: }
1.1065 raeburn 11173: $output .=
11174: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11175: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11176: "\n";
1.1065 raeburn 11177: if ($duplicates ne '') {
11178: $output .= '<p><span class="LC_warning">'.
11179: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11180: &start_data_table().
11181: &start_data_table_header_row().
11182: '<th>'.&mt('Overwrite?').'</th>'.
11183: '<th>'.&mt('Name').'</th>'.
11184: '<th>'.&mt('Type').'</th>'.
11185: '<th>'.&mt('Size').'</th>'.
11186: '<th>'.&mt('Last modified').'</th>'.
11187: &end_data_table_header_row().
11188: $duplicates.
11189: &end_data_table().
11190: '</p>';
11191: }
1.1067 raeburn 11192: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11193: if (ref($hiddenelements) eq 'HASH') {
11194: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11195: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11196: }
11197: }
11198: $output .= <<"END";
1.1067 raeburn 11199: <br />
1.1053 raeburn 11200: <input type="submit" name="decompress" value="$lt{'extr'}" />
11201: </form>
11202: $noextract
11203: END
11204: return $output;
11205: }
11206:
1.1065 raeburn 11207: sub decompression_utility {
11208: my ($program) = @_;
11209: my @utilities = ('tar','gunzip','bunzip2','unzip');
11210: my $location;
11211: if (grep(/^\Q$program\E$/,@utilities)) {
11212: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11213: '/usr/sbin/') {
11214: if (-x $dir.$program) {
11215: $location = $dir.$program;
11216: last;
11217: }
11218: }
11219: }
11220: return $location;
11221: }
11222:
11223: sub list_archive_contents {
11224: my ($file,$pathsref) = @_;
11225: my (@cmd,$output);
11226: my $needsregexp;
11227: if ($file =~ /\.zip$/) {
11228: @cmd = (&decompression_utility('unzip'),"-l");
11229: $needsregexp = 1;
11230: } elsif (($file =~ m/\.tar\.gz$/) ||
11231: ($file =~ /\.tgz$/)) {
11232: @cmd = (&decompression_utility('tar'),"-ztf");
11233: } elsif ($file =~ /\.tar\.bz2$/) {
11234: @cmd = (&decompression_utility('tar'),"-jtf");
11235: } elsif ($file =~ m|\.tar$|) {
11236: @cmd = (&decompression_utility('tar'),"-tf");
11237: }
11238: if (@cmd) {
11239: undef($!);
11240: undef($@);
11241: if (open(my $fh,"-|", @cmd, $file)) {
11242: while (my $line = <$fh>) {
11243: $output .= $line;
11244: chomp($line);
11245: my $item;
11246: if ($needsregexp) {
11247: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11248: } else {
11249: $item = $line;
11250: }
11251: if ($item ne '') {
11252: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11253: push(@{$pathsref},$item);
11254: }
11255: }
11256: }
11257: close($fh);
11258: }
11259: }
11260: return $output;
11261: }
11262:
1.1053 raeburn 11263: sub decompress_uploaded_file {
11264: my ($file,$dir) = @_;
11265: &Apache::lonnet::appenv({'cgi.file' => $file});
11266: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11267: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11268: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11269: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11270: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11271: my $decompressed = $env{'cgi.decompressed'};
11272: &Apache::lonnet::delenv('cgi.file');
11273: &Apache::lonnet::delenv('cgi.dir');
11274: &Apache::lonnet::delenv('cgi.decompressed');
11275: return ($decompressed,$result);
11276: }
11277:
1.1055 raeburn 11278: sub process_decompression {
11279: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11280: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 11281: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 11282: $error = &mt('Filename not a supported archive file type.').
11283: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11284: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11285: } else {
11286: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11287: if ($docuhome eq 'no_host') {
11288: $error = &mt('Could not determine home server for course.');
11289: } else {
11290: my @ids=&Apache::lonnet::current_machine_ids();
11291: my $currdir = "$dir_root/$destination";
11292: if (grep(/^\Q$docuhome\E$/,@ids)) {
11293: $dir = &LONCAPA::propath($docudom,$docuname).
11294: "$dir_root/$destination";
11295: } else {
11296: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11297: "$dir_root/$docudom/$docuname/$destination";
11298: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11299: $error = &mt('Archive file not found.');
11300: }
11301: }
1.1065 raeburn 11302: my (@to_overwrite,@to_skip);
11303: if ($env{'form.archive_overwrite_total'} > 0) {
11304: my $total = $env{'form.archive_overwrite_total'};
11305: for (my $i=0; $i<$total; $i++) {
11306: if ($env{'form.archive_overwrite_'.$i} == 1) {
11307: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11308: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11309: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11310: }
11311: }
11312: }
11313: my $numskip = scalar(@to_skip);
11314: if (($numskip > 0) &&
11315: ($numskip == $env{'form.archive_itemcount'})) {
11316: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11317: } elsif ($dir eq '') {
1.1055 raeburn 11318: $error = &mt('Directory containing archive file unavailable.');
11319: } elsif (!$error) {
1.1065 raeburn 11320: my ($decompressed,$display);
11321: if ($numskip > 0) {
11322: my $tempdir = time.'_'.$$.int(rand(10000));
11323: mkdir("$dir/$tempdir",0755);
11324: system("mv $dir/$file $dir/$tempdir/$file");
11325: ($decompressed,$display) =
11326: &decompress_uploaded_file($file,"$dir/$tempdir");
11327: foreach my $item (@to_skip) {
11328: if (($item ne '') && ($item !~ /\.\./)) {
11329: if (-f "$dir/$tempdir/$item") {
11330: unlink("$dir/$tempdir/$item");
11331: } elsif (-d "$dir/$tempdir/$item") {
11332: system("rm -rf $dir/$tempdir/$item");
11333: }
11334: }
11335: }
11336: system("mv $dir/$tempdir/* $dir");
11337: rmdir("$dir/$tempdir");
11338: } else {
11339: ($decompressed,$display) =
11340: &decompress_uploaded_file($file,$dir);
11341: }
1.1055 raeburn 11342: if ($decompressed eq 'ok') {
1.1065 raeburn 11343: $output = '<p class="LC_info">'.
11344: &mt('Files extracted successfully from archive.').
11345: '</p>'."\n";
1.1055 raeburn 11346: my ($warning,$result,@contents);
11347: my ($newdirlistref,$newlisterror) =
11348: &Apache::lonnet::dirlist($currdir,$docudom,
11349: $docuname,1);
11350: my (%is_dir,%changes,@newitems);
11351: my $dirptr = 16384;
1.1065 raeburn 11352: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11353: foreach my $dir_line (@{$newdirlistref}) {
11354: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11355: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11356: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11357: push(@newitems,$item);
11358: if ($dirptr&$testdir) {
11359: $is_dir{$item} = 1;
11360: }
11361: $changes{$item} = 1;
11362: }
11363: }
11364: }
11365: if (keys(%changes) > 0) {
11366: foreach my $item (sort(@newitems)) {
11367: if ($changes{$item}) {
11368: push(@contents,$item);
11369: }
11370: }
11371: }
11372: if (@contents > 0) {
1.1067 raeburn 11373: my $wantform;
11374: unless ($env{'form.autoextract_camtasia'}) {
11375: $wantform = 1;
11376: }
1.1056 raeburn 11377: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11378: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11379: $currdir,\%is_dir,
11380: \%children,\%parent,
1.1056 raeburn 11381: \@contents,\%dirorder,
11382: \%titles,$wantform);
1.1055 raeburn 11383: if ($datatable ne '') {
11384: $output .= &archive_options_form('decompressed',$datatable,
11385: $count,$hiddenelem);
1.1065 raeburn 11386: my $startcount = 6;
1.1055 raeburn 11387: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11388: \%titles,\%children);
1.1055 raeburn 11389: }
1.1067 raeburn 11390: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 11391: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 11392: my %displayed;
11393: my $total = 1;
11394: $env{'form.archive_directory'} = [];
11395: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11396: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11397: $path =~ s{/$}{};
11398: my $item;
11399: if ($path ne '') {
11400: $item = "$path/$titles{$i}";
11401: } else {
11402: $item = $titles{$i};
11403: }
11404: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11405: if ($item eq $contents[0]) {
11406: push(@{$env{'form.archive_directory'}},$i);
11407: $env{'form.archive_'.$i} = 'display';
11408: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11409: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 11410: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
11411: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 11412: $env{'form.archive_'.$i} = 'display';
11413: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11414: $displayed{'web'} = $i;
11415: } else {
1.1075.2.59 raeburn 11416: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
11417: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
11418: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 11419: push(@{$env{'form.archive_directory'}},$i);
11420: }
11421: $env{'form.archive_'.$i} = 'dependency';
11422: }
11423: $total ++;
11424: }
11425: for (my $i=1; $i<$total; $i++) {
11426: next if ($i == $displayed{'web'});
11427: next if ($i == $displayed{'folder'});
11428: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11429: }
11430: $env{'form.phase'} = 'decompress_cleanup';
11431: $env{'form.archivedelete'} = 1;
11432: $env{'form.archive_count'} = $total-1;
11433: $output .=
11434: &process_extracted_files('coursedocs',$docudom,
11435: $docuname,$destination,
11436: $dir_root,$hiddenelem);
11437: }
1.1055 raeburn 11438: } else {
11439: $warning = &mt('No new items extracted from archive file.');
11440: }
11441: } else {
11442: $output = $display;
11443: $error = &mt('An error occurred during extraction from the archive file.');
11444: }
11445: }
11446: }
11447: }
11448: if ($error) {
11449: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11450: $error.'</p>'."\n";
11451: }
11452: if ($warning) {
11453: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11454: }
11455: return $output;
11456: }
11457:
11458: sub get_extracted {
1.1056 raeburn 11459: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11460: $titles,$wantform) = @_;
1.1055 raeburn 11461: my $count = 0;
11462: my $depth = 0;
11463: my $datatable;
1.1056 raeburn 11464: my @hierarchy;
1.1055 raeburn 11465: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11466: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11467: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11468: foreach my $item (@{$contents}) {
11469: $count ++;
1.1056 raeburn 11470: @{$dirorder->{$count}} = @hierarchy;
11471: $titles->{$count} = $item;
1.1055 raeburn 11472: &archive_hierarchy($depth,$count,$parent,$children);
11473: if ($wantform) {
11474: $datatable .= &archive_row($is_dir->{$item},$item,
11475: $currdir,$depth,$count);
11476: }
11477: if ($is_dir->{$item}) {
11478: $depth ++;
1.1056 raeburn 11479: push(@hierarchy,$count);
11480: $parent->{$depth} = $count;
1.1055 raeburn 11481: $datatable .=
11482: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11483: \$depth,\$count,\@hierarchy,$dirorder,
11484: $children,$parent,$titles,$wantform);
1.1055 raeburn 11485: $depth --;
1.1056 raeburn 11486: pop(@hierarchy);
1.1055 raeburn 11487: }
11488: }
11489: return ($count,$datatable);
11490: }
11491:
11492: sub recurse_extracted_archive {
1.1056 raeburn 11493: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11494: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11495: my $result='';
1.1056 raeburn 11496: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11497: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11498: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11499: return $result;
11500: }
11501: my $dirptr = 16384;
11502: my ($newdirlistref,$newlisterror) =
11503: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11504: if (ref($newdirlistref) eq 'ARRAY') {
11505: foreach my $dir_line (@{$newdirlistref}) {
11506: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11507: unless ($item =~ /^\.+$/) {
11508: $$count ++;
1.1056 raeburn 11509: @{$dirorder->{$$count}} = @{$hierarchy};
11510: $titles->{$$count} = $item;
1.1055 raeburn 11511: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11512:
1.1055 raeburn 11513: my $is_dir;
11514: if ($dirptr&$testdir) {
11515: $is_dir = 1;
11516: }
11517: if ($wantform) {
11518: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11519: }
11520: if ($is_dir) {
11521: $$depth ++;
1.1056 raeburn 11522: push(@{$hierarchy},$$count);
11523: $parent->{$$depth} = $$count;
1.1055 raeburn 11524: $result .=
11525: &recurse_extracted_archive("$currdir/$item",$docudom,
11526: $docuname,$depth,$count,
1.1056 raeburn 11527: $hierarchy,$dirorder,$children,
11528: $parent,$titles,$wantform);
1.1055 raeburn 11529: $$depth --;
1.1056 raeburn 11530: pop(@{$hierarchy});
1.1055 raeburn 11531: }
11532: }
11533: }
11534: }
11535: return $result;
11536: }
11537:
11538: sub archive_hierarchy {
11539: my ($depth,$count,$parent,$children) =@_;
11540: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11541: if (exists($parent->{$depth})) {
11542: $children->{$parent->{$depth}} .= $count.':';
11543: }
11544: }
11545: return;
11546: }
11547:
11548: sub archive_row {
11549: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11550: my ($name) = ($item =~ m{([^/]+)$});
11551: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11552: 'display' => 'Add as file',
1.1055 raeburn 11553: 'dependency' => 'Include as dependency',
11554: 'discard' => 'Discard',
11555: );
11556: if ($is_dir) {
1.1059 raeburn 11557: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11558: }
1.1056 raeburn 11559: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11560: my $offset = 0;
1.1055 raeburn 11561: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11562: $offset ++;
1.1065 raeburn 11563: if ($action ne 'display') {
11564: $offset ++;
11565: }
1.1055 raeburn 11566: $output .= '<td><span class="LC_nobreak">'.
11567: '<label><input type="radio" name="archive_'.$count.
11568: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11569: my $text = $choices{$action};
11570: if ($is_dir) {
11571: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11572: if ($action eq 'display') {
1.1059 raeburn 11573: $text = &mt('Add as folder');
1.1055 raeburn 11574: }
1.1056 raeburn 11575: } else {
11576: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11577:
11578: }
11579: $output .= ' /> '.$choices{$action}.'</label></span>';
11580: if ($action eq 'dependency') {
11581: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11582: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11583: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11584: '<option value=""></option>'."\n".
11585: '</select>'."\n".
11586: '</div>';
1.1059 raeburn 11587: } elsif ($action eq 'display') {
11588: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11589: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11590: '</div>';
1.1055 raeburn 11591: }
1.1056 raeburn 11592: $output .= '</td>';
1.1055 raeburn 11593: }
11594: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11595: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11596: for (my $i=0; $i<$depth; $i++) {
11597: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11598: }
11599: if ($is_dir) {
11600: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11601: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11602: } else {
11603: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11604: }
11605: $output .= ' '.$name.'</td>'."\n".
11606: &end_data_table_row();
11607: return $output;
11608: }
11609:
11610: sub archive_options_form {
1.1065 raeburn 11611: my ($form,$display,$count,$hiddenelem) = @_;
11612: my %lt = &Apache::lonlocal::texthash(
11613: perm => 'Permanently remove archive file?',
11614: hows => 'How should each extracted item be incorporated in the course?',
11615: cont => 'Content actions for all',
11616: addf => 'Add as folder/file',
11617: incd => 'Include as dependency for a displayed file',
11618: disc => 'Discard',
11619: no => 'No',
11620: yes => 'Yes',
11621: save => 'Save',
11622: );
11623: my $output = <<"END";
11624: <form name="$form" method="post" action="">
11625: <p><span class="LC_nobreak">$lt{'perm'}
11626: <label>
11627: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11628: </label>
11629:
11630: <label>
11631: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11632: </span>
11633: </p>
11634: <input type="hidden" name="phase" value="decompress_cleanup" />
11635: <br />$lt{'hows'}
11636: <div class="LC_columnSection">
11637: <fieldset>
11638: <legend>$lt{'cont'}</legend>
11639: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11640: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11641: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11642: </fieldset>
11643: </div>
11644: END
11645: return $output.
1.1055 raeburn 11646: &start_data_table()."\n".
1.1065 raeburn 11647: $display."\n".
1.1055 raeburn 11648: &end_data_table()."\n".
11649: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11650: $hiddenelem.
1.1065 raeburn 11651: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11652: '</form>';
11653: }
11654:
11655: sub archive_javascript {
1.1056 raeburn 11656: my ($startcount,$numitems,$titles,$children) = @_;
11657: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11658: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11659: my $scripttag = <<START;
11660: <script type="text/javascript">
11661: // <![CDATA[
11662:
11663: function checkAll(form,prefix) {
11664: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11665: for (var i=0; i < form.elements.length; i++) {
11666: var id = form.elements[i].id;
11667: if ((id != '') && (id != undefined)) {
11668: if (idstr.test(id)) {
11669: if (form.elements[i].type == 'radio') {
11670: form.elements[i].checked = true;
1.1056 raeburn 11671: var nostart = i-$startcount;
1.1059 raeburn 11672: var offset = nostart%7;
11673: var count = (nostart-offset)/7;
1.1056 raeburn 11674: dependencyCheck(form,count,offset);
1.1055 raeburn 11675: }
11676: }
11677: }
11678: }
11679: }
11680:
11681: function propagateCheck(form,count) {
11682: if (count > 0) {
1.1059 raeburn 11683: var startelement = $startcount + ((count-1) * 7);
11684: for (var j=1; j<6; j++) {
11685: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11686: var item = startelement + j;
11687: if (form.elements[item].type == 'radio') {
11688: if (form.elements[item].checked) {
11689: containerCheck(form,count,j);
11690: break;
11691: }
1.1055 raeburn 11692: }
11693: }
11694: }
11695: }
11696: }
11697:
11698: numitems = $numitems
1.1056 raeburn 11699: var titles = new Array(numitems);
11700: var parents = new Array(numitems);
1.1055 raeburn 11701: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11702: parents[i] = new Array;
1.1055 raeburn 11703: }
1.1059 raeburn 11704: var maintitle = '$maintitle';
1.1055 raeburn 11705:
11706: START
11707:
1.1056 raeburn 11708: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11709: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11710: for (my $i=0; $i<@contents; $i ++) {
11711: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11712: }
11713: }
11714:
1.1056 raeburn 11715: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11716: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11717: }
11718:
1.1055 raeburn 11719: $scripttag .= <<END;
11720:
11721: function containerCheck(form,count,offset) {
11722: if (count > 0) {
1.1056 raeburn 11723: dependencyCheck(form,count,offset);
1.1059 raeburn 11724: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11725: form.elements[item].checked = true;
11726: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11727: if (parents[count].length > 0) {
11728: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11729: containerCheck(form,parents[count][j],offset);
11730: }
11731: }
11732: }
11733: }
11734: }
11735:
11736: function dependencyCheck(form,count,offset) {
11737: if (count > 0) {
1.1059 raeburn 11738: var chosen = (offset+$startcount)+7*(count-1);
11739: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11740: var currtype = form.elements[depitem].type;
11741: if (form.elements[chosen].value == 'dependency') {
11742: document.getElementById('arc_depon_'+count).style.display='block';
11743: form.elements[depitem].options.length = 0;
11744: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 11745: for (var i=1; i<=numitems; i++) {
11746: if (i == count) {
11747: continue;
11748: }
1.1059 raeburn 11749: var startelement = $startcount + (i-1) * 7;
11750: for (var j=1; j<6; j++) {
11751: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11752: var item = startelement + j;
11753: if (form.elements[item].type == 'radio') {
11754: if (form.elements[item].checked) {
11755: if (form.elements[item].value == 'display') {
11756: var n = form.elements[depitem].options.length;
11757: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11758: }
11759: }
11760: }
11761: }
11762: }
11763: }
11764: } else {
11765: document.getElementById('arc_depon_'+count).style.display='none';
11766: form.elements[depitem].options.length = 0;
11767: form.elements[depitem].options[0] = new Option('Select','',true,true);
11768: }
1.1059 raeburn 11769: titleCheck(form,count,offset);
1.1056 raeburn 11770: }
11771: }
11772:
11773: function propagateSelect(form,count,offset) {
11774: if (count > 0) {
1.1065 raeburn 11775: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11776: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11777: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11778: if (parents[count].length > 0) {
11779: for (var j=0; j<parents[count].length; j++) {
11780: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11781: }
11782: }
11783: }
11784: }
11785: }
1.1056 raeburn 11786:
11787: function containerSelect(form,count,offset,picked) {
11788: if (count > 0) {
1.1065 raeburn 11789: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11790: if (form.elements[item].type == 'radio') {
11791: if (form.elements[item].value == 'dependency') {
11792: if (form.elements[item+1].type == 'select-one') {
11793: for (var i=0; i<form.elements[item+1].options.length; i++) {
11794: if (form.elements[item+1].options[i].value == picked) {
11795: form.elements[item+1].selectedIndex = i;
11796: break;
11797: }
11798: }
11799: }
11800: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11801: if (parents[count].length > 0) {
11802: for (var j=0; j<parents[count].length; j++) {
11803: containerSelect(form,parents[count][j],offset,picked);
11804: }
11805: }
11806: }
11807: }
11808: }
11809: }
11810: }
11811:
1.1059 raeburn 11812: function titleCheck(form,count,offset) {
11813: if (count > 0) {
11814: var chosen = (offset+$startcount)+7*(count-1);
11815: var depitem = $startcount + ((count-1) * 7) + 2;
11816: var currtype = form.elements[depitem].type;
11817: if (form.elements[chosen].value == 'display') {
11818: document.getElementById('arc_title_'+count).style.display='block';
11819: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11820: document.getElementById('archive_title_'+count).value=maintitle;
11821: }
11822: } else {
11823: document.getElementById('arc_title_'+count).style.display='none';
11824: if (currtype == 'text') {
11825: document.getElementById('archive_title_'+count).value='';
11826: }
11827: }
11828: }
11829: return;
11830: }
11831:
1.1055 raeburn 11832: // ]]>
11833: </script>
11834: END
11835: return $scripttag;
11836: }
11837:
11838: sub process_extracted_files {
1.1067 raeburn 11839: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11840: my $numitems = $env{'form.archive_count'};
11841: return unless ($numitems);
11842: my @ids=&Apache::lonnet::current_machine_ids();
11843: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11844: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11845: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11846: if (grep(/^\Q$docuhome\E$/,@ids)) {
11847: $prefix = &LONCAPA::propath($docudom,$docuname);
11848: $pathtocheck = "$dir_root/$destination";
11849: $dir = $dir_root;
11850: $ishome = 1;
11851: } else {
11852: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11853: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11854: $dir = "$dir_root/$docudom/$docuname";
11855: }
11856: my $currdir = "$dir_root/$destination";
11857: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11858: if ($env{'form.folderpath'}) {
11859: my @items = split('&',$env{'form.folderpath'});
11860: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 11861: if ($env{'form.folderpath'} =~ /\:1$/) {
11862: $containers{'0'}='page';
11863: } else {
11864: $containers{'0'}='sequence';
11865: }
1.1055 raeburn 11866: }
11867: my @archdirs = &get_env_multiple('form.archive_directory');
11868: if ($numitems) {
11869: for (my $i=1; $i<=$numitems; $i++) {
11870: my $path = $env{'form.archive_content_'.$i};
11871: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11872: my $item = $1;
11873: $toplevelitems{$item} = $i;
11874: if (grep(/^\Q$i\E$/,@archdirs)) {
11875: $is_dir{$item} = 1;
11876: }
11877: }
11878: }
11879: }
1.1067 raeburn 11880: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11881: if (keys(%toplevelitems) > 0) {
11882: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11883: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11884: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11885: }
1.1066 raeburn 11886: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11887: if ($numitems) {
11888: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 11889: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11890: my $path = $env{'form.archive_content_'.$i};
11891: if ($path =~ /^\Q$pathtocheck\E/) {
11892: if ($env{'form.archive_'.$i} eq 'discard') {
11893: if ($prefix ne '' && $path ne '') {
11894: if (-e $prefix.$path) {
1.1066 raeburn 11895: if ((@archdirs > 0) &&
11896: (grep(/^\Q$i\E$/,@archdirs))) {
11897: $todeletedir{$prefix.$path} = 1;
11898: } else {
11899: $todelete{$prefix.$path} = 1;
11900: }
1.1055 raeburn 11901: }
11902: }
11903: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11904: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11905: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11906: $docstitle = $env{'form.archive_title_'.$i};
11907: if ($docstitle eq '') {
11908: $docstitle = $title;
11909: }
1.1055 raeburn 11910: $outer = 0;
1.1056 raeburn 11911: if (ref($dirorder{$i}) eq 'ARRAY') {
11912: if (@{$dirorder{$i}} > 0) {
11913: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11914: if ($env{'form.archive_'.$item} eq 'display') {
11915: $outer = $item;
11916: last;
11917: }
11918: }
11919: }
11920: }
11921: my ($errtext,$fatal) =
11922: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11923: '/'.$folders{$outer}.'.'.
11924: $containers{$outer});
11925: next if ($fatal);
11926: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11927: if ($context eq 'coursedocs') {
1.1056 raeburn 11928: $mapinner{$i} = time;
1.1055 raeburn 11929: $folders{$i} = 'default_'.$mapinner{$i};
11930: $containers{$i} = 'sequence';
11931: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11932: $folders{$i}.'.'.$containers{$i};
11933: my $newidx = &LONCAPA::map::getresidx();
11934: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11935: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11936: push(@LONCAPA::map::order,$newidx);
11937: my ($outtext,$errtext) =
11938: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11939: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11940: '.'.$containers{$outer},1,1);
1.1056 raeburn 11941: $newseqid{$i} = $newidx;
1.1067 raeburn 11942: unless ($errtext) {
11943: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11944: }
1.1055 raeburn 11945: }
11946: } else {
11947: if ($context eq 'coursedocs') {
11948: my $newidx=&LONCAPA::map::getresidx();
11949: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11950: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11951: $title;
11952: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11953: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11954: }
11955: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11956: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11957: }
11958: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11959: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11960: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11961: unless ($ishome) {
11962: my $fetch = "$newdest{$i}/$title";
11963: $fetch =~ s/^\Q$prefix$dir\E//;
11964: $prompttofetch{$fetch} = 1;
11965: }
1.1055 raeburn 11966: }
11967: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11968: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11969: push(@LONCAPA::map::order, $newidx);
11970: my ($outtext,$errtext)=
11971: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11972: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11973: '.'.$containers{$outer},1,1);
1.1067 raeburn 11974: unless ($errtext) {
11975: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11976: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11977: }
11978: }
1.1055 raeburn 11979: }
11980: }
1.1075.2.11 raeburn 11981: }
11982: } else {
11983: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11984: }
11985: }
11986: for (my $i=1; $i<=$numitems; $i++) {
11987: next unless ($env{'form.archive_'.$i} eq 'dependency');
11988: my $path = $env{'form.archive_content_'.$i};
11989: if ($path =~ /^\Q$pathtocheck\E/) {
11990: my ($title) = ($path =~ m{/([^/]+)$});
11991: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11992: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11993: if (ref($dirorder{$i}) eq 'ARRAY') {
11994: my ($itemidx,$fullpath,$relpath);
11995: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11996: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11997: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 11998: if ($dirorder{$i}->[$j] eq $container) {
11999: $itemidx = $j;
1.1056 raeburn 12000: }
12001: }
1.1075.2.11 raeburn 12002: }
12003: if ($itemidx eq '') {
12004: $itemidx = 0;
12005: }
12006: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12007: if ($mapinner{$referrer{$i}}) {
12008: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12009: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12010: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12011: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12012: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12013: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12014: if (!-e $fullpath) {
12015: mkdir($fullpath,0755);
1.1056 raeburn 12016: }
12017: }
1.1075.2.11 raeburn 12018: } else {
12019: last;
1.1056 raeburn 12020: }
1.1075.2.11 raeburn 12021: }
12022: }
12023: } elsif ($newdest{$referrer{$i}}) {
12024: $fullpath = $newdest{$referrer{$i}};
12025: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12026: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12027: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12028: last;
12029: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12030: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12031: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12032: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12033: if (!-e $fullpath) {
12034: mkdir($fullpath,0755);
1.1056 raeburn 12035: }
12036: }
1.1075.2.11 raeburn 12037: } else {
12038: last;
1.1056 raeburn 12039: }
1.1075.2.11 raeburn 12040: }
12041: }
12042: if ($fullpath ne '') {
12043: if (-e "$prefix$path") {
12044: system("mv $prefix$path $fullpath/$title");
12045: }
12046: if (-e "$fullpath/$title") {
12047: my $showpath;
12048: if ($relpath ne '') {
12049: $showpath = "$relpath/$title";
12050: } else {
12051: $showpath = "/$title";
1.1056 raeburn 12052: }
1.1075.2.11 raeburn 12053: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12054: }
12055: unless ($ishome) {
12056: my $fetch = "$fullpath/$title";
12057: $fetch =~ s/^\Q$prefix$dir\E//;
12058: $prompttofetch{$fetch} = 1;
1.1055 raeburn 12059: }
12060: }
12061: }
1.1075.2.11 raeburn 12062: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12063: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12064: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12065: }
12066: } else {
1.1075.2.11 raeburn 12067: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 12068: }
12069: }
12070: if (keys(%todelete)) {
12071: foreach my $key (keys(%todelete)) {
12072: unlink($key);
1.1066 raeburn 12073: }
12074: }
12075: if (keys(%todeletedir)) {
12076: foreach my $key (keys(%todeletedir)) {
12077: rmdir($key);
12078: }
12079: }
12080: foreach my $dir (sort(keys(%is_dir))) {
12081: if (($pathtocheck ne '') && ($dir ne '')) {
12082: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12083: }
12084: }
1.1067 raeburn 12085: if ($result ne '') {
12086: $output .= '<ul>'."\n".
12087: $result."\n".
12088: '</ul>';
12089: }
12090: unless ($ishome) {
12091: my $replicationfail;
12092: foreach my $item (keys(%prompttofetch)) {
12093: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12094: unless ($fetchresult eq 'ok') {
12095: $replicationfail .= '<li>'.$item.'</li>'."\n";
12096: }
12097: }
12098: if ($replicationfail) {
12099: $output .= '<p class="LC_error">'.
12100: &mt('Course home server failed to retrieve:').'<ul>'.
12101: $replicationfail.
12102: '</ul></p>';
12103: }
12104: }
1.1055 raeburn 12105: } else {
12106: $warning = &mt('No items found in archive.');
12107: }
12108: if ($error) {
12109: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12110: $error.'</p>'."\n";
12111: }
12112: if ($warning) {
12113: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12114: }
12115: return $output;
12116: }
12117:
1.1066 raeburn 12118: sub cleanup_empty_dirs {
12119: my ($path) = @_;
12120: if (($path ne '') && (-d $path)) {
12121: if (opendir(my $dirh,$path)) {
12122: my @dircontents = grep(!/^\./,readdir($dirh));
12123: my $numitems = 0;
12124: foreach my $item (@dircontents) {
12125: if (-d "$path/$item") {
1.1075.2.28 raeburn 12126: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12127: if (-e "$path/$item") {
12128: $numitems ++;
12129: }
12130: } else {
12131: $numitems ++;
12132: }
12133: }
12134: if ($numitems == 0) {
12135: rmdir($path);
12136: }
12137: closedir($dirh);
12138: }
12139: }
12140: return;
12141: }
12142:
1.41 ng 12143: =pod
1.45 matthew 12144:
1.1075.2.56 raeburn 12145: =item * &get_folder_hierarchy()
1.1068 raeburn 12146:
12147: Provides hierarchy of names of folders/sub-folders containing the current
12148: item,
12149:
12150: Inputs: 3
12151: - $navmap - navmaps object
12152:
12153: - $map - url for map (either the trigger itself, or map containing
12154: the resource, which is the trigger).
12155:
12156: - $showitem - 1 => show title for map itself; 0 => do not show.
12157:
12158: Outputs: 1 @pathitems - array of folder/subfolder names.
12159:
12160: =cut
12161:
12162: sub get_folder_hierarchy {
12163: my ($navmap,$map,$showitem) = @_;
12164: my @pathitems;
12165: if (ref($navmap)) {
12166: my $mapres = $navmap->getResourceByUrl($map);
12167: if (ref($mapres)) {
12168: my $pcslist = $mapres->map_hierarchy();
12169: if ($pcslist ne '') {
12170: my @pcs = split(/,/,$pcslist);
12171: foreach my $pc (@pcs) {
12172: if ($pc == 1) {
1.1075.2.38 raeburn 12173: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12174: } else {
12175: my $res = $navmap->getByMapPc($pc);
12176: if (ref($res)) {
12177: my $title = $res->compTitle();
12178: $title =~ s/\W+/_/g;
12179: if ($title ne '') {
12180: push(@pathitems,$title);
12181: }
12182: }
12183: }
12184: }
12185: }
1.1071 raeburn 12186: if ($showitem) {
12187: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12188: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12189: } else {
12190: my $maptitle = $mapres->compTitle();
12191: $maptitle =~ s/\W+/_/g;
12192: if ($maptitle ne '') {
12193: push(@pathitems,$maptitle);
12194: }
1.1068 raeburn 12195: }
12196: }
12197: }
12198: }
12199: return @pathitems;
12200: }
12201:
12202: =pod
12203:
1.1015 raeburn 12204: =item * &get_turnedin_filepath()
12205:
12206: Determines path in a user's portfolio file for storage of files uploaded
12207: to a specific essayresponse or dropbox item.
12208:
12209: Inputs: 3 required + 1 optional.
12210: $symb is symb for resource, $uname and $udom are for current user (required).
12211: $caller is optional (can be "submission", if routine is called when storing
12212: an upoaded file when "Submit Answer" button was pressed).
12213:
12214: Returns array containing $path and $multiresp.
12215: $path is path in portfolio. $multiresp is 1 if this resource contains more
12216: than one file upload item. Callers of routine should append partid as a
12217: subdirectory to $path in cases where $multiresp is 1.
12218:
12219: Called by: homework/essayresponse.pm and homework/structuretags.pm
12220:
12221: =cut
12222:
12223: sub get_turnedin_filepath {
12224: my ($symb,$uname,$udom,$caller) = @_;
12225: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12226: my $turnindir;
12227: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12228: $turnindir = $userhash{'turnindir'};
12229: my ($path,$multiresp);
12230: if ($turnindir eq '') {
12231: if ($caller eq 'submission') {
12232: $turnindir = &mt('turned in');
12233: $turnindir =~ s/\W+/_/g;
12234: my %newhash = (
12235: 'turnindir' => $turnindir,
12236: );
12237: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12238: }
12239: }
12240: if ($turnindir ne '') {
12241: $path = '/'.$turnindir.'/';
12242: my ($multipart,$turnin,@pathitems);
12243: my $navmap = Apache::lonnavmaps::navmap->new();
12244: if (defined($navmap)) {
12245: my $mapres = $navmap->getResourceByUrl($map);
12246: if (ref($mapres)) {
12247: my $pcslist = $mapres->map_hierarchy();
12248: if ($pcslist ne '') {
12249: foreach my $pc (split(/,/,$pcslist)) {
12250: my $res = $navmap->getByMapPc($pc);
12251: if (ref($res)) {
12252: my $title = $res->compTitle();
12253: $title =~ s/\W+/_/g;
12254: if ($title ne '') {
1.1075.2.48 raeburn 12255: if (($pc > 1) && (length($title) > 12)) {
12256: $title = substr($title,0,12);
12257: }
1.1015 raeburn 12258: push(@pathitems,$title);
12259: }
12260: }
12261: }
12262: }
12263: my $maptitle = $mapres->compTitle();
12264: $maptitle =~ s/\W+/_/g;
12265: if ($maptitle ne '') {
1.1075.2.48 raeburn 12266: if (length($maptitle) > 12) {
12267: $maptitle = substr($maptitle,0,12);
12268: }
1.1015 raeburn 12269: push(@pathitems,$maptitle);
12270: }
12271: unless ($env{'request.state'} eq 'construct') {
12272: my $res = $navmap->getBySymb($symb);
12273: if (ref($res)) {
12274: my $partlist = $res->parts();
12275: my $totaluploads = 0;
12276: if (ref($partlist) eq 'ARRAY') {
12277: foreach my $part (@{$partlist}) {
12278: my @types = $res->responseType($part);
12279: my @ids = $res->responseIds($part);
12280: for (my $i=0; $i < scalar(@ids); $i++) {
12281: if ($types[$i] eq 'essay') {
12282: my $partid = $part.'_'.$ids[$i];
12283: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12284: $totaluploads ++;
12285: }
12286: }
12287: }
12288: }
12289: if ($totaluploads > 1) {
12290: $multiresp = 1;
12291: }
12292: }
12293: }
12294: }
12295: } else {
12296: return;
12297: }
12298: } else {
12299: return;
12300: }
12301: my $restitle=&Apache::lonnet::gettitle($symb);
12302: $restitle =~ s/\W+/_/g;
12303: if ($restitle eq '') {
12304: $restitle = ($resurl =~ m{/[^/]+$});
12305: if ($restitle eq '') {
12306: $restitle = time;
12307: }
12308: }
1.1075.2.48 raeburn 12309: if (length($restitle) > 12) {
12310: $restitle = substr($restitle,0,12);
12311: }
1.1015 raeburn 12312: push(@pathitems,$restitle);
12313: $path .= join('/',@pathitems);
12314: }
12315: return ($path,$multiresp);
12316: }
12317:
12318: =pod
12319:
1.464 albertel 12320: =back
1.41 ng 12321:
1.112 bowersj2 12322: =head1 CSV Upload/Handling functions
1.38 albertel 12323:
1.41 ng 12324: =over 4
12325:
1.648 raeburn 12326: =item * &upfile_store($r)
1.41 ng 12327:
12328: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12329: needs $env{'form.upfile'}
1.41 ng 12330: returns $datatoken to be put into hidden field
12331:
12332: =cut
1.31 albertel 12333:
12334: sub upfile_store {
12335: my $r=shift;
1.258 albertel 12336: $env{'form.upfile'}=~s/\r/\n/gs;
12337: $env{'form.upfile'}=~s/\f/\n/gs;
12338: $env{'form.upfile'}=~s/\n+/\n/gs;
12339: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12340:
1.258 albertel 12341: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12342: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12343: {
1.158 raeburn 12344: my $datafile = $r->dir_config('lonDaemons').
12345: '/tmp/'.$datatoken.'.tmp';
12346: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12347: print $fh $env{'form.upfile'};
1.158 raeburn 12348: close($fh);
12349: }
1.31 albertel 12350: }
12351: return $datatoken;
12352: }
12353:
1.56 matthew 12354: =pod
12355:
1.648 raeburn 12356: =item * &load_tmp_file($r)
1.41 ng 12357:
12358: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12359: needs $env{'form.datatoken'},
12360: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12361:
12362: =cut
1.31 albertel 12363:
12364: sub load_tmp_file {
12365: my $r=shift;
12366: my @studentdata=();
12367: {
1.158 raeburn 12368: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12369: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12370: if ( open(my $fh,"<$studentfile") ) {
12371: @studentdata=<$fh>;
12372: close($fh);
12373: }
1.31 albertel 12374: }
1.258 albertel 12375: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12376: }
12377:
1.56 matthew 12378: =pod
12379:
1.648 raeburn 12380: =item * &upfile_record_sep()
1.41 ng 12381:
12382: Separate uploaded file into records
12383: returns array of records,
1.258 albertel 12384: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12385:
12386: =cut
1.31 albertel 12387:
12388: sub upfile_record_sep {
1.258 albertel 12389: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12390: } else {
1.248 albertel 12391: my @records;
1.258 albertel 12392: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12393: if ($line=~/^\s*$/) { next; }
12394: push(@records,$line);
12395: }
12396: return @records;
1.31 albertel 12397: }
12398: }
12399:
1.56 matthew 12400: =pod
12401:
1.648 raeburn 12402: =item * &record_sep($record)
1.41 ng 12403:
1.258 albertel 12404: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12405:
12406: =cut
12407:
1.263 www 12408: sub takeleft {
12409: my $index=shift;
12410: return substr('0000'.$index,-4,4);
12411: }
12412:
1.31 albertel 12413: sub record_sep {
12414: my $record=shift;
12415: my %components=();
1.258 albertel 12416: if ($env{'form.upfiletype'} eq 'xml') {
12417: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12418: my $i=0;
1.356 albertel 12419: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12420: $field=~s/^(\"|\')//;
12421: $field=~s/(\"|\')$//;
1.263 www 12422: $components{&takeleft($i)}=$field;
1.31 albertel 12423: $i++;
12424: }
1.258 albertel 12425: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12426: my $i=0;
1.356 albertel 12427: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12428: $field=~s/^(\"|\')//;
12429: $field=~s/(\"|\')$//;
1.263 www 12430: $components{&takeleft($i)}=$field;
1.31 albertel 12431: $i++;
12432: }
12433: } else {
1.561 www 12434: my $separator=',';
1.480 banghart 12435: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12436: $separator=';';
1.480 banghart 12437: }
1.31 albertel 12438: my $i=0;
1.561 www 12439: # the character we are looking for to indicate the end of a quote or a record
12440: my $looking_for=$separator;
12441: # do not add the characters to the fields
12442: my $ignore=0;
12443: # we just encountered a separator (or the beginning of the record)
12444: my $just_found_separator=1;
12445: # store the field we are working on here
12446: my $field='';
12447: # work our way through all characters in record
12448: foreach my $character ($record=~/(.)/g) {
12449: if ($character eq $looking_for) {
12450: if ($character ne $separator) {
12451: # Found the end of a quote, again looking for separator
12452: $looking_for=$separator;
12453: $ignore=1;
12454: } else {
12455: # Found a separator, store away what we got
12456: $components{&takeleft($i)}=$field;
12457: $i++;
12458: $just_found_separator=1;
12459: $ignore=0;
12460: $field='';
12461: }
12462: next;
12463: }
12464: # single or double quotation marks after a separator indicate beginning of a quote
12465: # we are now looking for the end of the quote and need to ignore separators
12466: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12467: $looking_for=$character;
12468: next;
12469: }
12470: # ignore would be true after we reached the end of a quote
12471: if ($ignore) { next; }
12472: if (($just_found_separator) && ($character=~/\s/)) { next; }
12473: $field.=$character;
12474: $just_found_separator=0;
1.31 albertel 12475: }
1.561 www 12476: # catch the very last entry, since we never encountered the separator
12477: $components{&takeleft($i)}=$field;
1.31 albertel 12478: }
12479: return %components;
12480: }
12481:
1.144 matthew 12482: ######################################################
12483: ######################################################
12484:
1.56 matthew 12485: =pod
12486:
1.648 raeburn 12487: =item * &upfile_select_html()
1.41 ng 12488:
1.144 matthew 12489: Return HTML code to select a file from the users machine and specify
12490: the file type.
1.41 ng 12491:
12492: =cut
12493:
1.144 matthew 12494: ######################################################
12495: ######################################################
1.31 albertel 12496: sub upfile_select_html {
1.144 matthew 12497: my %Types = (
12498: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12499: semisv => &mt('Semicolon separated values'),
1.144 matthew 12500: space => &mt('Space separated'),
12501: tab => &mt('Tabulator separated'),
12502: # xml => &mt('HTML/XML'),
12503: );
12504: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12505: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12506: foreach my $type (sort(keys(%Types))) {
12507: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12508: }
12509: $Str .= "</select>\n";
12510: return $Str;
1.31 albertel 12511: }
12512:
1.301 albertel 12513: sub get_samples {
12514: my ($records,$toget) = @_;
12515: my @samples=({});
12516: my $got=0;
12517: foreach my $rec (@$records) {
12518: my %temp = &record_sep($rec);
12519: if (! grep(/\S/, values(%temp))) { next; }
12520: if (%temp) {
12521: $samples[$got]=\%temp;
12522: $got++;
12523: if ($got == $toget) { last; }
12524: }
12525: }
12526: return \@samples;
12527: }
12528:
1.144 matthew 12529: ######################################################
12530: ######################################################
12531:
1.56 matthew 12532: =pod
12533:
1.648 raeburn 12534: =item * &csv_print_samples($r,$records)
1.41 ng 12535:
12536: Prints a table of sample values from each column uploaded $r is an
12537: Apache Request ref, $records is an arrayref from
12538: &Apache::loncommon::upfile_record_sep
12539:
12540: =cut
12541:
1.144 matthew 12542: ######################################################
12543: ######################################################
1.31 albertel 12544: sub csv_print_samples {
12545: my ($r,$records) = @_;
1.662 bisitz 12546: my $samples = &get_samples($records,5);
1.301 albertel 12547:
1.594 raeburn 12548: $r->print(&mt('Samples').'<br />'.&start_data_table().
12549: &start_data_table_header_row());
1.356 albertel 12550: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12551: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12552: $r->print(&end_data_table_header_row());
1.301 albertel 12553: foreach my $hash (@$samples) {
1.594 raeburn 12554: $r->print(&start_data_table_row());
1.356 albertel 12555: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12556: $r->print('<td>');
1.356 albertel 12557: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12558: $r->print('</td>');
12559: }
1.594 raeburn 12560: $r->print(&end_data_table_row());
1.31 albertel 12561: }
1.594 raeburn 12562: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12563: }
12564:
1.144 matthew 12565: ######################################################
12566: ######################################################
12567:
1.56 matthew 12568: =pod
12569:
1.648 raeburn 12570: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12571:
12572: Prints a table to create associations between values and table columns.
1.144 matthew 12573:
1.41 ng 12574: $r is an Apache Request ref,
12575: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12576: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12577:
12578: =cut
12579:
1.144 matthew 12580: ######################################################
12581: ######################################################
1.31 albertel 12582: sub csv_print_select_table {
12583: my ($r,$records,$d) = @_;
1.301 albertel 12584: my $i=0;
12585: my $samples = &get_samples($records,1);
1.144 matthew 12586: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12587: &start_data_table().&start_data_table_header_row().
1.144 matthew 12588: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12589: '<th>'.&mt('Column').'</th>'.
12590: &end_data_table_header_row()."\n");
1.356 albertel 12591: foreach my $array_ref (@$d) {
12592: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12593: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12594:
1.875 bisitz 12595: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12596: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12597: $r->print('<option value="none"></option>');
1.356 albertel 12598: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12599: $r->print('<option value="'.$sample.'"'.
12600: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12601: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12602: }
1.594 raeburn 12603: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12604: $i++;
12605: }
1.594 raeburn 12606: $r->print(&end_data_table());
1.31 albertel 12607: $i--;
12608: return $i;
12609: }
1.56 matthew 12610:
1.144 matthew 12611: ######################################################
12612: ######################################################
12613:
1.56 matthew 12614: =pod
1.31 albertel 12615:
1.648 raeburn 12616: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12617:
12618: Prints a table of sample values from the upload and can make associate samples to internal names.
12619:
12620: $r is an Apache Request ref,
12621: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12622: $d is an array of 2 element arrays (internal name, displayed name)
12623:
12624: =cut
12625:
1.144 matthew 12626: ######################################################
12627: ######################################################
1.31 albertel 12628: sub csv_samples_select_table {
12629: my ($r,$records,$d) = @_;
12630: my $i=0;
1.144 matthew 12631: #
1.662 bisitz 12632: my $max_samples = 5;
12633: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12634: $r->print(&start_data_table().
12635: &start_data_table_header_row().'<th>'.
12636: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12637: &end_data_table_header_row());
1.301 albertel 12638:
12639: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12640: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12641: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12642: foreach my $option (@$d) {
12643: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12644: $r->print('<option value="'.$value.'"'.
1.253 albertel 12645: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12646: $display.'</option>');
1.31 albertel 12647: }
12648: $r->print('</select></td><td>');
1.662 bisitz 12649: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12650: if (defined($samples->[$line]{$key})) {
12651: $r->print($samples->[$line]{$key}."<br />\n");
12652: }
12653: }
1.594 raeburn 12654: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12655: $i++;
12656: }
1.594 raeburn 12657: $r->print(&end_data_table());
1.31 albertel 12658: $i--;
12659: return($i);
1.115 matthew 12660: }
12661:
1.144 matthew 12662: ######################################################
12663: ######################################################
12664:
1.115 matthew 12665: =pod
12666:
1.648 raeburn 12667: =item * &clean_excel_name($name)
1.115 matthew 12668:
12669: Returns a replacement for $name which does not contain any illegal characters.
12670:
12671: =cut
12672:
1.144 matthew 12673: ######################################################
12674: ######################################################
1.115 matthew 12675: sub clean_excel_name {
12676: my ($name) = @_;
12677: $name =~ s/[:\*\?\/\\]//g;
12678: if (length($name) > 31) {
12679: $name = substr($name,0,31);
12680: }
12681: return $name;
1.25 albertel 12682: }
1.84 albertel 12683:
1.85 albertel 12684: =pod
12685:
1.648 raeburn 12686: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12687:
12688: Returns either 1 or undef
12689:
12690: 1 if the part is to be hidden, undef if it is to be shown
12691:
12692: Arguments are:
12693:
12694: $id the id of the part to be checked
12695: $symb, optional the symb of the resource to check
12696: $udom, optional the domain of the user to check for
12697: $uname, optional the username of the user to check for
12698:
12699: =cut
1.84 albertel 12700:
12701: sub check_if_partid_hidden {
12702: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12703: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12704: $symb,$udom,$uname);
1.141 albertel 12705: my $truth=1;
12706: #if the string starts with !, then the list is the list to show not hide
12707: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12708: my @hiddenlist=split(/,/,$hiddenparts);
12709: foreach my $checkid (@hiddenlist) {
1.141 albertel 12710: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12711: }
1.141 albertel 12712: return !$truth;
1.84 albertel 12713: }
1.127 matthew 12714:
1.138 matthew 12715:
12716: ############################################################
12717: ############################################################
12718:
12719: =pod
12720:
1.157 matthew 12721: =back
12722:
1.138 matthew 12723: =head1 cgi-bin script and graphing routines
12724:
1.157 matthew 12725: =over 4
12726:
1.648 raeburn 12727: =item * &get_cgi_id()
1.138 matthew 12728:
12729: Inputs: none
12730:
12731: Returns an id which can be used to pass environment variables
12732: to various cgi-bin scripts. These environment variables will
12733: be removed from the users environment after a given time by
12734: the routine &Apache::lonnet::transfer_profile_to_env.
12735:
12736: =cut
12737:
12738: ############################################################
12739: ############################################################
1.152 albertel 12740: my $uniq=0;
1.136 matthew 12741: sub get_cgi_id {
1.154 albertel 12742: $uniq=($uniq+1)%100000;
1.280 albertel 12743: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12744: }
12745:
1.127 matthew 12746: ############################################################
12747: ############################################################
12748:
12749: =pod
12750:
1.648 raeburn 12751: =item * &DrawBarGraph()
1.127 matthew 12752:
1.138 matthew 12753: Facilitates the plotting of data in a (stacked) bar graph.
12754: Puts plot definition data into the users environment in order for
12755: graph.png to plot it. Returns an <img> tag for the plot.
12756: The bars on the plot are labeled '1','2',...,'n'.
12757:
12758: Inputs:
12759:
12760: =over 4
12761:
12762: =item $Title: string, the title of the plot
12763:
12764: =item $xlabel: string, text describing the X-axis of the plot
12765:
12766: =item $ylabel: string, text describing the Y-axis of the plot
12767:
12768: =item $Max: scalar, the maximum Y value to use in the plot
12769: If $Max is < any data point, the graph will not be rendered.
12770:
1.140 matthew 12771: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12772: they are plotted. If undefined, default values will be used.
12773:
1.178 matthew 12774: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12775:
1.138 matthew 12776: =item @Values: An array of array references. Each array reference holds data
12777: to be plotted in a stacked bar chart.
12778:
1.239 matthew 12779: =item If the final element of @Values is a hash reference the key/value
12780: pairs will be added to the graph definition.
12781:
1.138 matthew 12782: =back
12783:
12784: Returns:
12785:
12786: An <img> tag which references graph.png and the appropriate identifying
12787: information for the plot.
12788:
1.127 matthew 12789: =cut
12790:
12791: ############################################################
12792: ############################################################
1.134 matthew 12793: sub DrawBarGraph {
1.178 matthew 12794: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12795: #
12796: if (! defined($colors)) {
12797: $colors = ['#33ff00',
12798: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12799: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12800: ];
12801: }
1.228 matthew 12802: my $extra_settings = {};
12803: if (ref($Values[-1]) eq 'HASH') {
12804: $extra_settings = pop(@Values);
12805: }
1.127 matthew 12806: #
1.136 matthew 12807: my $identifier = &get_cgi_id();
12808: my $id = 'cgi.'.$identifier;
1.129 matthew 12809: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12810: return '';
12811: }
1.225 matthew 12812: #
12813: my @Labels;
12814: if (defined($labels)) {
12815: @Labels = @$labels;
12816: } else {
12817: for (my $i=0;$i<@{$Values[0]};$i++) {
12818: push (@Labels,$i+1);
12819: }
12820: }
12821: #
1.129 matthew 12822: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12823: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12824: my %ValuesHash;
12825: my $NumSets=1;
12826: foreach my $array (@Values) {
12827: next if (! ref($array));
1.136 matthew 12828: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12829: join(',',@$array);
1.129 matthew 12830: }
1.127 matthew 12831: #
1.136 matthew 12832: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12833: if ($NumBars < 3) {
12834: $width = 120+$NumBars*32;
1.220 matthew 12835: $xskip = 1;
1.225 matthew 12836: $bar_width = 30;
12837: } elsif ($NumBars < 5) {
12838: $width = 120+$NumBars*20;
12839: $xskip = 1;
12840: $bar_width = 20;
1.220 matthew 12841: } elsif ($NumBars < 10) {
1.136 matthew 12842: $width = 120+$NumBars*15;
12843: $xskip = 1;
12844: $bar_width = 15;
12845: } elsif ($NumBars <= 25) {
12846: $width = 120+$NumBars*11;
12847: $xskip = 5;
12848: $bar_width = 8;
12849: } elsif ($NumBars <= 50) {
12850: $width = 120+$NumBars*8;
12851: $xskip = 5;
12852: $bar_width = 4;
12853: } else {
12854: $width = 120+$NumBars*8;
12855: $xskip = 5;
12856: $bar_width = 4;
12857: }
12858: #
1.137 matthew 12859: $Max = 1 if ($Max < 1);
12860: if ( int($Max) < $Max ) {
12861: $Max++;
12862: $Max = int($Max);
12863: }
1.127 matthew 12864: $Title = '' if (! defined($Title));
12865: $xlabel = '' if (! defined($xlabel));
12866: $ylabel = '' if (! defined($ylabel));
1.369 www 12867: $ValuesHash{$id.'.title'} = &escape($Title);
12868: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12869: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12870: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12871: $ValuesHash{$id.'.NumBars'} = $NumBars;
12872: $ValuesHash{$id.'.NumSets'} = $NumSets;
12873: $ValuesHash{$id.'.PlotType'} = 'bar';
12874: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12875: $ValuesHash{$id.'.height'} = $height;
12876: $ValuesHash{$id.'.width'} = $width;
12877: $ValuesHash{$id.'.xskip'} = $xskip;
12878: $ValuesHash{$id.'.bar_width'} = $bar_width;
12879: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12880: #
1.228 matthew 12881: # Deal with other parameters
12882: while (my ($key,$value) = each(%$extra_settings)) {
12883: $ValuesHash{$id.'.'.$key} = $value;
12884: }
12885: #
1.646 raeburn 12886: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12887: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12888: }
12889:
12890: ############################################################
12891: ############################################################
12892:
12893: =pod
12894:
1.648 raeburn 12895: =item * &DrawXYGraph()
1.137 matthew 12896:
1.138 matthew 12897: Facilitates the plotting of data in an XY graph.
12898: Puts plot definition data into the users environment in order for
12899: graph.png to plot it. Returns an <img> tag for the plot.
12900:
12901: Inputs:
12902:
12903: =over 4
12904:
12905: =item $Title: string, the title of the plot
12906:
12907: =item $xlabel: string, text describing the X-axis of the plot
12908:
12909: =item $ylabel: string, text describing the Y-axis of the plot
12910:
12911: =item $Max: scalar, the maximum Y value to use in the plot
12912: If $Max is < any data point, the graph will not be rendered.
12913:
12914: =item $colors: Array ref containing the hex color codes for the data to be
12915: plotted in. If undefined, default values will be used.
12916:
12917: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12918:
12919: =item $Ydata: Array ref containing Array refs.
1.185 www 12920: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12921:
12922: =item %Values: hash indicating or overriding any default values which are
12923: passed to graph.png.
12924: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12925:
12926: =back
12927:
12928: Returns:
12929:
12930: An <img> tag which references graph.png and the appropriate identifying
12931: information for the plot.
12932:
1.137 matthew 12933: =cut
12934:
12935: ############################################################
12936: ############################################################
12937: sub DrawXYGraph {
12938: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12939: #
12940: # Create the identifier for the graph
12941: my $identifier = &get_cgi_id();
12942: my $id = 'cgi.'.$identifier;
12943: #
12944: $Title = '' if (! defined($Title));
12945: $xlabel = '' if (! defined($xlabel));
12946: $ylabel = '' if (! defined($ylabel));
12947: my %ValuesHash =
12948: (
1.369 www 12949: $id.'.title' => &escape($Title),
12950: $id.'.xlabel' => &escape($xlabel),
12951: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12952: $id.'.y_max_value'=> $Max,
12953: $id.'.labels' => join(',',@$Xlabels),
12954: $id.'.PlotType' => 'XY',
12955: );
12956: #
12957: if (defined($colors) && ref($colors) eq 'ARRAY') {
12958: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12959: }
12960: #
12961: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12962: return '';
12963: }
12964: my $NumSets=1;
1.138 matthew 12965: foreach my $array (@{$Ydata}){
1.137 matthew 12966: next if (! ref($array));
12967: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12968: }
1.138 matthew 12969: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12970: #
12971: # Deal with other parameters
12972: while (my ($key,$value) = each(%Values)) {
12973: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12974: }
12975: #
1.646 raeburn 12976: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12977: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12978: }
12979:
12980: ############################################################
12981: ############################################################
12982:
12983: =pod
12984:
1.648 raeburn 12985: =item * &DrawXYYGraph()
1.138 matthew 12986:
12987: Facilitates the plotting of data in an XY graph with two Y axes.
12988: Puts plot definition data into the users environment in order for
12989: graph.png to plot it. Returns an <img> tag for the plot.
12990:
12991: Inputs:
12992:
12993: =over 4
12994:
12995: =item $Title: string, the title of the plot
12996:
12997: =item $xlabel: string, text describing the X-axis of the plot
12998:
12999: =item $ylabel: string, text describing the Y-axis of the plot
13000:
13001: =item $colors: Array ref containing the hex color codes for the data to be
13002: plotted in. If undefined, default values will be used.
13003:
13004: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13005:
13006: =item $Ydata1: The first data set
13007:
13008: =item $Min1: The minimum value of the left Y-axis
13009:
13010: =item $Max1: The maximum value of the left Y-axis
13011:
13012: =item $Ydata2: The second data set
13013:
13014: =item $Min2: The minimum value of the right Y-axis
13015:
13016: =item $Max2: The maximum value of the left Y-axis
13017:
13018: =item %Values: hash indicating or overriding any default values which are
13019: passed to graph.png.
13020: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13021:
13022: =back
13023:
13024: Returns:
13025:
13026: An <img> tag which references graph.png and the appropriate identifying
13027: information for the plot.
1.136 matthew 13028:
13029: =cut
13030:
13031: ############################################################
13032: ############################################################
1.137 matthew 13033: sub DrawXYYGraph {
13034: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13035: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13036: #
13037: # Create the identifier for the graph
13038: my $identifier = &get_cgi_id();
13039: my $id = 'cgi.'.$identifier;
13040: #
13041: $Title = '' if (! defined($Title));
13042: $xlabel = '' if (! defined($xlabel));
13043: $ylabel = '' if (! defined($ylabel));
13044: my %ValuesHash =
13045: (
1.369 www 13046: $id.'.title' => &escape($Title),
13047: $id.'.xlabel' => &escape($xlabel),
13048: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13049: $id.'.labels' => join(',',@$Xlabels),
13050: $id.'.PlotType' => 'XY',
13051: $id.'.NumSets' => 2,
1.137 matthew 13052: $id.'.two_axes' => 1,
13053: $id.'.y1_max_value' => $Max1,
13054: $id.'.y1_min_value' => $Min1,
13055: $id.'.y2_max_value' => $Max2,
13056: $id.'.y2_min_value' => $Min2,
1.136 matthew 13057: );
13058: #
1.137 matthew 13059: if (defined($colors) && ref($colors) eq 'ARRAY') {
13060: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13061: }
13062: #
13063: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13064: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13065: return '';
13066: }
13067: my $NumSets=1;
1.137 matthew 13068: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13069: next if (! ref($array));
13070: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13071: }
13072: #
13073: # Deal with other parameters
13074: while (my ($key,$value) = each(%Values)) {
13075: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13076: }
13077: #
1.646 raeburn 13078: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13079: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13080: }
13081:
13082: ############################################################
13083: ############################################################
13084:
13085: =pod
13086:
1.157 matthew 13087: =back
13088:
1.139 matthew 13089: =head1 Statistics helper routines?
13090:
13091: Bad place for them but what the hell.
13092:
1.157 matthew 13093: =over 4
13094:
1.648 raeburn 13095: =item * &chartlink()
1.139 matthew 13096:
13097: Returns a link to the chart for a specific student.
13098:
13099: Inputs:
13100:
13101: =over 4
13102:
13103: =item $linktext: The text of the link
13104:
13105: =item $sname: The students username
13106:
13107: =item $sdomain: The students domain
13108:
13109: =back
13110:
1.157 matthew 13111: =back
13112:
1.139 matthew 13113: =cut
13114:
13115: ############################################################
13116: ############################################################
13117: sub chartlink {
13118: my ($linktext, $sname, $sdomain) = @_;
13119: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13120: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13121: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13122: '">'.$linktext.'</a>';
1.153 matthew 13123: }
13124:
13125: #######################################################
13126: #######################################################
13127:
13128: =pod
13129:
13130: =head1 Course Environment Routines
1.157 matthew 13131:
13132: =over 4
1.153 matthew 13133:
1.648 raeburn 13134: =item * &restore_course_settings()
1.153 matthew 13135:
1.648 raeburn 13136: =item * &store_course_settings()
1.153 matthew 13137:
13138: Restores/Store indicated form parameters from the course environment.
13139: Will not overwrite existing values of the form parameters.
13140:
13141: Inputs:
13142: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13143:
13144: a hash ref describing the data to be stored. For example:
13145:
13146: %Save_Parameters = ('Status' => 'scalar',
13147: 'chartoutputmode' => 'scalar',
13148: 'chartoutputdata' => 'scalar',
13149: 'Section' => 'array',
1.373 raeburn 13150: 'Group' => 'array',
1.153 matthew 13151: 'StudentData' => 'array',
13152: 'Maps' => 'array');
13153:
13154: Returns: both routines return nothing
13155:
1.631 raeburn 13156: =back
13157:
1.153 matthew 13158: =cut
13159:
13160: #######################################################
13161: #######################################################
13162: sub store_course_settings {
1.496 albertel 13163: return &store_settings($env{'request.course.id'},@_);
13164: }
13165:
13166: sub store_settings {
1.153 matthew 13167: # save to the environment
13168: # appenv the same items, just to be safe
1.300 albertel 13169: my $udom = $env{'user.domain'};
13170: my $uname = $env{'user.name'};
1.496 albertel 13171: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13172: my %SaveHash;
13173: my %AppHash;
13174: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13175: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13176: my $envname = 'environment.'.$basename;
1.258 albertel 13177: if (exists($env{'form.'.$setting})) {
1.153 matthew 13178: # Save this value away
13179: if ($type eq 'scalar' &&
1.258 albertel 13180: (! exists($env{$envname}) ||
13181: $env{$envname} ne $env{'form.'.$setting})) {
13182: $SaveHash{$basename} = $env{'form.'.$setting};
13183: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13184: } elsif ($type eq 'array') {
13185: my $stored_form;
1.258 albertel 13186: if (ref($env{'form.'.$setting})) {
1.153 matthew 13187: $stored_form = join(',',
13188: map {
1.369 www 13189: &escape($_);
1.258 albertel 13190: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13191: } else {
13192: $stored_form =
1.369 www 13193: &escape($env{'form.'.$setting});
1.153 matthew 13194: }
13195: # Determine if the array contents are the same.
1.258 albertel 13196: if ($stored_form ne $env{$envname}) {
1.153 matthew 13197: $SaveHash{$basename} = $stored_form;
13198: $AppHash{$envname} = $stored_form;
13199: }
13200: }
13201: }
13202: }
13203: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13204: $udom,$uname);
1.153 matthew 13205: if ($put_result !~ /^(ok|delayed)/) {
13206: &Apache::lonnet::logthis('unable to save form parameters, '.
13207: 'got error:'.$put_result);
13208: }
13209: # Make sure these settings stick around in this session, too
1.646 raeburn 13210: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13211: return;
13212: }
13213:
13214: sub restore_course_settings {
1.499 albertel 13215: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13216: }
13217:
13218: sub restore_settings {
13219: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13220: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13221: next if (exists($env{'form.'.$setting}));
1.496 albertel 13222: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13223: '.'.$setting;
1.258 albertel 13224: if (exists($env{$envname})) {
1.153 matthew 13225: if ($type eq 'scalar') {
1.258 albertel 13226: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13227: } elsif ($type eq 'array') {
1.258 albertel 13228: $env{'form.'.$setting} = [
1.153 matthew 13229: map {
1.369 www 13230: &unescape($_);
1.258 albertel 13231: } split(',',$env{$envname})
1.153 matthew 13232: ];
13233: }
13234: }
13235: }
1.127 matthew 13236: }
13237:
1.618 raeburn 13238: #######################################################
13239: #######################################################
13240:
13241: =pod
13242:
13243: =head1 Domain E-mail Routines
13244:
13245: =over 4
13246:
1.648 raeburn 13247: =item * &build_recipient_list()
1.618 raeburn 13248:
1.1075.2.44 raeburn 13249: Build recipient lists for following types of e-mail:
1.766 raeburn 13250: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 13251: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13252: module change checking, student/employee ID conflict checks, as
13253: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13254: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13255:
13256: Inputs:
1.1075.2.44 raeburn 13257: defmail (scalar - email address of default recipient),
13258: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13259: requestsmail, updatesmail, or idconflictsmail).
13260:
1.619 raeburn 13261: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 13262:
13263: origmail (scalar - email address of recipient from loncapa.conf,
13264: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13265:
1.655 raeburn 13266: Returns: comma separated list of addresses to which to send e-mail.
13267:
13268: =back
1.618 raeburn 13269:
13270: =cut
13271:
13272: ############################################################
13273: ############################################################
13274: sub build_recipient_list {
1.619 raeburn 13275: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13276: my @recipients;
13277: my $otheremails;
13278: my %domconfig =
13279: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13280: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13281: if (exists($domconfig{'contacts'}{$mailing})) {
13282: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13283: my @contacts = ('adminemail','supportemail');
13284: foreach my $item (@contacts) {
13285: if ($domconfig{'contacts'}{$mailing}{$item}) {
13286: my $addr = $domconfig{'contacts'}{$item};
13287: if (!grep(/^\Q$addr\E$/,@recipients)) {
13288: push(@recipients,$addr);
13289: }
1.619 raeburn 13290: }
1.766 raeburn 13291: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13292: }
13293: }
1.766 raeburn 13294: } elsif ($origmail ne '') {
13295: push(@recipients,$origmail);
1.618 raeburn 13296: }
1.619 raeburn 13297: } elsif ($origmail ne '') {
13298: push(@recipients,$origmail);
1.618 raeburn 13299: }
1.688 raeburn 13300: if (defined($defmail)) {
13301: if ($defmail ne '') {
13302: push(@recipients,$defmail);
13303: }
1.618 raeburn 13304: }
13305: if ($otheremails) {
1.619 raeburn 13306: my @others;
13307: if ($otheremails =~ /,/) {
13308: @others = split(/,/,$otheremails);
1.618 raeburn 13309: } else {
1.619 raeburn 13310: push(@others,$otheremails);
13311: }
13312: foreach my $addr (@others) {
13313: if (!grep(/^\Q$addr\E$/,@recipients)) {
13314: push(@recipients,$addr);
13315: }
1.618 raeburn 13316: }
13317: }
1.619 raeburn 13318: my $recipientlist = join(',',@recipients);
1.618 raeburn 13319: return $recipientlist;
13320: }
13321:
1.127 matthew 13322: ############################################################
13323: ############################################################
1.154 albertel 13324:
1.655 raeburn 13325: =pod
13326:
13327: =head1 Course Catalog Routines
13328:
13329: =over 4
13330:
13331: =item * &gather_categories()
13332:
13333: Converts category definitions - keys of categories hash stored in
13334: coursecategories in configuration.db on the primary library server in a
13335: domain - to an array. Also generates javascript and idx hash used to
13336: generate Domain Coordinator interface for editing Course Categories.
13337:
13338: Inputs:
1.663 raeburn 13339:
1.655 raeburn 13340: categories (reference to hash of category definitions).
1.663 raeburn 13341:
1.655 raeburn 13342: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13343: categories and subcategories).
1.663 raeburn 13344:
1.655 raeburn 13345: idx (reference to hash of counters used in Domain Coordinator interface for
13346: editing Course Categories).
1.663 raeburn 13347:
1.655 raeburn 13348: jsarray (reference to array of categories used to create Javascript arrays for
13349: Domain Coordinator interface for editing Course Categories).
13350:
13351: Returns: nothing
13352:
13353: Side effects: populates cats, idx and jsarray.
13354:
13355: =cut
13356:
13357: sub gather_categories {
13358: my ($categories,$cats,$idx,$jsarray) = @_;
13359: my %counters;
13360: my $num = 0;
13361: foreach my $item (keys(%{$categories})) {
13362: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13363: if ($container eq '' && $depth == 0) {
13364: $cats->[$depth][$categories->{$item}] = $cat;
13365: } else {
13366: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13367: }
13368: my ($escitem,$tail) = split(/:/,$item,2);
13369: if ($counters{$tail} eq '') {
13370: $counters{$tail} = $num;
13371: $num ++;
13372: }
13373: if (ref($idx) eq 'HASH') {
13374: $idx->{$item} = $counters{$tail};
13375: }
13376: if (ref($jsarray) eq 'ARRAY') {
13377: push(@{$jsarray->[$counters{$tail}]},$item);
13378: }
13379: }
13380: return;
13381: }
13382:
13383: =pod
13384:
13385: =item * &extract_categories()
13386:
13387: Used to generate breadcrumb trails for course categories.
13388:
13389: Inputs:
1.663 raeburn 13390:
1.655 raeburn 13391: categories (reference to hash of category definitions).
1.663 raeburn 13392:
1.655 raeburn 13393: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13394: categories and subcategories).
1.663 raeburn 13395:
1.655 raeburn 13396: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13397:
1.655 raeburn 13398: allitems (reference to hash - key is category key
13399: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13400:
1.655 raeburn 13401: idx (reference to hash of counters used in Domain Coordinator interface for
13402: editing Course Categories).
1.663 raeburn 13403:
1.655 raeburn 13404: jsarray (reference to array of categories used to create Javascript arrays for
13405: Domain Coordinator interface for editing Course Categories).
13406:
1.665 raeburn 13407: subcats (reference to hash of arrays containing all subcategories within each
13408: category, -recursive)
13409:
1.655 raeburn 13410: Returns: nothing
13411:
13412: Side effects: populates trails and allitems hash references.
13413:
13414: =cut
13415:
13416: sub extract_categories {
1.665 raeburn 13417: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13418: if (ref($categories) eq 'HASH') {
13419: &gather_categories($categories,$cats,$idx,$jsarray);
13420: if (ref($cats->[0]) eq 'ARRAY') {
13421: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13422: my $name = $cats->[0][$i];
13423: my $item = &escape($name).'::0';
13424: my $trailstr;
13425: if ($name eq 'instcode') {
13426: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13427: } elsif ($name eq 'communities') {
13428: $trailstr = &mt('Communities');
1.655 raeburn 13429: } else {
13430: $trailstr = $name;
13431: }
13432: if ($allitems->{$item} eq '') {
13433: push(@{$trails},$trailstr);
13434: $allitems->{$item} = scalar(@{$trails})-1;
13435: }
13436: my @parents = ($name);
13437: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13438: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13439: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13440: if (ref($subcats) eq 'HASH') {
13441: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13442: }
13443: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13444: }
13445: } else {
13446: if (ref($subcats) eq 'HASH') {
13447: $subcats->{$item} = [];
1.655 raeburn 13448: }
13449: }
13450: }
13451: }
13452: }
13453: return;
13454: }
13455:
13456: =pod
13457:
1.1075.2.56 raeburn 13458: =item * &recurse_categories()
1.655 raeburn 13459:
13460: Recursively used to generate breadcrumb trails for course categories.
13461:
13462: Inputs:
1.663 raeburn 13463:
1.655 raeburn 13464: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13465: categories and subcategories).
1.663 raeburn 13466:
1.655 raeburn 13467: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13468:
13469: category (current course category, for which breadcrumb trail is being generated).
13470:
13471: trails (reference to array of breadcrumb trails for each category).
13472:
1.655 raeburn 13473: allitems (reference to hash - key is category key
13474: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13475:
1.655 raeburn 13476: parents (array containing containers directories for current category,
13477: back to top level).
13478:
13479: Returns: nothing
13480:
13481: Side effects: populates trails and allitems hash references
13482:
13483: =cut
13484:
13485: sub recurse_categories {
1.665 raeburn 13486: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13487: my $shallower = $depth - 1;
13488: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13489: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13490: my $name = $cats->[$depth]{$category}[$k];
13491: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13492: my $trailstr = join(' -> ',(@{$parents},$category));
13493: if ($allitems->{$item} eq '') {
13494: push(@{$trails},$trailstr);
13495: $allitems->{$item} = scalar(@{$trails})-1;
13496: }
13497: my $deeper = $depth+1;
13498: push(@{$parents},$category);
1.665 raeburn 13499: if (ref($subcats) eq 'HASH') {
13500: my $subcat = &escape($name).':'.$category.':'.$depth;
13501: for (my $j=@{$parents}; $j>=0; $j--) {
13502: my $higher;
13503: if ($j > 0) {
13504: $higher = &escape($parents->[$j]).':'.
13505: &escape($parents->[$j-1]).':'.$j;
13506: } else {
13507: $higher = &escape($parents->[$j]).'::'.$j;
13508: }
13509: push(@{$subcats->{$higher}},$subcat);
13510: }
13511: }
13512: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13513: $subcats);
1.655 raeburn 13514: pop(@{$parents});
13515: }
13516: } else {
13517: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13518: my $trailstr = join(' -> ',(@{$parents},$category));
13519: if ($allitems->{$item} eq '') {
13520: push(@{$trails},$trailstr);
13521: $allitems->{$item} = scalar(@{$trails})-1;
13522: }
13523: }
13524: return;
13525: }
13526:
1.663 raeburn 13527: =pod
13528:
1.1075.2.56 raeburn 13529: =item * &assign_categories_table()
1.663 raeburn 13530:
13531: Create a datatable for display of hierarchical categories in a domain,
13532: with checkboxes to allow a course to be categorized.
13533:
13534: Inputs:
13535:
13536: cathash - reference to hash of categories defined for the domain (from
13537: configuration.db)
13538:
13539: currcat - scalar with an & separated list of categories assigned to a course.
13540:
1.919 raeburn 13541: type - scalar contains course type (Course or Community).
13542:
1.663 raeburn 13543: Returns: $output (markup to be displayed)
13544:
13545: =cut
13546:
13547: sub assign_categories_table {
1.919 raeburn 13548: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13549: my $output;
13550: if (ref($cathash) eq 'HASH') {
13551: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13552: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13553: $maxdepth = scalar(@cats);
13554: if (@cats > 0) {
13555: my $itemcount = 0;
13556: if (ref($cats[0]) eq 'ARRAY') {
13557: my @currcategories;
13558: if ($currcat ne '') {
13559: @currcategories = split('&',$currcat);
13560: }
1.919 raeburn 13561: my $table;
1.663 raeburn 13562: for (my $i=0; $i<@{$cats[0]}; $i++) {
13563: my $parent = $cats[0][$i];
1.919 raeburn 13564: next if ($parent eq 'instcode');
13565: if ($type eq 'Community') {
13566: next unless ($parent eq 'communities');
13567: } else {
13568: next if ($parent eq 'communities');
13569: }
1.663 raeburn 13570: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13571: my $item = &escape($parent).'::0';
13572: my $checked = '';
13573: if (@currcategories > 0) {
13574: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13575: $checked = ' checked="checked"';
1.663 raeburn 13576: }
13577: }
1.919 raeburn 13578: my $parent_title = $parent;
13579: if ($parent eq 'communities') {
13580: $parent_title = &mt('Communities');
13581: }
13582: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13583: '<input type="checkbox" name="usecategory" value="'.
13584: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13585: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13586: my $depth = 1;
13587: push(@path,$parent);
1.919 raeburn 13588: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13589: pop(@path);
1.919 raeburn 13590: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13591: $itemcount ++;
13592: }
1.919 raeburn 13593: if ($itemcount) {
13594: $output = &Apache::loncommon::start_data_table().
13595: $table.
13596: &Apache::loncommon::end_data_table();
13597: }
1.663 raeburn 13598: }
13599: }
13600: }
13601: return $output;
13602: }
13603:
13604: =pod
13605:
1.1075.2.56 raeburn 13606: =item * &assign_category_rows()
1.663 raeburn 13607:
13608: Create a datatable row for display of nested categories in a domain,
13609: with checkboxes to allow a course to be categorized,called recursively.
13610:
13611: Inputs:
13612:
13613: itemcount - track row number for alternating colors
13614:
13615: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13616: categories and subcategories.
13617:
13618: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13619:
13620: parent - parent of current category item
13621:
13622: path - Array containing all categories back up through the hierarchy from the
13623: current category to the top level.
13624:
13625: currcategories - reference to array of current categories assigned to the course
13626:
13627: Returns: $output (markup to be displayed).
13628:
13629: =cut
13630:
13631: sub assign_category_rows {
13632: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13633: my ($text,$name,$item,$chgstr);
13634: if (ref($cats) eq 'ARRAY') {
13635: my $maxdepth = scalar(@{$cats});
13636: if (ref($cats->[$depth]) eq 'HASH') {
13637: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13638: my $numchildren = @{$cats->[$depth]{$parent}};
13639: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 13640: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13641: for (my $j=0; $j<$numchildren; $j++) {
13642: $name = $cats->[$depth]{$parent}[$j];
13643: $item = &escape($name).':'.&escape($parent).':'.$depth;
13644: my $deeper = $depth+1;
13645: my $checked = '';
13646: if (ref($currcategories) eq 'ARRAY') {
13647: if (@{$currcategories} > 0) {
13648: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13649: $checked = ' checked="checked"';
1.663 raeburn 13650: }
13651: }
13652: }
1.664 raeburn 13653: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13654: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13655: $item.'"'.$checked.' />'.$name.'</label></span>'.
13656: '<input type="hidden" name="catname" value="'.$name.'" />'.
13657: '</td><td>';
1.663 raeburn 13658: if (ref($path) eq 'ARRAY') {
13659: push(@{$path},$name);
13660: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13661: pop(@{$path});
13662: }
13663: $text .= '</td></tr>';
13664: }
13665: $text .= '</table></td>';
13666: }
13667: }
13668: }
13669: return $text;
13670: }
13671:
1.1075.2.69 raeburn 13672: =pod
13673:
13674: =back
13675:
13676: =cut
13677:
1.655 raeburn 13678: ############################################################
13679: ############################################################
13680:
13681:
1.443 albertel 13682: sub commit_customrole {
1.664 raeburn 13683: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13684: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13685: ($start?', '.&mt('starting').' '.localtime($start):'').
13686: ($end?', ending '.localtime($end):'').': <b>'.
13687: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13688: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13689: '</b><br />';
13690: return $output;
13691: }
13692:
13693: sub commit_standardrole {
1.1075.2.31 raeburn 13694: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13695: my ($output,$logmsg,$linefeed);
13696: if ($context eq 'auto') {
13697: $linefeed = "\n";
13698: } else {
13699: $linefeed = "<br />\n";
13700: }
1.443 albertel 13701: if ($three eq 'st') {
1.541 raeburn 13702: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 13703: $one,$two,$sec,$context,$credits);
1.541 raeburn 13704: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13705: ($result eq 'unknown_course') || ($result eq 'refused')) {
13706: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13707: } else {
1.541 raeburn 13708: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13709: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13710: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13711: if ($context eq 'auto') {
13712: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13713: } else {
13714: $output .= '<b>'.$result.'</b>'.$linefeed.
13715: &mt('Add to classlist').': <b>ok</b>';
13716: }
13717: $output .= $linefeed;
1.443 albertel 13718: }
13719: } else {
13720: $output = &mt('Assigning').' '.$three.' in '.$url.
13721: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13722: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13723: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13724: if ($context eq 'auto') {
13725: $output .= $result.$linefeed;
13726: } else {
13727: $output .= '<b>'.$result.'</b>'.$linefeed;
13728: }
1.443 albertel 13729: }
13730: return $output;
13731: }
13732:
13733: sub commit_studentrole {
1.1075.2.31 raeburn 13734: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13735: $credits) = @_;
1.626 raeburn 13736: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13737: if ($context eq 'auto') {
13738: $linefeed = "\n";
13739: } else {
13740: $linefeed = '<br />'."\n";
13741: }
1.443 albertel 13742: if (defined($one) && defined($two)) {
13743: my $cid=$one.'_'.$two;
13744: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13745: my $secchange = 0;
13746: my $expire_role_result;
13747: my $modify_section_result;
1.628 raeburn 13748: if ($oldsec ne '-1') {
13749: if ($oldsec ne $sec) {
1.443 albertel 13750: $secchange = 1;
1.628 raeburn 13751: my $now = time;
1.443 albertel 13752: my $uurl='/'.$cid;
13753: $uurl=~s/\_/\//g;
13754: if ($oldsec) {
13755: $uurl.='/'.$oldsec;
13756: }
1.626 raeburn 13757: $oldsecurl = $uurl;
1.628 raeburn 13758: $expire_role_result =
1.652 raeburn 13759: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13760: if ($env{'request.course.sec'} ne '') {
13761: if ($expire_role_result eq 'refused') {
13762: my @roles = ('st');
13763: my @statuses = ('previous');
13764: my @roledoms = ($one);
13765: my $withsec = 1;
13766: my %roleshash =
13767: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13768: \@statuses,\@roles,\@roledoms,$withsec);
13769: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13770: my ($oldstart,$oldend) =
13771: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13772: if ($oldend > 0 && $oldend <= $now) {
13773: $expire_role_result = 'ok';
13774: }
13775: }
13776: }
13777: }
1.443 albertel 13778: $result = $expire_role_result;
13779: }
13780: }
13781: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 13782: $modify_section_result =
13783: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13784: undef,undef,undef,$sec,
13785: $end,$start,'','',$cid,
13786: '',$context,$credits);
1.443 albertel 13787: if ($modify_section_result =~ /^ok/) {
13788: if ($secchange == 1) {
1.628 raeburn 13789: if ($sec eq '') {
13790: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13791: } else {
13792: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13793: }
1.443 albertel 13794: } elsif ($oldsec eq '-1') {
1.628 raeburn 13795: if ($sec eq '') {
13796: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13797: } else {
13798: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13799: }
1.443 albertel 13800: } else {
1.628 raeburn 13801: if ($sec eq '') {
13802: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13803: } else {
13804: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13805: }
1.443 albertel 13806: }
13807: } else {
1.628 raeburn 13808: if ($secchange) {
13809: $$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;
13810: } else {
13811: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13812: }
1.443 albertel 13813: }
13814: $result = $modify_section_result;
13815: } elsif ($secchange == 1) {
1.628 raeburn 13816: if ($oldsec eq '') {
1.1075.2.20 raeburn 13817: $$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 13818: } else {
13819: $$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;
13820: }
1.626 raeburn 13821: if ($expire_role_result eq 'refused') {
13822: my $newsecurl = '/'.$cid;
13823: $newsecurl =~ s/\_/\//g;
13824: if ($sec ne '') {
13825: $newsecurl.='/'.$sec;
13826: }
13827: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13828: if ($sec eq '') {
13829: $$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;
13830: } else {
13831: $$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;
13832: }
13833: }
13834: }
1.443 albertel 13835: }
13836: } else {
1.626 raeburn 13837: $$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 13838: $result = "error: incomplete course id\n";
13839: }
13840: return $result;
13841: }
13842:
1.1075.2.25 raeburn 13843: sub show_role_extent {
13844: my ($scope,$context,$role) = @_;
13845: $scope =~ s{^/}{};
13846: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13847: push(@courseroles,'co');
13848: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13849: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13850: $scope =~ s{/}{_};
13851: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13852: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13853: my ($audom,$auname) = split(/\//,$scope);
13854: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13855: &Apache::loncommon::plainname($auname,$audom).'</span>');
13856: } else {
13857: $scope =~ s{/$}{};
13858: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13859: &Apache::lonnet::domain($scope,'description').'</span>');
13860: }
13861: }
13862:
1.443 albertel 13863: ############################################################
13864: ############################################################
13865:
1.566 albertel 13866: sub check_clone {
1.578 raeburn 13867: my ($args,$linefeed) = @_;
1.566 albertel 13868: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13869: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13870: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13871: my $clonemsg;
13872: my $can_clone = 0;
1.944 raeburn 13873: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13874: if ($lctype ne 'community') {
13875: $lctype = 'course';
13876: }
1.566 albertel 13877: if ($clonehome eq 'no_host') {
1.944 raeburn 13878: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13879: $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'});
13880: } else {
13881: $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'});
13882: }
1.566 albertel 13883: } else {
13884: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13885: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13886: if ($clonedesc{'type'} ne 'Community') {
13887: $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'});
13888: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13889: }
13890: }
1.882 raeburn 13891: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13892: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13893: $can_clone = 1;
13894: } else {
13895: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13896: $args->{'clonedomain'},$args->{'clonecourse'});
13897: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13898: if (grep(/^\*$/,@cloners)) {
13899: $can_clone = 1;
13900: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13901: $can_clone = 1;
13902: } else {
1.908 raeburn 13903: my $ccrole = 'cc';
1.944 raeburn 13904: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13905: $ccrole = 'co';
13906: }
1.578 raeburn 13907: my %roleshash =
13908: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13909: $args->{'ccdomain'},
1.908 raeburn 13910: 'userroles',['active'],[$ccrole],
1.578 raeburn 13911: [$args->{'clonedomain'}]);
1.908 raeburn 13912: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13913: $can_clone = 1;
13914: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13915: $can_clone = 1;
13916: } else {
1.944 raeburn 13917: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13918: $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'});
13919: } else {
13920: $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'});
13921: }
1.578 raeburn 13922: }
1.566 albertel 13923: }
1.578 raeburn 13924: }
1.566 albertel 13925: }
13926: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13927: }
13928:
1.444 albertel 13929: sub construct_course {
1.1075.2.59 raeburn 13930: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 13931: my $outcome;
1.541 raeburn 13932: my $linefeed = '<br />'."\n";
13933: if ($context eq 'auto') {
13934: $linefeed = "\n";
13935: }
1.566 albertel 13936:
13937: #
13938: # Are we cloning?
13939: #
13940: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13941: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13942: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13943: if ($context ne 'auto') {
1.578 raeburn 13944: if ($clonemsg ne '') {
13945: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13946: }
1.566 albertel 13947: }
13948: $outcome .= $clonemsg.$linefeed;
13949:
13950: if (!$can_clone) {
13951: return (0,$outcome);
13952: }
13953: }
13954:
1.444 albertel 13955: #
13956: # Open course
13957: #
13958: my $crstype = lc($args->{'crstype'});
13959: my %cenv=();
13960: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13961: $args->{'cdescr'},
13962: $args->{'curl'},
13963: $args->{'course_home'},
13964: $args->{'nonstandard'},
13965: $args->{'crscode'},
13966: $args->{'ccuname'}.':'.
13967: $args->{'ccdomain'},
1.882 raeburn 13968: $args->{'crstype'},
1.885 raeburn 13969: $cnum,$context,$category);
1.444 albertel 13970:
13971: # Note: The testing routines depend on this being output; see
13972: # Utils::Course. This needs to at least be output as a comment
13973: # if anyone ever decides to not show this, and Utils::Course::new
13974: # will need to be suitably modified.
1.541 raeburn 13975: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13976: if ($$courseid =~ /^error:/) {
13977: return (0,$outcome);
13978: }
13979:
1.444 albertel 13980: #
13981: # Check if created correctly
13982: #
1.479 albertel 13983: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13984: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13985: if ($crsuhome eq 'no_host') {
13986: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13987: return (0,$outcome);
13988: }
1.541 raeburn 13989: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13990:
1.444 albertel 13991: #
1.566 albertel 13992: # Do the cloning
13993: #
13994: if ($can_clone && $cloneid) {
13995: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13996: if ($context ne 'auto') {
13997: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13998: }
13999: $outcome .= $clonemsg.$linefeed;
14000: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14001: # Copy all files
1.637 www 14002: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14003: # Restore URL
1.566 albertel 14004: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14005: # Restore title
1.566 albertel 14006: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14007: # Restore creation date, creator and creation context.
14008: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14009: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14010: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14011: # Mark as cloned
1.566 albertel 14012: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14013: # Need to clone grading mode
14014: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14015: $cenv{'grading'}=$newenv{'grading'};
14016: # Do not clone these environment entries
14017: &Apache::lonnet::del('environment',
14018: ['default_enrollment_start_date',
14019: 'default_enrollment_end_date',
14020: 'question.email',
14021: 'policy.email',
14022: 'comment.email',
14023: 'pch.users.denied',
1.725 raeburn 14024: 'plc.users.denied',
14025: 'hidefromcat',
1.1075.2.36 raeburn 14026: 'checkforpriv',
1.1075.2.59 raeburn 14027: 'categories',
14028: 'internal.uniquecode'],
1.638 www 14029: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 14030: if ($args->{'textbook'}) {
14031: $cenv{'internal.textbook'} = $args->{'textbook'};
14032: }
1.444 albertel 14033: }
1.566 albertel 14034:
1.444 albertel 14035: #
14036: # Set environment (will override cloned, if existing)
14037: #
14038: my @sections = ();
14039: my @xlists = ();
14040: if ($args->{'crstype'}) {
14041: $cenv{'type'}=$args->{'crstype'};
14042: }
14043: if ($args->{'crsid'}) {
14044: $cenv{'courseid'}=$args->{'crsid'};
14045: }
14046: if ($args->{'crscode'}) {
14047: $cenv{'internal.coursecode'}=$args->{'crscode'};
14048: }
14049: if ($args->{'crsquota'} ne '') {
14050: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14051: } else {
14052: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14053: }
14054: if ($args->{'ccuname'}) {
14055: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14056: ':'.$args->{'ccdomain'};
14057: } else {
14058: $cenv{'internal.courseowner'} = $args->{'curruser'};
14059: }
1.1075.2.31 raeburn 14060: if ($args->{'defaultcredits'}) {
14061: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14062: }
1.444 albertel 14063: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14064: if ($args->{'crssections'}) {
14065: $cenv{'internal.sectionnums'} = '';
14066: if ($args->{'crssections'} =~ m/,/) {
14067: @sections = split/,/,$args->{'crssections'};
14068: } else {
14069: $sections[0] = $args->{'crssections'};
14070: }
14071: if (@sections > 0) {
14072: foreach my $item (@sections) {
14073: my ($sec,$gp) = split/:/,$item;
14074: my $class = $args->{'crscode'}.$sec;
14075: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14076: $cenv{'internal.sectionnums'} .= $item.',';
14077: unless ($addcheck eq 'ok') {
14078: push @badclasses, $class;
14079: }
14080: }
14081: $cenv{'internal.sectionnums'} =~ s/,$//;
14082: }
14083: }
14084: # do not hide course coordinator from staff listing,
14085: # even if privileged
14086: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 14087: # add course coordinator's domain to domains to check for privileged users
14088: # if different to course domain
14089: if ($$crsudom ne $args->{'ccdomain'}) {
14090: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14091: }
1.444 albertel 14092: # add crosslistings
14093: if ($args->{'crsxlist'}) {
14094: $cenv{'internal.crosslistings'}='';
14095: if ($args->{'crsxlist'} =~ m/,/) {
14096: @xlists = split/,/,$args->{'crsxlist'};
14097: } else {
14098: $xlists[0] = $args->{'crsxlist'};
14099: }
14100: if (@xlists > 0) {
14101: foreach my $item (@xlists) {
14102: my ($xl,$gp) = split/:/,$item;
14103: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14104: $cenv{'internal.crosslistings'} .= $item.',';
14105: unless ($addcheck eq 'ok') {
14106: push @badclasses, $xl;
14107: }
14108: }
14109: $cenv{'internal.crosslistings'} =~ s/,$//;
14110: }
14111: }
14112: if ($args->{'autoadds'}) {
14113: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14114: }
14115: if ($args->{'autodrops'}) {
14116: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14117: }
14118: # check for notification of enrollment changes
14119: my @notified = ();
14120: if ($args->{'notify_owner'}) {
14121: if ($args->{'ccuname'} ne '') {
14122: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14123: }
14124: }
14125: if ($args->{'notify_dc'}) {
14126: if ($uname ne '') {
1.630 raeburn 14127: push(@notified,$uname.':'.$udom);
1.444 albertel 14128: }
14129: }
14130: if (@notified > 0) {
14131: my $notifylist;
14132: if (@notified > 1) {
14133: $notifylist = join(',',@notified);
14134: } else {
14135: $notifylist = $notified[0];
14136: }
14137: $cenv{'internal.notifylist'} = $notifylist;
14138: }
14139: if (@badclasses > 0) {
14140: my %lt=&Apache::lonlocal::texthash(
14141: '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',
14142: 'dnhr' => 'does not have rights to access enrollment in these classes',
14143: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14144: );
1.541 raeburn 14145: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14146: ' ('.$lt{'adby'}.')';
14147: if ($context eq 'auto') {
14148: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14149: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14150: foreach my $item (@badclasses) {
14151: if ($context eq 'auto') {
14152: $outcome .= " - $item\n";
14153: } else {
14154: $outcome .= "<li>$item</li>\n";
14155: }
14156: }
14157: if ($context eq 'auto') {
14158: $outcome .= $linefeed;
14159: } else {
1.566 albertel 14160: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14161: }
14162: }
1.444 albertel 14163: }
14164: if ($args->{'no_end_date'}) {
14165: $args->{'endaccess'} = 0;
14166: }
14167: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14168: $cenv{'internal.autoend'}=$args->{'enrollend'};
14169: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14170: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14171: if ($args->{'showphotos'}) {
14172: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14173: }
14174: $cenv{'internal.authtype'} = $args->{'authtype'};
14175: $cenv{'internal.autharg'} = $args->{'autharg'};
14176: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14177: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14178: 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');
14179: if ($context eq 'auto') {
14180: $outcome .= $krb_msg;
14181: } else {
1.566 albertel 14182: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14183: }
14184: $outcome .= $linefeed;
1.444 albertel 14185: }
14186: }
14187: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14188: if ($args->{'setpolicy'}) {
14189: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14190: }
14191: if ($args->{'setcontent'}) {
14192: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14193: }
14194: }
14195: if ($args->{'reshome'}) {
14196: $cenv{'reshome'}=$args->{'reshome'}.'/';
14197: $cenv{'reshome'}=~s/\/+$/\//;
14198: }
14199: #
14200: # course has keyed access
14201: #
14202: if ($args->{'setkeys'}) {
14203: $cenv{'keyaccess'}='yes';
14204: }
14205: # if specified, key authority is not course, but user
14206: # only active if keyaccess is yes
14207: if ($args->{'keyauth'}) {
1.487 albertel 14208: my ($user,$domain) = split(':',$args->{'keyauth'});
14209: $user = &LONCAPA::clean_username($user);
14210: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14211: if ($user ne '' && $domain ne '') {
1.487 albertel 14212: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14213: }
14214: }
14215:
1.1075.2.59 raeburn 14216: #
14217: # generate and store uniquecode (available to course requester), if course should have one.
14218: #
14219: if ($args->{'uniquecode'}) {
14220: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14221: if ($code) {
14222: $cenv{'internal.uniquecode'} = $code;
14223: my %crsinfo =
14224: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
14225: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
14226: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
14227: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
14228: }
14229: if (ref($coderef)) {
14230: $$coderef = $code;
14231: }
14232: }
14233: }
14234:
1.444 albertel 14235: if ($args->{'disresdis'}) {
14236: $cenv{'pch.roles.denied'}='st';
14237: }
14238: if ($args->{'disablechat'}) {
14239: $cenv{'plc.roles.denied'}='st';
14240: }
14241:
14242: # Record we've not yet viewed the Course Initialization Helper for this
14243: # course
14244: $cenv{'course.helper.not.run'} = 1;
14245: #
14246: # Use new Randomseed
14247: #
14248: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14249: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14250: #
14251: # The encryption code and receipt prefix for this course
14252: #
14253: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14254: $cenv{'internal.encpref'}=100+int(9*rand(99));
14255: #
14256: # By default, use standard grading
14257: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14258:
1.541 raeburn 14259: $outcome .= $linefeed.&mt('Setting environment').': '.
14260: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14261: #
14262: # Open all assignments
14263: #
14264: if ($args->{'openall'}) {
14265: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14266: my %storecontent = ($storeunder => time,
14267: $storeunder.'.type' => 'date_start');
14268:
14269: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14270: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14271: }
14272: #
14273: # Set first page
14274: #
14275: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14276: || ($cloneid)) {
1.445 albertel 14277: use LONCAPA::map;
1.444 albertel 14278: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14279:
14280: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14281: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14282:
1.444 albertel 14283: $outcome .= ($fatal?$errtext:'read ok').' - ';
14284: my $title; my $url;
14285: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14286: $title=&mt('Syllabus');
1.444 albertel 14287: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14288: } else {
1.963 raeburn 14289: $title=&mt('Table of Contents');
1.444 albertel 14290: $url='/adm/navmaps';
14291: }
1.445 albertel 14292:
14293: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14294: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14295:
14296: if ($errtext) { $fatal=2; }
1.541 raeburn 14297: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14298: }
1.566 albertel 14299:
14300: return (1,$outcome);
1.444 albertel 14301: }
14302:
1.1075.2.59 raeburn 14303: sub make_unique_code {
14304: my ($cdom,$cnum) = @_;
14305: # get lock on uniquecodes db
14306: my $lockhash = {
14307: $cnum."\0".'uniquecodes' => $env{'user.name'}.
14308: ':'.$env{'user.domain'},
14309: };
14310: my $tries = 0;
14311: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14312: my ($code,$error);
14313:
14314: while (($gotlock ne 'ok') && ($tries<3)) {
14315: $tries ++;
14316: sleep 1;
14317: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14318: }
14319: if ($gotlock eq 'ok') {
14320: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
14321: my $gotcode;
14322: my $attempts = 0;
14323: while ((!$gotcode) && ($attempts < 100)) {
14324: $code = &generate_code();
14325: if (!exists($currcodes{$code})) {
14326: $gotcode = 1;
14327: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
14328: $error = 'nostore';
14329: }
14330: }
14331: $attempts ++;
14332: }
14333: my @del_lock = ($cnum."\0".'uniquecodes');
14334: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
14335: } else {
14336: $error = 'nolock';
14337: }
14338: return ($code,$error);
14339: }
14340:
14341: sub generate_code {
14342: my $code;
14343: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
14344: for (my $i=0; $i<6; $i++) {
14345: my $lettnum = int (rand 2);
14346: my $item = '';
14347: if ($lettnum) {
14348: $item = $letts[int( rand(18) )];
14349: } else {
14350: $item = 1+int( rand(8) );
14351: }
14352: $code .= $item;
14353: }
14354: return $code;
14355: }
14356:
1.444 albertel 14357: ############################################################
14358: ############################################################
14359:
1.953 droeschl 14360: #SD
14361: # only Community and Course, or anything else?
1.378 raeburn 14362: sub course_type {
14363: my ($cid) = @_;
14364: if (!defined($cid)) {
14365: $cid = $env{'request.course.id'};
14366: }
1.404 albertel 14367: if (defined($env{'course.'.$cid.'.type'})) {
14368: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14369: } else {
14370: return 'Course';
1.377 raeburn 14371: }
14372: }
1.156 albertel 14373:
1.406 raeburn 14374: sub group_term {
14375: my $crstype = &course_type();
14376: my %names = (
14377: 'Course' => 'group',
1.865 raeburn 14378: 'Community' => 'group',
1.406 raeburn 14379: );
14380: return $names{$crstype};
14381: }
14382:
1.902 raeburn 14383: sub course_types {
1.1075.2.59 raeburn 14384: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 14385: my %typename = (
14386: official => 'Official course',
14387: unofficial => 'Unofficial course',
14388: community => 'Community',
1.1075.2.59 raeburn 14389: textbook => 'Textbook course',
1.902 raeburn 14390: );
14391: return (\@types,\%typename);
14392: }
14393:
1.156 albertel 14394: sub icon {
14395: my ($file)=@_;
1.505 albertel 14396: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14397: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14398: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14399: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14400: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14401: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14402: $curfext.".gif") {
14403: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14404: $curfext.".gif";
14405: }
14406: }
1.249 albertel 14407: return &lonhttpdurl($iconname);
1.154 albertel 14408: }
1.84 albertel 14409:
1.575 albertel 14410: sub lonhttpdurl {
1.692 www 14411: #
14412: # Had been used for "small fry" static images on separate port 8080.
14413: # Modify here if lightweight http functionality desired again.
14414: # Currently eliminated due to increasing firewall issues.
14415: #
1.575 albertel 14416: my ($url)=@_;
1.692 www 14417: return $url;
1.215 albertel 14418: }
14419:
1.213 albertel 14420: sub connection_aborted {
14421: my ($r)=@_;
14422: $r->print(" ");$r->rflush();
14423: my $c = $r->connection;
14424: return $c->aborted();
14425: }
14426:
1.221 foxr 14427: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14428: # strings as 'strings'.
14429: sub escape_single {
1.221 foxr 14430: my ($input) = @_;
1.223 albertel 14431: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14432: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14433: return $input;
14434: }
1.223 albertel 14435:
1.222 foxr 14436: # Same as escape_single, but escape's "'s This
14437: # can be used for "strings"
14438: sub escape_double {
14439: my ($input) = @_;
14440: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14441: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14442: return $input;
14443: }
1.223 albertel 14444:
1.222 foxr 14445: # Escapes the last element of a full URL.
14446: sub escape_url {
14447: my ($url) = @_;
1.238 raeburn 14448: my @urlslices = split(/\//, $url,-1);
1.369 www 14449: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14450: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14451: }
1.462 albertel 14452:
1.820 raeburn 14453: sub compare_arrays {
14454: my ($arrayref1,$arrayref2) = @_;
14455: my (@difference,%count);
14456: @difference = ();
14457: %count = ();
14458: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14459: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14460: foreach my $element (keys(%count)) {
14461: if ($count{$element} == 1) {
14462: push(@difference,$element);
14463: }
14464: }
14465: }
14466: return @difference;
14467: }
14468:
1.817 bisitz 14469: # -------------------------------------------------------- Initialize user login
1.462 albertel 14470: sub init_user_environment {
1.463 albertel 14471: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14472: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14473:
14474: my $public=($username eq 'public' && $domain eq 'public');
14475:
14476: # See if old ID present, if so, remove
14477:
1.1062 raeburn 14478: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14479: my $now=time;
14480:
14481: if ($public) {
14482: my $max_public=100;
14483: my $oldest;
14484: my $oldest_time=0;
14485: for(my $next=1;$next<=$max_public;$next++) {
14486: if (-e $lonids."/publicuser_$next.id") {
14487: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14488: if ($mtime<$oldest_time || !$oldest_time) {
14489: $oldest_time=$mtime;
14490: $oldest=$next;
14491: }
14492: } else {
14493: $cookie="publicuser_$next";
14494: last;
14495: }
14496: }
14497: if (!$cookie) { $cookie="publicuser_$oldest"; }
14498: } else {
1.463 albertel 14499: # if this isn't a robot, kill any existing non-robot sessions
14500: if (!$args->{'robot'}) {
14501: opendir(DIR,$lonids);
14502: while ($filename=readdir(DIR)) {
14503: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14504: unlink($lonids.'/'.$filename);
14505: }
1.462 albertel 14506: }
1.463 albertel 14507: closedir(DIR);
1.462 albertel 14508: }
14509: # Give them a new cookie
1.463 albertel 14510: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14511: : $now.$$.int(rand(10000)));
1.463 albertel 14512: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14513:
14514: # Initialize roles
14515:
1.1062 raeburn 14516: ($userroles,$firstaccenv,$timerintenv) =
14517: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14518: }
14519: # ------------------------------------ Check browser type and MathML capability
14520:
14521: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.42 raeburn 14522: $clientunicode,$clientos,$clientmobile,$clientinfo) = &decode_user_agent($r);
1.462 albertel 14523:
14524: # ------------------------------------------------------------- Get environment
14525:
14526: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14527: my ($tmp) = keys(%userenv);
14528: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14529: } else {
14530: undef(%userenv);
14531: }
14532: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14533: $form->{'interface'}=$userenv{'interface'};
14534: }
14535: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14536:
14537: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14538: foreach my $option ('interface','localpath','localres') {
14539: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14540: }
14541: # --------------------------------------------------------- Write first profile
14542:
14543: {
14544: my %initial_env =
14545: ("user.name" => $username,
14546: "user.domain" => $domain,
14547: "user.home" => $authhost,
14548: "browser.type" => $clientbrowser,
14549: "browser.version" => $clientversion,
14550: "browser.mathml" => $clientmathml,
14551: "browser.unicode" => $clientunicode,
14552: "browser.os" => $clientos,
1.1075.2.42 raeburn 14553: "browser.mobile" => $clientmobile,
14554: "browser.info" => $clientinfo,
1.462 albertel 14555: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14556: "request.course.fn" => '',
14557: "request.course.uri" => '',
14558: "request.course.sec" => '',
14559: "request.role" => 'cm',
14560: "request.role.adv" => $env{'user.adv'},
14561: "request.host" => $ENV{'REMOTE_ADDR'},);
14562:
14563: if ($form->{'localpath'}) {
14564: $initial_env{"browser.localpath"} = $form->{'localpath'};
14565: $initial_env{"browser.localres"} = $form->{'localres'};
14566: }
14567:
14568: if ($form->{'interface'}) {
14569: $form->{'interface'}=~s/\W//gs;
14570: $initial_env{"browser.interface"} = $form->{'interface'};
14571: $env{'browser.interface'}=$form->{'interface'};
14572: }
14573:
1.1075.2.54 raeburn 14574: if ($form->{'iptoken'}) {
14575: my $lonhost = $r->dir_config('lonHostID');
14576: $initial_env{"user.noloadbalance"} = $lonhost;
14577: $env{'user.noloadbalance'} = $lonhost;
14578: }
14579:
1.981 raeburn 14580: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14581: my %domdef;
14582: unless ($domain eq 'public') {
14583: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14584: }
1.980 raeburn 14585:
1.1075.2.7 raeburn 14586: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14587: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14588: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14589: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14590: }
14591:
1.1075.2.59 raeburn 14592: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 14593: $userenv{'canrequest.'.$crstype} =
14594: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14595: 'reload','requestcourses',
14596: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14597: }
14598:
1.1075.2.14 raeburn 14599: $userenv{'canrequest.author'} =
14600: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14601: 'reload','requestauthor',
14602: \%userenv,\%domdef,\%is_adv);
14603: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14604: $domain,$username);
14605: my $reqstatus = $reqauthor{'author_status'};
14606: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14607: if (ref($reqauthor{'author'}) eq 'HASH') {
14608: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14609: $reqauthor{'author'}{'timestamp'};
14610: }
14611: }
14612:
1.462 albertel 14613: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14614:
1.462 albertel 14615: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14616: &GDBM_WRCREAT(),0640)) {
14617: &_add_to_env(\%disk_env,\%initial_env);
14618: &_add_to_env(\%disk_env,\%userenv,'environment.');
14619: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14620: if (ref($firstaccenv) eq 'HASH') {
14621: &_add_to_env(\%disk_env,$firstaccenv);
14622: }
14623: if (ref($timerintenv) eq 'HASH') {
14624: &_add_to_env(\%disk_env,$timerintenv);
14625: }
1.463 albertel 14626: if (ref($args->{'extra_env'})) {
14627: &_add_to_env(\%disk_env,$args->{'extra_env'});
14628: }
1.462 albertel 14629: untie(%disk_env);
14630: } else {
1.705 tempelho 14631: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14632: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14633: return 'error: '.$!;
14634: }
14635: }
14636: $env{'request.role'}='cm';
14637: $env{'request.role.adv'}=$env{'user.adv'};
14638: $env{'browser.type'}=$clientbrowser;
14639:
14640: return $cookie;
14641:
14642: }
14643:
14644: sub _add_to_env {
14645: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14646: if (ref($env_data) eq 'HASH') {
14647: while (my ($key,$value) = each(%$env_data)) {
14648: $idf->{$prefix.$key} = $value;
14649: $env{$prefix.$key} = $value;
14650: }
1.462 albertel 14651: }
14652: }
14653:
1.685 tempelho 14654: # --- Get the symbolic name of a problem and the url
14655: sub get_symb {
14656: my ($request,$silent) = @_;
1.726 raeburn 14657: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14658: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14659: if ($symb eq '') {
14660: if (!$silent) {
1.1071 raeburn 14661: if (ref($request)) {
14662: $request->print("Unable to handle ambiguous references:$url:.");
14663: }
1.685 tempelho 14664: return ();
14665: }
14666: }
14667: &Apache::lonenc::check_decrypt(\$symb);
14668: return ($symb);
14669: }
14670:
14671: # --------------------------------------------------------------Get annotation
14672:
14673: sub get_annotation {
14674: my ($symb,$enc) = @_;
14675:
14676: my $key = $symb;
14677: if (!$enc) {
14678: $key =
14679: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14680: }
14681: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14682: return $annotation{$key};
14683: }
14684:
14685: sub clean_symb {
1.731 raeburn 14686: my ($symb,$delete_enc) = @_;
1.685 tempelho 14687:
14688: &Apache::lonenc::check_decrypt(\$symb);
14689: my $enc = $env{'request.enc'};
1.731 raeburn 14690: if ($delete_enc) {
1.730 raeburn 14691: delete($env{'request.enc'});
14692: }
1.685 tempelho 14693:
14694: return ($symb,$enc);
14695: }
1.462 albertel 14696:
1.1075.2.69 raeburn 14697: ############################################################
14698: ############################################################
14699:
14700: =pod
14701:
14702: =head1 Routines for building display used to search for courses
14703:
14704:
14705: =over 4
14706:
14707: =item * &build_filters()
14708:
14709: Create markup for a table used to set filters to use when selecting
14710: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
14711: and quotacheck.pl
14712:
14713:
14714: Inputs:
14715:
14716: filterlist - anonymous array of fields to include as potential filters
14717:
14718: crstype - course type
14719:
14720: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
14721: to pop-open a course selector (will contain "extra element").
14722:
14723: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
14724:
14725: filter - anonymous hash of criteria and their values
14726:
14727: action - form action
14728:
14729: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
14730:
14731: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
14732:
14733: cloneruname - username of owner of new course who wants to clone
14734:
14735: clonerudom - domain of owner of new course who wants to clone
14736:
14737: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
14738:
14739: codetitlesref - reference to array of titles of components in institutional codes (official courses)
14740:
14741: codedom - domain
14742:
14743: formname - value of form element named "form".
14744:
14745: fixeddom - domain, if fixed.
14746:
14747: prevphase - value to assign to form element named "phase" when going back to the previous screen
14748:
14749: cnameelement - name of form element in form on opener page which will receive title of selected course
14750:
14751: cnumelement - name of form element in form on opener page which will receive courseID of selected course
14752:
14753: cdomelement - name of form element in form on opener page which will receive domain of selected course
14754:
14755: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
14756:
14757: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
14758:
14759: clonewarning - warning message about missing information for intended course owner when DC creates a course
14760:
14761:
14762: Returns: $output - HTML for display of search criteria, and hidden form elements.
14763:
14764:
14765: Side Effects: None
14766:
14767: =cut
14768:
14769: # ---------------------------------------------- search for courses based on last activity etc.
14770:
14771: sub build_filters {
14772: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
14773: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
14774: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
14775: $cnameelement,$cnumelement,$cdomelement,$setroles,
14776: $clonetext,$clonewarning) = @_;
14777: my ($list,$jscript);
14778: my $onchange = 'javascript:updateFilters(this)';
14779: my ($domainselectform,$sincefilterform,$createdfilterform,
14780: $ownerdomselectform,$persondomselectform,$instcodeform,
14781: $typeselectform,$instcodetitle);
14782: if ($formname eq '') {
14783: $formname = $caller;
14784: }
14785: foreach my $item (@{$filterlist}) {
14786: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
14787: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
14788: if ($item eq 'domainfilter') {
14789: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
14790: } elsif ($item eq 'coursefilter') {
14791: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
14792: } elsif ($item eq 'ownerfilter') {
14793: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
14794: } elsif ($item eq 'ownerdomfilter') {
14795: $filter->{'ownerdomfilter'} =
14796: &LONCAPA::clean_domain($filter->{$item});
14797: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
14798: 'ownerdomfilter',1);
14799: } elsif ($item eq 'personfilter') {
14800: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
14801: } elsif ($item eq 'persondomfilter') {
14802: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
14803: 'persondomfilter',1);
14804: } else {
14805: $filter->{$item} =~ s/\W//g;
14806: }
14807: if (!$filter->{$item}) {
14808: $filter->{$item} = '';
14809: }
14810: }
14811: if ($item eq 'domainfilter') {
14812: my $allow_blank = 1;
14813: if ($formname eq 'portform') {
14814: $allow_blank=0;
14815: } elsif ($formname eq 'studentform') {
14816: $allow_blank=0;
14817: }
14818: if ($fixeddom) {
14819: $domainselectform = '<input type="hidden" name="domainfilter"'.
14820: ' value="'.$codedom.'" />'.
14821: &Apache::lonnet::domain($codedom,'description');
14822: } else {
14823: $domainselectform = &select_dom_form($filter->{$item},
14824: 'domainfilter',
14825: $allow_blank,'',$onchange);
14826: }
14827: } else {
14828: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
14829: }
14830: }
14831:
14832: # last course activity filter and selection
14833: $sincefilterform = &timebased_select_form('sincefilter',$filter);
14834:
14835: # course created filter and selection
14836: if (exists($filter->{'createdfilter'})) {
14837: $createdfilterform = &timebased_select_form('createdfilter',$filter);
14838: }
14839:
14840: my %lt = &Apache::lonlocal::texthash(
14841: 'cac' => "$crstype Activity",
14842: 'ccr' => "$crstype Created",
14843: 'cde' => "$crstype Title",
14844: 'cdo' => "$crstype Domain",
14845: 'ins' => 'Institutional Code',
14846: 'inc' => 'Institutional Categorization',
14847: 'cow' => "$crstype Owner/Co-owner",
14848: 'cop' => "$crstype Personnel Includes",
14849: 'cog' => 'Type',
14850: );
14851:
14852: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
14853: my $typeval = 'Course';
14854: if ($crstype eq 'Community') {
14855: $typeval = 'Community';
14856: }
14857: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
14858: } else {
14859: $typeselectform = '<select name="type" size="1"';
14860: if ($onchange) {
14861: $typeselectform .= ' onchange="'.$onchange.'"';
14862: }
14863: $typeselectform .= '>'."\n";
14864: foreach my $posstype ('Course','Community') {
14865: $typeselectform.='<option value="'.$posstype.'"'.
14866: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
14867: }
14868: $typeselectform.="</select>";
14869: }
14870:
14871: my ($cloneableonlyform,$cloneabletitle);
14872: if (exists($filter->{'cloneableonly'})) {
14873: my $cloneableon = '';
14874: my $cloneableoff = ' checked="checked"';
14875: if ($filter->{'cloneableonly'}) {
14876: $cloneableon = $cloneableoff;
14877: $cloneableoff = '';
14878: }
14879: $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>';
14880: if ($formname eq 'ccrs') {
1.1075.2.71! raeburn 14881: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 14882: } else {
14883: $cloneabletitle = &mt('Cloneable by you');
14884: }
14885: }
14886: my $officialjs;
14887: if ($crstype eq 'Course') {
14888: if (exists($filter->{'instcodefilter'})) {
14889: # if (($fixeddom) || ($formname eq 'requestcrs') ||
14890: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
14891: if ($codedom) {
14892: $officialjs = 1;
14893: ($instcodeform,$jscript,$$numtitlesref) =
14894: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
14895: $officialjs,$codetitlesref);
14896: if ($jscript) {
14897: $jscript = '<script type="text/javascript">'."\n".
14898: '// <![CDATA['."\n".
14899: $jscript."\n".
14900: '// ]]>'."\n".
14901: '</script>'."\n";
14902: }
14903: }
14904: if ($instcodeform eq '') {
14905: $instcodeform =
14906: '<input type="text" name="instcodefilter" size="10" value="'.
14907: $list->{'instcodefilter'}.'" />';
14908: $instcodetitle = $lt{'ins'};
14909: } else {
14910: $instcodetitle = $lt{'inc'};
14911: }
14912: if ($fixeddom) {
14913: $instcodetitle .= '<br />('.$codedom.')';
14914: }
14915: }
14916: }
14917: my $output = qq|
14918: <form method="post" name="filterpicker" action="$action">
14919: <input type="hidden" name="form" value="$formname" />
14920: |;
14921: if ($formname eq 'modifycourse') {
14922: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
14923: '<input type="hidden" name="prevphase" value="'.
14924: $prevphase.'" />'."\n";
14925: } elsif ($formname ne 'quotacheck') {
14926: my $name_input;
14927: if ($cnameelement ne '') {
14928: $name_input = '<input type="hidden" name="cnameelement" value="'.
14929: $cnameelement.'" />';
14930: }
14931: $output .= qq|
14932: <input type="hidden" name="cnumelement" value="$cnumelement" />
14933: <input type="hidden" name="cdomelement" value="$cdomelement" />
14934: $name_input
14935: $roleelement
14936: $multelement
14937: $typeelement
14938: |;
14939: if ($formname eq 'portform') {
14940: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
14941: }
14942: }
14943: if ($fixeddom) {
14944: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
14945: }
14946: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
14947: if ($sincefilterform) {
14948: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
14949: .$sincefilterform
14950: .&Apache::lonhtmlcommon::row_closure();
14951: }
14952: if ($createdfilterform) {
14953: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
14954: .$createdfilterform
14955: .&Apache::lonhtmlcommon::row_closure();
14956: }
14957: if ($domainselectform) {
14958: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
14959: .$domainselectform
14960: .&Apache::lonhtmlcommon::row_closure();
14961: }
14962: if ($typeselectform) {
14963: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
14964: $output .= $typeselectform;
14965: } else {
14966: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
14967: .$typeselectform
14968: .&Apache::lonhtmlcommon::row_closure();
14969: }
14970: }
14971: if ($instcodeform) {
14972: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
14973: .$instcodeform
14974: .&Apache::lonhtmlcommon::row_closure();
14975: }
14976: if (exists($filter->{'ownerfilter'})) {
14977: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
14978: '<table><tr><td>'.&mt('Username').'<br />'.
14979: '<input type="text" name="ownerfilter" size="20" value="'.
14980: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
14981: $ownerdomselectform.'</td></tr></table>'.
14982: &Apache::lonhtmlcommon::row_closure();
14983: }
14984: if (exists($filter->{'personfilter'})) {
14985: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
14986: '<table><tr><td>'.&mt('Username').'<br />'.
14987: '<input type="text" name="personfilter" size="20" value="'.
14988: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
14989: $persondomselectform.'</td></tr></table>'.
14990: &Apache::lonhtmlcommon::row_closure();
14991: }
14992: if (exists($filter->{'coursefilter'})) {
14993: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
14994: .'<input type="text" name="coursefilter" size="25" value="'
14995: .$list->{'coursefilter'}.'" />'
14996: .&Apache::lonhtmlcommon::row_closure();
14997: }
14998: if ($cloneableonlyform) {
14999: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15000: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15001: }
15002: if (exists($filter->{'descriptfilter'})) {
15003: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15004: .'<input type="text" name="descriptfilter" size="40" value="'
15005: .$list->{'descriptfilter'}.'" />'
15006: .&Apache::lonhtmlcommon::row_closure(1);
15007: }
15008: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15009: '<input type="hidden" name="updater" value="" />'."\n".
15010: '<input type="submit" name="gosearch" value="'.
15011: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15012: return $jscript.$clonewarning.$output;
15013: }
15014:
15015: =pod
15016:
15017: =item * &timebased_select_form()
15018:
15019: Create markup for a dropdown list used to select a time-based
15020: filter e.g., Course Activity, Course Created, when searching for courses
15021: or communities
15022:
15023: Inputs:
15024:
15025: item - name of form element (sincefilter or createdfilter)
15026:
15027: filter - anonymous hash of criteria and their values
15028:
15029: Returns: HTML for a select box contained a blank, then six time selections,
15030: with value set in incoming form variables currently selected.
15031:
15032: Side Effects: None
15033:
15034: =cut
15035:
15036: sub timebased_select_form {
15037: my ($item,$filter) = @_;
15038: if (ref($filter) eq 'HASH') {
15039: $filter->{$item} =~ s/[^\d-]//g;
15040: if (!$filter->{$item}) { $filter->{$item}=-1; }
15041: return &select_form(
15042: $filter->{$item},
15043: $item,
15044: { '-1' => '',
15045: '86400' => &mt('today'),
15046: '604800' => &mt('last week'),
15047: '2592000' => &mt('last month'),
15048: '7776000' => &mt('last three months'),
15049: '15552000' => &mt('last six months'),
15050: '31104000' => &mt('last year'),
15051: 'select_form_order' =>
15052: ['-1','86400','604800','2592000','7776000',
15053: '15552000','31104000']});
15054: }
15055: }
15056:
15057: =pod
15058:
15059: =item * &js_changer()
15060:
15061: Create script tag containing Javascript used to submit course search form
15062: when course type or domain is changed, and also to hide 'Searching ...' on
15063: page load completion for page showing search result.
15064:
15065: Inputs: None
15066:
15067: Returns: markup containing updateFilters() and hideSearching() javascript functions.
15068:
15069: Side Effects: None
15070:
15071: =cut
15072:
15073: sub js_changer {
15074: return <<ENDJS;
15075: <script type="text/javascript">
15076: // <![CDATA[
15077: function updateFilters(caller) {
15078: if (typeof(caller) != "undefined") {
15079: document.filterpicker.updater.value = caller.name;
15080: }
15081: document.filterpicker.submit();
15082: }
15083:
15084: function hideSearching() {
15085: if (document.getElementById('searching')) {
15086: document.getElementById('searching').style.display = 'none';
15087: }
15088: return;
15089: }
15090:
15091: // ]]>
15092: </script>
15093:
15094: ENDJS
15095: }
15096:
15097: =pod
15098:
15099: =item * &search_courses()
15100:
15101: Process selected filters form course search form and pass to lonnet::courseiddump
15102: to retrieve a hash for which keys are courseIDs which match the selected filters.
15103:
15104: Inputs:
15105:
15106: dom - domain being searched
15107:
15108: type - course type ('Course' or 'Community' or '.' if any).
15109:
15110: filter - anonymous hash of criteria and their values
15111:
15112: numtitles - for institutional codes - number of categories
15113:
15114: cloneruname - optional username of new course owner
15115:
15116: clonerudom - optional domain of new course owner
15117:
15118: domcloner - Optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
15119: (used when DC is using course creation form)
15120:
15121: codetitles - reference to array of titles of components in institutional codes (official courses).
15122:
15123:
15124: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
15125:
15126:
15127: Side Effects: None
15128:
15129: =cut
15130:
15131:
15132: sub search_courses {
15133: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_;
15134: my (%courses,%showcourses,$cloner);
15135: if (($filter->{'ownerfilter'} ne '') ||
15136: ($filter->{'ownerdomfilter'} ne '')) {
15137: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
15138: $filter->{'ownerdomfilter'};
15139: }
15140: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
15141: if (!$filter->{$item}) {
15142: $filter->{$item}='.';
15143: }
15144: }
15145: my $now = time;
15146: my $timefilter =
15147: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
15148: my ($createdbefore,$createdafter);
15149: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
15150: $createdbefore = $now;
15151: $createdafter = $now-$filter->{'createdfilter'};
15152: }
15153: my ($instcodefilter,$regexpok);
15154: if ($numtitles) {
15155: if ($env{'form.official'} eq 'on') {
15156: $instcodefilter =
15157: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15158: $regexpok = 1;
15159: } elsif ($env{'form.official'} eq 'off') {
15160: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15161: unless ($instcodefilter eq '') {
15162: $regexpok = -1;
15163: }
15164: }
15165: } else {
15166: $instcodefilter = $filter->{'instcodefilter'};
15167: }
15168: if ($instcodefilter eq '') { $instcodefilter = '.'; }
15169: if ($type eq '') { $type = '.'; }
15170:
15171: if (($clonerudom ne '') && ($cloneruname ne '')) {
15172: $cloner = $cloneruname.':'.$clonerudom;
15173: }
15174: %courses = &Apache::lonnet::courseiddump($dom,
15175: $filter->{'descriptfilter'},
15176: $timefilter,
15177: $instcodefilter,
15178: $filter->{'combownerfilter'},
15179: $filter->{'coursefilter'},
15180: undef,undef,$type,$regexpok,undef,undef,
15181: undef,undef,$cloner,$env{'form.cc_clone'},
15182: $filter->{'cloneableonly'},
15183: $createdbefore,$createdafter,undef,
15184: $domcloner);
15185: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
15186: my $ccrole;
15187: if ($type eq 'Community') {
15188: $ccrole = 'co';
15189: } else {
15190: $ccrole = 'cc';
15191: }
15192: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
15193: $filter->{'persondomfilter'},
15194: 'userroles',undef,
15195: [$ccrole,'in','ad','ep','ta','cr'],
15196: $dom);
15197: foreach my $role (keys(%rolehash)) {
15198: my ($cnum,$cdom,$courserole) = split(':',$role);
15199: my $cid = $cdom.'_'.$cnum;
15200: if (exists($courses{$cid})) {
15201: if (ref($courses{$cid}) eq 'HASH') {
15202: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
15203: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
15204: push (@{$courses{$cid}{roles}},$courserole);
15205: }
15206: } else {
15207: $courses{$cid}{roles} = [$courserole];
15208: }
15209: $showcourses{$cid} = $courses{$cid};
15210: }
15211: }
15212: }
15213: %courses = %showcourses;
15214: }
15215: return %courses;
15216: }
15217:
15218:
15219: =pod
15220:
15221: =back
15222:
15223: =cut
15224:
15225:
1.990 raeburn 15226: sub build_release_hashes {
15227: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
15228: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
15229: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
15230: (ref($randomizetry) eq 'HASH'));
15231: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
15232: my ($item,$name,$value) = split(/:/,$key);
15233: if ($item eq 'parameter') {
15234: if (ref($checkparms->{$name}) eq 'ARRAY') {
15235: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
15236: push(@{$checkparms->{$name}},$value);
15237: }
15238: } else {
15239: push(@{$checkparms->{$name}},$value);
15240: }
15241: } elsif ($item eq 'resourcetag') {
15242: if ($name eq 'responsetype') {
15243: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
15244: }
15245: } elsif ($item eq 'course') {
15246: if ($name eq 'crstype') {
15247: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
15248: }
15249: }
15250: }
15251: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
15252: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
15253: return;
15254: }
15255:
1.1075.2.11 raeburn 15256: sub update_content_constraints {
15257: my ($cdom,$cnum,$chome,$cid) = @_;
15258: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15259: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
15260: my %checkresponsetypes;
15261: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
15262: my ($item,$name,$value) = split(/:/,$key);
15263: if ($item eq 'resourcetag') {
15264: if ($name eq 'responsetype') {
15265: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
15266: }
15267: }
15268: }
15269: my $navmap = Apache::lonnavmaps::navmap->new();
15270: if (defined($navmap)) {
15271: my %allresponses;
15272: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
15273: my %responses = $res->responseTypes();
15274: foreach my $key (keys(%responses)) {
15275: next unless(exists($checkresponsetypes{$key}));
15276: $allresponses{$key} += $responses{$key};
15277: }
15278: }
15279: foreach my $key (keys(%allresponses)) {
15280: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
15281: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
15282: ($reqdmajor,$reqdminor) = ($major,$minor);
15283: }
15284: }
15285: undef($navmap);
15286: }
15287: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
15288: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
15289: }
15290: return;
15291: }
15292:
1.1075.2.27 raeburn 15293: sub allmaps_incourse {
15294: my ($cdom,$cnum,$chome,$cid) = @_;
15295: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
15296: $cid = $env{'request.course.id'};
15297: $cdom = $env{'course.'.$cid.'.domain'};
15298: $cnum = $env{'course.'.$cid.'.num'};
15299: $chome = $env{'course.'.$cid.'.home'};
15300: }
15301: my %allmaps = ();
15302: my $lastchange =
15303: &Apache::lonnet::get_coursechange($cdom,$cnum);
15304: if ($lastchange > $env{'request.course.tied'}) {
15305: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
15306: unless ($ferr) {
15307: &update_content_constraints($cdom,$cnum,$chome,$cid);
15308: }
15309: }
15310: my $navmap = Apache::lonnavmaps::navmap->new();
15311: if (defined($navmap)) {
15312: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
15313: $allmaps{$res->src()} = 1;
15314: }
15315: }
15316: return \%allmaps;
15317: }
15318:
1.1075.2.11 raeburn 15319: sub parse_supplemental_title {
15320: my ($title) = @_;
15321:
15322: my ($foldertitle,$renametitle);
15323: if ($title =~ /&&&/) {
15324: $title = &HTML::Entites::decode($title);
15325: }
15326: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
15327: $renametitle=$4;
15328: my ($time,$uname,$udom) = ($1,$2,$3);
15329: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
15330: my $name = &plainname($uname,$udom);
15331: $name = &HTML::Entities::encode($name,'"<>&\'');
15332: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
15333: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
15334: $name.': <br />'.$foldertitle;
15335: }
15336: if (wantarray) {
15337: return ($title,$foldertitle,$renametitle);
15338: }
15339: return $title;
15340: }
15341:
1.1075.2.43 raeburn 15342: sub recurse_supplemental {
15343: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
15344: if ($suppmap) {
15345: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
15346: if ($fatal) {
15347: $errors ++;
15348: } else {
15349: if ($#LONCAPA::map::resources > 0) {
15350: foreach my $res (@LONCAPA::map::resources) {
15351: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
15352: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 15353: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
15354: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 15355: } else {
15356: $numfiles ++;
15357: }
15358: }
15359: }
15360: }
15361: }
15362: }
15363: return ($numfiles,$errors);
15364: }
15365:
1.1075.2.18 raeburn 15366: sub symb_to_docspath {
15367: my ($symb) = @_;
15368: return unless ($symb);
15369: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
15370: if ($resurl=~/\.(sequence|page)$/) {
15371: $mapurl=$resurl;
15372: } elsif ($resurl eq 'adm/navmaps') {
15373: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
15374: }
15375: my $mapresobj;
15376: my $navmap = Apache::lonnavmaps::navmap->new();
15377: if (ref($navmap)) {
15378: $mapresobj = $navmap->getResourceByUrl($mapurl);
15379: }
15380: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
15381: my $type=$2;
15382: my $path;
15383: if (ref($mapresobj)) {
15384: my $pcslist = $mapresobj->map_hierarchy();
15385: if ($pcslist ne '') {
15386: foreach my $pc (split(/,/,$pcslist)) {
15387: next if ($pc <= 1);
15388: my $res = $navmap->getByMapPc($pc);
15389: if (ref($res)) {
15390: my $thisurl = $res->src();
15391: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
15392: my $thistitle = $res->title();
15393: $path .= '&'.
15394: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 15395: &escape($thistitle).
1.1075.2.18 raeburn 15396: ':'.$res->randompick().
15397: ':'.$res->randomout().
15398: ':'.$res->encrypted().
15399: ':'.$res->randomorder().
15400: ':'.$res->is_page();
15401: }
15402: }
15403: }
15404: $path =~ s/^\&//;
15405: my $maptitle = $mapresobj->title();
15406: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 15407: $maptitle = 'Main Content';
1.1075.2.18 raeburn 15408: }
15409: $path .= (($path ne '')? '&' : '').
15410: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 15411: &escape($maptitle).
1.1075.2.18 raeburn 15412: ':'.$mapresobj->randompick().
15413: ':'.$mapresobj->randomout().
15414: ':'.$mapresobj->encrypted().
15415: ':'.$mapresobj->randomorder().
15416: ':'.$mapresobj->is_page();
15417: } else {
15418: my $maptitle = &Apache::lonnet::gettitle($mapurl);
15419: my $ispage = (($type eq 'page')? 1 : '');
15420: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 15421: $maptitle = 'Main Content';
1.1075.2.18 raeburn 15422: }
15423: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 15424: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 15425: }
15426: unless ($mapurl eq 'default') {
15427: $path = 'default&'.
1.1075.2.46 raeburn 15428: &escape('Main Content').
1.1075.2.18 raeburn 15429: ':::::&'.$path;
15430: }
15431: return $path;
15432: }
15433:
1.1075.2.14 raeburn 15434: sub captcha_display {
15435: my ($context,$lonhost) = @_;
15436: my ($output,$error);
15437: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
15438: if ($captcha eq 'original') {
15439: $output = &create_captcha();
15440: unless ($output) {
15441: $error = 'captcha';
15442: }
15443: } elsif ($captcha eq 'recaptcha') {
15444: $output = &create_recaptcha($pubkey);
15445: unless ($output) {
15446: $error = 'recaptcha';
15447: }
15448: }
1.1075.2.66 raeburn 15449: return ($output,$error,$captcha);
1.1075.2.14 raeburn 15450: }
15451:
15452: sub captcha_response {
15453: my ($context,$lonhost) = @_;
15454: my ($captcha_chk,$captcha_error);
15455: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
15456: if ($captcha eq 'original') {
15457: ($captcha_chk,$captcha_error) = &check_captcha();
15458: } elsif ($captcha eq 'recaptcha') {
15459: $captcha_chk = &check_recaptcha($privkey);
15460: } else {
15461: $captcha_chk = 1;
15462: }
15463: return ($captcha_chk,$captcha_error);
15464: }
15465:
15466: sub get_captcha_config {
15467: my ($context,$lonhost) = @_;
15468: my ($captcha,$pubkey,$privkey,$hashtocheck);
15469: my $hostname = &Apache::lonnet::hostname($lonhost);
15470: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
15471: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
15472: if ($context eq 'usercreation') {
15473: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
15474: if (ref($domconfig{$context}) eq 'HASH') {
15475: $hashtocheck = $domconfig{$context}{'cancreate'};
15476: if (ref($hashtocheck) eq 'HASH') {
15477: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
15478: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
15479: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
15480: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
15481: }
15482: if ($privkey && $pubkey) {
15483: $captcha = 'recaptcha';
15484: } else {
15485: $captcha = 'original';
15486: }
15487: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
15488: $captcha = 'original';
15489: }
15490: }
15491: } else {
15492: $captcha = 'captcha';
15493: }
15494: } elsif ($context eq 'login') {
15495: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
15496: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
15497: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
15498: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
15499: if ($privkey && $pubkey) {
15500: $captcha = 'recaptcha';
15501: } else {
15502: $captcha = 'original';
15503: }
15504: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
15505: $captcha = 'original';
15506: }
15507: }
15508: return ($captcha,$pubkey,$privkey);
15509: }
15510:
15511: sub create_captcha {
15512: my %captcha_params = &captcha_settings();
15513: my ($output,$maxtries,$tries) = ('',10,0);
15514: while ($tries < $maxtries) {
15515: $tries ++;
15516: my $captcha = Authen::Captcha->new (
15517: output_folder => $captcha_params{'output_dir'},
15518: data_folder => $captcha_params{'db_dir'},
15519: );
15520: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
15521:
15522: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
15523: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
15524: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 15525: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
15526: '<br />'.
15527: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 15528: last;
15529: }
15530: }
15531: return $output;
15532: }
15533:
15534: sub captcha_settings {
15535: my %captcha_params = (
15536: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
15537: www_output_dir => "/captchaspool",
15538: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
15539: numchars => '5',
15540: );
15541: return %captcha_params;
15542: }
15543:
15544: sub check_captcha {
15545: my ($captcha_chk,$captcha_error);
15546: my $code = $env{'form.code'};
15547: my $md5sum = $env{'form.crypt'};
15548: my %captcha_params = &captcha_settings();
15549: my $captcha = Authen::Captcha->new(
15550: output_folder => $captcha_params{'output_dir'},
15551: data_folder => $captcha_params{'db_dir'},
15552: );
1.1075.2.26 raeburn 15553: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 15554: my %captcha_hash = (
15555: 0 => 'Code not checked (file error)',
15556: -1 => 'Failed: code expired',
15557: -2 => 'Failed: invalid code (not in database)',
15558: -3 => 'Failed: invalid code (code does not match crypt)',
15559: );
15560: if ($captcha_chk != 1) {
15561: $captcha_error = $captcha_hash{$captcha_chk}
15562: }
15563: return ($captcha_chk,$captcha_error);
15564: }
15565:
15566: sub create_recaptcha {
15567: my ($pubkey) = @_;
1.1075.2.51 raeburn 15568: my $use_ssl;
15569: if ($ENV{'SERVER_PORT'} == 443) {
15570: $use_ssl = 1;
15571: }
1.1075.2.14 raeburn 15572: my $captcha = Captcha::reCAPTCHA->new;
15573: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1075.2.51 raeburn 15574: $captcha->get_html($pubkey,undef,$use_ssl).
1.1075.2.14 raeburn 15575: &mt('If either word is hard to read, [_1] will replace them.',
1.1075.2.39 raeburn 15576: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1075.2.14 raeburn 15577: '<br /><br />';
15578: }
15579:
15580: sub check_recaptcha {
15581: my ($privkey) = @_;
15582: my $captcha_chk;
15583: my $captcha = Captcha::reCAPTCHA->new;
15584: my $captcha_result =
15585: $captcha->check_answer(
15586: $privkey,
15587: $ENV{'REMOTE_ADDR'},
15588: $env{'form.recaptcha_challenge_field'},
15589: $env{'form.recaptcha_response_field'},
15590: );
15591: if ($captcha_result->{is_valid}) {
15592: $captcha_chk = 1;
15593: }
15594: return $captcha_chk;
15595: }
15596:
1.1075.2.64 raeburn 15597: sub emailusername_info {
1.1075.2.67 raeburn 15598: my @fields = ('firstname','lastname','institution','web','location','officialemail');
1.1075.2.64 raeburn 15599: my %titles = &Apache::lonlocal::texthash (
15600: lastname => 'Last Name',
15601: firstname => 'First Name',
15602: institution => 'School/college/university',
15603: location => "School's city, state/province, country",
15604: web => "School's web address",
15605: officialemail => 'E-mail address at institution (if different)',
15606: );
15607: return (\@fields,\%titles);
15608: }
15609:
1.1075.2.56 raeburn 15610: sub cleanup_html {
15611: my ($incoming) = @_;
15612: my $outgoing;
15613: if ($incoming ne '') {
15614: $outgoing = $incoming;
15615: $outgoing =~ s/;/;/g;
15616: $outgoing =~ s/\#/#/g;
15617: $outgoing =~ s/\&/&/g;
15618: $outgoing =~ s/</</g;
15619: $outgoing =~ s/>/>/g;
15620: $outgoing =~ s/\(/(/g;
15621: $outgoing =~ s/\)/)/g;
15622: $outgoing =~ s/"/"/g;
15623: $outgoing =~ s/'/'/g;
15624: $outgoing =~ s/\$/$/g;
15625: $outgoing =~ s{/}{/}g;
15626: $outgoing =~ s/=/=/g;
15627: $outgoing =~ s/\\/\/g
15628: }
15629: return $outgoing;
15630: }
15631:
1.1075.2.64 raeburn 15632: # Use:
15633: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
15634: #
15635: ##################################################
15636: # password associated functions #
15637: ##################################################
15638: sub des_keys {
15639: # Make a new key for DES encryption.
15640: # Each key has two parts which are returned separately.
15641: # Please note: Each key must be passed through the &hex function
15642: # before it is output to the web browser. The hex versions cannot
15643: # be used to decrypt.
15644: my @hexstr=('0','1','2','3','4','5','6','7',
15645: '8','9','a','b','c','d','e','f');
15646: my $lkey='';
15647: for (0..7) {
15648: $lkey.=$hexstr[rand(15)];
15649: }
15650: my $ukey='';
15651: for (0..7) {
15652: $ukey.=$hexstr[rand(15)];
15653: }
15654: return ($lkey,$ukey);
15655: }
15656:
15657: sub des_decrypt {
15658: my ($key,$cyphertext) = @_;
15659: my $keybin=pack("H16",$key);
15660: my $cypher;
15661: if ($Crypt::DES::VERSION>=2.03) {
15662: $cypher=new Crypt::DES $keybin;
15663: } else {
15664: $cypher=new DES $keybin;
15665: }
15666: my $plaintext=
15667: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
15668: $plaintext.=
15669: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
15670: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
15671: return $plaintext;
15672: }
15673:
1.112 bowersj2 15674: 1;
15675: __END__;
1.41 ng 15676:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>