Annotation of loncom/interface/loncommon.pm, revision 1.1188
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1188 ! raeburn 4: # $Id: loncommon.pm,v 1.1187 2014/04/25 17:56:43 bisitz 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.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 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.1091 foxr 76: use Text::Aspell;
1.1094 raeburn 77: use Authen::Captcha;
78: use Captcha::reCAPTCHA;
1.1174 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.1088 foxr 165: my %supported_codes;
1.1048 foxr 166: my %latex_language; # For choosing hyphenation in <transl..>
167: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 168: my %cprtag;
1.192 taceyjo1 169: my %scprtag;
1.351 www 170: my %fe; my %fd; my %fm;
1.41 ng 171: my %category_extensions;
1.12 harris41 172:
1.46 matthew 173: # ---------------------------------------------- Thesaurus variables
1.144 matthew 174: #
175: # %Keywords:
176: # A hash used by &keyword to determine if a word is considered a keyword.
177: # $thesaurus_db_file
178: # Scalar containing the full path to the thesaurus database.
1.46 matthew 179:
180: my %Keywords;
181: my $thesaurus_db_file;
182:
1.144 matthew 183: #
184: # Initialize values from language.tab, copyright.tab, filetypes.tab,
185: # thesaurus.tab, and filecategories.tab.
186: #
1.18 www 187: BEGIN {
1.46 matthew 188: # Variable initialization
189: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
190: #
1.22 www 191: unless ($readit) {
1.12 harris41 192: # ------------------------------------------------------------------- languages
193: {
1.158 raeburn 194: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
195: '/language.tab';
196: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 197: while (my $line = <$fh>) {
198: next if ($line=~/^\#/);
199: chomp($line);
1.1088 foxr 200: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 201: $language{$key}=$val.' - '.$enc;
202: if ($sup) {
203: $supported_language{$key}=$sup;
1.1088 foxr 204: $supported_codes{$key} = $code;
1.158 raeburn 205: }
1.1048 foxr 206: if ($latex) {
207: $latex_language_bykey{$key} = $latex;
1.1088 foxr 208: $latex_language{$code} = $latex;
1.1048 foxr 209: }
1.158 raeburn 210: }
211: close($fh);
212: }
1.12 harris41 213: }
214: # ------------------------------------------------------------------ copyrights
215: {
1.158 raeburn 216: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
217: '/copyright.tab';
218: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 219: while (my $line = <$fh>) {
220: next if ($line=~/^\#/);
221: chomp($line);
222: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 223: $cprtag{$key}=$val;
224: }
225: close($fh);
226: }
1.12 harris41 227: }
1.351 www 228: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 229: {
230: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
231: '/source_copyright.tab';
232: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 233: while (my $line = <$fh>) {
234: next if ($line =~ /^\#/);
235: chomp($line);
236: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 237: $scprtag{$key}=$val;
238: }
239: close($fh);
240: }
241: }
1.63 www 242:
1.517 raeburn 243: # -------------------------------------------------------------- default domain designs
1.63 www 244: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 245: my $designfile = $designdir.'/default.tab';
246: if ( open (my $fh,"<$designfile") ) {
247: while (my $line = <$fh>) {
248: next if ($line =~ /^\#/);
249: chomp($line);
250: my ($key,$val)=(split(/\=/,$line));
251: if ($val) { $defaultdesign{$key}=$val; }
252: }
253: close($fh);
1.63 www 254: }
255:
1.15 harris41 256: # ------------------------------------------------------------- file categories
257: {
1.158 raeburn 258: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
259: '/filecategories.tab';
260: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 261: while (my $line = <$fh>) {
262: next if ($line =~ /^\#/);
263: chomp($line);
264: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 265: push @{$category_extensions{lc($category)}},$extension;
266: }
267: close($fh);
268: }
269:
1.15 harris41 270: }
1.12 harris41 271: # ------------------------------------------------------------------ file types
272: {
1.158 raeburn 273: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
274: '/filetypes.tab';
275: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 276: while (my $line = <$fh>) {
277: next if ($line =~ /^\#/);
278: chomp($line);
279: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 280: if ($descr ne '') {
281: $fe{$ending}=lc($emb);
282: $fd{$ending}=$descr;
1.351 www 283: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 284: }
285: }
286: close($fh);
287: }
1.12 harris41 288: }
1.22 www 289: &Apache::lonnet::logthis(
1.705 tempelho 290: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 291: $readit=1;
1.46 matthew 292: } # end of unless($readit)
1.32 matthew 293:
294: }
1.112 bowersj2 295:
1.42 matthew 296: ###############################################################
297: ## HTML and Javascript Helper Functions ##
298: ###############################################################
299:
300: =pod
301:
1.112 bowersj2 302: =head1 HTML and Javascript Functions
1.42 matthew 303:
1.112 bowersj2 304: =over 4
305:
1.648 raeburn 306: =item * &browser_and_searcher_javascript()
1.112 bowersj2 307:
308: X<browsing, javascript>X<searching, javascript>Returns a string
309: containing javascript with two functions, C<openbrowser> and
310: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
311: tags.
1.42 matthew 312:
1.648 raeburn 313: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 314:
315: inputs: formname, elementname, only, omit
316:
317: formname and elementname indicate the name of the html form and name of
318: the element that the results of the browsing selection are to be placed in.
319:
320: Specifying 'only' will restrict the browser to displaying only files
1.185 www 321: with the given extension. Can be a comma separated list.
1.42 matthew 322:
323: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 324: with the given extension. Can be a comma separated list.
1.42 matthew 325:
1.648 raeburn 326: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 327:
328: Inputs: formname, elementname
329:
330: formname and elementname specify the name of the html form and the name
331: of the element the selection from the search results will be placed in.
1.542 raeburn 332:
1.42 matthew 333: =cut
334:
335: sub browser_and_searcher_javascript {
1.199 albertel 336: my ($mode)=@_;
337: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 338: my $resurl=&escape_single(&lastresurl());
1.42 matthew 339: return <<END;
1.219 albertel 340: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 341: var editbrowser = null;
1.135 albertel 342: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 343: var url = '$resurl/?';
1.42 matthew 344: if (editbrowser == null) {
345: url += 'launch=1&';
346: }
347: url += 'catalogmode=interactive&';
1.199 albertel 348: url += 'mode=$mode&';
1.611 albertel 349: url += 'inhibitmenu=yes&';
1.42 matthew 350: url += 'form=' + formname + '&';
351: if (only != null) {
352: url += 'only=' + only + '&';
1.217 albertel 353: } else {
354: url += 'only=&';
355: }
1.42 matthew 356: if (omit != null) {
357: url += 'omit=' + omit + '&';
1.217 albertel 358: } else {
359: url += 'omit=&';
360: }
1.135 albertel 361: if (titleelement != null) {
362: url += 'titleelement=' + titleelement + '&';
1.217 albertel 363: } else {
364: url += 'titleelement=&';
365: }
1.42 matthew 366: url += 'element=' + elementname + '';
367: var title = 'Browser';
1.435 albertel 368: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 369: options += ',width=700,height=600';
370: editbrowser = open(url,title,options,'1');
371: editbrowser.focus();
372: }
373: var editsearcher;
1.135 albertel 374: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 375: var url = '/adm/searchcat?';
376: if (editsearcher == null) {
377: url += 'launch=1&';
378: }
379: url += 'catalogmode=interactive&';
1.199 albertel 380: url += 'mode=$mode&';
1.42 matthew 381: url += 'form=' + formname + '&';
1.135 albertel 382: if (titleelement != null) {
383: url += 'titleelement=' + titleelement + '&';
1.217 albertel 384: } else {
385: url += 'titleelement=&';
386: }
1.42 matthew 387: url += 'element=' + elementname + '';
388: var title = 'Search';
1.435 albertel 389: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 390: options += ',width=700,height=600';
391: editsearcher = open(url,title,options,'1');
392: editsearcher.focus();
393: }
1.219 albertel 394: // END LON-CAPA Internal -->
1.42 matthew 395: END
1.170 www 396: }
397:
398: sub lastresurl {
1.258 albertel 399: if ($env{'environment.lastresurl'}) {
400: return $env{'environment.lastresurl'}
1.170 www 401: } else {
402: return '/res';
403: }
404: }
405:
406: sub storeresurl {
407: my $resurl=&Apache::lonnet::clutter(shift);
408: unless ($resurl=~/^\/res/) { return 0; }
409: $resurl=~s/\/$//;
410: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 411: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 412: return 1;
1.42 matthew 413: }
414:
1.74 www 415: sub studentbrowser_javascript {
1.111 www 416: unless (
1.258 albertel 417: (($env{'request.course.id'}) &&
1.302 albertel 418: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
419: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
420: '/'.$env{'request.course.sec'})
421: ))
1.258 albertel 422: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 423: ) { return ''; }
1.74 www 424: return (<<'ENDSTDBRW');
1.776 bisitz 425: <script type="text/javascript" language="Javascript">
1.824 bisitz 426: // <![CDATA[
1.74 www 427: var stdeditbrowser;
1.999 www 428: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 429: var url = '/adm/pickstudent?';
430: var filter;
1.558 albertel 431: if (!ignorefilter) {
432: eval('filter=document.'+formname+'.'+uname+'.value;');
433: }
1.74 www 434: if (filter != null) {
435: if (filter != '') {
436: url += 'filter='+filter+'&';
437: }
438: }
439: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 440: '&udomelement='+udom+
441: '&clicker='+clicker;
1.111 www 442: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 443: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 444: var title = 'Student_Browser';
1.74 www 445: var options = 'scrollbars=1,resizable=1,menubar=0';
446: options += ',width=700,height=600';
447: stdeditbrowser = open(url,title,options,'1');
448: stdeditbrowser.focus();
449: }
1.824 bisitz 450: // ]]>
1.74 www 451: </script>
452: ENDSTDBRW
453: }
1.42 matthew 454:
1.1003 www 455: sub resourcebrowser_javascript {
456: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 457: return (<<'ENDRESBRW');
1.1003 www 458: <script type="text/javascript" language="Javascript">
459: // <![CDATA[
460: var reseditbrowser;
1.1004 www 461: function openresbrowser(formname,reslink) {
1.1005 www 462: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 463: var title = 'Resource_Browser';
464: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 465: options += ',width=700,height=500';
1.1004 www 466: reseditbrowser = open(url,title,options,'1');
467: reseditbrowser.focus();
1.1003 www 468: }
469: // ]]>
470: </script>
1.1004 www 471: ENDRESBRW
1.1003 www 472: }
473:
1.74 www 474: sub selectstudent_link {
1.999 www 475: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
476: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
477: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
478: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 479: if ($env{'request.course.id'}) {
1.302 albertel 480: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
481: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
482: '/'.$env{'request.course.sec'})) {
1.111 www 483: return '';
484: }
1.999 www 485: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 486: if ($courseadvonly) {
487: $callargs .= ",'',1,1";
488: }
489: return '<span class="LC_nobreak">'.
490: '<a href="javascript:openstdbrowser('.$callargs.');">'.
491: &mt('Select User').'</a></span>';
1.74 www 492: }
1.258 albertel 493: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 494: $callargs .= ",'',1";
1.793 raeburn 495: return '<span class="LC_nobreak">'.
496: '<a href="javascript:openstdbrowser('.$callargs.');">'.
497: &mt('Select User').'</a></span>';
1.111 www 498: }
499: return '';
1.91 www 500: }
501:
1.1004 www 502: sub selectresource_link {
503: my ($form,$reslink,$arg)=@_;
504:
505: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
506: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
507: unless ($env{'request.course.id'}) { return $arg; }
508: return '<span class="LC_nobreak">'.
509: '<a href="javascript:openresbrowser('.$callargs.');">'.
510: $arg.'</a></span>';
511: }
512:
513:
514:
1.653 raeburn 515: sub authorbrowser_javascript {
516: return <<"ENDAUTHORBRW";
1.776 bisitz 517: <script type="text/javascript" language="JavaScript">
1.824 bisitz 518: // <![CDATA[
1.653 raeburn 519: var stdeditbrowser;
520:
521: function openauthorbrowser(formname,udom) {
522: var url = '/adm/pickauthor?';
523: url += 'form='+formname+'&roledom='+udom;
524: var title = 'Author_Browser';
525: var options = 'scrollbars=1,resizable=1,menubar=0';
526: options += ',width=700,height=600';
527: stdeditbrowser = open(url,title,options,'1');
528: stdeditbrowser.focus();
529: }
530:
1.824 bisitz 531: // ]]>
1.653 raeburn 532: </script>
533: ENDAUTHORBRW
534: }
535:
1.91 www 536: sub coursebrowser_javascript {
1.1116 raeburn 537: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
538: $credits_element) = @_;
1.932 raeburn 539: my $wintitle = 'Course_Browser';
1.931 raeburn 540: if ($crstype eq 'Community') {
1.932 raeburn 541: $wintitle = 'Community_Browser';
1.909 raeburn 542: }
1.876 raeburn 543: my $id_functions = &javascript_index_functions();
544: my $output = '
1.776 bisitz 545: <script type="text/javascript" language="JavaScript">
1.824 bisitz 546: // <![CDATA[
1.468 raeburn 547: var stdeditbrowser;'."\n";
1.876 raeburn 548:
549: $output .= <<"ENDSTDBRW";
1.909 raeburn 550: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 551: var url = '/adm/pickcourse?';
1.895 raeburn 552: var formid = getFormIdByName(formname);
1.876 raeburn 553: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 554: if (domainfilter != null) {
555: if (domainfilter != '') {
556: url += 'domainfilter='+domainfilter+'&';
557: }
558: }
1.91 www 559: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 560: '&cdomelement='+udom+
561: '&cnameelement='+desc;
1.468 raeburn 562: if (extra_element !=null && extra_element != '') {
1.594 raeburn 563: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 564: url += '&roleelement='+extra_element;
565: if (domainfilter == null || domainfilter == '') {
566: url += '&domainfilter='+extra_element;
567: }
1.234 raeburn 568: }
1.468 raeburn 569: else {
570: if (formname == 'portform') {
571: url += '&setroles='+extra_element;
1.800 raeburn 572: } else {
573: if (formname == 'rules') {
574: url += '&fixeddom='+extra_element;
575: }
1.468 raeburn 576: }
577: }
1.230 raeburn 578: }
1.909 raeburn 579: if (type != null && type != '') {
580: url += '&type='+type;
581: }
582: if (type_elem != null && type_elem != '') {
583: url += '&typeelement='+type_elem;
584: }
1.872 raeburn 585: if (formname == 'ccrs') {
586: var ownername = document.forms[formid].ccuname.value;
587: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
588: url += '&cloner='+ownername+':'+ownerdom;
589: }
1.293 raeburn 590: if (multflag !=null && multflag != '') {
591: url += '&multiple='+multflag;
592: }
1.909 raeburn 593: var title = '$wintitle';
1.91 www 594: var options = 'scrollbars=1,resizable=1,menubar=0';
595: options += ',width=700,height=600';
596: stdeditbrowser = open(url,title,options,'1');
597: stdeditbrowser.focus();
598: }
1.876 raeburn 599: $id_functions
600: ENDSTDBRW
1.1116 raeburn 601: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
602: $output .= &setsec_javascript($sec_element,$formname,$role_element,
603: $credits_element);
1.876 raeburn 604: }
605: $output .= '
606: // ]]>
607: </script>';
608: return $output;
609: }
610:
611: sub javascript_index_functions {
612: return <<"ENDJS";
613:
614: function getFormIdByName(formname) {
615: for (var i=0;i<document.forms.length;i++) {
616: if (document.forms[i].name == formname) {
617: return i;
618: }
619: }
620: return -1;
621: }
622:
623: function getIndexByName(formid,item) {
624: for (var i=0;i<document.forms[formid].elements.length;i++) {
625: if (document.forms[formid].elements[i].name == item) {
626: return i;
627: }
628: }
629: return -1;
630: }
1.468 raeburn 631:
1.876 raeburn 632: function getDomainFromSelectbox(formname,udom) {
633: var userdom;
634: var formid = getFormIdByName(formname);
635: if (formid > -1) {
636: var domid = getIndexByName(formid,udom);
637: if (domid > -1) {
638: if (document.forms[formid].elements[domid].type == 'select-one') {
639: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
640: }
641: if (document.forms[formid].elements[domid].type == 'hidden') {
642: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 643: }
644: }
645: }
1.876 raeburn 646: return userdom;
647: }
648:
649: ENDJS
1.468 raeburn 650:
1.876 raeburn 651: }
652:
1.1017 raeburn 653: sub javascript_array_indexof {
1.1018 raeburn 654: return <<ENDJS;
1.1017 raeburn 655: <script type="text/javascript" language="JavaScript">
656: // <![CDATA[
657:
658: if (!Array.prototype.indexOf) {
659: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
660: "use strict";
661: if (this === void 0 || this === null) {
662: throw new TypeError();
663: }
664: var t = Object(this);
665: var len = t.length >>> 0;
666: if (len === 0) {
667: return -1;
668: }
669: var n = 0;
670: if (arguments.length > 0) {
671: n = Number(arguments[1]);
1.1088 foxr 672: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 673: n = 0;
674: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
675: n = (n > 0 || -1) * Math.floor(Math.abs(n));
676: }
677: }
678: if (n >= len) {
679: return -1;
680: }
681: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
682: for (; k < len; k++) {
683: if (k in t && t[k] === searchElement) {
684: return k;
685: }
686: }
687: return -1;
688: }
689: }
690:
691: // ]]>
692: </script>
693:
694: ENDJS
695:
696: }
697:
1.876 raeburn 698: sub userbrowser_javascript {
699: my $id_functions = &javascript_index_functions();
700: return <<"ENDUSERBRW";
701:
1.888 raeburn 702: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 703: var url = '/adm/pickuser?';
704: var userdom = getDomainFromSelectbox(formname,udom);
705: if (userdom != null) {
706: if (userdom != '') {
707: url += 'srchdom='+userdom+'&';
708: }
709: }
710: url += 'form=' + formname + '&unameelement='+uname+
711: '&udomelement='+udom+
712: '&ulastelement='+ulast+
713: '&ufirstelement='+ufirst+
714: '&uemailelement='+uemail+
1.881 raeburn 715: '&hideudomelement='+hideudom+
716: '&coursedom='+crsdom;
1.888 raeburn 717: if ((caller != null) && (caller != undefined)) {
718: url += '&caller='+caller;
719: }
1.876 raeburn 720: var title = 'User_Browser';
721: var options = 'scrollbars=1,resizable=1,menubar=0';
722: options += ',width=700,height=600';
723: var stdeditbrowser = open(url,title,options,'1');
724: stdeditbrowser.focus();
725: }
726:
1.888 raeburn 727: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 728: var formid = getFormIdByName(formname);
729: if (formid > -1) {
1.888 raeburn 730: var unameid = getIndexByName(formid,uname);
1.876 raeburn 731: var domid = getIndexByName(formid,udom);
732: var hidedomid = getIndexByName(formid,origdom);
733: if (hidedomid > -1) {
734: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 735: var unameval = document.forms[formid].elements[unameid].value;
736: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
737: if (domid > -1) {
738: var slct = document.forms[formid].elements[domid];
739: if (slct.type == 'select-one') {
740: var i;
741: for (i=0;i<slct.length;i++) {
742: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
743: }
744: }
745: if (slct.type == 'hidden') {
746: slct.value = fixeddom;
1.876 raeburn 747: }
748: }
1.468 raeburn 749: }
750: }
751: }
1.876 raeburn 752: return;
753: }
754:
755: $id_functions
756: ENDUSERBRW
1.468 raeburn 757: }
758:
759: sub setsec_javascript {
1.1116 raeburn 760: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 761: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
762: $communityrolestr);
763: if ($role_element ne '') {
764: my @allroles = ('st','ta','ep','in','ad');
765: foreach my $crstype ('Course','Community') {
766: if ($crstype eq 'Community') {
767: foreach my $role (@allroles) {
768: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
769: }
770: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
771: } else {
772: foreach my $role (@allroles) {
773: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
774: }
775: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
776: }
777: }
778: $rolestr = '"'.join('","',@allroles).'"';
779: $courserolestr = '"'.join('","',@courserolenames).'"';
780: $communityrolestr = '"'.join('","',@communityrolenames).'"';
781: }
1.468 raeburn 782: my $setsections = qq|
783: function setSect(sectionlist) {
1.629 raeburn 784: var sectionsArray = new Array();
785: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
786: sectionsArray = sectionlist.split(",");
787: }
1.468 raeburn 788: var numSections = sectionsArray.length;
789: document.$formname.$sec_element.length = 0;
790: if (numSections == 0) {
791: document.$formname.$sec_element.multiple=false;
792: document.$formname.$sec_element.size=1;
793: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
794: } else {
795: if (numSections == 1) {
796: document.$formname.$sec_element.multiple=false;
797: document.$formname.$sec_element.size=1;
798: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
799: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
800: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
801: } else {
802: for (var i=0; i<numSections; i++) {
803: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
804: }
805: document.$formname.$sec_element.multiple=true
806: if (numSections < 3) {
807: document.$formname.$sec_element.size=numSections;
808: } else {
809: document.$formname.$sec_element.size=3;
810: }
811: document.$formname.$sec_element.options[0].selected = false
812: }
813: }
1.91 www 814: }
1.905 raeburn 815:
816: function setRole(crstype) {
1.468 raeburn 817: |;
1.905 raeburn 818: if ($role_element eq '') {
819: $setsections .= ' return;
820: }
821: ';
822: } else {
823: $setsections .= qq|
824: var elementLength = document.$formname.$role_element.length;
825: var allroles = Array($rolestr);
826: var courserolenames = Array($courserolestr);
827: var communityrolenames = Array($communityrolestr);
828: if (elementLength != undefined) {
829: if (document.$formname.$role_element.options[5].value == 'cc') {
830: if (crstype == 'Course') {
831: return;
832: } else {
833: allroles[5] = 'co';
834: for (var i=0; i<6; i++) {
835: document.$formname.$role_element.options[i].value = allroles[i];
836: document.$formname.$role_element.options[i].text = communityrolenames[i];
837: }
838: }
839: } else {
840: if (crstype == 'Community') {
841: return;
842: } else {
843: allroles[5] = 'cc';
844: for (var i=0; i<6; i++) {
845: document.$formname.$role_element.options[i].value = allroles[i];
846: document.$formname.$role_element.options[i].text = courserolenames[i];
847: }
848: }
849: }
850: }
851: return;
852: }
853: |;
854: }
1.1116 raeburn 855: if ($credits_element) {
856: $setsections .= qq|
857: function setCredits(defaultcredits) {
858: document.$formname.$credits_element.value = defaultcredits;
859: return;
860: }
861: |;
862: }
1.468 raeburn 863: return $setsections;
864: }
865:
1.91 www 866: sub selectcourse_link {
1.909 raeburn 867: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
868: $typeelement) = @_;
869: my $type = $selecttype;
1.871 raeburn 870: my $linktext = &mt('Select Course');
871: if ($selecttype eq 'Community') {
1.909 raeburn 872: $linktext = &mt('Select Community');
1.906 raeburn 873: } elsif ($selecttype eq 'Course/Community') {
874: $linktext = &mt('Select Course/Community');
1.909 raeburn 875: $type = '';
1.1019 raeburn 876: } elsif ($selecttype eq 'Select') {
877: $linktext = &mt('Select');
878: $type = '';
1.871 raeburn 879: }
1.787 bisitz 880: return '<span class="LC_nobreak">'
881: ."<a href='"
882: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
883: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 884: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 885: ."'>".$linktext.'</a>'
1.787 bisitz 886: .'</span>';
1.74 www 887: }
1.42 matthew 888:
1.653 raeburn 889: sub selectauthor_link {
890: my ($form,$udom)=@_;
891: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
892: &mt('Select Author').'</a>';
893: }
894:
1.876 raeburn 895: sub selectuser_link {
1.881 raeburn 896: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 897: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 898: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 899: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 900: ');">'.$linktext.'</a>';
1.876 raeburn 901: }
902:
1.273 raeburn 903: sub check_uncheck_jscript {
904: my $jscript = <<"ENDSCRT";
905: function checkAll(field) {
906: if (field.length > 0) {
907: for (i = 0; i < field.length; i++) {
1.1093 raeburn 908: if (!field[i].disabled) {
909: field[i].checked = true;
910: }
1.273 raeburn 911: }
912: } else {
1.1093 raeburn 913: if (!field.disabled) {
914: field.checked = true;
915: }
1.273 raeburn 916: }
917: }
918:
919: function uncheckAll(field) {
920: if (field.length > 0) {
921: for (i = 0; i < field.length; i++) {
922: field[i].checked = false ;
1.543 albertel 923: }
924: } else {
1.273 raeburn 925: field.checked = false ;
926: }
927: }
928: ENDSCRT
929: return $jscript;
930: }
931:
1.656 www 932: sub select_timezone {
1.659 raeburn 933: my ($name,$selected,$onchange,$includeempty)=@_;
934: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
935: if ($includeempty) {
936: $output .= '<option value=""';
937: if (($selected eq '') || ($selected eq 'local')) {
938: $output .= ' selected="selected" ';
939: }
940: $output .= '> </option>';
941: }
1.657 raeburn 942: my @timezones = DateTime::TimeZone->all_names;
943: foreach my $tzone (@timezones) {
944: $output.= '<option value="'.$tzone.'"';
945: if ($tzone eq $selected) {
946: $output.=' selected="selected"';
947: }
948: $output.=">$tzone</option>\n";
1.656 www 949: }
950: $output.="</select>";
951: return $output;
952: }
1.273 raeburn 953:
1.687 raeburn 954: sub select_datelocale {
955: my ($name,$selected,$onchange,$includeempty)=@_;
956: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
957: if ($includeempty) {
958: $output .= '<option value=""';
959: if ($selected eq '') {
960: $output .= ' selected="selected" ';
961: }
962: $output .= '> </option>';
963: }
964: my (@possibles,%locale_names);
965: my @locales = DateTime::Locale::Catalog::Locales;
966: foreach my $locale (@locales) {
967: if (ref($locale) eq 'HASH') {
968: my $id = $locale->{'id'};
969: if ($id ne '') {
970: my $en_terr = $locale->{'en_territory'};
971: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 972: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 973: if (grep(/^en$/,@languages) || !@languages) {
974: if ($en_terr ne '') {
975: $locale_names{$id} = '('.$en_terr.')';
976: } elsif ($native_terr ne '') {
977: $locale_names{$id} = $native_terr;
978: }
979: } else {
980: if ($native_terr ne '') {
981: $locale_names{$id} = $native_terr.' ';
982: } elsif ($en_terr ne '') {
983: $locale_names{$id} = '('.$en_terr.')';
984: }
985: }
986: push (@possibles,$id);
987: }
988: }
989: }
990: foreach my $item (sort(@possibles)) {
991: $output.= '<option value="'.$item.'"';
992: if ($item eq $selected) {
993: $output.=' selected="selected"';
994: }
995: $output.=">$item";
996: if ($locale_names{$item} ne '') {
997: $output.=" $locale_names{$item}</option>\n";
998: }
999: $output.="</option>\n";
1000: }
1001: $output.="</select>";
1002: return $output;
1003: }
1004:
1.792 raeburn 1005: sub select_language {
1006: my ($name,$selected,$includeempty) = @_;
1007: my %langchoices;
1008: if ($includeempty) {
1.1117 raeburn 1009: %langchoices = ('' => 'No language preference');
1.792 raeburn 1010: }
1011: foreach my $id (&languageids()) {
1012: my $code = &supportedlanguagecode($id);
1013: if ($code) {
1014: $langchoices{$code} = &plainlanguagedescription($id);
1015: }
1016: }
1.1117 raeburn 1017: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970 raeburn 1018: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1019: }
1020:
1.42 matthew 1021: =pod
1.36 matthew 1022:
1.1088 foxr 1023:
1024: =item * &list_languages()
1025:
1026: Returns an array reference that is suitable for use in language prompters.
1027: Each array element is itself a two element array. The first element
1028: is the language code. The second element a descsriptiuon of the
1029: language itself. This is suitable for use in e.g.
1030: &Apache::edit::select_arg (once dereferenced that is).
1031:
1032: =cut
1033:
1034: sub list_languages {
1035: my @lang_choices;
1036:
1037: foreach my $id (&languageids()) {
1038: my $code = &supportedlanguagecode($id);
1039: if ($code) {
1040: my $selector = $supported_codes{$id};
1041: my $description = &plainlanguagedescription($id);
1042: push (@lang_choices, [$selector, $description]);
1043: }
1044: }
1045: return \@lang_choices;
1046: }
1047:
1048: =pod
1049:
1.648 raeburn 1050: =item * &linked_select_forms(...)
1.36 matthew 1051:
1052: linked_select_forms returns a string containing a <script></script> block
1053: and html for two <select> menus. The select menus will be linked in that
1054: changing the value of the first menu will result in new values being placed
1055: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1056: order unless a defined order is provided.
1.36 matthew 1057:
1058: linked_select_forms takes the following ordered inputs:
1059:
1060: =over 4
1061:
1.112 bowersj2 1062: =item * $formname, the name of the <form> tag
1.36 matthew 1063:
1.112 bowersj2 1064: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1065:
1.112 bowersj2 1066: =item * $firstdefault, the default value for the first menu
1.36 matthew 1067:
1.112 bowersj2 1068: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1069:
1.112 bowersj2 1070: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1071:
1.112 bowersj2 1072: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1073:
1.609 raeburn 1074: =item * $menuorder, the order of values in the first menu
1075:
1.1115 raeburn 1076: =item * $onchangefirst, additional javascript call to execute for an onchange
1077: event for the first <select> tag
1078:
1079: =item * $onchangesecond, additional javascript call to execute for an onchange
1080: event for the second <select> tag
1081:
1.41 ng 1082: =back
1083:
1.36 matthew 1084: Below is an example of such a hash. Only the 'text', 'default', and
1085: 'select2' keys must appear as stated. keys(%menu) are the possible
1086: values for the first select menu. The text that coincides with the
1.41 ng 1087: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1088: and text for the second menu are given in the hash pointed to by
1089: $menu{$choice1}->{'select2'}.
1090:
1.112 bowersj2 1091: my %menu = ( A1 => { text =>"Choice A1" ,
1092: default => "B3",
1093: select2 => {
1094: B1 => "Choice B1",
1095: B2 => "Choice B2",
1096: B3 => "Choice B3",
1097: B4 => "Choice B4"
1.609 raeburn 1098: },
1099: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1100: },
1101: A2 => { text =>"Choice A2" ,
1102: default => "C2",
1103: select2 => {
1104: C1 => "Choice C1",
1105: C2 => "Choice C2",
1106: C3 => "Choice C3"
1.609 raeburn 1107: },
1108: order => ['C2','C1','C3'],
1.112 bowersj2 1109: },
1110: A3 => { text =>"Choice A3" ,
1111: default => "D6",
1112: select2 => {
1113: D1 => "Choice D1",
1114: D2 => "Choice D2",
1115: D3 => "Choice D3",
1116: D4 => "Choice D4",
1117: D5 => "Choice D5",
1118: D6 => "Choice D6",
1119: D7 => "Choice D7"
1.609 raeburn 1120: },
1121: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1122: }
1123: );
1.36 matthew 1124:
1125: =cut
1126:
1127: sub linked_select_forms {
1128: my ($formname,
1129: $middletext,
1130: $firstdefault,
1131: $firstselectname,
1132: $secondselectname,
1.609 raeburn 1133: $hashref,
1134: $menuorder,
1.1115 raeburn 1135: $onchangefirst,
1136: $onchangesecond
1.36 matthew 1137: ) = @_;
1138: my $second = "document.$formname.$secondselectname";
1139: my $first = "document.$formname.$firstselectname";
1140: # output the javascript to do the changing
1141: my $result = '';
1.776 bisitz 1142: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1143: $result.="// <![CDATA[\n";
1.36 matthew 1144: $result.="var select2data = new Object();\n";
1145: $" = '","';
1146: my $debug = '';
1147: foreach my $s1 (sort(keys(%$hashref))) {
1148: $result.="select2data.d_$s1 = new Object();\n";
1149: $result.="select2data.d_$s1.def = new String('".
1150: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1151: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1152: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1153: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1154: @s2values = @{$hashref->{$s1}->{'order'}};
1155: }
1.36 matthew 1156: $result.="\"@s2values\");\n";
1157: $result.="select2data.d_$s1.texts = new Array(";
1158: my @s2texts;
1159: foreach my $value (@s2values) {
1160: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1161: }
1162: $result.="\"@s2texts\");\n";
1163: }
1164: $"=' ';
1165: $result.= <<"END";
1166:
1167: function select1_changed() {
1168: // Determine new choice
1169: var newvalue = "d_" + $first.value;
1170: // update select2
1171: var values = select2data[newvalue].values;
1172: var texts = select2data[newvalue].texts;
1173: var select2def = select2data[newvalue].def;
1174: var i;
1175: // out with the old
1176: for (i = 0; i < $second.options.length; i++) {
1177: $second.options[i] = null;
1178: }
1179: // in with the nuclear
1180: for (i=0;i<values.length; i++) {
1181: $second.options[i] = new Option(values[i]);
1.143 matthew 1182: $second.options[i].value = values[i];
1.36 matthew 1183: $second.options[i].text = texts[i];
1184: if (values[i] == select2def) {
1185: $second.options[i].selected = true;
1186: }
1187: }
1188: }
1.824 bisitz 1189: // ]]>
1.36 matthew 1190: </script>
1191: END
1192: # output the initial values for the selection lists
1.1115 raeburn 1193: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1194: my @order = sort(keys(%{$hashref}));
1195: if (ref($menuorder) eq 'ARRAY') {
1196: @order = @{$menuorder};
1197: }
1198: foreach my $value (@order) {
1.36 matthew 1199: $result.=" <option value=\"$value\" ";
1.253 albertel 1200: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1201: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1202: }
1203: $result .= "</select>\n";
1204: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1205: $result .= $middletext;
1.1115 raeburn 1206: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1207: if ($onchangesecond) {
1208: $result .= ' onchange="'.$onchangesecond.'"';
1209: }
1210: $result .= ">\n";
1.36 matthew 1211: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1212:
1213: my @secondorder = sort(keys(%select2));
1214: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1215: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1216: }
1217: foreach my $value (@secondorder) {
1.36 matthew 1218: $result.=" <option value=\"$value\" ";
1.253 albertel 1219: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1220: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1221: }
1222: $result .= "</select>\n";
1223: # return $debug;
1224: return $result;
1225: } # end of sub linked_select_forms {
1226:
1.45 matthew 1227: =pod
1.44 bowersj2 1228:
1.973 raeburn 1229: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1230:
1.112 bowersj2 1231: Returns a string corresponding to an HTML link to the given help
1232: $topic, where $topic corresponds to the name of a .tex file in
1233: /home/httpd/html/adm/help/tex, with underscores replaced by
1234: spaces.
1235:
1236: $text will optionally be linked to the same topic, allowing you to
1237: link text in addition to the graphic. If you do not want to link
1238: text, but wish to specify one of the later parameters, pass an
1239: empty string.
1240:
1241: $stayOnPage is a value that will be interpreted as a boolean. If true,
1242: the link will not open a new window. If false, the link will open
1243: a new window using Javascript. (Default is false.)
1244:
1245: $width and $height are optional numerical parameters that will
1246: override the width and height of the popped up window, which may
1.973 raeburn 1247: be useful for certain help topics with big pictures included.
1248:
1249: $imgid is the id of the img tag used for the help icon. This may be
1250: used in a javascript call to switch the image src. See
1251: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1252:
1253: =cut
1254:
1255: sub help_open_topic {
1.973 raeburn 1256: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1257: $text = "" if (not defined $text);
1.44 bowersj2 1258: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1259: $width = 500 if (not defined $width);
1.44 bowersj2 1260: $height = 400 if (not defined $height);
1261: my $filename = $topic;
1262: $filename =~ s/ /_/g;
1263:
1.48 bowersj2 1264: my $template = "";
1265: my $link;
1.572 banghart 1266:
1.159 www 1267: $topic=~s/\W/\_/g;
1.44 bowersj2 1268:
1.572 banghart 1269: if (!$stayOnPage) {
1.1033 www 1270: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1271: } elsif ($stayOnPage eq 'popup') {
1272: $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 1273: } else {
1.48 bowersj2 1274: $link = "/adm/help/${filename}.hlp";
1275: }
1276:
1277: # Add the text
1.755 neumanie 1278: if ($text ne "") {
1.763 bisitz 1279: $template.='<span class="LC_help_open_topic">'
1280: .'<a target="_top" href="'.$link.'">'
1281: .$text.'</a>';
1.48 bowersj2 1282: }
1283:
1.763 bisitz 1284: # (Always) Add the graphic
1.179 matthew 1285: my $title = &mt('Online Help');
1.667 raeburn 1286: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1287: if ($imgid ne '') {
1288: $imgid = ' id="'.$imgid.'"';
1289: }
1.763 bisitz 1290: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1291: .'<img src="'.$helpicon.'" border="0"'
1292: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1293: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1294: .' /></a>';
1295: if ($text ne "") {
1296: $template.='</span>';
1297: }
1.44 bowersj2 1298: return $template;
1299:
1.106 bowersj2 1300: }
1301:
1302: # This is a quicky function for Latex cheatsheet editing, since it
1303: # appears in at least four places
1304: sub helpLatexCheatsheet {
1.1037 www 1305: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1306: my $out;
1.106 bowersj2 1307: my $addOther = '';
1.732 raeburn 1308: if ($topic) {
1.1037 www 1309: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1310: }
1311: $out = '<span>' # Start cheatsheet
1312: .$addOther
1313: .'<span>'
1.1037 www 1314: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1315: .'</span> <span>'
1.1037 www 1316: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1317: .'</span>';
1.732 raeburn 1318: unless ($not_author) {
1.1186 kruse 1319: $out .= '<span>'
1320: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1321: .'</span> <span>'
1322: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1323: .'</span>';
1.732 raeburn 1324: }
1.763 bisitz 1325: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1326: return $out;
1.172 www 1327: }
1328:
1.430 albertel 1329: sub general_help {
1330: my $helptopic='Student_Intro';
1331: if ($env{'request.role'}=~/^(ca|au)/) {
1332: $helptopic='Authoring_Intro';
1.907 raeburn 1333: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1334: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1335: } elsif ($env{'request.role'}=~/^dc/) {
1336: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1337: }
1338: return $helptopic;
1339: }
1340:
1341: sub update_help_link {
1342: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1343: my $origurl = $ENV{'REQUEST_URI'};
1344: $origurl=~s|^/~|/priv/|;
1345: my $timestamp = time;
1346: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1347: $$datum = &escape($$datum);
1348: }
1349:
1350: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1351: my $output .= <<"ENDOUTPUT";
1352: <script type="text/javascript">
1.824 bisitz 1353: // <![CDATA[
1.430 albertel 1354: banner_link = '$banner_link';
1.824 bisitz 1355: // ]]>
1.430 albertel 1356: </script>
1357: ENDOUTPUT
1358: return $output;
1359: }
1360:
1361: # now just updates the help link and generates a blue icon
1.193 raeburn 1362: sub help_open_menu {
1.430 albertel 1363: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1364: = @_;
1.949 droeschl 1365: $stayOnPage = 1;
1.430 albertel 1366: my $output;
1367: if ($component_help) {
1368: if (!$text) {
1369: $output=&help_open_topic($component_help,undef,$stayOnPage,
1370: $width,$height);
1371: } else {
1372: my $help_text;
1373: $help_text=&unescape($topic);
1374: $output='<table><tr><td>'.
1375: &help_open_topic($component_help,$help_text,$stayOnPage,
1376: $width,$height).'</td></tr></table>';
1377: }
1378: }
1379: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1380: return $output.$banner_link;
1381: }
1382:
1383: sub top_nav_help {
1384: my ($text) = @_;
1.436 albertel 1385: $text = &mt($text);
1.949 droeschl 1386: my $stay_on_page = 1;
1387:
1.1168 raeburn 1388: my ($link,$banner_link);
1389: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1390: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1391: : "javascript:helpMenu('open')";
1392: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1393: }
1.201 raeburn 1394: my $title = &mt('Get help');
1.1168 raeburn 1395: if ($link) {
1396: return <<"END";
1.436 albertel 1397: $banner_link
1.1159 raeburn 1398: <a href="$link" title="$title">$text</a>
1.436 albertel 1399: END
1.1168 raeburn 1400: } else {
1401: return ' '.$text.' ';
1402: }
1.436 albertel 1403: }
1404:
1405: sub help_menu_js {
1.1154 raeburn 1406: my ($httphost) = @_;
1.949 droeschl 1407: my $stayOnPage = 1;
1.436 albertel 1408: my $width = 620;
1409: my $height = 600;
1.430 albertel 1410: my $helptopic=&general_help();
1.1154 raeburn 1411: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1412: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1413: my $start_page =
1414: &Apache::loncommon::start_page('Help Menu', undef,
1415: {'frameset' => 1,
1416: 'js_ready' => 1,
1.1154 raeburn 1417: 'use_absolute' => $httphost,
1.331 albertel 1418: 'add_entries' => {
1.1168 raeburn 1419: 'border' => '0',
1.579 raeburn 1420: 'rows' => "110,*",},});
1.331 albertel 1421: my $end_page =
1422: &Apache::loncommon::end_page({'frameset' => 1,
1423: 'js_ready' => 1,});
1424:
1.436 albertel 1425: my $template .= <<"ENDTEMPLATE";
1426: <script type="text/javascript">
1.877 bisitz 1427: // <![CDATA[
1.253 albertel 1428: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1429: var banner_link = '';
1.243 raeburn 1430: function helpMenu(target) {
1431: var caller = this;
1432: if (target == 'open') {
1433: var newWindow = null;
1434: try {
1.262 albertel 1435: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1436: }
1437: catch(error) {
1438: writeHelp(caller);
1439: return;
1440: }
1441: if (newWindow) {
1442: caller = newWindow;
1443: }
1.193 raeburn 1444: }
1.243 raeburn 1445: writeHelp(caller);
1446: return;
1447: }
1448: function writeHelp(caller) {
1.1168 raeburn 1449: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1450: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1451: caller.document.close();
1452: caller.focus();
1.193 raeburn 1453: }
1.877 bisitz 1454: // END LON-CAPA Internal -->
1.253 albertel 1455: // ]]>
1.436 albertel 1456: </script>
1.193 raeburn 1457: ENDTEMPLATE
1458: return $template;
1459: }
1460:
1.172 www 1461: sub help_open_bug {
1462: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1463: unless ($env{'user.adv'}) { return ''; }
1.172 www 1464: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1465: $text = "" if (not defined $text);
1466: $stayOnPage=1;
1.184 albertel 1467: $width = 600 if (not defined $width);
1468: $height = 600 if (not defined $height);
1.172 www 1469:
1470: $topic=~s/\W+/\+/g;
1471: my $link='';
1472: my $template='';
1.379 albertel 1473: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1474: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1475: if (!$stayOnPage)
1476: {
1477: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1478: }
1479: else
1480: {
1481: $link = $url;
1482: }
1483: # Add the text
1484: if ($text ne "")
1485: {
1486: $template .=
1487: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1488: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1489: }
1490:
1491: # Add the graphic
1.179 matthew 1492: my $title = &mt('Report a Bug');
1.215 albertel 1493: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1494: $template .= <<"ENDTEMPLATE";
1.436 albertel 1495: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1496: ENDTEMPLATE
1497: if ($text ne '') { $template.='</td></tr></table>' };
1498: return $template;
1499:
1500: }
1501:
1502: sub help_open_faq {
1503: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1504: unless ($env{'user.adv'}) { return ''; }
1.172 www 1505: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1506: $text = "" if (not defined $text);
1507: $stayOnPage=1;
1508: $width = 350 if (not defined $width);
1509: $height = 400 if (not defined $height);
1510:
1511: $topic=~s/\W+/\+/g;
1512: my $link='';
1513: my $template='';
1514: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1515: if (!$stayOnPage)
1516: {
1517: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1518: }
1519: else
1520: {
1521: $link = $url;
1522: }
1523:
1524: # Add the text
1525: if ($text ne "")
1526: {
1527: $template .=
1.173 www 1528: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1529: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1530: }
1531:
1532: # Add the graphic
1.179 matthew 1533: my $title = &mt('View the FAQ');
1.215 albertel 1534: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1535: $template .= <<"ENDTEMPLATE";
1.436 albertel 1536: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1537: ENDTEMPLATE
1538: if ($text ne '') { $template.='</td></tr></table>' };
1539: return $template;
1540:
1.44 bowersj2 1541: }
1.37 matthew 1542:
1.180 matthew 1543: ###############################################################
1544: ###############################################################
1545:
1.45 matthew 1546: =pod
1547:
1.648 raeburn 1548: =item * &change_content_javascript():
1.256 matthew 1549:
1550: This and the next function allow you to create small sections of an
1551: otherwise static HTML page that you can update on the fly with
1552: Javascript, even in Netscape 4.
1553:
1554: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1555: must be written to the HTML page once. It will prove the Javascript
1556: function "change(name, content)". Calling the change function with the
1557: name of the section
1558: you want to update, matching the name passed to C<changable_area>, and
1559: the new content you want to put in there, will put the content into
1560: that area.
1561:
1562: B<Note>: Netscape 4 only reserves enough space for the changable area
1563: to contain room for the original contents. You need to "make space"
1564: for whatever changes you wish to make, and be B<sure> to check your
1565: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1566: it's adequate for updating a one-line status display, but little more.
1567: This script will set the space to 100% width, so you only need to
1568: worry about height in Netscape 4.
1569:
1570: Modern browsers are much less limiting, and if you can commit to the
1571: user not using Netscape 4, this feature may be used freely with
1572: pretty much any HTML.
1573:
1574: =cut
1575:
1576: sub change_content_javascript {
1577: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1578: if ($env{'browser.type'} eq 'netscape' &&
1579: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1580: return (<<NETSCAPE4);
1581: function change(name, content) {
1582: doc = document.layers[name+"___escape"].layers[0].document;
1583: doc.open();
1584: doc.write(content);
1585: doc.close();
1586: }
1587: NETSCAPE4
1588: } else {
1589: # Otherwise, we need to use semi-standards-compliant code
1590: # (technically, "innerHTML" isn't standard but the equivalent
1591: # is really scary, and every useful browser supports it
1592: return (<<DOMBASED);
1593: function change(name, content) {
1594: element = document.getElementById(name);
1595: element.innerHTML = content;
1596: }
1597: DOMBASED
1598: }
1599: }
1600:
1601: =pod
1602:
1.648 raeburn 1603: =item * &changable_area($name,$origContent):
1.256 matthew 1604:
1605: This provides a "changable area" that can be modified on the fly via
1606: the Javascript code provided in C<change_content_javascript>. $name is
1607: the name you will use to reference the area later; do not repeat the
1608: same name on a given HTML page more then once. $origContent is what
1609: the area will originally contain, which can be left blank.
1610:
1611: =cut
1612:
1613: sub changable_area {
1614: my ($name, $origContent) = @_;
1615:
1.258 albertel 1616: if ($env{'browser.type'} eq 'netscape' &&
1617: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1618: # If this is netscape 4, we need to use the Layer tag
1619: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1620: } else {
1621: return "<span id='$name'>$origContent</span>";
1622: }
1623: }
1624:
1625: =pod
1626:
1.648 raeburn 1627: =item * &viewport_geometry_js
1.590 raeburn 1628:
1629: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1630:
1631: =cut
1632:
1633:
1634: sub viewport_geometry_js {
1635: return <<"GEOMETRY";
1636: var Geometry = {};
1637: function init_geometry() {
1638: if (Geometry.init) { return };
1639: Geometry.init=1;
1640: if (window.innerHeight) {
1641: Geometry.getViewportHeight = function() { return window.innerHeight; };
1642: Geometry.getViewportWidth = function() { return window.innerWidth; };
1643: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1644: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1645: }
1646: else if (document.documentElement && document.documentElement.clientHeight) {
1647: Geometry.getViewportHeight =
1648: function() { return document.documentElement.clientHeight; };
1649: Geometry.getViewportWidth =
1650: function() { return document.documentElement.clientWidth; };
1651:
1652: Geometry.getHorizontalScroll =
1653: function() { return document.documentElement.scrollLeft; };
1654: Geometry.getVerticalScroll =
1655: function() { return document.documentElement.scrollTop; };
1656: }
1657: else if (document.body.clientHeight) {
1658: Geometry.getViewportHeight =
1659: function() { return document.body.clientHeight; };
1660: Geometry.getViewportWidth =
1661: function() { return document.body.clientWidth; };
1662: Geometry.getHorizontalScroll =
1663: function() { return document.body.scrollLeft; };
1664: Geometry.getVerticalScroll =
1665: function() { return document.body.scrollTop; };
1666: }
1667: }
1668:
1669: GEOMETRY
1670: }
1671:
1672: =pod
1673:
1.648 raeburn 1674: =item * &viewport_size_js()
1.590 raeburn 1675:
1676: 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.
1677:
1678: =cut
1679:
1680: sub viewport_size_js {
1681: my $geometry = &viewport_geometry_js();
1682: return <<"DIMS";
1683:
1684: $geometry
1685:
1686: function getViewportDims(width,height) {
1687: init_geometry();
1688: width.value = Geometry.getViewportWidth();
1689: height.value = Geometry.getViewportHeight();
1690: return;
1691: }
1692:
1693: DIMS
1694: }
1695:
1696: =pod
1697:
1.648 raeburn 1698: =item * &resize_textarea_js()
1.565 albertel 1699:
1700: emits the needed javascript to resize a textarea to be as big as possible
1701:
1702: creates a function resize_textrea that takes two IDs first should be
1703: the id of the element to resize, second should be the id of a div that
1704: surrounds everything that comes after the textarea, this routine needs
1705: to be attached to the <body> for the onload and onresize events.
1706:
1.648 raeburn 1707: =back
1.565 albertel 1708:
1709: =cut
1710:
1711: sub resize_textarea_js {
1.590 raeburn 1712: my $geometry = &viewport_geometry_js();
1.565 albertel 1713: return <<"RESIZE";
1714: <script type="text/javascript">
1.824 bisitz 1715: // <![CDATA[
1.590 raeburn 1716: $geometry
1.565 albertel 1717:
1.588 albertel 1718: function getX(element) {
1719: var x = 0;
1720: while (element) {
1721: x += element.offsetLeft;
1722: element = element.offsetParent;
1723: }
1724: return x;
1725: }
1726: function getY(element) {
1727: var y = 0;
1728: while (element) {
1729: y += element.offsetTop;
1730: element = element.offsetParent;
1731: }
1732: return y;
1733: }
1734:
1735:
1.565 albertel 1736: function resize_textarea(textarea_id,bottom_id) {
1737: init_geometry();
1738: var textarea = document.getElementById(textarea_id);
1739: //alert(textarea);
1740:
1.588 albertel 1741: var textarea_top = getY(textarea);
1.565 albertel 1742: var textarea_height = textarea.offsetHeight;
1743: var bottom = document.getElementById(bottom_id);
1.588 albertel 1744: var bottom_top = getY(bottom);
1.565 albertel 1745: var bottom_height = bottom.offsetHeight;
1746: var window_height = Geometry.getViewportHeight();
1.588 albertel 1747: var fudge = 23;
1.565 albertel 1748: var new_height = window_height-fudge-textarea_top-bottom_height;
1749: if (new_height < 300) {
1750: new_height = 300;
1751: }
1752: textarea.style.height=new_height+'px';
1753: }
1.824 bisitz 1754: // ]]>
1.565 albertel 1755: </script>
1756: RESIZE
1757:
1758: }
1759:
1760: =pod
1761:
1.256 matthew 1762: =head1 Excel and CSV file utility routines
1763:
1764: =cut
1765:
1766: ###############################################################
1767: ###############################################################
1768:
1769: =pod
1770:
1.1162 raeburn 1771: =over 4
1772:
1.648 raeburn 1773: =item * &csv_translate($text)
1.37 matthew 1774:
1.185 www 1775: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1776: format.
1777:
1778: =cut
1779:
1.180 matthew 1780: ###############################################################
1781: ###############################################################
1.37 matthew 1782: sub csv_translate {
1783: my $text = shift;
1784: $text =~ s/\"/\"\"/g;
1.209 albertel 1785: $text =~ s/\n/ /g;
1.37 matthew 1786: return $text;
1787: }
1.180 matthew 1788:
1789: ###############################################################
1790: ###############################################################
1791:
1792: =pod
1793:
1.648 raeburn 1794: =item * &define_excel_formats()
1.180 matthew 1795:
1796: Define some commonly used Excel cell formats.
1797:
1798: Currently supported formats:
1799:
1800: =over 4
1801:
1802: =item header
1803:
1804: =item bold
1805:
1806: =item h1
1807:
1808: =item h2
1809:
1810: =item h3
1811:
1.256 matthew 1812: =item h4
1813:
1814: =item i
1815:
1.180 matthew 1816: =item date
1817:
1818: =back
1819:
1820: Inputs: $workbook
1821:
1822: Returns: $format, a hash reference.
1823:
1.1057 foxr 1824:
1.180 matthew 1825: =cut
1826:
1827: ###############################################################
1828: ###############################################################
1829: sub define_excel_formats {
1830: my ($workbook) = @_;
1831: my $format;
1832: $format->{'header'} = $workbook->add_format(bold => 1,
1833: bottom => 1,
1834: align => 'center');
1835: $format->{'bold'} = $workbook->add_format(bold=>1);
1836: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1837: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1838: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1839: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1840: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1841: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1842: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1843: return $format;
1844: }
1845:
1846: ###############################################################
1847: ###############################################################
1.113 bowersj2 1848:
1849: =pod
1850:
1.648 raeburn 1851: =item * &create_workbook()
1.255 matthew 1852:
1853: Create an Excel worksheet. If it fails, output message on the
1854: request object and return undefs.
1855:
1856: Inputs: Apache request object
1857:
1858: Returns (undef) on failure,
1859: Excel worksheet object, scalar with filename, and formats
1860: from &Apache::loncommon::define_excel_formats on success
1861:
1862: =cut
1863:
1864: ###############################################################
1865: ###############################################################
1866: sub create_workbook {
1867: my ($r) = @_;
1868: #
1869: # Create the excel spreadsheet
1870: my $filename = '/prtspool/'.
1.258 albertel 1871: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1872: time.'_'.rand(1000000000).'.xls';
1873: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1874: if (! defined($workbook)) {
1875: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1876: $r->print(
1877: '<p class="LC_error">'
1878: .&mt('Problems occurred in creating the new Excel file.')
1879: .' '.&mt('This error has been logged.')
1880: .' '.&mt('Please alert your LON-CAPA administrator.')
1881: .'</p>'
1882: );
1.255 matthew 1883: return (undef);
1884: }
1885: #
1.1014 foxr 1886: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1887: #
1888: my $format = &Apache::loncommon::define_excel_formats($workbook);
1889: return ($workbook,$filename,$format);
1890: }
1891:
1892: ###############################################################
1893: ###############################################################
1894:
1895: =pod
1896:
1.648 raeburn 1897: =item * &create_text_file()
1.113 bowersj2 1898:
1.542 raeburn 1899: Create a file to write to and eventually make available to the user.
1.256 matthew 1900: If file creation fails, outputs an error message on the request object and
1901: return undefs.
1.113 bowersj2 1902:
1.256 matthew 1903: Inputs: Apache request object, and file suffix
1.113 bowersj2 1904:
1.256 matthew 1905: Returns (undef) on failure,
1906: Filehandle and filename on success.
1.113 bowersj2 1907:
1908: =cut
1909:
1.256 matthew 1910: ###############################################################
1911: ###############################################################
1912: sub create_text_file {
1913: my ($r,$suffix) = @_;
1914: if (! defined($suffix)) { $suffix = 'txt'; };
1915: my $fh;
1916: my $filename = '/prtspool/'.
1.258 albertel 1917: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1918: time.'_'.rand(1000000000).'.'.$suffix;
1919: $fh = Apache::File->new('>/home/httpd'.$filename);
1920: if (! defined($fh)) {
1921: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1922: $r->print(
1923: '<p class="LC_error">'
1924: .&mt('Problems occurred in creating the output file.')
1925: .' '.&mt('This error has been logged.')
1926: .' '.&mt('Please alert your LON-CAPA administrator.')
1927: .'</p>'
1928: );
1.113 bowersj2 1929: }
1.256 matthew 1930: return ($fh,$filename)
1.113 bowersj2 1931: }
1932:
1933:
1.256 matthew 1934: =pod
1.113 bowersj2 1935:
1936: =back
1937:
1938: =cut
1.37 matthew 1939:
1940: ###############################################################
1.33 matthew 1941: ## Home server <option> list generating code ##
1942: ###############################################################
1.35 matthew 1943:
1.169 www 1944: # ------------------------------------------
1945:
1946: sub domain_select {
1947: my ($name,$value,$multiple)=@_;
1948: my %domains=map {
1.514 albertel 1949: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1950: } &Apache::lonnet::all_domains();
1.169 www 1951: if ($multiple) {
1952: $domains{''}=&mt('Any domain');
1.550 albertel 1953: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1954: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1955: } else {
1.550 albertel 1956: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1957: return &select_form($name,$value,\%domains);
1.169 www 1958: }
1959: }
1960:
1.282 albertel 1961: #-------------------------------------------
1962:
1963: =pod
1964:
1.519 raeburn 1965: =head1 Routines for form select boxes
1966:
1967: =over 4
1968:
1.648 raeburn 1969: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1970:
1971: Returns a string containing a <select> element int multiple mode
1972:
1973:
1974: Args:
1975: $name - name of the <select> element
1.506 raeburn 1976: $value - scalar or array ref of values that should already be selected
1.282 albertel 1977: $size - number of rows long the select element is
1.283 albertel 1978: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1979: (shown text should already have been &mt())
1.506 raeburn 1980: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1981:
1.282 albertel 1982: =cut
1983:
1984: #-------------------------------------------
1.169 www 1985: sub multiple_select_form {
1.284 albertel 1986: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1987: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1988: my $output='';
1.191 matthew 1989: if (! defined($size)) {
1990: $size = 4;
1.283 albertel 1991: if (scalar(keys(%$hash))<4) {
1992: $size = scalar(keys(%$hash));
1.191 matthew 1993: }
1994: }
1.734 bisitz 1995: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1996: my @order;
1.506 raeburn 1997: if (ref($order) eq 'ARRAY') {
1998: @order = @{$order};
1999: } else {
2000: @order = sort(keys(%$hash));
1.501 banghart 2001: }
2002: if (exists($$hash{'select_form_order'})) {
2003: @order = @{$$hash{'select_form_order'}};
2004: }
2005:
1.284 albertel 2006: foreach my $key (@order) {
1.356 albertel 2007: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2008: $output.='selected="selected" ' if ($selected{$key});
2009: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2010: }
2011: $output.="</select>\n";
2012: return $output;
2013: }
2014:
1.88 www 2015: #-------------------------------------------
2016:
2017: =pod
2018:
1.970 raeburn 2019: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 2020:
2021: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2022: allow a user to select options from a ref to a hash containing:
2023: option_name => displayed text. An optional $onchange can include
2024: a javascript onchange item, e.g., onchange="this.form.submit();"
2025:
1.88 www 2026: See lonrights.pm for an example invocation and use.
2027:
2028: =cut
2029:
2030: #-------------------------------------------
2031: sub select_form {
1.970 raeburn 2032: my ($def,$name,$hashref,$onchange) = @_;
2033: return unless (ref($hashref) eq 'HASH');
2034: if ($onchange) {
2035: $onchange = ' onchange="'.$onchange.'"';
2036: }
2037: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2038: my @keys;
1.970 raeburn 2039: if (exists($hashref->{'select_form_order'})) {
2040: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2041: } else {
1.970 raeburn 2042: @keys=sort(keys(%{$hashref}));
1.128 albertel 2043: }
1.356 albertel 2044: foreach my $key (@keys) {
2045: $selectform.=
2046: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2047: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2048: ">".$hashref->{$key}."</option>\n";
1.88 www 2049: }
2050: $selectform.="</select>";
2051: return $selectform;
2052: }
2053:
1.475 www 2054: # For display filters
2055:
2056: sub display_filter {
1.1074 raeburn 2057: my ($context) = @_;
1.475 www 2058: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2059: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2060: my $phraseinput = 'hidden';
2061: my $includeinput = 'hidden';
2062: my ($checked,$includetypestext);
2063: if ($env{'form.displayfilter'} eq 'containing') {
2064: $phraseinput = 'text';
2065: if ($context eq 'parmslog') {
2066: $includeinput = 'checkbox';
2067: if ($env{'form.includetypes'}) {
2068: $checked = ' checked="checked"';
2069: }
2070: $includetypestext = &mt('Include parameter types');
2071: }
2072: } else {
2073: $includetypestext = ' ';
2074: }
2075: my ($additional,$secondid,$thirdid);
2076: if ($context eq 'parmslog') {
2077: $additional =
2078: '<label><input type="'.$includeinput.'" name="includetypes"'.
2079: $checked.' name="includetypes" value="1" id="includetypes" />'.
2080: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2081: '</label>';
2082: $secondid = 'includetypes';
2083: $thirdid = 'includetypestext';
2084: }
2085: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2086: '$secondid','$thirdid')";
2087: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2088: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2089: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2090: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2091: &mt('Filter: [_1]',
1.477 www 2092: &select_form($env{'form.displayfilter'},
2093: 'displayfilter',
1.970 raeburn 2094: {'currentfolder' => 'Current folder/page',
1.477 www 2095: 'containing' => 'Containing phrase',
1.1074 raeburn 2096: 'none' => 'None'},$onchange)).' '.
2097: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2098: &HTML::Entities::encode($env{'form.containingphrase'}).
2099: '" />'.$additional;
2100: }
2101:
2102: sub display_filter_js {
2103: my $includetext = &mt('Include parameter types');
2104: return <<"ENDJS";
2105:
2106: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2107: var firstType = 'hidden';
2108: if (setter.options[setter.selectedIndex].value == 'containing') {
2109: firstType = 'text';
2110: }
2111: firstObject = document.getElementById(firstid);
2112: if (typeof(firstObject) == 'object') {
2113: if (firstObject.type != firstType) {
2114: changeInputType(firstObject,firstType);
2115: }
2116: }
2117: if (context == 'parmslog') {
2118: var secondType = 'hidden';
2119: if (firstType == 'text') {
2120: secondType = 'checkbox';
2121: }
2122: secondObject = document.getElementById(secondid);
2123: if (typeof(secondObject) == 'object') {
2124: if (secondObject.type != secondType) {
2125: changeInputType(secondObject,secondType);
2126: }
2127: }
2128: var textItem = document.getElementById(thirdid);
2129: var currtext = textItem.innerHTML;
2130: var newtext;
2131: if (firstType == 'text') {
2132: newtext = '$includetext';
2133: } else {
2134: newtext = ' ';
2135: }
2136: if (currtext != newtext) {
2137: textItem.innerHTML = newtext;
2138: }
2139: }
2140: return;
2141: }
2142:
2143: function changeInputType(oldObject,newType) {
2144: var newObject = document.createElement('input');
2145: newObject.type = newType;
2146: if (oldObject.size) {
2147: newObject.size = oldObject.size;
2148: }
2149: if (oldObject.value) {
2150: newObject.value = oldObject.value;
2151: }
2152: if (oldObject.name) {
2153: newObject.name = oldObject.name;
2154: }
2155: if (oldObject.id) {
2156: newObject.id = oldObject.id;
2157: }
2158: oldObject.parentNode.replaceChild(newObject,oldObject);
2159: return;
2160: }
2161:
2162: ENDJS
1.475 www 2163: }
2164:
1.167 www 2165: sub gradeleveldescription {
2166: my $gradelevel=shift;
2167: my %gradelevels=(0 => 'Not specified',
2168: 1 => 'Grade 1',
2169: 2 => 'Grade 2',
2170: 3 => 'Grade 3',
2171: 4 => 'Grade 4',
2172: 5 => 'Grade 5',
2173: 6 => 'Grade 6',
2174: 7 => 'Grade 7',
2175: 8 => 'Grade 8',
2176: 9 => 'Grade 9',
2177: 10 => 'Grade 10',
2178: 11 => 'Grade 11',
2179: 12 => 'Grade 12',
2180: 13 => 'Grade 13',
2181: 14 => '100 Level',
2182: 15 => '200 Level',
2183: 16 => '300 Level',
2184: 17 => '400 Level',
2185: 18 => 'Graduate Level');
2186: return &mt($gradelevels{$gradelevel});
2187: }
2188:
1.163 www 2189: sub select_level_form {
2190: my ($deflevel,$name)=@_;
2191: unless ($deflevel) { $deflevel=0; }
1.167 www 2192: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2193: for (my $i=0; $i<=18; $i++) {
2194: $selectform.="<option value=\"$i\" ".
1.253 albertel 2195: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2196: ">".&gradeleveldescription($i)."</option>\n";
2197: }
2198: $selectform.="</select>";
2199: return $selectform;
1.163 www 2200: }
1.167 www 2201:
1.35 matthew 2202: #-------------------------------------------
2203:
1.45 matthew 2204: =pod
2205:
1.1121 raeburn 2206: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2207:
2208: Returns a string containing a <select name='$name' size='1'> form to
2209: allow a user to select the domain to preform an operation in.
2210: See loncreateuser.pm for an example invocation and use.
2211:
1.90 www 2212: If the $includeempty flag is set, it also includes an empty choice ("no domain
2213: selected");
2214:
1.743 raeburn 2215: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2216:
1.910 raeburn 2217: 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.
2218:
1.1121 raeburn 2219: The optional $incdoms is a reference to an array of domains which will be the only available options.
2220:
2221: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2222:
1.35 matthew 2223: =cut
2224:
2225: #-------------------------------------------
1.34 matthew 2226: sub select_dom_form {
1.1121 raeburn 2227: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2228: if ($onchange) {
1.874 raeburn 2229: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2230: }
1.1121 raeburn 2231: my (@domains,%exclude);
1.910 raeburn 2232: if (ref($incdoms) eq 'ARRAY') {
2233: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2234: } else {
2235: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2236: }
1.90 www 2237: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2238: if (ref($excdoms) eq 'ARRAY') {
2239: map { $exclude{$_} = 1; } @{$excdoms};
2240: }
1.743 raeburn 2241: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2242: foreach my $dom (@domains) {
1.1121 raeburn 2243: next if ($exclude{$dom});
1.356 albertel 2244: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2245: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2246: if ($showdomdesc) {
2247: if ($dom ne '') {
2248: my $domdesc = &Apache::lonnet::domain($dom,'description');
2249: if ($domdesc ne '') {
2250: $selectdomain .= ' ('.$domdesc.')';
2251: }
2252: }
2253: }
2254: $selectdomain .= "</option>\n";
1.34 matthew 2255: }
2256: $selectdomain.="</select>";
2257: return $selectdomain;
2258: }
2259:
1.35 matthew 2260: #-------------------------------------------
2261:
1.45 matthew 2262: =pod
2263:
1.648 raeburn 2264: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2265:
1.586 raeburn 2266: input: 4 arguments (two required, two optional) -
2267: $domain - domain of new user
2268: $name - name of form element
2269: $default - Value of 'default' causes a default item to be first
2270: option, and selected by default.
2271: $hide - Value of 'hide' causes hiding of the name of the server,
2272: if 1 server found, or default, if 0 found.
1.594 raeburn 2273: output: returns 2 items:
1.586 raeburn 2274: (a) form element which contains either:
2275: (i) <select name="$name">
2276: <option value="$hostid1">$hostid $servers{$hostid}</option>
2277: <option value="$hostid2">$hostid $servers{$hostid}</option>
2278: </select>
2279: form item if there are multiple library servers in $domain, or
2280: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2281: if there is only one library server in $domain.
2282:
2283: (b) number of library servers found.
2284:
2285: See loncreateuser.pm for example of use.
1.35 matthew 2286:
2287: =cut
2288:
2289: #-------------------------------------------
1.586 raeburn 2290: sub home_server_form_item {
2291: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2292: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2293: my $result;
2294: my $numlib = keys(%servers);
2295: if ($numlib > 1) {
2296: $result .= '<select name="'.$name.'" />'."\n";
2297: if ($default) {
1.804 bisitz 2298: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2299: '</option>'."\n";
2300: }
2301: foreach my $hostid (sort(keys(%servers))) {
2302: $result.= '<option value="'.$hostid.'">'.
2303: $hostid.' '.$servers{$hostid}."</option>\n";
2304: }
2305: $result .= '</select>'."\n";
2306: } elsif ($numlib == 1) {
2307: my $hostid;
2308: foreach my $item (keys(%servers)) {
2309: $hostid = $item;
2310: }
2311: $result .= '<input type="hidden" name="'.$name.'" value="'.
2312: $hostid.'" />';
2313: if (!$hide) {
2314: $result .= $hostid.' '.$servers{$hostid};
2315: }
2316: $result .= "\n";
2317: } elsif ($default) {
2318: $result .= '<input type="hidden" name="'.$name.
2319: '" value="default" />';
2320: if (!$hide) {
2321: $result .= &mt('default');
2322: }
2323: $result .= "\n";
1.33 matthew 2324: }
1.586 raeburn 2325: return ($result,$numlib);
1.33 matthew 2326: }
1.112 bowersj2 2327:
2328: =pod
2329:
1.534 albertel 2330: =back
2331:
1.112 bowersj2 2332: =cut
1.87 matthew 2333:
2334: ###############################################################
1.112 bowersj2 2335: ## Decoding User Agent ##
1.87 matthew 2336: ###############################################################
2337:
2338: =pod
2339:
1.112 bowersj2 2340: =head1 Decoding the User Agent
2341:
2342: =over 4
2343:
2344: =item * &decode_user_agent()
1.87 matthew 2345:
2346: Inputs: $r
2347:
2348: Outputs:
2349:
2350: =over 4
2351:
1.112 bowersj2 2352: =item * $httpbrowser
1.87 matthew 2353:
1.112 bowersj2 2354: =item * $clientbrowser
1.87 matthew 2355:
1.112 bowersj2 2356: =item * $clientversion
1.87 matthew 2357:
1.112 bowersj2 2358: =item * $clientmathml
1.87 matthew 2359:
1.112 bowersj2 2360: =item * $clientunicode
1.87 matthew 2361:
1.112 bowersj2 2362: =item * $clientos
1.87 matthew 2363:
1.1137 raeburn 2364: =item * $clientmobile
2365:
1.1141 raeburn 2366: =item * $clientinfo
2367:
1.87 matthew 2368: =back
2369:
1.157 matthew 2370: =back
2371:
1.87 matthew 2372: =cut
2373:
2374: ###############################################################
2375: ###############################################################
2376: sub decode_user_agent {
1.247 albertel 2377: my ($r)=@_;
1.87 matthew 2378: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2379: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2380: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2381: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2382: my $clientbrowser='unknown';
2383: my $clientversion='0';
2384: my $clientmathml='';
2385: my $clientunicode='0';
1.1137 raeburn 2386: my $clientmobile=0;
1.87 matthew 2387: for (my $i=0;$i<=$#browsertype;$i++) {
2388: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2389: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2390: $clientbrowser=$bname;
2391: $httpbrowser=~/$vreg/i;
2392: $clientversion=$1;
2393: $clientmathml=($clientversion>=$minv);
2394: $clientunicode=($clientversion>=$univ);
2395: }
2396: }
2397: my $clientos='unknown';
1.1141 raeburn 2398: my $clientinfo;
1.87 matthew 2399: if (($httpbrowser=~/linux/i) ||
2400: ($httpbrowser=~/unix/i) ||
2401: ($httpbrowser=~/ux/i) ||
2402: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2403: if (($httpbrowser=~/vax/i) ||
2404: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2405: if ($httpbrowser=~/next/i) { $clientos='next'; }
2406: if (($httpbrowser=~/mac/i) ||
2407: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2408: if ($httpbrowser=~/win/i) { $clientos='win'; }
2409: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2410: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2411: $clientmobile=lc($1);
2412: }
1.1141 raeburn 2413: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2414: $clientinfo = 'firefox-'.$1;
2415: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2416: $clientinfo = 'chromeframe-'.$1;
2417: }
1.87 matthew 2418: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1141 raeburn 2419: $clientunicode,$clientos,$clientmobile,$clientinfo);
1.87 matthew 2420: }
2421:
1.32 matthew 2422: ###############################################################
2423: ## Authentication changing form generation subroutines ##
2424: ###############################################################
2425: ##
2426: ## All of the authform_xxxxxxx subroutines take their inputs in a
2427: ## hash, and have reasonable default values.
2428: ##
2429: ## formname = the name given in the <form> tag.
1.35 matthew 2430: #-------------------------------------------
2431:
1.45 matthew 2432: =pod
2433:
1.112 bowersj2 2434: =head1 Authentication Routines
2435:
2436: =over 4
2437:
1.648 raeburn 2438: =item * &authform_xxxxxx()
1.35 matthew 2439:
2440: The authform_xxxxxx subroutines provide javascript and html forms which
2441: handle some of the conveniences required for authentication forms.
2442: This is not an optimal method, but it works.
2443:
2444: =over 4
2445:
1.112 bowersj2 2446: =item * authform_header
1.35 matthew 2447:
1.112 bowersj2 2448: =item * authform_authorwarning
1.35 matthew 2449:
1.112 bowersj2 2450: =item * authform_nochange
1.35 matthew 2451:
1.112 bowersj2 2452: =item * authform_kerberos
1.35 matthew 2453:
1.112 bowersj2 2454: =item * authform_internal
1.35 matthew 2455:
1.112 bowersj2 2456: =item * authform_filesystem
1.35 matthew 2457:
2458: =back
2459:
1.648 raeburn 2460: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2461:
1.35 matthew 2462: =cut
2463:
2464: #-------------------------------------------
1.32 matthew 2465: sub authform_header{
2466: my %in = (
2467: formname => 'cu',
1.80 albertel 2468: kerb_def_dom => '',
1.32 matthew 2469: @_,
2470: );
2471: $in{'formname'} = 'document.' . $in{'formname'};
2472: my $result='';
1.80 albertel 2473:
2474: #---------------------------------------------- Code for upper case translation
2475: my $Javascript_toUpperCase;
2476: unless ($in{kerb_def_dom}) {
2477: $Javascript_toUpperCase =<<"END";
2478: switch (choice) {
2479: case 'krb': currentform.elements[choicearg].value =
2480: currentform.elements[choicearg].value.toUpperCase();
2481: break;
2482: default:
2483: }
2484: END
2485: } else {
2486: $Javascript_toUpperCase = "";
2487: }
2488:
1.165 raeburn 2489: my $radioval = "'nochange'";
1.591 raeburn 2490: if (defined($in{'curr_authtype'})) {
2491: if ($in{'curr_authtype'} ne '') {
2492: $radioval = "'".$in{'curr_authtype'}."arg'";
2493: }
1.174 matthew 2494: }
1.165 raeburn 2495: my $argfield = 'null';
1.591 raeburn 2496: if (defined($in{'mode'})) {
1.165 raeburn 2497: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2498: if (defined($in{'curr_autharg'})) {
2499: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2500: $argfield = "'$in{'curr_autharg'}'";
2501: }
2502: }
2503: }
2504: }
2505:
1.32 matthew 2506: $result.=<<"END";
2507: var current = new Object();
1.165 raeburn 2508: current.radiovalue = $radioval;
2509: current.argfield = $argfield;
1.32 matthew 2510:
2511: function changed_radio(choice,currentform) {
2512: var choicearg = choice + 'arg';
2513: // If a radio button in changed, we need to change the argfield
2514: if (current.radiovalue != choice) {
2515: current.radiovalue = choice;
2516: if (current.argfield != null) {
2517: currentform.elements[current.argfield].value = '';
2518: }
2519: if (choice == 'nochange') {
2520: current.argfield = null;
2521: } else {
2522: current.argfield = choicearg;
2523: switch(choice) {
2524: case 'krb':
2525: currentform.elements[current.argfield].value =
2526: "$in{'kerb_def_dom'}";
2527: break;
2528: default:
2529: break;
2530: }
2531: }
2532: }
2533: return;
2534: }
1.22 www 2535:
1.32 matthew 2536: function changed_text(choice,currentform) {
2537: var choicearg = choice + 'arg';
2538: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2539: $Javascript_toUpperCase
1.32 matthew 2540: // clear old field
2541: if ((current.argfield != choicearg) && (current.argfield != null)) {
2542: currentform.elements[current.argfield].value = '';
2543: }
2544: current.argfield = choicearg;
2545: }
2546: set_auth_radio_buttons(choice,currentform);
2547: return;
1.20 www 2548: }
1.32 matthew 2549:
2550: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2551: var numauthchoices = currentform.login.length;
2552: if (typeof numauthchoices == "undefined") {
2553: return;
2554: }
1.32 matthew 2555: var i=0;
1.986 raeburn 2556: while (i < numauthchoices) {
1.32 matthew 2557: if (currentform.login[i].value == newvalue) { break; }
2558: i++;
2559: }
1.986 raeburn 2560: if (i == numauthchoices) {
1.32 matthew 2561: return;
2562: }
2563: current.radiovalue = newvalue;
2564: currentform.login[i].checked = true;
2565: return;
2566: }
2567: END
2568: return $result;
2569: }
2570:
1.1106 raeburn 2571: sub authform_authorwarning {
1.32 matthew 2572: my $result='';
1.144 matthew 2573: $result='<i>'.
2574: &mt('As a general rule, only authors or co-authors should be '.
2575: 'filesystem authenticated '.
2576: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2577: return $result;
2578: }
2579:
1.1106 raeburn 2580: sub authform_nochange {
1.32 matthew 2581: my %in = (
2582: formname => 'document.cu',
2583: kerb_def_dom => 'MSU.EDU',
2584: @_,
2585: );
1.1106 raeburn 2586: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2587: my $result;
1.1104 raeburn 2588: if (!$authnum) {
1.1105 raeburn 2589: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2590: } else {
2591: $result = '<label>'.&mt('[_1] Do not change login data',
2592: '<input type="radio" name="login" value="nochange" '.
2593: 'checked="checked" onclick="'.
1.281 albertel 2594: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2595: '</label>';
1.586 raeburn 2596: }
1.32 matthew 2597: return $result;
2598: }
2599:
1.591 raeburn 2600: sub authform_kerberos {
1.32 matthew 2601: my %in = (
2602: formname => 'document.cu',
2603: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2604: kerb_def_auth => 'krb4',
1.32 matthew 2605: @_,
2606: );
1.586 raeburn 2607: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2608: $autharg,$jscall);
1.1106 raeburn 2609: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2610: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2611: $check5 = ' checked="checked"';
1.80 albertel 2612: } else {
1.772 bisitz 2613: $check4 = ' checked="checked"';
1.80 albertel 2614: }
1.165 raeburn 2615: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2616: if (defined($in{'curr_authtype'})) {
2617: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2618: $krbcheck = ' checked="checked"';
1.623 raeburn 2619: if (defined($in{'mode'})) {
2620: if ($in{'mode'} eq 'modifyuser') {
2621: $krbcheck = '';
2622: }
2623: }
1.591 raeburn 2624: if (defined($in{'curr_kerb_ver'})) {
2625: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2626: $check5 = ' checked="checked"';
1.591 raeburn 2627: $check4 = '';
2628: } else {
1.772 bisitz 2629: $check4 = ' checked="checked"';
1.591 raeburn 2630: $check5 = '';
2631: }
1.586 raeburn 2632: }
1.591 raeburn 2633: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2634: $krbarg = $in{'curr_autharg'};
2635: }
1.586 raeburn 2636: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2637: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2638: $result =
2639: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2640: $in{'curr_autharg'},$krbver);
2641: } else {
2642: $result =
2643: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2644: }
2645: return $result;
2646: }
2647: }
2648: } else {
2649: if ($authnum == 1) {
1.784 bisitz 2650: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2651: }
2652: }
1.586 raeburn 2653: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2654: return;
1.587 raeburn 2655: } elsif ($authtype eq '') {
1.591 raeburn 2656: if (defined($in{'mode'})) {
1.587 raeburn 2657: if ($in{'mode'} eq 'modifycourse') {
2658: if ($authnum == 1) {
1.1104 raeburn 2659: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2660: }
2661: }
2662: }
1.586 raeburn 2663: }
2664: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2665: if ($authtype eq '') {
2666: $authtype = '<input type="radio" name="login" value="krb" '.
2667: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2668: $krbcheck.' />';
2669: }
2670: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 2671: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2672: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 2673: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2674: $in{'curr_authtype'} eq 'krb4')) {
2675: $result .= &mt
1.144 matthew 2676: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2677: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2678: '<label>'.$authtype,
1.281 albertel 2679: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2680: 'value="'.$krbarg.'" '.
1.144 matthew 2681: 'onchange="'.$jscall.'" />',
1.281 albertel 2682: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2683: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2684: '</label>');
1.586 raeburn 2685: } elsif ($can_assign{'krb4'}) {
2686: $result .= &mt
2687: ('[_1] Kerberos authenticated with domain [_2] '.
2688: '[_3] Version 4 [_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="4" />',
2694: '</label>');
2695: } elsif ($can_assign{'krb5'}) {
2696: $result .= &mt
2697: ('[_1] Kerberos authenticated with domain [_2] '.
2698: '[_3] Version 5 [_4]',
2699: '<label>'.$authtype,
2700: '</label><input type="text" size="10" name="krbarg" '.
2701: 'value="'.$krbarg.'" '.
2702: 'onchange="'.$jscall.'" />',
2703: '<label><input type="hidden" name="krbver" value="5" />',
2704: '</label>');
2705: }
1.32 matthew 2706: return $result;
2707: }
2708:
1.1106 raeburn 2709: sub authform_internal {
1.586 raeburn 2710: my %in = (
1.32 matthew 2711: formname => 'document.cu',
2712: kerb_def_dom => 'MSU.EDU',
2713: @_,
2714: );
1.586 raeburn 2715: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2716: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2717: if (defined($in{'curr_authtype'})) {
2718: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2719: if ($can_assign{'int'}) {
1.772 bisitz 2720: $intcheck = 'checked="checked" ';
1.623 raeburn 2721: if (defined($in{'mode'})) {
2722: if ($in{'mode'} eq 'modifyuser') {
2723: $intcheck = '';
2724: }
2725: }
1.591 raeburn 2726: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2727: $intarg = $in{'curr_autharg'};
2728: }
2729: } else {
2730: $result = &mt('Currently internally authenticated.');
2731: return $result;
1.165 raeburn 2732: }
2733: }
1.586 raeburn 2734: } else {
2735: if ($authnum == 1) {
1.784 bisitz 2736: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2737: }
2738: }
2739: if (!$can_assign{'int'}) {
2740: return;
1.587 raeburn 2741: } elsif ($authtype eq '') {
1.591 raeburn 2742: if (defined($in{'mode'})) {
1.587 raeburn 2743: if ($in{'mode'} eq 'modifycourse') {
2744: if ($authnum == 1) {
1.1104 raeburn 2745: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2746: }
2747: }
2748: }
1.165 raeburn 2749: }
1.586 raeburn 2750: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2751: if ($authtype eq '') {
2752: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2753: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2754: }
1.605 bisitz 2755: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2756: $intarg.'" onchange="'.$jscall.'" />';
2757: $result = &mt
1.144 matthew 2758: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2759: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2760: $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 2761: return $result;
2762: }
2763:
1.1104 raeburn 2764: sub authform_local {
1.32 matthew 2765: my %in = (
2766: formname => 'document.cu',
2767: kerb_def_dom => 'MSU.EDU',
2768: @_,
2769: );
1.586 raeburn 2770: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2771: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2772: if (defined($in{'curr_authtype'})) {
2773: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2774: if ($can_assign{'loc'}) {
1.772 bisitz 2775: $loccheck = 'checked="checked" ';
1.623 raeburn 2776: if (defined($in{'mode'})) {
2777: if ($in{'mode'} eq 'modifyuser') {
2778: $loccheck = '';
2779: }
2780: }
1.591 raeburn 2781: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2782: $locarg = $in{'curr_autharg'};
2783: }
2784: } else {
2785: $result = &mt('Currently using local (institutional) authentication.');
2786: return $result;
1.165 raeburn 2787: }
2788: }
1.586 raeburn 2789: } else {
2790: if ($authnum == 1) {
1.784 bisitz 2791: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2792: }
2793: }
2794: if (!$can_assign{'loc'}) {
2795: return;
1.587 raeburn 2796: } elsif ($authtype eq '') {
1.591 raeburn 2797: if (defined($in{'mode'})) {
1.587 raeburn 2798: if ($in{'mode'} eq 'modifycourse') {
2799: if ($authnum == 1) {
1.1104 raeburn 2800: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2801: }
2802: }
2803: }
1.165 raeburn 2804: }
1.586 raeburn 2805: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2806: if ($authtype eq '') {
2807: $authtype = '<input type="radio" name="login" value="loc" '.
2808: $loccheck.' onchange="'.$jscall.'" onclick="'.
2809: $jscall.'" />';
2810: }
2811: $autharg = '<input type="text" size="10" name="locarg" value="'.
2812: $locarg.'" onchange="'.$jscall.'" />';
2813: $result = &mt('[_1] Local Authentication with argument [_2]',
2814: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2815: return $result;
2816: }
2817:
1.1106 raeburn 2818: sub authform_filesystem {
1.32 matthew 2819: my %in = (
2820: formname => 'document.cu',
2821: kerb_def_dom => 'MSU.EDU',
2822: @_,
2823: );
1.586 raeburn 2824: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2825: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2826: if (defined($in{'curr_authtype'})) {
2827: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2828: if ($can_assign{'fsys'}) {
1.772 bisitz 2829: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2830: if (defined($in{'mode'})) {
2831: if ($in{'mode'} eq 'modifyuser') {
2832: $fsyscheck = '';
2833: }
2834: }
1.586 raeburn 2835: } else {
2836: $result = &mt('Currently Filesystem Authenticated.');
2837: return $result;
2838: }
2839: }
2840: } else {
2841: if ($authnum == 1) {
1.784 bisitz 2842: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2843: }
2844: }
2845: if (!$can_assign{'fsys'}) {
2846: return;
1.587 raeburn 2847: } elsif ($authtype eq '') {
1.591 raeburn 2848: if (defined($in{'mode'})) {
1.587 raeburn 2849: if ($in{'mode'} eq 'modifycourse') {
2850: if ($authnum == 1) {
1.1104 raeburn 2851: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2852: }
2853: }
2854: }
1.586 raeburn 2855: }
2856: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2857: if ($authtype eq '') {
2858: $authtype = '<input type="radio" name="login" value="fsys" '.
2859: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2860: $jscall.'" />';
2861: }
2862: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2863: ' onchange="'.$jscall.'" />';
2864: $result = &mt
1.144 matthew 2865: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2866: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2867: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2868: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2869: 'onchange="'.$jscall.'" />');
1.32 matthew 2870: return $result;
2871: }
2872:
1.586 raeburn 2873: sub get_assignable_auth {
2874: my ($dom) = @_;
2875: if ($dom eq '') {
2876: $dom = $env{'request.role.domain'};
2877: }
2878: my %can_assign = (
2879: krb4 => 1,
2880: krb5 => 1,
2881: int => 1,
2882: loc => 1,
2883: );
2884: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2885: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2886: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2887: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2888: my $context;
2889: if ($env{'request.role'} =~ /^au/) {
2890: $context = 'author';
2891: } elsif ($env{'request.role'} =~ /^dc/) {
2892: $context = 'domain';
2893: } elsif ($env{'request.course.id'}) {
2894: $context = 'course';
2895: }
2896: if ($context) {
2897: if (ref($authhash->{$context}) eq 'HASH') {
2898: %can_assign = %{$authhash->{$context}};
2899: }
2900: }
2901: }
2902: }
2903: my $authnum = 0;
2904: foreach my $key (keys(%can_assign)) {
2905: if ($can_assign{$key}) {
2906: $authnum ++;
2907: }
2908: }
2909: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2910: $authnum --;
2911: }
2912: return ($authnum,%can_assign);
2913: }
2914:
1.80 albertel 2915: ###############################################################
2916: ## Get Kerberos Defaults for Domain ##
2917: ###############################################################
2918: ##
2919: ## Returns default kerberos version and an associated argument
2920: ## as listed in file domain.tab. If not listed, provides
2921: ## appropriate default domain and kerberos version.
2922: ##
2923: #-------------------------------------------
2924:
2925: =pod
2926:
1.648 raeburn 2927: =item * &get_kerberos_defaults()
1.80 albertel 2928:
2929: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2930: version and domain. If not found, it defaults to version 4 and the
2931: domain of the server.
1.80 albertel 2932:
1.648 raeburn 2933: =over 4
2934:
1.80 albertel 2935: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2936:
1.648 raeburn 2937: =back
2938:
2939: =back
2940:
1.80 albertel 2941: =cut
2942:
2943: #-------------------------------------------
2944: sub get_kerberos_defaults {
2945: my $domain=shift;
1.641 raeburn 2946: my ($krbdef,$krbdefdom);
2947: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2948: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2949: $krbdef = $domdefaults{'auth_def'};
2950: $krbdefdom = $domdefaults{'auth_arg_def'};
2951: } else {
1.80 albertel 2952: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2953: my $krbdefdom=$1;
2954: $krbdefdom=~tr/a-z/A-Z/;
2955: $krbdef = "krb4";
2956: }
2957: return ($krbdef,$krbdefdom);
2958: }
1.112 bowersj2 2959:
1.32 matthew 2960:
1.46 matthew 2961: ###############################################################
2962: ## Thesaurus Functions ##
2963: ###############################################################
1.20 www 2964:
1.46 matthew 2965: =pod
1.20 www 2966:
1.112 bowersj2 2967: =head1 Thesaurus Functions
2968:
2969: =over 4
2970:
1.648 raeburn 2971: =item * &initialize_keywords()
1.46 matthew 2972:
2973: Initializes the package variable %Keywords if it is empty. Uses the
2974: package variable $thesaurus_db_file.
2975:
2976: =cut
2977:
2978: ###################################################
2979:
2980: sub initialize_keywords {
2981: return 1 if (scalar keys(%Keywords));
2982: # If we are here, %Keywords is empty, so fill it up
2983: # Make sure the file we need exists...
2984: if (! -e $thesaurus_db_file) {
2985: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2986: " failed because it does not exist");
2987: return 0;
2988: }
2989: # Set up the hash as a database
2990: my %thesaurus_db;
2991: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2992: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2993: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2994: $thesaurus_db_file);
2995: return 0;
2996: }
2997: # Get the average number of appearances of a word.
2998: my $avecount = $thesaurus_db{'average.count'};
2999: # Put keywords (those that appear > average) into %Keywords
3000: while (my ($word,$data)=each (%thesaurus_db)) {
3001: my ($count,undef) = split /:/,$data;
3002: $Keywords{$word}++ if ($count > $avecount);
3003: }
3004: untie %thesaurus_db;
3005: # Remove special values from %Keywords.
1.356 albertel 3006: foreach my $value ('total.count','average.count') {
3007: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3008: }
1.46 matthew 3009: return 1;
3010: }
3011:
3012: ###################################################
3013:
3014: =pod
3015:
1.648 raeburn 3016: =item * &keyword($word)
1.46 matthew 3017:
3018: Returns true if $word is a keyword. A keyword is a word that appears more
3019: than the average number of times in the thesaurus database. Calls
3020: &initialize_keywords
3021:
3022: =cut
3023:
3024: ###################################################
1.20 www 3025:
3026: sub keyword {
1.46 matthew 3027: return if (!&initialize_keywords());
3028: my $word=lc(shift());
3029: $word=~s/\W//g;
3030: return exists($Keywords{$word});
1.20 www 3031: }
1.46 matthew 3032:
3033: ###############################################################
3034:
3035: =pod
1.20 www 3036:
1.648 raeburn 3037: =item * &get_related_words()
1.46 matthew 3038:
1.160 matthew 3039: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3040: an array of words. If the keyword is not in the thesaurus, an empty array
3041: will be returned. The order of the words returned is determined by the
3042: database which holds them.
3043:
3044: Uses global $thesaurus_db_file.
3045:
1.1057 foxr 3046:
1.46 matthew 3047: =cut
3048:
3049: ###############################################################
3050: sub get_related_words {
3051: my $keyword = shift;
3052: my %thesaurus_db;
3053: if (! -e $thesaurus_db_file) {
3054: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3055: "failed because the file does not exist");
3056: return ();
3057: }
3058: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3059: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3060: return ();
3061: }
3062: my @Words=();
1.429 www 3063: my $count=0;
1.46 matthew 3064: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3065: # The first element is the number of times
3066: # the word appears. We do not need it now.
1.429 www 3067: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3068: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3069: my $threshold=$mostfrequentcount/10;
3070: foreach my $possibleword (@RelatedWords) {
3071: my ($word,$wordcount)=split(/\,/,$possibleword);
3072: if ($wordcount>$threshold) {
3073: push(@Words,$word);
3074: $count++;
3075: if ($count>10) { last; }
3076: }
1.20 www 3077: }
3078: }
1.46 matthew 3079: untie %thesaurus_db;
3080: return @Words;
1.14 harris41 3081: }
1.1090 foxr 3082: ###############################################################
3083: #
3084: # Spell checking
3085: #
3086:
3087: =pod
3088:
1.1142 raeburn 3089: =back
3090:
1.1090 foxr 3091: =head1 Spell checking
3092:
3093: =over 4
3094:
3095: =item * &check_spelling($wordlist $language)
3096:
3097: Takes a string containing words and feeds it to an external
3098: spellcheck program via a pipeline. Returns a string containing
3099: them mis-spelled words.
3100:
3101: Parameters:
3102:
3103: =over 4
3104:
3105: =item - $wordlist
3106:
3107: String that will be fed into the spellcheck program.
3108:
3109: =item - $language
3110:
3111: Language string that specifies the language for which the spell
3112: check will be performed.
3113:
3114: =back
3115:
3116: =back
3117:
3118: Note: This sub assumes that aspell is installed.
3119:
3120:
3121: =cut
3122:
1.46 matthew 3123:
1.1090 foxr 3124: sub check_spelling {
3125: my ($wordlist, $language) = @_;
1.1091 foxr 3126: my @misspellings;
3127:
3128: # Generate the speller and set the langauge.
3129: # if explicitly selected:
1.1090 foxr 3130:
1.1091 foxr 3131: my $speller = Text::Aspell->new;
1.1090 foxr 3132: if ($language) {
1.1091 foxr 3133: $speller->set_option('lang', $language);
1.1090 foxr 3134: }
3135:
1.1091 foxr 3136: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3137:
1.1091 foxr 3138: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3139:
1.1091 foxr 3140: foreach my $word (@words) {
3141: if(! $speller->check($word)) {
3142: push(@misspellings, $word);
1.1090 foxr 3143: }
3144: }
1.1091 foxr 3145: return join(' ', @misspellings);
3146:
1.1090 foxr 3147: }
3148:
1.61 www 3149: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3150: =pod
3151:
1.112 bowersj2 3152: =head1 User Name Functions
3153:
3154: =over 4
3155:
1.648 raeburn 3156: =item * &plainname($uname,$udom,$first)
1.81 albertel 3157:
1.112 bowersj2 3158: Takes a users logon name and returns it as a string in
1.226 albertel 3159: "first middle last generation" form
3160: if $first is set to 'lastname' then it returns it as
3161: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3162:
3163: =cut
1.61 www 3164:
1.295 www 3165:
1.81 albertel 3166: ###############################################################
1.61 www 3167: sub plainname {
1.226 albertel 3168: my ($uname,$udom,$first)=@_;
1.537 albertel 3169: return if (!defined($uname) || !defined($udom));
1.295 www 3170: my %names=&getnames($uname,$udom);
1.226 albertel 3171: my $name=&Apache::lonnet::format_name($names{'firstname'},
3172: $names{'middlename'},
3173: $names{'lastname'},
3174: $names{'generation'},$first);
3175: $name=~s/^\s+//;
1.62 www 3176: $name=~s/\s+$//;
3177: $name=~s/\s+/ /g;
1.353 albertel 3178: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3179: return $name;
1.61 www 3180: }
1.66 www 3181:
3182: # -------------------------------------------------------------------- Nickname
1.81 albertel 3183: =pod
3184:
1.648 raeburn 3185: =item * &nickname($uname,$udom)
1.81 albertel 3186:
3187: Gets a users name and returns it as a string as
3188:
3189: ""nickname""
1.66 www 3190:
1.81 albertel 3191: if the user has a nickname or
3192:
3193: "first middle last generation"
3194:
3195: if the user does not
3196:
3197: =cut
1.66 www 3198:
3199: sub nickname {
3200: my ($uname,$udom)=@_;
1.537 albertel 3201: return if (!defined($uname) || !defined($udom));
1.295 www 3202: my %names=&getnames($uname,$udom);
1.68 albertel 3203: my $name=$names{'nickname'};
1.66 www 3204: if ($name) {
3205: $name='"'.$name.'"';
3206: } else {
3207: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3208: $names{'lastname'}.' '.$names{'generation'};
3209: $name=~s/\s+$//;
3210: $name=~s/\s+/ /g;
3211: }
3212: return $name;
3213: }
3214:
1.295 www 3215: sub getnames {
3216: my ($uname,$udom)=@_;
1.537 albertel 3217: return if (!defined($uname) || !defined($udom));
1.433 albertel 3218: if ($udom eq 'public' && $uname eq 'public') {
3219: return ('lastname' => &mt('Public'));
3220: }
1.295 www 3221: my $id=$uname.':'.$udom;
3222: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3223: if ($cached) {
3224: return %{$names};
3225: } else {
3226: my %loadnames=&Apache::lonnet::get('environment',
3227: ['firstname','middlename','lastname','generation','nickname'],
3228: $udom,$uname);
3229: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3230: return %loadnames;
3231: }
3232: }
1.61 www 3233:
1.542 raeburn 3234: # -------------------------------------------------------------------- getemails
1.648 raeburn 3235:
1.542 raeburn 3236: =pod
3237:
1.648 raeburn 3238: =item * &getemails($uname,$udom)
1.542 raeburn 3239:
3240: Gets a user's email information and returns it as a hash with keys:
3241: notification, critnotification, permanentemail
3242:
3243: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3244: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3245:
1.648 raeburn 3246:
1.542 raeburn 3247: =cut
3248:
1.648 raeburn 3249:
1.466 albertel 3250: sub getemails {
3251: my ($uname,$udom)=@_;
3252: if ($udom eq 'public' && $uname eq 'public') {
3253: return;
3254: }
1.467 www 3255: if (!$udom) { $udom=$env{'user.domain'}; }
3256: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3257: my $id=$uname.':'.$udom;
3258: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3259: if ($cached) {
3260: return %{$names};
3261: } else {
3262: my %loadnames=&Apache::lonnet::get('environment',
3263: ['notification','critnotification',
3264: 'permanentemail'],
3265: $udom,$uname);
3266: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3267: return %loadnames;
3268: }
3269: }
3270:
1.551 albertel 3271: sub flush_email_cache {
3272: my ($uname,$udom)=@_;
3273: if (!$udom) { $udom =$env{'user.domain'}; }
3274: if (!$uname) { $uname=$env{'user.name'}; }
3275: return if ($udom eq 'public' && $uname eq 'public');
3276: my $id=$uname.':'.$udom;
3277: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3278: }
3279:
1.728 raeburn 3280: # -------------------------------------------------------------------- getlangs
3281:
3282: =pod
3283:
3284: =item * &getlangs($uname,$udom)
3285:
3286: Gets a user's language preference and returns it as a hash with key:
3287: language.
3288:
3289: =cut
3290:
3291:
3292: sub getlangs {
3293: my ($uname,$udom) = @_;
3294: if (!$udom) { $udom =$env{'user.domain'}; }
3295: if (!$uname) { $uname=$env{'user.name'}; }
3296: my $id=$uname.':'.$udom;
3297: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3298: if ($cached) {
3299: return %{$langs};
3300: } else {
3301: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3302: $udom,$uname);
3303: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3304: return %loadlangs;
3305: }
3306: }
3307:
3308: sub flush_langs_cache {
3309: my ($uname,$udom)=@_;
3310: if (!$udom) { $udom =$env{'user.domain'}; }
3311: if (!$uname) { $uname=$env{'user.name'}; }
3312: return if ($udom eq 'public' && $uname eq 'public');
3313: my $id=$uname.':'.$udom;
3314: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3315: }
3316:
1.61 www 3317: # ------------------------------------------------------------------ Screenname
1.81 albertel 3318:
3319: =pod
3320:
1.648 raeburn 3321: =item * &screenname($uname,$udom)
1.81 albertel 3322:
3323: Gets a users screenname and returns it as a string
3324:
3325: =cut
1.61 www 3326:
3327: sub screenname {
3328: my ($uname,$udom)=@_;
1.258 albertel 3329: if ($uname eq $env{'user.name'} &&
3330: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3331: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3332: return $names{'screenname'};
1.62 www 3333: }
3334:
1.212 albertel 3335:
1.802 bisitz 3336: # ------------------------------------------------------------- Confirm Wrapper
3337: =pod
3338:
1.1142 raeburn 3339: =item * &confirmwrapper($message)
1.802 bisitz 3340:
3341: Wrap messages about completion of operation in box
3342:
3343: =cut
3344:
3345: sub confirmwrapper {
3346: my ($message)=@_;
3347: if ($message) {
3348: return "\n".'<div class="LC_confirm_box">'."\n"
3349: .$message."\n"
3350: .'</div>'."\n";
3351: } else {
3352: return $message;
3353: }
3354: }
3355:
1.62 www 3356: # ------------------------------------------------------------- Message Wrapper
3357:
3358: sub messagewrapper {
1.369 www 3359: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3360: return
1.441 albertel 3361: '<a href="/adm/email?compose=individual&'.
3362: 'recname='.$username.'&recdom='.$domain.
3363: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3364: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3365: }
1.802 bisitz 3366:
1.74 www 3367: # --------------------------------------------------------------- Notes Wrapper
3368:
3369: sub noteswrapper {
3370: my ($link,$un,$do)=@_;
3371: return
1.896 amueller 3372: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3373: }
1.802 bisitz 3374:
1.62 www 3375: # ------------------------------------------------------------- Aboutme Wrapper
3376:
3377: sub aboutmewrapper {
1.1070 raeburn 3378: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3379: if (!defined($username) && !defined($domain)) {
3380: return;
3381: }
1.1096 raeburn 3382: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3383: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3384: }
3385:
3386: # ------------------------------------------------------------ Syllabus Wrapper
3387:
3388: sub syllabuswrapper {
1.707 bisitz 3389: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3390: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3391: }
1.14 harris41 3392:
1.802 bisitz 3393: # -----------------------------------------------------------------------------
3394:
1.208 matthew 3395: sub track_student_link {
1.887 raeburn 3396: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3397: my $link ="/adm/trackstudent?";
1.208 matthew 3398: my $title = 'View recent activity';
3399: if (defined($sname) && $sname !~ /^\s*$/ &&
3400: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3401: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3402: $title .= ' of this student';
1.268 albertel 3403: }
1.208 matthew 3404: if (defined($target) && $target !~ /^\s*$/) {
3405: $target = qq{target="$target"};
3406: } else {
3407: $target = '';
3408: }
1.268 albertel 3409: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3410: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3411: $title = &mt($title);
3412: $linktext = &mt($linktext);
1.448 albertel 3413: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3414: &help_open_topic('View_recent_activity');
1.208 matthew 3415: }
3416:
1.781 raeburn 3417: sub slot_reservations_link {
3418: my ($linktext,$sname,$sdom,$target) = @_;
3419: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3420: my $title = 'View slot reservation history';
3421: if (defined($sname) && $sname !~ /^\s*$/ &&
3422: defined($sdom) && $sdom !~ /^\s*$/) {
3423: $link .= "&uname=$sname&udom=$sdom";
3424: $title .= ' of this student';
3425: }
3426: if (defined($target) && $target !~ /^\s*$/) {
3427: $target = qq{target="$target"};
3428: } else {
3429: $target = '';
3430: }
3431: $title = &mt($title);
3432: $linktext = &mt($linktext);
3433: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3434: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3435:
3436: }
3437:
1.508 www 3438: # ===================================================== Display a student photo
3439:
3440:
1.509 albertel 3441: sub student_image_tag {
1.508 www 3442: my ($domain,$user)=@_;
3443: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3444: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3445: return '<img src="'.$imgsrc.'" align="right" />';
3446: } else {
3447: return '';
3448: }
3449: }
3450:
1.112 bowersj2 3451: =pod
3452:
3453: =back
3454:
3455: =head1 Access .tab File Data
3456:
3457: =over 4
3458:
1.648 raeburn 3459: =item * &languageids()
1.112 bowersj2 3460:
3461: returns list of all language ids
3462:
3463: =cut
3464:
1.14 harris41 3465: sub languageids {
1.16 harris41 3466: return sort(keys(%language));
1.14 harris41 3467: }
3468:
1.112 bowersj2 3469: =pod
3470:
1.648 raeburn 3471: =item * &languagedescription()
1.112 bowersj2 3472:
3473: returns description of a specified language id
3474:
3475: =cut
3476:
1.14 harris41 3477: sub languagedescription {
1.125 www 3478: my $code=shift;
3479: return ($supported_language{$code}?'* ':'').
3480: $language{$code}.
1.126 www 3481: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3482: }
3483:
1.1048 foxr 3484: =pod
3485:
3486: =item * &plainlanguagedescription
3487:
3488: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3489: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3490:
3491: =cut
3492:
1.145 www 3493: sub plainlanguagedescription {
3494: my $code=shift;
3495: return $language{$code};
3496: }
3497:
1.1048 foxr 3498: =pod
3499:
3500: =item * &supportedlanguagecode
3501:
3502: Returns the supported language code (e.g. sptutf maps to pt) given a language
3503: code.
3504:
3505: =cut
3506:
1.145 www 3507: sub supportedlanguagecode {
3508: my $code=shift;
3509: return $supported_language{$code};
1.97 www 3510: }
3511:
1.112 bowersj2 3512: =pod
3513:
1.1048 foxr 3514: =item * &latexlanguage()
3515:
3516: Given a language key code returns the correspondnig language to use
3517: to select the correct hyphenation on LaTeX printouts. This is undef if there
3518: is no supported hyphenation for the language code.
3519:
3520: =cut
3521:
3522: sub latexlanguage {
3523: my $code = shift;
3524: return $latex_language{$code};
3525: }
3526:
3527: =pod
3528:
3529: =item * &latexhyphenation()
3530:
3531: Same as above but what's supplied is the language as it might be stored
3532: in the metadata.
3533:
3534: =cut
3535:
3536: sub latexhyphenation {
3537: my $key = shift;
3538: return $latex_language_bykey{$key};
3539: }
3540:
3541: =pod
3542:
1.648 raeburn 3543: =item * ©rightids()
1.112 bowersj2 3544:
3545: returns list of all copyrights
3546:
3547: =cut
3548:
3549: sub copyrightids {
3550: return sort(keys(%cprtag));
3551: }
3552:
3553: =pod
3554:
1.648 raeburn 3555: =item * ©rightdescription()
1.112 bowersj2 3556:
3557: returns description of a specified copyright id
3558:
3559: =cut
3560:
3561: sub copyrightdescription {
1.166 www 3562: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3563: }
1.197 matthew 3564:
3565: =pod
3566:
1.648 raeburn 3567: =item * &source_copyrightids()
1.192 taceyjo1 3568:
3569: returns list of all source copyrights
3570:
3571: =cut
3572:
3573: sub source_copyrightids {
3574: return sort(keys(%scprtag));
3575: }
3576:
3577: =pod
3578:
1.648 raeburn 3579: =item * &source_copyrightdescription()
1.192 taceyjo1 3580:
3581: returns description of a specified source copyright id
3582:
3583: =cut
3584:
3585: sub source_copyrightdescription {
3586: return &mt($scprtag{shift(@_)});
3587: }
1.112 bowersj2 3588:
3589: =pod
3590:
1.648 raeburn 3591: =item * &filecategories()
1.112 bowersj2 3592:
3593: returns list of all file categories
3594:
3595: =cut
3596:
3597: sub filecategories {
3598: return sort(keys(%category_extensions));
3599: }
3600:
3601: =pod
3602:
1.648 raeburn 3603: =item * &filecategorytypes()
1.112 bowersj2 3604:
3605: returns list of file types belonging to a given file
3606: category
3607:
3608: =cut
3609:
3610: sub filecategorytypes {
1.356 albertel 3611: my ($cat) = @_;
3612: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3613: }
3614:
3615: =pod
3616:
1.648 raeburn 3617: =item * &fileembstyle()
1.112 bowersj2 3618:
3619: returns embedding style for a specified file type
3620:
3621: =cut
3622:
3623: sub fileembstyle {
3624: return $fe{lc(shift(@_))};
1.169 www 3625: }
3626:
1.351 www 3627: sub filemimetype {
3628: return $fm{lc(shift(@_))};
3629: }
3630:
1.169 www 3631:
3632: sub filecategoryselect {
3633: my ($name,$value)=@_;
1.189 matthew 3634: return &select_form($value,$name,
1.970 raeburn 3635: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3636: }
3637:
3638: =pod
3639:
1.648 raeburn 3640: =item * &filedescription()
1.112 bowersj2 3641:
3642: returns description for a specified file type
3643:
3644: =cut
3645:
3646: sub filedescription {
1.188 matthew 3647: my $file_description = $fd{lc(shift())};
3648: $file_description =~ s:([\[\]]):~$1:g;
3649: return &mt($file_description);
1.112 bowersj2 3650: }
3651:
3652: =pod
3653:
1.648 raeburn 3654: =item * &filedescriptionex()
1.112 bowersj2 3655:
3656: returns description for a specified file type with
3657: extra formatting
3658:
3659: =cut
3660:
3661: sub filedescriptionex {
3662: my $ex=shift;
1.188 matthew 3663: my $file_description = $fd{lc($ex)};
3664: $file_description =~ s:([\[\]]):~$1:g;
3665: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3666: }
3667:
3668: # End of .tab access
3669: =pod
3670:
3671: =back
3672:
3673: =cut
3674:
3675: # ------------------------------------------------------------------ File Types
3676: sub fileextensions {
3677: return sort(keys(%fe));
3678: }
3679:
1.97 www 3680: # ----------------------------------------------------------- Display Languages
3681: # returns a hash with all desired display languages
3682: #
3683:
3684: sub display_languages {
3685: my %languages=();
1.695 raeburn 3686: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3687: $languages{$lang}=1;
1.97 www 3688: }
3689: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3690: if ($env{'form.displaylanguage'}) {
1.356 albertel 3691: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3692: $languages{$lang}=1;
1.97 www 3693: }
3694: }
3695: return %languages;
1.14 harris41 3696: }
3697:
1.582 albertel 3698: sub languages {
3699: my ($possible_langs) = @_;
1.695 raeburn 3700: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3701: if (!ref($possible_langs)) {
3702: if( wantarray ) {
3703: return @preferred_langs;
3704: } else {
3705: return $preferred_langs[0];
3706: }
3707: }
3708: my %possibilities = map { $_ => 1 } (@$possible_langs);
3709: my @preferred_possibilities;
3710: foreach my $preferred_lang (@preferred_langs) {
3711: if (exists($possibilities{$preferred_lang})) {
3712: push(@preferred_possibilities, $preferred_lang);
3713: }
3714: }
3715: if( wantarray ) {
3716: return @preferred_possibilities;
3717: }
3718: return $preferred_possibilities[0];
3719: }
3720:
1.742 raeburn 3721: sub user_lang {
3722: my ($touname,$toudom,$fromcid) = @_;
3723: my @userlangs;
3724: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3725: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3726: $env{'course.'.$fromcid.'.languages'}));
3727: } else {
3728: my %langhash = &getlangs($touname,$toudom);
3729: if ($langhash{'languages'} ne '') {
3730: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3731: } else {
3732: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3733: if ($domdefs{'lang_def'} ne '') {
3734: @userlangs = ($domdefs{'lang_def'});
3735: }
3736: }
3737: }
3738: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3739: my $user_lh = Apache::localize->get_handle(@languages);
3740: return $user_lh;
3741: }
3742:
3743:
1.112 bowersj2 3744: ###############################################################
3745: ## Student Answer Attempts ##
3746: ###############################################################
3747:
3748: =pod
3749:
3750: =head1 Alternate Problem Views
3751:
3752: =over 4
3753:
1.648 raeburn 3754: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3755: $getattempt, $regexp, $gradesub)
3756:
3757: Return string with previous attempt on problem. Arguments:
3758:
3759: =over 4
3760:
3761: =item * $symb: Problem, including path
3762:
3763: =item * $username: username of the desired student
3764:
3765: =item * $domain: domain of the desired student
1.14 harris41 3766:
1.112 bowersj2 3767: =item * $course: Course ID
1.14 harris41 3768:
1.112 bowersj2 3769: =item * $getattempt: Leave blank for all attempts, otherwise put
3770: something
1.14 harris41 3771:
1.112 bowersj2 3772: =item * $regexp: if string matches this regexp, the string will be
3773: sent to $gradesub
1.14 harris41 3774:
1.112 bowersj2 3775: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3776:
1.112 bowersj2 3777: =back
1.14 harris41 3778:
1.112 bowersj2 3779: The output string is a table containing all desired attempts, if any.
1.16 harris41 3780:
1.112 bowersj2 3781: =cut
1.1 albertel 3782:
3783: sub get_previous_attempt {
1.43 ng 3784: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3785: my $prevattempts='';
1.43 ng 3786: no strict 'refs';
1.1 albertel 3787: if ($symb) {
1.3 albertel 3788: my (%returnhash)=
3789: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3790: if ($returnhash{'version'}) {
3791: my %lasthash=();
3792: my $version;
3793: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3794: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3795: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3796: }
1.1 albertel 3797: }
1.596 albertel 3798: $prevattempts=&start_data_table().&start_data_table_header_row();
3799: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3800: my (%typeparts,%lasthidden);
1.945 raeburn 3801: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3802: foreach my $key (sort(keys(%lasthash))) {
3803: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3804: if ($#parts > 0) {
1.31 albertel 3805: my $data=$parts[-1];
1.989 raeburn 3806: next if ($data eq 'foilorder');
1.31 albertel 3807: pop(@parts);
1.1010 www 3808: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3809: if ($data eq 'type') {
3810: unless ($showsurv) {
3811: my $id = join(',',@parts);
3812: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3813: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3814: $lasthidden{$ign.'.'.$id} = 1;
3815: }
1.945 raeburn 3816: }
1.1010 www 3817: }
1.31 albertel 3818: } else {
1.41 ng 3819: if ($#parts == 0) {
3820: $prevattempts.='<th>'.$parts[0].'</th>';
3821: } else {
3822: $prevattempts.='<th>'.$ign.'</th>';
3823: }
1.31 albertel 3824: }
1.16 harris41 3825: }
1.596 albertel 3826: $prevattempts.=&end_data_table_header_row();
1.40 ng 3827: if ($getattempt eq '') {
3828: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3829: my @hidden;
3830: if (%typeparts) {
3831: foreach my $id (keys(%typeparts)) {
3832: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3833: push(@hidden,$id);
3834: }
3835: }
3836: }
3837: $prevattempts.=&start_data_table_row().
3838: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3839: if (@hidden) {
3840: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3841: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3842: my $hide;
3843: foreach my $id (@hidden) {
3844: if ($key =~ /^\Q$id\E/) {
3845: $hide = 1;
3846: last;
3847: }
3848: }
3849: if ($hide) {
3850: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3851: if (($data eq 'award') || ($data eq 'awarddetail')) {
3852: my $value = &format_previous_attempt_value($key,
3853: $returnhash{$version.':'.$key});
1.1173 kruse 3854: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 3855: } else {
3856: $prevattempts.='<td> </td>';
3857: }
3858: } else {
3859: if ($key =~ /\./) {
3860: my $value = &format_previous_attempt_value($key,
3861: $returnhash{$version.':'.$key});
1.1173 kruse 3862: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 3863: } else {
3864: $prevattempts.='<td> </td>';
3865: }
3866: }
3867: }
3868: } else {
3869: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3870: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3871: my $value = &format_previous_attempt_value($key,
3872: $returnhash{$version.':'.$key});
1.1173 kruse 3873: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 3874: }
3875: }
3876: $prevattempts.=&end_data_table_row();
1.40 ng 3877: }
1.1 albertel 3878: }
1.945 raeburn 3879: my @currhidden = keys(%lasthidden);
1.596 albertel 3880: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3881: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3882: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3883: if (%typeparts) {
3884: my $hidden;
3885: foreach my $id (@currhidden) {
3886: if ($key =~ /^\Q$id\E/) {
3887: $hidden = 1;
3888: last;
3889: }
3890: }
3891: if ($hidden) {
3892: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3893: if (($data eq 'award') || ($data eq 'awarddetail')) {
3894: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3895: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3896: $value = &$gradesub($value);
3897: }
1.1173 kruse 3898: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 3899: } else {
3900: $prevattempts.='<td> </td>';
3901: }
3902: } else {
3903: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3904: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3905: $value = &$gradesub($value);
3906: }
1.1173 kruse 3907: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 3908: }
3909: } else {
3910: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3911: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3912: $value = &$gradesub($value);
3913: }
1.1173 kruse 3914: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 3915: }
1.16 harris41 3916: }
1.596 albertel 3917: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3918: } else {
1.596 albertel 3919: $prevattempts=
3920: &start_data_table().&start_data_table_row().
3921: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3922: &end_data_table_row().&end_data_table();
1.1 albertel 3923: }
3924: } else {
1.596 albertel 3925: $prevattempts=
3926: &start_data_table().&start_data_table_row().
3927: '<td>'.&mt('No data.').'</td>'.
3928: &end_data_table_row().&end_data_table();
1.1 albertel 3929: }
1.10 albertel 3930: }
3931:
1.581 albertel 3932: sub format_previous_attempt_value {
3933: my ($key,$value) = @_;
1.1011 www 3934: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 3935: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 3936: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 3937: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 3938: } elsif ($key =~ /answerstring$/) {
3939: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 3940: my @answer = %answers;
3941: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 3942: my @anskeys = sort(keys(%answers));
3943: if (@anskeys == 1) {
3944: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3945: if ($answer =~ m{\0}) {
3946: $answer =~ s{\0}{,}g;
1.988 raeburn 3947: }
3948: my $tag_internal_answer_name = 'INTERNAL';
3949: if ($anskeys[0] eq $tag_internal_answer_name) {
3950: $value = $answer;
3951: } else {
3952: $value = $anskeys[0].'='.$answer;
3953: }
3954: } else {
3955: foreach my $ans (@anskeys) {
3956: my $answer = $answers{$ans};
1.1001 raeburn 3957: if ($answer =~ m{\0}) {
3958: $answer =~ s{\0}{,}g;
1.988 raeburn 3959: }
3960: $value .= $ans.'='.$answer.'<br />';;
3961: }
3962: }
1.581 albertel 3963: } else {
1.1173 kruse 3964: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 3965: }
3966: return $value;
3967: }
3968:
3969:
1.107 albertel 3970: sub relative_to_absolute {
3971: my ($url,$output)=@_;
3972: my $parser=HTML::TokeParser->new(\$output);
3973: my $token;
3974: my $thisdir=$url;
3975: my @rlinks=();
3976: while ($token=$parser->get_token) {
3977: if ($token->[0] eq 'S') {
3978: if ($token->[1] eq 'a') {
3979: if ($token->[2]->{'href'}) {
3980: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3981: }
3982: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3983: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3984: } elsif ($token->[1] eq 'base') {
3985: $thisdir=$token->[2]->{'href'};
3986: }
3987: }
3988: }
3989: $thisdir=~s-/[^/]*$--;
1.356 albertel 3990: foreach my $link (@rlinks) {
1.726 raeburn 3991: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3992: ($link=~/^\//) ||
3993: ($link=~/^javascript:/i) ||
3994: ($link=~/^mailto:/i) ||
3995: ($link=~/^\#/)) {
3996: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3997: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3998: }
3999: }
4000: # -------------------------------------------------- Deal with Applet codebases
4001: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4002: return $output;
4003: }
4004:
1.112 bowersj2 4005: =pod
4006:
1.648 raeburn 4007: =item * &get_student_view()
1.112 bowersj2 4008:
4009: show a snapshot of what student was looking at
4010:
4011: =cut
4012:
1.10 albertel 4013: sub get_student_view {
1.186 albertel 4014: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4015: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4016: my (%form);
1.10 albertel 4017: my @elements=('symb','courseid','domain','username');
4018: foreach my $element (@elements) {
1.186 albertel 4019: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4020: }
1.186 albertel 4021: if (defined($moreenv)) {
4022: %form=(%form,%{$moreenv});
4023: }
1.236 albertel 4024: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4025: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4026: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4027: $userview=~s/\<body[^\>]*\>//gi;
4028: $userview=~s/\<\/body\>//gi;
4029: $userview=~s/\<html\>//gi;
4030: $userview=~s/\<\/html\>//gi;
4031: $userview=~s/\<head\>//gi;
4032: $userview=~s/\<\/head\>//gi;
4033: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4034: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4035: if (wantarray) {
4036: return ($userview,$response);
4037: } else {
4038: return $userview;
4039: }
4040: }
4041:
4042: sub get_student_view_with_retries {
4043: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4044:
4045: my $ok = 0; # True if we got a good response.
4046: my $content;
4047: my $response;
4048:
4049: # Try to get the student_view done. within the retries count:
4050:
4051: do {
4052: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4053: $ok = $response->is_success;
4054: if (!$ok) {
4055: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4056: }
4057: $retries--;
4058: } while (!$ok && ($retries > 0));
4059:
4060: if (!$ok) {
4061: $content = ''; # On error return an empty content.
4062: }
1.651 www 4063: if (wantarray) {
4064: return ($content, $response);
4065: } else {
4066: return $content;
4067: }
1.11 albertel 4068: }
4069:
1.112 bowersj2 4070: =pod
4071:
1.648 raeburn 4072: =item * &get_student_answers()
1.112 bowersj2 4073:
4074: show a snapshot of how student was answering problem
4075:
4076: =cut
4077:
1.11 albertel 4078: sub get_student_answers {
1.100 sakharuk 4079: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4080: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4081: my (%moreenv);
1.11 albertel 4082: my @elements=('symb','courseid','domain','username');
4083: foreach my $element (@elements) {
1.186 albertel 4084: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4085: }
1.186 albertel 4086: $moreenv{'grade_target'}='answer';
4087: %moreenv=(%form,%moreenv);
1.497 raeburn 4088: $feedurl = &Apache::lonnet::clutter($feedurl);
4089: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4090: return $userview;
1.1 albertel 4091: }
1.116 albertel 4092:
4093: =pod
4094:
4095: =item * &submlink()
4096:
1.242 albertel 4097: Inputs: $text $uname $udom $symb $target
1.116 albertel 4098:
4099: Returns: A link to grades.pm such as to see the SUBM view of a student
4100:
4101: =cut
4102:
4103: ###############################################
4104: sub submlink {
1.242 albertel 4105: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4106: if (!($uname && $udom)) {
4107: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4108: &Apache::lonnet::whichuser($symb);
1.116 albertel 4109: if (!$symb) { $symb=$cursymb; }
4110: }
1.254 matthew 4111: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4112: $symb=&escape($symb);
1.960 bisitz 4113: if ($target) { $target=" target=\"$target\""; }
4114: return
4115: '<a href="/adm/grades?command=submission'.
4116: '&symb='.$symb.
4117: '&student='.$uname.
4118: '&userdom='.$udom.'"'.
4119: $target.'>'.$text.'</a>';
1.242 albertel 4120: }
4121: ##############################################
4122:
4123: =pod
4124:
4125: =item * &pgrdlink()
4126:
4127: Inputs: $text $uname $udom $symb $target
4128:
4129: Returns: A link to grades.pm such as to see the PGRD view of a student
4130:
4131: =cut
4132:
4133: ###############################################
4134: sub pgrdlink {
4135: my $link=&submlink(@_);
4136: $link=~s/(&command=submission)/$1&showgrading=yes/;
4137: return $link;
4138: }
4139: ##############################################
4140:
4141: =pod
4142:
4143: =item * &pprmlink()
4144:
4145: Inputs: $text $uname $udom $symb $target
4146:
4147: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4148: student and a specific resource
1.242 albertel 4149:
4150: =cut
4151:
4152: ###############################################
4153: sub pprmlink {
4154: my ($text,$uname,$udom,$symb,$target)=@_;
4155: if (!($uname && $udom)) {
4156: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4157: &Apache::lonnet::whichuser($symb);
1.242 albertel 4158: if (!$symb) { $symb=$cursymb; }
4159: }
1.254 matthew 4160: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4161: $symb=&escape($symb);
1.242 albertel 4162: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4163: return '<a href="/adm/parmset?command=set&'.
4164: 'symb='.$symb.'&uname='.$uname.
4165: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4166: }
4167: ##############################################
1.37 matthew 4168:
1.112 bowersj2 4169: =pod
4170:
4171: =back
4172:
4173: =cut
4174:
1.37 matthew 4175: ###############################################
1.51 www 4176:
4177:
4178: sub timehash {
1.687 raeburn 4179: my ($thistime) = @_;
4180: my $timezone = &Apache::lonlocal::gettimezone();
4181: my $dt = DateTime->from_epoch(epoch => $thistime)
4182: ->set_time_zone($timezone);
4183: my $wday = $dt->day_of_week();
4184: if ($wday == 7) { $wday = 0; }
4185: return ( 'second' => $dt->second(),
4186: 'minute' => $dt->minute(),
4187: 'hour' => $dt->hour(),
4188: 'day' => $dt->day_of_month(),
4189: 'month' => $dt->month(),
4190: 'year' => $dt->year(),
4191: 'weekday' => $wday,
4192: 'dayyear' => $dt->day_of_year(),
4193: 'dlsav' => $dt->is_dst() );
1.51 www 4194: }
4195:
1.370 www 4196: sub utc_string {
4197: my ($date)=@_;
1.371 www 4198: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4199: }
4200:
1.51 www 4201: sub maketime {
4202: my %th=@_;
1.687 raeburn 4203: my ($epoch_time,$timezone,$dt);
4204: $timezone = &Apache::lonlocal::gettimezone();
4205: eval {
4206: $dt = DateTime->new( year => $th{'year'},
4207: month => $th{'month'},
4208: day => $th{'day'},
4209: hour => $th{'hour'},
4210: minute => $th{'minute'},
4211: second => $th{'second'},
4212: time_zone => $timezone,
4213: );
4214: };
4215: if (!$@) {
4216: $epoch_time = $dt->epoch;
4217: if ($epoch_time) {
4218: return $epoch_time;
4219: }
4220: }
1.51 www 4221: return POSIX::mktime(
4222: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4223: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4224: }
4225:
4226: #########################################
1.51 www 4227:
4228: sub findallcourses {
1.482 raeburn 4229: my ($roles,$uname,$udom) = @_;
1.355 albertel 4230: my %roles;
4231: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4232: my %courses;
1.51 www 4233: my $now=time;
1.482 raeburn 4234: if (!defined($uname)) {
4235: $uname = $env{'user.name'};
4236: }
4237: if (!defined($udom)) {
4238: $udom = $env{'user.domain'};
4239: }
4240: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4241: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4242: if (!%roles) {
4243: %roles = (
4244: cc => 1,
1.907 raeburn 4245: co => 1,
1.482 raeburn 4246: in => 1,
4247: ep => 1,
4248: ta => 1,
4249: cr => 1,
4250: st => 1,
4251: );
4252: }
4253: foreach my $entry (keys(%roleshash)) {
4254: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4255: if ($trole =~ /^cr/) {
4256: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4257: } else {
4258: next if (!exists($roles{$trole}));
4259: }
4260: if ($tend) {
4261: next if ($tend < $now);
4262: }
4263: if ($tstart) {
4264: next if ($tstart > $now);
4265: }
1.1058 raeburn 4266: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4267: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4268: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4269: if ($secpart eq '') {
4270: ($cnum,$role) = split(/_/,$cnumpart);
4271: $sec = 'none';
1.1058 raeburn 4272: $value .= $cnum.'/';
1.482 raeburn 4273: } else {
4274: $cnum = $cnumpart;
4275: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4276: $value .= $cnum.'/'.$sec;
4277: }
4278: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4279: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4280: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4281: }
4282: } else {
4283: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4284: }
1.482 raeburn 4285: }
4286: } else {
4287: foreach my $key (keys(%env)) {
1.483 albertel 4288: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4289: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4290: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4291: next if ($role eq 'ca' || $role eq 'aa');
4292: next if (%roles && !exists($roles{$role}));
4293: my ($starttime,$endtime)=split(/\./,$env{$key});
4294: my $active=1;
4295: if ($starttime) {
4296: if ($now<$starttime) { $active=0; }
4297: }
4298: if ($endtime) {
4299: if ($now>$endtime) { $active=0; }
4300: }
4301: if ($active) {
1.1058 raeburn 4302: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4303: if ($sec eq '') {
4304: $sec = 'none';
1.1058 raeburn 4305: } else {
4306: $value .= $sec;
4307: }
4308: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4309: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4310: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4311: }
4312: } else {
4313: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4314: }
1.474 raeburn 4315: }
4316: }
1.51 www 4317: }
4318: }
1.474 raeburn 4319: return %courses;
1.51 www 4320: }
1.37 matthew 4321:
1.54 www 4322: ###############################################
1.474 raeburn 4323:
4324: sub blockcheck {
1.1062 raeburn 4325: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4326:
4327: if (!defined($udom)) {
4328: $udom = $env{'user.domain'};
4329: }
4330: if (!defined($uname)) {
4331: $uname = $env{'user.name'};
4332: }
4333:
4334: # If uname and udom are for a course, check for blocks in the course.
4335:
4336: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4337: my ($startblock,$endblock,$triggerblock) =
4338: &get_blocks($setters,$activity,$udom,$uname,$url);
4339: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4340: }
1.474 raeburn 4341:
1.502 raeburn 4342: my $startblock = 0;
4343: my $endblock = 0;
1.1062 raeburn 4344: my $triggerblock = '';
1.482 raeburn 4345: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4346:
1.490 raeburn 4347: # If uname is for a user, and activity is course-specific, i.e.,
4348: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4349:
1.490 raeburn 4350: if (($activity eq 'boards' || $activity eq 'chat' ||
4351: $activity eq 'groups') && ($env{'request.course.id'})) {
4352: foreach my $key (keys(%live_courses)) {
4353: if ($key ne $env{'request.course.id'}) {
4354: delete($live_courses{$key});
4355: }
4356: }
4357: }
4358:
4359: my $otheruser = 0;
4360: my %own_courses;
4361: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4362: # Resource belongs to user other than current user.
4363: $otheruser = 1;
4364: # Gather courses for current user
4365: %own_courses =
4366: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4367: }
4368:
4369: # Gather active course roles - course coordinator, instructor,
4370: # exam proctor, ta, student, or custom role.
1.474 raeburn 4371:
4372: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4373: my ($cdom,$cnum);
4374: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4375: $cdom = $env{'course.'.$course.'.domain'};
4376: $cnum = $env{'course.'.$course.'.num'};
4377: } else {
1.490 raeburn 4378: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4379: }
4380: my $no_ownblock = 0;
4381: my $no_userblock = 0;
1.533 raeburn 4382: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4383: # Check if current user has 'evb' priv for this
4384: if (defined($own_courses{$course})) {
4385: foreach my $sec (keys(%{$own_courses{$course}})) {
4386: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4387: if ($sec ne 'none') {
4388: $checkrole .= '/'.$sec;
4389: }
4390: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4391: $no_ownblock = 1;
4392: last;
4393: }
4394: }
4395: }
4396: # if they have 'evb' priv and are currently not playing student
4397: next if (($no_ownblock) &&
4398: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4399: }
1.474 raeburn 4400: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4401: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4402: if ($sec ne 'none') {
1.482 raeburn 4403: $checkrole .= '/'.$sec;
1.474 raeburn 4404: }
1.490 raeburn 4405: if ($otheruser) {
4406: # Resource belongs to user other than current user.
4407: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4408: my (%allroles,%userroles);
4409: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4410: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4411: my ($trole,$tdom,$tnum,$tsec);
4412: if ($entry =~ /^cr/) {
4413: ($trole,$tdom,$tnum,$tsec) =
4414: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4415: } else {
4416: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4417: }
4418: my ($spec,$area,$trest);
4419: $area = '/'.$tdom.'/'.$tnum;
4420: $trest = $tnum;
4421: if ($tsec ne '') {
4422: $area .= '/'.$tsec;
4423: $trest .= '/'.$tsec;
4424: }
4425: $spec = $trole.'.'.$area;
4426: if ($trole =~ /^cr/) {
4427: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4428: $tdom,$spec,$trest,$area);
4429: } else {
4430: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4431: $tdom,$spec,$trest,$area);
4432: }
4433: }
4434: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4435: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4436: if ($1) {
4437: $no_userblock = 1;
4438: last;
4439: }
1.486 raeburn 4440: }
4441: }
1.490 raeburn 4442: } else {
4443: # Resource belongs to current user
4444: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4445: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4446: $no_ownblock = 1;
4447: last;
4448: }
1.474 raeburn 4449: }
4450: }
4451: # if they have the evb priv and are currently not playing student
1.482 raeburn 4452: next if (($no_ownblock) &&
1.491 albertel 4453: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4454: next if ($no_userblock);
1.474 raeburn 4455:
1.866 kalberla 4456: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4457: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4458:
1.1062 raeburn 4459: my ($start,$end,$trigger) =
4460: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4461: if (($start != 0) &&
4462: (($startblock == 0) || ($startblock > $start))) {
4463: $startblock = $start;
1.1062 raeburn 4464: if ($trigger ne '') {
4465: $triggerblock = $trigger;
4466: }
1.502 raeburn 4467: }
4468: if (($end != 0) &&
4469: (($endblock == 0) || ($endblock < $end))) {
4470: $endblock = $end;
1.1062 raeburn 4471: if ($trigger ne '') {
4472: $triggerblock = $trigger;
4473: }
1.502 raeburn 4474: }
1.490 raeburn 4475: }
1.1062 raeburn 4476: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4477: }
4478:
4479: sub get_blocks {
1.1062 raeburn 4480: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4481: my $startblock = 0;
4482: my $endblock = 0;
1.1062 raeburn 4483: my $triggerblock = '';
1.490 raeburn 4484: my $course = $cdom.'_'.$cnum;
4485: $setters->{$course} = {};
4486: $setters->{$course}{'staff'} = [];
4487: $setters->{$course}{'times'} = [];
1.1062 raeburn 4488: $setters->{$course}{'triggers'} = [];
4489: my (@blockers,%triggered);
4490: my $now = time;
4491: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4492: if ($activity eq 'docs') {
4493: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4494: foreach my $block (@blockers) {
4495: if ($block =~ /^firstaccess____(.+)$/) {
4496: my $item = $1;
4497: my $type = 'map';
4498: my $timersymb = $item;
4499: if ($item eq 'course') {
4500: $type = 'course';
4501: } elsif ($item =~ /___\d+___/) {
4502: $type = 'resource';
4503: } else {
4504: $timersymb = &Apache::lonnet::symbread($item);
4505: }
4506: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4507: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4508: $triggered{$block} = {
4509: start => $start,
4510: end => $end,
4511: type => $type,
4512: };
4513: }
4514: }
4515: } else {
4516: foreach my $block (keys(%commblocks)) {
4517: if ($block =~ m/^(\d+)____(\d+)$/) {
4518: my ($start,$end) = ($1,$2);
4519: if ($start <= time && $end >= time) {
4520: if (ref($commblocks{$block}) eq 'HASH') {
4521: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4522: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4523: unless(grep(/^\Q$block\E$/,@blockers)) {
4524: push(@blockers,$block);
4525: }
4526: }
4527: }
4528: }
4529: }
4530: } elsif ($block =~ /^firstaccess____(.+)$/) {
4531: my $item = $1;
4532: my $timersymb = $item;
4533: my $type = 'map';
4534: if ($item eq 'course') {
4535: $type = 'course';
4536: } elsif ($item =~ /___\d+___/) {
4537: $type = 'resource';
4538: } else {
4539: $timersymb = &Apache::lonnet::symbread($item);
4540: }
4541: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4542: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4543: if ($start && $end) {
4544: if (($start <= time) && ($end >= time)) {
4545: unless (grep(/^\Q$block\E$/,@blockers)) {
4546: push(@blockers,$block);
4547: $triggered{$block} = {
4548: start => $start,
4549: end => $end,
4550: type => $type,
4551: };
4552: }
4553: }
1.490 raeburn 4554: }
1.1062 raeburn 4555: }
4556: }
4557: }
4558: foreach my $blocker (@blockers) {
4559: my ($staff_name,$staff_dom,$title,$blocks) =
4560: &parse_block_record($commblocks{$blocker});
4561: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4562: my ($start,$end,$triggertype);
4563: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4564: ($start,$end) = ($1,$2);
4565: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4566: $start = $triggered{$blocker}{'start'};
4567: $end = $triggered{$blocker}{'end'};
4568: $triggertype = $triggered{$blocker}{'type'};
4569: }
4570: if ($start) {
4571: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4572: if ($triggertype) {
4573: push(@{$$setters{$course}{'triggers'}},$triggertype);
4574: } else {
4575: push(@{$$setters{$course}{'triggers'}},0);
4576: }
4577: if ( ($startblock == 0) || ($startblock > $start) ) {
4578: $startblock = $start;
4579: if ($triggertype) {
4580: $triggerblock = $blocker;
1.474 raeburn 4581: }
4582: }
1.1062 raeburn 4583: if ( ($endblock == 0) || ($endblock < $end) ) {
4584: $endblock = $end;
4585: if ($triggertype) {
4586: $triggerblock = $blocker;
4587: }
4588: }
1.474 raeburn 4589: }
4590: }
1.1062 raeburn 4591: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4592: }
4593:
4594: sub parse_block_record {
4595: my ($record) = @_;
4596: my ($setuname,$setudom,$title,$blocks);
4597: if (ref($record) eq 'HASH') {
4598: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4599: $title = &unescape($record->{'event'});
4600: $blocks = $record->{'blocks'};
4601: } else {
4602: my @data = split(/:/,$record,3);
4603: if (scalar(@data) eq 2) {
4604: $title = $data[1];
4605: ($setuname,$setudom) = split(/@/,$data[0]);
4606: } else {
4607: ($setuname,$setudom,$title) = @data;
4608: }
4609: $blocks = { 'com' => 'on' };
4610: }
4611: return ($setuname,$setudom,$title,$blocks);
4612: }
4613:
1.854 kalberla 4614: sub blocking_status {
1.1062 raeburn 4615: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4616: my %setters;
1.890 droeschl 4617:
1.1061 raeburn 4618: # check for active blocking
1.1062 raeburn 4619: my ($startblock,$endblock,$triggerblock) =
4620: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4621: my $blocked = 0;
4622: if ($startblock && $endblock) {
4623: $blocked = 1;
4624: }
1.890 droeschl 4625:
1.1061 raeburn 4626: # caller just wants to know whether a block is active
4627: if (!wantarray) { return $blocked; }
4628:
4629: # build a link to a popup window containing the details
4630: my $querystring = "?activity=$activity";
4631: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4632: if ($activity eq 'port') {
4633: $querystring .= "&udom=$udom" if $udom;
4634: $querystring .= "&uname=$uname" if $uname;
4635: } elsif ($activity eq 'docs') {
4636: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4637: }
1.1061 raeburn 4638:
4639: my $output .= <<'END_MYBLOCK';
4640: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4641: var options = "width=" + w + ",height=" + h + ",";
4642: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4643: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4644: var newWin = window.open(url, wdwName, options);
4645: newWin.focus();
4646: }
1.890 droeschl 4647: END_MYBLOCK
1.854 kalberla 4648:
1.1061 raeburn 4649: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4650:
1.1061 raeburn 4651: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4652: my $text = &mt('Communication Blocked');
4653: if ($activity eq 'docs') {
4654: $text = &mt('Content Access Blocked');
1.1063 raeburn 4655: } elsif ($activity eq 'printout') {
4656: $text = &mt('Printing Blocked');
1.1062 raeburn 4657: }
1.1061 raeburn 4658: $output .= <<"END_BLOCK";
1.867 kalberla 4659: <div class='LC_comblock'>
1.869 kalberla 4660: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4661: title='$text'>
4662: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4663: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4664: title='$text'>$text</a>
1.867 kalberla 4665: </div>
4666:
4667: END_BLOCK
1.474 raeburn 4668:
1.1061 raeburn 4669: return ($blocked, $output);
1.854 kalberla 4670: }
1.490 raeburn 4671:
1.60 matthew 4672: ###############################################
4673:
1.682 raeburn 4674: sub check_ip_acc {
4675: my ($acc)=@_;
4676: &Apache::lonxml::debug("acc is $acc");
4677: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4678: return 1;
4679: }
4680: my $allowed=0;
4681: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4682:
4683: my $name;
4684: foreach my $pattern (split(',',$acc)) {
4685: $pattern =~ s/^\s*//;
4686: $pattern =~ s/\s*$//;
4687: if ($pattern =~ /\*$/) {
4688: #35.8.*
4689: $pattern=~s/\*//;
4690: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4691: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4692: #35.8.3.[34-56]
4693: my $low=$2;
4694: my $high=$3;
4695: $pattern=$1;
4696: if ($ip =~ /^\Q$pattern\E/) {
4697: my $last=(split(/\./,$ip))[3];
4698: if ($last <=$high && $last >=$low) { $allowed=1; }
4699: }
4700: } elsif ($pattern =~ /^\*/) {
4701: #*.msu.edu
4702: $pattern=~s/\*//;
4703: if (!defined($name)) {
4704: use Socket;
4705: my $netaddr=inet_aton($ip);
4706: ($name)=gethostbyaddr($netaddr,AF_INET);
4707: }
4708: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4709: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4710: #127.0.0.1
4711: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4712: } else {
4713: #some.name.com
4714: if (!defined($name)) {
4715: use Socket;
4716: my $netaddr=inet_aton($ip);
4717: ($name)=gethostbyaddr($netaddr,AF_INET);
4718: }
4719: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4720: }
4721: if ($allowed) { last; }
4722: }
4723: return $allowed;
4724: }
4725:
4726: ###############################################
4727:
1.60 matthew 4728: =pod
4729:
1.112 bowersj2 4730: =head1 Domain Template Functions
4731:
4732: =over 4
4733:
4734: =item * &determinedomain()
1.60 matthew 4735:
4736: Inputs: $domain (usually will be undef)
4737:
1.63 www 4738: Returns: Determines which domain should be used for designs
1.60 matthew 4739:
4740: =cut
1.54 www 4741:
1.60 matthew 4742: ###############################################
1.63 www 4743: sub determinedomain {
4744: my $domain=shift;
1.531 albertel 4745: if (! $domain) {
1.60 matthew 4746: # Determine domain if we have not been given one
1.893 raeburn 4747: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4748: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4749: if ($env{'request.role.domain'}) {
4750: $domain=$env{'request.role.domain'};
1.60 matthew 4751: }
4752: }
1.63 www 4753: return $domain;
4754: }
4755: ###############################################
1.517 raeburn 4756:
1.518 albertel 4757: sub devalidate_domconfig_cache {
4758: my ($udom)=@_;
4759: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4760: }
4761:
4762: # ---------------------- Get domain configuration for a domain
4763: sub get_domainconf {
4764: my ($udom) = @_;
4765: my $cachetime=1800;
4766: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4767: if (defined($cached)) { return %{$result}; }
4768:
4769: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4770: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4771: my (%designhash,%legacy);
1.518 albertel 4772: if (keys(%domconfig) > 0) {
4773: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4774: if (keys(%{$domconfig{'login'}})) {
4775: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4776: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4777: if ($key eq 'loginvia') {
4778: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4779: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4780: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4781: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4782: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4783: $designhash{$udom.'.login.loginvia'} = $server;
4784: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4785:
4786: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4787: } else {
1.1013 raeburn 4788: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4789: }
4790: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4791: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4792: }
1.946 raeburn 4793: }
4794: }
4795: }
4796: }
4797: } else {
4798: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4799: $designhash{$udom.'.login.'.$key.'_'.$img} =
4800: $domconfig{'login'}{$key}{$img};
4801: }
1.699 raeburn 4802: }
4803: } else {
4804: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4805: }
1.632 raeburn 4806: }
4807: } else {
4808: $legacy{'login'} = 1;
1.518 albertel 4809: }
1.632 raeburn 4810: } else {
4811: $legacy{'login'} = 1;
1.518 albertel 4812: }
4813: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4814: if (keys(%{$domconfig{'rolecolors'}})) {
4815: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4816: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4817: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4818: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4819: }
1.518 albertel 4820: }
4821: }
1.632 raeburn 4822: } else {
4823: $legacy{'rolecolors'} = 1;
1.518 albertel 4824: }
1.632 raeburn 4825: } else {
4826: $legacy{'rolecolors'} = 1;
1.518 albertel 4827: }
1.948 raeburn 4828: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4829: if ($domconfig{'autoenroll'}{'co-owners'}) {
4830: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4831: }
4832: }
1.632 raeburn 4833: if (keys(%legacy) > 0) {
4834: my %legacyhash = &get_legacy_domconf($udom);
4835: foreach my $item (keys(%legacyhash)) {
4836: if ($item =~ /^\Q$udom\E\.login/) {
4837: if ($legacy{'login'}) {
4838: $designhash{$item} = $legacyhash{$item};
4839: }
4840: } else {
4841: if ($legacy{'rolecolors'}) {
4842: $designhash{$item} = $legacyhash{$item};
4843: }
1.518 albertel 4844: }
4845: }
4846: }
1.632 raeburn 4847: } else {
4848: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4849: }
4850: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4851: $cachetime);
4852: return %designhash;
4853: }
4854:
1.632 raeburn 4855: sub get_legacy_domconf {
4856: my ($udom) = @_;
4857: my %legacyhash;
4858: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4859: my $designfile = $designdir.'/'.$udom.'.tab';
4860: if (-e $designfile) {
4861: if ( open (my $fh,"<$designfile") ) {
4862: while (my $line = <$fh>) {
4863: next if ($line =~ /^\#/);
4864: chomp($line);
4865: my ($key,$val)=(split(/\=/,$line));
4866: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4867: }
4868: close($fh);
4869: }
4870: }
1.1026 raeburn 4871: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4872: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4873: }
4874: return %legacyhash;
4875: }
4876:
1.63 www 4877: =pod
4878:
1.112 bowersj2 4879: =item * &domainlogo()
1.63 www 4880:
4881: Inputs: $domain (usually will be undef)
4882:
4883: Returns: A link to a domain logo, if the domain logo exists.
4884: If the domain logo does not exist, a description of the domain.
4885:
4886: =cut
1.112 bowersj2 4887:
1.63 www 4888: ###############################################
4889: sub domainlogo {
1.517 raeburn 4890: my $domain = &determinedomain(shift);
1.518 albertel 4891: my %designhash = &get_domainconf($domain);
1.517 raeburn 4892: # See if there is a logo
4893: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4894: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4895: if ($imgsrc =~ m{^/(adm|res)/}) {
4896: if ($imgsrc =~ m{^/res/}) {
4897: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4898: &Apache::lonnet::repcopy($local_name);
4899: }
4900: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4901: }
4902: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4903: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4904: return &Apache::lonnet::domain($domain,'description');
1.59 www 4905: } else {
1.60 matthew 4906: return '';
1.59 www 4907: }
4908: }
1.63 www 4909: ##############################################
4910:
4911: =pod
4912:
1.112 bowersj2 4913: =item * &designparm()
1.63 www 4914:
4915: Inputs: $which parameter; $domain (usually will be undef)
4916:
4917: Returns: value of designparamter $which
4918:
4919: =cut
1.112 bowersj2 4920:
1.397 albertel 4921:
1.400 albertel 4922: ##############################################
1.397 albertel 4923: sub designparm {
4924: my ($which,$domain)=@_;
4925: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4926: return $env{'environment.color.'.$which};
1.96 www 4927: }
1.63 www 4928: $domain=&determinedomain($domain);
1.1016 raeburn 4929: my %domdesign;
4930: unless ($domain eq 'public') {
4931: %domdesign = &get_domainconf($domain);
4932: }
1.520 raeburn 4933: my $output;
1.517 raeburn 4934: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4935: $output = $domdesign{$domain.'.'.$which};
1.63 www 4936: } else {
1.520 raeburn 4937: $output = $defaultdesign{$which};
4938: }
4939: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4940: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4941: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4942: if ($output =~ m{^/res/}) {
4943: my $local_name = &Apache::lonnet::filelocation('',$output);
4944: &Apache::lonnet::repcopy($local_name);
4945: }
1.520 raeburn 4946: $output = &lonhttpdurl($output);
4947: }
1.63 www 4948: }
1.520 raeburn 4949: return $output;
1.63 www 4950: }
1.59 www 4951:
1.822 bisitz 4952: ##############################################
4953: =pod
4954:
1.832 bisitz 4955: =item * &authorspace()
4956:
1.1028 raeburn 4957: Inputs: $url (usually will be undef).
1.832 bisitz 4958:
1.1132 raeburn 4959: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4960: directory being viewed (or for which action is being taken).
4961: If $url is provided, and begins /priv/<domain>/<uname>
4962: the path will be that portion of the $context argument.
4963: Otherwise the path will be for the author space of the current
4964: user when the current role is author, or for that of the
4965: co-author/assistant co-author space when the current role
4966: is co-author or assistant co-author.
1.832 bisitz 4967:
4968: =cut
4969:
4970: sub authorspace {
1.1028 raeburn 4971: my ($url) = @_;
4972: if ($url ne '') {
4973: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4974: return $1;
4975: }
4976: }
1.832 bisitz 4977: my $caname = '';
1.1024 www 4978: my $cadom = '';
1.1028 raeburn 4979: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4980: ($cadom,$caname) =
1.832 bisitz 4981: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4982: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4983: $caname = $env{'user.name'};
1.1024 www 4984: $cadom = $env{'user.domain'};
1.832 bisitz 4985: }
1.1028 raeburn 4986: if (($caname ne '') && ($cadom ne '')) {
4987: return "/priv/$cadom/$caname/";
4988: }
4989: return;
1.832 bisitz 4990: }
4991:
4992: ##############################################
4993: =pod
4994:
1.822 bisitz 4995: =item * &head_subbox()
4996:
4997: Inputs: $content (contains HTML code with page functions, etc.)
4998:
4999: Returns: HTML div with $content
5000: To be included in page header
5001:
5002: =cut
5003:
5004: sub head_subbox {
5005: my ($content)=@_;
5006: my $output =
1.993 raeburn 5007: '<div class="LC_head_subbox">'
1.822 bisitz 5008: .$content
5009: .'</div>'
5010: }
5011:
5012: ##############################################
5013: =pod
5014:
5015: =item * &CSTR_pageheader()
5016:
1.1026 raeburn 5017: Input: (optional) filename from which breadcrumb trail is built.
5018: In most cases no input as needed, as $env{'request.filename'}
5019: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5020:
5021: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5022: To be included on Authoring Space pages
1.822 bisitz 5023:
5024: =cut
5025:
5026: sub CSTR_pageheader {
1.1026 raeburn 5027: my ($trailfile) = @_;
5028: if ($trailfile eq '') {
5029: $trailfile = $env{'request.filename'};
5030: }
5031:
5032: # this is for resources; directories have customtitle, and crumbs
5033: # and select recent are created in lonpubdir.pm
5034:
5035: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5036: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5037: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5038: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5039: $formaction =~ s{/+}{/}g;
1.822 bisitz 5040:
5041: my $parentpath = '';
5042: my $lastitem = '';
5043: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5044: $parentpath = $1;
5045: $lastitem = $2;
5046: } else {
5047: $lastitem = $thisdisfn;
5048: }
1.921 bisitz 5049:
5050: my $output =
1.822 bisitz 5051: '<div>'
5052: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1132 raeburn 5053: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5054: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5055: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5056: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5057:
5058: if ($lastitem) {
5059: $output .=
5060: '<span class="LC_filename">'
5061: .$lastitem
5062: .'</span>';
5063: }
5064: $output .=
5065: '<br />'
1.822 bisitz 5066: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5067: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5068: .'</form>'
5069: .&Apache::lonmenu::constspaceform()
5070: .'</div>';
1.921 bisitz 5071:
5072: return $output;
1.822 bisitz 5073: }
5074:
1.60 matthew 5075: ###############################################
5076: ###############################################
5077:
5078: =pod
5079:
1.112 bowersj2 5080: =back
5081:
1.549 albertel 5082: =head1 HTML Helpers
1.112 bowersj2 5083:
5084: =over 4
5085:
5086: =item * &bodytag()
1.60 matthew 5087:
5088: Returns a uniform header for LON-CAPA web pages.
5089:
5090: Inputs:
5091:
1.112 bowersj2 5092: =over 4
5093:
5094: =item * $title, A title to be displayed on the page.
5095:
5096: =item * $function, the current role (can be undef).
5097:
5098: =item * $addentries, extra parameters for the <body> tag.
5099:
5100: =item * $bodyonly, if defined, only return the <body> tag.
5101:
5102: =item * $domain, if defined, force a given domain.
5103:
5104: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5105: text interface only)
1.60 matthew 5106:
1.814 bisitz 5107: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5108: navigational links
1.317 albertel 5109:
1.338 albertel 5110: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5111:
1.460 albertel 5112: =item * $args, optional argument valid values are
5113: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5114: inherit_jsmath -> when creating popup window in a page,
5115: should it have jsmath forced on by the
5116: current page
1.460 albertel 5117:
1.1096 raeburn 5118: =item * $advtoolsref, optional argument, ref to an array containing
5119: inlineremote items to be added in "Functions" menu below
5120: breadcrumbs.
5121:
1.112 bowersj2 5122: =back
5123:
1.60 matthew 5124: Returns: A uniform header for LON-CAPA web pages.
5125: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5126: If $bodyonly is undef or zero, an html string containing a <body> tag and
5127: other decorations will be returned.
5128:
5129: =cut
5130:
1.54 www 5131: sub bodytag {
1.831 bisitz 5132: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5133: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5134:
1.954 raeburn 5135: my $public;
5136: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5137: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5138: $public = 1;
5139: }
1.460 albertel 5140: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5141: my $httphost = $args->{'use_absolute'};
1.339 albertel 5142:
1.183 matthew 5143: $function = &get_users_function() if (!$function);
1.339 albertel 5144: my $img = &designparm($function.'.img',$domain);
5145: my $font = &designparm($function.'.font',$domain);
5146: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5147:
1.803 bisitz 5148: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5149: 'bgcolor' => $pgbg,
1.339 albertel 5150: 'text' => $font,
5151: 'alink' => &designparm($function.'.alink',$domain),
5152: 'vlink' => &designparm($function.'.vlink',$domain),
5153: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5154: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5155:
1.63 www 5156: # role and realm
1.1178 raeburn 5157: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5158: if ($realm) {
5159: $realm = '/'.$realm;
5160: }
1.378 raeburn 5161: if ($role eq 'ca') {
1.479 albertel 5162: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5163: $realm = &plainname($rname,$rdom);
1.378 raeburn 5164: }
1.55 www 5165: # realm
1.258 albertel 5166: if ($env{'request.course.id'}) {
1.378 raeburn 5167: if ($env{'request.role'} !~ /^cr/) {
5168: $role = &Apache::lonnet::plaintext($role,&course_type());
5169: }
1.898 raeburn 5170: if ($env{'request.course.sec'}) {
5171: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5172: }
1.359 albertel 5173: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5174: } else {
5175: $role = &Apache::lonnet::plaintext($role);
1.54 www 5176: }
1.433 albertel 5177:
1.359 albertel 5178: if (!$realm) { $realm=' '; }
1.330 albertel 5179:
1.438 albertel 5180: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5181:
1.101 www 5182: # construct main body tag
1.359 albertel 5183: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5184: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5185:
1.1131 raeburn 5186: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5187:
1.1130 raeburn 5188: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5189: return $bodytag;
1.1130 raeburn 5190: }
1.359 albertel 5191:
1.954 raeburn 5192: if ($public) {
1.433 albertel 5193: undef($role);
5194: }
1.359 albertel 5195:
1.762 bisitz 5196: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5197: #
5198: # Extra info if you are the DC
5199: my $dc_info = '';
5200: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5201: $env{'course.'.$env{'request.course.id'}.
5202: '.domain'}.'/'})) {
5203: my $cid = $env{'request.course.id'};
1.917 raeburn 5204: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5205: $dc_info =~ s/\s+$//;
1.359 albertel 5206: }
5207:
1.898 raeburn 5208: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5209:
1.903 droeschl 5210: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5211:
5212: # if ($env{'request.state'} eq 'construct') {
5213: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5214: # }
5215:
1.1130 raeburn 5216: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 5217: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5218:
1.1130 raeburn 5219: my ($left,$right) = Apache::lonmenu::primary_menu();
1.359 albertel 5220:
1.916 droeschl 5221: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5222: if ($dc_info) {
5223: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5224: }
1.1130 raeburn 5225: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5226: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5227: return $bodytag;
5228: }
1.894 droeschl 5229:
1.927 raeburn 5230: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5231: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5232: }
1.916 droeschl 5233:
1.1130 raeburn 5234: $bodytag .= $right;
1.852 droeschl 5235:
1.917 raeburn 5236: if ($dc_info) {
5237: $dc_info = &dc_courseid_toggle($dc_info);
5238: }
5239: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5240:
1.1169 raeburn 5241: #if directed to not display the secondary menu, don't.
1.1168 raeburn 5242: if ($args->{'no_secondary_menu'}) {
5243: return $bodytag;
5244: }
1.1169 raeburn 5245: #don't show menus for public users
1.954 raeburn 5246: if (!$public){
1.1154 raeburn 5247: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5248: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5249: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5250: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5251: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5252: $args->{'bread_crumbs'});
1.1096 raeburn 5253: } elsif ($forcereg) {
5254: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5255: $args->{'group'});
5256: } else {
5257: $bodytag .=
5258: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5259: $forcereg,$args->{'group'},
5260: $args->{'bread_crumbs'},
5261: $advtoolsref);
1.920 raeburn 5262: }
1.903 droeschl 5263: }else{
5264: # this is to seperate menu from content when there's no secondary
5265: # menu. Especially needed for public accessible ressources.
5266: $bodytag .= '<hr style="clear:both" />';
5267: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5268: }
1.903 droeschl 5269:
1.235 raeburn 5270: return $bodytag;
1.182 matthew 5271: }
5272:
1.917 raeburn 5273: sub dc_courseid_toggle {
5274: my ($dc_info) = @_;
1.980 raeburn 5275: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5276: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5277: &mt('(More ...)').'</a></span>'.
5278: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5279: }
5280:
1.330 albertel 5281: sub make_attr_string {
5282: my ($register,$attr_ref) = @_;
5283:
5284: if ($attr_ref && !ref($attr_ref)) {
5285: die("addentries Must be a hash ref ".
5286: join(':',caller(1))." ".
5287: join(':',caller(0))." ");
5288: }
5289:
5290: if ($register) {
1.339 albertel 5291: my ($on_load,$on_unload);
5292: foreach my $key (keys(%{$attr_ref})) {
5293: if (lc($key) eq 'onload') {
5294: $on_load.=$attr_ref->{$key}.';';
5295: delete($attr_ref->{$key});
5296:
5297: } elsif (lc($key) eq 'onunload') {
5298: $on_unload.=$attr_ref->{$key}.';';
5299: delete($attr_ref->{$key});
5300: }
5301: }
1.953 droeschl 5302: $attr_ref->{'onload'} = $on_load;
5303: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5304: }
1.339 albertel 5305:
1.330 albertel 5306: my $attr_string;
1.1159 raeburn 5307: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5308: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5309: }
5310: return $attr_string;
5311: }
5312:
5313:
1.182 matthew 5314: ###############################################
1.251 albertel 5315: ###############################################
5316:
5317: =pod
5318:
5319: =item * &endbodytag()
5320:
5321: Returns a uniform footer for LON-CAPA web pages.
5322:
1.635 raeburn 5323: Inputs: 1 - optional reference to an args hash
5324: If in the hash, key for noredirectlink has a value which evaluates to true,
5325: a 'Continue' link is not displayed if the page contains an
5326: internal redirect in the <head></head> section,
5327: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5328:
5329: =cut
5330:
5331: sub endbodytag {
1.635 raeburn 5332: my ($args) = @_;
1.1080 raeburn 5333: my $endbodytag;
5334: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5335: $endbodytag='</body>';
5336: }
1.269 albertel 5337: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5338: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5339: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5340: $endbodytag=
5341: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5342: &mt('Continue').'</a>'.
5343: $endbodytag;
5344: }
1.315 albertel 5345: }
1.251 albertel 5346: return $endbodytag;
5347: }
5348:
1.352 albertel 5349: =pod
5350:
5351: =item * &standard_css()
5352:
5353: Returns a style sheet
5354:
5355: Inputs: (all optional)
5356: domain -> force to color decorate a page for a specific
5357: domain
5358: function -> force usage of a specific rolish color scheme
5359: bgcolor -> override the default page bgcolor
5360:
5361: =cut
5362:
1.343 albertel 5363: sub standard_css {
1.345 albertel 5364: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5365: $function = &get_users_function() if (!$function);
5366: my $img = &designparm($function.'.img', $domain);
5367: my $tabbg = &designparm($function.'.tabbg', $domain);
5368: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5369: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5370: #second colour for later usage
1.345 albertel 5371: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5372: my $pgbg_or_bgcolor =
5373: $bgcolor ||
1.352 albertel 5374: &designparm($function.'.pgbg', $domain);
1.382 albertel 5375: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5376: my $alink = &designparm($function.'.alink', $domain);
5377: my $vlink = &designparm($function.'.vlink', $domain);
5378: my $link = &designparm($function.'.link', $domain);
5379:
1.602 albertel 5380: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5381: my $mono = 'monospace';
1.850 bisitz 5382: my $data_table_head = $sidebg;
5383: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5384: my $data_table_dark = '#E0E0E0';
1.470 banghart 5385: my $data_table_darker = '#CCCCCC';
1.349 albertel 5386: my $data_table_highlight = '#FFFF00';
1.352 albertel 5387: my $mail_new = '#FFBB77';
5388: my $mail_new_hover = '#DD9955';
5389: my $mail_read = '#BBBB77';
5390: my $mail_read_hover = '#999944';
5391: my $mail_replied = '#AAAA88';
5392: my $mail_replied_hover = '#888855';
5393: my $mail_other = '#99BBBB';
5394: my $mail_other_hover = '#669999';
1.391 albertel 5395: my $table_header = '#DDDDDD';
1.489 raeburn 5396: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5397: my $lg_border_color = '#C8C8C8';
1.952 onken 5398: my $button_hover = '#BF2317';
1.392 albertel 5399:
1.608 albertel 5400: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5401: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5402: : '0 3px 0 4px';
1.448 albertel 5403:
1.523 albertel 5404:
1.343 albertel 5405: return <<END;
1.947 droeschl 5406:
5407: /* needed for iframe to allow 100% height in FF */
5408: body, html {
5409: margin: 0;
5410: padding: 0 0.5%;
5411: height: 99%; /* to avoid scrollbars */
5412: }
5413:
1.795 www 5414: body {
1.911 bisitz 5415: font-family: $sans;
5416: line-height:130%;
5417: font-size:0.83em;
5418: color:$font;
1.795 www 5419: }
5420:
1.959 onken 5421: a:focus,
5422: a:focus img {
1.795 www 5423: color: red;
5424: }
1.698 harmsja 5425:
1.911 bisitz 5426: form, .inline {
5427: display: inline;
1.795 www 5428: }
1.721 harmsja 5429:
1.795 www 5430: .LC_right {
1.911 bisitz 5431: text-align:right;
1.795 www 5432: }
5433:
5434: .LC_middle {
1.911 bisitz 5435: vertical-align:middle;
1.795 www 5436: }
1.721 harmsja 5437:
1.1130 raeburn 5438: .LC_floatleft {
5439: float: left;
5440: }
5441:
5442: .LC_floatright {
5443: float: right;
5444: }
5445:
1.911 bisitz 5446: .LC_400Box {
5447: width:400px;
5448: }
1.721 harmsja 5449:
1.947 droeschl 5450: .LC_iframecontainer {
5451: width: 98%;
5452: margin: 0;
5453: position: fixed;
5454: top: 8.5em;
5455: bottom: 0;
5456: }
5457:
5458: .LC_iframecontainer iframe{
5459: border: none;
5460: width: 100%;
5461: height: 100%;
5462: }
5463:
1.778 bisitz 5464: .LC_filename {
5465: font-family: $mono;
5466: white-space:pre;
1.921 bisitz 5467: font-size: 120%;
1.778 bisitz 5468: }
5469:
5470: .LC_fileicon {
5471: border: none;
5472: height: 1.3em;
5473: vertical-align: text-bottom;
5474: margin-right: 0.3em;
5475: text-decoration:none;
5476: }
5477:
1.1008 www 5478: .LC_setting {
5479: text-decoration:underline;
5480: }
5481:
1.350 albertel 5482: .LC_error {
5483: color: red;
5484: }
1.795 www 5485:
1.1097 bisitz 5486: .LC_warning {
5487: color: darkorange;
5488: }
5489:
1.457 albertel 5490: .LC_diff_removed {
1.733 bisitz 5491: color: red;
1.394 albertel 5492: }
1.532 albertel 5493:
5494: .LC_info,
1.457 albertel 5495: .LC_success,
5496: .LC_diff_added {
1.350 albertel 5497: color: green;
5498: }
1.795 www 5499:
1.802 bisitz 5500: div.LC_confirm_box {
5501: background-color: #FAFAFA;
5502: border: 1px solid $lg_border_color;
5503: margin-right: 0;
5504: padding: 5px;
5505: }
5506:
5507: div.LC_confirm_box .LC_error img,
5508: div.LC_confirm_box .LC_success img {
5509: vertical-align: middle;
5510: }
5511:
1.440 albertel 5512: .LC_icon {
1.771 droeschl 5513: border: none;
1.790 droeschl 5514: vertical-align: middle;
1.771 droeschl 5515: }
5516:
1.543 albertel 5517: .LC_docs_spacer {
5518: width: 25px;
5519: height: 1px;
1.771 droeschl 5520: border: none;
1.543 albertel 5521: }
1.346 albertel 5522:
1.532 albertel 5523: .LC_internal_info {
1.735 bisitz 5524: color: #999999;
1.532 albertel 5525: }
5526:
1.794 www 5527: .LC_discussion {
1.1050 www 5528: background: $data_table_dark;
1.911 bisitz 5529: border: 1px solid black;
5530: margin: 2px;
1.794 www 5531: }
5532:
5533: .LC_disc_action_left {
1.1050 www 5534: background: $sidebg;
1.911 bisitz 5535: text-align: left;
1.1050 www 5536: padding: 4px;
5537: margin: 2px;
1.794 www 5538: }
5539:
5540: .LC_disc_action_right {
1.1050 www 5541: background: $sidebg;
1.911 bisitz 5542: text-align: right;
1.1050 www 5543: padding: 4px;
5544: margin: 2px;
1.794 www 5545: }
5546:
5547: .LC_disc_new_item {
1.911 bisitz 5548: background: white;
5549: border: 2px solid red;
1.1050 www 5550: margin: 4px;
5551: padding: 4px;
1.794 www 5552: }
5553:
5554: .LC_disc_old_item {
1.911 bisitz 5555: background: white;
1.1050 www 5556: margin: 4px;
5557: padding: 4px;
1.794 www 5558: }
5559:
1.458 albertel 5560: table.LC_pastsubmission {
5561: border: 1px solid black;
5562: margin: 2px;
5563: }
5564:
1.924 bisitz 5565: table#LC_menubuttons {
1.345 albertel 5566: width: 100%;
5567: background: $pgbg;
1.392 albertel 5568: border: 2px;
1.402 albertel 5569: border-collapse: separate;
1.803 bisitz 5570: padding: 0;
1.345 albertel 5571: }
1.392 albertel 5572:
1.801 tempelho 5573: table#LC_title_bar a {
5574: color: $fontmenu;
5575: }
1.836 bisitz 5576:
1.807 droeschl 5577: table#LC_title_bar {
1.819 tempelho 5578: clear: both;
1.836 bisitz 5579: display: none;
1.807 droeschl 5580: }
5581:
1.795 www 5582: table#LC_title_bar,
1.933 droeschl 5583: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5584: table#LC_title_bar.LC_with_remote {
1.359 albertel 5585: width: 100%;
1.392 albertel 5586: border-color: $pgbg;
5587: border-style: solid;
5588: border-width: $border;
1.379 albertel 5589: background: $pgbg;
1.801 tempelho 5590: color: $fontmenu;
1.392 albertel 5591: border-collapse: collapse;
1.803 bisitz 5592: padding: 0;
1.819 tempelho 5593: margin: 0;
1.359 albertel 5594: }
1.795 www 5595:
1.933 droeschl 5596: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5597: margin: 0;
5598: padding: 0;
1.933 droeschl 5599: position: relative;
5600: list-style: none;
1.913 droeschl 5601: }
1.933 droeschl 5602: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5603: display: inline;
5604: }
1.933 droeschl 5605:
5606: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5607: padding: 0;
1.933 droeschl 5608: margin: 0;
5609: float: left;
1.913 droeschl 5610: }
1.933 droeschl 5611: .LC_breadcrumb_tools_tools {
5612: padding: 0;
5613: margin: 0;
1.913 droeschl 5614: float: right;
5615: }
5616:
1.359 albertel 5617: table#LC_title_bar td {
5618: background: $tabbg;
5619: }
1.795 www 5620:
1.911 bisitz 5621: table#LC_menubuttons img {
1.803 bisitz 5622: border: none;
1.346 albertel 5623: }
1.795 www 5624:
1.842 droeschl 5625: .LC_breadcrumbs_component {
1.911 bisitz 5626: float: right;
5627: margin: 0 1em;
1.357 albertel 5628: }
1.842 droeschl 5629: .LC_breadcrumbs_component img {
1.911 bisitz 5630: vertical-align: middle;
1.777 tempelho 5631: }
1.795 www 5632:
1.383 albertel 5633: td.LC_table_cell_checkbox {
5634: text-align: center;
5635: }
1.795 www 5636:
5637: .LC_fontsize_small {
1.911 bisitz 5638: font-size: 70%;
1.705 tempelho 5639: }
5640:
1.844 bisitz 5641: #LC_breadcrumbs {
1.911 bisitz 5642: clear:both;
5643: background: $sidebg;
5644: border-bottom: 1px solid $lg_border_color;
5645: line-height: 2.5em;
1.933 droeschl 5646: overflow: hidden;
1.911 bisitz 5647: margin: 0;
5648: padding: 0;
1.995 raeburn 5649: text-align: left;
1.819 tempelho 5650: }
1.862 bisitz 5651:
1.1098 bisitz 5652: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5653: clear:both;
5654: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5655: border: 1px solid $sidebg;
1.1098 bisitz 5656: margin: 0 0 10px 0;
1.966 bisitz 5657: padding: 3px;
1.995 raeburn 5658: text-align: left;
1.822 bisitz 5659: }
5660:
1.795 www 5661: .LC_fontsize_medium {
1.911 bisitz 5662: font-size: 85%;
1.705 tempelho 5663: }
5664:
1.795 www 5665: .LC_fontsize_large {
1.911 bisitz 5666: font-size: 120%;
1.705 tempelho 5667: }
5668:
1.346 albertel 5669: .LC_menubuttons_inline_text {
5670: color: $font;
1.698 harmsja 5671: font-size: 90%;
1.701 harmsja 5672: padding-left:3px;
1.346 albertel 5673: }
5674:
1.934 droeschl 5675: .LC_menubuttons_inline_text img{
5676: vertical-align: middle;
5677: }
5678:
1.1051 www 5679: li.LC_menubuttons_inline_text img {
1.951 onken 5680: cursor:pointer;
1.1002 droeschl 5681: text-decoration: none;
1.951 onken 5682: }
5683:
1.526 www 5684: .LC_menubuttons_link {
5685: text-decoration: none;
5686: }
1.795 www 5687:
1.522 albertel 5688: .LC_menubuttons_category {
1.521 www 5689: color: $font;
1.526 www 5690: background: $pgbg;
1.521 www 5691: font-size: larger;
5692: font-weight: bold;
5693: }
5694:
1.346 albertel 5695: td.LC_menubuttons_text {
1.911 bisitz 5696: color: $font;
1.346 albertel 5697: }
1.706 harmsja 5698:
1.346 albertel 5699: .LC_current_location {
5700: background: $tabbg;
5701: }
1.795 www 5702:
1.938 bisitz 5703: table.LC_data_table {
1.347 albertel 5704: border: 1px solid #000000;
1.402 albertel 5705: border-collapse: separate;
1.426 albertel 5706: border-spacing: 1px;
1.610 albertel 5707: background: $pgbg;
1.347 albertel 5708: }
1.795 www 5709:
1.422 albertel 5710: .LC_data_table_dense {
5711: font-size: small;
5712: }
1.795 www 5713:
1.507 raeburn 5714: table.LC_nested_outer {
5715: border: 1px solid #000000;
1.589 raeburn 5716: border-collapse: collapse;
1.803 bisitz 5717: border-spacing: 0;
1.507 raeburn 5718: width: 100%;
5719: }
1.795 www 5720:
1.879 raeburn 5721: table.LC_innerpickbox,
1.507 raeburn 5722: table.LC_nested {
1.803 bisitz 5723: border: none;
1.589 raeburn 5724: border-collapse: collapse;
1.803 bisitz 5725: border-spacing: 0;
1.507 raeburn 5726: width: 100%;
5727: }
1.795 www 5728:
1.911 bisitz 5729: table.LC_data_table tr th,
5730: table.LC_calendar tr th,
1.879 raeburn 5731: table.LC_prior_tries tr th,
5732: table.LC_innerpickbox tr th {
1.349 albertel 5733: font-weight: bold;
5734: background-color: $data_table_head;
1.801 tempelho 5735: color:$fontmenu;
1.701 harmsja 5736: font-size:90%;
1.347 albertel 5737: }
1.795 www 5738:
1.879 raeburn 5739: table.LC_innerpickbox tr th,
5740: table.LC_innerpickbox tr td {
5741: vertical-align: top;
5742: }
5743:
1.711 raeburn 5744: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5745: background-color: #CCCCCC;
1.711 raeburn 5746: font-weight: bold;
5747: text-align: left;
5748: }
1.795 www 5749:
1.912 bisitz 5750: table.LC_data_table tr.LC_odd_row > td {
5751: background-color: $data_table_light;
5752: padding: 2px;
5753: vertical-align: top;
5754: }
5755:
1.809 bisitz 5756: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5757: background-color: $data_table_light;
1.912 bisitz 5758: vertical-align: top;
5759: }
5760:
5761: table.LC_data_table tr.LC_even_row > td {
5762: background-color: $data_table_dark;
1.425 albertel 5763: padding: 2px;
1.900 bisitz 5764: vertical-align: top;
1.347 albertel 5765: }
1.795 www 5766:
1.809 bisitz 5767: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5768: background-color: $data_table_dark;
1.900 bisitz 5769: vertical-align: top;
1.347 albertel 5770: }
1.795 www 5771:
1.425 albertel 5772: table.LC_data_table tr.LC_data_table_highlight td {
5773: background-color: $data_table_darker;
5774: }
1.795 www 5775:
1.639 raeburn 5776: table.LC_data_table tr td.LC_leftcol_header {
5777: background-color: $data_table_head;
5778: font-weight: bold;
5779: }
1.795 www 5780:
1.451 albertel 5781: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5782: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5783: font-weight: bold;
5784: font-style: italic;
5785: text-align: center;
5786: padding: 8px;
1.347 albertel 5787: }
1.795 www 5788:
1.1114 raeburn 5789: table.LC_data_table tr.LC_empty_row td,
5790: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5791: background-color: $sidebg;
5792: }
5793:
5794: table.LC_nested tr.LC_empty_row td {
5795: background-color: #FFFFFF;
5796: }
5797:
1.890 droeschl 5798: table.LC_caption {
5799: }
5800:
1.507 raeburn 5801: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5802: padding: 4ex
5803: }
1.795 www 5804:
1.507 raeburn 5805: table.LC_nested_outer tr th {
5806: font-weight: bold;
1.801 tempelho 5807: color:$fontmenu;
1.507 raeburn 5808: background-color: $data_table_head;
1.701 harmsja 5809: font-size: small;
1.507 raeburn 5810: border-bottom: 1px solid #000000;
5811: }
1.795 www 5812:
1.507 raeburn 5813: table.LC_nested_outer tr td.LC_subheader {
5814: background-color: $data_table_head;
5815: font-weight: bold;
5816: font-size: small;
5817: border-bottom: 1px solid #000000;
5818: text-align: right;
1.451 albertel 5819: }
1.795 www 5820:
1.507 raeburn 5821: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5822: background-color: #CCCCCC;
1.451 albertel 5823: font-weight: bold;
5824: font-size: small;
1.507 raeburn 5825: text-align: center;
5826: }
1.795 www 5827:
1.589 raeburn 5828: table.LC_nested tr.LC_info_row td.LC_left_item,
5829: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5830: text-align: left;
1.451 albertel 5831: }
1.795 www 5832:
1.507 raeburn 5833: table.LC_nested td {
1.735 bisitz 5834: background-color: #FFFFFF;
1.451 albertel 5835: font-size: small;
1.507 raeburn 5836: }
1.795 www 5837:
1.507 raeburn 5838: table.LC_nested_outer tr th.LC_right_item,
5839: table.LC_nested tr.LC_info_row td.LC_right_item,
5840: table.LC_nested tr.LC_odd_row td.LC_right_item,
5841: table.LC_nested tr td.LC_right_item {
1.451 albertel 5842: text-align: right;
5843: }
5844:
1.507 raeburn 5845: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5846: background-color: #EEEEEE;
1.451 albertel 5847: }
5848:
1.473 raeburn 5849: table.LC_createuser {
5850: }
5851:
5852: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5853: font-size: small;
1.473 raeburn 5854: }
5855:
5856: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5857: background-color: #CCCCCC;
1.473 raeburn 5858: font-weight: bold;
5859: text-align: center;
5860: }
5861:
1.349 albertel 5862: table.LC_calendar {
5863: border: 1px solid #000000;
5864: border-collapse: collapse;
1.917 raeburn 5865: width: 98%;
1.349 albertel 5866: }
1.795 www 5867:
1.349 albertel 5868: table.LC_calendar_pickdate {
5869: font-size: xx-small;
5870: }
1.795 www 5871:
1.349 albertel 5872: table.LC_calendar tr td {
5873: border: 1px solid #000000;
5874: vertical-align: top;
1.917 raeburn 5875: width: 14%;
1.349 albertel 5876: }
1.795 www 5877:
1.349 albertel 5878: table.LC_calendar tr td.LC_calendar_day_empty {
5879: background-color: $data_table_dark;
5880: }
1.795 www 5881:
1.779 bisitz 5882: table.LC_calendar tr td.LC_calendar_day_current {
5883: background-color: $data_table_highlight;
1.777 tempelho 5884: }
1.795 www 5885:
1.938 bisitz 5886: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5887: background-color: $mail_new;
5888: }
1.795 www 5889:
1.938 bisitz 5890: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5891: background-color: $mail_new_hover;
5892: }
1.795 www 5893:
1.938 bisitz 5894: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5895: background-color: $mail_read;
5896: }
1.795 www 5897:
1.938 bisitz 5898: /*
5899: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5900: background-color: $mail_read_hover;
5901: }
1.938 bisitz 5902: */
1.795 www 5903:
1.938 bisitz 5904: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5905: background-color: $mail_replied;
5906: }
1.795 www 5907:
1.938 bisitz 5908: /*
5909: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5910: background-color: $mail_replied_hover;
5911: }
1.938 bisitz 5912: */
1.795 www 5913:
1.938 bisitz 5914: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5915: background-color: $mail_other;
5916: }
1.795 www 5917:
1.938 bisitz 5918: /*
5919: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5920: background-color: $mail_other_hover;
5921: }
1.938 bisitz 5922: */
1.494 raeburn 5923:
1.777 tempelho 5924: table.LC_data_table tr > td.LC_browser_file,
5925: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5926: background: #AAEE77;
1.389 albertel 5927: }
1.795 www 5928:
1.777 tempelho 5929: table.LC_data_table tr > td.LC_browser_file_locked,
5930: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5931: background: #FFAA99;
1.387 albertel 5932: }
1.795 www 5933:
1.777 tempelho 5934: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5935: background: #888888;
1.779 bisitz 5936: }
1.795 www 5937:
1.777 tempelho 5938: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5939: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5940: background: #F8F866;
1.777 tempelho 5941: }
1.795 www 5942:
1.696 bisitz 5943: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5944: background: #E0E8FF;
1.387 albertel 5945: }
1.696 bisitz 5946:
1.707 bisitz 5947: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5948: /* background: #77FF77; */
1.707 bisitz 5949: }
1.795 www 5950:
1.707 bisitz 5951: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5952: border-right: 8px solid #FFFF77;
1.707 bisitz 5953: }
1.795 www 5954:
1.707 bisitz 5955: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5956: border-right: 8px solid #FFAA77;
1.707 bisitz 5957: }
1.795 www 5958:
1.707 bisitz 5959: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5960: border-right: 8px solid #FF7777;
1.707 bisitz 5961: }
1.795 www 5962:
1.707 bisitz 5963: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5964: border-right: 8px solid #AAFF77;
1.707 bisitz 5965: }
1.795 www 5966:
1.707 bisitz 5967: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5968: border-right: 8px solid #11CC55;
1.707 bisitz 5969: }
5970:
1.388 albertel 5971: span.LC_current_location {
1.701 harmsja 5972: font-size:larger;
1.388 albertel 5973: background: $pgbg;
5974: }
1.387 albertel 5975:
1.1029 www 5976: span.LC_current_nav_location {
5977: font-weight:bold;
5978: background: $sidebg;
5979: }
5980:
1.395 albertel 5981: span.LC_parm_menu_item {
5982: font-size: larger;
5983: }
1.795 www 5984:
1.395 albertel 5985: span.LC_parm_scope_all {
5986: color: red;
5987: }
1.795 www 5988:
1.395 albertel 5989: span.LC_parm_scope_folder {
5990: color: green;
5991: }
1.795 www 5992:
1.395 albertel 5993: span.LC_parm_scope_resource {
5994: color: orange;
5995: }
1.795 www 5996:
1.395 albertel 5997: span.LC_parm_part {
5998: color: blue;
5999: }
1.795 www 6000:
1.911 bisitz 6001: span.LC_parm_folder,
6002: span.LC_parm_symb {
1.395 albertel 6003: font-size: x-small;
6004: font-family: $mono;
6005: color: #AAAAAA;
6006: }
6007:
1.977 bisitz 6008: ul.LC_parm_parmlist li {
6009: display: inline-block;
6010: padding: 0.3em 0.8em;
6011: vertical-align: top;
6012: width: 150px;
6013: border-top:1px solid $lg_border_color;
6014: }
6015:
1.795 www 6016: td.LC_parm_overview_level_menu,
6017: td.LC_parm_overview_map_menu,
6018: td.LC_parm_overview_parm_selectors,
6019: td.LC_parm_overview_restrictions {
1.396 albertel 6020: border: 1px solid black;
6021: border-collapse: collapse;
6022: }
1.795 www 6023:
1.396 albertel 6024: table.LC_parm_overview_restrictions td {
6025: border-width: 1px 4px 1px 4px;
6026: border-style: solid;
6027: border-color: $pgbg;
6028: text-align: center;
6029: }
1.795 www 6030:
1.396 albertel 6031: table.LC_parm_overview_restrictions th {
6032: background: $tabbg;
6033: border-width: 1px 4px 1px 4px;
6034: border-style: solid;
6035: border-color: $pgbg;
6036: }
1.795 www 6037:
1.398 albertel 6038: table#LC_helpmenu {
1.803 bisitz 6039: border: none;
1.398 albertel 6040: height: 55px;
1.803 bisitz 6041: border-spacing: 0;
1.398 albertel 6042: }
6043:
6044: table#LC_helpmenu fieldset legend {
6045: font-size: larger;
6046: }
1.795 www 6047:
1.397 albertel 6048: table#LC_helpmenu_links {
6049: width: 100%;
6050: border: 1px solid black;
6051: background: $pgbg;
1.803 bisitz 6052: padding: 0;
1.397 albertel 6053: border-spacing: 1px;
6054: }
1.795 www 6055:
1.397 albertel 6056: table#LC_helpmenu_links tr td {
6057: padding: 1px;
6058: background: $tabbg;
1.399 albertel 6059: text-align: center;
6060: font-weight: bold;
1.397 albertel 6061: }
1.396 albertel 6062:
1.795 www 6063: table#LC_helpmenu_links a:link,
6064: table#LC_helpmenu_links a:visited,
1.397 albertel 6065: table#LC_helpmenu_links a:active {
6066: text-decoration: none;
6067: color: $font;
6068: }
1.795 www 6069:
1.397 albertel 6070: table#LC_helpmenu_links a:hover {
6071: text-decoration: underline;
6072: color: $vlink;
6073: }
1.396 albertel 6074:
1.417 albertel 6075: .LC_chrt_popup_exists {
6076: border: 1px solid #339933;
6077: margin: -1px;
6078: }
1.795 www 6079:
1.417 albertel 6080: .LC_chrt_popup_up {
6081: border: 1px solid yellow;
6082: margin: -1px;
6083: }
1.795 www 6084:
1.417 albertel 6085: .LC_chrt_popup {
6086: border: 1px solid #8888FF;
6087: background: #CCCCFF;
6088: }
1.795 www 6089:
1.421 albertel 6090: table.LC_pick_box {
6091: border-collapse: separate;
6092: background: white;
6093: border: 1px solid black;
6094: border-spacing: 1px;
6095: }
1.795 www 6096:
1.421 albertel 6097: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6098: background: $sidebg;
1.421 albertel 6099: font-weight: bold;
1.900 bisitz 6100: text-align: left;
1.740 bisitz 6101: vertical-align: top;
1.421 albertel 6102: width: 184px;
6103: padding: 8px;
6104: }
1.795 www 6105:
1.579 raeburn 6106: table.LC_pick_box td.LC_pick_box_value {
6107: text-align: left;
6108: padding: 8px;
6109: }
1.795 www 6110:
1.579 raeburn 6111: table.LC_pick_box td.LC_pick_box_select {
6112: text-align: left;
6113: padding: 8px;
6114: }
1.795 www 6115:
1.424 albertel 6116: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6117: padding: 0;
1.421 albertel 6118: height: 1px;
6119: background: black;
6120: }
1.795 www 6121:
1.421 albertel 6122: table.LC_pick_box td.LC_pick_box_submit {
6123: text-align: right;
6124: }
1.795 www 6125:
1.579 raeburn 6126: table.LC_pick_box td.LC_evenrow_value {
6127: text-align: left;
6128: padding: 8px;
6129: background-color: $data_table_light;
6130: }
1.795 www 6131:
1.579 raeburn 6132: table.LC_pick_box td.LC_oddrow_value {
6133: text-align: left;
6134: padding: 8px;
6135: background-color: $data_table_light;
6136: }
1.795 www 6137:
1.579 raeburn 6138: span.LC_helpform_receipt_cat {
6139: font-weight: bold;
6140: }
1.795 www 6141:
1.424 albertel 6142: table.LC_group_priv_box {
6143: background: white;
6144: border: 1px solid black;
6145: border-spacing: 1px;
6146: }
1.795 www 6147:
1.424 albertel 6148: table.LC_group_priv_box td.LC_pick_box_title {
6149: background: $tabbg;
6150: font-weight: bold;
6151: text-align: right;
6152: width: 184px;
6153: }
1.795 www 6154:
1.424 albertel 6155: table.LC_group_priv_box td.LC_groups_fixed {
6156: background: $data_table_light;
6157: text-align: center;
6158: }
1.795 www 6159:
1.424 albertel 6160: table.LC_group_priv_box td.LC_groups_optional {
6161: background: $data_table_dark;
6162: text-align: center;
6163: }
1.795 www 6164:
1.424 albertel 6165: table.LC_group_priv_box td.LC_groups_functionality {
6166: background: $data_table_darker;
6167: text-align: center;
6168: font-weight: bold;
6169: }
1.795 www 6170:
1.424 albertel 6171: table.LC_group_priv td {
6172: text-align: left;
1.803 bisitz 6173: padding: 0;
1.424 albertel 6174: }
6175:
6176: .LC_navbuttons {
6177: margin: 2ex 0ex 2ex 0ex;
6178: }
1.795 www 6179:
1.423 albertel 6180: .LC_topic_bar {
6181: font-weight: bold;
6182: background: $tabbg;
1.918 wenzelju 6183: margin: 1em 0em 1em 2em;
1.805 bisitz 6184: padding: 3px;
1.918 wenzelju 6185: font-size: 1.2em;
1.423 albertel 6186: }
1.795 www 6187:
1.423 albertel 6188: .LC_topic_bar span {
1.918 wenzelju 6189: left: 0.5em;
6190: position: absolute;
1.423 albertel 6191: vertical-align: middle;
1.918 wenzelju 6192: font-size: 1.2em;
1.423 albertel 6193: }
1.795 www 6194:
1.423 albertel 6195: table.LC_course_group_status {
6196: margin: 20px;
6197: }
1.795 www 6198:
1.423 albertel 6199: table.LC_status_selector td {
6200: vertical-align: top;
6201: text-align: center;
1.424 albertel 6202: padding: 4px;
6203: }
1.795 www 6204:
1.599 albertel 6205: div.LC_feedback_link {
1.616 albertel 6206: clear: both;
1.829 kalberla 6207: background: $sidebg;
1.779 bisitz 6208: width: 100%;
1.829 kalberla 6209: padding-bottom: 10px;
6210: border: 1px $tabbg solid;
1.833 kalberla 6211: height: 22px;
6212: line-height: 22px;
6213: padding-top: 5px;
6214: }
6215:
6216: div.LC_feedback_link img {
6217: height: 22px;
1.867 kalberla 6218: vertical-align:middle;
1.829 kalberla 6219: }
6220:
1.911 bisitz 6221: div.LC_feedback_link a {
1.829 kalberla 6222: text-decoration: none;
1.489 raeburn 6223: }
1.795 www 6224:
1.867 kalberla 6225: div.LC_comblock {
1.911 bisitz 6226: display:inline;
1.867 kalberla 6227: color:$font;
6228: font-size:90%;
6229: }
6230:
6231: div.LC_feedback_link div.LC_comblock {
6232: padding-left:5px;
6233: }
6234:
6235: div.LC_feedback_link div.LC_comblock a {
6236: color:$font;
6237: }
6238:
1.489 raeburn 6239: span.LC_feedback_link {
1.858 bisitz 6240: /* background: $feedback_link_bg; */
1.599 albertel 6241: font-size: larger;
6242: }
1.795 www 6243:
1.599 albertel 6244: span.LC_message_link {
1.858 bisitz 6245: /* background: $feedback_link_bg; */
1.599 albertel 6246: font-size: larger;
6247: position: absolute;
6248: right: 1em;
1.489 raeburn 6249: }
1.421 albertel 6250:
1.515 albertel 6251: table.LC_prior_tries {
1.524 albertel 6252: border: 1px solid #000000;
6253: border-collapse: separate;
6254: border-spacing: 1px;
1.515 albertel 6255: }
1.523 albertel 6256:
1.515 albertel 6257: table.LC_prior_tries td {
1.524 albertel 6258: padding: 2px;
1.515 albertel 6259: }
1.523 albertel 6260:
6261: .LC_answer_correct {
1.795 www 6262: background: lightgreen;
6263: color: darkgreen;
6264: padding: 6px;
1.523 albertel 6265: }
1.795 www 6266:
1.523 albertel 6267: .LC_answer_charged_try {
1.797 www 6268: background: #FFAAAA;
1.795 www 6269: color: darkred;
6270: padding: 6px;
1.523 albertel 6271: }
1.795 www 6272:
1.779 bisitz 6273: .LC_answer_not_charged_try,
1.523 albertel 6274: .LC_answer_no_grade,
6275: .LC_answer_late {
1.795 www 6276: background: lightyellow;
1.523 albertel 6277: color: black;
1.795 www 6278: padding: 6px;
1.523 albertel 6279: }
1.795 www 6280:
1.523 albertel 6281: .LC_answer_previous {
1.795 www 6282: background: lightblue;
6283: color: darkblue;
6284: padding: 6px;
1.523 albertel 6285: }
1.795 www 6286:
1.779 bisitz 6287: .LC_answer_no_message {
1.777 tempelho 6288: background: #FFFFFF;
6289: color: black;
1.795 www 6290: padding: 6px;
1.779 bisitz 6291: }
1.795 www 6292:
1.779 bisitz 6293: .LC_answer_unknown {
6294: background: orange;
6295: color: black;
1.795 www 6296: padding: 6px;
1.777 tempelho 6297: }
1.795 www 6298:
1.529 albertel 6299: span.LC_prior_numerical,
6300: span.LC_prior_string,
6301: span.LC_prior_custom,
6302: span.LC_prior_reaction,
6303: span.LC_prior_math {
1.925 bisitz 6304: font-family: $mono;
1.523 albertel 6305: white-space: pre;
6306: }
6307:
1.525 albertel 6308: span.LC_prior_string {
1.925 bisitz 6309: font-family: $mono;
1.525 albertel 6310: white-space: pre;
6311: }
6312:
1.523 albertel 6313: table.LC_prior_option {
6314: width: 100%;
6315: border-collapse: collapse;
6316: }
1.795 www 6317:
1.911 bisitz 6318: table.LC_prior_rank,
1.795 www 6319: table.LC_prior_match {
1.528 albertel 6320: border-collapse: collapse;
6321: }
1.795 www 6322:
1.528 albertel 6323: table.LC_prior_option tr td,
6324: table.LC_prior_rank tr td,
6325: table.LC_prior_match tr td {
1.524 albertel 6326: border: 1px solid #000000;
1.515 albertel 6327: }
6328:
1.855 bisitz 6329: .LC_nobreak {
1.544 albertel 6330: white-space: nowrap;
1.519 raeburn 6331: }
6332:
1.576 raeburn 6333: span.LC_cusr_emph {
6334: font-style: italic;
6335: }
6336:
1.633 raeburn 6337: span.LC_cusr_subheading {
6338: font-weight: normal;
6339: font-size: 85%;
6340: }
6341:
1.861 bisitz 6342: div.LC_docs_entry_move {
1.859 bisitz 6343: border: 1px solid #BBBBBB;
1.545 albertel 6344: background: #DDDDDD;
1.861 bisitz 6345: width: 22px;
1.859 bisitz 6346: padding: 1px;
6347: margin: 0;
1.545 albertel 6348: }
6349:
1.861 bisitz 6350: table.LC_data_table tr > td.LC_docs_entry_commands,
6351: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6352: font-size: x-small;
6353: }
1.795 www 6354:
1.861 bisitz 6355: .LC_docs_entry_parameter {
6356: white-space: nowrap;
6357: }
6358:
1.544 albertel 6359: .LC_docs_copy {
1.545 albertel 6360: color: #000099;
1.544 albertel 6361: }
1.795 www 6362:
1.544 albertel 6363: .LC_docs_cut {
1.545 albertel 6364: color: #550044;
1.544 albertel 6365: }
1.795 www 6366:
1.544 albertel 6367: .LC_docs_rename {
1.545 albertel 6368: color: #009900;
1.544 albertel 6369: }
1.795 www 6370:
1.544 albertel 6371: .LC_docs_remove {
1.545 albertel 6372: color: #990000;
6373: }
6374:
1.547 albertel 6375: .LC_docs_reinit_warn,
6376: .LC_docs_ext_edit {
6377: font-size: x-small;
6378: }
6379:
1.545 albertel 6380: table.LC_docs_adddocs td,
6381: table.LC_docs_adddocs th {
6382: border: 1px solid #BBBBBB;
6383: padding: 4px;
6384: background: #DDDDDD;
1.543 albertel 6385: }
6386:
1.584 albertel 6387: table.LC_sty_begin {
6388: background: #BBFFBB;
6389: }
1.795 www 6390:
1.584 albertel 6391: table.LC_sty_end {
6392: background: #FFBBBB;
6393: }
6394:
1.589 raeburn 6395: table.LC_double_column {
1.803 bisitz 6396: border-width: 0;
1.589 raeburn 6397: border-collapse: collapse;
6398: width: 100%;
6399: padding: 2px;
6400: }
6401:
6402: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6403: top: 2px;
1.589 raeburn 6404: left: 2px;
6405: width: 47%;
6406: vertical-align: top;
6407: }
6408:
6409: table.LC_double_column tr td.LC_right_col {
6410: top: 2px;
1.779 bisitz 6411: right: 2px;
1.589 raeburn 6412: width: 47%;
6413: vertical-align: top;
6414: }
6415:
1.591 raeburn 6416: div.LC_left_float {
6417: float: left;
6418: padding-right: 5%;
1.597 albertel 6419: padding-bottom: 4px;
1.591 raeburn 6420: }
6421:
6422: div.LC_clear_float_header {
1.597 albertel 6423: padding-bottom: 2px;
1.591 raeburn 6424: }
6425:
6426: div.LC_clear_float_footer {
1.597 albertel 6427: padding-top: 10px;
1.591 raeburn 6428: clear: both;
6429: }
6430:
1.597 albertel 6431: div.LC_grade_show_user {
1.941 bisitz 6432: /* border-left: 5px solid $sidebg; */
6433: border-top: 5px solid #000000;
6434: margin: 50px 0 0 0;
1.936 bisitz 6435: padding: 15px 0 5px 10px;
1.597 albertel 6436: }
1.795 www 6437:
1.936 bisitz 6438: div.LC_grade_show_user_odd_row {
1.941 bisitz 6439: /* border-left: 5px solid #000000; */
6440: }
6441:
6442: div.LC_grade_show_user div.LC_Box {
6443: margin-right: 50px;
1.597 albertel 6444: }
6445:
6446: div.LC_grade_submissions,
6447: div.LC_grade_message_center,
1.936 bisitz 6448: div.LC_grade_info_links {
1.597 albertel 6449: margin: 5px;
6450: width: 99%;
6451: background: #FFFFFF;
6452: }
1.795 www 6453:
1.597 albertel 6454: div.LC_grade_submissions_header,
1.936 bisitz 6455: div.LC_grade_message_center_header {
1.705 tempelho 6456: font-weight: bold;
6457: font-size: large;
1.597 albertel 6458: }
1.795 www 6459:
1.597 albertel 6460: div.LC_grade_submissions_body,
1.936 bisitz 6461: div.LC_grade_message_center_body {
1.597 albertel 6462: border: 1px solid black;
6463: width: 99%;
6464: background: #FFFFFF;
6465: }
1.795 www 6466:
1.613 albertel 6467: table.LC_scantron_action {
6468: width: 100%;
6469: }
1.795 www 6470:
1.613 albertel 6471: table.LC_scantron_action tr th {
1.698 harmsja 6472: font-weight:bold;
6473: font-style:normal;
1.613 albertel 6474: }
1.795 www 6475:
1.779 bisitz 6476: .LC_edit_problem_header,
1.614 albertel 6477: div.LC_edit_problem_footer {
1.705 tempelho 6478: font-weight: normal;
6479: font-size: medium;
1.602 albertel 6480: margin: 2px;
1.1060 bisitz 6481: background-color: $sidebg;
1.600 albertel 6482: }
1.795 www 6483:
1.600 albertel 6484: div.LC_edit_problem_header,
1.602 albertel 6485: div.LC_edit_problem_header div,
1.614 albertel 6486: div.LC_edit_problem_footer,
6487: div.LC_edit_problem_footer div,
1.602 albertel 6488: div.LC_edit_problem_editxml_header,
6489: div.LC_edit_problem_editxml_header div {
1.600 albertel 6490: margin-top: 5px;
6491: }
1.795 www 6492:
1.600 albertel 6493: div.LC_edit_problem_header_title {
1.705 tempelho 6494: font-weight: bold;
6495: font-size: larger;
1.602 albertel 6496: background: $tabbg;
6497: padding: 3px;
1.1060 bisitz 6498: margin: 0 0 5px 0;
1.602 albertel 6499: }
1.795 www 6500:
1.602 albertel 6501: table.LC_edit_problem_header_title {
6502: width: 100%;
1.600 albertel 6503: background: $tabbg;
1.602 albertel 6504: }
6505:
6506: div.LC_edit_problem_discards {
6507: float: left;
6508: padding-bottom: 5px;
6509: }
1.795 www 6510:
1.602 albertel 6511: div.LC_edit_problem_saves {
6512: float: right;
6513: padding-bottom: 5px;
1.600 albertel 6514: }
1.795 www 6515:
1.1124 bisitz 6516: .LC_edit_opt {
6517: padding-left: 1em;
6518: white-space: nowrap;
6519: }
6520:
1.1152 golterma 6521: .LC_edit_problem_latexhelper{
6522: text-align: right;
6523: }
6524:
6525: #LC_edit_problem_colorful div{
6526: margin-left: 40px;
6527: }
6528:
1.911 bisitz 6529: img.stift {
1.803 bisitz 6530: border-width: 0;
6531: vertical-align: middle;
1.677 riegler 6532: }
1.680 riegler 6533:
1.923 bisitz 6534: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6535: vertical-align: top;
1.777 tempelho 6536: }
1.795 www 6537:
1.716 raeburn 6538: div.LC_createcourse {
1.911 bisitz 6539: margin: 10px 10px 10px 10px;
1.716 raeburn 6540: }
6541:
1.917 raeburn 6542: .LC_dccid {
1.1130 raeburn 6543: float: right;
1.917 raeburn 6544: margin: 0.2em 0 0 0;
6545: padding: 0;
6546: font-size: 90%;
6547: display:none;
6548: }
6549:
1.897 wenzelju 6550: ol.LC_primary_menu a:hover,
1.721 harmsja 6551: ol#LC_MenuBreadcrumbs a:hover,
6552: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6553: ul#LC_secondary_menu a:hover,
1.721 harmsja 6554: .LC_FormSectionClearButton input:hover
1.795 www 6555: ul.LC_TabContent li:hover a {
1.952 onken 6556: color:$button_hover;
1.911 bisitz 6557: text-decoration:none;
1.693 droeschl 6558: }
6559:
1.779 bisitz 6560: h1 {
1.911 bisitz 6561: padding: 0;
6562: line-height:130%;
1.693 droeschl 6563: }
1.698 harmsja 6564:
1.911 bisitz 6565: h2,
6566: h3,
6567: h4,
6568: h5,
6569: h6 {
6570: margin: 5px 0 5px 0;
6571: padding: 0;
6572: line-height:130%;
1.693 droeschl 6573: }
1.795 www 6574:
6575: .LC_hcell {
1.911 bisitz 6576: padding:3px 15px 3px 15px;
6577: margin: 0;
6578: background-color:$tabbg;
6579: color:$fontmenu;
6580: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6581: }
1.795 www 6582:
1.840 bisitz 6583: .LC_Box > .LC_hcell {
1.911 bisitz 6584: margin: 0 -10px 10px -10px;
1.835 bisitz 6585: }
6586:
1.721 harmsja 6587: .LC_noBorder {
1.911 bisitz 6588: border: 0;
1.698 harmsja 6589: }
1.693 droeschl 6590:
1.721 harmsja 6591: .LC_FormSectionClearButton input {
1.911 bisitz 6592: background-color:transparent;
6593: border: none;
6594: cursor:pointer;
6595: text-decoration:underline;
1.693 droeschl 6596: }
1.763 bisitz 6597:
6598: .LC_help_open_topic {
1.911 bisitz 6599: color: #FFFFFF;
6600: background-color: #EEEEFF;
6601: margin: 1px;
6602: padding: 4px;
6603: border: 1px solid #000033;
6604: white-space: nowrap;
6605: /* vertical-align: middle; */
1.759 neumanie 6606: }
1.693 droeschl 6607:
1.911 bisitz 6608: dl,
6609: ul,
6610: div,
6611: fieldset {
6612: margin: 10px 10px 10px 0;
6613: /* overflow: hidden; */
1.693 droeschl 6614: }
1.795 www 6615:
1.838 bisitz 6616: fieldset > legend {
1.911 bisitz 6617: font-weight: bold;
6618: padding: 0 5px 0 5px;
1.838 bisitz 6619: }
6620:
1.813 bisitz 6621: #LC_nav_bar {
1.911 bisitz 6622: float: left;
1.995 raeburn 6623: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6624: margin: 0 0 2px 0;
1.807 droeschl 6625: }
6626:
1.916 droeschl 6627: #LC_realm {
6628: margin: 0.2em 0 0 0;
6629: padding: 0;
6630: font-weight: bold;
6631: text-align: center;
1.995 raeburn 6632: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6633: }
6634:
1.911 bisitz 6635: #LC_nav_bar em {
6636: font-weight: bold;
6637: font-style: normal;
1.807 droeschl 6638: }
6639:
1.897 wenzelju 6640: ol.LC_primary_menu {
1.934 droeschl 6641: margin: 0;
1.1076 raeburn 6642: padding: 0;
1.995 raeburn 6643: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6644: }
6645:
1.852 droeschl 6646: ol#LC_PathBreadcrumbs {
1.911 bisitz 6647: margin: 0;
1.693 droeschl 6648: }
6649:
1.897 wenzelju 6650: ol.LC_primary_menu li {
1.1076 raeburn 6651: color: RGB(80, 80, 80);
6652: vertical-align: middle;
6653: text-align: left;
6654: list-style: none;
6655: float: left;
6656: }
6657:
6658: ol.LC_primary_menu li a {
6659: display: block;
6660: margin: 0;
6661: padding: 0 5px 0 10px;
6662: text-decoration: none;
6663: }
6664:
6665: ol.LC_primary_menu li ul {
6666: display: none;
6667: width: 10em;
6668: background-color: $data_table_light;
6669: }
6670:
6671: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6672: display: block;
6673: position: absolute;
6674: margin: 0;
6675: padding: 0;
1.1078 raeburn 6676: z-index: 2;
1.1076 raeburn 6677: }
6678:
6679: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6680: font-size: 90%;
1.911 bisitz 6681: vertical-align: top;
1.1076 raeburn 6682: float: none;
1.1079 raeburn 6683: border-left: 1px solid black;
6684: border-right: 1px solid black;
1.1076 raeburn 6685: }
6686:
6687: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1078 raeburn 6688: background-color:$data_table_light;
1.1076 raeburn 6689: }
6690:
6691: ol.LC_primary_menu li li a:hover {
6692: color:$button_hover;
6693: background-color:$data_table_dark;
1.693 droeschl 6694: }
6695:
1.897 wenzelju 6696: ol.LC_primary_menu li img {
1.911 bisitz 6697: vertical-align: bottom;
1.934 droeschl 6698: height: 1.1em;
1.1077 raeburn 6699: margin: 0.2em 0 0 0;
1.693 droeschl 6700: }
6701:
1.897 wenzelju 6702: ol.LC_primary_menu a {
1.911 bisitz 6703: color: RGB(80, 80, 80);
6704: text-decoration: none;
1.693 droeschl 6705: }
1.795 www 6706:
1.949 droeschl 6707: ol.LC_primary_menu a.LC_new_message {
6708: font-weight:bold;
6709: color: darkred;
6710: }
6711:
1.975 raeburn 6712: ol.LC_docs_parameters {
6713: margin-left: 0;
6714: padding: 0;
6715: list-style: none;
6716: }
6717:
6718: ol.LC_docs_parameters li {
6719: margin: 0;
6720: padding-right: 20px;
6721: display: inline;
6722: }
6723:
1.976 raeburn 6724: ol.LC_docs_parameters li:before {
6725: content: "\\002022 \\0020";
6726: }
6727:
6728: li.LC_docs_parameters_title {
6729: font-weight: bold;
6730: }
6731:
6732: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6733: content: "";
6734: }
6735:
1.897 wenzelju 6736: ul#LC_secondary_menu {
1.1107 raeburn 6737: clear: right;
1.911 bisitz 6738: color: $fontmenu;
6739: background: $tabbg;
6740: list-style: none;
6741: padding: 0;
6742: margin: 0;
6743: width: 100%;
1.995 raeburn 6744: text-align: left;
1.1107 raeburn 6745: float: left;
1.808 droeschl 6746: }
6747:
1.897 wenzelju 6748: ul#LC_secondary_menu li {
1.911 bisitz 6749: font-weight: bold;
6750: line-height: 1.8em;
1.1107 raeburn 6751: border-right: 1px solid black;
6752: float: left;
6753: }
6754:
6755: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6756: background-color: $data_table_light;
6757: }
6758:
6759: ul#LC_secondary_menu li a {
1.911 bisitz 6760: padding: 0 0.8em;
1.1107 raeburn 6761: }
6762:
6763: ul#LC_secondary_menu li ul {
6764: display: none;
6765: }
6766:
6767: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6768: display: block;
6769: position: absolute;
6770: margin: 0;
6771: padding: 0;
6772: list-style:none;
6773: float: none;
6774: background-color: $data_table_light;
6775: z-index: 2;
6776: margin-left: -1px;
6777: }
6778:
6779: ul#LC_secondary_menu li ul li {
6780: font-size: 90%;
6781: vertical-align: top;
6782: border-left: 1px solid black;
1.911 bisitz 6783: border-right: 1px solid black;
1.1119 raeburn 6784: background-color: $data_table_light;
1.1107 raeburn 6785: list-style:none;
6786: float: none;
6787: }
6788:
6789: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6790: background-color: $data_table_dark;
1.807 droeschl 6791: }
6792:
1.847 tempelho 6793: ul.LC_TabContent {
1.911 bisitz 6794: display:block;
6795: background: $sidebg;
6796: border-bottom: solid 1px $lg_border_color;
6797: list-style:none;
1.1020 raeburn 6798: margin: -1px -10px 0 -10px;
1.911 bisitz 6799: padding: 0;
1.693 droeschl 6800: }
6801:
1.795 www 6802: ul.LC_TabContent li,
6803: ul.LC_TabContentBigger li {
1.911 bisitz 6804: float:left;
1.741 harmsja 6805: }
1.795 www 6806:
1.897 wenzelju 6807: ul#LC_secondary_menu li a {
1.911 bisitz 6808: color: $fontmenu;
6809: text-decoration: none;
1.693 droeschl 6810: }
1.795 www 6811:
1.721 harmsja 6812: ul.LC_TabContent {
1.952 onken 6813: min-height:20px;
1.721 harmsja 6814: }
1.795 www 6815:
6816: ul.LC_TabContent li {
1.911 bisitz 6817: vertical-align:middle;
1.959 onken 6818: padding: 0 16px 0 10px;
1.911 bisitz 6819: background-color:$tabbg;
6820: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6821: border-left: solid 1px $font;
1.721 harmsja 6822: }
1.795 www 6823:
1.847 tempelho 6824: ul.LC_TabContent .right {
1.911 bisitz 6825: float:right;
1.847 tempelho 6826: }
6827:
1.911 bisitz 6828: ul.LC_TabContent li a,
6829: ul.LC_TabContent li {
6830: color:rgb(47,47,47);
6831: text-decoration:none;
6832: font-size:95%;
6833: font-weight:bold;
1.952 onken 6834: min-height:20px;
6835: }
6836:
1.959 onken 6837: ul.LC_TabContent li a:hover,
6838: ul.LC_TabContent li a:focus {
1.952 onken 6839: color: $button_hover;
1.959 onken 6840: background:none;
6841: outline:none;
1.952 onken 6842: }
6843:
6844: ul.LC_TabContent li:hover {
6845: color: $button_hover;
6846: cursor:pointer;
1.721 harmsja 6847: }
1.795 www 6848:
1.911 bisitz 6849: ul.LC_TabContent li.active {
1.952 onken 6850: color: $font;
1.911 bisitz 6851: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6852: border-bottom:solid 1px #FFFFFF;
6853: cursor: default;
1.744 ehlerst 6854: }
1.795 www 6855:
1.959 onken 6856: ul.LC_TabContent li.active a {
6857: color:$font;
6858: background:#FFFFFF;
6859: outline: none;
6860: }
1.1047 raeburn 6861:
6862: ul.LC_TabContent li.goback {
6863: float: left;
6864: border-left: none;
6865: }
6866:
1.870 tempelho 6867: #maincoursedoc {
1.911 bisitz 6868: clear:both;
1.870 tempelho 6869: }
6870:
6871: ul.LC_TabContentBigger {
1.911 bisitz 6872: display:block;
6873: list-style:none;
6874: padding: 0;
1.870 tempelho 6875: }
6876:
1.795 www 6877: ul.LC_TabContentBigger li {
1.911 bisitz 6878: vertical-align:bottom;
6879: height: 30px;
6880: font-size:110%;
6881: font-weight:bold;
6882: color: #737373;
1.841 tempelho 6883: }
6884:
1.957 onken 6885: ul.LC_TabContentBigger li.active {
6886: position: relative;
6887: top: 1px;
6888: }
6889:
1.870 tempelho 6890: ul.LC_TabContentBigger li a {
1.911 bisitz 6891: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6892: height: 30px;
6893: line-height: 30px;
6894: text-align: center;
6895: display: block;
6896: text-decoration: none;
1.958 onken 6897: outline: none;
1.741 harmsja 6898: }
1.795 www 6899:
1.870 tempelho 6900: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6901: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6902: color:$font;
1.744 ehlerst 6903: }
1.795 www 6904:
1.870 tempelho 6905: ul.LC_TabContentBigger li b {
1.911 bisitz 6906: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6907: display: block;
6908: float: left;
6909: padding: 0 30px;
1.957 onken 6910: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6911: }
6912:
1.956 onken 6913: ul.LC_TabContentBigger li:hover b {
6914: color:$button_hover;
6915: }
6916:
1.870 tempelho 6917: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6918: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6919: color:$font;
1.957 onken 6920: border: 0;
1.741 harmsja 6921: }
1.693 droeschl 6922:
1.870 tempelho 6923:
1.862 bisitz 6924: ul.LC_CourseBreadcrumbs {
6925: background: $sidebg;
1.1020 raeburn 6926: height: 2em;
1.862 bisitz 6927: padding-left: 10px;
1.1020 raeburn 6928: margin: 0;
1.862 bisitz 6929: list-style-position: inside;
6930: }
6931:
1.911 bisitz 6932: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6933: ol#LC_PathBreadcrumbs {
1.911 bisitz 6934: padding-left: 10px;
6935: margin: 0;
1.933 droeschl 6936: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6937: }
6938:
1.911 bisitz 6939: ol#LC_MenuBreadcrumbs li,
6940: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6941: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6942: display: inline;
1.933 droeschl 6943: white-space: normal;
1.693 droeschl 6944: }
6945:
1.823 bisitz 6946: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6947: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6948: text-decoration: none;
6949: font-size:90%;
1.693 droeschl 6950: }
1.795 www 6951:
1.969 droeschl 6952: ol#LC_MenuBreadcrumbs h1 {
6953: display: inline;
6954: font-size: 90%;
6955: line-height: 2.5em;
6956: margin: 0;
6957: padding: 0;
6958: }
6959:
1.795 www 6960: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6961: text-decoration:none;
6962: font-size:100%;
6963: font-weight:bold;
1.693 droeschl 6964: }
1.795 www 6965:
1.840 bisitz 6966: .LC_Box {
1.911 bisitz 6967: border: solid 1px $lg_border_color;
6968: padding: 0 10px 10px 10px;
1.746 neumanie 6969: }
1.795 www 6970:
1.1020 raeburn 6971: .LC_DocsBox {
6972: border: solid 1px $lg_border_color;
6973: padding: 0 0 10px 10px;
6974: }
6975:
1.795 www 6976: .LC_AboutMe_Image {
1.911 bisitz 6977: float:left;
6978: margin-right:10px;
1.747 neumanie 6979: }
1.795 www 6980:
6981: .LC_Clear_AboutMe_Image {
1.911 bisitz 6982: clear:left;
1.747 neumanie 6983: }
1.795 www 6984:
1.721 harmsja 6985: dl.LC_ListStyleClean dt {
1.911 bisitz 6986: padding-right: 5px;
6987: display: table-header-group;
1.693 droeschl 6988: }
6989:
1.721 harmsja 6990: dl.LC_ListStyleClean dd {
1.911 bisitz 6991: display: table-row;
1.693 droeschl 6992: }
6993:
1.721 harmsja 6994: .LC_ListStyleClean,
6995: .LC_ListStyleSimple,
6996: .LC_ListStyleNormal,
1.795 www 6997: .LC_ListStyleSpecial {
1.911 bisitz 6998: /* display:block; */
6999: list-style-position: inside;
7000: list-style-type: none;
7001: overflow: hidden;
7002: padding: 0;
1.693 droeschl 7003: }
7004:
1.721 harmsja 7005: .LC_ListStyleSimple li,
7006: .LC_ListStyleSimple dd,
7007: .LC_ListStyleNormal li,
7008: .LC_ListStyleNormal dd,
7009: .LC_ListStyleSpecial li,
1.795 www 7010: .LC_ListStyleSpecial dd {
1.911 bisitz 7011: margin: 0;
7012: padding: 5px 5px 5px 10px;
7013: clear: both;
1.693 droeschl 7014: }
7015:
1.721 harmsja 7016: .LC_ListStyleClean li,
7017: .LC_ListStyleClean dd {
1.911 bisitz 7018: padding-top: 0;
7019: padding-bottom: 0;
1.693 droeschl 7020: }
7021:
1.721 harmsja 7022: .LC_ListStyleSimple dd,
1.795 www 7023: .LC_ListStyleSimple li {
1.911 bisitz 7024: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7025: }
7026:
1.721 harmsja 7027: .LC_ListStyleSpecial li,
7028: .LC_ListStyleSpecial dd {
1.911 bisitz 7029: list-style-type: none;
7030: background-color: RGB(220, 220, 220);
7031: margin-bottom: 4px;
1.693 droeschl 7032: }
7033:
1.721 harmsja 7034: table.LC_SimpleTable {
1.911 bisitz 7035: margin:5px;
7036: border:solid 1px $lg_border_color;
1.795 www 7037: }
1.693 droeschl 7038:
1.721 harmsja 7039: table.LC_SimpleTable tr {
1.911 bisitz 7040: padding: 0;
7041: border:solid 1px $lg_border_color;
1.693 droeschl 7042: }
1.795 www 7043:
7044: table.LC_SimpleTable thead {
1.911 bisitz 7045: background:rgb(220,220,220);
1.693 droeschl 7046: }
7047:
1.721 harmsja 7048: div.LC_columnSection {
1.911 bisitz 7049: display: block;
7050: clear: both;
7051: overflow: hidden;
7052: margin: 0;
1.693 droeschl 7053: }
7054:
1.721 harmsja 7055: div.LC_columnSection>* {
1.911 bisitz 7056: float: left;
7057: margin: 10px 20px 10px 0;
7058: overflow:hidden;
1.693 droeschl 7059: }
1.721 harmsja 7060:
1.795 www 7061: table em {
1.911 bisitz 7062: font-weight: bold;
7063: font-style: normal;
1.748 schulted 7064: }
1.795 www 7065:
1.779 bisitz 7066: table.LC_tableBrowseRes,
1.795 www 7067: table.LC_tableOfContent {
1.911 bisitz 7068: border:none;
7069: border-spacing: 1px;
7070: padding: 3px;
7071: background-color: #FFFFFF;
7072: font-size: 90%;
1.753 droeschl 7073: }
1.789 droeschl 7074:
1.911 bisitz 7075: table.LC_tableOfContent {
7076: border-collapse: collapse;
1.789 droeschl 7077: }
7078:
1.771 droeschl 7079: table.LC_tableBrowseRes a,
1.768 schulted 7080: table.LC_tableOfContent a {
1.911 bisitz 7081: background-color: transparent;
7082: text-decoration: none;
1.753 droeschl 7083: }
7084:
1.795 www 7085: table.LC_tableOfContent img {
1.911 bisitz 7086: border: none;
7087: height: 1.3em;
7088: vertical-align: text-bottom;
7089: margin-right: 0.3em;
1.753 droeschl 7090: }
1.757 schulted 7091:
1.795 www 7092: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7093: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7094: }
7095:
1.795 www 7096: a#LC_content_toolbar_everything {
1.911 bisitz 7097: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7098: }
7099:
1.795 www 7100: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7101: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7102: }
7103:
1.795 www 7104: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7105: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7106: }
7107:
1.795 www 7108: a#LC_content_toolbar_changefolder {
1.911 bisitz 7109: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7110: }
7111:
1.795 www 7112: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7113: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7114: }
7115:
1.1043 raeburn 7116: a#LC_content_toolbar_edittoplevel {
7117: background-image:url(/res/adm/pages/edittoplevel.gif);
7118: }
7119:
1.795 www 7120: ul#LC_toolbar li a:hover {
1.911 bisitz 7121: background-position: bottom center;
1.757 schulted 7122: }
7123:
1.795 www 7124: ul#LC_toolbar {
1.911 bisitz 7125: padding: 0;
7126: margin: 2px;
7127: list-style:none;
7128: position:relative;
7129: background-color:white;
1.1082 raeburn 7130: overflow: auto;
1.757 schulted 7131: }
7132:
1.795 www 7133: ul#LC_toolbar li {
1.911 bisitz 7134: border:1px solid white;
7135: padding: 0;
7136: margin: 0;
7137: float: left;
7138: display:inline;
7139: vertical-align:middle;
1.1082 raeburn 7140: white-space: nowrap;
1.911 bisitz 7141: }
1.757 schulted 7142:
1.783 amueller 7143:
1.795 www 7144: a.LC_toolbarItem {
1.911 bisitz 7145: display:block;
7146: padding: 0;
7147: margin: 0;
7148: height: 32px;
7149: width: 32px;
7150: color:white;
7151: border: none;
7152: background-repeat:no-repeat;
7153: background-color:transparent;
1.757 schulted 7154: }
7155:
1.915 droeschl 7156: ul.LC_funclist {
7157: margin: 0;
7158: padding: 0.5em 1em 0.5em 0;
7159: }
7160:
1.933 droeschl 7161: ul.LC_funclist > li:first-child {
7162: font-weight:bold;
7163: margin-left:0.8em;
7164: }
7165:
1.915 droeschl 7166: ul.LC_funclist + ul.LC_funclist {
7167: /*
7168: left border as a seperator if we have more than
7169: one list
7170: */
7171: border-left: 1px solid $sidebg;
7172: /*
7173: this hides the left border behind the border of the
7174: outer box if element is wrapped to the next 'line'
7175: */
7176: margin-left: -1px;
7177: }
7178:
1.843 bisitz 7179: ul.LC_funclist li {
1.915 droeschl 7180: display: inline;
1.782 bisitz 7181: white-space: nowrap;
1.915 droeschl 7182: margin: 0 0 0 25px;
7183: line-height: 150%;
1.782 bisitz 7184: }
7185:
1.974 wenzelju 7186: .LC_hidden {
7187: display: none;
7188: }
7189:
1.1030 www 7190: .LCmodal-overlay {
7191: position:fixed;
7192: top:0;
7193: right:0;
7194: bottom:0;
7195: left:0;
7196: height:100%;
7197: width:100%;
7198: margin:0;
7199: padding:0;
7200: background:#999;
7201: opacity:.75;
7202: filter: alpha(opacity=75);
7203: -moz-opacity: 0.75;
7204: z-index:101;
7205: }
7206:
7207: * html .LCmodal-overlay {
7208: position: absolute;
7209: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7210: }
7211:
7212: .LCmodal-window {
7213: position:fixed;
7214: top:50%;
7215: left:50%;
7216: margin:0;
7217: padding:0;
7218: z-index:102;
7219: }
7220:
7221: * html .LCmodal-window {
7222: position:absolute;
7223: }
7224:
7225: .LCclose-window {
7226: position:absolute;
7227: width:32px;
7228: height:32px;
7229: right:8px;
7230: top:8px;
7231: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7232: text-indent:-99999px;
7233: overflow:hidden;
7234: cursor:pointer;
7235: }
7236:
1.1100 raeburn 7237: /*
7238: styles used by TTH when "Default set of options to pass to tth/m
7239: when converting TeX" in course settings has been set
7240:
7241: option passed: -t
7242:
7243: */
7244:
7245: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7246: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7247: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7248: td div.norm {line-height:normal;}
7249:
7250: /*
7251: option passed -y3
7252: */
7253:
7254: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7255: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7256: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7257:
1.343 albertel 7258: END
7259: }
7260:
1.306 albertel 7261: =pod
7262:
7263: =item * &headtag()
7264:
7265: Returns a uniform footer for LON-CAPA web pages.
7266:
1.307 albertel 7267: Inputs: $title - optional title for the head
7268: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7269: $args - optional arguments
1.319 albertel 7270: force_register - if is true call registerurl so the remote is
7271: informed
1.415 albertel 7272: redirect -> array ref of
7273: 1- seconds before redirect occurs
7274: 2- url to redirect to
7275: 3- whether the side effect should occur
1.315 albertel 7276: (side effect of setting
7277: $env{'internal.head.redirect'} to the url
7278: redirected too)
1.352 albertel 7279: domain -> force to color decorate a page for a specific
7280: domain
7281: function -> force usage of a specific rolish color scheme
7282: bgcolor -> override the default page bgcolor
1.460 albertel 7283: no_auto_mt_title
7284: -> prevent &mt()ing the title arg
1.464 albertel 7285:
1.306 albertel 7286: =cut
7287:
7288: sub headtag {
1.313 albertel 7289: my ($title,$head_extra,$args) = @_;
1.306 albertel 7290:
1.363 albertel 7291: my $function = $args->{'function'} || &get_users_function();
7292: my $domain = $args->{'domain'} || &determinedomain();
7293: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 7294: my $httphost = $args->{'use_absolute'};
1.418 albertel 7295: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7296: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7297: #time(),
1.418 albertel 7298: $env{'environment.color.timestamp'},
1.363 albertel 7299: $function,$domain,$bgcolor);
7300:
1.369 www 7301: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7302:
1.308 albertel 7303: my $result =
7304: '<head>'.
1.1160 raeburn 7305: &font_settings($args);
1.319 albertel 7306:
1.1188 ! raeburn 7307: my $inhibitprint;
! 7308: if ($args->{'print_suppress'}) {
! 7309: $inhibitprint = &print_suppression();
! 7310: }
1.1064 raeburn 7311:
1.461 albertel 7312: if (!$args->{'frameset'}) {
7313: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7314: }
1.962 droeschl 7315: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7316: $result .= Apache::lonxml::display_title();
1.319 albertel 7317: }
1.436 albertel 7318: if (!$args->{'no_nav_bar'}
7319: && !$args->{'only_body'}
7320: && !$args->{'frameset'}) {
1.1154 raeburn 7321: $result .= &help_menu_js($httphost);
1.1032 www 7322: $result.=&modal_window();
1.1038 www 7323: $result.=&togglebox_script();
1.1034 www 7324: $result.=&wishlist_window();
1.1041 www 7325: $result.=&LCprogressbarUpdate_script();
1.1034 www 7326: } else {
7327: if ($args->{'add_modal'}) {
7328: $result.=&modal_window();
7329: }
7330: if ($args->{'add_wishlist'}) {
7331: $result.=&wishlist_window();
7332: }
1.1038 www 7333: if ($args->{'add_togglebox'}) {
7334: $result.=&togglebox_script();
7335: }
1.1041 www 7336: if ($args->{'add_progressbar'}) {
7337: $result.=&LCprogressbarUpdate_script();
7338: }
1.436 albertel 7339: }
1.314 albertel 7340: if (ref($args->{'redirect'})) {
1.414 albertel 7341: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7342: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7343: if (!$inhibit_continue) {
7344: $env{'internal.head.redirect'} = $url;
7345: }
1.313 albertel 7346: $result.=<<ADDMETA
7347: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7348: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7349: ADDMETA
7350: }
1.306 albertel 7351: if (!defined($title)) {
7352: $title = 'The LearningOnline Network with CAPA';
7353: }
1.460 albertel 7354: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7355: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 7356: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7357: if (!$args->{'frameset'}) {
7358: $result .= ' /';
7359: }
7360: $result .= '>'
1.1064 raeburn 7361: .$inhibitprint
1.414 albertel 7362: .$head_extra;
1.1137 raeburn 7363: if ($env{'browser.mobile'}) {
7364: $result .= '
7365: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7366: <meta name="apple-mobile-web-app-capable" content="yes" />';
7367: }
1.962 droeschl 7368: return $result.'</head>';
1.306 albertel 7369: }
7370:
7371: =pod
7372:
1.340 albertel 7373: =item * &font_settings()
7374:
7375: Returns neccessary <meta> to set the proper encoding
7376:
1.1160 raeburn 7377: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7378:
7379: =cut
7380:
7381: sub font_settings {
1.1160 raeburn 7382: my ($args) = @_;
1.340 albertel 7383: my $headerstring='';
1.1160 raeburn 7384: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7385: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 7386: $headerstring.=
7387: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7388: if (!$args->{'frameset'}) {
7389: $headerstring.= ' /';
7390: }
7391: $headerstring .= '>'."\n";
1.340 albertel 7392: }
7393: return $headerstring;
7394: }
7395:
1.341 albertel 7396: =pod
7397:
1.1064 raeburn 7398: =item * &print_suppression()
7399:
7400: In course context returns css which causes the body to be blank when media="print",
7401: if printout generation is unavailable for the current resource.
7402:
7403: This could be because:
7404:
7405: (a) printstartdate is in the future
7406:
7407: (b) printenddate is in the past
7408:
7409: (c) there is an active exam block with "printout"
7410: functionality blocked
7411:
7412: Users with pav, pfo or evb privileges are exempt.
7413:
7414: Inputs: none
7415:
7416: =cut
7417:
7418:
7419: sub print_suppression {
7420: my $noprint;
7421: if ($env{'request.course.id'}) {
7422: my $scope = $env{'request.course.id'};
7423: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7424: (&Apache::lonnet::allowed('pfo',$scope))) {
7425: return;
7426: }
7427: if ($env{'request.course.sec'} ne '') {
7428: $scope .= "/$env{'request.course.sec'}";
7429: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7430: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7431: return;
1.1064 raeburn 7432: }
7433: }
7434: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7435: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7436: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7437: if ($blocked) {
7438: my $checkrole = "cm./$cdom/$cnum";
7439: if ($env{'request.course.sec'} ne '') {
7440: $checkrole .= "/$env{'request.course.sec'}";
7441: }
7442: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7443: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7444: $noprint = 1;
7445: }
7446: }
7447: unless ($noprint) {
7448: my $symb = &Apache::lonnet::symbread();
7449: if ($symb ne '') {
7450: my $navmap = Apache::lonnavmaps::navmap->new();
7451: if (ref($navmap)) {
7452: my $res = $navmap->getBySymb($symb);
7453: if (ref($res)) {
7454: if (!$res->resprintable()) {
7455: $noprint = 1;
7456: }
7457: }
7458: }
7459: }
7460: }
7461: if ($noprint) {
7462: return <<"ENDSTYLE";
7463: <style type="text/css" media="print">
7464: body { display:none }
7465: </style>
7466: ENDSTYLE
7467: }
7468: }
7469: return;
7470: }
7471:
7472: =pod
7473:
1.341 albertel 7474: =item * &xml_begin()
7475:
7476: Returns the needed doctype and <html>
7477:
7478: Inputs: none
7479:
7480: =cut
7481:
7482: sub xml_begin {
1.1168 raeburn 7483: my ($is_frameset) = @_;
1.341 albertel 7484: my $output='';
7485:
7486: if ($env{'browser.mathml'}) {
7487: $output='<?xml version="1.0"?>'
7488: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7489: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7490:
7491: # .'<!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">] >'
7492: .'<!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">'
7493: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7494: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 7495: } elsif ($is_frameset) {
7496: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7497: '<html>'."\n";
1.341 albertel 7498: } else {
1.1168 raeburn 7499: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7500: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7501: }
7502: return $output;
7503: }
1.340 albertel 7504:
7505: =pod
7506:
1.306 albertel 7507: =item * &start_page()
7508:
7509: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7510:
1.648 raeburn 7511: Inputs:
7512:
7513: =over 4
7514:
7515: $title - optional title for the page
7516:
7517: $head_extra - optional extra HTML to incude inside the <head>
7518:
7519: $args - additional optional args supported are:
7520:
7521: =over 8
7522:
7523: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7524: arg on
1.814 bisitz 7525: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7526: add_entries -> additional attributes to add to the <body>
7527: domain -> force to color decorate a page for a
1.317 albertel 7528: specific domain
1.648 raeburn 7529: function -> force usage of a specific rolish color
1.317 albertel 7530: scheme
1.648 raeburn 7531: redirect -> see &headtag()
7532: bgcolor -> override the default page bg color
7533: js_ready -> return a string ready for being used in
1.317 albertel 7534: a javascript writeln
1.648 raeburn 7535: html_encode -> return a string ready for being used in
1.320 albertel 7536: a html attribute
1.648 raeburn 7537: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7538: $forcereg arg
1.648 raeburn 7539: frameset -> if true will start with a <frameset>
1.330 albertel 7540: rather than <body>
1.648 raeburn 7541: skip_phases -> hash ref of
1.338 albertel 7542: head -> skip the <html><head> generation
7543: body -> skip all <body> generation
1.648 raeburn 7544: no_auto_mt_title -> prevent &mt()ing the title arg
7545: inherit_jsmath -> when creating popup window in a page,
7546: should it have jsmath forced on by the
7547: current page
1.867 kalberla 7548: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7549: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 7550: group -> includes the current group, if page is for a
7551: specific group
1.361 albertel 7552:
1.648 raeburn 7553: =back
1.460 albertel 7554:
1.648 raeburn 7555: =back
1.562 albertel 7556:
1.306 albertel 7557: =cut
7558:
7559: sub start_page {
1.309 albertel 7560: my ($title,$head_extra,$args) = @_;
1.318 albertel 7561: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7562:
1.315 albertel 7563: $env{'internal.start_page'}++;
1.1096 raeburn 7564: my ($result,@advtools);
1.964 droeschl 7565:
1.338 albertel 7566: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 7567: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 7568: }
7569:
7570: if (! exists($args->{'skip_phases'}{'body'}) ) {
7571: if ($args->{'frameset'}) {
7572: my $attr_string = &make_attr_string($args->{'force_register'},
7573: $args->{'add_entries'});
7574: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7575: } else {
7576: $result .=
7577: &bodytag($title,
7578: $args->{'function'}, $args->{'add_entries'},
7579: $args->{'only_body'}, $args->{'domain'},
7580: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 7581: $args->{'bgcolor'}, $args,
7582: \@advtools);
1.831 bisitz 7583: }
1.330 albertel 7584: }
1.338 albertel 7585:
1.315 albertel 7586: if ($args->{'js_ready'}) {
1.713 kaisler 7587: $result = &js_ready($result);
1.315 albertel 7588: }
1.320 albertel 7589: if ($args->{'html_encode'}) {
1.713 kaisler 7590: $result = &html_encode($result);
7591: }
7592:
1.813 bisitz 7593: # Preparation for new and consistent functionlist at top of screen
7594: # if ($args->{'functionlist'}) {
7595: # $result .= &build_functionlist();
7596: #}
7597:
1.964 droeschl 7598: # Don't add anything more if only_body wanted or in const space
7599: return $result if $args->{'only_body'}
7600: || $env{'request.state'} eq 'construct';
1.813 bisitz 7601:
7602: #Breadcrumbs
1.758 kaisler 7603: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7604: &Apache::lonhtmlcommon::clear_breadcrumbs();
7605: #if any br links exists, add them to the breadcrumbs
7606: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7607: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7608: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7609: }
7610: }
1.1096 raeburn 7611: # if @advtools array contains items add then to the breadcrumbs
7612: if (@advtools > 0) {
7613: &Apache::lonmenu::advtools_crumbs(@advtools);
7614: }
1.758 kaisler 7615:
7616: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7617: if(exists($args->{'bread_crumbs_component'})){
7618: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7619: }else{
7620: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7621: }
1.320 albertel 7622: }
1.315 albertel 7623: return $result;
1.306 albertel 7624: }
7625:
7626: sub end_page {
1.315 albertel 7627: my ($args) = @_;
7628: $env{'internal.end_page'}++;
1.330 albertel 7629: my $result;
1.335 albertel 7630: if ($args->{'discussion'}) {
7631: my ($target,$parser);
7632: if (ref($args->{'discussion'})) {
7633: ($target,$parser) =($args->{'discussion'}{'target'},
7634: $args->{'discussion'}{'parser'});
7635: }
7636: $result .= &Apache::lonxml::xmlend($target,$parser);
7637: }
1.330 albertel 7638: if ($args->{'frameset'}) {
7639: $result .= '</frameset>';
7640: } else {
1.635 raeburn 7641: $result .= &endbodytag($args);
1.330 albertel 7642: }
1.1080 raeburn 7643: unless ($args->{'notbody'}) {
7644: $result .= "\n</html>";
7645: }
1.330 albertel 7646:
1.315 albertel 7647: if ($args->{'js_ready'}) {
1.317 albertel 7648: $result = &js_ready($result);
1.315 albertel 7649: }
1.335 albertel 7650:
1.320 albertel 7651: if ($args->{'html_encode'}) {
7652: $result = &html_encode($result);
7653: }
1.335 albertel 7654:
1.315 albertel 7655: return $result;
7656: }
7657:
1.1034 www 7658: sub wishlist_window {
7659: return(<<'ENDWISHLIST');
1.1046 raeburn 7660: <script type="text/javascript">
1.1034 www 7661: // <![CDATA[
7662: // <!-- BEGIN LON-CAPA Internal
7663: function set_wishlistlink(title, path) {
7664: if (!title) {
7665: title = document.title;
7666: title = title.replace(/^LON-CAPA /,'');
7667: }
1.1175 raeburn 7668: title = encodeURIComponent(title);
1.1034 www 7669: if (!path) {
7670: path = location.pathname;
7671: }
1.1175 raeburn 7672: path = encodeURIComponent(path);
1.1034 www 7673: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7674: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7675: }
7676: // END LON-CAPA Internal -->
7677: // ]]>
7678: </script>
7679: ENDWISHLIST
7680: }
7681:
1.1030 www 7682: sub modal_window {
7683: return(<<'ENDMODAL');
1.1046 raeburn 7684: <script type="text/javascript">
1.1030 www 7685: // <![CDATA[
7686: // <!-- BEGIN LON-CAPA Internal
7687: var modalWindow = {
7688: parent:"body",
7689: windowId:null,
7690: content:null,
7691: width:null,
7692: height:null,
7693: close:function()
7694: {
7695: $(".LCmodal-window").remove();
7696: $(".LCmodal-overlay").remove();
7697: },
7698: open:function()
7699: {
7700: var modal = "";
7701: modal += "<div class=\"LCmodal-overlay\"></div>";
7702: 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;\">";
7703: modal += this.content;
7704: modal += "</div>";
7705:
7706: $(this.parent).append(modal);
7707:
7708: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7709: $(".LCclose-window").click(function(){modalWindow.close();});
7710: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7711: }
7712: };
1.1140 raeburn 7713: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7714: {
7715: modalWindow.windowId = "myModal";
7716: modalWindow.width = width;
7717: modalWindow.height = height;
1.1140 raeburn 7718: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7719: modalWindow.open();
7720: };
7721: // END LON-CAPA Internal -->
7722: // ]]>
7723: </script>
7724: ENDMODAL
7725: }
7726:
7727: sub modal_link {
1.1140 raeburn 7728: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7729: unless ($width) { $width=480; }
7730: unless ($height) { $height=400; }
1.1031 www 7731: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 7732: unless ($transparency) { $transparency='true'; }
7733:
1.1074 raeburn 7734: my $target_attr;
7735: if (defined($target)) {
7736: $target_attr = 'target="'.$target.'"';
7737: }
7738: return <<"ENDLINK";
1.1140 raeburn 7739: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7740: $linktext</a>
7741: ENDLINK
1.1030 www 7742: }
7743:
1.1032 www 7744: sub modal_adhoc_script {
7745: my ($funcname,$width,$height,$content)=@_;
7746: return (<<ENDADHOC);
1.1046 raeburn 7747: <script type="text/javascript">
1.1032 www 7748: // <![CDATA[
7749: var $funcname = function()
7750: {
7751: modalWindow.windowId = "myModal";
7752: modalWindow.width = $width;
7753: modalWindow.height = $height;
7754: modalWindow.content = '$content';
7755: modalWindow.open();
7756: };
7757: // ]]>
7758: </script>
7759: ENDADHOC
7760: }
7761:
1.1041 www 7762: sub modal_adhoc_inner {
7763: my ($funcname,$width,$height,$content)=@_;
7764: my $innerwidth=$width-20;
7765: $content=&js_ready(
1.1140 raeburn 7766: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
7767: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7768: $content.
1.1041 www 7769: &end_scrollbox().
1.1140 raeburn 7770: &end_page()
1.1041 www 7771: );
7772: return &modal_adhoc_script($funcname,$width,$height,$content);
7773: }
7774:
7775: sub modal_adhoc_window {
7776: my ($funcname,$width,$height,$content,$linktext)=@_;
7777: return &modal_adhoc_inner($funcname,$width,$height,$content).
7778: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7779: }
7780:
7781: sub modal_adhoc_launch {
7782: my ($funcname,$width,$height,$content)=@_;
7783: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7784: <script type="text/javascript">
7785: // <![CDATA[
7786: $funcname();
7787: // ]]>
7788: </script>
7789: ENDLAUNCH
7790: }
7791:
7792: sub modal_adhoc_close {
7793: return (<<ENDCLOSE);
7794: <script type="text/javascript">
7795: // <![CDATA[
7796: modalWindow.close();
7797: // ]]>
7798: </script>
7799: ENDCLOSE
7800: }
7801:
1.1038 www 7802: sub togglebox_script {
7803: return(<<ENDTOGGLE);
7804: <script type="text/javascript">
7805: // <![CDATA[
7806: function LCtoggleDisplay(id,hidetext,showtext) {
7807: link = document.getElementById(id + "link").childNodes[0];
7808: with (document.getElementById(id).style) {
7809: if (display == "none" ) {
7810: display = "inline";
7811: link.nodeValue = hidetext;
7812: } else {
7813: display = "none";
7814: link.nodeValue = showtext;
7815: }
7816: }
7817: }
7818: // ]]>
7819: </script>
7820: ENDTOGGLE
7821: }
7822:
1.1039 www 7823: sub start_togglebox {
7824: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7825: unless ($heading) { $heading=''; } else { $heading.=' '; }
7826: unless ($showtext) { $showtext=&mt('show'); }
7827: unless ($hidetext) { $hidetext=&mt('hide'); }
7828: unless ($headerbg) { $headerbg='#FFFFFF'; }
7829: return &start_data_table().
7830: &start_data_table_header_row().
7831: '<td bgcolor="'.$headerbg.'">'.$heading.
7832: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7833: $showtext.'\')">'.$showtext.'</a>]</td>'.
7834: &end_data_table_header_row().
7835: '<tr id="'.$id.'" style="display:none""><td>';
7836: }
7837:
7838: sub end_togglebox {
7839: return '</td></tr>'.&end_data_table();
7840: }
7841:
1.1041 www 7842: sub LCprogressbar_script {
1.1045 www 7843: my ($id)=@_;
1.1041 www 7844: return(<<ENDPROGRESS);
7845: <script type="text/javascript">
7846: // <![CDATA[
1.1045 www 7847: \$('#progressbar$id').progressbar({
1.1041 www 7848: value: 0,
7849: change: function(event, ui) {
7850: var newVal = \$(this).progressbar('option', 'value');
7851: \$('.pblabel', this).text(LCprogressTxt);
7852: }
7853: });
7854: // ]]>
7855: </script>
7856: ENDPROGRESS
7857: }
7858:
7859: sub LCprogressbarUpdate_script {
7860: return(<<ENDPROGRESSUPDATE);
7861: <style type="text/css">
7862: .ui-progressbar { position:relative; }
7863: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7864: </style>
7865: <script type="text/javascript">
7866: // <![CDATA[
1.1045 www 7867: var LCprogressTxt='---';
7868:
7869: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7870: LCprogressTxt=progresstext;
1.1045 www 7871: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7872: }
7873: // ]]>
7874: </script>
7875: ENDPROGRESSUPDATE
7876: }
7877:
1.1042 www 7878: my $LClastpercent;
1.1045 www 7879: my $LCidcnt;
7880: my $LCcurrentid;
1.1042 www 7881:
1.1041 www 7882: sub LCprogressbar {
1.1042 www 7883: my ($r)=(@_);
7884: $LClastpercent=0;
1.1045 www 7885: $LCidcnt++;
7886: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7887: my $starting=&mt('Starting');
7888: my $content=(<<ENDPROGBAR);
1.1045 www 7889: <div id="progressbar$LCcurrentid">
1.1041 www 7890: <span class="pblabel">$starting</span>
7891: </div>
7892: ENDPROGBAR
1.1045 www 7893: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7894: }
7895:
7896: sub LCprogressbarUpdate {
1.1042 www 7897: my ($r,$val,$text)=@_;
7898: unless ($val) {
7899: if ($LClastpercent) {
7900: $val=$LClastpercent;
7901: } else {
7902: $val=0;
7903: }
7904: }
1.1041 www 7905: if ($val<0) { $val=0; }
7906: if ($val>100) { $val=0; }
1.1042 www 7907: $LClastpercent=$val;
1.1041 www 7908: unless ($text) { $text=$val.'%'; }
7909: $text=&js_ready($text);
1.1044 www 7910: &r_print($r,<<ENDUPDATE);
1.1041 www 7911: <script type="text/javascript">
7912: // <![CDATA[
1.1045 www 7913: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7914: // ]]>
7915: </script>
7916: ENDUPDATE
1.1035 www 7917: }
7918:
1.1042 www 7919: sub LCprogressbarClose {
7920: my ($r)=@_;
7921: $LClastpercent=0;
1.1044 www 7922: &r_print($r,<<ENDCLOSE);
1.1042 www 7923: <script type="text/javascript">
7924: // <![CDATA[
1.1045 www 7925: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7926: // ]]>
7927: </script>
7928: ENDCLOSE
1.1044 www 7929: }
7930:
7931: sub r_print {
7932: my ($r,$to_print)=@_;
7933: if ($r) {
7934: $r->print($to_print);
7935: $r->rflush();
7936: } else {
7937: print($to_print);
7938: }
1.1042 www 7939: }
7940:
1.320 albertel 7941: sub html_encode {
7942: my ($result) = @_;
7943:
1.322 albertel 7944: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7945:
7946: return $result;
7947: }
1.1044 www 7948:
1.317 albertel 7949: sub js_ready {
7950: my ($result) = @_;
7951:
1.323 albertel 7952: $result =~ s/[\n\r]/ /xmsg;
7953: $result =~ s/\\/\\\\/xmsg;
7954: $result =~ s/'/\\'/xmsg;
1.372 albertel 7955: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7956:
7957: return $result;
7958: }
7959:
1.315 albertel 7960: sub validate_page {
7961: if ( exists($env{'internal.start_page'})
1.316 albertel 7962: && $env{'internal.start_page'} > 1) {
7963: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7964: $env{'internal.start_page'}.' '.
1.316 albertel 7965: $ENV{'request.filename'});
1.315 albertel 7966: }
7967: if ( exists($env{'internal.end_page'})
1.316 albertel 7968: && $env{'internal.end_page'} > 1) {
7969: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7970: $env{'internal.end_page'}.' '.
1.316 albertel 7971: $env{'request.filename'});
1.315 albertel 7972: }
7973: if ( exists($env{'internal.start_page'})
7974: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7975: &Apache::lonnet::logthis('start_page called without end_page '.
7976: $env{'request.filename'});
1.315 albertel 7977: }
7978: if ( ! exists($env{'internal.start_page'})
7979: && exists($env{'internal.end_page'})) {
1.316 albertel 7980: &Apache::lonnet::logthis('end_page called without start_page'.
7981: $env{'request.filename'});
1.315 albertel 7982: }
1.306 albertel 7983: }
1.315 albertel 7984:
1.996 www 7985:
7986: sub start_scrollbox {
1.1140 raeburn 7987: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 7988: unless ($outerwidth) { $outerwidth='520px'; }
7989: unless ($width) { $width='500px'; }
7990: unless ($height) { $height='200px'; }
1.1075 raeburn 7991: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7992: if ($id ne '') {
1.1140 raeburn 7993: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 7994: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 7995: }
1.1075 raeburn 7996: if ($bgcolor ne '') {
7997: $tdcol = "background-color: $bgcolor;";
7998: }
1.1137 raeburn 7999: my $nicescroll_js;
8000: if ($env{'browser.mobile'}) {
1.1140 raeburn 8001: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8002: }
8003: return <<"END";
8004: $nicescroll_js
8005:
8006: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
8007: <div style="overflow:auto; width:$width; height:$height;"$div_id>
8008: END
8009: }
8010:
8011: sub end_scrollbox {
8012: return '</div></td></tr></table>';
8013: }
8014:
8015: sub nicescroll_javascript {
8016: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8017: my %options;
8018: if (ref($cursor) eq 'HASH') {
8019: %options = %{$cursor};
8020: }
8021: unless ($options{'railalign'} =~ /^left|right$/) {
8022: $options{'railalign'} = 'left';
8023: }
8024: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8025: my $function = &get_users_function();
8026: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 8027: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 8028: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 8029: }
1.1140 raeburn 8030: }
8031: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8032: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 8033: $options{'cursoropacity'}='1.0';
8034: }
1.1140 raeburn 8035: } else {
8036: $options{'cursoropacity'}='1.0';
8037: }
8038: if ($options{'cursorfixedheight'} eq 'none') {
8039: delete($options{'cursorfixedheight'});
8040: } else {
8041: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8042: }
8043: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8044: delete($options{'railoffset'});
8045: }
8046: my @niceoptions;
8047: while (my($key,$value) = each(%options)) {
8048: if ($value =~ /^\{.+\}$/) {
8049: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 8050: } else {
1.1140 raeburn 8051: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 8052: }
1.1140 raeburn 8053: }
8054: my $nicescroll_js = '
1.1137 raeburn 8055: $(document).ready(
1.1140 raeburn 8056: function() {
8057: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8058: }
1.1137 raeburn 8059: );
8060: ';
1.1140 raeburn 8061: if ($framecheck) {
8062: $nicescroll_js .= '
8063: function expand_div(caller) {
8064: if (top === self) {
8065: document.getElementById("'.$id.'").style.width = "auto";
8066: document.getElementById("'.$id.'").style.height = "auto";
8067: } else {
8068: try {
8069: if (parent.frames) {
8070: if (parent.frames.length > 1) {
8071: var framesrc = parent.frames[1].location.href;
8072: var currsrc = framesrc.replace(/\#.*$/,"");
8073: if ((caller == "search") || (currsrc == "'.$location.'")) {
8074: document.getElementById("'.$id.'").style.width = "auto";
8075: document.getElementById("'.$id.'").style.height = "auto";
8076: }
8077: }
8078: }
8079: } catch (e) {
8080: return;
8081: }
1.1137 raeburn 8082: }
1.1140 raeburn 8083: return;
1.996 www 8084: }
1.1140 raeburn 8085: ';
8086: }
8087: if ($needjsready) {
8088: $nicescroll_js = '
8089: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8090: } else {
8091: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8092: }
8093: return $nicescroll_js;
1.996 www 8094: }
8095:
1.318 albertel 8096: sub simple_error_page {
1.1150 bisitz 8097: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 8098: if (ref($args) eq 'HASH') {
8099: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8100: } else {
8101: $msg = &mt($msg);
8102: }
1.1150 bisitz 8103:
1.318 albertel 8104: my $page =
8105: &Apache::loncommon::start_page($title).
1.1150 bisitz 8106: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8107: &Apache::loncommon::end_page();
8108: if (ref($r)) {
8109: $r->print($page);
1.327 albertel 8110: return;
1.318 albertel 8111: }
8112: return $page;
8113: }
1.347 albertel 8114:
8115: {
1.610 albertel 8116: my @row_count;
1.961 onken 8117:
8118: sub start_data_table_count {
8119: unshift(@row_count, 0);
8120: return;
8121: }
8122:
8123: sub end_data_table_count {
8124: shift(@row_count);
8125: return;
8126: }
8127:
1.347 albertel 8128: sub start_data_table {
1.1018 raeburn 8129: my ($add_class,$id) = @_;
1.422 albertel 8130: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8131: my $table_id;
8132: if (defined($id)) {
8133: $table_id = ' id="'.$id.'"';
8134: }
1.961 onken 8135: &start_data_table_count();
1.1018 raeburn 8136: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8137: }
8138:
8139: sub end_data_table {
1.961 onken 8140: &end_data_table_count();
1.389 albertel 8141: return '</table>'."\n";;
1.347 albertel 8142: }
8143:
8144: sub start_data_table_row {
1.974 wenzelju 8145: my ($add_class, $id) = @_;
1.610 albertel 8146: $row_count[0]++;
8147: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8148: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8149: $id = (' id="'.$id.'"') unless ($id eq '');
8150: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8151: }
1.471 banghart 8152:
8153: sub continue_data_table_row {
1.974 wenzelju 8154: my ($add_class, $id) = @_;
1.610 albertel 8155: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8156: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8157: $id = (' id="'.$id.'"') unless ($id eq '');
8158: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8159: }
1.347 albertel 8160:
8161: sub end_data_table_row {
1.389 albertel 8162: return '</tr>'."\n";;
1.347 albertel 8163: }
1.367 www 8164:
1.421 albertel 8165: sub start_data_table_empty_row {
1.707 bisitz 8166: # $row_count[0]++;
1.421 albertel 8167: return '<tr class="LC_empty_row" >'."\n";;
8168: }
8169:
8170: sub end_data_table_empty_row {
8171: return '</tr>'."\n";;
8172: }
8173:
1.367 www 8174: sub start_data_table_header_row {
1.389 albertel 8175: return '<tr class="LC_header_row">'."\n";;
1.367 www 8176: }
8177:
8178: sub end_data_table_header_row {
1.389 albertel 8179: return '</tr>'."\n";;
1.367 www 8180: }
1.890 droeschl 8181:
8182: sub data_table_caption {
8183: my $caption = shift;
8184: return "<caption class=\"LC_caption\">$caption</caption>";
8185: }
1.347 albertel 8186: }
8187:
1.548 albertel 8188: =pod
8189:
8190: =item * &inhibit_menu_check($arg)
8191:
8192: Checks for a inhibitmenu state and generates output to preserve it
8193:
8194: Inputs: $arg - can be any of
8195: - undef - in which case the return value is a string
8196: to add into arguments list of a uri
8197: - 'input' - in which case the return value is a HTML
8198: <form> <input> field of type hidden to
8199: preserve the value
8200: - a url - in which case the return value is the url with
8201: the neccesary cgi args added to preserve the
8202: inhibitmenu state
8203: - a ref to a url - no return value, but the string is
8204: updated to include the neccessary cgi
8205: args to preserve the inhibitmenu state
8206:
8207: =cut
8208:
8209: sub inhibit_menu_check {
8210: my ($arg) = @_;
8211: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8212: if ($arg eq 'input') {
8213: if ($env{'form.inhibitmenu'}) {
8214: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8215: } else {
8216: return
8217: }
8218: }
8219: if ($env{'form.inhibitmenu'}) {
8220: if (ref($arg)) {
8221: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8222: } elsif ($arg eq '') {
8223: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8224: } else {
8225: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8226: }
8227: }
8228: if (!ref($arg)) {
8229: return $arg;
8230: }
8231: }
8232:
1.251 albertel 8233: ###############################################
1.182 matthew 8234:
8235: =pod
8236:
1.549 albertel 8237: =back
8238:
8239: =head1 User Information Routines
8240:
8241: =over 4
8242:
1.405 albertel 8243: =item * &get_users_function()
1.182 matthew 8244:
8245: Used by &bodytag to determine the current users primary role.
8246: Returns either 'student','coordinator','admin', or 'author'.
8247:
8248: =cut
8249:
8250: ###############################################
8251: sub get_users_function {
1.815 tempelho 8252: my $function = 'norole';
1.818 tempelho 8253: if ($env{'request.role'}=~/^(st)/) {
8254: $function='student';
8255: }
1.907 raeburn 8256: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8257: $function='coordinator';
8258: }
1.258 albertel 8259: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8260: $function='admin';
8261: }
1.826 bisitz 8262: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8263: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8264: $function='author';
8265: }
8266: return $function;
1.54 www 8267: }
1.99 www 8268:
8269: ###############################################
8270:
1.233 raeburn 8271: =pod
8272:
1.821 raeburn 8273: =item * &show_course()
8274:
8275: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8276: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8277:
8278: Inputs:
8279: None
8280:
8281: Outputs:
8282: Scalar: 1 if 'Course' to be used, 0 otherwise.
8283:
8284: =cut
8285:
8286: ###############################################
8287: sub show_course {
8288: my $course = !$env{'user.adv'};
8289: if (!$env{'user.adv'}) {
8290: foreach my $env (keys(%env)) {
8291: next if ($env !~ m/^user\.priv\./);
8292: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8293: $course = 0;
8294: last;
8295: }
8296: }
8297: }
8298: return $course;
8299: }
8300:
8301: ###############################################
8302:
8303: =pod
8304:
1.542 raeburn 8305: =item * &check_user_status()
1.274 raeburn 8306:
8307: Determines current status of supplied role for a
8308: specific user. Roles can be active, previous or future.
8309:
8310: Inputs:
8311: user's domain, user's username, course's domain,
1.375 raeburn 8312: course's number, optional section ID.
1.274 raeburn 8313:
8314: Outputs:
8315: role status: active, previous or future.
8316:
8317: =cut
8318:
8319: sub check_user_status {
1.412 raeburn 8320: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8321: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8322: my @uroles = keys %userinfo;
8323: my $srchstr;
8324: my $active_chk = 'none';
1.412 raeburn 8325: my $now = time;
1.274 raeburn 8326: if (@uroles > 0) {
1.908 raeburn 8327: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8328: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8329: } else {
1.412 raeburn 8330: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8331: }
8332: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8333: my $role_end = 0;
8334: my $role_start = 0;
8335: $active_chk = 'active';
1.412 raeburn 8336: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8337: $role_end = $1;
8338: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8339: $role_start = $1;
1.274 raeburn 8340: }
8341: }
8342: if ($role_start > 0) {
1.412 raeburn 8343: if ($now < $role_start) {
1.274 raeburn 8344: $active_chk = 'future';
8345: }
8346: }
8347: if ($role_end > 0) {
1.412 raeburn 8348: if ($now > $role_end) {
1.274 raeburn 8349: $active_chk = 'previous';
8350: }
8351: }
8352: }
8353: }
8354: return $active_chk;
8355: }
8356:
8357: ###############################################
8358:
8359: =pod
8360:
1.405 albertel 8361: =item * &get_sections()
1.233 raeburn 8362:
8363: Determines all the sections for a course including
8364: sections with students and sections containing other roles.
1.419 raeburn 8365: Incoming parameters:
8366:
8367: 1. domain
8368: 2. course number
8369: 3. reference to array containing roles for which sections should
8370: be gathered (optional).
8371: 4. reference to array containing status types for which sections
8372: should be gathered (optional).
8373:
8374: If the third argument is undefined, sections are gathered for any role.
8375: If the fourth argument is undefined, sections are gathered for any status.
8376: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8377:
1.374 raeburn 8378: Returns section hash (keys are section IDs, values are
8379: number of users in each section), subject to the
1.419 raeburn 8380: optional roles filter, optional status filter
1.233 raeburn 8381:
8382: =cut
8383:
8384: ###############################################
8385: sub get_sections {
1.419 raeburn 8386: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8387: if (!defined($cdom) || !defined($cnum)) {
8388: my $cid = $env{'request.course.id'};
8389:
8390: return if (!defined($cid));
8391:
8392: $cdom = $env{'course.'.$cid.'.domain'};
8393: $cnum = $env{'course.'.$cid.'.num'};
8394: }
8395:
8396: my %sectioncount;
1.419 raeburn 8397: my $now = time;
1.240 albertel 8398:
1.1118 raeburn 8399: my $check_students = 1;
8400: my $only_students = 0;
8401: if (ref($possible_roles) eq 'ARRAY') {
8402: if (grep(/^st$/,@{$possible_roles})) {
8403: if (@{$possible_roles} == 1) {
8404: $only_students = 1;
8405: }
8406: } else {
8407: $check_students = 0;
8408: }
8409: }
8410:
8411: if ($check_students) {
1.276 albertel 8412: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8413: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8414: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8415: my $start_index = &Apache::loncoursedata::CL_START();
8416: my $end_index = &Apache::loncoursedata::CL_END();
8417: my $status;
1.366 albertel 8418: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8419: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8420: $data->[$status_index],
8421: $data->[$start_index],
8422: $data->[$end_index]);
8423: if ($stu_status eq 'Active') {
8424: $status = 'active';
8425: } elsif ($end < $now) {
8426: $status = 'previous';
8427: } elsif ($start > $now) {
8428: $status = 'future';
8429: }
8430: if ($section ne '-1' && $section !~ /^\s*$/) {
8431: if ((!defined($possible_status)) || (($status ne '') &&
8432: (grep/^\Q$status\E$/,@{$possible_status}))) {
8433: $sectioncount{$section}++;
8434: }
1.240 albertel 8435: }
8436: }
8437: }
1.1118 raeburn 8438: if ($only_students) {
8439: return %sectioncount;
8440: }
1.240 albertel 8441: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8442: foreach my $user (sort(keys(%courseroles))) {
8443: if ($user !~ /^(\w{2})/) { next; }
8444: my ($role) = ($user =~ /^(\w{2})/);
8445: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8446: my ($section,$status);
1.240 albertel 8447: if ($role eq 'cr' &&
8448: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8449: $section=$1;
8450: }
8451: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8452: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8453: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8454: if ($end == -1 && $start == -1) {
8455: next; #deleted role
8456: }
8457: if (!defined($possible_status)) {
8458: $sectioncount{$section}++;
8459: } else {
8460: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8461: $status = 'active';
8462: } elsif ($end < $now) {
8463: $status = 'future';
8464: } elsif ($start > $now) {
8465: $status = 'previous';
8466: }
8467: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8468: $sectioncount{$section}++;
8469: }
8470: }
1.233 raeburn 8471: }
1.366 albertel 8472: return %sectioncount;
1.233 raeburn 8473: }
8474:
1.274 raeburn 8475: ###############################################
1.294 raeburn 8476:
8477: =pod
1.405 albertel 8478:
8479: =item * &get_course_users()
8480:
1.275 raeburn 8481: Retrieves usernames:domains for users in the specified course
8482: with specific role(s), and access status.
8483:
8484: Incoming parameters:
1.277 albertel 8485: 1. course domain
8486: 2. course number
8487: 3. access status: users must have - either active,
1.275 raeburn 8488: previous, future, or all.
1.277 albertel 8489: 4. reference to array of permissible roles
1.288 raeburn 8490: 5. reference to array of section restrictions (optional)
8491: 6. reference to results object (hash of hashes).
8492: 7. reference to optional userdata hash
1.609 raeburn 8493: 8. reference to optional statushash
1.630 raeburn 8494: 9. flag if privileged users (except those set to unhide in
8495: course settings) should be excluded
1.609 raeburn 8496: Keys of top level results hash are roles.
1.275 raeburn 8497: Keys of inner hashes are username:domain, with
8498: values set to access type.
1.288 raeburn 8499: Optional userdata hash returns an array with arguments in the
8500: same order as loncoursedata::get_classlist() for student data.
8501:
1.609 raeburn 8502: Optional statushash returns
8503:
1.288 raeburn 8504: Entries for end, start, section and status are blank because
8505: of the possibility of multiple values for non-student roles.
8506:
1.275 raeburn 8507: =cut
1.405 albertel 8508:
1.275 raeburn 8509: ###############################################
1.405 albertel 8510:
1.275 raeburn 8511: sub get_course_users {
1.630 raeburn 8512: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8513: my %idx = ();
1.419 raeburn 8514: my %seclists;
1.288 raeburn 8515:
8516: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8517: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8518: $idx{end} = &Apache::loncoursedata::CL_END();
8519: $idx{start} = &Apache::loncoursedata::CL_START();
8520: $idx{id} = &Apache::loncoursedata::CL_ID();
8521: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8522: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8523: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8524:
1.290 albertel 8525: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8526: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8527: my $now = time;
1.277 albertel 8528: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8529: my $match = 0;
1.412 raeburn 8530: my $secmatch = 0;
1.419 raeburn 8531: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8532: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8533: if ($section eq '') {
8534: $section = 'none';
8535: }
1.291 albertel 8536: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8537: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8538: $secmatch = 1;
8539: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8540: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8541: $secmatch = 1;
8542: }
8543: } else {
1.419 raeburn 8544: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8545: $secmatch = 1;
8546: }
1.290 albertel 8547: }
1.412 raeburn 8548: if (!$secmatch) {
8549: next;
8550: }
1.419 raeburn 8551: }
1.275 raeburn 8552: if (defined($$types{'active'})) {
1.288 raeburn 8553: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8554: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8555: $match = 1;
1.275 raeburn 8556: }
8557: }
8558: if (defined($$types{'previous'})) {
1.609 raeburn 8559: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8560: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8561: $match = 1;
1.275 raeburn 8562: }
8563: }
8564: if (defined($$types{'future'})) {
1.609 raeburn 8565: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8566: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8567: $match = 1;
1.275 raeburn 8568: }
8569: }
1.609 raeburn 8570: if ($match) {
8571: push(@{$seclists{$student}},$section);
8572: if (ref($userdata) eq 'HASH') {
8573: $$userdata{$student} = $$classlist{$student};
8574: }
8575: if (ref($statushash) eq 'HASH') {
8576: $statushash->{$student}{'st'}{$section} = $status;
8577: }
1.288 raeburn 8578: }
1.275 raeburn 8579: }
8580: }
1.412 raeburn 8581: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8582: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8583: my $now = time;
1.609 raeburn 8584: my %displaystatus = ( previous => 'Expired',
8585: active => 'Active',
8586: future => 'Future',
8587: );
1.1121 raeburn 8588: my (%nothide,@possdoms);
1.630 raeburn 8589: if ($hidepriv) {
8590: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8591: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8592: if ($user !~ /:/) {
8593: $nothide{join(':',split(/[\@]/,$user))}=1;
8594: } else {
8595: $nothide{$user} = 1;
8596: }
8597: }
1.1121 raeburn 8598: my @possdoms = ($cdom);
8599: if ($coursehash{'checkforpriv'}) {
8600: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8601: }
1.630 raeburn 8602: }
1.439 raeburn 8603: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8604: my $match = 0;
1.412 raeburn 8605: my $secmatch = 0;
1.439 raeburn 8606: my $status;
1.412 raeburn 8607: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8608: $user =~ s/:$//;
1.439 raeburn 8609: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8610: if ($end == -1 || $start == -1) {
8611: next;
8612: }
8613: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8614: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8615: my ($uname,$udom) = split(/:/,$user);
8616: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8617: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8618: $secmatch = 1;
8619: } elsif ($usec eq '') {
1.420 albertel 8620: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8621: $secmatch = 1;
8622: }
8623: } else {
8624: if (grep(/^\Q$usec\E$/,@{$sections})) {
8625: $secmatch = 1;
8626: }
8627: }
8628: if (!$secmatch) {
8629: next;
8630: }
1.288 raeburn 8631: }
1.419 raeburn 8632: if ($usec eq '') {
8633: $usec = 'none';
8634: }
1.275 raeburn 8635: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8636: if ($hidepriv) {
1.1121 raeburn 8637: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8638: (!$nothide{$uname.':'.$udom})) {
8639: next;
8640: }
8641: }
1.503 raeburn 8642: if ($end > 0 && $end < $now) {
1.439 raeburn 8643: $status = 'previous';
8644: } elsif ($start > $now) {
8645: $status = 'future';
8646: } else {
8647: $status = 'active';
8648: }
1.277 albertel 8649: foreach my $type (keys(%{$types})) {
1.275 raeburn 8650: if ($status eq $type) {
1.420 albertel 8651: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8652: push(@{$$users{$role}{$user}},$type);
8653: }
1.288 raeburn 8654: $match = 1;
8655: }
8656: }
1.419 raeburn 8657: if (($match) && (ref($userdata) eq 'HASH')) {
8658: if (!exists($$userdata{$uname.':'.$udom})) {
8659: &get_user_info($udom,$uname,\%idx,$userdata);
8660: }
1.420 albertel 8661: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8662: push(@{$seclists{$uname.':'.$udom}},$usec);
8663: }
1.609 raeburn 8664: if (ref($statushash) eq 'HASH') {
8665: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8666: }
1.275 raeburn 8667: }
8668: }
8669: }
8670: }
1.290 albertel 8671: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8672: if ((defined($cdom)) && (defined($cnum))) {
8673: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8674: if ( defined($csettings{'internal.courseowner'}) ) {
8675: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8676: next if ($owner eq '');
8677: my ($ownername,$ownerdom);
8678: if ($owner =~ /^([^:]+):([^:]+)$/) {
8679: $ownername = $1;
8680: $ownerdom = $2;
8681: } else {
8682: $ownername = $owner;
8683: $ownerdom = $cdom;
8684: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8685: }
8686: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8687: if (defined($userdata) &&
1.609 raeburn 8688: !exists($$userdata{$owner})) {
8689: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8690: if (!grep(/^none$/,@{$seclists{$owner}})) {
8691: push(@{$seclists{$owner}},'none');
8692: }
8693: if (ref($statushash) eq 'HASH') {
8694: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8695: }
1.290 albertel 8696: }
1.279 raeburn 8697: }
8698: }
8699: }
1.419 raeburn 8700: foreach my $user (keys(%seclists)) {
8701: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8702: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8703: }
1.275 raeburn 8704: }
8705: return;
8706: }
8707:
1.288 raeburn 8708: sub get_user_info {
8709: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8710: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8711: &plainname($uname,$udom,'lastname');
1.291 albertel 8712: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8713: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8714: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8715: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8716: return;
8717: }
1.275 raeburn 8718:
1.472 raeburn 8719: ###############################################
8720:
8721: =pod
8722:
8723: =item * &get_user_quota()
8724:
1.1134 raeburn 8725: Retrieves quota assigned for storage of user files.
8726: Default is to report quota for portfolio files.
1.472 raeburn 8727:
8728: Incoming parameters:
8729: 1. user's username
8730: 2. user's domain
1.1134 raeburn 8731: 3. quota name - portfolio, author, or course
1.1136 raeburn 8732: (if no quota name provided, defaults to portfolio).
1.1165 raeburn 8733: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1136 raeburn 8734: course
1.472 raeburn 8735:
8736: Returns:
1.1163 raeburn 8737: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 8738: 2. (Optional) Type of setting: custom or default
8739: (individually assigned or default for user's
8740: institutional status).
8741: 3. (Optional) - User's institutional status (e.g., faculty, staff
8742: or student - types as defined in localenroll::inst_usertypes
8743: for user's domain, which determines default quota for user.
8744: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8745:
8746: If a value has been stored in the user's environment,
1.536 raeburn 8747: it will return that, otherwise it returns the maximal default
1.1134 raeburn 8748: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8749:
8750: =cut
8751:
8752: ###############################################
8753:
8754:
8755: sub get_user_quota {
1.1136 raeburn 8756: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8757: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8758: if (!defined($udom)) {
8759: $udom = $env{'user.domain'};
8760: }
8761: if (!defined($uname)) {
8762: $uname = $env{'user.name'};
8763: }
8764: if (($udom eq '' || $uname eq '') ||
8765: ($udom eq 'public') && ($uname eq 'public')) {
8766: $quota = 0;
1.536 raeburn 8767: $quotatype = 'default';
8768: $defquota = 0;
1.472 raeburn 8769: } else {
1.536 raeburn 8770: my $inststatus;
1.1134 raeburn 8771: if ($quotaname eq 'course') {
8772: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8773: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8774: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8775: } else {
8776: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8777: $quota = $cenv{'internal.uploadquota'};
8778: }
1.536 raeburn 8779: } else {
1.1134 raeburn 8780: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8781: if ($quotaname eq 'author') {
8782: $quota = $env{'environment.authorquota'};
8783: } else {
8784: $quota = $env{'environment.portfolioquota'};
8785: }
8786: $inststatus = $env{'environment.inststatus'};
8787: } else {
8788: my %userenv =
8789: &Apache::lonnet::get('environment',['portfolioquota',
8790: 'authorquota','inststatus'],$udom,$uname);
8791: my ($tmp) = keys(%userenv);
8792: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8793: if ($quotaname eq 'author') {
8794: $quota = $userenv{'authorquota'};
8795: } else {
8796: $quota = $userenv{'portfolioquota'};
8797: }
8798: $inststatus = $userenv{'inststatus'};
8799: } else {
8800: undef(%userenv);
8801: }
8802: }
8803: }
8804: if ($quota eq '' || wantarray) {
8805: if ($quotaname eq 'course') {
8806: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 8807: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
8808: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1136 raeburn 8809: $defquota = $domdefs{$crstype.'quota'};
8810: }
8811: if ($defquota eq '') {
8812: $defquota = 500;
8813: }
1.1134 raeburn 8814: } else {
8815: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8816: }
8817: if ($quota eq '') {
8818: $quota = $defquota;
8819: $quotatype = 'default';
8820: } else {
8821: $quotatype = 'custom';
8822: }
1.472 raeburn 8823: }
8824: }
1.536 raeburn 8825: if (wantarray) {
8826: return ($quota,$quotatype,$settingstatus,$defquota);
8827: } else {
8828: return $quota;
8829: }
1.472 raeburn 8830: }
8831:
8832: ###############################################
8833:
8834: =pod
8835:
8836: =item * &default_quota()
8837:
1.536 raeburn 8838: Retrieves default quota assigned for storage of user portfolio files,
8839: given an (optional) user's institutional status.
1.472 raeburn 8840:
8841: Incoming parameters:
1.1142 raeburn 8842:
1.472 raeburn 8843: 1. domain
1.536 raeburn 8844: 2. (Optional) institutional status(es). This is a : separated list of
8845: status types (e.g., faculty, staff, student etc.)
8846: which apply to the user for whom the default is being retrieved.
8847: If the institutional status string in undefined, the domain
1.1134 raeburn 8848: default quota will be returned.
8849: 3. quota name - portfolio, author, or course
8850: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8851:
8852: Returns:
1.1142 raeburn 8853:
1.1163 raeburn 8854: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 8855: 2. (Optional) institutional type which determined the value of the
8856: default quota.
1.472 raeburn 8857:
8858: If a value has been stored in the domain's configuration db,
8859: it will return that, otherwise it returns 20 (for backwards
8860: compatibility with domains which have not set up a configuration
1.1163 raeburn 8861: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 8862:
1.536 raeburn 8863: If the user's status includes multiple types (e.g., staff and student),
8864: the largest default quota which applies to the user determines the
8865: default quota returned.
8866:
1.472 raeburn 8867: =cut
8868:
8869: ###############################################
8870:
8871:
8872: sub default_quota {
1.1134 raeburn 8873: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8874: my ($defquota,$settingstatus);
8875: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8876: ['quotas'],$udom);
1.1134 raeburn 8877: my $key = 'defaultquota';
8878: if ($quotaname eq 'author') {
8879: $key = 'authorquota';
8880: }
1.622 raeburn 8881: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8882: if ($inststatus ne '') {
1.765 raeburn 8883: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8884: foreach my $item (@statuses) {
1.1134 raeburn 8885: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8886: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8887: if ($defquota eq '') {
1.1134 raeburn 8888: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8889: $settingstatus = $item;
1.1134 raeburn 8890: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8891: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8892: $settingstatus = $item;
8893: }
8894: }
1.1134 raeburn 8895: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8896: if ($quotahash{'quotas'}{$item} ne '') {
8897: if ($defquota eq '') {
8898: $defquota = $quotahash{'quotas'}{$item};
8899: $settingstatus = $item;
8900: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8901: $defquota = $quotahash{'quotas'}{$item};
8902: $settingstatus = $item;
8903: }
1.536 raeburn 8904: }
8905: }
8906: }
8907: }
8908: if ($defquota eq '') {
1.1134 raeburn 8909: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8910: $defquota = $quotahash{'quotas'}{$key}{'default'};
8911: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8912: $defquota = $quotahash{'quotas'}{'default'};
8913: }
1.536 raeburn 8914: $settingstatus = 'default';
1.1139 raeburn 8915: if ($defquota eq '') {
8916: if ($quotaname eq 'author') {
8917: $defquota = 500;
8918: }
8919: }
1.536 raeburn 8920: }
8921: } else {
8922: $settingstatus = 'default';
1.1134 raeburn 8923: if ($quotaname eq 'author') {
8924: $defquota = 500;
8925: } else {
8926: $defquota = 20;
8927: }
1.536 raeburn 8928: }
8929: if (wantarray) {
8930: return ($defquota,$settingstatus);
1.472 raeburn 8931: } else {
1.536 raeburn 8932: return $defquota;
1.472 raeburn 8933: }
8934: }
8935:
1.1135 raeburn 8936: ###############################################
8937:
8938: =pod
8939:
1.1136 raeburn 8940: =item * &excess_filesize_warning()
1.1135 raeburn 8941:
8942: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 8943: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 8944: space to be exceeded.
1.1136 raeburn 8945:
8946: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 8947: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 8948:
1.1165 raeburn 8949: Inputs: 7
1.1136 raeburn 8950: 1. username or coursenum
1.1135 raeburn 8951: 2. domain
1.1136 raeburn 8952: 3. context ('author' or 'course')
1.1135 raeburn 8953: 4. filename of file for which action is being requested
8954: 5. filesize (kB) of file
8955: 6. action being taken: copy or upload.
1.1165 raeburn 8956: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1135 raeburn 8957:
8958: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 8959: otherwise return null.
8960:
8961: =back
1.1135 raeburn 8962:
8963: =cut
8964:
1.1136 raeburn 8965: sub excess_filesize_warning {
1.1165 raeburn 8966: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 8967: my $current_disk_usage = 0;
1.1165 raeburn 8968: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 8969: if ($context eq 'author') {
8970: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8971: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8972: } else {
8973: foreach my $subdir ('docs','supplemental') {
8974: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8975: }
8976: }
1.1135 raeburn 8977: $disk_quota = int($disk_quota * 1000);
8978: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 8979: return '<p class="LC_warning">'.
1.1135 raeburn 8980: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 8981: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
8982: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 8983: $disk_quota,$current_disk_usage).
8984: '</p>';
8985: }
8986: return;
8987: }
8988:
8989: ###############################################
8990:
8991:
1.1136 raeburn 8992:
8993:
1.384 raeburn 8994: sub get_secgrprole_info {
8995: my ($cdom,$cnum,$needroles,$type) = @_;
8996: my %sections_count = &get_sections($cdom,$cnum);
8997: my @sections = (sort {$a <=> $b} keys(%sections_count));
8998: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8999: my @groups = sort(keys(%curr_groups));
9000: my $allroles = [];
9001: my $rolehash;
9002: my $accesshash = {
9003: active => 'Currently has access',
9004: future => 'Will have future access',
9005: previous => 'Previously had access',
9006: };
9007: if ($needroles) {
9008: $rolehash = {'all' => 'all'};
1.385 albertel 9009: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9010: if (&Apache::lonnet::error(%user_roles)) {
9011: undef(%user_roles);
9012: }
9013: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9014: my ($role)=split(/\:/,$item,2);
9015: if ($role eq 'cr') { next; }
9016: if ($role =~ /^cr/) {
9017: $$rolehash{$role} = (split('/',$role))[3];
9018: } else {
9019: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9020: }
9021: }
9022: foreach my $key (sort(keys(%{$rolehash}))) {
9023: push(@{$allroles},$key);
9024: }
9025: push (@{$allroles},'st');
9026: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9027: }
9028: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9029: }
9030:
1.555 raeburn 9031: sub user_picker {
1.994 raeburn 9032: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9033: my $currdom = $dom;
9034: my %curr_selected = (
9035: srchin => 'dom',
1.580 raeburn 9036: srchby => 'lastname',
1.555 raeburn 9037: );
9038: my $srchterm;
1.625 raeburn 9039: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9040: if ($srch->{'srchby'} ne '') {
9041: $curr_selected{'srchby'} = $srch->{'srchby'};
9042: }
9043: if ($srch->{'srchin'} ne '') {
9044: $curr_selected{'srchin'} = $srch->{'srchin'};
9045: }
9046: if ($srch->{'srchtype'} ne '') {
9047: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9048: }
9049: if ($srch->{'srchdomain'} ne '') {
9050: $currdom = $srch->{'srchdomain'};
9051: }
9052: $srchterm = $srch->{'srchterm'};
9053: }
9054: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 9055: 'usr' => 'Search criteria',
1.563 raeburn 9056: 'doma' => 'Domain/institution to search',
1.558 albertel 9057: 'uname' => 'username',
9058: 'lastname' => 'last name',
1.555 raeburn 9059: 'lastfirst' => 'last name, first name',
1.558 albertel 9060: 'crs' => 'in this course',
1.576 raeburn 9061: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9062: 'alc' => 'all LON-CAPA',
1.573 raeburn 9063: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9064: 'exact' => 'is',
9065: 'contains' => 'contains',
1.569 raeburn 9066: 'begins' => 'begins with',
1.571 raeburn 9067: 'youm' => "You must include some text to search for.",
9068: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9069: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9070: 'yomc' => "You must choose a domain when using an institutional directory search.",
9071: 'ymcd' => "You must choose a domain when using a domain search.",
9072: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9073: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9074: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9075: );
1.563 raeburn 9076: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9077: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9078:
9079: my @srchins = ('crs','dom','alc','instd');
9080:
9081: foreach my $option (@srchins) {
9082: # FIXME 'alc' option unavailable until
9083: # loncreateuser::print_user_query_page()
9084: # has been completed.
9085: next if ($option eq 'alc');
1.880 raeburn 9086: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9087: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9088: if ($curr_selected{'srchin'} eq $option) {
9089: $srchinsel .= '
9090: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9091: } else {
9092: $srchinsel .= '
9093: <option value="'.$option.'">'.$lt{$option}.'</option>';
9094: }
1.555 raeburn 9095: }
1.563 raeburn 9096: $srchinsel .= "\n </select>\n";
1.555 raeburn 9097:
9098: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9099: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9100: if ($curr_selected{'srchby'} eq $option) {
9101: $srchbysel .= '
9102: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9103: } else {
9104: $srchbysel .= '
9105: <option value="'.$option.'">'.$lt{$option}.'</option>';
9106: }
9107: }
9108: $srchbysel .= "\n </select>\n";
9109:
9110: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9111: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9112: if ($curr_selected{'srchtype'} eq $option) {
9113: $srchtypesel .= '
9114: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9115: } else {
9116: $srchtypesel .= '
9117: <option value="'.$option.'">'.$lt{$option}.'</option>';
9118: }
9119: }
9120: $srchtypesel .= "\n </select>\n";
9121:
1.558 albertel 9122: my ($newuserscript,$new_user_create);
1.994 raeburn 9123: my $context_dom = $env{'request.role.domain'};
9124: if ($context eq 'requestcrs') {
9125: if ($env{'form.coursedom'} ne '') {
9126: $context_dom = $env{'form.coursedom'};
9127: }
9128: }
1.556 raeburn 9129: if ($forcenewuser) {
1.576 raeburn 9130: if (ref($srch) eq 'HASH') {
1.994 raeburn 9131: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9132: if ($cancreate) {
9133: $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>';
9134: } else {
1.799 bisitz 9135: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9136: my %usertypetext = (
9137: official => 'institutional',
9138: unofficial => 'non-institutional',
9139: );
1.799 bisitz 9140: $new_user_create = '<p class="LC_warning">'
9141: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9142: .' '
9143: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9144: ,'<a href="'.$helplink.'">','</a>')
9145: .'</p><br />';
1.627 raeburn 9146: }
1.576 raeburn 9147: }
9148: }
9149:
1.556 raeburn 9150: $newuserscript = <<"ENDSCRIPT";
9151:
1.570 raeburn 9152: function setSearch(createnew,callingForm) {
1.556 raeburn 9153: if (createnew == 1) {
1.570 raeburn 9154: for (var i=0; i<callingForm.srchby.length; i++) {
9155: if (callingForm.srchby.options[i].value == 'uname') {
9156: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9157: }
9158: }
1.570 raeburn 9159: for (var i=0; i<callingForm.srchin.length; i++) {
9160: if ( callingForm.srchin.options[i].value == 'dom') {
9161: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9162: }
9163: }
1.570 raeburn 9164: for (var i=0; i<callingForm.srchtype.length; i++) {
9165: if (callingForm.srchtype.options[i].value == 'exact') {
9166: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9167: }
9168: }
1.570 raeburn 9169: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9170: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9171: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9172: }
9173: }
9174: }
9175: }
9176: ENDSCRIPT
1.558 albertel 9177:
1.556 raeburn 9178: }
9179:
1.555 raeburn 9180: my $output = <<"END_BLOCK";
1.556 raeburn 9181: <script type="text/javascript">
1.824 bisitz 9182: // <![CDATA[
1.570 raeburn 9183: function validateEntry(callingForm) {
1.558 albertel 9184:
1.556 raeburn 9185: var checkok = 1;
1.558 albertel 9186: var srchin;
1.570 raeburn 9187: for (var i=0; i<callingForm.srchin.length; i++) {
9188: if ( callingForm.srchin[i].checked ) {
9189: srchin = callingForm.srchin[i].value;
1.558 albertel 9190: }
9191: }
9192:
1.570 raeburn 9193: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9194: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9195: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9196: var srchterm = callingForm.srchterm.value;
9197: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9198: var msg = "";
9199:
9200: if (srchterm == "") {
9201: checkok = 0;
1.571 raeburn 9202: msg += "$lt{'youm'}\\n";
1.556 raeburn 9203: }
9204:
1.569 raeburn 9205: if (srchtype== 'begins') {
9206: if (srchterm.length < 2) {
9207: checkok = 0;
1.571 raeburn 9208: msg += "$lt{'thte'}\\n";
1.569 raeburn 9209: }
9210: }
9211:
1.556 raeburn 9212: if (srchtype== 'contains') {
9213: if (srchterm.length < 3) {
9214: checkok = 0;
1.571 raeburn 9215: msg += "$lt{'thet'}\\n";
1.556 raeburn 9216: }
9217: }
9218: if (srchin == 'instd') {
9219: if (srchdomain == '') {
9220: checkok = 0;
1.571 raeburn 9221: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9222: }
9223: }
9224: if (srchin == 'dom') {
9225: if (srchdomain == '') {
9226: checkok = 0;
1.571 raeburn 9227: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9228: }
9229: }
9230: if (srchby == 'lastfirst') {
9231: if (srchterm.indexOf(",") == -1) {
9232: checkok = 0;
1.571 raeburn 9233: msg += "$lt{'whus'}\\n";
1.556 raeburn 9234: }
9235: if (srchterm.indexOf(",") == srchterm.length -1) {
9236: checkok = 0;
1.571 raeburn 9237: msg += "$lt{'whse'}\\n";
1.556 raeburn 9238: }
9239: }
9240: if (checkok == 0) {
1.571 raeburn 9241: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9242: return;
9243: }
9244: if (checkok == 1) {
1.570 raeburn 9245: callingForm.submit();
1.556 raeburn 9246: }
9247: }
9248:
9249: $newuserscript
9250:
1.824 bisitz 9251: // ]]>
1.556 raeburn 9252: </script>
1.558 albertel 9253:
9254: $new_user_create
9255:
1.555 raeburn 9256: END_BLOCK
1.558 albertel 9257:
1.876 raeburn 9258: $output .= &Apache::lonhtmlcommon::start_pick_box().
9259: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9260: $domform.
9261: &Apache::lonhtmlcommon::row_closure().
9262: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9263: $srchbysel.
9264: $srchtypesel.
9265: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9266: $srchinsel.
9267: &Apache::lonhtmlcommon::row_closure(1).
9268: &Apache::lonhtmlcommon::end_pick_box().
9269: '<br />';
1.555 raeburn 9270: return $output;
9271: }
9272:
1.612 raeburn 9273: sub user_rule_check {
1.615 raeburn 9274: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9275: my $response;
9276: if (ref($usershash) eq 'HASH') {
9277: foreach my $user (keys(%{$usershash})) {
9278: my ($uname,$udom) = split(/:/,$user);
9279: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9280: my ($id,$newuser);
1.612 raeburn 9281: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9282: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9283: $id = $usershash->{$user}->{'id'};
9284: }
9285: my $inst_response;
9286: if (ref($checks) eq 'HASH') {
9287: if (defined($checks->{'username'})) {
1.615 raeburn 9288: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9289: &Apache::lonnet::get_instuser($udom,$uname);
9290: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9291: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9292: &Apache::lonnet::get_instuser($udom,undef,$id);
9293: }
1.615 raeburn 9294: } else {
9295: ($inst_response,%{$inst_results->{$user}}) =
9296: &Apache::lonnet::get_instuser($udom,$uname);
9297: return;
1.612 raeburn 9298: }
1.615 raeburn 9299: if (!$got_rules->{$udom}) {
1.612 raeburn 9300: my %domconfig = &Apache::lonnet::get_dom('configuration',
9301: ['usercreation'],$udom);
9302: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9303: foreach my $item ('username','id') {
1.612 raeburn 9304: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9305: $$curr_rules{$udom}{$item} =
9306: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9307: }
9308: }
9309: }
1.615 raeburn 9310: $got_rules->{$udom} = 1;
1.585 raeburn 9311: }
1.612 raeburn 9312: foreach my $item (keys(%{$checks})) {
9313: if (ref($$curr_rules{$udom}) eq 'HASH') {
9314: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9315: if (@{$$curr_rules{$udom}{$item}} > 0) {
9316: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9317: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9318: if ($rule_check{$rule}) {
9319: $$rulematch{$user}{$item} = $rule;
9320: if ($inst_response eq 'ok') {
1.615 raeburn 9321: if (ref($inst_results) eq 'HASH') {
9322: if (ref($inst_results->{$user}) eq 'HASH') {
9323: if (keys(%{$inst_results->{$user}}) == 0) {
9324: $$alerts{$item}{$udom}{$uname} = 1;
9325: }
1.612 raeburn 9326: }
9327: }
1.615 raeburn 9328: }
9329: last;
1.585 raeburn 9330: }
9331: }
9332: }
9333: }
9334: }
9335: }
9336: }
9337: }
1.612 raeburn 9338: return;
9339: }
9340:
9341: sub user_rule_formats {
9342: my ($domain,$domdesc,$curr_rules,$check) = @_;
9343: my %text = (
9344: 'username' => 'Usernames',
9345: 'id' => 'IDs',
9346: );
9347: my $output;
9348: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9349: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9350: if (@{$ruleorder} > 0) {
1.1102 raeburn 9351: $output = '<br />'.
9352: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9353: '<span class="LC_cusr_emph">','</span>',$domdesc).
9354: ' <ul>';
1.612 raeburn 9355: foreach my $rule (@{$ruleorder}) {
9356: if (ref($curr_rules) eq 'ARRAY') {
9357: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9358: if (ref($rules->{$rule}) eq 'HASH') {
9359: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9360: $rules->{$rule}{'desc'}.'</li>';
9361: }
9362: }
9363: }
9364: }
9365: $output .= '</ul>';
9366: }
9367: }
9368: return $output;
9369: }
9370:
9371: sub instrule_disallow_msg {
1.615 raeburn 9372: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9373: my $response;
9374: my %text = (
9375: item => 'username',
9376: items => 'usernames',
9377: match => 'matches',
9378: do => 'does',
9379: action => 'a username',
9380: one => 'one',
9381: );
9382: if ($count > 1) {
9383: $text{'item'} = 'usernames';
9384: $text{'match'} ='match';
9385: $text{'do'} = 'do';
9386: $text{'action'} = 'usernames',
9387: $text{'one'} = 'ones';
9388: }
9389: if ($checkitem eq 'id') {
9390: $text{'items'} = 'IDs';
9391: $text{'item'} = 'ID';
9392: $text{'action'} = 'an ID';
1.615 raeburn 9393: if ($count > 1) {
9394: $text{'item'} = 'IDs';
9395: $text{'action'} = 'IDs';
9396: }
1.612 raeburn 9397: }
1.674 bisitz 9398: $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 9399: if ($mode eq 'upload') {
9400: if ($checkitem eq 'username') {
9401: $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'}.");
9402: } elsif ($checkitem eq 'id') {
1.674 bisitz 9403: $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 9404: }
1.669 raeburn 9405: } elsif ($mode eq 'selfcreate') {
9406: if ($checkitem eq 'id') {
9407: $response .= &mt("You must either choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or leave the ID field blank.");
9408: }
1.615 raeburn 9409: } else {
9410: if ($checkitem eq 'username') {
9411: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9412: } elsif ($checkitem eq 'id') {
9413: $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.");
9414: }
1.612 raeburn 9415: }
9416: return $response;
1.585 raeburn 9417: }
9418:
1.624 raeburn 9419: sub personal_data_fieldtitles {
9420: my %fieldtitles = &Apache::lonlocal::texthash (
9421: id => 'Student/Employee ID',
9422: permanentemail => 'E-mail address',
9423: lastname => 'Last Name',
9424: firstname => 'First Name',
9425: middlename => 'Middle Name',
9426: generation => 'Generation',
9427: gen => 'Generation',
1.765 raeburn 9428: inststatus => 'Affiliation',
1.624 raeburn 9429: );
9430: return %fieldtitles;
9431: }
9432:
1.642 raeburn 9433: sub sorted_inst_types {
9434: my ($dom) = @_;
1.1185 raeburn 9435: my ($usertypes,$order);
9436: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9437: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
9438: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
9439: $order = $domdefaults{'inststatus'}{'inststatusorder'};
9440: } else {
9441: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9442: }
1.642 raeburn 9443: my $othertitle = &mt('All users');
9444: if ($env{'request.course.id'}) {
1.668 raeburn 9445: $othertitle = &mt('Any users');
1.642 raeburn 9446: }
9447: my @types;
9448: if (ref($order) eq 'ARRAY') {
9449: @types = @{$order};
9450: }
9451: if (@types == 0) {
9452: if (ref($usertypes) eq 'HASH') {
9453: @types = sort(keys(%{$usertypes}));
9454: }
9455: }
9456: if (keys(%{$usertypes}) > 0) {
9457: $othertitle = &mt('Other users');
9458: }
9459: return ($othertitle,$usertypes,\@types);
9460: }
9461:
1.645 raeburn 9462: sub get_institutional_codes {
9463: my ($settings,$allcourses,$LC_code) = @_;
9464: # Get complete list of course sections to update
9465: my @currsections = ();
9466: my @currxlists = ();
9467: my $coursecode = $$settings{'internal.coursecode'};
9468:
9469: if ($$settings{'internal.sectionnums'} ne '') {
9470: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9471: }
9472:
9473: if ($$settings{'internal.crosslistings'} ne '') {
9474: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9475: }
9476:
9477: if (@currxlists > 0) {
9478: foreach (@currxlists) {
9479: if (m/^([^:]+):(\w*)$/) {
9480: unless (grep/^$1$/,@{$allcourses}) {
9481: push @{$allcourses},$1;
9482: $$LC_code{$1} = $2;
9483: }
9484: }
9485: }
9486: }
9487:
9488: if (@currsections > 0) {
9489: foreach (@currsections) {
9490: if (m/^(\w+):(\w*)$/) {
9491: my $sec = $coursecode.$1;
9492: my $lc_sec = $2;
9493: unless (grep/^$sec$/,@{$allcourses}) {
9494: push @{$allcourses},$sec;
9495: $$LC_code{$sec} = $lc_sec;
9496: }
9497: }
9498: }
9499: }
9500: return;
9501: }
9502:
1.971 raeburn 9503: sub get_standard_codeitems {
9504: return ('Year','Semester','Department','Number','Section');
9505: }
9506:
1.112 bowersj2 9507: =pod
9508:
1.780 raeburn 9509: =head1 Slot Helpers
9510:
9511: =over 4
9512:
9513: =item * sorted_slots()
9514:
1.1040 raeburn 9515: Sorts an array of slot names in order of an optional sort key,
9516: default sort is by slot start time (earliest first).
1.780 raeburn 9517:
9518: Inputs:
9519:
9520: =over 4
9521:
9522: slotsarr - Reference to array of unsorted slot names.
9523:
9524: slots - Reference to hash of hash, where outer hash keys are slot names.
9525:
1.1040 raeburn 9526: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9527:
1.549 albertel 9528: =back
9529:
1.780 raeburn 9530: Returns:
9531:
9532: =over 4
9533:
1.1040 raeburn 9534: sorted - An array of slot names sorted by a specified sort key
9535: (default sort key is start time of the slot).
1.780 raeburn 9536:
9537: =back
9538:
9539: =cut
9540:
9541:
9542: sub sorted_slots {
1.1040 raeburn 9543: my ($slotsarr,$slots,$sortkey) = @_;
9544: if ($sortkey eq '') {
9545: $sortkey = 'starttime';
9546: }
1.780 raeburn 9547: my @sorted;
9548: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9549: @sorted =
9550: sort {
9551: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9552: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9553: }
9554: if (ref($slots->{$a})) { return -1;}
9555: if (ref($slots->{$b})) { return 1;}
9556: return 0;
9557: } @{$slotsarr};
9558: }
9559: return @sorted;
9560: }
9561:
1.1040 raeburn 9562: =pod
9563:
9564: =item * get_future_slots()
9565:
9566: Inputs:
9567:
9568: =over 4
9569:
9570: cnum - course number
9571:
9572: cdom - course domain
9573:
9574: now - current UNIX time
9575:
9576: symb - optional symb
9577:
9578: =back
9579:
9580: Returns:
9581:
9582: =over 4
9583:
9584: sorted_reservable - ref to array of student_schedulable slots currently
9585: reservable, ordered by end date of reservation period.
9586:
9587: reservable_now - ref to hash of student_schedulable slots currently
9588: reservable.
9589:
9590: Keys in inner hash are:
9591: (a) symb: either blank or symb to which slot use is restricted.
9592: (b) endreserve: end date of reservation period.
9593:
9594: sorted_future - ref to array of student_schedulable slots reservable in
9595: the future, ordered by start date of reservation period.
9596:
9597: future_reservable - ref to hash of student_schedulable slots reservable
9598: in the future.
9599:
9600: Keys in inner hash are:
9601: (a) symb: either blank or symb to which slot use is restricted.
9602: (b) startreserve: start date of reservation period.
9603:
9604: =back
9605:
9606: =cut
9607:
9608: sub get_future_slots {
9609: my ($cnum,$cdom,$now,$symb) = @_;
9610: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9611: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9612: foreach my $slot (keys(%slots)) {
9613: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9614: if ($symb) {
9615: next if (($slots{$slot}->{'symb'} ne '') &&
9616: ($slots{$slot}->{'symb'} ne $symb));
9617: }
9618: if (($slots{$slot}->{'starttime'} > $now) &&
9619: ($slots{$slot}->{'endtime'} > $now)) {
9620: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9621: my $userallowed = 0;
9622: if ($slots{$slot}->{'allowedsections'}) {
9623: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9624: if (!defined($env{'request.role.sec'})
9625: && grep(/^No section assigned$/,@allowed_sec)) {
9626: $userallowed=1;
9627: } else {
9628: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9629: $userallowed=1;
9630: }
9631: }
9632: unless ($userallowed) {
9633: if (defined($env{'request.course.groups'})) {
9634: my @groups = split(/:/,$env{'request.course.groups'});
9635: foreach my $group (@groups) {
9636: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9637: $userallowed=1;
9638: last;
9639: }
9640: }
9641: }
9642: }
9643: }
9644: if ($slots{$slot}->{'allowedusers'}) {
9645: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9646: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9647: if (grep(/^\Q$user\E$/,@allowed_users)) {
9648: $userallowed = 1;
9649: }
9650: }
9651: next unless($userallowed);
9652: }
9653: my $startreserve = $slots{$slot}->{'startreserve'};
9654: my $endreserve = $slots{$slot}->{'endreserve'};
9655: my $symb = $slots{$slot}->{'symb'};
9656: if (($startreserve < $now) &&
9657: (!$endreserve || $endreserve > $now)) {
9658: my $lastres = $endreserve;
9659: if (!$lastres) {
9660: $lastres = $slots{$slot}->{'starttime'};
9661: }
9662: $reservable_now{$slot} = {
9663: symb => $symb,
9664: endreserve => $lastres
9665: };
9666: } elsif (($startreserve > $now) &&
9667: (!$endreserve || $endreserve > $startreserve)) {
9668: $future_reservable{$slot} = {
9669: symb => $symb,
9670: startreserve => $startreserve
9671: };
9672: }
9673: }
9674: }
9675: my @unsorted_reservable = keys(%reservable_now);
9676: if (@unsorted_reservable > 0) {
9677: @sorted_reservable =
9678: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9679: }
9680: my @unsorted_future = keys(%future_reservable);
9681: if (@unsorted_future > 0) {
9682: @sorted_future =
9683: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9684: }
9685: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9686: }
1.780 raeburn 9687:
9688: =pod
9689:
1.1057 foxr 9690: =back
9691:
1.549 albertel 9692: =head1 HTTP Helpers
9693:
9694: =over 4
9695:
1.648 raeburn 9696: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9697:
1.258 albertel 9698: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9699: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9700: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9701:
9702: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9703: $possible_names is an ref to an array of form element names. As an example:
9704: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9705: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9706:
9707: =cut
1.1 albertel 9708:
1.6 albertel 9709: sub get_unprocessed_cgi {
1.25 albertel 9710: my ($query,$possible_names)= @_;
1.26 matthew 9711: # $Apache::lonxml::debug=1;
1.356 albertel 9712: foreach my $pair (split(/&/,$query)) {
9713: my ($name, $value) = split(/=/,$pair);
1.369 www 9714: $name = &unescape($name);
1.25 albertel 9715: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9716: $value =~ tr/+/ /;
9717: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9718: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9719: }
1.16 harris41 9720: }
1.6 albertel 9721: }
9722:
1.112 bowersj2 9723: =pod
9724:
1.648 raeburn 9725: =item * &cacheheader()
1.112 bowersj2 9726:
9727: returns cache-controlling header code
9728:
9729: =cut
9730:
1.7 albertel 9731: sub cacheheader {
1.258 albertel 9732: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9733: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9734: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9735: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9736: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9737: return $output;
1.7 albertel 9738: }
9739:
1.112 bowersj2 9740: =pod
9741:
1.648 raeburn 9742: =item * &no_cache($r)
1.112 bowersj2 9743:
9744: specifies header code to not have cache
9745:
9746: =cut
9747:
1.9 albertel 9748: sub no_cache {
1.216 albertel 9749: my ($r) = @_;
9750: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9751: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9752: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9753: $r->no_cache(1);
9754: $r->header_out("Expires" => $date);
9755: $r->header_out("Pragma" => "no-cache");
1.123 www 9756: }
9757:
9758: sub content_type {
1.181 albertel 9759: my ($r,$type,$charset) = @_;
1.299 foxr 9760: if ($r) {
9761: # Note that printout.pl calls this with undef for $r.
9762: &no_cache($r);
9763: }
1.258 albertel 9764: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9765: unless ($charset) {
9766: $charset=&Apache::lonlocal::current_encoding;
9767: }
9768: if ($charset) { $type.='; charset='.$charset; }
9769: if ($r) {
9770: $r->content_type($type);
9771: } else {
9772: print("Content-type: $type\n\n");
9773: }
1.9 albertel 9774: }
1.25 albertel 9775:
1.112 bowersj2 9776: =pod
9777:
1.648 raeburn 9778: =item * &add_to_env($name,$value)
1.112 bowersj2 9779:
1.258 albertel 9780: adds $name to the %env hash with value
1.112 bowersj2 9781: $value, if $name already exists, the entry is converted to an array
9782: reference and $value is added to the array.
9783:
9784: =cut
9785:
1.25 albertel 9786: sub add_to_env {
9787: my ($name,$value)=@_;
1.258 albertel 9788: if (defined($env{$name})) {
9789: if (ref($env{$name})) {
1.25 albertel 9790: #already have multiple values
1.258 albertel 9791: push(@{ $env{$name} },$value);
1.25 albertel 9792: } else {
9793: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9794: my $first=$env{$name};
9795: undef($env{$name});
9796: push(@{ $env{$name} },$first,$value);
1.25 albertel 9797: }
9798: } else {
1.258 albertel 9799: $env{$name}=$value;
1.25 albertel 9800: }
1.31 albertel 9801: }
1.149 albertel 9802:
9803: =pod
9804:
1.648 raeburn 9805: =item * &get_env_multiple($name)
1.149 albertel 9806:
1.258 albertel 9807: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9808: values may be defined and end up as an array ref.
9809:
9810: returns an array of values
9811:
9812: =cut
9813:
9814: sub get_env_multiple {
9815: my ($name) = @_;
9816: my @values;
1.258 albertel 9817: if (defined($env{$name})) {
1.149 albertel 9818: # exists is it an array
1.258 albertel 9819: if (ref($env{$name})) {
9820: @values=@{ $env{$name} };
1.149 albertel 9821: } else {
1.258 albertel 9822: $values[0]=$env{$name};
1.149 albertel 9823: }
9824: }
9825: return(@values);
9826: }
9827:
1.660 raeburn 9828: sub ask_for_embedded_content {
9829: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9830: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 9831: %currsubfile,%unused,$rem);
1.1071 raeburn 9832: my $counter = 0;
9833: my $numnew = 0;
1.987 raeburn 9834: my $numremref = 0;
9835: my $numinvalid = 0;
9836: my $numpathchg = 0;
9837: my $numexisting = 0;
1.1071 raeburn 9838: my $numunused = 0;
9839: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 9840: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 9841: my $heading = &mt('Upload embedded files');
9842: my $buttontext = &mt('Upload');
9843:
1.1085 raeburn 9844: if ($env{'request.course.id'}) {
1.1123 raeburn 9845: if ($actionurl eq '/adm/dependencies') {
9846: $navmap = Apache::lonnavmaps::navmap->new();
9847: }
9848: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9849: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 9850: }
1.1123 raeburn 9851: if (($actionurl eq '/adm/portfolio') ||
9852: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9853: my $current_path='/';
9854: if ($env{'form.currentpath'}) {
9855: $current_path = $env{'form.currentpath'};
9856: }
9857: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 9858: $udom = $cdom;
9859: $uname = $cnum;
1.984 raeburn 9860: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9861: } else {
9862: $udom = $env{'user.domain'};
9863: $uname = $env{'user.name'};
9864: $url = '/userfiles/portfolio';
9865: }
1.987 raeburn 9866: $toplevel = $url.'/';
1.984 raeburn 9867: $url .= $current_path;
9868: $getpropath = 1;
1.987 raeburn 9869: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9870: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9871: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9872: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9873: $toplevel = $url;
1.984 raeburn 9874: if ($rest ne '') {
1.987 raeburn 9875: $url .= $rest;
9876: }
9877: } elsif ($actionurl eq '/adm/coursedocs') {
9878: if (ref($args) eq 'HASH') {
1.1071 raeburn 9879: $url = $args->{'docs_url'};
9880: $toplevel = $url;
1.1084 raeburn 9881: if ($args->{'context'} eq 'paste') {
9882: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9883: ($path) =
9884: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9885: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9886: $fileloc =~ s{^/}{};
9887: }
1.1071 raeburn 9888: }
1.1084 raeburn 9889: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 9890: if ($env{'request.course.id'} ne '') {
9891: if (ref($args) eq 'HASH') {
9892: $url = $args->{'docs_url'};
9893: $title = $args->{'docs_title'};
1.1126 raeburn 9894: $toplevel = $url;
9895: unless ($toplevel =~ m{^/}) {
9896: $toplevel = "/$url";
9897: }
1.1085 raeburn 9898: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 9899: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9900: $path = $1;
9901: } else {
9902: ($path) =
9903: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9904: }
1.1071 raeburn 9905: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9906: $fileloc =~ s{^/}{};
9907: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9908: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9909: }
1.987 raeburn 9910: }
1.1123 raeburn 9911: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9912: $udom = $cdom;
9913: $uname = $cnum;
9914: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9915: $toplevel = $url;
9916: $path = $url;
9917: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9918: $fileloc =~ s{^/}{};
1.987 raeburn 9919: }
1.1126 raeburn 9920: foreach my $file (keys(%{$allfiles})) {
9921: my $embed_file;
9922: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9923: $embed_file = $1;
9924: } else {
9925: $embed_file = $file;
9926: }
1.1158 raeburn 9927: my ($absolutepath,$cleaned_file);
9928: if ($embed_file =~ m{^\w+://}) {
9929: $cleaned_file = $embed_file;
1.1147 raeburn 9930: $newfiles{$cleaned_file} = 1;
9931: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9932: } else {
1.1158 raeburn 9933: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 9934: if ($embed_file =~ m{^/}) {
9935: $absolutepath = $embed_file;
9936: }
1.1147 raeburn 9937: if ($cleaned_file =~ m{/}) {
9938: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 9939: $path = &check_for_traversal($path,$url,$toplevel);
9940: my $item = $fname;
9941: if ($path ne '') {
9942: $item = $path.'/'.$fname;
9943: $subdependencies{$path}{$fname} = 1;
9944: } else {
9945: $dependencies{$item} = 1;
9946: }
9947: if ($absolutepath) {
9948: $mapping{$item} = $absolutepath;
9949: } else {
9950: $mapping{$item} = $embed_file;
9951: }
9952: } else {
9953: $dependencies{$embed_file} = 1;
9954: if ($absolutepath) {
1.1147 raeburn 9955: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 9956: } else {
1.1147 raeburn 9957: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9958: }
9959: }
1.984 raeburn 9960: }
9961: }
1.1071 raeburn 9962: my $dirptr = 16384;
1.984 raeburn 9963: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9964: $currsubfile{$path} = {};
1.1123 raeburn 9965: if (($actionurl eq '/adm/portfolio') ||
9966: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9967: my ($sublistref,$listerror) =
9968: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9969: if (ref($sublistref) eq 'ARRAY') {
9970: foreach my $line (@{$sublistref}) {
9971: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9972: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9973: }
1.984 raeburn 9974: }
1.987 raeburn 9975: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9976: if (opendir(my $dir,$url.'/'.$path)) {
9977: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9978: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9979: }
1.1084 raeburn 9980: } elsif (($actionurl eq '/adm/dependencies') ||
9981: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 9982: ($args->{'context'} eq 'paste')) ||
9983: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9984: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 9985: my $dir;
9986: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9987: $dir = $fileloc;
9988: } else {
9989: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9990: }
1.1071 raeburn 9991: if ($dir ne '') {
9992: my ($sublistref,$listerror) =
9993: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9994: if (ref($sublistref) eq 'ARRAY') {
9995: foreach my $line (@{$sublistref}) {
9996: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9997: undef,$mtime)=split(/\&/,$line,12);
9998: unless (($testdir&$dirptr) ||
9999: ($file_name =~ /^\.\.?$/)) {
10000: $currsubfile{$path}{$file_name} = [$size,$mtime];
10001: }
10002: }
10003: }
10004: }
1.984 raeburn 10005: }
10006: }
10007: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10008: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10009: my $item = $path.'/'.$file;
10010: unless ($mapping{$item} eq $item) {
10011: $pathchanges{$item} = 1;
10012: }
10013: $existing{$item} = 1;
10014: $numexisting ++;
10015: } else {
10016: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10017: }
10018: }
1.1071 raeburn 10019: if ($actionurl eq '/adm/dependencies') {
10020: foreach my $path (keys(%currsubfile)) {
10021: if (ref($currsubfile{$path}) eq 'HASH') {
10022: foreach my $file (keys(%{$currsubfile{$path}})) {
10023: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 10024: next if (($rem ne '') &&
10025: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10026: (ref($navmap) &&
10027: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10028: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10029: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10030: $unused{$path.'/'.$file} = 1;
10031: }
10032: }
10033: }
10034: }
10035: }
1.984 raeburn 10036: }
1.987 raeburn 10037: my %currfile;
1.1123 raeburn 10038: if (($actionurl eq '/adm/portfolio') ||
10039: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10040: my ($dirlistref,$listerror) =
10041: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10042: if (ref($dirlistref) eq 'ARRAY') {
10043: foreach my $line (@{$dirlistref}) {
10044: my ($file_name,$rest) = split(/\&/,$line,2);
10045: $currfile{$file_name} = 1;
10046: }
1.984 raeburn 10047: }
1.987 raeburn 10048: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10049: if (opendir(my $dir,$url)) {
1.987 raeburn 10050: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10051: map {$currfile{$_} = 1;} @dir_list;
10052: }
1.1084 raeburn 10053: } elsif (($actionurl eq '/adm/dependencies') ||
10054: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 10055: ($args->{'context'} eq 'paste')) ||
10056: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10057: if ($env{'request.course.id'} ne '') {
10058: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10059: if ($dir ne '') {
10060: my ($dirlistref,$listerror) =
10061: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10062: if (ref($dirlistref) eq 'ARRAY') {
10063: foreach my $line (@{$dirlistref}) {
10064: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10065: $size,undef,$mtime)=split(/\&/,$line,12);
10066: unless (($testdir&$dirptr) ||
10067: ($file_name =~ /^\.\.?$/)) {
10068: $currfile{$file_name} = [$size,$mtime];
10069: }
10070: }
10071: }
10072: }
10073: }
1.984 raeburn 10074: }
10075: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10076: if (exists($currfile{$file})) {
1.987 raeburn 10077: unless ($mapping{$file} eq $file) {
10078: $pathchanges{$file} = 1;
10079: }
10080: $existing{$file} = 1;
10081: $numexisting ++;
10082: } else {
1.984 raeburn 10083: $newfiles{$file} = 1;
10084: }
10085: }
1.1071 raeburn 10086: foreach my $file (keys(%currfile)) {
10087: unless (($file eq $filename) ||
10088: ($file eq $filename.'.bak') ||
10089: ($dependencies{$file})) {
1.1085 raeburn 10090: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 10091: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10092: next if (($rem ne '') &&
10093: (($env{"httpref.$rem".$file} ne '') ||
10094: (ref($navmap) &&
10095: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10096: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10097: ($navmap->getResourceByUrl($rem.$1)))))));
10098: }
1.1085 raeburn 10099: }
1.1071 raeburn 10100: $unused{$file} = 1;
10101: }
10102: }
1.1084 raeburn 10103: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10104: ($args->{'context'} eq 'paste')) {
10105: $counter = scalar(keys(%existing));
10106: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 10107: return ($output,$counter,$numpathchg,\%existing);
10108: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10109: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10110: $counter = scalar(keys(%existing));
10111: $numpathchg = scalar(keys(%pathchanges));
10112: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 10113: }
1.984 raeburn 10114: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10115: if ($actionurl eq '/adm/dependencies') {
10116: next if ($embed_file =~ m{^\w+://});
10117: }
1.660 raeburn 10118: $upload_output .= &start_data_table_row().
1.1123 raeburn 10119: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10120: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10121: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 10122: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10123: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10124: }
1.1123 raeburn 10125: $upload_output .= '</td>';
1.1071 raeburn 10126: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 10127: $upload_output.='<td align="right">'.
10128: '<span class="LC_info LC_fontsize_medium">'.
10129: &mt("URL points to web address").'</span>';
1.987 raeburn 10130: $numremref++;
1.660 raeburn 10131: } elsif ($args->{'error_on_invalid_names'}
10132: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 10133: $upload_output.='<td align="right"><span class="LC_warning">'.
10134: &mt('Invalid characters').'</span>';
1.987 raeburn 10135: $numinvalid++;
1.660 raeburn 10136: } else {
1.1123 raeburn 10137: $upload_output .= '<td>'.
10138: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10139: $embed_file,\%mapping,
1.1071 raeburn 10140: $allfiles,$codebase,'upload');
10141: $counter ++;
10142: $numnew ++;
1.987 raeburn 10143: }
10144: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10145: }
10146: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10147: if ($actionurl eq '/adm/dependencies') {
10148: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10149: $modify_output .= &start_data_table_row().
10150: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10151: '<img src="'.&icon($embed_file).'" border="0" />'.
10152: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10153: '<td>'.$size.'</td>'.
10154: '<td>'.$mtime.'</td>'.
10155: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10156: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10157: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10158: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10159: &embedded_file_element('upload_embedded',$counter,
10160: $embed_file,\%mapping,
10161: $allfiles,$codebase,'modify').
10162: '</div></td>'.
10163: &end_data_table_row()."\n";
10164: $counter ++;
10165: } else {
10166: $upload_output .= &start_data_table_row().
1.1123 raeburn 10167: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10168: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10169: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10170: &Apache::loncommon::end_data_table_row()."\n";
10171: }
10172: }
10173: my $delidx = $counter;
10174: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10175: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10176: $delete_output .= &start_data_table_row().
10177: '<td><img src="'.&icon($oldfile).'" />'.
10178: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10179: '<td>'.$size.'</td>'.
10180: '<td>'.$mtime.'</td>'.
10181: '<td><label><input type="checkbox" name="del_upload_dep" '.
10182: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10183: &embedded_file_element('upload_embedded',$delidx,
10184: $oldfile,\%mapping,$allfiles,
10185: $codebase,'delete').'</td>'.
10186: &end_data_table_row()."\n";
10187: $numunused ++;
10188: $delidx ++;
1.987 raeburn 10189: }
10190: if ($upload_output) {
10191: $upload_output = &start_data_table().
10192: $upload_output.
10193: &end_data_table()."\n";
10194: }
1.1071 raeburn 10195: if ($modify_output) {
10196: $modify_output = &start_data_table().
10197: &start_data_table_header_row().
10198: '<th>'.&mt('File').'</th>'.
10199: '<th>'.&mt('Size (KB)').'</th>'.
10200: '<th>'.&mt('Modified').'</th>'.
10201: '<th>'.&mt('Upload replacement?').'</th>'.
10202: &end_data_table_header_row().
10203: $modify_output.
10204: &end_data_table()."\n";
10205: }
10206: if ($delete_output) {
10207: $delete_output = &start_data_table().
10208: &start_data_table_header_row().
10209: '<th>'.&mt('File').'</th>'.
10210: '<th>'.&mt('Size (KB)').'</th>'.
10211: '<th>'.&mt('Modified').'</th>'.
10212: '<th>'.&mt('Delete?').'</th>'.
10213: &end_data_table_header_row().
10214: $delete_output.
10215: &end_data_table()."\n";
10216: }
1.987 raeburn 10217: my $applies = 0;
10218: if ($numremref) {
10219: $applies ++;
10220: }
10221: if ($numinvalid) {
10222: $applies ++;
10223: }
10224: if ($numexisting) {
10225: $applies ++;
10226: }
1.1071 raeburn 10227: if ($counter || $numunused) {
1.987 raeburn 10228: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10229: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10230: $state.'<h3>'.$heading.'</h3>';
10231: if ($actionurl eq '/adm/dependencies') {
10232: if ($numnew) {
10233: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10234: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10235: $upload_output.'<br />'."\n";
10236: }
10237: if ($numexisting) {
10238: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10239: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10240: $modify_output.'<br />'."\n";
10241: $buttontext = &mt('Save changes');
10242: }
10243: if ($numunused) {
10244: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10245: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10246: $delete_output.'<br />'."\n";
10247: $buttontext = &mt('Save changes');
10248: }
10249: } else {
10250: $output .= $upload_output.'<br />'."\n";
10251: }
10252: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10253: $counter.'" />'."\n";
10254: if ($actionurl eq '/adm/dependencies') {
10255: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10256: $numnew.'" />'."\n";
10257: } elsif ($actionurl eq '') {
1.987 raeburn 10258: $output .= '<input type="hidden" name="phase" value="three" />';
10259: }
10260: } elsif ($applies) {
10261: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10262: if ($applies > 1) {
10263: $output .=
1.1123 raeburn 10264: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10265: if ($numremref) {
10266: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10267: }
10268: if ($numinvalid) {
10269: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10270: }
10271: if ($numexisting) {
10272: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10273: }
10274: $output .= '</ul><br />';
10275: } elsif ($numremref) {
10276: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10277: } elsif ($numinvalid) {
10278: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10279: } elsif ($numexisting) {
10280: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10281: }
10282: $output .= $upload_output.'<br />';
10283: }
10284: my ($pathchange_output,$chgcount);
1.1071 raeburn 10285: $chgcount = $counter;
1.987 raeburn 10286: if (keys(%pathchanges) > 0) {
10287: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10288: if ($counter) {
1.987 raeburn 10289: $output .= &embedded_file_element('pathchange',$chgcount,
10290: $embed_file,\%mapping,
1.1071 raeburn 10291: $allfiles,$codebase,'change');
1.987 raeburn 10292: } else {
10293: $pathchange_output .=
10294: &start_data_table_row().
10295: '<td><input type ="checkbox" name="namechange" value="'.
10296: $chgcount.'" checked="checked" /></td>'.
10297: '<td>'.$mapping{$embed_file}.'</td>'.
10298: '<td>'.$embed_file.
10299: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10300: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10301: '</td>'.&end_data_table_row();
1.660 raeburn 10302: }
1.987 raeburn 10303: $numpathchg ++;
10304: $chgcount ++;
1.660 raeburn 10305: }
10306: }
1.1127 raeburn 10307: if (($counter) || ($numunused)) {
1.987 raeburn 10308: if ($numpathchg) {
10309: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10310: $numpathchg.'" />'."\n";
10311: }
10312: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10313: ($actionurl eq '/adm/imsimport')) {
10314: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10315: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10316: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10317: } elsif ($actionurl eq '/adm/dependencies') {
10318: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10319: }
1.1123 raeburn 10320: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10321: } elsif ($numpathchg) {
10322: my %pathchange = ();
10323: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10324: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10325: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 10326: }
1.987 raeburn 10327: }
1.1071 raeburn 10328: return ($output,$counter,$numpathchg);
1.987 raeburn 10329: }
10330:
1.1147 raeburn 10331: =pod
10332:
10333: =item * clean_path($name)
10334:
10335: Performs clean-up of directories, subdirectories and filename in an
10336: embedded object, referenced in an HTML file which is being uploaded
10337: to a course or portfolio, where
10338: "Upload embedded images/multimedia files if HTML file" checkbox was
10339: checked.
10340:
10341: Clean-up is similar to replacements in lonnet::clean_filename()
10342: except each / between sub-directory and next level is preserved.
10343:
10344: =cut
10345:
10346: sub clean_path {
10347: my ($embed_file) = @_;
10348: $embed_file =~s{^/+}{};
10349: my @contents;
10350: if ($embed_file =~ m{/}) {
10351: @contents = split(/\//,$embed_file);
10352: } else {
10353: @contents = ($embed_file);
10354: }
10355: my $lastidx = scalar(@contents)-1;
10356: for (my $i=0; $i<=$lastidx; $i++) {
10357: $contents[$i]=~s{\\}{/}g;
10358: $contents[$i]=~s/\s+/\_/g;
10359: $contents[$i]=~s{[^/\w\.\-]}{}g;
10360: if ($i == $lastidx) {
10361: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10362: }
10363: }
10364: if ($lastidx > 0) {
10365: return join('/',@contents);
10366: } else {
10367: return $contents[0];
10368: }
10369: }
10370:
1.987 raeburn 10371: sub embedded_file_element {
1.1071 raeburn 10372: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10373: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10374: (ref($codebase) eq 'HASH'));
10375: my $output;
1.1071 raeburn 10376: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10377: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10378: }
10379: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10380: &escape($embed_file).'" />';
10381: unless (($context eq 'upload_embedded') &&
10382: ($mapping->{$embed_file} eq $embed_file)) {
10383: $output .='
10384: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10385: }
10386: my $attrib;
10387: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10388: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10389: }
10390: $output .=
10391: "\n\t\t".
10392: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10393: $attrib.'" />';
10394: if (exists($codebase->{$mapping->{$embed_file}})) {
10395: $output .=
10396: "\n\t\t".
10397: '<input name="codebase_'.$num.'" type="hidden" value="'.
10398: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10399: }
1.987 raeburn 10400: return $output;
1.660 raeburn 10401: }
10402:
1.1071 raeburn 10403: sub get_dependency_details {
10404: my ($currfile,$currsubfile,$embed_file) = @_;
10405: my ($size,$mtime,$showsize,$showmtime);
10406: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10407: if ($embed_file =~ m{/}) {
10408: my ($path,$fname) = split(/\//,$embed_file);
10409: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10410: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10411: }
10412: } else {
10413: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10414: ($size,$mtime) = @{$currfile->{$embed_file}};
10415: }
10416: }
10417: $showsize = $size/1024.0;
10418: $showsize = sprintf("%.1f",$showsize);
10419: if ($mtime > 0) {
10420: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10421: }
10422: }
10423: return ($showsize,$showmtime);
10424: }
10425:
10426: sub ask_embedded_js {
10427: return <<"END";
10428: <script type="text/javascript"">
10429: // <![CDATA[
10430: function toggleBrowse(counter) {
10431: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10432: var fileid = document.getElementById('embedded_item_'+counter);
10433: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10434: if (chkboxid.checked == true) {
10435: uploaddivid.style.display='block';
10436: } else {
10437: uploaddivid.style.display='none';
10438: fileid.value = '';
10439: }
10440: }
10441: // ]]>
10442: </script>
10443:
10444: END
10445: }
10446:
1.661 raeburn 10447: sub upload_embedded {
10448: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10449: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10450: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10451: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10452: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10453: my $orig_uploaded_filename =
10454: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10455: foreach my $type ('orig','ref','attrib','codebase') {
10456: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10457: $env{'form.embedded_'.$type.'_'.$i} =
10458: &unescape($env{'form.embedded_'.$type.'_'.$i});
10459: }
10460: }
1.661 raeburn 10461: my ($path,$fname) =
10462: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10463: # no path, whole string is fname
10464: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10465: $fname = &Apache::lonnet::clean_filename($fname);
10466: # See if there is anything left
10467: next if ($fname eq '');
10468:
10469: # Check if file already exists as a file or directory.
10470: my ($state,$msg);
10471: if ($context eq 'portfolio') {
10472: my $port_path = $dirpath;
10473: if ($group ne '') {
10474: $port_path = "groups/$group/$port_path";
10475: }
1.987 raeburn 10476: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10477: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10478: $dir_root,$port_path,$disk_quota,
10479: $current_disk_usage,$uname,$udom);
10480: if ($state eq 'will_exceed_quota'
1.984 raeburn 10481: || $state eq 'file_locked') {
1.661 raeburn 10482: $output .= $msg;
10483: next;
10484: }
10485: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10486: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10487: if ($state eq 'exists') {
10488: $output .= $msg;
10489: next;
10490: }
10491: }
10492: # Check if extension is valid
10493: if (($fname =~ /\.(\w+)$/) &&
10494: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 10495: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10496: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10497: next;
10498: } elsif (($fname =~ /\.(\w+)$/) &&
10499: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10500: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10501: next;
10502: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 10503: $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 10504: next;
10505: }
10506: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 10507: my $subdir = $path;
10508: $subdir =~ s{/+$}{};
1.661 raeburn 10509: if ($context eq 'portfolio') {
1.984 raeburn 10510: my $result;
10511: if ($state eq 'existingfile') {
10512: $result=
10513: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 10514: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10515: } else {
1.984 raeburn 10516: $result=
10517: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10518: $dirpath.
1.1123 raeburn 10519: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10520: if ($result !~ m|^/uploaded/|) {
10521: $output .= '<span class="LC_error">'
10522: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10523: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10524: .'</span><br />';
10525: next;
10526: } else {
1.987 raeburn 10527: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10528: $path.$fname.'</span>').'<br />';
1.984 raeburn 10529: }
1.661 raeburn 10530: }
1.1123 raeburn 10531: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 10532: my $extendedsubdir = $dirpath.'/'.$subdir;
10533: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10534: my $result =
1.1126 raeburn 10535: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10536: if ($result !~ m|^/uploaded/|) {
10537: $output .= '<span class="LC_error">'
10538: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10539: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10540: .'</span><br />';
10541: next;
10542: } else {
10543: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10544: $path.$fname.'</span>').'<br />';
1.1125 raeburn 10545: if ($context eq 'syllabus') {
10546: &Apache::lonnet::make_public_indefinitely($result);
10547: }
1.987 raeburn 10548: }
1.661 raeburn 10549: } else {
10550: # Save the file
10551: my $target = $env{'form.embedded_item_'.$i};
10552: my $fullpath = $dir_root.$dirpath.'/'.$path;
10553: my $dest = $fullpath.$fname;
10554: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10555: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10556: my $count;
10557: my $filepath = $dir_root;
1.1027 raeburn 10558: foreach my $subdir (@parts) {
10559: $filepath .= "/$subdir";
10560: if (!-e $filepath) {
1.661 raeburn 10561: mkdir($filepath,0770);
10562: }
10563: }
10564: my $fh;
10565: if (!open($fh,'>'.$dest)) {
10566: &Apache::lonnet::logthis('Failed to create '.$dest);
10567: $output .= '<span class="LC_error">'.
1.1071 raeburn 10568: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10569: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10570: '</span><br />';
10571: } else {
10572: if (!print $fh $env{'form.embedded_item_'.$i}) {
10573: &Apache::lonnet::logthis('Failed to write to '.$dest);
10574: $output .= '<span class="LC_error">'.
1.1071 raeburn 10575: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10576: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10577: '</span><br />';
10578: } else {
1.987 raeburn 10579: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10580: $url.'</span>').'<br />';
10581: unless ($context eq 'testbank') {
10582: $footer .= &mt('View embedded file: [_1]',
10583: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10584: }
10585: }
10586: close($fh);
10587: }
10588: }
10589: if ($env{'form.embedded_ref_'.$i}) {
10590: $pathchange{$i} = 1;
10591: }
10592: }
10593: if ($output) {
10594: $output = '<p>'.$output.'</p>';
10595: }
10596: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10597: $returnflag = 'ok';
1.1071 raeburn 10598: my $numpathchgs = scalar(keys(%pathchange));
10599: if ($numpathchgs > 0) {
1.987 raeburn 10600: if ($context eq 'portfolio') {
10601: $output .= '<p>'.&mt('or').'</p>';
10602: } elsif ($context eq 'testbank') {
1.1071 raeburn 10603: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10604: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10605: $returnflag = 'modify_orightml';
10606: }
10607: }
1.1071 raeburn 10608: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10609: }
10610:
10611: sub modify_html_form {
10612: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10613: my $end = 0;
10614: my $modifyform;
10615: if ($context eq 'upload_embedded') {
10616: return unless (ref($pathchange) eq 'HASH');
10617: if ($env{'form.number_embedded_items'}) {
10618: $end += $env{'form.number_embedded_items'};
10619: }
10620: if ($env{'form.number_pathchange_items'}) {
10621: $end += $env{'form.number_pathchange_items'};
10622: }
10623: if ($end) {
10624: for (my $i=0; $i<$end; $i++) {
10625: if ($i < $env{'form.number_embedded_items'}) {
10626: next unless($pathchange->{$i});
10627: }
10628: $modifyform .=
10629: &start_data_table_row().
10630: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10631: 'checked="checked" /></td>'.
10632: '<td>'.$env{'form.embedded_ref_'.$i}.
10633: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10634: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10635: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10636: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10637: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10638: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10639: '<td>'.$env{'form.embedded_orig_'.$i}.
10640: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10641: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10642: &end_data_table_row();
1.1071 raeburn 10643: }
1.987 raeburn 10644: }
10645: } else {
10646: $modifyform = $pathchgtable;
10647: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10648: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10649: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10650: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10651: }
10652: }
10653: if ($modifyform) {
1.1071 raeburn 10654: if ($actionurl eq '/adm/dependencies') {
10655: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10656: }
1.987 raeburn 10657: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10658: '<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".
10659: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10660: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10661: '</ol></p>'."\n".'<p>'.
10662: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10663: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10664: &start_data_table()."\n".
10665: &start_data_table_header_row().
10666: '<th>'.&mt('Change?').'</th>'.
10667: '<th>'.&mt('Current reference').'</th>'.
10668: '<th>'.&mt('Required reference').'</th>'.
10669: &end_data_table_header_row()."\n".
10670: $modifyform.
10671: &end_data_table().'<br />'."\n".$hiddenstate.
10672: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10673: '</form>'."\n";
10674: }
10675: return;
10676: }
10677:
10678: sub modify_html_refs {
1.1123 raeburn 10679: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10680: my $container;
10681: if ($context eq 'portfolio') {
10682: $container = $env{'form.container'};
10683: } elsif ($context eq 'coursedoc') {
10684: $container = $env{'form.primaryurl'};
1.1071 raeburn 10685: } elsif ($context eq 'manage_dependencies') {
10686: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10687: $container = "/$container";
1.1123 raeburn 10688: } elsif ($context eq 'syllabus') {
10689: $container = $url;
1.987 raeburn 10690: } else {
1.1027 raeburn 10691: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10692: }
10693: my (%allfiles,%codebase,$output,$content);
10694: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 10695: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10696: if (wantarray) {
10697: return ('',0,0);
10698: } else {
10699: return;
10700: }
10701: }
10702: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 10703: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10704: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10705: if (wantarray) {
10706: return ('',0,0);
10707: } else {
10708: return;
10709: }
10710: }
1.987 raeburn 10711: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10712: if ($content eq '-1') {
10713: if (wantarray) {
10714: return ('',0,0);
10715: } else {
10716: return;
10717: }
10718: }
1.987 raeburn 10719: } else {
1.1071 raeburn 10720: unless ($container =~ /^\Q$dir_root\E/) {
10721: if (wantarray) {
10722: return ('',0,0);
10723: } else {
10724: return;
10725: }
10726: }
1.987 raeburn 10727: if (open(my $fh,"<$container")) {
10728: $content = join('', <$fh>);
10729: close($fh);
10730: } else {
1.1071 raeburn 10731: if (wantarray) {
10732: return ('',0,0);
10733: } else {
10734: return;
10735: }
1.987 raeburn 10736: }
10737: }
10738: my ($count,$codebasecount) = (0,0);
10739: my $mm = new File::MMagic;
10740: my $mime_type = $mm->checktype_contents($content);
10741: if ($mime_type eq 'text/html') {
10742: my $parse_result =
10743: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10744: \%codebase,\$content);
10745: if ($parse_result eq 'ok') {
10746: foreach my $i (@changes) {
10747: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10748: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10749: if ($allfiles{$ref}) {
10750: my $newname = $orig;
10751: my ($attrib_regexp,$codebase);
1.1006 raeburn 10752: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10753: if ($attrib_regexp =~ /:/) {
10754: $attrib_regexp =~ s/\:/|/g;
10755: }
10756: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10757: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10758: $count += $numchg;
1.1123 raeburn 10759: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 10760: delete($allfiles{$ref});
1.987 raeburn 10761: }
10762: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10763: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10764: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10765: $codebasecount ++;
10766: }
10767: }
10768: }
1.1123 raeburn 10769: my $skiprewrites;
1.987 raeburn 10770: if ($count || $codebasecount) {
10771: my $saveresult;
1.1071 raeburn 10772: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 10773: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10774: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10775: if ($url eq $container) {
10776: my ($fname) = ($container =~ m{/([^/]+)$});
10777: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10778: $count,'<span class="LC_filename">'.
1.1071 raeburn 10779: $fname.'</span>').'</p>';
1.987 raeburn 10780: } else {
10781: $output = '<p class="LC_error">'.
10782: &mt('Error: update failed for: [_1].',
10783: '<span class="LC_filename">'.
10784: $container.'</span>').'</p>';
10785: }
1.1123 raeburn 10786: if ($context eq 'syllabus') {
10787: unless ($saveresult eq 'ok') {
10788: $skiprewrites = 1;
10789: }
10790: }
1.987 raeburn 10791: } else {
10792: if (open(my $fh,">$container")) {
10793: print $fh $content;
10794: close($fh);
10795: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10796: $count,'<span class="LC_filename">'.
10797: $container.'</span>').'</p>';
1.661 raeburn 10798: } else {
1.987 raeburn 10799: $output = '<p class="LC_error">'.
10800: &mt('Error: could not update [_1].',
10801: '<span class="LC_filename">'.
10802: $container.'</span>').'</p>';
1.661 raeburn 10803: }
10804: }
10805: }
1.1123 raeburn 10806: if (($context eq 'syllabus') && (!$skiprewrites)) {
10807: my ($actionurl,$state);
10808: $actionurl = "/public/$udom/$uname/syllabus";
10809: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10810: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10811: \%codebase,
10812: {'context' => 'rewrites',
10813: 'ignore_remote_references' => 1,});
10814: if (ref($mapping) eq 'HASH') {
10815: my $rewrites = 0;
10816: foreach my $key (keys(%{$mapping})) {
10817: next if ($key =~ m{^https?://});
10818: my $ref = $mapping->{$key};
10819: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10820: my $attrib;
10821: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10822: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10823: }
10824: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10825: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10826: $rewrites += $numchg;
10827: }
10828: }
10829: if ($rewrites) {
10830: my $saveresult;
10831: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10832: if ($url eq $container) {
10833: my ($fname) = ($container =~ m{/([^/]+)$});
10834: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10835: $count,'<span class="LC_filename">'.
10836: $fname.'</span>').'</p>';
10837: } else {
10838: $output .= '<p class="LC_error">'.
10839: &mt('Error: could not update links in [_1].',
10840: '<span class="LC_filename">'.
10841: $container.'</span>').'</p>';
10842:
10843: }
10844: }
10845: }
10846: }
1.987 raeburn 10847: } else {
10848: &logthis('Failed to parse '.$container.
10849: ' to modify references: '.$parse_result);
1.661 raeburn 10850: }
10851: }
1.1071 raeburn 10852: if (wantarray) {
10853: return ($output,$count,$codebasecount);
10854: } else {
10855: return $output;
10856: }
1.661 raeburn 10857: }
10858:
10859: sub check_for_existing {
10860: my ($path,$fname,$element) = @_;
10861: my ($state,$msg);
10862: if (-d $path.'/'.$fname) {
10863: $state = 'exists';
10864: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10865: } elsif (-e $path.'/'.$fname) {
10866: $state = 'exists';
10867: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10868: }
10869: if ($state eq 'exists') {
10870: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10871: }
10872: return ($state,$msg);
10873: }
10874:
10875: sub check_for_upload {
10876: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10877: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10878: my $filesize = length($env{'form.'.$element});
10879: if (!$filesize) {
10880: my $msg = '<span class="LC_error">'.
10881: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10882: '<span class="LC_filename">'.$fname.'</span>',
10883: $filesize).'<br />'.
1.1007 raeburn 10884: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10885: '</span>';
10886: return ('zero_bytes',$msg);
10887: }
10888: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10889: my $getpropath = 1;
1.1021 raeburn 10890: my ($dirlistref,$listerror) =
10891: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10892: my $found_file = 0;
10893: my $locked_file = 0;
1.991 raeburn 10894: my @lockers;
10895: my $navmap;
10896: if ($env{'request.course.id'}) {
10897: $navmap = Apache::lonnavmaps::navmap->new();
10898: }
1.1021 raeburn 10899: if (ref($dirlistref) eq 'ARRAY') {
10900: foreach my $line (@{$dirlistref}) {
10901: my ($file_name,$rest)=split(/\&/,$line,2);
10902: if ($file_name eq $fname){
10903: $file_name = $path.$file_name;
10904: if ($group ne '') {
10905: $file_name = $group.$file_name;
10906: }
10907: $found_file = 1;
10908: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10909: foreach my $lock (@lockers) {
10910: if (ref($lock) eq 'ARRAY') {
10911: my ($symb,$crsid) = @{$lock};
10912: if ($crsid eq $env{'request.course.id'}) {
10913: if (ref($navmap)) {
10914: my $res = $navmap->getBySymb($symb);
10915: foreach my $part (@{$res->parts()}) {
10916: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10917: unless (($slot_status == $res->RESERVED) ||
10918: ($slot_status == $res->RESERVED_LOCATION)) {
10919: $locked_file = 1;
10920: }
1.991 raeburn 10921: }
1.1021 raeburn 10922: } else {
10923: $locked_file = 1;
1.991 raeburn 10924: }
10925: } else {
10926: $locked_file = 1;
10927: }
10928: }
1.1021 raeburn 10929: }
10930: } else {
10931: my @info = split(/\&/,$rest);
10932: my $currsize = $info[6]/1000;
10933: if ($currsize < $filesize) {
10934: my $extra = $filesize - $currsize;
10935: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 10936: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 10937: &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.1179 bisitz 10938: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
10939: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10940: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 10941: return ('will_exceed_quota',$msg);
10942: }
1.984 raeburn 10943: }
10944: }
1.661 raeburn 10945: }
10946: }
10947: }
10948: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 10949: my $msg = '<p class="LC_warning">'.
10950: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 10951: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 10952: return ('will_exceed_quota',$msg);
10953: } elsif ($found_file) {
10954: if ($locked_file) {
1.1179 bisitz 10955: my $msg = '<p class="LC_warning">';
1.661 raeburn 10956: $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.1179 bisitz 10957: $msg .= '</p>';
1.661 raeburn 10958: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10959: return ('file_locked',$msg);
10960: } else {
1.1179 bisitz 10961: my $msg = '<p class="LC_error">';
1.984 raeburn 10962: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.1179 bisitz 10963: $msg .= '</p>';
1.984 raeburn 10964: return ('existingfile',$msg);
1.661 raeburn 10965: }
10966: }
10967: }
10968:
1.987 raeburn 10969: sub check_for_traversal {
10970: my ($path,$url,$toplevel) = @_;
10971: my @parts=split(/\//,$path);
10972: my $cleanpath;
10973: my $fullpath = $url;
10974: for (my $i=0;$i<@parts;$i++) {
10975: next if ($parts[$i] eq '.');
10976: if ($parts[$i] eq '..') {
10977: $fullpath =~ s{([^/]+/)$}{};
10978: } else {
10979: $fullpath .= $parts[$i].'/';
10980: }
10981: }
10982: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10983: $cleanpath = $1;
10984: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10985: my $curr_toprel = $1;
10986: my @parts = split(/\//,$curr_toprel);
10987: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10988: my @urlparts = split(/\//,$url_toprel);
10989: my $doubledots;
10990: my $startdiff = -1;
10991: for (my $i=0; $i<@urlparts; $i++) {
10992: if ($startdiff == -1) {
10993: unless ($urlparts[$i] eq $parts[$i]) {
10994: $startdiff = $i;
10995: $doubledots .= '../';
10996: }
10997: } else {
10998: $doubledots .= '../';
10999: }
11000: }
11001: if ($startdiff > -1) {
11002: $cleanpath = $doubledots;
11003: for (my $i=$startdiff; $i<@parts; $i++) {
11004: $cleanpath .= $parts[$i].'/';
11005: }
11006: }
11007: }
11008: $cleanpath =~ s{(/)$}{};
11009: return $cleanpath;
11010: }
1.31 albertel 11011:
1.1053 raeburn 11012: sub is_archive_file {
11013: my ($mimetype) = @_;
11014: if (($mimetype eq 'application/octet-stream') ||
11015: ($mimetype eq 'application/x-stuffit') ||
11016: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11017: return 1;
11018: }
11019: return;
11020: }
11021:
11022: sub decompress_form {
1.1065 raeburn 11023: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11024: my %lt = &Apache::lonlocal::texthash (
11025: this => 'This file is an archive file.',
1.1067 raeburn 11026: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11027: itsc => 'Its contents are as follows:',
1.1053 raeburn 11028: youm => 'You may wish to extract its contents.',
11029: extr => 'Extract contents',
1.1067 raeburn 11030: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11031: proa => 'Process automatically?',
1.1053 raeburn 11032: yes => 'Yes',
11033: no => 'No',
1.1067 raeburn 11034: fold => 'Title for folder containing movie',
11035: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11036: );
1.1065 raeburn 11037: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11038: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11039: my $info = &list_archive_contents($fileloc,\@paths);
11040: if (@paths) {
11041: foreach my $path (@paths) {
11042: $path =~ s{^/}{};
1.1067 raeburn 11043: if ($path =~ m{^([^/]+)/$}) {
11044: $topdir = $1;
11045: }
1.1065 raeburn 11046: if ($path =~ m{^([^/]+)/}) {
11047: $toplevel{$1} = $path;
11048: } else {
11049: $toplevel{$path} = $path;
11050: }
11051: }
11052: }
1.1067 raeburn 11053: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 11054: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11055: "$topdir/media/",
11056: "$topdir/media/$topdir.mp4",
11057: "$topdir/media/FirstFrame.png",
11058: "$topdir/media/player.swf",
11059: "$topdir/media/swfobject.js",
11060: "$topdir/media/expressInstall.swf");
1.1164 raeburn 11061: my @camtasia8 = ("$topdir/","$topdir/$topdir.html",
11062: "$topdir/$topdir.mp4",
11063: "$topdir/$topdir\_config.xml",
11064: "$topdir/$topdir\_controller.swf",
11065: "$topdir/$topdir\_embed.css",
11066: "$topdir/$topdir\_First_Frame.png",
11067: "$topdir/$topdir\_player.html",
11068: "$topdir/$topdir\_Thumbnails.png",
11069: "$topdir/playerProductInstall.swf",
11070: "$topdir/scripts/",
11071: "$topdir/scripts/config_xml.js",
11072: "$topdir/scripts/handlebars.js",
11073: "$topdir/scripts/jquery-1.7.1.min.js",
11074: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11075: "$topdir/scripts/modernizr.js",
11076: "$topdir/scripts/player-min.js",
11077: "$topdir/scripts/swfobject.js",
11078: "$topdir/skins/",
11079: "$topdir/skins/configuration_express.xml",
11080: "$topdir/skins/express_show/",
11081: "$topdir/skins/express_show/player-min.css",
11082: "$topdir/skins/express_show/spritesheet.png");
11083: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11084: if (@diffs == 0) {
1.1164 raeburn 11085: $is_camtasia = 6;
11086: } else {
11087: @diffs = &compare_arrays(\@paths,\@camtasia8);
11088: if (@diffs == 0) {
11089: $is_camtasia = 8;
11090: }
1.1067 raeburn 11091: }
11092: }
11093: my $output;
11094: if ($is_camtasia) {
11095: $output = <<"ENDCAM";
11096: <script type="text/javascript" language="Javascript">
11097: // <![CDATA[
11098:
11099: function camtasiaToggle() {
11100: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11101: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 11102: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11103:
11104: document.getElementById('camtasia_titles').style.display='block';
11105: } else {
11106: document.getElementById('camtasia_titles').style.display='none';
11107: }
11108: }
11109: }
11110: return;
11111: }
11112:
11113: // ]]>
11114: </script>
11115: <p>$lt{'camt'}</p>
11116: ENDCAM
1.1065 raeburn 11117: } else {
1.1067 raeburn 11118: $output = '<p>'.$lt{'this'};
11119: if ($info eq '') {
11120: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11121: } else {
11122: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11123: '<div><pre>'.$info.'</pre></div>';
11124: }
1.1065 raeburn 11125: }
1.1067 raeburn 11126: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11127: my $duplicates;
11128: my $num = 0;
11129: if (ref($dirlist) eq 'ARRAY') {
11130: foreach my $item (@{$dirlist}) {
11131: if (ref($item) eq 'ARRAY') {
11132: if (exists($toplevel{$item->[0]})) {
11133: $duplicates .=
11134: &start_data_table_row().
11135: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11136: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11137: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11138: 'value="1" />'.&mt('Yes').'</label>'.
11139: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11140: '<td>'.$item->[0].'</td>';
11141: if ($item->[2]) {
11142: $duplicates .= '<td>'.&mt('Directory').'</td>';
11143: } else {
11144: $duplicates .= '<td>'.&mt('File').'</td>';
11145: }
11146: $duplicates .= '<td>'.$item->[3].'</td>'.
11147: '<td>'.
11148: &Apache::lonlocal::locallocaltime($item->[4]).
11149: '</td>'.
11150: &end_data_table_row();
11151: $num ++;
11152: }
11153: }
11154: }
11155: }
11156: my $itemcount;
11157: if (@paths > 0) {
11158: $itemcount = scalar(@paths);
11159: } else {
11160: $itemcount = 1;
11161: }
1.1067 raeburn 11162: if ($is_camtasia) {
11163: $output .= $lt{'auto'}.'<br />'.
11164: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 11165: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11166: $lt{'yes'}.'</label> <label>'.
11167: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11168: $lt{'no'}.'</label></span><br />'.
11169: '<div id="camtasia_titles" style="display:block">'.
11170: &Apache::lonhtmlcommon::start_pick_box().
11171: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11172: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11173: &Apache::lonhtmlcommon::row_closure().
11174: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11175: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11176: &Apache::lonhtmlcommon::row_closure(1).
11177: &Apache::lonhtmlcommon::end_pick_box().
11178: '</div>';
11179: }
1.1065 raeburn 11180: $output .=
11181: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11182: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11183: "\n";
1.1065 raeburn 11184: if ($duplicates ne '') {
11185: $output .= '<p><span class="LC_warning">'.
11186: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11187: &start_data_table().
11188: &start_data_table_header_row().
11189: '<th>'.&mt('Overwrite?').'</th>'.
11190: '<th>'.&mt('Name').'</th>'.
11191: '<th>'.&mt('Type').'</th>'.
11192: '<th>'.&mt('Size').'</th>'.
11193: '<th>'.&mt('Last modified').'</th>'.
11194: &end_data_table_header_row().
11195: $duplicates.
11196: &end_data_table().
11197: '</p>';
11198: }
1.1067 raeburn 11199: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11200: if (ref($hiddenelements) eq 'HASH') {
11201: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11202: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11203: }
11204: }
11205: $output .= <<"END";
1.1067 raeburn 11206: <br />
1.1053 raeburn 11207: <input type="submit" name="decompress" value="$lt{'extr'}" />
11208: </form>
11209: $noextract
11210: END
11211: return $output;
11212: }
11213:
1.1065 raeburn 11214: sub decompression_utility {
11215: my ($program) = @_;
11216: my @utilities = ('tar','gunzip','bunzip2','unzip');
11217: my $location;
11218: if (grep(/^\Q$program\E$/,@utilities)) {
11219: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11220: '/usr/sbin/') {
11221: if (-x $dir.$program) {
11222: $location = $dir.$program;
11223: last;
11224: }
11225: }
11226: }
11227: return $location;
11228: }
11229:
11230: sub list_archive_contents {
11231: my ($file,$pathsref) = @_;
11232: my (@cmd,$output);
11233: my $needsregexp;
11234: if ($file =~ /\.zip$/) {
11235: @cmd = (&decompression_utility('unzip'),"-l");
11236: $needsregexp = 1;
11237: } elsif (($file =~ m/\.tar\.gz$/) ||
11238: ($file =~ /\.tgz$/)) {
11239: @cmd = (&decompression_utility('tar'),"-ztf");
11240: } elsif ($file =~ /\.tar\.bz2$/) {
11241: @cmd = (&decompression_utility('tar'),"-jtf");
11242: } elsif ($file =~ m|\.tar$|) {
11243: @cmd = (&decompression_utility('tar'),"-tf");
11244: }
11245: if (@cmd) {
11246: undef($!);
11247: undef($@);
11248: if (open(my $fh,"-|", @cmd, $file)) {
11249: while (my $line = <$fh>) {
11250: $output .= $line;
11251: chomp($line);
11252: my $item;
11253: if ($needsregexp) {
11254: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11255: } else {
11256: $item = $line;
11257: }
11258: if ($item ne '') {
11259: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11260: push(@{$pathsref},$item);
11261: }
11262: }
11263: }
11264: close($fh);
11265: }
11266: }
11267: return $output;
11268: }
11269:
1.1053 raeburn 11270: sub decompress_uploaded_file {
11271: my ($file,$dir) = @_;
11272: &Apache::lonnet::appenv({'cgi.file' => $file});
11273: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11274: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11275: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11276: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11277: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11278: my $decompressed = $env{'cgi.decompressed'};
11279: &Apache::lonnet::delenv('cgi.file');
11280: &Apache::lonnet::delenv('cgi.dir');
11281: &Apache::lonnet::delenv('cgi.decompressed');
11282: return ($decompressed,$result);
11283: }
11284:
1.1055 raeburn 11285: sub process_decompression {
11286: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11287: my ($dir,$error,$warning,$output);
1.1180 raeburn 11288: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 11289: $error = &mt('Filename not a supported archive file type.').
11290: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11291: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11292: } else {
11293: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11294: if ($docuhome eq 'no_host') {
11295: $error = &mt('Could not determine home server for course.');
11296: } else {
11297: my @ids=&Apache::lonnet::current_machine_ids();
11298: my $currdir = "$dir_root/$destination";
11299: if (grep(/^\Q$docuhome\E$/,@ids)) {
11300: $dir = &LONCAPA::propath($docudom,$docuname).
11301: "$dir_root/$destination";
11302: } else {
11303: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11304: "$dir_root/$docudom/$docuname/$destination";
11305: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11306: $error = &mt('Archive file not found.');
11307: }
11308: }
1.1065 raeburn 11309: my (@to_overwrite,@to_skip);
11310: if ($env{'form.archive_overwrite_total'} > 0) {
11311: my $total = $env{'form.archive_overwrite_total'};
11312: for (my $i=0; $i<$total; $i++) {
11313: if ($env{'form.archive_overwrite_'.$i} == 1) {
11314: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11315: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11316: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11317: }
11318: }
11319: }
11320: my $numskip = scalar(@to_skip);
11321: if (($numskip > 0) &&
11322: ($numskip == $env{'form.archive_itemcount'})) {
11323: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11324: } elsif ($dir eq '') {
1.1055 raeburn 11325: $error = &mt('Directory containing archive file unavailable.');
11326: } elsif (!$error) {
1.1065 raeburn 11327: my ($decompressed,$display);
11328: if ($numskip > 0) {
11329: my $tempdir = time.'_'.$$.int(rand(10000));
11330: mkdir("$dir/$tempdir",0755);
11331: system("mv $dir/$file $dir/$tempdir/$file");
11332: ($decompressed,$display) =
11333: &decompress_uploaded_file($file,"$dir/$tempdir");
11334: foreach my $item (@to_skip) {
11335: if (($item ne '') && ($item !~ /\.\./)) {
11336: if (-f "$dir/$tempdir/$item") {
11337: unlink("$dir/$tempdir/$item");
11338: } elsif (-d "$dir/$tempdir/$item") {
11339: system("rm -rf $dir/$tempdir/$item");
11340: }
11341: }
11342: }
11343: system("mv $dir/$tempdir/* $dir");
11344: rmdir("$dir/$tempdir");
11345: } else {
11346: ($decompressed,$display) =
11347: &decompress_uploaded_file($file,$dir);
11348: }
1.1055 raeburn 11349: if ($decompressed eq 'ok') {
1.1065 raeburn 11350: $output = '<p class="LC_info">'.
11351: &mt('Files extracted successfully from archive.').
11352: '</p>'."\n";
1.1055 raeburn 11353: my ($warning,$result,@contents);
11354: my ($newdirlistref,$newlisterror) =
11355: &Apache::lonnet::dirlist($currdir,$docudom,
11356: $docuname,1);
11357: my (%is_dir,%changes,@newitems);
11358: my $dirptr = 16384;
1.1065 raeburn 11359: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11360: foreach my $dir_line (@{$newdirlistref}) {
11361: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11362: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11363: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11364: push(@newitems,$item);
11365: if ($dirptr&$testdir) {
11366: $is_dir{$item} = 1;
11367: }
11368: $changes{$item} = 1;
11369: }
11370: }
11371: }
11372: if (keys(%changes) > 0) {
11373: foreach my $item (sort(@newitems)) {
11374: if ($changes{$item}) {
11375: push(@contents,$item);
11376: }
11377: }
11378: }
11379: if (@contents > 0) {
1.1067 raeburn 11380: my $wantform;
11381: unless ($env{'form.autoextract_camtasia'}) {
11382: $wantform = 1;
11383: }
1.1056 raeburn 11384: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11385: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11386: $currdir,\%is_dir,
11387: \%children,\%parent,
1.1056 raeburn 11388: \@contents,\%dirorder,
11389: \%titles,$wantform);
1.1055 raeburn 11390: if ($datatable ne '') {
11391: $output .= &archive_options_form('decompressed',$datatable,
11392: $count,$hiddenelem);
1.1065 raeburn 11393: my $startcount = 6;
1.1055 raeburn 11394: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11395: \%titles,\%children);
1.1055 raeburn 11396: }
1.1067 raeburn 11397: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 11398: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 11399: my %displayed;
11400: my $total = 1;
11401: $env{'form.archive_directory'} = [];
11402: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11403: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11404: $path =~ s{/$}{};
11405: my $item;
11406: if ($path ne '') {
11407: $item = "$path/$titles{$i}";
11408: } else {
11409: $item = $titles{$i};
11410: }
11411: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11412: if ($item eq $contents[0]) {
11413: push(@{$env{'form.archive_directory'}},$i);
11414: $env{'form.archive_'.$i} = 'display';
11415: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11416: $displayed{'folder'} = $i;
1.1164 raeburn 11417: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
11418: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 11419: $env{'form.archive_'.$i} = 'display';
11420: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11421: $displayed{'web'} = $i;
11422: } else {
1.1164 raeburn 11423: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
11424: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
11425: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 11426: push(@{$env{'form.archive_directory'}},$i);
11427: }
11428: $env{'form.archive_'.$i} = 'dependency';
11429: }
11430: $total ++;
11431: }
11432: for (my $i=1; $i<$total; $i++) {
11433: next if ($i == $displayed{'web'});
11434: next if ($i == $displayed{'folder'});
11435: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11436: }
11437: $env{'form.phase'} = 'decompress_cleanup';
11438: $env{'form.archivedelete'} = 1;
11439: $env{'form.archive_count'} = $total-1;
11440: $output .=
11441: &process_extracted_files('coursedocs',$docudom,
11442: $docuname,$destination,
11443: $dir_root,$hiddenelem);
11444: }
1.1055 raeburn 11445: } else {
11446: $warning = &mt('No new items extracted from archive file.');
11447: }
11448: } else {
11449: $output = $display;
11450: $error = &mt('An error occurred during extraction from the archive file.');
11451: }
11452: }
11453: }
11454: }
11455: if ($error) {
11456: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11457: $error.'</p>'."\n";
11458: }
11459: if ($warning) {
11460: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11461: }
11462: return $output;
11463: }
11464:
11465: sub get_extracted {
1.1056 raeburn 11466: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11467: $titles,$wantform) = @_;
1.1055 raeburn 11468: my $count = 0;
11469: my $depth = 0;
11470: my $datatable;
1.1056 raeburn 11471: my @hierarchy;
1.1055 raeburn 11472: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11473: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11474: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11475: foreach my $item (@{$contents}) {
11476: $count ++;
1.1056 raeburn 11477: @{$dirorder->{$count}} = @hierarchy;
11478: $titles->{$count} = $item;
1.1055 raeburn 11479: &archive_hierarchy($depth,$count,$parent,$children);
11480: if ($wantform) {
11481: $datatable .= &archive_row($is_dir->{$item},$item,
11482: $currdir,$depth,$count);
11483: }
11484: if ($is_dir->{$item}) {
11485: $depth ++;
1.1056 raeburn 11486: push(@hierarchy,$count);
11487: $parent->{$depth} = $count;
1.1055 raeburn 11488: $datatable .=
11489: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11490: \$depth,\$count,\@hierarchy,$dirorder,
11491: $children,$parent,$titles,$wantform);
1.1055 raeburn 11492: $depth --;
1.1056 raeburn 11493: pop(@hierarchy);
1.1055 raeburn 11494: }
11495: }
11496: return ($count,$datatable);
11497: }
11498:
11499: sub recurse_extracted_archive {
1.1056 raeburn 11500: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11501: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11502: my $result='';
1.1056 raeburn 11503: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11504: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11505: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11506: return $result;
11507: }
11508: my $dirptr = 16384;
11509: my ($newdirlistref,$newlisterror) =
11510: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11511: if (ref($newdirlistref) eq 'ARRAY') {
11512: foreach my $dir_line (@{$newdirlistref}) {
11513: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11514: unless ($item =~ /^\.+$/) {
11515: $$count ++;
1.1056 raeburn 11516: @{$dirorder->{$$count}} = @{$hierarchy};
11517: $titles->{$$count} = $item;
1.1055 raeburn 11518: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11519:
1.1055 raeburn 11520: my $is_dir;
11521: if ($dirptr&$testdir) {
11522: $is_dir = 1;
11523: }
11524: if ($wantform) {
11525: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11526: }
11527: if ($is_dir) {
11528: $$depth ++;
1.1056 raeburn 11529: push(@{$hierarchy},$$count);
11530: $parent->{$$depth} = $$count;
1.1055 raeburn 11531: $result .=
11532: &recurse_extracted_archive("$currdir/$item",$docudom,
11533: $docuname,$depth,$count,
1.1056 raeburn 11534: $hierarchy,$dirorder,$children,
11535: $parent,$titles,$wantform);
1.1055 raeburn 11536: $$depth --;
1.1056 raeburn 11537: pop(@{$hierarchy});
1.1055 raeburn 11538: }
11539: }
11540: }
11541: }
11542: return $result;
11543: }
11544:
11545: sub archive_hierarchy {
11546: my ($depth,$count,$parent,$children) =@_;
11547: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11548: if (exists($parent->{$depth})) {
11549: $children->{$parent->{$depth}} .= $count.':';
11550: }
11551: }
11552: return;
11553: }
11554:
11555: sub archive_row {
11556: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11557: my ($name) = ($item =~ m{([^/]+)$});
11558: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11559: 'display' => 'Add as file',
1.1055 raeburn 11560: 'dependency' => 'Include as dependency',
11561: 'discard' => 'Discard',
11562: );
11563: if ($is_dir) {
1.1059 raeburn 11564: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11565: }
1.1056 raeburn 11566: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11567: my $offset = 0;
1.1055 raeburn 11568: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11569: $offset ++;
1.1065 raeburn 11570: if ($action ne 'display') {
11571: $offset ++;
11572: }
1.1055 raeburn 11573: $output .= '<td><span class="LC_nobreak">'.
11574: '<label><input type="radio" name="archive_'.$count.
11575: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11576: my $text = $choices{$action};
11577: if ($is_dir) {
11578: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11579: if ($action eq 'display') {
1.1059 raeburn 11580: $text = &mt('Add as folder');
1.1055 raeburn 11581: }
1.1056 raeburn 11582: } else {
11583: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11584:
11585: }
11586: $output .= ' /> '.$choices{$action}.'</label></span>';
11587: if ($action eq 'dependency') {
11588: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11589: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11590: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11591: '<option value=""></option>'."\n".
11592: '</select>'."\n".
11593: '</div>';
1.1059 raeburn 11594: } elsif ($action eq 'display') {
11595: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11596: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11597: '</div>';
1.1055 raeburn 11598: }
1.1056 raeburn 11599: $output .= '</td>';
1.1055 raeburn 11600: }
11601: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11602: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11603: for (my $i=0; $i<$depth; $i++) {
11604: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11605: }
11606: if ($is_dir) {
11607: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11608: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11609: } else {
11610: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11611: }
11612: $output .= ' '.$name.'</td>'."\n".
11613: &end_data_table_row();
11614: return $output;
11615: }
11616:
11617: sub archive_options_form {
1.1065 raeburn 11618: my ($form,$display,$count,$hiddenelem) = @_;
11619: my %lt = &Apache::lonlocal::texthash(
11620: perm => 'Permanently remove archive file?',
11621: hows => 'How should each extracted item be incorporated in the course?',
11622: cont => 'Content actions for all',
11623: addf => 'Add as folder/file',
11624: incd => 'Include as dependency for a displayed file',
11625: disc => 'Discard',
11626: no => 'No',
11627: yes => 'Yes',
11628: save => 'Save',
11629: );
11630: my $output = <<"END";
11631: <form name="$form" method="post" action="">
11632: <p><span class="LC_nobreak">$lt{'perm'}
11633: <label>
11634: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11635: </label>
11636:
11637: <label>
11638: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11639: </span>
11640: </p>
11641: <input type="hidden" name="phase" value="decompress_cleanup" />
11642: <br />$lt{'hows'}
11643: <div class="LC_columnSection">
11644: <fieldset>
11645: <legend>$lt{'cont'}</legend>
11646: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11647: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11648: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11649: </fieldset>
11650: </div>
11651: END
11652: return $output.
1.1055 raeburn 11653: &start_data_table()."\n".
1.1065 raeburn 11654: $display."\n".
1.1055 raeburn 11655: &end_data_table()."\n".
11656: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11657: $hiddenelem.
1.1065 raeburn 11658: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11659: '</form>';
11660: }
11661:
11662: sub archive_javascript {
1.1056 raeburn 11663: my ($startcount,$numitems,$titles,$children) = @_;
11664: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11665: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11666: my $scripttag = <<START;
11667: <script type="text/javascript">
11668: // <![CDATA[
11669:
11670: function checkAll(form,prefix) {
11671: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11672: for (var i=0; i < form.elements.length; i++) {
11673: var id = form.elements[i].id;
11674: if ((id != '') && (id != undefined)) {
11675: if (idstr.test(id)) {
11676: if (form.elements[i].type == 'radio') {
11677: form.elements[i].checked = true;
1.1056 raeburn 11678: var nostart = i-$startcount;
1.1059 raeburn 11679: var offset = nostart%7;
11680: var count = (nostart-offset)/7;
1.1056 raeburn 11681: dependencyCheck(form,count,offset);
1.1055 raeburn 11682: }
11683: }
11684: }
11685: }
11686: }
11687:
11688: function propagateCheck(form,count) {
11689: if (count > 0) {
1.1059 raeburn 11690: var startelement = $startcount + ((count-1) * 7);
11691: for (var j=1; j<6; j++) {
11692: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11693: var item = startelement + j;
11694: if (form.elements[item].type == 'radio') {
11695: if (form.elements[item].checked) {
11696: containerCheck(form,count,j);
11697: break;
11698: }
1.1055 raeburn 11699: }
11700: }
11701: }
11702: }
11703: }
11704:
11705: numitems = $numitems
1.1056 raeburn 11706: var titles = new Array(numitems);
11707: var parents = new Array(numitems);
1.1055 raeburn 11708: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11709: parents[i] = new Array;
1.1055 raeburn 11710: }
1.1059 raeburn 11711: var maintitle = '$maintitle';
1.1055 raeburn 11712:
11713: START
11714:
1.1056 raeburn 11715: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11716: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11717: for (my $i=0; $i<@contents; $i ++) {
11718: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11719: }
11720: }
11721:
1.1056 raeburn 11722: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11723: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11724: }
11725:
1.1055 raeburn 11726: $scripttag .= <<END;
11727:
11728: function containerCheck(form,count,offset) {
11729: if (count > 0) {
1.1056 raeburn 11730: dependencyCheck(form,count,offset);
1.1059 raeburn 11731: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11732: form.elements[item].checked = true;
11733: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11734: if (parents[count].length > 0) {
11735: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11736: containerCheck(form,parents[count][j],offset);
11737: }
11738: }
11739: }
11740: }
11741: }
11742:
11743: function dependencyCheck(form,count,offset) {
11744: if (count > 0) {
1.1059 raeburn 11745: var chosen = (offset+$startcount)+7*(count-1);
11746: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11747: var currtype = form.elements[depitem].type;
11748: if (form.elements[chosen].value == 'dependency') {
11749: document.getElementById('arc_depon_'+count).style.display='block';
11750: form.elements[depitem].options.length = 0;
11751: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 11752: for (var i=1; i<=numitems; i++) {
11753: if (i == count) {
11754: continue;
11755: }
1.1059 raeburn 11756: var startelement = $startcount + (i-1) * 7;
11757: for (var j=1; j<6; j++) {
11758: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11759: var item = startelement + j;
11760: if (form.elements[item].type == 'radio') {
11761: if (form.elements[item].checked) {
11762: if (form.elements[item].value == 'display') {
11763: var n = form.elements[depitem].options.length;
11764: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11765: }
11766: }
11767: }
11768: }
11769: }
11770: }
11771: } else {
11772: document.getElementById('arc_depon_'+count).style.display='none';
11773: form.elements[depitem].options.length = 0;
11774: form.elements[depitem].options[0] = new Option('Select','',true,true);
11775: }
1.1059 raeburn 11776: titleCheck(form,count,offset);
1.1056 raeburn 11777: }
11778: }
11779:
11780: function propagateSelect(form,count,offset) {
11781: if (count > 0) {
1.1065 raeburn 11782: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11783: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11784: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11785: if (parents[count].length > 0) {
11786: for (var j=0; j<parents[count].length; j++) {
11787: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11788: }
11789: }
11790: }
11791: }
11792: }
1.1056 raeburn 11793:
11794: function containerSelect(form,count,offset,picked) {
11795: if (count > 0) {
1.1065 raeburn 11796: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11797: if (form.elements[item].type == 'radio') {
11798: if (form.elements[item].value == 'dependency') {
11799: if (form.elements[item+1].type == 'select-one') {
11800: for (var i=0; i<form.elements[item+1].options.length; i++) {
11801: if (form.elements[item+1].options[i].value == picked) {
11802: form.elements[item+1].selectedIndex = i;
11803: break;
11804: }
11805: }
11806: }
11807: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11808: if (parents[count].length > 0) {
11809: for (var j=0; j<parents[count].length; j++) {
11810: containerSelect(form,parents[count][j],offset,picked);
11811: }
11812: }
11813: }
11814: }
11815: }
11816: }
11817: }
11818:
1.1059 raeburn 11819: function titleCheck(form,count,offset) {
11820: if (count > 0) {
11821: var chosen = (offset+$startcount)+7*(count-1);
11822: var depitem = $startcount + ((count-1) * 7) + 2;
11823: var currtype = form.elements[depitem].type;
11824: if (form.elements[chosen].value == 'display') {
11825: document.getElementById('arc_title_'+count).style.display='block';
11826: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11827: document.getElementById('archive_title_'+count).value=maintitle;
11828: }
11829: } else {
11830: document.getElementById('arc_title_'+count).style.display='none';
11831: if (currtype == 'text') {
11832: document.getElementById('archive_title_'+count).value='';
11833: }
11834: }
11835: }
11836: return;
11837: }
11838:
1.1055 raeburn 11839: // ]]>
11840: </script>
11841: END
11842: return $scripttag;
11843: }
11844:
11845: sub process_extracted_files {
1.1067 raeburn 11846: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11847: my $numitems = $env{'form.archive_count'};
11848: return unless ($numitems);
11849: my @ids=&Apache::lonnet::current_machine_ids();
11850: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11851: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11852: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11853: if (grep(/^\Q$docuhome\E$/,@ids)) {
11854: $prefix = &LONCAPA::propath($docudom,$docuname);
11855: $pathtocheck = "$dir_root/$destination";
11856: $dir = $dir_root;
11857: $ishome = 1;
11858: } else {
11859: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11860: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11861: $dir = "$dir_root/$docudom/$docuname";
11862: }
11863: my $currdir = "$dir_root/$destination";
11864: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11865: if ($env{'form.folderpath'}) {
11866: my @items = split('&',$env{'form.folderpath'});
11867: $folders{'0'} = $items[-2];
1.1099 raeburn 11868: if ($env{'form.folderpath'} =~ /\:1$/) {
11869: $containers{'0'}='page';
11870: } else {
11871: $containers{'0'}='sequence';
11872: }
1.1055 raeburn 11873: }
11874: my @archdirs = &get_env_multiple('form.archive_directory');
11875: if ($numitems) {
11876: for (my $i=1; $i<=$numitems; $i++) {
11877: my $path = $env{'form.archive_content_'.$i};
11878: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11879: my $item = $1;
11880: $toplevelitems{$item} = $i;
11881: if (grep(/^\Q$i\E$/,@archdirs)) {
11882: $is_dir{$item} = 1;
11883: }
11884: }
11885: }
11886: }
1.1067 raeburn 11887: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11888: if (keys(%toplevelitems) > 0) {
11889: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11890: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11891: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11892: }
1.1066 raeburn 11893: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11894: if ($numitems) {
11895: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 11896: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11897: my $path = $env{'form.archive_content_'.$i};
11898: if ($path =~ /^\Q$pathtocheck\E/) {
11899: if ($env{'form.archive_'.$i} eq 'discard') {
11900: if ($prefix ne '' && $path ne '') {
11901: if (-e $prefix.$path) {
1.1066 raeburn 11902: if ((@archdirs > 0) &&
11903: (grep(/^\Q$i\E$/,@archdirs))) {
11904: $todeletedir{$prefix.$path} = 1;
11905: } else {
11906: $todelete{$prefix.$path} = 1;
11907: }
1.1055 raeburn 11908: }
11909: }
11910: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11911: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11912: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11913: $docstitle = $env{'form.archive_title_'.$i};
11914: if ($docstitle eq '') {
11915: $docstitle = $title;
11916: }
1.1055 raeburn 11917: $outer = 0;
1.1056 raeburn 11918: if (ref($dirorder{$i}) eq 'ARRAY') {
11919: if (@{$dirorder{$i}} > 0) {
11920: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11921: if ($env{'form.archive_'.$item} eq 'display') {
11922: $outer = $item;
11923: last;
11924: }
11925: }
11926: }
11927: }
11928: my ($errtext,$fatal) =
11929: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11930: '/'.$folders{$outer}.'.'.
11931: $containers{$outer});
11932: next if ($fatal);
11933: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11934: if ($context eq 'coursedocs') {
1.1056 raeburn 11935: $mapinner{$i} = time;
1.1055 raeburn 11936: $folders{$i} = 'default_'.$mapinner{$i};
11937: $containers{$i} = 'sequence';
11938: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11939: $folders{$i}.'.'.$containers{$i};
11940: my $newidx = &LONCAPA::map::getresidx();
11941: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11942: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11943: push(@LONCAPA::map::order,$newidx);
11944: my ($outtext,$errtext) =
11945: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11946: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11947: '.'.$containers{$outer},1,1);
1.1056 raeburn 11948: $newseqid{$i} = $newidx;
1.1067 raeburn 11949: unless ($errtext) {
11950: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11951: }
1.1055 raeburn 11952: }
11953: } else {
11954: if ($context eq 'coursedocs') {
11955: my $newidx=&LONCAPA::map::getresidx();
11956: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11957: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11958: $title;
11959: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11960: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11961: }
11962: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11963: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11964: }
11965: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11966: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11967: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11968: unless ($ishome) {
11969: my $fetch = "$newdest{$i}/$title";
11970: $fetch =~ s/^\Q$prefix$dir\E//;
11971: $prompttofetch{$fetch} = 1;
11972: }
1.1055 raeburn 11973: }
11974: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11975: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11976: push(@LONCAPA::map::order, $newidx);
11977: my ($outtext,$errtext)=
11978: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11979: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11980: '.'.$containers{$outer},1,1);
1.1067 raeburn 11981: unless ($errtext) {
11982: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11983: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11984: }
11985: }
1.1055 raeburn 11986: }
11987: }
1.1086 raeburn 11988: }
11989: } else {
11990: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11991: }
11992: }
11993: for (my $i=1; $i<=$numitems; $i++) {
11994: next unless ($env{'form.archive_'.$i} eq 'dependency');
11995: my $path = $env{'form.archive_content_'.$i};
11996: if ($path =~ /^\Q$pathtocheck\E/) {
11997: my ($title) = ($path =~ m{/([^/]+)$});
11998: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11999: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12000: if (ref($dirorder{$i}) eq 'ARRAY') {
12001: my ($itemidx,$fullpath,$relpath);
12002: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12003: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12004: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 12005: if ($dirorder{$i}->[$j] eq $container) {
12006: $itemidx = $j;
1.1056 raeburn 12007: }
12008: }
1.1086 raeburn 12009: }
12010: if ($itemidx eq '') {
12011: $itemidx = 0;
12012: }
12013: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12014: if ($mapinner{$referrer{$i}}) {
12015: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12016: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12017: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12018: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12019: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12020: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12021: if (!-e $fullpath) {
12022: mkdir($fullpath,0755);
1.1056 raeburn 12023: }
12024: }
1.1086 raeburn 12025: } else {
12026: last;
1.1056 raeburn 12027: }
1.1086 raeburn 12028: }
12029: }
12030: } elsif ($newdest{$referrer{$i}}) {
12031: $fullpath = $newdest{$referrer{$i}};
12032: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12033: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12034: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12035: last;
12036: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12037: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12038: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12039: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12040: if (!-e $fullpath) {
12041: mkdir($fullpath,0755);
1.1056 raeburn 12042: }
12043: }
1.1086 raeburn 12044: } else {
12045: last;
1.1056 raeburn 12046: }
1.1055 raeburn 12047: }
12048: }
1.1086 raeburn 12049: if ($fullpath ne '') {
12050: if (-e "$prefix$path") {
12051: system("mv $prefix$path $fullpath/$title");
12052: }
12053: if (-e "$fullpath/$title") {
12054: my $showpath;
12055: if ($relpath ne '') {
12056: $showpath = "$relpath/$title";
12057: } else {
12058: $showpath = "/$title";
12059: }
12060: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12061: }
12062: unless ($ishome) {
12063: my $fetch = "$fullpath/$title";
12064: $fetch =~ s/^\Q$prefix$dir\E//;
12065: $prompttofetch{$fetch} = 1;
12066: }
12067: }
1.1055 raeburn 12068: }
1.1086 raeburn 12069: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12070: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12071: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12072: }
12073: } else {
12074: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12075: }
12076: }
12077: if (keys(%todelete)) {
12078: foreach my $key (keys(%todelete)) {
12079: unlink($key);
1.1066 raeburn 12080: }
12081: }
12082: if (keys(%todeletedir)) {
12083: foreach my $key (keys(%todeletedir)) {
12084: rmdir($key);
12085: }
12086: }
12087: foreach my $dir (sort(keys(%is_dir))) {
12088: if (($pathtocheck ne '') && ($dir ne '')) {
12089: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12090: }
12091: }
1.1067 raeburn 12092: if ($result ne '') {
12093: $output .= '<ul>'."\n".
12094: $result."\n".
12095: '</ul>';
12096: }
12097: unless ($ishome) {
12098: my $replicationfail;
12099: foreach my $item (keys(%prompttofetch)) {
12100: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12101: unless ($fetchresult eq 'ok') {
12102: $replicationfail .= '<li>'.$item.'</li>'."\n";
12103: }
12104: }
12105: if ($replicationfail) {
12106: $output .= '<p class="LC_error">'.
12107: &mt('Course home server failed to retrieve:').'<ul>'.
12108: $replicationfail.
12109: '</ul></p>';
12110: }
12111: }
1.1055 raeburn 12112: } else {
12113: $warning = &mt('No items found in archive.');
12114: }
12115: if ($error) {
12116: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12117: $error.'</p>'."\n";
12118: }
12119: if ($warning) {
12120: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12121: }
12122: return $output;
12123: }
12124:
1.1066 raeburn 12125: sub cleanup_empty_dirs {
12126: my ($path) = @_;
12127: if (($path ne '') && (-d $path)) {
12128: if (opendir(my $dirh,$path)) {
12129: my @dircontents = grep(!/^\./,readdir($dirh));
12130: my $numitems = 0;
12131: foreach my $item (@dircontents) {
12132: if (-d "$path/$item") {
1.1111 raeburn 12133: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12134: if (-e "$path/$item") {
12135: $numitems ++;
12136: }
12137: } else {
12138: $numitems ++;
12139: }
12140: }
12141: if ($numitems == 0) {
12142: rmdir($path);
12143: }
12144: closedir($dirh);
12145: }
12146: }
12147: return;
12148: }
12149:
1.41 ng 12150: =pod
1.45 matthew 12151:
1.1162 raeburn 12152: =item * &get_folder_hierarchy()
1.1068 raeburn 12153:
12154: Provides hierarchy of names of folders/sub-folders containing the current
12155: item,
12156:
12157: Inputs: 3
12158: - $navmap - navmaps object
12159:
12160: - $map - url for map (either the trigger itself, or map containing
12161: the resource, which is the trigger).
12162:
12163: - $showitem - 1 => show title for map itself; 0 => do not show.
12164:
12165: Outputs: 1 @pathitems - array of folder/subfolder names.
12166:
12167: =cut
12168:
12169: sub get_folder_hierarchy {
12170: my ($navmap,$map,$showitem) = @_;
12171: my @pathitems;
12172: if (ref($navmap)) {
12173: my $mapres = $navmap->getResourceByUrl($map);
12174: if (ref($mapres)) {
12175: my $pcslist = $mapres->map_hierarchy();
12176: if ($pcslist ne '') {
12177: my @pcs = split(/,/,$pcslist);
12178: foreach my $pc (@pcs) {
12179: if ($pc == 1) {
1.1129 raeburn 12180: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12181: } else {
12182: my $res = $navmap->getByMapPc($pc);
12183: if (ref($res)) {
12184: my $title = $res->compTitle();
12185: $title =~ s/\W+/_/g;
12186: if ($title ne '') {
12187: push(@pathitems,$title);
12188: }
12189: }
12190: }
12191: }
12192: }
1.1071 raeburn 12193: if ($showitem) {
12194: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 12195: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12196: } else {
12197: my $maptitle = $mapres->compTitle();
12198: $maptitle =~ s/\W+/_/g;
12199: if ($maptitle ne '') {
12200: push(@pathitems,$maptitle);
12201: }
1.1068 raeburn 12202: }
12203: }
12204: }
12205: }
12206: return @pathitems;
12207: }
12208:
12209: =pod
12210:
1.1015 raeburn 12211: =item * &get_turnedin_filepath()
12212:
12213: Determines path in a user's portfolio file for storage of files uploaded
12214: to a specific essayresponse or dropbox item.
12215:
12216: Inputs: 3 required + 1 optional.
12217: $symb is symb for resource, $uname and $udom are for current user (required).
12218: $caller is optional (can be "submission", if routine is called when storing
12219: an upoaded file when "Submit Answer" button was pressed).
12220:
12221: Returns array containing $path and $multiresp.
12222: $path is path in portfolio. $multiresp is 1 if this resource contains more
12223: than one file upload item. Callers of routine should append partid as a
12224: subdirectory to $path in cases where $multiresp is 1.
12225:
12226: Called by: homework/essayresponse.pm and homework/structuretags.pm
12227:
12228: =cut
12229:
12230: sub get_turnedin_filepath {
12231: my ($symb,$uname,$udom,$caller) = @_;
12232: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12233: my $turnindir;
12234: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12235: $turnindir = $userhash{'turnindir'};
12236: my ($path,$multiresp);
12237: if ($turnindir eq '') {
12238: if ($caller eq 'submission') {
12239: $turnindir = &mt('turned in');
12240: $turnindir =~ s/\W+/_/g;
12241: my %newhash = (
12242: 'turnindir' => $turnindir,
12243: );
12244: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12245: }
12246: }
12247: if ($turnindir ne '') {
12248: $path = '/'.$turnindir.'/';
12249: my ($multipart,$turnin,@pathitems);
12250: my $navmap = Apache::lonnavmaps::navmap->new();
12251: if (defined($navmap)) {
12252: my $mapres = $navmap->getResourceByUrl($map);
12253: if (ref($mapres)) {
12254: my $pcslist = $mapres->map_hierarchy();
12255: if ($pcslist ne '') {
12256: foreach my $pc (split(/,/,$pcslist)) {
12257: my $res = $navmap->getByMapPc($pc);
12258: if (ref($res)) {
12259: my $title = $res->compTitle();
12260: $title =~ s/\W+/_/g;
12261: if ($title ne '') {
1.1149 raeburn 12262: if (($pc > 1) && (length($title) > 12)) {
12263: $title = substr($title,0,12);
12264: }
1.1015 raeburn 12265: push(@pathitems,$title);
12266: }
12267: }
12268: }
12269: }
12270: my $maptitle = $mapres->compTitle();
12271: $maptitle =~ s/\W+/_/g;
12272: if ($maptitle ne '') {
1.1149 raeburn 12273: if (length($maptitle) > 12) {
12274: $maptitle = substr($maptitle,0,12);
12275: }
1.1015 raeburn 12276: push(@pathitems,$maptitle);
12277: }
12278: unless ($env{'request.state'} eq 'construct') {
12279: my $res = $navmap->getBySymb($symb);
12280: if (ref($res)) {
12281: my $partlist = $res->parts();
12282: my $totaluploads = 0;
12283: if (ref($partlist) eq 'ARRAY') {
12284: foreach my $part (@{$partlist}) {
12285: my @types = $res->responseType($part);
12286: my @ids = $res->responseIds($part);
12287: for (my $i=0; $i < scalar(@ids); $i++) {
12288: if ($types[$i] eq 'essay') {
12289: my $partid = $part.'_'.$ids[$i];
12290: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12291: $totaluploads ++;
12292: }
12293: }
12294: }
12295: }
12296: if ($totaluploads > 1) {
12297: $multiresp = 1;
12298: }
12299: }
12300: }
12301: }
12302: } else {
12303: return;
12304: }
12305: } else {
12306: return;
12307: }
12308: my $restitle=&Apache::lonnet::gettitle($symb);
12309: $restitle =~ s/\W+/_/g;
12310: if ($restitle eq '') {
12311: $restitle = ($resurl =~ m{/[^/]+$});
12312: if ($restitle eq '') {
12313: $restitle = time;
12314: }
12315: }
1.1149 raeburn 12316: if (length($restitle) > 12) {
12317: $restitle = substr($restitle,0,12);
12318: }
1.1015 raeburn 12319: push(@pathitems,$restitle);
12320: $path .= join('/',@pathitems);
12321: }
12322: return ($path,$multiresp);
12323: }
12324:
12325: =pod
12326:
1.464 albertel 12327: =back
1.41 ng 12328:
1.112 bowersj2 12329: =head1 CSV Upload/Handling functions
1.38 albertel 12330:
1.41 ng 12331: =over 4
12332:
1.648 raeburn 12333: =item * &upfile_store($r)
1.41 ng 12334:
12335: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12336: needs $env{'form.upfile'}
1.41 ng 12337: returns $datatoken to be put into hidden field
12338:
12339: =cut
1.31 albertel 12340:
12341: sub upfile_store {
12342: my $r=shift;
1.258 albertel 12343: $env{'form.upfile'}=~s/\r/\n/gs;
12344: $env{'form.upfile'}=~s/\f/\n/gs;
12345: $env{'form.upfile'}=~s/\n+/\n/gs;
12346: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12347:
1.258 albertel 12348: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12349: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12350: {
1.158 raeburn 12351: my $datafile = $r->dir_config('lonDaemons').
12352: '/tmp/'.$datatoken.'.tmp';
12353: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12354: print $fh $env{'form.upfile'};
1.158 raeburn 12355: close($fh);
12356: }
1.31 albertel 12357: }
12358: return $datatoken;
12359: }
12360:
1.56 matthew 12361: =pod
12362:
1.648 raeburn 12363: =item * &load_tmp_file($r)
1.41 ng 12364:
12365: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12366: needs $env{'form.datatoken'},
12367: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12368:
12369: =cut
1.31 albertel 12370:
12371: sub load_tmp_file {
12372: my $r=shift;
12373: my @studentdata=();
12374: {
1.158 raeburn 12375: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12376: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12377: if ( open(my $fh,"<$studentfile") ) {
12378: @studentdata=<$fh>;
12379: close($fh);
12380: }
1.31 albertel 12381: }
1.258 albertel 12382: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12383: }
12384:
1.56 matthew 12385: =pod
12386:
1.648 raeburn 12387: =item * &upfile_record_sep()
1.41 ng 12388:
12389: Separate uploaded file into records
12390: returns array of records,
1.258 albertel 12391: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12392:
12393: =cut
1.31 albertel 12394:
12395: sub upfile_record_sep {
1.258 albertel 12396: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12397: } else {
1.248 albertel 12398: my @records;
1.258 albertel 12399: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12400: if ($line=~/^\s*$/) { next; }
12401: push(@records,$line);
12402: }
12403: return @records;
1.31 albertel 12404: }
12405: }
12406:
1.56 matthew 12407: =pod
12408:
1.648 raeburn 12409: =item * &record_sep($record)
1.41 ng 12410:
1.258 albertel 12411: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12412:
12413: =cut
12414:
1.263 www 12415: sub takeleft {
12416: my $index=shift;
12417: return substr('0000'.$index,-4,4);
12418: }
12419:
1.31 albertel 12420: sub record_sep {
12421: my $record=shift;
12422: my %components=();
1.258 albertel 12423: if ($env{'form.upfiletype'} eq 'xml') {
12424: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12425: my $i=0;
1.356 albertel 12426: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12427: $field=~s/^(\"|\')//;
12428: $field=~s/(\"|\')$//;
1.263 www 12429: $components{&takeleft($i)}=$field;
1.31 albertel 12430: $i++;
12431: }
1.258 albertel 12432: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12433: my $i=0;
1.356 albertel 12434: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12435: $field=~s/^(\"|\')//;
12436: $field=~s/(\"|\')$//;
1.263 www 12437: $components{&takeleft($i)}=$field;
1.31 albertel 12438: $i++;
12439: }
12440: } else {
1.561 www 12441: my $separator=',';
1.480 banghart 12442: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12443: $separator=';';
1.480 banghart 12444: }
1.31 albertel 12445: my $i=0;
1.561 www 12446: # the character we are looking for to indicate the end of a quote or a record
12447: my $looking_for=$separator;
12448: # do not add the characters to the fields
12449: my $ignore=0;
12450: # we just encountered a separator (or the beginning of the record)
12451: my $just_found_separator=1;
12452: # store the field we are working on here
12453: my $field='';
12454: # work our way through all characters in record
12455: foreach my $character ($record=~/(.)/g) {
12456: if ($character eq $looking_for) {
12457: if ($character ne $separator) {
12458: # Found the end of a quote, again looking for separator
12459: $looking_for=$separator;
12460: $ignore=1;
12461: } else {
12462: # Found a separator, store away what we got
12463: $components{&takeleft($i)}=$field;
12464: $i++;
12465: $just_found_separator=1;
12466: $ignore=0;
12467: $field='';
12468: }
12469: next;
12470: }
12471: # single or double quotation marks after a separator indicate beginning of a quote
12472: # we are now looking for the end of the quote and need to ignore separators
12473: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12474: $looking_for=$character;
12475: next;
12476: }
12477: # ignore would be true after we reached the end of a quote
12478: if ($ignore) { next; }
12479: if (($just_found_separator) && ($character=~/\s/)) { next; }
12480: $field.=$character;
12481: $just_found_separator=0;
1.31 albertel 12482: }
1.561 www 12483: # catch the very last entry, since we never encountered the separator
12484: $components{&takeleft($i)}=$field;
1.31 albertel 12485: }
12486: return %components;
12487: }
12488:
1.144 matthew 12489: ######################################################
12490: ######################################################
12491:
1.56 matthew 12492: =pod
12493:
1.648 raeburn 12494: =item * &upfile_select_html()
1.41 ng 12495:
1.144 matthew 12496: Return HTML code to select a file from the users machine and specify
12497: the file type.
1.41 ng 12498:
12499: =cut
12500:
1.144 matthew 12501: ######################################################
12502: ######################################################
1.31 albertel 12503: sub upfile_select_html {
1.144 matthew 12504: my %Types = (
12505: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12506: semisv => &mt('Semicolon separated values'),
1.144 matthew 12507: space => &mt('Space separated'),
12508: tab => &mt('Tabulator separated'),
12509: # xml => &mt('HTML/XML'),
12510: );
12511: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12512: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12513: foreach my $type (sort(keys(%Types))) {
12514: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12515: }
12516: $Str .= "</select>\n";
12517: return $Str;
1.31 albertel 12518: }
12519:
1.301 albertel 12520: sub get_samples {
12521: my ($records,$toget) = @_;
12522: my @samples=({});
12523: my $got=0;
12524: foreach my $rec (@$records) {
12525: my %temp = &record_sep($rec);
12526: if (! grep(/\S/, values(%temp))) { next; }
12527: if (%temp) {
12528: $samples[$got]=\%temp;
12529: $got++;
12530: if ($got == $toget) { last; }
12531: }
12532: }
12533: return \@samples;
12534: }
12535:
1.144 matthew 12536: ######################################################
12537: ######################################################
12538:
1.56 matthew 12539: =pod
12540:
1.648 raeburn 12541: =item * &csv_print_samples($r,$records)
1.41 ng 12542:
12543: Prints a table of sample values from each column uploaded $r is an
12544: Apache Request ref, $records is an arrayref from
12545: &Apache::loncommon::upfile_record_sep
12546:
12547: =cut
12548:
1.144 matthew 12549: ######################################################
12550: ######################################################
1.31 albertel 12551: sub csv_print_samples {
12552: my ($r,$records) = @_;
1.662 bisitz 12553: my $samples = &get_samples($records,5);
1.301 albertel 12554:
1.594 raeburn 12555: $r->print(&mt('Samples').'<br />'.&start_data_table().
12556: &start_data_table_header_row());
1.356 albertel 12557: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12558: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12559: $r->print(&end_data_table_header_row());
1.301 albertel 12560: foreach my $hash (@$samples) {
1.594 raeburn 12561: $r->print(&start_data_table_row());
1.356 albertel 12562: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12563: $r->print('<td>');
1.356 albertel 12564: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12565: $r->print('</td>');
12566: }
1.594 raeburn 12567: $r->print(&end_data_table_row());
1.31 albertel 12568: }
1.594 raeburn 12569: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12570: }
12571:
1.144 matthew 12572: ######################################################
12573: ######################################################
12574:
1.56 matthew 12575: =pod
12576:
1.648 raeburn 12577: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12578:
12579: Prints a table to create associations between values and table columns.
1.144 matthew 12580:
1.41 ng 12581: $r is an Apache Request ref,
12582: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12583: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12584:
12585: =cut
12586:
1.144 matthew 12587: ######################################################
12588: ######################################################
1.31 albertel 12589: sub csv_print_select_table {
12590: my ($r,$records,$d) = @_;
1.301 albertel 12591: my $i=0;
12592: my $samples = &get_samples($records,1);
1.144 matthew 12593: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12594: &start_data_table().&start_data_table_header_row().
1.144 matthew 12595: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12596: '<th>'.&mt('Column').'</th>'.
12597: &end_data_table_header_row()."\n");
1.356 albertel 12598: foreach my $array_ref (@$d) {
12599: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12600: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12601:
1.875 bisitz 12602: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12603: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12604: $r->print('<option value="none"></option>');
1.356 albertel 12605: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12606: $r->print('<option value="'.$sample.'"'.
12607: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12608: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12609: }
1.594 raeburn 12610: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12611: $i++;
12612: }
1.594 raeburn 12613: $r->print(&end_data_table());
1.31 albertel 12614: $i--;
12615: return $i;
12616: }
1.56 matthew 12617:
1.144 matthew 12618: ######################################################
12619: ######################################################
12620:
1.56 matthew 12621: =pod
1.31 albertel 12622:
1.648 raeburn 12623: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12624:
12625: Prints a table of sample values from the upload and can make associate samples to internal names.
12626:
12627: $r is an Apache Request ref,
12628: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12629: $d is an array of 2 element arrays (internal name, displayed name)
12630:
12631: =cut
12632:
1.144 matthew 12633: ######################################################
12634: ######################################################
1.31 albertel 12635: sub csv_samples_select_table {
12636: my ($r,$records,$d) = @_;
12637: my $i=0;
1.144 matthew 12638: #
1.662 bisitz 12639: my $max_samples = 5;
12640: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12641: $r->print(&start_data_table().
12642: &start_data_table_header_row().'<th>'.
12643: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12644: &end_data_table_header_row());
1.301 albertel 12645:
12646: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12647: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12648: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12649: foreach my $option (@$d) {
12650: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12651: $r->print('<option value="'.$value.'"'.
1.253 albertel 12652: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12653: $display.'</option>');
1.31 albertel 12654: }
12655: $r->print('</select></td><td>');
1.662 bisitz 12656: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12657: if (defined($samples->[$line]{$key})) {
12658: $r->print($samples->[$line]{$key}."<br />\n");
12659: }
12660: }
1.594 raeburn 12661: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12662: $i++;
12663: }
1.594 raeburn 12664: $r->print(&end_data_table());
1.31 albertel 12665: $i--;
12666: return($i);
1.115 matthew 12667: }
12668:
1.144 matthew 12669: ######################################################
12670: ######################################################
12671:
1.115 matthew 12672: =pod
12673:
1.648 raeburn 12674: =item * &clean_excel_name($name)
1.115 matthew 12675:
12676: Returns a replacement for $name which does not contain any illegal characters.
12677:
12678: =cut
12679:
1.144 matthew 12680: ######################################################
12681: ######################################################
1.115 matthew 12682: sub clean_excel_name {
12683: my ($name) = @_;
12684: $name =~ s/[:\*\?\/\\]//g;
12685: if (length($name) > 31) {
12686: $name = substr($name,0,31);
12687: }
12688: return $name;
1.25 albertel 12689: }
1.84 albertel 12690:
1.85 albertel 12691: =pod
12692:
1.648 raeburn 12693: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12694:
12695: Returns either 1 or undef
12696:
12697: 1 if the part is to be hidden, undef if it is to be shown
12698:
12699: Arguments are:
12700:
12701: $id the id of the part to be checked
12702: $symb, optional the symb of the resource to check
12703: $udom, optional the domain of the user to check for
12704: $uname, optional the username of the user to check for
12705:
12706: =cut
1.84 albertel 12707:
12708: sub check_if_partid_hidden {
12709: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12710: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12711: $symb,$udom,$uname);
1.141 albertel 12712: my $truth=1;
12713: #if the string starts with !, then the list is the list to show not hide
12714: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12715: my @hiddenlist=split(/,/,$hiddenparts);
12716: foreach my $checkid (@hiddenlist) {
1.141 albertel 12717: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12718: }
1.141 albertel 12719: return !$truth;
1.84 albertel 12720: }
1.127 matthew 12721:
1.138 matthew 12722:
12723: ############################################################
12724: ############################################################
12725:
12726: =pod
12727:
1.157 matthew 12728: =back
12729:
1.138 matthew 12730: =head1 cgi-bin script and graphing routines
12731:
1.157 matthew 12732: =over 4
12733:
1.648 raeburn 12734: =item * &get_cgi_id()
1.138 matthew 12735:
12736: Inputs: none
12737:
12738: Returns an id which can be used to pass environment variables
12739: to various cgi-bin scripts. These environment variables will
12740: be removed from the users environment after a given time by
12741: the routine &Apache::lonnet::transfer_profile_to_env.
12742:
12743: =cut
12744:
12745: ############################################################
12746: ############################################################
1.152 albertel 12747: my $uniq=0;
1.136 matthew 12748: sub get_cgi_id {
1.154 albertel 12749: $uniq=($uniq+1)%100000;
1.280 albertel 12750: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12751: }
12752:
1.127 matthew 12753: ############################################################
12754: ############################################################
12755:
12756: =pod
12757:
1.648 raeburn 12758: =item * &DrawBarGraph()
1.127 matthew 12759:
1.138 matthew 12760: Facilitates the plotting of data in a (stacked) bar graph.
12761: Puts plot definition data into the users environment in order for
12762: graph.png to plot it. Returns an <img> tag for the plot.
12763: The bars on the plot are labeled '1','2',...,'n'.
12764:
12765: Inputs:
12766:
12767: =over 4
12768:
12769: =item $Title: string, the title of the plot
12770:
12771: =item $xlabel: string, text describing the X-axis of the plot
12772:
12773: =item $ylabel: string, text describing the Y-axis of the plot
12774:
12775: =item $Max: scalar, the maximum Y value to use in the plot
12776: If $Max is < any data point, the graph will not be rendered.
12777:
1.140 matthew 12778: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12779: they are plotted. If undefined, default values will be used.
12780:
1.178 matthew 12781: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12782:
1.138 matthew 12783: =item @Values: An array of array references. Each array reference holds data
12784: to be plotted in a stacked bar chart.
12785:
1.239 matthew 12786: =item If the final element of @Values is a hash reference the key/value
12787: pairs will be added to the graph definition.
12788:
1.138 matthew 12789: =back
12790:
12791: Returns:
12792:
12793: An <img> tag which references graph.png and the appropriate identifying
12794: information for the plot.
12795:
1.127 matthew 12796: =cut
12797:
12798: ############################################################
12799: ############################################################
1.134 matthew 12800: sub DrawBarGraph {
1.178 matthew 12801: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12802: #
12803: if (! defined($colors)) {
12804: $colors = ['#33ff00',
12805: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12806: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12807: ];
12808: }
1.228 matthew 12809: my $extra_settings = {};
12810: if (ref($Values[-1]) eq 'HASH') {
12811: $extra_settings = pop(@Values);
12812: }
1.127 matthew 12813: #
1.136 matthew 12814: my $identifier = &get_cgi_id();
12815: my $id = 'cgi.'.$identifier;
1.129 matthew 12816: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12817: return '';
12818: }
1.225 matthew 12819: #
12820: my @Labels;
12821: if (defined($labels)) {
12822: @Labels = @$labels;
12823: } else {
12824: for (my $i=0;$i<@{$Values[0]};$i++) {
12825: push (@Labels,$i+1);
12826: }
12827: }
12828: #
1.129 matthew 12829: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12830: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12831: my %ValuesHash;
12832: my $NumSets=1;
12833: foreach my $array (@Values) {
12834: next if (! ref($array));
1.136 matthew 12835: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12836: join(',',@$array);
1.129 matthew 12837: }
1.127 matthew 12838: #
1.136 matthew 12839: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12840: if ($NumBars < 3) {
12841: $width = 120+$NumBars*32;
1.220 matthew 12842: $xskip = 1;
1.225 matthew 12843: $bar_width = 30;
12844: } elsif ($NumBars < 5) {
12845: $width = 120+$NumBars*20;
12846: $xskip = 1;
12847: $bar_width = 20;
1.220 matthew 12848: } elsif ($NumBars < 10) {
1.136 matthew 12849: $width = 120+$NumBars*15;
12850: $xskip = 1;
12851: $bar_width = 15;
12852: } elsif ($NumBars <= 25) {
12853: $width = 120+$NumBars*11;
12854: $xskip = 5;
12855: $bar_width = 8;
12856: } elsif ($NumBars <= 50) {
12857: $width = 120+$NumBars*8;
12858: $xskip = 5;
12859: $bar_width = 4;
12860: } else {
12861: $width = 120+$NumBars*8;
12862: $xskip = 5;
12863: $bar_width = 4;
12864: }
12865: #
1.137 matthew 12866: $Max = 1 if ($Max < 1);
12867: if ( int($Max) < $Max ) {
12868: $Max++;
12869: $Max = int($Max);
12870: }
1.127 matthew 12871: $Title = '' if (! defined($Title));
12872: $xlabel = '' if (! defined($xlabel));
12873: $ylabel = '' if (! defined($ylabel));
1.369 www 12874: $ValuesHash{$id.'.title'} = &escape($Title);
12875: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12876: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12877: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12878: $ValuesHash{$id.'.NumBars'} = $NumBars;
12879: $ValuesHash{$id.'.NumSets'} = $NumSets;
12880: $ValuesHash{$id.'.PlotType'} = 'bar';
12881: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12882: $ValuesHash{$id.'.height'} = $height;
12883: $ValuesHash{$id.'.width'} = $width;
12884: $ValuesHash{$id.'.xskip'} = $xskip;
12885: $ValuesHash{$id.'.bar_width'} = $bar_width;
12886: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12887: #
1.228 matthew 12888: # Deal with other parameters
12889: while (my ($key,$value) = each(%$extra_settings)) {
12890: $ValuesHash{$id.'.'.$key} = $value;
12891: }
12892: #
1.646 raeburn 12893: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12894: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12895: }
12896:
12897: ############################################################
12898: ############################################################
12899:
12900: =pod
12901:
1.648 raeburn 12902: =item * &DrawXYGraph()
1.137 matthew 12903:
1.138 matthew 12904: Facilitates the plotting of data in an XY graph.
12905: Puts plot definition data into the users environment in order for
12906: graph.png to plot it. Returns an <img> tag for the plot.
12907:
12908: Inputs:
12909:
12910: =over 4
12911:
12912: =item $Title: string, the title of the plot
12913:
12914: =item $xlabel: string, text describing the X-axis of the plot
12915:
12916: =item $ylabel: string, text describing the Y-axis of the plot
12917:
12918: =item $Max: scalar, the maximum Y value to use in the plot
12919: If $Max is < any data point, the graph will not be rendered.
12920:
12921: =item $colors: Array ref containing the hex color codes for the data to be
12922: plotted in. If undefined, default values will be used.
12923:
12924: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12925:
12926: =item $Ydata: Array ref containing Array refs.
1.185 www 12927: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12928:
12929: =item %Values: hash indicating or overriding any default values which are
12930: passed to graph.png.
12931: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12932:
12933: =back
12934:
12935: Returns:
12936:
12937: An <img> tag which references graph.png and the appropriate identifying
12938: information for the plot.
12939:
1.137 matthew 12940: =cut
12941:
12942: ############################################################
12943: ############################################################
12944: sub DrawXYGraph {
12945: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12946: #
12947: # Create the identifier for the graph
12948: my $identifier = &get_cgi_id();
12949: my $id = 'cgi.'.$identifier;
12950: #
12951: $Title = '' if (! defined($Title));
12952: $xlabel = '' if (! defined($xlabel));
12953: $ylabel = '' if (! defined($ylabel));
12954: my %ValuesHash =
12955: (
1.369 www 12956: $id.'.title' => &escape($Title),
12957: $id.'.xlabel' => &escape($xlabel),
12958: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12959: $id.'.y_max_value'=> $Max,
12960: $id.'.labels' => join(',',@$Xlabels),
12961: $id.'.PlotType' => 'XY',
12962: );
12963: #
12964: if (defined($colors) && ref($colors) eq 'ARRAY') {
12965: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12966: }
12967: #
12968: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12969: return '';
12970: }
12971: my $NumSets=1;
1.138 matthew 12972: foreach my $array (@{$Ydata}){
1.137 matthew 12973: next if (! ref($array));
12974: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12975: }
1.138 matthew 12976: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12977: #
12978: # Deal with other parameters
12979: while (my ($key,$value) = each(%Values)) {
12980: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12981: }
12982: #
1.646 raeburn 12983: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12984: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12985: }
12986:
12987: ############################################################
12988: ############################################################
12989:
12990: =pod
12991:
1.648 raeburn 12992: =item * &DrawXYYGraph()
1.138 matthew 12993:
12994: Facilitates the plotting of data in an XY graph with two Y axes.
12995: Puts plot definition data into the users environment in order for
12996: graph.png to plot it. Returns an <img> tag for the plot.
12997:
12998: Inputs:
12999:
13000: =over 4
13001:
13002: =item $Title: string, the title of the plot
13003:
13004: =item $xlabel: string, text describing the X-axis of the plot
13005:
13006: =item $ylabel: string, text describing the Y-axis of the plot
13007:
13008: =item $colors: Array ref containing the hex color codes for the data to be
13009: plotted in. If undefined, default values will be used.
13010:
13011: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13012:
13013: =item $Ydata1: The first data set
13014:
13015: =item $Min1: The minimum value of the left Y-axis
13016:
13017: =item $Max1: The maximum value of the left Y-axis
13018:
13019: =item $Ydata2: The second data set
13020:
13021: =item $Min2: The minimum value of the right Y-axis
13022:
13023: =item $Max2: The maximum value of the left Y-axis
13024:
13025: =item %Values: hash indicating or overriding any default values which are
13026: passed to graph.png.
13027: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13028:
13029: =back
13030:
13031: Returns:
13032:
13033: An <img> tag which references graph.png and the appropriate identifying
13034: information for the plot.
1.136 matthew 13035:
13036: =cut
13037:
13038: ############################################################
13039: ############################################################
1.137 matthew 13040: sub DrawXYYGraph {
13041: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13042: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13043: #
13044: # Create the identifier for the graph
13045: my $identifier = &get_cgi_id();
13046: my $id = 'cgi.'.$identifier;
13047: #
13048: $Title = '' if (! defined($Title));
13049: $xlabel = '' if (! defined($xlabel));
13050: $ylabel = '' if (! defined($ylabel));
13051: my %ValuesHash =
13052: (
1.369 www 13053: $id.'.title' => &escape($Title),
13054: $id.'.xlabel' => &escape($xlabel),
13055: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13056: $id.'.labels' => join(',',@$Xlabels),
13057: $id.'.PlotType' => 'XY',
13058: $id.'.NumSets' => 2,
1.137 matthew 13059: $id.'.two_axes' => 1,
13060: $id.'.y1_max_value' => $Max1,
13061: $id.'.y1_min_value' => $Min1,
13062: $id.'.y2_max_value' => $Max2,
13063: $id.'.y2_min_value' => $Min2,
1.136 matthew 13064: );
13065: #
1.137 matthew 13066: if (defined($colors) && ref($colors) eq 'ARRAY') {
13067: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13068: }
13069: #
13070: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13071: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13072: return '';
13073: }
13074: my $NumSets=1;
1.137 matthew 13075: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13076: next if (! ref($array));
13077: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13078: }
13079: #
13080: # Deal with other parameters
13081: while (my ($key,$value) = each(%Values)) {
13082: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13083: }
13084: #
1.646 raeburn 13085: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13086: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13087: }
13088:
13089: ############################################################
13090: ############################################################
13091:
13092: =pod
13093:
1.157 matthew 13094: =back
13095:
1.139 matthew 13096: =head1 Statistics helper routines?
13097:
13098: Bad place for them but what the hell.
13099:
1.157 matthew 13100: =over 4
13101:
1.648 raeburn 13102: =item * &chartlink()
1.139 matthew 13103:
13104: Returns a link to the chart for a specific student.
13105:
13106: Inputs:
13107:
13108: =over 4
13109:
13110: =item $linktext: The text of the link
13111:
13112: =item $sname: The students username
13113:
13114: =item $sdomain: The students domain
13115:
13116: =back
13117:
1.157 matthew 13118: =back
13119:
1.139 matthew 13120: =cut
13121:
13122: ############################################################
13123: ############################################################
13124: sub chartlink {
13125: my ($linktext, $sname, $sdomain) = @_;
13126: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13127: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13128: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13129: '">'.$linktext.'</a>';
1.153 matthew 13130: }
13131:
13132: #######################################################
13133: #######################################################
13134:
13135: =pod
13136:
13137: =head1 Course Environment Routines
1.157 matthew 13138:
13139: =over 4
1.153 matthew 13140:
1.648 raeburn 13141: =item * &restore_course_settings()
1.153 matthew 13142:
1.648 raeburn 13143: =item * &store_course_settings()
1.153 matthew 13144:
13145: Restores/Store indicated form parameters from the course environment.
13146: Will not overwrite existing values of the form parameters.
13147:
13148: Inputs:
13149: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13150:
13151: a hash ref describing the data to be stored. For example:
13152:
13153: %Save_Parameters = ('Status' => 'scalar',
13154: 'chartoutputmode' => 'scalar',
13155: 'chartoutputdata' => 'scalar',
13156: 'Section' => 'array',
1.373 raeburn 13157: 'Group' => 'array',
1.153 matthew 13158: 'StudentData' => 'array',
13159: 'Maps' => 'array');
13160:
13161: Returns: both routines return nothing
13162:
1.631 raeburn 13163: =back
13164:
1.153 matthew 13165: =cut
13166:
13167: #######################################################
13168: #######################################################
13169: sub store_course_settings {
1.496 albertel 13170: return &store_settings($env{'request.course.id'},@_);
13171: }
13172:
13173: sub store_settings {
1.153 matthew 13174: # save to the environment
13175: # appenv the same items, just to be safe
1.300 albertel 13176: my $udom = $env{'user.domain'};
13177: my $uname = $env{'user.name'};
1.496 albertel 13178: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13179: my %SaveHash;
13180: my %AppHash;
13181: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13182: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13183: my $envname = 'environment.'.$basename;
1.258 albertel 13184: if (exists($env{'form.'.$setting})) {
1.153 matthew 13185: # Save this value away
13186: if ($type eq 'scalar' &&
1.258 albertel 13187: (! exists($env{$envname}) ||
13188: $env{$envname} ne $env{'form.'.$setting})) {
13189: $SaveHash{$basename} = $env{'form.'.$setting};
13190: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13191: } elsif ($type eq 'array') {
13192: my $stored_form;
1.258 albertel 13193: if (ref($env{'form.'.$setting})) {
1.153 matthew 13194: $stored_form = join(',',
13195: map {
1.369 www 13196: &escape($_);
1.258 albertel 13197: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13198: } else {
13199: $stored_form =
1.369 www 13200: &escape($env{'form.'.$setting});
1.153 matthew 13201: }
13202: # Determine if the array contents are the same.
1.258 albertel 13203: if ($stored_form ne $env{$envname}) {
1.153 matthew 13204: $SaveHash{$basename} = $stored_form;
13205: $AppHash{$envname} = $stored_form;
13206: }
13207: }
13208: }
13209: }
13210: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13211: $udom,$uname);
1.153 matthew 13212: if ($put_result !~ /^(ok|delayed)/) {
13213: &Apache::lonnet::logthis('unable to save form parameters, '.
13214: 'got error:'.$put_result);
13215: }
13216: # Make sure these settings stick around in this session, too
1.646 raeburn 13217: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13218: return;
13219: }
13220:
13221: sub restore_course_settings {
1.499 albertel 13222: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13223: }
13224:
13225: sub restore_settings {
13226: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13227: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13228: next if (exists($env{'form.'.$setting}));
1.496 albertel 13229: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13230: '.'.$setting;
1.258 albertel 13231: if (exists($env{$envname})) {
1.153 matthew 13232: if ($type eq 'scalar') {
1.258 albertel 13233: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13234: } elsif ($type eq 'array') {
1.258 albertel 13235: $env{'form.'.$setting} = [
1.153 matthew 13236: map {
1.369 www 13237: &unescape($_);
1.258 albertel 13238: } split(',',$env{$envname})
1.153 matthew 13239: ];
13240: }
13241: }
13242: }
1.127 matthew 13243: }
13244:
1.618 raeburn 13245: #######################################################
13246: #######################################################
13247:
13248: =pod
13249:
13250: =head1 Domain E-mail Routines
13251:
13252: =over 4
13253:
1.648 raeburn 13254: =item * &build_recipient_list()
1.618 raeburn 13255:
1.1144 raeburn 13256: Build recipient lists for following types of e-mail:
1.766 raeburn 13257: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 13258: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13259: module change checking, student/employee ID conflict checks, as
13260: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13261: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13262:
13263: Inputs:
1.619 raeburn 13264: defmail (scalar - email address of default recipient),
1.1144 raeburn 13265: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13266: requestsmail, updatesmail, or idconflictsmail).
13267:
1.619 raeburn 13268: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 13269:
1.619 raeburn 13270: origmail (scalar - email address of recipient from loncapa.conf,
13271: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13272:
1.655 raeburn 13273: Returns: comma separated list of addresses to which to send e-mail.
13274:
13275: =back
1.618 raeburn 13276:
13277: =cut
13278:
13279: ############################################################
13280: ############################################################
13281: sub build_recipient_list {
1.619 raeburn 13282: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13283: my @recipients;
13284: my $otheremails;
13285: my %domconfig =
13286: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13287: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13288: if (exists($domconfig{'contacts'}{$mailing})) {
13289: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13290: my @contacts = ('adminemail','supportemail');
13291: foreach my $item (@contacts) {
13292: if ($domconfig{'contacts'}{$mailing}{$item}) {
13293: my $addr = $domconfig{'contacts'}{$item};
13294: if (!grep(/^\Q$addr\E$/,@recipients)) {
13295: push(@recipients,$addr);
13296: }
1.619 raeburn 13297: }
1.766 raeburn 13298: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13299: }
13300: }
1.766 raeburn 13301: } elsif ($origmail ne '') {
13302: push(@recipients,$origmail);
1.618 raeburn 13303: }
1.619 raeburn 13304: } elsif ($origmail ne '') {
13305: push(@recipients,$origmail);
1.618 raeburn 13306: }
1.688 raeburn 13307: if (defined($defmail)) {
13308: if ($defmail ne '') {
13309: push(@recipients,$defmail);
13310: }
1.618 raeburn 13311: }
13312: if ($otheremails) {
1.619 raeburn 13313: my @others;
13314: if ($otheremails =~ /,/) {
13315: @others = split(/,/,$otheremails);
1.618 raeburn 13316: } else {
1.619 raeburn 13317: push(@others,$otheremails);
13318: }
13319: foreach my $addr (@others) {
13320: if (!grep(/^\Q$addr\E$/,@recipients)) {
13321: push(@recipients,$addr);
13322: }
1.618 raeburn 13323: }
13324: }
1.619 raeburn 13325: my $recipientlist = join(',',@recipients);
1.618 raeburn 13326: return $recipientlist;
13327: }
13328:
1.127 matthew 13329: ############################################################
13330: ############################################################
1.154 albertel 13331:
1.655 raeburn 13332: =pod
13333:
13334: =head1 Course Catalog Routines
13335:
13336: =over 4
13337:
13338: =item * &gather_categories()
13339:
13340: Converts category definitions - keys of categories hash stored in
13341: coursecategories in configuration.db on the primary library server in a
13342: domain - to an array. Also generates javascript and idx hash used to
13343: generate Domain Coordinator interface for editing Course Categories.
13344:
13345: Inputs:
1.663 raeburn 13346:
1.655 raeburn 13347: categories (reference to hash of category definitions).
1.663 raeburn 13348:
1.655 raeburn 13349: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13350: categories and subcategories).
1.663 raeburn 13351:
1.655 raeburn 13352: idx (reference to hash of counters used in Domain Coordinator interface for
13353: editing Course Categories).
1.663 raeburn 13354:
1.655 raeburn 13355: jsarray (reference to array of categories used to create Javascript arrays for
13356: Domain Coordinator interface for editing Course Categories).
13357:
13358: Returns: nothing
13359:
13360: Side effects: populates cats, idx and jsarray.
13361:
13362: =cut
13363:
13364: sub gather_categories {
13365: my ($categories,$cats,$idx,$jsarray) = @_;
13366: my %counters;
13367: my $num = 0;
13368: foreach my $item (keys(%{$categories})) {
13369: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13370: if ($container eq '' && $depth == 0) {
13371: $cats->[$depth][$categories->{$item}] = $cat;
13372: } else {
13373: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13374: }
13375: my ($escitem,$tail) = split(/:/,$item,2);
13376: if ($counters{$tail} eq '') {
13377: $counters{$tail} = $num;
13378: $num ++;
13379: }
13380: if (ref($idx) eq 'HASH') {
13381: $idx->{$item} = $counters{$tail};
13382: }
13383: if (ref($jsarray) eq 'ARRAY') {
13384: push(@{$jsarray->[$counters{$tail}]},$item);
13385: }
13386: }
13387: return;
13388: }
13389:
13390: =pod
13391:
13392: =item * &extract_categories()
13393:
13394: Used to generate breadcrumb trails for course categories.
13395:
13396: Inputs:
1.663 raeburn 13397:
1.655 raeburn 13398: categories (reference to hash of category definitions).
1.663 raeburn 13399:
1.655 raeburn 13400: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13401: categories and subcategories).
1.663 raeburn 13402:
1.655 raeburn 13403: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13404:
1.655 raeburn 13405: allitems (reference to hash - key is category key
13406: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13407:
1.655 raeburn 13408: idx (reference to hash of counters used in Domain Coordinator interface for
13409: editing Course Categories).
1.663 raeburn 13410:
1.655 raeburn 13411: jsarray (reference to array of categories used to create Javascript arrays for
13412: Domain Coordinator interface for editing Course Categories).
13413:
1.665 raeburn 13414: subcats (reference to hash of arrays containing all subcategories within each
13415: category, -recursive)
13416:
1.655 raeburn 13417: Returns: nothing
13418:
13419: Side effects: populates trails and allitems hash references.
13420:
13421: =cut
13422:
13423: sub extract_categories {
1.665 raeburn 13424: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13425: if (ref($categories) eq 'HASH') {
13426: &gather_categories($categories,$cats,$idx,$jsarray);
13427: if (ref($cats->[0]) eq 'ARRAY') {
13428: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13429: my $name = $cats->[0][$i];
13430: my $item = &escape($name).'::0';
13431: my $trailstr;
13432: if ($name eq 'instcode') {
13433: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13434: } elsif ($name eq 'communities') {
13435: $trailstr = &mt('Communities');
1.655 raeburn 13436: } else {
13437: $trailstr = $name;
13438: }
13439: if ($allitems->{$item} eq '') {
13440: push(@{$trails},$trailstr);
13441: $allitems->{$item} = scalar(@{$trails})-1;
13442: }
13443: my @parents = ($name);
13444: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13445: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13446: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13447: if (ref($subcats) eq 'HASH') {
13448: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13449: }
13450: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13451: }
13452: } else {
13453: if (ref($subcats) eq 'HASH') {
13454: $subcats->{$item} = [];
1.655 raeburn 13455: }
13456: }
13457: }
13458: }
13459: }
13460: return;
13461: }
13462:
13463: =pod
13464:
1.1162 raeburn 13465: =item * &recurse_categories()
1.655 raeburn 13466:
13467: Recursively used to generate breadcrumb trails for course categories.
13468:
13469: Inputs:
1.663 raeburn 13470:
1.655 raeburn 13471: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13472: categories and subcategories).
1.663 raeburn 13473:
1.655 raeburn 13474: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13475:
13476: category (current course category, for which breadcrumb trail is being generated).
13477:
13478: trails (reference to array of breadcrumb trails for each category).
13479:
1.655 raeburn 13480: allitems (reference to hash - key is category key
13481: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13482:
1.655 raeburn 13483: parents (array containing containers directories for current category,
13484: back to top level).
13485:
13486: Returns: nothing
13487:
13488: Side effects: populates trails and allitems hash references
13489:
13490: =cut
13491:
13492: sub recurse_categories {
1.665 raeburn 13493: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13494: my $shallower = $depth - 1;
13495: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13496: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13497: my $name = $cats->[$depth]{$category}[$k];
13498: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13499: my $trailstr = join(' -> ',(@{$parents},$category));
13500: if ($allitems->{$item} eq '') {
13501: push(@{$trails},$trailstr);
13502: $allitems->{$item} = scalar(@{$trails})-1;
13503: }
13504: my $deeper = $depth+1;
13505: push(@{$parents},$category);
1.665 raeburn 13506: if (ref($subcats) eq 'HASH') {
13507: my $subcat = &escape($name).':'.$category.':'.$depth;
13508: for (my $j=@{$parents}; $j>=0; $j--) {
13509: my $higher;
13510: if ($j > 0) {
13511: $higher = &escape($parents->[$j]).':'.
13512: &escape($parents->[$j-1]).':'.$j;
13513: } else {
13514: $higher = &escape($parents->[$j]).'::'.$j;
13515: }
13516: push(@{$subcats->{$higher}},$subcat);
13517: }
13518: }
13519: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13520: $subcats);
1.655 raeburn 13521: pop(@{$parents});
13522: }
13523: } else {
13524: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13525: my $trailstr = join(' -> ',(@{$parents},$category));
13526: if ($allitems->{$item} eq '') {
13527: push(@{$trails},$trailstr);
13528: $allitems->{$item} = scalar(@{$trails})-1;
13529: }
13530: }
13531: return;
13532: }
13533:
1.663 raeburn 13534: =pod
13535:
1.1162 raeburn 13536: =item * &assign_categories_table()
1.663 raeburn 13537:
13538: Create a datatable for display of hierarchical categories in a domain,
13539: with checkboxes to allow a course to be categorized.
13540:
13541: Inputs:
13542:
13543: cathash - reference to hash of categories defined for the domain (from
13544: configuration.db)
13545:
13546: currcat - scalar with an & separated list of categories assigned to a course.
13547:
1.919 raeburn 13548: type - scalar contains course type (Course or Community).
13549:
1.663 raeburn 13550: Returns: $output (markup to be displayed)
13551:
13552: =cut
13553:
13554: sub assign_categories_table {
1.919 raeburn 13555: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13556: my $output;
13557: if (ref($cathash) eq 'HASH') {
13558: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13559: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13560: $maxdepth = scalar(@cats);
13561: if (@cats > 0) {
13562: my $itemcount = 0;
13563: if (ref($cats[0]) eq 'ARRAY') {
13564: my @currcategories;
13565: if ($currcat ne '') {
13566: @currcategories = split('&',$currcat);
13567: }
1.919 raeburn 13568: my $table;
1.663 raeburn 13569: for (my $i=0; $i<@{$cats[0]}; $i++) {
13570: my $parent = $cats[0][$i];
1.919 raeburn 13571: next if ($parent eq 'instcode');
13572: if ($type eq 'Community') {
13573: next unless ($parent eq 'communities');
13574: } else {
13575: next if ($parent eq 'communities');
13576: }
1.663 raeburn 13577: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13578: my $item = &escape($parent).'::0';
13579: my $checked = '';
13580: if (@currcategories > 0) {
13581: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13582: $checked = ' checked="checked"';
1.663 raeburn 13583: }
13584: }
1.919 raeburn 13585: my $parent_title = $parent;
13586: if ($parent eq 'communities') {
13587: $parent_title = &mt('Communities');
13588: }
13589: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13590: '<input type="checkbox" name="usecategory" value="'.
13591: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13592: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13593: my $depth = 1;
13594: push(@path,$parent);
1.919 raeburn 13595: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13596: pop(@path);
1.919 raeburn 13597: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13598: $itemcount ++;
13599: }
1.919 raeburn 13600: if ($itemcount) {
13601: $output = &Apache::loncommon::start_data_table().
13602: $table.
13603: &Apache::loncommon::end_data_table();
13604: }
1.663 raeburn 13605: }
13606: }
13607: }
13608: return $output;
13609: }
13610:
13611: =pod
13612:
1.1162 raeburn 13613: =item * &assign_category_rows()
1.663 raeburn 13614:
13615: Create a datatable row for display of nested categories in a domain,
13616: with checkboxes to allow a course to be categorized,called recursively.
13617:
13618: Inputs:
13619:
13620: itemcount - track row number for alternating colors
13621:
13622: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13623: categories and subcategories.
13624:
13625: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13626:
13627: parent - parent of current category item
13628:
13629: path - Array containing all categories back up through the hierarchy from the
13630: current category to the top level.
13631:
13632: currcategories - reference to array of current categories assigned to the course
13633:
13634: Returns: $output (markup to be displayed).
13635:
13636: =cut
13637:
13638: sub assign_category_rows {
13639: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13640: my ($text,$name,$item,$chgstr);
13641: if (ref($cats) eq 'ARRAY') {
13642: my $maxdepth = scalar(@{$cats});
13643: if (ref($cats->[$depth]) eq 'HASH') {
13644: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13645: my $numchildren = @{$cats->[$depth]{$parent}};
13646: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 13647: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13648: for (my $j=0; $j<$numchildren; $j++) {
13649: $name = $cats->[$depth]{$parent}[$j];
13650: $item = &escape($name).':'.&escape($parent).':'.$depth;
13651: my $deeper = $depth+1;
13652: my $checked = '';
13653: if (ref($currcategories) eq 'ARRAY') {
13654: if (@{$currcategories} > 0) {
13655: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13656: $checked = ' checked="checked"';
1.663 raeburn 13657: }
13658: }
13659: }
1.664 raeburn 13660: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13661: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13662: $item.'"'.$checked.' />'.$name.'</label></span>'.
13663: '<input type="hidden" name="catname" value="'.$name.'" />'.
13664: '</td><td>';
1.663 raeburn 13665: if (ref($path) eq 'ARRAY') {
13666: push(@{$path},$name);
13667: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13668: pop(@{$path});
13669: }
13670: $text .= '</td></tr>';
13671: }
13672: $text .= '</table></td>';
13673: }
13674: }
13675: }
13676: return $text;
13677: }
13678:
1.1181 raeburn 13679: =pod
13680:
13681: =back
13682:
13683: =cut
13684:
1.655 raeburn 13685: ############################################################
13686: ############################################################
13687:
13688:
1.443 albertel 13689: sub commit_customrole {
1.664 raeburn 13690: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13691: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13692: ($start?', '.&mt('starting').' '.localtime($start):'').
13693: ($end?', ending '.localtime($end):'').': <b>'.
13694: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13695: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13696: '</b><br />';
13697: return $output;
13698: }
13699:
13700: sub commit_standardrole {
1.1116 raeburn 13701: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13702: my ($output,$logmsg,$linefeed);
13703: if ($context eq 'auto') {
13704: $linefeed = "\n";
13705: } else {
13706: $linefeed = "<br />\n";
13707: }
1.443 albertel 13708: if ($three eq 'st') {
1.541 raeburn 13709: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 13710: $one,$two,$sec,$context,$credits);
1.541 raeburn 13711: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13712: ($result eq 'unknown_course') || ($result eq 'refused')) {
13713: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13714: } else {
1.541 raeburn 13715: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13716: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13717: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13718: if ($context eq 'auto') {
13719: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13720: } else {
13721: $output .= '<b>'.$result.'</b>'.$linefeed.
13722: &mt('Add to classlist').': <b>ok</b>';
13723: }
13724: $output .= $linefeed;
1.443 albertel 13725: }
13726: } else {
13727: $output = &mt('Assigning').' '.$three.' in '.$url.
13728: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13729: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13730: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13731: if ($context eq 'auto') {
13732: $output .= $result.$linefeed;
13733: } else {
13734: $output .= '<b>'.$result.'</b>'.$linefeed;
13735: }
1.443 albertel 13736: }
13737: return $output;
13738: }
13739:
13740: sub commit_studentrole {
1.1116 raeburn 13741: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13742: $credits) = @_;
1.626 raeburn 13743: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13744: if ($context eq 'auto') {
13745: $linefeed = "\n";
13746: } else {
13747: $linefeed = '<br />'."\n";
13748: }
1.443 albertel 13749: if (defined($one) && defined($two)) {
13750: my $cid=$one.'_'.$two;
13751: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13752: my $secchange = 0;
13753: my $expire_role_result;
13754: my $modify_section_result;
1.628 raeburn 13755: if ($oldsec ne '-1') {
13756: if ($oldsec ne $sec) {
1.443 albertel 13757: $secchange = 1;
1.628 raeburn 13758: my $now = time;
1.443 albertel 13759: my $uurl='/'.$cid;
13760: $uurl=~s/\_/\//g;
13761: if ($oldsec) {
13762: $uurl.='/'.$oldsec;
13763: }
1.626 raeburn 13764: $oldsecurl = $uurl;
1.628 raeburn 13765: $expire_role_result =
1.652 raeburn 13766: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13767: if ($env{'request.course.sec'} ne '') {
13768: if ($expire_role_result eq 'refused') {
13769: my @roles = ('st');
13770: my @statuses = ('previous');
13771: my @roledoms = ($one);
13772: my $withsec = 1;
13773: my %roleshash =
13774: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13775: \@statuses,\@roles,\@roledoms,$withsec);
13776: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13777: my ($oldstart,$oldend) =
13778: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13779: if ($oldend > 0 && $oldend <= $now) {
13780: $expire_role_result = 'ok';
13781: }
13782: }
13783: }
13784: }
1.443 albertel 13785: $result = $expire_role_result;
13786: }
13787: }
13788: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 13789: $modify_section_result =
13790: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13791: undef,undef,undef,$sec,
13792: $end,$start,'','',$cid,
13793: '',$context,$credits);
1.443 albertel 13794: if ($modify_section_result =~ /^ok/) {
13795: if ($secchange == 1) {
1.628 raeburn 13796: if ($sec eq '') {
13797: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13798: } else {
13799: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13800: }
1.443 albertel 13801: } elsif ($oldsec eq '-1') {
1.628 raeburn 13802: if ($sec eq '') {
13803: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13804: } else {
13805: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13806: }
1.443 albertel 13807: } else {
1.628 raeburn 13808: if ($sec eq '') {
13809: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13810: } else {
13811: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13812: }
1.443 albertel 13813: }
13814: } else {
1.1115 raeburn 13815: if ($secchange) {
1.628 raeburn 13816: $$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;
13817: } else {
13818: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13819: }
1.443 albertel 13820: }
13821: $result = $modify_section_result;
13822: } elsif ($secchange == 1) {
1.628 raeburn 13823: if ($oldsec eq '') {
1.1103 raeburn 13824: $$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 13825: } else {
13826: $$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;
13827: }
1.626 raeburn 13828: if ($expire_role_result eq 'refused') {
13829: my $newsecurl = '/'.$cid;
13830: $newsecurl =~ s/\_/\//g;
13831: if ($sec ne '') {
13832: $newsecurl.='/'.$sec;
13833: }
13834: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13835: if ($sec eq '') {
13836: $$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;
13837: } else {
13838: $$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;
13839: }
13840: }
13841: }
1.443 albertel 13842: }
13843: } else {
1.626 raeburn 13844: $$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 13845: $result = "error: incomplete course id\n";
13846: }
13847: return $result;
13848: }
13849:
1.1108 raeburn 13850: sub show_role_extent {
13851: my ($scope,$context,$role) = @_;
13852: $scope =~ s{^/}{};
13853: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13854: push(@courseroles,'co');
13855: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13856: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13857: $scope =~ s{/}{_};
13858: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13859: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13860: my ($audom,$auname) = split(/\//,$scope);
13861: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13862: &Apache::loncommon::plainname($auname,$audom).'</span>');
13863: } else {
13864: $scope =~ s{/$}{};
13865: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13866: &Apache::lonnet::domain($scope,'description').'</span>');
13867: }
13868: }
13869:
1.443 albertel 13870: ############################################################
13871: ############################################################
13872:
1.566 albertel 13873: sub check_clone {
1.578 raeburn 13874: my ($args,$linefeed) = @_;
1.566 albertel 13875: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13876: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13877: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13878: my $clonemsg;
13879: my $can_clone = 0;
1.944 raeburn 13880: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13881: if ($lctype ne 'community') {
13882: $lctype = 'course';
13883: }
1.566 albertel 13884: if ($clonehome eq 'no_host') {
1.944 raeburn 13885: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13886: $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'});
13887: } else {
13888: $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'});
13889: }
1.566 albertel 13890: } else {
13891: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13892: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13893: if ($clonedesc{'type'} ne 'Community') {
13894: $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'});
13895: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13896: }
13897: }
1.882 raeburn 13898: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13899: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13900: $can_clone = 1;
13901: } else {
13902: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13903: $args->{'clonedomain'},$args->{'clonecourse'});
13904: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13905: if (grep(/^\*$/,@cloners)) {
13906: $can_clone = 1;
13907: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13908: $can_clone = 1;
13909: } else {
1.908 raeburn 13910: my $ccrole = 'cc';
1.944 raeburn 13911: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13912: $ccrole = 'co';
13913: }
1.578 raeburn 13914: my %roleshash =
13915: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13916: $args->{'ccdomain'},
1.908 raeburn 13917: 'userroles',['active'],[$ccrole],
1.578 raeburn 13918: [$args->{'clonedomain'}]);
1.908 raeburn 13919: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13920: $can_clone = 1;
13921: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13922: $can_clone = 1;
13923: } else {
1.944 raeburn 13924: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13925: $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'});
13926: } else {
13927: $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'});
13928: }
1.578 raeburn 13929: }
1.566 albertel 13930: }
1.578 raeburn 13931: }
1.566 albertel 13932: }
13933: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13934: }
13935:
1.444 albertel 13936: sub construct_course {
1.1166 raeburn 13937: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 13938: my $outcome;
1.541 raeburn 13939: my $linefeed = '<br />'."\n";
13940: if ($context eq 'auto') {
13941: $linefeed = "\n";
13942: }
1.566 albertel 13943:
13944: #
13945: # Are we cloning?
13946: #
13947: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13948: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13949: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13950: if ($context ne 'auto') {
1.578 raeburn 13951: if ($clonemsg ne '') {
13952: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13953: }
1.566 albertel 13954: }
13955: $outcome .= $clonemsg.$linefeed;
13956:
13957: if (!$can_clone) {
13958: return (0,$outcome);
13959: }
13960: }
13961:
1.444 albertel 13962: #
13963: # Open course
13964: #
13965: my $crstype = lc($args->{'crstype'});
13966: my %cenv=();
13967: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13968: $args->{'cdescr'},
13969: $args->{'curl'},
13970: $args->{'course_home'},
13971: $args->{'nonstandard'},
13972: $args->{'crscode'},
13973: $args->{'ccuname'}.':'.
13974: $args->{'ccdomain'},
1.882 raeburn 13975: $args->{'crstype'},
1.885 raeburn 13976: $cnum,$context,$category);
1.444 albertel 13977:
13978: # Note: The testing routines depend on this being output; see
13979: # Utils::Course. This needs to at least be output as a comment
13980: # if anyone ever decides to not show this, and Utils::Course::new
13981: # will need to be suitably modified.
1.541 raeburn 13982: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13983: if ($$courseid =~ /^error:/) {
13984: return (0,$outcome);
13985: }
13986:
1.444 albertel 13987: #
13988: # Check if created correctly
13989: #
1.479 albertel 13990: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13991: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13992: if ($crsuhome eq 'no_host') {
13993: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13994: return (0,$outcome);
13995: }
1.541 raeburn 13996: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13997:
1.444 albertel 13998: #
1.566 albertel 13999: # Do the cloning
14000: #
14001: if ($can_clone && $cloneid) {
14002: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14003: if ($context ne 'auto') {
14004: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14005: }
14006: $outcome .= $clonemsg.$linefeed;
14007: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14008: # Copy all files
1.637 www 14009: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14010: # Restore URL
1.566 albertel 14011: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14012: # Restore title
1.566 albertel 14013: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14014: # Restore creation date, creator and creation context.
14015: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14016: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14017: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14018: # Mark as cloned
1.566 albertel 14019: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14020: # Need to clone grading mode
14021: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14022: $cenv{'grading'}=$newenv{'grading'};
14023: # Do not clone these environment entries
14024: &Apache::lonnet::del('environment',
14025: ['default_enrollment_start_date',
14026: 'default_enrollment_end_date',
14027: 'question.email',
14028: 'policy.email',
14029: 'comment.email',
14030: 'pch.users.denied',
1.725 raeburn 14031: 'plc.users.denied',
14032: 'hidefromcat',
1.1121 raeburn 14033: 'checkforpriv',
1.1166 raeburn 14034: 'categories',
14035: 'internal.uniquecode'],
1.638 www 14036: $$crsudom,$$crsunum);
1.1170 raeburn 14037: if ($args->{'textbook'}) {
14038: $cenv{'internal.textbook'} = $args->{'textbook'};
14039: }
1.444 albertel 14040: }
1.566 albertel 14041:
1.444 albertel 14042: #
14043: # Set environment (will override cloned, if existing)
14044: #
14045: my @sections = ();
14046: my @xlists = ();
14047: if ($args->{'crstype'}) {
14048: $cenv{'type'}=$args->{'crstype'};
14049: }
14050: if ($args->{'crsid'}) {
14051: $cenv{'courseid'}=$args->{'crsid'};
14052: }
14053: if ($args->{'crscode'}) {
14054: $cenv{'internal.coursecode'}=$args->{'crscode'};
14055: }
14056: if ($args->{'crsquota'} ne '') {
14057: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14058: } else {
14059: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14060: }
14061: if ($args->{'ccuname'}) {
14062: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14063: ':'.$args->{'ccdomain'};
14064: } else {
14065: $cenv{'internal.courseowner'} = $args->{'curruser'};
14066: }
1.1116 raeburn 14067: if ($args->{'defaultcredits'}) {
14068: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14069: }
1.444 albertel 14070: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14071: if ($args->{'crssections'}) {
14072: $cenv{'internal.sectionnums'} = '';
14073: if ($args->{'crssections'} =~ m/,/) {
14074: @sections = split/,/,$args->{'crssections'};
14075: } else {
14076: $sections[0] = $args->{'crssections'};
14077: }
14078: if (@sections > 0) {
14079: foreach my $item (@sections) {
14080: my ($sec,$gp) = split/:/,$item;
14081: my $class = $args->{'crscode'}.$sec;
14082: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14083: $cenv{'internal.sectionnums'} .= $item.',';
14084: unless ($addcheck eq 'ok') {
14085: push @badclasses, $class;
14086: }
14087: }
14088: $cenv{'internal.sectionnums'} =~ s/,$//;
14089: }
14090: }
14091: # do not hide course coordinator from staff listing,
14092: # even if privileged
14093: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 14094: # add course coordinator's domain to domains to check for privileged users
14095: # if different to course domain
14096: if ($$crsudom ne $args->{'ccdomain'}) {
14097: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14098: }
1.444 albertel 14099: # add crosslistings
14100: if ($args->{'crsxlist'}) {
14101: $cenv{'internal.crosslistings'}='';
14102: if ($args->{'crsxlist'} =~ m/,/) {
14103: @xlists = split/,/,$args->{'crsxlist'};
14104: } else {
14105: $xlists[0] = $args->{'crsxlist'};
14106: }
14107: if (@xlists > 0) {
14108: foreach my $item (@xlists) {
14109: my ($xl,$gp) = split/:/,$item;
14110: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14111: $cenv{'internal.crosslistings'} .= $item.',';
14112: unless ($addcheck eq 'ok') {
14113: push @badclasses, $xl;
14114: }
14115: }
14116: $cenv{'internal.crosslistings'} =~ s/,$//;
14117: }
14118: }
14119: if ($args->{'autoadds'}) {
14120: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14121: }
14122: if ($args->{'autodrops'}) {
14123: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14124: }
14125: # check for notification of enrollment changes
14126: my @notified = ();
14127: if ($args->{'notify_owner'}) {
14128: if ($args->{'ccuname'} ne '') {
14129: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14130: }
14131: }
14132: if ($args->{'notify_dc'}) {
14133: if ($uname ne '') {
1.630 raeburn 14134: push(@notified,$uname.':'.$udom);
1.444 albertel 14135: }
14136: }
14137: if (@notified > 0) {
14138: my $notifylist;
14139: if (@notified > 1) {
14140: $notifylist = join(',',@notified);
14141: } else {
14142: $notifylist = $notified[0];
14143: }
14144: $cenv{'internal.notifylist'} = $notifylist;
14145: }
14146: if (@badclasses > 0) {
14147: my %lt=&Apache::lonlocal::texthash(
14148: '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',
14149: 'dnhr' => 'does not have rights to access enrollment in these classes',
14150: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14151: );
1.541 raeburn 14152: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14153: ' ('.$lt{'adby'}.')';
14154: if ($context eq 'auto') {
14155: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14156: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14157: foreach my $item (@badclasses) {
14158: if ($context eq 'auto') {
14159: $outcome .= " - $item\n";
14160: } else {
14161: $outcome .= "<li>$item</li>\n";
14162: }
14163: }
14164: if ($context eq 'auto') {
14165: $outcome .= $linefeed;
14166: } else {
1.566 albertel 14167: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14168: }
14169: }
1.444 albertel 14170: }
14171: if ($args->{'no_end_date'}) {
14172: $args->{'endaccess'} = 0;
14173: }
14174: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14175: $cenv{'internal.autoend'}=$args->{'enrollend'};
14176: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14177: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14178: if ($args->{'showphotos'}) {
14179: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14180: }
14181: $cenv{'internal.authtype'} = $args->{'authtype'};
14182: $cenv{'internal.autharg'} = $args->{'autharg'};
14183: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14184: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14185: 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');
14186: if ($context eq 'auto') {
14187: $outcome .= $krb_msg;
14188: } else {
1.566 albertel 14189: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14190: }
14191: $outcome .= $linefeed;
1.444 albertel 14192: }
14193: }
14194: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14195: if ($args->{'setpolicy'}) {
14196: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14197: }
14198: if ($args->{'setcontent'}) {
14199: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14200: }
14201: }
14202: if ($args->{'reshome'}) {
14203: $cenv{'reshome'}=$args->{'reshome'}.'/';
14204: $cenv{'reshome'}=~s/\/+$/\//;
14205: }
14206: #
14207: # course has keyed access
14208: #
14209: if ($args->{'setkeys'}) {
14210: $cenv{'keyaccess'}='yes';
14211: }
14212: # if specified, key authority is not course, but user
14213: # only active if keyaccess is yes
14214: if ($args->{'keyauth'}) {
1.487 albertel 14215: my ($user,$domain) = split(':',$args->{'keyauth'});
14216: $user = &LONCAPA::clean_username($user);
14217: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14218: if ($user ne '' && $domain ne '') {
1.487 albertel 14219: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14220: }
14221: }
14222:
1.1166 raeburn 14223: #
1.1167 raeburn 14224: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 14225: #
14226: if ($args->{'uniquecode'}) {
14227: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14228: if ($code) {
14229: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 14230: my %crsinfo =
14231: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
14232: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
14233: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
14234: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
14235: }
1.1166 raeburn 14236: if (ref($coderef)) {
14237: $$coderef = $code;
14238: }
14239: }
14240: }
14241:
1.444 albertel 14242: if ($args->{'disresdis'}) {
14243: $cenv{'pch.roles.denied'}='st';
14244: }
14245: if ($args->{'disablechat'}) {
14246: $cenv{'plc.roles.denied'}='st';
14247: }
14248:
14249: # Record we've not yet viewed the Course Initialization Helper for this
14250: # course
14251: $cenv{'course.helper.not.run'} = 1;
14252: #
14253: # Use new Randomseed
14254: #
14255: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14256: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14257: #
14258: # The encryption code and receipt prefix for this course
14259: #
14260: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14261: $cenv{'internal.encpref'}=100+int(9*rand(99));
14262: #
14263: # By default, use standard grading
14264: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14265:
1.541 raeburn 14266: $outcome .= $linefeed.&mt('Setting environment').': '.
14267: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14268: #
14269: # Open all assignments
14270: #
14271: if ($args->{'openall'}) {
14272: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14273: my %storecontent = ($storeunder => time,
14274: $storeunder.'.type' => 'date_start');
14275:
14276: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14277: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14278: }
14279: #
14280: # Set first page
14281: #
14282: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14283: || ($cloneid)) {
1.445 albertel 14284: use LONCAPA::map;
1.444 albertel 14285: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14286:
14287: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14288: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14289:
1.444 albertel 14290: $outcome .= ($fatal?$errtext:'read ok').' - ';
14291: my $title; my $url;
14292: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14293: $title=&mt('Syllabus');
1.444 albertel 14294: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14295: } else {
1.963 raeburn 14296: $title=&mt('Table of Contents');
1.444 albertel 14297: $url='/adm/navmaps';
14298: }
1.445 albertel 14299:
14300: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14301: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14302:
14303: if ($errtext) { $fatal=2; }
1.541 raeburn 14304: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14305: }
1.566 albertel 14306:
14307: return (1,$outcome);
1.444 albertel 14308: }
14309:
1.1166 raeburn 14310: sub make_unique_code {
14311: my ($cdom,$cnum) = @_;
14312: # get lock on uniquecodes db
14313: my $lockhash = {
14314: $cnum."\0".'uniquecodes' => $env{'user.name'}.
14315: ':'.$env{'user.domain'},
14316: };
14317: my $tries = 0;
14318: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14319: my ($code,$error);
14320:
14321: while (($gotlock ne 'ok') && ($tries<3)) {
14322: $tries ++;
14323: sleep 1;
14324: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14325: }
14326: if ($gotlock eq 'ok') {
14327: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
14328: my $gotcode;
14329: my $attempts = 0;
14330: while ((!$gotcode) && ($attempts < 100)) {
14331: $code = &generate_code();
14332: if (!exists($currcodes{$code})) {
14333: $gotcode = 1;
14334: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
14335: $error = 'nostore';
14336: }
14337: }
14338: $attempts ++;
14339: }
14340: my @del_lock = ($cnum."\0".'uniquecodes');
14341: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
14342: } else {
14343: $error = 'nolock';
14344: }
14345: return ($code,$error);
14346: }
14347:
14348: sub generate_code {
14349: my $code;
14350: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
14351: for (my $i=0; $i<6; $i++) {
14352: my $lettnum = int (rand 2);
14353: my $item = '';
14354: if ($lettnum) {
14355: $item = $letts[int( rand(18) )];
14356: } else {
14357: $item = 1+int( rand(8) );
14358: }
14359: $code .= $item;
14360: }
14361: return $code;
14362: }
14363:
1.444 albertel 14364: ############################################################
14365: ############################################################
14366:
1.953 droeschl 14367: #SD
14368: # only Community and Course, or anything else?
1.378 raeburn 14369: sub course_type {
14370: my ($cid) = @_;
14371: if (!defined($cid)) {
14372: $cid = $env{'request.course.id'};
14373: }
1.404 albertel 14374: if (defined($env{'course.'.$cid.'.type'})) {
14375: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14376: } else {
14377: return 'Course';
1.377 raeburn 14378: }
14379: }
1.156 albertel 14380:
1.406 raeburn 14381: sub group_term {
14382: my $crstype = &course_type();
14383: my %names = (
14384: 'Course' => 'group',
1.865 raeburn 14385: 'Community' => 'group',
1.406 raeburn 14386: );
14387: return $names{$crstype};
14388: }
14389:
1.902 raeburn 14390: sub course_types {
1.1165 raeburn 14391: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 14392: my %typename = (
14393: official => 'Official course',
14394: unofficial => 'Unofficial course',
14395: community => 'Community',
1.1165 raeburn 14396: textbook => 'Textbook course',
1.902 raeburn 14397: );
14398: return (\@types,\%typename);
14399: }
14400:
1.156 albertel 14401: sub icon {
14402: my ($file)=@_;
1.505 albertel 14403: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14404: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14405: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14406: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14407: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14408: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14409: $curfext.".gif") {
14410: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14411: $curfext.".gif";
14412: }
14413: }
1.249 albertel 14414: return &lonhttpdurl($iconname);
1.154 albertel 14415: }
1.84 albertel 14416:
1.575 albertel 14417: sub lonhttpdurl {
1.692 www 14418: #
14419: # Had been used for "small fry" static images on separate port 8080.
14420: # Modify here if lightweight http functionality desired again.
14421: # Currently eliminated due to increasing firewall issues.
14422: #
1.575 albertel 14423: my ($url)=@_;
1.692 www 14424: return $url;
1.215 albertel 14425: }
14426:
1.213 albertel 14427: sub connection_aborted {
14428: my ($r)=@_;
14429: $r->print(" ");$r->rflush();
14430: my $c = $r->connection;
14431: return $c->aborted();
14432: }
14433:
1.221 foxr 14434: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14435: # strings as 'strings'.
14436: sub escape_single {
1.221 foxr 14437: my ($input) = @_;
1.223 albertel 14438: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14439: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14440: return $input;
14441: }
1.223 albertel 14442:
1.222 foxr 14443: # Same as escape_single, but escape's "'s This
14444: # can be used for "strings"
14445: sub escape_double {
14446: my ($input) = @_;
14447: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14448: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14449: return $input;
14450: }
1.223 albertel 14451:
1.222 foxr 14452: # Escapes the last element of a full URL.
14453: sub escape_url {
14454: my ($url) = @_;
1.238 raeburn 14455: my @urlslices = split(/\//, $url,-1);
1.369 www 14456: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14457: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14458: }
1.462 albertel 14459:
1.820 raeburn 14460: sub compare_arrays {
14461: my ($arrayref1,$arrayref2) = @_;
14462: my (@difference,%count);
14463: @difference = ();
14464: %count = ();
14465: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14466: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14467: foreach my $element (keys(%count)) {
14468: if ($count{$element} == 1) {
14469: push(@difference,$element);
14470: }
14471: }
14472: }
14473: return @difference;
14474: }
14475:
1.817 bisitz 14476: # -------------------------------------------------------- Initialize user login
1.462 albertel 14477: sub init_user_environment {
1.463 albertel 14478: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14479: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14480:
14481: my $public=($username eq 'public' && $domain eq 'public');
14482:
14483: # See if old ID present, if so, remove
14484:
1.1062 raeburn 14485: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14486: my $now=time;
14487:
14488: if ($public) {
14489: my $max_public=100;
14490: my $oldest;
14491: my $oldest_time=0;
14492: for(my $next=1;$next<=$max_public;$next++) {
14493: if (-e $lonids."/publicuser_$next.id") {
14494: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14495: if ($mtime<$oldest_time || !$oldest_time) {
14496: $oldest_time=$mtime;
14497: $oldest=$next;
14498: }
14499: } else {
14500: $cookie="publicuser_$next";
14501: last;
14502: }
14503: }
14504: if (!$cookie) { $cookie="publicuser_$oldest"; }
14505: } else {
1.463 albertel 14506: # if this isn't a robot, kill any existing non-robot sessions
14507: if (!$args->{'robot'}) {
14508: opendir(DIR,$lonids);
14509: while ($filename=readdir(DIR)) {
14510: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14511: unlink($lonids.'/'.$filename);
14512: }
1.462 albertel 14513: }
1.463 albertel 14514: closedir(DIR);
1.462 albertel 14515: }
14516: # Give them a new cookie
1.463 albertel 14517: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14518: : $now.$$.int(rand(10000)));
1.463 albertel 14519: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14520:
14521: # Initialize roles
14522:
1.1062 raeburn 14523: ($userroles,$firstaccenv,$timerintenv) =
14524: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14525: }
14526: # ------------------------------------ Check browser type and MathML capability
14527:
14528: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1141 raeburn 14529: $clientunicode,$clientos,$clientmobile,$clientinfo) = &decode_user_agent($r);
1.462 albertel 14530:
14531: # ------------------------------------------------------------- Get environment
14532:
14533: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14534: my ($tmp) = keys(%userenv);
14535: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14536: } else {
14537: undef(%userenv);
14538: }
14539: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14540: $form->{'interface'}=$userenv{'interface'};
14541: }
14542: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14543:
14544: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14545: foreach my $option ('interface','localpath','localres') {
14546: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14547: }
14548: # --------------------------------------------------------- Write first profile
14549:
14550: {
14551: my %initial_env =
14552: ("user.name" => $username,
14553: "user.domain" => $domain,
14554: "user.home" => $authhost,
14555: "browser.type" => $clientbrowser,
14556: "browser.version" => $clientversion,
14557: "browser.mathml" => $clientmathml,
14558: "browser.unicode" => $clientunicode,
14559: "browser.os" => $clientos,
1.1137 raeburn 14560: "browser.mobile" => $clientmobile,
1.1141 raeburn 14561: "browser.info" => $clientinfo,
1.462 albertel 14562: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14563: "request.course.fn" => '',
14564: "request.course.uri" => '',
14565: "request.course.sec" => '',
14566: "request.role" => 'cm',
14567: "request.role.adv" => $env{'user.adv'},
14568: "request.host" => $ENV{'REMOTE_ADDR'},);
14569:
14570: if ($form->{'localpath'}) {
14571: $initial_env{"browser.localpath"} = $form->{'localpath'};
14572: $initial_env{"browser.localres"} = $form->{'localres'};
14573: }
14574:
14575: if ($form->{'interface'}) {
14576: $form->{'interface'}=~s/\W//gs;
14577: $initial_env{"browser.interface"} = $form->{'interface'};
14578: $env{'browser.interface'}=$form->{'interface'};
14579: }
14580:
1.1157 raeburn 14581: if ($form->{'iptoken'}) {
14582: my $lonhost = $r->dir_config('lonHostID');
14583: $initial_env{"user.noloadbalance"} = $lonhost;
14584: $env{'user.noloadbalance'} = $lonhost;
14585: }
14586:
1.981 raeburn 14587: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14588: my %domdef;
14589: unless ($domain eq 'public') {
14590: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14591: }
1.980 raeburn 14592:
1.1081 raeburn 14593: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14594: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14595: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14596: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14597: }
14598:
1.1165 raeburn 14599: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 14600: $userenv{'canrequest.'.$crstype} =
14601: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14602: 'reload','requestcourses',
14603: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14604: }
14605:
1.1092 raeburn 14606: $userenv{'canrequest.author'} =
14607: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14608: 'reload','requestauthor',
14609: \%userenv,\%domdef,\%is_adv);
14610: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14611: $domain,$username);
14612: my $reqstatus = $reqauthor{'author_status'};
14613: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14614: if (ref($reqauthor{'author'}) eq 'HASH') {
14615: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14616: $reqauthor{'author'}{'timestamp'};
14617: }
14618: }
14619:
1.462 albertel 14620: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14621:
1.462 albertel 14622: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14623: &GDBM_WRCREAT(),0640)) {
14624: &_add_to_env(\%disk_env,\%initial_env);
14625: &_add_to_env(\%disk_env,\%userenv,'environment.');
14626: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14627: if (ref($firstaccenv) eq 'HASH') {
14628: &_add_to_env(\%disk_env,$firstaccenv);
14629: }
14630: if (ref($timerintenv) eq 'HASH') {
14631: &_add_to_env(\%disk_env,$timerintenv);
14632: }
1.463 albertel 14633: if (ref($args->{'extra_env'})) {
14634: &_add_to_env(\%disk_env,$args->{'extra_env'});
14635: }
1.462 albertel 14636: untie(%disk_env);
14637: } else {
1.705 tempelho 14638: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14639: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14640: return 'error: '.$!;
14641: }
14642: }
14643: $env{'request.role'}='cm';
14644: $env{'request.role.adv'}=$env{'user.adv'};
14645: $env{'browser.type'}=$clientbrowser;
14646:
14647: return $cookie;
14648:
14649: }
14650:
14651: sub _add_to_env {
14652: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14653: if (ref($env_data) eq 'HASH') {
14654: while (my ($key,$value) = each(%$env_data)) {
14655: $idf->{$prefix.$key} = $value;
14656: $env{$prefix.$key} = $value;
14657: }
1.462 albertel 14658: }
14659: }
14660:
1.685 tempelho 14661: # --- Get the symbolic name of a problem and the url
14662: sub get_symb {
14663: my ($request,$silent) = @_;
1.726 raeburn 14664: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14665: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14666: if ($symb eq '') {
14667: if (!$silent) {
1.1071 raeburn 14668: if (ref($request)) {
14669: $request->print("Unable to handle ambiguous references:$url:.");
14670: }
1.685 tempelho 14671: return ();
14672: }
14673: }
14674: &Apache::lonenc::check_decrypt(\$symb);
14675: return ($symb);
14676: }
14677:
14678: # --------------------------------------------------------------Get annotation
14679:
14680: sub get_annotation {
14681: my ($symb,$enc) = @_;
14682:
14683: my $key = $symb;
14684: if (!$enc) {
14685: $key =
14686: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14687: }
14688: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14689: return $annotation{$key};
14690: }
14691:
14692: sub clean_symb {
1.731 raeburn 14693: my ($symb,$delete_enc) = @_;
1.685 tempelho 14694:
14695: &Apache::lonenc::check_decrypt(\$symb);
14696: my $enc = $env{'request.enc'};
1.731 raeburn 14697: if ($delete_enc) {
1.730 raeburn 14698: delete($env{'request.enc'});
14699: }
1.685 tempelho 14700:
14701: return ($symb,$enc);
14702: }
1.462 albertel 14703:
1.1181 raeburn 14704: ############################################################
14705: ############################################################
14706:
14707: =pod
14708:
14709: =head1 Routines for building display used to search for courses
14710:
14711:
14712: =over 4
14713:
14714: =item * &build_filters()
14715:
14716: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 14717: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
14718: and quotacheck.pl
14719:
1.1181 raeburn 14720:
14721: Inputs:
14722:
14723: filterlist - anonymous array of fields to include as potential filters
14724:
14725: crstype - course type
14726:
14727: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
14728: to pop-open a course selector (will contain "extra element").
14729:
14730: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
14731:
14732: filter - anonymous hash of criteria and their values
14733:
14734: action - form action
14735:
14736: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
14737:
1.1182 raeburn 14738: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 14739:
14740: cloneruname - username of owner of new course who wants to clone
14741:
14742: clonerudom - domain of owner of new course who wants to clone
14743:
14744: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
14745:
14746: codetitlesref - reference to array of titles of components in institutional codes (official courses)
14747:
14748: codedom - domain
14749:
14750: formname - value of form element named "form".
14751:
14752: fixeddom - domain, if fixed.
14753:
14754: prevphase - value to assign to form element named "phase" when going back to the previous screen
14755:
14756: cnameelement - name of form element in form on opener page which will receive title of selected course
14757:
14758: cnumelement - name of form element in form on opener page which will receive courseID of selected course
14759:
14760: cdomelement - name of form element in form on opener page which will receive domain of selected course
14761:
14762: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
14763:
14764: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
14765:
14766: clonewarning - warning message about missing information for intended course owner when DC creates a course
14767:
1.1182 raeburn 14768:
1.1181 raeburn 14769: Returns: $output - HTML for display of search criteria, and hidden form elements.
14770:
1.1182 raeburn 14771:
1.1181 raeburn 14772: Side Effects: None
14773:
14774: =cut
14775:
14776: # ---------------------------------------------- search for courses based on last activity etc.
14777:
14778: sub build_filters {
14779: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
14780: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
14781: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
14782: $cnameelement,$cnumelement,$cdomelement,$setroles,
14783: $clonetext,$clonewarning) = @_;
1.1182 raeburn 14784: my ($list,$jscript);
1.1181 raeburn 14785: my $onchange = 'javascript:updateFilters(this)';
14786: my ($domainselectform,$sincefilterform,$createdfilterform,
14787: $ownerdomselectform,$persondomselectform,$instcodeform,
14788: $typeselectform,$instcodetitle);
14789: if ($formname eq '') {
14790: $formname = $caller;
14791: }
14792: foreach my $item (@{$filterlist}) {
14793: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
14794: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
14795: if ($item eq 'domainfilter') {
14796: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
14797: } elsif ($item eq 'coursefilter') {
14798: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
14799: } elsif ($item eq 'ownerfilter') {
14800: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
14801: } elsif ($item eq 'ownerdomfilter') {
14802: $filter->{'ownerdomfilter'} =
14803: &LONCAPA::clean_domain($filter->{$item});
14804: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
14805: 'ownerdomfilter',1);
14806: } elsif ($item eq 'personfilter') {
14807: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
14808: } elsif ($item eq 'persondomfilter') {
14809: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
14810: 'persondomfilter',1);
14811: } else {
14812: $filter->{$item} =~ s/\W//g;
14813: }
14814: if (!$filter->{$item}) {
14815: $filter->{$item} = '';
14816: }
14817: }
14818: if ($item eq 'domainfilter') {
14819: my $allow_blank = 1;
14820: if ($formname eq 'portform') {
14821: $allow_blank=0;
14822: } elsif ($formname eq 'studentform') {
14823: $allow_blank=0;
14824: }
14825: if ($fixeddom) {
14826: $domainselectform = '<input type="hidden" name="domainfilter"'.
14827: ' value="'.$codedom.'" />'.
14828: &Apache::lonnet::domain($codedom,'description');
14829: } else {
14830: $domainselectform = &select_dom_form($filter->{$item},
14831: 'domainfilter',
14832: $allow_blank,'',$onchange);
14833: }
14834: } else {
14835: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
14836: }
14837: }
14838:
14839: # last course activity filter and selection
14840: $sincefilterform = &timebased_select_form('sincefilter',$filter);
14841:
14842: # course created filter and selection
14843: if (exists($filter->{'createdfilter'})) {
14844: $createdfilterform = &timebased_select_form('createdfilter',$filter);
14845: }
14846:
14847: my %lt = &Apache::lonlocal::texthash(
14848: 'cac' => "$crstype Activity",
14849: 'ccr' => "$crstype Created",
14850: 'cde' => "$crstype Title",
14851: 'cdo' => "$crstype Domain",
14852: 'ins' => 'Institutional Code',
14853: 'inc' => 'Institutional Categorization',
14854: 'cow' => "$crstype Owner/Co-owner",
14855: 'cop' => "$crstype Personnel Includes",
14856: 'cog' => 'Type',
14857: );
14858:
14859: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
14860: my $typeval = 'Course';
14861: if ($crstype eq 'Community') {
14862: $typeval = 'Community';
14863: }
14864: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
14865: } else {
14866: $typeselectform = '<select name="type" size="1"';
14867: if ($onchange) {
14868: $typeselectform .= ' onchange="'.$onchange.'"';
14869: }
14870: $typeselectform .= '>'."\n";
14871: foreach my $posstype ('Course','Community') {
14872: $typeselectform.='<option value="'.$posstype.'"'.
14873: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
14874: }
14875: $typeselectform.="</select>";
14876: }
14877:
14878: my ($cloneableonlyform,$cloneabletitle);
14879: if (exists($filter->{'cloneableonly'})) {
14880: my $cloneableon = '';
14881: my $cloneableoff = ' checked="checked"';
14882: if ($filter->{'cloneableonly'}) {
14883: $cloneableon = $cloneableoff;
14884: $cloneableoff = '';
14885: }
14886: $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>';
14887: if ($formname eq 'ccrs') {
1.1187 bisitz 14888: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 14889: } else {
14890: $cloneabletitle = &mt('Cloneable by you');
14891: }
14892: }
14893: my $officialjs;
14894: if ($crstype eq 'Course') {
14895: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 14896: # if (($fixeddom) || ($formname eq 'requestcrs') ||
14897: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
14898: if ($codedom) {
1.1181 raeburn 14899: $officialjs = 1;
14900: ($instcodeform,$jscript,$$numtitlesref) =
14901: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
14902: $officialjs,$codetitlesref);
14903: if ($jscript) {
1.1182 raeburn 14904: $jscript = '<script type="text/javascript">'."\n".
14905: '// <![CDATA['."\n".
14906: $jscript."\n".
14907: '// ]]>'."\n".
14908: '</script>'."\n";
1.1181 raeburn 14909: }
14910: }
14911: if ($instcodeform eq '') {
14912: $instcodeform =
14913: '<input type="text" name="instcodefilter" size="10" value="'.
14914: $list->{'instcodefilter'}.'" />';
14915: $instcodetitle = $lt{'ins'};
14916: } else {
14917: $instcodetitle = $lt{'inc'};
14918: }
14919: if ($fixeddom) {
14920: $instcodetitle .= '<br />('.$codedom.')';
14921: }
14922: }
14923: }
14924: my $output = qq|
14925: <form method="post" name="filterpicker" action="$action">
14926: <input type="hidden" name="form" value="$formname" />
14927: |;
14928: if ($formname eq 'modifycourse') {
14929: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
14930: '<input type="hidden" name="prevphase" value="'.
14931: $prevphase.'" />'."\n";
1.1182 raeburn 14932: } elsif ($formname ne 'quotacheck') {
1.1181 raeburn 14933: my $name_input;
14934: if ($cnameelement ne '') {
14935: $name_input = '<input type="hidden" name="cnameelement" value="'.
14936: $cnameelement.'" />';
14937: }
14938: $output .= qq|
1.1182 raeburn 14939: <input type="hidden" name="cnumelement" value="$cnumelement" />
14940: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 14941: $name_input
14942: $roleelement
14943: $multelement
14944: $typeelement
14945: |;
14946: if ($formname eq 'portform') {
14947: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
14948: }
14949: }
14950: if ($fixeddom) {
14951: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
14952: }
14953: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
14954: if ($sincefilterform) {
14955: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
14956: .$sincefilterform
14957: .&Apache::lonhtmlcommon::row_closure();
14958: }
14959: if ($createdfilterform) {
14960: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
14961: .$createdfilterform
14962: .&Apache::lonhtmlcommon::row_closure();
14963: }
14964: if ($domainselectform) {
14965: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
14966: .$domainselectform
14967: .&Apache::lonhtmlcommon::row_closure();
14968: }
14969: if ($typeselectform) {
14970: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
14971: $output .= $typeselectform;
14972: } else {
14973: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
14974: .$typeselectform
14975: .&Apache::lonhtmlcommon::row_closure();
14976: }
14977: }
14978: if ($instcodeform) {
14979: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
14980: .$instcodeform
14981: .&Apache::lonhtmlcommon::row_closure();
14982: }
14983: if (exists($filter->{'ownerfilter'})) {
14984: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
14985: '<table><tr><td>'.&mt('Username').'<br />'.
14986: '<input type="text" name="ownerfilter" size="20" value="'.
14987: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
14988: $ownerdomselectform.'</td></tr></table>'.
14989: &Apache::lonhtmlcommon::row_closure();
14990: }
14991: if (exists($filter->{'personfilter'})) {
14992: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
14993: '<table><tr><td>'.&mt('Username').'<br />'.
14994: '<input type="text" name="personfilter" size="20" value="'.
14995: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
14996: $persondomselectform.'</td></tr></table>'.
14997: &Apache::lonhtmlcommon::row_closure();
14998: }
14999: if (exists($filter->{'coursefilter'})) {
15000: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15001: .'<input type="text" name="coursefilter" size="25" value="'
15002: .$list->{'coursefilter'}.'" />'
15003: .&Apache::lonhtmlcommon::row_closure();
15004: }
15005: if ($cloneableonlyform) {
15006: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15007: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15008: }
15009: if (exists($filter->{'descriptfilter'})) {
15010: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15011: .'<input type="text" name="descriptfilter" size="40" value="'
15012: .$list->{'descriptfilter'}.'" />'
15013: .&Apache::lonhtmlcommon::row_closure(1);
15014: }
15015: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15016: '<input type="hidden" name="updater" value="" />'."\n".
15017: '<input type="submit" name="gosearch" value="'.
15018: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15019: return $jscript.$clonewarning.$output;
15020: }
15021:
15022: =pod
15023:
15024: =item * &timebased_select_form()
15025:
1.1182 raeburn 15026: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 15027: filter e.g., Course Activity, Course Created, when searching for courses
15028: or communities
15029:
15030: Inputs:
15031:
15032: item - name of form element (sincefilter or createdfilter)
15033:
15034: filter - anonymous hash of criteria and their values
15035:
15036: Returns: HTML for a select box contained a blank, then six time selections,
15037: with value set in incoming form variables currently selected.
15038:
15039: Side Effects: None
15040:
15041: =cut
15042:
15043: sub timebased_select_form {
15044: my ($item,$filter) = @_;
15045: if (ref($filter) eq 'HASH') {
15046: $filter->{$item} =~ s/[^\d-]//g;
15047: if (!$filter->{$item}) { $filter->{$item}=-1; }
15048: return &select_form(
15049: $filter->{$item},
15050: $item,
15051: { '-1' => '',
15052: '86400' => &mt('today'),
15053: '604800' => &mt('last week'),
15054: '2592000' => &mt('last month'),
15055: '7776000' => &mt('last three months'),
15056: '15552000' => &mt('last six months'),
15057: '31104000' => &mt('last year'),
15058: 'select_form_order' =>
15059: ['-1','86400','604800','2592000','7776000',
15060: '15552000','31104000']});
15061: }
15062: }
15063:
15064: =pod
15065:
15066: =item * &js_changer()
15067:
15068: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 15069: when course type or domain is changed, and also to hide 'Searching ...' on
15070: page load completion for page showing search result.
1.1181 raeburn 15071:
15072: Inputs: None
15073:
1.1183 raeburn 15074: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 15075:
15076: Side Effects: None
15077:
15078: =cut
15079:
15080: sub js_changer {
15081: return <<ENDJS;
15082: <script type="text/javascript">
15083: // <![CDATA[
15084: function updateFilters(caller) {
15085: if (typeof(caller) != "undefined") {
15086: document.filterpicker.updater.value = caller.name;
15087: }
15088: document.filterpicker.submit();
15089: }
1.1183 raeburn 15090:
15091: function hideSearching() {
15092: if (document.getElementById('searching')) {
15093: document.getElementById('searching').style.display = 'none';
15094: }
15095: return;
15096: }
15097:
1.1181 raeburn 15098: // ]]>
15099: </script>
15100:
15101: ENDJS
15102: }
15103:
15104: =pod
15105:
1.1182 raeburn 15106: =item * &search_courses()
15107:
15108: Process selected filters form course search form and pass to lonnet::courseiddump
15109: to retrieve a hash for which keys are courseIDs which match the selected filters.
15110:
15111: Inputs:
15112:
15113: dom - domain being searched
15114:
15115: type - course type ('Course' or 'Community' or '.' if any).
15116:
15117: filter - anonymous hash of criteria and their values
15118:
15119: numtitles - for institutional codes - number of categories
15120:
15121: cloneruname - optional username of new course owner
15122:
15123: clonerudom - optional domain of new course owner
15124:
15125: domcloner - Optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
15126: (used when DC is using course creation form)
15127:
15128: codetitles - reference to array of titles of components in institutional codes (official courses).
15129:
15130:
15131: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
15132:
15133:
15134: Side Effects: None
15135:
15136: =cut
15137:
15138:
15139: sub search_courses {
15140: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_;
15141: my (%courses,%showcourses,$cloner);
15142: if (($filter->{'ownerfilter'} ne '') ||
15143: ($filter->{'ownerdomfilter'} ne '')) {
15144: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
15145: $filter->{'ownerdomfilter'};
15146: }
15147: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
15148: if (!$filter->{$item}) {
15149: $filter->{$item}='.';
15150: }
15151: }
15152: my $now = time;
15153: my $timefilter =
15154: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
15155: my ($createdbefore,$createdafter);
15156: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
15157: $createdbefore = $now;
15158: $createdafter = $now-$filter->{'createdfilter'};
15159: }
15160: my ($instcodefilter,$regexpok);
15161: if ($numtitles) {
15162: if ($env{'form.official'} eq 'on') {
15163: $instcodefilter =
15164: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15165: $regexpok = 1;
15166: } elsif ($env{'form.official'} eq 'off') {
15167: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15168: unless ($instcodefilter eq '') {
15169: $regexpok = -1;
15170: }
15171: }
15172: } else {
15173: $instcodefilter = $filter->{'instcodefilter'};
15174: }
15175: if ($instcodefilter eq '') { $instcodefilter = '.'; }
15176: if ($type eq '') { $type = '.'; }
15177:
15178: if (($clonerudom ne '') && ($cloneruname ne '')) {
15179: $cloner = $cloneruname.':'.$clonerudom;
15180: }
15181: %courses = &Apache::lonnet::courseiddump($dom,
15182: $filter->{'descriptfilter'},
15183: $timefilter,
15184: $instcodefilter,
15185: $filter->{'combownerfilter'},
15186: $filter->{'coursefilter'},
15187: undef,undef,$type,$regexpok,undef,undef,
15188: undef,undef,$cloner,$env{'form.cc_clone'},
15189: $filter->{'cloneableonly'},
15190: $createdbefore,$createdafter,undef,
15191: $domcloner);
15192: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
15193: my $ccrole;
15194: if ($type eq 'Community') {
15195: $ccrole = 'co';
15196: } else {
15197: $ccrole = 'cc';
15198: }
15199: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
15200: $filter->{'persondomfilter'},
15201: 'userroles',undef,
15202: [$ccrole,'in','ad','ep','ta','cr'],
15203: $dom);
15204: foreach my $role (keys(%rolehash)) {
15205: my ($cnum,$cdom,$courserole) = split(':',$role);
15206: my $cid = $cdom.'_'.$cnum;
15207: if (exists($courses{$cid})) {
15208: if (ref($courses{$cid}) eq 'HASH') {
15209: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
15210: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
15211: push (@{$courses{$cid}{roles}},$courserole);
15212: }
15213: } else {
15214: $courses{$cid}{roles} = [$courserole];
15215: }
15216: $showcourses{$cid} = $courses{$cid};
15217: }
15218: }
15219: }
15220: %courses = %showcourses;
15221: }
15222: return %courses;
15223: }
15224:
15225:
15226: =pod
15227:
1.1181 raeburn 15228: =back
15229:
15230: =cut
15231:
15232:
1.990 raeburn 15233: sub build_release_hashes {
15234: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
15235: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
15236: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
15237: (ref($randomizetry) eq 'HASH'));
15238: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
15239: my ($item,$name,$value) = split(/:/,$key);
15240: if ($item eq 'parameter') {
15241: if (ref($checkparms->{$name}) eq 'ARRAY') {
15242: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
15243: push(@{$checkparms->{$name}},$value);
15244: }
15245: } else {
15246: push(@{$checkparms->{$name}},$value);
15247: }
15248: } elsif ($item eq 'resourcetag') {
15249: if ($name eq 'responsetype') {
15250: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
15251: }
15252: } elsif ($item eq 'course') {
15253: if ($name eq 'crstype') {
15254: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
15255: }
15256: }
15257: }
15258: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
15259: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
15260: return;
15261: }
15262:
1.1083 raeburn 15263: sub update_content_constraints {
15264: my ($cdom,$cnum,$chome,$cid) = @_;
15265: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15266: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
15267: my %checkresponsetypes;
15268: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
15269: my ($item,$name,$value) = split(/:/,$key);
15270: if ($item eq 'resourcetag') {
15271: if ($name eq 'responsetype') {
15272: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
15273: }
15274: }
15275: }
15276: my $navmap = Apache::lonnavmaps::navmap->new();
15277: if (defined($navmap)) {
15278: my %allresponses;
15279: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
15280: my %responses = $res->responseTypes();
15281: foreach my $key (keys(%responses)) {
15282: next unless(exists($checkresponsetypes{$key}));
15283: $allresponses{$key} += $responses{$key};
15284: }
15285: }
15286: foreach my $key (keys(%allresponses)) {
15287: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
15288: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
15289: ($reqdmajor,$reqdminor) = ($major,$minor);
15290: }
15291: }
15292: undef($navmap);
15293: }
15294: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
15295: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
15296: }
15297: return;
15298: }
15299:
1.1110 raeburn 15300: sub allmaps_incourse {
15301: my ($cdom,$cnum,$chome,$cid) = @_;
15302: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
15303: $cid = $env{'request.course.id'};
15304: $cdom = $env{'course.'.$cid.'.domain'};
15305: $cnum = $env{'course.'.$cid.'.num'};
15306: $chome = $env{'course.'.$cid.'.home'};
15307: }
15308: my %allmaps = ();
15309: my $lastchange =
15310: &Apache::lonnet::get_coursechange($cdom,$cnum);
15311: if ($lastchange > $env{'request.course.tied'}) {
15312: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
15313: unless ($ferr) {
15314: &update_content_constraints($cdom,$cnum,$chome,$cid);
15315: }
15316: }
15317: my $navmap = Apache::lonnavmaps::navmap->new();
15318: if (defined($navmap)) {
15319: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
15320: $allmaps{$res->src()} = 1;
15321: }
15322: }
15323: return \%allmaps;
15324: }
15325:
1.1083 raeburn 15326: sub parse_supplemental_title {
15327: my ($title) = @_;
15328:
15329: my ($foldertitle,$renametitle);
15330: if ($title =~ /&&&/) {
15331: $title = &HTML::Entites::decode($title);
15332: }
15333: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
15334: $renametitle=$4;
15335: my ($time,$uname,$udom) = ($1,$2,$3);
15336: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
15337: my $name = &plainname($uname,$udom);
15338: $name = &HTML::Entities::encode($name,'"<>&\'');
15339: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
15340: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
15341: $name.': <br />'.$foldertitle;
15342: }
15343: if (wantarray) {
15344: return ($title,$foldertitle,$renametitle);
15345: }
15346: return $title;
15347: }
15348:
1.1143 raeburn 15349: sub recurse_supplemental {
15350: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
15351: if ($suppmap) {
15352: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
15353: if ($fatal) {
15354: $errors ++;
15355: } else {
15356: if ($#LONCAPA::map::resources > 0) {
15357: foreach my $res (@LONCAPA::map::resources) {
15358: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
15359: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 15360: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
15361: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 15362: } else {
15363: $numfiles ++;
15364: }
15365: }
15366: }
15367: }
15368: }
15369: }
15370: return ($numfiles,$errors);
15371: }
15372:
1.1101 raeburn 15373: sub symb_to_docspath {
15374: my ($symb) = @_;
15375: return unless ($symb);
15376: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
15377: if ($resurl=~/\.(sequence|page)$/) {
15378: $mapurl=$resurl;
15379: } elsif ($resurl eq 'adm/navmaps') {
15380: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
15381: }
15382: my $mapresobj;
15383: my $navmap = Apache::lonnavmaps::navmap->new();
15384: if (ref($navmap)) {
15385: $mapresobj = $navmap->getResourceByUrl($mapurl);
15386: }
15387: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
15388: my $type=$2;
15389: my $path;
15390: if (ref($mapresobj)) {
15391: my $pcslist = $mapresobj->map_hierarchy();
15392: if ($pcslist ne '') {
15393: foreach my $pc (split(/,/,$pcslist)) {
15394: next if ($pc <= 1);
15395: my $res = $navmap->getByMapPc($pc);
15396: if (ref($res)) {
15397: my $thisurl = $res->src();
15398: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
15399: my $thistitle = $res->title();
15400: $path .= '&'.
15401: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 15402: &escape($thistitle).
1.1101 raeburn 15403: ':'.$res->randompick().
15404: ':'.$res->randomout().
15405: ':'.$res->encrypted().
15406: ':'.$res->randomorder().
15407: ':'.$res->is_page();
15408: }
15409: }
15410: }
15411: $path =~ s/^\&//;
15412: my $maptitle = $mapresobj->title();
15413: if ($mapurl eq 'default') {
1.1129 raeburn 15414: $maptitle = 'Main Content';
1.1101 raeburn 15415: }
15416: $path .= (($path ne '')? '&' : '').
15417: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 15418: &escape($maptitle).
1.1101 raeburn 15419: ':'.$mapresobj->randompick().
15420: ':'.$mapresobj->randomout().
15421: ':'.$mapresobj->encrypted().
15422: ':'.$mapresobj->randomorder().
15423: ':'.$mapresobj->is_page();
15424: } else {
15425: my $maptitle = &Apache::lonnet::gettitle($mapurl);
15426: my $ispage = (($type eq 'page')? 1 : '');
15427: if ($mapurl eq 'default') {
1.1129 raeburn 15428: $maptitle = 'Main Content';
1.1101 raeburn 15429: }
15430: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 15431: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 15432: }
15433: unless ($mapurl eq 'default') {
15434: $path = 'default&'.
1.1146 raeburn 15435: &escape('Main Content').
1.1101 raeburn 15436: ':::::&'.$path;
15437: }
15438: return $path;
15439: }
15440:
1.1094 raeburn 15441: sub captcha_display {
15442: my ($context,$lonhost) = @_;
15443: my ($output,$error);
15444: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 15445: if ($captcha eq 'original') {
1.1094 raeburn 15446: $output = &create_captcha();
15447: unless ($output) {
1.1172 raeburn 15448: $error = 'captcha';
1.1094 raeburn 15449: }
15450: } elsif ($captcha eq 'recaptcha') {
15451: $output = &create_recaptcha($pubkey);
15452: unless ($output) {
1.1172 raeburn 15453: $error = 'recaptcha';
1.1094 raeburn 15454: }
15455: }
1.1176 raeburn 15456: return ($output,$error,$captcha);
1.1094 raeburn 15457: }
15458:
15459: sub captcha_response {
15460: my ($context,$lonhost) = @_;
15461: my ($captcha_chk,$captcha_error);
15462: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 15463: if ($captcha eq 'original') {
1.1094 raeburn 15464: ($captcha_chk,$captcha_error) = &check_captcha();
15465: } elsif ($captcha eq 'recaptcha') {
15466: $captcha_chk = &check_recaptcha($privkey);
15467: } else {
15468: $captcha_chk = 1;
15469: }
15470: return ($captcha_chk,$captcha_error);
15471: }
15472:
15473: sub get_captcha_config {
15474: my ($context,$lonhost) = @_;
1.1095 raeburn 15475: my ($captcha,$pubkey,$privkey,$hashtocheck);
1.1094 raeburn 15476: my $hostname = &Apache::lonnet::hostname($lonhost);
15477: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
15478: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 15479: if ($context eq 'usercreation') {
15480: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
15481: if (ref($domconfig{$context}) eq 'HASH') {
15482: $hashtocheck = $domconfig{$context}{'cancreate'};
15483: if (ref($hashtocheck) eq 'HASH') {
15484: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
15485: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
15486: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
15487: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
15488: }
15489: if ($privkey && $pubkey) {
15490: $captcha = 'recaptcha';
15491: } else {
15492: $captcha = 'original';
15493: }
15494: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
15495: $captcha = 'original';
15496: }
1.1094 raeburn 15497: }
1.1095 raeburn 15498: } else {
15499: $captcha = 'captcha';
15500: }
15501: } elsif ($context eq 'login') {
15502: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
15503: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
15504: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
15505: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 15506: if ($privkey && $pubkey) {
15507: $captcha = 'recaptcha';
1.1095 raeburn 15508: } else {
15509: $captcha = 'original';
1.1094 raeburn 15510: }
1.1095 raeburn 15511: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
15512: $captcha = 'original';
1.1094 raeburn 15513: }
15514: }
15515: return ($captcha,$pubkey,$privkey);
15516: }
15517:
15518: sub create_captcha {
15519: my %captcha_params = &captcha_settings();
15520: my ($output,$maxtries,$tries) = ('',10,0);
15521: while ($tries < $maxtries) {
15522: $tries ++;
15523: my $captcha = Authen::Captcha->new (
15524: output_folder => $captcha_params{'output_dir'},
15525: data_folder => $captcha_params{'db_dir'},
15526: );
15527: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
15528:
15529: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
15530: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
15531: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 15532: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
15533: '<br />'.
15534: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 15535: last;
15536: }
15537: }
15538: return $output;
15539: }
15540:
15541: sub captcha_settings {
15542: my %captcha_params = (
15543: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
15544: www_output_dir => "/captchaspool",
15545: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
15546: numchars => '5',
15547: );
15548: return %captcha_params;
15549: }
15550:
15551: sub check_captcha {
15552: my ($captcha_chk,$captcha_error);
15553: my $code = $env{'form.code'};
15554: my $md5sum = $env{'form.crypt'};
15555: my %captcha_params = &captcha_settings();
15556: my $captcha = Authen::Captcha->new(
15557: output_folder => $captcha_params{'output_dir'},
15558: data_folder => $captcha_params{'db_dir'},
15559: );
1.1109 raeburn 15560: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 15561: my %captcha_hash = (
15562: 0 => 'Code not checked (file error)',
15563: -1 => 'Failed: code expired',
15564: -2 => 'Failed: invalid code (not in database)',
15565: -3 => 'Failed: invalid code (code does not match crypt)',
15566: );
15567: if ($captcha_chk != 1) {
15568: $captcha_error = $captcha_hash{$captcha_chk}
15569: }
15570: return ($captcha_chk,$captcha_error);
15571: }
15572:
15573: sub create_recaptcha {
15574: my ($pubkey) = @_;
1.1153 raeburn 15575: my $use_ssl;
15576: if ($ENV{'SERVER_PORT'} == 443) {
15577: $use_ssl = 1;
15578: }
1.1094 raeburn 15579: my $captcha = Captcha::reCAPTCHA->new;
15580: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1153 raeburn 15581: $captcha->get_html($pubkey,undef,$use_ssl).
1.1094 raeburn 15582: &mt('If either word is hard to read, [_1] will replace them.',
1.1133 raeburn 15583: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1094 raeburn 15584: '<br /><br />';
15585: }
15586:
15587: sub check_recaptcha {
15588: my ($privkey) = @_;
15589: my $captcha_chk;
15590: my $captcha = Captcha::reCAPTCHA->new;
15591: my $captcha_result =
15592: $captcha->check_answer(
15593: $privkey,
15594: $ENV{'REMOTE_ADDR'},
15595: $env{'form.recaptcha_challenge_field'},
15596: $env{'form.recaptcha_response_field'},
15597: );
15598: if ($captcha_result->{is_valid}) {
15599: $captcha_chk = 1;
15600: }
15601: return $captcha_chk;
15602: }
15603:
1.1174 raeburn 15604: sub emailusername_info {
1.1177 raeburn 15605: my @fields = ('firstname','lastname','institution','web','location','officialemail');
1.1174 raeburn 15606: my %titles = &Apache::lonlocal::texthash (
15607: lastname => 'Last Name',
15608: firstname => 'First Name',
15609: institution => 'School/college/university',
15610: location => "School's city, state/province, country",
15611: web => "School's web address",
15612: officialemail => 'E-mail address at institution (if different)',
15613: );
15614: return (\@fields,\%titles);
15615: }
15616:
1.1161 raeburn 15617: sub cleanup_html {
15618: my ($incoming) = @_;
15619: my $outgoing;
15620: if ($incoming ne '') {
15621: $outgoing = $incoming;
15622: $outgoing =~ s/;/;/g;
15623: $outgoing =~ s/\#/#/g;
15624: $outgoing =~ s/\&/&/g;
15625: $outgoing =~ s/</</g;
15626: $outgoing =~ s/>/>/g;
15627: $outgoing =~ s/\(/(/g;
15628: $outgoing =~ s/\)/)/g;
15629: $outgoing =~ s/"/"/g;
15630: $outgoing =~ s/'/'/g;
15631: $outgoing =~ s/\$/$/g;
15632: $outgoing =~ s{/}{/}g;
15633: $outgoing =~ s/=/=/g;
15634: $outgoing =~ s/\\/\/g
15635: }
15636: return $outgoing;
15637: }
15638:
1.1174 raeburn 15639: # Use:
15640: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
15641: #
15642: ##################################################
15643: # password associated functions #
15644: ##################################################
15645: sub des_keys {
15646: # Make a new key for DES encryption.
15647: # Each key has two parts which are returned separately.
15648: # Please note: Each key must be passed through the &hex function
15649: # before it is output to the web browser. The hex versions cannot
15650: # be used to decrypt.
15651: my @hexstr=('0','1','2','3','4','5','6','7',
15652: '8','9','a','b','c','d','e','f');
15653: my $lkey='';
15654: for (0..7) {
15655: $lkey.=$hexstr[rand(15)];
15656: }
15657: my $ukey='';
15658: for (0..7) {
15659: $ukey.=$hexstr[rand(15)];
15660: }
15661: return ($lkey,$ukey);
15662: }
15663:
15664: sub des_decrypt {
15665: my ($key,$cyphertext) = @_;
15666: my $keybin=pack("H16",$key);
15667: my $cypher;
15668: if ($Crypt::DES::VERSION>=2.03) {
15669: $cypher=new Crypt::DES $keybin;
15670: } else {
15671: $cypher=new DES $keybin;
15672: }
15673: my $plaintext=
15674: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
15675: $plaintext.=
15676: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
15677: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
15678: return $plaintext;
15679: }
15680:
1.112 bowersj2 15681: 1;
15682: __END__;
1.41 ng 15683:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>