Annotation of loncom/interface/loncommon.pm, revision 1.1284
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1284 ! raeburn 4: # $Id: loncommon.pm,v 1.1283 2017/07/10 12:35:07 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1280 raeburn 74: use LONCAPA::LWPReq;
1.657 raeburn 75: use DateTime::TimeZone;
1.1241 raeburn 76: use DateTime::Locale;
1.1220 raeburn 77: use Encode();
1.1091 foxr 78: use Text::Aspell;
1.1094 raeburn 79: use Authen::Captcha;
80: use Captcha::reCAPTCHA;
1.1234 raeburn 81: use JSON::DWIW;
82: use LWP::UserAgent;
1.1174 raeburn 83: use Crypt::DES;
84: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 85: use MIME::Lite;
86: use MIME::Types;
1.117 www 87:
1.517 raeburn 88: # ---------------------------------------------- Designs
89: use vars qw(%defaultdesign);
90:
1.22 www 91: my $readit;
92:
1.517 raeburn 93:
1.157 matthew 94: ##
95: ## Global Variables
96: ##
1.46 matthew 97:
1.643 foxr 98:
99: # ----------------------------------------------- SSI with retries:
100: #
101:
102: =pod
103:
1.648 raeburn 104: =head1 Server Side include with retries:
1.643 foxr 105:
106: =over 4
107:
1.648 raeburn 108: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 109:
110: Performs an ssi with some number of retries. Retries continue either
111: until the result is ok or until the retry count supplied by the
112: caller is exhausted.
113:
114: Inputs:
1.648 raeburn 115:
116: =over 4
117:
1.643 foxr 118: resource - Identifies the resource to insert.
1.648 raeburn 119:
1.643 foxr 120: retries - Count of the number of retries allowed.
1.648 raeburn 121:
1.643 foxr 122: form - Hash that identifies the rendering options.
123:
1.648 raeburn 124: =back
125:
126: Returns:
127:
128: =over 4
129:
1.643 foxr 130: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 131:
1.643 foxr 132: response - The response from the last attempt (which may or may not have been successful.
133:
1.648 raeburn 134: =back
135:
136: =back
137:
1.643 foxr 138: =cut
139:
140: sub ssi_with_retries {
141: my ($resource, $retries, %form) = @_;
142:
143:
144: my $ok = 0; # True if we got a good response.
145: my $content;
146: my $response;
147:
148: # Try to get the ssi done. within the retries count:
149:
150: do {
151: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
152: $ok = $response->is_success;
1.650 www 153: if (!$ok) {
154: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
155: }
1.643 foxr 156: $retries--;
157: } while (!$ok && ($retries > 0));
158:
159: if (!$ok) {
160: $content = ''; # On error return an empty content.
161: }
162: return ($content, $response);
163:
164: }
165:
166:
167:
1.20 www 168: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 169: my %language;
1.124 www 170: my %supported_language;
1.1088 foxr 171: my %supported_codes;
1.1048 foxr 172: my %latex_language; # For choosing hyphenation in <transl..>
173: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 174: my %cprtag;
1.192 taceyjo1 175: my %scprtag;
1.351 www 176: my %fe; my %fd; my %fm;
1.41 ng 177: my %category_extensions;
1.12 harris41 178:
1.46 matthew 179: # ---------------------------------------------- Thesaurus variables
1.144 matthew 180: #
181: # %Keywords:
182: # A hash used by &keyword to determine if a word is considered a keyword.
183: # $thesaurus_db_file
184: # Scalar containing the full path to the thesaurus database.
1.46 matthew 185:
186: my %Keywords;
187: my $thesaurus_db_file;
188:
1.144 matthew 189: #
190: # Initialize values from language.tab, copyright.tab, filetypes.tab,
191: # thesaurus.tab, and filecategories.tab.
192: #
1.18 www 193: BEGIN {
1.46 matthew 194: # Variable initialization
195: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
196: #
1.22 www 197: unless ($readit) {
1.12 harris41 198: # ------------------------------------------------------------------- languages
199: {
1.158 raeburn 200: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
201: '/language.tab';
202: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
1.1088 foxr 206: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 207: $language{$key}=$val.' - '.$enc;
208: if ($sup) {
209: $supported_language{$key}=$sup;
1.1088 foxr 210: $supported_codes{$key} = $code;
1.158 raeburn 211: }
1.1048 foxr 212: if ($latex) {
213: $latex_language_bykey{$key} = $latex;
1.1088 foxr 214: $latex_language{$code} = $latex;
1.1048 foxr 215: }
1.158 raeburn 216: }
217: close($fh);
218: }
1.12 harris41 219: }
220: # ------------------------------------------------------------------ copyrights
221: {
1.158 raeburn 222: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
223: '/copyright.tab';
224: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 225: while (my $line = <$fh>) {
226: next if ($line=~/^\#/);
227: chomp($line);
228: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 229: $cprtag{$key}=$val;
230: }
231: close($fh);
232: }
1.12 harris41 233: }
1.351 www 234: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 235: {
236: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
237: '/source_copyright.tab';
238: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 239: while (my $line = <$fh>) {
240: next if ($line =~ /^\#/);
241: chomp($line);
242: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 243: $scprtag{$key}=$val;
244: }
245: close($fh);
246: }
247: }
1.63 www 248:
1.517 raeburn 249: # -------------------------------------------------------------- default domain designs
1.63 www 250: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 251: my $designfile = $designdir.'/default.tab';
252: if ( open (my $fh,"<$designfile") ) {
253: while (my $line = <$fh>) {
254: next if ($line =~ /^\#/);
255: chomp($line);
256: my ($key,$val)=(split(/\=/,$line));
257: if ($val) { $defaultdesign{$key}=$val; }
258: }
259: close($fh);
1.63 www 260: }
261:
1.15 harris41 262: # ------------------------------------------------------------- file categories
263: {
1.158 raeburn 264: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
265: '/filecategories.tab';
266: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 267: while (my $line = <$fh>) {
268: next if ($line =~ /^\#/);
269: chomp($line);
270: my ($extension,$category)=(split(/\s+/,$line,2));
1.1263 raeburn 271: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 272: }
273: close($fh);
274: }
275:
1.15 harris41 276: }
1.12 harris41 277: # ------------------------------------------------------------------ file types
278: {
1.158 raeburn 279: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
280: '/filetypes.tab';
281: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 282: while (my $line = <$fh>) {
283: next if ($line =~ /^\#/);
284: chomp($line);
285: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 286: if ($descr ne '') {
287: $fe{$ending}=lc($emb);
288: $fd{$ending}=$descr;
1.351 www 289: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 290: }
291: }
292: close($fh);
293: }
1.12 harris41 294: }
1.22 www 295: &Apache::lonnet::logthis(
1.705 tempelho 296: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 297: $readit=1;
1.46 matthew 298: } # end of unless($readit)
1.32 matthew 299:
300: }
1.112 bowersj2 301:
1.42 matthew 302: ###############################################################
303: ## HTML and Javascript Helper Functions ##
304: ###############################################################
305:
306: =pod
307:
1.112 bowersj2 308: =head1 HTML and Javascript Functions
1.42 matthew 309:
1.112 bowersj2 310: =over 4
311:
1.648 raeburn 312: =item * &browser_and_searcher_javascript()
1.112 bowersj2 313:
314: X<browsing, javascript>X<searching, javascript>Returns a string
315: containing javascript with two functions, C<openbrowser> and
316: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
317: tags.
1.42 matthew 318:
1.648 raeburn 319: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 320:
321: inputs: formname, elementname, only, omit
322:
323: formname and elementname indicate the name of the html form and name of
324: the element that the results of the browsing selection are to be placed in.
325:
326: Specifying 'only' will restrict the browser to displaying only files
1.185 www 327: with the given extension. Can be a comma separated list.
1.42 matthew 328:
329: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 330: with the given extension. Can be a comma separated list.
1.42 matthew 331:
1.648 raeburn 332: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 333:
334: Inputs: formname, elementname
335:
336: formname and elementname specify the name of the html form and the name
337: of the element the selection from the search results will be placed in.
1.542 raeburn 338:
1.42 matthew 339: =cut
340:
341: sub browser_and_searcher_javascript {
1.199 albertel 342: my ($mode)=@_;
343: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 344: my $resurl=&escape_single(&lastresurl());
1.42 matthew 345: return <<END;
1.219 albertel 346: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 347: var editbrowser = null;
1.135 albertel 348: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 349: var url = '$resurl/?';
1.42 matthew 350: if (editbrowser == null) {
351: url += 'launch=1&';
352: }
353: url += 'catalogmode=interactive&';
1.199 albertel 354: url += 'mode=$mode&';
1.611 albertel 355: url += 'inhibitmenu=yes&';
1.42 matthew 356: url += 'form=' + formname + '&';
357: if (only != null) {
358: url += 'only=' + only + '&';
1.217 albertel 359: } else {
360: url += 'only=&';
361: }
1.42 matthew 362: if (omit != null) {
363: url += 'omit=' + omit + '&';
1.217 albertel 364: } else {
365: url += 'omit=&';
366: }
1.135 albertel 367: if (titleelement != null) {
368: url += 'titleelement=' + titleelement + '&';
1.217 albertel 369: } else {
370: url += 'titleelement=&';
371: }
1.42 matthew 372: url += 'element=' + elementname + '';
373: var title = 'Browser';
1.435 albertel 374: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 375: options += ',width=700,height=600';
376: editbrowser = open(url,title,options,'1');
377: editbrowser.focus();
378: }
379: var editsearcher;
1.135 albertel 380: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 381: var url = '/adm/searchcat?';
382: if (editsearcher == null) {
383: url += 'launch=1&';
384: }
385: url += 'catalogmode=interactive&';
1.199 albertel 386: url += 'mode=$mode&';
1.42 matthew 387: url += 'form=' + formname + '&';
1.135 albertel 388: if (titleelement != null) {
389: url += 'titleelement=' + titleelement + '&';
1.217 albertel 390: } else {
391: url += 'titleelement=&';
392: }
1.42 matthew 393: url += 'element=' + elementname + '';
394: var title = 'Search';
1.435 albertel 395: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 396: options += ',width=700,height=600';
397: editsearcher = open(url,title,options,'1');
398: editsearcher.focus();
399: }
1.219 albertel 400: // END LON-CAPA Internal -->
1.42 matthew 401: END
1.170 www 402: }
403:
404: sub lastresurl {
1.258 albertel 405: if ($env{'environment.lastresurl'}) {
406: return $env{'environment.lastresurl'}
1.170 www 407: } else {
408: return '/res';
409: }
410: }
411:
412: sub storeresurl {
413: my $resurl=&Apache::lonnet::clutter(shift);
414: unless ($resurl=~/^\/res/) { return 0; }
415: $resurl=~s/\/$//;
416: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 417: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 418: return 1;
1.42 matthew 419: }
420:
1.74 www 421: sub studentbrowser_javascript {
1.111 www 422: unless (
1.258 albertel 423: (($env{'request.course.id'}) &&
1.302 albertel 424: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
425: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
426: '/'.$env{'request.course.sec'})
427: ))
1.258 albertel 428: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 429: ) { return ''; }
1.74 www 430: return (<<'ENDSTDBRW');
1.776 bisitz 431: <script type="text/javascript" language="Javascript">
1.824 bisitz 432: // <![CDATA[
1.74 www 433: var stdeditbrowser;
1.999 www 434: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 435: var url = '/adm/pickstudent?';
436: var filter;
1.558 albertel 437: if (!ignorefilter) {
438: eval('filter=document.'+formname+'.'+uname+'.value;');
439: }
1.74 www 440: if (filter != null) {
441: if (filter != '') {
442: url += 'filter='+filter+'&';
443: }
444: }
445: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 446: '&udomelement='+udom+
447: '&clicker='+clicker;
1.111 www 448: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 449: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 450: var title = 'Student_Browser';
1.74 www 451: var options = 'scrollbars=1,resizable=1,menubar=0';
452: options += ',width=700,height=600';
453: stdeditbrowser = open(url,title,options,'1');
454: stdeditbrowser.focus();
455: }
1.824 bisitz 456: // ]]>
1.74 www 457: </script>
458: ENDSTDBRW
459: }
1.42 matthew 460:
1.1003 www 461: sub resourcebrowser_javascript {
462: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 463: return (<<'ENDRESBRW');
1.1003 www 464: <script type="text/javascript" language="Javascript">
465: // <![CDATA[
466: var reseditbrowser;
1.1004 www 467: function openresbrowser(formname,reslink) {
1.1005 www 468: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 469: var title = 'Resource_Browser';
470: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 471: options += ',width=700,height=500';
1.1004 www 472: reseditbrowser = open(url,title,options,'1');
473: reseditbrowser.focus();
1.1003 www 474: }
475: // ]]>
476: </script>
1.1004 www 477: ENDRESBRW
1.1003 www 478: }
479:
1.74 www 480: sub selectstudent_link {
1.999 www 481: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
482: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
483: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
484: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 485: if ($env{'request.course.id'}) {
1.302 albertel 486: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
487: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
488: '/'.$env{'request.course.sec'})) {
1.111 www 489: return '';
490: }
1.999 www 491: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 492: if ($courseadvonly) {
493: $callargs .= ",'',1,1";
494: }
495: return '<span class="LC_nobreak">'.
496: '<a href="javascript:openstdbrowser('.$callargs.');">'.
497: &mt('Select User').'</a></span>';
1.74 www 498: }
1.258 albertel 499: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 500: $callargs .= ",'',1";
1.793 raeburn 501: return '<span class="LC_nobreak">'.
502: '<a href="javascript:openstdbrowser('.$callargs.');">'.
503: &mt('Select User').'</a></span>';
1.111 www 504: }
505: return '';
1.91 www 506: }
507:
1.1004 www 508: sub selectresource_link {
509: my ($form,$reslink,$arg)=@_;
510:
511: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
512: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
513: unless ($env{'request.course.id'}) { return $arg; }
514: return '<span class="LC_nobreak">'.
515: '<a href="javascript:openresbrowser('.$callargs.');">'.
516: $arg.'</a></span>';
517: }
518:
519:
520:
1.653 raeburn 521: sub authorbrowser_javascript {
522: return <<"ENDAUTHORBRW";
1.776 bisitz 523: <script type="text/javascript" language="JavaScript">
1.824 bisitz 524: // <![CDATA[
1.653 raeburn 525: var stdeditbrowser;
526:
527: function openauthorbrowser(formname,udom) {
528: var url = '/adm/pickauthor?';
529: url += 'form='+formname+'&roledom='+udom;
530: var title = 'Author_Browser';
531: var options = 'scrollbars=1,resizable=1,menubar=0';
532: options += ',width=700,height=600';
533: stdeditbrowser = open(url,title,options,'1');
534: stdeditbrowser.focus();
535: }
536:
1.824 bisitz 537: // ]]>
1.653 raeburn 538: </script>
539: ENDAUTHORBRW
540: }
541:
1.91 www 542: sub coursebrowser_javascript {
1.1116 raeburn 543: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 544: $credits_element,$instcode) = @_;
1.932 raeburn 545: my $wintitle = 'Course_Browser';
1.931 raeburn 546: if ($crstype eq 'Community') {
1.932 raeburn 547: $wintitle = 'Community_Browser';
1.909 raeburn 548: }
1.876 raeburn 549: my $id_functions = &javascript_index_functions();
550: my $output = '
1.776 bisitz 551: <script type="text/javascript" language="JavaScript">
1.824 bisitz 552: // <![CDATA[
1.468 raeburn 553: var stdeditbrowser;'."\n";
1.876 raeburn 554:
555: $output .= <<"ENDSTDBRW";
1.909 raeburn 556: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 557: var url = '/adm/pickcourse?';
1.895 raeburn 558: var formid = getFormIdByName(formname);
1.876 raeburn 559: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 560: if (domainfilter != null) {
561: if (domainfilter != '') {
562: url += 'domainfilter='+domainfilter+'&';
563: }
564: }
1.91 www 565: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 566: '&cdomelement='+udom+
567: '&cnameelement='+desc;
1.468 raeburn 568: if (extra_element !=null && extra_element != '') {
1.594 raeburn 569: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 570: url += '&roleelement='+extra_element;
571: if (domainfilter == null || domainfilter == '') {
572: url += '&domainfilter='+extra_element;
573: }
1.234 raeburn 574: }
1.468 raeburn 575: else {
576: if (formname == 'portform') {
577: url += '&setroles='+extra_element;
1.800 raeburn 578: } else {
579: if (formname == 'rules') {
580: url += '&fixeddom='+extra_element;
581: }
1.468 raeburn 582: }
583: }
1.230 raeburn 584: }
1.909 raeburn 585: if (type != null && type != '') {
586: url += '&type='+type;
587: }
588: if (type_elem != null && type_elem != '') {
589: url += '&typeelement='+type_elem;
590: }
1.872 raeburn 591: if (formname == 'ccrs') {
592: var ownername = document.forms[formid].ccuname.value;
593: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 594: url += '&cloner='+ownername+':'+ownerdom;
595: if (type == 'Course') {
596: url += '&crscode='+document.forms[formid].crscode.value;
597: }
1.1221 raeburn 598: }
599: if (formname == 'requestcrs') {
600: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 601: }
1.293 raeburn 602: if (multflag !=null && multflag != '') {
603: url += '&multiple='+multflag;
604: }
1.909 raeburn 605: var title = '$wintitle';
1.91 www 606: var options = 'scrollbars=1,resizable=1,menubar=0';
607: options += ',width=700,height=600';
608: stdeditbrowser = open(url,title,options,'1');
609: stdeditbrowser.focus();
610: }
1.876 raeburn 611: $id_functions
612: ENDSTDBRW
1.1116 raeburn 613: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
614: $output .= &setsec_javascript($sec_element,$formname,$role_element,
615: $credits_element);
1.876 raeburn 616: }
617: $output .= '
618: // ]]>
619: </script>';
620: return $output;
621: }
622:
623: sub javascript_index_functions {
624: return <<"ENDJS";
625:
626: function getFormIdByName(formname) {
627: for (var i=0;i<document.forms.length;i++) {
628: if (document.forms[i].name == formname) {
629: return i;
630: }
631: }
632: return -1;
633: }
634:
635: function getIndexByName(formid,item) {
636: for (var i=0;i<document.forms[formid].elements.length;i++) {
637: if (document.forms[formid].elements[i].name == item) {
638: return i;
639: }
640: }
641: return -1;
642: }
1.468 raeburn 643:
1.876 raeburn 644: function getDomainFromSelectbox(formname,udom) {
645: var userdom;
646: var formid = getFormIdByName(formname);
647: if (formid > -1) {
648: var domid = getIndexByName(formid,udom);
649: if (domid > -1) {
650: if (document.forms[formid].elements[domid].type == 'select-one') {
651: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
652: }
653: if (document.forms[formid].elements[domid].type == 'hidden') {
654: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 655: }
656: }
657: }
1.876 raeburn 658: return userdom;
659: }
660:
661: ENDJS
1.468 raeburn 662:
1.876 raeburn 663: }
664:
1.1017 raeburn 665: sub javascript_array_indexof {
1.1018 raeburn 666: return <<ENDJS;
1.1017 raeburn 667: <script type="text/javascript" language="JavaScript">
668: // <![CDATA[
669:
670: if (!Array.prototype.indexOf) {
671: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
672: "use strict";
673: if (this === void 0 || this === null) {
674: throw new TypeError();
675: }
676: var t = Object(this);
677: var len = t.length >>> 0;
678: if (len === 0) {
679: return -1;
680: }
681: var n = 0;
682: if (arguments.length > 0) {
683: n = Number(arguments[1]);
1.1088 foxr 684: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 685: n = 0;
686: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
687: n = (n > 0 || -1) * Math.floor(Math.abs(n));
688: }
689: }
690: if (n >= len) {
691: return -1;
692: }
693: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
694: for (; k < len; k++) {
695: if (k in t && t[k] === searchElement) {
696: return k;
697: }
698: }
699: return -1;
700: }
701: }
702:
703: // ]]>
704: </script>
705:
706: ENDJS
707:
708: }
709:
1.876 raeburn 710: sub userbrowser_javascript {
711: my $id_functions = &javascript_index_functions();
712: return <<"ENDUSERBRW";
713:
1.888 raeburn 714: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 715: var url = '/adm/pickuser?';
716: var userdom = getDomainFromSelectbox(formname,udom);
717: if (userdom != null) {
718: if (userdom != '') {
719: url += 'srchdom='+userdom+'&';
720: }
721: }
722: url += 'form=' + formname + '&unameelement='+uname+
723: '&udomelement='+udom+
724: '&ulastelement='+ulast+
725: '&ufirstelement='+ufirst+
726: '&uemailelement='+uemail+
1.881 raeburn 727: '&hideudomelement='+hideudom+
728: '&coursedom='+crsdom;
1.888 raeburn 729: if ((caller != null) && (caller != undefined)) {
730: url += '&caller='+caller;
731: }
1.876 raeburn 732: var title = 'User_Browser';
733: var options = 'scrollbars=1,resizable=1,menubar=0';
734: options += ',width=700,height=600';
735: var stdeditbrowser = open(url,title,options,'1');
736: stdeditbrowser.focus();
737: }
738:
1.888 raeburn 739: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 740: var formid = getFormIdByName(formname);
741: if (formid > -1) {
1.888 raeburn 742: var unameid = getIndexByName(formid,uname);
1.876 raeburn 743: var domid = getIndexByName(formid,udom);
744: var hidedomid = getIndexByName(formid,origdom);
745: if (hidedomid > -1) {
746: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 747: var unameval = document.forms[formid].elements[unameid].value;
748: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
749: if (domid > -1) {
750: var slct = document.forms[formid].elements[domid];
751: if (slct.type == 'select-one') {
752: var i;
753: for (i=0;i<slct.length;i++) {
754: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
755: }
756: }
757: if (slct.type == 'hidden') {
758: slct.value = fixeddom;
1.876 raeburn 759: }
760: }
1.468 raeburn 761: }
762: }
763: }
1.876 raeburn 764: return;
765: }
766:
767: $id_functions
768: ENDUSERBRW
1.468 raeburn 769: }
770:
771: sub setsec_javascript {
1.1116 raeburn 772: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 773: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
774: $communityrolestr);
775: if ($role_element ne '') {
776: my @allroles = ('st','ta','ep','in','ad');
777: foreach my $crstype ('Course','Community') {
778: if ($crstype eq 'Community') {
779: foreach my $role (@allroles) {
780: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
781: }
782: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
783: } else {
784: foreach my $role (@allroles) {
785: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
786: }
787: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
788: }
789: }
790: $rolestr = '"'.join('","',@allroles).'"';
791: $courserolestr = '"'.join('","',@courserolenames).'"';
792: $communityrolestr = '"'.join('","',@communityrolenames).'"';
793: }
1.468 raeburn 794: my $setsections = qq|
795: function setSect(sectionlist) {
1.629 raeburn 796: var sectionsArray = new Array();
797: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
798: sectionsArray = sectionlist.split(",");
799: }
1.468 raeburn 800: var numSections = sectionsArray.length;
801: document.$formname.$sec_element.length = 0;
802: if (numSections == 0) {
803: document.$formname.$sec_element.multiple=false;
804: document.$formname.$sec_element.size=1;
805: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
806: } else {
807: if (numSections == 1) {
808: document.$formname.$sec_element.multiple=false;
809: document.$formname.$sec_element.size=1;
810: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
811: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
812: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
813: } else {
814: for (var i=0; i<numSections; i++) {
815: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
816: }
817: document.$formname.$sec_element.multiple=true
818: if (numSections < 3) {
819: document.$formname.$sec_element.size=numSections;
820: } else {
821: document.$formname.$sec_element.size=3;
822: }
823: document.$formname.$sec_element.options[0].selected = false
824: }
825: }
1.91 www 826: }
1.905 raeburn 827:
828: function setRole(crstype) {
1.468 raeburn 829: |;
1.905 raeburn 830: if ($role_element eq '') {
831: $setsections .= ' return;
832: }
833: ';
834: } else {
835: $setsections .= qq|
836: var elementLength = document.$formname.$role_element.length;
837: var allroles = Array($rolestr);
838: var courserolenames = Array($courserolestr);
839: var communityrolenames = Array($communityrolestr);
840: if (elementLength != undefined) {
841: if (document.$formname.$role_element.options[5].value == 'cc') {
842: if (crstype == 'Course') {
843: return;
844: } else {
845: allroles[5] = 'co';
846: for (var i=0; i<6; i++) {
847: document.$formname.$role_element.options[i].value = allroles[i];
848: document.$formname.$role_element.options[i].text = communityrolenames[i];
849: }
850: }
851: } else {
852: if (crstype == 'Community') {
853: return;
854: } else {
855: allroles[5] = 'cc';
856: for (var i=0; i<6; i++) {
857: document.$formname.$role_element.options[i].value = allroles[i];
858: document.$formname.$role_element.options[i].text = courserolenames[i];
859: }
860: }
861: }
862: }
863: return;
864: }
865: |;
866: }
1.1116 raeburn 867: if ($credits_element) {
868: $setsections .= qq|
869: function setCredits(defaultcredits) {
870: document.$formname.$credits_element.value = defaultcredits;
871: return;
872: }
873: |;
874: }
1.468 raeburn 875: return $setsections;
876: }
877:
1.91 www 878: sub selectcourse_link {
1.909 raeburn 879: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
880: $typeelement) = @_;
881: my $type = $selecttype;
1.871 raeburn 882: my $linktext = &mt('Select Course');
883: if ($selecttype eq 'Community') {
1.909 raeburn 884: $linktext = &mt('Select Community');
1.1239 raeburn 885: } elsif ($selecttype eq 'Placement') {
886: $linktext = &mt('Select Placement Test');
1.906 raeburn 887: } elsif ($selecttype eq 'Course/Community') {
888: $linktext = &mt('Select Course/Community');
1.909 raeburn 889: $type = '';
1.1019 raeburn 890: } elsif ($selecttype eq 'Select') {
891: $linktext = &mt('Select');
892: $type = '';
1.871 raeburn 893: }
1.787 bisitz 894: return '<span class="LC_nobreak">'
895: ."<a href='"
896: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
897: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 898: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 899: ."'>".$linktext.'</a>'
1.787 bisitz 900: .'</span>';
1.74 www 901: }
1.42 matthew 902:
1.653 raeburn 903: sub selectauthor_link {
904: my ($form,$udom)=@_;
905: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
906: &mt('Select Author').'</a>';
907: }
908:
1.876 raeburn 909: sub selectuser_link {
1.881 raeburn 910: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 911: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 912: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 913: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 914: ');">'.$linktext.'</a>';
1.876 raeburn 915: }
916:
1.273 raeburn 917: sub check_uncheck_jscript {
918: my $jscript = <<"ENDSCRT";
919: function checkAll(field) {
920: if (field.length > 0) {
921: for (i = 0; i < field.length; i++) {
1.1093 raeburn 922: if (!field[i].disabled) {
923: field[i].checked = true;
924: }
1.273 raeburn 925: }
926: } else {
1.1093 raeburn 927: if (!field.disabled) {
928: field.checked = true;
929: }
1.273 raeburn 930: }
931: }
932:
933: function uncheckAll(field) {
934: if (field.length > 0) {
935: for (i = 0; i < field.length; i++) {
936: field[i].checked = false ;
1.543 albertel 937: }
938: } else {
1.273 raeburn 939: field.checked = false ;
940: }
941: }
942: ENDSCRT
943: return $jscript;
944: }
945:
1.656 www 946: sub select_timezone {
1.1256 raeburn 947: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
948: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 949: if ($includeempty) {
950: $output .= '<option value=""';
951: if (($selected eq '') || ($selected eq 'local')) {
952: $output .= ' selected="selected" ';
953: }
954: $output .= '> </option>';
955: }
1.657 raeburn 956: my @timezones = DateTime::TimeZone->all_names;
957: foreach my $tzone (@timezones) {
958: $output.= '<option value="'.$tzone.'"';
959: if ($tzone eq $selected) {
960: $output.=' selected="selected"';
961: }
962: $output.=">$tzone</option>\n";
1.656 www 963: }
964: $output.="</select>";
965: return $output;
966: }
1.273 raeburn 967:
1.687 raeburn 968: sub select_datelocale {
1.1256 raeburn 969: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
970: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 971: if ($includeempty) {
972: $output .= '<option value=""';
973: if ($selected eq '') {
974: $output .= ' selected="selected" ';
975: }
976: $output .= '> </option>';
977: }
1.1241 raeburn 978: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 979: my (@possibles,%locale_names);
1.1241 raeburn 980: my @locales = DateTime::Locale->ids();
981: foreach my $id (@locales) {
982: if ($id ne '') {
983: my ($en_terr,$native_terr);
984: my $loc = DateTime::Locale->load($id);
985: if (ref($loc)) {
986: $en_terr = $loc->name();
987: $native_terr = $loc->native_name();
1.687 raeburn 988: if (grep(/^en$/,@languages) || !@languages) {
989: if ($en_terr ne '') {
990: $locale_names{$id} = '('.$en_terr.')';
991: } elsif ($native_terr ne '') {
992: $locale_names{$id} = $native_terr;
993: }
994: } else {
995: if ($native_terr ne '') {
996: $locale_names{$id} = $native_terr.' ';
997: } elsif ($en_terr ne '') {
998: $locale_names{$id} = '('.$en_terr.')';
999: }
1000: }
1.1220 raeburn 1001: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1002: push(@possibles,$id);
1003: }
1.687 raeburn 1004: }
1005: }
1006: foreach my $item (sort(@possibles)) {
1007: $output.= '<option value="'.$item.'"';
1008: if ($item eq $selected) {
1009: $output.=' selected="selected"';
1010: }
1011: $output.=">$item";
1012: if ($locale_names{$item} ne '') {
1.1220 raeburn 1013: $output.=' '.$locale_names{$item};
1.687 raeburn 1014: }
1015: $output.="</option>\n";
1016: }
1017: $output.="</select>";
1018: return $output;
1019: }
1020:
1.792 raeburn 1021: sub select_language {
1.1256 raeburn 1022: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1023: my %langchoices;
1024: if ($includeempty) {
1.1117 raeburn 1025: %langchoices = ('' => 'No language preference');
1.792 raeburn 1026: }
1027: foreach my $id (&languageids()) {
1028: my $code = &supportedlanguagecode($id);
1029: if ($code) {
1030: $langchoices{$code} = &plainlanguagedescription($id);
1031: }
1032: }
1.1117 raeburn 1033: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1034: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1035: }
1036:
1.42 matthew 1037: =pod
1.36 matthew 1038:
1.1088 foxr 1039:
1040: =item * &list_languages()
1041:
1042: Returns an array reference that is suitable for use in language prompters.
1043: Each array element is itself a two element array. The first element
1044: is the language code. The second element a descsriptiuon of the
1045: language itself. This is suitable for use in e.g.
1046: &Apache::edit::select_arg (once dereferenced that is).
1047:
1048: =cut
1049:
1050: sub list_languages {
1051: my @lang_choices;
1052:
1053: foreach my $id (&languageids()) {
1054: my $code = &supportedlanguagecode($id);
1055: if ($code) {
1056: my $selector = $supported_codes{$id};
1057: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1058: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1059: }
1060: }
1061: return \@lang_choices;
1062: }
1063:
1064: =pod
1065:
1.648 raeburn 1066: =item * &linked_select_forms(...)
1.36 matthew 1067:
1068: linked_select_forms returns a string containing a <script></script> block
1069: and html for two <select> menus. The select menus will be linked in that
1070: changing the value of the first menu will result in new values being placed
1071: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1072: order unless a defined order is provided.
1.36 matthew 1073:
1074: linked_select_forms takes the following ordered inputs:
1075:
1076: =over 4
1077:
1.112 bowersj2 1078: =item * $formname, the name of the <form> tag
1.36 matthew 1079:
1.112 bowersj2 1080: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1081:
1.112 bowersj2 1082: =item * $firstdefault, the default value for the first menu
1.36 matthew 1083:
1.112 bowersj2 1084: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1085:
1.112 bowersj2 1086: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1087:
1.112 bowersj2 1088: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1089:
1.609 raeburn 1090: =item * $menuorder, the order of values in the first menu
1091:
1.1115 raeburn 1092: =item * $onchangefirst, additional javascript call to execute for an onchange
1093: event for the first <select> tag
1094:
1095: =item * $onchangesecond, additional javascript call to execute for an onchange
1096: event for the second <select> tag
1097:
1.1245 raeburn 1098: =item * $suffix, to differentiate separate uses of select2data javascript
1099: objects in a page.
1100:
1.41 ng 1101: =back
1102:
1.36 matthew 1103: Below is an example of such a hash. Only the 'text', 'default', and
1104: 'select2' keys must appear as stated. keys(%menu) are the possible
1105: values for the first select menu. The text that coincides with the
1.41 ng 1106: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1107: and text for the second menu are given in the hash pointed to by
1108: $menu{$choice1}->{'select2'}.
1109:
1.112 bowersj2 1110: my %menu = ( A1 => { text =>"Choice A1" ,
1111: default => "B3",
1112: select2 => {
1113: B1 => "Choice B1",
1114: B2 => "Choice B2",
1115: B3 => "Choice B3",
1116: B4 => "Choice B4"
1.609 raeburn 1117: },
1118: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1119: },
1120: A2 => { text =>"Choice A2" ,
1121: default => "C2",
1122: select2 => {
1123: C1 => "Choice C1",
1124: C2 => "Choice C2",
1125: C3 => "Choice C3"
1.609 raeburn 1126: },
1127: order => ['C2','C1','C3'],
1.112 bowersj2 1128: },
1129: A3 => { text =>"Choice A3" ,
1130: default => "D6",
1131: select2 => {
1132: D1 => "Choice D1",
1133: D2 => "Choice D2",
1134: D3 => "Choice D3",
1135: D4 => "Choice D4",
1136: D5 => "Choice D5",
1137: D6 => "Choice D6",
1138: D7 => "Choice D7"
1.609 raeburn 1139: },
1140: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1141: }
1142: );
1.36 matthew 1143:
1144: =cut
1145:
1146: sub linked_select_forms {
1147: my ($formname,
1148: $middletext,
1149: $firstdefault,
1150: $firstselectname,
1151: $secondselectname,
1.609 raeburn 1152: $hashref,
1153: $menuorder,
1.1115 raeburn 1154: $onchangefirst,
1.1245 raeburn 1155: $onchangesecond,
1156: $suffix
1.36 matthew 1157: ) = @_;
1158: my $second = "document.$formname.$secondselectname";
1159: my $first = "document.$formname.$firstselectname";
1160: # output the javascript to do the changing
1161: my $result = '';
1.776 bisitz 1162: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1163: $result.="// <![CDATA[\n";
1.1245 raeburn 1164: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1165: $" = '","';
1166: my $debug = '';
1167: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1168: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1169: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1170: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1171: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1172: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1173: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1174: @s2values = @{$hashref->{$s1}->{'order'}};
1175: }
1.36 matthew 1176: $result.="\"@s2values\");\n";
1.1245 raeburn 1177: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1178: my @s2texts;
1179: foreach my $value (@s2values) {
1.1263 raeburn 1180: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1181: }
1182: $result.="\"@s2texts\");\n";
1183: }
1184: $"=' ';
1185: $result.= <<"END";
1186:
1.1245 raeburn 1187: function select1${suffix}_changed() {
1.36 matthew 1188: // Determine new choice
1.1245 raeburn 1189: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1190: // update select2
1.1245 raeburn 1191: var values = select2data${suffix}[newvalue].values;
1192: var texts = select2data${suffix}[newvalue].texts;
1193: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1194: var i;
1195: // out with the old
1.1245 raeburn 1196: $second.options.length = 0;
1197: // in with the new
1.36 matthew 1198: for (i=0;i<values.length; i++) {
1199: $second.options[i] = new Option(values[i]);
1.143 matthew 1200: $second.options[i].value = values[i];
1.36 matthew 1201: $second.options[i].text = texts[i];
1202: if (values[i] == select2def) {
1203: $second.options[i].selected = true;
1204: }
1205: }
1206: }
1.824 bisitz 1207: // ]]>
1.36 matthew 1208: </script>
1209: END
1210: # output the initial values for the selection lists
1.1245 raeburn 1211: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1212: my @order = sort(keys(%{$hashref}));
1213: if (ref($menuorder) eq 'ARRAY') {
1214: @order = @{$menuorder};
1215: }
1216: foreach my $value (@order) {
1.36 matthew 1217: $result.=" <option value=\"$value\" ";
1.253 albertel 1218: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1219: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1220: }
1221: $result .= "</select>\n";
1222: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1223: $result .= $middletext;
1.1115 raeburn 1224: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1225: if ($onchangesecond) {
1226: $result .= ' onchange="'.$onchangesecond.'"';
1227: }
1228: $result .= ">\n";
1.36 matthew 1229: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1230:
1231: my @secondorder = sort(keys(%select2));
1232: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1233: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1234: }
1235: foreach my $value (@secondorder) {
1.36 matthew 1236: $result.=" <option value=\"$value\" ";
1.253 albertel 1237: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1238: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1239: }
1240: $result .= "</select>\n";
1241: # return $debug;
1242: return $result;
1243: } # end of sub linked_select_forms {
1244:
1.45 matthew 1245: =pod
1.44 bowersj2 1246:
1.973 raeburn 1247: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1248:
1.112 bowersj2 1249: Returns a string corresponding to an HTML link to the given help
1250: $topic, where $topic corresponds to the name of a .tex file in
1251: /home/httpd/html/adm/help/tex, with underscores replaced by
1252: spaces.
1253:
1254: $text will optionally be linked to the same topic, allowing you to
1255: link text in addition to the graphic. If you do not want to link
1256: text, but wish to specify one of the later parameters, pass an
1257: empty string.
1258:
1259: $stayOnPage is a value that will be interpreted as a boolean. If true,
1260: the link will not open a new window. If false, the link will open
1261: a new window using Javascript. (Default is false.)
1262:
1263: $width and $height are optional numerical parameters that will
1264: override the width and height of the popped up window, which may
1.973 raeburn 1265: be useful for certain help topics with big pictures included.
1266:
1267: $imgid is the id of the img tag used for the help icon. This may be
1268: used in a javascript call to switch the image src. See
1269: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1270:
1271: =cut
1272:
1273: sub help_open_topic {
1.973 raeburn 1274: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1275: $text = "" if (not defined $text);
1.44 bowersj2 1276: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1277: $width = 500 if (not defined $width);
1.44 bowersj2 1278: $height = 400 if (not defined $height);
1279: my $filename = $topic;
1280: $filename =~ s/ /_/g;
1281:
1.48 bowersj2 1282: my $template = "";
1283: my $link;
1.572 banghart 1284:
1.159 www 1285: $topic=~s/\W/\_/g;
1.44 bowersj2 1286:
1.572 banghart 1287: if (!$stayOnPage) {
1.1033 www 1288: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1289: } elsif ($stayOnPage eq 'popup') {
1290: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1291: } else {
1.48 bowersj2 1292: $link = "/adm/help/${filename}.hlp";
1293: }
1294:
1295: # Add the text
1.755 neumanie 1296: if ($text ne "") {
1.763 bisitz 1297: $template.='<span class="LC_help_open_topic">'
1298: .'<a target="_top" href="'.$link.'">'
1299: .$text.'</a>';
1.48 bowersj2 1300: }
1301:
1.763 bisitz 1302: # (Always) Add the graphic
1.179 matthew 1303: my $title = &mt('Online Help');
1.667 raeburn 1304: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1305: if ($imgid ne '') {
1306: $imgid = ' id="'.$imgid.'"';
1307: }
1.763 bisitz 1308: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1309: .'<img src="'.$helpicon.'" border="0"'
1310: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1311: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1312: .' /></a>';
1313: if ($text ne "") {
1314: $template.='</span>';
1315: }
1.44 bowersj2 1316: return $template;
1317:
1.106 bowersj2 1318: }
1319:
1320: # This is a quicky function for Latex cheatsheet editing, since it
1321: # appears in at least four places
1322: sub helpLatexCheatsheet {
1.1037 www 1323: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1324: my $out;
1.106 bowersj2 1325: my $addOther = '';
1.732 raeburn 1326: if ($topic) {
1.1037 www 1327: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1328: }
1329: $out = '<span>' # Start cheatsheet
1330: .$addOther
1331: .'<span>'
1.1037 www 1332: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1333: .'</span> <span>'
1.1037 www 1334: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1335: .'</span>';
1.732 raeburn 1336: unless ($not_author) {
1.1186 kruse 1337: $out .= '<span>'
1338: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1339: .'</span> <span>'
1340: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1341: .'</span>';
1.732 raeburn 1342: }
1.763 bisitz 1343: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1344: return $out;
1.172 www 1345: }
1346:
1.430 albertel 1347: sub general_help {
1348: my $helptopic='Student_Intro';
1349: if ($env{'request.role'}=~/^(ca|au)/) {
1350: $helptopic='Authoring_Intro';
1.907 raeburn 1351: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1352: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1353: } elsif ($env{'request.role'}=~/^dc/) {
1354: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1355: }
1356: return $helptopic;
1357: }
1358:
1359: sub update_help_link {
1360: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1361: my $origurl = $ENV{'REQUEST_URI'};
1362: $origurl=~s|^/~|/priv/|;
1363: my $timestamp = time;
1364: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1365: $$datum = &escape($$datum);
1366: }
1367:
1368: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1369: my $output .= <<"ENDOUTPUT";
1370: <script type="text/javascript">
1.824 bisitz 1371: // <![CDATA[
1.430 albertel 1372: banner_link = '$banner_link';
1.824 bisitz 1373: // ]]>
1.430 albertel 1374: </script>
1375: ENDOUTPUT
1376: return $output;
1377: }
1378:
1379: # now just updates the help link and generates a blue icon
1.193 raeburn 1380: sub help_open_menu {
1.430 albertel 1381: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1382: = @_;
1.949 droeschl 1383: $stayOnPage = 1;
1.430 albertel 1384: my $output;
1385: if ($component_help) {
1386: if (!$text) {
1387: $output=&help_open_topic($component_help,undef,$stayOnPage,
1388: $width,$height);
1389: } else {
1390: my $help_text;
1391: $help_text=&unescape($topic);
1392: $output='<table><tr><td>'.
1393: &help_open_topic($component_help,$help_text,$stayOnPage,
1394: $width,$height).'</td></tr></table>';
1395: }
1396: }
1397: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1398: return $output.$banner_link;
1399: }
1400:
1401: sub top_nav_help {
1402: my ($text) = @_;
1.436 albertel 1403: $text = &mt($text);
1.949 droeschl 1404: my $stay_on_page = 1;
1405:
1.1168 raeburn 1406: my ($link,$banner_link);
1407: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1408: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1409: : "javascript:helpMenu('open')";
1410: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1411: }
1.201 raeburn 1412: my $title = &mt('Get help');
1.1168 raeburn 1413: if ($link) {
1414: return <<"END";
1.436 albertel 1415: $banner_link
1.1159 raeburn 1416: <a href="$link" title="$title">$text</a>
1.436 albertel 1417: END
1.1168 raeburn 1418: } else {
1419: return ' '.$text.' ';
1420: }
1.436 albertel 1421: }
1422:
1423: sub help_menu_js {
1.1154 raeburn 1424: my ($httphost) = @_;
1.949 droeschl 1425: my $stayOnPage = 1;
1.436 albertel 1426: my $width = 620;
1427: my $height = 600;
1.430 albertel 1428: my $helptopic=&general_help();
1.1154 raeburn 1429: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1430: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1431: my $start_page =
1432: &Apache::loncommon::start_page('Help Menu', undef,
1433: {'frameset' => 1,
1434: 'js_ready' => 1,
1.1154 raeburn 1435: 'use_absolute' => $httphost,
1.331 albertel 1436: 'add_entries' => {
1.1168 raeburn 1437: 'border' => '0',
1.579 raeburn 1438: 'rows' => "110,*",},});
1.331 albertel 1439: my $end_page =
1440: &Apache::loncommon::end_page({'frameset' => 1,
1441: 'js_ready' => 1,});
1442:
1.436 albertel 1443: my $template .= <<"ENDTEMPLATE";
1444: <script type="text/javascript">
1.877 bisitz 1445: // <![CDATA[
1.253 albertel 1446: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1447: var banner_link = '';
1.243 raeburn 1448: function helpMenu(target) {
1449: var caller = this;
1450: if (target == 'open') {
1451: var newWindow = null;
1452: try {
1.262 albertel 1453: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1454: }
1455: catch(error) {
1456: writeHelp(caller);
1457: return;
1458: }
1459: if (newWindow) {
1460: caller = newWindow;
1461: }
1.193 raeburn 1462: }
1.243 raeburn 1463: writeHelp(caller);
1464: return;
1465: }
1466: function writeHelp(caller) {
1.1168 raeburn 1467: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1468: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1469: caller.document.close();
1470: caller.focus();
1.193 raeburn 1471: }
1.877 bisitz 1472: // END LON-CAPA Internal -->
1.253 albertel 1473: // ]]>
1.436 albertel 1474: </script>
1.193 raeburn 1475: ENDTEMPLATE
1476: return $template;
1477: }
1478:
1.172 www 1479: sub help_open_bug {
1480: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1481: unless ($env{'user.adv'}) { return ''; }
1.172 www 1482: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1483: $text = "" if (not defined $text);
1484: $stayOnPage=1;
1.184 albertel 1485: $width = 600 if (not defined $width);
1486: $height = 600 if (not defined $height);
1.172 www 1487:
1488: $topic=~s/\W+/\+/g;
1489: my $link='';
1490: my $template='';
1.379 albertel 1491: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1492: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1493: if (!$stayOnPage)
1494: {
1495: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1496: }
1497: else
1498: {
1499: $link = $url;
1500: }
1501: # Add the text
1502: if ($text ne "")
1503: {
1504: $template .=
1505: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1506: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1507: }
1508:
1509: # Add the graphic
1.179 matthew 1510: my $title = &mt('Report a Bug');
1.215 albertel 1511: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1512: $template .= <<"ENDTEMPLATE";
1.436 albertel 1513: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1514: ENDTEMPLATE
1515: if ($text ne '') { $template.='</td></tr></table>' };
1516: return $template;
1517:
1518: }
1519:
1520: sub help_open_faq {
1521: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1522: unless ($env{'user.adv'}) { return ''; }
1.172 www 1523: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1524: $text = "" if (not defined $text);
1525: $stayOnPage=1;
1526: $width = 350 if (not defined $width);
1527: $height = 400 if (not defined $height);
1528:
1529: $topic=~s/\W+/\+/g;
1530: my $link='';
1531: my $template='';
1532: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1533: if (!$stayOnPage)
1534: {
1535: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1536: }
1537: else
1538: {
1539: $link = $url;
1540: }
1541:
1542: # Add the text
1543: if ($text ne "")
1544: {
1545: $template .=
1.173 www 1546: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1547: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1548: }
1549:
1550: # Add the graphic
1.179 matthew 1551: my $title = &mt('View the FAQ');
1.215 albertel 1552: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1553: $template .= <<"ENDTEMPLATE";
1.436 albertel 1554: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1555: ENDTEMPLATE
1556: if ($text ne '') { $template.='</td></tr></table>' };
1557: return $template;
1558:
1.44 bowersj2 1559: }
1.37 matthew 1560:
1.180 matthew 1561: ###############################################################
1562: ###############################################################
1563:
1.45 matthew 1564: =pod
1565:
1.648 raeburn 1566: =item * &change_content_javascript():
1.256 matthew 1567:
1568: This and the next function allow you to create small sections of an
1569: otherwise static HTML page that you can update on the fly with
1570: Javascript, even in Netscape 4.
1571:
1572: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1573: must be written to the HTML page once. It will prove the Javascript
1574: function "change(name, content)". Calling the change function with the
1575: name of the section
1576: you want to update, matching the name passed to C<changable_area>, and
1577: the new content you want to put in there, will put the content into
1578: that area.
1579:
1580: B<Note>: Netscape 4 only reserves enough space for the changable area
1581: to contain room for the original contents. You need to "make space"
1582: for whatever changes you wish to make, and be B<sure> to check your
1583: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1584: it's adequate for updating a one-line status display, but little more.
1585: This script will set the space to 100% width, so you only need to
1586: worry about height in Netscape 4.
1587:
1588: Modern browsers are much less limiting, and if you can commit to the
1589: user not using Netscape 4, this feature may be used freely with
1590: pretty much any HTML.
1591:
1592: =cut
1593:
1594: sub change_content_javascript {
1595: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1596: if ($env{'browser.type'} eq 'netscape' &&
1597: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1598: return (<<NETSCAPE4);
1599: function change(name, content) {
1600: doc = document.layers[name+"___escape"].layers[0].document;
1601: doc.open();
1602: doc.write(content);
1603: doc.close();
1604: }
1605: NETSCAPE4
1606: } else {
1607: # Otherwise, we need to use semi-standards-compliant code
1608: # (technically, "innerHTML" isn't standard but the equivalent
1609: # is really scary, and every useful browser supports it
1610: return (<<DOMBASED);
1611: function change(name, content) {
1612: element = document.getElementById(name);
1613: element.innerHTML = content;
1614: }
1615: DOMBASED
1616: }
1617: }
1618:
1619: =pod
1620:
1.648 raeburn 1621: =item * &changable_area($name,$origContent):
1.256 matthew 1622:
1623: This provides a "changable area" that can be modified on the fly via
1624: the Javascript code provided in C<change_content_javascript>. $name is
1625: the name you will use to reference the area later; do not repeat the
1626: same name on a given HTML page more then once. $origContent is what
1627: the area will originally contain, which can be left blank.
1628:
1629: =cut
1630:
1631: sub changable_area {
1632: my ($name, $origContent) = @_;
1633:
1.258 albertel 1634: if ($env{'browser.type'} eq 'netscape' &&
1635: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1636: # If this is netscape 4, we need to use the Layer tag
1637: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1638: } else {
1639: return "<span id='$name'>$origContent</span>";
1640: }
1641: }
1642:
1643: =pod
1644:
1.648 raeburn 1645: =item * &viewport_geometry_js
1.590 raeburn 1646:
1647: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1648:
1649: =cut
1650:
1651:
1652: sub viewport_geometry_js {
1653: return <<"GEOMETRY";
1654: var Geometry = {};
1655: function init_geometry() {
1656: if (Geometry.init) { return };
1657: Geometry.init=1;
1658: if (window.innerHeight) {
1659: Geometry.getViewportHeight = function() { return window.innerHeight; };
1660: Geometry.getViewportWidth = function() { return window.innerWidth; };
1661: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1662: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1663: }
1664: else if (document.documentElement && document.documentElement.clientHeight) {
1665: Geometry.getViewportHeight =
1666: function() { return document.documentElement.clientHeight; };
1667: Geometry.getViewportWidth =
1668: function() { return document.documentElement.clientWidth; };
1669:
1670: Geometry.getHorizontalScroll =
1671: function() { return document.documentElement.scrollLeft; };
1672: Geometry.getVerticalScroll =
1673: function() { return document.documentElement.scrollTop; };
1674: }
1675: else if (document.body.clientHeight) {
1676: Geometry.getViewportHeight =
1677: function() { return document.body.clientHeight; };
1678: Geometry.getViewportWidth =
1679: function() { return document.body.clientWidth; };
1680: Geometry.getHorizontalScroll =
1681: function() { return document.body.scrollLeft; };
1682: Geometry.getVerticalScroll =
1683: function() { return document.body.scrollTop; };
1684: }
1685: }
1686:
1687: GEOMETRY
1688: }
1689:
1690: =pod
1691:
1.648 raeburn 1692: =item * &viewport_size_js()
1.590 raeburn 1693:
1694: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1695:
1696: =cut
1697:
1698: sub viewport_size_js {
1699: my $geometry = &viewport_geometry_js();
1700: return <<"DIMS";
1701:
1702: $geometry
1703:
1704: function getViewportDims(width,height) {
1705: init_geometry();
1706: width.value = Geometry.getViewportWidth();
1707: height.value = Geometry.getViewportHeight();
1708: return;
1709: }
1710:
1711: DIMS
1712: }
1713:
1714: =pod
1715:
1.648 raeburn 1716: =item * &resize_textarea_js()
1.565 albertel 1717:
1718: emits the needed javascript to resize a textarea to be as big as possible
1719:
1720: creates a function resize_textrea that takes two IDs first should be
1721: the id of the element to resize, second should be the id of a div that
1722: surrounds everything that comes after the textarea, this routine needs
1723: to be attached to the <body> for the onload and onresize events.
1724:
1.648 raeburn 1725: =back
1.565 albertel 1726:
1727: =cut
1728:
1729: sub resize_textarea_js {
1.590 raeburn 1730: my $geometry = &viewport_geometry_js();
1.565 albertel 1731: return <<"RESIZE";
1732: <script type="text/javascript">
1.824 bisitz 1733: // <![CDATA[
1.590 raeburn 1734: $geometry
1.565 albertel 1735:
1.588 albertel 1736: function getX(element) {
1737: var x = 0;
1738: while (element) {
1739: x += element.offsetLeft;
1740: element = element.offsetParent;
1741: }
1742: return x;
1743: }
1744: function getY(element) {
1745: var y = 0;
1746: while (element) {
1747: y += element.offsetTop;
1748: element = element.offsetParent;
1749: }
1750: return y;
1751: }
1752:
1753:
1.565 albertel 1754: function resize_textarea(textarea_id,bottom_id) {
1755: init_geometry();
1756: var textarea = document.getElementById(textarea_id);
1757: //alert(textarea);
1758:
1.588 albertel 1759: var textarea_top = getY(textarea);
1.565 albertel 1760: var textarea_height = textarea.offsetHeight;
1761: var bottom = document.getElementById(bottom_id);
1.588 albertel 1762: var bottom_top = getY(bottom);
1.565 albertel 1763: var bottom_height = bottom.offsetHeight;
1764: var window_height = Geometry.getViewportHeight();
1.588 albertel 1765: var fudge = 23;
1.565 albertel 1766: var new_height = window_height-fudge-textarea_top-bottom_height;
1767: if (new_height < 300) {
1768: new_height = 300;
1769: }
1770: textarea.style.height=new_height+'px';
1771: }
1.824 bisitz 1772: // ]]>
1.565 albertel 1773: </script>
1774: RESIZE
1775:
1776: }
1777:
1.1205 golterma 1778: sub colorfuleditor_js {
1.1248 raeburn 1779: my $browse_or_search;
1780: my $respath;
1781: my ($cnum,$cdom) = &crsauthor_url();
1782: if ($cnum) {
1783: $respath = "/res/$cdom/$cnum/";
1784: my %js_lt = &Apache::lonlocal::texthash(
1785: sunm => 'Sub-directory name',
1786: save => 'Save page to make this permanent',
1787: );
1788: &js_escape(\%js_lt);
1789: $browse_or_search = <<"END";
1790:
1791: function toggleChooser(form,element,titleid,only,search) {
1792: var disp = 'none';
1793: if (document.getElementById('chooser_'+element)) {
1794: var curr = document.getElementById('chooser_'+element).style.display;
1795: if (curr == 'none') {
1796: disp='inline';
1797: if (form.elements['chooser_'+element].length) {
1798: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1799: form.elements['chooser_'+element][i].checked = false;
1800: }
1801: }
1802: toggleResImport(form,element);
1803: }
1804: document.getElementById('chooser_'+element).style.display = disp;
1805: }
1806: }
1807:
1808: function toggleCrsFile(form,element,numdirs) {
1809: if (document.getElementById('chooser_'+element+'_crsres')) {
1810: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1811: if (curr == 'none') {
1812: if (numdirs) {
1813: form.elements['coursepath_'+element].selectedIndex = 0;
1814: if (numdirs > 1) {
1815: window['select1'+element+'_changed']();
1816: }
1817: }
1818: }
1819: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1820:
1821: }
1822: if (document.getElementById('chooser_'+element+'_upload')) {
1823: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1824: if (document.getElementById('uploadcrsres_'+element)) {
1825: document.getElementById('uploadcrsres_'+element).value = '';
1826: }
1827: }
1828: return;
1829: }
1830:
1831: function toggleCrsUpload(form,element,numcrsdirs) {
1832: if (document.getElementById('chooser_'+element+'_crsres')) {
1833: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1834: }
1835: if (document.getElementById('chooser_'+element+'_upload')) {
1836: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1837: if (curr == 'none') {
1838: if (numcrsdirs) {
1839: form.elements['crsauthorpath_'+element].selectedIndex = 0;
1840: form.elements['newsubdir_'+element][0].checked = true;
1841: toggleNewsubdir(form,element);
1842: }
1843: }
1844: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1845: }
1846: return;
1847: }
1848:
1849: function toggleResImport(form,element) {
1850: var choices = new Array('crsres','upload');
1851: for (var i=0; i<choices.length; i++) {
1852: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1853: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1854: }
1855: }
1856: }
1857:
1858: function toggleNewsubdir(form,element) {
1859: var newsub = form.elements['newsubdir_'+element];
1860: if (newsub) {
1861: if (newsub.length) {
1862: for (var j=0; j<newsub.length; j++) {
1863: if (newsub[j].checked) {
1864: if (document.getElementById('newsubdirname_'+element)) {
1865: if (newsub[j].value == '1') {
1866: document.getElementById('newsubdirname_'+element).type = "text";
1867: if (document.getElementById('newsubdir_'+element)) {
1868: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1869: }
1870: } else {
1871: document.getElementById('newsubdirname_'+element).type = "hidden";
1872: document.getElementById('newsubdirname_'+element).value = "";
1873: document.getElementById('newsubdir_'+element).innerHTML = "";
1874: }
1875: }
1876: break;
1877: }
1878: }
1879: }
1880: }
1881: }
1882:
1883: function updateCrsFile(form,element) {
1884: var directory = form.elements['coursepath_'+element];
1885: var filename = form.elements['coursefile_'+element];
1886: var path = directory.options[directory.selectedIndex].value;
1887: var file = filename.options[filename.selectedIndex].value;
1888: form.elements[element].value = '$respath';
1889: if (path == '/') {
1890: form.elements[element].value += file;
1891: } else {
1892: form.elements[element].value += path+'/'+file;
1893: }
1894: unClean();
1895: if (document.getElementById('previewimg_'+element)) {
1896: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1897: var newsrc = document.getElementById('previewimg_'+element).src;
1898: }
1899: if (document.getElementById('showimg_'+element)) {
1900: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1901: }
1902: toggleChooser(form,element);
1903: return;
1904: }
1905:
1906: function uploadDone(suffix,name) {
1907: if (name) {
1908: document.forms["lonhomework"].elements[suffix].value = name;
1909: unClean();
1910: toggleChooser(document.forms["lonhomework"],suffix);
1911: }
1912: }
1913:
1914: \$(document).ready(function(){
1915:
1916: \$(document).delegate('form :submit', 'click', function( event ) {
1917: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
1918: var buttonId = this.id;
1919: var suffix = buttonId.toString();
1920: suffix = suffix.replace(/^crsupload_/,'');
1921: event.preventDefault();
1922: document.lonhomework.target = 'crsupload_target_'+suffix;
1923: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
1924: \$(this.form).submit();
1925: document.lonhomework.target = '';
1926: if (document.getElementById('crsuploadto_'+suffix)) {
1927: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
1928: }
1929: return false;
1930: }
1931: });
1932: });
1933: END
1934: }
1.1205 golterma 1935: return <<"COLORFULEDIT"
1936: <script type="text/javascript">
1937: // <![CDATA[>
1938: function fold_box(curDepth, lastresource){
1939:
1940: // we need a list because there can be several blocks you need to fold in one tag
1941: var block = document.getElementsByName('foldblock_'+curDepth);
1942: // but there is only one folding button per tag
1943: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1944:
1945: if(block.item(0).style.display == 'none'){
1946:
1947: foldbutton.value = '@{[&mt("Hide")]}';
1948: for (i = 0; i < block.length; i++){
1949: block.item(i).style.display = '';
1950: }
1951: }else{
1952:
1953: foldbutton.value = '@{[&mt("Show")]}';
1954: for (i = 0; i < block.length; i++){
1955: // block.item(i).style.visibility = 'collapse';
1956: block.item(i).style.display = 'none';
1957: }
1958: };
1959: saveState(lastresource);
1960: }
1961:
1962: function saveState (lastresource) {
1963:
1964: var tag_list = getTagList();
1965: if(tag_list != null){
1966: var timestamp = new Date().getTime();
1967: var key = lastresource;
1968:
1969: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1970: // starting with timestamp
1971: var value = timestamp+';';
1972:
1973: // building the list of key-value pairs
1974: for(var i = 0; i < tag_list.length; i++){
1975: value += tag_list[i]+',';
1976: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1977: }
1978:
1979: // only iterate whole storage if nothing to override
1980: if(localStorage.getItem(key) == null){
1981:
1982: // prevent storage from growing large
1983: if(localStorage.length > 50){
1984: var regex_getTimestamp = /^(?:\d)+;/;
1985: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1986: var oldest_key;
1987:
1988: for(var i = 1; i < localStorage.length; i++){
1989: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1990: oldest_key = localStorage.key(i);
1991: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1992: }
1993: }
1994: localStorage.removeItem(oldest_key);
1995: }
1996: }
1997: localStorage.setItem(key,value);
1998: }
1999: }
2000:
2001: // restore folding status of blocks (on page load)
2002: function restoreState (lastresource) {
2003: if(localStorage.getItem(lastresource) != null){
2004: var key = lastresource;
2005: var value = localStorage.getItem(key);
2006: var regex_delTimestamp = /^\d+;/;
2007:
2008: value.replace(regex_delTimestamp, '');
2009:
2010: var valueArr = value.split(';');
2011: var pairs;
2012: var elements;
2013: for (var i = 0; i < valueArr.length; i++){
2014: pairs = valueArr[i].split(',');
2015: elements = document.getElementsByName(pairs[0]);
2016:
2017: for (var j = 0; j < elements.length; j++){
2018: elements[j].style.display = pairs[1];
2019: if (pairs[1] == "none"){
2020: var regex_id = /([_\\d]+)\$/;
2021: regex_id.exec(pairs[0]);
2022: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2023: }
2024: }
2025: }
2026: }
2027: }
2028:
2029: function getTagList () {
2030:
2031: var stringToSearch = document.lonhomework.innerHTML;
2032:
2033: var ret = new Array();
2034: var regex_findBlock = /(foldblock_.*?)"/g;
2035: var tag_list = stringToSearch.match(regex_findBlock);
2036:
2037: if(tag_list != null){
2038: for(var i = 0; i < tag_list.length; i++){
2039: ret.push(tag_list[i].replace(/"/, ''));
2040: }
2041: }
2042: return ret;
2043: }
2044:
2045: function saveScrollPosition (resource) {
2046: var tag_list = getTagList();
2047:
2048: // we dont always want to jump to the first block
2049: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2050: if(\$(window).scrollTop() > 170){
2051: if(tag_list != null){
2052: var result;
2053: for(var i = 0; i < tag_list.length; i++){
2054: if(isElementInViewport(tag_list[i])){
2055: result += tag_list[i]+';';
2056: }
2057: }
2058: sessionStorage.setItem('anchor_'+resource, result);
2059: }
2060: } else {
2061: // we dont need to save zero, just delete the item to leave everything tidy
2062: sessionStorage.removeItem('anchor_'+resource);
2063: }
2064: }
2065:
2066: function restoreScrollPosition(resource){
2067:
2068: var elem = sessionStorage.getItem('anchor_'+resource);
2069: if(elem != null){
2070: var tag_list = elem.split(';');
2071: var elem_list;
2072:
2073: for(var i = 0; i < tag_list.length; i++){
2074: elem_list = document.getElementsByName(tag_list[i]);
2075:
2076: if(elem_list.length > 0){
2077: elem = elem_list[0];
2078: break;
2079: }
2080: }
2081: elem.scrollIntoView();
2082: }
2083: }
2084:
2085: function isElementInViewport(el) {
2086:
2087: // change to last element instead of first
2088: var elem = document.getElementsByName(el);
2089: var rect = elem[0].getBoundingClientRect();
2090:
2091: return (
2092: rect.top >= 0 &&
2093: rect.left >= 0 &&
2094: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2095: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2096: );
2097: }
2098:
2099: function autosize(depth){
2100: var cmInst = window['cm'+depth];
2101: var fitsizeButton = document.getElementById('fitsize'+depth);
2102:
2103: // is fixed size, switching to dynamic
2104: if (sessionStorage.getItem("autosized_"+depth) == null) {
2105: cmInst.setSize("","auto");
2106: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2107: sessionStorage.setItem("autosized_"+depth, "yes");
2108:
2109: // is dynamic size, switching to fixed
2110: } else {
2111: cmInst.setSize("","300px");
2112: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2113: sessionStorage.removeItem("autosized_"+depth);
2114: }
2115: }
2116:
1.1248 raeburn 2117: $browse_or_search
1.1205 golterma 2118:
2119: // ]]>
2120: </script>
2121: COLORFULEDIT
2122: }
2123:
2124: sub xmleditor_js {
2125: return <<XMLEDIT
2126: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2127: <script type="text/javascript">
2128: // <![CDATA[>
2129:
2130: function saveScrollPosition (resource) {
2131:
2132: var scrollPos = \$(window).scrollTop();
2133: sessionStorage.setItem(resource,scrollPos);
2134: }
2135:
2136: function restoreScrollPosition(resource){
2137:
2138: var scrollPos = sessionStorage.getItem(resource);
2139: \$(window).scrollTop(scrollPos);
2140: }
2141:
2142: // unless internet explorer
2143: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2144:
2145: \$(document).ready(function() {
2146: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2147: });
2148: }
2149:
2150: // inserts text at cursor position into codemirror (xml editor only)
2151: function insertText(text){
2152: cm.focus();
2153: var curPos = cm.getCursor();
2154: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2155: }
2156: // ]]>
2157: </script>
2158: XMLEDIT
2159: }
2160:
2161: sub insert_folding_button {
2162: my $curDepth = $Apache::lonxml::curdepth;
2163: my $lastresource = $env{'request.ambiguous'};
2164:
2165: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2166: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2167: }
2168:
1.1248 raeburn 2169: sub crsauthor_url {
2170: my ($url) = @_;
2171: if ($url eq '') {
2172: $url = $ENV{'REQUEST_URI'};
2173: }
2174: my ($cnum,$cdom);
2175: if ($env{'request.course.id'}) {
2176: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2177: if ($audom ne '' && $auname ne '') {
2178: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2179: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2180: $cnum = $auname;
2181: $cdom = $audom;
2182: }
2183: }
2184: }
2185: return ($cnum,$cdom);
2186: }
2187:
2188: sub import_crsauthor_form {
1.1265 raeburn 2189: my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2190: return (0) unless ($env{'request.course.id'});
2191: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2192: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2193: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2194: return (0) unless (($cnum ne '') && ($cdom ne ''));
2195: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
2196: my @ids=&Apache::lonnet::current_machine_ids();
2197: my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
2198:
2199: if (grep(/^\Q$crshome\E$/,@ids)) {
2200: $is_home = 1;
2201: }
2202: $relpath = "/priv/$cdom/$cnum";
2203: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
2204: my %lt = &Apache::lonlocal::texthash (
2205: fnam => 'Filename',
2206: dire => 'Directory',
2207: );
2208: my $numdirs = scalar(keys(%files));
2209: my (%possexts,$singledir,@singledirfiles);
2210: if ($only) {
2211: map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
2212: }
2213: my (%nonemptydirs,$possdirs);
2214: if ($numdirs > 1) {
2215: my @order;
2216: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
2217: if (ref($files{$key}) eq 'HASH') {
2218: my $shown = $key;
2219: if ($key eq '') {
2220: $shown = '/';
2221: }
2222: my @ordered = ();
2223: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
2224: if ($only) {
2225: my ($ext) = ($file =~ /\.([^.]+)$/);
2226: unless ($possexts{lc($ext)}) {
2227: next;
2228: }
2229: }
2230: $selimport_menus{$key}->{'select2'}->{$file} = $file;
2231: push(@ordered,$file);
2232: }
2233: if (@ordered) {
2234: push(@order,$key);
2235: $nonemptydirs{$key} = 1;
2236: $selimport_menus{$key}->{'text'} = $shown;
2237: $selimport_menus{$key}->{'default'} = '';
2238: $selimport_menus{$key}->{'select2'}->{''} = '';
2239: $selimport_menus{$key}->{'order'} = \@ordered;
2240: }
2241: }
2242: }
2243: $possdirs = scalar(keys(%nonemptydirs));
2244: if ($possdirs > 1) {
2245: my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
2246: $output = $lt{'dire'}.
2247: &linked_select_forms($form,'<br />'.
2248: $lt{'fnam'},'',
2249: $firstselectname,$secondselectname,
2250: \%selimport_menus,\@order,
2251: $onchangefirst,'',$suffix).'<br />';
2252: } elsif ($possdirs == 1) {
2253: $singledir = (keys(%nonemptydirs))[0];
2254: if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
2255: @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
2256: }
2257: delete($selimport_menus{$singledir});
2258: }
2259: } elsif ($numdirs == 1) {
2260: $singledir = (keys(%files))[0];
2261: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
2262: if ($only) {
2263: my ($ext) = ($file =~ /\.([^.]+)$/);
2264: unless ($possexts{lc($ext)}) {
2265: next;
2266: }
2267: }
2268: push(@singledirfiles,$file);
2269: }
2270: if (@singledirfiles) {
2271: $possdirs == 1;
2272: }
2273: }
2274: if (($possdirs == 1) && (@singledirfiles)) {
2275: my $showdir = $singledir;
2276: if ($singledir eq '') {
2277: $showdir = '/';
2278: }
2279: $output = $lt{'dire'}.
2280: '<select name="'.$firstselectname.'">'.
2281: '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
2282: '</select><br />'.
2283: $lt{'fnam'}.'<select name="'.$secondselectname.'">'."\n".
2284: '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
2285: foreach my $file (@singledirfiles) {
2286: $output .= '<option value="'.$file.'">'.$file.'</option>'."\n";
2287: }
2288: $output .= '</select><br />'."\n";
2289: }
2290: return ($possdirs,$output);
2291: }
2292:
1.565 albertel 2293: =pod
2294:
1.256 matthew 2295: =head1 Excel and CSV file utility routines
2296:
2297: =cut
2298:
2299: ###############################################################
2300: ###############################################################
2301:
2302: =pod
2303:
1.1162 raeburn 2304: =over 4
2305:
1.648 raeburn 2306: =item * &csv_translate($text)
1.37 matthew 2307:
1.185 www 2308: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2309: format.
2310:
2311: =cut
2312:
1.180 matthew 2313: ###############################################################
2314: ###############################################################
1.37 matthew 2315: sub csv_translate {
2316: my $text = shift;
2317: $text =~ s/\"/\"\"/g;
1.209 albertel 2318: $text =~ s/\n/ /g;
1.37 matthew 2319: return $text;
2320: }
1.180 matthew 2321:
2322: ###############################################################
2323: ###############################################################
2324:
2325: =pod
2326:
1.648 raeburn 2327: =item * &define_excel_formats()
1.180 matthew 2328:
2329: Define some commonly used Excel cell formats.
2330:
2331: Currently supported formats:
2332:
2333: =over 4
2334:
2335: =item header
2336:
2337: =item bold
2338:
2339: =item h1
2340:
2341: =item h2
2342:
2343: =item h3
2344:
1.256 matthew 2345: =item h4
2346:
2347: =item i
2348:
1.180 matthew 2349: =item date
2350:
2351: =back
2352:
2353: Inputs: $workbook
2354:
2355: Returns: $format, a hash reference.
2356:
1.1057 foxr 2357:
1.180 matthew 2358: =cut
2359:
2360: ###############################################################
2361: ###############################################################
2362: sub define_excel_formats {
2363: my ($workbook) = @_;
2364: my $format;
2365: $format->{'header'} = $workbook->add_format(bold => 1,
2366: bottom => 1,
2367: align => 'center');
2368: $format->{'bold'} = $workbook->add_format(bold=>1);
2369: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2370: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2371: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2372: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2373: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2374: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2375: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2376: return $format;
2377: }
2378:
2379: ###############################################################
2380: ###############################################################
1.113 bowersj2 2381:
2382: =pod
2383:
1.648 raeburn 2384: =item * &create_workbook()
1.255 matthew 2385:
2386: Create an Excel worksheet. If it fails, output message on the
2387: request object and return undefs.
2388:
2389: Inputs: Apache request object
2390:
2391: Returns (undef) on failure,
2392: Excel worksheet object, scalar with filename, and formats
2393: from &Apache::loncommon::define_excel_formats on success
2394:
2395: =cut
2396:
2397: ###############################################################
2398: ###############################################################
2399: sub create_workbook {
2400: my ($r) = @_;
2401: #
2402: # Create the excel spreadsheet
2403: my $filename = '/prtspool/'.
1.258 albertel 2404: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2405: time.'_'.rand(1000000000).'.xls';
2406: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2407: if (! defined($workbook)) {
2408: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2409: $r->print(
2410: '<p class="LC_error">'
2411: .&mt('Problems occurred in creating the new Excel file.')
2412: .' '.&mt('This error has been logged.')
2413: .' '.&mt('Please alert your LON-CAPA administrator.')
2414: .'</p>'
2415: );
1.255 matthew 2416: return (undef);
2417: }
2418: #
1.1014 foxr 2419: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2420: #
2421: my $format = &Apache::loncommon::define_excel_formats($workbook);
2422: return ($workbook,$filename,$format);
2423: }
2424:
2425: ###############################################################
2426: ###############################################################
2427:
2428: =pod
2429:
1.648 raeburn 2430: =item * &create_text_file()
1.113 bowersj2 2431:
1.542 raeburn 2432: Create a file to write to and eventually make available to the user.
1.256 matthew 2433: If file creation fails, outputs an error message on the request object and
2434: return undefs.
1.113 bowersj2 2435:
1.256 matthew 2436: Inputs: Apache request object, and file suffix
1.113 bowersj2 2437:
1.256 matthew 2438: Returns (undef) on failure,
2439: Filehandle and filename on success.
1.113 bowersj2 2440:
2441: =cut
2442:
1.256 matthew 2443: ###############################################################
2444: ###############################################################
2445: sub create_text_file {
2446: my ($r,$suffix) = @_;
2447: if (! defined($suffix)) { $suffix = 'txt'; };
2448: my $fh;
2449: my $filename = '/prtspool/'.
1.258 albertel 2450: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2451: time.'_'.rand(1000000000).'.'.$suffix;
2452: $fh = Apache::File->new('>/home/httpd'.$filename);
2453: if (! defined($fh)) {
2454: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2455: $r->print(
2456: '<p class="LC_error">'
2457: .&mt('Problems occurred in creating the output file.')
2458: .' '.&mt('This error has been logged.')
2459: .' '.&mt('Please alert your LON-CAPA administrator.')
2460: .'</p>'
2461: );
1.113 bowersj2 2462: }
1.256 matthew 2463: return ($fh,$filename)
1.113 bowersj2 2464: }
2465:
2466:
1.256 matthew 2467: =pod
1.113 bowersj2 2468:
2469: =back
2470:
2471: =cut
1.37 matthew 2472:
2473: ###############################################################
1.33 matthew 2474: ## Home server <option> list generating code ##
2475: ###############################################################
1.35 matthew 2476:
1.169 www 2477: # ------------------------------------------
2478:
2479: sub domain_select {
2480: my ($name,$value,$multiple)=@_;
2481: my %domains=map {
1.514 albertel 2482: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2483: } &Apache::lonnet::all_domains();
1.169 www 2484: if ($multiple) {
2485: $domains{''}=&mt('Any domain');
1.550 albertel 2486: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2487: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2488: } else {
1.550 albertel 2489: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2490: return &select_form($name,$value,\%domains);
1.169 www 2491: }
2492: }
2493:
1.282 albertel 2494: #-------------------------------------------
2495:
2496: =pod
2497:
1.519 raeburn 2498: =head1 Routines for form select boxes
2499:
2500: =over 4
2501:
1.648 raeburn 2502: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2503:
2504: Returns a string containing a <select> element int multiple mode
2505:
2506:
2507: Args:
2508: $name - name of the <select> element
1.506 raeburn 2509: $value - scalar or array ref of values that should already be selected
1.282 albertel 2510: $size - number of rows long the select element is
1.283 albertel 2511: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2512: (shown text should already have been &mt())
1.506 raeburn 2513: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2514:
1.282 albertel 2515: =cut
2516:
2517: #-------------------------------------------
1.169 www 2518: sub multiple_select_form {
1.284 albertel 2519: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2520: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2521: my $output='';
1.191 matthew 2522: if (! defined($size)) {
2523: $size = 4;
1.283 albertel 2524: if (scalar(keys(%$hash))<4) {
2525: $size = scalar(keys(%$hash));
1.191 matthew 2526: }
2527: }
1.734 bisitz 2528: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2529: my @order;
1.506 raeburn 2530: if (ref($order) eq 'ARRAY') {
2531: @order = @{$order};
2532: } else {
2533: @order = sort(keys(%$hash));
1.501 banghart 2534: }
2535: if (exists($$hash{'select_form_order'})) {
2536: @order = @{$$hash{'select_form_order'}};
2537: }
2538:
1.284 albertel 2539: foreach my $key (@order) {
1.356 albertel 2540: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2541: $output.='selected="selected" ' if ($selected{$key});
2542: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2543: }
2544: $output.="</select>\n";
2545: return $output;
2546: }
2547:
1.88 www 2548: #-------------------------------------------
2549:
2550: =pod
2551:
1.1254 raeburn 2552: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2553:
2554: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2555: allow a user to select options from a ref to a hash containing:
2556: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2557: a javascript onchange item, e.g., onchange="this.form.submit();".
2558: An optional arg -- $readonly -- if true will cause the select form
2559: to be disabled, e.g., for the case where an instructor has a section-
2560: specific role, and is viewing/modifying parameters.
1.970 raeburn 2561:
1.88 www 2562: See lonrights.pm for an example invocation and use.
2563:
2564: =cut
2565:
2566: #-------------------------------------------
2567: sub select_form {
1.1228 raeburn 2568: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2569: return unless (ref($hashref) eq 'HASH');
2570: if ($onchange) {
2571: $onchange = ' onchange="'.$onchange.'"';
2572: }
1.1228 raeburn 2573: my $disabled;
2574: if ($readonly) {
2575: $disabled = ' disabled="disabled"';
2576: }
2577: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2578: my @keys;
1.970 raeburn 2579: if (exists($hashref->{'select_form_order'})) {
2580: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2581: } else {
1.970 raeburn 2582: @keys=sort(keys(%{$hashref}));
1.128 albertel 2583: }
1.356 albertel 2584: foreach my $key (@keys) {
2585: $selectform.=
2586: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2587: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2588: ">".$hashref->{$key}."</option>\n";
1.88 www 2589: }
2590: $selectform.="</select>";
2591: return $selectform;
2592: }
2593:
1.475 www 2594: # For display filters
2595:
2596: sub display_filter {
1.1074 raeburn 2597: my ($context) = @_;
1.475 www 2598: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2599: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2600: my $phraseinput = 'hidden';
2601: my $includeinput = 'hidden';
2602: my ($checked,$includetypestext);
2603: if ($env{'form.displayfilter'} eq 'containing') {
2604: $phraseinput = 'text';
2605: if ($context eq 'parmslog') {
2606: $includeinput = 'checkbox';
2607: if ($env{'form.includetypes'}) {
2608: $checked = ' checked="checked"';
2609: }
2610: $includetypestext = &mt('Include parameter types');
2611: }
2612: } else {
2613: $includetypestext = ' ';
2614: }
2615: my ($additional,$secondid,$thirdid);
2616: if ($context eq 'parmslog') {
2617: $additional =
2618: '<label><input type="'.$includeinput.'" name="includetypes"'.
2619: $checked.' name="includetypes" value="1" id="includetypes" />'.
2620: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2621: '</label>';
2622: $secondid = 'includetypes';
2623: $thirdid = 'includetypestext';
2624: }
2625: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2626: '$secondid','$thirdid')";
2627: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2628: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2629: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2630: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2631: &mt('Filter: [_1]',
1.477 www 2632: &select_form($env{'form.displayfilter'},
2633: 'displayfilter',
1.970 raeburn 2634: {'currentfolder' => 'Current folder/page',
1.477 www 2635: 'containing' => 'Containing phrase',
1.1074 raeburn 2636: 'none' => 'None'},$onchange)).' '.
2637: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2638: &HTML::Entities::encode($env{'form.containingphrase'}).
2639: '" />'.$additional;
2640: }
2641:
2642: sub display_filter_js {
2643: my $includetext = &mt('Include parameter types');
2644: return <<"ENDJS";
2645:
2646: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2647: var firstType = 'hidden';
2648: if (setter.options[setter.selectedIndex].value == 'containing') {
2649: firstType = 'text';
2650: }
2651: firstObject = document.getElementById(firstid);
2652: if (typeof(firstObject) == 'object') {
2653: if (firstObject.type != firstType) {
2654: changeInputType(firstObject,firstType);
2655: }
2656: }
2657: if (context == 'parmslog') {
2658: var secondType = 'hidden';
2659: if (firstType == 'text') {
2660: secondType = 'checkbox';
2661: }
2662: secondObject = document.getElementById(secondid);
2663: if (typeof(secondObject) == 'object') {
2664: if (secondObject.type != secondType) {
2665: changeInputType(secondObject,secondType);
2666: }
2667: }
2668: var textItem = document.getElementById(thirdid);
2669: var currtext = textItem.innerHTML;
2670: var newtext;
2671: if (firstType == 'text') {
2672: newtext = '$includetext';
2673: } else {
2674: newtext = ' ';
2675: }
2676: if (currtext != newtext) {
2677: textItem.innerHTML = newtext;
2678: }
2679: }
2680: return;
2681: }
2682:
2683: function changeInputType(oldObject,newType) {
2684: var newObject = document.createElement('input');
2685: newObject.type = newType;
2686: if (oldObject.size) {
2687: newObject.size = oldObject.size;
2688: }
2689: if (oldObject.value) {
2690: newObject.value = oldObject.value;
2691: }
2692: if (oldObject.name) {
2693: newObject.name = oldObject.name;
2694: }
2695: if (oldObject.id) {
2696: newObject.id = oldObject.id;
2697: }
2698: oldObject.parentNode.replaceChild(newObject,oldObject);
2699: return;
2700: }
2701:
2702: ENDJS
1.475 www 2703: }
2704:
1.167 www 2705: sub gradeleveldescription {
2706: my $gradelevel=shift;
2707: my %gradelevels=(0 => 'Not specified',
2708: 1 => 'Grade 1',
2709: 2 => 'Grade 2',
2710: 3 => 'Grade 3',
2711: 4 => 'Grade 4',
2712: 5 => 'Grade 5',
2713: 6 => 'Grade 6',
2714: 7 => 'Grade 7',
2715: 8 => 'Grade 8',
2716: 9 => 'Grade 9',
2717: 10 => 'Grade 10',
2718: 11 => 'Grade 11',
2719: 12 => 'Grade 12',
2720: 13 => 'Grade 13',
2721: 14 => '100 Level',
2722: 15 => '200 Level',
2723: 16 => '300 Level',
2724: 17 => '400 Level',
2725: 18 => 'Graduate Level');
2726: return &mt($gradelevels{$gradelevel});
2727: }
2728:
1.163 www 2729: sub select_level_form {
2730: my ($deflevel,$name)=@_;
2731: unless ($deflevel) { $deflevel=0; }
1.167 www 2732: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2733: for (my $i=0; $i<=18; $i++) {
2734: $selectform.="<option value=\"$i\" ".
1.253 albertel 2735: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2736: ">".&gradeleveldescription($i)."</option>\n";
2737: }
2738: $selectform.="</select>";
2739: return $selectform;
1.163 www 2740: }
1.167 www 2741:
1.35 matthew 2742: #-------------------------------------------
2743:
1.45 matthew 2744: =pod
2745:
1.1256 raeburn 2746: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2747:
2748: Returns a string containing a <select name='$name' size='1'> form to
2749: allow a user to select the domain to preform an operation in.
2750: See loncreateuser.pm for an example invocation and use.
2751:
1.90 www 2752: If the $includeempty flag is set, it also includes an empty choice ("no domain
2753: selected");
2754:
1.743 raeburn 2755: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2756:
1.910 raeburn 2757: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
2758:
1.1121 raeburn 2759: The optional $incdoms is a reference to an array of domains which will be the only available options.
2760:
2761: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2762:
1.1256 raeburn 2763: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2764:
1.35 matthew 2765: =cut
2766:
2767: #-------------------------------------------
1.34 matthew 2768: sub select_dom_form {
1.1256 raeburn 2769: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2770: if ($onchange) {
1.874 raeburn 2771: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2772: }
1.1256 raeburn 2773: if ($disabled) {
2774: $disabled = ' disabled="disabled"';
2775: }
1.1121 raeburn 2776: my (@domains,%exclude);
1.910 raeburn 2777: if (ref($incdoms) eq 'ARRAY') {
2778: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2779: } else {
2780: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2781: }
1.90 www 2782: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2783: if (ref($excdoms) eq 'ARRAY') {
2784: map { $exclude{$_} = 1; } @{$excdoms};
2785: }
1.1256 raeburn 2786: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2787: foreach my $dom (@domains) {
1.1121 raeburn 2788: next if ($exclude{$dom});
1.356 albertel 2789: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2790: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2791: if ($showdomdesc) {
2792: if ($dom ne '') {
2793: my $domdesc = &Apache::lonnet::domain($dom,'description');
2794: if ($domdesc ne '') {
2795: $selectdomain .= ' ('.$domdesc.')';
2796: }
2797: }
2798: }
2799: $selectdomain .= "</option>\n";
1.34 matthew 2800: }
2801: $selectdomain.="</select>";
2802: return $selectdomain;
2803: }
2804:
1.35 matthew 2805: #-------------------------------------------
2806:
1.45 matthew 2807: =pod
2808:
1.648 raeburn 2809: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2810:
1.586 raeburn 2811: input: 4 arguments (two required, two optional) -
2812: $domain - domain of new user
2813: $name - name of form element
2814: $default - Value of 'default' causes a default item to be first
2815: option, and selected by default.
2816: $hide - Value of 'hide' causes hiding of the name of the server,
2817: if 1 server found, or default, if 0 found.
1.594 raeburn 2818: output: returns 2 items:
1.586 raeburn 2819: (a) form element which contains either:
2820: (i) <select name="$name">
2821: <option value="$hostid1">$hostid $servers{$hostid}</option>
2822: <option value="$hostid2">$hostid $servers{$hostid}</option>
2823: </select>
2824: form item if there are multiple library servers in $domain, or
2825: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2826: if there is only one library server in $domain.
2827:
2828: (b) number of library servers found.
2829:
2830: See loncreateuser.pm for example of use.
1.35 matthew 2831:
2832: =cut
2833:
2834: #-------------------------------------------
1.586 raeburn 2835: sub home_server_form_item {
2836: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2837: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2838: my $result;
2839: my $numlib = keys(%servers);
2840: if ($numlib > 1) {
2841: $result .= '<select name="'.$name.'" />'."\n";
2842: if ($default) {
1.804 bisitz 2843: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2844: '</option>'."\n";
2845: }
2846: foreach my $hostid (sort(keys(%servers))) {
2847: $result.= '<option value="'.$hostid.'">'.
2848: $hostid.' '.$servers{$hostid}."</option>\n";
2849: }
2850: $result .= '</select>'."\n";
2851: } elsif ($numlib == 1) {
2852: my $hostid;
2853: foreach my $item (keys(%servers)) {
2854: $hostid = $item;
2855: }
2856: $result .= '<input type="hidden" name="'.$name.'" value="'.
2857: $hostid.'" />';
2858: if (!$hide) {
2859: $result .= $hostid.' '.$servers{$hostid};
2860: }
2861: $result .= "\n";
2862: } elsif ($default) {
2863: $result .= '<input type="hidden" name="'.$name.
2864: '" value="default" />';
2865: if (!$hide) {
2866: $result .= &mt('default');
2867: }
2868: $result .= "\n";
1.33 matthew 2869: }
1.586 raeburn 2870: return ($result,$numlib);
1.33 matthew 2871: }
1.112 bowersj2 2872:
2873: =pod
2874:
1.534 albertel 2875: =back
2876:
1.112 bowersj2 2877: =cut
1.87 matthew 2878:
2879: ###############################################################
1.112 bowersj2 2880: ## Decoding User Agent ##
1.87 matthew 2881: ###############################################################
2882:
2883: =pod
2884:
1.112 bowersj2 2885: =head1 Decoding the User Agent
2886:
2887: =over 4
2888:
2889: =item * &decode_user_agent()
1.87 matthew 2890:
2891: Inputs: $r
2892:
2893: Outputs:
2894:
2895: =over 4
2896:
1.112 bowersj2 2897: =item * $httpbrowser
1.87 matthew 2898:
1.112 bowersj2 2899: =item * $clientbrowser
1.87 matthew 2900:
1.112 bowersj2 2901: =item * $clientversion
1.87 matthew 2902:
1.112 bowersj2 2903: =item * $clientmathml
1.87 matthew 2904:
1.112 bowersj2 2905: =item * $clientunicode
1.87 matthew 2906:
1.112 bowersj2 2907: =item * $clientos
1.87 matthew 2908:
1.1137 raeburn 2909: =item * $clientmobile
2910:
1.1141 raeburn 2911: =item * $clientinfo
2912:
1.1194 raeburn 2913: =item * $clientosversion
2914:
1.87 matthew 2915: =back
2916:
1.157 matthew 2917: =back
2918:
1.87 matthew 2919: =cut
2920:
2921: ###############################################################
2922: ###############################################################
2923: sub decode_user_agent {
1.247 albertel 2924: my ($r)=@_;
1.87 matthew 2925: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2926: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2927: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2928: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2929: my $clientbrowser='unknown';
2930: my $clientversion='0';
2931: my $clientmathml='';
2932: my $clientunicode='0';
1.1137 raeburn 2933: my $clientmobile=0;
1.1194 raeburn 2934: my $clientosversion='';
1.87 matthew 2935: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2936: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2937: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2938: $clientbrowser=$bname;
2939: $httpbrowser=~/$vreg/i;
2940: $clientversion=$1;
2941: $clientmathml=($clientversion>=$minv);
2942: $clientunicode=($clientversion>=$univ);
2943: }
2944: }
2945: my $clientos='unknown';
1.1141 raeburn 2946: my $clientinfo;
1.87 matthew 2947: if (($httpbrowser=~/linux/i) ||
2948: ($httpbrowser=~/unix/i) ||
2949: ($httpbrowser=~/ux/i) ||
2950: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2951: if (($httpbrowser=~/vax/i) ||
2952: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2953: if ($httpbrowser=~/next/i) { $clientos='next'; }
2954: if (($httpbrowser=~/mac/i) ||
2955: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2956: if ($httpbrowser=~/win/i) {
2957: $clientos='win';
2958: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2959: $clientosversion = $1;
2960: }
2961: }
1.87 matthew 2962: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2963: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2964: $clientmobile=lc($1);
2965: }
1.1141 raeburn 2966: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2967: $clientinfo = 'firefox-'.$1;
2968: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2969: $clientinfo = 'chromeframe-'.$1;
2970: }
1.87 matthew 2971: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 2972: $clientunicode,$clientos,$clientmobile,$clientinfo,
2973: $clientosversion);
1.87 matthew 2974: }
2975:
1.32 matthew 2976: ###############################################################
2977: ## Authentication changing form generation subroutines ##
2978: ###############################################################
2979: ##
2980: ## All of the authform_xxxxxxx subroutines take their inputs in a
2981: ## hash, and have reasonable default values.
2982: ##
2983: ## formname = the name given in the <form> tag.
1.35 matthew 2984: #-------------------------------------------
2985:
1.45 matthew 2986: =pod
2987:
1.112 bowersj2 2988: =head1 Authentication Routines
2989:
2990: =over 4
2991:
1.648 raeburn 2992: =item * &authform_xxxxxx()
1.35 matthew 2993:
2994: The authform_xxxxxx subroutines provide javascript and html forms which
2995: handle some of the conveniences required for authentication forms.
2996: This is not an optimal method, but it works.
2997:
2998: =over 4
2999:
1.112 bowersj2 3000: =item * authform_header
1.35 matthew 3001:
1.112 bowersj2 3002: =item * authform_authorwarning
1.35 matthew 3003:
1.112 bowersj2 3004: =item * authform_nochange
1.35 matthew 3005:
1.112 bowersj2 3006: =item * authform_kerberos
1.35 matthew 3007:
1.112 bowersj2 3008: =item * authform_internal
1.35 matthew 3009:
1.112 bowersj2 3010: =item * authform_filesystem
1.35 matthew 3011:
3012: =back
3013:
1.648 raeburn 3014: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3015:
1.35 matthew 3016: =cut
3017:
3018: #-------------------------------------------
1.32 matthew 3019: sub authform_header{
3020: my %in = (
3021: formname => 'cu',
1.80 albertel 3022: kerb_def_dom => '',
1.32 matthew 3023: @_,
3024: );
3025: $in{'formname'} = 'document.' . $in{'formname'};
3026: my $result='';
1.80 albertel 3027:
3028: #---------------------------------------------- Code for upper case translation
3029: my $Javascript_toUpperCase;
3030: unless ($in{kerb_def_dom}) {
3031: $Javascript_toUpperCase =<<"END";
3032: switch (choice) {
3033: case 'krb': currentform.elements[choicearg].value =
3034: currentform.elements[choicearg].value.toUpperCase();
3035: break;
3036: default:
3037: }
3038: END
3039: } else {
3040: $Javascript_toUpperCase = "";
3041: }
3042:
1.165 raeburn 3043: my $radioval = "'nochange'";
1.591 raeburn 3044: if (defined($in{'curr_authtype'})) {
3045: if ($in{'curr_authtype'} ne '') {
3046: $radioval = "'".$in{'curr_authtype'}."arg'";
3047: }
1.174 matthew 3048: }
1.165 raeburn 3049: my $argfield = 'null';
1.591 raeburn 3050: if (defined($in{'mode'})) {
1.165 raeburn 3051: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3052: if (defined($in{'curr_autharg'})) {
3053: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3054: $argfield = "'$in{'curr_autharg'}'";
3055: }
3056: }
3057: }
3058: }
3059:
1.32 matthew 3060: $result.=<<"END";
3061: var current = new Object();
1.165 raeburn 3062: current.radiovalue = $radioval;
3063: current.argfield = $argfield;
1.32 matthew 3064:
3065: function changed_radio(choice,currentform) {
3066: var choicearg = choice + 'arg';
3067: // If a radio button in changed, we need to change the argfield
3068: if (current.radiovalue != choice) {
3069: current.radiovalue = choice;
3070: if (current.argfield != null) {
3071: currentform.elements[current.argfield].value = '';
3072: }
3073: if (choice == 'nochange') {
3074: current.argfield = null;
3075: } else {
3076: current.argfield = choicearg;
3077: switch(choice) {
3078: case 'krb':
3079: currentform.elements[current.argfield].value =
3080: "$in{'kerb_def_dom'}";
3081: break;
3082: default:
3083: break;
3084: }
3085: }
3086: }
3087: return;
3088: }
1.22 www 3089:
1.32 matthew 3090: function changed_text(choice,currentform) {
3091: var choicearg = choice + 'arg';
3092: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3093: $Javascript_toUpperCase
1.32 matthew 3094: // clear old field
3095: if ((current.argfield != choicearg) && (current.argfield != null)) {
3096: currentform.elements[current.argfield].value = '';
3097: }
3098: current.argfield = choicearg;
3099: }
3100: set_auth_radio_buttons(choice,currentform);
3101: return;
1.20 www 3102: }
1.32 matthew 3103:
3104: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3105: var numauthchoices = currentform.login.length;
3106: if (typeof numauthchoices == "undefined") {
3107: return;
3108: }
1.32 matthew 3109: var i=0;
1.986 raeburn 3110: while (i < numauthchoices) {
1.32 matthew 3111: if (currentform.login[i].value == newvalue) { break; }
3112: i++;
3113: }
1.986 raeburn 3114: if (i == numauthchoices) {
1.32 matthew 3115: return;
3116: }
3117: current.radiovalue = newvalue;
3118: currentform.login[i].checked = true;
3119: return;
3120: }
3121: END
3122: return $result;
3123: }
3124:
1.1106 raeburn 3125: sub authform_authorwarning {
1.32 matthew 3126: my $result='';
1.144 matthew 3127: $result='<i>'.
3128: &mt('As a general rule, only authors or co-authors should be '.
3129: 'filesystem authenticated '.
3130: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3131: return $result;
3132: }
3133:
1.1106 raeburn 3134: sub authform_nochange {
1.32 matthew 3135: my %in = (
3136: formname => 'document.cu',
3137: kerb_def_dom => 'MSU.EDU',
3138: @_,
3139: );
1.1106 raeburn 3140: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3141: my $result;
1.1104 raeburn 3142: if (!$authnum) {
1.1105 raeburn 3143: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3144: } else {
3145: $result = '<label>'.&mt('[_1] Do not change login data',
3146: '<input type="radio" name="login" value="nochange" '.
3147: 'checked="checked" onclick="'.
1.281 albertel 3148: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3149: '</label>';
1.586 raeburn 3150: }
1.32 matthew 3151: return $result;
3152: }
3153:
1.591 raeburn 3154: sub authform_kerberos {
1.32 matthew 3155: my %in = (
3156: formname => 'document.cu',
3157: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3158: kerb_def_auth => 'krb4',
1.32 matthew 3159: @_,
3160: );
1.586 raeburn 3161: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3162: $autharg,$jscall,$disabled);
1.1106 raeburn 3163: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3164: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3165: $check5 = ' checked="checked"';
1.80 albertel 3166: } else {
1.772 bisitz 3167: $check4 = ' checked="checked"';
1.80 albertel 3168: }
1.1259 raeburn 3169: if ($in{'readonly'}) {
3170: $disabled = ' disabled="disabled"';
3171: }
1.165 raeburn 3172: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3173: if (defined($in{'curr_authtype'})) {
3174: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3175: $krbcheck = ' checked="checked"';
1.623 raeburn 3176: if (defined($in{'mode'})) {
3177: if ($in{'mode'} eq 'modifyuser') {
3178: $krbcheck = '';
3179: }
3180: }
1.591 raeburn 3181: if (defined($in{'curr_kerb_ver'})) {
3182: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3183: $check5 = ' checked="checked"';
1.591 raeburn 3184: $check4 = '';
3185: } else {
1.772 bisitz 3186: $check4 = ' checked="checked"';
1.591 raeburn 3187: $check5 = '';
3188: }
1.586 raeburn 3189: }
1.591 raeburn 3190: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3191: $krbarg = $in{'curr_autharg'};
3192: }
1.586 raeburn 3193: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3194: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3195: $result =
3196: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3197: $in{'curr_autharg'},$krbver);
3198: } else {
3199: $result =
3200: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3201: }
3202: return $result;
3203: }
3204: }
3205: } else {
3206: if ($authnum == 1) {
1.784 bisitz 3207: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3208: }
3209: }
1.586 raeburn 3210: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3211: return;
1.587 raeburn 3212: } elsif ($authtype eq '') {
1.591 raeburn 3213: if (defined($in{'mode'})) {
1.587 raeburn 3214: if ($in{'mode'} eq 'modifycourse') {
3215: if ($authnum == 1) {
1.1259 raeburn 3216: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3217: }
3218: }
3219: }
1.586 raeburn 3220: }
3221: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3222: if ($authtype eq '') {
3223: $authtype = '<input type="radio" name="login" value="krb" '.
3224: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3225: $krbcheck.$disabled.' />';
1.586 raeburn 3226: }
3227: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3228: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3229: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3230: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3231: $in{'curr_authtype'} eq 'krb4')) {
3232: $result .= &mt
1.144 matthew 3233: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3234: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3235: '<label>'.$authtype,
1.281 albertel 3236: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3237: 'value="'.$krbarg.'" '.
1.1259 raeburn 3238: 'onchange="'.$jscall.'"'.$disabled.' />',
3239: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3240: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3241: '</label>');
1.586 raeburn 3242: } elsif ($can_assign{'krb4'}) {
3243: $result .= &mt
3244: ('[_1] Kerberos authenticated with domain [_2] '.
3245: '[_3] Version 4 [_4]',
3246: '<label>'.$authtype,
3247: '</label><input type="text" size="10" name="krbarg" '.
3248: 'value="'.$krbarg.'" '.
1.1259 raeburn 3249: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3250: '<label><input type="hidden" name="krbver" value="4" />',
3251: '</label>');
3252: } elsif ($can_assign{'krb5'}) {
3253: $result .= &mt
3254: ('[_1] Kerberos authenticated with domain [_2] '.
3255: '[_3] Version 5 [_4]',
3256: '<label>'.$authtype,
3257: '</label><input type="text" size="10" name="krbarg" '.
3258: 'value="'.$krbarg.'" '.
1.1259 raeburn 3259: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3260: '<label><input type="hidden" name="krbver" value="5" />',
3261: '</label>');
3262: }
1.32 matthew 3263: return $result;
3264: }
3265:
1.1106 raeburn 3266: sub authform_internal {
1.586 raeburn 3267: my %in = (
1.32 matthew 3268: formname => 'document.cu',
3269: kerb_def_dom => 'MSU.EDU',
3270: @_,
3271: );
1.1259 raeburn 3272: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3273: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3274: if ($in{'readonly'}) {
3275: $disabled = ' disabled="disabled"';
3276: }
1.591 raeburn 3277: if (defined($in{'curr_authtype'})) {
3278: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3279: if ($can_assign{'int'}) {
1.772 bisitz 3280: $intcheck = 'checked="checked" ';
1.623 raeburn 3281: if (defined($in{'mode'})) {
3282: if ($in{'mode'} eq 'modifyuser') {
3283: $intcheck = '';
3284: }
3285: }
1.591 raeburn 3286: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3287: $intarg = $in{'curr_autharg'};
3288: }
3289: } else {
3290: $result = &mt('Currently internally authenticated.');
3291: return $result;
1.165 raeburn 3292: }
3293: }
1.586 raeburn 3294: } else {
3295: if ($authnum == 1) {
1.784 bisitz 3296: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3297: }
3298: }
3299: if (!$can_assign{'int'}) {
3300: return;
1.587 raeburn 3301: } elsif ($authtype eq '') {
1.591 raeburn 3302: if (defined($in{'mode'})) {
1.587 raeburn 3303: if ($in{'mode'} eq 'modifycourse') {
3304: if ($authnum == 1) {
1.1259 raeburn 3305: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3306: }
3307: }
3308: }
1.165 raeburn 3309: }
1.586 raeburn 3310: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3311: if ($authtype eq '') {
3312: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3313: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3314: }
1.605 bisitz 3315: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3316: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3317: $result = &mt
1.144 matthew 3318: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3319: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3320: $result.='<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>';
1.32 matthew 3321: return $result;
3322: }
3323:
1.1104 raeburn 3324: sub authform_local {
1.32 matthew 3325: my %in = (
3326: formname => 'document.cu',
3327: kerb_def_dom => 'MSU.EDU',
3328: @_,
3329: );
1.1259 raeburn 3330: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3331: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3332: if ($in{'readonly'}) {
3333: $disabled = ' disabled="disabled"';
3334: }
1.591 raeburn 3335: if (defined($in{'curr_authtype'})) {
3336: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3337: if ($can_assign{'loc'}) {
1.772 bisitz 3338: $loccheck = 'checked="checked" ';
1.623 raeburn 3339: if (defined($in{'mode'})) {
3340: if ($in{'mode'} eq 'modifyuser') {
3341: $loccheck = '';
3342: }
3343: }
1.591 raeburn 3344: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3345: $locarg = $in{'curr_autharg'};
3346: }
3347: } else {
3348: $result = &mt('Currently using local (institutional) authentication.');
3349: return $result;
1.165 raeburn 3350: }
3351: }
1.586 raeburn 3352: } else {
3353: if ($authnum == 1) {
1.784 bisitz 3354: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3355: }
3356: }
3357: if (!$can_assign{'loc'}) {
3358: return;
1.587 raeburn 3359: } elsif ($authtype eq '') {
1.591 raeburn 3360: if (defined($in{'mode'})) {
1.587 raeburn 3361: if ($in{'mode'} eq 'modifycourse') {
3362: if ($authnum == 1) {
1.1259 raeburn 3363: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3364: }
3365: }
3366: }
1.165 raeburn 3367: }
1.586 raeburn 3368: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3369: if ($authtype eq '') {
3370: $authtype = '<input type="radio" name="login" value="loc" '.
3371: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3372: $jscall.'"'.$disabled.' />';
1.586 raeburn 3373: }
3374: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3375: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3376: $result = &mt('[_1] Local Authentication with argument [_2]',
3377: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3378: return $result;
3379: }
3380:
1.1106 raeburn 3381: sub authform_filesystem {
1.32 matthew 3382: my %in = (
3383: formname => 'document.cu',
3384: kerb_def_dom => 'MSU.EDU',
3385: @_,
3386: );
1.1259 raeburn 3387: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3388: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3389: if ($in{'readonly'}) {
3390: $disabled = ' disabled="disabled"';
3391: }
1.591 raeburn 3392: if (defined($in{'curr_authtype'})) {
3393: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3394: if ($can_assign{'fsys'}) {
1.772 bisitz 3395: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3396: if (defined($in{'mode'})) {
3397: if ($in{'mode'} eq 'modifyuser') {
3398: $fsyscheck = '';
3399: }
3400: }
1.586 raeburn 3401: } else {
3402: $result = &mt('Currently Filesystem Authenticated.');
3403: return $result;
1.1259 raeburn 3404: }
1.586 raeburn 3405: }
3406: } else {
3407: if ($authnum == 1) {
1.784 bisitz 3408: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3409: }
3410: }
3411: if (!$can_assign{'fsys'}) {
3412: return;
1.587 raeburn 3413: } elsif ($authtype eq '') {
1.591 raeburn 3414: if (defined($in{'mode'})) {
1.587 raeburn 3415: if ($in{'mode'} eq 'modifycourse') {
3416: if ($authnum == 1) {
1.1259 raeburn 3417: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3418: }
3419: }
3420: }
1.586 raeburn 3421: }
3422: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3423: if ($authtype eq '') {
3424: $authtype = '<input type="radio" name="login" value="fsys" '.
3425: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3426: $jscall.'"'.$disabled.' />';
1.586 raeburn 3427: }
3428: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3429: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3430: $result = &mt
1.144 matthew 3431: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3432: '<label><input type="radio" name="login" value="fsys" '.
1.1259 raeburn 3433: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />',
1.605 bisitz 3434: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.1259 raeburn 3435: 'onchange="'.$jscall.'"'.$disabled.' />');
1.32 matthew 3436: return $result;
3437: }
3438:
1.586 raeburn 3439: sub get_assignable_auth {
3440: my ($dom) = @_;
3441: if ($dom eq '') {
3442: $dom = $env{'request.role.domain'};
3443: }
3444: my %can_assign = (
3445: krb4 => 1,
3446: krb5 => 1,
3447: int => 1,
3448: loc => 1,
3449: );
3450: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3451: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3452: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3453: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3454: my $context;
3455: if ($env{'request.role'} =~ /^au/) {
3456: $context = 'author';
1.1259 raeburn 3457: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3458: $context = 'domain';
3459: } elsif ($env{'request.course.id'}) {
3460: $context = 'course';
3461: }
3462: if ($context) {
3463: if (ref($authhash->{$context}) eq 'HASH') {
3464: %can_assign = %{$authhash->{$context}};
3465: }
3466: }
3467: }
3468: }
3469: my $authnum = 0;
3470: foreach my $key (keys(%can_assign)) {
3471: if ($can_assign{$key}) {
3472: $authnum ++;
3473: }
3474: }
3475: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3476: $authnum --;
3477: }
3478: return ($authnum,%can_assign);
3479: }
3480:
1.80 albertel 3481: ###############################################################
3482: ## Get Kerberos Defaults for Domain ##
3483: ###############################################################
3484: ##
3485: ## Returns default kerberos version and an associated argument
3486: ## as listed in file domain.tab. If not listed, provides
3487: ## appropriate default domain and kerberos version.
3488: ##
3489: #-------------------------------------------
3490:
3491: =pod
3492:
1.648 raeburn 3493: =item * &get_kerberos_defaults()
1.80 albertel 3494:
3495: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3496: version and domain. If not found, it defaults to version 4 and the
3497: domain of the server.
1.80 albertel 3498:
1.648 raeburn 3499: =over 4
3500:
1.80 albertel 3501: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3502:
1.648 raeburn 3503: =back
3504:
3505: =back
3506:
1.80 albertel 3507: =cut
3508:
3509: #-------------------------------------------
3510: sub get_kerberos_defaults {
3511: my $domain=shift;
1.641 raeburn 3512: my ($krbdef,$krbdefdom);
3513: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3514: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3515: $krbdef = $domdefaults{'auth_def'};
3516: $krbdefdom = $domdefaults{'auth_arg_def'};
3517: } else {
1.80 albertel 3518: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3519: my $krbdefdom=$1;
3520: $krbdefdom=~tr/a-z/A-Z/;
3521: $krbdef = "krb4";
3522: }
3523: return ($krbdef,$krbdefdom);
3524: }
1.112 bowersj2 3525:
1.32 matthew 3526:
1.46 matthew 3527: ###############################################################
3528: ## Thesaurus Functions ##
3529: ###############################################################
1.20 www 3530:
1.46 matthew 3531: =pod
1.20 www 3532:
1.112 bowersj2 3533: =head1 Thesaurus Functions
3534:
3535: =over 4
3536:
1.648 raeburn 3537: =item * &initialize_keywords()
1.46 matthew 3538:
3539: Initializes the package variable %Keywords if it is empty. Uses the
3540: package variable $thesaurus_db_file.
3541:
3542: =cut
3543:
3544: ###################################################
3545:
3546: sub initialize_keywords {
3547: return 1 if (scalar keys(%Keywords));
3548: # If we are here, %Keywords is empty, so fill it up
3549: # Make sure the file we need exists...
3550: if (! -e $thesaurus_db_file) {
3551: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3552: " failed because it does not exist");
3553: return 0;
3554: }
3555: # Set up the hash as a database
3556: my %thesaurus_db;
3557: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3558: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3559: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3560: $thesaurus_db_file);
3561: return 0;
3562: }
3563: # Get the average number of appearances of a word.
3564: my $avecount = $thesaurus_db{'average.count'};
3565: # Put keywords (those that appear > average) into %Keywords
3566: while (my ($word,$data)=each (%thesaurus_db)) {
3567: my ($count,undef) = split /:/,$data;
3568: $Keywords{$word}++ if ($count > $avecount);
3569: }
3570: untie %thesaurus_db;
3571: # Remove special values from %Keywords.
1.356 albertel 3572: foreach my $value ('total.count','average.count') {
3573: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3574: }
1.46 matthew 3575: return 1;
3576: }
3577:
3578: ###################################################
3579:
3580: =pod
3581:
1.648 raeburn 3582: =item * &keyword($word)
1.46 matthew 3583:
3584: Returns true if $word is a keyword. A keyword is a word that appears more
3585: than the average number of times in the thesaurus database. Calls
3586: &initialize_keywords
3587:
3588: =cut
3589:
3590: ###################################################
1.20 www 3591:
3592: sub keyword {
1.46 matthew 3593: return if (!&initialize_keywords());
3594: my $word=lc(shift());
3595: $word=~s/\W//g;
3596: return exists($Keywords{$word});
1.20 www 3597: }
1.46 matthew 3598:
3599: ###############################################################
3600:
3601: =pod
1.20 www 3602:
1.648 raeburn 3603: =item * &get_related_words()
1.46 matthew 3604:
1.160 matthew 3605: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3606: an array of words. If the keyword is not in the thesaurus, an empty array
3607: will be returned. The order of the words returned is determined by the
3608: database which holds them.
3609:
3610: Uses global $thesaurus_db_file.
3611:
1.1057 foxr 3612:
1.46 matthew 3613: =cut
3614:
3615: ###############################################################
3616: sub get_related_words {
3617: my $keyword = shift;
3618: my %thesaurus_db;
3619: if (! -e $thesaurus_db_file) {
3620: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3621: "failed because the file does not exist");
3622: return ();
3623: }
3624: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3625: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3626: return ();
3627: }
3628: my @Words=();
1.429 www 3629: my $count=0;
1.46 matthew 3630: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3631: # The first element is the number of times
3632: # the word appears. We do not need it now.
1.429 www 3633: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3634: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3635: my $threshold=$mostfrequentcount/10;
3636: foreach my $possibleword (@RelatedWords) {
3637: my ($word,$wordcount)=split(/\,/,$possibleword);
3638: if ($wordcount>$threshold) {
3639: push(@Words,$word);
3640: $count++;
3641: if ($count>10) { last; }
3642: }
1.20 www 3643: }
3644: }
1.46 matthew 3645: untie %thesaurus_db;
3646: return @Words;
1.14 harris41 3647: }
1.1090 foxr 3648: ###############################################################
3649: #
3650: # Spell checking
3651: #
3652:
3653: =pod
3654:
1.1142 raeburn 3655: =back
3656:
1.1090 foxr 3657: =head1 Spell checking
3658:
3659: =over 4
3660:
3661: =item * &check_spelling($wordlist $language)
3662:
3663: Takes a string containing words and feeds it to an external
3664: spellcheck program via a pipeline. Returns a string containing
3665: them mis-spelled words.
3666:
3667: Parameters:
3668:
3669: =over 4
3670:
3671: =item - $wordlist
3672:
3673: String that will be fed into the spellcheck program.
3674:
3675: =item - $language
3676:
3677: Language string that specifies the language for which the spell
3678: check will be performed.
3679:
3680: =back
3681:
3682: =back
3683:
3684: Note: This sub assumes that aspell is installed.
3685:
3686:
3687: =cut
3688:
1.46 matthew 3689:
1.1090 foxr 3690: sub check_spelling {
3691: my ($wordlist, $language) = @_;
1.1091 foxr 3692: my @misspellings;
3693:
3694: # Generate the speller and set the langauge.
3695: # if explicitly selected:
1.1090 foxr 3696:
1.1091 foxr 3697: my $speller = Text::Aspell->new;
1.1090 foxr 3698: if ($language) {
1.1091 foxr 3699: $speller->set_option('lang', $language);
1.1090 foxr 3700: }
3701:
1.1091 foxr 3702: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3703:
1.1091 foxr 3704: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3705:
1.1091 foxr 3706: foreach my $word (@words) {
3707: if(! $speller->check($word)) {
3708: push(@misspellings, $word);
1.1090 foxr 3709: }
3710: }
1.1091 foxr 3711: return join(' ', @misspellings);
3712:
1.1090 foxr 3713: }
3714:
1.61 www 3715: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3716: =pod
3717:
1.112 bowersj2 3718: =head1 User Name Functions
3719:
3720: =over 4
3721:
1.648 raeburn 3722: =item * &plainname($uname,$udom,$first)
1.81 albertel 3723:
1.112 bowersj2 3724: Takes a users logon name and returns it as a string in
1.226 albertel 3725: "first middle last generation" form
3726: if $first is set to 'lastname' then it returns it as
3727: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3728:
3729: =cut
1.61 www 3730:
1.295 www 3731:
1.81 albertel 3732: ###############################################################
1.61 www 3733: sub plainname {
1.226 albertel 3734: my ($uname,$udom,$first)=@_;
1.537 albertel 3735: return if (!defined($uname) || !defined($udom));
1.295 www 3736: my %names=&getnames($uname,$udom);
1.226 albertel 3737: my $name=&Apache::lonnet::format_name($names{'firstname'},
3738: $names{'middlename'},
3739: $names{'lastname'},
3740: $names{'generation'},$first);
3741: $name=~s/^\s+//;
1.62 www 3742: $name=~s/\s+$//;
3743: $name=~s/\s+/ /g;
1.353 albertel 3744: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3745: return $name;
1.61 www 3746: }
1.66 www 3747:
3748: # -------------------------------------------------------------------- Nickname
1.81 albertel 3749: =pod
3750:
1.648 raeburn 3751: =item * &nickname($uname,$udom)
1.81 albertel 3752:
3753: Gets a users name and returns it as a string as
3754:
3755: ""nickname""
1.66 www 3756:
1.81 albertel 3757: if the user has a nickname or
3758:
3759: "first middle last generation"
3760:
3761: if the user does not
3762:
3763: =cut
1.66 www 3764:
3765: sub nickname {
3766: my ($uname,$udom)=@_;
1.537 albertel 3767: return if (!defined($uname) || !defined($udom));
1.295 www 3768: my %names=&getnames($uname,$udom);
1.68 albertel 3769: my $name=$names{'nickname'};
1.66 www 3770: if ($name) {
3771: $name='"'.$name.'"';
3772: } else {
3773: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3774: $names{'lastname'}.' '.$names{'generation'};
3775: $name=~s/\s+$//;
3776: $name=~s/\s+/ /g;
3777: }
3778: return $name;
3779: }
3780:
1.295 www 3781: sub getnames {
3782: my ($uname,$udom)=@_;
1.537 albertel 3783: return if (!defined($uname) || !defined($udom));
1.433 albertel 3784: if ($udom eq 'public' && $uname eq 'public') {
3785: return ('lastname' => &mt('Public'));
3786: }
1.295 www 3787: my $id=$uname.':'.$udom;
3788: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3789: if ($cached) {
3790: return %{$names};
3791: } else {
3792: my %loadnames=&Apache::lonnet::get('environment',
3793: ['firstname','middlename','lastname','generation','nickname'],
3794: $udom,$uname);
3795: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3796: return %loadnames;
3797: }
3798: }
1.61 www 3799:
1.542 raeburn 3800: # -------------------------------------------------------------------- getemails
1.648 raeburn 3801:
1.542 raeburn 3802: =pod
3803:
1.648 raeburn 3804: =item * &getemails($uname,$udom)
1.542 raeburn 3805:
3806: Gets a user's email information and returns it as a hash with keys:
3807: notification, critnotification, permanentemail
3808:
3809: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3810: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3811:
1.648 raeburn 3812:
1.542 raeburn 3813: =cut
3814:
1.648 raeburn 3815:
1.466 albertel 3816: sub getemails {
3817: my ($uname,$udom)=@_;
3818: if ($udom eq 'public' && $uname eq 'public') {
3819: return;
3820: }
1.467 www 3821: if (!$udom) { $udom=$env{'user.domain'}; }
3822: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3823: my $id=$uname.':'.$udom;
3824: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3825: if ($cached) {
3826: return %{$names};
3827: } else {
3828: my %loadnames=&Apache::lonnet::get('environment',
3829: ['notification','critnotification',
3830: 'permanentemail'],
3831: $udom,$uname);
3832: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3833: return %loadnames;
3834: }
3835: }
3836:
1.551 albertel 3837: sub flush_email_cache {
3838: my ($uname,$udom)=@_;
3839: if (!$udom) { $udom =$env{'user.domain'}; }
3840: if (!$uname) { $uname=$env{'user.name'}; }
3841: return if ($udom eq 'public' && $uname eq 'public');
3842: my $id=$uname.':'.$udom;
3843: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3844: }
3845:
1.728 raeburn 3846: # -------------------------------------------------------------------- getlangs
3847:
3848: =pod
3849:
3850: =item * &getlangs($uname,$udom)
3851:
3852: Gets a user's language preference and returns it as a hash with key:
3853: language.
3854:
3855: =cut
3856:
3857:
3858: sub getlangs {
3859: my ($uname,$udom) = @_;
3860: if (!$udom) { $udom =$env{'user.domain'}; }
3861: if (!$uname) { $uname=$env{'user.name'}; }
3862: my $id=$uname.':'.$udom;
3863: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3864: if ($cached) {
3865: return %{$langs};
3866: } else {
3867: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3868: $udom,$uname);
3869: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3870: return %loadlangs;
3871: }
3872: }
3873:
3874: sub flush_langs_cache {
3875: my ($uname,$udom)=@_;
3876: if (!$udom) { $udom =$env{'user.domain'}; }
3877: if (!$uname) { $uname=$env{'user.name'}; }
3878: return if ($udom eq 'public' && $uname eq 'public');
3879: my $id=$uname.':'.$udom;
3880: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3881: }
3882:
1.61 www 3883: # ------------------------------------------------------------------ Screenname
1.81 albertel 3884:
3885: =pod
3886:
1.648 raeburn 3887: =item * &screenname($uname,$udom)
1.81 albertel 3888:
3889: Gets a users screenname and returns it as a string
3890:
3891: =cut
1.61 www 3892:
3893: sub screenname {
3894: my ($uname,$udom)=@_;
1.258 albertel 3895: if ($uname eq $env{'user.name'} &&
3896: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3897: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3898: return $names{'screenname'};
1.62 www 3899: }
3900:
1.212 albertel 3901:
1.802 bisitz 3902: # ------------------------------------------------------------- Confirm Wrapper
3903: =pod
3904:
1.1142 raeburn 3905: =item * &confirmwrapper($message)
1.802 bisitz 3906:
3907: Wrap messages about completion of operation in box
3908:
3909: =cut
3910:
3911: sub confirmwrapper {
3912: my ($message)=@_;
3913: if ($message) {
3914: return "\n".'<div class="LC_confirm_box">'."\n"
3915: .$message."\n"
3916: .'</div>'."\n";
3917: } else {
3918: return $message;
3919: }
3920: }
3921:
1.62 www 3922: # ------------------------------------------------------------- Message Wrapper
3923:
3924: sub messagewrapper {
1.369 www 3925: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3926: return
1.441 albertel 3927: '<a href="/adm/email?compose=individual&'.
3928: 'recname='.$username.'&recdom='.$domain.
3929: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3930: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3931: }
1.802 bisitz 3932:
1.74 www 3933: # --------------------------------------------------------------- Notes Wrapper
3934:
3935: sub noteswrapper {
3936: my ($link,$un,$do)=@_;
3937: return
1.896 amueller 3938: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3939: }
1.802 bisitz 3940:
1.62 www 3941: # ------------------------------------------------------------- Aboutme Wrapper
3942:
3943: sub aboutmewrapper {
1.1070 raeburn 3944: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3945: if (!defined($username) && !defined($domain)) {
3946: return;
3947: }
1.1096 raeburn 3948: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3949: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3950: }
3951:
3952: # ------------------------------------------------------------ Syllabus Wrapper
3953:
3954: sub syllabuswrapper {
1.707 bisitz 3955: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3956: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3957: }
1.14 harris41 3958:
1.802 bisitz 3959: # -----------------------------------------------------------------------------
3960:
1.208 matthew 3961: sub track_student_link {
1.887 raeburn 3962: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3963: my $link ="/adm/trackstudent?";
1.208 matthew 3964: my $title = 'View recent activity';
3965: if (defined($sname) && $sname !~ /^\s*$/ &&
3966: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3967: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3968: $title .= ' of this student';
1.268 albertel 3969: }
1.208 matthew 3970: if (defined($target) && $target !~ /^\s*$/) {
3971: $target = qq{target="$target"};
3972: } else {
3973: $target = '';
3974: }
1.268 albertel 3975: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3976: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3977: $title = &mt($title);
3978: $linktext = &mt($linktext);
1.448 albertel 3979: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3980: &help_open_topic('View_recent_activity');
1.208 matthew 3981: }
3982:
1.781 raeburn 3983: sub slot_reservations_link {
3984: my ($linktext,$sname,$sdom,$target) = @_;
3985: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3986: my $title = 'View slot reservation history';
3987: if (defined($sname) && $sname !~ /^\s*$/ &&
3988: defined($sdom) && $sdom !~ /^\s*$/) {
3989: $link .= "&uname=$sname&udom=$sdom";
3990: $title .= ' of this student';
3991: }
3992: if (defined($target) && $target !~ /^\s*$/) {
3993: $target = qq{target="$target"};
3994: } else {
3995: $target = '';
3996: }
3997: $title = &mt($title);
3998: $linktext = &mt($linktext);
3999: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4000: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4001:
4002: }
4003:
1.508 www 4004: # ===================================================== Display a student photo
4005:
4006:
1.509 albertel 4007: sub student_image_tag {
1.508 www 4008: my ($domain,$user)=@_;
4009: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4010: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4011: return '<img src="'.$imgsrc.'" align="right" />';
4012: } else {
4013: return '';
4014: }
4015: }
4016:
1.112 bowersj2 4017: =pod
4018:
4019: =back
4020:
4021: =head1 Access .tab File Data
4022:
4023: =over 4
4024:
1.648 raeburn 4025: =item * &languageids()
1.112 bowersj2 4026:
4027: returns list of all language ids
4028:
4029: =cut
4030:
1.14 harris41 4031: sub languageids {
1.16 harris41 4032: return sort(keys(%language));
1.14 harris41 4033: }
4034:
1.112 bowersj2 4035: =pod
4036:
1.648 raeburn 4037: =item * &languagedescription()
1.112 bowersj2 4038:
4039: returns description of a specified language id
4040:
4041: =cut
4042:
1.14 harris41 4043: sub languagedescription {
1.125 www 4044: my $code=shift;
4045: return ($supported_language{$code}?'* ':'').
4046: $language{$code}.
1.126 www 4047: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4048: }
4049:
1.1048 foxr 4050: =pod
4051:
4052: =item * &plainlanguagedescription
4053:
4054: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4055: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4056:
4057: =cut
4058:
1.145 www 4059: sub plainlanguagedescription {
4060: my $code=shift;
4061: return $language{$code};
4062: }
4063:
1.1048 foxr 4064: =pod
4065:
4066: =item * &supportedlanguagecode
4067:
4068: Returns the supported language code (e.g. sptutf maps to pt) given a language
4069: code.
4070:
4071: =cut
4072:
1.145 www 4073: sub supportedlanguagecode {
4074: my $code=shift;
4075: return $supported_language{$code};
1.97 www 4076: }
4077:
1.112 bowersj2 4078: =pod
4079:
1.1048 foxr 4080: =item * &latexlanguage()
4081:
4082: Given a language key code returns the correspondnig language to use
4083: to select the correct hyphenation on LaTeX printouts. This is undef if there
4084: is no supported hyphenation for the language code.
4085:
4086: =cut
4087:
4088: sub latexlanguage {
4089: my $code = shift;
4090: return $latex_language{$code};
4091: }
4092:
4093: =pod
4094:
4095: =item * &latexhyphenation()
4096:
4097: Same as above but what's supplied is the language as it might be stored
4098: in the metadata.
4099:
4100: =cut
4101:
4102: sub latexhyphenation {
4103: my $key = shift;
4104: return $latex_language_bykey{$key};
4105: }
4106:
4107: =pod
4108:
1.648 raeburn 4109: =item * ©rightids()
1.112 bowersj2 4110:
4111: returns list of all copyrights
4112:
4113: =cut
4114:
4115: sub copyrightids {
4116: return sort(keys(%cprtag));
4117: }
4118:
4119: =pod
4120:
1.648 raeburn 4121: =item * ©rightdescription()
1.112 bowersj2 4122:
4123: returns description of a specified copyright id
4124:
4125: =cut
4126:
4127: sub copyrightdescription {
1.166 www 4128: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4129: }
1.197 matthew 4130:
4131: =pod
4132:
1.648 raeburn 4133: =item * &source_copyrightids()
1.192 taceyjo1 4134:
4135: returns list of all source copyrights
4136:
4137: =cut
4138:
4139: sub source_copyrightids {
4140: return sort(keys(%scprtag));
4141: }
4142:
4143: =pod
4144:
1.648 raeburn 4145: =item * &source_copyrightdescription()
1.192 taceyjo1 4146:
4147: returns description of a specified source copyright id
4148:
4149: =cut
4150:
4151: sub source_copyrightdescription {
4152: return &mt($scprtag{shift(@_)});
4153: }
1.112 bowersj2 4154:
4155: =pod
4156:
1.648 raeburn 4157: =item * &filecategories()
1.112 bowersj2 4158:
4159: returns list of all file categories
4160:
4161: =cut
4162:
4163: sub filecategories {
4164: return sort(keys(%category_extensions));
4165: }
4166:
4167: =pod
4168:
1.648 raeburn 4169: =item * &filecategorytypes()
1.112 bowersj2 4170:
4171: returns list of file types belonging to a given file
4172: category
4173:
4174: =cut
4175:
4176: sub filecategorytypes {
1.356 albertel 4177: my ($cat) = @_;
1.1248 raeburn 4178: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4179: return @{$category_extensions{lc($cat)}};
4180: } else {
4181: return ();
4182: }
1.112 bowersj2 4183: }
4184:
4185: =pod
4186:
1.648 raeburn 4187: =item * &fileembstyle()
1.112 bowersj2 4188:
4189: returns embedding style for a specified file type
4190:
4191: =cut
4192:
4193: sub fileembstyle {
4194: return $fe{lc(shift(@_))};
1.169 www 4195: }
4196:
1.351 www 4197: sub filemimetype {
4198: return $fm{lc(shift(@_))};
4199: }
4200:
1.169 www 4201:
4202: sub filecategoryselect {
4203: my ($name,$value)=@_;
1.189 matthew 4204: return &select_form($value,$name,
1.970 raeburn 4205: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4206: }
4207:
4208: =pod
4209:
1.648 raeburn 4210: =item * &filedescription()
1.112 bowersj2 4211:
4212: returns description for a specified file type
4213:
4214: =cut
4215:
4216: sub filedescription {
1.188 matthew 4217: my $file_description = $fd{lc(shift())};
4218: $file_description =~ s:([\[\]]):~$1:g;
4219: return &mt($file_description);
1.112 bowersj2 4220: }
4221:
4222: =pod
4223:
1.648 raeburn 4224: =item * &filedescriptionex()
1.112 bowersj2 4225:
4226: returns description for a specified file type with
4227: extra formatting
4228:
4229: =cut
4230:
4231: sub filedescriptionex {
4232: my $ex=shift;
1.188 matthew 4233: my $file_description = $fd{lc($ex)};
4234: $file_description =~ s:([\[\]]):~$1:g;
4235: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4236: }
4237:
4238: # End of .tab access
4239: =pod
4240:
4241: =back
4242:
4243: =cut
4244:
4245: # ------------------------------------------------------------------ File Types
4246: sub fileextensions {
4247: return sort(keys(%fe));
4248: }
4249:
1.97 www 4250: # ----------------------------------------------------------- Display Languages
4251: # returns a hash with all desired display languages
4252: #
4253:
4254: sub display_languages {
4255: my %languages=();
1.695 raeburn 4256: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4257: $languages{$lang}=1;
1.97 www 4258: }
4259: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4260: if ($env{'form.displaylanguage'}) {
1.356 albertel 4261: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4262: $languages{$lang}=1;
1.97 www 4263: }
4264: }
4265: return %languages;
1.14 harris41 4266: }
4267:
1.582 albertel 4268: sub languages {
4269: my ($possible_langs) = @_;
1.695 raeburn 4270: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4271: if (!ref($possible_langs)) {
4272: if( wantarray ) {
4273: return @preferred_langs;
4274: } else {
4275: return $preferred_langs[0];
4276: }
4277: }
4278: my %possibilities = map { $_ => 1 } (@$possible_langs);
4279: my @preferred_possibilities;
4280: foreach my $preferred_lang (@preferred_langs) {
4281: if (exists($possibilities{$preferred_lang})) {
4282: push(@preferred_possibilities, $preferred_lang);
4283: }
4284: }
4285: if( wantarray ) {
4286: return @preferred_possibilities;
4287: }
4288: return $preferred_possibilities[0];
4289: }
4290:
1.742 raeburn 4291: sub user_lang {
4292: my ($touname,$toudom,$fromcid) = @_;
4293: my @userlangs;
4294: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4295: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4296: $env{'course.'.$fromcid.'.languages'}));
4297: } else {
4298: my %langhash = &getlangs($touname,$toudom);
4299: if ($langhash{'languages'} ne '') {
4300: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4301: } else {
4302: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4303: if ($domdefs{'lang_def'} ne '') {
4304: @userlangs = ($domdefs{'lang_def'});
4305: }
4306: }
4307: }
4308: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4309: my $user_lh = Apache::localize->get_handle(@languages);
4310: return $user_lh;
4311: }
4312:
4313:
1.112 bowersj2 4314: ###############################################################
4315: ## Student Answer Attempts ##
4316: ###############################################################
4317:
4318: =pod
4319:
4320: =head1 Alternate Problem Views
4321:
4322: =over 4
4323:
1.648 raeburn 4324: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4325: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4326:
4327: Return string with previous attempt on problem. Arguments:
4328:
4329: =over 4
4330:
4331: =item * $symb: Problem, including path
4332:
4333: =item * $username: username of the desired student
4334:
4335: =item * $domain: domain of the desired student
1.14 harris41 4336:
1.112 bowersj2 4337: =item * $course: Course ID
1.14 harris41 4338:
1.112 bowersj2 4339: =item * $getattempt: Leave blank for all attempts, otherwise put
4340: something
1.14 harris41 4341:
1.112 bowersj2 4342: =item * $regexp: if string matches this regexp, the string will be
4343: sent to $gradesub
1.14 harris41 4344:
1.112 bowersj2 4345: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4346:
1.1199 raeburn 4347: =item * $usec: section of the desired student
4348:
4349: =item * $identifier: counter for student (multiple students one problem) or
4350: problem (one student; whole sequence).
4351:
1.112 bowersj2 4352: =back
1.14 harris41 4353:
1.112 bowersj2 4354: The output string is a table containing all desired attempts, if any.
1.16 harris41 4355:
1.112 bowersj2 4356: =cut
1.1 albertel 4357:
4358: sub get_previous_attempt {
1.1199 raeburn 4359: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4360: my $prevattempts='';
1.43 ng 4361: no strict 'refs';
1.1 albertel 4362: if ($symb) {
1.3 albertel 4363: my (%returnhash)=
4364: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4365: if ($returnhash{'version'}) {
4366: my %lasthash=();
4367: my $version;
4368: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4369: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4370: if ($key =~ /\.rawrndseed$/) {
4371: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4372: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4373: } else {
4374: $lasthash{$key}=$returnhash{$version.':'.$key};
4375: }
1.19 harris41 4376: }
1.1 albertel 4377: }
1.596 albertel 4378: $prevattempts=&start_data_table().&start_data_table_header_row();
4379: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4380: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4381: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4382: foreach my $key (sort(keys(%lasthash))) {
4383: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4384: if ($#parts > 0) {
1.31 albertel 4385: my $data=$parts[-1];
1.989 raeburn 4386: next if ($data eq 'foilorder');
1.31 albertel 4387: pop(@parts);
1.1010 www 4388: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4389: if ($data eq 'type') {
4390: unless ($showsurv) {
4391: my $id = join(',',@parts);
4392: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4393: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4394: $lasthidden{$ign.'.'.$id} = 1;
4395: }
1.945 raeburn 4396: }
1.1199 raeburn 4397: if ($identifier ne '') {
4398: my $id = join(',',@parts);
4399: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4400: $domain,$username,$usec,undef,$course) =~ /^no/) {
4401: $hidestatus{$ign.'.'.$id} = 1;
4402: }
4403: }
4404: } elsif ($data eq 'regrader') {
4405: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4406: my $id = join(',',@parts);
4407: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4408: }
1.1010 www 4409: }
1.31 albertel 4410: } else {
1.41 ng 4411: if ($#parts == 0) {
4412: $prevattempts.='<th>'.$parts[0].'</th>';
4413: } else {
4414: $prevattempts.='<th>'.$ign.'</th>';
4415: }
1.31 albertel 4416: }
1.16 harris41 4417: }
1.596 albertel 4418: $prevattempts.=&end_data_table_header_row();
1.40 ng 4419: if ($getattempt eq '') {
1.1199 raeburn 4420: my (%solved,%resets,%probstatus);
1.1200 raeburn 4421: if (($identifier ne '') && (keys(%regraded) > 0)) {
4422: for ($version=1;$version<=$returnhash{'version'};$version++) {
4423: foreach my $id (keys(%regraded)) {
4424: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4425: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4426: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4427: push(@{$resets{$id}},$version);
1.1199 raeburn 4428: }
4429: }
4430: }
1.1200 raeburn 4431: }
4432: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4433: my (@hidden,@unsolved);
1.945 raeburn 4434: if (%typeparts) {
4435: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4436: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4437: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4438: push(@hidden,$id);
1.1199 raeburn 4439: } elsif ($identifier ne '') {
4440: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4441: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4442: ($hidestatus{$id})) {
1.1200 raeburn 4443: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4444: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4445: push(@{$solved{$id}},$version);
4446: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4447: (ref($solved{$id}) eq 'ARRAY')) {
4448: my $skip;
4449: if (ref($resets{$id}) eq 'ARRAY') {
4450: foreach my $reset (@{$resets{$id}}) {
4451: if ($reset > $solved{$id}[-1]) {
4452: $skip=1;
4453: last;
4454: }
4455: }
4456: }
4457: unless ($skip) {
4458: my ($ign,$partslist) = split(/\./,$id,2);
4459: push(@unsolved,$partslist);
4460: }
4461: }
4462: }
1.945 raeburn 4463: }
4464: }
4465: }
4466: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4467: '<td>'.&mt('Transaction [_1]',$version);
4468: if (@unsolved) {
4469: $prevattempts .= '<span class="LC_nobreak"><label>'.
4470: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4471: &mt('Hide').'</label></span>';
4472: }
4473: $prevattempts .= '</td>';
1.945 raeburn 4474: if (@hidden) {
4475: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4476: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4477: my $hide;
4478: foreach my $id (@hidden) {
4479: if ($key =~ /^\Q$id\E/) {
4480: $hide = 1;
4481: last;
4482: }
4483: }
4484: if ($hide) {
4485: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4486: if (($data eq 'award') || ($data eq 'awarddetail')) {
4487: my $value = &format_previous_attempt_value($key,
4488: $returnhash{$version.':'.$key});
1.1173 kruse 4489: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4490: } else {
4491: $prevattempts.='<td> </td>';
4492: }
4493: } else {
4494: if ($key =~ /\./) {
1.1212 raeburn 4495: my $value = $returnhash{$version.':'.$key};
4496: if ($key =~ /\.rndseed$/) {
4497: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4498: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4499: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4500: }
4501: }
4502: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4503: ' </td>';
1.945 raeburn 4504: } else {
4505: $prevattempts.='<td> </td>';
4506: }
4507: }
4508: }
4509: } else {
4510: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4511: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4512: my $value = $returnhash{$version.':'.$key};
4513: if ($key =~ /\.rndseed$/) {
4514: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4515: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4516: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4517: }
4518: }
4519: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4520: ' </td>';
1.945 raeburn 4521: }
4522: }
4523: $prevattempts.=&end_data_table_row();
1.40 ng 4524: }
1.1 albertel 4525: }
1.945 raeburn 4526: my @currhidden = keys(%lasthidden);
1.596 albertel 4527: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4528: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4529: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4530: if (%typeparts) {
4531: my $hidden;
4532: foreach my $id (@currhidden) {
4533: if ($key =~ /^\Q$id\E/) {
4534: $hidden = 1;
4535: last;
4536: }
4537: }
4538: if ($hidden) {
4539: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4540: if (($data eq 'award') || ($data eq 'awarddetail')) {
4541: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4542: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4543: $value = &$gradesub($value);
4544: }
1.1173 kruse 4545: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4546: } else {
4547: $prevattempts.='<td> </td>';
4548: }
4549: } else {
4550: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4551: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4552: $value = &$gradesub($value);
4553: }
1.1173 kruse 4554: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4555: }
4556: } else {
4557: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4558: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4559: $value = &$gradesub($value);
4560: }
1.1173 kruse 4561: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4562: }
1.16 harris41 4563: }
1.596 albertel 4564: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4565: } else {
1.596 albertel 4566: $prevattempts=
4567: &start_data_table().&start_data_table_row().
4568: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4569: &end_data_table_row().&end_data_table();
1.1 albertel 4570: }
4571: } else {
1.596 albertel 4572: $prevattempts=
4573: &start_data_table().&start_data_table_row().
4574: '<td>'.&mt('No data.').'</td>'.
4575: &end_data_table_row().&end_data_table();
1.1 albertel 4576: }
1.10 albertel 4577: }
4578:
1.581 albertel 4579: sub format_previous_attempt_value {
4580: my ($key,$value) = @_;
1.1011 www 4581: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4582: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4583: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4584: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4585: } elsif ($key =~ /answerstring$/) {
4586: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4587: my @answer = %answers;
4588: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4589: my @anskeys = sort(keys(%answers));
4590: if (@anskeys == 1) {
4591: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4592: if ($answer =~ m{\0}) {
4593: $answer =~ s{\0}{,}g;
1.988 raeburn 4594: }
4595: my $tag_internal_answer_name = 'INTERNAL';
4596: if ($anskeys[0] eq $tag_internal_answer_name) {
4597: $value = $answer;
4598: } else {
4599: $value = $anskeys[0].'='.$answer;
4600: }
4601: } else {
4602: foreach my $ans (@anskeys) {
4603: my $answer = $answers{$ans};
1.1001 raeburn 4604: if ($answer =~ m{\0}) {
4605: $answer =~ s{\0}{,}g;
1.988 raeburn 4606: }
4607: $value .= $ans.'='.$answer.'<br />';;
4608: }
4609: }
1.581 albertel 4610: } else {
1.1173 kruse 4611: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4612: }
4613: return $value;
4614: }
4615:
4616:
1.107 albertel 4617: sub relative_to_absolute {
4618: my ($url,$output)=@_;
4619: my $parser=HTML::TokeParser->new(\$output);
4620: my $token;
4621: my $thisdir=$url;
4622: my @rlinks=();
4623: while ($token=$parser->get_token) {
4624: if ($token->[0] eq 'S') {
4625: if ($token->[1] eq 'a') {
4626: if ($token->[2]->{'href'}) {
4627: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4628: }
4629: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4630: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4631: } elsif ($token->[1] eq 'base') {
4632: $thisdir=$token->[2]->{'href'};
4633: }
4634: }
4635: }
4636: $thisdir=~s-/[^/]*$--;
1.356 albertel 4637: foreach my $link (@rlinks) {
1.726 raeburn 4638: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4639: ($link=~/^\//) ||
4640: ($link=~/^javascript:/i) ||
4641: ($link=~/^mailto:/i) ||
4642: ($link=~/^\#/)) {
4643: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4644: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4645: }
4646: }
4647: # -------------------------------------------------- Deal with Applet codebases
4648: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4649: return $output;
4650: }
4651:
1.112 bowersj2 4652: =pod
4653:
1.648 raeburn 4654: =item * &get_student_view()
1.112 bowersj2 4655:
4656: show a snapshot of what student was looking at
4657:
4658: =cut
4659:
1.10 albertel 4660: sub get_student_view {
1.186 albertel 4661: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4662: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4663: my (%form);
1.10 albertel 4664: my @elements=('symb','courseid','domain','username');
4665: foreach my $element (@elements) {
1.186 albertel 4666: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4667: }
1.186 albertel 4668: if (defined($moreenv)) {
4669: %form=(%form,%{$moreenv});
4670: }
1.236 albertel 4671: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4672: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4673: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4674: $userview=~s/\<body[^\>]*\>//gi;
4675: $userview=~s/\<\/body\>//gi;
4676: $userview=~s/\<html\>//gi;
4677: $userview=~s/\<\/html\>//gi;
4678: $userview=~s/\<head\>//gi;
4679: $userview=~s/\<\/head\>//gi;
4680: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4681: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4682: if (wantarray) {
4683: return ($userview,$response);
4684: } else {
4685: return $userview;
4686: }
4687: }
4688:
4689: sub get_student_view_with_retries {
4690: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4691:
4692: my $ok = 0; # True if we got a good response.
4693: my $content;
4694: my $response;
4695:
4696: # Try to get the student_view done. within the retries count:
4697:
4698: do {
4699: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4700: $ok = $response->is_success;
4701: if (!$ok) {
4702: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4703: }
4704: $retries--;
4705: } while (!$ok && ($retries > 0));
4706:
4707: if (!$ok) {
4708: $content = ''; # On error return an empty content.
4709: }
1.651 www 4710: if (wantarray) {
4711: return ($content, $response);
4712: } else {
4713: return $content;
4714: }
1.11 albertel 4715: }
4716:
1.112 bowersj2 4717: =pod
4718:
1.648 raeburn 4719: =item * &get_student_answers()
1.112 bowersj2 4720:
4721: show a snapshot of how student was answering problem
4722:
4723: =cut
4724:
1.11 albertel 4725: sub get_student_answers {
1.100 sakharuk 4726: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4727: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4728: my (%moreenv);
1.11 albertel 4729: my @elements=('symb','courseid','domain','username');
4730: foreach my $element (@elements) {
1.186 albertel 4731: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4732: }
1.186 albertel 4733: $moreenv{'grade_target'}='answer';
4734: %moreenv=(%form,%moreenv);
1.497 raeburn 4735: $feedurl = &Apache::lonnet::clutter($feedurl);
4736: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4737: return $userview;
1.1 albertel 4738: }
1.116 albertel 4739:
4740: =pod
4741:
4742: =item * &submlink()
4743:
1.242 albertel 4744: Inputs: $text $uname $udom $symb $target
1.116 albertel 4745:
4746: Returns: A link to grades.pm such as to see the SUBM view of a student
4747:
4748: =cut
4749:
4750: ###############################################
4751: sub submlink {
1.242 albertel 4752: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4753: if (!($uname && $udom)) {
4754: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4755: &Apache::lonnet::whichuser($symb);
1.116 albertel 4756: if (!$symb) { $symb=$cursymb; }
4757: }
1.254 matthew 4758: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4759: $symb=&escape($symb);
1.960 bisitz 4760: if ($target) { $target=" target=\"$target\""; }
4761: return
4762: '<a href="/adm/grades?command=submission'.
4763: '&symb='.$symb.
4764: '&student='.$uname.
4765: '&userdom='.$udom.'"'.
4766: $target.'>'.$text.'</a>';
1.242 albertel 4767: }
4768: ##############################################
4769:
4770: =pod
4771:
4772: =item * &pgrdlink()
4773:
4774: Inputs: $text $uname $udom $symb $target
4775:
4776: Returns: A link to grades.pm such as to see the PGRD view of a student
4777:
4778: =cut
4779:
4780: ###############################################
4781: sub pgrdlink {
4782: my $link=&submlink(@_);
4783: $link=~s/(&command=submission)/$1&showgrading=yes/;
4784: return $link;
4785: }
4786: ##############################################
4787:
4788: =pod
4789:
4790: =item * &pprmlink()
4791:
4792: Inputs: $text $uname $udom $symb $target
4793:
4794: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4795: student and a specific resource
1.242 albertel 4796:
4797: =cut
4798:
4799: ###############################################
4800: sub pprmlink {
4801: my ($text,$uname,$udom,$symb,$target)=@_;
4802: if (!($uname && $udom)) {
4803: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4804: &Apache::lonnet::whichuser($symb);
1.242 albertel 4805: if (!$symb) { $symb=$cursymb; }
4806: }
1.254 matthew 4807: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4808: $symb=&escape($symb);
1.242 albertel 4809: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4810: return '<a href="/adm/parmset?command=set&'.
4811: 'symb='.$symb.'&uname='.$uname.
4812: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4813: }
4814: ##############################################
1.37 matthew 4815:
1.112 bowersj2 4816: =pod
4817:
4818: =back
4819:
4820: =cut
4821:
1.37 matthew 4822: ###############################################
1.51 www 4823:
4824:
4825: sub timehash {
1.687 raeburn 4826: my ($thistime) = @_;
4827: my $timezone = &Apache::lonlocal::gettimezone();
4828: my $dt = DateTime->from_epoch(epoch => $thistime)
4829: ->set_time_zone($timezone);
4830: my $wday = $dt->day_of_week();
4831: if ($wday == 7) { $wday = 0; }
4832: return ( 'second' => $dt->second(),
4833: 'minute' => $dt->minute(),
4834: 'hour' => $dt->hour(),
4835: 'day' => $dt->day_of_month(),
4836: 'month' => $dt->month(),
4837: 'year' => $dt->year(),
4838: 'weekday' => $wday,
4839: 'dayyear' => $dt->day_of_year(),
4840: 'dlsav' => $dt->is_dst() );
1.51 www 4841: }
4842:
1.370 www 4843: sub utc_string {
4844: my ($date)=@_;
1.371 www 4845: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4846: }
4847:
1.51 www 4848: sub maketime {
4849: my %th=@_;
1.687 raeburn 4850: my ($epoch_time,$timezone,$dt);
4851: $timezone = &Apache::lonlocal::gettimezone();
4852: eval {
4853: $dt = DateTime->new( year => $th{'year'},
4854: month => $th{'month'},
4855: day => $th{'day'},
4856: hour => $th{'hour'},
4857: minute => $th{'minute'},
4858: second => $th{'second'},
4859: time_zone => $timezone,
4860: );
4861: };
4862: if (!$@) {
4863: $epoch_time = $dt->epoch;
4864: if ($epoch_time) {
4865: return $epoch_time;
4866: }
4867: }
1.51 www 4868: return POSIX::mktime(
4869: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4870: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4871: }
4872:
4873: #########################################
1.51 www 4874:
4875: sub findallcourses {
1.482 raeburn 4876: my ($roles,$uname,$udom) = @_;
1.355 albertel 4877: my %roles;
4878: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4879: my %courses;
1.51 www 4880: my $now=time;
1.482 raeburn 4881: if (!defined($uname)) {
4882: $uname = $env{'user.name'};
4883: }
4884: if (!defined($udom)) {
4885: $udom = $env{'user.domain'};
4886: }
4887: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4888: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4889: if (!%roles) {
4890: %roles = (
4891: cc => 1,
1.907 raeburn 4892: co => 1,
1.482 raeburn 4893: in => 1,
4894: ep => 1,
4895: ta => 1,
4896: cr => 1,
4897: st => 1,
4898: );
4899: }
4900: foreach my $entry (keys(%roleshash)) {
4901: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4902: if ($trole =~ /^cr/) {
4903: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4904: } else {
4905: next if (!exists($roles{$trole}));
4906: }
4907: if ($tend) {
4908: next if ($tend < $now);
4909: }
4910: if ($tstart) {
4911: next if ($tstart > $now);
4912: }
1.1058 raeburn 4913: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4914: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4915: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4916: if ($secpart eq '') {
4917: ($cnum,$role) = split(/_/,$cnumpart);
4918: $sec = 'none';
1.1058 raeburn 4919: $value .= $cnum.'/';
1.482 raeburn 4920: } else {
4921: $cnum = $cnumpart;
4922: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4923: $value .= $cnum.'/'.$sec;
4924: }
4925: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4926: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4927: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4928: }
4929: } else {
4930: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4931: }
1.482 raeburn 4932: }
4933: } else {
4934: foreach my $key (keys(%env)) {
1.483 albertel 4935: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4936: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4937: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4938: next if ($role eq 'ca' || $role eq 'aa');
4939: next if (%roles && !exists($roles{$role}));
4940: my ($starttime,$endtime)=split(/\./,$env{$key});
4941: my $active=1;
4942: if ($starttime) {
4943: if ($now<$starttime) { $active=0; }
4944: }
4945: if ($endtime) {
4946: if ($now>$endtime) { $active=0; }
4947: }
4948: if ($active) {
1.1058 raeburn 4949: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4950: if ($sec eq '') {
4951: $sec = 'none';
1.1058 raeburn 4952: } else {
4953: $value .= $sec;
4954: }
4955: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4956: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4957: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4958: }
4959: } else {
4960: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4961: }
1.474 raeburn 4962: }
4963: }
1.51 www 4964: }
4965: }
1.474 raeburn 4966: return %courses;
1.51 www 4967: }
1.37 matthew 4968:
1.54 www 4969: ###############################################
1.474 raeburn 4970:
4971: sub blockcheck {
1.1189 raeburn 4972: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4973:
1.1189 raeburn 4974: if (defined($udom) && defined($uname)) {
4975: # If uname and udom are for a course, check for blocks in the course.
4976: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4977: my ($startblock,$endblock,$triggerblock) =
4978: &get_blocks($setters,$activity,$udom,$uname,$url);
4979: return ($startblock,$endblock,$triggerblock);
4980: }
4981: } else {
1.490 raeburn 4982: $udom = $env{'user.domain'};
4983: $uname = $env{'user.name'};
4984: }
4985:
1.502 raeburn 4986: my $startblock = 0;
4987: my $endblock = 0;
1.1062 raeburn 4988: my $triggerblock = '';
1.482 raeburn 4989: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4990:
1.490 raeburn 4991: # If uname is for a user, and activity is course-specific, i.e.,
4992: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4993:
1.490 raeburn 4994: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 4995: $activity eq 'groups' || $activity eq 'printout' ||
4996: $activity eq 'reinit' || $activity eq 'alert') &&
1.1189 raeburn 4997: ($env{'request.course.id'})) {
1.490 raeburn 4998: foreach my $key (keys(%live_courses)) {
4999: if ($key ne $env{'request.course.id'}) {
5000: delete($live_courses{$key});
5001: }
5002: }
5003: }
5004:
5005: my $otheruser = 0;
5006: my %own_courses;
5007: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5008: # Resource belongs to user other than current user.
5009: $otheruser = 1;
5010: # Gather courses for current user
5011: %own_courses =
5012: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5013: }
5014:
5015: # Gather active course roles - course coordinator, instructor,
5016: # exam proctor, ta, student, or custom role.
1.474 raeburn 5017:
5018: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5019: my ($cdom,$cnum);
5020: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5021: $cdom = $env{'course.'.$course.'.domain'};
5022: $cnum = $env{'course.'.$course.'.num'};
5023: } else {
1.490 raeburn 5024: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5025: }
5026: my $no_ownblock = 0;
5027: my $no_userblock = 0;
1.533 raeburn 5028: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5029: # Check if current user has 'evb' priv for this
5030: if (defined($own_courses{$course})) {
5031: foreach my $sec (keys(%{$own_courses{$course}})) {
5032: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5033: if ($sec ne 'none') {
5034: $checkrole .= '/'.$sec;
5035: }
5036: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5037: $no_ownblock = 1;
5038: last;
5039: }
5040: }
5041: }
5042: # if they have 'evb' priv and are currently not playing student
5043: next if (($no_ownblock) &&
5044: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5045: }
1.474 raeburn 5046: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5047: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5048: if ($sec ne 'none') {
1.482 raeburn 5049: $checkrole .= '/'.$sec;
1.474 raeburn 5050: }
1.490 raeburn 5051: if ($otheruser) {
5052: # Resource belongs to user other than current user.
5053: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5054: my (%allroles,%userroles);
5055: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5056: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5057: my ($trole,$tdom,$tnum,$tsec);
5058: if ($entry =~ /^cr/) {
5059: ($trole,$tdom,$tnum,$tsec) =
5060: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5061: } else {
5062: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5063: }
5064: my ($spec,$area,$trest);
5065: $area = '/'.$tdom.'/'.$tnum;
5066: $trest = $tnum;
5067: if ($tsec ne '') {
5068: $area .= '/'.$tsec;
5069: $trest .= '/'.$tsec;
5070: }
5071: $spec = $trole.'.'.$area;
5072: if ($trole =~ /^cr/) {
5073: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5074: $tdom,$spec,$trest,$area);
5075: } else {
5076: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5077: $tdom,$spec,$trest,$area);
5078: }
5079: }
1.1276 raeburn 5080: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5081: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5082: if ($1) {
5083: $no_userblock = 1;
5084: last;
5085: }
1.486 raeburn 5086: }
5087: }
1.490 raeburn 5088: } else {
5089: # Resource belongs to current user
5090: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5091: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5092: $no_ownblock = 1;
5093: last;
5094: }
1.474 raeburn 5095: }
5096: }
5097: # if they have the evb priv and are currently not playing student
1.482 raeburn 5098: next if (($no_ownblock) &&
1.491 albertel 5099: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5100: next if ($no_userblock);
1.474 raeburn 5101:
1.866 kalberla 5102: # Retrieve blocking times and identity of locker for course
1.490 raeburn 5103: # of specified user, unless user has 'evb' privilege.
1.1284 ! raeburn 5104:
1.1062 raeburn 5105: my ($start,$end,$trigger) =
5106: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 5107: if (($start != 0) &&
5108: (($startblock == 0) || ($startblock > $start))) {
5109: $startblock = $start;
1.1062 raeburn 5110: if ($trigger ne '') {
5111: $triggerblock = $trigger;
5112: }
1.502 raeburn 5113: }
5114: if (($end != 0) &&
5115: (($endblock == 0) || ($endblock < $end))) {
5116: $endblock = $end;
1.1062 raeburn 5117: if ($trigger ne '') {
5118: $triggerblock = $trigger;
5119: }
1.502 raeburn 5120: }
1.490 raeburn 5121: }
1.1062 raeburn 5122: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5123: }
5124:
5125: sub get_blocks {
1.1062 raeburn 5126: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 5127: my $startblock = 0;
5128: my $endblock = 0;
1.1062 raeburn 5129: my $triggerblock = '';
1.490 raeburn 5130: my $course = $cdom.'_'.$cnum;
5131: $setters->{$course} = {};
5132: $setters->{$course}{'staff'} = [];
5133: $setters->{$course}{'times'} = [];
1.1062 raeburn 5134: $setters->{$course}{'triggers'} = [];
5135: my (@blockers,%triggered);
5136: my $now = time;
5137: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5138: if ($activity eq 'docs') {
5139: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
5140: foreach my $block (@blockers) {
5141: if ($block =~ /^firstaccess____(.+)$/) {
5142: my $item = $1;
5143: my $type = 'map';
5144: my $timersymb = $item;
5145: if ($item eq 'course') {
5146: $type = 'course';
5147: } elsif ($item =~ /___\d+___/) {
5148: $type = 'resource';
5149: } else {
5150: $timersymb = &Apache::lonnet::symbread($item);
5151: }
5152: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5153: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5154: $triggered{$block} = {
5155: start => $start,
5156: end => $end,
5157: type => $type,
5158: };
5159: }
5160: }
5161: } else {
5162: foreach my $block (keys(%commblocks)) {
5163: if ($block =~ m/^(\d+)____(\d+)$/) {
5164: my ($start,$end) = ($1,$2);
5165: if ($start <= time && $end >= time) {
5166: if (ref($commblocks{$block}) eq 'HASH') {
5167: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5168: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5169: unless(grep(/^\Q$block\E$/,@blockers)) {
5170: push(@blockers,$block);
5171: }
5172: }
5173: }
5174: }
5175: }
5176: } elsif ($block =~ /^firstaccess____(.+)$/) {
5177: my $item = $1;
5178: my $timersymb = $item;
5179: my $type = 'map';
5180: if ($item eq 'course') {
5181: $type = 'course';
5182: } elsif ($item =~ /___\d+___/) {
5183: $type = 'resource';
5184: } else {
5185: $timersymb = &Apache::lonnet::symbread($item);
5186: }
5187: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5188: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5189: if ($start && $end) {
5190: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5191: if (ref($commblocks{$block}) eq 'HASH') {
5192: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5193: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5194: unless(grep(/^\Q$block\E$/,@blockers)) {
5195: push(@blockers,$block);
5196: $triggered{$block} = {
5197: start => $start,
5198: end => $end,
5199: type => $type,
5200: };
5201: }
5202: }
5203: }
1.1062 raeburn 5204: }
5205: }
1.490 raeburn 5206: }
1.1062 raeburn 5207: }
5208: }
5209: }
5210: foreach my $blocker (@blockers) {
5211: my ($staff_name,$staff_dom,$title,$blocks) =
5212: &parse_block_record($commblocks{$blocker});
5213: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5214: my ($start,$end,$triggertype);
5215: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5216: ($start,$end) = ($1,$2);
5217: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5218: $start = $triggered{$blocker}{'start'};
5219: $end = $triggered{$blocker}{'end'};
5220: $triggertype = $triggered{$blocker}{'type'};
5221: }
5222: if ($start) {
5223: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5224: if ($triggertype) {
5225: push(@{$$setters{$course}{'triggers'}},$triggertype);
5226: } else {
5227: push(@{$$setters{$course}{'triggers'}},0);
5228: }
5229: if ( ($startblock == 0) || ($startblock > $start) ) {
5230: $startblock = $start;
5231: if ($triggertype) {
5232: $triggerblock = $blocker;
1.474 raeburn 5233: }
5234: }
1.1062 raeburn 5235: if ( ($endblock == 0) || ($endblock < $end) ) {
5236: $endblock = $end;
5237: if ($triggertype) {
5238: $triggerblock = $blocker;
5239: }
5240: }
1.474 raeburn 5241: }
5242: }
1.1062 raeburn 5243: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5244: }
5245:
5246: sub parse_block_record {
5247: my ($record) = @_;
5248: my ($setuname,$setudom,$title,$blocks);
5249: if (ref($record) eq 'HASH') {
5250: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5251: $title = &unescape($record->{'event'});
5252: $blocks = $record->{'blocks'};
5253: } else {
5254: my @data = split(/:/,$record,3);
5255: if (scalar(@data) eq 2) {
5256: $title = $data[1];
5257: ($setuname,$setudom) = split(/@/,$data[0]);
5258: } else {
5259: ($setuname,$setudom,$title) = @data;
5260: }
5261: $blocks = { 'com' => 'on' };
5262: }
5263: return ($setuname,$setudom,$title,$blocks);
5264: }
5265:
1.854 kalberla 5266: sub blocking_status {
1.1189 raeburn 5267: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 5268: my %setters;
1.890 droeschl 5269:
1.1061 raeburn 5270: # check for active blocking
1.1062 raeburn 5271: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 5272: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 5273: my $blocked = 0;
5274: if ($startblock && $endblock) {
5275: $blocked = 1;
5276: }
1.890 droeschl 5277:
1.1061 raeburn 5278: # caller just wants to know whether a block is active
5279: if (!wantarray) { return $blocked; }
5280:
5281: # build a link to a popup window containing the details
5282: my $querystring = "?activity=$activity";
5283: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 raeburn 5284: if (($activity eq 'port') || ($activity eq 'passwd')) {
5285: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5286: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5287: } elsif ($activity eq 'docs') {
5288: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
5289: }
1.1061 raeburn 5290:
5291: my $output .= <<'END_MYBLOCK';
5292: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5293: var options = "width=" + w + ",height=" + h + ",";
5294: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5295: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5296: var newWin = window.open(url, wdwName, options);
5297: newWin.focus();
5298: }
1.890 droeschl 5299: END_MYBLOCK
1.854 kalberla 5300:
1.1061 raeburn 5301: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5302:
1.1061 raeburn 5303: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5304: my $text = &mt('Communication Blocked');
1.1217 raeburn 5305: my $class = 'LC_comblock';
1.1062 raeburn 5306: if ($activity eq 'docs') {
5307: $text = &mt('Content Access Blocked');
1.1217 raeburn 5308: $class = '';
1.1063 raeburn 5309: } elsif ($activity eq 'printout') {
5310: $text = &mt('Printing Blocked');
1.1232 raeburn 5311: } elsif ($activity eq 'passwd') {
5312: $text = &mt('Password Changing Blocked');
1.1282 raeburn 5313: } elsif ($activity eq 'alert') {
5314: $text = &mt('Checking Critical Messages Blocked');
5315: } elsif ($activity eq 'reinit') {
5316: $text = &mt('Checking Course Update Blocked');
1.1062 raeburn 5317: }
1.1061 raeburn 5318: $output .= <<"END_BLOCK";
1.1217 raeburn 5319: <div class='$class'>
1.869 kalberla 5320: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5321: title='$text'>
5322: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5323: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5324: title='$text'>$text</a>
1.867 kalberla 5325: </div>
5326:
5327: END_BLOCK
1.474 raeburn 5328:
1.1061 raeburn 5329: return ($blocked, $output);
1.854 kalberla 5330: }
1.490 raeburn 5331:
1.60 matthew 5332: ###############################################
5333:
1.682 raeburn 5334: sub check_ip_acc {
1.1201 raeburn 5335: my ($acc,$clientip)=@_;
1.682 raeburn 5336: &Apache::lonxml::debug("acc is $acc");
5337: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5338: return 1;
5339: }
1.1219 raeburn 5340: my $allowed;
1.1252 raeburn 5341: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 5342:
5343: my $name;
1.1219 raeburn 5344: my %access = (
5345: allowfrom => 1,
5346: denyfrom => 0,
5347: );
5348: my @allows;
5349: my @denies;
5350: foreach my $item (split(',',$acc)) {
5351: $item =~ s/^\s*//;
5352: $item =~ s/\s*$//;
5353: my $pattern;
5354: if ($item =~ /^\!(.+)$/) {
5355: push(@denies,$1);
5356: } else {
5357: push(@allows,$item);
5358: }
5359: }
5360: my $numdenies = scalar(@denies);
5361: my $numallows = scalar(@allows);
5362: my $count = 0;
5363: foreach my $pattern (@denies,@allows) {
5364: $count ++;
5365: my $acctype = 'allowfrom';
5366: if ($count <= $numdenies) {
5367: $acctype = 'denyfrom';
5368: }
1.682 raeburn 5369: if ($pattern =~ /\*$/) {
5370: #35.8.*
5371: $pattern=~s/\*//;
1.1219 raeburn 5372: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5373: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5374: #35.8.3.[34-56]
5375: my $low=$2;
5376: my $high=$3;
5377: $pattern=$1;
5378: if ($ip =~ /^\Q$pattern\E/) {
5379: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5380: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5381: }
5382: } elsif ($pattern =~ /^\*/) {
5383: #*.msu.edu
5384: $pattern=~s/\*//;
5385: if (!defined($name)) {
5386: use Socket;
5387: my $netaddr=inet_aton($ip);
5388: ($name)=gethostbyaddr($netaddr,AF_INET);
5389: }
1.1219 raeburn 5390: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5391: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5392: #127.0.0.1
1.1219 raeburn 5393: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5394: } else {
5395: #some.name.com
5396: if (!defined($name)) {
5397: use Socket;
5398: my $netaddr=inet_aton($ip);
5399: ($name)=gethostbyaddr($netaddr,AF_INET);
5400: }
1.1219 raeburn 5401: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5402: }
5403: if ($allowed =~ /^(0|1)$/) { last; }
5404: }
5405: if ($allowed eq '') {
5406: if ($numdenies && !$numallows) {
5407: $allowed = 1;
5408: } else {
5409: $allowed = 0;
1.682 raeburn 5410: }
5411: }
5412: return $allowed;
5413: }
5414:
5415: ###############################################
5416:
1.60 matthew 5417: =pod
5418:
1.112 bowersj2 5419: =head1 Domain Template Functions
5420:
5421: =over 4
5422:
5423: =item * &determinedomain()
1.60 matthew 5424:
5425: Inputs: $domain (usually will be undef)
5426:
1.63 www 5427: Returns: Determines which domain should be used for designs
1.60 matthew 5428:
5429: =cut
1.54 www 5430:
1.60 matthew 5431: ###############################################
1.63 www 5432: sub determinedomain {
5433: my $domain=shift;
1.531 albertel 5434: if (! $domain) {
1.60 matthew 5435: # Determine domain if we have not been given one
1.893 raeburn 5436: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5437: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5438: if ($env{'request.role.domain'}) {
5439: $domain=$env{'request.role.domain'};
1.60 matthew 5440: }
5441: }
1.63 www 5442: return $domain;
5443: }
5444: ###############################################
1.517 raeburn 5445:
1.518 albertel 5446: sub devalidate_domconfig_cache {
5447: my ($udom)=@_;
5448: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5449: }
5450:
5451: # ---------------------- Get domain configuration for a domain
5452: sub get_domainconf {
5453: my ($udom) = @_;
5454: my $cachetime=1800;
5455: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5456: if (defined($cached)) { return %{$result}; }
5457:
5458: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5459: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5460: my (%designhash,%legacy);
1.518 albertel 5461: if (keys(%domconfig) > 0) {
5462: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5463: if (keys(%{$domconfig{'login'}})) {
5464: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5465: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5466: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5467: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5468: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5469: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5470: if ($key eq 'loginvia') {
5471: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5472: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5473: $designhash{$udom.'.login.loginvia'} = $server;
5474: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5475:
5476: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5477: } else {
5478: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5479: }
1.948 raeburn 5480: }
1.1208 raeburn 5481: } elsif ($key eq 'headtag') {
5482: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5483: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5484: }
1.946 raeburn 5485: }
1.1208 raeburn 5486: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5487: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5488: }
1.946 raeburn 5489: }
5490: }
5491: }
5492: } else {
5493: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5494: $designhash{$udom.'.login.'.$key.'_'.$img} =
5495: $domconfig{'login'}{$key}{$img};
5496: }
1.699 raeburn 5497: }
5498: } else {
5499: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5500: }
1.632 raeburn 5501: }
5502: } else {
5503: $legacy{'login'} = 1;
1.518 albertel 5504: }
1.632 raeburn 5505: } else {
5506: $legacy{'login'} = 1;
1.518 albertel 5507: }
5508: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5509: if (keys(%{$domconfig{'rolecolors'}})) {
5510: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5511: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5512: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5513: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5514: }
1.518 albertel 5515: }
5516: }
1.632 raeburn 5517: } else {
5518: $legacy{'rolecolors'} = 1;
1.518 albertel 5519: }
1.632 raeburn 5520: } else {
5521: $legacy{'rolecolors'} = 1;
1.518 albertel 5522: }
1.948 raeburn 5523: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5524: if ($domconfig{'autoenroll'}{'co-owners'}) {
5525: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5526: }
5527: }
1.632 raeburn 5528: if (keys(%legacy) > 0) {
5529: my %legacyhash = &get_legacy_domconf($udom);
5530: foreach my $item (keys(%legacyhash)) {
5531: if ($item =~ /^\Q$udom\E\.login/) {
5532: if ($legacy{'login'}) {
5533: $designhash{$item} = $legacyhash{$item};
5534: }
5535: } else {
5536: if ($legacy{'rolecolors'}) {
5537: $designhash{$item} = $legacyhash{$item};
5538: }
1.518 albertel 5539: }
5540: }
5541: }
1.632 raeburn 5542: } else {
5543: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5544: }
5545: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5546: $cachetime);
5547: return %designhash;
5548: }
5549:
1.632 raeburn 5550: sub get_legacy_domconf {
5551: my ($udom) = @_;
5552: my %legacyhash;
5553: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5554: my $designfile = $designdir.'/'.$udom.'.tab';
5555: if (-e $designfile) {
5556: if ( open (my $fh,"<$designfile") ) {
5557: while (my $line = <$fh>) {
5558: next if ($line =~ /^\#/);
5559: chomp($line);
5560: my ($key,$val)=(split(/\=/,$line));
5561: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5562: }
5563: close($fh);
5564: }
5565: }
1.1026 raeburn 5566: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5567: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5568: }
5569: return %legacyhash;
5570: }
5571:
1.63 www 5572: =pod
5573:
1.112 bowersj2 5574: =item * &domainlogo()
1.63 www 5575:
5576: Inputs: $domain (usually will be undef)
5577:
5578: Returns: A link to a domain logo, if the domain logo exists.
5579: If the domain logo does not exist, a description of the domain.
5580:
5581: =cut
1.112 bowersj2 5582:
1.63 www 5583: ###############################################
5584: sub domainlogo {
1.517 raeburn 5585: my $domain = &determinedomain(shift);
1.518 albertel 5586: my %designhash = &get_domainconf($domain);
1.517 raeburn 5587: # See if there is a logo
5588: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5589: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5590: if ($imgsrc =~ m{^/(adm|res)/}) {
5591: if ($imgsrc =~ m{^/res/}) {
5592: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5593: &Apache::lonnet::repcopy($local_name);
5594: }
5595: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5596: }
5597: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5598: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5599: return &Apache::lonnet::domain($domain,'description');
1.59 www 5600: } else {
1.60 matthew 5601: return '';
1.59 www 5602: }
5603: }
1.63 www 5604: ##############################################
5605:
5606: =pod
5607:
1.112 bowersj2 5608: =item * &designparm()
1.63 www 5609:
5610: Inputs: $which parameter; $domain (usually will be undef)
5611:
5612: Returns: value of designparamter $which
5613:
5614: =cut
1.112 bowersj2 5615:
1.397 albertel 5616:
1.400 albertel 5617: ##############################################
1.397 albertel 5618: sub designparm {
5619: my ($which,$domain)=@_;
5620: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5621: return $env{'environment.color.'.$which};
1.96 www 5622: }
1.63 www 5623: $domain=&determinedomain($domain);
1.1016 raeburn 5624: my %domdesign;
5625: unless ($domain eq 'public') {
5626: %domdesign = &get_domainconf($domain);
5627: }
1.520 raeburn 5628: my $output;
1.517 raeburn 5629: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5630: $output = $domdesign{$domain.'.'.$which};
1.63 www 5631: } else {
1.520 raeburn 5632: $output = $defaultdesign{$which};
5633: }
5634: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5635: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5636: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5637: if ($output =~ m{^/res/}) {
5638: my $local_name = &Apache::lonnet::filelocation('',$output);
5639: &Apache::lonnet::repcopy($local_name);
5640: }
1.520 raeburn 5641: $output = &lonhttpdurl($output);
5642: }
1.63 www 5643: }
1.520 raeburn 5644: return $output;
1.63 www 5645: }
1.59 www 5646:
1.822 bisitz 5647: ##############################################
5648: =pod
5649:
1.832 bisitz 5650: =item * &authorspace()
5651:
1.1028 raeburn 5652: Inputs: $url (usually will be undef).
1.832 bisitz 5653:
1.1132 raeburn 5654: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5655: directory being viewed (or for which action is being taken).
5656: If $url is provided, and begins /priv/<domain>/<uname>
5657: the path will be that portion of the $context argument.
5658: Otherwise the path will be for the author space of the current
5659: user when the current role is author, or for that of the
5660: co-author/assistant co-author space when the current role
5661: is co-author or assistant co-author.
1.832 bisitz 5662:
5663: =cut
5664:
5665: sub authorspace {
1.1028 raeburn 5666: my ($url) = @_;
5667: if ($url ne '') {
5668: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5669: return $1;
5670: }
5671: }
1.832 bisitz 5672: my $caname = '';
1.1024 www 5673: my $cadom = '';
1.1028 raeburn 5674: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5675: ($cadom,$caname) =
1.832 bisitz 5676: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5677: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5678: $caname = $env{'user.name'};
1.1024 www 5679: $cadom = $env{'user.domain'};
1.832 bisitz 5680: }
1.1028 raeburn 5681: if (($caname ne '') && ($cadom ne '')) {
5682: return "/priv/$cadom/$caname/";
5683: }
5684: return;
1.832 bisitz 5685: }
5686:
5687: ##############################################
5688: =pod
5689:
1.822 bisitz 5690: =item * &head_subbox()
5691:
5692: Inputs: $content (contains HTML code with page functions, etc.)
5693:
5694: Returns: HTML div with $content
5695: To be included in page header
5696:
5697: =cut
5698:
5699: sub head_subbox {
5700: my ($content)=@_;
5701: my $output =
1.993 raeburn 5702: '<div class="LC_head_subbox">'
1.822 bisitz 5703: .$content
5704: .'</div>'
5705: }
5706:
5707: ##############################################
5708: =pod
5709:
5710: =item * &CSTR_pageheader()
5711:
1.1026 raeburn 5712: Input: (optional) filename from which breadcrumb trail is built.
5713: In most cases no input as needed, as $env{'request.filename'}
5714: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5715:
5716: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5717: To be included on Authoring Space pages
1.822 bisitz 5718:
5719: =cut
5720:
5721: sub CSTR_pageheader {
1.1026 raeburn 5722: my ($trailfile) = @_;
5723: if ($trailfile eq '') {
5724: $trailfile = $env{'request.filename'};
5725: }
5726:
5727: # this is for resources; directories have customtitle, and crumbs
5728: # and select recent are created in lonpubdir.pm
5729:
5730: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5731: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5732: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5733: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5734: $formaction =~ s{/+}{/}g;
1.822 bisitz 5735:
5736: my $parentpath = '';
5737: my $lastitem = '';
5738: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5739: $parentpath = $1;
5740: $lastitem = $2;
5741: } else {
5742: $lastitem = $thisdisfn;
5743: }
1.921 bisitz 5744:
1.1246 raeburn 5745: my ($crsauthor,$title);
5746: if (($env{'request.course.id'}) &&
5747: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 5748: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 5749: $crsauthor = 1;
5750: $title = &mt('Course Authoring Space');
5751: } else {
5752: $title = &mt('Authoring Space');
5753: }
5754:
1.921 bisitz 5755: my $output =
1.822 bisitz 5756: '<div>'
5757: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 5758: .'<b>'.$title.'</b> '
1.822 bisitz 5759: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5760: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5761: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5762:
5763: if ($lastitem) {
5764: $output .=
5765: '<span class="LC_filename">'
5766: .$lastitem
5767: .'</span>';
5768: }
1.1245 raeburn 5769:
1.1246 raeburn 5770: if ($crsauthor) {
5771: $output .= '</form>'.&Apache::lonmenu::constspaceform();
5772: } else {
5773: $output .=
5774: '<br />'
5775: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5776: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5777: .'</form>'
5778: .&Apache::lonmenu::constspaceform();
5779: }
5780: $output .= '</div>';
1.921 bisitz 5781:
5782: return $output;
1.822 bisitz 5783: }
5784:
1.60 matthew 5785: ###############################################
5786: ###############################################
5787:
5788: =pod
5789:
1.112 bowersj2 5790: =back
5791:
1.549 albertel 5792: =head1 HTML Helpers
1.112 bowersj2 5793:
5794: =over 4
5795:
5796: =item * &bodytag()
1.60 matthew 5797:
5798: Returns a uniform header for LON-CAPA web pages.
5799:
5800: Inputs:
5801:
1.112 bowersj2 5802: =over 4
5803:
5804: =item * $title, A title to be displayed on the page.
5805:
5806: =item * $function, the current role (can be undef).
5807:
5808: =item * $addentries, extra parameters for the <body> tag.
5809:
5810: =item * $bodyonly, if defined, only return the <body> tag.
5811:
5812: =item * $domain, if defined, force a given domain.
5813:
5814: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5815: text interface only)
1.60 matthew 5816:
1.814 bisitz 5817: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5818: navigational links
1.317 albertel 5819:
1.338 albertel 5820: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5821:
1.460 albertel 5822: =item * $args, optional argument valid values are
5823: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 5824: use_absolute -> for external resource or syllabus, this will
5825: contain https://<hostname> if server uses
5826: https (as per hosts.tab), but request is for http
5827: hostname -> hostname, from $r->hostname().
1.460 albertel 5828:
1.1096 raeburn 5829: =item * $advtoolsref, optional argument, ref to an array containing
5830: inlineremote items to be added in "Functions" menu below
5831: breadcrumbs.
5832:
1.112 bowersj2 5833: =back
5834:
1.60 matthew 5835: Returns: A uniform header for LON-CAPA web pages.
5836: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5837: If $bodyonly is undef or zero, an html string containing a <body> tag and
5838: other decorations will be returned.
5839:
5840: =cut
5841:
1.54 www 5842: sub bodytag {
1.831 bisitz 5843: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5844: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5845:
1.954 raeburn 5846: my $public;
5847: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5848: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5849: $public = 1;
5850: }
1.460 albertel 5851: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5852: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 5853: my $hostname = $args->{'hostname'};
1.339 albertel 5854:
1.183 matthew 5855: $function = &get_users_function() if (!$function);
1.339 albertel 5856: my $img = &designparm($function.'.img',$domain);
5857: my $font = &designparm($function.'.font',$domain);
5858: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5859:
1.803 bisitz 5860: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5861: 'bgcolor' => $pgbg,
1.339 albertel 5862: 'text' => $font,
5863: 'alink' => &designparm($function.'.alink',$domain),
5864: 'vlink' => &designparm($function.'.vlink',$domain),
5865: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5866: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5867:
1.63 www 5868: # role and realm
1.1178 raeburn 5869: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5870: if ($realm) {
5871: $realm = '/'.$realm;
5872: }
1.378 raeburn 5873: if ($role eq 'ca') {
1.479 albertel 5874: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5875: $realm = &plainname($rname,$rdom);
1.378 raeburn 5876: }
1.55 www 5877: # realm
1.258 albertel 5878: if ($env{'request.course.id'}) {
1.378 raeburn 5879: if ($env{'request.role'} !~ /^cr/) {
5880: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 5881: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 5882: if ($env{'request.role.desc'}) {
5883: $role = $env{'request.role.desc'};
5884: } else {
5885: $role = &mt('Helpdesk[_1]',' '.$2);
5886: }
1.1257 raeburn 5887: } else {
5888: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5889: }
1.898 raeburn 5890: if ($env{'request.course.sec'}) {
5891: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5892: }
1.359 albertel 5893: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5894: } else {
5895: $role = &Apache::lonnet::plaintext($role);
1.54 www 5896: }
1.433 albertel 5897:
1.359 albertel 5898: if (!$realm) { $realm=' '; }
1.330 albertel 5899:
1.438 albertel 5900: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5901:
1.101 www 5902: # construct main body tag
1.359 albertel 5903: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 5904: &Apache::lontexconvert::init_math_support();
1.252 albertel 5905:
1.1131 raeburn 5906: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5907:
1.1130 raeburn 5908: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5909: return $bodytag;
1.1130 raeburn 5910: }
1.359 albertel 5911:
1.954 raeburn 5912: if ($public) {
1.433 albertel 5913: undef($role);
5914: }
1.359 albertel 5915:
1.762 bisitz 5916: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5917: #
5918: # Extra info if you are the DC
5919: my $dc_info = '';
5920: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5921: $env{'course.'.$env{'request.course.id'}.
5922: '.domain'}.'/'})) {
5923: my $cid = $env{'request.course.id'};
1.917 raeburn 5924: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5925: $dc_info =~ s/\s+$//;
1.359 albertel 5926: }
5927:
1.1237 raeburn 5928: my $crstype;
5929: if ($env{'request.course.id'}) {
5930: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
5931: } elsif ($args->{'crstype'}) {
5932: $crstype = $args->{'crstype'};
5933: }
5934: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
5935: undef($role);
5936: } else {
1.1242 raeburn 5937: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 5938: }
1.853 droeschl 5939:
1.903 droeschl 5940: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5941:
5942: # if ($env{'request.state'} eq 'construct') {
5943: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5944: # }
5945:
1.1130 raeburn 5946: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 5947: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5948:
1.1237 raeburn 5949: my ($left,$right) = Apache::lonmenu::primary_menu($crstype);
1.359 albertel 5950:
1.916 droeschl 5951: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5952: if ($dc_info) {
5953: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5954: }
1.1130 raeburn 5955: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5956: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5957: return $bodytag;
5958: }
1.894 droeschl 5959:
1.927 raeburn 5960: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5961: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5962: }
1.916 droeschl 5963:
1.1130 raeburn 5964: $bodytag .= $right;
1.852 droeschl 5965:
1.917 raeburn 5966: if ($dc_info) {
5967: $dc_info = &dc_courseid_toggle($dc_info);
5968: }
5969: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5970:
1.1169 raeburn 5971: #if directed to not display the secondary menu, don't.
1.1168 raeburn 5972: if ($args->{'no_secondary_menu'}) {
5973: return $bodytag;
5974: }
1.1169 raeburn 5975: #don't show menus for public users
1.954 raeburn 5976: if (!$public){
1.1154 raeburn 5977: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5978: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5979: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5980: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5981: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1274 raeburn 5982: $args->{'bread_crumbs'},'','',$hostname);
1.1096 raeburn 5983: } elsif ($forcereg) {
5984: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 5985: $args->{'group'},
1.1274 raeburn 5986: $args->{'hide_buttons'},
5987: $hostname);
1.1096 raeburn 5988: } else {
5989: $bodytag .=
5990: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5991: $forcereg,$args->{'group'},
5992: $args->{'bread_crumbs'},
1.1274 raeburn 5993: $advtoolsref,'',$hostname);
1.920 raeburn 5994: }
1.903 droeschl 5995: }else{
5996: # this is to seperate menu from content when there's no secondary
5997: # menu. Especially needed for public accessible ressources.
5998: $bodytag .= '<hr style="clear:both" />';
5999: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6000: }
1.903 droeschl 6001:
1.235 raeburn 6002: return $bodytag;
1.182 matthew 6003: }
6004:
1.917 raeburn 6005: sub dc_courseid_toggle {
6006: my ($dc_info) = @_;
1.980 raeburn 6007: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6008: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6009: &mt('(More ...)').'</a></span>'.
6010: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6011: }
6012:
1.330 albertel 6013: sub make_attr_string {
6014: my ($register,$attr_ref) = @_;
6015:
6016: if ($attr_ref && !ref($attr_ref)) {
6017: die("addentries Must be a hash ref ".
6018: join(':',caller(1))." ".
6019: join(':',caller(0))." ");
6020: }
6021:
6022: if ($register) {
1.339 albertel 6023: my ($on_load,$on_unload);
6024: foreach my $key (keys(%{$attr_ref})) {
6025: if (lc($key) eq 'onload') {
6026: $on_load.=$attr_ref->{$key}.';';
6027: delete($attr_ref->{$key});
6028:
6029: } elsif (lc($key) eq 'onunload') {
6030: $on_unload.=$attr_ref->{$key}.';';
6031: delete($attr_ref->{$key});
6032: }
6033: }
1.953 droeschl 6034: $attr_ref->{'onload'} = $on_load;
6035: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6036: }
1.339 albertel 6037:
1.330 albertel 6038: my $attr_string;
1.1159 raeburn 6039: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6040: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6041: }
6042: return $attr_string;
6043: }
6044:
6045:
1.182 matthew 6046: ###############################################
1.251 albertel 6047: ###############################################
6048:
6049: =pod
6050:
6051: =item * &endbodytag()
6052:
6053: Returns a uniform footer for LON-CAPA web pages.
6054:
1.635 raeburn 6055: Inputs: 1 - optional reference to an args hash
6056: If in the hash, key for noredirectlink has a value which evaluates to true,
6057: a 'Continue' link is not displayed if the page contains an
6058: internal redirect in the <head></head> section,
6059: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6060:
6061: =cut
6062:
6063: sub endbodytag {
1.635 raeburn 6064: my ($args) = @_;
1.1080 raeburn 6065: my $endbodytag;
6066: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6067: $endbodytag='</body>';
6068: }
1.315 albertel 6069: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6070: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6071: $endbodytag=
6072: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6073: &mt('Continue').'</a>'.
6074: $endbodytag;
6075: }
1.315 albertel 6076: }
1.251 albertel 6077: return $endbodytag;
6078: }
6079:
1.352 albertel 6080: =pod
6081:
6082: =item * &standard_css()
6083:
6084: Returns a style sheet
6085:
6086: Inputs: (all optional)
6087: domain -> force to color decorate a page for a specific
6088: domain
6089: function -> force usage of a specific rolish color scheme
6090: bgcolor -> override the default page bgcolor
6091:
6092: =cut
6093:
1.343 albertel 6094: sub standard_css {
1.345 albertel 6095: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6096: $function = &get_users_function() if (!$function);
6097: my $img = &designparm($function.'.img', $domain);
6098: my $tabbg = &designparm($function.'.tabbg', $domain);
6099: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6100: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6101: #second colour for later usage
1.345 albertel 6102: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6103: my $pgbg_or_bgcolor =
6104: $bgcolor ||
1.352 albertel 6105: &designparm($function.'.pgbg', $domain);
1.382 albertel 6106: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6107: my $alink = &designparm($function.'.alink', $domain);
6108: my $vlink = &designparm($function.'.vlink', $domain);
6109: my $link = &designparm($function.'.link', $domain);
6110:
1.602 albertel 6111: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6112: my $mono = 'monospace';
1.850 bisitz 6113: my $data_table_head = $sidebg;
6114: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6115: my $data_table_dark = '#E0E0E0';
1.470 banghart 6116: my $data_table_darker = '#CCCCCC';
1.349 albertel 6117: my $data_table_highlight = '#FFFF00';
1.352 albertel 6118: my $mail_new = '#FFBB77';
6119: my $mail_new_hover = '#DD9955';
6120: my $mail_read = '#BBBB77';
6121: my $mail_read_hover = '#999944';
6122: my $mail_replied = '#AAAA88';
6123: my $mail_replied_hover = '#888855';
6124: my $mail_other = '#99BBBB';
6125: my $mail_other_hover = '#669999';
1.391 albertel 6126: my $table_header = '#DDDDDD';
1.489 raeburn 6127: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6128: my $lg_border_color = '#C8C8C8';
1.952 onken 6129: my $button_hover = '#BF2317';
1.392 albertel 6130:
1.608 albertel 6131: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6132: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6133: : '0 3px 0 4px';
1.448 albertel 6134:
1.523 albertel 6135:
1.343 albertel 6136: return <<END;
1.947 droeschl 6137:
6138: /* needed for iframe to allow 100% height in FF */
6139: body, html {
6140: margin: 0;
6141: padding: 0 0.5%;
6142: height: 99%; /* to avoid scrollbars */
6143: }
6144:
1.795 www 6145: body {
1.911 bisitz 6146: font-family: $sans;
6147: line-height:130%;
6148: font-size:0.83em;
6149: color:$font;
1.795 www 6150: }
6151:
1.959 onken 6152: a:focus,
6153: a:focus img {
1.795 www 6154: color: red;
6155: }
1.698 harmsja 6156:
1.911 bisitz 6157: form, .inline {
6158: display: inline;
1.795 www 6159: }
1.721 harmsja 6160:
1.795 www 6161: .LC_right {
1.911 bisitz 6162: text-align:right;
1.795 www 6163: }
6164:
6165: .LC_middle {
1.911 bisitz 6166: vertical-align:middle;
1.795 www 6167: }
1.721 harmsja 6168:
1.1130 raeburn 6169: .LC_floatleft {
6170: float: left;
6171: }
6172:
6173: .LC_floatright {
6174: float: right;
6175: }
6176:
1.911 bisitz 6177: .LC_400Box {
6178: width:400px;
6179: }
1.721 harmsja 6180:
1.947 droeschl 6181: .LC_iframecontainer {
6182: width: 98%;
6183: margin: 0;
6184: position: fixed;
6185: top: 8.5em;
6186: bottom: 0;
6187: }
6188:
6189: .LC_iframecontainer iframe{
6190: border: none;
6191: width: 100%;
6192: height: 100%;
6193: }
6194:
1.778 bisitz 6195: .LC_filename {
6196: font-family: $mono;
6197: white-space:pre;
1.921 bisitz 6198: font-size: 120%;
1.778 bisitz 6199: }
6200:
6201: .LC_fileicon {
6202: border: none;
6203: height: 1.3em;
6204: vertical-align: text-bottom;
6205: margin-right: 0.3em;
6206: text-decoration:none;
6207: }
6208:
1.1008 www 6209: .LC_setting {
6210: text-decoration:underline;
6211: }
6212:
1.350 albertel 6213: .LC_error {
6214: color: red;
6215: }
1.795 www 6216:
1.1097 bisitz 6217: .LC_warning {
6218: color: darkorange;
6219: }
6220:
1.457 albertel 6221: .LC_diff_removed {
1.733 bisitz 6222: color: red;
1.394 albertel 6223: }
1.532 albertel 6224:
6225: .LC_info,
1.457 albertel 6226: .LC_success,
6227: .LC_diff_added {
1.350 albertel 6228: color: green;
6229: }
1.795 www 6230:
1.802 bisitz 6231: div.LC_confirm_box {
6232: background-color: #FAFAFA;
6233: border: 1px solid $lg_border_color;
6234: margin-right: 0;
6235: padding: 5px;
6236: }
6237:
6238: div.LC_confirm_box .LC_error img,
6239: div.LC_confirm_box .LC_success img {
6240: vertical-align: middle;
6241: }
6242:
1.1242 raeburn 6243: .LC_maxwidth {
6244: max-width: 100%;
6245: height: auto;
6246: }
6247:
1.1243 raeburn 6248: .LC_textsize_mobile {
6249: \@media only screen and (max-device-width: 480px) {
6250: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6251: }
6252: }
6253:
1.440 albertel 6254: .LC_icon {
1.771 droeschl 6255: border: none;
1.790 droeschl 6256: vertical-align: middle;
1.771 droeschl 6257: }
6258:
1.543 albertel 6259: .LC_docs_spacer {
6260: width: 25px;
6261: height: 1px;
1.771 droeschl 6262: border: none;
1.543 albertel 6263: }
1.346 albertel 6264:
1.532 albertel 6265: .LC_internal_info {
1.735 bisitz 6266: color: #999999;
1.532 albertel 6267: }
6268:
1.794 www 6269: .LC_discussion {
1.1050 www 6270: background: $data_table_dark;
1.911 bisitz 6271: border: 1px solid black;
6272: margin: 2px;
1.794 www 6273: }
6274:
6275: .LC_disc_action_left {
1.1050 www 6276: background: $sidebg;
1.911 bisitz 6277: text-align: left;
1.1050 www 6278: padding: 4px;
6279: margin: 2px;
1.794 www 6280: }
6281:
6282: .LC_disc_action_right {
1.1050 www 6283: background: $sidebg;
1.911 bisitz 6284: text-align: right;
1.1050 www 6285: padding: 4px;
6286: margin: 2px;
1.794 www 6287: }
6288:
6289: .LC_disc_new_item {
1.911 bisitz 6290: background: white;
6291: border: 2px solid red;
1.1050 www 6292: margin: 4px;
6293: padding: 4px;
1.794 www 6294: }
6295:
6296: .LC_disc_old_item {
1.911 bisitz 6297: background: white;
1.1050 www 6298: margin: 4px;
6299: padding: 4px;
1.794 www 6300: }
6301:
1.458 albertel 6302: table.LC_pastsubmission {
6303: border: 1px solid black;
6304: margin: 2px;
6305: }
6306:
1.924 bisitz 6307: table#LC_menubuttons {
1.345 albertel 6308: width: 100%;
6309: background: $pgbg;
1.392 albertel 6310: border: 2px;
1.402 albertel 6311: border-collapse: separate;
1.803 bisitz 6312: padding: 0;
1.345 albertel 6313: }
1.392 albertel 6314:
1.801 tempelho 6315: table#LC_title_bar a {
6316: color: $fontmenu;
6317: }
1.836 bisitz 6318:
1.807 droeschl 6319: table#LC_title_bar {
1.819 tempelho 6320: clear: both;
1.836 bisitz 6321: display: none;
1.807 droeschl 6322: }
6323:
1.795 www 6324: table#LC_title_bar,
1.933 droeschl 6325: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6326: table#LC_title_bar.LC_with_remote {
1.359 albertel 6327: width: 100%;
1.392 albertel 6328: border-color: $pgbg;
6329: border-style: solid;
6330: border-width: $border;
1.379 albertel 6331: background: $pgbg;
1.801 tempelho 6332: color: $fontmenu;
1.392 albertel 6333: border-collapse: collapse;
1.803 bisitz 6334: padding: 0;
1.819 tempelho 6335: margin: 0;
1.359 albertel 6336: }
1.795 www 6337:
1.933 droeschl 6338: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6339: margin: 0;
6340: padding: 0;
1.933 droeschl 6341: position: relative;
6342: list-style: none;
1.913 droeschl 6343: }
1.933 droeschl 6344: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6345: display: inline;
6346: }
1.933 droeschl 6347:
6348: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6349: padding: 0;
1.933 droeschl 6350: margin: 0;
6351: float: left;
1.913 droeschl 6352: }
1.933 droeschl 6353: .LC_breadcrumb_tools_tools {
6354: padding: 0;
6355: margin: 0;
1.913 droeschl 6356: float: right;
6357: }
6358:
1.1240 raeburn 6359: .LC_placement_prog {
6360: padding-right: 20px;
6361: font-weight: bold;
6362: font-size: 90%;
6363: }
6364:
1.359 albertel 6365: table#LC_title_bar td {
6366: background: $tabbg;
6367: }
1.795 www 6368:
1.911 bisitz 6369: table#LC_menubuttons img {
1.803 bisitz 6370: border: none;
1.346 albertel 6371: }
1.795 www 6372:
1.842 droeschl 6373: .LC_breadcrumbs_component {
1.911 bisitz 6374: float: right;
6375: margin: 0 1em;
1.357 albertel 6376: }
1.842 droeschl 6377: .LC_breadcrumbs_component img {
1.911 bisitz 6378: vertical-align: middle;
1.777 tempelho 6379: }
1.795 www 6380:
1.1243 raeburn 6381: .LC_breadcrumbs_hoverable {
6382: background: $sidebg;
6383: }
6384:
1.383 albertel 6385: td.LC_table_cell_checkbox {
6386: text-align: center;
6387: }
1.795 www 6388:
6389: .LC_fontsize_small {
1.911 bisitz 6390: font-size: 70%;
1.705 tempelho 6391: }
6392:
1.844 bisitz 6393: #LC_breadcrumbs {
1.911 bisitz 6394: clear:both;
6395: background: $sidebg;
6396: border-bottom: 1px solid $lg_border_color;
6397: line-height: 2.5em;
1.933 droeschl 6398: overflow: hidden;
1.911 bisitz 6399: margin: 0;
6400: padding: 0;
1.995 raeburn 6401: text-align: left;
1.819 tempelho 6402: }
1.862 bisitz 6403:
1.1098 bisitz 6404: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6405: clear:both;
6406: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6407: border: 1px solid $sidebg;
1.1098 bisitz 6408: margin: 0 0 10px 0;
1.966 bisitz 6409: padding: 3px;
1.995 raeburn 6410: text-align: left;
1.822 bisitz 6411: }
6412:
1.795 www 6413: .LC_fontsize_medium {
1.911 bisitz 6414: font-size: 85%;
1.705 tempelho 6415: }
6416:
1.795 www 6417: .LC_fontsize_large {
1.911 bisitz 6418: font-size: 120%;
1.705 tempelho 6419: }
6420:
1.346 albertel 6421: .LC_menubuttons_inline_text {
6422: color: $font;
1.698 harmsja 6423: font-size: 90%;
1.701 harmsja 6424: padding-left:3px;
1.346 albertel 6425: }
6426:
1.934 droeschl 6427: .LC_menubuttons_inline_text img{
6428: vertical-align: middle;
6429: }
6430:
1.1051 www 6431: li.LC_menubuttons_inline_text img {
1.951 onken 6432: cursor:pointer;
1.1002 droeschl 6433: text-decoration: none;
1.951 onken 6434: }
6435:
1.526 www 6436: .LC_menubuttons_link {
6437: text-decoration: none;
6438: }
1.795 www 6439:
1.522 albertel 6440: .LC_menubuttons_category {
1.521 www 6441: color: $font;
1.526 www 6442: background: $pgbg;
1.521 www 6443: font-size: larger;
6444: font-weight: bold;
6445: }
6446:
1.346 albertel 6447: td.LC_menubuttons_text {
1.911 bisitz 6448: color: $font;
1.346 albertel 6449: }
1.706 harmsja 6450:
1.346 albertel 6451: .LC_current_location {
6452: background: $tabbg;
6453: }
1.795 www 6454:
1.938 bisitz 6455: table.LC_data_table {
1.347 albertel 6456: border: 1px solid #000000;
1.402 albertel 6457: border-collapse: separate;
1.426 albertel 6458: border-spacing: 1px;
1.610 albertel 6459: background: $pgbg;
1.347 albertel 6460: }
1.795 www 6461:
1.422 albertel 6462: .LC_data_table_dense {
6463: font-size: small;
6464: }
1.795 www 6465:
1.507 raeburn 6466: table.LC_nested_outer {
6467: border: 1px solid #000000;
1.589 raeburn 6468: border-collapse: collapse;
1.803 bisitz 6469: border-spacing: 0;
1.507 raeburn 6470: width: 100%;
6471: }
1.795 www 6472:
1.879 raeburn 6473: table.LC_innerpickbox,
1.507 raeburn 6474: table.LC_nested {
1.803 bisitz 6475: border: none;
1.589 raeburn 6476: border-collapse: collapse;
1.803 bisitz 6477: border-spacing: 0;
1.507 raeburn 6478: width: 100%;
6479: }
1.795 www 6480:
1.911 bisitz 6481: table.LC_data_table tr th,
6482: table.LC_calendar tr th,
1.879 raeburn 6483: table.LC_prior_tries tr th,
6484: table.LC_innerpickbox tr th {
1.349 albertel 6485: font-weight: bold;
6486: background-color: $data_table_head;
1.801 tempelho 6487: color:$fontmenu;
1.701 harmsja 6488: font-size:90%;
1.347 albertel 6489: }
1.795 www 6490:
1.879 raeburn 6491: table.LC_innerpickbox tr th,
6492: table.LC_innerpickbox tr td {
6493: vertical-align: top;
6494: }
6495:
1.711 raeburn 6496: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6497: background-color: #CCCCCC;
1.711 raeburn 6498: font-weight: bold;
6499: text-align: left;
6500: }
1.795 www 6501:
1.912 bisitz 6502: table.LC_data_table tr.LC_odd_row > td {
6503: background-color: $data_table_light;
6504: padding: 2px;
6505: vertical-align: top;
6506: }
6507:
1.809 bisitz 6508: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6509: background-color: $data_table_light;
1.912 bisitz 6510: vertical-align: top;
6511: }
6512:
6513: table.LC_data_table tr.LC_even_row > td {
6514: background-color: $data_table_dark;
1.425 albertel 6515: padding: 2px;
1.900 bisitz 6516: vertical-align: top;
1.347 albertel 6517: }
1.795 www 6518:
1.809 bisitz 6519: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6520: background-color: $data_table_dark;
1.900 bisitz 6521: vertical-align: top;
1.347 albertel 6522: }
1.795 www 6523:
1.425 albertel 6524: table.LC_data_table tr.LC_data_table_highlight td {
6525: background-color: $data_table_darker;
6526: }
1.795 www 6527:
1.639 raeburn 6528: table.LC_data_table tr td.LC_leftcol_header {
6529: background-color: $data_table_head;
6530: font-weight: bold;
6531: }
1.795 www 6532:
1.451 albertel 6533: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6534: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6535: font-weight: bold;
6536: font-style: italic;
6537: text-align: center;
6538: padding: 8px;
1.347 albertel 6539: }
1.795 www 6540:
1.1114 raeburn 6541: table.LC_data_table tr.LC_empty_row td,
6542: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6543: background-color: $sidebg;
6544: }
6545:
6546: table.LC_nested tr.LC_empty_row td {
6547: background-color: #FFFFFF;
6548: }
6549:
1.890 droeschl 6550: table.LC_caption {
6551: }
6552:
1.507 raeburn 6553: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6554: padding: 4ex
6555: }
1.795 www 6556:
1.507 raeburn 6557: table.LC_nested_outer tr th {
6558: font-weight: bold;
1.801 tempelho 6559: color:$fontmenu;
1.507 raeburn 6560: background-color: $data_table_head;
1.701 harmsja 6561: font-size: small;
1.507 raeburn 6562: border-bottom: 1px solid #000000;
6563: }
1.795 www 6564:
1.507 raeburn 6565: table.LC_nested_outer tr td.LC_subheader {
6566: background-color: $data_table_head;
6567: font-weight: bold;
6568: font-size: small;
6569: border-bottom: 1px solid #000000;
6570: text-align: right;
1.451 albertel 6571: }
1.795 www 6572:
1.507 raeburn 6573: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6574: background-color: #CCCCCC;
1.451 albertel 6575: font-weight: bold;
6576: font-size: small;
1.507 raeburn 6577: text-align: center;
6578: }
1.795 www 6579:
1.589 raeburn 6580: table.LC_nested tr.LC_info_row td.LC_left_item,
6581: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6582: text-align: left;
1.451 albertel 6583: }
1.795 www 6584:
1.507 raeburn 6585: table.LC_nested td {
1.735 bisitz 6586: background-color: #FFFFFF;
1.451 albertel 6587: font-size: small;
1.507 raeburn 6588: }
1.795 www 6589:
1.507 raeburn 6590: table.LC_nested_outer tr th.LC_right_item,
6591: table.LC_nested tr.LC_info_row td.LC_right_item,
6592: table.LC_nested tr.LC_odd_row td.LC_right_item,
6593: table.LC_nested tr td.LC_right_item {
1.451 albertel 6594: text-align: right;
6595: }
6596:
1.507 raeburn 6597: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6598: background-color: #EEEEEE;
1.451 albertel 6599: }
6600:
1.473 raeburn 6601: table.LC_createuser {
6602: }
6603:
6604: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6605: font-size: small;
1.473 raeburn 6606: }
6607:
6608: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6609: background-color: #CCCCCC;
1.473 raeburn 6610: font-weight: bold;
6611: text-align: center;
6612: }
6613:
1.349 albertel 6614: table.LC_calendar {
6615: border: 1px solid #000000;
6616: border-collapse: collapse;
1.917 raeburn 6617: width: 98%;
1.349 albertel 6618: }
1.795 www 6619:
1.349 albertel 6620: table.LC_calendar_pickdate {
6621: font-size: xx-small;
6622: }
1.795 www 6623:
1.349 albertel 6624: table.LC_calendar tr td {
6625: border: 1px solid #000000;
6626: vertical-align: top;
1.917 raeburn 6627: width: 14%;
1.349 albertel 6628: }
1.795 www 6629:
1.349 albertel 6630: table.LC_calendar tr td.LC_calendar_day_empty {
6631: background-color: $data_table_dark;
6632: }
1.795 www 6633:
1.779 bisitz 6634: table.LC_calendar tr td.LC_calendar_day_current {
6635: background-color: $data_table_highlight;
1.777 tempelho 6636: }
1.795 www 6637:
1.938 bisitz 6638: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6639: background-color: $mail_new;
6640: }
1.795 www 6641:
1.938 bisitz 6642: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6643: background-color: $mail_new_hover;
6644: }
1.795 www 6645:
1.938 bisitz 6646: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6647: background-color: $mail_read;
6648: }
1.795 www 6649:
1.938 bisitz 6650: /*
6651: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6652: background-color: $mail_read_hover;
6653: }
1.938 bisitz 6654: */
1.795 www 6655:
1.938 bisitz 6656: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6657: background-color: $mail_replied;
6658: }
1.795 www 6659:
1.938 bisitz 6660: /*
6661: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6662: background-color: $mail_replied_hover;
6663: }
1.938 bisitz 6664: */
1.795 www 6665:
1.938 bisitz 6666: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6667: background-color: $mail_other;
6668: }
1.795 www 6669:
1.938 bisitz 6670: /*
6671: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6672: background-color: $mail_other_hover;
6673: }
1.938 bisitz 6674: */
1.494 raeburn 6675:
1.777 tempelho 6676: table.LC_data_table tr > td.LC_browser_file,
6677: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6678: background: #AAEE77;
1.389 albertel 6679: }
1.795 www 6680:
1.777 tempelho 6681: table.LC_data_table tr > td.LC_browser_file_locked,
6682: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6683: background: #FFAA99;
1.387 albertel 6684: }
1.795 www 6685:
1.777 tempelho 6686: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6687: background: #888888;
1.779 bisitz 6688: }
1.795 www 6689:
1.777 tempelho 6690: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6691: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6692: background: #F8F866;
1.777 tempelho 6693: }
1.795 www 6694:
1.696 bisitz 6695: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6696: background: #E0E8FF;
1.387 albertel 6697: }
1.696 bisitz 6698:
1.707 bisitz 6699: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6700: /* background: #77FF77; */
1.707 bisitz 6701: }
1.795 www 6702:
1.707 bisitz 6703: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6704: border-right: 8px solid #FFFF77;
1.707 bisitz 6705: }
1.795 www 6706:
1.707 bisitz 6707: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6708: border-right: 8px solid #FFAA77;
1.707 bisitz 6709: }
1.795 www 6710:
1.707 bisitz 6711: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6712: border-right: 8px solid #FF7777;
1.707 bisitz 6713: }
1.795 www 6714:
1.707 bisitz 6715: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6716: border-right: 8px solid #AAFF77;
1.707 bisitz 6717: }
1.795 www 6718:
1.707 bisitz 6719: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6720: border-right: 8px solid #11CC55;
1.707 bisitz 6721: }
6722:
1.388 albertel 6723: span.LC_current_location {
1.701 harmsja 6724: font-size:larger;
1.388 albertel 6725: background: $pgbg;
6726: }
1.387 albertel 6727:
1.1029 www 6728: span.LC_current_nav_location {
6729: font-weight:bold;
6730: background: $sidebg;
6731: }
6732:
1.395 albertel 6733: span.LC_parm_menu_item {
6734: font-size: larger;
6735: }
1.795 www 6736:
1.395 albertel 6737: span.LC_parm_scope_all {
6738: color: red;
6739: }
1.795 www 6740:
1.395 albertel 6741: span.LC_parm_scope_folder {
6742: color: green;
6743: }
1.795 www 6744:
1.395 albertel 6745: span.LC_parm_scope_resource {
6746: color: orange;
6747: }
1.795 www 6748:
1.395 albertel 6749: span.LC_parm_part {
6750: color: blue;
6751: }
1.795 www 6752:
1.911 bisitz 6753: span.LC_parm_folder,
6754: span.LC_parm_symb {
1.395 albertel 6755: font-size: x-small;
6756: font-family: $mono;
6757: color: #AAAAAA;
6758: }
6759:
1.977 bisitz 6760: ul.LC_parm_parmlist li {
6761: display: inline-block;
6762: padding: 0.3em 0.8em;
6763: vertical-align: top;
6764: width: 150px;
6765: border-top:1px solid $lg_border_color;
6766: }
6767:
1.795 www 6768: td.LC_parm_overview_level_menu,
6769: td.LC_parm_overview_map_menu,
6770: td.LC_parm_overview_parm_selectors,
6771: td.LC_parm_overview_restrictions {
1.396 albertel 6772: border: 1px solid black;
6773: border-collapse: collapse;
6774: }
1.795 www 6775:
1.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.1284 ! raeburn 7127: .LC_docs_alias {
! 7128: color: #440055;
! 7129: }
! 7130:
! 7131: .LC_docs_alias_name,
1.547 albertel 7132: .LC_docs_reinit_warn,
7133: .LC_docs_ext_edit {
7134: font-size: x-small;
7135: }
7136:
1.545 albertel 7137: table.LC_docs_adddocs td,
7138: table.LC_docs_adddocs th {
7139: border: 1px solid #BBBBBB;
7140: padding: 4px;
7141: background: #DDDDDD;
1.543 albertel 7142: }
7143:
1.584 albertel 7144: table.LC_sty_begin {
7145: background: #BBFFBB;
7146: }
1.795 www 7147:
1.584 albertel 7148: table.LC_sty_end {
7149: background: #FFBBBB;
7150: }
7151:
1.589 raeburn 7152: table.LC_double_column {
1.803 bisitz 7153: border-width: 0;
1.589 raeburn 7154: border-collapse: collapse;
7155: width: 100%;
7156: padding: 2px;
7157: }
7158:
7159: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7160: top: 2px;
1.589 raeburn 7161: left: 2px;
7162: width: 47%;
7163: vertical-align: top;
7164: }
7165:
7166: table.LC_double_column tr td.LC_right_col {
7167: top: 2px;
1.779 bisitz 7168: right: 2px;
1.589 raeburn 7169: width: 47%;
7170: vertical-align: top;
7171: }
7172:
1.591 raeburn 7173: div.LC_left_float {
7174: float: left;
7175: padding-right: 5%;
1.597 albertel 7176: padding-bottom: 4px;
1.591 raeburn 7177: }
7178:
7179: div.LC_clear_float_header {
1.597 albertel 7180: padding-bottom: 2px;
1.591 raeburn 7181: }
7182:
7183: div.LC_clear_float_footer {
1.597 albertel 7184: padding-top: 10px;
1.591 raeburn 7185: clear: both;
7186: }
7187:
1.597 albertel 7188: div.LC_grade_show_user {
1.941 bisitz 7189: /* border-left: 5px solid $sidebg; */
7190: border-top: 5px solid #000000;
7191: margin: 50px 0 0 0;
1.936 bisitz 7192: padding: 15px 0 5px 10px;
1.597 albertel 7193: }
1.795 www 7194:
1.936 bisitz 7195: div.LC_grade_show_user_odd_row {
1.941 bisitz 7196: /* border-left: 5px solid #000000; */
7197: }
7198:
7199: div.LC_grade_show_user div.LC_Box {
7200: margin-right: 50px;
1.597 albertel 7201: }
7202:
7203: div.LC_grade_submissions,
7204: div.LC_grade_message_center,
1.936 bisitz 7205: div.LC_grade_info_links {
1.597 albertel 7206: margin: 5px;
7207: width: 99%;
7208: background: #FFFFFF;
7209: }
1.795 www 7210:
1.597 albertel 7211: div.LC_grade_submissions_header,
1.936 bisitz 7212: div.LC_grade_message_center_header {
1.705 tempelho 7213: font-weight: bold;
7214: font-size: large;
1.597 albertel 7215: }
1.795 www 7216:
1.597 albertel 7217: div.LC_grade_submissions_body,
1.936 bisitz 7218: div.LC_grade_message_center_body {
1.597 albertel 7219: border: 1px solid black;
7220: width: 99%;
7221: background: #FFFFFF;
7222: }
1.795 www 7223:
1.613 albertel 7224: table.LC_scantron_action {
7225: width: 100%;
7226: }
1.795 www 7227:
1.613 albertel 7228: table.LC_scantron_action tr th {
1.698 harmsja 7229: font-weight:bold;
7230: font-style:normal;
1.613 albertel 7231: }
1.795 www 7232:
1.779 bisitz 7233: .LC_edit_problem_header,
1.614 albertel 7234: div.LC_edit_problem_footer {
1.705 tempelho 7235: font-weight: normal;
7236: font-size: medium;
1.602 albertel 7237: margin: 2px;
1.1060 bisitz 7238: background-color: $sidebg;
1.600 albertel 7239: }
1.795 www 7240:
1.600 albertel 7241: div.LC_edit_problem_header,
1.602 albertel 7242: div.LC_edit_problem_header div,
1.614 albertel 7243: div.LC_edit_problem_footer,
7244: div.LC_edit_problem_footer div,
1.602 albertel 7245: div.LC_edit_problem_editxml_header,
7246: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7247: z-index: 100;
1.600 albertel 7248: }
1.795 www 7249:
1.600 albertel 7250: div.LC_edit_problem_header_title {
1.705 tempelho 7251: font-weight: bold;
7252: font-size: larger;
1.602 albertel 7253: background: $tabbg;
7254: padding: 3px;
1.1060 bisitz 7255: margin: 0 0 5px 0;
1.602 albertel 7256: }
1.795 www 7257:
1.602 albertel 7258: table.LC_edit_problem_header_title {
7259: width: 100%;
1.600 albertel 7260: background: $tabbg;
1.602 albertel 7261: }
7262:
1.1205 golterma 7263: div.LC_edit_actionbar {
7264: background-color: $sidebg;
1.1218 droeschl 7265: margin: 0;
7266: padding: 0;
7267: line-height: 200%;
1.602 albertel 7268: }
1.795 www 7269:
1.1218 droeschl 7270: div.LC_edit_actionbar div{
7271: padding: 0;
7272: margin: 0;
7273: display: inline-block;
1.600 albertel 7274: }
1.795 www 7275:
1.1124 bisitz 7276: .LC_edit_opt {
7277: padding-left: 1em;
7278: white-space: nowrap;
7279: }
7280:
1.1152 golterma 7281: .LC_edit_problem_latexhelper{
7282: text-align: right;
7283: }
7284:
7285: #LC_edit_problem_colorful div{
7286: margin-left: 40px;
7287: }
7288:
1.1205 golterma 7289: #LC_edit_problem_codemirror div{
7290: margin-left: 0px;
7291: }
7292:
1.911 bisitz 7293: img.stift {
1.803 bisitz 7294: border-width: 0;
7295: vertical-align: middle;
1.677 riegler 7296: }
1.680 riegler 7297:
1.923 bisitz 7298: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7299: vertical-align: top;
1.777 tempelho 7300: }
1.795 www 7301:
1.716 raeburn 7302: div.LC_createcourse {
1.911 bisitz 7303: margin: 10px 10px 10px 10px;
1.716 raeburn 7304: }
7305:
1.917 raeburn 7306: .LC_dccid {
1.1130 raeburn 7307: float: right;
1.917 raeburn 7308: margin: 0.2em 0 0 0;
7309: padding: 0;
7310: font-size: 90%;
7311: display:none;
7312: }
7313:
1.897 wenzelju 7314: ol.LC_primary_menu a:hover,
1.721 harmsja 7315: ol#LC_MenuBreadcrumbs a:hover,
7316: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7317: ul#LC_secondary_menu a:hover,
1.721 harmsja 7318: .LC_FormSectionClearButton input:hover
1.795 www 7319: ul.LC_TabContent li:hover a {
1.952 onken 7320: color:$button_hover;
1.911 bisitz 7321: text-decoration:none;
1.693 droeschl 7322: }
7323:
1.779 bisitz 7324: h1 {
1.911 bisitz 7325: padding: 0;
7326: line-height:130%;
1.693 droeschl 7327: }
1.698 harmsja 7328:
1.911 bisitz 7329: h2,
7330: h3,
7331: h4,
7332: h5,
7333: h6 {
7334: margin: 5px 0 5px 0;
7335: padding: 0;
7336: line-height:130%;
1.693 droeschl 7337: }
1.795 www 7338:
7339: .LC_hcell {
1.911 bisitz 7340: padding:3px 15px 3px 15px;
7341: margin: 0;
7342: background-color:$tabbg;
7343: color:$fontmenu;
7344: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7345: }
1.795 www 7346:
1.840 bisitz 7347: .LC_Box > .LC_hcell {
1.911 bisitz 7348: margin: 0 -10px 10px -10px;
1.835 bisitz 7349: }
7350:
1.721 harmsja 7351: .LC_noBorder {
1.911 bisitz 7352: border: 0;
1.698 harmsja 7353: }
1.693 droeschl 7354:
1.721 harmsja 7355: .LC_FormSectionClearButton input {
1.911 bisitz 7356: background-color:transparent;
7357: border: none;
7358: cursor:pointer;
7359: text-decoration:underline;
1.693 droeschl 7360: }
1.763 bisitz 7361:
7362: .LC_help_open_topic {
1.911 bisitz 7363: color: #FFFFFF;
7364: background-color: #EEEEFF;
7365: margin: 1px;
7366: padding: 4px;
7367: border: 1px solid #000033;
7368: white-space: nowrap;
7369: /* vertical-align: middle; */
1.759 neumanie 7370: }
1.693 droeschl 7371:
1.911 bisitz 7372: dl,
7373: ul,
7374: div,
7375: fieldset {
7376: margin: 10px 10px 10px 0;
7377: /* overflow: hidden; */
1.693 droeschl 7378: }
1.795 www 7379:
1.1211 raeburn 7380: article.geogebraweb div {
7381: margin: 0;
7382: }
7383:
1.838 bisitz 7384: fieldset > legend {
1.911 bisitz 7385: font-weight: bold;
7386: padding: 0 5px 0 5px;
1.838 bisitz 7387: }
7388:
1.813 bisitz 7389: #LC_nav_bar {
1.911 bisitz 7390: float: left;
1.995 raeburn 7391: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7392: margin: 0 0 2px 0;
1.807 droeschl 7393: }
7394:
1.916 droeschl 7395: #LC_realm {
7396: margin: 0.2em 0 0 0;
7397: padding: 0;
7398: font-weight: bold;
7399: text-align: center;
1.995 raeburn 7400: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7401: }
7402:
1.911 bisitz 7403: #LC_nav_bar em {
7404: font-weight: bold;
7405: font-style: normal;
1.807 droeschl 7406: }
7407:
1.897 wenzelju 7408: ol.LC_primary_menu {
1.934 droeschl 7409: margin: 0;
1.1076 raeburn 7410: padding: 0;
1.807 droeschl 7411: }
7412:
1.852 droeschl 7413: ol#LC_PathBreadcrumbs {
1.911 bisitz 7414: margin: 0;
1.693 droeschl 7415: }
7416:
1.897 wenzelju 7417: ol.LC_primary_menu li {
1.1076 raeburn 7418: color: RGB(80, 80, 80);
7419: vertical-align: middle;
7420: text-align: left;
7421: list-style: none;
1.1205 golterma 7422: position: relative;
1.1076 raeburn 7423: float: left;
1.1205 golterma 7424: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7425: line-height: 1.5em;
1.1076 raeburn 7426: }
7427:
1.1205 golterma 7428: ol.LC_primary_menu li a,
7429: ol.LC_primary_menu li p {
1.1076 raeburn 7430: display: block;
7431: margin: 0;
7432: padding: 0 5px 0 10px;
7433: text-decoration: none;
7434: }
7435:
1.1205 golterma 7436: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7437: display: inline-block;
7438: width: 95%;
7439: text-align: left;
7440: }
7441:
7442: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7443: display: inline-block;
7444: width: 5%;
7445: float: right;
7446: text-align: right;
7447: font-size: 70%;
7448: }
7449:
7450: ol.LC_primary_menu ul {
1.1076 raeburn 7451: display: none;
1.1205 golterma 7452: width: 15em;
1.1076 raeburn 7453: background-color: $data_table_light;
1.1205 golterma 7454: position: absolute;
7455: top: 100%;
1.1076 raeburn 7456: }
7457:
1.1205 golterma 7458: ol.LC_primary_menu ul ul {
7459: left: 100%;
7460: top: 0;
7461: }
7462:
7463: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7464: display: block;
7465: position: absolute;
7466: margin: 0;
7467: padding: 0;
1.1078 raeburn 7468: z-index: 2;
1.1076 raeburn 7469: }
7470:
7471: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7472: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7473: font-size: 90%;
1.911 bisitz 7474: vertical-align: top;
1.1076 raeburn 7475: float: none;
1.1079 raeburn 7476: border-left: 1px solid black;
7477: border-right: 1px solid black;
1.1205 golterma 7478: /* A dark bottom border to visualize different menu options;
7479: overwritten in the create_submenu routine for the last border-bottom of the menu */
7480: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7481: }
7482:
1.1205 golterma 7483: ol.LC_primary_menu li li p:hover {
7484: color:$button_hover;
7485: text-decoration:none;
7486: background-color:$data_table_dark;
1.1076 raeburn 7487: }
7488:
7489: ol.LC_primary_menu li li a:hover {
7490: color:$button_hover;
7491: background-color:$data_table_dark;
1.693 droeschl 7492: }
7493:
1.1205 golterma 7494: /* Font-size equal to the size of the predecessors*/
7495: ol.LC_primary_menu li:hover li li {
7496: font-size: 100%;
7497: }
7498:
1.897 wenzelju 7499: ol.LC_primary_menu li img {
1.911 bisitz 7500: vertical-align: bottom;
1.934 droeschl 7501: height: 1.1em;
1.1077 raeburn 7502: margin: 0.2em 0 0 0;
1.693 droeschl 7503: }
7504:
1.897 wenzelju 7505: ol.LC_primary_menu a {
1.911 bisitz 7506: color: RGB(80, 80, 80);
7507: text-decoration: none;
1.693 droeschl 7508: }
1.795 www 7509:
1.949 droeschl 7510: ol.LC_primary_menu a.LC_new_message {
7511: font-weight:bold;
7512: color: darkred;
7513: }
7514:
1.975 raeburn 7515: ol.LC_docs_parameters {
7516: margin-left: 0;
7517: padding: 0;
7518: list-style: none;
7519: }
7520:
7521: ol.LC_docs_parameters li {
7522: margin: 0;
7523: padding-right: 20px;
7524: display: inline;
7525: }
7526:
1.976 raeburn 7527: ol.LC_docs_parameters li:before {
7528: content: "\\002022 \\0020";
7529: }
7530:
7531: li.LC_docs_parameters_title {
7532: font-weight: bold;
7533: }
7534:
7535: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7536: content: "";
7537: }
7538:
1.897 wenzelju 7539: ul#LC_secondary_menu {
1.1107 raeburn 7540: clear: right;
1.911 bisitz 7541: color: $fontmenu;
7542: background: $tabbg;
7543: list-style: none;
7544: padding: 0;
7545: margin: 0;
7546: width: 100%;
1.995 raeburn 7547: text-align: left;
1.1107 raeburn 7548: float: left;
1.808 droeschl 7549: }
7550:
1.897 wenzelju 7551: ul#LC_secondary_menu li {
1.911 bisitz 7552: font-weight: bold;
7553: line-height: 1.8em;
1.1107 raeburn 7554: border-right: 1px solid black;
7555: float: left;
7556: }
7557:
7558: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7559: background-color: $data_table_light;
7560: }
7561:
7562: ul#LC_secondary_menu li a {
1.911 bisitz 7563: padding: 0 0.8em;
1.1107 raeburn 7564: }
7565:
7566: ul#LC_secondary_menu li ul {
7567: display: none;
7568: }
7569:
7570: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7571: display: block;
7572: position: absolute;
7573: margin: 0;
7574: padding: 0;
7575: list-style:none;
7576: float: none;
7577: background-color: $data_table_light;
7578: z-index: 2;
7579: margin-left: -1px;
7580: }
7581:
7582: ul#LC_secondary_menu li ul li {
7583: font-size: 90%;
7584: vertical-align: top;
7585: border-left: 1px solid black;
1.911 bisitz 7586: border-right: 1px solid black;
1.1119 raeburn 7587: background-color: $data_table_light;
1.1107 raeburn 7588: list-style:none;
7589: float: none;
7590: }
7591:
7592: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7593: background-color: $data_table_dark;
1.807 droeschl 7594: }
7595:
1.847 tempelho 7596: ul.LC_TabContent {
1.911 bisitz 7597: display:block;
7598: background: $sidebg;
7599: border-bottom: solid 1px $lg_border_color;
7600: list-style:none;
1.1020 raeburn 7601: margin: -1px -10px 0 -10px;
1.911 bisitz 7602: padding: 0;
1.693 droeschl 7603: }
7604:
1.795 www 7605: ul.LC_TabContent li,
7606: ul.LC_TabContentBigger li {
1.911 bisitz 7607: float:left;
1.741 harmsja 7608: }
1.795 www 7609:
1.897 wenzelju 7610: ul#LC_secondary_menu li a {
1.911 bisitz 7611: color: $fontmenu;
7612: text-decoration: none;
1.693 droeschl 7613: }
1.795 www 7614:
1.721 harmsja 7615: ul.LC_TabContent {
1.952 onken 7616: min-height:20px;
1.721 harmsja 7617: }
1.795 www 7618:
7619: ul.LC_TabContent li {
1.911 bisitz 7620: vertical-align:middle;
1.959 onken 7621: padding: 0 16px 0 10px;
1.911 bisitz 7622: background-color:$tabbg;
7623: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7624: border-left: solid 1px $font;
1.721 harmsja 7625: }
1.795 www 7626:
1.847 tempelho 7627: ul.LC_TabContent .right {
1.911 bisitz 7628: float:right;
1.847 tempelho 7629: }
7630:
1.911 bisitz 7631: ul.LC_TabContent li a,
7632: ul.LC_TabContent li {
7633: color:rgb(47,47,47);
7634: text-decoration:none;
7635: font-size:95%;
7636: font-weight:bold;
1.952 onken 7637: min-height:20px;
7638: }
7639:
1.959 onken 7640: ul.LC_TabContent li a:hover,
7641: ul.LC_TabContent li a:focus {
1.952 onken 7642: color: $button_hover;
1.959 onken 7643: background:none;
7644: outline:none;
1.952 onken 7645: }
7646:
7647: ul.LC_TabContent li:hover {
7648: color: $button_hover;
7649: cursor:pointer;
1.721 harmsja 7650: }
1.795 www 7651:
1.911 bisitz 7652: ul.LC_TabContent li.active {
1.952 onken 7653: color: $font;
1.911 bisitz 7654: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7655: border-bottom:solid 1px #FFFFFF;
7656: cursor: default;
1.744 ehlerst 7657: }
1.795 www 7658:
1.959 onken 7659: ul.LC_TabContent li.active a {
7660: color:$font;
7661: background:#FFFFFF;
7662: outline: none;
7663: }
1.1047 raeburn 7664:
7665: ul.LC_TabContent li.goback {
7666: float: left;
7667: border-left: none;
7668: }
7669:
1.870 tempelho 7670: #maincoursedoc {
1.911 bisitz 7671: clear:both;
1.870 tempelho 7672: }
7673:
7674: ul.LC_TabContentBigger {
1.911 bisitz 7675: display:block;
7676: list-style:none;
7677: padding: 0;
1.870 tempelho 7678: }
7679:
1.795 www 7680: ul.LC_TabContentBigger li {
1.911 bisitz 7681: vertical-align:bottom;
7682: height: 30px;
7683: font-size:110%;
7684: font-weight:bold;
7685: color: #737373;
1.841 tempelho 7686: }
7687:
1.957 onken 7688: ul.LC_TabContentBigger li.active {
7689: position: relative;
7690: top: 1px;
7691: }
7692:
1.870 tempelho 7693: ul.LC_TabContentBigger li a {
1.911 bisitz 7694: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7695: height: 30px;
7696: line-height: 30px;
7697: text-align: center;
7698: display: block;
7699: text-decoration: none;
1.958 onken 7700: outline: none;
1.741 harmsja 7701: }
1.795 www 7702:
1.870 tempelho 7703: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7704: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7705: color:$font;
1.744 ehlerst 7706: }
1.795 www 7707:
1.870 tempelho 7708: ul.LC_TabContentBigger li b {
1.911 bisitz 7709: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7710: display: block;
7711: float: left;
7712: padding: 0 30px;
1.957 onken 7713: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7714: }
7715:
1.956 onken 7716: ul.LC_TabContentBigger li:hover b {
7717: color:$button_hover;
7718: }
7719:
1.870 tempelho 7720: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7721: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7722: color:$font;
1.957 onken 7723: border: 0;
1.741 harmsja 7724: }
1.693 droeschl 7725:
1.870 tempelho 7726:
1.862 bisitz 7727: ul.LC_CourseBreadcrumbs {
7728: background: $sidebg;
1.1020 raeburn 7729: height: 2em;
1.862 bisitz 7730: padding-left: 10px;
1.1020 raeburn 7731: margin: 0;
1.862 bisitz 7732: list-style-position: inside;
7733: }
7734:
1.911 bisitz 7735: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7736: ol#LC_PathBreadcrumbs {
1.911 bisitz 7737: padding-left: 10px;
7738: margin: 0;
1.933 droeschl 7739: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7740: }
7741:
1.911 bisitz 7742: ol#LC_MenuBreadcrumbs li,
7743: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7744: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7745: display: inline;
1.933 droeschl 7746: white-space: normal;
1.693 droeschl 7747: }
7748:
1.823 bisitz 7749: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7750: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7751: text-decoration: none;
7752: font-size:90%;
1.693 droeschl 7753: }
1.795 www 7754:
1.969 droeschl 7755: ol#LC_MenuBreadcrumbs h1 {
7756: display: inline;
7757: font-size: 90%;
7758: line-height: 2.5em;
7759: margin: 0;
7760: padding: 0;
7761: }
7762:
1.795 www 7763: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7764: text-decoration:none;
7765: font-size:100%;
7766: font-weight:bold;
1.693 droeschl 7767: }
1.795 www 7768:
1.840 bisitz 7769: .LC_Box {
1.911 bisitz 7770: border: solid 1px $lg_border_color;
7771: padding: 0 10px 10px 10px;
1.746 neumanie 7772: }
1.795 www 7773:
1.1020 raeburn 7774: .LC_DocsBox {
7775: border: solid 1px $lg_border_color;
7776: padding: 0 0 10px 10px;
7777: }
7778:
1.795 www 7779: .LC_AboutMe_Image {
1.911 bisitz 7780: float:left;
7781: margin-right:10px;
1.747 neumanie 7782: }
1.795 www 7783:
7784: .LC_Clear_AboutMe_Image {
1.911 bisitz 7785: clear:left;
1.747 neumanie 7786: }
1.795 www 7787:
1.721 harmsja 7788: dl.LC_ListStyleClean dt {
1.911 bisitz 7789: padding-right: 5px;
7790: display: table-header-group;
1.693 droeschl 7791: }
7792:
1.721 harmsja 7793: dl.LC_ListStyleClean dd {
1.911 bisitz 7794: display: table-row;
1.693 droeschl 7795: }
7796:
1.721 harmsja 7797: .LC_ListStyleClean,
7798: .LC_ListStyleSimple,
7799: .LC_ListStyleNormal,
1.795 www 7800: .LC_ListStyleSpecial {
1.911 bisitz 7801: /* display:block; */
7802: list-style-position: inside;
7803: list-style-type: none;
7804: overflow: hidden;
7805: padding: 0;
1.693 droeschl 7806: }
7807:
1.721 harmsja 7808: .LC_ListStyleSimple li,
7809: .LC_ListStyleSimple dd,
7810: .LC_ListStyleNormal li,
7811: .LC_ListStyleNormal dd,
7812: .LC_ListStyleSpecial li,
1.795 www 7813: .LC_ListStyleSpecial dd {
1.911 bisitz 7814: margin: 0;
7815: padding: 5px 5px 5px 10px;
7816: clear: both;
1.693 droeschl 7817: }
7818:
1.721 harmsja 7819: .LC_ListStyleClean li,
7820: .LC_ListStyleClean dd {
1.911 bisitz 7821: padding-top: 0;
7822: padding-bottom: 0;
1.693 droeschl 7823: }
7824:
1.721 harmsja 7825: .LC_ListStyleSimple dd,
1.795 www 7826: .LC_ListStyleSimple li {
1.911 bisitz 7827: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7828: }
7829:
1.721 harmsja 7830: .LC_ListStyleSpecial li,
7831: .LC_ListStyleSpecial dd {
1.911 bisitz 7832: list-style-type: none;
7833: background-color: RGB(220, 220, 220);
7834: margin-bottom: 4px;
1.693 droeschl 7835: }
7836:
1.721 harmsja 7837: table.LC_SimpleTable {
1.911 bisitz 7838: margin:5px;
7839: border:solid 1px $lg_border_color;
1.795 www 7840: }
1.693 droeschl 7841:
1.721 harmsja 7842: table.LC_SimpleTable tr {
1.911 bisitz 7843: padding: 0;
7844: border:solid 1px $lg_border_color;
1.693 droeschl 7845: }
1.795 www 7846:
7847: table.LC_SimpleTable thead {
1.911 bisitz 7848: background:rgb(220,220,220);
1.693 droeschl 7849: }
7850:
1.721 harmsja 7851: div.LC_columnSection {
1.911 bisitz 7852: display: block;
7853: clear: both;
7854: overflow: hidden;
7855: margin: 0;
1.693 droeschl 7856: }
7857:
1.721 harmsja 7858: div.LC_columnSection>* {
1.911 bisitz 7859: float: left;
7860: margin: 10px 20px 10px 0;
7861: overflow:hidden;
1.693 droeschl 7862: }
1.721 harmsja 7863:
1.795 www 7864: table em {
1.911 bisitz 7865: font-weight: bold;
7866: font-style: normal;
1.748 schulted 7867: }
1.795 www 7868:
1.779 bisitz 7869: table.LC_tableBrowseRes,
1.795 www 7870: table.LC_tableOfContent {
1.911 bisitz 7871: border:none;
7872: border-spacing: 1px;
7873: padding: 3px;
7874: background-color: #FFFFFF;
7875: font-size: 90%;
1.753 droeschl 7876: }
1.789 droeschl 7877:
1.911 bisitz 7878: table.LC_tableOfContent {
7879: border-collapse: collapse;
1.789 droeschl 7880: }
7881:
1.771 droeschl 7882: table.LC_tableBrowseRes a,
1.768 schulted 7883: table.LC_tableOfContent a {
1.911 bisitz 7884: background-color: transparent;
7885: text-decoration: none;
1.753 droeschl 7886: }
7887:
1.795 www 7888: table.LC_tableOfContent img {
1.911 bisitz 7889: border: none;
7890: height: 1.3em;
7891: vertical-align: text-bottom;
7892: margin-right: 0.3em;
1.753 droeschl 7893: }
1.757 schulted 7894:
1.795 www 7895: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7896: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7897: }
7898:
1.795 www 7899: a#LC_content_toolbar_everything {
1.911 bisitz 7900: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7901: }
7902:
1.795 www 7903: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7904: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7905: }
7906:
1.795 www 7907: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7908: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7909: }
7910:
1.795 www 7911: a#LC_content_toolbar_changefolder {
1.911 bisitz 7912: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7913: }
7914:
1.795 www 7915: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7916: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7917: }
7918:
1.1043 raeburn 7919: a#LC_content_toolbar_edittoplevel {
7920: background-image:url(/res/adm/pages/edittoplevel.gif);
7921: }
7922:
1.795 www 7923: ul#LC_toolbar li a:hover {
1.911 bisitz 7924: background-position: bottom center;
1.757 schulted 7925: }
7926:
1.795 www 7927: ul#LC_toolbar {
1.911 bisitz 7928: padding: 0;
7929: margin: 2px;
7930: list-style:none;
7931: position:relative;
7932: background-color:white;
1.1082 raeburn 7933: overflow: auto;
1.757 schulted 7934: }
7935:
1.795 www 7936: ul#LC_toolbar li {
1.911 bisitz 7937: border:1px solid white;
7938: padding: 0;
7939: margin: 0;
7940: float: left;
7941: display:inline;
7942: vertical-align:middle;
1.1082 raeburn 7943: white-space: nowrap;
1.911 bisitz 7944: }
1.757 schulted 7945:
1.783 amueller 7946:
1.795 www 7947: a.LC_toolbarItem {
1.911 bisitz 7948: display:block;
7949: padding: 0;
7950: margin: 0;
7951: height: 32px;
7952: width: 32px;
7953: color:white;
7954: border: none;
7955: background-repeat:no-repeat;
7956: background-color:transparent;
1.757 schulted 7957: }
7958:
1.915 droeschl 7959: ul.LC_funclist {
7960: margin: 0;
7961: padding: 0.5em 1em 0.5em 0;
7962: }
7963:
1.933 droeschl 7964: ul.LC_funclist > li:first-child {
7965: font-weight:bold;
7966: margin-left:0.8em;
7967: }
7968:
1.915 droeschl 7969: ul.LC_funclist + ul.LC_funclist {
7970: /*
7971: left border as a seperator if we have more than
7972: one list
7973: */
7974: border-left: 1px solid $sidebg;
7975: /*
7976: this hides the left border behind the border of the
7977: outer box if element is wrapped to the next 'line'
7978: */
7979: margin-left: -1px;
7980: }
7981:
1.843 bisitz 7982: ul.LC_funclist li {
1.915 droeschl 7983: display: inline;
1.782 bisitz 7984: white-space: nowrap;
1.915 droeschl 7985: margin: 0 0 0 25px;
7986: line-height: 150%;
1.782 bisitz 7987: }
7988:
1.974 wenzelju 7989: .LC_hidden {
7990: display: none;
7991: }
7992:
1.1030 www 7993: .LCmodal-overlay {
7994: position:fixed;
7995: top:0;
7996: right:0;
7997: bottom:0;
7998: left:0;
7999: height:100%;
8000: width:100%;
8001: margin:0;
8002: padding:0;
8003: background:#999;
8004: opacity:.75;
8005: filter: alpha(opacity=75);
8006: -moz-opacity: 0.75;
8007: z-index:101;
8008: }
8009:
8010: * html .LCmodal-overlay {
8011: position: absolute;
8012: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8013: }
8014:
8015: .LCmodal-window {
8016: position:fixed;
8017: top:50%;
8018: left:50%;
8019: margin:0;
8020: padding:0;
8021: z-index:102;
8022: }
8023:
8024: * html .LCmodal-window {
8025: position:absolute;
8026: }
8027:
8028: .LCclose-window {
8029: position:absolute;
8030: width:32px;
8031: height:32px;
8032: right:8px;
8033: top:8px;
8034: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8035: text-indent:-99999px;
8036: overflow:hidden;
8037: cursor:pointer;
8038: }
8039:
1.1100 raeburn 8040: /*
1.1231 damieng 8041: styles used for response display
8042: */
8043: div.LC_radiofoil, div.LC_rankfoil {
8044: margin: .5em 0em .5em 0em;
8045: }
8046: table.LC_itemgroup {
8047: margin-top: 1em;
8048: }
8049:
8050: /*
1.1100 raeburn 8051: styles used by TTH when "Default set of options to pass to tth/m
8052: when converting TeX" in course settings has been set
8053:
8054: option passed: -t
8055:
8056: */
8057:
8058: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8059: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8060: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8061: td div.norm {line-height:normal;}
8062:
8063: /*
8064: option passed -y3
8065: */
8066:
8067: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8068: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8069: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8070:
1.1230 damieng 8071: /*
8072: sections with roles, for content only
8073: */
8074: section[class^="role-"] {
8075: padding-left: 10px;
8076: padding-right: 5px;
8077: margin-top: 8px;
8078: margin-bottom: 8px;
8079: border: 1px solid #2A4;
8080: border-radius: 5px;
8081: box-shadow: 0px 1px 1px #BBB;
8082: }
8083: section[class^="role-"]>h1 {
8084: position: relative;
8085: margin: 0px;
8086: padding-top: 10px;
8087: padding-left: 40px;
8088: }
8089: section[class^="role-"]>h1:before {
8090: position: absolute;
8091: left: -5px;
8092: top: 5px;
8093: }
8094: section.role-activity>h1:before {
8095: content:url('/adm/daxe/images/section_icons/activity.png');
8096: }
8097: section.role-advice>h1:before {
8098: content:url('/adm/daxe/images/section_icons/advice.png');
8099: }
8100: section.role-bibliography>h1:before {
8101: content:url('/adm/daxe/images/section_icons/bibliography.png');
8102: }
8103: section.role-citation>h1:before {
8104: content:url('/adm/daxe/images/section_icons/citation.png');
8105: }
8106: section.role-conclusion>h1:before {
8107: content:url('/adm/daxe/images/section_icons/conclusion.png');
8108: }
8109: section.role-definition>h1:before {
8110: content:url('/adm/daxe/images/section_icons/definition.png');
8111: }
8112: section.role-demonstration>h1:before {
8113: content:url('/adm/daxe/images/section_icons/demonstration.png');
8114: }
8115: section.role-example>h1:before {
8116: content:url('/adm/daxe/images/section_icons/example.png');
8117: }
8118: section.role-explanation>h1:before {
8119: content:url('/adm/daxe/images/section_icons/explanation.png');
8120: }
8121: section.role-introduction>h1:before {
8122: content:url('/adm/daxe/images/section_icons/introduction.png');
8123: }
8124: section.role-method>h1:before {
8125: content:url('/adm/daxe/images/section_icons/method.png');
8126: }
8127: section.role-more_information>h1:before {
8128: content:url('/adm/daxe/images/section_icons/more_information.png');
8129: }
8130: section.role-objectives>h1:before {
8131: content:url('/adm/daxe/images/section_icons/objectives.png');
8132: }
8133: section.role-prerequisites>h1:before {
8134: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8135: }
8136: section.role-remark>h1:before {
8137: content:url('/adm/daxe/images/section_icons/remark.png');
8138: }
8139: section.role-reminder>h1:before {
8140: content:url('/adm/daxe/images/section_icons/reminder.png');
8141: }
8142: section.role-summary>h1:before {
8143: content:url('/adm/daxe/images/section_icons/summary.png');
8144: }
8145: section.role-syntax>h1:before {
8146: content:url('/adm/daxe/images/section_icons/syntax.png');
8147: }
8148: section.role-warning>h1:before {
8149: content:url('/adm/daxe/images/section_icons/warning.png');
8150: }
8151:
1.1269 raeburn 8152: #LC_minitab_header {
8153: float:left;
8154: width:100%;
8155: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8156: font-size:93%;
8157: line-height:normal;
8158: margin: 0.5em 0 0.5em 0;
8159: }
8160: #LC_minitab_header ul {
8161: margin:0;
8162: padding:10px 10px 0;
8163: list-style:none;
8164: }
8165: #LC_minitab_header li {
8166: float:left;
8167: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8168: margin:0;
8169: padding:0 0 0 9px;
8170: }
8171: #LC_minitab_header a {
8172: display:block;
8173: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8174: padding:5px 15px 4px 6px;
8175: }
8176: #LC_minitab_header #LC_current_minitab {
8177: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8178: }
8179: #LC_minitab_header #LC_current_minitab a {
8180: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8181: padding-bottom:5px;
8182: }
8183:
8184:
1.343 albertel 8185: END
8186: }
8187:
1.306 albertel 8188: =pod
8189:
8190: =item * &headtag()
8191:
8192: Returns a uniform footer for LON-CAPA web pages.
8193:
1.307 albertel 8194: Inputs: $title - optional title for the head
8195: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8196: $args - optional arguments
1.319 albertel 8197: force_register - if is true call registerurl so the remote is
8198: informed
1.415 albertel 8199: redirect -> array ref of
8200: 1- seconds before redirect occurs
8201: 2- url to redirect to
8202: 3- whether the side effect should occur
1.315 albertel 8203: (side effect of setting
8204: $env{'internal.head.redirect'} to the url
8205: redirected too)
1.352 albertel 8206: domain -> force to color decorate a page for a specific
8207: domain
8208: function -> force usage of a specific rolish color scheme
8209: bgcolor -> override the default page bgcolor
1.460 albertel 8210: no_auto_mt_title
8211: -> prevent &mt()ing the title arg
1.464 albertel 8212:
1.306 albertel 8213: =cut
8214:
8215: sub headtag {
1.313 albertel 8216: my ($title,$head_extra,$args) = @_;
1.306 albertel 8217:
1.363 albertel 8218: my $function = $args->{'function'} || &get_users_function();
8219: my $domain = $args->{'domain'} || &determinedomain();
8220: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8221: my $httphost = $args->{'use_absolute'};
1.418 albertel 8222: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8223: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8224: #time(),
1.418 albertel 8225: $env{'environment.color.timestamp'},
1.363 albertel 8226: $function,$domain,$bgcolor);
8227:
1.369 www 8228: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8229:
1.308 albertel 8230: my $result =
8231: '<head>'.
1.1160 raeburn 8232: &font_settings($args);
1.319 albertel 8233:
1.1188 raeburn 8234: my $inhibitprint;
8235: if ($args->{'print_suppress'}) {
8236: $inhibitprint = &print_suppression();
8237: }
1.1064 raeburn 8238:
1.461 albertel 8239: if (!$args->{'frameset'}) {
8240: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8241: }
1.962 droeschl 8242: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8243: $result .= Apache::lonxml::display_title();
1.319 albertel 8244: }
1.436 albertel 8245: if (!$args->{'no_nav_bar'}
8246: && !$args->{'only_body'}
8247: && !$args->{'frameset'}) {
1.1154 raeburn 8248: $result .= &help_menu_js($httphost);
1.1032 www 8249: $result.=&modal_window();
1.1038 www 8250: $result.=&togglebox_script();
1.1034 www 8251: $result.=&wishlist_window();
1.1041 www 8252: $result.=&LCprogressbarUpdate_script();
1.1034 www 8253: } else {
8254: if ($args->{'add_modal'}) {
8255: $result.=&modal_window();
8256: }
8257: if ($args->{'add_wishlist'}) {
8258: $result.=&wishlist_window();
8259: }
1.1038 www 8260: if ($args->{'add_togglebox'}) {
8261: $result.=&togglebox_script();
8262: }
1.1041 www 8263: if ($args->{'add_progressbar'}) {
8264: $result.=&LCprogressbarUpdate_script();
8265: }
1.436 albertel 8266: }
1.314 albertel 8267: if (ref($args->{'redirect'})) {
1.414 albertel 8268: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8269: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8270: if (!$inhibit_continue) {
8271: $env{'internal.head.redirect'} = $url;
8272: }
1.313 albertel 8273: $result.=<<ADDMETA
8274: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8275: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8276: ADDMETA
1.1210 raeburn 8277: } else {
8278: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8279: my $requrl = $env{'request.uri'};
8280: if ($requrl eq '') {
8281: $requrl = $ENV{'REQUEST_URI'};
8282: $requrl =~ s/\?.+$//;
8283: }
8284: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8285: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8286: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8287: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8288: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8289: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
8290: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8291: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8292: if ($domdefs{'offloadnow'}{$lonhost}) {
8293: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8294: if (($newserver) && ($newserver ne $lonhost)) {
8295: my $numsec = 5;
8296: my $timeout = $numsec * 1000;
8297: my ($newurl,$locknum,%locks,$msg);
8298: if ($env{'request.role.adv'}) {
8299: ($locknum,%locks) = &Apache::lonnet::get_locks();
8300: }
8301: my $disable_submit = 0;
8302: if ($requrl =~ /$LONCAPA::assess_re/) {
8303: $disable_submit = 1;
8304: }
8305: if ($locknum) {
8306: my @lockinfo = sort(values(%locks));
8307: $msg = &mt('Once the following tasks are complete: ')."\\n".
8308: join(", ",sort(values(%locks)))."\\n".
8309: &mt('your session will be transferred to a different server, after you click "Roles".');
8310: } else {
8311: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8312: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
8313: }
8314: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8315: $newurl = '/adm/switchserver?otherserver='.$newserver;
8316: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8317: $newurl .= '&role='.$env{'request.role'};
8318: }
8319: if ($env{'request.symb'}) {
8320: $newurl .= '&symb='.$env{'request.symb'};
8321: } else {
8322: $newurl .= '&origurl='.$requrl;
8323: }
8324: }
1.1222 damieng 8325: &js_escape(\$msg);
1.1210 raeburn 8326: $result.=<<OFFLOAD
8327: <meta http-equiv="pragma" content="no-cache" />
8328: <script type="text/javascript">
1.1215 raeburn 8329: // <![CDATA[
1.1210 raeburn 8330: function LC_Offload_Now() {
8331: var dest = "$newurl";
8332: if (dest != '') {
8333: window.location.href="$newurl";
8334: }
8335: }
1.1214 raeburn 8336: \$(document).ready(function () {
8337: window.alert('$msg');
8338: if ($disable_submit) {
1.1210 raeburn 8339: \$(".LC_hwk_submit").prop("disabled", true);
8340: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8341: }
8342: setTimeout('LC_Offload_Now()', $timeout);
8343: });
1.1215 raeburn 8344: // ]]>
1.1210 raeburn 8345: </script>
8346: OFFLOAD
8347: }
8348: }
8349: }
8350: }
8351: }
8352: }
1.313 albertel 8353: }
1.306 albertel 8354: if (!defined($title)) {
8355: $title = 'The LearningOnline Network with CAPA';
8356: }
1.460 albertel 8357: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8358: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8359: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8360: if (!$args->{'frameset'}) {
8361: $result .= ' /';
8362: }
8363: $result .= '>'
1.1064 raeburn 8364: .$inhibitprint
1.414 albertel 8365: .$head_extra;
1.1242 raeburn 8366: my $clientmobile;
8367: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8368: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8369: } else {
8370: $clientmobile = $env{'browser.mobile'};
8371: }
8372: if ($clientmobile) {
1.1137 raeburn 8373: $result .= '
8374: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8375: <meta name="apple-mobile-web-app-capable" content="yes" />';
8376: }
1.1278 raeburn 8377: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8378: return $result.'</head>';
1.306 albertel 8379: }
8380:
8381: =pod
8382:
1.340 albertel 8383: =item * &font_settings()
8384:
8385: Returns neccessary <meta> to set the proper encoding
8386:
1.1160 raeburn 8387: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8388:
8389: =cut
8390:
8391: sub font_settings {
1.1160 raeburn 8392: my ($args) = @_;
1.340 albertel 8393: my $headerstring='';
1.1160 raeburn 8394: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8395: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8396: $headerstring.=
8397: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8398: if (!$args->{'frameset'}) {
8399: $headerstring.= ' /';
8400: }
8401: $headerstring .= '>'."\n";
1.340 albertel 8402: }
8403: return $headerstring;
8404: }
8405:
1.341 albertel 8406: =pod
8407:
1.1064 raeburn 8408: =item * &print_suppression()
8409:
8410: In course context returns css which causes the body to be blank when media="print",
8411: if printout generation is unavailable for the current resource.
8412:
8413: This could be because:
8414:
8415: (a) printstartdate is in the future
8416:
8417: (b) printenddate is in the past
8418:
8419: (c) there is an active exam block with "printout"
8420: functionality blocked
8421:
8422: Users with pav, pfo or evb privileges are exempt.
8423:
8424: Inputs: none
8425:
8426: =cut
8427:
8428:
8429: sub print_suppression {
8430: my $noprint;
8431: if ($env{'request.course.id'}) {
8432: my $scope = $env{'request.course.id'};
8433: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8434: (&Apache::lonnet::allowed('pfo',$scope))) {
8435: return;
8436: }
8437: if ($env{'request.course.sec'} ne '') {
8438: $scope .= "/$env{'request.course.sec'}";
8439: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8440: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8441: return;
1.1064 raeburn 8442: }
8443: }
8444: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8445: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8446: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8447: if ($blocked) {
8448: my $checkrole = "cm./$cdom/$cnum";
8449: if ($env{'request.course.sec'} ne '') {
8450: $checkrole .= "/$env{'request.course.sec'}";
8451: }
8452: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8453: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8454: $noprint = 1;
8455: }
8456: }
8457: unless ($noprint) {
8458: my $symb = &Apache::lonnet::symbread();
8459: if ($symb ne '') {
8460: my $navmap = Apache::lonnavmaps::navmap->new();
8461: if (ref($navmap)) {
8462: my $res = $navmap->getBySymb($symb);
8463: if (ref($res)) {
8464: if (!$res->resprintable()) {
8465: $noprint = 1;
8466: }
8467: }
8468: }
8469: }
8470: }
8471: if ($noprint) {
8472: return <<"ENDSTYLE";
8473: <style type="text/css" media="print">
8474: body { display:none }
8475: </style>
8476: ENDSTYLE
8477: }
8478: }
8479: return;
8480: }
8481:
8482: =pod
8483:
1.341 albertel 8484: =item * &xml_begin()
8485:
8486: Returns the needed doctype and <html>
8487:
8488: Inputs: none
8489:
8490: =cut
8491:
8492: sub xml_begin {
1.1168 raeburn 8493: my ($is_frameset) = @_;
1.341 albertel 8494: my $output='';
8495:
8496: if ($env{'browser.mathml'}) {
8497: $output='<?xml version="1.0"?>'
8498: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8499: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8500:
8501: # .'<!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">] >'
8502: .'<!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">'
8503: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8504: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8505: } elsif ($is_frameset) {
8506: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8507: '<html>'."\n";
1.341 albertel 8508: } else {
1.1168 raeburn 8509: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8510: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8511: }
8512: return $output;
8513: }
1.340 albertel 8514:
8515: =pod
8516:
1.306 albertel 8517: =item * &start_page()
8518:
8519: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8520:
1.648 raeburn 8521: Inputs:
8522:
8523: =over 4
8524:
8525: $title - optional title for the page
8526:
8527: $head_extra - optional extra HTML to incude inside the <head>
8528:
8529: $args - additional optional args supported are:
8530:
8531: =over 8
8532:
8533: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8534: arg on
1.814 bisitz 8535: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8536: add_entries -> additional attributes to add to the <body>
8537: domain -> force to color decorate a page for a
1.317 albertel 8538: specific domain
1.648 raeburn 8539: function -> force usage of a specific rolish color
1.317 albertel 8540: scheme
1.648 raeburn 8541: redirect -> see &headtag()
8542: bgcolor -> override the default page bg color
8543: js_ready -> return a string ready for being used in
1.317 albertel 8544: a javascript writeln
1.648 raeburn 8545: html_encode -> return a string ready for being used in
1.320 albertel 8546: a html attribute
1.648 raeburn 8547: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8548: $forcereg arg
1.648 raeburn 8549: frameset -> if true will start with a <frameset>
1.330 albertel 8550: rather than <body>
1.648 raeburn 8551: skip_phases -> hash ref of
1.338 albertel 8552: head -> skip the <html><head> generation
8553: body -> skip all <body> generation
1.648 raeburn 8554: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8555: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8556: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8557: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8558: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8559: group -> includes the current group, if page is for a
1.1274 raeburn 8560: specific group
8561: use_absolute -> for request for external resource or syllabus, this
8562: will contain https://<hostname> if server uses
8563: https (as per hosts.tab), but request is for http
8564: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8565:
1.648 raeburn 8566: =back
1.460 albertel 8567:
1.648 raeburn 8568: =back
1.562 albertel 8569:
1.306 albertel 8570: =cut
8571:
8572: sub start_page {
1.309 albertel 8573: my ($title,$head_extra,$args) = @_;
1.318 albertel 8574: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8575:
1.315 albertel 8576: $env{'internal.start_page'}++;
1.1096 raeburn 8577: my ($result,@advtools);
1.964 droeschl 8578:
1.338 albertel 8579: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8580: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8581: }
8582:
8583: if (! exists($args->{'skip_phases'}{'body'}) ) {
8584: if ($args->{'frameset'}) {
8585: my $attr_string = &make_attr_string($args->{'force_register'},
8586: $args->{'add_entries'});
8587: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8588: } else {
8589: $result .=
8590: &bodytag($title,
8591: $args->{'function'}, $args->{'add_entries'},
8592: $args->{'only_body'}, $args->{'domain'},
8593: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8594: $args->{'bgcolor'}, $args,
8595: \@advtools);
1.831 bisitz 8596: }
1.330 albertel 8597: }
1.338 albertel 8598:
1.315 albertel 8599: if ($args->{'js_ready'}) {
1.713 kaisler 8600: $result = &js_ready($result);
1.315 albertel 8601: }
1.320 albertel 8602: if ($args->{'html_encode'}) {
1.713 kaisler 8603: $result = &html_encode($result);
8604: }
8605:
1.813 bisitz 8606: # Preparation for new and consistent functionlist at top of screen
8607: # if ($args->{'functionlist'}) {
8608: # $result .= &build_functionlist();
8609: #}
8610:
1.964 droeschl 8611: # Don't add anything more if only_body wanted or in const space
8612: return $result if $args->{'only_body'}
8613: || $env{'request.state'} eq 'construct';
1.813 bisitz 8614:
8615: #Breadcrumbs
1.758 kaisler 8616: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8617: &Apache::lonhtmlcommon::clear_breadcrumbs();
8618: #if any br links exists, add them to the breadcrumbs
8619: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8620: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8621: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8622: }
8623: }
1.1096 raeburn 8624: # if @advtools array contains items add then to the breadcrumbs
8625: if (@advtools > 0) {
8626: &Apache::lonmenu::advtools_crumbs(@advtools);
8627: }
1.1272 raeburn 8628: my $menulink;
8629: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8630: if ((exists($args->{'bread_crumbs_nomenu'})) ||
8631: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
8632: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
8633: (!$env{'request.role.adv'}))) {
8634: $menulink = 0;
8635: } else {
8636: undef($menulink);
8637: }
1.758 kaisler 8638: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8639: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 8640: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 8641: } else {
1.1272 raeburn 8642: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8643: }
1.320 albertel 8644: }
1.315 albertel 8645: return $result;
1.306 albertel 8646: }
8647:
8648: sub end_page {
1.315 albertel 8649: my ($args) = @_;
8650: $env{'internal.end_page'}++;
1.330 albertel 8651: my $result;
1.335 albertel 8652: if ($args->{'discussion'}) {
8653: my ($target,$parser);
8654: if (ref($args->{'discussion'})) {
8655: ($target,$parser) =($args->{'discussion'}{'target'},
8656: $args->{'discussion'}{'parser'});
8657: }
8658: $result .= &Apache::lonxml::xmlend($target,$parser);
8659: }
1.330 albertel 8660: if ($args->{'frameset'}) {
8661: $result .= '</frameset>';
8662: } else {
1.635 raeburn 8663: $result .= &endbodytag($args);
1.330 albertel 8664: }
1.1080 raeburn 8665: unless ($args->{'notbody'}) {
8666: $result .= "\n</html>";
8667: }
1.330 albertel 8668:
1.315 albertel 8669: if ($args->{'js_ready'}) {
1.317 albertel 8670: $result = &js_ready($result);
1.315 albertel 8671: }
1.335 albertel 8672:
1.320 albertel 8673: if ($args->{'html_encode'}) {
8674: $result = &html_encode($result);
8675: }
1.335 albertel 8676:
1.315 albertel 8677: return $result;
8678: }
8679:
1.1034 www 8680: sub wishlist_window {
8681: return(<<'ENDWISHLIST');
1.1046 raeburn 8682: <script type="text/javascript">
1.1034 www 8683: // <![CDATA[
8684: // <!-- BEGIN LON-CAPA Internal
8685: function set_wishlistlink(title, path) {
8686: if (!title) {
8687: title = document.title;
8688: title = title.replace(/^LON-CAPA /,'');
8689: }
1.1175 raeburn 8690: title = encodeURIComponent(title);
1.1203 raeburn 8691: title = title.replace("'","\\\'");
1.1034 www 8692: if (!path) {
8693: path = location.pathname;
8694: }
1.1175 raeburn 8695: path = encodeURIComponent(path);
1.1203 raeburn 8696: path = path.replace("'","\\\'");
1.1034 www 8697: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8698: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8699: }
8700: // END LON-CAPA Internal -->
8701: // ]]>
8702: </script>
8703: ENDWISHLIST
8704: }
8705:
1.1030 www 8706: sub modal_window {
8707: return(<<'ENDMODAL');
1.1046 raeburn 8708: <script type="text/javascript">
1.1030 www 8709: // <![CDATA[
8710: // <!-- BEGIN LON-CAPA Internal
8711: var modalWindow = {
8712: parent:"body",
8713: windowId:null,
8714: content:null,
8715: width:null,
8716: height:null,
8717: close:function()
8718: {
8719: $(".LCmodal-window").remove();
8720: $(".LCmodal-overlay").remove();
8721: },
8722: open:function()
8723: {
8724: var modal = "";
8725: modal += "<div class=\"LCmodal-overlay\"></div>";
8726: 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;\">";
8727: modal += this.content;
8728: modal += "</div>";
8729:
8730: $(this.parent).append(modal);
8731:
8732: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8733: $(".LCclose-window").click(function(){modalWindow.close();});
8734: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8735: }
8736: };
1.1140 raeburn 8737: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8738: {
1.1266 raeburn 8739: source = source.replace(/'/g,"'");
1.1030 www 8740: modalWindow.windowId = "myModal";
8741: modalWindow.width = width;
8742: modalWindow.height = height;
1.1196 raeburn 8743: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8744: modalWindow.open();
1.1208 raeburn 8745: };
1.1030 www 8746: // END LON-CAPA Internal -->
8747: // ]]>
8748: </script>
8749: ENDMODAL
8750: }
8751:
8752: sub modal_link {
1.1140 raeburn 8753: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8754: unless ($width) { $width=480; }
8755: unless ($height) { $height=400; }
1.1031 www 8756: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8757: unless ($transparency) { $transparency='true'; }
8758:
1.1074 raeburn 8759: my $target_attr;
8760: if (defined($target)) {
8761: $target_attr = 'target="'.$target.'"';
8762: }
8763: return <<"ENDLINK";
1.1140 raeburn 8764: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8765: $linktext</a>
8766: ENDLINK
1.1030 www 8767: }
8768:
1.1032 www 8769: sub modal_adhoc_script {
8770: my ($funcname,$width,$height,$content)=@_;
8771: return (<<ENDADHOC);
1.1046 raeburn 8772: <script type="text/javascript">
1.1032 www 8773: // <![CDATA[
8774: var $funcname = function()
8775: {
8776: modalWindow.windowId = "myModal";
8777: modalWindow.width = $width;
8778: modalWindow.height = $height;
8779: modalWindow.content = '$content';
8780: modalWindow.open();
8781: };
8782: // ]]>
8783: </script>
8784: ENDADHOC
8785: }
8786:
1.1041 www 8787: sub modal_adhoc_inner {
8788: my ($funcname,$width,$height,$content)=@_;
8789: my $innerwidth=$width-20;
8790: $content=&js_ready(
1.1140 raeburn 8791: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8792: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8793: $content.
1.1041 www 8794: &end_scrollbox().
1.1140 raeburn 8795: &end_page()
1.1041 www 8796: );
8797: return &modal_adhoc_script($funcname,$width,$height,$content);
8798: }
8799:
8800: sub modal_adhoc_window {
8801: my ($funcname,$width,$height,$content,$linktext)=@_;
8802: return &modal_adhoc_inner($funcname,$width,$height,$content).
8803: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8804: }
8805:
8806: sub modal_adhoc_launch {
8807: my ($funcname,$width,$height,$content)=@_;
8808: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8809: <script type="text/javascript">
8810: // <![CDATA[
8811: $funcname();
8812: // ]]>
8813: </script>
8814: ENDLAUNCH
8815: }
8816:
8817: sub modal_adhoc_close {
8818: return (<<ENDCLOSE);
8819: <script type="text/javascript">
8820: // <![CDATA[
8821: modalWindow.close();
8822: // ]]>
8823: </script>
8824: ENDCLOSE
8825: }
8826:
1.1038 www 8827: sub togglebox_script {
8828: return(<<ENDTOGGLE);
8829: <script type="text/javascript">
8830: // <![CDATA[
8831: function LCtoggleDisplay(id,hidetext,showtext) {
8832: link = document.getElementById(id + "link").childNodes[0];
8833: with (document.getElementById(id).style) {
8834: if (display == "none" ) {
8835: display = "inline";
8836: link.nodeValue = hidetext;
8837: } else {
8838: display = "none";
8839: link.nodeValue = showtext;
8840: }
8841: }
8842: }
8843: // ]]>
8844: </script>
8845: ENDTOGGLE
8846: }
8847:
1.1039 www 8848: sub start_togglebox {
8849: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8850: unless ($heading) { $heading=''; } else { $heading.=' '; }
8851: unless ($showtext) { $showtext=&mt('show'); }
8852: unless ($hidetext) { $hidetext=&mt('hide'); }
8853: unless ($headerbg) { $headerbg='#FFFFFF'; }
8854: return &start_data_table().
8855: &start_data_table_header_row().
8856: '<td bgcolor="'.$headerbg.'">'.$heading.
8857: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8858: $showtext.'\')">'.$showtext.'</a>]</td>'.
8859: &end_data_table_header_row().
8860: '<tr id="'.$id.'" style="display:none""><td>';
8861: }
8862:
8863: sub end_togglebox {
8864: return '</td></tr>'.&end_data_table();
8865: }
8866:
1.1041 www 8867: sub LCprogressbar_script {
1.1045 www 8868: my ($id)=@_;
1.1041 www 8869: return(<<ENDPROGRESS);
8870: <script type="text/javascript">
8871: // <![CDATA[
1.1045 www 8872: \$('#progressbar$id').progressbar({
1.1041 www 8873: value: 0,
8874: change: function(event, ui) {
8875: var newVal = \$(this).progressbar('option', 'value');
8876: \$('.pblabel', this).text(LCprogressTxt);
8877: }
8878: });
8879: // ]]>
8880: </script>
8881: ENDPROGRESS
8882: }
8883:
8884: sub LCprogressbarUpdate_script {
8885: return(<<ENDPROGRESSUPDATE);
8886: <style type="text/css">
8887: .ui-progressbar { position:relative; }
8888: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8889: </style>
8890: <script type="text/javascript">
8891: // <![CDATA[
1.1045 www 8892: var LCprogressTxt='---';
8893:
8894: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8895: LCprogressTxt=progresstext;
1.1045 www 8896: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8897: }
8898: // ]]>
8899: </script>
8900: ENDPROGRESSUPDATE
8901: }
8902:
1.1042 www 8903: my $LClastpercent;
1.1045 www 8904: my $LCidcnt;
8905: my $LCcurrentid;
1.1042 www 8906:
1.1041 www 8907: sub LCprogressbar {
1.1042 www 8908: my ($r)=(@_);
8909: $LClastpercent=0;
1.1045 www 8910: $LCidcnt++;
8911: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8912: my $starting=&mt('Starting');
8913: my $content=(<<ENDPROGBAR);
1.1045 www 8914: <div id="progressbar$LCcurrentid">
1.1041 www 8915: <span class="pblabel">$starting</span>
8916: </div>
8917: ENDPROGBAR
1.1045 www 8918: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8919: }
8920:
8921: sub LCprogressbarUpdate {
1.1042 www 8922: my ($r,$val,$text)=@_;
8923: unless ($val) {
8924: if ($LClastpercent) {
8925: $val=$LClastpercent;
8926: } else {
8927: $val=0;
8928: }
8929: }
1.1041 www 8930: if ($val<0) { $val=0; }
8931: if ($val>100) { $val=0; }
1.1042 www 8932: $LClastpercent=$val;
1.1041 www 8933: unless ($text) { $text=$val.'%'; }
8934: $text=&js_ready($text);
1.1044 www 8935: &r_print($r,<<ENDUPDATE);
1.1041 www 8936: <script type="text/javascript">
8937: // <![CDATA[
1.1045 www 8938: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8939: // ]]>
8940: </script>
8941: ENDUPDATE
1.1035 www 8942: }
8943:
1.1042 www 8944: sub LCprogressbarClose {
8945: my ($r)=@_;
8946: $LClastpercent=0;
1.1044 www 8947: &r_print($r,<<ENDCLOSE);
1.1042 www 8948: <script type="text/javascript">
8949: // <![CDATA[
1.1045 www 8950: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8951: // ]]>
8952: </script>
8953: ENDCLOSE
1.1044 www 8954: }
8955:
8956: sub r_print {
8957: my ($r,$to_print)=@_;
8958: if ($r) {
8959: $r->print($to_print);
8960: $r->rflush();
8961: } else {
8962: print($to_print);
8963: }
1.1042 www 8964: }
8965:
1.320 albertel 8966: sub html_encode {
8967: my ($result) = @_;
8968:
1.322 albertel 8969: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8970:
8971: return $result;
8972: }
1.1044 www 8973:
1.317 albertel 8974: sub js_ready {
8975: my ($result) = @_;
8976:
1.323 albertel 8977: $result =~ s/[\n\r]/ /xmsg;
8978: $result =~ s/\\/\\\\/xmsg;
8979: $result =~ s/'/\\'/xmsg;
1.372 albertel 8980: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8981:
8982: return $result;
8983: }
8984:
1.315 albertel 8985: sub validate_page {
8986: if ( exists($env{'internal.start_page'})
1.316 albertel 8987: && $env{'internal.start_page'} > 1) {
8988: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8989: $env{'internal.start_page'}.' '.
1.316 albertel 8990: $ENV{'request.filename'});
1.315 albertel 8991: }
8992: if ( exists($env{'internal.end_page'})
1.316 albertel 8993: && $env{'internal.end_page'} > 1) {
8994: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8995: $env{'internal.end_page'}.' '.
1.316 albertel 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('start_page called without end_page '.
9001: $env{'request.filename'});
1.315 albertel 9002: }
9003: if ( ! exists($env{'internal.start_page'})
9004: && exists($env{'internal.end_page'})) {
1.316 albertel 9005: &Apache::lonnet::logthis('end_page called without start_page'.
9006: $env{'request.filename'});
1.315 albertel 9007: }
1.306 albertel 9008: }
1.315 albertel 9009:
1.996 www 9010:
9011: sub start_scrollbox {
1.1140 raeburn 9012: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9013: unless ($outerwidth) { $outerwidth='520px'; }
9014: unless ($width) { $width='500px'; }
9015: unless ($height) { $height='200px'; }
1.1075 raeburn 9016: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9017: if ($id ne '') {
1.1140 raeburn 9018: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9019: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9020: }
1.1075 raeburn 9021: if ($bgcolor ne '') {
9022: $tdcol = "background-color: $bgcolor;";
9023: }
1.1137 raeburn 9024: my $nicescroll_js;
9025: if ($env{'browser.mobile'}) {
1.1140 raeburn 9026: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9027: }
9028: return <<"END";
9029: $nicescroll_js
9030:
9031: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9032: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9033: END
9034: }
9035:
9036: sub end_scrollbox {
9037: return '</div></td></tr></table>';
9038: }
9039:
9040: sub nicescroll_javascript {
9041: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9042: my %options;
9043: if (ref($cursor) eq 'HASH') {
9044: %options = %{$cursor};
9045: }
9046: unless ($options{'railalign'} =~ /^left|right$/) {
9047: $options{'railalign'} = 'left';
9048: }
9049: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9050: my $function = &get_users_function();
9051: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9052: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9053: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9054: }
1.1140 raeburn 9055: }
9056: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9057: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9058: $options{'cursoropacity'}='1.0';
9059: }
1.1140 raeburn 9060: } else {
9061: $options{'cursoropacity'}='1.0';
9062: }
9063: if ($options{'cursorfixedheight'} eq 'none') {
9064: delete($options{'cursorfixedheight'});
9065: } else {
9066: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9067: }
9068: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9069: delete($options{'railoffset'});
9070: }
9071: my @niceoptions;
9072: while (my($key,$value) = each(%options)) {
9073: if ($value =~ /^\{.+\}$/) {
9074: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9075: } else {
1.1140 raeburn 9076: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9077: }
1.1140 raeburn 9078: }
9079: my $nicescroll_js = '
1.1137 raeburn 9080: $(document).ready(
1.1140 raeburn 9081: function() {
9082: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9083: }
1.1137 raeburn 9084: );
9085: ';
1.1140 raeburn 9086: if ($framecheck) {
9087: $nicescroll_js .= '
9088: function expand_div(caller) {
9089: if (top === self) {
9090: document.getElementById("'.$id.'").style.width = "auto";
9091: document.getElementById("'.$id.'").style.height = "auto";
9092: } else {
9093: try {
9094: if (parent.frames) {
9095: if (parent.frames.length > 1) {
9096: var framesrc = parent.frames[1].location.href;
9097: var currsrc = framesrc.replace(/\#.*$/,"");
9098: if ((caller == "search") || (currsrc == "'.$location.'")) {
9099: document.getElementById("'.$id.'").style.width = "auto";
9100: document.getElementById("'.$id.'").style.height = "auto";
9101: }
9102: }
9103: }
9104: } catch (e) {
9105: return;
9106: }
1.1137 raeburn 9107: }
1.1140 raeburn 9108: return;
1.996 www 9109: }
1.1140 raeburn 9110: ';
9111: }
9112: if ($needjsready) {
9113: $nicescroll_js = '
9114: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9115: } else {
9116: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9117: }
9118: return $nicescroll_js;
1.996 www 9119: }
9120:
1.318 albertel 9121: sub simple_error_page {
1.1150 bisitz 9122: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 9123: if (ref($args) eq 'HASH') {
9124: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
9125: } else {
9126: $msg = &mt($msg);
9127: }
1.1150 bisitz 9128:
1.318 albertel 9129: my $page =
9130: &Apache::loncommon::start_page($title).
1.1150 bisitz 9131: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9132: &Apache::loncommon::end_page();
9133: if (ref($r)) {
9134: $r->print($page);
1.327 albertel 9135: return;
1.318 albertel 9136: }
9137: return $page;
9138: }
1.347 albertel 9139:
9140: {
1.610 albertel 9141: my @row_count;
1.961 onken 9142:
9143: sub start_data_table_count {
9144: unshift(@row_count, 0);
9145: return;
9146: }
9147:
9148: sub end_data_table_count {
9149: shift(@row_count);
9150: return;
9151: }
9152:
1.347 albertel 9153: sub start_data_table {
1.1018 raeburn 9154: my ($add_class,$id) = @_;
1.422 albertel 9155: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9156: my $table_id;
9157: if (defined($id)) {
9158: $table_id = ' id="'.$id.'"';
9159: }
1.961 onken 9160: &start_data_table_count();
1.1018 raeburn 9161: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9162: }
9163:
9164: sub end_data_table {
1.961 onken 9165: &end_data_table_count();
1.389 albertel 9166: return '</table>'."\n";;
1.347 albertel 9167: }
9168:
9169: sub start_data_table_row {
1.974 wenzelju 9170: my ($add_class, $id) = @_;
1.610 albertel 9171: $row_count[0]++;
9172: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9173: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9174: $id = (' id="'.$id.'"') unless ($id eq '');
9175: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9176: }
1.471 banghart 9177:
9178: sub continue_data_table_row {
1.974 wenzelju 9179: my ($add_class, $id) = @_;
1.610 albertel 9180: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9181: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9182: $id = (' id="'.$id.'"') unless ($id eq '');
9183: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9184: }
1.347 albertel 9185:
9186: sub end_data_table_row {
1.389 albertel 9187: return '</tr>'."\n";;
1.347 albertel 9188: }
1.367 www 9189:
1.421 albertel 9190: sub start_data_table_empty_row {
1.707 bisitz 9191: # $row_count[0]++;
1.421 albertel 9192: return '<tr class="LC_empty_row" >'."\n";;
9193: }
9194:
9195: sub end_data_table_empty_row {
9196: return '</tr>'."\n";;
9197: }
9198:
1.367 www 9199: sub start_data_table_header_row {
1.389 albertel 9200: return '<tr class="LC_header_row">'."\n";;
1.367 www 9201: }
9202:
9203: sub end_data_table_header_row {
1.389 albertel 9204: return '</tr>'."\n";;
1.367 www 9205: }
1.890 droeschl 9206:
9207: sub data_table_caption {
9208: my $caption = shift;
9209: return "<caption class=\"LC_caption\">$caption</caption>";
9210: }
1.347 albertel 9211: }
9212:
1.548 albertel 9213: =pod
9214:
9215: =item * &inhibit_menu_check($arg)
9216:
9217: Checks for a inhibitmenu state and generates output to preserve it
9218:
9219: Inputs: $arg - can be any of
9220: - undef - in which case the return value is a string
9221: to add into arguments list of a uri
9222: - 'input' - in which case the return value is a HTML
9223: <form> <input> field of type hidden to
9224: preserve the value
9225: - a url - in which case the return value is the url with
9226: the neccesary cgi args added to preserve the
9227: inhibitmenu state
9228: - a ref to a url - no return value, but the string is
9229: updated to include the neccessary cgi
9230: args to preserve the inhibitmenu state
9231:
9232: =cut
9233:
9234: sub inhibit_menu_check {
9235: my ($arg) = @_;
9236: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9237: if ($arg eq 'input') {
9238: if ($env{'form.inhibitmenu'}) {
9239: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9240: } else {
9241: return
9242: }
9243: }
9244: if ($env{'form.inhibitmenu'}) {
9245: if (ref($arg)) {
9246: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9247: } elsif ($arg eq '') {
9248: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9249: } else {
9250: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9251: }
9252: }
9253: if (!ref($arg)) {
9254: return $arg;
9255: }
9256: }
9257:
1.251 albertel 9258: ###############################################
1.182 matthew 9259:
9260: =pod
9261:
1.549 albertel 9262: =back
9263:
9264: =head1 User Information Routines
9265:
9266: =over 4
9267:
1.405 albertel 9268: =item * &get_users_function()
1.182 matthew 9269:
9270: Used by &bodytag to determine the current users primary role.
9271: Returns either 'student','coordinator','admin', or 'author'.
9272:
9273: =cut
9274:
9275: ###############################################
9276: sub get_users_function {
1.815 tempelho 9277: my $function = 'norole';
1.818 tempelho 9278: if ($env{'request.role'}=~/^(st)/) {
9279: $function='student';
9280: }
1.907 raeburn 9281: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9282: $function='coordinator';
9283: }
1.258 albertel 9284: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9285: $function='admin';
9286: }
1.826 bisitz 9287: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9288: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9289: $function='author';
9290: }
9291: return $function;
1.54 www 9292: }
1.99 www 9293:
9294: ###############################################
9295:
1.233 raeburn 9296: =pod
9297:
1.821 raeburn 9298: =item * &show_course()
9299:
9300: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9301: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9302:
9303: Inputs:
9304: None
9305:
9306: Outputs:
9307: Scalar: 1 if 'Course' to be used, 0 otherwise.
9308:
9309: =cut
9310:
9311: ###############################################
9312: sub show_course {
9313: my $course = !$env{'user.adv'};
9314: if (!$env{'user.adv'}) {
9315: foreach my $env (keys(%env)) {
9316: next if ($env !~ m/^user\.priv\./);
9317: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9318: $course = 0;
9319: last;
9320: }
9321: }
9322: }
9323: return $course;
9324: }
9325:
9326: ###############################################
9327:
9328: =pod
9329:
1.542 raeburn 9330: =item * &check_user_status()
1.274 raeburn 9331:
9332: Determines current status of supplied role for a
9333: specific user. Roles can be active, previous or future.
9334:
9335: Inputs:
9336: user's domain, user's username, course's domain,
1.375 raeburn 9337: course's number, optional section ID.
1.274 raeburn 9338:
9339: Outputs:
9340: role status: active, previous or future.
9341:
9342: =cut
9343:
9344: sub check_user_status {
1.412 raeburn 9345: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9346: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9347: my @uroles = keys(%userinfo);
1.274 raeburn 9348: my $srchstr;
9349: my $active_chk = 'none';
1.412 raeburn 9350: my $now = time;
1.274 raeburn 9351: if (@uroles > 0) {
1.908 raeburn 9352: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9353: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9354: } else {
1.412 raeburn 9355: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9356: }
9357: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9358: my $role_end = 0;
9359: my $role_start = 0;
9360: $active_chk = 'active';
1.412 raeburn 9361: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9362: $role_end = $1;
9363: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9364: $role_start = $1;
1.274 raeburn 9365: }
9366: }
9367: if ($role_start > 0) {
1.412 raeburn 9368: if ($now < $role_start) {
1.274 raeburn 9369: $active_chk = 'future';
9370: }
9371: }
9372: if ($role_end > 0) {
1.412 raeburn 9373: if ($now > $role_end) {
1.274 raeburn 9374: $active_chk = 'previous';
9375: }
9376: }
9377: }
9378: }
9379: return $active_chk;
9380: }
9381:
9382: ###############################################
9383:
9384: =pod
9385:
1.405 albertel 9386: =item * &get_sections()
1.233 raeburn 9387:
9388: Determines all the sections for a course including
9389: sections with students and sections containing other roles.
1.419 raeburn 9390: Incoming parameters:
9391:
9392: 1. domain
9393: 2. course number
9394: 3. reference to array containing roles for which sections should
9395: be gathered (optional).
9396: 4. reference to array containing status types for which sections
9397: should be gathered (optional).
9398:
9399: If the third argument is undefined, sections are gathered for any role.
9400: If the fourth argument is undefined, sections are gathered for any status.
9401: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9402:
1.374 raeburn 9403: Returns section hash (keys are section IDs, values are
9404: number of users in each section), subject to the
1.419 raeburn 9405: optional roles filter, optional status filter
1.233 raeburn 9406:
9407: =cut
9408:
9409: ###############################################
9410: sub get_sections {
1.419 raeburn 9411: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9412: if (!defined($cdom) || !defined($cnum)) {
9413: my $cid = $env{'request.course.id'};
9414:
9415: return if (!defined($cid));
9416:
9417: $cdom = $env{'course.'.$cid.'.domain'};
9418: $cnum = $env{'course.'.$cid.'.num'};
9419: }
9420:
9421: my %sectioncount;
1.419 raeburn 9422: my $now = time;
1.240 albertel 9423:
1.1118 raeburn 9424: my $check_students = 1;
9425: my $only_students = 0;
9426: if (ref($possible_roles) eq 'ARRAY') {
9427: if (grep(/^st$/,@{$possible_roles})) {
9428: if (@{$possible_roles} == 1) {
9429: $only_students = 1;
9430: }
9431: } else {
9432: $check_students = 0;
9433: }
9434: }
9435:
9436: if ($check_students) {
1.276 albertel 9437: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9438: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9439: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9440: my $start_index = &Apache::loncoursedata::CL_START();
9441: my $end_index = &Apache::loncoursedata::CL_END();
9442: my $status;
1.366 albertel 9443: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9444: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9445: $data->[$status_index],
9446: $data->[$start_index],
9447: $data->[$end_index]);
9448: if ($stu_status eq 'Active') {
9449: $status = 'active';
9450: } elsif ($end < $now) {
9451: $status = 'previous';
9452: } elsif ($start > $now) {
9453: $status = 'future';
9454: }
9455: if ($section ne '-1' && $section !~ /^\s*$/) {
9456: if ((!defined($possible_status)) || (($status ne '') &&
9457: (grep/^\Q$status\E$/,@{$possible_status}))) {
9458: $sectioncount{$section}++;
9459: }
1.240 albertel 9460: }
9461: }
9462: }
1.1118 raeburn 9463: if ($only_students) {
9464: return %sectioncount;
9465: }
1.240 albertel 9466: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9467: foreach my $user (sort(keys(%courseroles))) {
9468: if ($user !~ /^(\w{2})/) { next; }
9469: my ($role) = ($user =~ /^(\w{2})/);
9470: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9471: my ($section,$status);
1.240 albertel 9472: if ($role eq 'cr' &&
9473: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9474: $section=$1;
9475: }
9476: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9477: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9478: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9479: if ($end == -1 && $start == -1) {
9480: next; #deleted role
9481: }
9482: if (!defined($possible_status)) {
9483: $sectioncount{$section}++;
9484: } else {
9485: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9486: $status = 'active';
9487: } elsif ($end < $now) {
9488: $status = 'future';
9489: } elsif ($start > $now) {
9490: $status = 'previous';
9491: }
9492: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9493: $sectioncount{$section}++;
9494: }
9495: }
1.233 raeburn 9496: }
1.366 albertel 9497: return %sectioncount;
1.233 raeburn 9498: }
9499:
1.274 raeburn 9500: ###############################################
1.294 raeburn 9501:
9502: =pod
1.405 albertel 9503:
9504: =item * &get_course_users()
9505:
1.275 raeburn 9506: Retrieves usernames:domains for users in the specified course
9507: with specific role(s), and access status.
9508:
9509: Incoming parameters:
1.277 albertel 9510: 1. course domain
9511: 2. course number
9512: 3. access status: users must have - either active,
1.275 raeburn 9513: previous, future, or all.
1.277 albertel 9514: 4. reference to array of permissible roles
1.288 raeburn 9515: 5. reference to array of section restrictions (optional)
9516: 6. reference to results object (hash of hashes).
9517: 7. reference to optional userdata hash
1.609 raeburn 9518: 8. reference to optional statushash
1.630 raeburn 9519: 9. flag if privileged users (except those set to unhide in
9520: course settings) should be excluded
1.609 raeburn 9521: Keys of top level results hash are roles.
1.275 raeburn 9522: Keys of inner hashes are username:domain, with
9523: values set to access type.
1.288 raeburn 9524: Optional userdata hash returns an array with arguments in the
9525: same order as loncoursedata::get_classlist() for student data.
9526:
1.609 raeburn 9527: Optional statushash returns
9528:
1.288 raeburn 9529: Entries for end, start, section and status are blank because
9530: of the possibility of multiple values for non-student roles.
9531:
1.275 raeburn 9532: =cut
1.405 albertel 9533:
1.275 raeburn 9534: ###############################################
1.405 albertel 9535:
1.275 raeburn 9536: sub get_course_users {
1.630 raeburn 9537: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9538: my %idx = ();
1.419 raeburn 9539: my %seclists;
1.288 raeburn 9540:
9541: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9542: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9543: $idx{end} = &Apache::loncoursedata::CL_END();
9544: $idx{start} = &Apache::loncoursedata::CL_START();
9545: $idx{id} = &Apache::loncoursedata::CL_ID();
9546: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9547: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9548: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9549:
1.290 albertel 9550: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9551: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9552: my $now = time;
1.277 albertel 9553: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9554: my $match = 0;
1.412 raeburn 9555: my $secmatch = 0;
1.419 raeburn 9556: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9557: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9558: if ($section eq '') {
9559: $section = 'none';
9560: }
1.291 albertel 9561: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9562: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9563: $secmatch = 1;
9564: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9565: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9566: $secmatch = 1;
9567: }
9568: } else {
1.419 raeburn 9569: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9570: $secmatch = 1;
9571: }
1.290 albertel 9572: }
1.412 raeburn 9573: if (!$secmatch) {
9574: next;
9575: }
1.419 raeburn 9576: }
1.275 raeburn 9577: if (defined($$types{'active'})) {
1.288 raeburn 9578: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9579: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9580: $match = 1;
1.275 raeburn 9581: }
9582: }
9583: if (defined($$types{'previous'})) {
1.609 raeburn 9584: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9585: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9586: $match = 1;
1.275 raeburn 9587: }
9588: }
9589: if (defined($$types{'future'})) {
1.609 raeburn 9590: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9591: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9592: $match = 1;
1.275 raeburn 9593: }
9594: }
1.609 raeburn 9595: if ($match) {
9596: push(@{$seclists{$student}},$section);
9597: if (ref($userdata) eq 'HASH') {
9598: $$userdata{$student} = $$classlist{$student};
9599: }
9600: if (ref($statushash) eq 'HASH') {
9601: $statushash->{$student}{'st'}{$section} = $status;
9602: }
1.288 raeburn 9603: }
1.275 raeburn 9604: }
9605: }
1.412 raeburn 9606: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9607: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9608: my $now = time;
1.609 raeburn 9609: my %displaystatus = ( previous => 'Expired',
9610: active => 'Active',
9611: future => 'Future',
9612: );
1.1121 raeburn 9613: my (%nothide,@possdoms);
1.630 raeburn 9614: if ($hidepriv) {
9615: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9616: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9617: if ($user !~ /:/) {
9618: $nothide{join(':',split(/[\@]/,$user))}=1;
9619: } else {
9620: $nothide{$user} = 1;
9621: }
9622: }
1.1121 raeburn 9623: my @possdoms = ($cdom);
9624: if ($coursehash{'checkforpriv'}) {
9625: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9626: }
1.630 raeburn 9627: }
1.439 raeburn 9628: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9629: my $match = 0;
1.412 raeburn 9630: my $secmatch = 0;
1.439 raeburn 9631: my $status;
1.412 raeburn 9632: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9633: $user =~ s/:$//;
1.439 raeburn 9634: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9635: if ($end == -1 || $start == -1) {
9636: next;
9637: }
9638: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9639: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9640: my ($uname,$udom) = split(/:/,$user);
9641: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9642: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9643: $secmatch = 1;
9644: } elsif ($usec eq '') {
1.420 albertel 9645: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9646: $secmatch = 1;
9647: }
9648: } else {
9649: if (grep(/^\Q$usec\E$/,@{$sections})) {
9650: $secmatch = 1;
9651: }
9652: }
9653: if (!$secmatch) {
9654: next;
9655: }
1.288 raeburn 9656: }
1.419 raeburn 9657: if ($usec eq '') {
9658: $usec = 'none';
9659: }
1.275 raeburn 9660: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9661: if ($hidepriv) {
1.1121 raeburn 9662: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9663: (!$nothide{$uname.':'.$udom})) {
9664: next;
9665: }
9666: }
1.503 raeburn 9667: if ($end > 0 && $end < $now) {
1.439 raeburn 9668: $status = 'previous';
9669: } elsif ($start > $now) {
9670: $status = 'future';
9671: } else {
9672: $status = 'active';
9673: }
1.277 albertel 9674: foreach my $type (keys(%{$types})) {
1.275 raeburn 9675: if ($status eq $type) {
1.420 albertel 9676: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9677: push(@{$$users{$role}{$user}},$type);
9678: }
1.288 raeburn 9679: $match = 1;
9680: }
9681: }
1.419 raeburn 9682: if (($match) && (ref($userdata) eq 'HASH')) {
9683: if (!exists($$userdata{$uname.':'.$udom})) {
9684: &get_user_info($udom,$uname,\%idx,$userdata);
9685: }
1.420 albertel 9686: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9687: push(@{$seclists{$uname.':'.$udom}},$usec);
9688: }
1.609 raeburn 9689: if (ref($statushash) eq 'HASH') {
9690: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9691: }
1.275 raeburn 9692: }
9693: }
9694: }
9695: }
1.290 albertel 9696: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9697: if ((defined($cdom)) && (defined($cnum))) {
9698: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9699: if ( defined($csettings{'internal.courseowner'}) ) {
9700: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9701: next if ($owner eq '');
9702: my ($ownername,$ownerdom);
9703: if ($owner =~ /^([^:]+):([^:]+)$/) {
9704: $ownername = $1;
9705: $ownerdom = $2;
9706: } else {
9707: $ownername = $owner;
9708: $ownerdom = $cdom;
9709: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9710: }
9711: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9712: if (defined($userdata) &&
1.609 raeburn 9713: !exists($$userdata{$owner})) {
9714: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9715: if (!grep(/^none$/,@{$seclists{$owner}})) {
9716: push(@{$seclists{$owner}},'none');
9717: }
9718: if (ref($statushash) eq 'HASH') {
9719: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9720: }
1.290 albertel 9721: }
1.279 raeburn 9722: }
9723: }
9724: }
1.419 raeburn 9725: foreach my $user (keys(%seclists)) {
9726: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9727: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9728: }
1.275 raeburn 9729: }
9730: return;
9731: }
9732:
1.288 raeburn 9733: sub get_user_info {
9734: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9735: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9736: &plainname($uname,$udom,'lastname');
1.291 albertel 9737: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9738: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9739: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9740: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9741: return;
9742: }
1.275 raeburn 9743:
1.472 raeburn 9744: ###############################################
9745:
9746: =pod
9747:
9748: =item * &get_user_quota()
9749:
1.1134 raeburn 9750: Retrieves quota assigned for storage of user files.
9751: Default is to report quota for portfolio files.
1.472 raeburn 9752:
9753: Incoming parameters:
9754: 1. user's username
9755: 2. user's domain
1.1134 raeburn 9756: 3. quota name - portfolio, author, or course
1.1136 raeburn 9757: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 9758: 4. crstype - official, unofficial, textbook, placement or community,
9759: if quota name is course
1.472 raeburn 9760:
9761: Returns:
1.1163 raeburn 9762: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9763: 2. (Optional) Type of setting: custom or default
9764: (individually assigned or default for user's
9765: institutional status).
9766: 3. (Optional) - User's institutional status (e.g., faculty, staff
9767: or student - types as defined in localenroll::inst_usertypes
9768: for user's domain, which determines default quota for user.
9769: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9770:
9771: If a value has been stored in the user's environment,
1.536 raeburn 9772: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9773: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9774:
9775: =cut
9776:
9777: ###############################################
9778:
9779:
9780: sub get_user_quota {
1.1136 raeburn 9781: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9782: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9783: if (!defined($udom)) {
9784: $udom = $env{'user.domain'};
9785: }
9786: if (!defined($uname)) {
9787: $uname = $env{'user.name'};
9788: }
9789: if (($udom eq '' || $uname eq '') ||
9790: ($udom eq 'public') && ($uname eq 'public')) {
9791: $quota = 0;
1.536 raeburn 9792: $quotatype = 'default';
9793: $defquota = 0;
1.472 raeburn 9794: } else {
1.536 raeburn 9795: my $inststatus;
1.1134 raeburn 9796: if ($quotaname eq 'course') {
9797: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9798: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9799: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9800: } else {
9801: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9802: $quota = $cenv{'internal.uploadquota'};
9803: }
1.536 raeburn 9804: } else {
1.1134 raeburn 9805: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9806: if ($quotaname eq 'author') {
9807: $quota = $env{'environment.authorquota'};
9808: } else {
9809: $quota = $env{'environment.portfolioquota'};
9810: }
9811: $inststatus = $env{'environment.inststatus'};
9812: } else {
9813: my %userenv =
9814: &Apache::lonnet::get('environment',['portfolioquota',
9815: 'authorquota','inststatus'],$udom,$uname);
9816: my ($tmp) = keys(%userenv);
9817: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9818: if ($quotaname eq 'author') {
9819: $quota = $userenv{'authorquota'};
9820: } else {
9821: $quota = $userenv{'portfolioquota'};
9822: }
9823: $inststatus = $userenv{'inststatus'};
9824: } else {
9825: undef(%userenv);
9826: }
9827: }
9828: }
9829: if ($quota eq '' || wantarray) {
9830: if ($quotaname eq 'course') {
9831: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 9832: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 9833: ($crstype eq 'community') || ($crstype eq 'textbook') ||
9834: ($crstype eq 'placement')) {
1.1136 raeburn 9835: $defquota = $domdefs{$crstype.'quota'};
9836: }
9837: if ($defquota eq '') {
9838: $defquota = 500;
9839: }
1.1134 raeburn 9840: } else {
9841: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9842: }
9843: if ($quota eq '') {
9844: $quota = $defquota;
9845: $quotatype = 'default';
9846: } else {
9847: $quotatype = 'custom';
9848: }
1.472 raeburn 9849: }
9850: }
1.536 raeburn 9851: if (wantarray) {
9852: return ($quota,$quotatype,$settingstatus,$defquota);
9853: } else {
9854: return $quota;
9855: }
1.472 raeburn 9856: }
9857:
9858: ###############################################
9859:
9860: =pod
9861:
9862: =item * &default_quota()
9863:
1.536 raeburn 9864: Retrieves default quota assigned for storage of user portfolio files,
9865: given an (optional) user's institutional status.
1.472 raeburn 9866:
9867: Incoming parameters:
1.1142 raeburn 9868:
1.472 raeburn 9869: 1. domain
1.536 raeburn 9870: 2. (Optional) institutional status(es). This is a : separated list of
9871: status types (e.g., faculty, staff, student etc.)
9872: which apply to the user for whom the default is being retrieved.
9873: If the institutional status string in undefined, the domain
1.1134 raeburn 9874: default quota will be returned.
9875: 3. quota name - portfolio, author, or course
9876: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9877:
9878: Returns:
1.1142 raeburn 9879:
1.1163 raeburn 9880: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9881: 2. (Optional) institutional type which determined the value of the
9882: default quota.
1.472 raeburn 9883:
9884: If a value has been stored in the domain's configuration db,
9885: it will return that, otherwise it returns 20 (for backwards
9886: compatibility with domains which have not set up a configuration
1.1163 raeburn 9887: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9888:
1.536 raeburn 9889: If the user's status includes multiple types (e.g., staff and student),
9890: the largest default quota which applies to the user determines the
9891: default quota returned.
9892:
1.472 raeburn 9893: =cut
9894:
9895: ###############################################
9896:
9897:
9898: sub default_quota {
1.1134 raeburn 9899: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9900: my ($defquota,$settingstatus);
9901: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9902: ['quotas'],$udom);
1.1134 raeburn 9903: my $key = 'defaultquota';
9904: if ($quotaname eq 'author') {
9905: $key = 'authorquota';
9906: }
1.622 raeburn 9907: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9908: if ($inststatus ne '') {
1.765 raeburn 9909: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9910: foreach my $item (@statuses) {
1.1134 raeburn 9911: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9912: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9913: if ($defquota eq '') {
1.1134 raeburn 9914: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9915: $settingstatus = $item;
1.1134 raeburn 9916: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9917: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9918: $settingstatus = $item;
9919: }
9920: }
1.1134 raeburn 9921: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9922: if ($quotahash{'quotas'}{$item} ne '') {
9923: if ($defquota eq '') {
9924: $defquota = $quotahash{'quotas'}{$item};
9925: $settingstatus = $item;
9926: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9927: $defquota = $quotahash{'quotas'}{$item};
9928: $settingstatus = $item;
9929: }
1.536 raeburn 9930: }
9931: }
9932: }
9933: }
9934: if ($defquota eq '') {
1.1134 raeburn 9935: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9936: $defquota = $quotahash{'quotas'}{$key}{'default'};
9937: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9938: $defquota = $quotahash{'quotas'}{'default'};
9939: }
1.536 raeburn 9940: $settingstatus = 'default';
1.1139 raeburn 9941: if ($defquota eq '') {
9942: if ($quotaname eq 'author') {
9943: $defquota = 500;
9944: }
9945: }
1.536 raeburn 9946: }
9947: } else {
9948: $settingstatus = 'default';
1.1134 raeburn 9949: if ($quotaname eq 'author') {
9950: $defquota = 500;
9951: } else {
9952: $defquota = 20;
9953: }
1.536 raeburn 9954: }
9955: if (wantarray) {
9956: return ($defquota,$settingstatus);
1.472 raeburn 9957: } else {
1.536 raeburn 9958: return $defquota;
1.472 raeburn 9959: }
9960: }
9961:
1.1135 raeburn 9962: ###############################################
9963:
9964: =pod
9965:
1.1136 raeburn 9966: =item * &excess_filesize_warning()
1.1135 raeburn 9967:
9968: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 9969: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 9970: space to be exceeded.
1.1136 raeburn 9971:
9972: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 9973: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 9974:
1.1165 raeburn 9975: Inputs: 7
1.1136 raeburn 9976: 1. username or coursenum
1.1135 raeburn 9977: 2. domain
1.1136 raeburn 9978: 3. context ('author' or 'course')
1.1135 raeburn 9979: 4. filename of file for which action is being requested
9980: 5. filesize (kB) of file
9981: 6. action being taken: copy or upload.
1.1237 raeburn 9982: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 9983:
9984: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 9985: otherwise return null.
9986:
9987: =back
1.1135 raeburn 9988:
9989: =cut
9990:
1.1136 raeburn 9991: sub excess_filesize_warning {
1.1165 raeburn 9992: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 9993: my $current_disk_usage = 0;
1.1165 raeburn 9994: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 9995: if ($context eq 'author') {
9996: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9997: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9998: } else {
9999: foreach my $subdir ('docs','supplemental') {
10000: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10001: }
10002: }
1.1135 raeburn 10003: $disk_quota = int($disk_quota * 1000);
10004: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10005: return '<p class="LC_warning">'.
1.1135 raeburn 10006: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10007: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10008: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10009: $disk_quota,$current_disk_usage).
10010: '</p>';
10011: }
10012: return;
10013: }
10014:
10015: ###############################################
10016:
10017:
1.1136 raeburn 10018:
10019:
1.384 raeburn 10020: sub get_secgrprole_info {
10021: my ($cdom,$cnum,$needroles,$type) = @_;
10022: my %sections_count = &get_sections($cdom,$cnum);
10023: my @sections = (sort {$a <=> $b} keys(%sections_count));
10024: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10025: my @groups = sort(keys(%curr_groups));
10026: my $allroles = [];
10027: my $rolehash;
10028: my $accesshash = {
10029: active => 'Currently has access',
10030: future => 'Will have future access',
10031: previous => 'Previously had access',
10032: };
10033: if ($needroles) {
10034: $rolehash = {'all' => 'all'};
1.385 albertel 10035: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10036: if (&Apache::lonnet::error(%user_roles)) {
10037: undef(%user_roles);
10038: }
10039: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10040: my ($role)=split(/\:/,$item,2);
10041: if ($role eq 'cr') { next; }
10042: if ($role =~ /^cr/) {
10043: $$rolehash{$role} = (split('/',$role))[3];
10044: } else {
10045: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10046: }
10047: }
10048: foreach my $key (sort(keys(%{$rolehash}))) {
10049: push(@{$allroles},$key);
10050: }
10051: push (@{$allroles},'st');
10052: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10053: }
10054: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10055: }
10056:
1.555 raeburn 10057: sub user_picker {
1.1279 raeburn 10058: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10059: my $currdom = $dom;
1.1253 raeburn 10060: my @alldoms = &Apache::lonnet::all_domains();
10061: if (@alldoms == 1) {
10062: my %domsrch = &Apache::lonnet::get_dom('configuration',
10063: ['directorysrch'],$alldoms[0]);
10064: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10065: my $showdom = $domdesc;
10066: if ($showdom eq '') {
10067: $showdom = $dom;
10068: }
10069: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10070: if ((!$domsrch{'directorysrch'}{'available'}) &&
10071: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10072: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10073: }
10074: }
10075: }
1.555 raeburn 10076: my %curr_selected = (
10077: srchin => 'dom',
1.580 raeburn 10078: srchby => 'lastname',
1.555 raeburn 10079: );
10080: my $srchterm;
1.625 raeburn 10081: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10082: if ($srch->{'srchby'} ne '') {
10083: $curr_selected{'srchby'} = $srch->{'srchby'};
10084: }
10085: if ($srch->{'srchin'} ne '') {
10086: $curr_selected{'srchin'} = $srch->{'srchin'};
10087: }
10088: if ($srch->{'srchtype'} ne '') {
10089: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10090: }
10091: if ($srch->{'srchdomain'} ne '') {
10092: $currdom = $srch->{'srchdomain'};
10093: }
10094: $srchterm = $srch->{'srchterm'};
10095: }
1.1222 damieng 10096: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10097: 'usr' => 'Search criteria',
1.563 raeburn 10098: 'doma' => 'Domain/institution to search',
1.558 albertel 10099: 'uname' => 'username',
10100: 'lastname' => 'last name',
1.555 raeburn 10101: 'lastfirst' => 'last name, first name',
1.558 albertel 10102: 'crs' => 'in this course',
1.576 raeburn 10103: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10104: 'alc' => 'all LON-CAPA',
1.573 raeburn 10105: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10106: 'exact' => 'is',
10107: 'contains' => 'contains',
1.569 raeburn 10108: 'begins' => 'begins with',
1.1222 damieng 10109: );
10110: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10111: 'youm' => "You must include some text to search for.",
10112: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10113: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10114: 'yomc' => "You must choose a domain when using an institutional directory search.",
10115: 'ymcd' => "You must choose a domain when using a domain search.",
10116: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10117: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10118: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10119: );
1.1222 damieng 10120: &html_escape(\%html_lt);
10121: &js_escape(\%js_lt);
1.1255 raeburn 10122: my $domform;
1.1277 raeburn 10123: my $allow_blank = 1;
1.1255 raeburn 10124: if ($fixeddom) {
1.1277 raeburn 10125: $allow_blank = 0;
10126: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10127: } else {
1.1277 raeburn 10128: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1255 raeburn 10129: }
1.563 raeburn 10130: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10131:
10132: my @srchins = ('crs','dom','alc','instd');
10133:
10134: foreach my $option (@srchins) {
10135: # FIXME 'alc' option unavailable until
10136: # loncreateuser::print_user_query_page()
10137: # has been completed.
10138: next if ($option eq 'alc');
1.880 raeburn 10139: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10140: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10141: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10142: if ($curr_selected{'srchin'} eq $option) {
10143: $srchinsel .= '
1.1222 damieng 10144: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10145: } else {
10146: $srchinsel .= '
1.1222 damieng 10147: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10148: }
1.555 raeburn 10149: }
1.563 raeburn 10150: $srchinsel .= "\n </select>\n";
1.555 raeburn 10151:
10152: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10153: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10154: if ($curr_selected{'srchby'} eq $option) {
10155: $srchbysel .= '
1.1222 damieng 10156: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10157: } else {
10158: $srchbysel .= '
1.1222 damieng 10159: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10160: }
10161: }
10162: $srchbysel .= "\n </select>\n";
10163:
10164: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10165: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10166: if ($curr_selected{'srchtype'} eq $option) {
10167: $srchtypesel .= '
1.1222 damieng 10168: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10169: } else {
10170: $srchtypesel .= '
1.1222 damieng 10171: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10172: }
10173: }
10174: $srchtypesel .= "\n </select>\n";
10175:
1.558 albertel 10176: my ($newuserscript,$new_user_create);
1.994 raeburn 10177: my $context_dom = $env{'request.role.domain'};
10178: if ($context eq 'requestcrs') {
10179: if ($env{'form.coursedom'} ne '') {
10180: $context_dom = $env{'form.coursedom'};
10181: }
10182: }
1.556 raeburn 10183: if ($forcenewuser) {
1.576 raeburn 10184: if (ref($srch) eq 'HASH') {
1.994 raeburn 10185: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10186: if ($cancreate) {
10187: $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>';
10188: } else {
1.799 bisitz 10189: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10190: my %usertypetext = (
10191: official => 'institutional',
10192: unofficial => 'non-institutional',
10193: );
1.799 bisitz 10194: $new_user_create = '<p class="LC_warning">'
10195: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10196: .' '
10197: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10198: ,'<a href="'.$helplink.'">','</a>')
10199: .'</p><br />';
1.627 raeburn 10200: }
1.576 raeburn 10201: }
10202: }
10203:
1.556 raeburn 10204: $newuserscript = <<"ENDSCRIPT";
10205:
1.570 raeburn 10206: function setSearch(createnew,callingForm) {
1.556 raeburn 10207: if (createnew == 1) {
1.570 raeburn 10208: for (var i=0; i<callingForm.srchby.length; i++) {
10209: if (callingForm.srchby.options[i].value == 'uname') {
10210: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10211: }
10212: }
1.570 raeburn 10213: for (var i=0; i<callingForm.srchin.length; i++) {
10214: if ( callingForm.srchin.options[i].value == 'dom') {
10215: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10216: }
10217: }
1.570 raeburn 10218: for (var i=0; i<callingForm.srchtype.length; i++) {
10219: if (callingForm.srchtype.options[i].value == 'exact') {
10220: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10221: }
10222: }
1.570 raeburn 10223: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10224: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10225: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10226: }
10227: }
10228: }
10229: }
10230: ENDSCRIPT
1.558 albertel 10231:
1.556 raeburn 10232: }
10233:
1.555 raeburn 10234: my $output = <<"END_BLOCK";
1.556 raeburn 10235: <script type="text/javascript">
1.824 bisitz 10236: // <![CDATA[
1.570 raeburn 10237: function validateEntry(callingForm) {
1.558 albertel 10238:
1.556 raeburn 10239: var checkok = 1;
1.558 albertel 10240: var srchin;
1.570 raeburn 10241: for (var i=0; i<callingForm.srchin.length; i++) {
10242: if ( callingForm.srchin[i].checked ) {
10243: srchin = callingForm.srchin[i].value;
1.558 albertel 10244: }
10245: }
10246:
1.570 raeburn 10247: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10248: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10249: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10250: var srchterm = callingForm.srchterm.value;
10251: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10252: var msg = "";
10253:
10254: if (srchterm == "") {
10255: checkok = 0;
1.1222 damieng 10256: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10257: }
10258:
1.569 raeburn 10259: if (srchtype== 'begins') {
10260: if (srchterm.length < 2) {
10261: checkok = 0;
1.1222 damieng 10262: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10263: }
10264: }
10265:
1.556 raeburn 10266: if (srchtype== 'contains') {
10267: if (srchterm.length < 3) {
10268: checkok = 0;
1.1222 damieng 10269: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10270: }
10271: }
10272: if (srchin == 'instd') {
10273: if (srchdomain == '') {
10274: checkok = 0;
1.1222 damieng 10275: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10276: }
10277: }
10278: if (srchin == 'dom') {
10279: if (srchdomain == '') {
10280: checkok = 0;
1.1222 damieng 10281: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10282: }
10283: }
10284: if (srchby == 'lastfirst') {
10285: if (srchterm.indexOf(",") == -1) {
10286: checkok = 0;
1.1222 damieng 10287: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10288: }
10289: if (srchterm.indexOf(",") == srchterm.length -1) {
10290: checkok = 0;
1.1222 damieng 10291: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10292: }
10293: }
10294: if (checkok == 0) {
1.1222 damieng 10295: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10296: return;
10297: }
10298: if (checkok == 1) {
1.570 raeburn 10299: callingForm.submit();
1.556 raeburn 10300: }
10301: }
10302:
10303: $newuserscript
10304:
1.824 bisitz 10305: // ]]>
1.556 raeburn 10306: </script>
1.558 albertel 10307:
10308: $new_user_create
10309:
1.555 raeburn 10310: END_BLOCK
1.558 albertel 10311:
1.876 raeburn 10312: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10313: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10314: $domform.
10315: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10316: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10317: $srchbysel.
10318: $srchtypesel.
10319: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10320: $srchinsel.
10321: &Apache::lonhtmlcommon::row_closure(1).
10322: &Apache::lonhtmlcommon::end_pick_box().
10323: '<br />';
1.1253 raeburn 10324: return ($output,1);
1.555 raeburn 10325: }
10326:
1.612 raeburn 10327: sub user_rule_check {
1.615 raeburn 10328: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10329: my ($response,%inst_response);
1.612 raeburn 10330: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10331: if (keys(%{$usershash}) > 1) {
10332: my (%by_username,%by_id,%userdoms);
10333: my $checkid;
10334: if (ref($checks) eq 'HASH') {
10335: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10336: $checkid = 1;
10337: }
10338: }
10339: foreach my $user (keys(%{$usershash})) {
10340: my ($uname,$udom) = split(/:/,$user);
10341: if ($checkid) {
10342: if (ref($usershash->{$user}) eq 'HASH') {
10343: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10344: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10345: $userdoms{$udom} = 1;
1.1227 raeburn 10346: if (ref($inst_results) eq 'HASH') {
10347: $inst_results->{$uname.':'.$udom} = {};
10348: }
1.1226 raeburn 10349: }
10350: }
10351: } else {
10352: $by_username{$udom}{$uname} = 1;
10353: $userdoms{$udom} = 1;
1.1227 raeburn 10354: if (ref($inst_results) eq 'HASH') {
10355: $inst_results->{$uname.':'.$udom} = {};
10356: }
1.1226 raeburn 10357: }
10358: }
10359: foreach my $udom (keys(%userdoms)) {
10360: if (!$got_rules->{$udom}) {
10361: my %domconfig = &Apache::lonnet::get_dom('configuration',
10362: ['usercreation'],$udom);
10363: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10364: foreach my $item ('username','id') {
10365: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10366: $$curr_rules{$udom}{$item} =
10367: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10368: }
10369: }
10370: }
10371: $got_rules->{$udom} = 1;
10372: }
1.612 raeburn 10373: }
1.1226 raeburn 10374: if ($checkid) {
10375: foreach my $udom (keys(%by_id)) {
10376: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10377: if ($outcome eq 'ok') {
1.1227 raeburn 10378: foreach my $id (keys(%{$by_id{$udom}})) {
10379: my $uname = $by_id{$udom}{$id};
10380: $inst_response{$uname.':'.$udom} = $outcome;
10381: }
1.1226 raeburn 10382: if (ref($results) eq 'HASH') {
10383: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10384: if (exists($inst_response{$uname.':'.$udom})) {
10385: $inst_response{$uname.':'.$udom} = $outcome;
10386: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10387: }
1.1226 raeburn 10388: }
10389: }
10390: }
1.612 raeburn 10391: }
1.615 raeburn 10392: } else {
1.1226 raeburn 10393: foreach my $udom (keys(%by_username)) {
10394: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10395: if ($outcome eq 'ok') {
1.1227 raeburn 10396: foreach my $uname (keys(%{$by_username{$udom}})) {
10397: $inst_response{$uname.':'.$udom} = $outcome;
10398: }
1.1226 raeburn 10399: if (ref($results) eq 'HASH') {
10400: foreach my $uname (keys(%{$results})) {
10401: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10402: }
10403: }
10404: }
10405: }
1.612 raeburn 10406: }
1.1226 raeburn 10407: } elsif (keys(%{$usershash}) == 1) {
10408: my $user = (keys(%{$usershash}))[0];
10409: my ($uname,$udom) = split(/:/,$user);
10410: if (($udom ne '') && ($uname ne '')) {
10411: if (ref($usershash->{$user}) eq 'HASH') {
10412: if (ref($checks) eq 'HASH') {
10413: if (defined($checks->{'username'})) {
10414: ($inst_response{$user},%{$inst_results->{$user}}) =
10415: &Apache::lonnet::get_instuser($udom,$uname);
10416: } elsif (defined($checks->{'id'})) {
10417: if ($usershash->{$user}->{'id'} ne '') {
10418: ($inst_response{$user},%{$inst_results->{$user}}) =
10419: &Apache::lonnet::get_instuser($udom,undef,
10420: $usershash->{$user}->{'id'});
10421: } else {
10422: ($inst_response{$user},%{$inst_results->{$user}}) =
10423: &Apache::lonnet::get_instuser($udom,$uname);
10424: }
1.585 raeburn 10425: }
1.1226 raeburn 10426: } else {
10427: ($inst_response{$user},%{$inst_results->{$user}}) =
10428: &Apache::lonnet::get_instuser($udom,$uname);
10429: return;
10430: }
10431: if (!$got_rules->{$udom}) {
10432: my %domconfig = &Apache::lonnet::get_dom('configuration',
10433: ['usercreation'],$udom);
10434: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10435: foreach my $item ('username','id') {
10436: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10437: $$curr_rules{$udom}{$item} =
10438: $domconfig{'usercreation'}{$item.'_rule'};
10439: }
10440: }
10441: }
10442: $got_rules->{$udom} = 1;
1.585 raeburn 10443: }
10444: }
1.1226 raeburn 10445: } else {
10446: return;
10447: }
10448: } else {
10449: return;
10450: }
10451: foreach my $user (keys(%{$usershash})) {
10452: my ($uname,$udom) = split(/:/,$user);
10453: next if (($udom eq '') || ($uname eq ''));
10454: my $id;
1.1227 raeburn 10455: if (ref($inst_results) eq 'HASH') {
10456: if (ref($inst_results->{$user}) eq 'HASH') {
10457: $id = $inst_results->{$user}->{'id'};
10458: }
10459: }
10460: if ($id eq '') {
10461: if (ref($usershash->{$user})) {
10462: $id = $usershash->{$user}->{'id'};
10463: }
1.585 raeburn 10464: }
1.612 raeburn 10465: foreach my $item (keys(%{$checks})) {
10466: if (ref($$curr_rules{$udom}) eq 'HASH') {
10467: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10468: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10469: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10470: $$curr_rules{$udom}{$item});
1.612 raeburn 10471: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10472: if ($rule_check{$rule}) {
10473: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10474: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10475: if (ref($inst_results) eq 'HASH') {
10476: if (ref($inst_results->{$user}) eq 'HASH') {
10477: if (keys(%{$inst_results->{$user}}) == 0) {
10478: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10479: } elsif ($item eq 'id') {
10480: if ($inst_results->{$user}->{'id'} eq '') {
10481: $$alerts{$item}{$udom}{$uname} = 1;
10482: }
1.615 raeburn 10483: }
1.612 raeburn 10484: }
10485: }
1.615 raeburn 10486: }
10487: last;
1.585 raeburn 10488: }
10489: }
10490: }
10491: }
10492: }
10493: }
10494: }
10495: }
1.612 raeburn 10496: return;
10497: }
10498:
10499: sub user_rule_formats {
10500: my ($domain,$domdesc,$curr_rules,$check) = @_;
10501: my %text = (
10502: 'username' => 'Usernames',
10503: 'id' => 'IDs',
10504: );
10505: my $output;
10506: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10507: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10508: if (@{$ruleorder} > 0) {
1.1102 raeburn 10509: $output = '<br />'.
10510: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10511: '<span class="LC_cusr_emph">','</span>',$domdesc).
10512: ' <ul>';
1.612 raeburn 10513: foreach my $rule (@{$ruleorder}) {
10514: if (ref($curr_rules) eq 'ARRAY') {
10515: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10516: if (ref($rules->{$rule}) eq 'HASH') {
10517: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10518: $rules->{$rule}{'desc'}.'</li>';
10519: }
10520: }
10521: }
10522: }
10523: $output .= '</ul>';
10524: }
10525: }
10526: return $output;
10527: }
10528:
10529: sub instrule_disallow_msg {
1.615 raeburn 10530: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10531: my $response;
10532: my %text = (
10533: item => 'username',
10534: items => 'usernames',
10535: match => 'matches',
10536: do => 'does',
10537: action => 'a username',
10538: one => 'one',
10539: );
10540: if ($count > 1) {
10541: $text{'item'} = 'usernames';
10542: $text{'match'} ='match';
10543: $text{'do'} = 'do';
10544: $text{'action'} = 'usernames',
10545: $text{'one'} = 'ones';
10546: }
10547: if ($checkitem eq 'id') {
10548: $text{'items'} = 'IDs';
10549: $text{'item'} = 'ID';
10550: $text{'action'} = 'an ID';
1.615 raeburn 10551: if ($count > 1) {
10552: $text{'item'} = 'IDs';
10553: $text{'action'} = 'IDs';
10554: }
1.612 raeburn 10555: }
1.674 bisitz 10556: $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 10557: if ($mode eq 'upload') {
10558: if ($checkitem eq 'username') {
10559: $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'}.");
10560: } elsif ($checkitem eq 'id') {
1.674 bisitz 10561: $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 10562: }
1.669 raeburn 10563: } elsif ($mode eq 'selfcreate') {
10564: if ($checkitem eq 'id') {
10565: $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.");
10566: }
1.615 raeburn 10567: } else {
10568: if ($checkitem eq 'username') {
10569: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10570: } elsif ($checkitem eq 'id') {
10571: $response .= &mt("You must either choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or leave the ID field blank.");
10572: }
1.612 raeburn 10573: }
10574: return $response;
1.585 raeburn 10575: }
10576:
1.624 raeburn 10577: sub personal_data_fieldtitles {
10578: my %fieldtitles = &Apache::lonlocal::texthash (
10579: id => 'Student/Employee ID',
10580: permanentemail => 'E-mail address',
10581: lastname => 'Last Name',
10582: firstname => 'First Name',
10583: middlename => 'Middle Name',
10584: generation => 'Generation',
10585: gen => 'Generation',
1.765 raeburn 10586: inststatus => 'Affiliation',
1.624 raeburn 10587: );
10588: return %fieldtitles;
10589: }
10590:
1.642 raeburn 10591: sub sorted_inst_types {
10592: my ($dom) = @_;
1.1185 raeburn 10593: my ($usertypes,$order);
10594: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10595: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10596: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10597: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10598: } else {
10599: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10600: }
1.642 raeburn 10601: my $othertitle = &mt('All users');
10602: if ($env{'request.course.id'}) {
1.668 raeburn 10603: $othertitle = &mt('Any users');
1.642 raeburn 10604: }
10605: my @types;
10606: if (ref($order) eq 'ARRAY') {
10607: @types = @{$order};
10608: }
10609: if (@types == 0) {
10610: if (ref($usertypes) eq 'HASH') {
10611: @types = sort(keys(%{$usertypes}));
10612: }
10613: }
10614: if (keys(%{$usertypes}) > 0) {
10615: $othertitle = &mt('Other users');
10616: }
10617: return ($othertitle,$usertypes,\@types);
10618: }
10619:
1.645 raeburn 10620: sub get_institutional_codes {
10621: my ($settings,$allcourses,$LC_code) = @_;
10622: # Get complete list of course sections to update
10623: my @currsections = ();
10624: my @currxlists = ();
10625: my $coursecode = $$settings{'internal.coursecode'};
10626:
10627: if ($$settings{'internal.sectionnums'} ne '') {
10628: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10629: }
10630:
10631: if ($$settings{'internal.crosslistings'} ne '') {
10632: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10633: }
10634:
10635: if (@currxlists > 0) {
10636: foreach (@currxlists) {
10637: if (m/^([^:]+):(\w*)$/) {
10638: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 10639: push(@{$allcourses},$1);
1.645 raeburn 10640: $$LC_code{$1} = $2;
10641: }
10642: }
10643: }
10644: }
10645:
10646: if (@currsections > 0) {
10647: foreach (@currsections) {
10648: if (m/^(\w+):(\w*)$/) {
10649: my $sec = $coursecode.$1;
10650: my $lc_sec = $2;
10651: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 10652: push(@{$allcourses},$sec);
1.645 raeburn 10653: $$LC_code{$sec} = $lc_sec;
10654: }
10655: }
10656: }
10657: }
10658: return;
10659: }
10660:
1.971 raeburn 10661: sub get_standard_codeitems {
10662: return ('Year','Semester','Department','Number','Section');
10663: }
10664:
1.112 bowersj2 10665: =pod
10666:
1.780 raeburn 10667: =head1 Slot Helpers
10668:
10669: =over 4
10670:
10671: =item * sorted_slots()
10672:
1.1040 raeburn 10673: Sorts an array of slot names in order of an optional sort key,
10674: default sort is by slot start time (earliest first).
1.780 raeburn 10675:
10676: Inputs:
10677:
10678: =over 4
10679:
10680: slotsarr - Reference to array of unsorted slot names.
10681:
10682: slots - Reference to hash of hash, where outer hash keys are slot names.
10683:
1.1040 raeburn 10684: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10685:
1.549 albertel 10686: =back
10687:
1.780 raeburn 10688: Returns:
10689:
10690: =over 4
10691:
1.1040 raeburn 10692: sorted - An array of slot names sorted by a specified sort key
10693: (default sort key is start time of the slot).
1.780 raeburn 10694:
10695: =back
10696:
10697: =cut
10698:
10699:
10700: sub sorted_slots {
1.1040 raeburn 10701: my ($slotsarr,$slots,$sortkey) = @_;
10702: if ($sortkey eq '') {
10703: $sortkey = 'starttime';
10704: }
1.780 raeburn 10705: my @sorted;
10706: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10707: @sorted =
10708: sort {
10709: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10710: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10711: }
10712: if (ref($slots->{$a})) { return -1;}
10713: if (ref($slots->{$b})) { return 1;}
10714: return 0;
10715: } @{$slotsarr};
10716: }
10717: return @sorted;
10718: }
10719:
1.1040 raeburn 10720: =pod
10721:
10722: =item * get_future_slots()
10723:
10724: Inputs:
10725:
10726: =over 4
10727:
10728: cnum - course number
10729:
10730: cdom - course domain
10731:
10732: now - current UNIX time
10733:
10734: symb - optional symb
10735:
10736: =back
10737:
10738: Returns:
10739:
10740: =over 4
10741:
10742: sorted_reservable - ref to array of student_schedulable slots currently
10743: reservable, ordered by end date of reservation period.
10744:
10745: reservable_now - ref to hash of student_schedulable slots currently
10746: reservable.
10747:
10748: Keys in inner hash are:
10749: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10750: (b) endreserve: end date of reservation period.
10751: (c) uniqueperiod: start,end dates when slot is to be uniquely
10752: selected.
1.1040 raeburn 10753:
10754: sorted_future - ref to array of student_schedulable slots reservable in
10755: the future, ordered by start date of reservation period.
10756:
10757: future_reservable - ref to hash of student_schedulable slots reservable
10758: in the future.
10759:
10760: Keys in inner hash are:
10761: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10762: (b) startreserve: start date of reservation period.
10763: (c) uniqueperiod: start,end dates when slot is to be uniquely
10764: selected.
1.1040 raeburn 10765:
10766: =back
10767:
10768: =cut
10769:
10770: sub get_future_slots {
10771: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 10772: my $map;
10773: if ($symb) {
10774: ($map) = &Apache::lonnet::decode_symb($symb);
10775: }
1.1040 raeburn 10776: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10777: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10778: foreach my $slot (keys(%slots)) {
10779: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10780: if ($symb) {
1.1229 raeburn 10781: if ($slots{$slot}->{'symb'} ne '') {
10782: my $canuse;
10783: my %oksymbs;
10784: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
10785: map { $oksymbs{$_} = 1; } @slotsymbs;
10786: if ($oksymbs{$symb}) {
10787: $canuse = 1;
10788: } else {
10789: foreach my $item (@slotsymbs) {
10790: if ($item =~ /\.(page|sequence)$/) {
10791: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
10792: if (($map ne '') && ($map eq $sloturl)) {
10793: $canuse = 1;
10794: last;
10795: }
10796: }
10797: }
10798: }
10799: next unless ($canuse);
10800: }
1.1040 raeburn 10801: }
10802: if (($slots{$slot}->{'starttime'} > $now) &&
10803: ($slots{$slot}->{'endtime'} > $now)) {
10804: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10805: my $userallowed = 0;
10806: if ($slots{$slot}->{'allowedsections'}) {
10807: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10808: if (!defined($env{'request.role.sec'})
10809: && grep(/^No section assigned$/,@allowed_sec)) {
10810: $userallowed=1;
10811: } else {
10812: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10813: $userallowed=1;
10814: }
10815: }
10816: unless ($userallowed) {
10817: if (defined($env{'request.course.groups'})) {
10818: my @groups = split(/:/,$env{'request.course.groups'});
10819: foreach my $group (@groups) {
10820: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10821: $userallowed=1;
10822: last;
10823: }
10824: }
10825: }
10826: }
10827: }
10828: if ($slots{$slot}->{'allowedusers'}) {
10829: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10830: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10831: if (grep(/^\Q$user\E$/,@allowed_users)) {
10832: $userallowed = 1;
10833: }
10834: }
10835: next unless($userallowed);
10836: }
10837: my $startreserve = $slots{$slot}->{'startreserve'};
10838: my $endreserve = $slots{$slot}->{'endreserve'};
10839: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 10840: my $uniqueperiod;
10841: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10842: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10843: }
1.1040 raeburn 10844: if (($startreserve < $now) &&
10845: (!$endreserve || $endreserve > $now)) {
10846: my $lastres = $endreserve;
10847: if (!$lastres) {
10848: $lastres = $slots{$slot}->{'starttime'};
10849: }
10850: $reservable_now{$slot} = {
10851: symb => $symb,
1.1250 raeburn 10852: endreserve => $lastres,
10853: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10854: };
10855: } elsif (($startreserve > $now) &&
10856: (!$endreserve || $endreserve > $startreserve)) {
10857: $future_reservable{$slot} = {
10858: symb => $symb,
1.1250 raeburn 10859: startreserve => $startreserve,
10860: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10861: };
10862: }
10863: }
10864: }
10865: my @unsorted_reservable = keys(%reservable_now);
10866: if (@unsorted_reservable > 0) {
10867: @sorted_reservable =
10868: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10869: }
10870: my @unsorted_future = keys(%future_reservable);
10871: if (@unsorted_future > 0) {
10872: @sorted_future =
10873: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10874: }
10875: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10876: }
1.780 raeburn 10877:
10878: =pod
10879:
1.1057 foxr 10880: =back
10881:
1.549 albertel 10882: =head1 HTTP Helpers
10883:
10884: =over 4
10885:
1.648 raeburn 10886: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10887:
1.258 albertel 10888: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10889: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10890: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10891:
10892: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10893: $possible_names is an ref to an array of form element names. As an example:
10894: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10895: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10896:
10897: =cut
1.1 albertel 10898:
1.6 albertel 10899: sub get_unprocessed_cgi {
1.25 albertel 10900: my ($query,$possible_names)= @_;
1.26 matthew 10901: # $Apache::lonxml::debug=1;
1.356 albertel 10902: foreach my $pair (split(/&/,$query)) {
10903: my ($name, $value) = split(/=/,$pair);
1.369 www 10904: $name = &unescape($name);
1.25 albertel 10905: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10906: $value =~ tr/+/ /;
10907: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10908: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10909: }
1.16 harris41 10910: }
1.6 albertel 10911: }
10912:
1.112 bowersj2 10913: =pod
10914:
1.648 raeburn 10915: =item * &cacheheader()
1.112 bowersj2 10916:
10917: returns cache-controlling header code
10918:
10919: =cut
10920:
1.7 albertel 10921: sub cacheheader {
1.258 albertel 10922: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10923: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10924: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10925: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10926: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10927: return $output;
1.7 albertel 10928: }
10929:
1.112 bowersj2 10930: =pod
10931:
1.648 raeburn 10932: =item * &no_cache($r)
1.112 bowersj2 10933:
10934: specifies header code to not have cache
10935:
10936: =cut
10937:
1.9 albertel 10938: sub no_cache {
1.216 albertel 10939: my ($r) = @_;
10940: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10941: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10942: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10943: $r->no_cache(1);
10944: $r->header_out("Expires" => $date);
10945: $r->header_out("Pragma" => "no-cache");
1.123 www 10946: }
10947:
10948: sub content_type {
1.181 albertel 10949: my ($r,$type,$charset) = @_;
1.299 foxr 10950: if ($r) {
10951: # Note that printout.pl calls this with undef for $r.
10952: &no_cache($r);
10953: }
1.258 albertel 10954: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10955: unless ($charset) {
10956: $charset=&Apache::lonlocal::current_encoding;
10957: }
10958: if ($charset) { $type.='; charset='.$charset; }
10959: if ($r) {
10960: $r->content_type($type);
10961: } else {
10962: print("Content-type: $type\n\n");
10963: }
1.9 albertel 10964: }
1.25 albertel 10965:
1.112 bowersj2 10966: =pod
10967:
1.648 raeburn 10968: =item * &add_to_env($name,$value)
1.112 bowersj2 10969:
1.258 albertel 10970: adds $name to the %env hash with value
1.112 bowersj2 10971: $value, if $name already exists, the entry is converted to an array
10972: reference and $value is added to the array.
10973:
10974: =cut
10975:
1.25 albertel 10976: sub add_to_env {
10977: my ($name,$value)=@_;
1.258 albertel 10978: if (defined($env{$name})) {
10979: if (ref($env{$name})) {
1.25 albertel 10980: #already have multiple values
1.258 albertel 10981: push(@{ $env{$name} },$value);
1.25 albertel 10982: } else {
10983: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10984: my $first=$env{$name};
10985: undef($env{$name});
10986: push(@{ $env{$name} },$first,$value);
1.25 albertel 10987: }
10988: } else {
1.258 albertel 10989: $env{$name}=$value;
1.25 albertel 10990: }
1.31 albertel 10991: }
1.149 albertel 10992:
10993: =pod
10994:
1.648 raeburn 10995: =item * &get_env_multiple($name)
1.149 albertel 10996:
1.258 albertel 10997: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10998: values may be defined and end up as an array ref.
10999:
11000: returns an array of values
11001:
11002: =cut
11003:
11004: sub get_env_multiple {
11005: my ($name) = @_;
11006: my @values;
1.258 albertel 11007: if (defined($env{$name})) {
1.149 albertel 11008: # exists is it an array
1.258 albertel 11009: if (ref($env{$name})) {
11010: @values=@{ $env{$name} };
1.149 albertel 11011: } else {
1.258 albertel 11012: $values[0]=$env{$name};
1.149 albertel 11013: }
11014: }
11015: return(@values);
11016: }
11017:
1.1249 damieng 11018: # Looks at given dependencies, and returns something depending on the context.
11019: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11020: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11021: # For all other contexts, returns ($output, $counter, $numpathchg).
11022: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11023: # $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.
11024: # $numpathchg: integer with the number of cleaned up dependency paths.
11025: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11026: # \%mapping: hash reference clean path -> original path for all dependencies.
11027: # @param {string} actionurl - The path to the handler, indicative of the context.
11028: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11029: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11030: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11031: # @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)
11032: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11033: sub ask_for_embedded_content {
1.1249 damieng 11034: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11035: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11036: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11037: %currsubfile,%unused,$rem);
1.1071 raeburn 11038: my $counter = 0;
11039: my $numnew = 0;
1.987 raeburn 11040: my $numremref = 0;
11041: my $numinvalid = 0;
11042: my $numpathchg = 0;
11043: my $numexisting = 0;
1.1071 raeburn 11044: my $numunused = 0;
11045: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11046: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11047: my $heading = &mt('Upload embedded files');
11048: my $buttontext = &mt('Upload');
11049:
1.1249 damieng 11050: # fills these variables based on the context:
11051: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11052: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11053: if ($env{'request.course.id'}) {
1.1123 raeburn 11054: if ($actionurl eq '/adm/dependencies') {
11055: $navmap = Apache::lonnavmaps::navmap->new();
11056: }
11057: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11058: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11059: }
1.1123 raeburn 11060: if (($actionurl eq '/adm/portfolio') ||
11061: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11062: my $current_path='/';
11063: if ($env{'form.currentpath'}) {
11064: $current_path = $env{'form.currentpath'};
11065: }
11066: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11067: $udom = $cdom;
11068: $uname = $cnum;
1.984 raeburn 11069: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11070: } else {
11071: $udom = $env{'user.domain'};
11072: $uname = $env{'user.name'};
11073: $url = '/userfiles/portfolio';
11074: }
1.987 raeburn 11075: $toplevel = $url.'/';
1.984 raeburn 11076: $url .= $current_path;
11077: $getpropath = 1;
1.987 raeburn 11078: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11079: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11080: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11081: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11082: $toplevel = $url;
1.984 raeburn 11083: if ($rest ne '') {
1.987 raeburn 11084: $url .= $rest;
11085: }
11086: } elsif ($actionurl eq '/adm/coursedocs') {
11087: if (ref($args) eq 'HASH') {
1.1071 raeburn 11088: $url = $args->{'docs_url'};
11089: $toplevel = $url;
1.1084 raeburn 11090: if ($args->{'context'} eq 'paste') {
11091: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11092: ($path) =
11093: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11094: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11095: $fileloc =~ s{^/}{};
11096: }
1.1071 raeburn 11097: }
1.1084 raeburn 11098: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11099: if ($env{'request.course.id'} ne '') {
11100: if (ref($args) eq 'HASH') {
11101: $url = $args->{'docs_url'};
11102: $title = $args->{'docs_title'};
1.1126 raeburn 11103: $toplevel = $url;
11104: unless ($toplevel =~ m{^/}) {
11105: $toplevel = "/$url";
11106: }
1.1085 raeburn 11107: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11108: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11109: $path = $1;
11110: } else {
11111: ($path) =
11112: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11113: }
1.1195 raeburn 11114: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11115: $fileloc = $toplevel;
11116: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11117: my ($udom,$uname,$fname) =
11118: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11119: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11120: } else {
11121: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11122: }
1.1071 raeburn 11123: $fileloc =~ s{^/}{};
11124: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11125: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11126: }
1.987 raeburn 11127: }
1.1123 raeburn 11128: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11129: $udom = $cdom;
11130: $uname = $cnum;
11131: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11132: $toplevel = $url;
11133: $path = $url;
11134: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11135: $fileloc =~ s{^/}{};
1.987 raeburn 11136: }
1.1249 damieng 11137:
11138: # parses the dependency paths to get some info
11139: # fills $newfiles, $mapping, $subdependencies, $dependencies
11140: # $newfiles: hash URL -> 1 for new files or external URLs
11141: # (will be completed later)
11142: # $mapping:
11143: # for external URLs: external URL -> external URL
11144: # for relative paths: clean path -> original path
11145: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11146: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11147: foreach my $file (keys(%{$allfiles})) {
11148: my $embed_file;
11149: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11150: $embed_file = $1;
11151: } else {
11152: $embed_file = $file;
11153: }
1.1158 raeburn 11154: my ($absolutepath,$cleaned_file);
11155: if ($embed_file =~ m{^\w+://}) {
11156: $cleaned_file = $embed_file;
1.1147 raeburn 11157: $newfiles{$cleaned_file} = 1;
11158: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11159: } else {
1.1158 raeburn 11160: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11161: if ($embed_file =~ m{^/}) {
11162: $absolutepath = $embed_file;
11163: }
1.1147 raeburn 11164: if ($cleaned_file =~ m{/}) {
11165: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11166: $path = &check_for_traversal($path,$url,$toplevel);
11167: my $item = $fname;
11168: if ($path ne '') {
11169: $item = $path.'/'.$fname;
11170: $subdependencies{$path}{$fname} = 1;
11171: } else {
11172: $dependencies{$item} = 1;
11173: }
11174: if ($absolutepath) {
11175: $mapping{$item} = $absolutepath;
11176: } else {
11177: $mapping{$item} = $embed_file;
11178: }
11179: } else {
11180: $dependencies{$embed_file} = 1;
11181: if ($absolutepath) {
1.1147 raeburn 11182: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11183: } else {
1.1147 raeburn 11184: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11185: }
11186: }
1.984 raeburn 11187: }
11188: }
1.1249 damieng 11189:
11190: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11191: # and lists
11192: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11193: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11194: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11195: # the path had to be cleaned up
11196: # $existing: hash clean path -> 1 if the file exists
11197: # $numexisting: number of keys in $existing
11198: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11199: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11200: # dependency subdirectories that are
11201: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11202: my $dirptr = 16384;
1.984 raeburn 11203: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11204: $currsubfile{$path} = {};
1.1123 raeburn 11205: if (($actionurl eq '/adm/portfolio') ||
11206: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11207: my ($sublistref,$listerror) =
11208: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11209: if (ref($sublistref) eq 'ARRAY') {
11210: foreach my $line (@{$sublistref}) {
11211: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11212: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11213: }
1.984 raeburn 11214: }
1.987 raeburn 11215: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11216: if (opendir(my $dir,$url.'/'.$path)) {
11217: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11218: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11219: }
1.1084 raeburn 11220: } elsif (($actionurl eq '/adm/dependencies') ||
11221: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11222: ($args->{'context'} eq 'paste')) ||
11223: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11224: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11225: my $dir;
11226: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11227: $dir = $fileloc;
11228: } else {
11229: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11230: }
1.1071 raeburn 11231: if ($dir ne '') {
11232: my ($sublistref,$listerror) =
11233: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11234: if (ref($sublistref) eq 'ARRAY') {
11235: foreach my $line (@{$sublistref}) {
11236: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11237: undef,$mtime)=split(/\&/,$line,12);
11238: unless (($testdir&$dirptr) ||
11239: ($file_name =~ /^\.\.?$/)) {
11240: $currsubfile{$path}{$file_name} = [$size,$mtime];
11241: }
11242: }
11243: }
11244: }
1.984 raeburn 11245: }
11246: }
11247: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11248: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11249: my $item = $path.'/'.$file;
11250: unless ($mapping{$item} eq $item) {
11251: $pathchanges{$item} = 1;
11252: }
11253: $existing{$item} = 1;
11254: $numexisting ++;
11255: } else {
11256: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11257: }
11258: }
1.1071 raeburn 11259: if ($actionurl eq '/adm/dependencies') {
11260: foreach my $path (keys(%currsubfile)) {
11261: if (ref($currsubfile{$path}) eq 'HASH') {
11262: foreach my $file (keys(%{$currsubfile{$path}})) {
11263: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11264: next if (($rem ne '') &&
11265: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11266: (ref($navmap) &&
11267: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11268: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11269: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11270: $unused{$path.'/'.$file} = 1;
11271: }
11272: }
11273: }
11274: }
11275: }
1.984 raeburn 11276: }
1.1249 damieng 11277:
11278: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11279: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11280: my %currfile;
1.1123 raeburn 11281: if (($actionurl eq '/adm/portfolio') ||
11282: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11283: my ($dirlistref,$listerror) =
11284: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11285: if (ref($dirlistref) eq 'ARRAY') {
11286: foreach my $line (@{$dirlistref}) {
11287: my ($file_name,$rest) = split(/\&/,$line,2);
11288: $currfile{$file_name} = 1;
11289: }
1.984 raeburn 11290: }
1.987 raeburn 11291: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11292: if (opendir(my $dir,$url)) {
1.987 raeburn 11293: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11294: map {$currfile{$_} = 1;} @dir_list;
11295: }
1.1084 raeburn 11296: } elsif (($actionurl eq '/adm/dependencies') ||
11297: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11298: ($args->{'context'} eq 'paste')) ||
11299: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11300: if ($env{'request.course.id'} ne '') {
11301: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11302: if ($dir ne '') {
11303: my ($dirlistref,$listerror) =
11304: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11305: if (ref($dirlistref) eq 'ARRAY') {
11306: foreach my $line (@{$dirlistref}) {
11307: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11308: $size,undef,$mtime)=split(/\&/,$line,12);
11309: unless (($testdir&$dirptr) ||
11310: ($file_name =~ /^\.\.?$/)) {
11311: $currfile{$file_name} = [$size,$mtime];
11312: }
11313: }
11314: }
11315: }
11316: }
1.984 raeburn 11317: }
1.1249 damieng 11318: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11319: # are not in subdirectories, using $currfile
1.984 raeburn 11320: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11321: if (exists($currfile{$file})) {
1.987 raeburn 11322: unless ($mapping{$file} eq $file) {
11323: $pathchanges{$file} = 1;
11324: }
11325: $existing{$file} = 1;
11326: $numexisting ++;
11327: } else {
1.984 raeburn 11328: $newfiles{$file} = 1;
11329: }
11330: }
1.1071 raeburn 11331: foreach my $file (keys(%currfile)) {
11332: unless (($file eq $filename) ||
11333: ($file eq $filename.'.bak') ||
11334: ($dependencies{$file})) {
1.1085 raeburn 11335: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11336: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11337: next if (($rem ne '') &&
11338: (($env{"httpref.$rem".$file} ne '') ||
11339: (ref($navmap) &&
11340: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11341: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11342: ($navmap->getResourceByUrl($rem.$1)))))));
11343: }
1.1085 raeburn 11344: }
1.1071 raeburn 11345: $unused{$file} = 1;
11346: }
11347: }
1.1249 damieng 11348:
11349: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11350: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11351: ($args->{'context'} eq 'paste')) {
11352: $counter = scalar(keys(%existing));
11353: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11354: return ($output,$counter,$numpathchg,\%existing);
11355: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11356: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11357: $counter = scalar(keys(%existing));
11358: $numpathchg = scalar(keys(%pathchanges));
11359: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11360: }
1.1249 damieng 11361:
11362: # returns HTML otherwise, with dependency results and to ask for more uploads
11363:
11364: # $upload_output: missing dependencies (with upload form)
11365: # $modify_output: uploaded dependencies (in use)
11366: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11367: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11368: if ($actionurl eq '/adm/dependencies') {
11369: next if ($embed_file =~ m{^\w+://});
11370: }
1.660 raeburn 11371: $upload_output .= &start_data_table_row().
1.1123 raeburn 11372: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11373: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11374: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11375: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11376: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11377: }
1.1123 raeburn 11378: $upload_output .= '</td>';
1.1071 raeburn 11379: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11380: $upload_output.='<td align="right">'.
11381: '<span class="LC_info LC_fontsize_medium">'.
11382: &mt("URL points to web address").'</span>';
1.987 raeburn 11383: $numremref++;
1.660 raeburn 11384: } elsif ($args->{'error_on_invalid_names'}
11385: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11386: $upload_output.='<td align="right"><span class="LC_warning">'.
11387: &mt('Invalid characters').'</span>';
1.987 raeburn 11388: $numinvalid++;
1.660 raeburn 11389: } else {
1.1123 raeburn 11390: $upload_output .= '<td>'.
11391: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11392: $embed_file,\%mapping,
1.1071 raeburn 11393: $allfiles,$codebase,'upload');
11394: $counter ++;
11395: $numnew ++;
1.987 raeburn 11396: }
11397: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11398: }
11399: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11400: if ($actionurl eq '/adm/dependencies') {
11401: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11402: $modify_output .= &start_data_table_row().
11403: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11404: '<img src="'.&icon($embed_file).'" border="0" />'.
11405: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11406: '<td>'.$size.'</td>'.
11407: '<td>'.$mtime.'</td>'.
11408: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11409: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11410: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11411: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11412: &embedded_file_element('upload_embedded',$counter,
11413: $embed_file,\%mapping,
11414: $allfiles,$codebase,'modify').
11415: '</div></td>'.
11416: &end_data_table_row()."\n";
11417: $counter ++;
11418: } else {
11419: $upload_output .= &start_data_table_row().
1.1123 raeburn 11420: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11421: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11422: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11423: &Apache::loncommon::end_data_table_row()."\n";
11424: }
11425: }
11426: my $delidx = $counter;
11427: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11428: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11429: $delete_output .= &start_data_table_row().
11430: '<td><img src="'.&icon($oldfile).'" />'.
11431: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11432: '<td>'.$size.'</td>'.
11433: '<td>'.$mtime.'</td>'.
11434: '<td><label><input type="checkbox" name="del_upload_dep" '.
11435: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11436: &embedded_file_element('upload_embedded',$delidx,
11437: $oldfile,\%mapping,$allfiles,
11438: $codebase,'delete').'</td>'.
11439: &end_data_table_row()."\n";
11440: $numunused ++;
11441: $delidx ++;
1.987 raeburn 11442: }
11443: if ($upload_output) {
11444: $upload_output = &start_data_table().
11445: $upload_output.
11446: &end_data_table()."\n";
11447: }
1.1071 raeburn 11448: if ($modify_output) {
11449: $modify_output = &start_data_table().
11450: &start_data_table_header_row().
11451: '<th>'.&mt('File').'</th>'.
11452: '<th>'.&mt('Size (KB)').'</th>'.
11453: '<th>'.&mt('Modified').'</th>'.
11454: '<th>'.&mt('Upload replacement?').'</th>'.
11455: &end_data_table_header_row().
11456: $modify_output.
11457: &end_data_table()."\n";
11458: }
11459: if ($delete_output) {
11460: $delete_output = &start_data_table().
11461: &start_data_table_header_row().
11462: '<th>'.&mt('File').'</th>'.
11463: '<th>'.&mt('Size (KB)').'</th>'.
11464: '<th>'.&mt('Modified').'</th>'.
11465: '<th>'.&mt('Delete?').'</th>'.
11466: &end_data_table_header_row().
11467: $delete_output.
11468: &end_data_table()."\n";
11469: }
1.987 raeburn 11470: my $applies = 0;
11471: if ($numremref) {
11472: $applies ++;
11473: }
11474: if ($numinvalid) {
11475: $applies ++;
11476: }
11477: if ($numexisting) {
11478: $applies ++;
11479: }
1.1071 raeburn 11480: if ($counter || $numunused) {
1.987 raeburn 11481: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11482: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11483: $state.'<h3>'.$heading.'</h3>';
11484: if ($actionurl eq '/adm/dependencies') {
11485: if ($numnew) {
11486: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11487: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11488: $upload_output.'<br />'."\n";
11489: }
11490: if ($numexisting) {
11491: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11492: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11493: $modify_output.'<br />'."\n";
11494: $buttontext = &mt('Save changes');
11495: }
11496: if ($numunused) {
11497: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11498: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11499: $delete_output.'<br />'."\n";
11500: $buttontext = &mt('Save changes');
11501: }
11502: } else {
11503: $output .= $upload_output.'<br />'."\n";
11504: }
11505: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11506: $counter.'" />'."\n";
11507: if ($actionurl eq '/adm/dependencies') {
11508: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11509: $numnew.'" />'."\n";
11510: } elsif ($actionurl eq '') {
1.987 raeburn 11511: $output .= '<input type="hidden" name="phase" value="three" />';
11512: }
11513: } elsif ($applies) {
11514: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11515: if ($applies > 1) {
11516: $output .=
1.1123 raeburn 11517: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11518: if ($numremref) {
11519: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11520: }
11521: if ($numinvalid) {
11522: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11523: }
11524: if ($numexisting) {
11525: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11526: }
11527: $output .= '</ul><br />';
11528: } elsif ($numremref) {
11529: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11530: } elsif ($numinvalid) {
11531: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11532: } elsif ($numexisting) {
11533: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11534: }
11535: $output .= $upload_output.'<br />';
11536: }
11537: my ($pathchange_output,$chgcount);
1.1071 raeburn 11538: $chgcount = $counter;
1.987 raeburn 11539: if (keys(%pathchanges) > 0) {
11540: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11541: if ($counter) {
1.987 raeburn 11542: $output .= &embedded_file_element('pathchange',$chgcount,
11543: $embed_file,\%mapping,
1.1071 raeburn 11544: $allfiles,$codebase,'change');
1.987 raeburn 11545: } else {
11546: $pathchange_output .=
11547: &start_data_table_row().
11548: '<td><input type ="checkbox" name="namechange" value="'.
11549: $chgcount.'" checked="checked" /></td>'.
11550: '<td>'.$mapping{$embed_file}.'</td>'.
11551: '<td>'.$embed_file.
11552: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11553: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11554: '</td>'.&end_data_table_row();
1.660 raeburn 11555: }
1.987 raeburn 11556: $numpathchg ++;
11557: $chgcount ++;
1.660 raeburn 11558: }
11559: }
1.1127 raeburn 11560: if (($counter) || ($numunused)) {
1.987 raeburn 11561: if ($numpathchg) {
11562: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11563: $numpathchg.'" />'."\n";
11564: }
11565: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11566: ($actionurl eq '/adm/imsimport')) {
11567: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11568: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11569: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11570: } elsif ($actionurl eq '/adm/dependencies') {
11571: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11572: }
1.1123 raeburn 11573: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11574: } elsif ($numpathchg) {
11575: my %pathchange = ();
11576: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11577: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11578: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11579: }
1.987 raeburn 11580: }
1.1071 raeburn 11581: return ($output,$counter,$numpathchg);
1.987 raeburn 11582: }
11583:
1.1147 raeburn 11584: =pod
11585:
11586: =item * clean_path($name)
11587:
11588: Performs clean-up of directories, subdirectories and filename in an
11589: embedded object, referenced in an HTML file which is being uploaded
11590: to a course or portfolio, where
11591: "Upload embedded images/multimedia files if HTML file" checkbox was
11592: checked.
11593:
11594: Clean-up is similar to replacements in lonnet::clean_filename()
11595: except each / between sub-directory and next level is preserved.
11596:
11597: =cut
11598:
11599: sub clean_path {
11600: my ($embed_file) = @_;
11601: $embed_file =~s{^/+}{};
11602: my @contents;
11603: if ($embed_file =~ m{/}) {
11604: @contents = split(/\//,$embed_file);
11605: } else {
11606: @contents = ($embed_file);
11607: }
11608: my $lastidx = scalar(@contents)-1;
11609: for (my $i=0; $i<=$lastidx; $i++) {
11610: $contents[$i]=~s{\\}{/}g;
11611: $contents[$i]=~s/\s+/\_/g;
11612: $contents[$i]=~s{[^/\w\.\-]}{}g;
11613: if ($i == $lastidx) {
11614: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11615: }
11616: }
11617: if ($lastidx > 0) {
11618: return join('/',@contents);
11619: } else {
11620: return $contents[0];
11621: }
11622: }
11623:
1.987 raeburn 11624: sub embedded_file_element {
1.1071 raeburn 11625: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11626: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11627: (ref($codebase) eq 'HASH'));
11628: my $output;
1.1071 raeburn 11629: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11630: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11631: }
11632: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11633: &escape($embed_file).'" />';
11634: unless (($context eq 'upload_embedded') &&
11635: ($mapping->{$embed_file} eq $embed_file)) {
11636: $output .='
11637: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11638: }
11639: my $attrib;
11640: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11641: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11642: }
11643: $output .=
11644: "\n\t\t".
11645: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11646: $attrib.'" />';
11647: if (exists($codebase->{$mapping->{$embed_file}})) {
11648: $output .=
11649: "\n\t\t".
11650: '<input name="codebase_'.$num.'" type="hidden" value="'.
11651: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11652: }
1.987 raeburn 11653: return $output;
1.660 raeburn 11654: }
11655:
1.1071 raeburn 11656: sub get_dependency_details {
11657: my ($currfile,$currsubfile,$embed_file) = @_;
11658: my ($size,$mtime,$showsize,$showmtime);
11659: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11660: if ($embed_file =~ m{/}) {
11661: my ($path,$fname) = split(/\//,$embed_file);
11662: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11663: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11664: }
11665: } else {
11666: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11667: ($size,$mtime) = @{$currfile->{$embed_file}};
11668: }
11669: }
11670: $showsize = $size/1024.0;
11671: $showsize = sprintf("%.1f",$showsize);
11672: if ($mtime > 0) {
11673: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11674: }
11675: }
11676: return ($showsize,$showmtime);
11677: }
11678:
11679: sub ask_embedded_js {
11680: return <<"END";
11681: <script type="text/javascript"">
11682: // <![CDATA[
11683: function toggleBrowse(counter) {
11684: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11685: var fileid = document.getElementById('embedded_item_'+counter);
11686: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11687: if (chkboxid.checked == true) {
11688: uploaddivid.style.display='block';
11689: } else {
11690: uploaddivid.style.display='none';
11691: fileid.value = '';
11692: }
11693: }
11694: // ]]>
11695: </script>
11696:
11697: END
11698: }
11699:
1.661 raeburn 11700: sub upload_embedded {
11701: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11702: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11703: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11704: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11705: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11706: my $orig_uploaded_filename =
11707: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11708: foreach my $type ('orig','ref','attrib','codebase') {
11709: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11710: $env{'form.embedded_'.$type.'_'.$i} =
11711: &unescape($env{'form.embedded_'.$type.'_'.$i});
11712: }
11713: }
1.661 raeburn 11714: my ($path,$fname) =
11715: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11716: # no path, whole string is fname
11717: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11718: $fname = &Apache::lonnet::clean_filename($fname);
11719: # See if there is anything left
11720: next if ($fname eq '');
11721:
11722: # Check if file already exists as a file or directory.
11723: my ($state,$msg);
11724: if ($context eq 'portfolio') {
11725: my $port_path = $dirpath;
11726: if ($group ne '') {
11727: $port_path = "groups/$group/$port_path";
11728: }
1.987 raeburn 11729: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11730: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11731: $dir_root,$port_path,$disk_quota,
11732: $current_disk_usage,$uname,$udom);
11733: if ($state eq 'will_exceed_quota'
1.984 raeburn 11734: || $state eq 'file_locked') {
1.661 raeburn 11735: $output .= $msg;
11736: next;
11737: }
11738: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11739: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11740: if ($state eq 'exists') {
11741: $output .= $msg;
11742: next;
11743: }
11744: }
11745: # Check if extension is valid
11746: if (($fname =~ /\.(\w+)$/) &&
11747: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11748: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11749: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11750: next;
11751: } elsif (($fname =~ /\.(\w+)$/) &&
11752: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11753: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11754: next;
11755: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11756: $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 11757: next;
11758: }
11759: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11760: my $subdir = $path;
11761: $subdir =~ s{/+$}{};
1.661 raeburn 11762: if ($context eq 'portfolio') {
1.984 raeburn 11763: my $result;
11764: if ($state eq 'existingfile') {
11765: $result=
11766: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11767: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11768: } else {
1.984 raeburn 11769: $result=
11770: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11771: $dirpath.
1.1123 raeburn 11772: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11773: if ($result !~ m|^/uploaded/|) {
11774: $output .= '<span class="LC_error">'
11775: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11776: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11777: .'</span><br />';
11778: next;
11779: } else {
1.987 raeburn 11780: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11781: $path.$fname.'</span>').'<br />';
1.984 raeburn 11782: }
1.661 raeburn 11783: }
1.1123 raeburn 11784: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 11785: my $extendedsubdir = $dirpath.'/'.$subdir;
11786: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11787: my $result =
1.1126 raeburn 11788: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11789: if ($result !~ m|^/uploaded/|) {
11790: $output .= '<span class="LC_error">'
11791: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11792: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11793: .'</span><br />';
11794: next;
11795: } else {
11796: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11797: $path.$fname.'</span>').'<br />';
1.1125 raeburn 11798: if ($context eq 'syllabus') {
11799: &Apache::lonnet::make_public_indefinitely($result);
11800: }
1.987 raeburn 11801: }
1.661 raeburn 11802: } else {
11803: # Save the file
11804: my $target = $env{'form.embedded_item_'.$i};
11805: my $fullpath = $dir_root.$dirpath.'/'.$path;
11806: my $dest = $fullpath.$fname;
11807: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11808: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11809: my $count;
11810: my $filepath = $dir_root;
1.1027 raeburn 11811: foreach my $subdir (@parts) {
11812: $filepath .= "/$subdir";
11813: if (!-e $filepath) {
1.661 raeburn 11814: mkdir($filepath,0770);
11815: }
11816: }
11817: my $fh;
11818: if (!open($fh,'>'.$dest)) {
11819: &Apache::lonnet::logthis('Failed to create '.$dest);
11820: $output .= '<span class="LC_error">'.
1.1071 raeburn 11821: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11822: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11823: '</span><br />';
11824: } else {
11825: if (!print $fh $env{'form.embedded_item_'.$i}) {
11826: &Apache::lonnet::logthis('Failed to write to '.$dest);
11827: $output .= '<span class="LC_error">'.
1.1071 raeburn 11828: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11829: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11830: '</span><br />';
11831: } else {
1.987 raeburn 11832: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11833: $url.'</span>').'<br />';
11834: unless ($context eq 'testbank') {
11835: $footer .= &mt('View embedded file: [_1]',
11836: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11837: }
11838: }
11839: close($fh);
11840: }
11841: }
11842: if ($env{'form.embedded_ref_'.$i}) {
11843: $pathchange{$i} = 1;
11844: }
11845: }
11846: if ($output) {
11847: $output = '<p>'.$output.'</p>';
11848: }
11849: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11850: $returnflag = 'ok';
1.1071 raeburn 11851: my $numpathchgs = scalar(keys(%pathchange));
11852: if ($numpathchgs > 0) {
1.987 raeburn 11853: if ($context eq 'portfolio') {
11854: $output .= '<p>'.&mt('or').'</p>';
11855: } elsif ($context eq 'testbank') {
1.1071 raeburn 11856: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11857: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11858: $returnflag = 'modify_orightml';
11859: }
11860: }
1.1071 raeburn 11861: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11862: }
11863:
11864: sub modify_html_form {
11865: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11866: my $end = 0;
11867: my $modifyform;
11868: if ($context eq 'upload_embedded') {
11869: return unless (ref($pathchange) eq 'HASH');
11870: if ($env{'form.number_embedded_items'}) {
11871: $end += $env{'form.number_embedded_items'};
11872: }
11873: if ($env{'form.number_pathchange_items'}) {
11874: $end += $env{'form.number_pathchange_items'};
11875: }
11876: if ($end) {
11877: for (my $i=0; $i<$end; $i++) {
11878: if ($i < $env{'form.number_embedded_items'}) {
11879: next unless($pathchange->{$i});
11880: }
11881: $modifyform .=
11882: &start_data_table_row().
11883: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11884: 'checked="checked" /></td>'.
11885: '<td>'.$env{'form.embedded_ref_'.$i}.
11886: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11887: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11888: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11889: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11890: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11891: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11892: '<td>'.$env{'form.embedded_orig_'.$i}.
11893: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11894: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11895: &end_data_table_row();
1.1071 raeburn 11896: }
1.987 raeburn 11897: }
11898: } else {
11899: $modifyform = $pathchgtable;
11900: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11901: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11902: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11903: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11904: }
11905: }
11906: if ($modifyform) {
1.1071 raeburn 11907: if ($actionurl eq '/adm/dependencies') {
11908: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11909: }
1.987 raeburn 11910: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11911: '<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".
11912: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11913: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11914: '</ol></p>'."\n".'<p>'.
11915: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11916: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11917: &start_data_table()."\n".
11918: &start_data_table_header_row().
11919: '<th>'.&mt('Change?').'</th>'.
11920: '<th>'.&mt('Current reference').'</th>'.
11921: '<th>'.&mt('Required reference').'</th>'.
11922: &end_data_table_header_row()."\n".
11923: $modifyform.
11924: &end_data_table().'<br />'."\n".$hiddenstate.
11925: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11926: '</form>'."\n";
11927: }
11928: return;
11929: }
11930:
11931: sub modify_html_refs {
1.1123 raeburn 11932: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11933: my $container;
11934: if ($context eq 'portfolio') {
11935: $container = $env{'form.container'};
11936: } elsif ($context eq 'coursedoc') {
11937: $container = $env{'form.primaryurl'};
1.1071 raeburn 11938: } elsif ($context eq 'manage_dependencies') {
11939: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11940: $container = "/$container";
1.1123 raeburn 11941: } elsif ($context eq 'syllabus') {
11942: $container = $url;
1.987 raeburn 11943: } else {
1.1027 raeburn 11944: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11945: }
11946: my (%allfiles,%codebase,$output,$content);
11947: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 11948: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11949: if (wantarray) {
11950: return ('',0,0);
11951: } else {
11952: return;
11953: }
11954: }
11955: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11956: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11957: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11958: if (wantarray) {
11959: return ('',0,0);
11960: } else {
11961: return;
11962: }
11963: }
1.987 raeburn 11964: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11965: if ($content eq '-1') {
11966: if (wantarray) {
11967: return ('',0,0);
11968: } else {
11969: return;
11970: }
11971: }
1.987 raeburn 11972: } else {
1.1071 raeburn 11973: unless ($container =~ /^\Q$dir_root\E/) {
11974: if (wantarray) {
11975: return ('',0,0);
11976: } else {
11977: return;
11978: }
11979: }
1.987 raeburn 11980: if (open(my $fh,"<$container")) {
11981: $content = join('', <$fh>);
11982: close($fh);
11983: } else {
1.1071 raeburn 11984: if (wantarray) {
11985: return ('',0,0);
11986: } else {
11987: return;
11988: }
1.987 raeburn 11989: }
11990: }
11991: my ($count,$codebasecount) = (0,0);
11992: my $mm = new File::MMagic;
11993: my $mime_type = $mm->checktype_contents($content);
11994: if ($mime_type eq 'text/html') {
11995: my $parse_result =
11996: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11997: \%codebase,\$content);
11998: if ($parse_result eq 'ok') {
11999: foreach my $i (@changes) {
12000: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12001: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12002: if ($allfiles{$ref}) {
12003: my $newname = $orig;
12004: my ($attrib_regexp,$codebase);
1.1006 raeburn 12005: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12006: if ($attrib_regexp =~ /:/) {
12007: $attrib_regexp =~ s/\:/|/g;
12008: }
12009: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12010: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12011: $count += $numchg;
1.1123 raeburn 12012: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12013: delete($allfiles{$ref});
1.987 raeburn 12014: }
12015: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12016: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12017: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12018: $codebasecount ++;
12019: }
12020: }
12021: }
1.1123 raeburn 12022: my $skiprewrites;
1.987 raeburn 12023: if ($count || $codebasecount) {
12024: my $saveresult;
1.1071 raeburn 12025: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12026: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12027: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12028: if ($url eq $container) {
12029: my ($fname) = ($container =~ m{/([^/]+)$});
12030: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12031: $count,'<span class="LC_filename">'.
1.1071 raeburn 12032: $fname.'</span>').'</p>';
1.987 raeburn 12033: } else {
12034: $output = '<p class="LC_error">'.
12035: &mt('Error: update failed for: [_1].',
12036: '<span class="LC_filename">'.
12037: $container.'</span>').'</p>';
12038: }
1.1123 raeburn 12039: if ($context eq 'syllabus') {
12040: unless ($saveresult eq 'ok') {
12041: $skiprewrites = 1;
12042: }
12043: }
1.987 raeburn 12044: } else {
12045: if (open(my $fh,">$container")) {
12046: print $fh $content;
12047: close($fh);
12048: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12049: $count,'<span class="LC_filename">'.
12050: $container.'</span>').'</p>';
1.661 raeburn 12051: } else {
1.987 raeburn 12052: $output = '<p class="LC_error">'.
12053: &mt('Error: could not update [_1].',
12054: '<span class="LC_filename">'.
12055: $container.'</span>').'</p>';
1.661 raeburn 12056: }
12057: }
12058: }
1.1123 raeburn 12059: if (($context eq 'syllabus') && (!$skiprewrites)) {
12060: my ($actionurl,$state);
12061: $actionurl = "/public/$udom/$uname/syllabus";
12062: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12063: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12064: \%codebase,
12065: {'context' => 'rewrites',
12066: 'ignore_remote_references' => 1,});
12067: if (ref($mapping) eq 'HASH') {
12068: my $rewrites = 0;
12069: foreach my $key (keys(%{$mapping})) {
12070: next if ($key =~ m{^https?://});
12071: my $ref = $mapping->{$key};
12072: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12073: my $attrib;
12074: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12075: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12076: }
12077: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12078: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12079: $rewrites += $numchg;
12080: }
12081: }
12082: if ($rewrites) {
12083: my $saveresult;
12084: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12085: if ($url eq $container) {
12086: my ($fname) = ($container =~ m{/([^/]+)$});
12087: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12088: $count,'<span class="LC_filename">'.
12089: $fname.'</span>').'</p>';
12090: } else {
12091: $output .= '<p class="LC_error">'.
12092: &mt('Error: could not update links in [_1].',
12093: '<span class="LC_filename">'.
12094: $container.'</span>').'</p>';
12095:
12096: }
12097: }
12098: }
12099: }
1.987 raeburn 12100: } else {
12101: &logthis('Failed to parse '.$container.
12102: ' to modify references: '.$parse_result);
1.661 raeburn 12103: }
12104: }
1.1071 raeburn 12105: if (wantarray) {
12106: return ($output,$count,$codebasecount);
12107: } else {
12108: return $output;
12109: }
1.661 raeburn 12110: }
12111:
12112: sub check_for_existing {
12113: my ($path,$fname,$element) = @_;
12114: my ($state,$msg);
12115: if (-d $path.'/'.$fname) {
12116: $state = 'exists';
12117: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12118: } elsif (-e $path.'/'.$fname) {
12119: $state = 'exists';
12120: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12121: }
12122: if ($state eq 'exists') {
12123: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12124: }
12125: return ($state,$msg);
12126: }
12127:
12128: sub check_for_upload {
12129: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12130: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12131: my $filesize = length($env{'form.'.$element});
12132: if (!$filesize) {
12133: my $msg = '<span class="LC_error">'.
12134: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12135: '<span class="LC_filename">'.$fname.'</span>',
12136: $filesize).'<br />'.
1.1007 raeburn 12137: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12138: '</span>';
12139: return ('zero_bytes',$msg);
12140: }
12141: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12142: my $getpropath = 1;
1.1021 raeburn 12143: my ($dirlistref,$listerror) =
12144: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12145: my $found_file = 0;
12146: my $locked_file = 0;
1.991 raeburn 12147: my @lockers;
12148: my $navmap;
12149: if ($env{'request.course.id'}) {
12150: $navmap = Apache::lonnavmaps::navmap->new();
12151: }
1.1021 raeburn 12152: if (ref($dirlistref) eq 'ARRAY') {
12153: foreach my $line (@{$dirlistref}) {
12154: my ($file_name,$rest)=split(/\&/,$line,2);
12155: if ($file_name eq $fname){
12156: $file_name = $path.$file_name;
12157: if ($group ne '') {
12158: $file_name = $group.$file_name;
12159: }
12160: $found_file = 1;
12161: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12162: foreach my $lock (@lockers) {
12163: if (ref($lock) eq 'ARRAY') {
12164: my ($symb,$crsid) = @{$lock};
12165: if ($crsid eq $env{'request.course.id'}) {
12166: if (ref($navmap)) {
12167: my $res = $navmap->getBySymb($symb);
12168: foreach my $part (@{$res->parts()}) {
12169: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12170: unless (($slot_status == $res->RESERVED) ||
12171: ($slot_status == $res->RESERVED_LOCATION)) {
12172: $locked_file = 1;
12173: }
1.991 raeburn 12174: }
1.1021 raeburn 12175: } else {
12176: $locked_file = 1;
1.991 raeburn 12177: }
12178: } else {
12179: $locked_file = 1;
12180: }
12181: }
1.1021 raeburn 12182: }
12183: } else {
12184: my @info = split(/\&/,$rest);
12185: my $currsize = $info[6]/1000;
12186: if ($currsize < $filesize) {
12187: my $extra = $filesize - $currsize;
12188: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12189: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12190: &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 12191: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12192: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12193: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12194: return ('will_exceed_quota',$msg);
12195: }
1.984 raeburn 12196: }
12197: }
1.661 raeburn 12198: }
12199: }
12200: }
12201: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12202: my $msg = '<p class="LC_warning">'.
12203: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12204: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12205: return ('will_exceed_quota',$msg);
12206: } elsif ($found_file) {
12207: if ($locked_file) {
1.1179 bisitz 12208: my $msg = '<p class="LC_warning">';
1.661 raeburn 12209: $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 12210: $msg .= '</p>';
1.661 raeburn 12211: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12212: return ('file_locked',$msg);
12213: } else {
1.1179 bisitz 12214: my $msg = '<p class="LC_error">';
1.984 raeburn 12215: $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 12216: $msg .= '</p>';
1.984 raeburn 12217: return ('existingfile',$msg);
1.661 raeburn 12218: }
12219: }
12220: }
12221:
1.987 raeburn 12222: sub check_for_traversal {
12223: my ($path,$url,$toplevel) = @_;
12224: my @parts=split(/\//,$path);
12225: my $cleanpath;
12226: my $fullpath = $url;
12227: for (my $i=0;$i<@parts;$i++) {
12228: next if ($parts[$i] eq '.');
12229: if ($parts[$i] eq '..') {
12230: $fullpath =~ s{([^/]+/)$}{};
12231: } else {
12232: $fullpath .= $parts[$i].'/';
12233: }
12234: }
12235: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12236: $cleanpath = $1;
12237: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12238: my $curr_toprel = $1;
12239: my @parts = split(/\//,$curr_toprel);
12240: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12241: my @urlparts = split(/\//,$url_toprel);
12242: my $doubledots;
12243: my $startdiff = -1;
12244: for (my $i=0; $i<@urlparts; $i++) {
12245: if ($startdiff == -1) {
12246: unless ($urlparts[$i] eq $parts[$i]) {
12247: $startdiff = $i;
12248: $doubledots .= '../';
12249: }
12250: } else {
12251: $doubledots .= '../';
12252: }
12253: }
12254: if ($startdiff > -1) {
12255: $cleanpath = $doubledots;
12256: for (my $i=$startdiff; $i<@parts; $i++) {
12257: $cleanpath .= $parts[$i].'/';
12258: }
12259: }
12260: }
12261: $cleanpath =~ s{(/)$}{};
12262: return $cleanpath;
12263: }
1.31 albertel 12264:
1.1053 raeburn 12265: sub is_archive_file {
12266: my ($mimetype) = @_;
12267: if (($mimetype eq 'application/octet-stream') ||
12268: ($mimetype eq 'application/x-stuffit') ||
12269: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12270: return 1;
12271: }
12272: return;
12273: }
12274:
12275: sub decompress_form {
1.1065 raeburn 12276: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12277: my %lt = &Apache::lonlocal::texthash (
12278: this => 'This file is an archive file.',
1.1067 raeburn 12279: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12280: itsc => 'Its contents are as follows:',
1.1053 raeburn 12281: youm => 'You may wish to extract its contents.',
12282: extr => 'Extract contents',
1.1067 raeburn 12283: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12284: proa => 'Process automatically?',
1.1053 raeburn 12285: yes => 'Yes',
12286: no => 'No',
1.1067 raeburn 12287: fold => 'Title for folder containing movie',
12288: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12289: );
1.1065 raeburn 12290: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12291: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12292: my $info = &list_archive_contents($fileloc,\@paths);
12293: if (@paths) {
12294: foreach my $path (@paths) {
12295: $path =~ s{^/}{};
1.1067 raeburn 12296: if ($path =~ m{^([^/]+)/$}) {
12297: $topdir = $1;
12298: }
1.1065 raeburn 12299: if ($path =~ m{^([^/]+)/}) {
12300: $toplevel{$1} = $path;
12301: } else {
12302: $toplevel{$path} = $path;
12303: }
12304: }
12305: }
1.1067 raeburn 12306: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12307: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12308: "$topdir/media/",
12309: "$topdir/media/$topdir.mp4",
12310: "$topdir/media/FirstFrame.png",
12311: "$topdir/media/player.swf",
12312: "$topdir/media/swfobject.js",
12313: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12314: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12315: "$topdir/$topdir.mp4",
12316: "$topdir/$topdir\_config.xml",
12317: "$topdir/$topdir\_controller.swf",
12318: "$topdir/$topdir\_embed.css",
12319: "$topdir/$topdir\_First_Frame.png",
12320: "$topdir/$topdir\_player.html",
12321: "$topdir/$topdir\_Thumbnails.png",
12322: "$topdir/playerProductInstall.swf",
12323: "$topdir/scripts/",
12324: "$topdir/scripts/config_xml.js",
12325: "$topdir/scripts/handlebars.js",
12326: "$topdir/scripts/jquery-1.7.1.min.js",
12327: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12328: "$topdir/scripts/modernizr.js",
12329: "$topdir/scripts/player-min.js",
12330: "$topdir/scripts/swfobject.js",
12331: "$topdir/skins/",
12332: "$topdir/skins/configuration_express.xml",
12333: "$topdir/skins/express_show/",
12334: "$topdir/skins/express_show/player-min.css",
12335: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12336: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12337: "$topdir/$topdir.mp4",
12338: "$topdir/$topdir\_config.xml",
12339: "$topdir/$topdir\_controller.swf",
12340: "$topdir/$topdir\_embed.css",
12341: "$topdir/$topdir\_First_Frame.png",
12342: "$topdir/$topdir\_player.html",
12343: "$topdir/$topdir\_Thumbnails.png",
12344: "$topdir/playerProductInstall.swf",
12345: "$topdir/scripts/",
12346: "$topdir/scripts/config_xml.js",
12347: "$topdir/scripts/techsmith-smart-player.min.js",
12348: "$topdir/skins/",
12349: "$topdir/skins/configuration_express.xml",
12350: "$topdir/skins/express_show/",
12351: "$topdir/skins/express_show/spritesheet.min.css",
12352: "$topdir/skins/express_show/spritesheet.png",
12353: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12354: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12355: if (@diffs == 0) {
1.1164 raeburn 12356: $is_camtasia = 6;
12357: } else {
1.1197 raeburn 12358: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12359: if (@diffs == 0) {
12360: $is_camtasia = 8;
1.1197 raeburn 12361: } else {
12362: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12363: if (@diffs == 0) {
12364: $is_camtasia = 8;
12365: }
1.1164 raeburn 12366: }
1.1067 raeburn 12367: }
12368: }
12369: my $output;
12370: if ($is_camtasia) {
12371: $output = <<"ENDCAM";
12372: <script type="text/javascript" language="Javascript">
12373: // <![CDATA[
12374:
12375: function camtasiaToggle() {
12376: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12377: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12378: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12379: document.getElementById('camtasia_titles').style.display='block';
12380: } else {
12381: document.getElementById('camtasia_titles').style.display='none';
12382: }
12383: }
12384: }
12385: return;
12386: }
12387:
12388: // ]]>
12389: </script>
12390: <p>$lt{'camt'}</p>
12391: ENDCAM
1.1065 raeburn 12392: } else {
1.1067 raeburn 12393: $output = '<p>'.$lt{'this'};
12394: if ($info eq '') {
12395: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12396: } else {
12397: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12398: '<div><pre>'.$info.'</pre></div>';
12399: }
1.1065 raeburn 12400: }
1.1067 raeburn 12401: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12402: my $duplicates;
12403: my $num = 0;
12404: if (ref($dirlist) eq 'ARRAY') {
12405: foreach my $item (@{$dirlist}) {
12406: if (ref($item) eq 'ARRAY') {
12407: if (exists($toplevel{$item->[0]})) {
12408: $duplicates .=
12409: &start_data_table_row().
12410: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12411: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12412: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12413: 'value="1" />'.&mt('Yes').'</label>'.
12414: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12415: '<td>'.$item->[0].'</td>';
12416: if ($item->[2]) {
12417: $duplicates .= '<td>'.&mt('Directory').'</td>';
12418: } else {
12419: $duplicates .= '<td>'.&mt('File').'</td>';
12420: }
12421: $duplicates .= '<td>'.$item->[3].'</td>'.
12422: '<td>'.
12423: &Apache::lonlocal::locallocaltime($item->[4]).
12424: '</td>'.
12425: &end_data_table_row();
12426: $num ++;
12427: }
12428: }
12429: }
12430: }
12431: my $itemcount;
12432: if (@paths > 0) {
12433: $itemcount = scalar(@paths);
12434: } else {
12435: $itemcount = 1;
12436: }
1.1067 raeburn 12437: if ($is_camtasia) {
12438: $output .= $lt{'auto'}.'<br />'.
12439: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12440: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12441: $lt{'yes'}.'</label> <label>'.
12442: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12443: $lt{'no'}.'</label></span><br />'.
12444: '<div id="camtasia_titles" style="display:block">'.
12445: &Apache::lonhtmlcommon::start_pick_box().
12446: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12447: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12448: &Apache::lonhtmlcommon::row_closure().
12449: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12450: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12451: &Apache::lonhtmlcommon::row_closure(1).
12452: &Apache::lonhtmlcommon::end_pick_box().
12453: '</div>';
12454: }
1.1065 raeburn 12455: $output .=
12456: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12457: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12458: "\n";
1.1065 raeburn 12459: if ($duplicates ne '') {
12460: $output .= '<p><span class="LC_warning">'.
12461: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12462: &start_data_table().
12463: &start_data_table_header_row().
12464: '<th>'.&mt('Overwrite?').'</th>'.
12465: '<th>'.&mt('Name').'</th>'.
12466: '<th>'.&mt('Type').'</th>'.
12467: '<th>'.&mt('Size').'</th>'.
12468: '<th>'.&mt('Last modified').'</th>'.
12469: &end_data_table_header_row().
12470: $duplicates.
12471: &end_data_table().
12472: '</p>';
12473: }
1.1067 raeburn 12474: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12475: if (ref($hiddenelements) eq 'HASH') {
12476: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12477: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12478: }
12479: }
12480: $output .= <<"END";
1.1067 raeburn 12481: <br />
1.1053 raeburn 12482: <input type="submit" name="decompress" value="$lt{'extr'}" />
12483: </form>
12484: $noextract
12485: END
12486: return $output;
12487: }
12488:
1.1065 raeburn 12489: sub decompression_utility {
12490: my ($program) = @_;
12491: my @utilities = ('tar','gunzip','bunzip2','unzip');
12492: my $location;
12493: if (grep(/^\Q$program\E$/,@utilities)) {
12494: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12495: '/usr/sbin/') {
12496: if (-x $dir.$program) {
12497: $location = $dir.$program;
12498: last;
12499: }
12500: }
12501: }
12502: return $location;
12503: }
12504:
12505: sub list_archive_contents {
12506: my ($file,$pathsref) = @_;
12507: my (@cmd,$output);
12508: my $needsregexp;
12509: if ($file =~ /\.zip$/) {
12510: @cmd = (&decompression_utility('unzip'),"-l");
12511: $needsregexp = 1;
12512: } elsif (($file =~ m/\.tar\.gz$/) ||
12513: ($file =~ /\.tgz$/)) {
12514: @cmd = (&decompression_utility('tar'),"-ztf");
12515: } elsif ($file =~ /\.tar\.bz2$/) {
12516: @cmd = (&decompression_utility('tar'),"-jtf");
12517: } elsif ($file =~ m|\.tar$|) {
12518: @cmd = (&decompression_utility('tar'),"-tf");
12519: }
12520: if (@cmd) {
12521: undef($!);
12522: undef($@);
12523: if (open(my $fh,"-|", @cmd, $file)) {
12524: while (my $line = <$fh>) {
12525: $output .= $line;
12526: chomp($line);
12527: my $item;
12528: if ($needsregexp) {
12529: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12530: } else {
12531: $item = $line;
12532: }
12533: if ($item ne '') {
12534: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12535: push(@{$pathsref},$item);
12536: }
12537: }
12538: }
12539: close($fh);
12540: }
12541: }
12542: return $output;
12543: }
12544:
1.1053 raeburn 12545: sub decompress_uploaded_file {
12546: my ($file,$dir) = @_;
12547: &Apache::lonnet::appenv({'cgi.file' => $file});
12548: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12549: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12550: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12551: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12552: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12553: my $decompressed = $env{'cgi.decompressed'};
12554: &Apache::lonnet::delenv('cgi.file');
12555: &Apache::lonnet::delenv('cgi.dir');
12556: &Apache::lonnet::delenv('cgi.decompressed');
12557: return ($decompressed,$result);
12558: }
12559:
1.1055 raeburn 12560: sub process_decompression {
12561: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
12562: my ($dir,$error,$warning,$output);
1.1180 raeburn 12563: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12564: $error = &mt('Filename not a supported archive file type.').
12565: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12566: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12567: } else {
12568: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12569: if ($docuhome eq 'no_host') {
12570: $error = &mt('Could not determine home server for course.');
12571: } else {
12572: my @ids=&Apache::lonnet::current_machine_ids();
12573: my $currdir = "$dir_root/$destination";
12574: if (grep(/^\Q$docuhome\E$/,@ids)) {
12575: $dir = &LONCAPA::propath($docudom,$docuname).
12576: "$dir_root/$destination";
12577: } else {
12578: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12579: "$dir_root/$docudom/$docuname/$destination";
12580: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12581: $error = &mt('Archive file not found.');
12582: }
12583: }
1.1065 raeburn 12584: my (@to_overwrite,@to_skip);
12585: if ($env{'form.archive_overwrite_total'} > 0) {
12586: my $total = $env{'form.archive_overwrite_total'};
12587: for (my $i=0; $i<$total; $i++) {
12588: if ($env{'form.archive_overwrite_'.$i} == 1) {
12589: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12590: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12591: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12592: }
12593: }
12594: }
12595: my $numskip = scalar(@to_skip);
12596: if (($numskip > 0) &&
12597: ($numskip == $env{'form.archive_itemcount'})) {
12598: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12599: } elsif ($dir eq '') {
1.1055 raeburn 12600: $error = &mt('Directory containing archive file unavailable.');
12601: } elsif (!$error) {
1.1065 raeburn 12602: my ($decompressed,$display);
12603: if ($numskip > 0) {
12604: my $tempdir = time.'_'.$$.int(rand(10000));
12605: mkdir("$dir/$tempdir",0755);
12606: system("mv $dir/$file $dir/$tempdir/$file");
12607: ($decompressed,$display) =
12608: &decompress_uploaded_file($file,"$dir/$tempdir");
12609: foreach my $item (@to_skip) {
12610: if (($item ne '') && ($item !~ /\.\./)) {
12611: if (-f "$dir/$tempdir/$item") {
12612: unlink("$dir/$tempdir/$item");
12613: } elsif (-d "$dir/$tempdir/$item") {
12614: system("rm -rf $dir/$tempdir/$item");
12615: }
12616: }
12617: }
12618: system("mv $dir/$tempdir/* $dir");
12619: rmdir("$dir/$tempdir");
12620: } else {
12621: ($decompressed,$display) =
12622: &decompress_uploaded_file($file,$dir);
12623: }
1.1055 raeburn 12624: if ($decompressed eq 'ok') {
1.1065 raeburn 12625: $output = '<p class="LC_info">'.
12626: &mt('Files extracted successfully from archive.').
12627: '</p>'."\n";
1.1055 raeburn 12628: my ($warning,$result,@contents);
12629: my ($newdirlistref,$newlisterror) =
12630: &Apache::lonnet::dirlist($currdir,$docudom,
12631: $docuname,1);
12632: my (%is_dir,%changes,@newitems);
12633: my $dirptr = 16384;
1.1065 raeburn 12634: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12635: foreach my $dir_line (@{$newdirlistref}) {
12636: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 12637: unless (($item =~ /^\.+$/) || ($item eq $file) ||
12638: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 12639: push(@newitems,$item);
12640: if ($dirptr&$testdir) {
12641: $is_dir{$item} = 1;
12642: }
12643: $changes{$item} = 1;
12644: }
12645: }
12646: }
12647: if (keys(%changes) > 0) {
12648: foreach my $item (sort(@newitems)) {
12649: if ($changes{$item}) {
12650: push(@contents,$item);
12651: }
12652: }
12653: }
12654: if (@contents > 0) {
1.1067 raeburn 12655: my $wantform;
12656: unless ($env{'form.autoextract_camtasia'}) {
12657: $wantform = 1;
12658: }
1.1056 raeburn 12659: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12660: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12661: $currdir,\%is_dir,
12662: \%children,\%parent,
1.1056 raeburn 12663: \@contents,\%dirorder,
12664: \%titles,$wantform);
1.1055 raeburn 12665: if ($datatable ne '') {
12666: $output .= &archive_options_form('decompressed',$datatable,
12667: $count,$hiddenelem);
1.1065 raeburn 12668: my $startcount = 6;
1.1055 raeburn 12669: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12670: \%titles,\%children);
1.1055 raeburn 12671: }
1.1067 raeburn 12672: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 12673: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12674: my %displayed;
12675: my $total = 1;
12676: $env{'form.archive_directory'} = [];
12677: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12678: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12679: $path =~ s{/$}{};
12680: my $item;
12681: if ($path ne '') {
12682: $item = "$path/$titles{$i}";
12683: } else {
12684: $item = $titles{$i};
12685: }
12686: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12687: if ($item eq $contents[0]) {
12688: push(@{$env{'form.archive_directory'}},$i);
12689: $env{'form.archive_'.$i} = 'display';
12690: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12691: $displayed{'folder'} = $i;
1.1164 raeburn 12692: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12693: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12694: $env{'form.archive_'.$i} = 'display';
12695: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12696: $displayed{'web'} = $i;
12697: } else {
1.1164 raeburn 12698: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12699: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12700: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12701: push(@{$env{'form.archive_directory'}},$i);
12702: }
12703: $env{'form.archive_'.$i} = 'dependency';
12704: }
12705: $total ++;
12706: }
12707: for (my $i=1; $i<$total; $i++) {
12708: next if ($i == $displayed{'web'});
12709: next if ($i == $displayed{'folder'});
12710: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12711: }
12712: $env{'form.phase'} = 'decompress_cleanup';
12713: $env{'form.archivedelete'} = 1;
12714: $env{'form.archive_count'} = $total-1;
12715: $output .=
12716: &process_extracted_files('coursedocs',$docudom,
12717: $docuname,$destination,
12718: $dir_root,$hiddenelem);
12719: }
1.1055 raeburn 12720: } else {
12721: $warning = &mt('No new items extracted from archive file.');
12722: }
12723: } else {
12724: $output = $display;
12725: $error = &mt('An error occurred during extraction from the archive file.');
12726: }
12727: }
12728: }
12729: }
12730: if ($error) {
12731: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12732: $error.'</p>'."\n";
12733: }
12734: if ($warning) {
12735: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12736: }
12737: return $output;
12738: }
12739:
12740: sub get_extracted {
1.1056 raeburn 12741: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12742: $titles,$wantform) = @_;
1.1055 raeburn 12743: my $count = 0;
12744: my $depth = 0;
12745: my $datatable;
1.1056 raeburn 12746: my @hierarchy;
1.1055 raeburn 12747: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12748: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12749: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12750: foreach my $item (@{$contents}) {
12751: $count ++;
1.1056 raeburn 12752: @{$dirorder->{$count}} = @hierarchy;
12753: $titles->{$count} = $item;
1.1055 raeburn 12754: &archive_hierarchy($depth,$count,$parent,$children);
12755: if ($wantform) {
12756: $datatable .= &archive_row($is_dir->{$item},$item,
12757: $currdir,$depth,$count);
12758: }
12759: if ($is_dir->{$item}) {
12760: $depth ++;
1.1056 raeburn 12761: push(@hierarchy,$count);
12762: $parent->{$depth} = $count;
1.1055 raeburn 12763: $datatable .=
12764: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12765: \$depth,\$count,\@hierarchy,$dirorder,
12766: $children,$parent,$titles,$wantform);
1.1055 raeburn 12767: $depth --;
1.1056 raeburn 12768: pop(@hierarchy);
1.1055 raeburn 12769: }
12770: }
12771: return ($count,$datatable);
12772: }
12773:
12774: sub recurse_extracted_archive {
1.1056 raeburn 12775: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12776: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12777: my $result='';
1.1056 raeburn 12778: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12779: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12780: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12781: return $result;
12782: }
12783: my $dirptr = 16384;
12784: my ($newdirlistref,$newlisterror) =
12785: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12786: if (ref($newdirlistref) eq 'ARRAY') {
12787: foreach my $dir_line (@{$newdirlistref}) {
12788: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12789: unless ($item =~ /^\.+$/) {
12790: $$count ++;
1.1056 raeburn 12791: @{$dirorder->{$$count}} = @{$hierarchy};
12792: $titles->{$$count} = $item;
1.1055 raeburn 12793: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12794:
1.1055 raeburn 12795: my $is_dir;
12796: if ($dirptr&$testdir) {
12797: $is_dir = 1;
12798: }
12799: if ($wantform) {
12800: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12801: }
12802: if ($is_dir) {
12803: $$depth ++;
1.1056 raeburn 12804: push(@{$hierarchy},$$count);
12805: $parent->{$$depth} = $$count;
1.1055 raeburn 12806: $result .=
12807: &recurse_extracted_archive("$currdir/$item",$docudom,
12808: $docuname,$depth,$count,
1.1056 raeburn 12809: $hierarchy,$dirorder,$children,
12810: $parent,$titles,$wantform);
1.1055 raeburn 12811: $$depth --;
1.1056 raeburn 12812: pop(@{$hierarchy});
1.1055 raeburn 12813: }
12814: }
12815: }
12816: }
12817: return $result;
12818: }
12819:
12820: sub archive_hierarchy {
12821: my ($depth,$count,$parent,$children) =@_;
12822: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12823: if (exists($parent->{$depth})) {
12824: $children->{$parent->{$depth}} .= $count.':';
12825: }
12826: }
12827: return;
12828: }
12829:
12830: sub archive_row {
12831: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12832: my ($name) = ($item =~ m{([^/]+)$});
12833: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12834: 'display' => 'Add as file',
1.1055 raeburn 12835: 'dependency' => 'Include as dependency',
12836: 'discard' => 'Discard',
12837: );
12838: if ($is_dir) {
1.1059 raeburn 12839: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12840: }
1.1056 raeburn 12841: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12842: my $offset = 0;
1.1055 raeburn 12843: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12844: $offset ++;
1.1065 raeburn 12845: if ($action ne 'display') {
12846: $offset ++;
12847: }
1.1055 raeburn 12848: $output .= '<td><span class="LC_nobreak">'.
12849: '<label><input type="radio" name="archive_'.$count.
12850: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12851: my $text = $choices{$action};
12852: if ($is_dir) {
12853: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12854: if ($action eq 'display') {
1.1059 raeburn 12855: $text = &mt('Add as folder');
1.1055 raeburn 12856: }
1.1056 raeburn 12857: } else {
12858: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12859:
12860: }
12861: $output .= ' /> '.$choices{$action}.'</label></span>';
12862: if ($action eq 'dependency') {
12863: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12864: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12865: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12866: '<option value=""></option>'."\n".
12867: '</select>'."\n".
12868: '</div>';
1.1059 raeburn 12869: } elsif ($action eq 'display') {
12870: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12871: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12872: '</div>';
1.1055 raeburn 12873: }
1.1056 raeburn 12874: $output .= '</td>';
1.1055 raeburn 12875: }
12876: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12877: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12878: for (my $i=0; $i<$depth; $i++) {
12879: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12880: }
12881: if ($is_dir) {
12882: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12883: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12884: } else {
12885: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12886: }
12887: $output .= ' '.$name.'</td>'."\n".
12888: &end_data_table_row();
12889: return $output;
12890: }
12891:
12892: sub archive_options_form {
1.1065 raeburn 12893: my ($form,$display,$count,$hiddenelem) = @_;
12894: my %lt = &Apache::lonlocal::texthash(
12895: perm => 'Permanently remove archive file?',
12896: hows => 'How should each extracted item be incorporated in the course?',
12897: cont => 'Content actions for all',
12898: addf => 'Add as folder/file',
12899: incd => 'Include as dependency for a displayed file',
12900: disc => 'Discard',
12901: no => 'No',
12902: yes => 'Yes',
12903: save => 'Save',
12904: );
12905: my $output = <<"END";
12906: <form name="$form" method="post" action="">
12907: <p><span class="LC_nobreak">$lt{'perm'}
12908: <label>
12909: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12910: </label>
12911:
12912: <label>
12913: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12914: </span>
12915: </p>
12916: <input type="hidden" name="phase" value="decompress_cleanup" />
12917: <br />$lt{'hows'}
12918: <div class="LC_columnSection">
12919: <fieldset>
12920: <legend>$lt{'cont'}</legend>
12921: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12922: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12923: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12924: </fieldset>
12925: </div>
12926: END
12927: return $output.
1.1055 raeburn 12928: &start_data_table()."\n".
1.1065 raeburn 12929: $display."\n".
1.1055 raeburn 12930: &end_data_table()."\n".
12931: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12932: $hiddenelem.
1.1065 raeburn 12933: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12934: '</form>';
12935: }
12936:
12937: sub archive_javascript {
1.1056 raeburn 12938: my ($startcount,$numitems,$titles,$children) = @_;
12939: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12940: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12941: my $scripttag = <<START;
12942: <script type="text/javascript">
12943: // <![CDATA[
12944:
12945: function checkAll(form,prefix) {
12946: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12947: for (var i=0; i < form.elements.length; i++) {
12948: var id = form.elements[i].id;
12949: if ((id != '') && (id != undefined)) {
12950: if (idstr.test(id)) {
12951: if (form.elements[i].type == 'radio') {
12952: form.elements[i].checked = true;
1.1056 raeburn 12953: var nostart = i-$startcount;
1.1059 raeburn 12954: var offset = nostart%7;
12955: var count = (nostart-offset)/7;
1.1056 raeburn 12956: dependencyCheck(form,count,offset);
1.1055 raeburn 12957: }
12958: }
12959: }
12960: }
12961: }
12962:
12963: function propagateCheck(form,count) {
12964: if (count > 0) {
1.1059 raeburn 12965: var startelement = $startcount + ((count-1) * 7);
12966: for (var j=1; j<6; j++) {
12967: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12968: var item = startelement + j;
12969: if (form.elements[item].type == 'radio') {
12970: if (form.elements[item].checked) {
12971: containerCheck(form,count,j);
12972: break;
12973: }
1.1055 raeburn 12974: }
12975: }
12976: }
12977: }
12978: }
12979:
12980: numitems = $numitems
1.1056 raeburn 12981: var titles = new Array(numitems);
12982: var parents = new Array(numitems);
1.1055 raeburn 12983: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12984: parents[i] = new Array;
1.1055 raeburn 12985: }
1.1059 raeburn 12986: var maintitle = '$maintitle';
1.1055 raeburn 12987:
12988: START
12989:
1.1056 raeburn 12990: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12991: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12992: for (my $i=0; $i<@contents; $i ++) {
12993: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12994: }
12995: }
12996:
1.1056 raeburn 12997: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12998: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12999: }
13000:
1.1055 raeburn 13001: $scripttag .= <<END;
13002:
13003: function containerCheck(form,count,offset) {
13004: if (count > 0) {
1.1056 raeburn 13005: dependencyCheck(form,count,offset);
1.1059 raeburn 13006: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13007: form.elements[item].checked = true;
13008: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13009: if (parents[count].length > 0) {
13010: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13011: containerCheck(form,parents[count][j],offset);
13012: }
13013: }
13014: }
13015: }
13016: }
13017:
13018: function dependencyCheck(form,count,offset) {
13019: if (count > 0) {
1.1059 raeburn 13020: var chosen = (offset+$startcount)+7*(count-1);
13021: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13022: var currtype = form.elements[depitem].type;
13023: if (form.elements[chosen].value == 'dependency') {
13024: document.getElementById('arc_depon_'+count).style.display='block';
13025: form.elements[depitem].options.length = 0;
13026: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13027: for (var i=1; i<=numitems; i++) {
13028: if (i == count) {
13029: continue;
13030: }
1.1059 raeburn 13031: var startelement = $startcount + (i-1) * 7;
13032: for (var j=1; j<6; j++) {
13033: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13034: var item = startelement + j;
13035: if (form.elements[item].type == 'radio') {
13036: if (form.elements[item].checked) {
13037: if (form.elements[item].value == 'display') {
13038: var n = form.elements[depitem].options.length;
13039: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13040: }
13041: }
13042: }
13043: }
13044: }
13045: }
13046: } else {
13047: document.getElementById('arc_depon_'+count).style.display='none';
13048: form.elements[depitem].options.length = 0;
13049: form.elements[depitem].options[0] = new Option('Select','',true,true);
13050: }
1.1059 raeburn 13051: titleCheck(form,count,offset);
1.1056 raeburn 13052: }
13053: }
13054:
13055: function propagateSelect(form,count,offset) {
13056: if (count > 0) {
1.1065 raeburn 13057: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13058: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13059: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13060: if (parents[count].length > 0) {
13061: for (var j=0; j<parents[count].length; j++) {
13062: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13063: }
13064: }
13065: }
13066: }
13067: }
1.1056 raeburn 13068:
13069: function containerSelect(form,count,offset,picked) {
13070: if (count > 0) {
1.1065 raeburn 13071: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13072: if (form.elements[item].type == 'radio') {
13073: if (form.elements[item].value == 'dependency') {
13074: if (form.elements[item+1].type == 'select-one') {
13075: for (var i=0; i<form.elements[item+1].options.length; i++) {
13076: if (form.elements[item+1].options[i].value == picked) {
13077: form.elements[item+1].selectedIndex = i;
13078: break;
13079: }
13080: }
13081: }
13082: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13083: if (parents[count].length > 0) {
13084: for (var j=0; j<parents[count].length; j++) {
13085: containerSelect(form,parents[count][j],offset,picked);
13086: }
13087: }
13088: }
13089: }
13090: }
13091: }
13092: }
13093:
1.1059 raeburn 13094: function titleCheck(form,count,offset) {
13095: if (count > 0) {
13096: var chosen = (offset+$startcount)+7*(count-1);
13097: var depitem = $startcount + ((count-1) * 7) + 2;
13098: var currtype = form.elements[depitem].type;
13099: if (form.elements[chosen].value == 'display') {
13100: document.getElementById('arc_title_'+count).style.display='block';
13101: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13102: document.getElementById('archive_title_'+count).value=maintitle;
13103: }
13104: } else {
13105: document.getElementById('arc_title_'+count).style.display='none';
13106: if (currtype == 'text') {
13107: document.getElementById('archive_title_'+count).value='';
13108: }
13109: }
13110: }
13111: return;
13112: }
13113:
1.1055 raeburn 13114: // ]]>
13115: </script>
13116: END
13117: return $scripttag;
13118: }
13119:
13120: sub process_extracted_files {
1.1067 raeburn 13121: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13122: my $numitems = $env{'form.archive_count'};
13123: return unless ($numitems);
13124: my @ids=&Apache::lonnet::current_machine_ids();
13125: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13126: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13127: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13128: if (grep(/^\Q$docuhome\E$/,@ids)) {
13129: $prefix = &LONCAPA::propath($docudom,$docuname);
13130: $pathtocheck = "$dir_root/$destination";
13131: $dir = $dir_root;
13132: $ishome = 1;
13133: } else {
13134: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13135: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
13136: $dir = "$dir_root/$docudom/$docuname";
13137: }
13138: my $currdir = "$dir_root/$destination";
13139: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13140: if ($env{'form.folderpath'}) {
13141: my @items = split('&',$env{'form.folderpath'});
13142: $folders{'0'} = $items[-2];
1.1099 raeburn 13143: if ($env{'form.folderpath'} =~ /\:1$/) {
13144: $containers{'0'}='page';
13145: } else {
13146: $containers{'0'}='sequence';
13147: }
1.1055 raeburn 13148: }
13149: my @archdirs = &get_env_multiple('form.archive_directory');
13150: if ($numitems) {
13151: for (my $i=1; $i<=$numitems; $i++) {
13152: my $path = $env{'form.archive_content_'.$i};
13153: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13154: my $item = $1;
13155: $toplevelitems{$item} = $i;
13156: if (grep(/^\Q$i\E$/,@archdirs)) {
13157: $is_dir{$item} = 1;
13158: }
13159: }
13160: }
13161: }
1.1067 raeburn 13162: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13163: if (keys(%toplevelitems) > 0) {
13164: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13165: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13166: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13167: }
1.1066 raeburn 13168: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13169: if ($numitems) {
13170: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13171: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13172: my $path = $env{'form.archive_content_'.$i};
13173: if ($path =~ /^\Q$pathtocheck\E/) {
13174: if ($env{'form.archive_'.$i} eq 'discard') {
13175: if ($prefix ne '' && $path ne '') {
13176: if (-e $prefix.$path) {
1.1066 raeburn 13177: if ((@archdirs > 0) &&
13178: (grep(/^\Q$i\E$/,@archdirs))) {
13179: $todeletedir{$prefix.$path} = 1;
13180: } else {
13181: $todelete{$prefix.$path} = 1;
13182: }
1.1055 raeburn 13183: }
13184: }
13185: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13186: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13187: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13188: $docstitle = $env{'form.archive_title_'.$i};
13189: if ($docstitle eq '') {
13190: $docstitle = $title;
13191: }
1.1055 raeburn 13192: $outer = 0;
1.1056 raeburn 13193: if (ref($dirorder{$i}) eq 'ARRAY') {
13194: if (@{$dirorder{$i}} > 0) {
13195: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13196: if ($env{'form.archive_'.$item} eq 'display') {
13197: $outer = $item;
13198: last;
13199: }
13200: }
13201: }
13202: }
13203: my ($errtext,$fatal) =
13204: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13205: '/'.$folders{$outer}.'.'.
13206: $containers{$outer});
13207: next if ($fatal);
13208: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13209: if ($context eq 'coursedocs') {
1.1056 raeburn 13210: $mapinner{$i} = time;
1.1055 raeburn 13211: $folders{$i} = 'default_'.$mapinner{$i};
13212: $containers{$i} = 'sequence';
13213: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13214: $folders{$i}.'.'.$containers{$i};
13215: my $newidx = &LONCAPA::map::getresidx();
13216: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13217: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13218: push(@LONCAPA::map::order,$newidx);
13219: my ($outtext,$errtext) =
13220: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13221: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13222: '.'.$containers{$outer},1,1);
1.1056 raeburn 13223: $newseqid{$i} = $newidx;
1.1067 raeburn 13224: unless ($errtext) {
13225: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
13226: }
1.1055 raeburn 13227: }
13228: } else {
13229: if ($context eq 'coursedocs') {
13230: my $newidx=&LONCAPA::map::getresidx();
13231: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13232: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13233: $title;
13234: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13235: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13236: }
13237: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13238: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13239: }
13240: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13241: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 13242: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 13243: unless ($ishome) {
13244: my $fetch = "$newdest{$i}/$title";
13245: $fetch =~ s/^\Q$prefix$dir\E//;
13246: $prompttofetch{$fetch} = 1;
13247: }
1.1055 raeburn 13248: }
13249: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13250: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13251: push(@LONCAPA::map::order, $newidx);
13252: my ($outtext,$errtext)=
13253: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13254: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13255: '.'.$containers{$outer},1,1);
1.1067 raeburn 13256: unless ($errtext) {
13257: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13258: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
13259: }
13260: }
1.1055 raeburn 13261: }
13262: }
1.1086 raeburn 13263: }
13264: } else {
13265: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13266: }
13267: }
13268: for (my $i=1; $i<=$numitems; $i++) {
13269: next unless ($env{'form.archive_'.$i} eq 'dependency');
13270: my $path = $env{'form.archive_content_'.$i};
13271: if ($path =~ /^\Q$pathtocheck\E/) {
13272: my ($title) = ($path =~ m{/([^/]+)$});
13273: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13274: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13275: if (ref($dirorder{$i}) eq 'ARRAY') {
13276: my ($itemidx,$fullpath,$relpath);
13277: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13278: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13279: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13280: if ($dirorder{$i}->[$j] eq $container) {
13281: $itemidx = $j;
1.1056 raeburn 13282: }
13283: }
1.1086 raeburn 13284: }
13285: if ($itemidx eq '') {
13286: $itemidx = 0;
13287: }
13288: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13289: if ($mapinner{$referrer{$i}}) {
13290: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13291: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13292: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13293: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13294: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13295: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13296: if (!-e $fullpath) {
13297: mkdir($fullpath,0755);
1.1056 raeburn 13298: }
13299: }
1.1086 raeburn 13300: } else {
13301: last;
1.1056 raeburn 13302: }
1.1086 raeburn 13303: }
13304: }
13305: } elsif ($newdest{$referrer{$i}}) {
13306: $fullpath = $newdest{$referrer{$i}};
13307: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13308: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13309: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13310: last;
13311: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13312: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13313: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13314: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13315: if (!-e $fullpath) {
13316: mkdir($fullpath,0755);
1.1056 raeburn 13317: }
13318: }
1.1086 raeburn 13319: } else {
13320: last;
1.1056 raeburn 13321: }
1.1055 raeburn 13322: }
13323: }
1.1086 raeburn 13324: if ($fullpath ne '') {
13325: if (-e "$prefix$path") {
13326: system("mv $prefix$path $fullpath/$title");
13327: }
13328: if (-e "$fullpath/$title") {
13329: my $showpath;
13330: if ($relpath ne '') {
13331: $showpath = "$relpath/$title";
13332: } else {
13333: $showpath = "/$title";
13334: }
13335: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
13336: }
13337: unless ($ishome) {
13338: my $fetch = "$fullpath/$title";
13339: $fetch =~ s/^\Q$prefix$dir\E//;
13340: $prompttofetch{$fetch} = 1;
13341: }
13342: }
1.1055 raeburn 13343: }
1.1086 raeburn 13344: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13345: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
13346: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 13347: }
13348: } else {
13349: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13350: }
13351: }
13352: if (keys(%todelete)) {
13353: foreach my $key (keys(%todelete)) {
13354: unlink($key);
1.1066 raeburn 13355: }
13356: }
13357: if (keys(%todeletedir)) {
13358: foreach my $key (keys(%todeletedir)) {
13359: rmdir($key);
13360: }
13361: }
13362: foreach my $dir (sort(keys(%is_dir))) {
13363: if (($pathtocheck ne '') && ($dir ne '')) {
13364: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13365: }
13366: }
1.1067 raeburn 13367: if ($result ne '') {
13368: $output .= '<ul>'."\n".
13369: $result."\n".
13370: '</ul>';
13371: }
13372: unless ($ishome) {
13373: my $replicationfail;
13374: foreach my $item (keys(%prompttofetch)) {
13375: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13376: unless ($fetchresult eq 'ok') {
13377: $replicationfail .= '<li>'.$item.'</li>'."\n";
13378: }
13379: }
13380: if ($replicationfail) {
13381: $output .= '<p class="LC_error">'.
13382: &mt('Course home server failed to retrieve:').'<ul>'.
13383: $replicationfail.
13384: '</ul></p>';
13385: }
13386: }
1.1055 raeburn 13387: } else {
13388: $warning = &mt('No items found in archive.');
13389: }
13390: if ($error) {
13391: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13392: $error.'</p>'."\n";
13393: }
13394: if ($warning) {
13395: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13396: }
13397: return $output;
13398: }
13399:
1.1066 raeburn 13400: sub cleanup_empty_dirs {
13401: my ($path) = @_;
13402: if (($path ne '') && (-d $path)) {
13403: if (opendir(my $dirh,$path)) {
13404: my @dircontents = grep(!/^\./,readdir($dirh));
13405: my $numitems = 0;
13406: foreach my $item (@dircontents) {
13407: if (-d "$path/$item") {
1.1111 raeburn 13408: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13409: if (-e "$path/$item") {
13410: $numitems ++;
13411: }
13412: } else {
13413: $numitems ++;
13414: }
13415: }
13416: if ($numitems == 0) {
13417: rmdir($path);
13418: }
13419: closedir($dirh);
13420: }
13421: }
13422: return;
13423: }
13424:
1.41 ng 13425: =pod
1.45 matthew 13426:
1.1162 raeburn 13427: =item * &get_folder_hierarchy()
1.1068 raeburn 13428:
13429: Provides hierarchy of names of folders/sub-folders containing the current
13430: item,
13431:
13432: Inputs: 3
13433: - $navmap - navmaps object
13434:
13435: - $map - url for map (either the trigger itself, or map containing
13436: the resource, which is the trigger).
13437:
13438: - $showitem - 1 => show title for map itself; 0 => do not show.
13439:
13440: Outputs: 1 @pathitems - array of folder/subfolder names.
13441:
13442: =cut
13443:
13444: sub get_folder_hierarchy {
13445: my ($navmap,$map,$showitem) = @_;
13446: my @pathitems;
13447: if (ref($navmap)) {
13448: my $mapres = $navmap->getResourceByUrl($map);
13449: if (ref($mapres)) {
13450: my $pcslist = $mapres->map_hierarchy();
13451: if ($pcslist ne '') {
13452: my @pcs = split(/,/,$pcslist);
13453: foreach my $pc (@pcs) {
13454: if ($pc == 1) {
1.1129 raeburn 13455: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13456: } else {
13457: my $res = $navmap->getByMapPc($pc);
13458: if (ref($res)) {
13459: my $title = $res->compTitle();
13460: $title =~ s/\W+/_/g;
13461: if ($title ne '') {
13462: push(@pathitems,$title);
13463: }
13464: }
13465: }
13466: }
13467: }
1.1071 raeburn 13468: if ($showitem) {
13469: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13470: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13471: } else {
13472: my $maptitle = $mapres->compTitle();
13473: $maptitle =~ s/\W+/_/g;
13474: if ($maptitle ne '') {
13475: push(@pathitems,$maptitle);
13476: }
1.1068 raeburn 13477: }
13478: }
13479: }
13480: }
13481: return @pathitems;
13482: }
13483:
13484: =pod
13485:
1.1015 raeburn 13486: =item * &get_turnedin_filepath()
13487:
13488: Determines path in a user's portfolio file for storage of files uploaded
13489: to a specific essayresponse or dropbox item.
13490:
13491: Inputs: 3 required + 1 optional.
13492: $symb is symb for resource, $uname and $udom are for current user (required).
13493: $caller is optional (can be "submission", if routine is called when storing
13494: an upoaded file when "Submit Answer" button was pressed).
13495:
13496: Returns array containing $path and $multiresp.
13497: $path is path in portfolio. $multiresp is 1 if this resource contains more
13498: than one file upload item. Callers of routine should append partid as a
13499: subdirectory to $path in cases where $multiresp is 1.
13500:
13501: Called by: homework/essayresponse.pm and homework/structuretags.pm
13502:
13503: =cut
13504:
13505: sub get_turnedin_filepath {
13506: my ($symb,$uname,$udom,$caller) = @_;
13507: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13508: my $turnindir;
13509: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13510: $turnindir = $userhash{'turnindir'};
13511: my ($path,$multiresp);
13512: if ($turnindir eq '') {
13513: if ($caller eq 'submission') {
13514: $turnindir = &mt('turned in');
13515: $turnindir =~ s/\W+/_/g;
13516: my %newhash = (
13517: 'turnindir' => $turnindir,
13518: );
13519: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13520: }
13521: }
13522: if ($turnindir ne '') {
13523: $path = '/'.$turnindir.'/';
13524: my ($multipart,$turnin,@pathitems);
13525: my $navmap = Apache::lonnavmaps::navmap->new();
13526: if (defined($navmap)) {
13527: my $mapres = $navmap->getResourceByUrl($map);
13528: if (ref($mapres)) {
13529: my $pcslist = $mapres->map_hierarchy();
13530: if ($pcslist ne '') {
13531: foreach my $pc (split(/,/,$pcslist)) {
13532: my $res = $navmap->getByMapPc($pc);
13533: if (ref($res)) {
13534: my $title = $res->compTitle();
13535: $title =~ s/\W+/_/g;
13536: if ($title ne '') {
1.1149 raeburn 13537: if (($pc > 1) && (length($title) > 12)) {
13538: $title = substr($title,0,12);
13539: }
1.1015 raeburn 13540: push(@pathitems,$title);
13541: }
13542: }
13543: }
13544: }
13545: my $maptitle = $mapres->compTitle();
13546: $maptitle =~ s/\W+/_/g;
13547: if ($maptitle ne '') {
1.1149 raeburn 13548: if (length($maptitle) > 12) {
13549: $maptitle = substr($maptitle,0,12);
13550: }
1.1015 raeburn 13551: push(@pathitems,$maptitle);
13552: }
13553: unless ($env{'request.state'} eq 'construct') {
13554: my $res = $navmap->getBySymb($symb);
13555: if (ref($res)) {
13556: my $partlist = $res->parts();
13557: my $totaluploads = 0;
13558: if (ref($partlist) eq 'ARRAY') {
13559: foreach my $part (@{$partlist}) {
13560: my @types = $res->responseType($part);
13561: my @ids = $res->responseIds($part);
13562: for (my $i=0; $i < scalar(@ids); $i++) {
13563: if ($types[$i] eq 'essay') {
13564: my $partid = $part.'_'.$ids[$i];
13565: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13566: $totaluploads ++;
13567: }
13568: }
13569: }
13570: }
13571: if ($totaluploads > 1) {
13572: $multiresp = 1;
13573: }
13574: }
13575: }
13576: }
13577: } else {
13578: return;
13579: }
13580: } else {
13581: return;
13582: }
13583: my $restitle=&Apache::lonnet::gettitle($symb);
13584: $restitle =~ s/\W+/_/g;
13585: if ($restitle eq '') {
13586: $restitle = ($resurl =~ m{/[^/]+$});
13587: if ($restitle eq '') {
13588: $restitle = time;
13589: }
13590: }
1.1149 raeburn 13591: if (length($restitle) > 12) {
13592: $restitle = substr($restitle,0,12);
13593: }
1.1015 raeburn 13594: push(@pathitems,$restitle);
13595: $path .= join('/',@pathitems);
13596: }
13597: return ($path,$multiresp);
13598: }
13599:
13600: =pod
13601:
1.464 albertel 13602: =back
1.41 ng 13603:
1.112 bowersj2 13604: =head1 CSV Upload/Handling functions
1.38 albertel 13605:
1.41 ng 13606: =over 4
13607:
1.648 raeburn 13608: =item * &upfile_store($r)
1.41 ng 13609:
13610: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13611: needs $env{'form.upfile'}
1.41 ng 13612: returns $datatoken to be put into hidden field
13613:
13614: =cut
1.31 albertel 13615:
13616: sub upfile_store {
13617: my $r=shift;
1.258 albertel 13618: $env{'form.upfile'}=~s/\r/\n/gs;
13619: $env{'form.upfile'}=~s/\f/\n/gs;
13620: $env{'form.upfile'}=~s/\n+/\n/gs;
13621: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13622:
1.258 albertel 13623: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
13624: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 13625: {
1.158 raeburn 13626: my $datafile = $r->dir_config('lonDaemons').
13627: '/tmp/'.$datatoken.'.tmp';
13628: if ( open(my $fh,">$datafile") ) {
1.258 albertel 13629: print $fh $env{'form.upfile'};
1.158 raeburn 13630: close($fh);
13631: }
1.31 albertel 13632: }
13633: return $datatoken;
13634: }
13635:
1.56 matthew 13636: =pod
13637:
1.648 raeburn 13638: =item * &load_tmp_file($r)
1.41 ng 13639:
13640: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 13641: needs $env{'form.datatoken'},
13642: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13643:
13644: =cut
1.31 albertel 13645:
13646: sub load_tmp_file {
13647: my $r=shift;
13648: my @studentdata=();
13649: {
1.158 raeburn 13650: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 13651: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 13652: if ( open(my $fh,"<$studentfile") ) {
13653: @studentdata=<$fh>;
13654: close($fh);
13655: }
1.31 albertel 13656: }
1.258 albertel 13657: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13658: }
13659:
1.56 matthew 13660: =pod
13661:
1.648 raeburn 13662: =item * &upfile_record_sep()
1.41 ng 13663:
13664: Separate uploaded file into records
13665: returns array of records,
1.258 albertel 13666: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13667:
13668: =cut
1.31 albertel 13669:
13670: sub upfile_record_sep {
1.258 albertel 13671: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13672: } else {
1.248 albertel 13673: my @records;
1.258 albertel 13674: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13675: if ($line=~/^\s*$/) { next; }
13676: push(@records,$line);
13677: }
13678: return @records;
1.31 albertel 13679: }
13680: }
13681:
1.56 matthew 13682: =pod
13683:
1.648 raeburn 13684: =item * &record_sep($record)
1.41 ng 13685:
1.258 albertel 13686: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13687:
13688: =cut
13689:
1.263 www 13690: sub takeleft {
13691: my $index=shift;
13692: return substr('0000'.$index,-4,4);
13693: }
13694:
1.31 albertel 13695: sub record_sep {
13696: my $record=shift;
13697: my %components=();
1.258 albertel 13698: if ($env{'form.upfiletype'} eq 'xml') {
13699: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13700: my $i=0;
1.356 albertel 13701: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13702: $field=~s/^(\"|\')//;
13703: $field=~s/(\"|\')$//;
1.263 www 13704: $components{&takeleft($i)}=$field;
1.31 albertel 13705: $i++;
13706: }
1.258 albertel 13707: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13708: my $i=0;
1.356 albertel 13709: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13710: $field=~s/^(\"|\')//;
13711: $field=~s/(\"|\')$//;
1.263 www 13712: $components{&takeleft($i)}=$field;
1.31 albertel 13713: $i++;
13714: }
13715: } else {
1.561 www 13716: my $separator=',';
1.480 banghart 13717: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13718: $separator=';';
1.480 banghart 13719: }
1.31 albertel 13720: my $i=0;
1.561 www 13721: # the character we are looking for to indicate the end of a quote or a record
13722: my $looking_for=$separator;
13723: # do not add the characters to the fields
13724: my $ignore=0;
13725: # we just encountered a separator (or the beginning of the record)
13726: my $just_found_separator=1;
13727: # store the field we are working on here
13728: my $field='';
13729: # work our way through all characters in record
13730: foreach my $character ($record=~/(.)/g) {
13731: if ($character eq $looking_for) {
13732: if ($character ne $separator) {
13733: # Found the end of a quote, again looking for separator
13734: $looking_for=$separator;
13735: $ignore=1;
13736: } else {
13737: # Found a separator, store away what we got
13738: $components{&takeleft($i)}=$field;
13739: $i++;
13740: $just_found_separator=1;
13741: $ignore=0;
13742: $field='';
13743: }
13744: next;
13745: }
13746: # single or double quotation marks after a separator indicate beginning of a quote
13747: # we are now looking for the end of the quote and need to ignore separators
13748: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13749: $looking_for=$character;
13750: next;
13751: }
13752: # ignore would be true after we reached the end of a quote
13753: if ($ignore) { next; }
13754: if (($just_found_separator) && ($character=~/\s/)) { next; }
13755: $field.=$character;
13756: $just_found_separator=0;
1.31 albertel 13757: }
1.561 www 13758: # catch the very last entry, since we never encountered the separator
13759: $components{&takeleft($i)}=$field;
1.31 albertel 13760: }
13761: return %components;
13762: }
13763:
1.144 matthew 13764: ######################################################
13765: ######################################################
13766:
1.56 matthew 13767: =pod
13768:
1.648 raeburn 13769: =item * &upfile_select_html()
1.41 ng 13770:
1.144 matthew 13771: Return HTML code to select a file from the users machine and specify
13772: the file type.
1.41 ng 13773:
13774: =cut
13775:
1.144 matthew 13776: ######################################################
13777: ######################################################
1.31 albertel 13778: sub upfile_select_html {
1.144 matthew 13779: my %Types = (
13780: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13781: semisv => &mt('Semicolon separated values'),
1.144 matthew 13782: space => &mt('Space separated'),
13783: tab => &mt('Tabulator separated'),
13784: # xml => &mt('HTML/XML'),
13785: );
13786: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13787: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13788: foreach my $type (sort(keys(%Types))) {
13789: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13790: }
13791: $Str .= "</select>\n";
13792: return $Str;
1.31 albertel 13793: }
13794:
1.301 albertel 13795: sub get_samples {
13796: my ($records,$toget) = @_;
13797: my @samples=({});
13798: my $got=0;
13799: foreach my $rec (@$records) {
13800: my %temp = &record_sep($rec);
13801: if (! grep(/\S/, values(%temp))) { next; }
13802: if (%temp) {
13803: $samples[$got]=\%temp;
13804: $got++;
13805: if ($got == $toget) { last; }
13806: }
13807: }
13808: return \@samples;
13809: }
13810:
1.144 matthew 13811: ######################################################
13812: ######################################################
13813:
1.56 matthew 13814: =pod
13815:
1.648 raeburn 13816: =item * &csv_print_samples($r,$records)
1.41 ng 13817:
13818: Prints a table of sample values from each column uploaded $r is an
13819: Apache Request ref, $records is an arrayref from
13820: &Apache::loncommon::upfile_record_sep
13821:
13822: =cut
13823:
1.144 matthew 13824: ######################################################
13825: ######################################################
1.31 albertel 13826: sub csv_print_samples {
13827: my ($r,$records) = @_;
1.662 bisitz 13828: my $samples = &get_samples($records,5);
1.301 albertel 13829:
1.594 raeburn 13830: $r->print(&mt('Samples').'<br />'.&start_data_table().
13831: &start_data_table_header_row());
1.356 albertel 13832: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13833: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13834: $r->print(&end_data_table_header_row());
1.301 albertel 13835: foreach my $hash (@$samples) {
1.594 raeburn 13836: $r->print(&start_data_table_row());
1.356 albertel 13837: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13838: $r->print('<td>');
1.356 albertel 13839: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13840: $r->print('</td>');
13841: }
1.594 raeburn 13842: $r->print(&end_data_table_row());
1.31 albertel 13843: }
1.594 raeburn 13844: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13845: }
13846:
1.144 matthew 13847: ######################################################
13848: ######################################################
13849:
1.56 matthew 13850: =pod
13851:
1.648 raeburn 13852: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13853:
13854: Prints a table to create associations between values and table columns.
1.144 matthew 13855:
1.41 ng 13856: $r is an Apache Request ref,
13857: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13858: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13859:
13860: =cut
13861:
1.144 matthew 13862: ######################################################
13863: ######################################################
1.31 albertel 13864: sub csv_print_select_table {
13865: my ($r,$records,$d) = @_;
1.301 albertel 13866: my $i=0;
13867: my $samples = &get_samples($records,1);
1.144 matthew 13868: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13869: &start_data_table().&start_data_table_header_row().
1.144 matthew 13870: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13871: '<th>'.&mt('Column').'</th>'.
13872: &end_data_table_header_row()."\n");
1.356 albertel 13873: foreach my $array_ref (@$d) {
13874: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13875: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13876:
1.875 bisitz 13877: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13878: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13879: $r->print('<option value="none"></option>');
1.356 albertel 13880: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13881: $r->print('<option value="'.$sample.'"'.
13882: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13883: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13884: }
1.594 raeburn 13885: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13886: $i++;
13887: }
1.594 raeburn 13888: $r->print(&end_data_table());
1.31 albertel 13889: $i--;
13890: return $i;
13891: }
1.56 matthew 13892:
1.144 matthew 13893: ######################################################
13894: ######################################################
13895:
1.56 matthew 13896: =pod
1.31 albertel 13897:
1.648 raeburn 13898: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13899:
13900: Prints a table of sample values from the upload and can make associate samples to internal names.
13901:
13902: $r is an Apache Request ref,
13903: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13904: $d is an array of 2 element arrays (internal name, displayed name)
13905:
13906: =cut
13907:
1.144 matthew 13908: ######################################################
13909: ######################################################
1.31 albertel 13910: sub csv_samples_select_table {
13911: my ($r,$records,$d) = @_;
13912: my $i=0;
1.144 matthew 13913: #
1.662 bisitz 13914: my $max_samples = 5;
13915: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13916: $r->print(&start_data_table().
13917: &start_data_table_header_row().'<th>'.
13918: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13919: &end_data_table_header_row());
1.301 albertel 13920:
13921: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13922: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13923: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13924: foreach my $option (@$d) {
13925: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13926: $r->print('<option value="'.$value.'"'.
1.253 albertel 13927: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13928: $display.'</option>');
1.31 albertel 13929: }
13930: $r->print('</select></td><td>');
1.662 bisitz 13931: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13932: if (defined($samples->[$line]{$key})) {
13933: $r->print($samples->[$line]{$key}."<br />\n");
13934: }
13935: }
1.594 raeburn 13936: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13937: $i++;
13938: }
1.594 raeburn 13939: $r->print(&end_data_table());
1.31 albertel 13940: $i--;
13941: return($i);
1.115 matthew 13942: }
13943:
1.144 matthew 13944: ######################################################
13945: ######################################################
13946:
1.115 matthew 13947: =pod
13948:
1.648 raeburn 13949: =item * &clean_excel_name($name)
1.115 matthew 13950:
13951: Returns a replacement for $name which does not contain any illegal characters.
13952:
13953: =cut
13954:
1.144 matthew 13955: ######################################################
13956: ######################################################
1.115 matthew 13957: sub clean_excel_name {
13958: my ($name) = @_;
13959: $name =~ s/[:\*\?\/\\]//g;
13960: if (length($name) > 31) {
13961: $name = substr($name,0,31);
13962: }
13963: return $name;
1.25 albertel 13964: }
1.84 albertel 13965:
1.85 albertel 13966: =pod
13967:
1.648 raeburn 13968: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13969:
13970: Returns either 1 or undef
13971:
13972: 1 if the part is to be hidden, undef if it is to be shown
13973:
13974: Arguments are:
13975:
13976: $id the id of the part to be checked
13977: $symb, optional the symb of the resource to check
13978: $udom, optional the domain of the user to check for
13979: $uname, optional the username of the user to check for
13980:
13981: =cut
1.84 albertel 13982:
13983: sub check_if_partid_hidden {
13984: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13985: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13986: $symb,$udom,$uname);
1.141 albertel 13987: my $truth=1;
13988: #if the string starts with !, then the list is the list to show not hide
13989: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13990: my @hiddenlist=split(/,/,$hiddenparts);
13991: foreach my $checkid (@hiddenlist) {
1.141 albertel 13992: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13993: }
1.141 albertel 13994: return !$truth;
1.84 albertel 13995: }
1.127 matthew 13996:
1.138 matthew 13997:
13998: ############################################################
13999: ############################################################
14000:
14001: =pod
14002:
1.157 matthew 14003: =back
14004:
1.138 matthew 14005: =head1 cgi-bin script and graphing routines
14006:
1.157 matthew 14007: =over 4
14008:
1.648 raeburn 14009: =item * &get_cgi_id()
1.138 matthew 14010:
14011: Inputs: none
14012:
14013: Returns an id which can be used to pass environment variables
14014: to various cgi-bin scripts. These environment variables will
14015: be removed from the users environment after a given time by
14016: the routine &Apache::lonnet::transfer_profile_to_env.
14017:
14018: =cut
14019:
14020: ############################################################
14021: ############################################################
1.152 albertel 14022: my $uniq=0;
1.136 matthew 14023: sub get_cgi_id {
1.154 albertel 14024: $uniq=($uniq+1)%100000;
1.280 albertel 14025: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14026: }
14027:
1.127 matthew 14028: ############################################################
14029: ############################################################
14030:
14031: =pod
14032:
1.648 raeburn 14033: =item * &DrawBarGraph()
1.127 matthew 14034:
1.138 matthew 14035: Facilitates the plotting of data in a (stacked) bar graph.
14036: Puts plot definition data into the users environment in order for
14037: graph.png to plot it. Returns an <img> tag for the plot.
14038: The bars on the plot are labeled '1','2',...,'n'.
14039:
14040: Inputs:
14041:
14042: =over 4
14043:
14044: =item $Title: string, the title of the plot
14045:
14046: =item $xlabel: string, text describing the X-axis of the plot
14047:
14048: =item $ylabel: string, text describing the Y-axis of the plot
14049:
14050: =item $Max: scalar, the maximum Y value to use in the plot
14051: If $Max is < any data point, the graph will not be rendered.
14052:
1.140 matthew 14053: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14054: they are plotted. If undefined, default values will be used.
14055:
1.178 matthew 14056: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14057:
1.138 matthew 14058: =item @Values: An array of array references. Each array reference holds data
14059: to be plotted in a stacked bar chart.
14060:
1.239 matthew 14061: =item If the final element of @Values is a hash reference the key/value
14062: pairs will be added to the graph definition.
14063:
1.138 matthew 14064: =back
14065:
14066: Returns:
14067:
14068: An <img> tag which references graph.png and the appropriate identifying
14069: information for the plot.
14070:
1.127 matthew 14071: =cut
14072:
14073: ############################################################
14074: ############################################################
1.134 matthew 14075: sub DrawBarGraph {
1.178 matthew 14076: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14077: #
14078: if (! defined($colors)) {
14079: $colors = ['#33ff00',
14080: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14081: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14082: ];
14083: }
1.228 matthew 14084: my $extra_settings = {};
14085: if (ref($Values[-1]) eq 'HASH') {
14086: $extra_settings = pop(@Values);
14087: }
1.127 matthew 14088: #
1.136 matthew 14089: my $identifier = &get_cgi_id();
14090: my $id = 'cgi.'.$identifier;
1.129 matthew 14091: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14092: return '';
14093: }
1.225 matthew 14094: #
14095: my @Labels;
14096: if (defined($labels)) {
14097: @Labels = @$labels;
14098: } else {
14099: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14100: push(@Labels,$i+1);
1.225 matthew 14101: }
14102: }
14103: #
1.129 matthew 14104: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14105: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14106: my %ValuesHash;
14107: my $NumSets=1;
14108: foreach my $array (@Values) {
14109: next if (! ref($array));
1.136 matthew 14110: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14111: join(',',@$array);
1.129 matthew 14112: }
1.127 matthew 14113: #
1.136 matthew 14114: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14115: if ($NumBars < 3) {
14116: $width = 120+$NumBars*32;
1.220 matthew 14117: $xskip = 1;
1.225 matthew 14118: $bar_width = 30;
14119: } elsif ($NumBars < 5) {
14120: $width = 120+$NumBars*20;
14121: $xskip = 1;
14122: $bar_width = 20;
1.220 matthew 14123: } elsif ($NumBars < 10) {
1.136 matthew 14124: $width = 120+$NumBars*15;
14125: $xskip = 1;
14126: $bar_width = 15;
14127: } elsif ($NumBars <= 25) {
14128: $width = 120+$NumBars*11;
14129: $xskip = 5;
14130: $bar_width = 8;
14131: } elsif ($NumBars <= 50) {
14132: $width = 120+$NumBars*8;
14133: $xskip = 5;
14134: $bar_width = 4;
14135: } else {
14136: $width = 120+$NumBars*8;
14137: $xskip = 5;
14138: $bar_width = 4;
14139: }
14140: #
1.137 matthew 14141: $Max = 1 if ($Max < 1);
14142: if ( int($Max) < $Max ) {
14143: $Max++;
14144: $Max = int($Max);
14145: }
1.127 matthew 14146: $Title = '' if (! defined($Title));
14147: $xlabel = '' if (! defined($xlabel));
14148: $ylabel = '' if (! defined($ylabel));
1.369 www 14149: $ValuesHash{$id.'.title'} = &escape($Title);
14150: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14151: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14152: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14153: $ValuesHash{$id.'.NumBars'} = $NumBars;
14154: $ValuesHash{$id.'.NumSets'} = $NumSets;
14155: $ValuesHash{$id.'.PlotType'} = 'bar';
14156: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14157: $ValuesHash{$id.'.height'} = $height;
14158: $ValuesHash{$id.'.width'} = $width;
14159: $ValuesHash{$id.'.xskip'} = $xskip;
14160: $ValuesHash{$id.'.bar_width'} = $bar_width;
14161: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14162: #
1.228 matthew 14163: # Deal with other parameters
14164: while (my ($key,$value) = each(%$extra_settings)) {
14165: $ValuesHash{$id.'.'.$key} = $value;
14166: }
14167: #
1.646 raeburn 14168: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14169: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14170: }
14171:
14172: ############################################################
14173: ############################################################
14174:
14175: =pod
14176:
1.648 raeburn 14177: =item * &DrawXYGraph()
1.137 matthew 14178:
1.138 matthew 14179: Facilitates the plotting of data in an XY graph.
14180: Puts plot definition data into the users environment in order for
14181: graph.png to plot it. Returns an <img> tag for the plot.
14182:
14183: Inputs:
14184:
14185: =over 4
14186:
14187: =item $Title: string, the title of the plot
14188:
14189: =item $xlabel: string, text describing the X-axis of the plot
14190:
14191: =item $ylabel: string, text describing the Y-axis of the plot
14192:
14193: =item $Max: scalar, the maximum Y value to use in the plot
14194: If $Max is < any data point, the graph will not be rendered.
14195:
14196: =item $colors: Array ref containing the hex color codes for the data to be
14197: plotted in. If undefined, default values will be used.
14198:
14199: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14200:
14201: =item $Ydata: Array ref containing Array refs.
1.185 www 14202: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14203:
14204: =item %Values: hash indicating or overriding any default values which are
14205: passed to graph.png.
14206: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14207:
14208: =back
14209:
14210: Returns:
14211:
14212: An <img> tag which references graph.png and the appropriate identifying
14213: information for the plot.
14214:
1.137 matthew 14215: =cut
14216:
14217: ############################################################
14218: ############################################################
14219: sub DrawXYGraph {
14220: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14221: #
14222: # Create the identifier for the graph
14223: my $identifier = &get_cgi_id();
14224: my $id = 'cgi.'.$identifier;
14225: #
14226: $Title = '' if (! defined($Title));
14227: $xlabel = '' if (! defined($xlabel));
14228: $ylabel = '' if (! defined($ylabel));
14229: my %ValuesHash =
14230: (
1.369 www 14231: $id.'.title' => &escape($Title),
14232: $id.'.xlabel' => &escape($xlabel),
14233: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14234: $id.'.y_max_value'=> $Max,
14235: $id.'.labels' => join(',',@$Xlabels),
14236: $id.'.PlotType' => 'XY',
14237: );
14238: #
14239: if (defined($colors) && ref($colors) eq 'ARRAY') {
14240: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14241: }
14242: #
14243: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14244: return '';
14245: }
14246: my $NumSets=1;
1.138 matthew 14247: foreach my $array (@{$Ydata}){
1.137 matthew 14248: next if (! ref($array));
14249: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14250: }
1.138 matthew 14251: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14252: #
14253: # Deal with other parameters
14254: while (my ($key,$value) = each(%Values)) {
14255: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14256: }
14257: #
1.646 raeburn 14258: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14259: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14260: }
14261:
14262: ############################################################
14263: ############################################################
14264:
14265: =pod
14266:
1.648 raeburn 14267: =item * &DrawXYYGraph()
1.138 matthew 14268:
14269: Facilitates the plotting of data in an XY graph with two Y axes.
14270: Puts plot definition data into the users environment in order for
14271: graph.png to plot it. Returns an <img> tag for the plot.
14272:
14273: Inputs:
14274:
14275: =over 4
14276:
14277: =item $Title: string, the title of the plot
14278:
14279: =item $xlabel: string, text describing the X-axis of the plot
14280:
14281: =item $ylabel: string, text describing the Y-axis of the plot
14282:
14283: =item $colors: Array ref containing the hex color codes for the data to be
14284: plotted in. If undefined, default values will be used.
14285:
14286: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14287:
14288: =item $Ydata1: The first data set
14289:
14290: =item $Min1: The minimum value of the left Y-axis
14291:
14292: =item $Max1: The maximum value of the left Y-axis
14293:
14294: =item $Ydata2: The second data set
14295:
14296: =item $Min2: The minimum value of the right Y-axis
14297:
14298: =item $Max2: The maximum value of the left Y-axis
14299:
14300: =item %Values: hash indicating or overriding any default values which are
14301: passed to graph.png.
14302: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14303:
14304: =back
14305:
14306: Returns:
14307:
14308: An <img> tag which references graph.png and the appropriate identifying
14309: information for the plot.
1.136 matthew 14310:
14311: =cut
14312:
14313: ############################################################
14314: ############################################################
1.137 matthew 14315: sub DrawXYYGraph {
14316: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14317: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14318: #
14319: # Create the identifier for the graph
14320: my $identifier = &get_cgi_id();
14321: my $id = 'cgi.'.$identifier;
14322: #
14323: $Title = '' if (! defined($Title));
14324: $xlabel = '' if (! defined($xlabel));
14325: $ylabel = '' if (! defined($ylabel));
14326: my %ValuesHash =
14327: (
1.369 www 14328: $id.'.title' => &escape($Title),
14329: $id.'.xlabel' => &escape($xlabel),
14330: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14331: $id.'.labels' => join(',',@$Xlabels),
14332: $id.'.PlotType' => 'XY',
14333: $id.'.NumSets' => 2,
1.137 matthew 14334: $id.'.two_axes' => 1,
14335: $id.'.y1_max_value' => $Max1,
14336: $id.'.y1_min_value' => $Min1,
14337: $id.'.y2_max_value' => $Max2,
14338: $id.'.y2_min_value' => $Min2,
1.136 matthew 14339: );
14340: #
1.137 matthew 14341: if (defined($colors) && ref($colors) eq 'ARRAY') {
14342: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14343: }
14344: #
14345: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14346: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14347: return '';
14348: }
14349: my $NumSets=1;
1.137 matthew 14350: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14351: next if (! ref($array));
14352: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14353: }
14354: #
14355: # Deal with other parameters
14356: while (my ($key,$value) = each(%Values)) {
14357: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14358: }
14359: #
1.646 raeburn 14360: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14361: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14362: }
14363:
14364: ############################################################
14365: ############################################################
14366:
14367: =pod
14368:
1.157 matthew 14369: =back
14370:
1.139 matthew 14371: =head1 Statistics helper routines?
14372:
14373: Bad place for them but what the hell.
14374:
1.157 matthew 14375: =over 4
14376:
1.648 raeburn 14377: =item * &chartlink()
1.139 matthew 14378:
14379: Returns a link to the chart for a specific student.
14380:
14381: Inputs:
14382:
14383: =over 4
14384:
14385: =item $linktext: The text of the link
14386:
14387: =item $sname: The students username
14388:
14389: =item $sdomain: The students domain
14390:
14391: =back
14392:
1.157 matthew 14393: =back
14394:
1.139 matthew 14395: =cut
14396:
14397: ############################################################
14398: ############################################################
14399: sub chartlink {
14400: my ($linktext, $sname, $sdomain) = @_;
14401: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14402: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14403: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14404: '">'.$linktext.'</a>';
1.153 matthew 14405: }
14406:
14407: #######################################################
14408: #######################################################
14409:
14410: =pod
14411:
14412: =head1 Course Environment Routines
1.157 matthew 14413:
14414: =over 4
1.153 matthew 14415:
1.648 raeburn 14416: =item * &restore_course_settings()
1.153 matthew 14417:
1.648 raeburn 14418: =item * &store_course_settings()
1.153 matthew 14419:
14420: Restores/Store indicated form parameters from the course environment.
14421: Will not overwrite existing values of the form parameters.
14422:
14423: Inputs:
14424: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14425:
14426: a hash ref describing the data to be stored. For example:
14427:
14428: %Save_Parameters = ('Status' => 'scalar',
14429: 'chartoutputmode' => 'scalar',
14430: 'chartoutputdata' => 'scalar',
14431: 'Section' => 'array',
1.373 raeburn 14432: 'Group' => 'array',
1.153 matthew 14433: 'StudentData' => 'array',
14434: 'Maps' => 'array');
14435:
14436: Returns: both routines return nothing
14437:
1.631 raeburn 14438: =back
14439:
1.153 matthew 14440: =cut
14441:
14442: #######################################################
14443: #######################################################
14444: sub store_course_settings {
1.496 albertel 14445: return &store_settings($env{'request.course.id'},@_);
14446: }
14447:
14448: sub store_settings {
1.153 matthew 14449: # save to the environment
14450: # appenv the same items, just to be safe
1.300 albertel 14451: my $udom = $env{'user.domain'};
14452: my $uname = $env{'user.name'};
1.496 albertel 14453: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14454: my %SaveHash;
14455: my %AppHash;
14456: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14457: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14458: my $envname = 'environment.'.$basename;
1.258 albertel 14459: if (exists($env{'form.'.$setting})) {
1.153 matthew 14460: # Save this value away
14461: if ($type eq 'scalar' &&
1.258 albertel 14462: (! exists($env{$envname}) ||
14463: $env{$envname} ne $env{'form.'.$setting})) {
14464: $SaveHash{$basename} = $env{'form.'.$setting};
14465: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14466: } elsif ($type eq 'array') {
14467: my $stored_form;
1.258 albertel 14468: if (ref($env{'form.'.$setting})) {
1.153 matthew 14469: $stored_form = join(',',
14470: map {
1.369 www 14471: &escape($_);
1.258 albertel 14472: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14473: } else {
14474: $stored_form =
1.369 www 14475: &escape($env{'form.'.$setting});
1.153 matthew 14476: }
14477: # Determine if the array contents are the same.
1.258 albertel 14478: if ($stored_form ne $env{$envname}) {
1.153 matthew 14479: $SaveHash{$basename} = $stored_form;
14480: $AppHash{$envname} = $stored_form;
14481: }
14482: }
14483: }
14484: }
14485: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14486: $udom,$uname);
1.153 matthew 14487: if ($put_result !~ /^(ok|delayed)/) {
14488: &Apache::lonnet::logthis('unable to save form parameters, '.
14489: 'got error:'.$put_result);
14490: }
14491: # Make sure these settings stick around in this session, too
1.646 raeburn 14492: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14493: return;
14494: }
14495:
14496: sub restore_course_settings {
1.499 albertel 14497: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14498: }
14499:
14500: sub restore_settings {
14501: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14502: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14503: next if (exists($env{'form.'.$setting}));
1.496 albertel 14504: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14505: '.'.$setting;
1.258 albertel 14506: if (exists($env{$envname})) {
1.153 matthew 14507: if ($type eq 'scalar') {
1.258 albertel 14508: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14509: } elsif ($type eq 'array') {
1.258 albertel 14510: $env{'form.'.$setting} = [
1.153 matthew 14511: map {
1.369 www 14512: &unescape($_);
1.258 albertel 14513: } split(',',$env{$envname})
1.153 matthew 14514: ];
14515: }
14516: }
14517: }
1.127 matthew 14518: }
14519:
1.618 raeburn 14520: #######################################################
14521: #######################################################
14522:
14523: =pod
14524:
14525: =head1 Domain E-mail Routines
14526:
14527: =over 4
14528:
1.648 raeburn 14529: =item * &build_recipient_list()
1.618 raeburn 14530:
1.1144 raeburn 14531: Build recipient lists for following types of e-mail:
1.766 raeburn 14532: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14533: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14534: module change checking, student/employee ID conflict checks, as
14535: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14536: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14537:
14538: Inputs:
1.619 raeburn 14539: defmail (scalar - email address of default recipient),
1.1144 raeburn 14540: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14541: requestsmail, updatesmail, or idconflictsmail).
14542:
1.619 raeburn 14543: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14544:
1.619 raeburn 14545: origmail (scalar - email address of recipient from loncapa.conf,
14546: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14547:
1.655 raeburn 14548: Returns: comma separated list of addresses to which to send e-mail.
14549:
14550: =back
1.618 raeburn 14551:
14552: =cut
14553:
14554: ############################################################
14555: ############################################################
14556: sub build_recipient_list {
1.619 raeburn 14557: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 14558: my @recipients;
1.1270 raeburn 14559: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14560: my %domconfig =
1.1270 raeburn 14561: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14562: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14563: if (exists($domconfig{'contacts'}{$mailing})) {
14564: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14565: my @contacts = ('adminemail','supportemail');
14566: foreach my $item (@contacts) {
14567: if ($domconfig{'contacts'}{$mailing}{$item}) {
14568: my $addr = $domconfig{'contacts'}{$item};
14569: if (!grep(/^\Q$addr\E$/,@recipients)) {
14570: push(@recipients,$addr);
14571: }
1.619 raeburn 14572: }
1.1270 raeburn 14573: }
14574: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14575: if ($mailing eq 'helpdeskmail') {
14576: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14577: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14578: my @ok_bccs;
14579: foreach my $bcc (@bccs) {
14580: $bcc =~ s/^\s+//g;
14581: $bcc =~ s/\s+$//g;
14582: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14583: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14584: push(@ok_bccs,$bcc);
14585: }
14586: }
14587: }
14588: if (@ok_bccs > 0) {
14589: $allbcc = join(', ',@ok_bccs);
14590: }
14591: }
14592: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14593: }
14594: }
1.766 raeburn 14595: } elsif ($origmail ne '') {
1.1270 raeburn 14596: $lastresort = $origmail;
1.618 raeburn 14597: }
1.619 raeburn 14598: } elsif ($origmail ne '') {
1.1270 raeburn 14599: $lastresort = $origmail;
14600: }
14601:
14602: if (($mailing eq 'helpdesk') && ($lastresort ne '')) {
14603: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14604: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14605: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14606: my %what = (
14607: perlvar => 1,
14608: );
14609: my $primary = &Apache::lonnet::domain($defdom,'primary');
14610: if ($primary) {
14611: my $gotaddr;
14612: my ($result,$returnhash) =
14613: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14614: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14615: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14616: $lastresort = $returnhash->{'lonSupportEMail'};
14617: $gotaddr = 1;
14618: }
14619: }
14620: unless ($gotaddr) {
14621: my $uintdom = &Apache::lonnet::internet_dom($primary);
14622: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14623: unless ($uintdom eq $intdom) {
14624: my %domconfig =
14625: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14626: if (ref($domconfig{'contacts'}) eq 'HASH') {
14627: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14628: my @contacts = ('adminemail','supportemail');
14629: foreach my $item (@contacts) {
14630: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14631: my $addr = $domconfig{'contacts'}{$item};
14632: if (!grep(/^\Q$addr\E$/,@recipients)) {
14633: push(@recipients,$addr);
14634: }
14635: }
14636: }
14637: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14638: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14639: }
14640: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14641: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14642: my @ok_bccs;
14643: foreach my $bcc (@bccs) {
14644: $bcc =~ s/^\s+//g;
14645: $bcc =~ s/\s+$//g;
14646: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14647: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14648: push(@ok_bccs,$bcc);
14649: }
14650: }
14651: }
14652: if (@ok_bccs > 0) {
14653: $allbcc = join(', ',@ok_bccs);
14654: }
14655: }
14656: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14657: }
14658: }
14659: }
14660: }
14661: }
14662: }
1.618 raeburn 14663: }
1.688 raeburn 14664: if (defined($defmail)) {
14665: if ($defmail ne '') {
14666: push(@recipients,$defmail);
14667: }
1.618 raeburn 14668: }
14669: if ($otheremails) {
1.619 raeburn 14670: my @others;
14671: if ($otheremails =~ /,/) {
14672: @others = split(/,/,$otheremails);
1.618 raeburn 14673: } else {
1.619 raeburn 14674: push(@others,$otheremails);
14675: }
14676: foreach my $addr (@others) {
14677: if (!grep(/^\Q$addr\E$/,@recipients)) {
14678: push(@recipients,$addr);
14679: }
1.618 raeburn 14680: }
14681: }
1.1270 raeburn 14682: if ($mailing eq 'helpdesk') {
14683: if ((!@recipients) && ($lastresort ne '')) {
14684: push(@recipients,$lastresort);
14685: }
14686: } elsif ($lastresort ne '') {
14687: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14688: push(@recipients,$lastresort);
14689: }
14690: }
1.1271 raeburn 14691: my $recipientlist = join(',',@recipients);
1.1270 raeburn 14692: if (wantarray) {
14693: return ($recipientlist,$allbcc,$addtext);
14694: } else {
14695: return $recipientlist;
14696: }
1.618 raeburn 14697: }
14698:
1.127 matthew 14699: ############################################################
14700: ############################################################
1.154 albertel 14701:
1.655 raeburn 14702: =pod
14703:
1.1224 musolffc 14704: =over 4
14705:
1.1223 musolffc 14706: =item * &mime_email()
14707:
14708: Sends an email with a possible attachment
14709:
14710: Inputs:
14711:
14712: =over 4
14713:
14714: from - Sender's email address
14715:
14716: to - Email address of recipient
14717:
14718: subject - Subject of email
14719:
14720: body - Body of email
14721:
14722: cc_string - Carbon copy email address
14723:
14724: bcc - Blind carbon copy email address
14725:
14726: type - File type of attachment
14727:
14728: attachment_path - Path of file to be attached
14729:
14730: file_name - Name of file to be attached
14731:
14732: attachment_text - The body of an attachment of type "TEXT"
14733:
14734: =back
14735:
14736: =back
14737:
14738: =cut
14739:
14740: ############################################################
14741: ############################################################
14742:
14743: sub mime_email {
14744: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
14745: $file_name, $attachment_text) = @_;
14746: my $msg = MIME::Lite->new(
14747: From => $from,
14748: To => $to,
14749: Subject => $subject,
14750: Type =>'TEXT',
14751: Data => $body,
14752: );
14753: if ($cc_string ne '') {
14754: $msg->add("Cc" => $cc_string);
14755: }
14756: if ($bcc ne '') {
14757: $msg->add("Bcc" => $bcc);
14758: }
14759: $msg->attr("content-type" => "text/plain");
14760: $msg->attr("content-type.charset" => "UTF-8");
14761: # Attach file if given
14762: if ($attachment_path) {
14763: unless ($file_name) {
14764: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
14765: }
14766: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
14767: $msg->attach(Type => $type,
14768: Path => $attachment_path,
14769: Filename => $file_name
14770: );
14771: # Otherwise attach text if given
14772: } elsif ($attachment_text) {
14773: $msg->attach(Type => 'TEXT',
14774: Data => $attachment_text);
14775: }
14776: # Send it
14777: $msg->send('sendmail');
14778: }
14779:
14780: ############################################################
14781: ############################################################
14782:
14783: =pod
14784:
1.655 raeburn 14785: =head1 Course Catalog Routines
14786:
14787: =over 4
14788:
14789: =item * &gather_categories()
14790:
14791: Converts category definitions - keys of categories hash stored in
14792: coursecategories in configuration.db on the primary library server in a
14793: domain - to an array. Also generates javascript and idx hash used to
14794: generate Domain Coordinator interface for editing Course Categories.
14795:
14796: Inputs:
1.663 raeburn 14797:
1.655 raeburn 14798: categories (reference to hash of category definitions).
1.663 raeburn 14799:
1.655 raeburn 14800: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14801: categories and subcategories).
1.663 raeburn 14802:
1.655 raeburn 14803: idx (reference to hash of counters used in Domain Coordinator interface for
14804: editing Course Categories).
1.663 raeburn 14805:
1.655 raeburn 14806: jsarray (reference to array of categories used to create Javascript arrays for
14807: Domain Coordinator interface for editing Course Categories).
14808:
14809: Returns: nothing
14810:
14811: Side effects: populates cats, idx and jsarray.
14812:
14813: =cut
14814:
14815: sub gather_categories {
14816: my ($categories,$cats,$idx,$jsarray) = @_;
14817: my %counters;
14818: my $num = 0;
14819: foreach my $item (keys(%{$categories})) {
14820: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14821: if ($container eq '' && $depth == 0) {
14822: $cats->[$depth][$categories->{$item}] = $cat;
14823: } else {
14824: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14825: }
14826: my ($escitem,$tail) = split(/:/,$item,2);
14827: if ($counters{$tail} eq '') {
14828: $counters{$tail} = $num;
14829: $num ++;
14830: }
14831: if (ref($idx) eq 'HASH') {
14832: $idx->{$item} = $counters{$tail};
14833: }
14834: if (ref($jsarray) eq 'ARRAY') {
14835: push(@{$jsarray->[$counters{$tail}]},$item);
14836: }
14837: }
14838: return;
14839: }
14840:
14841: =pod
14842:
14843: =item * &extract_categories()
14844:
14845: Used to generate breadcrumb trails for course categories.
14846:
14847: Inputs:
1.663 raeburn 14848:
1.655 raeburn 14849: categories (reference to hash of category definitions).
1.663 raeburn 14850:
1.655 raeburn 14851: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14852: categories and subcategories).
1.663 raeburn 14853:
1.655 raeburn 14854: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14855:
1.655 raeburn 14856: allitems (reference to hash - key is category key
14857: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14858:
1.655 raeburn 14859: idx (reference to hash of counters used in Domain Coordinator interface for
14860: editing Course Categories).
1.663 raeburn 14861:
1.655 raeburn 14862: jsarray (reference to array of categories used to create Javascript arrays for
14863: Domain Coordinator interface for editing Course Categories).
14864:
1.665 raeburn 14865: subcats (reference to hash of arrays containing all subcategories within each
14866: category, -recursive)
14867:
1.655 raeburn 14868: Returns: nothing
14869:
14870: Side effects: populates trails and allitems hash references.
14871:
14872: =cut
14873:
14874: sub extract_categories {
1.665 raeburn 14875: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14876: if (ref($categories) eq 'HASH') {
14877: &gather_categories($categories,$cats,$idx,$jsarray);
14878: if (ref($cats->[0]) eq 'ARRAY') {
14879: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14880: my $name = $cats->[0][$i];
14881: my $item = &escape($name).'::0';
14882: my $trailstr;
14883: if ($name eq 'instcode') {
14884: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14885: } elsif ($name eq 'communities') {
14886: $trailstr = &mt('Communities');
1.1239 raeburn 14887: } elsif ($name eq 'placement') {
14888: $trailstr = &mt('Placement Tests');
1.655 raeburn 14889: } else {
14890: $trailstr = $name;
14891: }
14892: if ($allitems->{$item} eq '') {
14893: push(@{$trails},$trailstr);
14894: $allitems->{$item} = scalar(@{$trails})-1;
14895: }
14896: my @parents = ($name);
14897: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14898: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14899: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14900: if (ref($subcats) eq 'HASH') {
14901: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14902: }
14903: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14904: }
14905: } else {
14906: if (ref($subcats) eq 'HASH') {
14907: $subcats->{$item} = [];
1.655 raeburn 14908: }
14909: }
14910: }
14911: }
14912: }
14913: return;
14914: }
14915:
14916: =pod
14917:
1.1162 raeburn 14918: =item * &recurse_categories()
1.655 raeburn 14919:
14920: Recursively used to generate breadcrumb trails for course categories.
14921:
14922: Inputs:
1.663 raeburn 14923:
1.655 raeburn 14924: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14925: categories and subcategories).
1.663 raeburn 14926:
1.655 raeburn 14927: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14928:
14929: category (current course category, for which breadcrumb trail is being generated).
14930:
14931: trails (reference to array of breadcrumb trails for each category).
14932:
1.655 raeburn 14933: allitems (reference to hash - key is category key
14934: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14935:
1.655 raeburn 14936: parents (array containing containers directories for current category,
14937: back to top level).
14938:
14939: Returns: nothing
14940:
14941: Side effects: populates trails and allitems hash references
14942:
14943: =cut
14944:
14945: sub recurse_categories {
1.665 raeburn 14946: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14947: my $shallower = $depth - 1;
14948: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14949: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14950: my $name = $cats->[$depth]{$category}[$k];
14951: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14952: my $trailstr = join(' -> ',(@{$parents},$category));
14953: if ($allitems->{$item} eq '') {
14954: push(@{$trails},$trailstr);
14955: $allitems->{$item} = scalar(@{$trails})-1;
14956: }
14957: my $deeper = $depth+1;
14958: push(@{$parents},$category);
1.665 raeburn 14959: if (ref($subcats) eq 'HASH') {
14960: my $subcat = &escape($name).':'.$category.':'.$depth;
14961: for (my $j=@{$parents}; $j>=0; $j--) {
14962: my $higher;
14963: if ($j > 0) {
14964: $higher = &escape($parents->[$j]).':'.
14965: &escape($parents->[$j-1]).':'.$j;
14966: } else {
14967: $higher = &escape($parents->[$j]).'::'.$j;
14968: }
14969: push(@{$subcats->{$higher}},$subcat);
14970: }
14971: }
14972: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14973: $subcats);
1.655 raeburn 14974: pop(@{$parents});
14975: }
14976: } else {
14977: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14978: my $trailstr = join(' -> ',(@{$parents},$category));
14979: if ($allitems->{$item} eq '') {
14980: push(@{$trails},$trailstr);
14981: $allitems->{$item} = scalar(@{$trails})-1;
14982: }
14983: }
14984: return;
14985: }
14986:
1.663 raeburn 14987: =pod
14988:
1.1162 raeburn 14989: =item * &assign_categories_table()
1.663 raeburn 14990:
14991: Create a datatable for display of hierarchical categories in a domain,
14992: with checkboxes to allow a course to be categorized.
14993:
14994: Inputs:
14995:
14996: cathash - reference to hash of categories defined for the domain (from
14997: configuration.db)
14998:
14999: currcat - scalar with an & separated list of categories assigned to a course.
15000:
1.919 raeburn 15001: type - scalar contains course type (Course or Community).
15002:
1.1260 raeburn 15003: disabled - scalar (optional) contains disabled="disabled" if input elements are
15004: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15005:
1.663 raeburn 15006: Returns: $output (markup to be displayed)
15007:
15008: =cut
15009:
15010: sub assign_categories_table {
1.1259 raeburn 15011: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15012: my $output;
15013: if (ref($cathash) eq 'HASH') {
15014: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
15015: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
15016: $maxdepth = scalar(@cats);
15017: if (@cats > 0) {
15018: my $itemcount = 0;
15019: if (ref($cats[0]) eq 'ARRAY') {
15020: my @currcategories;
15021: if ($currcat ne '') {
15022: @currcategories = split('&',$currcat);
15023: }
1.919 raeburn 15024: my $table;
1.663 raeburn 15025: for (my $i=0; $i<@{$cats[0]}; $i++) {
15026: my $parent = $cats[0][$i];
1.919 raeburn 15027: next if ($parent eq 'instcode');
15028: if ($type eq 'Community') {
15029: next unless ($parent eq 'communities');
1.1239 raeburn 15030: } elsif ($type eq 'Placement') {
15031: next unless ($parent eq 'placement');
1.919 raeburn 15032: } else {
1.1239 raeburn 15033: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15034: }
1.663 raeburn 15035: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15036: my $item = &escape($parent).'::0';
15037: my $checked = '';
15038: if (@currcategories > 0) {
15039: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15040: $checked = ' checked="checked"';
1.663 raeburn 15041: }
15042: }
1.919 raeburn 15043: my $parent_title = $parent;
15044: if ($parent eq 'communities') {
15045: $parent_title = &mt('Communities');
1.1239 raeburn 15046: } elsif ($parent eq 'placement') {
15047: $parent_title = &mt('Placement Tests');
1.919 raeburn 15048: }
15049: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15050: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15051: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15052: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15053: my $depth = 1;
15054: push(@path,$parent);
1.1259 raeburn 15055: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15056: pop(@path);
1.919 raeburn 15057: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15058: $itemcount ++;
15059: }
1.919 raeburn 15060: if ($itemcount) {
15061: $output = &Apache::loncommon::start_data_table().
15062: $table.
15063: &Apache::loncommon::end_data_table();
15064: }
1.663 raeburn 15065: }
15066: }
15067: }
15068: return $output;
15069: }
15070:
15071: =pod
15072:
1.1162 raeburn 15073: =item * &assign_category_rows()
1.663 raeburn 15074:
15075: Create a datatable row for display of nested categories in a domain,
15076: with checkboxes to allow a course to be categorized,called recursively.
15077:
15078: Inputs:
15079:
15080: itemcount - track row number for alternating colors
15081:
15082: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15083: categories and subcategories.
15084:
15085: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15086:
15087: parent - parent of current category item
15088:
15089: path - Array containing all categories back up through the hierarchy from the
15090: current category to the top level.
15091:
15092: currcategories - reference to array of current categories assigned to the course
15093:
1.1260 raeburn 15094: disabled - scalar (optional) contains disabled="disabled" if input elements are
15095: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15096:
1.663 raeburn 15097: Returns: $output (markup to be displayed).
15098:
15099: =cut
15100:
15101: sub assign_category_rows {
1.1259 raeburn 15102: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15103: my ($text,$name,$item,$chgstr);
15104: if (ref($cats) eq 'ARRAY') {
15105: my $maxdepth = scalar(@{$cats});
15106: if (ref($cats->[$depth]) eq 'HASH') {
15107: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15108: my $numchildren = @{$cats->[$depth]{$parent}};
15109: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15110: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15111: for (my $j=0; $j<$numchildren; $j++) {
15112: $name = $cats->[$depth]{$parent}[$j];
15113: $item = &escape($name).':'.&escape($parent).':'.$depth;
15114: my $deeper = $depth+1;
15115: my $checked = '';
15116: if (ref($currcategories) eq 'ARRAY') {
15117: if (@{$currcategories} > 0) {
15118: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15119: $checked = ' checked="checked"';
1.663 raeburn 15120: }
15121: }
15122: }
1.664 raeburn 15123: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15124: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15125: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15126: '<input type="hidden" name="catname" value="'.$name.'" />'.
15127: '</td><td>';
1.663 raeburn 15128: if (ref($path) eq 'ARRAY') {
15129: push(@{$path},$name);
1.1259 raeburn 15130: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15131: pop(@{$path});
15132: }
15133: $text .= '</td></tr>';
15134: }
15135: $text .= '</table></td>';
15136: }
15137: }
15138: }
15139: return $text;
15140: }
15141:
1.1181 raeburn 15142: =pod
15143:
15144: =back
15145:
15146: =cut
15147:
1.655 raeburn 15148: ############################################################
15149: ############################################################
15150:
15151:
1.443 albertel 15152: sub commit_customrole {
1.664 raeburn 15153: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15154: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15155: ($start?', '.&mt('starting').' '.localtime($start):'').
15156: ($end?', ending '.localtime($end):'').': <b>'.
15157: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15158: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15159: '</b><br />';
15160: return $output;
15161: }
15162:
15163: sub commit_standardrole {
1.1116 raeburn 15164: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15165: my ($output,$logmsg,$linefeed);
15166: if ($context eq 'auto') {
15167: $linefeed = "\n";
15168: } else {
15169: $linefeed = "<br />\n";
15170: }
1.443 albertel 15171: if ($three eq 'st') {
1.541 raeburn 15172: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15173: $one,$two,$sec,$context,$credits);
1.541 raeburn 15174: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15175: ($result eq 'unknown_course') || ($result eq 'refused')) {
15176: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15177: } else {
1.541 raeburn 15178: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15179: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15180: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15181: if ($context eq 'auto') {
15182: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15183: } else {
15184: $output .= '<b>'.$result.'</b>'.$linefeed.
15185: &mt('Add to classlist').': <b>ok</b>';
15186: }
15187: $output .= $linefeed;
1.443 albertel 15188: }
15189: } else {
15190: $output = &mt('Assigning').' '.$three.' in '.$url.
15191: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15192: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15193: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15194: if ($context eq 'auto') {
15195: $output .= $result.$linefeed;
15196: } else {
15197: $output .= '<b>'.$result.'</b>'.$linefeed;
15198: }
1.443 albertel 15199: }
15200: return $output;
15201: }
15202:
15203: sub commit_studentrole {
1.1116 raeburn 15204: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15205: $credits) = @_;
1.626 raeburn 15206: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15207: if ($context eq 'auto') {
15208: $linefeed = "\n";
15209: } else {
15210: $linefeed = '<br />'."\n";
15211: }
1.443 albertel 15212: if (defined($one) && defined($two)) {
15213: my $cid=$one.'_'.$two;
15214: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15215: my $secchange = 0;
15216: my $expire_role_result;
15217: my $modify_section_result;
1.628 raeburn 15218: if ($oldsec ne '-1') {
15219: if ($oldsec ne $sec) {
1.443 albertel 15220: $secchange = 1;
1.628 raeburn 15221: my $now = time;
1.443 albertel 15222: my $uurl='/'.$cid;
15223: $uurl=~s/\_/\//g;
15224: if ($oldsec) {
15225: $uurl.='/'.$oldsec;
15226: }
1.626 raeburn 15227: $oldsecurl = $uurl;
1.628 raeburn 15228: $expire_role_result =
1.652 raeburn 15229: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15230: if ($env{'request.course.sec'} ne '') {
15231: if ($expire_role_result eq 'refused') {
15232: my @roles = ('st');
15233: my @statuses = ('previous');
15234: my @roledoms = ($one);
15235: my $withsec = 1;
15236: my %roleshash =
15237: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15238: \@statuses,\@roles,\@roledoms,$withsec);
15239: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15240: my ($oldstart,$oldend) =
15241: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15242: if ($oldend > 0 && $oldend <= $now) {
15243: $expire_role_result = 'ok';
15244: }
15245: }
15246: }
15247: }
1.443 albertel 15248: $result = $expire_role_result;
15249: }
15250: }
15251: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15252: $modify_section_result =
15253: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15254: undef,undef,undef,$sec,
15255: $end,$start,'','',$cid,
15256: '',$context,$credits);
1.443 albertel 15257: if ($modify_section_result =~ /^ok/) {
15258: if ($secchange == 1) {
1.628 raeburn 15259: if ($sec eq '') {
15260: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15261: } else {
15262: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15263: }
1.443 albertel 15264: } elsif ($oldsec eq '-1') {
1.628 raeburn 15265: if ($sec eq '') {
15266: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15267: } else {
15268: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15269: }
1.443 albertel 15270: } else {
1.628 raeburn 15271: if ($sec eq '') {
15272: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15273: } else {
15274: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15275: }
1.443 albertel 15276: }
15277: } else {
1.1115 raeburn 15278: if ($secchange) {
1.628 raeburn 15279: $$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;
15280: } else {
15281: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15282: }
1.443 albertel 15283: }
15284: $result = $modify_section_result;
15285: } elsif ($secchange == 1) {
1.628 raeburn 15286: if ($oldsec eq '') {
1.1103 raeburn 15287: $$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 15288: } else {
15289: $$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;
15290: }
1.626 raeburn 15291: if ($expire_role_result eq 'refused') {
15292: my $newsecurl = '/'.$cid;
15293: $newsecurl =~ s/\_/\//g;
15294: if ($sec ne '') {
15295: $newsecurl.='/'.$sec;
15296: }
15297: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15298: if ($sec eq '') {
15299: $$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;
15300: } else {
15301: $$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;
15302: }
15303: }
15304: }
1.443 albertel 15305: }
15306: } else {
1.626 raeburn 15307: $$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 15308: $result = "error: incomplete course id\n";
15309: }
15310: return $result;
15311: }
15312:
1.1108 raeburn 15313: sub show_role_extent {
15314: my ($scope,$context,$role) = @_;
15315: $scope =~ s{^/}{};
15316: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15317: push(@courseroles,'co');
15318: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15319: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15320: $scope =~ s{/}{_};
15321: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15322: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15323: my ($audom,$auname) = split(/\//,$scope);
15324: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15325: &Apache::loncommon::plainname($auname,$audom).'</span>');
15326: } else {
15327: $scope =~ s{/$}{};
15328: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15329: &Apache::lonnet::domain($scope,'description').'</span>');
15330: }
15331: }
15332:
1.443 albertel 15333: ############################################################
15334: ############################################################
15335:
1.566 albertel 15336: sub check_clone {
1.578 raeburn 15337: my ($args,$linefeed) = @_;
1.566 albertel 15338: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15339: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15340: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15341: my $clonemsg;
15342: my $can_clone = 0;
1.944 raeburn 15343: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15344: if ($lctype ne 'community') {
15345: $lctype = 'course';
15346: }
1.566 albertel 15347: if ($clonehome eq 'no_host') {
1.944 raeburn 15348: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15349: $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'});
15350: } else {
15351: $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'});
15352: }
1.566 albertel 15353: } else {
15354: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15355: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15356: if ($clonedesc{'type'} ne 'Community') {
1.1262 raeburn 15357: $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 15358: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15359: }
15360: }
1.1262 raeburn 15361: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15362: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15363: $can_clone = 1;
15364: } else {
1.1221 raeburn 15365: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15366: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15367: if ($clonehash{'cloners'} eq '') {
15368: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15369: if ($domdefs{'canclone'}) {
15370: unless ($domdefs{'canclone'} eq 'none') {
15371: if ($domdefs{'canclone'} eq 'domain') {
15372: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15373: $can_clone = 1;
15374: }
15375: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15376: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15377: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15378: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15379: $can_clone = 1;
15380: }
15381: }
15382: }
15383: }
1.578 raeburn 15384: } else {
1.1221 raeburn 15385: my @cloners = split(/,/,$clonehash{'cloners'});
15386: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15387: $can_clone = 1;
1.1221 raeburn 15388: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15389: $can_clone = 1;
1.1225 raeburn 15390: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15391: $can_clone = 1;
1.1221 raeburn 15392: }
15393: unless ($can_clone) {
1.1225 raeburn 15394: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15395: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15396: my (%gotdomdefaults,%gotcodedefaults);
15397: foreach my $cloner (@cloners) {
15398: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15399: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15400: my (%codedefaults,@code_order);
15401: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15402: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15403: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15404: }
15405: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15406: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15407: }
15408: } else {
15409: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15410: \%codedefaults,
15411: \@code_order);
15412: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15413: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15414: }
15415: if (@code_order > 0) {
15416: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15417: $cloner,$clonehash{'internal.coursecode'},
15418: $args->{'crscode'})) {
15419: $can_clone = 1;
15420: last;
15421: }
15422: }
15423: }
15424: }
15425: }
1.1225 raeburn 15426: }
15427: }
15428: unless ($can_clone) {
15429: my $ccrole = 'cc';
15430: if ($args->{'crstype'} eq 'Community') {
15431: $ccrole = 'co';
15432: }
15433: my %roleshash =
15434: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15435: $args->{'ccdomain'},
15436: 'userroles',['active'],[$ccrole],
15437: [$args->{'clonedomain'}]);
15438: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15439: $can_clone = 1;
15440: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15441: $args->{'ccuname'},$args->{'ccdomain'})) {
15442: $can_clone = 1;
1.1221 raeburn 15443: }
15444: }
15445: unless ($can_clone) {
15446: if ($args->{'crstype'} eq 'Community') {
15447: $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 15448: } else {
1.1221 raeburn 15449: $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'});
15450: }
1.566 albertel 15451: }
1.578 raeburn 15452: }
1.566 albertel 15453: }
15454: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15455: }
15456:
1.444 albertel 15457: sub construct_course {
1.1262 raeburn 15458: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15459: $cnum,$category,$coderef) = @_;
1.444 albertel 15460: my $outcome;
1.541 raeburn 15461: my $linefeed = '<br />'."\n";
15462: if ($context eq 'auto') {
15463: $linefeed = "\n";
15464: }
1.566 albertel 15465:
15466: #
15467: # Are we cloning?
15468: #
15469: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15470: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15471: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15472: if ($context ne 'auto') {
1.578 raeburn 15473: if ($clonemsg ne '') {
15474: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15475: }
1.566 albertel 15476: }
15477: $outcome .= $clonemsg.$linefeed;
15478:
15479: if (!$can_clone) {
15480: return (0,$outcome);
15481: }
15482: }
15483:
1.444 albertel 15484: #
15485: # Open course
15486: #
1.1239 raeburn 15487: my $showncrstype;
15488: if ($args->{'crstype'} eq 'Placement') {
15489: $showncrstype = 'placement test';
15490: } else {
15491: $showncrstype = lc($args->{'crstype'});
15492: }
1.444 albertel 15493: my %cenv=();
15494: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15495: $args->{'cdescr'},
15496: $args->{'curl'},
15497: $args->{'course_home'},
15498: $args->{'nonstandard'},
15499: $args->{'crscode'},
15500: $args->{'ccuname'}.':'.
15501: $args->{'ccdomain'},
1.882 raeburn 15502: $args->{'crstype'},
1.885 raeburn 15503: $cnum,$context,$category);
1.444 albertel 15504:
15505: # Note: The testing routines depend on this being output; see
15506: # Utils::Course. This needs to at least be output as a comment
15507: # if anyone ever decides to not show this, and Utils::Course::new
15508: # will need to be suitably modified.
1.1239 raeburn 15509: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15510: if ($$courseid =~ /^error:/) {
15511: return (0,$outcome);
15512: }
15513:
1.444 albertel 15514: #
15515: # Check if created correctly
15516: #
1.479 albertel 15517: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15518: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15519: if ($crsuhome eq 'no_host') {
15520: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15521: return (0,$outcome);
15522: }
1.541 raeburn 15523: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15524:
1.444 albertel 15525: #
1.566 albertel 15526: # Do the cloning
15527: #
15528: if ($can_clone && $cloneid) {
1.1239 raeburn 15529: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 15530: if ($context ne 'auto') {
15531: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15532: }
15533: $outcome .= $clonemsg.$linefeed;
15534: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15535: # Copy all files
1.637 www 15536: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15537: # Restore URL
1.566 albertel 15538: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15539: # Restore title
1.566 albertel 15540: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15541: # Restore creation date, creator and creation context.
15542: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15543: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15544: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15545: # Mark as cloned
1.566 albertel 15546: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15547: # Need to clone grading mode
15548: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15549: $cenv{'grading'}=$newenv{'grading'};
15550: # Do not clone these environment entries
15551: &Apache::lonnet::del('environment',
15552: ['default_enrollment_start_date',
15553: 'default_enrollment_end_date',
15554: 'question.email',
15555: 'policy.email',
15556: 'comment.email',
15557: 'pch.users.denied',
1.725 raeburn 15558: 'plc.users.denied',
15559: 'hidefromcat',
1.1121 raeburn 15560: 'checkforpriv',
1.1166 raeburn 15561: 'categories',
15562: 'internal.uniquecode'],
1.638 www 15563: $$crsudom,$$crsunum);
1.1170 raeburn 15564: if ($args->{'textbook'}) {
15565: $cenv{'internal.textbook'} = $args->{'textbook'};
15566: }
1.444 albertel 15567: }
1.566 albertel 15568:
1.444 albertel 15569: #
15570: # Set environment (will override cloned, if existing)
15571: #
15572: my @sections = ();
15573: my @xlists = ();
15574: if ($args->{'crstype'}) {
15575: $cenv{'type'}=$args->{'crstype'};
15576: }
15577: if ($args->{'crsid'}) {
15578: $cenv{'courseid'}=$args->{'crsid'};
15579: }
15580: if ($args->{'crscode'}) {
15581: $cenv{'internal.coursecode'}=$args->{'crscode'};
15582: }
15583: if ($args->{'crsquota'} ne '') {
15584: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15585: } else {
15586: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15587: }
15588: if ($args->{'ccuname'}) {
15589: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15590: ':'.$args->{'ccdomain'};
15591: } else {
15592: $cenv{'internal.courseowner'} = $args->{'curruser'};
15593: }
1.1116 raeburn 15594: if ($args->{'defaultcredits'}) {
15595: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15596: }
1.444 albertel 15597: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15598: if ($args->{'crssections'}) {
15599: $cenv{'internal.sectionnums'} = '';
15600: if ($args->{'crssections'} =~ m/,/) {
15601: @sections = split/,/,$args->{'crssections'};
15602: } else {
15603: $sections[0] = $args->{'crssections'};
15604: }
15605: if (@sections > 0) {
15606: foreach my $item (@sections) {
15607: my ($sec,$gp) = split/:/,$item;
15608: my $class = $args->{'crscode'}.$sec;
15609: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15610: $cenv{'internal.sectionnums'} .= $item.',';
15611: unless ($addcheck eq 'ok') {
1.1263 raeburn 15612: push(@badclasses,$class);
1.444 albertel 15613: }
15614: }
15615: $cenv{'internal.sectionnums'} =~ s/,$//;
15616: }
15617: }
15618: # do not hide course coordinator from staff listing,
15619: # even if privileged
15620: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 15621: # add course coordinator's domain to domains to check for privileged users
15622: # if different to course domain
15623: if ($$crsudom ne $args->{'ccdomain'}) {
15624: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15625: }
1.444 albertel 15626: # add crosslistings
15627: if ($args->{'crsxlist'}) {
15628: $cenv{'internal.crosslistings'}='';
15629: if ($args->{'crsxlist'} =~ m/,/) {
15630: @xlists = split/,/,$args->{'crsxlist'};
15631: } else {
15632: $xlists[0] = $args->{'crsxlist'};
15633: }
15634: if (@xlists > 0) {
15635: foreach my $item (@xlists) {
15636: my ($xl,$gp) = split/:/,$item;
15637: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15638: $cenv{'internal.crosslistings'} .= $item.',';
15639: unless ($addcheck eq 'ok') {
1.1263 raeburn 15640: push(@badclasses,$xl);
1.444 albertel 15641: }
15642: }
15643: $cenv{'internal.crosslistings'} =~ s/,$//;
15644: }
15645: }
15646: if ($args->{'autoadds'}) {
15647: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15648: }
15649: if ($args->{'autodrops'}) {
15650: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15651: }
15652: # check for notification of enrollment changes
15653: my @notified = ();
15654: if ($args->{'notify_owner'}) {
15655: if ($args->{'ccuname'} ne '') {
15656: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15657: }
15658: }
15659: if ($args->{'notify_dc'}) {
15660: if ($uname ne '') {
1.630 raeburn 15661: push(@notified,$uname.':'.$udom);
1.444 albertel 15662: }
15663: }
15664: if (@notified > 0) {
15665: my $notifylist;
15666: if (@notified > 1) {
15667: $notifylist = join(',',@notified);
15668: } else {
15669: $notifylist = $notified[0];
15670: }
15671: $cenv{'internal.notifylist'} = $notifylist;
15672: }
15673: if (@badclasses > 0) {
15674: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 15675: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15676: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15677: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15678: );
1.1264 raeburn 15679: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15680: &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 15681: if ($context eq 'auto') {
15682: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 15683: } else {
1.566 albertel 15684: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 15685: }
15686: foreach my $item (@badclasses) {
1.541 raeburn 15687: if ($context eq 'auto') {
1.1261 raeburn 15688: $outcome .= " - $item\n";
1.541 raeburn 15689: } else {
1.1261 raeburn 15690: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15691: }
1.1261 raeburn 15692: }
15693: if ($context eq 'auto') {
15694: $outcome .= $linefeed;
15695: } else {
15696: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 15697: }
1.444 albertel 15698: }
15699: if ($args->{'no_end_date'}) {
15700: $args->{'endaccess'} = 0;
15701: }
15702: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15703: $cenv{'internal.autoend'}=$args->{'enrollend'};
15704: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15705: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15706: if ($args->{'showphotos'}) {
15707: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15708: }
15709: $cenv{'internal.authtype'} = $args->{'authtype'};
15710: $cenv{'internal.autharg'} = $args->{'autharg'};
15711: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15712: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15713: 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');
15714: if ($context eq 'auto') {
15715: $outcome .= $krb_msg;
15716: } else {
1.566 albertel 15717: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15718: }
15719: $outcome .= $linefeed;
1.444 albertel 15720: }
15721: }
15722: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15723: if ($args->{'setpolicy'}) {
15724: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15725: }
15726: if ($args->{'setcontent'}) {
15727: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15728: }
1.1251 raeburn 15729: if ($args->{'setcomment'}) {
15730: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15731: }
1.444 albertel 15732: }
15733: if ($args->{'reshome'}) {
15734: $cenv{'reshome'}=$args->{'reshome'}.'/';
15735: $cenv{'reshome'}=~s/\/+$/\//;
15736: }
15737: #
15738: # course has keyed access
15739: #
15740: if ($args->{'setkeys'}) {
15741: $cenv{'keyaccess'}='yes';
15742: }
15743: # if specified, key authority is not course, but user
15744: # only active if keyaccess is yes
15745: if ($args->{'keyauth'}) {
1.487 albertel 15746: my ($user,$domain) = split(':',$args->{'keyauth'});
15747: $user = &LONCAPA::clean_username($user);
15748: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15749: if ($user ne '' && $domain ne '') {
1.487 albertel 15750: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15751: }
15752: }
15753:
1.1166 raeburn 15754: #
1.1167 raeburn 15755: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 15756: #
15757: if ($args->{'uniquecode'}) {
15758: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15759: if ($code) {
15760: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 15761: my %crsinfo =
15762: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15763: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15764: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15765: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15766: }
1.1166 raeburn 15767: if (ref($coderef)) {
15768: $$coderef = $code;
15769: }
15770: }
15771: }
15772:
1.444 albertel 15773: if ($args->{'disresdis'}) {
15774: $cenv{'pch.roles.denied'}='st';
15775: }
15776: if ($args->{'disablechat'}) {
15777: $cenv{'plc.roles.denied'}='st';
15778: }
15779:
15780: # Record we've not yet viewed the Course Initialization Helper for this
15781: # course
15782: $cenv{'course.helper.not.run'} = 1;
15783: #
15784: # Use new Randomseed
15785: #
15786: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15787: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15788: #
15789: # The encryption code and receipt prefix for this course
15790: #
15791: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15792: $cenv{'internal.encpref'}=100+int(9*rand(99));
15793: #
15794: # By default, use standard grading
15795: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15796:
1.541 raeburn 15797: $outcome .= $linefeed.&mt('Setting environment').': '.
15798: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15799: #
15800: # Open all assignments
15801: #
15802: if ($args->{'openall'}) {
15803: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15804: my %storecontent = ($storeunder => time,
15805: $storeunder.'.type' => 'date_start');
15806:
15807: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15808: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15809: }
15810: #
15811: # Set first page
15812: #
15813: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15814: || ($cloneid)) {
1.445 albertel 15815: use LONCAPA::map;
1.444 albertel 15816: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15817:
15818: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15819: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15820:
1.444 albertel 15821: $outcome .= ($fatal?$errtext:'read ok').' - ';
15822: my $title; my $url;
15823: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15824: $title=&mt('Syllabus');
1.444 albertel 15825: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15826: } else {
1.963 raeburn 15827: $title=&mt('Table of Contents');
1.444 albertel 15828: $url='/adm/navmaps';
15829: }
1.445 albertel 15830:
15831: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15832: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15833:
15834: if ($errtext) { $fatal=2; }
1.541 raeburn 15835: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15836: }
1.566 albertel 15837:
1.1237 raeburn 15838: #
15839: # Set params for Placement Tests
15840: #
1.1239 raeburn 15841: if ($args->{'crstype'} eq 'Placement') {
15842: my %storecontent;
15843: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
15844: my %defaults = (
15845: buttonshide => { value => 'yes',
15846: type => 'string_yesno',},
15847: type => { value => 'randomizetry',
15848: type => 'string_questiontype',},
15849: maxtries => { value => 1,
15850: type => 'int_pos',},
15851: problemstatus => { value => 'no',
15852: type => 'string_problemstatus',},
15853: );
15854: foreach my $key (keys(%defaults)) {
15855: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
15856: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
15857: }
1.1237 raeburn 15858: &Apache::lonnet::cput
15859: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
15860: }
15861:
1.566 albertel 15862: return (1,$outcome);
1.444 albertel 15863: }
15864:
1.1166 raeburn 15865: sub make_unique_code {
15866: my ($cdom,$cnum) = @_;
15867: # get lock on uniquecodes db
15868: my $lockhash = {
15869: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15870: ':'.$env{'user.domain'},
15871: };
15872: my $tries = 0;
15873: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15874: my ($code,$error);
15875:
15876: while (($gotlock ne 'ok') && ($tries<3)) {
15877: $tries ++;
15878: sleep 1;
15879: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15880: }
15881: if ($gotlock eq 'ok') {
15882: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15883: my $gotcode;
15884: my $attempts = 0;
15885: while ((!$gotcode) && ($attempts < 100)) {
15886: $code = &generate_code();
15887: if (!exists($currcodes{$code})) {
15888: $gotcode = 1;
15889: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15890: $error = 'nostore';
15891: }
15892: }
15893: $attempts ++;
15894: }
15895: my @del_lock = ($cnum."\0".'uniquecodes');
15896: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15897: } else {
15898: $error = 'nolock';
15899: }
15900: return ($code,$error);
15901: }
15902:
15903: sub generate_code {
15904: my $code;
15905: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15906: for (my $i=0; $i<6; $i++) {
15907: my $lettnum = int (rand 2);
15908: my $item = '';
15909: if ($lettnum) {
15910: $item = $letts[int( rand(18) )];
15911: } else {
15912: $item = 1+int( rand(8) );
15913: }
15914: $code .= $item;
15915: }
15916: return $code;
15917: }
15918:
1.444 albertel 15919: ############################################################
15920: ############################################################
15921:
1.1237 raeburn 15922: # Community, Course and Placement Test
1.378 raeburn 15923: sub course_type {
15924: my ($cid) = @_;
15925: if (!defined($cid)) {
15926: $cid = $env{'request.course.id'};
15927: }
1.404 albertel 15928: if (defined($env{'course.'.$cid.'.type'})) {
15929: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15930: } else {
15931: return 'Course';
1.377 raeburn 15932: }
15933: }
1.156 albertel 15934:
1.406 raeburn 15935: sub group_term {
15936: my $crstype = &course_type();
15937: my %names = (
15938: 'Course' => 'group',
1.865 raeburn 15939: 'Community' => 'group',
1.1237 raeburn 15940: 'Placement' => 'group',
1.406 raeburn 15941: );
15942: return $names{$crstype};
15943: }
15944:
1.902 raeburn 15945: sub course_types {
1.1237 raeburn 15946: my @types = ('official','unofficial','community','textbook','placement');
1.902 raeburn 15947: my %typename = (
15948: official => 'Official course',
15949: unofficial => 'Unofficial course',
15950: community => 'Community',
1.1165 raeburn 15951: textbook => 'Textbook course',
1.1237 raeburn 15952: placement => 'Placement test',
1.902 raeburn 15953: );
15954: return (\@types,\%typename);
15955: }
15956:
1.156 albertel 15957: sub icon {
15958: my ($file)=@_;
1.505 albertel 15959: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15960: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15961: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15962: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15963: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15964: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15965: $curfext.".gif") {
15966: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15967: $curfext.".gif";
15968: }
15969: }
1.249 albertel 15970: return &lonhttpdurl($iconname);
1.154 albertel 15971: }
1.84 albertel 15972:
1.575 albertel 15973: sub lonhttpdurl {
1.692 www 15974: #
15975: # Had been used for "small fry" static images on separate port 8080.
15976: # Modify here if lightweight http functionality desired again.
15977: # Currently eliminated due to increasing firewall issues.
15978: #
1.575 albertel 15979: my ($url)=@_;
1.692 www 15980: return $url;
1.215 albertel 15981: }
15982:
1.213 albertel 15983: sub connection_aborted {
15984: my ($r)=@_;
15985: $r->print(" ");$r->rflush();
15986: my $c = $r->connection;
15987: return $c->aborted();
15988: }
15989:
1.221 foxr 15990: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15991: # strings as 'strings'.
15992: sub escape_single {
1.221 foxr 15993: my ($input) = @_;
1.223 albertel 15994: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15995: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15996: return $input;
15997: }
1.223 albertel 15998:
1.222 foxr 15999: # Same as escape_single, but escape's "'s This
16000: # can be used for "strings"
16001: sub escape_double {
16002: my ($input) = @_;
16003: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16004: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16005: return $input;
16006: }
1.223 albertel 16007:
1.222 foxr 16008: # Escapes the last element of a full URL.
16009: sub escape_url {
16010: my ($url) = @_;
1.238 raeburn 16011: my @urlslices = split(/\//, $url,-1);
1.369 www 16012: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16013: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16014: }
1.462 albertel 16015:
1.820 raeburn 16016: sub compare_arrays {
16017: my ($arrayref1,$arrayref2) = @_;
16018: my (@difference,%count);
16019: @difference = ();
16020: %count = ();
16021: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16022: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16023: foreach my $element (keys(%count)) {
16024: if ($count{$element} == 1) {
16025: push(@difference,$element);
16026: }
16027: }
16028: }
16029: return @difference;
16030: }
16031:
1.817 bisitz 16032: # -------------------------------------------------------- Initialize user login
1.462 albertel 16033: sub init_user_environment {
1.463 albertel 16034: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16035: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16036:
16037: my $public=($username eq 'public' && $domain eq 'public');
16038:
1.1062 raeburn 16039: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16040: my $now=time;
16041:
16042: if ($public) {
16043: my $max_public=100;
16044: my $oldest;
16045: my $oldest_time=0;
16046: for(my $next=1;$next<=$max_public;$next++) {
16047: if (-e $lonids."/publicuser_$next.id") {
16048: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16049: if ($mtime<$oldest_time || !$oldest_time) {
16050: $oldest_time=$mtime;
16051: $oldest=$next;
16052: }
16053: } else {
16054: $cookie="publicuser_$next";
16055: last;
16056: }
16057: }
16058: if (!$cookie) { $cookie="publicuser_$oldest"; }
16059: } else {
1.1275 raeburn 16060: # See if old ID present, if so, remove if this isn't a robot,
16061: # killing any existing non-robot sessions
1.463 albertel 16062: if (!$args->{'robot'}) {
16063: opendir(DIR,$lonids);
16064: while ($filename=readdir(DIR)) {
16065: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
16066: unlink($lonids.'/'.$filename);
16067: }
1.462 albertel 16068: }
1.463 albertel 16069: closedir(DIR);
1.1204 raeburn 16070: # If there is a undeleted lockfile for the user's paste buffer remove it.
16071: my $namespace = 'nohist_courseeditor';
16072: my $lockingkey = 'paste'."\0".'locked_num';
16073: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16074: $domain,$username);
16075: if (exists($lockhash{$lockingkey})) {
16076: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16077: unless ($delresult eq 'ok') {
16078: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16079: }
16080: }
1.462 albertel 16081: }
16082: # Give them a new cookie
1.463 albertel 16083: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16084: : $now.$$.int(rand(10000)));
1.463 albertel 16085: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16086:
16087: # Initialize roles
16088:
1.1062 raeburn 16089: ($userroles,$firstaccenv,$timerintenv) =
16090: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16091: }
16092: # ------------------------------------ Check browser type and MathML capability
16093:
1.1194 raeburn 16094: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16095: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16096:
16097: # ------------------------------------------------------------- Get environment
16098:
16099: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16100: my ($tmp) = keys(%userenv);
1.1275 raeburn 16101: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16102: undef(%userenv);
16103: }
16104: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16105: $form->{'interface'}=$userenv{'interface'};
16106: }
16107: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16108:
16109: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16110: foreach my $option ('interface','localpath','localres') {
16111: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16112: }
16113: # --------------------------------------------------------- Write first profile
16114:
16115: {
16116: my %initial_env =
16117: ("user.name" => $username,
16118: "user.domain" => $domain,
16119: "user.home" => $authhost,
16120: "browser.type" => $clientbrowser,
16121: "browser.version" => $clientversion,
16122: "browser.mathml" => $clientmathml,
16123: "browser.unicode" => $clientunicode,
16124: "browser.os" => $clientos,
1.1137 raeburn 16125: "browser.mobile" => $clientmobile,
1.1141 raeburn 16126: "browser.info" => $clientinfo,
1.1194 raeburn 16127: "browser.osversion" => $clientosversion,
1.462 albertel 16128: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16129: "request.course.fn" => '',
16130: "request.course.uri" => '',
16131: "request.course.sec" => '',
16132: "request.role" => 'cm',
16133: "request.role.adv" => $env{'user.adv'},
16134: "request.host" => $ENV{'REMOTE_ADDR'},);
16135:
16136: if ($form->{'localpath'}) {
16137: $initial_env{"browser.localpath"} = $form->{'localpath'};
16138: $initial_env{"browser.localres"} = $form->{'localres'};
16139: }
16140:
16141: if ($form->{'interface'}) {
16142: $form->{'interface'}=~s/\W//gs;
16143: $initial_env{"browser.interface"} = $form->{'interface'};
16144: $env{'browser.interface'}=$form->{'interface'};
16145: }
16146:
1.1157 raeburn 16147: if ($form->{'iptoken'}) {
16148: my $lonhost = $r->dir_config('lonHostID');
16149: $initial_env{"user.noloadbalance"} = $lonhost;
16150: $env{'user.noloadbalance'} = $lonhost;
16151: }
16152:
1.1268 raeburn 16153: if ($form->{'noloadbalance'}) {
16154: my @hosts = &Apache::lonnet::current_machine_ids();
16155: my $hosthere = $form->{'noloadbalance'};
16156: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16157: $initial_env{"user.noloadbalance"} = $hosthere;
16158: $env{'user.noloadbalance'} = $hosthere;
16159: }
16160: }
16161:
1.1016 raeburn 16162: unless ($domain eq 'public') {
1.1273 raeburn 16163: my %is_adv = ( is_adv => $env{'user.adv'} );
16164: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16165:
16166: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16167: $userenv{'availabletools.'.$tool} =
16168: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16169: undef,\%userenv,\%domdef,\%is_adv);
16170: }
1.980 raeburn 16171:
1.1273 raeburn 16172: foreach my $crstype ('official','unofficial','community','textbook','placement') {
16173: $userenv{'canrequest.'.$crstype} =
16174: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16175: 'reload','requestcourses',
16176: \%userenv,\%domdef,\%is_adv);
16177: }
1.724 raeburn 16178:
1.1273 raeburn 16179: $userenv{'canrequest.author'} =
16180: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16181: 'reload','requestauthor',
1.980 raeburn 16182: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16183: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16184: $domain,$username);
16185: my $reqstatus = $reqauthor{'author_status'};
16186: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16187: if (ref($reqauthor{'author'}) eq 'HASH') {
16188: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16189: $reqauthor{'author'}{'timestamp'};
16190: }
1.1092 raeburn 16191: }
16192: }
16193:
1.462 albertel 16194: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16195:
1.462 albertel 16196: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16197: &GDBM_WRCREAT(),0640)) {
16198: &_add_to_env(\%disk_env,\%initial_env);
16199: &_add_to_env(\%disk_env,\%userenv,'environment.');
16200: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16201: if (ref($firstaccenv) eq 'HASH') {
16202: &_add_to_env(\%disk_env,$firstaccenv);
16203: }
16204: if (ref($timerintenv) eq 'HASH') {
16205: &_add_to_env(\%disk_env,$timerintenv);
16206: }
1.463 albertel 16207: if (ref($args->{'extra_env'})) {
16208: &_add_to_env(\%disk_env,$args->{'extra_env'});
16209: }
1.462 albertel 16210: untie(%disk_env);
16211: } else {
1.705 tempelho 16212: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16213: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16214: return 'error: '.$!;
16215: }
16216: }
16217: $env{'request.role'}='cm';
16218: $env{'request.role.adv'}=$env{'user.adv'};
16219: $env{'browser.type'}=$clientbrowser;
16220:
16221: return $cookie;
16222:
16223: }
16224:
16225: sub _add_to_env {
16226: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16227: if (ref($env_data) eq 'HASH') {
16228: while (my ($key,$value) = each(%$env_data)) {
16229: $idf->{$prefix.$key} = $value;
16230: $env{$prefix.$key} = $value;
16231: }
1.462 albertel 16232: }
16233: }
16234:
1.685 tempelho 16235: # --- Get the symbolic name of a problem and the url
16236: sub get_symb {
16237: my ($request,$silent) = @_;
1.726 raeburn 16238: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16239: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16240: if ($symb eq '') {
16241: if (!$silent) {
1.1071 raeburn 16242: if (ref($request)) {
16243: $request->print("Unable to handle ambiguous references:$url:.");
16244: }
1.685 tempelho 16245: return ();
16246: }
16247: }
16248: &Apache::lonenc::check_decrypt(\$symb);
16249: return ($symb);
16250: }
16251:
16252: # --------------------------------------------------------------Get annotation
16253:
16254: sub get_annotation {
16255: my ($symb,$enc) = @_;
16256:
16257: my $key = $symb;
16258: if (!$enc) {
16259: $key =
16260: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16261: }
16262: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16263: return $annotation{$key};
16264: }
16265:
16266: sub clean_symb {
1.731 raeburn 16267: my ($symb,$delete_enc) = @_;
1.685 tempelho 16268:
16269: &Apache::lonenc::check_decrypt(\$symb);
16270: my $enc = $env{'request.enc'};
1.731 raeburn 16271: if ($delete_enc) {
1.730 raeburn 16272: delete($env{'request.enc'});
16273: }
1.685 tempelho 16274:
16275: return ($symb,$enc);
16276: }
1.462 albertel 16277:
1.1181 raeburn 16278: ############################################################
16279: ############################################################
16280:
16281: =pod
16282:
16283: =head1 Routines for building display used to search for courses
16284:
16285:
16286: =over 4
16287:
16288: =item * &build_filters()
16289:
16290: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16291: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16292: and quotacheck.pl
16293:
1.1181 raeburn 16294:
16295: Inputs:
16296:
16297: filterlist - anonymous array of fields to include as potential filters
16298:
16299: crstype - course type
16300:
16301: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16302: to pop-open a course selector (will contain "extra element").
16303:
16304: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16305:
16306: filter - anonymous hash of criteria and their values
16307:
16308: action - form action
16309:
16310: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16311:
1.1182 raeburn 16312: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16313:
16314: cloneruname - username of owner of new course who wants to clone
16315:
16316: clonerudom - domain of owner of new course who wants to clone
16317:
16318: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16319:
16320: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16321:
16322: codedom - domain
16323:
16324: formname - value of form element named "form".
16325:
16326: fixeddom - domain, if fixed.
16327:
16328: prevphase - value to assign to form element named "phase" when going back to the previous screen
16329:
16330: cnameelement - name of form element in form on opener page which will receive title of selected course
16331:
16332: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16333:
16334: cdomelement - name of form element in form on opener page which will receive domain of selected course
16335:
16336: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16337:
16338: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16339:
16340: clonewarning - warning message about missing information for intended course owner when DC creates a course
16341:
1.1182 raeburn 16342:
1.1181 raeburn 16343: Returns: $output - HTML for display of search criteria, and hidden form elements.
16344:
1.1182 raeburn 16345:
1.1181 raeburn 16346: Side Effects: None
16347:
16348: =cut
16349:
16350: # ---------------------------------------------- search for courses based on last activity etc.
16351:
16352: sub build_filters {
16353: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16354: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16355: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16356: $cnameelement,$cnumelement,$cdomelement,$setroles,
16357: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16358: my ($list,$jscript);
1.1181 raeburn 16359: my $onchange = 'javascript:updateFilters(this)';
16360: my ($domainselectform,$sincefilterform,$createdfilterform,
16361: $ownerdomselectform,$persondomselectform,$instcodeform,
16362: $typeselectform,$instcodetitle);
16363: if ($formname eq '') {
16364: $formname = $caller;
16365: }
16366: foreach my $item (@{$filterlist}) {
16367: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16368: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16369: if ($item eq 'domainfilter') {
16370: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16371: } elsif ($item eq 'coursefilter') {
16372: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16373: } elsif ($item eq 'ownerfilter') {
16374: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16375: } elsif ($item eq 'ownerdomfilter') {
16376: $filter->{'ownerdomfilter'} =
16377: &LONCAPA::clean_domain($filter->{$item});
16378: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16379: 'ownerdomfilter',1);
16380: } elsif ($item eq 'personfilter') {
16381: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16382: } elsif ($item eq 'persondomfilter') {
16383: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16384: 'persondomfilter',1);
16385: } else {
16386: $filter->{$item} =~ s/\W//g;
16387: }
16388: if (!$filter->{$item}) {
16389: $filter->{$item} = '';
16390: }
16391: }
16392: if ($item eq 'domainfilter') {
16393: my $allow_blank = 1;
16394: if ($formname eq 'portform') {
16395: $allow_blank=0;
16396: } elsif ($formname eq 'studentform') {
16397: $allow_blank=0;
16398: }
16399: if ($fixeddom) {
16400: $domainselectform = '<input type="hidden" name="domainfilter"'.
16401: ' value="'.$codedom.'" />'.
16402: &Apache::lonnet::domain($codedom,'description');
16403: } else {
16404: $domainselectform = &select_dom_form($filter->{$item},
16405: 'domainfilter',
16406: $allow_blank,'',$onchange);
16407: }
16408: } else {
16409: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16410: }
16411: }
16412:
16413: # last course activity filter and selection
16414: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16415:
16416: # course created filter and selection
16417: if (exists($filter->{'createdfilter'})) {
16418: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16419: }
16420:
1.1239 raeburn 16421: my $prefix = $crstype;
16422: if ($crstype eq 'Placement') {
16423: $prefix = 'Placement Test'
16424: }
1.1181 raeburn 16425: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16426: 'cac' => "$prefix Activity",
16427: 'ccr' => "$prefix Created",
16428: 'cde' => "$prefix Title",
16429: 'cdo' => "$prefix Domain",
1.1181 raeburn 16430: 'ins' => 'Institutional Code',
16431: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16432: 'cow' => "$prefix Owner/Co-owner",
16433: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16434: 'cog' => 'Type',
16435: );
16436:
16437: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16438: my $typeval = 'Course';
16439: if ($crstype eq 'Community') {
16440: $typeval = 'Community';
1.1239 raeburn 16441: } elsif ($crstype eq 'Placement') {
16442: $typeval = 'Placement';
1.1181 raeburn 16443: }
16444: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16445: } else {
16446: $typeselectform = '<select name="type" size="1"';
16447: if ($onchange) {
16448: $typeselectform .= ' onchange="'.$onchange.'"';
16449: }
16450: $typeselectform .= '>'."\n";
1.1237 raeburn 16451: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16452: my $shown;
16453: if ($posstype eq 'Placement') {
16454: $shown = &mt('Placement Test');
16455: } else {
16456: $shown = &mt($posstype);
16457: }
1.1181 raeburn 16458: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 16459: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 16460: }
16461: $typeselectform.="</select>";
16462: }
16463:
16464: my ($cloneableonlyform,$cloneabletitle);
16465: if (exists($filter->{'cloneableonly'})) {
16466: my $cloneableon = '';
16467: my $cloneableoff = ' checked="checked"';
16468: if ($filter->{'cloneableonly'}) {
16469: $cloneableon = $cloneableoff;
16470: $cloneableoff = '';
16471: }
16472: $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>';
16473: if ($formname eq 'ccrs') {
1.1187 bisitz 16474: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 16475: } else {
16476: $cloneabletitle = &mt('Cloneable by you');
16477: }
16478: }
16479: my $officialjs;
16480: if ($crstype eq 'Course') {
16481: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 16482: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16483: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16484: if ($codedom) {
1.1181 raeburn 16485: $officialjs = 1;
16486: ($instcodeform,$jscript,$$numtitlesref) =
16487: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16488: $officialjs,$codetitlesref);
16489: if ($jscript) {
1.1182 raeburn 16490: $jscript = '<script type="text/javascript">'."\n".
16491: '// <![CDATA['."\n".
16492: $jscript."\n".
16493: '// ]]>'."\n".
16494: '</script>'."\n";
1.1181 raeburn 16495: }
16496: }
16497: if ($instcodeform eq '') {
16498: $instcodeform =
16499: '<input type="text" name="instcodefilter" size="10" value="'.
16500: $list->{'instcodefilter'}.'" />';
16501: $instcodetitle = $lt{'ins'};
16502: } else {
16503: $instcodetitle = $lt{'inc'};
16504: }
16505: if ($fixeddom) {
16506: $instcodetitle .= '<br />('.$codedom.')';
16507: }
16508: }
16509: }
16510: my $output = qq|
16511: <form method="post" name="filterpicker" action="$action">
16512: <input type="hidden" name="form" value="$formname" />
16513: |;
16514: if ($formname eq 'modifycourse') {
16515: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16516: '<input type="hidden" name="prevphase" value="'.
16517: $prevphase.'" />'."\n";
1.1198 musolffc 16518: } elsif ($formname eq 'quotacheck') {
16519: $output .= qq|
16520: <input type="hidden" name="sortby" value="" />
16521: <input type="hidden" name="sortorder" value="" />
16522: |;
16523: } else {
1.1181 raeburn 16524: my $name_input;
16525: if ($cnameelement ne '') {
16526: $name_input = '<input type="hidden" name="cnameelement" value="'.
16527: $cnameelement.'" />';
16528: }
16529: $output .= qq|
1.1182 raeburn 16530: <input type="hidden" name="cnumelement" value="$cnumelement" />
16531: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 16532: $name_input
16533: $roleelement
16534: $multelement
16535: $typeelement
16536: |;
16537: if ($formname eq 'portform') {
16538: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16539: }
16540: }
16541: if ($fixeddom) {
16542: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16543: }
16544: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16545: if ($sincefilterform) {
16546: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16547: .$sincefilterform
16548: .&Apache::lonhtmlcommon::row_closure();
16549: }
16550: if ($createdfilterform) {
16551: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16552: .$createdfilterform
16553: .&Apache::lonhtmlcommon::row_closure();
16554: }
16555: if ($domainselectform) {
16556: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16557: .$domainselectform
16558: .&Apache::lonhtmlcommon::row_closure();
16559: }
16560: if ($typeselectform) {
16561: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16562: $output .= $typeselectform;
16563: } else {
16564: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16565: .$typeselectform
16566: .&Apache::lonhtmlcommon::row_closure();
16567: }
16568: }
16569: if ($instcodeform) {
16570: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16571: .$instcodeform
16572: .&Apache::lonhtmlcommon::row_closure();
16573: }
16574: if (exists($filter->{'ownerfilter'})) {
16575: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16576: '<table><tr><td>'.&mt('Username').'<br />'.
16577: '<input type="text" name="ownerfilter" size="20" value="'.
16578: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16579: $ownerdomselectform.'</td></tr></table>'.
16580: &Apache::lonhtmlcommon::row_closure();
16581: }
16582: if (exists($filter->{'personfilter'})) {
16583: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16584: '<table><tr><td>'.&mt('Username').'<br />'.
16585: '<input type="text" name="personfilter" size="20" value="'.
16586: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16587: $persondomselectform.'</td></tr></table>'.
16588: &Apache::lonhtmlcommon::row_closure();
16589: }
16590: if (exists($filter->{'coursefilter'})) {
16591: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16592: .'<input type="text" name="coursefilter" size="25" value="'
16593: .$list->{'coursefilter'}.'" />'
16594: .&Apache::lonhtmlcommon::row_closure();
16595: }
16596: if ($cloneableonlyform) {
16597: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16598: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16599: }
16600: if (exists($filter->{'descriptfilter'})) {
16601: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16602: .'<input type="text" name="descriptfilter" size="40" value="'
16603: .$list->{'descriptfilter'}.'" />'
16604: .&Apache::lonhtmlcommon::row_closure(1);
16605: }
16606: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16607: '<input type="hidden" name="updater" value="" />'."\n".
16608: '<input type="submit" name="gosearch" value="'.
16609: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16610: return $jscript.$clonewarning.$output;
16611: }
16612:
16613: =pod
16614:
16615: =item * &timebased_select_form()
16616:
1.1182 raeburn 16617: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 16618: filter e.g., Course Activity, Course Created, when searching for courses
16619: or communities
16620:
16621: Inputs:
16622:
16623: item - name of form element (sincefilter or createdfilter)
16624:
16625: filter - anonymous hash of criteria and their values
16626:
16627: Returns: HTML for a select box contained a blank, then six time selections,
16628: with value set in incoming form variables currently selected.
16629:
16630: Side Effects: None
16631:
16632: =cut
16633:
16634: sub timebased_select_form {
16635: my ($item,$filter) = @_;
16636: if (ref($filter) eq 'HASH') {
16637: $filter->{$item} =~ s/[^\d-]//g;
16638: if (!$filter->{$item}) { $filter->{$item}=-1; }
16639: return &select_form(
16640: $filter->{$item},
16641: $item,
16642: { '-1' => '',
16643: '86400' => &mt('today'),
16644: '604800' => &mt('last week'),
16645: '2592000' => &mt('last month'),
16646: '7776000' => &mt('last three months'),
16647: '15552000' => &mt('last six months'),
16648: '31104000' => &mt('last year'),
16649: 'select_form_order' =>
16650: ['-1','86400','604800','2592000','7776000',
16651: '15552000','31104000']});
16652: }
16653: }
16654:
16655: =pod
16656:
16657: =item * &js_changer()
16658:
16659: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 16660: when course type or domain is changed, and also to hide 'Searching ...' on
16661: page load completion for page showing search result.
1.1181 raeburn 16662:
16663: Inputs: None
16664:
1.1183 raeburn 16665: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 16666:
16667: Side Effects: None
16668:
16669: =cut
16670:
16671: sub js_changer {
16672: return <<ENDJS;
16673: <script type="text/javascript">
16674: // <![CDATA[
16675: function updateFilters(caller) {
16676: if (typeof(caller) != "undefined") {
16677: document.filterpicker.updater.value = caller.name;
16678: }
16679: document.filterpicker.submit();
16680: }
1.1183 raeburn 16681:
16682: function hideSearching() {
16683: if (document.getElementById('searching')) {
16684: document.getElementById('searching').style.display = 'none';
16685: }
16686: return;
16687: }
16688:
1.1181 raeburn 16689: // ]]>
16690: </script>
16691:
16692: ENDJS
16693: }
16694:
16695: =pod
16696:
1.1182 raeburn 16697: =item * &search_courses()
16698:
16699: Process selected filters form course search form and pass to lonnet::courseiddump
16700: to retrieve a hash for which keys are courseIDs which match the selected filters.
16701:
16702: Inputs:
16703:
16704: dom - domain being searched
16705:
16706: type - course type ('Course' or 'Community' or '.' if any).
16707:
16708: filter - anonymous hash of criteria and their values
16709:
16710: numtitles - for institutional codes - number of categories
16711:
16712: cloneruname - optional username of new course owner
16713:
16714: clonerudom - optional domain of new course owner
16715:
1.1221 raeburn 16716: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 16717: (used when DC is using course creation form)
16718:
16719: codetitles - reference to array of titles of components in institutional codes (official courses).
16720:
1.1221 raeburn 16721: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16722: (and so can clone automatically)
16723:
16724: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16725:
16726: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16727: courses to clone
1.1182 raeburn 16728:
16729: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16730:
16731:
16732: Side Effects: None
16733:
16734: =cut
16735:
16736:
16737: sub search_courses {
1.1221 raeburn 16738: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16739: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 16740: my (%courses,%showcourses,$cloner);
16741: if (($filter->{'ownerfilter'} ne '') ||
16742: ($filter->{'ownerdomfilter'} ne '')) {
16743: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16744: $filter->{'ownerdomfilter'};
16745: }
16746: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16747: if (!$filter->{$item}) {
16748: $filter->{$item}='.';
16749: }
16750: }
16751: my $now = time;
16752: my $timefilter =
16753: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16754: my ($createdbefore,$createdafter);
16755: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16756: $createdbefore = $now;
16757: $createdafter = $now-$filter->{'createdfilter'};
16758: }
16759: my ($instcodefilter,$regexpok);
16760: if ($numtitles) {
16761: if ($env{'form.official'} eq 'on') {
16762: $instcodefilter =
16763: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16764: $regexpok = 1;
16765: } elsif ($env{'form.official'} eq 'off') {
16766: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16767: unless ($instcodefilter eq '') {
16768: $regexpok = -1;
16769: }
16770: }
16771: } else {
16772: $instcodefilter = $filter->{'instcodefilter'};
16773: }
16774: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16775: if ($type eq '') { $type = '.'; }
16776:
16777: if (($clonerudom ne '') && ($cloneruname ne '')) {
16778: $cloner = $cloneruname.':'.$clonerudom;
16779: }
16780: %courses = &Apache::lonnet::courseiddump($dom,
16781: $filter->{'descriptfilter'},
16782: $timefilter,
16783: $instcodefilter,
16784: $filter->{'combownerfilter'},
16785: $filter->{'coursefilter'},
16786: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 16787: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 16788: $filter->{'cloneableonly'},
16789: $createdbefore,$createdafter,undef,
1.1221 raeburn 16790: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 16791: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16792: my $ccrole;
16793: if ($type eq 'Community') {
16794: $ccrole = 'co';
16795: } else {
16796: $ccrole = 'cc';
16797: }
16798: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16799: $filter->{'persondomfilter'},
16800: 'userroles',undef,
16801: [$ccrole,'in','ad','ep','ta','cr'],
16802: $dom);
16803: foreach my $role (keys(%rolehash)) {
16804: my ($cnum,$cdom,$courserole) = split(':',$role);
16805: my $cid = $cdom.'_'.$cnum;
16806: if (exists($courses{$cid})) {
16807: if (ref($courses{$cid}) eq 'HASH') {
16808: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16809: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 16810: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 16811: }
16812: } else {
16813: $courses{$cid}{roles} = [$courserole];
16814: }
16815: $showcourses{$cid} = $courses{$cid};
16816: }
16817: }
16818: }
16819: %courses = %showcourses;
16820: }
16821: return %courses;
16822: }
16823:
16824: =pod
16825:
1.1181 raeburn 16826: =back
16827:
1.1207 raeburn 16828: =head1 Routines for version requirements for current course.
16829:
16830: =over 4
16831:
16832: =item * &check_release_required()
16833:
16834: Compares required LON-CAPA version with version on server, and
16835: if required version is newer looks for a server with the required version.
16836:
16837: Looks first at servers in user's owen domain; if none suitable, looks at
16838: servers in course's domain are permitted to host sessions for user's domain.
16839:
16840: Inputs:
16841:
16842: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16843:
16844: $courseid - Course ID of current course
16845:
16846: $rolecode - User's current role in course (for switchserver query string).
16847:
16848: $required - LON-CAPA version needed by course (format: Major.Minor).
16849:
16850:
16851: Returns:
16852:
16853: $switchserver - query string tp append to /adm/switchserver call (if
16854: current server's LON-CAPA version is too old.
16855:
16856: $warning - Message is displayed if no suitable server could be found.
16857:
16858: =cut
16859:
16860: sub check_release_required {
16861: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16862: my ($switchserver,$warning);
16863: if ($required ne '') {
16864: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16865: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16866: if ($reqdmajor ne '' && $reqdminor ne '') {
16867: my $otherserver;
16868: if (($major eq '' && $minor eq '') ||
16869: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16870: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16871: my $switchlcrev =
16872: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16873: $userdomserver);
16874: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16875: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16876: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16877: my $cdom = $env{'course.'.$courseid.'.domain'};
16878: if ($cdom ne $env{'user.domain'}) {
16879: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16880: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16881: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16882: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16883: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16884: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16885: my $canhost =
16886: &Apache::lonnet::can_host_session($env{'user.domain'},
16887: $coursedomserver,
16888: $remoterev,
16889: $udomdefaults{'remotesessions'},
16890: $defdomdefaults{'hostedsessions'});
16891:
16892: if ($canhost) {
16893: $otherserver = $coursedomserver;
16894: } else {
16895: $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.");
16896: }
16897: } else {
16898: $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).");
16899: }
16900: } else {
16901: $otherserver = $userdomserver;
16902: }
16903: }
16904: if ($otherserver ne '') {
16905: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16906: }
16907: }
16908: }
16909: return ($switchserver,$warning);
16910: }
16911:
16912: =pod
16913:
16914: =item * &check_release_result()
16915:
16916: Inputs:
16917:
16918: $switchwarning - Warning message if no suitable server found to host session.
16919:
16920: $switchserver - query string to append to /adm/switchserver containing lonHostID
16921: and current role.
16922:
16923: Returns: HTML to display with information about requirement to switch server.
16924: Either displaying warning with link to Roles/Courses screen or
16925: display link to switchserver.
16926:
1.1181 raeburn 16927: =cut
16928:
1.1207 raeburn 16929: sub check_release_result {
16930: my ($switchwarning,$switchserver) = @_;
16931: my $output = &start_page('Selected course unavailable on this server').
16932: '<p class="LC_warning">';
16933: if ($switchwarning) {
16934: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16935: if (&show_course()) {
16936: $output .= &mt('Display courses');
16937: } else {
16938: $output .= &mt('Display roles');
16939: }
16940: $output .= '</a>';
16941: } elsif ($switchserver) {
16942: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16943: '<br />'.
16944: '<a href="/adm/switchserver?'.$switchserver.'">'.
16945: &mt('Switch Server').
16946: '</a>';
16947: }
16948: $output .= '</p>'.&end_page();
16949: return $output;
16950: }
16951:
16952: =pod
16953:
16954: =item * &needs_coursereinit()
16955:
16956: Determine if course contents stored for user's session needs to be
16957: refreshed, because content has changed since "Big Hash" last tied.
16958:
16959: Check for change is made if time last checked is more than 10 minutes ago
16960: (by default).
16961:
16962: Inputs:
16963:
16964: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16965:
16966: $interval (optional) - Time which may elapse (in s) between last check for content
16967: change in current course. (default: 600 s).
16968:
16969: Returns: an array; first element is:
16970:
16971: =over 4
16972:
16973: 'switch' - if content updates mean user's session
16974: needs to be switched to a server running a newer LON-CAPA version
16975:
16976: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16977: on current server hosting user's session
16978:
16979: '' - if no action required.
16980:
16981: =back
16982:
16983: If first item element is 'switch':
16984:
16985: second item is $switchwarning - Warning message if no suitable server found to host session.
16986:
16987: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16988: and current role.
16989:
16990: otherwise: no other elements returned.
16991:
16992: =back
16993:
16994: =cut
16995:
16996: sub needs_coursereinit {
16997: my ($loncaparev,$interval) = @_;
16998: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16999: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17000: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17001: my $now = time;
17002: if ($interval eq '') {
17003: $interval = 600;
17004: }
17005: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 17006: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1283 raeburn 17007: my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
1.1282 raeburn 17008: if ($blocked) {
17009: return ();
17010: }
1.1207 raeburn 17011: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17012: if ($lastchange > $env{'request.course.tied'}) {
17013: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17014: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17015: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17016: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17017: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17018: $curr_reqd_hash{'internal.releaserequired'}});
17019: my ($switchserver,$switchwarning) =
17020: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17021: $curr_reqd_hash{'internal.releaserequired'});
17022: if ($switchwarning ne '' || $switchserver ne '') {
17023: return ('switch',$switchwarning,$switchserver);
17024: }
17025: }
17026: }
17027: return ('update');
17028: }
17029: }
17030: return ();
17031: }
1.1181 raeburn 17032:
1.1083 raeburn 17033: sub update_content_constraints {
17034: my ($cdom,$cnum,$chome,$cid) = @_;
17035: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17036: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
17037: my %checkresponsetypes;
17038: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17039: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17040: if ($item eq 'resourcetag') {
17041: if ($name eq 'responsetype') {
17042: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17043: }
17044: }
17045: }
17046: my $navmap = Apache::lonnavmaps::navmap->new();
17047: if (defined($navmap)) {
17048: my %allresponses;
17049: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
17050: my %responses = $res->responseTypes();
17051: foreach my $key (keys(%responses)) {
17052: next unless(exists($checkresponsetypes{$key}));
17053: $allresponses{$key} += $responses{$key};
17054: }
17055: }
17056: foreach my $key (keys(%allresponses)) {
17057: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17058: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17059: ($reqdmajor,$reqdminor) = ($major,$minor);
17060: }
17061: }
17062: undef($navmap);
17063: }
17064: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17065: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17066: }
17067: return;
17068: }
17069:
1.1110 raeburn 17070: sub allmaps_incourse {
17071: my ($cdom,$cnum,$chome,$cid) = @_;
17072: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17073: $cid = $env{'request.course.id'};
17074: $cdom = $env{'course.'.$cid.'.domain'};
17075: $cnum = $env{'course.'.$cid.'.num'};
17076: $chome = $env{'course.'.$cid.'.home'};
17077: }
17078: my %allmaps = ();
17079: my $lastchange =
17080: &Apache::lonnet::get_coursechange($cdom,$cnum);
17081: if ($lastchange > $env{'request.course.tied'}) {
17082: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17083: unless ($ferr) {
17084: &update_content_constraints($cdom,$cnum,$chome,$cid);
17085: }
17086: }
17087: my $navmap = Apache::lonnavmaps::navmap->new();
17088: if (defined($navmap)) {
17089: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17090: $allmaps{$res->src()} = 1;
17091: }
17092: }
17093: return \%allmaps;
17094: }
17095:
1.1083 raeburn 17096: sub parse_supplemental_title {
17097: my ($title) = @_;
17098:
17099: my ($foldertitle,$renametitle);
17100: if ($title =~ /&&&/) {
17101: $title = &HTML::Entites::decode($title);
17102: }
17103: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17104: $renametitle=$4;
17105: my ($time,$uname,$udom) = ($1,$2,$3);
17106: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17107: my $name = &plainname($uname,$udom);
17108: $name = &HTML::Entities::encode($name,'"<>&\'');
17109: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17110: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17111: $name.': <br />'.$foldertitle;
17112: }
17113: if (wantarray) {
17114: return ($title,$foldertitle,$renametitle);
17115: }
17116: return $title;
17117: }
17118:
1.1143 raeburn 17119: sub recurse_supplemental {
17120: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
17121: if ($suppmap) {
17122: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17123: if ($fatal) {
17124: $errors ++;
17125: } else {
17126: if ($#LONCAPA::map::resources > 0) {
17127: foreach my $res (@LONCAPA::map::resources) {
17128: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17129: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17130: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
17131: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 17132: } else {
17133: $numfiles ++;
17134: }
17135: }
17136: }
17137: }
17138: }
17139: }
17140: return ($numfiles,$errors);
17141: }
17142:
1.1101 raeburn 17143: sub symb_to_docspath {
1.1267 raeburn 17144: my ($symb,$navmapref) = @_;
17145: return unless ($symb && ref($navmapref));
1.1101 raeburn 17146: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17147: if ($resurl=~/\.(sequence|page)$/) {
17148: $mapurl=$resurl;
17149: } elsif ($resurl eq 'adm/navmaps') {
17150: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17151: }
17152: my $mapresobj;
1.1267 raeburn 17153: unless (ref($$navmapref)) {
17154: $$navmapref = Apache::lonnavmaps::navmap->new();
17155: }
17156: if (ref($$navmapref)) {
17157: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17158: }
17159: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17160: my $type=$2;
17161: my $path;
17162: if (ref($mapresobj)) {
17163: my $pcslist = $mapresobj->map_hierarchy();
17164: if ($pcslist ne '') {
17165: foreach my $pc (split(/,/,$pcslist)) {
17166: next if ($pc <= 1);
1.1267 raeburn 17167: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17168: if (ref($res)) {
17169: my $thisurl = $res->src();
17170: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17171: my $thistitle = $res->title();
17172: $path .= '&'.
17173: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17174: &escape($thistitle).
1.1101 raeburn 17175: ':'.$res->randompick().
17176: ':'.$res->randomout().
17177: ':'.$res->encrypted().
17178: ':'.$res->randomorder().
17179: ':'.$res->is_page();
17180: }
17181: }
17182: }
17183: $path =~ s/^\&//;
17184: my $maptitle = $mapresobj->title();
17185: if ($mapurl eq 'default') {
1.1129 raeburn 17186: $maptitle = 'Main Content';
1.1101 raeburn 17187: }
17188: $path .= (($path ne '')? '&' : '').
17189: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17190: &escape($maptitle).
1.1101 raeburn 17191: ':'.$mapresobj->randompick().
17192: ':'.$mapresobj->randomout().
17193: ':'.$mapresobj->encrypted().
17194: ':'.$mapresobj->randomorder().
17195: ':'.$mapresobj->is_page();
17196: } else {
17197: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17198: my $ispage = (($type eq 'page')? 1 : '');
17199: if ($mapurl eq 'default') {
1.1129 raeburn 17200: $maptitle = 'Main Content';
1.1101 raeburn 17201: }
17202: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17203: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17204: }
17205: unless ($mapurl eq 'default') {
17206: $path = 'default&'.
1.1146 raeburn 17207: &escape('Main Content').
1.1101 raeburn 17208: ':::::&'.$path;
17209: }
17210: return $path;
17211: }
17212:
1.1094 raeburn 17213: sub captcha_display {
17214: my ($context,$lonhost) = @_;
17215: my ($output,$error);
1.1234 raeburn 17216: my ($captcha,$pubkey,$privkey,$version) =
17217: &get_captcha_config($context,$lonhost);
1.1095 raeburn 17218: if ($captcha eq 'original') {
1.1094 raeburn 17219: $output = &create_captcha();
17220: unless ($output) {
1.1172 raeburn 17221: $error = 'captcha';
1.1094 raeburn 17222: }
17223: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17224: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17225: unless ($output) {
1.1172 raeburn 17226: $error = 'recaptcha';
1.1094 raeburn 17227: }
17228: }
1.1234 raeburn 17229: return ($output,$error,$captcha,$version);
1.1094 raeburn 17230: }
17231:
17232: sub captcha_response {
17233: my ($context,$lonhost) = @_;
17234: my ($captcha_chk,$captcha_error);
1.1234 raeburn 17235: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 17236: if ($captcha eq 'original') {
1.1094 raeburn 17237: ($captcha_chk,$captcha_error) = &check_captcha();
17238: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17239: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17240: } else {
17241: $captcha_chk = 1;
17242: }
17243: return ($captcha_chk,$captcha_error);
17244: }
17245:
17246: sub get_captcha_config {
17247: my ($context,$lonhost) = @_;
1.1234 raeburn 17248: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17249: my $hostname = &Apache::lonnet::hostname($lonhost);
17250: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17251: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17252: if ($context eq 'usercreation') {
17253: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17254: if (ref($domconfig{$context}) eq 'HASH') {
17255: $hashtocheck = $domconfig{$context}{'cancreate'};
17256: if (ref($hashtocheck) eq 'HASH') {
17257: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17258: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17259: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17260: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17261: }
17262: if ($privkey && $pubkey) {
17263: $captcha = 'recaptcha';
1.1234 raeburn 17264: $version = $hashtocheck->{'recaptchaversion'};
17265: if ($version ne '2') {
17266: $version = 1;
17267: }
1.1095 raeburn 17268: } else {
17269: $captcha = 'original';
17270: }
17271: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17272: $captcha = 'original';
17273: }
1.1094 raeburn 17274: }
1.1095 raeburn 17275: } else {
17276: $captcha = 'captcha';
17277: }
17278: } elsif ($context eq 'login') {
17279: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17280: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17281: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17282: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17283: if ($privkey && $pubkey) {
17284: $captcha = 'recaptcha';
1.1234 raeburn 17285: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17286: if ($version ne '2') {
17287: $version = 1;
17288: }
1.1095 raeburn 17289: } else {
17290: $captcha = 'original';
1.1094 raeburn 17291: }
1.1095 raeburn 17292: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17293: $captcha = 'original';
1.1094 raeburn 17294: }
17295: }
1.1234 raeburn 17296: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17297: }
17298:
17299: sub create_captcha {
17300: my %captcha_params = &captcha_settings();
17301: my ($output,$maxtries,$tries) = ('',10,0);
17302: while ($tries < $maxtries) {
17303: $tries ++;
17304: my $captcha = Authen::Captcha->new (
17305: output_folder => $captcha_params{'output_dir'},
17306: data_folder => $captcha_params{'db_dir'},
17307: );
17308: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17309:
17310: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17311: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17312: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17313: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17314: '<br />'.
17315: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17316: last;
17317: }
17318: }
17319: return $output;
17320: }
17321:
17322: sub captcha_settings {
17323: my %captcha_params = (
17324: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17325: www_output_dir => "/captchaspool",
17326: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17327: numchars => '5',
17328: );
17329: return %captcha_params;
17330: }
17331:
17332: sub check_captcha {
17333: my ($captcha_chk,$captcha_error);
17334: my $code = $env{'form.code'};
17335: my $md5sum = $env{'form.crypt'};
17336: my %captcha_params = &captcha_settings();
17337: my $captcha = Authen::Captcha->new(
17338: output_folder => $captcha_params{'output_dir'},
17339: data_folder => $captcha_params{'db_dir'},
17340: );
1.1109 raeburn 17341: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17342: my %captcha_hash = (
17343: 0 => 'Code not checked (file error)',
17344: -1 => 'Failed: code expired',
17345: -2 => 'Failed: invalid code (not in database)',
17346: -3 => 'Failed: invalid code (code does not match crypt)',
17347: );
17348: if ($captcha_chk != 1) {
17349: $captcha_error = $captcha_hash{$captcha_chk}
17350: }
17351: return ($captcha_chk,$captcha_error);
17352: }
17353:
17354: sub create_recaptcha {
1.1234 raeburn 17355: my ($pubkey,$version) = @_;
17356: if ($version >= 2) {
17357: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17358: } else {
17359: my $use_ssl;
17360: if ($ENV{'SERVER_PORT'} == 443) {
17361: $use_ssl = 1;
17362: }
17363: my $captcha = Captcha::reCAPTCHA->new;
17364: return $captcha->get_options_setter({theme => 'white'})."\n".
17365: $captcha->get_html($pubkey,undef,$use_ssl).
17366: &mt('If the text is hard to read, [_1] will replace them.',
17367: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17368: '<br /><br />';
17369: }
1.1094 raeburn 17370: }
17371:
17372: sub check_recaptcha {
1.1234 raeburn 17373: my ($privkey,$version) = @_;
1.1094 raeburn 17374: my $captcha_chk;
1.1234 raeburn 17375: if ($version >= 2) {
17376: my %info = (
17377: secret => $privkey,
17378: response => $env{'form.g-recaptcha-response'},
17379: remoteip => $ENV{'REMOTE_ADDR'},
17380: );
1.1280 raeburn 17381: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
17382: $request->content(join('&',map {
17383: my $name = escape($_);
17384: "$name=" . ( ref($info{$_}) eq 'ARRAY'
17385: ? join("&$name=", map {escape($_) } @{$info{$_}})
17386: : &escape($info{$_}) );
17387: } keys(%info)));
17388: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 17389: if ($response->is_success) {
17390: my $data = JSON::DWIW->from_json($response->decoded_content);
17391: if (ref($data) eq 'HASH') {
17392: if ($data->{'success'}) {
17393: $captcha_chk = 1;
17394: }
17395: }
17396: }
17397: } else {
17398: my $captcha = Captcha::reCAPTCHA->new;
17399: my $captcha_result =
17400: $captcha->check_answer(
17401: $privkey,
17402: $ENV{'REMOTE_ADDR'},
17403: $env{'form.recaptcha_challenge_field'},
17404: $env{'form.recaptcha_response_field'},
17405: );
17406: if ($captcha_result->{is_valid}) {
17407: $captcha_chk = 1;
17408: }
1.1094 raeburn 17409: }
17410: return $captcha_chk;
17411: }
17412:
1.1174 raeburn 17413: sub emailusername_info {
1.1244 raeburn 17414: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 17415: my %titles = &Apache::lonlocal::texthash (
17416: lastname => 'Last Name',
17417: firstname => 'First Name',
17418: institution => 'School/college/university',
17419: location => "School's city, state/province, country",
17420: web => "School's web address",
17421: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 17422: id => 'Student/Employee ID',
1.1174 raeburn 17423: );
17424: return (\@fields,\%titles);
17425: }
17426:
1.1161 raeburn 17427: sub cleanup_html {
17428: my ($incoming) = @_;
17429: my $outgoing;
17430: if ($incoming ne '') {
17431: $outgoing = $incoming;
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: $outgoing =~ s/'/'/g;
17441: $outgoing =~ s/\$/$/g;
17442: $outgoing =~ s{/}{/}g;
17443: $outgoing =~ s/=/=/g;
17444: $outgoing =~ s/\\/\/g
17445: }
17446: return $outgoing;
17447: }
17448:
1.1190 musolffc 17449: # Checks for critical messages and returns a redirect url if one exists.
17450: # $interval indicates how often to check for messages.
1.1282 raeburn 17451: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 17452: sub critical_redirect {
1.1282 raeburn 17453: my ($interval,$context) = @_;
1.1190 musolffc 17454: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 17455: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
17456: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17457: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17458: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
17459: if ($blocked) {
17460: my $checkrole = "cm./$cdom/$cnum";
17461: if ($env{'request.course.sec'} ne '') {
17462: $checkrole .= "/$env{'request.course.sec'}";
17463: }
17464: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
17465: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
17466: return;
17467: }
17468: }
17469: }
1.1190 musolffc 17470: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17471: $env{'user.name'});
17472: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 17473: my $redirecturl;
1.1190 musolffc 17474: if ($what[0]) {
17475: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17476: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 17477: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17478: return (1, $url);
1.1190 musolffc 17479: }
1.1191 raeburn 17480: }
17481: }
17482: return ();
1.1190 musolffc 17483: }
17484:
1.1174 raeburn 17485: # Use:
17486: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17487: #
17488: ##################################################
17489: # password associated functions #
17490: ##################################################
17491: sub des_keys {
17492: # Make a new key for DES encryption.
17493: # Each key has two parts which are returned separately.
17494: # Please note: Each key must be passed through the &hex function
17495: # before it is output to the web browser. The hex versions cannot
17496: # be used to decrypt.
17497: my @hexstr=('0','1','2','3','4','5','6','7',
17498: '8','9','a','b','c','d','e','f');
17499: my $lkey='';
17500: for (0..7) {
17501: $lkey.=$hexstr[rand(15)];
17502: }
17503: my $ukey='';
17504: for (0..7) {
17505: $ukey.=$hexstr[rand(15)];
17506: }
17507: return ($lkey,$ukey);
17508: }
17509:
17510: sub des_decrypt {
17511: my ($key,$cyphertext) = @_;
17512: my $keybin=pack("H16",$key);
17513: my $cypher;
17514: if ($Crypt::DES::VERSION>=2.03) {
17515: $cypher=new Crypt::DES $keybin;
17516: } else {
17517: $cypher=new DES $keybin;
17518: }
1.1233 raeburn 17519: my $plaintext='';
17520: my $cypherlength = length($cyphertext);
17521: my $numchunks = int($cypherlength/32);
17522: for (my $j=0; $j<$numchunks; $j++) {
17523: my $start = $j*32;
17524: my $cypherblock = substr($cyphertext,$start,32);
17525: my $chunk =
17526: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17527: $chunk .=
17528: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17529: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17530: $plaintext .= $chunk;
17531: }
1.1174 raeburn 17532: return $plaintext;
17533: }
17534:
1.112 bowersj2 17535: 1;
17536: __END__;
1.41 ng 17537:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>