Annotation of loncom/interface/loncommon.pm, revision 1.1285
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1285 ! raeburn 4: # $Id: loncommon.pm,v 1.1284 2017/07/10 12:48:41 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.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.1280 raeburn 74: use LONCAPA::LWPReq;
1.657 raeburn 75: use DateTime::TimeZone;
1.1241 raeburn 76: use DateTime::Locale;
1.1220 raeburn 77: use Encode();
1.1091 foxr 78: use Text::Aspell;
1.1094 raeburn 79: use Authen::Captcha;
80: use Captcha::reCAPTCHA;
1.1234 raeburn 81: use JSON::DWIW;
82: use LWP::UserAgent;
1.1174 raeburn 83: use Crypt::DES;
84: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 85: use MIME::Lite;
86: use MIME::Types;
1.117 www 87:
1.517 raeburn 88: # ---------------------------------------------- Designs
89: use vars qw(%defaultdesign);
90:
1.22 www 91: my $readit;
92:
1.517 raeburn 93:
1.157 matthew 94: ##
95: ## Global Variables
96: ##
1.46 matthew 97:
1.643 foxr 98:
99: # ----------------------------------------------- SSI with retries:
100: #
101:
102: =pod
103:
1.648 raeburn 104: =head1 Server Side include with retries:
1.643 foxr 105:
106: =over 4
107:
1.648 raeburn 108: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 109:
110: Performs an ssi with some number of retries. Retries continue either
111: until the result is ok or until the retry count supplied by the
112: caller is exhausted.
113:
114: Inputs:
1.648 raeburn 115:
116: =over 4
117:
1.643 foxr 118: resource - Identifies the resource to insert.
1.648 raeburn 119:
1.643 foxr 120: retries - Count of the number of retries allowed.
1.648 raeburn 121:
1.643 foxr 122: form - Hash that identifies the rendering options.
123:
1.648 raeburn 124: =back
125:
126: Returns:
127:
128: =over 4
129:
1.643 foxr 130: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 131:
1.643 foxr 132: response - The response from the last attempt (which may or may not have been successful.
133:
1.648 raeburn 134: =back
135:
136: =back
137:
1.643 foxr 138: =cut
139:
140: sub ssi_with_retries {
141: my ($resource, $retries, %form) = @_;
142:
143:
144: my $ok = 0; # True if we got a good response.
145: my $content;
146: my $response;
147:
148: # Try to get the ssi done. within the retries count:
149:
150: do {
151: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
152: $ok = $response->is_success;
1.650 www 153: if (!$ok) {
154: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
155: }
1.643 foxr 156: $retries--;
157: } while (!$ok && ($retries > 0));
158:
159: if (!$ok) {
160: $content = ''; # On error return an empty content.
161: }
162: return ($content, $response);
163:
164: }
165:
166:
167:
1.20 www 168: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 169: my %language;
1.124 www 170: my %supported_language;
1.1088 foxr 171: my %supported_codes;
1.1048 foxr 172: my %latex_language; # For choosing hyphenation in <transl..>
173: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 174: my %cprtag;
1.192 taceyjo1 175: my %scprtag;
1.351 www 176: my %fe; my %fd; my %fm;
1.41 ng 177: my %category_extensions;
1.12 harris41 178:
1.46 matthew 179: # ---------------------------------------------- Thesaurus variables
1.144 matthew 180: #
181: # %Keywords:
182: # A hash used by &keyword to determine if a word is considered a keyword.
183: # $thesaurus_db_file
184: # Scalar containing the full path to the thesaurus database.
1.46 matthew 185:
186: my %Keywords;
187: my $thesaurus_db_file;
188:
1.144 matthew 189: #
190: # Initialize values from language.tab, copyright.tab, filetypes.tab,
191: # thesaurus.tab, and filecategories.tab.
192: #
1.18 www 193: BEGIN {
1.46 matthew 194: # Variable initialization
195: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
196: #
1.22 www 197: unless ($readit) {
1.12 harris41 198: # ------------------------------------------------------------------- languages
199: {
1.158 raeburn 200: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
201: '/language.tab';
202: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
1.1088 foxr 206: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 207: $language{$key}=$val.' - '.$enc;
208: if ($sup) {
209: $supported_language{$key}=$sup;
1.1088 foxr 210: $supported_codes{$key} = $code;
1.158 raeburn 211: }
1.1048 foxr 212: if ($latex) {
213: $latex_language_bykey{$key} = $latex;
1.1088 foxr 214: $latex_language{$code} = $latex;
1.1048 foxr 215: }
1.158 raeburn 216: }
217: close($fh);
218: }
1.12 harris41 219: }
220: # ------------------------------------------------------------------ copyrights
221: {
1.158 raeburn 222: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
223: '/copyright.tab';
224: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 225: while (my $line = <$fh>) {
226: next if ($line=~/^\#/);
227: chomp($line);
228: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 229: $cprtag{$key}=$val;
230: }
231: close($fh);
232: }
1.12 harris41 233: }
1.351 www 234: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 235: {
236: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
237: '/source_copyright.tab';
238: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 239: while (my $line = <$fh>) {
240: next if ($line =~ /^\#/);
241: chomp($line);
242: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 243: $scprtag{$key}=$val;
244: }
245: close($fh);
246: }
247: }
1.63 www 248:
1.517 raeburn 249: # -------------------------------------------------------------- default domain designs
1.63 www 250: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 251: my $designfile = $designdir.'/default.tab';
252: if ( open (my $fh,"<$designfile") ) {
253: while (my $line = <$fh>) {
254: next if ($line =~ /^\#/);
255: chomp($line);
256: my ($key,$val)=(split(/\=/,$line));
257: if ($val) { $defaultdesign{$key}=$val; }
258: }
259: close($fh);
1.63 www 260: }
261:
1.15 harris41 262: # ------------------------------------------------------------- file categories
263: {
1.158 raeburn 264: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
265: '/filecategories.tab';
266: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 267: while (my $line = <$fh>) {
268: next if ($line =~ /^\#/);
269: chomp($line);
270: my ($extension,$category)=(split(/\s+/,$line,2));
1.1263 raeburn 271: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 272: }
273: close($fh);
274: }
275:
1.15 harris41 276: }
1.12 harris41 277: # ------------------------------------------------------------------ file types
278: {
1.158 raeburn 279: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
280: '/filetypes.tab';
281: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 282: while (my $line = <$fh>) {
283: next if ($line =~ /^\#/);
284: chomp($line);
285: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 286: if ($descr ne '') {
287: $fe{$ending}=lc($emb);
288: $fd{$ending}=$descr;
1.351 www 289: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 290: }
291: }
292: close($fh);
293: }
1.12 harris41 294: }
1.22 www 295: &Apache::lonnet::logthis(
1.705 tempelho 296: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 297: $readit=1;
1.46 matthew 298: } # end of unless($readit)
1.32 matthew 299:
300: }
1.112 bowersj2 301:
1.42 matthew 302: ###############################################################
303: ## HTML and Javascript Helper Functions ##
304: ###############################################################
305:
306: =pod
307:
1.112 bowersj2 308: =head1 HTML and Javascript Functions
1.42 matthew 309:
1.112 bowersj2 310: =over 4
311:
1.648 raeburn 312: =item * &browser_and_searcher_javascript()
1.112 bowersj2 313:
314: X<browsing, javascript>X<searching, javascript>Returns a string
315: containing javascript with two functions, C<openbrowser> and
316: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
317: tags.
1.42 matthew 318:
1.648 raeburn 319: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 320:
321: inputs: formname, elementname, only, omit
322:
323: formname and elementname indicate the name of the html form and name of
324: the element that the results of the browsing selection are to be placed in.
325:
326: Specifying 'only' will restrict the browser to displaying only files
1.185 www 327: with the given extension. Can be a comma separated list.
1.42 matthew 328:
329: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 330: with the given extension. Can be a comma separated list.
1.42 matthew 331:
1.648 raeburn 332: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 333:
334: Inputs: formname, elementname
335:
336: formname and elementname specify the name of the html form and the name
337: of the element the selection from the search results will be placed in.
1.542 raeburn 338:
1.42 matthew 339: =cut
340:
341: sub browser_and_searcher_javascript {
1.199 albertel 342: my ($mode)=@_;
343: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 344: my $resurl=&escape_single(&lastresurl());
1.42 matthew 345: return <<END;
1.219 albertel 346: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 347: var editbrowser = null;
1.135 albertel 348: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 349: var url = '$resurl/?';
1.42 matthew 350: if (editbrowser == null) {
351: url += 'launch=1&';
352: }
353: url += 'catalogmode=interactive&';
1.199 albertel 354: url += 'mode=$mode&';
1.611 albertel 355: url += 'inhibitmenu=yes&';
1.42 matthew 356: url += 'form=' + formname + '&';
357: if (only != null) {
358: url += 'only=' + only + '&';
1.217 albertel 359: } else {
360: url += 'only=&';
361: }
1.42 matthew 362: if (omit != null) {
363: url += 'omit=' + omit + '&';
1.217 albertel 364: } else {
365: url += 'omit=&';
366: }
1.135 albertel 367: if (titleelement != null) {
368: url += 'titleelement=' + titleelement + '&';
1.217 albertel 369: } else {
370: url += 'titleelement=&';
371: }
1.42 matthew 372: url += 'element=' + elementname + '';
373: var title = 'Browser';
1.435 albertel 374: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 375: options += ',width=700,height=600';
376: editbrowser = open(url,title,options,'1');
377: editbrowser.focus();
378: }
379: var editsearcher;
1.135 albertel 380: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 381: var url = '/adm/searchcat?';
382: if (editsearcher == null) {
383: url += 'launch=1&';
384: }
385: url += 'catalogmode=interactive&';
1.199 albertel 386: url += 'mode=$mode&';
1.42 matthew 387: url += 'form=' + formname + '&';
1.135 albertel 388: if (titleelement != null) {
389: url += 'titleelement=' + titleelement + '&';
1.217 albertel 390: } else {
391: url += 'titleelement=&';
392: }
1.42 matthew 393: url += 'element=' + elementname + '';
394: var title = 'Search';
1.435 albertel 395: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 396: options += ',width=700,height=600';
397: editsearcher = open(url,title,options,'1');
398: editsearcher.focus();
399: }
1.219 albertel 400: // END LON-CAPA Internal -->
1.42 matthew 401: END
1.170 www 402: }
403:
404: sub lastresurl {
1.258 albertel 405: if ($env{'environment.lastresurl'}) {
406: return $env{'environment.lastresurl'}
1.170 www 407: } else {
408: return '/res';
409: }
410: }
411:
412: sub storeresurl {
413: my $resurl=&Apache::lonnet::clutter(shift);
414: unless ($resurl=~/^\/res/) { return 0; }
415: $resurl=~s/\/$//;
416: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 417: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 418: return 1;
1.42 matthew 419: }
420:
1.74 www 421: sub studentbrowser_javascript {
1.111 www 422: unless (
1.258 albertel 423: (($env{'request.course.id'}) &&
1.302 albertel 424: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
425: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
426: '/'.$env{'request.course.sec'})
427: ))
1.258 albertel 428: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 429: ) { return ''; }
1.74 www 430: return (<<'ENDSTDBRW');
1.776 bisitz 431: <script type="text/javascript" language="Javascript">
1.824 bisitz 432: // <![CDATA[
1.74 www 433: var stdeditbrowser;
1.999 www 434: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 435: var url = '/adm/pickstudent?';
436: var filter;
1.558 albertel 437: if (!ignorefilter) {
438: eval('filter=document.'+formname+'.'+uname+'.value;');
439: }
1.74 www 440: if (filter != null) {
441: if (filter != '') {
442: url += 'filter='+filter+'&';
443: }
444: }
445: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 446: '&udomelement='+udom+
447: '&clicker='+clicker;
1.111 www 448: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 449: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 450: var title = 'Student_Browser';
1.74 www 451: var options = 'scrollbars=1,resizable=1,menubar=0';
452: options += ',width=700,height=600';
453: stdeditbrowser = open(url,title,options,'1');
454: stdeditbrowser.focus();
455: }
1.824 bisitz 456: // ]]>
1.74 www 457: </script>
458: ENDSTDBRW
459: }
1.42 matthew 460:
1.1003 www 461: sub resourcebrowser_javascript {
462: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 463: return (<<'ENDRESBRW');
1.1003 www 464: <script type="text/javascript" language="Javascript">
465: // <![CDATA[
466: var reseditbrowser;
1.1004 www 467: function openresbrowser(formname,reslink) {
1.1005 www 468: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 469: var title = 'Resource_Browser';
470: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 471: options += ',width=700,height=500';
1.1004 www 472: reseditbrowser = open(url,title,options,'1');
473: reseditbrowser.focus();
1.1003 www 474: }
475: // ]]>
476: </script>
1.1004 www 477: ENDRESBRW
1.1003 www 478: }
479:
1.74 www 480: sub selectstudent_link {
1.999 www 481: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
482: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
483: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
484: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 485: if ($env{'request.course.id'}) {
1.302 albertel 486: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
487: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
488: '/'.$env{'request.course.sec'})) {
1.111 www 489: return '';
490: }
1.999 www 491: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 492: if ($courseadvonly) {
493: $callargs .= ",'',1,1";
494: }
495: return '<span class="LC_nobreak">'.
496: '<a href="javascript:openstdbrowser('.$callargs.');">'.
497: &mt('Select User').'</a></span>';
1.74 www 498: }
1.258 albertel 499: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 500: $callargs .= ",'',1";
1.793 raeburn 501: return '<span class="LC_nobreak">'.
502: '<a href="javascript:openstdbrowser('.$callargs.');">'.
503: &mt('Select User').'</a></span>';
1.111 www 504: }
505: return '';
1.91 www 506: }
507:
1.1004 www 508: sub selectresource_link {
509: my ($form,$reslink,$arg)=@_;
510:
511: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
512: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
513: unless ($env{'request.course.id'}) { return $arg; }
514: return '<span class="LC_nobreak">'.
515: '<a href="javascript:openresbrowser('.$callargs.');">'.
516: $arg.'</a></span>';
517: }
518:
519:
520:
1.653 raeburn 521: sub authorbrowser_javascript {
522: return <<"ENDAUTHORBRW";
1.776 bisitz 523: <script type="text/javascript" language="JavaScript">
1.824 bisitz 524: // <![CDATA[
1.653 raeburn 525: var stdeditbrowser;
526:
527: function openauthorbrowser(formname,udom) {
528: var url = '/adm/pickauthor?';
529: url += 'form='+formname+'&roledom='+udom;
530: var title = 'Author_Browser';
531: var options = 'scrollbars=1,resizable=1,menubar=0';
532: options += ',width=700,height=600';
533: stdeditbrowser = open(url,title,options,'1');
534: stdeditbrowser.focus();
535: }
536:
1.824 bisitz 537: // ]]>
1.653 raeburn 538: </script>
539: ENDAUTHORBRW
540: }
541:
1.91 www 542: sub coursebrowser_javascript {
1.1116 raeburn 543: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 544: $credits_element,$instcode) = @_;
1.932 raeburn 545: my $wintitle = 'Course_Browser';
1.931 raeburn 546: if ($crstype eq 'Community') {
1.932 raeburn 547: $wintitle = 'Community_Browser';
1.909 raeburn 548: }
1.876 raeburn 549: my $id_functions = &javascript_index_functions();
550: my $output = '
1.776 bisitz 551: <script type="text/javascript" language="JavaScript">
1.824 bisitz 552: // <![CDATA[
1.468 raeburn 553: var stdeditbrowser;'."\n";
1.876 raeburn 554:
555: $output .= <<"ENDSTDBRW";
1.909 raeburn 556: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 557: var url = '/adm/pickcourse?';
1.895 raeburn 558: var formid = getFormIdByName(formname);
1.876 raeburn 559: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 560: if (domainfilter != null) {
561: if (domainfilter != '') {
562: url += 'domainfilter='+domainfilter+'&';
563: }
564: }
1.91 www 565: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 566: '&cdomelement='+udom+
567: '&cnameelement='+desc;
1.468 raeburn 568: if (extra_element !=null && extra_element != '') {
1.594 raeburn 569: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 570: url += '&roleelement='+extra_element;
571: if (domainfilter == null || domainfilter == '') {
572: url += '&domainfilter='+extra_element;
573: }
1.234 raeburn 574: }
1.468 raeburn 575: else {
576: if (formname == 'portform') {
577: url += '&setroles='+extra_element;
1.800 raeburn 578: } else {
579: if (formname == 'rules') {
580: url += '&fixeddom='+extra_element;
581: }
1.468 raeburn 582: }
583: }
1.230 raeburn 584: }
1.909 raeburn 585: if (type != null && type != '') {
586: url += '&type='+type;
587: }
588: if (type_elem != null && type_elem != '') {
589: url += '&typeelement='+type_elem;
590: }
1.872 raeburn 591: if (formname == 'ccrs') {
592: var ownername = document.forms[formid].ccuname.value;
593: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 594: url += '&cloner='+ownername+':'+ownerdom;
595: if (type == 'Course') {
596: url += '&crscode='+document.forms[formid].crscode.value;
597: }
1.1221 raeburn 598: }
599: if (formname == 'requestcrs') {
600: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 601: }
1.293 raeburn 602: if (multflag !=null && multflag != '') {
603: url += '&multiple='+multflag;
604: }
1.909 raeburn 605: var title = '$wintitle';
1.91 www 606: var options = 'scrollbars=1,resizable=1,menubar=0';
607: options += ',width=700,height=600';
608: stdeditbrowser = open(url,title,options,'1');
609: stdeditbrowser.focus();
610: }
1.876 raeburn 611: $id_functions
612: ENDSTDBRW
1.1116 raeburn 613: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
614: $output .= &setsec_javascript($sec_element,$formname,$role_element,
615: $credits_element);
1.876 raeburn 616: }
617: $output .= '
618: // ]]>
619: </script>';
620: return $output;
621: }
622:
623: sub javascript_index_functions {
624: return <<"ENDJS";
625:
626: function getFormIdByName(formname) {
627: for (var i=0;i<document.forms.length;i++) {
628: if (document.forms[i].name == formname) {
629: return i;
630: }
631: }
632: return -1;
633: }
634:
635: function getIndexByName(formid,item) {
636: for (var i=0;i<document.forms[formid].elements.length;i++) {
637: if (document.forms[formid].elements[i].name == item) {
638: return i;
639: }
640: }
641: return -1;
642: }
1.468 raeburn 643:
1.876 raeburn 644: function getDomainFromSelectbox(formname,udom) {
645: var userdom;
646: var formid = getFormIdByName(formname);
647: if (formid > -1) {
648: var domid = getIndexByName(formid,udom);
649: if (domid > -1) {
650: if (document.forms[formid].elements[domid].type == 'select-one') {
651: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
652: }
653: if (document.forms[formid].elements[domid].type == 'hidden') {
654: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 655: }
656: }
657: }
1.876 raeburn 658: return userdom;
659: }
660:
661: ENDJS
1.468 raeburn 662:
1.876 raeburn 663: }
664:
1.1017 raeburn 665: sub javascript_array_indexof {
1.1018 raeburn 666: return <<ENDJS;
1.1017 raeburn 667: <script type="text/javascript" language="JavaScript">
668: // <![CDATA[
669:
670: if (!Array.prototype.indexOf) {
671: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
672: "use strict";
673: if (this === void 0 || this === null) {
674: throw new TypeError();
675: }
676: var t = Object(this);
677: var len = t.length >>> 0;
678: if (len === 0) {
679: return -1;
680: }
681: var n = 0;
682: if (arguments.length > 0) {
683: n = Number(arguments[1]);
1.1088 foxr 684: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 685: n = 0;
686: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
687: n = (n > 0 || -1) * Math.floor(Math.abs(n));
688: }
689: }
690: if (n >= len) {
691: return -1;
692: }
693: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
694: for (; k < len; k++) {
695: if (k in t && t[k] === searchElement) {
696: return k;
697: }
698: }
699: return -1;
700: }
701: }
702:
703: // ]]>
704: </script>
705:
706: ENDJS
707:
708: }
709:
1.876 raeburn 710: sub userbrowser_javascript {
711: my $id_functions = &javascript_index_functions();
712: return <<"ENDUSERBRW";
713:
1.888 raeburn 714: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 715: var url = '/adm/pickuser?';
716: var userdom = getDomainFromSelectbox(formname,udom);
717: if (userdom != null) {
718: if (userdom != '') {
719: url += 'srchdom='+userdom+'&';
720: }
721: }
722: url += 'form=' + formname + '&unameelement='+uname+
723: '&udomelement='+udom+
724: '&ulastelement='+ulast+
725: '&ufirstelement='+ufirst+
726: '&uemailelement='+uemail+
1.881 raeburn 727: '&hideudomelement='+hideudom+
728: '&coursedom='+crsdom;
1.888 raeburn 729: if ((caller != null) && (caller != undefined)) {
730: url += '&caller='+caller;
731: }
1.876 raeburn 732: var title = 'User_Browser';
733: var options = 'scrollbars=1,resizable=1,menubar=0';
734: options += ',width=700,height=600';
735: var stdeditbrowser = open(url,title,options,'1');
736: stdeditbrowser.focus();
737: }
738:
1.888 raeburn 739: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 740: var formid = getFormIdByName(formname);
741: if (formid > -1) {
1.888 raeburn 742: var unameid = getIndexByName(formid,uname);
1.876 raeburn 743: var domid = getIndexByName(formid,udom);
744: var hidedomid = getIndexByName(formid,origdom);
745: if (hidedomid > -1) {
746: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 747: var unameval = document.forms[formid].elements[unameid].value;
748: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
749: if (domid > -1) {
750: var slct = document.forms[formid].elements[domid];
751: if (slct.type == 'select-one') {
752: var i;
753: for (i=0;i<slct.length;i++) {
754: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
755: }
756: }
757: if (slct.type == 'hidden') {
758: slct.value = fixeddom;
1.876 raeburn 759: }
760: }
1.468 raeburn 761: }
762: }
763: }
1.876 raeburn 764: return;
765: }
766:
767: $id_functions
768: ENDUSERBRW
1.468 raeburn 769: }
770:
771: sub setsec_javascript {
1.1116 raeburn 772: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 773: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
774: $communityrolestr);
775: if ($role_element ne '') {
776: my @allroles = ('st','ta','ep','in','ad');
777: foreach my $crstype ('Course','Community') {
778: if ($crstype eq 'Community') {
779: foreach my $role (@allroles) {
780: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
781: }
782: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
783: } else {
784: foreach my $role (@allroles) {
785: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
786: }
787: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
788: }
789: }
790: $rolestr = '"'.join('","',@allroles).'"';
791: $courserolestr = '"'.join('","',@courserolenames).'"';
792: $communityrolestr = '"'.join('","',@communityrolenames).'"';
793: }
1.468 raeburn 794: my $setsections = qq|
795: function setSect(sectionlist) {
1.629 raeburn 796: var sectionsArray = new Array();
797: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
798: sectionsArray = sectionlist.split(",");
799: }
1.468 raeburn 800: var numSections = sectionsArray.length;
801: document.$formname.$sec_element.length = 0;
802: if (numSections == 0) {
803: document.$formname.$sec_element.multiple=false;
804: document.$formname.$sec_element.size=1;
805: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
806: } else {
807: if (numSections == 1) {
808: document.$formname.$sec_element.multiple=false;
809: document.$formname.$sec_element.size=1;
810: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
811: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
812: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
813: } else {
814: for (var i=0; i<numSections; i++) {
815: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
816: }
817: document.$formname.$sec_element.multiple=true
818: if (numSections < 3) {
819: document.$formname.$sec_element.size=numSections;
820: } else {
821: document.$formname.$sec_element.size=3;
822: }
823: document.$formname.$sec_element.options[0].selected = false
824: }
825: }
1.91 www 826: }
1.905 raeburn 827:
828: function setRole(crstype) {
1.468 raeburn 829: |;
1.905 raeburn 830: if ($role_element eq '') {
831: $setsections .= ' return;
832: }
833: ';
834: } else {
835: $setsections .= qq|
836: var elementLength = document.$formname.$role_element.length;
837: var allroles = Array($rolestr);
838: var courserolenames = Array($courserolestr);
839: var communityrolenames = Array($communityrolestr);
840: if (elementLength != undefined) {
841: if (document.$formname.$role_element.options[5].value == 'cc') {
842: if (crstype == 'Course') {
843: return;
844: } else {
845: allroles[5] = 'co';
846: for (var i=0; i<6; i++) {
847: document.$formname.$role_element.options[i].value = allroles[i];
848: document.$formname.$role_element.options[i].text = communityrolenames[i];
849: }
850: }
851: } else {
852: if (crstype == 'Community') {
853: return;
854: } else {
855: allroles[5] = 'cc';
856: for (var i=0; i<6; i++) {
857: document.$formname.$role_element.options[i].value = allroles[i];
858: document.$formname.$role_element.options[i].text = courserolenames[i];
859: }
860: }
861: }
862: }
863: return;
864: }
865: |;
866: }
1.1116 raeburn 867: if ($credits_element) {
868: $setsections .= qq|
869: function setCredits(defaultcredits) {
870: document.$formname.$credits_element.value = defaultcredits;
871: return;
872: }
873: |;
874: }
1.468 raeburn 875: return $setsections;
876: }
877:
1.91 www 878: sub selectcourse_link {
1.909 raeburn 879: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
880: $typeelement) = @_;
881: my $type = $selecttype;
1.871 raeburn 882: my $linktext = &mt('Select Course');
883: if ($selecttype eq 'Community') {
1.909 raeburn 884: $linktext = &mt('Select Community');
1.1239 raeburn 885: } elsif ($selecttype eq 'Placement') {
886: $linktext = &mt('Select Placement Test');
1.906 raeburn 887: } elsif ($selecttype eq 'Course/Community') {
888: $linktext = &mt('Select Course/Community');
1.909 raeburn 889: $type = '';
1.1019 raeburn 890: } elsif ($selecttype eq 'Select') {
891: $linktext = &mt('Select');
892: $type = '';
1.871 raeburn 893: }
1.787 bisitz 894: return '<span class="LC_nobreak">'
895: ."<a href='"
896: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
897: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 898: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 899: ."'>".$linktext.'</a>'
1.787 bisitz 900: .'</span>';
1.74 www 901: }
1.42 matthew 902:
1.653 raeburn 903: sub selectauthor_link {
904: my ($form,$udom)=@_;
905: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
906: &mt('Select Author').'</a>';
907: }
908:
1.876 raeburn 909: sub selectuser_link {
1.881 raeburn 910: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 911: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 912: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 913: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 914: ');">'.$linktext.'</a>';
1.876 raeburn 915: }
916:
1.273 raeburn 917: sub check_uncheck_jscript {
918: my $jscript = <<"ENDSCRT";
919: function checkAll(field) {
920: if (field.length > 0) {
921: for (i = 0; i < field.length; i++) {
1.1093 raeburn 922: if (!field[i].disabled) {
923: field[i].checked = true;
924: }
1.273 raeburn 925: }
926: } else {
1.1093 raeburn 927: if (!field.disabled) {
928: field.checked = true;
929: }
1.273 raeburn 930: }
931: }
932:
933: function uncheckAll(field) {
934: if (field.length > 0) {
935: for (i = 0; i < field.length; i++) {
936: field[i].checked = false ;
1.543 albertel 937: }
938: } else {
1.273 raeburn 939: field.checked = false ;
940: }
941: }
942: ENDSCRT
943: return $jscript;
944: }
945:
1.656 www 946: sub select_timezone {
1.1256 raeburn 947: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
948: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 949: if ($includeempty) {
950: $output .= '<option value=""';
951: if (($selected eq '') || ($selected eq 'local')) {
952: $output .= ' selected="selected" ';
953: }
954: $output .= '> </option>';
955: }
1.657 raeburn 956: my @timezones = DateTime::TimeZone->all_names;
957: foreach my $tzone (@timezones) {
958: $output.= '<option value="'.$tzone.'"';
959: if ($tzone eq $selected) {
960: $output.=' selected="selected"';
961: }
962: $output.=">$tzone</option>\n";
1.656 www 963: }
964: $output.="</select>";
965: return $output;
966: }
1.273 raeburn 967:
1.687 raeburn 968: sub select_datelocale {
1.1256 raeburn 969: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
970: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 971: if ($includeempty) {
972: $output .= '<option value=""';
973: if ($selected eq '') {
974: $output .= ' selected="selected" ';
975: }
976: $output .= '> </option>';
977: }
1.1241 raeburn 978: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 979: my (@possibles,%locale_names);
1.1241 raeburn 980: my @locales = DateTime::Locale->ids();
981: foreach my $id (@locales) {
982: if ($id ne '') {
983: my ($en_terr,$native_terr);
984: my $loc = DateTime::Locale->load($id);
985: if (ref($loc)) {
986: $en_terr = $loc->name();
987: $native_terr = $loc->native_name();
1.687 raeburn 988: if (grep(/^en$/,@languages) || !@languages) {
989: if ($en_terr ne '') {
990: $locale_names{$id} = '('.$en_terr.')';
991: } elsif ($native_terr ne '') {
992: $locale_names{$id} = $native_terr;
993: }
994: } else {
995: if ($native_terr ne '') {
996: $locale_names{$id} = $native_terr.' ';
997: } elsif ($en_terr ne '') {
998: $locale_names{$id} = '('.$en_terr.')';
999: }
1000: }
1.1220 raeburn 1001: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1002: push(@possibles,$id);
1003: }
1.687 raeburn 1004: }
1005: }
1006: foreach my $item (sort(@possibles)) {
1007: $output.= '<option value="'.$item.'"';
1008: if ($item eq $selected) {
1009: $output.=' selected="selected"';
1010: }
1011: $output.=">$item";
1012: if ($locale_names{$item} ne '') {
1.1220 raeburn 1013: $output.=' '.$locale_names{$item};
1.687 raeburn 1014: }
1015: $output.="</option>\n";
1016: }
1017: $output.="</select>";
1018: return $output;
1019: }
1020:
1.792 raeburn 1021: sub select_language {
1.1256 raeburn 1022: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1023: my %langchoices;
1024: if ($includeempty) {
1.1117 raeburn 1025: %langchoices = ('' => 'No language preference');
1.792 raeburn 1026: }
1027: foreach my $id (&languageids()) {
1028: my $code = &supportedlanguagecode($id);
1029: if ($code) {
1030: $langchoices{$code} = &plainlanguagedescription($id);
1031: }
1032: }
1.1117 raeburn 1033: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1034: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1035: }
1036:
1.42 matthew 1037: =pod
1.36 matthew 1038:
1.1088 foxr 1039:
1040: =item * &list_languages()
1041:
1042: Returns an array reference that is suitable for use in language prompters.
1043: Each array element is itself a two element array. The first element
1044: is the language code. The second element a descsriptiuon of the
1045: language itself. This is suitable for use in e.g.
1046: &Apache::edit::select_arg (once dereferenced that is).
1047:
1048: =cut
1049:
1050: sub list_languages {
1051: my @lang_choices;
1052:
1053: foreach my $id (&languageids()) {
1054: my $code = &supportedlanguagecode($id);
1055: if ($code) {
1056: my $selector = $supported_codes{$id};
1057: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1058: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1059: }
1060: }
1061: return \@lang_choices;
1062: }
1063:
1064: =pod
1065:
1.648 raeburn 1066: =item * &linked_select_forms(...)
1.36 matthew 1067:
1068: linked_select_forms returns a string containing a <script></script> block
1069: and html for two <select> menus. The select menus will be linked in that
1070: changing the value of the first menu will result in new values being placed
1071: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1072: order unless a defined order is provided.
1.36 matthew 1073:
1074: linked_select_forms takes the following ordered inputs:
1075:
1076: =over 4
1077:
1.112 bowersj2 1078: =item * $formname, the name of the <form> tag
1.36 matthew 1079:
1.112 bowersj2 1080: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1081:
1.112 bowersj2 1082: =item * $firstdefault, the default value for the first menu
1.36 matthew 1083:
1.112 bowersj2 1084: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1085:
1.112 bowersj2 1086: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1087:
1.112 bowersj2 1088: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1089:
1.609 raeburn 1090: =item * $menuorder, the order of values in the first menu
1091:
1.1115 raeburn 1092: =item * $onchangefirst, additional javascript call to execute for an onchange
1093: event for the first <select> tag
1094:
1095: =item * $onchangesecond, additional javascript call to execute for an onchange
1096: event for the second <select> tag
1097:
1.1245 raeburn 1098: =item * $suffix, to differentiate separate uses of select2data javascript
1099: objects in a page.
1100:
1.41 ng 1101: =back
1102:
1.36 matthew 1103: Below is an example of such a hash. Only the 'text', 'default', and
1104: 'select2' keys must appear as stated. keys(%menu) are the possible
1105: values for the first select menu. The text that coincides with the
1.41 ng 1106: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1107: and text for the second menu are given in the hash pointed to by
1108: $menu{$choice1}->{'select2'}.
1109:
1.112 bowersj2 1110: my %menu = ( A1 => { text =>"Choice A1" ,
1111: default => "B3",
1112: select2 => {
1113: B1 => "Choice B1",
1114: B2 => "Choice B2",
1115: B3 => "Choice B3",
1116: B4 => "Choice B4"
1.609 raeburn 1117: },
1118: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1119: },
1120: A2 => { text =>"Choice A2" ,
1121: default => "C2",
1122: select2 => {
1123: C1 => "Choice C1",
1124: C2 => "Choice C2",
1125: C3 => "Choice C3"
1.609 raeburn 1126: },
1127: order => ['C2','C1','C3'],
1.112 bowersj2 1128: },
1129: A3 => { text =>"Choice A3" ,
1130: default => "D6",
1131: select2 => {
1132: D1 => "Choice D1",
1133: D2 => "Choice D2",
1134: D3 => "Choice D3",
1135: D4 => "Choice D4",
1136: D5 => "Choice D5",
1137: D6 => "Choice D6",
1138: D7 => "Choice D7"
1.609 raeburn 1139: },
1140: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1141: }
1142: );
1.36 matthew 1143:
1144: =cut
1145:
1146: sub linked_select_forms {
1147: my ($formname,
1148: $middletext,
1149: $firstdefault,
1150: $firstselectname,
1151: $secondselectname,
1.609 raeburn 1152: $hashref,
1153: $menuorder,
1.1115 raeburn 1154: $onchangefirst,
1.1245 raeburn 1155: $onchangesecond,
1156: $suffix
1.36 matthew 1157: ) = @_;
1158: my $second = "document.$formname.$secondselectname";
1159: my $first = "document.$formname.$firstselectname";
1160: # output the javascript to do the changing
1161: my $result = '';
1.776 bisitz 1162: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1163: $result.="// <![CDATA[\n";
1.1245 raeburn 1164: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1165: $" = '","';
1166: my $debug = '';
1167: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1168: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1169: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1170: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1171: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1172: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1173: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1174: @s2values = @{$hashref->{$s1}->{'order'}};
1175: }
1.36 matthew 1176: $result.="\"@s2values\");\n";
1.1245 raeburn 1177: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1178: my @s2texts;
1179: foreach my $value (@s2values) {
1.1263 raeburn 1180: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1181: }
1182: $result.="\"@s2texts\");\n";
1183: }
1184: $"=' ';
1185: $result.= <<"END";
1186:
1.1245 raeburn 1187: function select1${suffix}_changed() {
1.36 matthew 1188: // Determine new choice
1.1245 raeburn 1189: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1190: // update select2
1.1245 raeburn 1191: var values = select2data${suffix}[newvalue].values;
1192: var texts = select2data${suffix}[newvalue].texts;
1193: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1194: var i;
1195: // out with the old
1.1245 raeburn 1196: $second.options.length = 0;
1197: // in with the new
1.36 matthew 1198: for (i=0;i<values.length; i++) {
1199: $second.options[i] = new Option(values[i]);
1.143 matthew 1200: $second.options[i].value = values[i];
1.36 matthew 1201: $second.options[i].text = texts[i];
1202: if (values[i] == select2def) {
1203: $second.options[i].selected = true;
1204: }
1205: }
1206: }
1.824 bisitz 1207: // ]]>
1.36 matthew 1208: </script>
1209: END
1210: # output the initial values for the selection lists
1.1245 raeburn 1211: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1212: my @order = sort(keys(%{$hashref}));
1213: if (ref($menuorder) eq 'ARRAY') {
1214: @order = @{$menuorder};
1215: }
1216: foreach my $value (@order) {
1.36 matthew 1217: $result.=" <option value=\"$value\" ";
1.253 albertel 1218: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1219: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1220: }
1221: $result .= "</select>\n";
1222: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1223: $result .= $middletext;
1.1115 raeburn 1224: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1225: if ($onchangesecond) {
1226: $result .= ' onchange="'.$onchangesecond.'"';
1227: }
1228: $result .= ">\n";
1.36 matthew 1229: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1230:
1231: my @secondorder = sort(keys(%select2));
1232: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1233: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1234: }
1235: foreach my $value (@secondorder) {
1.36 matthew 1236: $result.=" <option value=\"$value\" ";
1.253 albertel 1237: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1238: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1239: }
1240: $result .= "</select>\n";
1241: # return $debug;
1242: return $result;
1243: } # end of sub linked_select_forms {
1244:
1.45 matthew 1245: =pod
1.44 bowersj2 1246:
1.973 raeburn 1247: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1248:
1.112 bowersj2 1249: Returns a string corresponding to an HTML link to the given help
1250: $topic, where $topic corresponds to the name of a .tex file in
1251: /home/httpd/html/adm/help/tex, with underscores replaced by
1252: spaces.
1253:
1254: $text will optionally be linked to the same topic, allowing you to
1255: link text in addition to the graphic. If you do not want to link
1256: text, but wish to specify one of the later parameters, pass an
1257: empty string.
1258:
1259: $stayOnPage is a value that will be interpreted as a boolean. If true,
1260: the link will not open a new window. If false, the link will open
1261: a new window using Javascript. (Default is false.)
1262:
1263: $width and $height are optional numerical parameters that will
1264: override the width and height of the popped up window, which may
1.973 raeburn 1265: be useful for certain help topics with big pictures included.
1266:
1267: $imgid is the id of the img tag used for the help icon. This may be
1268: used in a javascript call to switch the image src. See
1269: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1270:
1271: =cut
1272:
1273: sub help_open_topic {
1.973 raeburn 1274: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1275: $text = "" if (not defined $text);
1.44 bowersj2 1276: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1277: $width = 500 if (not defined $width);
1.44 bowersj2 1278: $height = 400 if (not defined $height);
1279: my $filename = $topic;
1280: $filename =~ s/ /_/g;
1281:
1.48 bowersj2 1282: my $template = "";
1283: my $link;
1.572 banghart 1284:
1.159 www 1285: $topic=~s/\W/\_/g;
1.44 bowersj2 1286:
1.572 banghart 1287: if (!$stayOnPage) {
1.1033 www 1288: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1289: } elsif ($stayOnPage eq 'popup') {
1290: $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 1291: } else {
1.48 bowersj2 1292: $link = "/adm/help/${filename}.hlp";
1293: }
1294:
1295: # Add the text
1.755 neumanie 1296: if ($text ne "") {
1.763 bisitz 1297: $template.='<span class="LC_help_open_topic">'
1298: .'<a target="_top" href="'.$link.'">'
1299: .$text.'</a>';
1.48 bowersj2 1300: }
1301:
1.763 bisitz 1302: # (Always) Add the graphic
1.179 matthew 1303: my $title = &mt('Online Help');
1.667 raeburn 1304: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1305: if ($imgid ne '') {
1306: $imgid = ' id="'.$imgid.'"';
1307: }
1.763 bisitz 1308: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1309: .'<img src="'.$helpicon.'" border="0"'
1310: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1311: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1312: .' /></a>';
1313: if ($text ne "") {
1314: $template.='</span>';
1315: }
1.44 bowersj2 1316: return $template;
1317:
1.106 bowersj2 1318: }
1319:
1320: # This is a quicky function for Latex cheatsheet editing, since it
1321: # appears in at least four places
1322: sub helpLatexCheatsheet {
1.1037 www 1323: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1324: my $out;
1.106 bowersj2 1325: my $addOther = '';
1.732 raeburn 1326: if ($topic) {
1.1037 www 1327: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1328: }
1329: $out = '<span>' # Start cheatsheet
1330: .$addOther
1331: .'<span>'
1.1037 www 1332: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1333: .'</span> <span>'
1.1037 www 1334: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1335: .'</span>';
1.732 raeburn 1336: unless ($not_author) {
1.1186 kruse 1337: $out .= '<span>'
1338: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1339: .'</span> <span>'
1340: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1341: .'</span>';
1.732 raeburn 1342: }
1.763 bisitz 1343: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1344: return $out;
1.172 www 1345: }
1346:
1.430 albertel 1347: sub general_help {
1348: my $helptopic='Student_Intro';
1349: if ($env{'request.role'}=~/^(ca|au)/) {
1350: $helptopic='Authoring_Intro';
1.907 raeburn 1351: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1352: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1353: } elsif ($env{'request.role'}=~/^dc/) {
1354: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1355: }
1356: return $helptopic;
1357: }
1358:
1359: sub update_help_link {
1360: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1361: my $origurl = $ENV{'REQUEST_URI'};
1362: $origurl=~s|^/~|/priv/|;
1363: my $timestamp = time;
1364: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1365: $$datum = &escape($$datum);
1366: }
1367:
1368: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1369: my $output .= <<"ENDOUTPUT";
1370: <script type="text/javascript">
1.824 bisitz 1371: // <![CDATA[
1.430 albertel 1372: banner_link = '$banner_link';
1.824 bisitz 1373: // ]]>
1.430 albertel 1374: </script>
1375: ENDOUTPUT
1376: return $output;
1377: }
1378:
1379: # now just updates the help link and generates a blue icon
1.193 raeburn 1380: sub help_open_menu {
1.430 albertel 1381: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1382: = @_;
1.949 droeschl 1383: $stayOnPage = 1;
1.430 albertel 1384: my $output;
1385: if ($component_help) {
1386: if (!$text) {
1387: $output=&help_open_topic($component_help,undef,$stayOnPage,
1388: $width,$height);
1389: } else {
1390: my $help_text;
1391: $help_text=&unescape($topic);
1392: $output='<table><tr><td>'.
1393: &help_open_topic($component_help,$help_text,$stayOnPage,
1394: $width,$height).'</td></tr></table>';
1395: }
1396: }
1397: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1398: return $output.$banner_link;
1399: }
1400:
1401: sub top_nav_help {
1402: my ($text) = @_;
1.436 albertel 1403: $text = &mt($text);
1.949 droeschl 1404: my $stay_on_page = 1;
1405:
1.1168 raeburn 1406: my ($link,$banner_link);
1407: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1408: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1409: : "javascript:helpMenu('open')";
1410: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1411: }
1.201 raeburn 1412: my $title = &mt('Get help');
1.1168 raeburn 1413: if ($link) {
1414: return <<"END";
1.436 albertel 1415: $banner_link
1.1159 raeburn 1416: <a href="$link" title="$title">$text</a>
1.436 albertel 1417: END
1.1168 raeburn 1418: } else {
1419: return ' '.$text.' ';
1420: }
1.436 albertel 1421: }
1422:
1423: sub help_menu_js {
1.1154 raeburn 1424: my ($httphost) = @_;
1.949 droeschl 1425: my $stayOnPage = 1;
1.436 albertel 1426: my $width = 620;
1427: my $height = 600;
1.430 albertel 1428: my $helptopic=&general_help();
1.1154 raeburn 1429: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1430: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1431: my $start_page =
1432: &Apache::loncommon::start_page('Help Menu', undef,
1433: {'frameset' => 1,
1434: 'js_ready' => 1,
1.1154 raeburn 1435: 'use_absolute' => $httphost,
1.331 albertel 1436: 'add_entries' => {
1.1168 raeburn 1437: 'border' => '0',
1.579 raeburn 1438: 'rows' => "110,*",},});
1.331 albertel 1439: my $end_page =
1440: &Apache::loncommon::end_page({'frameset' => 1,
1441: 'js_ready' => 1,});
1442:
1.436 albertel 1443: my $template .= <<"ENDTEMPLATE";
1444: <script type="text/javascript">
1.877 bisitz 1445: // <![CDATA[
1.253 albertel 1446: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1447: var banner_link = '';
1.243 raeburn 1448: function helpMenu(target) {
1449: var caller = this;
1450: if (target == 'open') {
1451: var newWindow = null;
1452: try {
1.262 albertel 1453: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1454: }
1455: catch(error) {
1456: writeHelp(caller);
1457: return;
1458: }
1459: if (newWindow) {
1460: caller = newWindow;
1461: }
1.193 raeburn 1462: }
1.243 raeburn 1463: writeHelp(caller);
1464: return;
1465: }
1466: function writeHelp(caller) {
1.1168 raeburn 1467: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1468: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1469: caller.document.close();
1470: caller.focus();
1.193 raeburn 1471: }
1.877 bisitz 1472: // END LON-CAPA Internal -->
1.253 albertel 1473: // ]]>
1.436 albertel 1474: </script>
1.193 raeburn 1475: ENDTEMPLATE
1476: return $template;
1477: }
1478:
1.172 www 1479: sub help_open_bug {
1480: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1481: unless ($env{'user.adv'}) { return ''; }
1.172 www 1482: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1483: $text = "" if (not defined $text);
1484: $stayOnPage=1;
1.184 albertel 1485: $width = 600 if (not defined $width);
1486: $height = 600 if (not defined $height);
1.172 www 1487:
1488: $topic=~s/\W+/\+/g;
1489: my $link='';
1490: my $template='';
1.379 albertel 1491: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1492: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1493: if (!$stayOnPage)
1494: {
1495: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1496: }
1497: else
1498: {
1499: $link = $url;
1500: }
1501: # Add the text
1502: if ($text ne "")
1503: {
1504: $template .=
1505: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1506: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1507: }
1508:
1509: # Add the graphic
1.179 matthew 1510: my $title = &mt('Report a Bug');
1.215 albertel 1511: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1512: $template .= <<"ENDTEMPLATE";
1.436 albertel 1513: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1514: ENDTEMPLATE
1515: if ($text ne '') { $template.='</td></tr></table>' };
1516: return $template;
1517:
1518: }
1519:
1520: sub help_open_faq {
1521: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1522: unless ($env{'user.adv'}) { return ''; }
1.172 www 1523: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1524: $text = "" if (not defined $text);
1525: $stayOnPage=1;
1526: $width = 350 if (not defined $width);
1527: $height = 400 if (not defined $height);
1528:
1529: $topic=~s/\W+/\+/g;
1530: my $link='';
1531: my $template='';
1532: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1533: if (!$stayOnPage)
1534: {
1535: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1536: }
1537: else
1538: {
1539: $link = $url;
1540: }
1541:
1542: # Add the text
1543: if ($text ne "")
1544: {
1545: $template .=
1.173 www 1546: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1547: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1548: }
1549:
1550: # Add the graphic
1.179 matthew 1551: my $title = &mt('View the FAQ');
1.215 albertel 1552: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1553: $template .= <<"ENDTEMPLATE";
1.436 albertel 1554: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1555: ENDTEMPLATE
1556: if ($text ne '') { $template.='</td></tr></table>' };
1557: return $template;
1558:
1.44 bowersj2 1559: }
1.37 matthew 1560:
1.180 matthew 1561: ###############################################################
1562: ###############################################################
1563:
1.45 matthew 1564: =pod
1565:
1.648 raeburn 1566: =item * &change_content_javascript():
1.256 matthew 1567:
1568: This and the next function allow you to create small sections of an
1569: otherwise static HTML page that you can update on the fly with
1570: Javascript, even in Netscape 4.
1571:
1572: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1573: must be written to the HTML page once. It will prove the Javascript
1574: function "change(name, content)". Calling the change function with the
1575: name of the section
1576: you want to update, matching the name passed to C<changable_area>, and
1577: the new content you want to put in there, will put the content into
1578: that area.
1579:
1580: B<Note>: Netscape 4 only reserves enough space for the changable area
1581: to contain room for the original contents. You need to "make space"
1582: for whatever changes you wish to make, and be B<sure> to check your
1583: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1584: it's adequate for updating a one-line status display, but little more.
1585: This script will set the space to 100% width, so you only need to
1586: worry about height in Netscape 4.
1587:
1588: Modern browsers are much less limiting, and if you can commit to the
1589: user not using Netscape 4, this feature may be used freely with
1590: pretty much any HTML.
1591:
1592: =cut
1593:
1594: sub change_content_javascript {
1595: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1596: if ($env{'browser.type'} eq 'netscape' &&
1597: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1598: return (<<NETSCAPE4);
1599: function change(name, content) {
1600: doc = document.layers[name+"___escape"].layers[0].document;
1601: doc.open();
1602: doc.write(content);
1603: doc.close();
1604: }
1605: NETSCAPE4
1606: } else {
1607: # Otherwise, we need to use semi-standards-compliant code
1608: # (technically, "innerHTML" isn't standard but the equivalent
1609: # is really scary, and every useful browser supports it
1610: return (<<DOMBASED);
1611: function change(name, content) {
1612: element = document.getElementById(name);
1613: element.innerHTML = content;
1614: }
1615: DOMBASED
1616: }
1617: }
1618:
1619: =pod
1620:
1.648 raeburn 1621: =item * &changable_area($name,$origContent):
1.256 matthew 1622:
1623: This provides a "changable area" that can be modified on the fly via
1624: the Javascript code provided in C<change_content_javascript>. $name is
1625: the name you will use to reference the area later; do not repeat the
1626: same name on a given HTML page more then once. $origContent is what
1627: the area will originally contain, which can be left blank.
1628:
1629: =cut
1630:
1631: sub changable_area {
1632: my ($name, $origContent) = @_;
1633:
1.258 albertel 1634: if ($env{'browser.type'} eq 'netscape' &&
1635: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1636: # If this is netscape 4, we need to use the Layer tag
1637: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1638: } else {
1639: return "<span id='$name'>$origContent</span>";
1640: }
1641: }
1642:
1643: =pod
1644:
1.648 raeburn 1645: =item * &viewport_geometry_js
1.590 raeburn 1646:
1647: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1648:
1649: =cut
1650:
1651:
1652: sub viewport_geometry_js {
1653: return <<"GEOMETRY";
1654: var Geometry = {};
1655: function init_geometry() {
1656: if (Geometry.init) { return };
1657: Geometry.init=1;
1658: if (window.innerHeight) {
1659: Geometry.getViewportHeight = function() { return window.innerHeight; };
1660: Geometry.getViewportWidth = function() { return window.innerWidth; };
1661: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1662: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1663: }
1664: else if (document.documentElement && document.documentElement.clientHeight) {
1665: Geometry.getViewportHeight =
1666: function() { return document.documentElement.clientHeight; };
1667: Geometry.getViewportWidth =
1668: function() { return document.documentElement.clientWidth; };
1669:
1670: Geometry.getHorizontalScroll =
1671: function() { return document.documentElement.scrollLeft; };
1672: Geometry.getVerticalScroll =
1673: function() { return document.documentElement.scrollTop; };
1674: }
1675: else if (document.body.clientHeight) {
1676: Geometry.getViewportHeight =
1677: function() { return document.body.clientHeight; };
1678: Geometry.getViewportWidth =
1679: function() { return document.body.clientWidth; };
1680: Geometry.getHorizontalScroll =
1681: function() { return document.body.scrollLeft; };
1682: Geometry.getVerticalScroll =
1683: function() { return document.body.scrollTop; };
1684: }
1685: }
1686:
1687: GEOMETRY
1688: }
1689:
1690: =pod
1691:
1.648 raeburn 1692: =item * &viewport_size_js()
1.590 raeburn 1693:
1694: 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.
1695:
1696: =cut
1697:
1698: sub viewport_size_js {
1699: my $geometry = &viewport_geometry_js();
1700: return <<"DIMS";
1701:
1702: $geometry
1703:
1704: function getViewportDims(width,height) {
1705: init_geometry();
1706: width.value = Geometry.getViewportWidth();
1707: height.value = Geometry.getViewportHeight();
1708: return;
1709: }
1710:
1711: DIMS
1712: }
1713:
1714: =pod
1715:
1.648 raeburn 1716: =item * &resize_textarea_js()
1.565 albertel 1717:
1718: emits the needed javascript to resize a textarea to be as big as possible
1719:
1720: creates a function resize_textrea that takes two IDs first should be
1721: the id of the element to resize, second should be the id of a div that
1722: surrounds everything that comes after the textarea, this routine needs
1723: to be attached to the <body> for the onload and onresize events.
1724:
1.648 raeburn 1725: =back
1.565 albertel 1726:
1727: =cut
1728:
1729: sub resize_textarea_js {
1.590 raeburn 1730: my $geometry = &viewport_geometry_js();
1.565 albertel 1731: return <<"RESIZE";
1732: <script type="text/javascript">
1.824 bisitz 1733: // <![CDATA[
1.590 raeburn 1734: $geometry
1.565 albertel 1735:
1.588 albertel 1736: function getX(element) {
1737: var x = 0;
1738: while (element) {
1739: x += element.offsetLeft;
1740: element = element.offsetParent;
1741: }
1742: return x;
1743: }
1744: function getY(element) {
1745: var y = 0;
1746: while (element) {
1747: y += element.offsetTop;
1748: element = element.offsetParent;
1749: }
1750: return y;
1751: }
1752:
1753:
1.565 albertel 1754: function resize_textarea(textarea_id,bottom_id) {
1755: init_geometry();
1756: var textarea = document.getElementById(textarea_id);
1757: //alert(textarea);
1758:
1.588 albertel 1759: var textarea_top = getY(textarea);
1.565 albertel 1760: var textarea_height = textarea.offsetHeight;
1761: var bottom = document.getElementById(bottom_id);
1.588 albertel 1762: var bottom_top = getY(bottom);
1.565 albertel 1763: var bottom_height = bottom.offsetHeight;
1764: var window_height = Geometry.getViewportHeight();
1.588 albertel 1765: var fudge = 23;
1.565 albertel 1766: var new_height = window_height-fudge-textarea_top-bottom_height;
1767: if (new_height < 300) {
1768: new_height = 300;
1769: }
1770: textarea.style.height=new_height+'px';
1771: }
1.824 bisitz 1772: // ]]>
1.565 albertel 1773: </script>
1774: RESIZE
1775:
1776: }
1777:
1.1205 golterma 1778: sub colorfuleditor_js {
1.1248 raeburn 1779: my $browse_or_search;
1780: my $respath;
1781: my ($cnum,$cdom) = &crsauthor_url();
1782: if ($cnum) {
1783: $respath = "/res/$cdom/$cnum/";
1784: my %js_lt = &Apache::lonlocal::texthash(
1785: sunm => 'Sub-directory name',
1786: save => 'Save page to make this permanent',
1787: );
1788: &js_escape(\%js_lt);
1789: $browse_or_search = <<"END";
1790:
1791: function toggleChooser(form,element,titleid,only,search) {
1792: var disp = 'none';
1793: if (document.getElementById('chooser_'+element)) {
1794: var curr = document.getElementById('chooser_'+element).style.display;
1795: if (curr == 'none') {
1796: disp='inline';
1797: if (form.elements['chooser_'+element].length) {
1798: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1799: form.elements['chooser_'+element][i].checked = false;
1800: }
1801: }
1802: toggleResImport(form,element);
1803: }
1804: document.getElementById('chooser_'+element).style.display = disp;
1805: }
1806: }
1807:
1808: function toggleCrsFile(form,element,numdirs) {
1809: if (document.getElementById('chooser_'+element+'_crsres')) {
1810: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1811: if (curr == 'none') {
1812: if (numdirs) {
1813: form.elements['coursepath_'+element].selectedIndex = 0;
1814: if (numdirs > 1) {
1815: window['select1'+element+'_changed']();
1816: }
1817: }
1818: }
1819: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1820:
1821: }
1822: if (document.getElementById('chooser_'+element+'_upload')) {
1823: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1824: if (document.getElementById('uploadcrsres_'+element)) {
1825: document.getElementById('uploadcrsres_'+element).value = '';
1826: }
1827: }
1828: return;
1829: }
1830:
1831: function toggleCrsUpload(form,element,numcrsdirs) {
1832: if (document.getElementById('chooser_'+element+'_crsres')) {
1833: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1834: }
1835: if (document.getElementById('chooser_'+element+'_upload')) {
1836: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1837: if (curr == 'none') {
1838: if (numcrsdirs) {
1839: form.elements['crsauthorpath_'+element].selectedIndex = 0;
1840: form.elements['newsubdir_'+element][0].checked = true;
1841: toggleNewsubdir(form,element);
1842: }
1843: }
1844: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1845: }
1846: return;
1847: }
1848:
1849: function toggleResImport(form,element) {
1850: var choices = new Array('crsres','upload');
1851: for (var i=0; i<choices.length; i++) {
1852: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1853: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1854: }
1855: }
1856: }
1857:
1858: function toggleNewsubdir(form,element) {
1859: var newsub = form.elements['newsubdir_'+element];
1860: if (newsub) {
1861: if (newsub.length) {
1862: for (var j=0; j<newsub.length; j++) {
1863: if (newsub[j].checked) {
1864: if (document.getElementById('newsubdirname_'+element)) {
1865: if (newsub[j].value == '1') {
1866: document.getElementById('newsubdirname_'+element).type = "text";
1867: if (document.getElementById('newsubdir_'+element)) {
1868: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1869: }
1870: } else {
1871: document.getElementById('newsubdirname_'+element).type = "hidden";
1872: document.getElementById('newsubdirname_'+element).value = "";
1873: document.getElementById('newsubdir_'+element).innerHTML = "";
1874: }
1875: }
1876: break;
1877: }
1878: }
1879: }
1880: }
1881: }
1882:
1883: function updateCrsFile(form,element) {
1884: var directory = form.elements['coursepath_'+element];
1885: var filename = form.elements['coursefile_'+element];
1886: var path = directory.options[directory.selectedIndex].value;
1887: var file = filename.options[filename.selectedIndex].value;
1888: form.elements[element].value = '$respath';
1889: if (path == '/') {
1890: form.elements[element].value += file;
1891: } else {
1892: form.elements[element].value += path+'/'+file;
1893: }
1894: unClean();
1895: if (document.getElementById('previewimg_'+element)) {
1896: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1897: var newsrc = document.getElementById('previewimg_'+element).src;
1898: }
1899: if (document.getElementById('showimg_'+element)) {
1900: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1901: }
1902: toggleChooser(form,element);
1903: return;
1904: }
1905:
1906: function uploadDone(suffix,name) {
1907: if (name) {
1908: document.forms["lonhomework"].elements[suffix].value = name;
1909: unClean();
1910: toggleChooser(document.forms["lonhomework"],suffix);
1911: }
1912: }
1913:
1914: \$(document).ready(function(){
1915:
1916: \$(document).delegate('form :submit', 'click', function( event ) {
1917: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
1918: var buttonId = this.id;
1919: var suffix = buttonId.toString();
1920: suffix = suffix.replace(/^crsupload_/,'');
1921: event.preventDefault();
1922: document.lonhomework.target = 'crsupload_target_'+suffix;
1923: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
1924: \$(this.form).submit();
1925: document.lonhomework.target = '';
1926: if (document.getElementById('crsuploadto_'+suffix)) {
1927: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
1928: }
1929: return false;
1930: }
1931: });
1932: });
1933: END
1934: }
1.1205 golterma 1935: return <<"COLORFULEDIT"
1936: <script type="text/javascript">
1937: // <![CDATA[>
1938: function fold_box(curDepth, lastresource){
1939:
1940: // we need a list because there can be several blocks you need to fold in one tag
1941: var block = document.getElementsByName('foldblock_'+curDepth);
1942: // but there is only one folding button per tag
1943: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1944:
1945: if(block.item(0).style.display == 'none'){
1946:
1947: foldbutton.value = '@{[&mt("Hide")]}';
1948: for (i = 0; i < block.length; i++){
1949: block.item(i).style.display = '';
1950: }
1951: }else{
1952:
1953: foldbutton.value = '@{[&mt("Show")]}';
1954: for (i = 0; i < block.length; i++){
1955: // block.item(i).style.visibility = 'collapse';
1956: block.item(i).style.display = 'none';
1957: }
1958: };
1959: saveState(lastresource);
1960: }
1961:
1962: function saveState (lastresource) {
1963:
1964: var tag_list = getTagList();
1965: if(tag_list != null){
1966: var timestamp = new Date().getTime();
1967: var key = lastresource;
1968:
1969: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1970: // starting with timestamp
1971: var value = timestamp+';';
1972:
1973: // building the list of key-value pairs
1974: for(var i = 0; i < tag_list.length; i++){
1975: value += tag_list[i]+',';
1976: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1977: }
1978:
1979: // only iterate whole storage if nothing to override
1980: if(localStorage.getItem(key) == null){
1981:
1982: // prevent storage from growing large
1983: if(localStorage.length > 50){
1984: var regex_getTimestamp = /^(?:\d)+;/;
1985: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1986: var oldest_key;
1987:
1988: for(var i = 1; i < localStorage.length; i++){
1989: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1990: oldest_key = localStorage.key(i);
1991: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1992: }
1993: }
1994: localStorage.removeItem(oldest_key);
1995: }
1996: }
1997: localStorage.setItem(key,value);
1998: }
1999: }
2000:
2001: // restore folding status of blocks (on page load)
2002: function restoreState (lastresource) {
2003: if(localStorage.getItem(lastresource) != null){
2004: var key = lastresource;
2005: var value = localStorage.getItem(key);
2006: var regex_delTimestamp = /^\d+;/;
2007:
2008: value.replace(regex_delTimestamp, '');
2009:
2010: var valueArr = value.split(';');
2011: var pairs;
2012: var elements;
2013: for (var i = 0; i < valueArr.length; i++){
2014: pairs = valueArr[i].split(',');
2015: elements = document.getElementsByName(pairs[0]);
2016:
2017: for (var j = 0; j < elements.length; j++){
2018: elements[j].style.display = pairs[1];
2019: if (pairs[1] == "none"){
2020: var regex_id = /([_\\d]+)\$/;
2021: regex_id.exec(pairs[0]);
2022: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2023: }
2024: }
2025: }
2026: }
2027: }
2028:
2029: function getTagList () {
2030:
2031: var stringToSearch = document.lonhomework.innerHTML;
2032:
2033: var ret = new Array();
2034: var regex_findBlock = /(foldblock_.*?)"/g;
2035: var tag_list = stringToSearch.match(regex_findBlock);
2036:
2037: if(tag_list != null){
2038: for(var i = 0; i < tag_list.length; i++){
2039: ret.push(tag_list[i].replace(/"/, ''));
2040: }
2041: }
2042: return ret;
2043: }
2044:
2045: function saveScrollPosition (resource) {
2046: var tag_list = getTagList();
2047:
2048: // we dont always want to jump to the first block
2049: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2050: if(\$(window).scrollTop() > 170){
2051: if(tag_list != null){
2052: var result;
2053: for(var i = 0; i < tag_list.length; i++){
2054: if(isElementInViewport(tag_list[i])){
2055: result += tag_list[i]+';';
2056: }
2057: }
2058: sessionStorage.setItem('anchor_'+resource, result);
2059: }
2060: } else {
2061: // we dont need to save zero, just delete the item to leave everything tidy
2062: sessionStorage.removeItem('anchor_'+resource);
2063: }
2064: }
2065:
2066: function restoreScrollPosition(resource){
2067:
2068: var elem = sessionStorage.getItem('anchor_'+resource);
2069: if(elem != null){
2070: var tag_list = elem.split(';');
2071: var elem_list;
2072:
2073: for(var i = 0; i < tag_list.length; i++){
2074: elem_list = document.getElementsByName(tag_list[i]);
2075:
2076: if(elem_list.length > 0){
2077: elem = elem_list[0];
2078: break;
2079: }
2080: }
2081: elem.scrollIntoView();
2082: }
2083: }
2084:
2085: function isElementInViewport(el) {
2086:
2087: // change to last element instead of first
2088: var elem = document.getElementsByName(el);
2089: var rect = elem[0].getBoundingClientRect();
2090:
2091: return (
2092: rect.top >= 0 &&
2093: rect.left >= 0 &&
2094: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2095: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2096: );
2097: }
2098:
2099: function autosize(depth){
2100: var cmInst = window['cm'+depth];
2101: var fitsizeButton = document.getElementById('fitsize'+depth);
2102:
2103: // is fixed size, switching to dynamic
2104: if (sessionStorage.getItem("autosized_"+depth) == null) {
2105: cmInst.setSize("","auto");
2106: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2107: sessionStorage.setItem("autosized_"+depth, "yes");
2108:
2109: // is dynamic size, switching to fixed
2110: } else {
2111: cmInst.setSize("","300px");
2112: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2113: sessionStorage.removeItem("autosized_"+depth);
2114: }
2115: }
2116:
1.1248 raeburn 2117: $browse_or_search
1.1205 golterma 2118:
2119: // ]]>
2120: </script>
2121: COLORFULEDIT
2122: }
2123:
2124: sub xmleditor_js {
2125: return <<XMLEDIT
2126: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2127: <script type="text/javascript">
2128: // <![CDATA[>
2129:
2130: function saveScrollPosition (resource) {
2131:
2132: var scrollPos = \$(window).scrollTop();
2133: sessionStorage.setItem(resource,scrollPos);
2134: }
2135:
2136: function restoreScrollPosition(resource){
2137:
2138: var scrollPos = sessionStorage.getItem(resource);
2139: \$(window).scrollTop(scrollPos);
2140: }
2141:
2142: // unless internet explorer
2143: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2144:
2145: \$(document).ready(function() {
2146: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2147: });
2148: }
2149:
2150: // inserts text at cursor position into codemirror (xml editor only)
2151: function insertText(text){
2152: cm.focus();
2153: var curPos = cm.getCursor();
2154: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2155: }
2156: // ]]>
2157: </script>
2158: XMLEDIT
2159: }
2160:
2161: sub insert_folding_button {
2162: my $curDepth = $Apache::lonxml::curdepth;
2163: my $lastresource = $env{'request.ambiguous'};
2164:
2165: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2166: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2167: }
2168:
1.1248 raeburn 2169: sub crsauthor_url {
2170: my ($url) = @_;
2171: if ($url eq '') {
2172: $url = $ENV{'REQUEST_URI'};
2173: }
2174: my ($cnum,$cdom);
2175: if ($env{'request.course.id'}) {
2176: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2177: if ($audom ne '' && $auname ne '') {
2178: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2179: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2180: $cnum = $auname;
2181: $cdom = $audom;
2182: }
2183: }
2184: }
2185: return ($cnum,$cdom);
2186: }
2187:
2188: sub import_crsauthor_form {
1.1265 raeburn 2189: my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2190: return (0) unless ($env{'request.course.id'});
2191: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2192: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2193: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2194: return (0) unless (($cnum ne '') && ($cdom ne ''));
2195: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
2196: my @ids=&Apache::lonnet::current_machine_ids();
2197: my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
2198:
2199: if (grep(/^\Q$crshome\E$/,@ids)) {
2200: $is_home = 1;
2201: }
2202: $relpath = "/priv/$cdom/$cnum";
2203: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
2204: my %lt = &Apache::lonlocal::texthash (
2205: fnam => 'Filename',
2206: dire => 'Directory',
2207: );
2208: my $numdirs = scalar(keys(%files));
2209: my (%possexts,$singledir,@singledirfiles);
2210: if ($only) {
2211: map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
2212: }
2213: my (%nonemptydirs,$possdirs);
2214: if ($numdirs > 1) {
2215: my @order;
2216: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
2217: if (ref($files{$key}) eq 'HASH') {
2218: my $shown = $key;
2219: if ($key eq '') {
2220: $shown = '/';
2221: }
2222: my @ordered = ();
2223: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
2224: if ($only) {
2225: my ($ext) = ($file =~ /\.([^.]+)$/);
2226: unless ($possexts{lc($ext)}) {
2227: next;
2228: }
2229: }
2230: $selimport_menus{$key}->{'select2'}->{$file} = $file;
2231: push(@ordered,$file);
2232: }
2233: if (@ordered) {
2234: push(@order,$key);
2235: $nonemptydirs{$key} = 1;
2236: $selimport_menus{$key}->{'text'} = $shown;
2237: $selimport_menus{$key}->{'default'} = '';
2238: $selimport_menus{$key}->{'select2'}->{''} = '';
2239: $selimport_menus{$key}->{'order'} = \@ordered;
2240: }
2241: }
2242: }
2243: $possdirs = scalar(keys(%nonemptydirs));
2244: if ($possdirs > 1) {
2245: my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
2246: $output = $lt{'dire'}.
2247: &linked_select_forms($form,'<br />'.
2248: $lt{'fnam'},'',
2249: $firstselectname,$secondselectname,
2250: \%selimport_menus,\@order,
2251: $onchangefirst,'',$suffix).'<br />';
2252: } elsif ($possdirs == 1) {
2253: $singledir = (keys(%nonemptydirs))[0];
2254: if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
2255: @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
2256: }
2257: delete($selimport_menus{$singledir});
2258: }
2259: } elsif ($numdirs == 1) {
2260: $singledir = (keys(%files))[0];
2261: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
2262: if ($only) {
2263: my ($ext) = ($file =~ /\.([^.]+)$/);
2264: unless ($possexts{lc($ext)}) {
2265: next;
2266: }
2267: }
2268: push(@singledirfiles,$file);
2269: }
2270: if (@singledirfiles) {
2271: $possdirs == 1;
2272: }
2273: }
2274: if (($possdirs == 1) && (@singledirfiles)) {
2275: my $showdir = $singledir;
2276: if ($singledir eq '') {
2277: $showdir = '/';
2278: }
2279: $output = $lt{'dire'}.
2280: '<select name="'.$firstselectname.'">'.
2281: '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
2282: '</select><br />'.
2283: $lt{'fnam'}.'<select name="'.$secondselectname.'">'."\n".
2284: '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
2285: foreach my $file (@singledirfiles) {
2286: $output .= '<option value="'.$file.'">'.$file.'</option>'."\n";
2287: }
2288: $output .= '</select><br />'."\n";
2289: }
2290: return ($possdirs,$output);
2291: }
2292:
1.565 albertel 2293: =pod
2294:
1.256 matthew 2295: =head1 Excel and CSV file utility routines
2296:
2297: =cut
2298:
2299: ###############################################################
2300: ###############################################################
2301:
2302: =pod
2303:
1.1162 raeburn 2304: =over 4
2305:
1.648 raeburn 2306: =item * &csv_translate($text)
1.37 matthew 2307:
1.185 www 2308: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2309: format.
2310:
2311: =cut
2312:
1.180 matthew 2313: ###############################################################
2314: ###############################################################
1.37 matthew 2315: sub csv_translate {
2316: my $text = shift;
2317: $text =~ s/\"/\"\"/g;
1.209 albertel 2318: $text =~ s/\n/ /g;
1.37 matthew 2319: return $text;
2320: }
1.180 matthew 2321:
2322: ###############################################################
2323: ###############################################################
2324:
2325: =pod
2326:
1.648 raeburn 2327: =item * &define_excel_formats()
1.180 matthew 2328:
2329: Define some commonly used Excel cell formats.
2330:
2331: Currently supported formats:
2332:
2333: =over 4
2334:
2335: =item header
2336:
2337: =item bold
2338:
2339: =item h1
2340:
2341: =item h2
2342:
2343: =item h3
2344:
1.256 matthew 2345: =item h4
2346:
2347: =item i
2348:
1.180 matthew 2349: =item date
2350:
2351: =back
2352:
2353: Inputs: $workbook
2354:
2355: Returns: $format, a hash reference.
2356:
1.1057 foxr 2357:
1.180 matthew 2358: =cut
2359:
2360: ###############################################################
2361: ###############################################################
2362: sub define_excel_formats {
2363: my ($workbook) = @_;
2364: my $format;
2365: $format->{'header'} = $workbook->add_format(bold => 1,
2366: bottom => 1,
2367: align => 'center');
2368: $format->{'bold'} = $workbook->add_format(bold=>1);
2369: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2370: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2371: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2372: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2373: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2374: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2375: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2376: return $format;
2377: }
2378:
2379: ###############################################################
2380: ###############################################################
1.113 bowersj2 2381:
2382: =pod
2383:
1.648 raeburn 2384: =item * &create_workbook()
1.255 matthew 2385:
2386: Create an Excel worksheet. If it fails, output message on the
2387: request object and return undefs.
2388:
2389: Inputs: Apache request object
2390:
2391: Returns (undef) on failure,
2392: Excel worksheet object, scalar with filename, and formats
2393: from &Apache::loncommon::define_excel_formats on success
2394:
2395: =cut
2396:
2397: ###############################################################
2398: ###############################################################
2399: sub create_workbook {
2400: my ($r) = @_;
2401: #
2402: # Create the excel spreadsheet
2403: my $filename = '/prtspool/'.
1.258 albertel 2404: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2405: time.'_'.rand(1000000000).'.xls';
2406: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2407: if (! defined($workbook)) {
2408: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2409: $r->print(
2410: '<p class="LC_error">'
2411: .&mt('Problems occurred in creating the new Excel file.')
2412: .' '.&mt('This error has been logged.')
2413: .' '.&mt('Please alert your LON-CAPA administrator.')
2414: .'</p>'
2415: );
1.255 matthew 2416: return (undef);
2417: }
2418: #
1.1014 foxr 2419: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2420: #
2421: my $format = &Apache::loncommon::define_excel_formats($workbook);
2422: return ($workbook,$filename,$format);
2423: }
2424:
2425: ###############################################################
2426: ###############################################################
2427:
2428: =pod
2429:
1.648 raeburn 2430: =item * &create_text_file()
1.113 bowersj2 2431:
1.542 raeburn 2432: Create a file to write to and eventually make available to the user.
1.256 matthew 2433: If file creation fails, outputs an error message on the request object and
2434: return undefs.
1.113 bowersj2 2435:
1.256 matthew 2436: Inputs: Apache request object, and file suffix
1.113 bowersj2 2437:
1.256 matthew 2438: Returns (undef) on failure,
2439: Filehandle and filename on success.
1.113 bowersj2 2440:
2441: =cut
2442:
1.256 matthew 2443: ###############################################################
2444: ###############################################################
2445: sub create_text_file {
2446: my ($r,$suffix) = @_;
2447: if (! defined($suffix)) { $suffix = 'txt'; };
2448: my $fh;
2449: my $filename = '/prtspool/'.
1.258 albertel 2450: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2451: time.'_'.rand(1000000000).'.'.$suffix;
2452: $fh = Apache::File->new('>/home/httpd'.$filename);
2453: if (! defined($fh)) {
2454: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2455: $r->print(
2456: '<p class="LC_error">'
2457: .&mt('Problems occurred in creating the output file.')
2458: .' '.&mt('This error has been logged.')
2459: .' '.&mt('Please alert your LON-CAPA administrator.')
2460: .'</p>'
2461: );
1.113 bowersj2 2462: }
1.256 matthew 2463: return ($fh,$filename)
1.113 bowersj2 2464: }
2465:
2466:
1.256 matthew 2467: =pod
1.113 bowersj2 2468:
2469: =back
2470:
2471: =cut
1.37 matthew 2472:
2473: ###############################################################
1.33 matthew 2474: ## Home server <option> list generating code ##
2475: ###############################################################
1.35 matthew 2476:
1.169 www 2477: # ------------------------------------------
2478:
2479: sub domain_select {
2480: my ($name,$value,$multiple)=@_;
2481: my %domains=map {
1.514 albertel 2482: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2483: } &Apache::lonnet::all_domains();
1.169 www 2484: if ($multiple) {
2485: $domains{''}=&mt('Any domain');
1.550 albertel 2486: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2487: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2488: } else {
1.550 albertel 2489: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2490: return &select_form($name,$value,\%domains);
1.169 www 2491: }
2492: }
2493:
1.282 albertel 2494: #-------------------------------------------
2495:
2496: =pod
2497:
1.519 raeburn 2498: =head1 Routines for form select boxes
2499:
2500: =over 4
2501:
1.648 raeburn 2502: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2503:
2504: Returns a string containing a <select> element int multiple mode
2505:
2506:
2507: Args:
2508: $name - name of the <select> element
1.506 raeburn 2509: $value - scalar or array ref of values that should already be selected
1.282 albertel 2510: $size - number of rows long the select element is
1.283 albertel 2511: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2512: (shown text should already have been &mt())
1.506 raeburn 2513: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2514:
1.282 albertel 2515: =cut
2516:
2517: #-------------------------------------------
1.169 www 2518: sub multiple_select_form {
1.284 albertel 2519: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2520: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2521: my $output='';
1.191 matthew 2522: if (! defined($size)) {
2523: $size = 4;
1.283 albertel 2524: if (scalar(keys(%$hash))<4) {
2525: $size = scalar(keys(%$hash));
1.191 matthew 2526: }
2527: }
1.734 bisitz 2528: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2529: my @order;
1.506 raeburn 2530: if (ref($order) eq 'ARRAY') {
2531: @order = @{$order};
2532: } else {
2533: @order = sort(keys(%$hash));
1.501 banghart 2534: }
2535: if (exists($$hash{'select_form_order'})) {
2536: @order = @{$$hash{'select_form_order'}};
2537: }
2538:
1.284 albertel 2539: foreach my $key (@order) {
1.356 albertel 2540: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2541: $output.='selected="selected" ' if ($selected{$key});
2542: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2543: }
2544: $output.="</select>\n";
2545: return $output;
2546: }
2547:
1.88 www 2548: #-------------------------------------------
2549:
2550: =pod
2551:
1.1254 raeburn 2552: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2553:
2554: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2555: allow a user to select options from a ref to a hash containing:
2556: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2557: a javascript onchange item, e.g., onchange="this.form.submit();".
2558: An optional arg -- $readonly -- if true will cause the select form
2559: to be disabled, e.g., for the case where an instructor has a section-
2560: specific role, and is viewing/modifying parameters.
1.970 raeburn 2561:
1.88 www 2562: See lonrights.pm for an example invocation and use.
2563:
2564: =cut
2565:
2566: #-------------------------------------------
2567: sub select_form {
1.1228 raeburn 2568: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2569: return unless (ref($hashref) eq 'HASH');
2570: if ($onchange) {
2571: $onchange = ' onchange="'.$onchange.'"';
2572: }
1.1228 raeburn 2573: my $disabled;
2574: if ($readonly) {
2575: $disabled = ' disabled="disabled"';
2576: }
2577: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2578: my @keys;
1.970 raeburn 2579: if (exists($hashref->{'select_form_order'})) {
2580: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2581: } else {
1.970 raeburn 2582: @keys=sort(keys(%{$hashref}));
1.128 albertel 2583: }
1.356 albertel 2584: foreach my $key (@keys) {
2585: $selectform.=
2586: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2587: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2588: ">".$hashref->{$key}."</option>\n";
1.88 www 2589: }
2590: $selectform.="</select>";
2591: return $selectform;
2592: }
2593:
1.475 www 2594: # For display filters
2595:
2596: sub display_filter {
1.1074 raeburn 2597: my ($context) = @_;
1.475 www 2598: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2599: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2600: my $phraseinput = 'hidden';
2601: my $includeinput = 'hidden';
2602: my ($checked,$includetypestext);
2603: if ($env{'form.displayfilter'} eq 'containing') {
2604: $phraseinput = 'text';
2605: if ($context eq 'parmslog') {
2606: $includeinput = 'checkbox';
2607: if ($env{'form.includetypes'}) {
2608: $checked = ' checked="checked"';
2609: }
2610: $includetypestext = &mt('Include parameter types');
2611: }
2612: } else {
2613: $includetypestext = ' ';
2614: }
2615: my ($additional,$secondid,$thirdid);
2616: if ($context eq 'parmslog') {
2617: $additional =
2618: '<label><input type="'.$includeinput.'" name="includetypes"'.
2619: $checked.' name="includetypes" value="1" id="includetypes" />'.
2620: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2621: '</label>';
2622: $secondid = 'includetypes';
2623: $thirdid = 'includetypestext';
2624: }
2625: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2626: '$secondid','$thirdid')";
2627: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2628: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2629: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2630: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2631: &mt('Filter: [_1]',
1.477 www 2632: &select_form($env{'form.displayfilter'},
2633: 'displayfilter',
1.970 raeburn 2634: {'currentfolder' => 'Current folder/page',
1.477 www 2635: 'containing' => 'Containing phrase',
1.1074 raeburn 2636: 'none' => 'None'},$onchange)).' '.
2637: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2638: &HTML::Entities::encode($env{'form.containingphrase'}).
2639: '" />'.$additional;
2640: }
2641:
2642: sub display_filter_js {
2643: my $includetext = &mt('Include parameter types');
2644: return <<"ENDJS";
2645:
2646: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2647: var firstType = 'hidden';
2648: if (setter.options[setter.selectedIndex].value == 'containing') {
2649: firstType = 'text';
2650: }
2651: firstObject = document.getElementById(firstid);
2652: if (typeof(firstObject) == 'object') {
2653: if (firstObject.type != firstType) {
2654: changeInputType(firstObject,firstType);
2655: }
2656: }
2657: if (context == 'parmslog') {
2658: var secondType = 'hidden';
2659: if (firstType == 'text') {
2660: secondType = 'checkbox';
2661: }
2662: secondObject = document.getElementById(secondid);
2663: if (typeof(secondObject) == 'object') {
2664: if (secondObject.type != secondType) {
2665: changeInputType(secondObject,secondType);
2666: }
2667: }
2668: var textItem = document.getElementById(thirdid);
2669: var currtext = textItem.innerHTML;
2670: var newtext;
2671: if (firstType == 'text') {
2672: newtext = '$includetext';
2673: } else {
2674: newtext = ' ';
2675: }
2676: if (currtext != newtext) {
2677: textItem.innerHTML = newtext;
2678: }
2679: }
2680: return;
2681: }
2682:
2683: function changeInputType(oldObject,newType) {
2684: var newObject = document.createElement('input');
2685: newObject.type = newType;
2686: if (oldObject.size) {
2687: newObject.size = oldObject.size;
2688: }
2689: if (oldObject.value) {
2690: newObject.value = oldObject.value;
2691: }
2692: if (oldObject.name) {
2693: newObject.name = oldObject.name;
2694: }
2695: if (oldObject.id) {
2696: newObject.id = oldObject.id;
2697: }
2698: oldObject.parentNode.replaceChild(newObject,oldObject);
2699: return;
2700: }
2701:
2702: ENDJS
1.475 www 2703: }
2704:
1.167 www 2705: sub gradeleveldescription {
2706: my $gradelevel=shift;
2707: my %gradelevels=(0 => 'Not specified',
2708: 1 => 'Grade 1',
2709: 2 => 'Grade 2',
2710: 3 => 'Grade 3',
2711: 4 => 'Grade 4',
2712: 5 => 'Grade 5',
2713: 6 => 'Grade 6',
2714: 7 => 'Grade 7',
2715: 8 => 'Grade 8',
2716: 9 => 'Grade 9',
2717: 10 => 'Grade 10',
2718: 11 => 'Grade 11',
2719: 12 => 'Grade 12',
2720: 13 => 'Grade 13',
2721: 14 => '100 Level',
2722: 15 => '200 Level',
2723: 16 => '300 Level',
2724: 17 => '400 Level',
2725: 18 => 'Graduate Level');
2726: return &mt($gradelevels{$gradelevel});
2727: }
2728:
1.163 www 2729: sub select_level_form {
2730: my ($deflevel,$name)=@_;
2731: unless ($deflevel) { $deflevel=0; }
1.167 www 2732: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2733: for (my $i=0; $i<=18; $i++) {
2734: $selectform.="<option value=\"$i\" ".
1.253 albertel 2735: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2736: ">".&gradeleveldescription($i)."</option>\n";
2737: }
2738: $selectform.="</select>";
2739: return $selectform;
1.163 www 2740: }
1.167 www 2741:
1.35 matthew 2742: #-------------------------------------------
2743:
1.45 matthew 2744: =pod
2745:
1.1256 raeburn 2746: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2747:
2748: Returns a string containing a <select name='$name' size='1'> form to
2749: allow a user to select the domain to preform an operation in.
2750: See loncreateuser.pm for an example invocation and use.
2751:
1.90 www 2752: If the $includeempty flag is set, it also includes an empty choice ("no domain
2753: selected");
2754:
1.743 raeburn 2755: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2756:
1.910 raeburn 2757: 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.
2758:
1.1121 raeburn 2759: The optional $incdoms is a reference to an array of domains which will be the only available options.
2760:
2761: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2762:
1.1256 raeburn 2763: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2764:
1.35 matthew 2765: =cut
2766:
2767: #-------------------------------------------
1.34 matthew 2768: sub select_dom_form {
1.1256 raeburn 2769: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2770: if ($onchange) {
1.874 raeburn 2771: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2772: }
1.1256 raeburn 2773: if ($disabled) {
2774: $disabled = ' disabled="disabled"';
2775: }
1.1121 raeburn 2776: my (@domains,%exclude);
1.910 raeburn 2777: if (ref($incdoms) eq 'ARRAY') {
2778: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2779: } else {
2780: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2781: }
1.90 www 2782: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2783: if (ref($excdoms) eq 'ARRAY') {
2784: map { $exclude{$_} = 1; } @{$excdoms};
2785: }
1.1256 raeburn 2786: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2787: foreach my $dom (@domains) {
1.1121 raeburn 2788: next if ($exclude{$dom});
1.356 albertel 2789: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2790: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2791: if ($showdomdesc) {
2792: if ($dom ne '') {
2793: my $domdesc = &Apache::lonnet::domain($dom,'description');
2794: if ($domdesc ne '') {
2795: $selectdomain .= ' ('.$domdesc.')';
2796: }
2797: }
2798: }
2799: $selectdomain .= "</option>\n";
1.34 matthew 2800: }
2801: $selectdomain.="</select>";
2802: return $selectdomain;
2803: }
2804:
1.35 matthew 2805: #-------------------------------------------
2806:
1.45 matthew 2807: =pod
2808:
1.648 raeburn 2809: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2810:
1.586 raeburn 2811: input: 4 arguments (two required, two optional) -
2812: $domain - domain of new user
2813: $name - name of form element
2814: $default - Value of 'default' causes a default item to be first
2815: option, and selected by default.
2816: $hide - Value of 'hide' causes hiding of the name of the server,
2817: if 1 server found, or default, if 0 found.
1.594 raeburn 2818: output: returns 2 items:
1.586 raeburn 2819: (a) form element which contains either:
2820: (i) <select name="$name">
2821: <option value="$hostid1">$hostid $servers{$hostid}</option>
2822: <option value="$hostid2">$hostid $servers{$hostid}</option>
2823: </select>
2824: form item if there are multiple library servers in $domain, or
2825: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2826: if there is only one library server in $domain.
2827:
2828: (b) number of library servers found.
2829:
2830: See loncreateuser.pm for example of use.
1.35 matthew 2831:
2832: =cut
2833:
2834: #-------------------------------------------
1.586 raeburn 2835: sub home_server_form_item {
2836: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2837: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2838: my $result;
2839: my $numlib = keys(%servers);
2840: if ($numlib > 1) {
2841: $result .= '<select name="'.$name.'" />'."\n";
2842: if ($default) {
1.804 bisitz 2843: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2844: '</option>'."\n";
2845: }
2846: foreach my $hostid (sort(keys(%servers))) {
2847: $result.= '<option value="'.$hostid.'">'.
2848: $hostid.' '.$servers{$hostid}."</option>\n";
2849: }
2850: $result .= '</select>'."\n";
2851: } elsif ($numlib == 1) {
2852: my $hostid;
2853: foreach my $item (keys(%servers)) {
2854: $hostid = $item;
2855: }
2856: $result .= '<input type="hidden" name="'.$name.'" value="'.
2857: $hostid.'" />';
2858: if (!$hide) {
2859: $result .= $hostid.' '.$servers{$hostid};
2860: }
2861: $result .= "\n";
2862: } elsif ($default) {
2863: $result .= '<input type="hidden" name="'.$name.
2864: '" value="default" />';
2865: if (!$hide) {
2866: $result .= &mt('default');
2867: }
2868: $result .= "\n";
1.33 matthew 2869: }
1.586 raeburn 2870: return ($result,$numlib);
1.33 matthew 2871: }
1.112 bowersj2 2872:
2873: =pod
2874:
1.534 albertel 2875: =back
2876:
1.112 bowersj2 2877: =cut
1.87 matthew 2878:
2879: ###############################################################
1.112 bowersj2 2880: ## Decoding User Agent ##
1.87 matthew 2881: ###############################################################
2882:
2883: =pod
2884:
1.112 bowersj2 2885: =head1 Decoding the User Agent
2886:
2887: =over 4
2888:
2889: =item * &decode_user_agent()
1.87 matthew 2890:
2891: Inputs: $r
2892:
2893: Outputs:
2894:
2895: =over 4
2896:
1.112 bowersj2 2897: =item * $httpbrowser
1.87 matthew 2898:
1.112 bowersj2 2899: =item * $clientbrowser
1.87 matthew 2900:
1.112 bowersj2 2901: =item * $clientversion
1.87 matthew 2902:
1.112 bowersj2 2903: =item * $clientmathml
1.87 matthew 2904:
1.112 bowersj2 2905: =item * $clientunicode
1.87 matthew 2906:
1.112 bowersj2 2907: =item * $clientos
1.87 matthew 2908:
1.1137 raeburn 2909: =item * $clientmobile
2910:
1.1141 raeburn 2911: =item * $clientinfo
2912:
1.1194 raeburn 2913: =item * $clientosversion
2914:
1.87 matthew 2915: =back
2916:
1.157 matthew 2917: =back
2918:
1.87 matthew 2919: =cut
2920:
2921: ###############################################################
2922: ###############################################################
2923: sub decode_user_agent {
1.247 albertel 2924: my ($r)=@_;
1.87 matthew 2925: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2926: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2927: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2928: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2929: my $clientbrowser='unknown';
2930: my $clientversion='0';
2931: my $clientmathml='';
2932: my $clientunicode='0';
1.1137 raeburn 2933: my $clientmobile=0;
1.1194 raeburn 2934: my $clientosversion='';
1.87 matthew 2935: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2936: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2937: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2938: $clientbrowser=$bname;
2939: $httpbrowser=~/$vreg/i;
2940: $clientversion=$1;
2941: $clientmathml=($clientversion>=$minv);
2942: $clientunicode=($clientversion>=$univ);
2943: }
2944: }
2945: my $clientos='unknown';
1.1141 raeburn 2946: my $clientinfo;
1.87 matthew 2947: if (($httpbrowser=~/linux/i) ||
2948: ($httpbrowser=~/unix/i) ||
2949: ($httpbrowser=~/ux/i) ||
2950: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2951: if (($httpbrowser=~/vax/i) ||
2952: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2953: if ($httpbrowser=~/next/i) { $clientos='next'; }
2954: if (($httpbrowser=~/mac/i) ||
2955: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2956: if ($httpbrowser=~/win/i) {
2957: $clientos='win';
2958: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2959: $clientosversion = $1;
2960: }
2961: }
1.87 matthew 2962: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2963: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2964: $clientmobile=lc($1);
2965: }
1.1141 raeburn 2966: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2967: $clientinfo = 'firefox-'.$1;
2968: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2969: $clientinfo = 'chromeframe-'.$1;
2970: }
1.87 matthew 2971: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 2972: $clientunicode,$clientos,$clientmobile,$clientinfo,
2973: $clientosversion);
1.87 matthew 2974: }
2975:
1.32 matthew 2976: ###############################################################
2977: ## Authentication changing form generation subroutines ##
2978: ###############################################################
2979: ##
2980: ## All of the authform_xxxxxxx subroutines take their inputs in a
2981: ## hash, and have reasonable default values.
2982: ##
2983: ## formname = the name given in the <form> tag.
1.35 matthew 2984: #-------------------------------------------
2985:
1.45 matthew 2986: =pod
2987:
1.112 bowersj2 2988: =head1 Authentication Routines
2989:
2990: =over 4
2991:
1.648 raeburn 2992: =item * &authform_xxxxxx()
1.35 matthew 2993:
2994: The authform_xxxxxx subroutines provide javascript and html forms which
2995: handle some of the conveniences required for authentication forms.
2996: This is not an optimal method, but it works.
2997:
2998: =over 4
2999:
1.112 bowersj2 3000: =item * authform_header
1.35 matthew 3001:
1.112 bowersj2 3002: =item * authform_authorwarning
1.35 matthew 3003:
1.112 bowersj2 3004: =item * authform_nochange
1.35 matthew 3005:
1.112 bowersj2 3006: =item * authform_kerberos
1.35 matthew 3007:
1.112 bowersj2 3008: =item * authform_internal
1.35 matthew 3009:
1.112 bowersj2 3010: =item * authform_filesystem
1.35 matthew 3011:
3012: =back
3013:
1.648 raeburn 3014: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3015:
1.35 matthew 3016: =cut
3017:
3018: #-------------------------------------------
1.32 matthew 3019: sub authform_header{
3020: my %in = (
3021: formname => 'cu',
1.80 albertel 3022: kerb_def_dom => '',
1.32 matthew 3023: @_,
3024: );
3025: $in{'formname'} = 'document.' . $in{'formname'};
3026: my $result='';
1.80 albertel 3027:
3028: #---------------------------------------------- Code for upper case translation
3029: my $Javascript_toUpperCase;
3030: unless ($in{kerb_def_dom}) {
3031: $Javascript_toUpperCase =<<"END";
3032: switch (choice) {
3033: case 'krb': currentform.elements[choicearg].value =
3034: currentform.elements[choicearg].value.toUpperCase();
3035: break;
3036: default:
3037: }
3038: END
3039: } else {
3040: $Javascript_toUpperCase = "";
3041: }
3042:
1.165 raeburn 3043: my $radioval = "'nochange'";
1.591 raeburn 3044: if (defined($in{'curr_authtype'})) {
3045: if ($in{'curr_authtype'} ne '') {
3046: $radioval = "'".$in{'curr_authtype'}."arg'";
3047: }
1.174 matthew 3048: }
1.165 raeburn 3049: my $argfield = 'null';
1.591 raeburn 3050: if (defined($in{'mode'})) {
1.165 raeburn 3051: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3052: if (defined($in{'curr_autharg'})) {
3053: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3054: $argfield = "'$in{'curr_autharg'}'";
3055: }
3056: }
3057: }
3058: }
3059:
1.32 matthew 3060: $result.=<<"END";
3061: var current = new Object();
1.165 raeburn 3062: current.radiovalue = $radioval;
3063: current.argfield = $argfield;
1.32 matthew 3064:
3065: function changed_radio(choice,currentform) {
3066: var choicearg = choice + 'arg';
3067: // If a radio button in changed, we need to change the argfield
3068: if (current.radiovalue != choice) {
3069: current.radiovalue = choice;
3070: if (current.argfield != null) {
3071: currentform.elements[current.argfield].value = '';
3072: }
3073: if (choice == 'nochange') {
3074: current.argfield = null;
3075: } else {
3076: current.argfield = choicearg;
3077: switch(choice) {
3078: case 'krb':
3079: currentform.elements[current.argfield].value =
3080: "$in{'kerb_def_dom'}";
3081: break;
3082: default:
3083: break;
3084: }
3085: }
3086: }
3087: return;
3088: }
1.22 www 3089:
1.32 matthew 3090: function changed_text(choice,currentform) {
3091: var choicearg = choice + 'arg';
3092: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3093: $Javascript_toUpperCase
1.32 matthew 3094: // clear old field
3095: if ((current.argfield != choicearg) && (current.argfield != null)) {
3096: currentform.elements[current.argfield].value = '';
3097: }
3098: current.argfield = choicearg;
3099: }
3100: set_auth_radio_buttons(choice,currentform);
3101: return;
1.20 www 3102: }
1.32 matthew 3103:
3104: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3105: var numauthchoices = currentform.login.length;
3106: if (typeof numauthchoices == "undefined") {
3107: return;
3108: }
1.32 matthew 3109: var i=0;
1.986 raeburn 3110: while (i < numauthchoices) {
1.32 matthew 3111: if (currentform.login[i].value == newvalue) { break; }
3112: i++;
3113: }
1.986 raeburn 3114: if (i == numauthchoices) {
1.32 matthew 3115: return;
3116: }
3117: current.radiovalue = newvalue;
3118: currentform.login[i].checked = true;
3119: return;
3120: }
3121: END
3122: return $result;
3123: }
3124:
1.1106 raeburn 3125: sub authform_authorwarning {
1.32 matthew 3126: my $result='';
1.144 matthew 3127: $result='<i>'.
3128: &mt('As a general rule, only authors or co-authors should be '.
3129: 'filesystem authenticated '.
3130: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3131: return $result;
3132: }
3133:
1.1106 raeburn 3134: sub authform_nochange {
1.32 matthew 3135: my %in = (
3136: formname => 'document.cu',
3137: kerb_def_dom => 'MSU.EDU',
3138: @_,
3139: );
1.1106 raeburn 3140: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3141: my $result;
1.1104 raeburn 3142: if (!$authnum) {
1.1105 raeburn 3143: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3144: } else {
3145: $result = '<label>'.&mt('[_1] Do not change login data',
3146: '<input type="radio" name="login" value="nochange" '.
3147: 'checked="checked" onclick="'.
1.281 albertel 3148: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3149: '</label>';
1.586 raeburn 3150: }
1.32 matthew 3151: return $result;
3152: }
3153:
1.591 raeburn 3154: sub authform_kerberos {
1.32 matthew 3155: my %in = (
3156: formname => 'document.cu',
3157: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3158: kerb_def_auth => 'krb4',
1.32 matthew 3159: @_,
3160: );
1.586 raeburn 3161: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3162: $autharg,$jscall,$disabled);
1.1106 raeburn 3163: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3164: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3165: $check5 = ' checked="checked"';
1.80 albertel 3166: } else {
1.772 bisitz 3167: $check4 = ' checked="checked"';
1.80 albertel 3168: }
1.1259 raeburn 3169: if ($in{'readonly'}) {
3170: $disabled = ' disabled="disabled"';
3171: }
1.165 raeburn 3172: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3173: if (defined($in{'curr_authtype'})) {
3174: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3175: $krbcheck = ' checked="checked"';
1.623 raeburn 3176: if (defined($in{'mode'})) {
3177: if ($in{'mode'} eq 'modifyuser') {
3178: $krbcheck = '';
3179: }
3180: }
1.591 raeburn 3181: if (defined($in{'curr_kerb_ver'})) {
3182: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3183: $check5 = ' checked="checked"';
1.591 raeburn 3184: $check4 = '';
3185: } else {
1.772 bisitz 3186: $check4 = ' checked="checked"';
1.591 raeburn 3187: $check5 = '';
3188: }
1.586 raeburn 3189: }
1.591 raeburn 3190: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3191: $krbarg = $in{'curr_autharg'};
3192: }
1.586 raeburn 3193: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3194: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3195: $result =
3196: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3197: $in{'curr_autharg'},$krbver);
3198: } else {
3199: $result =
3200: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3201: }
3202: return $result;
3203: }
3204: }
3205: } else {
3206: if ($authnum == 1) {
1.784 bisitz 3207: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3208: }
3209: }
1.586 raeburn 3210: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3211: return;
1.587 raeburn 3212: } elsif ($authtype eq '') {
1.591 raeburn 3213: if (defined($in{'mode'})) {
1.587 raeburn 3214: if ($in{'mode'} eq 'modifycourse') {
3215: if ($authnum == 1) {
1.1259 raeburn 3216: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3217: }
3218: }
3219: }
1.586 raeburn 3220: }
3221: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3222: if ($authtype eq '') {
3223: $authtype = '<input type="radio" name="login" value="krb" '.
3224: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3225: $krbcheck.$disabled.' />';
1.586 raeburn 3226: }
3227: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3228: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3229: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3230: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3231: $in{'curr_authtype'} eq 'krb4')) {
3232: $result .= &mt
1.144 matthew 3233: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3234: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3235: '<label>'.$authtype,
1.281 albertel 3236: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3237: 'value="'.$krbarg.'" '.
1.1259 raeburn 3238: 'onchange="'.$jscall.'"'.$disabled.' />',
3239: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3240: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3241: '</label>');
1.586 raeburn 3242: } elsif ($can_assign{'krb4'}) {
3243: $result .= &mt
3244: ('[_1] Kerberos authenticated with domain [_2] '.
3245: '[_3] Version 4 [_4]',
3246: '<label>'.$authtype,
3247: '</label><input type="text" size="10" name="krbarg" '.
3248: 'value="'.$krbarg.'" '.
1.1259 raeburn 3249: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3250: '<label><input type="hidden" name="krbver" value="4" />',
3251: '</label>');
3252: } elsif ($can_assign{'krb5'}) {
3253: $result .= &mt
3254: ('[_1] Kerberos authenticated with domain [_2] '.
3255: '[_3] Version 5 [_4]',
3256: '<label>'.$authtype,
3257: '</label><input type="text" size="10" name="krbarg" '.
3258: 'value="'.$krbarg.'" '.
1.1259 raeburn 3259: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3260: '<label><input type="hidden" name="krbver" value="5" />',
3261: '</label>');
3262: }
1.32 matthew 3263: return $result;
3264: }
3265:
1.1106 raeburn 3266: sub authform_internal {
1.586 raeburn 3267: my %in = (
1.32 matthew 3268: formname => 'document.cu',
3269: kerb_def_dom => 'MSU.EDU',
3270: @_,
3271: );
1.1259 raeburn 3272: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3273: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3274: if ($in{'readonly'}) {
3275: $disabled = ' disabled="disabled"';
3276: }
1.591 raeburn 3277: if (defined($in{'curr_authtype'})) {
3278: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3279: if ($can_assign{'int'}) {
1.772 bisitz 3280: $intcheck = 'checked="checked" ';
1.623 raeburn 3281: if (defined($in{'mode'})) {
3282: if ($in{'mode'} eq 'modifyuser') {
3283: $intcheck = '';
3284: }
3285: }
1.591 raeburn 3286: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3287: $intarg = $in{'curr_autharg'};
3288: }
3289: } else {
3290: $result = &mt('Currently internally authenticated.');
3291: return $result;
1.165 raeburn 3292: }
3293: }
1.586 raeburn 3294: } else {
3295: if ($authnum == 1) {
1.784 bisitz 3296: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3297: }
3298: }
3299: if (!$can_assign{'int'}) {
3300: return;
1.587 raeburn 3301: } elsif ($authtype eq '') {
1.591 raeburn 3302: if (defined($in{'mode'})) {
1.587 raeburn 3303: if ($in{'mode'} eq 'modifycourse') {
3304: if ($authnum == 1) {
1.1259 raeburn 3305: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3306: }
3307: }
3308: }
1.165 raeburn 3309: }
1.586 raeburn 3310: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3311: if ($authtype eq '') {
3312: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3313: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3314: }
1.605 bisitz 3315: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3316: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3317: $result = &mt
1.144 matthew 3318: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3319: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3320: $result.='<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>';
1.32 matthew 3321: return $result;
3322: }
3323:
1.1104 raeburn 3324: sub authform_local {
1.32 matthew 3325: my %in = (
3326: formname => 'document.cu',
3327: kerb_def_dom => 'MSU.EDU',
3328: @_,
3329: );
1.1259 raeburn 3330: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3331: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3332: if ($in{'readonly'}) {
3333: $disabled = ' disabled="disabled"';
3334: }
1.591 raeburn 3335: if (defined($in{'curr_authtype'})) {
3336: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3337: if ($can_assign{'loc'}) {
1.772 bisitz 3338: $loccheck = 'checked="checked" ';
1.623 raeburn 3339: if (defined($in{'mode'})) {
3340: if ($in{'mode'} eq 'modifyuser') {
3341: $loccheck = '';
3342: }
3343: }
1.591 raeburn 3344: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3345: $locarg = $in{'curr_autharg'};
3346: }
3347: } else {
3348: $result = &mt('Currently using local (institutional) authentication.');
3349: return $result;
1.165 raeburn 3350: }
3351: }
1.586 raeburn 3352: } else {
3353: if ($authnum == 1) {
1.784 bisitz 3354: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3355: }
3356: }
3357: if (!$can_assign{'loc'}) {
3358: return;
1.587 raeburn 3359: } elsif ($authtype eq '') {
1.591 raeburn 3360: if (defined($in{'mode'})) {
1.587 raeburn 3361: if ($in{'mode'} eq 'modifycourse') {
3362: if ($authnum == 1) {
1.1259 raeburn 3363: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3364: }
3365: }
3366: }
1.165 raeburn 3367: }
1.586 raeburn 3368: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3369: if ($authtype eq '') {
3370: $authtype = '<input type="radio" name="login" value="loc" '.
3371: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3372: $jscall.'"'.$disabled.' />';
1.586 raeburn 3373: }
3374: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3375: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3376: $result = &mt('[_1] Local Authentication with argument [_2]',
3377: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3378: return $result;
3379: }
3380:
1.1106 raeburn 3381: sub authform_filesystem {
1.32 matthew 3382: my %in = (
3383: formname => 'document.cu',
3384: kerb_def_dom => 'MSU.EDU',
3385: @_,
3386: );
1.1259 raeburn 3387: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3388: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3389: if ($in{'readonly'}) {
3390: $disabled = ' disabled="disabled"';
3391: }
1.591 raeburn 3392: if (defined($in{'curr_authtype'})) {
3393: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3394: if ($can_assign{'fsys'}) {
1.772 bisitz 3395: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3396: if (defined($in{'mode'})) {
3397: if ($in{'mode'} eq 'modifyuser') {
3398: $fsyscheck = '';
3399: }
3400: }
1.586 raeburn 3401: } else {
3402: $result = &mt('Currently Filesystem Authenticated.');
3403: return $result;
1.1259 raeburn 3404: }
1.586 raeburn 3405: }
3406: } else {
3407: if ($authnum == 1) {
1.784 bisitz 3408: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3409: }
3410: }
3411: if (!$can_assign{'fsys'}) {
3412: return;
1.587 raeburn 3413: } elsif ($authtype eq '') {
1.591 raeburn 3414: if (defined($in{'mode'})) {
1.587 raeburn 3415: if ($in{'mode'} eq 'modifycourse') {
3416: if ($authnum == 1) {
1.1259 raeburn 3417: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3418: }
3419: }
3420: }
1.586 raeburn 3421: }
3422: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3423: if ($authtype eq '') {
3424: $authtype = '<input type="radio" name="login" value="fsys" '.
3425: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3426: $jscall.'"'.$disabled.' />';
1.586 raeburn 3427: }
3428: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3429: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3430: $result = &mt
1.144 matthew 3431: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3432: '<label><input type="radio" name="login" value="fsys" '.
1.1259 raeburn 3433: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />',
1.605 bisitz 3434: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.1259 raeburn 3435: 'onchange="'.$jscall.'"'.$disabled.' />');
1.32 matthew 3436: return $result;
3437: }
3438:
1.586 raeburn 3439: sub get_assignable_auth {
3440: my ($dom) = @_;
3441: if ($dom eq '') {
3442: $dom = $env{'request.role.domain'};
3443: }
3444: my %can_assign = (
3445: krb4 => 1,
3446: krb5 => 1,
3447: int => 1,
3448: loc => 1,
3449: );
3450: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3451: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3452: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3453: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3454: my $context;
3455: if ($env{'request.role'} =~ /^au/) {
3456: $context = 'author';
1.1259 raeburn 3457: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3458: $context = 'domain';
3459: } elsif ($env{'request.course.id'}) {
3460: $context = 'course';
3461: }
3462: if ($context) {
3463: if (ref($authhash->{$context}) eq 'HASH') {
3464: %can_assign = %{$authhash->{$context}};
3465: }
3466: }
3467: }
3468: }
3469: my $authnum = 0;
3470: foreach my $key (keys(%can_assign)) {
3471: if ($can_assign{$key}) {
3472: $authnum ++;
3473: }
3474: }
3475: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3476: $authnum --;
3477: }
3478: return ($authnum,%can_assign);
3479: }
3480:
1.80 albertel 3481: ###############################################################
3482: ## Get Kerberos Defaults for Domain ##
3483: ###############################################################
3484: ##
3485: ## Returns default kerberos version and an associated argument
3486: ## as listed in file domain.tab. If not listed, provides
3487: ## appropriate default domain and kerberos version.
3488: ##
3489: #-------------------------------------------
3490:
3491: =pod
3492:
1.648 raeburn 3493: =item * &get_kerberos_defaults()
1.80 albertel 3494:
3495: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3496: version and domain. If not found, it defaults to version 4 and the
3497: domain of the server.
1.80 albertel 3498:
1.648 raeburn 3499: =over 4
3500:
1.80 albertel 3501: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3502:
1.648 raeburn 3503: =back
3504:
3505: =back
3506:
1.80 albertel 3507: =cut
3508:
3509: #-------------------------------------------
3510: sub get_kerberos_defaults {
3511: my $domain=shift;
1.641 raeburn 3512: my ($krbdef,$krbdefdom);
3513: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3514: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3515: $krbdef = $domdefaults{'auth_def'};
3516: $krbdefdom = $domdefaults{'auth_arg_def'};
3517: } else {
1.80 albertel 3518: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3519: my $krbdefdom=$1;
3520: $krbdefdom=~tr/a-z/A-Z/;
3521: $krbdef = "krb4";
3522: }
3523: return ($krbdef,$krbdefdom);
3524: }
1.112 bowersj2 3525:
1.32 matthew 3526:
1.46 matthew 3527: ###############################################################
3528: ## Thesaurus Functions ##
3529: ###############################################################
1.20 www 3530:
1.46 matthew 3531: =pod
1.20 www 3532:
1.112 bowersj2 3533: =head1 Thesaurus Functions
3534:
3535: =over 4
3536:
1.648 raeburn 3537: =item * &initialize_keywords()
1.46 matthew 3538:
3539: Initializes the package variable %Keywords if it is empty. Uses the
3540: package variable $thesaurus_db_file.
3541:
3542: =cut
3543:
3544: ###################################################
3545:
3546: sub initialize_keywords {
3547: return 1 if (scalar keys(%Keywords));
3548: # If we are here, %Keywords is empty, so fill it up
3549: # Make sure the file we need exists...
3550: if (! -e $thesaurus_db_file) {
3551: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3552: " failed because it does not exist");
3553: return 0;
3554: }
3555: # Set up the hash as a database
3556: my %thesaurus_db;
3557: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3558: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3559: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3560: $thesaurus_db_file);
3561: return 0;
3562: }
3563: # Get the average number of appearances of a word.
3564: my $avecount = $thesaurus_db{'average.count'};
3565: # Put keywords (those that appear > average) into %Keywords
3566: while (my ($word,$data)=each (%thesaurus_db)) {
3567: my ($count,undef) = split /:/,$data;
3568: $Keywords{$word}++ if ($count > $avecount);
3569: }
3570: untie %thesaurus_db;
3571: # Remove special values from %Keywords.
1.356 albertel 3572: foreach my $value ('total.count','average.count') {
3573: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3574: }
1.46 matthew 3575: return 1;
3576: }
3577:
3578: ###################################################
3579:
3580: =pod
3581:
1.648 raeburn 3582: =item * &keyword($word)
1.46 matthew 3583:
3584: Returns true if $word is a keyword. A keyword is a word that appears more
3585: than the average number of times in the thesaurus database. Calls
3586: &initialize_keywords
3587:
3588: =cut
3589:
3590: ###################################################
1.20 www 3591:
3592: sub keyword {
1.46 matthew 3593: return if (!&initialize_keywords());
3594: my $word=lc(shift());
3595: $word=~s/\W//g;
3596: return exists($Keywords{$word});
1.20 www 3597: }
1.46 matthew 3598:
3599: ###############################################################
3600:
3601: =pod
1.20 www 3602:
1.648 raeburn 3603: =item * &get_related_words()
1.46 matthew 3604:
1.160 matthew 3605: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3606: an array of words. If the keyword is not in the thesaurus, an empty array
3607: will be returned. The order of the words returned is determined by the
3608: database which holds them.
3609:
3610: Uses global $thesaurus_db_file.
3611:
1.1057 foxr 3612:
1.46 matthew 3613: =cut
3614:
3615: ###############################################################
3616: sub get_related_words {
3617: my $keyword = shift;
3618: my %thesaurus_db;
3619: if (! -e $thesaurus_db_file) {
3620: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3621: "failed because the file does not exist");
3622: return ();
3623: }
3624: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3625: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3626: return ();
3627: }
3628: my @Words=();
1.429 www 3629: my $count=0;
1.46 matthew 3630: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3631: # The first element is the number of times
3632: # the word appears. We do not need it now.
1.429 www 3633: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3634: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3635: my $threshold=$mostfrequentcount/10;
3636: foreach my $possibleword (@RelatedWords) {
3637: my ($word,$wordcount)=split(/\,/,$possibleword);
3638: if ($wordcount>$threshold) {
3639: push(@Words,$word);
3640: $count++;
3641: if ($count>10) { last; }
3642: }
1.20 www 3643: }
3644: }
1.46 matthew 3645: untie %thesaurus_db;
3646: return @Words;
1.14 harris41 3647: }
1.1090 foxr 3648: ###############################################################
3649: #
3650: # Spell checking
3651: #
3652:
3653: =pod
3654:
1.1142 raeburn 3655: =back
3656:
1.1090 foxr 3657: =head1 Spell checking
3658:
3659: =over 4
3660:
3661: =item * &check_spelling($wordlist $language)
3662:
3663: Takes a string containing words and feeds it to an external
3664: spellcheck program via a pipeline. Returns a string containing
3665: them mis-spelled words.
3666:
3667: Parameters:
3668:
3669: =over 4
3670:
3671: =item - $wordlist
3672:
3673: String that will be fed into the spellcheck program.
3674:
3675: =item - $language
3676:
3677: Language string that specifies the language for which the spell
3678: check will be performed.
3679:
3680: =back
3681:
3682: =back
3683:
3684: Note: This sub assumes that aspell is installed.
3685:
3686:
3687: =cut
3688:
1.46 matthew 3689:
1.1090 foxr 3690: sub check_spelling {
3691: my ($wordlist, $language) = @_;
1.1091 foxr 3692: my @misspellings;
3693:
3694: # Generate the speller and set the langauge.
3695: # if explicitly selected:
1.1090 foxr 3696:
1.1091 foxr 3697: my $speller = Text::Aspell->new;
1.1090 foxr 3698: if ($language) {
1.1091 foxr 3699: $speller->set_option('lang', $language);
1.1090 foxr 3700: }
3701:
1.1091 foxr 3702: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3703:
1.1091 foxr 3704: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3705:
1.1091 foxr 3706: foreach my $word (@words) {
3707: if(! $speller->check($word)) {
3708: push(@misspellings, $word);
1.1090 foxr 3709: }
3710: }
1.1091 foxr 3711: return join(' ', @misspellings);
3712:
1.1090 foxr 3713: }
3714:
1.61 www 3715: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3716: =pod
3717:
1.112 bowersj2 3718: =head1 User Name Functions
3719:
3720: =over 4
3721:
1.648 raeburn 3722: =item * &plainname($uname,$udom,$first)
1.81 albertel 3723:
1.112 bowersj2 3724: Takes a users logon name and returns it as a string in
1.226 albertel 3725: "first middle last generation" form
3726: if $first is set to 'lastname' then it returns it as
3727: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3728:
3729: =cut
1.61 www 3730:
1.295 www 3731:
1.81 albertel 3732: ###############################################################
1.61 www 3733: sub plainname {
1.226 albertel 3734: my ($uname,$udom,$first)=@_;
1.537 albertel 3735: return if (!defined($uname) || !defined($udom));
1.295 www 3736: my %names=&getnames($uname,$udom);
1.226 albertel 3737: my $name=&Apache::lonnet::format_name($names{'firstname'},
3738: $names{'middlename'},
3739: $names{'lastname'},
3740: $names{'generation'},$first);
3741: $name=~s/^\s+//;
1.62 www 3742: $name=~s/\s+$//;
3743: $name=~s/\s+/ /g;
1.353 albertel 3744: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3745: return $name;
1.61 www 3746: }
1.66 www 3747:
3748: # -------------------------------------------------------------------- Nickname
1.81 albertel 3749: =pod
3750:
1.648 raeburn 3751: =item * &nickname($uname,$udom)
1.81 albertel 3752:
3753: Gets a users name and returns it as a string as
3754:
3755: ""nickname""
1.66 www 3756:
1.81 albertel 3757: if the user has a nickname or
3758:
3759: "first middle last generation"
3760:
3761: if the user does not
3762:
3763: =cut
1.66 www 3764:
3765: sub nickname {
3766: my ($uname,$udom)=@_;
1.537 albertel 3767: return if (!defined($uname) || !defined($udom));
1.295 www 3768: my %names=&getnames($uname,$udom);
1.68 albertel 3769: my $name=$names{'nickname'};
1.66 www 3770: if ($name) {
3771: $name='"'.$name.'"';
3772: } else {
3773: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3774: $names{'lastname'}.' '.$names{'generation'};
3775: $name=~s/\s+$//;
3776: $name=~s/\s+/ /g;
3777: }
3778: return $name;
3779: }
3780:
1.295 www 3781: sub getnames {
3782: my ($uname,$udom)=@_;
1.537 albertel 3783: return if (!defined($uname) || !defined($udom));
1.433 albertel 3784: if ($udom eq 'public' && $uname eq 'public') {
3785: return ('lastname' => &mt('Public'));
3786: }
1.295 www 3787: my $id=$uname.':'.$udom;
3788: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3789: if ($cached) {
3790: return %{$names};
3791: } else {
3792: my %loadnames=&Apache::lonnet::get('environment',
3793: ['firstname','middlename','lastname','generation','nickname'],
3794: $udom,$uname);
3795: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3796: return %loadnames;
3797: }
3798: }
1.61 www 3799:
1.542 raeburn 3800: # -------------------------------------------------------------------- getemails
1.648 raeburn 3801:
1.542 raeburn 3802: =pod
3803:
1.648 raeburn 3804: =item * &getemails($uname,$udom)
1.542 raeburn 3805:
3806: Gets a user's email information and returns it as a hash with keys:
3807: notification, critnotification, permanentemail
3808:
3809: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3810: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3811:
1.648 raeburn 3812:
1.542 raeburn 3813: =cut
3814:
1.648 raeburn 3815:
1.466 albertel 3816: sub getemails {
3817: my ($uname,$udom)=@_;
3818: if ($udom eq 'public' && $uname eq 'public') {
3819: return;
3820: }
1.467 www 3821: if (!$udom) { $udom=$env{'user.domain'}; }
3822: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3823: my $id=$uname.':'.$udom;
3824: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3825: if ($cached) {
3826: return %{$names};
3827: } else {
3828: my %loadnames=&Apache::lonnet::get('environment',
3829: ['notification','critnotification',
3830: 'permanentemail'],
3831: $udom,$uname);
3832: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3833: return %loadnames;
3834: }
3835: }
3836:
1.551 albertel 3837: sub flush_email_cache {
3838: my ($uname,$udom)=@_;
3839: if (!$udom) { $udom =$env{'user.domain'}; }
3840: if (!$uname) { $uname=$env{'user.name'}; }
3841: return if ($udom eq 'public' && $uname eq 'public');
3842: my $id=$uname.':'.$udom;
3843: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3844: }
3845:
1.728 raeburn 3846: # -------------------------------------------------------------------- getlangs
3847:
3848: =pod
3849:
3850: =item * &getlangs($uname,$udom)
3851:
3852: Gets a user's language preference and returns it as a hash with key:
3853: language.
3854:
3855: =cut
3856:
3857:
3858: sub getlangs {
3859: my ($uname,$udom) = @_;
3860: if (!$udom) { $udom =$env{'user.domain'}; }
3861: if (!$uname) { $uname=$env{'user.name'}; }
3862: my $id=$uname.':'.$udom;
3863: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3864: if ($cached) {
3865: return %{$langs};
3866: } else {
3867: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3868: $udom,$uname);
3869: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3870: return %loadlangs;
3871: }
3872: }
3873:
3874: sub flush_langs_cache {
3875: my ($uname,$udom)=@_;
3876: if (!$udom) { $udom =$env{'user.domain'}; }
3877: if (!$uname) { $uname=$env{'user.name'}; }
3878: return if ($udom eq 'public' && $uname eq 'public');
3879: my $id=$uname.':'.$udom;
3880: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3881: }
3882:
1.61 www 3883: # ------------------------------------------------------------------ Screenname
1.81 albertel 3884:
3885: =pod
3886:
1.648 raeburn 3887: =item * &screenname($uname,$udom)
1.81 albertel 3888:
3889: Gets a users screenname and returns it as a string
3890:
3891: =cut
1.61 www 3892:
3893: sub screenname {
3894: my ($uname,$udom)=@_;
1.258 albertel 3895: if ($uname eq $env{'user.name'} &&
3896: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3897: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3898: return $names{'screenname'};
1.62 www 3899: }
3900:
1.212 albertel 3901:
1.802 bisitz 3902: # ------------------------------------------------------------- Confirm Wrapper
3903: =pod
3904:
1.1142 raeburn 3905: =item * &confirmwrapper($message)
1.802 bisitz 3906:
3907: Wrap messages about completion of operation in box
3908:
3909: =cut
3910:
3911: sub confirmwrapper {
3912: my ($message)=@_;
3913: if ($message) {
3914: return "\n".'<div class="LC_confirm_box">'."\n"
3915: .$message."\n"
3916: .'</div>'."\n";
3917: } else {
3918: return $message;
3919: }
3920: }
3921:
1.62 www 3922: # ------------------------------------------------------------- Message Wrapper
3923:
3924: sub messagewrapper {
1.369 www 3925: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3926: return
1.441 albertel 3927: '<a href="/adm/email?compose=individual&'.
3928: 'recname='.$username.'&recdom='.$domain.
3929: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3930: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3931: }
1.802 bisitz 3932:
1.74 www 3933: # --------------------------------------------------------------- Notes Wrapper
3934:
3935: sub noteswrapper {
3936: my ($link,$un,$do)=@_;
3937: return
1.896 amueller 3938: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3939: }
1.802 bisitz 3940:
1.62 www 3941: # ------------------------------------------------------------- Aboutme Wrapper
3942:
3943: sub aboutmewrapper {
1.1070 raeburn 3944: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3945: if (!defined($username) && !defined($domain)) {
3946: return;
3947: }
1.1096 raeburn 3948: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3949: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3950: }
3951:
3952: # ------------------------------------------------------------ Syllabus Wrapper
3953:
3954: sub syllabuswrapper {
1.707 bisitz 3955: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3956: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3957: }
1.14 harris41 3958:
1.802 bisitz 3959: # -----------------------------------------------------------------------------
3960:
1.208 matthew 3961: sub track_student_link {
1.887 raeburn 3962: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3963: my $link ="/adm/trackstudent?";
1.208 matthew 3964: my $title = 'View recent activity';
3965: if (defined($sname) && $sname !~ /^\s*$/ &&
3966: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3967: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3968: $title .= ' of this student';
1.268 albertel 3969: }
1.208 matthew 3970: if (defined($target) && $target !~ /^\s*$/) {
3971: $target = qq{target="$target"};
3972: } else {
3973: $target = '';
3974: }
1.268 albertel 3975: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3976: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3977: $title = &mt($title);
3978: $linktext = &mt($linktext);
1.448 albertel 3979: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3980: &help_open_topic('View_recent_activity');
1.208 matthew 3981: }
3982:
1.781 raeburn 3983: sub slot_reservations_link {
3984: my ($linktext,$sname,$sdom,$target) = @_;
3985: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3986: my $title = 'View slot reservation history';
3987: if (defined($sname) && $sname !~ /^\s*$/ &&
3988: defined($sdom) && $sdom !~ /^\s*$/) {
3989: $link .= "&uname=$sname&udom=$sdom";
3990: $title .= ' of this student';
3991: }
3992: if (defined($target) && $target !~ /^\s*$/) {
3993: $target = qq{target="$target"};
3994: } else {
3995: $target = '';
3996: }
3997: $title = &mt($title);
3998: $linktext = &mt($linktext);
3999: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4000: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4001:
4002: }
4003:
1.508 www 4004: # ===================================================== Display a student photo
4005:
4006:
1.509 albertel 4007: sub student_image_tag {
1.508 www 4008: my ($domain,$user)=@_;
4009: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4010: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4011: return '<img src="'.$imgsrc.'" align="right" />';
4012: } else {
4013: return '';
4014: }
4015: }
4016:
1.112 bowersj2 4017: =pod
4018:
4019: =back
4020:
4021: =head1 Access .tab File Data
4022:
4023: =over 4
4024:
1.648 raeburn 4025: =item * &languageids()
1.112 bowersj2 4026:
4027: returns list of all language ids
4028:
4029: =cut
4030:
1.14 harris41 4031: sub languageids {
1.16 harris41 4032: return sort(keys(%language));
1.14 harris41 4033: }
4034:
1.112 bowersj2 4035: =pod
4036:
1.648 raeburn 4037: =item * &languagedescription()
1.112 bowersj2 4038:
4039: returns description of a specified language id
4040:
4041: =cut
4042:
1.14 harris41 4043: sub languagedescription {
1.125 www 4044: my $code=shift;
4045: return ($supported_language{$code}?'* ':'').
4046: $language{$code}.
1.126 www 4047: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4048: }
4049:
1.1048 foxr 4050: =pod
4051:
4052: =item * &plainlanguagedescription
4053:
4054: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4055: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4056:
4057: =cut
4058:
1.145 www 4059: sub plainlanguagedescription {
4060: my $code=shift;
4061: return $language{$code};
4062: }
4063:
1.1048 foxr 4064: =pod
4065:
4066: =item * &supportedlanguagecode
4067:
4068: Returns the supported language code (e.g. sptutf maps to pt) given a language
4069: code.
4070:
4071: =cut
4072:
1.145 www 4073: sub supportedlanguagecode {
4074: my $code=shift;
4075: return $supported_language{$code};
1.97 www 4076: }
4077:
1.112 bowersj2 4078: =pod
4079:
1.1048 foxr 4080: =item * &latexlanguage()
4081:
4082: Given a language key code returns the correspondnig language to use
4083: to select the correct hyphenation on LaTeX printouts. This is undef if there
4084: is no supported hyphenation for the language code.
4085:
4086: =cut
4087:
4088: sub latexlanguage {
4089: my $code = shift;
4090: return $latex_language{$code};
4091: }
4092:
4093: =pod
4094:
4095: =item * &latexhyphenation()
4096:
4097: Same as above but what's supplied is the language as it might be stored
4098: in the metadata.
4099:
4100: =cut
4101:
4102: sub latexhyphenation {
4103: my $key = shift;
4104: return $latex_language_bykey{$key};
4105: }
4106:
4107: =pod
4108:
1.648 raeburn 4109: =item * ©rightids()
1.112 bowersj2 4110:
4111: returns list of all copyrights
4112:
4113: =cut
4114:
4115: sub copyrightids {
4116: return sort(keys(%cprtag));
4117: }
4118:
4119: =pod
4120:
1.648 raeburn 4121: =item * ©rightdescription()
1.112 bowersj2 4122:
4123: returns description of a specified copyright id
4124:
4125: =cut
4126:
4127: sub copyrightdescription {
1.166 www 4128: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4129: }
1.197 matthew 4130:
4131: =pod
4132:
1.648 raeburn 4133: =item * &source_copyrightids()
1.192 taceyjo1 4134:
4135: returns list of all source copyrights
4136:
4137: =cut
4138:
4139: sub source_copyrightids {
4140: return sort(keys(%scprtag));
4141: }
4142:
4143: =pod
4144:
1.648 raeburn 4145: =item * &source_copyrightdescription()
1.192 taceyjo1 4146:
4147: returns description of a specified source copyright id
4148:
4149: =cut
4150:
4151: sub source_copyrightdescription {
4152: return &mt($scprtag{shift(@_)});
4153: }
1.112 bowersj2 4154:
4155: =pod
4156:
1.648 raeburn 4157: =item * &filecategories()
1.112 bowersj2 4158:
4159: returns list of all file categories
4160:
4161: =cut
4162:
4163: sub filecategories {
4164: return sort(keys(%category_extensions));
4165: }
4166:
4167: =pod
4168:
1.648 raeburn 4169: =item * &filecategorytypes()
1.112 bowersj2 4170:
4171: returns list of file types belonging to a given file
4172: category
4173:
4174: =cut
4175:
4176: sub filecategorytypes {
1.356 albertel 4177: my ($cat) = @_;
1.1248 raeburn 4178: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4179: return @{$category_extensions{lc($cat)}};
4180: } else {
4181: return ();
4182: }
1.112 bowersj2 4183: }
4184:
4185: =pod
4186:
1.648 raeburn 4187: =item * &fileembstyle()
1.112 bowersj2 4188:
4189: returns embedding style for a specified file type
4190:
4191: =cut
4192:
4193: sub fileembstyle {
4194: return $fe{lc(shift(@_))};
1.169 www 4195: }
4196:
1.351 www 4197: sub filemimetype {
4198: return $fm{lc(shift(@_))};
4199: }
4200:
1.169 www 4201:
4202: sub filecategoryselect {
4203: my ($name,$value)=@_;
1.189 matthew 4204: return &select_form($value,$name,
1.970 raeburn 4205: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4206: }
4207:
4208: =pod
4209:
1.648 raeburn 4210: =item * &filedescription()
1.112 bowersj2 4211:
4212: returns description for a specified file type
4213:
4214: =cut
4215:
4216: sub filedescription {
1.188 matthew 4217: my $file_description = $fd{lc(shift())};
4218: $file_description =~ s:([\[\]]):~$1:g;
4219: return &mt($file_description);
1.112 bowersj2 4220: }
4221:
4222: =pod
4223:
1.648 raeburn 4224: =item * &filedescriptionex()
1.112 bowersj2 4225:
4226: returns description for a specified file type with
4227: extra formatting
4228:
4229: =cut
4230:
4231: sub filedescriptionex {
4232: my $ex=shift;
1.188 matthew 4233: my $file_description = $fd{lc($ex)};
4234: $file_description =~ s:([\[\]]):~$1:g;
4235: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4236: }
4237:
4238: # End of .tab access
4239: =pod
4240:
4241: =back
4242:
4243: =cut
4244:
4245: # ------------------------------------------------------------------ File Types
4246: sub fileextensions {
4247: return sort(keys(%fe));
4248: }
4249:
1.97 www 4250: # ----------------------------------------------------------- Display Languages
4251: # returns a hash with all desired display languages
4252: #
4253:
4254: sub display_languages {
4255: my %languages=();
1.695 raeburn 4256: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4257: $languages{$lang}=1;
1.97 www 4258: }
4259: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4260: if ($env{'form.displaylanguage'}) {
1.356 albertel 4261: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4262: $languages{$lang}=1;
1.97 www 4263: }
4264: }
4265: return %languages;
1.14 harris41 4266: }
4267:
1.582 albertel 4268: sub languages {
4269: my ($possible_langs) = @_;
1.695 raeburn 4270: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4271: if (!ref($possible_langs)) {
4272: if( wantarray ) {
4273: return @preferred_langs;
4274: } else {
4275: return $preferred_langs[0];
4276: }
4277: }
4278: my %possibilities = map { $_ => 1 } (@$possible_langs);
4279: my @preferred_possibilities;
4280: foreach my $preferred_lang (@preferred_langs) {
4281: if (exists($possibilities{$preferred_lang})) {
4282: push(@preferred_possibilities, $preferred_lang);
4283: }
4284: }
4285: if( wantarray ) {
4286: return @preferred_possibilities;
4287: }
4288: return $preferred_possibilities[0];
4289: }
4290:
1.742 raeburn 4291: sub user_lang {
4292: my ($touname,$toudom,$fromcid) = @_;
4293: my @userlangs;
4294: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4295: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4296: $env{'course.'.$fromcid.'.languages'}));
4297: } else {
4298: my %langhash = &getlangs($touname,$toudom);
4299: if ($langhash{'languages'} ne '') {
4300: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4301: } else {
4302: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4303: if ($domdefs{'lang_def'} ne '') {
4304: @userlangs = ($domdefs{'lang_def'});
4305: }
4306: }
4307: }
4308: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4309: my $user_lh = Apache::localize->get_handle(@languages);
4310: return $user_lh;
4311: }
4312:
4313:
1.112 bowersj2 4314: ###############################################################
4315: ## Student Answer Attempts ##
4316: ###############################################################
4317:
4318: =pod
4319:
4320: =head1 Alternate Problem Views
4321:
4322: =over 4
4323:
1.648 raeburn 4324: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4325: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4326:
4327: Return string with previous attempt on problem. Arguments:
4328:
4329: =over 4
4330:
4331: =item * $symb: Problem, including path
4332:
4333: =item * $username: username of the desired student
4334:
4335: =item * $domain: domain of the desired student
1.14 harris41 4336:
1.112 bowersj2 4337: =item * $course: Course ID
1.14 harris41 4338:
1.112 bowersj2 4339: =item * $getattempt: Leave blank for all attempts, otherwise put
4340: something
1.14 harris41 4341:
1.112 bowersj2 4342: =item * $regexp: if string matches this regexp, the string will be
4343: sent to $gradesub
1.14 harris41 4344:
1.112 bowersj2 4345: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4346:
1.1199 raeburn 4347: =item * $usec: section of the desired student
4348:
4349: =item * $identifier: counter for student (multiple students one problem) or
4350: problem (one student; whole sequence).
4351:
1.112 bowersj2 4352: =back
1.14 harris41 4353:
1.112 bowersj2 4354: The output string is a table containing all desired attempts, if any.
1.16 harris41 4355:
1.112 bowersj2 4356: =cut
1.1 albertel 4357:
4358: sub get_previous_attempt {
1.1199 raeburn 4359: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4360: my $prevattempts='';
1.43 ng 4361: no strict 'refs';
1.1 albertel 4362: if ($symb) {
1.3 albertel 4363: my (%returnhash)=
4364: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4365: if ($returnhash{'version'}) {
4366: my %lasthash=();
4367: my $version;
4368: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4369: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4370: if ($key =~ /\.rawrndseed$/) {
4371: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4372: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4373: } else {
4374: $lasthash{$key}=$returnhash{$version.':'.$key};
4375: }
1.19 harris41 4376: }
1.1 albertel 4377: }
1.596 albertel 4378: $prevattempts=&start_data_table().&start_data_table_header_row();
4379: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4380: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4381: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4382: foreach my $key (sort(keys(%lasthash))) {
4383: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4384: if ($#parts > 0) {
1.31 albertel 4385: my $data=$parts[-1];
1.989 raeburn 4386: next if ($data eq 'foilorder');
1.31 albertel 4387: pop(@parts);
1.1010 www 4388: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4389: if ($data eq 'type') {
4390: unless ($showsurv) {
4391: my $id = join(',',@parts);
4392: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4393: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4394: $lasthidden{$ign.'.'.$id} = 1;
4395: }
1.945 raeburn 4396: }
1.1199 raeburn 4397: if ($identifier ne '') {
4398: my $id = join(',',@parts);
4399: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4400: $domain,$username,$usec,undef,$course) =~ /^no/) {
4401: $hidestatus{$ign.'.'.$id} = 1;
4402: }
4403: }
4404: } elsif ($data eq 'regrader') {
4405: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4406: my $id = join(',',@parts);
4407: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4408: }
1.1010 www 4409: }
1.31 albertel 4410: } else {
1.41 ng 4411: if ($#parts == 0) {
4412: $prevattempts.='<th>'.$parts[0].'</th>';
4413: } else {
4414: $prevattempts.='<th>'.$ign.'</th>';
4415: }
1.31 albertel 4416: }
1.16 harris41 4417: }
1.596 albertel 4418: $prevattempts.=&end_data_table_header_row();
1.40 ng 4419: if ($getattempt eq '') {
1.1199 raeburn 4420: my (%solved,%resets,%probstatus);
1.1200 raeburn 4421: if (($identifier ne '') && (keys(%regraded) > 0)) {
4422: for ($version=1;$version<=$returnhash{'version'};$version++) {
4423: foreach my $id (keys(%regraded)) {
4424: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4425: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4426: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4427: push(@{$resets{$id}},$version);
1.1199 raeburn 4428: }
4429: }
4430: }
1.1200 raeburn 4431: }
4432: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4433: my (@hidden,@unsolved);
1.945 raeburn 4434: if (%typeparts) {
4435: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4436: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4437: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4438: push(@hidden,$id);
1.1199 raeburn 4439: } elsif ($identifier ne '') {
4440: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4441: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4442: ($hidestatus{$id})) {
1.1200 raeburn 4443: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4444: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4445: push(@{$solved{$id}},$version);
4446: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4447: (ref($solved{$id}) eq 'ARRAY')) {
4448: my $skip;
4449: if (ref($resets{$id}) eq 'ARRAY') {
4450: foreach my $reset (@{$resets{$id}}) {
4451: if ($reset > $solved{$id}[-1]) {
4452: $skip=1;
4453: last;
4454: }
4455: }
4456: }
4457: unless ($skip) {
4458: my ($ign,$partslist) = split(/\./,$id,2);
4459: push(@unsolved,$partslist);
4460: }
4461: }
4462: }
1.945 raeburn 4463: }
4464: }
4465: }
4466: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4467: '<td>'.&mt('Transaction [_1]',$version);
4468: if (@unsolved) {
4469: $prevattempts .= '<span class="LC_nobreak"><label>'.
4470: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4471: &mt('Hide').'</label></span>';
4472: }
4473: $prevattempts .= '</td>';
1.945 raeburn 4474: if (@hidden) {
4475: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4476: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4477: my $hide;
4478: foreach my $id (@hidden) {
4479: if ($key =~ /^\Q$id\E/) {
4480: $hide = 1;
4481: last;
4482: }
4483: }
4484: if ($hide) {
4485: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4486: if (($data eq 'award') || ($data eq 'awarddetail')) {
4487: my $value = &format_previous_attempt_value($key,
4488: $returnhash{$version.':'.$key});
1.1173 kruse 4489: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4490: } else {
4491: $prevattempts.='<td> </td>';
4492: }
4493: } else {
4494: if ($key =~ /\./) {
1.1212 raeburn 4495: my $value = $returnhash{$version.':'.$key};
4496: if ($key =~ /\.rndseed$/) {
4497: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4498: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4499: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4500: }
4501: }
4502: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4503: ' </td>';
1.945 raeburn 4504: } else {
4505: $prevattempts.='<td> </td>';
4506: }
4507: }
4508: }
4509: } else {
4510: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4511: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4512: my $value = $returnhash{$version.':'.$key};
4513: if ($key =~ /\.rndseed$/) {
4514: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4515: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4516: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4517: }
4518: }
4519: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4520: ' </td>';
1.945 raeburn 4521: }
4522: }
4523: $prevattempts.=&end_data_table_row();
1.40 ng 4524: }
1.1 albertel 4525: }
1.945 raeburn 4526: my @currhidden = keys(%lasthidden);
1.596 albertel 4527: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4528: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4529: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4530: if (%typeparts) {
4531: my $hidden;
4532: foreach my $id (@currhidden) {
4533: if ($key =~ /^\Q$id\E/) {
4534: $hidden = 1;
4535: last;
4536: }
4537: }
4538: if ($hidden) {
4539: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4540: if (($data eq 'award') || ($data eq 'awarddetail')) {
4541: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4542: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4543: $value = &$gradesub($value);
4544: }
1.1173 kruse 4545: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4546: } else {
4547: $prevattempts.='<td> </td>';
4548: }
4549: } else {
4550: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4551: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4552: $value = &$gradesub($value);
4553: }
1.1173 kruse 4554: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4555: }
4556: } else {
4557: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4558: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4559: $value = &$gradesub($value);
4560: }
1.1173 kruse 4561: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4562: }
1.16 harris41 4563: }
1.596 albertel 4564: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4565: } else {
1.596 albertel 4566: $prevattempts=
4567: &start_data_table().&start_data_table_row().
4568: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4569: &end_data_table_row().&end_data_table();
1.1 albertel 4570: }
4571: } else {
1.596 albertel 4572: $prevattempts=
4573: &start_data_table().&start_data_table_row().
4574: '<td>'.&mt('No data.').'</td>'.
4575: &end_data_table_row().&end_data_table();
1.1 albertel 4576: }
1.10 albertel 4577: }
4578:
1.581 albertel 4579: sub format_previous_attempt_value {
4580: my ($key,$value) = @_;
1.1011 www 4581: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4582: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4583: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4584: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4585: } elsif ($key =~ /answerstring$/) {
4586: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4587: my @answer = %answers;
4588: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4589: my @anskeys = sort(keys(%answers));
4590: if (@anskeys == 1) {
4591: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4592: if ($answer =~ m{\0}) {
4593: $answer =~ s{\0}{,}g;
1.988 raeburn 4594: }
4595: my $tag_internal_answer_name = 'INTERNAL';
4596: if ($anskeys[0] eq $tag_internal_answer_name) {
4597: $value = $answer;
4598: } else {
4599: $value = $anskeys[0].'='.$answer;
4600: }
4601: } else {
4602: foreach my $ans (@anskeys) {
4603: my $answer = $answers{$ans};
1.1001 raeburn 4604: if ($answer =~ m{\0}) {
4605: $answer =~ s{\0}{,}g;
1.988 raeburn 4606: }
4607: $value .= $ans.'='.$answer.'<br />';;
4608: }
4609: }
1.581 albertel 4610: } else {
1.1173 kruse 4611: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4612: }
4613: return $value;
4614: }
4615:
4616:
1.107 albertel 4617: sub relative_to_absolute {
4618: my ($url,$output)=@_;
4619: my $parser=HTML::TokeParser->new(\$output);
4620: my $token;
4621: my $thisdir=$url;
4622: my @rlinks=();
4623: while ($token=$parser->get_token) {
4624: if ($token->[0] eq 'S') {
4625: if ($token->[1] eq 'a') {
4626: if ($token->[2]->{'href'}) {
4627: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4628: }
4629: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4630: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4631: } elsif ($token->[1] eq 'base') {
4632: $thisdir=$token->[2]->{'href'};
4633: }
4634: }
4635: }
4636: $thisdir=~s-/[^/]*$--;
1.356 albertel 4637: foreach my $link (@rlinks) {
1.726 raeburn 4638: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4639: ($link=~/^\//) ||
4640: ($link=~/^javascript:/i) ||
4641: ($link=~/^mailto:/i) ||
4642: ($link=~/^\#/)) {
4643: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4644: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4645: }
4646: }
4647: # -------------------------------------------------- Deal with Applet codebases
4648: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4649: return $output;
4650: }
4651:
1.112 bowersj2 4652: =pod
4653:
1.648 raeburn 4654: =item * &get_student_view()
1.112 bowersj2 4655:
4656: show a snapshot of what student was looking at
4657:
4658: =cut
4659:
1.10 albertel 4660: sub get_student_view {
1.186 albertel 4661: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4662: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4663: my (%form);
1.10 albertel 4664: my @elements=('symb','courseid','domain','username');
4665: foreach my $element (@elements) {
1.186 albertel 4666: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4667: }
1.186 albertel 4668: if (defined($moreenv)) {
4669: %form=(%form,%{$moreenv});
4670: }
1.236 albertel 4671: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4672: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4673: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4674: $userview=~s/\<body[^\>]*\>//gi;
4675: $userview=~s/\<\/body\>//gi;
4676: $userview=~s/\<html\>//gi;
4677: $userview=~s/\<\/html\>//gi;
4678: $userview=~s/\<head\>//gi;
4679: $userview=~s/\<\/head\>//gi;
4680: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4681: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4682: if (wantarray) {
4683: return ($userview,$response);
4684: } else {
4685: return $userview;
4686: }
4687: }
4688:
4689: sub get_student_view_with_retries {
4690: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4691:
4692: my $ok = 0; # True if we got a good response.
4693: my $content;
4694: my $response;
4695:
4696: # Try to get the student_view done. within the retries count:
4697:
4698: do {
4699: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4700: $ok = $response->is_success;
4701: if (!$ok) {
4702: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4703: }
4704: $retries--;
4705: } while (!$ok && ($retries > 0));
4706:
4707: if (!$ok) {
4708: $content = ''; # On error return an empty content.
4709: }
1.651 www 4710: if (wantarray) {
4711: return ($content, $response);
4712: } else {
4713: return $content;
4714: }
1.11 albertel 4715: }
4716:
1.112 bowersj2 4717: =pod
4718:
1.648 raeburn 4719: =item * &get_student_answers()
1.112 bowersj2 4720:
4721: show a snapshot of how student was answering problem
4722:
4723: =cut
4724:
1.11 albertel 4725: sub get_student_answers {
1.100 sakharuk 4726: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4727: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4728: my (%moreenv);
1.11 albertel 4729: my @elements=('symb','courseid','domain','username');
4730: foreach my $element (@elements) {
1.186 albertel 4731: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4732: }
1.186 albertel 4733: $moreenv{'grade_target'}='answer';
4734: %moreenv=(%form,%moreenv);
1.497 raeburn 4735: $feedurl = &Apache::lonnet::clutter($feedurl);
4736: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4737: return $userview;
1.1 albertel 4738: }
1.116 albertel 4739:
4740: =pod
4741:
4742: =item * &submlink()
4743:
1.242 albertel 4744: Inputs: $text $uname $udom $symb $target
1.116 albertel 4745:
4746: Returns: A link to grades.pm such as to see the SUBM view of a student
4747:
4748: =cut
4749:
4750: ###############################################
4751: sub submlink {
1.242 albertel 4752: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4753: if (!($uname && $udom)) {
4754: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4755: &Apache::lonnet::whichuser($symb);
1.116 albertel 4756: if (!$symb) { $symb=$cursymb; }
4757: }
1.254 matthew 4758: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4759: $symb=&escape($symb);
1.960 bisitz 4760: if ($target) { $target=" target=\"$target\""; }
4761: return
4762: '<a href="/adm/grades?command=submission'.
4763: '&symb='.$symb.
4764: '&student='.$uname.
4765: '&userdom='.$udom.'"'.
4766: $target.'>'.$text.'</a>';
1.242 albertel 4767: }
4768: ##############################################
4769:
4770: =pod
4771:
4772: =item * &pgrdlink()
4773:
4774: Inputs: $text $uname $udom $symb $target
4775:
4776: Returns: A link to grades.pm such as to see the PGRD view of a student
4777:
4778: =cut
4779:
4780: ###############################################
4781: sub pgrdlink {
4782: my $link=&submlink(@_);
4783: $link=~s/(&command=submission)/$1&showgrading=yes/;
4784: return $link;
4785: }
4786: ##############################################
4787:
4788: =pod
4789:
4790: =item * &pprmlink()
4791:
4792: Inputs: $text $uname $udom $symb $target
4793:
4794: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4795: student and a specific resource
1.242 albertel 4796:
4797: =cut
4798:
4799: ###############################################
4800: sub pprmlink {
4801: my ($text,$uname,$udom,$symb,$target)=@_;
4802: if (!($uname && $udom)) {
4803: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4804: &Apache::lonnet::whichuser($symb);
1.242 albertel 4805: if (!$symb) { $symb=$cursymb; }
4806: }
1.254 matthew 4807: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4808: $symb=&escape($symb);
1.242 albertel 4809: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4810: return '<a href="/adm/parmset?command=set&'.
4811: 'symb='.$symb.'&uname='.$uname.
4812: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4813: }
4814: ##############################################
1.37 matthew 4815:
1.112 bowersj2 4816: =pod
4817:
4818: =back
4819:
4820: =cut
4821:
1.37 matthew 4822: ###############################################
1.51 www 4823:
4824:
4825: sub timehash {
1.687 raeburn 4826: my ($thistime) = @_;
4827: my $timezone = &Apache::lonlocal::gettimezone();
4828: my $dt = DateTime->from_epoch(epoch => $thistime)
4829: ->set_time_zone($timezone);
4830: my $wday = $dt->day_of_week();
4831: if ($wday == 7) { $wday = 0; }
4832: return ( 'second' => $dt->second(),
4833: 'minute' => $dt->minute(),
4834: 'hour' => $dt->hour(),
4835: 'day' => $dt->day_of_month(),
4836: 'month' => $dt->month(),
4837: 'year' => $dt->year(),
4838: 'weekday' => $wday,
4839: 'dayyear' => $dt->day_of_year(),
4840: 'dlsav' => $dt->is_dst() );
1.51 www 4841: }
4842:
1.370 www 4843: sub utc_string {
4844: my ($date)=@_;
1.371 www 4845: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4846: }
4847:
1.51 www 4848: sub maketime {
4849: my %th=@_;
1.687 raeburn 4850: my ($epoch_time,$timezone,$dt);
4851: $timezone = &Apache::lonlocal::gettimezone();
4852: eval {
4853: $dt = DateTime->new( year => $th{'year'},
4854: month => $th{'month'},
4855: day => $th{'day'},
4856: hour => $th{'hour'},
4857: minute => $th{'minute'},
4858: second => $th{'second'},
4859: time_zone => $timezone,
4860: );
4861: };
4862: if (!$@) {
4863: $epoch_time = $dt->epoch;
4864: if ($epoch_time) {
4865: return $epoch_time;
4866: }
4867: }
1.51 www 4868: return POSIX::mktime(
4869: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4870: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4871: }
4872:
4873: #########################################
1.51 www 4874:
4875: sub findallcourses {
1.482 raeburn 4876: my ($roles,$uname,$udom) = @_;
1.355 albertel 4877: my %roles;
4878: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4879: my %courses;
1.51 www 4880: my $now=time;
1.482 raeburn 4881: if (!defined($uname)) {
4882: $uname = $env{'user.name'};
4883: }
4884: if (!defined($udom)) {
4885: $udom = $env{'user.domain'};
4886: }
4887: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4888: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4889: if (!%roles) {
4890: %roles = (
4891: cc => 1,
1.907 raeburn 4892: co => 1,
1.482 raeburn 4893: in => 1,
4894: ep => 1,
4895: ta => 1,
4896: cr => 1,
4897: st => 1,
4898: );
4899: }
4900: foreach my $entry (keys(%roleshash)) {
4901: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4902: if ($trole =~ /^cr/) {
4903: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4904: } else {
4905: next if (!exists($roles{$trole}));
4906: }
4907: if ($tend) {
4908: next if ($tend < $now);
4909: }
4910: if ($tstart) {
4911: next if ($tstart > $now);
4912: }
1.1058 raeburn 4913: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4914: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4915: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4916: if ($secpart eq '') {
4917: ($cnum,$role) = split(/_/,$cnumpart);
4918: $sec = 'none';
1.1058 raeburn 4919: $value .= $cnum.'/';
1.482 raeburn 4920: } else {
4921: $cnum = $cnumpart;
4922: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4923: $value .= $cnum.'/'.$sec;
4924: }
4925: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4926: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4927: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4928: }
4929: } else {
4930: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4931: }
1.482 raeburn 4932: }
4933: } else {
4934: foreach my $key (keys(%env)) {
1.483 albertel 4935: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4936: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4937: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4938: next if ($role eq 'ca' || $role eq 'aa');
4939: next if (%roles && !exists($roles{$role}));
4940: my ($starttime,$endtime)=split(/\./,$env{$key});
4941: my $active=1;
4942: if ($starttime) {
4943: if ($now<$starttime) { $active=0; }
4944: }
4945: if ($endtime) {
4946: if ($now>$endtime) { $active=0; }
4947: }
4948: if ($active) {
1.1058 raeburn 4949: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4950: if ($sec eq '') {
4951: $sec = 'none';
1.1058 raeburn 4952: } else {
4953: $value .= $sec;
4954: }
4955: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4956: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4957: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4958: }
4959: } else {
4960: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4961: }
1.474 raeburn 4962: }
4963: }
1.51 www 4964: }
4965: }
1.474 raeburn 4966: return %courses;
1.51 www 4967: }
1.37 matthew 4968:
1.54 www 4969: ###############################################
1.474 raeburn 4970:
4971: sub blockcheck {
1.1189 raeburn 4972: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4973:
1.1189 raeburn 4974: if (defined($udom) && defined($uname)) {
4975: # If uname and udom are for a course, check for blocks in the course.
4976: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4977: my ($startblock,$endblock,$triggerblock) =
4978: &get_blocks($setters,$activity,$udom,$uname,$url);
4979: return ($startblock,$endblock,$triggerblock);
4980: }
4981: } else {
1.490 raeburn 4982: $udom = $env{'user.domain'};
4983: $uname = $env{'user.name'};
4984: }
4985:
1.502 raeburn 4986: my $startblock = 0;
4987: my $endblock = 0;
1.1062 raeburn 4988: my $triggerblock = '';
1.482 raeburn 4989: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4990:
1.490 raeburn 4991: # If uname is for a user, and activity is course-specific, i.e.,
4992: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4993:
1.490 raeburn 4994: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 4995: $activity eq 'groups' || $activity eq 'printout' ||
4996: $activity eq 'reinit' || $activity eq 'alert') &&
1.1189 raeburn 4997: ($env{'request.course.id'})) {
1.490 raeburn 4998: foreach my $key (keys(%live_courses)) {
4999: if ($key ne $env{'request.course.id'}) {
5000: delete($live_courses{$key});
5001: }
5002: }
5003: }
5004:
5005: my $otheruser = 0;
5006: my %own_courses;
5007: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5008: # Resource belongs to user other than current user.
5009: $otheruser = 1;
5010: # Gather courses for current user
5011: %own_courses =
5012: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5013: }
5014:
5015: # Gather active course roles - course coordinator, instructor,
5016: # exam proctor, ta, student, or custom role.
1.474 raeburn 5017:
5018: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5019: my ($cdom,$cnum);
5020: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5021: $cdom = $env{'course.'.$course.'.domain'};
5022: $cnum = $env{'course.'.$course.'.num'};
5023: } else {
1.490 raeburn 5024: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5025: }
5026: my $no_ownblock = 0;
5027: my $no_userblock = 0;
1.533 raeburn 5028: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5029: # Check if current user has 'evb' priv for this
5030: if (defined($own_courses{$course})) {
5031: foreach my $sec (keys(%{$own_courses{$course}})) {
5032: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5033: if ($sec ne 'none') {
5034: $checkrole .= '/'.$sec;
5035: }
5036: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5037: $no_ownblock = 1;
5038: last;
5039: }
5040: }
5041: }
5042: # if they have 'evb' priv and are currently not playing student
5043: next if (($no_ownblock) &&
5044: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5045: }
1.474 raeburn 5046: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5047: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5048: if ($sec ne 'none') {
1.482 raeburn 5049: $checkrole .= '/'.$sec;
1.474 raeburn 5050: }
1.490 raeburn 5051: if ($otheruser) {
5052: # Resource belongs to user other than current user.
5053: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5054: my (%allroles,%userroles);
5055: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5056: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5057: my ($trole,$tdom,$tnum,$tsec);
5058: if ($entry =~ /^cr/) {
5059: ($trole,$tdom,$tnum,$tsec) =
5060: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5061: } else {
5062: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5063: }
5064: my ($spec,$area,$trest);
5065: $area = '/'.$tdom.'/'.$tnum;
5066: $trest = $tnum;
5067: if ($tsec ne '') {
5068: $area .= '/'.$tsec;
5069: $trest .= '/'.$tsec;
5070: }
5071: $spec = $trole.'.'.$area;
5072: if ($trole =~ /^cr/) {
5073: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5074: $tdom,$spec,$trest,$area);
5075: } else {
5076: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5077: $tdom,$spec,$trest,$area);
5078: }
5079: }
1.1276 raeburn 5080: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5081: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5082: if ($1) {
5083: $no_userblock = 1;
5084: last;
5085: }
1.486 raeburn 5086: }
5087: }
1.490 raeburn 5088: } else {
5089: # Resource belongs to current user
5090: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5091: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5092: $no_ownblock = 1;
5093: last;
5094: }
1.474 raeburn 5095: }
5096: }
5097: # if they have the evb priv and are currently not playing student
1.482 raeburn 5098: next if (($no_ownblock) &&
1.491 albertel 5099: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5100: next if ($no_userblock);
1.474 raeburn 5101:
1.866 kalberla 5102: # Retrieve blocking times and identity of locker for course
1.490 raeburn 5103: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5104:
1.1062 raeburn 5105: my ($start,$end,$trigger) =
5106: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 5107: if (($start != 0) &&
5108: (($startblock == 0) || ($startblock > $start))) {
5109: $startblock = $start;
1.1062 raeburn 5110: if ($trigger ne '') {
5111: $triggerblock = $trigger;
5112: }
1.502 raeburn 5113: }
5114: if (($end != 0) &&
5115: (($endblock == 0) || ($endblock < $end))) {
5116: $endblock = $end;
1.1062 raeburn 5117: if ($trigger ne '') {
5118: $triggerblock = $trigger;
5119: }
1.502 raeburn 5120: }
1.490 raeburn 5121: }
1.1062 raeburn 5122: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5123: }
5124:
5125: sub get_blocks {
1.1062 raeburn 5126: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 5127: my $startblock = 0;
5128: my $endblock = 0;
1.1062 raeburn 5129: my $triggerblock = '';
1.490 raeburn 5130: my $course = $cdom.'_'.$cnum;
5131: $setters->{$course} = {};
5132: $setters->{$course}{'staff'} = [];
5133: $setters->{$course}{'times'} = [];
1.1062 raeburn 5134: $setters->{$course}{'triggers'} = [];
5135: my (@blockers,%triggered);
5136: my $now = time;
5137: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5138: if ($activity eq 'docs') {
5139: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
5140: foreach my $block (@blockers) {
5141: if ($block =~ /^firstaccess____(.+)$/) {
5142: my $item = $1;
5143: my $type = 'map';
5144: my $timersymb = $item;
5145: if ($item eq 'course') {
5146: $type = 'course';
5147: } elsif ($item =~ /___\d+___/) {
5148: $type = 'resource';
5149: } else {
5150: $timersymb = &Apache::lonnet::symbread($item);
5151: }
5152: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5153: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5154: $triggered{$block} = {
5155: start => $start,
5156: end => $end,
5157: type => $type,
5158: };
5159: }
5160: }
5161: } else {
5162: foreach my $block (keys(%commblocks)) {
5163: if ($block =~ m/^(\d+)____(\d+)$/) {
5164: my ($start,$end) = ($1,$2);
5165: if ($start <= time && $end >= time) {
5166: if (ref($commblocks{$block}) eq 'HASH') {
5167: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5168: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5169: unless(grep(/^\Q$block\E$/,@blockers)) {
5170: push(@blockers,$block);
5171: }
5172: }
5173: }
5174: }
5175: }
5176: } elsif ($block =~ /^firstaccess____(.+)$/) {
5177: my $item = $1;
5178: my $timersymb = $item;
5179: my $type = 'map';
5180: if ($item eq 'course') {
5181: $type = 'course';
5182: } elsif ($item =~ /___\d+___/) {
5183: $type = 'resource';
5184: } else {
5185: $timersymb = &Apache::lonnet::symbread($item);
5186: }
5187: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5188: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5189: if ($start && $end) {
5190: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5191: if (ref($commblocks{$block}) eq 'HASH') {
5192: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5193: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5194: unless(grep(/^\Q$block\E$/,@blockers)) {
5195: push(@blockers,$block);
5196: $triggered{$block} = {
5197: start => $start,
5198: end => $end,
5199: type => $type,
5200: };
5201: }
5202: }
5203: }
1.1062 raeburn 5204: }
5205: }
1.490 raeburn 5206: }
1.1062 raeburn 5207: }
5208: }
5209: }
5210: foreach my $blocker (@blockers) {
5211: my ($staff_name,$staff_dom,$title,$blocks) =
5212: &parse_block_record($commblocks{$blocker});
5213: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5214: my ($start,$end,$triggertype);
5215: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5216: ($start,$end) = ($1,$2);
5217: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5218: $start = $triggered{$blocker}{'start'};
5219: $end = $triggered{$blocker}{'end'};
5220: $triggertype = $triggered{$blocker}{'type'};
5221: }
5222: if ($start) {
5223: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5224: if ($triggertype) {
5225: push(@{$$setters{$course}{'triggers'}},$triggertype);
5226: } else {
5227: push(@{$$setters{$course}{'triggers'}},0);
5228: }
5229: if ( ($startblock == 0) || ($startblock > $start) ) {
5230: $startblock = $start;
5231: if ($triggertype) {
5232: $triggerblock = $blocker;
1.474 raeburn 5233: }
5234: }
1.1062 raeburn 5235: if ( ($endblock == 0) || ($endblock < $end) ) {
5236: $endblock = $end;
5237: if ($triggertype) {
5238: $triggerblock = $blocker;
5239: }
5240: }
1.474 raeburn 5241: }
5242: }
1.1062 raeburn 5243: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5244: }
5245:
5246: sub parse_block_record {
5247: my ($record) = @_;
5248: my ($setuname,$setudom,$title,$blocks);
5249: if (ref($record) eq 'HASH') {
5250: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5251: $title = &unescape($record->{'event'});
5252: $blocks = $record->{'blocks'};
5253: } else {
5254: my @data = split(/:/,$record,3);
5255: if (scalar(@data) eq 2) {
5256: $title = $data[1];
5257: ($setuname,$setudom) = split(/@/,$data[0]);
5258: } else {
5259: ($setuname,$setudom,$title) = @data;
5260: }
5261: $blocks = { 'com' => 'on' };
5262: }
5263: return ($setuname,$setudom,$title,$blocks);
5264: }
5265:
1.854 kalberla 5266: sub blocking_status {
1.1189 raeburn 5267: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 5268: my %setters;
1.890 droeschl 5269:
1.1061 raeburn 5270: # check for active blocking
1.1062 raeburn 5271: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 5272: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 5273: my $blocked = 0;
5274: if ($startblock && $endblock) {
5275: $blocked = 1;
5276: }
1.890 droeschl 5277:
1.1061 raeburn 5278: # caller just wants to know whether a block is active
5279: if (!wantarray) { return $blocked; }
5280:
5281: # build a link to a popup window containing the details
5282: my $querystring = "?activity=$activity";
5283: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 raeburn 5284: if (($activity eq 'port') || ($activity eq 'passwd')) {
5285: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5286: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5287: } elsif ($activity eq 'docs') {
5288: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
5289: }
1.1061 raeburn 5290:
5291: my $output .= <<'END_MYBLOCK';
5292: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5293: var options = "width=" + w + ",height=" + h + ",";
5294: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5295: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5296: var newWin = window.open(url, wdwName, options);
5297: newWin.focus();
5298: }
1.890 droeschl 5299: END_MYBLOCK
1.854 kalberla 5300:
1.1061 raeburn 5301: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5302:
1.1061 raeburn 5303: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5304: my $text = &mt('Communication Blocked');
1.1217 raeburn 5305: my $class = 'LC_comblock';
1.1062 raeburn 5306: if ($activity eq 'docs') {
5307: $text = &mt('Content Access Blocked');
1.1217 raeburn 5308: $class = '';
1.1063 raeburn 5309: } elsif ($activity eq 'printout') {
5310: $text = &mt('Printing Blocked');
1.1232 raeburn 5311: } elsif ($activity eq 'passwd') {
5312: $text = &mt('Password Changing Blocked');
1.1282 raeburn 5313: } elsif ($activity eq 'alert') {
5314: $text = &mt('Checking Critical Messages Blocked');
5315: } elsif ($activity eq 'reinit') {
5316: $text = &mt('Checking Course Update Blocked');
1.1062 raeburn 5317: }
1.1061 raeburn 5318: $output .= <<"END_BLOCK";
1.1217 raeburn 5319: <div class='$class'>
1.869 kalberla 5320: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5321: title='$text'>
5322: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5323: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5324: title='$text'>$text</a>
1.867 kalberla 5325: </div>
5326:
5327: END_BLOCK
1.474 raeburn 5328:
1.1061 raeburn 5329: return ($blocked, $output);
1.854 kalberla 5330: }
1.490 raeburn 5331:
1.60 matthew 5332: ###############################################
5333:
1.682 raeburn 5334: sub check_ip_acc {
1.1201 raeburn 5335: my ($acc,$clientip)=@_;
1.682 raeburn 5336: &Apache::lonxml::debug("acc is $acc");
5337: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5338: return 1;
5339: }
1.1219 raeburn 5340: my $allowed;
1.1252 raeburn 5341: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 5342:
5343: my $name;
1.1219 raeburn 5344: my %access = (
5345: allowfrom => 1,
5346: denyfrom => 0,
5347: );
5348: my @allows;
5349: my @denies;
5350: foreach my $item (split(',',$acc)) {
5351: $item =~ s/^\s*//;
5352: $item =~ s/\s*$//;
5353: my $pattern;
5354: if ($item =~ /^\!(.+)$/) {
5355: push(@denies,$1);
5356: } else {
5357: push(@allows,$item);
5358: }
5359: }
5360: my $numdenies = scalar(@denies);
5361: my $numallows = scalar(@allows);
5362: my $count = 0;
5363: foreach my $pattern (@denies,@allows) {
5364: $count ++;
5365: my $acctype = 'allowfrom';
5366: if ($count <= $numdenies) {
5367: $acctype = 'denyfrom';
5368: }
1.682 raeburn 5369: if ($pattern =~ /\*$/) {
5370: #35.8.*
5371: $pattern=~s/\*//;
1.1219 raeburn 5372: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5373: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5374: #35.8.3.[34-56]
5375: my $low=$2;
5376: my $high=$3;
5377: $pattern=$1;
5378: if ($ip =~ /^\Q$pattern\E/) {
5379: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5380: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5381: }
5382: } elsif ($pattern =~ /^\*/) {
5383: #*.msu.edu
5384: $pattern=~s/\*//;
5385: if (!defined($name)) {
5386: use Socket;
5387: my $netaddr=inet_aton($ip);
5388: ($name)=gethostbyaddr($netaddr,AF_INET);
5389: }
1.1219 raeburn 5390: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5391: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5392: #127.0.0.1
1.1219 raeburn 5393: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5394: } else {
5395: #some.name.com
5396: if (!defined($name)) {
5397: use Socket;
5398: my $netaddr=inet_aton($ip);
5399: ($name)=gethostbyaddr($netaddr,AF_INET);
5400: }
1.1219 raeburn 5401: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5402: }
5403: if ($allowed =~ /^(0|1)$/) { last; }
5404: }
5405: if ($allowed eq '') {
5406: if ($numdenies && !$numallows) {
5407: $allowed = 1;
5408: } else {
5409: $allowed = 0;
1.682 raeburn 5410: }
5411: }
5412: return $allowed;
5413: }
5414:
5415: ###############################################
5416:
1.60 matthew 5417: =pod
5418:
1.112 bowersj2 5419: =head1 Domain Template Functions
5420:
5421: =over 4
5422:
5423: =item * &determinedomain()
1.60 matthew 5424:
5425: Inputs: $domain (usually will be undef)
5426:
1.63 www 5427: Returns: Determines which domain should be used for designs
1.60 matthew 5428:
5429: =cut
1.54 www 5430:
1.60 matthew 5431: ###############################################
1.63 www 5432: sub determinedomain {
5433: my $domain=shift;
1.531 albertel 5434: if (! $domain) {
1.60 matthew 5435: # Determine domain if we have not been given one
1.893 raeburn 5436: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5437: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5438: if ($env{'request.role.domain'}) {
5439: $domain=$env{'request.role.domain'};
1.60 matthew 5440: }
5441: }
1.63 www 5442: return $domain;
5443: }
5444: ###############################################
1.517 raeburn 5445:
1.518 albertel 5446: sub devalidate_domconfig_cache {
5447: my ($udom)=@_;
5448: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5449: }
5450:
5451: # ---------------------- Get domain configuration for a domain
5452: sub get_domainconf {
5453: my ($udom) = @_;
5454: my $cachetime=1800;
5455: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5456: if (defined($cached)) { return %{$result}; }
5457:
5458: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5459: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5460: my (%designhash,%legacy);
1.518 albertel 5461: if (keys(%domconfig) > 0) {
5462: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5463: if (keys(%{$domconfig{'login'}})) {
5464: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5465: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5466: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5467: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5468: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5469: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5470: if ($key eq 'loginvia') {
5471: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5472: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5473: $designhash{$udom.'.login.loginvia'} = $server;
5474: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5475:
5476: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5477: } else {
5478: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5479: }
1.948 raeburn 5480: }
1.1208 raeburn 5481: } elsif ($key eq 'headtag') {
5482: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5483: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5484: }
1.946 raeburn 5485: }
1.1208 raeburn 5486: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5487: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5488: }
1.946 raeburn 5489: }
5490: }
5491: }
5492: } else {
5493: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5494: $designhash{$udom.'.login.'.$key.'_'.$img} =
5495: $domconfig{'login'}{$key}{$img};
5496: }
1.699 raeburn 5497: }
5498: } else {
5499: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5500: }
1.632 raeburn 5501: }
5502: } else {
5503: $legacy{'login'} = 1;
1.518 albertel 5504: }
1.632 raeburn 5505: } else {
5506: $legacy{'login'} = 1;
1.518 albertel 5507: }
5508: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5509: if (keys(%{$domconfig{'rolecolors'}})) {
5510: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5511: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5512: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5513: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5514: }
1.518 albertel 5515: }
5516: }
1.632 raeburn 5517: } else {
5518: $legacy{'rolecolors'} = 1;
1.518 albertel 5519: }
1.632 raeburn 5520: } else {
5521: $legacy{'rolecolors'} = 1;
1.518 albertel 5522: }
1.948 raeburn 5523: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5524: if ($domconfig{'autoenroll'}{'co-owners'}) {
5525: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5526: }
5527: }
1.632 raeburn 5528: if (keys(%legacy) > 0) {
5529: my %legacyhash = &get_legacy_domconf($udom);
5530: foreach my $item (keys(%legacyhash)) {
5531: if ($item =~ /^\Q$udom\E\.login/) {
5532: if ($legacy{'login'}) {
5533: $designhash{$item} = $legacyhash{$item};
5534: }
5535: } else {
5536: if ($legacy{'rolecolors'}) {
5537: $designhash{$item} = $legacyhash{$item};
5538: }
1.518 albertel 5539: }
5540: }
5541: }
1.632 raeburn 5542: } else {
5543: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5544: }
5545: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5546: $cachetime);
5547: return %designhash;
5548: }
5549:
1.632 raeburn 5550: sub get_legacy_domconf {
5551: my ($udom) = @_;
5552: my %legacyhash;
5553: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5554: my $designfile = $designdir.'/'.$udom.'.tab';
5555: if (-e $designfile) {
5556: if ( open (my $fh,"<$designfile") ) {
5557: while (my $line = <$fh>) {
5558: next if ($line =~ /^\#/);
5559: chomp($line);
5560: my ($key,$val)=(split(/\=/,$line));
5561: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5562: }
5563: close($fh);
5564: }
5565: }
1.1026 raeburn 5566: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5567: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5568: }
5569: return %legacyhash;
5570: }
5571:
1.63 www 5572: =pod
5573:
1.112 bowersj2 5574: =item * &domainlogo()
1.63 www 5575:
5576: Inputs: $domain (usually will be undef)
5577:
5578: Returns: A link to a domain logo, if the domain logo exists.
5579: If the domain logo does not exist, a description of the domain.
5580:
5581: =cut
1.112 bowersj2 5582:
1.63 www 5583: ###############################################
5584: sub domainlogo {
1.517 raeburn 5585: my $domain = &determinedomain(shift);
1.518 albertel 5586: my %designhash = &get_domainconf($domain);
1.517 raeburn 5587: # See if there is a logo
5588: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5589: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5590: if ($imgsrc =~ m{^/(adm|res)/}) {
5591: if ($imgsrc =~ m{^/res/}) {
5592: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5593: &Apache::lonnet::repcopy($local_name);
5594: }
5595: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5596: }
5597: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5598: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5599: return &Apache::lonnet::domain($domain,'description');
1.59 www 5600: } else {
1.60 matthew 5601: return '';
1.59 www 5602: }
5603: }
1.63 www 5604: ##############################################
5605:
5606: =pod
5607:
1.112 bowersj2 5608: =item * &designparm()
1.63 www 5609:
5610: Inputs: $which parameter; $domain (usually will be undef)
5611:
5612: Returns: value of designparamter $which
5613:
5614: =cut
1.112 bowersj2 5615:
1.397 albertel 5616:
1.400 albertel 5617: ##############################################
1.397 albertel 5618: sub designparm {
5619: my ($which,$domain)=@_;
5620: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5621: return $env{'environment.color.'.$which};
1.96 www 5622: }
1.63 www 5623: $domain=&determinedomain($domain);
1.1016 raeburn 5624: my %domdesign;
5625: unless ($domain eq 'public') {
5626: %domdesign = &get_domainconf($domain);
5627: }
1.520 raeburn 5628: my $output;
1.517 raeburn 5629: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5630: $output = $domdesign{$domain.'.'.$which};
1.63 www 5631: } else {
1.520 raeburn 5632: $output = $defaultdesign{$which};
5633: }
5634: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5635: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5636: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5637: if ($output =~ m{^/res/}) {
5638: my $local_name = &Apache::lonnet::filelocation('',$output);
5639: &Apache::lonnet::repcopy($local_name);
5640: }
1.520 raeburn 5641: $output = &lonhttpdurl($output);
5642: }
1.63 www 5643: }
1.520 raeburn 5644: return $output;
1.63 www 5645: }
1.59 www 5646:
1.822 bisitz 5647: ##############################################
5648: =pod
5649:
1.832 bisitz 5650: =item * &authorspace()
5651:
1.1028 raeburn 5652: Inputs: $url (usually will be undef).
1.832 bisitz 5653:
1.1132 raeburn 5654: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5655: directory being viewed (or for which action is being taken).
5656: If $url is provided, and begins /priv/<domain>/<uname>
5657: the path will be that portion of the $context argument.
5658: Otherwise the path will be for the author space of the current
5659: user when the current role is author, or for that of the
5660: co-author/assistant co-author space when the current role
5661: is co-author or assistant co-author.
1.832 bisitz 5662:
5663: =cut
5664:
5665: sub authorspace {
1.1028 raeburn 5666: my ($url) = @_;
5667: if ($url ne '') {
5668: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5669: return $1;
5670: }
5671: }
1.832 bisitz 5672: my $caname = '';
1.1024 www 5673: my $cadom = '';
1.1028 raeburn 5674: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5675: ($cadom,$caname) =
1.832 bisitz 5676: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5677: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5678: $caname = $env{'user.name'};
1.1024 www 5679: $cadom = $env{'user.domain'};
1.832 bisitz 5680: }
1.1028 raeburn 5681: if (($caname ne '') && ($cadom ne '')) {
5682: return "/priv/$cadom/$caname/";
5683: }
5684: return;
1.832 bisitz 5685: }
5686:
5687: ##############################################
5688: =pod
5689:
1.822 bisitz 5690: =item * &head_subbox()
5691:
5692: Inputs: $content (contains HTML code with page functions, etc.)
5693:
5694: Returns: HTML div with $content
5695: To be included in page header
5696:
5697: =cut
5698:
5699: sub head_subbox {
5700: my ($content)=@_;
5701: my $output =
1.993 raeburn 5702: '<div class="LC_head_subbox">'
1.822 bisitz 5703: .$content
5704: .'</div>'
5705: }
5706:
5707: ##############################################
5708: =pod
5709:
5710: =item * &CSTR_pageheader()
5711:
1.1026 raeburn 5712: Input: (optional) filename from which breadcrumb trail is built.
5713: In most cases no input as needed, as $env{'request.filename'}
5714: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5715:
5716: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5717: To be included on Authoring Space pages
1.822 bisitz 5718:
5719: =cut
5720:
5721: sub CSTR_pageheader {
1.1026 raeburn 5722: my ($trailfile) = @_;
5723: if ($trailfile eq '') {
5724: $trailfile = $env{'request.filename'};
5725: }
5726:
5727: # this is for resources; directories have customtitle, and crumbs
5728: # and select recent are created in lonpubdir.pm
5729:
5730: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5731: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5732: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5733: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5734: $formaction =~ s{/+}{/}g;
1.822 bisitz 5735:
5736: my $parentpath = '';
5737: my $lastitem = '';
5738: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5739: $parentpath = $1;
5740: $lastitem = $2;
5741: } else {
5742: $lastitem = $thisdisfn;
5743: }
1.921 bisitz 5744:
1.1246 raeburn 5745: my ($crsauthor,$title);
5746: if (($env{'request.course.id'}) &&
5747: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 5748: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 5749: $crsauthor = 1;
5750: $title = &mt('Course Authoring Space');
5751: } else {
5752: $title = &mt('Authoring Space');
5753: }
5754:
1.921 bisitz 5755: my $output =
1.822 bisitz 5756: '<div>'
5757: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 5758: .'<b>'.$title.'</b> '
1.822 bisitz 5759: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5760: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5761: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5762:
5763: if ($lastitem) {
5764: $output .=
5765: '<span class="LC_filename">'
5766: .$lastitem
5767: .'</span>';
5768: }
1.1245 raeburn 5769:
1.1246 raeburn 5770: if ($crsauthor) {
5771: $output .= '</form>'.&Apache::lonmenu::constspaceform();
5772: } else {
5773: $output .=
5774: '<br />'
5775: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5776: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5777: .'</form>'
5778: .&Apache::lonmenu::constspaceform();
5779: }
5780: $output .= '</div>';
1.921 bisitz 5781:
5782: return $output;
1.822 bisitz 5783: }
5784:
1.60 matthew 5785: ###############################################
5786: ###############################################
5787:
5788: =pod
5789:
1.112 bowersj2 5790: =back
5791:
1.549 albertel 5792: =head1 HTML Helpers
1.112 bowersj2 5793:
5794: =over 4
5795:
5796: =item * &bodytag()
1.60 matthew 5797:
5798: Returns a uniform header for LON-CAPA web pages.
5799:
5800: Inputs:
5801:
1.112 bowersj2 5802: =over 4
5803:
5804: =item * $title, A title to be displayed on the page.
5805:
5806: =item * $function, the current role (can be undef).
5807:
5808: =item * $addentries, extra parameters for the <body> tag.
5809:
5810: =item * $bodyonly, if defined, only return the <body> tag.
5811:
5812: =item * $domain, if defined, force a given domain.
5813:
5814: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5815: text interface only)
1.60 matthew 5816:
1.814 bisitz 5817: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5818: navigational links
1.317 albertel 5819:
1.338 albertel 5820: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5821:
1.460 albertel 5822: =item * $args, optional argument valid values are
5823: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 5824: use_absolute -> for external resource or syllabus, this will
5825: contain https://<hostname> if server uses
5826: https (as per hosts.tab), but request is for http
5827: hostname -> hostname, from $r->hostname().
1.460 albertel 5828:
1.1096 raeburn 5829: =item * $advtoolsref, optional argument, ref to an array containing
5830: inlineremote items to be added in "Functions" menu below
5831: breadcrumbs.
5832:
1.112 bowersj2 5833: =back
5834:
1.60 matthew 5835: Returns: A uniform header for LON-CAPA web pages.
5836: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5837: If $bodyonly is undef or zero, an html string containing a <body> tag and
5838: other decorations will be returned.
5839:
5840: =cut
5841:
1.54 www 5842: sub bodytag {
1.831 bisitz 5843: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5844: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5845:
1.954 raeburn 5846: my $public;
5847: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5848: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5849: $public = 1;
5850: }
1.460 albertel 5851: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5852: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 5853: my $hostname = $args->{'hostname'};
1.339 albertel 5854:
1.183 matthew 5855: $function = &get_users_function() if (!$function);
1.339 albertel 5856: my $img = &designparm($function.'.img',$domain);
5857: my $font = &designparm($function.'.font',$domain);
5858: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5859:
1.803 bisitz 5860: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5861: 'bgcolor' => $pgbg,
1.339 albertel 5862: 'text' => $font,
5863: 'alink' => &designparm($function.'.alink',$domain),
5864: 'vlink' => &designparm($function.'.vlink',$domain),
5865: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5866: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5867:
1.63 www 5868: # role and realm
1.1178 raeburn 5869: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5870: if ($realm) {
5871: $realm = '/'.$realm;
5872: }
1.378 raeburn 5873: if ($role eq 'ca') {
1.479 albertel 5874: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5875: $realm = &plainname($rname,$rdom);
1.378 raeburn 5876: }
1.55 www 5877: # realm
1.258 albertel 5878: if ($env{'request.course.id'}) {
1.378 raeburn 5879: if ($env{'request.role'} !~ /^cr/) {
5880: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 5881: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 5882: if ($env{'request.role.desc'}) {
5883: $role = $env{'request.role.desc'};
5884: } else {
5885: $role = &mt('Helpdesk[_1]',' '.$2);
5886: }
1.1257 raeburn 5887: } else {
5888: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5889: }
1.898 raeburn 5890: if ($env{'request.course.sec'}) {
5891: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5892: }
1.359 albertel 5893: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5894: } else {
5895: $role = &Apache::lonnet::plaintext($role);
1.54 www 5896: }
1.433 albertel 5897:
1.359 albertel 5898: if (!$realm) { $realm=' '; }
1.330 albertel 5899:
1.438 albertel 5900: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5901:
1.101 www 5902: # construct main body tag
1.359 albertel 5903: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 5904: &Apache::lontexconvert::init_math_support();
1.252 albertel 5905:
1.1131 raeburn 5906: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5907:
1.1130 raeburn 5908: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5909: return $bodytag;
1.1130 raeburn 5910: }
1.359 albertel 5911:
1.954 raeburn 5912: if ($public) {
1.433 albertel 5913: undef($role);
5914: }
1.359 albertel 5915:
1.762 bisitz 5916: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5917: #
5918: # Extra info if you are the DC
5919: my $dc_info = '';
5920: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5921: $env{'course.'.$env{'request.course.id'}.
5922: '.domain'}.'/'})) {
5923: my $cid = $env{'request.course.id'};
1.917 raeburn 5924: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5925: $dc_info =~ s/\s+$//;
1.359 albertel 5926: }
5927:
1.1237 raeburn 5928: my $crstype;
5929: if ($env{'request.course.id'}) {
5930: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
5931: } elsif ($args->{'crstype'}) {
5932: $crstype = $args->{'crstype'};
5933: }
5934: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
5935: undef($role);
5936: } else {
1.1242 raeburn 5937: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 5938: }
1.853 droeschl 5939:
1.903 droeschl 5940: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5941:
5942: # if ($env{'request.state'} eq 'construct') {
5943: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5944: # }
5945:
1.1130 raeburn 5946: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 5947: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5948:
1.1237 raeburn 5949: my ($left,$right) = Apache::lonmenu::primary_menu($crstype);
1.359 albertel 5950:
1.916 droeschl 5951: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5952: if ($dc_info) {
5953: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5954: }
1.1130 raeburn 5955: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5956: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5957: return $bodytag;
5958: }
1.894 droeschl 5959:
1.927 raeburn 5960: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5961: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5962: }
1.916 droeschl 5963:
1.1130 raeburn 5964: $bodytag .= $right;
1.852 droeschl 5965:
1.917 raeburn 5966: if ($dc_info) {
5967: $dc_info = &dc_courseid_toggle($dc_info);
5968: }
5969: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5970:
1.1169 raeburn 5971: #if directed to not display the secondary menu, don't.
1.1168 raeburn 5972: if ($args->{'no_secondary_menu'}) {
5973: return $bodytag;
5974: }
1.1169 raeburn 5975: #don't show menus for public users
1.954 raeburn 5976: if (!$public){
1.1154 raeburn 5977: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5978: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5979: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5980: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5981: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1274 raeburn 5982: $args->{'bread_crumbs'},'','',$hostname);
1.1096 raeburn 5983: } elsif ($forcereg) {
5984: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 5985: $args->{'group'},
1.1274 raeburn 5986: $args->{'hide_buttons'},
5987: $hostname);
1.1096 raeburn 5988: } else {
5989: $bodytag .=
5990: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5991: $forcereg,$args->{'group'},
5992: $args->{'bread_crumbs'},
1.1274 raeburn 5993: $advtoolsref,'',$hostname);
1.920 raeburn 5994: }
1.903 droeschl 5995: }else{
5996: # this is to seperate menu from content when there's no secondary
5997: # menu. Especially needed for public accessible ressources.
5998: $bodytag .= '<hr style="clear:both" />';
5999: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6000: }
1.903 droeschl 6001:
1.235 raeburn 6002: return $bodytag;
1.182 matthew 6003: }
6004:
1.917 raeburn 6005: sub dc_courseid_toggle {
6006: my ($dc_info) = @_;
1.980 raeburn 6007: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6008: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6009: &mt('(More ...)').'</a></span>'.
6010: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6011: }
6012:
1.330 albertel 6013: sub make_attr_string {
6014: my ($register,$attr_ref) = @_;
6015:
6016: if ($attr_ref && !ref($attr_ref)) {
6017: die("addentries Must be a hash ref ".
6018: join(':',caller(1))." ".
6019: join(':',caller(0))." ");
6020: }
6021:
6022: if ($register) {
1.339 albertel 6023: my ($on_load,$on_unload);
6024: foreach my $key (keys(%{$attr_ref})) {
6025: if (lc($key) eq 'onload') {
6026: $on_load.=$attr_ref->{$key}.';';
6027: delete($attr_ref->{$key});
6028:
6029: } elsif (lc($key) eq 'onunload') {
6030: $on_unload.=$attr_ref->{$key}.';';
6031: delete($attr_ref->{$key});
6032: }
6033: }
1.953 droeschl 6034: $attr_ref->{'onload'} = $on_load;
6035: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6036: }
1.339 albertel 6037:
1.330 albertel 6038: my $attr_string;
1.1159 raeburn 6039: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6040: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6041: }
6042: return $attr_string;
6043: }
6044:
6045:
1.182 matthew 6046: ###############################################
1.251 albertel 6047: ###############################################
6048:
6049: =pod
6050:
6051: =item * &endbodytag()
6052:
6053: Returns a uniform footer for LON-CAPA web pages.
6054:
1.635 raeburn 6055: Inputs: 1 - optional reference to an args hash
6056: If in the hash, key for noredirectlink has a value which evaluates to true,
6057: a 'Continue' link is not displayed if the page contains an
6058: internal redirect in the <head></head> section,
6059: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6060:
6061: =cut
6062:
6063: sub endbodytag {
1.635 raeburn 6064: my ($args) = @_;
1.1080 raeburn 6065: my $endbodytag;
6066: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6067: $endbodytag='</body>';
6068: }
1.315 albertel 6069: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6070: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6071: $endbodytag=
6072: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6073: &mt('Continue').'</a>'.
6074: $endbodytag;
6075: }
1.315 albertel 6076: }
1.251 albertel 6077: return $endbodytag;
6078: }
6079:
1.352 albertel 6080: =pod
6081:
6082: =item * &standard_css()
6083:
6084: Returns a style sheet
6085:
6086: Inputs: (all optional)
6087: domain -> force to color decorate a page for a specific
6088: domain
6089: function -> force usage of a specific rolish color scheme
6090: bgcolor -> override the default page bgcolor
6091:
6092: =cut
6093:
1.343 albertel 6094: sub standard_css {
1.345 albertel 6095: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6096: $function = &get_users_function() if (!$function);
6097: my $img = &designparm($function.'.img', $domain);
6098: my $tabbg = &designparm($function.'.tabbg', $domain);
6099: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6100: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6101: #second colour for later usage
1.345 albertel 6102: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6103: my $pgbg_or_bgcolor =
6104: $bgcolor ||
1.352 albertel 6105: &designparm($function.'.pgbg', $domain);
1.382 albertel 6106: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6107: my $alink = &designparm($function.'.alink', $domain);
6108: my $vlink = &designparm($function.'.vlink', $domain);
6109: my $link = &designparm($function.'.link', $domain);
6110:
1.602 albertel 6111: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6112: my $mono = 'monospace';
1.850 bisitz 6113: my $data_table_head = $sidebg;
6114: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6115: my $data_table_dark = '#E0E0E0';
1.470 banghart 6116: my $data_table_darker = '#CCCCCC';
1.349 albertel 6117: my $data_table_highlight = '#FFFF00';
1.352 albertel 6118: my $mail_new = '#FFBB77';
6119: my $mail_new_hover = '#DD9955';
6120: my $mail_read = '#BBBB77';
6121: my $mail_read_hover = '#999944';
6122: my $mail_replied = '#AAAA88';
6123: my $mail_replied_hover = '#888855';
6124: my $mail_other = '#99BBBB';
6125: my $mail_other_hover = '#669999';
1.391 albertel 6126: my $table_header = '#DDDDDD';
1.489 raeburn 6127: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6128: my $lg_border_color = '#C8C8C8';
1.952 onken 6129: my $button_hover = '#BF2317';
1.392 albertel 6130:
1.608 albertel 6131: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6132: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6133: : '0 3px 0 4px';
1.448 albertel 6134:
1.523 albertel 6135:
1.343 albertel 6136: return <<END;
1.947 droeschl 6137:
6138: /* needed for iframe to allow 100% height in FF */
6139: body, html {
6140: margin: 0;
6141: padding: 0 0.5%;
6142: height: 99%; /* to avoid scrollbars */
6143: }
6144:
1.795 www 6145: body {
1.911 bisitz 6146: font-family: $sans;
6147: line-height:130%;
6148: font-size:0.83em;
6149: color:$font;
1.795 www 6150: }
6151:
1.959 onken 6152: a:focus,
6153: a:focus img {
1.795 www 6154: color: red;
6155: }
1.698 harmsja 6156:
1.911 bisitz 6157: form, .inline {
6158: display: inline;
1.795 www 6159: }
1.721 harmsja 6160:
1.795 www 6161: .LC_right {
1.911 bisitz 6162: text-align:right;
1.795 www 6163: }
6164:
6165: .LC_middle {
1.911 bisitz 6166: vertical-align:middle;
1.795 www 6167: }
1.721 harmsja 6168:
1.1130 raeburn 6169: .LC_floatleft {
6170: float: left;
6171: }
6172:
6173: .LC_floatright {
6174: float: right;
6175: }
6176:
1.911 bisitz 6177: .LC_400Box {
6178: width:400px;
6179: }
1.721 harmsja 6180:
1.947 droeschl 6181: .LC_iframecontainer {
6182: width: 98%;
6183: margin: 0;
6184: position: fixed;
6185: top: 8.5em;
6186: bottom: 0;
6187: }
6188:
6189: .LC_iframecontainer iframe{
6190: border: none;
6191: width: 100%;
6192: height: 100%;
6193: }
6194:
1.778 bisitz 6195: .LC_filename {
6196: font-family: $mono;
6197: white-space:pre;
1.921 bisitz 6198: font-size: 120%;
1.778 bisitz 6199: }
6200:
6201: .LC_fileicon {
6202: border: none;
6203: height: 1.3em;
6204: vertical-align: text-bottom;
6205: margin-right: 0.3em;
6206: text-decoration:none;
6207: }
6208:
1.1008 www 6209: .LC_setting {
6210: text-decoration:underline;
6211: }
6212:
1.350 albertel 6213: .LC_error {
6214: color: red;
6215: }
1.795 www 6216:
1.1097 bisitz 6217: .LC_warning {
6218: color: darkorange;
6219: }
6220:
1.457 albertel 6221: .LC_diff_removed {
1.733 bisitz 6222: color: red;
1.394 albertel 6223: }
1.532 albertel 6224:
6225: .LC_info,
1.457 albertel 6226: .LC_success,
6227: .LC_diff_added {
1.350 albertel 6228: color: green;
6229: }
1.795 www 6230:
1.802 bisitz 6231: div.LC_confirm_box {
6232: background-color: #FAFAFA;
6233: border: 1px solid $lg_border_color;
6234: margin-right: 0;
6235: padding: 5px;
6236: }
6237:
6238: div.LC_confirm_box .LC_error img,
6239: div.LC_confirm_box .LC_success img {
6240: vertical-align: middle;
6241: }
6242:
1.1242 raeburn 6243: .LC_maxwidth {
6244: max-width: 100%;
6245: height: auto;
6246: }
6247:
1.1243 raeburn 6248: .LC_textsize_mobile {
6249: \@media only screen and (max-device-width: 480px) {
6250: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6251: }
6252: }
6253:
1.440 albertel 6254: .LC_icon {
1.771 droeschl 6255: border: none;
1.790 droeschl 6256: vertical-align: middle;
1.771 droeschl 6257: }
6258:
1.543 albertel 6259: .LC_docs_spacer {
6260: width: 25px;
6261: height: 1px;
1.771 droeschl 6262: border: none;
1.543 albertel 6263: }
1.346 albertel 6264:
1.532 albertel 6265: .LC_internal_info {
1.735 bisitz 6266: color: #999999;
1.532 albertel 6267: }
6268:
1.794 www 6269: .LC_discussion {
1.1050 www 6270: background: $data_table_dark;
1.911 bisitz 6271: border: 1px solid black;
6272: margin: 2px;
1.794 www 6273: }
6274:
6275: .LC_disc_action_left {
1.1050 www 6276: background: $sidebg;
1.911 bisitz 6277: text-align: left;
1.1050 www 6278: padding: 4px;
6279: margin: 2px;
1.794 www 6280: }
6281:
6282: .LC_disc_action_right {
1.1050 www 6283: background: $sidebg;
1.911 bisitz 6284: text-align: right;
1.1050 www 6285: padding: 4px;
6286: margin: 2px;
1.794 www 6287: }
6288:
6289: .LC_disc_new_item {
1.911 bisitz 6290: background: white;
6291: border: 2px solid red;
1.1050 www 6292: margin: 4px;
6293: padding: 4px;
1.794 www 6294: }
6295:
6296: .LC_disc_old_item {
1.911 bisitz 6297: background: white;
1.1050 www 6298: margin: 4px;
6299: padding: 4px;
1.794 www 6300: }
6301:
1.458 albertel 6302: table.LC_pastsubmission {
6303: border: 1px solid black;
6304: margin: 2px;
6305: }
6306:
1.924 bisitz 6307: table#LC_menubuttons {
1.345 albertel 6308: width: 100%;
6309: background: $pgbg;
1.392 albertel 6310: border: 2px;
1.402 albertel 6311: border-collapse: separate;
1.803 bisitz 6312: padding: 0;
1.345 albertel 6313: }
1.392 albertel 6314:
1.801 tempelho 6315: table#LC_title_bar a {
6316: color: $fontmenu;
6317: }
1.836 bisitz 6318:
1.807 droeschl 6319: table#LC_title_bar {
1.819 tempelho 6320: clear: both;
1.836 bisitz 6321: display: none;
1.807 droeschl 6322: }
6323:
1.795 www 6324: table#LC_title_bar,
1.933 droeschl 6325: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6326: table#LC_title_bar.LC_with_remote {
1.359 albertel 6327: width: 100%;
1.392 albertel 6328: border-color: $pgbg;
6329: border-style: solid;
6330: border-width: $border;
1.379 albertel 6331: background: $pgbg;
1.801 tempelho 6332: color: $fontmenu;
1.392 albertel 6333: border-collapse: collapse;
1.803 bisitz 6334: padding: 0;
1.819 tempelho 6335: margin: 0;
1.359 albertel 6336: }
1.795 www 6337:
1.933 droeschl 6338: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6339: margin: 0;
6340: padding: 0;
1.933 droeschl 6341: position: relative;
6342: list-style: none;
1.913 droeschl 6343: }
1.933 droeschl 6344: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6345: display: inline;
6346: }
1.933 droeschl 6347:
6348: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6349: padding: 0;
1.933 droeschl 6350: margin: 0;
6351: float: left;
1.913 droeschl 6352: }
1.933 droeschl 6353: .LC_breadcrumb_tools_tools {
6354: padding: 0;
6355: margin: 0;
1.913 droeschl 6356: float: right;
6357: }
6358:
1.1240 raeburn 6359: .LC_placement_prog {
6360: padding-right: 20px;
6361: font-weight: bold;
6362: font-size: 90%;
6363: }
6364:
1.359 albertel 6365: table#LC_title_bar td {
6366: background: $tabbg;
6367: }
1.795 www 6368:
1.911 bisitz 6369: table#LC_menubuttons img {
1.803 bisitz 6370: border: none;
1.346 albertel 6371: }
1.795 www 6372:
1.842 droeschl 6373: .LC_breadcrumbs_component {
1.911 bisitz 6374: float: right;
6375: margin: 0 1em;
1.357 albertel 6376: }
1.842 droeschl 6377: .LC_breadcrumbs_component img {
1.911 bisitz 6378: vertical-align: middle;
1.777 tempelho 6379: }
1.795 www 6380:
1.1243 raeburn 6381: .LC_breadcrumbs_hoverable {
6382: background: $sidebg;
6383: }
6384:
1.383 albertel 6385: td.LC_table_cell_checkbox {
6386: text-align: center;
6387: }
1.795 www 6388:
6389: .LC_fontsize_small {
1.911 bisitz 6390: font-size: 70%;
1.705 tempelho 6391: }
6392:
1.844 bisitz 6393: #LC_breadcrumbs {
1.911 bisitz 6394: clear:both;
6395: background: $sidebg;
6396: border-bottom: 1px solid $lg_border_color;
6397: line-height: 2.5em;
1.933 droeschl 6398: overflow: hidden;
1.911 bisitz 6399: margin: 0;
6400: padding: 0;
1.995 raeburn 6401: text-align: left;
1.819 tempelho 6402: }
1.862 bisitz 6403:
1.1098 bisitz 6404: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6405: clear:both;
6406: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6407: border: 1px solid $sidebg;
1.1098 bisitz 6408: margin: 0 0 10px 0;
1.966 bisitz 6409: padding: 3px;
1.995 raeburn 6410: text-align: left;
1.822 bisitz 6411: }
6412:
1.795 www 6413: .LC_fontsize_medium {
1.911 bisitz 6414: font-size: 85%;
1.705 tempelho 6415: }
6416:
1.795 www 6417: .LC_fontsize_large {
1.911 bisitz 6418: font-size: 120%;
1.705 tempelho 6419: }
6420:
1.346 albertel 6421: .LC_menubuttons_inline_text {
6422: color: $font;
1.698 harmsja 6423: font-size: 90%;
1.701 harmsja 6424: padding-left:3px;
1.346 albertel 6425: }
6426:
1.934 droeschl 6427: .LC_menubuttons_inline_text img{
6428: vertical-align: middle;
6429: }
6430:
1.1051 www 6431: li.LC_menubuttons_inline_text img {
1.951 onken 6432: cursor:pointer;
1.1002 droeschl 6433: text-decoration: none;
1.951 onken 6434: }
6435:
1.526 www 6436: .LC_menubuttons_link {
6437: text-decoration: none;
6438: }
1.795 www 6439:
1.522 albertel 6440: .LC_menubuttons_category {
1.521 www 6441: color: $font;
1.526 www 6442: background: $pgbg;
1.521 www 6443: font-size: larger;
6444: font-weight: bold;
6445: }
6446:
1.346 albertel 6447: td.LC_menubuttons_text {
1.911 bisitz 6448: color: $font;
1.346 albertel 6449: }
1.706 harmsja 6450:
1.346 albertel 6451: .LC_current_location {
6452: background: $tabbg;
6453: }
1.795 www 6454:
1.938 bisitz 6455: table.LC_data_table {
1.347 albertel 6456: border: 1px solid #000000;
1.402 albertel 6457: border-collapse: separate;
1.426 albertel 6458: border-spacing: 1px;
1.610 albertel 6459: background: $pgbg;
1.347 albertel 6460: }
1.795 www 6461:
1.422 albertel 6462: .LC_data_table_dense {
6463: font-size: small;
6464: }
1.795 www 6465:
1.507 raeburn 6466: table.LC_nested_outer {
6467: border: 1px solid #000000;
1.589 raeburn 6468: border-collapse: collapse;
1.803 bisitz 6469: border-spacing: 0;
1.507 raeburn 6470: width: 100%;
6471: }
1.795 www 6472:
1.879 raeburn 6473: table.LC_innerpickbox,
1.507 raeburn 6474: table.LC_nested {
1.803 bisitz 6475: border: none;
1.589 raeburn 6476: border-collapse: collapse;
1.803 bisitz 6477: border-spacing: 0;
1.507 raeburn 6478: width: 100%;
6479: }
1.795 www 6480:
1.911 bisitz 6481: table.LC_data_table tr th,
6482: table.LC_calendar tr th,
1.879 raeburn 6483: table.LC_prior_tries tr th,
6484: table.LC_innerpickbox tr th {
1.349 albertel 6485: font-weight: bold;
6486: background-color: $data_table_head;
1.801 tempelho 6487: color:$fontmenu;
1.701 harmsja 6488: font-size:90%;
1.347 albertel 6489: }
1.795 www 6490:
1.879 raeburn 6491: table.LC_innerpickbox tr th,
6492: table.LC_innerpickbox tr td {
6493: vertical-align: top;
6494: }
6495:
1.711 raeburn 6496: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6497: background-color: #CCCCCC;
1.711 raeburn 6498: font-weight: bold;
6499: text-align: left;
6500: }
1.795 www 6501:
1.912 bisitz 6502: table.LC_data_table tr.LC_odd_row > td {
6503: background-color: $data_table_light;
6504: padding: 2px;
6505: vertical-align: top;
6506: }
6507:
1.809 bisitz 6508: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6509: background-color: $data_table_light;
1.912 bisitz 6510: vertical-align: top;
6511: }
6512:
6513: table.LC_data_table tr.LC_even_row > td {
6514: background-color: $data_table_dark;
1.425 albertel 6515: padding: 2px;
1.900 bisitz 6516: vertical-align: top;
1.347 albertel 6517: }
1.795 www 6518:
1.809 bisitz 6519: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6520: background-color: $data_table_dark;
1.900 bisitz 6521: vertical-align: top;
1.347 albertel 6522: }
1.795 www 6523:
1.425 albertel 6524: table.LC_data_table tr.LC_data_table_highlight td {
6525: background-color: $data_table_darker;
6526: }
1.795 www 6527:
1.639 raeburn 6528: table.LC_data_table tr td.LC_leftcol_header {
6529: background-color: $data_table_head;
6530: font-weight: bold;
6531: }
1.795 www 6532:
1.451 albertel 6533: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6534: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6535: font-weight: bold;
6536: font-style: italic;
6537: text-align: center;
6538: padding: 8px;
1.347 albertel 6539: }
1.795 www 6540:
1.1114 raeburn 6541: table.LC_data_table tr.LC_empty_row td,
6542: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6543: background-color: $sidebg;
6544: }
6545:
6546: table.LC_nested tr.LC_empty_row td {
6547: background-color: #FFFFFF;
6548: }
6549:
1.890 droeschl 6550: table.LC_caption {
6551: }
6552:
1.507 raeburn 6553: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6554: padding: 4ex
6555: }
1.795 www 6556:
1.507 raeburn 6557: table.LC_nested_outer tr th {
6558: font-weight: bold;
1.801 tempelho 6559: color:$fontmenu;
1.507 raeburn 6560: background-color: $data_table_head;
1.701 harmsja 6561: font-size: small;
1.507 raeburn 6562: border-bottom: 1px solid #000000;
6563: }
1.795 www 6564:
1.507 raeburn 6565: table.LC_nested_outer tr td.LC_subheader {
6566: background-color: $data_table_head;
6567: font-weight: bold;
6568: font-size: small;
6569: border-bottom: 1px solid #000000;
6570: text-align: right;
1.451 albertel 6571: }
1.795 www 6572:
1.507 raeburn 6573: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6574: background-color: #CCCCCC;
1.451 albertel 6575: font-weight: bold;
6576: font-size: small;
1.507 raeburn 6577: text-align: center;
6578: }
1.795 www 6579:
1.589 raeburn 6580: table.LC_nested tr.LC_info_row td.LC_left_item,
6581: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6582: text-align: left;
1.451 albertel 6583: }
1.795 www 6584:
1.507 raeburn 6585: table.LC_nested td {
1.735 bisitz 6586: background-color: #FFFFFF;
1.451 albertel 6587: font-size: small;
1.507 raeburn 6588: }
1.795 www 6589:
1.507 raeburn 6590: table.LC_nested_outer tr th.LC_right_item,
6591: table.LC_nested tr.LC_info_row td.LC_right_item,
6592: table.LC_nested tr.LC_odd_row td.LC_right_item,
6593: table.LC_nested tr td.LC_right_item {
1.451 albertel 6594: text-align: right;
6595: }
6596:
1.507 raeburn 6597: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6598: background-color: #EEEEEE;
1.451 albertel 6599: }
6600:
1.473 raeburn 6601: table.LC_createuser {
6602: }
6603:
6604: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6605: font-size: small;
1.473 raeburn 6606: }
6607:
6608: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6609: background-color: #CCCCCC;
1.473 raeburn 6610: font-weight: bold;
6611: text-align: center;
6612: }
6613:
1.349 albertel 6614: table.LC_calendar {
6615: border: 1px solid #000000;
6616: border-collapse: collapse;
1.917 raeburn 6617: width: 98%;
1.349 albertel 6618: }
1.795 www 6619:
1.349 albertel 6620: table.LC_calendar_pickdate {
6621: font-size: xx-small;
6622: }
1.795 www 6623:
1.349 albertel 6624: table.LC_calendar tr td {
6625: border: 1px solid #000000;
6626: vertical-align: top;
1.917 raeburn 6627: width: 14%;
1.349 albertel 6628: }
1.795 www 6629:
1.349 albertel 6630: table.LC_calendar tr td.LC_calendar_day_empty {
6631: background-color: $data_table_dark;
6632: }
1.795 www 6633:
1.779 bisitz 6634: table.LC_calendar tr td.LC_calendar_day_current {
6635: background-color: $data_table_highlight;
1.777 tempelho 6636: }
1.795 www 6637:
1.938 bisitz 6638: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6639: background-color: $mail_new;
6640: }
1.795 www 6641:
1.938 bisitz 6642: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6643: background-color: $mail_new_hover;
6644: }
1.795 www 6645:
1.938 bisitz 6646: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6647: background-color: $mail_read;
6648: }
1.795 www 6649:
1.938 bisitz 6650: /*
6651: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6652: background-color: $mail_read_hover;
6653: }
1.938 bisitz 6654: */
1.795 www 6655:
1.938 bisitz 6656: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6657: background-color: $mail_replied;
6658: }
1.795 www 6659:
1.938 bisitz 6660: /*
6661: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6662: background-color: $mail_replied_hover;
6663: }
1.938 bisitz 6664: */
1.795 www 6665:
1.938 bisitz 6666: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6667: background-color: $mail_other;
6668: }
1.795 www 6669:
1.938 bisitz 6670: /*
6671: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6672: background-color: $mail_other_hover;
6673: }
1.938 bisitz 6674: */
1.494 raeburn 6675:
1.777 tempelho 6676: table.LC_data_table tr > td.LC_browser_file,
6677: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6678: background: #AAEE77;
1.389 albertel 6679: }
1.795 www 6680:
1.777 tempelho 6681: table.LC_data_table tr > td.LC_browser_file_locked,
6682: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6683: background: #FFAA99;
1.387 albertel 6684: }
1.795 www 6685:
1.777 tempelho 6686: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6687: background: #888888;
1.779 bisitz 6688: }
1.795 www 6689:
1.777 tempelho 6690: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6691: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6692: background: #F8F866;
1.777 tempelho 6693: }
1.795 www 6694:
1.696 bisitz 6695: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6696: background: #E0E8FF;
1.387 albertel 6697: }
1.696 bisitz 6698:
1.707 bisitz 6699: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6700: /* background: #77FF77; */
1.707 bisitz 6701: }
1.795 www 6702:
1.707 bisitz 6703: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6704: border-right: 8px solid #FFFF77;
1.707 bisitz 6705: }
1.795 www 6706:
1.707 bisitz 6707: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6708: border-right: 8px solid #FFAA77;
1.707 bisitz 6709: }
1.795 www 6710:
1.707 bisitz 6711: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6712: border-right: 8px solid #FF7777;
1.707 bisitz 6713: }
1.795 www 6714:
1.707 bisitz 6715: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6716: border-right: 8px solid #AAFF77;
1.707 bisitz 6717: }
1.795 www 6718:
1.707 bisitz 6719: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6720: border-right: 8px solid #11CC55;
1.707 bisitz 6721: }
6722:
1.388 albertel 6723: span.LC_current_location {
1.701 harmsja 6724: font-size:larger;
1.388 albertel 6725: background: $pgbg;
6726: }
1.387 albertel 6727:
1.1029 www 6728: span.LC_current_nav_location {
6729: font-weight:bold;
6730: background: $sidebg;
6731: }
6732:
1.395 albertel 6733: span.LC_parm_menu_item {
6734: font-size: larger;
6735: }
1.795 www 6736:
1.395 albertel 6737: span.LC_parm_scope_all {
6738: color: red;
6739: }
1.795 www 6740:
1.395 albertel 6741: span.LC_parm_scope_folder {
6742: color: green;
6743: }
1.795 www 6744:
1.395 albertel 6745: span.LC_parm_scope_resource {
6746: color: orange;
6747: }
1.795 www 6748:
1.395 albertel 6749: span.LC_parm_part {
6750: color: blue;
6751: }
1.795 www 6752:
1.911 bisitz 6753: span.LC_parm_folder,
6754: span.LC_parm_symb {
1.395 albertel 6755: font-size: x-small;
6756: font-family: $mono;
6757: color: #AAAAAA;
6758: }
6759:
1.977 bisitz 6760: ul.LC_parm_parmlist li {
6761: display: inline-block;
6762: padding: 0.3em 0.8em;
6763: vertical-align: top;
6764: width: 150px;
6765: border-top:1px solid $lg_border_color;
6766: }
6767:
1.795 www 6768: td.LC_parm_overview_level_menu,
6769: td.LC_parm_overview_map_menu,
6770: td.LC_parm_overview_parm_selectors,
6771: td.LC_parm_overview_restrictions {
1.396 albertel 6772: border: 1px solid black;
6773: border-collapse: collapse;
6774: }
1.795 www 6775:
1.1285 ! raeburn 6776: span.LC_parm_recursive,
! 6777: td.LC_parm_recursive {
! 6778: font-weight: bold;
! 6779: font-size: smaller;
! 6780: }
! 6781:
1.396 albertel 6782: table.LC_parm_overview_restrictions td {
6783: border-width: 1px 4px 1px 4px;
6784: border-style: solid;
6785: border-color: $pgbg;
6786: text-align: center;
6787: }
1.795 www 6788:
1.396 albertel 6789: table.LC_parm_overview_restrictions th {
6790: background: $tabbg;
6791: border-width: 1px 4px 1px 4px;
6792: border-style: solid;
6793: border-color: $pgbg;
6794: }
1.795 www 6795:
1.398 albertel 6796: table#LC_helpmenu {
1.803 bisitz 6797: border: none;
1.398 albertel 6798: height: 55px;
1.803 bisitz 6799: border-spacing: 0;
1.398 albertel 6800: }
6801:
6802: table#LC_helpmenu fieldset legend {
6803: font-size: larger;
6804: }
1.795 www 6805:
1.397 albertel 6806: table#LC_helpmenu_links {
6807: width: 100%;
6808: border: 1px solid black;
6809: background: $pgbg;
1.803 bisitz 6810: padding: 0;
1.397 albertel 6811: border-spacing: 1px;
6812: }
1.795 www 6813:
1.397 albertel 6814: table#LC_helpmenu_links tr td {
6815: padding: 1px;
6816: background: $tabbg;
1.399 albertel 6817: text-align: center;
6818: font-weight: bold;
1.397 albertel 6819: }
1.396 albertel 6820:
1.795 www 6821: table#LC_helpmenu_links a:link,
6822: table#LC_helpmenu_links a:visited,
1.397 albertel 6823: table#LC_helpmenu_links a:active {
6824: text-decoration: none;
6825: color: $font;
6826: }
1.795 www 6827:
1.397 albertel 6828: table#LC_helpmenu_links a:hover {
6829: text-decoration: underline;
6830: color: $vlink;
6831: }
1.396 albertel 6832:
1.417 albertel 6833: .LC_chrt_popup_exists {
6834: border: 1px solid #339933;
6835: margin: -1px;
6836: }
1.795 www 6837:
1.417 albertel 6838: .LC_chrt_popup_up {
6839: border: 1px solid yellow;
6840: margin: -1px;
6841: }
1.795 www 6842:
1.417 albertel 6843: .LC_chrt_popup {
6844: border: 1px solid #8888FF;
6845: background: #CCCCFF;
6846: }
1.795 www 6847:
1.421 albertel 6848: table.LC_pick_box {
6849: border-collapse: separate;
6850: background: white;
6851: border: 1px solid black;
6852: border-spacing: 1px;
6853: }
1.795 www 6854:
1.421 albertel 6855: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6856: background: $sidebg;
1.421 albertel 6857: font-weight: bold;
1.900 bisitz 6858: text-align: left;
1.740 bisitz 6859: vertical-align: top;
1.421 albertel 6860: width: 184px;
6861: padding: 8px;
6862: }
1.795 www 6863:
1.579 raeburn 6864: table.LC_pick_box td.LC_pick_box_value {
6865: text-align: left;
6866: padding: 8px;
6867: }
1.795 www 6868:
1.579 raeburn 6869: table.LC_pick_box td.LC_pick_box_select {
6870: text-align: left;
6871: padding: 8px;
6872: }
1.795 www 6873:
1.424 albertel 6874: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6875: padding: 0;
1.421 albertel 6876: height: 1px;
6877: background: black;
6878: }
1.795 www 6879:
1.421 albertel 6880: table.LC_pick_box td.LC_pick_box_submit {
6881: text-align: right;
6882: }
1.795 www 6883:
1.579 raeburn 6884: table.LC_pick_box td.LC_evenrow_value {
6885: text-align: left;
6886: padding: 8px;
6887: background-color: $data_table_light;
6888: }
1.795 www 6889:
1.579 raeburn 6890: table.LC_pick_box td.LC_oddrow_value {
6891: text-align: left;
6892: padding: 8px;
6893: background-color: $data_table_light;
6894: }
1.795 www 6895:
1.579 raeburn 6896: span.LC_helpform_receipt_cat {
6897: font-weight: bold;
6898: }
1.795 www 6899:
1.424 albertel 6900: table.LC_group_priv_box {
6901: background: white;
6902: border: 1px solid black;
6903: border-spacing: 1px;
6904: }
1.795 www 6905:
1.424 albertel 6906: table.LC_group_priv_box td.LC_pick_box_title {
6907: background: $tabbg;
6908: font-weight: bold;
6909: text-align: right;
6910: width: 184px;
6911: }
1.795 www 6912:
1.424 albertel 6913: table.LC_group_priv_box td.LC_groups_fixed {
6914: background: $data_table_light;
6915: text-align: center;
6916: }
1.795 www 6917:
1.424 albertel 6918: table.LC_group_priv_box td.LC_groups_optional {
6919: background: $data_table_dark;
6920: text-align: center;
6921: }
1.795 www 6922:
1.424 albertel 6923: table.LC_group_priv_box td.LC_groups_functionality {
6924: background: $data_table_darker;
6925: text-align: center;
6926: font-weight: bold;
6927: }
1.795 www 6928:
1.424 albertel 6929: table.LC_group_priv td {
6930: text-align: left;
1.803 bisitz 6931: padding: 0;
1.424 albertel 6932: }
6933:
6934: .LC_navbuttons {
6935: margin: 2ex 0ex 2ex 0ex;
6936: }
1.795 www 6937:
1.423 albertel 6938: .LC_topic_bar {
6939: font-weight: bold;
6940: background: $tabbg;
1.918 wenzelju 6941: margin: 1em 0em 1em 2em;
1.805 bisitz 6942: padding: 3px;
1.918 wenzelju 6943: font-size: 1.2em;
1.423 albertel 6944: }
1.795 www 6945:
1.423 albertel 6946: .LC_topic_bar span {
1.918 wenzelju 6947: left: 0.5em;
6948: position: absolute;
1.423 albertel 6949: vertical-align: middle;
1.918 wenzelju 6950: font-size: 1.2em;
1.423 albertel 6951: }
1.795 www 6952:
1.423 albertel 6953: table.LC_course_group_status {
6954: margin: 20px;
6955: }
1.795 www 6956:
1.423 albertel 6957: table.LC_status_selector td {
6958: vertical-align: top;
6959: text-align: center;
1.424 albertel 6960: padding: 4px;
6961: }
1.795 www 6962:
1.599 albertel 6963: div.LC_feedback_link {
1.616 albertel 6964: clear: both;
1.829 kalberla 6965: background: $sidebg;
1.779 bisitz 6966: width: 100%;
1.829 kalberla 6967: padding-bottom: 10px;
6968: border: 1px $tabbg solid;
1.833 kalberla 6969: height: 22px;
6970: line-height: 22px;
6971: padding-top: 5px;
6972: }
6973:
6974: div.LC_feedback_link img {
6975: height: 22px;
1.867 kalberla 6976: vertical-align:middle;
1.829 kalberla 6977: }
6978:
1.911 bisitz 6979: div.LC_feedback_link a {
1.829 kalberla 6980: text-decoration: none;
1.489 raeburn 6981: }
1.795 www 6982:
1.867 kalberla 6983: div.LC_comblock {
1.911 bisitz 6984: display:inline;
1.867 kalberla 6985: color:$font;
6986: font-size:90%;
6987: }
6988:
6989: div.LC_feedback_link div.LC_comblock {
6990: padding-left:5px;
6991: }
6992:
6993: div.LC_feedback_link div.LC_comblock a {
6994: color:$font;
6995: }
6996:
1.489 raeburn 6997: span.LC_feedback_link {
1.858 bisitz 6998: /* background: $feedback_link_bg; */
1.599 albertel 6999: font-size: larger;
7000: }
1.795 www 7001:
1.599 albertel 7002: span.LC_message_link {
1.858 bisitz 7003: /* background: $feedback_link_bg; */
1.599 albertel 7004: font-size: larger;
7005: position: absolute;
7006: right: 1em;
1.489 raeburn 7007: }
1.421 albertel 7008:
1.515 albertel 7009: table.LC_prior_tries {
1.524 albertel 7010: border: 1px solid #000000;
7011: border-collapse: separate;
7012: border-spacing: 1px;
1.515 albertel 7013: }
1.523 albertel 7014:
1.515 albertel 7015: table.LC_prior_tries td {
1.524 albertel 7016: padding: 2px;
1.515 albertel 7017: }
1.523 albertel 7018:
7019: .LC_answer_correct {
1.795 www 7020: background: lightgreen;
7021: color: darkgreen;
7022: padding: 6px;
1.523 albertel 7023: }
1.795 www 7024:
1.523 albertel 7025: .LC_answer_charged_try {
1.797 www 7026: background: #FFAAAA;
1.795 www 7027: color: darkred;
7028: padding: 6px;
1.523 albertel 7029: }
1.795 www 7030:
1.779 bisitz 7031: .LC_answer_not_charged_try,
1.523 albertel 7032: .LC_answer_no_grade,
7033: .LC_answer_late {
1.795 www 7034: background: lightyellow;
1.523 albertel 7035: color: black;
1.795 www 7036: padding: 6px;
1.523 albertel 7037: }
1.795 www 7038:
1.523 albertel 7039: .LC_answer_previous {
1.795 www 7040: background: lightblue;
7041: color: darkblue;
7042: padding: 6px;
1.523 albertel 7043: }
1.795 www 7044:
1.779 bisitz 7045: .LC_answer_no_message {
1.777 tempelho 7046: background: #FFFFFF;
7047: color: black;
1.795 www 7048: padding: 6px;
1.779 bisitz 7049: }
1.795 www 7050:
1.779 bisitz 7051: .LC_answer_unknown {
7052: background: orange;
7053: color: black;
1.795 www 7054: padding: 6px;
1.777 tempelho 7055: }
1.795 www 7056:
1.529 albertel 7057: span.LC_prior_numerical,
7058: span.LC_prior_string,
7059: span.LC_prior_custom,
7060: span.LC_prior_reaction,
7061: span.LC_prior_math {
1.925 bisitz 7062: font-family: $mono;
1.523 albertel 7063: white-space: pre;
7064: }
7065:
1.525 albertel 7066: span.LC_prior_string {
1.925 bisitz 7067: font-family: $mono;
1.525 albertel 7068: white-space: pre;
7069: }
7070:
1.523 albertel 7071: table.LC_prior_option {
7072: width: 100%;
7073: border-collapse: collapse;
7074: }
1.795 www 7075:
1.911 bisitz 7076: table.LC_prior_rank,
1.795 www 7077: table.LC_prior_match {
1.528 albertel 7078: border-collapse: collapse;
7079: }
1.795 www 7080:
1.528 albertel 7081: table.LC_prior_option tr td,
7082: table.LC_prior_rank tr td,
7083: table.LC_prior_match tr td {
1.524 albertel 7084: border: 1px solid #000000;
1.515 albertel 7085: }
7086:
1.855 bisitz 7087: .LC_nobreak {
1.544 albertel 7088: white-space: nowrap;
1.519 raeburn 7089: }
7090:
1.576 raeburn 7091: span.LC_cusr_emph {
7092: font-style: italic;
7093: }
7094:
1.633 raeburn 7095: span.LC_cusr_subheading {
7096: font-weight: normal;
7097: font-size: 85%;
7098: }
7099:
1.861 bisitz 7100: div.LC_docs_entry_move {
1.859 bisitz 7101: border: 1px solid #BBBBBB;
1.545 albertel 7102: background: #DDDDDD;
1.861 bisitz 7103: width: 22px;
1.859 bisitz 7104: padding: 1px;
7105: margin: 0;
1.545 albertel 7106: }
7107:
1.861 bisitz 7108: table.LC_data_table tr > td.LC_docs_entry_commands,
7109: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7110: font-size: x-small;
7111: }
1.795 www 7112:
1.861 bisitz 7113: .LC_docs_entry_parameter {
7114: white-space: nowrap;
7115: }
7116:
1.544 albertel 7117: .LC_docs_copy {
1.545 albertel 7118: color: #000099;
1.544 albertel 7119: }
1.795 www 7120:
1.544 albertel 7121: .LC_docs_cut {
1.545 albertel 7122: color: #550044;
1.544 albertel 7123: }
1.795 www 7124:
1.544 albertel 7125: .LC_docs_rename {
1.545 albertel 7126: color: #009900;
1.544 albertel 7127: }
1.795 www 7128:
1.544 albertel 7129: .LC_docs_remove {
1.545 albertel 7130: color: #990000;
7131: }
7132:
1.1284 raeburn 7133: .LC_docs_alias {
7134: color: #440055;
7135: }
7136:
7137: .LC_docs_alias_name,
1.547 albertel 7138: .LC_docs_reinit_warn,
7139: .LC_docs_ext_edit {
7140: font-size: x-small;
7141: }
7142:
1.545 albertel 7143: table.LC_docs_adddocs td,
7144: table.LC_docs_adddocs th {
7145: border: 1px solid #BBBBBB;
7146: padding: 4px;
7147: background: #DDDDDD;
1.543 albertel 7148: }
7149:
1.584 albertel 7150: table.LC_sty_begin {
7151: background: #BBFFBB;
7152: }
1.795 www 7153:
1.584 albertel 7154: table.LC_sty_end {
7155: background: #FFBBBB;
7156: }
7157:
1.589 raeburn 7158: table.LC_double_column {
1.803 bisitz 7159: border-width: 0;
1.589 raeburn 7160: border-collapse: collapse;
7161: width: 100%;
7162: padding: 2px;
7163: }
7164:
7165: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7166: top: 2px;
1.589 raeburn 7167: left: 2px;
7168: width: 47%;
7169: vertical-align: top;
7170: }
7171:
7172: table.LC_double_column tr td.LC_right_col {
7173: top: 2px;
1.779 bisitz 7174: right: 2px;
1.589 raeburn 7175: width: 47%;
7176: vertical-align: top;
7177: }
7178:
1.591 raeburn 7179: div.LC_left_float {
7180: float: left;
7181: padding-right: 5%;
1.597 albertel 7182: padding-bottom: 4px;
1.591 raeburn 7183: }
7184:
7185: div.LC_clear_float_header {
1.597 albertel 7186: padding-bottom: 2px;
1.591 raeburn 7187: }
7188:
7189: div.LC_clear_float_footer {
1.597 albertel 7190: padding-top: 10px;
1.591 raeburn 7191: clear: both;
7192: }
7193:
1.597 albertel 7194: div.LC_grade_show_user {
1.941 bisitz 7195: /* border-left: 5px solid $sidebg; */
7196: border-top: 5px solid #000000;
7197: margin: 50px 0 0 0;
1.936 bisitz 7198: padding: 15px 0 5px 10px;
1.597 albertel 7199: }
1.795 www 7200:
1.936 bisitz 7201: div.LC_grade_show_user_odd_row {
1.941 bisitz 7202: /* border-left: 5px solid #000000; */
7203: }
7204:
7205: div.LC_grade_show_user div.LC_Box {
7206: margin-right: 50px;
1.597 albertel 7207: }
7208:
7209: div.LC_grade_submissions,
7210: div.LC_grade_message_center,
1.936 bisitz 7211: div.LC_grade_info_links {
1.597 albertel 7212: margin: 5px;
7213: width: 99%;
7214: background: #FFFFFF;
7215: }
1.795 www 7216:
1.597 albertel 7217: div.LC_grade_submissions_header,
1.936 bisitz 7218: div.LC_grade_message_center_header {
1.705 tempelho 7219: font-weight: bold;
7220: font-size: large;
1.597 albertel 7221: }
1.795 www 7222:
1.597 albertel 7223: div.LC_grade_submissions_body,
1.936 bisitz 7224: div.LC_grade_message_center_body {
1.597 albertel 7225: border: 1px solid black;
7226: width: 99%;
7227: background: #FFFFFF;
7228: }
1.795 www 7229:
1.613 albertel 7230: table.LC_scantron_action {
7231: width: 100%;
7232: }
1.795 www 7233:
1.613 albertel 7234: table.LC_scantron_action tr th {
1.698 harmsja 7235: font-weight:bold;
7236: font-style:normal;
1.613 albertel 7237: }
1.795 www 7238:
1.779 bisitz 7239: .LC_edit_problem_header,
1.614 albertel 7240: div.LC_edit_problem_footer {
1.705 tempelho 7241: font-weight: normal;
7242: font-size: medium;
1.602 albertel 7243: margin: 2px;
1.1060 bisitz 7244: background-color: $sidebg;
1.600 albertel 7245: }
1.795 www 7246:
1.600 albertel 7247: div.LC_edit_problem_header,
1.602 albertel 7248: div.LC_edit_problem_header div,
1.614 albertel 7249: div.LC_edit_problem_footer,
7250: div.LC_edit_problem_footer div,
1.602 albertel 7251: div.LC_edit_problem_editxml_header,
7252: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7253: z-index: 100;
1.600 albertel 7254: }
1.795 www 7255:
1.600 albertel 7256: div.LC_edit_problem_header_title {
1.705 tempelho 7257: font-weight: bold;
7258: font-size: larger;
1.602 albertel 7259: background: $tabbg;
7260: padding: 3px;
1.1060 bisitz 7261: margin: 0 0 5px 0;
1.602 albertel 7262: }
1.795 www 7263:
1.602 albertel 7264: table.LC_edit_problem_header_title {
7265: width: 100%;
1.600 albertel 7266: background: $tabbg;
1.602 albertel 7267: }
7268:
1.1205 golterma 7269: div.LC_edit_actionbar {
7270: background-color: $sidebg;
1.1218 droeschl 7271: margin: 0;
7272: padding: 0;
7273: line-height: 200%;
1.602 albertel 7274: }
1.795 www 7275:
1.1218 droeschl 7276: div.LC_edit_actionbar div{
7277: padding: 0;
7278: margin: 0;
7279: display: inline-block;
1.600 albertel 7280: }
1.795 www 7281:
1.1124 bisitz 7282: .LC_edit_opt {
7283: padding-left: 1em;
7284: white-space: nowrap;
7285: }
7286:
1.1152 golterma 7287: .LC_edit_problem_latexhelper{
7288: text-align: right;
7289: }
7290:
7291: #LC_edit_problem_colorful div{
7292: margin-left: 40px;
7293: }
7294:
1.1205 golterma 7295: #LC_edit_problem_codemirror div{
7296: margin-left: 0px;
7297: }
7298:
1.911 bisitz 7299: img.stift {
1.803 bisitz 7300: border-width: 0;
7301: vertical-align: middle;
1.677 riegler 7302: }
1.680 riegler 7303:
1.923 bisitz 7304: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7305: vertical-align: top;
1.777 tempelho 7306: }
1.795 www 7307:
1.716 raeburn 7308: div.LC_createcourse {
1.911 bisitz 7309: margin: 10px 10px 10px 10px;
1.716 raeburn 7310: }
7311:
1.917 raeburn 7312: .LC_dccid {
1.1130 raeburn 7313: float: right;
1.917 raeburn 7314: margin: 0.2em 0 0 0;
7315: padding: 0;
7316: font-size: 90%;
7317: display:none;
7318: }
7319:
1.897 wenzelju 7320: ol.LC_primary_menu a:hover,
1.721 harmsja 7321: ol#LC_MenuBreadcrumbs a:hover,
7322: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7323: ul#LC_secondary_menu a:hover,
1.721 harmsja 7324: .LC_FormSectionClearButton input:hover
1.795 www 7325: ul.LC_TabContent li:hover a {
1.952 onken 7326: color:$button_hover;
1.911 bisitz 7327: text-decoration:none;
1.693 droeschl 7328: }
7329:
1.779 bisitz 7330: h1 {
1.911 bisitz 7331: padding: 0;
7332: line-height:130%;
1.693 droeschl 7333: }
1.698 harmsja 7334:
1.911 bisitz 7335: h2,
7336: h3,
7337: h4,
7338: h5,
7339: h6 {
7340: margin: 5px 0 5px 0;
7341: padding: 0;
7342: line-height:130%;
1.693 droeschl 7343: }
1.795 www 7344:
7345: .LC_hcell {
1.911 bisitz 7346: padding:3px 15px 3px 15px;
7347: margin: 0;
7348: background-color:$tabbg;
7349: color:$fontmenu;
7350: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7351: }
1.795 www 7352:
1.840 bisitz 7353: .LC_Box > .LC_hcell {
1.911 bisitz 7354: margin: 0 -10px 10px -10px;
1.835 bisitz 7355: }
7356:
1.721 harmsja 7357: .LC_noBorder {
1.911 bisitz 7358: border: 0;
1.698 harmsja 7359: }
1.693 droeschl 7360:
1.721 harmsja 7361: .LC_FormSectionClearButton input {
1.911 bisitz 7362: background-color:transparent;
7363: border: none;
7364: cursor:pointer;
7365: text-decoration:underline;
1.693 droeschl 7366: }
1.763 bisitz 7367:
7368: .LC_help_open_topic {
1.911 bisitz 7369: color: #FFFFFF;
7370: background-color: #EEEEFF;
7371: margin: 1px;
7372: padding: 4px;
7373: border: 1px solid #000033;
7374: white-space: nowrap;
7375: /* vertical-align: middle; */
1.759 neumanie 7376: }
1.693 droeschl 7377:
1.911 bisitz 7378: dl,
7379: ul,
7380: div,
7381: fieldset {
7382: margin: 10px 10px 10px 0;
7383: /* overflow: hidden; */
1.693 droeschl 7384: }
1.795 www 7385:
1.1211 raeburn 7386: article.geogebraweb div {
7387: margin: 0;
7388: }
7389:
1.838 bisitz 7390: fieldset > legend {
1.911 bisitz 7391: font-weight: bold;
7392: padding: 0 5px 0 5px;
1.838 bisitz 7393: }
7394:
1.813 bisitz 7395: #LC_nav_bar {
1.911 bisitz 7396: float: left;
1.995 raeburn 7397: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7398: margin: 0 0 2px 0;
1.807 droeschl 7399: }
7400:
1.916 droeschl 7401: #LC_realm {
7402: margin: 0.2em 0 0 0;
7403: padding: 0;
7404: font-weight: bold;
7405: text-align: center;
1.995 raeburn 7406: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7407: }
7408:
1.911 bisitz 7409: #LC_nav_bar em {
7410: font-weight: bold;
7411: font-style: normal;
1.807 droeschl 7412: }
7413:
1.897 wenzelju 7414: ol.LC_primary_menu {
1.934 droeschl 7415: margin: 0;
1.1076 raeburn 7416: padding: 0;
1.807 droeschl 7417: }
7418:
1.852 droeschl 7419: ol#LC_PathBreadcrumbs {
1.911 bisitz 7420: margin: 0;
1.693 droeschl 7421: }
7422:
1.897 wenzelju 7423: ol.LC_primary_menu li {
1.1076 raeburn 7424: color: RGB(80, 80, 80);
7425: vertical-align: middle;
7426: text-align: left;
7427: list-style: none;
1.1205 golterma 7428: position: relative;
1.1076 raeburn 7429: float: left;
1.1205 golterma 7430: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7431: line-height: 1.5em;
1.1076 raeburn 7432: }
7433:
1.1205 golterma 7434: ol.LC_primary_menu li a,
7435: ol.LC_primary_menu li p {
1.1076 raeburn 7436: display: block;
7437: margin: 0;
7438: padding: 0 5px 0 10px;
7439: text-decoration: none;
7440: }
7441:
1.1205 golterma 7442: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7443: display: inline-block;
7444: width: 95%;
7445: text-align: left;
7446: }
7447:
7448: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7449: display: inline-block;
7450: width: 5%;
7451: float: right;
7452: text-align: right;
7453: font-size: 70%;
7454: }
7455:
7456: ol.LC_primary_menu ul {
1.1076 raeburn 7457: display: none;
1.1205 golterma 7458: width: 15em;
1.1076 raeburn 7459: background-color: $data_table_light;
1.1205 golterma 7460: position: absolute;
7461: top: 100%;
1.1076 raeburn 7462: }
7463:
1.1205 golterma 7464: ol.LC_primary_menu ul ul {
7465: left: 100%;
7466: top: 0;
7467: }
7468:
7469: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7470: display: block;
7471: position: absolute;
7472: margin: 0;
7473: padding: 0;
1.1078 raeburn 7474: z-index: 2;
1.1076 raeburn 7475: }
7476:
7477: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7478: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7479: font-size: 90%;
1.911 bisitz 7480: vertical-align: top;
1.1076 raeburn 7481: float: none;
1.1079 raeburn 7482: border-left: 1px solid black;
7483: border-right: 1px solid black;
1.1205 golterma 7484: /* A dark bottom border to visualize different menu options;
7485: overwritten in the create_submenu routine for the last border-bottom of the menu */
7486: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7487: }
7488:
1.1205 golterma 7489: ol.LC_primary_menu li li p:hover {
7490: color:$button_hover;
7491: text-decoration:none;
7492: background-color:$data_table_dark;
1.1076 raeburn 7493: }
7494:
7495: ol.LC_primary_menu li li a:hover {
7496: color:$button_hover;
7497: background-color:$data_table_dark;
1.693 droeschl 7498: }
7499:
1.1205 golterma 7500: /* Font-size equal to the size of the predecessors*/
7501: ol.LC_primary_menu li:hover li li {
7502: font-size: 100%;
7503: }
7504:
1.897 wenzelju 7505: ol.LC_primary_menu li img {
1.911 bisitz 7506: vertical-align: bottom;
1.934 droeschl 7507: height: 1.1em;
1.1077 raeburn 7508: margin: 0.2em 0 0 0;
1.693 droeschl 7509: }
7510:
1.897 wenzelju 7511: ol.LC_primary_menu a {
1.911 bisitz 7512: color: RGB(80, 80, 80);
7513: text-decoration: none;
1.693 droeschl 7514: }
1.795 www 7515:
1.949 droeschl 7516: ol.LC_primary_menu a.LC_new_message {
7517: font-weight:bold;
7518: color: darkred;
7519: }
7520:
1.975 raeburn 7521: ol.LC_docs_parameters {
7522: margin-left: 0;
7523: padding: 0;
7524: list-style: none;
7525: }
7526:
7527: ol.LC_docs_parameters li {
7528: margin: 0;
7529: padding-right: 20px;
7530: display: inline;
7531: }
7532:
1.976 raeburn 7533: ol.LC_docs_parameters li:before {
7534: content: "\\002022 \\0020";
7535: }
7536:
7537: li.LC_docs_parameters_title {
7538: font-weight: bold;
7539: }
7540:
7541: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7542: content: "";
7543: }
7544:
1.897 wenzelju 7545: ul#LC_secondary_menu {
1.1107 raeburn 7546: clear: right;
1.911 bisitz 7547: color: $fontmenu;
7548: background: $tabbg;
7549: list-style: none;
7550: padding: 0;
7551: margin: 0;
7552: width: 100%;
1.995 raeburn 7553: text-align: left;
1.1107 raeburn 7554: float: left;
1.808 droeschl 7555: }
7556:
1.897 wenzelju 7557: ul#LC_secondary_menu li {
1.911 bisitz 7558: font-weight: bold;
7559: line-height: 1.8em;
1.1107 raeburn 7560: border-right: 1px solid black;
7561: float: left;
7562: }
7563:
7564: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7565: background-color: $data_table_light;
7566: }
7567:
7568: ul#LC_secondary_menu li a {
1.911 bisitz 7569: padding: 0 0.8em;
1.1107 raeburn 7570: }
7571:
7572: ul#LC_secondary_menu li ul {
7573: display: none;
7574: }
7575:
7576: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7577: display: block;
7578: position: absolute;
7579: margin: 0;
7580: padding: 0;
7581: list-style:none;
7582: float: none;
7583: background-color: $data_table_light;
7584: z-index: 2;
7585: margin-left: -1px;
7586: }
7587:
7588: ul#LC_secondary_menu li ul li {
7589: font-size: 90%;
7590: vertical-align: top;
7591: border-left: 1px solid black;
1.911 bisitz 7592: border-right: 1px solid black;
1.1119 raeburn 7593: background-color: $data_table_light;
1.1107 raeburn 7594: list-style:none;
7595: float: none;
7596: }
7597:
7598: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7599: background-color: $data_table_dark;
1.807 droeschl 7600: }
7601:
1.847 tempelho 7602: ul.LC_TabContent {
1.911 bisitz 7603: display:block;
7604: background: $sidebg;
7605: border-bottom: solid 1px $lg_border_color;
7606: list-style:none;
1.1020 raeburn 7607: margin: -1px -10px 0 -10px;
1.911 bisitz 7608: padding: 0;
1.693 droeschl 7609: }
7610:
1.795 www 7611: ul.LC_TabContent li,
7612: ul.LC_TabContentBigger li {
1.911 bisitz 7613: float:left;
1.741 harmsja 7614: }
1.795 www 7615:
1.897 wenzelju 7616: ul#LC_secondary_menu li a {
1.911 bisitz 7617: color: $fontmenu;
7618: text-decoration: none;
1.693 droeschl 7619: }
1.795 www 7620:
1.721 harmsja 7621: ul.LC_TabContent {
1.952 onken 7622: min-height:20px;
1.721 harmsja 7623: }
1.795 www 7624:
7625: ul.LC_TabContent li {
1.911 bisitz 7626: vertical-align:middle;
1.959 onken 7627: padding: 0 16px 0 10px;
1.911 bisitz 7628: background-color:$tabbg;
7629: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7630: border-left: solid 1px $font;
1.721 harmsja 7631: }
1.795 www 7632:
1.847 tempelho 7633: ul.LC_TabContent .right {
1.911 bisitz 7634: float:right;
1.847 tempelho 7635: }
7636:
1.911 bisitz 7637: ul.LC_TabContent li a,
7638: ul.LC_TabContent li {
7639: color:rgb(47,47,47);
7640: text-decoration:none;
7641: font-size:95%;
7642: font-weight:bold;
1.952 onken 7643: min-height:20px;
7644: }
7645:
1.959 onken 7646: ul.LC_TabContent li a:hover,
7647: ul.LC_TabContent li a:focus {
1.952 onken 7648: color: $button_hover;
1.959 onken 7649: background:none;
7650: outline:none;
1.952 onken 7651: }
7652:
7653: ul.LC_TabContent li:hover {
7654: color: $button_hover;
7655: cursor:pointer;
1.721 harmsja 7656: }
1.795 www 7657:
1.911 bisitz 7658: ul.LC_TabContent li.active {
1.952 onken 7659: color: $font;
1.911 bisitz 7660: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7661: border-bottom:solid 1px #FFFFFF;
7662: cursor: default;
1.744 ehlerst 7663: }
1.795 www 7664:
1.959 onken 7665: ul.LC_TabContent li.active a {
7666: color:$font;
7667: background:#FFFFFF;
7668: outline: none;
7669: }
1.1047 raeburn 7670:
7671: ul.LC_TabContent li.goback {
7672: float: left;
7673: border-left: none;
7674: }
7675:
1.870 tempelho 7676: #maincoursedoc {
1.911 bisitz 7677: clear:both;
1.870 tempelho 7678: }
7679:
7680: ul.LC_TabContentBigger {
1.911 bisitz 7681: display:block;
7682: list-style:none;
7683: padding: 0;
1.870 tempelho 7684: }
7685:
1.795 www 7686: ul.LC_TabContentBigger li {
1.911 bisitz 7687: vertical-align:bottom;
7688: height: 30px;
7689: font-size:110%;
7690: font-weight:bold;
7691: color: #737373;
1.841 tempelho 7692: }
7693:
1.957 onken 7694: ul.LC_TabContentBigger li.active {
7695: position: relative;
7696: top: 1px;
7697: }
7698:
1.870 tempelho 7699: ul.LC_TabContentBigger li a {
1.911 bisitz 7700: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7701: height: 30px;
7702: line-height: 30px;
7703: text-align: center;
7704: display: block;
7705: text-decoration: none;
1.958 onken 7706: outline: none;
1.741 harmsja 7707: }
1.795 www 7708:
1.870 tempelho 7709: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7710: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7711: color:$font;
1.744 ehlerst 7712: }
1.795 www 7713:
1.870 tempelho 7714: ul.LC_TabContentBigger li b {
1.911 bisitz 7715: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7716: display: block;
7717: float: left;
7718: padding: 0 30px;
1.957 onken 7719: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7720: }
7721:
1.956 onken 7722: ul.LC_TabContentBigger li:hover b {
7723: color:$button_hover;
7724: }
7725:
1.870 tempelho 7726: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7727: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7728: color:$font;
1.957 onken 7729: border: 0;
1.741 harmsja 7730: }
1.693 droeschl 7731:
1.870 tempelho 7732:
1.862 bisitz 7733: ul.LC_CourseBreadcrumbs {
7734: background: $sidebg;
1.1020 raeburn 7735: height: 2em;
1.862 bisitz 7736: padding-left: 10px;
1.1020 raeburn 7737: margin: 0;
1.862 bisitz 7738: list-style-position: inside;
7739: }
7740:
1.911 bisitz 7741: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7742: ol#LC_PathBreadcrumbs {
1.911 bisitz 7743: padding-left: 10px;
7744: margin: 0;
1.933 droeschl 7745: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7746: }
7747:
1.911 bisitz 7748: ol#LC_MenuBreadcrumbs li,
7749: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7750: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7751: display: inline;
1.933 droeschl 7752: white-space: normal;
1.693 droeschl 7753: }
7754:
1.823 bisitz 7755: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7756: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7757: text-decoration: none;
7758: font-size:90%;
1.693 droeschl 7759: }
1.795 www 7760:
1.969 droeschl 7761: ol#LC_MenuBreadcrumbs h1 {
7762: display: inline;
7763: font-size: 90%;
7764: line-height: 2.5em;
7765: margin: 0;
7766: padding: 0;
7767: }
7768:
1.795 www 7769: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7770: text-decoration:none;
7771: font-size:100%;
7772: font-weight:bold;
1.693 droeschl 7773: }
1.795 www 7774:
1.840 bisitz 7775: .LC_Box {
1.911 bisitz 7776: border: solid 1px $lg_border_color;
7777: padding: 0 10px 10px 10px;
1.746 neumanie 7778: }
1.795 www 7779:
1.1020 raeburn 7780: .LC_DocsBox {
7781: border: solid 1px $lg_border_color;
7782: padding: 0 0 10px 10px;
7783: }
7784:
1.795 www 7785: .LC_AboutMe_Image {
1.911 bisitz 7786: float:left;
7787: margin-right:10px;
1.747 neumanie 7788: }
1.795 www 7789:
7790: .LC_Clear_AboutMe_Image {
1.911 bisitz 7791: clear:left;
1.747 neumanie 7792: }
1.795 www 7793:
1.721 harmsja 7794: dl.LC_ListStyleClean dt {
1.911 bisitz 7795: padding-right: 5px;
7796: display: table-header-group;
1.693 droeschl 7797: }
7798:
1.721 harmsja 7799: dl.LC_ListStyleClean dd {
1.911 bisitz 7800: display: table-row;
1.693 droeschl 7801: }
7802:
1.721 harmsja 7803: .LC_ListStyleClean,
7804: .LC_ListStyleSimple,
7805: .LC_ListStyleNormal,
1.795 www 7806: .LC_ListStyleSpecial {
1.911 bisitz 7807: /* display:block; */
7808: list-style-position: inside;
7809: list-style-type: none;
7810: overflow: hidden;
7811: padding: 0;
1.693 droeschl 7812: }
7813:
1.721 harmsja 7814: .LC_ListStyleSimple li,
7815: .LC_ListStyleSimple dd,
7816: .LC_ListStyleNormal li,
7817: .LC_ListStyleNormal dd,
7818: .LC_ListStyleSpecial li,
1.795 www 7819: .LC_ListStyleSpecial dd {
1.911 bisitz 7820: margin: 0;
7821: padding: 5px 5px 5px 10px;
7822: clear: both;
1.693 droeschl 7823: }
7824:
1.721 harmsja 7825: .LC_ListStyleClean li,
7826: .LC_ListStyleClean dd {
1.911 bisitz 7827: padding-top: 0;
7828: padding-bottom: 0;
1.693 droeschl 7829: }
7830:
1.721 harmsja 7831: .LC_ListStyleSimple dd,
1.795 www 7832: .LC_ListStyleSimple li {
1.911 bisitz 7833: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7834: }
7835:
1.721 harmsja 7836: .LC_ListStyleSpecial li,
7837: .LC_ListStyleSpecial dd {
1.911 bisitz 7838: list-style-type: none;
7839: background-color: RGB(220, 220, 220);
7840: margin-bottom: 4px;
1.693 droeschl 7841: }
7842:
1.721 harmsja 7843: table.LC_SimpleTable {
1.911 bisitz 7844: margin:5px;
7845: border:solid 1px $lg_border_color;
1.795 www 7846: }
1.693 droeschl 7847:
1.721 harmsja 7848: table.LC_SimpleTable tr {
1.911 bisitz 7849: padding: 0;
7850: border:solid 1px $lg_border_color;
1.693 droeschl 7851: }
1.795 www 7852:
7853: table.LC_SimpleTable thead {
1.911 bisitz 7854: background:rgb(220,220,220);
1.693 droeschl 7855: }
7856:
1.721 harmsja 7857: div.LC_columnSection {
1.911 bisitz 7858: display: block;
7859: clear: both;
7860: overflow: hidden;
7861: margin: 0;
1.693 droeschl 7862: }
7863:
1.721 harmsja 7864: div.LC_columnSection>* {
1.911 bisitz 7865: float: left;
7866: margin: 10px 20px 10px 0;
7867: overflow:hidden;
1.693 droeschl 7868: }
1.721 harmsja 7869:
1.795 www 7870: table em {
1.911 bisitz 7871: font-weight: bold;
7872: font-style: normal;
1.748 schulted 7873: }
1.795 www 7874:
1.779 bisitz 7875: table.LC_tableBrowseRes,
1.795 www 7876: table.LC_tableOfContent {
1.911 bisitz 7877: border:none;
7878: border-spacing: 1px;
7879: padding: 3px;
7880: background-color: #FFFFFF;
7881: font-size: 90%;
1.753 droeschl 7882: }
1.789 droeschl 7883:
1.911 bisitz 7884: table.LC_tableOfContent {
7885: border-collapse: collapse;
1.789 droeschl 7886: }
7887:
1.771 droeschl 7888: table.LC_tableBrowseRes a,
1.768 schulted 7889: table.LC_tableOfContent a {
1.911 bisitz 7890: background-color: transparent;
7891: text-decoration: none;
1.753 droeschl 7892: }
7893:
1.795 www 7894: table.LC_tableOfContent img {
1.911 bisitz 7895: border: none;
7896: height: 1.3em;
7897: vertical-align: text-bottom;
7898: margin-right: 0.3em;
1.753 droeschl 7899: }
1.757 schulted 7900:
1.795 www 7901: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7902: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7903: }
7904:
1.795 www 7905: a#LC_content_toolbar_everything {
1.911 bisitz 7906: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7907: }
7908:
1.795 www 7909: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7910: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7911: }
7912:
1.795 www 7913: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7914: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7915: }
7916:
1.795 www 7917: a#LC_content_toolbar_changefolder {
1.911 bisitz 7918: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7919: }
7920:
1.795 www 7921: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7922: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7923: }
7924:
1.1043 raeburn 7925: a#LC_content_toolbar_edittoplevel {
7926: background-image:url(/res/adm/pages/edittoplevel.gif);
7927: }
7928:
1.795 www 7929: ul#LC_toolbar li a:hover {
1.911 bisitz 7930: background-position: bottom center;
1.757 schulted 7931: }
7932:
1.795 www 7933: ul#LC_toolbar {
1.911 bisitz 7934: padding: 0;
7935: margin: 2px;
7936: list-style:none;
7937: position:relative;
7938: background-color:white;
1.1082 raeburn 7939: overflow: auto;
1.757 schulted 7940: }
7941:
1.795 www 7942: ul#LC_toolbar li {
1.911 bisitz 7943: border:1px solid white;
7944: padding: 0;
7945: margin: 0;
7946: float: left;
7947: display:inline;
7948: vertical-align:middle;
1.1082 raeburn 7949: white-space: nowrap;
1.911 bisitz 7950: }
1.757 schulted 7951:
1.783 amueller 7952:
1.795 www 7953: a.LC_toolbarItem {
1.911 bisitz 7954: display:block;
7955: padding: 0;
7956: margin: 0;
7957: height: 32px;
7958: width: 32px;
7959: color:white;
7960: border: none;
7961: background-repeat:no-repeat;
7962: background-color:transparent;
1.757 schulted 7963: }
7964:
1.915 droeschl 7965: ul.LC_funclist {
7966: margin: 0;
7967: padding: 0.5em 1em 0.5em 0;
7968: }
7969:
1.933 droeschl 7970: ul.LC_funclist > li:first-child {
7971: font-weight:bold;
7972: margin-left:0.8em;
7973: }
7974:
1.915 droeschl 7975: ul.LC_funclist + ul.LC_funclist {
7976: /*
7977: left border as a seperator if we have more than
7978: one list
7979: */
7980: border-left: 1px solid $sidebg;
7981: /*
7982: this hides the left border behind the border of the
7983: outer box if element is wrapped to the next 'line'
7984: */
7985: margin-left: -1px;
7986: }
7987:
1.843 bisitz 7988: ul.LC_funclist li {
1.915 droeschl 7989: display: inline;
1.782 bisitz 7990: white-space: nowrap;
1.915 droeschl 7991: margin: 0 0 0 25px;
7992: line-height: 150%;
1.782 bisitz 7993: }
7994:
1.974 wenzelju 7995: .LC_hidden {
7996: display: none;
7997: }
7998:
1.1030 www 7999: .LCmodal-overlay {
8000: position:fixed;
8001: top:0;
8002: right:0;
8003: bottom:0;
8004: left:0;
8005: height:100%;
8006: width:100%;
8007: margin:0;
8008: padding:0;
8009: background:#999;
8010: opacity:.75;
8011: filter: alpha(opacity=75);
8012: -moz-opacity: 0.75;
8013: z-index:101;
8014: }
8015:
8016: * html .LCmodal-overlay {
8017: position: absolute;
8018: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8019: }
8020:
8021: .LCmodal-window {
8022: position:fixed;
8023: top:50%;
8024: left:50%;
8025: margin:0;
8026: padding:0;
8027: z-index:102;
8028: }
8029:
8030: * html .LCmodal-window {
8031: position:absolute;
8032: }
8033:
8034: .LCclose-window {
8035: position:absolute;
8036: width:32px;
8037: height:32px;
8038: right:8px;
8039: top:8px;
8040: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8041: text-indent:-99999px;
8042: overflow:hidden;
8043: cursor:pointer;
8044: }
8045:
1.1100 raeburn 8046: /*
1.1231 damieng 8047: styles used for response display
8048: */
8049: div.LC_radiofoil, div.LC_rankfoil {
8050: margin: .5em 0em .5em 0em;
8051: }
8052: table.LC_itemgroup {
8053: margin-top: 1em;
8054: }
8055:
8056: /*
1.1100 raeburn 8057: styles used by TTH when "Default set of options to pass to tth/m
8058: when converting TeX" in course settings has been set
8059:
8060: option passed: -t
8061:
8062: */
8063:
8064: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8065: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8066: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8067: td div.norm {line-height:normal;}
8068:
8069: /*
8070: option passed -y3
8071: */
8072:
8073: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8074: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8075: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8076:
1.1230 damieng 8077: /*
8078: sections with roles, for content only
8079: */
8080: section[class^="role-"] {
8081: padding-left: 10px;
8082: padding-right: 5px;
8083: margin-top: 8px;
8084: margin-bottom: 8px;
8085: border: 1px solid #2A4;
8086: border-radius: 5px;
8087: box-shadow: 0px 1px 1px #BBB;
8088: }
8089: section[class^="role-"]>h1 {
8090: position: relative;
8091: margin: 0px;
8092: padding-top: 10px;
8093: padding-left: 40px;
8094: }
8095: section[class^="role-"]>h1:before {
8096: position: absolute;
8097: left: -5px;
8098: top: 5px;
8099: }
8100: section.role-activity>h1:before {
8101: content:url('/adm/daxe/images/section_icons/activity.png');
8102: }
8103: section.role-advice>h1:before {
8104: content:url('/adm/daxe/images/section_icons/advice.png');
8105: }
8106: section.role-bibliography>h1:before {
8107: content:url('/adm/daxe/images/section_icons/bibliography.png');
8108: }
8109: section.role-citation>h1:before {
8110: content:url('/adm/daxe/images/section_icons/citation.png');
8111: }
8112: section.role-conclusion>h1:before {
8113: content:url('/adm/daxe/images/section_icons/conclusion.png');
8114: }
8115: section.role-definition>h1:before {
8116: content:url('/adm/daxe/images/section_icons/definition.png');
8117: }
8118: section.role-demonstration>h1:before {
8119: content:url('/adm/daxe/images/section_icons/demonstration.png');
8120: }
8121: section.role-example>h1:before {
8122: content:url('/adm/daxe/images/section_icons/example.png');
8123: }
8124: section.role-explanation>h1:before {
8125: content:url('/adm/daxe/images/section_icons/explanation.png');
8126: }
8127: section.role-introduction>h1:before {
8128: content:url('/adm/daxe/images/section_icons/introduction.png');
8129: }
8130: section.role-method>h1:before {
8131: content:url('/adm/daxe/images/section_icons/method.png');
8132: }
8133: section.role-more_information>h1:before {
8134: content:url('/adm/daxe/images/section_icons/more_information.png');
8135: }
8136: section.role-objectives>h1:before {
8137: content:url('/adm/daxe/images/section_icons/objectives.png');
8138: }
8139: section.role-prerequisites>h1:before {
8140: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8141: }
8142: section.role-remark>h1:before {
8143: content:url('/adm/daxe/images/section_icons/remark.png');
8144: }
8145: section.role-reminder>h1:before {
8146: content:url('/adm/daxe/images/section_icons/reminder.png');
8147: }
8148: section.role-summary>h1:before {
8149: content:url('/adm/daxe/images/section_icons/summary.png');
8150: }
8151: section.role-syntax>h1:before {
8152: content:url('/adm/daxe/images/section_icons/syntax.png');
8153: }
8154: section.role-warning>h1:before {
8155: content:url('/adm/daxe/images/section_icons/warning.png');
8156: }
8157:
1.1269 raeburn 8158: #LC_minitab_header {
8159: float:left;
8160: width:100%;
8161: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8162: font-size:93%;
8163: line-height:normal;
8164: margin: 0.5em 0 0.5em 0;
8165: }
8166: #LC_minitab_header ul {
8167: margin:0;
8168: padding:10px 10px 0;
8169: list-style:none;
8170: }
8171: #LC_minitab_header li {
8172: float:left;
8173: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8174: margin:0;
8175: padding:0 0 0 9px;
8176: }
8177: #LC_minitab_header a {
8178: display:block;
8179: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8180: padding:5px 15px 4px 6px;
8181: }
8182: #LC_minitab_header #LC_current_minitab {
8183: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8184: }
8185: #LC_minitab_header #LC_current_minitab a {
8186: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8187: padding-bottom:5px;
8188: }
8189:
8190:
1.343 albertel 8191: END
8192: }
8193:
1.306 albertel 8194: =pod
8195:
8196: =item * &headtag()
8197:
8198: Returns a uniform footer for LON-CAPA web pages.
8199:
1.307 albertel 8200: Inputs: $title - optional title for the head
8201: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8202: $args - optional arguments
1.319 albertel 8203: force_register - if is true call registerurl so the remote is
8204: informed
1.415 albertel 8205: redirect -> array ref of
8206: 1- seconds before redirect occurs
8207: 2- url to redirect to
8208: 3- whether the side effect should occur
1.315 albertel 8209: (side effect of setting
8210: $env{'internal.head.redirect'} to the url
8211: redirected too)
1.352 albertel 8212: domain -> force to color decorate a page for a specific
8213: domain
8214: function -> force usage of a specific rolish color scheme
8215: bgcolor -> override the default page bgcolor
1.460 albertel 8216: no_auto_mt_title
8217: -> prevent &mt()ing the title arg
1.464 albertel 8218:
1.306 albertel 8219: =cut
8220:
8221: sub headtag {
1.313 albertel 8222: my ($title,$head_extra,$args) = @_;
1.306 albertel 8223:
1.363 albertel 8224: my $function = $args->{'function'} || &get_users_function();
8225: my $domain = $args->{'domain'} || &determinedomain();
8226: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8227: my $httphost = $args->{'use_absolute'};
1.418 albertel 8228: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8229: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8230: #time(),
1.418 albertel 8231: $env{'environment.color.timestamp'},
1.363 albertel 8232: $function,$domain,$bgcolor);
8233:
1.369 www 8234: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8235:
1.308 albertel 8236: my $result =
8237: '<head>'.
1.1160 raeburn 8238: &font_settings($args);
1.319 albertel 8239:
1.1188 raeburn 8240: my $inhibitprint;
8241: if ($args->{'print_suppress'}) {
8242: $inhibitprint = &print_suppression();
8243: }
1.1064 raeburn 8244:
1.461 albertel 8245: if (!$args->{'frameset'}) {
8246: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8247: }
1.962 droeschl 8248: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8249: $result .= Apache::lonxml::display_title();
1.319 albertel 8250: }
1.436 albertel 8251: if (!$args->{'no_nav_bar'}
8252: && !$args->{'only_body'}
8253: && !$args->{'frameset'}) {
1.1154 raeburn 8254: $result .= &help_menu_js($httphost);
1.1032 www 8255: $result.=&modal_window();
1.1038 www 8256: $result.=&togglebox_script();
1.1034 www 8257: $result.=&wishlist_window();
1.1041 www 8258: $result.=&LCprogressbarUpdate_script();
1.1034 www 8259: } else {
8260: if ($args->{'add_modal'}) {
8261: $result.=&modal_window();
8262: }
8263: if ($args->{'add_wishlist'}) {
8264: $result.=&wishlist_window();
8265: }
1.1038 www 8266: if ($args->{'add_togglebox'}) {
8267: $result.=&togglebox_script();
8268: }
1.1041 www 8269: if ($args->{'add_progressbar'}) {
8270: $result.=&LCprogressbarUpdate_script();
8271: }
1.436 albertel 8272: }
1.314 albertel 8273: if (ref($args->{'redirect'})) {
1.414 albertel 8274: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8275: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8276: if (!$inhibit_continue) {
8277: $env{'internal.head.redirect'} = $url;
8278: }
1.313 albertel 8279: $result.=<<ADDMETA
8280: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8281: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8282: ADDMETA
1.1210 raeburn 8283: } else {
8284: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8285: my $requrl = $env{'request.uri'};
8286: if ($requrl eq '') {
8287: $requrl = $ENV{'REQUEST_URI'};
8288: $requrl =~ s/\?.+$//;
8289: }
8290: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8291: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8292: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8293: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8294: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8295: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
8296: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8297: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8298: if ($domdefs{'offloadnow'}{$lonhost}) {
8299: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8300: if (($newserver) && ($newserver ne $lonhost)) {
8301: my $numsec = 5;
8302: my $timeout = $numsec * 1000;
8303: my ($newurl,$locknum,%locks,$msg);
8304: if ($env{'request.role.adv'}) {
8305: ($locknum,%locks) = &Apache::lonnet::get_locks();
8306: }
8307: my $disable_submit = 0;
8308: if ($requrl =~ /$LONCAPA::assess_re/) {
8309: $disable_submit = 1;
8310: }
8311: if ($locknum) {
8312: my @lockinfo = sort(values(%locks));
8313: $msg = &mt('Once the following tasks are complete: ')."\\n".
8314: join(", ",sort(values(%locks)))."\\n".
8315: &mt('your session will be transferred to a different server, after you click "Roles".');
8316: } else {
8317: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8318: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
8319: }
8320: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8321: $newurl = '/adm/switchserver?otherserver='.$newserver;
8322: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8323: $newurl .= '&role='.$env{'request.role'};
8324: }
8325: if ($env{'request.symb'}) {
8326: $newurl .= '&symb='.$env{'request.symb'};
8327: } else {
8328: $newurl .= '&origurl='.$requrl;
8329: }
8330: }
1.1222 damieng 8331: &js_escape(\$msg);
1.1210 raeburn 8332: $result.=<<OFFLOAD
8333: <meta http-equiv="pragma" content="no-cache" />
8334: <script type="text/javascript">
1.1215 raeburn 8335: // <![CDATA[
1.1210 raeburn 8336: function LC_Offload_Now() {
8337: var dest = "$newurl";
8338: if (dest != '') {
8339: window.location.href="$newurl";
8340: }
8341: }
1.1214 raeburn 8342: \$(document).ready(function () {
8343: window.alert('$msg');
8344: if ($disable_submit) {
1.1210 raeburn 8345: \$(".LC_hwk_submit").prop("disabled", true);
8346: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8347: }
8348: setTimeout('LC_Offload_Now()', $timeout);
8349: });
1.1215 raeburn 8350: // ]]>
1.1210 raeburn 8351: </script>
8352: OFFLOAD
8353: }
8354: }
8355: }
8356: }
8357: }
8358: }
1.313 albertel 8359: }
1.306 albertel 8360: if (!defined($title)) {
8361: $title = 'The LearningOnline Network with CAPA';
8362: }
1.460 albertel 8363: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8364: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8365: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8366: if (!$args->{'frameset'}) {
8367: $result .= ' /';
8368: }
8369: $result .= '>'
1.1064 raeburn 8370: .$inhibitprint
1.414 albertel 8371: .$head_extra;
1.1242 raeburn 8372: my $clientmobile;
8373: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8374: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8375: } else {
8376: $clientmobile = $env{'browser.mobile'};
8377: }
8378: if ($clientmobile) {
1.1137 raeburn 8379: $result .= '
8380: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8381: <meta name="apple-mobile-web-app-capable" content="yes" />';
8382: }
1.1278 raeburn 8383: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8384: return $result.'</head>';
1.306 albertel 8385: }
8386:
8387: =pod
8388:
1.340 albertel 8389: =item * &font_settings()
8390:
8391: Returns neccessary <meta> to set the proper encoding
8392:
1.1160 raeburn 8393: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8394:
8395: =cut
8396:
8397: sub font_settings {
1.1160 raeburn 8398: my ($args) = @_;
1.340 albertel 8399: my $headerstring='';
1.1160 raeburn 8400: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8401: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8402: $headerstring.=
8403: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8404: if (!$args->{'frameset'}) {
8405: $headerstring.= ' /';
8406: }
8407: $headerstring .= '>'."\n";
1.340 albertel 8408: }
8409: return $headerstring;
8410: }
8411:
1.341 albertel 8412: =pod
8413:
1.1064 raeburn 8414: =item * &print_suppression()
8415:
8416: In course context returns css which causes the body to be blank when media="print",
8417: if printout generation is unavailable for the current resource.
8418:
8419: This could be because:
8420:
8421: (a) printstartdate is in the future
8422:
8423: (b) printenddate is in the past
8424:
8425: (c) there is an active exam block with "printout"
8426: functionality blocked
8427:
8428: Users with pav, pfo or evb privileges are exempt.
8429:
8430: Inputs: none
8431:
8432: =cut
8433:
8434:
8435: sub print_suppression {
8436: my $noprint;
8437: if ($env{'request.course.id'}) {
8438: my $scope = $env{'request.course.id'};
8439: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8440: (&Apache::lonnet::allowed('pfo',$scope))) {
8441: return;
8442: }
8443: if ($env{'request.course.sec'} ne '') {
8444: $scope .= "/$env{'request.course.sec'}";
8445: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8446: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8447: return;
1.1064 raeburn 8448: }
8449: }
8450: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8451: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8452: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8453: if ($blocked) {
8454: my $checkrole = "cm./$cdom/$cnum";
8455: if ($env{'request.course.sec'} ne '') {
8456: $checkrole .= "/$env{'request.course.sec'}";
8457: }
8458: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8459: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8460: $noprint = 1;
8461: }
8462: }
8463: unless ($noprint) {
8464: my $symb = &Apache::lonnet::symbread();
8465: if ($symb ne '') {
8466: my $navmap = Apache::lonnavmaps::navmap->new();
8467: if (ref($navmap)) {
8468: my $res = $navmap->getBySymb($symb);
8469: if (ref($res)) {
8470: if (!$res->resprintable()) {
8471: $noprint = 1;
8472: }
8473: }
8474: }
8475: }
8476: }
8477: if ($noprint) {
8478: return <<"ENDSTYLE";
8479: <style type="text/css" media="print">
8480: body { display:none }
8481: </style>
8482: ENDSTYLE
8483: }
8484: }
8485: return;
8486: }
8487:
8488: =pod
8489:
1.341 albertel 8490: =item * &xml_begin()
8491:
8492: Returns the needed doctype and <html>
8493:
8494: Inputs: none
8495:
8496: =cut
8497:
8498: sub xml_begin {
1.1168 raeburn 8499: my ($is_frameset) = @_;
1.341 albertel 8500: my $output='';
8501:
8502: if ($env{'browser.mathml'}) {
8503: $output='<?xml version="1.0"?>'
8504: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8505: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8506:
8507: # .'<!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">] >'
8508: .'<!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">'
8509: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8510: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8511: } elsif ($is_frameset) {
8512: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8513: '<html>'."\n";
1.341 albertel 8514: } else {
1.1168 raeburn 8515: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8516: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8517: }
8518: return $output;
8519: }
1.340 albertel 8520:
8521: =pod
8522:
1.306 albertel 8523: =item * &start_page()
8524:
8525: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8526:
1.648 raeburn 8527: Inputs:
8528:
8529: =over 4
8530:
8531: $title - optional title for the page
8532:
8533: $head_extra - optional extra HTML to incude inside the <head>
8534:
8535: $args - additional optional args supported are:
8536:
8537: =over 8
8538:
8539: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8540: arg on
1.814 bisitz 8541: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8542: add_entries -> additional attributes to add to the <body>
8543: domain -> force to color decorate a page for a
1.317 albertel 8544: specific domain
1.648 raeburn 8545: function -> force usage of a specific rolish color
1.317 albertel 8546: scheme
1.648 raeburn 8547: redirect -> see &headtag()
8548: bgcolor -> override the default page bg color
8549: js_ready -> return a string ready for being used in
1.317 albertel 8550: a javascript writeln
1.648 raeburn 8551: html_encode -> return a string ready for being used in
1.320 albertel 8552: a html attribute
1.648 raeburn 8553: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8554: $forcereg arg
1.648 raeburn 8555: frameset -> if true will start with a <frameset>
1.330 albertel 8556: rather than <body>
1.648 raeburn 8557: skip_phases -> hash ref of
1.338 albertel 8558: head -> skip the <html><head> generation
8559: body -> skip all <body> generation
1.648 raeburn 8560: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8561: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8562: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8563: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8564: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8565: group -> includes the current group, if page is for a
1.1274 raeburn 8566: specific group
8567: use_absolute -> for request for external resource or syllabus, this
8568: will contain https://<hostname> if server uses
8569: https (as per hosts.tab), but request is for http
8570: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8571:
1.648 raeburn 8572: =back
1.460 albertel 8573:
1.648 raeburn 8574: =back
1.562 albertel 8575:
1.306 albertel 8576: =cut
8577:
8578: sub start_page {
1.309 albertel 8579: my ($title,$head_extra,$args) = @_;
1.318 albertel 8580: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8581:
1.315 albertel 8582: $env{'internal.start_page'}++;
1.1096 raeburn 8583: my ($result,@advtools);
1.964 droeschl 8584:
1.338 albertel 8585: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8586: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8587: }
8588:
8589: if (! exists($args->{'skip_phases'}{'body'}) ) {
8590: if ($args->{'frameset'}) {
8591: my $attr_string = &make_attr_string($args->{'force_register'},
8592: $args->{'add_entries'});
8593: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8594: } else {
8595: $result .=
8596: &bodytag($title,
8597: $args->{'function'}, $args->{'add_entries'},
8598: $args->{'only_body'}, $args->{'domain'},
8599: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8600: $args->{'bgcolor'}, $args,
8601: \@advtools);
1.831 bisitz 8602: }
1.330 albertel 8603: }
1.338 albertel 8604:
1.315 albertel 8605: if ($args->{'js_ready'}) {
1.713 kaisler 8606: $result = &js_ready($result);
1.315 albertel 8607: }
1.320 albertel 8608: if ($args->{'html_encode'}) {
1.713 kaisler 8609: $result = &html_encode($result);
8610: }
8611:
1.813 bisitz 8612: # Preparation for new and consistent functionlist at top of screen
8613: # if ($args->{'functionlist'}) {
8614: # $result .= &build_functionlist();
8615: #}
8616:
1.964 droeschl 8617: # Don't add anything more if only_body wanted or in const space
8618: return $result if $args->{'only_body'}
8619: || $env{'request.state'} eq 'construct';
1.813 bisitz 8620:
8621: #Breadcrumbs
1.758 kaisler 8622: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8623: &Apache::lonhtmlcommon::clear_breadcrumbs();
8624: #if any br links exists, add them to the breadcrumbs
8625: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8626: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8627: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8628: }
8629: }
1.1096 raeburn 8630: # if @advtools array contains items add then to the breadcrumbs
8631: if (@advtools > 0) {
8632: &Apache::lonmenu::advtools_crumbs(@advtools);
8633: }
1.1272 raeburn 8634: my $menulink;
8635: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8636: if ((exists($args->{'bread_crumbs_nomenu'})) ||
8637: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
8638: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
8639: (!$env{'request.role.adv'}))) {
8640: $menulink = 0;
8641: } else {
8642: undef($menulink);
8643: }
1.758 kaisler 8644: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8645: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 8646: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 8647: } else {
1.1272 raeburn 8648: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8649: }
1.320 albertel 8650: }
1.315 albertel 8651: return $result;
1.306 albertel 8652: }
8653:
8654: sub end_page {
1.315 albertel 8655: my ($args) = @_;
8656: $env{'internal.end_page'}++;
1.330 albertel 8657: my $result;
1.335 albertel 8658: if ($args->{'discussion'}) {
8659: my ($target,$parser);
8660: if (ref($args->{'discussion'})) {
8661: ($target,$parser) =($args->{'discussion'}{'target'},
8662: $args->{'discussion'}{'parser'});
8663: }
8664: $result .= &Apache::lonxml::xmlend($target,$parser);
8665: }
1.330 albertel 8666: if ($args->{'frameset'}) {
8667: $result .= '</frameset>';
8668: } else {
1.635 raeburn 8669: $result .= &endbodytag($args);
1.330 albertel 8670: }
1.1080 raeburn 8671: unless ($args->{'notbody'}) {
8672: $result .= "\n</html>";
8673: }
1.330 albertel 8674:
1.315 albertel 8675: if ($args->{'js_ready'}) {
1.317 albertel 8676: $result = &js_ready($result);
1.315 albertel 8677: }
1.335 albertel 8678:
1.320 albertel 8679: if ($args->{'html_encode'}) {
8680: $result = &html_encode($result);
8681: }
1.335 albertel 8682:
1.315 albertel 8683: return $result;
8684: }
8685:
1.1034 www 8686: sub wishlist_window {
8687: return(<<'ENDWISHLIST');
1.1046 raeburn 8688: <script type="text/javascript">
1.1034 www 8689: // <![CDATA[
8690: // <!-- BEGIN LON-CAPA Internal
8691: function set_wishlistlink(title, path) {
8692: if (!title) {
8693: title = document.title;
8694: title = title.replace(/^LON-CAPA /,'');
8695: }
1.1175 raeburn 8696: title = encodeURIComponent(title);
1.1203 raeburn 8697: title = title.replace("'","\\\'");
1.1034 www 8698: if (!path) {
8699: path = location.pathname;
8700: }
1.1175 raeburn 8701: path = encodeURIComponent(path);
1.1203 raeburn 8702: path = path.replace("'","\\\'");
1.1034 www 8703: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8704: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8705: }
8706: // END LON-CAPA Internal -->
8707: // ]]>
8708: </script>
8709: ENDWISHLIST
8710: }
8711:
1.1030 www 8712: sub modal_window {
8713: return(<<'ENDMODAL');
1.1046 raeburn 8714: <script type="text/javascript">
1.1030 www 8715: // <![CDATA[
8716: // <!-- BEGIN LON-CAPA Internal
8717: var modalWindow = {
8718: parent:"body",
8719: windowId:null,
8720: content:null,
8721: width:null,
8722: height:null,
8723: close:function()
8724: {
8725: $(".LCmodal-window").remove();
8726: $(".LCmodal-overlay").remove();
8727: },
8728: open:function()
8729: {
8730: var modal = "";
8731: modal += "<div class=\"LCmodal-overlay\"></div>";
8732: 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;\">";
8733: modal += this.content;
8734: modal += "</div>";
8735:
8736: $(this.parent).append(modal);
8737:
8738: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8739: $(".LCclose-window").click(function(){modalWindow.close();});
8740: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8741: }
8742: };
1.1140 raeburn 8743: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8744: {
1.1266 raeburn 8745: source = source.replace(/'/g,"'");
1.1030 www 8746: modalWindow.windowId = "myModal";
8747: modalWindow.width = width;
8748: modalWindow.height = height;
1.1196 raeburn 8749: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8750: modalWindow.open();
1.1208 raeburn 8751: };
1.1030 www 8752: // END LON-CAPA Internal -->
8753: // ]]>
8754: </script>
8755: ENDMODAL
8756: }
8757:
8758: sub modal_link {
1.1140 raeburn 8759: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8760: unless ($width) { $width=480; }
8761: unless ($height) { $height=400; }
1.1031 www 8762: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8763: unless ($transparency) { $transparency='true'; }
8764:
1.1074 raeburn 8765: my $target_attr;
8766: if (defined($target)) {
8767: $target_attr = 'target="'.$target.'"';
8768: }
8769: return <<"ENDLINK";
1.1140 raeburn 8770: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8771: $linktext</a>
8772: ENDLINK
1.1030 www 8773: }
8774:
1.1032 www 8775: sub modal_adhoc_script {
8776: my ($funcname,$width,$height,$content)=@_;
8777: return (<<ENDADHOC);
1.1046 raeburn 8778: <script type="text/javascript">
1.1032 www 8779: // <![CDATA[
8780: var $funcname = function()
8781: {
8782: modalWindow.windowId = "myModal";
8783: modalWindow.width = $width;
8784: modalWindow.height = $height;
8785: modalWindow.content = '$content';
8786: modalWindow.open();
8787: };
8788: // ]]>
8789: </script>
8790: ENDADHOC
8791: }
8792:
1.1041 www 8793: sub modal_adhoc_inner {
8794: my ($funcname,$width,$height,$content)=@_;
8795: my $innerwidth=$width-20;
8796: $content=&js_ready(
1.1140 raeburn 8797: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8798: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8799: $content.
1.1041 www 8800: &end_scrollbox().
1.1140 raeburn 8801: &end_page()
1.1041 www 8802: );
8803: return &modal_adhoc_script($funcname,$width,$height,$content);
8804: }
8805:
8806: sub modal_adhoc_window {
8807: my ($funcname,$width,$height,$content,$linktext)=@_;
8808: return &modal_adhoc_inner($funcname,$width,$height,$content).
8809: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8810: }
8811:
8812: sub modal_adhoc_launch {
8813: my ($funcname,$width,$height,$content)=@_;
8814: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8815: <script type="text/javascript">
8816: // <![CDATA[
8817: $funcname();
8818: // ]]>
8819: </script>
8820: ENDLAUNCH
8821: }
8822:
8823: sub modal_adhoc_close {
8824: return (<<ENDCLOSE);
8825: <script type="text/javascript">
8826: // <![CDATA[
8827: modalWindow.close();
8828: // ]]>
8829: </script>
8830: ENDCLOSE
8831: }
8832:
1.1038 www 8833: sub togglebox_script {
8834: return(<<ENDTOGGLE);
8835: <script type="text/javascript">
8836: // <![CDATA[
8837: function LCtoggleDisplay(id,hidetext,showtext) {
8838: link = document.getElementById(id + "link").childNodes[0];
8839: with (document.getElementById(id).style) {
8840: if (display == "none" ) {
8841: display = "inline";
8842: link.nodeValue = hidetext;
8843: } else {
8844: display = "none";
8845: link.nodeValue = showtext;
8846: }
8847: }
8848: }
8849: // ]]>
8850: </script>
8851: ENDTOGGLE
8852: }
8853:
1.1039 www 8854: sub start_togglebox {
8855: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8856: unless ($heading) { $heading=''; } else { $heading.=' '; }
8857: unless ($showtext) { $showtext=&mt('show'); }
8858: unless ($hidetext) { $hidetext=&mt('hide'); }
8859: unless ($headerbg) { $headerbg='#FFFFFF'; }
8860: return &start_data_table().
8861: &start_data_table_header_row().
8862: '<td bgcolor="'.$headerbg.'">'.$heading.
8863: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8864: $showtext.'\')">'.$showtext.'</a>]</td>'.
8865: &end_data_table_header_row().
8866: '<tr id="'.$id.'" style="display:none""><td>';
8867: }
8868:
8869: sub end_togglebox {
8870: return '</td></tr>'.&end_data_table();
8871: }
8872:
1.1041 www 8873: sub LCprogressbar_script {
1.1045 www 8874: my ($id)=@_;
1.1041 www 8875: return(<<ENDPROGRESS);
8876: <script type="text/javascript">
8877: // <![CDATA[
1.1045 www 8878: \$('#progressbar$id').progressbar({
1.1041 www 8879: value: 0,
8880: change: function(event, ui) {
8881: var newVal = \$(this).progressbar('option', 'value');
8882: \$('.pblabel', this).text(LCprogressTxt);
8883: }
8884: });
8885: // ]]>
8886: </script>
8887: ENDPROGRESS
8888: }
8889:
8890: sub LCprogressbarUpdate_script {
8891: return(<<ENDPROGRESSUPDATE);
8892: <style type="text/css">
8893: .ui-progressbar { position:relative; }
8894: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8895: </style>
8896: <script type="text/javascript">
8897: // <![CDATA[
1.1045 www 8898: var LCprogressTxt='---';
8899:
8900: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8901: LCprogressTxt=progresstext;
1.1045 www 8902: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8903: }
8904: // ]]>
8905: </script>
8906: ENDPROGRESSUPDATE
8907: }
8908:
1.1042 www 8909: my $LClastpercent;
1.1045 www 8910: my $LCidcnt;
8911: my $LCcurrentid;
1.1042 www 8912:
1.1041 www 8913: sub LCprogressbar {
1.1042 www 8914: my ($r)=(@_);
8915: $LClastpercent=0;
1.1045 www 8916: $LCidcnt++;
8917: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8918: my $starting=&mt('Starting');
8919: my $content=(<<ENDPROGBAR);
1.1045 www 8920: <div id="progressbar$LCcurrentid">
1.1041 www 8921: <span class="pblabel">$starting</span>
8922: </div>
8923: ENDPROGBAR
1.1045 www 8924: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8925: }
8926:
8927: sub LCprogressbarUpdate {
1.1042 www 8928: my ($r,$val,$text)=@_;
8929: unless ($val) {
8930: if ($LClastpercent) {
8931: $val=$LClastpercent;
8932: } else {
8933: $val=0;
8934: }
8935: }
1.1041 www 8936: if ($val<0) { $val=0; }
8937: if ($val>100) { $val=0; }
1.1042 www 8938: $LClastpercent=$val;
1.1041 www 8939: unless ($text) { $text=$val.'%'; }
8940: $text=&js_ready($text);
1.1044 www 8941: &r_print($r,<<ENDUPDATE);
1.1041 www 8942: <script type="text/javascript">
8943: // <![CDATA[
1.1045 www 8944: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8945: // ]]>
8946: </script>
8947: ENDUPDATE
1.1035 www 8948: }
8949:
1.1042 www 8950: sub LCprogressbarClose {
8951: my ($r)=@_;
8952: $LClastpercent=0;
1.1044 www 8953: &r_print($r,<<ENDCLOSE);
1.1042 www 8954: <script type="text/javascript">
8955: // <![CDATA[
1.1045 www 8956: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8957: // ]]>
8958: </script>
8959: ENDCLOSE
1.1044 www 8960: }
8961:
8962: sub r_print {
8963: my ($r,$to_print)=@_;
8964: if ($r) {
8965: $r->print($to_print);
8966: $r->rflush();
8967: } else {
8968: print($to_print);
8969: }
1.1042 www 8970: }
8971:
1.320 albertel 8972: sub html_encode {
8973: my ($result) = @_;
8974:
1.322 albertel 8975: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8976:
8977: return $result;
8978: }
1.1044 www 8979:
1.317 albertel 8980: sub js_ready {
8981: my ($result) = @_;
8982:
1.323 albertel 8983: $result =~ s/[\n\r]/ /xmsg;
8984: $result =~ s/\\/\\\\/xmsg;
8985: $result =~ s/'/\\'/xmsg;
1.372 albertel 8986: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8987:
8988: return $result;
8989: }
8990:
1.315 albertel 8991: sub validate_page {
8992: if ( exists($env{'internal.start_page'})
1.316 albertel 8993: && $env{'internal.start_page'} > 1) {
8994: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8995: $env{'internal.start_page'}.' '.
1.316 albertel 8996: $ENV{'request.filename'});
1.315 albertel 8997: }
8998: if ( exists($env{'internal.end_page'})
1.316 albertel 8999: && $env{'internal.end_page'} > 1) {
9000: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9001: $env{'internal.end_page'}.' '.
1.316 albertel 9002: $env{'request.filename'});
1.315 albertel 9003: }
9004: if ( exists($env{'internal.start_page'})
9005: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9006: &Apache::lonnet::logthis('start_page called without end_page '.
9007: $env{'request.filename'});
1.315 albertel 9008: }
9009: if ( ! exists($env{'internal.start_page'})
9010: && exists($env{'internal.end_page'})) {
1.316 albertel 9011: &Apache::lonnet::logthis('end_page called without start_page'.
9012: $env{'request.filename'});
1.315 albertel 9013: }
1.306 albertel 9014: }
1.315 albertel 9015:
1.996 www 9016:
9017: sub start_scrollbox {
1.1140 raeburn 9018: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9019: unless ($outerwidth) { $outerwidth='520px'; }
9020: unless ($width) { $width='500px'; }
9021: unless ($height) { $height='200px'; }
1.1075 raeburn 9022: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9023: if ($id ne '') {
1.1140 raeburn 9024: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9025: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9026: }
1.1075 raeburn 9027: if ($bgcolor ne '') {
9028: $tdcol = "background-color: $bgcolor;";
9029: }
1.1137 raeburn 9030: my $nicescroll_js;
9031: if ($env{'browser.mobile'}) {
1.1140 raeburn 9032: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9033: }
9034: return <<"END";
9035: $nicescroll_js
9036:
9037: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9038: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9039: END
9040: }
9041:
9042: sub end_scrollbox {
9043: return '</div></td></tr></table>';
9044: }
9045:
9046: sub nicescroll_javascript {
9047: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9048: my %options;
9049: if (ref($cursor) eq 'HASH') {
9050: %options = %{$cursor};
9051: }
9052: unless ($options{'railalign'} =~ /^left|right$/) {
9053: $options{'railalign'} = 'left';
9054: }
9055: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9056: my $function = &get_users_function();
9057: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9058: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9059: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9060: }
1.1140 raeburn 9061: }
9062: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9063: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9064: $options{'cursoropacity'}='1.0';
9065: }
1.1140 raeburn 9066: } else {
9067: $options{'cursoropacity'}='1.0';
9068: }
9069: if ($options{'cursorfixedheight'} eq 'none') {
9070: delete($options{'cursorfixedheight'});
9071: } else {
9072: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9073: }
9074: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9075: delete($options{'railoffset'});
9076: }
9077: my @niceoptions;
9078: while (my($key,$value) = each(%options)) {
9079: if ($value =~ /^\{.+\}$/) {
9080: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9081: } else {
1.1140 raeburn 9082: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9083: }
1.1140 raeburn 9084: }
9085: my $nicescroll_js = '
1.1137 raeburn 9086: $(document).ready(
1.1140 raeburn 9087: function() {
9088: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9089: }
1.1137 raeburn 9090: );
9091: ';
1.1140 raeburn 9092: if ($framecheck) {
9093: $nicescroll_js .= '
9094: function expand_div(caller) {
9095: if (top === self) {
9096: document.getElementById("'.$id.'").style.width = "auto";
9097: document.getElementById("'.$id.'").style.height = "auto";
9098: } else {
9099: try {
9100: if (parent.frames) {
9101: if (parent.frames.length > 1) {
9102: var framesrc = parent.frames[1].location.href;
9103: var currsrc = framesrc.replace(/\#.*$/,"");
9104: if ((caller == "search") || (currsrc == "'.$location.'")) {
9105: document.getElementById("'.$id.'").style.width = "auto";
9106: document.getElementById("'.$id.'").style.height = "auto";
9107: }
9108: }
9109: }
9110: } catch (e) {
9111: return;
9112: }
1.1137 raeburn 9113: }
1.1140 raeburn 9114: return;
1.996 www 9115: }
1.1140 raeburn 9116: ';
9117: }
9118: if ($needjsready) {
9119: $nicescroll_js = '
9120: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9121: } else {
9122: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9123: }
9124: return $nicescroll_js;
1.996 www 9125: }
9126:
1.318 albertel 9127: sub simple_error_page {
1.1150 bisitz 9128: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 9129: if (ref($args) eq 'HASH') {
9130: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
9131: } else {
9132: $msg = &mt($msg);
9133: }
1.1150 bisitz 9134:
1.318 albertel 9135: my $page =
9136: &Apache::loncommon::start_page($title).
1.1150 bisitz 9137: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9138: &Apache::loncommon::end_page();
9139: if (ref($r)) {
9140: $r->print($page);
1.327 albertel 9141: return;
1.318 albertel 9142: }
9143: return $page;
9144: }
1.347 albertel 9145:
9146: {
1.610 albertel 9147: my @row_count;
1.961 onken 9148:
9149: sub start_data_table_count {
9150: unshift(@row_count, 0);
9151: return;
9152: }
9153:
9154: sub end_data_table_count {
9155: shift(@row_count);
9156: return;
9157: }
9158:
1.347 albertel 9159: sub start_data_table {
1.1018 raeburn 9160: my ($add_class,$id) = @_;
1.422 albertel 9161: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9162: my $table_id;
9163: if (defined($id)) {
9164: $table_id = ' id="'.$id.'"';
9165: }
1.961 onken 9166: &start_data_table_count();
1.1018 raeburn 9167: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9168: }
9169:
9170: sub end_data_table {
1.961 onken 9171: &end_data_table_count();
1.389 albertel 9172: return '</table>'."\n";;
1.347 albertel 9173: }
9174:
9175: sub start_data_table_row {
1.974 wenzelju 9176: my ($add_class, $id) = @_;
1.610 albertel 9177: $row_count[0]++;
9178: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9179: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9180: $id = (' id="'.$id.'"') unless ($id eq '');
9181: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9182: }
1.471 banghart 9183:
9184: sub continue_data_table_row {
1.974 wenzelju 9185: my ($add_class, $id) = @_;
1.610 albertel 9186: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9187: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9188: $id = (' id="'.$id.'"') unless ($id eq '');
9189: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9190: }
1.347 albertel 9191:
9192: sub end_data_table_row {
1.389 albertel 9193: return '</tr>'."\n";;
1.347 albertel 9194: }
1.367 www 9195:
1.421 albertel 9196: sub start_data_table_empty_row {
1.707 bisitz 9197: # $row_count[0]++;
1.421 albertel 9198: return '<tr class="LC_empty_row" >'."\n";;
9199: }
9200:
9201: sub end_data_table_empty_row {
9202: return '</tr>'."\n";;
9203: }
9204:
1.367 www 9205: sub start_data_table_header_row {
1.389 albertel 9206: return '<tr class="LC_header_row">'."\n";;
1.367 www 9207: }
9208:
9209: sub end_data_table_header_row {
1.389 albertel 9210: return '</tr>'."\n";;
1.367 www 9211: }
1.890 droeschl 9212:
9213: sub data_table_caption {
9214: my $caption = shift;
9215: return "<caption class=\"LC_caption\">$caption</caption>";
9216: }
1.347 albertel 9217: }
9218:
1.548 albertel 9219: =pod
9220:
9221: =item * &inhibit_menu_check($arg)
9222:
9223: Checks for a inhibitmenu state and generates output to preserve it
9224:
9225: Inputs: $arg - can be any of
9226: - undef - in which case the return value is a string
9227: to add into arguments list of a uri
9228: - 'input' - in which case the return value is a HTML
9229: <form> <input> field of type hidden to
9230: preserve the value
9231: - a url - in which case the return value is the url with
9232: the neccesary cgi args added to preserve the
9233: inhibitmenu state
9234: - a ref to a url - no return value, but the string is
9235: updated to include the neccessary cgi
9236: args to preserve the inhibitmenu state
9237:
9238: =cut
9239:
9240: sub inhibit_menu_check {
9241: my ($arg) = @_;
9242: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9243: if ($arg eq 'input') {
9244: if ($env{'form.inhibitmenu'}) {
9245: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9246: } else {
9247: return
9248: }
9249: }
9250: if ($env{'form.inhibitmenu'}) {
9251: if (ref($arg)) {
9252: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9253: } elsif ($arg eq '') {
9254: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9255: } else {
9256: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9257: }
9258: }
9259: if (!ref($arg)) {
9260: return $arg;
9261: }
9262: }
9263:
1.251 albertel 9264: ###############################################
1.182 matthew 9265:
9266: =pod
9267:
1.549 albertel 9268: =back
9269:
9270: =head1 User Information Routines
9271:
9272: =over 4
9273:
1.405 albertel 9274: =item * &get_users_function()
1.182 matthew 9275:
9276: Used by &bodytag to determine the current users primary role.
9277: Returns either 'student','coordinator','admin', or 'author'.
9278:
9279: =cut
9280:
9281: ###############################################
9282: sub get_users_function {
1.815 tempelho 9283: my $function = 'norole';
1.818 tempelho 9284: if ($env{'request.role'}=~/^(st)/) {
9285: $function='student';
9286: }
1.907 raeburn 9287: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9288: $function='coordinator';
9289: }
1.258 albertel 9290: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9291: $function='admin';
9292: }
1.826 bisitz 9293: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9294: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9295: $function='author';
9296: }
9297: return $function;
1.54 www 9298: }
1.99 www 9299:
9300: ###############################################
9301:
1.233 raeburn 9302: =pod
9303:
1.821 raeburn 9304: =item * &show_course()
9305:
9306: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9307: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9308:
9309: Inputs:
9310: None
9311:
9312: Outputs:
9313: Scalar: 1 if 'Course' to be used, 0 otherwise.
9314:
9315: =cut
9316:
9317: ###############################################
9318: sub show_course {
9319: my $course = !$env{'user.adv'};
9320: if (!$env{'user.adv'}) {
9321: foreach my $env (keys(%env)) {
9322: next if ($env !~ m/^user\.priv\./);
9323: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9324: $course = 0;
9325: last;
9326: }
9327: }
9328: }
9329: return $course;
9330: }
9331:
9332: ###############################################
9333:
9334: =pod
9335:
1.542 raeburn 9336: =item * &check_user_status()
1.274 raeburn 9337:
9338: Determines current status of supplied role for a
9339: specific user. Roles can be active, previous or future.
9340:
9341: Inputs:
9342: user's domain, user's username, course's domain,
1.375 raeburn 9343: course's number, optional section ID.
1.274 raeburn 9344:
9345: Outputs:
9346: role status: active, previous or future.
9347:
9348: =cut
9349:
9350: sub check_user_status {
1.412 raeburn 9351: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9352: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9353: my @uroles = keys(%userinfo);
1.274 raeburn 9354: my $srchstr;
9355: my $active_chk = 'none';
1.412 raeburn 9356: my $now = time;
1.274 raeburn 9357: if (@uroles > 0) {
1.908 raeburn 9358: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9359: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9360: } else {
1.412 raeburn 9361: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9362: }
9363: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9364: my $role_end = 0;
9365: my $role_start = 0;
9366: $active_chk = 'active';
1.412 raeburn 9367: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9368: $role_end = $1;
9369: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9370: $role_start = $1;
1.274 raeburn 9371: }
9372: }
9373: if ($role_start > 0) {
1.412 raeburn 9374: if ($now < $role_start) {
1.274 raeburn 9375: $active_chk = 'future';
9376: }
9377: }
9378: if ($role_end > 0) {
1.412 raeburn 9379: if ($now > $role_end) {
1.274 raeburn 9380: $active_chk = 'previous';
9381: }
9382: }
9383: }
9384: }
9385: return $active_chk;
9386: }
9387:
9388: ###############################################
9389:
9390: =pod
9391:
1.405 albertel 9392: =item * &get_sections()
1.233 raeburn 9393:
9394: Determines all the sections for a course including
9395: sections with students and sections containing other roles.
1.419 raeburn 9396: Incoming parameters:
9397:
9398: 1. domain
9399: 2. course number
9400: 3. reference to array containing roles for which sections should
9401: be gathered (optional).
9402: 4. reference to array containing status types for which sections
9403: should be gathered (optional).
9404:
9405: If the third argument is undefined, sections are gathered for any role.
9406: If the fourth argument is undefined, sections are gathered for any status.
9407: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9408:
1.374 raeburn 9409: Returns section hash (keys are section IDs, values are
9410: number of users in each section), subject to the
1.419 raeburn 9411: optional roles filter, optional status filter
1.233 raeburn 9412:
9413: =cut
9414:
9415: ###############################################
9416: sub get_sections {
1.419 raeburn 9417: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9418: if (!defined($cdom) || !defined($cnum)) {
9419: my $cid = $env{'request.course.id'};
9420:
9421: return if (!defined($cid));
9422:
9423: $cdom = $env{'course.'.$cid.'.domain'};
9424: $cnum = $env{'course.'.$cid.'.num'};
9425: }
9426:
9427: my %sectioncount;
1.419 raeburn 9428: my $now = time;
1.240 albertel 9429:
1.1118 raeburn 9430: my $check_students = 1;
9431: my $only_students = 0;
9432: if (ref($possible_roles) eq 'ARRAY') {
9433: if (grep(/^st$/,@{$possible_roles})) {
9434: if (@{$possible_roles} == 1) {
9435: $only_students = 1;
9436: }
9437: } else {
9438: $check_students = 0;
9439: }
9440: }
9441:
9442: if ($check_students) {
1.276 albertel 9443: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9444: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9445: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9446: my $start_index = &Apache::loncoursedata::CL_START();
9447: my $end_index = &Apache::loncoursedata::CL_END();
9448: my $status;
1.366 albertel 9449: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9450: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9451: $data->[$status_index],
9452: $data->[$start_index],
9453: $data->[$end_index]);
9454: if ($stu_status eq 'Active') {
9455: $status = 'active';
9456: } elsif ($end < $now) {
9457: $status = 'previous';
9458: } elsif ($start > $now) {
9459: $status = 'future';
9460: }
9461: if ($section ne '-1' && $section !~ /^\s*$/) {
9462: if ((!defined($possible_status)) || (($status ne '') &&
9463: (grep/^\Q$status\E$/,@{$possible_status}))) {
9464: $sectioncount{$section}++;
9465: }
1.240 albertel 9466: }
9467: }
9468: }
1.1118 raeburn 9469: if ($only_students) {
9470: return %sectioncount;
9471: }
1.240 albertel 9472: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9473: foreach my $user (sort(keys(%courseroles))) {
9474: if ($user !~ /^(\w{2})/) { next; }
9475: my ($role) = ($user =~ /^(\w{2})/);
9476: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9477: my ($section,$status);
1.240 albertel 9478: if ($role eq 'cr' &&
9479: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9480: $section=$1;
9481: }
9482: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9483: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9484: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9485: if ($end == -1 && $start == -1) {
9486: next; #deleted role
9487: }
9488: if (!defined($possible_status)) {
9489: $sectioncount{$section}++;
9490: } else {
9491: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9492: $status = 'active';
9493: } elsif ($end < $now) {
9494: $status = 'future';
9495: } elsif ($start > $now) {
9496: $status = 'previous';
9497: }
9498: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9499: $sectioncount{$section}++;
9500: }
9501: }
1.233 raeburn 9502: }
1.366 albertel 9503: return %sectioncount;
1.233 raeburn 9504: }
9505:
1.274 raeburn 9506: ###############################################
1.294 raeburn 9507:
9508: =pod
1.405 albertel 9509:
9510: =item * &get_course_users()
9511:
1.275 raeburn 9512: Retrieves usernames:domains for users in the specified course
9513: with specific role(s), and access status.
9514:
9515: Incoming parameters:
1.277 albertel 9516: 1. course domain
9517: 2. course number
9518: 3. access status: users must have - either active,
1.275 raeburn 9519: previous, future, or all.
1.277 albertel 9520: 4. reference to array of permissible roles
1.288 raeburn 9521: 5. reference to array of section restrictions (optional)
9522: 6. reference to results object (hash of hashes).
9523: 7. reference to optional userdata hash
1.609 raeburn 9524: 8. reference to optional statushash
1.630 raeburn 9525: 9. flag if privileged users (except those set to unhide in
9526: course settings) should be excluded
1.609 raeburn 9527: Keys of top level results hash are roles.
1.275 raeburn 9528: Keys of inner hashes are username:domain, with
9529: values set to access type.
1.288 raeburn 9530: Optional userdata hash returns an array with arguments in the
9531: same order as loncoursedata::get_classlist() for student data.
9532:
1.609 raeburn 9533: Optional statushash returns
9534:
1.288 raeburn 9535: Entries for end, start, section and status are blank because
9536: of the possibility of multiple values for non-student roles.
9537:
1.275 raeburn 9538: =cut
1.405 albertel 9539:
1.275 raeburn 9540: ###############################################
1.405 albertel 9541:
1.275 raeburn 9542: sub get_course_users {
1.630 raeburn 9543: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9544: my %idx = ();
1.419 raeburn 9545: my %seclists;
1.288 raeburn 9546:
9547: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9548: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9549: $idx{end} = &Apache::loncoursedata::CL_END();
9550: $idx{start} = &Apache::loncoursedata::CL_START();
9551: $idx{id} = &Apache::loncoursedata::CL_ID();
9552: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9553: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9554: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9555:
1.290 albertel 9556: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9557: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9558: my $now = time;
1.277 albertel 9559: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9560: my $match = 0;
1.412 raeburn 9561: my $secmatch = 0;
1.419 raeburn 9562: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9563: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9564: if ($section eq '') {
9565: $section = 'none';
9566: }
1.291 albertel 9567: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9568: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9569: $secmatch = 1;
9570: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9571: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9572: $secmatch = 1;
9573: }
9574: } else {
1.419 raeburn 9575: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9576: $secmatch = 1;
9577: }
1.290 albertel 9578: }
1.412 raeburn 9579: if (!$secmatch) {
9580: next;
9581: }
1.419 raeburn 9582: }
1.275 raeburn 9583: if (defined($$types{'active'})) {
1.288 raeburn 9584: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9585: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9586: $match = 1;
1.275 raeburn 9587: }
9588: }
9589: if (defined($$types{'previous'})) {
1.609 raeburn 9590: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9591: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9592: $match = 1;
1.275 raeburn 9593: }
9594: }
9595: if (defined($$types{'future'})) {
1.609 raeburn 9596: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9597: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9598: $match = 1;
1.275 raeburn 9599: }
9600: }
1.609 raeburn 9601: if ($match) {
9602: push(@{$seclists{$student}},$section);
9603: if (ref($userdata) eq 'HASH') {
9604: $$userdata{$student} = $$classlist{$student};
9605: }
9606: if (ref($statushash) eq 'HASH') {
9607: $statushash->{$student}{'st'}{$section} = $status;
9608: }
1.288 raeburn 9609: }
1.275 raeburn 9610: }
9611: }
1.412 raeburn 9612: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9613: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9614: my $now = time;
1.609 raeburn 9615: my %displaystatus = ( previous => 'Expired',
9616: active => 'Active',
9617: future => 'Future',
9618: );
1.1121 raeburn 9619: my (%nothide,@possdoms);
1.630 raeburn 9620: if ($hidepriv) {
9621: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9622: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9623: if ($user !~ /:/) {
9624: $nothide{join(':',split(/[\@]/,$user))}=1;
9625: } else {
9626: $nothide{$user} = 1;
9627: }
9628: }
1.1121 raeburn 9629: my @possdoms = ($cdom);
9630: if ($coursehash{'checkforpriv'}) {
9631: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9632: }
1.630 raeburn 9633: }
1.439 raeburn 9634: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9635: my $match = 0;
1.412 raeburn 9636: my $secmatch = 0;
1.439 raeburn 9637: my $status;
1.412 raeburn 9638: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9639: $user =~ s/:$//;
1.439 raeburn 9640: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9641: if ($end == -1 || $start == -1) {
9642: next;
9643: }
9644: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9645: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9646: my ($uname,$udom) = split(/:/,$user);
9647: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9648: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9649: $secmatch = 1;
9650: } elsif ($usec eq '') {
1.420 albertel 9651: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9652: $secmatch = 1;
9653: }
9654: } else {
9655: if (grep(/^\Q$usec\E$/,@{$sections})) {
9656: $secmatch = 1;
9657: }
9658: }
9659: if (!$secmatch) {
9660: next;
9661: }
1.288 raeburn 9662: }
1.419 raeburn 9663: if ($usec eq '') {
9664: $usec = 'none';
9665: }
1.275 raeburn 9666: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9667: if ($hidepriv) {
1.1121 raeburn 9668: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9669: (!$nothide{$uname.':'.$udom})) {
9670: next;
9671: }
9672: }
1.503 raeburn 9673: if ($end > 0 && $end < $now) {
1.439 raeburn 9674: $status = 'previous';
9675: } elsif ($start > $now) {
9676: $status = 'future';
9677: } else {
9678: $status = 'active';
9679: }
1.277 albertel 9680: foreach my $type (keys(%{$types})) {
1.275 raeburn 9681: if ($status eq $type) {
1.420 albertel 9682: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9683: push(@{$$users{$role}{$user}},$type);
9684: }
1.288 raeburn 9685: $match = 1;
9686: }
9687: }
1.419 raeburn 9688: if (($match) && (ref($userdata) eq 'HASH')) {
9689: if (!exists($$userdata{$uname.':'.$udom})) {
9690: &get_user_info($udom,$uname,\%idx,$userdata);
9691: }
1.420 albertel 9692: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9693: push(@{$seclists{$uname.':'.$udom}},$usec);
9694: }
1.609 raeburn 9695: if (ref($statushash) eq 'HASH') {
9696: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9697: }
1.275 raeburn 9698: }
9699: }
9700: }
9701: }
1.290 albertel 9702: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9703: if ((defined($cdom)) && (defined($cnum))) {
9704: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9705: if ( defined($csettings{'internal.courseowner'}) ) {
9706: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9707: next if ($owner eq '');
9708: my ($ownername,$ownerdom);
9709: if ($owner =~ /^([^:]+):([^:]+)$/) {
9710: $ownername = $1;
9711: $ownerdom = $2;
9712: } else {
9713: $ownername = $owner;
9714: $ownerdom = $cdom;
9715: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9716: }
9717: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9718: if (defined($userdata) &&
1.609 raeburn 9719: !exists($$userdata{$owner})) {
9720: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9721: if (!grep(/^none$/,@{$seclists{$owner}})) {
9722: push(@{$seclists{$owner}},'none');
9723: }
9724: if (ref($statushash) eq 'HASH') {
9725: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9726: }
1.290 albertel 9727: }
1.279 raeburn 9728: }
9729: }
9730: }
1.419 raeburn 9731: foreach my $user (keys(%seclists)) {
9732: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9733: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9734: }
1.275 raeburn 9735: }
9736: return;
9737: }
9738:
1.288 raeburn 9739: sub get_user_info {
9740: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9741: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9742: &plainname($uname,$udom,'lastname');
1.291 albertel 9743: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9744: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9745: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9746: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9747: return;
9748: }
1.275 raeburn 9749:
1.472 raeburn 9750: ###############################################
9751:
9752: =pod
9753:
9754: =item * &get_user_quota()
9755:
1.1134 raeburn 9756: Retrieves quota assigned for storage of user files.
9757: Default is to report quota for portfolio files.
1.472 raeburn 9758:
9759: Incoming parameters:
9760: 1. user's username
9761: 2. user's domain
1.1134 raeburn 9762: 3. quota name - portfolio, author, or course
1.1136 raeburn 9763: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 9764: 4. crstype - official, unofficial, textbook, placement or community,
9765: if quota name is course
1.472 raeburn 9766:
9767: Returns:
1.1163 raeburn 9768: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9769: 2. (Optional) Type of setting: custom or default
9770: (individually assigned or default for user's
9771: institutional status).
9772: 3. (Optional) - User's institutional status (e.g., faculty, staff
9773: or student - types as defined in localenroll::inst_usertypes
9774: for user's domain, which determines default quota for user.
9775: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9776:
9777: If a value has been stored in the user's environment,
1.536 raeburn 9778: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9779: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9780:
9781: =cut
9782:
9783: ###############################################
9784:
9785:
9786: sub get_user_quota {
1.1136 raeburn 9787: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9788: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9789: if (!defined($udom)) {
9790: $udom = $env{'user.domain'};
9791: }
9792: if (!defined($uname)) {
9793: $uname = $env{'user.name'};
9794: }
9795: if (($udom eq '' || $uname eq '') ||
9796: ($udom eq 'public') && ($uname eq 'public')) {
9797: $quota = 0;
1.536 raeburn 9798: $quotatype = 'default';
9799: $defquota = 0;
1.472 raeburn 9800: } else {
1.536 raeburn 9801: my $inststatus;
1.1134 raeburn 9802: if ($quotaname eq 'course') {
9803: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9804: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9805: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9806: } else {
9807: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9808: $quota = $cenv{'internal.uploadquota'};
9809: }
1.536 raeburn 9810: } else {
1.1134 raeburn 9811: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9812: if ($quotaname eq 'author') {
9813: $quota = $env{'environment.authorquota'};
9814: } else {
9815: $quota = $env{'environment.portfolioquota'};
9816: }
9817: $inststatus = $env{'environment.inststatus'};
9818: } else {
9819: my %userenv =
9820: &Apache::lonnet::get('environment',['portfolioquota',
9821: 'authorquota','inststatus'],$udom,$uname);
9822: my ($tmp) = keys(%userenv);
9823: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9824: if ($quotaname eq 'author') {
9825: $quota = $userenv{'authorquota'};
9826: } else {
9827: $quota = $userenv{'portfolioquota'};
9828: }
9829: $inststatus = $userenv{'inststatus'};
9830: } else {
9831: undef(%userenv);
9832: }
9833: }
9834: }
9835: if ($quota eq '' || wantarray) {
9836: if ($quotaname eq 'course') {
9837: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 9838: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 9839: ($crstype eq 'community') || ($crstype eq 'textbook') ||
9840: ($crstype eq 'placement')) {
1.1136 raeburn 9841: $defquota = $domdefs{$crstype.'quota'};
9842: }
9843: if ($defquota eq '') {
9844: $defquota = 500;
9845: }
1.1134 raeburn 9846: } else {
9847: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9848: }
9849: if ($quota eq '') {
9850: $quota = $defquota;
9851: $quotatype = 'default';
9852: } else {
9853: $quotatype = 'custom';
9854: }
1.472 raeburn 9855: }
9856: }
1.536 raeburn 9857: if (wantarray) {
9858: return ($quota,$quotatype,$settingstatus,$defquota);
9859: } else {
9860: return $quota;
9861: }
1.472 raeburn 9862: }
9863:
9864: ###############################################
9865:
9866: =pod
9867:
9868: =item * &default_quota()
9869:
1.536 raeburn 9870: Retrieves default quota assigned for storage of user portfolio files,
9871: given an (optional) user's institutional status.
1.472 raeburn 9872:
9873: Incoming parameters:
1.1142 raeburn 9874:
1.472 raeburn 9875: 1. domain
1.536 raeburn 9876: 2. (Optional) institutional status(es). This is a : separated list of
9877: status types (e.g., faculty, staff, student etc.)
9878: which apply to the user for whom the default is being retrieved.
9879: If the institutional status string in undefined, the domain
1.1134 raeburn 9880: default quota will be returned.
9881: 3. quota name - portfolio, author, or course
9882: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9883:
9884: Returns:
1.1142 raeburn 9885:
1.1163 raeburn 9886: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9887: 2. (Optional) institutional type which determined the value of the
9888: default quota.
1.472 raeburn 9889:
9890: If a value has been stored in the domain's configuration db,
9891: it will return that, otherwise it returns 20 (for backwards
9892: compatibility with domains which have not set up a configuration
1.1163 raeburn 9893: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9894:
1.536 raeburn 9895: If the user's status includes multiple types (e.g., staff and student),
9896: the largest default quota which applies to the user determines the
9897: default quota returned.
9898:
1.472 raeburn 9899: =cut
9900:
9901: ###############################################
9902:
9903:
9904: sub default_quota {
1.1134 raeburn 9905: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9906: my ($defquota,$settingstatus);
9907: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9908: ['quotas'],$udom);
1.1134 raeburn 9909: my $key = 'defaultquota';
9910: if ($quotaname eq 'author') {
9911: $key = 'authorquota';
9912: }
1.622 raeburn 9913: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9914: if ($inststatus ne '') {
1.765 raeburn 9915: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9916: foreach my $item (@statuses) {
1.1134 raeburn 9917: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9918: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9919: if ($defquota eq '') {
1.1134 raeburn 9920: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9921: $settingstatus = $item;
1.1134 raeburn 9922: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9923: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9924: $settingstatus = $item;
9925: }
9926: }
1.1134 raeburn 9927: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9928: if ($quotahash{'quotas'}{$item} ne '') {
9929: if ($defquota eq '') {
9930: $defquota = $quotahash{'quotas'}{$item};
9931: $settingstatus = $item;
9932: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9933: $defquota = $quotahash{'quotas'}{$item};
9934: $settingstatus = $item;
9935: }
1.536 raeburn 9936: }
9937: }
9938: }
9939: }
9940: if ($defquota eq '') {
1.1134 raeburn 9941: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9942: $defquota = $quotahash{'quotas'}{$key}{'default'};
9943: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9944: $defquota = $quotahash{'quotas'}{'default'};
9945: }
1.536 raeburn 9946: $settingstatus = 'default';
1.1139 raeburn 9947: if ($defquota eq '') {
9948: if ($quotaname eq 'author') {
9949: $defquota = 500;
9950: }
9951: }
1.536 raeburn 9952: }
9953: } else {
9954: $settingstatus = 'default';
1.1134 raeburn 9955: if ($quotaname eq 'author') {
9956: $defquota = 500;
9957: } else {
9958: $defquota = 20;
9959: }
1.536 raeburn 9960: }
9961: if (wantarray) {
9962: return ($defquota,$settingstatus);
1.472 raeburn 9963: } else {
1.536 raeburn 9964: return $defquota;
1.472 raeburn 9965: }
9966: }
9967:
1.1135 raeburn 9968: ###############################################
9969:
9970: =pod
9971:
1.1136 raeburn 9972: =item * &excess_filesize_warning()
1.1135 raeburn 9973:
9974: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 9975: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 9976: space to be exceeded.
1.1136 raeburn 9977:
9978: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 9979: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 9980:
1.1165 raeburn 9981: Inputs: 7
1.1136 raeburn 9982: 1. username or coursenum
1.1135 raeburn 9983: 2. domain
1.1136 raeburn 9984: 3. context ('author' or 'course')
1.1135 raeburn 9985: 4. filename of file for which action is being requested
9986: 5. filesize (kB) of file
9987: 6. action being taken: copy or upload.
1.1237 raeburn 9988: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 9989:
9990: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 9991: otherwise return null.
9992:
9993: =back
1.1135 raeburn 9994:
9995: =cut
9996:
1.1136 raeburn 9997: sub excess_filesize_warning {
1.1165 raeburn 9998: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 9999: my $current_disk_usage = 0;
1.1165 raeburn 10000: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10001: if ($context eq 'author') {
10002: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10003: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10004: } else {
10005: foreach my $subdir ('docs','supplemental') {
10006: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10007: }
10008: }
1.1135 raeburn 10009: $disk_quota = int($disk_quota * 1000);
10010: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10011: return '<p class="LC_warning">'.
1.1135 raeburn 10012: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10013: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10014: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10015: $disk_quota,$current_disk_usage).
10016: '</p>';
10017: }
10018: return;
10019: }
10020:
10021: ###############################################
10022:
10023:
1.1136 raeburn 10024:
10025:
1.384 raeburn 10026: sub get_secgrprole_info {
10027: my ($cdom,$cnum,$needroles,$type) = @_;
10028: my %sections_count = &get_sections($cdom,$cnum);
10029: my @sections = (sort {$a <=> $b} keys(%sections_count));
10030: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10031: my @groups = sort(keys(%curr_groups));
10032: my $allroles = [];
10033: my $rolehash;
10034: my $accesshash = {
10035: active => 'Currently has access',
10036: future => 'Will have future access',
10037: previous => 'Previously had access',
10038: };
10039: if ($needroles) {
10040: $rolehash = {'all' => 'all'};
1.385 albertel 10041: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10042: if (&Apache::lonnet::error(%user_roles)) {
10043: undef(%user_roles);
10044: }
10045: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10046: my ($role)=split(/\:/,$item,2);
10047: if ($role eq 'cr') { next; }
10048: if ($role =~ /^cr/) {
10049: $$rolehash{$role} = (split('/',$role))[3];
10050: } else {
10051: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10052: }
10053: }
10054: foreach my $key (sort(keys(%{$rolehash}))) {
10055: push(@{$allroles},$key);
10056: }
10057: push (@{$allroles},'st');
10058: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10059: }
10060: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10061: }
10062:
1.555 raeburn 10063: sub user_picker {
1.1279 raeburn 10064: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10065: my $currdom = $dom;
1.1253 raeburn 10066: my @alldoms = &Apache::lonnet::all_domains();
10067: if (@alldoms == 1) {
10068: my %domsrch = &Apache::lonnet::get_dom('configuration',
10069: ['directorysrch'],$alldoms[0]);
10070: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10071: my $showdom = $domdesc;
10072: if ($showdom eq '') {
10073: $showdom = $dom;
10074: }
10075: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10076: if ((!$domsrch{'directorysrch'}{'available'}) &&
10077: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10078: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10079: }
10080: }
10081: }
1.555 raeburn 10082: my %curr_selected = (
10083: srchin => 'dom',
1.580 raeburn 10084: srchby => 'lastname',
1.555 raeburn 10085: );
10086: my $srchterm;
1.625 raeburn 10087: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10088: if ($srch->{'srchby'} ne '') {
10089: $curr_selected{'srchby'} = $srch->{'srchby'};
10090: }
10091: if ($srch->{'srchin'} ne '') {
10092: $curr_selected{'srchin'} = $srch->{'srchin'};
10093: }
10094: if ($srch->{'srchtype'} ne '') {
10095: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10096: }
10097: if ($srch->{'srchdomain'} ne '') {
10098: $currdom = $srch->{'srchdomain'};
10099: }
10100: $srchterm = $srch->{'srchterm'};
10101: }
1.1222 damieng 10102: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10103: 'usr' => 'Search criteria',
1.563 raeburn 10104: 'doma' => 'Domain/institution to search',
1.558 albertel 10105: 'uname' => 'username',
10106: 'lastname' => 'last name',
1.555 raeburn 10107: 'lastfirst' => 'last name, first name',
1.558 albertel 10108: 'crs' => 'in this course',
1.576 raeburn 10109: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10110: 'alc' => 'all LON-CAPA',
1.573 raeburn 10111: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10112: 'exact' => 'is',
10113: 'contains' => 'contains',
1.569 raeburn 10114: 'begins' => 'begins with',
1.1222 damieng 10115: );
10116: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10117: 'youm' => "You must include some text to search for.",
10118: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10119: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10120: 'yomc' => "You must choose a domain when using an institutional directory search.",
10121: 'ymcd' => "You must choose a domain when using a domain search.",
10122: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10123: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10124: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10125: );
1.1222 damieng 10126: &html_escape(\%html_lt);
10127: &js_escape(\%js_lt);
1.1255 raeburn 10128: my $domform;
1.1277 raeburn 10129: my $allow_blank = 1;
1.1255 raeburn 10130: if ($fixeddom) {
1.1277 raeburn 10131: $allow_blank = 0;
10132: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10133: } else {
1.1277 raeburn 10134: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1255 raeburn 10135: }
1.563 raeburn 10136: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10137:
10138: my @srchins = ('crs','dom','alc','instd');
10139:
10140: foreach my $option (@srchins) {
10141: # FIXME 'alc' option unavailable until
10142: # loncreateuser::print_user_query_page()
10143: # has been completed.
10144: next if ($option eq 'alc');
1.880 raeburn 10145: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10146: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10147: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10148: if ($curr_selected{'srchin'} eq $option) {
10149: $srchinsel .= '
1.1222 damieng 10150: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10151: } else {
10152: $srchinsel .= '
1.1222 damieng 10153: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10154: }
1.555 raeburn 10155: }
1.563 raeburn 10156: $srchinsel .= "\n </select>\n";
1.555 raeburn 10157:
10158: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10159: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10160: if ($curr_selected{'srchby'} eq $option) {
10161: $srchbysel .= '
1.1222 damieng 10162: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10163: } else {
10164: $srchbysel .= '
1.1222 damieng 10165: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10166: }
10167: }
10168: $srchbysel .= "\n </select>\n";
10169:
10170: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10171: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10172: if ($curr_selected{'srchtype'} eq $option) {
10173: $srchtypesel .= '
1.1222 damieng 10174: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10175: } else {
10176: $srchtypesel .= '
1.1222 damieng 10177: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10178: }
10179: }
10180: $srchtypesel .= "\n </select>\n";
10181:
1.558 albertel 10182: my ($newuserscript,$new_user_create);
1.994 raeburn 10183: my $context_dom = $env{'request.role.domain'};
10184: if ($context eq 'requestcrs') {
10185: if ($env{'form.coursedom'} ne '') {
10186: $context_dom = $env{'form.coursedom'};
10187: }
10188: }
1.556 raeburn 10189: if ($forcenewuser) {
1.576 raeburn 10190: if (ref($srch) eq 'HASH') {
1.994 raeburn 10191: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10192: if ($cancreate) {
10193: $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>';
10194: } else {
1.799 bisitz 10195: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10196: my %usertypetext = (
10197: official => 'institutional',
10198: unofficial => 'non-institutional',
10199: );
1.799 bisitz 10200: $new_user_create = '<p class="LC_warning">'
10201: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10202: .' '
10203: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10204: ,'<a href="'.$helplink.'">','</a>')
10205: .'</p><br />';
1.627 raeburn 10206: }
1.576 raeburn 10207: }
10208: }
10209:
1.556 raeburn 10210: $newuserscript = <<"ENDSCRIPT";
10211:
1.570 raeburn 10212: function setSearch(createnew,callingForm) {
1.556 raeburn 10213: if (createnew == 1) {
1.570 raeburn 10214: for (var i=0; i<callingForm.srchby.length; i++) {
10215: if (callingForm.srchby.options[i].value == 'uname') {
10216: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10217: }
10218: }
1.570 raeburn 10219: for (var i=0; i<callingForm.srchin.length; i++) {
10220: if ( callingForm.srchin.options[i].value == 'dom') {
10221: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10222: }
10223: }
1.570 raeburn 10224: for (var i=0; i<callingForm.srchtype.length; i++) {
10225: if (callingForm.srchtype.options[i].value == 'exact') {
10226: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10227: }
10228: }
1.570 raeburn 10229: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10230: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10231: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10232: }
10233: }
10234: }
10235: }
10236: ENDSCRIPT
1.558 albertel 10237:
1.556 raeburn 10238: }
10239:
1.555 raeburn 10240: my $output = <<"END_BLOCK";
1.556 raeburn 10241: <script type="text/javascript">
1.824 bisitz 10242: // <![CDATA[
1.570 raeburn 10243: function validateEntry(callingForm) {
1.558 albertel 10244:
1.556 raeburn 10245: var checkok = 1;
1.558 albertel 10246: var srchin;
1.570 raeburn 10247: for (var i=0; i<callingForm.srchin.length; i++) {
10248: if ( callingForm.srchin[i].checked ) {
10249: srchin = callingForm.srchin[i].value;
1.558 albertel 10250: }
10251: }
10252:
1.570 raeburn 10253: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10254: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10255: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10256: var srchterm = callingForm.srchterm.value;
10257: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10258: var msg = "";
10259:
10260: if (srchterm == "") {
10261: checkok = 0;
1.1222 damieng 10262: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10263: }
10264:
1.569 raeburn 10265: if (srchtype== 'begins') {
10266: if (srchterm.length < 2) {
10267: checkok = 0;
1.1222 damieng 10268: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10269: }
10270: }
10271:
1.556 raeburn 10272: if (srchtype== 'contains') {
10273: if (srchterm.length < 3) {
10274: checkok = 0;
1.1222 damieng 10275: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10276: }
10277: }
10278: if (srchin == 'instd') {
10279: if (srchdomain == '') {
10280: checkok = 0;
1.1222 damieng 10281: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10282: }
10283: }
10284: if (srchin == 'dom') {
10285: if (srchdomain == '') {
10286: checkok = 0;
1.1222 damieng 10287: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10288: }
10289: }
10290: if (srchby == 'lastfirst') {
10291: if (srchterm.indexOf(",") == -1) {
10292: checkok = 0;
1.1222 damieng 10293: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10294: }
10295: if (srchterm.indexOf(",") == srchterm.length -1) {
10296: checkok = 0;
1.1222 damieng 10297: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10298: }
10299: }
10300: if (checkok == 0) {
1.1222 damieng 10301: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10302: return;
10303: }
10304: if (checkok == 1) {
1.570 raeburn 10305: callingForm.submit();
1.556 raeburn 10306: }
10307: }
10308:
10309: $newuserscript
10310:
1.824 bisitz 10311: // ]]>
1.556 raeburn 10312: </script>
1.558 albertel 10313:
10314: $new_user_create
10315:
1.555 raeburn 10316: END_BLOCK
1.558 albertel 10317:
1.876 raeburn 10318: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10319: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10320: $domform.
10321: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10322: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10323: $srchbysel.
10324: $srchtypesel.
10325: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10326: $srchinsel.
10327: &Apache::lonhtmlcommon::row_closure(1).
10328: &Apache::lonhtmlcommon::end_pick_box().
10329: '<br />';
1.1253 raeburn 10330: return ($output,1);
1.555 raeburn 10331: }
10332:
1.612 raeburn 10333: sub user_rule_check {
1.615 raeburn 10334: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10335: my ($response,%inst_response);
1.612 raeburn 10336: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10337: if (keys(%{$usershash}) > 1) {
10338: my (%by_username,%by_id,%userdoms);
10339: my $checkid;
10340: if (ref($checks) eq 'HASH') {
10341: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10342: $checkid = 1;
10343: }
10344: }
10345: foreach my $user (keys(%{$usershash})) {
10346: my ($uname,$udom) = split(/:/,$user);
10347: if ($checkid) {
10348: if (ref($usershash->{$user}) eq 'HASH') {
10349: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10350: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10351: $userdoms{$udom} = 1;
1.1227 raeburn 10352: if (ref($inst_results) eq 'HASH') {
10353: $inst_results->{$uname.':'.$udom} = {};
10354: }
1.1226 raeburn 10355: }
10356: }
10357: } else {
10358: $by_username{$udom}{$uname} = 1;
10359: $userdoms{$udom} = 1;
1.1227 raeburn 10360: if (ref($inst_results) eq 'HASH') {
10361: $inst_results->{$uname.':'.$udom} = {};
10362: }
1.1226 raeburn 10363: }
10364: }
10365: foreach my $udom (keys(%userdoms)) {
10366: if (!$got_rules->{$udom}) {
10367: my %domconfig = &Apache::lonnet::get_dom('configuration',
10368: ['usercreation'],$udom);
10369: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10370: foreach my $item ('username','id') {
10371: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10372: $$curr_rules{$udom}{$item} =
10373: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10374: }
10375: }
10376: }
10377: $got_rules->{$udom} = 1;
10378: }
1.612 raeburn 10379: }
1.1226 raeburn 10380: if ($checkid) {
10381: foreach my $udom (keys(%by_id)) {
10382: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10383: if ($outcome eq 'ok') {
1.1227 raeburn 10384: foreach my $id (keys(%{$by_id{$udom}})) {
10385: my $uname = $by_id{$udom}{$id};
10386: $inst_response{$uname.':'.$udom} = $outcome;
10387: }
1.1226 raeburn 10388: if (ref($results) eq 'HASH') {
10389: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10390: if (exists($inst_response{$uname.':'.$udom})) {
10391: $inst_response{$uname.':'.$udom} = $outcome;
10392: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10393: }
1.1226 raeburn 10394: }
10395: }
10396: }
1.612 raeburn 10397: }
1.615 raeburn 10398: } else {
1.1226 raeburn 10399: foreach my $udom (keys(%by_username)) {
10400: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10401: if ($outcome eq 'ok') {
1.1227 raeburn 10402: foreach my $uname (keys(%{$by_username{$udom}})) {
10403: $inst_response{$uname.':'.$udom} = $outcome;
10404: }
1.1226 raeburn 10405: if (ref($results) eq 'HASH') {
10406: foreach my $uname (keys(%{$results})) {
10407: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10408: }
10409: }
10410: }
10411: }
1.612 raeburn 10412: }
1.1226 raeburn 10413: } elsif (keys(%{$usershash}) == 1) {
10414: my $user = (keys(%{$usershash}))[0];
10415: my ($uname,$udom) = split(/:/,$user);
10416: if (($udom ne '') && ($uname ne '')) {
10417: if (ref($usershash->{$user}) eq 'HASH') {
10418: if (ref($checks) eq 'HASH') {
10419: if (defined($checks->{'username'})) {
10420: ($inst_response{$user},%{$inst_results->{$user}}) =
10421: &Apache::lonnet::get_instuser($udom,$uname);
10422: } elsif (defined($checks->{'id'})) {
10423: if ($usershash->{$user}->{'id'} ne '') {
10424: ($inst_response{$user},%{$inst_results->{$user}}) =
10425: &Apache::lonnet::get_instuser($udom,undef,
10426: $usershash->{$user}->{'id'});
10427: } else {
10428: ($inst_response{$user},%{$inst_results->{$user}}) =
10429: &Apache::lonnet::get_instuser($udom,$uname);
10430: }
1.585 raeburn 10431: }
1.1226 raeburn 10432: } else {
10433: ($inst_response{$user},%{$inst_results->{$user}}) =
10434: &Apache::lonnet::get_instuser($udom,$uname);
10435: return;
10436: }
10437: if (!$got_rules->{$udom}) {
10438: my %domconfig = &Apache::lonnet::get_dom('configuration',
10439: ['usercreation'],$udom);
10440: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10441: foreach my $item ('username','id') {
10442: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10443: $$curr_rules{$udom}{$item} =
10444: $domconfig{'usercreation'}{$item.'_rule'};
10445: }
10446: }
10447: }
10448: $got_rules->{$udom} = 1;
1.585 raeburn 10449: }
10450: }
1.1226 raeburn 10451: } else {
10452: return;
10453: }
10454: } else {
10455: return;
10456: }
10457: foreach my $user (keys(%{$usershash})) {
10458: my ($uname,$udom) = split(/:/,$user);
10459: next if (($udom eq '') || ($uname eq ''));
10460: my $id;
1.1227 raeburn 10461: if (ref($inst_results) eq 'HASH') {
10462: if (ref($inst_results->{$user}) eq 'HASH') {
10463: $id = $inst_results->{$user}->{'id'};
10464: }
10465: }
10466: if ($id eq '') {
10467: if (ref($usershash->{$user})) {
10468: $id = $usershash->{$user}->{'id'};
10469: }
1.585 raeburn 10470: }
1.612 raeburn 10471: foreach my $item (keys(%{$checks})) {
10472: if (ref($$curr_rules{$udom}) eq 'HASH') {
10473: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10474: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10475: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10476: $$curr_rules{$udom}{$item});
1.612 raeburn 10477: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10478: if ($rule_check{$rule}) {
10479: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10480: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10481: if (ref($inst_results) eq 'HASH') {
10482: if (ref($inst_results->{$user}) eq 'HASH') {
10483: if (keys(%{$inst_results->{$user}}) == 0) {
10484: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10485: } elsif ($item eq 'id') {
10486: if ($inst_results->{$user}->{'id'} eq '') {
10487: $$alerts{$item}{$udom}{$uname} = 1;
10488: }
1.615 raeburn 10489: }
1.612 raeburn 10490: }
10491: }
1.615 raeburn 10492: }
10493: last;
1.585 raeburn 10494: }
10495: }
10496: }
10497: }
10498: }
10499: }
10500: }
10501: }
1.612 raeburn 10502: return;
10503: }
10504:
10505: sub user_rule_formats {
10506: my ($domain,$domdesc,$curr_rules,$check) = @_;
10507: my %text = (
10508: 'username' => 'Usernames',
10509: 'id' => 'IDs',
10510: );
10511: my $output;
10512: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10513: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10514: if (@{$ruleorder} > 0) {
1.1102 raeburn 10515: $output = '<br />'.
10516: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10517: '<span class="LC_cusr_emph">','</span>',$domdesc).
10518: ' <ul>';
1.612 raeburn 10519: foreach my $rule (@{$ruleorder}) {
10520: if (ref($curr_rules) eq 'ARRAY') {
10521: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10522: if (ref($rules->{$rule}) eq 'HASH') {
10523: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10524: $rules->{$rule}{'desc'}.'</li>';
10525: }
10526: }
10527: }
10528: }
10529: $output .= '</ul>';
10530: }
10531: }
10532: return $output;
10533: }
10534:
10535: sub instrule_disallow_msg {
1.615 raeburn 10536: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10537: my $response;
10538: my %text = (
10539: item => 'username',
10540: items => 'usernames',
10541: match => 'matches',
10542: do => 'does',
10543: action => 'a username',
10544: one => 'one',
10545: );
10546: if ($count > 1) {
10547: $text{'item'} = 'usernames';
10548: $text{'match'} ='match';
10549: $text{'do'} = 'do';
10550: $text{'action'} = 'usernames',
10551: $text{'one'} = 'ones';
10552: }
10553: if ($checkitem eq 'id') {
10554: $text{'items'} = 'IDs';
10555: $text{'item'} = 'ID';
10556: $text{'action'} = 'an ID';
1.615 raeburn 10557: if ($count > 1) {
10558: $text{'item'} = 'IDs';
10559: $text{'action'} = 'IDs';
10560: }
1.612 raeburn 10561: }
1.674 bisitz 10562: $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 10563: if ($mode eq 'upload') {
10564: if ($checkitem eq 'username') {
10565: $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'}.");
10566: } elsif ($checkitem eq 'id') {
1.674 bisitz 10567: $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 10568: }
1.669 raeburn 10569: } elsif ($mode eq 'selfcreate') {
10570: if ($checkitem eq 'id') {
10571: $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.");
10572: }
1.615 raeburn 10573: } else {
10574: if ($checkitem eq 'username') {
10575: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10576: } elsif ($checkitem eq 'id') {
10577: $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.");
10578: }
1.612 raeburn 10579: }
10580: return $response;
1.585 raeburn 10581: }
10582:
1.624 raeburn 10583: sub personal_data_fieldtitles {
10584: my %fieldtitles = &Apache::lonlocal::texthash (
10585: id => 'Student/Employee ID',
10586: permanentemail => 'E-mail address',
10587: lastname => 'Last Name',
10588: firstname => 'First Name',
10589: middlename => 'Middle Name',
10590: generation => 'Generation',
10591: gen => 'Generation',
1.765 raeburn 10592: inststatus => 'Affiliation',
1.624 raeburn 10593: );
10594: return %fieldtitles;
10595: }
10596:
1.642 raeburn 10597: sub sorted_inst_types {
10598: my ($dom) = @_;
1.1185 raeburn 10599: my ($usertypes,$order);
10600: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10601: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10602: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10603: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10604: } else {
10605: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10606: }
1.642 raeburn 10607: my $othertitle = &mt('All users');
10608: if ($env{'request.course.id'}) {
1.668 raeburn 10609: $othertitle = &mt('Any users');
1.642 raeburn 10610: }
10611: my @types;
10612: if (ref($order) eq 'ARRAY') {
10613: @types = @{$order};
10614: }
10615: if (@types == 0) {
10616: if (ref($usertypes) eq 'HASH') {
10617: @types = sort(keys(%{$usertypes}));
10618: }
10619: }
10620: if (keys(%{$usertypes}) > 0) {
10621: $othertitle = &mt('Other users');
10622: }
10623: return ($othertitle,$usertypes,\@types);
10624: }
10625:
1.645 raeburn 10626: sub get_institutional_codes {
10627: my ($settings,$allcourses,$LC_code) = @_;
10628: # Get complete list of course sections to update
10629: my @currsections = ();
10630: my @currxlists = ();
10631: my $coursecode = $$settings{'internal.coursecode'};
10632:
10633: if ($$settings{'internal.sectionnums'} ne '') {
10634: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10635: }
10636:
10637: if ($$settings{'internal.crosslistings'} ne '') {
10638: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10639: }
10640:
10641: if (@currxlists > 0) {
10642: foreach (@currxlists) {
10643: if (m/^([^:]+):(\w*)$/) {
10644: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 10645: push(@{$allcourses},$1);
1.645 raeburn 10646: $$LC_code{$1} = $2;
10647: }
10648: }
10649: }
10650: }
10651:
10652: if (@currsections > 0) {
10653: foreach (@currsections) {
10654: if (m/^(\w+):(\w*)$/) {
10655: my $sec = $coursecode.$1;
10656: my $lc_sec = $2;
10657: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 10658: push(@{$allcourses},$sec);
1.645 raeburn 10659: $$LC_code{$sec} = $lc_sec;
10660: }
10661: }
10662: }
10663: }
10664: return;
10665: }
10666:
1.971 raeburn 10667: sub get_standard_codeitems {
10668: return ('Year','Semester','Department','Number','Section');
10669: }
10670:
1.112 bowersj2 10671: =pod
10672:
1.780 raeburn 10673: =head1 Slot Helpers
10674:
10675: =over 4
10676:
10677: =item * sorted_slots()
10678:
1.1040 raeburn 10679: Sorts an array of slot names in order of an optional sort key,
10680: default sort is by slot start time (earliest first).
1.780 raeburn 10681:
10682: Inputs:
10683:
10684: =over 4
10685:
10686: slotsarr - Reference to array of unsorted slot names.
10687:
10688: slots - Reference to hash of hash, where outer hash keys are slot names.
10689:
1.1040 raeburn 10690: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10691:
1.549 albertel 10692: =back
10693:
1.780 raeburn 10694: Returns:
10695:
10696: =over 4
10697:
1.1040 raeburn 10698: sorted - An array of slot names sorted by a specified sort key
10699: (default sort key is start time of the slot).
1.780 raeburn 10700:
10701: =back
10702:
10703: =cut
10704:
10705:
10706: sub sorted_slots {
1.1040 raeburn 10707: my ($slotsarr,$slots,$sortkey) = @_;
10708: if ($sortkey eq '') {
10709: $sortkey = 'starttime';
10710: }
1.780 raeburn 10711: my @sorted;
10712: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10713: @sorted =
10714: sort {
10715: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10716: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10717: }
10718: if (ref($slots->{$a})) { return -1;}
10719: if (ref($slots->{$b})) { return 1;}
10720: return 0;
10721: } @{$slotsarr};
10722: }
10723: return @sorted;
10724: }
10725:
1.1040 raeburn 10726: =pod
10727:
10728: =item * get_future_slots()
10729:
10730: Inputs:
10731:
10732: =over 4
10733:
10734: cnum - course number
10735:
10736: cdom - course domain
10737:
10738: now - current UNIX time
10739:
10740: symb - optional symb
10741:
10742: =back
10743:
10744: Returns:
10745:
10746: =over 4
10747:
10748: sorted_reservable - ref to array of student_schedulable slots currently
10749: reservable, ordered by end date of reservation period.
10750:
10751: reservable_now - ref to hash of student_schedulable slots currently
10752: reservable.
10753:
10754: Keys in inner hash are:
10755: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10756: (b) endreserve: end date of reservation period.
10757: (c) uniqueperiod: start,end dates when slot is to be uniquely
10758: selected.
1.1040 raeburn 10759:
10760: sorted_future - ref to array of student_schedulable slots reservable in
10761: the future, ordered by start date of reservation period.
10762:
10763: future_reservable - ref to hash of student_schedulable slots reservable
10764: in the future.
10765:
10766: Keys in inner hash are:
10767: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10768: (b) startreserve: start date of reservation period.
10769: (c) uniqueperiod: start,end dates when slot is to be uniquely
10770: selected.
1.1040 raeburn 10771:
10772: =back
10773:
10774: =cut
10775:
10776: sub get_future_slots {
10777: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 10778: my $map;
10779: if ($symb) {
10780: ($map) = &Apache::lonnet::decode_symb($symb);
10781: }
1.1040 raeburn 10782: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10783: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10784: foreach my $slot (keys(%slots)) {
10785: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10786: if ($symb) {
1.1229 raeburn 10787: if ($slots{$slot}->{'symb'} ne '') {
10788: my $canuse;
10789: my %oksymbs;
10790: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
10791: map { $oksymbs{$_} = 1; } @slotsymbs;
10792: if ($oksymbs{$symb}) {
10793: $canuse = 1;
10794: } else {
10795: foreach my $item (@slotsymbs) {
10796: if ($item =~ /\.(page|sequence)$/) {
10797: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
10798: if (($map ne '') && ($map eq $sloturl)) {
10799: $canuse = 1;
10800: last;
10801: }
10802: }
10803: }
10804: }
10805: next unless ($canuse);
10806: }
1.1040 raeburn 10807: }
10808: if (($slots{$slot}->{'starttime'} > $now) &&
10809: ($slots{$slot}->{'endtime'} > $now)) {
10810: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10811: my $userallowed = 0;
10812: if ($slots{$slot}->{'allowedsections'}) {
10813: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10814: if (!defined($env{'request.role.sec'})
10815: && grep(/^No section assigned$/,@allowed_sec)) {
10816: $userallowed=1;
10817: } else {
10818: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10819: $userallowed=1;
10820: }
10821: }
10822: unless ($userallowed) {
10823: if (defined($env{'request.course.groups'})) {
10824: my @groups = split(/:/,$env{'request.course.groups'});
10825: foreach my $group (@groups) {
10826: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10827: $userallowed=1;
10828: last;
10829: }
10830: }
10831: }
10832: }
10833: }
10834: if ($slots{$slot}->{'allowedusers'}) {
10835: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10836: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10837: if (grep(/^\Q$user\E$/,@allowed_users)) {
10838: $userallowed = 1;
10839: }
10840: }
10841: next unless($userallowed);
10842: }
10843: my $startreserve = $slots{$slot}->{'startreserve'};
10844: my $endreserve = $slots{$slot}->{'endreserve'};
10845: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 10846: my $uniqueperiod;
10847: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10848: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10849: }
1.1040 raeburn 10850: if (($startreserve < $now) &&
10851: (!$endreserve || $endreserve > $now)) {
10852: my $lastres = $endreserve;
10853: if (!$lastres) {
10854: $lastres = $slots{$slot}->{'starttime'};
10855: }
10856: $reservable_now{$slot} = {
10857: symb => $symb,
1.1250 raeburn 10858: endreserve => $lastres,
10859: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10860: };
10861: } elsif (($startreserve > $now) &&
10862: (!$endreserve || $endreserve > $startreserve)) {
10863: $future_reservable{$slot} = {
10864: symb => $symb,
1.1250 raeburn 10865: startreserve => $startreserve,
10866: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10867: };
10868: }
10869: }
10870: }
10871: my @unsorted_reservable = keys(%reservable_now);
10872: if (@unsorted_reservable > 0) {
10873: @sorted_reservable =
10874: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10875: }
10876: my @unsorted_future = keys(%future_reservable);
10877: if (@unsorted_future > 0) {
10878: @sorted_future =
10879: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10880: }
10881: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10882: }
1.780 raeburn 10883:
10884: =pod
10885:
1.1057 foxr 10886: =back
10887:
1.549 albertel 10888: =head1 HTTP Helpers
10889:
10890: =over 4
10891:
1.648 raeburn 10892: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10893:
1.258 albertel 10894: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10895: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10896: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10897:
10898: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10899: $possible_names is an ref to an array of form element names. As an example:
10900: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10901: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10902:
10903: =cut
1.1 albertel 10904:
1.6 albertel 10905: sub get_unprocessed_cgi {
1.25 albertel 10906: my ($query,$possible_names)= @_;
1.26 matthew 10907: # $Apache::lonxml::debug=1;
1.356 albertel 10908: foreach my $pair (split(/&/,$query)) {
10909: my ($name, $value) = split(/=/,$pair);
1.369 www 10910: $name = &unescape($name);
1.25 albertel 10911: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10912: $value =~ tr/+/ /;
10913: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10914: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10915: }
1.16 harris41 10916: }
1.6 albertel 10917: }
10918:
1.112 bowersj2 10919: =pod
10920:
1.648 raeburn 10921: =item * &cacheheader()
1.112 bowersj2 10922:
10923: returns cache-controlling header code
10924:
10925: =cut
10926:
1.7 albertel 10927: sub cacheheader {
1.258 albertel 10928: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10929: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10930: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10931: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10932: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10933: return $output;
1.7 albertel 10934: }
10935:
1.112 bowersj2 10936: =pod
10937:
1.648 raeburn 10938: =item * &no_cache($r)
1.112 bowersj2 10939:
10940: specifies header code to not have cache
10941:
10942: =cut
10943:
1.9 albertel 10944: sub no_cache {
1.216 albertel 10945: my ($r) = @_;
10946: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10947: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10948: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10949: $r->no_cache(1);
10950: $r->header_out("Expires" => $date);
10951: $r->header_out("Pragma" => "no-cache");
1.123 www 10952: }
10953:
10954: sub content_type {
1.181 albertel 10955: my ($r,$type,$charset) = @_;
1.299 foxr 10956: if ($r) {
10957: # Note that printout.pl calls this with undef for $r.
10958: &no_cache($r);
10959: }
1.258 albertel 10960: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10961: unless ($charset) {
10962: $charset=&Apache::lonlocal::current_encoding;
10963: }
10964: if ($charset) { $type.='; charset='.$charset; }
10965: if ($r) {
10966: $r->content_type($type);
10967: } else {
10968: print("Content-type: $type\n\n");
10969: }
1.9 albertel 10970: }
1.25 albertel 10971:
1.112 bowersj2 10972: =pod
10973:
1.648 raeburn 10974: =item * &add_to_env($name,$value)
1.112 bowersj2 10975:
1.258 albertel 10976: adds $name to the %env hash with value
1.112 bowersj2 10977: $value, if $name already exists, the entry is converted to an array
10978: reference and $value is added to the array.
10979:
10980: =cut
10981:
1.25 albertel 10982: sub add_to_env {
10983: my ($name,$value)=@_;
1.258 albertel 10984: if (defined($env{$name})) {
10985: if (ref($env{$name})) {
1.25 albertel 10986: #already have multiple values
1.258 albertel 10987: push(@{ $env{$name} },$value);
1.25 albertel 10988: } else {
10989: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10990: my $first=$env{$name};
10991: undef($env{$name});
10992: push(@{ $env{$name} },$first,$value);
1.25 albertel 10993: }
10994: } else {
1.258 albertel 10995: $env{$name}=$value;
1.25 albertel 10996: }
1.31 albertel 10997: }
1.149 albertel 10998:
10999: =pod
11000:
1.648 raeburn 11001: =item * &get_env_multiple($name)
1.149 albertel 11002:
1.258 albertel 11003: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11004: values may be defined and end up as an array ref.
11005:
11006: returns an array of values
11007:
11008: =cut
11009:
11010: sub get_env_multiple {
11011: my ($name) = @_;
11012: my @values;
1.258 albertel 11013: if (defined($env{$name})) {
1.149 albertel 11014: # exists is it an array
1.258 albertel 11015: if (ref($env{$name})) {
11016: @values=@{ $env{$name} };
1.149 albertel 11017: } else {
1.258 albertel 11018: $values[0]=$env{$name};
1.149 albertel 11019: }
11020: }
11021: return(@values);
11022: }
11023:
1.1249 damieng 11024: # Looks at given dependencies, and returns something depending on the context.
11025: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11026: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11027: # For all other contexts, returns ($output, $counter, $numpathchg).
11028: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11029: # $counter: integer with the number of existing dependencies when no HTML output is returned, and the number of missing dependencies when an HTML output is returned.
11030: # $numpathchg: integer with the number of cleaned up dependency paths.
11031: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11032: # \%mapping: hash reference clean path -> original path for all dependencies.
11033: # @param {string} actionurl - The path to the handler, indicative of the context.
11034: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11035: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11036: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11037: # @param {hash reference} args - More parameters ! Possible keys: error_on_invalid_names (boolean), ignore_remote_references (boolean), current_path (string), docs_url (string), docs_title (string), context (string)
11038: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11039: sub ask_for_embedded_content {
1.1249 damieng 11040: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11041: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11042: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11043: %currsubfile,%unused,$rem);
1.1071 raeburn 11044: my $counter = 0;
11045: my $numnew = 0;
1.987 raeburn 11046: my $numremref = 0;
11047: my $numinvalid = 0;
11048: my $numpathchg = 0;
11049: my $numexisting = 0;
1.1071 raeburn 11050: my $numunused = 0;
11051: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11052: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11053: my $heading = &mt('Upload embedded files');
11054: my $buttontext = &mt('Upload');
11055:
1.1249 damieng 11056: # fills these variables based on the context:
11057: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11058: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11059: if ($env{'request.course.id'}) {
1.1123 raeburn 11060: if ($actionurl eq '/adm/dependencies') {
11061: $navmap = Apache::lonnavmaps::navmap->new();
11062: }
11063: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11064: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11065: }
1.1123 raeburn 11066: if (($actionurl eq '/adm/portfolio') ||
11067: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11068: my $current_path='/';
11069: if ($env{'form.currentpath'}) {
11070: $current_path = $env{'form.currentpath'};
11071: }
11072: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11073: $udom = $cdom;
11074: $uname = $cnum;
1.984 raeburn 11075: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11076: } else {
11077: $udom = $env{'user.domain'};
11078: $uname = $env{'user.name'};
11079: $url = '/userfiles/portfolio';
11080: }
1.987 raeburn 11081: $toplevel = $url.'/';
1.984 raeburn 11082: $url .= $current_path;
11083: $getpropath = 1;
1.987 raeburn 11084: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11085: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11086: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11087: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11088: $toplevel = $url;
1.984 raeburn 11089: if ($rest ne '') {
1.987 raeburn 11090: $url .= $rest;
11091: }
11092: } elsif ($actionurl eq '/adm/coursedocs') {
11093: if (ref($args) eq 'HASH') {
1.1071 raeburn 11094: $url = $args->{'docs_url'};
11095: $toplevel = $url;
1.1084 raeburn 11096: if ($args->{'context'} eq 'paste') {
11097: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11098: ($path) =
11099: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11100: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11101: $fileloc =~ s{^/}{};
11102: }
1.1071 raeburn 11103: }
1.1084 raeburn 11104: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11105: if ($env{'request.course.id'} ne '') {
11106: if (ref($args) eq 'HASH') {
11107: $url = $args->{'docs_url'};
11108: $title = $args->{'docs_title'};
1.1126 raeburn 11109: $toplevel = $url;
11110: unless ($toplevel =~ m{^/}) {
11111: $toplevel = "/$url";
11112: }
1.1085 raeburn 11113: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11114: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11115: $path = $1;
11116: } else {
11117: ($path) =
11118: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11119: }
1.1195 raeburn 11120: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11121: $fileloc = $toplevel;
11122: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11123: my ($udom,$uname,$fname) =
11124: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11125: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11126: } else {
11127: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11128: }
1.1071 raeburn 11129: $fileloc =~ s{^/}{};
11130: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11131: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11132: }
1.987 raeburn 11133: }
1.1123 raeburn 11134: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11135: $udom = $cdom;
11136: $uname = $cnum;
11137: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11138: $toplevel = $url;
11139: $path = $url;
11140: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11141: $fileloc =~ s{^/}{};
1.987 raeburn 11142: }
1.1249 damieng 11143:
11144: # parses the dependency paths to get some info
11145: # fills $newfiles, $mapping, $subdependencies, $dependencies
11146: # $newfiles: hash URL -> 1 for new files or external URLs
11147: # (will be completed later)
11148: # $mapping:
11149: # for external URLs: external URL -> external URL
11150: # for relative paths: clean path -> original path
11151: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11152: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11153: foreach my $file (keys(%{$allfiles})) {
11154: my $embed_file;
11155: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11156: $embed_file = $1;
11157: } else {
11158: $embed_file = $file;
11159: }
1.1158 raeburn 11160: my ($absolutepath,$cleaned_file);
11161: if ($embed_file =~ m{^\w+://}) {
11162: $cleaned_file = $embed_file;
1.1147 raeburn 11163: $newfiles{$cleaned_file} = 1;
11164: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11165: } else {
1.1158 raeburn 11166: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11167: if ($embed_file =~ m{^/}) {
11168: $absolutepath = $embed_file;
11169: }
1.1147 raeburn 11170: if ($cleaned_file =~ m{/}) {
11171: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11172: $path = &check_for_traversal($path,$url,$toplevel);
11173: my $item = $fname;
11174: if ($path ne '') {
11175: $item = $path.'/'.$fname;
11176: $subdependencies{$path}{$fname} = 1;
11177: } else {
11178: $dependencies{$item} = 1;
11179: }
11180: if ($absolutepath) {
11181: $mapping{$item} = $absolutepath;
11182: } else {
11183: $mapping{$item} = $embed_file;
11184: }
11185: } else {
11186: $dependencies{$embed_file} = 1;
11187: if ($absolutepath) {
1.1147 raeburn 11188: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11189: } else {
1.1147 raeburn 11190: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11191: }
11192: }
1.984 raeburn 11193: }
11194: }
1.1249 damieng 11195:
11196: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11197: # and lists
11198: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11199: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11200: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11201: # the path had to be cleaned up
11202: # $existing: hash clean path -> 1 if the file exists
11203: # $numexisting: number of keys in $existing
11204: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11205: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11206: # dependency subdirectories that are
11207: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11208: my $dirptr = 16384;
1.984 raeburn 11209: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11210: $currsubfile{$path} = {};
1.1123 raeburn 11211: if (($actionurl eq '/adm/portfolio') ||
11212: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11213: my ($sublistref,$listerror) =
11214: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11215: if (ref($sublistref) eq 'ARRAY') {
11216: foreach my $line (@{$sublistref}) {
11217: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11218: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11219: }
1.984 raeburn 11220: }
1.987 raeburn 11221: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11222: if (opendir(my $dir,$url.'/'.$path)) {
11223: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11224: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11225: }
1.1084 raeburn 11226: } elsif (($actionurl eq '/adm/dependencies') ||
11227: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11228: ($args->{'context'} eq 'paste')) ||
11229: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11230: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11231: my $dir;
11232: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11233: $dir = $fileloc;
11234: } else {
11235: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11236: }
1.1071 raeburn 11237: if ($dir ne '') {
11238: my ($sublistref,$listerror) =
11239: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11240: if (ref($sublistref) eq 'ARRAY') {
11241: foreach my $line (@{$sublistref}) {
11242: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11243: undef,$mtime)=split(/\&/,$line,12);
11244: unless (($testdir&$dirptr) ||
11245: ($file_name =~ /^\.\.?$/)) {
11246: $currsubfile{$path}{$file_name} = [$size,$mtime];
11247: }
11248: }
11249: }
11250: }
1.984 raeburn 11251: }
11252: }
11253: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11254: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11255: my $item = $path.'/'.$file;
11256: unless ($mapping{$item} eq $item) {
11257: $pathchanges{$item} = 1;
11258: }
11259: $existing{$item} = 1;
11260: $numexisting ++;
11261: } else {
11262: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11263: }
11264: }
1.1071 raeburn 11265: if ($actionurl eq '/adm/dependencies') {
11266: foreach my $path (keys(%currsubfile)) {
11267: if (ref($currsubfile{$path}) eq 'HASH') {
11268: foreach my $file (keys(%{$currsubfile{$path}})) {
11269: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11270: next if (($rem ne '') &&
11271: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11272: (ref($navmap) &&
11273: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11274: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11275: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11276: $unused{$path.'/'.$file} = 1;
11277: }
11278: }
11279: }
11280: }
11281: }
1.984 raeburn 11282: }
1.1249 damieng 11283:
11284: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11285: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11286: my %currfile;
1.1123 raeburn 11287: if (($actionurl eq '/adm/portfolio') ||
11288: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11289: my ($dirlistref,$listerror) =
11290: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11291: if (ref($dirlistref) eq 'ARRAY') {
11292: foreach my $line (@{$dirlistref}) {
11293: my ($file_name,$rest) = split(/\&/,$line,2);
11294: $currfile{$file_name} = 1;
11295: }
1.984 raeburn 11296: }
1.987 raeburn 11297: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11298: if (opendir(my $dir,$url)) {
1.987 raeburn 11299: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11300: map {$currfile{$_} = 1;} @dir_list;
11301: }
1.1084 raeburn 11302: } elsif (($actionurl eq '/adm/dependencies') ||
11303: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11304: ($args->{'context'} eq 'paste')) ||
11305: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11306: if ($env{'request.course.id'} ne '') {
11307: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11308: if ($dir ne '') {
11309: my ($dirlistref,$listerror) =
11310: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11311: if (ref($dirlistref) eq 'ARRAY') {
11312: foreach my $line (@{$dirlistref}) {
11313: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11314: $size,undef,$mtime)=split(/\&/,$line,12);
11315: unless (($testdir&$dirptr) ||
11316: ($file_name =~ /^\.\.?$/)) {
11317: $currfile{$file_name} = [$size,$mtime];
11318: }
11319: }
11320: }
11321: }
11322: }
1.984 raeburn 11323: }
1.1249 damieng 11324: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11325: # are not in subdirectories, using $currfile
1.984 raeburn 11326: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11327: if (exists($currfile{$file})) {
1.987 raeburn 11328: unless ($mapping{$file} eq $file) {
11329: $pathchanges{$file} = 1;
11330: }
11331: $existing{$file} = 1;
11332: $numexisting ++;
11333: } else {
1.984 raeburn 11334: $newfiles{$file} = 1;
11335: }
11336: }
1.1071 raeburn 11337: foreach my $file (keys(%currfile)) {
11338: unless (($file eq $filename) ||
11339: ($file eq $filename.'.bak') ||
11340: ($dependencies{$file})) {
1.1085 raeburn 11341: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11342: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11343: next if (($rem ne '') &&
11344: (($env{"httpref.$rem".$file} ne '') ||
11345: (ref($navmap) &&
11346: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11347: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11348: ($navmap->getResourceByUrl($rem.$1)))))));
11349: }
1.1085 raeburn 11350: }
1.1071 raeburn 11351: $unused{$file} = 1;
11352: }
11353: }
1.1249 damieng 11354:
11355: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11356: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11357: ($args->{'context'} eq 'paste')) {
11358: $counter = scalar(keys(%existing));
11359: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11360: return ($output,$counter,$numpathchg,\%existing);
11361: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11362: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11363: $counter = scalar(keys(%existing));
11364: $numpathchg = scalar(keys(%pathchanges));
11365: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11366: }
1.1249 damieng 11367:
11368: # returns HTML otherwise, with dependency results and to ask for more uploads
11369:
11370: # $upload_output: missing dependencies (with upload form)
11371: # $modify_output: uploaded dependencies (in use)
11372: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11373: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11374: if ($actionurl eq '/adm/dependencies') {
11375: next if ($embed_file =~ m{^\w+://});
11376: }
1.660 raeburn 11377: $upload_output .= &start_data_table_row().
1.1123 raeburn 11378: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11379: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11380: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11381: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11382: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11383: }
1.1123 raeburn 11384: $upload_output .= '</td>';
1.1071 raeburn 11385: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11386: $upload_output.='<td align="right">'.
11387: '<span class="LC_info LC_fontsize_medium">'.
11388: &mt("URL points to web address").'</span>';
1.987 raeburn 11389: $numremref++;
1.660 raeburn 11390: } elsif ($args->{'error_on_invalid_names'}
11391: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11392: $upload_output.='<td align="right"><span class="LC_warning">'.
11393: &mt('Invalid characters').'</span>';
1.987 raeburn 11394: $numinvalid++;
1.660 raeburn 11395: } else {
1.1123 raeburn 11396: $upload_output .= '<td>'.
11397: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11398: $embed_file,\%mapping,
1.1071 raeburn 11399: $allfiles,$codebase,'upload');
11400: $counter ++;
11401: $numnew ++;
1.987 raeburn 11402: }
11403: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11404: }
11405: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11406: if ($actionurl eq '/adm/dependencies') {
11407: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11408: $modify_output .= &start_data_table_row().
11409: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11410: '<img src="'.&icon($embed_file).'" border="0" />'.
11411: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11412: '<td>'.$size.'</td>'.
11413: '<td>'.$mtime.'</td>'.
11414: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11415: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11416: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11417: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11418: &embedded_file_element('upload_embedded',$counter,
11419: $embed_file,\%mapping,
11420: $allfiles,$codebase,'modify').
11421: '</div></td>'.
11422: &end_data_table_row()."\n";
11423: $counter ++;
11424: } else {
11425: $upload_output .= &start_data_table_row().
1.1123 raeburn 11426: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11427: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11428: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11429: &Apache::loncommon::end_data_table_row()."\n";
11430: }
11431: }
11432: my $delidx = $counter;
11433: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11434: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11435: $delete_output .= &start_data_table_row().
11436: '<td><img src="'.&icon($oldfile).'" />'.
11437: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11438: '<td>'.$size.'</td>'.
11439: '<td>'.$mtime.'</td>'.
11440: '<td><label><input type="checkbox" name="del_upload_dep" '.
11441: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11442: &embedded_file_element('upload_embedded',$delidx,
11443: $oldfile,\%mapping,$allfiles,
11444: $codebase,'delete').'</td>'.
11445: &end_data_table_row()."\n";
11446: $numunused ++;
11447: $delidx ++;
1.987 raeburn 11448: }
11449: if ($upload_output) {
11450: $upload_output = &start_data_table().
11451: $upload_output.
11452: &end_data_table()."\n";
11453: }
1.1071 raeburn 11454: if ($modify_output) {
11455: $modify_output = &start_data_table().
11456: &start_data_table_header_row().
11457: '<th>'.&mt('File').'</th>'.
11458: '<th>'.&mt('Size (KB)').'</th>'.
11459: '<th>'.&mt('Modified').'</th>'.
11460: '<th>'.&mt('Upload replacement?').'</th>'.
11461: &end_data_table_header_row().
11462: $modify_output.
11463: &end_data_table()."\n";
11464: }
11465: if ($delete_output) {
11466: $delete_output = &start_data_table().
11467: &start_data_table_header_row().
11468: '<th>'.&mt('File').'</th>'.
11469: '<th>'.&mt('Size (KB)').'</th>'.
11470: '<th>'.&mt('Modified').'</th>'.
11471: '<th>'.&mt('Delete?').'</th>'.
11472: &end_data_table_header_row().
11473: $delete_output.
11474: &end_data_table()."\n";
11475: }
1.987 raeburn 11476: my $applies = 0;
11477: if ($numremref) {
11478: $applies ++;
11479: }
11480: if ($numinvalid) {
11481: $applies ++;
11482: }
11483: if ($numexisting) {
11484: $applies ++;
11485: }
1.1071 raeburn 11486: if ($counter || $numunused) {
1.987 raeburn 11487: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11488: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11489: $state.'<h3>'.$heading.'</h3>';
11490: if ($actionurl eq '/adm/dependencies') {
11491: if ($numnew) {
11492: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11493: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11494: $upload_output.'<br />'."\n";
11495: }
11496: if ($numexisting) {
11497: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11498: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11499: $modify_output.'<br />'."\n";
11500: $buttontext = &mt('Save changes');
11501: }
11502: if ($numunused) {
11503: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11504: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11505: $delete_output.'<br />'."\n";
11506: $buttontext = &mt('Save changes');
11507: }
11508: } else {
11509: $output .= $upload_output.'<br />'."\n";
11510: }
11511: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11512: $counter.'" />'."\n";
11513: if ($actionurl eq '/adm/dependencies') {
11514: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11515: $numnew.'" />'."\n";
11516: } elsif ($actionurl eq '') {
1.987 raeburn 11517: $output .= '<input type="hidden" name="phase" value="three" />';
11518: }
11519: } elsif ($applies) {
11520: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11521: if ($applies > 1) {
11522: $output .=
1.1123 raeburn 11523: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11524: if ($numremref) {
11525: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11526: }
11527: if ($numinvalid) {
11528: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11529: }
11530: if ($numexisting) {
11531: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11532: }
11533: $output .= '</ul><br />';
11534: } elsif ($numremref) {
11535: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11536: } elsif ($numinvalid) {
11537: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11538: } elsif ($numexisting) {
11539: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11540: }
11541: $output .= $upload_output.'<br />';
11542: }
11543: my ($pathchange_output,$chgcount);
1.1071 raeburn 11544: $chgcount = $counter;
1.987 raeburn 11545: if (keys(%pathchanges) > 0) {
11546: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11547: if ($counter) {
1.987 raeburn 11548: $output .= &embedded_file_element('pathchange',$chgcount,
11549: $embed_file,\%mapping,
1.1071 raeburn 11550: $allfiles,$codebase,'change');
1.987 raeburn 11551: } else {
11552: $pathchange_output .=
11553: &start_data_table_row().
11554: '<td><input type ="checkbox" name="namechange" value="'.
11555: $chgcount.'" checked="checked" /></td>'.
11556: '<td>'.$mapping{$embed_file}.'</td>'.
11557: '<td>'.$embed_file.
11558: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11559: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11560: '</td>'.&end_data_table_row();
1.660 raeburn 11561: }
1.987 raeburn 11562: $numpathchg ++;
11563: $chgcount ++;
1.660 raeburn 11564: }
11565: }
1.1127 raeburn 11566: if (($counter) || ($numunused)) {
1.987 raeburn 11567: if ($numpathchg) {
11568: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11569: $numpathchg.'" />'."\n";
11570: }
11571: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11572: ($actionurl eq '/adm/imsimport')) {
11573: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11574: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11575: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11576: } elsif ($actionurl eq '/adm/dependencies') {
11577: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11578: }
1.1123 raeburn 11579: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11580: } elsif ($numpathchg) {
11581: my %pathchange = ();
11582: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11583: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11584: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11585: }
1.987 raeburn 11586: }
1.1071 raeburn 11587: return ($output,$counter,$numpathchg);
1.987 raeburn 11588: }
11589:
1.1147 raeburn 11590: =pod
11591:
11592: =item * clean_path($name)
11593:
11594: Performs clean-up of directories, subdirectories and filename in an
11595: embedded object, referenced in an HTML file which is being uploaded
11596: to a course or portfolio, where
11597: "Upload embedded images/multimedia files if HTML file" checkbox was
11598: checked.
11599:
11600: Clean-up is similar to replacements in lonnet::clean_filename()
11601: except each / between sub-directory and next level is preserved.
11602:
11603: =cut
11604:
11605: sub clean_path {
11606: my ($embed_file) = @_;
11607: $embed_file =~s{^/+}{};
11608: my @contents;
11609: if ($embed_file =~ m{/}) {
11610: @contents = split(/\//,$embed_file);
11611: } else {
11612: @contents = ($embed_file);
11613: }
11614: my $lastidx = scalar(@contents)-1;
11615: for (my $i=0; $i<=$lastidx; $i++) {
11616: $contents[$i]=~s{\\}{/}g;
11617: $contents[$i]=~s/\s+/\_/g;
11618: $contents[$i]=~s{[^/\w\.\-]}{}g;
11619: if ($i == $lastidx) {
11620: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11621: }
11622: }
11623: if ($lastidx > 0) {
11624: return join('/',@contents);
11625: } else {
11626: return $contents[0];
11627: }
11628: }
11629:
1.987 raeburn 11630: sub embedded_file_element {
1.1071 raeburn 11631: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11632: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11633: (ref($codebase) eq 'HASH'));
11634: my $output;
1.1071 raeburn 11635: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11636: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11637: }
11638: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11639: &escape($embed_file).'" />';
11640: unless (($context eq 'upload_embedded') &&
11641: ($mapping->{$embed_file} eq $embed_file)) {
11642: $output .='
11643: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11644: }
11645: my $attrib;
11646: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11647: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11648: }
11649: $output .=
11650: "\n\t\t".
11651: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11652: $attrib.'" />';
11653: if (exists($codebase->{$mapping->{$embed_file}})) {
11654: $output .=
11655: "\n\t\t".
11656: '<input name="codebase_'.$num.'" type="hidden" value="'.
11657: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11658: }
1.987 raeburn 11659: return $output;
1.660 raeburn 11660: }
11661:
1.1071 raeburn 11662: sub get_dependency_details {
11663: my ($currfile,$currsubfile,$embed_file) = @_;
11664: my ($size,$mtime,$showsize,$showmtime);
11665: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11666: if ($embed_file =~ m{/}) {
11667: my ($path,$fname) = split(/\//,$embed_file);
11668: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11669: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11670: }
11671: } else {
11672: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11673: ($size,$mtime) = @{$currfile->{$embed_file}};
11674: }
11675: }
11676: $showsize = $size/1024.0;
11677: $showsize = sprintf("%.1f",$showsize);
11678: if ($mtime > 0) {
11679: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11680: }
11681: }
11682: return ($showsize,$showmtime);
11683: }
11684:
11685: sub ask_embedded_js {
11686: return <<"END";
11687: <script type="text/javascript"">
11688: // <![CDATA[
11689: function toggleBrowse(counter) {
11690: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11691: var fileid = document.getElementById('embedded_item_'+counter);
11692: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11693: if (chkboxid.checked == true) {
11694: uploaddivid.style.display='block';
11695: } else {
11696: uploaddivid.style.display='none';
11697: fileid.value = '';
11698: }
11699: }
11700: // ]]>
11701: </script>
11702:
11703: END
11704: }
11705:
1.661 raeburn 11706: sub upload_embedded {
11707: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11708: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11709: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11710: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11711: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11712: my $orig_uploaded_filename =
11713: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11714: foreach my $type ('orig','ref','attrib','codebase') {
11715: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11716: $env{'form.embedded_'.$type.'_'.$i} =
11717: &unescape($env{'form.embedded_'.$type.'_'.$i});
11718: }
11719: }
1.661 raeburn 11720: my ($path,$fname) =
11721: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11722: # no path, whole string is fname
11723: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11724: $fname = &Apache::lonnet::clean_filename($fname);
11725: # See if there is anything left
11726: next if ($fname eq '');
11727:
11728: # Check if file already exists as a file or directory.
11729: my ($state,$msg);
11730: if ($context eq 'portfolio') {
11731: my $port_path = $dirpath;
11732: if ($group ne '') {
11733: $port_path = "groups/$group/$port_path";
11734: }
1.987 raeburn 11735: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11736: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11737: $dir_root,$port_path,$disk_quota,
11738: $current_disk_usage,$uname,$udom);
11739: if ($state eq 'will_exceed_quota'
1.984 raeburn 11740: || $state eq 'file_locked') {
1.661 raeburn 11741: $output .= $msg;
11742: next;
11743: }
11744: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11745: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11746: if ($state eq 'exists') {
11747: $output .= $msg;
11748: next;
11749: }
11750: }
11751: # Check if extension is valid
11752: if (($fname =~ /\.(\w+)$/) &&
11753: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11754: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11755: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11756: next;
11757: } elsif (($fname =~ /\.(\w+)$/) &&
11758: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11759: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11760: next;
11761: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11762: $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 11763: next;
11764: }
11765: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11766: my $subdir = $path;
11767: $subdir =~ s{/+$}{};
1.661 raeburn 11768: if ($context eq 'portfolio') {
1.984 raeburn 11769: my $result;
11770: if ($state eq 'existingfile') {
11771: $result=
11772: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11773: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11774: } else {
1.984 raeburn 11775: $result=
11776: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11777: $dirpath.
1.1123 raeburn 11778: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11779: if ($result !~ m|^/uploaded/|) {
11780: $output .= '<span class="LC_error">'
11781: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11782: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11783: .'</span><br />';
11784: next;
11785: } else {
1.987 raeburn 11786: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11787: $path.$fname.'</span>').'<br />';
1.984 raeburn 11788: }
1.661 raeburn 11789: }
1.1123 raeburn 11790: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 11791: my $extendedsubdir = $dirpath.'/'.$subdir;
11792: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11793: my $result =
1.1126 raeburn 11794: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11795: if ($result !~ m|^/uploaded/|) {
11796: $output .= '<span class="LC_error">'
11797: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11798: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11799: .'</span><br />';
11800: next;
11801: } else {
11802: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11803: $path.$fname.'</span>').'<br />';
1.1125 raeburn 11804: if ($context eq 'syllabus') {
11805: &Apache::lonnet::make_public_indefinitely($result);
11806: }
1.987 raeburn 11807: }
1.661 raeburn 11808: } else {
11809: # Save the file
11810: my $target = $env{'form.embedded_item_'.$i};
11811: my $fullpath = $dir_root.$dirpath.'/'.$path;
11812: my $dest = $fullpath.$fname;
11813: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11814: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11815: my $count;
11816: my $filepath = $dir_root;
1.1027 raeburn 11817: foreach my $subdir (@parts) {
11818: $filepath .= "/$subdir";
11819: if (!-e $filepath) {
1.661 raeburn 11820: mkdir($filepath,0770);
11821: }
11822: }
11823: my $fh;
11824: if (!open($fh,'>'.$dest)) {
11825: &Apache::lonnet::logthis('Failed to create '.$dest);
11826: $output .= '<span class="LC_error">'.
1.1071 raeburn 11827: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11828: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11829: '</span><br />';
11830: } else {
11831: if (!print $fh $env{'form.embedded_item_'.$i}) {
11832: &Apache::lonnet::logthis('Failed to write to '.$dest);
11833: $output .= '<span class="LC_error">'.
1.1071 raeburn 11834: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11835: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11836: '</span><br />';
11837: } else {
1.987 raeburn 11838: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11839: $url.'</span>').'<br />';
11840: unless ($context eq 'testbank') {
11841: $footer .= &mt('View embedded file: [_1]',
11842: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11843: }
11844: }
11845: close($fh);
11846: }
11847: }
11848: if ($env{'form.embedded_ref_'.$i}) {
11849: $pathchange{$i} = 1;
11850: }
11851: }
11852: if ($output) {
11853: $output = '<p>'.$output.'</p>';
11854: }
11855: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11856: $returnflag = 'ok';
1.1071 raeburn 11857: my $numpathchgs = scalar(keys(%pathchange));
11858: if ($numpathchgs > 0) {
1.987 raeburn 11859: if ($context eq 'portfolio') {
11860: $output .= '<p>'.&mt('or').'</p>';
11861: } elsif ($context eq 'testbank') {
1.1071 raeburn 11862: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11863: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11864: $returnflag = 'modify_orightml';
11865: }
11866: }
1.1071 raeburn 11867: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11868: }
11869:
11870: sub modify_html_form {
11871: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11872: my $end = 0;
11873: my $modifyform;
11874: if ($context eq 'upload_embedded') {
11875: return unless (ref($pathchange) eq 'HASH');
11876: if ($env{'form.number_embedded_items'}) {
11877: $end += $env{'form.number_embedded_items'};
11878: }
11879: if ($env{'form.number_pathchange_items'}) {
11880: $end += $env{'form.number_pathchange_items'};
11881: }
11882: if ($end) {
11883: for (my $i=0; $i<$end; $i++) {
11884: if ($i < $env{'form.number_embedded_items'}) {
11885: next unless($pathchange->{$i});
11886: }
11887: $modifyform .=
11888: &start_data_table_row().
11889: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11890: 'checked="checked" /></td>'.
11891: '<td>'.$env{'form.embedded_ref_'.$i}.
11892: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11893: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11894: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11895: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11896: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11897: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11898: '<td>'.$env{'form.embedded_orig_'.$i}.
11899: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11900: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11901: &end_data_table_row();
1.1071 raeburn 11902: }
1.987 raeburn 11903: }
11904: } else {
11905: $modifyform = $pathchgtable;
11906: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11907: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11908: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11909: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11910: }
11911: }
11912: if ($modifyform) {
1.1071 raeburn 11913: if ($actionurl eq '/adm/dependencies') {
11914: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11915: }
1.987 raeburn 11916: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11917: '<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".
11918: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11919: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11920: '</ol></p>'."\n".'<p>'.
11921: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11922: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11923: &start_data_table()."\n".
11924: &start_data_table_header_row().
11925: '<th>'.&mt('Change?').'</th>'.
11926: '<th>'.&mt('Current reference').'</th>'.
11927: '<th>'.&mt('Required reference').'</th>'.
11928: &end_data_table_header_row()."\n".
11929: $modifyform.
11930: &end_data_table().'<br />'."\n".$hiddenstate.
11931: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11932: '</form>'."\n";
11933: }
11934: return;
11935: }
11936:
11937: sub modify_html_refs {
1.1123 raeburn 11938: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11939: my $container;
11940: if ($context eq 'portfolio') {
11941: $container = $env{'form.container'};
11942: } elsif ($context eq 'coursedoc') {
11943: $container = $env{'form.primaryurl'};
1.1071 raeburn 11944: } elsif ($context eq 'manage_dependencies') {
11945: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11946: $container = "/$container";
1.1123 raeburn 11947: } elsif ($context eq 'syllabus') {
11948: $container = $url;
1.987 raeburn 11949: } else {
1.1027 raeburn 11950: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11951: }
11952: my (%allfiles,%codebase,$output,$content);
11953: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 11954: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11955: if (wantarray) {
11956: return ('',0,0);
11957: } else {
11958: return;
11959: }
11960: }
11961: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11962: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11963: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11964: if (wantarray) {
11965: return ('',0,0);
11966: } else {
11967: return;
11968: }
11969: }
1.987 raeburn 11970: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11971: if ($content eq '-1') {
11972: if (wantarray) {
11973: return ('',0,0);
11974: } else {
11975: return;
11976: }
11977: }
1.987 raeburn 11978: } else {
1.1071 raeburn 11979: unless ($container =~ /^\Q$dir_root\E/) {
11980: if (wantarray) {
11981: return ('',0,0);
11982: } else {
11983: return;
11984: }
11985: }
1.987 raeburn 11986: if (open(my $fh,"<$container")) {
11987: $content = join('', <$fh>);
11988: close($fh);
11989: } else {
1.1071 raeburn 11990: if (wantarray) {
11991: return ('',0,0);
11992: } else {
11993: return;
11994: }
1.987 raeburn 11995: }
11996: }
11997: my ($count,$codebasecount) = (0,0);
11998: my $mm = new File::MMagic;
11999: my $mime_type = $mm->checktype_contents($content);
12000: if ($mime_type eq 'text/html') {
12001: my $parse_result =
12002: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12003: \%codebase,\$content);
12004: if ($parse_result eq 'ok') {
12005: foreach my $i (@changes) {
12006: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12007: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12008: if ($allfiles{$ref}) {
12009: my $newname = $orig;
12010: my ($attrib_regexp,$codebase);
1.1006 raeburn 12011: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12012: if ($attrib_regexp =~ /:/) {
12013: $attrib_regexp =~ s/\:/|/g;
12014: }
12015: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12016: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12017: $count += $numchg;
1.1123 raeburn 12018: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12019: delete($allfiles{$ref});
1.987 raeburn 12020: }
12021: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12022: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12023: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12024: $codebasecount ++;
12025: }
12026: }
12027: }
1.1123 raeburn 12028: my $skiprewrites;
1.987 raeburn 12029: if ($count || $codebasecount) {
12030: my $saveresult;
1.1071 raeburn 12031: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12032: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12033: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12034: if ($url eq $container) {
12035: my ($fname) = ($container =~ m{/([^/]+)$});
12036: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12037: $count,'<span class="LC_filename">'.
1.1071 raeburn 12038: $fname.'</span>').'</p>';
1.987 raeburn 12039: } else {
12040: $output = '<p class="LC_error">'.
12041: &mt('Error: update failed for: [_1].',
12042: '<span class="LC_filename">'.
12043: $container.'</span>').'</p>';
12044: }
1.1123 raeburn 12045: if ($context eq 'syllabus') {
12046: unless ($saveresult eq 'ok') {
12047: $skiprewrites = 1;
12048: }
12049: }
1.987 raeburn 12050: } else {
12051: if (open(my $fh,">$container")) {
12052: print $fh $content;
12053: close($fh);
12054: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12055: $count,'<span class="LC_filename">'.
12056: $container.'</span>').'</p>';
1.661 raeburn 12057: } else {
1.987 raeburn 12058: $output = '<p class="LC_error">'.
12059: &mt('Error: could not update [_1].',
12060: '<span class="LC_filename">'.
12061: $container.'</span>').'</p>';
1.661 raeburn 12062: }
12063: }
12064: }
1.1123 raeburn 12065: if (($context eq 'syllabus') && (!$skiprewrites)) {
12066: my ($actionurl,$state);
12067: $actionurl = "/public/$udom/$uname/syllabus";
12068: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12069: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12070: \%codebase,
12071: {'context' => 'rewrites',
12072: 'ignore_remote_references' => 1,});
12073: if (ref($mapping) eq 'HASH') {
12074: my $rewrites = 0;
12075: foreach my $key (keys(%{$mapping})) {
12076: next if ($key =~ m{^https?://});
12077: my $ref = $mapping->{$key};
12078: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12079: my $attrib;
12080: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12081: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12082: }
12083: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12084: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12085: $rewrites += $numchg;
12086: }
12087: }
12088: if ($rewrites) {
12089: my $saveresult;
12090: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12091: if ($url eq $container) {
12092: my ($fname) = ($container =~ m{/([^/]+)$});
12093: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12094: $count,'<span class="LC_filename">'.
12095: $fname.'</span>').'</p>';
12096: } else {
12097: $output .= '<p class="LC_error">'.
12098: &mt('Error: could not update links in [_1].',
12099: '<span class="LC_filename">'.
12100: $container.'</span>').'</p>';
12101:
12102: }
12103: }
12104: }
12105: }
1.987 raeburn 12106: } else {
12107: &logthis('Failed to parse '.$container.
12108: ' to modify references: '.$parse_result);
1.661 raeburn 12109: }
12110: }
1.1071 raeburn 12111: if (wantarray) {
12112: return ($output,$count,$codebasecount);
12113: } else {
12114: return $output;
12115: }
1.661 raeburn 12116: }
12117:
12118: sub check_for_existing {
12119: my ($path,$fname,$element) = @_;
12120: my ($state,$msg);
12121: if (-d $path.'/'.$fname) {
12122: $state = 'exists';
12123: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12124: } elsif (-e $path.'/'.$fname) {
12125: $state = 'exists';
12126: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12127: }
12128: if ($state eq 'exists') {
12129: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12130: }
12131: return ($state,$msg);
12132: }
12133:
12134: sub check_for_upload {
12135: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12136: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12137: my $filesize = length($env{'form.'.$element});
12138: if (!$filesize) {
12139: my $msg = '<span class="LC_error">'.
12140: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12141: '<span class="LC_filename">'.$fname.'</span>',
12142: $filesize).'<br />'.
1.1007 raeburn 12143: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12144: '</span>';
12145: return ('zero_bytes',$msg);
12146: }
12147: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12148: my $getpropath = 1;
1.1021 raeburn 12149: my ($dirlistref,$listerror) =
12150: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12151: my $found_file = 0;
12152: my $locked_file = 0;
1.991 raeburn 12153: my @lockers;
12154: my $navmap;
12155: if ($env{'request.course.id'}) {
12156: $navmap = Apache::lonnavmaps::navmap->new();
12157: }
1.1021 raeburn 12158: if (ref($dirlistref) eq 'ARRAY') {
12159: foreach my $line (@{$dirlistref}) {
12160: my ($file_name,$rest)=split(/\&/,$line,2);
12161: if ($file_name eq $fname){
12162: $file_name = $path.$file_name;
12163: if ($group ne '') {
12164: $file_name = $group.$file_name;
12165: }
12166: $found_file = 1;
12167: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12168: foreach my $lock (@lockers) {
12169: if (ref($lock) eq 'ARRAY') {
12170: my ($symb,$crsid) = @{$lock};
12171: if ($crsid eq $env{'request.course.id'}) {
12172: if (ref($navmap)) {
12173: my $res = $navmap->getBySymb($symb);
12174: foreach my $part (@{$res->parts()}) {
12175: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12176: unless (($slot_status == $res->RESERVED) ||
12177: ($slot_status == $res->RESERVED_LOCATION)) {
12178: $locked_file = 1;
12179: }
1.991 raeburn 12180: }
1.1021 raeburn 12181: } else {
12182: $locked_file = 1;
1.991 raeburn 12183: }
12184: } else {
12185: $locked_file = 1;
12186: }
12187: }
1.1021 raeburn 12188: }
12189: } else {
12190: my @info = split(/\&/,$rest);
12191: my $currsize = $info[6]/1000;
12192: if ($currsize < $filesize) {
12193: my $extra = $filesize - $currsize;
12194: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12195: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12196: &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 12197: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12198: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12199: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12200: return ('will_exceed_quota',$msg);
12201: }
1.984 raeburn 12202: }
12203: }
1.661 raeburn 12204: }
12205: }
12206: }
12207: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12208: my $msg = '<p class="LC_warning">'.
12209: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12210: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12211: return ('will_exceed_quota',$msg);
12212: } elsif ($found_file) {
12213: if ($locked_file) {
1.1179 bisitz 12214: my $msg = '<p class="LC_warning">';
1.661 raeburn 12215: $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 12216: $msg .= '</p>';
1.661 raeburn 12217: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12218: return ('file_locked',$msg);
12219: } else {
1.1179 bisitz 12220: my $msg = '<p class="LC_error">';
1.984 raeburn 12221: $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 12222: $msg .= '</p>';
1.984 raeburn 12223: return ('existingfile',$msg);
1.661 raeburn 12224: }
12225: }
12226: }
12227:
1.987 raeburn 12228: sub check_for_traversal {
12229: my ($path,$url,$toplevel) = @_;
12230: my @parts=split(/\//,$path);
12231: my $cleanpath;
12232: my $fullpath = $url;
12233: for (my $i=0;$i<@parts;$i++) {
12234: next if ($parts[$i] eq '.');
12235: if ($parts[$i] eq '..') {
12236: $fullpath =~ s{([^/]+/)$}{};
12237: } else {
12238: $fullpath .= $parts[$i].'/';
12239: }
12240: }
12241: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12242: $cleanpath = $1;
12243: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12244: my $curr_toprel = $1;
12245: my @parts = split(/\//,$curr_toprel);
12246: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12247: my @urlparts = split(/\//,$url_toprel);
12248: my $doubledots;
12249: my $startdiff = -1;
12250: for (my $i=0; $i<@urlparts; $i++) {
12251: if ($startdiff == -1) {
12252: unless ($urlparts[$i] eq $parts[$i]) {
12253: $startdiff = $i;
12254: $doubledots .= '../';
12255: }
12256: } else {
12257: $doubledots .= '../';
12258: }
12259: }
12260: if ($startdiff > -1) {
12261: $cleanpath = $doubledots;
12262: for (my $i=$startdiff; $i<@parts; $i++) {
12263: $cleanpath .= $parts[$i].'/';
12264: }
12265: }
12266: }
12267: $cleanpath =~ s{(/)$}{};
12268: return $cleanpath;
12269: }
1.31 albertel 12270:
1.1053 raeburn 12271: sub is_archive_file {
12272: my ($mimetype) = @_;
12273: if (($mimetype eq 'application/octet-stream') ||
12274: ($mimetype eq 'application/x-stuffit') ||
12275: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12276: return 1;
12277: }
12278: return;
12279: }
12280:
12281: sub decompress_form {
1.1065 raeburn 12282: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12283: my %lt = &Apache::lonlocal::texthash (
12284: this => 'This file is an archive file.',
1.1067 raeburn 12285: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12286: itsc => 'Its contents are as follows:',
1.1053 raeburn 12287: youm => 'You may wish to extract its contents.',
12288: extr => 'Extract contents',
1.1067 raeburn 12289: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12290: proa => 'Process automatically?',
1.1053 raeburn 12291: yes => 'Yes',
12292: no => 'No',
1.1067 raeburn 12293: fold => 'Title for folder containing movie',
12294: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12295: );
1.1065 raeburn 12296: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12297: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12298: my $info = &list_archive_contents($fileloc,\@paths);
12299: if (@paths) {
12300: foreach my $path (@paths) {
12301: $path =~ s{^/}{};
1.1067 raeburn 12302: if ($path =~ m{^([^/]+)/$}) {
12303: $topdir = $1;
12304: }
1.1065 raeburn 12305: if ($path =~ m{^([^/]+)/}) {
12306: $toplevel{$1} = $path;
12307: } else {
12308: $toplevel{$path} = $path;
12309: }
12310: }
12311: }
1.1067 raeburn 12312: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12313: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12314: "$topdir/media/",
12315: "$topdir/media/$topdir.mp4",
12316: "$topdir/media/FirstFrame.png",
12317: "$topdir/media/player.swf",
12318: "$topdir/media/swfobject.js",
12319: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12320: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12321: "$topdir/$topdir.mp4",
12322: "$topdir/$topdir\_config.xml",
12323: "$topdir/$topdir\_controller.swf",
12324: "$topdir/$topdir\_embed.css",
12325: "$topdir/$topdir\_First_Frame.png",
12326: "$topdir/$topdir\_player.html",
12327: "$topdir/$topdir\_Thumbnails.png",
12328: "$topdir/playerProductInstall.swf",
12329: "$topdir/scripts/",
12330: "$topdir/scripts/config_xml.js",
12331: "$topdir/scripts/handlebars.js",
12332: "$topdir/scripts/jquery-1.7.1.min.js",
12333: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12334: "$topdir/scripts/modernizr.js",
12335: "$topdir/scripts/player-min.js",
12336: "$topdir/scripts/swfobject.js",
12337: "$topdir/skins/",
12338: "$topdir/skins/configuration_express.xml",
12339: "$topdir/skins/express_show/",
12340: "$topdir/skins/express_show/player-min.css",
12341: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12342: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12343: "$topdir/$topdir.mp4",
12344: "$topdir/$topdir\_config.xml",
12345: "$topdir/$topdir\_controller.swf",
12346: "$topdir/$topdir\_embed.css",
12347: "$topdir/$topdir\_First_Frame.png",
12348: "$topdir/$topdir\_player.html",
12349: "$topdir/$topdir\_Thumbnails.png",
12350: "$topdir/playerProductInstall.swf",
12351: "$topdir/scripts/",
12352: "$topdir/scripts/config_xml.js",
12353: "$topdir/scripts/techsmith-smart-player.min.js",
12354: "$topdir/skins/",
12355: "$topdir/skins/configuration_express.xml",
12356: "$topdir/skins/express_show/",
12357: "$topdir/skins/express_show/spritesheet.min.css",
12358: "$topdir/skins/express_show/spritesheet.png",
12359: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12360: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12361: if (@diffs == 0) {
1.1164 raeburn 12362: $is_camtasia = 6;
12363: } else {
1.1197 raeburn 12364: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12365: if (@diffs == 0) {
12366: $is_camtasia = 8;
1.1197 raeburn 12367: } else {
12368: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12369: if (@diffs == 0) {
12370: $is_camtasia = 8;
12371: }
1.1164 raeburn 12372: }
1.1067 raeburn 12373: }
12374: }
12375: my $output;
12376: if ($is_camtasia) {
12377: $output = <<"ENDCAM";
12378: <script type="text/javascript" language="Javascript">
12379: // <![CDATA[
12380:
12381: function camtasiaToggle() {
12382: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12383: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12384: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12385: document.getElementById('camtasia_titles').style.display='block';
12386: } else {
12387: document.getElementById('camtasia_titles').style.display='none';
12388: }
12389: }
12390: }
12391: return;
12392: }
12393:
12394: // ]]>
12395: </script>
12396: <p>$lt{'camt'}</p>
12397: ENDCAM
1.1065 raeburn 12398: } else {
1.1067 raeburn 12399: $output = '<p>'.$lt{'this'};
12400: if ($info eq '') {
12401: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12402: } else {
12403: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12404: '<div><pre>'.$info.'</pre></div>';
12405: }
1.1065 raeburn 12406: }
1.1067 raeburn 12407: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12408: my $duplicates;
12409: my $num = 0;
12410: if (ref($dirlist) eq 'ARRAY') {
12411: foreach my $item (@{$dirlist}) {
12412: if (ref($item) eq 'ARRAY') {
12413: if (exists($toplevel{$item->[0]})) {
12414: $duplicates .=
12415: &start_data_table_row().
12416: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12417: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12418: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12419: 'value="1" />'.&mt('Yes').'</label>'.
12420: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12421: '<td>'.$item->[0].'</td>';
12422: if ($item->[2]) {
12423: $duplicates .= '<td>'.&mt('Directory').'</td>';
12424: } else {
12425: $duplicates .= '<td>'.&mt('File').'</td>';
12426: }
12427: $duplicates .= '<td>'.$item->[3].'</td>'.
12428: '<td>'.
12429: &Apache::lonlocal::locallocaltime($item->[4]).
12430: '</td>'.
12431: &end_data_table_row();
12432: $num ++;
12433: }
12434: }
12435: }
12436: }
12437: my $itemcount;
12438: if (@paths > 0) {
12439: $itemcount = scalar(@paths);
12440: } else {
12441: $itemcount = 1;
12442: }
1.1067 raeburn 12443: if ($is_camtasia) {
12444: $output .= $lt{'auto'}.'<br />'.
12445: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12446: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12447: $lt{'yes'}.'</label> <label>'.
12448: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12449: $lt{'no'}.'</label></span><br />'.
12450: '<div id="camtasia_titles" style="display:block">'.
12451: &Apache::lonhtmlcommon::start_pick_box().
12452: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12453: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12454: &Apache::lonhtmlcommon::row_closure().
12455: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12456: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12457: &Apache::lonhtmlcommon::row_closure(1).
12458: &Apache::lonhtmlcommon::end_pick_box().
12459: '</div>';
12460: }
1.1065 raeburn 12461: $output .=
12462: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12463: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12464: "\n";
1.1065 raeburn 12465: if ($duplicates ne '') {
12466: $output .= '<p><span class="LC_warning">'.
12467: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12468: &start_data_table().
12469: &start_data_table_header_row().
12470: '<th>'.&mt('Overwrite?').'</th>'.
12471: '<th>'.&mt('Name').'</th>'.
12472: '<th>'.&mt('Type').'</th>'.
12473: '<th>'.&mt('Size').'</th>'.
12474: '<th>'.&mt('Last modified').'</th>'.
12475: &end_data_table_header_row().
12476: $duplicates.
12477: &end_data_table().
12478: '</p>';
12479: }
1.1067 raeburn 12480: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12481: if (ref($hiddenelements) eq 'HASH') {
12482: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12483: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12484: }
12485: }
12486: $output .= <<"END";
1.1067 raeburn 12487: <br />
1.1053 raeburn 12488: <input type="submit" name="decompress" value="$lt{'extr'}" />
12489: </form>
12490: $noextract
12491: END
12492: return $output;
12493: }
12494:
1.1065 raeburn 12495: sub decompression_utility {
12496: my ($program) = @_;
12497: my @utilities = ('tar','gunzip','bunzip2','unzip');
12498: my $location;
12499: if (grep(/^\Q$program\E$/,@utilities)) {
12500: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12501: '/usr/sbin/') {
12502: if (-x $dir.$program) {
12503: $location = $dir.$program;
12504: last;
12505: }
12506: }
12507: }
12508: return $location;
12509: }
12510:
12511: sub list_archive_contents {
12512: my ($file,$pathsref) = @_;
12513: my (@cmd,$output);
12514: my $needsregexp;
12515: if ($file =~ /\.zip$/) {
12516: @cmd = (&decompression_utility('unzip'),"-l");
12517: $needsregexp = 1;
12518: } elsif (($file =~ m/\.tar\.gz$/) ||
12519: ($file =~ /\.tgz$/)) {
12520: @cmd = (&decompression_utility('tar'),"-ztf");
12521: } elsif ($file =~ /\.tar\.bz2$/) {
12522: @cmd = (&decompression_utility('tar'),"-jtf");
12523: } elsif ($file =~ m|\.tar$|) {
12524: @cmd = (&decompression_utility('tar'),"-tf");
12525: }
12526: if (@cmd) {
12527: undef($!);
12528: undef($@);
12529: if (open(my $fh,"-|", @cmd, $file)) {
12530: while (my $line = <$fh>) {
12531: $output .= $line;
12532: chomp($line);
12533: my $item;
12534: if ($needsregexp) {
12535: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12536: } else {
12537: $item = $line;
12538: }
12539: if ($item ne '') {
12540: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12541: push(@{$pathsref},$item);
12542: }
12543: }
12544: }
12545: close($fh);
12546: }
12547: }
12548: return $output;
12549: }
12550:
1.1053 raeburn 12551: sub decompress_uploaded_file {
12552: my ($file,$dir) = @_;
12553: &Apache::lonnet::appenv({'cgi.file' => $file});
12554: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12555: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12556: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12557: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12558: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12559: my $decompressed = $env{'cgi.decompressed'};
12560: &Apache::lonnet::delenv('cgi.file');
12561: &Apache::lonnet::delenv('cgi.dir');
12562: &Apache::lonnet::delenv('cgi.decompressed');
12563: return ($decompressed,$result);
12564: }
12565:
1.1055 raeburn 12566: sub process_decompression {
12567: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
12568: my ($dir,$error,$warning,$output);
1.1180 raeburn 12569: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12570: $error = &mt('Filename not a supported archive file type.').
12571: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12572: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12573: } else {
12574: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12575: if ($docuhome eq 'no_host') {
12576: $error = &mt('Could not determine home server for course.');
12577: } else {
12578: my @ids=&Apache::lonnet::current_machine_ids();
12579: my $currdir = "$dir_root/$destination";
12580: if (grep(/^\Q$docuhome\E$/,@ids)) {
12581: $dir = &LONCAPA::propath($docudom,$docuname).
12582: "$dir_root/$destination";
12583: } else {
12584: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12585: "$dir_root/$docudom/$docuname/$destination";
12586: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12587: $error = &mt('Archive file not found.');
12588: }
12589: }
1.1065 raeburn 12590: my (@to_overwrite,@to_skip);
12591: if ($env{'form.archive_overwrite_total'} > 0) {
12592: my $total = $env{'form.archive_overwrite_total'};
12593: for (my $i=0; $i<$total; $i++) {
12594: if ($env{'form.archive_overwrite_'.$i} == 1) {
12595: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12596: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12597: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12598: }
12599: }
12600: }
12601: my $numskip = scalar(@to_skip);
12602: if (($numskip > 0) &&
12603: ($numskip == $env{'form.archive_itemcount'})) {
12604: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12605: } elsif ($dir eq '') {
1.1055 raeburn 12606: $error = &mt('Directory containing archive file unavailable.');
12607: } elsif (!$error) {
1.1065 raeburn 12608: my ($decompressed,$display);
12609: if ($numskip > 0) {
12610: my $tempdir = time.'_'.$$.int(rand(10000));
12611: mkdir("$dir/$tempdir",0755);
12612: system("mv $dir/$file $dir/$tempdir/$file");
12613: ($decompressed,$display) =
12614: &decompress_uploaded_file($file,"$dir/$tempdir");
12615: foreach my $item (@to_skip) {
12616: if (($item ne '') && ($item !~ /\.\./)) {
12617: if (-f "$dir/$tempdir/$item") {
12618: unlink("$dir/$tempdir/$item");
12619: } elsif (-d "$dir/$tempdir/$item") {
12620: system("rm -rf $dir/$tempdir/$item");
12621: }
12622: }
12623: }
12624: system("mv $dir/$tempdir/* $dir");
12625: rmdir("$dir/$tempdir");
12626: } else {
12627: ($decompressed,$display) =
12628: &decompress_uploaded_file($file,$dir);
12629: }
1.1055 raeburn 12630: if ($decompressed eq 'ok') {
1.1065 raeburn 12631: $output = '<p class="LC_info">'.
12632: &mt('Files extracted successfully from archive.').
12633: '</p>'."\n";
1.1055 raeburn 12634: my ($warning,$result,@contents);
12635: my ($newdirlistref,$newlisterror) =
12636: &Apache::lonnet::dirlist($currdir,$docudom,
12637: $docuname,1);
12638: my (%is_dir,%changes,@newitems);
12639: my $dirptr = 16384;
1.1065 raeburn 12640: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12641: foreach my $dir_line (@{$newdirlistref}) {
12642: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 12643: unless (($item =~ /^\.+$/) || ($item eq $file) ||
12644: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 12645: push(@newitems,$item);
12646: if ($dirptr&$testdir) {
12647: $is_dir{$item} = 1;
12648: }
12649: $changes{$item} = 1;
12650: }
12651: }
12652: }
12653: if (keys(%changes) > 0) {
12654: foreach my $item (sort(@newitems)) {
12655: if ($changes{$item}) {
12656: push(@contents,$item);
12657: }
12658: }
12659: }
12660: if (@contents > 0) {
1.1067 raeburn 12661: my $wantform;
12662: unless ($env{'form.autoextract_camtasia'}) {
12663: $wantform = 1;
12664: }
1.1056 raeburn 12665: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12666: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12667: $currdir,\%is_dir,
12668: \%children,\%parent,
1.1056 raeburn 12669: \@contents,\%dirorder,
12670: \%titles,$wantform);
1.1055 raeburn 12671: if ($datatable ne '') {
12672: $output .= &archive_options_form('decompressed',$datatable,
12673: $count,$hiddenelem);
1.1065 raeburn 12674: my $startcount = 6;
1.1055 raeburn 12675: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12676: \%titles,\%children);
1.1055 raeburn 12677: }
1.1067 raeburn 12678: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 12679: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12680: my %displayed;
12681: my $total = 1;
12682: $env{'form.archive_directory'} = [];
12683: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12684: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12685: $path =~ s{/$}{};
12686: my $item;
12687: if ($path ne '') {
12688: $item = "$path/$titles{$i}";
12689: } else {
12690: $item = $titles{$i};
12691: }
12692: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12693: if ($item eq $contents[0]) {
12694: push(@{$env{'form.archive_directory'}},$i);
12695: $env{'form.archive_'.$i} = 'display';
12696: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12697: $displayed{'folder'} = $i;
1.1164 raeburn 12698: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12699: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12700: $env{'form.archive_'.$i} = 'display';
12701: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12702: $displayed{'web'} = $i;
12703: } else {
1.1164 raeburn 12704: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12705: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12706: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12707: push(@{$env{'form.archive_directory'}},$i);
12708: }
12709: $env{'form.archive_'.$i} = 'dependency';
12710: }
12711: $total ++;
12712: }
12713: for (my $i=1; $i<$total; $i++) {
12714: next if ($i == $displayed{'web'});
12715: next if ($i == $displayed{'folder'});
12716: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12717: }
12718: $env{'form.phase'} = 'decompress_cleanup';
12719: $env{'form.archivedelete'} = 1;
12720: $env{'form.archive_count'} = $total-1;
12721: $output .=
12722: &process_extracted_files('coursedocs',$docudom,
12723: $docuname,$destination,
12724: $dir_root,$hiddenelem);
12725: }
1.1055 raeburn 12726: } else {
12727: $warning = &mt('No new items extracted from archive file.');
12728: }
12729: } else {
12730: $output = $display;
12731: $error = &mt('An error occurred during extraction from the archive file.');
12732: }
12733: }
12734: }
12735: }
12736: if ($error) {
12737: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12738: $error.'</p>'."\n";
12739: }
12740: if ($warning) {
12741: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12742: }
12743: return $output;
12744: }
12745:
12746: sub get_extracted {
1.1056 raeburn 12747: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12748: $titles,$wantform) = @_;
1.1055 raeburn 12749: my $count = 0;
12750: my $depth = 0;
12751: my $datatable;
1.1056 raeburn 12752: my @hierarchy;
1.1055 raeburn 12753: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12754: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12755: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12756: foreach my $item (@{$contents}) {
12757: $count ++;
1.1056 raeburn 12758: @{$dirorder->{$count}} = @hierarchy;
12759: $titles->{$count} = $item;
1.1055 raeburn 12760: &archive_hierarchy($depth,$count,$parent,$children);
12761: if ($wantform) {
12762: $datatable .= &archive_row($is_dir->{$item},$item,
12763: $currdir,$depth,$count);
12764: }
12765: if ($is_dir->{$item}) {
12766: $depth ++;
1.1056 raeburn 12767: push(@hierarchy,$count);
12768: $parent->{$depth} = $count;
1.1055 raeburn 12769: $datatable .=
12770: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12771: \$depth,\$count,\@hierarchy,$dirorder,
12772: $children,$parent,$titles,$wantform);
1.1055 raeburn 12773: $depth --;
1.1056 raeburn 12774: pop(@hierarchy);
1.1055 raeburn 12775: }
12776: }
12777: return ($count,$datatable);
12778: }
12779:
12780: sub recurse_extracted_archive {
1.1056 raeburn 12781: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12782: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12783: my $result='';
1.1056 raeburn 12784: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12785: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12786: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12787: return $result;
12788: }
12789: my $dirptr = 16384;
12790: my ($newdirlistref,$newlisterror) =
12791: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12792: if (ref($newdirlistref) eq 'ARRAY') {
12793: foreach my $dir_line (@{$newdirlistref}) {
12794: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12795: unless ($item =~ /^\.+$/) {
12796: $$count ++;
1.1056 raeburn 12797: @{$dirorder->{$$count}} = @{$hierarchy};
12798: $titles->{$$count} = $item;
1.1055 raeburn 12799: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12800:
1.1055 raeburn 12801: my $is_dir;
12802: if ($dirptr&$testdir) {
12803: $is_dir = 1;
12804: }
12805: if ($wantform) {
12806: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12807: }
12808: if ($is_dir) {
12809: $$depth ++;
1.1056 raeburn 12810: push(@{$hierarchy},$$count);
12811: $parent->{$$depth} = $$count;
1.1055 raeburn 12812: $result .=
12813: &recurse_extracted_archive("$currdir/$item",$docudom,
12814: $docuname,$depth,$count,
1.1056 raeburn 12815: $hierarchy,$dirorder,$children,
12816: $parent,$titles,$wantform);
1.1055 raeburn 12817: $$depth --;
1.1056 raeburn 12818: pop(@{$hierarchy});
1.1055 raeburn 12819: }
12820: }
12821: }
12822: }
12823: return $result;
12824: }
12825:
12826: sub archive_hierarchy {
12827: my ($depth,$count,$parent,$children) =@_;
12828: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12829: if (exists($parent->{$depth})) {
12830: $children->{$parent->{$depth}} .= $count.':';
12831: }
12832: }
12833: return;
12834: }
12835:
12836: sub archive_row {
12837: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12838: my ($name) = ($item =~ m{([^/]+)$});
12839: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12840: 'display' => 'Add as file',
1.1055 raeburn 12841: 'dependency' => 'Include as dependency',
12842: 'discard' => 'Discard',
12843: );
12844: if ($is_dir) {
1.1059 raeburn 12845: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12846: }
1.1056 raeburn 12847: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12848: my $offset = 0;
1.1055 raeburn 12849: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12850: $offset ++;
1.1065 raeburn 12851: if ($action ne 'display') {
12852: $offset ++;
12853: }
1.1055 raeburn 12854: $output .= '<td><span class="LC_nobreak">'.
12855: '<label><input type="radio" name="archive_'.$count.
12856: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12857: my $text = $choices{$action};
12858: if ($is_dir) {
12859: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12860: if ($action eq 'display') {
1.1059 raeburn 12861: $text = &mt('Add as folder');
1.1055 raeburn 12862: }
1.1056 raeburn 12863: } else {
12864: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12865:
12866: }
12867: $output .= ' /> '.$choices{$action}.'</label></span>';
12868: if ($action eq 'dependency') {
12869: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12870: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12871: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12872: '<option value=""></option>'."\n".
12873: '</select>'."\n".
12874: '</div>';
1.1059 raeburn 12875: } elsif ($action eq 'display') {
12876: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12877: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12878: '</div>';
1.1055 raeburn 12879: }
1.1056 raeburn 12880: $output .= '</td>';
1.1055 raeburn 12881: }
12882: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12883: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12884: for (my $i=0; $i<$depth; $i++) {
12885: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12886: }
12887: if ($is_dir) {
12888: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12889: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12890: } else {
12891: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12892: }
12893: $output .= ' '.$name.'</td>'."\n".
12894: &end_data_table_row();
12895: return $output;
12896: }
12897:
12898: sub archive_options_form {
1.1065 raeburn 12899: my ($form,$display,$count,$hiddenelem) = @_;
12900: my %lt = &Apache::lonlocal::texthash(
12901: perm => 'Permanently remove archive file?',
12902: hows => 'How should each extracted item be incorporated in the course?',
12903: cont => 'Content actions for all',
12904: addf => 'Add as folder/file',
12905: incd => 'Include as dependency for a displayed file',
12906: disc => 'Discard',
12907: no => 'No',
12908: yes => 'Yes',
12909: save => 'Save',
12910: );
12911: my $output = <<"END";
12912: <form name="$form" method="post" action="">
12913: <p><span class="LC_nobreak">$lt{'perm'}
12914: <label>
12915: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12916: </label>
12917:
12918: <label>
12919: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12920: </span>
12921: </p>
12922: <input type="hidden" name="phase" value="decompress_cleanup" />
12923: <br />$lt{'hows'}
12924: <div class="LC_columnSection">
12925: <fieldset>
12926: <legend>$lt{'cont'}</legend>
12927: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12928: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12929: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12930: </fieldset>
12931: </div>
12932: END
12933: return $output.
1.1055 raeburn 12934: &start_data_table()."\n".
1.1065 raeburn 12935: $display."\n".
1.1055 raeburn 12936: &end_data_table()."\n".
12937: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12938: $hiddenelem.
1.1065 raeburn 12939: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12940: '</form>';
12941: }
12942:
12943: sub archive_javascript {
1.1056 raeburn 12944: my ($startcount,$numitems,$titles,$children) = @_;
12945: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12946: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12947: my $scripttag = <<START;
12948: <script type="text/javascript">
12949: // <![CDATA[
12950:
12951: function checkAll(form,prefix) {
12952: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12953: for (var i=0; i < form.elements.length; i++) {
12954: var id = form.elements[i].id;
12955: if ((id != '') && (id != undefined)) {
12956: if (idstr.test(id)) {
12957: if (form.elements[i].type == 'radio') {
12958: form.elements[i].checked = true;
1.1056 raeburn 12959: var nostart = i-$startcount;
1.1059 raeburn 12960: var offset = nostart%7;
12961: var count = (nostart-offset)/7;
1.1056 raeburn 12962: dependencyCheck(form,count,offset);
1.1055 raeburn 12963: }
12964: }
12965: }
12966: }
12967: }
12968:
12969: function propagateCheck(form,count) {
12970: if (count > 0) {
1.1059 raeburn 12971: var startelement = $startcount + ((count-1) * 7);
12972: for (var j=1; j<6; j++) {
12973: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12974: var item = startelement + j;
12975: if (form.elements[item].type == 'radio') {
12976: if (form.elements[item].checked) {
12977: containerCheck(form,count,j);
12978: break;
12979: }
1.1055 raeburn 12980: }
12981: }
12982: }
12983: }
12984: }
12985:
12986: numitems = $numitems
1.1056 raeburn 12987: var titles = new Array(numitems);
12988: var parents = new Array(numitems);
1.1055 raeburn 12989: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12990: parents[i] = new Array;
1.1055 raeburn 12991: }
1.1059 raeburn 12992: var maintitle = '$maintitle';
1.1055 raeburn 12993:
12994: START
12995:
1.1056 raeburn 12996: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12997: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12998: for (my $i=0; $i<@contents; $i ++) {
12999: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13000: }
13001: }
13002:
1.1056 raeburn 13003: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13004: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13005: }
13006:
1.1055 raeburn 13007: $scripttag .= <<END;
13008:
13009: function containerCheck(form,count,offset) {
13010: if (count > 0) {
1.1056 raeburn 13011: dependencyCheck(form,count,offset);
1.1059 raeburn 13012: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13013: form.elements[item].checked = true;
13014: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13015: if (parents[count].length > 0) {
13016: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13017: containerCheck(form,parents[count][j],offset);
13018: }
13019: }
13020: }
13021: }
13022: }
13023:
13024: function dependencyCheck(form,count,offset) {
13025: if (count > 0) {
1.1059 raeburn 13026: var chosen = (offset+$startcount)+7*(count-1);
13027: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13028: var currtype = form.elements[depitem].type;
13029: if (form.elements[chosen].value == 'dependency') {
13030: document.getElementById('arc_depon_'+count).style.display='block';
13031: form.elements[depitem].options.length = 0;
13032: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13033: for (var i=1; i<=numitems; i++) {
13034: if (i == count) {
13035: continue;
13036: }
1.1059 raeburn 13037: var startelement = $startcount + (i-1) * 7;
13038: for (var j=1; j<6; j++) {
13039: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13040: var item = startelement + j;
13041: if (form.elements[item].type == 'radio') {
13042: if (form.elements[item].checked) {
13043: if (form.elements[item].value == 'display') {
13044: var n = form.elements[depitem].options.length;
13045: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13046: }
13047: }
13048: }
13049: }
13050: }
13051: }
13052: } else {
13053: document.getElementById('arc_depon_'+count).style.display='none';
13054: form.elements[depitem].options.length = 0;
13055: form.elements[depitem].options[0] = new Option('Select','',true,true);
13056: }
1.1059 raeburn 13057: titleCheck(form,count,offset);
1.1056 raeburn 13058: }
13059: }
13060:
13061: function propagateSelect(form,count,offset) {
13062: if (count > 0) {
1.1065 raeburn 13063: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13064: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13065: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13066: if (parents[count].length > 0) {
13067: for (var j=0; j<parents[count].length; j++) {
13068: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13069: }
13070: }
13071: }
13072: }
13073: }
1.1056 raeburn 13074:
13075: function containerSelect(form,count,offset,picked) {
13076: if (count > 0) {
1.1065 raeburn 13077: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13078: if (form.elements[item].type == 'radio') {
13079: if (form.elements[item].value == 'dependency') {
13080: if (form.elements[item+1].type == 'select-one') {
13081: for (var i=0; i<form.elements[item+1].options.length; i++) {
13082: if (form.elements[item+1].options[i].value == picked) {
13083: form.elements[item+1].selectedIndex = i;
13084: break;
13085: }
13086: }
13087: }
13088: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13089: if (parents[count].length > 0) {
13090: for (var j=0; j<parents[count].length; j++) {
13091: containerSelect(form,parents[count][j],offset,picked);
13092: }
13093: }
13094: }
13095: }
13096: }
13097: }
13098: }
13099:
1.1059 raeburn 13100: function titleCheck(form,count,offset) {
13101: if (count > 0) {
13102: var chosen = (offset+$startcount)+7*(count-1);
13103: var depitem = $startcount + ((count-1) * 7) + 2;
13104: var currtype = form.elements[depitem].type;
13105: if (form.elements[chosen].value == 'display') {
13106: document.getElementById('arc_title_'+count).style.display='block';
13107: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13108: document.getElementById('archive_title_'+count).value=maintitle;
13109: }
13110: } else {
13111: document.getElementById('arc_title_'+count).style.display='none';
13112: if (currtype == 'text') {
13113: document.getElementById('archive_title_'+count).value='';
13114: }
13115: }
13116: }
13117: return;
13118: }
13119:
1.1055 raeburn 13120: // ]]>
13121: </script>
13122: END
13123: return $scripttag;
13124: }
13125:
13126: sub process_extracted_files {
1.1067 raeburn 13127: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13128: my $numitems = $env{'form.archive_count'};
13129: return unless ($numitems);
13130: my @ids=&Apache::lonnet::current_machine_ids();
13131: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13132: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13133: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13134: if (grep(/^\Q$docuhome\E$/,@ids)) {
13135: $prefix = &LONCAPA::propath($docudom,$docuname);
13136: $pathtocheck = "$dir_root/$destination";
13137: $dir = $dir_root;
13138: $ishome = 1;
13139: } else {
13140: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13141: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
13142: $dir = "$dir_root/$docudom/$docuname";
13143: }
13144: my $currdir = "$dir_root/$destination";
13145: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13146: if ($env{'form.folderpath'}) {
13147: my @items = split('&',$env{'form.folderpath'});
13148: $folders{'0'} = $items[-2];
1.1099 raeburn 13149: if ($env{'form.folderpath'} =~ /\:1$/) {
13150: $containers{'0'}='page';
13151: } else {
13152: $containers{'0'}='sequence';
13153: }
1.1055 raeburn 13154: }
13155: my @archdirs = &get_env_multiple('form.archive_directory');
13156: if ($numitems) {
13157: for (my $i=1; $i<=$numitems; $i++) {
13158: my $path = $env{'form.archive_content_'.$i};
13159: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13160: my $item = $1;
13161: $toplevelitems{$item} = $i;
13162: if (grep(/^\Q$i\E$/,@archdirs)) {
13163: $is_dir{$item} = 1;
13164: }
13165: }
13166: }
13167: }
1.1067 raeburn 13168: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13169: if (keys(%toplevelitems) > 0) {
13170: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13171: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13172: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13173: }
1.1066 raeburn 13174: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13175: if ($numitems) {
13176: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13177: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13178: my $path = $env{'form.archive_content_'.$i};
13179: if ($path =~ /^\Q$pathtocheck\E/) {
13180: if ($env{'form.archive_'.$i} eq 'discard') {
13181: if ($prefix ne '' && $path ne '') {
13182: if (-e $prefix.$path) {
1.1066 raeburn 13183: if ((@archdirs > 0) &&
13184: (grep(/^\Q$i\E$/,@archdirs))) {
13185: $todeletedir{$prefix.$path} = 1;
13186: } else {
13187: $todelete{$prefix.$path} = 1;
13188: }
1.1055 raeburn 13189: }
13190: }
13191: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13192: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13193: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13194: $docstitle = $env{'form.archive_title_'.$i};
13195: if ($docstitle eq '') {
13196: $docstitle = $title;
13197: }
1.1055 raeburn 13198: $outer = 0;
1.1056 raeburn 13199: if (ref($dirorder{$i}) eq 'ARRAY') {
13200: if (@{$dirorder{$i}} > 0) {
13201: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13202: if ($env{'form.archive_'.$item} eq 'display') {
13203: $outer = $item;
13204: last;
13205: }
13206: }
13207: }
13208: }
13209: my ($errtext,$fatal) =
13210: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13211: '/'.$folders{$outer}.'.'.
13212: $containers{$outer});
13213: next if ($fatal);
13214: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13215: if ($context eq 'coursedocs') {
1.1056 raeburn 13216: $mapinner{$i} = time;
1.1055 raeburn 13217: $folders{$i} = 'default_'.$mapinner{$i};
13218: $containers{$i} = 'sequence';
13219: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13220: $folders{$i}.'.'.$containers{$i};
13221: my $newidx = &LONCAPA::map::getresidx();
13222: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13223: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13224: push(@LONCAPA::map::order,$newidx);
13225: my ($outtext,$errtext) =
13226: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13227: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13228: '.'.$containers{$outer},1,1);
1.1056 raeburn 13229: $newseqid{$i} = $newidx;
1.1067 raeburn 13230: unless ($errtext) {
13231: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
13232: }
1.1055 raeburn 13233: }
13234: } else {
13235: if ($context eq 'coursedocs') {
13236: my $newidx=&LONCAPA::map::getresidx();
13237: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13238: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13239: $title;
13240: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13241: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13242: }
13243: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13244: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13245: }
13246: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13247: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 13248: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 13249: unless ($ishome) {
13250: my $fetch = "$newdest{$i}/$title";
13251: $fetch =~ s/^\Q$prefix$dir\E//;
13252: $prompttofetch{$fetch} = 1;
13253: }
1.1055 raeburn 13254: }
13255: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13256: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13257: push(@LONCAPA::map::order, $newidx);
13258: my ($outtext,$errtext)=
13259: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13260: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13261: '.'.$containers{$outer},1,1);
1.1067 raeburn 13262: unless ($errtext) {
13263: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13264: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
13265: }
13266: }
1.1055 raeburn 13267: }
13268: }
1.1086 raeburn 13269: }
13270: } else {
13271: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13272: }
13273: }
13274: for (my $i=1; $i<=$numitems; $i++) {
13275: next unless ($env{'form.archive_'.$i} eq 'dependency');
13276: my $path = $env{'form.archive_content_'.$i};
13277: if ($path =~ /^\Q$pathtocheck\E/) {
13278: my ($title) = ($path =~ m{/([^/]+)$});
13279: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13280: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13281: if (ref($dirorder{$i}) eq 'ARRAY') {
13282: my ($itemidx,$fullpath,$relpath);
13283: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13284: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13285: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13286: if ($dirorder{$i}->[$j] eq $container) {
13287: $itemidx = $j;
1.1056 raeburn 13288: }
13289: }
1.1086 raeburn 13290: }
13291: if ($itemidx eq '') {
13292: $itemidx = 0;
13293: }
13294: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13295: if ($mapinner{$referrer{$i}}) {
13296: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13297: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13298: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13299: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13300: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13301: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13302: if (!-e $fullpath) {
13303: mkdir($fullpath,0755);
1.1056 raeburn 13304: }
13305: }
1.1086 raeburn 13306: } else {
13307: last;
1.1056 raeburn 13308: }
1.1086 raeburn 13309: }
13310: }
13311: } elsif ($newdest{$referrer{$i}}) {
13312: $fullpath = $newdest{$referrer{$i}};
13313: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13314: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13315: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13316: last;
13317: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13318: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13319: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13320: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13321: if (!-e $fullpath) {
13322: mkdir($fullpath,0755);
1.1056 raeburn 13323: }
13324: }
1.1086 raeburn 13325: } else {
13326: last;
1.1056 raeburn 13327: }
1.1055 raeburn 13328: }
13329: }
1.1086 raeburn 13330: if ($fullpath ne '') {
13331: if (-e "$prefix$path") {
13332: system("mv $prefix$path $fullpath/$title");
13333: }
13334: if (-e "$fullpath/$title") {
13335: my $showpath;
13336: if ($relpath ne '') {
13337: $showpath = "$relpath/$title";
13338: } else {
13339: $showpath = "/$title";
13340: }
13341: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
13342: }
13343: unless ($ishome) {
13344: my $fetch = "$fullpath/$title";
13345: $fetch =~ s/^\Q$prefix$dir\E//;
13346: $prompttofetch{$fetch} = 1;
13347: }
13348: }
1.1055 raeburn 13349: }
1.1086 raeburn 13350: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13351: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
13352: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 13353: }
13354: } else {
13355: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13356: }
13357: }
13358: if (keys(%todelete)) {
13359: foreach my $key (keys(%todelete)) {
13360: unlink($key);
1.1066 raeburn 13361: }
13362: }
13363: if (keys(%todeletedir)) {
13364: foreach my $key (keys(%todeletedir)) {
13365: rmdir($key);
13366: }
13367: }
13368: foreach my $dir (sort(keys(%is_dir))) {
13369: if (($pathtocheck ne '') && ($dir ne '')) {
13370: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13371: }
13372: }
1.1067 raeburn 13373: if ($result ne '') {
13374: $output .= '<ul>'."\n".
13375: $result."\n".
13376: '</ul>';
13377: }
13378: unless ($ishome) {
13379: my $replicationfail;
13380: foreach my $item (keys(%prompttofetch)) {
13381: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13382: unless ($fetchresult eq 'ok') {
13383: $replicationfail .= '<li>'.$item.'</li>'."\n";
13384: }
13385: }
13386: if ($replicationfail) {
13387: $output .= '<p class="LC_error">'.
13388: &mt('Course home server failed to retrieve:').'<ul>'.
13389: $replicationfail.
13390: '</ul></p>';
13391: }
13392: }
1.1055 raeburn 13393: } else {
13394: $warning = &mt('No items found in archive.');
13395: }
13396: if ($error) {
13397: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13398: $error.'</p>'."\n";
13399: }
13400: if ($warning) {
13401: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13402: }
13403: return $output;
13404: }
13405:
1.1066 raeburn 13406: sub cleanup_empty_dirs {
13407: my ($path) = @_;
13408: if (($path ne '') && (-d $path)) {
13409: if (opendir(my $dirh,$path)) {
13410: my @dircontents = grep(!/^\./,readdir($dirh));
13411: my $numitems = 0;
13412: foreach my $item (@dircontents) {
13413: if (-d "$path/$item") {
1.1111 raeburn 13414: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13415: if (-e "$path/$item") {
13416: $numitems ++;
13417: }
13418: } else {
13419: $numitems ++;
13420: }
13421: }
13422: if ($numitems == 0) {
13423: rmdir($path);
13424: }
13425: closedir($dirh);
13426: }
13427: }
13428: return;
13429: }
13430:
1.41 ng 13431: =pod
1.45 matthew 13432:
1.1162 raeburn 13433: =item * &get_folder_hierarchy()
1.1068 raeburn 13434:
13435: Provides hierarchy of names of folders/sub-folders containing the current
13436: item,
13437:
13438: Inputs: 3
13439: - $navmap - navmaps object
13440:
13441: - $map - url for map (either the trigger itself, or map containing
13442: the resource, which is the trigger).
13443:
13444: - $showitem - 1 => show title for map itself; 0 => do not show.
13445:
13446: Outputs: 1 @pathitems - array of folder/subfolder names.
13447:
13448: =cut
13449:
13450: sub get_folder_hierarchy {
13451: my ($navmap,$map,$showitem) = @_;
13452: my @pathitems;
13453: if (ref($navmap)) {
13454: my $mapres = $navmap->getResourceByUrl($map);
13455: if (ref($mapres)) {
13456: my $pcslist = $mapres->map_hierarchy();
13457: if ($pcslist ne '') {
13458: my @pcs = split(/,/,$pcslist);
13459: foreach my $pc (@pcs) {
13460: if ($pc == 1) {
1.1129 raeburn 13461: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13462: } else {
13463: my $res = $navmap->getByMapPc($pc);
13464: if (ref($res)) {
13465: my $title = $res->compTitle();
13466: $title =~ s/\W+/_/g;
13467: if ($title ne '') {
13468: push(@pathitems,$title);
13469: }
13470: }
13471: }
13472: }
13473: }
1.1071 raeburn 13474: if ($showitem) {
13475: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13476: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13477: } else {
13478: my $maptitle = $mapres->compTitle();
13479: $maptitle =~ s/\W+/_/g;
13480: if ($maptitle ne '') {
13481: push(@pathitems,$maptitle);
13482: }
1.1068 raeburn 13483: }
13484: }
13485: }
13486: }
13487: return @pathitems;
13488: }
13489:
13490: =pod
13491:
1.1015 raeburn 13492: =item * &get_turnedin_filepath()
13493:
13494: Determines path in a user's portfolio file for storage of files uploaded
13495: to a specific essayresponse or dropbox item.
13496:
13497: Inputs: 3 required + 1 optional.
13498: $symb is symb for resource, $uname and $udom are for current user (required).
13499: $caller is optional (can be "submission", if routine is called when storing
13500: an upoaded file when "Submit Answer" button was pressed).
13501:
13502: Returns array containing $path and $multiresp.
13503: $path is path in portfolio. $multiresp is 1 if this resource contains more
13504: than one file upload item. Callers of routine should append partid as a
13505: subdirectory to $path in cases where $multiresp is 1.
13506:
13507: Called by: homework/essayresponse.pm and homework/structuretags.pm
13508:
13509: =cut
13510:
13511: sub get_turnedin_filepath {
13512: my ($symb,$uname,$udom,$caller) = @_;
13513: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13514: my $turnindir;
13515: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13516: $turnindir = $userhash{'turnindir'};
13517: my ($path,$multiresp);
13518: if ($turnindir eq '') {
13519: if ($caller eq 'submission') {
13520: $turnindir = &mt('turned in');
13521: $turnindir =~ s/\W+/_/g;
13522: my %newhash = (
13523: 'turnindir' => $turnindir,
13524: );
13525: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13526: }
13527: }
13528: if ($turnindir ne '') {
13529: $path = '/'.$turnindir.'/';
13530: my ($multipart,$turnin,@pathitems);
13531: my $navmap = Apache::lonnavmaps::navmap->new();
13532: if (defined($navmap)) {
13533: my $mapres = $navmap->getResourceByUrl($map);
13534: if (ref($mapres)) {
13535: my $pcslist = $mapres->map_hierarchy();
13536: if ($pcslist ne '') {
13537: foreach my $pc (split(/,/,$pcslist)) {
13538: my $res = $navmap->getByMapPc($pc);
13539: if (ref($res)) {
13540: my $title = $res->compTitle();
13541: $title =~ s/\W+/_/g;
13542: if ($title ne '') {
1.1149 raeburn 13543: if (($pc > 1) && (length($title) > 12)) {
13544: $title = substr($title,0,12);
13545: }
1.1015 raeburn 13546: push(@pathitems,$title);
13547: }
13548: }
13549: }
13550: }
13551: my $maptitle = $mapres->compTitle();
13552: $maptitle =~ s/\W+/_/g;
13553: if ($maptitle ne '') {
1.1149 raeburn 13554: if (length($maptitle) > 12) {
13555: $maptitle = substr($maptitle,0,12);
13556: }
1.1015 raeburn 13557: push(@pathitems,$maptitle);
13558: }
13559: unless ($env{'request.state'} eq 'construct') {
13560: my $res = $navmap->getBySymb($symb);
13561: if (ref($res)) {
13562: my $partlist = $res->parts();
13563: my $totaluploads = 0;
13564: if (ref($partlist) eq 'ARRAY') {
13565: foreach my $part (@{$partlist}) {
13566: my @types = $res->responseType($part);
13567: my @ids = $res->responseIds($part);
13568: for (my $i=0; $i < scalar(@ids); $i++) {
13569: if ($types[$i] eq 'essay') {
13570: my $partid = $part.'_'.$ids[$i];
13571: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13572: $totaluploads ++;
13573: }
13574: }
13575: }
13576: }
13577: if ($totaluploads > 1) {
13578: $multiresp = 1;
13579: }
13580: }
13581: }
13582: }
13583: } else {
13584: return;
13585: }
13586: } else {
13587: return;
13588: }
13589: my $restitle=&Apache::lonnet::gettitle($symb);
13590: $restitle =~ s/\W+/_/g;
13591: if ($restitle eq '') {
13592: $restitle = ($resurl =~ m{/[^/]+$});
13593: if ($restitle eq '') {
13594: $restitle = time;
13595: }
13596: }
1.1149 raeburn 13597: if (length($restitle) > 12) {
13598: $restitle = substr($restitle,0,12);
13599: }
1.1015 raeburn 13600: push(@pathitems,$restitle);
13601: $path .= join('/',@pathitems);
13602: }
13603: return ($path,$multiresp);
13604: }
13605:
13606: =pod
13607:
1.464 albertel 13608: =back
1.41 ng 13609:
1.112 bowersj2 13610: =head1 CSV Upload/Handling functions
1.38 albertel 13611:
1.41 ng 13612: =over 4
13613:
1.648 raeburn 13614: =item * &upfile_store($r)
1.41 ng 13615:
13616: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13617: needs $env{'form.upfile'}
1.41 ng 13618: returns $datatoken to be put into hidden field
13619:
13620: =cut
1.31 albertel 13621:
13622: sub upfile_store {
13623: my $r=shift;
1.258 albertel 13624: $env{'form.upfile'}=~s/\r/\n/gs;
13625: $env{'form.upfile'}=~s/\f/\n/gs;
13626: $env{'form.upfile'}=~s/\n+/\n/gs;
13627: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13628:
1.258 albertel 13629: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
13630: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 13631: {
1.158 raeburn 13632: my $datafile = $r->dir_config('lonDaemons').
13633: '/tmp/'.$datatoken.'.tmp';
13634: if ( open(my $fh,">$datafile") ) {
1.258 albertel 13635: print $fh $env{'form.upfile'};
1.158 raeburn 13636: close($fh);
13637: }
1.31 albertel 13638: }
13639: return $datatoken;
13640: }
13641:
1.56 matthew 13642: =pod
13643:
1.648 raeburn 13644: =item * &load_tmp_file($r)
1.41 ng 13645:
13646: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 13647: needs $env{'form.datatoken'},
13648: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13649:
13650: =cut
1.31 albertel 13651:
13652: sub load_tmp_file {
13653: my $r=shift;
13654: my @studentdata=();
13655: {
1.158 raeburn 13656: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 13657: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 13658: if ( open(my $fh,"<$studentfile") ) {
13659: @studentdata=<$fh>;
13660: close($fh);
13661: }
1.31 albertel 13662: }
1.258 albertel 13663: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13664: }
13665:
1.56 matthew 13666: =pod
13667:
1.648 raeburn 13668: =item * &upfile_record_sep()
1.41 ng 13669:
13670: Separate uploaded file into records
13671: returns array of records,
1.258 albertel 13672: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13673:
13674: =cut
1.31 albertel 13675:
13676: sub upfile_record_sep {
1.258 albertel 13677: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13678: } else {
1.248 albertel 13679: my @records;
1.258 albertel 13680: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13681: if ($line=~/^\s*$/) { next; }
13682: push(@records,$line);
13683: }
13684: return @records;
1.31 albertel 13685: }
13686: }
13687:
1.56 matthew 13688: =pod
13689:
1.648 raeburn 13690: =item * &record_sep($record)
1.41 ng 13691:
1.258 albertel 13692: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13693:
13694: =cut
13695:
1.263 www 13696: sub takeleft {
13697: my $index=shift;
13698: return substr('0000'.$index,-4,4);
13699: }
13700:
1.31 albertel 13701: sub record_sep {
13702: my $record=shift;
13703: my %components=();
1.258 albertel 13704: if ($env{'form.upfiletype'} eq 'xml') {
13705: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13706: my $i=0;
1.356 albertel 13707: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13708: $field=~s/^(\"|\')//;
13709: $field=~s/(\"|\')$//;
1.263 www 13710: $components{&takeleft($i)}=$field;
1.31 albertel 13711: $i++;
13712: }
1.258 albertel 13713: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13714: my $i=0;
1.356 albertel 13715: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13716: $field=~s/^(\"|\')//;
13717: $field=~s/(\"|\')$//;
1.263 www 13718: $components{&takeleft($i)}=$field;
1.31 albertel 13719: $i++;
13720: }
13721: } else {
1.561 www 13722: my $separator=',';
1.480 banghart 13723: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13724: $separator=';';
1.480 banghart 13725: }
1.31 albertel 13726: my $i=0;
1.561 www 13727: # the character we are looking for to indicate the end of a quote or a record
13728: my $looking_for=$separator;
13729: # do not add the characters to the fields
13730: my $ignore=0;
13731: # we just encountered a separator (or the beginning of the record)
13732: my $just_found_separator=1;
13733: # store the field we are working on here
13734: my $field='';
13735: # work our way through all characters in record
13736: foreach my $character ($record=~/(.)/g) {
13737: if ($character eq $looking_for) {
13738: if ($character ne $separator) {
13739: # Found the end of a quote, again looking for separator
13740: $looking_for=$separator;
13741: $ignore=1;
13742: } else {
13743: # Found a separator, store away what we got
13744: $components{&takeleft($i)}=$field;
13745: $i++;
13746: $just_found_separator=1;
13747: $ignore=0;
13748: $field='';
13749: }
13750: next;
13751: }
13752: # single or double quotation marks after a separator indicate beginning of a quote
13753: # we are now looking for the end of the quote and need to ignore separators
13754: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13755: $looking_for=$character;
13756: next;
13757: }
13758: # ignore would be true after we reached the end of a quote
13759: if ($ignore) { next; }
13760: if (($just_found_separator) && ($character=~/\s/)) { next; }
13761: $field.=$character;
13762: $just_found_separator=0;
1.31 albertel 13763: }
1.561 www 13764: # catch the very last entry, since we never encountered the separator
13765: $components{&takeleft($i)}=$field;
1.31 albertel 13766: }
13767: return %components;
13768: }
13769:
1.144 matthew 13770: ######################################################
13771: ######################################################
13772:
1.56 matthew 13773: =pod
13774:
1.648 raeburn 13775: =item * &upfile_select_html()
1.41 ng 13776:
1.144 matthew 13777: Return HTML code to select a file from the users machine and specify
13778: the file type.
1.41 ng 13779:
13780: =cut
13781:
1.144 matthew 13782: ######################################################
13783: ######################################################
1.31 albertel 13784: sub upfile_select_html {
1.144 matthew 13785: my %Types = (
13786: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13787: semisv => &mt('Semicolon separated values'),
1.144 matthew 13788: space => &mt('Space separated'),
13789: tab => &mt('Tabulator separated'),
13790: # xml => &mt('HTML/XML'),
13791: );
13792: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13793: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13794: foreach my $type (sort(keys(%Types))) {
13795: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13796: }
13797: $Str .= "</select>\n";
13798: return $Str;
1.31 albertel 13799: }
13800:
1.301 albertel 13801: sub get_samples {
13802: my ($records,$toget) = @_;
13803: my @samples=({});
13804: my $got=0;
13805: foreach my $rec (@$records) {
13806: my %temp = &record_sep($rec);
13807: if (! grep(/\S/, values(%temp))) { next; }
13808: if (%temp) {
13809: $samples[$got]=\%temp;
13810: $got++;
13811: if ($got == $toget) { last; }
13812: }
13813: }
13814: return \@samples;
13815: }
13816:
1.144 matthew 13817: ######################################################
13818: ######################################################
13819:
1.56 matthew 13820: =pod
13821:
1.648 raeburn 13822: =item * &csv_print_samples($r,$records)
1.41 ng 13823:
13824: Prints a table of sample values from each column uploaded $r is an
13825: Apache Request ref, $records is an arrayref from
13826: &Apache::loncommon::upfile_record_sep
13827:
13828: =cut
13829:
1.144 matthew 13830: ######################################################
13831: ######################################################
1.31 albertel 13832: sub csv_print_samples {
13833: my ($r,$records) = @_;
1.662 bisitz 13834: my $samples = &get_samples($records,5);
1.301 albertel 13835:
1.594 raeburn 13836: $r->print(&mt('Samples').'<br />'.&start_data_table().
13837: &start_data_table_header_row());
1.356 albertel 13838: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13839: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13840: $r->print(&end_data_table_header_row());
1.301 albertel 13841: foreach my $hash (@$samples) {
1.594 raeburn 13842: $r->print(&start_data_table_row());
1.356 albertel 13843: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13844: $r->print('<td>');
1.356 albertel 13845: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13846: $r->print('</td>');
13847: }
1.594 raeburn 13848: $r->print(&end_data_table_row());
1.31 albertel 13849: }
1.594 raeburn 13850: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13851: }
13852:
1.144 matthew 13853: ######################################################
13854: ######################################################
13855:
1.56 matthew 13856: =pod
13857:
1.648 raeburn 13858: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13859:
13860: Prints a table to create associations between values and table columns.
1.144 matthew 13861:
1.41 ng 13862: $r is an Apache Request ref,
13863: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13864: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13865:
13866: =cut
13867:
1.144 matthew 13868: ######################################################
13869: ######################################################
1.31 albertel 13870: sub csv_print_select_table {
13871: my ($r,$records,$d) = @_;
1.301 albertel 13872: my $i=0;
13873: my $samples = &get_samples($records,1);
1.144 matthew 13874: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13875: &start_data_table().&start_data_table_header_row().
1.144 matthew 13876: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13877: '<th>'.&mt('Column').'</th>'.
13878: &end_data_table_header_row()."\n");
1.356 albertel 13879: foreach my $array_ref (@$d) {
13880: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13881: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13882:
1.875 bisitz 13883: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13884: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13885: $r->print('<option value="none"></option>');
1.356 albertel 13886: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13887: $r->print('<option value="'.$sample.'"'.
13888: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13889: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13890: }
1.594 raeburn 13891: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13892: $i++;
13893: }
1.594 raeburn 13894: $r->print(&end_data_table());
1.31 albertel 13895: $i--;
13896: return $i;
13897: }
1.56 matthew 13898:
1.144 matthew 13899: ######################################################
13900: ######################################################
13901:
1.56 matthew 13902: =pod
1.31 albertel 13903:
1.648 raeburn 13904: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13905:
13906: Prints a table of sample values from the upload and can make associate samples to internal names.
13907:
13908: $r is an Apache Request ref,
13909: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13910: $d is an array of 2 element arrays (internal name, displayed name)
13911:
13912: =cut
13913:
1.144 matthew 13914: ######################################################
13915: ######################################################
1.31 albertel 13916: sub csv_samples_select_table {
13917: my ($r,$records,$d) = @_;
13918: my $i=0;
1.144 matthew 13919: #
1.662 bisitz 13920: my $max_samples = 5;
13921: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13922: $r->print(&start_data_table().
13923: &start_data_table_header_row().'<th>'.
13924: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13925: &end_data_table_header_row());
1.301 albertel 13926:
13927: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13928: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13929: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13930: foreach my $option (@$d) {
13931: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13932: $r->print('<option value="'.$value.'"'.
1.253 albertel 13933: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13934: $display.'</option>');
1.31 albertel 13935: }
13936: $r->print('</select></td><td>');
1.662 bisitz 13937: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13938: if (defined($samples->[$line]{$key})) {
13939: $r->print($samples->[$line]{$key}."<br />\n");
13940: }
13941: }
1.594 raeburn 13942: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13943: $i++;
13944: }
1.594 raeburn 13945: $r->print(&end_data_table());
1.31 albertel 13946: $i--;
13947: return($i);
1.115 matthew 13948: }
13949:
1.144 matthew 13950: ######################################################
13951: ######################################################
13952:
1.115 matthew 13953: =pod
13954:
1.648 raeburn 13955: =item * &clean_excel_name($name)
1.115 matthew 13956:
13957: Returns a replacement for $name which does not contain any illegal characters.
13958:
13959: =cut
13960:
1.144 matthew 13961: ######################################################
13962: ######################################################
1.115 matthew 13963: sub clean_excel_name {
13964: my ($name) = @_;
13965: $name =~ s/[:\*\?\/\\]//g;
13966: if (length($name) > 31) {
13967: $name = substr($name,0,31);
13968: }
13969: return $name;
1.25 albertel 13970: }
1.84 albertel 13971:
1.85 albertel 13972: =pod
13973:
1.648 raeburn 13974: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13975:
13976: Returns either 1 or undef
13977:
13978: 1 if the part is to be hidden, undef if it is to be shown
13979:
13980: Arguments are:
13981:
13982: $id the id of the part to be checked
13983: $symb, optional the symb of the resource to check
13984: $udom, optional the domain of the user to check for
13985: $uname, optional the username of the user to check for
13986:
13987: =cut
1.84 albertel 13988:
13989: sub check_if_partid_hidden {
13990: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13991: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13992: $symb,$udom,$uname);
1.141 albertel 13993: my $truth=1;
13994: #if the string starts with !, then the list is the list to show not hide
13995: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13996: my @hiddenlist=split(/,/,$hiddenparts);
13997: foreach my $checkid (@hiddenlist) {
1.141 albertel 13998: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13999: }
1.141 albertel 14000: return !$truth;
1.84 albertel 14001: }
1.127 matthew 14002:
1.138 matthew 14003:
14004: ############################################################
14005: ############################################################
14006:
14007: =pod
14008:
1.157 matthew 14009: =back
14010:
1.138 matthew 14011: =head1 cgi-bin script and graphing routines
14012:
1.157 matthew 14013: =over 4
14014:
1.648 raeburn 14015: =item * &get_cgi_id()
1.138 matthew 14016:
14017: Inputs: none
14018:
14019: Returns an id which can be used to pass environment variables
14020: to various cgi-bin scripts. These environment variables will
14021: be removed from the users environment after a given time by
14022: the routine &Apache::lonnet::transfer_profile_to_env.
14023:
14024: =cut
14025:
14026: ############################################################
14027: ############################################################
1.152 albertel 14028: my $uniq=0;
1.136 matthew 14029: sub get_cgi_id {
1.154 albertel 14030: $uniq=($uniq+1)%100000;
1.280 albertel 14031: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14032: }
14033:
1.127 matthew 14034: ############################################################
14035: ############################################################
14036:
14037: =pod
14038:
1.648 raeburn 14039: =item * &DrawBarGraph()
1.127 matthew 14040:
1.138 matthew 14041: Facilitates the plotting of data in a (stacked) bar graph.
14042: Puts plot definition data into the users environment in order for
14043: graph.png to plot it. Returns an <img> tag for the plot.
14044: The bars on the plot are labeled '1','2',...,'n'.
14045:
14046: Inputs:
14047:
14048: =over 4
14049:
14050: =item $Title: string, the title of the plot
14051:
14052: =item $xlabel: string, text describing the X-axis of the plot
14053:
14054: =item $ylabel: string, text describing the Y-axis of the plot
14055:
14056: =item $Max: scalar, the maximum Y value to use in the plot
14057: If $Max is < any data point, the graph will not be rendered.
14058:
1.140 matthew 14059: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14060: they are plotted. If undefined, default values will be used.
14061:
1.178 matthew 14062: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14063:
1.138 matthew 14064: =item @Values: An array of array references. Each array reference holds data
14065: to be plotted in a stacked bar chart.
14066:
1.239 matthew 14067: =item If the final element of @Values is a hash reference the key/value
14068: pairs will be added to the graph definition.
14069:
1.138 matthew 14070: =back
14071:
14072: Returns:
14073:
14074: An <img> tag which references graph.png and the appropriate identifying
14075: information for the plot.
14076:
1.127 matthew 14077: =cut
14078:
14079: ############################################################
14080: ############################################################
1.134 matthew 14081: sub DrawBarGraph {
1.178 matthew 14082: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14083: #
14084: if (! defined($colors)) {
14085: $colors = ['#33ff00',
14086: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14087: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14088: ];
14089: }
1.228 matthew 14090: my $extra_settings = {};
14091: if (ref($Values[-1]) eq 'HASH') {
14092: $extra_settings = pop(@Values);
14093: }
1.127 matthew 14094: #
1.136 matthew 14095: my $identifier = &get_cgi_id();
14096: my $id = 'cgi.'.$identifier;
1.129 matthew 14097: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14098: return '';
14099: }
1.225 matthew 14100: #
14101: my @Labels;
14102: if (defined($labels)) {
14103: @Labels = @$labels;
14104: } else {
14105: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14106: push(@Labels,$i+1);
1.225 matthew 14107: }
14108: }
14109: #
1.129 matthew 14110: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14111: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14112: my %ValuesHash;
14113: my $NumSets=1;
14114: foreach my $array (@Values) {
14115: next if (! ref($array));
1.136 matthew 14116: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14117: join(',',@$array);
1.129 matthew 14118: }
1.127 matthew 14119: #
1.136 matthew 14120: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14121: if ($NumBars < 3) {
14122: $width = 120+$NumBars*32;
1.220 matthew 14123: $xskip = 1;
1.225 matthew 14124: $bar_width = 30;
14125: } elsif ($NumBars < 5) {
14126: $width = 120+$NumBars*20;
14127: $xskip = 1;
14128: $bar_width = 20;
1.220 matthew 14129: } elsif ($NumBars < 10) {
1.136 matthew 14130: $width = 120+$NumBars*15;
14131: $xskip = 1;
14132: $bar_width = 15;
14133: } elsif ($NumBars <= 25) {
14134: $width = 120+$NumBars*11;
14135: $xskip = 5;
14136: $bar_width = 8;
14137: } elsif ($NumBars <= 50) {
14138: $width = 120+$NumBars*8;
14139: $xskip = 5;
14140: $bar_width = 4;
14141: } else {
14142: $width = 120+$NumBars*8;
14143: $xskip = 5;
14144: $bar_width = 4;
14145: }
14146: #
1.137 matthew 14147: $Max = 1 if ($Max < 1);
14148: if ( int($Max) < $Max ) {
14149: $Max++;
14150: $Max = int($Max);
14151: }
1.127 matthew 14152: $Title = '' if (! defined($Title));
14153: $xlabel = '' if (! defined($xlabel));
14154: $ylabel = '' if (! defined($ylabel));
1.369 www 14155: $ValuesHash{$id.'.title'} = &escape($Title);
14156: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14157: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14158: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14159: $ValuesHash{$id.'.NumBars'} = $NumBars;
14160: $ValuesHash{$id.'.NumSets'} = $NumSets;
14161: $ValuesHash{$id.'.PlotType'} = 'bar';
14162: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14163: $ValuesHash{$id.'.height'} = $height;
14164: $ValuesHash{$id.'.width'} = $width;
14165: $ValuesHash{$id.'.xskip'} = $xskip;
14166: $ValuesHash{$id.'.bar_width'} = $bar_width;
14167: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14168: #
1.228 matthew 14169: # Deal with other parameters
14170: while (my ($key,$value) = each(%$extra_settings)) {
14171: $ValuesHash{$id.'.'.$key} = $value;
14172: }
14173: #
1.646 raeburn 14174: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14175: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14176: }
14177:
14178: ############################################################
14179: ############################################################
14180:
14181: =pod
14182:
1.648 raeburn 14183: =item * &DrawXYGraph()
1.137 matthew 14184:
1.138 matthew 14185: Facilitates the plotting of data in an XY graph.
14186: Puts plot definition data into the users environment in order for
14187: graph.png to plot it. Returns an <img> tag for the plot.
14188:
14189: Inputs:
14190:
14191: =over 4
14192:
14193: =item $Title: string, the title of the plot
14194:
14195: =item $xlabel: string, text describing the X-axis of the plot
14196:
14197: =item $ylabel: string, text describing the Y-axis of the plot
14198:
14199: =item $Max: scalar, the maximum Y value to use in the plot
14200: If $Max is < any data point, the graph will not be rendered.
14201:
14202: =item $colors: Array ref containing the hex color codes for the data to be
14203: plotted in. If undefined, default values will be used.
14204:
14205: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14206:
14207: =item $Ydata: Array ref containing Array refs.
1.185 www 14208: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14209:
14210: =item %Values: hash indicating or overriding any default values which are
14211: passed to graph.png.
14212: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14213:
14214: =back
14215:
14216: Returns:
14217:
14218: An <img> tag which references graph.png and the appropriate identifying
14219: information for the plot.
14220:
1.137 matthew 14221: =cut
14222:
14223: ############################################################
14224: ############################################################
14225: sub DrawXYGraph {
14226: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14227: #
14228: # Create the identifier for the graph
14229: my $identifier = &get_cgi_id();
14230: my $id = 'cgi.'.$identifier;
14231: #
14232: $Title = '' if (! defined($Title));
14233: $xlabel = '' if (! defined($xlabel));
14234: $ylabel = '' if (! defined($ylabel));
14235: my %ValuesHash =
14236: (
1.369 www 14237: $id.'.title' => &escape($Title),
14238: $id.'.xlabel' => &escape($xlabel),
14239: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14240: $id.'.y_max_value'=> $Max,
14241: $id.'.labels' => join(',',@$Xlabels),
14242: $id.'.PlotType' => 'XY',
14243: );
14244: #
14245: if (defined($colors) && ref($colors) eq 'ARRAY') {
14246: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14247: }
14248: #
14249: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14250: return '';
14251: }
14252: my $NumSets=1;
1.138 matthew 14253: foreach my $array (@{$Ydata}){
1.137 matthew 14254: next if (! ref($array));
14255: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14256: }
1.138 matthew 14257: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14258: #
14259: # Deal with other parameters
14260: while (my ($key,$value) = each(%Values)) {
14261: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14262: }
14263: #
1.646 raeburn 14264: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14265: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14266: }
14267:
14268: ############################################################
14269: ############################################################
14270:
14271: =pod
14272:
1.648 raeburn 14273: =item * &DrawXYYGraph()
1.138 matthew 14274:
14275: Facilitates the plotting of data in an XY graph with two Y axes.
14276: Puts plot definition data into the users environment in order for
14277: graph.png to plot it. Returns an <img> tag for the plot.
14278:
14279: Inputs:
14280:
14281: =over 4
14282:
14283: =item $Title: string, the title of the plot
14284:
14285: =item $xlabel: string, text describing the X-axis of the plot
14286:
14287: =item $ylabel: string, text describing the Y-axis of the plot
14288:
14289: =item $colors: Array ref containing the hex color codes for the data to be
14290: plotted in. If undefined, default values will be used.
14291:
14292: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14293:
14294: =item $Ydata1: The first data set
14295:
14296: =item $Min1: The minimum value of the left Y-axis
14297:
14298: =item $Max1: The maximum value of the left Y-axis
14299:
14300: =item $Ydata2: The second data set
14301:
14302: =item $Min2: The minimum value of the right Y-axis
14303:
14304: =item $Max2: The maximum value of the left Y-axis
14305:
14306: =item %Values: hash indicating or overriding any default values which are
14307: passed to graph.png.
14308: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14309:
14310: =back
14311:
14312: Returns:
14313:
14314: An <img> tag which references graph.png and the appropriate identifying
14315: information for the plot.
1.136 matthew 14316:
14317: =cut
14318:
14319: ############################################################
14320: ############################################################
1.137 matthew 14321: sub DrawXYYGraph {
14322: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14323: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14324: #
14325: # Create the identifier for the graph
14326: my $identifier = &get_cgi_id();
14327: my $id = 'cgi.'.$identifier;
14328: #
14329: $Title = '' if (! defined($Title));
14330: $xlabel = '' if (! defined($xlabel));
14331: $ylabel = '' if (! defined($ylabel));
14332: my %ValuesHash =
14333: (
1.369 www 14334: $id.'.title' => &escape($Title),
14335: $id.'.xlabel' => &escape($xlabel),
14336: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14337: $id.'.labels' => join(',',@$Xlabels),
14338: $id.'.PlotType' => 'XY',
14339: $id.'.NumSets' => 2,
1.137 matthew 14340: $id.'.two_axes' => 1,
14341: $id.'.y1_max_value' => $Max1,
14342: $id.'.y1_min_value' => $Min1,
14343: $id.'.y2_max_value' => $Max2,
14344: $id.'.y2_min_value' => $Min2,
1.136 matthew 14345: );
14346: #
1.137 matthew 14347: if (defined($colors) && ref($colors) eq 'ARRAY') {
14348: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14349: }
14350: #
14351: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14352: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14353: return '';
14354: }
14355: my $NumSets=1;
1.137 matthew 14356: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14357: next if (! ref($array));
14358: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14359: }
14360: #
14361: # Deal with other parameters
14362: while (my ($key,$value) = each(%Values)) {
14363: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14364: }
14365: #
1.646 raeburn 14366: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14367: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14368: }
14369:
14370: ############################################################
14371: ############################################################
14372:
14373: =pod
14374:
1.157 matthew 14375: =back
14376:
1.139 matthew 14377: =head1 Statistics helper routines?
14378:
14379: Bad place for them but what the hell.
14380:
1.157 matthew 14381: =over 4
14382:
1.648 raeburn 14383: =item * &chartlink()
1.139 matthew 14384:
14385: Returns a link to the chart for a specific student.
14386:
14387: Inputs:
14388:
14389: =over 4
14390:
14391: =item $linktext: The text of the link
14392:
14393: =item $sname: The students username
14394:
14395: =item $sdomain: The students domain
14396:
14397: =back
14398:
1.157 matthew 14399: =back
14400:
1.139 matthew 14401: =cut
14402:
14403: ############################################################
14404: ############################################################
14405: sub chartlink {
14406: my ($linktext, $sname, $sdomain) = @_;
14407: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14408: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14409: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14410: '">'.$linktext.'</a>';
1.153 matthew 14411: }
14412:
14413: #######################################################
14414: #######################################################
14415:
14416: =pod
14417:
14418: =head1 Course Environment Routines
1.157 matthew 14419:
14420: =over 4
1.153 matthew 14421:
1.648 raeburn 14422: =item * &restore_course_settings()
1.153 matthew 14423:
1.648 raeburn 14424: =item * &store_course_settings()
1.153 matthew 14425:
14426: Restores/Store indicated form parameters from the course environment.
14427: Will not overwrite existing values of the form parameters.
14428:
14429: Inputs:
14430: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14431:
14432: a hash ref describing the data to be stored. For example:
14433:
14434: %Save_Parameters = ('Status' => 'scalar',
14435: 'chartoutputmode' => 'scalar',
14436: 'chartoutputdata' => 'scalar',
14437: 'Section' => 'array',
1.373 raeburn 14438: 'Group' => 'array',
1.153 matthew 14439: 'StudentData' => 'array',
14440: 'Maps' => 'array');
14441:
14442: Returns: both routines return nothing
14443:
1.631 raeburn 14444: =back
14445:
1.153 matthew 14446: =cut
14447:
14448: #######################################################
14449: #######################################################
14450: sub store_course_settings {
1.496 albertel 14451: return &store_settings($env{'request.course.id'},@_);
14452: }
14453:
14454: sub store_settings {
1.153 matthew 14455: # save to the environment
14456: # appenv the same items, just to be safe
1.300 albertel 14457: my $udom = $env{'user.domain'};
14458: my $uname = $env{'user.name'};
1.496 albertel 14459: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14460: my %SaveHash;
14461: my %AppHash;
14462: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14463: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14464: my $envname = 'environment.'.$basename;
1.258 albertel 14465: if (exists($env{'form.'.$setting})) {
1.153 matthew 14466: # Save this value away
14467: if ($type eq 'scalar' &&
1.258 albertel 14468: (! exists($env{$envname}) ||
14469: $env{$envname} ne $env{'form.'.$setting})) {
14470: $SaveHash{$basename} = $env{'form.'.$setting};
14471: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14472: } elsif ($type eq 'array') {
14473: my $stored_form;
1.258 albertel 14474: if (ref($env{'form.'.$setting})) {
1.153 matthew 14475: $stored_form = join(',',
14476: map {
1.369 www 14477: &escape($_);
1.258 albertel 14478: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14479: } else {
14480: $stored_form =
1.369 www 14481: &escape($env{'form.'.$setting});
1.153 matthew 14482: }
14483: # Determine if the array contents are the same.
1.258 albertel 14484: if ($stored_form ne $env{$envname}) {
1.153 matthew 14485: $SaveHash{$basename} = $stored_form;
14486: $AppHash{$envname} = $stored_form;
14487: }
14488: }
14489: }
14490: }
14491: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14492: $udom,$uname);
1.153 matthew 14493: if ($put_result !~ /^(ok|delayed)/) {
14494: &Apache::lonnet::logthis('unable to save form parameters, '.
14495: 'got error:'.$put_result);
14496: }
14497: # Make sure these settings stick around in this session, too
1.646 raeburn 14498: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14499: return;
14500: }
14501:
14502: sub restore_course_settings {
1.499 albertel 14503: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14504: }
14505:
14506: sub restore_settings {
14507: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14508: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14509: next if (exists($env{'form.'.$setting}));
1.496 albertel 14510: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14511: '.'.$setting;
1.258 albertel 14512: if (exists($env{$envname})) {
1.153 matthew 14513: if ($type eq 'scalar') {
1.258 albertel 14514: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14515: } elsif ($type eq 'array') {
1.258 albertel 14516: $env{'form.'.$setting} = [
1.153 matthew 14517: map {
1.369 www 14518: &unescape($_);
1.258 albertel 14519: } split(',',$env{$envname})
1.153 matthew 14520: ];
14521: }
14522: }
14523: }
1.127 matthew 14524: }
14525:
1.618 raeburn 14526: #######################################################
14527: #######################################################
14528:
14529: =pod
14530:
14531: =head1 Domain E-mail Routines
14532:
14533: =over 4
14534:
1.648 raeburn 14535: =item * &build_recipient_list()
1.618 raeburn 14536:
1.1144 raeburn 14537: Build recipient lists for following types of e-mail:
1.766 raeburn 14538: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14539: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14540: module change checking, student/employee ID conflict checks, as
14541: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14542: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14543:
14544: Inputs:
1.619 raeburn 14545: defmail (scalar - email address of default recipient),
1.1144 raeburn 14546: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14547: requestsmail, updatesmail, or idconflictsmail).
14548:
1.619 raeburn 14549: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14550:
1.619 raeburn 14551: origmail (scalar - email address of recipient from loncapa.conf,
14552: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14553:
1.655 raeburn 14554: Returns: comma separated list of addresses to which to send e-mail.
14555:
14556: =back
1.618 raeburn 14557:
14558: =cut
14559:
14560: ############################################################
14561: ############################################################
14562: sub build_recipient_list {
1.619 raeburn 14563: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 14564: my @recipients;
1.1270 raeburn 14565: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14566: my %domconfig =
1.1270 raeburn 14567: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14568: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14569: if (exists($domconfig{'contacts'}{$mailing})) {
14570: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14571: my @contacts = ('adminemail','supportemail');
14572: foreach my $item (@contacts) {
14573: if ($domconfig{'contacts'}{$mailing}{$item}) {
14574: my $addr = $domconfig{'contacts'}{$item};
14575: if (!grep(/^\Q$addr\E$/,@recipients)) {
14576: push(@recipients,$addr);
14577: }
1.619 raeburn 14578: }
1.1270 raeburn 14579: }
14580: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14581: if ($mailing eq 'helpdeskmail') {
14582: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14583: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14584: my @ok_bccs;
14585: foreach my $bcc (@bccs) {
14586: $bcc =~ s/^\s+//g;
14587: $bcc =~ s/\s+$//g;
14588: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14589: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14590: push(@ok_bccs,$bcc);
14591: }
14592: }
14593: }
14594: if (@ok_bccs > 0) {
14595: $allbcc = join(', ',@ok_bccs);
14596: }
14597: }
14598: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14599: }
14600: }
1.766 raeburn 14601: } elsif ($origmail ne '') {
1.1270 raeburn 14602: $lastresort = $origmail;
1.618 raeburn 14603: }
1.619 raeburn 14604: } elsif ($origmail ne '') {
1.1270 raeburn 14605: $lastresort = $origmail;
14606: }
14607:
14608: if (($mailing eq 'helpdesk') && ($lastresort ne '')) {
14609: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14610: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14611: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14612: my %what = (
14613: perlvar => 1,
14614: );
14615: my $primary = &Apache::lonnet::domain($defdom,'primary');
14616: if ($primary) {
14617: my $gotaddr;
14618: my ($result,$returnhash) =
14619: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14620: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14621: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14622: $lastresort = $returnhash->{'lonSupportEMail'};
14623: $gotaddr = 1;
14624: }
14625: }
14626: unless ($gotaddr) {
14627: my $uintdom = &Apache::lonnet::internet_dom($primary);
14628: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14629: unless ($uintdom eq $intdom) {
14630: my %domconfig =
14631: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14632: if (ref($domconfig{'contacts'}) eq 'HASH') {
14633: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14634: my @contacts = ('adminemail','supportemail');
14635: foreach my $item (@contacts) {
14636: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14637: my $addr = $domconfig{'contacts'}{$item};
14638: if (!grep(/^\Q$addr\E$/,@recipients)) {
14639: push(@recipients,$addr);
14640: }
14641: }
14642: }
14643: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14644: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14645: }
14646: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14647: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14648: my @ok_bccs;
14649: foreach my $bcc (@bccs) {
14650: $bcc =~ s/^\s+//g;
14651: $bcc =~ s/\s+$//g;
14652: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14653: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14654: push(@ok_bccs,$bcc);
14655: }
14656: }
14657: }
14658: if (@ok_bccs > 0) {
14659: $allbcc = join(', ',@ok_bccs);
14660: }
14661: }
14662: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14663: }
14664: }
14665: }
14666: }
14667: }
14668: }
1.618 raeburn 14669: }
1.688 raeburn 14670: if (defined($defmail)) {
14671: if ($defmail ne '') {
14672: push(@recipients,$defmail);
14673: }
1.618 raeburn 14674: }
14675: if ($otheremails) {
1.619 raeburn 14676: my @others;
14677: if ($otheremails =~ /,/) {
14678: @others = split(/,/,$otheremails);
1.618 raeburn 14679: } else {
1.619 raeburn 14680: push(@others,$otheremails);
14681: }
14682: foreach my $addr (@others) {
14683: if (!grep(/^\Q$addr\E$/,@recipients)) {
14684: push(@recipients,$addr);
14685: }
1.618 raeburn 14686: }
14687: }
1.1270 raeburn 14688: if ($mailing eq 'helpdesk') {
14689: if ((!@recipients) && ($lastresort ne '')) {
14690: push(@recipients,$lastresort);
14691: }
14692: } elsif ($lastresort ne '') {
14693: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14694: push(@recipients,$lastresort);
14695: }
14696: }
1.1271 raeburn 14697: my $recipientlist = join(',',@recipients);
1.1270 raeburn 14698: if (wantarray) {
14699: return ($recipientlist,$allbcc,$addtext);
14700: } else {
14701: return $recipientlist;
14702: }
1.618 raeburn 14703: }
14704:
1.127 matthew 14705: ############################################################
14706: ############################################################
1.154 albertel 14707:
1.655 raeburn 14708: =pod
14709:
1.1224 musolffc 14710: =over 4
14711:
1.1223 musolffc 14712: =item * &mime_email()
14713:
14714: Sends an email with a possible attachment
14715:
14716: Inputs:
14717:
14718: =over 4
14719:
14720: from - Sender's email address
14721:
14722: to - Email address of recipient
14723:
14724: subject - Subject of email
14725:
14726: body - Body of email
14727:
14728: cc_string - Carbon copy email address
14729:
14730: bcc - Blind carbon copy email address
14731:
14732: type - File type of attachment
14733:
14734: attachment_path - Path of file to be attached
14735:
14736: file_name - Name of file to be attached
14737:
14738: attachment_text - The body of an attachment of type "TEXT"
14739:
14740: =back
14741:
14742: =back
14743:
14744: =cut
14745:
14746: ############################################################
14747: ############################################################
14748:
14749: sub mime_email {
14750: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
14751: $file_name, $attachment_text) = @_;
14752: my $msg = MIME::Lite->new(
14753: From => $from,
14754: To => $to,
14755: Subject => $subject,
14756: Type =>'TEXT',
14757: Data => $body,
14758: );
14759: if ($cc_string ne '') {
14760: $msg->add("Cc" => $cc_string);
14761: }
14762: if ($bcc ne '') {
14763: $msg->add("Bcc" => $bcc);
14764: }
14765: $msg->attr("content-type" => "text/plain");
14766: $msg->attr("content-type.charset" => "UTF-8");
14767: # Attach file if given
14768: if ($attachment_path) {
14769: unless ($file_name) {
14770: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
14771: }
14772: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
14773: $msg->attach(Type => $type,
14774: Path => $attachment_path,
14775: Filename => $file_name
14776: );
14777: # Otherwise attach text if given
14778: } elsif ($attachment_text) {
14779: $msg->attach(Type => 'TEXT',
14780: Data => $attachment_text);
14781: }
14782: # Send it
14783: $msg->send('sendmail');
14784: }
14785:
14786: ############################################################
14787: ############################################################
14788:
14789: =pod
14790:
1.655 raeburn 14791: =head1 Course Catalog Routines
14792:
14793: =over 4
14794:
14795: =item * &gather_categories()
14796:
14797: Converts category definitions - keys of categories hash stored in
14798: coursecategories in configuration.db on the primary library server in a
14799: domain - to an array. Also generates javascript and idx hash used to
14800: generate Domain Coordinator interface for editing Course Categories.
14801:
14802: Inputs:
1.663 raeburn 14803:
1.655 raeburn 14804: categories (reference to hash of category definitions).
1.663 raeburn 14805:
1.655 raeburn 14806: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14807: categories and subcategories).
1.663 raeburn 14808:
1.655 raeburn 14809: idx (reference to hash of counters used in Domain Coordinator interface for
14810: editing Course Categories).
1.663 raeburn 14811:
1.655 raeburn 14812: jsarray (reference to array of categories used to create Javascript arrays for
14813: Domain Coordinator interface for editing Course Categories).
14814:
14815: Returns: nothing
14816:
14817: Side effects: populates cats, idx and jsarray.
14818:
14819: =cut
14820:
14821: sub gather_categories {
14822: my ($categories,$cats,$idx,$jsarray) = @_;
14823: my %counters;
14824: my $num = 0;
14825: foreach my $item (keys(%{$categories})) {
14826: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14827: if ($container eq '' && $depth == 0) {
14828: $cats->[$depth][$categories->{$item}] = $cat;
14829: } else {
14830: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14831: }
14832: my ($escitem,$tail) = split(/:/,$item,2);
14833: if ($counters{$tail} eq '') {
14834: $counters{$tail} = $num;
14835: $num ++;
14836: }
14837: if (ref($idx) eq 'HASH') {
14838: $idx->{$item} = $counters{$tail};
14839: }
14840: if (ref($jsarray) eq 'ARRAY') {
14841: push(@{$jsarray->[$counters{$tail}]},$item);
14842: }
14843: }
14844: return;
14845: }
14846:
14847: =pod
14848:
14849: =item * &extract_categories()
14850:
14851: Used to generate breadcrumb trails for course categories.
14852:
14853: Inputs:
1.663 raeburn 14854:
1.655 raeburn 14855: categories (reference to hash of category definitions).
1.663 raeburn 14856:
1.655 raeburn 14857: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14858: categories and subcategories).
1.663 raeburn 14859:
1.655 raeburn 14860: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14861:
1.655 raeburn 14862: allitems (reference to hash - key is category key
14863: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14864:
1.655 raeburn 14865: idx (reference to hash of counters used in Domain Coordinator interface for
14866: editing Course Categories).
1.663 raeburn 14867:
1.655 raeburn 14868: jsarray (reference to array of categories used to create Javascript arrays for
14869: Domain Coordinator interface for editing Course Categories).
14870:
1.665 raeburn 14871: subcats (reference to hash of arrays containing all subcategories within each
14872: category, -recursive)
14873:
1.655 raeburn 14874: Returns: nothing
14875:
14876: Side effects: populates trails and allitems hash references.
14877:
14878: =cut
14879:
14880: sub extract_categories {
1.665 raeburn 14881: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14882: if (ref($categories) eq 'HASH') {
14883: &gather_categories($categories,$cats,$idx,$jsarray);
14884: if (ref($cats->[0]) eq 'ARRAY') {
14885: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14886: my $name = $cats->[0][$i];
14887: my $item = &escape($name).'::0';
14888: my $trailstr;
14889: if ($name eq 'instcode') {
14890: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14891: } elsif ($name eq 'communities') {
14892: $trailstr = &mt('Communities');
1.1239 raeburn 14893: } elsif ($name eq 'placement') {
14894: $trailstr = &mt('Placement Tests');
1.655 raeburn 14895: } else {
14896: $trailstr = $name;
14897: }
14898: if ($allitems->{$item} eq '') {
14899: push(@{$trails},$trailstr);
14900: $allitems->{$item} = scalar(@{$trails})-1;
14901: }
14902: my @parents = ($name);
14903: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14904: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14905: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14906: if (ref($subcats) eq 'HASH') {
14907: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14908: }
14909: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14910: }
14911: } else {
14912: if (ref($subcats) eq 'HASH') {
14913: $subcats->{$item} = [];
1.655 raeburn 14914: }
14915: }
14916: }
14917: }
14918: }
14919: return;
14920: }
14921:
14922: =pod
14923:
1.1162 raeburn 14924: =item * &recurse_categories()
1.655 raeburn 14925:
14926: Recursively used to generate breadcrumb trails for course categories.
14927:
14928: Inputs:
1.663 raeburn 14929:
1.655 raeburn 14930: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14931: categories and subcategories).
1.663 raeburn 14932:
1.655 raeburn 14933: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14934:
14935: category (current course category, for which breadcrumb trail is being generated).
14936:
14937: trails (reference to array of breadcrumb trails for each category).
14938:
1.655 raeburn 14939: allitems (reference to hash - key is category key
14940: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14941:
1.655 raeburn 14942: parents (array containing containers directories for current category,
14943: back to top level).
14944:
14945: Returns: nothing
14946:
14947: Side effects: populates trails and allitems hash references
14948:
14949: =cut
14950:
14951: sub recurse_categories {
1.665 raeburn 14952: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14953: my $shallower = $depth - 1;
14954: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14955: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14956: my $name = $cats->[$depth]{$category}[$k];
14957: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14958: my $trailstr = join(' -> ',(@{$parents},$category));
14959: if ($allitems->{$item} eq '') {
14960: push(@{$trails},$trailstr);
14961: $allitems->{$item} = scalar(@{$trails})-1;
14962: }
14963: my $deeper = $depth+1;
14964: push(@{$parents},$category);
1.665 raeburn 14965: if (ref($subcats) eq 'HASH') {
14966: my $subcat = &escape($name).':'.$category.':'.$depth;
14967: for (my $j=@{$parents}; $j>=0; $j--) {
14968: my $higher;
14969: if ($j > 0) {
14970: $higher = &escape($parents->[$j]).':'.
14971: &escape($parents->[$j-1]).':'.$j;
14972: } else {
14973: $higher = &escape($parents->[$j]).'::'.$j;
14974: }
14975: push(@{$subcats->{$higher}},$subcat);
14976: }
14977: }
14978: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14979: $subcats);
1.655 raeburn 14980: pop(@{$parents});
14981: }
14982: } else {
14983: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14984: my $trailstr = join(' -> ',(@{$parents},$category));
14985: if ($allitems->{$item} eq '') {
14986: push(@{$trails},$trailstr);
14987: $allitems->{$item} = scalar(@{$trails})-1;
14988: }
14989: }
14990: return;
14991: }
14992:
1.663 raeburn 14993: =pod
14994:
1.1162 raeburn 14995: =item * &assign_categories_table()
1.663 raeburn 14996:
14997: Create a datatable for display of hierarchical categories in a domain,
14998: with checkboxes to allow a course to be categorized.
14999:
15000: Inputs:
15001:
15002: cathash - reference to hash of categories defined for the domain (from
15003: configuration.db)
15004:
15005: currcat - scalar with an & separated list of categories assigned to a course.
15006:
1.919 raeburn 15007: type - scalar contains course type (Course or Community).
15008:
1.1260 raeburn 15009: disabled - scalar (optional) contains disabled="disabled" if input elements are
15010: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15011:
1.663 raeburn 15012: Returns: $output (markup to be displayed)
15013:
15014: =cut
15015:
15016: sub assign_categories_table {
1.1259 raeburn 15017: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15018: my $output;
15019: if (ref($cathash) eq 'HASH') {
15020: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
15021: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
15022: $maxdepth = scalar(@cats);
15023: if (@cats > 0) {
15024: my $itemcount = 0;
15025: if (ref($cats[0]) eq 'ARRAY') {
15026: my @currcategories;
15027: if ($currcat ne '') {
15028: @currcategories = split('&',$currcat);
15029: }
1.919 raeburn 15030: my $table;
1.663 raeburn 15031: for (my $i=0; $i<@{$cats[0]}; $i++) {
15032: my $parent = $cats[0][$i];
1.919 raeburn 15033: next if ($parent eq 'instcode');
15034: if ($type eq 'Community') {
15035: next unless ($parent eq 'communities');
1.1239 raeburn 15036: } elsif ($type eq 'Placement') {
15037: next unless ($parent eq 'placement');
1.919 raeburn 15038: } else {
1.1239 raeburn 15039: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15040: }
1.663 raeburn 15041: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15042: my $item = &escape($parent).'::0';
15043: my $checked = '';
15044: if (@currcategories > 0) {
15045: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15046: $checked = ' checked="checked"';
1.663 raeburn 15047: }
15048: }
1.919 raeburn 15049: my $parent_title = $parent;
15050: if ($parent eq 'communities') {
15051: $parent_title = &mt('Communities');
1.1239 raeburn 15052: } elsif ($parent eq 'placement') {
15053: $parent_title = &mt('Placement Tests');
1.919 raeburn 15054: }
15055: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15056: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15057: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15058: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15059: my $depth = 1;
15060: push(@path,$parent);
1.1259 raeburn 15061: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15062: pop(@path);
1.919 raeburn 15063: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15064: $itemcount ++;
15065: }
1.919 raeburn 15066: if ($itemcount) {
15067: $output = &Apache::loncommon::start_data_table().
15068: $table.
15069: &Apache::loncommon::end_data_table();
15070: }
1.663 raeburn 15071: }
15072: }
15073: }
15074: return $output;
15075: }
15076:
15077: =pod
15078:
1.1162 raeburn 15079: =item * &assign_category_rows()
1.663 raeburn 15080:
15081: Create a datatable row for display of nested categories in a domain,
15082: with checkboxes to allow a course to be categorized,called recursively.
15083:
15084: Inputs:
15085:
15086: itemcount - track row number for alternating colors
15087:
15088: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15089: categories and subcategories.
15090:
15091: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15092:
15093: parent - parent of current category item
15094:
15095: path - Array containing all categories back up through the hierarchy from the
15096: current category to the top level.
15097:
15098: currcategories - reference to array of current categories assigned to the course
15099:
1.1260 raeburn 15100: disabled - scalar (optional) contains disabled="disabled" if input elements are
15101: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15102:
1.663 raeburn 15103: Returns: $output (markup to be displayed).
15104:
15105: =cut
15106:
15107: sub assign_category_rows {
1.1259 raeburn 15108: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15109: my ($text,$name,$item,$chgstr);
15110: if (ref($cats) eq 'ARRAY') {
15111: my $maxdepth = scalar(@{$cats});
15112: if (ref($cats->[$depth]) eq 'HASH') {
15113: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15114: my $numchildren = @{$cats->[$depth]{$parent}};
15115: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15116: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15117: for (my $j=0; $j<$numchildren; $j++) {
15118: $name = $cats->[$depth]{$parent}[$j];
15119: $item = &escape($name).':'.&escape($parent).':'.$depth;
15120: my $deeper = $depth+1;
15121: my $checked = '';
15122: if (ref($currcategories) eq 'ARRAY') {
15123: if (@{$currcategories} > 0) {
15124: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15125: $checked = ' checked="checked"';
1.663 raeburn 15126: }
15127: }
15128: }
1.664 raeburn 15129: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15130: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15131: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15132: '<input type="hidden" name="catname" value="'.$name.'" />'.
15133: '</td><td>';
1.663 raeburn 15134: if (ref($path) eq 'ARRAY') {
15135: push(@{$path},$name);
1.1259 raeburn 15136: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15137: pop(@{$path});
15138: }
15139: $text .= '</td></tr>';
15140: }
15141: $text .= '</table></td>';
15142: }
15143: }
15144: }
15145: return $text;
15146: }
15147:
1.1181 raeburn 15148: =pod
15149:
15150: =back
15151:
15152: =cut
15153:
1.655 raeburn 15154: ############################################################
15155: ############################################################
15156:
15157:
1.443 albertel 15158: sub commit_customrole {
1.664 raeburn 15159: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15160: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15161: ($start?', '.&mt('starting').' '.localtime($start):'').
15162: ($end?', ending '.localtime($end):'').': <b>'.
15163: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15164: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15165: '</b><br />';
15166: return $output;
15167: }
15168:
15169: sub commit_standardrole {
1.1116 raeburn 15170: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15171: my ($output,$logmsg,$linefeed);
15172: if ($context eq 'auto') {
15173: $linefeed = "\n";
15174: } else {
15175: $linefeed = "<br />\n";
15176: }
1.443 albertel 15177: if ($three eq 'st') {
1.541 raeburn 15178: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15179: $one,$two,$sec,$context,$credits);
1.541 raeburn 15180: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15181: ($result eq 'unknown_course') || ($result eq 'refused')) {
15182: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15183: } else {
1.541 raeburn 15184: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15185: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15186: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15187: if ($context eq 'auto') {
15188: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15189: } else {
15190: $output .= '<b>'.$result.'</b>'.$linefeed.
15191: &mt('Add to classlist').': <b>ok</b>';
15192: }
15193: $output .= $linefeed;
1.443 albertel 15194: }
15195: } else {
15196: $output = &mt('Assigning').' '.$three.' in '.$url.
15197: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15198: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15199: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15200: if ($context eq 'auto') {
15201: $output .= $result.$linefeed;
15202: } else {
15203: $output .= '<b>'.$result.'</b>'.$linefeed;
15204: }
1.443 albertel 15205: }
15206: return $output;
15207: }
15208:
15209: sub commit_studentrole {
1.1116 raeburn 15210: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15211: $credits) = @_;
1.626 raeburn 15212: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15213: if ($context eq 'auto') {
15214: $linefeed = "\n";
15215: } else {
15216: $linefeed = '<br />'."\n";
15217: }
1.443 albertel 15218: if (defined($one) && defined($two)) {
15219: my $cid=$one.'_'.$two;
15220: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15221: my $secchange = 0;
15222: my $expire_role_result;
15223: my $modify_section_result;
1.628 raeburn 15224: if ($oldsec ne '-1') {
15225: if ($oldsec ne $sec) {
1.443 albertel 15226: $secchange = 1;
1.628 raeburn 15227: my $now = time;
1.443 albertel 15228: my $uurl='/'.$cid;
15229: $uurl=~s/\_/\//g;
15230: if ($oldsec) {
15231: $uurl.='/'.$oldsec;
15232: }
1.626 raeburn 15233: $oldsecurl = $uurl;
1.628 raeburn 15234: $expire_role_result =
1.652 raeburn 15235: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15236: if ($env{'request.course.sec'} ne '') {
15237: if ($expire_role_result eq 'refused') {
15238: my @roles = ('st');
15239: my @statuses = ('previous');
15240: my @roledoms = ($one);
15241: my $withsec = 1;
15242: my %roleshash =
15243: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15244: \@statuses,\@roles,\@roledoms,$withsec);
15245: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15246: my ($oldstart,$oldend) =
15247: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15248: if ($oldend > 0 && $oldend <= $now) {
15249: $expire_role_result = 'ok';
15250: }
15251: }
15252: }
15253: }
1.443 albertel 15254: $result = $expire_role_result;
15255: }
15256: }
15257: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15258: $modify_section_result =
15259: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15260: undef,undef,undef,$sec,
15261: $end,$start,'','',$cid,
15262: '',$context,$credits);
1.443 albertel 15263: if ($modify_section_result =~ /^ok/) {
15264: if ($secchange == 1) {
1.628 raeburn 15265: if ($sec eq '') {
15266: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15267: } else {
15268: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15269: }
1.443 albertel 15270: } elsif ($oldsec eq '-1') {
1.628 raeburn 15271: if ($sec eq '') {
15272: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15273: } else {
15274: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15275: }
1.443 albertel 15276: } else {
1.628 raeburn 15277: if ($sec eq '') {
15278: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15279: } else {
15280: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15281: }
1.443 albertel 15282: }
15283: } else {
1.1115 raeburn 15284: if ($secchange) {
1.628 raeburn 15285: $$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;
15286: } else {
15287: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15288: }
1.443 albertel 15289: }
15290: $result = $modify_section_result;
15291: } elsif ($secchange == 1) {
1.628 raeburn 15292: if ($oldsec eq '') {
1.1103 raeburn 15293: $$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 15294: } else {
15295: $$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;
15296: }
1.626 raeburn 15297: if ($expire_role_result eq 'refused') {
15298: my $newsecurl = '/'.$cid;
15299: $newsecurl =~ s/\_/\//g;
15300: if ($sec ne '') {
15301: $newsecurl.='/'.$sec;
15302: }
15303: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15304: if ($sec eq '') {
15305: $$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;
15306: } else {
15307: $$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;
15308: }
15309: }
15310: }
1.443 albertel 15311: }
15312: } else {
1.626 raeburn 15313: $$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 15314: $result = "error: incomplete course id\n";
15315: }
15316: return $result;
15317: }
15318:
1.1108 raeburn 15319: sub show_role_extent {
15320: my ($scope,$context,$role) = @_;
15321: $scope =~ s{^/}{};
15322: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15323: push(@courseroles,'co');
15324: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15325: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15326: $scope =~ s{/}{_};
15327: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15328: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15329: my ($audom,$auname) = split(/\//,$scope);
15330: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15331: &Apache::loncommon::plainname($auname,$audom).'</span>');
15332: } else {
15333: $scope =~ s{/$}{};
15334: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15335: &Apache::lonnet::domain($scope,'description').'</span>');
15336: }
15337: }
15338:
1.443 albertel 15339: ############################################################
15340: ############################################################
15341:
1.566 albertel 15342: sub check_clone {
1.578 raeburn 15343: my ($args,$linefeed) = @_;
1.566 albertel 15344: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15345: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15346: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15347: my $clonemsg;
15348: my $can_clone = 0;
1.944 raeburn 15349: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15350: if ($lctype ne 'community') {
15351: $lctype = 'course';
15352: }
1.566 albertel 15353: if ($clonehome eq 'no_host') {
1.944 raeburn 15354: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15355: $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'});
15356: } else {
15357: $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'});
15358: }
1.566 albertel 15359: } else {
15360: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15361: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15362: if ($clonedesc{'type'} ne 'Community') {
1.1262 raeburn 15363: $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'});
1.908 raeburn 15364: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15365: }
15366: }
1.1262 raeburn 15367: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15368: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15369: $can_clone = 1;
15370: } else {
1.1221 raeburn 15371: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15372: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15373: if ($clonehash{'cloners'} eq '') {
15374: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15375: if ($domdefs{'canclone'}) {
15376: unless ($domdefs{'canclone'} eq 'none') {
15377: if ($domdefs{'canclone'} eq 'domain') {
15378: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15379: $can_clone = 1;
15380: }
15381: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15382: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15383: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15384: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15385: $can_clone = 1;
15386: }
15387: }
15388: }
15389: }
1.578 raeburn 15390: } else {
1.1221 raeburn 15391: my @cloners = split(/,/,$clonehash{'cloners'});
15392: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15393: $can_clone = 1;
1.1221 raeburn 15394: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15395: $can_clone = 1;
1.1225 raeburn 15396: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15397: $can_clone = 1;
1.1221 raeburn 15398: }
15399: unless ($can_clone) {
1.1225 raeburn 15400: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15401: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15402: my (%gotdomdefaults,%gotcodedefaults);
15403: foreach my $cloner (@cloners) {
15404: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15405: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15406: my (%codedefaults,@code_order);
15407: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15408: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15409: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15410: }
15411: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15412: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15413: }
15414: } else {
15415: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15416: \%codedefaults,
15417: \@code_order);
15418: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15419: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15420: }
15421: if (@code_order > 0) {
15422: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15423: $cloner,$clonehash{'internal.coursecode'},
15424: $args->{'crscode'})) {
15425: $can_clone = 1;
15426: last;
15427: }
15428: }
15429: }
15430: }
15431: }
1.1225 raeburn 15432: }
15433: }
15434: unless ($can_clone) {
15435: my $ccrole = 'cc';
15436: if ($args->{'crstype'} eq 'Community') {
15437: $ccrole = 'co';
15438: }
15439: my %roleshash =
15440: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15441: $args->{'ccdomain'},
15442: 'userroles',['active'],[$ccrole],
15443: [$args->{'clonedomain'}]);
15444: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15445: $can_clone = 1;
15446: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15447: $args->{'ccuname'},$args->{'ccdomain'})) {
15448: $can_clone = 1;
1.1221 raeburn 15449: }
15450: }
15451: unless ($can_clone) {
15452: if ($args->{'crstype'} eq 'Community') {
15453: $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'});
1.942 raeburn 15454: } else {
1.1221 raeburn 15455: $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'});
15456: }
1.566 albertel 15457: }
1.578 raeburn 15458: }
1.566 albertel 15459: }
15460: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15461: }
15462:
1.444 albertel 15463: sub construct_course {
1.1262 raeburn 15464: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15465: $cnum,$category,$coderef) = @_;
1.444 albertel 15466: my $outcome;
1.541 raeburn 15467: my $linefeed = '<br />'."\n";
15468: if ($context eq 'auto') {
15469: $linefeed = "\n";
15470: }
1.566 albertel 15471:
15472: #
15473: # Are we cloning?
15474: #
15475: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15476: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15477: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15478: if ($context ne 'auto') {
1.578 raeburn 15479: if ($clonemsg ne '') {
15480: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15481: }
1.566 albertel 15482: }
15483: $outcome .= $clonemsg.$linefeed;
15484:
15485: if (!$can_clone) {
15486: return (0,$outcome);
15487: }
15488: }
15489:
1.444 albertel 15490: #
15491: # Open course
15492: #
1.1239 raeburn 15493: my $showncrstype;
15494: if ($args->{'crstype'} eq 'Placement') {
15495: $showncrstype = 'placement test';
15496: } else {
15497: $showncrstype = lc($args->{'crstype'});
15498: }
1.444 albertel 15499: my %cenv=();
15500: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15501: $args->{'cdescr'},
15502: $args->{'curl'},
15503: $args->{'course_home'},
15504: $args->{'nonstandard'},
15505: $args->{'crscode'},
15506: $args->{'ccuname'}.':'.
15507: $args->{'ccdomain'},
1.882 raeburn 15508: $args->{'crstype'},
1.885 raeburn 15509: $cnum,$context,$category);
1.444 albertel 15510:
15511: # Note: The testing routines depend on this being output; see
15512: # Utils::Course. This needs to at least be output as a comment
15513: # if anyone ever decides to not show this, and Utils::Course::new
15514: # will need to be suitably modified.
1.1239 raeburn 15515: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15516: if ($$courseid =~ /^error:/) {
15517: return (0,$outcome);
15518: }
15519:
1.444 albertel 15520: #
15521: # Check if created correctly
15522: #
1.479 albertel 15523: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15524: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15525: if ($crsuhome eq 'no_host') {
15526: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15527: return (0,$outcome);
15528: }
1.541 raeburn 15529: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15530:
1.444 albertel 15531: #
1.566 albertel 15532: # Do the cloning
15533: #
15534: if ($can_clone && $cloneid) {
1.1239 raeburn 15535: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 15536: if ($context ne 'auto') {
15537: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15538: }
15539: $outcome .= $clonemsg.$linefeed;
15540: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15541: # Copy all files
1.637 www 15542: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15543: # Restore URL
1.566 albertel 15544: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15545: # Restore title
1.566 albertel 15546: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15547: # Restore creation date, creator and creation context.
15548: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15549: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15550: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15551: # Mark as cloned
1.566 albertel 15552: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15553: # Need to clone grading mode
15554: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15555: $cenv{'grading'}=$newenv{'grading'};
15556: # Do not clone these environment entries
15557: &Apache::lonnet::del('environment',
15558: ['default_enrollment_start_date',
15559: 'default_enrollment_end_date',
15560: 'question.email',
15561: 'policy.email',
15562: 'comment.email',
15563: 'pch.users.denied',
1.725 raeburn 15564: 'plc.users.denied',
15565: 'hidefromcat',
1.1121 raeburn 15566: 'checkforpriv',
1.1166 raeburn 15567: 'categories',
15568: 'internal.uniquecode'],
1.638 www 15569: $$crsudom,$$crsunum);
1.1170 raeburn 15570: if ($args->{'textbook'}) {
15571: $cenv{'internal.textbook'} = $args->{'textbook'};
15572: }
1.444 albertel 15573: }
1.566 albertel 15574:
1.444 albertel 15575: #
15576: # Set environment (will override cloned, if existing)
15577: #
15578: my @sections = ();
15579: my @xlists = ();
15580: if ($args->{'crstype'}) {
15581: $cenv{'type'}=$args->{'crstype'};
15582: }
15583: if ($args->{'crsid'}) {
15584: $cenv{'courseid'}=$args->{'crsid'};
15585: }
15586: if ($args->{'crscode'}) {
15587: $cenv{'internal.coursecode'}=$args->{'crscode'};
15588: }
15589: if ($args->{'crsquota'} ne '') {
15590: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15591: } else {
15592: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15593: }
15594: if ($args->{'ccuname'}) {
15595: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15596: ':'.$args->{'ccdomain'};
15597: } else {
15598: $cenv{'internal.courseowner'} = $args->{'curruser'};
15599: }
1.1116 raeburn 15600: if ($args->{'defaultcredits'}) {
15601: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15602: }
1.444 albertel 15603: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15604: if ($args->{'crssections'}) {
15605: $cenv{'internal.sectionnums'} = '';
15606: if ($args->{'crssections'} =~ m/,/) {
15607: @sections = split/,/,$args->{'crssections'};
15608: } else {
15609: $sections[0] = $args->{'crssections'};
15610: }
15611: if (@sections > 0) {
15612: foreach my $item (@sections) {
15613: my ($sec,$gp) = split/:/,$item;
15614: my $class = $args->{'crscode'}.$sec;
15615: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15616: $cenv{'internal.sectionnums'} .= $item.',';
15617: unless ($addcheck eq 'ok') {
1.1263 raeburn 15618: push(@badclasses,$class);
1.444 albertel 15619: }
15620: }
15621: $cenv{'internal.sectionnums'} =~ s/,$//;
15622: }
15623: }
15624: # do not hide course coordinator from staff listing,
15625: # even if privileged
15626: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 15627: # add course coordinator's domain to domains to check for privileged users
15628: # if different to course domain
15629: if ($$crsudom ne $args->{'ccdomain'}) {
15630: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15631: }
1.444 albertel 15632: # add crosslistings
15633: if ($args->{'crsxlist'}) {
15634: $cenv{'internal.crosslistings'}='';
15635: if ($args->{'crsxlist'} =~ m/,/) {
15636: @xlists = split/,/,$args->{'crsxlist'};
15637: } else {
15638: $xlists[0] = $args->{'crsxlist'};
15639: }
15640: if (@xlists > 0) {
15641: foreach my $item (@xlists) {
15642: my ($xl,$gp) = split/:/,$item;
15643: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15644: $cenv{'internal.crosslistings'} .= $item.',';
15645: unless ($addcheck eq 'ok') {
1.1263 raeburn 15646: push(@badclasses,$xl);
1.444 albertel 15647: }
15648: }
15649: $cenv{'internal.crosslistings'} =~ s/,$//;
15650: }
15651: }
15652: if ($args->{'autoadds'}) {
15653: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15654: }
15655: if ($args->{'autodrops'}) {
15656: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15657: }
15658: # check for notification of enrollment changes
15659: my @notified = ();
15660: if ($args->{'notify_owner'}) {
15661: if ($args->{'ccuname'} ne '') {
15662: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15663: }
15664: }
15665: if ($args->{'notify_dc'}) {
15666: if ($uname ne '') {
1.630 raeburn 15667: push(@notified,$uname.':'.$udom);
1.444 albertel 15668: }
15669: }
15670: if (@notified > 0) {
15671: my $notifylist;
15672: if (@notified > 1) {
15673: $notifylist = join(',',@notified);
15674: } else {
15675: $notifylist = $notified[0];
15676: }
15677: $cenv{'internal.notifylist'} = $notifylist;
15678: }
15679: if (@badclasses > 0) {
15680: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 15681: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15682: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15683: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15684: );
1.1264 raeburn 15685: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15686: &mt('That is because the user identified as the course owner ([_1]) does not have rights to access enrollment in these classes, as determined by the policies of your institution on access to official classlists',$cenv{'internal.courseowner'}).$linefeed.$lt{'itis'};
1.541 raeburn 15687: if ($context eq 'auto') {
15688: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 15689: } else {
1.566 albertel 15690: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 15691: }
15692: foreach my $item (@badclasses) {
1.541 raeburn 15693: if ($context eq 'auto') {
1.1261 raeburn 15694: $outcome .= " - $item\n";
1.541 raeburn 15695: } else {
1.1261 raeburn 15696: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15697: }
1.1261 raeburn 15698: }
15699: if ($context eq 'auto') {
15700: $outcome .= $linefeed;
15701: } else {
15702: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 15703: }
1.444 albertel 15704: }
15705: if ($args->{'no_end_date'}) {
15706: $args->{'endaccess'} = 0;
15707: }
15708: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15709: $cenv{'internal.autoend'}=$args->{'enrollend'};
15710: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15711: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15712: if ($args->{'showphotos'}) {
15713: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15714: }
15715: $cenv{'internal.authtype'} = $args->{'authtype'};
15716: $cenv{'internal.autharg'} = $args->{'autharg'};
15717: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15718: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15719: 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');
15720: if ($context eq 'auto') {
15721: $outcome .= $krb_msg;
15722: } else {
1.566 albertel 15723: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15724: }
15725: $outcome .= $linefeed;
1.444 albertel 15726: }
15727: }
15728: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15729: if ($args->{'setpolicy'}) {
15730: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15731: }
15732: if ($args->{'setcontent'}) {
15733: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15734: }
1.1251 raeburn 15735: if ($args->{'setcomment'}) {
15736: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15737: }
1.444 albertel 15738: }
15739: if ($args->{'reshome'}) {
15740: $cenv{'reshome'}=$args->{'reshome'}.'/';
15741: $cenv{'reshome'}=~s/\/+$/\//;
15742: }
15743: #
15744: # course has keyed access
15745: #
15746: if ($args->{'setkeys'}) {
15747: $cenv{'keyaccess'}='yes';
15748: }
15749: # if specified, key authority is not course, but user
15750: # only active if keyaccess is yes
15751: if ($args->{'keyauth'}) {
1.487 albertel 15752: my ($user,$domain) = split(':',$args->{'keyauth'});
15753: $user = &LONCAPA::clean_username($user);
15754: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15755: if ($user ne '' && $domain ne '') {
1.487 albertel 15756: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15757: }
15758: }
15759:
1.1166 raeburn 15760: #
1.1167 raeburn 15761: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 15762: #
15763: if ($args->{'uniquecode'}) {
15764: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15765: if ($code) {
15766: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 15767: my %crsinfo =
15768: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15769: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15770: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15771: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15772: }
1.1166 raeburn 15773: if (ref($coderef)) {
15774: $$coderef = $code;
15775: }
15776: }
15777: }
15778:
1.444 albertel 15779: if ($args->{'disresdis'}) {
15780: $cenv{'pch.roles.denied'}='st';
15781: }
15782: if ($args->{'disablechat'}) {
15783: $cenv{'plc.roles.denied'}='st';
15784: }
15785:
15786: # Record we've not yet viewed the Course Initialization Helper for this
15787: # course
15788: $cenv{'course.helper.not.run'} = 1;
15789: #
15790: # Use new Randomseed
15791: #
15792: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15793: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15794: #
15795: # The encryption code and receipt prefix for this course
15796: #
15797: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15798: $cenv{'internal.encpref'}=100+int(9*rand(99));
15799: #
15800: # By default, use standard grading
15801: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15802:
1.541 raeburn 15803: $outcome .= $linefeed.&mt('Setting environment').': '.
15804: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15805: #
15806: # Open all assignments
15807: #
15808: if ($args->{'openall'}) {
15809: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15810: my %storecontent = ($storeunder => time,
15811: $storeunder.'.type' => 'date_start');
15812:
15813: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15814: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15815: }
15816: #
15817: # Set first page
15818: #
15819: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15820: || ($cloneid)) {
1.445 albertel 15821: use LONCAPA::map;
1.444 albertel 15822: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15823:
15824: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15825: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15826:
1.444 albertel 15827: $outcome .= ($fatal?$errtext:'read ok').' - ';
15828: my $title; my $url;
15829: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15830: $title=&mt('Syllabus');
1.444 albertel 15831: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15832: } else {
1.963 raeburn 15833: $title=&mt('Table of Contents');
1.444 albertel 15834: $url='/adm/navmaps';
15835: }
1.445 albertel 15836:
15837: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15838: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15839:
15840: if ($errtext) { $fatal=2; }
1.541 raeburn 15841: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15842: }
1.566 albertel 15843:
1.1237 raeburn 15844: #
15845: # Set params for Placement Tests
15846: #
1.1239 raeburn 15847: if ($args->{'crstype'} eq 'Placement') {
15848: my %storecontent;
15849: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
15850: my %defaults = (
15851: buttonshide => { value => 'yes',
15852: type => 'string_yesno',},
15853: type => { value => 'randomizetry',
15854: type => 'string_questiontype',},
15855: maxtries => { value => 1,
15856: type => 'int_pos',},
15857: problemstatus => { value => 'no',
15858: type => 'string_problemstatus',},
15859: );
15860: foreach my $key (keys(%defaults)) {
15861: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
15862: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
15863: }
1.1237 raeburn 15864: &Apache::lonnet::cput
15865: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
15866: }
15867:
1.566 albertel 15868: return (1,$outcome);
1.444 albertel 15869: }
15870:
1.1166 raeburn 15871: sub make_unique_code {
15872: my ($cdom,$cnum) = @_;
15873: # get lock on uniquecodes db
15874: my $lockhash = {
15875: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15876: ':'.$env{'user.domain'},
15877: };
15878: my $tries = 0;
15879: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15880: my ($code,$error);
15881:
15882: while (($gotlock ne 'ok') && ($tries<3)) {
15883: $tries ++;
15884: sleep 1;
15885: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15886: }
15887: if ($gotlock eq 'ok') {
15888: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15889: my $gotcode;
15890: my $attempts = 0;
15891: while ((!$gotcode) && ($attempts < 100)) {
15892: $code = &generate_code();
15893: if (!exists($currcodes{$code})) {
15894: $gotcode = 1;
15895: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15896: $error = 'nostore';
15897: }
15898: }
15899: $attempts ++;
15900: }
15901: my @del_lock = ($cnum."\0".'uniquecodes');
15902: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15903: } else {
15904: $error = 'nolock';
15905: }
15906: return ($code,$error);
15907: }
15908:
15909: sub generate_code {
15910: my $code;
15911: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15912: for (my $i=0; $i<6; $i++) {
15913: my $lettnum = int (rand 2);
15914: my $item = '';
15915: if ($lettnum) {
15916: $item = $letts[int( rand(18) )];
15917: } else {
15918: $item = 1+int( rand(8) );
15919: }
15920: $code .= $item;
15921: }
15922: return $code;
15923: }
15924:
1.444 albertel 15925: ############################################################
15926: ############################################################
15927:
1.1237 raeburn 15928: # Community, Course and Placement Test
1.378 raeburn 15929: sub course_type {
15930: my ($cid) = @_;
15931: if (!defined($cid)) {
15932: $cid = $env{'request.course.id'};
15933: }
1.404 albertel 15934: if (defined($env{'course.'.$cid.'.type'})) {
15935: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15936: } else {
15937: return 'Course';
1.377 raeburn 15938: }
15939: }
1.156 albertel 15940:
1.406 raeburn 15941: sub group_term {
15942: my $crstype = &course_type();
15943: my %names = (
15944: 'Course' => 'group',
1.865 raeburn 15945: 'Community' => 'group',
1.1237 raeburn 15946: 'Placement' => 'group',
1.406 raeburn 15947: );
15948: return $names{$crstype};
15949: }
15950:
1.902 raeburn 15951: sub course_types {
1.1237 raeburn 15952: my @types = ('official','unofficial','community','textbook','placement');
1.902 raeburn 15953: my %typename = (
15954: official => 'Official course',
15955: unofficial => 'Unofficial course',
15956: community => 'Community',
1.1165 raeburn 15957: textbook => 'Textbook course',
1.1237 raeburn 15958: placement => 'Placement test',
1.902 raeburn 15959: );
15960: return (\@types,\%typename);
15961: }
15962:
1.156 albertel 15963: sub icon {
15964: my ($file)=@_;
1.505 albertel 15965: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15966: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15967: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15968: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15969: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15970: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15971: $curfext.".gif") {
15972: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15973: $curfext.".gif";
15974: }
15975: }
1.249 albertel 15976: return &lonhttpdurl($iconname);
1.154 albertel 15977: }
1.84 albertel 15978:
1.575 albertel 15979: sub lonhttpdurl {
1.692 www 15980: #
15981: # Had been used for "small fry" static images on separate port 8080.
15982: # Modify here if lightweight http functionality desired again.
15983: # Currently eliminated due to increasing firewall issues.
15984: #
1.575 albertel 15985: my ($url)=@_;
1.692 www 15986: return $url;
1.215 albertel 15987: }
15988:
1.213 albertel 15989: sub connection_aborted {
15990: my ($r)=@_;
15991: $r->print(" ");$r->rflush();
15992: my $c = $r->connection;
15993: return $c->aborted();
15994: }
15995:
1.221 foxr 15996: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15997: # strings as 'strings'.
15998: sub escape_single {
1.221 foxr 15999: my ($input) = @_;
1.223 albertel 16000: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16001: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16002: return $input;
16003: }
1.223 albertel 16004:
1.222 foxr 16005: # Same as escape_single, but escape's "'s This
16006: # can be used for "strings"
16007: sub escape_double {
16008: my ($input) = @_;
16009: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16010: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16011: return $input;
16012: }
1.223 albertel 16013:
1.222 foxr 16014: # Escapes the last element of a full URL.
16015: sub escape_url {
16016: my ($url) = @_;
1.238 raeburn 16017: my @urlslices = split(/\//, $url,-1);
1.369 www 16018: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16019: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16020: }
1.462 albertel 16021:
1.820 raeburn 16022: sub compare_arrays {
16023: my ($arrayref1,$arrayref2) = @_;
16024: my (@difference,%count);
16025: @difference = ();
16026: %count = ();
16027: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16028: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16029: foreach my $element (keys(%count)) {
16030: if ($count{$element} == 1) {
16031: push(@difference,$element);
16032: }
16033: }
16034: }
16035: return @difference;
16036: }
16037:
1.817 bisitz 16038: # -------------------------------------------------------- Initialize user login
1.462 albertel 16039: sub init_user_environment {
1.463 albertel 16040: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16041: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16042:
16043: my $public=($username eq 'public' && $domain eq 'public');
16044:
1.1062 raeburn 16045: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16046: my $now=time;
16047:
16048: if ($public) {
16049: my $max_public=100;
16050: my $oldest;
16051: my $oldest_time=0;
16052: for(my $next=1;$next<=$max_public;$next++) {
16053: if (-e $lonids."/publicuser_$next.id") {
16054: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16055: if ($mtime<$oldest_time || !$oldest_time) {
16056: $oldest_time=$mtime;
16057: $oldest=$next;
16058: }
16059: } else {
16060: $cookie="publicuser_$next";
16061: last;
16062: }
16063: }
16064: if (!$cookie) { $cookie="publicuser_$oldest"; }
16065: } else {
1.1275 raeburn 16066: # See if old ID present, if so, remove if this isn't a robot,
16067: # killing any existing non-robot sessions
1.463 albertel 16068: if (!$args->{'robot'}) {
16069: opendir(DIR,$lonids);
16070: while ($filename=readdir(DIR)) {
16071: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
16072: unlink($lonids.'/'.$filename);
16073: }
1.462 albertel 16074: }
1.463 albertel 16075: closedir(DIR);
1.1204 raeburn 16076: # If there is a undeleted lockfile for the user's paste buffer remove it.
16077: my $namespace = 'nohist_courseeditor';
16078: my $lockingkey = 'paste'."\0".'locked_num';
16079: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16080: $domain,$username);
16081: if (exists($lockhash{$lockingkey})) {
16082: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16083: unless ($delresult eq 'ok') {
16084: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16085: }
16086: }
1.462 albertel 16087: }
16088: # Give them a new cookie
1.463 albertel 16089: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16090: : $now.$$.int(rand(10000)));
1.463 albertel 16091: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16092:
16093: # Initialize roles
16094:
1.1062 raeburn 16095: ($userroles,$firstaccenv,$timerintenv) =
16096: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16097: }
16098: # ------------------------------------ Check browser type and MathML capability
16099:
1.1194 raeburn 16100: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16101: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16102:
16103: # ------------------------------------------------------------- Get environment
16104:
16105: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16106: my ($tmp) = keys(%userenv);
1.1275 raeburn 16107: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16108: undef(%userenv);
16109: }
16110: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16111: $form->{'interface'}=$userenv{'interface'};
16112: }
16113: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16114:
16115: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16116: foreach my $option ('interface','localpath','localres') {
16117: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16118: }
16119: # --------------------------------------------------------- Write first profile
16120:
16121: {
16122: my %initial_env =
16123: ("user.name" => $username,
16124: "user.domain" => $domain,
16125: "user.home" => $authhost,
16126: "browser.type" => $clientbrowser,
16127: "browser.version" => $clientversion,
16128: "browser.mathml" => $clientmathml,
16129: "browser.unicode" => $clientunicode,
16130: "browser.os" => $clientos,
1.1137 raeburn 16131: "browser.mobile" => $clientmobile,
1.1141 raeburn 16132: "browser.info" => $clientinfo,
1.1194 raeburn 16133: "browser.osversion" => $clientosversion,
1.462 albertel 16134: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16135: "request.course.fn" => '',
16136: "request.course.uri" => '',
16137: "request.course.sec" => '',
16138: "request.role" => 'cm',
16139: "request.role.adv" => $env{'user.adv'},
16140: "request.host" => $ENV{'REMOTE_ADDR'},);
16141:
16142: if ($form->{'localpath'}) {
16143: $initial_env{"browser.localpath"} = $form->{'localpath'};
16144: $initial_env{"browser.localres"} = $form->{'localres'};
16145: }
16146:
16147: if ($form->{'interface'}) {
16148: $form->{'interface'}=~s/\W//gs;
16149: $initial_env{"browser.interface"} = $form->{'interface'};
16150: $env{'browser.interface'}=$form->{'interface'};
16151: }
16152:
1.1157 raeburn 16153: if ($form->{'iptoken'}) {
16154: my $lonhost = $r->dir_config('lonHostID');
16155: $initial_env{"user.noloadbalance"} = $lonhost;
16156: $env{'user.noloadbalance'} = $lonhost;
16157: }
16158:
1.1268 raeburn 16159: if ($form->{'noloadbalance'}) {
16160: my @hosts = &Apache::lonnet::current_machine_ids();
16161: my $hosthere = $form->{'noloadbalance'};
16162: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16163: $initial_env{"user.noloadbalance"} = $hosthere;
16164: $env{'user.noloadbalance'} = $hosthere;
16165: }
16166: }
16167:
1.1016 raeburn 16168: unless ($domain eq 'public') {
1.1273 raeburn 16169: my %is_adv = ( is_adv => $env{'user.adv'} );
16170: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16171:
16172: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16173: $userenv{'availabletools.'.$tool} =
16174: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16175: undef,\%userenv,\%domdef,\%is_adv);
16176: }
1.980 raeburn 16177:
1.1273 raeburn 16178: foreach my $crstype ('official','unofficial','community','textbook','placement') {
16179: $userenv{'canrequest.'.$crstype} =
16180: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16181: 'reload','requestcourses',
16182: \%userenv,\%domdef,\%is_adv);
16183: }
1.724 raeburn 16184:
1.1273 raeburn 16185: $userenv{'canrequest.author'} =
16186: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16187: 'reload','requestauthor',
1.980 raeburn 16188: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16189: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16190: $domain,$username);
16191: my $reqstatus = $reqauthor{'author_status'};
16192: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16193: if (ref($reqauthor{'author'}) eq 'HASH') {
16194: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16195: $reqauthor{'author'}{'timestamp'};
16196: }
1.1092 raeburn 16197: }
16198: }
16199:
1.462 albertel 16200: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16201:
1.462 albertel 16202: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16203: &GDBM_WRCREAT(),0640)) {
16204: &_add_to_env(\%disk_env,\%initial_env);
16205: &_add_to_env(\%disk_env,\%userenv,'environment.');
16206: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16207: if (ref($firstaccenv) eq 'HASH') {
16208: &_add_to_env(\%disk_env,$firstaccenv);
16209: }
16210: if (ref($timerintenv) eq 'HASH') {
16211: &_add_to_env(\%disk_env,$timerintenv);
16212: }
1.463 albertel 16213: if (ref($args->{'extra_env'})) {
16214: &_add_to_env(\%disk_env,$args->{'extra_env'});
16215: }
1.462 albertel 16216: untie(%disk_env);
16217: } else {
1.705 tempelho 16218: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16219: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16220: return 'error: '.$!;
16221: }
16222: }
16223: $env{'request.role'}='cm';
16224: $env{'request.role.adv'}=$env{'user.adv'};
16225: $env{'browser.type'}=$clientbrowser;
16226:
16227: return $cookie;
16228:
16229: }
16230:
16231: sub _add_to_env {
16232: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16233: if (ref($env_data) eq 'HASH') {
16234: while (my ($key,$value) = each(%$env_data)) {
16235: $idf->{$prefix.$key} = $value;
16236: $env{$prefix.$key} = $value;
16237: }
1.462 albertel 16238: }
16239: }
16240:
1.685 tempelho 16241: # --- Get the symbolic name of a problem and the url
16242: sub get_symb {
16243: my ($request,$silent) = @_;
1.726 raeburn 16244: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16245: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16246: if ($symb eq '') {
16247: if (!$silent) {
1.1071 raeburn 16248: if (ref($request)) {
16249: $request->print("Unable to handle ambiguous references:$url:.");
16250: }
1.685 tempelho 16251: return ();
16252: }
16253: }
16254: &Apache::lonenc::check_decrypt(\$symb);
16255: return ($symb);
16256: }
16257:
16258: # --------------------------------------------------------------Get annotation
16259:
16260: sub get_annotation {
16261: my ($symb,$enc) = @_;
16262:
16263: my $key = $symb;
16264: if (!$enc) {
16265: $key =
16266: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16267: }
16268: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16269: return $annotation{$key};
16270: }
16271:
16272: sub clean_symb {
1.731 raeburn 16273: my ($symb,$delete_enc) = @_;
1.685 tempelho 16274:
16275: &Apache::lonenc::check_decrypt(\$symb);
16276: my $enc = $env{'request.enc'};
1.731 raeburn 16277: if ($delete_enc) {
1.730 raeburn 16278: delete($env{'request.enc'});
16279: }
1.685 tempelho 16280:
16281: return ($symb,$enc);
16282: }
1.462 albertel 16283:
1.1181 raeburn 16284: ############################################################
16285: ############################################################
16286:
16287: =pod
16288:
16289: =head1 Routines for building display used to search for courses
16290:
16291:
16292: =over 4
16293:
16294: =item * &build_filters()
16295:
16296: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16297: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16298: and quotacheck.pl
16299:
1.1181 raeburn 16300:
16301: Inputs:
16302:
16303: filterlist - anonymous array of fields to include as potential filters
16304:
16305: crstype - course type
16306:
16307: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16308: to pop-open a course selector (will contain "extra element").
16309:
16310: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16311:
16312: filter - anonymous hash of criteria and their values
16313:
16314: action - form action
16315:
16316: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16317:
1.1182 raeburn 16318: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16319:
16320: cloneruname - username of owner of new course who wants to clone
16321:
16322: clonerudom - domain of owner of new course who wants to clone
16323:
16324: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16325:
16326: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16327:
16328: codedom - domain
16329:
16330: formname - value of form element named "form".
16331:
16332: fixeddom - domain, if fixed.
16333:
16334: prevphase - value to assign to form element named "phase" when going back to the previous screen
16335:
16336: cnameelement - name of form element in form on opener page which will receive title of selected course
16337:
16338: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16339:
16340: cdomelement - name of form element in form on opener page which will receive domain of selected course
16341:
16342: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16343:
16344: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16345:
16346: clonewarning - warning message about missing information for intended course owner when DC creates a course
16347:
1.1182 raeburn 16348:
1.1181 raeburn 16349: Returns: $output - HTML for display of search criteria, and hidden form elements.
16350:
1.1182 raeburn 16351:
1.1181 raeburn 16352: Side Effects: None
16353:
16354: =cut
16355:
16356: # ---------------------------------------------- search for courses based on last activity etc.
16357:
16358: sub build_filters {
16359: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16360: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16361: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16362: $cnameelement,$cnumelement,$cdomelement,$setroles,
16363: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16364: my ($list,$jscript);
1.1181 raeburn 16365: my $onchange = 'javascript:updateFilters(this)';
16366: my ($domainselectform,$sincefilterform,$createdfilterform,
16367: $ownerdomselectform,$persondomselectform,$instcodeform,
16368: $typeselectform,$instcodetitle);
16369: if ($formname eq '') {
16370: $formname = $caller;
16371: }
16372: foreach my $item (@{$filterlist}) {
16373: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16374: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16375: if ($item eq 'domainfilter') {
16376: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16377: } elsif ($item eq 'coursefilter') {
16378: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16379: } elsif ($item eq 'ownerfilter') {
16380: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16381: } elsif ($item eq 'ownerdomfilter') {
16382: $filter->{'ownerdomfilter'} =
16383: &LONCAPA::clean_domain($filter->{$item});
16384: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16385: 'ownerdomfilter',1);
16386: } elsif ($item eq 'personfilter') {
16387: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16388: } elsif ($item eq 'persondomfilter') {
16389: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16390: 'persondomfilter',1);
16391: } else {
16392: $filter->{$item} =~ s/\W//g;
16393: }
16394: if (!$filter->{$item}) {
16395: $filter->{$item} = '';
16396: }
16397: }
16398: if ($item eq 'domainfilter') {
16399: my $allow_blank = 1;
16400: if ($formname eq 'portform') {
16401: $allow_blank=0;
16402: } elsif ($formname eq 'studentform') {
16403: $allow_blank=0;
16404: }
16405: if ($fixeddom) {
16406: $domainselectform = '<input type="hidden" name="domainfilter"'.
16407: ' value="'.$codedom.'" />'.
16408: &Apache::lonnet::domain($codedom,'description');
16409: } else {
16410: $domainselectform = &select_dom_form($filter->{$item},
16411: 'domainfilter',
16412: $allow_blank,'',$onchange);
16413: }
16414: } else {
16415: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16416: }
16417: }
16418:
16419: # last course activity filter and selection
16420: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16421:
16422: # course created filter and selection
16423: if (exists($filter->{'createdfilter'})) {
16424: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16425: }
16426:
1.1239 raeburn 16427: my $prefix = $crstype;
16428: if ($crstype eq 'Placement') {
16429: $prefix = 'Placement Test'
16430: }
1.1181 raeburn 16431: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16432: 'cac' => "$prefix Activity",
16433: 'ccr' => "$prefix Created",
16434: 'cde' => "$prefix Title",
16435: 'cdo' => "$prefix Domain",
1.1181 raeburn 16436: 'ins' => 'Institutional Code',
16437: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16438: 'cow' => "$prefix Owner/Co-owner",
16439: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16440: 'cog' => 'Type',
16441: );
16442:
16443: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16444: my $typeval = 'Course';
16445: if ($crstype eq 'Community') {
16446: $typeval = 'Community';
1.1239 raeburn 16447: } elsif ($crstype eq 'Placement') {
16448: $typeval = 'Placement';
1.1181 raeburn 16449: }
16450: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16451: } else {
16452: $typeselectform = '<select name="type" size="1"';
16453: if ($onchange) {
16454: $typeselectform .= ' onchange="'.$onchange.'"';
16455: }
16456: $typeselectform .= '>'."\n";
1.1237 raeburn 16457: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16458: my $shown;
16459: if ($posstype eq 'Placement') {
16460: $shown = &mt('Placement Test');
16461: } else {
16462: $shown = &mt($posstype);
16463: }
1.1181 raeburn 16464: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 16465: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 16466: }
16467: $typeselectform.="</select>";
16468: }
16469:
16470: my ($cloneableonlyform,$cloneabletitle);
16471: if (exists($filter->{'cloneableonly'})) {
16472: my $cloneableon = '';
16473: my $cloneableoff = ' checked="checked"';
16474: if ($filter->{'cloneableonly'}) {
16475: $cloneableon = $cloneableoff;
16476: $cloneableoff = '';
16477: }
16478: $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>';
16479: if ($formname eq 'ccrs') {
1.1187 bisitz 16480: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 16481: } else {
16482: $cloneabletitle = &mt('Cloneable by you');
16483: }
16484: }
16485: my $officialjs;
16486: if ($crstype eq 'Course') {
16487: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 16488: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16489: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16490: if ($codedom) {
1.1181 raeburn 16491: $officialjs = 1;
16492: ($instcodeform,$jscript,$$numtitlesref) =
16493: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16494: $officialjs,$codetitlesref);
16495: if ($jscript) {
1.1182 raeburn 16496: $jscript = '<script type="text/javascript">'."\n".
16497: '// <![CDATA['."\n".
16498: $jscript."\n".
16499: '// ]]>'."\n".
16500: '</script>'."\n";
1.1181 raeburn 16501: }
16502: }
16503: if ($instcodeform eq '') {
16504: $instcodeform =
16505: '<input type="text" name="instcodefilter" size="10" value="'.
16506: $list->{'instcodefilter'}.'" />';
16507: $instcodetitle = $lt{'ins'};
16508: } else {
16509: $instcodetitle = $lt{'inc'};
16510: }
16511: if ($fixeddom) {
16512: $instcodetitle .= '<br />('.$codedom.')';
16513: }
16514: }
16515: }
16516: my $output = qq|
16517: <form method="post" name="filterpicker" action="$action">
16518: <input type="hidden" name="form" value="$formname" />
16519: |;
16520: if ($formname eq 'modifycourse') {
16521: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16522: '<input type="hidden" name="prevphase" value="'.
16523: $prevphase.'" />'."\n";
1.1198 musolffc 16524: } elsif ($formname eq 'quotacheck') {
16525: $output .= qq|
16526: <input type="hidden" name="sortby" value="" />
16527: <input type="hidden" name="sortorder" value="" />
16528: |;
16529: } else {
1.1181 raeburn 16530: my $name_input;
16531: if ($cnameelement ne '') {
16532: $name_input = '<input type="hidden" name="cnameelement" value="'.
16533: $cnameelement.'" />';
16534: }
16535: $output .= qq|
1.1182 raeburn 16536: <input type="hidden" name="cnumelement" value="$cnumelement" />
16537: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 16538: $name_input
16539: $roleelement
16540: $multelement
16541: $typeelement
16542: |;
16543: if ($formname eq 'portform') {
16544: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16545: }
16546: }
16547: if ($fixeddom) {
16548: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16549: }
16550: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16551: if ($sincefilterform) {
16552: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16553: .$sincefilterform
16554: .&Apache::lonhtmlcommon::row_closure();
16555: }
16556: if ($createdfilterform) {
16557: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16558: .$createdfilterform
16559: .&Apache::lonhtmlcommon::row_closure();
16560: }
16561: if ($domainselectform) {
16562: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16563: .$domainselectform
16564: .&Apache::lonhtmlcommon::row_closure();
16565: }
16566: if ($typeselectform) {
16567: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16568: $output .= $typeselectform;
16569: } else {
16570: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16571: .$typeselectform
16572: .&Apache::lonhtmlcommon::row_closure();
16573: }
16574: }
16575: if ($instcodeform) {
16576: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16577: .$instcodeform
16578: .&Apache::lonhtmlcommon::row_closure();
16579: }
16580: if (exists($filter->{'ownerfilter'})) {
16581: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16582: '<table><tr><td>'.&mt('Username').'<br />'.
16583: '<input type="text" name="ownerfilter" size="20" value="'.
16584: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16585: $ownerdomselectform.'</td></tr></table>'.
16586: &Apache::lonhtmlcommon::row_closure();
16587: }
16588: if (exists($filter->{'personfilter'})) {
16589: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16590: '<table><tr><td>'.&mt('Username').'<br />'.
16591: '<input type="text" name="personfilter" size="20" value="'.
16592: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16593: $persondomselectform.'</td></tr></table>'.
16594: &Apache::lonhtmlcommon::row_closure();
16595: }
16596: if (exists($filter->{'coursefilter'})) {
16597: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16598: .'<input type="text" name="coursefilter" size="25" value="'
16599: .$list->{'coursefilter'}.'" />'
16600: .&Apache::lonhtmlcommon::row_closure();
16601: }
16602: if ($cloneableonlyform) {
16603: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16604: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16605: }
16606: if (exists($filter->{'descriptfilter'})) {
16607: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16608: .'<input type="text" name="descriptfilter" size="40" value="'
16609: .$list->{'descriptfilter'}.'" />'
16610: .&Apache::lonhtmlcommon::row_closure(1);
16611: }
16612: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16613: '<input type="hidden" name="updater" value="" />'."\n".
16614: '<input type="submit" name="gosearch" value="'.
16615: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16616: return $jscript.$clonewarning.$output;
16617: }
16618:
16619: =pod
16620:
16621: =item * &timebased_select_form()
16622:
1.1182 raeburn 16623: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 16624: filter e.g., Course Activity, Course Created, when searching for courses
16625: or communities
16626:
16627: Inputs:
16628:
16629: item - name of form element (sincefilter or createdfilter)
16630:
16631: filter - anonymous hash of criteria and their values
16632:
16633: Returns: HTML for a select box contained a blank, then six time selections,
16634: with value set in incoming form variables currently selected.
16635:
16636: Side Effects: None
16637:
16638: =cut
16639:
16640: sub timebased_select_form {
16641: my ($item,$filter) = @_;
16642: if (ref($filter) eq 'HASH') {
16643: $filter->{$item} =~ s/[^\d-]//g;
16644: if (!$filter->{$item}) { $filter->{$item}=-1; }
16645: return &select_form(
16646: $filter->{$item},
16647: $item,
16648: { '-1' => '',
16649: '86400' => &mt('today'),
16650: '604800' => &mt('last week'),
16651: '2592000' => &mt('last month'),
16652: '7776000' => &mt('last three months'),
16653: '15552000' => &mt('last six months'),
16654: '31104000' => &mt('last year'),
16655: 'select_form_order' =>
16656: ['-1','86400','604800','2592000','7776000',
16657: '15552000','31104000']});
16658: }
16659: }
16660:
16661: =pod
16662:
16663: =item * &js_changer()
16664:
16665: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 16666: when course type or domain is changed, and also to hide 'Searching ...' on
16667: page load completion for page showing search result.
1.1181 raeburn 16668:
16669: Inputs: None
16670:
1.1183 raeburn 16671: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 16672:
16673: Side Effects: None
16674:
16675: =cut
16676:
16677: sub js_changer {
16678: return <<ENDJS;
16679: <script type="text/javascript">
16680: // <![CDATA[
16681: function updateFilters(caller) {
16682: if (typeof(caller) != "undefined") {
16683: document.filterpicker.updater.value = caller.name;
16684: }
16685: document.filterpicker.submit();
16686: }
1.1183 raeburn 16687:
16688: function hideSearching() {
16689: if (document.getElementById('searching')) {
16690: document.getElementById('searching').style.display = 'none';
16691: }
16692: return;
16693: }
16694:
1.1181 raeburn 16695: // ]]>
16696: </script>
16697:
16698: ENDJS
16699: }
16700:
16701: =pod
16702:
1.1182 raeburn 16703: =item * &search_courses()
16704:
16705: Process selected filters form course search form and pass to lonnet::courseiddump
16706: to retrieve a hash for which keys are courseIDs which match the selected filters.
16707:
16708: Inputs:
16709:
16710: dom - domain being searched
16711:
16712: type - course type ('Course' or 'Community' or '.' if any).
16713:
16714: filter - anonymous hash of criteria and their values
16715:
16716: numtitles - for institutional codes - number of categories
16717:
16718: cloneruname - optional username of new course owner
16719:
16720: clonerudom - optional domain of new course owner
16721:
1.1221 raeburn 16722: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 16723: (used when DC is using course creation form)
16724:
16725: codetitles - reference to array of titles of components in institutional codes (official courses).
16726:
1.1221 raeburn 16727: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16728: (and so can clone automatically)
16729:
16730: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16731:
16732: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16733: courses to clone
1.1182 raeburn 16734:
16735: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16736:
16737:
16738: Side Effects: None
16739:
16740: =cut
16741:
16742:
16743: sub search_courses {
1.1221 raeburn 16744: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16745: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 16746: my (%courses,%showcourses,$cloner);
16747: if (($filter->{'ownerfilter'} ne '') ||
16748: ($filter->{'ownerdomfilter'} ne '')) {
16749: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16750: $filter->{'ownerdomfilter'};
16751: }
16752: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16753: if (!$filter->{$item}) {
16754: $filter->{$item}='.';
16755: }
16756: }
16757: my $now = time;
16758: my $timefilter =
16759: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16760: my ($createdbefore,$createdafter);
16761: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16762: $createdbefore = $now;
16763: $createdafter = $now-$filter->{'createdfilter'};
16764: }
16765: my ($instcodefilter,$regexpok);
16766: if ($numtitles) {
16767: if ($env{'form.official'} eq 'on') {
16768: $instcodefilter =
16769: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16770: $regexpok = 1;
16771: } elsif ($env{'form.official'} eq 'off') {
16772: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16773: unless ($instcodefilter eq '') {
16774: $regexpok = -1;
16775: }
16776: }
16777: } else {
16778: $instcodefilter = $filter->{'instcodefilter'};
16779: }
16780: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16781: if ($type eq '') { $type = '.'; }
16782:
16783: if (($clonerudom ne '') && ($cloneruname ne '')) {
16784: $cloner = $cloneruname.':'.$clonerudom;
16785: }
16786: %courses = &Apache::lonnet::courseiddump($dom,
16787: $filter->{'descriptfilter'},
16788: $timefilter,
16789: $instcodefilter,
16790: $filter->{'combownerfilter'},
16791: $filter->{'coursefilter'},
16792: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 16793: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 16794: $filter->{'cloneableonly'},
16795: $createdbefore,$createdafter,undef,
1.1221 raeburn 16796: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 16797: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16798: my $ccrole;
16799: if ($type eq 'Community') {
16800: $ccrole = 'co';
16801: } else {
16802: $ccrole = 'cc';
16803: }
16804: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16805: $filter->{'persondomfilter'},
16806: 'userroles',undef,
16807: [$ccrole,'in','ad','ep','ta','cr'],
16808: $dom);
16809: foreach my $role (keys(%rolehash)) {
16810: my ($cnum,$cdom,$courserole) = split(':',$role);
16811: my $cid = $cdom.'_'.$cnum;
16812: if (exists($courses{$cid})) {
16813: if (ref($courses{$cid}) eq 'HASH') {
16814: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16815: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 16816: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 16817: }
16818: } else {
16819: $courses{$cid}{roles} = [$courserole];
16820: }
16821: $showcourses{$cid} = $courses{$cid};
16822: }
16823: }
16824: }
16825: %courses = %showcourses;
16826: }
16827: return %courses;
16828: }
16829:
16830: =pod
16831:
1.1181 raeburn 16832: =back
16833:
1.1207 raeburn 16834: =head1 Routines for version requirements for current course.
16835:
16836: =over 4
16837:
16838: =item * &check_release_required()
16839:
16840: Compares required LON-CAPA version with version on server, and
16841: if required version is newer looks for a server with the required version.
16842:
16843: Looks first at servers in user's owen domain; if none suitable, looks at
16844: servers in course's domain are permitted to host sessions for user's domain.
16845:
16846: Inputs:
16847:
16848: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16849:
16850: $courseid - Course ID of current course
16851:
16852: $rolecode - User's current role in course (for switchserver query string).
16853:
16854: $required - LON-CAPA version needed by course (format: Major.Minor).
16855:
16856:
16857: Returns:
16858:
16859: $switchserver - query string tp append to /adm/switchserver call (if
16860: current server's LON-CAPA version is too old.
16861:
16862: $warning - Message is displayed if no suitable server could be found.
16863:
16864: =cut
16865:
16866: sub check_release_required {
16867: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16868: my ($switchserver,$warning);
16869: if ($required ne '') {
16870: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16871: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16872: if ($reqdmajor ne '' && $reqdminor ne '') {
16873: my $otherserver;
16874: if (($major eq '' && $minor eq '') ||
16875: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16876: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16877: my $switchlcrev =
16878: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16879: $userdomserver);
16880: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16881: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16882: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16883: my $cdom = $env{'course.'.$courseid.'.domain'};
16884: if ($cdom ne $env{'user.domain'}) {
16885: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16886: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16887: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16888: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16889: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16890: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16891: my $canhost =
16892: &Apache::lonnet::can_host_session($env{'user.domain'},
16893: $coursedomserver,
16894: $remoterev,
16895: $udomdefaults{'remotesessions'},
16896: $defdomdefaults{'hostedsessions'});
16897:
16898: if ($canhost) {
16899: $otherserver = $coursedomserver;
16900: } else {
16901: $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).'<br />'. &mt("No suitable server could be found amongst servers in either your own domain or in the course's domain.");
16902: }
16903: } else {
16904: $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).'<br />'.&mt("No suitable server could be found amongst servers in your own domain (which is also the course's domain).");
16905: }
16906: } else {
16907: $otherserver = $userdomserver;
16908: }
16909: }
16910: if ($otherserver ne '') {
16911: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16912: }
16913: }
16914: }
16915: return ($switchserver,$warning);
16916: }
16917:
16918: =pod
16919:
16920: =item * &check_release_result()
16921:
16922: Inputs:
16923:
16924: $switchwarning - Warning message if no suitable server found to host session.
16925:
16926: $switchserver - query string to append to /adm/switchserver containing lonHostID
16927: and current role.
16928:
16929: Returns: HTML to display with information about requirement to switch server.
16930: Either displaying warning with link to Roles/Courses screen or
16931: display link to switchserver.
16932:
1.1181 raeburn 16933: =cut
16934:
1.1207 raeburn 16935: sub check_release_result {
16936: my ($switchwarning,$switchserver) = @_;
16937: my $output = &start_page('Selected course unavailable on this server').
16938: '<p class="LC_warning">';
16939: if ($switchwarning) {
16940: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16941: if (&show_course()) {
16942: $output .= &mt('Display courses');
16943: } else {
16944: $output .= &mt('Display roles');
16945: }
16946: $output .= '</a>';
16947: } elsif ($switchserver) {
16948: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16949: '<br />'.
16950: '<a href="/adm/switchserver?'.$switchserver.'">'.
16951: &mt('Switch Server').
16952: '</a>';
16953: }
16954: $output .= '</p>'.&end_page();
16955: return $output;
16956: }
16957:
16958: =pod
16959:
16960: =item * &needs_coursereinit()
16961:
16962: Determine if course contents stored for user's session needs to be
16963: refreshed, because content has changed since "Big Hash" last tied.
16964:
16965: Check for change is made if time last checked is more than 10 minutes ago
16966: (by default).
16967:
16968: Inputs:
16969:
16970: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16971:
16972: $interval (optional) - Time which may elapse (in s) between last check for content
16973: change in current course. (default: 600 s).
16974:
16975: Returns: an array; first element is:
16976:
16977: =over 4
16978:
16979: 'switch' - if content updates mean user's session
16980: needs to be switched to a server running a newer LON-CAPA version
16981:
16982: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16983: on current server hosting user's session
16984:
16985: '' - if no action required.
16986:
16987: =back
16988:
16989: If first item element is 'switch':
16990:
16991: second item is $switchwarning - Warning message if no suitable server found to host session.
16992:
16993: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16994: and current role.
16995:
16996: otherwise: no other elements returned.
16997:
16998: =back
16999:
17000: =cut
17001:
17002: sub needs_coursereinit {
17003: my ($loncaparev,$interval) = @_;
17004: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17005: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17006: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17007: my $now = time;
17008: if ($interval eq '') {
17009: $interval = 600;
17010: }
17011: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 17012: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1283 raeburn 17013: my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
1.1282 raeburn 17014: if ($blocked) {
17015: return ();
17016: }
1.1207 raeburn 17017: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17018: if ($lastchange > $env{'request.course.tied'}) {
17019: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17020: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17021: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17022: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17023: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17024: $curr_reqd_hash{'internal.releaserequired'}});
17025: my ($switchserver,$switchwarning) =
17026: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17027: $curr_reqd_hash{'internal.releaserequired'});
17028: if ($switchwarning ne '' || $switchserver ne '') {
17029: return ('switch',$switchwarning,$switchserver);
17030: }
17031: }
17032: }
17033: return ('update');
17034: }
17035: }
17036: return ();
17037: }
1.1181 raeburn 17038:
1.1083 raeburn 17039: sub update_content_constraints {
17040: my ($cdom,$cnum,$chome,$cid) = @_;
17041: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17042: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
17043: my %checkresponsetypes;
17044: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17045: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17046: if ($item eq 'resourcetag') {
17047: if ($name eq 'responsetype') {
17048: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17049: }
17050: }
17051: }
17052: my $navmap = Apache::lonnavmaps::navmap->new();
17053: if (defined($navmap)) {
17054: my %allresponses;
17055: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
17056: my %responses = $res->responseTypes();
17057: foreach my $key (keys(%responses)) {
17058: next unless(exists($checkresponsetypes{$key}));
17059: $allresponses{$key} += $responses{$key};
17060: }
17061: }
17062: foreach my $key (keys(%allresponses)) {
17063: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17064: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17065: ($reqdmajor,$reqdminor) = ($major,$minor);
17066: }
17067: }
17068: undef($navmap);
17069: }
17070: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17071: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17072: }
17073: return;
17074: }
17075:
1.1110 raeburn 17076: sub allmaps_incourse {
17077: my ($cdom,$cnum,$chome,$cid) = @_;
17078: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17079: $cid = $env{'request.course.id'};
17080: $cdom = $env{'course.'.$cid.'.domain'};
17081: $cnum = $env{'course.'.$cid.'.num'};
17082: $chome = $env{'course.'.$cid.'.home'};
17083: }
17084: my %allmaps = ();
17085: my $lastchange =
17086: &Apache::lonnet::get_coursechange($cdom,$cnum);
17087: if ($lastchange > $env{'request.course.tied'}) {
17088: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17089: unless ($ferr) {
17090: &update_content_constraints($cdom,$cnum,$chome,$cid);
17091: }
17092: }
17093: my $navmap = Apache::lonnavmaps::navmap->new();
17094: if (defined($navmap)) {
17095: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17096: $allmaps{$res->src()} = 1;
17097: }
17098: }
17099: return \%allmaps;
17100: }
17101:
1.1083 raeburn 17102: sub parse_supplemental_title {
17103: my ($title) = @_;
17104:
17105: my ($foldertitle,$renametitle);
17106: if ($title =~ /&&&/) {
17107: $title = &HTML::Entites::decode($title);
17108: }
17109: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17110: $renametitle=$4;
17111: my ($time,$uname,$udom) = ($1,$2,$3);
17112: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17113: my $name = &plainname($uname,$udom);
17114: $name = &HTML::Entities::encode($name,'"<>&\'');
17115: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17116: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17117: $name.': <br />'.$foldertitle;
17118: }
17119: if (wantarray) {
17120: return ($title,$foldertitle,$renametitle);
17121: }
17122: return $title;
17123: }
17124:
1.1143 raeburn 17125: sub recurse_supplemental {
17126: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
17127: if ($suppmap) {
17128: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17129: if ($fatal) {
17130: $errors ++;
17131: } else {
17132: if ($#LONCAPA::map::resources > 0) {
17133: foreach my $res (@LONCAPA::map::resources) {
17134: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17135: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17136: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
17137: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 17138: } else {
17139: $numfiles ++;
17140: }
17141: }
17142: }
17143: }
17144: }
17145: }
17146: return ($numfiles,$errors);
17147: }
17148:
1.1101 raeburn 17149: sub symb_to_docspath {
1.1267 raeburn 17150: my ($symb,$navmapref) = @_;
17151: return unless ($symb && ref($navmapref));
1.1101 raeburn 17152: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17153: if ($resurl=~/\.(sequence|page)$/) {
17154: $mapurl=$resurl;
17155: } elsif ($resurl eq 'adm/navmaps') {
17156: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17157: }
17158: my $mapresobj;
1.1267 raeburn 17159: unless (ref($$navmapref)) {
17160: $$navmapref = Apache::lonnavmaps::navmap->new();
17161: }
17162: if (ref($$navmapref)) {
17163: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17164: }
17165: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17166: my $type=$2;
17167: my $path;
17168: if (ref($mapresobj)) {
17169: my $pcslist = $mapresobj->map_hierarchy();
17170: if ($pcslist ne '') {
17171: foreach my $pc (split(/,/,$pcslist)) {
17172: next if ($pc <= 1);
1.1267 raeburn 17173: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17174: if (ref($res)) {
17175: my $thisurl = $res->src();
17176: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17177: my $thistitle = $res->title();
17178: $path .= '&'.
17179: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17180: &escape($thistitle).
1.1101 raeburn 17181: ':'.$res->randompick().
17182: ':'.$res->randomout().
17183: ':'.$res->encrypted().
17184: ':'.$res->randomorder().
17185: ':'.$res->is_page();
17186: }
17187: }
17188: }
17189: $path =~ s/^\&//;
17190: my $maptitle = $mapresobj->title();
17191: if ($mapurl eq 'default') {
1.1129 raeburn 17192: $maptitle = 'Main Content';
1.1101 raeburn 17193: }
17194: $path .= (($path ne '')? '&' : '').
17195: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17196: &escape($maptitle).
1.1101 raeburn 17197: ':'.$mapresobj->randompick().
17198: ':'.$mapresobj->randomout().
17199: ':'.$mapresobj->encrypted().
17200: ':'.$mapresobj->randomorder().
17201: ':'.$mapresobj->is_page();
17202: } else {
17203: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17204: my $ispage = (($type eq 'page')? 1 : '');
17205: if ($mapurl eq 'default') {
1.1129 raeburn 17206: $maptitle = 'Main Content';
1.1101 raeburn 17207: }
17208: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17209: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17210: }
17211: unless ($mapurl eq 'default') {
17212: $path = 'default&'.
1.1146 raeburn 17213: &escape('Main Content').
1.1101 raeburn 17214: ':::::&'.$path;
17215: }
17216: return $path;
17217: }
17218:
1.1094 raeburn 17219: sub captcha_display {
17220: my ($context,$lonhost) = @_;
17221: my ($output,$error);
1.1234 raeburn 17222: my ($captcha,$pubkey,$privkey,$version) =
17223: &get_captcha_config($context,$lonhost);
1.1095 raeburn 17224: if ($captcha eq 'original') {
1.1094 raeburn 17225: $output = &create_captcha();
17226: unless ($output) {
1.1172 raeburn 17227: $error = 'captcha';
1.1094 raeburn 17228: }
17229: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17230: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17231: unless ($output) {
1.1172 raeburn 17232: $error = 'recaptcha';
1.1094 raeburn 17233: }
17234: }
1.1234 raeburn 17235: return ($output,$error,$captcha,$version);
1.1094 raeburn 17236: }
17237:
17238: sub captcha_response {
17239: my ($context,$lonhost) = @_;
17240: my ($captcha_chk,$captcha_error);
1.1234 raeburn 17241: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 17242: if ($captcha eq 'original') {
1.1094 raeburn 17243: ($captcha_chk,$captcha_error) = &check_captcha();
17244: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17245: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17246: } else {
17247: $captcha_chk = 1;
17248: }
17249: return ($captcha_chk,$captcha_error);
17250: }
17251:
17252: sub get_captcha_config {
17253: my ($context,$lonhost) = @_;
1.1234 raeburn 17254: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17255: my $hostname = &Apache::lonnet::hostname($lonhost);
17256: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17257: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17258: if ($context eq 'usercreation') {
17259: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17260: if (ref($domconfig{$context}) eq 'HASH') {
17261: $hashtocheck = $domconfig{$context}{'cancreate'};
17262: if (ref($hashtocheck) eq 'HASH') {
17263: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17264: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17265: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17266: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17267: }
17268: if ($privkey && $pubkey) {
17269: $captcha = 'recaptcha';
1.1234 raeburn 17270: $version = $hashtocheck->{'recaptchaversion'};
17271: if ($version ne '2') {
17272: $version = 1;
17273: }
1.1095 raeburn 17274: } else {
17275: $captcha = 'original';
17276: }
17277: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17278: $captcha = 'original';
17279: }
1.1094 raeburn 17280: }
1.1095 raeburn 17281: } else {
17282: $captcha = 'captcha';
17283: }
17284: } elsif ($context eq 'login') {
17285: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17286: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17287: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17288: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17289: if ($privkey && $pubkey) {
17290: $captcha = 'recaptcha';
1.1234 raeburn 17291: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17292: if ($version ne '2') {
17293: $version = 1;
17294: }
1.1095 raeburn 17295: } else {
17296: $captcha = 'original';
1.1094 raeburn 17297: }
1.1095 raeburn 17298: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17299: $captcha = 'original';
1.1094 raeburn 17300: }
17301: }
1.1234 raeburn 17302: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17303: }
17304:
17305: sub create_captcha {
17306: my %captcha_params = &captcha_settings();
17307: my ($output,$maxtries,$tries) = ('',10,0);
17308: while ($tries < $maxtries) {
17309: $tries ++;
17310: my $captcha = Authen::Captcha->new (
17311: output_folder => $captcha_params{'output_dir'},
17312: data_folder => $captcha_params{'db_dir'},
17313: );
17314: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17315:
17316: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17317: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17318: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17319: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17320: '<br />'.
17321: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17322: last;
17323: }
17324: }
17325: return $output;
17326: }
17327:
17328: sub captcha_settings {
17329: my %captcha_params = (
17330: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17331: www_output_dir => "/captchaspool",
17332: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17333: numchars => '5',
17334: );
17335: return %captcha_params;
17336: }
17337:
17338: sub check_captcha {
17339: my ($captcha_chk,$captcha_error);
17340: my $code = $env{'form.code'};
17341: my $md5sum = $env{'form.crypt'};
17342: my %captcha_params = &captcha_settings();
17343: my $captcha = Authen::Captcha->new(
17344: output_folder => $captcha_params{'output_dir'},
17345: data_folder => $captcha_params{'db_dir'},
17346: );
1.1109 raeburn 17347: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17348: my %captcha_hash = (
17349: 0 => 'Code not checked (file error)',
17350: -1 => 'Failed: code expired',
17351: -2 => 'Failed: invalid code (not in database)',
17352: -3 => 'Failed: invalid code (code does not match crypt)',
17353: );
17354: if ($captcha_chk != 1) {
17355: $captcha_error = $captcha_hash{$captcha_chk}
17356: }
17357: return ($captcha_chk,$captcha_error);
17358: }
17359:
17360: sub create_recaptcha {
1.1234 raeburn 17361: my ($pubkey,$version) = @_;
17362: if ($version >= 2) {
17363: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17364: } else {
17365: my $use_ssl;
17366: if ($ENV{'SERVER_PORT'} == 443) {
17367: $use_ssl = 1;
17368: }
17369: my $captcha = Captcha::reCAPTCHA->new;
17370: return $captcha->get_options_setter({theme => 'white'})."\n".
17371: $captcha->get_html($pubkey,undef,$use_ssl).
17372: &mt('If the text is hard to read, [_1] will replace them.',
17373: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17374: '<br /><br />';
17375: }
1.1094 raeburn 17376: }
17377:
17378: sub check_recaptcha {
1.1234 raeburn 17379: my ($privkey,$version) = @_;
1.1094 raeburn 17380: my $captcha_chk;
1.1234 raeburn 17381: if ($version >= 2) {
17382: my %info = (
17383: secret => $privkey,
17384: response => $env{'form.g-recaptcha-response'},
17385: remoteip => $ENV{'REMOTE_ADDR'},
17386: );
1.1280 raeburn 17387: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
17388: $request->content(join('&',map {
17389: my $name = escape($_);
17390: "$name=" . ( ref($info{$_}) eq 'ARRAY'
17391: ? join("&$name=", map {escape($_) } @{$info{$_}})
17392: : &escape($info{$_}) );
17393: } keys(%info)));
17394: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 17395: if ($response->is_success) {
17396: my $data = JSON::DWIW->from_json($response->decoded_content);
17397: if (ref($data) eq 'HASH') {
17398: if ($data->{'success'}) {
17399: $captcha_chk = 1;
17400: }
17401: }
17402: }
17403: } else {
17404: my $captcha = Captcha::reCAPTCHA->new;
17405: my $captcha_result =
17406: $captcha->check_answer(
17407: $privkey,
17408: $ENV{'REMOTE_ADDR'},
17409: $env{'form.recaptcha_challenge_field'},
17410: $env{'form.recaptcha_response_field'},
17411: );
17412: if ($captcha_result->{is_valid}) {
17413: $captcha_chk = 1;
17414: }
1.1094 raeburn 17415: }
17416: return $captcha_chk;
17417: }
17418:
1.1174 raeburn 17419: sub emailusername_info {
1.1244 raeburn 17420: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 17421: my %titles = &Apache::lonlocal::texthash (
17422: lastname => 'Last Name',
17423: firstname => 'First Name',
17424: institution => 'School/college/university',
17425: location => "School's city, state/province, country",
17426: web => "School's web address",
17427: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 17428: id => 'Student/Employee ID',
1.1174 raeburn 17429: );
17430: return (\@fields,\%titles);
17431: }
17432:
1.1161 raeburn 17433: sub cleanup_html {
17434: my ($incoming) = @_;
17435: my $outgoing;
17436: if ($incoming ne '') {
17437: $outgoing = $incoming;
17438: $outgoing =~ s/;/;/g;
17439: $outgoing =~ s/\#/#/g;
17440: $outgoing =~ s/\&/&/g;
17441: $outgoing =~ s/</</g;
17442: $outgoing =~ s/>/>/g;
17443: $outgoing =~ s/\(/(/g;
17444: $outgoing =~ s/\)/)/g;
17445: $outgoing =~ s/"/"/g;
17446: $outgoing =~ s/'/'/g;
17447: $outgoing =~ s/\$/$/g;
17448: $outgoing =~ s{/}{/}g;
17449: $outgoing =~ s/=/=/g;
17450: $outgoing =~ s/\\/\/g
17451: }
17452: return $outgoing;
17453: }
17454:
1.1190 musolffc 17455: # Checks for critical messages and returns a redirect url if one exists.
17456: # $interval indicates how often to check for messages.
1.1282 raeburn 17457: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 17458: sub critical_redirect {
1.1282 raeburn 17459: my ($interval,$context) = @_;
1.1190 musolffc 17460: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 17461: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
17462: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17463: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17464: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
17465: if ($blocked) {
17466: my $checkrole = "cm./$cdom/$cnum";
17467: if ($env{'request.course.sec'} ne '') {
17468: $checkrole .= "/$env{'request.course.sec'}";
17469: }
17470: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
17471: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
17472: return;
17473: }
17474: }
17475: }
1.1190 musolffc 17476: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17477: $env{'user.name'});
17478: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 17479: my $redirecturl;
1.1190 musolffc 17480: if ($what[0]) {
17481: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17482: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 17483: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17484: return (1, $url);
1.1190 musolffc 17485: }
1.1191 raeburn 17486: }
17487: }
17488: return ();
1.1190 musolffc 17489: }
17490:
1.1174 raeburn 17491: # Use:
17492: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17493: #
17494: ##################################################
17495: # password associated functions #
17496: ##################################################
17497: sub des_keys {
17498: # Make a new key for DES encryption.
17499: # Each key has two parts which are returned separately.
17500: # Please note: Each key must be passed through the &hex function
17501: # before it is output to the web browser. The hex versions cannot
17502: # be used to decrypt.
17503: my @hexstr=('0','1','2','3','4','5','6','7',
17504: '8','9','a','b','c','d','e','f');
17505: my $lkey='';
17506: for (0..7) {
17507: $lkey.=$hexstr[rand(15)];
17508: }
17509: my $ukey='';
17510: for (0..7) {
17511: $ukey.=$hexstr[rand(15)];
17512: }
17513: return ($lkey,$ukey);
17514: }
17515:
17516: sub des_decrypt {
17517: my ($key,$cyphertext) = @_;
17518: my $keybin=pack("H16",$key);
17519: my $cypher;
17520: if ($Crypt::DES::VERSION>=2.03) {
17521: $cypher=new Crypt::DES $keybin;
17522: } else {
17523: $cypher=new DES $keybin;
17524: }
1.1233 raeburn 17525: my $plaintext='';
17526: my $cypherlength = length($cyphertext);
17527: my $numchunks = int($cypherlength/32);
17528: for (my $j=0; $j<$numchunks; $j++) {
17529: my $start = $j*32;
17530: my $cypherblock = substr($cyphertext,$start,32);
17531: my $chunk =
17532: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17533: $chunk .=
17534: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17535: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17536: $plaintext .= $chunk;
17537: }
1.1174 raeburn 17538: return $plaintext;
17539: }
17540:
1.112 bowersj2 17541: 1;
17542: __END__;
1.41 ng 17543:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>