Annotation of loncom/interface/loncommon.pm, revision 1.1282
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1282 ! raeburn 4: # $Id: loncommon.pm,v 1.1281 2017/06/26 01:34:32 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.502 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.396 albertel 6776: table.LC_parm_overview_restrictions td {
6777: border-width: 1px 4px 1px 4px;
6778: border-style: solid;
6779: border-color: $pgbg;
6780: text-align: center;
6781: }
1.795 www 6782:
1.396 albertel 6783: table.LC_parm_overview_restrictions th {
6784: background: $tabbg;
6785: border-width: 1px 4px 1px 4px;
6786: border-style: solid;
6787: border-color: $pgbg;
6788: }
1.795 www 6789:
1.398 albertel 6790: table#LC_helpmenu {
1.803 bisitz 6791: border: none;
1.398 albertel 6792: height: 55px;
1.803 bisitz 6793: border-spacing: 0;
1.398 albertel 6794: }
6795:
6796: table#LC_helpmenu fieldset legend {
6797: font-size: larger;
6798: }
1.795 www 6799:
1.397 albertel 6800: table#LC_helpmenu_links {
6801: width: 100%;
6802: border: 1px solid black;
6803: background: $pgbg;
1.803 bisitz 6804: padding: 0;
1.397 albertel 6805: border-spacing: 1px;
6806: }
1.795 www 6807:
1.397 albertel 6808: table#LC_helpmenu_links tr td {
6809: padding: 1px;
6810: background: $tabbg;
1.399 albertel 6811: text-align: center;
6812: font-weight: bold;
1.397 albertel 6813: }
1.396 albertel 6814:
1.795 www 6815: table#LC_helpmenu_links a:link,
6816: table#LC_helpmenu_links a:visited,
1.397 albertel 6817: table#LC_helpmenu_links a:active {
6818: text-decoration: none;
6819: color: $font;
6820: }
1.795 www 6821:
1.397 albertel 6822: table#LC_helpmenu_links a:hover {
6823: text-decoration: underline;
6824: color: $vlink;
6825: }
1.396 albertel 6826:
1.417 albertel 6827: .LC_chrt_popup_exists {
6828: border: 1px solid #339933;
6829: margin: -1px;
6830: }
1.795 www 6831:
1.417 albertel 6832: .LC_chrt_popup_up {
6833: border: 1px solid yellow;
6834: margin: -1px;
6835: }
1.795 www 6836:
1.417 albertel 6837: .LC_chrt_popup {
6838: border: 1px solid #8888FF;
6839: background: #CCCCFF;
6840: }
1.795 www 6841:
1.421 albertel 6842: table.LC_pick_box {
6843: border-collapse: separate;
6844: background: white;
6845: border: 1px solid black;
6846: border-spacing: 1px;
6847: }
1.795 www 6848:
1.421 albertel 6849: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6850: background: $sidebg;
1.421 albertel 6851: font-weight: bold;
1.900 bisitz 6852: text-align: left;
1.740 bisitz 6853: vertical-align: top;
1.421 albertel 6854: width: 184px;
6855: padding: 8px;
6856: }
1.795 www 6857:
1.579 raeburn 6858: table.LC_pick_box td.LC_pick_box_value {
6859: text-align: left;
6860: padding: 8px;
6861: }
1.795 www 6862:
1.579 raeburn 6863: table.LC_pick_box td.LC_pick_box_select {
6864: text-align: left;
6865: padding: 8px;
6866: }
1.795 www 6867:
1.424 albertel 6868: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6869: padding: 0;
1.421 albertel 6870: height: 1px;
6871: background: black;
6872: }
1.795 www 6873:
1.421 albertel 6874: table.LC_pick_box td.LC_pick_box_submit {
6875: text-align: right;
6876: }
1.795 www 6877:
1.579 raeburn 6878: table.LC_pick_box td.LC_evenrow_value {
6879: text-align: left;
6880: padding: 8px;
6881: background-color: $data_table_light;
6882: }
1.795 www 6883:
1.579 raeburn 6884: table.LC_pick_box td.LC_oddrow_value {
6885: text-align: left;
6886: padding: 8px;
6887: background-color: $data_table_light;
6888: }
1.795 www 6889:
1.579 raeburn 6890: span.LC_helpform_receipt_cat {
6891: font-weight: bold;
6892: }
1.795 www 6893:
1.424 albertel 6894: table.LC_group_priv_box {
6895: background: white;
6896: border: 1px solid black;
6897: border-spacing: 1px;
6898: }
1.795 www 6899:
1.424 albertel 6900: table.LC_group_priv_box td.LC_pick_box_title {
6901: background: $tabbg;
6902: font-weight: bold;
6903: text-align: right;
6904: width: 184px;
6905: }
1.795 www 6906:
1.424 albertel 6907: table.LC_group_priv_box td.LC_groups_fixed {
6908: background: $data_table_light;
6909: text-align: center;
6910: }
1.795 www 6911:
1.424 albertel 6912: table.LC_group_priv_box td.LC_groups_optional {
6913: background: $data_table_dark;
6914: text-align: center;
6915: }
1.795 www 6916:
1.424 albertel 6917: table.LC_group_priv_box td.LC_groups_functionality {
6918: background: $data_table_darker;
6919: text-align: center;
6920: font-weight: bold;
6921: }
1.795 www 6922:
1.424 albertel 6923: table.LC_group_priv td {
6924: text-align: left;
1.803 bisitz 6925: padding: 0;
1.424 albertel 6926: }
6927:
6928: .LC_navbuttons {
6929: margin: 2ex 0ex 2ex 0ex;
6930: }
1.795 www 6931:
1.423 albertel 6932: .LC_topic_bar {
6933: font-weight: bold;
6934: background: $tabbg;
1.918 wenzelju 6935: margin: 1em 0em 1em 2em;
1.805 bisitz 6936: padding: 3px;
1.918 wenzelju 6937: font-size: 1.2em;
1.423 albertel 6938: }
1.795 www 6939:
1.423 albertel 6940: .LC_topic_bar span {
1.918 wenzelju 6941: left: 0.5em;
6942: position: absolute;
1.423 albertel 6943: vertical-align: middle;
1.918 wenzelju 6944: font-size: 1.2em;
1.423 albertel 6945: }
1.795 www 6946:
1.423 albertel 6947: table.LC_course_group_status {
6948: margin: 20px;
6949: }
1.795 www 6950:
1.423 albertel 6951: table.LC_status_selector td {
6952: vertical-align: top;
6953: text-align: center;
1.424 albertel 6954: padding: 4px;
6955: }
1.795 www 6956:
1.599 albertel 6957: div.LC_feedback_link {
1.616 albertel 6958: clear: both;
1.829 kalberla 6959: background: $sidebg;
1.779 bisitz 6960: width: 100%;
1.829 kalberla 6961: padding-bottom: 10px;
6962: border: 1px $tabbg solid;
1.833 kalberla 6963: height: 22px;
6964: line-height: 22px;
6965: padding-top: 5px;
6966: }
6967:
6968: div.LC_feedback_link img {
6969: height: 22px;
1.867 kalberla 6970: vertical-align:middle;
1.829 kalberla 6971: }
6972:
1.911 bisitz 6973: div.LC_feedback_link a {
1.829 kalberla 6974: text-decoration: none;
1.489 raeburn 6975: }
1.795 www 6976:
1.867 kalberla 6977: div.LC_comblock {
1.911 bisitz 6978: display:inline;
1.867 kalberla 6979: color:$font;
6980: font-size:90%;
6981: }
6982:
6983: div.LC_feedback_link div.LC_comblock {
6984: padding-left:5px;
6985: }
6986:
6987: div.LC_feedback_link div.LC_comblock a {
6988: color:$font;
6989: }
6990:
1.489 raeburn 6991: span.LC_feedback_link {
1.858 bisitz 6992: /* background: $feedback_link_bg; */
1.599 albertel 6993: font-size: larger;
6994: }
1.795 www 6995:
1.599 albertel 6996: span.LC_message_link {
1.858 bisitz 6997: /* background: $feedback_link_bg; */
1.599 albertel 6998: font-size: larger;
6999: position: absolute;
7000: right: 1em;
1.489 raeburn 7001: }
1.421 albertel 7002:
1.515 albertel 7003: table.LC_prior_tries {
1.524 albertel 7004: border: 1px solid #000000;
7005: border-collapse: separate;
7006: border-spacing: 1px;
1.515 albertel 7007: }
1.523 albertel 7008:
1.515 albertel 7009: table.LC_prior_tries td {
1.524 albertel 7010: padding: 2px;
1.515 albertel 7011: }
1.523 albertel 7012:
7013: .LC_answer_correct {
1.795 www 7014: background: lightgreen;
7015: color: darkgreen;
7016: padding: 6px;
1.523 albertel 7017: }
1.795 www 7018:
1.523 albertel 7019: .LC_answer_charged_try {
1.797 www 7020: background: #FFAAAA;
1.795 www 7021: color: darkred;
7022: padding: 6px;
1.523 albertel 7023: }
1.795 www 7024:
1.779 bisitz 7025: .LC_answer_not_charged_try,
1.523 albertel 7026: .LC_answer_no_grade,
7027: .LC_answer_late {
1.795 www 7028: background: lightyellow;
1.523 albertel 7029: color: black;
1.795 www 7030: padding: 6px;
1.523 albertel 7031: }
1.795 www 7032:
1.523 albertel 7033: .LC_answer_previous {
1.795 www 7034: background: lightblue;
7035: color: darkblue;
7036: padding: 6px;
1.523 albertel 7037: }
1.795 www 7038:
1.779 bisitz 7039: .LC_answer_no_message {
1.777 tempelho 7040: background: #FFFFFF;
7041: color: black;
1.795 www 7042: padding: 6px;
1.779 bisitz 7043: }
1.795 www 7044:
1.779 bisitz 7045: .LC_answer_unknown {
7046: background: orange;
7047: color: black;
1.795 www 7048: padding: 6px;
1.777 tempelho 7049: }
1.795 www 7050:
1.529 albertel 7051: span.LC_prior_numerical,
7052: span.LC_prior_string,
7053: span.LC_prior_custom,
7054: span.LC_prior_reaction,
7055: span.LC_prior_math {
1.925 bisitz 7056: font-family: $mono;
1.523 albertel 7057: white-space: pre;
7058: }
7059:
1.525 albertel 7060: span.LC_prior_string {
1.925 bisitz 7061: font-family: $mono;
1.525 albertel 7062: white-space: pre;
7063: }
7064:
1.523 albertel 7065: table.LC_prior_option {
7066: width: 100%;
7067: border-collapse: collapse;
7068: }
1.795 www 7069:
1.911 bisitz 7070: table.LC_prior_rank,
1.795 www 7071: table.LC_prior_match {
1.528 albertel 7072: border-collapse: collapse;
7073: }
1.795 www 7074:
1.528 albertel 7075: table.LC_prior_option tr td,
7076: table.LC_prior_rank tr td,
7077: table.LC_prior_match tr td {
1.524 albertel 7078: border: 1px solid #000000;
1.515 albertel 7079: }
7080:
1.855 bisitz 7081: .LC_nobreak {
1.544 albertel 7082: white-space: nowrap;
1.519 raeburn 7083: }
7084:
1.576 raeburn 7085: span.LC_cusr_emph {
7086: font-style: italic;
7087: }
7088:
1.633 raeburn 7089: span.LC_cusr_subheading {
7090: font-weight: normal;
7091: font-size: 85%;
7092: }
7093:
1.861 bisitz 7094: div.LC_docs_entry_move {
1.859 bisitz 7095: border: 1px solid #BBBBBB;
1.545 albertel 7096: background: #DDDDDD;
1.861 bisitz 7097: width: 22px;
1.859 bisitz 7098: padding: 1px;
7099: margin: 0;
1.545 albertel 7100: }
7101:
1.861 bisitz 7102: table.LC_data_table tr > td.LC_docs_entry_commands,
7103: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7104: font-size: x-small;
7105: }
1.795 www 7106:
1.861 bisitz 7107: .LC_docs_entry_parameter {
7108: white-space: nowrap;
7109: }
7110:
1.544 albertel 7111: .LC_docs_copy {
1.545 albertel 7112: color: #000099;
1.544 albertel 7113: }
1.795 www 7114:
1.544 albertel 7115: .LC_docs_cut {
1.545 albertel 7116: color: #550044;
1.544 albertel 7117: }
1.795 www 7118:
1.544 albertel 7119: .LC_docs_rename {
1.545 albertel 7120: color: #009900;
1.544 albertel 7121: }
1.795 www 7122:
1.544 albertel 7123: .LC_docs_remove {
1.545 albertel 7124: color: #990000;
7125: }
7126:
1.547 albertel 7127: .LC_docs_reinit_warn,
7128: .LC_docs_ext_edit {
7129: font-size: x-small;
7130: }
7131:
1.545 albertel 7132: table.LC_docs_adddocs td,
7133: table.LC_docs_adddocs th {
7134: border: 1px solid #BBBBBB;
7135: padding: 4px;
7136: background: #DDDDDD;
1.543 albertel 7137: }
7138:
1.584 albertel 7139: table.LC_sty_begin {
7140: background: #BBFFBB;
7141: }
1.795 www 7142:
1.584 albertel 7143: table.LC_sty_end {
7144: background: #FFBBBB;
7145: }
7146:
1.589 raeburn 7147: table.LC_double_column {
1.803 bisitz 7148: border-width: 0;
1.589 raeburn 7149: border-collapse: collapse;
7150: width: 100%;
7151: padding: 2px;
7152: }
7153:
7154: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7155: top: 2px;
1.589 raeburn 7156: left: 2px;
7157: width: 47%;
7158: vertical-align: top;
7159: }
7160:
7161: table.LC_double_column tr td.LC_right_col {
7162: top: 2px;
1.779 bisitz 7163: right: 2px;
1.589 raeburn 7164: width: 47%;
7165: vertical-align: top;
7166: }
7167:
1.591 raeburn 7168: div.LC_left_float {
7169: float: left;
7170: padding-right: 5%;
1.597 albertel 7171: padding-bottom: 4px;
1.591 raeburn 7172: }
7173:
7174: div.LC_clear_float_header {
1.597 albertel 7175: padding-bottom: 2px;
1.591 raeburn 7176: }
7177:
7178: div.LC_clear_float_footer {
1.597 albertel 7179: padding-top: 10px;
1.591 raeburn 7180: clear: both;
7181: }
7182:
1.597 albertel 7183: div.LC_grade_show_user {
1.941 bisitz 7184: /* border-left: 5px solid $sidebg; */
7185: border-top: 5px solid #000000;
7186: margin: 50px 0 0 0;
1.936 bisitz 7187: padding: 15px 0 5px 10px;
1.597 albertel 7188: }
1.795 www 7189:
1.936 bisitz 7190: div.LC_grade_show_user_odd_row {
1.941 bisitz 7191: /* border-left: 5px solid #000000; */
7192: }
7193:
7194: div.LC_grade_show_user div.LC_Box {
7195: margin-right: 50px;
1.597 albertel 7196: }
7197:
7198: div.LC_grade_submissions,
7199: div.LC_grade_message_center,
1.936 bisitz 7200: div.LC_grade_info_links {
1.597 albertel 7201: margin: 5px;
7202: width: 99%;
7203: background: #FFFFFF;
7204: }
1.795 www 7205:
1.597 albertel 7206: div.LC_grade_submissions_header,
1.936 bisitz 7207: div.LC_grade_message_center_header {
1.705 tempelho 7208: font-weight: bold;
7209: font-size: large;
1.597 albertel 7210: }
1.795 www 7211:
1.597 albertel 7212: div.LC_grade_submissions_body,
1.936 bisitz 7213: div.LC_grade_message_center_body {
1.597 albertel 7214: border: 1px solid black;
7215: width: 99%;
7216: background: #FFFFFF;
7217: }
1.795 www 7218:
1.613 albertel 7219: table.LC_scantron_action {
7220: width: 100%;
7221: }
1.795 www 7222:
1.613 albertel 7223: table.LC_scantron_action tr th {
1.698 harmsja 7224: font-weight:bold;
7225: font-style:normal;
1.613 albertel 7226: }
1.795 www 7227:
1.779 bisitz 7228: .LC_edit_problem_header,
1.614 albertel 7229: div.LC_edit_problem_footer {
1.705 tempelho 7230: font-weight: normal;
7231: font-size: medium;
1.602 albertel 7232: margin: 2px;
1.1060 bisitz 7233: background-color: $sidebg;
1.600 albertel 7234: }
1.795 www 7235:
1.600 albertel 7236: div.LC_edit_problem_header,
1.602 albertel 7237: div.LC_edit_problem_header div,
1.614 albertel 7238: div.LC_edit_problem_footer,
7239: div.LC_edit_problem_footer div,
1.602 albertel 7240: div.LC_edit_problem_editxml_header,
7241: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7242: z-index: 100;
1.600 albertel 7243: }
1.795 www 7244:
1.600 albertel 7245: div.LC_edit_problem_header_title {
1.705 tempelho 7246: font-weight: bold;
7247: font-size: larger;
1.602 albertel 7248: background: $tabbg;
7249: padding: 3px;
1.1060 bisitz 7250: margin: 0 0 5px 0;
1.602 albertel 7251: }
1.795 www 7252:
1.602 albertel 7253: table.LC_edit_problem_header_title {
7254: width: 100%;
1.600 albertel 7255: background: $tabbg;
1.602 albertel 7256: }
7257:
1.1205 golterma 7258: div.LC_edit_actionbar {
7259: background-color: $sidebg;
1.1218 droeschl 7260: margin: 0;
7261: padding: 0;
7262: line-height: 200%;
1.602 albertel 7263: }
1.795 www 7264:
1.1218 droeschl 7265: div.LC_edit_actionbar div{
7266: padding: 0;
7267: margin: 0;
7268: display: inline-block;
1.600 albertel 7269: }
1.795 www 7270:
1.1124 bisitz 7271: .LC_edit_opt {
7272: padding-left: 1em;
7273: white-space: nowrap;
7274: }
7275:
1.1152 golterma 7276: .LC_edit_problem_latexhelper{
7277: text-align: right;
7278: }
7279:
7280: #LC_edit_problem_colorful div{
7281: margin-left: 40px;
7282: }
7283:
1.1205 golterma 7284: #LC_edit_problem_codemirror div{
7285: margin-left: 0px;
7286: }
7287:
1.911 bisitz 7288: img.stift {
1.803 bisitz 7289: border-width: 0;
7290: vertical-align: middle;
1.677 riegler 7291: }
1.680 riegler 7292:
1.923 bisitz 7293: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7294: vertical-align: top;
1.777 tempelho 7295: }
1.795 www 7296:
1.716 raeburn 7297: div.LC_createcourse {
1.911 bisitz 7298: margin: 10px 10px 10px 10px;
1.716 raeburn 7299: }
7300:
1.917 raeburn 7301: .LC_dccid {
1.1130 raeburn 7302: float: right;
1.917 raeburn 7303: margin: 0.2em 0 0 0;
7304: padding: 0;
7305: font-size: 90%;
7306: display:none;
7307: }
7308:
1.897 wenzelju 7309: ol.LC_primary_menu a:hover,
1.721 harmsja 7310: ol#LC_MenuBreadcrumbs a:hover,
7311: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7312: ul#LC_secondary_menu a:hover,
1.721 harmsja 7313: .LC_FormSectionClearButton input:hover
1.795 www 7314: ul.LC_TabContent li:hover a {
1.952 onken 7315: color:$button_hover;
1.911 bisitz 7316: text-decoration:none;
1.693 droeschl 7317: }
7318:
1.779 bisitz 7319: h1 {
1.911 bisitz 7320: padding: 0;
7321: line-height:130%;
1.693 droeschl 7322: }
1.698 harmsja 7323:
1.911 bisitz 7324: h2,
7325: h3,
7326: h4,
7327: h5,
7328: h6 {
7329: margin: 5px 0 5px 0;
7330: padding: 0;
7331: line-height:130%;
1.693 droeschl 7332: }
1.795 www 7333:
7334: .LC_hcell {
1.911 bisitz 7335: padding:3px 15px 3px 15px;
7336: margin: 0;
7337: background-color:$tabbg;
7338: color:$fontmenu;
7339: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7340: }
1.795 www 7341:
1.840 bisitz 7342: .LC_Box > .LC_hcell {
1.911 bisitz 7343: margin: 0 -10px 10px -10px;
1.835 bisitz 7344: }
7345:
1.721 harmsja 7346: .LC_noBorder {
1.911 bisitz 7347: border: 0;
1.698 harmsja 7348: }
1.693 droeschl 7349:
1.721 harmsja 7350: .LC_FormSectionClearButton input {
1.911 bisitz 7351: background-color:transparent;
7352: border: none;
7353: cursor:pointer;
7354: text-decoration:underline;
1.693 droeschl 7355: }
1.763 bisitz 7356:
7357: .LC_help_open_topic {
1.911 bisitz 7358: color: #FFFFFF;
7359: background-color: #EEEEFF;
7360: margin: 1px;
7361: padding: 4px;
7362: border: 1px solid #000033;
7363: white-space: nowrap;
7364: /* vertical-align: middle; */
1.759 neumanie 7365: }
1.693 droeschl 7366:
1.911 bisitz 7367: dl,
7368: ul,
7369: div,
7370: fieldset {
7371: margin: 10px 10px 10px 0;
7372: /* overflow: hidden; */
1.693 droeschl 7373: }
1.795 www 7374:
1.1211 raeburn 7375: article.geogebraweb div {
7376: margin: 0;
7377: }
7378:
1.838 bisitz 7379: fieldset > legend {
1.911 bisitz 7380: font-weight: bold;
7381: padding: 0 5px 0 5px;
1.838 bisitz 7382: }
7383:
1.813 bisitz 7384: #LC_nav_bar {
1.911 bisitz 7385: float: left;
1.995 raeburn 7386: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7387: margin: 0 0 2px 0;
1.807 droeschl 7388: }
7389:
1.916 droeschl 7390: #LC_realm {
7391: margin: 0.2em 0 0 0;
7392: padding: 0;
7393: font-weight: bold;
7394: text-align: center;
1.995 raeburn 7395: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7396: }
7397:
1.911 bisitz 7398: #LC_nav_bar em {
7399: font-weight: bold;
7400: font-style: normal;
1.807 droeschl 7401: }
7402:
1.897 wenzelju 7403: ol.LC_primary_menu {
1.934 droeschl 7404: margin: 0;
1.1076 raeburn 7405: padding: 0;
1.807 droeschl 7406: }
7407:
1.852 droeschl 7408: ol#LC_PathBreadcrumbs {
1.911 bisitz 7409: margin: 0;
1.693 droeschl 7410: }
7411:
1.897 wenzelju 7412: ol.LC_primary_menu li {
1.1076 raeburn 7413: color: RGB(80, 80, 80);
7414: vertical-align: middle;
7415: text-align: left;
7416: list-style: none;
1.1205 golterma 7417: position: relative;
1.1076 raeburn 7418: float: left;
1.1205 golterma 7419: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7420: line-height: 1.5em;
1.1076 raeburn 7421: }
7422:
1.1205 golterma 7423: ol.LC_primary_menu li a,
7424: ol.LC_primary_menu li p {
1.1076 raeburn 7425: display: block;
7426: margin: 0;
7427: padding: 0 5px 0 10px;
7428: text-decoration: none;
7429: }
7430:
1.1205 golterma 7431: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7432: display: inline-block;
7433: width: 95%;
7434: text-align: left;
7435: }
7436:
7437: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7438: display: inline-block;
7439: width: 5%;
7440: float: right;
7441: text-align: right;
7442: font-size: 70%;
7443: }
7444:
7445: ol.LC_primary_menu ul {
1.1076 raeburn 7446: display: none;
1.1205 golterma 7447: width: 15em;
1.1076 raeburn 7448: background-color: $data_table_light;
1.1205 golterma 7449: position: absolute;
7450: top: 100%;
1.1076 raeburn 7451: }
7452:
1.1205 golterma 7453: ol.LC_primary_menu ul ul {
7454: left: 100%;
7455: top: 0;
7456: }
7457:
7458: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7459: display: block;
7460: position: absolute;
7461: margin: 0;
7462: padding: 0;
1.1078 raeburn 7463: z-index: 2;
1.1076 raeburn 7464: }
7465:
7466: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7467: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7468: font-size: 90%;
1.911 bisitz 7469: vertical-align: top;
1.1076 raeburn 7470: float: none;
1.1079 raeburn 7471: border-left: 1px solid black;
7472: border-right: 1px solid black;
1.1205 golterma 7473: /* A dark bottom border to visualize different menu options;
7474: overwritten in the create_submenu routine for the last border-bottom of the menu */
7475: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7476: }
7477:
1.1205 golterma 7478: ol.LC_primary_menu li li p:hover {
7479: color:$button_hover;
7480: text-decoration:none;
7481: background-color:$data_table_dark;
1.1076 raeburn 7482: }
7483:
7484: ol.LC_primary_menu li li a:hover {
7485: color:$button_hover;
7486: background-color:$data_table_dark;
1.693 droeschl 7487: }
7488:
1.1205 golterma 7489: /* Font-size equal to the size of the predecessors*/
7490: ol.LC_primary_menu li:hover li li {
7491: font-size: 100%;
7492: }
7493:
1.897 wenzelju 7494: ol.LC_primary_menu li img {
1.911 bisitz 7495: vertical-align: bottom;
1.934 droeschl 7496: height: 1.1em;
1.1077 raeburn 7497: margin: 0.2em 0 0 0;
1.693 droeschl 7498: }
7499:
1.897 wenzelju 7500: ol.LC_primary_menu a {
1.911 bisitz 7501: color: RGB(80, 80, 80);
7502: text-decoration: none;
1.693 droeschl 7503: }
1.795 www 7504:
1.949 droeschl 7505: ol.LC_primary_menu a.LC_new_message {
7506: font-weight:bold;
7507: color: darkred;
7508: }
7509:
1.975 raeburn 7510: ol.LC_docs_parameters {
7511: margin-left: 0;
7512: padding: 0;
7513: list-style: none;
7514: }
7515:
7516: ol.LC_docs_parameters li {
7517: margin: 0;
7518: padding-right: 20px;
7519: display: inline;
7520: }
7521:
1.976 raeburn 7522: ol.LC_docs_parameters li:before {
7523: content: "\\002022 \\0020";
7524: }
7525:
7526: li.LC_docs_parameters_title {
7527: font-weight: bold;
7528: }
7529:
7530: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7531: content: "";
7532: }
7533:
1.897 wenzelju 7534: ul#LC_secondary_menu {
1.1107 raeburn 7535: clear: right;
1.911 bisitz 7536: color: $fontmenu;
7537: background: $tabbg;
7538: list-style: none;
7539: padding: 0;
7540: margin: 0;
7541: width: 100%;
1.995 raeburn 7542: text-align: left;
1.1107 raeburn 7543: float: left;
1.808 droeschl 7544: }
7545:
1.897 wenzelju 7546: ul#LC_secondary_menu li {
1.911 bisitz 7547: font-weight: bold;
7548: line-height: 1.8em;
1.1107 raeburn 7549: border-right: 1px solid black;
7550: float: left;
7551: }
7552:
7553: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7554: background-color: $data_table_light;
7555: }
7556:
7557: ul#LC_secondary_menu li a {
1.911 bisitz 7558: padding: 0 0.8em;
1.1107 raeburn 7559: }
7560:
7561: ul#LC_secondary_menu li ul {
7562: display: none;
7563: }
7564:
7565: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7566: display: block;
7567: position: absolute;
7568: margin: 0;
7569: padding: 0;
7570: list-style:none;
7571: float: none;
7572: background-color: $data_table_light;
7573: z-index: 2;
7574: margin-left: -1px;
7575: }
7576:
7577: ul#LC_secondary_menu li ul li {
7578: font-size: 90%;
7579: vertical-align: top;
7580: border-left: 1px solid black;
1.911 bisitz 7581: border-right: 1px solid black;
1.1119 raeburn 7582: background-color: $data_table_light;
1.1107 raeburn 7583: list-style:none;
7584: float: none;
7585: }
7586:
7587: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7588: background-color: $data_table_dark;
1.807 droeschl 7589: }
7590:
1.847 tempelho 7591: ul.LC_TabContent {
1.911 bisitz 7592: display:block;
7593: background: $sidebg;
7594: border-bottom: solid 1px $lg_border_color;
7595: list-style:none;
1.1020 raeburn 7596: margin: -1px -10px 0 -10px;
1.911 bisitz 7597: padding: 0;
1.693 droeschl 7598: }
7599:
1.795 www 7600: ul.LC_TabContent li,
7601: ul.LC_TabContentBigger li {
1.911 bisitz 7602: float:left;
1.741 harmsja 7603: }
1.795 www 7604:
1.897 wenzelju 7605: ul#LC_secondary_menu li a {
1.911 bisitz 7606: color: $fontmenu;
7607: text-decoration: none;
1.693 droeschl 7608: }
1.795 www 7609:
1.721 harmsja 7610: ul.LC_TabContent {
1.952 onken 7611: min-height:20px;
1.721 harmsja 7612: }
1.795 www 7613:
7614: ul.LC_TabContent li {
1.911 bisitz 7615: vertical-align:middle;
1.959 onken 7616: padding: 0 16px 0 10px;
1.911 bisitz 7617: background-color:$tabbg;
7618: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7619: border-left: solid 1px $font;
1.721 harmsja 7620: }
1.795 www 7621:
1.847 tempelho 7622: ul.LC_TabContent .right {
1.911 bisitz 7623: float:right;
1.847 tempelho 7624: }
7625:
1.911 bisitz 7626: ul.LC_TabContent li a,
7627: ul.LC_TabContent li {
7628: color:rgb(47,47,47);
7629: text-decoration:none;
7630: font-size:95%;
7631: font-weight:bold;
1.952 onken 7632: min-height:20px;
7633: }
7634:
1.959 onken 7635: ul.LC_TabContent li a:hover,
7636: ul.LC_TabContent li a:focus {
1.952 onken 7637: color: $button_hover;
1.959 onken 7638: background:none;
7639: outline:none;
1.952 onken 7640: }
7641:
7642: ul.LC_TabContent li:hover {
7643: color: $button_hover;
7644: cursor:pointer;
1.721 harmsja 7645: }
1.795 www 7646:
1.911 bisitz 7647: ul.LC_TabContent li.active {
1.952 onken 7648: color: $font;
1.911 bisitz 7649: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7650: border-bottom:solid 1px #FFFFFF;
7651: cursor: default;
1.744 ehlerst 7652: }
1.795 www 7653:
1.959 onken 7654: ul.LC_TabContent li.active a {
7655: color:$font;
7656: background:#FFFFFF;
7657: outline: none;
7658: }
1.1047 raeburn 7659:
7660: ul.LC_TabContent li.goback {
7661: float: left;
7662: border-left: none;
7663: }
7664:
1.870 tempelho 7665: #maincoursedoc {
1.911 bisitz 7666: clear:both;
1.870 tempelho 7667: }
7668:
7669: ul.LC_TabContentBigger {
1.911 bisitz 7670: display:block;
7671: list-style:none;
7672: padding: 0;
1.870 tempelho 7673: }
7674:
1.795 www 7675: ul.LC_TabContentBigger li {
1.911 bisitz 7676: vertical-align:bottom;
7677: height: 30px;
7678: font-size:110%;
7679: font-weight:bold;
7680: color: #737373;
1.841 tempelho 7681: }
7682:
1.957 onken 7683: ul.LC_TabContentBigger li.active {
7684: position: relative;
7685: top: 1px;
7686: }
7687:
1.870 tempelho 7688: ul.LC_TabContentBigger li a {
1.911 bisitz 7689: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7690: height: 30px;
7691: line-height: 30px;
7692: text-align: center;
7693: display: block;
7694: text-decoration: none;
1.958 onken 7695: outline: none;
1.741 harmsja 7696: }
1.795 www 7697:
1.870 tempelho 7698: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7699: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7700: color:$font;
1.744 ehlerst 7701: }
1.795 www 7702:
1.870 tempelho 7703: ul.LC_TabContentBigger li b {
1.911 bisitz 7704: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7705: display: block;
7706: float: left;
7707: padding: 0 30px;
1.957 onken 7708: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7709: }
7710:
1.956 onken 7711: ul.LC_TabContentBigger li:hover b {
7712: color:$button_hover;
7713: }
7714:
1.870 tempelho 7715: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7716: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7717: color:$font;
1.957 onken 7718: border: 0;
1.741 harmsja 7719: }
1.693 droeschl 7720:
1.870 tempelho 7721:
1.862 bisitz 7722: ul.LC_CourseBreadcrumbs {
7723: background: $sidebg;
1.1020 raeburn 7724: height: 2em;
1.862 bisitz 7725: padding-left: 10px;
1.1020 raeburn 7726: margin: 0;
1.862 bisitz 7727: list-style-position: inside;
7728: }
7729:
1.911 bisitz 7730: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7731: ol#LC_PathBreadcrumbs {
1.911 bisitz 7732: padding-left: 10px;
7733: margin: 0;
1.933 droeschl 7734: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7735: }
7736:
1.911 bisitz 7737: ol#LC_MenuBreadcrumbs li,
7738: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7739: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7740: display: inline;
1.933 droeschl 7741: white-space: normal;
1.693 droeschl 7742: }
7743:
1.823 bisitz 7744: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7745: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7746: text-decoration: none;
7747: font-size:90%;
1.693 droeschl 7748: }
1.795 www 7749:
1.969 droeschl 7750: ol#LC_MenuBreadcrumbs h1 {
7751: display: inline;
7752: font-size: 90%;
7753: line-height: 2.5em;
7754: margin: 0;
7755: padding: 0;
7756: }
7757:
1.795 www 7758: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7759: text-decoration:none;
7760: font-size:100%;
7761: font-weight:bold;
1.693 droeschl 7762: }
1.795 www 7763:
1.840 bisitz 7764: .LC_Box {
1.911 bisitz 7765: border: solid 1px $lg_border_color;
7766: padding: 0 10px 10px 10px;
1.746 neumanie 7767: }
1.795 www 7768:
1.1020 raeburn 7769: .LC_DocsBox {
7770: border: solid 1px $lg_border_color;
7771: padding: 0 0 10px 10px;
7772: }
7773:
1.795 www 7774: .LC_AboutMe_Image {
1.911 bisitz 7775: float:left;
7776: margin-right:10px;
1.747 neumanie 7777: }
1.795 www 7778:
7779: .LC_Clear_AboutMe_Image {
1.911 bisitz 7780: clear:left;
1.747 neumanie 7781: }
1.795 www 7782:
1.721 harmsja 7783: dl.LC_ListStyleClean dt {
1.911 bisitz 7784: padding-right: 5px;
7785: display: table-header-group;
1.693 droeschl 7786: }
7787:
1.721 harmsja 7788: dl.LC_ListStyleClean dd {
1.911 bisitz 7789: display: table-row;
1.693 droeschl 7790: }
7791:
1.721 harmsja 7792: .LC_ListStyleClean,
7793: .LC_ListStyleSimple,
7794: .LC_ListStyleNormal,
1.795 www 7795: .LC_ListStyleSpecial {
1.911 bisitz 7796: /* display:block; */
7797: list-style-position: inside;
7798: list-style-type: none;
7799: overflow: hidden;
7800: padding: 0;
1.693 droeschl 7801: }
7802:
1.721 harmsja 7803: .LC_ListStyleSimple li,
7804: .LC_ListStyleSimple dd,
7805: .LC_ListStyleNormal li,
7806: .LC_ListStyleNormal dd,
7807: .LC_ListStyleSpecial li,
1.795 www 7808: .LC_ListStyleSpecial dd {
1.911 bisitz 7809: margin: 0;
7810: padding: 5px 5px 5px 10px;
7811: clear: both;
1.693 droeschl 7812: }
7813:
1.721 harmsja 7814: .LC_ListStyleClean li,
7815: .LC_ListStyleClean dd {
1.911 bisitz 7816: padding-top: 0;
7817: padding-bottom: 0;
1.693 droeschl 7818: }
7819:
1.721 harmsja 7820: .LC_ListStyleSimple dd,
1.795 www 7821: .LC_ListStyleSimple li {
1.911 bisitz 7822: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7823: }
7824:
1.721 harmsja 7825: .LC_ListStyleSpecial li,
7826: .LC_ListStyleSpecial dd {
1.911 bisitz 7827: list-style-type: none;
7828: background-color: RGB(220, 220, 220);
7829: margin-bottom: 4px;
1.693 droeschl 7830: }
7831:
1.721 harmsja 7832: table.LC_SimpleTable {
1.911 bisitz 7833: margin:5px;
7834: border:solid 1px $lg_border_color;
1.795 www 7835: }
1.693 droeschl 7836:
1.721 harmsja 7837: table.LC_SimpleTable tr {
1.911 bisitz 7838: padding: 0;
7839: border:solid 1px $lg_border_color;
1.693 droeschl 7840: }
1.795 www 7841:
7842: table.LC_SimpleTable thead {
1.911 bisitz 7843: background:rgb(220,220,220);
1.693 droeschl 7844: }
7845:
1.721 harmsja 7846: div.LC_columnSection {
1.911 bisitz 7847: display: block;
7848: clear: both;
7849: overflow: hidden;
7850: margin: 0;
1.693 droeschl 7851: }
7852:
1.721 harmsja 7853: div.LC_columnSection>* {
1.911 bisitz 7854: float: left;
7855: margin: 10px 20px 10px 0;
7856: overflow:hidden;
1.693 droeschl 7857: }
1.721 harmsja 7858:
1.795 www 7859: table em {
1.911 bisitz 7860: font-weight: bold;
7861: font-style: normal;
1.748 schulted 7862: }
1.795 www 7863:
1.779 bisitz 7864: table.LC_tableBrowseRes,
1.795 www 7865: table.LC_tableOfContent {
1.911 bisitz 7866: border:none;
7867: border-spacing: 1px;
7868: padding: 3px;
7869: background-color: #FFFFFF;
7870: font-size: 90%;
1.753 droeschl 7871: }
1.789 droeschl 7872:
1.911 bisitz 7873: table.LC_tableOfContent {
7874: border-collapse: collapse;
1.789 droeschl 7875: }
7876:
1.771 droeschl 7877: table.LC_tableBrowseRes a,
1.768 schulted 7878: table.LC_tableOfContent a {
1.911 bisitz 7879: background-color: transparent;
7880: text-decoration: none;
1.753 droeschl 7881: }
7882:
1.795 www 7883: table.LC_tableOfContent img {
1.911 bisitz 7884: border: none;
7885: height: 1.3em;
7886: vertical-align: text-bottom;
7887: margin-right: 0.3em;
1.753 droeschl 7888: }
1.757 schulted 7889:
1.795 www 7890: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7891: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7892: }
7893:
1.795 www 7894: a#LC_content_toolbar_everything {
1.911 bisitz 7895: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7896: }
7897:
1.795 www 7898: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7899: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7900: }
7901:
1.795 www 7902: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7903: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7904: }
7905:
1.795 www 7906: a#LC_content_toolbar_changefolder {
1.911 bisitz 7907: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7908: }
7909:
1.795 www 7910: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7911: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7912: }
7913:
1.1043 raeburn 7914: a#LC_content_toolbar_edittoplevel {
7915: background-image:url(/res/adm/pages/edittoplevel.gif);
7916: }
7917:
1.795 www 7918: ul#LC_toolbar li a:hover {
1.911 bisitz 7919: background-position: bottom center;
1.757 schulted 7920: }
7921:
1.795 www 7922: ul#LC_toolbar {
1.911 bisitz 7923: padding: 0;
7924: margin: 2px;
7925: list-style:none;
7926: position:relative;
7927: background-color:white;
1.1082 raeburn 7928: overflow: auto;
1.757 schulted 7929: }
7930:
1.795 www 7931: ul#LC_toolbar li {
1.911 bisitz 7932: border:1px solid white;
7933: padding: 0;
7934: margin: 0;
7935: float: left;
7936: display:inline;
7937: vertical-align:middle;
1.1082 raeburn 7938: white-space: nowrap;
1.911 bisitz 7939: }
1.757 schulted 7940:
1.783 amueller 7941:
1.795 www 7942: a.LC_toolbarItem {
1.911 bisitz 7943: display:block;
7944: padding: 0;
7945: margin: 0;
7946: height: 32px;
7947: width: 32px;
7948: color:white;
7949: border: none;
7950: background-repeat:no-repeat;
7951: background-color:transparent;
1.757 schulted 7952: }
7953:
1.915 droeschl 7954: ul.LC_funclist {
7955: margin: 0;
7956: padding: 0.5em 1em 0.5em 0;
7957: }
7958:
1.933 droeschl 7959: ul.LC_funclist > li:first-child {
7960: font-weight:bold;
7961: margin-left:0.8em;
7962: }
7963:
1.915 droeschl 7964: ul.LC_funclist + ul.LC_funclist {
7965: /*
7966: left border as a seperator if we have more than
7967: one list
7968: */
7969: border-left: 1px solid $sidebg;
7970: /*
7971: this hides the left border behind the border of the
7972: outer box if element is wrapped to the next 'line'
7973: */
7974: margin-left: -1px;
7975: }
7976:
1.843 bisitz 7977: ul.LC_funclist li {
1.915 droeschl 7978: display: inline;
1.782 bisitz 7979: white-space: nowrap;
1.915 droeschl 7980: margin: 0 0 0 25px;
7981: line-height: 150%;
1.782 bisitz 7982: }
7983:
1.974 wenzelju 7984: .LC_hidden {
7985: display: none;
7986: }
7987:
1.1030 www 7988: .LCmodal-overlay {
7989: position:fixed;
7990: top:0;
7991: right:0;
7992: bottom:0;
7993: left:0;
7994: height:100%;
7995: width:100%;
7996: margin:0;
7997: padding:0;
7998: background:#999;
7999: opacity:.75;
8000: filter: alpha(opacity=75);
8001: -moz-opacity: 0.75;
8002: z-index:101;
8003: }
8004:
8005: * html .LCmodal-overlay {
8006: position: absolute;
8007: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8008: }
8009:
8010: .LCmodal-window {
8011: position:fixed;
8012: top:50%;
8013: left:50%;
8014: margin:0;
8015: padding:0;
8016: z-index:102;
8017: }
8018:
8019: * html .LCmodal-window {
8020: position:absolute;
8021: }
8022:
8023: .LCclose-window {
8024: position:absolute;
8025: width:32px;
8026: height:32px;
8027: right:8px;
8028: top:8px;
8029: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8030: text-indent:-99999px;
8031: overflow:hidden;
8032: cursor:pointer;
8033: }
8034:
1.1100 raeburn 8035: /*
1.1231 damieng 8036: styles used for response display
8037: */
8038: div.LC_radiofoil, div.LC_rankfoil {
8039: margin: .5em 0em .5em 0em;
8040: }
8041: table.LC_itemgroup {
8042: margin-top: 1em;
8043: }
8044:
8045: /*
1.1100 raeburn 8046: styles used by TTH when "Default set of options to pass to tth/m
8047: when converting TeX" in course settings has been set
8048:
8049: option passed: -t
8050:
8051: */
8052:
8053: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8054: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8055: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8056: td div.norm {line-height:normal;}
8057:
8058: /*
8059: option passed -y3
8060: */
8061:
8062: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8063: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8064: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8065:
1.1230 damieng 8066: /*
8067: sections with roles, for content only
8068: */
8069: section[class^="role-"] {
8070: padding-left: 10px;
8071: padding-right: 5px;
8072: margin-top: 8px;
8073: margin-bottom: 8px;
8074: border: 1px solid #2A4;
8075: border-radius: 5px;
8076: box-shadow: 0px 1px 1px #BBB;
8077: }
8078: section[class^="role-"]>h1 {
8079: position: relative;
8080: margin: 0px;
8081: padding-top: 10px;
8082: padding-left: 40px;
8083: }
8084: section[class^="role-"]>h1:before {
8085: position: absolute;
8086: left: -5px;
8087: top: 5px;
8088: }
8089: section.role-activity>h1:before {
8090: content:url('/adm/daxe/images/section_icons/activity.png');
8091: }
8092: section.role-advice>h1:before {
8093: content:url('/adm/daxe/images/section_icons/advice.png');
8094: }
8095: section.role-bibliography>h1:before {
8096: content:url('/adm/daxe/images/section_icons/bibliography.png');
8097: }
8098: section.role-citation>h1:before {
8099: content:url('/adm/daxe/images/section_icons/citation.png');
8100: }
8101: section.role-conclusion>h1:before {
8102: content:url('/adm/daxe/images/section_icons/conclusion.png');
8103: }
8104: section.role-definition>h1:before {
8105: content:url('/adm/daxe/images/section_icons/definition.png');
8106: }
8107: section.role-demonstration>h1:before {
8108: content:url('/adm/daxe/images/section_icons/demonstration.png');
8109: }
8110: section.role-example>h1:before {
8111: content:url('/adm/daxe/images/section_icons/example.png');
8112: }
8113: section.role-explanation>h1:before {
8114: content:url('/adm/daxe/images/section_icons/explanation.png');
8115: }
8116: section.role-introduction>h1:before {
8117: content:url('/adm/daxe/images/section_icons/introduction.png');
8118: }
8119: section.role-method>h1:before {
8120: content:url('/adm/daxe/images/section_icons/method.png');
8121: }
8122: section.role-more_information>h1:before {
8123: content:url('/adm/daxe/images/section_icons/more_information.png');
8124: }
8125: section.role-objectives>h1:before {
8126: content:url('/adm/daxe/images/section_icons/objectives.png');
8127: }
8128: section.role-prerequisites>h1:before {
8129: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8130: }
8131: section.role-remark>h1:before {
8132: content:url('/adm/daxe/images/section_icons/remark.png');
8133: }
8134: section.role-reminder>h1:before {
8135: content:url('/adm/daxe/images/section_icons/reminder.png');
8136: }
8137: section.role-summary>h1:before {
8138: content:url('/adm/daxe/images/section_icons/summary.png');
8139: }
8140: section.role-syntax>h1:before {
8141: content:url('/adm/daxe/images/section_icons/syntax.png');
8142: }
8143: section.role-warning>h1:before {
8144: content:url('/adm/daxe/images/section_icons/warning.png');
8145: }
8146:
1.1269 raeburn 8147: #LC_minitab_header {
8148: float:left;
8149: width:100%;
8150: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8151: font-size:93%;
8152: line-height:normal;
8153: margin: 0.5em 0 0.5em 0;
8154: }
8155: #LC_minitab_header ul {
8156: margin:0;
8157: padding:10px 10px 0;
8158: list-style:none;
8159: }
8160: #LC_minitab_header li {
8161: float:left;
8162: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8163: margin:0;
8164: padding:0 0 0 9px;
8165: }
8166: #LC_minitab_header a {
8167: display:block;
8168: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8169: padding:5px 15px 4px 6px;
8170: }
8171: #LC_minitab_header #LC_current_minitab {
8172: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8173: }
8174: #LC_minitab_header #LC_current_minitab a {
8175: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8176: padding-bottom:5px;
8177: }
8178:
8179:
1.343 albertel 8180: END
8181: }
8182:
1.306 albertel 8183: =pod
8184:
8185: =item * &headtag()
8186:
8187: Returns a uniform footer for LON-CAPA web pages.
8188:
1.307 albertel 8189: Inputs: $title - optional title for the head
8190: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8191: $args - optional arguments
1.319 albertel 8192: force_register - if is true call registerurl so the remote is
8193: informed
1.415 albertel 8194: redirect -> array ref of
8195: 1- seconds before redirect occurs
8196: 2- url to redirect to
8197: 3- whether the side effect should occur
1.315 albertel 8198: (side effect of setting
8199: $env{'internal.head.redirect'} to the url
8200: redirected too)
1.352 albertel 8201: domain -> force to color decorate a page for a specific
8202: domain
8203: function -> force usage of a specific rolish color scheme
8204: bgcolor -> override the default page bgcolor
1.460 albertel 8205: no_auto_mt_title
8206: -> prevent &mt()ing the title arg
1.464 albertel 8207:
1.306 albertel 8208: =cut
8209:
8210: sub headtag {
1.313 albertel 8211: my ($title,$head_extra,$args) = @_;
1.306 albertel 8212:
1.363 albertel 8213: my $function = $args->{'function'} || &get_users_function();
8214: my $domain = $args->{'domain'} || &determinedomain();
8215: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8216: my $httphost = $args->{'use_absolute'};
1.418 albertel 8217: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8218: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8219: #time(),
1.418 albertel 8220: $env{'environment.color.timestamp'},
1.363 albertel 8221: $function,$domain,$bgcolor);
8222:
1.369 www 8223: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8224:
1.308 albertel 8225: my $result =
8226: '<head>'.
1.1160 raeburn 8227: &font_settings($args);
1.319 albertel 8228:
1.1188 raeburn 8229: my $inhibitprint;
8230: if ($args->{'print_suppress'}) {
8231: $inhibitprint = &print_suppression();
8232: }
1.1064 raeburn 8233:
1.461 albertel 8234: if (!$args->{'frameset'}) {
8235: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8236: }
1.962 droeschl 8237: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8238: $result .= Apache::lonxml::display_title();
1.319 albertel 8239: }
1.436 albertel 8240: if (!$args->{'no_nav_bar'}
8241: && !$args->{'only_body'}
8242: && !$args->{'frameset'}) {
1.1154 raeburn 8243: $result .= &help_menu_js($httphost);
1.1032 www 8244: $result.=&modal_window();
1.1038 www 8245: $result.=&togglebox_script();
1.1034 www 8246: $result.=&wishlist_window();
1.1041 www 8247: $result.=&LCprogressbarUpdate_script();
1.1034 www 8248: } else {
8249: if ($args->{'add_modal'}) {
8250: $result.=&modal_window();
8251: }
8252: if ($args->{'add_wishlist'}) {
8253: $result.=&wishlist_window();
8254: }
1.1038 www 8255: if ($args->{'add_togglebox'}) {
8256: $result.=&togglebox_script();
8257: }
1.1041 www 8258: if ($args->{'add_progressbar'}) {
8259: $result.=&LCprogressbarUpdate_script();
8260: }
1.436 albertel 8261: }
1.314 albertel 8262: if (ref($args->{'redirect'})) {
1.414 albertel 8263: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8264: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8265: if (!$inhibit_continue) {
8266: $env{'internal.head.redirect'} = $url;
8267: }
1.313 albertel 8268: $result.=<<ADDMETA
8269: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8270: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8271: ADDMETA
1.1210 raeburn 8272: } else {
8273: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8274: my $requrl = $env{'request.uri'};
8275: if ($requrl eq '') {
8276: $requrl = $ENV{'REQUEST_URI'};
8277: $requrl =~ s/\?.+$//;
8278: }
8279: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8280: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8281: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8282: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8283: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8284: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
8285: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8286: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8287: if ($domdefs{'offloadnow'}{$lonhost}) {
8288: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8289: if (($newserver) && ($newserver ne $lonhost)) {
8290: my $numsec = 5;
8291: my $timeout = $numsec * 1000;
8292: my ($newurl,$locknum,%locks,$msg);
8293: if ($env{'request.role.adv'}) {
8294: ($locknum,%locks) = &Apache::lonnet::get_locks();
8295: }
8296: my $disable_submit = 0;
8297: if ($requrl =~ /$LONCAPA::assess_re/) {
8298: $disable_submit = 1;
8299: }
8300: if ($locknum) {
8301: my @lockinfo = sort(values(%locks));
8302: $msg = &mt('Once the following tasks are complete: ')."\\n".
8303: join(", ",sort(values(%locks)))."\\n".
8304: &mt('your session will be transferred to a different server, after you click "Roles".');
8305: } else {
8306: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8307: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
8308: }
8309: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8310: $newurl = '/adm/switchserver?otherserver='.$newserver;
8311: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8312: $newurl .= '&role='.$env{'request.role'};
8313: }
8314: if ($env{'request.symb'}) {
8315: $newurl .= '&symb='.$env{'request.symb'};
8316: } else {
8317: $newurl .= '&origurl='.$requrl;
8318: }
8319: }
1.1222 damieng 8320: &js_escape(\$msg);
1.1210 raeburn 8321: $result.=<<OFFLOAD
8322: <meta http-equiv="pragma" content="no-cache" />
8323: <script type="text/javascript">
1.1215 raeburn 8324: // <![CDATA[
1.1210 raeburn 8325: function LC_Offload_Now() {
8326: var dest = "$newurl";
8327: if (dest != '') {
8328: window.location.href="$newurl";
8329: }
8330: }
1.1214 raeburn 8331: \$(document).ready(function () {
8332: window.alert('$msg');
8333: if ($disable_submit) {
1.1210 raeburn 8334: \$(".LC_hwk_submit").prop("disabled", true);
8335: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8336: }
8337: setTimeout('LC_Offload_Now()', $timeout);
8338: });
1.1215 raeburn 8339: // ]]>
1.1210 raeburn 8340: </script>
8341: OFFLOAD
8342: }
8343: }
8344: }
8345: }
8346: }
8347: }
1.313 albertel 8348: }
1.306 albertel 8349: if (!defined($title)) {
8350: $title = 'The LearningOnline Network with CAPA';
8351: }
1.460 albertel 8352: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8353: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8354: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8355: if (!$args->{'frameset'}) {
8356: $result .= ' /';
8357: }
8358: $result .= '>'
1.1064 raeburn 8359: .$inhibitprint
1.414 albertel 8360: .$head_extra;
1.1242 raeburn 8361: my $clientmobile;
8362: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8363: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8364: } else {
8365: $clientmobile = $env{'browser.mobile'};
8366: }
8367: if ($clientmobile) {
1.1137 raeburn 8368: $result .= '
8369: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8370: <meta name="apple-mobile-web-app-capable" content="yes" />';
8371: }
1.1278 raeburn 8372: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8373: return $result.'</head>';
1.306 albertel 8374: }
8375:
8376: =pod
8377:
1.340 albertel 8378: =item * &font_settings()
8379:
8380: Returns neccessary <meta> to set the proper encoding
8381:
1.1160 raeburn 8382: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8383:
8384: =cut
8385:
8386: sub font_settings {
1.1160 raeburn 8387: my ($args) = @_;
1.340 albertel 8388: my $headerstring='';
1.1160 raeburn 8389: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8390: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8391: $headerstring.=
8392: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8393: if (!$args->{'frameset'}) {
8394: $headerstring.= ' /';
8395: }
8396: $headerstring .= '>'."\n";
1.340 albertel 8397: }
8398: return $headerstring;
8399: }
8400:
1.341 albertel 8401: =pod
8402:
1.1064 raeburn 8403: =item * &print_suppression()
8404:
8405: In course context returns css which causes the body to be blank when media="print",
8406: if printout generation is unavailable for the current resource.
8407:
8408: This could be because:
8409:
8410: (a) printstartdate is in the future
8411:
8412: (b) printenddate is in the past
8413:
8414: (c) there is an active exam block with "printout"
8415: functionality blocked
8416:
8417: Users with pav, pfo or evb privileges are exempt.
8418:
8419: Inputs: none
8420:
8421: =cut
8422:
8423:
8424: sub print_suppression {
8425: my $noprint;
8426: if ($env{'request.course.id'}) {
8427: my $scope = $env{'request.course.id'};
8428: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8429: (&Apache::lonnet::allowed('pfo',$scope))) {
8430: return;
8431: }
8432: if ($env{'request.course.sec'} ne '') {
8433: $scope .= "/$env{'request.course.sec'}";
8434: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8435: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8436: return;
1.1064 raeburn 8437: }
8438: }
8439: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8440: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8441: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8442: if ($blocked) {
8443: my $checkrole = "cm./$cdom/$cnum";
8444: if ($env{'request.course.sec'} ne '') {
8445: $checkrole .= "/$env{'request.course.sec'}";
8446: }
8447: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8448: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8449: $noprint = 1;
8450: }
8451: }
8452: unless ($noprint) {
8453: my $symb = &Apache::lonnet::symbread();
8454: if ($symb ne '') {
8455: my $navmap = Apache::lonnavmaps::navmap->new();
8456: if (ref($navmap)) {
8457: my $res = $navmap->getBySymb($symb);
8458: if (ref($res)) {
8459: if (!$res->resprintable()) {
8460: $noprint = 1;
8461: }
8462: }
8463: }
8464: }
8465: }
8466: if ($noprint) {
8467: return <<"ENDSTYLE";
8468: <style type="text/css" media="print">
8469: body { display:none }
8470: </style>
8471: ENDSTYLE
8472: }
8473: }
8474: return;
8475: }
8476:
8477: =pod
8478:
1.341 albertel 8479: =item * &xml_begin()
8480:
8481: Returns the needed doctype and <html>
8482:
8483: Inputs: none
8484:
8485: =cut
8486:
8487: sub xml_begin {
1.1168 raeburn 8488: my ($is_frameset) = @_;
1.341 albertel 8489: my $output='';
8490:
8491: if ($env{'browser.mathml'}) {
8492: $output='<?xml version="1.0"?>'
8493: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8494: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8495:
8496: # .'<!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">] >'
8497: .'<!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">'
8498: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8499: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8500: } elsif ($is_frameset) {
8501: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8502: '<html>'."\n";
1.341 albertel 8503: } else {
1.1168 raeburn 8504: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8505: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8506: }
8507: return $output;
8508: }
1.340 albertel 8509:
8510: =pod
8511:
1.306 albertel 8512: =item * &start_page()
8513:
8514: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8515:
1.648 raeburn 8516: Inputs:
8517:
8518: =over 4
8519:
8520: $title - optional title for the page
8521:
8522: $head_extra - optional extra HTML to incude inside the <head>
8523:
8524: $args - additional optional args supported are:
8525:
8526: =over 8
8527:
8528: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8529: arg on
1.814 bisitz 8530: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8531: add_entries -> additional attributes to add to the <body>
8532: domain -> force to color decorate a page for a
1.317 albertel 8533: specific domain
1.648 raeburn 8534: function -> force usage of a specific rolish color
1.317 albertel 8535: scheme
1.648 raeburn 8536: redirect -> see &headtag()
8537: bgcolor -> override the default page bg color
8538: js_ready -> return a string ready for being used in
1.317 albertel 8539: a javascript writeln
1.648 raeburn 8540: html_encode -> return a string ready for being used in
1.320 albertel 8541: a html attribute
1.648 raeburn 8542: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8543: $forcereg arg
1.648 raeburn 8544: frameset -> if true will start with a <frameset>
1.330 albertel 8545: rather than <body>
1.648 raeburn 8546: skip_phases -> hash ref of
1.338 albertel 8547: head -> skip the <html><head> generation
8548: body -> skip all <body> generation
1.648 raeburn 8549: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8550: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8551: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8552: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8553: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8554: group -> includes the current group, if page is for a
1.1274 raeburn 8555: specific group
8556: use_absolute -> for request for external resource or syllabus, this
8557: will contain https://<hostname> if server uses
8558: https (as per hosts.tab), but request is for http
8559: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8560:
1.648 raeburn 8561: =back
1.460 albertel 8562:
1.648 raeburn 8563: =back
1.562 albertel 8564:
1.306 albertel 8565: =cut
8566:
8567: sub start_page {
1.309 albertel 8568: my ($title,$head_extra,$args) = @_;
1.318 albertel 8569: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8570:
1.315 albertel 8571: $env{'internal.start_page'}++;
1.1096 raeburn 8572: my ($result,@advtools);
1.964 droeschl 8573:
1.338 albertel 8574: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8575: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8576: }
8577:
8578: if (! exists($args->{'skip_phases'}{'body'}) ) {
8579: if ($args->{'frameset'}) {
8580: my $attr_string = &make_attr_string($args->{'force_register'},
8581: $args->{'add_entries'});
8582: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8583: } else {
8584: $result .=
8585: &bodytag($title,
8586: $args->{'function'}, $args->{'add_entries'},
8587: $args->{'only_body'}, $args->{'domain'},
8588: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8589: $args->{'bgcolor'}, $args,
8590: \@advtools);
1.831 bisitz 8591: }
1.330 albertel 8592: }
1.338 albertel 8593:
1.315 albertel 8594: if ($args->{'js_ready'}) {
1.713 kaisler 8595: $result = &js_ready($result);
1.315 albertel 8596: }
1.320 albertel 8597: if ($args->{'html_encode'}) {
1.713 kaisler 8598: $result = &html_encode($result);
8599: }
8600:
1.813 bisitz 8601: # Preparation for new and consistent functionlist at top of screen
8602: # if ($args->{'functionlist'}) {
8603: # $result .= &build_functionlist();
8604: #}
8605:
1.964 droeschl 8606: # Don't add anything more if only_body wanted or in const space
8607: return $result if $args->{'only_body'}
8608: || $env{'request.state'} eq 'construct';
1.813 bisitz 8609:
8610: #Breadcrumbs
1.758 kaisler 8611: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8612: &Apache::lonhtmlcommon::clear_breadcrumbs();
8613: #if any br links exists, add them to the breadcrumbs
8614: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8615: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8616: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8617: }
8618: }
1.1096 raeburn 8619: # if @advtools array contains items add then to the breadcrumbs
8620: if (@advtools > 0) {
8621: &Apache::lonmenu::advtools_crumbs(@advtools);
8622: }
1.1272 raeburn 8623: my $menulink;
8624: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8625: if ((exists($args->{'bread_crumbs_nomenu'})) ||
8626: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
8627: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
8628: (!$env{'request.role.adv'}))) {
8629: $menulink = 0;
8630: } else {
8631: undef($menulink);
8632: }
1.758 kaisler 8633: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8634: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 8635: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 8636: } else {
1.1272 raeburn 8637: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8638: }
1.320 albertel 8639: }
1.315 albertel 8640: return $result;
1.306 albertel 8641: }
8642:
8643: sub end_page {
1.315 albertel 8644: my ($args) = @_;
8645: $env{'internal.end_page'}++;
1.330 albertel 8646: my $result;
1.335 albertel 8647: if ($args->{'discussion'}) {
8648: my ($target,$parser);
8649: if (ref($args->{'discussion'})) {
8650: ($target,$parser) =($args->{'discussion'}{'target'},
8651: $args->{'discussion'}{'parser'});
8652: }
8653: $result .= &Apache::lonxml::xmlend($target,$parser);
8654: }
1.330 albertel 8655: if ($args->{'frameset'}) {
8656: $result .= '</frameset>';
8657: } else {
1.635 raeburn 8658: $result .= &endbodytag($args);
1.330 albertel 8659: }
1.1080 raeburn 8660: unless ($args->{'notbody'}) {
8661: $result .= "\n</html>";
8662: }
1.330 albertel 8663:
1.315 albertel 8664: if ($args->{'js_ready'}) {
1.317 albertel 8665: $result = &js_ready($result);
1.315 albertel 8666: }
1.335 albertel 8667:
1.320 albertel 8668: if ($args->{'html_encode'}) {
8669: $result = &html_encode($result);
8670: }
1.335 albertel 8671:
1.315 albertel 8672: return $result;
8673: }
8674:
1.1034 www 8675: sub wishlist_window {
8676: return(<<'ENDWISHLIST');
1.1046 raeburn 8677: <script type="text/javascript">
1.1034 www 8678: // <![CDATA[
8679: // <!-- BEGIN LON-CAPA Internal
8680: function set_wishlistlink(title, path) {
8681: if (!title) {
8682: title = document.title;
8683: title = title.replace(/^LON-CAPA /,'');
8684: }
1.1175 raeburn 8685: title = encodeURIComponent(title);
1.1203 raeburn 8686: title = title.replace("'","\\\'");
1.1034 www 8687: if (!path) {
8688: path = location.pathname;
8689: }
1.1175 raeburn 8690: path = encodeURIComponent(path);
1.1203 raeburn 8691: path = path.replace("'","\\\'");
1.1034 www 8692: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8693: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8694: }
8695: // END LON-CAPA Internal -->
8696: // ]]>
8697: </script>
8698: ENDWISHLIST
8699: }
8700:
1.1030 www 8701: sub modal_window {
8702: return(<<'ENDMODAL');
1.1046 raeburn 8703: <script type="text/javascript">
1.1030 www 8704: // <![CDATA[
8705: // <!-- BEGIN LON-CAPA Internal
8706: var modalWindow = {
8707: parent:"body",
8708: windowId:null,
8709: content:null,
8710: width:null,
8711: height:null,
8712: close:function()
8713: {
8714: $(".LCmodal-window").remove();
8715: $(".LCmodal-overlay").remove();
8716: },
8717: open:function()
8718: {
8719: var modal = "";
8720: modal += "<div class=\"LCmodal-overlay\"></div>";
8721: 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;\">";
8722: modal += this.content;
8723: modal += "</div>";
8724:
8725: $(this.parent).append(modal);
8726:
8727: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8728: $(".LCclose-window").click(function(){modalWindow.close();});
8729: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8730: }
8731: };
1.1140 raeburn 8732: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8733: {
1.1266 raeburn 8734: source = source.replace(/'/g,"'");
1.1030 www 8735: modalWindow.windowId = "myModal";
8736: modalWindow.width = width;
8737: modalWindow.height = height;
1.1196 raeburn 8738: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8739: modalWindow.open();
1.1208 raeburn 8740: };
1.1030 www 8741: // END LON-CAPA Internal -->
8742: // ]]>
8743: </script>
8744: ENDMODAL
8745: }
8746:
8747: sub modal_link {
1.1140 raeburn 8748: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8749: unless ($width) { $width=480; }
8750: unless ($height) { $height=400; }
1.1031 www 8751: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8752: unless ($transparency) { $transparency='true'; }
8753:
1.1074 raeburn 8754: my $target_attr;
8755: if (defined($target)) {
8756: $target_attr = 'target="'.$target.'"';
8757: }
8758: return <<"ENDLINK";
1.1140 raeburn 8759: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8760: $linktext</a>
8761: ENDLINK
1.1030 www 8762: }
8763:
1.1032 www 8764: sub modal_adhoc_script {
8765: my ($funcname,$width,$height,$content)=@_;
8766: return (<<ENDADHOC);
1.1046 raeburn 8767: <script type="text/javascript">
1.1032 www 8768: // <![CDATA[
8769: var $funcname = function()
8770: {
8771: modalWindow.windowId = "myModal";
8772: modalWindow.width = $width;
8773: modalWindow.height = $height;
8774: modalWindow.content = '$content';
8775: modalWindow.open();
8776: };
8777: // ]]>
8778: </script>
8779: ENDADHOC
8780: }
8781:
1.1041 www 8782: sub modal_adhoc_inner {
8783: my ($funcname,$width,$height,$content)=@_;
8784: my $innerwidth=$width-20;
8785: $content=&js_ready(
1.1140 raeburn 8786: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8787: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8788: $content.
1.1041 www 8789: &end_scrollbox().
1.1140 raeburn 8790: &end_page()
1.1041 www 8791: );
8792: return &modal_adhoc_script($funcname,$width,$height,$content);
8793: }
8794:
8795: sub modal_adhoc_window {
8796: my ($funcname,$width,$height,$content,$linktext)=@_;
8797: return &modal_adhoc_inner($funcname,$width,$height,$content).
8798: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8799: }
8800:
8801: sub modal_adhoc_launch {
8802: my ($funcname,$width,$height,$content)=@_;
8803: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8804: <script type="text/javascript">
8805: // <![CDATA[
8806: $funcname();
8807: // ]]>
8808: </script>
8809: ENDLAUNCH
8810: }
8811:
8812: sub modal_adhoc_close {
8813: return (<<ENDCLOSE);
8814: <script type="text/javascript">
8815: // <![CDATA[
8816: modalWindow.close();
8817: // ]]>
8818: </script>
8819: ENDCLOSE
8820: }
8821:
1.1038 www 8822: sub togglebox_script {
8823: return(<<ENDTOGGLE);
8824: <script type="text/javascript">
8825: // <![CDATA[
8826: function LCtoggleDisplay(id,hidetext,showtext) {
8827: link = document.getElementById(id + "link").childNodes[0];
8828: with (document.getElementById(id).style) {
8829: if (display == "none" ) {
8830: display = "inline";
8831: link.nodeValue = hidetext;
8832: } else {
8833: display = "none";
8834: link.nodeValue = showtext;
8835: }
8836: }
8837: }
8838: // ]]>
8839: </script>
8840: ENDTOGGLE
8841: }
8842:
1.1039 www 8843: sub start_togglebox {
8844: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8845: unless ($heading) { $heading=''; } else { $heading.=' '; }
8846: unless ($showtext) { $showtext=&mt('show'); }
8847: unless ($hidetext) { $hidetext=&mt('hide'); }
8848: unless ($headerbg) { $headerbg='#FFFFFF'; }
8849: return &start_data_table().
8850: &start_data_table_header_row().
8851: '<td bgcolor="'.$headerbg.'">'.$heading.
8852: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8853: $showtext.'\')">'.$showtext.'</a>]</td>'.
8854: &end_data_table_header_row().
8855: '<tr id="'.$id.'" style="display:none""><td>';
8856: }
8857:
8858: sub end_togglebox {
8859: return '</td></tr>'.&end_data_table();
8860: }
8861:
1.1041 www 8862: sub LCprogressbar_script {
1.1045 www 8863: my ($id)=@_;
1.1041 www 8864: return(<<ENDPROGRESS);
8865: <script type="text/javascript">
8866: // <![CDATA[
1.1045 www 8867: \$('#progressbar$id').progressbar({
1.1041 www 8868: value: 0,
8869: change: function(event, ui) {
8870: var newVal = \$(this).progressbar('option', 'value');
8871: \$('.pblabel', this).text(LCprogressTxt);
8872: }
8873: });
8874: // ]]>
8875: </script>
8876: ENDPROGRESS
8877: }
8878:
8879: sub LCprogressbarUpdate_script {
8880: return(<<ENDPROGRESSUPDATE);
8881: <style type="text/css">
8882: .ui-progressbar { position:relative; }
8883: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8884: </style>
8885: <script type="text/javascript">
8886: // <![CDATA[
1.1045 www 8887: var LCprogressTxt='---';
8888:
8889: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8890: LCprogressTxt=progresstext;
1.1045 www 8891: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8892: }
8893: // ]]>
8894: </script>
8895: ENDPROGRESSUPDATE
8896: }
8897:
1.1042 www 8898: my $LClastpercent;
1.1045 www 8899: my $LCidcnt;
8900: my $LCcurrentid;
1.1042 www 8901:
1.1041 www 8902: sub LCprogressbar {
1.1042 www 8903: my ($r)=(@_);
8904: $LClastpercent=0;
1.1045 www 8905: $LCidcnt++;
8906: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8907: my $starting=&mt('Starting');
8908: my $content=(<<ENDPROGBAR);
1.1045 www 8909: <div id="progressbar$LCcurrentid">
1.1041 www 8910: <span class="pblabel">$starting</span>
8911: </div>
8912: ENDPROGBAR
1.1045 www 8913: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8914: }
8915:
8916: sub LCprogressbarUpdate {
1.1042 www 8917: my ($r,$val,$text)=@_;
8918: unless ($val) {
8919: if ($LClastpercent) {
8920: $val=$LClastpercent;
8921: } else {
8922: $val=0;
8923: }
8924: }
1.1041 www 8925: if ($val<0) { $val=0; }
8926: if ($val>100) { $val=0; }
1.1042 www 8927: $LClastpercent=$val;
1.1041 www 8928: unless ($text) { $text=$val.'%'; }
8929: $text=&js_ready($text);
1.1044 www 8930: &r_print($r,<<ENDUPDATE);
1.1041 www 8931: <script type="text/javascript">
8932: // <![CDATA[
1.1045 www 8933: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8934: // ]]>
8935: </script>
8936: ENDUPDATE
1.1035 www 8937: }
8938:
1.1042 www 8939: sub LCprogressbarClose {
8940: my ($r)=@_;
8941: $LClastpercent=0;
1.1044 www 8942: &r_print($r,<<ENDCLOSE);
1.1042 www 8943: <script type="text/javascript">
8944: // <![CDATA[
1.1045 www 8945: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8946: // ]]>
8947: </script>
8948: ENDCLOSE
1.1044 www 8949: }
8950:
8951: sub r_print {
8952: my ($r,$to_print)=@_;
8953: if ($r) {
8954: $r->print($to_print);
8955: $r->rflush();
8956: } else {
8957: print($to_print);
8958: }
1.1042 www 8959: }
8960:
1.320 albertel 8961: sub html_encode {
8962: my ($result) = @_;
8963:
1.322 albertel 8964: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8965:
8966: return $result;
8967: }
1.1044 www 8968:
1.317 albertel 8969: sub js_ready {
8970: my ($result) = @_;
8971:
1.323 albertel 8972: $result =~ s/[\n\r]/ /xmsg;
8973: $result =~ s/\\/\\\\/xmsg;
8974: $result =~ s/'/\\'/xmsg;
1.372 albertel 8975: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8976:
8977: return $result;
8978: }
8979:
1.315 albertel 8980: sub validate_page {
8981: if ( exists($env{'internal.start_page'})
1.316 albertel 8982: && $env{'internal.start_page'} > 1) {
8983: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8984: $env{'internal.start_page'}.' '.
1.316 albertel 8985: $ENV{'request.filename'});
1.315 albertel 8986: }
8987: if ( exists($env{'internal.end_page'})
1.316 albertel 8988: && $env{'internal.end_page'} > 1) {
8989: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8990: $env{'internal.end_page'}.' '.
1.316 albertel 8991: $env{'request.filename'});
1.315 albertel 8992: }
8993: if ( exists($env{'internal.start_page'})
8994: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8995: &Apache::lonnet::logthis('start_page called without end_page '.
8996: $env{'request.filename'});
1.315 albertel 8997: }
8998: if ( ! exists($env{'internal.start_page'})
8999: && exists($env{'internal.end_page'})) {
1.316 albertel 9000: &Apache::lonnet::logthis('end_page called without start_page'.
9001: $env{'request.filename'});
1.315 albertel 9002: }
1.306 albertel 9003: }
1.315 albertel 9004:
1.996 www 9005:
9006: sub start_scrollbox {
1.1140 raeburn 9007: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9008: unless ($outerwidth) { $outerwidth='520px'; }
9009: unless ($width) { $width='500px'; }
9010: unless ($height) { $height='200px'; }
1.1075 raeburn 9011: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9012: if ($id ne '') {
1.1140 raeburn 9013: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9014: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9015: }
1.1075 raeburn 9016: if ($bgcolor ne '') {
9017: $tdcol = "background-color: $bgcolor;";
9018: }
1.1137 raeburn 9019: my $nicescroll_js;
9020: if ($env{'browser.mobile'}) {
1.1140 raeburn 9021: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9022: }
9023: return <<"END";
9024: $nicescroll_js
9025:
9026: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9027: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9028: END
9029: }
9030:
9031: sub end_scrollbox {
9032: return '</div></td></tr></table>';
9033: }
9034:
9035: sub nicescroll_javascript {
9036: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9037: my %options;
9038: if (ref($cursor) eq 'HASH') {
9039: %options = %{$cursor};
9040: }
9041: unless ($options{'railalign'} =~ /^left|right$/) {
9042: $options{'railalign'} = 'left';
9043: }
9044: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9045: my $function = &get_users_function();
9046: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9047: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9048: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9049: }
1.1140 raeburn 9050: }
9051: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9052: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9053: $options{'cursoropacity'}='1.0';
9054: }
1.1140 raeburn 9055: } else {
9056: $options{'cursoropacity'}='1.0';
9057: }
9058: if ($options{'cursorfixedheight'} eq 'none') {
9059: delete($options{'cursorfixedheight'});
9060: } else {
9061: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9062: }
9063: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9064: delete($options{'railoffset'});
9065: }
9066: my @niceoptions;
9067: while (my($key,$value) = each(%options)) {
9068: if ($value =~ /^\{.+\}$/) {
9069: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9070: } else {
1.1140 raeburn 9071: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9072: }
1.1140 raeburn 9073: }
9074: my $nicescroll_js = '
1.1137 raeburn 9075: $(document).ready(
1.1140 raeburn 9076: function() {
9077: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9078: }
1.1137 raeburn 9079: );
9080: ';
1.1140 raeburn 9081: if ($framecheck) {
9082: $nicescroll_js .= '
9083: function expand_div(caller) {
9084: if (top === self) {
9085: document.getElementById("'.$id.'").style.width = "auto";
9086: document.getElementById("'.$id.'").style.height = "auto";
9087: } else {
9088: try {
9089: if (parent.frames) {
9090: if (parent.frames.length > 1) {
9091: var framesrc = parent.frames[1].location.href;
9092: var currsrc = framesrc.replace(/\#.*$/,"");
9093: if ((caller == "search") || (currsrc == "'.$location.'")) {
9094: document.getElementById("'.$id.'").style.width = "auto";
9095: document.getElementById("'.$id.'").style.height = "auto";
9096: }
9097: }
9098: }
9099: } catch (e) {
9100: return;
9101: }
1.1137 raeburn 9102: }
1.1140 raeburn 9103: return;
1.996 www 9104: }
1.1140 raeburn 9105: ';
9106: }
9107: if ($needjsready) {
9108: $nicescroll_js = '
9109: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9110: } else {
9111: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9112: }
9113: return $nicescroll_js;
1.996 www 9114: }
9115:
1.318 albertel 9116: sub simple_error_page {
1.1150 bisitz 9117: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 9118: if (ref($args) eq 'HASH') {
9119: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
9120: } else {
9121: $msg = &mt($msg);
9122: }
1.1150 bisitz 9123:
1.318 albertel 9124: my $page =
9125: &Apache::loncommon::start_page($title).
1.1150 bisitz 9126: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9127: &Apache::loncommon::end_page();
9128: if (ref($r)) {
9129: $r->print($page);
1.327 albertel 9130: return;
1.318 albertel 9131: }
9132: return $page;
9133: }
1.347 albertel 9134:
9135: {
1.610 albertel 9136: my @row_count;
1.961 onken 9137:
9138: sub start_data_table_count {
9139: unshift(@row_count, 0);
9140: return;
9141: }
9142:
9143: sub end_data_table_count {
9144: shift(@row_count);
9145: return;
9146: }
9147:
1.347 albertel 9148: sub start_data_table {
1.1018 raeburn 9149: my ($add_class,$id) = @_;
1.422 albertel 9150: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9151: my $table_id;
9152: if (defined($id)) {
9153: $table_id = ' id="'.$id.'"';
9154: }
1.961 onken 9155: &start_data_table_count();
1.1018 raeburn 9156: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9157: }
9158:
9159: sub end_data_table {
1.961 onken 9160: &end_data_table_count();
1.389 albertel 9161: return '</table>'."\n";;
1.347 albertel 9162: }
9163:
9164: sub start_data_table_row {
1.974 wenzelju 9165: my ($add_class, $id) = @_;
1.610 albertel 9166: $row_count[0]++;
9167: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9168: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9169: $id = (' id="'.$id.'"') unless ($id eq '');
9170: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9171: }
1.471 banghart 9172:
9173: sub continue_data_table_row {
1.974 wenzelju 9174: my ($add_class, $id) = @_;
1.610 albertel 9175: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9176: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9177: $id = (' id="'.$id.'"') unless ($id eq '');
9178: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9179: }
1.347 albertel 9180:
9181: sub end_data_table_row {
1.389 albertel 9182: return '</tr>'."\n";;
1.347 albertel 9183: }
1.367 www 9184:
1.421 albertel 9185: sub start_data_table_empty_row {
1.707 bisitz 9186: # $row_count[0]++;
1.421 albertel 9187: return '<tr class="LC_empty_row" >'."\n";;
9188: }
9189:
9190: sub end_data_table_empty_row {
9191: return '</tr>'."\n";;
9192: }
9193:
1.367 www 9194: sub start_data_table_header_row {
1.389 albertel 9195: return '<tr class="LC_header_row">'."\n";;
1.367 www 9196: }
9197:
9198: sub end_data_table_header_row {
1.389 albertel 9199: return '</tr>'."\n";;
1.367 www 9200: }
1.890 droeschl 9201:
9202: sub data_table_caption {
9203: my $caption = shift;
9204: return "<caption class=\"LC_caption\">$caption</caption>";
9205: }
1.347 albertel 9206: }
9207:
1.548 albertel 9208: =pod
9209:
9210: =item * &inhibit_menu_check($arg)
9211:
9212: Checks for a inhibitmenu state and generates output to preserve it
9213:
9214: Inputs: $arg - can be any of
9215: - undef - in which case the return value is a string
9216: to add into arguments list of a uri
9217: - 'input' - in which case the return value is a HTML
9218: <form> <input> field of type hidden to
9219: preserve the value
9220: - a url - in which case the return value is the url with
9221: the neccesary cgi args added to preserve the
9222: inhibitmenu state
9223: - a ref to a url - no return value, but the string is
9224: updated to include the neccessary cgi
9225: args to preserve the inhibitmenu state
9226:
9227: =cut
9228:
9229: sub inhibit_menu_check {
9230: my ($arg) = @_;
9231: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9232: if ($arg eq 'input') {
9233: if ($env{'form.inhibitmenu'}) {
9234: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9235: } else {
9236: return
9237: }
9238: }
9239: if ($env{'form.inhibitmenu'}) {
9240: if (ref($arg)) {
9241: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9242: } elsif ($arg eq '') {
9243: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9244: } else {
9245: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9246: }
9247: }
9248: if (!ref($arg)) {
9249: return $arg;
9250: }
9251: }
9252:
1.251 albertel 9253: ###############################################
1.182 matthew 9254:
9255: =pod
9256:
1.549 albertel 9257: =back
9258:
9259: =head1 User Information Routines
9260:
9261: =over 4
9262:
1.405 albertel 9263: =item * &get_users_function()
1.182 matthew 9264:
9265: Used by &bodytag to determine the current users primary role.
9266: Returns either 'student','coordinator','admin', or 'author'.
9267:
9268: =cut
9269:
9270: ###############################################
9271: sub get_users_function {
1.815 tempelho 9272: my $function = 'norole';
1.818 tempelho 9273: if ($env{'request.role'}=~/^(st)/) {
9274: $function='student';
9275: }
1.907 raeburn 9276: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9277: $function='coordinator';
9278: }
1.258 albertel 9279: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9280: $function='admin';
9281: }
1.826 bisitz 9282: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9283: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9284: $function='author';
9285: }
9286: return $function;
1.54 www 9287: }
1.99 www 9288:
9289: ###############################################
9290:
1.233 raeburn 9291: =pod
9292:
1.821 raeburn 9293: =item * &show_course()
9294:
9295: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9296: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9297:
9298: Inputs:
9299: None
9300:
9301: Outputs:
9302: Scalar: 1 if 'Course' to be used, 0 otherwise.
9303:
9304: =cut
9305:
9306: ###############################################
9307: sub show_course {
9308: my $course = !$env{'user.adv'};
9309: if (!$env{'user.adv'}) {
9310: foreach my $env (keys(%env)) {
9311: next if ($env !~ m/^user\.priv\./);
9312: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9313: $course = 0;
9314: last;
9315: }
9316: }
9317: }
9318: return $course;
9319: }
9320:
9321: ###############################################
9322:
9323: =pod
9324:
1.542 raeburn 9325: =item * &check_user_status()
1.274 raeburn 9326:
9327: Determines current status of supplied role for a
9328: specific user. Roles can be active, previous or future.
9329:
9330: Inputs:
9331: user's domain, user's username, course's domain,
1.375 raeburn 9332: course's number, optional section ID.
1.274 raeburn 9333:
9334: Outputs:
9335: role status: active, previous or future.
9336:
9337: =cut
9338:
9339: sub check_user_status {
1.412 raeburn 9340: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9341: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9342: my @uroles = keys(%userinfo);
1.274 raeburn 9343: my $srchstr;
9344: my $active_chk = 'none';
1.412 raeburn 9345: my $now = time;
1.274 raeburn 9346: if (@uroles > 0) {
1.908 raeburn 9347: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9348: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9349: } else {
1.412 raeburn 9350: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9351: }
9352: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9353: my $role_end = 0;
9354: my $role_start = 0;
9355: $active_chk = 'active';
1.412 raeburn 9356: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9357: $role_end = $1;
9358: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9359: $role_start = $1;
1.274 raeburn 9360: }
9361: }
9362: if ($role_start > 0) {
1.412 raeburn 9363: if ($now < $role_start) {
1.274 raeburn 9364: $active_chk = 'future';
9365: }
9366: }
9367: if ($role_end > 0) {
1.412 raeburn 9368: if ($now > $role_end) {
1.274 raeburn 9369: $active_chk = 'previous';
9370: }
9371: }
9372: }
9373: }
9374: return $active_chk;
9375: }
9376:
9377: ###############################################
9378:
9379: =pod
9380:
1.405 albertel 9381: =item * &get_sections()
1.233 raeburn 9382:
9383: Determines all the sections for a course including
9384: sections with students and sections containing other roles.
1.419 raeburn 9385: Incoming parameters:
9386:
9387: 1. domain
9388: 2. course number
9389: 3. reference to array containing roles for which sections should
9390: be gathered (optional).
9391: 4. reference to array containing status types for which sections
9392: should be gathered (optional).
9393:
9394: If the third argument is undefined, sections are gathered for any role.
9395: If the fourth argument is undefined, sections are gathered for any status.
9396: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9397:
1.374 raeburn 9398: Returns section hash (keys are section IDs, values are
9399: number of users in each section), subject to the
1.419 raeburn 9400: optional roles filter, optional status filter
1.233 raeburn 9401:
9402: =cut
9403:
9404: ###############################################
9405: sub get_sections {
1.419 raeburn 9406: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9407: if (!defined($cdom) || !defined($cnum)) {
9408: my $cid = $env{'request.course.id'};
9409:
9410: return if (!defined($cid));
9411:
9412: $cdom = $env{'course.'.$cid.'.domain'};
9413: $cnum = $env{'course.'.$cid.'.num'};
9414: }
9415:
9416: my %sectioncount;
1.419 raeburn 9417: my $now = time;
1.240 albertel 9418:
1.1118 raeburn 9419: my $check_students = 1;
9420: my $only_students = 0;
9421: if (ref($possible_roles) eq 'ARRAY') {
9422: if (grep(/^st$/,@{$possible_roles})) {
9423: if (@{$possible_roles} == 1) {
9424: $only_students = 1;
9425: }
9426: } else {
9427: $check_students = 0;
9428: }
9429: }
9430:
9431: if ($check_students) {
1.276 albertel 9432: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9433: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9434: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9435: my $start_index = &Apache::loncoursedata::CL_START();
9436: my $end_index = &Apache::loncoursedata::CL_END();
9437: my $status;
1.366 albertel 9438: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9439: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9440: $data->[$status_index],
9441: $data->[$start_index],
9442: $data->[$end_index]);
9443: if ($stu_status eq 'Active') {
9444: $status = 'active';
9445: } elsif ($end < $now) {
9446: $status = 'previous';
9447: } elsif ($start > $now) {
9448: $status = 'future';
9449: }
9450: if ($section ne '-1' && $section !~ /^\s*$/) {
9451: if ((!defined($possible_status)) || (($status ne '') &&
9452: (grep/^\Q$status\E$/,@{$possible_status}))) {
9453: $sectioncount{$section}++;
9454: }
1.240 albertel 9455: }
9456: }
9457: }
1.1118 raeburn 9458: if ($only_students) {
9459: return %sectioncount;
9460: }
1.240 albertel 9461: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9462: foreach my $user (sort(keys(%courseroles))) {
9463: if ($user !~ /^(\w{2})/) { next; }
9464: my ($role) = ($user =~ /^(\w{2})/);
9465: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9466: my ($section,$status);
1.240 albertel 9467: if ($role eq 'cr' &&
9468: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9469: $section=$1;
9470: }
9471: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9472: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9473: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9474: if ($end == -1 && $start == -1) {
9475: next; #deleted role
9476: }
9477: if (!defined($possible_status)) {
9478: $sectioncount{$section}++;
9479: } else {
9480: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9481: $status = 'active';
9482: } elsif ($end < $now) {
9483: $status = 'future';
9484: } elsif ($start > $now) {
9485: $status = 'previous';
9486: }
9487: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9488: $sectioncount{$section}++;
9489: }
9490: }
1.233 raeburn 9491: }
1.366 albertel 9492: return %sectioncount;
1.233 raeburn 9493: }
9494:
1.274 raeburn 9495: ###############################################
1.294 raeburn 9496:
9497: =pod
1.405 albertel 9498:
9499: =item * &get_course_users()
9500:
1.275 raeburn 9501: Retrieves usernames:domains for users in the specified course
9502: with specific role(s), and access status.
9503:
9504: Incoming parameters:
1.277 albertel 9505: 1. course domain
9506: 2. course number
9507: 3. access status: users must have - either active,
1.275 raeburn 9508: previous, future, or all.
1.277 albertel 9509: 4. reference to array of permissible roles
1.288 raeburn 9510: 5. reference to array of section restrictions (optional)
9511: 6. reference to results object (hash of hashes).
9512: 7. reference to optional userdata hash
1.609 raeburn 9513: 8. reference to optional statushash
1.630 raeburn 9514: 9. flag if privileged users (except those set to unhide in
9515: course settings) should be excluded
1.609 raeburn 9516: Keys of top level results hash are roles.
1.275 raeburn 9517: Keys of inner hashes are username:domain, with
9518: values set to access type.
1.288 raeburn 9519: Optional userdata hash returns an array with arguments in the
9520: same order as loncoursedata::get_classlist() for student data.
9521:
1.609 raeburn 9522: Optional statushash returns
9523:
1.288 raeburn 9524: Entries for end, start, section and status are blank because
9525: of the possibility of multiple values for non-student roles.
9526:
1.275 raeburn 9527: =cut
1.405 albertel 9528:
1.275 raeburn 9529: ###############################################
1.405 albertel 9530:
1.275 raeburn 9531: sub get_course_users {
1.630 raeburn 9532: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9533: my %idx = ();
1.419 raeburn 9534: my %seclists;
1.288 raeburn 9535:
9536: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9537: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9538: $idx{end} = &Apache::loncoursedata::CL_END();
9539: $idx{start} = &Apache::loncoursedata::CL_START();
9540: $idx{id} = &Apache::loncoursedata::CL_ID();
9541: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9542: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9543: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9544:
1.290 albertel 9545: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9546: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9547: my $now = time;
1.277 albertel 9548: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9549: my $match = 0;
1.412 raeburn 9550: my $secmatch = 0;
1.419 raeburn 9551: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9552: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9553: if ($section eq '') {
9554: $section = 'none';
9555: }
1.291 albertel 9556: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9557: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9558: $secmatch = 1;
9559: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9560: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9561: $secmatch = 1;
9562: }
9563: } else {
1.419 raeburn 9564: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9565: $secmatch = 1;
9566: }
1.290 albertel 9567: }
1.412 raeburn 9568: if (!$secmatch) {
9569: next;
9570: }
1.419 raeburn 9571: }
1.275 raeburn 9572: if (defined($$types{'active'})) {
1.288 raeburn 9573: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9574: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9575: $match = 1;
1.275 raeburn 9576: }
9577: }
9578: if (defined($$types{'previous'})) {
1.609 raeburn 9579: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9580: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9581: $match = 1;
1.275 raeburn 9582: }
9583: }
9584: if (defined($$types{'future'})) {
1.609 raeburn 9585: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9586: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9587: $match = 1;
1.275 raeburn 9588: }
9589: }
1.609 raeburn 9590: if ($match) {
9591: push(@{$seclists{$student}},$section);
9592: if (ref($userdata) eq 'HASH') {
9593: $$userdata{$student} = $$classlist{$student};
9594: }
9595: if (ref($statushash) eq 'HASH') {
9596: $statushash->{$student}{'st'}{$section} = $status;
9597: }
1.288 raeburn 9598: }
1.275 raeburn 9599: }
9600: }
1.412 raeburn 9601: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9602: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9603: my $now = time;
1.609 raeburn 9604: my %displaystatus = ( previous => 'Expired',
9605: active => 'Active',
9606: future => 'Future',
9607: );
1.1121 raeburn 9608: my (%nothide,@possdoms);
1.630 raeburn 9609: if ($hidepriv) {
9610: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9611: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9612: if ($user !~ /:/) {
9613: $nothide{join(':',split(/[\@]/,$user))}=1;
9614: } else {
9615: $nothide{$user} = 1;
9616: }
9617: }
1.1121 raeburn 9618: my @possdoms = ($cdom);
9619: if ($coursehash{'checkforpriv'}) {
9620: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9621: }
1.630 raeburn 9622: }
1.439 raeburn 9623: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9624: my $match = 0;
1.412 raeburn 9625: my $secmatch = 0;
1.439 raeburn 9626: my $status;
1.412 raeburn 9627: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9628: $user =~ s/:$//;
1.439 raeburn 9629: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9630: if ($end == -1 || $start == -1) {
9631: next;
9632: }
9633: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9634: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9635: my ($uname,$udom) = split(/:/,$user);
9636: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9637: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9638: $secmatch = 1;
9639: } elsif ($usec eq '') {
1.420 albertel 9640: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9641: $secmatch = 1;
9642: }
9643: } else {
9644: if (grep(/^\Q$usec\E$/,@{$sections})) {
9645: $secmatch = 1;
9646: }
9647: }
9648: if (!$secmatch) {
9649: next;
9650: }
1.288 raeburn 9651: }
1.419 raeburn 9652: if ($usec eq '') {
9653: $usec = 'none';
9654: }
1.275 raeburn 9655: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9656: if ($hidepriv) {
1.1121 raeburn 9657: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9658: (!$nothide{$uname.':'.$udom})) {
9659: next;
9660: }
9661: }
1.503 raeburn 9662: if ($end > 0 && $end < $now) {
1.439 raeburn 9663: $status = 'previous';
9664: } elsif ($start > $now) {
9665: $status = 'future';
9666: } else {
9667: $status = 'active';
9668: }
1.277 albertel 9669: foreach my $type (keys(%{$types})) {
1.275 raeburn 9670: if ($status eq $type) {
1.420 albertel 9671: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9672: push(@{$$users{$role}{$user}},$type);
9673: }
1.288 raeburn 9674: $match = 1;
9675: }
9676: }
1.419 raeburn 9677: if (($match) && (ref($userdata) eq 'HASH')) {
9678: if (!exists($$userdata{$uname.':'.$udom})) {
9679: &get_user_info($udom,$uname,\%idx,$userdata);
9680: }
1.420 albertel 9681: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9682: push(@{$seclists{$uname.':'.$udom}},$usec);
9683: }
1.609 raeburn 9684: if (ref($statushash) eq 'HASH') {
9685: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9686: }
1.275 raeburn 9687: }
9688: }
9689: }
9690: }
1.290 albertel 9691: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9692: if ((defined($cdom)) && (defined($cnum))) {
9693: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9694: if ( defined($csettings{'internal.courseowner'}) ) {
9695: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9696: next if ($owner eq '');
9697: my ($ownername,$ownerdom);
9698: if ($owner =~ /^([^:]+):([^:]+)$/) {
9699: $ownername = $1;
9700: $ownerdom = $2;
9701: } else {
9702: $ownername = $owner;
9703: $ownerdom = $cdom;
9704: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9705: }
9706: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9707: if (defined($userdata) &&
1.609 raeburn 9708: !exists($$userdata{$owner})) {
9709: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9710: if (!grep(/^none$/,@{$seclists{$owner}})) {
9711: push(@{$seclists{$owner}},'none');
9712: }
9713: if (ref($statushash) eq 'HASH') {
9714: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9715: }
1.290 albertel 9716: }
1.279 raeburn 9717: }
9718: }
9719: }
1.419 raeburn 9720: foreach my $user (keys(%seclists)) {
9721: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9722: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9723: }
1.275 raeburn 9724: }
9725: return;
9726: }
9727:
1.288 raeburn 9728: sub get_user_info {
9729: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9730: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9731: &plainname($uname,$udom,'lastname');
1.291 albertel 9732: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9733: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9734: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9735: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9736: return;
9737: }
1.275 raeburn 9738:
1.472 raeburn 9739: ###############################################
9740:
9741: =pod
9742:
9743: =item * &get_user_quota()
9744:
1.1134 raeburn 9745: Retrieves quota assigned for storage of user files.
9746: Default is to report quota for portfolio files.
1.472 raeburn 9747:
9748: Incoming parameters:
9749: 1. user's username
9750: 2. user's domain
1.1134 raeburn 9751: 3. quota name - portfolio, author, or course
1.1136 raeburn 9752: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 9753: 4. crstype - official, unofficial, textbook, placement or community,
9754: if quota name is course
1.472 raeburn 9755:
9756: Returns:
1.1163 raeburn 9757: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9758: 2. (Optional) Type of setting: custom or default
9759: (individually assigned or default for user's
9760: institutional status).
9761: 3. (Optional) - User's institutional status (e.g., faculty, staff
9762: or student - types as defined in localenroll::inst_usertypes
9763: for user's domain, which determines default quota for user.
9764: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9765:
9766: If a value has been stored in the user's environment,
1.536 raeburn 9767: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9768: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9769:
9770: =cut
9771:
9772: ###############################################
9773:
9774:
9775: sub get_user_quota {
1.1136 raeburn 9776: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9777: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9778: if (!defined($udom)) {
9779: $udom = $env{'user.domain'};
9780: }
9781: if (!defined($uname)) {
9782: $uname = $env{'user.name'};
9783: }
9784: if (($udom eq '' || $uname eq '') ||
9785: ($udom eq 'public') && ($uname eq 'public')) {
9786: $quota = 0;
1.536 raeburn 9787: $quotatype = 'default';
9788: $defquota = 0;
1.472 raeburn 9789: } else {
1.536 raeburn 9790: my $inststatus;
1.1134 raeburn 9791: if ($quotaname eq 'course') {
9792: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9793: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9794: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9795: } else {
9796: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9797: $quota = $cenv{'internal.uploadquota'};
9798: }
1.536 raeburn 9799: } else {
1.1134 raeburn 9800: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9801: if ($quotaname eq 'author') {
9802: $quota = $env{'environment.authorquota'};
9803: } else {
9804: $quota = $env{'environment.portfolioquota'};
9805: }
9806: $inststatus = $env{'environment.inststatus'};
9807: } else {
9808: my %userenv =
9809: &Apache::lonnet::get('environment',['portfolioquota',
9810: 'authorquota','inststatus'],$udom,$uname);
9811: my ($tmp) = keys(%userenv);
9812: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9813: if ($quotaname eq 'author') {
9814: $quota = $userenv{'authorquota'};
9815: } else {
9816: $quota = $userenv{'portfolioquota'};
9817: }
9818: $inststatus = $userenv{'inststatus'};
9819: } else {
9820: undef(%userenv);
9821: }
9822: }
9823: }
9824: if ($quota eq '' || wantarray) {
9825: if ($quotaname eq 'course') {
9826: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 9827: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 9828: ($crstype eq 'community') || ($crstype eq 'textbook') ||
9829: ($crstype eq 'placement')) {
1.1136 raeburn 9830: $defquota = $domdefs{$crstype.'quota'};
9831: }
9832: if ($defquota eq '') {
9833: $defquota = 500;
9834: }
1.1134 raeburn 9835: } else {
9836: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9837: }
9838: if ($quota eq '') {
9839: $quota = $defquota;
9840: $quotatype = 'default';
9841: } else {
9842: $quotatype = 'custom';
9843: }
1.472 raeburn 9844: }
9845: }
1.536 raeburn 9846: if (wantarray) {
9847: return ($quota,$quotatype,$settingstatus,$defquota);
9848: } else {
9849: return $quota;
9850: }
1.472 raeburn 9851: }
9852:
9853: ###############################################
9854:
9855: =pod
9856:
9857: =item * &default_quota()
9858:
1.536 raeburn 9859: Retrieves default quota assigned for storage of user portfolio files,
9860: given an (optional) user's institutional status.
1.472 raeburn 9861:
9862: Incoming parameters:
1.1142 raeburn 9863:
1.472 raeburn 9864: 1. domain
1.536 raeburn 9865: 2. (Optional) institutional status(es). This is a : separated list of
9866: status types (e.g., faculty, staff, student etc.)
9867: which apply to the user for whom the default is being retrieved.
9868: If the institutional status string in undefined, the domain
1.1134 raeburn 9869: default quota will be returned.
9870: 3. quota name - portfolio, author, or course
9871: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9872:
9873: Returns:
1.1142 raeburn 9874:
1.1163 raeburn 9875: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9876: 2. (Optional) institutional type which determined the value of the
9877: default quota.
1.472 raeburn 9878:
9879: If a value has been stored in the domain's configuration db,
9880: it will return that, otherwise it returns 20 (for backwards
9881: compatibility with domains which have not set up a configuration
1.1163 raeburn 9882: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9883:
1.536 raeburn 9884: If the user's status includes multiple types (e.g., staff and student),
9885: the largest default quota which applies to the user determines the
9886: default quota returned.
9887:
1.472 raeburn 9888: =cut
9889:
9890: ###############################################
9891:
9892:
9893: sub default_quota {
1.1134 raeburn 9894: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9895: my ($defquota,$settingstatus);
9896: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9897: ['quotas'],$udom);
1.1134 raeburn 9898: my $key = 'defaultquota';
9899: if ($quotaname eq 'author') {
9900: $key = 'authorquota';
9901: }
1.622 raeburn 9902: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9903: if ($inststatus ne '') {
1.765 raeburn 9904: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9905: foreach my $item (@statuses) {
1.1134 raeburn 9906: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9907: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9908: if ($defquota eq '') {
1.1134 raeburn 9909: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9910: $settingstatus = $item;
1.1134 raeburn 9911: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9912: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9913: $settingstatus = $item;
9914: }
9915: }
1.1134 raeburn 9916: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9917: if ($quotahash{'quotas'}{$item} ne '') {
9918: if ($defquota eq '') {
9919: $defquota = $quotahash{'quotas'}{$item};
9920: $settingstatus = $item;
9921: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9922: $defquota = $quotahash{'quotas'}{$item};
9923: $settingstatus = $item;
9924: }
1.536 raeburn 9925: }
9926: }
9927: }
9928: }
9929: if ($defquota eq '') {
1.1134 raeburn 9930: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9931: $defquota = $quotahash{'quotas'}{$key}{'default'};
9932: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9933: $defquota = $quotahash{'quotas'}{'default'};
9934: }
1.536 raeburn 9935: $settingstatus = 'default';
1.1139 raeburn 9936: if ($defquota eq '') {
9937: if ($quotaname eq 'author') {
9938: $defquota = 500;
9939: }
9940: }
1.536 raeburn 9941: }
9942: } else {
9943: $settingstatus = 'default';
1.1134 raeburn 9944: if ($quotaname eq 'author') {
9945: $defquota = 500;
9946: } else {
9947: $defquota = 20;
9948: }
1.536 raeburn 9949: }
9950: if (wantarray) {
9951: return ($defquota,$settingstatus);
1.472 raeburn 9952: } else {
1.536 raeburn 9953: return $defquota;
1.472 raeburn 9954: }
9955: }
9956:
1.1135 raeburn 9957: ###############################################
9958:
9959: =pod
9960:
1.1136 raeburn 9961: =item * &excess_filesize_warning()
1.1135 raeburn 9962:
9963: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 9964: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 9965: space to be exceeded.
1.1136 raeburn 9966:
9967: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 9968: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 9969:
1.1165 raeburn 9970: Inputs: 7
1.1136 raeburn 9971: 1. username or coursenum
1.1135 raeburn 9972: 2. domain
1.1136 raeburn 9973: 3. context ('author' or 'course')
1.1135 raeburn 9974: 4. filename of file for which action is being requested
9975: 5. filesize (kB) of file
9976: 6. action being taken: copy or upload.
1.1237 raeburn 9977: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 9978:
9979: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 9980: otherwise return null.
9981:
9982: =back
1.1135 raeburn 9983:
9984: =cut
9985:
1.1136 raeburn 9986: sub excess_filesize_warning {
1.1165 raeburn 9987: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 9988: my $current_disk_usage = 0;
1.1165 raeburn 9989: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 9990: if ($context eq 'author') {
9991: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9992: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9993: } else {
9994: foreach my $subdir ('docs','supplemental') {
9995: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9996: }
9997: }
1.1135 raeburn 9998: $disk_quota = int($disk_quota * 1000);
9999: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10000: return '<p class="LC_warning">'.
1.1135 raeburn 10001: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10002: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10003: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10004: $disk_quota,$current_disk_usage).
10005: '</p>';
10006: }
10007: return;
10008: }
10009:
10010: ###############################################
10011:
10012:
1.1136 raeburn 10013:
10014:
1.384 raeburn 10015: sub get_secgrprole_info {
10016: my ($cdom,$cnum,$needroles,$type) = @_;
10017: my %sections_count = &get_sections($cdom,$cnum);
10018: my @sections = (sort {$a <=> $b} keys(%sections_count));
10019: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10020: my @groups = sort(keys(%curr_groups));
10021: my $allroles = [];
10022: my $rolehash;
10023: my $accesshash = {
10024: active => 'Currently has access',
10025: future => 'Will have future access',
10026: previous => 'Previously had access',
10027: };
10028: if ($needroles) {
10029: $rolehash = {'all' => 'all'};
1.385 albertel 10030: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10031: if (&Apache::lonnet::error(%user_roles)) {
10032: undef(%user_roles);
10033: }
10034: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10035: my ($role)=split(/\:/,$item,2);
10036: if ($role eq 'cr') { next; }
10037: if ($role =~ /^cr/) {
10038: $$rolehash{$role} = (split('/',$role))[3];
10039: } else {
10040: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10041: }
10042: }
10043: foreach my $key (sort(keys(%{$rolehash}))) {
10044: push(@{$allroles},$key);
10045: }
10046: push (@{$allroles},'st');
10047: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10048: }
10049: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10050: }
10051:
1.555 raeburn 10052: sub user_picker {
1.1279 raeburn 10053: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10054: my $currdom = $dom;
1.1253 raeburn 10055: my @alldoms = &Apache::lonnet::all_domains();
10056: if (@alldoms == 1) {
10057: my %domsrch = &Apache::lonnet::get_dom('configuration',
10058: ['directorysrch'],$alldoms[0]);
10059: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10060: my $showdom = $domdesc;
10061: if ($showdom eq '') {
10062: $showdom = $dom;
10063: }
10064: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10065: if ((!$domsrch{'directorysrch'}{'available'}) &&
10066: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10067: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10068: }
10069: }
10070: }
1.555 raeburn 10071: my %curr_selected = (
10072: srchin => 'dom',
1.580 raeburn 10073: srchby => 'lastname',
1.555 raeburn 10074: );
10075: my $srchterm;
1.625 raeburn 10076: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10077: if ($srch->{'srchby'} ne '') {
10078: $curr_selected{'srchby'} = $srch->{'srchby'};
10079: }
10080: if ($srch->{'srchin'} ne '') {
10081: $curr_selected{'srchin'} = $srch->{'srchin'};
10082: }
10083: if ($srch->{'srchtype'} ne '') {
10084: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10085: }
10086: if ($srch->{'srchdomain'} ne '') {
10087: $currdom = $srch->{'srchdomain'};
10088: }
10089: $srchterm = $srch->{'srchterm'};
10090: }
1.1222 damieng 10091: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10092: 'usr' => 'Search criteria',
1.563 raeburn 10093: 'doma' => 'Domain/institution to search',
1.558 albertel 10094: 'uname' => 'username',
10095: 'lastname' => 'last name',
1.555 raeburn 10096: 'lastfirst' => 'last name, first name',
1.558 albertel 10097: 'crs' => 'in this course',
1.576 raeburn 10098: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10099: 'alc' => 'all LON-CAPA',
1.573 raeburn 10100: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10101: 'exact' => 'is',
10102: 'contains' => 'contains',
1.569 raeburn 10103: 'begins' => 'begins with',
1.1222 damieng 10104: );
10105: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10106: 'youm' => "You must include some text to search for.",
10107: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10108: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10109: 'yomc' => "You must choose a domain when using an institutional directory search.",
10110: 'ymcd' => "You must choose a domain when using a domain search.",
10111: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10112: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10113: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10114: );
1.1222 damieng 10115: &html_escape(\%html_lt);
10116: &js_escape(\%js_lt);
1.1255 raeburn 10117: my $domform;
1.1277 raeburn 10118: my $allow_blank = 1;
1.1255 raeburn 10119: if ($fixeddom) {
1.1277 raeburn 10120: $allow_blank = 0;
10121: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10122: } else {
1.1277 raeburn 10123: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1255 raeburn 10124: }
1.563 raeburn 10125: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10126:
10127: my @srchins = ('crs','dom','alc','instd');
10128:
10129: foreach my $option (@srchins) {
10130: # FIXME 'alc' option unavailable until
10131: # loncreateuser::print_user_query_page()
10132: # has been completed.
10133: next if ($option eq 'alc');
1.880 raeburn 10134: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10135: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10136: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10137: if ($curr_selected{'srchin'} eq $option) {
10138: $srchinsel .= '
1.1222 damieng 10139: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10140: } else {
10141: $srchinsel .= '
1.1222 damieng 10142: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10143: }
1.555 raeburn 10144: }
1.563 raeburn 10145: $srchinsel .= "\n </select>\n";
1.555 raeburn 10146:
10147: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10148: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10149: if ($curr_selected{'srchby'} eq $option) {
10150: $srchbysel .= '
1.1222 damieng 10151: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10152: } else {
10153: $srchbysel .= '
1.1222 damieng 10154: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10155: }
10156: }
10157: $srchbysel .= "\n </select>\n";
10158:
10159: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10160: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10161: if ($curr_selected{'srchtype'} eq $option) {
10162: $srchtypesel .= '
1.1222 damieng 10163: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10164: } else {
10165: $srchtypesel .= '
1.1222 damieng 10166: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10167: }
10168: }
10169: $srchtypesel .= "\n </select>\n";
10170:
1.558 albertel 10171: my ($newuserscript,$new_user_create);
1.994 raeburn 10172: my $context_dom = $env{'request.role.domain'};
10173: if ($context eq 'requestcrs') {
10174: if ($env{'form.coursedom'} ne '') {
10175: $context_dom = $env{'form.coursedom'};
10176: }
10177: }
1.556 raeburn 10178: if ($forcenewuser) {
1.576 raeburn 10179: if (ref($srch) eq 'HASH') {
1.994 raeburn 10180: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10181: if ($cancreate) {
10182: $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>';
10183: } else {
1.799 bisitz 10184: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10185: my %usertypetext = (
10186: official => 'institutional',
10187: unofficial => 'non-institutional',
10188: );
1.799 bisitz 10189: $new_user_create = '<p class="LC_warning">'
10190: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10191: .' '
10192: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10193: ,'<a href="'.$helplink.'">','</a>')
10194: .'</p><br />';
1.627 raeburn 10195: }
1.576 raeburn 10196: }
10197: }
10198:
1.556 raeburn 10199: $newuserscript = <<"ENDSCRIPT";
10200:
1.570 raeburn 10201: function setSearch(createnew,callingForm) {
1.556 raeburn 10202: if (createnew == 1) {
1.570 raeburn 10203: for (var i=0; i<callingForm.srchby.length; i++) {
10204: if (callingForm.srchby.options[i].value == 'uname') {
10205: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10206: }
10207: }
1.570 raeburn 10208: for (var i=0; i<callingForm.srchin.length; i++) {
10209: if ( callingForm.srchin.options[i].value == 'dom') {
10210: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10211: }
10212: }
1.570 raeburn 10213: for (var i=0; i<callingForm.srchtype.length; i++) {
10214: if (callingForm.srchtype.options[i].value == 'exact') {
10215: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10216: }
10217: }
1.570 raeburn 10218: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10219: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10220: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10221: }
10222: }
10223: }
10224: }
10225: ENDSCRIPT
1.558 albertel 10226:
1.556 raeburn 10227: }
10228:
1.555 raeburn 10229: my $output = <<"END_BLOCK";
1.556 raeburn 10230: <script type="text/javascript">
1.824 bisitz 10231: // <![CDATA[
1.570 raeburn 10232: function validateEntry(callingForm) {
1.558 albertel 10233:
1.556 raeburn 10234: var checkok = 1;
1.558 albertel 10235: var srchin;
1.570 raeburn 10236: for (var i=0; i<callingForm.srchin.length; i++) {
10237: if ( callingForm.srchin[i].checked ) {
10238: srchin = callingForm.srchin[i].value;
1.558 albertel 10239: }
10240: }
10241:
1.570 raeburn 10242: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10243: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10244: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10245: var srchterm = callingForm.srchterm.value;
10246: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10247: var msg = "";
10248:
10249: if (srchterm == "") {
10250: checkok = 0;
1.1222 damieng 10251: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10252: }
10253:
1.569 raeburn 10254: if (srchtype== 'begins') {
10255: if (srchterm.length < 2) {
10256: checkok = 0;
1.1222 damieng 10257: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10258: }
10259: }
10260:
1.556 raeburn 10261: if (srchtype== 'contains') {
10262: if (srchterm.length < 3) {
10263: checkok = 0;
1.1222 damieng 10264: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10265: }
10266: }
10267: if (srchin == 'instd') {
10268: if (srchdomain == '') {
10269: checkok = 0;
1.1222 damieng 10270: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10271: }
10272: }
10273: if (srchin == 'dom') {
10274: if (srchdomain == '') {
10275: checkok = 0;
1.1222 damieng 10276: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10277: }
10278: }
10279: if (srchby == 'lastfirst') {
10280: if (srchterm.indexOf(",") == -1) {
10281: checkok = 0;
1.1222 damieng 10282: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10283: }
10284: if (srchterm.indexOf(",") == srchterm.length -1) {
10285: checkok = 0;
1.1222 damieng 10286: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10287: }
10288: }
10289: if (checkok == 0) {
1.1222 damieng 10290: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10291: return;
10292: }
10293: if (checkok == 1) {
1.570 raeburn 10294: callingForm.submit();
1.556 raeburn 10295: }
10296: }
10297:
10298: $newuserscript
10299:
1.824 bisitz 10300: // ]]>
1.556 raeburn 10301: </script>
1.558 albertel 10302:
10303: $new_user_create
10304:
1.555 raeburn 10305: END_BLOCK
1.558 albertel 10306:
1.876 raeburn 10307: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10308: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10309: $domform.
10310: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10311: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10312: $srchbysel.
10313: $srchtypesel.
10314: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10315: $srchinsel.
10316: &Apache::lonhtmlcommon::row_closure(1).
10317: &Apache::lonhtmlcommon::end_pick_box().
10318: '<br />';
1.1253 raeburn 10319: return ($output,1);
1.555 raeburn 10320: }
10321:
1.612 raeburn 10322: sub user_rule_check {
1.615 raeburn 10323: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10324: my ($response,%inst_response);
1.612 raeburn 10325: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10326: if (keys(%{$usershash}) > 1) {
10327: my (%by_username,%by_id,%userdoms);
10328: my $checkid;
10329: if (ref($checks) eq 'HASH') {
10330: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10331: $checkid = 1;
10332: }
10333: }
10334: foreach my $user (keys(%{$usershash})) {
10335: my ($uname,$udom) = split(/:/,$user);
10336: if ($checkid) {
10337: if (ref($usershash->{$user}) eq 'HASH') {
10338: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10339: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10340: $userdoms{$udom} = 1;
1.1227 raeburn 10341: if (ref($inst_results) eq 'HASH') {
10342: $inst_results->{$uname.':'.$udom} = {};
10343: }
1.1226 raeburn 10344: }
10345: }
10346: } else {
10347: $by_username{$udom}{$uname} = 1;
10348: $userdoms{$udom} = 1;
1.1227 raeburn 10349: if (ref($inst_results) eq 'HASH') {
10350: $inst_results->{$uname.':'.$udom} = {};
10351: }
1.1226 raeburn 10352: }
10353: }
10354: foreach my $udom (keys(%userdoms)) {
10355: if (!$got_rules->{$udom}) {
10356: my %domconfig = &Apache::lonnet::get_dom('configuration',
10357: ['usercreation'],$udom);
10358: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10359: foreach my $item ('username','id') {
10360: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10361: $$curr_rules{$udom}{$item} =
10362: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10363: }
10364: }
10365: }
10366: $got_rules->{$udom} = 1;
10367: }
1.612 raeburn 10368: }
1.1226 raeburn 10369: if ($checkid) {
10370: foreach my $udom (keys(%by_id)) {
10371: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10372: if ($outcome eq 'ok') {
1.1227 raeburn 10373: foreach my $id (keys(%{$by_id{$udom}})) {
10374: my $uname = $by_id{$udom}{$id};
10375: $inst_response{$uname.':'.$udom} = $outcome;
10376: }
1.1226 raeburn 10377: if (ref($results) eq 'HASH') {
10378: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10379: if (exists($inst_response{$uname.':'.$udom})) {
10380: $inst_response{$uname.':'.$udom} = $outcome;
10381: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10382: }
1.1226 raeburn 10383: }
10384: }
10385: }
1.612 raeburn 10386: }
1.615 raeburn 10387: } else {
1.1226 raeburn 10388: foreach my $udom (keys(%by_username)) {
10389: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10390: if ($outcome eq 'ok') {
1.1227 raeburn 10391: foreach my $uname (keys(%{$by_username{$udom}})) {
10392: $inst_response{$uname.':'.$udom} = $outcome;
10393: }
1.1226 raeburn 10394: if (ref($results) eq 'HASH') {
10395: foreach my $uname (keys(%{$results})) {
10396: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10397: }
10398: }
10399: }
10400: }
1.612 raeburn 10401: }
1.1226 raeburn 10402: } elsif (keys(%{$usershash}) == 1) {
10403: my $user = (keys(%{$usershash}))[0];
10404: my ($uname,$udom) = split(/:/,$user);
10405: if (($udom ne '') && ($uname ne '')) {
10406: if (ref($usershash->{$user}) eq 'HASH') {
10407: if (ref($checks) eq 'HASH') {
10408: if (defined($checks->{'username'})) {
10409: ($inst_response{$user},%{$inst_results->{$user}}) =
10410: &Apache::lonnet::get_instuser($udom,$uname);
10411: } elsif (defined($checks->{'id'})) {
10412: if ($usershash->{$user}->{'id'} ne '') {
10413: ($inst_response{$user},%{$inst_results->{$user}}) =
10414: &Apache::lonnet::get_instuser($udom,undef,
10415: $usershash->{$user}->{'id'});
10416: } else {
10417: ($inst_response{$user},%{$inst_results->{$user}}) =
10418: &Apache::lonnet::get_instuser($udom,$uname);
10419: }
1.585 raeburn 10420: }
1.1226 raeburn 10421: } else {
10422: ($inst_response{$user},%{$inst_results->{$user}}) =
10423: &Apache::lonnet::get_instuser($udom,$uname);
10424: return;
10425: }
10426: if (!$got_rules->{$udom}) {
10427: my %domconfig = &Apache::lonnet::get_dom('configuration',
10428: ['usercreation'],$udom);
10429: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10430: foreach my $item ('username','id') {
10431: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10432: $$curr_rules{$udom}{$item} =
10433: $domconfig{'usercreation'}{$item.'_rule'};
10434: }
10435: }
10436: }
10437: $got_rules->{$udom} = 1;
1.585 raeburn 10438: }
10439: }
1.1226 raeburn 10440: } else {
10441: return;
10442: }
10443: } else {
10444: return;
10445: }
10446: foreach my $user (keys(%{$usershash})) {
10447: my ($uname,$udom) = split(/:/,$user);
10448: next if (($udom eq '') || ($uname eq ''));
10449: my $id;
1.1227 raeburn 10450: if (ref($inst_results) eq 'HASH') {
10451: if (ref($inst_results->{$user}) eq 'HASH') {
10452: $id = $inst_results->{$user}->{'id'};
10453: }
10454: }
10455: if ($id eq '') {
10456: if (ref($usershash->{$user})) {
10457: $id = $usershash->{$user}->{'id'};
10458: }
1.585 raeburn 10459: }
1.612 raeburn 10460: foreach my $item (keys(%{$checks})) {
10461: if (ref($$curr_rules{$udom}) eq 'HASH') {
10462: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10463: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10464: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10465: $$curr_rules{$udom}{$item});
1.612 raeburn 10466: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10467: if ($rule_check{$rule}) {
10468: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10469: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10470: if (ref($inst_results) eq 'HASH') {
10471: if (ref($inst_results->{$user}) eq 'HASH') {
10472: if (keys(%{$inst_results->{$user}}) == 0) {
10473: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10474: } elsif ($item eq 'id') {
10475: if ($inst_results->{$user}->{'id'} eq '') {
10476: $$alerts{$item}{$udom}{$uname} = 1;
10477: }
1.615 raeburn 10478: }
1.612 raeburn 10479: }
10480: }
1.615 raeburn 10481: }
10482: last;
1.585 raeburn 10483: }
10484: }
10485: }
10486: }
10487: }
10488: }
10489: }
10490: }
1.612 raeburn 10491: return;
10492: }
10493:
10494: sub user_rule_formats {
10495: my ($domain,$domdesc,$curr_rules,$check) = @_;
10496: my %text = (
10497: 'username' => 'Usernames',
10498: 'id' => 'IDs',
10499: );
10500: my $output;
10501: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10502: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10503: if (@{$ruleorder} > 0) {
1.1102 raeburn 10504: $output = '<br />'.
10505: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10506: '<span class="LC_cusr_emph">','</span>',$domdesc).
10507: ' <ul>';
1.612 raeburn 10508: foreach my $rule (@{$ruleorder}) {
10509: if (ref($curr_rules) eq 'ARRAY') {
10510: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10511: if (ref($rules->{$rule}) eq 'HASH') {
10512: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10513: $rules->{$rule}{'desc'}.'</li>';
10514: }
10515: }
10516: }
10517: }
10518: $output .= '</ul>';
10519: }
10520: }
10521: return $output;
10522: }
10523:
10524: sub instrule_disallow_msg {
1.615 raeburn 10525: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10526: my $response;
10527: my %text = (
10528: item => 'username',
10529: items => 'usernames',
10530: match => 'matches',
10531: do => 'does',
10532: action => 'a username',
10533: one => 'one',
10534: );
10535: if ($count > 1) {
10536: $text{'item'} = 'usernames';
10537: $text{'match'} ='match';
10538: $text{'do'} = 'do';
10539: $text{'action'} = 'usernames',
10540: $text{'one'} = 'ones';
10541: }
10542: if ($checkitem eq 'id') {
10543: $text{'items'} = 'IDs';
10544: $text{'item'} = 'ID';
10545: $text{'action'} = 'an ID';
1.615 raeburn 10546: if ($count > 1) {
10547: $text{'item'} = 'IDs';
10548: $text{'action'} = 'IDs';
10549: }
1.612 raeburn 10550: }
1.674 bisitz 10551: $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 10552: if ($mode eq 'upload') {
10553: if ($checkitem eq 'username') {
10554: $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'}.");
10555: } elsif ($checkitem eq 'id') {
1.674 bisitz 10556: $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 10557: }
1.669 raeburn 10558: } elsif ($mode eq 'selfcreate') {
10559: if ($checkitem eq 'id') {
10560: $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.");
10561: }
1.615 raeburn 10562: } else {
10563: if ($checkitem eq 'username') {
10564: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10565: } elsif ($checkitem eq 'id') {
10566: $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.");
10567: }
1.612 raeburn 10568: }
10569: return $response;
1.585 raeburn 10570: }
10571:
1.624 raeburn 10572: sub personal_data_fieldtitles {
10573: my %fieldtitles = &Apache::lonlocal::texthash (
10574: id => 'Student/Employee ID',
10575: permanentemail => 'E-mail address',
10576: lastname => 'Last Name',
10577: firstname => 'First Name',
10578: middlename => 'Middle Name',
10579: generation => 'Generation',
10580: gen => 'Generation',
1.765 raeburn 10581: inststatus => 'Affiliation',
1.624 raeburn 10582: );
10583: return %fieldtitles;
10584: }
10585:
1.642 raeburn 10586: sub sorted_inst_types {
10587: my ($dom) = @_;
1.1185 raeburn 10588: my ($usertypes,$order);
10589: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10590: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10591: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10592: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10593: } else {
10594: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10595: }
1.642 raeburn 10596: my $othertitle = &mt('All users');
10597: if ($env{'request.course.id'}) {
1.668 raeburn 10598: $othertitle = &mt('Any users');
1.642 raeburn 10599: }
10600: my @types;
10601: if (ref($order) eq 'ARRAY') {
10602: @types = @{$order};
10603: }
10604: if (@types == 0) {
10605: if (ref($usertypes) eq 'HASH') {
10606: @types = sort(keys(%{$usertypes}));
10607: }
10608: }
10609: if (keys(%{$usertypes}) > 0) {
10610: $othertitle = &mt('Other users');
10611: }
10612: return ($othertitle,$usertypes,\@types);
10613: }
10614:
1.645 raeburn 10615: sub get_institutional_codes {
10616: my ($settings,$allcourses,$LC_code) = @_;
10617: # Get complete list of course sections to update
10618: my @currsections = ();
10619: my @currxlists = ();
10620: my $coursecode = $$settings{'internal.coursecode'};
10621:
10622: if ($$settings{'internal.sectionnums'} ne '') {
10623: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10624: }
10625:
10626: if ($$settings{'internal.crosslistings'} ne '') {
10627: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10628: }
10629:
10630: if (@currxlists > 0) {
10631: foreach (@currxlists) {
10632: if (m/^([^:]+):(\w*)$/) {
10633: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 10634: push(@{$allcourses},$1);
1.645 raeburn 10635: $$LC_code{$1} = $2;
10636: }
10637: }
10638: }
10639: }
10640:
10641: if (@currsections > 0) {
10642: foreach (@currsections) {
10643: if (m/^(\w+):(\w*)$/) {
10644: my $sec = $coursecode.$1;
10645: my $lc_sec = $2;
10646: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 10647: push(@{$allcourses},$sec);
1.645 raeburn 10648: $$LC_code{$sec} = $lc_sec;
10649: }
10650: }
10651: }
10652: }
10653: return;
10654: }
10655:
1.971 raeburn 10656: sub get_standard_codeitems {
10657: return ('Year','Semester','Department','Number','Section');
10658: }
10659:
1.112 bowersj2 10660: =pod
10661:
1.780 raeburn 10662: =head1 Slot Helpers
10663:
10664: =over 4
10665:
10666: =item * sorted_slots()
10667:
1.1040 raeburn 10668: Sorts an array of slot names in order of an optional sort key,
10669: default sort is by slot start time (earliest first).
1.780 raeburn 10670:
10671: Inputs:
10672:
10673: =over 4
10674:
10675: slotsarr - Reference to array of unsorted slot names.
10676:
10677: slots - Reference to hash of hash, where outer hash keys are slot names.
10678:
1.1040 raeburn 10679: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10680:
1.549 albertel 10681: =back
10682:
1.780 raeburn 10683: Returns:
10684:
10685: =over 4
10686:
1.1040 raeburn 10687: sorted - An array of slot names sorted by a specified sort key
10688: (default sort key is start time of the slot).
1.780 raeburn 10689:
10690: =back
10691:
10692: =cut
10693:
10694:
10695: sub sorted_slots {
1.1040 raeburn 10696: my ($slotsarr,$slots,$sortkey) = @_;
10697: if ($sortkey eq '') {
10698: $sortkey = 'starttime';
10699: }
1.780 raeburn 10700: my @sorted;
10701: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10702: @sorted =
10703: sort {
10704: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10705: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10706: }
10707: if (ref($slots->{$a})) { return -1;}
10708: if (ref($slots->{$b})) { return 1;}
10709: return 0;
10710: } @{$slotsarr};
10711: }
10712: return @sorted;
10713: }
10714:
1.1040 raeburn 10715: =pod
10716:
10717: =item * get_future_slots()
10718:
10719: Inputs:
10720:
10721: =over 4
10722:
10723: cnum - course number
10724:
10725: cdom - course domain
10726:
10727: now - current UNIX time
10728:
10729: symb - optional symb
10730:
10731: =back
10732:
10733: Returns:
10734:
10735: =over 4
10736:
10737: sorted_reservable - ref to array of student_schedulable slots currently
10738: reservable, ordered by end date of reservation period.
10739:
10740: reservable_now - ref to hash of student_schedulable slots currently
10741: reservable.
10742:
10743: Keys in inner hash are:
10744: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10745: (b) endreserve: end date of reservation period.
10746: (c) uniqueperiod: start,end dates when slot is to be uniquely
10747: selected.
1.1040 raeburn 10748:
10749: sorted_future - ref to array of student_schedulable slots reservable in
10750: the future, ordered by start date of reservation period.
10751:
10752: future_reservable - ref to hash of student_schedulable slots reservable
10753: in the future.
10754:
10755: Keys in inner hash are:
10756: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10757: (b) startreserve: start date of reservation period.
10758: (c) uniqueperiod: start,end dates when slot is to be uniquely
10759: selected.
1.1040 raeburn 10760:
10761: =back
10762:
10763: =cut
10764:
10765: sub get_future_slots {
10766: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 10767: my $map;
10768: if ($symb) {
10769: ($map) = &Apache::lonnet::decode_symb($symb);
10770: }
1.1040 raeburn 10771: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10772: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10773: foreach my $slot (keys(%slots)) {
10774: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10775: if ($symb) {
1.1229 raeburn 10776: if ($slots{$slot}->{'symb'} ne '') {
10777: my $canuse;
10778: my %oksymbs;
10779: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
10780: map { $oksymbs{$_} = 1; } @slotsymbs;
10781: if ($oksymbs{$symb}) {
10782: $canuse = 1;
10783: } else {
10784: foreach my $item (@slotsymbs) {
10785: if ($item =~ /\.(page|sequence)$/) {
10786: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
10787: if (($map ne '') && ($map eq $sloturl)) {
10788: $canuse = 1;
10789: last;
10790: }
10791: }
10792: }
10793: }
10794: next unless ($canuse);
10795: }
1.1040 raeburn 10796: }
10797: if (($slots{$slot}->{'starttime'} > $now) &&
10798: ($slots{$slot}->{'endtime'} > $now)) {
10799: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10800: my $userallowed = 0;
10801: if ($slots{$slot}->{'allowedsections'}) {
10802: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10803: if (!defined($env{'request.role.sec'})
10804: && grep(/^No section assigned$/,@allowed_sec)) {
10805: $userallowed=1;
10806: } else {
10807: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10808: $userallowed=1;
10809: }
10810: }
10811: unless ($userallowed) {
10812: if (defined($env{'request.course.groups'})) {
10813: my @groups = split(/:/,$env{'request.course.groups'});
10814: foreach my $group (@groups) {
10815: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10816: $userallowed=1;
10817: last;
10818: }
10819: }
10820: }
10821: }
10822: }
10823: if ($slots{$slot}->{'allowedusers'}) {
10824: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10825: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10826: if (grep(/^\Q$user\E$/,@allowed_users)) {
10827: $userallowed = 1;
10828: }
10829: }
10830: next unless($userallowed);
10831: }
10832: my $startreserve = $slots{$slot}->{'startreserve'};
10833: my $endreserve = $slots{$slot}->{'endreserve'};
10834: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 10835: my $uniqueperiod;
10836: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10837: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10838: }
1.1040 raeburn 10839: if (($startreserve < $now) &&
10840: (!$endreserve || $endreserve > $now)) {
10841: my $lastres = $endreserve;
10842: if (!$lastres) {
10843: $lastres = $slots{$slot}->{'starttime'};
10844: }
10845: $reservable_now{$slot} = {
10846: symb => $symb,
1.1250 raeburn 10847: endreserve => $lastres,
10848: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10849: };
10850: } elsif (($startreserve > $now) &&
10851: (!$endreserve || $endreserve > $startreserve)) {
10852: $future_reservable{$slot} = {
10853: symb => $symb,
1.1250 raeburn 10854: startreserve => $startreserve,
10855: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10856: };
10857: }
10858: }
10859: }
10860: my @unsorted_reservable = keys(%reservable_now);
10861: if (@unsorted_reservable > 0) {
10862: @sorted_reservable =
10863: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10864: }
10865: my @unsorted_future = keys(%future_reservable);
10866: if (@unsorted_future > 0) {
10867: @sorted_future =
10868: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10869: }
10870: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10871: }
1.780 raeburn 10872:
10873: =pod
10874:
1.1057 foxr 10875: =back
10876:
1.549 albertel 10877: =head1 HTTP Helpers
10878:
10879: =over 4
10880:
1.648 raeburn 10881: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10882:
1.258 albertel 10883: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10884: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10885: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10886:
10887: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10888: $possible_names is an ref to an array of form element names. As an example:
10889: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10890: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10891:
10892: =cut
1.1 albertel 10893:
1.6 albertel 10894: sub get_unprocessed_cgi {
1.25 albertel 10895: my ($query,$possible_names)= @_;
1.26 matthew 10896: # $Apache::lonxml::debug=1;
1.356 albertel 10897: foreach my $pair (split(/&/,$query)) {
10898: my ($name, $value) = split(/=/,$pair);
1.369 www 10899: $name = &unescape($name);
1.25 albertel 10900: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10901: $value =~ tr/+/ /;
10902: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10903: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10904: }
1.16 harris41 10905: }
1.6 albertel 10906: }
10907:
1.112 bowersj2 10908: =pod
10909:
1.648 raeburn 10910: =item * &cacheheader()
1.112 bowersj2 10911:
10912: returns cache-controlling header code
10913:
10914: =cut
10915:
1.7 albertel 10916: sub cacheheader {
1.258 albertel 10917: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10918: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10919: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10920: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10921: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10922: return $output;
1.7 albertel 10923: }
10924:
1.112 bowersj2 10925: =pod
10926:
1.648 raeburn 10927: =item * &no_cache($r)
1.112 bowersj2 10928:
10929: specifies header code to not have cache
10930:
10931: =cut
10932:
1.9 albertel 10933: sub no_cache {
1.216 albertel 10934: my ($r) = @_;
10935: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10936: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10937: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10938: $r->no_cache(1);
10939: $r->header_out("Expires" => $date);
10940: $r->header_out("Pragma" => "no-cache");
1.123 www 10941: }
10942:
10943: sub content_type {
1.181 albertel 10944: my ($r,$type,$charset) = @_;
1.299 foxr 10945: if ($r) {
10946: # Note that printout.pl calls this with undef for $r.
10947: &no_cache($r);
10948: }
1.258 albertel 10949: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10950: unless ($charset) {
10951: $charset=&Apache::lonlocal::current_encoding;
10952: }
10953: if ($charset) { $type.='; charset='.$charset; }
10954: if ($r) {
10955: $r->content_type($type);
10956: } else {
10957: print("Content-type: $type\n\n");
10958: }
1.9 albertel 10959: }
1.25 albertel 10960:
1.112 bowersj2 10961: =pod
10962:
1.648 raeburn 10963: =item * &add_to_env($name,$value)
1.112 bowersj2 10964:
1.258 albertel 10965: adds $name to the %env hash with value
1.112 bowersj2 10966: $value, if $name already exists, the entry is converted to an array
10967: reference and $value is added to the array.
10968:
10969: =cut
10970:
1.25 albertel 10971: sub add_to_env {
10972: my ($name,$value)=@_;
1.258 albertel 10973: if (defined($env{$name})) {
10974: if (ref($env{$name})) {
1.25 albertel 10975: #already have multiple values
1.258 albertel 10976: push(@{ $env{$name} },$value);
1.25 albertel 10977: } else {
10978: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10979: my $first=$env{$name};
10980: undef($env{$name});
10981: push(@{ $env{$name} },$first,$value);
1.25 albertel 10982: }
10983: } else {
1.258 albertel 10984: $env{$name}=$value;
1.25 albertel 10985: }
1.31 albertel 10986: }
1.149 albertel 10987:
10988: =pod
10989:
1.648 raeburn 10990: =item * &get_env_multiple($name)
1.149 albertel 10991:
1.258 albertel 10992: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10993: values may be defined and end up as an array ref.
10994:
10995: returns an array of values
10996:
10997: =cut
10998:
10999: sub get_env_multiple {
11000: my ($name) = @_;
11001: my @values;
1.258 albertel 11002: if (defined($env{$name})) {
1.149 albertel 11003: # exists is it an array
1.258 albertel 11004: if (ref($env{$name})) {
11005: @values=@{ $env{$name} };
1.149 albertel 11006: } else {
1.258 albertel 11007: $values[0]=$env{$name};
1.149 albertel 11008: }
11009: }
11010: return(@values);
11011: }
11012:
1.1249 damieng 11013: # Looks at given dependencies, and returns something depending on the context.
11014: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11015: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11016: # For all other contexts, returns ($output, $counter, $numpathchg).
11017: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11018: # $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.
11019: # $numpathchg: integer with the number of cleaned up dependency paths.
11020: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11021: # \%mapping: hash reference clean path -> original path for all dependencies.
11022: # @param {string} actionurl - The path to the handler, indicative of the context.
11023: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11024: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11025: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11026: # @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)
11027: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11028: sub ask_for_embedded_content {
1.1249 damieng 11029: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11030: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11031: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11032: %currsubfile,%unused,$rem);
1.1071 raeburn 11033: my $counter = 0;
11034: my $numnew = 0;
1.987 raeburn 11035: my $numremref = 0;
11036: my $numinvalid = 0;
11037: my $numpathchg = 0;
11038: my $numexisting = 0;
1.1071 raeburn 11039: my $numunused = 0;
11040: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11041: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11042: my $heading = &mt('Upload embedded files');
11043: my $buttontext = &mt('Upload');
11044:
1.1249 damieng 11045: # fills these variables based on the context:
11046: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11047: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11048: if ($env{'request.course.id'}) {
1.1123 raeburn 11049: if ($actionurl eq '/adm/dependencies') {
11050: $navmap = Apache::lonnavmaps::navmap->new();
11051: }
11052: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11053: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11054: }
1.1123 raeburn 11055: if (($actionurl eq '/adm/portfolio') ||
11056: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11057: my $current_path='/';
11058: if ($env{'form.currentpath'}) {
11059: $current_path = $env{'form.currentpath'};
11060: }
11061: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11062: $udom = $cdom;
11063: $uname = $cnum;
1.984 raeburn 11064: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11065: } else {
11066: $udom = $env{'user.domain'};
11067: $uname = $env{'user.name'};
11068: $url = '/userfiles/portfolio';
11069: }
1.987 raeburn 11070: $toplevel = $url.'/';
1.984 raeburn 11071: $url .= $current_path;
11072: $getpropath = 1;
1.987 raeburn 11073: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11074: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11075: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11076: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11077: $toplevel = $url;
1.984 raeburn 11078: if ($rest ne '') {
1.987 raeburn 11079: $url .= $rest;
11080: }
11081: } elsif ($actionurl eq '/adm/coursedocs') {
11082: if (ref($args) eq 'HASH') {
1.1071 raeburn 11083: $url = $args->{'docs_url'};
11084: $toplevel = $url;
1.1084 raeburn 11085: if ($args->{'context'} eq 'paste') {
11086: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11087: ($path) =
11088: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11089: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11090: $fileloc =~ s{^/}{};
11091: }
1.1071 raeburn 11092: }
1.1084 raeburn 11093: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11094: if ($env{'request.course.id'} ne '') {
11095: if (ref($args) eq 'HASH') {
11096: $url = $args->{'docs_url'};
11097: $title = $args->{'docs_title'};
1.1126 raeburn 11098: $toplevel = $url;
11099: unless ($toplevel =~ m{^/}) {
11100: $toplevel = "/$url";
11101: }
1.1085 raeburn 11102: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11103: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11104: $path = $1;
11105: } else {
11106: ($path) =
11107: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11108: }
1.1195 raeburn 11109: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11110: $fileloc = $toplevel;
11111: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11112: my ($udom,$uname,$fname) =
11113: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11114: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11115: } else {
11116: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11117: }
1.1071 raeburn 11118: $fileloc =~ s{^/}{};
11119: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11120: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11121: }
1.987 raeburn 11122: }
1.1123 raeburn 11123: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11124: $udom = $cdom;
11125: $uname = $cnum;
11126: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11127: $toplevel = $url;
11128: $path = $url;
11129: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11130: $fileloc =~ s{^/}{};
1.987 raeburn 11131: }
1.1249 damieng 11132:
11133: # parses the dependency paths to get some info
11134: # fills $newfiles, $mapping, $subdependencies, $dependencies
11135: # $newfiles: hash URL -> 1 for new files or external URLs
11136: # (will be completed later)
11137: # $mapping:
11138: # for external URLs: external URL -> external URL
11139: # for relative paths: clean path -> original path
11140: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11141: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11142: foreach my $file (keys(%{$allfiles})) {
11143: my $embed_file;
11144: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11145: $embed_file = $1;
11146: } else {
11147: $embed_file = $file;
11148: }
1.1158 raeburn 11149: my ($absolutepath,$cleaned_file);
11150: if ($embed_file =~ m{^\w+://}) {
11151: $cleaned_file = $embed_file;
1.1147 raeburn 11152: $newfiles{$cleaned_file} = 1;
11153: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11154: } else {
1.1158 raeburn 11155: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11156: if ($embed_file =~ m{^/}) {
11157: $absolutepath = $embed_file;
11158: }
1.1147 raeburn 11159: if ($cleaned_file =~ m{/}) {
11160: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11161: $path = &check_for_traversal($path,$url,$toplevel);
11162: my $item = $fname;
11163: if ($path ne '') {
11164: $item = $path.'/'.$fname;
11165: $subdependencies{$path}{$fname} = 1;
11166: } else {
11167: $dependencies{$item} = 1;
11168: }
11169: if ($absolutepath) {
11170: $mapping{$item} = $absolutepath;
11171: } else {
11172: $mapping{$item} = $embed_file;
11173: }
11174: } else {
11175: $dependencies{$embed_file} = 1;
11176: if ($absolutepath) {
1.1147 raeburn 11177: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11178: } else {
1.1147 raeburn 11179: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11180: }
11181: }
1.984 raeburn 11182: }
11183: }
1.1249 damieng 11184:
11185: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11186: # and lists
11187: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11188: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11189: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11190: # the path had to be cleaned up
11191: # $existing: hash clean path -> 1 if the file exists
11192: # $numexisting: number of keys in $existing
11193: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11194: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11195: # dependency subdirectories that are
11196: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11197: my $dirptr = 16384;
1.984 raeburn 11198: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11199: $currsubfile{$path} = {};
1.1123 raeburn 11200: if (($actionurl eq '/adm/portfolio') ||
11201: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11202: my ($sublistref,$listerror) =
11203: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11204: if (ref($sublistref) eq 'ARRAY') {
11205: foreach my $line (@{$sublistref}) {
11206: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11207: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11208: }
1.984 raeburn 11209: }
1.987 raeburn 11210: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11211: if (opendir(my $dir,$url.'/'.$path)) {
11212: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11213: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11214: }
1.1084 raeburn 11215: } elsif (($actionurl eq '/adm/dependencies') ||
11216: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11217: ($args->{'context'} eq 'paste')) ||
11218: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11219: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11220: my $dir;
11221: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11222: $dir = $fileloc;
11223: } else {
11224: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11225: }
1.1071 raeburn 11226: if ($dir ne '') {
11227: my ($sublistref,$listerror) =
11228: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11229: if (ref($sublistref) eq 'ARRAY') {
11230: foreach my $line (@{$sublistref}) {
11231: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11232: undef,$mtime)=split(/\&/,$line,12);
11233: unless (($testdir&$dirptr) ||
11234: ($file_name =~ /^\.\.?$/)) {
11235: $currsubfile{$path}{$file_name} = [$size,$mtime];
11236: }
11237: }
11238: }
11239: }
1.984 raeburn 11240: }
11241: }
11242: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11243: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11244: my $item = $path.'/'.$file;
11245: unless ($mapping{$item} eq $item) {
11246: $pathchanges{$item} = 1;
11247: }
11248: $existing{$item} = 1;
11249: $numexisting ++;
11250: } else {
11251: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11252: }
11253: }
1.1071 raeburn 11254: if ($actionurl eq '/adm/dependencies') {
11255: foreach my $path (keys(%currsubfile)) {
11256: if (ref($currsubfile{$path}) eq 'HASH') {
11257: foreach my $file (keys(%{$currsubfile{$path}})) {
11258: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11259: next if (($rem ne '') &&
11260: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11261: (ref($navmap) &&
11262: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11263: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11264: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11265: $unused{$path.'/'.$file} = 1;
11266: }
11267: }
11268: }
11269: }
11270: }
1.984 raeburn 11271: }
1.1249 damieng 11272:
11273: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11274: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11275: my %currfile;
1.1123 raeburn 11276: if (($actionurl eq '/adm/portfolio') ||
11277: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11278: my ($dirlistref,$listerror) =
11279: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11280: if (ref($dirlistref) eq 'ARRAY') {
11281: foreach my $line (@{$dirlistref}) {
11282: my ($file_name,$rest) = split(/\&/,$line,2);
11283: $currfile{$file_name} = 1;
11284: }
1.984 raeburn 11285: }
1.987 raeburn 11286: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11287: if (opendir(my $dir,$url)) {
1.987 raeburn 11288: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11289: map {$currfile{$_} = 1;} @dir_list;
11290: }
1.1084 raeburn 11291: } elsif (($actionurl eq '/adm/dependencies') ||
11292: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11293: ($args->{'context'} eq 'paste')) ||
11294: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11295: if ($env{'request.course.id'} ne '') {
11296: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11297: if ($dir ne '') {
11298: my ($dirlistref,$listerror) =
11299: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11300: if (ref($dirlistref) eq 'ARRAY') {
11301: foreach my $line (@{$dirlistref}) {
11302: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11303: $size,undef,$mtime)=split(/\&/,$line,12);
11304: unless (($testdir&$dirptr) ||
11305: ($file_name =~ /^\.\.?$/)) {
11306: $currfile{$file_name} = [$size,$mtime];
11307: }
11308: }
11309: }
11310: }
11311: }
1.984 raeburn 11312: }
1.1249 damieng 11313: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11314: # are not in subdirectories, using $currfile
1.984 raeburn 11315: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11316: if (exists($currfile{$file})) {
1.987 raeburn 11317: unless ($mapping{$file} eq $file) {
11318: $pathchanges{$file} = 1;
11319: }
11320: $existing{$file} = 1;
11321: $numexisting ++;
11322: } else {
1.984 raeburn 11323: $newfiles{$file} = 1;
11324: }
11325: }
1.1071 raeburn 11326: foreach my $file (keys(%currfile)) {
11327: unless (($file eq $filename) ||
11328: ($file eq $filename.'.bak') ||
11329: ($dependencies{$file})) {
1.1085 raeburn 11330: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11331: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11332: next if (($rem ne '') &&
11333: (($env{"httpref.$rem".$file} ne '') ||
11334: (ref($navmap) &&
11335: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11336: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11337: ($navmap->getResourceByUrl($rem.$1)))))));
11338: }
1.1085 raeburn 11339: }
1.1071 raeburn 11340: $unused{$file} = 1;
11341: }
11342: }
1.1249 damieng 11343:
11344: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11345: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11346: ($args->{'context'} eq 'paste')) {
11347: $counter = scalar(keys(%existing));
11348: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11349: return ($output,$counter,$numpathchg,\%existing);
11350: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11351: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11352: $counter = scalar(keys(%existing));
11353: $numpathchg = scalar(keys(%pathchanges));
11354: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11355: }
1.1249 damieng 11356:
11357: # returns HTML otherwise, with dependency results and to ask for more uploads
11358:
11359: # $upload_output: missing dependencies (with upload form)
11360: # $modify_output: uploaded dependencies (in use)
11361: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11362: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11363: if ($actionurl eq '/adm/dependencies') {
11364: next if ($embed_file =~ m{^\w+://});
11365: }
1.660 raeburn 11366: $upload_output .= &start_data_table_row().
1.1123 raeburn 11367: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11368: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11369: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11370: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11371: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11372: }
1.1123 raeburn 11373: $upload_output .= '</td>';
1.1071 raeburn 11374: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11375: $upload_output.='<td align="right">'.
11376: '<span class="LC_info LC_fontsize_medium">'.
11377: &mt("URL points to web address").'</span>';
1.987 raeburn 11378: $numremref++;
1.660 raeburn 11379: } elsif ($args->{'error_on_invalid_names'}
11380: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11381: $upload_output.='<td align="right"><span class="LC_warning">'.
11382: &mt('Invalid characters').'</span>';
1.987 raeburn 11383: $numinvalid++;
1.660 raeburn 11384: } else {
1.1123 raeburn 11385: $upload_output .= '<td>'.
11386: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11387: $embed_file,\%mapping,
1.1071 raeburn 11388: $allfiles,$codebase,'upload');
11389: $counter ++;
11390: $numnew ++;
1.987 raeburn 11391: }
11392: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11393: }
11394: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11395: if ($actionurl eq '/adm/dependencies') {
11396: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11397: $modify_output .= &start_data_table_row().
11398: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11399: '<img src="'.&icon($embed_file).'" border="0" />'.
11400: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11401: '<td>'.$size.'</td>'.
11402: '<td>'.$mtime.'</td>'.
11403: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11404: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11405: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11406: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11407: &embedded_file_element('upload_embedded',$counter,
11408: $embed_file,\%mapping,
11409: $allfiles,$codebase,'modify').
11410: '</div></td>'.
11411: &end_data_table_row()."\n";
11412: $counter ++;
11413: } else {
11414: $upload_output .= &start_data_table_row().
1.1123 raeburn 11415: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11416: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11417: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11418: &Apache::loncommon::end_data_table_row()."\n";
11419: }
11420: }
11421: my $delidx = $counter;
11422: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11423: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11424: $delete_output .= &start_data_table_row().
11425: '<td><img src="'.&icon($oldfile).'" />'.
11426: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11427: '<td>'.$size.'</td>'.
11428: '<td>'.$mtime.'</td>'.
11429: '<td><label><input type="checkbox" name="del_upload_dep" '.
11430: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11431: &embedded_file_element('upload_embedded',$delidx,
11432: $oldfile,\%mapping,$allfiles,
11433: $codebase,'delete').'</td>'.
11434: &end_data_table_row()."\n";
11435: $numunused ++;
11436: $delidx ++;
1.987 raeburn 11437: }
11438: if ($upload_output) {
11439: $upload_output = &start_data_table().
11440: $upload_output.
11441: &end_data_table()."\n";
11442: }
1.1071 raeburn 11443: if ($modify_output) {
11444: $modify_output = &start_data_table().
11445: &start_data_table_header_row().
11446: '<th>'.&mt('File').'</th>'.
11447: '<th>'.&mt('Size (KB)').'</th>'.
11448: '<th>'.&mt('Modified').'</th>'.
11449: '<th>'.&mt('Upload replacement?').'</th>'.
11450: &end_data_table_header_row().
11451: $modify_output.
11452: &end_data_table()."\n";
11453: }
11454: if ($delete_output) {
11455: $delete_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('Delete?').'</th>'.
11461: &end_data_table_header_row().
11462: $delete_output.
11463: &end_data_table()."\n";
11464: }
1.987 raeburn 11465: my $applies = 0;
11466: if ($numremref) {
11467: $applies ++;
11468: }
11469: if ($numinvalid) {
11470: $applies ++;
11471: }
11472: if ($numexisting) {
11473: $applies ++;
11474: }
1.1071 raeburn 11475: if ($counter || $numunused) {
1.987 raeburn 11476: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11477: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11478: $state.'<h3>'.$heading.'</h3>';
11479: if ($actionurl eq '/adm/dependencies') {
11480: if ($numnew) {
11481: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11482: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11483: $upload_output.'<br />'."\n";
11484: }
11485: if ($numexisting) {
11486: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11487: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11488: $modify_output.'<br />'."\n";
11489: $buttontext = &mt('Save changes');
11490: }
11491: if ($numunused) {
11492: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11493: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11494: $delete_output.'<br />'."\n";
11495: $buttontext = &mt('Save changes');
11496: }
11497: } else {
11498: $output .= $upload_output.'<br />'."\n";
11499: }
11500: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11501: $counter.'" />'."\n";
11502: if ($actionurl eq '/adm/dependencies') {
11503: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11504: $numnew.'" />'."\n";
11505: } elsif ($actionurl eq '') {
1.987 raeburn 11506: $output .= '<input type="hidden" name="phase" value="three" />';
11507: }
11508: } elsif ($applies) {
11509: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11510: if ($applies > 1) {
11511: $output .=
1.1123 raeburn 11512: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11513: if ($numremref) {
11514: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11515: }
11516: if ($numinvalid) {
11517: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11518: }
11519: if ($numexisting) {
11520: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11521: }
11522: $output .= '</ul><br />';
11523: } elsif ($numremref) {
11524: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11525: } elsif ($numinvalid) {
11526: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11527: } elsif ($numexisting) {
11528: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11529: }
11530: $output .= $upload_output.'<br />';
11531: }
11532: my ($pathchange_output,$chgcount);
1.1071 raeburn 11533: $chgcount = $counter;
1.987 raeburn 11534: if (keys(%pathchanges) > 0) {
11535: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11536: if ($counter) {
1.987 raeburn 11537: $output .= &embedded_file_element('pathchange',$chgcount,
11538: $embed_file,\%mapping,
1.1071 raeburn 11539: $allfiles,$codebase,'change');
1.987 raeburn 11540: } else {
11541: $pathchange_output .=
11542: &start_data_table_row().
11543: '<td><input type ="checkbox" name="namechange" value="'.
11544: $chgcount.'" checked="checked" /></td>'.
11545: '<td>'.$mapping{$embed_file}.'</td>'.
11546: '<td>'.$embed_file.
11547: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11548: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11549: '</td>'.&end_data_table_row();
1.660 raeburn 11550: }
1.987 raeburn 11551: $numpathchg ++;
11552: $chgcount ++;
1.660 raeburn 11553: }
11554: }
1.1127 raeburn 11555: if (($counter) || ($numunused)) {
1.987 raeburn 11556: if ($numpathchg) {
11557: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11558: $numpathchg.'" />'."\n";
11559: }
11560: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11561: ($actionurl eq '/adm/imsimport')) {
11562: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11563: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11564: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11565: } elsif ($actionurl eq '/adm/dependencies') {
11566: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11567: }
1.1123 raeburn 11568: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11569: } elsif ($numpathchg) {
11570: my %pathchange = ();
11571: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11572: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11573: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11574: }
1.987 raeburn 11575: }
1.1071 raeburn 11576: return ($output,$counter,$numpathchg);
1.987 raeburn 11577: }
11578:
1.1147 raeburn 11579: =pod
11580:
11581: =item * clean_path($name)
11582:
11583: Performs clean-up of directories, subdirectories and filename in an
11584: embedded object, referenced in an HTML file which is being uploaded
11585: to a course or portfolio, where
11586: "Upload embedded images/multimedia files if HTML file" checkbox was
11587: checked.
11588:
11589: Clean-up is similar to replacements in lonnet::clean_filename()
11590: except each / between sub-directory and next level is preserved.
11591:
11592: =cut
11593:
11594: sub clean_path {
11595: my ($embed_file) = @_;
11596: $embed_file =~s{^/+}{};
11597: my @contents;
11598: if ($embed_file =~ m{/}) {
11599: @contents = split(/\//,$embed_file);
11600: } else {
11601: @contents = ($embed_file);
11602: }
11603: my $lastidx = scalar(@contents)-1;
11604: for (my $i=0; $i<=$lastidx; $i++) {
11605: $contents[$i]=~s{\\}{/}g;
11606: $contents[$i]=~s/\s+/\_/g;
11607: $contents[$i]=~s{[^/\w\.\-]}{}g;
11608: if ($i == $lastidx) {
11609: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11610: }
11611: }
11612: if ($lastidx > 0) {
11613: return join('/',@contents);
11614: } else {
11615: return $contents[0];
11616: }
11617: }
11618:
1.987 raeburn 11619: sub embedded_file_element {
1.1071 raeburn 11620: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11621: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11622: (ref($codebase) eq 'HASH'));
11623: my $output;
1.1071 raeburn 11624: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11625: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11626: }
11627: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11628: &escape($embed_file).'" />';
11629: unless (($context eq 'upload_embedded') &&
11630: ($mapping->{$embed_file} eq $embed_file)) {
11631: $output .='
11632: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11633: }
11634: my $attrib;
11635: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11636: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11637: }
11638: $output .=
11639: "\n\t\t".
11640: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11641: $attrib.'" />';
11642: if (exists($codebase->{$mapping->{$embed_file}})) {
11643: $output .=
11644: "\n\t\t".
11645: '<input name="codebase_'.$num.'" type="hidden" value="'.
11646: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11647: }
1.987 raeburn 11648: return $output;
1.660 raeburn 11649: }
11650:
1.1071 raeburn 11651: sub get_dependency_details {
11652: my ($currfile,$currsubfile,$embed_file) = @_;
11653: my ($size,$mtime,$showsize,$showmtime);
11654: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11655: if ($embed_file =~ m{/}) {
11656: my ($path,$fname) = split(/\//,$embed_file);
11657: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11658: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11659: }
11660: } else {
11661: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11662: ($size,$mtime) = @{$currfile->{$embed_file}};
11663: }
11664: }
11665: $showsize = $size/1024.0;
11666: $showsize = sprintf("%.1f",$showsize);
11667: if ($mtime > 0) {
11668: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11669: }
11670: }
11671: return ($showsize,$showmtime);
11672: }
11673:
11674: sub ask_embedded_js {
11675: return <<"END";
11676: <script type="text/javascript"">
11677: // <![CDATA[
11678: function toggleBrowse(counter) {
11679: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11680: var fileid = document.getElementById('embedded_item_'+counter);
11681: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11682: if (chkboxid.checked == true) {
11683: uploaddivid.style.display='block';
11684: } else {
11685: uploaddivid.style.display='none';
11686: fileid.value = '';
11687: }
11688: }
11689: // ]]>
11690: </script>
11691:
11692: END
11693: }
11694:
1.661 raeburn 11695: sub upload_embedded {
11696: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11697: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11698: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11699: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11700: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11701: my $orig_uploaded_filename =
11702: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11703: foreach my $type ('orig','ref','attrib','codebase') {
11704: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11705: $env{'form.embedded_'.$type.'_'.$i} =
11706: &unescape($env{'form.embedded_'.$type.'_'.$i});
11707: }
11708: }
1.661 raeburn 11709: my ($path,$fname) =
11710: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11711: # no path, whole string is fname
11712: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11713: $fname = &Apache::lonnet::clean_filename($fname);
11714: # See if there is anything left
11715: next if ($fname eq '');
11716:
11717: # Check if file already exists as a file or directory.
11718: my ($state,$msg);
11719: if ($context eq 'portfolio') {
11720: my $port_path = $dirpath;
11721: if ($group ne '') {
11722: $port_path = "groups/$group/$port_path";
11723: }
1.987 raeburn 11724: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11725: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11726: $dir_root,$port_path,$disk_quota,
11727: $current_disk_usage,$uname,$udom);
11728: if ($state eq 'will_exceed_quota'
1.984 raeburn 11729: || $state eq 'file_locked') {
1.661 raeburn 11730: $output .= $msg;
11731: next;
11732: }
11733: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11734: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11735: if ($state eq 'exists') {
11736: $output .= $msg;
11737: next;
11738: }
11739: }
11740: # Check if extension is valid
11741: if (($fname =~ /\.(\w+)$/) &&
11742: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11743: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11744: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11745: next;
11746: } elsif (($fname =~ /\.(\w+)$/) &&
11747: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11748: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11749: next;
11750: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11751: $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 11752: next;
11753: }
11754: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11755: my $subdir = $path;
11756: $subdir =~ s{/+$}{};
1.661 raeburn 11757: if ($context eq 'portfolio') {
1.984 raeburn 11758: my $result;
11759: if ($state eq 'existingfile') {
11760: $result=
11761: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11762: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11763: } else {
1.984 raeburn 11764: $result=
11765: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11766: $dirpath.
1.1123 raeburn 11767: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11768: if ($result !~ m|^/uploaded/|) {
11769: $output .= '<span class="LC_error">'
11770: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11771: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11772: .'</span><br />';
11773: next;
11774: } else {
1.987 raeburn 11775: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11776: $path.$fname.'</span>').'<br />';
1.984 raeburn 11777: }
1.661 raeburn 11778: }
1.1123 raeburn 11779: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 11780: my $extendedsubdir = $dirpath.'/'.$subdir;
11781: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11782: my $result =
1.1126 raeburn 11783: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11784: if ($result !~ m|^/uploaded/|) {
11785: $output .= '<span class="LC_error">'
11786: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11787: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11788: .'</span><br />';
11789: next;
11790: } else {
11791: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11792: $path.$fname.'</span>').'<br />';
1.1125 raeburn 11793: if ($context eq 'syllabus') {
11794: &Apache::lonnet::make_public_indefinitely($result);
11795: }
1.987 raeburn 11796: }
1.661 raeburn 11797: } else {
11798: # Save the file
11799: my $target = $env{'form.embedded_item_'.$i};
11800: my $fullpath = $dir_root.$dirpath.'/'.$path;
11801: my $dest = $fullpath.$fname;
11802: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11803: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11804: my $count;
11805: my $filepath = $dir_root;
1.1027 raeburn 11806: foreach my $subdir (@parts) {
11807: $filepath .= "/$subdir";
11808: if (!-e $filepath) {
1.661 raeburn 11809: mkdir($filepath,0770);
11810: }
11811: }
11812: my $fh;
11813: if (!open($fh,'>'.$dest)) {
11814: &Apache::lonnet::logthis('Failed to create '.$dest);
11815: $output .= '<span class="LC_error">'.
1.1071 raeburn 11816: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11817: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11818: '</span><br />';
11819: } else {
11820: if (!print $fh $env{'form.embedded_item_'.$i}) {
11821: &Apache::lonnet::logthis('Failed to write to '.$dest);
11822: $output .= '<span class="LC_error">'.
1.1071 raeburn 11823: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11824: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11825: '</span><br />';
11826: } else {
1.987 raeburn 11827: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11828: $url.'</span>').'<br />';
11829: unless ($context eq 'testbank') {
11830: $footer .= &mt('View embedded file: [_1]',
11831: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11832: }
11833: }
11834: close($fh);
11835: }
11836: }
11837: if ($env{'form.embedded_ref_'.$i}) {
11838: $pathchange{$i} = 1;
11839: }
11840: }
11841: if ($output) {
11842: $output = '<p>'.$output.'</p>';
11843: }
11844: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11845: $returnflag = 'ok';
1.1071 raeburn 11846: my $numpathchgs = scalar(keys(%pathchange));
11847: if ($numpathchgs > 0) {
1.987 raeburn 11848: if ($context eq 'portfolio') {
11849: $output .= '<p>'.&mt('or').'</p>';
11850: } elsif ($context eq 'testbank') {
1.1071 raeburn 11851: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11852: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11853: $returnflag = 'modify_orightml';
11854: }
11855: }
1.1071 raeburn 11856: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11857: }
11858:
11859: sub modify_html_form {
11860: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11861: my $end = 0;
11862: my $modifyform;
11863: if ($context eq 'upload_embedded') {
11864: return unless (ref($pathchange) eq 'HASH');
11865: if ($env{'form.number_embedded_items'}) {
11866: $end += $env{'form.number_embedded_items'};
11867: }
11868: if ($env{'form.number_pathchange_items'}) {
11869: $end += $env{'form.number_pathchange_items'};
11870: }
11871: if ($end) {
11872: for (my $i=0; $i<$end; $i++) {
11873: if ($i < $env{'form.number_embedded_items'}) {
11874: next unless($pathchange->{$i});
11875: }
11876: $modifyform .=
11877: &start_data_table_row().
11878: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11879: 'checked="checked" /></td>'.
11880: '<td>'.$env{'form.embedded_ref_'.$i}.
11881: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11882: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11883: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11884: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11885: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11886: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11887: '<td>'.$env{'form.embedded_orig_'.$i}.
11888: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11889: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11890: &end_data_table_row();
1.1071 raeburn 11891: }
1.987 raeburn 11892: }
11893: } else {
11894: $modifyform = $pathchgtable;
11895: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11896: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11897: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11898: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11899: }
11900: }
11901: if ($modifyform) {
1.1071 raeburn 11902: if ($actionurl eq '/adm/dependencies') {
11903: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11904: }
1.987 raeburn 11905: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11906: '<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".
11907: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11908: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11909: '</ol></p>'."\n".'<p>'.
11910: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11911: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11912: &start_data_table()."\n".
11913: &start_data_table_header_row().
11914: '<th>'.&mt('Change?').'</th>'.
11915: '<th>'.&mt('Current reference').'</th>'.
11916: '<th>'.&mt('Required reference').'</th>'.
11917: &end_data_table_header_row()."\n".
11918: $modifyform.
11919: &end_data_table().'<br />'."\n".$hiddenstate.
11920: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11921: '</form>'."\n";
11922: }
11923: return;
11924: }
11925:
11926: sub modify_html_refs {
1.1123 raeburn 11927: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11928: my $container;
11929: if ($context eq 'portfolio') {
11930: $container = $env{'form.container'};
11931: } elsif ($context eq 'coursedoc') {
11932: $container = $env{'form.primaryurl'};
1.1071 raeburn 11933: } elsif ($context eq 'manage_dependencies') {
11934: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11935: $container = "/$container";
1.1123 raeburn 11936: } elsif ($context eq 'syllabus') {
11937: $container = $url;
1.987 raeburn 11938: } else {
1.1027 raeburn 11939: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11940: }
11941: my (%allfiles,%codebase,$output,$content);
11942: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 11943: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11944: if (wantarray) {
11945: return ('',0,0);
11946: } else {
11947: return;
11948: }
11949: }
11950: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11951: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11952: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11953: if (wantarray) {
11954: return ('',0,0);
11955: } else {
11956: return;
11957: }
11958: }
1.987 raeburn 11959: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11960: if ($content eq '-1') {
11961: if (wantarray) {
11962: return ('',0,0);
11963: } else {
11964: return;
11965: }
11966: }
1.987 raeburn 11967: } else {
1.1071 raeburn 11968: unless ($container =~ /^\Q$dir_root\E/) {
11969: if (wantarray) {
11970: return ('',0,0);
11971: } else {
11972: return;
11973: }
11974: }
1.987 raeburn 11975: if (open(my $fh,"<$container")) {
11976: $content = join('', <$fh>);
11977: close($fh);
11978: } else {
1.1071 raeburn 11979: if (wantarray) {
11980: return ('',0,0);
11981: } else {
11982: return;
11983: }
1.987 raeburn 11984: }
11985: }
11986: my ($count,$codebasecount) = (0,0);
11987: my $mm = new File::MMagic;
11988: my $mime_type = $mm->checktype_contents($content);
11989: if ($mime_type eq 'text/html') {
11990: my $parse_result =
11991: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11992: \%codebase,\$content);
11993: if ($parse_result eq 'ok') {
11994: foreach my $i (@changes) {
11995: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11996: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11997: if ($allfiles{$ref}) {
11998: my $newname = $orig;
11999: my ($attrib_regexp,$codebase);
1.1006 raeburn 12000: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12001: if ($attrib_regexp =~ /:/) {
12002: $attrib_regexp =~ s/\:/|/g;
12003: }
12004: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12005: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12006: $count += $numchg;
1.1123 raeburn 12007: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12008: delete($allfiles{$ref});
1.987 raeburn 12009: }
12010: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12011: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12012: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12013: $codebasecount ++;
12014: }
12015: }
12016: }
1.1123 raeburn 12017: my $skiprewrites;
1.987 raeburn 12018: if ($count || $codebasecount) {
12019: my $saveresult;
1.1071 raeburn 12020: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12021: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12022: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12023: if ($url eq $container) {
12024: my ($fname) = ($container =~ m{/([^/]+)$});
12025: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12026: $count,'<span class="LC_filename">'.
1.1071 raeburn 12027: $fname.'</span>').'</p>';
1.987 raeburn 12028: } else {
12029: $output = '<p class="LC_error">'.
12030: &mt('Error: update failed for: [_1].',
12031: '<span class="LC_filename">'.
12032: $container.'</span>').'</p>';
12033: }
1.1123 raeburn 12034: if ($context eq 'syllabus') {
12035: unless ($saveresult eq 'ok') {
12036: $skiprewrites = 1;
12037: }
12038: }
1.987 raeburn 12039: } else {
12040: if (open(my $fh,">$container")) {
12041: print $fh $content;
12042: close($fh);
12043: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12044: $count,'<span class="LC_filename">'.
12045: $container.'</span>').'</p>';
1.661 raeburn 12046: } else {
1.987 raeburn 12047: $output = '<p class="LC_error">'.
12048: &mt('Error: could not update [_1].',
12049: '<span class="LC_filename">'.
12050: $container.'</span>').'</p>';
1.661 raeburn 12051: }
12052: }
12053: }
1.1123 raeburn 12054: if (($context eq 'syllabus') && (!$skiprewrites)) {
12055: my ($actionurl,$state);
12056: $actionurl = "/public/$udom/$uname/syllabus";
12057: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12058: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12059: \%codebase,
12060: {'context' => 'rewrites',
12061: 'ignore_remote_references' => 1,});
12062: if (ref($mapping) eq 'HASH') {
12063: my $rewrites = 0;
12064: foreach my $key (keys(%{$mapping})) {
12065: next if ($key =~ m{^https?://});
12066: my $ref = $mapping->{$key};
12067: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12068: my $attrib;
12069: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12070: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12071: }
12072: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12073: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12074: $rewrites += $numchg;
12075: }
12076: }
12077: if ($rewrites) {
12078: my $saveresult;
12079: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12080: if ($url eq $container) {
12081: my ($fname) = ($container =~ m{/([^/]+)$});
12082: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12083: $count,'<span class="LC_filename">'.
12084: $fname.'</span>').'</p>';
12085: } else {
12086: $output .= '<p class="LC_error">'.
12087: &mt('Error: could not update links in [_1].',
12088: '<span class="LC_filename">'.
12089: $container.'</span>').'</p>';
12090:
12091: }
12092: }
12093: }
12094: }
1.987 raeburn 12095: } else {
12096: &logthis('Failed to parse '.$container.
12097: ' to modify references: '.$parse_result);
1.661 raeburn 12098: }
12099: }
1.1071 raeburn 12100: if (wantarray) {
12101: return ($output,$count,$codebasecount);
12102: } else {
12103: return $output;
12104: }
1.661 raeburn 12105: }
12106:
12107: sub check_for_existing {
12108: my ($path,$fname,$element) = @_;
12109: my ($state,$msg);
12110: if (-d $path.'/'.$fname) {
12111: $state = 'exists';
12112: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12113: } elsif (-e $path.'/'.$fname) {
12114: $state = 'exists';
12115: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12116: }
12117: if ($state eq 'exists') {
12118: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12119: }
12120: return ($state,$msg);
12121: }
12122:
12123: sub check_for_upload {
12124: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12125: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12126: my $filesize = length($env{'form.'.$element});
12127: if (!$filesize) {
12128: my $msg = '<span class="LC_error">'.
12129: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12130: '<span class="LC_filename">'.$fname.'</span>',
12131: $filesize).'<br />'.
1.1007 raeburn 12132: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12133: '</span>';
12134: return ('zero_bytes',$msg);
12135: }
12136: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12137: my $getpropath = 1;
1.1021 raeburn 12138: my ($dirlistref,$listerror) =
12139: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12140: my $found_file = 0;
12141: my $locked_file = 0;
1.991 raeburn 12142: my @lockers;
12143: my $navmap;
12144: if ($env{'request.course.id'}) {
12145: $navmap = Apache::lonnavmaps::navmap->new();
12146: }
1.1021 raeburn 12147: if (ref($dirlistref) eq 'ARRAY') {
12148: foreach my $line (@{$dirlistref}) {
12149: my ($file_name,$rest)=split(/\&/,$line,2);
12150: if ($file_name eq $fname){
12151: $file_name = $path.$file_name;
12152: if ($group ne '') {
12153: $file_name = $group.$file_name;
12154: }
12155: $found_file = 1;
12156: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12157: foreach my $lock (@lockers) {
12158: if (ref($lock) eq 'ARRAY') {
12159: my ($symb,$crsid) = @{$lock};
12160: if ($crsid eq $env{'request.course.id'}) {
12161: if (ref($navmap)) {
12162: my $res = $navmap->getBySymb($symb);
12163: foreach my $part (@{$res->parts()}) {
12164: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12165: unless (($slot_status == $res->RESERVED) ||
12166: ($slot_status == $res->RESERVED_LOCATION)) {
12167: $locked_file = 1;
12168: }
1.991 raeburn 12169: }
1.1021 raeburn 12170: } else {
12171: $locked_file = 1;
1.991 raeburn 12172: }
12173: } else {
12174: $locked_file = 1;
12175: }
12176: }
1.1021 raeburn 12177: }
12178: } else {
12179: my @info = split(/\&/,$rest);
12180: my $currsize = $info[6]/1000;
12181: if ($currsize < $filesize) {
12182: my $extra = $filesize - $currsize;
12183: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12184: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12185: &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 12186: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12187: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12188: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12189: return ('will_exceed_quota',$msg);
12190: }
1.984 raeburn 12191: }
12192: }
1.661 raeburn 12193: }
12194: }
12195: }
12196: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12197: my $msg = '<p class="LC_warning">'.
12198: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12199: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12200: return ('will_exceed_quota',$msg);
12201: } elsif ($found_file) {
12202: if ($locked_file) {
1.1179 bisitz 12203: my $msg = '<p class="LC_warning">';
1.661 raeburn 12204: $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 12205: $msg .= '</p>';
1.661 raeburn 12206: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12207: return ('file_locked',$msg);
12208: } else {
1.1179 bisitz 12209: my $msg = '<p class="LC_error">';
1.984 raeburn 12210: $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 12211: $msg .= '</p>';
1.984 raeburn 12212: return ('existingfile',$msg);
1.661 raeburn 12213: }
12214: }
12215: }
12216:
1.987 raeburn 12217: sub check_for_traversal {
12218: my ($path,$url,$toplevel) = @_;
12219: my @parts=split(/\//,$path);
12220: my $cleanpath;
12221: my $fullpath = $url;
12222: for (my $i=0;$i<@parts;$i++) {
12223: next if ($parts[$i] eq '.');
12224: if ($parts[$i] eq '..') {
12225: $fullpath =~ s{([^/]+/)$}{};
12226: } else {
12227: $fullpath .= $parts[$i].'/';
12228: }
12229: }
12230: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12231: $cleanpath = $1;
12232: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12233: my $curr_toprel = $1;
12234: my @parts = split(/\//,$curr_toprel);
12235: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12236: my @urlparts = split(/\//,$url_toprel);
12237: my $doubledots;
12238: my $startdiff = -1;
12239: for (my $i=0; $i<@urlparts; $i++) {
12240: if ($startdiff == -1) {
12241: unless ($urlparts[$i] eq $parts[$i]) {
12242: $startdiff = $i;
12243: $doubledots .= '../';
12244: }
12245: } else {
12246: $doubledots .= '../';
12247: }
12248: }
12249: if ($startdiff > -1) {
12250: $cleanpath = $doubledots;
12251: for (my $i=$startdiff; $i<@parts; $i++) {
12252: $cleanpath .= $parts[$i].'/';
12253: }
12254: }
12255: }
12256: $cleanpath =~ s{(/)$}{};
12257: return $cleanpath;
12258: }
1.31 albertel 12259:
1.1053 raeburn 12260: sub is_archive_file {
12261: my ($mimetype) = @_;
12262: if (($mimetype eq 'application/octet-stream') ||
12263: ($mimetype eq 'application/x-stuffit') ||
12264: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12265: return 1;
12266: }
12267: return;
12268: }
12269:
12270: sub decompress_form {
1.1065 raeburn 12271: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12272: my %lt = &Apache::lonlocal::texthash (
12273: this => 'This file is an archive file.',
1.1067 raeburn 12274: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12275: itsc => 'Its contents are as follows:',
1.1053 raeburn 12276: youm => 'You may wish to extract its contents.',
12277: extr => 'Extract contents',
1.1067 raeburn 12278: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12279: proa => 'Process automatically?',
1.1053 raeburn 12280: yes => 'Yes',
12281: no => 'No',
1.1067 raeburn 12282: fold => 'Title for folder containing movie',
12283: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12284: );
1.1065 raeburn 12285: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12286: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12287: my $info = &list_archive_contents($fileloc,\@paths);
12288: if (@paths) {
12289: foreach my $path (@paths) {
12290: $path =~ s{^/}{};
1.1067 raeburn 12291: if ($path =~ m{^([^/]+)/$}) {
12292: $topdir = $1;
12293: }
1.1065 raeburn 12294: if ($path =~ m{^([^/]+)/}) {
12295: $toplevel{$1} = $path;
12296: } else {
12297: $toplevel{$path} = $path;
12298: }
12299: }
12300: }
1.1067 raeburn 12301: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12302: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12303: "$topdir/media/",
12304: "$topdir/media/$topdir.mp4",
12305: "$topdir/media/FirstFrame.png",
12306: "$topdir/media/player.swf",
12307: "$topdir/media/swfobject.js",
12308: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12309: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12310: "$topdir/$topdir.mp4",
12311: "$topdir/$topdir\_config.xml",
12312: "$topdir/$topdir\_controller.swf",
12313: "$topdir/$topdir\_embed.css",
12314: "$topdir/$topdir\_First_Frame.png",
12315: "$topdir/$topdir\_player.html",
12316: "$topdir/$topdir\_Thumbnails.png",
12317: "$topdir/playerProductInstall.swf",
12318: "$topdir/scripts/",
12319: "$topdir/scripts/config_xml.js",
12320: "$topdir/scripts/handlebars.js",
12321: "$topdir/scripts/jquery-1.7.1.min.js",
12322: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12323: "$topdir/scripts/modernizr.js",
12324: "$topdir/scripts/player-min.js",
12325: "$topdir/scripts/swfobject.js",
12326: "$topdir/skins/",
12327: "$topdir/skins/configuration_express.xml",
12328: "$topdir/skins/express_show/",
12329: "$topdir/skins/express_show/player-min.css",
12330: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12331: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12332: "$topdir/$topdir.mp4",
12333: "$topdir/$topdir\_config.xml",
12334: "$topdir/$topdir\_controller.swf",
12335: "$topdir/$topdir\_embed.css",
12336: "$topdir/$topdir\_First_Frame.png",
12337: "$topdir/$topdir\_player.html",
12338: "$topdir/$topdir\_Thumbnails.png",
12339: "$topdir/playerProductInstall.swf",
12340: "$topdir/scripts/",
12341: "$topdir/scripts/config_xml.js",
12342: "$topdir/scripts/techsmith-smart-player.min.js",
12343: "$topdir/skins/",
12344: "$topdir/skins/configuration_express.xml",
12345: "$topdir/skins/express_show/",
12346: "$topdir/skins/express_show/spritesheet.min.css",
12347: "$topdir/skins/express_show/spritesheet.png",
12348: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12349: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12350: if (@diffs == 0) {
1.1164 raeburn 12351: $is_camtasia = 6;
12352: } else {
1.1197 raeburn 12353: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12354: if (@diffs == 0) {
12355: $is_camtasia = 8;
1.1197 raeburn 12356: } else {
12357: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12358: if (@diffs == 0) {
12359: $is_camtasia = 8;
12360: }
1.1164 raeburn 12361: }
1.1067 raeburn 12362: }
12363: }
12364: my $output;
12365: if ($is_camtasia) {
12366: $output = <<"ENDCAM";
12367: <script type="text/javascript" language="Javascript">
12368: // <![CDATA[
12369:
12370: function camtasiaToggle() {
12371: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12372: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12373: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12374: document.getElementById('camtasia_titles').style.display='block';
12375: } else {
12376: document.getElementById('camtasia_titles').style.display='none';
12377: }
12378: }
12379: }
12380: return;
12381: }
12382:
12383: // ]]>
12384: </script>
12385: <p>$lt{'camt'}</p>
12386: ENDCAM
1.1065 raeburn 12387: } else {
1.1067 raeburn 12388: $output = '<p>'.$lt{'this'};
12389: if ($info eq '') {
12390: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12391: } else {
12392: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12393: '<div><pre>'.$info.'</pre></div>';
12394: }
1.1065 raeburn 12395: }
1.1067 raeburn 12396: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12397: my $duplicates;
12398: my $num = 0;
12399: if (ref($dirlist) eq 'ARRAY') {
12400: foreach my $item (@{$dirlist}) {
12401: if (ref($item) eq 'ARRAY') {
12402: if (exists($toplevel{$item->[0]})) {
12403: $duplicates .=
12404: &start_data_table_row().
12405: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12406: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12407: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12408: 'value="1" />'.&mt('Yes').'</label>'.
12409: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12410: '<td>'.$item->[0].'</td>';
12411: if ($item->[2]) {
12412: $duplicates .= '<td>'.&mt('Directory').'</td>';
12413: } else {
12414: $duplicates .= '<td>'.&mt('File').'</td>';
12415: }
12416: $duplicates .= '<td>'.$item->[3].'</td>'.
12417: '<td>'.
12418: &Apache::lonlocal::locallocaltime($item->[4]).
12419: '</td>'.
12420: &end_data_table_row();
12421: $num ++;
12422: }
12423: }
12424: }
12425: }
12426: my $itemcount;
12427: if (@paths > 0) {
12428: $itemcount = scalar(@paths);
12429: } else {
12430: $itemcount = 1;
12431: }
1.1067 raeburn 12432: if ($is_camtasia) {
12433: $output .= $lt{'auto'}.'<br />'.
12434: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12435: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12436: $lt{'yes'}.'</label> <label>'.
12437: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12438: $lt{'no'}.'</label></span><br />'.
12439: '<div id="camtasia_titles" style="display:block">'.
12440: &Apache::lonhtmlcommon::start_pick_box().
12441: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12442: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12443: &Apache::lonhtmlcommon::row_closure().
12444: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12445: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12446: &Apache::lonhtmlcommon::row_closure(1).
12447: &Apache::lonhtmlcommon::end_pick_box().
12448: '</div>';
12449: }
1.1065 raeburn 12450: $output .=
12451: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12452: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12453: "\n";
1.1065 raeburn 12454: if ($duplicates ne '') {
12455: $output .= '<p><span class="LC_warning">'.
12456: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12457: &start_data_table().
12458: &start_data_table_header_row().
12459: '<th>'.&mt('Overwrite?').'</th>'.
12460: '<th>'.&mt('Name').'</th>'.
12461: '<th>'.&mt('Type').'</th>'.
12462: '<th>'.&mt('Size').'</th>'.
12463: '<th>'.&mt('Last modified').'</th>'.
12464: &end_data_table_header_row().
12465: $duplicates.
12466: &end_data_table().
12467: '</p>';
12468: }
1.1067 raeburn 12469: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12470: if (ref($hiddenelements) eq 'HASH') {
12471: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12472: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12473: }
12474: }
12475: $output .= <<"END";
1.1067 raeburn 12476: <br />
1.1053 raeburn 12477: <input type="submit" name="decompress" value="$lt{'extr'}" />
12478: </form>
12479: $noextract
12480: END
12481: return $output;
12482: }
12483:
1.1065 raeburn 12484: sub decompression_utility {
12485: my ($program) = @_;
12486: my @utilities = ('tar','gunzip','bunzip2','unzip');
12487: my $location;
12488: if (grep(/^\Q$program\E$/,@utilities)) {
12489: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12490: '/usr/sbin/') {
12491: if (-x $dir.$program) {
12492: $location = $dir.$program;
12493: last;
12494: }
12495: }
12496: }
12497: return $location;
12498: }
12499:
12500: sub list_archive_contents {
12501: my ($file,$pathsref) = @_;
12502: my (@cmd,$output);
12503: my $needsregexp;
12504: if ($file =~ /\.zip$/) {
12505: @cmd = (&decompression_utility('unzip'),"-l");
12506: $needsregexp = 1;
12507: } elsif (($file =~ m/\.tar\.gz$/) ||
12508: ($file =~ /\.tgz$/)) {
12509: @cmd = (&decompression_utility('tar'),"-ztf");
12510: } elsif ($file =~ /\.tar\.bz2$/) {
12511: @cmd = (&decompression_utility('tar'),"-jtf");
12512: } elsif ($file =~ m|\.tar$|) {
12513: @cmd = (&decompression_utility('tar'),"-tf");
12514: }
12515: if (@cmd) {
12516: undef($!);
12517: undef($@);
12518: if (open(my $fh,"-|", @cmd, $file)) {
12519: while (my $line = <$fh>) {
12520: $output .= $line;
12521: chomp($line);
12522: my $item;
12523: if ($needsregexp) {
12524: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12525: } else {
12526: $item = $line;
12527: }
12528: if ($item ne '') {
12529: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12530: push(@{$pathsref},$item);
12531: }
12532: }
12533: }
12534: close($fh);
12535: }
12536: }
12537: return $output;
12538: }
12539:
1.1053 raeburn 12540: sub decompress_uploaded_file {
12541: my ($file,$dir) = @_;
12542: &Apache::lonnet::appenv({'cgi.file' => $file});
12543: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12544: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12545: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12546: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12547: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12548: my $decompressed = $env{'cgi.decompressed'};
12549: &Apache::lonnet::delenv('cgi.file');
12550: &Apache::lonnet::delenv('cgi.dir');
12551: &Apache::lonnet::delenv('cgi.decompressed');
12552: return ($decompressed,$result);
12553: }
12554:
1.1055 raeburn 12555: sub process_decompression {
12556: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
12557: my ($dir,$error,$warning,$output);
1.1180 raeburn 12558: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12559: $error = &mt('Filename not a supported archive file type.').
12560: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12561: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12562: } else {
12563: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12564: if ($docuhome eq 'no_host') {
12565: $error = &mt('Could not determine home server for course.');
12566: } else {
12567: my @ids=&Apache::lonnet::current_machine_ids();
12568: my $currdir = "$dir_root/$destination";
12569: if (grep(/^\Q$docuhome\E$/,@ids)) {
12570: $dir = &LONCAPA::propath($docudom,$docuname).
12571: "$dir_root/$destination";
12572: } else {
12573: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12574: "$dir_root/$docudom/$docuname/$destination";
12575: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12576: $error = &mt('Archive file not found.');
12577: }
12578: }
1.1065 raeburn 12579: my (@to_overwrite,@to_skip);
12580: if ($env{'form.archive_overwrite_total'} > 0) {
12581: my $total = $env{'form.archive_overwrite_total'};
12582: for (my $i=0; $i<$total; $i++) {
12583: if ($env{'form.archive_overwrite_'.$i} == 1) {
12584: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12585: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12586: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12587: }
12588: }
12589: }
12590: my $numskip = scalar(@to_skip);
12591: if (($numskip > 0) &&
12592: ($numskip == $env{'form.archive_itemcount'})) {
12593: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12594: } elsif ($dir eq '') {
1.1055 raeburn 12595: $error = &mt('Directory containing archive file unavailable.');
12596: } elsif (!$error) {
1.1065 raeburn 12597: my ($decompressed,$display);
12598: if ($numskip > 0) {
12599: my $tempdir = time.'_'.$$.int(rand(10000));
12600: mkdir("$dir/$tempdir",0755);
12601: system("mv $dir/$file $dir/$tempdir/$file");
12602: ($decompressed,$display) =
12603: &decompress_uploaded_file($file,"$dir/$tempdir");
12604: foreach my $item (@to_skip) {
12605: if (($item ne '') && ($item !~ /\.\./)) {
12606: if (-f "$dir/$tempdir/$item") {
12607: unlink("$dir/$tempdir/$item");
12608: } elsif (-d "$dir/$tempdir/$item") {
12609: system("rm -rf $dir/$tempdir/$item");
12610: }
12611: }
12612: }
12613: system("mv $dir/$tempdir/* $dir");
12614: rmdir("$dir/$tempdir");
12615: } else {
12616: ($decompressed,$display) =
12617: &decompress_uploaded_file($file,$dir);
12618: }
1.1055 raeburn 12619: if ($decompressed eq 'ok') {
1.1065 raeburn 12620: $output = '<p class="LC_info">'.
12621: &mt('Files extracted successfully from archive.').
12622: '</p>'."\n";
1.1055 raeburn 12623: my ($warning,$result,@contents);
12624: my ($newdirlistref,$newlisterror) =
12625: &Apache::lonnet::dirlist($currdir,$docudom,
12626: $docuname,1);
12627: my (%is_dir,%changes,@newitems);
12628: my $dirptr = 16384;
1.1065 raeburn 12629: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12630: foreach my $dir_line (@{$newdirlistref}) {
12631: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 12632: unless (($item =~ /^\.+$/) || ($item eq $file) ||
12633: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 12634: push(@newitems,$item);
12635: if ($dirptr&$testdir) {
12636: $is_dir{$item} = 1;
12637: }
12638: $changes{$item} = 1;
12639: }
12640: }
12641: }
12642: if (keys(%changes) > 0) {
12643: foreach my $item (sort(@newitems)) {
12644: if ($changes{$item}) {
12645: push(@contents,$item);
12646: }
12647: }
12648: }
12649: if (@contents > 0) {
1.1067 raeburn 12650: my $wantform;
12651: unless ($env{'form.autoextract_camtasia'}) {
12652: $wantform = 1;
12653: }
1.1056 raeburn 12654: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12655: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12656: $currdir,\%is_dir,
12657: \%children,\%parent,
1.1056 raeburn 12658: \@contents,\%dirorder,
12659: \%titles,$wantform);
1.1055 raeburn 12660: if ($datatable ne '') {
12661: $output .= &archive_options_form('decompressed',$datatable,
12662: $count,$hiddenelem);
1.1065 raeburn 12663: my $startcount = 6;
1.1055 raeburn 12664: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12665: \%titles,\%children);
1.1055 raeburn 12666: }
1.1067 raeburn 12667: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 12668: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12669: my %displayed;
12670: my $total = 1;
12671: $env{'form.archive_directory'} = [];
12672: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12673: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12674: $path =~ s{/$}{};
12675: my $item;
12676: if ($path ne '') {
12677: $item = "$path/$titles{$i}";
12678: } else {
12679: $item = $titles{$i};
12680: }
12681: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12682: if ($item eq $contents[0]) {
12683: push(@{$env{'form.archive_directory'}},$i);
12684: $env{'form.archive_'.$i} = 'display';
12685: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12686: $displayed{'folder'} = $i;
1.1164 raeburn 12687: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12688: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12689: $env{'form.archive_'.$i} = 'display';
12690: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12691: $displayed{'web'} = $i;
12692: } else {
1.1164 raeburn 12693: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12694: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12695: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12696: push(@{$env{'form.archive_directory'}},$i);
12697: }
12698: $env{'form.archive_'.$i} = 'dependency';
12699: }
12700: $total ++;
12701: }
12702: for (my $i=1; $i<$total; $i++) {
12703: next if ($i == $displayed{'web'});
12704: next if ($i == $displayed{'folder'});
12705: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12706: }
12707: $env{'form.phase'} = 'decompress_cleanup';
12708: $env{'form.archivedelete'} = 1;
12709: $env{'form.archive_count'} = $total-1;
12710: $output .=
12711: &process_extracted_files('coursedocs',$docudom,
12712: $docuname,$destination,
12713: $dir_root,$hiddenelem);
12714: }
1.1055 raeburn 12715: } else {
12716: $warning = &mt('No new items extracted from archive file.');
12717: }
12718: } else {
12719: $output = $display;
12720: $error = &mt('An error occurred during extraction from the archive file.');
12721: }
12722: }
12723: }
12724: }
12725: if ($error) {
12726: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12727: $error.'</p>'."\n";
12728: }
12729: if ($warning) {
12730: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12731: }
12732: return $output;
12733: }
12734:
12735: sub get_extracted {
1.1056 raeburn 12736: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12737: $titles,$wantform) = @_;
1.1055 raeburn 12738: my $count = 0;
12739: my $depth = 0;
12740: my $datatable;
1.1056 raeburn 12741: my @hierarchy;
1.1055 raeburn 12742: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12743: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12744: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12745: foreach my $item (@{$contents}) {
12746: $count ++;
1.1056 raeburn 12747: @{$dirorder->{$count}} = @hierarchy;
12748: $titles->{$count} = $item;
1.1055 raeburn 12749: &archive_hierarchy($depth,$count,$parent,$children);
12750: if ($wantform) {
12751: $datatable .= &archive_row($is_dir->{$item},$item,
12752: $currdir,$depth,$count);
12753: }
12754: if ($is_dir->{$item}) {
12755: $depth ++;
1.1056 raeburn 12756: push(@hierarchy,$count);
12757: $parent->{$depth} = $count;
1.1055 raeburn 12758: $datatable .=
12759: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12760: \$depth,\$count,\@hierarchy,$dirorder,
12761: $children,$parent,$titles,$wantform);
1.1055 raeburn 12762: $depth --;
1.1056 raeburn 12763: pop(@hierarchy);
1.1055 raeburn 12764: }
12765: }
12766: return ($count,$datatable);
12767: }
12768:
12769: sub recurse_extracted_archive {
1.1056 raeburn 12770: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12771: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12772: my $result='';
1.1056 raeburn 12773: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12774: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12775: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12776: return $result;
12777: }
12778: my $dirptr = 16384;
12779: my ($newdirlistref,$newlisterror) =
12780: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12781: if (ref($newdirlistref) eq 'ARRAY') {
12782: foreach my $dir_line (@{$newdirlistref}) {
12783: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12784: unless ($item =~ /^\.+$/) {
12785: $$count ++;
1.1056 raeburn 12786: @{$dirorder->{$$count}} = @{$hierarchy};
12787: $titles->{$$count} = $item;
1.1055 raeburn 12788: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12789:
1.1055 raeburn 12790: my $is_dir;
12791: if ($dirptr&$testdir) {
12792: $is_dir = 1;
12793: }
12794: if ($wantform) {
12795: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12796: }
12797: if ($is_dir) {
12798: $$depth ++;
1.1056 raeburn 12799: push(@{$hierarchy},$$count);
12800: $parent->{$$depth} = $$count;
1.1055 raeburn 12801: $result .=
12802: &recurse_extracted_archive("$currdir/$item",$docudom,
12803: $docuname,$depth,$count,
1.1056 raeburn 12804: $hierarchy,$dirorder,$children,
12805: $parent,$titles,$wantform);
1.1055 raeburn 12806: $$depth --;
1.1056 raeburn 12807: pop(@{$hierarchy});
1.1055 raeburn 12808: }
12809: }
12810: }
12811: }
12812: return $result;
12813: }
12814:
12815: sub archive_hierarchy {
12816: my ($depth,$count,$parent,$children) =@_;
12817: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12818: if (exists($parent->{$depth})) {
12819: $children->{$parent->{$depth}} .= $count.':';
12820: }
12821: }
12822: return;
12823: }
12824:
12825: sub archive_row {
12826: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12827: my ($name) = ($item =~ m{([^/]+)$});
12828: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12829: 'display' => 'Add as file',
1.1055 raeburn 12830: 'dependency' => 'Include as dependency',
12831: 'discard' => 'Discard',
12832: );
12833: if ($is_dir) {
1.1059 raeburn 12834: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12835: }
1.1056 raeburn 12836: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12837: my $offset = 0;
1.1055 raeburn 12838: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12839: $offset ++;
1.1065 raeburn 12840: if ($action ne 'display') {
12841: $offset ++;
12842: }
1.1055 raeburn 12843: $output .= '<td><span class="LC_nobreak">'.
12844: '<label><input type="radio" name="archive_'.$count.
12845: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12846: my $text = $choices{$action};
12847: if ($is_dir) {
12848: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12849: if ($action eq 'display') {
1.1059 raeburn 12850: $text = &mt('Add as folder');
1.1055 raeburn 12851: }
1.1056 raeburn 12852: } else {
12853: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12854:
12855: }
12856: $output .= ' /> '.$choices{$action}.'</label></span>';
12857: if ($action eq 'dependency') {
12858: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12859: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12860: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12861: '<option value=""></option>'."\n".
12862: '</select>'."\n".
12863: '</div>';
1.1059 raeburn 12864: } elsif ($action eq 'display') {
12865: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12866: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12867: '</div>';
1.1055 raeburn 12868: }
1.1056 raeburn 12869: $output .= '</td>';
1.1055 raeburn 12870: }
12871: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12872: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12873: for (my $i=0; $i<$depth; $i++) {
12874: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12875: }
12876: if ($is_dir) {
12877: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12878: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12879: } else {
12880: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12881: }
12882: $output .= ' '.$name.'</td>'."\n".
12883: &end_data_table_row();
12884: return $output;
12885: }
12886:
12887: sub archive_options_form {
1.1065 raeburn 12888: my ($form,$display,$count,$hiddenelem) = @_;
12889: my %lt = &Apache::lonlocal::texthash(
12890: perm => 'Permanently remove archive file?',
12891: hows => 'How should each extracted item be incorporated in the course?',
12892: cont => 'Content actions for all',
12893: addf => 'Add as folder/file',
12894: incd => 'Include as dependency for a displayed file',
12895: disc => 'Discard',
12896: no => 'No',
12897: yes => 'Yes',
12898: save => 'Save',
12899: );
12900: my $output = <<"END";
12901: <form name="$form" method="post" action="">
12902: <p><span class="LC_nobreak">$lt{'perm'}
12903: <label>
12904: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12905: </label>
12906:
12907: <label>
12908: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12909: </span>
12910: </p>
12911: <input type="hidden" name="phase" value="decompress_cleanup" />
12912: <br />$lt{'hows'}
12913: <div class="LC_columnSection">
12914: <fieldset>
12915: <legend>$lt{'cont'}</legend>
12916: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12917: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12918: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12919: </fieldset>
12920: </div>
12921: END
12922: return $output.
1.1055 raeburn 12923: &start_data_table()."\n".
1.1065 raeburn 12924: $display."\n".
1.1055 raeburn 12925: &end_data_table()."\n".
12926: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12927: $hiddenelem.
1.1065 raeburn 12928: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12929: '</form>';
12930: }
12931:
12932: sub archive_javascript {
1.1056 raeburn 12933: my ($startcount,$numitems,$titles,$children) = @_;
12934: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12935: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12936: my $scripttag = <<START;
12937: <script type="text/javascript">
12938: // <![CDATA[
12939:
12940: function checkAll(form,prefix) {
12941: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12942: for (var i=0; i < form.elements.length; i++) {
12943: var id = form.elements[i].id;
12944: if ((id != '') && (id != undefined)) {
12945: if (idstr.test(id)) {
12946: if (form.elements[i].type == 'radio') {
12947: form.elements[i].checked = true;
1.1056 raeburn 12948: var nostart = i-$startcount;
1.1059 raeburn 12949: var offset = nostart%7;
12950: var count = (nostart-offset)/7;
1.1056 raeburn 12951: dependencyCheck(form,count,offset);
1.1055 raeburn 12952: }
12953: }
12954: }
12955: }
12956: }
12957:
12958: function propagateCheck(form,count) {
12959: if (count > 0) {
1.1059 raeburn 12960: var startelement = $startcount + ((count-1) * 7);
12961: for (var j=1; j<6; j++) {
12962: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12963: var item = startelement + j;
12964: if (form.elements[item].type == 'radio') {
12965: if (form.elements[item].checked) {
12966: containerCheck(form,count,j);
12967: break;
12968: }
1.1055 raeburn 12969: }
12970: }
12971: }
12972: }
12973: }
12974:
12975: numitems = $numitems
1.1056 raeburn 12976: var titles = new Array(numitems);
12977: var parents = new Array(numitems);
1.1055 raeburn 12978: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12979: parents[i] = new Array;
1.1055 raeburn 12980: }
1.1059 raeburn 12981: var maintitle = '$maintitle';
1.1055 raeburn 12982:
12983: START
12984:
1.1056 raeburn 12985: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12986: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12987: for (my $i=0; $i<@contents; $i ++) {
12988: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12989: }
12990: }
12991:
1.1056 raeburn 12992: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12993: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12994: }
12995:
1.1055 raeburn 12996: $scripttag .= <<END;
12997:
12998: function containerCheck(form,count,offset) {
12999: if (count > 0) {
1.1056 raeburn 13000: dependencyCheck(form,count,offset);
1.1059 raeburn 13001: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13002: form.elements[item].checked = true;
13003: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13004: if (parents[count].length > 0) {
13005: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13006: containerCheck(form,parents[count][j],offset);
13007: }
13008: }
13009: }
13010: }
13011: }
13012:
13013: function dependencyCheck(form,count,offset) {
13014: if (count > 0) {
1.1059 raeburn 13015: var chosen = (offset+$startcount)+7*(count-1);
13016: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13017: var currtype = form.elements[depitem].type;
13018: if (form.elements[chosen].value == 'dependency') {
13019: document.getElementById('arc_depon_'+count).style.display='block';
13020: form.elements[depitem].options.length = 0;
13021: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13022: for (var i=1; i<=numitems; i++) {
13023: if (i == count) {
13024: continue;
13025: }
1.1059 raeburn 13026: var startelement = $startcount + (i-1) * 7;
13027: for (var j=1; j<6; j++) {
13028: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13029: var item = startelement + j;
13030: if (form.elements[item].type == 'radio') {
13031: if (form.elements[item].checked) {
13032: if (form.elements[item].value == 'display') {
13033: var n = form.elements[depitem].options.length;
13034: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13035: }
13036: }
13037: }
13038: }
13039: }
13040: }
13041: } else {
13042: document.getElementById('arc_depon_'+count).style.display='none';
13043: form.elements[depitem].options.length = 0;
13044: form.elements[depitem].options[0] = new Option('Select','',true,true);
13045: }
1.1059 raeburn 13046: titleCheck(form,count,offset);
1.1056 raeburn 13047: }
13048: }
13049:
13050: function propagateSelect(form,count,offset) {
13051: if (count > 0) {
1.1065 raeburn 13052: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13053: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13054: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13055: if (parents[count].length > 0) {
13056: for (var j=0; j<parents[count].length; j++) {
13057: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13058: }
13059: }
13060: }
13061: }
13062: }
1.1056 raeburn 13063:
13064: function containerSelect(form,count,offset,picked) {
13065: if (count > 0) {
1.1065 raeburn 13066: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13067: if (form.elements[item].type == 'radio') {
13068: if (form.elements[item].value == 'dependency') {
13069: if (form.elements[item+1].type == 'select-one') {
13070: for (var i=0; i<form.elements[item+1].options.length; i++) {
13071: if (form.elements[item+1].options[i].value == picked) {
13072: form.elements[item+1].selectedIndex = i;
13073: break;
13074: }
13075: }
13076: }
13077: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13078: if (parents[count].length > 0) {
13079: for (var j=0; j<parents[count].length; j++) {
13080: containerSelect(form,parents[count][j],offset,picked);
13081: }
13082: }
13083: }
13084: }
13085: }
13086: }
13087: }
13088:
1.1059 raeburn 13089: function titleCheck(form,count,offset) {
13090: if (count > 0) {
13091: var chosen = (offset+$startcount)+7*(count-1);
13092: var depitem = $startcount + ((count-1) * 7) + 2;
13093: var currtype = form.elements[depitem].type;
13094: if (form.elements[chosen].value == 'display') {
13095: document.getElementById('arc_title_'+count).style.display='block';
13096: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13097: document.getElementById('archive_title_'+count).value=maintitle;
13098: }
13099: } else {
13100: document.getElementById('arc_title_'+count).style.display='none';
13101: if (currtype == 'text') {
13102: document.getElementById('archive_title_'+count).value='';
13103: }
13104: }
13105: }
13106: return;
13107: }
13108:
1.1055 raeburn 13109: // ]]>
13110: </script>
13111: END
13112: return $scripttag;
13113: }
13114:
13115: sub process_extracted_files {
1.1067 raeburn 13116: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13117: my $numitems = $env{'form.archive_count'};
13118: return unless ($numitems);
13119: my @ids=&Apache::lonnet::current_machine_ids();
13120: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13121: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13122: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13123: if (grep(/^\Q$docuhome\E$/,@ids)) {
13124: $prefix = &LONCAPA::propath($docudom,$docuname);
13125: $pathtocheck = "$dir_root/$destination";
13126: $dir = $dir_root;
13127: $ishome = 1;
13128: } else {
13129: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13130: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
13131: $dir = "$dir_root/$docudom/$docuname";
13132: }
13133: my $currdir = "$dir_root/$destination";
13134: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13135: if ($env{'form.folderpath'}) {
13136: my @items = split('&',$env{'form.folderpath'});
13137: $folders{'0'} = $items[-2];
1.1099 raeburn 13138: if ($env{'form.folderpath'} =~ /\:1$/) {
13139: $containers{'0'}='page';
13140: } else {
13141: $containers{'0'}='sequence';
13142: }
1.1055 raeburn 13143: }
13144: my @archdirs = &get_env_multiple('form.archive_directory');
13145: if ($numitems) {
13146: for (my $i=1; $i<=$numitems; $i++) {
13147: my $path = $env{'form.archive_content_'.$i};
13148: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13149: my $item = $1;
13150: $toplevelitems{$item} = $i;
13151: if (grep(/^\Q$i\E$/,@archdirs)) {
13152: $is_dir{$item} = 1;
13153: }
13154: }
13155: }
13156: }
1.1067 raeburn 13157: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13158: if (keys(%toplevelitems) > 0) {
13159: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13160: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13161: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13162: }
1.1066 raeburn 13163: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13164: if ($numitems) {
13165: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13166: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13167: my $path = $env{'form.archive_content_'.$i};
13168: if ($path =~ /^\Q$pathtocheck\E/) {
13169: if ($env{'form.archive_'.$i} eq 'discard') {
13170: if ($prefix ne '' && $path ne '') {
13171: if (-e $prefix.$path) {
1.1066 raeburn 13172: if ((@archdirs > 0) &&
13173: (grep(/^\Q$i\E$/,@archdirs))) {
13174: $todeletedir{$prefix.$path} = 1;
13175: } else {
13176: $todelete{$prefix.$path} = 1;
13177: }
1.1055 raeburn 13178: }
13179: }
13180: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13181: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13182: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13183: $docstitle = $env{'form.archive_title_'.$i};
13184: if ($docstitle eq '') {
13185: $docstitle = $title;
13186: }
1.1055 raeburn 13187: $outer = 0;
1.1056 raeburn 13188: if (ref($dirorder{$i}) eq 'ARRAY') {
13189: if (@{$dirorder{$i}} > 0) {
13190: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13191: if ($env{'form.archive_'.$item} eq 'display') {
13192: $outer = $item;
13193: last;
13194: }
13195: }
13196: }
13197: }
13198: my ($errtext,$fatal) =
13199: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13200: '/'.$folders{$outer}.'.'.
13201: $containers{$outer});
13202: next if ($fatal);
13203: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13204: if ($context eq 'coursedocs') {
1.1056 raeburn 13205: $mapinner{$i} = time;
1.1055 raeburn 13206: $folders{$i} = 'default_'.$mapinner{$i};
13207: $containers{$i} = 'sequence';
13208: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13209: $folders{$i}.'.'.$containers{$i};
13210: my $newidx = &LONCAPA::map::getresidx();
13211: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13212: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13213: push(@LONCAPA::map::order,$newidx);
13214: my ($outtext,$errtext) =
13215: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13216: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13217: '.'.$containers{$outer},1,1);
1.1056 raeburn 13218: $newseqid{$i} = $newidx;
1.1067 raeburn 13219: unless ($errtext) {
13220: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
13221: }
1.1055 raeburn 13222: }
13223: } else {
13224: if ($context eq 'coursedocs') {
13225: my $newidx=&LONCAPA::map::getresidx();
13226: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13227: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13228: $title;
13229: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13230: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13231: }
13232: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13233: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13234: }
13235: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13236: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 13237: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 13238: unless ($ishome) {
13239: my $fetch = "$newdest{$i}/$title";
13240: $fetch =~ s/^\Q$prefix$dir\E//;
13241: $prompttofetch{$fetch} = 1;
13242: }
1.1055 raeburn 13243: }
13244: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13245: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13246: push(@LONCAPA::map::order, $newidx);
13247: my ($outtext,$errtext)=
13248: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13249: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13250: '.'.$containers{$outer},1,1);
1.1067 raeburn 13251: unless ($errtext) {
13252: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13253: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
13254: }
13255: }
1.1055 raeburn 13256: }
13257: }
1.1086 raeburn 13258: }
13259: } else {
13260: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13261: }
13262: }
13263: for (my $i=1; $i<=$numitems; $i++) {
13264: next unless ($env{'form.archive_'.$i} eq 'dependency');
13265: my $path = $env{'form.archive_content_'.$i};
13266: if ($path =~ /^\Q$pathtocheck\E/) {
13267: my ($title) = ($path =~ m{/([^/]+)$});
13268: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13269: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13270: if (ref($dirorder{$i}) eq 'ARRAY') {
13271: my ($itemidx,$fullpath,$relpath);
13272: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13273: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13274: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13275: if ($dirorder{$i}->[$j] eq $container) {
13276: $itemidx = $j;
1.1056 raeburn 13277: }
13278: }
1.1086 raeburn 13279: }
13280: if ($itemidx eq '') {
13281: $itemidx = 0;
13282: }
13283: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13284: if ($mapinner{$referrer{$i}}) {
13285: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13286: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13287: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13288: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13289: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13290: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13291: if (!-e $fullpath) {
13292: mkdir($fullpath,0755);
1.1056 raeburn 13293: }
13294: }
1.1086 raeburn 13295: } else {
13296: last;
1.1056 raeburn 13297: }
1.1086 raeburn 13298: }
13299: }
13300: } elsif ($newdest{$referrer{$i}}) {
13301: $fullpath = $newdest{$referrer{$i}};
13302: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13303: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13304: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13305: last;
13306: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13307: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13308: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13309: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13310: if (!-e $fullpath) {
13311: mkdir($fullpath,0755);
1.1056 raeburn 13312: }
13313: }
1.1086 raeburn 13314: } else {
13315: last;
1.1056 raeburn 13316: }
1.1055 raeburn 13317: }
13318: }
1.1086 raeburn 13319: if ($fullpath ne '') {
13320: if (-e "$prefix$path") {
13321: system("mv $prefix$path $fullpath/$title");
13322: }
13323: if (-e "$fullpath/$title") {
13324: my $showpath;
13325: if ($relpath ne '') {
13326: $showpath = "$relpath/$title";
13327: } else {
13328: $showpath = "/$title";
13329: }
13330: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
13331: }
13332: unless ($ishome) {
13333: my $fetch = "$fullpath/$title";
13334: $fetch =~ s/^\Q$prefix$dir\E//;
13335: $prompttofetch{$fetch} = 1;
13336: }
13337: }
1.1055 raeburn 13338: }
1.1086 raeburn 13339: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13340: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
13341: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 13342: }
13343: } else {
13344: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13345: }
13346: }
13347: if (keys(%todelete)) {
13348: foreach my $key (keys(%todelete)) {
13349: unlink($key);
1.1066 raeburn 13350: }
13351: }
13352: if (keys(%todeletedir)) {
13353: foreach my $key (keys(%todeletedir)) {
13354: rmdir($key);
13355: }
13356: }
13357: foreach my $dir (sort(keys(%is_dir))) {
13358: if (($pathtocheck ne '') && ($dir ne '')) {
13359: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13360: }
13361: }
1.1067 raeburn 13362: if ($result ne '') {
13363: $output .= '<ul>'."\n".
13364: $result."\n".
13365: '</ul>';
13366: }
13367: unless ($ishome) {
13368: my $replicationfail;
13369: foreach my $item (keys(%prompttofetch)) {
13370: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13371: unless ($fetchresult eq 'ok') {
13372: $replicationfail .= '<li>'.$item.'</li>'."\n";
13373: }
13374: }
13375: if ($replicationfail) {
13376: $output .= '<p class="LC_error">'.
13377: &mt('Course home server failed to retrieve:').'<ul>'.
13378: $replicationfail.
13379: '</ul></p>';
13380: }
13381: }
1.1055 raeburn 13382: } else {
13383: $warning = &mt('No items found in archive.');
13384: }
13385: if ($error) {
13386: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13387: $error.'</p>'."\n";
13388: }
13389: if ($warning) {
13390: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13391: }
13392: return $output;
13393: }
13394:
1.1066 raeburn 13395: sub cleanup_empty_dirs {
13396: my ($path) = @_;
13397: if (($path ne '') && (-d $path)) {
13398: if (opendir(my $dirh,$path)) {
13399: my @dircontents = grep(!/^\./,readdir($dirh));
13400: my $numitems = 0;
13401: foreach my $item (@dircontents) {
13402: if (-d "$path/$item") {
1.1111 raeburn 13403: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13404: if (-e "$path/$item") {
13405: $numitems ++;
13406: }
13407: } else {
13408: $numitems ++;
13409: }
13410: }
13411: if ($numitems == 0) {
13412: rmdir($path);
13413: }
13414: closedir($dirh);
13415: }
13416: }
13417: return;
13418: }
13419:
1.41 ng 13420: =pod
1.45 matthew 13421:
1.1162 raeburn 13422: =item * &get_folder_hierarchy()
1.1068 raeburn 13423:
13424: Provides hierarchy of names of folders/sub-folders containing the current
13425: item,
13426:
13427: Inputs: 3
13428: - $navmap - navmaps object
13429:
13430: - $map - url for map (either the trigger itself, or map containing
13431: the resource, which is the trigger).
13432:
13433: - $showitem - 1 => show title for map itself; 0 => do not show.
13434:
13435: Outputs: 1 @pathitems - array of folder/subfolder names.
13436:
13437: =cut
13438:
13439: sub get_folder_hierarchy {
13440: my ($navmap,$map,$showitem) = @_;
13441: my @pathitems;
13442: if (ref($navmap)) {
13443: my $mapres = $navmap->getResourceByUrl($map);
13444: if (ref($mapres)) {
13445: my $pcslist = $mapres->map_hierarchy();
13446: if ($pcslist ne '') {
13447: my @pcs = split(/,/,$pcslist);
13448: foreach my $pc (@pcs) {
13449: if ($pc == 1) {
1.1129 raeburn 13450: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13451: } else {
13452: my $res = $navmap->getByMapPc($pc);
13453: if (ref($res)) {
13454: my $title = $res->compTitle();
13455: $title =~ s/\W+/_/g;
13456: if ($title ne '') {
13457: push(@pathitems,$title);
13458: }
13459: }
13460: }
13461: }
13462: }
1.1071 raeburn 13463: if ($showitem) {
13464: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13465: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13466: } else {
13467: my $maptitle = $mapres->compTitle();
13468: $maptitle =~ s/\W+/_/g;
13469: if ($maptitle ne '') {
13470: push(@pathitems,$maptitle);
13471: }
1.1068 raeburn 13472: }
13473: }
13474: }
13475: }
13476: return @pathitems;
13477: }
13478:
13479: =pod
13480:
1.1015 raeburn 13481: =item * &get_turnedin_filepath()
13482:
13483: Determines path in a user's portfolio file for storage of files uploaded
13484: to a specific essayresponse or dropbox item.
13485:
13486: Inputs: 3 required + 1 optional.
13487: $symb is symb for resource, $uname and $udom are for current user (required).
13488: $caller is optional (can be "submission", if routine is called when storing
13489: an upoaded file when "Submit Answer" button was pressed).
13490:
13491: Returns array containing $path and $multiresp.
13492: $path is path in portfolio. $multiresp is 1 if this resource contains more
13493: than one file upload item. Callers of routine should append partid as a
13494: subdirectory to $path in cases where $multiresp is 1.
13495:
13496: Called by: homework/essayresponse.pm and homework/structuretags.pm
13497:
13498: =cut
13499:
13500: sub get_turnedin_filepath {
13501: my ($symb,$uname,$udom,$caller) = @_;
13502: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13503: my $turnindir;
13504: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13505: $turnindir = $userhash{'turnindir'};
13506: my ($path,$multiresp);
13507: if ($turnindir eq '') {
13508: if ($caller eq 'submission') {
13509: $turnindir = &mt('turned in');
13510: $turnindir =~ s/\W+/_/g;
13511: my %newhash = (
13512: 'turnindir' => $turnindir,
13513: );
13514: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13515: }
13516: }
13517: if ($turnindir ne '') {
13518: $path = '/'.$turnindir.'/';
13519: my ($multipart,$turnin,@pathitems);
13520: my $navmap = Apache::lonnavmaps::navmap->new();
13521: if (defined($navmap)) {
13522: my $mapres = $navmap->getResourceByUrl($map);
13523: if (ref($mapres)) {
13524: my $pcslist = $mapres->map_hierarchy();
13525: if ($pcslist ne '') {
13526: foreach my $pc (split(/,/,$pcslist)) {
13527: my $res = $navmap->getByMapPc($pc);
13528: if (ref($res)) {
13529: my $title = $res->compTitle();
13530: $title =~ s/\W+/_/g;
13531: if ($title ne '') {
1.1149 raeburn 13532: if (($pc > 1) && (length($title) > 12)) {
13533: $title = substr($title,0,12);
13534: }
1.1015 raeburn 13535: push(@pathitems,$title);
13536: }
13537: }
13538: }
13539: }
13540: my $maptitle = $mapres->compTitle();
13541: $maptitle =~ s/\W+/_/g;
13542: if ($maptitle ne '') {
1.1149 raeburn 13543: if (length($maptitle) > 12) {
13544: $maptitle = substr($maptitle,0,12);
13545: }
1.1015 raeburn 13546: push(@pathitems,$maptitle);
13547: }
13548: unless ($env{'request.state'} eq 'construct') {
13549: my $res = $navmap->getBySymb($symb);
13550: if (ref($res)) {
13551: my $partlist = $res->parts();
13552: my $totaluploads = 0;
13553: if (ref($partlist) eq 'ARRAY') {
13554: foreach my $part (@{$partlist}) {
13555: my @types = $res->responseType($part);
13556: my @ids = $res->responseIds($part);
13557: for (my $i=0; $i < scalar(@ids); $i++) {
13558: if ($types[$i] eq 'essay') {
13559: my $partid = $part.'_'.$ids[$i];
13560: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13561: $totaluploads ++;
13562: }
13563: }
13564: }
13565: }
13566: if ($totaluploads > 1) {
13567: $multiresp = 1;
13568: }
13569: }
13570: }
13571: }
13572: } else {
13573: return;
13574: }
13575: } else {
13576: return;
13577: }
13578: my $restitle=&Apache::lonnet::gettitle($symb);
13579: $restitle =~ s/\W+/_/g;
13580: if ($restitle eq '') {
13581: $restitle = ($resurl =~ m{/[^/]+$});
13582: if ($restitle eq '') {
13583: $restitle = time;
13584: }
13585: }
1.1149 raeburn 13586: if (length($restitle) > 12) {
13587: $restitle = substr($restitle,0,12);
13588: }
1.1015 raeburn 13589: push(@pathitems,$restitle);
13590: $path .= join('/',@pathitems);
13591: }
13592: return ($path,$multiresp);
13593: }
13594:
13595: =pod
13596:
1.464 albertel 13597: =back
1.41 ng 13598:
1.112 bowersj2 13599: =head1 CSV Upload/Handling functions
1.38 albertel 13600:
1.41 ng 13601: =over 4
13602:
1.648 raeburn 13603: =item * &upfile_store($r)
1.41 ng 13604:
13605: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13606: needs $env{'form.upfile'}
1.41 ng 13607: returns $datatoken to be put into hidden field
13608:
13609: =cut
1.31 albertel 13610:
13611: sub upfile_store {
13612: my $r=shift;
1.258 albertel 13613: $env{'form.upfile'}=~s/\r/\n/gs;
13614: $env{'form.upfile'}=~s/\f/\n/gs;
13615: $env{'form.upfile'}=~s/\n+/\n/gs;
13616: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13617:
1.258 albertel 13618: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
13619: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 13620: {
1.158 raeburn 13621: my $datafile = $r->dir_config('lonDaemons').
13622: '/tmp/'.$datatoken.'.tmp';
13623: if ( open(my $fh,">$datafile") ) {
1.258 albertel 13624: print $fh $env{'form.upfile'};
1.158 raeburn 13625: close($fh);
13626: }
1.31 albertel 13627: }
13628: return $datatoken;
13629: }
13630:
1.56 matthew 13631: =pod
13632:
1.648 raeburn 13633: =item * &load_tmp_file($r)
1.41 ng 13634:
13635: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 13636: needs $env{'form.datatoken'},
13637: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13638:
13639: =cut
1.31 albertel 13640:
13641: sub load_tmp_file {
13642: my $r=shift;
13643: my @studentdata=();
13644: {
1.158 raeburn 13645: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 13646: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 13647: if ( open(my $fh,"<$studentfile") ) {
13648: @studentdata=<$fh>;
13649: close($fh);
13650: }
1.31 albertel 13651: }
1.258 albertel 13652: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13653: }
13654:
1.56 matthew 13655: =pod
13656:
1.648 raeburn 13657: =item * &upfile_record_sep()
1.41 ng 13658:
13659: Separate uploaded file into records
13660: returns array of records,
1.258 albertel 13661: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13662:
13663: =cut
1.31 albertel 13664:
13665: sub upfile_record_sep {
1.258 albertel 13666: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13667: } else {
1.248 albertel 13668: my @records;
1.258 albertel 13669: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13670: if ($line=~/^\s*$/) { next; }
13671: push(@records,$line);
13672: }
13673: return @records;
1.31 albertel 13674: }
13675: }
13676:
1.56 matthew 13677: =pod
13678:
1.648 raeburn 13679: =item * &record_sep($record)
1.41 ng 13680:
1.258 albertel 13681: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13682:
13683: =cut
13684:
1.263 www 13685: sub takeleft {
13686: my $index=shift;
13687: return substr('0000'.$index,-4,4);
13688: }
13689:
1.31 albertel 13690: sub record_sep {
13691: my $record=shift;
13692: my %components=();
1.258 albertel 13693: if ($env{'form.upfiletype'} eq 'xml') {
13694: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13695: my $i=0;
1.356 albertel 13696: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13697: $field=~s/^(\"|\')//;
13698: $field=~s/(\"|\')$//;
1.263 www 13699: $components{&takeleft($i)}=$field;
1.31 albertel 13700: $i++;
13701: }
1.258 albertel 13702: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13703: my $i=0;
1.356 albertel 13704: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13705: $field=~s/^(\"|\')//;
13706: $field=~s/(\"|\')$//;
1.263 www 13707: $components{&takeleft($i)}=$field;
1.31 albertel 13708: $i++;
13709: }
13710: } else {
1.561 www 13711: my $separator=',';
1.480 banghart 13712: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13713: $separator=';';
1.480 banghart 13714: }
1.31 albertel 13715: my $i=0;
1.561 www 13716: # the character we are looking for to indicate the end of a quote or a record
13717: my $looking_for=$separator;
13718: # do not add the characters to the fields
13719: my $ignore=0;
13720: # we just encountered a separator (or the beginning of the record)
13721: my $just_found_separator=1;
13722: # store the field we are working on here
13723: my $field='';
13724: # work our way through all characters in record
13725: foreach my $character ($record=~/(.)/g) {
13726: if ($character eq $looking_for) {
13727: if ($character ne $separator) {
13728: # Found the end of a quote, again looking for separator
13729: $looking_for=$separator;
13730: $ignore=1;
13731: } else {
13732: # Found a separator, store away what we got
13733: $components{&takeleft($i)}=$field;
13734: $i++;
13735: $just_found_separator=1;
13736: $ignore=0;
13737: $field='';
13738: }
13739: next;
13740: }
13741: # single or double quotation marks after a separator indicate beginning of a quote
13742: # we are now looking for the end of the quote and need to ignore separators
13743: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13744: $looking_for=$character;
13745: next;
13746: }
13747: # ignore would be true after we reached the end of a quote
13748: if ($ignore) { next; }
13749: if (($just_found_separator) && ($character=~/\s/)) { next; }
13750: $field.=$character;
13751: $just_found_separator=0;
1.31 albertel 13752: }
1.561 www 13753: # catch the very last entry, since we never encountered the separator
13754: $components{&takeleft($i)}=$field;
1.31 albertel 13755: }
13756: return %components;
13757: }
13758:
1.144 matthew 13759: ######################################################
13760: ######################################################
13761:
1.56 matthew 13762: =pod
13763:
1.648 raeburn 13764: =item * &upfile_select_html()
1.41 ng 13765:
1.144 matthew 13766: Return HTML code to select a file from the users machine and specify
13767: the file type.
1.41 ng 13768:
13769: =cut
13770:
1.144 matthew 13771: ######################################################
13772: ######################################################
1.31 albertel 13773: sub upfile_select_html {
1.144 matthew 13774: my %Types = (
13775: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13776: semisv => &mt('Semicolon separated values'),
1.144 matthew 13777: space => &mt('Space separated'),
13778: tab => &mt('Tabulator separated'),
13779: # xml => &mt('HTML/XML'),
13780: );
13781: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13782: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13783: foreach my $type (sort(keys(%Types))) {
13784: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13785: }
13786: $Str .= "</select>\n";
13787: return $Str;
1.31 albertel 13788: }
13789:
1.301 albertel 13790: sub get_samples {
13791: my ($records,$toget) = @_;
13792: my @samples=({});
13793: my $got=0;
13794: foreach my $rec (@$records) {
13795: my %temp = &record_sep($rec);
13796: if (! grep(/\S/, values(%temp))) { next; }
13797: if (%temp) {
13798: $samples[$got]=\%temp;
13799: $got++;
13800: if ($got == $toget) { last; }
13801: }
13802: }
13803: return \@samples;
13804: }
13805:
1.144 matthew 13806: ######################################################
13807: ######################################################
13808:
1.56 matthew 13809: =pod
13810:
1.648 raeburn 13811: =item * &csv_print_samples($r,$records)
1.41 ng 13812:
13813: Prints a table of sample values from each column uploaded $r is an
13814: Apache Request ref, $records is an arrayref from
13815: &Apache::loncommon::upfile_record_sep
13816:
13817: =cut
13818:
1.144 matthew 13819: ######################################################
13820: ######################################################
1.31 albertel 13821: sub csv_print_samples {
13822: my ($r,$records) = @_;
1.662 bisitz 13823: my $samples = &get_samples($records,5);
1.301 albertel 13824:
1.594 raeburn 13825: $r->print(&mt('Samples').'<br />'.&start_data_table().
13826: &start_data_table_header_row());
1.356 albertel 13827: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13828: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13829: $r->print(&end_data_table_header_row());
1.301 albertel 13830: foreach my $hash (@$samples) {
1.594 raeburn 13831: $r->print(&start_data_table_row());
1.356 albertel 13832: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13833: $r->print('<td>');
1.356 albertel 13834: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13835: $r->print('</td>');
13836: }
1.594 raeburn 13837: $r->print(&end_data_table_row());
1.31 albertel 13838: }
1.594 raeburn 13839: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13840: }
13841:
1.144 matthew 13842: ######################################################
13843: ######################################################
13844:
1.56 matthew 13845: =pod
13846:
1.648 raeburn 13847: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13848:
13849: Prints a table to create associations between values and table columns.
1.144 matthew 13850:
1.41 ng 13851: $r is an Apache Request ref,
13852: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13853: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13854:
13855: =cut
13856:
1.144 matthew 13857: ######################################################
13858: ######################################################
1.31 albertel 13859: sub csv_print_select_table {
13860: my ($r,$records,$d) = @_;
1.301 albertel 13861: my $i=0;
13862: my $samples = &get_samples($records,1);
1.144 matthew 13863: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13864: &start_data_table().&start_data_table_header_row().
1.144 matthew 13865: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13866: '<th>'.&mt('Column').'</th>'.
13867: &end_data_table_header_row()."\n");
1.356 albertel 13868: foreach my $array_ref (@$d) {
13869: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13870: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13871:
1.875 bisitz 13872: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13873: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13874: $r->print('<option value="none"></option>');
1.356 albertel 13875: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13876: $r->print('<option value="'.$sample.'"'.
13877: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13878: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13879: }
1.594 raeburn 13880: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13881: $i++;
13882: }
1.594 raeburn 13883: $r->print(&end_data_table());
1.31 albertel 13884: $i--;
13885: return $i;
13886: }
1.56 matthew 13887:
1.144 matthew 13888: ######################################################
13889: ######################################################
13890:
1.56 matthew 13891: =pod
1.31 albertel 13892:
1.648 raeburn 13893: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13894:
13895: Prints a table of sample values from the upload and can make associate samples to internal names.
13896:
13897: $r is an Apache Request ref,
13898: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13899: $d is an array of 2 element arrays (internal name, displayed name)
13900:
13901: =cut
13902:
1.144 matthew 13903: ######################################################
13904: ######################################################
1.31 albertel 13905: sub csv_samples_select_table {
13906: my ($r,$records,$d) = @_;
13907: my $i=0;
1.144 matthew 13908: #
1.662 bisitz 13909: my $max_samples = 5;
13910: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13911: $r->print(&start_data_table().
13912: &start_data_table_header_row().'<th>'.
13913: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13914: &end_data_table_header_row());
1.301 albertel 13915:
13916: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13917: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13918: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13919: foreach my $option (@$d) {
13920: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13921: $r->print('<option value="'.$value.'"'.
1.253 albertel 13922: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13923: $display.'</option>');
1.31 albertel 13924: }
13925: $r->print('</select></td><td>');
1.662 bisitz 13926: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13927: if (defined($samples->[$line]{$key})) {
13928: $r->print($samples->[$line]{$key}."<br />\n");
13929: }
13930: }
1.594 raeburn 13931: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13932: $i++;
13933: }
1.594 raeburn 13934: $r->print(&end_data_table());
1.31 albertel 13935: $i--;
13936: return($i);
1.115 matthew 13937: }
13938:
1.144 matthew 13939: ######################################################
13940: ######################################################
13941:
1.115 matthew 13942: =pod
13943:
1.648 raeburn 13944: =item * &clean_excel_name($name)
1.115 matthew 13945:
13946: Returns a replacement for $name which does not contain any illegal characters.
13947:
13948: =cut
13949:
1.144 matthew 13950: ######################################################
13951: ######################################################
1.115 matthew 13952: sub clean_excel_name {
13953: my ($name) = @_;
13954: $name =~ s/[:\*\?\/\\]//g;
13955: if (length($name) > 31) {
13956: $name = substr($name,0,31);
13957: }
13958: return $name;
1.25 albertel 13959: }
1.84 albertel 13960:
1.85 albertel 13961: =pod
13962:
1.648 raeburn 13963: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13964:
13965: Returns either 1 or undef
13966:
13967: 1 if the part is to be hidden, undef if it is to be shown
13968:
13969: Arguments are:
13970:
13971: $id the id of the part to be checked
13972: $symb, optional the symb of the resource to check
13973: $udom, optional the domain of the user to check for
13974: $uname, optional the username of the user to check for
13975:
13976: =cut
1.84 albertel 13977:
13978: sub check_if_partid_hidden {
13979: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13980: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13981: $symb,$udom,$uname);
1.141 albertel 13982: my $truth=1;
13983: #if the string starts with !, then the list is the list to show not hide
13984: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13985: my @hiddenlist=split(/,/,$hiddenparts);
13986: foreach my $checkid (@hiddenlist) {
1.141 albertel 13987: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13988: }
1.141 albertel 13989: return !$truth;
1.84 albertel 13990: }
1.127 matthew 13991:
1.138 matthew 13992:
13993: ############################################################
13994: ############################################################
13995:
13996: =pod
13997:
1.157 matthew 13998: =back
13999:
1.138 matthew 14000: =head1 cgi-bin script and graphing routines
14001:
1.157 matthew 14002: =over 4
14003:
1.648 raeburn 14004: =item * &get_cgi_id()
1.138 matthew 14005:
14006: Inputs: none
14007:
14008: Returns an id which can be used to pass environment variables
14009: to various cgi-bin scripts. These environment variables will
14010: be removed from the users environment after a given time by
14011: the routine &Apache::lonnet::transfer_profile_to_env.
14012:
14013: =cut
14014:
14015: ############################################################
14016: ############################################################
1.152 albertel 14017: my $uniq=0;
1.136 matthew 14018: sub get_cgi_id {
1.154 albertel 14019: $uniq=($uniq+1)%100000;
1.280 albertel 14020: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14021: }
14022:
1.127 matthew 14023: ############################################################
14024: ############################################################
14025:
14026: =pod
14027:
1.648 raeburn 14028: =item * &DrawBarGraph()
1.127 matthew 14029:
1.138 matthew 14030: Facilitates the plotting of data in a (stacked) bar graph.
14031: Puts plot definition data into the users environment in order for
14032: graph.png to plot it. Returns an <img> tag for the plot.
14033: The bars on the plot are labeled '1','2',...,'n'.
14034:
14035: Inputs:
14036:
14037: =over 4
14038:
14039: =item $Title: string, the title of the plot
14040:
14041: =item $xlabel: string, text describing the X-axis of the plot
14042:
14043: =item $ylabel: string, text describing the Y-axis of the plot
14044:
14045: =item $Max: scalar, the maximum Y value to use in the plot
14046: If $Max is < any data point, the graph will not be rendered.
14047:
1.140 matthew 14048: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14049: they are plotted. If undefined, default values will be used.
14050:
1.178 matthew 14051: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14052:
1.138 matthew 14053: =item @Values: An array of array references. Each array reference holds data
14054: to be plotted in a stacked bar chart.
14055:
1.239 matthew 14056: =item If the final element of @Values is a hash reference the key/value
14057: pairs will be added to the graph definition.
14058:
1.138 matthew 14059: =back
14060:
14061: Returns:
14062:
14063: An <img> tag which references graph.png and the appropriate identifying
14064: information for the plot.
14065:
1.127 matthew 14066: =cut
14067:
14068: ############################################################
14069: ############################################################
1.134 matthew 14070: sub DrawBarGraph {
1.178 matthew 14071: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14072: #
14073: if (! defined($colors)) {
14074: $colors = ['#33ff00',
14075: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14076: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14077: ];
14078: }
1.228 matthew 14079: my $extra_settings = {};
14080: if (ref($Values[-1]) eq 'HASH') {
14081: $extra_settings = pop(@Values);
14082: }
1.127 matthew 14083: #
1.136 matthew 14084: my $identifier = &get_cgi_id();
14085: my $id = 'cgi.'.$identifier;
1.129 matthew 14086: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14087: return '';
14088: }
1.225 matthew 14089: #
14090: my @Labels;
14091: if (defined($labels)) {
14092: @Labels = @$labels;
14093: } else {
14094: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14095: push(@Labels,$i+1);
1.225 matthew 14096: }
14097: }
14098: #
1.129 matthew 14099: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14100: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14101: my %ValuesHash;
14102: my $NumSets=1;
14103: foreach my $array (@Values) {
14104: next if (! ref($array));
1.136 matthew 14105: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14106: join(',',@$array);
1.129 matthew 14107: }
1.127 matthew 14108: #
1.136 matthew 14109: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14110: if ($NumBars < 3) {
14111: $width = 120+$NumBars*32;
1.220 matthew 14112: $xskip = 1;
1.225 matthew 14113: $bar_width = 30;
14114: } elsif ($NumBars < 5) {
14115: $width = 120+$NumBars*20;
14116: $xskip = 1;
14117: $bar_width = 20;
1.220 matthew 14118: } elsif ($NumBars < 10) {
1.136 matthew 14119: $width = 120+$NumBars*15;
14120: $xskip = 1;
14121: $bar_width = 15;
14122: } elsif ($NumBars <= 25) {
14123: $width = 120+$NumBars*11;
14124: $xskip = 5;
14125: $bar_width = 8;
14126: } elsif ($NumBars <= 50) {
14127: $width = 120+$NumBars*8;
14128: $xskip = 5;
14129: $bar_width = 4;
14130: } else {
14131: $width = 120+$NumBars*8;
14132: $xskip = 5;
14133: $bar_width = 4;
14134: }
14135: #
1.137 matthew 14136: $Max = 1 if ($Max < 1);
14137: if ( int($Max) < $Max ) {
14138: $Max++;
14139: $Max = int($Max);
14140: }
1.127 matthew 14141: $Title = '' if (! defined($Title));
14142: $xlabel = '' if (! defined($xlabel));
14143: $ylabel = '' if (! defined($ylabel));
1.369 www 14144: $ValuesHash{$id.'.title'} = &escape($Title);
14145: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14146: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14147: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14148: $ValuesHash{$id.'.NumBars'} = $NumBars;
14149: $ValuesHash{$id.'.NumSets'} = $NumSets;
14150: $ValuesHash{$id.'.PlotType'} = 'bar';
14151: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14152: $ValuesHash{$id.'.height'} = $height;
14153: $ValuesHash{$id.'.width'} = $width;
14154: $ValuesHash{$id.'.xskip'} = $xskip;
14155: $ValuesHash{$id.'.bar_width'} = $bar_width;
14156: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14157: #
1.228 matthew 14158: # Deal with other parameters
14159: while (my ($key,$value) = each(%$extra_settings)) {
14160: $ValuesHash{$id.'.'.$key} = $value;
14161: }
14162: #
1.646 raeburn 14163: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14164: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14165: }
14166:
14167: ############################################################
14168: ############################################################
14169:
14170: =pod
14171:
1.648 raeburn 14172: =item * &DrawXYGraph()
1.137 matthew 14173:
1.138 matthew 14174: Facilitates the plotting of data in an XY graph.
14175: Puts plot definition data into the users environment in order for
14176: graph.png to plot it. Returns an <img> tag for the plot.
14177:
14178: Inputs:
14179:
14180: =over 4
14181:
14182: =item $Title: string, the title of the plot
14183:
14184: =item $xlabel: string, text describing the X-axis of the plot
14185:
14186: =item $ylabel: string, text describing the Y-axis of the plot
14187:
14188: =item $Max: scalar, the maximum Y value to use in the plot
14189: If $Max is < any data point, the graph will not be rendered.
14190:
14191: =item $colors: Array ref containing the hex color codes for the data to be
14192: plotted in. If undefined, default values will be used.
14193:
14194: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14195:
14196: =item $Ydata: Array ref containing Array refs.
1.185 www 14197: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14198:
14199: =item %Values: hash indicating or overriding any default values which are
14200: passed to graph.png.
14201: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14202:
14203: =back
14204:
14205: Returns:
14206:
14207: An <img> tag which references graph.png and the appropriate identifying
14208: information for the plot.
14209:
1.137 matthew 14210: =cut
14211:
14212: ############################################################
14213: ############################################################
14214: sub DrawXYGraph {
14215: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14216: #
14217: # Create the identifier for the graph
14218: my $identifier = &get_cgi_id();
14219: my $id = 'cgi.'.$identifier;
14220: #
14221: $Title = '' if (! defined($Title));
14222: $xlabel = '' if (! defined($xlabel));
14223: $ylabel = '' if (! defined($ylabel));
14224: my %ValuesHash =
14225: (
1.369 www 14226: $id.'.title' => &escape($Title),
14227: $id.'.xlabel' => &escape($xlabel),
14228: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14229: $id.'.y_max_value'=> $Max,
14230: $id.'.labels' => join(',',@$Xlabels),
14231: $id.'.PlotType' => 'XY',
14232: );
14233: #
14234: if (defined($colors) && ref($colors) eq 'ARRAY') {
14235: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14236: }
14237: #
14238: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14239: return '';
14240: }
14241: my $NumSets=1;
1.138 matthew 14242: foreach my $array (@{$Ydata}){
1.137 matthew 14243: next if (! ref($array));
14244: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14245: }
1.138 matthew 14246: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14247: #
14248: # Deal with other parameters
14249: while (my ($key,$value) = each(%Values)) {
14250: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14251: }
14252: #
1.646 raeburn 14253: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14254: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14255: }
14256:
14257: ############################################################
14258: ############################################################
14259:
14260: =pod
14261:
1.648 raeburn 14262: =item * &DrawXYYGraph()
1.138 matthew 14263:
14264: Facilitates the plotting of data in an XY graph with two Y axes.
14265: Puts plot definition data into the users environment in order for
14266: graph.png to plot it. Returns an <img> tag for the plot.
14267:
14268: Inputs:
14269:
14270: =over 4
14271:
14272: =item $Title: string, the title of the plot
14273:
14274: =item $xlabel: string, text describing the X-axis of the plot
14275:
14276: =item $ylabel: string, text describing the Y-axis of the plot
14277:
14278: =item $colors: Array ref containing the hex color codes for the data to be
14279: plotted in. If undefined, default values will be used.
14280:
14281: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14282:
14283: =item $Ydata1: The first data set
14284:
14285: =item $Min1: The minimum value of the left Y-axis
14286:
14287: =item $Max1: The maximum value of the left Y-axis
14288:
14289: =item $Ydata2: The second data set
14290:
14291: =item $Min2: The minimum value of the right Y-axis
14292:
14293: =item $Max2: The maximum value of the left Y-axis
14294:
14295: =item %Values: hash indicating or overriding any default values which are
14296: passed to graph.png.
14297: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14298:
14299: =back
14300:
14301: Returns:
14302:
14303: An <img> tag which references graph.png and the appropriate identifying
14304: information for the plot.
1.136 matthew 14305:
14306: =cut
14307:
14308: ############################################################
14309: ############################################################
1.137 matthew 14310: sub DrawXYYGraph {
14311: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14312: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14313: #
14314: # Create the identifier for the graph
14315: my $identifier = &get_cgi_id();
14316: my $id = 'cgi.'.$identifier;
14317: #
14318: $Title = '' if (! defined($Title));
14319: $xlabel = '' if (! defined($xlabel));
14320: $ylabel = '' if (! defined($ylabel));
14321: my %ValuesHash =
14322: (
1.369 www 14323: $id.'.title' => &escape($Title),
14324: $id.'.xlabel' => &escape($xlabel),
14325: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14326: $id.'.labels' => join(',',@$Xlabels),
14327: $id.'.PlotType' => 'XY',
14328: $id.'.NumSets' => 2,
1.137 matthew 14329: $id.'.two_axes' => 1,
14330: $id.'.y1_max_value' => $Max1,
14331: $id.'.y1_min_value' => $Min1,
14332: $id.'.y2_max_value' => $Max2,
14333: $id.'.y2_min_value' => $Min2,
1.136 matthew 14334: );
14335: #
1.137 matthew 14336: if (defined($colors) && ref($colors) eq 'ARRAY') {
14337: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14338: }
14339: #
14340: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14341: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14342: return '';
14343: }
14344: my $NumSets=1;
1.137 matthew 14345: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14346: next if (! ref($array));
14347: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14348: }
14349: #
14350: # Deal with other parameters
14351: while (my ($key,$value) = each(%Values)) {
14352: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14353: }
14354: #
1.646 raeburn 14355: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14356: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14357: }
14358:
14359: ############################################################
14360: ############################################################
14361:
14362: =pod
14363:
1.157 matthew 14364: =back
14365:
1.139 matthew 14366: =head1 Statistics helper routines?
14367:
14368: Bad place for them but what the hell.
14369:
1.157 matthew 14370: =over 4
14371:
1.648 raeburn 14372: =item * &chartlink()
1.139 matthew 14373:
14374: Returns a link to the chart for a specific student.
14375:
14376: Inputs:
14377:
14378: =over 4
14379:
14380: =item $linktext: The text of the link
14381:
14382: =item $sname: The students username
14383:
14384: =item $sdomain: The students domain
14385:
14386: =back
14387:
1.157 matthew 14388: =back
14389:
1.139 matthew 14390: =cut
14391:
14392: ############################################################
14393: ############################################################
14394: sub chartlink {
14395: my ($linktext, $sname, $sdomain) = @_;
14396: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14397: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14398: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14399: '">'.$linktext.'</a>';
1.153 matthew 14400: }
14401:
14402: #######################################################
14403: #######################################################
14404:
14405: =pod
14406:
14407: =head1 Course Environment Routines
1.157 matthew 14408:
14409: =over 4
1.153 matthew 14410:
1.648 raeburn 14411: =item * &restore_course_settings()
1.153 matthew 14412:
1.648 raeburn 14413: =item * &store_course_settings()
1.153 matthew 14414:
14415: Restores/Store indicated form parameters from the course environment.
14416: Will not overwrite existing values of the form parameters.
14417:
14418: Inputs:
14419: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14420:
14421: a hash ref describing the data to be stored. For example:
14422:
14423: %Save_Parameters = ('Status' => 'scalar',
14424: 'chartoutputmode' => 'scalar',
14425: 'chartoutputdata' => 'scalar',
14426: 'Section' => 'array',
1.373 raeburn 14427: 'Group' => 'array',
1.153 matthew 14428: 'StudentData' => 'array',
14429: 'Maps' => 'array');
14430:
14431: Returns: both routines return nothing
14432:
1.631 raeburn 14433: =back
14434:
1.153 matthew 14435: =cut
14436:
14437: #######################################################
14438: #######################################################
14439: sub store_course_settings {
1.496 albertel 14440: return &store_settings($env{'request.course.id'},@_);
14441: }
14442:
14443: sub store_settings {
1.153 matthew 14444: # save to the environment
14445: # appenv the same items, just to be safe
1.300 albertel 14446: my $udom = $env{'user.domain'};
14447: my $uname = $env{'user.name'};
1.496 albertel 14448: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14449: my %SaveHash;
14450: my %AppHash;
14451: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14452: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14453: my $envname = 'environment.'.$basename;
1.258 albertel 14454: if (exists($env{'form.'.$setting})) {
1.153 matthew 14455: # Save this value away
14456: if ($type eq 'scalar' &&
1.258 albertel 14457: (! exists($env{$envname}) ||
14458: $env{$envname} ne $env{'form.'.$setting})) {
14459: $SaveHash{$basename} = $env{'form.'.$setting};
14460: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14461: } elsif ($type eq 'array') {
14462: my $stored_form;
1.258 albertel 14463: if (ref($env{'form.'.$setting})) {
1.153 matthew 14464: $stored_form = join(',',
14465: map {
1.369 www 14466: &escape($_);
1.258 albertel 14467: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14468: } else {
14469: $stored_form =
1.369 www 14470: &escape($env{'form.'.$setting});
1.153 matthew 14471: }
14472: # Determine if the array contents are the same.
1.258 albertel 14473: if ($stored_form ne $env{$envname}) {
1.153 matthew 14474: $SaveHash{$basename} = $stored_form;
14475: $AppHash{$envname} = $stored_form;
14476: }
14477: }
14478: }
14479: }
14480: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14481: $udom,$uname);
1.153 matthew 14482: if ($put_result !~ /^(ok|delayed)/) {
14483: &Apache::lonnet::logthis('unable to save form parameters, '.
14484: 'got error:'.$put_result);
14485: }
14486: # Make sure these settings stick around in this session, too
1.646 raeburn 14487: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14488: return;
14489: }
14490:
14491: sub restore_course_settings {
1.499 albertel 14492: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14493: }
14494:
14495: sub restore_settings {
14496: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14497: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14498: next if (exists($env{'form.'.$setting}));
1.496 albertel 14499: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14500: '.'.$setting;
1.258 albertel 14501: if (exists($env{$envname})) {
1.153 matthew 14502: if ($type eq 'scalar') {
1.258 albertel 14503: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14504: } elsif ($type eq 'array') {
1.258 albertel 14505: $env{'form.'.$setting} = [
1.153 matthew 14506: map {
1.369 www 14507: &unescape($_);
1.258 albertel 14508: } split(',',$env{$envname})
1.153 matthew 14509: ];
14510: }
14511: }
14512: }
1.127 matthew 14513: }
14514:
1.618 raeburn 14515: #######################################################
14516: #######################################################
14517:
14518: =pod
14519:
14520: =head1 Domain E-mail Routines
14521:
14522: =over 4
14523:
1.648 raeburn 14524: =item * &build_recipient_list()
1.618 raeburn 14525:
1.1144 raeburn 14526: Build recipient lists for following types of e-mail:
1.766 raeburn 14527: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14528: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14529: module change checking, student/employee ID conflict checks, as
14530: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14531: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14532:
14533: Inputs:
1.619 raeburn 14534: defmail (scalar - email address of default recipient),
1.1144 raeburn 14535: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14536: requestsmail, updatesmail, or idconflictsmail).
14537:
1.619 raeburn 14538: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14539:
1.619 raeburn 14540: origmail (scalar - email address of recipient from loncapa.conf,
14541: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14542:
1.655 raeburn 14543: Returns: comma separated list of addresses to which to send e-mail.
14544:
14545: =back
1.618 raeburn 14546:
14547: =cut
14548:
14549: ############################################################
14550: ############################################################
14551: sub build_recipient_list {
1.619 raeburn 14552: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 14553: my @recipients;
1.1270 raeburn 14554: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14555: my %domconfig =
1.1270 raeburn 14556: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14557: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14558: if (exists($domconfig{'contacts'}{$mailing})) {
14559: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14560: my @contacts = ('adminemail','supportemail');
14561: foreach my $item (@contacts) {
14562: if ($domconfig{'contacts'}{$mailing}{$item}) {
14563: my $addr = $domconfig{'contacts'}{$item};
14564: if (!grep(/^\Q$addr\E$/,@recipients)) {
14565: push(@recipients,$addr);
14566: }
1.619 raeburn 14567: }
1.1270 raeburn 14568: }
14569: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14570: if ($mailing eq 'helpdeskmail') {
14571: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14572: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14573: my @ok_bccs;
14574: foreach my $bcc (@bccs) {
14575: $bcc =~ s/^\s+//g;
14576: $bcc =~ s/\s+$//g;
14577: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14578: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14579: push(@ok_bccs,$bcc);
14580: }
14581: }
14582: }
14583: if (@ok_bccs > 0) {
14584: $allbcc = join(', ',@ok_bccs);
14585: }
14586: }
14587: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14588: }
14589: }
1.766 raeburn 14590: } elsif ($origmail ne '') {
1.1270 raeburn 14591: $lastresort = $origmail;
1.618 raeburn 14592: }
1.619 raeburn 14593: } elsif ($origmail ne '') {
1.1270 raeburn 14594: $lastresort = $origmail;
14595: }
14596:
14597: if (($mailing eq 'helpdesk') && ($lastresort ne '')) {
14598: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14599: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14600: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14601: my %what = (
14602: perlvar => 1,
14603: );
14604: my $primary = &Apache::lonnet::domain($defdom,'primary');
14605: if ($primary) {
14606: my $gotaddr;
14607: my ($result,$returnhash) =
14608: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14609: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14610: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14611: $lastresort = $returnhash->{'lonSupportEMail'};
14612: $gotaddr = 1;
14613: }
14614: }
14615: unless ($gotaddr) {
14616: my $uintdom = &Apache::lonnet::internet_dom($primary);
14617: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14618: unless ($uintdom eq $intdom) {
14619: my %domconfig =
14620: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14621: if (ref($domconfig{'contacts'}) eq 'HASH') {
14622: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14623: my @contacts = ('adminemail','supportemail');
14624: foreach my $item (@contacts) {
14625: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14626: my $addr = $domconfig{'contacts'}{$item};
14627: if (!grep(/^\Q$addr\E$/,@recipients)) {
14628: push(@recipients,$addr);
14629: }
14630: }
14631: }
14632: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14633: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14634: }
14635: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14636: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14637: my @ok_bccs;
14638: foreach my $bcc (@bccs) {
14639: $bcc =~ s/^\s+//g;
14640: $bcc =~ s/\s+$//g;
14641: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14642: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14643: push(@ok_bccs,$bcc);
14644: }
14645: }
14646: }
14647: if (@ok_bccs > 0) {
14648: $allbcc = join(', ',@ok_bccs);
14649: }
14650: }
14651: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14652: }
14653: }
14654: }
14655: }
14656: }
14657: }
1.618 raeburn 14658: }
1.688 raeburn 14659: if (defined($defmail)) {
14660: if ($defmail ne '') {
14661: push(@recipients,$defmail);
14662: }
1.618 raeburn 14663: }
14664: if ($otheremails) {
1.619 raeburn 14665: my @others;
14666: if ($otheremails =~ /,/) {
14667: @others = split(/,/,$otheremails);
1.618 raeburn 14668: } else {
1.619 raeburn 14669: push(@others,$otheremails);
14670: }
14671: foreach my $addr (@others) {
14672: if (!grep(/^\Q$addr\E$/,@recipients)) {
14673: push(@recipients,$addr);
14674: }
1.618 raeburn 14675: }
14676: }
1.1270 raeburn 14677: if ($mailing eq 'helpdesk') {
14678: if ((!@recipients) && ($lastresort ne '')) {
14679: push(@recipients,$lastresort);
14680: }
14681: } elsif ($lastresort ne '') {
14682: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14683: push(@recipients,$lastresort);
14684: }
14685: }
1.1271 raeburn 14686: my $recipientlist = join(',',@recipients);
1.1270 raeburn 14687: if (wantarray) {
14688: return ($recipientlist,$allbcc,$addtext);
14689: } else {
14690: return $recipientlist;
14691: }
1.618 raeburn 14692: }
14693:
1.127 matthew 14694: ############################################################
14695: ############################################################
1.154 albertel 14696:
1.655 raeburn 14697: =pod
14698:
1.1224 musolffc 14699: =over 4
14700:
1.1223 musolffc 14701: =item * &mime_email()
14702:
14703: Sends an email with a possible attachment
14704:
14705: Inputs:
14706:
14707: =over 4
14708:
14709: from - Sender's email address
14710:
14711: to - Email address of recipient
14712:
14713: subject - Subject of email
14714:
14715: body - Body of email
14716:
14717: cc_string - Carbon copy email address
14718:
14719: bcc - Blind carbon copy email address
14720:
14721: type - File type of attachment
14722:
14723: attachment_path - Path of file to be attached
14724:
14725: file_name - Name of file to be attached
14726:
14727: attachment_text - The body of an attachment of type "TEXT"
14728:
14729: =back
14730:
14731: =back
14732:
14733: =cut
14734:
14735: ############################################################
14736: ############################################################
14737:
14738: sub mime_email {
14739: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
14740: $file_name, $attachment_text) = @_;
14741: my $msg = MIME::Lite->new(
14742: From => $from,
14743: To => $to,
14744: Subject => $subject,
14745: Type =>'TEXT',
14746: Data => $body,
14747: );
14748: if ($cc_string ne '') {
14749: $msg->add("Cc" => $cc_string);
14750: }
14751: if ($bcc ne '') {
14752: $msg->add("Bcc" => $bcc);
14753: }
14754: $msg->attr("content-type" => "text/plain");
14755: $msg->attr("content-type.charset" => "UTF-8");
14756: # Attach file if given
14757: if ($attachment_path) {
14758: unless ($file_name) {
14759: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
14760: }
14761: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
14762: $msg->attach(Type => $type,
14763: Path => $attachment_path,
14764: Filename => $file_name
14765: );
14766: # Otherwise attach text if given
14767: } elsif ($attachment_text) {
14768: $msg->attach(Type => 'TEXT',
14769: Data => $attachment_text);
14770: }
14771: # Send it
14772: $msg->send('sendmail');
14773: }
14774:
14775: ############################################################
14776: ############################################################
14777:
14778: =pod
14779:
1.655 raeburn 14780: =head1 Course Catalog Routines
14781:
14782: =over 4
14783:
14784: =item * &gather_categories()
14785:
14786: Converts category definitions - keys of categories hash stored in
14787: coursecategories in configuration.db on the primary library server in a
14788: domain - to an array. Also generates javascript and idx hash used to
14789: generate Domain Coordinator interface for editing Course Categories.
14790:
14791: Inputs:
1.663 raeburn 14792:
1.655 raeburn 14793: categories (reference to hash of category definitions).
1.663 raeburn 14794:
1.655 raeburn 14795: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14796: categories and subcategories).
1.663 raeburn 14797:
1.655 raeburn 14798: idx (reference to hash of counters used in Domain Coordinator interface for
14799: editing Course Categories).
1.663 raeburn 14800:
1.655 raeburn 14801: jsarray (reference to array of categories used to create Javascript arrays for
14802: Domain Coordinator interface for editing Course Categories).
14803:
14804: Returns: nothing
14805:
14806: Side effects: populates cats, idx and jsarray.
14807:
14808: =cut
14809:
14810: sub gather_categories {
14811: my ($categories,$cats,$idx,$jsarray) = @_;
14812: my %counters;
14813: my $num = 0;
14814: foreach my $item (keys(%{$categories})) {
14815: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14816: if ($container eq '' && $depth == 0) {
14817: $cats->[$depth][$categories->{$item}] = $cat;
14818: } else {
14819: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14820: }
14821: my ($escitem,$tail) = split(/:/,$item,2);
14822: if ($counters{$tail} eq '') {
14823: $counters{$tail} = $num;
14824: $num ++;
14825: }
14826: if (ref($idx) eq 'HASH') {
14827: $idx->{$item} = $counters{$tail};
14828: }
14829: if (ref($jsarray) eq 'ARRAY') {
14830: push(@{$jsarray->[$counters{$tail}]},$item);
14831: }
14832: }
14833: return;
14834: }
14835:
14836: =pod
14837:
14838: =item * &extract_categories()
14839:
14840: Used to generate breadcrumb trails for course categories.
14841:
14842: Inputs:
1.663 raeburn 14843:
1.655 raeburn 14844: categories (reference to hash of category definitions).
1.663 raeburn 14845:
1.655 raeburn 14846: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14847: categories and subcategories).
1.663 raeburn 14848:
1.655 raeburn 14849: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14850:
1.655 raeburn 14851: allitems (reference to hash - key is category key
14852: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14853:
1.655 raeburn 14854: idx (reference to hash of counters used in Domain Coordinator interface for
14855: editing Course Categories).
1.663 raeburn 14856:
1.655 raeburn 14857: jsarray (reference to array of categories used to create Javascript arrays for
14858: Domain Coordinator interface for editing Course Categories).
14859:
1.665 raeburn 14860: subcats (reference to hash of arrays containing all subcategories within each
14861: category, -recursive)
14862:
1.655 raeburn 14863: Returns: nothing
14864:
14865: Side effects: populates trails and allitems hash references.
14866:
14867: =cut
14868:
14869: sub extract_categories {
1.665 raeburn 14870: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14871: if (ref($categories) eq 'HASH') {
14872: &gather_categories($categories,$cats,$idx,$jsarray);
14873: if (ref($cats->[0]) eq 'ARRAY') {
14874: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14875: my $name = $cats->[0][$i];
14876: my $item = &escape($name).'::0';
14877: my $trailstr;
14878: if ($name eq 'instcode') {
14879: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14880: } elsif ($name eq 'communities') {
14881: $trailstr = &mt('Communities');
1.1239 raeburn 14882: } elsif ($name eq 'placement') {
14883: $trailstr = &mt('Placement Tests');
1.655 raeburn 14884: } else {
14885: $trailstr = $name;
14886: }
14887: if ($allitems->{$item} eq '') {
14888: push(@{$trails},$trailstr);
14889: $allitems->{$item} = scalar(@{$trails})-1;
14890: }
14891: my @parents = ($name);
14892: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14893: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14894: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14895: if (ref($subcats) eq 'HASH') {
14896: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14897: }
14898: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14899: }
14900: } else {
14901: if (ref($subcats) eq 'HASH') {
14902: $subcats->{$item} = [];
1.655 raeburn 14903: }
14904: }
14905: }
14906: }
14907: }
14908: return;
14909: }
14910:
14911: =pod
14912:
1.1162 raeburn 14913: =item * &recurse_categories()
1.655 raeburn 14914:
14915: Recursively used to generate breadcrumb trails for course categories.
14916:
14917: Inputs:
1.663 raeburn 14918:
1.655 raeburn 14919: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14920: categories and subcategories).
1.663 raeburn 14921:
1.655 raeburn 14922: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14923:
14924: category (current course category, for which breadcrumb trail is being generated).
14925:
14926: trails (reference to array of breadcrumb trails for each category).
14927:
1.655 raeburn 14928: allitems (reference to hash - key is category key
14929: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14930:
1.655 raeburn 14931: parents (array containing containers directories for current category,
14932: back to top level).
14933:
14934: Returns: nothing
14935:
14936: Side effects: populates trails and allitems hash references
14937:
14938: =cut
14939:
14940: sub recurse_categories {
1.665 raeburn 14941: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14942: my $shallower = $depth - 1;
14943: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14944: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14945: my $name = $cats->[$depth]{$category}[$k];
14946: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14947: my $trailstr = join(' -> ',(@{$parents},$category));
14948: if ($allitems->{$item} eq '') {
14949: push(@{$trails},$trailstr);
14950: $allitems->{$item} = scalar(@{$trails})-1;
14951: }
14952: my $deeper = $depth+1;
14953: push(@{$parents},$category);
1.665 raeburn 14954: if (ref($subcats) eq 'HASH') {
14955: my $subcat = &escape($name).':'.$category.':'.$depth;
14956: for (my $j=@{$parents}; $j>=0; $j--) {
14957: my $higher;
14958: if ($j > 0) {
14959: $higher = &escape($parents->[$j]).':'.
14960: &escape($parents->[$j-1]).':'.$j;
14961: } else {
14962: $higher = &escape($parents->[$j]).'::'.$j;
14963: }
14964: push(@{$subcats->{$higher}},$subcat);
14965: }
14966: }
14967: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14968: $subcats);
1.655 raeburn 14969: pop(@{$parents});
14970: }
14971: } else {
14972: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14973: my $trailstr = join(' -> ',(@{$parents},$category));
14974: if ($allitems->{$item} eq '') {
14975: push(@{$trails},$trailstr);
14976: $allitems->{$item} = scalar(@{$trails})-1;
14977: }
14978: }
14979: return;
14980: }
14981:
1.663 raeburn 14982: =pod
14983:
1.1162 raeburn 14984: =item * &assign_categories_table()
1.663 raeburn 14985:
14986: Create a datatable for display of hierarchical categories in a domain,
14987: with checkboxes to allow a course to be categorized.
14988:
14989: Inputs:
14990:
14991: cathash - reference to hash of categories defined for the domain (from
14992: configuration.db)
14993:
14994: currcat - scalar with an & separated list of categories assigned to a course.
14995:
1.919 raeburn 14996: type - scalar contains course type (Course or Community).
14997:
1.1260 raeburn 14998: disabled - scalar (optional) contains disabled="disabled" if input elements are
14999: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15000:
1.663 raeburn 15001: Returns: $output (markup to be displayed)
15002:
15003: =cut
15004:
15005: sub assign_categories_table {
1.1259 raeburn 15006: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15007: my $output;
15008: if (ref($cathash) eq 'HASH') {
15009: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
15010: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
15011: $maxdepth = scalar(@cats);
15012: if (@cats > 0) {
15013: my $itemcount = 0;
15014: if (ref($cats[0]) eq 'ARRAY') {
15015: my @currcategories;
15016: if ($currcat ne '') {
15017: @currcategories = split('&',$currcat);
15018: }
1.919 raeburn 15019: my $table;
1.663 raeburn 15020: for (my $i=0; $i<@{$cats[0]}; $i++) {
15021: my $parent = $cats[0][$i];
1.919 raeburn 15022: next if ($parent eq 'instcode');
15023: if ($type eq 'Community') {
15024: next unless ($parent eq 'communities');
1.1239 raeburn 15025: } elsif ($type eq 'Placement') {
15026: next unless ($parent eq 'placement');
1.919 raeburn 15027: } else {
1.1239 raeburn 15028: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15029: }
1.663 raeburn 15030: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15031: my $item = &escape($parent).'::0';
15032: my $checked = '';
15033: if (@currcategories > 0) {
15034: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15035: $checked = ' checked="checked"';
1.663 raeburn 15036: }
15037: }
1.919 raeburn 15038: my $parent_title = $parent;
15039: if ($parent eq 'communities') {
15040: $parent_title = &mt('Communities');
1.1239 raeburn 15041: } elsif ($parent eq 'placement') {
15042: $parent_title = &mt('Placement Tests');
1.919 raeburn 15043: }
15044: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15045: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15046: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15047: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15048: my $depth = 1;
15049: push(@path,$parent);
1.1259 raeburn 15050: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15051: pop(@path);
1.919 raeburn 15052: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15053: $itemcount ++;
15054: }
1.919 raeburn 15055: if ($itemcount) {
15056: $output = &Apache::loncommon::start_data_table().
15057: $table.
15058: &Apache::loncommon::end_data_table();
15059: }
1.663 raeburn 15060: }
15061: }
15062: }
15063: return $output;
15064: }
15065:
15066: =pod
15067:
1.1162 raeburn 15068: =item * &assign_category_rows()
1.663 raeburn 15069:
15070: Create a datatable row for display of nested categories in a domain,
15071: with checkboxes to allow a course to be categorized,called recursively.
15072:
15073: Inputs:
15074:
15075: itemcount - track row number for alternating colors
15076:
15077: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15078: categories and subcategories.
15079:
15080: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15081:
15082: parent - parent of current category item
15083:
15084: path - Array containing all categories back up through the hierarchy from the
15085: current category to the top level.
15086:
15087: currcategories - reference to array of current categories assigned to the course
15088:
1.1260 raeburn 15089: disabled - scalar (optional) contains disabled="disabled" if input elements are
15090: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15091:
1.663 raeburn 15092: Returns: $output (markup to be displayed).
15093:
15094: =cut
15095:
15096: sub assign_category_rows {
1.1259 raeburn 15097: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15098: my ($text,$name,$item,$chgstr);
15099: if (ref($cats) eq 'ARRAY') {
15100: my $maxdepth = scalar(@{$cats});
15101: if (ref($cats->[$depth]) eq 'HASH') {
15102: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15103: my $numchildren = @{$cats->[$depth]{$parent}};
15104: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15105: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15106: for (my $j=0; $j<$numchildren; $j++) {
15107: $name = $cats->[$depth]{$parent}[$j];
15108: $item = &escape($name).':'.&escape($parent).':'.$depth;
15109: my $deeper = $depth+1;
15110: my $checked = '';
15111: if (ref($currcategories) eq 'ARRAY') {
15112: if (@{$currcategories} > 0) {
15113: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15114: $checked = ' checked="checked"';
1.663 raeburn 15115: }
15116: }
15117: }
1.664 raeburn 15118: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15119: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15120: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15121: '<input type="hidden" name="catname" value="'.$name.'" />'.
15122: '</td><td>';
1.663 raeburn 15123: if (ref($path) eq 'ARRAY') {
15124: push(@{$path},$name);
1.1259 raeburn 15125: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15126: pop(@{$path});
15127: }
15128: $text .= '</td></tr>';
15129: }
15130: $text .= '</table></td>';
15131: }
15132: }
15133: }
15134: return $text;
15135: }
15136:
1.1181 raeburn 15137: =pod
15138:
15139: =back
15140:
15141: =cut
15142:
1.655 raeburn 15143: ############################################################
15144: ############################################################
15145:
15146:
1.443 albertel 15147: sub commit_customrole {
1.664 raeburn 15148: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15149: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15150: ($start?', '.&mt('starting').' '.localtime($start):'').
15151: ($end?', ending '.localtime($end):'').': <b>'.
15152: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15153: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15154: '</b><br />';
15155: return $output;
15156: }
15157:
15158: sub commit_standardrole {
1.1116 raeburn 15159: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15160: my ($output,$logmsg,$linefeed);
15161: if ($context eq 'auto') {
15162: $linefeed = "\n";
15163: } else {
15164: $linefeed = "<br />\n";
15165: }
1.443 albertel 15166: if ($three eq 'st') {
1.541 raeburn 15167: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15168: $one,$two,$sec,$context,$credits);
1.541 raeburn 15169: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15170: ($result eq 'unknown_course') || ($result eq 'refused')) {
15171: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15172: } else {
1.541 raeburn 15173: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15174: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15175: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15176: if ($context eq 'auto') {
15177: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15178: } else {
15179: $output .= '<b>'.$result.'</b>'.$linefeed.
15180: &mt('Add to classlist').': <b>ok</b>';
15181: }
15182: $output .= $linefeed;
1.443 albertel 15183: }
15184: } else {
15185: $output = &mt('Assigning').' '.$three.' in '.$url.
15186: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15187: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15188: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15189: if ($context eq 'auto') {
15190: $output .= $result.$linefeed;
15191: } else {
15192: $output .= '<b>'.$result.'</b>'.$linefeed;
15193: }
1.443 albertel 15194: }
15195: return $output;
15196: }
15197:
15198: sub commit_studentrole {
1.1116 raeburn 15199: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15200: $credits) = @_;
1.626 raeburn 15201: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15202: if ($context eq 'auto') {
15203: $linefeed = "\n";
15204: } else {
15205: $linefeed = '<br />'."\n";
15206: }
1.443 albertel 15207: if (defined($one) && defined($two)) {
15208: my $cid=$one.'_'.$two;
15209: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15210: my $secchange = 0;
15211: my $expire_role_result;
15212: my $modify_section_result;
1.628 raeburn 15213: if ($oldsec ne '-1') {
15214: if ($oldsec ne $sec) {
1.443 albertel 15215: $secchange = 1;
1.628 raeburn 15216: my $now = time;
1.443 albertel 15217: my $uurl='/'.$cid;
15218: $uurl=~s/\_/\//g;
15219: if ($oldsec) {
15220: $uurl.='/'.$oldsec;
15221: }
1.626 raeburn 15222: $oldsecurl = $uurl;
1.628 raeburn 15223: $expire_role_result =
1.652 raeburn 15224: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15225: if ($env{'request.course.sec'} ne '') {
15226: if ($expire_role_result eq 'refused') {
15227: my @roles = ('st');
15228: my @statuses = ('previous');
15229: my @roledoms = ($one);
15230: my $withsec = 1;
15231: my %roleshash =
15232: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15233: \@statuses,\@roles,\@roledoms,$withsec);
15234: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15235: my ($oldstart,$oldend) =
15236: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15237: if ($oldend > 0 && $oldend <= $now) {
15238: $expire_role_result = 'ok';
15239: }
15240: }
15241: }
15242: }
1.443 albertel 15243: $result = $expire_role_result;
15244: }
15245: }
15246: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15247: $modify_section_result =
15248: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15249: undef,undef,undef,$sec,
15250: $end,$start,'','',$cid,
15251: '',$context,$credits);
1.443 albertel 15252: if ($modify_section_result =~ /^ok/) {
15253: if ($secchange == 1) {
1.628 raeburn 15254: if ($sec eq '') {
15255: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15256: } else {
15257: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15258: }
1.443 albertel 15259: } elsif ($oldsec eq '-1') {
1.628 raeburn 15260: if ($sec eq '') {
15261: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15262: } else {
15263: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15264: }
1.443 albertel 15265: } else {
1.628 raeburn 15266: if ($sec eq '') {
15267: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15268: } else {
15269: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15270: }
1.443 albertel 15271: }
15272: } else {
1.1115 raeburn 15273: if ($secchange) {
1.628 raeburn 15274: $$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;
15275: } else {
15276: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15277: }
1.443 albertel 15278: }
15279: $result = $modify_section_result;
15280: } elsif ($secchange == 1) {
1.628 raeburn 15281: if ($oldsec eq '') {
1.1103 raeburn 15282: $$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 15283: } else {
15284: $$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;
15285: }
1.626 raeburn 15286: if ($expire_role_result eq 'refused') {
15287: my $newsecurl = '/'.$cid;
15288: $newsecurl =~ s/\_/\//g;
15289: if ($sec ne '') {
15290: $newsecurl.='/'.$sec;
15291: }
15292: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15293: if ($sec eq '') {
15294: $$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;
15295: } else {
15296: $$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;
15297: }
15298: }
15299: }
1.443 albertel 15300: }
15301: } else {
1.626 raeburn 15302: $$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 15303: $result = "error: incomplete course id\n";
15304: }
15305: return $result;
15306: }
15307:
1.1108 raeburn 15308: sub show_role_extent {
15309: my ($scope,$context,$role) = @_;
15310: $scope =~ s{^/}{};
15311: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15312: push(@courseroles,'co');
15313: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15314: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15315: $scope =~ s{/}{_};
15316: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15317: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15318: my ($audom,$auname) = split(/\//,$scope);
15319: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15320: &Apache::loncommon::plainname($auname,$audom).'</span>');
15321: } else {
15322: $scope =~ s{/$}{};
15323: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15324: &Apache::lonnet::domain($scope,'description').'</span>');
15325: }
15326: }
15327:
1.443 albertel 15328: ############################################################
15329: ############################################################
15330:
1.566 albertel 15331: sub check_clone {
1.578 raeburn 15332: my ($args,$linefeed) = @_;
1.566 albertel 15333: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15334: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15335: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15336: my $clonemsg;
15337: my $can_clone = 0;
1.944 raeburn 15338: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15339: if ($lctype ne 'community') {
15340: $lctype = 'course';
15341: }
1.566 albertel 15342: if ($clonehome eq 'no_host') {
1.944 raeburn 15343: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15344: $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'});
15345: } else {
15346: $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'});
15347: }
1.566 albertel 15348: } else {
15349: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15350: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15351: if ($clonedesc{'type'} ne 'Community') {
1.1262 raeburn 15352: $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 15353: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15354: }
15355: }
1.1262 raeburn 15356: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15357: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15358: $can_clone = 1;
15359: } else {
1.1221 raeburn 15360: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15361: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15362: if ($clonehash{'cloners'} eq '') {
15363: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15364: if ($domdefs{'canclone'}) {
15365: unless ($domdefs{'canclone'} eq 'none') {
15366: if ($domdefs{'canclone'} eq 'domain') {
15367: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15368: $can_clone = 1;
15369: }
15370: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15371: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15372: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15373: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15374: $can_clone = 1;
15375: }
15376: }
15377: }
15378: }
1.578 raeburn 15379: } else {
1.1221 raeburn 15380: my @cloners = split(/,/,$clonehash{'cloners'});
15381: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15382: $can_clone = 1;
1.1221 raeburn 15383: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15384: $can_clone = 1;
1.1225 raeburn 15385: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15386: $can_clone = 1;
1.1221 raeburn 15387: }
15388: unless ($can_clone) {
1.1225 raeburn 15389: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15390: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15391: my (%gotdomdefaults,%gotcodedefaults);
15392: foreach my $cloner (@cloners) {
15393: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15394: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15395: my (%codedefaults,@code_order);
15396: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15397: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15398: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15399: }
15400: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15401: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15402: }
15403: } else {
15404: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15405: \%codedefaults,
15406: \@code_order);
15407: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15408: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15409: }
15410: if (@code_order > 0) {
15411: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15412: $cloner,$clonehash{'internal.coursecode'},
15413: $args->{'crscode'})) {
15414: $can_clone = 1;
15415: last;
15416: }
15417: }
15418: }
15419: }
15420: }
1.1225 raeburn 15421: }
15422: }
15423: unless ($can_clone) {
15424: my $ccrole = 'cc';
15425: if ($args->{'crstype'} eq 'Community') {
15426: $ccrole = 'co';
15427: }
15428: my %roleshash =
15429: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15430: $args->{'ccdomain'},
15431: 'userroles',['active'],[$ccrole],
15432: [$args->{'clonedomain'}]);
15433: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15434: $can_clone = 1;
15435: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15436: $args->{'ccuname'},$args->{'ccdomain'})) {
15437: $can_clone = 1;
1.1221 raeburn 15438: }
15439: }
15440: unless ($can_clone) {
15441: if ($args->{'crstype'} eq 'Community') {
15442: $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 15443: } else {
1.1221 raeburn 15444: $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'});
15445: }
1.566 albertel 15446: }
1.578 raeburn 15447: }
1.566 albertel 15448: }
15449: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15450: }
15451:
1.444 albertel 15452: sub construct_course {
1.1262 raeburn 15453: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15454: $cnum,$category,$coderef) = @_;
1.444 albertel 15455: my $outcome;
1.541 raeburn 15456: my $linefeed = '<br />'."\n";
15457: if ($context eq 'auto') {
15458: $linefeed = "\n";
15459: }
1.566 albertel 15460:
15461: #
15462: # Are we cloning?
15463: #
15464: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15465: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15466: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15467: if ($context ne 'auto') {
1.578 raeburn 15468: if ($clonemsg ne '') {
15469: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15470: }
1.566 albertel 15471: }
15472: $outcome .= $clonemsg.$linefeed;
15473:
15474: if (!$can_clone) {
15475: return (0,$outcome);
15476: }
15477: }
15478:
1.444 albertel 15479: #
15480: # Open course
15481: #
1.1239 raeburn 15482: my $showncrstype;
15483: if ($args->{'crstype'} eq 'Placement') {
15484: $showncrstype = 'placement test';
15485: } else {
15486: $showncrstype = lc($args->{'crstype'});
15487: }
1.444 albertel 15488: my %cenv=();
15489: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15490: $args->{'cdescr'},
15491: $args->{'curl'},
15492: $args->{'course_home'},
15493: $args->{'nonstandard'},
15494: $args->{'crscode'},
15495: $args->{'ccuname'}.':'.
15496: $args->{'ccdomain'},
1.882 raeburn 15497: $args->{'crstype'},
1.885 raeburn 15498: $cnum,$context,$category);
1.444 albertel 15499:
15500: # Note: The testing routines depend on this being output; see
15501: # Utils::Course. This needs to at least be output as a comment
15502: # if anyone ever decides to not show this, and Utils::Course::new
15503: # will need to be suitably modified.
1.1239 raeburn 15504: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15505: if ($$courseid =~ /^error:/) {
15506: return (0,$outcome);
15507: }
15508:
1.444 albertel 15509: #
15510: # Check if created correctly
15511: #
1.479 albertel 15512: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15513: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15514: if ($crsuhome eq 'no_host') {
15515: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15516: return (0,$outcome);
15517: }
1.541 raeburn 15518: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15519:
1.444 albertel 15520: #
1.566 albertel 15521: # Do the cloning
15522: #
15523: if ($can_clone && $cloneid) {
1.1239 raeburn 15524: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 15525: if ($context ne 'auto') {
15526: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15527: }
15528: $outcome .= $clonemsg.$linefeed;
15529: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15530: # Copy all files
1.637 www 15531: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15532: # Restore URL
1.566 albertel 15533: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15534: # Restore title
1.566 albertel 15535: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15536: # Restore creation date, creator and creation context.
15537: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15538: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15539: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15540: # Mark as cloned
1.566 albertel 15541: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15542: # Need to clone grading mode
15543: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15544: $cenv{'grading'}=$newenv{'grading'};
15545: # Do not clone these environment entries
15546: &Apache::lonnet::del('environment',
15547: ['default_enrollment_start_date',
15548: 'default_enrollment_end_date',
15549: 'question.email',
15550: 'policy.email',
15551: 'comment.email',
15552: 'pch.users.denied',
1.725 raeburn 15553: 'plc.users.denied',
15554: 'hidefromcat',
1.1121 raeburn 15555: 'checkforpriv',
1.1166 raeburn 15556: 'categories',
15557: 'internal.uniquecode'],
1.638 www 15558: $$crsudom,$$crsunum);
1.1170 raeburn 15559: if ($args->{'textbook'}) {
15560: $cenv{'internal.textbook'} = $args->{'textbook'};
15561: }
1.444 albertel 15562: }
1.566 albertel 15563:
1.444 albertel 15564: #
15565: # Set environment (will override cloned, if existing)
15566: #
15567: my @sections = ();
15568: my @xlists = ();
15569: if ($args->{'crstype'}) {
15570: $cenv{'type'}=$args->{'crstype'};
15571: }
15572: if ($args->{'crsid'}) {
15573: $cenv{'courseid'}=$args->{'crsid'};
15574: }
15575: if ($args->{'crscode'}) {
15576: $cenv{'internal.coursecode'}=$args->{'crscode'};
15577: }
15578: if ($args->{'crsquota'} ne '') {
15579: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15580: } else {
15581: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15582: }
15583: if ($args->{'ccuname'}) {
15584: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15585: ':'.$args->{'ccdomain'};
15586: } else {
15587: $cenv{'internal.courseowner'} = $args->{'curruser'};
15588: }
1.1116 raeburn 15589: if ($args->{'defaultcredits'}) {
15590: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15591: }
1.444 albertel 15592: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15593: if ($args->{'crssections'}) {
15594: $cenv{'internal.sectionnums'} = '';
15595: if ($args->{'crssections'} =~ m/,/) {
15596: @sections = split/,/,$args->{'crssections'};
15597: } else {
15598: $sections[0] = $args->{'crssections'};
15599: }
15600: if (@sections > 0) {
15601: foreach my $item (@sections) {
15602: my ($sec,$gp) = split/:/,$item;
15603: my $class = $args->{'crscode'}.$sec;
15604: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15605: $cenv{'internal.sectionnums'} .= $item.',';
15606: unless ($addcheck eq 'ok') {
1.1263 raeburn 15607: push(@badclasses,$class);
1.444 albertel 15608: }
15609: }
15610: $cenv{'internal.sectionnums'} =~ s/,$//;
15611: }
15612: }
15613: # do not hide course coordinator from staff listing,
15614: # even if privileged
15615: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 15616: # add course coordinator's domain to domains to check for privileged users
15617: # if different to course domain
15618: if ($$crsudom ne $args->{'ccdomain'}) {
15619: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15620: }
1.444 albertel 15621: # add crosslistings
15622: if ($args->{'crsxlist'}) {
15623: $cenv{'internal.crosslistings'}='';
15624: if ($args->{'crsxlist'} =~ m/,/) {
15625: @xlists = split/,/,$args->{'crsxlist'};
15626: } else {
15627: $xlists[0] = $args->{'crsxlist'};
15628: }
15629: if (@xlists > 0) {
15630: foreach my $item (@xlists) {
15631: my ($xl,$gp) = split/:/,$item;
15632: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15633: $cenv{'internal.crosslistings'} .= $item.',';
15634: unless ($addcheck eq 'ok') {
1.1263 raeburn 15635: push(@badclasses,$xl);
1.444 albertel 15636: }
15637: }
15638: $cenv{'internal.crosslistings'} =~ s/,$//;
15639: }
15640: }
15641: if ($args->{'autoadds'}) {
15642: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15643: }
15644: if ($args->{'autodrops'}) {
15645: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15646: }
15647: # check for notification of enrollment changes
15648: my @notified = ();
15649: if ($args->{'notify_owner'}) {
15650: if ($args->{'ccuname'} ne '') {
15651: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15652: }
15653: }
15654: if ($args->{'notify_dc'}) {
15655: if ($uname ne '') {
1.630 raeburn 15656: push(@notified,$uname.':'.$udom);
1.444 albertel 15657: }
15658: }
15659: if (@notified > 0) {
15660: my $notifylist;
15661: if (@notified > 1) {
15662: $notifylist = join(',',@notified);
15663: } else {
15664: $notifylist = $notified[0];
15665: }
15666: $cenv{'internal.notifylist'} = $notifylist;
15667: }
15668: if (@badclasses > 0) {
15669: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 15670: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15671: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15672: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15673: );
1.1264 raeburn 15674: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15675: &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 15676: if ($context eq 'auto') {
15677: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 15678: } else {
1.566 albertel 15679: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 15680: }
15681: foreach my $item (@badclasses) {
1.541 raeburn 15682: if ($context eq 'auto') {
1.1261 raeburn 15683: $outcome .= " - $item\n";
1.541 raeburn 15684: } else {
1.1261 raeburn 15685: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15686: }
1.1261 raeburn 15687: }
15688: if ($context eq 'auto') {
15689: $outcome .= $linefeed;
15690: } else {
15691: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 15692: }
1.444 albertel 15693: }
15694: if ($args->{'no_end_date'}) {
15695: $args->{'endaccess'} = 0;
15696: }
15697: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15698: $cenv{'internal.autoend'}=$args->{'enrollend'};
15699: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15700: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15701: if ($args->{'showphotos'}) {
15702: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15703: }
15704: $cenv{'internal.authtype'} = $args->{'authtype'};
15705: $cenv{'internal.autharg'} = $args->{'autharg'};
15706: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15707: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15708: 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');
15709: if ($context eq 'auto') {
15710: $outcome .= $krb_msg;
15711: } else {
1.566 albertel 15712: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15713: }
15714: $outcome .= $linefeed;
1.444 albertel 15715: }
15716: }
15717: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15718: if ($args->{'setpolicy'}) {
15719: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15720: }
15721: if ($args->{'setcontent'}) {
15722: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15723: }
1.1251 raeburn 15724: if ($args->{'setcomment'}) {
15725: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15726: }
1.444 albertel 15727: }
15728: if ($args->{'reshome'}) {
15729: $cenv{'reshome'}=$args->{'reshome'}.'/';
15730: $cenv{'reshome'}=~s/\/+$/\//;
15731: }
15732: #
15733: # course has keyed access
15734: #
15735: if ($args->{'setkeys'}) {
15736: $cenv{'keyaccess'}='yes';
15737: }
15738: # if specified, key authority is not course, but user
15739: # only active if keyaccess is yes
15740: if ($args->{'keyauth'}) {
1.487 albertel 15741: my ($user,$domain) = split(':',$args->{'keyauth'});
15742: $user = &LONCAPA::clean_username($user);
15743: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15744: if ($user ne '' && $domain ne '') {
1.487 albertel 15745: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15746: }
15747: }
15748:
1.1166 raeburn 15749: #
1.1167 raeburn 15750: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 15751: #
15752: if ($args->{'uniquecode'}) {
15753: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15754: if ($code) {
15755: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 15756: my %crsinfo =
15757: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15758: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15759: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15760: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15761: }
1.1166 raeburn 15762: if (ref($coderef)) {
15763: $$coderef = $code;
15764: }
15765: }
15766: }
15767:
1.444 albertel 15768: if ($args->{'disresdis'}) {
15769: $cenv{'pch.roles.denied'}='st';
15770: }
15771: if ($args->{'disablechat'}) {
15772: $cenv{'plc.roles.denied'}='st';
15773: }
15774:
15775: # Record we've not yet viewed the Course Initialization Helper for this
15776: # course
15777: $cenv{'course.helper.not.run'} = 1;
15778: #
15779: # Use new Randomseed
15780: #
15781: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15782: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15783: #
15784: # The encryption code and receipt prefix for this course
15785: #
15786: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15787: $cenv{'internal.encpref'}=100+int(9*rand(99));
15788: #
15789: # By default, use standard grading
15790: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15791:
1.541 raeburn 15792: $outcome .= $linefeed.&mt('Setting environment').': '.
15793: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15794: #
15795: # Open all assignments
15796: #
15797: if ($args->{'openall'}) {
15798: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15799: my %storecontent = ($storeunder => time,
15800: $storeunder.'.type' => 'date_start');
15801:
15802: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15803: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15804: }
15805: #
15806: # Set first page
15807: #
15808: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15809: || ($cloneid)) {
1.445 albertel 15810: use LONCAPA::map;
1.444 albertel 15811: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15812:
15813: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15814: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15815:
1.444 albertel 15816: $outcome .= ($fatal?$errtext:'read ok').' - ';
15817: my $title; my $url;
15818: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15819: $title=&mt('Syllabus');
1.444 albertel 15820: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15821: } else {
1.963 raeburn 15822: $title=&mt('Table of Contents');
1.444 albertel 15823: $url='/adm/navmaps';
15824: }
1.445 albertel 15825:
15826: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15827: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15828:
15829: if ($errtext) { $fatal=2; }
1.541 raeburn 15830: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15831: }
1.566 albertel 15832:
1.1237 raeburn 15833: #
15834: # Set params for Placement Tests
15835: #
1.1239 raeburn 15836: if ($args->{'crstype'} eq 'Placement') {
15837: my %storecontent;
15838: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
15839: my %defaults = (
15840: buttonshide => { value => 'yes',
15841: type => 'string_yesno',},
15842: type => { value => 'randomizetry',
15843: type => 'string_questiontype',},
15844: maxtries => { value => 1,
15845: type => 'int_pos',},
15846: problemstatus => { value => 'no',
15847: type => 'string_problemstatus',},
15848: );
15849: foreach my $key (keys(%defaults)) {
15850: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
15851: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
15852: }
1.1237 raeburn 15853: &Apache::lonnet::cput
15854: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
15855: }
15856:
1.566 albertel 15857: return (1,$outcome);
1.444 albertel 15858: }
15859:
1.1166 raeburn 15860: sub make_unique_code {
15861: my ($cdom,$cnum) = @_;
15862: # get lock on uniquecodes db
15863: my $lockhash = {
15864: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15865: ':'.$env{'user.domain'},
15866: };
15867: my $tries = 0;
15868: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15869: my ($code,$error);
15870:
15871: while (($gotlock ne 'ok') && ($tries<3)) {
15872: $tries ++;
15873: sleep 1;
15874: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15875: }
15876: if ($gotlock eq 'ok') {
15877: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15878: my $gotcode;
15879: my $attempts = 0;
15880: while ((!$gotcode) && ($attempts < 100)) {
15881: $code = &generate_code();
15882: if (!exists($currcodes{$code})) {
15883: $gotcode = 1;
15884: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15885: $error = 'nostore';
15886: }
15887: }
15888: $attempts ++;
15889: }
15890: my @del_lock = ($cnum."\0".'uniquecodes');
15891: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15892: } else {
15893: $error = 'nolock';
15894: }
15895: return ($code,$error);
15896: }
15897:
15898: sub generate_code {
15899: my $code;
15900: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15901: for (my $i=0; $i<6; $i++) {
15902: my $lettnum = int (rand 2);
15903: my $item = '';
15904: if ($lettnum) {
15905: $item = $letts[int( rand(18) )];
15906: } else {
15907: $item = 1+int( rand(8) );
15908: }
15909: $code .= $item;
15910: }
15911: return $code;
15912: }
15913:
1.444 albertel 15914: ############################################################
15915: ############################################################
15916:
1.1237 raeburn 15917: # Community, Course and Placement Test
1.378 raeburn 15918: sub course_type {
15919: my ($cid) = @_;
15920: if (!defined($cid)) {
15921: $cid = $env{'request.course.id'};
15922: }
1.404 albertel 15923: if (defined($env{'course.'.$cid.'.type'})) {
15924: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15925: } else {
15926: return 'Course';
1.377 raeburn 15927: }
15928: }
1.156 albertel 15929:
1.406 raeburn 15930: sub group_term {
15931: my $crstype = &course_type();
15932: my %names = (
15933: 'Course' => 'group',
1.865 raeburn 15934: 'Community' => 'group',
1.1237 raeburn 15935: 'Placement' => 'group',
1.406 raeburn 15936: );
15937: return $names{$crstype};
15938: }
15939:
1.902 raeburn 15940: sub course_types {
1.1237 raeburn 15941: my @types = ('official','unofficial','community','textbook','placement');
1.902 raeburn 15942: my %typename = (
15943: official => 'Official course',
15944: unofficial => 'Unofficial course',
15945: community => 'Community',
1.1165 raeburn 15946: textbook => 'Textbook course',
1.1237 raeburn 15947: placement => 'Placement test',
1.902 raeburn 15948: );
15949: return (\@types,\%typename);
15950: }
15951:
1.156 albertel 15952: sub icon {
15953: my ($file)=@_;
1.505 albertel 15954: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15955: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15956: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15957: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15958: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15959: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15960: $curfext.".gif") {
15961: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15962: $curfext.".gif";
15963: }
15964: }
1.249 albertel 15965: return &lonhttpdurl($iconname);
1.154 albertel 15966: }
1.84 albertel 15967:
1.575 albertel 15968: sub lonhttpdurl {
1.692 www 15969: #
15970: # Had been used for "small fry" static images on separate port 8080.
15971: # Modify here if lightweight http functionality desired again.
15972: # Currently eliminated due to increasing firewall issues.
15973: #
1.575 albertel 15974: my ($url)=@_;
1.692 www 15975: return $url;
1.215 albertel 15976: }
15977:
1.213 albertel 15978: sub connection_aborted {
15979: my ($r)=@_;
15980: $r->print(" ");$r->rflush();
15981: my $c = $r->connection;
15982: return $c->aborted();
15983: }
15984:
1.221 foxr 15985: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15986: # strings as 'strings'.
15987: sub escape_single {
1.221 foxr 15988: my ($input) = @_;
1.223 albertel 15989: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15990: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15991: return $input;
15992: }
1.223 albertel 15993:
1.222 foxr 15994: # Same as escape_single, but escape's "'s This
15995: # can be used for "strings"
15996: sub escape_double {
15997: my ($input) = @_;
15998: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15999: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16000: return $input;
16001: }
1.223 albertel 16002:
1.222 foxr 16003: # Escapes the last element of a full URL.
16004: sub escape_url {
16005: my ($url) = @_;
1.238 raeburn 16006: my @urlslices = split(/\//, $url,-1);
1.369 www 16007: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16008: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16009: }
1.462 albertel 16010:
1.820 raeburn 16011: sub compare_arrays {
16012: my ($arrayref1,$arrayref2) = @_;
16013: my (@difference,%count);
16014: @difference = ();
16015: %count = ();
16016: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16017: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16018: foreach my $element (keys(%count)) {
16019: if ($count{$element} == 1) {
16020: push(@difference,$element);
16021: }
16022: }
16023: }
16024: return @difference;
16025: }
16026:
1.817 bisitz 16027: # -------------------------------------------------------- Initialize user login
1.462 albertel 16028: sub init_user_environment {
1.463 albertel 16029: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16030: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16031:
16032: my $public=($username eq 'public' && $domain eq 'public');
16033:
1.1062 raeburn 16034: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16035: my $now=time;
16036:
16037: if ($public) {
16038: my $max_public=100;
16039: my $oldest;
16040: my $oldest_time=0;
16041: for(my $next=1;$next<=$max_public;$next++) {
16042: if (-e $lonids."/publicuser_$next.id") {
16043: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16044: if ($mtime<$oldest_time || !$oldest_time) {
16045: $oldest_time=$mtime;
16046: $oldest=$next;
16047: }
16048: } else {
16049: $cookie="publicuser_$next";
16050: last;
16051: }
16052: }
16053: if (!$cookie) { $cookie="publicuser_$oldest"; }
16054: } else {
1.1275 raeburn 16055: # See if old ID present, if so, remove if this isn't a robot,
16056: # killing any existing non-robot sessions
1.463 albertel 16057: if (!$args->{'robot'}) {
16058: opendir(DIR,$lonids);
16059: while ($filename=readdir(DIR)) {
16060: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
16061: unlink($lonids.'/'.$filename);
16062: }
1.462 albertel 16063: }
1.463 albertel 16064: closedir(DIR);
1.1204 raeburn 16065: # If there is a undeleted lockfile for the user's paste buffer remove it.
16066: my $namespace = 'nohist_courseeditor';
16067: my $lockingkey = 'paste'."\0".'locked_num';
16068: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16069: $domain,$username);
16070: if (exists($lockhash{$lockingkey})) {
16071: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16072: unless ($delresult eq 'ok') {
16073: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16074: }
16075: }
1.462 albertel 16076: }
16077: # Give them a new cookie
1.463 albertel 16078: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16079: : $now.$$.int(rand(10000)));
1.463 albertel 16080: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16081:
16082: # Initialize roles
16083:
1.1062 raeburn 16084: ($userroles,$firstaccenv,$timerintenv) =
16085: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16086: }
16087: # ------------------------------------ Check browser type and MathML capability
16088:
1.1194 raeburn 16089: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16090: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16091:
16092: # ------------------------------------------------------------- Get environment
16093:
16094: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16095: my ($tmp) = keys(%userenv);
1.1275 raeburn 16096: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16097: undef(%userenv);
16098: }
16099: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16100: $form->{'interface'}=$userenv{'interface'};
16101: }
16102: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16103:
16104: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16105: foreach my $option ('interface','localpath','localres') {
16106: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16107: }
16108: # --------------------------------------------------------- Write first profile
16109:
16110: {
16111: my %initial_env =
16112: ("user.name" => $username,
16113: "user.domain" => $domain,
16114: "user.home" => $authhost,
16115: "browser.type" => $clientbrowser,
16116: "browser.version" => $clientversion,
16117: "browser.mathml" => $clientmathml,
16118: "browser.unicode" => $clientunicode,
16119: "browser.os" => $clientos,
1.1137 raeburn 16120: "browser.mobile" => $clientmobile,
1.1141 raeburn 16121: "browser.info" => $clientinfo,
1.1194 raeburn 16122: "browser.osversion" => $clientosversion,
1.462 albertel 16123: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16124: "request.course.fn" => '',
16125: "request.course.uri" => '',
16126: "request.course.sec" => '',
16127: "request.role" => 'cm',
16128: "request.role.adv" => $env{'user.adv'},
16129: "request.host" => $ENV{'REMOTE_ADDR'},);
16130:
16131: if ($form->{'localpath'}) {
16132: $initial_env{"browser.localpath"} = $form->{'localpath'};
16133: $initial_env{"browser.localres"} = $form->{'localres'};
16134: }
16135:
16136: if ($form->{'interface'}) {
16137: $form->{'interface'}=~s/\W//gs;
16138: $initial_env{"browser.interface"} = $form->{'interface'};
16139: $env{'browser.interface'}=$form->{'interface'};
16140: }
16141:
1.1157 raeburn 16142: if ($form->{'iptoken'}) {
16143: my $lonhost = $r->dir_config('lonHostID');
16144: $initial_env{"user.noloadbalance"} = $lonhost;
16145: $env{'user.noloadbalance'} = $lonhost;
16146: }
16147:
1.1268 raeburn 16148: if ($form->{'noloadbalance'}) {
16149: my @hosts = &Apache::lonnet::current_machine_ids();
16150: my $hosthere = $form->{'noloadbalance'};
16151: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16152: $initial_env{"user.noloadbalance"} = $hosthere;
16153: $env{'user.noloadbalance'} = $hosthere;
16154: }
16155: }
16156:
1.1016 raeburn 16157: unless ($domain eq 'public') {
1.1273 raeburn 16158: my %is_adv = ( is_adv => $env{'user.adv'} );
16159: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16160:
16161: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16162: $userenv{'availabletools.'.$tool} =
16163: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16164: undef,\%userenv,\%domdef,\%is_adv);
16165: }
1.980 raeburn 16166:
1.1273 raeburn 16167: foreach my $crstype ('official','unofficial','community','textbook','placement') {
16168: $userenv{'canrequest.'.$crstype} =
16169: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16170: 'reload','requestcourses',
16171: \%userenv,\%domdef,\%is_adv);
16172: }
1.724 raeburn 16173:
1.1273 raeburn 16174: $userenv{'canrequest.author'} =
16175: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16176: 'reload','requestauthor',
1.980 raeburn 16177: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16178: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16179: $domain,$username);
16180: my $reqstatus = $reqauthor{'author_status'};
16181: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16182: if (ref($reqauthor{'author'}) eq 'HASH') {
16183: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16184: $reqauthor{'author'}{'timestamp'};
16185: }
1.1092 raeburn 16186: }
16187: }
16188:
1.462 albertel 16189: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16190:
1.462 albertel 16191: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16192: &GDBM_WRCREAT(),0640)) {
16193: &_add_to_env(\%disk_env,\%initial_env);
16194: &_add_to_env(\%disk_env,\%userenv,'environment.');
16195: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16196: if (ref($firstaccenv) eq 'HASH') {
16197: &_add_to_env(\%disk_env,$firstaccenv);
16198: }
16199: if (ref($timerintenv) eq 'HASH') {
16200: &_add_to_env(\%disk_env,$timerintenv);
16201: }
1.463 albertel 16202: if (ref($args->{'extra_env'})) {
16203: &_add_to_env(\%disk_env,$args->{'extra_env'});
16204: }
1.462 albertel 16205: untie(%disk_env);
16206: } else {
1.705 tempelho 16207: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16208: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16209: return 'error: '.$!;
16210: }
16211: }
16212: $env{'request.role'}='cm';
16213: $env{'request.role.adv'}=$env{'user.adv'};
16214: $env{'browser.type'}=$clientbrowser;
16215:
16216: return $cookie;
16217:
16218: }
16219:
16220: sub _add_to_env {
16221: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16222: if (ref($env_data) eq 'HASH') {
16223: while (my ($key,$value) = each(%$env_data)) {
16224: $idf->{$prefix.$key} = $value;
16225: $env{$prefix.$key} = $value;
16226: }
1.462 albertel 16227: }
16228: }
16229:
1.685 tempelho 16230: # --- Get the symbolic name of a problem and the url
16231: sub get_symb {
16232: my ($request,$silent) = @_;
1.726 raeburn 16233: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16234: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16235: if ($symb eq '') {
16236: if (!$silent) {
1.1071 raeburn 16237: if (ref($request)) {
16238: $request->print("Unable to handle ambiguous references:$url:.");
16239: }
1.685 tempelho 16240: return ();
16241: }
16242: }
16243: &Apache::lonenc::check_decrypt(\$symb);
16244: return ($symb);
16245: }
16246:
16247: # --------------------------------------------------------------Get annotation
16248:
16249: sub get_annotation {
16250: my ($symb,$enc) = @_;
16251:
16252: my $key = $symb;
16253: if (!$enc) {
16254: $key =
16255: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16256: }
16257: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16258: return $annotation{$key};
16259: }
16260:
16261: sub clean_symb {
1.731 raeburn 16262: my ($symb,$delete_enc) = @_;
1.685 tempelho 16263:
16264: &Apache::lonenc::check_decrypt(\$symb);
16265: my $enc = $env{'request.enc'};
1.731 raeburn 16266: if ($delete_enc) {
1.730 raeburn 16267: delete($env{'request.enc'});
16268: }
1.685 tempelho 16269:
16270: return ($symb,$enc);
16271: }
1.462 albertel 16272:
1.1181 raeburn 16273: ############################################################
16274: ############################################################
16275:
16276: =pod
16277:
16278: =head1 Routines for building display used to search for courses
16279:
16280:
16281: =over 4
16282:
16283: =item * &build_filters()
16284:
16285: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16286: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16287: and quotacheck.pl
16288:
1.1181 raeburn 16289:
16290: Inputs:
16291:
16292: filterlist - anonymous array of fields to include as potential filters
16293:
16294: crstype - course type
16295:
16296: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16297: to pop-open a course selector (will contain "extra element").
16298:
16299: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16300:
16301: filter - anonymous hash of criteria and their values
16302:
16303: action - form action
16304:
16305: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16306:
1.1182 raeburn 16307: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16308:
16309: cloneruname - username of owner of new course who wants to clone
16310:
16311: clonerudom - domain of owner of new course who wants to clone
16312:
16313: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16314:
16315: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16316:
16317: codedom - domain
16318:
16319: formname - value of form element named "form".
16320:
16321: fixeddom - domain, if fixed.
16322:
16323: prevphase - value to assign to form element named "phase" when going back to the previous screen
16324:
16325: cnameelement - name of form element in form on opener page which will receive title of selected course
16326:
16327: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16328:
16329: cdomelement - name of form element in form on opener page which will receive domain of selected course
16330:
16331: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16332:
16333: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16334:
16335: clonewarning - warning message about missing information for intended course owner when DC creates a course
16336:
1.1182 raeburn 16337:
1.1181 raeburn 16338: Returns: $output - HTML for display of search criteria, and hidden form elements.
16339:
1.1182 raeburn 16340:
1.1181 raeburn 16341: Side Effects: None
16342:
16343: =cut
16344:
16345: # ---------------------------------------------- search for courses based on last activity etc.
16346:
16347: sub build_filters {
16348: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16349: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16350: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16351: $cnameelement,$cnumelement,$cdomelement,$setroles,
16352: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16353: my ($list,$jscript);
1.1181 raeburn 16354: my $onchange = 'javascript:updateFilters(this)';
16355: my ($domainselectform,$sincefilterform,$createdfilterform,
16356: $ownerdomselectform,$persondomselectform,$instcodeform,
16357: $typeselectform,$instcodetitle);
16358: if ($formname eq '') {
16359: $formname = $caller;
16360: }
16361: foreach my $item (@{$filterlist}) {
16362: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16363: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16364: if ($item eq 'domainfilter') {
16365: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16366: } elsif ($item eq 'coursefilter') {
16367: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16368: } elsif ($item eq 'ownerfilter') {
16369: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16370: } elsif ($item eq 'ownerdomfilter') {
16371: $filter->{'ownerdomfilter'} =
16372: &LONCAPA::clean_domain($filter->{$item});
16373: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16374: 'ownerdomfilter',1);
16375: } elsif ($item eq 'personfilter') {
16376: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16377: } elsif ($item eq 'persondomfilter') {
16378: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16379: 'persondomfilter',1);
16380: } else {
16381: $filter->{$item} =~ s/\W//g;
16382: }
16383: if (!$filter->{$item}) {
16384: $filter->{$item} = '';
16385: }
16386: }
16387: if ($item eq 'domainfilter') {
16388: my $allow_blank = 1;
16389: if ($formname eq 'portform') {
16390: $allow_blank=0;
16391: } elsif ($formname eq 'studentform') {
16392: $allow_blank=0;
16393: }
16394: if ($fixeddom) {
16395: $domainselectform = '<input type="hidden" name="domainfilter"'.
16396: ' value="'.$codedom.'" />'.
16397: &Apache::lonnet::domain($codedom,'description');
16398: } else {
16399: $domainselectform = &select_dom_form($filter->{$item},
16400: 'domainfilter',
16401: $allow_blank,'',$onchange);
16402: }
16403: } else {
16404: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16405: }
16406: }
16407:
16408: # last course activity filter and selection
16409: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16410:
16411: # course created filter and selection
16412: if (exists($filter->{'createdfilter'})) {
16413: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16414: }
16415:
1.1239 raeburn 16416: my $prefix = $crstype;
16417: if ($crstype eq 'Placement') {
16418: $prefix = 'Placement Test'
16419: }
1.1181 raeburn 16420: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16421: 'cac' => "$prefix Activity",
16422: 'ccr' => "$prefix Created",
16423: 'cde' => "$prefix Title",
16424: 'cdo' => "$prefix Domain",
1.1181 raeburn 16425: 'ins' => 'Institutional Code',
16426: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16427: 'cow' => "$prefix Owner/Co-owner",
16428: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16429: 'cog' => 'Type',
16430: );
16431:
16432: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16433: my $typeval = 'Course';
16434: if ($crstype eq 'Community') {
16435: $typeval = 'Community';
1.1239 raeburn 16436: } elsif ($crstype eq 'Placement') {
16437: $typeval = 'Placement';
1.1181 raeburn 16438: }
16439: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16440: } else {
16441: $typeselectform = '<select name="type" size="1"';
16442: if ($onchange) {
16443: $typeselectform .= ' onchange="'.$onchange.'"';
16444: }
16445: $typeselectform .= '>'."\n";
1.1237 raeburn 16446: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16447: my $shown;
16448: if ($posstype eq 'Placement') {
16449: $shown = &mt('Placement Test');
16450: } else {
16451: $shown = &mt($posstype);
16452: }
1.1181 raeburn 16453: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 16454: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 16455: }
16456: $typeselectform.="</select>";
16457: }
16458:
16459: my ($cloneableonlyform,$cloneabletitle);
16460: if (exists($filter->{'cloneableonly'})) {
16461: my $cloneableon = '';
16462: my $cloneableoff = ' checked="checked"';
16463: if ($filter->{'cloneableonly'}) {
16464: $cloneableon = $cloneableoff;
16465: $cloneableoff = '';
16466: }
16467: $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>';
16468: if ($formname eq 'ccrs') {
1.1187 bisitz 16469: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 16470: } else {
16471: $cloneabletitle = &mt('Cloneable by you');
16472: }
16473: }
16474: my $officialjs;
16475: if ($crstype eq 'Course') {
16476: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 16477: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16478: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16479: if ($codedom) {
1.1181 raeburn 16480: $officialjs = 1;
16481: ($instcodeform,$jscript,$$numtitlesref) =
16482: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16483: $officialjs,$codetitlesref);
16484: if ($jscript) {
1.1182 raeburn 16485: $jscript = '<script type="text/javascript">'."\n".
16486: '// <![CDATA['."\n".
16487: $jscript."\n".
16488: '// ]]>'."\n".
16489: '</script>'."\n";
1.1181 raeburn 16490: }
16491: }
16492: if ($instcodeform eq '') {
16493: $instcodeform =
16494: '<input type="text" name="instcodefilter" size="10" value="'.
16495: $list->{'instcodefilter'}.'" />';
16496: $instcodetitle = $lt{'ins'};
16497: } else {
16498: $instcodetitle = $lt{'inc'};
16499: }
16500: if ($fixeddom) {
16501: $instcodetitle .= '<br />('.$codedom.')';
16502: }
16503: }
16504: }
16505: my $output = qq|
16506: <form method="post" name="filterpicker" action="$action">
16507: <input type="hidden" name="form" value="$formname" />
16508: |;
16509: if ($formname eq 'modifycourse') {
16510: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16511: '<input type="hidden" name="prevphase" value="'.
16512: $prevphase.'" />'."\n";
1.1198 musolffc 16513: } elsif ($formname eq 'quotacheck') {
16514: $output .= qq|
16515: <input type="hidden" name="sortby" value="" />
16516: <input type="hidden" name="sortorder" value="" />
16517: |;
16518: } else {
1.1181 raeburn 16519: my $name_input;
16520: if ($cnameelement ne '') {
16521: $name_input = '<input type="hidden" name="cnameelement" value="'.
16522: $cnameelement.'" />';
16523: }
16524: $output .= qq|
1.1182 raeburn 16525: <input type="hidden" name="cnumelement" value="$cnumelement" />
16526: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 16527: $name_input
16528: $roleelement
16529: $multelement
16530: $typeelement
16531: |;
16532: if ($formname eq 'portform') {
16533: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16534: }
16535: }
16536: if ($fixeddom) {
16537: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16538: }
16539: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16540: if ($sincefilterform) {
16541: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16542: .$sincefilterform
16543: .&Apache::lonhtmlcommon::row_closure();
16544: }
16545: if ($createdfilterform) {
16546: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16547: .$createdfilterform
16548: .&Apache::lonhtmlcommon::row_closure();
16549: }
16550: if ($domainselectform) {
16551: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16552: .$domainselectform
16553: .&Apache::lonhtmlcommon::row_closure();
16554: }
16555: if ($typeselectform) {
16556: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16557: $output .= $typeselectform;
16558: } else {
16559: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16560: .$typeselectform
16561: .&Apache::lonhtmlcommon::row_closure();
16562: }
16563: }
16564: if ($instcodeform) {
16565: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16566: .$instcodeform
16567: .&Apache::lonhtmlcommon::row_closure();
16568: }
16569: if (exists($filter->{'ownerfilter'})) {
16570: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16571: '<table><tr><td>'.&mt('Username').'<br />'.
16572: '<input type="text" name="ownerfilter" size="20" value="'.
16573: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16574: $ownerdomselectform.'</td></tr></table>'.
16575: &Apache::lonhtmlcommon::row_closure();
16576: }
16577: if (exists($filter->{'personfilter'})) {
16578: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16579: '<table><tr><td>'.&mt('Username').'<br />'.
16580: '<input type="text" name="personfilter" size="20" value="'.
16581: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16582: $persondomselectform.'</td></tr></table>'.
16583: &Apache::lonhtmlcommon::row_closure();
16584: }
16585: if (exists($filter->{'coursefilter'})) {
16586: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16587: .'<input type="text" name="coursefilter" size="25" value="'
16588: .$list->{'coursefilter'}.'" />'
16589: .&Apache::lonhtmlcommon::row_closure();
16590: }
16591: if ($cloneableonlyform) {
16592: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16593: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16594: }
16595: if (exists($filter->{'descriptfilter'})) {
16596: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16597: .'<input type="text" name="descriptfilter" size="40" value="'
16598: .$list->{'descriptfilter'}.'" />'
16599: .&Apache::lonhtmlcommon::row_closure(1);
16600: }
16601: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16602: '<input type="hidden" name="updater" value="" />'."\n".
16603: '<input type="submit" name="gosearch" value="'.
16604: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16605: return $jscript.$clonewarning.$output;
16606: }
16607:
16608: =pod
16609:
16610: =item * &timebased_select_form()
16611:
1.1182 raeburn 16612: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 16613: filter e.g., Course Activity, Course Created, when searching for courses
16614: or communities
16615:
16616: Inputs:
16617:
16618: item - name of form element (sincefilter or createdfilter)
16619:
16620: filter - anonymous hash of criteria and their values
16621:
16622: Returns: HTML for a select box contained a blank, then six time selections,
16623: with value set in incoming form variables currently selected.
16624:
16625: Side Effects: None
16626:
16627: =cut
16628:
16629: sub timebased_select_form {
16630: my ($item,$filter) = @_;
16631: if (ref($filter) eq 'HASH') {
16632: $filter->{$item} =~ s/[^\d-]//g;
16633: if (!$filter->{$item}) { $filter->{$item}=-1; }
16634: return &select_form(
16635: $filter->{$item},
16636: $item,
16637: { '-1' => '',
16638: '86400' => &mt('today'),
16639: '604800' => &mt('last week'),
16640: '2592000' => &mt('last month'),
16641: '7776000' => &mt('last three months'),
16642: '15552000' => &mt('last six months'),
16643: '31104000' => &mt('last year'),
16644: 'select_form_order' =>
16645: ['-1','86400','604800','2592000','7776000',
16646: '15552000','31104000']});
16647: }
16648: }
16649:
16650: =pod
16651:
16652: =item * &js_changer()
16653:
16654: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 16655: when course type or domain is changed, and also to hide 'Searching ...' on
16656: page load completion for page showing search result.
1.1181 raeburn 16657:
16658: Inputs: None
16659:
1.1183 raeburn 16660: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 16661:
16662: Side Effects: None
16663:
16664: =cut
16665:
16666: sub js_changer {
16667: return <<ENDJS;
16668: <script type="text/javascript">
16669: // <![CDATA[
16670: function updateFilters(caller) {
16671: if (typeof(caller) != "undefined") {
16672: document.filterpicker.updater.value = caller.name;
16673: }
16674: document.filterpicker.submit();
16675: }
1.1183 raeburn 16676:
16677: function hideSearching() {
16678: if (document.getElementById('searching')) {
16679: document.getElementById('searching').style.display = 'none';
16680: }
16681: return;
16682: }
16683:
1.1181 raeburn 16684: // ]]>
16685: </script>
16686:
16687: ENDJS
16688: }
16689:
16690: =pod
16691:
1.1182 raeburn 16692: =item * &search_courses()
16693:
16694: Process selected filters form course search form and pass to lonnet::courseiddump
16695: to retrieve a hash for which keys are courseIDs which match the selected filters.
16696:
16697: Inputs:
16698:
16699: dom - domain being searched
16700:
16701: type - course type ('Course' or 'Community' or '.' if any).
16702:
16703: filter - anonymous hash of criteria and their values
16704:
16705: numtitles - for institutional codes - number of categories
16706:
16707: cloneruname - optional username of new course owner
16708:
16709: clonerudom - optional domain of new course owner
16710:
1.1221 raeburn 16711: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 16712: (used when DC is using course creation form)
16713:
16714: codetitles - reference to array of titles of components in institutional codes (official courses).
16715:
1.1221 raeburn 16716: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16717: (and so can clone automatically)
16718:
16719: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16720:
16721: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16722: courses to clone
1.1182 raeburn 16723:
16724: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16725:
16726:
16727: Side Effects: None
16728:
16729: =cut
16730:
16731:
16732: sub search_courses {
1.1221 raeburn 16733: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16734: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 16735: my (%courses,%showcourses,$cloner);
16736: if (($filter->{'ownerfilter'} ne '') ||
16737: ($filter->{'ownerdomfilter'} ne '')) {
16738: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16739: $filter->{'ownerdomfilter'};
16740: }
16741: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16742: if (!$filter->{$item}) {
16743: $filter->{$item}='.';
16744: }
16745: }
16746: my $now = time;
16747: my $timefilter =
16748: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16749: my ($createdbefore,$createdafter);
16750: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16751: $createdbefore = $now;
16752: $createdafter = $now-$filter->{'createdfilter'};
16753: }
16754: my ($instcodefilter,$regexpok);
16755: if ($numtitles) {
16756: if ($env{'form.official'} eq 'on') {
16757: $instcodefilter =
16758: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16759: $regexpok = 1;
16760: } elsif ($env{'form.official'} eq 'off') {
16761: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16762: unless ($instcodefilter eq '') {
16763: $regexpok = -1;
16764: }
16765: }
16766: } else {
16767: $instcodefilter = $filter->{'instcodefilter'};
16768: }
16769: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16770: if ($type eq '') { $type = '.'; }
16771:
16772: if (($clonerudom ne '') && ($cloneruname ne '')) {
16773: $cloner = $cloneruname.':'.$clonerudom;
16774: }
16775: %courses = &Apache::lonnet::courseiddump($dom,
16776: $filter->{'descriptfilter'},
16777: $timefilter,
16778: $instcodefilter,
16779: $filter->{'combownerfilter'},
16780: $filter->{'coursefilter'},
16781: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 16782: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 16783: $filter->{'cloneableonly'},
16784: $createdbefore,$createdafter,undef,
1.1221 raeburn 16785: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 16786: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16787: my $ccrole;
16788: if ($type eq 'Community') {
16789: $ccrole = 'co';
16790: } else {
16791: $ccrole = 'cc';
16792: }
16793: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16794: $filter->{'persondomfilter'},
16795: 'userroles',undef,
16796: [$ccrole,'in','ad','ep','ta','cr'],
16797: $dom);
16798: foreach my $role (keys(%rolehash)) {
16799: my ($cnum,$cdom,$courserole) = split(':',$role);
16800: my $cid = $cdom.'_'.$cnum;
16801: if (exists($courses{$cid})) {
16802: if (ref($courses{$cid}) eq 'HASH') {
16803: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16804: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 16805: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 16806: }
16807: } else {
16808: $courses{$cid}{roles} = [$courserole];
16809: }
16810: $showcourses{$cid} = $courses{$cid};
16811: }
16812: }
16813: }
16814: %courses = %showcourses;
16815: }
16816: return %courses;
16817: }
16818:
16819: =pod
16820:
1.1181 raeburn 16821: =back
16822:
1.1207 raeburn 16823: =head1 Routines for version requirements for current course.
16824:
16825: =over 4
16826:
16827: =item * &check_release_required()
16828:
16829: Compares required LON-CAPA version with version on server, and
16830: if required version is newer looks for a server with the required version.
16831:
16832: Looks first at servers in user's owen domain; if none suitable, looks at
16833: servers in course's domain are permitted to host sessions for user's domain.
16834:
16835: Inputs:
16836:
16837: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16838:
16839: $courseid - Course ID of current course
16840:
16841: $rolecode - User's current role in course (for switchserver query string).
16842:
16843: $required - LON-CAPA version needed by course (format: Major.Minor).
16844:
16845:
16846: Returns:
16847:
16848: $switchserver - query string tp append to /adm/switchserver call (if
16849: current server's LON-CAPA version is too old.
16850:
16851: $warning - Message is displayed if no suitable server could be found.
16852:
16853: =cut
16854:
16855: sub check_release_required {
16856: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16857: my ($switchserver,$warning);
16858: if ($required ne '') {
16859: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16860: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16861: if ($reqdmajor ne '' && $reqdminor ne '') {
16862: my $otherserver;
16863: if (($major eq '' && $minor eq '') ||
16864: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16865: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16866: my $switchlcrev =
16867: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16868: $userdomserver);
16869: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16870: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16871: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16872: my $cdom = $env{'course.'.$courseid.'.domain'};
16873: if ($cdom ne $env{'user.domain'}) {
16874: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16875: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16876: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16877: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16878: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16879: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16880: my $canhost =
16881: &Apache::lonnet::can_host_session($env{'user.domain'},
16882: $coursedomserver,
16883: $remoterev,
16884: $udomdefaults{'remotesessions'},
16885: $defdomdefaults{'hostedsessions'});
16886:
16887: if ($canhost) {
16888: $otherserver = $coursedomserver;
16889: } else {
16890: $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.");
16891: }
16892: } else {
16893: $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).");
16894: }
16895: } else {
16896: $otherserver = $userdomserver;
16897: }
16898: }
16899: if ($otherserver ne '') {
16900: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16901: }
16902: }
16903: }
16904: return ($switchserver,$warning);
16905: }
16906:
16907: =pod
16908:
16909: =item * &check_release_result()
16910:
16911: Inputs:
16912:
16913: $switchwarning - Warning message if no suitable server found to host session.
16914:
16915: $switchserver - query string to append to /adm/switchserver containing lonHostID
16916: and current role.
16917:
16918: Returns: HTML to display with information about requirement to switch server.
16919: Either displaying warning with link to Roles/Courses screen or
16920: display link to switchserver.
16921:
1.1181 raeburn 16922: =cut
16923:
1.1207 raeburn 16924: sub check_release_result {
16925: my ($switchwarning,$switchserver) = @_;
16926: my $output = &start_page('Selected course unavailable on this server').
16927: '<p class="LC_warning">';
16928: if ($switchwarning) {
16929: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16930: if (&show_course()) {
16931: $output .= &mt('Display courses');
16932: } else {
16933: $output .= &mt('Display roles');
16934: }
16935: $output .= '</a>';
16936: } elsif ($switchserver) {
16937: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16938: '<br />'.
16939: '<a href="/adm/switchserver?'.$switchserver.'">'.
16940: &mt('Switch Server').
16941: '</a>';
16942: }
16943: $output .= '</p>'.&end_page();
16944: return $output;
16945: }
16946:
16947: =pod
16948:
16949: =item * &needs_coursereinit()
16950:
16951: Determine if course contents stored for user's session needs to be
16952: refreshed, because content has changed since "Big Hash" last tied.
16953:
16954: Check for change is made if time last checked is more than 10 minutes ago
16955: (by default).
16956:
16957: Inputs:
16958:
16959: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16960:
16961: $interval (optional) - Time which may elapse (in s) between last check for content
16962: change in current course. (default: 600 s).
16963:
16964: Returns: an array; first element is:
16965:
16966: =over 4
16967:
16968: 'switch' - if content updates mean user's session
16969: needs to be switched to a server running a newer LON-CAPA version
16970:
16971: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16972: on current server hosting user's session
16973:
16974: '' - if no action required.
16975:
16976: =back
16977:
16978: If first item element is 'switch':
16979:
16980: second item is $switchwarning - Warning message if no suitable server found to host session.
16981:
16982: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16983: and current role.
16984:
16985: otherwise: no other elements returned.
16986:
16987: =back
16988:
16989: =cut
16990:
16991: sub needs_coursereinit {
16992: my ($loncaparev,$interval) = @_;
16993: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16994: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16995: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16996: my $now = time;
16997: if ($interval eq '') {
16998: $interval = 600;
16999: }
17000: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 ! raeburn 17001: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
! 17002: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
! 17003: if ($blocked) {
! 17004: return ();
! 17005: }
1.1207 raeburn 17006: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17007: if ($lastchange > $env{'request.course.tied'}) {
17008: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17009: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17010: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17011: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17012: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17013: $curr_reqd_hash{'internal.releaserequired'}});
17014: my ($switchserver,$switchwarning) =
17015: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17016: $curr_reqd_hash{'internal.releaserequired'});
17017: if ($switchwarning ne '' || $switchserver ne '') {
17018: return ('switch',$switchwarning,$switchserver);
17019: }
17020: }
17021: }
17022: return ('update');
17023: }
17024: }
17025: return ();
17026: }
1.1181 raeburn 17027:
1.1083 raeburn 17028: sub update_content_constraints {
17029: my ($cdom,$cnum,$chome,$cid) = @_;
17030: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17031: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
17032: my %checkresponsetypes;
17033: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17034: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17035: if ($item eq 'resourcetag') {
17036: if ($name eq 'responsetype') {
17037: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17038: }
17039: }
17040: }
17041: my $navmap = Apache::lonnavmaps::navmap->new();
17042: if (defined($navmap)) {
17043: my %allresponses;
17044: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
17045: my %responses = $res->responseTypes();
17046: foreach my $key (keys(%responses)) {
17047: next unless(exists($checkresponsetypes{$key}));
17048: $allresponses{$key} += $responses{$key};
17049: }
17050: }
17051: foreach my $key (keys(%allresponses)) {
17052: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17053: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17054: ($reqdmajor,$reqdminor) = ($major,$minor);
17055: }
17056: }
17057: undef($navmap);
17058: }
17059: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17060: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17061: }
17062: return;
17063: }
17064:
1.1110 raeburn 17065: sub allmaps_incourse {
17066: my ($cdom,$cnum,$chome,$cid) = @_;
17067: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17068: $cid = $env{'request.course.id'};
17069: $cdom = $env{'course.'.$cid.'.domain'};
17070: $cnum = $env{'course.'.$cid.'.num'};
17071: $chome = $env{'course.'.$cid.'.home'};
17072: }
17073: my %allmaps = ();
17074: my $lastchange =
17075: &Apache::lonnet::get_coursechange($cdom,$cnum);
17076: if ($lastchange > $env{'request.course.tied'}) {
17077: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17078: unless ($ferr) {
17079: &update_content_constraints($cdom,$cnum,$chome,$cid);
17080: }
17081: }
17082: my $navmap = Apache::lonnavmaps::navmap->new();
17083: if (defined($navmap)) {
17084: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17085: $allmaps{$res->src()} = 1;
17086: }
17087: }
17088: return \%allmaps;
17089: }
17090:
1.1083 raeburn 17091: sub parse_supplemental_title {
17092: my ($title) = @_;
17093:
17094: my ($foldertitle,$renametitle);
17095: if ($title =~ /&&&/) {
17096: $title = &HTML::Entites::decode($title);
17097: }
17098: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17099: $renametitle=$4;
17100: my ($time,$uname,$udom) = ($1,$2,$3);
17101: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17102: my $name = &plainname($uname,$udom);
17103: $name = &HTML::Entities::encode($name,'"<>&\'');
17104: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17105: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17106: $name.': <br />'.$foldertitle;
17107: }
17108: if (wantarray) {
17109: return ($title,$foldertitle,$renametitle);
17110: }
17111: return $title;
17112: }
17113:
1.1143 raeburn 17114: sub recurse_supplemental {
17115: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
17116: if ($suppmap) {
17117: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17118: if ($fatal) {
17119: $errors ++;
17120: } else {
17121: if ($#LONCAPA::map::resources > 0) {
17122: foreach my $res (@LONCAPA::map::resources) {
17123: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17124: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17125: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
17126: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 17127: } else {
17128: $numfiles ++;
17129: }
17130: }
17131: }
17132: }
17133: }
17134: }
17135: return ($numfiles,$errors);
17136: }
17137:
1.1101 raeburn 17138: sub symb_to_docspath {
1.1267 raeburn 17139: my ($symb,$navmapref) = @_;
17140: return unless ($symb && ref($navmapref));
1.1101 raeburn 17141: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17142: if ($resurl=~/\.(sequence|page)$/) {
17143: $mapurl=$resurl;
17144: } elsif ($resurl eq 'adm/navmaps') {
17145: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17146: }
17147: my $mapresobj;
1.1267 raeburn 17148: unless (ref($$navmapref)) {
17149: $$navmapref = Apache::lonnavmaps::navmap->new();
17150: }
17151: if (ref($$navmapref)) {
17152: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17153: }
17154: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17155: my $type=$2;
17156: my $path;
17157: if (ref($mapresobj)) {
17158: my $pcslist = $mapresobj->map_hierarchy();
17159: if ($pcslist ne '') {
17160: foreach my $pc (split(/,/,$pcslist)) {
17161: next if ($pc <= 1);
1.1267 raeburn 17162: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17163: if (ref($res)) {
17164: my $thisurl = $res->src();
17165: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17166: my $thistitle = $res->title();
17167: $path .= '&'.
17168: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17169: &escape($thistitle).
1.1101 raeburn 17170: ':'.$res->randompick().
17171: ':'.$res->randomout().
17172: ':'.$res->encrypted().
17173: ':'.$res->randomorder().
17174: ':'.$res->is_page();
17175: }
17176: }
17177: }
17178: $path =~ s/^\&//;
17179: my $maptitle = $mapresobj->title();
17180: if ($mapurl eq 'default') {
1.1129 raeburn 17181: $maptitle = 'Main Content';
1.1101 raeburn 17182: }
17183: $path .= (($path ne '')? '&' : '').
17184: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17185: &escape($maptitle).
1.1101 raeburn 17186: ':'.$mapresobj->randompick().
17187: ':'.$mapresobj->randomout().
17188: ':'.$mapresobj->encrypted().
17189: ':'.$mapresobj->randomorder().
17190: ':'.$mapresobj->is_page();
17191: } else {
17192: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17193: my $ispage = (($type eq 'page')? 1 : '');
17194: if ($mapurl eq 'default') {
1.1129 raeburn 17195: $maptitle = 'Main Content';
1.1101 raeburn 17196: }
17197: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17198: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17199: }
17200: unless ($mapurl eq 'default') {
17201: $path = 'default&'.
1.1146 raeburn 17202: &escape('Main Content').
1.1101 raeburn 17203: ':::::&'.$path;
17204: }
17205: return $path;
17206: }
17207:
1.1094 raeburn 17208: sub captcha_display {
17209: my ($context,$lonhost) = @_;
17210: my ($output,$error);
1.1234 raeburn 17211: my ($captcha,$pubkey,$privkey,$version) =
17212: &get_captcha_config($context,$lonhost);
1.1095 raeburn 17213: if ($captcha eq 'original') {
1.1094 raeburn 17214: $output = &create_captcha();
17215: unless ($output) {
1.1172 raeburn 17216: $error = 'captcha';
1.1094 raeburn 17217: }
17218: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17219: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17220: unless ($output) {
1.1172 raeburn 17221: $error = 'recaptcha';
1.1094 raeburn 17222: }
17223: }
1.1234 raeburn 17224: return ($output,$error,$captcha,$version);
1.1094 raeburn 17225: }
17226:
17227: sub captcha_response {
17228: my ($context,$lonhost) = @_;
17229: my ($captcha_chk,$captcha_error);
1.1234 raeburn 17230: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 17231: if ($captcha eq 'original') {
1.1094 raeburn 17232: ($captcha_chk,$captcha_error) = &check_captcha();
17233: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17234: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17235: } else {
17236: $captcha_chk = 1;
17237: }
17238: return ($captcha_chk,$captcha_error);
17239: }
17240:
17241: sub get_captcha_config {
17242: my ($context,$lonhost) = @_;
1.1234 raeburn 17243: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17244: my $hostname = &Apache::lonnet::hostname($lonhost);
17245: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17246: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17247: if ($context eq 'usercreation') {
17248: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17249: if (ref($domconfig{$context}) eq 'HASH') {
17250: $hashtocheck = $domconfig{$context}{'cancreate'};
17251: if (ref($hashtocheck) eq 'HASH') {
17252: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17253: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17254: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17255: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17256: }
17257: if ($privkey && $pubkey) {
17258: $captcha = 'recaptcha';
1.1234 raeburn 17259: $version = $hashtocheck->{'recaptchaversion'};
17260: if ($version ne '2') {
17261: $version = 1;
17262: }
1.1095 raeburn 17263: } else {
17264: $captcha = 'original';
17265: }
17266: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17267: $captcha = 'original';
17268: }
1.1094 raeburn 17269: }
1.1095 raeburn 17270: } else {
17271: $captcha = 'captcha';
17272: }
17273: } elsif ($context eq 'login') {
17274: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17275: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17276: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17277: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17278: if ($privkey && $pubkey) {
17279: $captcha = 'recaptcha';
1.1234 raeburn 17280: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17281: if ($version ne '2') {
17282: $version = 1;
17283: }
1.1095 raeburn 17284: } else {
17285: $captcha = 'original';
1.1094 raeburn 17286: }
1.1095 raeburn 17287: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17288: $captcha = 'original';
1.1094 raeburn 17289: }
17290: }
1.1234 raeburn 17291: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17292: }
17293:
17294: sub create_captcha {
17295: my %captcha_params = &captcha_settings();
17296: my ($output,$maxtries,$tries) = ('',10,0);
17297: while ($tries < $maxtries) {
17298: $tries ++;
17299: my $captcha = Authen::Captcha->new (
17300: output_folder => $captcha_params{'output_dir'},
17301: data_folder => $captcha_params{'db_dir'},
17302: );
17303: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17304:
17305: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17306: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17307: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17308: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17309: '<br />'.
17310: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17311: last;
17312: }
17313: }
17314: return $output;
17315: }
17316:
17317: sub captcha_settings {
17318: my %captcha_params = (
17319: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17320: www_output_dir => "/captchaspool",
17321: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17322: numchars => '5',
17323: );
17324: return %captcha_params;
17325: }
17326:
17327: sub check_captcha {
17328: my ($captcha_chk,$captcha_error);
17329: my $code = $env{'form.code'};
17330: my $md5sum = $env{'form.crypt'};
17331: my %captcha_params = &captcha_settings();
17332: my $captcha = Authen::Captcha->new(
17333: output_folder => $captcha_params{'output_dir'},
17334: data_folder => $captcha_params{'db_dir'},
17335: );
1.1109 raeburn 17336: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17337: my %captcha_hash = (
17338: 0 => 'Code not checked (file error)',
17339: -1 => 'Failed: code expired',
17340: -2 => 'Failed: invalid code (not in database)',
17341: -3 => 'Failed: invalid code (code does not match crypt)',
17342: );
17343: if ($captcha_chk != 1) {
17344: $captcha_error = $captcha_hash{$captcha_chk}
17345: }
17346: return ($captcha_chk,$captcha_error);
17347: }
17348:
17349: sub create_recaptcha {
1.1234 raeburn 17350: my ($pubkey,$version) = @_;
17351: if ($version >= 2) {
17352: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17353: } else {
17354: my $use_ssl;
17355: if ($ENV{'SERVER_PORT'} == 443) {
17356: $use_ssl = 1;
17357: }
17358: my $captcha = Captcha::reCAPTCHA->new;
17359: return $captcha->get_options_setter({theme => 'white'})."\n".
17360: $captcha->get_html($pubkey,undef,$use_ssl).
17361: &mt('If the text is hard to read, [_1] will replace them.',
17362: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17363: '<br /><br />';
17364: }
1.1094 raeburn 17365: }
17366:
17367: sub check_recaptcha {
1.1234 raeburn 17368: my ($privkey,$version) = @_;
1.1094 raeburn 17369: my $captcha_chk;
1.1234 raeburn 17370: if ($version >= 2) {
17371: my %info = (
17372: secret => $privkey,
17373: response => $env{'form.g-recaptcha-response'},
17374: remoteip => $ENV{'REMOTE_ADDR'},
17375: );
1.1280 raeburn 17376: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
17377: $request->content(join('&',map {
17378: my $name = escape($_);
17379: "$name=" . ( ref($info{$_}) eq 'ARRAY'
17380: ? join("&$name=", map {escape($_) } @{$info{$_}})
17381: : &escape($info{$_}) );
17382: } keys(%info)));
17383: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 17384: if ($response->is_success) {
17385: my $data = JSON::DWIW->from_json($response->decoded_content);
17386: if (ref($data) eq 'HASH') {
17387: if ($data->{'success'}) {
17388: $captcha_chk = 1;
17389: }
17390: }
17391: }
17392: } else {
17393: my $captcha = Captcha::reCAPTCHA->new;
17394: my $captcha_result =
17395: $captcha->check_answer(
17396: $privkey,
17397: $ENV{'REMOTE_ADDR'},
17398: $env{'form.recaptcha_challenge_field'},
17399: $env{'form.recaptcha_response_field'},
17400: );
17401: if ($captcha_result->{is_valid}) {
17402: $captcha_chk = 1;
17403: }
1.1094 raeburn 17404: }
17405: return $captcha_chk;
17406: }
17407:
1.1174 raeburn 17408: sub emailusername_info {
1.1244 raeburn 17409: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 17410: my %titles = &Apache::lonlocal::texthash (
17411: lastname => 'Last Name',
17412: firstname => 'First Name',
17413: institution => 'School/college/university',
17414: location => "School's city, state/province, country",
17415: web => "School's web address",
17416: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 17417: id => 'Student/Employee ID',
1.1174 raeburn 17418: );
17419: return (\@fields,\%titles);
17420: }
17421:
1.1161 raeburn 17422: sub cleanup_html {
17423: my ($incoming) = @_;
17424: my $outgoing;
17425: if ($incoming ne '') {
17426: $outgoing = $incoming;
17427: $outgoing =~ s/;/;/g;
17428: $outgoing =~ s/\#/#/g;
17429: $outgoing =~ s/\&/&/g;
17430: $outgoing =~ s/</</g;
17431: $outgoing =~ s/>/>/g;
17432: $outgoing =~ s/\(/(/g;
17433: $outgoing =~ s/\)/)/g;
17434: $outgoing =~ s/"/"/g;
17435: $outgoing =~ s/'/'/g;
17436: $outgoing =~ s/\$/$/g;
17437: $outgoing =~ s{/}{/}g;
17438: $outgoing =~ s/=/=/g;
17439: $outgoing =~ s/\\/\/g
17440: }
17441: return $outgoing;
17442: }
17443:
1.1190 musolffc 17444: # Checks for critical messages and returns a redirect url if one exists.
17445: # $interval indicates how often to check for messages.
1.1282 ! raeburn 17446: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 17447: sub critical_redirect {
1.1282 ! raeburn 17448: my ($interval,$context) = @_;
1.1190 musolffc 17449: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 ! raeburn 17450: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
! 17451: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
! 17452: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
! 17453: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
! 17454: if ($blocked) {
! 17455: my $checkrole = "cm./$cdom/$cnum";
! 17456: if ($env{'request.course.sec'} ne '') {
! 17457: $checkrole .= "/$env{'request.course.sec'}";
! 17458: }
! 17459: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
! 17460: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
! 17461: return;
! 17462: }
! 17463: }
! 17464: }
1.1190 musolffc 17465: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17466: $env{'user.name'});
17467: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 17468: my $redirecturl;
1.1190 musolffc 17469: if ($what[0]) {
17470: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17471: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 17472: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17473: return (1, $url);
1.1190 musolffc 17474: }
1.1191 raeburn 17475: }
17476: }
17477: return ();
1.1190 musolffc 17478: }
17479:
1.1174 raeburn 17480: # Use:
17481: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17482: #
17483: ##################################################
17484: # password associated functions #
17485: ##################################################
17486: sub des_keys {
17487: # Make a new key for DES encryption.
17488: # Each key has two parts which are returned separately.
17489: # Please note: Each key must be passed through the &hex function
17490: # before it is output to the web browser. The hex versions cannot
17491: # be used to decrypt.
17492: my @hexstr=('0','1','2','3','4','5','6','7',
17493: '8','9','a','b','c','d','e','f');
17494: my $lkey='';
17495: for (0..7) {
17496: $lkey.=$hexstr[rand(15)];
17497: }
17498: my $ukey='';
17499: for (0..7) {
17500: $ukey.=$hexstr[rand(15)];
17501: }
17502: return ($lkey,$ukey);
17503: }
17504:
17505: sub des_decrypt {
17506: my ($key,$cyphertext) = @_;
17507: my $keybin=pack("H16",$key);
17508: my $cypher;
17509: if ($Crypt::DES::VERSION>=2.03) {
17510: $cypher=new Crypt::DES $keybin;
17511: } else {
17512: $cypher=new DES $keybin;
17513: }
1.1233 raeburn 17514: my $plaintext='';
17515: my $cypherlength = length($cyphertext);
17516: my $numchunks = int($cypherlength/32);
17517: for (my $j=0; $j<$numchunks; $j++) {
17518: my $start = $j*32;
17519: my $cypherblock = substr($cyphertext,$start,32);
17520: my $chunk =
17521: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17522: $chunk .=
17523: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17524: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17525: $plaintext .= $chunk;
17526: }
1.1174 raeburn 17527: return $plaintext;
17528: }
17529:
1.112 bowersj2 17530: 1;
17531: __END__;
1.41 ng 17532:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>