Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.72
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.72! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.71 2014/05/04 15:44:46 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.1075.2.72! raeburn 7299: my $inhibitprint;
! 7300: if ($args->{'print_suppress'}) {
! 7301: $inhibitprint = &print_suppression();
! 7302: }
1.1064 raeburn 7303:
1.461 albertel 7304: if (!$args->{'frameset'}) {
7305: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7306: }
1.1075.2.12 raeburn 7307: if ($args->{'force_register'}) {
7308: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7309: }
1.436 albertel 7310: if (!$args->{'no_nav_bar'}
7311: && !$args->{'only_body'}
7312: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7313: $result .= &help_menu_js($httphost);
1.1032 www 7314: $result.=&modal_window();
1.1038 www 7315: $result.=&togglebox_script();
1.1034 www 7316: $result.=&wishlist_window();
1.1041 www 7317: $result.=&LCprogressbarUpdate_script();
1.1034 www 7318: } else {
7319: if ($args->{'add_modal'}) {
7320: $result.=&modal_window();
7321: }
7322: if ($args->{'add_wishlist'}) {
7323: $result.=&wishlist_window();
7324: }
1.1038 www 7325: if ($args->{'add_togglebox'}) {
7326: $result.=&togglebox_script();
7327: }
1.1041 www 7328: if ($args->{'add_progressbar'}) {
7329: $result.=&LCprogressbarUpdate_script();
7330: }
1.436 albertel 7331: }
1.314 albertel 7332: if (ref($args->{'redirect'})) {
1.414 albertel 7333: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7334: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7335: if (!$inhibit_continue) {
7336: $env{'internal.head.redirect'} = $url;
7337: }
1.313 albertel 7338: $result.=<<ADDMETA
7339: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7340: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7341: ADDMETA
7342: }
1.306 albertel 7343: if (!defined($title)) {
7344: $title = 'The LearningOnline Network with CAPA';
7345: }
1.460 albertel 7346: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7347: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7348: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7349: if (!$args->{'frameset'}) {
7350: $result .= ' /';
7351: }
7352: $result .= '>'
1.1064 raeburn 7353: .$inhibitprint
1.414 albertel 7354: .$head_extra;
1.1075.2.42 raeburn 7355: if ($env{'browser.mobile'}) {
7356: $result .= '
7357: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7358: <meta name="apple-mobile-web-app-capable" content="yes" />';
7359: }
1.962 droeschl 7360: return $result.'</head>';
1.306 albertel 7361: }
7362:
7363: =pod
7364:
1.340 albertel 7365: =item * &font_settings()
7366:
7367: Returns neccessary <meta> to set the proper encoding
7368:
1.1075.2.56 raeburn 7369: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7370:
7371: =cut
7372:
7373: sub font_settings {
1.1075.2.56 raeburn 7374: my ($args) = @_;
1.340 albertel 7375: my $headerstring='';
1.1075.2.56 raeburn 7376: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7377: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7378: $headerstring.=
1.1075.2.61 raeburn 7379: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7380: if (!$args->{'frameset'}) {
7381: $headerstring.= ' /';
7382: }
7383: $headerstring .= '>'."\n";
1.340 albertel 7384: }
7385: return $headerstring;
7386: }
7387:
1.341 albertel 7388: =pod
7389:
1.1064 raeburn 7390: =item * &print_suppression()
7391:
7392: In course context returns css which causes the body to be blank when media="print",
7393: if printout generation is unavailable for the current resource.
7394:
7395: This could be because:
7396:
7397: (a) printstartdate is in the future
7398:
7399: (b) printenddate is in the past
7400:
7401: (c) there is an active exam block with "printout"
7402: functionality blocked
7403:
7404: Users with pav, pfo or evb privileges are exempt.
7405:
7406: Inputs: none
7407:
7408: =cut
7409:
7410:
7411: sub print_suppression {
7412: my $noprint;
7413: if ($env{'request.course.id'}) {
7414: my $scope = $env{'request.course.id'};
7415: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7416: (&Apache::lonnet::allowed('pfo',$scope))) {
7417: return;
7418: }
7419: if ($env{'request.course.sec'} ne '') {
7420: $scope .= "/$env{'request.course.sec'}";
7421: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7422: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7423: return;
1.1064 raeburn 7424: }
7425: }
7426: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7427: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7428: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7429: if ($blocked) {
7430: my $checkrole = "cm./$cdom/$cnum";
7431: if ($env{'request.course.sec'} ne '') {
7432: $checkrole .= "/$env{'request.course.sec'}";
7433: }
7434: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7435: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7436: $noprint = 1;
7437: }
7438: }
7439: unless ($noprint) {
7440: my $symb = &Apache::lonnet::symbread();
7441: if ($symb ne '') {
7442: my $navmap = Apache::lonnavmaps::navmap->new();
7443: if (ref($navmap)) {
7444: my $res = $navmap->getBySymb($symb);
7445: if (ref($res)) {
7446: if (!$res->resprintable()) {
7447: $noprint = 1;
7448: }
7449: }
7450: }
7451: }
7452: }
7453: if ($noprint) {
7454: return <<"ENDSTYLE";
7455: <style type="text/css" media="print">
7456: body { display:none }
7457: </style>
7458: ENDSTYLE
7459: }
7460: }
7461: return;
7462: }
7463:
7464: =pod
7465:
1.341 albertel 7466: =item * &xml_begin()
7467:
7468: Returns the needed doctype and <html>
7469:
7470: Inputs: none
7471:
7472: =cut
7473:
7474: sub xml_begin {
1.1075.2.61 raeburn 7475: my ($is_frameset) = @_;
1.341 albertel 7476: my $output='';
7477:
7478: if ($env{'browser.mathml'}) {
7479: $output='<?xml version="1.0"?>'
7480: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7481: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7482:
7483: # .'<!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">] >'
7484: .'<!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">'
7485: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7486: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 7487: } elsif ($is_frameset) {
7488: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7489: '<html>'."\n";
1.341 albertel 7490: } else {
1.1075.2.61 raeburn 7491: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7492: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7493: }
7494: return $output;
7495: }
1.340 albertel 7496:
7497: =pod
7498:
1.306 albertel 7499: =item * &start_page()
7500:
7501: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7502:
1.648 raeburn 7503: Inputs:
7504:
7505: =over 4
7506:
7507: $title - optional title for the page
7508:
7509: $head_extra - optional extra HTML to incude inside the <head>
7510:
7511: $args - additional optional args supported are:
7512:
7513: =over 8
7514:
7515: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7516: arg on
1.814 bisitz 7517: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7518: add_entries -> additional attributes to add to the <body>
7519: domain -> force to color decorate a page for a
1.317 albertel 7520: specific domain
1.648 raeburn 7521: function -> force usage of a specific rolish color
1.317 albertel 7522: scheme
1.648 raeburn 7523: redirect -> see &headtag()
7524: bgcolor -> override the default page bg color
7525: js_ready -> return a string ready for being used in
1.317 albertel 7526: a javascript writeln
1.648 raeburn 7527: html_encode -> return a string ready for being used in
1.320 albertel 7528: a html attribute
1.648 raeburn 7529: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7530: $forcereg arg
1.648 raeburn 7531: frameset -> if true will start with a <frameset>
1.330 albertel 7532: rather than <body>
1.648 raeburn 7533: skip_phases -> hash ref of
1.338 albertel 7534: head -> skip the <html><head> generation
7535: body -> skip all <body> generation
1.1075.2.12 raeburn 7536: no_inline_link -> if true and in remote mode, don't show the
7537: 'Switch To Inline Menu' link
1.648 raeburn 7538: no_auto_mt_title -> prevent &mt()ing the title arg
7539: inherit_jsmath -> when creating popup window in a page,
7540: should it have jsmath forced on by the
7541: current page
1.867 kalberla 7542: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7543: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.15 raeburn 7544: group -> includes the current group, if page is for a
7545: specific group
1.361 albertel 7546:
1.648 raeburn 7547: =back
1.460 albertel 7548:
1.648 raeburn 7549: =back
1.562 albertel 7550:
1.306 albertel 7551: =cut
7552:
7553: sub start_page {
1.309 albertel 7554: my ($title,$head_extra,$args) = @_;
1.318 albertel 7555: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7556:
1.315 albertel 7557: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 7558: my ($result,@advtools);
1.964 droeschl 7559:
1.338 albertel 7560: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 7561: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 7562: }
7563:
7564: if (! exists($args->{'skip_phases'}{'body'}) ) {
7565: if ($args->{'frameset'}) {
7566: my $attr_string = &make_attr_string($args->{'force_register'},
7567: $args->{'add_entries'});
7568: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7569: } else {
7570: $result .=
7571: &bodytag($title,
7572: $args->{'function'}, $args->{'add_entries'},
7573: $args->{'only_body'}, $args->{'domain'},
7574: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 7575: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 7576: $args, \@advtools);
1.831 bisitz 7577: }
1.330 albertel 7578: }
1.338 albertel 7579:
1.315 albertel 7580: if ($args->{'js_ready'}) {
1.713 kaisler 7581: $result = &js_ready($result);
1.315 albertel 7582: }
1.320 albertel 7583: if ($args->{'html_encode'}) {
1.713 kaisler 7584: $result = &html_encode($result);
7585: }
7586:
1.813 bisitz 7587: # Preparation for new and consistent functionlist at top of screen
7588: # if ($args->{'functionlist'}) {
7589: # $result .= &build_functionlist();
7590: #}
7591:
1.964 droeschl 7592: # Don't add anything more if only_body wanted or in const space
7593: return $result if $args->{'only_body'}
7594: || $env{'request.state'} eq 'construct';
1.813 bisitz 7595:
7596: #Breadcrumbs
1.758 kaisler 7597: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7598: &Apache::lonhtmlcommon::clear_breadcrumbs();
7599: #if any br links exists, add them to the breadcrumbs
7600: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7601: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7602: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7603: }
7604: }
1.1075.2.19 raeburn 7605: # if @advtools array contains items add then to the breadcrumbs
7606: if (@advtools > 0) {
7607: &Apache::lonmenu::advtools_crumbs(@advtools);
7608: }
1.758 kaisler 7609:
7610: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7611: if(exists($args->{'bread_crumbs_component'})){
7612: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7613: }else{
7614: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7615: }
1.1075.2.24 raeburn 7616: } elsif (($env{'environment.remote'} eq 'on') &&
7617: ($env{'form.inhibitmenu'} ne 'yes') &&
7618: ($env{'request.noversionuri'} =~ m{^/res/}) &&
7619: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 7620: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 7621: }
1.315 albertel 7622: return $result;
1.306 albertel 7623: }
7624:
7625: sub end_page {
1.315 albertel 7626: my ($args) = @_;
7627: $env{'internal.end_page'}++;
1.330 albertel 7628: my $result;
1.335 albertel 7629: if ($args->{'discussion'}) {
7630: my ($target,$parser);
7631: if (ref($args->{'discussion'})) {
7632: ($target,$parser) =($args->{'discussion'}{'target'},
7633: $args->{'discussion'}{'parser'});
7634: }
7635: $result .= &Apache::lonxml::xmlend($target,$parser);
7636: }
1.330 albertel 7637: if ($args->{'frameset'}) {
7638: $result .= '</frameset>';
7639: } else {
1.635 raeburn 7640: $result .= &endbodytag($args);
1.330 albertel 7641: }
1.1075.2.6 raeburn 7642: unless ($args->{'notbody'}) {
7643: $result .= "\n</html>";
7644: }
1.330 albertel 7645:
1.315 albertel 7646: if ($args->{'js_ready'}) {
1.317 albertel 7647: $result = &js_ready($result);
1.315 albertel 7648: }
1.335 albertel 7649:
1.320 albertel 7650: if ($args->{'html_encode'}) {
7651: $result = &html_encode($result);
7652: }
1.335 albertel 7653:
1.315 albertel 7654: return $result;
7655: }
7656:
1.1034 www 7657: sub wishlist_window {
7658: return(<<'ENDWISHLIST');
1.1046 raeburn 7659: <script type="text/javascript">
1.1034 www 7660: // <![CDATA[
7661: // <!-- BEGIN LON-CAPA Internal
7662: function set_wishlistlink(title, path) {
7663: if (!title) {
7664: title = document.title;
7665: title = title.replace(/^LON-CAPA /,'');
7666: }
1.1075.2.65 raeburn 7667: title = encodeURIComponent(title);
1.1034 www 7668: if (!path) {
7669: path = location.pathname;
7670: }
1.1075.2.65 raeburn 7671: path = encodeURIComponent(path);
1.1034 www 7672: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7673: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7674: }
7675: // END LON-CAPA Internal -->
7676: // ]]>
7677: </script>
7678: ENDWISHLIST
7679: }
7680:
1.1030 www 7681: sub modal_window {
7682: return(<<'ENDMODAL');
1.1046 raeburn 7683: <script type="text/javascript">
1.1030 www 7684: // <![CDATA[
7685: // <!-- BEGIN LON-CAPA Internal
7686: var modalWindow = {
7687: parent:"body",
7688: windowId:null,
7689: content:null,
7690: width:null,
7691: height:null,
7692: close:function()
7693: {
7694: $(".LCmodal-window").remove();
7695: $(".LCmodal-overlay").remove();
7696: },
7697: open:function()
7698: {
7699: var modal = "";
7700: modal += "<div class=\"LCmodal-overlay\"></div>";
7701: 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;\">";
7702: modal += this.content;
7703: modal += "</div>";
7704:
7705: $(this.parent).append(modal);
7706:
7707: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7708: $(".LCclose-window").click(function(){modalWindow.close();});
7709: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7710: }
7711: };
1.1075.2.42 raeburn 7712: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7713: {
7714: modalWindow.windowId = "myModal";
7715: modalWindow.width = width;
7716: modalWindow.height = height;
1.1075.2.42 raeburn 7717: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7718: modalWindow.open();
7719: };
7720: // END LON-CAPA Internal -->
7721: // ]]>
7722: </script>
7723: ENDMODAL
7724: }
7725:
7726: sub modal_link {
1.1075.2.42 raeburn 7727: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7728: unless ($width) { $width=480; }
7729: unless ($height) { $height=400; }
1.1031 www 7730: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 7731: unless ($transparency) { $transparency='true'; }
7732:
1.1074 raeburn 7733: my $target_attr;
7734: if (defined($target)) {
7735: $target_attr = 'target="'.$target.'"';
7736: }
7737: return <<"ENDLINK";
1.1075.2.42 raeburn 7738: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7739: $linktext</a>
7740: ENDLINK
1.1030 www 7741: }
7742:
1.1032 www 7743: sub modal_adhoc_script {
7744: my ($funcname,$width,$height,$content)=@_;
7745: return (<<ENDADHOC);
1.1046 raeburn 7746: <script type="text/javascript">
1.1032 www 7747: // <![CDATA[
7748: var $funcname = function()
7749: {
7750: modalWindow.windowId = "myModal";
7751: modalWindow.width = $width;
7752: modalWindow.height = $height;
7753: modalWindow.content = '$content';
7754: modalWindow.open();
7755: };
7756: // ]]>
7757: </script>
7758: ENDADHOC
7759: }
7760:
1.1041 www 7761: sub modal_adhoc_inner {
7762: my ($funcname,$width,$height,$content)=@_;
7763: my $innerwidth=$width-20;
7764: $content=&js_ready(
1.1042 www 7765: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 7766: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7767: $content.
1.1041 www 7768: &end_scrollbox().
1.1075.2.42 raeburn 7769: &end_page()
1.1041 www 7770: );
7771: return &modal_adhoc_script($funcname,$width,$height,$content);
7772: }
7773:
7774: sub modal_adhoc_window {
7775: my ($funcname,$width,$height,$content,$linktext)=@_;
7776: return &modal_adhoc_inner($funcname,$width,$height,$content).
7777: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7778: }
7779:
7780: sub modal_adhoc_launch {
7781: my ($funcname,$width,$height,$content)=@_;
7782: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7783: <script type="text/javascript">
7784: // <![CDATA[
7785: $funcname();
7786: // ]]>
7787: </script>
7788: ENDLAUNCH
7789: }
7790:
7791: sub modal_adhoc_close {
7792: return (<<ENDCLOSE);
7793: <script type="text/javascript">
7794: // <![CDATA[
7795: modalWindow.close();
7796: // ]]>
7797: </script>
7798: ENDCLOSE
7799: }
7800:
1.1038 www 7801: sub togglebox_script {
7802: return(<<ENDTOGGLE);
7803: <script type="text/javascript">
7804: // <![CDATA[
7805: function LCtoggleDisplay(id,hidetext,showtext) {
7806: link = document.getElementById(id + "link").childNodes[0];
7807: with (document.getElementById(id).style) {
7808: if (display == "none" ) {
7809: display = "inline";
7810: link.nodeValue = hidetext;
7811: } else {
7812: display = "none";
7813: link.nodeValue = showtext;
7814: }
7815: }
7816: }
7817: // ]]>
7818: </script>
7819: ENDTOGGLE
7820: }
7821:
1.1039 www 7822: sub start_togglebox {
7823: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7824: unless ($heading) { $heading=''; } else { $heading.=' '; }
7825: unless ($showtext) { $showtext=&mt('show'); }
7826: unless ($hidetext) { $hidetext=&mt('hide'); }
7827: unless ($headerbg) { $headerbg='#FFFFFF'; }
7828: return &start_data_table().
7829: &start_data_table_header_row().
7830: '<td bgcolor="'.$headerbg.'">'.$heading.
7831: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7832: $showtext.'\')">'.$showtext.'</a>]</td>'.
7833: &end_data_table_header_row().
7834: '<tr id="'.$id.'" style="display:none""><td>';
7835: }
7836:
7837: sub end_togglebox {
7838: return '</td></tr>'.&end_data_table();
7839: }
7840:
1.1041 www 7841: sub LCprogressbar_script {
1.1045 www 7842: my ($id)=@_;
1.1041 www 7843: return(<<ENDPROGRESS);
7844: <script type="text/javascript">
7845: // <![CDATA[
1.1045 www 7846: \$('#progressbar$id').progressbar({
1.1041 www 7847: value: 0,
7848: change: function(event, ui) {
7849: var newVal = \$(this).progressbar('option', 'value');
7850: \$('.pblabel', this).text(LCprogressTxt);
7851: }
7852: });
7853: // ]]>
7854: </script>
7855: ENDPROGRESS
7856: }
7857:
7858: sub LCprogressbarUpdate_script {
7859: return(<<ENDPROGRESSUPDATE);
7860: <style type="text/css">
7861: .ui-progressbar { position:relative; }
7862: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7863: </style>
7864: <script type="text/javascript">
7865: // <![CDATA[
1.1045 www 7866: var LCprogressTxt='---';
7867:
7868: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7869: LCprogressTxt=progresstext;
1.1045 www 7870: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7871: }
7872: // ]]>
7873: </script>
7874: ENDPROGRESSUPDATE
7875: }
7876:
1.1042 www 7877: my $LClastpercent;
1.1045 www 7878: my $LCidcnt;
7879: my $LCcurrentid;
1.1042 www 7880:
1.1041 www 7881: sub LCprogressbar {
1.1042 www 7882: my ($r)=(@_);
7883: $LClastpercent=0;
1.1045 www 7884: $LCidcnt++;
7885: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7886: my $starting=&mt('Starting');
7887: my $content=(<<ENDPROGBAR);
1.1045 www 7888: <div id="progressbar$LCcurrentid">
1.1041 www 7889: <span class="pblabel">$starting</span>
7890: </div>
7891: ENDPROGBAR
1.1045 www 7892: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7893: }
7894:
7895: sub LCprogressbarUpdate {
1.1042 www 7896: my ($r,$val,$text)=@_;
7897: unless ($val) {
7898: if ($LClastpercent) {
7899: $val=$LClastpercent;
7900: } else {
7901: $val=0;
7902: }
7903: }
1.1041 www 7904: if ($val<0) { $val=0; }
7905: if ($val>100) { $val=0; }
1.1042 www 7906: $LClastpercent=$val;
1.1041 www 7907: unless ($text) { $text=$val.'%'; }
7908: $text=&js_ready($text);
1.1044 www 7909: &r_print($r,<<ENDUPDATE);
1.1041 www 7910: <script type="text/javascript">
7911: // <![CDATA[
1.1045 www 7912: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7913: // ]]>
7914: </script>
7915: ENDUPDATE
1.1035 www 7916: }
7917:
1.1042 www 7918: sub LCprogressbarClose {
7919: my ($r)=@_;
7920: $LClastpercent=0;
1.1044 www 7921: &r_print($r,<<ENDCLOSE);
1.1042 www 7922: <script type="text/javascript">
7923: // <![CDATA[
1.1045 www 7924: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7925: // ]]>
7926: </script>
7927: ENDCLOSE
1.1044 www 7928: }
7929:
7930: sub r_print {
7931: my ($r,$to_print)=@_;
7932: if ($r) {
7933: $r->print($to_print);
7934: $r->rflush();
7935: } else {
7936: print($to_print);
7937: }
1.1042 www 7938: }
7939:
1.320 albertel 7940: sub html_encode {
7941: my ($result) = @_;
7942:
1.322 albertel 7943: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7944:
7945: return $result;
7946: }
1.1044 www 7947:
1.317 albertel 7948: sub js_ready {
7949: my ($result) = @_;
7950:
1.323 albertel 7951: $result =~ s/[\n\r]/ /xmsg;
7952: $result =~ s/\\/\\\\/xmsg;
7953: $result =~ s/'/\\'/xmsg;
1.372 albertel 7954: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7955:
7956: return $result;
7957: }
7958:
1.315 albertel 7959: sub validate_page {
7960: if ( exists($env{'internal.start_page'})
1.316 albertel 7961: && $env{'internal.start_page'} > 1) {
7962: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7963: $env{'internal.start_page'}.' '.
1.316 albertel 7964: $ENV{'request.filename'});
1.315 albertel 7965: }
7966: if ( exists($env{'internal.end_page'})
1.316 albertel 7967: && $env{'internal.end_page'} > 1) {
7968: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7969: $env{'internal.end_page'}.' '.
1.316 albertel 7970: $env{'request.filename'});
1.315 albertel 7971: }
7972: if ( exists($env{'internal.start_page'})
7973: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7974: &Apache::lonnet::logthis('start_page called without end_page '.
7975: $env{'request.filename'});
1.315 albertel 7976: }
7977: if ( ! exists($env{'internal.start_page'})
7978: && exists($env{'internal.end_page'})) {
1.316 albertel 7979: &Apache::lonnet::logthis('end_page called without start_page'.
7980: $env{'request.filename'});
1.315 albertel 7981: }
1.306 albertel 7982: }
1.315 albertel 7983:
1.996 www 7984:
7985: sub start_scrollbox {
1.1075.2.56 raeburn 7986: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 7987: unless ($outerwidth) { $outerwidth='520px'; }
7988: unless ($width) { $width='500px'; }
7989: unless ($height) { $height='200px'; }
1.1075 raeburn 7990: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7991: if ($id ne '') {
1.1075.2.42 raeburn 7992: $table_id = ' id="table_'.$id.'"';
7993: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 7994: }
1.1075 raeburn 7995: if ($bgcolor ne '') {
7996: $tdcol = "background-color: $bgcolor;";
7997: }
1.1075.2.42 raeburn 7998: my $nicescroll_js;
7999: if ($env{'browser.mobile'}) {
8000: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8001: }
1.1075 raeburn 8002: return <<"END";
1.1075.2.42 raeburn 8003: $nicescroll_js
8004:
8005: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8006: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8007: END
1.996 www 8008: }
8009:
8010: sub end_scrollbox {
1.1036 www 8011: return '</div></td></tr></table>';
1.996 www 8012: }
8013:
1.1075.2.42 raeburn 8014: sub nicescroll_javascript {
8015: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8016: my %options;
8017: if (ref($cursor) eq 'HASH') {
8018: %options = %{$cursor};
8019: }
8020: unless ($options{'railalign'} =~ /^left|right$/) {
8021: $options{'railalign'} = 'left';
8022: }
8023: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8024: my $function = &get_users_function();
8025: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8026: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8027: $options{'cursorcolor'} = '#00F';
8028: }
8029: }
8030: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8031: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8032: $options{'cursoropacity'}='1.0';
8033: }
8034: } else {
8035: $options{'cursoropacity'}='1.0';
8036: }
8037: if ($options{'cursorfixedheight'} eq 'none') {
8038: delete($options{'cursorfixedheight'});
8039: } else {
8040: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8041: }
8042: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8043: delete($options{'railoffset'});
8044: }
8045: my @niceoptions;
8046: while (my($key,$value) = each(%options)) {
8047: if ($value =~ /^\{.+\}$/) {
8048: push(@niceoptions,$key.':'.$value);
8049: } else {
8050: push(@niceoptions,$key.':"'.$value.'"');
8051: }
8052: }
8053: my $nicescroll_js = '
8054: $(document).ready(
8055: function() {
8056: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8057: }
8058: );
8059: ';
8060: if ($framecheck) {
8061: $nicescroll_js .= '
8062: function expand_div(caller) {
8063: if (top === self) {
8064: document.getElementById("'.$id.'").style.width = "auto";
8065: document.getElementById("'.$id.'").style.height = "auto";
8066: } else {
8067: try {
8068: if (parent.frames) {
8069: if (parent.frames.length > 1) {
8070: var framesrc = parent.frames[1].location.href;
8071: var currsrc = framesrc.replace(/\#.*$/,"");
8072: if ((caller == "search") || (currsrc == "'.$location.'")) {
8073: document.getElementById("'.$id.'").style.width = "auto";
8074: document.getElementById("'.$id.'").style.height = "auto";
8075: }
8076: }
8077: }
8078: } catch (e) {
8079: return;
8080: }
8081: }
8082: return;
8083: }
8084: ';
8085: }
8086: if ($needjsready) {
8087: $nicescroll_js = '
8088: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8089: } else {
8090: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8091: }
8092: return $nicescroll_js;
8093: }
8094:
1.318 albertel 8095: sub simple_error_page {
1.1075.2.49 raeburn 8096: my ($r,$title,$msg,$args) = @_;
8097: if (ref($args) eq 'HASH') {
8098: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8099: } else {
8100: $msg = &mt($msg);
8101: }
8102:
1.318 albertel 8103: my $page =
8104: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8105: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8106: &Apache::loncommon::end_page();
8107: if (ref($r)) {
8108: $r->print($page);
1.327 albertel 8109: return;
1.318 albertel 8110: }
8111: return $page;
8112: }
1.347 albertel 8113:
8114: {
1.610 albertel 8115: my @row_count;
1.961 onken 8116:
8117: sub start_data_table_count {
8118: unshift(@row_count, 0);
8119: return;
8120: }
8121:
8122: sub end_data_table_count {
8123: shift(@row_count);
8124: return;
8125: }
8126:
1.347 albertel 8127: sub start_data_table {
1.1018 raeburn 8128: my ($add_class,$id) = @_;
1.422 albertel 8129: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8130: my $table_id;
8131: if (defined($id)) {
8132: $table_id = ' id="'.$id.'"';
8133: }
1.961 onken 8134: &start_data_table_count();
1.1018 raeburn 8135: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8136: }
8137:
8138: sub end_data_table {
1.961 onken 8139: &end_data_table_count();
1.389 albertel 8140: return '</table>'."\n";;
1.347 albertel 8141: }
8142:
8143: sub start_data_table_row {
1.974 wenzelju 8144: my ($add_class, $id) = @_;
1.610 albertel 8145: $row_count[0]++;
8146: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8147: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8148: $id = (' id="'.$id.'"') unless ($id eq '');
8149: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8150: }
1.471 banghart 8151:
8152: sub continue_data_table_row {
1.974 wenzelju 8153: my ($add_class, $id) = @_;
1.610 albertel 8154: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8155: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8156: $id = (' id="'.$id.'"') unless ($id eq '');
8157: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8158: }
1.347 albertel 8159:
8160: sub end_data_table_row {
1.389 albertel 8161: return '</tr>'."\n";;
1.347 albertel 8162: }
1.367 www 8163:
1.421 albertel 8164: sub start_data_table_empty_row {
1.707 bisitz 8165: # $row_count[0]++;
1.421 albertel 8166: return '<tr class="LC_empty_row" >'."\n";;
8167: }
8168:
8169: sub end_data_table_empty_row {
8170: return '</tr>'."\n";;
8171: }
8172:
1.367 www 8173: sub start_data_table_header_row {
1.389 albertel 8174: return '<tr class="LC_header_row">'."\n";;
1.367 www 8175: }
8176:
8177: sub end_data_table_header_row {
1.389 albertel 8178: return '</tr>'."\n";;
1.367 www 8179: }
1.890 droeschl 8180:
8181: sub data_table_caption {
8182: my $caption = shift;
8183: return "<caption class=\"LC_caption\">$caption</caption>";
8184: }
1.347 albertel 8185: }
8186:
1.548 albertel 8187: =pod
8188:
8189: =item * &inhibit_menu_check($arg)
8190:
8191: Checks for a inhibitmenu state and generates output to preserve it
8192:
8193: Inputs: $arg - can be any of
8194: - undef - in which case the return value is a string
8195: to add into arguments list of a uri
8196: - 'input' - in which case the return value is a HTML
8197: <form> <input> field of type hidden to
8198: preserve the value
8199: - a url - in which case the return value is the url with
8200: the neccesary cgi args added to preserve the
8201: inhibitmenu state
8202: - a ref to a url - no return value, but the string is
8203: updated to include the neccessary cgi
8204: args to preserve the inhibitmenu state
8205:
8206: =cut
8207:
8208: sub inhibit_menu_check {
8209: my ($arg) = @_;
8210: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8211: if ($arg eq 'input') {
8212: if ($env{'form.inhibitmenu'}) {
8213: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8214: } else {
8215: return
8216: }
8217: }
8218: if ($env{'form.inhibitmenu'}) {
8219: if (ref($arg)) {
8220: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8221: } elsif ($arg eq '') {
8222: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8223: } else {
8224: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8225: }
8226: }
8227: if (!ref($arg)) {
8228: return $arg;
8229: }
8230: }
8231:
1.251 albertel 8232: ###############################################
1.182 matthew 8233:
8234: =pod
8235:
1.549 albertel 8236: =back
8237:
8238: =head1 User Information Routines
8239:
8240: =over 4
8241:
1.405 albertel 8242: =item * &get_users_function()
1.182 matthew 8243:
8244: Used by &bodytag to determine the current users primary role.
8245: Returns either 'student','coordinator','admin', or 'author'.
8246:
8247: =cut
8248:
8249: ###############################################
8250: sub get_users_function {
1.815 tempelho 8251: my $function = 'norole';
1.818 tempelho 8252: if ($env{'request.role'}=~/^(st)/) {
8253: $function='student';
8254: }
1.907 raeburn 8255: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8256: $function='coordinator';
8257: }
1.258 albertel 8258: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8259: $function='admin';
8260: }
1.826 bisitz 8261: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8262: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8263: $function='author';
8264: }
8265: return $function;
1.54 www 8266: }
1.99 www 8267:
8268: ###############################################
8269:
1.233 raeburn 8270: =pod
8271:
1.821 raeburn 8272: =item * &show_course()
8273:
8274: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8275: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8276:
8277: Inputs:
8278: None
8279:
8280: Outputs:
8281: Scalar: 1 if 'Course' to be used, 0 otherwise.
8282:
8283: =cut
8284:
8285: ###############################################
8286: sub show_course {
8287: my $course = !$env{'user.adv'};
8288: if (!$env{'user.adv'}) {
8289: foreach my $env (keys(%env)) {
8290: next if ($env !~ m/^user\.priv\./);
8291: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8292: $course = 0;
8293: last;
8294: }
8295: }
8296: }
8297: return $course;
8298: }
8299:
8300: ###############################################
8301:
8302: =pod
8303:
1.542 raeburn 8304: =item * &check_user_status()
1.274 raeburn 8305:
8306: Determines current status of supplied role for a
8307: specific user. Roles can be active, previous or future.
8308:
8309: Inputs:
8310: user's domain, user's username, course's domain,
1.375 raeburn 8311: course's number, optional section ID.
1.274 raeburn 8312:
8313: Outputs:
8314: role status: active, previous or future.
8315:
8316: =cut
8317:
8318: sub check_user_status {
1.412 raeburn 8319: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8320: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8321: my @uroles = keys %userinfo;
8322: my $srchstr;
8323: my $active_chk = 'none';
1.412 raeburn 8324: my $now = time;
1.274 raeburn 8325: if (@uroles > 0) {
1.908 raeburn 8326: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8327: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8328: } else {
1.412 raeburn 8329: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8330: }
8331: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8332: my $role_end = 0;
8333: my $role_start = 0;
8334: $active_chk = 'active';
1.412 raeburn 8335: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8336: $role_end = $1;
8337: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8338: $role_start = $1;
1.274 raeburn 8339: }
8340: }
8341: if ($role_start > 0) {
1.412 raeburn 8342: if ($now < $role_start) {
1.274 raeburn 8343: $active_chk = 'future';
8344: }
8345: }
8346: if ($role_end > 0) {
1.412 raeburn 8347: if ($now > $role_end) {
1.274 raeburn 8348: $active_chk = 'previous';
8349: }
8350: }
8351: }
8352: }
8353: return $active_chk;
8354: }
8355:
8356: ###############################################
8357:
8358: =pod
8359:
1.405 albertel 8360: =item * &get_sections()
1.233 raeburn 8361:
8362: Determines all the sections for a course including
8363: sections with students and sections containing other roles.
1.419 raeburn 8364: Incoming parameters:
8365:
8366: 1. domain
8367: 2. course number
8368: 3. reference to array containing roles for which sections should
8369: be gathered (optional).
8370: 4. reference to array containing status types for which sections
8371: should be gathered (optional).
8372:
8373: If the third argument is undefined, sections are gathered for any role.
8374: If the fourth argument is undefined, sections are gathered for any status.
8375: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8376:
1.374 raeburn 8377: Returns section hash (keys are section IDs, values are
8378: number of users in each section), subject to the
1.419 raeburn 8379: optional roles filter, optional status filter
1.233 raeburn 8380:
8381: =cut
8382:
8383: ###############################################
8384: sub get_sections {
1.419 raeburn 8385: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8386: if (!defined($cdom) || !defined($cnum)) {
8387: my $cid = $env{'request.course.id'};
8388:
8389: return if (!defined($cid));
8390:
8391: $cdom = $env{'course.'.$cid.'.domain'};
8392: $cnum = $env{'course.'.$cid.'.num'};
8393: }
8394:
8395: my %sectioncount;
1.419 raeburn 8396: my $now = time;
1.240 albertel 8397:
1.1075.2.33 raeburn 8398: my $check_students = 1;
8399: my $only_students = 0;
8400: if (ref($possible_roles) eq 'ARRAY') {
8401: if (grep(/^st$/,@{$possible_roles})) {
8402: if (@{$possible_roles} == 1) {
8403: $only_students = 1;
8404: }
8405: } else {
8406: $check_students = 0;
8407: }
8408: }
8409:
8410: if ($check_students) {
1.276 albertel 8411: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8412: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8413: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8414: my $start_index = &Apache::loncoursedata::CL_START();
8415: my $end_index = &Apache::loncoursedata::CL_END();
8416: my $status;
1.366 albertel 8417: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8418: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8419: $data->[$status_index],
8420: $data->[$start_index],
8421: $data->[$end_index]);
8422: if ($stu_status eq 'Active') {
8423: $status = 'active';
8424: } elsif ($end < $now) {
8425: $status = 'previous';
8426: } elsif ($start > $now) {
8427: $status = 'future';
8428: }
8429: if ($section ne '-1' && $section !~ /^\s*$/) {
8430: if ((!defined($possible_status)) || (($status ne '') &&
8431: (grep/^\Q$status\E$/,@{$possible_status}))) {
8432: $sectioncount{$section}++;
8433: }
1.240 albertel 8434: }
8435: }
8436: }
1.1075.2.33 raeburn 8437: if ($only_students) {
8438: return %sectioncount;
8439: }
1.240 albertel 8440: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8441: foreach my $user (sort(keys(%courseroles))) {
8442: if ($user !~ /^(\w{2})/) { next; }
8443: my ($role) = ($user =~ /^(\w{2})/);
8444: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8445: my ($section,$status);
1.240 albertel 8446: if ($role eq 'cr' &&
8447: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8448: $section=$1;
8449: }
8450: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8451: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8452: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8453: if ($end == -1 && $start == -1) {
8454: next; #deleted role
8455: }
8456: if (!defined($possible_status)) {
8457: $sectioncount{$section}++;
8458: } else {
8459: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8460: $status = 'active';
8461: } elsif ($end < $now) {
8462: $status = 'future';
8463: } elsif ($start > $now) {
8464: $status = 'previous';
8465: }
8466: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8467: $sectioncount{$section}++;
8468: }
8469: }
1.233 raeburn 8470: }
1.366 albertel 8471: return %sectioncount;
1.233 raeburn 8472: }
8473:
1.274 raeburn 8474: ###############################################
1.294 raeburn 8475:
8476: =pod
1.405 albertel 8477:
8478: =item * &get_course_users()
8479:
1.275 raeburn 8480: Retrieves usernames:domains for users in the specified course
8481: with specific role(s), and access status.
8482:
8483: Incoming parameters:
1.277 albertel 8484: 1. course domain
8485: 2. course number
8486: 3. access status: users must have - either active,
1.275 raeburn 8487: previous, future, or all.
1.277 albertel 8488: 4. reference to array of permissible roles
1.288 raeburn 8489: 5. reference to array of section restrictions (optional)
8490: 6. reference to results object (hash of hashes).
8491: 7. reference to optional userdata hash
1.609 raeburn 8492: 8. reference to optional statushash
1.630 raeburn 8493: 9. flag if privileged users (except those set to unhide in
8494: course settings) should be excluded
1.609 raeburn 8495: Keys of top level results hash are roles.
1.275 raeburn 8496: Keys of inner hashes are username:domain, with
8497: values set to access type.
1.288 raeburn 8498: Optional userdata hash returns an array with arguments in the
8499: same order as loncoursedata::get_classlist() for student data.
8500:
1.609 raeburn 8501: Optional statushash returns
8502:
1.288 raeburn 8503: Entries for end, start, section and status are blank because
8504: of the possibility of multiple values for non-student roles.
8505:
1.275 raeburn 8506: =cut
1.405 albertel 8507:
1.275 raeburn 8508: ###############################################
1.405 albertel 8509:
1.275 raeburn 8510: sub get_course_users {
1.630 raeburn 8511: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8512: my %idx = ();
1.419 raeburn 8513: my %seclists;
1.288 raeburn 8514:
8515: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8516: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8517: $idx{end} = &Apache::loncoursedata::CL_END();
8518: $idx{start} = &Apache::loncoursedata::CL_START();
8519: $idx{id} = &Apache::loncoursedata::CL_ID();
8520: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8521: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8522: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8523:
1.290 albertel 8524: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8525: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8526: my $now = time;
1.277 albertel 8527: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8528: my $match = 0;
1.412 raeburn 8529: my $secmatch = 0;
1.419 raeburn 8530: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8531: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8532: if ($section eq '') {
8533: $section = 'none';
8534: }
1.291 albertel 8535: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8536: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8537: $secmatch = 1;
8538: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8539: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8540: $secmatch = 1;
8541: }
8542: } else {
1.419 raeburn 8543: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8544: $secmatch = 1;
8545: }
1.290 albertel 8546: }
1.412 raeburn 8547: if (!$secmatch) {
8548: next;
8549: }
1.419 raeburn 8550: }
1.275 raeburn 8551: if (defined($$types{'active'})) {
1.288 raeburn 8552: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8553: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8554: $match = 1;
1.275 raeburn 8555: }
8556: }
8557: if (defined($$types{'previous'})) {
1.609 raeburn 8558: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8559: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8560: $match = 1;
1.275 raeburn 8561: }
8562: }
8563: if (defined($$types{'future'})) {
1.609 raeburn 8564: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8565: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8566: $match = 1;
1.275 raeburn 8567: }
8568: }
1.609 raeburn 8569: if ($match) {
8570: push(@{$seclists{$student}},$section);
8571: if (ref($userdata) eq 'HASH') {
8572: $$userdata{$student} = $$classlist{$student};
8573: }
8574: if (ref($statushash) eq 'HASH') {
8575: $statushash->{$student}{'st'}{$section} = $status;
8576: }
1.288 raeburn 8577: }
1.275 raeburn 8578: }
8579: }
1.412 raeburn 8580: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8581: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8582: my $now = time;
1.609 raeburn 8583: my %displaystatus = ( previous => 'Expired',
8584: active => 'Active',
8585: future => 'Future',
8586: );
1.1075.2.36 raeburn 8587: my (%nothide,@possdoms);
1.630 raeburn 8588: if ($hidepriv) {
8589: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8590: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8591: if ($user !~ /:/) {
8592: $nothide{join(':',split(/[\@]/,$user))}=1;
8593: } else {
8594: $nothide{$user} = 1;
8595: }
8596: }
1.1075.2.36 raeburn 8597: my @possdoms = ($cdom);
8598: if ($coursehash{'checkforpriv'}) {
8599: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8600: }
1.630 raeburn 8601: }
1.439 raeburn 8602: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8603: my $match = 0;
1.412 raeburn 8604: my $secmatch = 0;
1.439 raeburn 8605: my $status;
1.412 raeburn 8606: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8607: $user =~ s/:$//;
1.439 raeburn 8608: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8609: if ($end == -1 || $start == -1) {
8610: next;
8611: }
8612: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8613: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8614: my ($uname,$udom) = split(/:/,$user);
8615: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8616: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8617: $secmatch = 1;
8618: } elsif ($usec eq '') {
1.420 albertel 8619: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8620: $secmatch = 1;
8621: }
8622: } else {
8623: if (grep(/^\Q$usec\E$/,@{$sections})) {
8624: $secmatch = 1;
8625: }
8626: }
8627: if (!$secmatch) {
8628: next;
8629: }
1.288 raeburn 8630: }
1.419 raeburn 8631: if ($usec eq '') {
8632: $usec = 'none';
8633: }
1.275 raeburn 8634: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8635: if ($hidepriv) {
1.1075.2.36 raeburn 8636: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8637: (!$nothide{$uname.':'.$udom})) {
8638: next;
8639: }
8640: }
1.503 raeburn 8641: if ($end > 0 && $end < $now) {
1.439 raeburn 8642: $status = 'previous';
8643: } elsif ($start > $now) {
8644: $status = 'future';
8645: } else {
8646: $status = 'active';
8647: }
1.277 albertel 8648: foreach my $type (keys(%{$types})) {
1.275 raeburn 8649: if ($status eq $type) {
1.420 albertel 8650: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8651: push(@{$$users{$role}{$user}},$type);
8652: }
1.288 raeburn 8653: $match = 1;
8654: }
8655: }
1.419 raeburn 8656: if (($match) && (ref($userdata) eq 'HASH')) {
8657: if (!exists($$userdata{$uname.':'.$udom})) {
8658: &get_user_info($udom,$uname,\%idx,$userdata);
8659: }
1.420 albertel 8660: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8661: push(@{$seclists{$uname.':'.$udom}},$usec);
8662: }
1.609 raeburn 8663: if (ref($statushash) eq 'HASH') {
8664: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8665: }
1.275 raeburn 8666: }
8667: }
8668: }
8669: }
1.290 albertel 8670: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8671: if ((defined($cdom)) && (defined($cnum))) {
8672: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8673: if ( defined($csettings{'internal.courseowner'}) ) {
8674: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8675: next if ($owner eq '');
8676: my ($ownername,$ownerdom);
8677: if ($owner =~ /^([^:]+):([^:]+)$/) {
8678: $ownername = $1;
8679: $ownerdom = $2;
8680: } else {
8681: $ownername = $owner;
8682: $ownerdom = $cdom;
8683: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8684: }
8685: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8686: if (defined($userdata) &&
1.609 raeburn 8687: !exists($$userdata{$owner})) {
8688: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8689: if (!grep(/^none$/,@{$seclists{$owner}})) {
8690: push(@{$seclists{$owner}},'none');
8691: }
8692: if (ref($statushash) eq 'HASH') {
8693: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8694: }
1.290 albertel 8695: }
1.279 raeburn 8696: }
8697: }
8698: }
1.419 raeburn 8699: foreach my $user (keys(%seclists)) {
8700: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8701: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8702: }
1.275 raeburn 8703: }
8704: return;
8705: }
8706:
1.288 raeburn 8707: sub get_user_info {
8708: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8709: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8710: &plainname($uname,$udom,'lastname');
1.291 albertel 8711: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8712: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8713: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8714: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8715: return;
8716: }
1.275 raeburn 8717:
1.472 raeburn 8718: ###############################################
8719:
8720: =pod
8721:
8722: =item * &get_user_quota()
8723:
1.1075.2.41 raeburn 8724: Retrieves quota assigned for storage of user files.
8725: Default is to report quota for portfolio files.
1.472 raeburn 8726:
8727: Incoming parameters:
8728: 1. user's username
8729: 2. user's domain
1.1075.2.41 raeburn 8730: 3. quota name - portfolio, author, or course
8731: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 8732: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 8733: course
1.472 raeburn 8734:
8735: Returns:
1.1075.2.58 raeburn 8736: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 8737: 2. (Optional) Type of setting: custom or default
8738: (individually assigned or default for user's
8739: institutional status).
8740: 3. (Optional) - User's institutional status (e.g., faculty, staff
8741: or student - types as defined in localenroll::inst_usertypes
8742: for user's domain, which determines default quota for user.
8743: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8744:
8745: If a value has been stored in the user's environment,
1.536 raeburn 8746: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 8747: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8748:
8749: =cut
8750:
8751: ###############################################
8752:
8753:
8754: sub get_user_quota {
1.1075.2.42 raeburn 8755: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8756: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8757: if (!defined($udom)) {
8758: $udom = $env{'user.domain'};
8759: }
8760: if (!defined($uname)) {
8761: $uname = $env{'user.name'};
8762: }
8763: if (($udom eq '' || $uname eq '') ||
8764: ($udom eq 'public') && ($uname eq 'public')) {
8765: $quota = 0;
1.536 raeburn 8766: $quotatype = 'default';
8767: $defquota = 0;
1.472 raeburn 8768: } else {
1.536 raeburn 8769: my $inststatus;
1.1075.2.41 raeburn 8770: if ($quotaname eq 'course') {
8771: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8772: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8773: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8774: } else {
8775: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8776: $quota = $cenv{'internal.uploadquota'};
8777: }
1.536 raeburn 8778: } else {
1.1075.2.41 raeburn 8779: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8780: if ($quotaname eq 'author') {
8781: $quota = $env{'environment.authorquota'};
8782: } else {
8783: $quota = $env{'environment.portfolioquota'};
8784: }
8785: $inststatus = $env{'environment.inststatus'};
8786: } else {
8787: my %userenv =
8788: &Apache::lonnet::get('environment',['portfolioquota',
8789: 'authorquota','inststatus'],$udom,$uname);
8790: my ($tmp) = keys(%userenv);
8791: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8792: if ($quotaname eq 'author') {
8793: $quota = $userenv{'authorquota'};
8794: } else {
8795: $quota = $userenv{'portfolioquota'};
8796: }
8797: $inststatus = $userenv{'inststatus'};
8798: } else {
8799: undef(%userenv);
8800: }
8801: }
8802: }
8803: if ($quota eq '' || wantarray) {
8804: if ($quotaname eq 'course') {
8805: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 8806: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
8807: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 8808: $defquota = $domdefs{$crstype.'quota'};
8809: }
8810: if ($defquota eq '') {
8811: $defquota = 500;
8812: }
1.1075.2.41 raeburn 8813: } else {
8814: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8815: }
8816: if ($quota eq '') {
8817: $quota = $defquota;
8818: $quotatype = 'default';
8819: } else {
8820: $quotatype = 'custom';
8821: }
1.472 raeburn 8822: }
8823: }
1.536 raeburn 8824: if (wantarray) {
8825: return ($quota,$quotatype,$settingstatus,$defquota);
8826: } else {
8827: return $quota;
8828: }
1.472 raeburn 8829: }
8830:
8831: ###############################################
8832:
8833: =pod
8834:
8835: =item * &default_quota()
8836:
1.536 raeburn 8837: Retrieves default quota assigned for storage of user portfolio files,
8838: given an (optional) user's institutional status.
1.472 raeburn 8839:
8840: Incoming parameters:
1.1075.2.42 raeburn 8841:
1.472 raeburn 8842: 1. domain
1.536 raeburn 8843: 2. (Optional) institutional status(es). This is a : separated list of
8844: status types (e.g., faculty, staff, student etc.)
8845: which apply to the user for whom the default is being retrieved.
8846: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 8847: default quota will be returned.
8848: 3. quota name - portfolio, author, or course
8849: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8850:
8851: Returns:
1.1075.2.42 raeburn 8852:
1.1075.2.58 raeburn 8853: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 8854: 2. (Optional) institutional type which determined the value of the
8855: default quota.
1.472 raeburn 8856:
8857: If a value has been stored in the domain's configuration db,
8858: it will return that, otherwise it returns 20 (for backwards
8859: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 8860: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 8861:
1.536 raeburn 8862: If the user's status includes multiple types (e.g., staff and student),
8863: the largest default quota which applies to the user determines the
8864: default quota returned.
8865:
1.472 raeburn 8866: =cut
8867:
8868: ###############################################
8869:
8870:
8871: sub default_quota {
1.1075.2.41 raeburn 8872: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8873: my ($defquota,$settingstatus);
8874: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8875: ['quotas'],$udom);
1.1075.2.41 raeburn 8876: my $key = 'defaultquota';
8877: if ($quotaname eq 'author') {
8878: $key = 'authorquota';
8879: }
1.622 raeburn 8880: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8881: if ($inststatus ne '') {
1.765 raeburn 8882: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8883: foreach my $item (@statuses) {
1.1075.2.41 raeburn 8884: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8885: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8886: if ($defquota eq '') {
1.1075.2.41 raeburn 8887: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8888: $settingstatus = $item;
1.1075.2.41 raeburn 8889: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8890: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8891: $settingstatus = $item;
8892: }
8893: }
1.1075.2.41 raeburn 8894: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8895: if ($quotahash{'quotas'}{$item} ne '') {
8896: if ($defquota eq '') {
8897: $defquota = $quotahash{'quotas'}{$item};
8898: $settingstatus = $item;
8899: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8900: $defquota = $quotahash{'quotas'}{$item};
8901: $settingstatus = $item;
8902: }
1.536 raeburn 8903: }
8904: }
8905: }
8906: }
8907: if ($defquota eq '') {
1.1075.2.41 raeburn 8908: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8909: $defquota = $quotahash{'quotas'}{$key}{'default'};
8910: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8911: $defquota = $quotahash{'quotas'}{'default'};
8912: }
1.536 raeburn 8913: $settingstatus = 'default';
1.1075.2.42 raeburn 8914: if ($defquota eq '') {
8915: if ($quotaname eq 'author') {
8916: $defquota = 500;
8917: }
8918: }
1.536 raeburn 8919: }
8920: } else {
8921: $settingstatus = 'default';
1.1075.2.41 raeburn 8922: if ($quotaname eq 'author') {
8923: $defquota = 500;
8924: } else {
8925: $defquota = 20;
8926: }
1.536 raeburn 8927: }
8928: if (wantarray) {
8929: return ($defquota,$settingstatus);
1.472 raeburn 8930: } else {
1.536 raeburn 8931: return $defquota;
1.472 raeburn 8932: }
8933: }
8934:
1.1075.2.41 raeburn 8935: ###############################################
8936:
8937: =pod
8938:
1.1075.2.42 raeburn 8939: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 8940:
8941: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 8942: of existing file within authoring space will cause quota for the authoring
8943: space to be exceeded.
8944:
8945: Same, if upload of a file directly to a course/community via Course Editor
8946: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 8947:
1.1075.2.61 raeburn 8948: Inputs: 7
1.1075.2.42 raeburn 8949: 1. username or coursenum
1.1075.2.41 raeburn 8950: 2. domain
1.1075.2.42 raeburn 8951: 3. context ('author' or 'course')
1.1075.2.41 raeburn 8952: 4. filename of file for which action is being requested
8953: 5. filesize (kB) of file
8954: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 8955: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 8956:
8957: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
8958: otherwise return null.
8959:
1.1075.2.42 raeburn 8960: =back
8961:
1.1075.2.41 raeburn 8962: =cut
8963:
1.1075.2.42 raeburn 8964: sub excess_filesize_warning {
1.1075.2.59 raeburn 8965: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 8966: my $current_disk_usage = 0;
1.1075.2.59 raeburn 8967: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 8968: if ($context eq 'author') {
8969: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8970: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8971: } else {
8972: foreach my $subdir ('docs','supplemental') {
8973: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8974: }
8975: }
1.1075.2.41 raeburn 8976: $disk_quota = int($disk_quota * 1000);
8977: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 8978: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 8979: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 8980: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
8981: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 8982: $disk_quota,$current_disk_usage).
8983: '</p>';
8984: }
8985: return;
8986: }
8987:
8988: ###############################################
8989:
8990:
1.384 raeburn 8991: sub get_secgrprole_info {
8992: my ($cdom,$cnum,$needroles,$type) = @_;
8993: my %sections_count = &get_sections($cdom,$cnum);
8994: my @sections = (sort {$a <=> $b} keys(%sections_count));
8995: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8996: my @groups = sort(keys(%curr_groups));
8997: my $allroles = [];
8998: my $rolehash;
8999: my $accesshash = {
9000: active => 'Currently has access',
9001: future => 'Will have future access',
9002: previous => 'Previously had access',
9003: };
9004: if ($needroles) {
9005: $rolehash = {'all' => 'all'};
1.385 albertel 9006: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9007: if (&Apache::lonnet::error(%user_roles)) {
9008: undef(%user_roles);
9009: }
9010: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9011: my ($role)=split(/\:/,$item,2);
9012: if ($role eq 'cr') { next; }
9013: if ($role =~ /^cr/) {
9014: $$rolehash{$role} = (split('/',$role))[3];
9015: } else {
9016: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9017: }
9018: }
9019: foreach my $key (sort(keys(%{$rolehash}))) {
9020: push(@{$allroles},$key);
9021: }
9022: push (@{$allroles},'st');
9023: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9024: }
9025: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9026: }
9027:
1.555 raeburn 9028: sub user_picker {
1.994 raeburn 9029: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9030: my $currdom = $dom;
9031: my %curr_selected = (
9032: srchin => 'dom',
1.580 raeburn 9033: srchby => 'lastname',
1.555 raeburn 9034: );
9035: my $srchterm;
1.625 raeburn 9036: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9037: if ($srch->{'srchby'} ne '') {
9038: $curr_selected{'srchby'} = $srch->{'srchby'};
9039: }
9040: if ($srch->{'srchin'} ne '') {
9041: $curr_selected{'srchin'} = $srch->{'srchin'};
9042: }
9043: if ($srch->{'srchtype'} ne '') {
9044: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9045: }
9046: if ($srch->{'srchdomain'} ne '') {
9047: $currdom = $srch->{'srchdomain'};
9048: }
9049: $srchterm = $srch->{'srchterm'};
9050: }
9051: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 9052: 'usr' => 'Search criteria',
1.563 raeburn 9053: 'doma' => 'Domain/institution to search',
1.558 albertel 9054: 'uname' => 'username',
9055: 'lastname' => 'last name',
1.555 raeburn 9056: 'lastfirst' => 'last name, first name',
1.558 albertel 9057: 'crs' => 'in this course',
1.576 raeburn 9058: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9059: 'alc' => 'all LON-CAPA',
1.573 raeburn 9060: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9061: 'exact' => 'is',
9062: 'contains' => 'contains',
1.569 raeburn 9063: 'begins' => 'begins with',
1.571 raeburn 9064: 'youm' => "You must include some text to search for.",
9065: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9066: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9067: 'yomc' => "You must choose a domain when using an institutional directory search.",
9068: 'ymcd' => "You must choose a domain when using a domain search.",
9069: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9070: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9071: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9072: );
1.563 raeburn 9073: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9074: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9075:
9076: my @srchins = ('crs','dom','alc','instd');
9077:
9078: foreach my $option (@srchins) {
9079: # FIXME 'alc' option unavailable until
9080: # loncreateuser::print_user_query_page()
9081: # has been completed.
9082: next if ($option eq 'alc');
1.880 raeburn 9083: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9084: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9085: if ($curr_selected{'srchin'} eq $option) {
9086: $srchinsel .= '
9087: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9088: } else {
9089: $srchinsel .= '
9090: <option value="'.$option.'">'.$lt{$option}.'</option>';
9091: }
1.555 raeburn 9092: }
1.563 raeburn 9093: $srchinsel .= "\n </select>\n";
1.555 raeburn 9094:
9095: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9096: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9097: if ($curr_selected{'srchby'} eq $option) {
9098: $srchbysel .= '
9099: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9100: } else {
9101: $srchbysel .= '
9102: <option value="'.$option.'">'.$lt{$option}.'</option>';
9103: }
9104: }
9105: $srchbysel .= "\n </select>\n";
9106:
9107: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9108: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9109: if ($curr_selected{'srchtype'} eq $option) {
9110: $srchtypesel .= '
9111: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9112: } else {
9113: $srchtypesel .= '
9114: <option value="'.$option.'">'.$lt{$option}.'</option>';
9115: }
9116: }
9117: $srchtypesel .= "\n </select>\n";
9118:
1.558 albertel 9119: my ($newuserscript,$new_user_create);
1.994 raeburn 9120: my $context_dom = $env{'request.role.domain'};
9121: if ($context eq 'requestcrs') {
9122: if ($env{'form.coursedom'} ne '') {
9123: $context_dom = $env{'form.coursedom'};
9124: }
9125: }
1.556 raeburn 9126: if ($forcenewuser) {
1.576 raeburn 9127: if (ref($srch) eq 'HASH') {
1.994 raeburn 9128: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9129: if ($cancreate) {
9130: $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>';
9131: } else {
1.799 bisitz 9132: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9133: my %usertypetext = (
9134: official => 'institutional',
9135: unofficial => 'non-institutional',
9136: );
1.799 bisitz 9137: $new_user_create = '<p class="LC_warning">'
9138: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9139: .' '
9140: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9141: ,'<a href="'.$helplink.'">','</a>')
9142: .'</p><br />';
1.627 raeburn 9143: }
1.576 raeburn 9144: }
9145: }
9146:
1.556 raeburn 9147: $newuserscript = <<"ENDSCRIPT";
9148:
1.570 raeburn 9149: function setSearch(createnew,callingForm) {
1.556 raeburn 9150: if (createnew == 1) {
1.570 raeburn 9151: for (var i=0; i<callingForm.srchby.length; i++) {
9152: if (callingForm.srchby.options[i].value == 'uname') {
9153: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9154: }
9155: }
1.570 raeburn 9156: for (var i=0; i<callingForm.srchin.length; i++) {
9157: if ( callingForm.srchin.options[i].value == 'dom') {
9158: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9159: }
9160: }
1.570 raeburn 9161: for (var i=0; i<callingForm.srchtype.length; i++) {
9162: if (callingForm.srchtype.options[i].value == 'exact') {
9163: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9164: }
9165: }
1.570 raeburn 9166: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9167: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9168: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9169: }
9170: }
9171: }
9172: }
9173: ENDSCRIPT
1.558 albertel 9174:
1.556 raeburn 9175: }
9176:
1.555 raeburn 9177: my $output = <<"END_BLOCK";
1.556 raeburn 9178: <script type="text/javascript">
1.824 bisitz 9179: // <![CDATA[
1.570 raeburn 9180: function validateEntry(callingForm) {
1.558 albertel 9181:
1.556 raeburn 9182: var checkok = 1;
1.558 albertel 9183: var srchin;
1.570 raeburn 9184: for (var i=0; i<callingForm.srchin.length; i++) {
9185: if ( callingForm.srchin[i].checked ) {
9186: srchin = callingForm.srchin[i].value;
1.558 albertel 9187: }
9188: }
9189:
1.570 raeburn 9190: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9191: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9192: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9193: var srchterm = callingForm.srchterm.value;
9194: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9195: var msg = "";
9196:
9197: if (srchterm == "") {
9198: checkok = 0;
1.571 raeburn 9199: msg += "$lt{'youm'}\\n";
1.556 raeburn 9200: }
9201:
1.569 raeburn 9202: if (srchtype== 'begins') {
9203: if (srchterm.length < 2) {
9204: checkok = 0;
1.571 raeburn 9205: msg += "$lt{'thte'}\\n";
1.569 raeburn 9206: }
9207: }
9208:
1.556 raeburn 9209: if (srchtype== 'contains') {
9210: if (srchterm.length < 3) {
9211: checkok = 0;
1.571 raeburn 9212: msg += "$lt{'thet'}\\n";
1.556 raeburn 9213: }
9214: }
9215: if (srchin == 'instd') {
9216: if (srchdomain == '') {
9217: checkok = 0;
1.571 raeburn 9218: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9219: }
9220: }
9221: if (srchin == 'dom') {
9222: if (srchdomain == '') {
9223: checkok = 0;
1.571 raeburn 9224: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9225: }
9226: }
9227: if (srchby == 'lastfirst') {
9228: if (srchterm.indexOf(",") == -1) {
9229: checkok = 0;
1.571 raeburn 9230: msg += "$lt{'whus'}\\n";
1.556 raeburn 9231: }
9232: if (srchterm.indexOf(",") == srchterm.length -1) {
9233: checkok = 0;
1.571 raeburn 9234: msg += "$lt{'whse'}\\n";
1.556 raeburn 9235: }
9236: }
9237: if (checkok == 0) {
1.571 raeburn 9238: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9239: return;
9240: }
9241: if (checkok == 1) {
1.570 raeburn 9242: callingForm.submit();
1.556 raeburn 9243: }
9244: }
9245:
9246: $newuserscript
9247:
1.824 bisitz 9248: // ]]>
1.556 raeburn 9249: </script>
1.558 albertel 9250:
9251: $new_user_create
9252:
1.555 raeburn 9253: END_BLOCK
1.558 albertel 9254:
1.876 raeburn 9255: $output .= &Apache::lonhtmlcommon::start_pick_box().
9256: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9257: $domform.
9258: &Apache::lonhtmlcommon::row_closure().
9259: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9260: $srchbysel.
9261: $srchtypesel.
9262: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9263: $srchinsel.
9264: &Apache::lonhtmlcommon::row_closure(1).
9265: &Apache::lonhtmlcommon::end_pick_box().
9266: '<br />';
1.555 raeburn 9267: return $output;
9268: }
9269:
1.612 raeburn 9270: sub user_rule_check {
1.615 raeburn 9271: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9272: my $response;
9273: if (ref($usershash) eq 'HASH') {
9274: foreach my $user (keys(%{$usershash})) {
9275: my ($uname,$udom) = split(/:/,$user);
9276: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9277: my ($id,$newuser);
1.612 raeburn 9278: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9279: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9280: $id = $usershash->{$user}->{'id'};
9281: }
9282: my $inst_response;
9283: if (ref($checks) eq 'HASH') {
9284: if (defined($checks->{'username'})) {
1.615 raeburn 9285: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9286: &Apache::lonnet::get_instuser($udom,$uname);
9287: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9288: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9289: &Apache::lonnet::get_instuser($udom,undef,$id);
9290: }
1.615 raeburn 9291: } else {
9292: ($inst_response,%{$inst_results->{$user}}) =
9293: &Apache::lonnet::get_instuser($udom,$uname);
9294: return;
1.612 raeburn 9295: }
1.615 raeburn 9296: if (!$got_rules->{$udom}) {
1.612 raeburn 9297: my %domconfig = &Apache::lonnet::get_dom('configuration',
9298: ['usercreation'],$udom);
9299: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9300: foreach my $item ('username','id') {
1.612 raeburn 9301: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9302: $$curr_rules{$udom}{$item} =
9303: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9304: }
9305: }
9306: }
1.615 raeburn 9307: $got_rules->{$udom} = 1;
1.585 raeburn 9308: }
1.612 raeburn 9309: foreach my $item (keys(%{$checks})) {
9310: if (ref($$curr_rules{$udom}) eq 'HASH') {
9311: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9312: if (@{$$curr_rules{$udom}{$item}} > 0) {
9313: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9314: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9315: if ($rule_check{$rule}) {
9316: $$rulematch{$user}{$item} = $rule;
9317: if ($inst_response eq 'ok') {
1.615 raeburn 9318: if (ref($inst_results) eq 'HASH') {
9319: if (ref($inst_results->{$user}) eq 'HASH') {
9320: if (keys(%{$inst_results->{$user}}) == 0) {
9321: $$alerts{$item}{$udom}{$uname} = 1;
9322: }
1.612 raeburn 9323: }
9324: }
1.615 raeburn 9325: }
9326: last;
1.585 raeburn 9327: }
9328: }
9329: }
9330: }
9331: }
9332: }
9333: }
9334: }
1.612 raeburn 9335: return;
9336: }
9337:
9338: sub user_rule_formats {
9339: my ($domain,$domdesc,$curr_rules,$check) = @_;
9340: my %text = (
9341: 'username' => 'Usernames',
9342: 'id' => 'IDs',
9343: );
9344: my $output;
9345: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9346: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9347: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 9348: $output = '<br />'.
9349: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9350: '<span class="LC_cusr_emph">','</span>',$domdesc).
9351: ' <ul>';
1.612 raeburn 9352: foreach my $rule (@{$ruleorder}) {
9353: if (ref($curr_rules) eq 'ARRAY') {
9354: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9355: if (ref($rules->{$rule}) eq 'HASH') {
9356: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9357: $rules->{$rule}{'desc'}.'</li>';
9358: }
9359: }
9360: }
9361: }
9362: $output .= '</ul>';
9363: }
9364: }
9365: return $output;
9366: }
9367:
9368: sub instrule_disallow_msg {
1.615 raeburn 9369: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9370: my $response;
9371: my %text = (
9372: item => 'username',
9373: items => 'usernames',
9374: match => 'matches',
9375: do => 'does',
9376: action => 'a username',
9377: one => 'one',
9378: );
9379: if ($count > 1) {
9380: $text{'item'} = 'usernames';
9381: $text{'match'} ='match';
9382: $text{'do'} = 'do';
9383: $text{'action'} = 'usernames',
9384: $text{'one'} = 'ones';
9385: }
9386: if ($checkitem eq 'id') {
9387: $text{'items'} = 'IDs';
9388: $text{'item'} = 'ID';
9389: $text{'action'} = 'an ID';
1.615 raeburn 9390: if ($count > 1) {
9391: $text{'item'} = 'IDs';
9392: $text{'action'} = 'IDs';
9393: }
1.612 raeburn 9394: }
1.674 bisitz 9395: $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 9396: if ($mode eq 'upload') {
9397: if ($checkitem eq 'username') {
9398: $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'}.");
9399: } elsif ($checkitem eq 'id') {
1.674 bisitz 9400: $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 9401: }
1.669 raeburn 9402: } elsif ($mode eq 'selfcreate') {
9403: if ($checkitem eq 'id') {
9404: $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.");
9405: }
1.615 raeburn 9406: } else {
9407: if ($checkitem eq 'username') {
9408: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9409: } elsif ($checkitem eq 'id') {
9410: $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.");
9411: }
1.612 raeburn 9412: }
9413: return $response;
1.585 raeburn 9414: }
9415:
1.624 raeburn 9416: sub personal_data_fieldtitles {
9417: my %fieldtitles = &Apache::lonlocal::texthash (
9418: id => 'Student/Employee ID',
9419: permanentemail => 'E-mail address',
9420: lastname => 'Last Name',
9421: firstname => 'First Name',
9422: middlename => 'Middle Name',
9423: generation => 'Generation',
9424: gen => 'Generation',
1.765 raeburn 9425: inststatus => 'Affiliation',
1.624 raeburn 9426: );
9427: return %fieldtitles;
9428: }
9429:
1.642 raeburn 9430: sub sorted_inst_types {
9431: my ($dom) = @_;
1.1075.2.70 raeburn 9432: my ($usertypes,$order);
9433: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9434: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
9435: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
9436: $order = $domdefaults{'inststatus'}{'inststatusorder'};
9437: } else {
9438: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9439: }
1.642 raeburn 9440: my $othertitle = &mt('All users');
9441: if ($env{'request.course.id'}) {
1.668 raeburn 9442: $othertitle = &mt('Any users');
1.642 raeburn 9443: }
9444: my @types;
9445: if (ref($order) eq 'ARRAY') {
9446: @types = @{$order};
9447: }
9448: if (@types == 0) {
9449: if (ref($usertypes) eq 'HASH') {
9450: @types = sort(keys(%{$usertypes}));
9451: }
9452: }
9453: if (keys(%{$usertypes}) > 0) {
9454: $othertitle = &mt('Other users');
9455: }
9456: return ($othertitle,$usertypes,\@types);
9457: }
9458:
1.645 raeburn 9459: sub get_institutional_codes {
9460: my ($settings,$allcourses,$LC_code) = @_;
9461: # Get complete list of course sections to update
9462: my @currsections = ();
9463: my @currxlists = ();
9464: my $coursecode = $$settings{'internal.coursecode'};
9465:
9466: if ($$settings{'internal.sectionnums'} ne '') {
9467: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9468: }
9469:
9470: if ($$settings{'internal.crosslistings'} ne '') {
9471: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9472: }
9473:
9474: if (@currxlists > 0) {
9475: foreach (@currxlists) {
9476: if (m/^([^:]+):(\w*)$/) {
9477: unless (grep/^$1$/,@{$allcourses}) {
9478: push @{$allcourses},$1;
9479: $$LC_code{$1} = $2;
9480: }
9481: }
9482: }
9483: }
9484:
9485: if (@currsections > 0) {
9486: foreach (@currsections) {
9487: if (m/^(\w+):(\w*)$/) {
9488: my $sec = $coursecode.$1;
9489: my $lc_sec = $2;
9490: unless (grep/^$sec$/,@{$allcourses}) {
9491: push @{$allcourses},$sec;
9492: $$LC_code{$sec} = $lc_sec;
9493: }
9494: }
9495: }
9496: }
9497: return;
9498: }
9499:
1.971 raeburn 9500: sub get_standard_codeitems {
9501: return ('Year','Semester','Department','Number','Section');
9502: }
9503:
1.112 bowersj2 9504: =pod
9505:
1.780 raeburn 9506: =head1 Slot Helpers
9507:
9508: =over 4
9509:
9510: =item * sorted_slots()
9511:
1.1040 raeburn 9512: Sorts an array of slot names in order of an optional sort key,
9513: default sort is by slot start time (earliest first).
1.780 raeburn 9514:
9515: Inputs:
9516:
9517: =over 4
9518:
9519: slotsarr - Reference to array of unsorted slot names.
9520:
9521: slots - Reference to hash of hash, where outer hash keys are slot names.
9522:
1.1040 raeburn 9523: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9524:
1.549 albertel 9525: =back
9526:
1.780 raeburn 9527: Returns:
9528:
9529: =over 4
9530:
1.1040 raeburn 9531: sorted - An array of slot names sorted by a specified sort key
9532: (default sort key is start time of the slot).
1.780 raeburn 9533:
9534: =back
9535:
9536: =cut
9537:
9538:
9539: sub sorted_slots {
1.1040 raeburn 9540: my ($slotsarr,$slots,$sortkey) = @_;
9541: if ($sortkey eq '') {
9542: $sortkey = 'starttime';
9543: }
1.780 raeburn 9544: my @sorted;
9545: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9546: @sorted =
9547: sort {
9548: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9549: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9550: }
9551: if (ref($slots->{$a})) { return -1;}
9552: if (ref($slots->{$b})) { return 1;}
9553: return 0;
9554: } @{$slotsarr};
9555: }
9556: return @sorted;
9557: }
9558:
1.1040 raeburn 9559: =pod
9560:
9561: =item * get_future_slots()
9562:
9563: Inputs:
9564:
9565: =over 4
9566:
9567: cnum - course number
9568:
9569: cdom - course domain
9570:
9571: now - current UNIX time
9572:
9573: symb - optional symb
9574:
9575: =back
9576:
9577: Returns:
9578:
9579: =over 4
9580:
9581: sorted_reservable - ref to array of student_schedulable slots currently
9582: reservable, ordered by end date of reservation period.
9583:
9584: reservable_now - ref to hash of student_schedulable slots currently
9585: reservable.
9586:
9587: Keys in inner hash are:
9588: (a) symb: either blank or symb to which slot use is restricted.
9589: (b) endreserve: end date of reservation period.
9590:
9591: sorted_future - ref to array of student_schedulable slots reservable in
9592: the future, ordered by start date of reservation period.
9593:
9594: future_reservable - ref to hash of student_schedulable slots reservable
9595: in the future.
9596:
9597: Keys in inner hash are:
9598: (a) symb: either blank or symb to which slot use is restricted.
9599: (b) startreserve: start date of reservation period.
9600:
9601: =back
9602:
9603: =cut
9604:
9605: sub get_future_slots {
9606: my ($cnum,$cdom,$now,$symb) = @_;
9607: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9608: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9609: foreach my $slot (keys(%slots)) {
9610: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9611: if ($symb) {
9612: next if (($slots{$slot}->{'symb'} ne '') &&
9613: ($slots{$slot}->{'symb'} ne $symb));
9614: }
9615: if (($slots{$slot}->{'starttime'} > $now) &&
9616: ($slots{$slot}->{'endtime'} > $now)) {
9617: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9618: my $userallowed = 0;
9619: if ($slots{$slot}->{'allowedsections'}) {
9620: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9621: if (!defined($env{'request.role.sec'})
9622: && grep(/^No section assigned$/,@allowed_sec)) {
9623: $userallowed=1;
9624: } else {
9625: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9626: $userallowed=1;
9627: }
9628: }
9629: unless ($userallowed) {
9630: if (defined($env{'request.course.groups'})) {
9631: my @groups = split(/:/,$env{'request.course.groups'});
9632: foreach my $group (@groups) {
9633: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9634: $userallowed=1;
9635: last;
9636: }
9637: }
9638: }
9639: }
9640: }
9641: if ($slots{$slot}->{'allowedusers'}) {
9642: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9643: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9644: if (grep(/^\Q$user\E$/,@allowed_users)) {
9645: $userallowed = 1;
9646: }
9647: }
9648: next unless($userallowed);
9649: }
9650: my $startreserve = $slots{$slot}->{'startreserve'};
9651: my $endreserve = $slots{$slot}->{'endreserve'};
9652: my $symb = $slots{$slot}->{'symb'};
9653: if (($startreserve < $now) &&
9654: (!$endreserve || $endreserve > $now)) {
9655: my $lastres = $endreserve;
9656: if (!$lastres) {
9657: $lastres = $slots{$slot}->{'starttime'};
9658: }
9659: $reservable_now{$slot} = {
9660: symb => $symb,
9661: endreserve => $lastres
9662: };
9663: } elsif (($startreserve > $now) &&
9664: (!$endreserve || $endreserve > $startreserve)) {
9665: $future_reservable{$slot} = {
9666: symb => $symb,
9667: startreserve => $startreserve
9668: };
9669: }
9670: }
9671: }
9672: my @unsorted_reservable = keys(%reservable_now);
9673: if (@unsorted_reservable > 0) {
9674: @sorted_reservable =
9675: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9676: }
9677: my @unsorted_future = keys(%future_reservable);
9678: if (@unsorted_future > 0) {
9679: @sorted_future =
9680: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9681: }
9682: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9683: }
1.780 raeburn 9684:
9685: =pod
9686:
1.1057 foxr 9687: =back
9688:
1.549 albertel 9689: =head1 HTTP Helpers
9690:
9691: =over 4
9692:
1.648 raeburn 9693: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9694:
1.258 albertel 9695: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9696: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9697: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9698:
9699: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9700: $possible_names is an ref to an array of form element names. As an example:
9701: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9702: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9703:
9704: =cut
1.1 albertel 9705:
1.6 albertel 9706: sub get_unprocessed_cgi {
1.25 albertel 9707: my ($query,$possible_names)= @_;
1.26 matthew 9708: # $Apache::lonxml::debug=1;
1.356 albertel 9709: foreach my $pair (split(/&/,$query)) {
9710: my ($name, $value) = split(/=/,$pair);
1.369 www 9711: $name = &unescape($name);
1.25 albertel 9712: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9713: $value =~ tr/+/ /;
9714: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9715: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9716: }
1.16 harris41 9717: }
1.6 albertel 9718: }
9719:
1.112 bowersj2 9720: =pod
9721:
1.648 raeburn 9722: =item * &cacheheader()
1.112 bowersj2 9723:
9724: returns cache-controlling header code
9725:
9726: =cut
9727:
1.7 albertel 9728: sub cacheheader {
1.258 albertel 9729: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9730: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9731: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9732: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9733: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9734: return $output;
1.7 albertel 9735: }
9736:
1.112 bowersj2 9737: =pod
9738:
1.648 raeburn 9739: =item * &no_cache($r)
1.112 bowersj2 9740:
9741: specifies header code to not have cache
9742:
9743: =cut
9744:
1.9 albertel 9745: sub no_cache {
1.216 albertel 9746: my ($r) = @_;
9747: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9748: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9749: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9750: $r->no_cache(1);
9751: $r->header_out("Expires" => $date);
9752: $r->header_out("Pragma" => "no-cache");
1.123 www 9753: }
9754:
9755: sub content_type {
1.181 albertel 9756: my ($r,$type,$charset) = @_;
1.299 foxr 9757: if ($r) {
9758: # Note that printout.pl calls this with undef for $r.
9759: &no_cache($r);
9760: }
1.258 albertel 9761: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9762: unless ($charset) {
9763: $charset=&Apache::lonlocal::current_encoding;
9764: }
9765: if ($charset) { $type.='; charset='.$charset; }
9766: if ($r) {
9767: $r->content_type($type);
9768: } else {
9769: print("Content-type: $type\n\n");
9770: }
1.9 albertel 9771: }
1.25 albertel 9772:
1.112 bowersj2 9773: =pod
9774:
1.648 raeburn 9775: =item * &add_to_env($name,$value)
1.112 bowersj2 9776:
1.258 albertel 9777: adds $name to the %env hash with value
1.112 bowersj2 9778: $value, if $name already exists, the entry is converted to an array
9779: reference and $value is added to the array.
9780:
9781: =cut
9782:
1.25 albertel 9783: sub add_to_env {
9784: my ($name,$value)=@_;
1.258 albertel 9785: if (defined($env{$name})) {
9786: if (ref($env{$name})) {
1.25 albertel 9787: #already have multiple values
1.258 albertel 9788: push(@{ $env{$name} },$value);
1.25 albertel 9789: } else {
9790: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9791: my $first=$env{$name};
9792: undef($env{$name});
9793: push(@{ $env{$name} },$first,$value);
1.25 albertel 9794: }
9795: } else {
1.258 albertel 9796: $env{$name}=$value;
1.25 albertel 9797: }
1.31 albertel 9798: }
1.149 albertel 9799:
9800: =pod
9801:
1.648 raeburn 9802: =item * &get_env_multiple($name)
1.149 albertel 9803:
1.258 albertel 9804: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9805: values may be defined and end up as an array ref.
9806:
9807: returns an array of values
9808:
9809: =cut
9810:
9811: sub get_env_multiple {
9812: my ($name) = @_;
9813: my @values;
1.258 albertel 9814: if (defined($env{$name})) {
1.149 albertel 9815: # exists is it an array
1.258 albertel 9816: if (ref($env{$name})) {
9817: @values=@{ $env{$name} };
1.149 albertel 9818: } else {
1.258 albertel 9819: $values[0]=$env{$name};
1.149 albertel 9820: }
9821: }
9822: return(@values);
9823: }
9824:
1.660 raeburn 9825: sub ask_for_embedded_content {
9826: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9827: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 9828: %currsubfile,%unused,$rem);
1.1071 raeburn 9829: my $counter = 0;
9830: my $numnew = 0;
1.987 raeburn 9831: my $numremref = 0;
9832: my $numinvalid = 0;
9833: my $numpathchg = 0;
9834: my $numexisting = 0;
1.1071 raeburn 9835: my $numunused = 0;
9836: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 9837: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 9838: my $heading = &mt('Upload embedded files');
9839: my $buttontext = &mt('Upload');
9840:
1.1075.2.11 raeburn 9841: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 9842: if ($actionurl eq '/adm/dependencies') {
9843: $navmap = Apache::lonnavmaps::navmap->new();
9844: }
9845: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9846: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 9847: }
1.1075.2.35 raeburn 9848: if (($actionurl eq '/adm/portfolio') ||
9849: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9850: my $current_path='/';
9851: if ($env{'form.currentpath'}) {
9852: $current_path = $env{'form.currentpath'};
9853: }
9854: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 9855: $udom = $cdom;
9856: $uname = $cnum;
1.984 raeburn 9857: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9858: } else {
9859: $udom = $env{'user.domain'};
9860: $uname = $env{'user.name'};
9861: $url = '/userfiles/portfolio';
9862: }
1.987 raeburn 9863: $toplevel = $url.'/';
1.984 raeburn 9864: $url .= $current_path;
9865: $getpropath = 1;
1.987 raeburn 9866: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9867: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9868: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9869: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9870: $toplevel = $url;
1.984 raeburn 9871: if ($rest ne '') {
1.987 raeburn 9872: $url .= $rest;
9873: }
9874: } elsif ($actionurl eq '/adm/coursedocs') {
9875: if (ref($args) eq 'HASH') {
1.1071 raeburn 9876: $url = $args->{'docs_url'};
9877: $toplevel = $url;
1.1075.2.11 raeburn 9878: if ($args->{'context'} eq 'paste') {
9879: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9880: ($path) =
9881: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9882: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9883: $fileloc =~ s{^/}{};
9884: }
1.1071 raeburn 9885: }
9886: } elsif ($actionurl eq '/adm/dependencies') {
9887: if ($env{'request.course.id'} ne '') {
9888: if (ref($args) eq 'HASH') {
9889: $url = $args->{'docs_url'};
9890: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 9891: $toplevel = $url;
9892: unless ($toplevel =~ m{^/}) {
9893: $toplevel = "/$url";
9894: }
1.1075.2.11 raeburn 9895: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 9896: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9897: $path = $1;
9898: } else {
9899: ($path) =
9900: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9901: }
1.1071 raeburn 9902: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9903: $fileloc =~ s{^/}{};
9904: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9905: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9906: }
1.987 raeburn 9907: }
1.1075.2.35 raeburn 9908: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9909: $udom = $cdom;
9910: $uname = $cnum;
9911: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9912: $toplevel = $url;
9913: $path = $url;
9914: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9915: $fileloc =~ s{^/}{};
9916: }
9917: foreach my $file (keys(%{$allfiles})) {
9918: my $embed_file;
9919: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9920: $embed_file = $1;
9921: } else {
9922: $embed_file = $file;
9923: }
1.1075.2.55 raeburn 9924: my ($absolutepath,$cleaned_file);
9925: if ($embed_file =~ m{^\w+://}) {
9926: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 9927: $newfiles{$cleaned_file} = 1;
9928: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9929: } else {
1.1075.2.55 raeburn 9930: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 9931: if ($embed_file =~ m{^/}) {
9932: $absolutepath = $embed_file;
9933: }
1.1075.2.47 raeburn 9934: if ($cleaned_file =~ m{/}) {
9935: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 9936: $path = &check_for_traversal($path,$url,$toplevel);
9937: my $item = $fname;
9938: if ($path ne '') {
9939: $item = $path.'/'.$fname;
9940: $subdependencies{$path}{$fname} = 1;
9941: } else {
9942: $dependencies{$item} = 1;
9943: }
9944: if ($absolutepath) {
9945: $mapping{$item} = $absolutepath;
9946: } else {
9947: $mapping{$item} = $embed_file;
9948: }
9949: } else {
9950: $dependencies{$embed_file} = 1;
9951: if ($absolutepath) {
1.1075.2.47 raeburn 9952: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 9953: } else {
1.1075.2.47 raeburn 9954: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9955: }
9956: }
1.984 raeburn 9957: }
9958: }
1.1071 raeburn 9959: my $dirptr = 16384;
1.984 raeburn 9960: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9961: $currsubfile{$path} = {};
1.1075.2.35 raeburn 9962: if (($actionurl eq '/adm/portfolio') ||
9963: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9964: my ($sublistref,$listerror) =
9965: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9966: if (ref($sublistref) eq 'ARRAY') {
9967: foreach my $line (@{$sublistref}) {
9968: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9969: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9970: }
1.984 raeburn 9971: }
1.987 raeburn 9972: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9973: if (opendir(my $dir,$url.'/'.$path)) {
9974: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9975: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9976: }
1.1075.2.11 raeburn 9977: } elsif (($actionurl eq '/adm/dependencies') ||
9978: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 9979: ($args->{'context'} eq 'paste')) ||
9980: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9981: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 9982: my $dir;
9983: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9984: $dir = $fileloc;
9985: } else {
9986: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9987: }
1.1071 raeburn 9988: if ($dir ne '') {
9989: my ($sublistref,$listerror) =
9990: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9991: if (ref($sublistref) eq 'ARRAY') {
9992: foreach my $line (@{$sublistref}) {
9993: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9994: undef,$mtime)=split(/\&/,$line,12);
9995: unless (($testdir&$dirptr) ||
9996: ($file_name =~ /^\.\.?$/)) {
9997: $currsubfile{$path}{$file_name} = [$size,$mtime];
9998: }
9999: }
10000: }
10001: }
1.984 raeburn 10002: }
10003: }
10004: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10005: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10006: my $item = $path.'/'.$file;
10007: unless ($mapping{$item} eq $item) {
10008: $pathchanges{$item} = 1;
10009: }
10010: $existing{$item} = 1;
10011: $numexisting ++;
10012: } else {
10013: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10014: }
10015: }
1.1071 raeburn 10016: if ($actionurl eq '/adm/dependencies') {
10017: foreach my $path (keys(%currsubfile)) {
10018: if (ref($currsubfile{$path}) eq 'HASH') {
10019: foreach my $file (keys(%{$currsubfile{$path}})) {
10020: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10021: next if (($rem ne '') &&
10022: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10023: (ref($navmap) &&
10024: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10025: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10026: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10027: $unused{$path.'/'.$file} = 1;
10028: }
10029: }
10030: }
10031: }
10032: }
1.984 raeburn 10033: }
1.987 raeburn 10034: my %currfile;
1.1075.2.35 raeburn 10035: if (($actionurl eq '/adm/portfolio') ||
10036: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10037: my ($dirlistref,$listerror) =
10038: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10039: if (ref($dirlistref) eq 'ARRAY') {
10040: foreach my $line (@{$dirlistref}) {
10041: my ($file_name,$rest) = split(/\&/,$line,2);
10042: $currfile{$file_name} = 1;
10043: }
1.984 raeburn 10044: }
1.987 raeburn 10045: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10046: if (opendir(my $dir,$url)) {
1.987 raeburn 10047: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10048: map {$currfile{$_} = 1;} @dir_list;
10049: }
1.1075.2.11 raeburn 10050: } elsif (($actionurl eq '/adm/dependencies') ||
10051: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10052: ($args->{'context'} eq 'paste')) ||
10053: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10054: if ($env{'request.course.id'} ne '') {
10055: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10056: if ($dir ne '') {
10057: my ($dirlistref,$listerror) =
10058: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10059: if (ref($dirlistref) eq 'ARRAY') {
10060: foreach my $line (@{$dirlistref}) {
10061: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10062: $size,undef,$mtime)=split(/\&/,$line,12);
10063: unless (($testdir&$dirptr) ||
10064: ($file_name =~ /^\.\.?$/)) {
10065: $currfile{$file_name} = [$size,$mtime];
10066: }
10067: }
10068: }
10069: }
10070: }
1.984 raeburn 10071: }
10072: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10073: if (exists($currfile{$file})) {
1.987 raeburn 10074: unless ($mapping{$file} eq $file) {
10075: $pathchanges{$file} = 1;
10076: }
10077: $existing{$file} = 1;
10078: $numexisting ++;
10079: } else {
1.984 raeburn 10080: $newfiles{$file} = 1;
10081: }
10082: }
1.1071 raeburn 10083: foreach my $file (keys(%currfile)) {
10084: unless (($file eq $filename) ||
10085: ($file eq $filename.'.bak') ||
10086: ($dependencies{$file})) {
1.1075.2.11 raeburn 10087: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10088: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10089: next if (($rem ne '') &&
10090: (($env{"httpref.$rem".$file} ne '') ||
10091: (ref($navmap) &&
10092: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10093: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10094: ($navmap->getResourceByUrl($rem.$1)))))));
10095: }
1.1075.2.11 raeburn 10096: }
1.1071 raeburn 10097: $unused{$file} = 1;
10098: }
10099: }
1.1075.2.11 raeburn 10100: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10101: ($args->{'context'} eq 'paste')) {
10102: $counter = scalar(keys(%existing));
10103: $numpathchg = scalar(keys(%pathchanges));
10104: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10105: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10106: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10107: $counter = scalar(keys(%existing));
10108: $numpathchg = scalar(keys(%pathchanges));
10109: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10110: }
1.984 raeburn 10111: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10112: if ($actionurl eq '/adm/dependencies') {
10113: next if ($embed_file =~ m{^\w+://});
10114: }
1.660 raeburn 10115: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10116: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10117: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10118: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10119: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10120: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10121: }
1.1075.2.35 raeburn 10122: $upload_output .= '</td>';
1.1071 raeburn 10123: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10124: $upload_output.='<td align="right">'.
10125: '<span class="LC_info LC_fontsize_medium">'.
10126: &mt("URL points to web address").'</span>';
1.987 raeburn 10127: $numremref++;
1.660 raeburn 10128: } elsif ($args->{'error_on_invalid_names'}
10129: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10130: $upload_output.='<td align="right"><span class="LC_warning">'.
10131: &mt('Invalid characters').'</span>';
1.987 raeburn 10132: $numinvalid++;
1.660 raeburn 10133: } else {
1.1075.2.35 raeburn 10134: $upload_output .= '<td>'.
10135: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10136: $embed_file,\%mapping,
1.1071 raeburn 10137: $allfiles,$codebase,'upload');
10138: $counter ++;
10139: $numnew ++;
1.987 raeburn 10140: }
10141: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10142: }
10143: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10144: if ($actionurl eq '/adm/dependencies') {
10145: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10146: $modify_output .= &start_data_table_row().
10147: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10148: '<img src="'.&icon($embed_file).'" border="0" />'.
10149: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10150: '<td>'.$size.'</td>'.
10151: '<td>'.$mtime.'</td>'.
10152: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10153: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10154: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10155: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10156: &embedded_file_element('upload_embedded',$counter,
10157: $embed_file,\%mapping,
10158: $allfiles,$codebase,'modify').
10159: '</div></td>'.
10160: &end_data_table_row()."\n";
10161: $counter ++;
10162: } else {
10163: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10164: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10165: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10166: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10167: &Apache::loncommon::end_data_table_row()."\n";
10168: }
10169: }
10170: my $delidx = $counter;
10171: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10172: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10173: $delete_output .= &start_data_table_row().
10174: '<td><img src="'.&icon($oldfile).'" />'.
10175: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10176: '<td>'.$size.'</td>'.
10177: '<td>'.$mtime.'</td>'.
10178: '<td><label><input type="checkbox" name="del_upload_dep" '.
10179: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10180: &embedded_file_element('upload_embedded',$delidx,
10181: $oldfile,\%mapping,$allfiles,
10182: $codebase,'delete').'</td>'.
10183: &end_data_table_row()."\n";
10184: $numunused ++;
10185: $delidx ++;
1.987 raeburn 10186: }
10187: if ($upload_output) {
10188: $upload_output = &start_data_table().
10189: $upload_output.
10190: &end_data_table()."\n";
10191: }
1.1071 raeburn 10192: if ($modify_output) {
10193: $modify_output = &start_data_table().
10194: &start_data_table_header_row().
10195: '<th>'.&mt('File').'</th>'.
10196: '<th>'.&mt('Size (KB)').'</th>'.
10197: '<th>'.&mt('Modified').'</th>'.
10198: '<th>'.&mt('Upload replacement?').'</th>'.
10199: &end_data_table_header_row().
10200: $modify_output.
10201: &end_data_table()."\n";
10202: }
10203: if ($delete_output) {
10204: $delete_output = &start_data_table().
10205: &start_data_table_header_row().
10206: '<th>'.&mt('File').'</th>'.
10207: '<th>'.&mt('Size (KB)').'</th>'.
10208: '<th>'.&mt('Modified').'</th>'.
10209: '<th>'.&mt('Delete?').'</th>'.
10210: &end_data_table_header_row().
10211: $delete_output.
10212: &end_data_table()."\n";
10213: }
1.987 raeburn 10214: my $applies = 0;
10215: if ($numremref) {
10216: $applies ++;
10217: }
10218: if ($numinvalid) {
10219: $applies ++;
10220: }
10221: if ($numexisting) {
10222: $applies ++;
10223: }
1.1071 raeburn 10224: if ($counter || $numunused) {
1.987 raeburn 10225: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10226: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10227: $state.'<h3>'.$heading.'</h3>';
10228: if ($actionurl eq '/adm/dependencies') {
10229: if ($numnew) {
10230: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10231: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10232: $upload_output.'<br />'."\n";
10233: }
10234: if ($numexisting) {
10235: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10236: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10237: $modify_output.'<br />'."\n";
10238: $buttontext = &mt('Save changes');
10239: }
10240: if ($numunused) {
10241: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10242: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10243: $delete_output.'<br />'."\n";
10244: $buttontext = &mt('Save changes');
10245: }
10246: } else {
10247: $output .= $upload_output.'<br />'."\n";
10248: }
10249: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10250: $counter.'" />'."\n";
10251: if ($actionurl eq '/adm/dependencies') {
10252: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10253: $numnew.'" />'."\n";
10254: } elsif ($actionurl eq '') {
1.987 raeburn 10255: $output .= '<input type="hidden" name="phase" value="three" />';
10256: }
10257: } elsif ($applies) {
10258: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10259: if ($applies > 1) {
10260: $output .=
1.1075.2.35 raeburn 10261: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10262: if ($numremref) {
10263: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10264: }
10265: if ($numinvalid) {
10266: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10267: }
10268: if ($numexisting) {
10269: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10270: }
10271: $output .= '</ul><br />';
10272: } elsif ($numremref) {
10273: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10274: } elsif ($numinvalid) {
10275: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10276: } elsif ($numexisting) {
10277: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10278: }
10279: $output .= $upload_output.'<br />';
10280: }
10281: my ($pathchange_output,$chgcount);
1.1071 raeburn 10282: $chgcount = $counter;
1.987 raeburn 10283: if (keys(%pathchanges) > 0) {
10284: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10285: if ($counter) {
1.987 raeburn 10286: $output .= &embedded_file_element('pathchange',$chgcount,
10287: $embed_file,\%mapping,
1.1071 raeburn 10288: $allfiles,$codebase,'change');
1.987 raeburn 10289: } else {
10290: $pathchange_output .=
10291: &start_data_table_row().
10292: '<td><input type ="checkbox" name="namechange" value="'.
10293: $chgcount.'" checked="checked" /></td>'.
10294: '<td>'.$mapping{$embed_file}.'</td>'.
10295: '<td>'.$embed_file.
10296: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10297: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10298: '</td>'.&end_data_table_row();
1.660 raeburn 10299: }
1.987 raeburn 10300: $numpathchg ++;
10301: $chgcount ++;
1.660 raeburn 10302: }
10303: }
1.1075.2.35 raeburn 10304: if (($counter) || ($numunused)) {
1.987 raeburn 10305: if ($numpathchg) {
10306: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10307: $numpathchg.'" />'."\n";
10308: }
10309: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10310: ($actionurl eq '/adm/imsimport')) {
10311: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10312: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10313: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10314: } elsif ($actionurl eq '/adm/dependencies') {
10315: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10316: }
1.1075.2.35 raeburn 10317: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10318: } elsif ($numpathchg) {
10319: my %pathchange = ();
10320: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10321: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10322: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 10323: }
1.987 raeburn 10324: }
1.1071 raeburn 10325: return ($output,$counter,$numpathchg);
1.987 raeburn 10326: }
10327:
1.1075.2.47 raeburn 10328: =pod
10329:
10330: =item * clean_path($name)
10331:
10332: Performs clean-up of directories, subdirectories and filename in an
10333: embedded object, referenced in an HTML file which is being uploaded
10334: to a course or portfolio, where
10335: "Upload embedded images/multimedia files if HTML file" checkbox was
10336: checked.
10337:
10338: Clean-up is similar to replacements in lonnet::clean_filename()
10339: except each / between sub-directory and next level is preserved.
10340:
10341: =cut
10342:
10343: sub clean_path {
10344: my ($embed_file) = @_;
10345: $embed_file =~s{^/+}{};
10346: my @contents;
10347: if ($embed_file =~ m{/}) {
10348: @contents = split(/\//,$embed_file);
10349: } else {
10350: @contents = ($embed_file);
10351: }
10352: my $lastidx = scalar(@contents)-1;
10353: for (my $i=0; $i<=$lastidx; $i++) {
10354: $contents[$i]=~s{\\}{/}g;
10355: $contents[$i]=~s/\s+/\_/g;
10356: $contents[$i]=~s{[^/\w\.\-]}{}g;
10357: if ($i == $lastidx) {
10358: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10359: }
10360: }
10361: if ($lastidx > 0) {
10362: return join('/',@contents);
10363: } else {
10364: return $contents[0];
10365: }
10366: }
10367:
1.987 raeburn 10368: sub embedded_file_element {
1.1071 raeburn 10369: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10370: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10371: (ref($codebase) eq 'HASH'));
10372: my $output;
1.1071 raeburn 10373: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10374: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10375: }
10376: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10377: &escape($embed_file).'" />';
10378: unless (($context eq 'upload_embedded') &&
10379: ($mapping->{$embed_file} eq $embed_file)) {
10380: $output .='
10381: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10382: }
10383: my $attrib;
10384: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10385: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10386: }
10387: $output .=
10388: "\n\t\t".
10389: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10390: $attrib.'" />';
10391: if (exists($codebase->{$mapping->{$embed_file}})) {
10392: $output .=
10393: "\n\t\t".
10394: '<input name="codebase_'.$num.'" type="hidden" value="'.
10395: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10396: }
1.987 raeburn 10397: return $output;
1.660 raeburn 10398: }
10399:
1.1071 raeburn 10400: sub get_dependency_details {
10401: my ($currfile,$currsubfile,$embed_file) = @_;
10402: my ($size,$mtime,$showsize,$showmtime);
10403: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10404: if ($embed_file =~ m{/}) {
10405: my ($path,$fname) = split(/\//,$embed_file);
10406: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10407: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10408: }
10409: } else {
10410: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10411: ($size,$mtime) = @{$currfile->{$embed_file}};
10412: }
10413: }
10414: $showsize = $size/1024.0;
10415: $showsize = sprintf("%.1f",$showsize);
10416: if ($mtime > 0) {
10417: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10418: }
10419: }
10420: return ($showsize,$showmtime);
10421: }
10422:
10423: sub ask_embedded_js {
10424: return <<"END";
10425: <script type="text/javascript"">
10426: // <![CDATA[
10427: function toggleBrowse(counter) {
10428: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10429: var fileid = document.getElementById('embedded_item_'+counter);
10430: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10431: if (chkboxid.checked == true) {
10432: uploaddivid.style.display='block';
10433: } else {
10434: uploaddivid.style.display='none';
10435: fileid.value = '';
10436: }
10437: }
10438: // ]]>
10439: </script>
10440:
10441: END
10442: }
10443:
1.661 raeburn 10444: sub upload_embedded {
10445: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10446: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10447: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10448: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10449: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10450: my $orig_uploaded_filename =
10451: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10452: foreach my $type ('orig','ref','attrib','codebase') {
10453: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10454: $env{'form.embedded_'.$type.'_'.$i} =
10455: &unescape($env{'form.embedded_'.$type.'_'.$i});
10456: }
10457: }
1.661 raeburn 10458: my ($path,$fname) =
10459: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10460: # no path, whole string is fname
10461: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10462: $fname = &Apache::lonnet::clean_filename($fname);
10463: # See if there is anything left
10464: next if ($fname eq '');
10465:
10466: # Check if file already exists as a file or directory.
10467: my ($state,$msg);
10468: if ($context eq 'portfolio') {
10469: my $port_path = $dirpath;
10470: if ($group ne '') {
10471: $port_path = "groups/$group/$port_path";
10472: }
1.987 raeburn 10473: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10474: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10475: $dir_root,$port_path,$disk_quota,
10476: $current_disk_usage,$uname,$udom);
10477: if ($state eq 'will_exceed_quota'
1.984 raeburn 10478: || $state eq 'file_locked') {
1.661 raeburn 10479: $output .= $msg;
10480: next;
10481: }
10482: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10483: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10484: if ($state eq 'exists') {
10485: $output .= $msg;
10486: next;
10487: }
10488: }
10489: # Check if extension is valid
10490: if (($fname =~ /\.(\w+)$/) &&
10491: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 10492: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10493: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10494: next;
10495: } elsif (($fname =~ /\.(\w+)$/) &&
10496: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10497: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10498: next;
10499: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 10500: $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 10501: next;
10502: }
10503: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 10504: my $subdir = $path;
10505: $subdir =~ s{/+$}{};
1.661 raeburn 10506: if ($context eq 'portfolio') {
1.984 raeburn 10507: my $result;
10508: if ($state eq 'existingfile') {
10509: $result=
10510: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 10511: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10512: } else {
1.984 raeburn 10513: $result=
10514: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10515: $dirpath.
1.1075.2.35 raeburn 10516: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10517: if ($result !~ m|^/uploaded/|) {
10518: $output .= '<span class="LC_error">'
10519: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10520: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10521: .'</span><br />';
10522: next;
10523: } else {
1.987 raeburn 10524: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10525: $path.$fname.'</span>').'<br />';
1.984 raeburn 10526: }
1.661 raeburn 10527: }
1.1075.2.35 raeburn 10528: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
10529: my $extendedsubdir = $dirpath.'/'.$subdir;
10530: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10531: my $result =
1.1075.2.35 raeburn 10532: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10533: if ($result !~ m|^/uploaded/|) {
10534: $output .= '<span class="LC_error">'
10535: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10536: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10537: .'</span><br />';
10538: next;
10539: } else {
10540: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10541: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 10542: if ($context eq 'syllabus') {
10543: &Apache::lonnet::make_public_indefinitely($result);
10544: }
1.987 raeburn 10545: }
1.661 raeburn 10546: } else {
10547: # Save the file
10548: my $target = $env{'form.embedded_item_'.$i};
10549: my $fullpath = $dir_root.$dirpath.'/'.$path;
10550: my $dest = $fullpath.$fname;
10551: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10552: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10553: my $count;
10554: my $filepath = $dir_root;
1.1027 raeburn 10555: foreach my $subdir (@parts) {
10556: $filepath .= "/$subdir";
10557: if (!-e $filepath) {
1.661 raeburn 10558: mkdir($filepath,0770);
10559: }
10560: }
10561: my $fh;
10562: if (!open($fh,'>'.$dest)) {
10563: &Apache::lonnet::logthis('Failed to create '.$dest);
10564: $output .= '<span class="LC_error">'.
1.1071 raeburn 10565: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10566: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10567: '</span><br />';
10568: } else {
10569: if (!print $fh $env{'form.embedded_item_'.$i}) {
10570: &Apache::lonnet::logthis('Failed to write to '.$dest);
10571: $output .= '<span class="LC_error">'.
1.1071 raeburn 10572: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10573: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10574: '</span><br />';
10575: } else {
1.987 raeburn 10576: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10577: $url.'</span>').'<br />';
10578: unless ($context eq 'testbank') {
10579: $footer .= &mt('View embedded file: [_1]',
10580: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10581: }
10582: }
10583: close($fh);
10584: }
10585: }
10586: if ($env{'form.embedded_ref_'.$i}) {
10587: $pathchange{$i} = 1;
10588: }
10589: }
10590: if ($output) {
10591: $output = '<p>'.$output.'</p>';
10592: }
10593: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10594: $returnflag = 'ok';
1.1071 raeburn 10595: my $numpathchgs = scalar(keys(%pathchange));
10596: if ($numpathchgs > 0) {
1.987 raeburn 10597: if ($context eq 'portfolio') {
10598: $output .= '<p>'.&mt('or').'</p>';
10599: } elsif ($context eq 'testbank') {
1.1071 raeburn 10600: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10601: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10602: $returnflag = 'modify_orightml';
10603: }
10604: }
1.1071 raeburn 10605: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10606: }
10607:
10608: sub modify_html_form {
10609: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10610: my $end = 0;
10611: my $modifyform;
10612: if ($context eq 'upload_embedded') {
10613: return unless (ref($pathchange) eq 'HASH');
10614: if ($env{'form.number_embedded_items'}) {
10615: $end += $env{'form.number_embedded_items'};
10616: }
10617: if ($env{'form.number_pathchange_items'}) {
10618: $end += $env{'form.number_pathchange_items'};
10619: }
10620: if ($end) {
10621: for (my $i=0; $i<$end; $i++) {
10622: if ($i < $env{'form.number_embedded_items'}) {
10623: next unless($pathchange->{$i});
10624: }
10625: $modifyform .=
10626: &start_data_table_row().
10627: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10628: 'checked="checked" /></td>'.
10629: '<td>'.$env{'form.embedded_ref_'.$i}.
10630: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10631: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10632: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10633: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10634: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10635: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10636: '<td>'.$env{'form.embedded_orig_'.$i}.
10637: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10638: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10639: &end_data_table_row();
1.1071 raeburn 10640: }
1.987 raeburn 10641: }
10642: } else {
10643: $modifyform = $pathchgtable;
10644: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10645: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10646: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10647: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10648: }
10649: }
10650: if ($modifyform) {
1.1071 raeburn 10651: if ($actionurl eq '/adm/dependencies') {
10652: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10653: }
1.987 raeburn 10654: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10655: '<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".
10656: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10657: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10658: '</ol></p>'."\n".'<p>'.
10659: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10660: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10661: &start_data_table()."\n".
10662: &start_data_table_header_row().
10663: '<th>'.&mt('Change?').'</th>'.
10664: '<th>'.&mt('Current reference').'</th>'.
10665: '<th>'.&mt('Required reference').'</th>'.
10666: &end_data_table_header_row()."\n".
10667: $modifyform.
10668: &end_data_table().'<br />'."\n".$hiddenstate.
10669: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10670: '</form>'."\n";
10671: }
10672: return;
10673: }
10674:
10675: sub modify_html_refs {
1.1075.2.35 raeburn 10676: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10677: my $container;
10678: if ($context eq 'portfolio') {
10679: $container = $env{'form.container'};
10680: } elsif ($context eq 'coursedoc') {
10681: $container = $env{'form.primaryurl'};
1.1071 raeburn 10682: } elsif ($context eq 'manage_dependencies') {
10683: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10684: $container = "/$container";
1.1075.2.35 raeburn 10685: } elsif ($context eq 'syllabus') {
10686: $container = $url;
1.987 raeburn 10687: } else {
1.1027 raeburn 10688: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10689: }
10690: my (%allfiles,%codebase,$output,$content);
10691: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 10692: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10693: if (wantarray) {
10694: return ('',0,0);
10695: } else {
10696: return;
10697: }
10698: }
10699: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10700: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10701: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10702: if (wantarray) {
10703: return ('',0,0);
10704: } else {
10705: return;
10706: }
10707: }
1.987 raeburn 10708: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10709: if ($content eq '-1') {
10710: if (wantarray) {
10711: return ('',0,0);
10712: } else {
10713: return;
10714: }
10715: }
1.987 raeburn 10716: } else {
1.1071 raeburn 10717: unless ($container =~ /^\Q$dir_root\E/) {
10718: if (wantarray) {
10719: return ('',0,0);
10720: } else {
10721: return;
10722: }
10723: }
1.987 raeburn 10724: if (open(my $fh,"<$container")) {
10725: $content = join('', <$fh>);
10726: close($fh);
10727: } else {
1.1071 raeburn 10728: if (wantarray) {
10729: return ('',0,0);
10730: } else {
10731: return;
10732: }
1.987 raeburn 10733: }
10734: }
10735: my ($count,$codebasecount) = (0,0);
10736: my $mm = new File::MMagic;
10737: my $mime_type = $mm->checktype_contents($content);
10738: if ($mime_type eq 'text/html') {
10739: my $parse_result =
10740: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10741: \%codebase,\$content);
10742: if ($parse_result eq 'ok') {
10743: foreach my $i (@changes) {
10744: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10745: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10746: if ($allfiles{$ref}) {
10747: my $newname = $orig;
10748: my ($attrib_regexp,$codebase);
1.1006 raeburn 10749: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10750: if ($attrib_regexp =~ /:/) {
10751: $attrib_regexp =~ s/\:/|/g;
10752: }
10753: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10754: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10755: $count += $numchg;
1.1075.2.35 raeburn 10756: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 10757: delete($allfiles{$ref});
1.987 raeburn 10758: }
10759: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10760: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10761: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10762: $codebasecount ++;
10763: }
10764: }
10765: }
1.1075.2.35 raeburn 10766: my $skiprewrites;
1.987 raeburn 10767: if ($count || $codebasecount) {
10768: my $saveresult;
1.1071 raeburn 10769: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10770: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10771: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10772: if ($url eq $container) {
10773: my ($fname) = ($container =~ m{/([^/]+)$});
10774: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10775: $count,'<span class="LC_filename">'.
1.1071 raeburn 10776: $fname.'</span>').'</p>';
1.987 raeburn 10777: } else {
10778: $output = '<p class="LC_error">'.
10779: &mt('Error: update failed for: [_1].',
10780: '<span class="LC_filename">'.
10781: $container.'</span>').'</p>';
10782: }
1.1075.2.35 raeburn 10783: if ($context eq 'syllabus') {
10784: unless ($saveresult eq 'ok') {
10785: $skiprewrites = 1;
10786: }
10787: }
1.987 raeburn 10788: } else {
10789: if (open(my $fh,">$container")) {
10790: print $fh $content;
10791: close($fh);
10792: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10793: $count,'<span class="LC_filename">'.
10794: $container.'</span>').'</p>';
1.661 raeburn 10795: } else {
1.987 raeburn 10796: $output = '<p class="LC_error">'.
10797: &mt('Error: could not update [_1].',
10798: '<span class="LC_filename">'.
10799: $container.'</span>').'</p>';
1.661 raeburn 10800: }
10801: }
10802: }
1.1075.2.35 raeburn 10803: if (($context eq 'syllabus') && (!$skiprewrites)) {
10804: my ($actionurl,$state);
10805: $actionurl = "/public/$udom/$uname/syllabus";
10806: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10807: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10808: \%codebase,
10809: {'context' => 'rewrites',
10810: 'ignore_remote_references' => 1,});
10811: if (ref($mapping) eq 'HASH') {
10812: my $rewrites = 0;
10813: foreach my $key (keys(%{$mapping})) {
10814: next if ($key =~ m{^https?://});
10815: my $ref = $mapping->{$key};
10816: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10817: my $attrib;
10818: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10819: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10820: }
10821: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10822: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10823: $rewrites += $numchg;
10824: }
10825: }
10826: if ($rewrites) {
10827: my $saveresult;
10828: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10829: if ($url eq $container) {
10830: my ($fname) = ($container =~ m{/([^/]+)$});
10831: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10832: $count,'<span class="LC_filename">'.
10833: $fname.'</span>').'</p>';
10834: } else {
10835: $output .= '<p class="LC_error">'.
10836: &mt('Error: could not update links in [_1].',
10837: '<span class="LC_filename">'.
10838: $container.'</span>').'</p>';
10839:
10840: }
10841: }
10842: }
10843: }
1.987 raeburn 10844: } else {
10845: &logthis('Failed to parse '.$container.
10846: ' to modify references: '.$parse_result);
1.661 raeburn 10847: }
10848: }
1.1071 raeburn 10849: if (wantarray) {
10850: return ($output,$count,$codebasecount);
10851: } else {
10852: return $output;
10853: }
1.661 raeburn 10854: }
10855:
10856: sub check_for_existing {
10857: my ($path,$fname,$element) = @_;
10858: my ($state,$msg);
10859: if (-d $path.'/'.$fname) {
10860: $state = 'exists';
10861: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10862: } elsif (-e $path.'/'.$fname) {
10863: $state = 'exists';
10864: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10865: }
10866: if ($state eq 'exists') {
10867: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10868: }
10869: return ($state,$msg);
10870: }
10871:
10872: sub check_for_upload {
10873: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10874: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10875: my $filesize = length($env{'form.'.$element});
10876: if (!$filesize) {
10877: my $msg = '<span class="LC_error">'.
10878: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10879: '<span class="LC_filename">'.$fname.'</span>',
10880: $filesize).'<br />'.
1.1007 raeburn 10881: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10882: '</span>';
10883: return ('zero_bytes',$msg);
10884: }
10885: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10886: my $getpropath = 1;
1.1021 raeburn 10887: my ($dirlistref,$listerror) =
10888: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10889: my $found_file = 0;
10890: my $locked_file = 0;
1.991 raeburn 10891: my @lockers;
10892: my $navmap;
10893: if ($env{'request.course.id'}) {
10894: $navmap = Apache::lonnavmaps::navmap->new();
10895: }
1.1021 raeburn 10896: if (ref($dirlistref) eq 'ARRAY') {
10897: foreach my $line (@{$dirlistref}) {
10898: my ($file_name,$rest)=split(/\&/,$line,2);
10899: if ($file_name eq $fname){
10900: $file_name = $path.$file_name;
10901: if ($group ne '') {
10902: $file_name = $group.$file_name;
10903: }
10904: $found_file = 1;
10905: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10906: foreach my $lock (@lockers) {
10907: if (ref($lock) eq 'ARRAY') {
10908: my ($symb,$crsid) = @{$lock};
10909: if ($crsid eq $env{'request.course.id'}) {
10910: if (ref($navmap)) {
10911: my $res = $navmap->getBySymb($symb);
10912: foreach my $part (@{$res->parts()}) {
10913: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10914: unless (($slot_status == $res->RESERVED) ||
10915: ($slot_status == $res->RESERVED_LOCATION)) {
10916: $locked_file = 1;
10917: }
1.991 raeburn 10918: }
1.1021 raeburn 10919: } else {
10920: $locked_file = 1;
1.991 raeburn 10921: }
10922: } else {
10923: $locked_file = 1;
10924: }
10925: }
1.1021 raeburn 10926: }
10927: } else {
10928: my @info = split(/\&/,$rest);
10929: my $currsize = $info[6]/1000;
10930: if ($currsize < $filesize) {
10931: my $extra = $filesize - $currsize;
10932: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 10933: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 10934: &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 10935: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
10936: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10937: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 10938: return ('will_exceed_quota',$msg);
10939: }
1.984 raeburn 10940: }
10941: }
1.661 raeburn 10942: }
10943: }
10944: }
10945: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 10946: my $msg = '<p class="LC_warning">'.
10947: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
10948: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 10949: return ('will_exceed_quota',$msg);
10950: } elsif ($found_file) {
10951: if ($locked_file) {
1.1075.2.69 raeburn 10952: my $msg = '<p class="LC_warning">';
1.661 raeburn 10953: $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 10954: $msg .= '</p>';
1.661 raeburn 10955: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10956: return ('file_locked',$msg);
10957: } else {
1.1075.2.69 raeburn 10958: my $msg = '<p class="LC_error">';
1.984 raeburn 10959: $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 10960: $msg .= '</p>';
1.984 raeburn 10961: return ('existingfile',$msg);
1.661 raeburn 10962: }
10963: }
10964: }
10965:
1.987 raeburn 10966: sub check_for_traversal {
10967: my ($path,$url,$toplevel) = @_;
10968: my @parts=split(/\//,$path);
10969: my $cleanpath;
10970: my $fullpath = $url;
10971: for (my $i=0;$i<@parts;$i++) {
10972: next if ($parts[$i] eq '.');
10973: if ($parts[$i] eq '..') {
10974: $fullpath =~ s{([^/]+/)$}{};
10975: } else {
10976: $fullpath .= $parts[$i].'/';
10977: }
10978: }
10979: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10980: $cleanpath = $1;
10981: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10982: my $curr_toprel = $1;
10983: my @parts = split(/\//,$curr_toprel);
10984: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10985: my @urlparts = split(/\//,$url_toprel);
10986: my $doubledots;
10987: my $startdiff = -1;
10988: for (my $i=0; $i<@urlparts; $i++) {
10989: if ($startdiff == -1) {
10990: unless ($urlparts[$i] eq $parts[$i]) {
10991: $startdiff = $i;
10992: $doubledots .= '../';
10993: }
10994: } else {
10995: $doubledots .= '../';
10996: }
10997: }
10998: if ($startdiff > -1) {
10999: $cleanpath = $doubledots;
11000: for (my $i=$startdiff; $i<@parts; $i++) {
11001: $cleanpath .= $parts[$i].'/';
11002: }
11003: }
11004: }
11005: $cleanpath =~ s{(/)$}{};
11006: return $cleanpath;
11007: }
1.31 albertel 11008:
1.1053 raeburn 11009: sub is_archive_file {
11010: my ($mimetype) = @_;
11011: if (($mimetype eq 'application/octet-stream') ||
11012: ($mimetype eq 'application/x-stuffit') ||
11013: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11014: return 1;
11015: }
11016: return;
11017: }
11018:
11019: sub decompress_form {
1.1065 raeburn 11020: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11021: my %lt = &Apache::lonlocal::texthash (
11022: this => 'This file is an archive file.',
1.1067 raeburn 11023: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11024: itsc => 'Its contents are as follows:',
1.1053 raeburn 11025: youm => 'You may wish to extract its contents.',
11026: extr => 'Extract contents',
1.1067 raeburn 11027: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11028: proa => 'Process automatically?',
1.1053 raeburn 11029: yes => 'Yes',
11030: no => 'No',
1.1067 raeburn 11031: fold => 'Title for folder containing movie',
11032: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11033: );
1.1065 raeburn 11034: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11035: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11036: my $info = &list_archive_contents($fileloc,\@paths);
11037: if (@paths) {
11038: foreach my $path (@paths) {
11039: $path =~ s{^/}{};
1.1067 raeburn 11040: if ($path =~ m{^([^/]+)/$}) {
11041: $topdir = $1;
11042: }
1.1065 raeburn 11043: if ($path =~ m{^([^/]+)/}) {
11044: $toplevel{$1} = $path;
11045: } else {
11046: $toplevel{$path} = $path;
11047: }
11048: }
11049: }
1.1067 raeburn 11050: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11051: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11052: "$topdir/media/",
11053: "$topdir/media/$topdir.mp4",
11054: "$topdir/media/FirstFrame.png",
11055: "$topdir/media/player.swf",
11056: "$topdir/media/swfobject.js",
11057: "$topdir/media/expressInstall.swf");
1.1075.2.59 raeburn 11058: my @camtasia8 = ("$topdir/","$topdir/$topdir.html",
11059: "$topdir/$topdir.mp4",
11060: "$topdir/$topdir\_config.xml",
11061: "$topdir/$topdir\_controller.swf",
11062: "$topdir/$topdir\_embed.css",
11063: "$topdir/$topdir\_First_Frame.png",
11064: "$topdir/$topdir\_player.html",
11065: "$topdir/$topdir\_Thumbnails.png",
11066: "$topdir/playerProductInstall.swf",
11067: "$topdir/scripts/",
11068: "$topdir/scripts/config_xml.js",
11069: "$topdir/scripts/handlebars.js",
11070: "$topdir/scripts/jquery-1.7.1.min.js",
11071: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11072: "$topdir/scripts/modernizr.js",
11073: "$topdir/scripts/player-min.js",
11074: "$topdir/scripts/swfobject.js",
11075: "$topdir/skins/",
11076: "$topdir/skins/configuration_express.xml",
11077: "$topdir/skins/express_show/",
11078: "$topdir/skins/express_show/player-min.css",
11079: "$topdir/skins/express_show/spritesheet.png");
11080: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11081: if (@diffs == 0) {
1.1075.2.59 raeburn 11082: $is_camtasia = 6;
11083: } else {
11084: @diffs = &compare_arrays(\@paths,\@camtasia8);
11085: if (@diffs == 0) {
11086: $is_camtasia = 8;
11087: }
1.1067 raeburn 11088: }
11089: }
11090: my $output;
11091: if ($is_camtasia) {
11092: $output = <<"ENDCAM";
11093: <script type="text/javascript" language="Javascript">
11094: // <![CDATA[
11095:
11096: function camtasiaToggle() {
11097: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11098: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11099: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11100: document.getElementById('camtasia_titles').style.display='block';
11101: } else {
11102: document.getElementById('camtasia_titles').style.display='none';
11103: }
11104: }
11105: }
11106: return;
11107: }
11108:
11109: // ]]>
11110: </script>
11111: <p>$lt{'camt'}</p>
11112: ENDCAM
1.1065 raeburn 11113: } else {
1.1067 raeburn 11114: $output = '<p>'.$lt{'this'};
11115: if ($info eq '') {
11116: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11117: } else {
11118: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11119: '<div><pre>'.$info.'</pre></div>';
11120: }
1.1065 raeburn 11121: }
1.1067 raeburn 11122: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11123: my $duplicates;
11124: my $num = 0;
11125: if (ref($dirlist) eq 'ARRAY') {
11126: foreach my $item (@{$dirlist}) {
11127: if (ref($item) eq 'ARRAY') {
11128: if (exists($toplevel{$item->[0]})) {
11129: $duplicates .=
11130: &start_data_table_row().
11131: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11132: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11133: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11134: 'value="1" />'.&mt('Yes').'</label>'.
11135: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11136: '<td>'.$item->[0].'</td>';
11137: if ($item->[2]) {
11138: $duplicates .= '<td>'.&mt('Directory').'</td>';
11139: } else {
11140: $duplicates .= '<td>'.&mt('File').'</td>';
11141: }
11142: $duplicates .= '<td>'.$item->[3].'</td>'.
11143: '<td>'.
11144: &Apache::lonlocal::locallocaltime($item->[4]).
11145: '</td>'.
11146: &end_data_table_row();
11147: $num ++;
11148: }
11149: }
11150: }
11151: }
11152: my $itemcount;
11153: if (@paths > 0) {
11154: $itemcount = scalar(@paths);
11155: } else {
11156: $itemcount = 1;
11157: }
1.1067 raeburn 11158: if ($is_camtasia) {
11159: $output .= $lt{'auto'}.'<br />'.
11160: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 11161: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11162: $lt{'yes'}.'</label> <label>'.
11163: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11164: $lt{'no'}.'</label></span><br />'.
11165: '<div id="camtasia_titles" style="display:block">'.
11166: &Apache::lonhtmlcommon::start_pick_box().
11167: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11168: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11169: &Apache::lonhtmlcommon::row_closure().
11170: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11171: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11172: &Apache::lonhtmlcommon::row_closure(1).
11173: &Apache::lonhtmlcommon::end_pick_box().
11174: '</div>';
11175: }
1.1065 raeburn 11176: $output .=
11177: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11178: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11179: "\n";
1.1065 raeburn 11180: if ($duplicates ne '') {
11181: $output .= '<p><span class="LC_warning">'.
11182: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11183: &start_data_table().
11184: &start_data_table_header_row().
11185: '<th>'.&mt('Overwrite?').'</th>'.
11186: '<th>'.&mt('Name').'</th>'.
11187: '<th>'.&mt('Type').'</th>'.
11188: '<th>'.&mt('Size').'</th>'.
11189: '<th>'.&mt('Last modified').'</th>'.
11190: &end_data_table_header_row().
11191: $duplicates.
11192: &end_data_table().
11193: '</p>';
11194: }
1.1067 raeburn 11195: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11196: if (ref($hiddenelements) eq 'HASH') {
11197: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11198: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11199: }
11200: }
11201: $output .= <<"END";
1.1067 raeburn 11202: <br />
1.1053 raeburn 11203: <input type="submit" name="decompress" value="$lt{'extr'}" />
11204: </form>
11205: $noextract
11206: END
11207: return $output;
11208: }
11209:
1.1065 raeburn 11210: sub decompression_utility {
11211: my ($program) = @_;
11212: my @utilities = ('tar','gunzip','bunzip2','unzip');
11213: my $location;
11214: if (grep(/^\Q$program\E$/,@utilities)) {
11215: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11216: '/usr/sbin/') {
11217: if (-x $dir.$program) {
11218: $location = $dir.$program;
11219: last;
11220: }
11221: }
11222: }
11223: return $location;
11224: }
11225:
11226: sub list_archive_contents {
11227: my ($file,$pathsref) = @_;
11228: my (@cmd,$output);
11229: my $needsregexp;
11230: if ($file =~ /\.zip$/) {
11231: @cmd = (&decompression_utility('unzip'),"-l");
11232: $needsregexp = 1;
11233: } elsif (($file =~ m/\.tar\.gz$/) ||
11234: ($file =~ /\.tgz$/)) {
11235: @cmd = (&decompression_utility('tar'),"-ztf");
11236: } elsif ($file =~ /\.tar\.bz2$/) {
11237: @cmd = (&decompression_utility('tar'),"-jtf");
11238: } elsif ($file =~ m|\.tar$|) {
11239: @cmd = (&decompression_utility('tar'),"-tf");
11240: }
11241: if (@cmd) {
11242: undef($!);
11243: undef($@);
11244: if (open(my $fh,"-|", @cmd, $file)) {
11245: while (my $line = <$fh>) {
11246: $output .= $line;
11247: chomp($line);
11248: my $item;
11249: if ($needsregexp) {
11250: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11251: } else {
11252: $item = $line;
11253: }
11254: if ($item ne '') {
11255: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11256: push(@{$pathsref},$item);
11257: }
11258: }
11259: }
11260: close($fh);
11261: }
11262: }
11263: return $output;
11264: }
11265:
1.1053 raeburn 11266: sub decompress_uploaded_file {
11267: my ($file,$dir) = @_;
11268: &Apache::lonnet::appenv({'cgi.file' => $file});
11269: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11270: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11271: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11272: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11273: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11274: my $decompressed = $env{'cgi.decompressed'};
11275: &Apache::lonnet::delenv('cgi.file');
11276: &Apache::lonnet::delenv('cgi.dir');
11277: &Apache::lonnet::delenv('cgi.decompressed');
11278: return ($decompressed,$result);
11279: }
11280:
1.1055 raeburn 11281: sub process_decompression {
11282: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11283: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 11284: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 11285: $error = &mt('Filename not a supported archive file type.').
11286: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11287: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11288: } else {
11289: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11290: if ($docuhome eq 'no_host') {
11291: $error = &mt('Could not determine home server for course.');
11292: } else {
11293: my @ids=&Apache::lonnet::current_machine_ids();
11294: my $currdir = "$dir_root/$destination";
11295: if (grep(/^\Q$docuhome\E$/,@ids)) {
11296: $dir = &LONCAPA::propath($docudom,$docuname).
11297: "$dir_root/$destination";
11298: } else {
11299: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11300: "$dir_root/$docudom/$docuname/$destination";
11301: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11302: $error = &mt('Archive file not found.');
11303: }
11304: }
1.1065 raeburn 11305: my (@to_overwrite,@to_skip);
11306: if ($env{'form.archive_overwrite_total'} > 0) {
11307: my $total = $env{'form.archive_overwrite_total'};
11308: for (my $i=0; $i<$total; $i++) {
11309: if ($env{'form.archive_overwrite_'.$i} == 1) {
11310: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11311: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11312: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11313: }
11314: }
11315: }
11316: my $numskip = scalar(@to_skip);
11317: if (($numskip > 0) &&
11318: ($numskip == $env{'form.archive_itemcount'})) {
11319: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11320: } elsif ($dir eq '') {
1.1055 raeburn 11321: $error = &mt('Directory containing archive file unavailable.');
11322: } elsif (!$error) {
1.1065 raeburn 11323: my ($decompressed,$display);
11324: if ($numskip > 0) {
11325: my $tempdir = time.'_'.$$.int(rand(10000));
11326: mkdir("$dir/$tempdir",0755);
11327: system("mv $dir/$file $dir/$tempdir/$file");
11328: ($decompressed,$display) =
11329: &decompress_uploaded_file($file,"$dir/$tempdir");
11330: foreach my $item (@to_skip) {
11331: if (($item ne '') && ($item !~ /\.\./)) {
11332: if (-f "$dir/$tempdir/$item") {
11333: unlink("$dir/$tempdir/$item");
11334: } elsif (-d "$dir/$tempdir/$item") {
11335: system("rm -rf $dir/$tempdir/$item");
11336: }
11337: }
11338: }
11339: system("mv $dir/$tempdir/* $dir");
11340: rmdir("$dir/$tempdir");
11341: } else {
11342: ($decompressed,$display) =
11343: &decompress_uploaded_file($file,$dir);
11344: }
1.1055 raeburn 11345: if ($decompressed eq 'ok') {
1.1065 raeburn 11346: $output = '<p class="LC_info">'.
11347: &mt('Files extracted successfully from archive.').
11348: '</p>'."\n";
1.1055 raeburn 11349: my ($warning,$result,@contents);
11350: my ($newdirlistref,$newlisterror) =
11351: &Apache::lonnet::dirlist($currdir,$docudom,
11352: $docuname,1);
11353: my (%is_dir,%changes,@newitems);
11354: my $dirptr = 16384;
1.1065 raeburn 11355: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11356: foreach my $dir_line (@{$newdirlistref}) {
11357: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11358: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11359: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11360: push(@newitems,$item);
11361: if ($dirptr&$testdir) {
11362: $is_dir{$item} = 1;
11363: }
11364: $changes{$item} = 1;
11365: }
11366: }
11367: }
11368: if (keys(%changes) > 0) {
11369: foreach my $item (sort(@newitems)) {
11370: if ($changes{$item}) {
11371: push(@contents,$item);
11372: }
11373: }
11374: }
11375: if (@contents > 0) {
1.1067 raeburn 11376: my $wantform;
11377: unless ($env{'form.autoextract_camtasia'}) {
11378: $wantform = 1;
11379: }
1.1056 raeburn 11380: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11381: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11382: $currdir,\%is_dir,
11383: \%children,\%parent,
1.1056 raeburn 11384: \@contents,\%dirorder,
11385: \%titles,$wantform);
1.1055 raeburn 11386: if ($datatable ne '') {
11387: $output .= &archive_options_form('decompressed',$datatable,
11388: $count,$hiddenelem);
1.1065 raeburn 11389: my $startcount = 6;
1.1055 raeburn 11390: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11391: \%titles,\%children);
1.1055 raeburn 11392: }
1.1067 raeburn 11393: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 11394: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 11395: my %displayed;
11396: my $total = 1;
11397: $env{'form.archive_directory'} = [];
11398: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11399: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11400: $path =~ s{/$}{};
11401: my $item;
11402: if ($path ne '') {
11403: $item = "$path/$titles{$i}";
11404: } else {
11405: $item = $titles{$i};
11406: }
11407: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11408: if ($item eq $contents[0]) {
11409: push(@{$env{'form.archive_directory'}},$i);
11410: $env{'form.archive_'.$i} = 'display';
11411: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11412: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 11413: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
11414: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 11415: $env{'form.archive_'.$i} = 'display';
11416: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11417: $displayed{'web'} = $i;
11418: } else {
1.1075.2.59 raeburn 11419: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
11420: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
11421: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 11422: push(@{$env{'form.archive_directory'}},$i);
11423: }
11424: $env{'form.archive_'.$i} = 'dependency';
11425: }
11426: $total ++;
11427: }
11428: for (my $i=1; $i<$total; $i++) {
11429: next if ($i == $displayed{'web'});
11430: next if ($i == $displayed{'folder'});
11431: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11432: }
11433: $env{'form.phase'} = 'decompress_cleanup';
11434: $env{'form.archivedelete'} = 1;
11435: $env{'form.archive_count'} = $total-1;
11436: $output .=
11437: &process_extracted_files('coursedocs',$docudom,
11438: $docuname,$destination,
11439: $dir_root,$hiddenelem);
11440: }
1.1055 raeburn 11441: } else {
11442: $warning = &mt('No new items extracted from archive file.');
11443: }
11444: } else {
11445: $output = $display;
11446: $error = &mt('An error occurred during extraction from the archive file.');
11447: }
11448: }
11449: }
11450: }
11451: if ($error) {
11452: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11453: $error.'</p>'."\n";
11454: }
11455: if ($warning) {
11456: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11457: }
11458: return $output;
11459: }
11460:
11461: sub get_extracted {
1.1056 raeburn 11462: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11463: $titles,$wantform) = @_;
1.1055 raeburn 11464: my $count = 0;
11465: my $depth = 0;
11466: my $datatable;
1.1056 raeburn 11467: my @hierarchy;
1.1055 raeburn 11468: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11469: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11470: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11471: foreach my $item (@{$contents}) {
11472: $count ++;
1.1056 raeburn 11473: @{$dirorder->{$count}} = @hierarchy;
11474: $titles->{$count} = $item;
1.1055 raeburn 11475: &archive_hierarchy($depth,$count,$parent,$children);
11476: if ($wantform) {
11477: $datatable .= &archive_row($is_dir->{$item},$item,
11478: $currdir,$depth,$count);
11479: }
11480: if ($is_dir->{$item}) {
11481: $depth ++;
1.1056 raeburn 11482: push(@hierarchy,$count);
11483: $parent->{$depth} = $count;
1.1055 raeburn 11484: $datatable .=
11485: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11486: \$depth,\$count,\@hierarchy,$dirorder,
11487: $children,$parent,$titles,$wantform);
1.1055 raeburn 11488: $depth --;
1.1056 raeburn 11489: pop(@hierarchy);
1.1055 raeburn 11490: }
11491: }
11492: return ($count,$datatable);
11493: }
11494:
11495: sub recurse_extracted_archive {
1.1056 raeburn 11496: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11497: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11498: my $result='';
1.1056 raeburn 11499: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11500: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11501: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11502: return $result;
11503: }
11504: my $dirptr = 16384;
11505: my ($newdirlistref,$newlisterror) =
11506: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11507: if (ref($newdirlistref) eq 'ARRAY') {
11508: foreach my $dir_line (@{$newdirlistref}) {
11509: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11510: unless ($item =~ /^\.+$/) {
11511: $$count ++;
1.1056 raeburn 11512: @{$dirorder->{$$count}} = @{$hierarchy};
11513: $titles->{$$count} = $item;
1.1055 raeburn 11514: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11515:
1.1055 raeburn 11516: my $is_dir;
11517: if ($dirptr&$testdir) {
11518: $is_dir = 1;
11519: }
11520: if ($wantform) {
11521: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11522: }
11523: if ($is_dir) {
11524: $$depth ++;
1.1056 raeburn 11525: push(@{$hierarchy},$$count);
11526: $parent->{$$depth} = $$count;
1.1055 raeburn 11527: $result .=
11528: &recurse_extracted_archive("$currdir/$item",$docudom,
11529: $docuname,$depth,$count,
1.1056 raeburn 11530: $hierarchy,$dirorder,$children,
11531: $parent,$titles,$wantform);
1.1055 raeburn 11532: $$depth --;
1.1056 raeburn 11533: pop(@{$hierarchy});
1.1055 raeburn 11534: }
11535: }
11536: }
11537: }
11538: return $result;
11539: }
11540:
11541: sub archive_hierarchy {
11542: my ($depth,$count,$parent,$children) =@_;
11543: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11544: if (exists($parent->{$depth})) {
11545: $children->{$parent->{$depth}} .= $count.':';
11546: }
11547: }
11548: return;
11549: }
11550:
11551: sub archive_row {
11552: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11553: my ($name) = ($item =~ m{([^/]+)$});
11554: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11555: 'display' => 'Add as file',
1.1055 raeburn 11556: 'dependency' => 'Include as dependency',
11557: 'discard' => 'Discard',
11558: );
11559: if ($is_dir) {
1.1059 raeburn 11560: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11561: }
1.1056 raeburn 11562: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11563: my $offset = 0;
1.1055 raeburn 11564: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11565: $offset ++;
1.1065 raeburn 11566: if ($action ne 'display') {
11567: $offset ++;
11568: }
1.1055 raeburn 11569: $output .= '<td><span class="LC_nobreak">'.
11570: '<label><input type="radio" name="archive_'.$count.
11571: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11572: my $text = $choices{$action};
11573: if ($is_dir) {
11574: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11575: if ($action eq 'display') {
1.1059 raeburn 11576: $text = &mt('Add as folder');
1.1055 raeburn 11577: }
1.1056 raeburn 11578: } else {
11579: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11580:
11581: }
11582: $output .= ' /> '.$choices{$action}.'</label></span>';
11583: if ($action eq 'dependency') {
11584: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11585: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11586: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11587: '<option value=""></option>'."\n".
11588: '</select>'."\n".
11589: '</div>';
1.1059 raeburn 11590: } elsif ($action eq 'display') {
11591: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11592: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11593: '</div>';
1.1055 raeburn 11594: }
1.1056 raeburn 11595: $output .= '</td>';
1.1055 raeburn 11596: }
11597: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11598: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11599: for (my $i=0; $i<$depth; $i++) {
11600: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11601: }
11602: if ($is_dir) {
11603: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11604: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11605: } else {
11606: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11607: }
11608: $output .= ' '.$name.'</td>'."\n".
11609: &end_data_table_row();
11610: return $output;
11611: }
11612:
11613: sub archive_options_form {
1.1065 raeburn 11614: my ($form,$display,$count,$hiddenelem) = @_;
11615: my %lt = &Apache::lonlocal::texthash(
11616: perm => 'Permanently remove archive file?',
11617: hows => 'How should each extracted item be incorporated in the course?',
11618: cont => 'Content actions for all',
11619: addf => 'Add as folder/file',
11620: incd => 'Include as dependency for a displayed file',
11621: disc => 'Discard',
11622: no => 'No',
11623: yes => 'Yes',
11624: save => 'Save',
11625: );
11626: my $output = <<"END";
11627: <form name="$form" method="post" action="">
11628: <p><span class="LC_nobreak">$lt{'perm'}
11629: <label>
11630: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11631: </label>
11632:
11633: <label>
11634: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11635: </span>
11636: </p>
11637: <input type="hidden" name="phase" value="decompress_cleanup" />
11638: <br />$lt{'hows'}
11639: <div class="LC_columnSection">
11640: <fieldset>
11641: <legend>$lt{'cont'}</legend>
11642: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11643: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11644: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11645: </fieldset>
11646: </div>
11647: END
11648: return $output.
1.1055 raeburn 11649: &start_data_table()."\n".
1.1065 raeburn 11650: $display."\n".
1.1055 raeburn 11651: &end_data_table()."\n".
11652: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11653: $hiddenelem.
1.1065 raeburn 11654: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11655: '</form>';
11656: }
11657:
11658: sub archive_javascript {
1.1056 raeburn 11659: my ($startcount,$numitems,$titles,$children) = @_;
11660: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11661: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11662: my $scripttag = <<START;
11663: <script type="text/javascript">
11664: // <![CDATA[
11665:
11666: function checkAll(form,prefix) {
11667: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11668: for (var i=0; i < form.elements.length; i++) {
11669: var id = form.elements[i].id;
11670: if ((id != '') && (id != undefined)) {
11671: if (idstr.test(id)) {
11672: if (form.elements[i].type == 'radio') {
11673: form.elements[i].checked = true;
1.1056 raeburn 11674: var nostart = i-$startcount;
1.1059 raeburn 11675: var offset = nostart%7;
11676: var count = (nostart-offset)/7;
1.1056 raeburn 11677: dependencyCheck(form,count,offset);
1.1055 raeburn 11678: }
11679: }
11680: }
11681: }
11682: }
11683:
11684: function propagateCheck(form,count) {
11685: if (count > 0) {
1.1059 raeburn 11686: var startelement = $startcount + ((count-1) * 7);
11687: for (var j=1; j<6; j++) {
11688: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11689: var item = startelement + j;
11690: if (form.elements[item].type == 'radio') {
11691: if (form.elements[item].checked) {
11692: containerCheck(form,count,j);
11693: break;
11694: }
1.1055 raeburn 11695: }
11696: }
11697: }
11698: }
11699: }
11700:
11701: numitems = $numitems
1.1056 raeburn 11702: var titles = new Array(numitems);
11703: var parents = new Array(numitems);
1.1055 raeburn 11704: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11705: parents[i] = new Array;
1.1055 raeburn 11706: }
1.1059 raeburn 11707: var maintitle = '$maintitle';
1.1055 raeburn 11708:
11709: START
11710:
1.1056 raeburn 11711: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11712: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11713: for (my $i=0; $i<@contents; $i ++) {
11714: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11715: }
11716: }
11717:
1.1056 raeburn 11718: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11719: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11720: }
11721:
1.1055 raeburn 11722: $scripttag .= <<END;
11723:
11724: function containerCheck(form,count,offset) {
11725: if (count > 0) {
1.1056 raeburn 11726: dependencyCheck(form,count,offset);
1.1059 raeburn 11727: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11728: form.elements[item].checked = true;
11729: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11730: if (parents[count].length > 0) {
11731: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11732: containerCheck(form,parents[count][j],offset);
11733: }
11734: }
11735: }
11736: }
11737: }
11738:
11739: function dependencyCheck(form,count,offset) {
11740: if (count > 0) {
1.1059 raeburn 11741: var chosen = (offset+$startcount)+7*(count-1);
11742: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11743: var currtype = form.elements[depitem].type;
11744: if (form.elements[chosen].value == 'dependency') {
11745: document.getElementById('arc_depon_'+count).style.display='block';
11746: form.elements[depitem].options.length = 0;
11747: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 11748: for (var i=1; i<=numitems; i++) {
11749: if (i == count) {
11750: continue;
11751: }
1.1059 raeburn 11752: var startelement = $startcount + (i-1) * 7;
11753: for (var j=1; j<6; j++) {
11754: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11755: var item = startelement + j;
11756: if (form.elements[item].type == 'radio') {
11757: if (form.elements[item].checked) {
11758: if (form.elements[item].value == 'display') {
11759: var n = form.elements[depitem].options.length;
11760: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11761: }
11762: }
11763: }
11764: }
11765: }
11766: }
11767: } else {
11768: document.getElementById('arc_depon_'+count).style.display='none';
11769: form.elements[depitem].options.length = 0;
11770: form.elements[depitem].options[0] = new Option('Select','',true,true);
11771: }
1.1059 raeburn 11772: titleCheck(form,count,offset);
1.1056 raeburn 11773: }
11774: }
11775:
11776: function propagateSelect(form,count,offset) {
11777: if (count > 0) {
1.1065 raeburn 11778: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11779: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11780: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11781: if (parents[count].length > 0) {
11782: for (var j=0; j<parents[count].length; j++) {
11783: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11784: }
11785: }
11786: }
11787: }
11788: }
1.1056 raeburn 11789:
11790: function containerSelect(form,count,offset,picked) {
11791: if (count > 0) {
1.1065 raeburn 11792: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11793: if (form.elements[item].type == 'radio') {
11794: if (form.elements[item].value == 'dependency') {
11795: if (form.elements[item+1].type == 'select-one') {
11796: for (var i=0; i<form.elements[item+1].options.length; i++) {
11797: if (form.elements[item+1].options[i].value == picked) {
11798: form.elements[item+1].selectedIndex = i;
11799: break;
11800: }
11801: }
11802: }
11803: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11804: if (parents[count].length > 0) {
11805: for (var j=0; j<parents[count].length; j++) {
11806: containerSelect(form,parents[count][j],offset,picked);
11807: }
11808: }
11809: }
11810: }
11811: }
11812: }
11813: }
11814:
1.1059 raeburn 11815: function titleCheck(form,count,offset) {
11816: if (count > 0) {
11817: var chosen = (offset+$startcount)+7*(count-1);
11818: var depitem = $startcount + ((count-1) * 7) + 2;
11819: var currtype = form.elements[depitem].type;
11820: if (form.elements[chosen].value == 'display') {
11821: document.getElementById('arc_title_'+count).style.display='block';
11822: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11823: document.getElementById('archive_title_'+count).value=maintitle;
11824: }
11825: } else {
11826: document.getElementById('arc_title_'+count).style.display='none';
11827: if (currtype == 'text') {
11828: document.getElementById('archive_title_'+count).value='';
11829: }
11830: }
11831: }
11832: return;
11833: }
11834:
1.1055 raeburn 11835: // ]]>
11836: </script>
11837: END
11838: return $scripttag;
11839: }
11840:
11841: sub process_extracted_files {
1.1067 raeburn 11842: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11843: my $numitems = $env{'form.archive_count'};
11844: return unless ($numitems);
11845: my @ids=&Apache::lonnet::current_machine_ids();
11846: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11847: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11848: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11849: if (grep(/^\Q$docuhome\E$/,@ids)) {
11850: $prefix = &LONCAPA::propath($docudom,$docuname);
11851: $pathtocheck = "$dir_root/$destination";
11852: $dir = $dir_root;
11853: $ishome = 1;
11854: } else {
11855: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11856: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11857: $dir = "$dir_root/$docudom/$docuname";
11858: }
11859: my $currdir = "$dir_root/$destination";
11860: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11861: if ($env{'form.folderpath'}) {
11862: my @items = split('&',$env{'form.folderpath'});
11863: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 11864: if ($env{'form.folderpath'} =~ /\:1$/) {
11865: $containers{'0'}='page';
11866: } else {
11867: $containers{'0'}='sequence';
11868: }
1.1055 raeburn 11869: }
11870: my @archdirs = &get_env_multiple('form.archive_directory');
11871: if ($numitems) {
11872: for (my $i=1; $i<=$numitems; $i++) {
11873: my $path = $env{'form.archive_content_'.$i};
11874: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11875: my $item = $1;
11876: $toplevelitems{$item} = $i;
11877: if (grep(/^\Q$i\E$/,@archdirs)) {
11878: $is_dir{$item} = 1;
11879: }
11880: }
11881: }
11882: }
1.1067 raeburn 11883: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11884: if (keys(%toplevelitems) > 0) {
11885: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11886: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11887: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11888: }
1.1066 raeburn 11889: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11890: if ($numitems) {
11891: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 11892: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11893: my $path = $env{'form.archive_content_'.$i};
11894: if ($path =~ /^\Q$pathtocheck\E/) {
11895: if ($env{'form.archive_'.$i} eq 'discard') {
11896: if ($prefix ne '' && $path ne '') {
11897: if (-e $prefix.$path) {
1.1066 raeburn 11898: if ((@archdirs > 0) &&
11899: (grep(/^\Q$i\E$/,@archdirs))) {
11900: $todeletedir{$prefix.$path} = 1;
11901: } else {
11902: $todelete{$prefix.$path} = 1;
11903: }
1.1055 raeburn 11904: }
11905: }
11906: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11907: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11908: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11909: $docstitle = $env{'form.archive_title_'.$i};
11910: if ($docstitle eq '') {
11911: $docstitle = $title;
11912: }
1.1055 raeburn 11913: $outer = 0;
1.1056 raeburn 11914: if (ref($dirorder{$i}) eq 'ARRAY') {
11915: if (@{$dirorder{$i}} > 0) {
11916: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11917: if ($env{'form.archive_'.$item} eq 'display') {
11918: $outer = $item;
11919: last;
11920: }
11921: }
11922: }
11923: }
11924: my ($errtext,$fatal) =
11925: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11926: '/'.$folders{$outer}.'.'.
11927: $containers{$outer});
11928: next if ($fatal);
11929: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11930: if ($context eq 'coursedocs') {
1.1056 raeburn 11931: $mapinner{$i} = time;
1.1055 raeburn 11932: $folders{$i} = 'default_'.$mapinner{$i};
11933: $containers{$i} = 'sequence';
11934: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11935: $folders{$i}.'.'.$containers{$i};
11936: my $newidx = &LONCAPA::map::getresidx();
11937: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11938: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11939: push(@LONCAPA::map::order,$newidx);
11940: my ($outtext,$errtext) =
11941: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11942: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11943: '.'.$containers{$outer},1,1);
1.1056 raeburn 11944: $newseqid{$i} = $newidx;
1.1067 raeburn 11945: unless ($errtext) {
11946: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11947: }
1.1055 raeburn 11948: }
11949: } else {
11950: if ($context eq 'coursedocs') {
11951: my $newidx=&LONCAPA::map::getresidx();
11952: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11953: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11954: $title;
11955: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11956: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11957: }
11958: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11959: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11960: }
11961: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11962: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11963: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11964: unless ($ishome) {
11965: my $fetch = "$newdest{$i}/$title";
11966: $fetch =~ s/^\Q$prefix$dir\E//;
11967: $prompttofetch{$fetch} = 1;
11968: }
1.1055 raeburn 11969: }
11970: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11971: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11972: push(@LONCAPA::map::order, $newidx);
11973: my ($outtext,$errtext)=
11974: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11975: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11976: '.'.$containers{$outer},1,1);
1.1067 raeburn 11977: unless ($errtext) {
11978: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11979: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11980: }
11981: }
1.1055 raeburn 11982: }
11983: }
1.1075.2.11 raeburn 11984: }
11985: } else {
11986: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11987: }
11988: }
11989: for (my $i=1; $i<=$numitems; $i++) {
11990: next unless ($env{'form.archive_'.$i} eq 'dependency');
11991: my $path = $env{'form.archive_content_'.$i};
11992: if ($path =~ /^\Q$pathtocheck\E/) {
11993: my ($title) = ($path =~ m{/([^/]+)$});
11994: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11995: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11996: if (ref($dirorder{$i}) eq 'ARRAY') {
11997: my ($itemidx,$fullpath,$relpath);
11998: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11999: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12000: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12001: if ($dirorder{$i}->[$j] eq $container) {
12002: $itemidx = $j;
1.1056 raeburn 12003: }
12004: }
1.1075.2.11 raeburn 12005: }
12006: if ($itemidx eq '') {
12007: $itemidx = 0;
12008: }
12009: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12010: if ($mapinner{$referrer{$i}}) {
12011: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12012: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12013: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12014: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12015: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12016: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12017: if (!-e $fullpath) {
12018: mkdir($fullpath,0755);
1.1056 raeburn 12019: }
12020: }
1.1075.2.11 raeburn 12021: } else {
12022: last;
1.1056 raeburn 12023: }
1.1075.2.11 raeburn 12024: }
12025: }
12026: } elsif ($newdest{$referrer{$i}}) {
12027: $fullpath = $newdest{$referrer{$i}};
12028: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12029: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12030: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12031: last;
12032: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12033: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12034: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12035: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12036: if (!-e $fullpath) {
12037: mkdir($fullpath,0755);
1.1056 raeburn 12038: }
12039: }
1.1075.2.11 raeburn 12040: } else {
12041: last;
1.1056 raeburn 12042: }
1.1075.2.11 raeburn 12043: }
12044: }
12045: if ($fullpath ne '') {
12046: if (-e "$prefix$path") {
12047: system("mv $prefix$path $fullpath/$title");
12048: }
12049: if (-e "$fullpath/$title") {
12050: my $showpath;
12051: if ($relpath ne '') {
12052: $showpath = "$relpath/$title";
12053: } else {
12054: $showpath = "/$title";
1.1056 raeburn 12055: }
1.1075.2.11 raeburn 12056: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12057: }
12058: unless ($ishome) {
12059: my $fetch = "$fullpath/$title";
12060: $fetch =~ s/^\Q$prefix$dir\E//;
12061: $prompttofetch{$fetch} = 1;
1.1055 raeburn 12062: }
12063: }
12064: }
1.1075.2.11 raeburn 12065: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12066: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12067: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12068: }
12069: } else {
1.1075.2.11 raeburn 12070: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 12071: }
12072: }
12073: if (keys(%todelete)) {
12074: foreach my $key (keys(%todelete)) {
12075: unlink($key);
1.1066 raeburn 12076: }
12077: }
12078: if (keys(%todeletedir)) {
12079: foreach my $key (keys(%todeletedir)) {
12080: rmdir($key);
12081: }
12082: }
12083: foreach my $dir (sort(keys(%is_dir))) {
12084: if (($pathtocheck ne '') && ($dir ne '')) {
12085: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12086: }
12087: }
1.1067 raeburn 12088: if ($result ne '') {
12089: $output .= '<ul>'."\n".
12090: $result."\n".
12091: '</ul>';
12092: }
12093: unless ($ishome) {
12094: my $replicationfail;
12095: foreach my $item (keys(%prompttofetch)) {
12096: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12097: unless ($fetchresult eq 'ok') {
12098: $replicationfail .= '<li>'.$item.'</li>'."\n";
12099: }
12100: }
12101: if ($replicationfail) {
12102: $output .= '<p class="LC_error">'.
12103: &mt('Course home server failed to retrieve:').'<ul>'.
12104: $replicationfail.
12105: '</ul></p>';
12106: }
12107: }
1.1055 raeburn 12108: } else {
12109: $warning = &mt('No items found in archive.');
12110: }
12111: if ($error) {
12112: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12113: $error.'</p>'."\n";
12114: }
12115: if ($warning) {
12116: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12117: }
12118: return $output;
12119: }
12120:
1.1066 raeburn 12121: sub cleanup_empty_dirs {
12122: my ($path) = @_;
12123: if (($path ne '') && (-d $path)) {
12124: if (opendir(my $dirh,$path)) {
12125: my @dircontents = grep(!/^\./,readdir($dirh));
12126: my $numitems = 0;
12127: foreach my $item (@dircontents) {
12128: if (-d "$path/$item") {
1.1075.2.28 raeburn 12129: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12130: if (-e "$path/$item") {
12131: $numitems ++;
12132: }
12133: } else {
12134: $numitems ++;
12135: }
12136: }
12137: if ($numitems == 0) {
12138: rmdir($path);
12139: }
12140: closedir($dirh);
12141: }
12142: }
12143: return;
12144: }
12145:
1.41 ng 12146: =pod
1.45 matthew 12147:
1.1075.2.56 raeburn 12148: =item * &get_folder_hierarchy()
1.1068 raeburn 12149:
12150: Provides hierarchy of names of folders/sub-folders containing the current
12151: item,
12152:
12153: Inputs: 3
12154: - $navmap - navmaps object
12155:
12156: - $map - url for map (either the trigger itself, or map containing
12157: the resource, which is the trigger).
12158:
12159: - $showitem - 1 => show title for map itself; 0 => do not show.
12160:
12161: Outputs: 1 @pathitems - array of folder/subfolder names.
12162:
12163: =cut
12164:
12165: sub get_folder_hierarchy {
12166: my ($navmap,$map,$showitem) = @_;
12167: my @pathitems;
12168: if (ref($navmap)) {
12169: my $mapres = $navmap->getResourceByUrl($map);
12170: if (ref($mapres)) {
12171: my $pcslist = $mapres->map_hierarchy();
12172: if ($pcslist ne '') {
12173: my @pcs = split(/,/,$pcslist);
12174: foreach my $pc (@pcs) {
12175: if ($pc == 1) {
1.1075.2.38 raeburn 12176: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12177: } else {
12178: my $res = $navmap->getByMapPc($pc);
12179: if (ref($res)) {
12180: my $title = $res->compTitle();
12181: $title =~ s/\W+/_/g;
12182: if ($title ne '') {
12183: push(@pathitems,$title);
12184: }
12185: }
12186: }
12187: }
12188: }
1.1071 raeburn 12189: if ($showitem) {
12190: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12191: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12192: } else {
12193: my $maptitle = $mapres->compTitle();
12194: $maptitle =~ s/\W+/_/g;
12195: if ($maptitle ne '') {
12196: push(@pathitems,$maptitle);
12197: }
1.1068 raeburn 12198: }
12199: }
12200: }
12201: }
12202: return @pathitems;
12203: }
12204:
12205: =pod
12206:
1.1015 raeburn 12207: =item * &get_turnedin_filepath()
12208:
12209: Determines path in a user's portfolio file for storage of files uploaded
12210: to a specific essayresponse or dropbox item.
12211:
12212: Inputs: 3 required + 1 optional.
12213: $symb is symb for resource, $uname and $udom are for current user (required).
12214: $caller is optional (can be "submission", if routine is called when storing
12215: an upoaded file when "Submit Answer" button was pressed).
12216:
12217: Returns array containing $path and $multiresp.
12218: $path is path in portfolio. $multiresp is 1 if this resource contains more
12219: than one file upload item. Callers of routine should append partid as a
12220: subdirectory to $path in cases where $multiresp is 1.
12221:
12222: Called by: homework/essayresponse.pm and homework/structuretags.pm
12223:
12224: =cut
12225:
12226: sub get_turnedin_filepath {
12227: my ($symb,$uname,$udom,$caller) = @_;
12228: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12229: my $turnindir;
12230: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12231: $turnindir = $userhash{'turnindir'};
12232: my ($path,$multiresp);
12233: if ($turnindir eq '') {
12234: if ($caller eq 'submission') {
12235: $turnindir = &mt('turned in');
12236: $turnindir =~ s/\W+/_/g;
12237: my %newhash = (
12238: 'turnindir' => $turnindir,
12239: );
12240: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12241: }
12242: }
12243: if ($turnindir ne '') {
12244: $path = '/'.$turnindir.'/';
12245: my ($multipart,$turnin,@pathitems);
12246: my $navmap = Apache::lonnavmaps::navmap->new();
12247: if (defined($navmap)) {
12248: my $mapres = $navmap->getResourceByUrl($map);
12249: if (ref($mapres)) {
12250: my $pcslist = $mapres->map_hierarchy();
12251: if ($pcslist ne '') {
12252: foreach my $pc (split(/,/,$pcslist)) {
12253: my $res = $navmap->getByMapPc($pc);
12254: if (ref($res)) {
12255: my $title = $res->compTitle();
12256: $title =~ s/\W+/_/g;
12257: if ($title ne '') {
1.1075.2.48 raeburn 12258: if (($pc > 1) && (length($title) > 12)) {
12259: $title = substr($title,0,12);
12260: }
1.1015 raeburn 12261: push(@pathitems,$title);
12262: }
12263: }
12264: }
12265: }
12266: my $maptitle = $mapres->compTitle();
12267: $maptitle =~ s/\W+/_/g;
12268: if ($maptitle ne '') {
1.1075.2.48 raeburn 12269: if (length($maptitle) > 12) {
12270: $maptitle = substr($maptitle,0,12);
12271: }
1.1015 raeburn 12272: push(@pathitems,$maptitle);
12273: }
12274: unless ($env{'request.state'} eq 'construct') {
12275: my $res = $navmap->getBySymb($symb);
12276: if (ref($res)) {
12277: my $partlist = $res->parts();
12278: my $totaluploads = 0;
12279: if (ref($partlist) eq 'ARRAY') {
12280: foreach my $part (@{$partlist}) {
12281: my @types = $res->responseType($part);
12282: my @ids = $res->responseIds($part);
12283: for (my $i=0; $i < scalar(@ids); $i++) {
12284: if ($types[$i] eq 'essay') {
12285: my $partid = $part.'_'.$ids[$i];
12286: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12287: $totaluploads ++;
12288: }
12289: }
12290: }
12291: }
12292: if ($totaluploads > 1) {
12293: $multiresp = 1;
12294: }
12295: }
12296: }
12297: }
12298: } else {
12299: return;
12300: }
12301: } else {
12302: return;
12303: }
12304: my $restitle=&Apache::lonnet::gettitle($symb);
12305: $restitle =~ s/\W+/_/g;
12306: if ($restitle eq '') {
12307: $restitle = ($resurl =~ m{/[^/]+$});
12308: if ($restitle eq '') {
12309: $restitle = time;
12310: }
12311: }
1.1075.2.48 raeburn 12312: if (length($restitle) > 12) {
12313: $restitle = substr($restitle,0,12);
12314: }
1.1015 raeburn 12315: push(@pathitems,$restitle);
12316: $path .= join('/',@pathitems);
12317: }
12318: return ($path,$multiresp);
12319: }
12320:
12321: =pod
12322:
1.464 albertel 12323: =back
1.41 ng 12324:
1.112 bowersj2 12325: =head1 CSV Upload/Handling functions
1.38 albertel 12326:
1.41 ng 12327: =over 4
12328:
1.648 raeburn 12329: =item * &upfile_store($r)
1.41 ng 12330:
12331: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12332: needs $env{'form.upfile'}
1.41 ng 12333: returns $datatoken to be put into hidden field
12334:
12335: =cut
1.31 albertel 12336:
12337: sub upfile_store {
12338: my $r=shift;
1.258 albertel 12339: $env{'form.upfile'}=~s/\r/\n/gs;
12340: $env{'form.upfile'}=~s/\f/\n/gs;
12341: $env{'form.upfile'}=~s/\n+/\n/gs;
12342: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12343:
1.258 albertel 12344: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12345: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12346: {
1.158 raeburn 12347: my $datafile = $r->dir_config('lonDaemons').
12348: '/tmp/'.$datatoken.'.tmp';
12349: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12350: print $fh $env{'form.upfile'};
1.158 raeburn 12351: close($fh);
12352: }
1.31 albertel 12353: }
12354: return $datatoken;
12355: }
12356:
1.56 matthew 12357: =pod
12358:
1.648 raeburn 12359: =item * &load_tmp_file($r)
1.41 ng 12360:
12361: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12362: needs $env{'form.datatoken'},
12363: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12364:
12365: =cut
1.31 albertel 12366:
12367: sub load_tmp_file {
12368: my $r=shift;
12369: my @studentdata=();
12370: {
1.158 raeburn 12371: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12372: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12373: if ( open(my $fh,"<$studentfile") ) {
12374: @studentdata=<$fh>;
12375: close($fh);
12376: }
1.31 albertel 12377: }
1.258 albertel 12378: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12379: }
12380:
1.56 matthew 12381: =pod
12382:
1.648 raeburn 12383: =item * &upfile_record_sep()
1.41 ng 12384:
12385: Separate uploaded file into records
12386: returns array of records,
1.258 albertel 12387: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12388:
12389: =cut
1.31 albertel 12390:
12391: sub upfile_record_sep {
1.258 albertel 12392: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12393: } else {
1.248 albertel 12394: my @records;
1.258 albertel 12395: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12396: if ($line=~/^\s*$/) { next; }
12397: push(@records,$line);
12398: }
12399: return @records;
1.31 albertel 12400: }
12401: }
12402:
1.56 matthew 12403: =pod
12404:
1.648 raeburn 12405: =item * &record_sep($record)
1.41 ng 12406:
1.258 albertel 12407: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12408:
12409: =cut
12410:
1.263 www 12411: sub takeleft {
12412: my $index=shift;
12413: return substr('0000'.$index,-4,4);
12414: }
12415:
1.31 albertel 12416: sub record_sep {
12417: my $record=shift;
12418: my %components=();
1.258 albertel 12419: if ($env{'form.upfiletype'} eq 'xml') {
12420: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12421: my $i=0;
1.356 albertel 12422: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12423: $field=~s/^(\"|\')//;
12424: $field=~s/(\"|\')$//;
1.263 www 12425: $components{&takeleft($i)}=$field;
1.31 albertel 12426: $i++;
12427: }
1.258 albertel 12428: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12429: my $i=0;
1.356 albertel 12430: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12431: $field=~s/^(\"|\')//;
12432: $field=~s/(\"|\')$//;
1.263 www 12433: $components{&takeleft($i)}=$field;
1.31 albertel 12434: $i++;
12435: }
12436: } else {
1.561 www 12437: my $separator=',';
1.480 banghart 12438: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12439: $separator=';';
1.480 banghart 12440: }
1.31 albertel 12441: my $i=0;
1.561 www 12442: # the character we are looking for to indicate the end of a quote or a record
12443: my $looking_for=$separator;
12444: # do not add the characters to the fields
12445: my $ignore=0;
12446: # we just encountered a separator (or the beginning of the record)
12447: my $just_found_separator=1;
12448: # store the field we are working on here
12449: my $field='';
12450: # work our way through all characters in record
12451: foreach my $character ($record=~/(.)/g) {
12452: if ($character eq $looking_for) {
12453: if ($character ne $separator) {
12454: # Found the end of a quote, again looking for separator
12455: $looking_for=$separator;
12456: $ignore=1;
12457: } else {
12458: # Found a separator, store away what we got
12459: $components{&takeleft($i)}=$field;
12460: $i++;
12461: $just_found_separator=1;
12462: $ignore=0;
12463: $field='';
12464: }
12465: next;
12466: }
12467: # single or double quotation marks after a separator indicate beginning of a quote
12468: # we are now looking for the end of the quote and need to ignore separators
12469: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12470: $looking_for=$character;
12471: next;
12472: }
12473: # ignore would be true after we reached the end of a quote
12474: if ($ignore) { next; }
12475: if (($just_found_separator) && ($character=~/\s/)) { next; }
12476: $field.=$character;
12477: $just_found_separator=0;
1.31 albertel 12478: }
1.561 www 12479: # catch the very last entry, since we never encountered the separator
12480: $components{&takeleft($i)}=$field;
1.31 albertel 12481: }
12482: return %components;
12483: }
12484:
1.144 matthew 12485: ######################################################
12486: ######################################################
12487:
1.56 matthew 12488: =pod
12489:
1.648 raeburn 12490: =item * &upfile_select_html()
1.41 ng 12491:
1.144 matthew 12492: Return HTML code to select a file from the users machine and specify
12493: the file type.
1.41 ng 12494:
12495: =cut
12496:
1.144 matthew 12497: ######################################################
12498: ######################################################
1.31 albertel 12499: sub upfile_select_html {
1.144 matthew 12500: my %Types = (
12501: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12502: semisv => &mt('Semicolon separated values'),
1.144 matthew 12503: space => &mt('Space separated'),
12504: tab => &mt('Tabulator separated'),
12505: # xml => &mt('HTML/XML'),
12506: );
12507: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12508: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12509: foreach my $type (sort(keys(%Types))) {
12510: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12511: }
12512: $Str .= "</select>\n";
12513: return $Str;
1.31 albertel 12514: }
12515:
1.301 albertel 12516: sub get_samples {
12517: my ($records,$toget) = @_;
12518: my @samples=({});
12519: my $got=0;
12520: foreach my $rec (@$records) {
12521: my %temp = &record_sep($rec);
12522: if (! grep(/\S/, values(%temp))) { next; }
12523: if (%temp) {
12524: $samples[$got]=\%temp;
12525: $got++;
12526: if ($got == $toget) { last; }
12527: }
12528: }
12529: return \@samples;
12530: }
12531:
1.144 matthew 12532: ######################################################
12533: ######################################################
12534:
1.56 matthew 12535: =pod
12536:
1.648 raeburn 12537: =item * &csv_print_samples($r,$records)
1.41 ng 12538:
12539: Prints a table of sample values from each column uploaded $r is an
12540: Apache Request ref, $records is an arrayref from
12541: &Apache::loncommon::upfile_record_sep
12542:
12543: =cut
12544:
1.144 matthew 12545: ######################################################
12546: ######################################################
1.31 albertel 12547: sub csv_print_samples {
12548: my ($r,$records) = @_;
1.662 bisitz 12549: my $samples = &get_samples($records,5);
1.301 albertel 12550:
1.594 raeburn 12551: $r->print(&mt('Samples').'<br />'.&start_data_table().
12552: &start_data_table_header_row());
1.356 albertel 12553: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12554: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12555: $r->print(&end_data_table_header_row());
1.301 albertel 12556: foreach my $hash (@$samples) {
1.594 raeburn 12557: $r->print(&start_data_table_row());
1.356 albertel 12558: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12559: $r->print('<td>');
1.356 albertel 12560: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12561: $r->print('</td>');
12562: }
1.594 raeburn 12563: $r->print(&end_data_table_row());
1.31 albertel 12564: }
1.594 raeburn 12565: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12566: }
12567:
1.144 matthew 12568: ######################################################
12569: ######################################################
12570:
1.56 matthew 12571: =pod
12572:
1.648 raeburn 12573: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12574:
12575: Prints a table to create associations between values and table columns.
1.144 matthew 12576:
1.41 ng 12577: $r is an Apache Request ref,
12578: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12579: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12580:
12581: =cut
12582:
1.144 matthew 12583: ######################################################
12584: ######################################################
1.31 albertel 12585: sub csv_print_select_table {
12586: my ($r,$records,$d) = @_;
1.301 albertel 12587: my $i=0;
12588: my $samples = &get_samples($records,1);
1.144 matthew 12589: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12590: &start_data_table().&start_data_table_header_row().
1.144 matthew 12591: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12592: '<th>'.&mt('Column').'</th>'.
12593: &end_data_table_header_row()."\n");
1.356 albertel 12594: foreach my $array_ref (@$d) {
12595: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12596: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12597:
1.875 bisitz 12598: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12599: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12600: $r->print('<option value="none"></option>');
1.356 albertel 12601: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12602: $r->print('<option value="'.$sample.'"'.
12603: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12604: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12605: }
1.594 raeburn 12606: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12607: $i++;
12608: }
1.594 raeburn 12609: $r->print(&end_data_table());
1.31 albertel 12610: $i--;
12611: return $i;
12612: }
1.56 matthew 12613:
1.144 matthew 12614: ######################################################
12615: ######################################################
12616:
1.56 matthew 12617: =pod
1.31 albertel 12618:
1.648 raeburn 12619: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12620:
12621: Prints a table of sample values from the upload and can make associate samples to internal names.
12622:
12623: $r is an Apache Request ref,
12624: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12625: $d is an array of 2 element arrays (internal name, displayed name)
12626:
12627: =cut
12628:
1.144 matthew 12629: ######################################################
12630: ######################################################
1.31 albertel 12631: sub csv_samples_select_table {
12632: my ($r,$records,$d) = @_;
12633: my $i=0;
1.144 matthew 12634: #
1.662 bisitz 12635: my $max_samples = 5;
12636: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12637: $r->print(&start_data_table().
12638: &start_data_table_header_row().'<th>'.
12639: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12640: &end_data_table_header_row());
1.301 albertel 12641:
12642: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12643: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12644: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12645: foreach my $option (@$d) {
12646: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12647: $r->print('<option value="'.$value.'"'.
1.253 albertel 12648: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12649: $display.'</option>');
1.31 albertel 12650: }
12651: $r->print('</select></td><td>');
1.662 bisitz 12652: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12653: if (defined($samples->[$line]{$key})) {
12654: $r->print($samples->[$line]{$key}."<br />\n");
12655: }
12656: }
1.594 raeburn 12657: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12658: $i++;
12659: }
1.594 raeburn 12660: $r->print(&end_data_table());
1.31 albertel 12661: $i--;
12662: return($i);
1.115 matthew 12663: }
12664:
1.144 matthew 12665: ######################################################
12666: ######################################################
12667:
1.115 matthew 12668: =pod
12669:
1.648 raeburn 12670: =item * &clean_excel_name($name)
1.115 matthew 12671:
12672: Returns a replacement for $name which does not contain any illegal characters.
12673:
12674: =cut
12675:
1.144 matthew 12676: ######################################################
12677: ######################################################
1.115 matthew 12678: sub clean_excel_name {
12679: my ($name) = @_;
12680: $name =~ s/[:\*\?\/\\]//g;
12681: if (length($name) > 31) {
12682: $name = substr($name,0,31);
12683: }
12684: return $name;
1.25 albertel 12685: }
1.84 albertel 12686:
1.85 albertel 12687: =pod
12688:
1.648 raeburn 12689: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12690:
12691: Returns either 1 or undef
12692:
12693: 1 if the part is to be hidden, undef if it is to be shown
12694:
12695: Arguments are:
12696:
12697: $id the id of the part to be checked
12698: $symb, optional the symb of the resource to check
12699: $udom, optional the domain of the user to check for
12700: $uname, optional the username of the user to check for
12701:
12702: =cut
1.84 albertel 12703:
12704: sub check_if_partid_hidden {
12705: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12706: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12707: $symb,$udom,$uname);
1.141 albertel 12708: my $truth=1;
12709: #if the string starts with !, then the list is the list to show not hide
12710: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12711: my @hiddenlist=split(/,/,$hiddenparts);
12712: foreach my $checkid (@hiddenlist) {
1.141 albertel 12713: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12714: }
1.141 albertel 12715: return !$truth;
1.84 albertel 12716: }
1.127 matthew 12717:
1.138 matthew 12718:
12719: ############################################################
12720: ############################################################
12721:
12722: =pod
12723:
1.157 matthew 12724: =back
12725:
1.138 matthew 12726: =head1 cgi-bin script and graphing routines
12727:
1.157 matthew 12728: =over 4
12729:
1.648 raeburn 12730: =item * &get_cgi_id()
1.138 matthew 12731:
12732: Inputs: none
12733:
12734: Returns an id which can be used to pass environment variables
12735: to various cgi-bin scripts. These environment variables will
12736: be removed from the users environment after a given time by
12737: the routine &Apache::lonnet::transfer_profile_to_env.
12738:
12739: =cut
12740:
12741: ############################################################
12742: ############################################################
1.152 albertel 12743: my $uniq=0;
1.136 matthew 12744: sub get_cgi_id {
1.154 albertel 12745: $uniq=($uniq+1)%100000;
1.280 albertel 12746: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12747: }
12748:
1.127 matthew 12749: ############################################################
12750: ############################################################
12751:
12752: =pod
12753:
1.648 raeburn 12754: =item * &DrawBarGraph()
1.127 matthew 12755:
1.138 matthew 12756: Facilitates the plotting of data in a (stacked) bar graph.
12757: Puts plot definition data into the users environment in order for
12758: graph.png to plot it. Returns an <img> tag for the plot.
12759: The bars on the plot are labeled '1','2',...,'n'.
12760:
12761: Inputs:
12762:
12763: =over 4
12764:
12765: =item $Title: string, the title of the plot
12766:
12767: =item $xlabel: string, text describing the X-axis of the plot
12768:
12769: =item $ylabel: string, text describing the Y-axis of the plot
12770:
12771: =item $Max: scalar, the maximum Y value to use in the plot
12772: If $Max is < any data point, the graph will not be rendered.
12773:
1.140 matthew 12774: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12775: they are plotted. If undefined, default values will be used.
12776:
1.178 matthew 12777: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12778:
1.138 matthew 12779: =item @Values: An array of array references. Each array reference holds data
12780: to be plotted in a stacked bar chart.
12781:
1.239 matthew 12782: =item If the final element of @Values is a hash reference the key/value
12783: pairs will be added to the graph definition.
12784:
1.138 matthew 12785: =back
12786:
12787: Returns:
12788:
12789: An <img> tag which references graph.png and the appropriate identifying
12790: information for the plot.
12791:
1.127 matthew 12792: =cut
12793:
12794: ############################################################
12795: ############################################################
1.134 matthew 12796: sub DrawBarGraph {
1.178 matthew 12797: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12798: #
12799: if (! defined($colors)) {
12800: $colors = ['#33ff00',
12801: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12802: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12803: ];
12804: }
1.228 matthew 12805: my $extra_settings = {};
12806: if (ref($Values[-1]) eq 'HASH') {
12807: $extra_settings = pop(@Values);
12808: }
1.127 matthew 12809: #
1.136 matthew 12810: my $identifier = &get_cgi_id();
12811: my $id = 'cgi.'.$identifier;
1.129 matthew 12812: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12813: return '';
12814: }
1.225 matthew 12815: #
12816: my @Labels;
12817: if (defined($labels)) {
12818: @Labels = @$labels;
12819: } else {
12820: for (my $i=0;$i<@{$Values[0]};$i++) {
12821: push (@Labels,$i+1);
12822: }
12823: }
12824: #
1.129 matthew 12825: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12826: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12827: my %ValuesHash;
12828: my $NumSets=1;
12829: foreach my $array (@Values) {
12830: next if (! ref($array));
1.136 matthew 12831: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12832: join(',',@$array);
1.129 matthew 12833: }
1.127 matthew 12834: #
1.136 matthew 12835: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12836: if ($NumBars < 3) {
12837: $width = 120+$NumBars*32;
1.220 matthew 12838: $xskip = 1;
1.225 matthew 12839: $bar_width = 30;
12840: } elsif ($NumBars < 5) {
12841: $width = 120+$NumBars*20;
12842: $xskip = 1;
12843: $bar_width = 20;
1.220 matthew 12844: } elsif ($NumBars < 10) {
1.136 matthew 12845: $width = 120+$NumBars*15;
12846: $xskip = 1;
12847: $bar_width = 15;
12848: } elsif ($NumBars <= 25) {
12849: $width = 120+$NumBars*11;
12850: $xskip = 5;
12851: $bar_width = 8;
12852: } elsif ($NumBars <= 50) {
12853: $width = 120+$NumBars*8;
12854: $xskip = 5;
12855: $bar_width = 4;
12856: } else {
12857: $width = 120+$NumBars*8;
12858: $xskip = 5;
12859: $bar_width = 4;
12860: }
12861: #
1.137 matthew 12862: $Max = 1 if ($Max < 1);
12863: if ( int($Max) < $Max ) {
12864: $Max++;
12865: $Max = int($Max);
12866: }
1.127 matthew 12867: $Title = '' if (! defined($Title));
12868: $xlabel = '' if (! defined($xlabel));
12869: $ylabel = '' if (! defined($ylabel));
1.369 www 12870: $ValuesHash{$id.'.title'} = &escape($Title);
12871: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12872: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12873: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12874: $ValuesHash{$id.'.NumBars'} = $NumBars;
12875: $ValuesHash{$id.'.NumSets'} = $NumSets;
12876: $ValuesHash{$id.'.PlotType'} = 'bar';
12877: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12878: $ValuesHash{$id.'.height'} = $height;
12879: $ValuesHash{$id.'.width'} = $width;
12880: $ValuesHash{$id.'.xskip'} = $xskip;
12881: $ValuesHash{$id.'.bar_width'} = $bar_width;
12882: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12883: #
1.228 matthew 12884: # Deal with other parameters
12885: while (my ($key,$value) = each(%$extra_settings)) {
12886: $ValuesHash{$id.'.'.$key} = $value;
12887: }
12888: #
1.646 raeburn 12889: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12890: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12891: }
12892:
12893: ############################################################
12894: ############################################################
12895:
12896: =pod
12897:
1.648 raeburn 12898: =item * &DrawXYGraph()
1.137 matthew 12899:
1.138 matthew 12900: Facilitates the plotting of data in an XY graph.
12901: Puts plot definition data into the users environment in order for
12902: graph.png to plot it. Returns an <img> tag for the plot.
12903:
12904: Inputs:
12905:
12906: =over 4
12907:
12908: =item $Title: string, the title of the plot
12909:
12910: =item $xlabel: string, text describing the X-axis of the plot
12911:
12912: =item $ylabel: string, text describing the Y-axis of the plot
12913:
12914: =item $Max: scalar, the maximum Y value to use in the plot
12915: If $Max is < any data point, the graph will not be rendered.
12916:
12917: =item $colors: Array ref containing the hex color codes for the data to be
12918: plotted in. If undefined, default values will be used.
12919:
12920: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12921:
12922: =item $Ydata: Array ref containing Array refs.
1.185 www 12923: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12924:
12925: =item %Values: hash indicating or overriding any default values which are
12926: passed to graph.png.
12927: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12928:
12929: =back
12930:
12931: Returns:
12932:
12933: An <img> tag which references graph.png and the appropriate identifying
12934: information for the plot.
12935:
1.137 matthew 12936: =cut
12937:
12938: ############################################################
12939: ############################################################
12940: sub DrawXYGraph {
12941: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12942: #
12943: # Create the identifier for the graph
12944: my $identifier = &get_cgi_id();
12945: my $id = 'cgi.'.$identifier;
12946: #
12947: $Title = '' if (! defined($Title));
12948: $xlabel = '' if (! defined($xlabel));
12949: $ylabel = '' if (! defined($ylabel));
12950: my %ValuesHash =
12951: (
1.369 www 12952: $id.'.title' => &escape($Title),
12953: $id.'.xlabel' => &escape($xlabel),
12954: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12955: $id.'.y_max_value'=> $Max,
12956: $id.'.labels' => join(',',@$Xlabels),
12957: $id.'.PlotType' => 'XY',
12958: );
12959: #
12960: if (defined($colors) && ref($colors) eq 'ARRAY') {
12961: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12962: }
12963: #
12964: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12965: return '';
12966: }
12967: my $NumSets=1;
1.138 matthew 12968: foreach my $array (@{$Ydata}){
1.137 matthew 12969: next if (! ref($array));
12970: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12971: }
1.138 matthew 12972: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12973: #
12974: # Deal with other parameters
12975: while (my ($key,$value) = each(%Values)) {
12976: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12977: }
12978: #
1.646 raeburn 12979: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12980: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12981: }
12982:
12983: ############################################################
12984: ############################################################
12985:
12986: =pod
12987:
1.648 raeburn 12988: =item * &DrawXYYGraph()
1.138 matthew 12989:
12990: Facilitates the plotting of data in an XY graph with two Y axes.
12991: Puts plot definition data into the users environment in order for
12992: graph.png to plot it. Returns an <img> tag for the plot.
12993:
12994: Inputs:
12995:
12996: =over 4
12997:
12998: =item $Title: string, the title of the plot
12999:
13000: =item $xlabel: string, text describing the X-axis of the plot
13001:
13002: =item $ylabel: string, text describing the Y-axis of the plot
13003:
13004: =item $colors: Array ref containing the hex color codes for the data to be
13005: plotted in. If undefined, default values will be used.
13006:
13007: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13008:
13009: =item $Ydata1: The first data set
13010:
13011: =item $Min1: The minimum value of the left Y-axis
13012:
13013: =item $Max1: The maximum value of the left Y-axis
13014:
13015: =item $Ydata2: The second data set
13016:
13017: =item $Min2: The minimum value of the right Y-axis
13018:
13019: =item $Max2: The maximum value of the left Y-axis
13020:
13021: =item %Values: hash indicating or overriding any default values which are
13022: passed to graph.png.
13023: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13024:
13025: =back
13026:
13027: Returns:
13028:
13029: An <img> tag which references graph.png and the appropriate identifying
13030: information for the plot.
1.136 matthew 13031:
13032: =cut
13033:
13034: ############################################################
13035: ############################################################
1.137 matthew 13036: sub DrawXYYGraph {
13037: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13038: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13039: #
13040: # Create the identifier for the graph
13041: my $identifier = &get_cgi_id();
13042: my $id = 'cgi.'.$identifier;
13043: #
13044: $Title = '' if (! defined($Title));
13045: $xlabel = '' if (! defined($xlabel));
13046: $ylabel = '' if (! defined($ylabel));
13047: my %ValuesHash =
13048: (
1.369 www 13049: $id.'.title' => &escape($Title),
13050: $id.'.xlabel' => &escape($xlabel),
13051: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13052: $id.'.labels' => join(',',@$Xlabels),
13053: $id.'.PlotType' => 'XY',
13054: $id.'.NumSets' => 2,
1.137 matthew 13055: $id.'.two_axes' => 1,
13056: $id.'.y1_max_value' => $Max1,
13057: $id.'.y1_min_value' => $Min1,
13058: $id.'.y2_max_value' => $Max2,
13059: $id.'.y2_min_value' => $Min2,
1.136 matthew 13060: );
13061: #
1.137 matthew 13062: if (defined($colors) && ref($colors) eq 'ARRAY') {
13063: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13064: }
13065: #
13066: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13067: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13068: return '';
13069: }
13070: my $NumSets=1;
1.137 matthew 13071: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13072: next if (! ref($array));
13073: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13074: }
13075: #
13076: # Deal with other parameters
13077: while (my ($key,$value) = each(%Values)) {
13078: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13079: }
13080: #
1.646 raeburn 13081: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13082: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13083: }
13084:
13085: ############################################################
13086: ############################################################
13087:
13088: =pod
13089:
1.157 matthew 13090: =back
13091:
1.139 matthew 13092: =head1 Statistics helper routines?
13093:
13094: Bad place for them but what the hell.
13095:
1.157 matthew 13096: =over 4
13097:
1.648 raeburn 13098: =item * &chartlink()
1.139 matthew 13099:
13100: Returns a link to the chart for a specific student.
13101:
13102: Inputs:
13103:
13104: =over 4
13105:
13106: =item $linktext: The text of the link
13107:
13108: =item $sname: The students username
13109:
13110: =item $sdomain: The students domain
13111:
13112: =back
13113:
1.157 matthew 13114: =back
13115:
1.139 matthew 13116: =cut
13117:
13118: ############################################################
13119: ############################################################
13120: sub chartlink {
13121: my ($linktext, $sname, $sdomain) = @_;
13122: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13123: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13124: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13125: '">'.$linktext.'</a>';
1.153 matthew 13126: }
13127:
13128: #######################################################
13129: #######################################################
13130:
13131: =pod
13132:
13133: =head1 Course Environment Routines
1.157 matthew 13134:
13135: =over 4
1.153 matthew 13136:
1.648 raeburn 13137: =item * &restore_course_settings()
1.153 matthew 13138:
1.648 raeburn 13139: =item * &store_course_settings()
1.153 matthew 13140:
13141: Restores/Store indicated form parameters from the course environment.
13142: Will not overwrite existing values of the form parameters.
13143:
13144: Inputs:
13145: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13146:
13147: a hash ref describing the data to be stored. For example:
13148:
13149: %Save_Parameters = ('Status' => 'scalar',
13150: 'chartoutputmode' => 'scalar',
13151: 'chartoutputdata' => 'scalar',
13152: 'Section' => 'array',
1.373 raeburn 13153: 'Group' => 'array',
1.153 matthew 13154: 'StudentData' => 'array',
13155: 'Maps' => 'array');
13156:
13157: Returns: both routines return nothing
13158:
1.631 raeburn 13159: =back
13160:
1.153 matthew 13161: =cut
13162:
13163: #######################################################
13164: #######################################################
13165: sub store_course_settings {
1.496 albertel 13166: return &store_settings($env{'request.course.id'},@_);
13167: }
13168:
13169: sub store_settings {
1.153 matthew 13170: # save to the environment
13171: # appenv the same items, just to be safe
1.300 albertel 13172: my $udom = $env{'user.domain'};
13173: my $uname = $env{'user.name'};
1.496 albertel 13174: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13175: my %SaveHash;
13176: my %AppHash;
13177: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13178: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13179: my $envname = 'environment.'.$basename;
1.258 albertel 13180: if (exists($env{'form.'.$setting})) {
1.153 matthew 13181: # Save this value away
13182: if ($type eq 'scalar' &&
1.258 albertel 13183: (! exists($env{$envname}) ||
13184: $env{$envname} ne $env{'form.'.$setting})) {
13185: $SaveHash{$basename} = $env{'form.'.$setting};
13186: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13187: } elsif ($type eq 'array') {
13188: my $stored_form;
1.258 albertel 13189: if (ref($env{'form.'.$setting})) {
1.153 matthew 13190: $stored_form = join(',',
13191: map {
1.369 www 13192: &escape($_);
1.258 albertel 13193: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13194: } else {
13195: $stored_form =
1.369 www 13196: &escape($env{'form.'.$setting});
1.153 matthew 13197: }
13198: # Determine if the array contents are the same.
1.258 albertel 13199: if ($stored_form ne $env{$envname}) {
1.153 matthew 13200: $SaveHash{$basename} = $stored_form;
13201: $AppHash{$envname} = $stored_form;
13202: }
13203: }
13204: }
13205: }
13206: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13207: $udom,$uname);
1.153 matthew 13208: if ($put_result !~ /^(ok|delayed)/) {
13209: &Apache::lonnet::logthis('unable to save form parameters, '.
13210: 'got error:'.$put_result);
13211: }
13212: # Make sure these settings stick around in this session, too
1.646 raeburn 13213: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13214: return;
13215: }
13216:
13217: sub restore_course_settings {
1.499 albertel 13218: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13219: }
13220:
13221: sub restore_settings {
13222: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13223: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13224: next if (exists($env{'form.'.$setting}));
1.496 albertel 13225: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13226: '.'.$setting;
1.258 albertel 13227: if (exists($env{$envname})) {
1.153 matthew 13228: if ($type eq 'scalar') {
1.258 albertel 13229: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13230: } elsif ($type eq 'array') {
1.258 albertel 13231: $env{'form.'.$setting} = [
1.153 matthew 13232: map {
1.369 www 13233: &unescape($_);
1.258 albertel 13234: } split(',',$env{$envname})
1.153 matthew 13235: ];
13236: }
13237: }
13238: }
1.127 matthew 13239: }
13240:
1.618 raeburn 13241: #######################################################
13242: #######################################################
13243:
13244: =pod
13245:
13246: =head1 Domain E-mail Routines
13247:
13248: =over 4
13249:
1.648 raeburn 13250: =item * &build_recipient_list()
1.618 raeburn 13251:
1.1075.2.44 raeburn 13252: Build recipient lists for following types of e-mail:
1.766 raeburn 13253: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 13254: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13255: module change checking, student/employee ID conflict checks, as
13256: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13257: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13258:
13259: Inputs:
1.1075.2.44 raeburn 13260: defmail (scalar - email address of default recipient),
13261: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13262: requestsmail, updatesmail, or idconflictsmail).
13263:
1.619 raeburn 13264: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 13265:
13266: origmail (scalar - email address of recipient from loncapa.conf,
13267: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13268:
1.655 raeburn 13269: Returns: comma separated list of addresses to which to send e-mail.
13270:
13271: =back
1.618 raeburn 13272:
13273: =cut
13274:
13275: ############################################################
13276: ############################################################
13277: sub build_recipient_list {
1.619 raeburn 13278: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13279: my @recipients;
13280: my $otheremails;
13281: my %domconfig =
13282: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13283: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13284: if (exists($domconfig{'contacts'}{$mailing})) {
13285: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13286: my @contacts = ('adminemail','supportemail');
13287: foreach my $item (@contacts) {
13288: if ($domconfig{'contacts'}{$mailing}{$item}) {
13289: my $addr = $domconfig{'contacts'}{$item};
13290: if (!grep(/^\Q$addr\E$/,@recipients)) {
13291: push(@recipients,$addr);
13292: }
1.619 raeburn 13293: }
1.766 raeburn 13294: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13295: }
13296: }
1.766 raeburn 13297: } elsif ($origmail ne '') {
13298: push(@recipients,$origmail);
1.618 raeburn 13299: }
1.619 raeburn 13300: } elsif ($origmail ne '') {
13301: push(@recipients,$origmail);
1.618 raeburn 13302: }
1.688 raeburn 13303: if (defined($defmail)) {
13304: if ($defmail ne '') {
13305: push(@recipients,$defmail);
13306: }
1.618 raeburn 13307: }
13308: if ($otheremails) {
1.619 raeburn 13309: my @others;
13310: if ($otheremails =~ /,/) {
13311: @others = split(/,/,$otheremails);
1.618 raeburn 13312: } else {
1.619 raeburn 13313: push(@others,$otheremails);
13314: }
13315: foreach my $addr (@others) {
13316: if (!grep(/^\Q$addr\E$/,@recipients)) {
13317: push(@recipients,$addr);
13318: }
1.618 raeburn 13319: }
13320: }
1.619 raeburn 13321: my $recipientlist = join(',',@recipients);
1.618 raeburn 13322: return $recipientlist;
13323: }
13324:
1.127 matthew 13325: ############################################################
13326: ############################################################
1.154 albertel 13327:
1.655 raeburn 13328: =pod
13329:
13330: =head1 Course Catalog Routines
13331:
13332: =over 4
13333:
13334: =item * &gather_categories()
13335:
13336: Converts category definitions - keys of categories hash stored in
13337: coursecategories in configuration.db on the primary library server in a
13338: domain - to an array. Also generates javascript and idx hash used to
13339: generate Domain Coordinator interface for editing Course Categories.
13340:
13341: Inputs:
1.663 raeburn 13342:
1.655 raeburn 13343: categories (reference to hash of category definitions).
1.663 raeburn 13344:
1.655 raeburn 13345: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13346: categories and subcategories).
1.663 raeburn 13347:
1.655 raeburn 13348: idx (reference to hash of counters used in Domain Coordinator interface for
13349: editing Course Categories).
1.663 raeburn 13350:
1.655 raeburn 13351: jsarray (reference to array of categories used to create Javascript arrays for
13352: Domain Coordinator interface for editing Course Categories).
13353:
13354: Returns: nothing
13355:
13356: Side effects: populates cats, idx and jsarray.
13357:
13358: =cut
13359:
13360: sub gather_categories {
13361: my ($categories,$cats,$idx,$jsarray) = @_;
13362: my %counters;
13363: my $num = 0;
13364: foreach my $item (keys(%{$categories})) {
13365: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13366: if ($container eq '' && $depth == 0) {
13367: $cats->[$depth][$categories->{$item}] = $cat;
13368: } else {
13369: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13370: }
13371: my ($escitem,$tail) = split(/:/,$item,2);
13372: if ($counters{$tail} eq '') {
13373: $counters{$tail} = $num;
13374: $num ++;
13375: }
13376: if (ref($idx) eq 'HASH') {
13377: $idx->{$item} = $counters{$tail};
13378: }
13379: if (ref($jsarray) eq 'ARRAY') {
13380: push(@{$jsarray->[$counters{$tail}]},$item);
13381: }
13382: }
13383: return;
13384: }
13385:
13386: =pod
13387:
13388: =item * &extract_categories()
13389:
13390: Used to generate breadcrumb trails for course categories.
13391:
13392: Inputs:
1.663 raeburn 13393:
1.655 raeburn 13394: categories (reference to hash of category definitions).
1.663 raeburn 13395:
1.655 raeburn 13396: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13397: categories and subcategories).
1.663 raeburn 13398:
1.655 raeburn 13399: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13400:
1.655 raeburn 13401: allitems (reference to hash - key is category key
13402: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13403:
1.655 raeburn 13404: idx (reference to hash of counters used in Domain Coordinator interface for
13405: editing Course Categories).
1.663 raeburn 13406:
1.655 raeburn 13407: jsarray (reference to array of categories used to create Javascript arrays for
13408: Domain Coordinator interface for editing Course Categories).
13409:
1.665 raeburn 13410: subcats (reference to hash of arrays containing all subcategories within each
13411: category, -recursive)
13412:
1.655 raeburn 13413: Returns: nothing
13414:
13415: Side effects: populates trails and allitems hash references.
13416:
13417: =cut
13418:
13419: sub extract_categories {
1.665 raeburn 13420: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13421: if (ref($categories) eq 'HASH') {
13422: &gather_categories($categories,$cats,$idx,$jsarray);
13423: if (ref($cats->[0]) eq 'ARRAY') {
13424: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13425: my $name = $cats->[0][$i];
13426: my $item = &escape($name).'::0';
13427: my $trailstr;
13428: if ($name eq 'instcode') {
13429: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13430: } elsif ($name eq 'communities') {
13431: $trailstr = &mt('Communities');
1.655 raeburn 13432: } else {
13433: $trailstr = $name;
13434: }
13435: if ($allitems->{$item} eq '') {
13436: push(@{$trails},$trailstr);
13437: $allitems->{$item} = scalar(@{$trails})-1;
13438: }
13439: my @parents = ($name);
13440: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13441: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13442: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13443: if (ref($subcats) eq 'HASH') {
13444: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13445: }
13446: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13447: }
13448: } else {
13449: if (ref($subcats) eq 'HASH') {
13450: $subcats->{$item} = [];
1.655 raeburn 13451: }
13452: }
13453: }
13454: }
13455: }
13456: return;
13457: }
13458:
13459: =pod
13460:
1.1075.2.56 raeburn 13461: =item * &recurse_categories()
1.655 raeburn 13462:
13463: Recursively used to generate breadcrumb trails for course categories.
13464:
13465: Inputs:
1.663 raeburn 13466:
1.655 raeburn 13467: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13468: categories and subcategories).
1.663 raeburn 13469:
1.655 raeburn 13470: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13471:
13472: category (current course category, for which breadcrumb trail is being generated).
13473:
13474: trails (reference to array of breadcrumb trails for each category).
13475:
1.655 raeburn 13476: allitems (reference to hash - key is category key
13477: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13478:
1.655 raeburn 13479: parents (array containing containers directories for current category,
13480: back to top level).
13481:
13482: Returns: nothing
13483:
13484: Side effects: populates trails and allitems hash references
13485:
13486: =cut
13487:
13488: sub recurse_categories {
1.665 raeburn 13489: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13490: my $shallower = $depth - 1;
13491: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13492: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13493: my $name = $cats->[$depth]{$category}[$k];
13494: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13495: my $trailstr = join(' -> ',(@{$parents},$category));
13496: if ($allitems->{$item} eq '') {
13497: push(@{$trails},$trailstr);
13498: $allitems->{$item} = scalar(@{$trails})-1;
13499: }
13500: my $deeper = $depth+1;
13501: push(@{$parents},$category);
1.665 raeburn 13502: if (ref($subcats) eq 'HASH') {
13503: my $subcat = &escape($name).':'.$category.':'.$depth;
13504: for (my $j=@{$parents}; $j>=0; $j--) {
13505: my $higher;
13506: if ($j > 0) {
13507: $higher = &escape($parents->[$j]).':'.
13508: &escape($parents->[$j-1]).':'.$j;
13509: } else {
13510: $higher = &escape($parents->[$j]).'::'.$j;
13511: }
13512: push(@{$subcats->{$higher}},$subcat);
13513: }
13514: }
13515: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13516: $subcats);
1.655 raeburn 13517: pop(@{$parents});
13518: }
13519: } else {
13520: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13521: my $trailstr = join(' -> ',(@{$parents},$category));
13522: if ($allitems->{$item} eq '') {
13523: push(@{$trails},$trailstr);
13524: $allitems->{$item} = scalar(@{$trails})-1;
13525: }
13526: }
13527: return;
13528: }
13529:
1.663 raeburn 13530: =pod
13531:
1.1075.2.56 raeburn 13532: =item * &assign_categories_table()
1.663 raeburn 13533:
13534: Create a datatable for display of hierarchical categories in a domain,
13535: with checkboxes to allow a course to be categorized.
13536:
13537: Inputs:
13538:
13539: cathash - reference to hash of categories defined for the domain (from
13540: configuration.db)
13541:
13542: currcat - scalar with an & separated list of categories assigned to a course.
13543:
1.919 raeburn 13544: type - scalar contains course type (Course or Community).
13545:
1.663 raeburn 13546: Returns: $output (markup to be displayed)
13547:
13548: =cut
13549:
13550: sub assign_categories_table {
1.919 raeburn 13551: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13552: my $output;
13553: if (ref($cathash) eq 'HASH') {
13554: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13555: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13556: $maxdepth = scalar(@cats);
13557: if (@cats > 0) {
13558: my $itemcount = 0;
13559: if (ref($cats[0]) eq 'ARRAY') {
13560: my @currcategories;
13561: if ($currcat ne '') {
13562: @currcategories = split('&',$currcat);
13563: }
1.919 raeburn 13564: my $table;
1.663 raeburn 13565: for (my $i=0; $i<@{$cats[0]}; $i++) {
13566: my $parent = $cats[0][$i];
1.919 raeburn 13567: next if ($parent eq 'instcode');
13568: if ($type eq 'Community') {
13569: next unless ($parent eq 'communities');
13570: } else {
13571: next if ($parent eq 'communities');
13572: }
1.663 raeburn 13573: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13574: my $item = &escape($parent).'::0';
13575: my $checked = '';
13576: if (@currcategories > 0) {
13577: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13578: $checked = ' checked="checked"';
1.663 raeburn 13579: }
13580: }
1.919 raeburn 13581: my $parent_title = $parent;
13582: if ($parent eq 'communities') {
13583: $parent_title = &mt('Communities');
13584: }
13585: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13586: '<input type="checkbox" name="usecategory" value="'.
13587: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13588: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13589: my $depth = 1;
13590: push(@path,$parent);
1.919 raeburn 13591: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13592: pop(@path);
1.919 raeburn 13593: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13594: $itemcount ++;
13595: }
1.919 raeburn 13596: if ($itemcount) {
13597: $output = &Apache::loncommon::start_data_table().
13598: $table.
13599: &Apache::loncommon::end_data_table();
13600: }
1.663 raeburn 13601: }
13602: }
13603: }
13604: return $output;
13605: }
13606:
13607: =pod
13608:
1.1075.2.56 raeburn 13609: =item * &assign_category_rows()
1.663 raeburn 13610:
13611: Create a datatable row for display of nested categories in a domain,
13612: with checkboxes to allow a course to be categorized,called recursively.
13613:
13614: Inputs:
13615:
13616: itemcount - track row number for alternating colors
13617:
13618: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13619: categories and subcategories.
13620:
13621: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13622:
13623: parent - parent of current category item
13624:
13625: path - Array containing all categories back up through the hierarchy from the
13626: current category to the top level.
13627:
13628: currcategories - reference to array of current categories assigned to the course
13629:
13630: Returns: $output (markup to be displayed).
13631:
13632: =cut
13633:
13634: sub assign_category_rows {
13635: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13636: my ($text,$name,$item,$chgstr);
13637: if (ref($cats) eq 'ARRAY') {
13638: my $maxdepth = scalar(@{$cats});
13639: if (ref($cats->[$depth]) eq 'HASH') {
13640: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13641: my $numchildren = @{$cats->[$depth]{$parent}};
13642: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 13643: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13644: for (my $j=0; $j<$numchildren; $j++) {
13645: $name = $cats->[$depth]{$parent}[$j];
13646: $item = &escape($name).':'.&escape($parent).':'.$depth;
13647: my $deeper = $depth+1;
13648: my $checked = '';
13649: if (ref($currcategories) eq 'ARRAY') {
13650: if (@{$currcategories} > 0) {
13651: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13652: $checked = ' checked="checked"';
1.663 raeburn 13653: }
13654: }
13655: }
1.664 raeburn 13656: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13657: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13658: $item.'"'.$checked.' />'.$name.'</label></span>'.
13659: '<input type="hidden" name="catname" value="'.$name.'" />'.
13660: '</td><td>';
1.663 raeburn 13661: if (ref($path) eq 'ARRAY') {
13662: push(@{$path},$name);
13663: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13664: pop(@{$path});
13665: }
13666: $text .= '</td></tr>';
13667: }
13668: $text .= '</table></td>';
13669: }
13670: }
13671: }
13672: return $text;
13673: }
13674:
1.1075.2.69 raeburn 13675: =pod
13676:
13677: =back
13678:
13679: =cut
13680:
1.655 raeburn 13681: ############################################################
13682: ############################################################
13683:
13684:
1.443 albertel 13685: sub commit_customrole {
1.664 raeburn 13686: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13687: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13688: ($start?', '.&mt('starting').' '.localtime($start):'').
13689: ($end?', ending '.localtime($end):'').': <b>'.
13690: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13691: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13692: '</b><br />';
13693: return $output;
13694: }
13695:
13696: sub commit_standardrole {
1.1075.2.31 raeburn 13697: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13698: my ($output,$logmsg,$linefeed);
13699: if ($context eq 'auto') {
13700: $linefeed = "\n";
13701: } else {
13702: $linefeed = "<br />\n";
13703: }
1.443 albertel 13704: if ($three eq 'st') {
1.541 raeburn 13705: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 13706: $one,$two,$sec,$context,$credits);
1.541 raeburn 13707: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13708: ($result eq 'unknown_course') || ($result eq 'refused')) {
13709: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13710: } else {
1.541 raeburn 13711: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13712: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13713: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13714: if ($context eq 'auto') {
13715: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13716: } else {
13717: $output .= '<b>'.$result.'</b>'.$linefeed.
13718: &mt('Add to classlist').': <b>ok</b>';
13719: }
13720: $output .= $linefeed;
1.443 albertel 13721: }
13722: } else {
13723: $output = &mt('Assigning').' '.$three.' in '.$url.
13724: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13725: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13726: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13727: if ($context eq 'auto') {
13728: $output .= $result.$linefeed;
13729: } else {
13730: $output .= '<b>'.$result.'</b>'.$linefeed;
13731: }
1.443 albertel 13732: }
13733: return $output;
13734: }
13735:
13736: sub commit_studentrole {
1.1075.2.31 raeburn 13737: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13738: $credits) = @_;
1.626 raeburn 13739: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13740: if ($context eq 'auto') {
13741: $linefeed = "\n";
13742: } else {
13743: $linefeed = '<br />'."\n";
13744: }
1.443 albertel 13745: if (defined($one) && defined($two)) {
13746: my $cid=$one.'_'.$two;
13747: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13748: my $secchange = 0;
13749: my $expire_role_result;
13750: my $modify_section_result;
1.628 raeburn 13751: if ($oldsec ne '-1') {
13752: if ($oldsec ne $sec) {
1.443 albertel 13753: $secchange = 1;
1.628 raeburn 13754: my $now = time;
1.443 albertel 13755: my $uurl='/'.$cid;
13756: $uurl=~s/\_/\//g;
13757: if ($oldsec) {
13758: $uurl.='/'.$oldsec;
13759: }
1.626 raeburn 13760: $oldsecurl = $uurl;
1.628 raeburn 13761: $expire_role_result =
1.652 raeburn 13762: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13763: if ($env{'request.course.sec'} ne '') {
13764: if ($expire_role_result eq 'refused') {
13765: my @roles = ('st');
13766: my @statuses = ('previous');
13767: my @roledoms = ($one);
13768: my $withsec = 1;
13769: my %roleshash =
13770: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13771: \@statuses,\@roles,\@roledoms,$withsec);
13772: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13773: my ($oldstart,$oldend) =
13774: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13775: if ($oldend > 0 && $oldend <= $now) {
13776: $expire_role_result = 'ok';
13777: }
13778: }
13779: }
13780: }
1.443 albertel 13781: $result = $expire_role_result;
13782: }
13783: }
13784: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 13785: $modify_section_result =
13786: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13787: undef,undef,undef,$sec,
13788: $end,$start,'','',$cid,
13789: '',$context,$credits);
1.443 albertel 13790: if ($modify_section_result =~ /^ok/) {
13791: if ($secchange == 1) {
1.628 raeburn 13792: if ($sec eq '') {
13793: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13794: } else {
13795: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13796: }
1.443 albertel 13797: } elsif ($oldsec eq '-1') {
1.628 raeburn 13798: if ($sec eq '') {
13799: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13800: } else {
13801: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13802: }
1.443 albertel 13803: } else {
1.628 raeburn 13804: if ($sec eq '') {
13805: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13806: } else {
13807: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13808: }
1.443 albertel 13809: }
13810: } else {
1.628 raeburn 13811: if ($secchange) {
13812: $$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;
13813: } else {
13814: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13815: }
1.443 albertel 13816: }
13817: $result = $modify_section_result;
13818: } elsif ($secchange == 1) {
1.628 raeburn 13819: if ($oldsec eq '') {
1.1075.2.20 raeburn 13820: $$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 13821: } else {
13822: $$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;
13823: }
1.626 raeburn 13824: if ($expire_role_result eq 'refused') {
13825: my $newsecurl = '/'.$cid;
13826: $newsecurl =~ s/\_/\//g;
13827: if ($sec ne '') {
13828: $newsecurl.='/'.$sec;
13829: }
13830: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13831: if ($sec eq '') {
13832: $$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;
13833: } else {
13834: $$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;
13835: }
13836: }
13837: }
1.443 albertel 13838: }
13839: } else {
1.626 raeburn 13840: $$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 13841: $result = "error: incomplete course id\n";
13842: }
13843: return $result;
13844: }
13845:
1.1075.2.25 raeburn 13846: sub show_role_extent {
13847: my ($scope,$context,$role) = @_;
13848: $scope =~ s{^/}{};
13849: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13850: push(@courseroles,'co');
13851: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13852: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13853: $scope =~ s{/}{_};
13854: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13855: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13856: my ($audom,$auname) = split(/\//,$scope);
13857: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13858: &Apache::loncommon::plainname($auname,$audom).'</span>');
13859: } else {
13860: $scope =~ s{/$}{};
13861: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13862: &Apache::lonnet::domain($scope,'description').'</span>');
13863: }
13864: }
13865:
1.443 albertel 13866: ############################################################
13867: ############################################################
13868:
1.566 albertel 13869: sub check_clone {
1.578 raeburn 13870: my ($args,$linefeed) = @_;
1.566 albertel 13871: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13872: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13873: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13874: my $clonemsg;
13875: my $can_clone = 0;
1.944 raeburn 13876: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13877: if ($lctype ne 'community') {
13878: $lctype = 'course';
13879: }
1.566 albertel 13880: if ($clonehome eq 'no_host') {
1.944 raeburn 13881: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13882: $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'});
13883: } else {
13884: $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'});
13885: }
1.566 albertel 13886: } else {
13887: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13888: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13889: if ($clonedesc{'type'} ne 'Community') {
13890: $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'});
13891: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13892: }
13893: }
1.882 raeburn 13894: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13895: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13896: $can_clone = 1;
13897: } else {
13898: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13899: $args->{'clonedomain'},$args->{'clonecourse'});
13900: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13901: if (grep(/^\*$/,@cloners)) {
13902: $can_clone = 1;
13903: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13904: $can_clone = 1;
13905: } else {
1.908 raeburn 13906: my $ccrole = 'cc';
1.944 raeburn 13907: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13908: $ccrole = 'co';
13909: }
1.578 raeburn 13910: my %roleshash =
13911: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13912: $args->{'ccdomain'},
1.908 raeburn 13913: 'userroles',['active'],[$ccrole],
1.578 raeburn 13914: [$args->{'clonedomain'}]);
1.908 raeburn 13915: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13916: $can_clone = 1;
13917: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13918: $can_clone = 1;
13919: } else {
1.944 raeburn 13920: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13921: $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'});
13922: } else {
13923: $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'});
13924: }
1.578 raeburn 13925: }
1.566 albertel 13926: }
1.578 raeburn 13927: }
1.566 albertel 13928: }
13929: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13930: }
13931:
1.444 albertel 13932: sub construct_course {
1.1075.2.59 raeburn 13933: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 13934: my $outcome;
1.541 raeburn 13935: my $linefeed = '<br />'."\n";
13936: if ($context eq 'auto') {
13937: $linefeed = "\n";
13938: }
1.566 albertel 13939:
13940: #
13941: # Are we cloning?
13942: #
13943: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13944: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13945: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13946: if ($context ne 'auto') {
1.578 raeburn 13947: if ($clonemsg ne '') {
13948: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13949: }
1.566 albertel 13950: }
13951: $outcome .= $clonemsg.$linefeed;
13952:
13953: if (!$can_clone) {
13954: return (0,$outcome);
13955: }
13956: }
13957:
1.444 albertel 13958: #
13959: # Open course
13960: #
13961: my $crstype = lc($args->{'crstype'});
13962: my %cenv=();
13963: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13964: $args->{'cdescr'},
13965: $args->{'curl'},
13966: $args->{'course_home'},
13967: $args->{'nonstandard'},
13968: $args->{'crscode'},
13969: $args->{'ccuname'}.':'.
13970: $args->{'ccdomain'},
1.882 raeburn 13971: $args->{'crstype'},
1.885 raeburn 13972: $cnum,$context,$category);
1.444 albertel 13973:
13974: # Note: The testing routines depend on this being output; see
13975: # Utils::Course. This needs to at least be output as a comment
13976: # if anyone ever decides to not show this, and Utils::Course::new
13977: # will need to be suitably modified.
1.541 raeburn 13978: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13979: if ($$courseid =~ /^error:/) {
13980: return (0,$outcome);
13981: }
13982:
1.444 albertel 13983: #
13984: # Check if created correctly
13985: #
1.479 albertel 13986: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13987: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13988: if ($crsuhome eq 'no_host') {
13989: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13990: return (0,$outcome);
13991: }
1.541 raeburn 13992: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13993:
1.444 albertel 13994: #
1.566 albertel 13995: # Do the cloning
13996: #
13997: if ($can_clone && $cloneid) {
13998: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13999: if ($context ne 'auto') {
14000: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14001: }
14002: $outcome .= $clonemsg.$linefeed;
14003: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14004: # Copy all files
1.637 www 14005: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14006: # Restore URL
1.566 albertel 14007: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14008: # Restore title
1.566 albertel 14009: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14010: # Restore creation date, creator and creation context.
14011: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14012: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14013: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14014: # Mark as cloned
1.566 albertel 14015: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14016: # Need to clone grading mode
14017: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14018: $cenv{'grading'}=$newenv{'grading'};
14019: # Do not clone these environment entries
14020: &Apache::lonnet::del('environment',
14021: ['default_enrollment_start_date',
14022: 'default_enrollment_end_date',
14023: 'question.email',
14024: 'policy.email',
14025: 'comment.email',
14026: 'pch.users.denied',
1.725 raeburn 14027: 'plc.users.denied',
14028: 'hidefromcat',
1.1075.2.36 raeburn 14029: 'checkforpriv',
1.1075.2.59 raeburn 14030: 'categories',
14031: 'internal.uniquecode'],
1.638 www 14032: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 14033: if ($args->{'textbook'}) {
14034: $cenv{'internal.textbook'} = $args->{'textbook'};
14035: }
1.444 albertel 14036: }
1.566 albertel 14037:
1.444 albertel 14038: #
14039: # Set environment (will override cloned, if existing)
14040: #
14041: my @sections = ();
14042: my @xlists = ();
14043: if ($args->{'crstype'}) {
14044: $cenv{'type'}=$args->{'crstype'};
14045: }
14046: if ($args->{'crsid'}) {
14047: $cenv{'courseid'}=$args->{'crsid'};
14048: }
14049: if ($args->{'crscode'}) {
14050: $cenv{'internal.coursecode'}=$args->{'crscode'};
14051: }
14052: if ($args->{'crsquota'} ne '') {
14053: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14054: } else {
14055: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14056: }
14057: if ($args->{'ccuname'}) {
14058: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14059: ':'.$args->{'ccdomain'};
14060: } else {
14061: $cenv{'internal.courseowner'} = $args->{'curruser'};
14062: }
1.1075.2.31 raeburn 14063: if ($args->{'defaultcredits'}) {
14064: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14065: }
1.444 albertel 14066: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14067: if ($args->{'crssections'}) {
14068: $cenv{'internal.sectionnums'} = '';
14069: if ($args->{'crssections'} =~ m/,/) {
14070: @sections = split/,/,$args->{'crssections'};
14071: } else {
14072: $sections[0] = $args->{'crssections'};
14073: }
14074: if (@sections > 0) {
14075: foreach my $item (@sections) {
14076: my ($sec,$gp) = split/:/,$item;
14077: my $class = $args->{'crscode'}.$sec;
14078: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14079: $cenv{'internal.sectionnums'} .= $item.',';
14080: unless ($addcheck eq 'ok') {
14081: push @badclasses, $class;
14082: }
14083: }
14084: $cenv{'internal.sectionnums'} =~ s/,$//;
14085: }
14086: }
14087: # do not hide course coordinator from staff listing,
14088: # even if privileged
14089: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 14090: # add course coordinator's domain to domains to check for privileged users
14091: # if different to course domain
14092: if ($$crsudom ne $args->{'ccdomain'}) {
14093: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14094: }
1.444 albertel 14095: # add crosslistings
14096: if ($args->{'crsxlist'}) {
14097: $cenv{'internal.crosslistings'}='';
14098: if ($args->{'crsxlist'} =~ m/,/) {
14099: @xlists = split/,/,$args->{'crsxlist'};
14100: } else {
14101: $xlists[0] = $args->{'crsxlist'};
14102: }
14103: if (@xlists > 0) {
14104: foreach my $item (@xlists) {
14105: my ($xl,$gp) = split/:/,$item;
14106: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14107: $cenv{'internal.crosslistings'} .= $item.',';
14108: unless ($addcheck eq 'ok') {
14109: push @badclasses, $xl;
14110: }
14111: }
14112: $cenv{'internal.crosslistings'} =~ s/,$//;
14113: }
14114: }
14115: if ($args->{'autoadds'}) {
14116: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14117: }
14118: if ($args->{'autodrops'}) {
14119: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14120: }
14121: # check for notification of enrollment changes
14122: my @notified = ();
14123: if ($args->{'notify_owner'}) {
14124: if ($args->{'ccuname'} ne '') {
14125: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14126: }
14127: }
14128: if ($args->{'notify_dc'}) {
14129: if ($uname ne '') {
1.630 raeburn 14130: push(@notified,$uname.':'.$udom);
1.444 albertel 14131: }
14132: }
14133: if (@notified > 0) {
14134: my $notifylist;
14135: if (@notified > 1) {
14136: $notifylist = join(',',@notified);
14137: } else {
14138: $notifylist = $notified[0];
14139: }
14140: $cenv{'internal.notifylist'} = $notifylist;
14141: }
14142: if (@badclasses > 0) {
14143: my %lt=&Apache::lonlocal::texthash(
14144: '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',
14145: 'dnhr' => 'does not have rights to access enrollment in these classes',
14146: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14147: );
1.541 raeburn 14148: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14149: ' ('.$lt{'adby'}.')';
14150: if ($context eq 'auto') {
14151: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14152: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14153: foreach my $item (@badclasses) {
14154: if ($context eq 'auto') {
14155: $outcome .= " - $item\n";
14156: } else {
14157: $outcome .= "<li>$item</li>\n";
14158: }
14159: }
14160: if ($context eq 'auto') {
14161: $outcome .= $linefeed;
14162: } else {
1.566 albertel 14163: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14164: }
14165: }
1.444 albertel 14166: }
14167: if ($args->{'no_end_date'}) {
14168: $args->{'endaccess'} = 0;
14169: }
14170: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14171: $cenv{'internal.autoend'}=$args->{'enrollend'};
14172: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14173: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14174: if ($args->{'showphotos'}) {
14175: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14176: }
14177: $cenv{'internal.authtype'} = $args->{'authtype'};
14178: $cenv{'internal.autharg'} = $args->{'autharg'};
14179: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14180: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14181: 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');
14182: if ($context eq 'auto') {
14183: $outcome .= $krb_msg;
14184: } else {
1.566 albertel 14185: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14186: }
14187: $outcome .= $linefeed;
1.444 albertel 14188: }
14189: }
14190: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14191: if ($args->{'setpolicy'}) {
14192: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14193: }
14194: if ($args->{'setcontent'}) {
14195: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14196: }
14197: }
14198: if ($args->{'reshome'}) {
14199: $cenv{'reshome'}=$args->{'reshome'}.'/';
14200: $cenv{'reshome'}=~s/\/+$/\//;
14201: }
14202: #
14203: # course has keyed access
14204: #
14205: if ($args->{'setkeys'}) {
14206: $cenv{'keyaccess'}='yes';
14207: }
14208: # if specified, key authority is not course, but user
14209: # only active if keyaccess is yes
14210: if ($args->{'keyauth'}) {
1.487 albertel 14211: my ($user,$domain) = split(':',$args->{'keyauth'});
14212: $user = &LONCAPA::clean_username($user);
14213: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14214: if ($user ne '' && $domain ne '') {
1.487 albertel 14215: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14216: }
14217: }
14218:
1.1075.2.59 raeburn 14219: #
14220: # generate and store uniquecode (available to course requester), if course should have one.
14221: #
14222: if ($args->{'uniquecode'}) {
14223: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14224: if ($code) {
14225: $cenv{'internal.uniquecode'} = $code;
14226: my %crsinfo =
14227: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
14228: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
14229: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
14230: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
14231: }
14232: if (ref($coderef)) {
14233: $$coderef = $code;
14234: }
14235: }
14236: }
14237:
1.444 albertel 14238: if ($args->{'disresdis'}) {
14239: $cenv{'pch.roles.denied'}='st';
14240: }
14241: if ($args->{'disablechat'}) {
14242: $cenv{'plc.roles.denied'}='st';
14243: }
14244:
14245: # Record we've not yet viewed the Course Initialization Helper for this
14246: # course
14247: $cenv{'course.helper.not.run'} = 1;
14248: #
14249: # Use new Randomseed
14250: #
14251: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14252: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14253: #
14254: # The encryption code and receipt prefix for this course
14255: #
14256: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14257: $cenv{'internal.encpref'}=100+int(9*rand(99));
14258: #
14259: # By default, use standard grading
14260: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14261:
1.541 raeburn 14262: $outcome .= $linefeed.&mt('Setting environment').': '.
14263: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14264: #
14265: # Open all assignments
14266: #
14267: if ($args->{'openall'}) {
14268: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14269: my %storecontent = ($storeunder => time,
14270: $storeunder.'.type' => 'date_start');
14271:
14272: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14273: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14274: }
14275: #
14276: # Set first page
14277: #
14278: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14279: || ($cloneid)) {
1.445 albertel 14280: use LONCAPA::map;
1.444 albertel 14281: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14282:
14283: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14284: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14285:
1.444 albertel 14286: $outcome .= ($fatal?$errtext:'read ok').' - ';
14287: my $title; my $url;
14288: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14289: $title=&mt('Syllabus');
1.444 albertel 14290: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14291: } else {
1.963 raeburn 14292: $title=&mt('Table of Contents');
1.444 albertel 14293: $url='/adm/navmaps';
14294: }
1.445 albertel 14295:
14296: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14297: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14298:
14299: if ($errtext) { $fatal=2; }
1.541 raeburn 14300: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14301: }
1.566 albertel 14302:
14303: return (1,$outcome);
1.444 albertel 14304: }
14305:
1.1075.2.59 raeburn 14306: sub make_unique_code {
14307: my ($cdom,$cnum) = @_;
14308: # get lock on uniquecodes db
14309: my $lockhash = {
14310: $cnum."\0".'uniquecodes' => $env{'user.name'}.
14311: ':'.$env{'user.domain'},
14312: };
14313: my $tries = 0;
14314: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14315: my ($code,$error);
14316:
14317: while (($gotlock ne 'ok') && ($tries<3)) {
14318: $tries ++;
14319: sleep 1;
14320: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14321: }
14322: if ($gotlock eq 'ok') {
14323: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
14324: my $gotcode;
14325: my $attempts = 0;
14326: while ((!$gotcode) && ($attempts < 100)) {
14327: $code = &generate_code();
14328: if (!exists($currcodes{$code})) {
14329: $gotcode = 1;
14330: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
14331: $error = 'nostore';
14332: }
14333: }
14334: $attempts ++;
14335: }
14336: my @del_lock = ($cnum."\0".'uniquecodes');
14337: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
14338: } else {
14339: $error = 'nolock';
14340: }
14341: return ($code,$error);
14342: }
14343:
14344: sub generate_code {
14345: my $code;
14346: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
14347: for (my $i=0; $i<6; $i++) {
14348: my $lettnum = int (rand 2);
14349: my $item = '';
14350: if ($lettnum) {
14351: $item = $letts[int( rand(18) )];
14352: } else {
14353: $item = 1+int( rand(8) );
14354: }
14355: $code .= $item;
14356: }
14357: return $code;
14358: }
14359:
1.444 albertel 14360: ############################################################
14361: ############################################################
14362:
1.953 droeschl 14363: #SD
14364: # only Community and Course, or anything else?
1.378 raeburn 14365: sub course_type {
14366: my ($cid) = @_;
14367: if (!defined($cid)) {
14368: $cid = $env{'request.course.id'};
14369: }
1.404 albertel 14370: if (defined($env{'course.'.$cid.'.type'})) {
14371: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14372: } else {
14373: return 'Course';
1.377 raeburn 14374: }
14375: }
1.156 albertel 14376:
1.406 raeburn 14377: sub group_term {
14378: my $crstype = &course_type();
14379: my %names = (
14380: 'Course' => 'group',
1.865 raeburn 14381: 'Community' => 'group',
1.406 raeburn 14382: );
14383: return $names{$crstype};
14384: }
14385:
1.902 raeburn 14386: sub course_types {
1.1075.2.59 raeburn 14387: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 14388: my %typename = (
14389: official => 'Official course',
14390: unofficial => 'Unofficial course',
14391: community => 'Community',
1.1075.2.59 raeburn 14392: textbook => 'Textbook course',
1.902 raeburn 14393: );
14394: return (\@types,\%typename);
14395: }
14396:
1.156 albertel 14397: sub icon {
14398: my ($file)=@_;
1.505 albertel 14399: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14400: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14401: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14402: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14403: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14404: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14405: $curfext.".gif") {
14406: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14407: $curfext.".gif";
14408: }
14409: }
1.249 albertel 14410: return &lonhttpdurl($iconname);
1.154 albertel 14411: }
1.84 albertel 14412:
1.575 albertel 14413: sub lonhttpdurl {
1.692 www 14414: #
14415: # Had been used for "small fry" static images on separate port 8080.
14416: # Modify here if lightweight http functionality desired again.
14417: # Currently eliminated due to increasing firewall issues.
14418: #
1.575 albertel 14419: my ($url)=@_;
1.692 www 14420: return $url;
1.215 albertel 14421: }
14422:
1.213 albertel 14423: sub connection_aborted {
14424: my ($r)=@_;
14425: $r->print(" ");$r->rflush();
14426: my $c = $r->connection;
14427: return $c->aborted();
14428: }
14429:
1.221 foxr 14430: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14431: # strings as 'strings'.
14432: sub escape_single {
1.221 foxr 14433: my ($input) = @_;
1.223 albertel 14434: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14435: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14436: return $input;
14437: }
1.223 albertel 14438:
1.222 foxr 14439: # Same as escape_single, but escape's "'s This
14440: # can be used for "strings"
14441: sub escape_double {
14442: my ($input) = @_;
14443: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14444: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14445: return $input;
14446: }
1.223 albertel 14447:
1.222 foxr 14448: # Escapes the last element of a full URL.
14449: sub escape_url {
14450: my ($url) = @_;
1.238 raeburn 14451: my @urlslices = split(/\//, $url,-1);
1.369 www 14452: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14453: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14454: }
1.462 albertel 14455:
1.820 raeburn 14456: sub compare_arrays {
14457: my ($arrayref1,$arrayref2) = @_;
14458: my (@difference,%count);
14459: @difference = ();
14460: %count = ();
14461: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14462: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14463: foreach my $element (keys(%count)) {
14464: if ($count{$element} == 1) {
14465: push(@difference,$element);
14466: }
14467: }
14468: }
14469: return @difference;
14470: }
14471:
1.817 bisitz 14472: # -------------------------------------------------------- Initialize user login
1.462 albertel 14473: sub init_user_environment {
1.463 albertel 14474: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14475: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14476:
14477: my $public=($username eq 'public' && $domain eq 'public');
14478:
14479: # See if old ID present, if so, remove
14480:
1.1062 raeburn 14481: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14482: my $now=time;
14483:
14484: if ($public) {
14485: my $max_public=100;
14486: my $oldest;
14487: my $oldest_time=0;
14488: for(my $next=1;$next<=$max_public;$next++) {
14489: if (-e $lonids."/publicuser_$next.id") {
14490: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14491: if ($mtime<$oldest_time || !$oldest_time) {
14492: $oldest_time=$mtime;
14493: $oldest=$next;
14494: }
14495: } else {
14496: $cookie="publicuser_$next";
14497: last;
14498: }
14499: }
14500: if (!$cookie) { $cookie="publicuser_$oldest"; }
14501: } else {
1.463 albertel 14502: # if this isn't a robot, kill any existing non-robot sessions
14503: if (!$args->{'robot'}) {
14504: opendir(DIR,$lonids);
14505: while ($filename=readdir(DIR)) {
14506: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14507: unlink($lonids.'/'.$filename);
14508: }
1.462 albertel 14509: }
1.463 albertel 14510: closedir(DIR);
1.462 albertel 14511: }
14512: # Give them a new cookie
1.463 albertel 14513: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14514: : $now.$$.int(rand(10000)));
1.463 albertel 14515: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14516:
14517: # Initialize roles
14518:
1.1062 raeburn 14519: ($userroles,$firstaccenv,$timerintenv) =
14520: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14521: }
14522: # ------------------------------------ Check browser type and MathML capability
14523:
14524: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.42 raeburn 14525: $clientunicode,$clientos,$clientmobile,$clientinfo) = &decode_user_agent($r);
1.462 albertel 14526:
14527: # ------------------------------------------------------------- Get environment
14528:
14529: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14530: my ($tmp) = keys(%userenv);
14531: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14532: } else {
14533: undef(%userenv);
14534: }
14535: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14536: $form->{'interface'}=$userenv{'interface'};
14537: }
14538: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14539:
14540: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14541: foreach my $option ('interface','localpath','localres') {
14542: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14543: }
14544: # --------------------------------------------------------- Write first profile
14545:
14546: {
14547: my %initial_env =
14548: ("user.name" => $username,
14549: "user.domain" => $domain,
14550: "user.home" => $authhost,
14551: "browser.type" => $clientbrowser,
14552: "browser.version" => $clientversion,
14553: "browser.mathml" => $clientmathml,
14554: "browser.unicode" => $clientunicode,
14555: "browser.os" => $clientos,
1.1075.2.42 raeburn 14556: "browser.mobile" => $clientmobile,
14557: "browser.info" => $clientinfo,
1.462 albertel 14558: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14559: "request.course.fn" => '',
14560: "request.course.uri" => '',
14561: "request.course.sec" => '',
14562: "request.role" => 'cm',
14563: "request.role.adv" => $env{'user.adv'},
14564: "request.host" => $ENV{'REMOTE_ADDR'},);
14565:
14566: if ($form->{'localpath'}) {
14567: $initial_env{"browser.localpath"} = $form->{'localpath'};
14568: $initial_env{"browser.localres"} = $form->{'localres'};
14569: }
14570:
14571: if ($form->{'interface'}) {
14572: $form->{'interface'}=~s/\W//gs;
14573: $initial_env{"browser.interface"} = $form->{'interface'};
14574: $env{'browser.interface'}=$form->{'interface'};
14575: }
14576:
1.1075.2.54 raeburn 14577: if ($form->{'iptoken'}) {
14578: my $lonhost = $r->dir_config('lonHostID');
14579: $initial_env{"user.noloadbalance"} = $lonhost;
14580: $env{'user.noloadbalance'} = $lonhost;
14581: }
14582:
1.981 raeburn 14583: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14584: my %domdef;
14585: unless ($domain eq 'public') {
14586: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14587: }
1.980 raeburn 14588:
1.1075.2.7 raeburn 14589: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14590: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14591: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14592: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14593: }
14594:
1.1075.2.59 raeburn 14595: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 14596: $userenv{'canrequest.'.$crstype} =
14597: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14598: 'reload','requestcourses',
14599: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14600: }
14601:
1.1075.2.14 raeburn 14602: $userenv{'canrequest.author'} =
14603: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14604: 'reload','requestauthor',
14605: \%userenv,\%domdef,\%is_adv);
14606: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14607: $domain,$username);
14608: my $reqstatus = $reqauthor{'author_status'};
14609: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14610: if (ref($reqauthor{'author'}) eq 'HASH') {
14611: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14612: $reqauthor{'author'}{'timestamp'};
14613: }
14614: }
14615:
1.462 albertel 14616: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14617:
1.462 albertel 14618: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14619: &GDBM_WRCREAT(),0640)) {
14620: &_add_to_env(\%disk_env,\%initial_env);
14621: &_add_to_env(\%disk_env,\%userenv,'environment.');
14622: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14623: if (ref($firstaccenv) eq 'HASH') {
14624: &_add_to_env(\%disk_env,$firstaccenv);
14625: }
14626: if (ref($timerintenv) eq 'HASH') {
14627: &_add_to_env(\%disk_env,$timerintenv);
14628: }
1.463 albertel 14629: if (ref($args->{'extra_env'})) {
14630: &_add_to_env(\%disk_env,$args->{'extra_env'});
14631: }
1.462 albertel 14632: untie(%disk_env);
14633: } else {
1.705 tempelho 14634: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14635: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14636: return 'error: '.$!;
14637: }
14638: }
14639: $env{'request.role'}='cm';
14640: $env{'request.role.adv'}=$env{'user.adv'};
14641: $env{'browser.type'}=$clientbrowser;
14642:
14643: return $cookie;
14644:
14645: }
14646:
14647: sub _add_to_env {
14648: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14649: if (ref($env_data) eq 'HASH') {
14650: while (my ($key,$value) = each(%$env_data)) {
14651: $idf->{$prefix.$key} = $value;
14652: $env{$prefix.$key} = $value;
14653: }
1.462 albertel 14654: }
14655: }
14656:
1.685 tempelho 14657: # --- Get the symbolic name of a problem and the url
14658: sub get_symb {
14659: my ($request,$silent) = @_;
1.726 raeburn 14660: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14661: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14662: if ($symb eq '') {
14663: if (!$silent) {
1.1071 raeburn 14664: if (ref($request)) {
14665: $request->print("Unable to handle ambiguous references:$url:.");
14666: }
1.685 tempelho 14667: return ();
14668: }
14669: }
14670: &Apache::lonenc::check_decrypt(\$symb);
14671: return ($symb);
14672: }
14673:
14674: # --------------------------------------------------------------Get annotation
14675:
14676: sub get_annotation {
14677: my ($symb,$enc) = @_;
14678:
14679: my $key = $symb;
14680: if (!$enc) {
14681: $key =
14682: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14683: }
14684: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14685: return $annotation{$key};
14686: }
14687:
14688: sub clean_symb {
1.731 raeburn 14689: my ($symb,$delete_enc) = @_;
1.685 tempelho 14690:
14691: &Apache::lonenc::check_decrypt(\$symb);
14692: my $enc = $env{'request.enc'};
1.731 raeburn 14693: if ($delete_enc) {
1.730 raeburn 14694: delete($env{'request.enc'});
14695: }
1.685 tempelho 14696:
14697: return ($symb,$enc);
14698: }
1.462 albertel 14699:
1.1075.2.69 raeburn 14700: ############################################################
14701: ############################################################
14702:
14703: =pod
14704:
14705: =head1 Routines for building display used to search for courses
14706:
14707:
14708: =over 4
14709:
14710: =item * &build_filters()
14711:
14712: Create markup for a table used to set filters to use when selecting
14713: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
14714: and quotacheck.pl
14715:
14716:
14717: Inputs:
14718:
14719: filterlist - anonymous array of fields to include as potential filters
14720:
14721: crstype - course type
14722:
14723: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
14724: to pop-open a course selector (will contain "extra element").
14725:
14726: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
14727:
14728: filter - anonymous hash of criteria and their values
14729:
14730: action - form action
14731:
14732: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
14733:
14734: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
14735:
14736: cloneruname - username of owner of new course who wants to clone
14737:
14738: clonerudom - domain of owner of new course who wants to clone
14739:
14740: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
14741:
14742: codetitlesref - reference to array of titles of components in institutional codes (official courses)
14743:
14744: codedom - domain
14745:
14746: formname - value of form element named "form".
14747:
14748: fixeddom - domain, if fixed.
14749:
14750: prevphase - value to assign to form element named "phase" when going back to the previous screen
14751:
14752: cnameelement - name of form element in form on opener page which will receive title of selected course
14753:
14754: cnumelement - name of form element in form on opener page which will receive courseID of selected course
14755:
14756: cdomelement - name of form element in form on opener page which will receive domain of selected course
14757:
14758: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
14759:
14760: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
14761:
14762: clonewarning - warning message about missing information for intended course owner when DC creates a course
14763:
14764:
14765: Returns: $output - HTML for display of search criteria, and hidden form elements.
14766:
14767:
14768: Side Effects: None
14769:
14770: =cut
14771:
14772: # ---------------------------------------------- search for courses based on last activity etc.
14773:
14774: sub build_filters {
14775: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
14776: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
14777: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
14778: $cnameelement,$cnumelement,$cdomelement,$setroles,
14779: $clonetext,$clonewarning) = @_;
14780: my ($list,$jscript);
14781: my $onchange = 'javascript:updateFilters(this)';
14782: my ($domainselectform,$sincefilterform,$createdfilterform,
14783: $ownerdomselectform,$persondomselectform,$instcodeform,
14784: $typeselectform,$instcodetitle);
14785: if ($formname eq '') {
14786: $formname = $caller;
14787: }
14788: foreach my $item (@{$filterlist}) {
14789: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
14790: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
14791: if ($item eq 'domainfilter') {
14792: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
14793: } elsif ($item eq 'coursefilter') {
14794: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
14795: } elsif ($item eq 'ownerfilter') {
14796: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
14797: } elsif ($item eq 'ownerdomfilter') {
14798: $filter->{'ownerdomfilter'} =
14799: &LONCAPA::clean_domain($filter->{$item});
14800: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
14801: 'ownerdomfilter',1);
14802: } elsif ($item eq 'personfilter') {
14803: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
14804: } elsif ($item eq 'persondomfilter') {
14805: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
14806: 'persondomfilter',1);
14807: } else {
14808: $filter->{$item} =~ s/\W//g;
14809: }
14810: if (!$filter->{$item}) {
14811: $filter->{$item} = '';
14812: }
14813: }
14814: if ($item eq 'domainfilter') {
14815: my $allow_blank = 1;
14816: if ($formname eq 'portform') {
14817: $allow_blank=0;
14818: } elsif ($formname eq 'studentform') {
14819: $allow_blank=0;
14820: }
14821: if ($fixeddom) {
14822: $domainselectform = '<input type="hidden" name="domainfilter"'.
14823: ' value="'.$codedom.'" />'.
14824: &Apache::lonnet::domain($codedom,'description');
14825: } else {
14826: $domainselectform = &select_dom_form($filter->{$item},
14827: 'domainfilter',
14828: $allow_blank,'',$onchange);
14829: }
14830: } else {
14831: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
14832: }
14833: }
14834:
14835: # last course activity filter and selection
14836: $sincefilterform = &timebased_select_form('sincefilter',$filter);
14837:
14838: # course created filter and selection
14839: if (exists($filter->{'createdfilter'})) {
14840: $createdfilterform = &timebased_select_form('createdfilter',$filter);
14841: }
14842:
14843: my %lt = &Apache::lonlocal::texthash(
14844: 'cac' => "$crstype Activity",
14845: 'ccr' => "$crstype Created",
14846: 'cde' => "$crstype Title",
14847: 'cdo' => "$crstype Domain",
14848: 'ins' => 'Institutional Code',
14849: 'inc' => 'Institutional Categorization',
14850: 'cow' => "$crstype Owner/Co-owner",
14851: 'cop' => "$crstype Personnel Includes",
14852: 'cog' => 'Type',
14853: );
14854:
14855: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
14856: my $typeval = 'Course';
14857: if ($crstype eq 'Community') {
14858: $typeval = 'Community';
14859: }
14860: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
14861: } else {
14862: $typeselectform = '<select name="type" size="1"';
14863: if ($onchange) {
14864: $typeselectform .= ' onchange="'.$onchange.'"';
14865: }
14866: $typeselectform .= '>'."\n";
14867: foreach my $posstype ('Course','Community') {
14868: $typeselectform.='<option value="'.$posstype.'"'.
14869: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
14870: }
14871: $typeselectform.="</select>";
14872: }
14873:
14874: my ($cloneableonlyform,$cloneabletitle);
14875: if (exists($filter->{'cloneableonly'})) {
14876: my $cloneableon = '';
14877: my $cloneableoff = ' checked="checked"';
14878: if ($filter->{'cloneableonly'}) {
14879: $cloneableon = $cloneableoff;
14880: $cloneableoff = '';
14881: }
14882: $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>';
14883: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 14884: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 14885: } else {
14886: $cloneabletitle = &mt('Cloneable by you');
14887: }
14888: }
14889: my $officialjs;
14890: if ($crstype eq 'Course') {
14891: if (exists($filter->{'instcodefilter'})) {
14892: # if (($fixeddom) || ($formname eq 'requestcrs') ||
14893: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
14894: if ($codedom) {
14895: $officialjs = 1;
14896: ($instcodeform,$jscript,$$numtitlesref) =
14897: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
14898: $officialjs,$codetitlesref);
14899: if ($jscript) {
14900: $jscript = '<script type="text/javascript">'."\n".
14901: '// <![CDATA['."\n".
14902: $jscript."\n".
14903: '// ]]>'."\n".
14904: '</script>'."\n";
14905: }
14906: }
14907: if ($instcodeform eq '') {
14908: $instcodeform =
14909: '<input type="text" name="instcodefilter" size="10" value="'.
14910: $list->{'instcodefilter'}.'" />';
14911: $instcodetitle = $lt{'ins'};
14912: } else {
14913: $instcodetitle = $lt{'inc'};
14914: }
14915: if ($fixeddom) {
14916: $instcodetitle .= '<br />('.$codedom.')';
14917: }
14918: }
14919: }
14920: my $output = qq|
14921: <form method="post" name="filterpicker" action="$action">
14922: <input type="hidden" name="form" value="$formname" />
14923: |;
14924: if ($formname eq 'modifycourse') {
14925: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
14926: '<input type="hidden" name="prevphase" value="'.
14927: $prevphase.'" />'."\n";
14928: } elsif ($formname ne 'quotacheck') {
14929: my $name_input;
14930: if ($cnameelement ne '') {
14931: $name_input = '<input type="hidden" name="cnameelement" value="'.
14932: $cnameelement.'" />';
14933: }
14934: $output .= qq|
14935: <input type="hidden" name="cnumelement" value="$cnumelement" />
14936: <input type="hidden" name="cdomelement" value="$cdomelement" />
14937: $name_input
14938: $roleelement
14939: $multelement
14940: $typeelement
14941: |;
14942: if ($formname eq 'portform') {
14943: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
14944: }
14945: }
14946: if ($fixeddom) {
14947: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
14948: }
14949: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
14950: if ($sincefilterform) {
14951: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
14952: .$sincefilterform
14953: .&Apache::lonhtmlcommon::row_closure();
14954: }
14955: if ($createdfilterform) {
14956: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
14957: .$createdfilterform
14958: .&Apache::lonhtmlcommon::row_closure();
14959: }
14960: if ($domainselectform) {
14961: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
14962: .$domainselectform
14963: .&Apache::lonhtmlcommon::row_closure();
14964: }
14965: if ($typeselectform) {
14966: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
14967: $output .= $typeselectform;
14968: } else {
14969: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
14970: .$typeselectform
14971: .&Apache::lonhtmlcommon::row_closure();
14972: }
14973: }
14974: if ($instcodeform) {
14975: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
14976: .$instcodeform
14977: .&Apache::lonhtmlcommon::row_closure();
14978: }
14979: if (exists($filter->{'ownerfilter'})) {
14980: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
14981: '<table><tr><td>'.&mt('Username').'<br />'.
14982: '<input type="text" name="ownerfilter" size="20" value="'.
14983: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
14984: $ownerdomselectform.'</td></tr></table>'.
14985: &Apache::lonhtmlcommon::row_closure();
14986: }
14987: if (exists($filter->{'personfilter'})) {
14988: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
14989: '<table><tr><td>'.&mt('Username').'<br />'.
14990: '<input type="text" name="personfilter" size="20" value="'.
14991: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
14992: $persondomselectform.'</td></tr></table>'.
14993: &Apache::lonhtmlcommon::row_closure();
14994: }
14995: if (exists($filter->{'coursefilter'})) {
14996: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
14997: .'<input type="text" name="coursefilter" size="25" value="'
14998: .$list->{'coursefilter'}.'" />'
14999: .&Apache::lonhtmlcommon::row_closure();
15000: }
15001: if ($cloneableonlyform) {
15002: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15003: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15004: }
15005: if (exists($filter->{'descriptfilter'})) {
15006: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15007: .'<input type="text" name="descriptfilter" size="40" value="'
15008: .$list->{'descriptfilter'}.'" />'
15009: .&Apache::lonhtmlcommon::row_closure(1);
15010: }
15011: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15012: '<input type="hidden" name="updater" value="" />'."\n".
15013: '<input type="submit" name="gosearch" value="'.
15014: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15015: return $jscript.$clonewarning.$output;
15016: }
15017:
15018: =pod
15019:
15020: =item * &timebased_select_form()
15021:
15022: Create markup for a dropdown list used to select a time-based
15023: filter e.g., Course Activity, Course Created, when searching for courses
15024: or communities
15025:
15026: Inputs:
15027:
15028: item - name of form element (sincefilter or createdfilter)
15029:
15030: filter - anonymous hash of criteria and their values
15031:
15032: Returns: HTML for a select box contained a blank, then six time selections,
15033: with value set in incoming form variables currently selected.
15034:
15035: Side Effects: None
15036:
15037: =cut
15038:
15039: sub timebased_select_form {
15040: my ($item,$filter) = @_;
15041: if (ref($filter) eq 'HASH') {
15042: $filter->{$item} =~ s/[^\d-]//g;
15043: if (!$filter->{$item}) { $filter->{$item}=-1; }
15044: return &select_form(
15045: $filter->{$item},
15046: $item,
15047: { '-1' => '',
15048: '86400' => &mt('today'),
15049: '604800' => &mt('last week'),
15050: '2592000' => &mt('last month'),
15051: '7776000' => &mt('last three months'),
15052: '15552000' => &mt('last six months'),
15053: '31104000' => &mt('last year'),
15054: 'select_form_order' =>
15055: ['-1','86400','604800','2592000','7776000',
15056: '15552000','31104000']});
15057: }
15058: }
15059:
15060: =pod
15061:
15062: =item * &js_changer()
15063:
15064: Create script tag containing Javascript used to submit course search form
15065: when course type or domain is changed, and also to hide 'Searching ...' on
15066: page load completion for page showing search result.
15067:
15068: Inputs: None
15069:
15070: Returns: markup containing updateFilters() and hideSearching() javascript functions.
15071:
15072: Side Effects: None
15073:
15074: =cut
15075:
15076: sub js_changer {
15077: return <<ENDJS;
15078: <script type="text/javascript">
15079: // <![CDATA[
15080: function updateFilters(caller) {
15081: if (typeof(caller) != "undefined") {
15082: document.filterpicker.updater.value = caller.name;
15083: }
15084: document.filterpicker.submit();
15085: }
15086:
15087: function hideSearching() {
15088: if (document.getElementById('searching')) {
15089: document.getElementById('searching').style.display = 'none';
15090: }
15091: return;
15092: }
15093:
15094: // ]]>
15095: </script>
15096:
15097: ENDJS
15098: }
15099:
15100: =pod
15101:
15102: =item * &search_courses()
15103:
15104: Process selected filters form course search form and pass to lonnet::courseiddump
15105: to retrieve a hash for which keys are courseIDs which match the selected filters.
15106:
15107: Inputs:
15108:
15109: dom - domain being searched
15110:
15111: type - course type ('Course' or 'Community' or '.' if any).
15112:
15113: filter - anonymous hash of criteria and their values
15114:
15115: numtitles - for institutional codes - number of categories
15116:
15117: cloneruname - optional username of new course owner
15118:
15119: clonerudom - optional domain of new course owner
15120:
15121: domcloner - Optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
15122: (used when DC is using course creation form)
15123:
15124: codetitles - reference to array of titles of components in institutional codes (official courses).
15125:
15126:
15127: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
15128:
15129:
15130: Side Effects: None
15131:
15132: =cut
15133:
15134:
15135: sub search_courses {
15136: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_;
15137: my (%courses,%showcourses,$cloner);
15138: if (($filter->{'ownerfilter'} ne '') ||
15139: ($filter->{'ownerdomfilter'} ne '')) {
15140: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
15141: $filter->{'ownerdomfilter'};
15142: }
15143: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
15144: if (!$filter->{$item}) {
15145: $filter->{$item}='.';
15146: }
15147: }
15148: my $now = time;
15149: my $timefilter =
15150: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
15151: my ($createdbefore,$createdafter);
15152: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
15153: $createdbefore = $now;
15154: $createdafter = $now-$filter->{'createdfilter'};
15155: }
15156: my ($instcodefilter,$regexpok);
15157: if ($numtitles) {
15158: if ($env{'form.official'} eq 'on') {
15159: $instcodefilter =
15160: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15161: $regexpok = 1;
15162: } elsif ($env{'form.official'} eq 'off') {
15163: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15164: unless ($instcodefilter eq '') {
15165: $regexpok = -1;
15166: }
15167: }
15168: } else {
15169: $instcodefilter = $filter->{'instcodefilter'};
15170: }
15171: if ($instcodefilter eq '') { $instcodefilter = '.'; }
15172: if ($type eq '') { $type = '.'; }
15173:
15174: if (($clonerudom ne '') && ($cloneruname ne '')) {
15175: $cloner = $cloneruname.':'.$clonerudom;
15176: }
15177: %courses = &Apache::lonnet::courseiddump($dom,
15178: $filter->{'descriptfilter'},
15179: $timefilter,
15180: $instcodefilter,
15181: $filter->{'combownerfilter'},
15182: $filter->{'coursefilter'},
15183: undef,undef,$type,$regexpok,undef,undef,
15184: undef,undef,$cloner,$env{'form.cc_clone'},
15185: $filter->{'cloneableonly'},
15186: $createdbefore,$createdafter,undef,
15187: $domcloner);
15188: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
15189: my $ccrole;
15190: if ($type eq 'Community') {
15191: $ccrole = 'co';
15192: } else {
15193: $ccrole = 'cc';
15194: }
15195: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
15196: $filter->{'persondomfilter'},
15197: 'userroles',undef,
15198: [$ccrole,'in','ad','ep','ta','cr'],
15199: $dom);
15200: foreach my $role (keys(%rolehash)) {
15201: my ($cnum,$cdom,$courserole) = split(':',$role);
15202: my $cid = $cdom.'_'.$cnum;
15203: if (exists($courses{$cid})) {
15204: if (ref($courses{$cid}) eq 'HASH') {
15205: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
15206: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
15207: push (@{$courses{$cid}{roles}},$courserole);
15208: }
15209: } else {
15210: $courses{$cid}{roles} = [$courserole];
15211: }
15212: $showcourses{$cid} = $courses{$cid};
15213: }
15214: }
15215: }
15216: %courses = %showcourses;
15217: }
15218: return %courses;
15219: }
15220:
15221:
15222: =pod
15223:
15224: =back
15225:
15226: =cut
15227:
15228:
1.990 raeburn 15229: sub build_release_hashes {
15230: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
15231: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
15232: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
15233: (ref($randomizetry) eq 'HASH'));
15234: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
15235: my ($item,$name,$value) = split(/:/,$key);
15236: if ($item eq 'parameter') {
15237: if (ref($checkparms->{$name}) eq 'ARRAY') {
15238: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
15239: push(@{$checkparms->{$name}},$value);
15240: }
15241: } else {
15242: push(@{$checkparms->{$name}},$value);
15243: }
15244: } elsif ($item eq 'resourcetag') {
15245: if ($name eq 'responsetype') {
15246: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
15247: }
15248: } elsif ($item eq 'course') {
15249: if ($name eq 'crstype') {
15250: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
15251: }
15252: }
15253: }
15254: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
15255: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
15256: return;
15257: }
15258:
1.1075.2.11 raeburn 15259: sub update_content_constraints {
15260: my ($cdom,$cnum,$chome,$cid) = @_;
15261: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15262: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
15263: my %checkresponsetypes;
15264: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
15265: my ($item,$name,$value) = split(/:/,$key);
15266: if ($item eq 'resourcetag') {
15267: if ($name eq 'responsetype') {
15268: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
15269: }
15270: }
15271: }
15272: my $navmap = Apache::lonnavmaps::navmap->new();
15273: if (defined($navmap)) {
15274: my %allresponses;
15275: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
15276: my %responses = $res->responseTypes();
15277: foreach my $key (keys(%responses)) {
15278: next unless(exists($checkresponsetypes{$key}));
15279: $allresponses{$key} += $responses{$key};
15280: }
15281: }
15282: foreach my $key (keys(%allresponses)) {
15283: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
15284: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
15285: ($reqdmajor,$reqdminor) = ($major,$minor);
15286: }
15287: }
15288: undef($navmap);
15289: }
15290: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
15291: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
15292: }
15293: return;
15294: }
15295:
1.1075.2.27 raeburn 15296: sub allmaps_incourse {
15297: my ($cdom,$cnum,$chome,$cid) = @_;
15298: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
15299: $cid = $env{'request.course.id'};
15300: $cdom = $env{'course.'.$cid.'.domain'};
15301: $cnum = $env{'course.'.$cid.'.num'};
15302: $chome = $env{'course.'.$cid.'.home'};
15303: }
15304: my %allmaps = ();
15305: my $lastchange =
15306: &Apache::lonnet::get_coursechange($cdom,$cnum);
15307: if ($lastchange > $env{'request.course.tied'}) {
15308: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
15309: unless ($ferr) {
15310: &update_content_constraints($cdom,$cnum,$chome,$cid);
15311: }
15312: }
15313: my $navmap = Apache::lonnavmaps::navmap->new();
15314: if (defined($navmap)) {
15315: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
15316: $allmaps{$res->src()} = 1;
15317: }
15318: }
15319: return \%allmaps;
15320: }
15321:
1.1075.2.11 raeburn 15322: sub parse_supplemental_title {
15323: my ($title) = @_;
15324:
15325: my ($foldertitle,$renametitle);
15326: if ($title =~ /&&&/) {
15327: $title = &HTML::Entites::decode($title);
15328: }
15329: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
15330: $renametitle=$4;
15331: my ($time,$uname,$udom) = ($1,$2,$3);
15332: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
15333: my $name = &plainname($uname,$udom);
15334: $name = &HTML::Entities::encode($name,'"<>&\'');
15335: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
15336: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
15337: $name.': <br />'.$foldertitle;
15338: }
15339: if (wantarray) {
15340: return ($title,$foldertitle,$renametitle);
15341: }
15342: return $title;
15343: }
15344:
1.1075.2.43 raeburn 15345: sub recurse_supplemental {
15346: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
15347: if ($suppmap) {
15348: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
15349: if ($fatal) {
15350: $errors ++;
15351: } else {
15352: if ($#LONCAPA::map::resources > 0) {
15353: foreach my $res (@LONCAPA::map::resources) {
15354: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
15355: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 15356: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
15357: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 15358: } else {
15359: $numfiles ++;
15360: }
15361: }
15362: }
15363: }
15364: }
15365: }
15366: return ($numfiles,$errors);
15367: }
15368:
1.1075.2.18 raeburn 15369: sub symb_to_docspath {
15370: my ($symb) = @_;
15371: return unless ($symb);
15372: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
15373: if ($resurl=~/\.(sequence|page)$/) {
15374: $mapurl=$resurl;
15375: } elsif ($resurl eq 'adm/navmaps') {
15376: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
15377: }
15378: my $mapresobj;
15379: my $navmap = Apache::lonnavmaps::navmap->new();
15380: if (ref($navmap)) {
15381: $mapresobj = $navmap->getResourceByUrl($mapurl);
15382: }
15383: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
15384: my $type=$2;
15385: my $path;
15386: if (ref($mapresobj)) {
15387: my $pcslist = $mapresobj->map_hierarchy();
15388: if ($pcslist ne '') {
15389: foreach my $pc (split(/,/,$pcslist)) {
15390: next if ($pc <= 1);
15391: my $res = $navmap->getByMapPc($pc);
15392: if (ref($res)) {
15393: my $thisurl = $res->src();
15394: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
15395: my $thistitle = $res->title();
15396: $path .= '&'.
15397: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 15398: &escape($thistitle).
1.1075.2.18 raeburn 15399: ':'.$res->randompick().
15400: ':'.$res->randomout().
15401: ':'.$res->encrypted().
15402: ':'.$res->randomorder().
15403: ':'.$res->is_page();
15404: }
15405: }
15406: }
15407: $path =~ s/^\&//;
15408: my $maptitle = $mapresobj->title();
15409: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 15410: $maptitle = 'Main Content';
1.1075.2.18 raeburn 15411: }
15412: $path .= (($path ne '')? '&' : '').
15413: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 15414: &escape($maptitle).
1.1075.2.18 raeburn 15415: ':'.$mapresobj->randompick().
15416: ':'.$mapresobj->randomout().
15417: ':'.$mapresobj->encrypted().
15418: ':'.$mapresobj->randomorder().
15419: ':'.$mapresobj->is_page();
15420: } else {
15421: my $maptitle = &Apache::lonnet::gettitle($mapurl);
15422: my $ispage = (($type eq 'page')? 1 : '');
15423: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 15424: $maptitle = 'Main Content';
1.1075.2.18 raeburn 15425: }
15426: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 15427: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 15428: }
15429: unless ($mapurl eq 'default') {
15430: $path = 'default&'.
1.1075.2.46 raeburn 15431: &escape('Main Content').
1.1075.2.18 raeburn 15432: ':::::&'.$path;
15433: }
15434: return $path;
15435: }
15436:
1.1075.2.14 raeburn 15437: sub captcha_display {
15438: my ($context,$lonhost) = @_;
15439: my ($output,$error);
15440: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
15441: if ($captcha eq 'original') {
15442: $output = &create_captcha();
15443: unless ($output) {
15444: $error = 'captcha';
15445: }
15446: } elsif ($captcha eq 'recaptcha') {
15447: $output = &create_recaptcha($pubkey);
15448: unless ($output) {
15449: $error = 'recaptcha';
15450: }
15451: }
1.1075.2.66 raeburn 15452: return ($output,$error,$captcha);
1.1075.2.14 raeburn 15453: }
15454:
15455: sub captcha_response {
15456: my ($context,$lonhost) = @_;
15457: my ($captcha_chk,$captcha_error);
15458: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
15459: if ($captcha eq 'original') {
15460: ($captcha_chk,$captcha_error) = &check_captcha();
15461: } elsif ($captcha eq 'recaptcha') {
15462: $captcha_chk = &check_recaptcha($privkey);
15463: } else {
15464: $captcha_chk = 1;
15465: }
15466: return ($captcha_chk,$captcha_error);
15467: }
15468:
15469: sub get_captcha_config {
15470: my ($context,$lonhost) = @_;
15471: my ($captcha,$pubkey,$privkey,$hashtocheck);
15472: my $hostname = &Apache::lonnet::hostname($lonhost);
15473: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
15474: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
15475: if ($context eq 'usercreation') {
15476: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
15477: if (ref($domconfig{$context}) eq 'HASH') {
15478: $hashtocheck = $domconfig{$context}{'cancreate'};
15479: if (ref($hashtocheck) eq 'HASH') {
15480: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
15481: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
15482: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
15483: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
15484: }
15485: if ($privkey && $pubkey) {
15486: $captcha = 'recaptcha';
15487: } else {
15488: $captcha = 'original';
15489: }
15490: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
15491: $captcha = 'original';
15492: }
15493: }
15494: } else {
15495: $captcha = 'captcha';
15496: }
15497: } elsif ($context eq 'login') {
15498: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
15499: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
15500: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
15501: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
15502: if ($privkey && $pubkey) {
15503: $captcha = 'recaptcha';
15504: } else {
15505: $captcha = 'original';
15506: }
15507: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
15508: $captcha = 'original';
15509: }
15510: }
15511: return ($captcha,$pubkey,$privkey);
15512: }
15513:
15514: sub create_captcha {
15515: my %captcha_params = &captcha_settings();
15516: my ($output,$maxtries,$tries) = ('',10,0);
15517: while ($tries < $maxtries) {
15518: $tries ++;
15519: my $captcha = Authen::Captcha->new (
15520: output_folder => $captcha_params{'output_dir'},
15521: data_folder => $captcha_params{'db_dir'},
15522: );
15523: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
15524:
15525: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
15526: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
15527: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 15528: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
15529: '<br />'.
15530: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 15531: last;
15532: }
15533: }
15534: return $output;
15535: }
15536:
15537: sub captcha_settings {
15538: my %captcha_params = (
15539: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
15540: www_output_dir => "/captchaspool",
15541: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
15542: numchars => '5',
15543: );
15544: return %captcha_params;
15545: }
15546:
15547: sub check_captcha {
15548: my ($captcha_chk,$captcha_error);
15549: my $code = $env{'form.code'};
15550: my $md5sum = $env{'form.crypt'};
15551: my %captcha_params = &captcha_settings();
15552: my $captcha = Authen::Captcha->new(
15553: output_folder => $captcha_params{'output_dir'},
15554: data_folder => $captcha_params{'db_dir'},
15555: );
1.1075.2.26 raeburn 15556: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 15557: my %captcha_hash = (
15558: 0 => 'Code not checked (file error)',
15559: -1 => 'Failed: code expired',
15560: -2 => 'Failed: invalid code (not in database)',
15561: -3 => 'Failed: invalid code (code does not match crypt)',
15562: );
15563: if ($captcha_chk != 1) {
15564: $captcha_error = $captcha_hash{$captcha_chk}
15565: }
15566: return ($captcha_chk,$captcha_error);
15567: }
15568:
15569: sub create_recaptcha {
15570: my ($pubkey) = @_;
1.1075.2.51 raeburn 15571: my $use_ssl;
15572: if ($ENV{'SERVER_PORT'} == 443) {
15573: $use_ssl = 1;
15574: }
1.1075.2.14 raeburn 15575: my $captcha = Captcha::reCAPTCHA->new;
15576: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1075.2.51 raeburn 15577: $captcha->get_html($pubkey,undef,$use_ssl).
1.1075.2.14 raeburn 15578: &mt('If either word is hard to read, [_1] will replace them.',
1.1075.2.39 raeburn 15579: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1075.2.14 raeburn 15580: '<br /><br />';
15581: }
15582:
15583: sub check_recaptcha {
15584: my ($privkey) = @_;
15585: my $captcha_chk;
15586: my $captcha = Captcha::reCAPTCHA->new;
15587: my $captcha_result =
15588: $captcha->check_answer(
15589: $privkey,
15590: $ENV{'REMOTE_ADDR'},
15591: $env{'form.recaptcha_challenge_field'},
15592: $env{'form.recaptcha_response_field'},
15593: );
15594: if ($captcha_result->{is_valid}) {
15595: $captcha_chk = 1;
15596: }
15597: return $captcha_chk;
15598: }
15599:
1.1075.2.64 raeburn 15600: sub emailusername_info {
1.1075.2.67 raeburn 15601: my @fields = ('firstname','lastname','institution','web','location','officialemail');
1.1075.2.64 raeburn 15602: my %titles = &Apache::lonlocal::texthash (
15603: lastname => 'Last Name',
15604: firstname => 'First Name',
15605: institution => 'School/college/university',
15606: location => "School's city, state/province, country",
15607: web => "School's web address",
15608: officialemail => 'E-mail address at institution (if different)',
15609: );
15610: return (\@fields,\%titles);
15611: }
15612:
1.1075.2.56 raeburn 15613: sub cleanup_html {
15614: my ($incoming) = @_;
15615: my $outgoing;
15616: if ($incoming ne '') {
15617: $outgoing = $incoming;
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: $outgoing =~ s{/}{/}g;
15629: $outgoing =~ s/=/=/g;
15630: $outgoing =~ s/\\/\/g
15631: }
15632: return $outgoing;
15633: }
15634:
1.1075.2.64 raeburn 15635: # Use:
15636: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
15637: #
15638: ##################################################
15639: # password associated functions #
15640: ##################################################
15641: sub des_keys {
15642: # Make a new key for DES encryption.
15643: # Each key has two parts which are returned separately.
15644: # Please note: Each key must be passed through the &hex function
15645: # before it is output to the web browser. The hex versions cannot
15646: # be used to decrypt.
15647: my @hexstr=('0','1','2','3','4','5','6','7',
15648: '8','9','a','b','c','d','e','f');
15649: my $lkey='';
15650: for (0..7) {
15651: $lkey.=$hexstr[rand(15)];
15652: }
15653: my $ukey='';
15654: for (0..7) {
15655: $ukey.=$hexstr[rand(15)];
15656: }
15657: return ($lkey,$ukey);
15658: }
15659:
15660: sub des_decrypt {
15661: my ($key,$cyphertext) = @_;
15662: my $keybin=pack("H16",$key);
15663: my $cypher;
15664: if ($Crypt::DES::VERSION>=2.03) {
15665: $cypher=new Crypt::DES $keybin;
15666: } else {
15667: $cypher=new DES $keybin;
15668: }
15669: my $plaintext=
15670: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
15671: $plaintext.=
15672: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
15673: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
15674: return $plaintext;
15675: }
15676:
1.112 bowersj2 15677: 1;
15678: __END__;
1.41 ng 15679:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>