Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.96
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.96! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.95 2015/05/22 17:33:11 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.94 raeburn 76: use Encode();
1.1075.2.14 raeburn 77: use Authen::Captcha;
78: use Captcha::reCAPTCHA;
1.1075.2.64 raeburn 79: use Crypt::DES;
80: use DynaLoader; # for Crypt::DES version
1.117 www 81:
1.517 raeburn 82: # ---------------------------------------------- Designs
83: use vars qw(%defaultdesign);
84:
1.22 www 85: my $readit;
86:
1.517 raeburn 87:
1.157 matthew 88: ##
89: ## Global Variables
90: ##
1.46 matthew 91:
1.643 foxr 92:
93: # ----------------------------------------------- SSI with retries:
94: #
95:
96: =pod
97:
1.648 raeburn 98: =head1 Server Side include with retries:
1.643 foxr 99:
100: =over 4
101:
1.648 raeburn 102: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 103:
104: Performs an ssi with some number of retries. Retries continue either
105: until the result is ok or until the retry count supplied by the
106: caller is exhausted.
107:
108: Inputs:
1.648 raeburn 109:
110: =over 4
111:
1.643 foxr 112: resource - Identifies the resource to insert.
1.648 raeburn 113:
1.643 foxr 114: retries - Count of the number of retries allowed.
1.648 raeburn 115:
1.643 foxr 116: form - Hash that identifies the rendering options.
117:
1.648 raeburn 118: =back
119:
120: Returns:
121:
122: =over 4
123:
1.643 foxr 124: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 125:
1.643 foxr 126: response - The response from the last attempt (which may or may not have been successful.
127:
1.648 raeburn 128: =back
129:
130: =back
131:
1.643 foxr 132: =cut
133:
134: sub ssi_with_retries {
135: my ($resource, $retries, %form) = @_;
136:
137:
138: my $ok = 0; # True if we got a good response.
139: my $content;
140: my $response;
141:
142: # Try to get the ssi done. within the retries count:
143:
144: do {
145: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
146: $ok = $response->is_success;
1.650 www 147: if (!$ok) {
148: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
149: }
1.643 foxr 150: $retries--;
151: } while (!$ok && ($retries > 0));
152:
153: if (!$ok) {
154: $content = ''; # On error return an empty content.
155: }
156: return ($content, $response);
157:
158: }
159:
160:
161:
1.20 www 162: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 163: my %language;
1.124 www 164: my %supported_language;
1.1048 foxr 165: my %latex_language; # For choosing hyphenation in <transl..>
166: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 167: my %cprtag;
1.192 taceyjo1 168: my %scprtag;
1.351 www 169: my %fe; my %fd; my %fm;
1.41 ng 170: my %category_extensions;
1.12 harris41 171:
1.46 matthew 172: # ---------------------------------------------- Thesaurus variables
1.144 matthew 173: #
174: # %Keywords:
175: # A hash used by &keyword to determine if a word is considered a keyword.
176: # $thesaurus_db_file
177: # Scalar containing the full path to the thesaurus database.
1.46 matthew 178:
179: my %Keywords;
180: my $thesaurus_db_file;
181:
1.144 matthew 182: #
183: # Initialize values from language.tab, copyright.tab, filetypes.tab,
184: # thesaurus.tab, and filecategories.tab.
185: #
1.18 www 186: BEGIN {
1.46 matthew 187: # Variable initialization
188: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
189: #
1.22 www 190: unless ($readit) {
1.12 harris41 191: # ------------------------------------------------------------------- languages
192: {
1.158 raeburn 193: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
194: '/language.tab';
195: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 196: while (my $line = <$fh>) {
197: next if ($line=~/^\#/);
198: chomp($line);
1.1048 foxr 199: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 200: $language{$key}=$val.' - '.$enc;
201: if ($sup) {
202: $supported_language{$key}=$sup;
203: }
1.1048 foxr 204: if ($latex) {
205: $latex_language_bykey{$key} = $latex;
206: $latex_language{$two} = $latex;
207: }
1.158 raeburn 208: }
209: close($fh);
210: }
1.12 harris41 211: }
212: # ------------------------------------------------------------------ copyrights
213: {
1.158 raeburn 214: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/copyright.tab';
216: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line=~/^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 221: $cprtag{$key}=$val;
222: }
223: close($fh);
224: }
1.12 harris41 225: }
1.351 www 226: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 227: {
228: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
229: '/source_copyright.tab';
230: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 235: $scprtag{$key}=$val;
236: }
237: close($fh);
238: }
239: }
1.63 www 240:
1.517 raeburn 241: # -------------------------------------------------------------- default domain designs
1.63 www 242: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 243: my $designfile = $designdir.'/default.tab';
244: if ( open (my $fh,"<$designfile") ) {
245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($key,$val)=(split(/\=/,$line));
249: if ($val) { $defaultdesign{$key}=$val; }
250: }
251: close($fh);
1.63 www 252: }
253:
1.15 harris41 254: # ------------------------------------------------------------- file categories
255: {
1.158 raeburn 256: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
257: '/filecategories.tab';
258: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 259: while (my $line = <$fh>) {
260: next if ($line =~ /^\#/);
261: chomp($line);
262: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 263: push @{$category_extensions{lc($category)}},$extension;
264: }
265: close($fh);
266: }
267:
1.15 harris41 268: }
1.12 harris41 269: # ------------------------------------------------------------------ file types
270: {
1.158 raeburn 271: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
272: '/filetypes.tab';
273: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 274: while (my $line = <$fh>) {
275: next if ($line =~ /^\#/);
276: chomp($line);
277: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 278: if ($descr ne '') {
279: $fe{$ending}=lc($emb);
280: $fd{$ending}=$descr;
1.351 www 281: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 282: }
283: }
284: close($fh);
285: }
1.12 harris41 286: }
1.22 www 287: &Apache::lonnet::logthis(
1.705 tempelho 288: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 289: $readit=1;
1.46 matthew 290: } # end of unless($readit)
1.32 matthew 291:
292: }
1.112 bowersj2 293:
1.42 matthew 294: ###############################################################
295: ## HTML and Javascript Helper Functions ##
296: ###############################################################
297:
298: =pod
299:
1.112 bowersj2 300: =head1 HTML and Javascript Functions
1.42 matthew 301:
1.112 bowersj2 302: =over 4
303:
1.648 raeburn 304: =item * &browser_and_searcher_javascript()
1.112 bowersj2 305:
306: X<browsing, javascript>X<searching, javascript>Returns a string
307: containing javascript with two functions, C<openbrowser> and
308: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
309: tags.
1.42 matthew 310:
1.648 raeburn 311: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 312:
313: inputs: formname, elementname, only, omit
314:
315: formname and elementname indicate the name of the html form and name of
316: the element that the results of the browsing selection are to be placed in.
317:
318: Specifying 'only' will restrict the browser to displaying only files
1.185 www 319: with the given extension. Can be a comma separated list.
1.42 matthew 320:
321: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 322: with the given extension. Can be a comma separated list.
1.42 matthew 323:
1.648 raeburn 324: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 325:
326: Inputs: formname, elementname
327:
328: formname and elementname specify the name of the html form and the name
329: of the element the selection from the search results will be placed in.
1.542 raeburn 330:
1.42 matthew 331: =cut
332:
333: sub browser_and_searcher_javascript {
1.199 albertel 334: my ($mode)=@_;
335: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 336: my $resurl=&escape_single(&lastresurl());
1.42 matthew 337: return <<END;
1.219 albertel 338: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 339: var editbrowser = null;
1.135 albertel 340: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 341: var url = '$resurl/?';
1.42 matthew 342: if (editbrowser == null) {
343: url += 'launch=1&';
344: }
345: url += 'catalogmode=interactive&';
1.199 albertel 346: url += 'mode=$mode&';
1.611 albertel 347: url += 'inhibitmenu=yes&';
1.42 matthew 348: url += 'form=' + formname + '&';
349: if (only != null) {
350: url += 'only=' + only + '&';
1.217 albertel 351: } else {
352: url += 'only=&';
353: }
1.42 matthew 354: if (omit != null) {
355: url += 'omit=' + omit + '&';
1.217 albertel 356: } else {
357: url += 'omit=&';
358: }
1.135 albertel 359: if (titleelement != null) {
360: url += 'titleelement=' + titleelement + '&';
1.217 albertel 361: } else {
362: url += 'titleelement=&';
363: }
1.42 matthew 364: url += 'element=' + elementname + '';
365: var title = 'Browser';
1.435 albertel 366: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 367: options += ',width=700,height=600';
368: editbrowser = open(url,title,options,'1');
369: editbrowser.focus();
370: }
371: var editsearcher;
1.135 albertel 372: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 373: var url = '/adm/searchcat?';
374: if (editsearcher == null) {
375: url += 'launch=1&';
376: }
377: url += 'catalogmode=interactive&';
1.199 albertel 378: url += 'mode=$mode&';
1.42 matthew 379: url += 'form=' + formname + '&';
1.135 albertel 380: if (titleelement != null) {
381: url += 'titleelement=' + titleelement + '&';
1.217 albertel 382: } else {
383: url += 'titleelement=&';
384: }
1.42 matthew 385: url += 'element=' + elementname + '';
386: var title = 'Search';
1.435 albertel 387: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 388: options += ',width=700,height=600';
389: editsearcher = open(url,title,options,'1');
390: editsearcher.focus();
391: }
1.219 albertel 392: // END LON-CAPA Internal -->
1.42 matthew 393: END
1.170 www 394: }
395:
396: sub lastresurl {
1.258 albertel 397: if ($env{'environment.lastresurl'}) {
398: return $env{'environment.lastresurl'}
1.170 www 399: } else {
400: return '/res';
401: }
402: }
403:
404: sub storeresurl {
405: my $resurl=&Apache::lonnet::clutter(shift);
406: unless ($resurl=~/^\/res/) { return 0; }
407: $resurl=~s/\/$//;
408: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 409: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 410: return 1;
1.42 matthew 411: }
412:
1.74 www 413: sub studentbrowser_javascript {
1.111 www 414: unless (
1.258 albertel 415: (($env{'request.course.id'}) &&
1.302 albertel 416: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
417: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
418: '/'.$env{'request.course.sec'})
419: ))
1.258 albertel 420: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 421: ) { return ''; }
1.74 www 422: return (<<'ENDSTDBRW');
1.776 bisitz 423: <script type="text/javascript" language="Javascript">
1.824 bisitz 424: // <![CDATA[
1.74 www 425: var stdeditbrowser;
1.999 www 426: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 427: var url = '/adm/pickstudent?';
428: var filter;
1.558 albertel 429: if (!ignorefilter) {
430: eval('filter=document.'+formname+'.'+uname+'.value;');
431: }
1.74 www 432: if (filter != null) {
433: if (filter != '') {
434: url += 'filter='+filter+'&';
435: }
436: }
437: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 438: '&udomelement='+udom+
439: '&clicker='+clicker;
1.111 www 440: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 441: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 442: var title = 'Student_Browser';
1.74 www 443: var options = 'scrollbars=1,resizable=1,menubar=0';
444: options += ',width=700,height=600';
445: stdeditbrowser = open(url,title,options,'1');
446: stdeditbrowser.focus();
447: }
1.824 bisitz 448: // ]]>
1.74 www 449: </script>
450: ENDSTDBRW
451: }
1.42 matthew 452:
1.1003 www 453: sub resourcebrowser_javascript {
454: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 455: return (<<'ENDRESBRW');
1.1003 www 456: <script type="text/javascript" language="Javascript">
457: // <![CDATA[
458: var reseditbrowser;
1.1004 www 459: function openresbrowser(formname,reslink) {
1.1005 www 460: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 461: var title = 'Resource_Browser';
462: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 463: options += ',width=700,height=500';
1.1004 www 464: reseditbrowser = open(url,title,options,'1');
465: reseditbrowser.focus();
1.1003 www 466: }
467: // ]]>
468: </script>
1.1004 www 469: ENDRESBRW
1.1003 www 470: }
471:
1.74 www 472: sub selectstudent_link {
1.999 www 473: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
474: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
475: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
476: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 477: if ($env{'request.course.id'}) {
1.302 albertel 478: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
479: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
480: '/'.$env{'request.course.sec'})) {
1.111 www 481: return '';
482: }
1.999 www 483: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 484: if ($courseadvonly) {
485: $callargs .= ",'',1,1";
486: }
487: return '<span class="LC_nobreak">'.
488: '<a href="javascript:openstdbrowser('.$callargs.');">'.
489: &mt('Select User').'</a></span>';
1.74 www 490: }
1.258 albertel 491: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 492: $callargs .= ",'',1";
1.793 raeburn 493: return '<span class="LC_nobreak">'.
494: '<a href="javascript:openstdbrowser('.$callargs.');">'.
495: &mt('Select User').'</a></span>';
1.111 www 496: }
497: return '';
1.91 www 498: }
499:
1.1004 www 500: sub selectresource_link {
501: my ($form,$reslink,$arg)=@_;
502:
503: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
504: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
505: unless ($env{'request.course.id'}) { return $arg; }
506: return '<span class="LC_nobreak">'.
507: '<a href="javascript:openresbrowser('.$callargs.');">'.
508: $arg.'</a></span>';
509: }
510:
511:
512:
1.653 raeburn 513: sub authorbrowser_javascript {
514: return <<"ENDAUTHORBRW";
1.776 bisitz 515: <script type="text/javascript" language="JavaScript">
1.824 bisitz 516: // <![CDATA[
1.653 raeburn 517: var stdeditbrowser;
518:
519: function openauthorbrowser(formname,udom) {
520: var url = '/adm/pickauthor?';
521: url += 'form='+formname+'&roledom='+udom;
522: var title = 'Author_Browser';
523: var options = 'scrollbars=1,resizable=1,menubar=0';
524: options += ',width=700,height=600';
525: stdeditbrowser = open(url,title,options,'1');
526: stdeditbrowser.focus();
527: }
528:
1.824 bisitz 529: // ]]>
1.653 raeburn 530: </script>
531: ENDAUTHORBRW
532: }
533:
1.91 www 534: sub coursebrowser_javascript {
1.1075.2.31 raeburn 535: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1075.2.95 raeburn 536: $credits_element,$instcode) = @_;
1.932 raeburn 537: my $wintitle = 'Course_Browser';
1.931 raeburn 538: if ($crstype eq 'Community') {
1.932 raeburn 539: $wintitle = 'Community_Browser';
1.909 raeburn 540: }
1.876 raeburn 541: my $id_functions = &javascript_index_functions();
542: my $output = '
1.776 bisitz 543: <script type="text/javascript" language="JavaScript">
1.824 bisitz 544: // <![CDATA[
1.468 raeburn 545: var stdeditbrowser;'."\n";
1.876 raeburn 546:
547: $output .= <<"ENDSTDBRW";
1.909 raeburn 548: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 549: var url = '/adm/pickcourse?';
1.895 raeburn 550: var formid = getFormIdByName(formname);
1.876 raeburn 551: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 552: if (domainfilter != null) {
553: if (domainfilter != '') {
554: url += 'domainfilter='+domainfilter+'&';
555: }
556: }
1.91 www 557: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 558: '&cdomelement='+udom+
559: '&cnameelement='+desc;
1.468 raeburn 560: if (extra_element !=null && extra_element != '') {
1.594 raeburn 561: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 562: url += '&roleelement='+extra_element;
563: if (domainfilter == null || domainfilter == '') {
564: url += '&domainfilter='+extra_element;
565: }
1.234 raeburn 566: }
1.468 raeburn 567: else {
568: if (formname == 'portform') {
569: url += '&setroles='+extra_element;
1.800 raeburn 570: } else {
571: if (formname == 'rules') {
572: url += '&fixeddom='+extra_element;
573: }
1.468 raeburn 574: }
575: }
1.230 raeburn 576: }
1.909 raeburn 577: if (type != null && type != '') {
578: url += '&type='+type;
579: }
580: if (type_elem != null && type_elem != '') {
581: url += '&typeelement='+type_elem;
582: }
1.872 raeburn 583: if (formname == 'ccrs') {
584: var ownername = document.forms[formid].ccuname.value;
585: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1075.2.95 raeburn 586: url += '&cloner='+ownername+':'+ownerdom+'&crscode='+document.forms[formid].crscode.value;
587: }
588: if (formname == 'requestcrs') {
589: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 590: }
1.293 raeburn 591: if (multflag !=null && multflag != '') {
592: url += '&multiple='+multflag;
593: }
1.909 raeburn 594: var title = '$wintitle';
1.91 www 595: var options = 'scrollbars=1,resizable=1,menubar=0';
596: options += ',width=700,height=600';
597: stdeditbrowser = open(url,title,options,'1');
598: stdeditbrowser.focus();
599: }
1.876 raeburn 600: $id_functions
601: ENDSTDBRW
1.1075.2.31 raeburn 602: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
603: $output .= &setsec_javascript($sec_element,$formname,$role_element,
604: $credits_element);
1.876 raeburn 605: }
606: $output .= '
607: // ]]>
608: </script>';
609: return $output;
610: }
611:
612: sub javascript_index_functions {
613: return <<"ENDJS";
614:
615: function getFormIdByName(formname) {
616: for (var i=0;i<document.forms.length;i++) {
617: if (document.forms[i].name == formname) {
618: return i;
619: }
620: }
621: return -1;
622: }
623:
624: function getIndexByName(formid,item) {
625: for (var i=0;i<document.forms[formid].elements.length;i++) {
626: if (document.forms[formid].elements[i].name == item) {
627: return i;
628: }
629: }
630: return -1;
631: }
1.468 raeburn 632:
1.876 raeburn 633: function getDomainFromSelectbox(formname,udom) {
634: var userdom;
635: var formid = getFormIdByName(formname);
636: if (formid > -1) {
637: var domid = getIndexByName(formid,udom);
638: if (domid > -1) {
639: if (document.forms[formid].elements[domid].type == 'select-one') {
640: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
641: }
642: if (document.forms[formid].elements[domid].type == 'hidden') {
643: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 644: }
645: }
646: }
1.876 raeburn 647: return userdom;
648: }
649:
650: ENDJS
1.468 raeburn 651:
1.876 raeburn 652: }
653:
1.1017 raeburn 654: sub javascript_array_indexof {
1.1018 raeburn 655: return <<ENDJS;
1.1017 raeburn 656: <script type="text/javascript" language="JavaScript">
657: // <![CDATA[
658:
659: if (!Array.prototype.indexOf) {
660: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
661: "use strict";
662: if (this === void 0 || this === null) {
663: throw new TypeError();
664: }
665: var t = Object(this);
666: var len = t.length >>> 0;
667: if (len === 0) {
668: return -1;
669: }
670: var n = 0;
671: if (arguments.length > 0) {
672: n = Number(arguments[1]);
673: if (n !== n) { // shortcut for verifying if it's NaN
674: n = 0;
675: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
676: n = (n > 0 || -1) * Math.floor(Math.abs(n));
677: }
678: }
679: if (n >= len) {
680: return -1;
681: }
682: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
683: for (; k < len; k++) {
684: if (k in t && t[k] === searchElement) {
685: return k;
686: }
687: }
688: return -1;
689: }
690: }
691:
692: // ]]>
693: </script>
694:
695: ENDJS
696:
697: }
698:
1.876 raeburn 699: sub userbrowser_javascript {
700: my $id_functions = &javascript_index_functions();
701: return <<"ENDUSERBRW";
702:
1.888 raeburn 703: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 704: var url = '/adm/pickuser?';
705: var userdom = getDomainFromSelectbox(formname,udom);
706: if (userdom != null) {
707: if (userdom != '') {
708: url += 'srchdom='+userdom+'&';
709: }
710: }
711: url += 'form=' + formname + '&unameelement='+uname+
712: '&udomelement='+udom+
713: '&ulastelement='+ulast+
714: '&ufirstelement='+ufirst+
715: '&uemailelement='+uemail+
1.881 raeburn 716: '&hideudomelement='+hideudom+
717: '&coursedom='+crsdom;
1.888 raeburn 718: if ((caller != null) && (caller != undefined)) {
719: url += '&caller='+caller;
720: }
1.876 raeburn 721: var title = 'User_Browser';
722: var options = 'scrollbars=1,resizable=1,menubar=0';
723: options += ',width=700,height=600';
724: var stdeditbrowser = open(url,title,options,'1');
725: stdeditbrowser.focus();
726: }
727:
1.888 raeburn 728: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 729: var formid = getFormIdByName(formname);
730: if (formid > -1) {
1.888 raeburn 731: var unameid = getIndexByName(formid,uname);
1.876 raeburn 732: var domid = getIndexByName(formid,udom);
733: var hidedomid = getIndexByName(formid,origdom);
734: if (hidedomid > -1) {
735: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 736: var unameval = document.forms[formid].elements[unameid].value;
737: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
738: if (domid > -1) {
739: var slct = document.forms[formid].elements[domid];
740: if (slct.type == 'select-one') {
741: var i;
742: for (i=0;i<slct.length;i++) {
743: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
744: }
745: }
746: if (slct.type == 'hidden') {
747: slct.value = fixeddom;
1.876 raeburn 748: }
749: }
1.468 raeburn 750: }
751: }
752: }
1.876 raeburn 753: return;
754: }
755:
756: $id_functions
757: ENDUSERBRW
1.468 raeburn 758: }
759:
760: sub setsec_javascript {
1.1075.2.31 raeburn 761: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 762: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
763: $communityrolestr);
764: if ($role_element ne '') {
765: my @allroles = ('st','ta','ep','in','ad');
766: foreach my $crstype ('Course','Community') {
767: if ($crstype eq 'Community') {
768: foreach my $role (@allroles) {
769: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
770: }
771: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
772: } else {
773: foreach my $role (@allroles) {
774: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
775: }
776: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
777: }
778: }
779: $rolestr = '"'.join('","',@allroles).'"';
780: $courserolestr = '"'.join('","',@courserolenames).'"';
781: $communityrolestr = '"'.join('","',@communityrolenames).'"';
782: }
1.468 raeburn 783: my $setsections = qq|
784: function setSect(sectionlist) {
1.629 raeburn 785: var sectionsArray = new Array();
786: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
787: sectionsArray = sectionlist.split(",");
788: }
1.468 raeburn 789: var numSections = sectionsArray.length;
790: document.$formname.$sec_element.length = 0;
791: if (numSections == 0) {
792: document.$formname.$sec_element.multiple=false;
793: document.$formname.$sec_element.size=1;
794: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
795: } else {
796: if (numSections == 1) {
797: document.$formname.$sec_element.multiple=false;
798: document.$formname.$sec_element.size=1;
799: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
800: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
801: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
802: } else {
803: for (var i=0; i<numSections; i++) {
804: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
805: }
806: document.$formname.$sec_element.multiple=true
807: if (numSections < 3) {
808: document.$formname.$sec_element.size=numSections;
809: } else {
810: document.$formname.$sec_element.size=3;
811: }
812: document.$formname.$sec_element.options[0].selected = false
813: }
814: }
1.91 www 815: }
1.905 raeburn 816:
817: function setRole(crstype) {
1.468 raeburn 818: |;
1.905 raeburn 819: if ($role_element eq '') {
820: $setsections .= ' return;
821: }
822: ';
823: } else {
824: $setsections .= qq|
825: var elementLength = document.$formname.$role_element.length;
826: var allroles = Array($rolestr);
827: var courserolenames = Array($courserolestr);
828: var communityrolenames = Array($communityrolestr);
829: if (elementLength != undefined) {
830: if (document.$formname.$role_element.options[5].value == 'cc') {
831: if (crstype == 'Course') {
832: return;
833: } else {
834: allroles[5] = 'co';
835: for (var i=0; i<6; i++) {
836: document.$formname.$role_element.options[i].value = allroles[i];
837: document.$formname.$role_element.options[i].text = communityrolenames[i];
838: }
839: }
840: } else {
841: if (crstype == 'Community') {
842: return;
843: } else {
844: allroles[5] = 'cc';
845: for (var i=0; i<6; i++) {
846: document.$formname.$role_element.options[i].value = allroles[i];
847: document.$formname.$role_element.options[i].text = courserolenames[i];
848: }
849: }
850: }
851: }
852: return;
853: }
854: |;
855: }
1.1075.2.31 raeburn 856: if ($credits_element) {
857: $setsections .= qq|
858: function setCredits(defaultcredits) {
859: document.$formname.$credits_element.value = defaultcredits;
860: return;
861: }
862: |;
863: }
1.468 raeburn 864: return $setsections;
865: }
866:
1.91 www 867: sub selectcourse_link {
1.909 raeburn 868: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
869: $typeelement) = @_;
870: my $type = $selecttype;
1.871 raeburn 871: my $linktext = &mt('Select Course');
872: if ($selecttype eq 'Community') {
1.909 raeburn 873: $linktext = &mt('Select Community');
1.906 raeburn 874: } elsif ($selecttype eq 'Course/Community') {
875: $linktext = &mt('Select Course/Community');
1.909 raeburn 876: $type = '';
1.1019 raeburn 877: } elsif ($selecttype eq 'Select') {
878: $linktext = &mt('Select');
879: $type = '';
1.871 raeburn 880: }
1.787 bisitz 881: return '<span class="LC_nobreak">'
882: ."<a href='"
883: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
884: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 885: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 886: ."'>".$linktext.'</a>'
1.787 bisitz 887: .'</span>';
1.74 www 888: }
1.42 matthew 889:
1.653 raeburn 890: sub selectauthor_link {
891: my ($form,$udom)=@_;
892: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
893: &mt('Select Author').'</a>';
894: }
895:
1.876 raeburn 896: sub selectuser_link {
1.881 raeburn 897: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 898: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 899: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 900: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 901: ');">'.$linktext.'</a>';
1.876 raeburn 902: }
903:
1.273 raeburn 904: sub check_uncheck_jscript {
905: my $jscript = <<"ENDSCRT";
906: function checkAll(field) {
907: if (field.length > 0) {
908: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 909: if (!field[i].disabled) {
910: field[i].checked = true;
911: }
1.273 raeburn 912: }
913: } else {
1.1075.2.14 raeburn 914: if (!field.disabled) {
915: field.checked = true;
916: }
1.273 raeburn 917: }
918: }
919:
920: function uncheckAll(field) {
921: if (field.length > 0) {
922: for (i = 0; i < field.length; i++) {
923: field[i].checked = false ;
1.543 albertel 924: }
925: } else {
1.273 raeburn 926: field.checked = false ;
927: }
928: }
929: ENDSCRT
930: return $jscript;
931: }
932:
1.656 www 933: sub select_timezone {
1.659 raeburn 934: my ($name,$selected,$onchange,$includeempty)=@_;
935: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
936: if ($includeempty) {
937: $output .= '<option value=""';
938: if (($selected eq '') || ($selected eq 'local')) {
939: $output .= ' selected="selected" ';
940: }
941: $output .= '> </option>';
942: }
1.657 raeburn 943: my @timezones = DateTime::TimeZone->all_names;
944: foreach my $tzone (@timezones) {
945: $output.= '<option value="'.$tzone.'"';
946: if ($tzone eq $selected) {
947: $output.=' selected="selected"';
948: }
949: $output.=">$tzone</option>\n";
1.656 www 950: }
951: $output.="</select>";
952: return $output;
953: }
1.273 raeburn 954:
1.687 raeburn 955: sub select_datelocale {
956: my ($name,$selected,$onchange,$includeempty)=@_;
957: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
958: if ($includeempty) {
959: $output .= '<option value=""';
960: if ($selected eq '') {
961: $output .= ' selected="selected" ';
962: }
963: $output .= '> </option>';
964: }
965: my (@possibles,%locale_names);
966: my @locales = DateTime::Locale::Catalog::Locales;
967: foreach my $locale (@locales) {
968: if (ref($locale) eq 'HASH') {
969: my $id = $locale->{'id'};
970: if ($id ne '') {
971: my $en_terr = $locale->{'en_territory'};
972: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 973: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 974: if (grep(/^en$/,@languages) || !@languages) {
975: if ($en_terr ne '') {
976: $locale_names{$id} = '('.$en_terr.')';
977: } elsif ($native_terr ne '') {
978: $locale_names{$id} = $native_terr;
979: }
980: } else {
981: if ($native_terr ne '') {
982: $locale_names{$id} = $native_terr.' ';
983: } elsif ($en_terr ne '') {
984: $locale_names{$id} = '('.$en_terr.')';
985: }
986: }
1.1075.2.94 raeburn 987: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.687 raeburn 988: push (@possibles,$id);
989: }
990: }
991: }
992: foreach my $item (sort(@possibles)) {
993: $output.= '<option value="'.$item.'"';
994: if ($item eq $selected) {
995: $output.=' selected="selected"';
996: }
997: $output.=">$item";
998: if ($locale_names{$item} ne '') {
1.1075.2.94 raeburn 999: $output.=' '.$locale_names{$item};
1.687 raeburn 1000: }
1001: $output.="</option>\n";
1002: }
1003: $output.="</select>";
1004: return $output;
1005: }
1006:
1.792 raeburn 1007: sub select_language {
1008: my ($name,$selected,$includeempty) = @_;
1009: my %langchoices;
1010: if ($includeempty) {
1.1075.2.32 raeburn 1011: %langchoices = ('' => 'No language preference');
1.792 raeburn 1012: }
1013: foreach my $id (&languageids()) {
1014: my $code = &supportedlanguagecode($id);
1015: if ($code) {
1016: $langchoices{$code} = &plainlanguagedescription($id);
1017: }
1018: }
1.1075.2.32 raeburn 1019: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970 raeburn 1020: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1021: }
1022:
1.42 matthew 1023: =pod
1.36 matthew 1024:
1.648 raeburn 1025: =item * &linked_select_forms(...)
1.36 matthew 1026:
1027: linked_select_forms returns a string containing a <script></script> block
1028: and html for two <select> menus. The select menus will be linked in that
1029: changing the value of the first menu will result in new values being placed
1030: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1031: order unless a defined order is provided.
1.36 matthew 1032:
1033: linked_select_forms takes the following ordered inputs:
1034:
1035: =over 4
1036:
1.112 bowersj2 1037: =item * $formname, the name of the <form> tag
1.36 matthew 1038:
1.112 bowersj2 1039: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1040:
1.112 bowersj2 1041: =item * $firstdefault, the default value for the first menu
1.36 matthew 1042:
1.112 bowersj2 1043: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1044:
1.112 bowersj2 1045: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1046:
1.112 bowersj2 1047: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1048:
1.609 raeburn 1049: =item * $menuorder, the order of values in the first menu
1050:
1.1075.2.31 raeburn 1051: =item * $onchangefirst, additional javascript call to execute for an onchange
1052: event for the first <select> tag
1053:
1054: =item * $onchangesecond, additional javascript call to execute for an onchange
1055: event for the second <select> tag
1056:
1.41 ng 1057: =back
1058:
1.36 matthew 1059: Below is an example of such a hash. Only the 'text', 'default', and
1060: 'select2' keys must appear as stated. keys(%menu) are the possible
1061: values for the first select menu. The text that coincides with the
1.41 ng 1062: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1063: and text for the second menu are given in the hash pointed to by
1064: $menu{$choice1}->{'select2'}.
1065:
1.112 bowersj2 1066: my %menu = ( A1 => { text =>"Choice A1" ,
1067: default => "B3",
1068: select2 => {
1069: B1 => "Choice B1",
1070: B2 => "Choice B2",
1071: B3 => "Choice B3",
1072: B4 => "Choice B4"
1.609 raeburn 1073: },
1074: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1075: },
1076: A2 => { text =>"Choice A2" ,
1077: default => "C2",
1078: select2 => {
1079: C1 => "Choice C1",
1080: C2 => "Choice C2",
1081: C3 => "Choice C3"
1.609 raeburn 1082: },
1083: order => ['C2','C1','C3'],
1.112 bowersj2 1084: },
1085: A3 => { text =>"Choice A3" ,
1086: default => "D6",
1087: select2 => {
1088: D1 => "Choice D1",
1089: D2 => "Choice D2",
1090: D3 => "Choice D3",
1091: D4 => "Choice D4",
1092: D5 => "Choice D5",
1093: D6 => "Choice D6",
1094: D7 => "Choice D7"
1.609 raeburn 1095: },
1096: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1097: }
1098: );
1.36 matthew 1099:
1100: =cut
1101:
1102: sub linked_select_forms {
1103: my ($formname,
1104: $middletext,
1105: $firstdefault,
1106: $firstselectname,
1107: $secondselectname,
1.609 raeburn 1108: $hashref,
1109: $menuorder,
1.1075.2.31 raeburn 1110: $onchangefirst,
1111: $onchangesecond
1.36 matthew 1112: ) = @_;
1113: my $second = "document.$formname.$secondselectname";
1114: my $first = "document.$formname.$firstselectname";
1115: # output the javascript to do the changing
1116: my $result = '';
1.776 bisitz 1117: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1118: $result.="// <![CDATA[\n";
1.36 matthew 1119: $result.="var select2data = new Object();\n";
1120: $" = '","';
1121: my $debug = '';
1122: foreach my $s1 (sort(keys(%$hashref))) {
1123: $result.="select2data.d_$s1 = new Object();\n";
1124: $result.="select2data.d_$s1.def = new String('".
1125: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1126: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1127: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1128: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1129: @s2values = @{$hashref->{$s1}->{'order'}};
1130: }
1.36 matthew 1131: $result.="\"@s2values\");\n";
1132: $result.="select2data.d_$s1.texts = new Array(";
1133: my @s2texts;
1134: foreach my $value (@s2values) {
1135: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1136: }
1137: $result.="\"@s2texts\");\n";
1138: }
1139: $"=' ';
1140: $result.= <<"END";
1141:
1142: function select1_changed() {
1143: // Determine new choice
1144: var newvalue = "d_" + $first.value;
1145: // update select2
1146: var values = select2data[newvalue].values;
1147: var texts = select2data[newvalue].texts;
1148: var select2def = select2data[newvalue].def;
1149: var i;
1150: // out with the old
1151: for (i = 0; i < $second.options.length; i++) {
1152: $second.options[i] = null;
1153: }
1154: // in with the nuclear
1155: for (i=0;i<values.length; i++) {
1156: $second.options[i] = new Option(values[i]);
1.143 matthew 1157: $second.options[i].value = values[i];
1.36 matthew 1158: $second.options[i].text = texts[i];
1159: if (values[i] == select2def) {
1160: $second.options[i].selected = true;
1161: }
1162: }
1163: }
1.824 bisitz 1164: // ]]>
1.36 matthew 1165: </script>
1166: END
1167: # output the initial values for the selection lists
1.1075.2.31 raeburn 1168: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1169: my @order = sort(keys(%{$hashref}));
1170: if (ref($menuorder) eq 'ARRAY') {
1171: @order = @{$menuorder};
1172: }
1173: foreach my $value (@order) {
1.36 matthew 1174: $result.=" <option value=\"$value\" ";
1.253 albertel 1175: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1176: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1177: }
1178: $result .= "</select>\n";
1179: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1180: $result .= $middletext;
1.1075.2.31 raeburn 1181: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1182: if ($onchangesecond) {
1183: $result .= ' onchange="'.$onchangesecond.'"';
1184: }
1185: $result .= ">\n";
1.36 matthew 1186: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1187:
1188: my @secondorder = sort(keys(%select2));
1189: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1190: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1191: }
1192: foreach my $value (@secondorder) {
1.36 matthew 1193: $result.=" <option value=\"$value\" ";
1.253 albertel 1194: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1195: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1196: }
1197: $result .= "</select>\n";
1198: # return $debug;
1199: return $result;
1200: } # end of sub linked_select_forms {
1201:
1.45 matthew 1202: =pod
1.44 bowersj2 1203:
1.973 raeburn 1204: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1205:
1.112 bowersj2 1206: Returns a string corresponding to an HTML link to the given help
1207: $topic, where $topic corresponds to the name of a .tex file in
1208: /home/httpd/html/adm/help/tex, with underscores replaced by
1209: spaces.
1210:
1211: $text will optionally be linked to the same topic, allowing you to
1212: link text in addition to the graphic. If you do not want to link
1213: text, but wish to specify one of the later parameters, pass an
1214: empty string.
1215:
1216: $stayOnPage is a value that will be interpreted as a boolean. If true,
1217: the link will not open a new window. If false, the link will open
1218: a new window using Javascript. (Default is false.)
1219:
1220: $width and $height are optional numerical parameters that will
1221: override the width and height of the popped up window, which may
1.973 raeburn 1222: be useful for certain help topics with big pictures included.
1223:
1224: $imgid is the id of the img tag used for the help icon. This may be
1225: used in a javascript call to switch the image src. See
1226: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1227:
1228: =cut
1229:
1230: sub help_open_topic {
1.973 raeburn 1231: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1232: $text = "" if (not defined $text);
1.44 bowersj2 1233: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1234: $width = 500 if (not defined $width);
1.44 bowersj2 1235: $height = 400 if (not defined $height);
1236: my $filename = $topic;
1237: $filename =~ s/ /_/g;
1238:
1.48 bowersj2 1239: my $template = "";
1240: my $link;
1.572 banghart 1241:
1.159 www 1242: $topic=~s/\W/\_/g;
1.44 bowersj2 1243:
1.572 banghart 1244: if (!$stayOnPage) {
1.1075.2.50 raeburn 1245: if ($env{'browser.mobile'}) {
1246: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1247: } else {
1248: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1249: }
1.1037 www 1250: } elsif ($stayOnPage eq 'popup') {
1251: $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 1252: } else {
1.48 bowersj2 1253: $link = "/adm/help/${filename}.hlp";
1254: }
1255:
1256: # Add the text
1.755 neumanie 1257: if ($text ne "") {
1.763 bisitz 1258: $template.='<span class="LC_help_open_topic">'
1259: .'<a target="_top" href="'.$link.'">'
1260: .$text.'</a>';
1.48 bowersj2 1261: }
1262:
1.763 bisitz 1263: # (Always) Add the graphic
1.179 matthew 1264: my $title = &mt('Online Help');
1.667 raeburn 1265: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1266: if ($imgid ne '') {
1267: $imgid = ' id="'.$imgid.'"';
1268: }
1.763 bisitz 1269: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1270: .'<img src="'.$helpicon.'" border="0"'
1271: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1272: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1273: .' /></a>';
1274: if ($text ne "") {
1275: $template.='</span>';
1276: }
1.44 bowersj2 1277: return $template;
1278:
1.106 bowersj2 1279: }
1280:
1281: # This is a quicky function for Latex cheatsheet editing, since it
1282: # appears in at least four places
1283: sub helpLatexCheatsheet {
1.1037 www 1284: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1285: my $out;
1.106 bowersj2 1286: my $addOther = '';
1.732 raeburn 1287: if ($topic) {
1.1037 www 1288: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1289: }
1290: $out = '<span>' # Start cheatsheet
1291: .$addOther
1292: .'<span>'
1.1037 www 1293: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1294: .'</span> <span>'
1.1037 www 1295: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1296: .'</span>';
1.732 raeburn 1297: unless ($not_author) {
1.763 bisitz 1298: $out .= ' <span>'
1.1037 www 1299: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1300: .'</span> <span>'
1.1075.2.78 raeburn 1301: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1302: .'</span>';
1.732 raeburn 1303: }
1.763 bisitz 1304: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1305: return $out;
1.172 www 1306: }
1307:
1.430 albertel 1308: sub general_help {
1309: my $helptopic='Student_Intro';
1310: if ($env{'request.role'}=~/^(ca|au)/) {
1311: $helptopic='Authoring_Intro';
1.907 raeburn 1312: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1313: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1314: } elsif ($env{'request.role'}=~/^dc/) {
1315: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1316: }
1317: return $helptopic;
1318: }
1319:
1320: sub update_help_link {
1321: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1322: my $origurl = $ENV{'REQUEST_URI'};
1323: $origurl=~s|^/~|/priv/|;
1324: my $timestamp = time;
1325: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1326: $$datum = &escape($$datum);
1327: }
1328:
1329: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1330: my $output .= <<"ENDOUTPUT";
1331: <script type="text/javascript">
1.824 bisitz 1332: // <![CDATA[
1.430 albertel 1333: banner_link = '$banner_link';
1.824 bisitz 1334: // ]]>
1.430 albertel 1335: </script>
1336: ENDOUTPUT
1337: return $output;
1338: }
1339:
1340: # now just updates the help link and generates a blue icon
1.193 raeburn 1341: sub help_open_menu {
1.430 albertel 1342: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1343: = @_;
1.949 droeschl 1344: $stayOnPage = 1;
1.430 albertel 1345: my $output;
1346: if ($component_help) {
1347: if (!$text) {
1348: $output=&help_open_topic($component_help,undef,$stayOnPage,
1349: $width,$height);
1350: } else {
1351: my $help_text;
1352: $help_text=&unescape($topic);
1353: $output='<table><tr><td>'.
1354: &help_open_topic($component_help,$help_text,$stayOnPage,
1355: $width,$height).'</td></tr></table>';
1356: }
1357: }
1358: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1359: return $output.$banner_link;
1360: }
1361:
1362: sub top_nav_help {
1363: my ($text) = @_;
1.436 albertel 1364: $text = &mt($text);
1.1075.2.60 raeburn 1365: my $stay_on_page;
1366: unless ($env{'environment.remote'} eq 'on') {
1367: $stay_on_page = 1;
1368: }
1.1075.2.61 raeburn 1369: my ($link,$banner_link);
1370: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1371: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1372: : "javascript:helpMenu('open')";
1373: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1374: }
1.201 raeburn 1375: my $title = &mt('Get help');
1.1075.2.61 raeburn 1376: if ($link) {
1377: return <<"END";
1.436 albertel 1378: $banner_link
1.1075.2.56 raeburn 1379: <a href="$link" title="$title">$text</a>
1.436 albertel 1380: END
1.1075.2.61 raeburn 1381: } else {
1382: return ' '.$text.' ';
1383: }
1.436 albertel 1384: }
1385:
1386: sub help_menu_js {
1.1075.2.52 raeburn 1387: my ($httphost) = @_;
1.949 droeschl 1388: my $stayOnPage = 1;
1.436 albertel 1389: my $width = 620;
1390: my $height = 600;
1.430 albertel 1391: my $helptopic=&general_help();
1.1075.2.52 raeburn 1392: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1393: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1394: my $start_page =
1395: &Apache::loncommon::start_page('Help Menu', undef,
1396: {'frameset' => 1,
1397: 'js_ready' => 1,
1.1075.2.52 raeburn 1398: 'use_absolute' => $httphost,
1.331 albertel 1399: 'add_entries' => {
1400: 'border' => '0',
1.579 raeburn 1401: 'rows' => "110,*",},});
1.331 albertel 1402: my $end_page =
1403: &Apache::loncommon::end_page({'frameset' => 1,
1404: 'js_ready' => 1,});
1405:
1.436 albertel 1406: my $template .= <<"ENDTEMPLATE";
1407: <script type="text/javascript">
1.877 bisitz 1408: // <![CDATA[
1.253 albertel 1409: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1410: var banner_link = '';
1.243 raeburn 1411: function helpMenu(target) {
1412: var caller = this;
1413: if (target == 'open') {
1414: var newWindow = null;
1415: try {
1.262 albertel 1416: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1417: }
1418: catch(error) {
1419: writeHelp(caller);
1420: return;
1421: }
1422: if (newWindow) {
1423: caller = newWindow;
1424: }
1.193 raeburn 1425: }
1.243 raeburn 1426: writeHelp(caller);
1427: return;
1428: }
1429: function writeHelp(caller) {
1.1075.2.61 raeburn 1430: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1431: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1432: caller.document.close();
1433: caller.focus();
1.193 raeburn 1434: }
1.877 bisitz 1435: // END LON-CAPA Internal -->
1.253 albertel 1436: // ]]>
1.436 albertel 1437: </script>
1.193 raeburn 1438: ENDTEMPLATE
1439: return $template;
1440: }
1441:
1.172 www 1442: sub help_open_bug {
1443: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1444: unless ($env{'user.adv'}) { return ''; }
1.172 www 1445: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1446: $text = "" if (not defined $text);
1447: $stayOnPage=1;
1.184 albertel 1448: $width = 600 if (not defined $width);
1449: $height = 600 if (not defined $height);
1.172 www 1450:
1451: $topic=~s/\W+/\+/g;
1452: my $link='';
1453: my $template='';
1.379 albertel 1454: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1455: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1456: if (!$stayOnPage)
1457: {
1458: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1459: }
1460: else
1461: {
1462: $link = $url;
1463: }
1464: # Add the text
1465: if ($text ne "")
1466: {
1467: $template .=
1468: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1469: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1470: }
1471:
1472: # Add the graphic
1.179 matthew 1473: my $title = &mt('Report a Bug');
1.215 albertel 1474: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1475: $template .= <<"ENDTEMPLATE";
1.436 albertel 1476: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1477: ENDTEMPLATE
1478: if ($text ne '') { $template.='</td></tr></table>' };
1479: return $template;
1480:
1481: }
1482:
1483: sub help_open_faq {
1484: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1485: unless ($env{'user.adv'}) { return ''; }
1.172 www 1486: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1487: $text = "" if (not defined $text);
1488: $stayOnPage=1;
1489: $width = 350 if (not defined $width);
1490: $height = 400 if (not defined $height);
1491:
1492: $topic=~s/\W+/\+/g;
1493: my $link='';
1494: my $template='';
1495: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1496: if (!$stayOnPage)
1497: {
1498: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1499: }
1500: else
1501: {
1502: $link = $url;
1503: }
1504:
1505: # Add the text
1506: if ($text ne "")
1507: {
1508: $template .=
1.173 www 1509: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1510: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1511: }
1512:
1513: # Add the graphic
1.179 matthew 1514: my $title = &mt('View the FAQ');
1.215 albertel 1515: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1516: $template .= <<"ENDTEMPLATE";
1.436 albertel 1517: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1518: ENDTEMPLATE
1519: if ($text ne '') { $template.='</td></tr></table>' };
1520: return $template;
1521:
1.44 bowersj2 1522: }
1.37 matthew 1523:
1.180 matthew 1524: ###############################################################
1525: ###############################################################
1526:
1.45 matthew 1527: =pod
1528:
1.648 raeburn 1529: =item * &change_content_javascript():
1.256 matthew 1530:
1531: This and the next function allow you to create small sections of an
1532: otherwise static HTML page that you can update on the fly with
1533: Javascript, even in Netscape 4.
1534:
1535: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1536: must be written to the HTML page once. It will prove the Javascript
1537: function "change(name, content)". Calling the change function with the
1538: name of the section
1539: you want to update, matching the name passed to C<changable_area>, and
1540: the new content you want to put in there, will put the content into
1541: that area.
1542:
1543: B<Note>: Netscape 4 only reserves enough space for the changable area
1544: to contain room for the original contents. You need to "make space"
1545: for whatever changes you wish to make, and be B<sure> to check your
1546: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1547: it's adequate for updating a one-line status display, but little more.
1548: This script will set the space to 100% width, so you only need to
1549: worry about height in Netscape 4.
1550:
1551: Modern browsers are much less limiting, and if you can commit to the
1552: user not using Netscape 4, this feature may be used freely with
1553: pretty much any HTML.
1554:
1555: =cut
1556:
1557: sub change_content_javascript {
1558: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1559: if ($env{'browser.type'} eq 'netscape' &&
1560: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1561: return (<<NETSCAPE4);
1562: function change(name, content) {
1563: doc = document.layers[name+"___escape"].layers[0].document;
1564: doc.open();
1565: doc.write(content);
1566: doc.close();
1567: }
1568: NETSCAPE4
1569: } else {
1570: # Otherwise, we need to use semi-standards-compliant code
1571: # (technically, "innerHTML" isn't standard but the equivalent
1572: # is really scary, and every useful browser supports it
1573: return (<<DOMBASED);
1574: function change(name, content) {
1575: element = document.getElementById(name);
1576: element.innerHTML = content;
1577: }
1578: DOMBASED
1579: }
1580: }
1581:
1582: =pod
1583:
1.648 raeburn 1584: =item * &changable_area($name,$origContent):
1.256 matthew 1585:
1586: This provides a "changable area" that can be modified on the fly via
1587: the Javascript code provided in C<change_content_javascript>. $name is
1588: the name you will use to reference the area later; do not repeat the
1589: same name on a given HTML page more then once. $origContent is what
1590: the area will originally contain, which can be left blank.
1591:
1592: =cut
1593:
1594: sub changable_area {
1595: my ($name, $origContent) = @_;
1596:
1.258 albertel 1597: if ($env{'browser.type'} eq 'netscape' &&
1598: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1599: # If this is netscape 4, we need to use the Layer tag
1600: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1601: } else {
1602: return "<span id='$name'>$origContent</span>";
1603: }
1604: }
1605:
1606: =pod
1607:
1.648 raeburn 1608: =item * &viewport_geometry_js
1.590 raeburn 1609:
1610: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1611:
1612: =cut
1613:
1614:
1615: sub viewport_geometry_js {
1616: return <<"GEOMETRY";
1617: var Geometry = {};
1618: function init_geometry() {
1619: if (Geometry.init) { return };
1620: Geometry.init=1;
1621: if (window.innerHeight) {
1622: Geometry.getViewportHeight = function() { return window.innerHeight; };
1623: Geometry.getViewportWidth = function() { return window.innerWidth; };
1624: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1625: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1626: }
1627: else if (document.documentElement && document.documentElement.clientHeight) {
1628: Geometry.getViewportHeight =
1629: function() { return document.documentElement.clientHeight; };
1630: Geometry.getViewportWidth =
1631: function() { return document.documentElement.clientWidth; };
1632:
1633: Geometry.getHorizontalScroll =
1634: function() { return document.documentElement.scrollLeft; };
1635: Geometry.getVerticalScroll =
1636: function() { return document.documentElement.scrollTop; };
1637: }
1638: else if (document.body.clientHeight) {
1639: Geometry.getViewportHeight =
1640: function() { return document.body.clientHeight; };
1641: Geometry.getViewportWidth =
1642: function() { return document.body.clientWidth; };
1643: Geometry.getHorizontalScroll =
1644: function() { return document.body.scrollLeft; };
1645: Geometry.getVerticalScroll =
1646: function() { return document.body.scrollTop; };
1647: }
1648: }
1649:
1650: GEOMETRY
1651: }
1652:
1653: =pod
1654:
1.648 raeburn 1655: =item * &viewport_size_js()
1.590 raeburn 1656:
1657: 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.
1658:
1659: =cut
1660:
1661: sub viewport_size_js {
1662: my $geometry = &viewport_geometry_js();
1663: return <<"DIMS";
1664:
1665: $geometry
1666:
1667: function getViewportDims(width,height) {
1668: init_geometry();
1669: width.value = Geometry.getViewportWidth();
1670: height.value = Geometry.getViewportHeight();
1671: return;
1672: }
1673:
1674: DIMS
1675: }
1676:
1677: =pod
1678:
1.648 raeburn 1679: =item * &resize_textarea_js()
1.565 albertel 1680:
1681: emits the needed javascript to resize a textarea to be as big as possible
1682:
1683: creates a function resize_textrea that takes two IDs first should be
1684: the id of the element to resize, second should be the id of a div that
1685: surrounds everything that comes after the textarea, this routine needs
1686: to be attached to the <body> for the onload and onresize events.
1687:
1.648 raeburn 1688: =back
1.565 albertel 1689:
1690: =cut
1691:
1692: sub resize_textarea_js {
1.590 raeburn 1693: my $geometry = &viewport_geometry_js();
1.565 albertel 1694: return <<"RESIZE";
1695: <script type="text/javascript">
1.824 bisitz 1696: // <![CDATA[
1.590 raeburn 1697: $geometry
1.565 albertel 1698:
1.588 albertel 1699: function getX(element) {
1700: var x = 0;
1701: while (element) {
1702: x += element.offsetLeft;
1703: element = element.offsetParent;
1704: }
1705: return x;
1706: }
1707: function getY(element) {
1708: var y = 0;
1709: while (element) {
1710: y += element.offsetTop;
1711: element = element.offsetParent;
1712: }
1713: return y;
1714: }
1715:
1716:
1.565 albertel 1717: function resize_textarea(textarea_id,bottom_id) {
1718: init_geometry();
1719: var textarea = document.getElementById(textarea_id);
1720: //alert(textarea);
1721:
1.588 albertel 1722: var textarea_top = getY(textarea);
1.565 albertel 1723: var textarea_height = textarea.offsetHeight;
1724: var bottom = document.getElementById(bottom_id);
1.588 albertel 1725: var bottom_top = getY(bottom);
1.565 albertel 1726: var bottom_height = bottom.offsetHeight;
1727: var window_height = Geometry.getViewportHeight();
1.588 albertel 1728: var fudge = 23;
1.565 albertel 1729: var new_height = window_height-fudge-textarea_top-bottom_height;
1730: if (new_height < 300) {
1731: new_height = 300;
1732: }
1733: textarea.style.height=new_height+'px';
1734: }
1.824 bisitz 1735: // ]]>
1.565 albertel 1736: </script>
1737: RESIZE
1738:
1739: }
1740:
1741: =pod
1742:
1.256 matthew 1743: =head1 Excel and CSV file utility routines
1744:
1745: =cut
1746:
1747: ###############################################################
1748: ###############################################################
1749:
1750: =pod
1751:
1.1075.2.56 raeburn 1752: =over 4
1753:
1.648 raeburn 1754: =item * &csv_translate($text)
1.37 matthew 1755:
1.185 www 1756: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1757: format.
1758:
1759: =cut
1760:
1.180 matthew 1761: ###############################################################
1762: ###############################################################
1.37 matthew 1763: sub csv_translate {
1764: my $text = shift;
1765: $text =~ s/\"/\"\"/g;
1.209 albertel 1766: $text =~ s/\n/ /g;
1.37 matthew 1767: return $text;
1768: }
1.180 matthew 1769:
1770: ###############################################################
1771: ###############################################################
1772:
1773: =pod
1774:
1.648 raeburn 1775: =item * &define_excel_formats()
1.180 matthew 1776:
1777: Define some commonly used Excel cell formats.
1778:
1779: Currently supported formats:
1780:
1781: =over 4
1782:
1783: =item header
1784:
1785: =item bold
1786:
1787: =item h1
1788:
1789: =item h2
1790:
1791: =item h3
1792:
1.256 matthew 1793: =item h4
1794:
1795: =item i
1796:
1.180 matthew 1797: =item date
1798:
1799: =back
1800:
1801: Inputs: $workbook
1802:
1803: Returns: $format, a hash reference.
1804:
1.1057 foxr 1805:
1.180 matthew 1806: =cut
1807:
1808: ###############################################################
1809: ###############################################################
1810: sub define_excel_formats {
1811: my ($workbook) = @_;
1812: my $format;
1813: $format->{'header'} = $workbook->add_format(bold => 1,
1814: bottom => 1,
1815: align => 'center');
1816: $format->{'bold'} = $workbook->add_format(bold=>1);
1817: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1818: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1819: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1820: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1821: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1822: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1823: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1824: return $format;
1825: }
1826:
1827: ###############################################################
1828: ###############################################################
1.113 bowersj2 1829:
1830: =pod
1831:
1.648 raeburn 1832: =item * &create_workbook()
1.255 matthew 1833:
1834: Create an Excel worksheet. If it fails, output message on the
1835: request object and return undefs.
1836:
1837: Inputs: Apache request object
1838:
1839: Returns (undef) on failure,
1840: Excel worksheet object, scalar with filename, and formats
1841: from &Apache::loncommon::define_excel_formats on success
1842:
1843: =cut
1844:
1845: ###############################################################
1846: ###############################################################
1847: sub create_workbook {
1848: my ($r) = @_;
1849: #
1850: # Create the excel spreadsheet
1851: my $filename = '/prtspool/'.
1.258 albertel 1852: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1853: time.'_'.rand(1000000000).'.xls';
1854: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1855: if (! defined($workbook)) {
1856: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1857: $r->print(
1858: '<p class="LC_error">'
1859: .&mt('Problems occurred in creating the new Excel file.')
1860: .' '.&mt('This error has been logged.')
1861: .' '.&mt('Please alert your LON-CAPA administrator.')
1862: .'</p>'
1863: );
1.255 matthew 1864: return (undef);
1865: }
1866: #
1.1014 foxr 1867: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1868: #
1869: my $format = &Apache::loncommon::define_excel_formats($workbook);
1870: return ($workbook,$filename,$format);
1871: }
1872:
1873: ###############################################################
1874: ###############################################################
1875:
1876: =pod
1877:
1.648 raeburn 1878: =item * &create_text_file()
1.113 bowersj2 1879:
1.542 raeburn 1880: Create a file to write to and eventually make available to the user.
1.256 matthew 1881: If file creation fails, outputs an error message on the request object and
1882: return undefs.
1.113 bowersj2 1883:
1.256 matthew 1884: Inputs: Apache request object, and file suffix
1.113 bowersj2 1885:
1.256 matthew 1886: Returns (undef) on failure,
1887: Filehandle and filename on success.
1.113 bowersj2 1888:
1889: =cut
1890:
1.256 matthew 1891: ###############################################################
1892: ###############################################################
1893: sub create_text_file {
1894: my ($r,$suffix) = @_;
1895: if (! defined($suffix)) { $suffix = 'txt'; };
1896: my $fh;
1897: my $filename = '/prtspool/'.
1.258 albertel 1898: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1899: time.'_'.rand(1000000000).'.'.$suffix;
1900: $fh = Apache::File->new('>/home/httpd'.$filename);
1901: if (! defined($fh)) {
1902: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1903: $r->print(
1904: '<p class="LC_error">'
1905: .&mt('Problems occurred in creating the output file.')
1906: .' '.&mt('This error has been logged.')
1907: .' '.&mt('Please alert your LON-CAPA administrator.')
1908: .'</p>'
1909: );
1.113 bowersj2 1910: }
1.256 matthew 1911: return ($fh,$filename)
1.113 bowersj2 1912: }
1913:
1914:
1.256 matthew 1915: =pod
1.113 bowersj2 1916:
1917: =back
1918:
1919: =cut
1.37 matthew 1920:
1921: ###############################################################
1.33 matthew 1922: ## Home server <option> list generating code ##
1923: ###############################################################
1.35 matthew 1924:
1.169 www 1925: # ------------------------------------------
1926:
1927: sub domain_select {
1928: my ($name,$value,$multiple)=@_;
1929: my %domains=map {
1.514 albertel 1930: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1931: } &Apache::lonnet::all_domains();
1.169 www 1932: if ($multiple) {
1933: $domains{''}=&mt('Any domain');
1.550 albertel 1934: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1935: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1936: } else {
1.550 albertel 1937: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1938: return &select_form($name,$value,\%domains);
1.169 www 1939: }
1940: }
1941:
1.282 albertel 1942: #-------------------------------------------
1943:
1944: =pod
1945:
1.519 raeburn 1946: =head1 Routines for form select boxes
1947:
1948: =over 4
1949:
1.648 raeburn 1950: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1951:
1952: Returns a string containing a <select> element int multiple mode
1953:
1954:
1955: Args:
1956: $name - name of the <select> element
1.506 raeburn 1957: $value - scalar or array ref of values that should already be selected
1.282 albertel 1958: $size - number of rows long the select element is
1.283 albertel 1959: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1960: (shown text should already have been &mt())
1.506 raeburn 1961: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1962:
1.282 albertel 1963: =cut
1964:
1965: #-------------------------------------------
1.169 www 1966: sub multiple_select_form {
1.284 albertel 1967: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1968: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1969: my $output='';
1.191 matthew 1970: if (! defined($size)) {
1971: $size = 4;
1.283 albertel 1972: if (scalar(keys(%$hash))<4) {
1973: $size = scalar(keys(%$hash));
1.191 matthew 1974: }
1975: }
1.734 bisitz 1976: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1977: my @order;
1.506 raeburn 1978: if (ref($order) eq 'ARRAY') {
1979: @order = @{$order};
1980: } else {
1981: @order = sort(keys(%$hash));
1.501 banghart 1982: }
1983: if (exists($$hash{'select_form_order'})) {
1984: @order = @{$$hash{'select_form_order'}};
1985: }
1986:
1.284 albertel 1987: foreach my $key (@order) {
1.356 albertel 1988: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1989: $output.='selected="selected" ' if ($selected{$key});
1990: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1991: }
1992: $output.="</select>\n";
1993: return $output;
1994: }
1995:
1.88 www 1996: #-------------------------------------------
1997:
1998: =pod
1999:
1.970 raeburn 2000: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 2001:
2002: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2003: allow a user to select options from a ref to a hash containing:
2004: option_name => displayed text. An optional $onchange can include
2005: a javascript onchange item, e.g., onchange="this.form.submit();"
2006:
1.88 www 2007: See lonrights.pm for an example invocation and use.
2008:
2009: =cut
2010:
2011: #-------------------------------------------
2012: sub select_form {
1.970 raeburn 2013: my ($def,$name,$hashref,$onchange) = @_;
2014: return unless (ref($hashref) eq 'HASH');
2015: if ($onchange) {
2016: $onchange = ' onchange="'.$onchange.'"';
2017: }
2018: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2019: my @keys;
1.970 raeburn 2020: if (exists($hashref->{'select_form_order'})) {
2021: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2022: } else {
1.970 raeburn 2023: @keys=sort(keys(%{$hashref}));
1.128 albertel 2024: }
1.356 albertel 2025: foreach my $key (@keys) {
2026: $selectform.=
2027: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2028: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2029: ">".$hashref->{$key}."</option>\n";
1.88 www 2030: }
2031: $selectform.="</select>";
2032: return $selectform;
2033: }
2034:
1.475 www 2035: # For display filters
2036:
2037: sub display_filter {
1.1074 raeburn 2038: my ($context) = @_;
1.475 www 2039: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2040: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2041: my $phraseinput = 'hidden';
2042: my $includeinput = 'hidden';
2043: my ($checked,$includetypestext);
2044: if ($env{'form.displayfilter'} eq 'containing') {
2045: $phraseinput = 'text';
2046: if ($context eq 'parmslog') {
2047: $includeinput = 'checkbox';
2048: if ($env{'form.includetypes'}) {
2049: $checked = ' checked="checked"';
2050: }
2051: $includetypestext = &mt('Include parameter types');
2052: }
2053: } else {
2054: $includetypestext = ' ';
2055: }
2056: my ($additional,$secondid,$thirdid);
2057: if ($context eq 'parmslog') {
2058: $additional =
2059: '<label><input type="'.$includeinput.'" name="includetypes"'.
2060: $checked.' name="includetypes" value="1" id="includetypes" />'.
2061: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2062: '</label>';
2063: $secondid = 'includetypes';
2064: $thirdid = 'includetypestext';
2065: }
2066: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2067: '$secondid','$thirdid')";
2068: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2069: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2070: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2071: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2072: &mt('Filter: [_1]',
1.477 www 2073: &select_form($env{'form.displayfilter'},
2074: 'displayfilter',
1.970 raeburn 2075: {'currentfolder' => 'Current folder/page',
1.477 www 2076: 'containing' => 'Containing phrase',
1.1074 raeburn 2077: 'none' => 'None'},$onchange)).' '.
2078: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2079: &HTML::Entities::encode($env{'form.containingphrase'}).
2080: '" />'.$additional;
2081: }
2082:
2083: sub display_filter_js {
2084: my $includetext = &mt('Include parameter types');
2085: return <<"ENDJS";
2086:
2087: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2088: var firstType = 'hidden';
2089: if (setter.options[setter.selectedIndex].value == 'containing') {
2090: firstType = 'text';
2091: }
2092: firstObject = document.getElementById(firstid);
2093: if (typeof(firstObject) == 'object') {
2094: if (firstObject.type != firstType) {
2095: changeInputType(firstObject,firstType);
2096: }
2097: }
2098: if (context == 'parmslog') {
2099: var secondType = 'hidden';
2100: if (firstType == 'text') {
2101: secondType = 'checkbox';
2102: }
2103: secondObject = document.getElementById(secondid);
2104: if (typeof(secondObject) == 'object') {
2105: if (secondObject.type != secondType) {
2106: changeInputType(secondObject,secondType);
2107: }
2108: }
2109: var textItem = document.getElementById(thirdid);
2110: var currtext = textItem.innerHTML;
2111: var newtext;
2112: if (firstType == 'text') {
2113: newtext = '$includetext';
2114: } else {
2115: newtext = ' ';
2116: }
2117: if (currtext != newtext) {
2118: textItem.innerHTML = newtext;
2119: }
2120: }
2121: return;
2122: }
2123:
2124: function changeInputType(oldObject,newType) {
2125: var newObject = document.createElement('input');
2126: newObject.type = newType;
2127: if (oldObject.size) {
2128: newObject.size = oldObject.size;
2129: }
2130: if (oldObject.value) {
2131: newObject.value = oldObject.value;
2132: }
2133: if (oldObject.name) {
2134: newObject.name = oldObject.name;
2135: }
2136: if (oldObject.id) {
2137: newObject.id = oldObject.id;
2138: }
2139: oldObject.parentNode.replaceChild(newObject,oldObject);
2140: return;
2141: }
2142:
2143: ENDJS
1.475 www 2144: }
2145:
1.167 www 2146: sub gradeleveldescription {
2147: my $gradelevel=shift;
2148: my %gradelevels=(0 => 'Not specified',
2149: 1 => 'Grade 1',
2150: 2 => 'Grade 2',
2151: 3 => 'Grade 3',
2152: 4 => 'Grade 4',
2153: 5 => 'Grade 5',
2154: 6 => 'Grade 6',
2155: 7 => 'Grade 7',
2156: 8 => 'Grade 8',
2157: 9 => 'Grade 9',
2158: 10 => 'Grade 10',
2159: 11 => 'Grade 11',
2160: 12 => 'Grade 12',
2161: 13 => 'Grade 13',
2162: 14 => '100 Level',
2163: 15 => '200 Level',
2164: 16 => '300 Level',
2165: 17 => '400 Level',
2166: 18 => 'Graduate Level');
2167: return &mt($gradelevels{$gradelevel});
2168: }
2169:
1.163 www 2170: sub select_level_form {
2171: my ($deflevel,$name)=@_;
2172: unless ($deflevel) { $deflevel=0; }
1.167 www 2173: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2174: for (my $i=0; $i<=18; $i++) {
2175: $selectform.="<option value=\"$i\" ".
1.253 albertel 2176: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2177: ">".&gradeleveldescription($i)."</option>\n";
2178: }
2179: $selectform.="</select>";
2180: return $selectform;
1.163 www 2181: }
1.167 www 2182:
1.35 matthew 2183: #-------------------------------------------
2184:
1.45 matthew 2185: =pod
2186:
1.1075.2.42 raeburn 2187: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2188:
2189: Returns a string containing a <select name='$name' size='1'> form to
2190: allow a user to select the domain to preform an operation in.
2191: See loncreateuser.pm for an example invocation and use.
2192:
1.90 www 2193: If the $includeempty flag is set, it also includes an empty choice ("no domain
2194: selected");
2195:
1.743 raeburn 2196: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2197:
1.910 raeburn 2198: 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.
2199:
1.1075.2.36 raeburn 2200: The optional $incdoms is a reference to an array of domains which will be the only available options.
2201:
2202: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2203:
1.35 matthew 2204: =cut
2205:
2206: #-------------------------------------------
1.34 matthew 2207: sub select_dom_form {
1.1075.2.36 raeburn 2208: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2209: if ($onchange) {
1.874 raeburn 2210: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2211: }
1.1075.2.36 raeburn 2212: my (@domains,%exclude);
1.910 raeburn 2213: if (ref($incdoms) eq 'ARRAY') {
2214: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2215: } else {
2216: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2217: }
1.90 www 2218: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2219: if (ref($excdoms) eq 'ARRAY') {
2220: map { $exclude{$_} = 1; } @{$excdoms};
2221: }
1.743 raeburn 2222: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2223: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2224: next if ($exclude{$dom});
1.356 albertel 2225: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2226: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2227: if ($showdomdesc) {
2228: if ($dom ne '') {
2229: my $domdesc = &Apache::lonnet::domain($dom,'description');
2230: if ($domdesc ne '') {
2231: $selectdomain .= ' ('.$domdesc.')';
2232: }
2233: }
2234: }
2235: $selectdomain .= "</option>\n";
1.34 matthew 2236: }
2237: $selectdomain.="</select>";
2238: return $selectdomain;
2239: }
2240:
1.35 matthew 2241: #-------------------------------------------
2242:
1.45 matthew 2243: =pod
2244:
1.648 raeburn 2245: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2246:
1.586 raeburn 2247: input: 4 arguments (two required, two optional) -
2248: $domain - domain of new user
2249: $name - name of form element
2250: $default - Value of 'default' causes a default item to be first
2251: option, and selected by default.
2252: $hide - Value of 'hide' causes hiding of the name of the server,
2253: if 1 server found, or default, if 0 found.
1.594 raeburn 2254: output: returns 2 items:
1.586 raeburn 2255: (a) form element which contains either:
2256: (i) <select name="$name">
2257: <option value="$hostid1">$hostid $servers{$hostid}</option>
2258: <option value="$hostid2">$hostid $servers{$hostid}</option>
2259: </select>
2260: form item if there are multiple library servers in $domain, or
2261: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2262: if there is only one library server in $domain.
2263:
2264: (b) number of library servers found.
2265:
2266: See loncreateuser.pm for example of use.
1.35 matthew 2267:
2268: =cut
2269:
2270: #-------------------------------------------
1.586 raeburn 2271: sub home_server_form_item {
2272: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2273: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2274: my $result;
2275: my $numlib = keys(%servers);
2276: if ($numlib > 1) {
2277: $result .= '<select name="'.$name.'" />'."\n";
2278: if ($default) {
1.804 bisitz 2279: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2280: '</option>'."\n";
2281: }
2282: foreach my $hostid (sort(keys(%servers))) {
2283: $result.= '<option value="'.$hostid.'">'.
2284: $hostid.' '.$servers{$hostid}."</option>\n";
2285: }
2286: $result .= '</select>'."\n";
2287: } elsif ($numlib == 1) {
2288: my $hostid;
2289: foreach my $item (keys(%servers)) {
2290: $hostid = $item;
2291: }
2292: $result .= '<input type="hidden" name="'.$name.'" value="'.
2293: $hostid.'" />';
2294: if (!$hide) {
2295: $result .= $hostid.' '.$servers{$hostid};
2296: }
2297: $result .= "\n";
2298: } elsif ($default) {
2299: $result .= '<input type="hidden" name="'.$name.
2300: '" value="default" />';
2301: if (!$hide) {
2302: $result .= &mt('default');
2303: }
2304: $result .= "\n";
1.33 matthew 2305: }
1.586 raeburn 2306: return ($result,$numlib);
1.33 matthew 2307: }
1.112 bowersj2 2308:
2309: =pod
2310:
1.534 albertel 2311: =back
2312:
1.112 bowersj2 2313: =cut
1.87 matthew 2314:
2315: ###############################################################
1.112 bowersj2 2316: ## Decoding User Agent ##
1.87 matthew 2317: ###############################################################
2318:
2319: =pod
2320:
1.112 bowersj2 2321: =head1 Decoding the User Agent
2322:
2323: =over 4
2324:
2325: =item * &decode_user_agent()
1.87 matthew 2326:
2327: Inputs: $r
2328:
2329: Outputs:
2330:
2331: =over 4
2332:
1.112 bowersj2 2333: =item * $httpbrowser
1.87 matthew 2334:
1.112 bowersj2 2335: =item * $clientbrowser
1.87 matthew 2336:
1.112 bowersj2 2337: =item * $clientversion
1.87 matthew 2338:
1.112 bowersj2 2339: =item * $clientmathml
1.87 matthew 2340:
1.112 bowersj2 2341: =item * $clientunicode
1.87 matthew 2342:
1.112 bowersj2 2343: =item * $clientos
1.87 matthew 2344:
1.1075.2.42 raeburn 2345: =item * $clientmobile
2346:
2347: =item * $clientinfo
2348:
1.1075.2.77 raeburn 2349: =item * $clientosversion
2350:
1.87 matthew 2351: =back
2352:
1.157 matthew 2353: =back
2354:
1.87 matthew 2355: =cut
2356:
2357: ###############################################################
2358: ###############################################################
2359: sub decode_user_agent {
1.247 albertel 2360: my ($r)=@_;
1.87 matthew 2361: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2362: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2363: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2364: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2365: my $clientbrowser='unknown';
2366: my $clientversion='0';
2367: my $clientmathml='';
2368: my $clientunicode='0';
1.1075.2.42 raeburn 2369: my $clientmobile=0;
1.1075.2.77 raeburn 2370: my $clientosversion='';
1.87 matthew 2371: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2372: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2373: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2374: $clientbrowser=$bname;
2375: $httpbrowser=~/$vreg/i;
2376: $clientversion=$1;
2377: $clientmathml=($clientversion>=$minv);
2378: $clientunicode=($clientversion>=$univ);
2379: }
2380: }
2381: my $clientos='unknown';
1.1075.2.42 raeburn 2382: my $clientinfo;
1.87 matthew 2383: if (($httpbrowser=~/linux/i) ||
2384: ($httpbrowser=~/unix/i) ||
2385: ($httpbrowser=~/ux/i) ||
2386: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2387: if (($httpbrowser=~/vax/i) ||
2388: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2389: if ($httpbrowser=~/next/i) { $clientos='next'; }
2390: if (($httpbrowser=~/mac/i) ||
2391: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2392: if ($httpbrowser=~/win/i) {
2393: $clientos='win';
2394: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2395: $clientosversion = $1;
2396: }
2397: }
1.87 matthew 2398: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2399: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2400: $clientmobile=lc($1);
2401: }
2402: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2403: $clientinfo = 'firefox-'.$1;
2404: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2405: $clientinfo = 'chromeframe-'.$1;
2406: }
1.87 matthew 2407: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2408: $clientunicode,$clientos,$clientmobile,$clientinfo,
2409: $clientosversion);
1.87 matthew 2410: }
2411:
1.32 matthew 2412: ###############################################################
2413: ## Authentication changing form generation subroutines ##
2414: ###############################################################
2415: ##
2416: ## All of the authform_xxxxxxx subroutines take their inputs in a
2417: ## hash, and have reasonable default values.
2418: ##
2419: ## formname = the name given in the <form> tag.
1.35 matthew 2420: #-------------------------------------------
2421:
1.45 matthew 2422: =pod
2423:
1.112 bowersj2 2424: =head1 Authentication Routines
2425:
2426: =over 4
2427:
1.648 raeburn 2428: =item * &authform_xxxxxx()
1.35 matthew 2429:
2430: The authform_xxxxxx subroutines provide javascript and html forms which
2431: handle some of the conveniences required for authentication forms.
2432: This is not an optimal method, but it works.
2433:
2434: =over 4
2435:
1.112 bowersj2 2436: =item * authform_header
1.35 matthew 2437:
1.112 bowersj2 2438: =item * authform_authorwarning
1.35 matthew 2439:
1.112 bowersj2 2440: =item * authform_nochange
1.35 matthew 2441:
1.112 bowersj2 2442: =item * authform_kerberos
1.35 matthew 2443:
1.112 bowersj2 2444: =item * authform_internal
1.35 matthew 2445:
1.112 bowersj2 2446: =item * authform_filesystem
1.35 matthew 2447:
2448: =back
2449:
1.648 raeburn 2450: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2451:
1.35 matthew 2452: =cut
2453:
2454: #-------------------------------------------
1.32 matthew 2455: sub authform_header{
2456: my %in = (
2457: formname => 'cu',
1.80 albertel 2458: kerb_def_dom => '',
1.32 matthew 2459: @_,
2460: );
2461: $in{'formname'} = 'document.' . $in{'formname'};
2462: my $result='';
1.80 albertel 2463:
2464: #---------------------------------------------- Code for upper case translation
2465: my $Javascript_toUpperCase;
2466: unless ($in{kerb_def_dom}) {
2467: $Javascript_toUpperCase =<<"END";
2468: switch (choice) {
2469: case 'krb': currentform.elements[choicearg].value =
2470: currentform.elements[choicearg].value.toUpperCase();
2471: break;
2472: default:
2473: }
2474: END
2475: } else {
2476: $Javascript_toUpperCase = "";
2477: }
2478:
1.165 raeburn 2479: my $radioval = "'nochange'";
1.591 raeburn 2480: if (defined($in{'curr_authtype'})) {
2481: if ($in{'curr_authtype'} ne '') {
2482: $radioval = "'".$in{'curr_authtype'}."arg'";
2483: }
1.174 matthew 2484: }
1.165 raeburn 2485: my $argfield = 'null';
1.591 raeburn 2486: if (defined($in{'mode'})) {
1.165 raeburn 2487: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2488: if (defined($in{'curr_autharg'})) {
2489: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2490: $argfield = "'$in{'curr_autharg'}'";
2491: }
2492: }
2493: }
2494: }
2495:
1.32 matthew 2496: $result.=<<"END";
2497: var current = new Object();
1.165 raeburn 2498: current.radiovalue = $radioval;
2499: current.argfield = $argfield;
1.32 matthew 2500:
2501: function changed_radio(choice,currentform) {
2502: var choicearg = choice + 'arg';
2503: // If a radio button in changed, we need to change the argfield
2504: if (current.radiovalue != choice) {
2505: current.radiovalue = choice;
2506: if (current.argfield != null) {
2507: currentform.elements[current.argfield].value = '';
2508: }
2509: if (choice == 'nochange') {
2510: current.argfield = null;
2511: } else {
2512: current.argfield = choicearg;
2513: switch(choice) {
2514: case 'krb':
2515: currentform.elements[current.argfield].value =
2516: "$in{'kerb_def_dom'}";
2517: break;
2518: default:
2519: break;
2520: }
2521: }
2522: }
2523: return;
2524: }
1.22 www 2525:
1.32 matthew 2526: function changed_text(choice,currentform) {
2527: var choicearg = choice + 'arg';
2528: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2529: $Javascript_toUpperCase
1.32 matthew 2530: // clear old field
2531: if ((current.argfield != choicearg) && (current.argfield != null)) {
2532: currentform.elements[current.argfield].value = '';
2533: }
2534: current.argfield = choicearg;
2535: }
2536: set_auth_radio_buttons(choice,currentform);
2537: return;
1.20 www 2538: }
1.32 matthew 2539:
2540: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2541: var numauthchoices = currentform.login.length;
2542: if (typeof numauthchoices == "undefined") {
2543: return;
2544: }
1.32 matthew 2545: var i=0;
1.986 raeburn 2546: while (i < numauthchoices) {
1.32 matthew 2547: if (currentform.login[i].value == newvalue) { break; }
2548: i++;
2549: }
1.986 raeburn 2550: if (i == numauthchoices) {
1.32 matthew 2551: return;
2552: }
2553: current.radiovalue = newvalue;
2554: currentform.login[i].checked = true;
2555: return;
2556: }
2557: END
2558: return $result;
2559: }
2560:
1.1075.2.20 raeburn 2561: sub authform_authorwarning {
1.32 matthew 2562: my $result='';
1.144 matthew 2563: $result='<i>'.
2564: &mt('As a general rule, only authors or co-authors should be '.
2565: 'filesystem authenticated '.
2566: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2567: return $result;
2568: }
2569:
1.1075.2.20 raeburn 2570: sub authform_nochange {
1.32 matthew 2571: my %in = (
2572: formname => 'document.cu',
2573: kerb_def_dom => 'MSU.EDU',
2574: @_,
2575: );
1.1075.2.20 raeburn 2576: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2577: my $result;
1.1075.2.20 raeburn 2578: if (!$authnum) {
2579: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2580: } else {
2581: $result = '<label>'.&mt('[_1] Do not change login data',
2582: '<input type="radio" name="login" value="nochange" '.
2583: 'checked="checked" onclick="'.
1.281 albertel 2584: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2585: '</label>';
1.586 raeburn 2586: }
1.32 matthew 2587: return $result;
2588: }
2589:
1.591 raeburn 2590: sub authform_kerberos {
1.32 matthew 2591: my %in = (
2592: formname => 'document.cu',
2593: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2594: kerb_def_auth => 'krb4',
1.32 matthew 2595: @_,
2596: );
1.586 raeburn 2597: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2598: $autharg,$jscall);
1.1075.2.20 raeburn 2599: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2600: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2601: $check5 = ' checked="checked"';
1.80 albertel 2602: } else {
1.772 bisitz 2603: $check4 = ' checked="checked"';
1.80 albertel 2604: }
1.165 raeburn 2605: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2606: if (defined($in{'curr_authtype'})) {
2607: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2608: $krbcheck = ' checked="checked"';
1.623 raeburn 2609: if (defined($in{'mode'})) {
2610: if ($in{'mode'} eq 'modifyuser') {
2611: $krbcheck = '';
2612: }
2613: }
1.591 raeburn 2614: if (defined($in{'curr_kerb_ver'})) {
2615: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2616: $check5 = ' checked="checked"';
1.591 raeburn 2617: $check4 = '';
2618: } else {
1.772 bisitz 2619: $check4 = ' checked="checked"';
1.591 raeburn 2620: $check5 = '';
2621: }
1.586 raeburn 2622: }
1.591 raeburn 2623: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2624: $krbarg = $in{'curr_autharg'};
2625: }
1.586 raeburn 2626: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2627: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2628: $result =
2629: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2630: $in{'curr_autharg'},$krbver);
2631: } else {
2632: $result =
2633: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2634: }
2635: return $result;
2636: }
2637: }
2638: } else {
2639: if ($authnum == 1) {
1.784 bisitz 2640: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2641: }
2642: }
1.586 raeburn 2643: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2644: return;
1.587 raeburn 2645: } elsif ($authtype eq '') {
1.591 raeburn 2646: if (defined($in{'mode'})) {
1.587 raeburn 2647: if ($in{'mode'} eq 'modifycourse') {
2648: if ($authnum == 1) {
1.1075.2.20 raeburn 2649: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2650: }
2651: }
2652: }
1.586 raeburn 2653: }
2654: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2655: if ($authtype eq '') {
2656: $authtype = '<input type="radio" name="login" value="krb" '.
2657: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2658: $krbcheck.' />';
2659: }
2660: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2661: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2662: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2663: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2664: $in{'curr_authtype'} eq 'krb4')) {
2665: $result .= &mt
1.144 matthew 2666: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2667: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2668: '<label>'.$authtype,
1.281 albertel 2669: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2670: 'value="'.$krbarg.'" '.
1.144 matthew 2671: 'onchange="'.$jscall.'" />',
1.281 albertel 2672: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2673: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2674: '</label>');
1.586 raeburn 2675: } elsif ($can_assign{'krb4'}) {
2676: $result .= &mt
2677: ('[_1] Kerberos authenticated with domain [_2] '.
2678: '[_3] Version 4 [_4]',
2679: '<label>'.$authtype,
2680: '</label><input type="text" size="10" name="krbarg" '.
2681: 'value="'.$krbarg.'" '.
2682: 'onchange="'.$jscall.'" />',
2683: '<label><input type="hidden" name="krbver" value="4" />',
2684: '</label>');
2685: } elsif ($can_assign{'krb5'}) {
2686: $result .= &mt
2687: ('[_1] Kerberos authenticated with domain [_2] '.
2688: '[_3] Version 5 [_4]',
2689: '<label>'.$authtype,
2690: '</label><input type="text" size="10" name="krbarg" '.
2691: 'value="'.$krbarg.'" '.
2692: 'onchange="'.$jscall.'" />',
2693: '<label><input type="hidden" name="krbver" value="5" />',
2694: '</label>');
2695: }
1.32 matthew 2696: return $result;
2697: }
2698:
1.1075.2.20 raeburn 2699: sub authform_internal {
1.586 raeburn 2700: my %in = (
1.32 matthew 2701: formname => 'document.cu',
2702: kerb_def_dom => 'MSU.EDU',
2703: @_,
2704: );
1.586 raeburn 2705: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2706: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2707: if (defined($in{'curr_authtype'})) {
2708: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2709: if ($can_assign{'int'}) {
1.772 bisitz 2710: $intcheck = 'checked="checked" ';
1.623 raeburn 2711: if (defined($in{'mode'})) {
2712: if ($in{'mode'} eq 'modifyuser') {
2713: $intcheck = '';
2714: }
2715: }
1.591 raeburn 2716: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2717: $intarg = $in{'curr_autharg'};
2718: }
2719: } else {
2720: $result = &mt('Currently internally authenticated.');
2721: return $result;
1.165 raeburn 2722: }
2723: }
1.586 raeburn 2724: } else {
2725: if ($authnum == 1) {
1.784 bisitz 2726: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2727: }
2728: }
2729: if (!$can_assign{'int'}) {
2730: return;
1.587 raeburn 2731: } elsif ($authtype eq '') {
1.591 raeburn 2732: if (defined($in{'mode'})) {
1.587 raeburn 2733: if ($in{'mode'} eq 'modifycourse') {
2734: if ($authnum == 1) {
1.1075.2.20 raeburn 2735: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2736: }
2737: }
2738: }
1.165 raeburn 2739: }
1.586 raeburn 2740: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2741: if ($authtype eq '') {
2742: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2743: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2744: }
1.605 bisitz 2745: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2746: $intarg.'" onchange="'.$jscall.'" />';
2747: $result = &mt
1.144 matthew 2748: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2749: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2750: $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 2751: return $result;
2752: }
2753:
1.1075.2.20 raeburn 2754: sub authform_local {
1.32 matthew 2755: my %in = (
2756: formname => 'document.cu',
2757: kerb_def_dom => 'MSU.EDU',
2758: @_,
2759: );
1.586 raeburn 2760: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2761: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2762: if (defined($in{'curr_authtype'})) {
2763: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2764: if ($can_assign{'loc'}) {
1.772 bisitz 2765: $loccheck = 'checked="checked" ';
1.623 raeburn 2766: if (defined($in{'mode'})) {
2767: if ($in{'mode'} eq 'modifyuser') {
2768: $loccheck = '';
2769: }
2770: }
1.591 raeburn 2771: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2772: $locarg = $in{'curr_autharg'};
2773: }
2774: } else {
2775: $result = &mt('Currently using local (institutional) authentication.');
2776: return $result;
1.165 raeburn 2777: }
2778: }
1.586 raeburn 2779: } else {
2780: if ($authnum == 1) {
1.784 bisitz 2781: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2782: }
2783: }
2784: if (!$can_assign{'loc'}) {
2785: return;
1.587 raeburn 2786: } elsif ($authtype eq '') {
1.591 raeburn 2787: if (defined($in{'mode'})) {
1.587 raeburn 2788: if ($in{'mode'} eq 'modifycourse') {
2789: if ($authnum == 1) {
1.1075.2.20 raeburn 2790: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2791: }
2792: }
2793: }
1.165 raeburn 2794: }
1.586 raeburn 2795: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2796: if ($authtype eq '') {
2797: $authtype = '<input type="radio" name="login" value="loc" '.
2798: $loccheck.' onchange="'.$jscall.'" onclick="'.
2799: $jscall.'" />';
2800: }
2801: $autharg = '<input type="text" size="10" name="locarg" value="'.
2802: $locarg.'" onchange="'.$jscall.'" />';
2803: $result = &mt('[_1] Local Authentication with argument [_2]',
2804: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2805: return $result;
2806: }
2807:
1.1075.2.20 raeburn 2808: sub authform_filesystem {
1.32 matthew 2809: my %in = (
2810: formname => 'document.cu',
2811: kerb_def_dom => 'MSU.EDU',
2812: @_,
2813: );
1.586 raeburn 2814: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2815: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2816: if (defined($in{'curr_authtype'})) {
2817: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2818: if ($can_assign{'fsys'}) {
1.772 bisitz 2819: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2820: if (defined($in{'mode'})) {
2821: if ($in{'mode'} eq 'modifyuser') {
2822: $fsyscheck = '';
2823: }
2824: }
1.586 raeburn 2825: } else {
2826: $result = &mt('Currently Filesystem Authenticated.');
2827: return $result;
2828: }
2829: }
2830: } else {
2831: if ($authnum == 1) {
1.784 bisitz 2832: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2833: }
2834: }
2835: if (!$can_assign{'fsys'}) {
2836: return;
1.587 raeburn 2837: } elsif ($authtype eq '') {
1.591 raeburn 2838: if (defined($in{'mode'})) {
1.587 raeburn 2839: if ($in{'mode'} eq 'modifycourse') {
2840: if ($authnum == 1) {
1.1075.2.20 raeburn 2841: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2842: }
2843: }
2844: }
1.586 raeburn 2845: }
2846: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2847: if ($authtype eq '') {
2848: $authtype = '<input type="radio" name="login" value="fsys" '.
2849: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2850: $jscall.'" />';
2851: }
2852: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2853: ' onchange="'.$jscall.'" />';
2854: $result = &mt
1.144 matthew 2855: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2856: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2857: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2858: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2859: 'onchange="'.$jscall.'" />');
1.32 matthew 2860: return $result;
2861: }
2862:
1.586 raeburn 2863: sub get_assignable_auth {
2864: my ($dom) = @_;
2865: if ($dom eq '') {
2866: $dom = $env{'request.role.domain'};
2867: }
2868: my %can_assign = (
2869: krb4 => 1,
2870: krb5 => 1,
2871: int => 1,
2872: loc => 1,
2873: );
2874: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2875: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2876: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2877: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2878: my $context;
2879: if ($env{'request.role'} =~ /^au/) {
2880: $context = 'author';
2881: } elsif ($env{'request.role'} =~ /^dc/) {
2882: $context = 'domain';
2883: } elsif ($env{'request.course.id'}) {
2884: $context = 'course';
2885: }
2886: if ($context) {
2887: if (ref($authhash->{$context}) eq 'HASH') {
2888: %can_assign = %{$authhash->{$context}};
2889: }
2890: }
2891: }
2892: }
2893: my $authnum = 0;
2894: foreach my $key (keys(%can_assign)) {
2895: if ($can_assign{$key}) {
2896: $authnum ++;
2897: }
2898: }
2899: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2900: $authnum --;
2901: }
2902: return ($authnum,%can_assign);
2903: }
2904:
1.80 albertel 2905: ###############################################################
2906: ## Get Kerberos Defaults for Domain ##
2907: ###############################################################
2908: ##
2909: ## Returns default kerberos version and an associated argument
2910: ## as listed in file domain.tab. If not listed, provides
2911: ## appropriate default domain and kerberos version.
2912: ##
2913: #-------------------------------------------
2914:
2915: =pod
2916:
1.648 raeburn 2917: =item * &get_kerberos_defaults()
1.80 albertel 2918:
2919: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2920: version and domain. If not found, it defaults to version 4 and the
2921: domain of the server.
1.80 albertel 2922:
1.648 raeburn 2923: =over 4
2924:
1.80 albertel 2925: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2926:
1.648 raeburn 2927: =back
2928:
2929: =back
2930:
1.80 albertel 2931: =cut
2932:
2933: #-------------------------------------------
2934: sub get_kerberos_defaults {
2935: my $domain=shift;
1.641 raeburn 2936: my ($krbdef,$krbdefdom);
2937: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2938: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2939: $krbdef = $domdefaults{'auth_def'};
2940: $krbdefdom = $domdefaults{'auth_arg_def'};
2941: } else {
1.80 albertel 2942: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2943: my $krbdefdom=$1;
2944: $krbdefdom=~tr/a-z/A-Z/;
2945: $krbdef = "krb4";
2946: }
2947: return ($krbdef,$krbdefdom);
2948: }
1.112 bowersj2 2949:
1.32 matthew 2950:
1.46 matthew 2951: ###############################################################
2952: ## Thesaurus Functions ##
2953: ###############################################################
1.20 www 2954:
1.46 matthew 2955: =pod
1.20 www 2956:
1.112 bowersj2 2957: =head1 Thesaurus Functions
2958:
2959: =over 4
2960:
1.648 raeburn 2961: =item * &initialize_keywords()
1.46 matthew 2962:
2963: Initializes the package variable %Keywords if it is empty. Uses the
2964: package variable $thesaurus_db_file.
2965:
2966: =cut
2967:
2968: ###################################################
2969:
2970: sub initialize_keywords {
2971: return 1 if (scalar keys(%Keywords));
2972: # If we are here, %Keywords is empty, so fill it up
2973: # Make sure the file we need exists...
2974: if (! -e $thesaurus_db_file) {
2975: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2976: " failed because it does not exist");
2977: return 0;
2978: }
2979: # Set up the hash as a database
2980: my %thesaurus_db;
2981: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2982: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2983: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2984: $thesaurus_db_file);
2985: return 0;
2986: }
2987: # Get the average number of appearances of a word.
2988: my $avecount = $thesaurus_db{'average.count'};
2989: # Put keywords (those that appear > average) into %Keywords
2990: while (my ($word,$data)=each (%thesaurus_db)) {
2991: my ($count,undef) = split /:/,$data;
2992: $Keywords{$word}++ if ($count > $avecount);
2993: }
2994: untie %thesaurus_db;
2995: # Remove special values from %Keywords.
1.356 albertel 2996: foreach my $value ('total.count','average.count') {
2997: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2998: }
1.46 matthew 2999: return 1;
3000: }
3001:
3002: ###################################################
3003:
3004: =pod
3005:
1.648 raeburn 3006: =item * &keyword($word)
1.46 matthew 3007:
3008: Returns true if $word is a keyword. A keyword is a word that appears more
3009: than the average number of times in the thesaurus database. Calls
3010: &initialize_keywords
3011:
3012: =cut
3013:
3014: ###################################################
1.20 www 3015:
3016: sub keyword {
1.46 matthew 3017: return if (!&initialize_keywords());
3018: my $word=lc(shift());
3019: $word=~s/\W//g;
3020: return exists($Keywords{$word});
1.20 www 3021: }
1.46 matthew 3022:
3023: ###############################################################
3024:
3025: =pod
1.20 www 3026:
1.648 raeburn 3027: =item * &get_related_words()
1.46 matthew 3028:
1.160 matthew 3029: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3030: an array of words. If the keyword is not in the thesaurus, an empty array
3031: will be returned. The order of the words returned is determined by the
3032: database which holds them.
3033:
3034: Uses global $thesaurus_db_file.
3035:
1.1057 foxr 3036:
1.46 matthew 3037: =cut
3038:
3039: ###############################################################
3040: sub get_related_words {
3041: my $keyword = shift;
3042: my %thesaurus_db;
3043: if (! -e $thesaurus_db_file) {
3044: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3045: "failed because the file does not exist");
3046: return ();
3047: }
3048: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3049: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3050: return ();
3051: }
3052: my @Words=();
1.429 www 3053: my $count=0;
1.46 matthew 3054: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3055: # The first element is the number of times
3056: # the word appears. We do not need it now.
1.429 www 3057: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3058: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3059: my $threshold=$mostfrequentcount/10;
3060: foreach my $possibleword (@RelatedWords) {
3061: my ($word,$wordcount)=split(/\,/,$possibleword);
3062: if ($wordcount>$threshold) {
3063: push(@Words,$word);
3064: $count++;
3065: if ($count>10) { last; }
3066: }
1.20 www 3067: }
3068: }
1.46 matthew 3069: untie %thesaurus_db;
3070: return @Words;
1.14 harris41 3071: }
1.46 matthew 3072:
1.112 bowersj2 3073: =pod
3074:
3075: =back
3076:
3077: =cut
1.61 www 3078:
3079: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3080: =pod
3081:
1.112 bowersj2 3082: =head1 User Name Functions
3083:
3084: =over 4
3085:
1.648 raeburn 3086: =item * &plainname($uname,$udom,$first)
1.81 albertel 3087:
1.112 bowersj2 3088: Takes a users logon name and returns it as a string in
1.226 albertel 3089: "first middle last generation" form
3090: if $first is set to 'lastname' then it returns it as
3091: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3092:
3093: =cut
1.61 www 3094:
1.295 www 3095:
1.81 albertel 3096: ###############################################################
1.61 www 3097: sub plainname {
1.226 albertel 3098: my ($uname,$udom,$first)=@_;
1.537 albertel 3099: return if (!defined($uname) || !defined($udom));
1.295 www 3100: my %names=&getnames($uname,$udom);
1.226 albertel 3101: my $name=&Apache::lonnet::format_name($names{'firstname'},
3102: $names{'middlename'},
3103: $names{'lastname'},
3104: $names{'generation'},$first);
3105: $name=~s/^\s+//;
1.62 www 3106: $name=~s/\s+$//;
3107: $name=~s/\s+/ /g;
1.353 albertel 3108: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3109: return $name;
1.61 www 3110: }
1.66 www 3111:
3112: # -------------------------------------------------------------------- Nickname
1.81 albertel 3113: =pod
3114:
1.648 raeburn 3115: =item * &nickname($uname,$udom)
1.81 albertel 3116:
3117: Gets a users name and returns it as a string as
3118:
3119: ""nickname""
1.66 www 3120:
1.81 albertel 3121: if the user has a nickname or
3122:
3123: "first middle last generation"
3124:
3125: if the user does not
3126:
3127: =cut
1.66 www 3128:
3129: sub nickname {
3130: my ($uname,$udom)=@_;
1.537 albertel 3131: return if (!defined($uname) || !defined($udom));
1.295 www 3132: my %names=&getnames($uname,$udom);
1.68 albertel 3133: my $name=$names{'nickname'};
1.66 www 3134: if ($name) {
3135: $name='"'.$name.'"';
3136: } else {
3137: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3138: $names{'lastname'}.' '.$names{'generation'};
3139: $name=~s/\s+$//;
3140: $name=~s/\s+/ /g;
3141: }
3142: return $name;
3143: }
3144:
1.295 www 3145: sub getnames {
3146: my ($uname,$udom)=@_;
1.537 albertel 3147: return if (!defined($uname) || !defined($udom));
1.433 albertel 3148: if ($udom eq 'public' && $uname eq 'public') {
3149: return ('lastname' => &mt('Public'));
3150: }
1.295 www 3151: my $id=$uname.':'.$udom;
3152: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3153: if ($cached) {
3154: return %{$names};
3155: } else {
3156: my %loadnames=&Apache::lonnet::get('environment',
3157: ['firstname','middlename','lastname','generation','nickname'],
3158: $udom,$uname);
3159: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3160: return %loadnames;
3161: }
3162: }
1.61 www 3163:
1.542 raeburn 3164: # -------------------------------------------------------------------- getemails
1.648 raeburn 3165:
1.542 raeburn 3166: =pod
3167:
1.648 raeburn 3168: =item * &getemails($uname,$udom)
1.542 raeburn 3169:
3170: Gets a user's email information and returns it as a hash with keys:
3171: notification, critnotification, permanentemail
3172:
3173: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3174: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3175:
1.648 raeburn 3176:
1.542 raeburn 3177: =cut
3178:
1.648 raeburn 3179:
1.466 albertel 3180: sub getemails {
3181: my ($uname,$udom)=@_;
3182: if ($udom eq 'public' && $uname eq 'public') {
3183: return;
3184: }
1.467 www 3185: if (!$udom) { $udom=$env{'user.domain'}; }
3186: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3187: my $id=$uname.':'.$udom;
3188: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3189: if ($cached) {
3190: return %{$names};
3191: } else {
3192: my %loadnames=&Apache::lonnet::get('environment',
3193: ['notification','critnotification',
3194: 'permanentemail'],
3195: $udom,$uname);
3196: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3197: return %loadnames;
3198: }
3199: }
3200:
1.551 albertel 3201: sub flush_email_cache {
3202: my ($uname,$udom)=@_;
3203: if (!$udom) { $udom =$env{'user.domain'}; }
3204: if (!$uname) { $uname=$env{'user.name'}; }
3205: return if ($udom eq 'public' && $uname eq 'public');
3206: my $id=$uname.':'.$udom;
3207: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3208: }
3209:
1.728 raeburn 3210: # -------------------------------------------------------------------- getlangs
3211:
3212: =pod
3213:
3214: =item * &getlangs($uname,$udom)
3215:
3216: Gets a user's language preference and returns it as a hash with key:
3217: language.
3218:
3219: =cut
3220:
3221:
3222: sub getlangs {
3223: my ($uname,$udom) = @_;
3224: if (!$udom) { $udom =$env{'user.domain'}; }
3225: if (!$uname) { $uname=$env{'user.name'}; }
3226: my $id=$uname.':'.$udom;
3227: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3228: if ($cached) {
3229: return %{$langs};
3230: } else {
3231: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3232: $udom,$uname);
3233: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3234: return %loadlangs;
3235: }
3236: }
3237:
3238: sub flush_langs_cache {
3239: my ($uname,$udom)=@_;
3240: if (!$udom) { $udom =$env{'user.domain'}; }
3241: if (!$uname) { $uname=$env{'user.name'}; }
3242: return if ($udom eq 'public' && $uname eq 'public');
3243: my $id=$uname.':'.$udom;
3244: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3245: }
3246:
1.61 www 3247: # ------------------------------------------------------------------ Screenname
1.81 albertel 3248:
3249: =pod
3250:
1.648 raeburn 3251: =item * &screenname($uname,$udom)
1.81 albertel 3252:
3253: Gets a users screenname and returns it as a string
3254:
3255: =cut
1.61 www 3256:
3257: sub screenname {
3258: my ($uname,$udom)=@_;
1.258 albertel 3259: if ($uname eq $env{'user.name'} &&
3260: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3261: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3262: return $names{'screenname'};
1.62 www 3263: }
3264:
1.212 albertel 3265:
1.802 bisitz 3266: # ------------------------------------------------------------- Confirm Wrapper
3267: =pod
3268:
1.1075.2.42 raeburn 3269: =item * &confirmwrapper($message)
1.802 bisitz 3270:
3271: Wrap messages about completion of operation in box
3272:
3273: =cut
3274:
3275: sub confirmwrapper {
3276: my ($message)=@_;
3277: if ($message) {
3278: return "\n".'<div class="LC_confirm_box">'."\n"
3279: .$message."\n"
3280: .'</div>'."\n";
3281: } else {
3282: return $message;
3283: }
3284: }
3285:
1.62 www 3286: # ------------------------------------------------------------- Message Wrapper
3287:
3288: sub messagewrapper {
1.369 www 3289: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3290: return
1.441 albertel 3291: '<a href="/adm/email?compose=individual&'.
3292: 'recname='.$username.'&recdom='.$domain.
3293: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3294: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3295: }
1.802 bisitz 3296:
1.74 www 3297: # --------------------------------------------------------------- Notes Wrapper
3298:
3299: sub noteswrapper {
3300: my ($link,$un,$do)=@_;
3301: return
1.896 amueller 3302: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3303: }
1.802 bisitz 3304:
1.62 www 3305: # ------------------------------------------------------------- Aboutme Wrapper
3306:
3307: sub aboutmewrapper {
1.1070 raeburn 3308: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3309: if (!defined($username) && !defined($domain)) {
3310: return;
3311: }
1.1075.2.15 raeburn 3312: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3313: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3314: }
3315:
3316: # ------------------------------------------------------------ Syllabus Wrapper
3317:
3318: sub syllabuswrapper {
1.707 bisitz 3319: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3320: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3321: }
1.14 harris41 3322:
1.802 bisitz 3323: # -----------------------------------------------------------------------------
3324:
1.208 matthew 3325: sub track_student_link {
1.887 raeburn 3326: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3327: my $link ="/adm/trackstudent?";
1.208 matthew 3328: my $title = 'View recent activity';
3329: if (defined($sname) && $sname !~ /^\s*$/ &&
3330: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3331: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3332: $title .= ' of this student';
1.268 albertel 3333: }
1.208 matthew 3334: if (defined($target) && $target !~ /^\s*$/) {
3335: $target = qq{target="$target"};
3336: } else {
3337: $target = '';
3338: }
1.268 albertel 3339: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3340: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3341: $title = &mt($title);
3342: $linktext = &mt($linktext);
1.448 albertel 3343: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3344: &help_open_topic('View_recent_activity');
1.208 matthew 3345: }
3346:
1.781 raeburn 3347: sub slot_reservations_link {
3348: my ($linktext,$sname,$sdom,$target) = @_;
3349: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3350: my $title = 'View slot reservation history';
3351: if (defined($sname) && $sname !~ /^\s*$/ &&
3352: defined($sdom) && $sdom !~ /^\s*$/) {
3353: $link .= "&uname=$sname&udom=$sdom";
3354: $title .= ' of this student';
3355: }
3356: if (defined($target) && $target !~ /^\s*$/) {
3357: $target = qq{target="$target"};
3358: } else {
3359: $target = '';
3360: }
3361: $title = &mt($title);
3362: $linktext = &mt($linktext);
3363: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3364: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3365:
3366: }
3367:
1.508 www 3368: # ===================================================== Display a student photo
3369:
3370:
1.509 albertel 3371: sub student_image_tag {
1.508 www 3372: my ($domain,$user)=@_;
3373: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3374: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3375: return '<img src="'.$imgsrc.'" align="right" />';
3376: } else {
3377: return '';
3378: }
3379: }
3380:
1.112 bowersj2 3381: =pod
3382:
3383: =back
3384:
3385: =head1 Access .tab File Data
3386:
3387: =over 4
3388:
1.648 raeburn 3389: =item * &languageids()
1.112 bowersj2 3390:
3391: returns list of all language ids
3392:
3393: =cut
3394:
1.14 harris41 3395: sub languageids {
1.16 harris41 3396: return sort(keys(%language));
1.14 harris41 3397: }
3398:
1.112 bowersj2 3399: =pod
3400:
1.648 raeburn 3401: =item * &languagedescription()
1.112 bowersj2 3402:
3403: returns description of a specified language id
3404:
3405: =cut
3406:
1.14 harris41 3407: sub languagedescription {
1.125 www 3408: my $code=shift;
3409: return ($supported_language{$code}?'* ':'').
3410: $language{$code}.
1.126 www 3411: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3412: }
3413:
1.1048 foxr 3414: =pod
3415:
3416: =item * &plainlanguagedescription
3417:
3418: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3419: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3420:
3421: =cut
3422:
1.145 www 3423: sub plainlanguagedescription {
3424: my $code=shift;
3425: return $language{$code};
3426: }
3427:
1.1048 foxr 3428: =pod
3429:
3430: =item * &supportedlanguagecode
3431:
3432: Returns the supported language code (e.g. sptutf maps to pt) given a language
3433: code.
3434:
3435: =cut
3436:
1.145 www 3437: sub supportedlanguagecode {
3438: my $code=shift;
3439: return $supported_language{$code};
1.97 www 3440: }
3441:
1.112 bowersj2 3442: =pod
3443:
1.1048 foxr 3444: =item * &latexlanguage()
3445:
3446: Given a language key code returns the correspondnig language to use
3447: to select the correct hyphenation on LaTeX printouts. This is undef if there
3448: is no supported hyphenation for the language code.
3449:
3450: =cut
3451:
3452: sub latexlanguage {
3453: my $code = shift;
3454: return $latex_language{$code};
3455: }
3456:
3457: =pod
3458:
3459: =item * &latexhyphenation()
3460:
3461: Same as above but what's supplied is the language as it might be stored
3462: in the metadata.
3463:
3464: =cut
3465:
3466: sub latexhyphenation {
3467: my $key = shift;
3468: return $latex_language_bykey{$key};
3469: }
3470:
3471: =pod
3472:
1.648 raeburn 3473: =item * ©rightids()
1.112 bowersj2 3474:
3475: returns list of all copyrights
3476:
3477: =cut
3478:
3479: sub copyrightids {
3480: return sort(keys(%cprtag));
3481: }
3482:
3483: =pod
3484:
1.648 raeburn 3485: =item * ©rightdescription()
1.112 bowersj2 3486:
3487: returns description of a specified copyright id
3488:
3489: =cut
3490:
3491: sub copyrightdescription {
1.166 www 3492: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3493: }
1.197 matthew 3494:
3495: =pod
3496:
1.648 raeburn 3497: =item * &source_copyrightids()
1.192 taceyjo1 3498:
3499: returns list of all source copyrights
3500:
3501: =cut
3502:
3503: sub source_copyrightids {
3504: return sort(keys(%scprtag));
3505: }
3506:
3507: =pod
3508:
1.648 raeburn 3509: =item * &source_copyrightdescription()
1.192 taceyjo1 3510:
3511: returns description of a specified source copyright id
3512:
3513: =cut
3514:
3515: sub source_copyrightdescription {
3516: return &mt($scprtag{shift(@_)});
3517: }
1.112 bowersj2 3518:
3519: =pod
3520:
1.648 raeburn 3521: =item * &filecategories()
1.112 bowersj2 3522:
3523: returns list of all file categories
3524:
3525: =cut
3526:
3527: sub filecategories {
3528: return sort(keys(%category_extensions));
3529: }
3530:
3531: =pod
3532:
1.648 raeburn 3533: =item * &filecategorytypes()
1.112 bowersj2 3534:
3535: returns list of file types belonging to a given file
3536: category
3537:
3538: =cut
3539:
3540: sub filecategorytypes {
1.356 albertel 3541: my ($cat) = @_;
3542: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3543: }
3544:
3545: =pod
3546:
1.648 raeburn 3547: =item * &fileembstyle()
1.112 bowersj2 3548:
3549: returns embedding style for a specified file type
3550:
3551: =cut
3552:
3553: sub fileembstyle {
3554: return $fe{lc(shift(@_))};
1.169 www 3555: }
3556:
1.351 www 3557: sub filemimetype {
3558: return $fm{lc(shift(@_))};
3559: }
3560:
1.169 www 3561:
3562: sub filecategoryselect {
3563: my ($name,$value)=@_;
1.189 matthew 3564: return &select_form($value,$name,
1.970 raeburn 3565: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3566: }
3567:
3568: =pod
3569:
1.648 raeburn 3570: =item * &filedescription()
1.112 bowersj2 3571:
3572: returns description for a specified file type
3573:
3574: =cut
3575:
3576: sub filedescription {
1.188 matthew 3577: my $file_description = $fd{lc(shift())};
3578: $file_description =~ s:([\[\]]):~$1:g;
3579: return &mt($file_description);
1.112 bowersj2 3580: }
3581:
3582: =pod
3583:
1.648 raeburn 3584: =item * &filedescriptionex()
1.112 bowersj2 3585:
3586: returns description for a specified file type with
3587: extra formatting
3588:
3589: =cut
3590:
3591: sub filedescriptionex {
3592: my $ex=shift;
1.188 matthew 3593: my $file_description = $fd{lc($ex)};
3594: $file_description =~ s:([\[\]]):~$1:g;
3595: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3596: }
3597:
3598: # End of .tab access
3599: =pod
3600:
3601: =back
3602:
3603: =cut
3604:
3605: # ------------------------------------------------------------------ File Types
3606: sub fileextensions {
3607: return sort(keys(%fe));
3608: }
3609:
1.97 www 3610: # ----------------------------------------------------------- Display Languages
3611: # returns a hash with all desired display languages
3612: #
3613:
3614: sub display_languages {
3615: my %languages=();
1.695 raeburn 3616: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3617: $languages{$lang}=1;
1.97 www 3618: }
3619: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3620: if ($env{'form.displaylanguage'}) {
1.356 albertel 3621: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3622: $languages{$lang}=1;
1.97 www 3623: }
3624: }
3625: return %languages;
1.14 harris41 3626: }
3627:
1.582 albertel 3628: sub languages {
3629: my ($possible_langs) = @_;
1.695 raeburn 3630: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3631: if (!ref($possible_langs)) {
3632: if( wantarray ) {
3633: return @preferred_langs;
3634: } else {
3635: return $preferred_langs[0];
3636: }
3637: }
3638: my %possibilities = map { $_ => 1 } (@$possible_langs);
3639: my @preferred_possibilities;
3640: foreach my $preferred_lang (@preferred_langs) {
3641: if (exists($possibilities{$preferred_lang})) {
3642: push(@preferred_possibilities, $preferred_lang);
3643: }
3644: }
3645: if( wantarray ) {
3646: return @preferred_possibilities;
3647: }
3648: return $preferred_possibilities[0];
3649: }
3650:
1.742 raeburn 3651: sub user_lang {
3652: my ($touname,$toudom,$fromcid) = @_;
3653: my @userlangs;
3654: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3655: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3656: $env{'course.'.$fromcid.'.languages'}));
3657: } else {
3658: my %langhash = &getlangs($touname,$toudom);
3659: if ($langhash{'languages'} ne '') {
3660: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3661: } else {
3662: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3663: if ($domdefs{'lang_def'} ne '') {
3664: @userlangs = ($domdefs{'lang_def'});
3665: }
3666: }
3667: }
3668: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3669: my $user_lh = Apache::localize->get_handle(@languages);
3670: return $user_lh;
3671: }
3672:
3673:
1.112 bowersj2 3674: ###############################################################
3675: ## Student Answer Attempts ##
3676: ###############################################################
3677:
3678: =pod
3679:
3680: =head1 Alternate Problem Views
3681:
3682: =over 4
3683:
1.648 raeburn 3684: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 3685: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 3686:
3687: Return string with previous attempt on problem. Arguments:
3688:
3689: =over 4
3690:
3691: =item * $symb: Problem, including path
3692:
3693: =item * $username: username of the desired student
3694:
3695: =item * $domain: domain of the desired student
1.14 harris41 3696:
1.112 bowersj2 3697: =item * $course: Course ID
1.14 harris41 3698:
1.112 bowersj2 3699: =item * $getattempt: Leave blank for all attempts, otherwise put
3700: something
1.14 harris41 3701:
1.112 bowersj2 3702: =item * $regexp: if string matches this regexp, the string will be
3703: sent to $gradesub
1.14 harris41 3704:
1.112 bowersj2 3705: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3706:
1.1075.2.86 raeburn 3707: =item * $usec: section of the desired student
3708:
3709: =item * $identifier: counter for student (multiple students one problem) or
3710: problem (one student; whole sequence).
3711:
1.112 bowersj2 3712: =back
1.14 harris41 3713:
1.112 bowersj2 3714: The output string is a table containing all desired attempts, if any.
1.16 harris41 3715:
1.112 bowersj2 3716: =cut
1.1 albertel 3717:
3718: sub get_previous_attempt {
1.1075.2.86 raeburn 3719: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 3720: my $prevattempts='';
1.43 ng 3721: no strict 'refs';
1.1 albertel 3722: if ($symb) {
1.3 albertel 3723: my (%returnhash)=
3724: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3725: if ($returnhash{'version'}) {
3726: my %lasthash=();
3727: my $version;
3728: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 3729: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
3730: if ($key =~ /\.rawrndseed$/) {
3731: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
3732: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
3733: } else {
3734: $lasthash{$key}=$returnhash{$version.':'.$key};
3735: }
1.19 harris41 3736: }
1.1 albertel 3737: }
1.596 albertel 3738: $prevattempts=&start_data_table().&start_data_table_header_row();
3739: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 3740: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 3741: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3742: foreach my $key (sort(keys(%lasthash))) {
3743: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3744: if ($#parts > 0) {
1.31 albertel 3745: my $data=$parts[-1];
1.989 raeburn 3746: next if ($data eq 'foilorder');
1.31 albertel 3747: pop(@parts);
1.1010 www 3748: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3749: if ($data eq 'type') {
3750: unless ($showsurv) {
3751: my $id = join(',',@parts);
3752: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3753: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3754: $lasthidden{$ign.'.'.$id} = 1;
3755: }
1.945 raeburn 3756: }
1.1075.2.86 raeburn 3757: if ($identifier ne '') {
3758: my $id = join(',',@parts);
3759: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
3760: $domain,$username,$usec,undef,$course) =~ /^no/) {
3761: $hidestatus{$ign.'.'.$id} = 1;
3762: }
3763: }
3764: } elsif ($data eq 'regrader') {
3765: if (($identifier ne '') && (@parts)) {
3766: my $id = join(',',@parts);
3767: $regraded{$ign.'.'.$id} = 1;
3768: }
1.1010 www 3769: }
1.31 albertel 3770: } else {
1.41 ng 3771: if ($#parts == 0) {
3772: $prevattempts.='<th>'.$parts[0].'</th>';
3773: } else {
3774: $prevattempts.='<th>'.$ign.'</th>';
3775: }
1.31 albertel 3776: }
1.16 harris41 3777: }
1.596 albertel 3778: $prevattempts.=&end_data_table_header_row();
1.40 ng 3779: if ($getattempt eq '') {
1.1075.2.86 raeburn 3780: my (%solved,%resets,%probstatus);
3781: if (($identifier ne '') && (keys(%regraded) > 0)) {
3782: for ($version=1;$version<=$returnhash{'version'};$version++) {
3783: foreach my $id (keys(%regraded)) {
3784: if (($returnhash{$version.':'.$id.'.regrader'}) &&
3785: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
3786: ($returnhash{$version.':'.$id.'.award'} eq '')) {
3787: push(@{$resets{$id}},$version);
3788: }
3789: }
3790: }
3791: }
1.40 ng 3792: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 3793: my (@hidden,@unsolved);
1.945 raeburn 3794: if (%typeparts) {
3795: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 3796: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
3797: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 3798: push(@hidden,$id);
1.1075.2.86 raeburn 3799: } elsif ($identifier ne '') {
3800: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
3801: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
3802: ($hidestatus{$id})) {
3803: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
3804: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
3805: push(@{$solved{$id}},$version);
3806: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
3807: (ref($solved{$id}) eq 'ARRAY')) {
3808: my $skip;
3809: if (ref($resets{$id}) eq 'ARRAY') {
3810: foreach my $reset (@{$resets{$id}}) {
3811: if ($reset > $solved{$id}[-1]) {
3812: $skip=1;
3813: last;
3814: }
3815: }
3816: }
3817: unless ($skip) {
3818: my ($ign,$partslist) = split(/\./,$id,2);
3819: push(@unsolved,$partslist);
3820: }
3821: }
3822: }
1.945 raeburn 3823: }
3824: }
3825: }
3826: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 3827: '<td>'.&mt('Transaction [_1]',$version);
3828: if (@unsolved) {
3829: $prevattempts .= '<span class="LC_nobreak"><label>'.
3830: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
3831: &mt('Hide').'</label></span>';
3832: }
3833: $prevattempts .= '</td>';
1.945 raeburn 3834: if (@hidden) {
3835: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3836: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3837: my $hide;
3838: foreach my $id (@hidden) {
3839: if ($key =~ /^\Q$id\E/) {
3840: $hide = 1;
3841: last;
3842: }
3843: }
3844: if ($hide) {
3845: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3846: if (($data eq 'award') || ($data eq 'awarddetail')) {
3847: my $value = &format_previous_attempt_value($key,
3848: $returnhash{$version.':'.$key});
3849: $prevattempts.='<td>'.$value.' </td>';
3850: } else {
3851: $prevattempts.='<td> </td>';
3852: }
3853: } else {
3854: if ($key =~ /\./) {
1.1075.2.91 raeburn 3855: my $value = $returnhash{$version.':'.$key};
3856: if ($key =~ /\.rndseed$/) {
3857: my ($id) = ($key =~ /^(.+)\.rndseed$/);
3858: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
3859: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
3860: }
3861: }
3862: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
3863: ' </td>';
1.945 raeburn 3864: } else {
3865: $prevattempts.='<td> </td>';
3866: }
3867: }
3868: }
3869: } else {
3870: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3871: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 3872: my $value = $returnhash{$version.':'.$key};
3873: if ($key =~ /\.rndseed$/) {
3874: my ($id) = ($key =~ /^(.+)\.rndseed$/);
3875: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
3876: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
3877: }
3878: }
3879: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
3880: ' </td>';
1.945 raeburn 3881: }
3882: }
3883: $prevattempts.=&end_data_table_row();
1.40 ng 3884: }
1.1 albertel 3885: }
1.945 raeburn 3886: my @currhidden = keys(%lasthidden);
1.596 albertel 3887: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3888: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3889: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3890: if (%typeparts) {
3891: my $hidden;
3892: foreach my $id (@currhidden) {
3893: if ($key =~ /^\Q$id\E/) {
3894: $hidden = 1;
3895: last;
3896: }
3897: }
3898: if ($hidden) {
3899: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3900: if (($data eq 'award') || ($data eq 'awarddetail')) {
3901: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3902: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3903: $value = &$gradesub($value);
3904: }
3905: $prevattempts.='<td>'.$value.' </td>';
3906: } else {
3907: $prevattempts.='<td> </td>';
3908: }
3909: } else {
3910: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3911: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3912: $value = &$gradesub($value);
3913: }
3914: $prevattempts.='<td>'.$value.' </td>';
3915: }
3916: } else {
3917: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3918: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3919: $value = &$gradesub($value);
3920: }
3921: $prevattempts.='<td>'.$value.' </td>';
3922: }
1.16 harris41 3923: }
1.596 albertel 3924: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3925: } else {
1.596 albertel 3926: $prevattempts=
3927: &start_data_table().&start_data_table_row().
3928: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3929: &end_data_table_row().&end_data_table();
1.1 albertel 3930: }
3931: } else {
1.596 albertel 3932: $prevattempts=
3933: &start_data_table().&start_data_table_row().
3934: '<td>'.&mt('No data.').'</td>'.
3935: &end_data_table_row().&end_data_table();
1.1 albertel 3936: }
1.10 albertel 3937: }
3938:
1.581 albertel 3939: sub format_previous_attempt_value {
3940: my ($key,$value) = @_;
1.1011 www 3941: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3942: $value = &Apache::lonlocal::locallocaltime($value);
3943: } elsif (ref($value) eq 'ARRAY') {
3944: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3945: } elsif ($key =~ /answerstring$/) {
3946: my %answers = &Apache::lonnet::str2hash($value);
3947: my @anskeys = sort(keys(%answers));
3948: if (@anskeys == 1) {
3949: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3950: if ($answer =~ m{\0}) {
3951: $answer =~ s{\0}{,}g;
1.988 raeburn 3952: }
3953: my $tag_internal_answer_name = 'INTERNAL';
3954: if ($anskeys[0] eq $tag_internal_answer_name) {
3955: $value = $answer;
3956: } else {
3957: $value = $anskeys[0].'='.$answer;
3958: }
3959: } else {
3960: foreach my $ans (@anskeys) {
3961: my $answer = $answers{$ans};
1.1001 raeburn 3962: if ($answer =~ m{\0}) {
3963: $answer =~ s{\0}{,}g;
1.988 raeburn 3964: }
3965: $value .= $ans.'='.$answer.'<br />';;
3966: }
3967: }
1.581 albertel 3968: } else {
3969: $value = &unescape($value);
3970: }
3971: return $value;
3972: }
3973:
3974:
1.107 albertel 3975: sub relative_to_absolute {
3976: my ($url,$output)=@_;
3977: my $parser=HTML::TokeParser->new(\$output);
3978: my $token;
3979: my $thisdir=$url;
3980: my @rlinks=();
3981: while ($token=$parser->get_token) {
3982: if ($token->[0] eq 'S') {
3983: if ($token->[1] eq 'a') {
3984: if ($token->[2]->{'href'}) {
3985: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3986: }
3987: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3988: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3989: } elsif ($token->[1] eq 'base') {
3990: $thisdir=$token->[2]->{'href'};
3991: }
3992: }
3993: }
3994: $thisdir=~s-/[^/]*$--;
1.356 albertel 3995: foreach my $link (@rlinks) {
1.726 raeburn 3996: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3997: ($link=~/^\//) ||
3998: ($link=~/^javascript:/i) ||
3999: ($link=~/^mailto:/i) ||
4000: ($link=~/^\#/)) {
4001: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4002: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4003: }
4004: }
4005: # -------------------------------------------------- Deal with Applet codebases
4006: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4007: return $output;
4008: }
4009:
1.112 bowersj2 4010: =pod
4011:
1.648 raeburn 4012: =item * &get_student_view()
1.112 bowersj2 4013:
4014: show a snapshot of what student was looking at
4015:
4016: =cut
4017:
1.10 albertel 4018: sub get_student_view {
1.186 albertel 4019: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4020: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4021: my (%form);
1.10 albertel 4022: my @elements=('symb','courseid','domain','username');
4023: foreach my $element (@elements) {
1.186 albertel 4024: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4025: }
1.186 albertel 4026: if (defined($moreenv)) {
4027: %form=(%form,%{$moreenv});
4028: }
1.236 albertel 4029: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4030: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4031: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4032: $userview=~s/\<body[^\>]*\>//gi;
4033: $userview=~s/\<\/body\>//gi;
4034: $userview=~s/\<html\>//gi;
4035: $userview=~s/\<\/html\>//gi;
4036: $userview=~s/\<head\>//gi;
4037: $userview=~s/\<\/head\>//gi;
4038: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4039: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4040: if (wantarray) {
4041: return ($userview,$response);
4042: } else {
4043: return $userview;
4044: }
4045: }
4046:
4047: sub get_student_view_with_retries {
4048: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4049:
4050: my $ok = 0; # True if we got a good response.
4051: my $content;
4052: my $response;
4053:
4054: # Try to get the student_view done. within the retries count:
4055:
4056: do {
4057: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4058: $ok = $response->is_success;
4059: if (!$ok) {
4060: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4061: }
4062: $retries--;
4063: } while (!$ok && ($retries > 0));
4064:
4065: if (!$ok) {
4066: $content = ''; # On error return an empty content.
4067: }
1.651 www 4068: if (wantarray) {
4069: return ($content, $response);
4070: } else {
4071: return $content;
4072: }
1.11 albertel 4073: }
4074:
1.112 bowersj2 4075: =pod
4076:
1.648 raeburn 4077: =item * &get_student_answers()
1.112 bowersj2 4078:
4079: show a snapshot of how student was answering problem
4080:
4081: =cut
4082:
1.11 albertel 4083: sub get_student_answers {
1.100 sakharuk 4084: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4085: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4086: my (%moreenv);
1.11 albertel 4087: my @elements=('symb','courseid','domain','username');
4088: foreach my $element (@elements) {
1.186 albertel 4089: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4090: }
1.186 albertel 4091: $moreenv{'grade_target'}='answer';
4092: %moreenv=(%form,%moreenv);
1.497 raeburn 4093: $feedurl = &Apache::lonnet::clutter($feedurl);
4094: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4095: return $userview;
1.1 albertel 4096: }
1.116 albertel 4097:
4098: =pod
4099:
4100: =item * &submlink()
4101:
1.242 albertel 4102: Inputs: $text $uname $udom $symb $target
1.116 albertel 4103:
4104: Returns: A link to grades.pm such as to see the SUBM view of a student
4105:
4106: =cut
4107:
4108: ###############################################
4109: sub submlink {
1.242 albertel 4110: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4111: if (!($uname && $udom)) {
4112: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4113: &Apache::lonnet::whichuser($symb);
1.116 albertel 4114: if (!$symb) { $symb=$cursymb; }
4115: }
1.254 matthew 4116: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4117: $symb=&escape($symb);
1.960 bisitz 4118: if ($target) { $target=" target=\"$target\""; }
4119: return
4120: '<a href="/adm/grades?command=submission'.
4121: '&symb='.$symb.
4122: '&student='.$uname.
4123: '&userdom='.$udom.'"'.
4124: $target.'>'.$text.'</a>';
1.242 albertel 4125: }
4126: ##############################################
4127:
4128: =pod
4129:
4130: =item * &pgrdlink()
4131:
4132: Inputs: $text $uname $udom $symb $target
4133:
4134: Returns: A link to grades.pm such as to see the PGRD view of a student
4135:
4136: =cut
4137:
4138: ###############################################
4139: sub pgrdlink {
4140: my $link=&submlink(@_);
4141: $link=~s/(&command=submission)/$1&showgrading=yes/;
4142: return $link;
4143: }
4144: ##############################################
4145:
4146: =pod
4147:
4148: =item * &pprmlink()
4149:
4150: Inputs: $text $uname $udom $symb $target
4151:
4152: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4153: student and a specific resource
1.242 albertel 4154:
4155: =cut
4156:
4157: ###############################################
4158: sub pprmlink {
4159: my ($text,$uname,$udom,$symb,$target)=@_;
4160: if (!($uname && $udom)) {
4161: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4162: &Apache::lonnet::whichuser($symb);
1.242 albertel 4163: if (!$symb) { $symb=$cursymb; }
4164: }
1.254 matthew 4165: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4166: $symb=&escape($symb);
1.242 albertel 4167: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4168: return '<a href="/adm/parmset?command=set&'.
4169: 'symb='.$symb.'&uname='.$uname.
4170: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4171: }
4172: ##############################################
1.37 matthew 4173:
1.112 bowersj2 4174: =pod
4175:
4176: =back
4177:
4178: =cut
4179:
1.37 matthew 4180: ###############################################
1.51 www 4181:
4182:
4183: sub timehash {
1.687 raeburn 4184: my ($thistime) = @_;
4185: my $timezone = &Apache::lonlocal::gettimezone();
4186: my $dt = DateTime->from_epoch(epoch => $thistime)
4187: ->set_time_zone($timezone);
4188: my $wday = $dt->day_of_week();
4189: if ($wday == 7) { $wday = 0; }
4190: return ( 'second' => $dt->second(),
4191: 'minute' => $dt->minute(),
4192: 'hour' => $dt->hour(),
4193: 'day' => $dt->day_of_month(),
4194: 'month' => $dt->month(),
4195: 'year' => $dt->year(),
4196: 'weekday' => $wday,
4197: 'dayyear' => $dt->day_of_year(),
4198: 'dlsav' => $dt->is_dst() );
1.51 www 4199: }
4200:
1.370 www 4201: sub utc_string {
4202: my ($date)=@_;
1.371 www 4203: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4204: }
4205:
1.51 www 4206: sub maketime {
4207: my %th=@_;
1.687 raeburn 4208: my ($epoch_time,$timezone,$dt);
4209: $timezone = &Apache::lonlocal::gettimezone();
4210: eval {
4211: $dt = DateTime->new( year => $th{'year'},
4212: month => $th{'month'},
4213: day => $th{'day'},
4214: hour => $th{'hour'},
4215: minute => $th{'minute'},
4216: second => $th{'second'},
4217: time_zone => $timezone,
4218: );
4219: };
4220: if (!$@) {
4221: $epoch_time = $dt->epoch;
4222: if ($epoch_time) {
4223: return $epoch_time;
4224: }
4225: }
1.51 www 4226: return POSIX::mktime(
4227: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4228: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4229: }
4230:
4231: #########################################
1.51 www 4232:
4233: sub findallcourses {
1.482 raeburn 4234: my ($roles,$uname,$udom) = @_;
1.355 albertel 4235: my %roles;
4236: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4237: my %courses;
1.51 www 4238: my $now=time;
1.482 raeburn 4239: if (!defined($uname)) {
4240: $uname = $env{'user.name'};
4241: }
4242: if (!defined($udom)) {
4243: $udom = $env{'user.domain'};
4244: }
4245: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4246: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4247: if (!%roles) {
4248: %roles = (
4249: cc => 1,
1.907 raeburn 4250: co => 1,
1.482 raeburn 4251: in => 1,
4252: ep => 1,
4253: ta => 1,
4254: cr => 1,
4255: st => 1,
4256: );
4257: }
4258: foreach my $entry (keys(%roleshash)) {
4259: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4260: if ($trole =~ /^cr/) {
4261: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4262: } else {
4263: next if (!exists($roles{$trole}));
4264: }
4265: if ($tend) {
4266: next if ($tend < $now);
4267: }
4268: if ($tstart) {
4269: next if ($tstart > $now);
4270: }
1.1058 raeburn 4271: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4272: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4273: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4274: if ($secpart eq '') {
4275: ($cnum,$role) = split(/_/,$cnumpart);
4276: $sec = 'none';
1.1058 raeburn 4277: $value .= $cnum.'/';
1.482 raeburn 4278: } else {
4279: $cnum = $cnumpart;
4280: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4281: $value .= $cnum.'/'.$sec;
4282: }
4283: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4284: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4285: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4286: }
4287: } else {
4288: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4289: }
1.482 raeburn 4290: }
4291: } else {
4292: foreach my $key (keys(%env)) {
1.483 albertel 4293: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4294: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4295: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4296: next if ($role eq 'ca' || $role eq 'aa');
4297: next if (%roles && !exists($roles{$role}));
4298: my ($starttime,$endtime)=split(/\./,$env{$key});
4299: my $active=1;
4300: if ($starttime) {
4301: if ($now<$starttime) { $active=0; }
4302: }
4303: if ($endtime) {
4304: if ($now>$endtime) { $active=0; }
4305: }
4306: if ($active) {
1.1058 raeburn 4307: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4308: if ($sec eq '') {
4309: $sec = 'none';
1.1058 raeburn 4310: } else {
4311: $value .= $sec;
4312: }
4313: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4314: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4315: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4316: }
4317: } else {
4318: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4319: }
1.474 raeburn 4320: }
4321: }
1.51 www 4322: }
4323: }
1.474 raeburn 4324: return %courses;
1.51 www 4325: }
1.37 matthew 4326:
1.54 www 4327: ###############################################
1.474 raeburn 4328:
4329: sub blockcheck {
1.1075.2.73 raeburn 4330: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4331:
1.1075.2.73 raeburn 4332: if (defined($udom) && defined($uname)) {
4333: # If uname and udom are for a course, check for blocks in the course.
4334: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4335: my ($startblock,$endblock,$triggerblock) =
4336: &get_blocks($setters,$activity,$udom,$uname,$url);
4337: return ($startblock,$endblock,$triggerblock);
4338: }
4339: } else {
1.490 raeburn 4340: $udom = $env{'user.domain'};
4341: $uname = $env{'user.name'};
4342: }
4343:
1.502 raeburn 4344: my $startblock = 0;
4345: my $endblock = 0;
1.1062 raeburn 4346: my $triggerblock = '';
1.482 raeburn 4347: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4348:
1.490 raeburn 4349: # If uname is for a user, and activity is course-specific, i.e.,
4350: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4351:
1.490 raeburn 4352: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.73 raeburn 4353: $activity eq 'groups' || $activity eq 'printout') &&
4354: ($env{'request.course.id'})) {
1.490 raeburn 4355: foreach my $key (keys(%live_courses)) {
4356: if ($key ne $env{'request.course.id'}) {
4357: delete($live_courses{$key});
4358: }
4359: }
4360: }
4361:
4362: my $otheruser = 0;
4363: my %own_courses;
4364: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4365: # Resource belongs to user other than current user.
4366: $otheruser = 1;
4367: # Gather courses for current user
4368: %own_courses =
4369: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4370: }
4371:
4372: # Gather active course roles - course coordinator, instructor,
4373: # exam proctor, ta, student, or custom role.
1.474 raeburn 4374:
4375: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4376: my ($cdom,$cnum);
4377: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4378: $cdom = $env{'course.'.$course.'.domain'};
4379: $cnum = $env{'course.'.$course.'.num'};
4380: } else {
1.490 raeburn 4381: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4382: }
4383: my $no_ownblock = 0;
4384: my $no_userblock = 0;
1.533 raeburn 4385: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4386: # Check if current user has 'evb' priv for this
4387: if (defined($own_courses{$course})) {
4388: foreach my $sec (keys(%{$own_courses{$course}})) {
4389: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4390: if ($sec ne 'none') {
4391: $checkrole .= '/'.$sec;
4392: }
4393: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4394: $no_ownblock = 1;
4395: last;
4396: }
4397: }
4398: }
4399: # if they have 'evb' priv and are currently not playing student
4400: next if (($no_ownblock) &&
4401: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4402: }
1.474 raeburn 4403: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4404: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4405: if ($sec ne 'none') {
1.482 raeburn 4406: $checkrole .= '/'.$sec;
1.474 raeburn 4407: }
1.490 raeburn 4408: if ($otheruser) {
4409: # Resource belongs to user other than current user.
4410: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4411: my (%allroles,%userroles);
4412: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4413: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4414: my ($trole,$tdom,$tnum,$tsec);
4415: if ($entry =~ /^cr/) {
4416: ($trole,$tdom,$tnum,$tsec) =
4417: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4418: } else {
4419: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4420: }
4421: my ($spec,$area,$trest);
4422: $area = '/'.$tdom.'/'.$tnum;
4423: $trest = $tnum;
4424: if ($tsec ne '') {
4425: $area .= '/'.$tsec;
4426: $trest .= '/'.$tsec;
4427: }
4428: $spec = $trole.'.'.$area;
4429: if ($trole =~ /^cr/) {
4430: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4431: $tdom,$spec,$trest,$area);
4432: } else {
4433: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4434: $tdom,$spec,$trest,$area);
4435: }
4436: }
4437: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4438: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4439: if ($1) {
4440: $no_userblock = 1;
4441: last;
4442: }
1.486 raeburn 4443: }
4444: }
1.490 raeburn 4445: } else {
4446: # Resource belongs to current user
4447: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4448: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4449: $no_ownblock = 1;
4450: last;
4451: }
1.474 raeburn 4452: }
4453: }
4454: # if they have the evb priv and are currently not playing student
1.482 raeburn 4455: next if (($no_ownblock) &&
1.491 albertel 4456: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4457: next if ($no_userblock);
1.474 raeburn 4458:
1.866 kalberla 4459: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4460: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4461:
1.1062 raeburn 4462: my ($start,$end,$trigger) =
4463: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4464: if (($start != 0) &&
4465: (($startblock == 0) || ($startblock > $start))) {
4466: $startblock = $start;
1.1062 raeburn 4467: if ($trigger ne '') {
4468: $triggerblock = $trigger;
4469: }
1.502 raeburn 4470: }
4471: if (($end != 0) &&
4472: (($endblock == 0) || ($endblock < $end))) {
4473: $endblock = $end;
1.1062 raeburn 4474: if ($trigger ne '') {
4475: $triggerblock = $trigger;
4476: }
1.502 raeburn 4477: }
1.490 raeburn 4478: }
1.1062 raeburn 4479: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4480: }
4481:
4482: sub get_blocks {
1.1062 raeburn 4483: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4484: my $startblock = 0;
4485: my $endblock = 0;
1.1062 raeburn 4486: my $triggerblock = '';
1.490 raeburn 4487: my $course = $cdom.'_'.$cnum;
4488: $setters->{$course} = {};
4489: $setters->{$course}{'staff'} = [];
4490: $setters->{$course}{'times'} = [];
1.1062 raeburn 4491: $setters->{$course}{'triggers'} = [];
4492: my (@blockers,%triggered);
4493: my $now = time;
4494: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4495: if ($activity eq 'docs') {
4496: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4497: foreach my $block (@blockers) {
4498: if ($block =~ /^firstaccess____(.+)$/) {
4499: my $item = $1;
4500: my $type = 'map';
4501: my $timersymb = $item;
4502: if ($item eq 'course') {
4503: $type = 'course';
4504: } elsif ($item =~ /___\d+___/) {
4505: $type = 'resource';
4506: } else {
4507: $timersymb = &Apache::lonnet::symbread($item);
4508: }
4509: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4510: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4511: $triggered{$block} = {
4512: start => $start,
4513: end => $end,
4514: type => $type,
4515: };
4516: }
4517: }
4518: } else {
4519: foreach my $block (keys(%commblocks)) {
4520: if ($block =~ m/^(\d+)____(\d+)$/) {
4521: my ($start,$end) = ($1,$2);
4522: if ($start <= time && $end >= time) {
4523: if (ref($commblocks{$block}) eq 'HASH') {
4524: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4525: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4526: unless(grep(/^\Q$block\E$/,@blockers)) {
4527: push(@blockers,$block);
4528: }
4529: }
4530: }
4531: }
4532: }
4533: } elsif ($block =~ /^firstaccess____(.+)$/) {
4534: my $item = $1;
4535: my $timersymb = $item;
4536: my $type = 'map';
4537: if ($item eq 'course') {
4538: $type = 'course';
4539: } elsif ($item =~ /___\d+___/) {
4540: $type = 'resource';
4541: } else {
4542: $timersymb = &Apache::lonnet::symbread($item);
4543: }
4544: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4545: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4546: if ($start && $end) {
4547: if (($start <= time) && ($end >= time)) {
4548: unless (grep(/^\Q$block\E$/,@blockers)) {
4549: push(@blockers,$block);
4550: $triggered{$block} = {
4551: start => $start,
4552: end => $end,
4553: type => $type,
4554: };
4555: }
4556: }
1.490 raeburn 4557: }
1.1062 raeburn 4558: }
4559: }
4560: }
4561: foreach my $blocker (@blockers) {
4562: my ($staff_name,$staff_dom,$title,$blocks) =
4563: &parse_block_record($commblocks{$blocker});
4564: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4565: my ($start,$end,$triggertype);
4566: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4567: ($start,$end) = ($1,$2);
4568: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4569: $start = $triggered{$blocker}{'start'};
4570: $end = $triggered{$blocker}{'end'};
4571: $triggertype = $triggered{$blocker}{'type'};
4572: }
4573: if ($start) {
4574: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4575: if ($triggertype) {
4576: push(@{$$setters{$course}{'triggers'}},$triggertype);
4577: } else {
4578: push(@{$$setters{$course}{'triggers'}},0);
4579: }
4580: if ( ($startblock == 0) || ($startblock > $start) ) {
4581: $startblock = $start;
4582: if ($triggertype) {
4583: $triggerblock = $blocker;
1.474 raeburn 4584: }
4585: }
1.1062 raeburn 4586: if ( ($endblock == 0) || ($endblock < $end) ) {
4587: $endblock = $end;
4588: if ($triggertype) {
4589: $triggerblock = $blocker;
4590: }
4591: }
1.474 raeburn 4592: }
4593: }
1.1062 raeburn 4594: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4595: }
4596:
4597: sub parse_block_record {
4598: my ($record) = @_;
4599: my ($setuname,$setudom,$title,$blocks);
4600: if (ref($record) eq 'HASH') {
4601: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4602: $title = &unescape($record->{'event'});
4603: $blocks = $record->{'blocks'};
4604: } else {
4605: my @data = split(/:/,$record,3);
4606: if (scalar(@data) eq 2) {
4607: $title = $data[1];
4608: ($setuname,$setudom) = split(/@/,$data[0]);
4609: } else {
4610: ($setuname,$setudom,$title) = @data;
4611: }
4612: $blocks = { 'com' => 'on' };
4613: }
4614: return ($setuname,$setudom,$title,$blocks);
4615: }
4616:
1.854 kalberla 4617: sub blocking_status {
1.1075.2.73 raeburn 4618: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4619: my %setters;
1.890 droeschl 4620:
1.1061 raeburn 4621: # check for active blocking
1.1062 raeburn 4622: my ($startblock,$endblock,$triggerblock) =
1.1075.2.73 raeburn 4623: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4624: my $blocked = 0;
4625: if ($startblock && $endblock) {
4626: $blocked = 1;
4627: }
1.890 droeschl 4628:
1.1061 raeburn 4629: # caller just wants to know whether a block is active
4630: if (!wantarray) { return $blocked; }
4631:
4632: # build a link to a popup window containing the details
4633: my $querystring = "?activity=$activity";
4634: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4635: if ($activity eq 'port') {
4636: $querystring .= "&udom=$udom" if $udom;
4637: $querystring .= "&uname=$uname" if $uname;
4638: } elsif ($activity eq 'docs') {
4639: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4640: }
1.1061 raeburn 4641:
4642: my $output .= <<'END_MYBLOCK';
4643: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4644: var options = "width=" + w + ",height=" + h + ",";
4645: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4646: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4647: var newWin = window.open(url, wdwName, options);
4648: newWin.focus();
4649: }
1.890 droeschl 4650: END_MYBLOCK
1.854 kalberla 4651:
1.1061 raeburn 4652: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4653:
1.1061 raeburn 4654: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4655: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 4656: my $class = 'LC_comblock';
1.1062 raeburn 4657: if ($activity eq 'docs') {
4658: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 4659: $class = '';
1.1063 raeburn 4660: } elsif ($activity eq 'printout') {
4661: $text = &mt('Printing Blocked');
1.1062 raeburn 4662: }
1.1061 raeburn 4663: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 4664: <div class='$class'>
1.869 kalberla 4665: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4666: title='$text'>
4667: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4668: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4669: title='$text'>$text</a>
1.867 kalberla 4670: </div>
4671:
4672: END_BLOCK
1.474 raeburn 4673:
1.1061 raeburn 4674: return ($blocked, $output);
1.854 kalberla 4675: }
1.490 raeburn 4676:
1.60 matthew 4677: ###############################################
4678:
1.682 raeburn 4679: sub check_ip_acc {
4680: my ($acc)=@_;
4681: &Apache::lonxml::debug("acc is $acc");
4682: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4683: return 1;
4684: }
4685: my $allowed=0;
4686: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4687:
4688: my $name;
4689: foreach my $pattern (split(',',$acc)) {
4690: $pattern =~ s/^\s*//;
4691: $pattern =~ s/\s*$//;
4692: if ($pattern =~ /\*$/) {
4693: #35.8.*
4694: $pattern=~s/\*//;
4695: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4696: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4697: #35.8.3.[34-56]
4698: my $low=$2;
4699: my $high=$3;
4700: $pattern=$1;
4701: if ($ip =~ /^\Q$pattern\E/) {
4702: my $last=(split(/\./,$ip))[3];
4703: if ($last <=$high && $last >=$low) { $allowed=1; }
4704: }
4705: } elsif ($pattern =~ /^\*/) {
4706: #*.msu.edu
4707: $pattern=~s/\*//;
4708: if (!defined($name)) {
4709: use Socket;
4710: my $netaddr=inet_aton($ip);
4711: ($name)=gethostbyaddr($netaddr,AF_INET);
4712: }
4713: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4714: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4715: #127.0.0.1
4716: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4717: } else {
4718: #some.name.com
4719: if (!defined($name)) {
4720: use Socket;
4721: my $netaddr=inet_aton($ip);
4722: ($name)=gethostbyaddr($netaddr,AF_INET);
4723: }
4724: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4725: }
4726: if ($allowed) { last; }
4727: }
4728: return $allowed;
4729: }
4730:
4731: ###############################################
4732:
1.60 matthew 4733: =pod
4734:
1.112 bowersj2 4735: =head1 Domain Template Functions
4736:
4737: =over 4
4738:
4739: =item * &determinedomain()
1.60 matthew 4740:
4741: Inputs: $domain (usually will be undef)
4742:
1.63 www 4743: Returns: Determines which domain should be used for designs
1.60 matthew 4744:
4745: =cut
1.54 www 4746:
1.60 matthew 4747: ###############################################
1.63 www 4748: sub determinedomain {
4749: my $domain=shift;
1.531 albertel 4750: if (! $domain) {
1.60 matthew 4751: # Determine domain if we have not been given one
1.893 raeburn 4752: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4753: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4754: if ($env{'request.role.domain'}) {
4755: $domain=$env{'request.role.domain'};
1.60 matthew 4756: }
4757: }
1.63 www 4758: return $domain;
4759: }
4760: ###############################################
1.517 raeburn 4761:
1.518 albertel 4762: sub devalidate_domconfig_cache {
4763: my ($udom)=@_;
4764: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4765: }
4766:
4767: # ---------------------- Get domain configuration for a domain
4768: sub get_domainconf {
4769: my ($udom) = @_;
4770: my $cachetime=1800;
4771: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4772: if (defined($cached)) { return %{$result}; }
4773:
4774: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4775: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4776: my (%designhash,%legacy);
1.518 albertel 4777: if (keys(%domconfig) > 0) {
4778: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4779: if (keys(%{$domconfig{'login'}})) {
4780: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4781: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 4782: if (($key eq 'loginvia') || ($key eq 'headtag')) {
4783: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4784: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
4785: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
4786: if ($key eq 'loginvia') {
4787: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4788: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4789: $designhash{$udom.'.login.loginvia'} = $server;
4790: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4791: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4792: } else {
4793: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
4794: }
1.948 raeburn 4795: }
1.1075.2.87 raeburn 4796: } elsif ($key eq 'headtag') {
4797: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
4798: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 4799: }
1.946 raeburn 4800: }
1.1075.2.87 raeburn 4801: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
4802: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
4803: }
1.946 raeburn 4804: }
4805: }
4806: }
4807: } else {
4808: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4809: $designhash{$udom.'.login.'.$key.'_'.$img} =
4810: $domconfig{'login'}{$key}{$img};
4811: }
1.699 raeburn 4812: }
4813: } else {
4814: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4815: }
1.632 raeburn 4816: }
4817: } else {
4818: $legacy{'login'} = 1;
1.518 albertel 4819: }
1.632 raeburn 4820: } else {
4821: $legacy{'login'} = 1;
1.518 albertel 4822: }
4823: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4824: if (keys(%{$domconfig{'rolecolors'}})) {
4825: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4826: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4827: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4828: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4829: }
1.518 albertel 4830: }
4831: }
1.632 raeburn 4832: } else {
4833: $legacy{'rolecolors'} = 1;
1.518 albertel 4834: }
1.632 raeburn 4835: } else {
4836: $legacy{'rolecolors'} = 1;
1.518 albertel 4837: }
1.948 raeburn 4838: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4839: if ($domconfig{'autoenroll'}{'co-owners'}) {
4840: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4841: }
4842: }
1.632 raeburn 4843: if (keys(%legacy) > 0) {
4844: my %legacyhash = &get_legacy_domconf($udom);
4845: foreach my $item (keys(%legacyhash)) {
4846: if ($item =~ /^\Q$udom\E\.login/) {
4847: if ($legacy{'login'}) {
4848: $designhash{$item} = $legacyhash{$item};
4849: }
4850: } else {
4851: if ($legacy{'rolecolors'}) {
4852: $designhash{$item} = $legacyhash{$item};
4853: }
1.518 albertel 4854: }
4855: }
4856: }
1.632 raeburn 4857: } else {
4858: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4859: }
4860: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4861: $cachetime);
4862: return %designhash;
4863: }
4864:
1.632 raeburn 4865: sub get_legacy_domconf {
4866: my ($udom) = @_;
4867: my %legacyhash;
4868: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4869: my $designfile = $designdir.'/'.$udom.'.tab';
4870: if (-e $designfile) {
4871: if ( open (my $fh,"<$designfile") ) {
4872: while (my $line = <$fh>) {
4873: next if ($line =~ /^\#/);
4874: chomp($line);
4875: my ($key,$val)=(split(/\=/,$line));
4876: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4877: }
4878: close($fh);
4879: }
4880: }
1.1026 raeburn 4881: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4882: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4883: }
4884: return %legacyhash;
4885: }
4886:
1.63 www 4887: =pod
4888:
1.112 bowersj2 4889: =item * &domainlogo()
1.63 www 4890:
4891: Inputs: $domain (usually will be undef)
4892:
4893: Returns: A link to a domain logo, if the domain logo exists.
4894: If the domain logo does not exist, a description of the domain.
4895:
4896: =cut
1.112 bowersj2 4897:
1.63 www 4898: ###############################################
4899: sub domainlogo {
1.517 raeburn 4900: my $domain = &determinedomain(shift);
1.518 albertel 4901: my %designhash = &get_domainconf($domain);
1.517 raeburn 4902: # See if there is a logo
4903: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4904: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4905: if ($imgsrc =~ m{^/(adm|res)/}) {
4906: if ($imgsrc =~ m{^/res/}) {
4907: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4908: &Apache::lonnet::repcopy($local_name);
4909: }
4910: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4911: }
4912: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4913: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4914: return &Apache::lonnet::domain($domain,'description');
1.59 www 4915: } else {
1.60 matthew 4916: return '';
1.59 www 4917: }
4918: }
1.63 www 4919: ##############################################
4920:
4921: =pod
4922:
1.112 bowersj2 4923: =item * &designparm()
1.63 www 4924:
4925: Inputs: $which parameter; $domain (usually will be undef)
4926:
4927: Returns: value of designparamter $which
4928:
4929: =cut
1.112 bowersj2 4930:
1.397 albertel 4931:
1.400 albertel 4932: ##############################################
1.397 albertel 4933: sub designparm {
4934: my ($which,$domain)=@_;
4935: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4936: return $env{'environment.color.'.$which};
1.96 www 4937: }
1.63 www 4938: $domain=&determinedomain($domain);
1.1016 raeburn 4939: my %domdesign;
4940: unless ($domain eq 'public') {
4941: %domdesign = &get_domainconf($domain);
4942: }
1.520 raeburn 4943: my $output;
1.517 raeburn 4944: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4945: $output = $domdesign{$domain.'.'.$which};
1.63 www 4946: } else {
1.520 raeburn 4947: $output = $defaultdesign{$which};
4948: }
4949: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4950: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4951: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4952: if ($output =~ m{^/res/}) {
4953: my $local_name = &Apache::lonnet::filelocation('',$output);
4954: &Apache::lonnet::repcopy($local_name);
4955: }
1.520 raeburn 4956: $output = &lonhttpdurl($output);
4957: }
1.63 www 4958: }
1.520 raeburn 4959: return $output;
1.63 www 4960: }
1.59 www 4961:
1.822 bisitz 4962: ##############################################
4963: =pod
4964:
1.832 bisitz 4965: =item * &authorspace()
4966:
1.1028 raeburn 4967: Inputs: $url (usually will be undef).
1.832 bisitz 4968:
1.1075.2.40 raeburn 4969: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4970: directory being viewed (or for which action is being taken).
4971: If $url is provided, and begins /priv/<domain>/<uname>
4972: the path will be that portion of the $context argument.
4973: Otherwise the path will be for the author space of the current
4974: user when the current role is author, or for that of the
4975: co-author/assistant co-author space when the current role
4976: is co-author or assistant co-author.
1.832 bisitz 4977:
4978: =cut
4979:
4980: sub authorspace {
1.1028 raeburn 4981: my ($url) = @_;
4982: if ($url ne '') {
4983: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4984: return $1;
4985: }
4986: }
1.832 bisitz 4987: my $caname = '';
1.1024 www 4988: my $cadom = '';
1.1028 raeburn 4989: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4990: ($cadom,$caname) =
1.832 bisitz 4991: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4992: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4993: $caname = $env{'user.name'};
1.1024 www 4994: $cadom = $env{'user.domain'};
1.832 bisitz 4995: }
1.1028 raeburn 4996: if (($caname ne '') && ($cadom ne '')) {
4997: return "/priv/$cadom/$caname/";
4998: }
4999: return;
1.832 bisitz 5000: }
5001:
5002: ##############################################
5003: =pod
5004:
1.822 bisitz 5005: =item * &head_subbox()
5006:
5007: Inputs: $content (contains HTML code with page functions, etc.)
5008:
5009: Returns: HTML div with $content
5010: To be included in page header
5011:
5012: =cut
5013:
5014: sub head_subbox {
5015: my ($content)=@_;
5016: my $output =
1.993 raeburn 5017: '<div class="LC_head_subbox">'
1.822 bisitz 5018: .$content
5019: .'</div>'
5020: }
5021:
5022: ##############################################
5023: =pod
5024:
5025: =item * &CSTR_pageheader()
5026:
1.1026 raeburn 5027: Input: (optional) filename from which breadcrumb trail is built.
5028: In most cases no input as needed, as $env{'request.filename'}
5029: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5030:
5031: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5032: To be included on Authoring Space pages
1.822 bisitz 5033:
5034: =cut
5035:
5036: sub CSTR_pageheader {
1.1026 raeburn 5037: my ($trailfile) = @_;
5038: if ($trailfile eq '') {
5039: $trailfile = $env{'request.filename'};
5040: }
5041:
5042: # this is for resources; directories have customtitle, and crumbs
5043: # and select recent are created in lonpubdir.pm
5044:
5045: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5046: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5047: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5048: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5049: $formaction =~ s{/+}{/}g;
1.822 bisitz 5050:
5051: my $parentpath = '';
5052: my $lastitem = '';
5053: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5054: $parentpath = $1;
5055: $lastitem = $2;
5056: } else {
5057: $lastitem = $thisdisfn;
5058: }
1.921 bisitz 5059:
5060: my $output =
1.822 bisitz 5061: '<div>'
5062: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5063: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5064: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5065: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5066: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5067:
5068: if ($lastitem) {
5069: $output .=
5070: '<span class="LC_filename">'
5071: .$lastitem
5072: .'</span>';
5073: }
5074: $output .=
5075: '<br />'
1.822 bisitz 5076: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5077: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5078: .'</form>'
5079: .&Apache::lonmenu::constspaceform()
5080: .'</div>';
1.921 bisitz 5081:
5082: return $output;
1.822 bisitz 5083: }
5084:
1.60 matthew 5085: ###############################################
5086: ###############################################
5087:
5088: =pod
5089:
1.112 bowersj2 5090: =back
5091:
1.549 albertel 5092: =head1 HTML Helpers
1.112 bowersj2 5093:
5094: =over 4
5095:
5096: =item * &bodytag()
1.60 matthew 5097:
5098: Returns a uniform header for LON-CAPA web pages.
5099:
5100: Inputs:
5101:
1.112 bowersj2 5102: =over 4
5103:
5104: =item * $title, A title to be displayed on the page.
5105:
5106: =item * $function, the current role (can be undef).
5107:
5108: =item * $addentries, extra parameters for the <body> tag.
5109:
5110: =item * $bodyonly, if defined, only return the <body> tag.
5111:
5112: =item * $domain, if defined, force a given domain.
5113:
5114: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5115: text interface only)
1.60 matthew 5116:
1.814 bisitz 5117: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5118: navigational links
1.317 albertel 5119:
1.338 albertel 5120: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5121:
1.1075.2.12 raeburn 5122: =item * $no_inline_link, if true and in remote mode, don't show the
5123: 'Switch To Inline Menu' link
5124:
1.460 albertel 5125: =item * $args, optional argument valid values are
5126: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5127: inherit_jsmath -> when creating popup window in a page,
5128: should it have jsmath forced on by the
5129: current page
1.460 albertel 5130:
1.1075.2.15 raeburn 5131: =item * $advtoolsref, optional argument, ref to an array containing
5132: inlineremote items to be added in "Functions" menu below
5133: breadcrumbs.
5134:
1.112 bowersj2 5135: =back
5136:
1.60 matthew 5137: Returns: A uniform header for LON-CAPA web pages.
5138: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5139: If $bodyonly is undef or zero, an html string containing a <body> tag and
5140: other decorations will be returned.
5141:
5142: =cut
5143:
1.54 www 5144: sub bodytag {
1.831 bisitz 5145: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5146: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5147:
1.954 raeburn 5148: my $public;
5149: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5150: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5151: $public = 1;
5152: }
1.460 albertel 5153: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5154: my $httphost = $args->{'use_absolute'};
1.339 albertel 5155:
1.183 matthew 5156: $function = &get_users_function() if (!$function);
1.339 albertel 5157: my $img = &designparm($function.'.img',$domain);
5158: my $font = &designparm($function.'.font',$domain);
5159: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5160:
1.803 bisitz 5161: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5162: 'bgcolor' => $pgbg,
1.339 albertel 5163: 'text' => $font,
5164: 'alink' => &designparm($function.'.alink',$domain),
5165: 'vlink' => &designparm($function.'.vlink',$domain),
5166: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5167: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5168:
1.63 www 5169: # role and realm
1.1075.2.68 raeburn 5170: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5171: if ($realm) {
5172: $realm = '/'.$realm;
5173: }
1.378 raeburn 5174: if ($role eq 'ca') {
1.479 albertel 5175: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5176: $realm = &plainname($rname,$rdom);
1.378 raeburn 5177: }
1.55 www 5178: # realm
1.258 albertel 5179: if ($env{'request.course.id'}) {
1.378 raeburn 5180: if ($env{'request.role'} !~ /^cr/) {
5181: $role = &Apache::lonnet::plaintext($role,&course_type());
5182: }
1.898 raeburn 5183: if ($env{'request.course.sec'}) {
5184: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5185: }
1.359 albertel 5186: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5187: } else {
5188: $role = &Apache::lonnet::plaintext($role);
1.54 www 5189: }
1.433 albertel 5190:
1.359 albertel 5191: if (!$realm) { $realm=' '; }
1.330 albertel 5192:
1.438 albertel 5193: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5194:
1.101 www 5195: # construct main body tag
1.359 albertel 5196: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5197: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5198:
1.1075.2.38 raeburn 5199: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5200:
5201: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5202: return $bodytag;
1.1075.2.38 raeburn 5203: }
1.359 albertel 5204:
1.954 raeburn 5205: if ($public) {
1.433 albertel 5206: undef($role);
5207: }
1.359 albertel 5208:
1.762 bisitz 5209: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5210: #
5211: # Extra info if you are the DC
5212: my $dc_info = '';
5213: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5214: $env{'course.'.$env{'request.course.id'}.
5215: '.domain'}.'/'})) {
5216: my $cid = $env{'request.course.id'};
1.917 raeburn 5217: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5218: $dc_info =~ s/\s+$//;
1.359 albertel 5219: }
5220:
1.898 raeburn 5221: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.903 droeschl 5222:
1.1075.2.13 raeburn 5223: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5224:
1.1075.2.38 raeburn 5225:
5226:
1.1075.2.21 raeburn 5227: my $funclist;
5228: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5229: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5230: Apache::lonmenu::serverform();
5231: my $forbodytag;
5232: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5233: $forcereg,$args->{'group'},
5234: $args->{'bread_crumbs'},
5235: $advtoolsref,'',\$forbodytag);
5236: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5237: $funclist = $forbodytag;
5238: }
5239: } else {
1.903 droeschl 5240:
5241: # if ($env{'request.state'} eq 'construct') {
5242: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5243: # }
5244:
1.1075.2.38 raeburn 5245: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5246: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5247:
1.1075.2.38 raeburn 5248: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5249:
1.916 droeschl 5250: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5251: if ($dc_info) {
5252: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5253: }
1.1075.2.38 raeburn 5254: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5255: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5256: return $bodytag;
5257: }
1.894 droeschl 5258:
1.927 raeburn 5259: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5260: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5261: }
1.916 droeschl 5262:
1.1075.2.38 raeburn 5263: $bodytag .= $right;
1.852 droeschl 5264:
1.917 raeburn 5265: if ($dc_info) {
5266: $dc_info = &dc_courseid_toggle($dc_info);
5267: }
5268: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5269:
1.1075.2.61 raeburn 5270: #if directed to not display the secondary menu, don't.
5271: if ($args->{'no_secondary_menu'}) {
5272: return $bodytag;
5273: }
1.903 droeschl 5274: #don't show menus for public users
1.954 raeburn 5275: if (!$public){
1.1075.2.52 raeburn 5276: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5277: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5278: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5279: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5280: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5281: $args->{'bread_crumbs'});
5282: } elsif ($forcereg) {
1.1075.2.22 raeburn 5283: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5284: $args->{'group'});
1.1075.2.15 raeburn 5285: } else {
1.1075.2.21 raeburn 5286: my $forbodytag;
5287: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5288: $forcereg,$args->{'group'},
5289: $args->{'bread_crumbs'},
5290: $advtoolsref,'',\$forbodytag);
5291: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5292: $bodytag .= $forbodytag;
5293: }
1.920 raeburn 5294: }
1.903 droeschl 5295: }else{
5296: # this is to seperate menu from content when there's no secondary
5297: # menu. Especially needed for public accessible ressources.
5298: $bodytag .= '<hr style="clear:both" />';
5299: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5300: }
1.903 droeschl 5301:
1.235 raeburn 5302: return $bodytag;
1.1075.2.12 raeburn 5303: }
5304:
5305: #
5306: # Top frame rendering, Remote is up
5307: #
5308:
5309: my $imgsrc = $img;
5310: if ($img =~ /^\/adm/) {
5311: $imgsrc = &lonhttpdurl($img);
5312: }
5313: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5314:
1.1075.2.60 raeburn 5315: my $help=($no_inline_link?''
5316: :&Apache::loncommon::top_nav_help('Help'));
5317:
1.1075.2.12 raeburn 5318: # Explicit link to get inline menu
5319: my $menu= ($no_inline_link?''
5320: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5321:
5322: if ($dc_info) {
5323: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5324: }
5325:
1.1075.2.38 raeburn 5326: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5327: unless ($public) {
5328: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5329: undef,'LC_menubuttons_link');
5330: }
5331:
1.1075.2.12 raeburn 5332: unless ($env{'form.inhibitmenu'}) {
5333: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5334: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5335: <li>$help</li>
1.1075.2.12 raeburn 5336: <li>$menu</li>
5337: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5338: }
1.1075.2.13 raeburn 5339: if ($env{'request.state'} eq 'construct') {
5340: if (!$public){
5341: if ($env{'request.state'} eq 'construct') {
5342: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5343: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5344: &Apache::lonhtmlcommon::scripttag('','end').
5345: &Apache::lonmenu::innerregister($forcereg,
5346: $args->{'bread_crumbs'});
5347: }
5348: }
5349: }
1.1075.2.21 raeburn 5350: return $bodytag."\n".$funclist;
1.182 matthew 5351: }
5352:
1.917 raeburn 5353: sub dc_courseid_toggle {
5354: my ($dc_info) = @_;
1.980 raeburn 5355: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5356: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5357: &mt('(More ...)').'</a></span>'.
5358: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5359: }
5360:
1.330 albertel 5361: sub make_attr_string {
5362: my ($register,$attr_ref) = @_;
5363:
5364: if ($attr_ref && !ref($attr_ref)) {
5365: die("addentries Must be a hash ref ".
5366: join(':',caller(1))." ".
5367: join(':',caller(0))." ");
5368: }
5369:
5370: if ($register) {
1.339 albertel 5371: my ($on_load,$on_unload);
5372: foreach my $key (keys(%{$attr_ref})) {
5373: if (lc($key) eq 'onload') {
5374: $on_load.=$attr_ref->{$key}.';';
5375: delete($attr_ref->{$key});
5376:
5377: } elsif (lc($key) eq 'onunload') {
5378: $on_unload.=$attr_ref->{$key}.';';
5379: delete($attr_ref->{$key});
5380: }
5381: }
1.1075.2.12 raeburn 5382: if ($env{'environment.remote'} eq 'on') {
5383: $attr_ref->{'onload'} =
5384: &Apache::lonmenu::loadevents(). $on_load;
5385: $attr_ref->{'onunload'}=
5386: &Apache::lonmenu::unloadevents().$on_unload;
5387: } else {
5388: $attr_ref->{'onload'} = $on_load;
5389: $attr_ref->{'onunload'}= $on_unload;
5390: }
1.330 albertel 5391: }
1.339 albertel 5392:
1.330 albertel 5393: my $attr_string;
1.1075.2.56 raeburn 5394: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5395: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5396: }
5397: return $attr_string;
5398: }
5399:
5400:
1.182 matthew 5401: ###############################################
1.251 albertel 5402: ###############################################
5403:
5404: =pod
5405:
5406: =item * &endbodytag()
5407:
5408: Returns a uniform footer for LON-CAPA web pages.
5409:
1.635 raeburn 5410: Inputs: 1 - optional reference to an args hash
5411: If in the hash, key for noredirectlink has a value which evaluates to true,
5412: a 'Continue' link is not displayed if the page contains an
5413: internal redirect in the <head></head> section,
5414: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5415:
5416: =cut
5417:
5418: sub endbodytag {
1.635 raeburn 5419: my ($args) = @_;
1.1075.2.6 raeburn 5420: my $endbodytag;
5421: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5422: $endbodytag='</body>';
5423: }
1.269 albertel 5424: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5425: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5426: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5427: $endbodytag=
5428: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5429: &mt('Continue').'</a>'.
5430: $endbodytag;
5431: }
1.315 albertel 5432: }
1.251 albertel 5433: return $endbodytag;
5434: }
5435:
1.352 albertel 5436: =pod
5437:
5438: =item * &standard_css()
5439:
5440: Returns a style sheet
5441:
5442: Inputs: (all optional)
5443: domain -> force to color decorate a page for a specific
5444: domain
5445: function -> force usage of a specific rolish color scheme
5446: bgcolor -> override the default page bgcolor
5447:
5448: =cut
5449:
1.343 albertel 5450: sub standard_css {
1.345 albertel 5451: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5452: $function = &get_users_function() if (!$function);
5453: my $img = &designparm($function.'.img', $domain);
5454: my $tabbg = &designparm($function.'.tabbg', $domain);
5455: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5456: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5457: #second colour for later usage
1.345 albertel 5458: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5459: my $pgbg_or_bgcolor =
5460: $bgcolor ||
1.352 albertel 5461: &designparm($function.'.pgbg', $domain);
1.382 albertel 5462: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5463: my $alink = &designparm($function.'.alink', $domain);
5464: my $vlink = &designparm($function.'.vlink', $domain);
5465: my $link = &designparm($function.'.link', $domain);
5466:
1.602 albertel 5467: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5468: my $mono = 'monospace';
1.850 bisitz 5469: my $data_table_head = $sidebg;
5470: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5471: my $data_table_dark = '#E0E0E0';
1.470 banghart 5472: my $data_table_darker = '#CCCCCC';
1.349 albertel 5473: my $data_table_highlight = '#FFFF00';
1.352 albertel 5474: my $mail_new = '#FFBB77';
5475: my $mail_new_hover = '#DD9955';
5476: my $mail_read = '#BBBB77';
5477: my $mail_read_hover = '#999944';
5478: my $mail_replied = '#AAAA88';
5479: my $mail_replied_hover = '#888855';
5480: my $mail_other = '#99BBBB';
5481: my $mail_other_hover = '#669999';
1.391 albertel 5482: my $table_header = '#DDDDDD';
1.489 raeburn 5483: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5484: my $lg_border_color = '#C8C8C8';
1.952 onken 5485: my $button_hover = '#BF2317';
1.392 albertel 5486:
1.608 albertel 5487: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5488: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5489: : '0 3px 0 4px';
1.448 albertel 5490:
1.523 albertel 5491:
1.343 albertel 5492: return <<END;
1.947 droeschl 5493:
5494: /* needed for iframe to allow 100% height in FF */
5495: body, html {
5496: margin: 0;
5497: padding: 0 0.5%;
5498: height: 99%; /* to avoid scrollbars */
5499: }
5500:
1.795 www 5501: body {
1.911 bisitz 5502: font-family: $sans;
5503: line-height:130%;
5504: font-size:0.83em;
5505: color:$font;
1.795 www 5506: }
5507:
1.959 onken 5508: a:focus,
5509: a:focus img {
1.795 www 5510: color: red;
5511: }
1.698 harmsja 5512:
1.911 bisitz 5513: form, .inline {
5514: display: inline;
1.795 www 5515: }
1.721 harmsja 5516:
1.795 www 5517: .LC_right {
1.911 bisitz 5518: text-align:right;
1.795 www 5519: }
5520:
5521: .LC_middle {
1.911 bisitz 5522: vertical-align:middle;
1.795 www 5523: }
1.721 harmsja 5524:
1.1075.2.38 raeburn 5525: .LC_floatleft {
5526: float: left;
5527: }
5528:
5529: .LC_floatright {
5530: float: right;
5531: }
5532:
1.911 bisitz 5533: .LC_400Box {
5534: width:400px;
5535: }
1.721 harmsja 5536:
1.947 droeschl 5537: .LC_iframecontainer {
5538: width: 98%;
5539: margin: 0;
5540: position: fixed;
5541: top: 8.5em;
5542: bottom: 0;
5543: }
5544:
5545: .LC_iframecontainer iframe{
5546: border: none;
5547: width: 100%;
5548: height: 100%;
5549: }
5550:
1.778 bisitz 5551: .LC_filename {
5552: font-family: $mono;
5553: white-space:pre;
1.921 bisitz 5554: font-size: 120%;
1.778 bisitz 5555: }
5556:
5557: .LC_fileicon {
5558: border: none;
5559: height: 1.3em;
5560: vertical-align: text-bottom;
5561: margin-right: 0.3em;
5562: text-decoration:none;
5563: }
5564:
1.1008 www 5565: .LC_setting {
5566: text-decoration:underline;
5567: }
5568:
1.350 albertel 5569: .LC_error {
5570: color: red;
5571: }
1.795 www 5572:
1.1075.2.15 raeburn 5573: .LC_warning {
5574: color: darkorange;
5575: }
5576:
1.457 albertel 5577: .LC_diff_removed {
1.733 bisitz 5578: color: red;
1.394 albertel 5579: }
1.532 albertel 5580:
5581: .LC_info,
1.457 albertel 5582: .LC_success,
5583: .LC_diff_added {
1.350 albertel 5584: color: green;
5585: }
1.795 www 5586:
1.802 bisitz 5587: div.LC_confirm_box {
5588: background-color: #FAFAFA;
5589: border: 1px solid $lg_border_color;
5590: margin-right: 0;
5591: padding: 5px;
5592: }
5593:
5594: div.LC_confirm_box .LC_error img,
5595: div.LC_confirm_box .LC_success img {
5596: vertical-align: middle;
5597: }
5598:
1.440 albertel 5599: .LC_icon {
1.771 droeschl 5600: border: none;
1.790 droeschl 5601: vertical-align: middle;
1.771 droeschl 5602: }
5603:
1.543 albertel 5604: .LC_docs_spacer {
5605: width: 25px;
5606: height: 1px;
1.771 droeschl 5607: border: none;
1.543 albertel 5608: }
1.346 albertel 5609:
1.532 albertel 5610: .LC_internal_info {
1.735 bisitz 5611: color: #999999;
1.532 albertel 5612: }
5613:
1.794 www 5614: .LC_discussion {
1.1050 www 5615: background: $data_table_dark;
1.911 bisitz 5616: border: 1px solid black;
5617: margin: 2px;
1.794 www 5618: }
5619:
5620: .LC_disc_action_left {
1.1050 www 5621: background: $sidebg;
1.911 bisitz 5622: text-align: left;
1.1050 www 5623: padding: 4px;
5624: margin: 2px;
1.794 www 5625: }
5626:
5627: .LC_disc_action_right {
1.1050 www 5628: background: $sidebg;
1.911 bisitz 5629: text-align: right;
1.1050 www 5630: padding: 4px;
5631: margin: 2px;
1.794 www 5632: }
5633:
5634: .LC_disc_new_item {
1.911 bisitz 5635: background: white;
5636: border: 2px solid red;
1.1050 www 5637: margin: 4px;
5638: padding: 4px;
1.794 www 5639: }
5640:
5641: .LC_disc_old_item {
1.911 bisitz 5642: background: white;
1.1050 www 5643: margin: 4px;
5644: padding: 4px;
1.794 www 5645: }
5646:
1.458 albertel 5647: table.LC_pastsubmission {
5648: border: 1px solid black;
5649: margin: 2px;
5650: }
5651:
1.924 bisitz 5652: table#LC_menubuttons {
1.345 albertel 5653: width: 100%;
5654: background: $pgbg;
1.392 albertel 5655: border: 2px;
1.402 albertel 5656: border-collapse: separate;
1.803 bisitz 5657: padding: 0;
1.345 albertel 5658: }
1.392 albertel 5659:
1.801 tempelho 5660: table#LC_title_bar a {
5661: color: $fontmenu;
5662: }
1.836 bisitz 5663:
1.807 droeschl 5664: table#LC_title_bar {
1.819 tempelho 5665: clear: both;
1.836 bisitz 5666: display: none;
1.807 droeschl 5667: }
5668:
1.795 www 5669: table#LC_title_bar,
1.933 droeschl 5670: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5671: table#LC_title_bar.LC_with_remote {
1.359 albertel 5672: width: 100%;
1.392 albertel 5673: border-color: $pgbg;
5674: border-style: solid;
5675: border-width: $border;
1.379 albertel 5676: background: $pgbg;
1.801 tempelho 5677: color: $fontmenu;
1.392 albertel 5678: border-collapse: collapse;
1.803 bisitz 5679: padding: 0;
1.819 tempelho 5680: margin: 0;
1.359 albertel 5681: }
1.795 www 5682:
1.933 droeschl 5683: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5684: margin: 0;
5685: padding: 0;
1.933 droeschl 5686: position: relative;
5687: list-style: none;
1.913 droeschl 5688: }
1.933 droeschl 5689: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5690: display: inline;
5691: }
1.933 droeschl 5692:
5693: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5694: padding: 0;
1.933 droeschl 5695: margin: 0;
5696: float: left;
1.913 droeschl 5697: }
1.933 droeschl 5698: .LC_breadcrumb_tools_tools {
5699: padding: 0;
5700: margin: 0;
1.913 droeschl 5701: float: right;
5702: }
5703:
1.359 albertel 5704: table#LC_title_bar td {
5705: background: $tabbg;
5706: }
1.795 www 5707:
1.911 bisitz 5708: table#LC_menubuttons img {
1.803 bisitz 5709: border: none;
1.346 albertel 5710: }
1.795 www 5711:
1.842 droeschl 5712: .LC_breadcrumbs_component {
1.911 bisitz 5713: float: right;
5714: margin: 0 1em;
1.357 albertel 5715: }
1.842 droeschl 5716: .LC_breadcrumbs_component img {
1.911 bisitz 5717: vertical-align: middle;
1.777 tempelho 5718: }
1.795 www 5719:
1.383 albertel 5720: td.LC_table_cell_checkbox {
5721: text-align: center;
5722: }
1.795 www 5723:
5724: .LC_fontsize_small {
1.911 bisitz 5725: font-size: 70%;
1.705 tempelho 5726: }
5727:
1.844 bisitz 5728: #LC_breadcrumbs {
1.911 bisitz 5729: clear:both;
5730: background: $sidebg;
5731: border-bottom: 1px solid $lg_border_color;
5732: line-height: 2.5em;
1.933 droeschl 5733: overflow: hidden;
1.911 bisitz 5734: margin: 0;
5735: padding: 0;
1.995 raeburn 5736: text-align: left;
1.819 tempelho 5737: }
1.862 bisitz 5738:
1.1075.2.16 raeburn 5739: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5740: clear:both;
5741: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5742: border: 1px solid $sidebg;
1.1075.2.16 raeburn 5743: margin: 0 0 10px 0;
1.966 bisitz 5744: padding: 3px;
1.995 raeburn 5745: text-align: left;
1.822 bisitz 5746: }
5747:
1.795 www 5748: .LC_fontsize_medium {
1.911 bisitz 5749: font-size: 85%;
1.705 tempelho 5750: }
5751:
1.795 www 5752: .LC_fontsize_large {
1.911 bisitz 5753: font-size: 120%;
1.705 tempelho 5754: }
5755:
1.346 albertel 5756: .LC_menubuttons_inline_text {
5757: color: $font;
1.698 harmsja 5758: font-size: 90%;
1.701 harmsja 5759: padding-left:3px;
1.346 albertel 5760: }
5761:
1.934 droeschl 5762: .LC_menubuttons_inline_text img{
5763: vertical-align: middle;
5764: }
5765:
1.1051 www 5766: li.LC_menubuttons_inline_text img {
1.951 onken 5767: cursor:pointer;
1.1002 droeschl 5768: text-decoration: none;
1.951 onken 5769: }
5770:
1.526 www 5771: .LC_menubuttons_link {
5772: text-decoration: none;
5773: }
1.795 www 5774:
1.522 albertel 5775: .LC_menubuttons_category {
1.521 www 5776: color: $font;
1.526 www 5777: background: $pgbg;
1.521 www 5778: font-size: larger;
5779: font-weight: bold;
5780: }
5781:
1.346 albertel 5782: td.LC_menubuttons_text {
1.911 bisitz 5783: color: $font;
1.346 albertel 5784: }
1.706 harmsja 5785:
1.346 albertel 5786: .LC_current_location {
5787: background: $tabbg;
5788: }
1.795 www 5789:
1.938 bisitz 5790: table.LC_data_table {
1.347 albertel 5791: border: 1px solid #000000;
1.402 albertel 5792: border-collapse: separate;
1.426 albertel 5793: border-spacing: 1px;
1.610 albertel 5794: background: $pgbg;
1.347 albertel 5795: }
1.795 www 5796:
1.422 albertel 5797: .LC_data_table_dense {
5798: font-size: small;
5799: }
1.795 www 5800:
1.507 raeburn 5801: table.LC_nested_outer {
5802: border: 1px solid #000000;
1.589 raeburn 5803: border-collapse: collapse;
1.803 bisitz 5804: border-spacing: 0;
1.507 raeburn 5805: width: 100%;
5806: }
1.795 www 5807:
1.879 raeburn 5808: table.LC_innerpickbox,
1.507 raeburn 5809: table.LC_nested {
1.803 bisitz 5810: border: none;
1.589 raeburn 5811: border-collapse: collapse;
1.803 bisitz 5812: border-spacing: 0;
1.507 raeburn 5813: width: 100%;
5814: }
1.795 www 5815:
1.911 bisitz 5816: table.LC_data_table tr th,
5817: table.LC_calendar tr th,
1.879 raeburn 5818: table.LC_prior_tries tr th,
5819: table.LC_innerpickbox tr th {
1.349 albertel 5820: font-weight: bold;
5821: background-color: $data_table_head;
1.801 tempelho 5822: color:$fontmenu;
1.701 harmsja 5823: font-size:90%;
1.347 albertel 5824: }
1.795 www 5825:
1.879 raeburn 5826: table.LC_innerpickbox tr th,
5827: table.LC_innerpickbox tr td {
5828: vertical-align: top;
5829: }
5830:
1.711 raeburn 5831: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5832: background-color: #CCCCCC;
1.711 raeburn 5833: font-weight: bold;
5834: text-align: left;
5835: }
1.795 www 5836:
1.912 bisitz 5837: table.LC_data_table tr.LC_odd_row > td {
5838: background-color: $data_table_light;
5839: padding: 2px;
5840: vertical-align: top;
5841: }
5842:
1.809 bisitz 5843: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5844: background-color: $data_table_light;
1.912 bisitz 5845: vertical-align: top;
5846: }
5847:
5848: table.LC_data_table tr.LC_even_row > td {
5849: background-color: $data_table_dark;
1.425 albertel 5850: padding: 2px;
1.900 bisitz 5851: vertical-align: top;
1.347 albertel 5852: }
1.795 www 5853:
1.809 bisitz 5854: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5855: background-color: $data_table_dark;
1.900 bisitz 5856: vertical-align: top;
1.347 albertel 5857: }
1.795 www 5858:
1.425 albertel 5859: table.LC_data_table tr.LC_data_table_highlight td {
5860: background-color: $data_table_darker;
5861: }
1.795 www 5862:
1.639 raeburn 5863: table.LC_data_table tr td.LC_leftcol_header {
5864: background-color: $data_table_head;
5865: font-weight: bold;
5866: }
1.795 www 5867:
1.451 albertel 5868: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5869: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5870: font-weight: bold;
5871: font-style: italic;
5872: text-align: center;
5873: padding: 8px;
1.347 albertel 5874: }
1.795 www 5875:
1.1075.2.30 raeburn 5876: table.LC_data_table tr.LC_empty_row td,
5877: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5878: background-color: $sidebg;
5879: }
5880:
5881: table.LC_nested tr.LC_empty_row td {
5882: background-color: #FFFFFF;
5883: }
5884:
1.890 droeschl 5885: table.LC_caption {
5886: }
5887:
1.507 raeburn 5888: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5889: padding: 4ex
5890: }
1.795 www 5891:
1.507 raeburn 5892: table.LC_nested_outer tr th {
5893: font-weight: bold;
1.801 tempelho 5894: color:$fontmenu;
1.507 raeburn 5895: background-color: $data_table_head;
1.701 harmsja 5896: font-size: small;
1.507 raeburn 5897: border-bottom: 1px solid #000000;
5898: }
1.795 www 5899:
1.507 raeburn 5900: table.LC_nested_outer tr td.LC_subheader {
5901: background-color: $data_table_head;
5902: font-weight: bold;
5903: font-size: small;
5904: border-bottom: 1px solid #000000;
5905: text-align: right;
1.451 albertel 5906: }
1.795 www 5907:
1.507 raeburn 5908: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5909: background-color: #CCCCCC;
1.451 albertel 5910: font-weight: bold;
5911: font-size: small;
1.507 raeburn 5912: text-align: center;
5913: }
1.795 www 5914:
1.589 raeburn 5915: table.LC_nested tr.LC_info_row td.LC_left_item,
5916: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5917: text-align: left;
1.451 albertel 5918: }
1.795 www 5919:
1.507 raeburn 5920: table.LC_nested td {
1.735 bisitz 5921: background-color: #FFFFFF;
1.451 albertel 5922: font-size: small;
1.507 raeburn 5923: }
1.795 www 5924:
1.507 raeburn 5925: table.LC_nested_outer tr th.LC_right_item,
5926: table.LC_nested tr.LC_info_row td.LC_right_item,
5927: table.LC_nested tr.LC_odd_row td.LC_right_item,
5928: table.LC_nested tr td.LC_right_item {
1.451 albertel 5929: text-align: right;
5930: }
5931:
1.507 raeburn 5932: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5933: background-color: #EEEEEE;
1.451 albertel 5934: }
5935:
1.473 raeburn 5936: table.LC_createuser {
5937: }
5938:
5939: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5940: font-size: small;
1.473 raeburn 5941: }
5942:
5943: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5944: background-color: #CCCCCC;
1.473 raeburn 5945: font-weight: bold;
5946: text-align: center;
5947: }
5948:
1.349 albertel 5949: table.LC_calendar {
5950: border: 1px solid #000000;
5951: border-collapse: collapse;
1.917 raeburn 5952: width: 98%;
1.349 albertel 5953: }
1.795 www 5954:
1.349 albertel 5955: table.LC_calendar_pickdate {
5956: font-size: xx-small;
5957: }
1.795 www 5958:
1.349 albertel 5959: table.LC_calendar tr td {
5960: border: 1px solid #000000;
5961: vertical-align: top;
1.917 raeburn 5962: width: 14%;
1.349 albertel 5963: }
1.795 www 5964:
1.349 albertel 5965: table.LC_calendar tr td.LC_calendar_day_empty {
5966: background-color: $data_table_dark;
5967: }
1.795 www 5968:
1.779 bisitz 5969: table.LC_calendar tr td.LC_calendar_day_current {
5970: background-color: $data_table_highlight;
1.777 tempelho 5971: }
1.795 www 5972:
1.938 bisitz 5973: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5974: background-color: $mail_new;
5975: }
1.795 www 5976:
1.938 bisitz 5977: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5978: background-color: $mail_new_hover;
5979: }
1.795 www 5980:
1.938 bisitz 5981: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5982: background-color: $mail_read;
5983: }
1.795 www 5984:
1.938 bisitz 5985: /*
5986: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5987: background-color: $mail_read_hover;
5988: }
1.938 bisitz 5989: */
1.795 www 5990:
1.938 bisitz 5991: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5992: background-color: $mail_replied;
5993: }
1.795 www 5994:
1.938 bisitz 5995: /*
5996: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5997: background-color: $mail_replied_hover;
5998: }
1.938 bisitz 5999: */
1.795 www 6000:
1.938 bisitz 6001: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6002: background-color: $mail_other;
6003: }
1.795 www 6004:
1.938 bisitz 6005: /*
6006: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6007: background-color: $mail_other_hover;
6008: }
1.938 bisitz 6009: */
1.494 raeburn 6010:
1.777 tempelho 6011: table.LC_data_table tr > td.LC_browser_file,
6012: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6013: background: #AAEE77;
1.389 albertel 6014: }
1.795 www 6015:
1.777 tempelho 6016: table.LC_data_table tr > td.LC_browser_file_locked,
6017: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6018: background: #FFAA99;
1.387 albertel 6019: }
1.795 www 6020:
1.777 tempelho 6021: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6022: background: #888888;
1.779 bisitz 6023: }
1.795 www 6024:
1.777 tempelho 6025: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6026: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6027: background: #F8F866;
1.777 tempelho 6028: }
1.795 www 6029:
1.696 bisitz 6030: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6031: background: #E0E8FF;
1.387 albertel 6032: }
1.696 bisitz 6033:
1.707 bisitz 6034: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6035: /* background: #77FF77; */
1.707 bisitz 6036: }
1.795 www 6037:
1.707 bisitz 6038: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6039: border-right: 8px solid #FFFF77;
1.707 bisitz 6040: }
1.795 www 6041:
1.707 bisitz 6042: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6043: border-right: 8px solid #FFAA77;
1.707 bisitz 6044: }
1.795 www 6045:
1.707 bisitz 6046: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6047: border-right: 8px solid #FF7777;
1.707 bisitz 6048: }
1.795 www 6049:
1.707 bisitz 6050: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6051: border-right: 8px solid #AAFF77;
1.707 bisitz 6052: }
1.795 www 6053:
1.707 bisitz 6054: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6055: border-right: 8px solid #11CC55;
1.707 bisitz 6056: }
6057:
1.388 albertel 6058: span.LC_current_location {
1.701 harmsja 6059: font-size:larger;
1.388 albertel 6060: background: $pgbg;
6061: }
1.387 albertel 6062:
1.1029 www 6063: span.LC_current_nav_location {
6064: font-weight:bold;
6065: background: $sidebg;
6066: }
6067:
1.395 albertel 6068: span.LC_parm_menu_item {
6069: font-size: larger;
6070: }
1.795 www 6071:
1.395 albertel 6072: span.LC_parm_scope_all {
6073: color: red;
6074: }
1.795 www 6075:
1.395 albertel 6076: span.LC_parm_scope_folder {
6077: color: green;
6078: }
1.795 www 6079:
1.395 albertel 6080: span.LC_parm_scope_resource {
6081: color: orange;
6082: }
1.795 www 6083:
1.395 albertel 6084: span.LC_parm_part {
6085: color: blue;
6086: }
1.795 www 6087:
1.911 bisitz 6088: span.LC_parm_folder,
6089: span.LC_parm_symb {
1.395 albertel 6090: font-size: x-small;
6091: font-family: $mono;
6092: color: #AAAAAA;
6093: }
6094:
1.977 bisitz 6095: ul.LC_parm_parmlist li {
6096: display: inline-block;
6097: padding: 0.3em 0.8em;
6098: vertical-align: top;
6099: width: 150px;
6100: border-top:1px solid $lg_border_color;
6101: }
6102:
1.795 www 6103: td.LC_parm_overview_level_menu,
6104: td.LC_parm_overview_map_menu,
6105: td.LC_parm_overview_parm_selectors,
6106: td.LC_parm_overview_restrictions {
1.396 albertel 6107: border: 1px solid black;
6108: border-collapse: collapse;
6109: }
1.795 www 6110:
1.396 albertel 6111: table.LC_parm_overview_restrictions td {
6112: border-width: 1px 4px 1px 4px;
6113: border-style: solid;
6114: border-color: $pgbg;
6115: text-align: center;
6116: }
1.795 www 6117:
1.396 albertel 6118: table.LC_parm_overview_restrictions th {
6119: background: $tabbg;
6120: border-width: 1px 4px 1px 4px;
6121: border-style: solid;
6122: border-color: $pgbg;
6123: }
1.795 www 6124:
1.398 albertel 6125: table#LC_helpmenu {
1.803 bisitz 6126: border: none;
1.398 albertel 6127: height: 55px;
1.803 bisitz 6128: border-spacing: 0;
1.398 albertel 6129: }
6130:
6131: table#LC_helpmenu fieldset legend {
6132: font-size: larger;
6133: }
1.795 www 6134:
1.397 albertel 6135: table#LC_helpmenu_links {
6136: width: 100%;
6137: border: 1px solid black;
6138: background: $pgbg;
1.803 bisitz 6139: padding: 0;
1.397 albertel 6140: border-spacing: 1px;
6141: }
1.795 www 6142:
1.397 albertel 6143: table#LC_helpmenu_links tr td {
6144: padding: 1px;
6145: background: $tabbg;
1.399 albertel 6146: text-align: center;
6147: font-weight: bold;
1.397 albertel 6148: }
1.396 albertel 6149:
1.795 www 6150: table#LC_helpmenu_links a:link,
6151: table#LC_helpmenu_links a:visited,
1.397 albertel 6152: table#LC_helpmenu_links a:active {
6153: text-decoration: none;
6154: color: $font;
6155: }
1.795 www 6156:
1.397 albertel 6157: table#LC_helpmenu_links a:hover {
6158: text-decoration: underline;
6159: color: $vlink;
6160: }
1.396 albertel 6161:
1.417 albertel 6162: .LC_chrt_popup_exists {
6163: border: 1px solid #339933;
6164: margin: -1px;
6165: }
1.795 www 6166:
1.417 albertel 6167: .LC_chrt_popup_up {
6168: border: 1px solid yellow;
6169: margin: -1px;
6170: }
1.795 www 6171:
1.417 albertel 6172: .LC_chrt_popup {
6173: border: 1px solid #8888FF;
6174: background: #CCCCFF;
6175: }
1.795 www 6176:
1.421 albertel 6177: table.LC_pick_box {
6178: border-collapse: separate;
6179: background: white;
6180: border: 1px solid black;
6181: border-spacing: 1px;
6182: }
1.795 www 6183:
1.421 albertel 6184: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6185: background: $sidebg;
1.421 albertel 6186: font-weight: bold;
1.900 bisitz 6187: text-align: left;
1.740 bisitz 6188: vertical-align: top;
1.421 albertel 6189: width: 184px;
6190: padding: 8px;
6191: }
1.795 www 6192:
1.579 raeburn 6193: table.LC_pick_box td.LC_pick_box_value {
6194: text-align: left;
6195: padding: 8px;
6196: }
1.795 www 6197:
1.579 raeburn 6198: table.LC_pick_box td.LC_pick_box_select {
6199: text-align: left;
6200: padding: 8px;
6201: }
1.795 www 6202:
1.424 albertel 6203: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6204: padding: 0;
1.421 albertel 6205: height: 1px;
6206: background: black;
6207: }
1.795 www 6208:
1.421 albertel 6209: table.LC_pick_box td.LC_pick_box_submit {
6210: text-align: right;
6211: }
1.795 www 6212:
1.579 raeburn 6213: table.LC_pick_box td.LC_evenrow_value {
6214: text-align: left;
6215: padding: 8px;
6216: background-color: $data_table_light;
6217: }
1.795 www 6218:
1.579 raeburn 6219: table.LC_pick_box td.LC_oddrow_value {
6220: text-align: left;
6221: padding: 8px;
6222: background-color: $data_table_light;
6223: }
1.795 www 6224:
1.579 raeburn 6225: span.LC_helpform_receipt_cat {
6226: font-weight: bold;
6227: }
1.795 www 6228:
1.424 albertel 6229: table.LC_group_priv_box {
6230: background: white;
6231: border: 1px solid black;
6232: border-spacing: 1px;
6233: }
1.795 www 6234:
1.424 albertel 6235: table.LC_group_priv_box td.LC_pick_box_title {
6236: background: $tabbg;
6237: font-weight: bold;
6238: text-align: right;
6239: width: 184px;
6240: }
1.795 www 6241:
1.424 albertel 6242: table.LC_group_priv_box td.LC_groups_fixed {
6243: background: $data_table_light;
6244: text-align: center;
6245: }
1.795 www 6246:
1.424 albertel 6247: table.LC_group_priv_box td.LC_groups_optional {
6248: background: $data_table_dark;
6249: text-align: center;
6250: }
1.795 www 6251:
1.424 albertel 6252: table.LC_group_priv_box td.LC_groups_functionality {
6253: background: $data_table_darker;
6254: text-align: center;
6255: font-weight: bold;
6256: }
1.795 www 6257:
1.424 albertel 6258: table.LC_group_priv td {
6259: text-align: left;
1.803 bisitz 6260: padding: 0;
1.424 albertel 6261: }
6262:
6263: .LC_navbuttons {
6264: margin: 2ex 0ex 2ex 0ex;
6265: }
1.795 www 6266:
1.423 albertel 6267: .LC_topic_bar {
6268: font-weight: bold;
6269: background: $tabbg;
1.918 wenzelju 6270: margin: 1em 0em 1em 2em;
1.805 bisitz 6271: padding: 3px;
1.918 wenzelju 6272: font-size: 1.2em;
1.423 albertel 6273: }
1.795 www 6274:
1.423 albertel 6275: .LC_topic_bar span {
1.918 wenzelju 6276: left: 0.5em;
6277: position: absolute;
1.423 albertel 6278: vertical-align: middle;
1.918 wenzelju 6279: font-size: 1.2em;
1.423 albertel 6280: }
1.795 www 6281:
1.423 albertel 6282: table.LC_course_group_status {
6283: margin: 20px;
6284: }
1.795 www 6285:
1.423 albertel 6286: table.LC_status_selector td {
6287: vertical-align: top;
6288: text-align: center;
1.424 albertel 6289: padding: 4px;
6290: }
1.795 www 6291:
1.599 albertel 6292: div.LC_feedback_link {
1.616 albertel 6293: clear: both;
1.829 kalberla 6294: background: $sidebg;
1.779 bisitz 6295: width: 100%;
1.829 kalberla 6296: padding-bottom: 10px;
6297: border: 1px $tabbg solid;
1.833 kalberla 6298: height: 22px;
6299: line-height: 22px;
6300: padding-top: 5px;
6301: }
6302:
6303: div.LC_feedback_link img {
6304: height: 22px;
1.867 kalberla 6305: vertical-align:middle;
1.829 kalberla 6306: }
6307:
1.911 bisitz 6308: div.LC_feedback_link a {
1.829 kalberla 6309: text-decoration: none;
1.489 raeburn 6310: }
1.795 www 6311:
1.867 kalberla 6312: div.LC_comblock {
1.911 bisitz 6313: display:inline;
1.867 kalberla 6314: color:$font;
6315: font-size:90%;
6316: }
6317:
6318: div.LC_feedback_link div.LC_comblock {
6319: padding-left:5px;
6320: }
6321:
6322: div.LC_feedback_link div.LC_comblock a {
6323: color:$font;
6324: }
6325:
1.489 raeburn 6326: span.LC_feedback_link {
1.858 bisitz 6327: /* background: $feedback_link_bg; */
1.599 albertel 6328: font-size: larger;
6329: }
1.795 www 6330:
1.599 albertel 6331: span.LC_message_link {
1.858 bisitz 6332: /* background: $feedback_link_bg; */
1.599 albertel 6333: font-size: larger;
6334: position: absolute;
6335: right: 1em;
1.489 raeburn 6336: }
1.421 albertel 6337:
1.515 albertel 6338: table.LC_prior_tries {
1.524 albertel 6339: border: 1px solid #000000;
6340: border-collapse: separate;
6341: border-spacing: 1px;
1.515 albertel 6342: }
1.523 albertel 6343:
1.515 albertel 6344: table.LC_prior_tries td {
1.524 albertel 6345: padding: 2px;
1.515 albertel 6346: }
1.523 albertel 6347:
6348: .LC_answer_correct {
1.795 www 6349: background: lightgreen;
6350: color: darkgreen;
6351: padding: 6px;
1.523 albertel 6352: }
1.795 www 6353:
1.523 albertel 6354: .LC_answer_charged_try {
1.797 www 6355: background: #FFAAAA;
1.795 www 6356: color: darkred;
6357: padding: 6px;
1.523 albertel 6358: }
1.795 www 6359:
1.779 bisitz 6360: .LC_answer_not_charged_try,
1.523 albertel 6361: .LC_answer_no_grade,
6362: .LC_answer_late {
1.795 www 6363: background: lightyellow;
1.523 albertel 6364: color: black;
1.795 www 6365: padding: 6px;
1.523 albertel 6366: }
1.795 www 6367:
1.523 albertel 6368: .LC_answer_previous {
1.795 www 6369: background: lightblue;
6370: color: darkblue;
6371: padding: 6px;
1.523 albertel 6372: }
1.795 www 6373:
1.779 bisitz 6374: .LC_answer_no_message {
1.777 tempelho 6375: background: #FFFFFF;
6376: color: black;
1.795 www 6377: padding: 6px;
1.779 bisitz 6378: }
1.795 www 6379:
1.779 bisitz 6380: .LC_answer_unknown {
6381: background: orange;
6382: color: black;
1.795 www 6383: padding: 6px;
1.777 tempelho 6384: }
1.795 www 6385:
1.529 albertel 6386: span.LC_prior_numerical,
6387: span.LC_prior_string,
6388: span.LC_prior_custom,
6389: span.LC_prior_reaction,
6390: span.LC_prior_math {
1.925 bisitz 6391: font-family: $mono;
1.523 albertel 6392: white-space: pre;
6393: }
6394:
1.525 albertel 6395: span.LC_prior_string {
1.925 bisitz 6396: font-family: $mono;
1.525 albertel 6397: white-space: pre;
6398: }
6399:
1.523 albertel 6400: table.LC_prior_option {
6401: width: 100%;
6402: border-collapse: collapse;
6403: }
1.795 www 6404:
1.911 bisitz 6405: table.LC_prior_rank,
1.795 www 6406: table.LC_prior_match {
1.528 albertel 6407: border-collapse: collapse;
6408: }
1.795 www 6409:
1.528 albertel 6410: table.LC_prior_option tr td,
6411: table.LC_prior_rank tr td,
6412: table.LC_prior_match tr td {
1.524 albertel 6413: border: 1px solid #000000;
1.515 albertel 6414: }
6415:
1.855 bisitz 6416: .LC_nobreak {
1.544 albertel 6417: white-space: nowrap;
1.519 raeburn 6418: }
6419:
1.576 raeburn 6420: span.LC_cusr_emph {
6421: font-style: italic;
6422: }
6423:
1.633 raeburn 6424: span.LC_cusr_subheading {
6425: font-weight: normal;
6426: font-size: 85%;
6427: }
6428:
1.861 bisitz 6429: div.LC_docs_entry_move {
1.859 bisitz 6430: border: 1px solid #BBBBBB;
1.545 albertel 6431: background: #DDDDDD;
1.861 bisitz 6432: width: 22px;
1.859 bisitz 6433: padding: 1px;
6434: margin: 0;
1.545 albertel 6435: }
6436:
1.861 bisitz 6437: table.LC_data_table tr > td.LC_docs_entry_commands,
6438: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6439: font-size: x-small;
6440: }
1.795 www 6441:
1.861 bisitz 6442: .LC_docs_entry_parameter {
6443: white-space: nowrap;
6444: }
6445:
1.544 albertel 6446: .LC_docs_copy {
1.545 albertel 6447: color: #000099;
1.544 albertel 6448: }
1.795 www 6449:
1.544 albertel 6450: .LC_docs_cut {
1.545 albertel 6451: color: #550044;
1.544 albertel 6452: }
1.795 www 6453:
1.544 albertel 6454: .LC_docs_rename {
1.545 albertel 6455: color: #009900;
1.544 albertel 6456: }
1.795 www 6457:
1.544 albertel 6458: .LC_docs_remove {
1.545 albertel 6459: color: #990000;
6460: }
6461:
1.547 albertel 6462: .LC_docs_reinit_warn,
6463: .LC_docs_ext_edit {
6464: font-size: x-small;
6465: }
6466:
1.545 albertel 6467: table.LC_docs_adddocs td,
6468: table.LC_docs_adddocs th {
6469: border: 1px solid #BBBBBB;
6470: padding: 4px;
6471: background: #DDDDDD;
1.543 albertel 6472: }
6473:
1.584 albertel 6474: table.LC_sty_begin {
6475: background: #BBFFBB;
6476: }
1.795 www 6477:
1.584 albertel 6478: table.LC_sty_end {
6479: background: #FFBBBB;
6480: }
6481:
1.589 raeburn 6482: table.LC_double_column {
1.803 bisitz 6483: border-width: 0;
1.589 raeburn 6484: border-collapse: collapse;
6485: width: 100%;
6486: padding: 2px;
6487: }
6488:
6489: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6490: top: 2px;
1.589 raeburn 6491: left: 2px;
6492: width: 47%;
6493: vertical-align: top;
6494: }
6495:
6496: table.LC_double_column tr td.LC_right_col {
6497: top: 2px;
1.779 bisitz 6498: right: 2px;
1.589 raeburn 6499: width: 47%;
6500: vertical-align: top;
6501: }
6502:
1.591 raeburn 6503: div.LC_left_float {
6504: float: left;
6505: padding-right: 5%;
1.597 albertel 6506: padding-bottom: 4px;
1.591 raeburn 6507: }
6508:
6509: div.LC_clear_float_header {
1.597 albertel 6510: padding-bottom: 2px;
1.591 raeburn 6511: }
6512:
6513: div.LC_clear_float_footer {
1.597 albertel 6514: padding-top: 10px;
1.591 raeburn 6515: clear: both;
6516: }
6517:
1.597 albertel 6518: div.LC_grade_show_user {
1.941 bisitz 6519: /* border-left: 5px solid $sidebg; */
6520: border-top: 5px solid #000000;
6521: margin: 50px 0 0 0;
1.936 bisitz 6522: padding: 15px 0 5px 10px;
1.597 albertel 6523: }
1.795 www 6524:
1.936 bisitz 6525: div.LC_grade_show_user_odd_row {
1.941 bisitz 6526: /* border-left: 5px solid #000000; */
6527: }
6528:
6529: div.LC_grade_show_user div.LC_Box {
6530: margin-right: 50px;
1.597 albertel 6531: }
6532:
6533: div.LC_grade_submissions,
6534: div.LC_grade_message_center,
1.936 bisitz 6535: div.LC_grade_info_links {
1.597 albertel 6536: margin: 5px;
6537: width: 99%;
6538: background: #FFFFFF;
6539: }
1.795 www 6540:
1.597 albertel 6541: div.LC_grade_submissions_header,
1.936 bisitz 6542: div.LC_grade_message_center_header {
1.705 tempelho 6543: font-weight: bold;
6544: font-size: large;
1.597 albertel 6545: }
1.795 www 6546:
1.597 albertel 6547: div.LC_grade_submissions_body,
1.936 bisitz 6548: div.LC_grade_message_center_body {
1.597 albertel 6549: border: 1px solid black;
6550: width: 99%;
6551: background: #FFFFFF;
6552: }
1.795 www 6553:
1.613 albertel 6554: table.LC_scantron_action {
6555: width: 100%;
6556: }
1.795 www 6557:
1.613 albertel 6558: table.LC_scantron_action tr th {
1.698 harmsja 6559: font-weight:bold;
6560: font-style:normal;
1.613 albertel 6561: }
1.795 www 6562:
1.779 bisitz 6563: .LC_edit_problem_header,
1.614 albertel 6564: div.LC_edit_problem_footer {
1.705 tempelho 6565: font-weight: normal;
6566: font-size: medium;
1.602 albertel 6567: margin: 2px;
1.1060 bisitz 6568: background-color: $sidebg;
1.600 albertel 6569: }
1.795 www 6570:
1.600 albertel 6571: div.LC_edit_problem_header,
1.602 albertel 6572: div.LC_edit_problem_header div,
1.614 albertel 6573: div.LC_edit_problem_footer,
6574: div.LC_edit_problem_footer div,
1.602 albertel 6575: div.LC_edit_problem_editxml_header,
6576: div.LC_edit_problem_editxml_header div {
1.600 albertel 6577: margin-top: 5px;
6578: }
1.795 www 6579:
1.600 albertel 6580: div.LC_edit_problem_header_title {
1.705 tempelho 6581: font-weight: bold;
6582: font-size: larger;
1.602 albertel 6583: background: $tabbg;
6584: padding: 3px;
1.1060 bisitz 6585: margin: 0 0 5px 0;
1.602 albertel 6586: }
1.795 www 6587:
1.602 albertel 6588: table.LC_edit_problem_header_title {
6589: width: 100%;
1.600 albertel 6590: background: $tabbg;
1.602 albertel 6591: }
6592:
6593: div.LC_edit_problem_discards {
6594: float: left;
6595: padding-bottom: 5px;
6596: }
1.795 www 6597:
1.602 albertel 6598: div.LC_edit_problem_saves {
6599: float: right;
6600: padding-bottom: 5px;
1.600 albertel 6601: }
1.795 www 6602:
1.1075.2.34 raeburn 6603: .LC_edit_opt {
6604: padding-left: 1em;
6605: white-space: nowrap;
6606: }
6607:
1.1075.2.57 raeburn 6608: .LC_edit_problem_latexhelper{
6609: text-align: right;
6610: }
6611:
6612: #LC_edit_problem_colorful div{
6613: margin-left: 40px;
6614: }
6615:
1.911 bisitz 6616: img.stift {
1.803 bisitz 6617: border-width: 0;
6618: vertical-align: middle;
1.677 riegler 6619: }
1.680 riegler 6620:
1.923 bisitz 6621: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6622: vertical-align: top;
1.777 tempelho 6623: }
1.795 www 6624:
1.716 raeburn 6625: div.LC_createcourse {
1.911 bisitz 6626: margin: 10px 10px 10px 10px;
1.716 raeburn 6627: }
6628:
1.917 raeburn 6629: .LC_dccid {
1.1075.2.38 raeburn 6630: float: right;
1.917 raeburn 6631: margin: 0.2em 0 0 0;
6632: padding: 0;
6633: font-size: 90%;
6634: display:none;
6635: }
6636:
1.897 wenzelju 6637: ol.LC_primary_menu a:hover,
1.721 harmsja 6638: ol#LC_MenuBreadcrumbs a:hover,
6639: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6640: ul#LC_secondary_menu a:hover,
1.721 harmsja 6641: .LC_FormSectionClearButton input:hover
1.795 www 6642: ul.LC_TabContent li:hover a {
1.952 onken 6643: color:$button_hover;
1.911 bisitz 6644: text-decoration:none;
1.693 droeschl 6645: }
6646:
1.779 bisitz 6647: h1 {
1.911 bisitz 6648: padding: 0;
6649: line-height:130%;
1.693 droeschl 6650: }
1.698 harmsja 6651:
1.911 bisitz 6652: h2,
6653: h3,
6654: h4,
6655: h5,
6656: h6 {
6657: margin: 5px 0 5px 0;
6658: padding: 0;
6659: line-height:130%;
1.693 droeschl 6660: }
1.795 www 6661:
6662: .LC_hcell {
1.911 bisitz 6663: padding:3px 15px 3px 15px;
6664: margin: 0;
6665: background-color:$tabbg;
6666: color:$fontmenu;
6667: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6668: }
1.795 www 6669:
1.840 bisitz 6670: .LC_Box > .LC_hcell {
1.911 bisitz 6671: margin: 0 -10px 10px -10px;
1.835 bisitz 6672: }
6673:
1.721 harmsja 6674: .LC_noBorder {
1.911 bisitz 6675: border: 0;
1.698 harmsja 6676: }
1.693 droeschl 6677:
1.721 harmsja 6678: .LC_FormSectionClearButton input {
1.911 bisitz 6679: background-color:transparent;
6680: border: none;
6681: cursor:pointer;
6682: text-decoration:underline;
1.693 droeschl 6683: }
1.763 bisitz 6684:
6685: .LC_help_open_topic {
1.911 bisitz 6686: color: #FFFFFF;
6687: background-color: #EEEEFF;
6688: margin: 1px;
6689: padding: 4px;
6690: border: 1px solid #000033;
6691: white-space: nowrap;
6692: /* vertical-align: middle; */
1.759 neumanie 6693: }
1.693 droeschl 6694:
1.911 bisitz 6695: dl,
6696: ul,
6697: div,
6698: fieldset {
6699: margin: 10px 10px 10px 0;
6700: /* overflow: hidden; */
1.693 droeschl 6701: }
1.795 www 6702:
1.1075.2.90 raeburn 6703: article.geogebraweb div {
6704: margin: 0;
6705: }
6706:
1.838 bisitz 6707: fieldset > legend {
1.911 bisitz 6708: font-weight: bold;
6709: padding: 0 5px 0 5px;
1.838 bisitz 6710: }
6711:
1.813 bisitz 6712: #LC_nav_bar {
1.911 bisitz 6713: float: left;
1.995 raeburn 6714: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6715: margin: 0 0 2px 0;
1.807 droeschl 6716: }
6717:
1.916 droeschl 6718: #LC_realm {
6719: margin: 0.2em 0 0 0;
6720: padding: 0;
6721: font-weight: bold;
6722: text-align: center;
1.995 raeburn 6723: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6724: }
6725:
1.911 bisitz 6726: #LC_nav_bar em {
6727: font-weight: bold;
6728: font-style: normal;
1.807 droeschl 6729: }
6730:
1.897 wenzelju 6731: ol.LC_primary_menu {
1.934 droeschl 6732: margin: 0;
1.1075.2.2 raeburn 6733: padding: 0;
1.995 raeburn 6734: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6735: }
6736:
1.852 droeschl 6737: ol#LC_PathBreadcrumbs {
1.911 bisitz 6738: margin: 0;
1.693 droeschl 6739: }
6740:
1.897 wenzelju 6741: ol.LC_primary_menu li {
1.1075.2.2 raeburn 6742: color: RGB(80, 80, 80);
6743: vertical-align: middle;
6744: text-align: left;
6745: list-style: none;
6746: float: left;
6747: }
6748:
6749: ol.LC_primary_menu li a {
6750: display: block;
6751: margin: 0;
6752: padding: 0 5px 0 10px;
6753: text-decoration: none;
6754: }
6755:
6756: ol.LC_primary_menu li ul {
6757: display: none;
6758: width: 10em;
6759: background-color: $data_table_light;
6760: }
6761:
6762: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6763: display: block;
6764: position: absolute;
6765: margin: 0;
6766: padding: 0;
1.1075.2.5 raeburn 6767: z-index: 2;
1.1075.2.2 raeburn 6768: }
6769:
6770: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6771: font-size: 90%;
1.911 bisitz 6772: vertical-align: top;
1.1075.2.2 raeburn 6773: float: none;
1.1075.2.5 raeburn 6774: border-left: 1px solid black;
6775: border-right: 1px solid black;
1.1075.2.2 raeburn 6776: }
6777:
6778: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5 raeburn 6779: background-color:$data_table_light;
1.1075.2.2 raeburn 6780: }
6781:
6782: ol.LC_primary_menu li li a:hover {
6783: color:$button_hover;
6784: background-color:$data_table_dark;
1.693 droeschl 6785: }
6786:
1.897 wenzelju 6787: ol.LC_primary_menu li img {
1.911 bisitz 6788: vertical-align: bottom;
1.934 droeschl 6789: height: 1.1em;
1.1075.2.3 raeburn 6790: margin: 0.2em 0 0 0;
1.693 droeschl 6791: }
6792:
1.897 wenzelju 6793: ol.LC_primary_menu a {
1.911 bisitz 6794: color: RGB(80, 80, 80);
6795: text-decoration: none;
1.693 droeschl 6796: }
1.795 www 6797:
1.949 droeschl 6798: ol.LC_primary_menu a.LC_new_message {
6799: font-weight:bold;
6800: color: darkred;
6801: }
6802:
1.975 raeburn 6803: ol.LC_docs_parameters {
6804: margin-left: 0;
6805: padding: 0;
6806: list-style: none;
6807: }
6808:
6809: ol.LC_docs_parameters li {
6810: margin: 0;
6811: padding-right: 20px;
6812: display: inline;
6813: }
6814:
1.976 raeburn 6815: ol.LC_docs_parameters li:before {
6816: content: "\\002022 \\0020";
6817: }
6818:
6819: li.LC_docs_parameters_title {
6820: font-weight: bold;
6821: }
6822:
6823: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6824: content: "";
6825: }
6826:
1.897 wenzelju 6827: ul#LC_secondary_menu {
1.1075.2.23 raeburn 6828: clear: right;
1.911 bisitz 6829: color: $fontmenu;
6830: background: $tabbg;
6831: list-style: none;
6832: padding: 0;
6833: margin: 0;
6834: width: 100%;
1.995 raeburn 6835: text-align: left;
1.1075.2.4 raeburn 6836: float: left;
1.808 droeschl 6837: }
6838:
1.897 wenzelju 6839: ul#LC_secondary_menu li {
1.911 bisitz 6840: font-weight: bold;
6841: line-height: 1.8em;
6842: border-right: 1px solid black;
6843: vertical-align: middle;
1.1075.2.4 raeburn 6844: float: left;
6845: }
6846:
6847: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6848: background-color: $data_table_light;
6849: }
6850:
6851: ul#LC_secondary_menu li a {
6852: padding: 0 0.8em;
6853: }
6854:
6855: ul#LC_secondary_menu li ul {
6856: display: none;
6857: }
6858:
6859: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6860: display: block;
6861: position: absolute;
6862: margin: 0;
6863: padding: 0;
6864: list-style:none;
6865: float: none;
6866: background-color: $data_table_light;
1.1075.2.5 raeburn 6867: z-index: 2;
1.1075.2.10 raeburn 6868: margin-left: -1px;
1.1075.2.4 raeburn 6869: }
6870:
6871: ul#LC_secondary_menu li ul li {
6872: font-size: 90%;
6873: vertical-align: top;
6874: border-left: 1px solid black;
6875: border-right: 1px solid black;
1.1075.2.33 raeburn 6876: background-color: $data_table_light;
1.1075.2.4 raeburn 6877: list-style:none;
6878: float: none;
6879: }
6880:
6881: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6882: background-color: $data_table_dark;
1.807 droeschl 6883: }
6884:
1.847 tempelho 6885: ul.LC_TabContent {
1.911 bisitz 6886: display:block;
6887: background: $sidebg;
6888: border-bottom: solid 1px $lg_border_color;
6889: list-style:none;
1.1020 raeburn 6890: margin: -1px -10px 0 -10px;
1.911 bisitz 6891: padding: 0;
1.693 droeschl 6892: }
6893:
1.795 www 6894: ul.LC_TabContent li,
6895: ul.LC_TabContentBigger li {
1.911 bisitz 6896: float:left;
1.741 harmsja 6897: }
1.795 www 6898:
1.897 wenzelju 6899: ul#LC_secondary_menu li a {
1.911 bisitz 6900: color: $fontmenu;
6901: text-decoration: none;
1.693 droeschl 6902: }
1.795 www 6903:
1.721 harmsja 6904: ul.LC_TabContent {
1.952 onken 6905: min-height:20px;
1.721 harmsja 6906: }
1.795 www 6907:
6908: ul.LC_TabContent li {
1.911 bisitz 6909: vertical-align:middle;
1.959 onken 6910: padding: 0 16px 0 10px;
1.911 bisitz 6911: background-color:$tabbg;
6912: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6913: border-left: solid 1px $font;
1.721 harmsja 6914: }
1.795 www 6915:
1.847 tempelho 6916: ul.LC_TabContent .right {
1.911 bisitz 6917: float:right;
1.847 tempelho 6918: }
6919:
1.911 bisitz 6920: ul.LC_TabContent li a,
6921: ul.LC_TabContent li {
6922: color:rgb(47,47,47);
6923: text-decoration:none;
6924: font-size:95%;
6925: font-weight:bold;
1.952 onken 6926: min-height:20px;
6927: }
6928:
1.959 onken 6929: ul.LC_TabContent li a:hover,
6930: ul.LC_TabContent li a:focus {
1.952 onken 6931: color: $button_hover;
1.959 onken 6932: background:none;
6933: outline:none;
1.952 onken 6934: }
6935:
6936: ul.LC_TabContent li:hover {
6937: color: $button_hover;
6938: cursor:pointer;
1.721 harmsja 6939: }
1.795 www 6940:
1.911 bisitz 6941: ul.LC_TabContent li.active {
1.952 onken 6942: color: $font;
1.911 bisitz 6943: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6944: border-bottom:solid 1px #FFFFFF;
6945: cursor: default;
1.744 ehlerst 6946: }
1.795 www 6947:
1.959 onken 6948: ul.LC_TabContent li.active a {
6949: color:$font;
6950: background:#FFFFFF;
6951: outline: none;
6952: }
1.1047 raeburn 6953:
6954: ul.LC_TabContent li.goback {
6955: float: left;
6956: border-left: none;
6957: }
6958:
1.870 tempelho 6959: #maincoursedoc {
1.911 bisitz 6960: clear:both;
1.870 tempelho 6961: }
6962:
6963: ul.LC_TabContentBigger {
1.911 bisitz 6964: display:block;
6965: list-style:none;
6966: padding: 0;
1.870 tempelho 6967: }
6968:
1.795 www 6969: ul.LC_TabContentBigger li {
1.911 bisitz 6970: vertical-align:bottom;
6971: height: 30px;
6972: font-size:110%;
6973: font-weight:bold;
6974: color: #737373;
1.841 tempelho 6975: }
6976:
1.957 onken 6977: ul.LC_TabContentBigger li.active {
6978: position: relative;
6979: top: 1px;
6980: }
6981:
1.870 tempelho 6982: ul.LC_TabContentBigger li a {
1.911 bisitz 6983: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6984: height: 30px;
6985: line-height: 30px;
6986: text-align: center;
6987: display: block;
6988: text-decoration: none;
1.958 onken 6989: outline: none;
1.741 harmsja 6990: }
1.795 www 6991:
1.870 tempelho 6992: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6993: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6994: color:$font;
1.744 ehlerst 6995: }
1.795 www 6996:
1.870 tempelho 6997: ul.LC_TabContentBigger li b {
1.911 bisitz 6998: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6999: display: block;
7000: float: left;
7001: padding: 0 30px;
1.957 onken 7002: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7003: }
7004:
1.956 onken 7005: ul.LC_TabContentBigger li:hover b {
7006: color:$button_hover;
7007: }
7008:
1.870 tempelho 7009: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7010: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7011: color:$font;
1.957 onken 7012: border: 0;
1.741 harmsja 7013: }
1.693 droeschl 7014:
1.870 tempelho 7015:
1.862 bisitz 7016: ul.LC_CourseBreadcrumbs {
7017: background: $sidebg;
1.1020 raeburn 7018: height: 2em;
1.862 bisitz 7019: padding-left: 10px;
1.1020 raeburn 7020: margin: 0;
1.862 bisitz 7021: list-style-position: inside;
7022: }
7023:
1.911 bisitz 7024: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7025: ol#LC_PathBreadcrumbs {
1.911 bisitz 7026: padding-left: 10px;
7027: margin: 0;
1.933 droeschl 7028: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7029: }
7030:
1.911 bisitz 7031: ol#LC_MenuBreadcrumbs li,
7032: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7033: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7034: display: inline;
1.933 droeschl 7035: white-space: normal;
1.693 droeschl 7036: }
7037:
1.823 bisitz 7038: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7039: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7040: text-decoration: none;
7041: font-size:90%;
1.693 droeschl 7042: }
1.795 www 7043:
1.969 droeschl 7044: ol#LC_MenuBreadcrumbs h1 {
7045: display: inline;
7046: font-size: 90%;
7047: line-height: 2.5em;
7048: margin: 0;
7049: padding: 0;
7050: }
7051:
1.795 www 7052: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7053: text-decoration:none;
7054: font-size:100%;
7055: font-weight:bold;
1.693 droeschl 7056: }
1.795 www 7057:
1.840 bisitz 7058: .LC_Box {
1.911 bisitz 7059: border: solid 1px $lg_border_color;
7060: padding: 0 10px 10px 10px;
1.746 neumanie 7061: }
1.795 www 7062:
1.1020 raeburn 7063: .LC_DocsBox {
7064: border: solid 1px $lg_border_color;
7065: padding: 0 0 10px 10px;
7066: }
7067:
1.795 www 7068: .LC_AboutMe_Image {
1.911 bisitz 7069: float:left;
7070: margin-right:10px;
1.747 neumanie 7071: }
1.795 www 7072:
7073: .LC_Clear_AboutMe_Image {
1.911 bisitz 7074: clear:left;
1.747 neumanie 7075: }
1.795 www 7076:
1.721 harmsja 7077: dl.LC_ListStyleClean dt {
1.911 bisitz 7078: padding-right: 5px;
7079: display: table-header-group;
1.693 droeschl 7080: }
7081:
1.721 harmsja 7082: dl.LC_ListStyleClean dd {
1.911 bisitz 7083: display: table-row;
1.693 droeschl 7084: }
7085:
1.721 harmsja 7086: .LC_ListStyleClean,
7087: .LC_ListStyleSimple,
7088: .LC_ListStyleNormal,
1.795 www 7089: .LC_ListStyleSpecial {
1.911 bisitz 7090: /* display:block; */
7091: list-style-position: inside;
7092: list-style-type: none;
7093: overflow: hidden;
7094: padding: 0;
1.693 droeschl 7095: }
7096:
1.721 harmsja 7097: .LC_ListStyleSimple li,
7098: .LC_ListStyleSimple dd,
7099: .LC_ListStyleNormal li,
7100: .LC_ListStyleNormal dd,
7101: .LC_ListStyleSpecial li,
1.795 www 7102: .LC_ListStyleSpecial dd {
1.911 bisitz 7103: margin: 0;
7104: padding: 5px 5px 5px 10px;
7105: clear: both;
1.693 droeschl 7106: }
7107:
1.721 harmsja 7108: .LC_ListStyleClean li,
7109: .LC_ListStyleClean dd {
1.911 bisitz 7110: padding-top: 0;
7111: padding-bottom: 0;
1.693 droeschl 7112: }
7113:
1.721 harmsja 7114: .LC_ListStyleSimple dd,
1.795 www 7115: .LC_ListStyleSimple li {
1.911 bisitz 7116: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7117: }
7118:
1.721 harmsja 7119: .LC_ListStyleSpecial li,
7120: .LC_ListStyleSpecial dd {
1.911 bisitz 7121: list-style-type: none;
7122: background-color: RGB(220, 220, 220);
7123: margin-bottom: 4px;
1.693 droeschl 7124: }
7125:
1.721 harmsja 7126: table.LC_SimpleTable {
1.911 bisitz 7127: margin:5px;
7128: border:solid 1px $lg_border_color;
1.795 www 7129: }
1.693 droeschl 7130:
1.721 harmsja 7131: table.LC_SimpleTable tr {
1.911 bisitz 7132: padding: 0;
7133: border:solid 1px $lg_border_color;
1.693 droeschl 7134: }
1.795 www 7135:
7136: table.LC_SimpleTable thead {
1.911 bisitz 7137: background:rgb(220,220,220);
1.693 droeschl 7138: }
7139:
1.721 harmsja 7140: div.LC_columnSection {
1.911 bisitz 7141: display: block;
7142: clear: both;
7143: overflow: hidden;
7144: margin: 0;
1.693 droeschl 7145: }
7146:
1.721 harmsja 7147: div.LC_columnSection>* {
1.911 bisitz 7148: float: left;
7149: margin: 10px 20px 10px 0;
7150: overflow:hidden;
1.693 droeschl 7151: }
1.721 harmsja 7152:
1.795 www 7153: table em {
1.911 bisitz 7154: font-weight: bold;
7155: font-style: normal;
1.748 schulted 7156: }
1.795 www 7157:
1.779 bisitz 7158: table.LC_tableBrowseRes,
1.795 www 7159: table.LC_tableOfContent {
1.911 bisitz 7160: border:none;
7161: border-spacing: 1px;
7162: padding: 3px;
7163: background-color: #FFFFFF;
7164: font-size: 90%;
1.753 droeschl 7165: }
1.789 droeschl 7166:
1.911 bisitz 7167: table.LC_tableOfContent {
7168: border-collapse: collapse;
1.789 droeschl 7169: }
7170:
1.771 droeschl 7171: table.LC_tableBrowseRes a,
1.768 schulted 7172: table.LC_tableOfContent a {
1.911 bisitz 7173: background-color: transparent;
7174: text-decoration: none;
1.753 droeschl 7175: }
7176:
1.795 www 7177: table.LC_tableOfContent img {
1.911 bisitz 7178: border: none;
7179: height: 1.3em;
7180: vertical-align: text-bottom;
7181: margin-right: 0.3em;
1.753 droeschl 7182: }
1.757 schulted 7183:
1.795 www 7184: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7185: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7186: }
7187:
1.795 www 7188: a#LC_content_toolbar_everything {
1.911 bisitz 7189: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7190: }
7191:
1.795 www 7192: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7193: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7194: }
7195:
1.795 www 7196: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7197: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7198: }
7199:
1.795 www 7200: a#LC_content_toolbar_changefolder {
1.911 bisitz 7201: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7202: }
7203:
1.795 www 7204: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7205: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7206: }
7207:
1.1043 raeburn 7208: a#LC_content_toolbar_edittoplevel {
7209: background-image:url(/res/adm/pages/edittoplevel.gif);
7210: }
7211:
1.795 www 7212: ul#LC_toolbar li a:hover {
1.911 bisitz 7213: background-position: bottom center;
1.757 schulted 7214: }
7215:
1.795 www 7216: ul#LC_toolbar {
1.911 bisitz 7217: padding: 0;
7218: margin: 2px;
7219: list-style:none;
7220: position:relative;
7221: background-color:white;
1.1075.2.9 raeburn 7222: overflow: auto;
1.757 schulted 7223: }
7224:
1.795 www 7225: ul#LC_toolbar li {
1.911 bisitz 7226: border:1px solid white;
7227: padding: 0;
7228: margin: 0;
7229: float: left;
7230: display:inline;
7231: vertical-align:middle;
1.1075.2.9 raeburn 7232: white-space: nowrap;
1.911 bisitz 7233: }
1.757 schulted 7234:
1.783 amueller 7235:
1.795 www 7236: a.LC_toolbarItem {
1.911 bisitz 7237: display:block;
7238: padding: 0;
7239: margin: 0;
7240: height: 32px;
7241: width: 32px;
7242: color:white;
7243: border: none;
7244: background-repeat:no-repeat;
7245: background-color:transparent;
1.757 schulted 7246: }
7247:
1.915 droeschl 7248: ul.LC_funclist {
7249: margin: 0;
7250: padding: 0.5em 1em 0.5em 0;
7251: }
7252:
1.933 droeschl 7253: ul.LC_funclist > li:first-child {
7254: font-weight:bold;
7255: margin-left:0.8em;
7256: }
7257:
1.915 droeschl 7258: ul.LC_funclist + ul.LC_funclist {
7259: /*
7260: left border as a seperator if we have more than
7261: one list
7262: */
7263: border-left: 1px solid $sidebg;
7264: /*
7265: this hides the left border behind the border of the
7266: outer box if element is wrapped to the next 'line'
7267: */
7268: margin-left: -1px;
7269: }
7270:
1.843 bisitz 7271: ul.LC_funclist li {
1.915 droeschl 7272: display: inline;
1.782 bisitz 7273: white-space: nowrap;
1.915 droeschl 7274: margin: 0 0 0 25px;
7275: line-height: 150%;
1.782 bisitz 7276: }
7277:
1.974 wenzelju 7278: .LC_hidden {
7279: display: none;
7280: }
7281:
1.1030 www 7282: .LCmodal-overlay {
7283: position:fixed;
7284: top:0;
7285: right:0;
7286: bottom:0;
7287: left:0;
7288: height:100%;
7289: width:100%;
7290: margin:0;
7291: padding:0;
7292: background:#999;
7293: opacity:.75;
7294: filter: alpha(opacity=75);
7295: -moz-opacity: 0.75;
7296: z-index:101;
7297: }
7298:
7299: * html .LCmodal-overlay {
7300: position: absolute;
7301: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7302: }
7303:
7304: .LCmodal-window {
7305: position:fixed;
7306: top:50%;
7307: left:50%;
7308: margin:0;
7309: padding:0;
7310: z-index:102;
7311: }
7312:
7313: * html .LCmodal-window {
7314: position:absolute;
7315: }
7316:
7317: .LCclose-window {
7318: position:absolute;
7319: width:32px;
7320: height:32px;
7321: right:8px;
7322: top:8px;
7323: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7324: text-indent:-99999px;
7325: overflow:hidden;
7326: cursor:pointer;
7327: }
7328:
1.1075.2.17 raeburn 7329: /*
7330: styles used by TTH when "Default set of options to pass to tth/m
7331: when converting TeX" in course settings has been set
7332:
7333: option passed: -t
7334:
7335: */
7336:
7337: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7338: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7339: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7340: td div.norm {line-height:normal;}
7341:
7342: /*
7343: option passed -y3
7344: */
7345:
7346: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7347: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7348: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7349:
1.343 albertel 7350: END
7351: }
7352:
1.306 albertel 7353: =pod
7354:
7355: =item * &headtag()
7356:
7357: Returns a uniform footer for LON-CAPA web pages.
7358:
1.307 albertel 7359: Inputs: $title - optional title for the head
7360: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7361: $args - optional arguments
1.319 albertel 7362: force_register - if is true call registerurl so the remote is
7363: informed
1.415 albertel 7364: redirect -> array ref of
7365: 1- seconds before redirect occurs
7366: 2- url to redirect to
7367: 3- whether the side effect should occur
1.315 albertel 7368: (side effect of setting
7369: $env{'internal.head.redirect'} to the url
7370: redirected too)
1.352 albertel 7371: domain -> force to color decorate a page for a specific
7372: domain
7373: function -> force usage of a specific rolish color scheme
7374: bgcolor -> override the default page bgcolor
1.460 albertel 7375: no_auto_mt_title
7376: -> prevent &mt()ing the title arg
1.464 albertel 7377:
1.306 albertel 7378: =cut
7379:
7380: sub headtag {
1.313 albertel 7381: my ($title,$head_extra,$args) = @_;
1.306 albertel 7382:
1.363 albertel 7383: my $function = $args->{'function'} || &get_users_function();
7384: my $domain = $args->{'domain'} || &determinedomain();
7385: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7386: my $httphost = $args->{'use_absolute'};
1.418 albertel 7387: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7388: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7389: #time(),
1.418 albertel 7390: $env{'environment.color.timestamp'},
1.363 albertel 7391: $function,$domain,$bgcolor);
7392:
1.369 www 7393: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7394:
1.308 albertel 7395: my $result =
7396: '<head>'.
1.1075.2.56 raeburn 7397: &font_settings($args);
1.319 albertel 7398:
1.1075.2.72 raeburn 7399: my $inhibitprint;
7400: if ($args->{'print_suppress'}) {
7401: $inhibitprint = &print_suppression();
7402: }
1.1064 raeburn 7403:
1.461 albertel 7404: if (!$args->{'frameset'}) {
7405: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7406: }
1.1075.2.12 raeburn 7407: if ($args->{'force_register'}) {
7408: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7409: }
1.436 albertel 7410: if (!$args->{'no_nav_bar'}
7411: && !$args->{'only_body'}
7412: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7413: $result .= &help_menu_js($httphost);
1.1032 www 7414: $result.=&modal_window();
1.1038 www 7415: $result.=&togglebox_script();
1.1034 www 7416: $result.=&wishlist_window();
1.1041 www 7417: $result.=&LCprogressbarUpdate_script();
1.1034 www 7418: } else {
7419: if ($args->{'add_modal'}) {
7420: $result.=&modal_window();
7421: }
7422: if ($args->{'add_wishlist'}) {
7423: $result.=&wishlist_window();
7424: }
1.1038 www 7425: if ($args->{'add_togglebox'}) {
7426: $result.=&togglebox_script();
7427: }
1.1041 www 7428: if ($args->{'add_progressbar'}) {
7429: $result.=&LCprogressbarUpdate_script();
7430: }
1.436 albertel 7431: }
1.314 albertel 7432: if (ref($args->{'redirect'})) {
1.414 albertel 7433: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7434: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7435: if (!$inhibit_continue) {
7436: $env{'internal.head.redirect'} = $url;
7437: }
1.313 albertel 7438: $result.=<<ADDMETA
7439: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7440: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7441: ADDMETA
1.1075.2.89 raeburn 7442: } else {
7443: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7444: my $requrl = $env{'request.uri'};
7445: if ($requrl eq '') {
7446: $requrl = $ENV{'REQUEST_URI'};
7447: $requrl =~ s/\?.+$//;
7448: }
7449: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7450: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7451: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7452: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7453: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7454: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7455: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7456: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7457: if ($domdefs{'offloadnow'}{$lonhost}) {
7458: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7459: if (($newserver) && ($newserver ne $lonhost)) {
7460: my $numsec = 5;
7461: my $timeout = $numsec * 1000;
7462: my ($newurl,$locknum,%locks,$msg);
7463: if ($env{'request.role.adv'}) {
7464: ($locknum,%locks) = &Apache::lonnet::get_locks();
7465: }
7466: my $disable_submit = 0;
7467: if ($requrl =~ /$LONCAPA::assess_re/) {
7468: $disable_submit = 1;
7469: }
7470: if ($locknum) {
7471: my @lockinfo = sort(values(%locks));
7472: $msg = &mt('Once the following tasks are complete: ')."\\n".
7473: join(", ",sort(values(%locks)))."\\n".
7474: &mt('your session will be transferred to a different server, after you click "Roles".');
7475: } else {
7476: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7477: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7478: }
7479: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7480: $newurl = '/adm/switchserver?otherserver='.$newserver;
7481: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7482: $newurl .= '&role='.$env{'request.role'};
7483: }
7484: if ($env{'request.symb'}) {
7485: $newurl .= '&symb='.$env{'request.symb'};
7486: } else {
7487: $newurl .= '&origurl='.$requrl;
7488: }
7489: }
7490: $result.=<<OFFLOAD
7491: <meta http-equiv="pragma" content="no-cache" />
7492: <script type="text/javascript">
1.1075.2.92 raeburn 7493: // <![CDATA[
1.1075.2.89 raeburn 7494: function LC_Offload_Now() {
7495: var dest = "$newurl";
7496: if (dest != '') {
7497: window.location.href="$newurl";
7498: }
7499: }
1.1075.2.92 raeburn 7500: \$(document).ready(function () {
7501: window.alert('$msg');
7502: if ($disable_submit) {
1.1075.2.89 raeburn 7503: \$(".LC_hwk_submit").prop("disabled", true);
7504: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 7505: }
7506: setTimeout('LC_Offload_Now()', $timeout);
7507: });
7508: // ]]>
1.1075.2.89 raeburn 7509: </script>
7510: OFFLOAD
7511: }
7512: }
7513: }
7514: }
7515: }
7516: }
1.313 albertel 7517: }
1.306 albertel 7518: if (!defined($title)) {
7519: $title = 'The LearningOnline Network with CAPA';
7520: }
1.460 albertel 7521: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7522: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7523: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7524: if (!$args->{'frameset'}) {
7525: $result .= ' /';
7526: }
7527: $result .= '>'
1.1064 raeburn 7528: .$inhibitprint
1.414 albertel 7529: .$head_extra;
1.1075.2.42 raeburn 7530: if ($env{'browser.mobile'}) {
7531: $result .= '
7532: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7533: <meta name="apple-mobile-web-app-capable" content="yes" />';
7534: }
1.962 droeschl 7535: return $result.'</head>';
1.306 albertel 7536: }
7537:
7538: =pod
7539:
1.340 albertel 7540: =item * &font_settings()
7541:
7542: Returns neccessary <meta> to set the proper encoding
7543:
1.1075.2.56 raeburn 7544: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7545:
7546: =cut
7547:
7548: sub font_settings {
1.1075.2.56 raeburn 7549: my ($args) = @_;
1.340 albertel 7550: my $headerstring='';
1.1075.2.56 raeburn 7551: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7552: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7553: $headerstring.=
1.1075.2.61 raeburn 7554: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7555: if (!$args->{'frameset'}) {
7556: $headerstring.= ' /';
7557: }
7558: $headerstring .= '>'."\n";
1.340 albertel 7559: }
7560: return $headerstring;
7561: }
7562:
1.341 albertel 7563: =pod
7564:
1.1064 raeburn 7565: =item * &print_suppression()
7566:
7567: In course context returns css which causes the body to be blank when media="print",
7568: if printout generation is unavailable for the current resource.
7569:
7570: This could be because:
7571:
7572: (a) printstartdate is in the future
7573:
7574: (b) printenddate is in the past
7575:
7576: (c) there is an active exam block with "printout"
7577: functionality blocked
7578:
7579: Users with pav, pfo or evb privileges are exempt.
7580:
7581: Inputs: none
7582:
7583: =cut
7584:
7585:
7586: sub print_suppression {
7587: my $noprint;
7588: if ($env{'request.course.id'}) {
7589: my $scope = $env{'request.course.id'};
7590: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7591: (&Apache::lonnet::allowed('pfo',$scope))) {
7592: return;
7593: }
7594: if ($env{'request.course.sec'} ne '') {
7595: $scope .= "/$env{'request.course.sec'}";
7596: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7597: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7598: return;
1.1064 raeburn 7599: }
7600: }
7601: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7602: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 7603: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 7604: if ($blocked) {
7605: my $checkrole = "cm./$cdom/$cnum";
7606: if ($env{'request.course.sec'} ne '') {
7607: $checkrole .= "/$env{'request.course.sec'}";
7608: }
7609: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7610: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7611: $noprint = 1;
7612: }
7613: }
7614: unless ($noprint) {
7615: my $symb = &Apache::lonnet::symbread();
7616: if ($symb ne '') {
7617: my $navmap = Apache::lonnavmaps::navmap->new();
7618: if (ref($navmap)) {
7619: my $res = $navmap->getBySymb($symb);
7620: if (ref($res)) {
7621: if (!$res->resprintable()) {
7622: $noprint = 1;
7623: }
7624: }
7625: }
7626: }
7627: }
7628: if ($noprint) {
7629: return <<"ENDSTYLE";
7630: <style type="text/css" media="print">
7631: body { display:none }
7632: </style>
7633: ENDSTYLE
7634: }
7635: }
7636: return;
7637: }
7638:
7639: =pod
7640:
1.341 albertel 7641: =item * &xml_begin()
7642:
7643: Returns the needed doctype and <html>
7644:
7645: Inputs: none
7646:
7647: =cut
7648:
7649: sub xml_begin {
1.1075.2.61 raeburn 7650: my ($is_frameset) = @_;
1.341 albertel 7651: my $output='';
7652:
7653: if ($env{'browser.mathml'}) {
7654: $output='<?xml version="1.0"?>'
7655: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7656: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7657:
7658: # .'<!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">] >'
7659: .'<!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">'
7660: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7661: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 7662: } elsif ($is_frameset) {
7663: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7664: '<html>'."\n";
1.341 albertel 7665: } else {
1.1075.2.61 raeburn 7666: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7667: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7668: }
7669: return $output;
7670: }
1.340 albertel 7671:
7672: =pod
7673:
1.306 albertel 7674: =item * &start_page()
7675:
7676: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7677:
1.648 raeburn 7678: Inputs:
7679:
7680: =over 4
7681:
7682: $title - optional title for the page
7683:
7684: $head_extra - optional extra HTML to incude inside the <head>
7685:
7686: $args - additional optional args supported are:
7687:
7688: =over 8
7689:
7690: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7691: arg on
1.814 bisitz 7692: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7693: add_entries -> additional attributes to add to the <body>
7694: domain -> force to color decorate a page for a
1.317 albertel 7695: specific domain
1.648 raeburn 7696: function -> force usage of a specific rolish color
1.317 albertel 7697: scheme
1.648 raeburn 7698: redirect -> see &headtag()
7699: bgcolor -> override the default page bg color
7700: js_ready -> return a string ready for being used in
1.317 albertel 7701: a javascript writeln
1.648 raeburn 7702: html_encode -> return a string ready for being used in
1.320 albertel 7703: a html attribute
1.648 raeburn 7704: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7705: $forcereg arg
1.648 raeburn 7706: frameset -> if true will start with a <frameset>
1.330 albertel 7707: rather than <body>
1.648 raeburn 7708: skip_phases -> hash ref of
1.338 albertel 7709: head -> skip the <html><head> generation
7710: body -> skip all <body> generation
1.1075.2.12 raeburn 7711: no_inline_link -> if true and in remote mode, don't show the
7712: 'Switch To Inline Menu' link
1.648 raeburn 7713: no_auto_mt_title -> prevent &mt()ing the title arg
7714: inherit_jsmath -> when creating popup window in a page,
7715: should it have jsmath forced on by the
7716: current page
1.867 kalberla 7717: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7718: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.15 raeburn 7719: group -> includes the current group, if page is for a
7720: specific group
1.361 albertel 7721:
1.648 raeburn 7722: =back
1.460 albertel 7723:
1.648 raeburn 7724: =back
1.562 albertel 7725:
1.306 albertel 7726: =cut
7727:
7728: sub start_page {
1.309 albertel 7729: my ($title,$head_extra,$args) = @_;
1.318 albertel 7730: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7731:
1.315 albertel 7732: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 7733: my ($result,@advtools);
1.964 droeschl 7734:
1.338 albertel 7735: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 7736: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 7737: }
7738:
7739: if (! exists($args->{'skip_phases'}{'body'}) ) {
7740: if ($args->{'frameset'}) {
7741: my $attr_string = &make_attr_string($args->{'force_register'},
7742: $args->{'add_entries'});
7743: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7744: } else {
7745: $result .=
7746: &bodytag($title,
7747: $args->{'function'}, $args->{'add_entries'},
7748: $args->{'only_body'}, $args->{'domain'},
7749: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 7750: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 7751: $args, \@advtools);
1.831 bisitz 7752: }
1.330 albertel 7753: }
1.338 albertel 7754:
1.315 albertel 7755: if ($args->{'js_ready'}) {
1.713 kaisler 7756: $result = &js_ready($result);
1.315 albertel 7757: }
1.320 albertel 7758: if ($args->{'html_encode'}) {
1.713 kaisler 7759: $result = &html_encode($result);
7760: }
7761:
1.813 bisitz 7762: # Preparation for new and consistent functionlist at top of screen
7763: # if ($args->{'functionlist'}) {
7764: # $result .= &build_functionlist();
7765: #}
7766:
1.964 droeschl 7767: # Don't add anything more if only_body wanted or in const space
7768: return $result if $args->{'only_body'}
7769: || $env{'request.state'} eq 'construct';
1.813 bisitz 7770:
7771: #Breadcrumbs
1.758 kaisler 7772: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7773: &Apache::lonhtmlcommon::clear_breadcrumbs();
7774: #if any br links exists, add them to the breadcrumbs
7775: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7776: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7777: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7778: }
7779: }
1.1075.2.19 raeburn 7780: # if @advtools array contains items add then to the breadcrumbs
7781: if (@advtools > 0) {
7782: &Apache::lonmenu::advtools_crumbs(@advtools);
7783: }
1.758 kaisler 7784:
7785: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7786: if(exists($args->{'bread_crumbs_component'})){
7787: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7788: }else{
7789: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7790: }
1.1075.2.24 raeburn 7791: } elsif (($env{'environment.remote'} eq 'on') &&
7792: ($env{'form.inhibitmenu'} ne 'yes') &&
7793: ($env{'request.noversionuri'} =~ m{^/res/}) &&
7794: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 7795: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 7796: }
1.315 albertel 7797: return $result;
1.306 albertel 7798: }
7799:
7800: sub end_page {
1.315 albertel 7801: my ($args) = @_;
7802: $env{'internal.end_page'}++;
1.330 albertel 7803: my $result;
1.335 albertel 7804: if ($args->{'discussion'}) {
7805: my ($target,$parser);
7806: if (ref($args->{'discussion'})) {
7807: ($target,$parser) =($args->{'discussion'}{'target'},
7808: $args->{'discussion'}{'parser'});
7809: }
7810: $result .= &Apache::lonxml::xmlend($target,$parser);
7811: }
1.330 albertel 7812: if ($args->{'frameset'}) {
7813: $result .= '</frameset>';
7814: } else {
1.635 raeburn 7815: $result .= &endbodytag($args);
1.330 albertel 7816: }
1.1075.2.6 raeburn 7817: unless ($args->{'notbody'}) {
7818: $result .= "\n</html>";
7819: }
1.330 albertel 7820:
1.315 albertel 7821: if ($args->{'js_ready'}) {
1.317 albertel 7822: $result = &js_ready($result);
1.315 albertel 7823: }
1.335 albertel 7824:
1.320 albertel 7825: if ($args->{'html_encode'}) {
7826: $result = &html_encode($result);
7827: }
1.335 albertel 7828:
1.315 albertel 7829: return $result;
7830: }
7831:
1.1034 www 7832: sub wishlist_window {
7833: return(<<'ENDWISHLIST');
1.1046 raeburn 7834: <script type="text/javascript">
1.1034 www 7835: // <![CDATA[
7836: // <!-- BEGIN LON-CAPA Internal
7837: function set_wishlistlink(title, path) {
7838: if (!title) {
7839: title = document.title;
7840: title = title.replace(/^LON-CAPA /,'');
7841: }
1.1075.2.65 raeburn 7842: title = encodeURIComponent(title);
1.1075.2.83 raeburn 7843: title = title.replace("'","\\\'");
1.1034 www 7844: if (!path) {
7845: path = location.pathname;
7846: }
1.1075.2.65 raeburn 7847: path = encodeURIComponent(path);
1.1075.2.83 raeburn 7848: path = path.replace("'","\\\'");
1.1034 www 7849: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7850: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7851: }
7852: // END LON-CAPA Internal -->
7853: // ]]>
7854: </script>
7855: ENDWISHLIST
7856: }
7857:
1.1030 www 7858: sub modal_window {
7859: return(<<'ENDMODAL');
1.1046 raeburn 7860: <script type="text/javascript">
1.1030 www 7861: // <![CDATA[
7862: // <!-- BEGIN LON-CAPA Internal
7863: var modalWindow = {
7864: parent:"body",
7865: windowId:null,
7866: content:null,
7867: width:null,
7868: height:null,
7869: close:function()
7870: {
7871: $(".LCmodal-window").remove();
7872: $(".LCmodal-overlay").remove();
7873: },
7874: open:function()
7875: {
7876: var modal = "";
7877: modal += "<div class=\"LCmodal-overlay\"></div>";
7878: 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;\">";
7879: modal += this.content;
7880: modal += "</div>";
7881:
7882: $(this.parent).append(modal);
7883:
7884: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7885: $(".LCclose-window").click(function(){modalWindow.close();});
7886: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7887: }
7888: };
1.1075.2.42 raeburn 7889: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7890: {
1.1075.2.83 raeburn 7891: source = source.replace("'","'");
1.1030 www 7892: modalWindow.windowId = "myModal";
7893: modalWindow.width = width;
7894: modalWindow.height = height;
1.1075.2.80 raeburn 7895: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7896: modalWindow.open();
1.1075.2.87 raeburn 7897: };
1.1030 www 7898: // END LON-CAPA Internal -->
7899: // ]]>
7900: </script>
7901: ENDMODAL
7902: }
7903:
7904: sub modal_link {
1.1075.2.42 raeburn 7905: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7906: unless ($width) { $width=480; }
7907: unless ($height) { $height=400; }
1.1031 www 7908: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 7909: unless ($transparency) { $transparency='true'; }
7910:
1.1074 raeburn 7911: my $target_attr;
7912: if (defined($target)) {
7913: $target_attr = 'target="'.$target.'"';
7914: }
7915: return <<"ENDLINK";
1.1075.2.42 raeburn 7916: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7917: $linktext</a>
7918: ENDLINK
1.1030 www 7919: }
7920:
1.1032 www 7921: sub modal_adhoc_script {
7922: my ($funcname,$width,$height,$content)=@_;
7923: return (<<ENDADHOC);
1.1046 raeburn 7924: <script type="text/javascript">
1.1032 www 7925: // <![CDATA[
7926: var $funcname = function()
7927: {
7928: modalWindow.windowId = "myModal";
7929: modalWindow.width = $width;
7930: modalWindow.height = $height;
7931: modalWindow.content = '$content';
7932: modalWindow.open();
7933: };
7934: // ]]>
7935: </script>
7936: ENDADHOC
7937: }
7938:
1.1041 www 7939: sub modal_adhoc_inner {
7940: my ($funcname,$width,$height,$content)=@_;
7941: my $innerwidth=$width-20;
7942: $content=&js_ready(
1.1042 www 7943: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 7944: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7945: $content.
1.1041 www 7946: &end_scrollbox().
1.1075.2.42 raeburn 7947: &end_page()
1.1041 www 7948: );
7949: return &modal_adhoc_script($funcname,$width,$height,$content);
7950: }
7951:
7952: sub modal_adhoc_window {
7953: my ($funcname,$width,$height,$content,$linktext)=@_;
7954: return &modal_adhoc_inner($funcname,$width,$height,$content).
7955: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7956: }
7957:
7958: sub modal_adhoc_launch {
7959: my ($funcname,$width,$height,$content)=@_;
7960: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7961: <script type="text/javascript">
7962: // <![CDATA[
7963: $funcname();
7964: // ]]>
7965: </script>
7966: ENDLAUNCH
7967: }
7968:
7969: sub modal_adhoc_close {
7970: return (<<ENDCLOSE);
7971: <script type="text/javascript">
7972: // <![CDATA[
7973: modalWindow.close();
7974: // ]]>
7975: </script>
7976: ENDCLOSE
7977: }
7978:
1.1038 www 7979: sub togglebox_script {
7980: return(<<ENDTOGGLE);
7981: <script type="text/javascript">
7982: // <![CDATA[
7983: function LCtoggleDisplay(id,hidetext,showtext) {
7984: link = document.getElementById(id + "link").childNodes[0];
7985: with (document.getElementById(id).style) {
7986: if (display == "none" ) {
7987: display = "inline";
7988: link.nodeValue = hidetext;
7989: } else {
7990: display = "none";
7991: link.nodeValue = showtext;
7992: }
7993: }
7994: }
7995: // ]]>
7996: </script>
7997: ENDTOGGLE
7998: }
7999:
1.1039 www 8000: sub start_togglebox {
8001: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8002: unless ($heading) { $heading=''; } else { $heading.=' '; }
8003: unless ($showtext) { $showtext=&mt('show'); }
8004: unless ($hidetext) { $hidetext=&mt('hide'); }
8005: unless ($headerbg) { $headerbg='#FFFFFF'; }
8006: return &start_data_table().
8007: &start_data_table_header_row().
8008: '<td bgcolor="'.$headerbg.'">'.$heading.
8009: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8010: $showtext.'\')">'.$showtext.'</a>]</td>'.
8011: &end_data_table_header_row().
8012: '<tr id="'.$id.'" style="display:none""><td>';
8013: }
8014:
8015: sub end_togglebox {
8016: return '</td></tr>'.&end_data_table();
8017: }
8018:
1.1041 www 8019: sub LCprogressbar_script {
1.1045 www 8020: my ($id)=@_;
1.1041 www 8021: return(<<ENDPROGRESS);
8022: <script type="text/javascript">
8023: // <![CDATA[
1.1045 www 8024: \$('#progressbar$id').progressbar({
1.1041 www 8025: value: 0,
8026: change: function(event, ui) {
8027: var newVal = \$(this).progressbar('option', 'value');
8028: \$('.pblabel', this).text(LCprogressTxt);
8029: }
8030: });
8031: // ]]>
8032: </script>
8033: ENDPROGRESS
8034: }
8035:
8036: sub LCprogressbarUpdate_script {
8037: return(<<ENDPROGRESSUPDATE);
8038: <style type="text/css">
8039: .ui-progressbar { position:relative; }
8040: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8041: </style>
8042: <script type="text/javascript">
8043: // <![CDATA[
1.1045 www 8044: var LCprogressTxt='---';
8045:
8046: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8047: LCprogressTxt=progresstext;
1.1045 www 8048: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8049: }
8050: // ]]>
8051: </script>
8052: ENDPROGRESSUPDATE
8053: }
8054:
1.1042 www 8055: my $LClastpercent;
1.1045 www 8056: my $LCidcnt;
8057: my $LCcurrentid;
1.1042 www 8058:
1.1041 www 8059: sub LCprogressbar {
1.1042 www 8060: my ($r)=(@_);
8061: $LClastpercent=0;
1.1045 www 8062: $LCidcnt++;
8063: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8064: my $starting=&mt('Starting');
8065: my $content=(<<ENDPROGBAR);
1.1045 www 8066: <div id="progressbar$LCcurrentid">
1.1041 www 8067: <span class="pblabel">$starting</span>
8068: </div>
8069: ENDPROGBAR
1.1045 www 8070: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8071: }
8072:
8073: sub LCprogressbarUpdate {
1.1042 www 8074: my ($r,$val,$text)=@_;
8075: unless ($val) {
8076: if ($LClastpercent) {
8077: $val=$LClastpercent;
8078: } else {
8079: $val=0;
8080: }
8081: }
1.1041 www 8082: if ($val<0) { $val=0; }
8083: if ($val>100) { $val=0; }
1.1042 www 8084: $LClastpercent=$val;
1.1041 www 8085: unless ($text) { $text=$val.'%'; }
8086: $text=&js_ready($text);
1.1044 www 8087: &r_print($r,<<ENDUPDATE);
1.1041 www 8088: <script type="text/javascript">
8089: // <![CDATA[
1.1045 www 8090: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8091: // ]]>
8092: </script>
8093: ENDUPDATE
1.1035 www 8094: }
8095:
1.1042 www 8096: sub LCprogressbarClose {
8097: my ($r)=@_;
8098: $LClastpercent=0;
1.1044 www 8099: &r_print($r,<<ENDCLOSE);
1.1042 www 8100: <script type="text/javascript">
8101: // <![CDATA[
1.1045 www 8102: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8103: // ]]>
8104: </script>
8105: ENDCLOSE
1.1044 www 8106: }
8107:
8108: sub r_print {
8109: my ($r,$to_print)=@_;
8110: if ($r) {
8111: $r->print($to_print);
8112: $r->rflush();
8113: } else {
8114: print($to_print);
8115: }
1.1042 www 8116: }
8117:
1.320 albertel 8118: sub html_encode {
8119: my ($result) = @_;
8120:
1.322 albertel 8121: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8122:
8123: return $result;
8124: }
1.1044 www 8125:
1.317 albertel 8126: sub js_ready {
8127: my ($result) = @_;
8128:
1.323 albertel 8129: $result =~ s/[\n\r]/ /xmsg;
8130: $result =~ s/\\/\\\\/xmsg;
8131: $result =~ s/'/\\'/xmsg;
1.372 albertel 8132: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8133:
8134: return $result;
8135: }
8136:
1.315 albertel 8137: sub validate_page {
8138: if ( exists($env{'internal.start_page'})
1.316 albertel 8139: && $env{'internal.start_page'} > 1) {
8140: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8141: $env{'internal.start_page'}.' '.
1.316 albertel 8142: $ENV{'request.filename'});
1.315 albertel 8143: }
8144: if ( exists($env{'internal.end_page'})
1.316 albertel 8145: && $env{'internal.end_page'} > 1) {
8146: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8147: $env{'internal.end_page'}.' '.
1.316 albertel 8148: $env{'request.filename'});
1.315 albertel 8149: }
8150: if ( exists($env{'internal.start_page'})
8151: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8152: &Apache::lonnet::logthis('start_page called without end_page '.
8153: $env{'request.filename'});
1.315 albertel 8154: }
8155: if ( ! exists($env{'internal.start_page'})
8156: && exists($env{'internal.end_page'})) {
1.316 albertel 8157: &Apache::lonnet::logthis('end_page called without start_page'.
8158: $env{'request.filename'});
1.315 albertel 8159: }
1.306 albertel 8160: }
1.315 albertel 8161:
1.996 www 8162:
8163: sub start_scrollbox {
1.1075.2.56 raeburn 8164: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8165: unless ($outerwidth) { $outerwidth='520px'; }
8166: unless ($width) { $width='500px'; }
8167: unless ($height) { $height='200px'; }
1.1075 raeburn 8168: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8169: if ($id ne '') {
1.1075.2.42 raeburn 8170: $table_id = ' id="table_'.$id.'"';
8171: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8172: }
1.1075 raeburn 8173: if ($bgcolor ne '') {
8174: $tdcol = "background-color: $bgcolor;";
8175: }
1.1075.2.42 raeburn 8176: my $nicescroll_js;
8177: if ($env{'browser.mobile'}) {
8178: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8179: }
1.1075 raeburn 8180: return <<"END";
1.1075.2.42 raeburn 8181: $nicescroll_js
8182:
8183: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8184: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8185: END
1.996 www 8186: }
8187:
8188: sub end_scrollbox {
1.1036 www 8189: return '</div></td></tr></table>';
1.996 www 8190: }
8191:
1.1075.2.42 raeburn 8192: sub nicescroll_javascript {
8193: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8194: my %options;
8195: if (ref($cursor) eq 'HASH') {
8196: %options = %{$cursor};
8197: }
8198: unless ($options{'railalign'} =~ /^left|right$/) {
8199: $options{'railalign'} = 'left';
8200: }
8201: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8202: my $function = &get_users_function();
8203: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8204: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8205: $options{'cursorcolor'} = '#00F';
8206: }
8207: }
8208: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8209: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8210: $options{'cursoropacity'}='1.0';
8211: }
8212: } else {
8213: $options{'cursoropacity'}='1.0';
8214: }
8215: if ($options{'cursorfixedheight'} eq 'none') {
8216: delete($options{'cursorfixedheight'});
8217: } else {
8218: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8219: }
8220: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8221: delete($options{'railoffset'});
8222: }
8223: my @niceoptions;
8224: while (my($key,$value) = each(%options)) {
8225: if ($value =~ /^\{.+\}$/) {
8226: push(@niceoptions,$key.':'.$value);
8227: } else {
8228: push(@niceoptions,$key.':"'.$value.'"');
8229: }
8230: }
8231: my $nicescroll_js = '
8232: $(document).ready(
8233: function() {
8234: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8235: }
8236: );
8237: ';
8238: if ($framecheck) {
8239: $nicescroll_js .= '
8240: function expand_div(caller) {
8241: if (top === self) {
8242: document.getElementById("'.$id.'").style.width = "auto";
8243: document.getElementById("'.$id.'").style.height = "auto";
8244: } else {
8245: try {
8246: if (parent.frames) {
8247: if (parent.frames.length > 1) {
8248: var framesrc = parent.frames[1].location.href;
8249: var currsrc = framesrc.replace(/\#.*$/,"");
8250: if ((caller == "search") || (currsrc == "'.$location.'")) {
8251: document.getElementById("'.$id.'").style.width = "auto";
8252: document.getElementById("'.$id.'").style.height = "auto";
8253: }
8254: }
8255: }
8256: } catch (e) {
8257: return;
8258: }
8259: }
8260: return;
8261: }
8262: ';
8263: }
8264: if ($needjsready) {
8265: $nicescroll_js = '
8266: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8267: } else {
8268: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8269: }
8270: return $nicescroll_js;
8271: }
8272:
1.318 albertel 8273: sub simple_error_page {
1.1075.2.49 raeburn 8274: my ($r,$title,$msg,$args) = @_;
8275: if (ref($args) eq 'HASH') {
8276: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8277: } else {
8278: $msg = &mt($msg);
8279: }
8280:
1.318 albertel 8281: my $page =
8282: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8283: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8284: &Apache::loncommon::end_page();
8285: if (ref($r)) {
8286: $r->print($page);
1.327 albertel 8287: return;
1.318 albertel 8288: }
8289: return $page;
8290: }
1.347 albertel 8291:
8292: {
1.610 albertel 8293: my @row_count;
1.961 onken 8294:
8295: sub start_data_table_count {
8296: unshift(@row_count, 0);
8297: return;
8298: }
8299:
8300: sub end_data_table_count {
8301: shift(@row_count);
8302: return;
8303: }
8304:
1.347 albertel 8305: sub start_data_table {
1.1018 raeburn 8306: my ($add_class,$id) = @_;
1.422 albertel 8307: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8308: my $table_id;
8309: if (defined($id)) {
8310: $table_id = ' id="'.$id.'"';
8311: }
1.961 onken 8312: &start_data_table_count();
1.1018 raeburn 8313: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8314: }
8315:
8316: sub end_data_table {
1.961 onken 8317: &end_data_table_count();
1.389 albertel 8318: return '</table>'."\n";;
1.347 albertel 8319: }
8320:
8321: sub start_data_table_row {
1.974 wenzelju 8322: my ($add_class, $id) = @_;
1.610 albertel 8323: $row_count[0]++;
8324: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8325: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8326: $id = (' id="'.$id.'"') unless ($id eq '');
8327: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8328: }
1.471 banghart 8329:
8330: sub continue_data_table_row {
1.974 wenzelju 8331: my ($add_class, $id) = @_;
1.610 albertel 8332: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8333: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8334: $id = (' id="'.$id.'"') unless ($id eq '');
8335: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8336: }
1.347 albertel 8337:
8338: sub end_data_table_row {
1.389 albertel 8339: return '</tr>'."\n";;
1.347 albertel 8340: }
1.367 www 8341:
1.421 albertel 8342: sub start_data_table_empty_row {
1.707 bisitz 8343: # $row_count[0]++;
1.421 albertel 8344: return '<tr class="LC_empty_row" >'."\n";;
8345: }
8346:
8347: sub end_data_table_empty_row {
8348: return '</tr>'."\n";;
8349: }
8350:
1.367 www 8351: sub start_data_table_header_row {
1.389 albertel 8352: return '<tr class="LC_header_row">'."\n";;
1.367 www 8353: }
8354:
8355: sub end_data_table_header_row {
1.389 albertel 8356: return '</tr>'."\n";;
1.367 www 8357: }
1.890 droeschl 8358:
8359: sub data_table_caption {
8360: my $caption = shift;
8361: return "<caption class=\"LC_caption\">$caption</caption>";
8362: }
1.347 albertel 8363: }
8364:
1.548 albertel 8365: =pod
8366:
8367: =item * &inhibit_menu_check($arg)
8368:
8369: Checks for a inhibitmenu state and generates output to preserve it
8370:
8371: Inputs: $arg - can be any of
8372: - undef - in which case the return value is a string
8373: to add into arguments list of a uri
8374: - 'input' - in which case the return value is a HTML
8375: <form> <input> field of type hidden to
8376: preserve the value
8377: - a url - in which case the return value is the url with
8378: the neccesary cgi args added to preserve the
8379: inhibitmenu state
8380: - a ref to a url - no return value, but the string is
8381: updated to include the neccessary cgi
8382: args to preserve the inhibitmenu state
8383:
8384: =cut
8385:
8386: sub inhibit_menu_check {
8387: my ($arg) = @_;
8388: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8389: if ($arg eq 'input') {
8390: if ($env{'form.inhibitmenu'}) {
8391: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8392: } else {
8393: return
8394: }
8395: }
8396: if ($env{'form.inhibitmenu'}) {
8397: if (ref($arg)) {
8398: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8399: } elsif ($arg eq '') {
8400: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8401: } else {
8402: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8403: }
8404: }
8405: if (!ref($arg)) {
8406: return $arg;
8407: }
8408: }
8409:
1.251 albertel 8410: ###############################################
1.182 matthew 8411:
8412: =pod
8413:
1.549 albertel 8414: =back
8415:
8416: =head1 User Information Routines
8417:
8418: =over 4
8419:
1.405 albertel 8420: =item * &get_users_function()
1.182 matthew 8421:
8422: Used by &bodytag to determine the current users primary role.
8423: Returns either 'student','coordinator','admin', or 'author'.
8424:
8425: =cut
8426:
8427: ###############################################
8428: sub get_users_function {
1.815 tempelho 8429: my $function = 'norole';
1.818 tempelho 8430: if ($env{'request.role'}=~/^(st)/) {
8431: $function='student';
8432: }
1.907 raeburn 8433: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8434: $function='coordinator';
8435: }
1.258 albertel 8436: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8437: $function='admin';
8438: }
1.826 bisitz 8439: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8440: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8441: $function='author';
8442: }
8443: return $function;
1.54 www 8444: }
1.99 www 8445:
8446: ###############################################
8447:
1.233 raeburn 8448: =pod
8449:
1.821 raeburn 8450: =item * &show_course()
8451:
8452: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8453: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8454:
8455: Inputs:
8456: None
8457:
8458: Outputs:
8459: Scalar: 1 if 'Course' to be used, 0 otherwise.
8460:
8461: =cut
8462:
8463: ###############################################
8464: sub show_course {
8465: my $course = !$env{'user.adv'};
8466: if (!$env{'user.adv'}) {
8467: foreach my $env (keys(%env)) {
8468: next if ($env !~ m/^user\.priv\./);
8469: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8470: $course = 0;
8471: last;
8472: }
8473: }
8474: }
8475: return $course;
8476: }
8477:
8478: ###############################################
8479:
8480: =pod
8481:
1.542 raeburn 8482: =item * &check_user_status()
1.274 raeburn 8483:
8484: Determines current status of supplied role for a
8485: specific user. Roles can be active, previous or future.
8486:
8487: Inputs:
8488: user's domain, user's username, course's domain,
1.375 raeburn 8489: course's number, optional section ID.
1.274 raeburn 8490:
8491: Outputs:
8492: role status: active, previous or future.
8493:
8494: =cut
8495:
8496: sub check_user_status {
1.412 raeburn 8497: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8498: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 8499: my @uroles = keys(%userinfo);
1.274 raeburn 8500: my $srchstr;
8501: my $active_chk = 'none';
1.412 raeburn 8502: my $now = time;
1.274 raeburn 8503: if (@uroles > 0) {
1.908 raeburn 8504: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8505: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8506: } else {
1.412 raeburn 8507: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8508: }
8509: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8510: my $role_end = 0;
8511: my $role_start = 0;
8512: $active_chk = 'active';
1.412 raeburn 8513: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8514: $role_end = $1;
8515: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8516: $role_start = $1;
1.274 raeburn 8517: }
8518: }
8519: if ($role_start > 0) {
1.412 raeburn 8520: if ($now < $role_start) {
1.274 raeburn 8521: $active_chk = 'future';
8522: }
8523: }
8524: if ($role_end > 0) {
1.412 raeburn 8525: if ($now > $role_end) {
1.274 raeburn 8526: $active_chk = 'previous';
8527: }
8528: }
8529: }
8530: }
8531: return $active_chk;
8532: }
8533:
8534: ###############################################
8535:
8536: =pod
8537:
1.405 albertel 8538: =item * &get_sections()
1.233 raeburn 8539:
8540: Determines all the sections for a course including
8541: sections with students and sections containing other roles.
1.419 raeburn 8542: Incoming parameters:
8543:
8544: 1. domain
8545: 2. course number
8546: 3. reference to array containing roles for which sections should
8547: be gathered (optional).
8548: 4. reference to array containing status types for which sections
8549: should be gathered (optional).
8550:
8551: If the third argument is undefined, sections are gathered for any role.
8552: If the fourth argument is undefined, sections are gathered for any status.
8553: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8554:
1.374 raeburn 8555: Returns section hash (keys are section IDs, values are
8556: number of users in each section), subject to the
1.419 raeburn 8557: optional roles filter, optional status filter
1.233 raeburn 8558:
8559: =cut
8560:
8561: ###############################################
8562: sub get_sections {
1.419 raeburn 8563: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8564: if (!defined($cdom) || !defined($cnum)) {
8565: my $cid = $env{'request.course.id'};
8566:
8567: return if (!defined($cid));
8568:
8569: $cdom = $env{'course.'.$cid.'.domain'};
8570: $cnum = $env{'course.'.$cid.'.num'};
8571: }
8572:
8573: my %sectioncount;
1.419 raeburn 8574: my $now = time;
1.240 albertel 8575:
1.1075.2.33 raeburn 8576: my $check_students = 1;
8577: my $only_students = 0;
8578: if (ref($possible_roles) eq 'ARRAY') {
8579: if (grep(/^st$/,@{$possible_roles})) {
8580: if (@{$possible_roles} == 1) {
8581: $only_students = 1;
8582: }
8583: } else {
8584: $check_students = 0;
8585: }
8586: }
8587:
8588: if ($check_students) {
1.276 albertel 8589: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8590: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8591: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8592: my $start_index = &Apache::loncoursedata::CL_START();
8593: my $end_index = &Apache::loncoursedata::CL_END();
8594: my $status;
1.366 albertel 8595: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8596: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8597: $data->[$status_index],
8598: $data->[$start_index],
8599: $data->[$end_index]);
8600: if ($stu_status eq 'Active') {
8601: $status = 'active';
8602: } elsif ($end < $now) {
8603: $status = 'previous';
8604: } elsif ($start > $now) {
8605: $status = 'future';
8606: }
8607: if ($section ne '-1' && $section !~ /^\s*$/) {
8608: if ((!defined($possible_status)) || (($status ne '') &&
8609: (grep/^\Q$status\E$/,@{$possible_status}))) {
8610: $sectioncount{$section}++;
8611: }
1.240 albertel 8612: }
8613: }
8614: }
1.1075.2.33 raeburn 8615: if ($only_students) {
8616: return %sectioncount;
8617: }
1.240 albertel 8618: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8619: foreach my $user (sort(keys(%courseroles))) {
8620: if ($user !~ /^(\w{2})/) { next; }
8621: my ($role) = ($user =~ /^(\w{2})/);
8622: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8623: my ($section,$status);
1.240 albertel 8624: if ($role eq 'cr' &&
8625: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8626: $section=$1;
8627: }
8628: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8629: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8630: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8631: if ($end == -1 && $start == -1) {
8632: next; #deleted role
8633: }
8634: if (!defined($possible_status)) {
8635: $sectioncount{$section}++;
8636: } else {
8637: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8638: $status = 'active';
8639: } elsif ($end < $now) {
8640: $status = 'future';
8641: } elsif ($start > $now) {
8642: $status = 'previous';
8643: }
8644: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8645: $sectioncount{$section}++;
8646: }
8647: }
1.233 raeburn 8648: }
1.366 albertel 8649: return %sectioncount;
1.233 raeburn 8650: }
8651:
1.274 raeburn 8652: ###############################################
1.294 raeburn 8653:
8654: =pod
1.405 albertel 8655:
8656: =item * &get_course_users()
8657:
1.275 raeburn 8658: Retrieves usernames:domains for users in the specified course
8659: with specific role(s), and access status.
8660:
8661: Incoming parameters:
1.277 albertel 8662: 1. course domain
8663: 2. course number
8664: 3. access status: users must have - either active,
1.275 raeburn 8665: previous, future, or all.
1.277 albertel 8666: 4. reference to array of permissible roles
1.288 raeburn 8667: 5. reference to array of section restrictions (optional)
8668: 6. reference to results object (hash of hashes).
8669: 7. reference to optional userdata hash
1.609 raeburn 8670: 8. reference to optional statushash
1.630 raeburn 8671: 9. flag if privileged users (except those set to unhide in
8672: course settings) should be excluded
1.609 raeburn 8673: Keys of top level results hash are roles.
1.275 raeburn 8674: Keys of inner hashes are username:domain, with
8675: values set to access type.
1.288 raeburn 8676: Optional userdata hash returns an array with arguments in the
8677: same order as loncoursedata::get_classlist() for student data.
8678:
1.609 raeburn 8679: Optional statushash returns
8680:
1.288 raeburn 8681: Entries for end, start, section and status are blank because
8682: of the possibility of multiple values for non-student roles.
8683:
1.275 raeburn 8684: =cut
1.405 albertel 8685:
1.275 raeburn 8686: ###############################################
1.405 albertel 8687:
1.275 raeburn 8688: sub get_course_users {
1.630 raeburn 8689: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8690: my %idx = ();
1.419 raeburn 8691: my %seclists;
1.288 raeburn 8692:
8693: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8694: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8695: $idx{end} = &Apache::loncoursedata::CL_END();
8696: $idx{start} = &Apache::loncoursedata::CL_START();
8697: $idx{id} = &Apache::loncoursedata::CL_ID();
8698: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8699: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8700: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8701:
1.290 albertel 8702: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8703: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8704: my $now = time;
1.277 albertel 8705: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8706: my $match = 0;
1.412 raeburn 8707: my $secmatch = 0;
1.419 raeburn 8708: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8709: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8710: if ($section eq '') {
8711: $section = 'none';
8712: }
1.291 albertel 8713: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8714: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8715: $secmatch = 1;
8716: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8717: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8718: $secmatch = 1;
8719: }
8720: } else {
1.419 raeburn 8721: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8722: $secmatch = 1;
8723: }
1.290 albertel 8724: }
1.412 raeburn 8725: if (!$secmatch) {
8726: next;
8727: }
1.419 raeburn 8728: }
1.275 raeburn 8729: if (defined($$types{'active'})) {
1.288 raeburn 8730: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8731: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8732: $match = 1;
1.275 raeburn 8733: }
8734: }
8735: if (defined($$types{'previous'})) {
1.609 raeburn 8736: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8737: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8738: $match = 1;
1.275 raeburn 8739: }
8740: }
8741: if (defined($$types{'future'})) {
1.609 raeburn 8742: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8743: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8744: $match = 1;
1.275 raeburn 8745: }
8746: }
1.609 raeburn 8747: if ($match) {
8748: push(@{$seclists{$student}},$section);
8749: if (ref($userdata) eq 'HASH') {
8750: $$userdata{$student} = $$classlist{$student};
8751: }
8752: if (ref($statushash) eq 'HASH') {
8753: $statushash->{$student}{'st'}{$section} = $status;
8754: }
1.288 raeburn 8755: }
1.275 raeburn 8756: }
8757: }
1.412 raeburn 8758: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8759: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8760: my $now = time;
1.609 raeburn 8761: my %displaystatus = ( previous => 'Expired',
8762: active => 'Active',
8763: future => 'Future',
8764: );
1.1075.2.36 raeburn 8765: my (%nothide,@possdoms);
1.630 raeburn 8766: if ($hidepriv) {
8767: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8768: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8769: if ($user !~ /:/) {
8770: $nothide{join(':',split(/[\@]/,$user))}=1;
8771: } else {
8772: $nothide{$user} = 1;
8773: }
8774: }
1.1075.2.36 raeburn 8775: my @possdoms = ($cdom);
8776: if ($coursehash{'checkforpriv'}) {
8777: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8778: }
1.630 raeburn 8779: }
1.439 raeburn 8780: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8781: my $match = 0;
1.412 raeburn 8782: my $secmatch = 0;
1.439 raeburn 8783: my $status;
1.412 raeburn 8784: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8785: $user =~ s/:$//;
1.439 raeburn 8786: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8787: if ($end == -1 || $start == -1) {
8788: next;
8789: }
8790: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8791: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8792: my ($uname,$udom) = split(/:/,$user);
8793: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8794: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8795: $secmatch = 1;
8796: } elsif ($usec eq '') {
1.420 albertel 8797: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8798: $secmatch = 1;
8799: }
8800: } else {
8801: if (grep(/^\Q$usec\E$/,@{$sections})) {
8802: $secmatch = 1;
8803: }
8804: }
8805: if (!$secmatch) {
8806: next;
8807: }
1.288 raeburn 8808: }
1.419 raeburn 8809: if ($usec eq '') {
8810: $usec = 'none';
8811: }
1.275 raeburn 8812: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8813: if ($hidepriv) {
1.1075.2.36 raeburn 8814: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8815: (!$nothide{$uname.':'.$udom})) {
8816: next;
8817: }
8818: }
1.503 raeburn 8819: if ($end > 0 && $end < $now) {
1.439 raeburn 8820: $status = 'previous';
8821: } elsif ($start > $now) {
8822: $status = 'future';
8823: } else {
8824: $status = 'active';
8825: }
1.277 albertel 8826: foreach my $type (keys(%{$types})) {
1.275 raeburn 8827: if ($status eq $type) {
1.420 albertel 8828: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8829: push(@{$$users{$role}{$user}},$type);
8830: }
1.288 raeburn 8831: $match = 1;
8832: }
8833: }
1.419 raeburn 8834: if (($match) && (ref($userdata) eq 'HASH')) {
8835: if (!exists($$userdata{$uname.':'.$udom})) {
8836: &get_user_info($udom,$uname,\%idx,$userdata);
8837: }
1.420 albertel 8838: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8839: push(@{$seclists{$uname.':'.$udom}},$usec);
8840: }
1.609 raeburn 8841: if (ref($statushash) eq 'HASH') {
8842: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8843: }
1.275 raeburn 8844: }
8845: }
8846: }
8847: }
1.290 albertel 8848: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8849: if ((defined($cdom)) && (defined($cnum))) {
8850: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8851: if ( defined($csettings{'internal.courseowner'}) ) {
8852: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8853: next if ($owner eq '');
8854: my ($ownername,$ownerdom);
8855: if ($owner =~ /^([^:]+):([^:]+)$/) {
8856: $ownername = $1;
8857: $ownerdom = $2;
8858: } else {
8859: $ownername = $owner;
8860: $ownerdom = $cdom;
8861: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8862: }
8863: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8864: if (defined($userdata) &&
1.609 raeburn 8865: !exists($$userdata{$owner})) {
8866: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8867: if (!grep(/^none$/,@{$seclists{$owner}})) {
8868: push(@{$seclists{$owner}},'none');
8869: }
8870: if (ref($statushash) eq 'HASH') {
8871: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8872: }
1.290 albertel 8873: }
1.279 raeburn 8874: }
8875: }
8876: }
1.419 raeburn 8877: foreach my $user (keys(%seclists)) {
8878: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8879: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8880: }
1.275 raeburn 8881: }
8882: return;
8883: }
8884:
1.288 raeburn 8885: sub get_user_info {
8886: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8887: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8888: &plainname($uname,$udom,'lastname');
1.291 albertel 8889: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8890: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8891: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8892: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8893: return;
8894: }
1.275 raeburn 8895:
1.472 raeburn 8896: ###############################################
8897:
8898: =pod
8899:
8900: =item * &get_user_quota()
8901:
1.1075.2.41 raeburn 8902: Retrieves quota assigned for storage of user files.
8903: Default is to report quota for portfolio files.
1.472 raeburn 8904:
8905: Incoming parameters:
8906: 1. user's username
8907: 2. user's domain
1.1075.2.41 raeburn 8908: 3. quota name - portfolio, author, or course
8909: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 8910: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 8911: course
1.472 raeburn 8912:
8913: Returns:
1.1075.2.58 raeburn 8914: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 8915: 2. (Optional) Type of setting: custom or default
8916: (individually assigned or default for user's
8917: institutional status).
8918: 3. (Optional) - User's institutional status (e.g., faculty, staff
8919: or student - types as defined in localenroll::inst_usertypes
8920: for user's domain, which determines default quota for user.
8921: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8922:
8923: If a value has been stored in the user's environment,
1.536 raeburn 8924: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 8925: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8926:
8927: =cut
8928:
8929: ###############################################
8930:
8931:
8932: sub get_user_quota {
1.1075.2.42 raeburn 8933: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8934: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8935: if (!defined($udom)) {
8936: $udom = $env{'user.domain'};
8937: }
8938: if (!defined($uname)) {
8939: $uname = $env{'user.name'};
8940: }
8941: if (($udom eq '' || $uname eq '') ||
8942: ($udom eq 'public') && ($uname eq 'public')) {
8943: $quota = 0;
1.536 raeburn 8944: $quotatype = 'default';
8945: $defquota = 0;
1.472 raeburn 8946: } else {
1.536 raeburn 8947: my $inststatus;
1.1075.2.41 raeburn 8948: if ($quotaname eq 'course') {
8949: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8950: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8951: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8952: } else {
8953: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8954: $quota = $cenv{'internal.uploadquota'};
8955: }
1.536 raeburn 8956: } else {
1.1075.2.41 raeburn 8957: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8958: if ($quotaname eq 'author') {
8959: $quota = $env{'environment.authorquota'};
8960: } else {
8961: $quota = $env{'environment.portfolioquota'};
8962: }
8963: $inststatus = $env{'environment.inststatus'};
8964: } else {
8965: my %userenv =
8966: &Apache::lonnet::get('environment',['portfolioquota',
8967: 'authorquota','inststatus'],$udom,$uname);
8968: my ($tmp) = keys(%userenv);
8969: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8970: if ($quotaname eq 'author') {
8971: $quota = $userenv{'authorquota'};
8972: } else {
8973: $quota = $userenv{'portfolioquota'};
8974: }
8975: $inststatus = $userenv{'inststatus'};
8976: } else {
8977: undef(%userenv);
8978: }
8979: }
8980: }
8981: if ($quota eq '' || wantarray) {
8982: if ($quotaname eq 'course') {
8983: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 8984: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
8985: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 8986: $defquota = $domdefs{$crstype.'quota'};
8987: }
8988: if ($defquota eq '') {
8989: $defquota = 500;
8990: }
1.1075.2.41 raeburn 8991: } else {
8992: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8993: }
8994: if ($quota eq '') {
8995: $quota = $defquota;
8996: $quotatype = 'default';
8997: } else {
8998: $quotatype = 'custom';
8999: }
1.472 raeburn 9000: }
9001: }
1.536 raeburn 9002: if (wantarray) {
9003: return ($quota,$quotatype,$settingstatus,$defquota);
9004: } else {
9005: return $quota;
9006: }
1.472 raeburn 9007: }
9008:
9009: ###############################################
9010:
9011: =pod
9012:
9013: =item * &default_quota()
9014:
1.536 raeburn 9015: Retrieves default quota assigned for storage of user portfolio files,
9016: given an (optional) user's institutional status.
1.472 raeburn 9017:
9018: Incoming parameters:
1.1075.2.42 raeburn 9019:
1.472 raeburn 9020: 1. domain
1.536 raeburn 9021: 2. (Optional) institutional status(es). This is a : separated list of
9022: status types (e.g., faculty, staff, student etc.)
9023: which apply to the user for whom the default is being retrieved.
9024: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9025: default quota will be returned.
9026: 3. quota name - portfolio, author, or course
9027: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9028:
9029: Returns:
1.1075.2.42 raeburn 9030:
1.1075.2.58 raeburn 9031: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9032: 2. (Optional) institutional type which determined the value of the
9033: default quota.
1.472 raeburn 9034:
9035: If a value has been stored in the domain's configuration db,
9036: it will return that, otherwise it returns 20 (for backwards
9037: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9038: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9039:
1.536 raeburn 9040: If the user's status includes multiple types (e.g., staff and student),
9041: the largest default quota which applies to the user determines the
9042: default quota returned.
9043:
1.472 raeburn 9044: =cut
9045:
9046: ###############################################
9047:
9048:
9049: sub default_quota {
1.1075.2.41 raeburn 9050: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9051: my ($defquota,$settingstatus);
9052: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9053: ['quotas'],$udom);
1.1075.2.41 raeburn 9054: my $key = 'defaultquota';
9055: if ($quotaname eq 'author') {
9056: $key = 'authorquota';
9057: }
1.622 raeburn 9058: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9059: if ($inststatus ne '') {
1.765 raeburn 9060: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9061: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9062: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9063: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9064: if ($defquota eq '') {
1.1075.2.41 raeburn 9065: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9066: $settingstatus = $item;
1.1075.2.41 raeburn 9067: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9068: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9069: $settingstatus = $item;
9070: }
9071: }
1.1075.2.41 raeburn 9072: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9073: if ($quotahash{'quotas'}{$item} ne '') {
9074: if ($defquota eq '') {
9075: $defquota = $quotahash{'quotas'}{$item};
9076: $settingstatus = $item;
9077: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9078: $defquota = $quotahash{'quotas'}{$item};
9079: $settingstatus = $item;
9080: }
1.536 raeburn 9081: }
9082: }
9083: }
9084: }
9085: if ($defquota eq '') {
1.1075.2.41 raeburn 9086: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9087: $defquota = $quotahash{'quotas'}{$key}{'default'};
9088: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9089: $defquota = $quotahash{'quotas'}{'default'};
9090: }
1.536 raeburn 9091: $settingstatus = 'default';
1.1075.2.42 raeburn 9092: if ($defquota eq '') {
9093: if ($quotaname eq 'author') {
9094: $defquota = 500;
9095: }
9096: }
1.536 raeburn 9097: }
9098: } else {
9099: $settingstatus = 'default';
1.1075.2.41 raeburn 9100: if ($quotaname eq 'author') {
9101: $defquota = 500;
9102: } else {
9103: $defquota = 20;
9104: }
1.536 raeburn 9105: }
9106: if (wantarray) {
9107: return ($defquota,$settingstatus);
1.472 raeburn 9108: } else {
1.536 raeburn 9109: return $defquota;
1.472 raeburn 9110: }
9111: }
9112:
1.1075.2.41 raeburn 9113: ###############################################
9114:
9115: =pod
9116:
1.1075.2.42 raeburn 9117: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9118:
9119: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9120: of existing file within authoring space will cause quota for the authoring
9121: space to be exceeded.
9122:
9123: Same, if upload of a file directly to a course/community via Course Editor
9124: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9125:
1.1075.2.61 raeburn 9126: Inputs: 7
1.1075.2.42 raeburn 9127: 1. username or coursenum
1.1075.2.41 raeburn 9128: 2. domain
1.1075.2.42 raeburn 9129: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9130: 4. filename of file for which action is being requested
9131: 5. filesize (kB) of file
9132: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9133: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9134:
9135: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9136: otherwise return null.
9137:
1.1075.2.42 raeburn 9138: =back
9139:
1.1075.2.41 raeburn 9140: =cut
9141:
1.1075.2.42 raeburn 9142: sub excess_filesize_warning {
1.1075.2.59 raeburn 9143: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9144: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9145: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9146: if ($context eq 'author') {
9147: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9148: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9149: } else {
9150: foreach my $subdir ('docs','supplemental') {
9151: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9152: }
9153: }
1.1075.2.41 raeburn 9154: $disk_quota = int($disk_quota * 1000);
9155: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9156: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9157: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9158: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9159: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9160: $disk_quota,$current_disk_usage).
9161: '</p>';
9162: }
9163: return;
9164: }
9165:
9166: ###############################################
9167:
9168:
1.384 raeburn 9169: sub get_secgrprole_info {
9170: my ($cdom,$cnum,$needroles,$type) = @_;
9171: my %sections_count = &get_sections($cdom,$cnum);
9172: my @sections = (sort {$a <=> $b} keys(%sections_count));
9173: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9174: my @groups = sort(keys(%curr_groups));
9175: my $allroles = [];
9176: my $rolehash;
9177: my $accesshash = {
9178: active => 'Currently has access',
9179: future => 'Will have future access',
9180: previous => 'Previously had access',
9181: };
9182: if ($needroles) {
9183: $rolehash = {'all' => 'all'};
1.385 albertel 9184: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9185: if (&Apache::lonnet::error(%user_roles)) {
9186: undef(%user_roles);
9187: }
9188: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9189: my ($role)=split(/\:/,$item,2);
9190: if ($role eq 'cr') { next; }
9191: if ($role =~ /^cr/) {
9192: $$rolehash{$role} = (split('/',$role))[3];
9193: } else {
9194: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9195: }
9196: }
9197: foreach my $key (sort(keys(%{$rolehash}))) {
9198: push(@{$allroles},$key);
9199: }
9200: push (@{$allroles},'st');
9201: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9202: }
9203: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9204: }
9205:
1.555 raeburn 9206: sub user_picker {
1.994 raeburn 9207: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9208: my $currdom = $dom;
9209: my %curr_selected = (
9210: srchin => 'dom',
1.580 raeburn 9211: srchby => 'lastname',
1.555 raeburn 9212: );
9213: my $srchterm;
1.625 raeburn 9214: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9215: if ($srch->{'srchby'} ne '') {
9216: $curr_selected{'srchby'} = $srch->{'srchby'};
9217: }
9218: if ($srch->{'srchin'} ne '') {
9219: $curr_selected{'srchin'} = $srch->{'srchin'};
9220: }
9221: if ($srch->{'srchtype'} ne '') {
9222: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9223: }
9224: if ($srch->{'srchdomain'} ne '') {
9225: $currdom = $srch->{'srchdomain'};
9226: }
9227: $srchterm = $srch->{'srchterm'};
9228: }
9229: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 9230: 'usr' => 'Search criteria',
1.563 raeburn 9231: 'doma' => 'Domain/institution to search',
1.558 albertel 9232: 'uname' => 'username',
9233: 'lastname' => 'last name',
1.555 raeburn 9234: 'lastfirst' => 'last name, first name',
1.558 albertel 9235: 'crs' => 'in this course',
1.576 raeburn 9236: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9237: 'alc' => 'all LON-CAPA',
1.573 raeburn 9238: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9239: 'exact' => 'is',
9240: 'contains' => 'contains',
1.569 raeburn 9241: 'begins' => 'begins with',
1.571 raeburn 9242: 'youm' => "You must include some text to search for.",
9243: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9244: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9245: 'yomc' => "You must choose a domain when using an institutional directory search.",
9246: 'ymcd' => "You must choose a domain when using a domain search.",
9247: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9248: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9249: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9250: );
1.563 raeburn 9251: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9252: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9253:
9254: my @srchins = ('crs','dom','alc','instd');
9255:
9256: foreach my $option (@srchins) {
9257: # FIXME 'alc' option unavailable until
9258: # loncreateuser::print_user_query_page()
9259: # has been completed.
9260: next if ($option eq 'alc');
1.880 raeburn 9261: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9262: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9263: if ($curr_selected{'srchin'} eq $option) {
9264: $srchinsel .= '
9265: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9266: } else {
9267: $srchinsel .= '
9268: <option value="'.$option.'">'.$lt{$option}.'</option>';
9269: }
1.555 raeburn 9270: }
1.563 raeburn 9271: $srchinsel .= "\n </select>\n";
1.555 raeburn 9272:
9273: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9274: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9275: if ($curr_selected{'srchby'} eq $option) {
9276: $srchbysel .= '
9277: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9278: } else {
9279: $srchbysel .= '
9280: <option value="'.$option.'">'.$lt{$option}.'</option>';
9281: }
9282: }
9283: $srchbysel .= "\n </select>\n";
9284:
9285: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9286: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9287: if ($curr_selected{'srchtype'} eq $option) {
9288: $srchtypesel .= '
9289: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9290: } else {
9291: $srchtypesel .= '
9292: <option value="'.$option.'">'.$lt{$option}.'</option>';
9293: }
9294: }
9295: $srchtypesel .= "\n </select>\n";
9296:
1.558 albertel 9297: my ($newuserscript,$new_user_create);
1.994 raeburn 9298: my $context_dom = $env{'request.role.domain'};
9299: if ($context eq 'requestcrs') {
9300: if ($env{'form.coursedom'} ne '') {
9301: $context_dom = $env{'form.coursedom'};
9302: }
9303: }
1.556 raeburn 9304: if ($forcenewuser) {
1.576 raeburn 9305: if (ref($srch) eq 'HASH') {
1.994 raeburn 9306: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9307: if ($cancreate) {
9308: $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>';
9309: } else {
1.799 bisitz 9310: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9311: my %usertypetext = (
9312: official => 'institutional',
9313: unofficial => 'non-institutional',
9314: );
1.799 bisitz 9315: $new_user_create = '<p class="LC_warning">'
9316: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9317: .' '
9318: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9319: ,'<a href="'.$helplink.'">','</a>')
9320: .'</p><br />';
1.627 raeburn 9321: }
1.576 raeburn 9322: }
9323: }
9324:
1.556 raeburn 9325: $newuserscript = <<"ENDSCRIPT";
9326:
1.570 raeburn 9327: function setSearch(createnew,callingForm) {
1.556 raeburn 9328: if (createnew == 1) {
1.570 raeburn 9329: for (var i=0; i<callingForm.srchby.length; i++) {
9330: if (callingForm.srchby.options[i].value == 'uname') {
9331: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9332: }
9333: }
1.570 raeburn 9334: for (var i=0; i<callingForm.srchin.length; i++) {
9335: if ( callingForm.srchin.options[i].value == 'dom') {
9336: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9337: }
9338: }
1.570 raeburn 9339: for (var i=0; i<callingForm.srchtype.length; i++) {
9340: if (callingForm.srchtype.options[i].value == 'exact') {
9341: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9342: }
9343: }
1.570 raeburn 9344: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9345: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9346: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9347: }
9348: }
9349: }
9350: }
9351: ENDSCRIPT
1.558 albertel 9352:
1.556 raeburn 9353: }
9354:
1.555 raeburn 9355: my $output = <<"END_BLOCK";
1.556 raeburn 9356: <script type="text/javascript">
1.824 bisitz 9357: // <![CDATA[
1.570 raeburn 9358: function validateEntry(callingForm) {
1.558 albertel 9359:
1.556 raeburn 9360: var checkok = 1;
1.558 albertel 9361: var srchin;
1.570 raeburn 9362: for (var i=0; i<callingForm.srchin.length; i++) {
9363: if ( callingForm.srchin[i].checked ) {
9364: srchin = callingForm.srchin[i].value;
1.558 albertel 9365: }
9366: }
9367:
1.570 raeburn 9368: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9369: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9370: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9371: var srchterm = callingForm.srchterm.value;
9372: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9373: var msg = "";
9374:
9375: if (srchterm == "") {
9376: checkok = 0;
1.571 raeburn 9377: msg += "$lt{'youm'}\\n";
1.556 raeburn 9378: }
9379:
1.569 raeburn 9380: if (srchtype== 'begins') {
9381: if (srchterm.length < 2) {
9382: checkok = 0;
1.571 raeburn 9383: msg += "$lt{'thte'}\\n";
1.569 raeburn 9384: }
9385: }
9386:
1.556 raeburn 9387: if (srchtype== 'contains') {
9388: if (srchterm.length < 3) {
9389: checkok = 0;
1.571 raeburn 9390: msg += "$lt{'thet'}\\n";
1.556 raeburn 9391: }
9392: }
9393: if (srchin == 'instd') {
9394: if (srchdomain == '') {
9395: checkok = 0;
1.571 raeburn 9396: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9397: }
9398: }
9399: if (srchin == 'dom') {
9400: if (srchdomain == '') {
9401: checkok = 0;
1.571 raeburn 9402: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9403: }
9404: }
9405: if (srchby == 'lastfirst') {
9406: if (srchterm.indexOf(",") == -1) {
9407: checkok = 0;
1.571 raeburn 9408: msg += "$lt{'whus'}\\n";
1.556 raeburn 9409: }
9410: if (srchterm.indexOf(",") == srchterm.length -1) {
9411: checkok = 0;
1.571 raeburn 9412: msg += "$lt{'whse'}\\n";
1.556 raeburn 9413: }
9414: }
9415: if (checkok == 0) {
1.571 raeburn 9416: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9417: return;
9418: }
9419: if (checkok == 1) {
1.570 raeburn 9420: callingForm.submit();
1.556 raeburn 9421: }
9422: }
9423:
9424: $newuserscript
9425:
1.824 bisitz 9426: // ]]>
1.556 raeburn 9427: </script>
1.558 albertel 9428:
9429: $new_user_create
9430:
1.555 raeburn 9431: END_BLOCK
1.558 albertel 9432:
1.876 raeburn 9433: $output .= &Apache::lonhtmlcommon::start_pick_box().
9434: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9435: $domform.
9436: &Apache::lonhtmlcommon::row_closure().
9437: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9438: $srchbysel.
9439: $srchtypesel.
9440: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9441: $srchinsel.
9442: &Apache::lonhtmlcommon::row_closure(1).
9443: &Apache::lonhtmlcommon::end_pick_box().
9444: '<br />';
1.555 raeburn 9445: return $output;
9446: }
9447:
1.612 raeburn 9448: sub user_rule_check {
1.615 raeburn 9449: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9450: my $response;
9451: if (ref($usershash) eq 'HASH') {
9452: foreach my $user (keys(%{$usershash})) {
9453: my ($uname,$udom) = split(/:/,$user);
9454: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9455: my ($id,$newuser);
1.612 raeburn 9456: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9457: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9458: $id = $usershash->{$user}->{'id'};
9459: }
9460: my $inst_response;
9461: if (ref($checks) eq 'HASH') {
9462: if (defined($checks->{'username'})) {
1.615 raeburn 9463: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9464: &Apache::lonnet::get_instuser($udom,$uname);
9465: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9466: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9467: &Apache::lonnet::get_instuser($udom,undef,$id);
9468: }
1.615 raeburn 9469: } else {
9470: ($inst_response,%{$inst_results->{$user}}) =
9471: &Apache::lonnet::get_instuser($udom,$uname);
9472: return;
1.612 raeburn 9473: }
1.615 raeburn 9474: if (!$got_rules->{$udom}) {
1.612 raeburn 9475: my %domconfig = &Apache::lonnet::get_dom('configuration',
9476: ['usercreation'],$udom);
9477: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9478: foreach my $item ('username','id') {
1.612 raeburn 9479: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9480: $$curr_rules{$udom}{$item} =
9481: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9482: }
9483: }
9484: }
1.615 raeburn 9485: $got_rules->{$udom} = 1;
1.585 raeburn 9486: }
1.612 raeburn 9487: foreach my $item (keys(%{$checks})) {
9488: if (ref($$curr_rules{$udom}) eq 'HASH') {
9489: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9490: if (@{$$curr_rules{$udom}{$item}} > 0) {
9491: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9492: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9493: if ($rule_check{$rule}) {
9494: $$rulematch{$user}{$item} = $rule;
9495: if ($inst_response eq 'ok') {
1.615 raeburn 9496: if (ref($inst_results) eq 'HASH') {
9497: if (ref($inst_results->{$user}) eq 'HASH') {
9498: if (keys(%{$inst_results->{$user}}) == 0) {
9499: $$alerts{$item}{$udom}{$uname} = 1;
9500: }
1.612 raeburn 9501: }
9502: }
1.615 raeburn 9503: }
9504: last;
1.585 raeburn 9505: }
9506: }
9507: }
9508: }
9509: }
9510: }
9511: }
9512: }
1.612 raeburn 9513: return;
9514: }
9515:
9516: sub user_rule_formats {
9517: my ($domain,$domdesc,$curr_rules,$check) = @_;
9518: my %text = (
9519: 'username' => 'Usernames',
9520: 'id' => 'IDs',
9521: );
9522: my $output;
9523: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9524: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9525: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 9526: $output = '<br />'.
9527: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9528: '<span class="LC_cusr_emph">','</span>',$domdesc).
9529: ' <ul>';
1.612 raeburn 9530: foreach my $rule (@{$ruleorder}) {
9531: if (ref($curr_rules) eq 'ARRAY') {
9532: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9533: if (ref($rules->{$rule}) eq 'HASH') {
9534: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9535: $rules->{$rule}{'desc'}.'</li>';
9536: }
9537: }
9538: }
9539: }
9540: $output .= '</ul>';
9541: }
9542: }
9543: return $output;
9544: }
9545:
9546: sub instrule_disallow_msg {
1.615 raeburn 9547: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9548: my $response;
9549: my %text = (
9550: item => 'username',
9551: items => 'usernames',
9552: match => 'matches',
9553: do => 'does',
9554: action => 'a username',
9555: one => 'one',
9556: );
9557: if ($count > 1) {
9558: $text{'item'} = 'usernames';
9559: $text{'match'} ='match';
9560: $text{'do'} = 'do';
9561: $text{'action'} = 'usernames',
9562: $text{'one'} = 'ones';
9563: }
9564: if ($checkitem eq 'id') {
9565: $text{'items'} = 'IDs';
9566: $text{'item'} = 'ID';
9567: $text{'action'} = 'an ID';
1.615 raeburn 9568: if ($count > 1) {
9569: $text{'item'} = 'IDs';
9570: $text{'action'} = 'IDs';
9571: }
1.612 raeburn 9572: }
1.674 bisitz 9573: $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 9574: if ($mode eq 'upload') {
9575: if ($checkitem eq 'username') {
9576: $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'}.");
9577: } elsif ($checkitem eq 'id') {
1.674 bisitz 9578: $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 9579: }
1.669 raeburn 9580: } elsif ($mode eq 'selfcreate') {
9581: if ($checkitem eq 'id') {
9582: $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.");
9583: }
1.615 raeburn 9584: } else {
9585: if ($checkitem eq 'username') {
9586: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9587: } elsif ($checkitem eq 'id') {
9588: $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.");
9589: }
1.612 raeburn 9590: }
9591: return $response;
1.585 raeburn 9592: }
9593:
1.624 raeburn 9594: sub personal_data_fieldtitles {
9595: my %fieldtitles = &Apache::lonlocal::texthash (
9596: id => 'Student/Employee ID',
9597: permanentemail => 'E-mail address',
9598: lastname => 'Last Name',
9599: firstname => 'First Name',
9600: middlename => 'Middle Name',
9601: generation => 'Generation',
9602: gen => 'Generation',
1.765 raeburn 9603: inststatus => 'Affiliation',
1.624 raeburn 9604: );
9605: return %fieldtitles;
9606: }
9607:
1.642 raeburn 9608: sub sorted_inst_types {
9609: my ($dom) = @_;
1.1075.2.70 raeburn 9610: my ($usertypes,$order);
9611: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9612: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
9613: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
9614: $order = $domdefaults{'inststatus'}{'inststatusorder'};
9615: } else {
9616: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9617: }
1.642 raeburn 9618: my $othertitle = &mt('All users');
9619: if ($env{'request.course.id'}) {
1.668 raeburn 9620: $othertitle = &mt('Any users');
1.642 raeburn 9621: }
9622: my @types;
9623: if (ref($order) eq 'ARRAY') {
9624: @types = @{$order};
9625: }
9626: if (@types == 0) {
9627: if (ref($usertypes) eq 'HASH') {
9628: @types = sort(keys(%{$usertypes}));
9629: }
9630: }
9631: if (keys(%{$usertypes}) > 0) {
9632: $othertitle = &mt('Other users');
9633: }
9634: return ($othertitle,$usertypes,\@types);
9635: }
9636:
1.645 raeburn 9637: sub get_institutional_codes {
9638: my ($settings,$allcourses,$LC_code) = @_;
9639: # Get complete list of course sections to update
9640: my @currsections = ();
9641: my @currxlists = ();
9642: my $coursecode = $$settings{'internal.coursecode'};
9643:
9644: if ($$settings{'internal.sectionnums'} ne '') {
9645: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9646: }
9647:
9648: if ($$settings{'internal.crosslistings'} ne '') {
9649: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9650: }
9651:
9652: if (@currxlists > 0) {
9653: foreach (@currxlists) {
9654: if (m/^([^:]+):(\w*)$/) {
9655: unless (grep/^$1$/,@{$allcourses}) {
9656: push @{$allcourses},$1;
9657: $$LC_code{$1} = $2;
9658: }
9659: }
9660: }
9661: }
9662:
9663: if (@currsections > 0) {
9664: foreach (@currsections) {
9665: if (m/^(\w+):(\w*)$/) {
9666: my $sec = $coursecode.$1;
9667: my $lc_sec = $2;
9668: unless (grep/^$sec$/,@{$allcourses}) {
9669: push @{$allcourses},$sec;
9670: $$LC_code{$sec} = $lc_sec;
9671: }
9672: }
9673: }
9674: }
9675: return;
9676: }
9677:
1.971 raeburn 9678: sub get_standard_codeitems {
9679: return ('Year','Semester','Department','Number','Section');
9680: }
9681:
1.112 bowersj2 9682: =pod
9683:
1.780 raeburn 9684: =head1 Slot Helpers
9685:
9686: =over 4
9687:
9688: =item * sorted_slots()
9689:
1.1040 raeburn 9690: Sorts an array of slot names in order of an optional sort key,
9691: default sort is by slot start time (earliest first).
1.780 raeburn 9692:
9693: Inputs:
9694:
9695: =over 4
9696:
9697: slotsarr - Reference to array of unsorted slot names.
9698:
9699: slots - Reference to hash of hash, where outer hash keys are slot names.
9700:
1.1040 raeburn 9701: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9702:
1.549 albertel 9703: =back
9704:
1.780 raeburn 9705: Returns:
9706:
9707: =over 4
9708:
1.1040 raeburn 9709: sorted - An array of slot names sorted by a specified sort key
9710: (default sort key is start time of the slot).
1.780 raeburn 9711:
9712: =back
9713:
9714: =cut
9715:
9716:
9717: sub sorted_slots {
1.1040 raeburn 9718: my ($slotsarr,$slots,$sortkey) = @_;
9719: if ($sortkey eq '') {
9720: $sortkey = 'starttime';
9721: }
1.780 raeburn 9722: my @sorted;
9723: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9724: @sorted =
9725: sort {
9726: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9727: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9728: }
9729: if (ref($slots->{$a})) { return -1;}
9730: if (ref($slots->{$b})) { return 1;}
9731: return 0;
9732: } @{$slotsarr};
9733: }
9734: return @sorted;
9735: }
9736:
1.1040 raeburn 9737: =pod
9738:
9739: =item * get_future_slots()
9740:
9741: Inputs:
9742:
9743: =over 4
9744:
9745: cnum - course number
9746:
9747: cdom - course domain
9748:
9749: now - current UNIX time
9750:
9751: symb - optional symb
9752:
9753: =back
9754:
9755: Returns:
9756:
9757: =over 4
9758:
9759: sorted_reservable - ref to array of student_schedulable slots currently
9760: reservable, ordered by end date of reservation period.
9761:
9762: reservable_now - ref to hash of student_schedulable slots currently
9763: reservable.
9764:
9765: Keys in inner hash are:
9766: (a) symb: either blank or symb to which slot use is restricted.
9767: (b) endreserve: end date of reservation period.
9768:
9769: sorted_future - ref to array of student_schedulable slots reservable in
9770: the future, ordered by start date of reservation period.
9771:
9772: future_reservable - ref to hash of student_schedulable slots reservable
9773: in the future.
9774:
9775: Keys in inner hash are:
9776: (a) symb: either blank or symb to which slot use is restricted.
9777: (b) startreserve: start date of reservation period.
9778:
9779: =back
9780:
9781: =cut
9782:
9783: sub get_future_slots {
9784: my ($cnum,$cdom,$now,$symb) = @_;
9785: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9786: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9787: foreach my $slot (keys(%slots)) {
9788: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9789: if ($symb) {
9790: next if (($slots{$slot}->{'symb'} ne '') &&
9791: ($slots{$slot}->{'symb'} ne $symb));
9792: }
9793: if (($slots{$slot}->{'starttime'} > $now) &&
9794: ($slots{$slot}->{'endtime'} > $now)) {
9795: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9796: my $userallowed = 0;
9797: if ($slots{$slot}->{'allowedsections'}) {
9798: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9799: if (!defined($env{'request.role.sec'})
9800: && grep(/^No section assigned$/,@allowed_sec)) {
9801: $userallowed=1;
9802: } else {
9803: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9804: $userallowed=1;
9805: }
9806: }
9807: unless ($userallowed) {
9808: if (defined($env{'request.course.groups'})) {
9809: my @groups = split(/:/,$env{'request.course.groups'});
9810: foreach my $group (@groups) {
9811: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9812: $userallowed=1;
9813: last;
9814: }
9815: }
9816: }
9817: }
9818: }
9819: if ($slots{$slot}->{'allowedusers'}) {
9820: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9821: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9822: if (grep(/^\Q$user\E$/,@allowed_users)) {
9823: $userallowed = 1;
9824: }
9825: }
9826: next unless($userallowed);
9827: }
9828: my $startreserve = $slots{$slot}->{'startreserve'};
9829: my $endreserve = $slots{$slot}->{'endreserve'};
9830: my $symb = $slots{$slot}->{'symb'};
9831: if (($startreserve < $now) &&
9832: (!$endreserve || $endreserve > $now)) {
9833: my $lastres = $endreserve;
9834: if (!$lastres) {
9835: $lastres = $slots{$slot}->{'starttime'};
9836: }
9837: $reservable_now{$slot} = {
9838: symb => $symb,
9839: endreserve => $lastres
9840: };
9841: } elsif (($startreserve > $now) &&
9842: (!$endreserve || $endreserve > $startreserve)) {
9843: $future_reservable{$slot} = {
9844: symb => $symb,
9845: startreserve => $startreserve
9846: };
9847: }
9848: }
9849: }
9850: my @unsorted_reservable = keys(%reservable_now);
9851: if (@unsorted_reservable > 0) {
9852: @sorted_reservable =
9853: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9854: }
9855: my @unsorted_future = keys(%future_reservable);
9856: if (@unsorted_future > 0) {
9857: @sorted_future =
9858: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9859: }
9860: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9861: }
1.780 raeburn 9862:
9863: =pod
9864:
1.1057 foxr 9865: =back
9866:
1.549 albertel 9867: =head1 HTTP Helpers
9868:
9869: =over 4
9870:
1.648 raeburn 9871: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9872:
1.258 albertel 9873: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9874: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9875: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9876:
9877: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9878: $possible_names is an ref to an array of form element names. As an example:
9879: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9880: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9881:
9882: =cut
1.1 albertel 9883:
1.6 albertel 9884: sub get_unprocessed_cgi {
1.25 albertel 9885: my ($query,$possible_names)= @_;
1.26 matthew 9886: # $Apache::lonxml::debug=1;
1.356 albertel 9887: foreach my $pair (split(/&/,$query)) {
9888: my ($name, $value) = split(/=/,$pair);
1.369 www 9889: $name = &unescape($name);
1.25 albertel 9890: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9891: $value =~ tr/+/ /;
9892: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9893: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9894: }
1.16 harris41 9895: }
1.6 albertel 9896: }
9897:
1.112 bowersj2 9898: =pod
9899:
1.648 raeburn 9900: =item * &cacheheader()
1.112 bowersj2 9901:
9902: returns cache-controlling header code
9903:
9904: =cut
9905:
1.7 albertel 9906: sub cacheheader {
1.258 albertel 9907: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9908: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9909: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9910: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9911: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9912: return $output;
1.7 albertel 9913: }
9914:
1.112 bowersj2 9915: =pod
9916:
1.648 raeburn 9917: =item * &no_cache($r)
1.112 bowersj2 9918:
9919: specifies header code to not have cache
9920:
9921: =cut
9922:
1.9 albertel 9923: sub no_cache {
1.216 albertel 9924: my ($r) = @_;
9925: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9926: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9927: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9928: $r->no_cache(1);
9929: $r->header_out("Expires" => $date);
9930: $r->header_out("Pragma" => "no-cache");
1.123 www 9931: }
9932:
9933: sub content_type {
1.181 albertel 9934: my ($r,$type,$charset) = @_;
1.299 foxr 9935: if ($r) {
9936: # Note that printout.pl calls this with undef for $r.
9937: &no_cache($r);
9938: }
1.258 albertel 9939: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9940: unless ($charset) {
9941: $charset=&Apache::lonlocal::current_encoding;
9942: }
9943: if ($charset) { $type.='; charset='.$charset; }
9944: if ($r) {
9945: $r->content_type($type);
9946: } else {
9947: print("Content-type: $type\n\n");
9948: }
1.9 albertel 9949: }
1.25 albertel 9950:
1.112 bowersj2 9951: =pod
9952:
1.648 raeburn 9953: =item * &add_to_env($name,$value)
1.112 bowersj2 9954:
1.258 albertel 9955: adds $name to the %env hash with value
1.112 bowersj2 9956: $value, if $name already exists, the entry is converted to an array
9957: reference and $value is added to the array.
9958:
9959: =cut
9960:
1.25 albertel 9961: sub add_to_env {
9962: my ($name,$value)=@_;
1.258 albertel 9963: if (defined($env{$name})) {
9964: if (ref($env{$name})) {
1.25 albertel 9965: #already have multiple values
1.258 albertel 9966: push(@{ $env{$name} },$value);
1.25 albertel 9967: } else {
9968: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9969: my $first=$env{$name};
9970: undef($env{$name});
9971: push(@{ $env{$name} },$first,$value);
1.25 albertel 9972: }
9973: } else {
1.258 albertel 9974: $env{$name}=$value;
1.25 albertel 9975: }
1.31 albertel 9976: }
1.149 albertel 9977:
9978: =pod
9979:
1.648 raeburn 9980: =item * &get_env_multiple($name)
1.149 albertel 9981:
1.258 albertel 9982: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9983: values may be defined and end up as an array ref.
9984:
9985: returns an array of values
9986:
9987: =cut
9988:
9989: sub get_env_multiple {
9990: my ($name) = @_;
9991: my @values;
1.258 albertel 9992: if (defined($env{$name})) {
1.149 albertel 9993: # exists is it an array
1.258 albertel 9994: if (ref($env{$name})) {
9995: @values=@{ $env{$name} };
1.149 albertel 9996: } else {
1.258 albertel 9997: $values[0]=$env{$name};
1.149 albertel 9998: }
9999: }
10000: return(@values);
10001: }
10002:
1.660 raeburn 10003: sub ask_for_embedded_content {
10004: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10005: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10006: %currsubfile,%unused,$rem);
1.1071 raeburn 10007: my $counter = 0;
10008: my $numnew = 0;
1.987 raeburn 10009: my $numremref = 0;
10010: my $numinvalid = 0;
10011: my $numpathchg = 0;
10012: my $numexisting = 0;
1.1071 raeburn 10013: my $numunused = 0;
10014: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10015: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10016: my $heading = &mt('Upload embedded files');
10017: my $buttontext = &mt('Upload');
10018:
1.1075.2.11 raeburn 10019: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10020: if ($actionurl eq '/adm/dependencies') {
10021: $navmap = Apache::lonnavmaps::navmap->new();
10022: }
10023: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10024: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10025: }
1.1075.2.35 raeburn 10026: if (($actionurl eq '/adm/portfolio') ||
10027: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10028: my $current_path='/';
10029: if ($env{'form.currentpath'}) {
10030: $current_path = $env{'form.currentpath'};
10031: }
10032: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10033: $udom = $cdom;
10034: $uname = $cnum;
1.984 raeburn 10035: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10036: } else {
10037: $udom = $env{'user.domain'};
10038: $uname = $env{'user.name'};
10039: $url = '/userfiles/portfolio';
10040: }
1.987 raeburn 10041: $toplevel = $url.'/';
1.984 raeburn 10042: $url .= $current_path;
10043: $getpropath = 1;
1.987 raeburn 10044: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10045: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10046: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10047: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10048: $toplevel = $url;
1.984 raeburn 10049: if ($rest ne '') {
1.987 raeburn 10050: $url .= $rest;
10051: }
10052: } elsif ($actionurl eq '/adm/coursedocs') {
10053: if (ref($args) eq 'HASH') {
1.1071 raeburn 10054: $url = $args->{'docs_url'};
10055: $toplevel = $url;
1.1075.2.11 raeburn 10056: if ($args->{'context'} eq 'paste') {
10057: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10058: ($path) =
10059: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10060: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10061: $fileloc =~ s{^/}{};
10062: }
1.1071 raeburn 10063: }
10064: } elsif ($actionurl eq '/adm/dependencies') {
10065: if ($env{'request.course.id'} ne '') {
10066: if (ref($args) eq 'HASH') {
10067: $url = $args->{'docs_url'};
10068: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10069: $toplevel = $url;
10070: unless ($toplevel =~ m{^/}) {
10071: $toplevel = "/$url";
10072: }
1.1075.2.11 raeburn 10073: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10074: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10075: $path = $1;
10076: } else {
10077: ($path) =
10078: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10079: }
1.1075.2.79 raeburn 10080: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10081: $fileloc = $toplevel;
10082: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10083: my ($udom,$uname,$fname) =
10084: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10085: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10086: } else {
10087: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10088: }
1.1071 raeburn 10089: $fileloc =~ s{^/}{};
10090: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10091: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10092: }
1.987 raeburn 10093: }
1.1075.2.35 raeburn 10094: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10095: $udom = $cdom;
10096: $uname = $cnum;
10097: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10098: $toplevel = $url;
10099: $path = $url;
10100: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10101: $fileloc =~ s{^/}{};
10102: }
10103: foreach my $file (keys(%{$allfiles})) {
10104: my $embed_file;
10105: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10106: $embed_file = $1;
10107: } else {
10108: $embed_file = $file;
10109: }
1.1075.2.55 raeburn 10110: my ($absolutepath,$cleaned_file);
10111: if ($embed_file =~ m{^\w+://}) {
10112: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10113: $newfiles{$cleaned_file} = 1;
10114: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10115: } else {
1.1075.2.55 raeburn 10116: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10117: if ($embed_file =~ m{^/}) {
10118: $absolutepath = $embed_file;
10119: }
1.1075.2.47 raeburn 10120: if ($cleaned_file =~ m{/}) {
10121: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10122: $path = &check_for_traversal($path,$url,$toplevel);
10123: my $item = $fname;
10124: if ($path ne '') {
10125: $item = $path.'/'.$fname;
10126: $subdependencies{$path}{$fname} = 1;
10127: } else {
10128: $dependencies{$item} = 1;
10129: }
10130: if ($absolutepath) {
10131: $mapping{$item} = $absolutepath;
10132: } else {
10133: $mapping{$item} = $embed_file;
10134: }
10135: } else {
10136: $dependencies{$embed_file} = 1;
10137: if ($absolutepath) {
1.1075.2.47 raeburn 10138: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10139: } else {
1.1075.2.47 raeburn 10140: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10141: }
10142: }
1.984 raeburn 10143: }
10144: }
1.1071 raeburn 10145: my $dirptr = 16384;
1.984 raeburn 10146: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10147: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10148: if (($actionurl eq '/adm/portfolio') ||
10149: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10150: my ($sublistref,$listerror) =
10151: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10152: if (ref($sublistref) eq 'ARRAY') {
10153: foreach my $line (@{$sublistref}) {
10154: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10155: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10156: }
1.984 raeburn 10157: }
1.987 raeburn 10158: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10159: if (opendir(my $dir,$url.'/'.$path)) {
10160: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10161: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10162: }
1.1075.2.11 raeburn 10163: } elsif (($actionurl eq '/adm/dependencies') ||
10164: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10165: ($args->{'context'} eq 'paste')) ||
10166: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10167: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10168: my $dir;
10169: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10170: $dir = $fileloc;
10171: } else {
10172: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10173: }
1.1071 raeburn 10174: if ($dir ne '') {
10175: my ($sublistref,$listerror) =
10176: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10177: if (ref($sublistref) eq 'ARRAY') {
10178: foreach my $line (@{$sublistref}) {
10179: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10180: undef,$mtime)=split(/\&/,$line,12);
10181: unless (($testdir&$dirptr) ||
10182: ($file_name =~ /^\.\.?$/)) {
10183: $currsubfile{$path}{$file_name} = [$size,$mtime];
10184: }
10185: }
10186: }
10187: }
1.984 raeburn 10188: }
10189: }
10190: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10191: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10192: my $item = $path.'/'.$file;
10193: unless ($mapping{$item} eq $item) {
10194: $pathchanges{$item} = 1;
10195: }
10196: $existing{$item} = 1;
10197: $numexisting ++;
10198: } else {
10199: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10200: }
10201: }
1.1071 raeburn 10202: if ($actionurl eq '/adm/dependencies') {
10203: foreach my $path (keys(%currsubfile)) {
10204: if (ref($currsubfile{$path}) eq 'HASH') {
10205: foreach my $file (keys(%{$currsubfile{$path}})) {
10206: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10207: next if (($rem ne '') &&
10208: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10209: (ref($navmap) &&
10210: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10211: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10212: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10213: $unused{$path.'/'.$file} = 1;
10214: }
10215: }
10216: }
10217: }
10218: }
1.984 raeburn 10219: }
1.987 raeburn 10220: my %currfile;
1.1075.2.35 raeburn 10221: if (($actionurl eq '/adm/portfolio') ||
10222: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10223: my ($dirlistref,$listerror) =
10224: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10225: if (ref($dirlistref) eq 'ARRAY') {
10226: foreach my $line (@{$dirlistref}) {
10227: my ($file_name,$rest) = split(/\&/,$line,2);
10228: $currfile{$file_name} = 1;
10229: }
1.984 raeburn 10230: }
1.987 raeburn 10231: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10232: if (opendir(my $dir,$url)) {
1.987 raeburn 10233: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10234: map {$currfile{$_} = 1;} @dir_list;
10235: }
1.1075.2.11 raeburn 10236: } elsif (($actionurl eq '/adm/dependencies') ||
10237: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10238: ($args->{'context'} eq 'paste')) ||
10239: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10240: if ($env{'request.course.id'} ne '') {
10241: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10242: if ($dir ne '') {
10243: my ($dirlistref,$listerror) =
10244: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10245: if (ref($dirlistref) eq 'ARRAY') {
10246: foreach my $line (@{$dirlistref}) {
10247: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10248: $size,undef,$mtime)=split(/\&/,$line,12);
10249: unless (($testdir&$dirptr) ||
10250: ($file_name =~ /^\.\.?$/)) {
10251: $currfile{$file_name} = [$size,$mtime];
10252: }
10253: }
10254: }
10255: }
10256: }
1.984 raeburn 10257: }
10258: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10259: if (exists($currfile{$file})) {
1.987 raeburn 10260: unless ($mapping{$file} eq $file) {
10261: $pathchanges{$file} = 1;
10262: }
10263: $existing{$file} = 1;
10264: $numexisting ++;
10265: } else {
1.984 raeburn 10266: $newfiles{$file} = 1;
10267: }
10268: }
1.1071 raeburn 10269: foreach my $file (keys(%currfile)) {
10270: unless (($file eq $filename) ||
10271: ($file eq $filename.'.bak') ||
10272: ($dependencies{$file})) {
1.1075.2.11 raeburn 10273: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10274: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10275: next if (($rem ne '') &&
10276: (($env{"httpref.$rem".$file} ne '') ||
10277: (ref($navmap) &&
10278: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10279: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10280: ($navmap->getResourceByUrl($rem.$1)))))));
10281: }
1.1075.2.11 raeburn 10282: }
1.1071 raeburn 10283: $unused{$file} = 1;
10284: }
10285: }
1.1075.2.11 raeburn 10286: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10287: ($args->{'context'} eq 'paste')) {
10288: $counter = scalar(keys(%existing));
10289: $numpathchg = scalar(keys(%pathchanges));
10290: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10291: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10292: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10293: $counter = scalar(keys(%existing));
10294: $numpathchg = scalar(keys(%pathchanges));
10295: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10296: }
1.984 raeburn 10297: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10298: if ($actionurl eq '/adm/dependencies') {
10299: next if ($embed_file =~ m{^\w+://});
10300: }
1.660 raeburn 10301: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10302: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10303: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10304: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10305: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10306: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10307: }
1.1075.2.35 raeburn 10308: $upload_output .= '</td>';
1.1071 raeburn 10309: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10310: $upload_output.='<td align="right">'.
10311: '<span class="LC_info LC_fontsize_medium">'.
10312: &mt("URL points to web address").'</span>';
1.987 raeburn 10313: $numremref++;
1.660 raeburn 10314: } elsif ($args->{'error_on_invalid_names'}
10315: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10316: $upload_output.='<td align="right"><span class="LC_warning">'.
10317: &mt('Invalid characters').'</span>';
1.987 raeburn 10318: $numinvalid++;
1.660 raeburn 10319: } else {
1.1075.2.35 raeburn 10320: $upload_output .= '<td>'.
10321: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10322: $embed_file,\%mapping,
1.1071 raeburn 10323: $allfiles,$codebase,'upload');
10324: $counter ++;
10325: $numnew ++;
1.987 raeburn 10326: }
10327: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10328: }
10329: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10330: if ($actionurl eq '/adm/dependencies') {
10331: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10332: $modify_output .= &start_data_table_row().
10333: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10334: '<img src="'.&icon($embed_file).'" border="0" />'.
10335: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10336: '<td>'.$size.'</td>'.
10337: '<td>'.$mtime.'</td>'.
10338: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10339: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10340: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10341: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10342: &embedded_file_element('upload_embedded',$counter,
10343: $embed_file,\%mapping,
10344: $allfiles,$codebase,'modify').
10345: '</div></td>'.
10346: &end_data_table_row()."\n";
10347: $counter ++;
10348: } else {
10349: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10350: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10351: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10352: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10353: &Apache::loncommon::end_data_table_row()."\n";
10354: }
10355: }
10356: my $delidx = $counter;
10357: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10358: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10359: $delete_output .= &start_data_table_row().
10360: '<td><img src="'.&icon($oldfile).'" />'.
10361: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10362: '<td>'.$size.'</td>'.
10363: '<td>'.$mtime.'</td>'.
10364: '<td><label><input type="checkbox" name="del_upload_dep" '.
10365: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10366: &embedded_file_element('upload_embedded',$delidx,
10367: $oldfile,\%mapping,$allfiles,
10368: $codebase,'delete').'</td>'.
10369: &end_data_table_row()."\n";
10370: $numunused ++;
10371: $delidx ++;
1.987 raeburn 10372: }
10373: if ($upload_output) {
10374: $upload_output = &start_data_table().
10375: $upload_output.
10376: &end_data_table()."\n";
10377: }
1.1071 raeburn 10378: if ($modify_output) {
10379: $modify_output = &start_data_table().
10380: &start_data_table_header_row().
10381: '<th>'.&mt('File').'</th>'.
10382: '<th>'.&mt('Size (KB)').'</th>'.
10383: '<th>'.&mt('Modified').'</th>'.
10384: '<th>'.&mt('Upload replacement?').'</th>'.
10385: &end_data_table_header_row().
10386: $modify_output.
10387: &end_data_table()."\n";
10388: }
10389: if ($delete_output) {
10390: $delete_output = &start_data_table().
10391: &start_data_table_header_row().
10392: '<th>'.&mt('File').'</th>'.
10393: '<th>'.&mt('Size (KB)').'</th>'.
10394: '<th>'.&mt('Modified').'</th>'.
10395: '<th>'.&mt('Delete?').'</th>'.
10396: &end_data_table_header_row().
10397: $delete_output.
10398: &end_data_table()."\n";
10399: }
1.987 raeburn 10400: my $applies = 0;
10401: if ($numremref) {
10402: $applies ++;
10403: }
10404: if ($numinvalid) {
10405: $applies ++;
10406: }
10407: if ($numexisting) {
10408: $applies ++;
10409: }
1.1071 raeburn 10410: if ($counter || $numunused) {
1.987 raeburn 10411: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10412: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10413: $state.'<h3>'.$heading.'</h3>';
10414: if ($actionurl eq '/adm/dependencies') {
10415: if ($numnew) {
10416: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10417: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10418: $upload_output.'<br />'."\n";
10419: }
10420: if ($numexisting) {
10421: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10422: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10423: $modify_output.'<br />'."\n";
10424: $buttontext = &mt('Save changes');
10425: }
10426: if ($numunused) {
10427: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10428: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10429: $delete_output.'<br />'."\n";
10430: $buttontext = &mt('Save changes');
10431: }
10432: } else {
10433: $output .= $upload_output.'<br />'."\n";
10434: }
10435: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10436: $counter.'" />'."\n";
10437: if ($actionurl eq '/adm/dependencies') {
10438: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10439: $numnew.'" />'."\n";
10440: } elsif ($actionurl eq '') {
1.987 raeburn 10441: $output .= '<input type="hidden" name="phase" value="three" />';
10442: }
10443: } elsif ($applies) {
10444: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10445: if ($applies > 1) {
10446: $output .=
1.1075.2.35 raeburn 10447: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10448: if ($numremref) {
10449: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10450: }
10451: if ($numinvalid) {
10452: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10453: }
10454: if ($numexisting) {
10455: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10456: }
10457: $output .= '</ul><br />';
10458: } elsif ($numremref) {
10459: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10460: } elsif ($numinvalid) {
10461: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10462: } elsif ($numexisting) {
10463: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10464: }
10465: $output .= $upload_output.'<br />';
10466: }
10467: my ($pathchange_output,$chgcount);
1.1071 raeburn 10468: $chgcount = $counter;
1.987 raeburn 10469: if (keys(%pathchanges) > 0) {
10470: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10471: if ($counter) {
1.987 raeburn 10472: $output .= &embedded_file_element('pathchange',$chgcount,
10473: $embed_file,\%mapping,
1.1071 raeburn 10474: $allfiles,$codebase,'change');
1.987 raeburn 10475: } else {
10476: $pathchange_output .=
10477: &start_data_table_row().
10478: '<td><input type ="checkbox" name="namechange" value="'.
10479: $chgcount.'" checked="checked" /></td>'.
10480: '<td>'.$mapping{$embed_file}.'</td>'.
10481: '<td>'.$embed_file.
10482: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10483: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10484: '</td>'.&end_data_table_row();
1.660 raeburn 10485: }
1.987 raeburn 10486: $numpathchg ++;
10487: $chgcount ++;
1.660 raeburn 10488: }
10489: }
1.1075.2.35 raeburn 10490: if (($counter) || ($numunused)) {
1.987 raeburn 10491: if ($numpathchg) {
10492: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10493: $numpathchg.'" />'."\n";
10494: }
10495: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10496: ($actionurl eq '/adm/imsimport')) {
10497: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10498: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10499: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10500: } elsif ($actionurl eq '/adm/dependencies') {
10501: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10502: }
1.1075.2.35 raeburn 10503: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10504: } elsif ($numpathchg) {
10505: my %pathchange = ();
10506: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10507: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10508: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 10509: }
1.987 raeburn 10510: }
1.1071 raeburn 10511: return ($output,$counter,$numpathchg);
1.987 raeburn 10512: }
10513:
1.1075.2.47 raeburn 10514: =pod
10515:
10516: =item * clean_path($name)
10517:
10518: Performs clean-up of directories, subdirectories and filename in an
10519: embedded object, referenced in an HTML file which is being uploaded
10520: to a course or portfolio, where
10521: "Upload embedded images/multimedia files if HTML file" checkbox was
10522: checked.
10523:
10524: Clean-up is similar to replacements in lonnet::clean_filename()
10525: except each / between sub-directory and next level is preserved.
10526:
10527: =cut
10528:
10529: sub clean_path {
10530: my ($embed_file) = @_;
10531: $embed_file =~s{^/+}{};
10532: my @contents;
10533: if ($embed_file =~ m{/}) {
10534: @contents = split(/\//,$embed_file);
10535: } else {
10536: @contents = ($embed_file);
10537: }
10538: my $lastidx = scalar(@contents)-1;
10539: for (my $i=0; $i<=$lastidx; $i++) {
10540: $contents[$i]=~s{\\}{/}g;
10541: $contents[$i]=~s/\s+/\_/g;
10542: $contents[$i]=~s{[^/\w\.\-]}{}g;
10543: if ($i == $lastidx) {
10544: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10545: }
10546: }
10547: if ($lastidx > 0) {
10548: return join('/',@contents);
10549: } else {
10550: return $contents[0];
10551: }
10552: }
10553:
1.987 raeburn 10554: sub embedded_file_element {
1.1071 raeburn 10555: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10556: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10557: (ref($codebase) eq 'HASH'));
10558: my $output;
1.1071 raeburn 10559: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10560: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10561: }
10562: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10563: &escape($embed_file).'" />';
10564: unless (($context eq 'upload_embedded') &&
10565: ($mapping->{$embed_file} eq $embed_file)) {
10566: $output .='
10567: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10568: }
10569: my $attrib;
10570: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10571: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10572: }
10573: $output .=
10574: "\n\t\t".
10575: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10576: $attrib.'" />';
10577: if (exists($codebase->{$mapping->{$embed_file}})) {
10578: $output .=
10579: "\n\t\t".
10580: '<input name="codebase_'.$num.'" type="hidden" value="'.
10581: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10582: }
1.987 raeburn 10583: return $output;
1.660 raeburn 10584: }
10585:
1.1071 raeburn 10586: sub get_dependency_details {
10587: my ($currfile,$currsubfile,$embed_file) = @_;
10588: my ($size,$mtime,$showsize,$showmtime);
10589: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10590: if ($embed_file =~ m{/}) {
10591: my ($path,$fname) = split(/\//,$embed_file);
10592: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10593: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10594: }
10595: } else {
10596: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10597: ($size,$mtime) = @{$currfile->{$embed_file}};
10598: }
10599: }
10600: $showsize = $size/1024.0;
10601: $showsize = sprintf("%.1f",$showsize);
10602: if ($mtime > 0) {
10603: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10604: }
10605: }
10606: return ($showsize,$showmtime);
10607: }
10608:
10609: sub ask_embedded_js {
10610: return <<"END";
10611: <script type="text/javascript"">
10612: // <![CDATA[
10613: function toggleBrowse(counter) {
10614: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10615: var fileid = document.getElementById('embedded_item_'+counter);
10616: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10617: if (chkboxid.checked == true) {
10618: uploaddivid.style.display='block';
10619: } else {
10620: uploaddivid.style.display='none';
10621: fileid.value = '';
10622: }
10623: }
10624: // ]]>
10625: </script>
10626:
10627: END
10628: }
10629:
1.661 raeburn 10630: sub upload_embedded {
10631: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10632: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10633: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10634: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10635: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10636: my $orig_uploaded_filename =
10637: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10638: foreach my $type ('orig','ref','attrib','codebase') {
10639: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10640: $env{'form.embedded_'.$type.'_'.$i} =
10641: &unescape($env{'form.embedded_'.$type.'_'.$i});
10642: }
10643: }
1.661 raeburn 10644: my ($path,$fname) =
10645: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10646: # no path, whole string is fname
10647: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10648: $fname = &Apache::lonnet::clean_filename($fname);
10649: # See if there is anything left
10650: next if ($fname eq '');
10651:
10652: # Check if file already exists as a file or directory.
10653: my ($state,$msg);
10654: if ($context eq 'portfolio') {
10655: my $port_path = $dirpath;
10656: if ($group ne '') {
10657: $port_path = "groups/$group/$port_path";
10658: }
1.987 raeburn 10659: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10660: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10661: $dir_root,$port_path,$disk_quota,
10662: $current_disk_usage,$uname,$udom);
10663: if ($state eq 'will_exceed_quota'
1.984 raeburn 10664: || $state eq 'file_locked') {
1.661 raeburn 10665: $output .= $msg;
10666: next;
10667: }
10668: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10669: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10670: if ($state eq 'exists') {
10671: $output .= $msg;
10672: next;
10673: }
10674: }
10675: # Check if extension is valid
10676: if (($fname =~ /\.(\w+)$/) &&
10677: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 10678: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10679: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10680: next;
10681: } elsif (($fname =~ /\.(\w+)$/) &&
10682: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10683: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10684: next;
10685: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 10686: $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 10687: next;
10688: }
10689: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 10690: my $subdir = $path;
10691: $subdir =~ s{/+$}{};
1.661 raeburn 10692: if ($context eq 'portfolio') {
1.984 raeburn 10693: my $result;
10694: if ($state eq 'existingfile') {
10695: $result=
10696: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 10697: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10698: } else {
1.984 raeburn 10699: $result=
10700: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10701: $dirpath.
1.1075.2.35 raeburn 10702: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10703: if ($result !~ m|^/uploaded/|) {
10704: $output .= '<span class="LC_error">'
10705: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10706: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10707: .'</span><br />';
10708: next;
10709: } else {
1.987 raeburn 10710: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10711: $path.$fname.'</span>').'<br />';
1.984 raeburn 10712: }
1.661 raeburn 10713: }
1.1075.2.35 raeburn 10714: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
10715: my $extendedsubdir = $dirpath.'/'.$subdir;
10716: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10717: my $result =
1.1075.2.35 raeburn 10718: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10719: if ($result !~ m|^/uploaded/|) {
10720: $output .= '<span class="LC_error">'
10721: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10722: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10723: .'</span><br />';
10724: next;
10725: } else {
10726: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10727: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 10728: if ($context eq 'syllabus') {
10729: &Apache::lonnet::make_public_indefinitely($result);
10730: }
1.987 raeburn 10731: }
1.661 raeburn 10732: } else {
10733: # Save the file
10734: my $target = $env{'form.embedded_item_'.$i};
10735: my $fullpath = $dir_root.$dirpath.'/'.$path;
10736: my $dest = $fullpath.$fname;
10737: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10738: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10739: my $count;
10740: my $filepath = $dir_root;
1.1027 raeburn 10741: foreach my $subdir (@parts) {
10742: $filepath .= "/$subdir";
10743: if (!-e $filepath) {
1.661 raeburn 10744: mkdir($filepath,0770);
10745: }
10746: }
10747: my $fh;
10748: if (!open($fh,'>'.$dest)) {
10749: &Apache::lonnet::logthis('Failed to create '.$dest);
10750: $output .= '<span class="LC_error">'.
1.1071 raeburn 10751: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10752: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10753: '</span><br />';
10754: } else {
10755: if (!print $fh $env{'form.embedded_item_'.$i}) {
10756: &Apache::lonnet::logthis('Failed to write to '.$dest);
10757: $output .= '<span class="LC_error">'.
1.1071 raeburn 10758: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10759: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10760: '</span><br />';
10761: } else {
1.987 raeburn 10762: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10763: $url.'</span>').'<br />';
10764: unless ($context eq 'testbank') {
10765: $footer .= &mt('View embedded file: [_1]',
10766: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10767: }
10768: }
10769: close($fh);
10770: }
10771: }
10772: if ($env{'form.embedded_ref_'.$i}) {
10773: $pathchange{$i} = 1;
10774: }
10775: }
10776: if ($output) {
10777: $output = '<p>'.$output.'</p>';
10778: }
10779: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10780: $returnflag = 'ok';
1.1071 raeburn 10781: my $numpathchgs = scalar(keys(%pathchange));
10782: if ($numpathchgs > 0) {
1.987 raeburn 10783: if ($context eq 'portfolio') {
10784: $output .= '<p>'.&mt('or').'</p>';
10785: } elsif ($context eq 'testbank') {
1.1071 raeburn 10786: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10787: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10788: $returnflag = 'modify_orightml';
10789: }
10790: }
1.1071 raeburn 10791: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10792: }
10793:
10794: sub modify_html_form {
10795: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10796: my $end = 0;
10797: my $modifyform;
10798: if ($context eq 'upload_embedded') {
10799: return unless (ref($pathchange) eq 'HASH');
10800: if ($env{'form.number_embedded_items'}) {
10801: $end += $env{'form.number_embedded_items'};
10802: }
10803: if ($env{'form.number_pathchange_items'}) {
10804: $end += $env{'form.number_pathchange_items'};
10805: }
10806: if ($end) {
10807: for (my $i=0; $i<$end; $i++) {
10808: if ($i < $env{'form.number_embedded_items'}) {
10809: next unless($pathchange->{$i});
10810: }
10811: $modifyform .=
10812: &start_data_table_row().
10813: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10814: 'checked="checked" /></td>'.
10815: '<td>'.$env{'form.embedded_ref_'.$i}.
10816: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10817: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10818: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10819: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10820: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10821: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10822: '<td>'.$env{'form.embedded_orig_'.$i}.
10823: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10824: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10825: &end_data_table_row();
1.1071 raeburn 10826: }
1.987 raeburn 10827: }
10828: } else {
10829: $modifyform = $pathchgtable;
10830: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10831: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10832: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10833: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10834: }
10835: }
10836: if ($modifyform) {
1.1071 raeburn 10837: if ($actionurl eq '/adm/dependencies') {
10838: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10839: }
1.987 raeburn 10840: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10841: '<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".
10842: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10843: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10844: '</ol></p>'."\n".'<p>'.
10845: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10846: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10847: &start_data_table()."\n".
10848: &start_data_table_header_row().
10849: '<th>'.&mt('Change?').'</th>'.
10850: '<th>'.&mt('Current reference').'</th>'.
10851: '<th>'.&mt('Required reference').'</th>'.
10852: &end_data_table_header_row()."\n".
10853: $modifyform.
10854: &end_data_table().'<br />'."\n".$hiddenstate.
10855: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10856: '</form>'."\n";
10857: }
10858: return;
10859: }
10860:
10861: sub modify_html_refs {
1.1075.2.35 raeburn 10862: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10863: my $container;
10864: if ($context eq 'portfolio') {
10865: $container = $env{'form.container'};
10866: } elsif ($context eq 'coursedoc') {
10867: $container = $env{'form.primaryurl'};
1.1071 raeburn 10868: } elsif ($context eq 'manage_dependencies') {
10869: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10870: $container = "/$container";
1.1075.2.35 raeburn 10871: } elsif ($context eq 'syllabus') {
10872: $container = $url;
1.987 raeburn 10873: } else {
1.1027 raeburn 10874: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10875: }
10876: my (%allfiles,%codebase,$output,$content);
10877: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 10878: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10879: if (wantarray) {
10880: return ('',0,0);
10881: } else {
10882: return;
10883: }
10884: }
10885: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10886: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10887: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10888: if (wantarray) {
10889: return ('',0,0);
10890: } else {
10891: return;
10892: }
10893: }
1.987 raeburn 10894: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10895: if ($content eq '-1') {
10896: if (wantarray) {
10897: return ('',0,0);
10898: } else {
10899: return;
10900: }
10901: }
1.987 raeburn 10902: } else {
1.1071 raeburn 10903: unless ($container =~ /^\Q$dir_root\E/) {
10904: if (wantarray) {
10905: return ('',0,0);
10906: } else {
10907: return;
10908: }
10909: }
1.987 raeburn 10910: if (open(my $fh,"<$container")) {
10911: $content = join('', <$fh>);
10912: close($fh);
10913: } else {
1.1071 raeburn 10914: if (wantarray) {
10915: return ('',0,0);
10916: } else {
10917: return;
10918: }
1.987 raeburn 10919: }
10920: }
10921: my ($count,$codebasecount) = (0,0);
10922: my $mm = new File::MMagic;
10923: my $mime_type = $mm->checktype_contents($content);
10924: if ($mime_type eq 'text/html') {
10925: my $parse_result =
10926: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10927: \%codebase,\$content);
10928: if ($parse_result eq 'ok') {
10929: foreach my $i (@changes) {
10930: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10931: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10932: if ($allfiles{$ref}) {
10933: my $newname = $orig;
10934: my ($attrib_regexp,$codebase);
1.1006 raeburn 10935: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10936: if ($attrib_regexp =~ /:/) {
10937: $attrib_regexp =~ s/\:/|/g;
10938: }
10939: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10940: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10941: $count += $numchg;
1.1075.2.35 raeburn 10942: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 10943: delete($allfiles{$ref});
1.987 raeburn 10944: }
10945: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10946: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10947: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10948: $codebasecount ++;
10949: }
10950: }
10951: }
1.1075.2.35 raeburn 10952: my $skiprewrites;
1.987 raeburn 10953: if ($count || $codebasecount) {
10954: my $saveresult;
1.1071 raeburn 10955: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10956: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10957: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10958: if ($url eq $container) {
10959: my ($fname) = ($container =~ m{/([^/]+)$});
10960: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10961: $count,'<span class="LC_filename">'.
1.1071 raeburn 10962: $fname.'</span>').'</p>';
1.987 raeburn 10963: } else {
10964: $output = '<p class="LC_error">'.
10965: &mt('Error: update failed for: [_1].',
10966: '<span class="LC_filename">'.
10967: $container.'</span>').'</p>';
10968: }
1.1075.2.35 raeburn 10969: if ($context eq 'syllabus') {
10970: unless ($saveresult eq 'ok') {
10971: $skiprewrites = 1;
10972: }
10973: }
1.987 raeburn 10974: } else {
10975: if (open(my $fh,">$container")) {
10976: print $fh $content;
10977: close($fh);
10978: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10979: $count,'<span class="LC_filename">'.
10980: $container.'</span>').'</p>';
1.661 raeburn 10981: } else {
1.987 raeburn 10982: $output = '<p class="LC_error">'.
10983: &mt('Error: could not update [_1].',
10984: '<span class="LC_filename">'.
10985: $container.'</span>').'</p>';
1.661 raeburn 10986: }
10987: }
10988: }
1.1075.2.35 raeburn 10989: if (($context eq 'syllabus') && (!$skiprewrites)) {
10990: my ($actionurl,$state);
10991: $actionurl = "/public/$udom/$uname/syllabus";
10992: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10993: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10994: \%codebase,
10995: {'context' => 'rewrites',
10996: 'ignore_remote_references' => 1,});
10997: if (ref($mapping) eq 'HASH') {
10998: my $rewrites = 0;
10999: foreach my $key (keys(%{$mapping})) {
11000: next if ($key =~ m{^https?://});
11001: my $ref = $mapping->{$key};
11002: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11003: my $attrib;
11004: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11005: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11006: }
11007: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11008: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11009: $rewrites += $numchg;
11010: }
11011: }
11012: if ($rewrites) {
11013: my $saveresult;
11014: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11015: if ($url eq $container) {
11016: my ($fname) = ($container =~ m{/([^/]+)$});
11017: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11018: $count,'<span class="LC_filename">'.
11019: $fname.'</span>').'</p>';
11020: } else {
11021: $output .= '<p class="LC_error">'.
11022: &mt('Error: could not update links in [_1].',
11023: '<span class="LC_filename">'.
11024: $container.'</span>').'</p>';
11025:
11026: }
11027: }
11028: }
11029: }
1.987 raeburn 11030: } else {
11031: &logthis('Failed to parse '.$container.
11032: ' to modify references: '.$parse_result);
1.661 raeburn 11033: }
11034: }
1.1071 raeburn 11035: if (wantarray) {
11036: return ($output,$count,$codebasecount);
11037: } else {
11038: return $output;
11039: }
1.661 raeburn 11040: }
11041:
11042: sub check_for_existing {
11043: my ($path,$fname,$element) = @_;
11044: my ($state,$msg);
11045: if (-d $path.'/'.$fname) {
11046: $state = 'exists';
11047: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11048: } elsif (-e $path.'/'.$fname) {
11049: $state = 'exists';
11050: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11051: }
11052: if ($state eq 'exists') {
11053: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11054: }
11055: return ($state,$msg);
11056: }
11057:
11058: sub check_for_upload {
11059: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11060: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11061: my $filesize = length($env{'form.'.$element});
11062: if (!$filesize) {
11063: my $msg = '<span class="LC_error">'.
11064: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11065: '<span class="LC_filename">'.$fname.'</span>',
11066: $filesize).'<br />'.
1.1007 raeburn 11067: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11068: '</span>';
11069: return ('zero_bytes',$msg);
11070: }
11071: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11072: my $getpropath = 1;
1.1021 raeburn 11073: my ($dirlistref,$listerror) =
11074: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11075: my $found_file = 0;
11076: my $locked_file = 0;
1.991 raeburn 11077: my @lockers;
11078: my $navmap;
11079: if ($env{'request.course.id'}) {
11080: $navmap = Apache::lonnavmaps::navmap->new();
11081: }
1.1021 raeburn 11082: if (ref($dirlistref) eq 'ARRAY') {
11083: foreach my $line (@{$dirlistref}) {
11084: my ($file_name,$rest)=split(/\&/,$line,2);
11085: if ($file_name eq $fname){
11086: $file_name = $path.$file_name;
11087: if ($group ne '') {
11088: $file_name = $group.$file_name;
11089: }
11090: $found_file = 1;
11091: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11092: foreach my $lock (@lockers) {
11093: if (ref($lock) eq 'ARRAY') {
11094: my ($symb,$crsid) = @{$lock};
11095: if ($crsid eq $env{'request.course.id'}) {
11096: if (ref($navmap)) {
11097: my $res = $navmap->getBySymb($symb);
11098: foreach my $part (@{$res->parts()}) {
11099: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11100: unless (($slot_status == $res->RESERVED) ||
11101: ($slot_status == $res->RESERVED_LOCATION)) {
11102: $locked_file = 1;
11103: }
1.991 raeburn 11104: }
1.1021 raeburn 11105: } else {
11106: $locked_file = 1;
1.991 raeburn 11107: }
11108: } else {
11109: $locked_file = 1;
11110: }
11111: }
1.1021 raeburn 11112: }
11113: } else {
11114: my @info = split(/\&/,$rest);
11115: my $currsize = $info[6]/1000;
11116: if ($currsize < $filesize) {
11117: my $extra = $filesize - $currsize;
11118: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11119: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11120: &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 11121: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11122: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11123: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11124: return ('will_exceed_quota',$msg);
11125: }
1.984 raeburn 11126: }
11127: }
1.661 raeburn 11128: }
11129: }
11130: }
11131: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11132: my $msg = '<p class="LC_warning">'.
11133: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11134: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11135: return ('will_exceed_quota',$msg);
11136: } elsif ($found_file) {
11137: if ($locked_file) {
1.1075.2.69 raeburn 11138: my $msg = '<p class="LC_warning">';
1.661 raeburn 11139: $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 11140: $msg .= '</p>';
1.661 raeburn 11141: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11142: return ('file_locked',$msg);
11143: } else {
1.1075.2.69 raeburn 11144: my $msg = '<p class="LC_error">';
1.984 raeburn 11145: $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 11146: $msg .= '</p>';
1.984 raeburn 11147: return ('existingfile',$msg);
1.661 raeburn 11148: }
11149: }
11150: }
11151:
1.987 raeburn 11152: sub check_for_traversal {
11153: my ($path,$url,$toplevel) = @_;
11154: my @parts=split(/\//,$path);
11155: my $cleanpath;
11156: my $fullpath = $url;
11157: for (my $i=0;$i<@parts;$i++) {
11158: next if ($parts[$i] eq '.');
11159: if ($parts[$i] eq '..') {
11160: $fullpath =~ s{([^/]+/)$}{};
11161: } else {
11162: $fullpath .= $parts[$i].'/';
11163: }
11164: }
11165: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11166: $cleanpath = $1;
11167: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11168: my $curr_toprel = $1;
11169: my @parts = split(/\//,$curr_toprel);
11170: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11171: my @urlparts = split(/\//,$url_toprel);
11172: my $doubledots;
11173: my $startdiff = -1;
11174: for (my $i=0; $i<@urlparts; $i++) {
11175: if ($startdiff == -1) {
11176: unless ($urlparts[$i] eq $parts[$i]) {
11177: $startdiff = $i;
11178: $doubledots .= '../';
11179: }
11180: } else {
11181: $doubledots .= '../';
11182: }
11183: }
11184: if ($startdiff > -1) {
11185: $cleanpath = $doubledots;
11186: for (my $i=$startdiff; $i<@parts; $i++) {
11187: $cleanpath .= $parts[$i].'/';
11188: }
11189: }
11190: }
11191: $cleanpath =~ s{(/)$}{};
11192: return $cleanpath;
11193: }
1.31 albertel 11194:
1.1053 raeburn 11195: sub is_archive_file {
11196: my ($mimetype) = @_;
11197: if (($mimetype eq 'application/octet-stream') ||
11198: ($mimetype eq 'application/x-stuffit') ||
11199: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11200: return 1;
11201: }
11202: return;
11203: }
11204:
11205: sub decompress_form {
1.1065 raeburn 11206: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11207: my %lt = &Apache::lonlocal::texthash (
11208: this => 'This file is an archive file.',
1.1067 raeburn 11209: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11210: itsc => 'Its contents are as follows:',
1.1053 raeburn 11211: youm => 'You may wish to extract its contents.',
11212: extr => 'Extract contents',
1.1067 raeburn 11213: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11214: proa => 'Process automatically?',
1.1053 raeburn 11215: yes => 'Yes',
11216: no => 'No',
1.1067 raeburn 11217: fold => 'Title for folder containing movie',
11218: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11219: );
1.1065 raeburn 11220: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11221: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11222: my $info = &list_archive_contents($fileloc,\@paths);
11223: if (@paths) {
11224: foreach my $path (@paths) {
11225: $path =~ s{^/}{};
1.1067 raeburn 11226: if ($path =~ m{^([^/]+)/$}) {
11227: $topdir = $1;
11228: }
1.1065 raeburn 11229: if ($path =~ m{^([^/]+)/}) {
11230: $toplevel{$1} = $path;
11231: } else {
11232: $toplevel{$path} = $path;
11233: }
11234: }
11235: }
1.1067 raeburn 11236: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11237: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11238: "$topdir/media/",
11239: "$topdir/media/$topdir.mp4",
11240: "$topdir/media/FirstFrame.png",
11241: "$topdir/media/player.swf",
11242: "$topdir/media/swfobject.js",
11243: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 11244: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 11245: "$topdir/$topdir.mp4",
11246: "$topdir/$topdir\_config.xml",
11247: "$topdir/$topdir\_controller.swf",
11248: "$topdir/$topdir\_embed.css",
11249: "$topdir/$topdir\_First_Frame.png",
11250: "$topdir/$topdir\_player.html",
11251: "$topdir/$topdir\_Thumbnails.png",
11252: "$topdir/playerProductInstall.swf",
11253: "$topdir/scripts/",
11254: "$topdir/scripts/config_xml.js",
11255: "$topdir/scripts/handlebars.js",
11256: "$topdir/scripts/jquery-1.7.1.min.js",
11257: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11258: "$topdir/scripts/modernizr.js",
11259: "$topdir/scripts/player-min.js",
11260: "$topdir/scripts/swfobject.js",
11261: "$topdir/skins/",
11262: "$topdir/skins/configuration_express.xml",
11263: "$topdir/skins/express_show/",
11264: "$topdir/skins/express_show/player-min.css",
11265: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 11266: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11267: "$topdir/$topdir.mp4",
11268: "$topdir/$topdir\_config.xml",
11269: "$topdir/$topdir\_controller.swf",
11270: "$topdir/$topdir\_embed.css",
11271: "$topdir/$topdir\_First_Frame.png",
11272: "$topdir/$topdir\_player.html",
11273: "$topdir/$topdir\_Thumbnails.png",
11274: "$topdir/playerProductInstall.swf",
11275: "$topdir/scripts/",
11276: "$topdir/scripts/config_xml.js",
11277: "$topdir/scripts/techsmith-smart-player.min.js",
11278: "$topdir/skins/",
11279: "$topdir/skins/configuration_express.xml",
11280: "$topdir/skins/express_show/",
11281: "$topdir/skins/express_show/spritesheet.min.css",
11282: "$topdir/skins/express_show/spritesheet.png",
11283: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 11284: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11285: if (@diffs == 0) {
1.1075.2.59 raeburn 11286: $is_camtasia = 6;
11287: } else {
1.1075.2.81 raeburn 11288: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 11289: if (@diffs == 0) {
11290: $is_camtasia = 8;
1.1075.2.81 raeburn 11291: } else {
11292: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11293: if (@diffs == 0) {
11294: $is_camtasia = 8;
11295: }
1.1075.2.59 raeburn 11296: }
1.1067 raeburn 11297: }
11298: }
11299: my $output;
11300: if ($is_camtasia) {
11301: $output = <<"ENDCAM";
11302: <script type="text/javascript" language="Javascript">
11303: // <![CDATA[
11304:
11305: function camtasiaToggle() {
11306: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11307: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11308: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11309: document.getElementById('camtasia_titles').style.display='block';
11310: } else {
11311: document.getElementById('camtasia_titles').style.display='none';
11312: }
11313: }
11314: }
11315: return;
11316: }
11317:
11318: // ]]>
11319: </script>
11320: <p>$lt{'camt'}</p>
11321: ENDCAM
1.1065 raeburn 11322: } else {
1.1067 raeburn 11323: $output = '<p>'.$lt{'this'};
11324: if ($info eq '') {
11325: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11326: } else {
11327: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11328: '<div><pre>'.$info.'</pre></div>';
11329: }
1.1065 raeburn 11330: }
1.1067 raeburn 11331: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11332: my $duplicates;
11333: my $num = 0;
11334: if (ref($dirlist) eq 'ARRAY') {
11335: foreach my $item (@{$dirlist}) {
11336: if (ref($item) eq 'ARRAY') {
11337: if (exists($toplevel{$item->[0]})) {
11338: $duplicates .=
11339: &start_data_table_row().
11340: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11341: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11342: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11343: 'value="1" />'.&mt('Yes').'</label>'.
11344: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11345: '<td>'.$item->[0].'</td>';
11346: if ($item->[2]) {
11347: $duplicates .= '<td>'.&mt('Directory').'</td>';
11348: } else {
11349: $duplicates .= '<td>'.&mt('File').'</td>';
11350: }
11351: $duplicates .= '<td>'.$item->[3].'</td>'.
11352: '<td>'.
11353: &Apache::lonlocal::locallocaltime($item->[4]).
11354: '</td>'.
11355: &end_data_table_row();
11356: $num ++;
11357: }
11358: }
11359: }
11360: }
11361: my $itemcount;
11362: if (@paths > 0) {
11363: $itemcount = scalar(@paths);
11364: } else {
11365: $itemcount = 1;
11366: }
1.1067 raeburn 11367: if ($is_camtasia) {
11368: $output .= $lt{'auto'}.'<br />'.
11369: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 11370: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11371: $lt{'yes'}.'</label> <label>'.
11372: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11373: $lt{'no'}.'</label></span><br />'.
11374: '<div id="camtasia_titles" style="display:block">'.
11375: &Apache::lonhtmlcommon::start_pick_box().
11376: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11377: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11378: &Apache::lonhtmlcommon::row_closure().
11379: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11380: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11381: &Apache::lonhtmlcommon::row_closure(1).
11382: &Apache::lonhtmlcommon::end_pick_box().
11383: '</div>';
11384: }
1.1065 raeburn 11385: $output .=
11386: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11387: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11388: "\n";
1.1065 raeburn 11389: if ($duplicates ne '') {
11390: $output .= '<p><span class="LC_warning">'.
11391: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11392: &start_data_table().
11393: &start_data_table_header_row().
11394: '<th>'.&mt('Overwrite?').'</th>'.
11395: '<th>'.&mt('Name').'</th>'.
11396: '<th>'.&mt('Type').'</th>'.
11397: '<th>'.&mt('Size').'</th>'.
11398: '<th>'.&mt('Last modified').'</th>'.
11399: &end_data_table_header_row().
11400: $duplicates.
11401: &end_data_table().
11402: '</p>';
11403: }
1.1067 raeburn 11404: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11405: if (ref($hiddenelements) eq 'HASH') {
11406: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11407: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11408: }
11409: }
11410: $output .= <<"END";
1.1067 raeburn 11411: <br />
1.1053 raeburn 11412: <input type="submit" name="decompress" value="$lt{'extr'}" />
11413: </form>
11414: $noextract
11415: END
11416: return $output;
11417: }
11418:
1.1065 raeburn 11419: sub decompression_utility {
11420: my ($program) = @_;
11421: my @utilities = ('tar','gunzip','bunzip2','unzip');
11422: my $location;
11423: if (grep(/^\Q$program\E$/,@utilities)) {
11424: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11425: '/usr/sbin/') {
11426: if (-x $dir.$program) {
11427: $location = $dir.$program;
11428: last;
11429: }
11430: }
11431: }
11432: return $location;
11433: }
11434:
11435: sub list_archive_contents {
11436: my ($file,$pathsref) = @_;
11437: my (@cmd,$output);
11438: my $needsregexp;
11439: if ($file =~ /\.zip$/) {
11440: @cmd = (&decompression_utility('unzip'),"-l");
11441: $needsregexp = 1;
11442: } elsif (($file =~ m/\.tar\.gz$/) ||
11443: ($file =~ /\.tgz$/)) {
11444: @cmd = (&decompression_utility('tar'),"-ztf");
11445: } elsif ($file =~ /\.tar\.bz2$/) {
11446: @cmd = (&decompression_utility('tar'),"-jtf");
11447: } elsif ($file =~ m|\.tar$|) {
11448: @cmd = (&decompression_utility('tar'),"-tf");
11449: }
11450: if (@cmd) {
11451: undef($!);
11452: undef($@);
11453: if (open(my $fh,"-|", @cmd, $file)) {
11454: while (my $line = <$fh>) {
11455: $output .= $line;
11456: chomp($line);
11457: my $item;
11458: if ($needsregexp) {
11459: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11460: } else {
11461: $item = $line;
11462: }
11463: if ($item ne '') {
11464: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11465: push(@{$pathsref},$item);
11466: }
11467: }
11468: }
11469: close($fh);
11470: }
11471: }
11472: return $output;
11473: }
11474:
1.1053 raeburn 11475: sub decompress_uploaded_file {
11476: my ($file,$dir) = @_;
11477: &Apache::lonnet::appenv({'cgi.file' => $file});
11478: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11479: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11480: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11481: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11482: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11483: my $decompressed = $env{'cgi.decompressed'};
11484: &Apache::lonnet::delenv('cgi.file');
11485: &Apache::lonnet::delenv('cgi.dir');
11486: &Apache::lonnet::delenv('cgi.decompressed');
11487: return ($decompressed,$result);
11488: }
11489:
1.1055 raeburn 11490: sub process_decompression {
11491: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11492: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 11493: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 11494: $error = &mt('Filename not a supported archive file type.').
11495: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11496: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11497: } else {
11498: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11499: if ($docuhome eq 'no_host') {
11500: $error = &mt('Could not determine home server for course.');
11501: } else {
11502: my @ids=&Apache::lonnet::current_machine_ids();
11503: my $currdir = "$dir_root/$destination";
11504: if (grep(/^\Q$docuhome\E$/,@ids)) {
11505: $dir = &LONCAPA::propath($docudom,$docuname).
11506: "$dir_root/$destination";
11507: } else {
11508: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11509: "$dir_root/$docudom/$docuname/$destination";
11510: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11511: $error = &mt('Archive file not found.');
11512: }
11513: }
1.1065 raeburn 11514: my (@to_overwrite,@to_skip);
11515: if ($env{'form.archive_overwrite_total'} > 0) {
11516: my $total = $env{'form.archive_overwrite_total'};
11517: for (my $i=0; $i<$total; $i++) {
11518: if ($env{'form.archive_overwrite_'.$i} == 1) {
11519: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11520: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11521: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11522: }
11523: }
11524: }
11525: my $numskip = scalar(@to_skip);
11526: if (($numskip > 0) &&
11527: ($numskip == $env{'form.archive_itemcount'})) {
11528: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11529: } elsif ($dir eq '') {
1.1055 raeburn 11530: $error = &mt('Directory containing archive file unavailable.');
11531: } elsif (!$error) {
1.1065 raeburn 11532: my ($decompressed,$display);
11533: if ($numskip > 0) {
11534: my $tempdir = time.'_'.$$.int(rand(10000));
11535: mkdir("$dir/$tempdir",0755);
11536: system("mv $dir/$file $dir/$tempdir/$file");
11537: ($decompressed,$display) =
11538: &decompress_uploaded_file($file,"$dir/$tempdir");
11539: foreach my $item (@to_skip) {
11540: if (($item ne '') && ($item !~ /\.\./)) {
11541: if (-f "$dir/$tempdir/$item") {
11542: unlink("$dir/$tempdir/$item");
11543: } elsif (-d "$dir/$tempdir/$item") {
11544: system("rm -rf $dir/$tempdir/$item");
11545: }
11546: }
11547: }
11548: system("mv $dir/$tempdir/* $dir");
11549: rmdir("$dir/$tempdir");
11550: } else {
11551: ($decompressed,$display) =
11552: &decompress_uploaded_file($file,$dir);
11553: }
1.1055 raeburn 11554: if ($decompressed eq 'ok') {
1.1065 raeburn 11555: $output = '<p class="LC_info">'.
11556: &mt('Files extracted successfully from archive.').
11557: '</p>'."\n";
1.1055 raeburn 11558: my ($warning,$result,@contents);
11559: my ($newdirlistref,$newlisterror) =
11560: &Apache::lonnet::dirlist($currdir,$docudom,
11561: $docuname,1);
11562: my (%is_dir,%changes,@newitems);
11563: my $dirptr = 16384;
1.1065 raeburn 11564: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11565: foreach my $dir_line (@{$newdirlistref}) {
11566: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11567: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11568: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11569: push(@newitems,$item);
11570: if ($dirptr&$testdir) {
11571: $is_dir{$item} = 1;
11572: }
11573: $changes{$item} = 1;
11574: }
11575: }
11576: }
11577: if (keys(%changes) > 0) {
11578: foreach my $item (sort(@newitems)) {
11579: if ($changes{$item}) {
11580: push(@contents,$item);
11581: }
11582: }
11583: }
11584: if (@contents > 0) {
1.1067 raeburn 11585: my $wantform;
11586: unless ($env{'form.autoextract_camtasia'}) {
11587: $wantform = 1;
11588: }
1.1056 raeburn 11589: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11590: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11591: $currdir,\%is_dir,
11592: \%children,\%parent,
1.1056 raeburn 11593: \@contents,\%dirorder,
11594: \%titles,$wantform);
1.1055 raeburn 11595: if ($datatable ne '') {
11596: $output .= &archive_options_form('decompressed',$datatable,
11597: $count,$hiddenelem);
1.1065 raeburn 11598: my $startcount = 6;
1.1055 raeburn 11599: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11600: \%titles,\%children);
1.1055 raeburn 11601: }
1.1067 raeburn 11602: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 11603: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 11604: my %displayed;
11605: my $total = 1;
11606: $env{'form.archive_directory'} = [];
11607: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11608: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11609: $path =~ s{/$}{};
11610: my $item;
11611: if ($path ne '') {
11612: $item = "$path/$titles{$i}";
11613: } else {
11614: $item = $titles{$i};
11615: }
11616: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11617: if ($item eq $contents[0]) {
11618: push(@{$env{'form.archive_directory'}},$i);
11619: $env{'form.archive_'.$i} = 'display';
11620: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11621: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 11622: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
11623: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 11624: $env{'form.archive_'.$i} = 'display';
11625: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11626: $displayed{'web'} = $i;
11627: } else {
1.1075.2.59 raeburn 11628: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
11629: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
11630: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 11631: push(@{$env{'form.archive_directory'}},$i);
11632: }
11633: $env{'form.archive_'.$i} = 'dependency';
11634: }
11635: $total ++;
11636: }
11637: for (my $i=1; $i<$total; $i++) {
11638: next if ($i == $displayed{'web'});
11639: next if ($i == $displayed{'folder'});
11640: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11641: }
11642: $env{'form.phase'} = 'decompress_cleanup';
11643: $env{'form.archivedelete'} = 1;
11644: $env{'form.archive_count'} = $total-1;
11645: $output .=
11646: &process_extracted_files('coursedocs',$docudom,
11647: $docuname,$destination,
11648: $dir_root,$hiddenelem);
11649: }
1.1055 raeburn 11650: } else {
11651: $warning = &mt('No new items extracted from archive file.');
11652: }
11653: } else {
11654: $output = $display;
11655: $error = &mt('An error occurred during extraction from the archive file.');
11656: }
11657: }
11658: }
11659: }
11660: if ($error) {
11661: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11662: $error.'</p>'."\n";
11663: }
11664: if ($warning) {
11665: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11666: }
11667: return $output;
11668: }
11669:
11670: sub get_extracted {
1.1056 raeburn 11671: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11672: $titles,$wantform) = @_;
1.1055 raeburn 11673: my $count = 0;
11674: my $depth = 0;
11675: my $datatable;
1.1056 raeburn 11676: my @hierarchy;
1.1055 raeburn 11677: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11678: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11679: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11680: foreach my $item (@{$contents}) {
11681: $count ++;
1.1056 raeburn 11682: @{$dirorder->{$count}} = @hierarchy;
11683: $titles->{$count} = $item;
1.1055 raeburn 11684: &archive_hierarchy($depth,$count,$parent,$children);
11685: if ($wantform) {
11686: $datatable .= &archive_row($is_dir->{$item},$item,
11687: $currdir,$depth,$count);
11688: }
11689: if ($is_dir->{$item}) {
11690: $depth ++;
1.1056 raeburn 11691: push(@hierarchy,$count);
11692: $parent->{$depth} = $count;
1.1055 raeburn 11693: $datatable .=
11694: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11695: \$depth,\$count,\@hierarchy,$dirorder,
11696: $children,$parent,$titles,$wantform);
1.1055 raeburn 11697: $depth --;
1.1056 raeburn 11698: pop(@hierarchy);
1.1055 raeburn 11699: }
11700: }
11701: return ($count,$datatable);
11702: }
11703:
11704: sub recurse_extracted_archive {
1.1056 raeburn 11705: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11706: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11707: my $result='';
1.1056 raeburn 11708: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11709: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11710: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11711: return $result;
11712: }
11713: my $dirptr = 16384;
11714: my ($newdirlistref,$newlisterror) =
11715: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11716: if (ref($newdirlistref) eq 'ARRAY') {
11717: foreach my $dir_line (@{$newdirlistref}) {
11718: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11719: unless ($item =~ /^\.+$/) {
11720: $$count ++;
1.1056 raeburn 11721: @{$dirorder->{$$count}} = @{$hierarchy};
11722: $titles->{$$count} = $item;
1.1055 raeburn 11723: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11724:
1.1055 raeburn 11725: my $is_dir;
11726: if ($dirptr&$testdir) {
11727: $is_dir = 1;
11728: }
11729: if ($wantform) {
11730: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11731: }
11732: if ($is_dir) {
11733: $$depth ++;
1.1056 raeburn 11734: push(@{$hierarchy},$$count);
11735: $parent->{$$depth} = $$count;
1.1055 raeburn 11736: $result .=
11737: &recurse_extracted_archive("$currdir/$item",$docudom,
11738: $docuname,$depth,$count,
1.1056 raeburn 11739: $hierarchy,$dirorder,$children,
11740: $parent,$titles,$wantform);
1.1055 raeburn 11741: $$depth --;
1.1056 raeburn 11742: pop(@{$hierarchy});
1.1055 raeburn 11743: }
11744: }
11745: }
11746: }
11747: return $result;
11748: }
11749:
11750: sub archive_hierarchy {
11751: my ($depth,$count,$parent,$children) =@_;
11752: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11753: if (exists($parent->{$depth})) {
11754: $children->{$parent->{$depth}} .= $count.':';
11755: }
11756: }
11757: return;
11758: }
11759:
11760: sub archive_row {
11761: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11762: my ($name) = ($item =~ m{([^/]+)$});
11763: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11764: 'display' => 'Add as file',
1.1055 raeburn 11765: 'dependency' => 'Include as dependency',
11766: 'discard' => 'Discard',
11767: );
11768: if ($is_dir) {
1.1059 raeburn 11769: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11770: }
1.1056 raeburn 11771: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11772: my $offset = 0;
1.1055 raeburn 11773: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11774: $offset ++;
1.1065 raeburn 11775: if ($action ne 'display') {
11776: $offset ++;
11777: }
1.1055 raeburn 11778: $output .= '<td><span class="LC_nobreak">'.
11779: '<label><input type="radio" name="archive_'.$count.
11780: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11781: my $text = $choices{$action};
11782: if ($is_dir) {
11783: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11784: if ($action eq 'display') {
1.1059 raeburn 11785: $text = &mt('Add as folder');
1.1055 raeburn 11786: }
1.1056 raeburn 11787: } else {
11788: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11789:
11790: }
11791: $output .= ' /> '.$choices{$action}.'</label></span>';
11792: if ($action eq 'dependency') {
11793: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11794: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11795: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11796: '<option value=""></option>'."\n".
11797: '</select>'."\n".
11798: '</div>';
1.1059 raeburn 11799: } elsif ($action eq 'display') {
11800: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11801: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11802: '</div>';
1.1055 raeburn 11803: }
1.1056 raeburn 11804: $output .= '</td>';
1.1055 raeburn 11805: }
11806: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11807: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11808: for (my $i=0; $i<$depth; $i++) {
11809: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11810: }
11811: if ($is_dir) {
11812: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11813: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11814: } else {
11815: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11816: }
11817: $output .= ' '.$name.'</td>'."\n".
11818: &end_data_table_row();
11819: return $output;
11820: }
11821:
11822: sub archive_options_form {
1.1065 raeburn 11823: my ($form,$display,$count,$hiddenelem) = @_;
11824: my %lt = &Apache::lonlocal::texthash(
11825: perm => 'Permanently remove archive file?',
11826: hows => 'How should each extracted item be incorporated in the course?',
11827: cont => 'Content actions for all',
11828: addf => 'Add as folder/file',
11829: incd => 'Include as dependency for a displayed file',
11830: disc => 'Discard',
11831: no => 'No',
11832: yes => 'Yes',
11833: save => 'Save',
11834: );
11835: my $output = <<"END";
11836: <form name="$form" method="post" action="">
11837: <p><span class="LC_nobreak">$lt{'perm'}
11838: <label>
11839: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11840: </label>
11841:
11842: <label>
11843: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11844: </span>
11845: </p>
11846: <input type="hidden" name="phase" value="decompress_cleanup" />
11847: <br />$lt{'hows'}
11848: <div class="LC_columnSection">
11849: <fieldset>
11850: <legend>$lt{'cont'}</legend>
11851: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11852: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11853: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11854: </fieldset>
11855: </div>
11856: END
11857: return $output.
1.1055 raeburn 11858: &start_data_table()."\n".
1.1065 raeburn 11859: $display."\n".
1.1055 raeburn 11860: &end_data_table()."\n".
11861: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11862: $hiddenelem.
1.1065 raeburn 11863: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11864: '</form>';
11865: }
11866:
11867: sub archive_javascript {
1.1056 raeburn 11868: my ($startcount,$numitems,$titles,$children) = @_;
11869: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11870: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11871: my $scripttag = <<START;
11872: <script type="text/javascript">
11873: // <![CDATA[
11874:
11875: function checkAll(form,prefix) {
11876: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11877: for (var i=0; i < form.elements.length; i++) {
11878: var id = form.elements[i].id;
11879: if ((id != '') && (id != undefined)) {
11880: if (idstr.test(id)) {
11881: if (form.elements[i].type == 'radio') {
11882: form.elements[i].checked = true;
1.1056 raeburn 11883: var nostart = i-$startcount;
1.1059 raeburn 11884: var offset = nostart%7;
11885: var count = (nostart-offset)/7;
1.1056 raeburn 11886: dependencyCheck(form,count,offset);
1.1055 raeburn 11887: }
11888: }
11889: }
11890: }
11891: }
11892:
11893: function propagateCheck(form,count) {
11894: if (count > 0) {
1.1059 raeburn 11895: var startelement = $startcount + ((count-1) * 7);
11896: for (var j=1; j<6; j++) {
11897: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11898: var item = startelement + j;
11899: if (form.elements[item].type == 'radio') {
11900: if (form.elements[item].checked) {
11901: containerCheck(form,count,j);
11902: break;
11903: }
1.1055 raeburn 11904: }
11905: }
11906: }
11907: }
11908: }
11909:
11910: numitems = $numitems
1.1056 raeburn 11911: var titles = new Array(numitems);
11912: var parents = new Array(numitems);
1.1055 raeburn 11913: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11914: parents[i] = new Array;
1.1055 raeburn 11915: }
1.1059 raeburn 11916: var maintitle = '$maintitle';
1.1055 raeburn 11917:
11918: START
11919:
1.1056 raeburn 11920: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11921: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11922: for (my $i=0; $i<@contents; $i ++) {
11923: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11924: }
11925: }
11926:
1.1056 raeburn 11927: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11928: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11929: }
11930:
1.1055 raeburn 11931: $scripttag .= <<END;
11932:
11933: function containerCheck(form,count,offset) {
11934: if (count > 0) {
1.1056 raeburn 11935: dependencyCheck(form,count,offset);
1.1059 raeburn 11936: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11937: form.elements[item].checked = true;
11938: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11939: if (parents[count].length > 0) {
11940: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11941: containerCheck(form,parents[count][j],offset);
11942: }
11943: }
11944: }
11945: }
11946: }
11947:
11948: function dependencyCheck(form,count,offset) {
11949: if (count > 0) {
1.1059 raeburn 11950: var chosen = (offset+$startcount)+7*(count-1);
11951: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11952: var currtype = form.elements[depitem].type;
11953: if (form.elements[chosen].value == 'dependency') {
11954: document.getElementById('arc_depon_'+count).style.display='block';
11955: form.elements[depitem].options.length = 0;
11956: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 11957: for (var i=1; i<=numitems; i++) {
11958: if (i == count) {
11959: continue;
11960: }
1.1059 raeburn 11961: var startelement = $startcount + (i-1) * 7;
11962: for (var j=1; j<6; j++) {
11963: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11964: var item = startelement + j;
11965: if (form.elements[item].type == 'radio') {
11966: if (form.elements[item].checked) {
11967: if (form.elements[item].value == 'display') {
11968: var n = form.elements[depitem].options.length;
11969: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11970: }
11971: }
11972: }
11973: }
11974: }
11975: }
11976: } else {
11977: document.getElementById('arc_depon_'+count).style.display='none';
11978: form.elements[depitem].options.length = 0;
11979: form.elements[depitem].options[0] = new Option('Select','',true,true);
11980: }
1.1059 raeburn 11981: titleCheck(form,count,offset);
1.1056 raeburn 11982: }
11983: }
11984:
11985: function propagateSelect(form,count,offset) {
11986: if (count > 0) {
1.1065 raeburn 11987: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11988: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11989: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11990: if (parents[count].length > 0) {
11991: for (var j=0; j<parents[count].length; j++) {
11992: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11993: }
11994: }
11995: }
11996: }
11997: }
1.1056 raeburn 11998:
11999: function containerSelect(form,count,offset,picked) {
12000: if (count > 0) {
1.1065 raeburn 12001: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12002: if (form.elements[item].type == 'radio') {
12003: if (form.elements[item].value == 'dependency') {
12004: if (form.elements[item+1].type == 'select-one') {
12005: for (var i=0; i<form.elements[item+1].options.length; i++) {
12006: if (form.elements[item+1].options[i].value == picked) {
12007: form.elements[item+1].selectedIndex = i;
12008: break;
12009: }
12010: }
12011: }
12012: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12013: if (parents[count].length > 0) {
12014: for (var j=0; j<parents[count].length; j++) {
12015: containerSelect(form,parents[count][j],offset,picked);
12016: }
12017: }
12018: }
12019: }
12020: }
12021: }
12022: }
12023:
1.1059 raeburn 12024: function titleCheck(form,count,offset) {
12025: if (count > 0) {
12026: var chosen = (offset+$startcount)+7*(count-1);
12027: var depitem = $startcount + ((count-1) * 7) + 2;
12028: var currtype = form.elements[depitem].type;
12029: if (form.elements[chosen].value == 'display') {
12030: document.getElementById('arc_title_'+count).style.display='block';
12031: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12032: document.getElementById('archive_title_'+count).value=maintitle;
12033: }
12034: } else {
12035: document.getElementById('arc_title_'+count).style.display='none';
12036: if (currtype == 'text') {
12037: document.getElementById('archive_title_'+count).value='';
12038: }
12039: }
12040: }
12041: return;
12042: }
12043:
1.1055 raeburn 12044: // ]]>
12045: </script>
12046: END
12047: return $scripttag;
12048: }
12049:
12050: sub process_extracted_files {
1.1067 raeburn 12051: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12052: my $numitems = $env{'form.archive_count'};
12053: return unless ($numitems);
12054: my @ids=&Apache::lonnet::current_machine_ids();
12055: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12056: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12057: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12058: if (grep(/^\Q$docuhome\E$/,@ids)) {
12059: $prefix = &LONCAPA::propath($docudom,$docuname);
12060: $pathtocheck = "$dir_root/$destination";
12061: $dir = $dir_root;
12062: $ishome = 1;
12063: } else {
12064: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12065: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
12066: $dir = "$dir_root/$docudom/$docuname";
12067: }
12068: my $currdir = "$dir_root/$destination";
12069: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12070: if ($env{'form.folderpath'}) {
12071: my @items = split('&',$env{'form.folderpath'});
12072: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12073: if ($env{'form.folderpath'} =~ /\:1$/) {
12074: $containers{'0'}='page';
12075: } else {
12076: $containers{'0'}='sequence';
12077: }
1.1055 raeburn 12078: }
12079: my @archdirs = &get_env_multiple('form.archive_directory');
12080: if ($numitems) {
12081: for (my $i=1; $i<=$numitems; $i++) {
12082: my $path = $env{'form.archive_content_'.$i};
12083: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12084: my $item = $1;
12085: $toplevelitems{$item} = $i;
12086: if (grep(/^\Q$i\E$/,@archdirs)) {
12087: $is_dir{$item} = 1;
12088: }
12089: }
12090: }
12091: }
1.1067 raeburn 12092: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12093: if (keys(%toplevelitems) > 0) {
12094: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12095: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12096: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12097: }
1.1066 raeburn 12098: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12099: if ($numitems) {
12100: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12101: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12102: my $path = $env{'form.archive_content_'.$i};
12103: if ($path =~ /^\Q$pathtocheck\E/) {
12104: if ($env{'form.archive_'.$i} eq 'discard') {
12105: if ($prefix ne '' && $path ne '') {
12106: if (-e $prefix.$path) {
1.1066 raeburn 12107: if ((@archdirs > 0) &&
12108: (grep(/^\Q$i\E$/,@archdirs))) {
12109: $todeletedir{$prefix.$path} = 1;
12110: } else {
12111: $todelete{$prefix.$path} = 1;
12112: }
1.1055 raeburn 12113: }
12114: }
12115: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12116: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12117: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12118: $docstitle = $env{'form.archive_title_'.$i};
12119: if ($docstitle eq '') {
12120: $docstitle = $title;
12121: }
1.1055 raeburn 12122: $outer = 0;
1.1056 raeburn 12123: if (ref($dirorder{$i}) eq 'ARRAY') {
12124: if (@{$dirorder{$i}} > 0) {
12125: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12126: if ($env{'form.archive_'.$item} eq 'display') {
12127: $outer = $item;
12128: last;
12129: }
12130: }
12131: }
12132: }
12133: my ($errtext,$fatal) =
12134: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12135: '/'.$folders{$outer}.'.'.
12136: $containers{$outer});
12137: next if ($fatal);
12138: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12139: if ($context eq 'coursedocs') {
1.1056 raeburn 12140: $mapinner{$i} = time;
1.1055 raeburn 12141: $folders{$i} = 'default_'.$mapinner{$i};
12142: $containers{$i} = 'sequence';
12143: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12144: $folders{$i}.'.'.$containers{$i};
12145: my $newidx = &LONCAPA::map::getresidx();
12146: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12147: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12148: push(@LONCAPA::map::order,$newidx);
12149: my ($outtext,$errtext) =
12150: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12151: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12152: '.'.$containers{$outer},1,1);
1.1056 raeburn 12153: $newseqid{$i} = $newidx;
1.1067 raeburn 12154: unless ($errtext) {
12155: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
12156: }
1.1055 raeburn 12157: }
12158: } else {
12159: if ($context eq 'coursedocs') {
12160: my $newidx=&LONCAPA::map::getresidx();
12161: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12162: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12163: $title;
12164: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12165: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
12166: }
12167: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12168: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12169: }
12170: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12171: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 12172: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 12173: unless ($ishome) {
12174: my $fetch = "$newdest{$i}/$title";
12175: $fetch =~ s/^\Q$prefix$dir\E//;
12176: $prompttofetch{$fetch} = 1;
12177: }
1.1055 raeburn 12178: }
12179: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12180: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12181: push(@LONCAPA::map::order, $newidx);
12182: my ($outtext,$errtext)=
12183: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12184: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12185: '.'.$containers{$outer},1,1);
1.1067 raeburn 12186: unless ($errtext) {
12187: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12188: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
12189: }
12190: }
1.1055 raeburn 12191: }
12192: }
1.1075.2.11 raeburn 12193: }
12194: } else {
12195: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12196: }
12197: }
12198: for (my $i=1; $i<=$numitems; $i++) {
12199: next unless ($env{'form.archive_'.$i} eq 'dependency');
12200: my $path = $env{'form.archive_content_'.$i};
12201: if ($path =~ /^\Q$pathtocheck\E/) {
12202: my ($title) = ($path =~ m{/([^/]+)$});
12203: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12204: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12205: if (ref($dirorder{$i}) eq 'ARRAY') {
12206: my ($itemidx,$fullpath,$relpath);
12207: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12208: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12209: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12210: if ($dirorder{$i}->[$j] eq $container) {
12211: $itemidx = $j;
1.1056 raeburn 12212: }
12213: }
1.1075.2.11 raeburn 12214: }
12215: if ($itemidx eq '') {
12216: $itemidx = 0;
12217: }
12218: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12219: if ($mapinner{$referrer{$i}}) {
12220: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12221: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12222: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12223: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12224: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12225: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12226: if (!-e $fullpath) {
12227: mkdir($fullpath,0755);
1.1056 raeburn 12228: }
12229: }
1.1075.2.11 raeburn 12230: } else {
12231: last;
1.1056 raeburn 12232: }
1.1075.2.11 raeburn 12233: }
12234: }
12235: } elsif ($newdest{$referrer{$i}}) {
12236: $fullpath = $newdest{$referrer{$i}};
12237: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12238: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12239: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12240: last;
12241: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12242: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12243: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12244: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12245: if (!-e $fullpath) {
12246: mkdir($fullpath,0755);
1.1056 raeburn 12247: }
12248: }
1.1075.2.11 raeburn 12249: } else {
12250: last;
1.1056 raeburn 12251: }
1.1075.2.11 raeburn 12252: }
12253: }
12254: if ($fullpath ne '') {
12255: if (-e "$prefix$path") {
12256: system("mv $prefix$path $fullpath/$title");
12257: }
12258: if (-e "$fullpath/$title") {
12259: my $showpath;
12260: if ($relpath ne '') {
12261: $showpath = "$relpath/$title";
12262: } else {
12263: $showpath = "/$title";
1.1056 raeburn 12264: }
1.1075.2.11 raeburn 12265: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12266: }
12267: unless ($ishome) {
12268: my $fetch = "$fullpath/$title";
12269: $fetch =~ s/^\Q$prefix$dir\E//;
12270: $prompttofetch{$fetch} = 1;
1.1055 raeburn 12271: }
12272: }
12273: }
1.1075.2.11 raeburn 12274: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12275: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12276: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12277: }
12278: } else {
1.1075.2.11 raeburn 12279: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 12280: }
12281: }
12282: if (keys(%todelete)) {
12283: foreach my $key (keys(%todelete)) {
12284: unlink($key);
1.1066 raeburn 12285: }
12286: }
12287: if (keys(%todeletedir)) {
12288: foreach my $key (keys(%todeletedir)) {
12289: rmdir($key);
12290: }
12291: }
12292: foreach my $dir (sort(keys(%is_dir))) {
12293: if (($pathtocheck ne '') && ($dir ne '')) {
12294: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12295: }
12296: }
1.1067 raeburn 12297: if ($result ne '') {
12298: $output .= '<ul>'."\n".
12299: $result."\n".
12300: '</ul>';
12301: }
12302: unless ($ishome) {
12303: my $replicationfail;
12304: foreach my $item (keys(%prompttofetch)) {
12305: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12306: unless ($fetchresult eq 'ok') {
12307: $replicationfail .= '<li>'.$item.'</li>'."\n";
12308: }
12309: }
12310: if ($replicationfail) {
12311: $output .= '<p class="LC_error">'.
12312: &mt('Course home server failed to retrieve:').'<ul>'.
12313: $replicationfail.
12314: '</ul></p>';
12315: }
12316: }
1.1055 raeburn 12317: } else {
12318: $warning = &mt('No items found in archive.');
12319: }
12320: if ($error) {
12321: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12322: $error.'</p>'."\n";
12323: }
12324: if ($warning) {
12325: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12326: }
12327: return $output;
12328: }
12329:
1.1066 raeburn 12330: sub cleanup_empty_dirs {
12331: my ($path) = @_;
12332: if (($path ne '') && (-d $path)) {
12333: if (opendir(my $dirh,$path)) {
12334: my @dircontents = grep(!/^\./,readdir($dirh));
12335: my $numitems = 0;
12336: foreach my $item (@dircontents) {
12337: if (-d "$path/$item") {
1.1075.2.28 raeburn 12338: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12339: if (-e "$path/$item") {
12340: $numitems ++;
12341: }
12342: } else {
12343: $numitems ++;
12344: }
12345: }
12346: if ($numitems == 0) {
12347: rmdir($path);
12348: }
12349: closedir($dirh);
12350: }
12351: }
12352: return;
12353: }
12354:
1.41 ng 12355: =pod
1.45 matthew 12356:
1.1075.2.56 raeburn 12357: =item * &get_folder_hierarchy()
1.1068 raeburn 12358:
12359: Provides hierarchy of names of folders/sub-folders containing the current
12360: item,
12361:
12362: Inputs: 3
12363: - $navmap - navmaps object
12364:
12365: - $map - url for map (either the trigger itself, or map containing
12366: the resource, which is the trigger).
12367:
12368: - $showitem - 1 => show title for map itself; 0 => do not show.
12369:
12370: Outputs: 1 @pathitems - array of folder/subfolder names.
12371:
12372: =cut
12373:
12374: sub get_folder_hierarchy {
12375: my ($navmap,$map,$showitem) = @_;
12376: my @pathitems;
12377: if (ref($navmap)) {
12378: my $mapres = $navmap->getResourceByUrl($map);
12379: if (ref($mapres)) {
12380: my $pcslist = $mapres->map_hierarchy();
12381: if ($pcslist ne '') {
12382: my @pcs = split(/,/,$pcslist);
12383: foreach my $pc (@pcs) {
12384: if ($pc == 1) {
1.1075.2.38 raeburn 12385: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12386: } else {
12387: my $res = $navmap->getByMapPc($pc);
12388: if (ref($res)) {
12389: my $title = $res->compTitle();
12390: $title =~ s/\W+/_/g;
12391: if ($title ne '') {
12392: push(@pathitems,$title);
12393: }
12394: }
12395: }
12396: }
12397: }
1.1071 raeburn 12398: if ($showitem) {
12399: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12400: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12401: } else {
12402: my $maptitle = $mapres->compTitle();
12403: $maptitle =~ s/\W+/_/g;
12404: if ($maptitle ne '') {
12405: push(@pathitems,$maptitle);
12406: }
1.1068 raeburn 12407: }
12408: }
12409: }
12410: }
12411: return @pathitems;
12412: }
12413:
12414: =pod
12415:
1.1015 raeburn 12416: =item * &get_turnedin_filepath()
12417:
12418: Determines path in a user's portfolio file for storage of files uploaded
12419: to a specific essayresponse or dropbox item.
12420:
12421: Inputs: 3 required + 1 optional.
12422: $symb is symb for resource, $uname and $udom are for current user (required).
12423: $caller is optional (can be "submission", if routine is called when storing
12424: an upoaded file when "Submit Answer" button was pressed).
12425:
12426: Returns array containing $path and $multiresp.
12427: $path is path in portfolio. $multiresp is 1 if this resource contains more
12428: than one file upload item. Callers of routine should append partid as a
12429: subdirectory to $path in cases where $multiresp is 1.
12430:
12431: Called by: homework/essayresponse.pm and homework/structuretags.pm
12432:
12433: =cut
12434:
12435: sub get_turnedin_filepath {
12436: my ($symb,$uname,$udom,$caller) = @_;
12437: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12438: my $turnindir;
12439: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12440: $turnindir = $userhash{'turnindir'};
12441: my ($path,$multiresp);
12442: if ($turnindir eq '') {
12443: if ($caller eq 'submission') {
12444: $turnindir = &mt('turned in');
12445: $turnindir =~ s/\W+/_/g;
12446: my %newhash = (
12447: 'turnindir' => $turnindir,
12448: );
12449: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12450: }
12451: }
12452: if ($turnindir ne '') {
12453: $path = '/'.$turnindir.'/';
12454: my ($multipart,$turnin,@pathitems);
12455: my $navmap = Apache::lonnavmaps::navmap->new();
12456: if (defined($navmap)) {
12457: my $mapres = $navmap->getResourceByUrl($map);
12458: if (ref($mapres)) {
12459: my $pcslist = $mapres->map_hierarchy();
12460: if ($pcslist ne '') {
12461: foreach my $pc (split(/,/,$pcslist)) {
12462: my $res = $navmap->getByMapPc($pc);
12463: if (ref($res)) {
12464: my $title = $res->compTitle();
12465: $title =~ s/\W+/_/g;
12466: if ($title ne '') {
1.1075.2.48 raeburn 12467: if (($pc > 1) && (length($title) > 12)) {
12468: $title = substr($title,0,12);
12469: }
1.1015 raeburn 12470: push(@pathitems,$title);
12471: }
12472: }
12473: }
12474: }
12475: my $maptitle = $mapres->compTitle();
12476: $maptitle =~ s/\W+/_/g;
12477: if ($maptitle ne '') {
1.1075.2.48 raeburn 12478: if (length($maptitle) > 12) {
12479: $maptitle = substr($maptitle,0,12);
12480: }
1.1015 raeburn 12481: push(@pathitems,$maptitle);
12482: }
12483: unless ($env{'request.state'} eq 'construct') {
12484: my $res = $navmap->getBySymb($symb);
12485: if (ref($res)) {
12486: my $partlist = $res->parts();
12487: my $totaluploads = 0;
12488: if (ref($partlist) eq 'ARRAY') {
12489: foreach my $part (@{$partlist}) {
12490: my @types = $res->responseType($part);
12491: my @ids = $res->responseIds($part);
12492: for (my $i=0; $i < scalar(@ids); $i++) {
12493: if ($types[$i] eq 'essay') {
12494: my $partid = $part.'_'.$ids[$i];
12495: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12496: $totaluploads ++;
12497: }
12498: }
12499: }
12500: }
12501: if ($totaluploads > 1) {
12502: $multiresp = 1;
12503: }
12504: }
12505: }
12506: }
12507: } else {
12508: return;
12509: }
12510: } else {
12511: return;
12512: }
12513: my $restitle=&Apache::lonnet::gettitle($symb);
12514: $restitle =~ s/\W+/_/g;
12515: if ($restitle eq '') {
12516: $restitle = ($resurl =~ m{/[^/]+$});
12517: if ($restitle eq '') {
12518: $restitle = time;
12519: }
12520: }
1.1075.2.48 raeburn 12521: if (length($restitle) > 12) {
12522: $restitle = substr($restitle,0,12);
12523: }
1.1015 raeburn 12524: push(@pathitems,$restitle);
12525: $path .= join('/',@pathitems);
12526: }
12527: return ($path,$multiresp);
12528: }
12529:
12530: =pod
12531:
1.464 albertel 12532: =back
1.41 ng 12533:
1.112 bowersj2 12534: =head1 CSV Upload/Handling functions
1.38 albertel 12535:
1.41 ng 12536: =over 4
12537:
1.648 raeburn 12538: =item * &upfile_store($r)
1.41 ng 12539:
12540: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12541: needs $env{'form.upfile'}
1.41 ng 12542: returns $datatoken to be put into hidden field
12543:
12544: =cut
1.31 albertel 12545:
12546: sub upfile_store {
12547: my $r=shift;
1.258 albertel 12548: $env{'form.upfile'}=~s/\r/\n/gs;
12549: $env{'form.upfile'}=~s/\f/\n/gs;
12550: $env{'form.upfile'}=~s/\n+/\n/gs;
12551: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12552:
1.258 albertel 12553: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12554: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12555: {
1.158 raeburn 12556: my $datafile = $r->dir_config('lonDaemons').
12557: '/tmp/'.$datatoken.'.tmp';
12558: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12559: print $fh $env{'form.upfile'};
1.158 raeburn 12560: close($fh);
12561: }
1.31 albertel 12562: }
12563: return $datatoken;
12564: }
12565:
1.56 matthew 12566: =pod
12567:
1.648 raeburn 12568: =item * &load_tmp_file($r)
1.41 ng 12569:
12570: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12571: needs $env{'form.datatoken'},
12572: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12573:
12574: =cut
1.31 albertel 12575:
12576: sub load_tmp_file {
12577: my $r=shift;
12578: my @studentdata=();
12579: {
1.158 raeburn 12580: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12581: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12582: if ( open(my $fh,"<$studentfile") ) {
12583: @studentdata=<$fh>;
12584: close($fh);
12585: }
1.31 albertel 12586: }
1.258 albertel 12587: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12588: }
12589:
1.56 matthew 12590: =pod
12591:
1.648 raeburn 12592: =item * &upfile_record_sep()
1.41 ng 12593:
12594: Separate uploaded file into records
12595: returns array of records,
1.258 albertel 12596: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12597:
12598: =cut
1.31 albertel 12599:
12600: sub upfile_record_sep {
1.258 albertel 12601: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12602: } else {
1.248 albertel 12603: my @records;
1.258 albertel 12604: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12605: if ($line=~/^\s*$/) { next; }
12606: push(@records,$line);
12607: }
12608: return @records;
1.31 albertel 12609: }
12610: }
12611:
1.56 matthew 12612: =pod
12613:
1.648 raeburn 12614: =item * &record_sep($record)
1.41 ng 12615:
1.258 albertel 12616: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12617:
12618: =cut
12619:
1.263 www 12620: sub takeleft {
12621: my $index=shift;
12622: return substr('0000'.$index,-4,4);
12623: }
12624:
1.31 albertel 12625: sub record_sep {
12626: my $record=shift;
12627: my %components=();
1.258 albertel 12628: if ($env{'form.upfiletype'} eq 'xml') {
12629: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12630: my $i=0;
1.356 albertel 12631: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12632: $field=~s/^(\"|\')//;
12633: $field=~s/(\"|\')$//;
1.263 www 12634: $components{&takeleft($i)}=$field;
1.31 albertel 12635: $i++;
12636: }
1.258 albertel 12637: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12638: my $i=0;
1.356 albertel 12639: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12640: $field=~s/^(\"|\')//;
12641: $field=~s/(\"|\')$//;
1.263 www 12642: $components{&takeleft($i)}=$field;
1.31 albertel 12643: $i++;
12644: }
12645: } else {
1.561 www 12646: my $separator=',';
1.480 banghart 12647: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12648: $separator=';';
1.480 banghart 12649: }
1.31 albertel 12650: my $i=0;
1.561 www 12651: # the character we are looking for to indicate the end of a quote or a record
12652: my $looking_for=$separator;
12653: # do not add the characters to the fields
12654: my $ignore=0;
12655: # we just encountered a separator (or the beginning of the record)
12656: my $just_found_separator=1;
12657: # store the field we are working on here
12658: my $field='';
12659: # work our way through all characters in record
12660: foreach my $character ($record=~/(.)/g) {
12661: if ($character eq $looking_for) {
12662: if ($character ne $separator) {
12663: # Found the end of a quote, again looking for separator
12664: $looking_for=$separator;
12665: $ignore=1;
12666: } else {
12667: # Found a separator, store away what we got
12668: $components{&takeleft($i)}=$field;
12669: $i++;
12670: $just_found_separator=1;
12671: $ignore=0;
12672: $field='';
12673: }
12674: next;
12675: }
12676: # single or double quotation marks after a separator indicate beginning of a quote
12677: # we are now looking for the end of the quote and need to ignore separators
12678: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12679: $looking_for=$character;
12680: next;
12681: }
12682: # ignore would be true after we reached the end of a quote
12683: if ($ignore) { next; }
12684: if (($just_found_separator) && ($character=~/\s/)) { next; }
12685: $field.=$character;
12686: $just_found_separator=0;
1.31 albertel 12687: }
1.561 www 12688: # catch the very last entry, since we never encountered the separator
12689: $components{&takeleft($i)}=$field;
1.31 albertel 12690: }
12691: return %components;
12692: }
12693:
1.144 matthew 12694: ######################################################
12695: ######################################################
12696:
1.56 matthew 12697: =pod
12698:
1.648 raeburn 12699: =item * &upfile_select_html()
1.41 ng 12700:
1.144 matthew 12701: Return HTML code to select a file from the users machine and specify
12702: the file type.
1.41 ng 12703:
12704: =cut
12705:
1.144 matthew 12706: ######################################################
12707: ######################################################
1.31 albertel 12708: sub upfile_select_html {
1.144 matthew 12709: my %Types = (
12710: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12711: semisv => &mt('Semicolon separated values'),
1.144 matthew 12712: space => &mt('Space separated'),
12713: tab => &mt('Tabulator separated'),
12714: # xml => &mt('HTML/XML'),
12715: );
12716: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12717: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12718: foreach my $type (sort(keys(%Types))) {
12719: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12720: }
12721: $Str .= "</select>\n";
12722: return $Str;
1.31 albertel 12723: }
12724:
1.301 albertel 12725: sub get_samples {
12726: my ($records,$toget) = @_;
12727: my @samples=({});
12728: my $got=0;
12729: foreach my $rec (@$records) {
12730: my %temp = &record_sep($rec);
12731: if (! grep(/\S/, values(%temp))) { next; }
12732: if (%temp) {
12733: $samples[$got]=\%temp;
12734: $got++;
12735: if ($got == $toget) { last; }
12736: }
12737: }
12738: return \@samples;
12739: }
12740:
1.144 matthew 12741: ######################################################
12742: ######################################################
12743:
1.56 matthew 12744: =pod
12745:
1.648 raeburn 12746: =item * &csv_print_samples($r,$records)
1.41 ng 12747:
12748: Prints a table of sample values from each column uploaded $r is an
12749: Apache Request ref, $records is an arrayref from
12750: &Apache::loncommon::upfile_record_sep
12751:
12752: =cut
12753:
1.144 matthew 12754: ######################################################
12755: ######################################################
1.31 albertel 12756: sub csv_print_samples {
12757: my ($r,$records) = @_;
1.662 bisitz 12758: my $samples = &get_samples($records,5);
1.301 albertel 12759:
1.594 raeburn 12760: $r->print(&mt('Samples').'<br />'.&start_data_table().
12761: &start_data_table_header_row());
1.356 albertel 12762: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12763: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12764: $r->print(&end_data_table_header_row());
1.301 albertel 12765: foreach my $hash (@$samples) {
1.594 raeburn 12766: $r->print(&start_data_table_row());
1.356 albertel 12767: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12768: $r->print('<td>');
1.356 albertel 12769: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12770: $r->print('</td>');
12771: }
1.594 raeburn 12772: $r->print(&end_data_table_row());
1.31 albertel 12773: }
1.594 raeburn 12774: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12775: }
12776:
1.144 matthew 12777: ######################################################
12778: ######################################################
12779:
1.56 matthew 12780: =pod
12781:
1.648 raeburn 12782: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12783:
12784: Prints a table to create associations between values and table columns.
1.144 matthew 12785:
1.41 ng 12786: $r is an Apache Request ref,
12787: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12788: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12789:
12790: =cut
12791:
1.144 matthew 12792: ######################################################
12793: ######################################################
1.31 albertel 12794: sub csv_print_select_table {
12795: my ($r,$records,$d) = @_;
1.301 albertel 12796: my $i=0;
12797: my $samples = &get_samples($records,1);
1.144 matthew 12798: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12799: &start_data_table().&start_data_table_header_row().
1.144 matthew 12800: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12801: '<th>'.&mt('Column').'</th>'.
12802: &end_data_table_header_row()."\n");
1.356 albertel 12803: foreach my $array_ref (@$d) {
12804: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12805: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12806:
1.875 bisitz 12807: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12808: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12809: $r->print('<option value="none"></option>');
1.356 albertel 12810: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12811: $r->print('<option value="'.$sample.'"'.
12812: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12813: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12814: }
1.594 raeburn 12815: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12816: $i++;
12817: }
1.594 raeburn 12818: $r->print(&end_data_table());
1.31 albertel 12819: $i--;
12820: return $i;
12821: }
1.56 matthew 12822:
1.144 matthew 12823: ######################################################
12824: ######################################################
12825:
1.56 matthew 12826: =pod
1.31 albertel 12827:
1.648 raeburn 12828: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12829:
12830: Prints a table of sample values from the upload and can make associate samples to internal names.
12831:
12832: $r is an Apache Request ref,
12833: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12834: $d is an array of 2 element arrays (internal name, displayed name)
12835:
12836: =cut
12837:
1.144 matthew 12838: ######################################################
12839: ######################################################
1.31 albertel 12840: sub csv_samples_select_table {
12841: my ($r,$records,$d) = @_;
12842: my $i=0;
1.144 matthew 12843: #
1.662 bisitz 12844: my $max_samples = 5;
12845: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12846: $r->print(&start_data_table().
12847: &start_data_table_header_row().'<th>'.
12848: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12849: &end_data_table_header_row());
1.301 albertel 12850:
12851: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12852: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12853: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12854: foreach my $option (@$d) {
12855: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12856: $r->print('<option value="'.$value.'"'.
1.253 albertel 12857: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12858: $display.'</option>');
1.31 albertel 12859: }
12860: $r->print('</select></td><td>');
1.662 bisitz 12861: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12862: if (defined($samples->[$line]{$key})) {
12863: $r->print($samples->[$line]{$key}."<br />\n");
12864: }
12865: }
1.594 raeburn 12866: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12867: $i++;
12868: }
1.594 raeburn 12869: $r->print(&end_data_table());
1.31 albertel 12870: $i--;
12871: return($i);
1.115 matthew 12872: }
12873:
1.144 matthew 12874: ######################################################
12875: ######################################################
12876:
1.115 matthew 12877: =pod
12878:
1.648 raeburn 12879: =item * &clean_excel_name($name)
1.115 matthew 12880:
12881: Returns a replacement for $name which does not contain any illegal characters.
12882:
12883: =cut
12884:
1.144 matthew 12885: ######################################################
12886: ######################################################
1.115 matthew 12887: sub clean_excel_name {
12888: my ($name) = @_;
12889: $name =~ s/[:\*\?\/\\]//g;
12890: if (length($name) > 31) {
12891: $name = substr($name,0,31);
12892: }
12893: return $name;
1.25 albertel 12894: }
1.84 albertel 12895:
1.85 albertel 12896: =pod
12897:
1.648 raeburn 12898: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12899:
12900: Returns either 1 or undef
12901:
12902: 1 if the part is to be hidden, undef if it is to be shown
12903:
12904: Arguments are:
12905:
12906: $id the id of the part to be checked
12907: $symb, optional the symb of the resource to check
12908: $udom, optional the domain of the user to check for
12909: $uname, optional the username of the user to check for
12910:
12911: =cut
1.84 albertel 12912:
12913: sub check_if_partid_hidden {
12914: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12915: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12916: $symb,$udom,$uname);
1.141 albertel 12917: my $truth=1;
12918: #if the string starts with !, then the list is the list to show not hide
12919: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12920: my @hiddenlist=split(/,/,$hiddenparts);
12921: foreach my $checkid (@hiddenlist) {
1.141 albertel 12922: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12923: }
1.141 albertel 12924: return !$truth;
1.84 albertel 12925: }
1.127 matthew 12926:
1.138 matthew 12927:
12928: ############################################################
12929: ############################################################
12930:
12931: =pod
12932:
1.157 matthew 12933: =back
12934:
1.138 matthew 12935: =head1 cgi-bin script and graphing routines
12936:
1.157 matthew 12937: =over 4
12938:
1.648 raeburn 12939: =item * &get_cgi_id()
1.138 matthew 12940:
12941: Inputs: none
12942:
12943: Returns an id which can be used to pass environment variables
12944: to various cgi-bin scripts. These environment variables will
12945: be removed from the users environment after a given time by
12946: the routine &Apache::lonnet::transfer_profile_to_env.
12947:
12948: =cut
12949:
12950: ############################################################
12951: ############################################################
1.152 albertel 12952: my $uniq=0;
1.136 matthew 12953: sub get_cgi_id {
1.154 albertel 12954: $uniq=($uniq+1)%100000;
1.280 albertel 12955: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12956: }
12957:
1.127 matthew 12958: ############################################################
12959: ############################################################
12960:
12961: =pod
12962:
1.648 raeburn 12963: =item * &DrawBarGraph()
1.127 matthew 12964:
1.138 matthew 12965: Facilitates the plotting of data in a (stacked) bar graph.
12966: Puts plot definition data into the users environment in order for
12967: graph.png to plot it. Returns an <img> tag for the plot.
12968: The bars on the plot are labeled '1','2',...,'n'.
12969:
12970: Inputs:
12971:
12972: =over 4
12973:
12974: =item $Title: string, the title of the plot
12975:
12976: =item $xlabel: string, text describing the X-axis of the plot
12977:
12978: =item $ylabel: string, text describing the Y-axis of the plot
12979:
12980: =item $Max: scalar, the maximum Y value to use in the plot
12981: If $Max is < any data point, the graph will not be rendered.
12982:
1.140 matthew 12983: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12984: they are plotted. If undefined, default values will be used.
12985:
1.178 matthew 12986: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12987:
1.138 matthew 12988: =item @Values: An array of array references. Each array reference holds data
12989: to be plotted in a stacked bar chart.
12990:
1.239 matthew 12991: =item If the final element of @Values is a hash reference the key/value
12992: pairs will be added to the graph definition.
12993:
1.138 matthew 12994: =back
12995:
12996: Returns:
12997:
12998: An <img> tag which references graph.png and the appropriate identifying
12999: information for the plot.
13000:
1.127 matthew 13001: =cut
13002:
13003: ############################################################
13004: ############################################################
1.134 matthew 13005: sub DrawBarGraph {
1.178 matthew 13006: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13007: #
13008: if (! defined($colors)) {
13009: $colors = ['#33ff00',
13010: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13011: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13012: ];
13013: }
1.228 matthew 13014: my $extra_settings = {};
13015: if (ref($Values[-1]) eq 'HASH') {
13016: $extra_settings = pop(@Values);
13017: }
1.127 matthew 13018: #
1.136 matthew 13019: my $identifier = &get_cgi_id();
13020: my $id = 'cgi.'.$identifier;
1.129 matthew 13021: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13022: return '';
13023: }
1.225 matthew 13024: #
13025: my @Labels;
13026: if (defined($labels)) {
13027: @Labels = @$labels;
13028: } else {
13029: for (my $i=0;$i<@{$Values[0]};$i++) {
13030: push (@Labels,$i+1);
13031: }
13032: }
13033: #
1.129 matthew 13034: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13035: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13036: my %ValuesHash;
13037: my $NumSets=1;
13038: foreach my $array (@Values) {
13039: next if (! ref($array));
1.136 matthew 13040: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13041: join(',',@$array);
1.129 matthew 13042: }
1.127 matthew 13043: #
1.136 matthew 13044: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13045: if ($NumBars < 3) {
13046: $width = 120+$NumBars*32;
1.220 matthew 13047: $xskip = 1;
1.225 matthew 13048: $bar_width = 30;
13049: } elsif ($NumBars < 5) {
13050: $width = 120+$NumBars*20;
13051: $xskip = 1;
13052: $bar_width = 20;
1.220 matthew 13053: } elsif ($NumBars < 10) {
1.136 matthew 13054: $width = 120+$NumBars*15;
13055: $xskip = 1;
13056: $bar_width = 15;
13057: } elsif ($NumBars <= 25) {
13058: $width = 120+$NumBars*11;
13059: $xskip = 5;
13060: $bar_width = 8;
13061: } elsif ($NumBars <= 50) {
13062: $width = 120+$NumBars*8;
13063: $xskip = 5;
13064: $bar_width = 4;
13065: } else {
13066: $width = 120+$NumBars*8;
13067: $xskip = 5;
13068: $bar_width = 4;
13069: }
13070: #
1.137 matthew 13071: $Max = 1 if ($Max < 1);
13072: if ( int($Max) < $Max ) {
13073: $Max++;
13074: $Max = int($Max);
13075: }
1.127 matthew 13076: $Title = '' if (! defined($Title));
13077: $xlabel = '' if (! defined($xlabel));
13078: $ylabel = '' if (! defined($ylabel));
1.369 www 13079: $ValuesHash{$id.'.title'} = &escape($Title);
13080: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13081: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13082: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13083: $ValuesHash{$id.'.NumBars'} = $NumBars;
13084: $ValuesHash{$id.'.NumSets'} = $NumSets;
13085: $ValuesHash{$id.'.PlotType'} = 'bar';
13086: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13087: $ValuesHash{$id.'.height'} = $height;
13088: $ValuesHash{$id.'.width'} = $width;
13089: $ValuesHash{$id.'.xskip'} = $xskip;
13090: $ValuesHash{$id.'.bar_width'} = $bar_width;
13091: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13092: #
1.228 matthew 13093: # Deal with other parameters
13094: while (my ($key,$value) = each(%$extra_settings)) {
13095: $ValuesHash{$id.'.'.$key} = $value;
13096: }
13097: #
1.646 raeburn 13098: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13099: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13100: }
13101:
13102: ############################################################
13103: ############################################################
13104:
13105: =pod
13106:
1.648 raeburn 13107: =item * &DrawXYGraph()
1.137 matthew 13108:
1.138 matthew 13109: Facilitates the plotting of data in an XY graph.
13110: Puts plot definition data into the users environment in order for
13111: graph.png to plot it. Returns an <img> tag for the plot.
13112:
13113: Inputs:
13114:
13115: =over 4
13116:
13117: =item $Title: string, the title of the plot
13118:
13119: =item $xlabel: string, text describing the X-axis of the plot
13120:
13121: =item $ylabel: string, text describing the Y-axis of the plot
13122:
13123: =item $Max: scalar, the maximum Y value to use in the plot
13124: If $Max is < any data point, the graph will not be rendered.
13125:
13126: =item $colors: Array ref containing the hex color codes for the data to be
13127: plotted in. If undefined, default values will be used.
13128:
13129: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13130:
13131: =item $Ydata: Array ref containing Array refs.
1.185 www 13132: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13133:
13134: =item %Values: hash indicating or overriding any default values which are
13135: passed to graph.png.
13136: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13137:
13138: =back
13139:
13140: Returns:
13141:
13142: An <img> tag which references graph.png and the appropriate identifying
13143: information for the plot.
13144:
1.137 matthew 13145: =cut
13146:
13147: ############################################################
13148: ############################################################
13149: sub DrawXYGraph {
13150: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13151: #
13152: # Create the identifier for the graph
13153: my $identifier = &get_cgi_id();
13154: my $id = 'cgi.'.$identifier;
13155: #
13156: $Title = '' if (! defined($Title));
13157: $xlabel = '' if (! defined($xlabel));
13158: $ylabel = '' if (! defined($ylabel));
13159: my %ValuesHash =
13160: (
1.369 www 13161: $id.'.title' => &escape($Title),
13162: $id.'.xlabel' => &escape($xlabel),
13163: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13164: $id.'.y_max_value'=> $Max,
13165: $id.'.labels' => join(',',@$Xlabels),
13166: $id.'.PlotType' => 'XY',
13167: );
13168: #
13169: if (defined($colors) && ref($colors) eq 'ARRAY') {
13170: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13171: }
13172: #
13173: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13174: return '';
13175: }
13176: my $NumSets=1;
1.138 matthew 13177: foreach my $array (@{$Ydata}){
1.137 matthew 13178: next if (! ref($array));
13179: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13180: }
1.138 matthew 13181: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13182: #
13183: # Deal with other parameters
13184: while (my ($key,$value) = each(%Values)) {
13185: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13186: }
13187: #
1.646 raeburn 13188: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13189: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13190: }
13191:
13192: ############################################################
13193: ############################################################
13194:
13195: =pod
13196:
1.648 raeburn 13197: =item * &DrawXYYGraph()
1.138 matthew 13198:
13199: Facilitates the plotting of data in an XY graph with two Y axes.
13200: Puts plot definition data into the users environment in order for
13201: graph.png to plot it. Returns an <img> tag for the plot.
13202:
13203: Inputs:
13204:
13205: =over 4
13206:
13207: =item $Title: string, the title of the plot
13208:
13209: =item $xlabel: string, text describing the X-axis of the plot
13210:
13211: =item $ylabel: string, text describing the Y-axis of the plot
13212:
13213: =item $colors: Array ref containing the hex color codes for the data to be
13214: plotted in. If undefined, default values will be used.
13215:
13216: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13217:
13218: =item $Ydata1: The first data set
13219:
13220: =item $Min1: The minimum value of the left Y-axis
13221:
13222: =item $Max1: The maximum value of the left Y-axis
13223:
13224: =item $Ydata2: The second data set
13225:
13226: =item $Min2: The minimum value of the right Y-axis
13227:
13228: =item $Max2: The maximum value of the left Y-axis
13229:
13230: =item %Values: hash indicating or overriding any default values which are
13231: passed to graph.png.
13232: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13233:
13234: =back
13235:
13236: Returns:
13237:
13238: An <img> tag which references graph.png and the appropriate identifying
13239: information for the plot.
1.136 matthew 13240:
13241: =cut
13242:
13243: ############################################################
13244: ############################################################
1.137 matthew 13245: sub DrawXYYGraph {
13246: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13247: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13248: #
13249: # Create the identifier for the graph
13250: my $identifier = &get_cgi_id();
13251: my $id = 'cgi.'.$identifier;
13252: #
13253: $Title = '' if (! defined($Title));
13254: $xlabel = '' if (! defined($xlabel));
13255: $ylabel = '' if (! defined($ylabel));
13256: my %ValuesHash =
13257: (
1.369 www 13258: $id.'.title' => &escape($Title),
13259: $id.'.xlabel' => &escape($xlabel),
13260: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13261: $id.'.labels' => join(',',@$Xlabels),
13262: $id.'.PlotType' => 'XY',
13263: $id.'.NumSets' => 2,
1.137 matthew 13264: $id.'.two_axes' => 1,
13265: $id.'.y1_max_value' => $Max1,
13266: $id.'.y1_min_value' => $Min1,
13267: $id.'.y2_max_value' => $Max2,
13268: $id.'.y2_min_value' => $Min2,
1.136 matthew 13269: );
13270: #
1.137 matthew 13271: if (defined($colors) && ref($colors) eq 'ARRAY') {
13272: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13273: }
13274: #
13275: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13276: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13277: return '';
13278: }
13279: my $NumSets=1;
1.137 matthew 13280: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13281: next if (! ref($array));
13282: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13283: }
13284: #
13285: # Deal with other parameters
13286: while (my ($key,$value) = each(%Values)) {
13287: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13288: }
13289: #
1.646 raeburn 13290: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13291: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13292: }
13293:
13294: ############################################################
13295: ############################################################
13296:
13297: =pod
13298:
1.157 matthew 13299: =back
13300:
1.139 matthew 13301: =head1 Statistics helper routines?
13302:
13303: Bad place for them but what the hell.
13304:
1.157 matthew 13305: =over 4
13306:
1.648 raeburn 13307: =item * &chartlink()
1.139 matthew 13308:
13309: Returns a link to the chart for a specific student.
13310:
13311: Inputs:
13312:
13313: =over 4
13314:
13315: =item $linktext: The text of the link
13316:
13317: =item $sname: The students username
13318:
13319: =item $sdomain: The students domain
13320:
13321: =back
13322:
1.157 matthew 13323: =back
13324:
1.139 matthew 13325: =cut
13326:
13327: ############################################################
13328: ############################################################
13329: sub chartlink {
13330: my ($linktext, $sname, $sdomain) = @_;
13331: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13332: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13333: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13334: '">'.$linktext.'</a>';
1.153 matthew 13335: }
13336:
13337: #######################################################
13338: #######################################################
13339:
13340: =pod
13341:
13342: =head1 Course Environment Routines
1.157 matthew 13343:
13344: =over 4
1.153 matthew 13345:
1.648 raeburn 13346: =item * &restore_course_settings()
1.153 matthew 13347:
1.648 raeburn 13348: =item * &store_course_settings()
1.153 matthew 13349:
13350: Restores/Store indicated form parameters from the course environment.
13351: Will not overwrite existing values of the form parameters.
13352:
13353: Inputs:
13354: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13355:
13356: a hash ref describing the data to be stored. For example:
13357:
13358: %Save_Parameters = ('Status' => 'scalar',
13359: 'chartoutputmode' => 'scalar',
13360: 'chartoutputdata' => 'scalar',
13361: 'Section' => 'array',
1.373 raeburn 13362: 'Group' => 'array',
1.153 matthew 13363: 'StudentData' => 'array',
13364: 'Maps' => 'array');
13365:
13366: Returns: both routines return nothing
13367:
1.631 raeburn 13368: =back
13369:
1.153 matthew 13370: =cut
13371:
13372: #######################################################
13373: #######################################################
13374: sub store_course_settings {
1.496 albertel 13375: return &store_settings($env{'request.course.id'},@_);
13376: }
13377:
13378: sub store_settings {
1.153 matthew 13379: # save to the environment
13380: # appenv the same items, just to be safe
1.300 albertel 13381: my $udom = $env{'user.domain'};
13382: my $uname = $env{'user.name'};
1.496 albertel 13383: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13384: my %SaveHash;
13385: my %AppHash;
13386: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13387: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13388: my $envname = 'environment.'.$basename;
1.258 albertel 13389: if (exists($env{'form.'.$setting})) {
1.153 matthew 13390: # Save this value away
13391: if ($type eq 'scalar' &&
1.258 albertel 13392: (! exists($env{$envname}) ||
13393: $env{$envname} ne $env{'form.'.$setting})) {
13394: $SaveHash{$basename} = $env{'form.'.$setting};
13395: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13396: } elsif ($type eq 'array') {
13397: my $stored_form;
1.258 albertel 13398: if (ref($env{'form.'.$setting})) {
1.153 matthew 13399: $stored_form = join(',',
13400: map {
1.369 www 13401: &escape($_);
1.258 albertel 13402: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13403: } else {
13404: $stored_form =
1.369 www 13405: &escape($env{'form.'.$setting});
1.153 matthew 13406: }
13407: # Determine if the array contents are the same.
1.258 albertel 13408: if ($stored_form ne $env{$envname}) {
1.153 matthew 13409: $SaveHash{$basename} = $stored_form;
13410: $AppHash{$envname} = $stored_form;
13411: }
13412: }
13413: }
13414: }
13415: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13416: $udom,$uname);
1.153 matthew 13417: if ($put_result !~ /^(ok|delayed)/) {
13418: &Apache::lonnet::logthis('unable to save form parameters, '.
13419: 'got error:'.$put_result);
13420: }
13421: # Make sure these settings stick around in this session, too
1.646 raeburn 13422: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13423: return;
13424: }
13425:
13426: sub restore_course_settings {
1.499 albertel 13427: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13428: }
13429:
13430: sub restore_settings {
13431: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13432: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13433: next if (exists($env{'form.'.$setting}));
1.496 albertel 13434: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13435: '.'.$setting;
1.258 albertel 13436: if (exists($env{$envname})) {
1.153 matthew 13437: if ($type eq 'scalar') {
1.258 albertel 13438: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13439: } elsif ($type eq 'array') {
1.258 albertel 13440: $env{'form.'.$setting} = [
1.153 matthew 13441: map {
1.369 www 13442: &unescape($_);
1.258 albertel 13443: } split(',',$env{$envname})
1.153 matthew 13444: ];
13445: }
13446: }
13447: }
1.127 matthew 13448: }
13449:
1.618 raeburn 13450: #######################################################
13451: #######################################################
13452:
13453: =pod
13454:
13455: =head1 Domain E-mail Routines
13456:
13457: =over 4
13458:
1.648 raeburn 13459: =item * &build_recipient_list()
1.618 raeburn 13460:
1.1075.2.44 raeburn 13461: Build recipient lists for following types of e-mail:
1.766 raeburn 13462: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 13463: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13464: module change checking, student/employee ID conflict checks, as
13465: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13466: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13467:
13468: Inputs:
1.1075.2.44 raeburn 13469: defmail (scalar - email address of default recipient),
13470: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13471: requestsmail, updatesmail, or idconflictsmail).
13472:
1.619 raeburn 13473: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 13474:
13475: origmail (scalar - email address of recipient from loncapa.conf,
13476: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13477:
1.655 raeburn 13478: Returns: comma separated list of addresses to which to send e-mail.
13479:
13480: =back
1.618 raeburn 13481:
13482: =cut
13483:
13484: ############################################################
13485: ############################################################
13486: sub build_recipient_list {
1.619 raeburn 13487: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13488: my @recipients;
13489: my $otheremails;
13490: my %domconfig =
13491: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13492: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13493: if (exists($domconfig{'contacts'}{$mailing})) {
13494: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13495: my @contacts = ('adminemail','supportemail');
13496: foreach my $item (@contacts) {
13497: if ($domconfig{'contacts'}{$mailing}{$item}) {
13498: my $addr = $domconfig{'contacts'}{$item};
13499: if (!grep(/^\Q$addr\E$/,@recipients)) {
13500: push(@recipients,$addr);
13501: }
1.619 raeburn 13502: }
1.766 raeburn 13503: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13504: }
13505: }
1.766 raeburn 13506: } elsif ($origmail ne '') {
13507: push(@recipients,$origmail);
1.618 raeburn 13508: }
1.619 raeburn 13509: } elsif ($origmail ne '') {
13510: push(@recipients,$origmail);
1.618 raeburn 13511: }
1.688 raeburn 13512: if (defined($defmail)) {
13513: if ($defmail ne '') {
13514: push(@recipients,$defmail);
13515: }
1.618 raeburn 13516: }
13517: if ($otheremails) {
1.619 raeburn 13518: my @others;
13519: if ($otheremails =~ /,/) {
13520: @others = split(/,/,$otheremails);
1.618 raeburn 13521: } else {
1.619 raeburn 13522: push(@others,$otheremails);
13523: }
13524: foreach my $addr (@others) {
13525: if (!grep(/^\Q$addr\E$/,@recipients)) {
13526: push(@recipients,$addr);
13527: }
1.618 raeburn 13528: }
13529: }
1.619 raeburn 13530: my $recipientlist = join(',',@recipients);
1.618 raeburn 13531: return $recipientlist;
13532: }
13533:
1.127 matthew 13534: ############################################################
13535: ############################################################
1.154 albertel 13536:
1.655 raeburn 13537: =pod
13538:
13539: =head1 Course Catalog Routines
13540:
13541: =over 4
13542:
13543: =item * &gather_categories()
13544:
13545: Converts category definitions - keys of categories hash stored in
13546: coursecategories in configuration.db on the primary library server in a
13547: domain - to an array. Also generates javascript and idx hash used to
13548: generate Domain Coordinator interface for editing Course Categories.
13549:
13550: Inputs:
1.663 raeburn 13551:
1.655 raeburn 13552: categories (reference to hash of category definitions).
1.663 raeburn 13553:
1.655 raeburn 13554: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13555: categories and subcategories).
1.663 raeburn 13556:
1.655 raeburn 13557: idx (reference to hash of counters used in Domain Coordinator interface for
13558: editing Course Categories).
1.663 raeburn 13559:
1.655 raeburn 13560: jsarray (reference to array of categories used to create Javascript arrays for
13561: Domain Coordinator interface for editing Course Categories).
13562:
13563: Returns: nothing
13564:
13565: Side effects: populates cats, idx and jsarray.
13566:
13567: =cut
13568:
13569: sub gather_categories {
13570: my ($categories,$cats,$idx,$jsarray) = @_;
13571: my %counters;
13572: my $num = 0;
13573: foreach my $item (keys(%{$categories})) {
13574: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13575: if ($container eq '' && $depth == 0) {
13576: $cats->[$depth][$categories->{$item}] = $cat;
13577: } else {
13578: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13579: }
13580: my ($escitem,$tail) = split(/:/,$item,2);
13581: if ($counters{$tail} eq '') {
13582: $counters{$tail} = $num;
13583: $num ++;
13584: }
13585: if (ref($idx) eq 'HASH') {
13586: $idx->{$item} = $counters{$tail};
13587: }
13588: if (ref($jsarray) eq 'ARRAY') {
13589: push(@{$jsarray->[$counters{$tail}]},$item);
13590: }
13591: }
13592: return;
13593: }
13594:
13595: =pod
13596:
13597: =item * &extract_categories()
13598:
13599: Used to generate breadcrumb trails for course categories.
13600:
13601: Inputs:
1.663 raeburn 13602:
1.655 raeburn 13603: categories (reference to hash of category definitions).
1.663 raeburn 13604:
1.655 raeburn 13605: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13606: categories and subcategories).
1.663 raeburn 13607:
1.655 raeburn 13608: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13609:
1.655 raeburn 13610: allitems (reference to hash - key is category key
13611: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13612:
1.655 raeburn 13613: idx (reference to hash of counters used in Domain Coordinator interface for
13614: editing Course Categories).
1.663 raeburn 13615:
1.655 raeburn 13616: jsarray (reference to array of categories used to create Javascript arrays for
13617: Domain Coordinator interface for editing Course Categories).
13618:
1.665 raeburn 13619: subcats (reference to hash of arrays containing all subcategories within each
13620: category, -recursive)
13621:
1.655 raeburn 13622: Returns: nothing
13623:
13624: Side effects: populates trails and allitems hash references.
13625:
13626: =cut
13627:
13628: sub extract_categories {
1.665 raeburn 13629: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13630: if (ref($categories) eq 'HASH') {
13631: &gather_categories($categories,$cats,$idx,$jsarray);
13632: if (ref($cats->[0]) eq 'ARRAY') {
13633: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13634: my $name = $cats->[0][$i];
13635: my $item = &escape($name).'::0';
13636: my $trailstr;
13637: if ($name eq 'instcode') {
13638: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13639: } elsif ($name eq 'communities') {
13640: $trailstr = &mt('Communities');
1.655 raeburn 13641: } else {
13642: $trailstr = $name;
13643: }
13644: if ($allitems->{$item} eq '') {
13645: push(@{$trails},$trailstr);
13646: $allitems->{$item} = scalar(@{$trails})-1;
13647: }
13648: my @parents = ($name);
13649: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13650: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13651: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13652: if (ref($subcats) eq 'HASH') {
13653: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13654: }
13655: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13656: }
13657: } else {
13658: if (ref($subcats) eq 'HASH') {
13659: $subcats->{$item} = [];
1.655 raeburn 13660: }
13661: }
13662: }
13663: }
13664: }
13665: return;
13666: }
13667:
13668: =pod
13669:
1.1075.2.56 raeburn 13670: =item * &recurse_categories()
1.655 raeburn 13671:
13672: Recursively used to generate breadcrumb trails for course categories.
13673:
13674: Inputs:
1.663 raeburn 13675:
1.655 raeburn 13676: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13677: categories and subcategories).
1.663 raeburn 13678:
1.655 raeburn 13679: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13680:
13681: category (current course category, for which breadcrumb trail is being generated).
13682:
13683: trails (reference to array of breadcrumb trails for each category).
13684:
1.655 raeburn 13685: allitems (reference to hash - key is category key
13686: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13687:
1.655 raeburn 13688: parents (array containing containers directories for current category,
13689: back to top level).
13690:
13691: Returns: nothing
13692:
13693: Side effects: populates trails and allitems hash references
13694:
13695: =cut
13696:
13697: sub recurse_categories {
1.665 raeburn 13698: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13699: my $shallower = $depth - 1;
13700: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13701: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13702: my $name = $cats->[$depth]{$category}[$k];
13703: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13704: my $trailstr = join(' -> ',(@{$parents},$category));
13705: if ($allitems->{$item} eq '') {
13706: push(@{$trails},$trailstr);
13707: $allitems->{$item} = scalar(@{$trails})-1;
13708: }
13709: my $deeper = $depth+1;
13710: push(@{$parents},$category);
1.665 raeburn 13711: if (ref($subcats) eq 'HASH') {
13712: my $subcat = &escape($name).':'.$category.':'.$depth;
13713: for (my $j=@{$parents}; $j>=0; $j--) {
13714: my $higher;
13715: if ($j > 0) {
13716: $higher = &escape($parents->[$j]).':'.
13717: &escape($parents->[$j-1]).':'.$j;
13718: } else {
13719: $higher = &escape($parents->[$j]).'::'.$j;
13720: }
13721: push(@{$subcats->{$higher}},$subcat);
13722: }
13723: }
13724: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13725: $subcats);
1.655 raeburn 13726: pop(@{$parents});
13727: }
13728: } else {
13729: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13730: my $trailstr = join(' -> ',(@{$parents},$category));
13731: if ($allitems->{$item} eq '') {
13732: push(@{$trails},$trailstr);
13733: $allitems->{$item} = scalar(@{$trails})-1;
13734: }
13735: }
13736: return;
13737: }
13738:
1.663 raeburn 13739: =pod
13740:
1.1075.2.56 raeburn 13741: =item * &assign_categories_table()
1.663 raeburn 13742:
13743: Create a datatable for display of hierarchical categories in a domain,
13744: with checkboxes to allow a course to be categorized.
13745:
13746: Inputs:
13747:
13748: cathash - reference to hash of categories defined for the domain (from
13749: configuration.db)
13750:
13751: currcat - scalar with an & separated list of categories assigned to a course.
13752:
1.919 raeburn 13753: type - scalar contains course type (Course or Community).
13754:
1.663 raeburn 13755: Returns: $output (markup to be displayed)
13756:
13757: =cut
13758:
13759: sub assign_categories_table {
1.919 raeburn 13760: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13761: my $output;
13762: if (ref($cathash) eq 'HASH') {
13763: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13764: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13765: $maxdepth = scalar(@cats);
13766: if (@cats > 0) {
13767: my $itemcount = 0;
13768: if (ref($cats[0]) eq 'ARRAY') {
13769: my @currcategories;
13770: if ($currcat ne '') {
13771: @currcategories = split('&',$currcat);
13772: }
1.919 raeburn 13773: my $table;
1.663 raeburn 13774: for (my $i=0; $i<@{$cats[0]}; $i++) {
13775: my $parent = $cats[0][$i];
1.919 raeburn 13776: next if ($parent eq 'instcode');
13777: if ($type eq 'Community') {
13778: next unless ($parent eq 'communities');
13779: } else {
13780: next if ($parent eq 'communities');
13781: }
1.663 raeburn 13782: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13783: my $item = &escape($parent).'::0';
13784: my $checked = '';
13785: if (@currcategories > 0) {
13786: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13787: $checked = ' checked="checked"';
1.663 raeburn 13788: }
13789: }
1.919 raeburn 13790: my $parent_title = $parent;
13791: if ($parent eq 'communities') {
13792: $parent_title = &mt('Communities');
13793: }
13794: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13795: '<input type="checkbox" name="usecategory" value="'.
13796: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13797: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13798: my $depth = 1;
13799: push(@path,$parent);
1.919 raeburn 13800: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13801: pop(@path);
1.919 raeburn 13802: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13803: $itemcount ++;
13804: }
1.919 raeburn 13805: if ($itemcount) {
13806: $output = &Apache::loncommon::start_data_table().
13807: $table.
13808: &Apache::loncommon::end_data_table();
13809: }
1.663 raeburn 13810: }
13811: }
13812: }
13813: return $output;
13814: }
13815:
13816: =pod
13817:
1.1075.2.56 raeburn 13818: =item * &assign_category_rows()
1.663 raeburn 13819:
13820: Create a datatable row for display of nested categories in a domain,
13821: with checkboxes to allow a course to be categorized,called recursively.
13822:
13823: Inputs:
13824:
13825: itemcount - track row number for alternating colors
13826:
13827: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13828: categories and subcategories.
13829:
13830: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13831:
13832: parent - parent of current category item
13833:
13834: path - Array containing all categories back up through the hierarchy from the
13835: current category to the top level.
13836:
13837: currcategories - reference to array of current categories assigned to the course
13838:
13839: Returns: $output (markup to be displayed).
13840:
13841: =cut
13842:
13843: sub assign_category_rows {
13844: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13845: my ($text,$name,$item,$chgstr);
13846: if (ref($cats) eq 'ARRAY') {
13847: my $maxdepth = scalar(@{$cats});
13848: if (ref($cats->[$depth]) eq 'HASH') {
13849: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13850: my $numchildren = @{$cats->[$depth]{$parent}};
13851: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 13852: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13853: for (my $j=0; $j<$numchildren; $j++) {
13854: $name = $cats->[$depth]{$parent}[$j];
13855: $item = &escape($name).':'.&escape($parent).':'.$depth;
13856: my $deeper = $depth+1;
13857: my $checked = '';
13858: if (ref($currcategories) eq 'ARRAY') {
13859: if (@{$currcategories} > 0) {
13860: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13861: $checked = ' checked="checked"';
1.663 raeburn 13862: }
13863: }
13864: }
1.664 raeburn 13865: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13866: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13867: $item.'"'.$checked.' />'.$name.'</label></span>'.
13868: '<input type="hidden" name="catname" value="'.$name.'" />'.
13869: '</td><td>';
1.663 raeburn 13870: if (ref($path) eq 'ARRAY') {
13871: push(@{$path},$name);
13872: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13873: pop(@{$path});
13874: }
13875: $text .= '</td></tr>';
13876: }
13877: $text .= '</table></td>';
13878: }
13879: }
13880: }
13881: return $text;
13882: }
13883:
1.1075.2.69 raeburn 13884: =pod
13885:
13886: =back
13887:
13888: =cut
13889:
1.655 raeburn 13890: ############################################################
13891: ############################################################
13892:
13893:
1.443 albertel 13894: sub commit_customrole {
1.664 raeburn 13895: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13896: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13897: ($start?', '.&mt('starting').' '.localtime($start):'').
13898: ($end?', ending '.localtime($end):'').': <b>'.
13899: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13900: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13901: '</b><br />';
13902: return $output;
13903: }
13904:
13905: sub commit_standardrole {
1.1075.2.31 raeburn 13906: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13907: my ($output,$logmsg,$linefeed);
13908: if ($context eq 'auto') {
13909: $linefeed = "\n";
13910: } else {
13911: $linefeed = "<br />\n";
13912: }
1.443 albertel 13913: if ($three eq 'st') {
1.541 raeburn 13914: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 13915: $one,$two,$sec,$context,$credits);
1.541 raeburn 13916: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13917: ($result eq 'unknown_course') || ($result eq 'refused')) {
13918: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13919: } else {
1.541 raeburn 13920: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13921: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13922: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13923: if ($context eq 'auto') {
13924: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13925: } else {
13926: $output .= '<b>'.$result.'</b>'.$linefeed.
13927: &mt('Add to classlist').': <b>ok</b>';
13928: }
13929: $output .= $linefeed;
1.443 albertel 13930: }
13931: } else {
13932: $output = &mt('Assigning').' '.$three.' in '.$url.
13933: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13934: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13935: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13936: if ($context eq 'auto') {
13937: $output .= $result.$linefeed;
13938: } else {
13939: $output .= '<b>'.$result.'</b>'.$linefeed;
13940: }
1.443 albertel 13941: }
13942: return $output;
13943: }
13944:
13945: sub commit_studentrole {
1.1075.2.31 raeburn 13946: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13947: $credits) = @_;
1.626 raeburn 13948: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13949: if ($context eq 'auto') {
13950: $linefeed = "\n";
13951: } else {
13952: $linefeed = '<br />'."\n";
13953: }
1.443 albertel 13954: if (defined($one) && defined($two)) {
13955: my $cid=$one.'_'.$two;
13956: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13957: my $secchange = 0;
13958: my $expire_role_result;
13959: my $modify_section_result;
1.628 raeburn 13960: if ($oldsec ne '-1') {
13961: if ($oldsec ne $sec) {
1.443 albertel 13962: $secchange = 1;
1.628 raeburn 13963: my $now = time;
1.443 albertel 13964: my $uurl='/'.$cid;
13965: $uurl=~s/\_/\//g;
13966: if ($oldsec) {
13967: $uurl.='/'.$oldsec;
13968: }
1.626 raeburn 13969: $oldsecurl = $uurl;
1.628 raeburn 13970: $expire_role_result =
1.652 raeburn 13971: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13972: if ($env{'request.course.sec'} ne '') {
13973: if ($expire_role_result eq 'refused') {
13974: my @roles = ('st');
13975: my @statuses = ('previous');
13976: my @roledoms = ($one);
13977: my $withsec = 1;
13978: my %roleshash =
13979: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13980: \@statuses,\@roles,\@roledoms,$withsec);
13981: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13982: my ($oldstart,$oldend) =
13983: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13984: if ($oldend > 0 && $oldend <= $now) {
13985: $expire_role_result = 'ok';
13986: }
13987: }
13988: }
13989: }
1.443 albertel 13990: $result = $expire_role_result;
13991: }
13992: }
13993: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 13994: $modify_section_result =
13995: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13996: undef,undef,undef,$sec,
13997: $end,$start,'','',$cid,
13998: '',$context,$credits);
1.443 albertel 13999: if ($modify_section_result =~ /^ok/) {
14000: if ($secchange == 1) {
1.628 raeburn 14001: if ($sec eq '') {
14002: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14003: } else {
14004: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14005: }
1.443 albertel 14006: } elsif ($oldsec eq '-1') {
1.628 raeburn 14007: if ($sec eq '') {
14008: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14009: } else {
14010: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14011: }
1.443 albertel 14012: } else {
1.628 raeburn 14013: if ($sec eq '') {
14014: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14015: } else {
14016: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14017: }
1.443 albertel 14018: }
14019: } else {
1.628 raeburn 14020: if ($secchange) {
14021: $$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;
14022: } else {
14023: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14024: }
1.443 albertel 14025: }
14026: $result = $modify_section_result;
14027: } elsif ($secchange == 1) {
1.628 raeburn 14028: if ($oldsec eq '') {
1.1075.2.20 raeburn 14029: $$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 14030: } else {
14031: $$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;
14032: }
1.626 raeburn 14033: if ($expire_role_result eq 'refused') {
14034: my $newsecurl = '/'.$cid;
14035: $newsecurl =~ s/\_/\//g;
14036: if ($sec ne '') {
14037: $newsecurl.='/'.$sec;
14038: }
14039: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14040: if ($sec eq '') {
14041: $$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;
14042: } else {
14043: $$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;
14044: }
14045: }
14046: }
1.443 albertel 14047: }
14048: } else {
1.626 raeburn 14049: $$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 14050: $result = "error: incomplete course id\n";
14051: }
14052: return $result;
14053: }
14054:
1.1075.2.25 raeburn 14055: sub show_role_extent {
14056: my ($scope,$context,$role) = @_;
14057: $scope =~ s{^/}{};
14058: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14059: push(@courseroles,'co');
14060: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14061: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14062: $scope =~ s{/}{_};
14063: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14064: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14065: my ($audom,$auname) = split(/\//,$scope);
14066: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14067: &Apache::loncommon::plainname($auname,$audom).'</span>');
14068: } else {
14069: $scope =~ s{/$}{};
14070: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14071: &Apache::lonnet::domain($scope,'description').'</span>');
14072: }
14073: }
14074:
1.443 albertel 14075: ############################################################
14076: ############################################################
14077:
1.566 albertel 14078: sub check_clone {
1.578 raeburn 14079: my ($args,$linefeed) = @_;
1.566 albertel 14080: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14081: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14082: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14083: my $clonemsg;
14084: my $can_clone = 0;
1.944 raeburn 14085: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14086: if ($lctype ne 'community') {
14087: $lctype = 'course';
14088: }
1.566 albertel 14089: if ($clonehome eq 'no_host') {
1.944 raeburn 14090: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14091: $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'});
14092: } else {
14093: $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'});
14094: }
1.566 albertel 14095: } else {
14096: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 14097: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14098: if ($clonedesc{'type'} ne 'Community') {
14099: $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'});
14100: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14101: }
14102: }
1.882 raeburn 14103: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
14104: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 14105: $can_clone = 1;
14106: } else {
1.1075.2.95 raeburn 14107: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 14108: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 14109: if ($clonehash{'cloners'} eq '') {
14110: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
14111: if ($domdefs{'canclone'}) {
14112: unless ($domdefs{'canclone'} eq 'none') {
14113: if ($domdefs{'canclone'} eq 'domain') {
14114: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
14115: $can_clone = 1;
14116: }
14117: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14118: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
14119: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
14120: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
14121: $can_clone = 1;
14122: }
14123: }
14124: }
1.908 raeburn 14125: }
1.1075.2.95 raeburn 14126: } else {
14127: my @cloners = split(/,/,$clonehash{'cloners'});
14128: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 14129: $can_clone = 1;
1.1075.2.95 raeburn 14130: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 14131: $can_clone = 1;
1.1075.2.96! raeburn 14132: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
! 14133: $can_clone = 1;
1.1075.2.95 raeburn 14134: }
14135: unless ($can_clone) {
1.1075.2.96! raeburn 14136: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
! 14137: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 14138: my (%gotdomdefaults,%gotcodedefaults);
14139: foreach my $cloner (@cloners) {
14140: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
14141: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
14142: my (%codedefaults,@code_order);
14143: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
14144: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
14145: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
14146: }
14147: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
14148: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
14149: }
14150: } else {
14151: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
14152: \%codedefaults,
14153: \@code_order);
14154: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
14155: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
14156: }
14157: if (@code_order > 0) {
14158: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
14159: $cloner,$clonehash{'internal.coursecode'},
14160: $args->{'crscode'})) {
14161: $can_clone = 1;
14162: last;
14163: }
14164: }
14165: }
14166: }
14167: }
1.1075.2.96! raeburn 14168: }
! 14169: }
! 14170: unless ($can_clone) {
! 14171: my $ccrole = 'cc';
! 14172: if ($args->{'crstype'} eq 'Community') {
! 14173: $ccrole = 'co';
! 14174: }
! 14175: my %roleshash =
! 14176: &Apache::lonnet::get_my_roles($args->{'ccuname'},
! 14177: $args->{'ccdomain'},
! 14178: 'userroles',['active'],[$ccrole],
! 14179: [$args->{'clonedomain'}]);
! 14180: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
! 14181: $can_clone = 1;
! 14182: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
! 14183: $args->{'ccuname'},$args->{'ccdomain'})) {
! 14184: $can_clone = 1;
1.1075.2.95 raeburn 14185: }
14186: }
14187: unless ($can_clone) {
14188: if ($args->{'crstype'} eq 'Community') {
14189: $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'});
14190: } else {
14191: $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'});
1.578 raeburn 14192: }
1.566 albertel 14193: }
1.578 raeburn 14194: }
1.566 albertel 14195: }
14196: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14197: }
14198:
1.444 albertel 14199: sub construct_course {
1.1075.2.59 raeburn 14200: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 14201: my $outcome;
1.541 raeburn 14202: my $linefeed = '<br />'."\n";
14203: if ($context eq 'auto') {
14204: $linefeed = "\n";
14205: }
1.566 albertel 14206:
14207: #
14208: # Are we cloning?
14209: #
14210: my ($can_clone, $clonemsg, $cloneid, $clonehome);
14211: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 14212: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 14213: if ($context ne 'auto') {
1.578 raeburn 14214: if ($clonemsg ne '') {
14215: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
14216: }
1.566 albertel 14217: }
14218: $outcome .= $clonemsg.$linefeed;
14219:
14220: if (!$can_clone) {
14221: return (0,$outcome);
14222: }
14223: }
14224:
1.444 albertel 14225: #
14226: # Open course
14227: #
14228: my $crstype = lc($args->{'crstype'});
14229: my %cenv=();
14230: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
14231: $args->{'cdescr'},
14232: $args->{'curl'},
14233: $args->{'course_home'},
14234: $args->{'nonstandard'},
14235: $args->{'crscode'},
14236: $args->{'ccuname'}.':'.
14237: $args->{'ccdomain'},
1.882 raeburn 14238: $args->{'crstype'},
1.885 raeburn 14239: $cnum,$context,$category);
1.444 albertel 14240:
14241: # Note: The testing routines depend on this being output; see
14242: # Utils::Course. This needs to at least be output as a comment
14243: # if anyone ever decides to not show this, and Utils::Course::new
14244: # will need to be suitably modified.
1.541 raeburn 14245: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 14246: if ($$courseid =~ /^error:/) {
14247: return (0,$outcome);
14248: }
14249:
1.444 albertel 14250: #
14251: # Check if created correctly
14252: #
1.479 albertel 14253: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 14254: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 14255: if ($crsuhome eq 'no_host') {
14256: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
14257: return (0,$outcome);
14258: }
1.541 raeburn 14259: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 14260:
1.444 albertel 14261: #
1.566 albertel 14262: # Do the cloning
14263: #
14264: if ($can_clone && $cloneid) {
14265: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14266: if ($context ne 'auto') {
14267: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14268: }
14269: $outcome .= $clonemsg.$linefeed;
14270: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14271: # Copy all files
1.637 www 14272: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14273: # Restore URL
1.566 albertel 14274: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14275: # Restore title
1.566 albertel 14276: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14277: # Restore creation date, creator and creation context.
14278: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14279: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14280: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14281: # Mark as cloned
1.566 albertel 14282: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14283: # Need to clone grading mode
14284: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14285: $cenv{'grading'}=$newenv{'grading'};
14286: # Do not clone these environment entries
14287: &Apache::lonnet::del('environment',
14288: ['default_enrollment_start_date',
14289: 'default_enrollment_end_date',
14290: 'question.email',
14291: 'policy.email',
14292: 'comment.email',
14293: 'pch.users.denied',
1.725 raeburn 14294: 'plc.users.denied',
14295: 'hidefromcat',
1.1075.2.36 raeburn 14296: 'checkforpriv',
1.1075.2.59 raeburn 14297: 'categories',
14298: 'internal.uniquecode'],
1.638 www 14299: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 14300: if ($args->{'textbook'}) {
14301: $cenv{'internal.textbook'} = $args->{'textbook'};
14302: }
1.444 albertel 14303: }
1.566 albertel 14304:
1.444 albertel 14305: #
14306: # Set environment (will override cloned, if existing)
14307: #
14308: my @sections = ();
14309: my @xlists = ();
14310: if ($args->{'crstype'}) {
14311: $cenv{'type'}=$args->{'crstype'};
14312: }
14313: if ($args->{'crsid'}) {
14314: $cenv{'courseid'}=$args->{'crsid'};
14315: }
14316: if ($args->{'crscode'}) {
14317: $cenv{'internal.coursecode'}=$args->{'crscode'};
14318: }
14319: if ($args->{'crsquota'} ne '') {
14320: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14321: } else {
14322: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14323: }
14324: if ($args->{'ccuname'}) {
14325: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14326: ':'.$args->{'ccdomain'};
14327: } else {
14328: $cenv{'internal.courseowner'} = $args->{'curruser'};
14329: }
1.1075.2.31 raeburn 14330: if ($args->{'defaultcredits'}) {
14331: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14332: }
1.444 albertel 14333: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14334: if ($args->{'crssections'}) {
14335: $cenv{'internal.sectionnums'} = '';
14336: if ($args->{'crssections'} =~ m/,/) {
14337: @sections = split/,/,$args->{'crssections'};
14338: } else {
14339: $sections[0] = $args->{'crssections'};
14340: }
14341: if (@sections > 0) {
14342: foreach my $item (@sections) {
14343: my ($sec,$gp) = split/:/,$item;
14344: my $class = $args->{'crscode'}.$sec;
14345: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14346: $cenv{'internal.sectionnums'} .= $item.',';
14347: unless ($addcheck eq 'ok') {
14348: push @badclasses, $class;
14349: }
14350: }
14351: $cenv{'internal.sectionnums'} =~ s/,$//;
14352: }
14353: }
14354: # do not hide course coordinator from staff listing,
14355: # even if privileged
14356: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 14357: # add course coordinator's domain to domains to check for privileged users
14358: # if different to course domain
14359: if ($$crsudom ne $args->{'ccdomain'}) {
14360: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14361: }
1.444 albertel 14362: # add crosslistings
14363: if ($args->{'crsxlist'}) {
14364: $cenv{'internal.crosslistings'}='';
14365: if ($args->{'crsxlist'} =~ m/,/) {
14366: @xlists = split/,/,$args->{'crsxlist'};
14367: } else {
14368: $xlists[0] = $args->{'crsxlist'};
14369: }
14370: if (@xlists > 0) {
14371: foreach my $item (@xlists) {
14372: my ($xl,$gp) = split/:/,$item;
14373: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14374: $cenv{'internal.crosslistings'} .= $item.',';
14375: unless ($addcheck eq 'ok') {
14376: push @badclasses, $xl;
14377: }
14378: }
14379: $cenv{'internal.crosslistings'} =~ s/,$//;
14380: }
14381: }
14382: if ($args->{'autoadds'}) {
14383: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14384: }
14385: if ($args->{'autodrops'}) {
14386: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14387: }
14388: # check for notification of enrollment changes
14389: my @notified = ();
14390: if ($args->{'notify_owner'}) {
14391: if ($args->{'ccuname'} ne '') {
14392: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14393: }
14394: }
14395: if ($args->{'notify_dc'}) {
14396: if ($uname ne '') {
1.630 raeburn 14397: push(@notified,$uname.':'.$udom);
1.444 albertel 14398: }
14399: }
14400: if (@notified > 0) {
14401: my $notifylist;
14402: if (@notified > 1) {
14403: $notifylist = join(',',@notified);
14404: } else {
14405: $notifylist = $notified[0];
14406: }
14407: $cenv{'internal.notifylist'} = $notifylist;
14408: }
14409: if (@badclasses > 0) {
14410: my %lt=&Apache::lonlocal::texthash(
14411: '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',
14412: 'dnhr' => 'does not have rights to access enrollment in these classes',
14413: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14414: );
1.541 raeburn 14415: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14416: ' ('.$lt{'adby'}.')';
14417: if ($context eq 'auto') {
14418: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14419: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14420: foreach my $item (@badclasses) {
14421: if ($context eq 'auto') {
14422: $outcome .= " - $item\n";
14423: } else {
14424: $outcome .= "<li>$item</li>\n";
14425: }
14426: }
14427: if ($context eq 'auto') {
14428: $outcome .= $linefeed;
14429: } else {
1.566 albertel 14430: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14431: }
14432: }
1.444 albertel 14433: }
14434: if ($args->{'no_end_date'}) {
14435: $args->{'endaccess'} = 0;
14436: }
14437: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14438: $cenv{'internal.autoend'}=$args->{'enrollend'};
14439: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14440: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14441: if ($args->{'showphotos'}) {
14442: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14443: }
14444: $cenv{'internal.authtype'} = $args->{'authtype'};
14445: $cenv{'internal.autharg'} = $args->{'autharg'};
14446: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14447: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14448: 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');
14449: if ($context eq 'auto') {
14450: $outcome .= $krb_msg;
14451: } else {
1.566 albertel 14452: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14453: }
14454: $outcome .= $linefeed;
1.444 albertel 14455: }
14456: }
14457: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14458: if ($args->{'setpolicy'}) {
14459: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14460: }
14461: if ($args->{'setcontent'}) {
14462: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14463: }
14464: }
14465: if ($args->{'reshome'}) {
14466: $cenv{'reshome'}=$args->{'reshome'}.'/';
14467: $cenv{'reshome'}=~s/\/+$/\//;
14468: }
14469: #
14470: # course has keyed access
14471: #
14472: if ($args->{'setkeys'}) {
14473: $cenv{'keyaccess'}='yes';
14474: }
14475: # if specified, key authority is not course, but user
14476: # only active if keyaccess is yes
14477: if ($args->{'keyauth'}) {
1.487 albertel 14478: my ($user,$domain) = split(':',$args->{'keyauth'});
14479: $user = &LONCAPA::clean_username($user);
14480: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14481: if ($user ne '' && $domain ne '') {
1.487 albertel 14482: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14483: }
14484: }
14485:
1.1075.2.59 raeburn 14486: #
14487: # generate and store uniquecode (available to course requester), if course should have one.
14488: #
14489: if ($args->{'uniquecode'}) {
14490: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14491: if ($code) {
14492: $cenv{'internal.uniquecode'} = $code;
14493: my %crsinfo =
14494: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
14495: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
14496: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
14497: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
14498: }
14499: if (ref($coderef)) {
14500: $$coderef = $code;
14501: }
14502: }
14503: }
14504:
1.444 albertel 14505: if ($args->{'disresdis'}) {
14506: $cenv{'pch.roles.denied'}='st';
14507: }
14508: if ($args->{'disablechat'}) {
14509: $cenv{'plc.roles.denied'}='st';
14510: }
14511:
14512: # Record we've not yet viewed the Course Initialization Helper for this
14513: # course
14514: $cenv{'course.helper.not.run'} = 1;
14515: #
14516: # Use new Randomseed
14517: #
14518: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14519: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14520: #
14521: # The encryption code and receipt prefix for this course
14522: #
14523: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14524: $cenv{'internal.encpref'}=100+int(9*rand(99));
14525: #
14526: # By default, use standard grading
14527: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14528:
1.541 raeburn 14529: $outcome .= $linefeed.&mt('Setting environment').': '.
14530: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14531: #
14532: # Open all assignments
14533: #
14534: if ($args->{'openall'}) {
14535: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14536: my %storecontent = ($storeunder => time,
14537: $storeunder.'.type' => 'date_start');
14538:
14539: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14540: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14541: }
14542: #
14543: # Set first page
14544: #
14545: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14546: || ($cloneid)) {
1.445 albertel 14547: use LONCAPA::map;
1.444 albertel 14548: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14549:
14550: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14551: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14552:
1.444 albertel 14553: $outcome .= ($fatal?$errtext:'read ok').' - ';
14554: my $title; my $url;
14555: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14556: $title=&mt('Syllabus');
1.444 albertel 14557: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14558: } else {
1.963 raeburn 14559: $title=&mt('Table of Contents');
1.444 albertel 14560: $url='/adm/navmaps';
14561: }
1.445 albertel 14562:
14563: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14564: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14565:
14566: if ($errtext) { $fatal=2; }
1.541 raeburn 14567: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14568: }
1.566 albertel 14569:
14570: return (1,$outcome);
1.444 albertel 14571: }
14572:
1.1075.2.59 raeburn 14573: sub make_unique_code {
14574: my ($cdom,$cnum) = @_;
14575: # get lock on uniquecodes db
14576: my $lockhash = {
14577: $cnum."\0".'uniquecodes' => $env{'user.name'}.
14578: ':'.$env{'user.domain'},
14579: };
14580: my $tries = 0;
14581: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14582: my ($code,$error);
14583:
14584: while (($gotlock ne 'ok') && ($tries<3)) {
14585: $tries ++;
14586: sleep 1;
14587: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14588: }
14589: if ($gotlock eq 'ok') {
14590: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
14591: my $gotcode;
14592: my $attempts = 0;
14593: while ((!$gotcode) && ($attempts < 100)) {
14594: $code = &generate_code();
14595: if (!exists($currcodes{$code})) {
14596: $gotcode = 1;
14597: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
14598: $error = 'nostore';
14599: }
14600: }
14601: $attempts ++;
14602: }
14603: my @del_lock = ($cnum."\0".'uniquecodes');
14604: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
14605: } else {
14606: $error = 'nolock';
14607: }
14608: return ($code,$error);
14609: }
14610:
14611: sub generate_code {
14612: my $code;
14613: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
14614: for (my $i=0; $i<6; $i++) {
14615: my $lettnum = int (rand 2);
14616: my $item = '';
14617: if ($lettnum) {
14618: $item = $letts[int( rand(18) )];
14619: } else {
14620: $item = 1+int( rand(8) );
14621: }
14622: $code .= $item;
14623: }
14624: return $code;
14625: }
14626:
1.444 albertel 14627: ############################################################
14628: ############################################################
14629:
1.953 droeschl 14630: #SD
14631: # only Community and Course, or anything else?
1.378 raeburn 14632: sub course_type {
14633: my ($cid) = @_;
14634: if (!defined($cid)) {
14635: $cid = $env{'request.course.id'};
14636: }
1.404 albertel 14637: if (defined($env{'course.'.$cid.'.type'})) {
14638: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14639: } else {
14640: return 'Course';
1.377 raeburn 14641: }
14642: }
1.156 albertel 14643:
1.406 raeburn 14644: sub group_term {
14645: my $crstype = &course_type();
14646: my %names = (
14647: 'Course' => 'group',
1.865 raeburn 14648: 'Community' => 'group',
1.406 raeburn 14649: );
14650: return $names{$crstype};
14651: }
14652:
1.902 raeburn 14653: sub course_types {
1.1075.2.59 raeburn 14654: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 14655: my %typename = (
14656: official => 'Official course',
14657: unofficial => 'Unofficial course',
14658: community => 'Community',
1.1075.2.59 raeburn 14659: textbook => 'Textbook course',
1.902 raeburn 14660: );
14661: return (\@types,\%typename);
14662: }
14663:
1.156 albertel 14664: sub icon {
14665: my ($file)=@_;
1.505 albertel 14666: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14667: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14668: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14669: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14670: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14671: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14672: $curfext.".gif") {
14673: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14674: $curfext.".gif";
14675: }
14676: }
1.249 albertel 14677: return &lonhttpdurl($iconname);
1.154 albertel 14678: }
1.84 albertel 14679:
1.575 albertel 14680: sub lonhttpdurl {
1.692 www 14681: #
14682: # Had been used for "small fry" static images on separate port 8080.
14683: # Modify here if lightweight http functionality desired again.
14684: # Currently eliminated due to increasing firewall issues.
14685: #
1.575 albertel 14686: my ($url)=@_;
1.692 www 14687: return $url;
1.215 albertel 14688: }
14689:
1.213 albertel 14690: sub connection_aborted {
14691: my ($r)=@_;
14692: $r->print(" ");$r->rflush();
14693: my $c = $r->connection;
14694: return $c->aborted();
14695: }
14696:
1.221 foxr 14697: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14698: # strings as 'strings'.
14699: sub escape_single {
1.221 foxr 14700: my ($input) = @_;
1.223 albertel 14701: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14702: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14703: return $input;
14704: }
1.223 albertel 14705:
1.222 foxr 14706: # Same as escape_single, but escape's "'s This
14707: # can be used for "strings"
14708: sub escape_double {
14709: my ($input) = @_;
14710: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14711: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14712: return $input;
14713: }
1.223 albertel 14714:
1.222 foxr 14715: # Escapes the last element of a full URL.
14716: sub escape_url {
14717: my ($url) = @_;
1.238 raeburn 14718: my @urlslices = split(/\//, $url,-1);
1.369 www 14719: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 14720: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 14721: }
1.462 albertel 14722:
1.820 raeburn 14723: sub compare_arrays {
14724: my ($arrayref1,$arrayref2) = @_;
14725: my (@difference,%count);
14726: @difference = ();
14727: %count = ();
14728: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14729: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14730: foreach my $element (keys(%count)) {
14731: if ($count{$element} == 1) {
14732: push(@difference,$element);
14733: }
14734: }
14735: }
14736: return @difference;
14737: }
14738:
1.817 bisitz 14739: # -------------------------------------------------------- Initialize user login
1.462 albertel 14740: sub init_user_environment {
1.463 albertel 14741: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14742: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14743:
14744: my $public=($username eq 'public' && $domain eq 'public');
14745:
14746: # See if old ID present, if so, remove
14747:
1.1062 raeburn 14748: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14749: my $now=time;
14750:
14751: if ($public) {
14752: my $max_public=100;
14753: my $oldest;
14754: my $oldest_time=0;
14755: for(my $next=1;$next<=$max_public;$next++) {
14756: if (-e $lonids."/publicuser_$next.id") {
14757: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14758: if ($mtime<$oldest_time || !$oldest_time) {
14759: $oldest_time=$mtime;
14760: $oldest=$next;
14761: }
14762: } else {
14763: $cookie="publicuser_$next";
14764: last;
14765: }
14766: }
14767: if (!$cookie) { $cookie="publicuser_$oldest"; }
14768: } else {
1.463 albertel 14769: # if this isn't a robot, kill any existing non-robot sessions
14770: if (!$args->{'robot'}) {
14771: opendir(DIR,$lonids);
14772: while ($filename=readdir(DIR)) {
14773: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14774: unlink($lonids.'/'.$filename);
14775: }
1.462 albertel 14776: }
1.463 albertel 14777: closedir(DIR);
1.1075.2.84 raeburn 14778: # If there is a undeleted lockfile for the user's paste buffer remove it.
14779: my $namespace = 'nohist_courseeditor';
14780: my $lockingkey = 'paste'."\0".'locked_num';
14781: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
14782: $domain,$username);
14783: if (exists($lockhash{$lockingkey})) {
14784: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
14785: unless ($delresult eq 'ok') {
14786: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
14787: }
14788: }
1.462 albertel 14789: }
14790: # Give them a new cookie
1.463 albertel 14791: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14792: : $now.$$.int(rand(10000)));
1.463 albertel 14793: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14794:
14795: # Initialize roles
14796:
1.1062 raeburn 14797: ($userroles,$firstaccenv,$timerintenv) =
14798: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14799: }
14800: # ------------------------------------ Check browser type and MathML capability
14801:
1.1075.2.77 raeburn 14802: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
14803: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 14804:
14805: # ------------------------------------------------------------- Get environment
14806:
14807: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14808: my ($tmp) = keys(%userenv);
14809: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14810: } else {
14811: undef(%userenv);
14812: }
14813: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14814: $form->{'interface'}=$userenv{'interface'};
14815: }
14816: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14817:
14818: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14819: foreach my $option ('interface','localpath','localres') {
14820: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14821: }
14822: # --------------------------------------------------------- Write first profile
14823:
14824: {
14825: my %initial_env =
14826: ("user.name" => $username,
14827: "user.domain" => $domain,
14828: "user.home" => $authhost,
14829: "browser.type" => $clientbrowser,
14830: "browser.version" => $clientversion,
14831: "browser.mathml" => $clientmathml,
14832: "browser.unicode" => $clientunicode,
14833: "browser.os" => $clientos,
1.1075.2.42 raeburn 14834: "browser.mobile" => $clientmobile,
14835: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 14836: "browser.osversion" => $clientosversion,
1.462 albertel 14837: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14838: "request.course.fn" => '',
14839: "request.course.uri" => '',
14840: "request.course.sec" => '',
14841: "request.role" => 'cm',
14842: "request.role.adv" => $env{'user.adv'},
14843: "request.host" => $ENV{'REMOTE_ADDR'},);
14844:
14845: if ($form->{'localpath'}) {
14846: $initial_env{"browser.localpath"} = $form->{'localpath'};
14847: $initial_env{"browser.localres"} = $form->{'localres'};
14848: }
14849:
14850: if ($form->{'interface'}) {
14851: $form->{'interface'}=~s/\W//gs;
14852: $initial_env{"browser.interface"} = $form->{'interface'};
14853: $env{'browser.interface'}=$form->{'interface'};
14854: }
14855:
1.1075.2.54 raeburn 14856: if ($form->{'iptoken'}) {
14857: my $lonhost = $r->dir_config('lonHostID');
14858: $initial_env{"user.noloadbalance"} = $lonhost;
14859: $env{'user.noloadbalance'} = $lonhost;
14860: }
14861:
1.981 raeburn 14862: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14863: my %domdef;
14864: unless ($domain eq 'public') {
14865: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14866: }
1.980 raeburn 14867:
1.1075.2.7 raeburn 14868: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14869: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14870: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14871: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14872: }
14873:
1.1075.2.59 raeburn 14874: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 14875: $userenv{'canrequest.'.$crstype} =
14876: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14877: 'reload','requestcourses',
14878: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14879: }
14880:
1.1075.2.14 raeburn 14881: $userenv{'canrequest.author'} =
14882: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14883: 'reload','requestauthor',
14884: \%userenv,\%domdef,\%is_adv);
14885: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14886: $domain,$username);
14887: my $reqstatus = $reqauthor{'author_status'};
14888: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14889: if (ref($reqauthor{'author'}) eq 'HASH') {
14890: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14891: $reqauthor{'author'}{'timestamp'};
14892: }
14893: }
14894:
1.462 albertel 14895: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14896:
1.462 albertel 14897: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14898: &GDBM_WRCREAT(),0640)) {
14899: &_add_to_env(\%disk_env,\%initial_env);
14900: &_add_to_env(\%disk_env,\%userenv,'environment.');
14901: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14902: if (ref($firstaccenv) eq 'HASH') {
14903: &_add_to_env(\%disk_env,$firstaccenv);
14904: }
14905: if (ref($timerintenv) eq 'HASH') {
14906: &_add_to_env(\%disk_env,$timerintenv);
14907: }
1.463 albertel 14908: if (ref($args->{'extra_env'})) {
14909: &_add_to_env(\%disk_env,$args->{'extra_env'});
14910: }
1.462 albertel 14911: untie(%disk_env);
14912: } else {
1.705 tempelho 14913: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14914: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14915: return 'error: '.$!;
14916: }
14917: }
14918: $env{'request.role'}='cm';
14919: $env{'request.role.adv'}=$env{'user.adv'};
14920: $env{'browser.type'}=$clientbrowser;
14921:
14922: return $cookie;
14923:
14924: }
14925:
14926: sub _add_to_env {
14927: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14928: if (ref($env_data) eq 'HASH') {
14929: while (my ($key,$value) = each(%$env_data)) {
14930: $idf->{$prefix.$key} = $value;
14931: $env{$prefix.$key} = $value;
14932: }
1.462 albertel 14933: }
14934: }
14935:
1.685 tempelho 14936: # --- Get the symbolic name of a problem and the url
14937: sub get_symb {
14938: my ($request,$silent) = @_;
1.726 raeburn 14939: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14940: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14941: if ($symb eq '') {
14942: if (!$silent) {
1.1071 raeburn 14943: if (ref($request)) {
14944: $request->print("Unable to handle ambiguous references:$url:.");
14945: }
1.685 tempelho 14946: return ();
14947: }
14948: }
14949: &Apache::lonenc::check_decrypt(\$symb);
14950: return ($symb);
14951: }
14952:
14953: # --------------------------------------------------------------Get annotation
14954:
14955: sub get_annotation {
14956: my ($symb,$enc) = @_;
14957:
14958: my $key = $symb;
14959: if (!$enc) {
14960: $key =
14961: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14962: }
14963: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14964: return $annotation{$key};
14965: }
14966:
14967: sub clean_symb {
1.731 raeburn 14968: my ($symb,$delete_enc) = @_;
1.685 tempelho 14969:
14970: &Apache::lonenc::check_decrypt(\$symb);
14971: my $enc = $env{'request.enc'};
1.731 raeburn 14972: if ($delete_enc) {
1.730 raeburn 14973: delete($env{'request.enc'});
14974: }
1.685 tempelho 14975:
14976: return ($symb,$enc);
14977: }
1.462 albertel 14978:
1.1075.2.69 raeburn 14979: ############################################################
14980: ############################################################
14981:
14982: =pod
14983:
14984: =head1 Routines for building display used to search for courses
14985:
14986:
14987: =over 4
14988:
14989: =item * &build_filters()
14990:
14991: Create markup for a table used to set filters to use when selecting
14992: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
14993: and quotacheck.pl
14994:
14995:
14996: Inputs:
14997:
14998: filterlist - anonymous array of fields to include as potential filters
14999:
15000: crstype - course type
15001:
15002: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15003: to pop-open a course selector (will contain "extra element").
15004:
15005: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15006:
15007: filter - anonymous hash of criteria and their values
15008:
15009: action - form action
15010:
15011: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15012:
15013: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
15014:
15015: cloneruname - username of owner of new course who wants to clone
15016:
15017: clonerudom - domain of owner of new course who wants to clone
15018:
15019: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15020:
15021: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15022:
15023: codedom - domain
15024:
15025: formname - value of form element named "form".
15026:
15027: fixeddom - domain, if fixed.
15028:
15029: prevphase - value to assign to form element named "phase" when going back to the previous screen
15030:
15031: cnameelement - name of form element in form on opener page which will receive title of selected course
15032:
15033: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15034:
15035: cdomelement - name of form element in form on opener page which will receive domain of selected course
15036:
15037: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15038:
15039: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
15040:
15041: clonewarning - warning message about missing information for intended course owner when DC creates a course
15042:
15043:
15044: Returns: $output - HTML for display of search criteria, and hidden form elements.
15045:
15046:
15047: Side Effects: None
15048:
15049: =cut
15050:
15051: # ---------------------------------------------- search for courses based on last activity etc.
15052:
15053: sub build_filters {
15054: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
15055: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
15056: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
15057: $cnameelement,$cnumelement,$cdomelement,$setroles,
15058: $clonetext,$clonewarning) = @_;
15059: my ($list,$jscript);
15060: my $onchange = 'javascript:updateFilters(this)';
15061: my ($domainselectform,$sincefilterform,$createdfilterform,
15062: $ownerdomselectform,$persondomselectform,$instcodeform,
15063: $typeselectform,$instcodetitle);
15064: if ($formname eq '') {
15065: $formname = $caller;
15066: }
15067: foreach my $item (@{$filterlist}) {
15068: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
15069: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
15070: if ($item eq 'domainfilter') {
15071: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
15072: } elsif ($item eq 'coursefilter') {
15073: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
15074: } elsif ($item eq 'ownerfilter') {
15075: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15076: } elsif ($item eq 'ownerdomfilter') {
15077: $filter->{'ownerdomfilter'} =
15078: &LONCAPA::clean_domain($filter->{$item});
15079: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
15080: 'ownerdomfilter',1);
15081: } elsif ($item eq 'personfilter') {
15082: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15083: } elsif ($item eq 'persondomfilter') {
15084: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
15085: 'persondomfilter',1);
15086: } else {
15087: $filter->{$item} =~ s/\W//g;
15088: }
15089: if (!$filter->{$item}) {
15090: $filter->{$item} = '';
15091: }
15092: }
15093: if ($item eq 'domainfilter') {
15094: my $allow_blank = 1;
15095: if ($formname eq 'portform') {
15096: $allow_blank=0;
15097: } elsif ($formname eq 'studentform') {
15098: $allow_blank=0;
15099: }
15100: if ($fixeddom) {
15101: $domainselectform = '<input type="hidden" name="domainfilter"'.
15102: ' value="'.$codedom.'" />'.
15103: &Apache::lonnet::domain($codedom,'description');
15104: } else {
15105: $domainselectform = &select_dom_form($filter->{$item},
15106: 'domainfilter',
15107: $allow_blank,'',$onchange);
15108: }
15109: } else {
15110: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
15111: }
15112: }
15113:
15114: # last course activity filter and selection
15115: $sincefilterform = &timebased_select_form('sincefilter',$filter);
15116:
15117: # course created filter and selection
15118: if (exists($filter->{'createdfilter'})) {
15119: $createdfilterform = &timebased_select_form('createdfilter',$filter);
15120: }
15121:
15122: my %lt = &Apache::lonlocal::texthash(
15123: 'cac' => "$crstype Activity",
15124: 'ccr' => "$crstype Created",
15125: 'cde' => "$crstype Title",
15126: 'cdo' => "$crstype Domain",
15127: 'ins' => 'Institutional Code',
15128: 'inc' => 'Institutional Categorization',
15129: 'cow' => "$crstype Owner/Co-owner",
15130: 'cop' => "$crstype Personnel Includes",
15131: 'cog' => 'Type',
15132: );
15133:
15134: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15135: my $typeval = 'Course';
15136: if ($crstype eq 'Community') {
15137: $typeval = 'Community';
15138: }
15139: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
15140: } else {
15141: $typeselectform = '<select name="type" size="1"';
15142: if ($onchange) {
15143: $typeselectform .= ' onchange="'.$onchange.'"';
15144: }
15145: $typeselectform .= '>'."\n";
15146: foreach my $posstype ('Course','Community') {
15147: $typeselectform.='<option value="'.$posstype.'"'.
15148: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
15149: }
15150: $typeselectform.="</select>";
15151: }
15152:
15153: my ($cloneableonlyform,$cloneabletitle);
15154: if (exists($filter->{'cloneableonly'})) {
15155: my $cloneableon = '';
15156: my $cloneableoff = ' checked="checked"';
15157: if ($filter->{'cloneableonly'}) {
15158: $cloneableon = $cloneableoff;
15159: $cloneableoff = '';
15160: }
15161: $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>';
15162: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 15163: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 15164: } else {
15165: $cloneabletitle = &mt('Cloneable by you');
15166: }
15167: }
15168: my $officialjs;
15169: if ($crstype eq 'Course') {
15170: if (exists($filter->{'instcodefilter'})) {
15171: # if (($fixeddom) || ($formname eq 'requestcrs') ||
15172: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
15173: if ($codedom) {
15174: $officialjs = 1;
15175: ($instcodeform,$jscript,$$numtitlesref) =
15176: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
15177: $officialjs,$codetitlesref);
15178: if ($jscript) {
15179: $jscript = '<script type="text/javascript">'."\n".
15180: '// <![CDATA['."\n".
15181: $jscript."\n".
15182: '// ]]>'."\n".
15183: '</script>'."\n";
15184: }
15185: }
15186: if ($instcodeform eq '') {
15187: $instcodeform =
15188: '<input type="text" name="instcodefilter" size="10" value="'.
15189: $list->{'instcodefilter'}.'" />';
15190: $instcodetitle = $lt{'ins'};
15191: } else {
15192: $instcodetitle = $lt{'inc'};
15193: }
15194: if ($fixeddom) {
15195: $instcodetitle .= '<br />('.$codedom.')';
15196: }
15197: }
15198: }
15199: my $output = qq|
15200: <form method="post" name="filterpicker" action="$action">
15201: <input type="hidden" name="form" value="$formname" />
15202: |;
15203: if ($formname eq 'modifycourse') {
15204: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
15205: '<input type="hidden" name="prevphase" value="'.
15206: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 15207: } elsif ($formname eq 'quotacheck') {
15208: $output .= qq|
15209: <input type="hidden" name="sortby" value="" />
15210: <input type="hidden" name="sortorder" value="" />
15211: |;
15212: } else {
1.1075.2.69 raeburn 15213: my $name_input;
15214: if ($cnameelement ne '') {
15215: $name_input = '<input type="hidden" name="cnameelement" value="'.
15216: $cnameelement.'" />';
15217: }
15218: $output .= qq|
15219: <input type="hidden" name="cnumelement" value="$cnumelement" />
15220: <input type="hidden" name="cdomelement" value="$cdomelement" />
15221: $name_input
15222: $roleelement
15223: $multelement
15224: $typeelement
15225: |;
15226: if ($formname eq 'portform') {
15227: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
15228: }
15229: }
15230: if ($fixeddom) {
15231: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
15232: }
15233: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
15234: if ($sincefilterform) {
15235: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
15236: .$sincefilterform
15237: .&Apache::lonhtmlcommon::row_closure();
15238: }
15239: if ($createdfilterform) {
15240: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
15241: .$createdfilterform
15242: .&Apache::lonhtmlcommon::row_closure();
15243: }
15244: if ($domainselectform) {
15245: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
15246: .$domainselectform
15247: .&Apache::lonhtmlcommon::row_closure();
15248: }
15249: if ($typeselectform) {
15250: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15251: $output .= $typeselectform;
15252: } else {
15253: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
15254: .$typeselectform
15255: .&Apache::lonhtmlcommon::row_closure();
15256: }
15257: }
15258: if ($instcodeform) {
15259: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
15260: .$instcodeform
15261: .&Apache::lonhtmlcommon::row_closure();
15262: }
15263: if (exists($filter->{'ownerfilter'})) {
15264: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
15265: '<table><tr><td>'.&mt('Username').'<br />'.
15266: '<input type="text" name="ownerfilter" size="20" value="'.
15267: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15268: $ownerdomselectform.'</td></tr></table>'.
15269: &Apache::lonhtmlcommon::row_closure();
15270: }
15271: if (exists($filter->{'personfilter'})) {
15272: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
15273: '<table><tr><td>'.&mt('Username').'<br />'.
15274: '<input type="text" name="personfilter" size="20" value="'.
15275: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15276: $persondomselectform.'</td></tr></table>'.
15277: &Apache::lonhtmlcommon::row_closure();
15278: }
15279: if (exists($filter->{'coursefilter'})) {
15280: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15281: .'<input type="text" name="coursefilter" size="25" value="'
15282: .$list->{'coursefilter'}.'" />'
15283: .&Apache::lonhtmlcommon::row_closure();
15284: }
15285: if ($cloneableonlyform) {
15286: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15287: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15288: }
15289: if (exists($filter->{'descriptfilter'})) {
15290: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15291: .'<input type="text" name="descriptfilter" size="40" value="'
15292: .$list->{'descriptfilter'}.'" />'
15293: .&Apache::lonhtmlcommon::row_closure(1);
15294: }
15295: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15296: '<input type="hidden" name="updater" value="" />'."\n".
15297: '<input type="submit" name="gosearch" value="'.
15298: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15299: return $jscript.$clonewarning.$output;
15300: }
15301:
15302: =pod
15303:
15304: =item * &timebased_select_form()
15305:
15306: Create markup for a dropdown list used to select a time-based
15307: filter e.g., Course Activity, Course Created, when searching for courses
15308: or communities
15309:
15310: Inputs:
15311:
15312: item - name of form element (sincefilter or createdfilter)
15313:
15314: filter - anonymous hash of criteria and their values
15315:
15316: Returns: HTML for a select box contained a blank, then six time selections,
15317: with value set in incoming form variables currently selected.
15318:
15319: Side Effects: None
15320:
15321: =cut
15322:
15323: sub timebased_select_form {
15324: my ($item,$filter) = @_;
15325: if (ref($filter) eq 'HASH') {
15326: $filter->{$item} =~ s/[^\d-]//g;
15327: if (!$filter->{$item}) { $filter->{$item}=-1; }
15328: return &select_form(
15329: $filter->{$item},
15330: $item,
15331: { '-1' => '',
15332: '86400' => &mt('today'),
15333: '604800' => &mt('last week'),
15334: '2592000' => &mt('last month'),
15335: '7776000' => &mt('last three months'),
15336: '15552000' => &mt('last six months'),
15337: '31104000' => &mt('last year'),
15338: 'select_form_order' =>
15339: ['-1','86400','604800','2592000','7776000',
15340: '15552000','31104000']});
15341: }
15342: }
15343:
15344: =pod
15345:
15346: =item * &js_changer()
15347:
15348: Create script tag containing Javascript used to submit course search form
15349: when course type or domain is changed, and also to hide 'Searching ...' on
15350: page load completion for page showing search result.
15351:
15352: Inputs: None
15353:
15354: Returns: markup containing updateFilters() and hideSearching() javascript functions.
15355:
15356: Side Effects: None
15357:
15358: =cut
15359:
15360: sub js_changer {
15361: return <<ENDJS;
15362: <script type="text/javascript">
15363: // <![CDATA[
15364: function updateFilters(caller) {
15365: if (typeof(caller) != "undefined") {
15366: document.filterpicker.updater.value = caller.name;
15367: }
15368: document.filterpicker.submit();
15369: }
15370:
15371: function hideSearching() {
15372: if (document.getElementById('searching')) {
15373: document.getElementById('searching').style.display = 'none';
15374: }
15375: return;
15376: }
15377:
15378: // ]]>
15379: </script>
15380:
15381: ENDJS
15382: }
15383:
15384: =pod
15385:
15386: =item * &search_courses()
15387:
15388: Process selected filters form course search form and pass to lonnet::courseiddump
15389: to retrieve a hash for which keys are courseIDs which match the selected filters.
15390:
15391: Inputs:
15392:
15393: dom - domain being searched
15394:
15395: type - course type ('Course' or 'Community' or '.' if any).
15396:
15397: filter - anonymous hash of criteria and their values
15398:
15399: numtitles - for institutional codes - number of categories
15400:
15401: cloneruname - optional username of new course owner
15402:
15403: clonerudom - optional domain of new course owner
15404:
1.1075.2.95 raeburn 15405: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 15406: (used when DC is using course creation form)
15407:
15408: codetitles - reference to array of titles of components in institutional codes (official courses).
15409:
1.1075.2.95 raeburn 15410: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
15411: (and so can clone automatically)
15412:
15413: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
15414:
15415: reqinstcode - institutional code of new course, where search_courses is used to identify potential
15416: courses to clone
1.1075.2.69 raeburn 15417:
15418: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
15419:
15420:
15421: Side Effects: None
15422:
15423: =cut
15424:
15425:
15426: sub search_courses {
1.1075.2.95 raeburn 15427: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
15428: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 15429: my (%courses,%showcourses,$cloner);
15430: if (($filter->{'ownerfilter'} ne '') ||
15431: ($filter->{'ownerdomfilter'} ne '')) {
15432: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
15433: $filter->{'ownerdomfilter'};
15434: }
15435: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
15436: if (!$filter->{$item}) {
15437: $filter->{$item}='.';
15438: }
15439: }
15440: my $now = time;
15441: my $timefilter =
15442: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
15443: my ($createdbefore,$createdafter);
15444: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
15445: $createdbefore = $now;
15446: $createdafter = $now-$filter->{'createdfilter'};
15447: }
15448: my ($instcodefilter,$regexpok);
15449: if ($numtitles) {
15450: if ($env{'form.official'} eq 'on') {
15451: $instcodefilter =
15452: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15453: $regexpok = 1;
15454: } elsif ($env{'form.official'} eq 'off') {
15455: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15456: unless ($instcodefilter eq '') {
15457: $regexpok = -1;
15458: }
15459: }
15460: } else {
15461: $instcodefilter = $filter->{'instcodefilter'};
15462: }
15463: if ($instcodefilter eq '') { $instcodefilter = '.'; }
15464: if ($type eq '') { $type = '.'; }
15465:
15466: if (($clonerudom ne '') && ($cloneruname ne '')) {
15467: $cloner = $cloneruname.':'.$clonerudom;
15468: }
15469: %courses = &Apache::lonnet::courseiddump($dom,
15470: $filter->{'descriptfilter'},
15471: $timefilter,
15472: $instcodefilter,
15473: $filter->{'combownerfilter'},
15474: $filter->{'coursefilter'},
15475: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 15476: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 15477: $filter->{'cloneableonly'},
15478: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 15479: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 15480: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
15481: my $ccrole;
15482: if ($type eq 'Community') {
15483: $ccrole = 'co';
15484: } else {
15485: $ccrole = 'cc';
15486: }
15487: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
15488: $filter->{'persondomfilter'},
15489: 'userroles',undef,
15490: [$ccrole,'in','ad','ep','ta','cr'],
15491: $dom);
15492: foreach my $role (keys(%rolehash)) {
15493: my ($cnum,$cdom,$courserole) = split(':',$role);
15494: my $cid = $cdom.'_'.$cnum;
15495: if (exists($courses{$cid})) {
15496: if (ref($courses{$cid}) eq 'HASH') {
15497: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
15498: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
15499: push (@{$courses{$cid}{roles}},$courserole);
15500: }
15501: } else {
15502: $courses{$cid}{roles} = [$courserole];
15503: }
15504: $showcourses{$cid} = $courses{$cid};
15505: }
15506: }
15507: }
15508: %courses = %showcourses;
15509: }
15510: return %courses;
15511: }
15512:
15513: =pod
15514:
15515: =back
15516:
1.1075.2.88 raeburn 15517: =head1 Routines for version requirements for current course.
15518:
15519: =over 4
15520:
15521: =item * &check_release_required()
15522:
15523: Compares required LON-CAPA version with version on server, and
15524: if required version is newer looks for a server with the required version.
15525:
15526: Looks first at servers in user's owen domain; if none suitable, looks at
15527: servers in course's domain are permitted to host sessions for user's domain.
15528:
15529: Inputs:
15530:
15531: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
15532:
15533: $courseid - Course ID of current course
15534:
15535: $rolecode - User's current role in course (for switchserver query string).
15536:
15537: $required - LON-CAPA version needed by course (format: Major.Minor).
15538:
15539:
15540: Returns:
15541:
15542: $switchserver - query string tp append to /adm/switchserver call (if
15543: current server's LON-CAPA version is too old.
15544:
15545: $warning - Message is displayed if no suitable server could be found.
15546:
15547: =cut
15548:
15549: sub check_release_required {
15550: my ($loncaparev,$courseid,$rolecode,$required) = @_;
15551: my ($switchserver,$warning);
15552: if ($required ne '') {
15553: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
15554: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
15555: if ($reqdmajor ne '' && $reqdminor ne '') {
15556: my $otherserver;
15557: if (($major eq '' && $minor eq '') ||
15558: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
15559: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
15560: my $switchlcrev =
15561: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
15562: $userdomserver);
15563: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
15564: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
15565: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
15566: my $cdom = $env{'course.'.$courseid.'.domain'};
15567: if ($cdom ne $env{'user.domain'}) {
15568: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
15569: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
15570: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
15571: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
15572: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
15573: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
15574: my $canhost =
15575: &Apache::lonnet::can_host_session($env{'user.domain'},
15576: $coursedomserver,
15577: $remoterev,
15578: $udomdefaults{'remotesessions'},
15579: $defdomdefaults{'hostedsessions'});
15580:
15581: if ($canhost) {
15582: $otherserver = $coursedomserver;
15583: } else {
15584: $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).'<br />'. &mt("No suitable server could be found amongst servers in either your own domain or in the course's domain.");
15585: }
15586: } else {
15587: $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).'<br />'.&mt("No suitable server could be found amongst servers in your own domain (which is also the course's domain).");
15588: }
15589: } else {
15590: $otherserver = $userdomserver;
15591: }
15592: }
15593: if ($otherserver ne '') {
15594: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
15595: }
15596: }
15597: }
15598: return ($switchserver,$warning);
15599: }
15600:
15601: =pod
15602:
15603: =item * &check_release_result()
15604:
15605: Inputs:
15606:
15607: $switchwarning - Warning message if no suitable server found to host session.
15608:
15609: $switchserver - query string to append to /adm/switchserver containing lonHostID
15610: and current role.
15611:
15612: Returns: HTML to display with information about requirement to switch server.
15613: Either displaying warning with link to Roles/Courses screen or
15614: display link to switchserver.
15615:
1.1075.2.69 raeburn 15616: =cut
15617:
1.1075.2.88 raeburn 15618: sub check_release_result {
15619: my ($switchwarning,$switchserver) = @_;
15620: my $output = &start_page('Selected course unavailable on this server').
15621: '<p class="LC_warning">';
15622: if ($switchwarning) {
15623: $output .= $switchwarning.'<br /><a href="/adm/roles">';
15624: if (&show_course()) {
15625: $output .= &mt('Display courses');
15626: } else {
15627: $output .= &mt('Display roles');
15628: }
15629: $output .= '</a>';
15630: } elsif ($switchserver) {
15631: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
15632: '<br />'.
15633: '<a href="/adm/switchserver?'.$switchserver.'">'.
15634: &mt('Switch Server').
15635: '</a>';
15636: }
15637: $output .= '</p>'.&end_page();
15638: return $output;
15639: }
15640:
15641: =pod
15642:
15643: =item * &needs_coursereinit()
15644:
15645: Determine if course contents stored for user's session needs to be
15646: refreshed, because content has changed since "Big Hash" last tied.
15647:
15648: Check for change is made if time last checked is more than 10 minutes ago
15649: (by default).
15650:
15651: Inputs:
15652:
15653: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
15654:
15655: $interval (optional) - Time which may elapse (in s) between last check for content
15656: change in current course. (default: 600 s).
15657:
15658: Returns: an array; first element is:
15659:
15660: =over 4
15661:
15662: 'switch' - if content updates mean user's session
15663: needs to be switched to a server running a newer LON-CAPA version
15664:
15665: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
15666: on current server hosting user's session
15667:
15668: '' - if no action required.
15669:
15670: =back
15671:
15672: If first item element is 'switch':
15673:
15674: second item is $switchwarning - Warning message if no suitable server found to host session.
15675:
15676: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
15677: and current role.
15678:
15679: otherwise: no other elements returned.
15680:
15681: =back
15682:
15683: =cut
15684:
15685: sub needs_coursereinit {
15686: my ($loncaparev,$interval) = @_;
15687: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
15688: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
15689: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
15690: my $now = time;
15691: if ($interval eq '') {
15692: $interval = 600;
15693: }
15694: if (($now-$env{'request.course.timechecked'})>$interval) {
15695: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
15696: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
15697: if ($lastchange > $env{'request.course.tied'}) {
15698: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15699: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
15700: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
15701: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
15702: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
15703: $curr_reqd_hash{'internal.releaserequired'}});
15704: my ($switchserver,$switchwarning) =
15705: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
15706: $curr_reqd_hash{'internal.releaserequired'});
15707: if ($switchwarning ne '' || $switchserver ne '') {
15708: return ('switch',$switchwarning,$switchserver);
15709: }
15710: }
15711: }
15712: return ('update');
15713: }
15714: }
15715: return ();
15716: }
1.1075.2.69 raeburn 15717:
1.1075.2.11 raeburn 15718: sub update_content_constraints {
15719: my ($cdom,$cnum,$chome,$cid) = @_;
15720: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15721: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
15722: my %checkresponsetypes;
15723: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
15724: my ($item,$name,$value) = split(/:/,$key);
15725: if ($item eq 'resourcetag') {
15726: if ($name eq 'responsetype') {
15727: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
15728: }
15729: }
15730: }
15731: my $navmap = Apache::lonnavmaps::navmap->new();
15732: if (defined($navmap)) {
15733: my %allresponses;
15734: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
15735: my %responses = $res->responseTypes();
15736: foreach my $key (keys(%responses)) {
15737: next unless(exists($checkresponsetypes{$key}));
15738: $allresponses{$key} += $responses{$key};
15739: }
15740: }
15741: foreach my $key (keys(%allresponses)) {
15742: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
15743: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
15744: ($reqdmajor,$reqdminor) = ($major,$minor);
15745: }
15746: }
15747: undef($navmap);
15748: }
15749: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
15750: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
15751: }
15752: return;
15753: }
15754:
1.1075.2.27 raeburn 15755: sub allmaps_incourse {
15756: my ($cdom,$cnum,$chome,$cid) = @_;
15757: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
15758: $cid = $env{'request.course.id'};
15759: $cdom = $env{'course.'.$cid.'.domain'};
15760: $cnum = $env{'course.'.$cid.'.num'};
15761: $chome = $env{'course.'.$cid.'.home'};
15762: }
15763: my %allmaps = ();
15764: my $lastchange =
15765: &Apache::lonnet::get_coursechange($cdom,$cnum);
15766: if ($lastchange > $env{'request.course.tied'}) {
15767: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
15768: unless ($ferr) {
15769: &update_content_constraints($cdom,$cnum,$chome,$cid);
15770: }
15771: }
15772: my $navmap = Apache::lonnavmaps::navmap->new();
15773: if (defined($navmap)) {
15774: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
15775: $allmaps{$res->src()} = 1;
15776: }
15777: }
15778: return \%allmaps;
15779: }
15780:
1.1075.2.11 raeburn 15781: sub parse_supplemental_title {
15782: my ($title) = @_;
15783:
15784: my ($foldertitle,$renametitle);
15785: if ($title =~ /&&&/) {
15786: $title = &HTML::Entites::decode($title);
15787: }
15788: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
15789: $renametitle=$4;
15790: my ($time,$uname,$udom) = ($1,$2,$3);
15791: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
15792: my $name = &plainname($uname,$udom);
15793: $name = &HTML::Entities::encode($name,'"<>&\'');
15794: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
15795: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
15796: $name.': <br />'.$foldertitle;
15797: }
15798: if (wantarray) {
15799: return ($title,$foldertitle,$renametitle);
15800: }
15801: return $title;
15802: }
15803:
1.1075.2.43 raeburn 15804: sub recurse_supplemental {
15805: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
15806: if ($suppmap) {
15807: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
15808: if ($fatal) {
15809: $errors ++;
15810: } else {
15811: if ($#LONCAPA::map::resources > 0) {
15812: foreach my $res (@LONCAPA::map::resources) {
15813: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
15814: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 15815: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
15816: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 15817: } else {
15818: $numfiles ++;
15819: }
15820: }
15821: }
15822: }
15823: }
15824: }
15825: return ($numfiles,$errors);
15826: }
15827:
1.1075.2.18 raeburn 15828: sub symb_to_docspath {
15829: my ($symb) = @_;
15830: return unless ($symb);
15831: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
15832: if ($resurl=~/\.(sequence|page)$/) {
15833: $mapurl=$resurl;
15834: } elsif ($resurl eq 'adm/navmaps') {
15835: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
15836: }
15837: my $mapresobj;
15838: my $navmap = Apache::lonnavmaps::navmap->new();
15839: if (ref($navmap)) {
15840: $mapresobj = $navmap->getResourceByUrl($mapurl);
15841: }
15842: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
15843: my $type=$2;
15844: my $path;
15845: if (ref($mapresobj)) {
15846: my $pcslist = $mapresobj->map_hierarchy();
15847: if ($pcslist ne '') {
15848: foreach my $pc (split(/,/,$pcslist)) {
15849: next if ($pc <= 1);
15850: my $res = $navmap->getByMapPc($pc);
15851: if (ref($res)) {
15852: my $thisurl = $res->src();
15853: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
15854: my $thistitle = $res->title();
15855: $path .= '&'.
15856: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 15857: &escape($thistitle).
1.1075.2.18 raeburn 15858: ':'.$res->randompick().
15859: ':'.$res->randomout().
15860: ':'.$res->encrypted().
15861: ':'.$res->randomorder().
15862: ':'.$res->is_page();
15863: }
15864: }
15865: }
15866: $path =~ s/^\&//;
15867: my $maptitle = $mapresobj->title();
15868: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 15869: $maptitle = 'Main Content';
1.1075.2.18 raeburn 15870: }
15871: $path .= (($path ne '')? '&' : '').
15872: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 15873: &escape($maptitle).
1.1075.2.18 raeburn 15874: ':'.$mapresobj->randompick().
15875: ':'.$mapresobj->randomout().
15876: ':'.$mapresobj->encrypted().
15877: ':'.$mapresobj->randomorder().
15878: ':'.$mapresobj->is_page();
15879: } else {
15880: my $maptitle = &Apache::lonnet::gettitle($mapurl);
15881: my $ispage = (($type eq 'page')? 1 : '');
15882: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 15883: $maptitle = 'Main Content';
1.1075.2.18 raeburn 15884: }
15885: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 15886: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 15887: }
15888: unless ($mapurl eq 'default') {
15889: $path = 'default&'.
1.1075.2.46 raeburn 15890: &escape('Main Content').
1.1075.2.18 raeburn 15891: ':::::&'.$path;
15892: }
15893: return $path;
15894: }
15895:
1.1075.2.14 raeburn 15896: sub captcha_display {
15897: my ($context,$lonhost) = @_;
15898: my ($output,$error);
15899: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
15900: if ($captcha eq 'original') {
15901: $output = &create_captcha();
15902: unless ($output) {
15903: $error = 'captcha';
15904: }
15905: } elsif ($captcha eq 'recaptcha') {
15906: $output = &create_recaptcha($pubkey);
15907: unless ($output) {
15908: $error = 'recaptcha';
15909: }
15910: }
1.1075.2.66 raeburn 15911: return ($output,$error,$captcha);
1.1075.2.14 raeburn 15912: }
15913:
15914: sub captcha_response {
15915: my ($context,$lonhost) = @_;
15916: my ($captcha_chk,$captcha_error);
15917: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
15918: if ($captcha eq 'original') {
15919: ($captcha_chk,$captcha_error) = &check_captcha();
15920: } elsif ($captcha eq 'recaptcha') {
15921: $captcha_chk = &check_recaptcha($privkey);
15922: } else {
15923: $captcha_chk = 1;
15924: }
15925: return ($captcha_chk,$captcha_error);
15926: }
15927:
15928: sub get_captcha_config {
15929: my ($context,$lonhost) = @_;
15930: my ($captcha,$pubkey,$privkey,$hashtocheck);
15931: my $hostname = &Apache::lonnet::hostname($lonhost);
15932: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
15933: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
15934: if ($context eq 'usercreation') {
15935: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
15936: if (ref($domconfig{$context}) eq 'HASH') {
15937: $hashtocheck = $domconfig{$context}{'cancreate'};
15938: if (ref($hashtocheck) eq 'HASH') {
15939: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
15940: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
15941: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
15942: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
15943: }
15944: if ($privkey && $pubkey) {
15945: $captcha = 'recaptcha';
15946: } else {
15947: $captcha = 'original';
15948: }
15949: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
15950: $captcha = 'original';
15951: }
15952: }
15953: } else {
15954: $captcha = 'captcha';
15955: }
15956: } elsif ($context eq 'login') {
15957: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
15958: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
15959: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
15960: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
15961: if ($privkey && $pubkey) {
15962: $captcha = 'recaptcha';
15963: } else {
15964: $captcha = 'original';
15965: }
15966: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
15967: $captcha = 'original';
15968: }
15969: }
15970: return ($captcha,$pubkey,$privkey);
15971: }
15972:
15973: sub create_captcha {
15974: my %captcha_params = &captcha_settings();
15975: my ($output,$maxtries,$tries) = ('',10,0);
15976: while ($tries < $maxtries) {
15977: $tries ++;
15978: my $captcha = Authen::Captcha->new (
15979: output_folder => $captcha_params{'output_dir'},
15980: data_folder => $captcha_params{'db_dir'},
15981: );
15982: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
15983:
15984: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
15985: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
15986: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 15987: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
15988: '<br />'.
15989: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 15990: last;
15991: }
15992: }
15993: return $output;
15994: }
15995:
15996: sub captcha_settings {
15997: my %captcha_params = (
15998: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
15999: www_output_dir => "/captchaspool",
16000: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16001: numchars => '5',
16002: );
16003: return %captcha_params;
16004: }
16005:
16006: sub check_captcha {
16007: my ($captcha_chk,$captcha_error);
16008: my $code = $env{'form.code'};
16009: my $md5sum = $env{'form.crypt'};
16010: my %captcha_params = &captcha_settings();
16011: my $captcha = Authen::Captcha->new(
16012: output_folder => $captcha_params{'output_dir'},
16013: data_folder => $captcha_params{'db_dir'},
16014: );
1.1075.2.26 raeburn 16015: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 16016: my %captcha_hash = (
16017: 0 => 'Code not checked (file error)',
16018: -1 => 'Failed: code expired',
16019: -2 => 'Failed: invalid code (not in database)',
16020: -3 => 'Failed: invalid code (code does not match crypt)',
16021: );
16022: if ($captcha_chk != 1) {
16023: $captcha_error = $captcha_hash{$captcha_chk}
16024: }
16025: return ($captcha_chk,$captcha_error);
16026: }
16027:
16028: sub create_recaptcha {
16029: my ($pubkey) = @_;
1.1075.2.51 raeburn 16030: my $use_ssl;
16031: if ($ENV{'SERVER_PORT'} == 443) {
16032: $use_ssl = 1;
16033: }
1.1075.2.14 raeburn 16034: my $captcha = Captcha::reCAPTCHA->new;
16035: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1075.2.51 raeburn 16036: $captcha->get_html($pubkey,undef,$use_ssl).
1.1075.2.92 raeburn 16037: &mt('If the text is hard to read, [_1] will replace them.',
1.1075.2.39 raeburn 16038: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1075.2.14 raeburn 16039: '<br /><br />';
16040: }
16041:
16042: sub check_recaptcha {
16043: my ($privkey) = @_;
16044: my $captcha_chk;
16045: my $captcha = Captcha::reCAPTCHA->new;
16046: my $captcha_result =
16047: $captcha->check_answer(
16048: $privkey,
16049: $ENV{'REMOTE_ADDR'},
16050: $env{'form.recaptcha_challenge_field'},
16051: $env{'form.recaptcha_response_field'},
16052: );
16053: if ($captcha_result->{is_valid}) {
16054: $captcha_chk = 1;
16055: }
16056: return $captcha_chk;
16057: }
16058:
1.1075.2.64 raeburn 16059: sub emailusername_info {
1.1075.2.67 raeburn 16060: my @fields = ('firstname','lastname','institution','web','location','officialemail');
1.1075.2.64 raeburn 16061: my %titles = &Apache::lonlocal::texthash (
16062: lastname => 'Last Name',
16063: firstname => 'First Name',
16064: institution => 'School/college/university',
16065: location => "School's city, state/province, country",
16066: web => "School's web address",
16067: officialemail => 'E-mail address at institution (if different)',
16068: );
16069: return (\@fields,\%titles);
16070: }
16071:
1.1075.2.56 raeburn 16072: sub cleanup_html {
16073: my ($incoming) = @_;
16074: my $outgoing;
16075: if ($incoming ne '') {
16076: $outgoing = $incoming;
16077: $outgoing =~ s/;/;/g;
16078: $outgoing =~ s/\#/#/g;
16079: $outgoing =~ s/\&/&/g;
16080: $outgoing =~ s/</</g;
16081: $outgoing =~ s/>/>/g;
16082: $outgoing =~ s/\(/(/g;
16083: $outgoing =~ s/\)/)/g;
16084: $outgoing =~ s/"/"/g;
16085: $outgoing =~ s/'/'/g;
16086: $outgoing =~ s/\$/$/g;
16087: $outgoing =~ s{/}{/}g;
16088: $outgoing =~ s/=/=/g;
16089: $outgoing =~ s/\\/\/g
16090: }
16091: return $outgoing;
16092: }
16093:
1.1075.2.74 raeburn 16094: # Checks for critical messages and returns a redirect url if one exists.
16095: # $interval indicates how often to check for messages.
16096: sub critical_redirect {
16097: my ($interval) = @_;
16098: if ((time-$env{'user.criticalcheck.time'})>$interval) {
16099: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
16100: $env{'user.name'});
16101: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
16102: my $redirecturl;
16103: if ($what[0]) {
16104: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
16105: $redirecturl='/adm/email?critical=display';
16106: my $url=&Apache::lonnet::absolute_url().$redirecturl;
16107: return (1, $url);
16108: }
16109: }
16110: }
16111: return ();
16112: }
16113:
1.1075.2.64 raeburn 16114: # Use:
16115: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
16116: #
16117: ##################################################
16118: # password associated functions #
16119: ##################################################
16120: sub des_keys {
16121: # Make a new key for DES encryption.
16122: # Each key has two parts which are returned separately.
16123: # Please note: Each key must be passed through the &hex function
16124: # before it is output to the web browser. The hex versions cannot
16125: # be used to decrypt.
16126: my @hexstr=('0','1','2','3','4','5','6','7',
16127: '8','9','a','b','c','d','e','f');
16128: my $lkey='';
16129: for (0..7) {
16130: $lkey.=$hexstr[rand(15)];
16131: }
16132: my $ukey='';
16133: for (0..7) {
16134: $ukey.=$hexstr[rand(15)];
16135: }
16136: return ($lkey,$ukey);
16137: }
16138:
16139: sub des_decrypt {
16140: my ($key,$cyphertext) = @_;
16141: my $keybin=pack("H16",$key);
16142: my $cypher;
16143: if ($Crypt::DES::VERSION>=2.03) {
16144: $cypher=new Crypt::DES $keybin;
16145: } else {
16146: $cypher=new DES $keybin;
16147: }
16148: my $plaintext=
16149: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
16150: $plaintext.=
16151: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
16152: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
16153: return $plaintext;
16154: }
16155:
1.112 bowersj2 16156: 1;
16157: __END__;
1.41 ng 16158:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>