Annotation of loncom/interface/loncommon.pm, revision 1.1187
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1187 ! bisitz 4: # $Id: loncommon.pm,v 1.1186 2014/04/24 13:26:23 kruse 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.1064 raeburn 7307: my $inhibitprint = &print_suppression();
7308:
1.461 albertel 7309: if (!$args->{'frameset'}) {
7310: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7311: }
1.962 droeschl 7312: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7313: $result .= Apache::lonxml::display_title();
1.319 albertel 7314: }
1.436 albertel 7315: if (!$args->{'no_nav_bar'}
7316: && !$args->{'only_body'}
7317: && !$args->{'frameset'}) {
1.1154 raeburn 7318: $result .= &help_menu_js($httphost);
1.1032 www 7319: $result.=&modal_window();
1.1038 www 7320: $result.=&togglebox_script();
1.1034 www 7321: $result.=&wishlist_window();
1.1041 www 7322: $result.=&LCprogressbarUpdate_script();
1.1034 www 7323: } else {
7324: if ($args->{'add_modal'}) {
7325: $result.=&modal_window();
7326: }
7327: if ($args->{'add_wishlist'}) {
7328: $result.=&wishlist_window();
7329: }
1.1038 www 7330: if ($args->{'add_togglebox'}) {
7331: $result.=&togglebox_script();
7332: }
1.1041 www 7333: if ($args->{'add_progressbar'}) {
7334: $result.=&LCprogressbarUpdate_script();
7335: }
1.436 albertel 7336: }
1.314 albertel 7337: if (ref($args->{'redirect'})) {
1.414 albertel 7338: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7339: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7340: if (!$inhibit_continue) {
7341: $env{'internal.head.redirect'} = $url;
7342: }
1.313 albertel 7343: $result.=<<ADDMETA
7344: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7345: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7346: ADDMETA
7347: }
1.306 albertel 7348: if (!defined($title)) {
7349: $title = 'The LearningOnline Network with CAPA';
7350: }
1.460 albertel 7351: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7352: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 7353: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7354: if (!$args->{'frameset'}) {
7355: $result .= ' /';
7356: }
7357: $result .= '>'
1.1064 raeburn 7358: .$inhibitprint
1.414 albertel 7359: .$head_extra;
1.1137 raeburn 7360: if ($env{'browser.mobile'}) {
7361: $result .= '
7362: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7363: <meta name="apple-mobile-web-app-capable" content="yes" />';
7364: }
1.962 droeschl 7365: return $result.'</head>';
1.306 albertel 7366: }
7367:
7368: =pod
7369:
1.340 albertel 7370: =item * &font_settings()
7371:
7372: Returns neccessary <meta> to set the proper encoding
7373:
1.1160 raeburn 7374: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7375:
7376: =cut
7377:
7378: sub font_settings {
1.1160 raeburn 7379: my ($args) = @_;
1.340 albertel 7380: my $headerstring='';
1.1160 raeburn 7381: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7382: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 7383: $headerstring.=
7384: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7385: if (!$args->{'frameset'}) {
7386: $headerstring.= ' /';
7387: }
7388: $headerstring .= '>'."\n";
1.340 albertel 7389: }
7390: return $headerstring;
7391: }
7392:
1.341 albertel 7393: =pod
7394:
1.1064 raeburn 7395: =item * &print_suppression()
7396:
7397: In course context returns css which causes the body to be blank when media="print",
7398: if printout generation is unavailable for the current resource.
7399:
7400: This could be because:
7401:
7402: (a) printstartdate is in the future
7403:
7404: (b) printenddate is in the past
7405:
7406: (c) there is an active exam block with "printout"
7407: functionality blocked
7408:
7409: Users with pav, pfo or evb privileges are exempt.
7410:
7411: Inputs: none
7412:
7413: =cut
7414:
7415:
7416: sub print_suppression {
7417: my $noprint;
7418: if ($env{'request.course.id'}) {
7419: my $scope = $env{'request.course.id'};
7420: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7421: (&Apache::lonnet::allowed('pfo',$scope))) {
7422: return;
7423: }
7424: if ($env{'request.course.sec'} ne '') {
7425: $scope .= "/$env{'request.course.sec'}";
7426: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7427: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7428: return;
1.1064 raeburn 7429: }
7430: }
7431: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7432: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7433: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7434: if ($blocked) {
7435: my $checkrole = "cm./$cdom/$cnum";
7436: if ($env{'request.course.sec'} ne '') {
7437: $checkrole .= "/$env{'request.course.sec'}";
7438: }
7439: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7440: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7441: $noprint = 1;
7442: }
7443: }
7444: unless ($noprint) {
7445: my $symb = &Apache::lonnet::symbread();
7446: if ($symb ne '') {
7447: my $navmap = Apache::lonnavmaps::navmap->new();
7448: if (ref($navmap)) {
7449: my $res = $navmap->getBySymb($symb);
7450: if (ref($res)) {
7451: if (!$res->resprintable()) {
7452: $noprint = 1;
7453: }
7454: }
7455: }
7456: }
7457: }
7458: if ($noprint) {
7459: return <<"ENDSTYLE";
7460: <style type="text/css" media="print">
7461: body { display:none }
7462: </style>
7463: ENDSTYLE
7464: }
7465: }
7466: return;
7467: }
7468:
7469: =pod
7470:
1.341 albertel 7471: =item * &xml_begin()
7472:
7473: Returns the needed doctype and <html>
7474:
7475: Inputs: none
7476:
7477: =cut
7478:
7479: sub xml_begin {
1.1168 raeburn 7480: my ($is_frameset) = @_;
1.341 albertel 7481: my $output='';
7482:
7483: if ($env{'browser.mathml'}) {
7484: $output='<?xml version="1.0"?>'
7485: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7486: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7487:
7488: # .'<!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">] >'
7489: .'<!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">'
7490: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7491: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 7492: } elsif ($is_frameset) {
7493: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7494: '<html>'."\n";
1.341 albertel 7495: } else {
1.1168 raeburn 7496: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7497: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7498: }
7499: return $output;
7500: }
1.340 albertel 7501:
7502: =pod
7503:
1.306 albertel 7504: =item * &start_page()
7505:
7506: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7507:
1.648 raeburn 7508: Inputs:
7509:
7510: =over 4
7511:
7512: $title - optional title for the page
7513:
7514: $head_extra - optional extra HTML to incude inside the <head>
7515:
7516: $args - additional optional args supported are:
7517:
7518: =over 8
7519:
7520: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7521: arg on
1.814 bisitz 7522: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7523: add_entries -> additional attributes to add to the <body>
7524: domain -> force to color decorate a page for a
1.317 albertel 7525: specific domain
1.648 raeburn 7526: function -> force usage of a specific rolish color
1.317 albertel 7527: scheme
1.648 raeburn 7528: redirect -> see &headtag()
7529: bgcolor -> override the default page bg color
7530: js_ready -> return a string ready for being used in
1.317 albertel 7531: a javascript writeln
1.648 raeburn 7532: html_encode -> return a string ready for being used in
1.320 albertel 7533: a html attribute
1.648 raeburn 7534: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7535: $forcereg arg
1.648 raeburn 7536: frameset -> if true will start with a <frameset>
1.330 albertel 7537: rather than <body>
1.648 raeburn 7538: skip_phases -> hash ref of
1.338 albertel 7539: head -> skip the <html><head> generation
7540: body -> skip all <body> generation
1.648 raeburn 7541: no_auto_mt_title -> prevent &mt()ing the title arg
7542: inherit_jsmath -> when creating popup window in a page,
7543: should it have jsmath forced on by the
7544: current page
1.867 kalberla 7545: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7546: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 7547: group -> includes the current group, if page is for a
7548: specific group
1.361 albertel 7549:
1.648 raeburn 7550: =back
1.460 albertel 7551:
1.648 raeburn 7552: =back
1.562 albertel 7553:
1.306 albertel 7554: =cut
7555:
7556: sub start_page {
1.309 albertel 7557: my ($title,$head_extra,$args) = @_;
1.318 albertel 7558: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7559:
1.315 albertel 7560: $env{'internal.start_page'}++;
1.1096 raeburn 7561: my ($result,@advtools);
1.964 droeschl 7562:
1.338 albertel 7563: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 7564: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 7565: }
7566:
7567: if (! exists($args->{'skip_phases'}{'body'}) ) {
7568: if ($args->{'frameset'}) {
7569: my $attr_string = &make_attr_string($args->{'force_register'},
7570: $args->{'add_entries'});
7571: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7572: } else {
7573: $result .=
7574: &bodytag($title,
7575: $args->{'function'}, $args->{'add_entries'},
7576: $args->{'only_body'}, $args->{'domain'},
7577: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 7578: $args->{'bgcolor'}, $args,
7579: \@advtools);
1.831 bisitz 7580: }
1.330 albertel 7581: }
1.338 albertel 7582:
1.315 albertel 7583: if ($args->{'js_ready'}) {
1.713 kaisler 7584: $result = &js_ready($result);
1.315 albertel 7585: }
1.320 albertel 7586: if ($args->{'html_encode'}) {
1.713 kaisler 7587: $result = &html_encode($result);
7588: }
7589:
1.813 bisitz 7590: # Preparation for new and consistent functionlist at top of screen
7591: # if ($args->{'functionlist'}) {
7592: # $result .= &build_functionlist();
7593: #}
7594:
1.964 droeschl 7595: # Don't add anything more if only_body wanted or in const space
7596: return $result if $args->{'only_body'}
7597: || $env{'request.state'} eq 'construct';
1.813 bisitz 7598:
7599: #Breadcrumbs
1.758 kaisler 7600: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7601: &Apache::lonhtmlcommon::clear_breadcrumbs();
7602: #if any br links exists, add them to the breadcrumbs
7603: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7604: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7605: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7606: }
7607: }
1.1096 raeburn 7608: # if @advtools array contains items add then to the breadcrumbs
7609: if (@advtools > 0) {
7610: &Apache::lonmenu::advtools_crumbs(@advtools);
7611: }
1.758 kaisler 7612:
7613: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7614: if(exists($args->{'bread_crumbs_component'})){
7615: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7616: }else{
7617: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7618: }
1.320 albertel 7619: }
1.315 albertel 7620: return $result;
1.306 albertel 7621: }
7622:
7623: sub end_page {
1.315 albertel 7624: my ($args) = @_;
7625: $env{'internal.end_page'}++;
1.330 albertel 7626: my $result;
1.335 albertel 7627: if ($args->{'discussion'}) {
7628: my ($target,$parser);
7629: if (ref($args->{'discussion'})) {
7630: ($target,$parser) =($args->{'discussion'}{'target'},
7631: $args->{'discussion'}{'parser'});
7632: }
7633: $result .= &Apache::lonxml::xmlend($target,$parser);
7634: }
1.330 albertel 7635: if ($args->{'frameset'}) {
7636: $result .= '</frameset>';
7637: } else {
1.635 raeburn 7638: $result .= &endbodytag($args);
1.330 albertel 7639: }
1.1080 raeburn 7640: unless ($args->{'notbody'}) {
7641: $result .= "\n</html>";
7642: }
1.330 albertel 7643:
1.315 albertel 7644: if ($args->{'js_ready'}) {
1.317 albertel 7645: $result = &js_ready($result);
1.315 albertel 7646: }
1.335 albertel 7647:
1.320 albertel 7648: if ($args->{'html_encode'}) {
7649: $result = &html_encode($result);
7650: }
1.335 albertel 7651:
1.315 albertel 7652: return $result;
7653: }
7654:
1.1034 www 7655: sub wishlist_window {
7656: return(<<'ENDWISHLIST');
1.1046 raeburn 7657: <script type="text/javascript">
1.1034 www 7658: // <![CDATA[
7659: // <!-- BEGIN LON-CAPA Internal
7660: function set_wishlistlink(title, path) {
7661: if (!title) {
7662: title = document.title;
7663: title = title.replace(/^LON-CAPA /,'');
7664: }
1.1175 raeburn 7665: title = encodeURIComponent(title);
1.1034 www 7666: if (!path) {
7667: path = location.pathname;
7668: }
1.1175 raeburn 7669: path = encodeURIComponent(path);
1.1034 www 7670: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7671: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7672: }
7673: // END LON-CAPA Internal -->
7674: // ]]>
7675: </script>
7676: ENDWISHLIST
7677: }
7678:
1.1030 www 7679: sub modal_window {
7680: return(<<'ENDMODAL');
1.1046 raeburn 7681: <script type="text/javascript">
1.1030 www 7682: // <![CDATA[
7683: // <!-- BEGIN LON-CAPA Internal
7684: var modalWindow = {
7685: parent:"body",
7686: windowId:null,
7687: content:null,
7688: width:null,
7689: height:null,
7690: close:function()
7691: {
7692: $(".LCmodal-window").remove();
7693: $(".LCmodal-overlay").remove();
7694: },
7695: open:function()
7696: {
7697: var modal = "";
7698: modal += "<div class=\"LCmodal-overlay\"></div>";
7699: 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;\">";
7700: modal += this.content;
7701: modal += "</div>";
7702:
7703: $(this.parent).append(modal);
7704:
7705: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7706: $(".LCclose-window").click(function(){modalWindow.close();});
7707: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7708: }
7709: };
1.1140 raeburn 7710: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7711: {
7712: modalWindow.windowId = "myModal";
7713: modalWindow.width = width;
7714: modalWindow.height = height;
1.1140 raeburn 7715: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7716: modalWindow.open();
7717: };
7718: // END LON-CAPA Internal -->
7719: // ]]>
7720: </script>
7721: ENDMODAL
7722: }
7723:
7724: sub modal_link {
1.1140 raeburn 7725: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7726: unless ($width) { $width=480; }
7727: unless ($height) { $height=400; }
1.1031 www 7728: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 7729: unless ($transparency) { $transparency='true'; }
7730:
1.1074 raeburn 7731: my $target_attr;
7732: if (defined($target)) {
7733: $target_attr = 'target="'.$target.'"';
7734: }
7735: return <<"ENDLINK";
1.1140 raeburn 7736: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7737: $linktext</a>
7738: ENDLINK
1.1030 www 7739: }
7740:
1.1032 www 7741: sub modal_adhoc_script {
7742: my ($funcname,$width,$height,$content)=@_;
7743: return (<<ENDADHOC);
1.1046 raeburn 7744: <script type="text/javascript">
1.1032 www 7745: // <![CDATA[
7746: var $funcname = function()
7747: {
7748: modalWindow.windowId = "myModal";
7749: modalWindow.width = $width;
7750: modalWindow.height = $height;
7751: modalWindow.content = '$content';
7752: modalWindow.open();
7753: };
7754: // ]]>
7755: </script>
7756: ENDADHOC
7757: }
7758:
1.1041 www 7759: sub modal_adhoc_inner {
7760: my ($funcname,$width,$height,$content)=@_;
7761: my $innerwidth=$width-20;
7762: $content=&js_ready(
1.1140 raeburn 7763: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
7764: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7765: $content.
1.1041 www 7766: &end_scrollbox().
1.1140 raeburn 7767: &end_page()
1.1041 www 7768: );
7769: return &modal_adhoc_script($funcname,$width,$height,$content);
7770: }
7771:
7772: sub modal_adhoc_window {
7773: my ($funcname,$width,$height,$content,$linktext)=@_;
7774: return &modal_adhoc_inner($funcname,$width,$height,$content).
7775: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7776: }
7777:
7778: sub modal_adhoc_launch {
7779: my ($funcname,$width,$height,$content)=@_;
7780: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7781: <script type="text/javascript">
7782: // <![CDATA[
7783: $funcname();
7784: // ]]>
7785: </script>
7786: ENDLAUNCH
7787: }
7788:
7789: sub modal_adhoc_close {
7790: return (<<ENDCLOSE);
7791: <script type="text/javascript">
7792: // <![CDATA[
7793: modalWindow.close();
7794: // ]]>
7795: </script>
7796: ENDCLOSE
7797: }
7798:
1.1038 www 7799: sub togglebox_script {
7800: return(<<ENDTOGGLE);
7801: <script type="text/javascript">
7802: // <![CDATA[
7803: function LCtoggleDisplay(id,hidetext,showtext) {
7804: link = document.getElementById(id + "link").childNodes[0];
7805: with (document.getElementById(id).style) {
7806: if (display == "none" ) {
7807: display = "inline";
7808: link.nodeValue = hidetext;
7809: } else {
7810: display = "none";
7811: link.nodeValue = showtext;
7812: }
7813: }
7814: }
7815: // ]]>
7816: </script>
7817: ENDTOGGLE
7818: }
7819:
1.1039 www 7820: sub start_togglebox {
7821: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7822: unless ($heading) { $heading=''; } else { $heading.=' '; }
7823: unless ($showtext) { $showtext=&mt('show'); }
7824: unless ($hidetext) { $hidetext=&mt('hide'); }
7825: unless ($headerbg) { $headerbg='#FFFFFF'; }
7826: return &start_data_table().
7827: &start_data_table_header_row().
7828: '<td bgcolor="'.$headerbg.'">'.$heading.
7829: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7830: $showtext.'\')">'.$showtext.'</a>]</td>'.
7831: &end_data_table_header_row().
7832: '<tr id="'.$id.'" style="display:none""><td>';
7833: }
7834:
7835: sub end_togglebox {
7836: return '</td></tr>'.&end_data_table();
7837: }
7838:
1.1041 www 7839: sub LCprogressbar_script {
1.1045 www 7840: my ($id)=@_;
1.1041 www 7841: return(<<ENDPROGRESS);
7842: <script type="text/javascript">
7843: // <![CDATA[
1.1045 www 7844: \$('#progressbar$id').progressbar({
1.1041 www 7845: value: 0,
7846: change: function(event, ui) {
7847: var newVal = \$(this).progressbar('option', 'value');
7848: \$('.pblabel', this).text(LCprogressTxt);
7849: }
7850: });
7851: // ]]>
7852: </script>
7853: ENDPROGRESS
7854: }
7855:
7856: sub LCprogressbarUpdate_script {
7857: return(<<ENDPROGRESSUPDATE);
7858: <style type="text/css">
7859: .ui-progressbar { position:relative; }
7860: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7861: </style>
7862: <script type="text/javascript">
7863: // <![CDATA[
1.1045 www 7864: var LCprogressTxt='---';
7865:
7866: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7867: LCprogressTxt=progresstext;
1.1045 www 7868: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7869: }
7870: // ]]>
7871: </script>
7872: ENDPROGRESSUPDATE
7873: }
7874:
1.1042 www 7875: my $LClastpercent;
1.1045 www 7876: my $LCidcnt;
7877: my $LCcurrentid;
1.1042 www 7878:
1.1041 www 7879: sub LCprogressbar {
1.1042 www 7880: my ($r)=(@_);
7881: $LClastpercent=0;
1.1045 www 7882: $LCidcnt++;
7883: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7884: my $starting=&mt('Starting');
7885: my $content=(<<ENDPROGBAR);
1.1045 www 7886: <div id="progressbar$LCcurrentid">
1.1041 www 7887: <span class="pblabel">$starting</span>
7888: </div>
7889: ENDPROGBAR
1.1045 www 7890: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7891: }
7892:
7893: sub LCprogressbarUpdate {
1.1042 www 7894: my ($r,$val,$text)=@_;
7895: unless ($val) {
7896: if ($LClastpercent) {
7897: $val=$LClastpercent;
7898: } else {
7899: $val=0;
7900: }
7901: }
1.1041 www 7902: if ($val<0) { $val=0; }
7903: if ($val>100) { $val=0; }
1.1042 www 7904: $LClastpercent=$val;
1.1041 www 7905: unless ($text) { $text=$val.'%'; }
7906: $text=&js_ready($text);
1.1044 www 7907: &r_print($r,<<ENDUPDATE);
1.1041 www 7908: <script type="text/javascript">
7909: // <![CDATA[
1.1045 www 7910: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7911: // ]]>
7912: </script>
7913: ENDUPDATE
1.1035 www 7914: }
7915:
1.1042 www 7916: sub LCprogressbarClose {
7917: my ($r)=@_;
7918: $LClastpercent=0;
1.1044 www 7919: &r_print($r,<<ENDCLOSE);
1.1042 www 7920: <script type="text/javascript">
7921: // <![CDATA[
1.1045 www 7922: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7923: // ]]>
7924: </script>
7925: ENDCLOSE
1.1044 www 7926: }
7927:
7928: sub r_print {
7929: my ($r,$to_print)=@_;
7930: if ($r) {
7931: $r->print($to_print);
7932: $r->rflush();
7933: } else {
7934: print($to_print);
7935: }
1.1042 www 7936: }
7937:
1.320 albertel 7938: sub html_encode {
7939: my ($result) = @_;
7940:
1.322 albertel 7941: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7942:
7943: return $result;
7944: }
1.1044 www 7945:
1.317 albertel 7946: sub js_ready {
7947: my ($result) = @_;
7948:
1.323 albertel 7949: $result =~ s/[\n\r]/ /xmsg;
7950: $result =~ s/\\/\\\\/xmsg;
7951: $result =~ s/'/\\'/xmsg;
1.372 albertel 7952: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7953:
7954: return $result;
7955: }
7956:
1.315 albertel 7957: sub validate_page {
7958: if ( exists($env{'internal.start_page'})
1.316 albertel 7959: && $env{'internal.start_page'} > 1) {
7960: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7961: $env{'internal.start_page'}.' '.
1.316 albertel 7962: $ENV{'request.filename'});
1.315 albertel 7963: }
7964: if ( exists($env{'internal.end_page'})
1.316 albertel 7965: && $env{'internal.end_page'} > 1) {
7966: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7967: $env{'internal.end_page'}.' '.
1.316 albertel 7968: $env{'request.filename'});
1.315 albertel 7969: }
7970: if ( exists($env{'internal.start_page'})
7971: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7972: &Apache::lonnet::logthis('start_page called without end_page '.
7973: $env{'request.filename'});
1.315 albertel 7974: }
7975: if ( ! exists($env{'internal.start_page'})
7976: && exists($env{'internal.end_page'})) {
1.316 albertel 7977: &Apache::lonnet::logthis('end_page called without start_page'.
7978: $env{'request.filename'});
1.315 albertel 7979: }
1.306 albertel 7980: }
1.315 albertel 7981:
1.996 www 7982:
7983: sub start_scrollbox {
1.1140 raeburn 7984: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 7985: unless ($outerwidth) { $outerwidth='520px'; }
7986: unless ($width) { $width='500px'; }
7987: unless ($height) { $height='200px'; }
1.1075 raeburn 7988: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7989: if ($id ne '') {
1.1140 raeburn 7990: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 7991: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 7992: }
1.1075 raeburn 7993: if ($bgcolor ne '') {
7994: $tdcol = "background-color: $bgcolor;";
7995: }
1.1137 raeburn 7996: my $nicescroll_js;
7997: if ($env{'browser.mobile'}) {
1.1140 raeburn 7998: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
7999: }
8000: return <<"END";
8001: $nicescroll_js
8002:
8003: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
8004: <div style="overflow:auto; width:$width; height:$height;"$div_id>
8005: END
8006: }
8007:
8008: sub end_scrollbox {
8009: return '</div></td></tr></table>';
8010: }
8011:
8012: sub nicescroll_javascript {
8013: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8014: my %options;
8015: if (ref($cursor) eq 'HASH') {
8016: %options = %{$cursor};
8017: }
8018: unless ($options{'railalign'} =~ /^left|right$/) {
8019: $options{'railalign'} = 'left';
8020: }
8021: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8022: my $function = &get_users_function();
8023: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 8024: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 8025: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 8026: }
1.1140 raeburn 8027: }
8028: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8029: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 8030: $options{'cursoropacity'}='1.0';
8031: }
1.1140 raeburn 8032: } else {
8033: $options{'cursoropacity'}='1.0';
8034: }
8035: if ($options{'cursorfixedheight'} eq 'none') {
8036: delete($options{'cursorfixedheight'});
8037: } else {
8038: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8039: }
8040: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8041: delete($options{'railoffset'});
8042: }
8043: my @niceoptions;
8044: while (my($key,$value) = each(%options)) {
8045: if ($value =~ /^\{.+\}$/) {
8046: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 8047: } else {
1.1140 raeburn 8048: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 8049: }
1.1140 raeburn 8050: }
8051: my $nicescroll_js = '
1.1137 raeburn 8052: $(document).ready(
1.1140 raeburn 8053: function() {
8054: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8055: }
1.1137 raeburn 8056: );
8057: ';
1.1140 raeburn 8058: if ($framecheck) {
8059: $nicescroll_js .= '
8060: function expand_div(caller) {
8061: if (top === self) {
8062: document.getElementById("'.$id.'").style.width = "auto";
8063: document.getElementById("'.$id.'").style.height = "auto";
8064: } else {
8065: try {
8066: if (parent.frames) {
8067: if (parent.frames.length > 1) {
8068: var framesrc = parent.frames[1].location.href;
8069: var currsrc = framesrc.replace(/\#.*$/,"");
8070: if ((caller == "search") || (currsrc == "'.$location.'")) {
8071: document.getElementById("'.$id.'").style.width = "auto";
8072: document.getElementById("'.$id.'").style.height = "auto";
8073: }
8074: }
8075: }
8076: } catch (e) {
8077: return;
8078: }
1.1137 raeburn 8079: }
1.1140 raeburn 8080: return;
1.996 www 8081: }
1.1140 raeburn 8082: ';
8083: }
8084: if ($needjsready) {
8085: $nicescroll_js = '
8086: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8087: } else {
8088: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8089: }
8090: return $nicescroll_js;
1.996 www 8091: }
8092:
1.318 albertel 8093: sub simple_error_page {
1.1150 bisitz 8094: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 8095: if (ref($args) eq 'HASH') {
8096: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8097: } else {
8098: $msg = &mt($msg);
8099: }
1.1150 bisitz 8100:
1.318 albertel 8101: my $page =
8102: &Apache::loncommon::start_page($title).
1.1150 bisitz 8103: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8104: &Apache::loncommon::end_page();
8105: if (ref($r)) {
8106: $r->print($page);
1.327 albertel 8107: return;
1.318 albertel 8108: }
8109: return $page;
8110: }
1.347 albertel 8111:
8112: {
1.610 albertel 8113: my @row_count;
1.961 onken 8114:
8115: sub start_data_table_count {
8116: unshift(@row_count, 0);
8117: return;
8118: }
8119:
8120: sub end_data_table_count {
8121: shift(@row_count);
8122: return;
8123: }
8124:
1.347 albertel 8125: sub start_data_table {
1.1018 raeburn 8126: my ($add_class,$id) = @_;
1.422 albertel 8127: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8128: my $table_id;
8129: if (defined($id)) {
8130: $table_id = ' id="'.$id.'"';
8131: }
1.961 onken 8132: &start_data_table_count();
1.1018 raeburn 8133: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8134: }
8135:
8136: sub end_data_table {
1.961 onken 8137: &end_data_table_count();
1.389 albertel 8138: return '</table>'."\n";;
1.347 albertel 8139: }
8140:
8141: sub start_data_table_row {
1.974 wenzelju 8142: my ($add_class, $id) = @_;
1.610 albertel 8143: $row_count[0]++;
8144: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8145: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8146: $id = (' id="'.$id.'"') unless ($id eq '');
8147: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8148: }
1.471 banghart 8149:
8150: sub continue_data_table_row {
1.974 wenzelju 8151: my ($add_class, $id) = @_;
1.610 albertel 8152: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8153: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8154: $id = (' id="'.$id.'"') unless ($id eq '');
8155: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8156: }
1.347 albertel 8157:
8158: sub end_data_table_row {
1.389 albertel 8159: return '</tr>'."\n";;
1.347 albertel 8160: }
1.367 www 8161:
1.421 albertel 8162: sub start_data_table_empty_row {
1.707 bisitz 8163: # $row_count[0]++;
1.421 albertel 8164: return '<tr class="LC_empty_row" >'."\n";;
8165: }
8166:
8167: sub end_data_table_empty_row {
8168: return '</tr>'."\n";;
8169: }
8170:
1.367 www 8171: sub start_data_table_header_row {
1.389 albertel 8172: return '<tr class="LC_header_row">'."\n";;
1.367 www 8173: }
8174:
8175: sub end_data_table_header_row {
1.389 albertel 8176: return '</tr>'."\n";;
1.367 www 8177: }
1.890 droeschl 8178:
8179: sub data_table_caption {
8180: my $caption = shift;
8181: return "<caption class=\"LC_caption\">$caption</caption>";
8182: }
1.347 albertel 8183: }
8184:
1.548 albertel 8185: =pod
8186:
8187: =item * &inhibit_menu_check($arg)
8188:
8189: Checks for a inhibitmenu state and generates output to preserve it
8190:
8191: Inputs: $arg - can be any of
8192: - undef - in which case the return value is a string
8193: to add into arguments list of a uri
8194: - 'input' - in which case the return value is a HTML
8195: <form> <input> field of type hidden to
8196: preserve the value
8197: - a url - in which case the return value is the url with
8198: the neccesary cgi args added to preserve the
8199: inhibitmenu state
8200: - a ref to a url - no return value, but the string is
8201: updated to include the neccessary cgi
8202: args to preserve the inhibitmenu state
8203:
8204: =cut
8205:
8206: sub inhibit_menu_check {
8207: my ($arg) = @_;
8208: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8209: if ($arg eq 'input') {
8210: if ($env{'form.inhibitmenu'}) {
8211: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8212: } else {
8213: return
8214: }
8215: }
8216: if ($env{'form.inhibitmenu'}) {
8217: if (ref($arg)) {
8218: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8219: } elsif ($arg eq '') {
8220: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8221: } else {
8222: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8223: }
8224: }
8225: if (!ref($arg)) {
8226: return $arg;
8227: }
8228: }
8229:
1.251 albertel 8230: ###############################################
1.182 matthew 8231:
8232: =pod
8233:
1.549 albertel 8234: =back
8235:
8236: =head1 User Information Routines
8237:
8238: =over 4
8239:
1.405 albertel 8240: =item * &get_users_function()
1.182 matthew 8241:
8242: Used by &bodytag to determine the current users primary role.
8243: Returns either 'student','coordinator','admin', or 'author'.
8244:
8245: =cut
8246:
8247: ###############################################
8248: sub get_users_function {
1.815 tempelho 8249: my $function = 'norole';
1.818 tempelho 8250: if ($env{'request.role'}=~/^(st)/) {
8251: $function='student';
8252: }
1.907 raeburn 8253: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8254: $function='coordinator';
8255: }
1.258 albertel 8256: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8257: $function='admin';
8258: }
1.826 bisitz 8259: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8260: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8261: $function='author';
8262: }
8263: return $function;
1.54 www 8264: }
1.99 www 8265:
8266: ###############################################
8267:
1.233 raeburn 8268: =pod
8269:
1.821 raeburn 8270: =item * &show_course()
8271:
8272: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8273: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8274:
8275: Inputs:
8276: None
8277:
8278: Outputs:
8279: Scalar: 1 if 'Course' to be used, 0 otherwise.
8280:
8281: =cut
8282:
8283: ###############################################
8284: sub show_course {
8285: my $course = !$env{'user.adv'};
8286: if (!$env{'user.adv'}) {
8287: foreach my $env (keys(%env)) {
8288: next if ($env !~ m/^user\.priv\./);
8289: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8290: $course = 0;
8291: last;
8292: }
8293: }
8294: }
8295: return $course;
8296: }
8297:
8298: ###############################################
8299:
8300: =pod
8301:
1.542 raeburn 8302: =item * &check_user_status()
1.274 raeburn 8303:
8304: Determines current status of supplied role for a
8305: specific user. Roles can be active, previous or future.
8306:
8307: Inputs:
8308: user's domain, user's username, course's domain,
1.375 raeburn 8309: course's number, optional section ID.
1.274 raeburn 8310:
8311: Outputs:
8312: role status: active, previous or future.
8313:
8314: =cut
8315:
8316: sub check_user_status {
1.412 raeburn 8317: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8318: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8319: my @uroles = keys %userinfo;
8320: my $srchstr;
8321: my $active_chk = 'none';
1.412 raeburn 8322: my $now = time;
1.274 raeburn 8323: if (@uroles > 0) {
1.908 raeburn 8324: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8325: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8326: } else {
1.412 raeburn 8327: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8328: }
8329: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8330: my $role_end = 0;
8331: my $role_start = 0;
8332: $active_chk = 'active';
1.412 raeburn 8333: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8334: $role_end = $1;
8335: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8336: $role_start = $1;
1.274 raeburn 8337: }
8338: }
8339: if ($role_start > 0) {
1.412 raeburn 8340: if ($now < $role_start) {
1.274 raeburn 8341: $active_chk = 'future';
8342: }
8343: }
8344: if ($role_end > 0) {
1.412 raeburn 8345: if ($now > $role_end) {
1.274 raeburn 8346: $active_chk = 'previous';
8347: }
8348: }
8349: }
8350: }
8351: return $active_chk;
8352: }
8353:
8354: ###############################################
8355:
8356: =pod
8357:
1.405 albertel 8358: =item * &get_sections()
1.233 raeburn 8359:
8360: Determines all the sections for a course including
8361: sections with students and sections containing other roles.
1.419 raeburn 8362: Incoming parameters:
8363:
8364: 1. domain
8365: 2. course number
8366: 3. reference to array containing roles for which sections should
8367: be gathered (optional).
8368: 4. reference to array containing status types for which sections
8369: should be gathered (optional).
8370:
8371: If the third argument is undefined, sections are gathered for any role.
8372: If the fourth argument is undefined, sections are gathered for any status.
8373: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8374:
1.374 raeburn 8375: Returns section hash (keys are section IDs, values are
8376: number of users in each section), subject to the
1.419 raeburn 8377: optional roles filter, optional status filter
1.233 raeburn 8378:
8379: =cut
8380:
8381: ###############################################
8382: sub get_sections {
1.419 raeburn 8383: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8384: if (!defined($cdom) || !defined($cnum)) {
8385: my $cid = $env{'request.course.id'};
8386:
8387: return if (!defined($cid));
8388:
8389: $cdom = $env{'course.'.$cid.'.domain'};
8390: $cnum = $env{'course.'.$cid.'.num'};
8391: }
8392:
8393: my %sectioncount;
1.419 raeburn 8394: my $now = time;
1.240 albertel 8395:
1.1118 raeburn 8396: my $check_students = 1;
8397: my $only_students = 0;
8398: if (ref($possible_roles) eq 'ARRAY') {
8399: if (grep(/^st$/,@{$possible_roles})) {
8400: if (@{$possible_roles} == 1) {
8401: $only_students = 1;
8402: }
8403: } else {
8404: $check_students = 0;
8405: }
8406: }
8407:
8408: if ($check_students) {
1.276 albertel 8409: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8410: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8411: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8412: my $start_index = &Apache::loncoursedata::CL_START();
8413: my $end_index = &Apache::loncoursedata::CL_END();
8414: my $status;
1.366 albertel 8415: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8416: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8417: $data->[$status_index],
8418: $data->[$start_index],
8419: $data->[$end_index]);
8420: if ($stu_status eq 'Active') {
8421: $status = 'active';
8422: } elsif ($end < $now) {
8423: $status = 'previous';
8424: } elsif ($start > $now) {
8425: $status = 'future';
8426: }
8427: if ($section ne '-1' && $section !~ /^\s*$/) {
8428: if ((!defined($possible_status)) || (($status ne '') &&
8429: (grep/^\Q$status\E$/,@{$possible_status}))) {
8430: $sectioncount{$section}++;
8431: }
1.240 albertel 8432: }
8433: }
8434: }
1.1118 raeburn 8435: if ($only_students) {
8436: return %sectioncount;
8437: }
1.240 albertel 8438: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8439: foreach my $user (sort(keys(%courseroles))) {
8440: if ($user !~ /^(\w{2})/) { next; }
8441: my ($role) = ($user =~ /^(\w{2})/);
8442: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8443: my ($section,$status);
1.240 albertel 8444: if ($role eq 'cr' &&
8445: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8446: $section=$1;
8447: }
8448: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8449: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8450: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8451: if ($end == -1 && $start == -1) {
8452: next; #deleted role
8453: }
8454: if (!defined($possible_status)) {
8455: $sectioncount{$section}++;
8456: } else {
8457: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8458: $status = 'active';
8459: } elsif ($end < $now) {
8460: $status = 'future';
8461: } elsif ($start > $now) {
8462: $status = 'previous';
8463: }
8464: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8465: $sectioncount{$section}++;
8466: }
8467: }
1.233 raeburn 8468: }
1.366 albertel 8469: return %sectioncount;
1.233 raeburn 8470: }
8471:
1.274 raeburn 8472: ###############################################
1.294 raeburn 8473:
8474: =pod
1.405 albertel 8475:
8476: =item * &get_course_users()
8477:
1.275 raeburn 8478: Retrieves usernames:domains for users in the specified course
8479: with specific role(s), and access status.
8480:
8481: Incoming parameters:
1.277 albertel 8482: 1. course domain
8483: 2. course number
8484: 3. access status: users must have - either active,
1.275 raeburn 8485: previous, future, or all.
1.277 albertel 8486: 4. reference to array of permissible roles
1.288 raeburn 8487: 5. reference to array of section restrictions (optional)
8488: 6. reference to results object (hash of hashes).
8489: 7. reference to optional userdata hash
1.609 raeburn 8490: 8. reference to optional statushash
1.630 raeburn 8491: 9. flag if privileged users (except those set to unhide in
8492: course settings) should be excluded
1.609 raeburn 8493: Keys of top level results hash are roles.
1.275 raeburn 8494: Keys of inner hashes are username:domain, with
8495: values set to access type.
1.288 raeburn 8496: Optional userdata hash returns an array with arguments in the
8497: same order as loncoursedata::get_classlist() for student data.
8498:
1.609 raeburn 8499: Optional statushash returns
8500:
1.288 raeburn 8501: Entries for end, start, section and status are blank because
8502: of the possibility of multiple values for non-student roles.
8503:
1.275 raeburn 8504: =cut
1.405 albertel 8505:
1.275 raeburn 8506: ###############################################
1.405 albertel 8507:
1.275 raeburn 8508: sub get_course_users {
1.630 raeburn 8509: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8510: my %idx = ();
1.419 raeburn 8511: my %seclists;
1.288 raeburn 8512:
8513: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8514: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8515: $idx{end} = &Apache::loncoursedata::CL_END();
8516: $idx{start} = &Apache::loncoursedata::CL_START();
8517: $idx{id} = &Apache::loncoursedata::CL_ID();
8518: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8519: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8520: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8521:
1.290 albertel 8522: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8523: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8524: my $now = time;
1.277 albertel 8525: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8526: my $match = 0;
1.412 raeburn 8527: my $secmatch = 0;
1.419 raeburn 8528: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8529: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8530: if ($section eq '') {
8531: $section = 'none';
8532: }
1.291 albertel 8533: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8534: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8535: $secmatch = 1;
8536: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8537: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8538: $secmatch = 1;
8539: }
8540: } else {
1.419 raeburn 8541: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8542: $secmatch = 1;
8543: }
1.290 albertel 8544: }
1.412 raeburn 8545: if (!$secmatch) {
8546: next;
8547: }
1.419 raeburn 8548: }
1.275 raeburn 8549: if (defined($$types{'active'})) {
1.288 raeburn 8550: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8551: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8552: $match = 1;
1.275 raeburn 8553: }
8554: }
8555: if (defined($$types{'previous'})) {
1.609 raeburn 8556: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8557: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8558: $match = 1;
1.275 raeburn 8559: }
8560: }
8561: if (defined($$types{'future'})) {
1.609 raeburn 8562: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8563: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8564: $match = 1;
1.275 raeburn 8565: }
8566: }
1.609 raeburn 8567: if ($match) {
8568: push(@{$seclists{$student}},$section);
8569: if (ref($userdata) eq 'HASH') {
8570: $$userdata{$student} = $$classlist{$student};
8571: }
8572: if (ref($statushash) eq 'HASH') {
8573: $statushash->{$student}{'st'}{$section} = $status;
8574: }
1.288 raeburn 8575: }
1.275 raeburn 8576: }
8577: }
1.412 raeburn 8578: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8579: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8580: my $now = time;
1.609 raeburn 8581: my %displaystatus = ( previous => 'Expired',
8582: active => 'Active',
8583: future => 'Future',
8584: );
1.1121 raeburn 8585: my (%nothide,@possdoms);
1.630 raeburn 8586: if ($hidepriv) {
8587: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8588: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8589: if ($user !~ /:/) {
8590: $nothide{join(':',split(/[\@]/,$user))}=1;
8591: } else {
8592: $nothide{$user} = 1;
8593: }
8594: }
1.1121 raeburn 8595: my @possdoms = ($cdom);
8596: if ($coursehash{'checkforpriv'}) {
8597: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8598: }
1.630 raeburn 8599: }
1.439 raeburn 8600: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8601: my $match = 0;
1.412 raeburn 8602: my $secmatch = 0;
1.439 raeburn 8603: my $status;
1.412 raeburn 8604: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8605: $user =~ s/:$//;
1.439 raeburn 8606: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8607: if ($end == -1 || $start == -1) {
8608: next;
8609: }
8610: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8611: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8612: my ($uname,$udom) = split(/:/,$user);
8613: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8614: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8615: $secmatch = 1;
8616: } elsif ($usec eq '') {
1.420 albertel 8617: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8618: $secmatch = 1;
8619: }
8620: } else {
8621: if (grep(/^\Q$usec\E$/,@{$sections})) {
8622: $secmatch = 1;
8623: }
8624: }
8625: if (!$secmatch) {
8626: next;
8627: }
1.288 raeburn 8628: }
1.419 raeburn 8629: if ($usec eq '') {
8630: $usec = 'none';
8631: }
1.275 raeburn 8632: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8633: if ($hidepriv) {
1.1121 raeburn 8634: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8635: (!$nothide{$uname.':'.$udom})) {
8636: next;
8637: }
8638: }
1.503 raeburn 8639: if ($end > 0 && $end < $now) {
1.439 raeburn 8640: $status = 'previous';
8641: } elsif ($start > $now) {
8642: $status = 'future';
8643: } else {
8644: $status = 'active';
8645: }
1.277 albertel 8646: foreach my $type (keys(%{$types})) {
1.275 raeburn 8647: if ($status eq $type) {
1.420 albertel 8648: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8649: push(@{$$users{$role}{$user}},$type);
8650: }
1.288 raeburn 8651: $match = 1;
8652: }
8653: }
1.419 raeburn 8654: if (($match) && (ref($userdata) eq 'HASH')) {
8655: if (!exists($$userdata{$uname.':'.$udom})) {
8656: &get_user_info($udom,$uname,\%idx,$userdata);
8657: }
1.420 albertel 8658: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8659: push(@{$seclists{$uname.':'.$udom}},$usec);
8660: }
1.609 raeburn 8661: if (ref($statushash) eq 'HASH') {
8662: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8663: }
1.275 raeburn 8664: }
8665: }
8666: }
8667: }
1.290 albertel 8668: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8669: if ((defined($cdom)) && (defined($cnum))) {
8670: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8671: if ( defined($csettings{'internal.courseowner'}) ) {
8672: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8673: next if ($owner eq '');
8674: my ($ownername,$ownerdom);
8675: if ($owner =~ /^([^:]+):([^:]+)$/) {
8676: $ownername = $1;
8677: $ownerdom = $2;
8678: } else {
8679: $ownername = $owner;
8680: $ownerdom = $cdom;
8681: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8682: }
8683: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8684: if (defined($userdata) &&
1.609 raeburn 8685: !exists($$userdata{$owner})) {
8686: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8687: if (!grep(/^none$/,@{$seclists{$owner}})) {
8688: push(@{$seclists{$owner}},'none');
8689: }
8690: if (ref($statushash) eq 'HASH') {
8691: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8692: }
1.290 albertel 8693: }
1.279 raeburn 8694: }
8695: }
8696: }
1.419 raeburn 8697: foreach my $user (keys(%seclists)) {
8698: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8699: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8700: }
1.275 raeburn 8701: }
8702: return;
8703: }
8704:
1.288 raeburn 8705: sub get_user_info {
8706: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8707: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8708: &plainname($uname,$udom,'lastname');
1.291 albertel 8709: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8710: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8711: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8712: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8713: return;
8714: }
1.275 raeburn 8715:
1.472 raeburn 8716: ###############################################
8717:
8718: =pod
8719:
8720: =item * &get_user_quota()
8721:
1.1134 raeburn 8722: Retrieves quota assigned for storage of user files.
8723: Default is to report quota for portfolio files.
1.472 raeburn 8724:
8725: Incoming parameters:
8726: 1. user's username
8727: 2. user's domain
1.1134 raeburn 8728: 3. quota name - portfolio, author, or course
1.1136 raeburn 8729: (if no quota name provided, defaults to portfolio).
1.1165 raeburn 8730: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1136 raeburn 8731: course
1.472 raeburn 8732:
8733: Returns:
1.1163 raeburn 8734: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 8735: 2. (Optional) Type of setting: custom or default
8736: (individually assigned or default for user's
8737: institutional status).
8738: 3. (Optional) - User's institutional status (e.g., faculty, staff
8739: or student - types as defined in localenroll::inst_usertypes
8740: for user's domain, which determines default quota for user.
8741: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8742:
8743: If a value has been stored in the user's environment,
1.536 raeburn 8744: it will return that, otherwise it returns the maximal default
1.1134 raeburn 8745: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8746:
8747: =cut
8748:
8749: ###############################################
8750:
8751:
8752: sub get_user_quota {
1.1136 raeburn 8753: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8754: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8755: if (!defined($udom)) {
8756: $udom = $env{'user.domain'};
8757: }
8758: if (!defined($uname)) {
8759: $uname = $env{'user.name'};
8760: }
8761: if (($udom eq '' || $uname eq '') ||
8762: ($udom eq 'public') && ($uname eq 'public')) {
8763: $quota = 0;
1.536 raeburn 8764: $quotatype = 'default';
8765: $defquota = 0;
1.472 raeburn 8766: } else {
1.536 raeburn 8767: my $inststatus;
1.1134 raeburn 8768: if ($quotaname eq 'course') {
8769: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8770: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8771: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8772: } else {
8773: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8774: $quota = $cenv{'internal.uploadquota'};
8775: }
1.536 raeburn 8776: } else {
1.1134 raeburn 8777: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8778: if ($quotaname eq 'author') {
8779: $quota = $env{'environment.authorquota'};
8780: } else {
8781: $quota = $env{'environment.portfolioquota'};
8782: }
8783: $inststatus = $env{'environment.inststatus'};
8784: } else {
8785: my %userenv =
8786: &Apache::lonnet::get('environment',['portfolioquota',
8787: 'authorquota','inststatus'],$udom,$uname);
8788: my ($tmp) = keys(%userenv);
8789: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8790: if ($quotaname eq 'author') {
8791: $quota = $userenv{'authorquota'};
8792: } else {
8793: $quota = $userenv{'portfolioquota'};
8794: }
8795: $inststatus = $userenv{'inststatus'};
8796: } else {
8797: undef(%userenv);
8798: }
8799: }
8800: }
8801: if ($quota eq '' || wantarray) {
8802: if ($quotaname eq 'course') {
8803: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 8804: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
8805: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1136 raeburn 8806: $defquota = $domdefs{$crstype.'quota'};
8807: }
8808: if ($defquota eq '') {
8809: $defquota = 500;
8810: }
1.1134 raeburn 8811: } else {
8812: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8813: }
8814: if ($quota eq '') {
8815: $quota = $defquota;
8816: $quotatype = 'default';
8817: } else {
8818: $quotatype = 'custom';
8819: }
1.472 raeburn 8820: }
8821: }
1.536 raeburn 8822: if (wantarray) {
8823: return ($quota,$quotatype,$settingstatus,$defquota);
8824: } else {
8825: return $quota;
8826: }
1.472 raeburn 8827: }
8828:
8829: ###############################################
8830:
8831: =pod
8832:
8833: =item * &default_quota()
8834:
1.536 raeburn 8835: Retrieves default quota assigned for storage of user portfolio files,
8836: given an (optional) user's institutional status.
1.472 raeburn 8837:
8838: Incoming parameters:
1.1142 raeburn 8839:
1.472 raeburn 8840: 1. domain
1.536 raeburn 8841: 2. (Optional) institutional status(es). This is a : separated list of
8842: status types (e.g., faculty, staff, student etc.)
8843: which apply to the user for whom the default is being retrieved.
8844: If the institutional status string in undefined, the domain
1.1134 raeburn 8845: default quota will be returned.
8846: 3. quota name - portfolio, author, or course
8847: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8848:
8849: Returns:
1.1142 raeburn 8850:
1.1163 raeburn 8851: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 8852: 2. (Optional) institutional type which determined the value of the
8853: default quota.
1.472 raeburn 8854:
8855: If a value has been stored in the domain's configuration db,
8856: it will return that, otherwise it returns 20 (for backwards
8857: compatibility with domains which have not set up a configuration
1.1163 raeburn 8858: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 8859:
1.536 raeburn 8860: If the user's status includes multiple types (e.g., staff and student),
8861: the largest default quota which applies to the user determines the
8862: default quota returned.
8863:
1.472 raeburn 8864: =cut
8865:
8866: ###############################################
8867:
8868:
8869: sub default_quota {
1.1134 raeburn 8870: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8871: my ($defquota,$settingstatus);
8872: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8873: ['quotas'],$udom);
1.1134 raeburn 8874: my $key = 'defaultquota';
8875: if ($quotaname eq 'author') {
8876: $key = 'authorquota';
8877: }
1.622 raeburn 8878: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8879: if ($inststatus ne '') {
1.765 raeburn 8880: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8881: foreach my $item (@statuses) {
1.1134 raeburn 8882: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8883: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8884: if ($defquota eq '') {
1.1134 raeburn 8885: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8886: $settingstatus = $item;
1.1134 raeburn 8887: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8888: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8889: $settingstatus = $item;
8890: }
8891: }
1.1134 raeburn 8892: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8893: if ($quotahash{'quotas'}{$item} ne '') {
8894: if ($defquota eq '') {
8895: $defquota = $quotahash{'quotas'}{$item};
8896: $settingstatus = $item;
8897: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8898: $defquota = $quotahash{'quotas'}{$item};
8899: $settingstatus = $item;
8900: }
1.536 raeburn 8901: }
8902: }
8903: }
8904: }
8905: if ($defquota eq '') {
1.1134 raeburn 8906: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8907: $defquota = $quotahash{'quotas'}{$key}{'default'};
8908: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8909: $defquota = $quotahash{'quotas'}{'default'};
8910: }
1.536 raeburn 8911: $settingstatus = 'default';
1.1139 raeburn 8912: if ($defquota eq '') {
8913: if ($quotaname eq 'author') {
8914: $defquota = 500;
8915: }
8916: }
1.536 raeburn 8917: }
8918: } else {
8919: $settingstatus = 'default';
1.1134 raeburn 8920: if ($quotaname eq 'author') {
8921: $defquota = 500;
8922: } else {
8923: $defquota = 20;
8924: }
1.536 raeburn 8925: }
8926: if (wantarray) {
8927: return ($defquota,$settingstatus);
1.472 raeburn 8928: } else {
1.536 raeburn 8929: return $defquota;
1.472 raeburn 8930: }
8931: }
8932:
1.1135 raeburn 8933: ###############################################
8934:
8935: =pod
8936:
1.1136 raeburn 8937: =item * &excess_filesize_warning()
1.1135 raeburn 8938:
8939: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 8940: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 8941: space to be exceeded.
1.1136 raeburn 8942:
8943: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 8944: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 8945:
1.1165 raeburn 8946: Inputs: 7
1.1136 raeburn 8947: 1. username or coursenum
1.1135 raeburn 8948: 2. domain
1.1136 raeburn 8949: 3. context ('author' or 'course')
1.1135 raeburn 8950: 4. filename of file for which action is being requested
8951: 5. filesize (kB) of file
8952: 6. action being taken: copy or upload.
1.1165 raeburn 8953: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1135 raeburn 8954:
8955: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 8956: otherwise return null.
8957:
8958: =back
1.1135 raeburn 8959:
8960: =cut
8961:
1.1136 raeburn 8962: sub excess_filesize_warning {
1.1165 raeburn 8963: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 8964: my $current_disk_usage = 0;
1.1165 raeburn 8965: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 8966: if ($context eq 'author') {
8967: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8968: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8969: } else {
8970: foreach my $subdir ('docs','supplemental') {
8971: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8972: }
8973: }
1.1135 raeburn 8974: $disk_quota = int($disk_quota * 1000);
8975: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 8976: return '<p class="LC_warning">'.
1.1135 raeburn 8977: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 8978: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
8979: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 8980: $disk_quota,$current_disk_usage).
8981: '</p>';
8982: }
8983: return;
8984: }
8985:
8986: ###############################################
8987:
8988:
1.1136 raeburn 8989:
8990:
1.384 raeburn 8991: sub get_secgrprole_info {
8992: my ($cdom,$cnum,$needroles,$type) = @_;
8993: my %sections_count = &get_sections($cdom,$cnum);
8994: my @sections = (sort {$a <=> $b} keys(%sections_count));
8995: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8996: my @groups = sort(keys(%curr_groups));
8997: my $allroles = [];
8998: my $rolehash;
8999: my $accesshash = {
9000: active => 'Currently has access',
9001: future => 'Will have future access',
9002: previous => 'Previously had access',
9003: };
9004: if ($needroles) {
9005: $rolehash = {'all' => 'all'};
1.385 albertel 9006: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9007: if (&Apache::lonnet::error(%user_roles)) {
9008: undef(%user_roles);
9009: }
9010: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9011: my ($role)=split(/\:/,$item,2);
9012: if ($role eq 'cr') { next; }
9013: if ($role =~ /^cr/) {
9014: $$rolehash{$role} = (split('/',$role))[3];
9015: } else {
9016: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9017: }
9018: }
9019: foreach my $key (sort(keys(%{$rolehash}))) {
9020: push(@{$allroles},$key);
9021: }
9022: push (@{$allroles},'st');
9023: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9024: }
9025: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9026: }
9027:
1.555 raeburn 9028: sub user_picker {
1.994 raeburn 9029: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9030: my $currdom = $dom;
9031: my %curr_selected = (
9032: srchin => 'dom',
1.580 raeburn 9033: srchby => 'lastname',
1.555 raeburn 9034: );
9035: my $srchterm;
1.625 raeburn 9036: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9037: if ($srch->{'srchby'} ne '') {
9038: $curr_selected{'srchby'} = $srch->{'srchby'};
9039: }
9040: if ($srch->{'srchin'} ne '') {
9041: $curr_selected{'srchin'} = $srch->{'srchin'};
9042: }
9043: if ($srch->{'srchtype'} ne '') {
9044: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9045: }
9046: if ($srch->{'srchdomain'} ne '') {
9047: $currdom = $srch->{'srchdomain'};
9048: }
9049: $srchterm = $srch->{'srchterm'};
9050: }
9051: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 9052: 'usr' => 'Search criteria',
1.563 raeburn 9053: 'doma' => 'Domain/institution to search',
1.558 albertel 9054: 'uname' => 'username',
9055: 'lastname' => 'last name',
1.555 raeburn 9056: 'lastfirst' => 'last name, first name',
1.558 albertel 9057: 'crs' => 'in this course',
1.576 raeburn 9058: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9059: 'alc' => 'all LON-CAPA',
1.573 raeburn 9060: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9061: 'exact' => 'is',
9062: 'contains' => 'contains',
1.569 raeburn 9063: 'begins' => 'begins with',
1.571 raeburn 9064: 'youm' => "You must include some text to search for.",
9065: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9066: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9067: 'yomc' => "You must choose a domain when using an institutional directory search.",
9068: 'ymcd' => "You must choose a domain when using a domain search.",
9069: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9070: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9071: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9072: );
1.563 raeburn 9073: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9074: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9075:
9076: my @srchins = ('crs','dom','alc','instd');
9077:
9078: foreach my $option (@srchins) {
9079: # FIXME 'alc' option unavailable until
9080: # loncreateuser::print_user_query_page()
9081: # has been completed.
9082: next if ($option eq 'alc');
1.880 raeburn 9083: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9084: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9085: if ($curr_selected{'srchin'} eq $option) {
9086: $srchinsel .= '
9087: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9088: } else {
9089: $srchinsel .= '
9090: <option value="'.$option.'">'.$lt{$option}.'</option>';
9091: }
1.555 raeburn 9092: }
1.563 raeburn 9093: $srchinsel .= "\n </select>\n";
1.555 raeburn 9094:
9095: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9096: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9097: if ($curr_selected{'srchby'} eq $option) {
9098: $srchbysel .= '
9099: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9100: } else {
9101: $srchbysel .= '
9102: <option value="'.$option.'">'.$lt{$option}.'</option>';
9103: }
9104: }
9105: $srchbysel .= "\n </select>\n";
9106:
9107: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9108: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9109: if ($curr_selected{'srchtype'} eq $option) {
9110: $srchtypesel .= '
9111: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9112: } else {
9113: $srchtypesel .= '
9114: <option value="'.$option.'">'.$lt{$option}.'</option>';
9115: }
9116: }
9117: $srchtypesel .= "\n </select>\n";
9118:
1.558 albertel 9119: my ($newuserscript,$new_user_create);
1.994 raeburn 9120: my $context_dom = $env{'request.role.domain'};
9121: if ($context eq 'requestcrs') {
9122: if ($env{'form.coursedom'} ne '') {
9123: $context_dom = $env{'form.coursedom'};
9124: }
9125: }
1.556 raeburn 9126: if ($forcenewuser) {
1.576 raeburn 9127: if (ref($srch) eq 'HASH') {
1.994 raeburn 9128: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9129: if ($cancreate) {
9130: $new_user_create = '<p> <input type="submit" name="forcenew" value="'.&HTML::Entities::encode(&mt('Make new user "[_1]"',$srchterm),'<>&"').'" onclick="javascript:setSearch(\'1\','.$caller.');" /> </p>';
9131: } else {
1.799 bisitz 9132: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9133: my %usertypetext = (
9134: official => 'institutional',
9135: unofficial => 'non-institutional',
9136: );
1.799 bisitz 9137: $new_user_create = '<p class="LC_warning">'
9138: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9139: .' '
9140: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9141: ,'<a href="'.$helplink.'">','</a>')
9142: .'</p><br />';
1.627 raeburn 9143: }
1.576 raeburn 9144: }
9145: }
9146:
1.556 raeburn 9147: $newuserscript = <<"ENDSCRIPT";
9148:
1.570 raeburn 9149: function setSearch(createnew,callingForm) {
1.556 raeburn 9150: if (createnew == 1) {
1.570 raeburn 9151: for (var i=0; i<callingForm.srchby.length; i++) {
9152: if (callingForm.srchby.options[i].value == 'uname') {
9153: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9154: }
9155: }
1.570 raeburn 9156: for (var i=0; i<callingForm.srchin.length; i++) {
9157: if ( callingForm.srchin.options[i].value == 'dom') {
9158: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9159: }
9160: }
1.570 raeburn 9161: for (var i=0; i<callingForm.srchtype.length; i++) {
9162: if (callingForm.srchtype.options[i].value == 'exact') {
9163: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9164: }
9165: }
1.570 raeburn 9166: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9167: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9168: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9169: }
9170: }
9171: }
9172: }
9173: ENDSCRIPT
1.558 albertel 9174:
1.556 raeburn 9175: }
9176:
1.555 raeburn 9177: my $output = <<"END_BLOCK";
1.556 raeburn 9178: <script type="text/javascript">
1.824 bisitz 9179: // <![CDATA[
1.570 raeburn 9180: function validateEntry(callingForm) {
1.558 albertel 9181:
1.556 raeburn 9182: var checkok = 1;
1.558 albertel 9183: var srchin;
1.570 raeburn 9184: for (var i=0; i<callingForm.srchin.length; i++) {
9185: if ( callingForm.srchin[i].checked ) {
9186: srchin = callingForm.srchin[i].value;
1.558 albertel 9187: }
9188: }
9189:
1.570 raeburn 9190: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9191: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9192: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9193: var srchterm = callingForm.srchterm.value;
9194: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9195: var msg = "";
9196:
9197: if (srchterm == "") {
9198: checkok = 0;
1.571 raeburn 9199: msg += "$lt{'youm'}\\n";
1.556 raeburn 9200: }
9201:
1.569 raeburn 9202: if (srchtype== 'begins') {
9203: if (srchterm.length < 2) {
9204: checkok = 0;
1.571 raeburn 9205: msg += "$lt{'thte'}\\n";
1.569 raeburn 9206: }
9207: }
9208:
1.556 raeburn 9209: if (srchtype== 'contains') {
9210: if (srchterm.length < 3) {
9211: checkok = 0;
1.571 raeburn 9212: msg += "$lt{'thet'}\\n";
1.556 raeburn 9213: }
9214: }
9215: if (srchin == 'instd') {
9216: if (srchdomain == '') {
9217: checkok = 0;
1.571 raeburn 9218: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9219: }
9220: }
9221: if (srchin == 'dom') {
9222: if (srchdomain == '') {
9223: checkok = 0;
1.571 raeburn 9224: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9225: }
9226: }
9227: if (srchby == 'lastfirst') {
9228: if (srchterm.indexOf(",") == -1) {
9229: checkok = 0;
1.571 raeburn 9230: msg += "$lt{'whus'}\\n";
1.556 raeburn 9231: }
9232: if (srchterm.indexOf(",") == srchterm.length -1) {
9233: checkok = 0;
1.571 raeburn 9234: msg += "$lt{'whse'}\\n";
1.556 raeburn 9235: }
9236: }
9237: if (checkok == 0) {
1.571 raeburn 9238: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9239: return;
9240: }
9241: if (checkok == 1) {
1.570 raeburn 9242: callingForm.submit();
1.556 raeburn 9243: }
9244: }
9245:
9246: $newuserscript
9247:
1.824 bisitz 9248: // ]]>
1.556 raeburn 9249: </script>
1.558 albertel 9250:
9251: $new_user_create
9252:
1.555 raeburn 9253: END_BLOCK
1.558 albertel 9254:
1.876 raeburn 9255: $output .= &Apache::lonhtmlcommon::start_pick_box().
9256: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9257: $domform.
9258: &Apache::lonhtmlcommon::row_closure().
9259: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9260: $srchbysel.
9261: $srchtypesel.
9262: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9263: $srchinsel.
9264: &Apache::lonhtmlcommon::row_closure(1).
9265: &Apache::lonhtmlcommon::end_pick_box().
9266: '<br />';
1.555 raeburn 9267: return $output;
9268: }
9269:
1.612 raeburn 9270: sub user_rule_check {
1.615 raeburn 9271: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9272: my $response;
9273: if (ref($usershash) eq 'HASH') {
9274: foreach my $user (keys(%{$usershash})) {
9275: my ($uname,$udom) = split(/:/,$user);
9276: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9277: my ($id,$newuser);
1.612 raeburn 9278: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9279: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9280: $id = $usershash->{$user}->{'id'};
9281: }
9282: my $inst_response;
9283: if (ref($checks) eq 'HASH') {
9284: if (defined($checks->{'username'})) {
1.615 raeburn 9285: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9286: &Apache::lonnet::get_instuser($udom,$uname);
9287: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9288: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9289: &Apache::lonnet::get_instuser($udom,undef,$id);
9290: }
1.615 raeburn 9291: } else {
9292: ($inst_response,%{$inst_results->{$user}}) =
9293: &Apache::lonnet::get_instuser($udom,$uname);
9294: return;
1.612 raeburn 9295: }
1.615 raeburn 9296: if (!$got_rules->{$udom}) {
1.612 raeburn 9297: my %domconfig = &Apache::lonnet::get_dom('configuration',
9298: ['usercreation'],$udom);
9299: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9300: foreach my $item ('username','id') {
1.612 raeburn 9301: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9302: $$curr_rules{$udom}{$item} =
9303: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9304: }
9305: }
9306: }
1.615 raeburn 9307: $got_rules->{$udom} = 1;
1.585 raeburn 9308: }
1.612 raeburn 9309: foreach my $item (keys(%{$checks})) {
9310: if (ref($$curr_rules{$udom}) eq 'HASH') {
9311: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9312: if (@{$$curr_rules{$udom}{$item}} > 0) {
9313: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9314: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9315: if ($rule_check{$rule}) {
9316: $$rulematch{$user}{$item} = $rule;
9317: if ($inst_response eq 'ok') {
1.615 raeburn 9318: if (ref($inst_results) eq 'HASH') {
9319: if (ref($inst_results->{$user}) eq 'HASH') {
9320: if (keys(%{$inst_results->{$user}}) == 0) {
9321: $$alerts{$item}{$udom}{$uname} = 1;
9322: }
1.612 raeburn 9323: }
9324: }
1.615 raeburn 9325: }
9326: last;
1.585 raeburn 9327: }
9328: }
9329: }
9330: }
9331: }
9332: }
9333: }
9334: }
1.612 raeburn 9335: return;
9336: }
9337:
9338: sub user_rule_formats {
9339: my ($domain,$domdesc,$curr_rules,$check) = @_;
9340: my %text = (
9341: 'username' => 'Usernames',
9342: 'id' => 'IDs',
9343: );
9344: my $output;
9345: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9346: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9347: if (@{$ruleorder} > 0) {
1.1102 raeburn 9348: $output = '<br />'.
9349: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9350: '<span class="LC_cusr_emph">','</span>',$domdesc).
9351: ' <ul>';
1.612 raeburn 9352: foreach my $rule (@{$ruleorder}) {
9353: if (ref($curr_rules) eq 'ARRAY') {
9354: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9355: if (ref($rules->{$rule}) eq 'HASH') {
9356: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9357: $rules->{$rule}{'desc'}.'</li>';
9358: }
9359: }
9360: }
9361: }
9362: $output .= '</ul>';
9363: }
9364: }
9365: return $output;
9366: }
9367:
9368: sub instrule_disallow_msg {
1.615 raeburn 9369: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9370: my $response;
9371: my %text = (
9372: item => 'username',
9373: items => 'usernames',
9374: match => 'matches',
9375: do => 'does',
9376: action => 'a username',
9377: one => 'one',
9378: );
9379: if ($count > 1) {
9380: $text{'item'} = 'usernames';
9381: $text{'match'} ='match';
9382: $text{'do'} = 'do';
9383: $text{'action'} = 'usernames',
9384: $text{'one'} = 'ones';
9385: }
9386: if ($checkitem eq 'id') {
9387: $text{'items'} = 'IDs';
9388: $text{'item'} = 'ID';
9389: $text{'action'} = 'an ID';
1.615 raeburn 9390: if ($count > 1) {
9391: $text{'item'} = 'IDs';
9392: $text{'action'} = 'IDs';
9393: }
1.612 raeburn 9394: }
1.674 bisitz 9395: $response = &mt("The $text{'item'} you chose $text{'match'} the format of $text{'items'} defined for [_1], but the $text{'item'} $text{'do'} not exist in the institutional directory.",'<span class="LC_cusr_emph">'.$domdesc.'</span>').'<br />';
1.615 raeburn 9396: if ($mode eq 'upload') {
9397: if ($checkitem eq 'username') {
9398: $response .= &mt("You will need to modify your upload file so it will include $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9399: } elsif ($checkitem eq 'id') {
1.674 bisitz 9400: $response .= &mt("Either upload a file which includes $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or when associating fields with data columns, omit an association for the Student/Employee ID field.");
1.615 raeburn 9401: }
1.669 raeburn 9402: } elsif ($mode eq 'selfcreate') {
9403: if ($checkitem eq 'id') {
9404: $response .= &mt("You must either choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or leave the ID field blank.");
9405: }
1.615 raeburn 9406: } else {
9407: if ($checkitem eq 'username') {
9408: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9409: } elsif ($checkitem eq 'id') {
9410: $response .= &mt("You must either choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or leave the ID field blank.");
9411: }
1.612 raeburn 9412: }
9413: return $response;
1.585 raeburn 9414: }
9415:
1.624 raeburn 9416: sub personal_data_fieldtitles {
9417: my %fieldtitles = &Apache::lonlocal::texthash (
9418: id => 'Student/Employee ID',
9419: permanentemail => 'E-mail address',
9420: lastname => 'Last Name',
9421: firstname => 'First Name',
9422: middlename => 'Middle Name',
9423: generation => 'Generation',
9424: gen => 'Generation',
1.765 raeburn 9425: inststatus => 'Affiliation',
1.624 raeburn 9426: );
9427: return %fieldtitles;
9428: }
9429:
1.642 raeburn 9430: sub sorted_inst_types {
9431: my ($dom) = @_;
1.1185 raeburn 9432: my ($usertypes,$order);
9433: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9434: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
9435: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
9436: $order = $domdefaults{'inststatus'}{'inststatusorder'};
9437: } else {
9438: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9439: }
1.642 raeburn 9440: my $othertitle = &mt('All users');
9441: if ($env{'request.course.id'}) {
1.668 raeburn 9442: $othertitle = &mt('Any users');
1.642 raeburn 9443: }
9444: my @types;
9445: if (ref($order) eq 'ARRAY') {
9446: @types = @{$order};
9447: }
9448: if (@types == 0) {
9449: if (ref($usertypes) eq 'HASH') {
9450: @types = sort(keys(%{$usertypes}));
9451: }
9452: }
9453: if (keys(%{$usertypes}) > 0) {
9454: $othertitle = &mt('Other users');
9455: }
9456: return ($othertitle,$usertypes,\@types);
9457: }
9458:
1.645 raeburn 9459: sub get_institutional_codes {
9460: my ($settings,$allcourses,$LC_code) = @_;
9461: # Get complete list of course sections to update
9462: my @currsections = ();
9463: my @currxlists = ();
9464: my $coursecode = $$settings{'internal.coursecode'};
9465:
9466: if ($$settings{'internal.sectionnums'} ne '') {
9467: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9468: }
9469:
9470: if ($$settings{'internal.crosslistings'} ne '') {
9471: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9472: }
9473:
9474: if (@currxlists > 0) {
9475: foreach (@currxlists) {
9476: if (m/^([^:]+):(\w*)$/) {
9477: unless (grep/^$1$/,@{$allcourses}) {
9478: push @{$allcourses},$1;
9479: $$LC_code{$1} = $2;
9480: }
9481: }
9482: }
9483: }
9484:
9485: if (@currsections > 0) {
9486: foreach (@currsections) {
9487: if (m/^(\w+):(\w*)$/) {
9488: my $sec = $coursecode.$1;
9489: my $lc_sec = $2;
9490: unless (grep/^$sec$/,@{$allcourses}) {
9491: push @{$allcourses},$sec;
9492: $$LC_code{$sec} = $lc_sec;
9493: }
9494: }
9495: }
9496: }
9497: return;
9498: }
9499:
1.971 raeburn 9500: sub get_standard_codeitems {
9501: return ('Year','Semester','Department','Number','Section');
9502: }
9503:
1.112 bowersj2 9504: =pod
9505:
1.780 raeburn 9506: =head1 Slot Helpers
9507:
9508: =over 4
9509:
9510: =item * sorted_slots()
9511:
1.1040 raeburn 9512: Sorts an array of slot names in order of an optional sort key,
9513: default sort is by slot start time (earliest first).
1.780 raeburn 9514:
9515: Inputs:
9516:
9517: =over 4
9518:
9519: slotsarr - Reference to array of unsorted slot names.
9520:
9521: slots - Reference to hash of hash, where outer hash keys are slot names.
9522:
1.1040 raeburn 9523: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9524:
1.549 albertel 9525: =back
9526:
1.780 raeburn 9527: Returns:
9528:
9529: =over 4
9530:
1.1040 raeburn 9531: sorted - An array of slot names sorted by a specified sort key
9532: (default sort key is start time of the slot).
1.780 raeburn 9533:
9534: =back
9535:
9536: =cut
9537:
9538:
9539: sub sorted_slots {
1.1040 raeburn 9540: my ($slotsarr,$slots,$sortkey) = @_;
9541: if ($sortkey eq '') {
9542: $sortkey = 'starttime';
9543: }
1.780 raeburn 9544: my @sorted;
9545: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9546: @sorted =
9547: sort {
9548: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9549: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9550: }
9551: if (ref($slots->{$a})) { return -1;}
9552: if (ref($slots->{$b})) { return 1;}
9553: return 0;
9554: } @{$slotsarr};
9555: }
9556: return @sorted;
9557: }
9558:
1.1040 raeburn 9559: =pod
9560:
9561: =item * get_future_slots()
9562:
9563: Inputs:
9564:
9565: =over 4
9566:
9567: cnum - course number
9568:
9569: cdom - course domain
9570:
9571: now - current UNIX time
9572:
9573: symb - optional symb
9574:
9575: =back
9576:
9577: Returns:
9578:
9579: =over 4
9580:
9581: sorted_reservable - ref to array of student_schedulable slots currently
9582: reservable, ordered by end date of reservation period.
9583:
9584: reservable_now - ref to hash of student_schedulable slots currently
9585: reservable.
9586:
9587: Keys in inner hash are:
9588: (a) symb: either blank or symb to which slot use is restricted.
9589: (b) endreserve: end date of reservation period.
9590:
9591: sorted_future - ref to array of student_schedulable slots reservable in
9592: the future, ordered by start date of reservation period.
9593:
9594: future_reservable - ref to hash of student_schedulable slots reservable
9595: in the future.
9596:
9597: Keys in inner hash are:
9598: (a) symb: either blank or symb to which slot use is restricted.
9599: (b) startreserve: start date of reservation period.
9600:
9601: =back
9602:
9603: =cut
9604:
9605: sub get_future_slots {
9606: my ($cnum,$cdom,$now,$symb) = @_;
9607: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9608: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9609: foreach my $slot (keys(%slots)) {
9610: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9611: if ($symb) {
9612: next if (($slots{$slot}->{'symb'} ne '') &&
9613: ($slots{$slot}->{'symb'} ne $symb));
9614: }
9615: if (($slots{$slot}->{'starttime'} > $now) &&
9616: ($slots{$slot}->{'endtime'} > $now)) {
9617: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9618: my $userallowed = 0;
9619: if ($slots{$slot}->{'allowedsections'}) {
9620: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9621: if (!defined($env{'request.role.sec'})
9622: && grep(/^No section assigned$/,@allowed_sec)) {
9623: $userallowed=1;
9624: } else {
9625: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9626: $userallowed=1;
9627: }
9628: }
9629: unless ($userallowed) {
9630: if (defined($env{'request.course.groups'})) {
9631: my @groups = split(/:/,$env{'request.course.groups'});
9632: foreach my $group (@groups) {
9633: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9634: $userallowed=1;
9635: last;
9636: }
9637: }
9638: }
9639: }
9640: }
9641: if ($slots{$slot}->{'allowedusers'}) {
9642: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9643: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9644: if (grep(/^\Q$user\E$/,@allowed_users)) {
9645: $userallowed = 1;
9646: }
9647: }
9648: next unless($userallowed);
9649: }
9650: my $startreserve = $slots{$slot}->{'startreserve'};
9651: my $endreserve = $slots{$slot}->{'endreserve'};
9652: my $symb = $slots{$slot}->{'symb'};
9653: if (($startreserve < $now) &&
9654: (!$endreserve || $endreserve > $now)) {
9655: my $lastres = $endreserve;
9656: if (!$lastres) {
9657: $lastres = $slots{$slot}->{'starttime'};
9658: }
9659: $reservable_now{$slot} = {
9660: symb => $symb,
9661: endreserve => $lastres
9662: };
9663: } elsif (($startreserve > $now) &&
9664: (!$endreserve || $endreserve > $startreserve)) {
9665: $future_reservable{$slot} = {
9666: symb => $symb,
9667: startreserve => $startreserve
9668: };
9669: }
9670: }
9671: }
9672: my @unsorted_reservable = keys(%reservable_now);
9673: if (@unsorted_reservable > 0) {
9674: @sorted_reservable =
9675: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9676: }
9677: my @unsorted_future = keys(%future_reservable);
9678: if (@unsorted_future > 0) {
9679: @sorted_future =
9680: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9681: }
9682: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9683: }
1.780 raeburn 9684:
9685: =pod
9686:
1.1057 foxr 9687: =back
9688:
1.549 albertel 9689: =head1 HTTP Helpers
9690:
9691: =over 4
9692:
1.648 raeburn 9693: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9694:
1.258 albertel 9695: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9696: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9697: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9698:
9699: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9700: $possible_names is an ref to an array of form element names. As an example:
9701: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9702: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9703:
9704: =cut
1.1 albertel 9705:
1.6 albertel 9706: sub get_unprocessed_cgi {
1.25 albertel 9707: my ($query,$possible_names)= @_;
1.26 matthew 9708: # $Apache::lonxml::debug=1;
1.356 albertel 9709: foreach my $pair (split(/&/,$query)) {
9710: my ($name, $value) = split(/=/,$pair);
1.369 www 9711: $name = &unescape($name);
1.25 albertel 9712: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9713: $value =~ tr/+/ /;
9714: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9715: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9716: }
1.16 harris41 9717: }
1.6 albertel 9718: }
9719:
1.112 bowersj2 9720: =pod
9721:
1.648 raeburn 9722: =item * &cacheheader()
1.112 bowersj2 9723:
9724: returns cache-controlling header code
9725:
9726: =cut
9727:
1.7 albertel 9728: sub cacheheader {
1.258 albertel 9729: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9730: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9731: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9732: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9733: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9734: return $output;
1.7 albertel 9735: }
9736:
1.112 bowersj2 9737: =pod
9738:
1.648 raeburn 9739: =item * &no_cache($r)
1.112 bowersj2 9740:
9741: specifies header code to not have cache
9742:
9743: =cut
9744:
1.9 albertel 9745: sub no_cache {
1.216 albertel 9746: my ($r) = @_;
9747: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9748: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9749: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9750: $r->no_cache(1);
9751: $r->header_out("Expires" => $date);
9752: $r->header_out("Pragma" => "no-cache");
1.123 www 9753: }
9754:
9755: sub content_type {
1.181 albertel 9756: my ($r,$type,$charset) = @_;
1.299 foxr 9757: if ($r) {
9758: # Note that printout.pl calls this with undef for $r.
9759: &no_cache($r);
9760: }
1.258 albertel 9761: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9762: unless ($charset) {
9763: $charset=&Apache::lonlocal::current_encoding;
9764: }
9765: if ($charset) { $type.='; charset='.$charset; }
9766: if ($r) {
9767: $r->content_type($type);
9768: } else {
9769: print("Content-type: $type\n\n");
9770: }
1.9 albertel 9771: }
1.25 albertel 9772:
1.112 bowersj2 9773: =pod
9774:
1.648 raeburn 9775: =item * &add_to_env($name,$value)
1.112 bowersj2 9776:
1.258 albertel 9777: adds $name to the %env hash with value
1.112 bowersj2 9778: $value, if $name already exists, the entry is converted to an array
9779: reference and $value is added to the array.
9780:
9781: =cut
9782:
1.25 albertel 9783: sub add_to_env {
9784: my ($name,$value)=@_;
1.258 albertel 9785: if (defined($env{$name})) {
9786: if (ref($env{$name})) {
1.25 albertel 9787: #already have multiple values
1.258 albertel 9788: push(@{ $env{$name} },$value);
1.25 albertel 9789: } else {
9790: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9791: my $first=$env{$name};
9792: undef($env{$name});
9793: push(@{ $env{$name} },$first,$value);
1.25 albertel 9794: }
9795: } else {
1.258 albertel 9796: $env{$name}=$value;
1.25 albertel 9797: }
1.31 albertel 9798: }
1.149 albertel 9799:
9800: =pod
9801:
1.648 raeburn 9802: =item * &get_env_multiple($name)
1.149 albertel 9803:
1.258 albertel 9804: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9805: values may be defined and end up as an array ref.
9806:
9807: returns an array of values
9808:
9809: =cut
9810:
9811: sub get_env_multiple {
9812: my ($name) = @_;
9813: my @values;
1.258 albertel 9814: if (defined($env{$name})) {
1.149 albertel 9815: # exists is it an array
1.258 albertel 9816: if (ref($env{$name})) {
9817: @values=@{ $env{$name} };
1.149 albertel 9818: } else {
1.258 albertel 9819: $values[0]=$env{$name};
1.149 albertel 9820: }
9821: }
9822: return(@values);
9823: }
9824:
1.660 raeburn 9825: sub ask_for_embedded_content {
9826: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9827: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 9828: %currsubfile,%unused,$rem);
1.1071 raeburn 9829: my $counter = 0;
9830: my $numnew = 0;
1.987 raeburn 9831: my $numremref = 0;
9832: my $numinvalid = 0;
9833: my $numpathchg = 0;
9834: my $numexisting = 0;
1.1071 raeburn 9835: my $numunused = 0;
9836: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 9837: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 9838: my $heading = &mt('Upload embedded files');
9839: my $buttontext = &mt('Upload');
9840:
1.1085 raeburn 9841: if ($env{'request.course.id'}) {
1.1123 raeburn 9842: if ($actionurl eq '/adm/dependencies') {
9843: $navmap = Apache::lonnavmaps::navmap->new();
9844: }
9845: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9846: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 9847: }
1.1123 raeburn 9848: if (($actionurl eq '/adm/portfolio') ||
9849: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9850: my $current_path='/';
9851: if ($env{'form.currentpath'}) {
9852: $current_path = $env{'form.currentpath'};
9853: }
9854: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 9855: $udom = $cdom;
9856: $uname = $cnum;
1.984 raeburn 9857: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9858: } else {
9859: $udom = $env{'user.domain'};
9860: $uname = $env{'user.name'};
9861: $url = '/userfiles/portfolio';
9862: }
1.987 raeburn 9863: $toplevel = $url.'/';
1.984 raeburn 9864: $url .= $current_path;
9865: $getpropath = 1;
1.987 raeburn 9866: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9867: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9868: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9869: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9870: $toplevel = $url;
1.984 raeburn 9871: if ($rest ne '') {
1.987 raeburn 9872: $url .= $rest;
9873: }
9874: } elsif ($actionurl eq '/adm/coursedocs') {
9875: if (ref($args) eq 'HASH') {
1.1071 raeburn 9876: $url = $args->{'docs_url'};
9877: $toplevel = $url;
1.1084 raeburn 9878: if ($args->{'context'} eq 'paste') {
9879: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9880: ($path) =
9881: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9882: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9883: $fileloc =~ s{^/}{};
9884: }
1.1071 raeburn 9885: }
1.1084 raeburn 9886: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 9887: if ($env{'request.course.id'} ne '') {
9888: if (ref($args) eq 'HASH') {
9889: $url = $args->{'docs_url'};
9890: $title = $args->{'docs_title'};
1.1126 raeburn 9891: $toplevel = $url;
9892: unless ($toplevel =~ m{^/}) {
9893: $toplevel = "/$url";
9894: }
1.1085 raeburn 9895: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 9896: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9897: $path = $1;
9898: } else {
9899: ($path) =
9900: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9901: }
1.1071 raeburn 9902: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9903: $fileloc =~ s{^/}{};
9904: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9905: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9906: }
1.987 raeburn 9907: }
1.1123 raeburn 9908: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9909: $udom = $cdom;
9910: $uname = $cnum;
9911: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9912: $toplevel = $url;
9913: $path = $url;
9914: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9915: $fileloc =~ s{^/}{};
1.987 raeburn 9916: }
1.1126 raeburn 9917: foreach my $file (keys(%{$allfiles})) {
9918: my $embed_file;
9919: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9920: $embed_file = $1;
9921: } else {
9922: $embed_file = $file;
9923: }
1.1158 raeburn 9924: my ($absolutepath,$cleaned_file);
9925: if ($embed_file =~ m{^\w+://}) {
9926: $cleaned_file = $embed_file;
1.1147 raeburn 9927: $newfiles{$cleaned_file} = 1;
9928: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9929: } else {
1.1158 raeburn 9930: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 9931: if ($embed_file =~ m{^/}) {
9932: $absolutepath = $embed_file;
9933: }
1.1147 raeburn 9934: if ($cleaned_file =~ m{/}) {
9935: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 9936: $path = &check_for_traversal($path,$url,$toplevel);
9937: my $item = $fname;
9938: if ($path ne '') {
9939: $item = $path.'/'.$fname;
9940: $subdependencies{$path}{$fname} = 1;
9941: } else {
9942: $dependencies{$item} = 1;
9943: }
9944: if ($absolutepath) {
9945: $mapping{$item} = $absolutepath;
9946: } else {
9947: $mapping{$item} = $embed_file;
9948: }
9949: } else {
9950: $dependencies{$embed_file} = 1;
9951: if ($absolutepath) {
1.1147 raeburn 9952: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 9953: } else {
1.1147 raeburn 9954: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9955: }
9956: }
1.984 raeburn 9957: }
9958: }
1.1071 raeburn 9959: my $dirptr = 16384;
1.984 raeburn 9960: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9961: $currsubfile{$path} = {};
1.1123 raeburn 9962: if (($actionurl eq '/adm/portfolio') ||
9963: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9964: my ($sublistref,$listerror) =
9965: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9966: if (ref($sublistref) eq 'ARRAY') {
9967: foreach my $line (@{$sublistref}) {
9968: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9969: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9970: }
1.984 raeburn 9971: }
1.987 raeburn 9972: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9973: if (opendir(my $dir,$url.'/'.$path)) {
9974: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9975: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9976: }
1.1084 raeburn 9977: } elsif (($actionurl eq '/adm/dependencies') ||
9978: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 9979: ($args->{'context'} eq 'paste')) ||
9980: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9981: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 9982: my $dir;
9983: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9984: $dir = $fileloc;
9985: } else {
9986: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9987: }
1.1071 raeburn 9988: if ($dir ne '') {
9989: my ($sublistref,$listerror) =
9990: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9991: if (ref($sublistref) eq 'ARRAY') {
9992: foreach my $line (@{$sublistref}) {
9993: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9994: undef,$mtime)=split(/\&/,$line,12);
9995: unless (($testdir&$dirptr) ||
9996: ($file_name =~ /^\.\.?$/)) {
9997: $currsubfile{$path}{$file_name} = [$size,$mtime];
9998: }
9999: }
10000: }
10001: }
1.984 raeburn 10002: }
10003: }
10004: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10005: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10006: my $item = $path.'/'.$file;
10007: unless ($mapping{$item} eq $item) {
10008: $pathchanges{$item} = 1;
10009: }
10010: $existing{$item} = 1;
10011: $numexisting ++;
10012: } else {
10013: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10014: }
10015: }
1.1071 raeburn 10016: if ($actionurl eq '/adm/dependencies') {
10017: foreach my $path (keys(%currsubfile)) {
10018: if (ref($currsubfile{$path}) eq 'HASH') {
10019: foreach my $file (keys(%{$currsubfile{$path}})) {
10020: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 10021: next if (($rem ne '') &&
10022: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10023: (ref($navmap) &&
10024: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10025: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10026: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10027: $unused{$path.'/'.$file} = 1;
10028: }
10029: }
10030: }
10031: }
10032: }
1.984 raeburn 10033: }
1.987 raeburn 10034: my %currfile;
1.1123 raeburn 10035: if (($actionurl eq '/adm/portfolio') ||
10036: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10037: my ($dirlistref,$listerror) =
10038: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10039: if (ref($dirlistref) eq 'ARRAY') {
10040: foreach my $line (@{$dirlistref}) {
10041: my ($file_name,$rest) = split(/\&/,$line,2);
10042: $currfile{$file_name} = 1;
10043: }
1.984 raeburn 10044: }
1.987 raeburn 10045: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10046: if (opendir(my $dir,$url)) {
1.987 raeburn 10047: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10048: map {$currfile{$_} = 1;} @dir_list;
10049: }
1.1084 raeburn 10050: } elsif (($actionurl eq '/adm/dependencies') ||
10051: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 10052: ($args->{'context'} eq 'paste')) ||
10053: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10054: if ($env{'request.course.id'} ne '') {
10055: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10056: if ($dir ne '') {
10057: my ($dirlistref,$listerror) =
10058: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10059: if (ref($dirlistref) eq 'ARRAY') {
10060: foreach my $line (@{$dirlistref}) {
10061: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10062: $size,undef,$mtime)=split(/\&/,$line,12);
10063: unless (($testdir&$dirptr) ||
10064: ($file_name =~ /^\.\.?$/)) {
10065: $currfile{$file_name} = [$size,$mtime];
10066: }
10067: }
10068: }
10069: }
10070: }
1.984 raeburn 10071: }
10072: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10073: if (exists($currfile{$file})) {
1.987 raeburn 10074: unless ($mapping{$file} eq $file) {
10075: $pathchanges{$file} = 1;
10076: }
10077: $existing{$file} = 1;
10078: $numexisting ++;
10079: } else {
1.984 raeburn 10080: $newfiles{$file} = 1;
10081: }
10082: }
1.1071 raeburn 10083: foreach my $file (keys(%currfile)) {
10084: unless (($file eq $filename) ||
10085: ($file eq $filename.'.bak') ||
10086: ($dependencies{$file})) {
1.1085 raeburn 10087: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 10088: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10089: next if (($rem ne '') &&
10090: (($env{"httpref.$rem".$file} ne '') ||
10091: (ref($navmap) &&
10092: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10093: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10094: ($navmap->getResourceByUrl($rem.$1)))))));
10095: }
1.1085 raeburn 10096: }
1.1071 raeburn 10097: $unused{$file} = 1;
10098: }
10099: }
1.1084 raeburn 10100: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10101: ($args->{'context'} eq 'paste')) {
10102: $counter = scalar(keys(%existing));
10103: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 10104: return ($output,$counter,$numpathchg,\%existing);
10105: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10106: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10107: $counter = scalar(keys(%existing));
10108: $numpathchg = scalar(keys(%pathchanges));
10109: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 10110: }
1.984 raeburn 10111: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10112: if ($actionurl eq '/adm/dependencies') {
10113: next if ($embed_file =~ m{^\w+://});
10114: }
1.660 raeburn 10115: $upload_output .= &start_data_table_row().
1.1123 raeburn 10116: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10117: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10118: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 10119: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10120: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10121: }
1.1123 raeburn 10122: $upload_output .= '</td>';
1.1071 raeburn 10123: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 10124: $upload_output.='<td align="right">'.
10125: '<span class="LC_info LC_fontsize_medium">'.
10126: &mt("URL points to web address").'</span>';
1.987 raeburn 10127: $numremref++;
1.660 raeburn 10128: } elsif ($args->{'error_on_invalid_names'}
10129: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 10130: $upload_output.='<td align="right"><span class="LC_warning">'.
10131: &mt('Invalid characters').'</span>';
1.987 raeburn 10132: $numinvalid++;
1.660 raeburn 10133: } else {
1.1123 raeburn 10134: $upload_output .= '<td>'.
10135: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10136: $embed_file,\%mapping,
1.1071 raeburn 10137: $allfiles,$codebase,'upload');
10138: $counter ++;
10139: $numnew ++;
1.987 raeburn 10140: }
10141: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10142: }
10143: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10144: if ($actionurl eq '/adm/dependencies') {
10145: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10146: $modify_output .= &start_data_table_row().
10147: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10148: '<img src="'.&icon($embed_file).'" border="0" />'.
10149: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10150: '<td>'.$size.'</td>'.
10151: '<td>'.$mtime.'</td>'.
10152: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10153: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10154: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10155: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10156: &embedded_file_element('upload_embedded',$counter,
10157: $embed_file,\%mapping,
10158: $allfiles,$codebase,'modify').
10159: '</div></td>'.
10160: &end_data_table_row()."\n";
10161: $counter ++;
10162: } else {
10163: $upload_output .= &start_data_table_row().
1.1123 raeburn 10164: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10165: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10166: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10167: &Apache::loncommon::end_data_table_row()."\n";
10168: }
10169: }
10170: my $delidx = $counter;
10171: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10172: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10173: $delete_output .= &start_data_table_row().
10174: '<td><img src="'.&icon($oldfile).'" />'.
10175: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10176: '<td>'.$size.'</td>'.
10177: '<td>'.$mtime.'</td>'.
10178: '<td><label><input type="checkbox" name="del_upload_dep" '.
10179: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10180: &embedded_file_element('upload_embedded',$delidx,
10181: $oldfile,\%mapping,$allfiles,
10182: $codebase,'delete').'</td>'.
10183: &end_data_table_row()."\n";
10184: $numunused ++;
10185: $delidx ++;
1.987 raeburn 10186: }
10187: if ($upload_output) {
10188: $upload_output = &start_data_table().
10189: $upload_output.
10190: &end_data_table()."\n";
10191: }
1.1071 raeburn 10192: if ($modify_output) {
10193: $modify_output = &start_data_table().
10194: &start_data_table_header_row().
10195: '<th>'.&mt('File').'</th>'.
10196: '<th>'.&mt('Size (KB)').'</th>'.
10197: '<th>'.&mt('Modified').'</th>'.
10198: '<th>'.&mt('Upload replacement?').'</th>'.
10199: &end_data_table_header_row().
10200: $modify_output.
10201: &end_data_table()."\n";
10202: }
10203: if ($delete_output) {
10204: $delete_output = &start_data_table().
10205: &start_data_table_header_row().
10206: '<th>'.&mt('File').'</th>'.
10207: '<th>'.&mt('Size (KB)').'</th>'.
10208: '<th>'.&mt('Modified').'</th>'.
10209: '<th>'.&mt('Delete?').'</th>'.
10210: &end_data_table_header_row().
10211: $delete_output.
10212: &end_data_table()."\n";
10213: }
1.987 raeburn 10214: my $applies = 0;
10215: if ($numremref) {
10216: $applies ++;
10217: }
10218: if ($numinvalid) {
10219: $applies ++;
10220: }
10221: if ($numexisting) {
10222: $applies ++;
10223: }
1.1071 raeburn 10224: if ($counter || $numunused) {
1.987 raeburn 10225: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10226: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10227: $state.'<h3>'.$heading.'</h3>';
10228: if ($actionurl eq '/adm/dependencies') {
10229: if ($numnew) {
10230: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10231: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10232: $upload_output.'<br />'."\n";
10233: }
10234: if ($numexisting) {
10235: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10236: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10237: $modify_output.'<br />'."\n";
10238: $buttontext = &mt('Save changes');
10239: }
10240: if ($numunused) {
10241: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10242: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10243: $delete_output.'<br />'."\n";
10244: $buttontext = &mt('Save changes');
10245: }
10246: } else {
10247: $output .= $upload_output.'<br />'."\n";
10248: }
10249: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10250: $counter.'" />'."\n";
10251: if ($actionurl eq '/adm/dependencies') {
10252: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10253: $numnew.'" />'."\n";
10254: } elsif ($actionurl eq '') {
1.987 raeburn 10255: $output .= '<input type="hidden" name="phase" value="three" />';
10256: }
10257: } elsif ($applies) {
10258: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10259: if ($applies > 1) {
10260: $output .=
1.1123 raeburn 10261: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10262: if ($numremref) {
10263: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10264: }
10265: if ($numinvalid) {
10266: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10267: }
10268: if ($numexisting) {
10269: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10270: }
10271: $output .= '</ul><br />';
10272: } elsif ($numremref) {
10273: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10274: } elsif ($numinvalid) {
10275: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10276: } elsif ($numexisting) {
10277: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10278: }
10279: $output .= $upload_output.'<br />';
10280: }
10281: my ($pathchange_output,$chgcount);
1.1071 raeburn 10282: $chgcount = $counter;
1.987 raeburn 10283: if (keys(%pathchanges) > 0) {
10284: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10285: if ($counter) {
1.987 raeburn 10286: $output .= &embedded_file_element('pathchange',$chgcount,
10287: $embed_file,\%mapping,
1.1071 raeburn 10288: $allfiles,$codebase,'change');
1.987 raeburn 10289: } else {
10290: $pathchange_output .=
10291: &start_data_table_row().
10292: '<td><input type ="checkbox" name="namechange" value="'.
10293: $chgcount.'" checked="checked" /></td>'.
10294: '<td>'.$mapping{$embed_file}.'</td>'.
10295: '<td>'.$embed_file.
10296: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10297: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10298: '</td>'.&end_data_table_row();
1.660 raeburn 10299: }
1.987 raeburn 10300: $numpathchg ++;
10301: $chgcount ++;
1.660 raeburn 10302: }
10303: }
1.1127 raeburn 10304: if (($counter) || ($numunused)) {
1.987 raeburn 10305: if ($numpathchg) {
10306: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10307: $numpathchg.'" />'."\n";
10308: }
10309: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10310: ($actionurl eq '/adm/imsimport')) {
10311: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10312: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10313: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10314: } elsif ($actionurl eq '/adm/dependencies') {
10315: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10316: }
1.1123 raeburn 10317: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10318: } elsif ($numpathchg) {
10319: my %pathchange = ();
10320: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10321: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10322: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 10323: }
1.987 raeburn 10324: }
1.1071 raeburn 10325: return ($output,$counter,$numpathchg);
1.987 raeburn 10326: }
10327:
1.1147 raeburn 10328: =pod
10329:
10330: =item * clean_path($name)
10331:
10332: Performs clean-up of directories, subdirectories and filename in an
10333: embedded object, referenced in an HTML file which is being uploaded
10334: to a course or portfolio, where
10335: "Upload embedded images/multimedia files if HTML file" checkbox was
10336: checked.
10337:
10338: Clean-up is similar to replacements in lonnet::clean_filename()
10339: except each / between sub-directory and next level is preserved.
10340:
10341: =cut
10342:
10343: sub clean_path {
10344: my ($embed_file) = @_;
10345: $embed_file =~s{^/+}{};
10346: my @contents;
10347: if ($embed_file =~ m{/}) {
10348: @contents = split(/\//,$embed_file);
10349: } else {
10350: @contents = ($embed_file);
10351: }
10352: my $lastidx = scalar(@contents)-1;
10353: for (my $i=0; $i<=$lastidx; $i++) {
10354: $contents[$i]=~s{\\}{/}g;
10355: $contents[$i]=~s/\s+/\_/g;
10356: $contents[$i]=~s{[^/\w\.\-]}{}g;
10357: if ($i == $lastidx) {
10358: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10359: }
10360: }
10361: if ($lastidx > 0) {
10362: return join('/',@contents);
10363: } else {
10364: return $contents[0];
10365: }
10366: }
10367:
1.987 raeburn 10368: sub embedded_file_element {
1.1071 raeburn 10369: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10370: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10371: (ref($codebase) eq 'HASH'));
10372: my $output;
1.1071 raeburn 10373: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10374: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10375: }
10376: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10377: &escape($embed_file).'" />';
10378: unless (($context eq 'upload_embedded') &&
10379: ($mapping->{$embed_file} eq $embed_file)) {
10380: $output .='
10381: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10382: }
10383: my $attrib;
10384: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10385: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10386: }
10387: $output .=
10388: "\n\t\t".
10389: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10390: $attrib.'" />';
10391: if (exists($codebase->{$mapping->{$embed_file}})) {
10392: $output .=
10393: "\n\t\t".
10394: '<input name="codebase_'.$num.'" type="hidden" value="'.
10395: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10396: }
1.987 raeburn 10397: return $output;
1.660 raeburn 10398: }
10399:
1.1071 raeburn 10400: sub get_dependency_details {
10401: my ($currfile,$currsubfile,$embed_file) = @_;
10402: my ($size,$mtime,$showsize,$showmtime);
10403: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10404: if ($embed_file =~ m{/}) {
10405: my ($path,$fname) = split(/\//,$embed_file);
10406: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10407: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10408: }
10409: } else {
10410: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10411: ($size,$mtime) = @{$currfile->{$embed_file}};
10412: }
10413: }
10414: $showsize = $size/1024.0;
10415: $showsize = sprintf("%.1f",$showsize);
10416: if ($mtime > 0) {
10417: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10418: }
10419: }
10420: return ($showsize,$showmtime);
10421: }
10422:
10423: sub ask_embedded_js {
10424: return <<"END";
10425: <script type="text/javascript"">
10426: // <![CDATA[
10427: function toggleBrowse(counter) {
10428: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10429: var fileid = document.getElementById('embedded_item_'+counter);
10430: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10431: if (chkboxid.checked == true) {
10432: uploaddivid.style.display='block';
10433: } else {
10434: uploaddivid.style.display='none';
10435: fileid.value = '';
10436: }
10437: }
10438: // ]]>
10439: </script>
10440:
10441: END
10442: }
10443:
1.661 raeburn 10444: sub upload_embedded {
10445: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10446: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10447: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10448: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10449: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10450: my $orig_uploaded_filename =
10451: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10452: foreach my $type ('orig','ref','attrib','codebase') {
10453: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10454: $env{'form.embedded_'.$type.'_'.$i} =
10455: &unescape($env{'form.embedded_'.$type.'_'.$i});
10456: }
10457: }
1.661 raeburn 10458: my ($path,$fname) =
10459: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10460: # no path, whole string is fname
10461: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10462: $fname = &Apache::lonnet::clean_filename($fname);
10463: # See if there is anything left
10464: next if ($fname eq '');
10465:
10466: # Check if file already exists as a file or directory.
10467: my ($state,$msg);
10468: if ($context eq 'portfolio') {
10469: my $port_path = $dirpath;
10470: if ($group ne '') {
10471: $port_path = "groups/$group/$port_path";
10472: }
1.987 raeburn 10473: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10474: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10475: $dir_root,$port_path,$disk_quota,
10476: $current_disk_usage,$uname,$udom);
10477: if ($state eq 'will_exceed_quota'
1.984 raeburn 10478: || $state eq 'file_locked') {
1.661 raeburn 10479: $output .= $msg;
10480: next;
10481: }
10482: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10483: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10484: if ($state eq 'exists') {
10485: $output .= $msg;
10486: next;
10487: }
10488: }
10489: # Check if extension is valid
10490: if (($fname =~ /\.(\w+)$/) &&
10491: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 10492: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10493: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10494: next;
10495: } elsif (($fname =~ /\.(\w+)$/) &&
10496: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10497: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10498: next;
10499: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 10500: $output .= &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
1.661 raeburn 10501: next;
10502: }
10503: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 10504: my $subdir = $path;
10505: $subdir =~ s{/+$}{};
1.661 raeburn 10506: if ($context eq 'portfolio') {
1.984 raeburn 10507: my $result;
10508: if ($state eq 'existingfile') {
10509: $result=
10510: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 10511: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10512: } else {
1.984 raeburn 10513: $result=
10514: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10515: $dirpath.
1.1123 raeburn 10516: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10517: if ($result !~ m|^/uploaded/|) {
10518: $output .= '<span class="LC_error">'
10519: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10520: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10521: .'</span><br />';
10522: next;
10523: } else {
1.987 raeburn 10524: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10525: $path.$fname.'</span>').'<br />';
1.984 raeburn 10526: }
1.661 raeburn 10527: }
1.1123 raeburn 10528: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 10529: my $extendedsubdir = $dirpath.'/'.$subdir;
10530: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10531: my $result =
1.1126 raeburn 10532: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10533: if ($result !~ m|^/uploaded/|) {
10534: $output .= '<span class="LC_error">'
10535: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10536: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10537: .'</span><br />';
10538: next;
10539: } else {
10540: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10541: $path.$fname.'</span>').'<br />';
1.1125 raeburn 10542: if ($context eq 'syllabus') {
10543: &Apache::lonnet::make_public_indefinitely($result);
10544: }
1.987 raeburn 10545: }
1.661 raeburn 10546: } else {
10547: # Save the file
10548: my $target = $env{'form.embedded_item_'.$i};
10549: my $fullpath = $dir_root.$dirpath.'/'.$path;
10550: my $dest = $fullpath.$fname;
10551: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10552: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10553: my $count;
10554: my $filepath = $dir_root;
1.1027 raeburn 10555: foreach my $subdir (@parts) {
10556: $filepath .= "/$subdir";
10557: if (!-e $filepath) {
1.661 raeburn 10558: mkdir($filepath,0770);
10559: }
10560: }
10561: my $fh;
10562: if (!open($fh,'>'.$dest)) {
10563: &Apache::lonnet::logthis('Failed to create '.$dest);
10564: $output .= '<span class="LC_error">'.
1.1071 raeburn 10565: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10566: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10567: '</span><br />';
10568: } else {
10569: if (!print $fh $env{'form.embedded_item_'.$i}) {
10570: &Apache::lonnet::logthis('Failed to write to '.$dest);
10571: $output .= '<span class="LC_error">'.
1.1071 raeburn 10572: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10573: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10574: '</span><br />';
10575: } else {
1.987 raeburn 10576: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10577: $url.'</span>').'<br />';
10578: unless ($context eq 'testbank') {
10579: $footer .= &mt('View embedded file: [_1]',
10580: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10581: }
10582: }
10583: close($fh);
10584: }
10585: }
10586: if ($env{'form.embedded_ref_'.$i}) {
10587: $pathchange{$i} = 1;
10588: }
10589: }
10590: if ($output) {
10591: $output = '<p>'.$output.'</p>';
10592: }
10593: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10594: $returnflag = 'ok';
1.1071 raeburn 10595: my $numpathchgs = scalar(keys(%pathchange));
10596: if ($numpathchgs > 0) {
1.987 raeburn 10597: if ($context eq 'portfolio') {
10598: $output .= '<p>'.&mt('or').'</p>';
10599: } elsif ($context eq 'testbank') {
1.1071 raeburn 10600: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10601: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10602: $returnflag = 'modify_orightml';
10603: }
10604: }
1.1071 raeburn 10605: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10606: }
10607:
10608: sub modify_html_form {
10609: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10610: my $end = 0;
10611: my $modifyform;
10612: if ($context eq 'upload_embedded') {
10613: return unless (ref($pathchange) eq 'HASH');
10614: if ($env{'form.number_embedded_items'}) {
10615: $end += $env{'form.number_embedded_items'};
10616: }
10617: if ($env{'form.number_pathchange_items'}) {
10618: $end += $env{'form.number_pathchange_items'};
10619: }
10620: if ($end) {
10621: for (my $i=0; $i<$end; $i++) {
10622: if ($i < $env{'form.number_embedded_items'}) {
10623: next unless($pathchange->{$i});
10624: }
10625: $modifyform .=
10626: &start_data_table_row().
10627: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10628: 'checked="checked" /></td>'.
10629: '<td>'.$env{'form.embedded_ref_'.$i}.
10630: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10631: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10632: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10633: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10634: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10635: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10636: '<td>'.$env{'form.embedded_orig_'.$i}.
10637: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10638: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10639: &end_data_table_row();
1.1071 raeburn 10640: }
1.987 raeburn 10641: }
10642: } else {
10643: $modifyform = $pathchgtable;
10644: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10645: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10646: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10647: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10648: }
10649: }
10650: if ($modifyform) {
1.1071 raeburn 10651: if ($actionurl eq '/adm/dependencies') {
10652: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10653: }
1.987 raeburn 10654: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10655: '<p>'.&mt('Changes need to be made to the reference(s) used for one or more of the dependencies, if your HTML file is to work correctly:').'<ol>'."\n".
10656: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10657: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10658: '</ol></p>'."\n".'<p>'.
10659: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10660: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10661: &start_data_table()."\n".
10662: &start_data_table_header_row().
10663: '<th>'.&mt('Change?').'</th>'.
10664: '<th>'.&mt('Current reference').'</th>'.
10665: '<th>'.&mt('Required reference').'</th>'.
10666: &end_data_table_header_row()."\n".
10667: $modifyform.
10668: &end_data_table().'<br />'."\n".$hiddenstate.
10669: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10670: '</form>'."\n";
10671: }
10672: return;
10673: }
10674:
10675: sub modify_html_refs {
1.1123 raeburn 10676: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10677: my $container;
10678: if ($context eq 'portfolio') {
10679: $container = $env{'form.container'};
10680: } elsif ($context eq 'coursedoc') {
10681: $container = $env{'form.primaryurl'};
1.1071 raeburn 10682: } elsif ($context eq 'manage_dependencies') {
10683: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10684: $container = "/$container";
1.1123 raeburn 10685: } elsif ($context eq 'syllabus') {
10686: $container = $url;
1.987 raeburn 10687: } else {
1.1027 raeburn 10688: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10689: }
10690: my (%allfiles,%codebase,$output,$content);
10691: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 10692: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10693: if (wantarray) {
10694: return ('',0,0);
10695: } else {
10696: return;
10697: }
10698: }
10699: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 10700: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10701: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10702: if (wantarray) {
10703: return ('',0,0);
10704: } else {
10705: return;
10706: }
10707: }
1.987 raeburn 10708: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10709: if ($content eq '-1') {
10710: if (wantarray) {
10711: return ('',0,0);
10712: } else {
10713: return;
10714: }
10715: }
1.987 raeburn 10716: } else {
1.1071 raeburn 10717: unless ($container =~ /^\Q$dir_root\E/) {
10718: if (wantarray) {
10719: return ('',0,0);
10720: } else {
10721: return;
10722: }
10723: }
1.987 raeburn 10724: if (open(my $fh,"<$container")) {
10725: $content = join('', <$fh>);
10726: close($fh);
10727: } else {
1.1071 raeburn 10728: if (wantarray) {
10729: return ('',0,0);
10730: } else {
10731: return;
10732: }
1.987 raeburn 10733: }
10734: }
10735: my ($count,$codebasecount) = (0,0);
10736: my $mm = new File::MMagic;
10737: my $mime_type = $mm->checktype_contents($content);
10738: if ($mime_type eq 'text/html') {
10739: my $parse_result =
10740: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10741: \%codebase,\$content);
10742: if ($parse_result eq 'ok') {
10743: foreach my $i (@changes) {
10744: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10745: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10746: if ($allfiles{$ref}) {
10747: my $newname = $orig;
10748: my ($attrib_regexp,$codebase);
1.1006 raeburn 10749: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10750: if ($attrib_regexp =~ /:/) {
10751: $attrib_regexp =~ s/\:/|/g;
10752: }
10753: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10754: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10755: $count += $numchg;
1.1123 raeburn 10756: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 10757: delete($allfiles{$ref});
1.987 raeburn 10758: }
10759: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10760: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10761: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10762: $codebasecount ++;
10763: }
10764: }
10765: }
1.1123 raeburn 10766: my $skiprewrites;
1.987 raeburn 10767: if ($count || $codebasecount) {
10768: my $saveresult;
1.1071 raeburn 10769: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 10770: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10771: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10772: if ($url eq $container) {
10773: my ($fname) = ($container =~ m{/([^/]+)$});
10774: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10775: $count,'<span class="LC_filename">'.
1.1071 raeburn 10776: $fname.'</span>').'</p>';
1.987 raeburn 10777: } else {
10778: $output = '<p class="LC_error">'.
10779: &mt('Error: update failed for: [_1].',
10780: '<span class="LC_filename">'.
10781: $container.'</span>').'</p>';
10782: }
1.1123 raeburn 10783: if ($context eq 'syllabus') {
10784: unless ($saveresult eq 'ok') {
10785: $skiprewrites = 1;
10786: }
10787: }
1.987 raeburn 10788: } else {
10789: if (open(my $fh,">$container")) {
10790: print $fh $content;
10791: close($fh);
10792: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10793: $count,'<span class="LC_filename">'.
10794: $container.'</span>').'</p>';
1.661 raeburn 10795: } else {
1.987 raeburn 10796: $output = '<p class="LC_error">'.
10797: &mt('Error: could not update [_1].',
10798: '<span class="LC_filename">'.
10799: $container.'</span>').'</p>';
1.661 raeburn 10800: }
10801: }
10802: }
1.1123 raeburn 10803: if (($context eq 'syllabus') && (!$skiprewrites)) {
10804: my ($actionurl,$state);
10805: $actionurl = "/public/$udom/$uname/syllabus";
10806: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10807: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10808: \%codebase,
10809: {'context' => 'rewrites',
10810: 'ignore_remote_references' => 1,});
10811: if (ref($mapping) eq 'HASH') {
10812: my $rewrites = 0;
10813: foreach my $key (keys(%{$mapping})) {
10814: next if ($key =~ m{^https?://});
10815: my $ref = $mapping->{$key};
10816: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10817: my $attrib;
10818: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10819: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10820: }
10821: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10822: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10823: $rewrites += $numchg;
10824: }
10825: }
10826: if ($rewrites) {
10827: my $saveresult;
10828: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10829: if ($url eq $container) {
10830: my ($fname) = ($container =~ m{/([^/]+)$});
10831: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10832: $count,'<span class="LC_filename">'.
10833: $fname.'</span>').'</p>';
10834: } else {
10835: $output .= '<p class="LC_error">'.
10836: &mt('Error: could not update links in [_1].',
10837: '<span class="LC_filename">'.
10838: $container.'</span>').'</p>';
10839:
10840: }
10841: }
10842: }
10843: }
1.987 raeburn 10844: } else {
10845: &logthis('Failed to parse '.$container.
10846: ' to modify references: '.$parse_result);
1.661 raeburn 10847: }
10848: }
1.1071 raeburn 10849: if (wantarray) {
10850: return ($output,$count,$codebasecount);
10851: } else {
10852: return $output;
10853: }
1.661 raeburn 10854: }
10855:
10856: sub check_for_existing {
10857: my ($path,$fname,$element) = @_;
10858: my ($state,$msg);
10859: if (-d $path.'/'.$fname) {
10860: $state = 'exists';
10861: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10862: } elsif (-e $path.'/'.$fname) {
10863: $state = 'exists';
10864: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10865: }
10866: if ($state eq 'exists') {
10867: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10868: }
10869: return ($state,$msg);
10870: }
10871:
10872: sub check_for_upload {
10873: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10874: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10875: my $filesize = length($env{'form.'.$element});
10876: if (!$filesize) {
10877: my $msg = '<span class="LC_error">'.
10878: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10879: '<span class="LC_filename">'.$fname.'</span>',
10880: $filesize).'<br />'.
1.1007 raeburn 10881: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10882: '</span>';
10883: return ('zero_bytes',$msg);
10884: }
10885: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10886: my $getpropath = 1;
1.1021 raeburn 10887: my ($dirlistref,$listerror) =
10888: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10889: my $found_file = 0;
10890: my $locked_file = 0;
1.991 raeburn 10891: my @lockers;
10892: my $navmap;
10893: if ($env{'request.course.id'}) {
10894: $navmap = Apache::lonnavmaps::navmap->new();
10895: }
1.1021 raeburn 10896: if (ref($dirlistref) eq 'ARRAY') {
10897: foreach my $line (@{$dirlistref}) {
10898: my ($file_name,$rest)=split(/\&/,$line,2);
10899: if ($file_name eq $fname){
10900: $file_name = $path.$file_name;
10901: if ($group ne '') {
10902: $file_name = $group.$file_name;
10903: }
10904: $found_file = 1;
10905: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10906: foreach my $lock (@lockers) {
10907: if (ref($lock) eq 'ARRAY') {
10908: my ($symb,$crsid) = @{$lock};
10909: if ($crsid eq $env{'request.course.id'}) {
10910: if (ref($navmap)) {
10911: my $res = $navmap->getBySymb($symb);
10912: foreach my $part (@{$res->parts()}) {
10913: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10914: unless (($slot_status == $res->RESERVED) ||
10915: ($slot_status == $res->RESERVED_LOCATION)) {
10916: $locked_file = 1;
10917: }
1.991 raeburn 10918: }
1.1021 raeburn 10919: } else {
10920: $locked_file = 1;
1.991 raeburn 10921: }
10922: } else {
10923: $locked_file = 1;
10924: }
10925: }
1.1021 raeburn 10926: }
10927: } else {
10928: my @info = split(/\&/,$rest);
10929: my $currsize = $info[6]/1000;
10930: if ($currsize < $filesize) {
10931: my $extra = $filesize - $currsize;
10932: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 10933: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 10934: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.',
1.1179 bisitz 10935: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
10936: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10937: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 10938: return ('will_exceed_quota',$msg);
10939: }
1.984 raeburn 10940: }
10941: }
1.661 raeburn 10942: }
10943: }
10944: }
10945: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 10946: my $msg = '<p class="LC_warning">'.
10947: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 10948: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 10949: return ('will_exceed_quota',$msg);
10950: } elsif ($found_file) {
10951: if ($locked_file) {
1.1179 bisitz 10952: my $msg = '<p class="LC_warning">';
1.661 raeburn 10953: $msg .= &mt('Unable to upload [_1]. A locked file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>','<span class="LC_filename">'.$port_path.$env{'form.currentpath'}.'</span>');
1.1179 bisitz 10954: $msg .= '</p>';
1.661 raeburn 10955: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10956: return ('file_locked',$msg);
10957: } else {
1.1179 bisitz 10958: my $msg = '<p class="LC_error">';
1.984 raeburn 10959: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.1179 bisitz 10960: $msg .= '</p>';
1.984 raeburn 10961: return ('existingfile',$msg);
1.661 raeburn 10962: }
10963: }
10964: }
10965:
1.987 raeburn 10966: sub check_for_traversal {
10967: my ($path,$url,$toplevel) = @_;
10968: my @parts=split(/\//,$path);
10969: my $cleanpath;
10970: my $fullpath = $url;
10971: for (my $i=0;$i<@parts;$i++) {
10972: next if ($parts[$i] eq '.');
10973: if ($parts[$i] eq '..') {
10974: $fullpath =~ s{([^/]+/)$}{};
10975: } else {
10976: $fullpath .= $parts[$i].'/';
10977: }
10978: }
10979: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10980: $cleanpath = $1;
10981: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10982: my $curr_toprel = $1;
10983: my @parts = split(/\//,$curr_toprel);
10984: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10985: my @urlparts = split(/\//,$url_toprel);
10986: my $doubledots;
10987: my $startdiff = -1;
10988: for (my $i=0; $i<@urlparts; $i++) {
10989: if ($startdiff == -1) {
10990: unless ($urlparts[$i] eq $parts[$i]) {
10991: $startdiff = $i;
10992: $doubledots .= '../';
10993: }
10994: } else {
10995: $doubledots .= '../';
10996: }
10997: }
10998: if ($startdiff > -1) {
10999: $cleanpath = $doubledots;
11000: for (my $i=$startdiff; $i<@parts; $i++) {
11001: $cleanpath .= $parts[$i].'/';
11002: }
11003: }
11004: }
11005: $cleanpath =~ s{(/)$}{};
11006: return $cleanpath;
11007: }
1.31 albertel 11008:
1.1053 raeburn 11009: sub is_archive_file {
11010: my ($mimetype) = @_;
11011: if (($mimetype eq 'application/octet-stream') ||
11012: ($mimetype eq 'application/x-stuffit') ||
11013: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11014: return 1;
11015: }
11016: return;
11017: }
11018:
11019: sub decompress_form {
1.1065 raeburn 11020: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11021: my %lt = &Apache::lonlocal::texthash (
11022: this => 'This file is an archive file.',
1.1067 raeburn 11023: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11024: itsc => 'Its contents are as follows:',
1.1053 raeburn 11025: youm => 'You may wish to extract its contents.',
11026: extr => 'Extract contents',
1.1067 raeburn 11027: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11028: proa => 'Process automatically?',
1.1053 raeburn 11029: yes => 'Yes',
11030: no => 'No',
1.1067 raeburn 11031: fold => 'Title for folder containing movie',
11032: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11033: );
1.1065 raeburn 11034: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11035: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11036: my $info = &list_archive_contents($fileloc,\@paths);
11037: if (@paths) {
11038: foreach my $path (@paths) {
11039: $path =~ s{^/}{};
1.1067 raeburn 11040: if ($path =~ m{^([^/]+)/$}) {
11041: $topdir = $1;
11042: }
1.1065 raeburn 11043: if ($path =~ m{^([^/]+)/}) {
11044: $toplevel{$1} = $path;
11045: } else {
11046: $toplevel{$path} = $path;
11047: }
11048: }
11049: }
1.1067 raeburn 11050: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 11051: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11052: "$topdir/media/",
11053: "$topdir/media/$topdir.mp4",
11054: "$topdir/media/FirstFrame.png",
11055: "$topdir/media/player.swf",
11056: "$topdir/media/swfobject.js",
11057: "$topdir/media/expressInstall.swf");
1.1164 raeburn 11058: my @camtasia8 = ("$topdir/","$topdir/$topdir.html",
11059: "$topdir/$topdir.mp4",
11060: "$topdir/$topdir\_config.xml",
11061: "$topdir/$topdir\_controller.swf",
11062: "$topdir/$topdir\_embed.css",
11063: "$topdir/$topdir\_First_Frame.png",
11064: "$topdir/$topdir\_player.html",
11065: "$topdir/$topdir\_Thumbnails.png",
11066: "$topdir/playerProductInstall.swf",
11067: "$topdir/scripts/",
11068: "$topdir/scripts/config_xml.js",
11069: "$topdir/scripts/handlebars.js",
11070: "$topdir/scripts/jquery-1.7.1.min.js",
11071: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11072: "$topdir/scripts/modernizr.js",
11073: "$topdir/scripts/player-min.js",
11074: "$topdir/scripts/swfobject.js",
11075: "$topdir/skins/",
11076: "$topdir/skins/configuration_express.xml",
11077: "$topdir/skins/express_show/",
11078: "$topdir/skins/express_show/player-min.css",
11079: "$topdir/skins/express_show/spritesheet.png");
11080: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11081: if (@diffs == 0) {
1.1164 raeburn 11082: $is_camtasia = 6;
11083: } else {
11084: @diffs = &compare_arrays(\@paths,\@camtasia8);
11085: if (@diffs == 0) {
11086: $is_camtasia = 8;
11087: }
1.1067 raeburn 11088: }
11089: }
11090: my $output;
11091: if ($is_camtasia) {
11092: $output = <<"ENDCAM";
11093: <script type="text/javascript" language="Javascript">
11094: // <![CDATA[
11095:
11096: function camtasiaToggle() {
11097: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11098: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 11099: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11100:
11101: document.getElementById('camtasia_titles').style.display='block';
11102: } else {
11103: document.getElementById('camtasia_titles').style.display='none';
11104: }
11105: }
11106: }
11107: return;
11108: }
11109:
11110: // ]]>
11111: </script>
11112: <p>$lt{'camt'}</p>
11113: ENDCAM
1.1065 raeburn 11114: } else {
1.1067 raeburn 11115: $output = '<p>'.$lt{'this'};
11116: if ($info eq '') {
11117: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11118: } else {
11119: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11120: '<div><pre>'.$info.'</pre></div>';
11121: }
1.1065 raeburn 11122: }
1.1067 raeburn 11123: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11124: my $duplicates;
11125: my $num = 0;
11126: if (ref($dirlist) eq 'ARRAY') {
11127: foreach my $item (@{$dirlist}) {
11128: if (ref($item) eq 'ARRAY') {
11129: if (exists($toplevel{$item->[0]})) {
11130: $duplicates .=
11131: &start_data_table_row().
11132: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11133: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11134: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11135: 'value="1" />'.&mt('Yes').'</label>'.
11136: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11137: '<td>'.$item->[0].'</td>';
11138: if ($item->[2]) {
11139: $duplicates .= '<td>'.&mt('Directory').'</td>';
11140: } else {
11141: $duplicates .= '<td>'.&mt('File').'</td>';
11142: }
11143: $duplicates .= '<td>'.$item->[3].'</td>'.
11144: '<td>'.
11145: &Apache::lonlocal::locallocaltime($item->[4]).
11146: '</td>'.
11147: &end_data_table_row();
11148: $num ++;
11149: }
11150: }
11151: }
11152: }
11153: my $itemcount;
11154: if (@paths > 0) {
11155: $itemcount = scalar(@paths);
11156: } else {
11157: $itemcount = 1;
11158: }
1.1067 raeburn 11159: if ($is_camtasia) {
11160: $output .= $lt{'auto'}.'<br />'.
11161: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 11162: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11163: $lt{'yes'}.'</label> <label>'.
11164: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11165: $lt{'no'}.'</label></span><br />'.
11166: '<div id="camtasia_titles" style="display:block">'.
11167: &Apache::lonhtmlcommon::start_pick_box().
11168: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11169: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11170: &Apache::lonhtmlcommon::row_closure().
11171: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11172: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11173: &Apache::lonhtmlcommon::row_closure(1).
11174: &Apache::lonhtmlcommon::end_pick_box().
11175: '</div>';
11176: }
1.1065 raeburn 11177: $output .=
11178: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11179: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11180: "\n";
1.1065 raeburn 11181: if ($duplicates ne '') {
11182: $output .= '<p><span class="LC_warning">'.
11183: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11184: &start_data_table().
11185: &start_data_table_header_row().
11186: '<th>'.&mt('Overwrite?').'</th>'.
11187: '<th>'.&mt('Name').'</th>'.
11188: '<th>'.&mt('Type').'</th>'.
11189: '<th>'.&mt('Size').'</th>'.
11190: '<th>'.&mt('Last modified').'</th>'.
11191: &end_data_table_header_row().
11192: $duplicates.
11193: &end_data_table().
11194: '</p>';
11195: }
1.1067 raeburn 11196: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11197: if (ref($hiddenelements) eq 'HASH') {
11198: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11199: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11200: }
11201: }
11202: $output .= <<"END";
1.1067 raeburn 11203: <br />
1.1053 raeburn 11204: <input type="submit" name="decompress" value="$lt{'extr'}" />
11205: </form>
11206: $noextract
11207: END
11208: return $output;
11209: }
11210:
1.1065 raeburn 11211: sub decompression_utility {
11212: my ($program) = @_;
11213: my @utilities = ('tar','gunzip','bunzip2','unzip');
11214: my $location;
11215: if (grep(/^\Q$program\E$/,@utilities)) {
11216: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11217: '/usr/sbin/') {
11218: if (-x $dir.$program) {
11219: $location = $dir.$program;
11220: last;
11221: }
11222: }
11223: }
11224: return $location;
11225: }
11226:
11227: sub list_archive_contents {
11228: my ($file,$pathsref) = @_;
11229: my (@cmd,$output);
11230: my $needsregexp;
11231: if ($file =~ /\.zip$/) {
11232: @cmd = (&decompression_utility('unzip'),"-l");
11233: $needsregexp = 1;
11234: } elsif (($file =~ m/\.tar\.gz$/) ||
11235: ($file =~ /\.tgz$/)) {
11236: @cmd = (&decompression_utility('tar'),"-ztf");
11237: } elsif ($file =~ /\.tar\.bz2$/) {
11238: @cmd = (&decompression_utility('tar'),"-jtf");
11239: } elsif ($file =~ m|\.tar$|) {
11240: @cmd = (&decompression_utility('tar'),"-tf");
11241: }
11242: if (@cmd) {
11243: undef($!);
11244: undef($@);
11245: if (open(my $fh,"-|", @cmd, $file)) {
11246: while (my $line = <$fh>) {
11247: $output .= $line;
11248: chomp($line);
11249: my $item;
11250: if ($needsregexp) {
11251: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11252: } else {
11253: $item = $line;
11254: }
11255: if ($item ne '') {
11256: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11257: push(@{$pathsref},$item);
11258: }
11259: }
11260: }
11261: close($fh);
11262: }
11263: }
11264: return $output;
11265: }
11266:
1.1053 raeburn 11267: sub decompress_uploaded_file {
11268: my ($file,$dir) = @_;
11269: &Apache::lonnet::appenv({'cgi.file' => $file});
11270: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11271: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11272: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11273: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11274: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11275: my $decompressed = $env{'cgi.decompressed'};
11276: &Apache::lonnet::delenv('cgi.file');
11277: &Apache::lonnet::delenv('cgi.dir');
11278: &Apache::lonnet::delenv('cgi.decompressed');
11279: return ($decompressed,$result);
11280: }
11281:
1.1055 raeburn 11282: sub process_decompression {
11283: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11284: my ($dir,$error,$warning,$output);
1.1180 raeburn 11285: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 11286: $error = &mt('Filename not a supported archive file type.').
11287: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11288: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11289: } else {
11290: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11291: if ($docuhome eq 'no_host') {
11292: $error = &mt('Could not determine home server for course.');
11293: } else {
11294: my @ids=&Apache::lonnet::current_machine_ids();
11295: my $currdir = "$dir_root/$destination";
11296: if (grep(/^\Q$docuhome\E$/,@ids)) {
11297: $dir = &LONCAPA::propath($docudom,$docuname).
11298: "$dir_root/$destination";
11299: } else {
11300: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11301: "$dir_root/$docudom/$docuname/$destination";
11302: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11303: $error = &mt('Archive file not found.');
11304: }
11305: }
1.1065 raeburn 11306: my (@to_overwrite,@to_skip);
11307: if ($env{'form.archive_overwrite_total'} > 0) {
11308: my $total = $env{'form.archive_overwrite_total'};
11309: for (my $i=0; $i<$total; $i++) {
11310: if ($env{'form.archive_overwrite_'.$i} == 1) {
11311: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11312: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11313: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11314: }
11315: }
11316: }
11317: my $numskip = scalar(@to_skip);
11318: if (($numskip > 0) &&
11319: ($numskip == $env{'form.archive_itemcount'})) {
11320: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11321: } elsif ($dir eq '') {
1.1055 raeburn 11322: $error = &mt('Directory containing archive file unavailable.');
11323: } elsif (!$error) {
1.1065 raeburn 11324: my ($decompressed,$display);
11325: if ($numskip > 0) {
11326: my $tempdir = time.'_'.$$.int(rand(10000));
11327: mkdir("$dir/$tempdir",0755);
11328: system("mv $dir/$file $dir/$tempdir/$file");
11329: ($decompressed,$display) =
11330: &decompress_uploaded_file($file,"$dir/$tempdir");
11331: foreach my $item (@to_skip) {
11332: if (($item ne '') && ($item !~ /\.\./)) {
11333: if (-f "$dir/$tempdir/$item") {
11334: unlink("$dir/$tempdir/$item");
11335: } elsif (-d "$dir/$tempdir/$item") {
11336: system("rm -rf $dir/$tempdir/$item");
11337: }
11338: }
11339: }
11340: system("mv $dir/$tempdir/* $dir");
11341: rmdir("$dir/$tempdir");
11342: } else {
11343: ($decompressed,$display) =
11344: &decompress_uploaded_file($file,$dir);
11345: }
1.1055 raeburn 11346: if ($decompressed eq 'ok') {
1.1065 raeburn 11347: $output = '<p class="LC_info">'.
11348: &mt('Files extracted successfully from archive.').
11349: '</p>'."\n";
1.1055 raeburn 11350: my ($warning,$result,@contents);
11351: my ($newdirlistref,$newlisterror) =
11352: &Apache::lonnet::dirlist($currdir,$docudom,
11353: $docuname,1);
11354: my (%is_dir,%changes,@newitems);
11355: my $dirptr = 16384;
1.1065 raeburn 11356: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11357: foreach my $dir_line (@{$newdirlistref}) {
11358: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11359: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11360: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11361: push(@newitems,$item);
11362: if ($dirptr&$testdir) {
11363: $is_dir{$item} = 1;
11364: }
11365: $changes{$item} = 1;
11366: }
11367: }
11368: }
11369: if (keys(%changes) > 0) {
11370: foreach my $item (sort(@newitems)) {
11371: if ($changes{$item}) {
11372: push(@contents,$item);
11373: }
11374: }
11375: }
11376: if (@contents > 0) {
1.1067 raeburn 11377: my $wantform;
11378: unless ($env{'form.autoextract_camtasia'}) {
11379: $wantform = 1;
11380: }
1.1056 raeburn 11381: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11382: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11383: $currdir,\%is_dir,
11384: \%children,\%parent,
1.1056 raeburn 11385: \@contents,\%dirorder,
11386: \%titles,$wantform);
1.1055 raeburn 11387: if ($datatable ne '') {
11388: $output .= &archive_options_form('decompressed',$datatable,
11389: $count,$hiddenelem);
1.1065 raeburn 11390: my $startcount = 6;
1.1055 raeburn 11391: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11392: \%titles,\%children);
1.1055 raeburn 11393: }
1.1067 raeburn 11394: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 11395: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 11396: my %displayed;
11397: my $total = 1;
11398: $env{'form.archive_directory'} = [];
11399: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11400: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11401: $path =~ s{/$}{};
11402: my $item;
11403: if ($path ne '') {
11404: $item = "$path/$titles{$i}";
11405: } else {
11406: $item = $titles{$i};
11407: }
11408: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11409: if ($item eq $contents[0]) {
11410: push(@{$env{'form.archive_directory'}},$i);
11411: $env{'form.archive_'.$i} = 'display';
11412: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11413: $displayed{'folder'} = $i;
1.1164 raeburn 11414: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
11415: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 11416: $env{'form.archive_'.$i} = 'display';
11417: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11418: $displayed{'web'} = $i;
11419: } else {
1.1164 raeburn 11420: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
11421: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
11422: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 11423: push(@{$env{'form.archive_directory'}},$i);
11424: }
11425: $env{'form.archive_'.$i} = 'dependency';
11426: }
11427: $total ++;
11428: }
11429: for (my $i=1; $i<$total; $i++) {
11430: next if ($i == $displayed{'web'});
11431: next if ($i == $displayed{'folder'});
11432: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11433: }
11434: $env{'form.phase'} = 'decompress_cleanup';
11435: $env{'form.archivedelete'} = 1;
11436: $env{'form.archive_count'} = $total-1;
11437: $output .=
11438: &process_extracted_files('coursedocs',$docudom,
11439: $docuname,$destination,
11440: $dir_root,$hiddenelem);
11441: }
1.1055 raeburn 11442: } else {
11443: $warning = &mt('No new items extracted from archive file.');
11444: }
11445: } else {
11446: $output = $display;
11447: $error = &mt('An error occurred during extraction from the archive file.');
11448: }
11449: }
11450: }
11451: }
11452: if ($error) {
11453: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11454: $error.'</p>'."\n";
11455: }
11456: if ($warning) {
11457: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11458: }
11459: return $output;
11460: }
11461:
11462: sub get_extracted {
1.1056 raeburn 11463: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11464: $titles,$wantform) = @_;
1.1055 raeburn 11465: my $count = 0;
11466: my $depth = 0;
11467: my $datatable;
1.1056 raeburn 11468: my @hierarchy;
1.1055 raeburn 11469: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11470: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11471: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11472: foreach my $item (@{$contents}) {
11473: $count ++;
1.1056 raeburn 11474: @{$dirorder->{$count}} = @hierarchy;
11475: $titles->{$count} = $item;
1.1055 raeburn 11476: &archive_hierarchy($depth,$count,$parent,$children);
11477: if ($wantform) {
11478: $datatable .= &archive_row($is_dir->{$item},$item,
11479: $currdir,$depth,$count);
11480: }
11481: if ($is_dir->{$item}) {
11482: $depth ++;
1.1056 raeburn 11483: push(@hierarchy,$count);
11484: $parent->{$depth} = $count;
1.1055 raeburn 11485: $datatable .=
11486: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11487: \$depth,\$count,\@hierarchy,$dirorder,
11488: $children,$parent,$titles,$wantform);
1.1055 raeburn 11489: $depth --;
1.1056 raeburn 11490: pop(@hierarchy);
1.1055 raeburn 11491: }
11492: }
11493: return ($count,$datatable);
11494: }
11495:
11496: sub recurse_extracted_archive {
1.1056 raeburn 11497: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11498: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11499: my $result='';
1.1056 raeburn 11500: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11501: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11502: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11503: return $result;
11504: }
11505: my $dirptr = 16384;
11506: my ($newdirlistref,$newlisterror) =
11507: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11508: if (ref($newdirlistref) eq 'ARRAY') {
11509: foreach my $dir_line (@{$newdirlistref}) {
11510: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11511: unless ($item =~ /^\.+$/) {
11512: $$count ++;
1.1056 raeburn 11513: @{$dirorder->{$$count}} = @{$hierarchy};
11514: $titles->{$$count} = $item;
1.1055 raeburn 11515: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11516:
1.1055 raeburn 11517: my $is_dir;
11518: if ($dirptr&$testdir) {
11519: $is_dir = 1;
11520: }
11521: if ($wantform) {
11522: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11523: }
11524: if ($is_dir) {
11525: $$depth ++;
1.1056 raeburn 11526: push(@{$hierarchy},$$count);
11527: $parent->{$$depth} = $$count;
1.1055 raeburn 11528: $result .=
11529: &recurse_extracted_archive("$currdir/$item",$docudom,
11530: $docuname,$depth,$count,
1.1056 raeburn 11531: $hierarchy,$dirorder,$children,
11532: $parent,$titles,$wantform);
1.1055 raeburn 11533: $$depth --;
1.1056 raeburn 11534: pop(@{$hierarchy});
1.1055 raeburn 11535: }
11536: }
11537: }
11538: }
11539: return $result;
11540: }
11541:
11542: sub archive_hierarchy {
11543: my ($depth,$count,$parent,$children) =@_;
11544: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11545: if (exists($parent->{$depth})) {
11546: $children->{$parent->{$depth}} .= $count.':';
11547: }
11548: }
11549: return;
11550: }
11551:
11552: sub archive_row {
11553: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11554: my ($name) = ($item =~ m{([^/]+)$});
11555: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11556: 'display' => 'Add as file',
1.1055 raeburn 11557: 'dependency' => 'Include as dependency',
11558: 'discard' => 'Discard',
11559: );
11560: if ($is_dir) {
1.1059 raeburn 11561: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11562: }
1.1056 raeburn 11563: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11564: my $offset = 0;
1.1055 raeburn 11565: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11566: $offset ++;
1.1065 raeburn 11567: if ($action ne 'display') {
11568: $offset ++;
11569: }
1.1055 raeburn 11570: $output .= '<td><span class="LC_nobreak">'.
11571: '<label><input type="radio" name="archive_'.$count.
11572: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11573: my $text = $choices{$action};
11574: if ($is_dir) {
11575: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11576: if ($action eq 'display') {
1.1059 raeburn 11577: $text = &mt('Add as folder');
1.1055 raeburn 11578: }
1.1056 raeburn 11579: } else {
11580: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11581:
11582: }
11583: $output .= ' /> '.$choices{$action}.'</label></span>';
11584: if ($action eq 'dependency') {
11585: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11586: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11587: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11588: '<option value=""></option>'."\n".
11589: '</select>'."\n".
11590: '</div>';
1.1059 raeburn 11591: } elsif ($action eq 'display') {
11592: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11593: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11594: '</div>';
1.1055 raeburn 11595: }
1.1056 raeburn 11596: $output .= '</td>';
1.1055 raeburn 11597: }
11598: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11599: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11600: for (my $i=0; $i<$depth; $i++) {
11601: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11602: }
11603: if ($is_dir) {
11604: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11605: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11606: } else {
11607: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11608: }
11609: $output .= ' '.$name.'</td>'."\n".
11610: &end_data_table_row();
11611: return $output;
11612: }
11613:
11614: sub archive_options_form {
1.1065 raeburn 11615: my ($form,$display,$count,$hiddenelem) = @_;
11616: my %lt = &Apache::lonlocal::texthash(
11617: perm => 'Permanently remove archive file?',
11618: hows => 'How should each extracted item be incorporated in the course?',
11619: cont => 'Content actions for all',
11620: addf => 'Add as folder/file',
11621: incd => 'Include as dependency for a displayed file',
11622: disc => 'Discard',
11623: no => 'No',
11624: yes => 'Yes',
11625: save => 'Save',
11626: );
11627: my $output = <<"END";
11628: <form name="$form" method="post" action="">
11629: <p><span class="LC_nobreak">$lt{'perm'}
11630: <label>
11631: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11632: </label>
11633:
11634: <label>
11635: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11636: </span>
11637: </p>
11638: <input type="hidden" name="phase" value="decompress_cleanup" />
11639: <br />$lt{'hows'}
11640: <div class="LC_columnSection">
11641: <fieldset>
11642: <legend>$lt{'cont'}</legend>
11643: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11644: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11645: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11646: </fieldset>
11647: </div>
11648: END
11649: return $output.
1.1055 raeburn 11650: &start_data_table()."\n".
1.1065 raeburn 11651: $display."\n".
1.1055 raeburn 11652: &end_data_table()."\n".
11653: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11654: $hiddenelem.
1.1065 raeburn 11655: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11656: '</form>';
11657: }
11658:
11659: sub archive_javascript {
1.1056 raeburn 11660: my ($startcount,$numitems,$titles,$children) = @_;
11661: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11662: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11663: my $scripttag = <<START;
11664: <script type="text/javascript">
11665: // <![CDATA[
11666:
11667: function checkAll(form,prefix) {
11668: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11669: for (var i=0; i < form.elements.length; i++) {
11670: var id = form.elements[i].id;
11671: if ((id != '') && (id != undefined)) {
11672: if (idstr.test(id)) {
11673: if (form.elements[i].type == 'radio') {
11674: form.elements[i].checked = true;
1.1056 raeburn 11675: var nostart = i-$startcount;
1.1059 raeburn 11676: var offset = nostart%7;
11677: var count = (nostart-offset)/7;
1.1056 raeburn 11678: dependencyCheck(form,count,offset);
1.1055 raeburn 11679: }
11680: }
11681: }
11682: }
11683: }
11684:
11685: function propagateCheck(form,count) {
11686: if (count > 0) {
1.1059 raeburn 11687: var startelement = $startcount + ((count-1) * 7);
11688: for (var j=1; j<6; j++) {
11689: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11690: var item = startelement + j;
11691: if (form.elements[item].type == 'radio') {
11692: if (form.elements[item].checked) {
11693: containerCheck(form,count,j);
11694: break;
11695: }
1.1055 raeburn 11696: }
11697: }
11698: }
11699: }
11700: }
11701:
11702: numitems = $numitems
1.1056 raeburn 11703: var titles = new Array(numitems);
11704: var parents = new Array(numitems);
1.1055 raeburn 11705: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11706: parents[i] = new Array;
1.1055 raeburn 11707: }
1.1059 raeburn 11708: var maintitle = '$maintitle';
1.1055 raeburn 11709:
11710: START
11711:
1.1056 raeburn 11712: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11713: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11714: for (my $i=0; $i<@contents; $i ++) {
11715: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11716: }
11717: }
11718:
1.1056 raeburn 11719: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11720: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11721: }
11722:
1.1055 raeburn 11723: $scripttag .= <<END;
11724:
11725: function containerCheck(form,count,offset) {
11726: if (count > 0) {
1.1056 raeburn 11727: dependencyCheck(form,count,offset);
1.1059 raeburn 11728: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11729: form.elements[item].checked = true;
11730: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11731: if (parents[count].length > 0) {
11732: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11733: containerCheck(form,parents[count][j],offset);
11734: }
11735: }
11736: }
11737: }
11738: }
11739:
11740: function dependencyCheck(form,count,offset) {
11741: if (count > 0) {
1.1059 raeburn 11742: var chosen = (offset+$startcount)+7*(count-1);
11743: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11744: var currtype = form.elements[depitem].type;
11745: if (form.elements[chosen].value == 'dependency') {
11746: document.getElementById('arc_depon_'+count).style.display='block';
11747: form.elements[depitem].options.length = 0;
11748: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 11749: for (var i=1; i<=numitems; i++) {
11750: if (i == count) {
11751: continue;
11752: }
1.1059 raeburn 11753: var startelement = $startcount + (i-1) * 7;
11754: for (var j=1; j<6; j++) {
11755: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11756: var item = startelement + j;
11757: if (form.elements[item].type == 'radio') {
11758: if (form.elements[item].checked) {
11759: if (form.elements[item].value == 'display') {
11760: var n = form.elements[depitem].options.length;
11761: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11762: }
11763: }
11764: }
11765: }
11766: }
11767: }
11768: } else {
11769: document.getElementById('arc_depon_'+count).style.display='none';
11770: form.elements[depitem].options.length = 0;
11771: form.elements[depitem].options[0] = new Option('Select','',true,true);
11772: }
1.1059 raeburn 11773: titleCheck(form,count,offset);
1.1056 raeburn 11774: }
11775: }
11776:
11777: function propagateSelect(form,count,offset) {
11778: if (count > 0) {
1.1065 raeburn 11779: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11780: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11781: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11782: if (parents[count].length > 0) {
11783: for (var j=0; j<parents[count].length; j++) {
11784: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11785: }
11786: }
11787: }
11788: }
11789: }
1.1056 raeburn 11790:
11791: function containerSelect(form,count,offset,picked) {
11792: if (count > 0) {
1.1065 raeburn 11793: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11794: if (form.elements[item].type == 'radio') {
11795: if (form.elements[item].value == 'dependency') {
11796: if (form.elements[item+1].type == 'select-one') {
11797: for (var i=0; i<form.elements[item+1].options.length; i++) {
11798: if (form.elements[item+1].options[i].value == picked) {
11799: form.elements[item+1].selectedIndex = i;
11800: break;
11801: }
11802: }
11803: }
11804: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11805: if (parents[count].length > 0) {
11806: for (var j=0; j<parents[count].length; j++) {
11807: containerSelect(form,parents[count][j],offset,picked);
11808: }
11809: }
11810: }
11811: }
11812: }
11813: }
11814: }
11815:
1.1059 raeburn 11816: function titleCheck(form,count,offset) {
11817: if (count > 0) {
11818: var chosen = (offset+$startcount)+7*(count-1);
11819: var depitem = $startcount + ((count-1) * 7) + 2;
11820: var currtype = form.elements[depitem].type;
11821: if (form.elements[chosen].value == 'display') {
11822: document.getElementById('arc_title_'+count).style.display='block';
11823: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11824: document.getElementById('archive_title_'+count).value=maintitle;
11825: }
11826: } else {
11827: document.getElementById('arc_title_'+count).style.display='none';
11828: if (currtype == 'text') {
11829: document.getElementById('archive_title_'+count).value='';
11830: }
11831: }
11832: }
11833: return;
11834: }
11835:
1.1055 raeburn 11836: // ]]>
11837: </script>
11838: END
11839: return $scripttag;
11840: }
11841:
11842: sub process_extracted_files {
1.1067 raeburn 11843: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11844: my $numitems = $env{'form.archive_count'};
11845: return unless ($numitems);
11846: my @ids=&Apache::lonnet::current_machine_ids();
11847: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11848: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11849: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11850: if (grep(/^\Q$docuhome\E$/,@ids)) {
11851: $prefix = &LONCAPA::propath($docudom,$docuname);
11852: $pathtocheck = "$dir_root/$destination";
11853: $dir = $dir_root;
11854: $ishome = 1;
11855: } else {
11856: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11857: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11858: $dir = "$dir_root/$docudom/$docuname";
11859: }
11860: my $currdir = "$dir_root/$destination";
11861: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11862: if ($env{'form.folderpath'}) {
11863: my @items = split('&',$env{'form.folderpath'});
11864: $folders{'0'} = $items[-2];
1.1099 raeburn 11865: if ($env{'form.folderpath'} =~ /\:1$/) {
11866: $containers{'0'}='page';
11867: } else {
11868: $containers{'0'}='sequence';
11869: }
1.1055 raeburn 11870: }
11871: my @archdirs = &get_env_multiple('form.archive_directory');
11872: if ($numitems) {
11873: for (my $i=1; $i<=$numitems; $i++) {
11874: my $path = $env{'form.archive_content_'.$i};
11875: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11876: my $item = $1;
11877: $toplevelitems{$item} = $i;
11878: if (grep(/^\Q$i\E$/,@archdirs)) {
11879: $is_dir{$item} = 1;
11880: }
11881: }
11882: }
11883: }
1.1067 raeburn 11884: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11885: if (keys(%toplevelitems) > 0) {
11886: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11887: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11888: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11889: }
1.1066 raeburn 11890: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11891: if ($numitems) {
11892: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 11893: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11894: my $path = $env{'form.archive_content_'.$i};
11895: if ($path =~ /^\Q$pathtocheck\E/) {
11896: if ($env{'form.archive_'.$i} eq 'discard') {
11897: if ($prefix ne '' && $path ne '') {
11898: if (-e $prefix.$path) {
1.1066 raeburn 11899: if ((@archdirs > 0) &&
11900: (grep(/^\Q$i\E$/,@archdirs))) {
11901: $todeletedir{$prefix.$path} = 1;
11902: } else {
11903: $todelete{$prefix.$path} = 1;
11904: }
1.1055 raeburn 11905: }
11906: }
11907: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11908: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11909: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11910: $docstitle = $env{'form.archive_title_'.$i};
11911: if ($docstitle eq '') {
11912: $docstitle = $title;
11913: }
1.1055 raeburn 11914: $outer = 0;
1.1056 raeburn 11915: if (ref($dirorder{$i}) eq 'ARRAY') {
11916: if (@{$dirorder{$i}} > 0) {
11917: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11918: if ($env{'form.archive_'.$item} eq 'display') {
11919: $outer = $item;
11920: last;
11921: }
11922: }
11923: }
11924: }
11925: my ($errtext,$fatal) =
11926: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11927: '/'.$folders{$outer}.'.'.
11928: $containers{$outer});
11929: next if ($fatal);
11930: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11931: if ($context eq 'coursedocs') {
1.1056 raeburn 11932: $mapinner{$i} = time;
1.1055 raeburn 11933: $folders{$i} = 'default_'.$mapinner{$i};
11934: $containers{$i} = 'sequence';
11935: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11936: $folders{$i}.'.'.$containers{$i};
11937: my $newidx = &LONCAPA::map::getresidx();
11938: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11939: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11940: push(@LONCAPA::map::order,$newidx);
11941: my ($outtext,$errtext) =
11942: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11943: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11944: '.'.$containers{$outer},1,1);
1.1056 raeburn 11945: $newseqid{$i} = $newidx;
1.1067 raeburn 11946: unless ($errtext) {
11947: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11948: }
1.1055 raeburn 11949: }
11950: } else {
11951: if ($context eq 'coursedocs') {
11952: my $newidx=&LONCAPA::map::getresidx();
11953: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11954: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11955: $title;
11956: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11957: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11958: }
11959: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11960: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11961: }
11962: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11963: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11964: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11965: unless ($ishome) {
11966: my $fetch = "$newdest{$i}/$title";
11967: $fetch =~ s/^\Q$prefix$dir\E//;
11968: $prompttofetch{$fetch} = 1;
11969: }
1.1055 raeburn 11970: }
11971: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11972: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11973: push(@LONCAPA::map::order, $newidx);
11974: my ($outtext,$errtext)=
11975: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11976: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11977: '.'.$containers{$outer},1,1);
1.1067 raeburn 11978: unless ($errtext) {
11979: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11980: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11981: }
11982: }
1.1055 raeburn 11983: }
11984: }
1.1086 raeburn 11985: }
11986: } else {
11987: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11988: }
11989: }
11990: for (my $i=1; $i<=$numitems; $i++) {
11991: next unless ($env{'form.archive_'.$i} eq 'dependency');
11992: my $path = $env{'form.archive_content_'.$i};
11993: if ($path =~ /^\Q$pathtocheck\E/) {
11994: my ($title) = ($path =~ m{/([^/]+)$});
11995: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11996: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11997: if (ref($dirorder{$i}) eq 'ARRAY') {
11998: my ($itemidx,$fullpath,$relpath);
11999: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12000: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12001: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 12002: if ($dirorder{$i}->[$j] eq $container) {
12003: $itemidx = $j;
1.1056 raeburn 12004: }
12005: }
1.1086 raeburn 12006: }
12007: if ($itemidx eq '') {
12008: $itemidx = 0;
12009: }
12010: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12011: if ($mapinner{$referrer{$i}}) {
12012: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12013: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12014: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12015: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12016: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12017: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12018: if (!-e $fullpath) {
12019: mkdir($fullpath,0755);
1.1056 raeburn 12020: }
12021: }
1.1086 raeburn 12022: } else {
12023: last;
1.1056 raeburn 12024: }
1.1086 raeburn 12025: }
12026: }
12027: } elsif ($newdest{$referrer{$i}}) {
12028: $fullpath = $newdest{$referrer{$i}};
12029: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12030: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12031: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12032: last;
12033: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12034: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12035: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12036: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12037: if (!-e $fullpath) {
12038: mkdir($fullpath,0755);
1.1056 raeburn 12039: }
12040: }
1.1086 raeburn 12041: } else {
12042: last;
1.1056 raeburn 12043: }
1.1055 raeburn 12044: }
12045: }
1.1086 raeburn 12046: if ($fullpath ne '') {
12047: if (-e "$prefix$path") {
12048: system("mv $prefix$path $fullpath/$title");
12049: }
12050: if (-e "$fullpath/$title") {
12051: my $showpath;
12052: if ($relpath ne '') {
12053: $showpath = "$relpath/$title";
12054: } else {
12055: $showpath = "/$title";
12056: }
12057: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12058: }
12059: unless ($ishome) {
12060: my $fetch = "$fullpath/$title";
12061: $fetch =~ s/^\Q$prefix$dir\E//;
12062: $prompttofetch{$fetch} = 1;
12063: }
12064: }
1.1055 raeburn 12065: }
1.1086 raeburn 12066: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12067: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12068: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12069: }
12070: } else {
12071: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12072: }
12073: }
12074: if (keys(%todelete)) {
12075: foreach my $key (keys(%todelete)) {
12076: unlink($key);
1.1066 raeburn 12077: }
12078: }
12079: if (keys(%todeletedir)) {
12080: foreach my $key (keys(%todeletedir)) {
12081: rmdir($key);
12082: }
12083: }
12084: foreach my $dir (sort(keys(%is_dir))) {
12085: if (($pathtocheck ne '') && ($dir ne '')) {
12086: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12087: }
12088: }
1.1067 raeburn 12089: if ($result ne '') {
12090: $output .= '<ul>'."\n".
12091: $result."\n".
12092: '</ul>';
12093: }
12094: unless ($ishome) {
12095: my $replicationfail;
12096: foreach my $item (keys(%prompttofetch)) {
12097: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12098: unless ($fetchresult eq 'ok') {
12099: $replicationfail .= '<li>'.$item.'</li>'."\n";
12100: }
12101: }
12102: if ($replicationfail) {
12103: $output .= '<p class="LC_error">'.
12104: &mt('Course home server failed to retrieve:').'<ul>'.
12105: $replicationfail.
12106: '</ul></p>';
12107: }
12108: }
1.1055 raeburn 12109: } else {
12110: $warning = &mt('No items found in archive.');
12111: }
12112: if ($error) {
12113: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12114: $error.'</p>'."\n";
12115: }
12116: if ($warning) {
12117: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12118: }
12119: return $output;
12120: }
12121:
1.1066 raeburn 12122: sub cleanup_empty_dirs {
12123: my ($path) = @_;
12124: if (($path ne '') && (-d $path)) {
12125: if (opendir(my $dirh,$path)) {
12126: my @dircontents = grep(!/^\./,readdir($dirh));
12127: my $numitems = 0;
12128: foreach my $item (@dircontents) {
12129: if (-d "$path/$item") {
1.1111 raeburn 12130: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12131: if (-e "$path/$item") {
12132: $numitems ++;
12133: }
12134: } else {
12135: $numitems ++;
12136: }
12137: }
12138: if ($numitems == 0) {
12139: rmdir($path);
12140: }
12141: closedir($dirh);
12142: }
12143: }
12144: return;
12145: }
12146:
1.41 ng 12147: =pod
1.45 matthew 12148:
1.1162 raeburn 12149: =item * &get_folder_hierarchy()
1.1068 raeburn 12150:
12151: Provides hierarchy of names of folders/sub-folders containing the current
12152: item,
12153:
12154: Inputs: 3
12155: - $navmap - navmaps object
12156:
12157: - $map - url for map (either the trigger itself, or map containing
12158: the resource, which is the trigger).
12159:
12160: - $showitem - 1 => show title for map itself; 0 => do not show.
12161:
12162: Outputs: 1 @pathitems - array of folder/subfolder names.
12163:
12164: =cut
12165:
12166: sub get_folder_hierarchy {
12167: my ($navmap,$map,$showitem) = @_;
12168: my @pathitems;
12169: if (ref($navmap)) {
12170: my $mapres = $navmap->getResourceByUrl($map);
12171: if (ref($mapres)) {
12172: my $pcslist = $mapres->map_hierarchy();
12173: if ($pcslist ne '') {
12174: my @pcs = split(/,/,$pcslist);
12175: foreach my $pc (@pcs) {
12176: if ($pc == 1) {
1.1129 raeburn 12177: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12178: } else {
12179: my $res = $navmap->getByMapPc($pc);
12180: if (ref($res)) {
12181: my $title = $res->compTitle();
12182: $title =~ s/\W+/_/g;
12183: if ($title ne '') {
12184: push(@pathitems,$title);
12185: }
12186: }
12187: }
12188: }
12189: }
1.1071 raeburn 12190: if ($showitem) {
12191: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 12192: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12193: } else {
12194: my $maptitle = $mapres->compTitle();
12195: $maptitle =~ s/\W+/_/g;
12196: if ($maptitle ne '') {
12197: push(@pathitems,$maptitle);
12198: }
1.1068 raeburn 12199: }
12200: }
12201: }
12202: }
12203: return @pathitems;
12204: }
12205:
12206: =pod
12207:
1.1015 raeburn 12208: =item * &get_turnedin_filepath()
12209:
12210: Determines path in a user's portfolio file for storage of files uploaded
12211: to a specific essayresponse or dropbox item.
12212:
12213: Inputs: 3 required + 1 optional.
12214: $symb is symb for resource, $uname and $udom are for current user (required).
12215: $caller is optional (can be "submission", if routine is called when storing
12216: an upoaded file when "Submit Answer" button was pressed).
12217:
12218: Returns array containing $path and $multiresp.
12219: $path is path in portfolio. $multiresp is 1 if this resource contains more
12220: than one file upload item. Callers of routine should append partid as a
12221: subdirectory to $path in cases where $multiresp is 1.
12222:
12223: Called by: homework/essayresponse.pm and homework/structuretags.pm
12224:
12225: =cut
12226:
12227: sub get_turnedin_filepath {
12228: my ($symb,$uname,$udom,$caller) = @_;
12229: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12230: my $turnindir;
12231: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12232: $turnindir = $userhash{'turnindir'};
12233: my ($path,$multiresp);
12234: if ($turnindir eq '') {
12235: if ($caller eq 'submission') {
12236: $turnindir = &mt('turned in');
12237: $turnindir =~ s/\W+/_/g;
12238: my %newhash = (
12239: 'turnindir' => $turnindir,
12240: );
12241: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12242: }
12243: }
12244: if ($turnindir ne '') {
12245: $path = '/'.$turnindir.'/';
12246: my ($multipart,$turnin,@pathitems);
12247: my $navmap = Apache::lonnavmaps::navmap->new();
12248: if (defined($navmap)) {
12249: my $mapres = $navmap->getResourceByUrl($map);
12250: if (ref($mapres)) {
12251: my $pcslist = $mapres->map_hierarchy();
12252: if ($pcslist ne '') {
12253: foreach my $pc (split(/,/,$pcslist)) {
12254: my $res = $navmap->getByMapPc($pc);
12255: if (ref($res)) {
12256: my $title = $res->compTitle();
12257: $title =~ s/\W+/_/g;
12258: if ($title ne '') {
1.1149 raeburn 12259: if (($pc > 1) && (length($title) > 12)) {
12260: $title = substr($title,0,12);
12261: }
1.1015 raeburn 12262: push(@pathitems,$title);
12263: }
12264: }
12265: }
12266: }
12267: my $maptitle = $mapres->compTitle();
12268: $maptitle =~ s/\W+/_/g;
12269: if ($maptitle ne '') {
1.1149 raeburn 12270: if (length($maptitle) > 12) {
12271: $maptitle = substr($maptitle,0,12);
12272: }
1.1015 raeburn 12273: push(@pathitems,$maptitle);
12274: }
12275: unless ($env{'request.state'} eq 'construct') {
12276: my $res = $navmap->getBySymb($symb);
12277: if (ref($res)) {
12278: my $partlist = $res->parts();
12279: my $totaluploads = 0;
12280: if (ref($partlist) eq 'ARRAY') {
12281: foreach my $part (@{$partlist}) {
12282: my @types = $res->responseType($part);
12283: my @ids = $res->responseIds($part);
12284: for (my $i=0; $i < scalar(@ids); $i++) {
12285: if ($types[$i] eq 'essay') {
12286: my $partid = $part.'_'.$ids[$i];
12287: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12288: $totaluploads ++;
12289: }
12290: }
12291: }
12292: }
12293: if ($totaluploads > 1) {
12294: $multiresp = 1;
12295: }
12296: }
12297: }
12298: }
12299: } else {
12300: return;
12301: }
12302: } else {
12303: return;
12304: }
12305: my $restitle=&Apache::lonnet::gettitle($symb);
12306: $restitle =~ s/\W+/_/g;
12307: if ($restitle eq '') {
12308: $restitle = ($resurl =~ m{/[^/]+$});
12309: if ($restitle eq '') {
12310: $restitle = time;
12311: }
12312: }
1.1149 raeburn 12313: if (length($restitle) > 12) {
12314: $restitle = substr($restitle,0,12);
12315: }
1.1015 raeburn 12316: push(@pathitems,$restitle);
12317: $path .= join('/',@pathitems);
12318: }
12319: return ($path,$multiresp);
12320: }
12321:
12322: =pod
12323:
1.464 albertel 12324: =back
1.41 ng 12325:
1.112 bowersj2 12326: =head1 CSV Upload/Handling functions
1.38 albertel 12327:
1.41 ng 12328: =over 4
12329:
1.648 raeburn 12330: =item * &upfile_store($r)
1.41 ng 12331:
12332: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12333: needs $env{'form.upfile'}
1.41 ng 12334: returns $datatoken to be put into hidden field
12335:
12336: =cut
1.31 albertel 12337:
12338: sub upfile_store {
12339: my $r=shift;
1.258 albertel 12340: $env{'form.upfile'}=~s/\r/\n/gs;
12341: $env{'form.upfile'}=~s/\f/\n/gs;
12342: $env{'form.upfile'}=~s/\n+/\n/gs;
12343: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12344:
1.258 albertel 12345: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12346: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12347: {
1.158 raeburn 12348: my $datafile = $r->dir_config('lonDaemons').
12349: '/tmp/'.$datatoken.'.tmp';
12350: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12351: print $fh $env{'form.upfile'};
1.158 raeburn 12352: close($fh);
12353: }
1.31 albertel 12354: }
12355: return $datatoken;
12356: }
12357:
1.56 matthew 12358: =pod
12359:
1.648 raeburn 12360: =item * &load_tmp_file($r)
1.41 ng 12361:
12362: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12363: needs $env{'form.datatoken'},
12364: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12365:
12366: =cut
1.31 albertel 12367:
12368: sub load_tmp_file {
12369: my $r=shift;
12370: my @studentdata=();
12371: {
1.158 raeburn 12372: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12373: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12374: if ( open(my $fh,"<$studentfile") ) {
12375: @studentdata=<$fh>;
12376: close($fh);
12377: }
1.31 albertel 12378: }
1.258 albertel 12379: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12380: }
12381:
1.56 matthew 12382: =pod
12383:
1.648 raeburn 12384: =item * &upfile_record_sep()
1.41 ng 12385:
12386: Separate uploaded file into records
12387: returns array of records,
1.258 albertel 12388: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12389:
12390: =cut
1.31 albertel 12391:
12392: sub upfile_record_sep {
1.258 albertel 12393: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12394: } else {
1.248 albertel 12395: my @records;
1.258 albertel 12396: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12397: if ($line=~/^\s*$/) { next; }
12398: push(@records,$line);
12399: }
12400: return @records;
1.31 albertel 12401: }
12402: }
12403:
1.56 matthew 12404: =pod
12405:
1.648 raeburn 12406: =item * &record_sep($record)
1.41 ng 12407:
1.258 albertel 12408: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12409:
12410: =cut
12411:
1.263 www 12412: sub takeleft {
12413: my $index=shift;
12414: return substr('0000'.$index,-4,4);
12415: }
12416:
1.31 albertel 12417: sub record_sep {
12418: my $record=shift;
12419: my %components=();
1.258 albertel 12420: if ($env{'form.upfiletype'} eq 'xml') {
12421: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12422: my $i=0;
1.356 albertel 12423: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12424: $field=~s/^(\"|\')//;
12425: $field=~s/(\"|\')$//;
1.263 www 12426: $components{&takeleft($i)}=$field;
1.31 albertel 12427: $i++;
12428: }
1.258 albertel 12429: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12430: my $i=0;
1.356 albertel 12431: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12432: $field=~s/^(\"|\')//;
12433: $field=~s/(\"|\')$//;
1.263 www 12434: $components{&takeleft($i)}=$field;
1.31 albertel 12435: $i++;
12436: }
12437: } else {
1.561 www 12438: my $separator=',';
1.480 banghart 12439: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12440: $separator=';';
1.480 banghart 12441: }
1.31 albertel 12442: my $i=0;
1.561 www 12443: # the character we are looking for to indicate the end of a quote or a record
12444: my $looking_for=$separator;
12445: # do not add the characters to the fields
12446: my $ignore=0;
12447: # we just encountered a separator (or the beginning of the record)
12448: my $just_found_separator=1;
12449: # store the field we are working on here
12450: my $field='';
12451: # work our way through all characters in record
12452: foreach my $character ($record=~/(.)/g) {
12453: if ($character eq $looking_for) {
12454: if ($character ne $separator) {
12455: # Found the end of a quote, again looking for separator
12456: $looking_for=$separator;
12457: $ignore=1;
12458: } else {
12459: # Found a separator, store away what we got
12460: $components{&takeleft($i)}=$field;
12461: $i++;
12462: $just_found_separator=1;
12463: $ignore=0;
12464: $field='';
12465: }
12466: next;
12467: }
12468: # single or double quotation marks after a separator indicate beginning of a quote
12469: # we are now looking for the end of the quote and need to ignore separators
12470: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12471: $looking_for=$character;
12472: next;
12473: }
12474: # ignore would be true after we reached the end of a quote
12475: if ($ignore) { next; }
12476: if (($just_found_separator) && ($character=~/\s/)) { next; }
12477: $field.=$character;
12478: $just_found_separator=0;
1.31 albertel 12479: }
1.561 www 12480: # catch the very last entry, since we never encountered the separator
12481: $components{&takeleft($i)}=$field;
1.31 albertel 12482: }
12483: return %components;
12484: }
12485:
1.144 matthew 12486: ######################################################
12487: ######################################################
12488:
1.56 matthew 12489: =pod
12490:
1.648 raeburn 12491: =item * &upfile_select_html()
1.41 ng 12492:
1.144 matthew 12493: Return HTML code to select a file from the users machine and specify
12494: the file type.
1.41 ng 12495:
12496: =cut
12497:
1.144 matthew 12498: ######################################################
12499: ######################################################
1.31 albertel 12500: sub upfile_select_html {
1.144 matthew 12501: my %Types = (
12502: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12503: semisv => &mt('Semicolon separated values'),
1.144 matthew 12504: space => &mt('Space separated'),
12505: tab => &mt('Tabulator separated'),
12506: # xml => &mt('HTML/XML'),
12507: );
12508: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12509: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12510: foreach my $type (sort(keys(%Types))) {
12511: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12512: }
12513: $Str .= "</select>\n";
12514: return $Str;
1.31 albertel 12515: }
12516:
1.301 albertel 12517: sub get_samples {
12518: my ($records,$toget) = @_;
12519: my @samples=({});
12520: my $got=0;
12521: foreach my $rec (@$records) {
12522: my %temp = &record_sep($rec);
12523: if (! grep(/\S/, values(%temp))) { next; }
12524: if (%temp) {
12525: $samples[$got]=\%temp;
12526: $got++;
12527: if ($got == $toget) { last; }
12528: }
12529: }
12530: return \@samples;
12531: }
12532:
1.144 matthew 12533: ######################################################
12534: ######################################################
12535:
1.56 matthew 12536: =pod
12537:
1.648 raeburn 12538: =item * &csv_print_samples($r,$records)
1.41 ng 12539:
12540: Prints a table of sample values from each column uploaded $r is an
12541: Apache Request ref, $records is an arrayref from
12542: &Apache::loncommon::upfile_record_sep
12543:
12544: =cut
12545:
1.144 matthew 12546: ######################################################
12547: ######################################################
1.31 albertel 12548: sub csv_print_samples {
12549: my ($r,$records) = @_;
1.662 bisitz 12550: my $samples = &get_samples($records,5);
1.301 albertel 12551:
1.594 raeburn 12552: $r->print(&mt('Samples').'<br />'.&start_data_table().
12553: &start_data_table_header_row());
1.356 albertel 12554: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12555: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12556: $r->print(&end_data_table_header_row());
1.301 albertel 12557: foreach my $hash (@$samples) {
1.594 raeburn 12558: $r->print(&start_data_table_row());
1.356 albertel 12559: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12560: $r->print('<td>');
1.356 albertel 12561: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12562: $r->print('</td>');
12563: }
1.594 raeburn 12564: $r->print(&end_data_table_row());
1.31 albertel 12565: }
1.594 raeburn 12566: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12567: }
12568:
1.144 matthew 12569: ######################################################
12570: ######################################################
12571:
1.56 matthew 12572: =pod
12573:
1.648 raeburn 12574: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12575:
12576: Prints a table to create associations between values and table columns.
1.144 matthew 12577:
1.41 ng 12578: $r is an Apache Request ref,
12579: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12580: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12581:
12582: =cut
12583:
1.144 matthew 12584: ######################################################
12585: ######################################################
1.31 albertel 12586: sub csv_print_select_table {
12587: my ($r,$records,$d) = @_;
1.301 albertel 12588: my $i=0;
12589: my $samples = &get_samples($records,1);
1.144 matthew 12590: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12591: &start_data_table().&start_data_table_header_row().
1.144 matthew 12592: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12593: '<th>'.&mt('Column').'</th>'.
12594: &end_data_table_header_row()."\n");
1.356 albertel 12595: foreach my $array_ref (@$d) {
12596: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12597: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12598:
1.875 bisitz 12599: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12600: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12601: $r->print('<option value="none"></option>');
1.356 albertel 12602: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12603: $r->print('<option value="'.$sample.'"'.
12604: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12605: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12606: }
1.594 raeburn 12607: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12608: $i++;
12609: }
1.594 raeburn 12610: $r->print(&end_data_table());
1.31 albertel 12611: $i--;
12612: return $i;
12613: }
1.56 matthew 12614:
1.144 matthew 12615: ######################################################
12616: ######################################################
12617:
1.56 matthew 12618: =pod
1.31 albertel 12619:
1.648 raeburn 12620: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12621:
12622: Prints a table of sample values from the upload and can make associate samples to internal names.
12623:
12624: $r is an Apache Request ref,
12625: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12626: $d is an array of 2 element arrays (internal name, displayed name)
12627:
12628: =cut
12629:
1.144 matthew 12630: ######################################################
12631: ######################################################
1.31 albertel 12632: sub csv_samples_select_table {
12633: my ($r,$records,$d) = @_;
12634: my $i=0;
1.144 matthew 12635: #
1.662 bisitz 12636: my $max_samples = 5;
12637: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12638: $r->print(&start_data_table().
12639: &start_data_table_header_row().'<th>'.
12640: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12641: &end_data_table_header_row());
1.301 albertel 12642:
12643: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12644: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12645: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12646: foreach my $option (@$d) {
12647: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12648: $r->print('<option value="'.$value.'"'.
1.253 albertel 12649: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12650: $display.'</option>');
1.31 albertel 12651: }
12652: $r->print('</select></td><td>');
1.662 bisitz 12653: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12654: if (defined($samples->[$line]{$key})) {
12655: $r->print($samples->[$line]{$key}."<br />\n");
12656: }
12657: }
1.594 raeburn 12658: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12659: $i++;
12660: }
1.594 raeburn 12661: $r->print(&end_data_table());
1.31 albertel 12662: $i--;
12663: return($i);
1.115 matthew 12664: }
12665:
1.144 matthew 12666: ######################################################
12667: ######################################################
12668:
1.115 matthew 12669: =pod
12670:
1.648 raeburn 12671: =item * &clean_excel_name($name)
1.115 matthew 12672:
12673: Returns a replacement for $name which does not contain any illegal characters.
12674:
12675: =cut
12676:
1.144 matthew 12677: ######################################################
12678: ######################################################
1.115 matthew 12679: sub clean_excel_name {
12680: my ($name) = @_;
12681: $name =~ s/[:\*\?\/\\]//g;
12682: if (length($name) > 31) {
12683: $name = substr($name,0,31);
12684: }
12685: return $name;
1.25 albertel 12686: }
1.84 albertel 12687:
1.85 albertel 12688: =pod
12689:
1.648 raeburn 12690: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12691:
12692: Returns either 1 or undef
12693:
12694: 1 if the part is to be hidden, undef if it is to be shown
12695:
12696: Arguments are:
12697:
12698: $id the id of the part to be checked
12699: $symb, optional the symb of the resource to check
12700: $udom, optional the domain of the user to check for
12701: $uname, optional the username of the user to check for
12702:
12703: =cut
1.84 albertel 12704:
12705: sub check_if_partid_hidden {
12706: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12707: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12708: $symb,$udom,$uname);
1.141 albertel 12709: my $truth=1;
12710: #if the string starts with !, then the list is the list to show not hide
12711: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12712: my @hiddenlist=split(/,/,$hiddenparts);
12713: foreach my $checkid (@hiddenlist) {
1.141 albertel 12714: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12715: }
1.141 albertel 12716: return !$truth;
1.84 albertel 12717: }
1.127 matthew 12718:
1.138 matthew 12719:
12720: ############################################################
12721: ############################################################
12722:
12723: =pod
12724:
1.157 matthew 12725: =back
12726:
1.138 matthew 12727: =head1 cgi-bin script and graphing routines
12728:
1.157 matthew 12729: =over 4
12730:
1.648 raeburn 12731: =item * &get_cgi_id()
1.138 matthew 12732:
12733: Inputs: none
12734:
12735: Returns an id which can be used to pass environment variables
12736: to various cgi-bin scripts. These environment variables will
12737: be removed from the users environment after a given time by
12738: the routine &Apache::lonnet::transfer_profile_to_env.
12739:
12740: =cut
12741:
12742: ############################################################
12743: ############################################################
1.152 albertel 12744: my $uniq=0;
1.136 matthew 12745: sub get_cgi_id {
1.154 albertel 12746: $uniq=($uniq+1)%100000;
1.280 albertel 12747: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12748: }
12749:
1.127 matthew 12750: ############################################################
12751: ############################################################
12752:
12753: =pod
12754:
1.648 raeburn 12755: =item * &DrawBarGraph()
1.127 matthew 12756:
1.138 matthew 12757: Facilitates the plotting of data in a (stacked) bar graph.
12758: Puts plot definition data into the users environment in order for
12759: graph.png to plot it. Returns an <img> tag for the plot.
12760: The bars on the plot are labeled '1','2',...,'n'.
12761:
12762: Inputs:
12763:
12764: =over 4
12765:
12766: =item $Title: string, the title of the plot
12767:
12768: =item $xlabel: string, text describing the X-axis of the plot
12769:
12770: =item $ylabel: string, text describing the Y-axis of the plot
12771:
12772: =item $Max: scalar, the maximum Y value to use in the plot
12773: If $Max is < any data point, the graph will not be rendered.
12774:
1.140 matthew 12775: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12776: they are plotted. If undefined, default values will be used.
12777:
1.178 matthew 12778: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12779:
1.138 matthew 12780: =item @Values: An array of array references. Each array reference holds data
12781: to be plotted in a stacked bar chart.
12782:
1.239 matthew 12783: =item If the final element of @Values is a hash reference the key/value
12784: pairs will be added to the graph definition.
12785:
1.138 matthew 12786: =back
12787:
12788: Returns:
12789:
12790: An <img> tag which references graph.png and the appropriate identifying
12791: information for the plot.
12792:
1.127 matthew 12793: =cut
12794:
12795: ############################################################
12796: ############################################################
1.134 matthew 12797: sub DrawBarGraph {
1.178 matthew 12798: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12799: #
12800: if (! defined($colors)) {
12801: $colors = ['#33ff00',
12802: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12803: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12804: ];
12805: }
1.228 matthew 12806: my $extra_settings = {};
12807: if (ref($Values[-1]) eq 'HASH') {
12808: $extra_settings = pop(@Values);
12809: }
1.127 matthew 12810: #
1.136 matthew 12811: my $identifier = &get_cgi_id();
12812: my $id = 'cgi.'.$identifier;
1.129 matthew 12813: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12814: return '';
12815: }
1.225 matthew 12816: #
12817: my @Labels;
12818: if (defined($labels)) {
12819: @Labels = @$labels;
12820: } else {
12821: for (my $i=0;$i<@{$Values[0]};$i++) {
12822: push (@Labels,$i+1);
12823: }
12824: }
12825: #
1.129 matthew 12826: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12827: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12828: my %ValuesHash;
12829: my $NumSets=1;
12830: foreach my $array (@Values) {
12831: next if (! ref($array));
1.136 matthew 12832: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12833: join(',',@$array);
1.129 matthew 12834: }
1.127 matthew 12835: #
1.136 matthew 12836: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12837: if ($NumBars < 3) {
12838: $width = 120+$NumBars*32;
1.220 matthew 12839: $xskip = 1;
1.225 matthew 12840: $bar_width = 30;
12841: } elsif ($NumBars < 5) {
12842: $width = 120+$NumBars*20;
12843: $xskip = 1;
12844: $bar_width = 20;
1.220 matthew 12845: } elsif ($NumBars < 10) {
1.136 matthew 12846: $width = 120+$NumBars*15;
12847: $xskip = 1;
12848: $bar_width = 15;
12849: } elsif ($NumBars <= 25) {
12850: $width = 120+$NumBars*11;
12851: $xskip = 5;
12852: $bar_width = 8;
12853: } elsif ($NumBars <= 50) {
12854: $width = 120+$NumBars*8;
12855: $xskip = 5;
12856: $bar_width = 4;
12857: } else {
12858: $width = 120+$NumBars*8;
12859: $xskip = 5;
12860: $bar_width = 4;
12861: }
12862: #
1.137 matthew 12863: $Max = 1 if ($Max < 1);
12864: if ( int($Max) < $Max ) {
12865: $Max++;
12866: $Max = int($Max);
12867: }
1.127 matthew 12868: $Title = '' if (! defined($Title));
12869: $xlabel = '' if (! defined($xlabel));
12870: $ylabel = '' if (! defined($ylabel));
1.369 www 12871: $ValuesHash{$id.'.title'} = &escape($Title);
12872: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12873: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12874: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12875: $ValuesHash{$id.'.NumBars'} = $NumBars;
12876: $ValuesHash{$id.'.NumSets'} = $NumSets;
12877: $ValuesHash{$id.'.PlotType'} = 'bar';
12878: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12879: $ValuesHash{$id.'.height'} = $height;
12880: $ValuesHash{$id.'.width'} = $width;
12881: $ValuesHash{$id.'.xskip'} = $xskip;
12882: $ValuesHash{$id.'.bar_width'} = $bar_width;
12883: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12884: #
1.228 matthew 12885: # Deal with other parameters
12886: while (my ($key,$value) = each(%$extra_settings)) {
12887: $ValuesHash{$id.'.'.$key} = $value;
12888: }
12889: #
1.646 raeburn 12890: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12891: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12892: }
12893:
12894: ############################################################
12895: ############################################################
12896:
12897: =pod
12898:
1.648 raeburn 12899: =item * &DrawXYGraph()
1.137 matthew 12900:
1.138 matthew 12901: Facilitates the plotting of data in an XY graph.
12902: Puts plot definition data into the users environment in order for
12903: graph.png to plot it. Returns an <img> tag for the plot.
12904:
12905: Inputs:
12906:
12907: =over 4
12908:
12909: =item $Title: string, the title of the plot
12910:
12911: =item $xlabel: string, text describing the X-axis of the plot
12912:
12913: =item $ylabel: string, text describing the Y-axis of the plot
12914:
12915: =item $Max: scalar, the maximum Y value to use in the plot
12916: If $Max is < any data point, the graph will not be rendered.
12917:
12918: =item $colors: Array ref containing the hex color codes for the data to be
12919: plotted in. If undefined, default values will be used.
12920:
12921: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12922:
12923: =item $Ydata: Array ref containing Array refs.
1.185 www 12924: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12925:
12926: =item %Values: hash indicating or overriding any default values which are
12927: passed to graph.png.
12928: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12929:
12930: =back
12931:
12932: Returns:
12933:
12934: An <img> tag which references graph.png and the appropriate identifying
12935: information for the plot.
12936:
1.137 matthew 12937: =cut
12938:
12939: ############################################################
12940: ############################################################
12941: sub DrawXYGraph {
12942: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12943: #
12944: # Create the identifier for the graph
12945: my $identifier = &get_cgi_id();
12946: my $id = 'cgi.'.$identifier;
12947: #
12948: $Title = '' if (! defined($Title));
12949: $xlabel = '' if (! defined($xlabel));
12950: $ylabel = '' if (! defined($ylabel));
12951: my %ValuesHash =
12952: (
1.369 www 12953: $id.'.title' => &escape($Title),
12954: $id.'.xlabel' => &escape($xlabel),
12955: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12956: $id.'.y_max_value'=> $Max,
12957: $id.'.labels' => join(',',@$Xlabels),
12958: $id.'.PlotType' => 'XY',
12959: );
12960: #
12961: if (defined($colors) && ref($colors) eq 'ARRAY') {
12962: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12963: }
12964: #
12965: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12966: return '';
12967: }
12968: my $NumSets=1;
1.138 matthew 12969: foreach my $array (@{$Ydata}){
1.137 matthew 12970: next if (! ref($array));
12971: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12972: }
1.138 matthew 12973: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12974: #
12975: # Deal with other parameters
12976: while (my ($key,$value) = each(%Values)) {
12977: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12978: }
12979: #
1.646 raeburn 12980: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12981: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12982: }
12983:
12984: ############################################################
12985: ############################################################
12986:
12987: =pod
12988:
1.648 raeburn 12989: =item * &DrawXYYGraph()
1.138 matthew 12990:
12991: Facilitates the plotting of data in an XY graph with two Y axes.
12992: Puts plot definition data into the users environment in order for
12993: graph.png to plot it. Returns an <img> tag for the plot.
12994:
12995: Inputs:
12996:
12997: =over 4
12998:
12999: =item $Title: string, the title of the plot
13000:
13001: =item $xlabel: string, text describing the X-axis of the plot
13002:
13003: =item $ylabel: string, text describing the Y-axis of the plot
13004:
13005: =item $colors: Array ref containing the hex color codes for the data to be
13006: plotted in. If undefined, default values will be used.
13007:
13008: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13009:
13010: =item $Ydata1: The first data set
13011:
13012: =item $Min1: The minimum value of the left Y-axis
13013:
13014: =item $Max1: The maximum value of the left Y-axis
13015:
13016: =item $Ydata2: The second data set
13017:
13018: =item $Min2: The minimum value of the right Y-axis
13019:
13020: =item $Max2: The maximum value of the left Y-axis
13021:
13022: =item %Values: hash indicating or overriding any default values which are
13023: passed to graph.png.
13024: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13025:
13026: =back
13027:
13028: Returns:
13029:
13030: An <img> tag which references graph.png and the appropriate identifying
13031: information for the plot.
1.136 matthew 13032:
13033: =cut
13034:
13035: ############################################################
13036: ############################################################
1.137 matthew 13037: sub DrawXYYGraph {
13038: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13039: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13040: #
13041: # Create the identifier for the graph
13042: my $identifier = &get_cgi_id();
13043: my $id = 'cgi.'.$identifier;
13044: #
13045: $Title = '' if (! defined($Title));
13046: $xlabel = '' if (! defined($xlabel));
13047: $ylabel = '' if (! defined($ylabel));
13048: my %ValuesHash =
13049: (
1.369 www 13050: $id.'.title' => &escape($Title),
13051: $id.'.xlabel' => &escape($xlabel),
13052: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13053: $id.'.labels' => join(',',@$Xlabels),
13054: $id.'.PlotType' => 'XY',
13055: $id.'.NumSets' => 2,
1.137 matthew 13056: $id.'.two_axes' => 1,
13057: $id.'.y1_max_value' => $Max1,
13058: $id.'.y1_min_value' => $Min1,
13059: $id.'.y2_max_value' => $Max2,
13060: $id.'.y2_min_value' => $Min2,
1.136 matthew 13061: );
13062: #
1.137 matthew 13063: if (defined($colors) && ref($colors) eq 'ARRAY') {
13064: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13065: }
13066: #
13067: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13068: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13069: return '';
13070: }
13071: my $NumSets=1;
1.137 matthew 13072: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13073: next if (! ref($array));
13074: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13075: }
13076: #
13077: # Deal with other parameters
13078: while (my ($key,$value) = each(%Values)) {
13079: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13080: }
13081: #
1.646 raeburn 13082: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13083: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13084: }
13085:
13086: ############################################################
13087: ############################################################
13088:
13089: =pod
13090:
1.157 matthew 13091: =back
13092:
1.139 matthew 13093: =head1 Statistics helper routines?
13094:
13095: Bad place for them but what the hell.
13096:
1.157 matthew 13097: =over 4
13098:
1.648 raeburn 13099: =item * &chartlink()
1.139 matthew 13100:
13101: Returns a link to the chart for a specific student.
13102:
13103: Inputs:
13104:
13105: =over 4
13106:
13107: =item $linktext: The text of the link
13108:
13109: =item $sname: The students username
13110:
13111: =item $sdomain: The students domain
13112:
13113: =back
13114:
1.157 matthew 13115: =back
13116:
1.139 matthew 13117: =cut
13118:
13119: ############################################################
13120: ############################################################
13121: sub chartlink {
13122: my ($linktext, $sname, $sdomain) = @_;
13123: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13124: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13125: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13126: '">'.$linktext.'</a>';
1.153 matthew 13127: }
13128:
13129: #######################################################
13130: #######################################################
13131:
13132: =pod
13133:
13134: =head1 Course Environment Routines
1.157 matthew 13135:
13136: =over 4
1.153 matthew 13137:
1.648 raeburn 13138: =item * &restore_course_settings()
1.153 matthew 13139:
1.648 raeburn 13140: =item * &store_course_settings()
1.153 matthew 13141:
13142: Restores/Store indicated form parameters from the course environment.
13143: Will not overwrite existing values of the form parameters.
13144:
13145: Inputs:
13146: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13147:
13148: a hash ref describing the data to be stored. For example:
13149:
13150: %Save_Parameters = ('Status' => 'scalar',
13151: 'chartoutputmode' => 'scalar',
13152: 'chartoutputdata' => 'scalar',
13153: 'Section' => 'array',
1.373 raeburn 13154: 'Group' => 'array',
1.153 matthew 13155: 'StudentData' => 'array',
13156: 'Maps' => 'array');
13157:
13158: Returns: both routines return nothing
13159:
1.631 raeburn 13160: =back
13161:
1.153 matthew 13162: =cut
13163:
13164: #######################################################
13165: #######################################################
13166: sub store_course_settings {
1.496 albertel 13167: return &store_settings($env{'request.course.id'},@_);
13168: }
13169:
13170: sub store_settings {
1.153 matthew 13171: # save to the environment
13172: # appenv the same items, just to be safe
1.300 albertel 13173: my $udom = $env{'user.domain'};
13174: my $uname = $env{'user.name'};
1.496 albertel 13175: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13176: my %SaveHash;
13177: my %AppHash;
13178: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13179: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13180: my $envname = 'environment.'.$basename;
1.258 albertel 13181: if (exists($env{'form.'.$setting})) {
1.153 matthew 13182: # Save this value away
13183: if ($type eq 'scalar' &&
1.258 albertel 13184: (! exists($env{$envname}) ||
13185: $env{$envname} ne $env{'form.'.$setting})) {
13186: $SaveHash{$basename} = $env{'form.'.$setting};
13187: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13188: } elsif ($type eq 'array') {
13189: my $stored_form;
1.258 albertel 13190: if (ref($env{'form.'.$setting})) {
1.153 matthew 13191: $stored_form = join(',',
13192: map {
1.369 www 13193: &escape($_);
1.258 albertel 13194: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13195: } else {
13196: $stored_form =
1.369 www 13197: &escape($env{'form.'.$setting});
1.153 matthew 13198: }
13199: # Determine if the array contents are the same.
1.258 albertel 13200: if ($stored_form ne $env{$envname}) {
1.153 matthew 13201: $SaveHash{$basename} = $stored_form;
13202: $AppHash{$envname} = $stored_form;
13203: }
13204: }
13205: }
13206: }
13207: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13208: $udom,$uname);
1.153 matthew 13209: if ($put_result !~ /^(ok|delayed)/) {
13210: &Apache::lonnet::logthis('unable to save form parameters, '.
13211: 'got error:'.$put_result);
13212: }
13213: # Make sure these settings stick around in this session, too
1.646 raeburn 13214: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13215: return;
13216: }
13217:
13218: sub restore_course_settings {
1.499 albertel 13219: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13220: }
13221:
13222: sub restore_settings {
13223: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13224: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13225: next if (exists($env{'form.'.$setting}));
1.496 albertel 13226: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13227: '.'.$setting;
1.258 albertel 13228: if (exists($env{$envname})) {
1.153 matthew 13229: if ($type eq 'scalar') {
1.258 albertel 13230: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13231: } elsif ($type eq 'array') {
1.258 albertel 13232: $env{'form.'.$setting} = [
1.153 matthew 13233: map {
1.369 www 13234: &unescape($_);
1.258 albertel 13235: } split(',',$env{$envname})
1.153 matthew 13236: ];
13237: }
13238: }
13239: }
1.127 matthew 13240: }
13241:
1.618 raeburn 13242: #######################################################
13243: #######################################################
13244:
13245: =pod
13246:
13247: =head1 Domain E-mail Routines
13248:
13249: =over 4
13250:
1.648 raeburn 13251: =item * &build_recipient_list()
1.618 raeburn 13252:
1.1144 raeburn 13253: Build recipient lists for following types of e-mail:
1.766 raeburn 13254: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 13255: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13256: module change checking, student/employee ID conflict checks, as
13257: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13258: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13259:
13260: Inputs:
1.619 raeburn 13261: defmail (scalar - email address of default recipient),
1.1144 raeburn 13262: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13263: requestsmail, updatesmail, or idconflictsmail).
13264:
1.619 raeburn 13265: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 13266:
1.619 raeburn 13267: origmail (scalar - email address of recipient from loncapa.conf,
13268: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13269:
1.655 raeburn 13270: Returns: comma separated list of addresses to which to send e-mail.
13271:
13272: =back
1.618 raeburn 13273:
13274: =cut
13275:
13276: ############################################################
13277: ############################################################
13278: sub build_recipient_list {
1.619 raeburn 13279: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13280: my @recipients;
13281: my $otheremails;
13282: my %domconfig =
13283: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13284: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13285: if (exists($domconfig{'contacts'}{$mailing})) {
13286: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13287: my @contacts = ('adminemail','supportemail');
13288: foreach my $item (@contacts) {
13289: if ($domconfig{'contacts'}{$mailing}{$item}) {
13290: my $addr = $domconfig{'contacts'}{$item};
13291: if (!grep(/^\Q$addr\E$/,@recipients)) {
13292: push(@recipients,$addr);
13293: }
1.619 raeburn 13294: }
1.766 raeburn 13295: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13296: }
13297: }
1.766 raeburn 13298: } elsif ($origmail ne '') {
13299: push(@recipients,$origmail);
1.618 raeburn 13300: }
1.619 raeburn 13301: } elsif ($origmail ne '') {
13302: push(@recipients,$origmail);
1.618 raeburn 13303: }
1.688 raeburn 13304: if (defined($defmail)) {
13305: if ($defmail ne '') {
13306: push(@recipients,$defmail);
13307: }
1.618 raeburn 13308: }
13309: if ($otheremails) {
1.619 raeburn 13310: my @others;
13311: if ($otheremails =~ /,/) {
13312: @others = split(/,/,$otheremails);
1.618 raeburn 13313: } else {
1.619 raeburn 13314: push(@others,$otheremails);
13315: }
13316: foreach my $addr (@others) {
13317: if (!grep(/^\Q$addr\E$/,@recipients)) {
13318: push(@recipients,$addr);
13319: }
1.618 raeburn 13320: }
13321: }
1.619 raeburn 13322: my $recipientlist = join(',',@recipients);
1.618 raeburn 13323: return $recipientlist;
13324: }
13325:
1.127 matthew 13326: ############################################################
13327: ############################################################
1.154 albertel 13328:
1.655 raeburn 13329: =pod
13330:
13331: =head1 Course Catalog Routines
13332:
13333: =over 4
13334:
13335: =item * &gather_categories()
13336:
13337: Converts category definitions - keys of categories hash stored in
13338: coursecategories in configuration.db on the primary library server in a
13339: domain - to an array. Also generates javascript and idx hash used to
13340: generate Domain Coordinator interface for editing Course Categories.
13341:
13342: Inputs:
1.663 raeburn 13343:
1.655 raeburn 13344: categories (reference to hash of category definitions).
1.663 raeburn 13345:
1.655 raeburn 13346: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13347: categories and subcategories).
1.663 raeburn 13348:
1.655 raeburn 13349: idx (reference to hash of counters used in Domain Coordinator interface for
13350: editing Course Categories).
1.663 raeburn 13351:
1.655 raeburn 13352: jsarray (reference to array of categories used to create Javascript arrays for
13353: Domain Coordinator interface for editing Course Categories).
13354:
13355: Returns: nothing
13356:
13357: Side effects: populates cats, idx and jsarray.
13358:
13359: =cut
13360:
13361: sub gather_categories {
13362: my ($categories,$cats,$idx,$jsarray) = @_;
13363: my %counters;
13364: my $num = 0;
13365: foreach my $item (keys(%{$categories})) {
13366: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13367: if ($container eq '' && $depth == 0) {
13368: $cats->[$depth][$categories->{$item}] = $cat;
13369: } else {
13370: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13371: }
13372: my ($escitem,$tail) = split(/:/,$item,2);
13373: if ($counters{$tail} eq '') {
13374: $counters{$tail} = $num;
13375: $num ++;
13376: }
13377: if (ref($idx) eq 'HASH') {
13378: $idx->{$item} = $counters{$tail};
13379: }
13380: if (ref($jsarray) eq 'ARRAY') {
13381: push(@{$jsarray->[$counters{$tail}]},$item);
13382: }
13383: }
13384: return;
13385: }
13386:
13387: =pod
13388:
13389: =item * &extract_categories()
13390:
13391: Used to generate breadcrumb trails for course categories.
13392:
13393: Inputs:
1.663 raeburn 13394:
1.655 raeburn 13395: categories (reference to hash of category definitions).
1.663 raeburn 13396:
1.655 raeburn 13397: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13398: categories and subcategories).
1.663 raeburn 13399:
1.655 raeburn 13400: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13401:
1.655 raeburn 13402: allitems (reference to hash - key is category key
13403: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13404:
1.655 raeburn 13405: idx (reference to hash of counters used in Domain Coordinator interface for
13406: editing Course Categories).
1.663 raeburn 13407:
1.655 raeburn 13408: jsarray (reference to array of categories used to create Javascript arrays for
13409: Domain Coordinator interface for editing Course Categories).
13410:
1.665 raeburn 13411: subcats (reference to hash of arrays containing all subcategories within each
13412: category, -recursive)
13413:
1.655 raeburn 13414: Returns: nothing
13415:
13416: Side effects: populates trails and allitems hash references.
13417:
13418: =cut
13419:
13420: sub extract_categories {
1.665 raeburn 13421: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13422: if (ref($categories) eq 'HASH') {
13423: &gather_categories($categories,$cats,$idx,$jsarray);
13424: if (ref($cats->[0]) eq 'ARRAY') {
13425: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13426: my $name = $cats->[0][$i];
13427: my $item = &escape($name).'::0';
13428: my $trailstr;
13429: if ($name eq 'instcode') {
13430: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13431: } elsif ($name eq 'communities') {
13432: $trailstr = &mt('Communities');
1.655 raeburn 13433: } else {
13434: $trailstr = $name;
13435: }
13436: if ($allitems->{$item} eq '') {
13437: push(@{$trails},$trailstr);
13438: $allitems->{$item} = scalar(@{$trails})-1;
13439: }
13440: my @parents = ($name);
13441: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13442: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13443: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13444: if (ref($subcats) eq 'HASH') {
13445: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13446: }
13447: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13448: }
13449: } else {
13450: if (ref($subcats) eq 'HASH') {
13451: $subcats->{$item} = [];
1.655 raeburn 13452: }
13453: }
13454: }
13455: }
13456: }
13457: return;
13458: }
13459:
13460: =pod
13461:
1.1162 raeburn 13462: =item * &recurse_categories()
1.655 raeburn 13463:
13464: Recursively used to generate breadcrumb trails for course categories.
13465:
13466: Inputs:
1.663 raeburn 13467:
1.655 raeburn 13468: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13469: categories and subcategories).
1.663 raeburn 13470:
1.655 raeburn 13471: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13472:
13473: category (current course category, for which breadcrumb trail is being generated).
13474:
13475: trails (reference to array of breadcrumb trails for each category).
13476:
1.655 raeburn 13477: allitems (reference to hash - key is category key
13478: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13479:
1.655 raeburn 13480: parents (array containing containers directories for current category,
13481: back to top level).
13482:
13483: Returns: nothing
13484:
13485: Side effects: populates trails and allitems hash references
13486:
13487: =cut
13488:
13489: sub recurse_categories {
1.665 raeburn 13490: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13491: my $shallower = $depth - 1;
13492: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13493: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13494: my $name = $cats->[$depth]{$category}[$k];
13495: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13496: my $trailstr = join(' -> ',(@{$parents},$category));
13497: if ($allitems->{$item} eq '') {
13498: push(@{$trails},$trailstr);
13499: $allitems->{$item} = scalar(@{$trails})-1;
13500: }
13501: my $deeper = $depth+1;
13502: push(@{$parents},$category);
1.665 raeburn 13503: if (ref($subcats) eq 'HASH') {
13504: my $subcat = &escape($name).':'.$category.':'.$depth;
13505: for (my $j=@{$parents}; $j>=0; $j--) {
13506: my $higher;
13507: if ($j > 0) {
13508: $higher = &escape($parents->[$j]).':'.
13509: &escape($parents->[$j-1]).':'.$j;
13510: } else {
13511: $higher = &escape($parents->[$j]).'::'.$j;
13512: }
13513: push(@{$subcats->{$higher}},$subcat);
13514: }
13515: }
13516: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13517: $subcats);
1.655 raeburn 13518: pop(@{$parents});
13519: }
13520: } else {
13521: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13522: my $trailstr = join(' -> ',(@{$parents},$category));
13523: if ($allitems->{$item} eq '') {
13524: push(@{$trails},$trailstr);
13525: $allitems->{$item} = scalar(@{$trails})-1;
13526: }
13527: }
13528: return;
13529: }
13530:
1.663 raeburn 13531: =pod
13532:
1.1162 raeburn 13533: =item * &assign_categories_table()
1.663 raeburn 13534:
13535: Create a datatable for display of hierarchical categories in a domain,
13536: with checkboxes to allow a course to be categorized.
13537:
13538: Inputs:
13539:
13540: cathash - reference to hash of categories defined for the domain (from
13541: configuration.db)
13542:
13543: currcat - scalar with an & separated list of categories assigned to a course.
13544:
1.919 raeburn 13545: type - scalar contains course type (Course or Community).
13546:
1.663 raeburn 13547: Returns: $output (markup to be displayed)
13548:
13549: =cut
13550:
13551: sub assign_categories_table {
1.919 raeburn 13552: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13553: my $output;
13554: if (ref($cathash) eq 'HASH') {
13555: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13556: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13557: $maxdepth = scalar(@cats);
13558: if (@cats > 0) {
13559: my $itemcount = 0;
13560: if (ref($cats[0]) eq 'ARRAY') {
13561: my @currcategories;
13562: if ($currcat ne '') {
13563: @currcategories = split('&',$currcat);
13564: }
1.919 raeburn 13565: my $table;
1.663 raeburn 13566: for (my $i=0; $i<@{$cats[0]}; $i++) {
13567: my $parent = $cats[0][$i];
1.919 raeburn 13568: next if ($parent eq 'instcode');
13569: if ($type eq 'Community') {
13570: next unless ($parent eq 'communities');
13571: } else {
13572: next if ($parent eq 'communities');
13573: }
1.663 raeburn 13574: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13575: my $item = &escape($parent).'::0';
13576: my $checked = '';
13577: if (@currcategories > 0) {
13578: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13579: $checked = ' checked="checked"';
1.663 raeburn 13580: }
13581: }
1.919 raeburn 13582: my $parent_title = $parent;
13583: if ($parent eq 'communities') {
13584: $parent_title = &mt('Communities');
13585: }
13586: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13587: '<input type="checkbox" name="usecategory" value="'.
13588: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13589: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13590: my $depth = 1;
13591: push(@path,$parent);
1.919 raeburn 13592: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13593: pop(@path);
1.919 raeburn 13594: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13595: $itemcount ++;
13596: }
1.919 raeburn 13597: if ($itemcount) {
13598: $output = &Apache::loncommon::start_data_table().
13599: $table.
13600: &Apache::loncommon::end_data_table();
13601: }
1.663 raeburn 13602: }
13603: }
13604: }
13605: return $output;
13606: }
13607:
13608: =pod
13609:
1.1162 raeburn 13610: =item * &assign_category_rows()
1.663 raeburn 13611:
13612: Create a datatable row for display of nested categories in a domain,
13613: with checkboxes to allow a course to be categorized,called recursively.
13614:
13615: Inputs:
13616:
13617: itemcount - track row number for alternating colors
13618:
13619: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13620: categories and subcategories.
13621:
13622: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13623:
13624: parent - parent of current category item
13625:
13626: path - Array containing all categories back up through the hierarchy from the
13627: current category to the top level.
13628:
13629: currcategories - reference to array of current categories assigned to the course
13630:
13631: Returns: $output (markup to be displayed).
13632:
13633: =cut
13634:
13635: sub assign_category_rows {
13636: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13637: my ($text,$name,$item,$chgstr);
13638: if (ref($cats) eq 'ARRAY') {
13639: my $maxdepth = scalar(@{$cats});
13640: if (ref($cats->[$depth]) eq 'HASH') {
13641: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13642: my $numchildren = @{$cats->[$depth]{$parent}};
13643: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 13644: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13645: for (my $j=0; $j<$numchildren; $j++) {
13646: $name = $cats->[$depth]{$parent}[$j];
13647: $item = &escape($name).':'.&escape($parent).':'.$depth;
13648: my $deeper = $depth+1;
13649: my $checked = '';
13650: if (ref($currcategories) eq 'ARRAY') {
13651: if (@{$currcategories} > 0) {
13652: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13653: $checked = ' checked="checked"';
1.663 raeburn 13654: }
13655: }
13656: }
1.664 raeburn 13657: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13658: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13659: $item.'"'.$checked.' />'.$name.'</label></span>'.
13660: '<input type="hidden" name="catname" value="'.$name.'" />'.
13661: '</td><td>';
1.663 raeburn 13662: if (ref($path) eq 'ARRAY') {
13663: push(@{$path},$name);
13664: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13665: pop(@{$path});
13666: }
13667: $text .= '</td></tr>';
13668: }
13669: $text .= '</table></td>';
13670: }
13671: }
13672: }
13673: return $text;
13674: }
13675:
1.1181 raeburn 13676: =pod
13677:
13678: =back
13679:
13680: =cut
13681:
1.655 raeburn 13682: ############################################################
13683: ############################################################
13684:
13685:
1.443 albertel 13686: sub commit_customrole {
1.664 raeburn 13687: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13688: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13689: ($start?', '.&mt('starting').' '.localtime($start):'').
13690: ($end?', ending '.localtime($end):'').': <b>'.
13691: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13692: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13693: '</b><br />';
13694: return $output;
13695: }
13696:
13697: sub commit_standardrole {
1.1116 raeburn 13698: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13699: my ($output,$logmsg,$linefeed);
13700: if ($context eq 'auto') {
13701: $linefeed = "\n";
13702: } else {
13703: $linefeed = "<br />\n";
13704: }
1.443 albertel 13705: if ($three eq 'st') {
1.541 raeburn 13706: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 13707: $one,$two,$sec,$context,$credits);
1.541 raeburn 13708: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13709: ($result eq 'unknown_course') || ($result eq 'refused')) {
13710: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13711: } else {
1.541 raeburn 13712: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13713: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13714: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13715: if ($context eq 'auto') {
13716: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13717: } else {
13718: $output .= '<b>'.$result.'</b>'.$linefeed.
13719: &mt('Add to classlist').': <b>ok</b>';
13720: }
13721: $output .= $linefeed;
1.443 albertel 13722: }
13723: } else {
13724: $output = &mt('Assigning').' '.$three.' in '.$url.
13725: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13726: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13727: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13728: if ($context eq 'auto') {
13729: $output .= $result.$linefeed;
13730: } else {
13731: $output .= '<b>'.$result.'</b>'.$linefeed;
13732: }
1.443 albertel 13733: }
13734: return $output;
13735: }
13736:
13737: sub commit_studentrole {
1.1116 raeburn 13738: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13739: $credits) = @_;
1.626 raeburn 13740: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13741: if ($context eq 'auto') {
13742: $linefeed = "\n";
13743: } else {
13744: $linefeed = '<br />'."\n";
13745: }
1.443 albertel 13746: if (defined($one) && defined($two)) {
13747: my $cid=$one.'_'.$two;
13748: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13749: my $secchange = 0;
13750: my $expire_role_result;
13751: my $modify_section_result;
1.628 raeburn 13752: if ($oldsec ne '-1') {
13753: if ($oldsec ne $sec) {
1.443 albertel 13754: $secchange = 1;
1.628 raeburn 13755: my $now = time;
1.443 albertel 13756: my $uurl='/'.$cid;
13757: $uurl=~s/\_/\//g;
13758: if ($oldsec) {
13759: $uurl.='/'.$oldsec;
13760: }
1.626 raeburn 13761: $oldsecurl = $uurl;
1.628 raeburn 13762: $expire_role_result =
1.652 raeburn 13763: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13764: if ($env{'request.course.sec'} ne '') {
13765: if ($expire_role_result eq 'refused') {
13766: my @roles = ('st');
13767: my @statuses = ('previous');
13768: my @roledoms = ($one);
13769: my $withsec = 1;
13770: my %roleshash =
13771: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13772: \@statuses,\@roles,\@roledoms,$withsec);
13773: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13774: my ($oldstart,$oldend) =
13775: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13776: if ($oldend > 0 && $oldend <= $now) {
13777: $expire_role_result = 'ok';
13778: }
13779: }
13780: }
13781: }
1.443 albertel 13782: $result = $expire_role_result;
13783: }
13784: }
13785: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 13786: $modify_section_result =
13787: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13788: undef,undef,undef,$sec,
13789: $end,$start,'','',$cid,
13790: '',$context,$credits);
1.443 albertel 13791: if ($modify_section_result =~ /^ok/) {
13792: if ($secchange == 1) {
1.628 raeburn 13793: if ($sec eq '') {
13794: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13795: } else {
13796: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13797: }
1.443 albertel 13798: } elsif ($oldsec eq '-1') {
1.628 raeburn 13799: if ($sec eq '') {
13800: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13801: } else {
13802: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13803: }
1.443 albertel 13804: } else {
1.628 raeburn 13805: if ($sec eq '') {
13806: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13807: } else {
13808: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13809: }
1.443 albertel 13810: }
13811: } else {
1.1115 raeburn 13812: if ($secchange) {
1.628 raeburn 13813: $$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;
13814: } else {
13815: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13816: }
1.443 albertel 13817: }
13818: $result = $modify_section_result;
13819: } elsif ($secchange == 1) {
1.628 raeburn 13820: if ($oldsec eq '') {
1.1103 raeburn 13821: $$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 13822: } else {
13823: $$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;
13824: }
1.626 raeburn 13825: if ($expire_role_result eq 'refused') {
13826: my $newsecurl = '/'.$cid;
13827: $newsecurl =~ s/\_/\//g;
13828: if ($sec ne '') {
13829: $newsecurl.='/'.$sec;
13830: }
13831: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13832: if ($sec eq '') {
13833: $$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;
13834: } else {
13835: $$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;
13836: }
13837: }
13838: }
1.443 albertel 13839: }
13840: } else {
1.626 raeburn 13841: $$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 13842: $result = "error: incomplete course id\n";
13843: }
13844: return $result;
13845: }
13846:
1.1108 raeburn 13847: sub show_role_extent {
13848: my ($scope,$context,$role) = @_;
13849: $scope =~ s{^/}{};
13850: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13851: push(@courseroles,'co');
13852: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13853: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13854: $scope =~ s{/}{_};
13855: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13856: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13857: my ($audom,$auname) = split(/\//,$scope);
13858: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13859: &Apache::loncommon::plainname($auname,$audom).'</span>');
13860: } else {
13861: $scope =~ s{/$}{};
13862: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13863: &Apache::lonnet::domain($scope,'description').'</span>');
13864: }
13865: }
13866:
1.443 albertel 13867: ############################################################
13868: ############################################################
13869:
1.566 albertel 13870: sub check_clone {
1.578 raeburn 13871: my ($args,$linefeed) = @_;
1.566 albertel 13872: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13873: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13874: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13875: my $clonemsg;
13876: my $can_clone = 0;
1.944 raeburn 13877: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13878: if ($lctype ne 'community') {
13879: $lctype = 'course';
13880: }
1.566 albertel 13881: if ($clonehome eq 'no_host') {
1.944 raeburn 13882: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13883: $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'});
13884: } else {
13885: $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'});
13886: }
1.566 albertel 13887: } else {
13888: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13889: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13890: if ($clonedesc{'type'} ne 'Community') {
13891: $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'});
13892: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13893: }
13894: }
1.882 raeburn 13895: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13896: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13897: $can_clone = 1;
13898: } else {
13899: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13900: $args->{'clonedomain'},$args->{'clonecourse'});
13901: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13902: if (grep(/^\*$/,@cloners)) {
13903: $can_clone = 1;
13904: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13905: $can_clone = 1;
13906: } else {
1.908 raeburn 13907: my $ccrole = 'cc';
1.944 raeburn 13908: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13909: $ccrole = 'co';
13910: }
1.578 raeburn 13911: my %roleshash =
13912: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13913: $args->{'ccdomain'},
1.908 raeburn 13914: 'userroles',['active'],[$ccrole],
1.578 raeburn 13915: [$args->{'clonedomain'}]);
1.908 raeburn 13916: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13917: $can_clone = 1;
13918: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13919: $can_clone = 1;
13920: } else {
1.944 raeburn 13921: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13922: $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'});
13923: } else {
13924: $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'});
13925: }
1.578 raeburn 13926: }
1.566 albertel 13927: }
1.578 raeburn 13928: }
1.566 albertel 13929: }
13930: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13931: }
13932:
1.444 albertel 13933: sub construct_course {
1.1166 raeburn 13934: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 13935: my $outcome;
1.541 raeburn 13936: my $linefeed = '<br />'."\n";
13937: if ($context eq 'auto') {
13938: $linefeed = "\n";
13939: }
1.566 albertel 13940:
13941: #
13942: # Are we cloning?
13943: #
13944: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13945: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13946: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13947: if ($context ne 'auto') {
1.578 raeburn 13948: if ($clonemsg ne '') {
13949: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13950: }
1.566 albertel 13951: }
13952: $outcome .= $clonemsg.$linefeed;
13953:
13954: if (!$can_clone) {
13955: return (0,$outcome);
13956: }
13957: }
13958:
1.444 albertel 13959: #
13960: # Open course
13961: #
13962: my $crstype = lc($args->{'crstype'});
13963: my %cenv=();
13964: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13965: $args->{'cdescr'},
13966: $args->{'curl'},
13967: $args->{'course_home'},
13968: $args->{'nonstandard'},
13969: $args->{'crscode'},
13970: $args->{'ccuname'}.':'.
13971: $args->{'ccdomain'},
1.882 raeburn 13972: $args->{'crstype'},
1.885 raeburn 13973: $cnum,$context,$category);
1.444 albertel 13974:
13975: # Note: The testing routines depend on this being output; see
13976: # Utils::Course. This needs to at least be output as a comment
13977: # if anyone ever decides to not show this, and Utils::Course::new
13978: # will need to be suitably modified.
1.541 raeburn 13979: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13980: if ($$courseid =~ /^error:/) {
13981: return (0,$outcome);
13982: }
13983:
1.444 albertel 13984: #
13985: # Check if created correctly
13986: #
1.479 albertel 13987: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13988: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13989: if ($crsuhome eq 'no_host') {
13990: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13991: return (0,$outcome);
13992: }
1.541 raeburn 13993: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13994:
1.444 albertel 13995: #
1.566 albertel 13996: # Do the cloning
13997: #
13998: if ($can_clone && $cloneid) {
13999: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14000: if ($context ne 'auto') {
14001: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14002: }
14003: $outcome .= $clonemsg.$linefeed;
14004: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14005: # Copy all files
1.637 www 14006: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14007: # Restore URL
1.566 albertel 14008: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14009: # Restore title
1.566 albertel 14010: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14011: # Restore creation date, creator and creation context.
14012: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14013: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14014: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14015: # Mark as cloned
1.566 albertel 14016: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14017: # Need to clone grading mode
14018: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14019: $cenv{'grading'}=$newenv{'grading'};
14020: # Do not clone these environment entries
14021: &Apache::lonnet::del('environment',
14022: ['default_enrollment_start_date',
14023: 'default_enrollment_end_date',
14024: 'question.email',
14025: 'policy.email',
14026: 'comment.email',
14027: 'pch.users.denied',
1.725 raeburn 14028: 'plc.users.denied',
14029: 'hidefromcat',
1.1121 raeburn 14030: 'checkforpriv',
1.1166 raeburn 14031: 'categories',
14032: 'internal.uniquecode'],
1.638 www 14033: $$crsudom,$$crsunum);
1.1170 raeburn 14034: if ($args->{'textbook'}) {
14035: $cenv{'internal.textbook'} = $args->{'textbook'};
14036: }
1.444 albertel 14037: }
1.566 albertel 14038:
1.444 albertel 14039: #
14040: # Set environment (will override cloned, if existing)
14041: #
14042: my @sections = ();
14043: my @xlists = ();
14044: if ($args->{'crstype'}) {
14045: $cenv{'type'}=$args->{'crstype'};
14046: }
14047: if ($args->{'crsid'}) {
14048: $cenv{'courseid'}=$args->{'crsid'};
14049: }
14050: if ($args->{'crscode'}) {
14051: $cenv{'internal.coursecode'}=$args->{'crscode'};
14052: }
14053: if ($args->{'crsquota'} ne '') {
14054: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14055: } else {
14056: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14057: }
14058: if ($args->{'ccuname'}) {
14059: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14060: ':'.$args->{'ccdomain'};
14061: } else {
14062: $cenv{'internal.courseowner'} = $args->{'curruser'};
14063: }
1.1116 raeburn 14064: if ($args->{'defaultcredits'}) {
14065: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14066: }
1.444 albertel 14067: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14068: if ($args->{'crssections'}) {
14069: $cenv{'internal.sectionnums'} = '';
14070: if ($args->{'crssections'} =~ m/,/) {
14071: @sections = split/,/,$args->{'crssections'};
14072: } else {
14073: $sections[0] = $args->{'crssections'};
14074: }
14075: if (@sections > 0) {
14076: foreach my $item (@sections) {
14077: my ($sec,$gp) = split/:/,$item;
14078: my $class = $args->{'crscode'}.$sec;
14079: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14080: $cenv{'internal.sectionnums'} .= $item.',';
14081: unless ($addcheck eq 'ok') {
14082: push @badclasses, $class;
14083: }
14084: }
14085: $cenv{'internal.sectionnums'} =~ s/,$//;
14086: }
14087: }
14088: # do not hide course coordinator from staff listing,
14089: # even if privileged
14090: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 14091: # add course coordinator's domain to domains to check for privileged users
14092: # if different to course domain
14093: if ($$crsudom ne $args->{'ccdomain'}) {
14094: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14095: }
1.444 albertel 14096: # add crosslistings
14097: if ($args->{'crsxlist'}) {
14098: $cenv{'internal.crosslistings'}='';
14099: if ($args->{'crsxlist'} =~ m/,/) {
14100: @xlists = split/,/,$args->{'crsxlist'};
14101: } else {
14102: $xlists[0] = $args->{'crsxlist'};
14103: }
14104: if (@xlists > 0) {
14105: foreach my $item (@xlists) {
14106: my ($xl,$gp) = split/:/,$item;
14107: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14108: $cenv{'internal.crosslistings'} .= $item.',';
14109: unless ($addcheck eq 'ok') {
14110: push @badclasses, $xl;
14111: }
14112: }
14113: $cenv{'internal.crosslistings'} =~ s/,$//;
14114: }
14115: }
14116: if ($args->{'autoadds'}) {
14117: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14118: }
14119: if ($args->{'autodrops'}) {
14120: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14121: }
14122: # check for notification of enrollment changes
14123: my @notified = ();
14124: if ($args->{'notify_owner'}) {
14125: if ($args->{'ccuname'} ne '') {
14126: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14127: }
14128: }
14129: if ($args->{'notify_dc'}) {
14130: if ($uname ne '') {
1.630 raeburn 14131: push(@notified,$uname.':'.$udom);
1.444 albertel 14132: }
14133: }
14134: if (@notified > 0) {
14135: my $notifylist;
14136: if (@notified > 1) {
14137: $notifylist = join(',',@notified);
14138: } else {
14139: $notifylist = $notified[0];
14140: }
14141: $cenv{'internal.notifylist'} = $notifylist;
14142: }
14143: if (@badclasses > 0) {
14144: my %lt=&Apache::lonlocal::texthash(
14145: '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',
14146: 'dnhr' => 'does not have rights to access enrollment in these classes',
14147: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14148: );
1.541 raeburn 14149: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14150: ' ('.$lt{'adby'}.')';
14151: if ($context eq 'auto') {
14152: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14153: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14154: foreach my $item (@badclasses) {
14155: if ($context eq 'auto') {
14156: $outcome .= " - $item\n";
14157: } else {
14158: $outcome .= "<li>$item</li>\n";
14159: }
14160: }
14161: if ($context eq 'auto') {
14162: $outcome .= $linefeed;
14163: } else {
1.566 albertel 14164: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14165: }
14166: }
1.444 albertel 14167: }
14168: if ($args->{'no_end_date'}) {
14169: $args->{'endaccess'} = 0;
14170: }
14171: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14172: $cenv{'internal.autoend'}=$args->{'enrollend'};
14173: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14174: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14175: if ($args->{'showphotos'}) {
14176: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14177: }
14178: $cenv{'internal.authtype'} = $args->{'authtype'};
14179: $cenv{'internal.autharg'} = $args->{'autharg'};
14180: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14181: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14182: 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');
14183: if ($context eq 'auto') {
14184: $outcome .= $krb_msg;
14185: } else {
1.566 albertel 14186: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14187: }
14188: $outcome .= $linefeed;
1.444 albertel 14189: }
14190: }
14191: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14192: if ($args->{'setpolicy'}) {
14193: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14194: }
14195: if ($args->{'setcontent'}) {
14196: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14197: }
14198: }
14199: if ($args->{'reshome'}) {
14200: $cenv{'reshome'}=$args->{'reshome'}.'/';
14201: $cenv{'reshome'}=~s/\/+$/\//;
14202: }
14203: #
14204: # course has keyed access
14205: #
14206: if ($args->{'setkeys'}) {
14207: $cenv{'keyaccess'}='yes';
14208: }
14209: # if specified, key authority is not course, but user
14210: # only active if keyaccess is yes
14211: if ($args->{'keyauth'}) {
1.487 albertel 14212: my ($user,$domain) = split(':',$args->{'keyauth'});
14213: $user = &LONCAPA::clean_username($user);
14214: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14215: if ($user ne '' && $domain ne '') {
1.487 albertel 14216: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14217: }
14218: }
14219:
1.1166 raeburn 14220: #
1.1167 raeburn 14221: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 14222: #
14223: if ($args->{'uniquecode'}) {
14224: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14225: if ($code) {
14226: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 14227: my %crsinfo =
14228: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
14229: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
14230: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
14231: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
14232: }
1.1166 raeburn 14233: if (ref($coderef)) {
14234: $$coderef = $code;
14235: }
14236: }
14237: }
14238:
1.444 albertel 14239: if ($args->{'disresdis'}) {
14240: $cenv{'pch.roles.denied'}='st';
14241: }
14242: if ($args->{'disablechat'}) {
14243: $cenv{'plc.roles.denied'}='st';
14244: }
14245:
14246: # Record we've not yet viewed the Course Initialization Helper for this
14247: # course
14248: $cenv{'course.helper.not.run'} = 1;
14249: #
14250: # Use new Randomseed
14251: #
14252: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14253: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14254: #
14255: # The encryption code and receipt prefix for this course
14256: #
14257: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14258: $cenv{'internal.encpref'}=100+int(9*rand(99));
14259: #
14260: # By default, use standard grading
14261: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14262:
1.541 raeburn 14263: $outcome .= $linefeed.&mt('Setting environment').': '.
14264: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14265: #
14266: # Open all assignments
14267: #
14268: if ($args->{'openall'}) {
14269: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14270: my %storecontent = ($storeunder => time,
14271: $storeunder.'.type' => 'date_start');
14272:
14273: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14274: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14275: }
14276: #
14277: # Set first page
14278: #
14279: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14280: || ($cloneid)) {
1.445 albertel 14281: use LONCAPA::map;
1.444 albertel 14282: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14283:
14284: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14285: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14286:
1.444 albertel 14287: $outcome .= ($fatal?$errtext:'read ok').' - ';
14288: my $title; my $url;
14289: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14290: $title=&mt('Syllabus');
1.444 albertel 14291: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14292: } else {
1.963 raeburn 14293: $title=&mt('Table of Contents');
1.444 albertel 14294: $url='/adm/navmaps';
14295: }
1.445 albertel 14296:
14297: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14298: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14299:
14300: if ($errtext) { $fatal=2; }
1.541 raeburn 14301: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14302: }
1.566 albertel 14303:
14304: return (1,$outcome);
1.444 albertel 14305: }
14306:
1.1166 raeburn 14307: sub make_unique_code {
14308: my ($cdom,$cnum) = @_;
14309: # get lock on uniquecodes db
14310: my $lockhash = {
14311: $cnum."\0".'uniquecodes' => $env{'user.name'}.
14312: ':'.$env{'user.domain'},
14313: };
14314: my $tries = 0;
14315: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14316: my ($code,$error);
14317:
14318: while (($gotlock ne 'ok') && ($tries<3)) {
14319: $tries ++;
14320: sleep 1;
14321: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14322: }
14323: if ($gotlock eq 'ok') {
14324: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
14325: my $gotcode;
14326: my $attempts = 0;
14327: while ((!$gotcode) && ($attempts < 100)) {
14328: $code = &generate_code();
14329: if (!exists($currcodes{$code})) {
14330: $gotcode = 1;
14331: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
14332: $error = 'nostore';
14333: }
14334: }
14335: $attempts ++;
14336: }
14337: my @del_lock = ($cnum."\0".'uniquecodes');
14338: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
14339: } else {
14340: $error = 'nolock';
14341: }
14342: return ($code,$error);
14343: }
14344:
14345: sub generate_code {
14346: my $code;
14347: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
14348: for (my $i=0; $i<6; $i++) {
14349: my $lettnum = int (rand 2);
14350: my $item = '';
14351: if ($lettnum) {
14352: $item = $letts[int( rand(18) )];
14353: } else {
14354: $item = 1+int( rand(8) );
14355: }
14356: $code .= $item;
14357: }
14358: return $code;
14359: }
14360:
1.444 albertel 14361: ############################################################
14362: ############################################################
14363:
1.953 droeschl 14364: #SD
14365: # only Community and Course, or anything else?
1.378 raeburn 14366: sub course_type {
14367: my ($cid) = @_;
14368: if (!defined($cid)) {
14369: $cid = $env{'request.course.id'};
14370: }
1.404 albertel 14371: if (defined($env{'course.'.$cid.'.type'})) {
14372: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14373: } else {
14374: return 'Course';
1.377 raeburn 14375: }
14376: }
1.156 albertel 14377:
1.406 raeburn 14378: sub group_term {
14379: my $crstype = &course_type();
14380: my %names = (
14381: 'Course' => 'group',
1.865 raeburn 14382: 'Community' => 'group',
1.406 raeburn 14383: );
14384: return $names{$crstype};
14385: }
14386:
1.902 raeburn 14387: sub course_types {
1.1165 raeburn 14388: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 14389: my %typename = (
14390: official => 'Official course',
14391: unofficial => 'Unofficial course',
14392: community => 'Community',
1.1165 raeburn 14393: textbook => 'Textbook course',
1.902 raeburn 14394: );
14395: return (\@types,\%typename);
14396: }
14397:
1.156 albertel 14398: sub icon {
14399: my ($file)=@_;
1.505 albertel 14400: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14401: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14402: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14403: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14404: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14405: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14406: $curfext.".gif") {
14407: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14408: $curfext.".gif";
14409: }
14410: }
1.249 albertel 14411: return &lonhttpdurl($iconname);
1.154 albertel 14412: }
1.84 albertel 14413:
1.575 albertel 14414: sub lonhttpdurl {
1.692 www 14415: #
14416: # Had been used for "small fry" static images on separate port 8080.
14417: # Modify here if lightweight http functionality desired again.
14418: # Currently eliminated due to increasing firewall issues.
14419: #
1.575 albertel 14420: my ($url)=@_;
1.692 www 14421: return $url;
1.215 albertel 14422: }
14423:
1.213 albertel 14424: sub connection_aborted {
14425: my ($r)=@_;
14426: $r->print(" ");$r->rflush();
14427: my $c = $r->connection;
14428: return $c->aborted();
14429: }
14430:
1.221 foxr 14431: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14432: # strings as 'strings'.
14433: sub escape_single {
1.221 foxr 14434: my ($input) = @_;
1.223 albertel 14435: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14436: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14437: return $input;
14438: }
1.223 albertel 14439:
1.222 foxr 14440: # Same as escape_single, but escape's "'s This
14441: # can be used for "strings"
14442: sub escape_double {
14443: my ($input) = @_;
14444: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14445: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14446: return $input;
14447: }
1.223 albertel 14448:
1.222 foxr 14449: # Escapes the last element of a full URL.
14450: sub escape_url {
14451: my ($url) = @_;
1.238 raeburn 14452: my @urlslices = split(/\//, $url,-1);
1.369 www 14453: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14454: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14455: }
1.462 albertel 14456:
1.820 raeburn 14457: sub compare_arrays {
14458: my ($arrayref1,$arrayref2) = @_;
14459: my (@difference,%count);
14460: @difference = ();
14461: %count = ();
14462: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14463: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14464: foreach my $element (keys(%count)) {
14465: if ($count{$element} == 1) {
14466: push(@difference,$element);
14467: }
14468: }
14469: }
14470: return @difference;
14471: }
14472:
1.817 bisitz 14473: # -------------------------------------------------------- Initialize user login
1.462 albertel 14474: sub init_user_environment {
1.463 albertel 14475: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14476: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14477:
14478: my $public=($username eq 'public' && $domain eq 'public');
14479:
14480: # See if old ID present, if so, remove
14481:
1.1062 raeburn 14482: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14483: my $now=time;
14484:
14485: if ($public) {
14486: my $max_public=100;
14487: my $oldest;
14488: my $oldest_time=0;
14489: for(my $next=1;$next<=$max_public;$next++) {
14490: if (-e $lonids."/publicuser_$next.id") {
14491: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14492: if ($mtime<$oldest_time || !$oldest_time) {
14493: $oldest_time=$mtime;
14494: $oldest=$next;
14495: }
14496: } else {
14497: $cookie="publicuser_$next";
14498: last;
14499: }
14500: }
14501: if (!$cookie) { $cookie="publicuser_$oldest"; }
14502: } else {
1.463 albertel 14503: # if this isn't a robot, kill any existing non-robot sessions
14504: if (!$args->{'robot'}) {
14505: opendir(DIR,$lonids);
14506: while ($filename=readdir(DIR)) {
14507: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14508: unlink($lonids.'/'.$filename);
14509: }
1.462 albertel 14510: }
1.463 albertel 14511: closedir(DIR);
1.462 albertel 14512: }
14513: # Give them a new cookie
1.463 albertel 14514: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14515: : $now.$$.int(rand(10000)));
1.463 albertel 14516: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14517:
14518: # Initialize roles
14519:
1.1062 raeburn 14520: ($userroles,$firstaccenv,$timerintenv) =
14521: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14522: }
14523: # ------------------------------------ Check browser type and MathML capability
14524:
14525: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1141 raeburn 14526: $clientunicode,$clientos,$clientmobile,$clientinfo) = &decode_user_agent($r);
1.462 albertel 14527:
14528: # ------------------------------------------------------------- Get environment
14529:
14530: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14531: my ($tmp) = keys(%userenv);
14532: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14533: } else {
14534: undef(%userenv);
14535: }
14536: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14537: $form->{'interface'}=$userenv{'interface'};
14538: }
14539: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14540:
14541: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14542: foreach my $option ('interface','localpath','localres') {
14543: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14544: }
14545: # --------------------------------------------------------- Write first profile
14546:
14547: {
14548: my %initial_env =
14549: ("user.name" => $username,
14550: "user.domain" => $domain,
14551: "user.home" => $authhost,
14552: "browser.type" => $clientbrowser,
14553: "browser.version" => $clientversion,
14554: "browser.mathml" => $clientmathml,
14555: "browser.unicode" => $clientunicode,
14556: "browser.os" => $clientos,
1.1137 raeburn 14557: "browser.mobile" => $clientmobile,
1.1141 raeburn 14558: "browser.info" => $clientinfo,
1.462 albertel 14559: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14560: "request.course.fn" => '',
14561: "request.course.uri" => '',
14562: "request.course.sec" => '',
14563: "request.role" => 'cm',
14564: "request.role.adv" => $env{'user.adv'},
14565: "request.host" => $ENV{'REMOTE_ADDR'},);
14566:
14567: if ($form->{'localpath'}) {
14568: $initial_env{"browser.localpath"} = $form->{'localpath'};
14569: $initial_env{"browser.localres"} = $form->{'localres'};
14570: }
14571:
14572: if ($form->{'interface'}) {
14573: $form->{'interface'}=~s/\W//gs;
14574: $initial_env{"browser.interface"} = $form->{'interface'};
14575: $env{'browser.interface'}=$form->{'interface'};
14576: }
14577:
1.1157 raeburn 14578: if ($form->{'iptoken'}) {
14579: my $lonhost = $r->dir_config('lonHostID');
14580: $initial_env{"user.noloadbalance"} = $lonhost;
14581: $env{'user.noloadbalance'} = $lonhost;
14582: }
14583:
1.981 raeburn 14584: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14585: my %domdef;
14586: unless ($domain eq 'public') {
14587: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14588: }
1.980 raeburn 14589:
1.1081 raeburn 14590: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14591: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14592: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14593: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14594: }
14595:
1.1165 raeburn 14596: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 14597: $userenv{'canrequest.'.$crstype} =
14598: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14599: 'reload','requestcourses',
14600: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14601: }
14602:
1.1092 raeburn 14603: $userenv{'canrequest.author'} =
14604: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14605: 'reload','requestauthor',
14606: \%userenv,\%domdef,\%is_adv);
14607: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14608: $domain,$username);
14609: my $reqstatus = $reqauthor{'author_status'};
14610: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14611: if (ref($reqauthor{'author'}) eq 'HASH') {
14612: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14613: $reqauthor{'author'}{'timestamp'};
14614: }
14615: }
14616:
1.462 albertel 14617: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14618:
1.462 albertel 14619: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14620: &GDBM_WRCREAT(),0640)) {
14621: &_add_to_env(\%disk_env,\%initial_env);
14622: &_add_to_env(\%disk_env,\%userenv,'environment.');
14623: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14624: if (ref($firstaccenv) eq 'HASH') {
14625: &_add_to_env(\%disk_env,$firstaccenv);
14626: }
14627: if (ref($timerintenv) eq 'HASH') {
14628: &_add_to_env(\%disk_env,$timerintenv);
14629: }
1.463 albertel 14630: if (ref($args->{'extra_env'})) {
14631: &_add_to_env(\%disk_env,$args->{'extra_env'});
14632: }
1.462 albertel 14633: untie(%disk_env);
14634: } else {
1.705 tempelho 14635: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14636: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14637: return 'error: '.$!;
14638: }
14639: }
14640: $env{'request.role'}='cm';
14641: $env{'request.role.adv'}=$env{'user.adv'};
14642: $env{'browser.type'}=$clientbrowser;
14643:
14644: return $cookie;
14645:
14646: }
14647:
14648: sub _add_to_env {
14649: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14650: if (ref($env_data) eq 'HASH') {
14651: while (my ($key,$value) = each(%$env_data)) {
14652: $idf->{$prefix.$key} = $value;
14653: $env{$prefix.$key} = $value;
14654: }
1.462 albertel 14655: }
14656: }
14657:
1.685 tempelho 14658: # --- Get the symbolic name of a problem and the url
14659: sub get_symb {
14660: my ($request,$silent) = @_;
1.726 raeburn 14661: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14662: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14663: if ($symb eq '') {
14664: if (!$silent) {
1.1071 raeburn 14665: if (ref($request)) {
14666: $request->print("Unable to handle ambiguous references:$url:.");
14667: }
1.685 tempelho 14668: return ();
14669: }
14670: }
14671: &Apache::lonenc::check_decrypt(\$symb);
14672: return ($symb);
14673: }
14674:
14675: # --------------------------------------------------------------Get annotation
14676:
14677: sub get_annotation {
14678: my ($symb,$enc) = @_;
14679:
14680: my $key = $symb;
14681: if (!$enc) {
14682: $key =
14683: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14684: }
14685: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14686: return $annotation{$key};
14687: }
14688:
14689: sub clean_symb {
1.731 raeburn 14690: my ($symb,$delete_enc) = @_;
1.685 tempelho 14691:
14692: &Apache::lonenc::check_decrypt(\$symb);
14693: my $enc = $env{'request.enc'};
1.731 raeburn 14694: if ($delete_enc) {
1.730 raeburn 14695: delete($env{'request.enc'});
14696: }
1.685 tempelho 14697:
14698: return ($symb,$enc);
14699: }
1.462 albertel 14700:
1.1181 raeburn 14701: ############################################################
14702: ############################################################
14703:
14704: =pod
14705:
14706: =head1 Routines for building display used to search for courses
14707:
14708:
14709: =over 4
14710:
14711: =item * &build_filters()
14712:
14713: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 14714: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
14715: and quotacheck.pl
14716:
1.1181 raeburn 14717:
14718: Inputs:
14719:
14720: filterlist - anonymous array of fields to include as potential filters
14721:
14722: crstype - course type
14723:
14724: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
14725: to pop-open a course selector (will contain "extra element").
14726:
14727: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
14728:
14729: filter - anonymous hash of criteria and their values
14730:
14731: action - form action
14732:
14733: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
14734:
1.1182 raeburn 14735: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 14736:
14737: cloneruname - username of owner of new course who wants to clone
14738:
14739: clonerudom - domain of owner of new course who wants to clone
14740:
14741: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
14742:
14743: codetitlesref - reference to array of titles of components in institutional codes (official courses)
14744:
14745: codedom - domain
14746:
14747: formname - value of form element named "form".
14748:
14749: fixeddom - domain, if fixed.
14750:
14751: prevphase - value to assign to form element named "phase" when going back to the previous screen
14752:
14753: cnameelement - name of form element in form on opener page which will receive title of selected course
14754:
14755: cnumelement - name of form element in form on opener page which will receive courseID of selected course
14756:
14757: cdomelement - name of form element in form on opener page which will receive domain of selected course
14758:
14759: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
14760:
14761: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
14762:
14763: clonewarning - warning message about missing information for intended course owner when DC creates a course
14764:
1.1182 raeburn 14765:
1.1181 raeburn 14766: Returns: $output - HTML for display of search criteria, and hidden form elements.
14767:
1.1182 raeburn 14768:
1.1181 raeburn 14769: Side Effects: None
14770:
14771: =cut
14772:
14773: # ---------------------------------------------- search for courses based on last activity etc.
14774:
14775: sub build_filters {
14776: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
14777: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
14778: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
14779: $cnameelement,$cnumelement,$cdomelement,$setroles,
14780: $clonetext,$clonewarning) = @_;
1.1182 raeburn 14781: my ($list,$jscript);
1.1181 raeburn 14782: my $onchange = 'javascript:updateFilters(this)';
14783: my ($domainselectform,$sincefilterform,$createdfilterform,
14784: $ownerdomselectform,$persondomselectform,$instcodeform,
14785: $typeselectform,$instcodetitle);
14786: if ($formname eq '') {
14787: $formname = $caller;
14788: }
14789: foreach my $item (@{$filterlist}) {
14790: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
14791: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
14792: if ($item eq 'domainfilter') {
14793: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
14794: } elsif ($item eq 'coursefilter') {
14795: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
14796: } elsif ($item eq 'ownerfilter') {
14797: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
14798: } elsif ($item eq 'ownerdomfilter') {
14799: $filter->{'ownerdomfilter'} =
14800: &LONCAPA::clean_domain($filter->{$item});
14801: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
14802: 'ownerdomfilter',1);
14803: } elsif ($item eq 'personfilter') {
14804: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
14805: } elsif ($item eq 'persondomfilter') {
14806: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
14807: 'persondomfilter',1);
14808: } else {
14809: $filter->{$item} =~ s/\W//g;
14810: }
14811: if (!$filter->{$item}) {
14812: $filter->{$item} = '';
14813: }
14814: }
14815: if ($item eq 'domainfilter') {
14816: my $allow_blank = 1;
14817: if ($formname eq 'portform') {
14818: $allow_blank=0;
14819: } elsif ($formname eq 'studentform') {
14820: $allow_blank=0;
14821: }
14822: if ($fixeddom) {
14823: $domainselectform = '<input type="hidden" name="domainfilter"'.
14824: ' value="'.$codedom.'" />'.
14825: &Apache::lonnet::domain($codedom,'description');
14826: } else {
14827: $domainselectform = &select_dom_form($filter->{$item},
14828: 'domainfilter',
14829: $allow_blank,'',$onchange);
14830: }
14831: } else {
14832: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
14833: }
14834: }
14835:
14836: # last course activity filter and selection
14837: $sincefilterform = &timebased_select_form('sincefilter',$filter);
14838:
14839: # course created filter and selection
14840: if (exists($filter->{'createdfilter'})) {
14841: $createdfilterform = &timebased_select_form('createdfilter',$filter);
14842: }
14843:
14844: my %lt = &Apache::lonlocal::texthash(
14845: 'cac' => "$crstype Activity",
14846: 'ccr' => "$crstype Created",
14847: 'cde' => "$crstype Title",
14848: 'cdo' => "$crstype Domain",
14849: 'ins' => 'Institutional Code',
14850: 'inc' => 'Institutional Categorization',
14851: 'cow' => "$crstype Owner/Co-owner",
14852: 'cop' => "$crstype Personnel Includes",
14853: 'cog' => 'Type',
14854: );
14855:
14856: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
14857: my $typeval = 'Course';
14858: if ($crstype eq 'Community') {
14859: $typeval = 'Community';
14860: }
14861: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
14862: } else {
14863: $typeselectform = '<select name="type" size="1"';
14864: if ($onchange) {
14865: $typeselectform .= ' onchange="'.$onchange.'"';
14866: }
14867: $typeselectform .= '>'."\n";
14868: foreach my $posstype ('Course','Community') {
14869: $typeselectform.='<option value="'.$posstype.'"'.
14870: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
14871: }
14872: $typeselectform.="</select>";
14873: }
14874:
14875: my ($cloneableonlyform,$cloneabletitle);
14876: if (exists($filter->{'cloneableonly'})) {
14877: my $cloneableon = '';
14878: my $cloneableoff = ' checked="checked"';
14879: if ($filter->{'cloneableonly'}) {
14880: $cloneableon = $cloneableoff;
14881: $cloneableoff = '';
14882: }
14883: $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>';
14884: if ($formname eq 'ccrs') {
1.1187 ! bisitz 14885: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 14886: } else {
14887: $cloneabletitle = &mt('Cloneable by you');
14888: }
14889: }
14890: my $officialjs;
14891: if ($crstype eq 'Course') {
14892: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 14893: # if (($fixeddom) || ($formname eq 'requestcrs') ||
14894: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
14895: if ($codedom) {
1.1181 raeburn 14896: $officialjs = 1;
14897: ($instcodeform,$jscript,$$numtitlesref) =
14898: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
14899: $officialjs,$codetitlesref);
14900: if ($jscript) {
1.1182 raeburn 14901: $jscript = '<script type="text/javascript">'."\n".
14902: '// <![CDATA['."\n".
14903: $jscript."\n".
14904: '// ]]>'."\n".
14905: '</script>'."\n";
1.1181 raeburn 14906: }
14907: }
14908: if ($instcodeform eq '') {
14909: $instcodeform =
14910: '<input type="text" name="instcodefilter" size="10" value="'.
14911: $list->{'instcodefilter'}.'" />';
14912: $instcodetitle = $lt{'ins'};
14913: } else {
14914: $instcodetitle = $lt{'inc'};
14915: }
14916: if ($fixeddom) {
14917: $instcodetitle .= '<br />('.$codedom.')';
14918: }
14919: }
14920: }
14921: my $output = qq|
14922: <form method="post" name="filterpicker" action="$action">
14923: <input type="hidden" name="form" value="$formname" />
14924: |;
14925: if ($formname eq 'modifycourse') {
14926: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
14927: '<input type="hidden" name="prevphase" value="'.
14928: $prevphase.'" />'."\n";
1.1182 raeburn 14929: } elsif ($formname ne 'quotacheck') {
1.1181 raeburn 14930: my $name_input;
14931: if ($cnameelement ne '') {
14932: $name_input = '<input type="hidden" name="cnameelement" value="'.
14933: $cnameelement.'" />';
14934: }
14935: $output .= qq|
1.1182 raeburn 14936: <input type="hidden" name="cnumelement" value="$cnumelement" />
14937: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 14938: $name_input
14939: $roleelement
14940: $multelement
14941: $typeelement
14942: |;
14943: if ($formname eq 'portform') {
14944: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
14945: }
14946: }
14947: if ($fixeddom) {
14948: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
14949: }
14950: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
14951: if ($sincefilterform) {
14952: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
14953: .$sincefilterform
14954: .&Apache::lonhtmlcommon::row_closure();
14955: }
14956: if ($createdfilterform) {
14957: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
14958: .$createdfilterform
14959: .&Apache::lonhtmlcommon::row_closure();
14960: }
14961: if ($domainselectform) {
14962: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
14963: .$domainselectform
14964: .&Apache::lonhtmlcommon::row_closure();
14965: }
14966: if ($typeselectform) {
14967: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
14968: $output .= $typeselectform;
14969: } else {
14970: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
14971: .$typeselectform
14972: .&Apache::lonhtmlcommon::row_closure();
14973: }
14974: }
14975: if ($instcodeform) {
14976: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
14977: .$instcodeform
14978: .&Apache::lonhtmlcommon::row_closure();
14979: }
14980: if (exists($filter->{'ownerfilter'})) {
14981: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
14982: '<table><tr><td>'.&mt('Username').'<br />'.
14983: '<input type="text" name="ownerfilter" size="20" value="'.
14984: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
14985: $ownerdomselectform.'</td></tr></table>'.
14986: &Apache::lonhtmlcommon::row_closure();
14987: }
14988: if (exists($filter->{'personfilter'})) {
14989: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
14990: '<table><tr><td>'.&mt('Username').'<br />'.
14991: '<input type="text" name="personfilter" size="20" value="'.
14992: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
14993: $persondomselectform.'</td></tr></table>'.
14994: &Apache::lonhtmlcommon::row_closure();
14995: }
14996: if (exists($filter->{'coursefilter'})) {
14997: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
14998: .'<input type="text" name="coursefilter" size="25" value="'
14999: .$list->{'coursefilter'}.'" />'
15000: .&Apache::lonhtmlcommon::row_closure();
15001: }
15002: if ($cloneableonlyform) {
15003: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15004: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15005: }
15006: if (exists($filter->{'descriptfilter'})) {
15007: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15008: .'<input type="text" name="descriptfilter" size="40" value="'
15009: .$list->{'descriptfilter'}.'" />'
15010: .&Apache::lonhtmlcommon::row_closure(1);
15011: }
15012: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15013: '<input type="hidden" name="updater" value="" />'."\n".
15014: '<input type="submit" name="gosearch" value="'.
15015: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15016: return $jscript.$clonewarning.$output;
15017: }
15018:
15019: =pod
15020:
15021: =item * &timebased_select_form()
15022:
1.1182 raeburn 15023: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 15024: filter e.g., Course Activity, Course Created, when searching for courses
15025: or communities
15026:
15027: Inputs:
15028:
15029: item - name of form element (sincefilter or createdfilter)
15030:
15031: filter - anonymous hash of criteria and their values
15032:
15033: Returns: HTML for a select box contained a blank, then six time selections,
15034: with value set in incoming form variables currently selected.
15035:
15036: Side Effects: None
15037:
15038: =cut
15039:
15040: sub timebased_select_form {
15041: my ($item,$filter) = @_;
15042: if (ref($filter) eq 'HASH') {
15043: $filter->{$item} =~ s/[^\d-]//g;
15044: if (!$filter->{$item}) { $filter->{$item}=-1; }
15045: return &select_form(
15046: $filter->{$item},
15047: $item,
15048: { '-1' => '',
15049: '86400' => &mt('today'),
15050: '604800' => &mt('last week'),
15051: '2592000' => &mt('last month'),
15052: '7776000' => &mt('last three months'),
15053: '15552000' => &mt('last six months'),
15054: '31104000' => &mt('last year'),
15055: 'select_form_order' =>
15056: ['-1','86400','604800','2592000','7776000',
15057: '15552000','31104000']});
15058: }
15059: }
15060:
15061: =pod
15062:
15063: =item * &js_changer()
15064:
15065: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 15066: when course type or domain is changed, and also to hide 'Searching ...' on
15067: page load completion for page showing search result.
1.1181 raeburn 15068:
15069: Inputs: None
15070:
1.1183 raeburn 15071: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 15072:
15073: Side Effects: None
15074:
15075: =cut
15076:
15077: sub js_changer {
15078: return <<ENDJS;
15079: <script type="text/javascript">
15080: // <![CDATA[
15081: function updateFilters(caller) {
15082: if (typeof(caller) != "undefined") {
15083: document.filterpicker.updater.value = caller.name;
15084: }
15085: document.filterpicker.submit();
15086: }
1.1183 raeburn 15087:
15088: function hideSearching() {
15089: if (document.getElementById('searching')) {
15090: document.getElementById('searching').style.display = 'none';
15091: }
15092: return;
15093: }
15094:
1.1181 raeburn 15095: // ]]>
15096: </script>
15097:
15098: ENDJS
15099: }
15100:
15101: =pod
15102:
1.1182 raeburn 15103: =item * &search_courses()
15104:
15105: Process selected filters form course search form and pass to lonnet::courseiddump
15106: to retrieve a hash for which keys are courseIDs which match the selected filters.
15107:
15108: Inputs:
15109:
15110: dom - domain being searched
15111:
15112: type - course type ('Course' or 'Community' or '.' if any).
15113:
15114: filter - anonymous hash of criteria and their values
15115:
15116: numtitles - for institutional codes - number of categories
15117:
15118: cloneruname - optional username of new course owner
15119:
15120: clonerudom - optional domain of new course owner
15121:
15122: domcloner - Optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
15123: (used when DC is using course creation form)
15124:
15125: codetitles - reference to array of titles of components in institutional codes (official courses).
15126:
15127:
15128: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
15129:
15130:
15131: Side Effects: None
15132:
15133: =cut
15134:
15135:
15136: sub search_courses {
15137: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_;
15138: my (%courses,%showcourses,$cloner);
15139: if (($filter->{'ownerfilter'} ne '') ||
15140: ($filter->{'ownerdomfilter'} ne '')) {
15141: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
15142: $filter->{'ownerdomfilter'};
15143: }
15144: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
15145: if (!$filter->{$item}) {
15146: $filter->{$item}='.';
15147: }
15148: }
15149: my $now = time;
15150: my $timefilter =
15151: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
15152: my ($createdbefore,$createdafter);
15153: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
15154: $createdbefore = $now;
15155: $createdafter = $now-$filter->{'createdfilter'};
15156: }
15157: my ($instcodefilter,$regexpok);
15158: if ($numtitles) {
15159: if ($env{'form.official'} eq 'on') {
15160: $instcodefilter =
15161: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15162: $regexpok = 1;
15163: } elsif ($env{'form.official'} eq 'off') {
15164: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15165: unless ($instcodefilter eq '') {
15166: $regexpok = -1;
15167: }
15168: }
15169: } else {
15170: $instcodefilter = $filter->{'instcodefilter'};
15171: }
15172: if ($instcodefilter eq '') { $instcodefilter = '.'; }
15173: if ($type eq '') { $type = '.'; }
15174:
15175: if (($clonerudom ne '') && ($cloneruname ne '')) {
15176: $cloner = $cloneruname.':'.$clonerudom;
15177: }
15178: %courses = &Apache::lonnet::courseiddump($dom,
15179: $filter->{'descriptfilter'},
15180: $timefilter,
15181: $instcodefilter,
15182: $filter->{'combownerfilter'},
15183: $filter->{'coursefilter'},
15184: undef,undef,$type,$regexpok,undef,undef,
15185: undef,undef,$cloner,$env{'form.cc_clone'},
15186: $filter->{'cloneableonly'},
15187: $createdbefore,$createdafter,undef,
15188: $domcloner);
15189: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
15190: my $ccrole;
15191: if ($type eq 'Community') {
15192: $ccrole = 'co';
15193: } else {
15194: $ccrole = 'cc';
15195: }
15196: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
15197: $filter->{'persondomfilter'},
15198: 'userroles',undef,
15199: [$ccrole,'in','ad','ep','ta','cr'],
15200: $dom);
15201: foreach my $role (keys(%rolehash)) {
15202: my ($cnum,$cdom,$courserole) = split(':',$role);
15203: my $cid = $cdom.'_'.$cnum;
15204: if (exists($courses{$cid})) {
15205: if (ref($courses{$cid}) eq 'HASH') {
15206: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
15207: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
15208: push (@{$courses{$cid}{roles}},$courserole);
15209: }
15210: } else {
15211: $courses{$cid}{roles} = [$courserole];
15212: }
15213: $showcourses{$cid} = $courses{$cid};
15214: }
15215: }
15216: }
15217: %courses = %showcourses;
15218: }
15219: return %courses;
15220: }
15221:
15222:
15223: =pod
15224:
1.1181 raeburn 15225: =back
15226:
15227: =cut
15228:
15229:
1.990 raeburn 15230: sub build_release_hashes {
15231: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
15232: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
15233: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
15234: (ref($randomizetry) eq 'HASH'));
15235: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
15236: my ($item,$name,$value) = split(/:/,$key);
15237: if ($item eq 'parameter') {
15238: if (ref($checkparms->{$name}) eq 'ARRAY') {
15239: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
15240: push(@{$checkparms->{$name}},$value);
15241: }
15242: } else {
15243: push(@{$checkparms->{$name}},$value);
15244: }
15245: } elsif ($item eq 'resourcetag') {
15246: if ($name eq 'responsetype') {
15247: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
15248: }
15249: } elsif ($item eq 'course') {
15250: if ($name eq 'crstype') {
15251: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
15252: }
15253: }
15254: }
15255: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
15256: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
15257: return;
15258: }
15259:
1.1083 raeburn 15260: sub update_content_constraints {
15261: my ($cdom,$cnum,$chome,$cid) = @_;
15262: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15263: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
15264: my %checkresponsetypes;
15265: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
15266: my ($item,$name,$value) = split(/:/,$key);
15267: if ($item eq 'resourcetag') {
15268: if ($name eq 'responsetype') {
15269: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
15270: }
15271: }
15272: }
15273: my $navmap = Apache::lonnavmaps::navmap->new();
15274: if (defined($navmap)) {
15275: my %allresponses;
15276: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
15277: my %responses = $res->responseTypes();
15278: foreach my $key (keys(%responses)) {
15279: next unless(exists($checkresponsetypes{$key}));
15280: $allresponses{$key} += $responses{$key};
15281: }
15282: }
15283: foreach my $key (keys(%allresponses)) {
15284: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
15285: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
15286: ($reqdmajor,$reqdminor) = ($major,$minor);
15287: }
15288: }
15289: undef($navmap);
15290: }
15291: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
15292: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
15293: }
15294: return;
15295: }
15296:
1.1110 raeburn 15297: sub allmaps_incourse {
15298: my ($cdom,$cnum,$chome,$cid) = @_;
15299: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
15300: $cid = $env{'request.course.id'};
15301: $cdom = $env{'course.'.$cid.'.domain'};
15302: $cnum = $env{'course.'.$cid.'.num'};
15303: $chome = $env{'course.'.$cid.'.home'};
15304: }
15305: my %allmaps = ();
15306: my $lastchange =
15307: &Apache::lonnet::get_coursechange($cdom,$cnum);
15308: if ($lastchange > $env{'request.course.tied'}) {
15309: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
15310: unless ($ferr) {
15311: &update_content_constraints($cdom,$cnum,$chome,$cid);
15312: }
15313: }
15314: my $navmap = Apache::lonnavmaps::navmap->new();
15315: if (defined($navmap)) {
15316: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
15317: $allmaps{$res->src()} = 1;
15318: }
15319: }
15320: return \%allmaps;
15321: }
15322:
1.1083 raeburn 15323: sub parse_supplemental_title {
15324: my ($title) = @_;
15325:
15326: my ($foldertitle,$renametitle);
15327: if ($title =~ /&&&/) {
15328: $title = &HTML::Entites::decode($title);
15329: }
15330: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
15331: $renametitle=$4;
15332: my ($time,$uname,$udom) = ($1,$2,$3);
15333: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
15334: my $name = &plainname($uname,$udom);
15335: $name = &HTML::Entities::encode($name,'"<>&\'');
15336: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
15337: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
15338: $name.': <br />'.$foldertitle;
15339: }
15340: if (wantarray) {
15341: return ($title,$foldertitle,$renametitle);
15342: }
15343: return $title;
15344: }
15345:
1.1143 raeburn 15346: sub recurse_supplemental {
15347: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
15348: if ($suppmap) {
15349: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
15350: if ($fatal) {
15351: $errors ++;
15352: } else {
15353: if ($#LONCAPA::map::resources > 0) {
15354: foreach my $res (@LONCAPA::map::resources) {
15355: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
15356: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 15357: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
15358: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 15359: } else {
15360: $numfiles ++;
15361: }
15362: }
15363: }
15364: }
15365: }
15366: }
15367: return ($numfiles,$errors);
15368: }
15369:
1.1101 raeburn 15370: sub symb_to_docspath {
15371: my ($symb) = @_;
15372: return unless ($symb);
15373: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
15374: if ($resurl=~/\.(sequence|page)$/) {
15375: $mapurl=$resurl;
15376: } elsif ($resurl eq 'adm/navmaps') {
15377: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
15378: }
15379: my $mapresobj;
15380: my $navmap = Apache::lonnavmaps::navmap->new();
15381: if (ref($navmap)) {
15382: $mapresobj = $navmap->getResourceByUrl($mapurl);
15383: }
15384: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
15385: my $type=$2;
15386: my $path;
15387: if (ref($mapresobj)) {
15388: my $pcslist = $mapresobj->map_hierarchy();
15389: if ($pcslist ne '') {
15390: foreach my $pc (split(/,/,$pcslist)) {
15391: next if ($pc <= 1);
15392: my $res = $navmap->getByMapPc($pc);
15393: if (ref($res)) {
15394: my $thisurl = $res->src();
15395: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
15396: my $thistitle = $res->title();
15397: $path .= '&'.
15398: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 15399: &escape($thistitle).
1.1101 raeburn 15400: ':'.$res->randompick().
15401: ':'.$res->randomout().
15402: ':'.$res->encrypted().
15403: ':'.$res->randomorder().
15404: ':'.$res->is_page();
15405: }
15406: }
15407: }
15408: $path =~ s/^\&//;
15409: my $maptitle = $mapresobj->title();
15410: if ($mapurl eq 'default') {
1.1129 raeburn 15411: $maptitle = 'Main Content';
1.1101 raeburn 15412: }
15413: $path .= (($path ne '')? '&' : '').
15414: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 15415: &escape($maptitle).
1.1101 raeburn 15416: ':'.$mapresobj->randompick().
15417: ':'.$mapresobj->randomout().
15418: ':'.$mapresobj->encrypted().
15419: ':'.$mapresobj->randomorder().
15420: ':'.$mapresobj->is_page();
15421: } else {
15422: my $maptitle = &Apache::lonnet::gettitle($mapurl);
15423: my $ispage = (($type eq 'page')? 1 : '');
15424: if ($mapurl eq 'default') {
1.1129 raeburn 15425: $maptitle = 'Main Content';
1.1101 raeburn 15426: }
15427: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 15428: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 15429: }
15430: unless ($mapurl eq 'default') {
15431: $path = 'default&'.
1.1146 raeburn 15432: &escape('Main Content').
1.1101 raeburn 15433: ':::::&'.$path;
15434: }
15435: return $path;
15436: }
15437:
1.1094 raeburn 15438: sub captcha_display {
15439: my ($context,$lonhost) = @_;
15440: my ($output,$error);
15441: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 15442: if ($captcha eq 'original') {
1.1094 raeburn 15443: $output = &create_captcha();
15444: unless ($output) {
1.1172 raeburn 15445: $error = 'captcha';
1.1094 raeburn 15446: }
15447: } elsif ($captcha eq 'recaptcha') {
15448: $output = &create_recaptcha($pubkey);
15449: unless ($output) {
1.1172 raeburn 15450: $error = 'recaptcha';
1.1094 raeburn 15451: }
15452: }
1.1176 raeburn 15453: return ($output,$error,$captcha);
1.1094 raeburn 15454: }
15455:
15456: sub captcha_response {
15457: my ($context,$lonhost) = @_;
15458: my ($captcha_chk,$captcha_error);
15459: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 15460: if ($captcha eq 'original') {
1.1094 raeburn 15461: ($captcha_chk,$captcha_error) = &check_captcha();
15462: } elsif ($captcha eq 'recaptcha') {
15463: $captcha_chk = &check_recaptcha($privkey);
15464: } else {
15465: $captcha_chk = 1;
15466: }
15467: return ($captcha_chk,$captcha_error);
15468: }
15469:
15470: sub get_captcha_config {
15471: my ($context,$lonhost) = @_;
1.1095 raeburn 15472: my ($captcha,$pubkey,$privkey,$hashtocheck);
1.1094 raeburn 15473: my $hostname = &Apache::lonnet::hostname($lonhost);
15474: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
15475: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 15476: if ($context eq 'usercreation') {
15477: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
15478: if (ref($domconfig{$context}) eq 'HASH') {
15479: $hashtocheck = $domconfig{$context}{'cancreate'};
15480: if (ref($hashtocheck) eq 'HASH') {
15481: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
15482: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
15483: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
15484: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
15485: }
15486: if ($privkey && $pubkey) {
15487: $captcha = 'recaptcha';
15488: } else {
15489: $captcha = 'original';
15490: }
15491: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
15492: $captcha = 'original';
15493: }
1.1094 raeburn 15494: }
1.1095 raeburn 15495: } else {
15496: $captcha = 'captcha';
15497: }
15498: } elsif ($context eq 'login') {
15499: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
15500: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
15501: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
15502: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 15503: if ($privkey && $pubkey) {
15504: $captcha = 'recaptcha';
1.1095 raeburn 15505: } else {
15506: $captcha = 'original';
1.1094 raeburn 15507: }
1.1095 raeburn 15508: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
15509: $captcha = 'original';
1.1094 raeburn 15510: }
15511: }
15512: return ($captcha,$pubkey,$privkey);
15513: }
15514:
15515: sub create_captcha {
15516: my %captcha_params = &captcha_settings();
15517: my ($output,$maxtries,$tries) = ('',10,0);
15518: while ($tries < $maxtries) {
15519: $tries ++;
15520: my $captcha = Authen::Captcha->new (
15521: output_folder => $captcha_params{'output_dir'},
15522: data_folder => $captcha_params{'db_dir'},
15523: );
15524: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
15525:
15526: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
15527: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
15528: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 15529: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
15530: '<br />'.
15531: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 15532: last;
15533: }
15534: }
15535: return $output;
15536: }
15537:
15538: sub captcha_settings {
15539: my %captcha_params = (
15540: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
15541: www_output_dir => "/captchaspool",
15542: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
15543: numchars => '5',
15544: );
15545: return %captcha_params;
15546: }
15547:
15548: sub check_captcha {
15549: my ($captcha_chk,$captcha_error);
15550: my $code = $env{'form.code'};
15551: my $md5sum = $env{'form.crypt'};
15552: my %captcha_params = &captcha_settings();
15553: my $captcha = Authen::Captcha->new(
15554: output_folder => $captcha_params{'output_dir'},
15555: data_folder => $captcha_params{'db_dir'},
15556: );
1.1109 raeburn 15557: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 15558: my %captcha_hash = (
15559: 0 => 'Code not checked (file error)',
15560: -1 => 'Failed: code expired',
15561: -2 => 'Failed: invalid code (not in database)',
15562: -3 => 'Failed: invalid code (code does not match crypt)',
15563: );
15564: if ($captcha_chk != 1) {
15565: $captcha_error = $captcha_hash{$captcha_chk}
15566: }
15567: return ($captcha_chk,$captcha_error);
15568: }
15569:
15570: sub create_recaptcha {
15571: my ($pubkey) = @_;
1.1153 raeburn 15572: my $use_ssl;
15573: if ($ENV{'SERVER_PORT'} == 443) {
15574: $use_ssl = 1;
15575: }
1.1094 raeburn 15576: my $captcha = Captcha::reCAPTCHA->new;
15577: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1153 raeburn 15578: $captcha->get_html($pubkey,undef,$use_ssl).
1.1094 raeburn 15579: &mt('If either word is hard to read, [_1] will replace them.',
1.1133 raeburn 15580: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1094 raeburn 15581: '<br /><br />';
15582: }
15583:
15584: sub check_recaptcha {
15585: my ($privkey) = @_;
15586: my $captcha_chk;
15587: my $captcha = Captcha::reCAPTCHA->new;
15588: my $captcha_result =
15589: $captcha->check_answer(
15590: $privkey,
15591: $ENV{'REMOTE_ADDR'},
15592: $env{'form.recaptcha_challenge_field'},
15593: $env{'form.recaptcha_response_field'},
15594: );
15595: if ($captcha_result->{is_valid}) {
15596: $captcha_chk = 1;
15597: }
15598: return $captcha_chk;
15599: }
15600:
1.1174 raeburn 15601: sub emailusername_info {
1.1177 raeburn 15602: my @fields = ('firstname','lastname','institution','web','location','officialemail');
1.1174 raeburn 15603: my %titles = &Apache::lonlocal::texthash (
15604: lastname => 'Last Name',
15605: firstname => 'First Name',
15606: institution => 'School/college/university',
15607: location => "School's city, state/province, country",
15608: web => "School's web address",
15609: officialemail => 'E-mail address at institution (if different)',
15610: );
15611: return (\@fields,\%titles);
15612: }
15613:
1.1161 raeburn 15614: sub cleanup_html {
15615: my ($incoming) = @_;
15616: my $outgoing;
15617: if ($incoming ne '') {
15618: $outgoing = $incoming;
15619: $outgoing =~ s/;/;/g;
15620: $outgoing =~ s/\#/#/g;
15621: $outgoing =~ s/\&/&/g;
15622: $outgoing =~ s/</</g;
15623: $outgoing =~ s/>/>/g;
15624: $outgoing =~ s/\(/(/g;
15625: $outgoing =~ s/\)/)/g;
15626: $outgoing =~ s/"/"/g;
15627: $outgoing =~ s/'/'/g;
15628: $outgoing =~ s/\$/$/g;
15629: $outgoing =~ s{/}{/}g;
15630: $outgoing =~ s/=/=/g;
15631: $outgoing =~ s/\\/\/g
15632: }
15633: return $outgoing;
15634: }
15635:
1.1174 raeburn 15636: # Use:
15637: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
15638: #
15639: ##################################################
15640: # password associated functions #
15641: ##################################################
15642: sub des_keys {
15643: # Make a new key for DES encryption.
15644: # Each key has two parts which are returned separately.
15645: # Please note: Each key must be passed through the &hex function
15646: # before it is output to the web browser. The hex versions cannot
15647: # be used to decrypt.
15648: my @hexstr=('0','1','2','3','4','5','6','7',
15649: '8','9','a','b','c','d','e','f');
15650: my $lkey='';
15651: for (0..7) {
15652: $lkey.=$hexstr[rand(15)];
15653: }
15654: my $ukey='';
15655: for (0..7) {
15656: $ukey.=$hexstr[rand(15)];
15657: }
15658: return ($lkey,$ukey);
15659: }
15660:
15661: sub des_decrypt {
15662: my ($key,$cyphertext) = @_;
15663: my $keybin=pack("H16",$key);
15664: my $cypher;
15665: if ($Crypt::DES::VERSION>=2.03) {
15666: $cypher=new Crypt::DES $keybin;
15667: } else {
15668: $cypher=new DES $keybin;
15669: }
15670: my $plaintext=
15671: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
15672: $plaintext.=
15673: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
15674: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
15675: return $plaintext;
15676: }
15677:
1.112 bowersj2 15678: 1;
15679: __END__;
1.41 ng 15680:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>