Annotation of loncom/interface/loncommon.pm, revision 1.1258
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1258 ! raeburn 4: # $Id: loncommon.pm,v 1.1257 2016/10/12 14:54:08 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.657 raeburn 74: use DateTime::TimeZone;
1.1241 raeburn 75: use DateTime::Locale;
1.1220 raeburn 76: use Encode();
1.1091 foxr 77: use Text::Aspell;
1.1094 raeburn 78: use Authen::Captcha;
79: use Captcha::reCAPTCHA;
1.1234 raeburn 80: use JSON::DWIW;
81: use LWP::UserAgent;
1.1174 raeburn 82: use Crypt::DES;
83: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 84: use MIME::Lite;
85: use MIME::Types;
1.117 www 86:
1.517 raeburn 87: # ---------------------------------------------- Designs
88: use vars qw(%defaultdesign);
89:
1.22 www 90: my $readit;
91:
1.517 raeburn 92:
1.157 matthew 93: ##
94: ## Global Variables
95: ##
1.46 matthew 96:
1.643 foxr 97:
98: # ----------------------------------------------- SSI with retries:
99: #
100:
101: =pod
102:
1.648 raeburn 103: =head1 Server Side include with retries:
1.643 foxr 104:
105: =over 4
106:
1.648 raeburn 107: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 108:
109: Performs an ssi with some number of retries. Retries continue either
110: until the result is ok or until the retry count supplied by the
111: caller is exhausted.
112:
113: Inputs:
1.648 raeburn 114:
115: =over 4
116:
1.643 foxr 117: resource - Identifies the resource to insert.
1.648 raeburn 118:
1.643 foxr 119: retries - Count of the number of retries allowed.
1.648 raeburn 120:
1.643 foxr 121: form - Hash that identifies the rendering options.
122:
1.648 raeburn 123: =back
124:
125: Returns:
126:
127: =over 4
128:
1.643 foxr 129: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 130:
1.643 foxr 131: response - The response from the last attempt (which may or may not have been successful.
132:
1.648 raeburn 133: =back
134:
135: =back
136:
1.643 foxr 137: =cut
138:
139: sub ssi_with_retries {
140: my ($resource, $retries, %form) = @_;
141:
142:
143: my $ok = 0; # True if we got a good response.
144: my $content;
145: my $response;
146:
147: # Try to get the ssi done. within the retries count:
148:
149: do {
150: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
151: $ok = $response->is_success;
1.650 www 152: if (!$ok) {
153: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
154: }
1.643 foxr 155: $retries--;
156: } while (!$ok && ($retries > 0));
157:
158: if (!$ok) {
159: $content = ''; # On error return an empty content.
160: }
161: return ($content, $response);
162:
163: }
164:
165:
166:
1.20 www 167: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 168: my %language;
1.124 www 169: my %supported_language;
1.1088 foxr 170: my %supported_codes;
1.1048 foxr 171: my %latex_language; # For choosing hyphenation in <transl..>
172: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 173: my %cprtag;
1.192 taceyjo1 174: my %scprtag;
1.351 www 175: my %fe; my %fd; my %fm;
1.41 ng 176: my %category_extensions;
1.12 harris41 177:
1.46 matthew 178: # ---------------------------------------------- Thesaurus variables
1.144 matthew 179: #
180: # %Keywords:
181: # A hash used by &keyword to determine if a word is considered a keyword.
182: # $thesaurus_db_file
183: # Scalar containing the full path to the thesaurus database.
1.46 matthew 184:
185: my %Keywords;
186: my $thesaurus_db_file;
187:
1.144 matthew 188: #
189: # Initialize values from language.tab, copyright.tab, filetypes.tab,
190: # thesaurus.tab, and filecategories.tab.
191: #
1.18 www 192: BEGIN {
1.46 matthew 193: # Variable initialization
194: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
195: #
1.22 www 196: unless ($readit) {
1.12 harris41 197: # ------------------------------------------------------------------- languages
198: {
1.158 raeburn 199: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
200: '/language.tab';
201: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 202: while (my $line = <$fh>) {
203: next if ($line=~/^\#/);
204: chomp($line);
1.1088 foxr 205: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 206: $language{$key}=$val.' - '.$enc;
207: if ($sup) {
208: $supported_language{$key}=$sup;
1.1088 foxr 209: $supported_codes{$key} = $code;
1.158 raeburn 210: }
1.1048 foxr 211: if ($latex) {
212: $latex_language_bykey{$key} = $latex;
1.1088 foxr 213: $latex_language{$code} = $latex;
1.1048 foxr 214: }
1.158 raeburn 215: }
216: close($fh);
217: }
1.12 harris41 218: }
219: # ------------------------------------------------------------------ copyrights
220: {
1.158 raeburn 221: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
222: '/copyright.tab';
223: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 224: while (my $line = <$fh>) {
225: next if ($line=~/^\#/);
226: chomp($line);
227: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 228: $cprtag{$key}=$val;
229: }
230: close($fh);
231: }
1.12 harris41 232: }
1.351 www 233: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 234: {
235: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
236: '/source_copyright.tab';
237: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 238: while (my $line = <$fh>) {
239: next if ($line =~ /^\#/);
240: chomp($line);
241: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 242: $scprtag{$key}=$val;
243: }
244: close($fh);
245: }
246: }
1.63 www 247:
1.517 raeburn 248: # -------------------------------------------------------------- default domain designs
1.63 www 249: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 250: my $designfile = $designdir.'/default.tab';
251: if ( open (my $fh,"<$designfile") ) {
252: while (my $line = <$fh>) {
253: next if ($line =~ /^\#/);
254: chomp($line);
255: my ($key,$val)=(split(/\=/,$line));
256: if ($val) { $defaultdesign{$key}=$val; }
257: }
258: close($fh);
1.63 www 259: }
260:
1.15 harris41 261: # ------------------------------------------------------------- file categories
262: {
1.158 raeburn 263: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
264: '/filecategories.tab';
265: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 266: while (my $line = <$fh>) {
267: next if ($line =~ /^\#/);
268: chomp($line);
269: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 270: push @{$category_extensions{lc($category)}},$extension;
271: }
272: close($fh);
273: }
274:
1.15 harris41 275: }
1.12 harris41 276: # ------------------------------------------------------------------ file types
277: {
1.158 raeburn 278: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
279: '/filetypes.tab';
280: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 281: while (my $line = <$fh>) {
282: next if ($line =~ /^\#/);
283: chomp($line);
284: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 285: if ($descr ne '') {
286: $fe{$ending}=lc($emb);
287: $fd{$ending}=$descr;
1.351 www 288: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 289: }
290: }
291: close($fh);
292: }
1.12 harris41 293: }
1.22 www 294: &Apache::lonnet::logthis(
1.705 tempelho 295: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 296: $readit=1;
1.46 matthew 297: } # end of unless($readit)
1.32 matthew 298:
299: }
1.112 bowersj2 300:
1.42 matthew 301: ###############################################################
302: ## HTML and Javascript Helper Functions ##
303: ###############################################################
304:
305: =pod
306:
1.112 bowersj2 307: =head1 HTML and Javascript Functions
1.42 matthew 308:
1.112 bowersj2 309: =over 4
310:
1.648 raeburn 311: =item * &browser_and_searcher_javascript()
1.112 bowersj2 312:
313: X<browsing, javascript>X<searching, javascript>Returns a string
314: containing javascript with two functions, C<openbrowser> and
315: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
316: tags.
1.42 matthew 317:
1.648 raeburn 318: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 319:
320: inputs: formname, elementname, only, omit
321:
322: formname and elementname indicate the name of the html form and name of
323: the element that the results of the browsing selection are to be placed in.
324:
325: Specifying 'only' will restrict the browser to displaying only files
1.185 www 326: with the given extension. Can be a comma separated list.
1.42 matthew 327:
328: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 329: with the given extension. Can be a comma separated list.
1.42 matthew 330:
1.648 raeburn 331: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 332:
333: Inputs: formname, elementname
334:
335: formname and elementname specify the name of the html form and the name
336: of the element the selection from the search results will be placed in.
1.542 raeburn 337:
1.42 matthew 338: =cut
339:
340: sub browser_and_searcher_javascript {
1.199 albertel 341: my ($mode)=@_;
342: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 343: my $resurl=&escape_single(&lastresurl());
1.42 matthew 344: return <<END;
1.219 albertel 345: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 346: var editbrowser = null;
1.135 albertel 347: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 348: var url = '$resurl/?';
1.42 matthew 349: if (editbrowser == null) {
350: url += 'launch=1&';
351: }
352: url += 'catalogmode=interactive&';
1.199 albertel 353: url += 'mode=$mode&';
1.611 albertel 354: url += 'inhibitmenu=yes&';
1.42 matthew 355: url += 'form=' + formname + '&';
356: if (only != null) {
357: url += 'only=' + only + '&';
1.217 albertel 358: } else {
359: url += 'only=&';
360: }
1.42 matthew 361: if (omit != null) {
362: url += 'omit=' + omit + '&';
1.217 albertel 363: } else {
364: url += 'omit=&';
365: }
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Browser';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editbrowser = open(url,title,options,'1');
376: editbrowser.focus();
377: }
378: var editsearcher;
1.135 albertel 379: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 380: var url = '/adm/searchcat?';
381: if (editsearcher == null) {
382: url += 'launch=1&';
383: }
384: url += 'catalogmode=interactive&';
1.199 albertel 385: url += 'mode=$mode&';
1.42 matthew 386: url += 'form=' + formname + '&';
1.135 albertel 387: if (titleelement != null) {
388: url += 'titleelement=' + titleelement + '&';
1.217 albertel 389: } else {
390: url += 'titleelement=&';
391: }
1.42 matthew 392: url += 'element=' + elementname + '';
393: var title = 'Search';
1.435 albertel 394: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 395: options += ',width=700,height=600';
396: editsearcher = open(url,title,options,'1');
397: editsearcher.focus();
398: }
1.219 albertel 399: // END LON-CAPA Internal -->
1.42 matthew 400: END
1.170 www 401: }
402:
403: sub lastresurl {
1.258 albertel 404: if ($env{'environment.lastresurl'}) {
405: return $env{'environment.lastresurl'}
1.170 www 406: } else {
407: return '/res';
408: }
409: }
410:
411: sub storeresurl {
412: my $resurl=&Apache::lonnet::clutter(shift);
413: unless ($resurl=~/^\/res/) { return 0; }
414: $resurl=~s/\/$//;
415: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 416: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 417: return 1;
1.42 matthew 418: }
419:
1.74 www 420: sub studentbrowser_javascript {
1.111 www 421: unless (
1.258 albertel 422: (($env{'request.course.id'}) &&
1.302 albertel 423: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
424: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
425: '/'.$env{'request.course.sec'})
426: ))
1.258 albertel 427: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 428: ) { return ''; }
1.74 www 429: return (<<'ENDSTDBRW');
1.776 bisitz 430: <script type="text/javascript" language="Javascript">
1.824 bisitz 431: // <![CDATA[
1.74 www 432: var stdeditbrowser;
1.999 www 433: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 434: var url = '/adm/pickstudent?';
435: var filter;
1.558 albertel 436: if (!ignorefilter) {
437: eval('filter=document.'+formname+'.'+uname+'.value;');
438: }
1.74 www 439: if (filter != null) {
440: if (filter != '') {
441: url += 'filter='+filter+'&';
442: }
443: }
444: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 445: '&udomelement='+udom+
446: '&clicker='+clicker;
1.111 www 447: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 448: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 449: var title = 'Student_Browser';
1.74 www 450: var options = 'scrollbars=1,resizable=1,menubar=0';
451: options += ',width=700,height=600';
452: stdeditbrowser = open(url,title,options,'1');
453: stdeditbrowser.focus();
454: }
1.824 bisitz 455: // ]]>
1.74 www 456: </script>
457: ENDSTDBRW
458: }
1.42 matthew 459:
1.1003 www 460: sub resourcebrowser_javascript {
461: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 462: return (<<'ENDRESBRW');
1.1003 www 463: <script type="text/javascript" language="Javascript">
464: // <![CDATA[
465: var reseditbrowser;
1.1004 www 466: function openresbrowser(formname,reslink) {
1.1005 www 467: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 468: var title = 'Resource_Browser';
469: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 470: options += ',width=700,height=500';
1.1004 www 471: reseditbrowser = open(url,title,options,'1');
472: reseditbrowser.focus();
1.1003 www 473: }
474: // ]]>
475: </script>
1.1004 www 476: ENDRESBRW
1.1003 www 477: }
478:
1.74 www 479: sub selectstudent_link {
1.999 www 480: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
481: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
482: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
483: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 484: if ($env{'request.course.id'}) {
1.302 albertel 485: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
486: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
487: '/'.$env{'request.course.sec'})) {
1.111 www 488: return '';
489: }
1.999 www 490: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 491: if ($courseadvonly) {
492: $callargs .= ",'',1,1";
493: }
494: return '<span class="LC_nobreak">'.
495: '<a href="javascript:openstdbrowser('.$callargs.');">'.
496: &mt('Select User').'</a></span>';
1.74 www 497: }
1.258 albertel 498: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 499: $callargs .= ",'',1";
1.793 raeburn 500: return '<span class="LC_nobreak">'.
501: '<a href="javascript:openstdbrowser('.$callargs.');">'.
502: &mt('Select User').'</a></span>';
1.111 www 503: }
504: return '';
1.91 www 505: }
506:
1.1004 www 507: sub selectresource_link {
508: my ($form,$reslink,$arg)=@_;
509:
510: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
511: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
512: unless ($env{'request.course.id'}) { return $arg; }
513: return '<span class="LC_nobreak">'.
514: '<a href="javascript:openresbrowser('.$callargs.');">'.
515: $arg.'</a></span>';
516: }
517:
518:
519:
1.653 raeburn 520: sub authorbrowser_javascript {
521: return <<"ENDAUTHORBRW";
1.776 bisitz 522: <script type="text/javascript" language="JavaScript">
1.824 bisitz 523: // <![CDATA[
1.653 raeburn 524: var stdeditbrowser;
525:
526: function openauthorbrowser(formname,udom) {
527: var url = '/adm/pickauthor?';
528: url += 'form='+formname+'&roledom='+udom;
529: var title = 'Author_Browser';
530: var options = 'scrollbars=1,resizable=1,menubar=0';
531: options += ',width=700,height=600';
532: stdeditbrowser = open(url,title,options,'1');
533: stdeditbrowser.focus();
534: }
535:
1.824 bisitz 536: // ]]>
1.653 raeburn 537: </script>
538: ENDAUTHORBRW
539: }
540:
1.91 www 541: sub coursebrowser_javascript {
1.1116 raeburn 542: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 543: $credits_element,$instcode) = @_;
1.932 raeburn 544: my $wintitle = 'Course_Browser';
1.931 raeburn 545: if ($crstype eq 'Community') {
1.932 raeburn 546: $wintitle = 'Community_Browser';
1.909 raeburn 547: }
1.876 raeburn 548: my $id_functions = &javascript_index_functions();
549: my $output = '
1.776 bisitz 550: <script type="text/javascript" language="JavaScript">
1.824 bisitz 551: // <![CDATA[
1.468 raeburn 552: var stdeditbrowser;'."\n";
1.876 raeburn 553:
554: $output .= <<"ENDSTDBRW";
1.909 raeburn 555: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 556: var url = '/adm/pickcourse?';
1.895 raeburn 557: var formid = getFormIdByName(formname);
1.876 raeburn 558: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 559: if (domainfilter != null) {
560: if (domainfilter != '') {
561: url += 'domainfilter='+domainfilter+'&';
562: }
563: }
1.91 www 564: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 565: '&cdomelement='+udom+
566: '&cnameelement='+desc;
1.468 raeburn 567: if (extra_element !=null && extra_element != '') {
1.594 raeburn 568: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 569: url += '&roleelement='+extra_element;
570: if (domainfilter == null || domainfilter == '') {
571: url += '&domainfilter='+extra_element;
572: }
1.234 raeburn 573: }
1.468 raeburn 574: else {
575: if (formname == 'portform') {
576: url += '&setroles='+extra_element;
1.800 raeburn 577: } else {
578: if (formname == 'rules') {
579: url += '&fixeddom='+extra_element;
580: }
1.468 raeburn 581: }
582: }
1.230 raeburn 583: }
1.909 raeburn 584: if (type != null && type != '') {
585: url += '&type='+type;
586: }
587: if (type_elem != null && type_elem != '') {
588: url += '&typeelement='+type_elem;
589: }
1.872 raeburn 590: if (formname == 'ccrs') {
591: var ownername = document.forms[formid].ccuname.value;
592: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 593: url += '&cloner='+ownername+':'+ownerdom;
594: if (type == 'Course') {
595: url += '&crscode='+document.forms[formid].crscode.value;
596: }
1.1221 raeburn 597: }
598: if (formname == 'requestcrs') {
599: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 600: }
1.293 raeburn 601: if (multflag !=null && multflag != '') {
602: url += '&multiple='+multflag;
603: }
1.909 raeburn 604: var title = '$wintitle';
1.91 www 605: var options = 'scrollbars=1,resizable=1,menubar=0';
606: options += ',width=700,height=600';
607: stdeditbrowser = open(url,title,options,'1');
608: stdeditbrowser.focus();
609: }
1.876 raeburn 610: $id_functions
611: ENDSTDBRW
1.1116 raeburn 612: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
613: $output .= &setsec_javascript($sec_element,$formname,$role_element,
614: $credits_element);
1.876 raeburn 615: }
616: $output .= '
617: // ]]>
618: </script>';
619: return $output;
620: }
621:
622: sub javascript_index_functions {
623: return <<"ENDJS";
624:
625: function getFormIdByName(formname) {
626: for (var i=0;i<document.forms.length;i++) {
627: if (document.forms[i].name == formname) {
628: return i;
629: }
630: }
631: return -1;
632: }
633:
634: function getIndexByName(formid,item) {
635: for (var i=0;i<document.forms[formid].elements.length;i++) {
636: if (document.forms[formid].elements[i].name == item) {
637: return i;
638: }
639: }
640: return -1;
641: }
1.468 raeburn 642:
1.876 raeburn 643: function getDomainFromSelectbox(formname,udom) {
644: var userdom;
645: var formid = getFormIdByName(formname);
646: if (formid > -1) {
647: var domid = getIndexByName(formid,udom);
648: if (domid > -1) {
649: if (document.forms[formid].elements[domid].type == 'select-one') {
650: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
651: }
652: if (document.forms[formid].elements[domid].type == 'hidden') {
653: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 654: }
655: }
656: }
1.876 raeburn 657: return userdom;
658: }
659:
660: ENDJS
1.468 raeburn 661:
1.876 raeburn 662: }
663:
1.1017 raeburn 664: sub javascript_array_indexof {
1.1018 raeburn 665: return <<ENDJS;
1.1017 raeburn 666: <script type="text/javascript" language="JavaScript">
667: // <![CDATA[
668:
669: if (!Array.prototype.indexOf) {
670: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
671: "use strict";
672: if (this === void 0 || this === null) {
673: throw new TypeError();
674: }
675: var t = Object(this);
676: var len = t.length >>> 0;
677: if (len === 0) {
678: return -1;
679: }
680: var n = 0;
681: if (arguments.length > 0) {
682: n = Number(arguments[1]);
1.1088 foxr 683: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 684: n = 0;
685: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
686: n = (n > 0 || -1) * Math.floor(Math.abs(n));
687: }
688: }
689: if (n >= len) {
690: return -1;
691: }
692: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
693: for (; k < len; k++) {
694: if (k in t && t[k] === searchElement) {
695: return k;
696: }
697: }
698: return -1;
699: }
700: }
701:
702: // ]]>
703: </script>
704:
705: ENDJS
706:
707: }
708:
1.876 raeburn 709: sub userbrowser_javascript {
710: my $id_functions = &javascript_index_functions();
711: return <<"ENDUSERBRW";
712:
1.888 raeburn 713: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 714: var url = '/adm/pickuser?';
715: var userdom = getDomainFromSelectbox(formname,udom);
716: if (userdom != null) {
717: if (userdom != '') {
718: url += 'srchdom='+userdom+'&';
719: }
720: }
721: url += 'form=' + formname + '&unameelement='+uname+
722: '&udomelement='+udom+
723: '&ulastelement='+ulast+
724: '&ufirstelement='+ufirst+
725: '&uemailelement='+uemail+
1.881 raeburn 726: '&hideudomelement='+hideudom+
727: '&coursedom='+crsdom;
1.888 raeburn 728: if ((caller != null) && (caller != undefined)) {
729: url += '&caller='+caller;
730: }
1.876 raeburn 731: var title = 'User_Browser';
732: var options = 'scrollbars=1,resizable=1,menubar=0';
733: options += ',width=700,height=600';
734: var stdeditbrowser = open(url,title,options,'1');
735: stdeditbrowser.focus();
736: }
737:
1.888 raeburn 738: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 739: var formid = getFormIdByName(formname);
740: if (formid > -1) {
1.888 raeburn 741: var unameid = getIndexByName(formid,uname);
1.876 raeburn 742: var domid = getIndexByName(formid,udom);
743: var hidedomid = getIndexByName(formid,origdom);
744: if (hidedomid > -1) {
745: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 746: var unameval = document.forms[formid].elements[unameid].value;
747: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
748: if (domid > -1) {
749: var slct = document.forms[formid].elements[domid];
750: if (slct.type == 'select-one') {
751: var i;
752: for (i=0;i<slct.length;i++) {
753: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
754: }
755: }
756: if (slct.type == 'hidden') {
757: slct.value = fixeddom;
1.876 raeburn 758: }
759: }
1.468 raeburn 760: }
761: }
762: }
1.876 raeburn 763: return;
764: }
765:
766: $id_functions
767: ENDUSERBRW
1.468 raeburn 768: }
769:
770: sub setsec_javascript {
1.1116 raeburn 771: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 772: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
773: $communityrolestr);
774: if ($role_element ne '') {
775: my @allroles = ('st','ta','ep','in','ad');
776: foreach my $crstype ('Course','Community') {
777: if ($crstype eq 'Community') {
778: foreach my $role (@allroles) {
779: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
780: }
781: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
782: } else {
783: foreach my $role (@allroles) {
784: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
785: }
786: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
787: }
788: }
789: $rolestr = '"'.join('","',@allroles).'"';
790: $courserolestr = '"'.join('","',@courserolenames).'"';
791: $communityrolestr = '"'.join('","',@communityrolenames).'"';
792: }
1.468 raeburn 793: my $setsections = qq|
794: function setSect(sectionlist) {
1.629 raeburn 795: var sectionsArray = new Array();
796: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
797: sectionsArray = sectionlist.split(",");
798: }
1.468 raeburn 799: var numSections = sectionsArray.length;
800: document.$formname.$sec_element.length = 0;
801: if (numSections == 0) {
802: document.$formname.$sec_element.multiple=false;
803: document.$formname.$sec_element.size=1;
804: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
805: } else {
806: if (numSections == 1) {
807: document.$formname.$sec_element.multiple=false;
808: document.$formname.$sec_element.size=1;
809: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
810: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
811: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
812: } else {
813: for (var i=0; i<numSections; i++) {
814: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
815: }
816: document.$formname.$sec_element.multiple=true
817: if (numSections < 3) {
818: document.$formname.$sec_element.size=numSections;
819: } else {
820: document.$formname.$sec_element.size=3;
821: }
822: document.$formname.$sec_element.options[0].selected = false
823: }
824: }
1.91 www 825: }
1.905 raeburn 826:
827: function setRole(crstype) {
1.468 raeburn 828: |;
1.905 raeburn 829: if ($role_element eq '') {
830: $setsections .= ' return;
831: }
832: ';
833: } else {
834: $setsections .= qq|
835: var elementLength = document.$formname.$role_element.length;
836: var allroles = Array($rolestr);
837: var courserolenames = Array($courserolestr);
838: var communityrolenames = Array($communityrolestr);
839: if (elementLength != undefined) {
840: if (document.$formname.$role_element.options[5].value == 'cc') {
841: if (crstype == 'Course') {
842: return;
843: } else {
844: allroles[5] = 'co';
845: for (var i=0; i<6; i++) {
846: document.$formname.$role_element.options[i].value = allroles[i];
847: document.$formname.$role_element.options[i].text = communityrolenames[i];
848: }
849: }
850: } else {
851: if (crstype == 'Community') {
852: return;
853: } else {
854: allroles[5] = 'cc';
855: for (var i=0; i<6; i++) {
856: document.$formname.$role_element.options[i].value = allroles[i];
857: document.$formname.$role_element.options[i].text = courserolenames[i];
858: }
859: }
860: }
861: }
862: return;
863: }
864: |;
865: }
1.1116 raeburn 866: if ($credits_element) {
867: $setsections .= qq|
868: function setCredits(defaultcredits) {
869: document.$formname.$credits_element.value = defaultcredits;
870: return;
871: }
872: |;
873: }
1.468 raeburn 874: return $setsections;
875: }
876:
1.91 www 877: sub selectcourse_link {
1.909 raeburn 878: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
879: $typeelement) = @_;
880: my $type = $selecttype;
1.871 raeburn 881: my $linktext = &mt('Select Course');
882: if ($selecttype eq 'Community') {
1.909 raeburn 883: $linktext = &mt('Select Community');
1.1239 raeburn 884: } elsif ($selecttype eq 'Placement') {
885: $linktext = &mt('Select Placement Test');
1.906 raeburn 886: } elsif ($selecttype eq 'Course/Community') {
887: $linktext = &mt('Select Course/Community');
1.909 raeburn 888: $type = '';
1.1019 raeburn 889: } elsif ($selecttype eq 'Select') {
890: $linktext = &mt('Select');
891: $type = '';
1.871 raeburn 892: }
1.787 bisitz 893: return '<span class="LC_nobreak">'
894: ."<a href='"
895: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
896: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 897: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 898: ."'>".$linktext.'</a>'
1.787 bisitz 899: .'</span>';
1.74 www 900: }
1.42 matthew 901:
1.653 raeburn 902: sub selectauthor_link {
903: my ($form,$udom)=@_;
904: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
905: &mt('Select Author').'</a>';
906: }
907:
1.876 raeburn 908: sub selectuser_link {
1.881 raeburn 909: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 910: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 911: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 912: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 913: ');">'.$linktext.'</a>';
1.876 raeburn 914: }
915:
1.273 raeburn 916: sub check_uncheck_jscript {
917: my $jscript = <<"ENDSCRT";
918: function checkAll(field) {
919: if (field.length > 0) {
920: for (i = 0; i < field.length; i++) {
1.1093 raeburn 921: if (!field[i].disabled) {
922: field[i].checked = true;
923: }
1.273 raeburn 924: }
925: } else {
1.1093 raeburn 926: if (!field.disabled) {
927: field.checked = true;
928: }
1.273 raeburn 929: }
930: }
931:
932: function uncheckAll(field) {
933: if (field.length > 0) {
934: for (i = 0; i < field.length; i++) {
935: field[i].checked = false ;
1.543 albertel 936: }
937: } else {
1.273 raeburn 938: field.checked = false ;
939: }
940: }
941: ENDSCRT
942: return $jscript;
943: }
944:
1.656 www 945: sub select_timezone {
1.1256 raeburn 946: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
947: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 948: if ($includeempty) {
949: $output .= '<option value=""';
950: if (($selected eq '') || ($selected eq 'local')) {
951: $output .= ' selected="selected" ';
952: }
953: $output .= '> </option>';
954: }
1.657 raeburn 955: my @timezones = DateTime::TimeZone->all_names;
956: foreach my $tzone (@timezones) {
957: $output.= '<option value="'.$tzone.'"';
958: if ($tzone eq $selected) {
959: $output.=' selected="selected"';
960: }
961: $output.=">$tzone</option>\n";
1.656 www 962: }
963: $output.="</select>";
964: return $output;
965: }
1.273 raeburn 966:
1.687 raeburn 967: sub select_datelocale {
1.1256 raeburn 968: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
969: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 970: if ($includeempty) {
971: $output .= '<option value=""';
972: if ($selected eq '') {
973: $output .= ' selected="selected" ';
974: }
975: $output .= '> </option>';
976: }
1.1241 raeburn 977: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 978: my (@possibles,%locale_names);
1.1241 raeburn 979: my @locales = DateTime::Locale->ids();
980: foreach my $id (@locales) {
981: if ($id ne '') {
982: my ($en_terr,$native_terr);
983: my $loc = DateTime::Locale->load($id);
984: if (ref($loc)) {
985: $en_terr = $loc->name();
986: $native_terr = $loc->native_name();
1.687 raeburn 987: if (grep(/^en$/,@languages) || !@languages) {
988: if ($en_terr ne '') {
989: $locale_names{$id} = '('.$en_terr.')';
990: } elsif ($native_terr ne '') {
991: $locale_names{$id} = $native_terr;
992: }
993: } else {
994: if ($native_terr ne '') {
995: $locale_names{$id} = $native_terr.' ';
996: } elsif ($en_terr ne '') {
997: $locale_names{$id} = '('.$en_terr.')';
998: }
999: }
1.1220 raeburn 1000: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1001: push(@possibles,$id);
1002: }
1.687 raeburn 1003: }
1004: }
1005: foreach my $item (sort(@possibles)) {
1006: $output.= '<option value="'.$item.'"';
1007: if ($item eq $selected) {
1008: $output.=' selected="selected"';
1009: }
1010: $output.=">$item";
1011: if ($locale_names{$item} ne '') {
1.1220 raeburn 1012: $output.=' '.$locale_names{$item};
1.687 raeburn 1013: }
1014: $output.="</option>\n";
1015: }
1016: $output.="</select>";
1017: return $output;
1018: }
1019:
1.792 raeburn 1020: sub select_language {
1.1256 raeburn 1021: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1022: my %langchoices;
1023: if ($includeempty) {
1.1117 raeburn 1024: %langchoices = ('' => 'No language preference');
1.792 raeburn 1025: }
1026: foreach my $id (&languageids()) {
1027: my $code = &supportedlanguagecode($id);
1028: if ($code) {
1029: $langchoices{$code} = &plainlanguagedescription($id);
1030: }
1031: }
1.1117 raeburn 1032: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1033: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1034: }
1035:
1.42 matthew 1036: =pod
1.36 matthew 1037:
1.1088 foxr 1038:
1039: =item * &list_languages()
1040:
1041: Returns an array reference that is suitable for use in language prompters.
1042: Each array element is itself a two element array. The first element
1043: is the language code. The second element a descsriptiuon of the
1044: language itself. This is suitable for use in e.g.
1045: &Apache::edit::select_arg (once dereferenced that is).
1046:
1047: =cut
1048:
1049: sub list_languages {
1050: my @lang_choices;
1051:
1052: foreach my $id (&languageids()) {
1053: my $code = &supportedlanguagecode($id);
1054: if ($code) {
1055: my $selector = $supported_codes{$id};
1056: my $description = &plainlanguagedescription($id);
1057: push (@lang_choices, [$selector, $description]);
1058: }
1059: }
1060: return \@lang_choices;
1061: }
1062:
1063: =pod
1064:
1.648 raeburn 1065: =item * &linked_select_forms(...)
1.36 matthew 1066:
1067: linked_select_forms returns a string containing a <script></script> block
1068: and html for two <select> menus. The select menus will be linked in that
1069: changing the value of the first menu will result in new values being placed
1070: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1071: order unless a defined order is provided.
1.36 matthew 1072:
1073: linked_select_forms takes the following ordered inputs:
1074:
1075: =over 4
1076:
1.112 bowersj2 1077: =item * $formname, the name of the <form> tag
1.36 matthew 1078:
1.112 bowersj2 1079: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1080:
1.112 bowersj2 1081: =item * $firstdefault, the default value for the first menu
1.36 matthew 1082:
1.112 bowersj2 1083: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1084:
1.112 bowersj2 1085: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1086:
1.112 bowersj2 1087: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1088:
1.609 raeburn 1089: =item * $menuorder, the order of values in the first menu
1090:
1.1115 raeburn 1091: =item * $onchangefirst, additional javascript call to execute for an onchange
1092: event for the first <select> tag
1093:
1094: =item * $onchangesecond, additional javascript call to execute for an onchange
1095: event for the second <select> tag
1096:
1.1245 raeburn 1097: =item * $suffix, to differentiate separate uses of select2data javascript
1098: objects in a page.
1099:
1.41 ng 1100: =back
1101:
1.36 matthew 1102: Below is an example of such a hash. Only the 'text', 'default', and
1103: 'select2' keys must appear as stated. keys(%menu) are the possible
1104: values for the first select menu. The text that coincides with the
1.41 ng 1105: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1106: and text for the second menu are given in the hash pointed to by
1107: $menu{$choice1}->{'select2'}.
1108:
1.112 bowersj2 1109: my %menu = ( A1 => { text =>"Choice A1" ,
1110: default => "B3",
1111: select2 => {
1112: B1 => "Choice B1",
1113: B2 => "Choice B2",
1114: B3 => "Choice B3",
1115: B4 => "Choice B4"
1.609 raeburn 1116: },
1117: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1118: },
1119: A2 => { text =>"Choice A2" ,
1120: default => "C2",
1121: select2 => {
1122: C1 => "Choice C1",
1123: C2 => "Choice C2",
1124: C3 => "Choice C3"
1.609 raeburn 1125: },
1126: order => ['C2','C1','C3'],
1.112 bowersj2 1127: },
1128: A3 => { text =>"Choice A3" ,
1129: default => "D6",
1130: select2 => {
1131: D1 => "Choice D1",
1132: D2 => "Choice D2",
1133: D3 => "Choice D3",
1134: D4 => "Choice D4",
1135: D5 => "Choice D5",
1136: D6 => "Choice D6",
1137: D7 => "Choice D7"
1.609 raeburn 1138: },
1139: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1140: }
1141: );
1.36 matthew 1142:
1143: =cut
1144:
1145: sub linked_select_forms {
1146: my ($formname,
1147: $middletext,
1148: $firstdefault,
1149: $firstselectname,
1150: $secondselectname,
1.609 raeburn 1151: $hashref,
1152: $menuorder,
1.1115 raeburn 1153: $onchangefirst,
1.1245 raeburn 1154: $onchangesecond,
1155: $suffix
1.36 matthew 1156: ) = @_;
1157: my $second = "document.$formname.$secondselectname";
1158: my $first = "document.$formname.$firstselectname";
1159: # output the javascript to do the changing
1160: my $result = '';
1.776 bisitz 1161: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1162: $result.="// <![CDATA[\n";
1.1245 raeburn 1163: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1164: $" = '","';
1165: my $debug = '';
1166: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1167: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1168: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1169: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1170: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1171: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1172: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1173: @s2values = @{$hashref->{$s1}->{'order'}};
1174: }
1.36 matthew 1175: $result.="\"@s2values\");\n";
1.1245 raeburn 1176: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1177: my @s2texts;
1178: foreach my $value (@s2values) {
1179: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1180: }
1181: $result.="\"@s2texts\");\n";
1182: }
1183: $"=' ';
1184: $result.= <<"END";
1185:
1.1245 raeburn 1186: function select1${suffix}_changed() {
1.36 matthew 1187: // Determine new choice
1.1245 raeburn 1188: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1189: // update select2
1.1245 raeburn 1190: var values = select2data${suffix}[newvalue].values;
1191: var texts = select2data${suffix}[newvalue].texts;
1192: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1193: var i;
1194: // out with the old
1.1245 raeburn 1195: $second.options.length = 0;
1196: // in with the new
1.36 matthew 1197: for (i=0;i<values.length; i++) {
1198: $second.options[i] = new Option(values[i]);
1.143 matthew 1199: $second.options[i].value = values[i];
1.36 matthew 1200: $second.options[i].text = texts[i];
1201: if (values[i] == select2def) {
1202: $second.options[i].selected = true;
1203: }
1204: }
1205: }
1.824 bisitz 1206: // ]]>
1.36 matthew 1207: </script>
1208: END
1209: # output the initial values for the selection lists
1.1245 raeburn 1210: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1211: my @order = sort(keys(%{$hashref}));
1212: if (ref($menuorder) eq 'ARRAY') {
1213: @order = @{$menuorder};
1214: }
1215: foreach my $value (@order) {
1.36 matthew 1216: $result.=" <option value=\"$value\" ";
1.253 albertel 1217: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1218: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1219: }
1220: $result .= "</select>\n";
1221: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1222: $result .= $middletext;
1.1115 raeburn 1223: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1224: if ($onchangesecond) {
1225: $result .= ' onchange="'.$onchangesecond.'"';
1226: }
1227: $result .= ">\n";
1.36 matthew 1228: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1229:
1230: my @secondorder = sort(keys(%select2));
1231: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1232: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1233: }
1234: foreach my $value (@secondorder) {
1.36 matthew 1235: $result.=" <option value=\"$value\" ";
1.253 albertel 1236: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1237: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1238: }
1239: $result .= "</select>\n";
1240: # return $debug;
1241: return $result;
1242: } # end of sub linked_select_forms {
1243:
1.45 matthew 1244: =pod
1.44 bowersj2 1245:
1.973 raeburn 1246: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1247:
1.112 bowersj2 1248: Returns a string corresponding to an HTML link to the given help
1249: $topic, where $topic corresponds to the name of a .tex file in
1250: /home/httpd/html/adm/help/tex, with underscores replaced by
1251: spaces.
1252:
1253: $text will optionally be linked to the same topic, allowing you to
1254: link text in addition to the graphic. If you do not want to link
1255: text, but wish to specify one of the later parameters, pass an
1256: empty string.
1257:
1258: $stayOnPage is a value that will be interpreted as a boolean. If true,
1259: the link will not open a new window. If false, the link will open
1260: a new window using Javascript. (Default is false.)
1261:
1262: $width and $height are optional numerical parameters that will
1263: override the width and height of the popped up window, which may
1.973 raeburn 1264: be useful for certain help topics with big pictures included.
1265:
1266: $imgid is the id of the img tag used for the help icon. This may be
1267: used in a javascript call to switch the image src. See
1268: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1269:
1270: =cut
1271:
1272: sub help_open_topic {
1.973 raeburn 1273: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1274: $text = "" if (not defined $text);
1.44 bowersj2 1275: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1276: $width = 500 if (not defined $width);
1.44 bowersj2 1277: $height = 400 if (not defined $height);
1278: my $filename = $topic;
1279: $filename =~ s/ /_/g;
1280:
1.48 bowersj2 1281: my $template = "";
1282: my $link;
1.572 banghart 1283:
1.159 www 1284: $topic=~s/\W/\_/g;
1.44 bowersj2 1285:
1.572 banghart 1286: if (!$stayOnPage) {
1.1033 www 1287: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1288: } elsif ($stayOnPage eq 'popup') {
1289: $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 1290: } else {
1.48 bowersj2 1291: $link = "/adm/help/${filename}.hlp";
1292: }
1293:
1294: # Add the text
1.755 neumanie 1295: if ($text ne "") {
1.763 bisitz 1296: $template.='<span class="LC_help_open_topic">'
1297: .'<a target="_top" href="'.$link.'">'
1298: .$text.'</a>';
1.48 bowersj2 1299: }
1300:
1.763 bisitz 1301: # (Always) Add the graphic
1.179 matthew 1302: my $title = &mt('Online Help');
1.667 raeburn 1303: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1304: if ($imgid ne '') {
1305: $imgid = ' id="'.$imgid.'"';
1306: }
1.763 bisitz 1307: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1308: .'<img src="'.$helpicon.'" border="0"'
1309: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1310: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1311: .' /></a>';
1312: if ($text ne "") {
1313: $template.='</span>';
1314: }
1.44 bowersj2 1315: return $template;
1316:
1.106 bowersj2 1317: }
1318:
1319: # This is a quicky function for Latex cheatsheet editing, since it
1320: # appears in at least four places
1321: sub helpLatexCheatsheet {
1.1037 www 1322: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1323: my $out;
1.106 bowersj2 1324: my $addOther = '';
1.732 raeburn 1325: if ($topic) {
1.1037 www 1326: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1327: }
1328: $out = '<span>' # Start cheatsheet
1329: .$addOther
1330: .'<span>'
1.1037 www 1331: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1332: .'</span> <span>'
1.1037 www 1333: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1334: .'</span>';
1.732 raeburn 1335: unless ($not_author) {
1.1186 kruse 1336: $out .= '<span>'
1337: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1338: .'</span> <span>'
1339: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1340: .'</span>';
1.732 raeburn 1341: }
1.763 bisitz 1342: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1343: return $out;
1.172 www 1344: }
1345:
1.430 albertel 1346: sub general_help {
1347: my $helptopic='Student_Intro';
1348: if ($env{'request.role'}=~/^(ca|au)/) {
1349: $helptopic='Authoring_Intro';
1.907 raeburn 1350: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1351: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1352: } elsif ($env{'request.role'}=~/^dc/) {
1353: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1354: }
1355: return $helptopic;
1356: }
1357:
1358: sub update_help_link {
1359: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1360: my $origurl = $ENV{'REQUEST_URI'};
1361: $origurl=~s|^/~|/priv/|;
1362: my $timestamp = time;
1363: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1364: $$datum = &escape($$datum);
1365: }
1366:
1367: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1368: my $output .= <<"ENDOUTPUT";
1369: <script type="text/javascript">
1.824 bisitz 1370: // <![CDATA[
1.430 albertel 1371: banner_link = '$banner_link';
1.824 bisitz 1372: // ]]>
1.430 albertel 1373: </script>
1374: ENDOUTPUT
1375: return $output;
1376: }
1377:
1378: # now just updates the help link and generates a blue icon
1.193 raeburn 1379: sub help_open_menu {
1.430 albertel 1380: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1381: = @_;
1.949 droeschl 1382: $stayOnPage = 1;
1.430 albertel 1383: my $output;
1384: if ($component_help) {
1385: if (!$text) {
1386: $output=&help_open_topic($component_help,undef,$stayOnPage,
1387: $width,$height);
1388: } else {
1389: my $help_text;
1390: $help_text=&unescape($topic);
1391: $output='<table><tr><td>'.
1392: &help_open_topic($component_help,$help_text,$stayOnPage,
1393: $width,$height).'</td></tr></table>';
1394: }
1395: }
1396: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1397: return $output.$banner_link;
1398: }
1399:
1400: sub top_nav_help {
1401: my ($text) = @_;
1.436 albertel 1402: $text = &mt($text);
1.949 droeschl 1403: my $stay_on_page = 1;
1404:
1.1168 raeburn 1405: my ($link,$banner_link);
1406: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1407: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1408: : "javascript:helpMenu('open')";
1409: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1410: }
1.201 raeburn 1411: my $title = &mt('Get help');
1.1168 raeburn 1412: if ($link) {
1413: return <<"END";
1.436 albertel 1414: $banner_link
1.1159 raeburn 1415: <a href="$link" title="$title">$text</a>
1.436 albertel 1416: END
1.1168 raeburn 1417: } else {
1418: return ' '.$text.' ';
1419: }
1.436 albertel 1420: }
1421:
1422: sub help_menu_js {
1.1154 raeburn 1423: my ($httphost) = @_;
1.949 droeschl 1424: my $stayOnPage = 1;
1.436 albertel 1425: my $width = 620;
1426: my $height = 600;
1.430 albertel 1427: my $helptopic=&general_help();
1.1154 raeburn 1428: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1429: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1430: my $start_page =
1431: &Apache::loncommon::start_page('Help Menu', undef,
1432: {'frameset' => 1,
1433: 'js_ready' => 1,
1.1154 raeburn 1434: 'use_absolute' => $httphost,
1.331 albertel 1435: 'add_entries' => {
1.1168 raeburn 1436: 'border' => '0',
1.579 raeburn 1437: 'rows' => "110,*",},});
1.331 albertel 1438: my $end_page =
1439: &Apache::loncommon::end_page({'frameset' => 1,
1440: 'js_ready' => 1,});
1441:
1.436 albertel 1442: my $template .= <<"ENDTEMPLATE";
1443: <script type="text/javascript">
1.877 bisitz 1444: // <![CDATA[
1.253 albertel 1445: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1446: var banner_link = '';
1.243 raeburn 1447: function helpMenu(target) {
1448: var caller = this;
1449: if (target == 'open') {
1450: var newWindow = null;
1451: try {
1.262 albertel 1452: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1453: }
1454: catch(error) {
1455: writeHelp(caller);
1456: return;
1457: }
1458: if (newWindow) {
1459: caller = newWindow;
1460: }
1.193 raeburn 1461: }
1.243 raeburn 1462: writeHelp(caller);
1463: return;
1464: }
1465: function writeHelp(caller) {
1.1168 raeburn 1466: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1467: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1468: caller.document.close();
1469: caller.focus();
1.193 raeburn 1470: }
1.877 bisitz 1471: // END LON-CAPA Internal -->
1.253 albertel 1472: // ]]>
1.436 albertel 1473: </script>
1.193 raeburn 1474: ENDTEMPLATE
1475: return $template;
1476: }
1477:
1.172 www 1478: sub help_open_bug {
1479: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1480: unless ($env{'user.adv'}) { return ''; }
1.172 www 1481: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1482: $text = "" if (not defined $text);
1483: $stayOnPage=1;
1.184 albertel 1484: $width = 600 if (not defined $width);
1485: $height = 600 if (not defined $height);
1.172 www 1486:
1487: $topic=~s/\W+/\+/g;
1488: my $link='';
1489: my $template='';
1.379 albertel 1490: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1491: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1492: if (!$stayOnPage)
1493: {
1494: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1495: }
1496: else
1497: {
1498: $link = $url;
1499: }
1500: # Add the text
1501: if ($text ne "")
1502: {
1503: $template .=
1504: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1505: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1506: }
1507:
1508: # Add the graphic
1.179 matthew 1509: my $title = &mt('Report a Bug');
1.215 albertel 1510: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1511: $template .= <<"ENDTEMPLATE";
1.436 albertel 1512: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1513: ENDTEMPLATE
1514: if ($text ne '') { $template.='</td></tr></table>' };
1515: return $template;
1516:
1517: }
1518:
1519: sub help_open_faq {
1520: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1521: unless ($env{'user.adv'}) { return ''; }
1.172 www 1522: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1523: $text = "" if (not defined $text);
1524: $stayOnPage=1;
1525: $width = 350 if (not defined $width);
1526: $height = 400 if (not defined $height);
1527:
1528: $topic=~s/\W+/\+/g;
1529: my $link='';
1530: my $template='';
1531: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1532: if (!$stayOnPage)
1533: {
1534: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1535: }
1536: else
1537: {
1538: $link = $url;
1539: }
1540:
1541: # Add the text
1542: if ($text ne "")
1543: {
1544: $template .=
1.173 www 1545: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1546: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1547: }
1548:
1549: # Add the graphic
1.179 matthew 1550: my $title = &mt('View the FAQ');
1.215 albertel 1551: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1552: $template .= <<"ENDTEMPLATE";
1.436 albertel 1553: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1554: ENDTEMPLATE
1555: if ($text ne '') { $template.='</td></tr></table>' };
1556: return $template;
1557:
1.44 bowersj2 1558: }
1.37 matthew 1559:
1.180 matthew 1560: ###############################################################
1561: ###############################################################
1562:
1.45 matthew 1563: =pod
1564:
1.648 raeburn 1565: =item * &change_content_javascript():
1.256 matthew 1566:
1567: This and the next function allow you to create small sections of an
1568: otherwise static HTML page that you can update on the fly with
1569: Javascript, even in Netscape 4.
1570:
1571: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1572: must be written to the HTML page once. It will prove the Javascript
1573: function "change(name, content)". Calling the change function with the
1574: name of the section
1575: you want to update, matching the name passed to C<changable_area>, and
1576: the new content you want to put in there, will put the content into
1577: that area.
1578:
1579: B<Note>: Netscape 4 only reserves enough space for the changable area
1580: to contain room for the original contents. You need to "make space"
1581: for whatever changes you wish to make, and be B<sure> to check your
1582: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1583: it's adequate for updating a one-line status display, but little more.
1584: This script will set the space to 100% width, so you only need to
1585: worry about height in Netscape 4.
1586:
1587: Modern browsers are much less limiting, and if you can commit to the
1588: user not using Netscape 4, this feature may be used freely with
1589: pretty much any HTML.
1590:
1591: =cut
1592:
1593: sub change_content_javascript {
1594: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1595: if ($env{'browser.type'} eq 'netscape' &&
1596: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1597: return (<<NETSCAPE4);
1598: function change(name, content) {
1599: doc = document.layers[name+"___escape"].layers[0].document;
1600: doc.open();
1601: doc.write(content);
1602: doc.close();
1603: }
1604: NETSCAPE4
1605: } else {
1606: # Otherwise, we need to use semi-standards-compliant code
1607: # (technically, "innerHTML" isn't standard but the equivalent
1608: # is really scary, and every useful browser supports it
1609: return (<<DOMBASED);
1610: function change(name, content) {
1611: element = document.getElementById(name);
1612: element.innerHTML = content;
1613: }
1614: DOMBASED
1615: }
1616: }
1617:
1618: =pod
1619:
1.648 raeburn 1620: =item * &changable_area($name,$origContent):
1.256 matthew 1621:
1622: This provides a "changable area" that can be modified on the fly via
1623: the Javascript code provided in C<change_content_javascript>. $name is
1624: the name you will use to reference the area later; do not repeat the
1625: same name on a given HTML page more then once. $origContent is what
1626: the area will originally contain, which can be left blank.
1627:
1628: =cut
1629:
1630: sub changable_area {
1631: my ($name, $origContent) = @_;
1632:
1.258 albertel 1633: if ($env{'browser.type'} eq 'netscape' &&
1634: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1635: # If this is netscape 4, we need to use the Layer tag
1636: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1637: } else {
1638: return "<span id='$name'>$origContent</span>";
1639: }
1640: }
1641:
1642: =pod
1643:
1.648 raeburn 1644: =item * &viewport_geometry_js
1.590 raeburn 1645:
1646: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1647:
1648: =cut
1649:
1650:
1651: sub viewport_geometry_js {
1652: return <<"GEOMETRY";
1653: var Geometry = {};
1654: function init_geometry() {
1655: if (Geometry.init) { return };
1656: Geometry.init=1;
1657: if (window.innerHeight) {
1658: Geometry.getViewportHeight = function() { return window.innerHeight; };
1659: Geometry.getViewportWidth = function() { return window.innerWidth; };
1660: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1661: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1662: }
1663: else if (document.documentElement && document.documentElement.clientHeight) {
1664: Geometry.getViewportHeight =
1665: function() { return document.documentElement.clientHeight; };
1666: Geometry.getViewportWidth =
1667: function() { return document.documentElement.clientWidth; };
1668:
1669: Geometry.getHorizontalScroll =
1670: function() { return document.documentElement.scrollLeft; };
1671: Geometry.getVerticalScroll =
1672: function() { return document.documentElement.scrollTop; };
1673: }
1674: else if (document.body.clientHeight) {
1675: Geometry.getViewportHeight =
1676: function() { return document.body.clientHeight; };
1677: Geometry.getViewportWidth =
1678: function() { return document.body.clientWidth; };
1679: Geometry.getHorizontalScroll =
1680: function() { return document.body.scrollLeft; };
1681: Geometry.getVerticalScroll =
1682: function() { return document.body.scrollTop; };
1683: }
1684: }
1685:
1686: GEOMETRY
1687: }
1688:
1689: =pod
1690:
1.648 raeburn 1691: =item * &viewport_size_js()
1.590 raeburn 1692:
1693: 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.
1694:
1695: =cut
1696:
1697: sub viewport_size_js {
1698: my $geometry = &viewport_geometry_js();
1699: return <<"DIMS";
1700:
1701: $geometry
1702:
1703: function getViewportDims(width,height) {
1704: init_geometry();
1705: width.value = Geometry.getViewportWidth();
1706: height.value = Geometry.getViewportHeight();
1707: return;
1708: }
1709:
1710: DIMS
1711: }
1712:
1713: =pod
1714:
1.648 raeburn 1715: =item * &resize_textarea_js()
1.565 albertel 1716:
1717: emits the needed javascript to resize a textarea to be as big as possible
1718:
1719: creates a function resize_textrea that takes two IDs first should be
1720: the id of the element to resize, second should be the id of a div that
1721: surrounds everything that comes after the textarea, this routine needs
1722: to be attached to the <body> for the onload and onresize events.
1723:
1.648 raeburn 1724: =back
1.565 albertel 1725:
1726: =cut
1727:
1728: sub resize_textarea_js {
1.590 raeburn 1729: my $geometry = &viewport_geometry_js();
1.565 albertel 1730: return <<"RESIZE";
1731: <script type="text/javascript">
1.824 bisitz 1732: // <![CDATA[
1.590 raeburn 1733: $geometry
1.565 albertel 1734:
1.588 albertel 1735: function getX(element) {
1736: var x = 0;
1737: while (element) {
1738: x += element.offsetLeft;
1739: element = element.offsetParent;
1740: }
1741: return x;
1742: }
1743: function getY(element) {
1744: var y = 0;
1745: while (element) {
1746: y += element.offsetTop;
1747: element = element.offsetParent;
1748: }
1749: return y;
1750: }
1751:
1752:
1.565 albertel 1753: function resize_textarea(textarea_id,bottom_id) {
1754: init_geometry();
1755: var textarea = document.getElementById(textarea_id);
1756: //alert(textarea);
1757:
1.588 albertel 1758: var textarea_top = getY(textarea);
1.565 albertel 1759: var textarea_height = textarea.offsetHeight;
1760: var bottom = document.getElementById(bottom_id);
1.588 albertel 1761: var bottom_top = getY(bottom);
1.565 albertel 1762: var bottom_height = bottom.offsetHeight;
1763: var window_height = Geometry.getViewportHeight();
1.588 albertel 1764: var fudge = 23;
1.565 albertel 1765: var new_height = window_height-fudge-textarea_top-bottom_height;
1766: if (new_height < 300) {
1767: new_height = 300;
1768: }
1769: textarea.style.height=new_height+'px';
1770: }
1.824 bisitz 1771: // ]]>
1.565 albertel 1772: </script>
1773: RESIZE
1774:
1775: }
1776:
1.1205 golterma 1777: sub colorfuleditor_js {
1.1248 raeburn 1778: my $browse_or_search;
1779: my $respath;
1780: my ($cnum,$cdom) = &crsauthor_url();
1781: if ($cnum) {
1782: $respath = "/res/$cdom/$cnum/";
1783: my %js_lt = &Apache::lonlocal::texthash(
1784: sunm => 'Sub-directory name',
1785: save => 'Save page to make this permanent',
1786: );
1787: &js_escape(\%js_lt);
1788: $browse_or_search = <<"END";
1789:
1790: function toggleChooser(form,element,titleid,only,search) {
1791: var disp = 'none';
1792: if (document.getElementById('chooser_'+element)) {
1793: var curr = document.getElementById('chooser_'+element).style.display;
1794: if (curr == 'none') {
1795: disp='inline';
1796: if (form.elements['chooser_'+element].length) {
1797: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1798: form.elements['chooser_'+element][i].checked = false;
1799: }
1800: }
1801: toggleResImport(form,element);
1802: }
1803: document.getElementById('chooser_'+element).style.display = disp;
1804: }
1805: }
1806:
1807: function toggleCrsFile(form,element,numdirs) {
1808: if (document.getElementById('chooser_'+element+'_crsres')) {
1809: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1810: if (curr == 'none') {
1811: if (numdirs) {
1812: form.elements['coursepath_'+element].selectedIndex = 0;
1813: if (numdirs > 1) {
1814: window['select1'+element+'_changed']();
1815: }
1816: }
1817: }
1818: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1819:
1820: }
1821: if (document.getElementById('chooser_'+element+'_upload')) {
1822: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1823: if (document.getElementById('uploadcrsres_'+element)) {
1824: document.getElementById('uploadcrsres_'+element).value = '';
1825: }
1826: }
1827: return;
1828: }
1829:
1830: function toggleCrsUpload(form,element,numcrsdirs) {
1831: if (document.getElementById('chooser_'+element+'_crsres')) {
1832: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1833: }
1834: if (document.getElementById('chooser_'+element+'_upload')) {
1835: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1836: if (curr == 'none') {
1837: if (numcrsdirs) {
1838: form.elements['crsauthorpath_'+element].selectedIndex = 0;
1839: form.elements['newsubdir_'+element][0].checked = true;
1840: toggleNewsubdir(form,element);
1841: }
1842: }
1843: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1844: }
1845: return;
1846: }
1847:
1848: function toggleResImport(form,element) {
1849: var choices = new Array('crsres','upload');
1850: for (var i=0; i<choices.length; i++) {
1851: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1852: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1853: }
1854: }
1855: }
1856:
1857: function toggleNewsubdir(form,element) {
1858: var newsub = form.elements['newsubdir_'+element];
1859: if (newsub) {
1860: if (newsub.length) {
1861: for (var j=0; j<newsub.length; j++) {
1862: if (newsub[j].checked) {
1863: if (document.getElementById('newsubdirname_'+element)) {
1864: if (newsub[j].value == '1') {
1865: document.getElementById('newsubdirname_'+element).type = "text";
1866: if (document.getElementById('newsubdir_'+element)) {
1867: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1868: }
1869: } else {
1870: document.getElementById('newsubdirname_'+element).type = "hidden";
1871: document.getElementById('newsubdirname_'+element).value = "";
1872: document.getElementById('newsubdir_'+element).innerHTML = "";
1873: }
1874: }
1875: break;
1876: }
1877: }
1878: }
1879: }
1880: }
1881:
1882: function updateCrsFile(form,element) {
1883: var directory = form.elements['coursepath_'+element];
1884: var filename = form.elements['coursefile_'+element];
1885: var path = directory.options[directory.selectedIndex].value;
1886: var file = filename.options[filename.selectedIndex].value;
1887: form.elements[element].value = '$respath';
1888: if (path == '/') {
1889: form.elements[element].value += file;
1890: } else {
1891: form.elements[element].value += path+'/'+file;
1892: }
1893: unClean();
1894: if (document.getElementById('previewimg_'+element)) {
1895: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1896: var newsrc = document.getElementById('previewimg_'+element).src;
1897: }
1898: if (document.getElementById('showimg_'+element)) {
1899: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1900: }
1901: toggleChooser(form,element);
1902: return;
1903: }
1904:
1905: function uploadDone(suffix,name) {
1906: if (name) {
1907: document.forms["lonhomework"].elements[suffix].value = name;
1908: unClean();
1909: toggleChooser(document.forms["lonhomework"],suffix);
1910: }
1911: }
1912:
1913: \$(document).ready(function(){
1914:
1915: \$(document).delegate('form :submit', 'click', function( event ) {
1916: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
1917: var buttonId = this.id;
1918: var suffix = buttonId.toString();
1919: suffix = suffix.replace(/^crsupload_/,'');
1920: event.preventDefault();
1921: document.lonhomework.target = 'crsupload_target_'+suffix;
1922: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
1923: \$(this.form).submit();
1924: document.lonhomework.target = '';
1925: if (document.getElementById('crsuploadto_'+suffix)) {
1926: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
1927: }
1928: return false;
1929: }
1930: });
1931: });
1932: END
1933: }
1.1205 golterma 1934: return <<"COLORFULEDIT"
1935: <script type="text/javascript">
1936: // <![CDATA[>
1937: function fold_box(curDepth, lastresource){
1938:
1939: // we need a list because there can be several blocks you need to fold in one tag
1940: var block = document.getElementsByName('foldblock_'+curDepth);
1941: // but there is only one folding button per tag
1942: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1943:
1944: if(block.item(0).style.display == 'none'){
1945:
1946: foldbutton.value = '@{[&mt("Hide")]}';
1947: for (i = 0; i < block.length; i++){
1948: block.item(i).style.display = '';
1949: }
1950: }else{
1951:
1952: foldbutton.value = '@{[&mt("Show")]}';
1953: for (i = 0; i < block.length; i++){
1954: // block.item(i).style.visibility = 'collapse';
1955: block.item(i).style.display = 'none';
1956: }
1957: };
1958: saveState(lastresource);
1959: }
1960:
1961: function saveState (lastresource) {
1962:
1963: var tag_list = getTagList();
1964: if(tag_list != null){
1965: var timestamp = new Date().getTime();
1966: var key = lastresource;
1967:
1968: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1969: // starting with timestamp
1970: var value = timestamp+';';
1971:
1972: // building the list of key-value pairs
1973: for(var i = 0; i < tag_list.length; i++){
1974: value += tag_list[i]+',';
1975: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1976: }
1977:
1978: // only iterate whole storage if nothing to override
1979: if(localStorage.getItem(key) == null){
1980:
1981: // prevent storage from growing large
1982: if(localStorage.length > 50){
1983: var regex_getTimestamp = /^(?:\d)+;/;
1984: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1985: var oldest_key;
1986:
1987: for(var i = 1; i < localStorage.length; i++){
1988: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1989: oldest_key = localStorage.key(i);
1990: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1991: }
1992: }
1993: localStorage.removeItem(oldest_key);
1994: }
1995: }
1996: localStorage.setItem(key,value);
1997: }
1998: }
1999:
2000: // restore folding status of blocks (on page load)
2001: function restoreState (lastresource) {
2002: if(localStorage.getItem(lastresource) != null){
2003: var key = lastresource;
2004: var value = localStorage.getItem(key);
2005: var regex_delTimestamp = /^\d+;/;
2006:
2007: value.replace(regex_delTimestamp, '');
2008:
2009: var valueArr = value.split(';');
2010: var pairs;
2011: var elements;
2012: for (var i = 0; i < valueArr.length; i++){
2013: pairs = valueArr[i].split(',');
2014: elements = document.getElementsByName(pairs[0]);
2015:
2016: for (var j = 0; j < elements.length; j++){
2017: elements[j].style.display = pairs[1];
2018: if (pairs[1] == "none"){
2019: var regex_id = /([_\\d]+)\$/;
2020: regex_id.exec(pairs[0]);
2021: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2022: }
2023: }
2024: }
2025: }
2026: }
2027:
2028: function getTagList () {
2029:
2030: var stringToSearch = document.lonhomework.innerHTML;
2031:
2032: var ret = new Array();
2033: var regex_findBlock = /(foldblock_.*?)"/g;
2034: var tag_list = stringToSearch.match(regex_findBlock);
2035:
2036: if(tag_list != null){
2037: for(var i = 0; i < tag_list.length; i++){
2038: ret.push(tag_list[i].replace(/"/, ''));
2039: }
2040: }
2041: return ret;
2042: }
2043:
2044: function saveScrollPosition (resource) {
2045: var tag_list = getTagList();
2046:
2047: // we dont always want to jump to the first block
2048: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2049: if(\$(window).scrollTop() > 170){
2050: if(tag_list != null){
2051: var result;
2052: for(var i = 0; i < tag_list.length; i++){
2053: if(isElementInViewport(tag_list[i])){
2054: result += tag_list[i]+';';
2055: }
2056: }
2057: sessionStorage.setItem('anchor_'+resource, result);
2058: }
2059: } else {
2060: // we dont need to save zero, just delete the item to leave everything tidy
2061: sessionStorage.removeItem('anchor_'+resource);
2062: }
2063: }
2064:
2065: function restoreScrollPosition(resource){
2066:
2067: var elem = sessionStorage.getItem('anchor_'+resource);
2068: if(elem != null){
2069: var tag_list = elem.split(';');
2070: var elem_list;
2071:
2072: for(var i = 0; i < tag_list.length; i++){
2073: elem_list = document.getElementsByName(tag_list[i]);
2074:
2075: if(elem_list.length > 0){
2076: elem = elem_list[0];
2077: break;
2078: }
2079: }
2080: elem.scrollIntoView();
2081: }
2082: }
2083:
2084: function isElementInViewport(el) {
2085:
2086: // change to last element instead of first
2087: var elem = document.getElementsByName(el);
2088: var rect = elem[0].getBoundingClientRect();
2089:
2090: return (
2091: rect.top >= 0 &&
2092: rect.left >= 0 &&
2093: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2094: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2095: );
2096: }
2097:
2098: function autosize(depth){
2099: var cmInst = window['cm'+depth];
2100: var fitsizeButton = document.getElementById('fitsize'+depth);
2101:
2102: // is fixed size, switching to dynamic
2103: if (sessionStorage.getItem("autosized_"+depth) == null) {
2104: cmInst.setSize("","auto");
2105: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2106: sessionStorage.setItem("autosized_"+depth, "yes");
2107:
2108: // is dynamic size, switching to fixed
2109: } else {
2110: cmInst.setSize("","300px");
2111: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2112: sessionStorage.removeItem("autosized_"+depth);
2113: }
2114: }
2115:
1.1248 raeburn 2116: $browse_or_search
1.1205 golterma 2117:
2118: // ]]>
2119: </script>
2120: COLORFULEDIT
2121: }
2122:
2123: sub xmleditor_js {
2124: return <<XMLEDIT
2125: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2126: <script type="text/javascript">
2127: // <![CDATA[>
2128:
2129: function saveScrollPosition (resource) {
2130:
2131: var scrollPos = \$(window).scrollTop();
2132: sessionStorage.setItem(resource,scrollPos);
2133: }
2134:
2135: function restoreScrollPosition(resource){
2136:
2137: var scrollPos = sessionStorage.getItem(resource);
2138: \$(window).scrollTop(scrollPos);
2139: }
2140:
2141: // unless internet explorer
2142: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2143:
2144: \$(document).ready(function() {
2145: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2146: });
2147: }
2148:
2149: // inserts text at cursor position into codemirror (xml editor only)
2150: function insertText(text){
2151: cm.focus();
2152: var curPos = cm.getCursor();
2153: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2154: }
2155: // ]]>
2156: </script>
2157: XMLEDIT
2158: }
2159:
2160: sub insert_folding_button {
2161: my $curDepth = $Apache::lonxml::curdepth;
2162: my $lastresource = $env{'request.ambiguous'};
2163:
2164: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2165: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2166: }
2167:
1.1248 raeburn 2168: sub crsauthor_url {
2169: my ($url) = @_;
2170: if ($url eq '') {
2171: $url = $ENV{'REQUEST_URI'};
2172: }
2173: my ($cnum,$cdom);
2174: if ($env{'request.course.id'}) {
2175: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2176: if ($audom ne '' && $auname ne '') {
2177: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2178: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2179: $cnum = $auname;
2180: $cdom = $audom;
2181: }
2182: }
2183: }
2184: return ($cnum,$cdom);
2185: }
2186:
2187: sub import_crsauthor_form {
2188: my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix) = @_;
2189: return (0) unless ($env{'request.course.id'});
2190: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2191: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2192: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2193: return (0) unless (($cnum ne '') && ($cdom ne ''));
2194: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
2195: my @ids=&Apache::lonnet::current_machine_ids();
2196: my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
2197:
2198: if (grep(/^\Q$crshome\E$/,@ids)) {
2199: $is_home = 1;
2200: }
2201: $relpath = "/priv/$cdom/$cnum";
2202: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
2203: my %lt = &Apache::lonlocal::texthash (
2204: fnam => 'Filename',
2205: dire => 'Directory',
2206: );
2207: my $numdirs = scalar(keys(%files));
2208: my (%possexts,$singledir,@singledirfiles);
2209: if ($only) {
2210: map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
2211: }
2212: my (%nonemptydirs,$possdirs);
2213: if ($numdirs > 1) {
2214: my @order;
2215: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
2216: if (ref($files{$key}) eq 'HASH') {
2217: my $shown = $key;
2218: if ($key eq '') {
2219: $shown = '/';
2220: }
2221: my @ordered = ();
2222: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
2223: if ($only) {
2224: my ($ext) = ($file =~ /\.([^.]+)$/);
2225: unless ($possexts{lc($ext)}) {
2226: next;
2227: }
2228: }
2229: $selimport_menus{$key}->{'select2'}->{$file} = $file;
2230: push(@ordered,$file);
2231: }
2232: if (@ordered) {
2233: push(@order,$key);
2234: $nonemptydirs{$key} = 1;
2235: $selimport_menus{$key}->{'text'} = $shown;
2236: $selimport_menus{$key}->{'default'} = '';
2237: $selimport_menus{$key}->{'select2'}->{''} = '';
2238: $selimport_menus{$key}->{'order'} = \@ordered;
2239: }
2240: }
2241: }
2242: $possdirs = scalar(keys(%nonemptydirs));
2243: if ($possdirs > 1) {
2244: my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
2245: $output = $lt{'dire'}.
2246: &linked_select_forms($form,'<br />'.
2247: $lt{'fnam'},'',
2248: $firstselectname,$secondselectname,
2249: \%selimport_menus,\@order,
2250: $onchangefirst,'',$suffix).'<br />';
2251: } elsif ($possdirs == 1) {
2252: $singledir = (keys(%nonemptydirs))[0];
2253: if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
2254: @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
2255: }
2256: delete($selimport_menus{$singledir});
2257: }
2258: } elsif ($numdirs == 1) {
2259: $singledir = (keys(%files))[0];
2260: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
2261: if ($only) {
2262: my ($ext) = ($file =~ /\.([^.]+)$/);
2263: unless ($possexts{lc($ext)}) {
2264: next;
2265: }
2266: }
2267: push(@singledirfiles,$file);
2268: }
2269: if (@singledirfiles) {
2270: $possdirs == 1;
2271: }
2272: }
2273: if (($possdirs == 1) && (@singledirfiles)) {
2274: my $showdir = $singledir;
2275: if ($singledir eq '') {
2276: $showdir = '/';
2277: }
2278: $output = $lt{'dire'}.
2279: '<select name="'.$firstselectname.'">'.
2280: '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
2281: '</select><br />'.
2282: $lt{'fnam'}.'<select name="'.$secondselectname.'">'."\n".
2283: '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
2284: foreach my $file (@singledirfiles) {
2285: $output .= '<option value="'.$file.'">'.$file.'</option>'."\n";
2286: }
2287: $output .= '</select><br />'."\n";
2288: }
2289: return ($possdirs,$output);
2290: }
2291:
1.565 albertel 2292: =pod
2293:
1.256 matthew 2294: =head1 Excel and CSV file utility routines
2295:
2296: =cut
2297:
2298: ###############################################################
2299: ###############################################################
2300:
2301: =pod
2302:
1.1162 raeburn 2303: =over 4
2304:
1.648 raeburn 2305: =item * &csv_translate($text)
1.37 matthew 2306:
1.185 www 2307: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2308: format.
2309:
2310: =cut
2311:
1.180 matthew 2312: ###############################################################
2313: ###############################################################
1.37 matthew 2314: sub csv_translate {
2315: my $text = shift;
2316: $text =~ s/\"/\"\"/g;
1.209 albertel 2317: $text =~ s/\n/ /g;
1.37 matthew 2318: return $text;
2319: }
1.180 matthew 2320:
2321: ###############################################################
2322: ###############################################################
2323:
2324: =pod
2325:
1.648 raeburn 2326: =item * &define_excel_formats()
1.180 matthew 2327:
2328: Define some commonly used Excel cell formats.
2329:
2330: Currently supported formats:
2331:
2332: =over 4
2333:
2334: =item header
2335:
2336: =item bold
2337:
2338: =item h1
2339:
2340: =item h2
2341:
2342: =item h3
2343:
1.256 matthew 2344: =item h4
2345:
2346: =item i
2347:
1.180 matthew 2348: =item date
2349:
2350: =back
2351:
2352: Inputs: $workbook
2353:
2354: Returns: $format, a hash reference.
2355:
1.1057 foxr 2356:
1.180 matthew 2357: =cut
2358:
2359: ###############################################################
2360: ###############################################################
2361: sub define_excel_formats {
2362: my ($workbook) = @_;
2363: my $format;
2364: $format->{'header'} = $workbook->add_format(bold => 1,
2365: bottom => 1,
2366: align => 'center');
2367: $format->{'bold'} = $workbook->add_format(bold=>1);
2368: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2369: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2370: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2371: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2372: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2373: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2374: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2375: return $format;
2376: }
2377:
2378: ###############################################################
2379: ###############################################################
1.113 bowersj2 2380:
2381: =pod
2382:
1.648 raeburn 2383: =item * &create_workbook()
1.255 matthew 2384:
2385: Create an Excel worksheet. If it fails, output message on the
2386: request object and return undefs.
2387:
2388: Inputs: Apache request object
2389:
2390: Returns (undef) on failure,
2391: Excel worksheet object, scalar with filename, and formats
2392: from &Apache::loncommon::define_excel_formats on success
2393:
2394: =cut
2395:
2396: ###############################################################
2397: ###############################################################
2398: sub create_workbook {
2399: my ($r) = @_;
2400: #
2401: # Create the excel spreadsheet
2402: my $filename = '/prtspool/'.
1.258 albertel 2403: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2404: time.'_'.rand(1000000000).'.xls';
2405: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2406: if (! defined($workbook)) {
2407: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2408: $r->print(
2409: '<p class="LC_error">'
2410: .&mt('Problems occurred in creating the new Excel file.')
2411: .' '.&mt('This error has been logged.')
2412: .' '.&mt('Please alert your LON-CAPA administrator.')
2413: .'</p>'
2414: );
1.255 matthew 2415: return (undef);
2416: }
2417: #
1.1014 foxr 2418: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2419: #
2420: my $format = &Apache::loncommon::define_excel_formats($workbook);
2421: return ($workbook,$filename,$format);
2422: }
2423:
2424: ###############################################################
2425: ###############################################################
2426:
2427: =pod
2428:
1.648 raeburn 2429: =item * &create_text_file()
1.113 bowersj2 2430:
1.542 raeburn 2431: Create a file to write to and eventually make available to the user.
1.256 matthew 2432: If file creation fails, outputs an error message on the request object and
2433: return undefs.
1.113 bowersj2 2434:
1.256 matthew 2435: Inputs: Apache request object, and file suffix
1.113 bowersj2 2436:
1.256 matthew 2437: Returns (undef) on failure,
2438: Filehandle and filename on success.
1.113 bowersj2 2439:
2440: =cut
2441:
1.256 matthew 2442: ###############################################################
2443: ###############################################################
2444: sub create_text_file {
2445: my ($r,$suffix) = @_;
2446: if (! defined($suffix)) { $suffix = 'txt'; };
2447: my $fh;
2448: my $filename = '/prtspool/'.
1.258 albertel 2449: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2450: time.'_'.rand(1000000000).'.'.$suffix;
2451: $fh = Apache::File->new('>/home/httpd'.$filename);
2452: if (! defined($fh)) {
2453: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2454: $r->print(
2455: '<p class="LC_error">'
2456: .&mt('Problems occurred in creating the output file.')
2457: .' '.&mt('This error has been logged.')
2458: .' '.&mt('Please alert your LON-CAPA administrator.')
2459: .'</p>'
2460: );
1.113 bowersj2 2461: }
1.256 matthew 2462: return ($fh,$filename)
1.113 bowersj2 2463: }
2464:
2465:
1.256 matthew 2466: =pod
1.113 bowersj2 2467:
2468: =back
2469:
2470: =cut
1.37 matthew 2471:
2472: ###############################################################
1.33 matthew 2473: ## Home server <option> list generating code ##
2474: ###############################################################
1.35 matthew 2475:
1.169 www 2476: # ------------------------------------------
2477:
2478: sub domain_select {
2479: my ($name,$value,$multiple)=@_;
2480: my %domains=map {
1.514 albertel 2481: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2482: } &Apache::lonnet::all_domains();
1.169 www 2483: if ($multiple) {
2484: $domains{''}=&mt('Any domain');
1.550 albertel 2485: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2486: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2487: } else {
1.550 albertel 2488: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2489: return &select_form($name,$value,\%domains);
1.169 www 2490: }
2491: }
2492:
1.282 albertel 2493: #-------------------------------------------
2494:
2495: =pod
2496:
1.519 raeburn 2497: =head1 Routines for form select boxes
2498:
2499: =over 4
2500:
1.648 raeburn 2501: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2502:
2503: Returns a string containing a <select> element int multiple mode
2504:
2505:
2506: Args:
2507: $name - name of the <select> element
1.506 raeburn 2508: $value - scalar or array ref of values that should already be selected
1.282 albertel 2509: $size - number of rows long the select element is
1.283 albertel 2510: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2511: (shown text should already have been &mt())
1.506 raeburn 2512: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2513:
1.282 albertel 2514: =cut
2515:
2516: #-------------------------------------------
1.169 www 2517: sub multiple_select_form {
1.284 albertel 2518: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2519: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2520: my $output='';
1.191 matthew 2521: if (! defined($size)) {
2522: $size = 4;
1.283 albertel 2523: if (scalar(keys(%$hash))<4) {
2524: $size = scalar(keys(%$hash));
1.191 matthew 2525: }
2526: }
1.734 bisitz 2527: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2528: my @order;
1.506 raeburn 2529: if (ref($order) eq 'ARRAY') {
2530: @order = @{$order};
2531: } else {
2532: @order = sort(keys(%$hash));
1.501 banghart 2533: }
2534: if (exists($$hash{'select_form_order'})) {
2535: @order = @{$$hash{'select_form_order'}};
2536: }
2537:
1.284 albertel 2538: foreach my $key (@order) {
1.356 albertel 2539: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2540: $output.='selected="selected" ' if ($selected{$key});
2541: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2542: }
2543: $output.="</select>\n";
2544: return $output;
2545: }
2546:
1.88 www 2547: #-------------------------------------------
2548:
2549: =pod
2550:
1.1254 raeburn 2551: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2552:
2553: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2554: allow a user to select options from a ref to a hash containing:
2555: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2556: a javascript onchange item, e.g., onchange="this.form.submit();".
2557: An optional arg -- $readonly -- if true will cause the select form
2558: to be disabled, e.g., for the case where an instructor has a section-
2559: specific role, and is viewing/modifying parameters.
1.970 raeburn 2560:
1.88 www 2561: See lonrights.pm for an example invocation and use.
2562:
2563: =cut
2564:
2565: #-------------------------------------------
2566: sub select_form {
1.1228 raeburn 2567: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2568: return unless (ref($hashref) eq 'HASH');
2569: if ($onchange) {
2570: $onchange = ' onchange="'.$onchange.'"';
2571: }
1.1228 raeburn 2572: my $disabled;
2573: if ($readonly) {
2574: $disabled = ' disabled="disabled"';
2575: }
2576: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2577: my @keys;
1.970 raeburn 2578: if (exists($hashref->{'select_form_order'})) {
2579: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2580: } else {
1.970 raeburn 2581: @keys=sort(keys(%{$hashref}));
1.128 albertel 2582: }
1.356 albertel 2583: foreach my $key (@keys) {
2584: $selectform.=
2585: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2586: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2587: ">".$hashref->{$key}."</option>\n";
1.88 www 2588: }
2589: $selectform.="</select>";
2590: return $selectform;
2591: }
2592:
1.475 www 2593: # For display filters
2594:
2595: sub display_filter {
1.1074 raeburn 2596: my ($context) = @_;
1.475 www 2597: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2598: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2599: my $phraseinput = 'hidden';
2600: my $includeinput = 'hidden';
2601: my ($checked,$includetypestext);
2602: if ($env{'form.displayfilter'} eq 'containing') {
2603: $phraseinput = 'text';
2604: if ($context eq 'parmslog') {
2605: $includeinput = 'checkbox';
2606: if ($env{'form.includetypes'}) {
2607: $checked = ' checked="checked"';
2608: }
2609: $includetypestext = &mt('Include parameter types');
2610: }
2611: } else {
2612: $includetypestext = ' ';
2613: }
2614: my ($additional,$secondid,$thirdid);
2615: if ($context eq 'parmslog') {
2616: $additional =
2617: '<label><input type="'.$includeinput.'" name="includetypes"'.
2618: $checked.' name="includetypes" value="1" id="includetypes" />'.
2619: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2620: '</label>';
2621: $secondid = 'includetypes';
2622: $thirdid = 'includetypestext';
2623: }
2624: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2625: '$secondid','$thirdid')";
2626: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2627: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2628: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2629: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2630: &mt('Filter: [_1]',
1.477 www 2631: &select_form($env{'form.displayfilter'},
2632: 'displayfilter',
1.970 raeburn 2633: {'currentfolder' => 'Current folder/page',
1.477 www 2634: 'containing' => 'Containing phrase',
1.1074 raeburn 2635: 'none' => 'None'},$onchange)).' '.
2636: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2637: &HTML::Entities::encode($env{'form.containingphrase'}).
2638: '" />'.$additional;
2639: }
2640:
2641: sub display_filter_js {
2642: my $includetext = &mt('Include parameter types');
2643: return <<"ENDJS";
2644:
2645: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2646: var firstType = 'hidden';
2647: if (setter.options[setter.selectedIndex].value == 'containing') {
2648: firstType = 'text';
2649: }
2650: firstObject = document.getElementById(firstid);
2651: if (typeof(firstObject) == 'object') {
2652: if (firstObject.type != firstType) {
2653: changeInputType(firstObject,firstType);
2654: }
2655: }
2656: if (context == 'parmslog') {
2657: var secondType = 'hidden';
2658: if (firstType == 'text') {
2659: secondType = 'checkbox';
2660: }
2661: secondObject = document.getElementById(secondid);
2662: if (typeof(secondObject) == 'object') {
2663: if (secondObject.type != secondType) {
2664: changeInputType(secondObject,secondType);
2665: }
2666: }
2667: var textItem = document.getElementById(thirdid);
2668: var currtext = textItem.innerHTML;
2669: var newtext;
2670: if (firstType == 'text') {
2671: newtext = '$includetext';
2672: } else {
2673: newtext = ' ';
2674: }
2675: if (currtext != newtext) {
2676: textItem.innerHTML = newtext;
2677: }
2678: }
2679: return;
2680: }
2681:
2682: function changeInputType(oldObject,newType) {
2683: var newObject = document.createElement('input');
2684: newObject.type = newType;
2685: if (oldObject.size) {
2686: newObject.size = oldObject.size;
2687: }
2688: if (oldObject.value) {
2689: newObject.value = oldObject.value;
2690: }
2691: if (oldObject.name) {
2692: newObject.name = oldObject.name;
2693: }
2694: if (oldObject.id) {
2695: newObject.id = oldObject.id;
2696: }
2697: oldObject.parentNode.replaceChild(newObject,oldObject);
2698: return;
2699: }
2700:
2701: ENDJS
1.475 www 2702: }
2703:
1.167 www 2704: sub gradeleveldescription {
2705: my $gradelevel=shift;
2706: my %gradelevels=(0 => 'Not specified',
2707: 1 => 'Grade 1',
2708: 2 => 'Grade 2',
2709: 3 => 'Grade 3',
2710: 4 => 'Grade 4',
2711: 5 => 'Grade 5',
2712: 6 => 'Grade 6',
2713: 7 => 'Grade 7',
2714: 8 => 'Grade 8',
2715: 9 => 'Grade 9',
2716: 10 => 'Grade 10',
2717: 11 => 'Grade 11',
2718: 12 => 'Grade 12',
2719: 13 => 'Grade 13',
2720: 14 => '100 Level',
2721: 15 => '200 Level',
2722: 16 => '300 Level',
2723: 17 => '400 Level',
2724: 18 => 'Graduate Level');
2725: return &mt($gradelevels{$gradelevel});
2726: }
2727:
1.163 www 2728: sub select_level_form {
2729: my ($deflevel,$name)=@_;
2730: unless ($deflevel) { $deflevel=0; }
1.167 www 2731: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2732: for (my $i=0; $i<=18; $i++) {
2733: $selectform.="<option value=\"$i\" ".
1.253 albertel 2734: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2735: ">".&gradeleveldescription($i)."</option>\n";
2736: }
2737: $selectform.="</select>";
2738: return $selectform;
1.163 www 2739: }
1.167 www 2740:
1.35 matthew 2741: #-------------------------------------------
2742:
1.45 matthew 2743: =pod
2744:
1.1256 raeburn 2745: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2746:
2747: Returns a string containing a <select name='$name' size='1'> form to
2748: allow a user to select the domain to preform an operation in.
2749: See loncreateuser.pm for an example invocation and use.
2750:
1.90 www 2751: If the $includeempty flag is set, it also includes an empty choice ("no domain
2752: selected");
2753:
1.743 raeburn 2754: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2755:
1.910 raeburn 2756: 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.
2757:
1.1121 raeburn 2758: The optional $incdoms is a reference to an array of domains which will be the only available options.
2759:
2760: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2761:
1.1256 raeburn 2762: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2763:
1.35 matthew 2764: =cut
2765:
2766: #-------------------------------------------
1.34 matthew 2767: sub select_dom_form {
1.1256 raeburn 2768: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2769: if ($onchange) {
1.874 raeburn 2770: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2771: }
1.1256 raeburn 2772: if ($disabled) {
2773: $disabled = ' disabled="disabled"';
2774: }
1.1121 raeburn 2775: my (@domains,%exclude);
1.910 raeburn 2776: if (ref($incdoms) eq 'ARRAY') {
2777: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2778: } else {
2779: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2780: }
1.90 www 2781: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2782: if (ref($excdoms) eq 'ARRAY') {
2783: map { $exclude{$_} = 1; } @{$excdoms};
2784: }
1.1256 raeburn 2785: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2786: foreach my $dom (@domains) {
1.1121 raeburn 2787: next if ($exclude{$dom});
1.356 albertel 2788: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2789: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2790: if ($showdomdesc) {
2791: if ($dom ne '') {
2792: my $domdesc = &Apache::lonnet::domain($dom,'description');
2793: if ($domdesc ne '') {
2794: $selectdomain .= ' ('.$domdesc.')';
2795: }
2796: }
2797: }
2798: $selectdomain .= "</option>\n";
1.34 matthew 2799: }
2800: $selectdomain.="</select>";
2801: return $selectdomain;
2802: }
2803:
1.35 matthew 2804: #-------------------------------------------
2805:
1.45 matthew 2806: =pod
2807:
1.648 raeburn 2808: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2809:
1.586 raeburn 2810: input: 4 arguments (two required, two optional) -
2811: $domain - domain of new user
2812: $name - name of form element
2813: $default - Value of 'default' causes a default item to be first
2814: option, and selected by default.
2815: $hide - Value of 'hide' causes hiding of the name of the server,
2816: if 1 server found, or default, if 0 found.
1.594 raeburn 2817: output: returns 2 items:
1.586 raeburn 2818: (a) form element which contains either:
2819: (i) <select name="$name">
2820: <option value="$hostid1">$hostid $servers{$hostid}</option>
2821: <option value="$hostid2">$hostid $servers{$hostid}</option>
2822: </select>
2823: form item if there are multiple library servers in $domain, or
2824: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2825: if there is only one library server in $domain.
2826:
2827: (b) number of library servers found.
2828:
2829: See loncreateuser.pm for example of use.
1.35 matthew 2830:
2831: =cut
2832:
2833: #-------------------------------------------
1.586 raeburn 2834: sub home_server_form_item {
2835: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2836: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2837: my $result;
2838: my $numlib = keys(%servers);
2839: if ($numlib > 1) {
2840: $result .= '<select name="'.$name.'" />'."\n";
2841: if ($default) {
1.804 bisitz 2842: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2843: '</option>'."\n";
2844: }
2845: foreach my $hostid (sort(keys(%servers))) {
2846: $result.= '<option value="'.$hostid.'">'.
2847: $hostid.' '.$servers{$hostid}."</option>\n";
2848: }
2849: $result .= '</select>'."\n";
2850: } elsif ($numlib == 1) {
2851: my $hostid;
2852: foreach my $item (keys(%servers)) {
2853: $hostid = $item;
2854: }
2855: $result .= '<input type="hidden" name="'.$name.'" value="'.
2856: $hostid.'" />';
2857: if (!$hide) {
2858: $result .= $hostid.' '.$servers{$hostid};
2859: }
2860: $result .= "\n";
2861: } elsif ($default) {
2862: $result .= '<input type="hidden" name="'.$name.
2863: '" value="default" />';
2864: if (!$hide) {
2865: $result .= &mt('default');
2866: }
2867: $result .= "\n";
1.33 matthew 2868: }
1.586 raeburn 2869: return ($result,$numlib);
1.33 matthew 2870: }
1.112 bowersj2 2871:
2872: =pod
2873:
1.534 albertel 2874: =back
2875:
1.112 bowersj2 2876: =cut
1.87 matthew 2877:
2878: ###############################################################
1.112 bowersj2 2879: ## Decoding User Agent ##
1.87 matthew 2880: ###############################################################
2881:
2882: =pod
2883:
1.112 bowersj2 2884: =head1 Decoding the User Agent
2885:
2886: =over 4
2887:
2888: =item * &decode_user_agent()
1.87 matthew 2889:
2890: Inputs: $r
2891:
2892: Outputs:
2893:
2894: =over 4
2895:
1.112 bowersj2 2896: =item * $httpbrowser
1.87 matthew 2897:
1.112 bowersj2 2898: =item * $clientbrowser
1.87 matthew 2899:
1.112 bowersj2 2900: =item * $clientversion
1.87 matthew 2901:
1.112 bowersj2 2902: =item * $clientmathml
1.87 matthew 2903:
1.112 bowersj2 2904: =item * $clientunicode
1.87 matthew 2905:
1.112 bowersj2 2906: =item * $clientos
1.87 matthew 2907:
1.1137 raeburn 2908: =item * $clientmobile
2909:
1.1141 raeburn 2910: =item * $clientinfo
2911:
1.1194 raeburn 2912: =item * $clientosversion
2913:
1.87 matthew 2914: =back
2915:
1.157 matthew 2916: =back
2917:
1.87 matthew 2918: =cut
2919:
2920: ###############################################################
2921: ###############################################################
2922: sub decode_user_agent {
1.247 albertel 2923: my ($r)=@_;
1.87 matthew 2924: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2925: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2926: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2927: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2928: my $clientbrowser='unknown';
2929: my $clientversion='0';
2930: my $clientmathml='';
2931: my $clientunicode='0';
1.1137 raeburn 2932: my $clientmobile=0;
1.1194 raeburn 2933: my $clientosversion='';
1.87 matthew 2934: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2935: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2936: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2937: $clientbrowser=$bname;
2938: $httpbrowser=~/$vreg/i;
2939: $clientversion=$1;
2940: $clientmathml=($clientversion>=$minv);
2941: $clientunicode=($clientversion>=$univ);
2942: }
2943: }
2944: my $clientos='unknown';
1.1141 raeburn 2945: my $clientinfo;
1.87 matthew 2946: if (($httpbrowser=~/linux/i) ||
2947: ($httpbrowser=~/unix/i) ||
2948: ($httpbrowser=~/ux/i) ||
2949: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2950: if (($httpbrowser=~/vax/i) ||
2951: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2952: if ($httpbrowser=~/next/i) { $clientos='next'; }
2953: if (($httpbrowser=~/mac/i) ||
2954: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2955: if ($httpbrowser=~/win/i) {
2956: $clientos='win';
2957: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2958: $clientosversion = $1;
2959: }
2960: }
1.87 matthew 2961: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2962: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2963: $clientmobile=lc($1);
2964: }
1.1141 raeburn 2965: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2966: $clientinfo = 'firefox-'.$1;
2967: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2968: $clientinfo = 'chromeframe-'.$1;
2969: }
1.87 matthew 2970: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 2971: $clientunicode,$clientos,$clientmobile,$clientinfo,
2972: $clientosversion);
1.87 matthew 2973: }
2974:
1.32 matthew 2975: ###############################################################
2976: ## Authentication changing form generation subroutines ##
2977: ###############################################################
2978: ##
2979: ## All of the authform_xxxxxxx subroutines take their inputs in a
2980: ## hash, and have reasonable default values.
2981: ##
2982: ## formname = the name given in the <form> tag.
1.35 matthew 2983: #-------------------------------------------
2984:
1.45 matthew 2985: =pod
2986:
1.112 bowersj2 2987: =head1 Authentication Routines
2988:
2989: =over 4
2990:
1.648 raeburn 2991: =item * &authform_xxxxxx()
1.35 matthew 2992:
2993: The authform_xxxxxx subroutines provide javascript and html forms which
2994: handle some of the conveniences required for authentication forms.
2995: This is not an optimal method, but it works.
2996:
2997: =over 4
2998:
1.112 bowersj2 2999: =item * authform_header
1.35 matthew 3000:
1.112 bowersj2 3001: =item * authform_authorwarning
1.35 matthew 3002:
1.112 bowersj2 3003: =item * authform_nochange
1.35 matthew 3004:
1.112 bowersj2 3005: =item * authform_kerberos
1.35 matthew 3006:
1.112 bowersj2 3007: =item * authform_internal
1.35 matthew 3008:
1.112 bowersj2 3009: =item * authform_filesystem
1.35 matthew 3010:
3011: =back
3012:
1.648 raeburn 3013: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3014:
1.35 matthew 3015: =cut
3016:
3017: #-------------------------------------------
1.32 matthew 3018: sub authform_header{
3019: my %in = (
3020: formname => 'cu',
1.80 albertel 3021: kerb_def_dom => '',
1.32 matthew 3022: @_,
3023: );
3024: $in{'formname'} = 'document.' . $in{'formname'};
3025: my $result='';
1.80 albertel 3026:
3027: #---------------------------------------------- Code for upper case translation
3028: my $Javascript_toUpperCase;
3029: unless ($in{kerb_def_dom}) {
3030: $Javascript_toUpperCase =<<"END";
3031: switch (choice) {
3032: case 'krb': currentform.elements[choicearg].value =
3033: currentform.elements[choicearg].value.toUpperCase();
3034: break;
3035: default:
3036: }
3037: END
3038: } else {
3039: $Javascript_toUpperCase = "";
3040: }
3041:
1.165 raeburn 3042: my $radioval = "'nochange'";
1.591 raeburn 3043: if (defined($in{'curr_authtype'})) {
3044: if ($in{'curr_authtype'} ne '') {
3045: $radioval = "'".$in{'curr_authtype'}."arg'";
3046: }
1.174 matthew 3047: }
1.165 raeburn 3048: my $argfield = 'null';
1.591 raeburn 3049: if (defined($in{'mode'})) {
1.165 raeburn 3050: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3051: if (defined($in{'curr_autharg'})) {
3052: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3053: $argfield = "'$in{'curr_autharg'}'";
3054: }
3055: }
3056: }
3057: }
3058:
1.32 matthew 3059: $result.=<<"END";
3060: var current = new Object();
1.165 raeburn 3061: current.radiovalue = $radioval;
3062: current.argfield = $argfield;
1.32 matthew 3063:
3064: function changed_radio(choice,currentform) {
3065: var choicearg = choice + 'arg';
3066: // If a radio button in changed, we need to change the argfield
3067: if (current.radiovalue != choice) {
3068: current.radiovalue = choice;
3069: if (current.argfield != null) {
3070: currentform.elements[current.argfield].value = '';
3071: }
3072: if (choice == 'nochange') {
3073: current.argfield = null;
3074: } else {
3075: current.argfield = choicearg;
3076: switch(choice) {
3077: case 'krb':
3078: currentform.elements[current.argfield].value =
3079: "$in{'kerb_def_dom'}";
3080: break;
3081: default:
3082: break;
3083: }
3084: }
3085: }
3086: return;
3087: }
1.22 www 3088:
1.32 matthew 3089: function changed_text(choice,currentform) {
3090: var choicearg = choice + 'arg';
3091: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3092: $Javascript_toUpperCase
1.32 matthew 3093: // clear old field
3094: if ((current.argfield != choicearg) && (current.argfield != null)) {
3095: currentform.elements[current.argfield].value = '';
3096: }
3097: current.argfield = choicearg;
3098: }
3099: set_auth_radio_buttons(choice,currentform);
3100: return;
1.20 www 3101: }
1.32 matthew 3102:
3103: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3104: var numauthchoices = currentform.login.length;
3105: if (typeof numauthchoices == "undefined") {
3106: return;
3107: }
1.32 matthew 3108: var i=0;
1.986 raeburn 3109: while (i < numauthchoices) {
1.32 matthew 3110: if (currentform.login[i].value == newvalue) { break; }
3111: i++;
3112: }
1.986 raeburn 3113: if (i == numauthchoices) {
1.32 matthew 3114: return;
3115: }
3116: current.radiovalue = newvalue;
3117: currentform.login[i].checked = true;
3118: return;
3119: }
3120: END
3121: return $result;
3122: }
3123:
1.1106 raeburn 3124: sub authform_authorwarning {
1.32 matthew 3125: my $result='';
1.144 matthew 3126: $result='<i>'.
3127: &mt('As a general rule, only authors or co-authors should be '.
3128: 'filesystem authenticated '.
3129: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3130: return $result;
3131: }
3132:
1.1106 raeburn 3133: sub authform_nochange {
1.32 matthew 3134: my %in = (
3135: formname => 'document.cu',
3136: kerb_def_dom => 'MSU.EDU',
3137: @_,
3138: );
1.1106 raeburn 3139: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3140: my $result;
1.1104 raeburn 3141: if (!$authnum) {
1.1105 raeburn 3142: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3143: } else {
3144: $result = '<label>'.&mt('[_1] Do not change login data',
3145: '<input type="radio" name="login" value="nochange" '.
3146: 'checked="checked" onclick="'.
1.281 albertel 3147: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3148: '</label>';
1.586 raeburn 3149: }
1.32 matthew 3150: return $result;
3151: }
3152:
1.591 raeburn 3153: sub authform_kerberos {
1.32 matthew 3154: my %in = (
3155: formname => 'document.cu',
3156: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3157: kerb_def_auth => 'krb4',
1.32 matthew 3158: @_,
3159: );
1.586 raeburn 3160: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
3161: $autharg,$jscall);
1.1106 raeburn 3162: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3163: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3164: $check5 = ' checked="checked"';
1.80 albertel 3165: } else {
1.772 bisitz 3166: $check4 = ' checked="checked"';
1.80 albertel 3167: }
1.165 raeburn 3168: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3169: if (defined($in{'curr_authtype'})) {
3170: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3171: $krbcheck = ' checked="checked"';
1.623 raeburn 3172: if (defined($in{'mode'})) {
3173: if ($in{'mode'} eq 'modifyuser') {
3174: $krbcheck = '';
3175: }
3176: }
1.591 raeburn 3177: if (defined($in{'curr_kerb_ver'})) {
3178: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3179: $check5 = ' checked="checked"';
1.591 raeburn 3180: $check4 = '';
3181: } else {
1.772 bisitz 3182: $check4 = ' checked="checked"';
1.591 raeburn 3183: $check5 = '';
3184: }
1.586 raeburn 3185: }
1.591 raeburn 3186: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3187: $krbarg = $in{'curr_autharg'};
3188: }
1.586 raeburn 3189: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3190: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3191: $result =
3192: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3193: $in{'curr_autharg'},$krbver);
3194: } else {
3195: $result =
3196: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3197: }
3198: return $result;
3199: }
3200: }
3201: } else {
3202: if ($authnum == 1) {
1.784 bisitz 3203: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3204: }
3205: }
1.586 raeburn 3206: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3207: return;
1.587 raeburn 3208: } elsif ($authtype eq '') {
1.591 raeburn 3209: if (defined($in{'mode'})) {
1.587 raeburn 3210: if ($in{'mode'} eq 'modifycourse') {
3211: if ($authnum == 1) {
1.1104 raeburn 3212: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 3213: }
3214: }
3215: }
1.586 raeburn 3216: }
3217: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3218: if ($authtype eq '') {
3219: $authtype = '<input type="radio" name="login" value="krb" '.
3220: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
3221: $krbcheck.' />';
3222: }
3223: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3224: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3225: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3226: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3227: $in{'curr_authtype'} eq 'krb4')) {
3228: $result .= &mt
1.144 matthew 3229: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3230: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3231: '<label>'.$authtype,
1.281 albertel 3232: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3233: 'value="'.$krbarg.'" '.
1.144 matthew 3234: 'onchange="'.$jscall.'" />',
1.281 albertel 3235: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
3236: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
3237: '</label>');
1.586 raeburn 3238: } elsif ($can_assign{'krb4'}) {
3239: $result .= &mt
3240: ('[_1] Kerberos authenticated with domain [_2] '.
3241: '[_3] Version 4 [_4]',
3242: '<label>'.$authtype,
3243: '</label><input type="text" size="10" name="krbarg" '.
3244: 'value="'.$krbarg.'" '.
3245: 'onchange="'.$jscall.'" />',
3246: '<label><input type="hidden" name="krbver" value="4" />',
3247: '</label>');
3248: } elsif ($can_assign{'krb5'}) {
3249: $result .= &mt
3250: ('[_1] Kerberos authenticated with domain [_2] '.
3251: '[_3] Version 5 [_4]',
3252: '<label>'.$authtype,
3253: '</label><input type="text" size="10" name="krbarg" '.
3254: 'value="'.$krbarg.'" '.
3255: 'onchange="'.$jscall.'" />',
3256: '<label><input type="hidden" name="krbver" value="5" />',
3257: '</label>');
3258: }
1.32 matthew 3259: return $result;
3260: }
3261:
1.1106 raeburn 3262: sub authform_internal {
1.586 raeburn 3263: my %in = (
1.32 matthew 3264: formname => 'document.cu',
3265: kerb_def_dom => 'MSU.EDU',
3266: @_,
3267: );
1.586 raeburn 3268: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 3269: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3270: if (defined($in{'curr_authtype'})) {
3271: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3272: if ($can_assign{'int'}) {
1.772 bisitz 3273: $intcheck = 'checked="checked" ';
1.623 raeburn 3274: if (defined($in{'mode'})) {
3275: if ($in{'mode'} eq 'modifyuser') {
3276: $intcheck = '';
3277: }
3278: }
1.591 raeburn 3279: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3280: $intarg = $in{'curr_autharg'};
3281: }
3282: } else {
3283: $result = &mt('Currently internally authenticated.');
3284: return $result;
1.165 raeburn 3285: }
3286: }
1.586 raeburn 3287: } else {
3288: if ($authnum == 1) {
1.784 bisitz 3289: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3290: }
3291: }
3292: if (!$can_assign{'int'}) {
3293: return;
1.587 raeburn 3294: } elsif ($authtype eq '') {
1.591 raeburn 3295: if (defined($in{'mode'})) {
1.587 raeburn 3296: if ($in{'mode'} eq 'modifycourse') {
3297: if ($authnum == 1) {
1.1104 raeburn 3298: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 3299: }
3300: }
3301: }
1.165 raeburn 3302: }
1.586 raeburn 3303: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3304: if ($authtype eq '') {
3305: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
3306: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
3307: }
1.605 bisitz 3308: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 3309: $intarg.'" onchange="'.$jscall.'" />';
3310: $result = &mt
1.144 matthew 3311: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3312: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 3313: $result.="<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 3314: return $result;
3315: }
3316:
1.1104 raeburn 3317: sub authform_local {
1.32 matthew 3318: my %in = (
3319: formname => 'document.cu',
3320: kerb_def_dom => 'MSU.EDU',
3321: @_,
3322: );
1.586 raeburn 3323: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 3324: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3325: if (defined($in{'curr_authtype'})) {
3326: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3327: if ($can_assign{'loc'}) {
1.772 bisitz 3328: $loccheck = 'checked="checked" ';
1.623 raeburn 3329: if (defined($in{'mode'})) {
3330: if ($in{'mode'} eq 'modifyuser') {
3331: $loccheck = '';
3332: }
3333: }
1.591 raeburn 3334: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3335: $locarg = $in{'curr_autharg'};
3336: }
3337: } else {
3338: $result = &mt('Currently using local (institutional) authentication.');
3339: return $result;
1.165 raeburn 3340: }
3341: }
1.586 raeburn 3342: } else {
3343: if ($authnum == 1) {
1.784 bisitz 3344: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3345: }
3346: }
3347: if (!$can_assign{'loc'}) {
3348: return;
1.587 raeburn 3349: } elsif ($authtype eq '') {
1.591 raeburn 3350: if (defined($in{'mode'})) {
1.587 raeburn 3351: if ($in{'mode'} eq 'modifycourse') {
3352: if ($authnum == 1) {
1.1104 raeburn 3353: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 3354: }
3355: }
3356: }
1.165 raeburn 3357: }
1.586 raeburn 3358: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3359: if ($authtype eq '') {
3360: $authtype = '<input type="radio" name="login" value="loc" '.
3361: $loccheck.' onchange="'.$jscall.'" onclick="'.
3362: $jscall.'" />';
3363: }
3364: $autharg = '<input type="text" size="10" name="locarg" value="'.
3365: $locarg.'" onchange="'.$jscall.'" />';
3366: $result = &mt('[_1] Local Authentication with argument [_2]',
3367: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3368: return $result;
3369: }
3370:
1.1106 raeburn 3371: sub authform_filesystem {
1.32 matthew 3372: my %in = (
3373: formname => 'document.cu',
3374: kerb_def_dom => 'MSU.EDU',
3375: @_,
3376: );
1.586 raeburn 3377: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 3378: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3379: if (defined($in{'curr_authtype'})) {
3380: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3381: if ($can_assign{'fsys'}) {
1.772 bisitz 3382: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3383: if (defined($in{'mode'})) {
3384: if ($in{'mode'} eq 'modifyuser') {
3385: $fsyscheck = '';
3386: }
3387: }
1.586 raeburn 3388: } else {
3389: $result = &mt('Currently Filesystem Authenticated.');
3390: return $result;
3391: }
3392: }
3393: } else {
3394: if ($authnum == 1) {
1.784 bisitz 3395: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3396: }
3397: }
3398: if (!$can_assign{'fsys'}) {
3399: return;
1.587 raeburn 3400: } elsif ($authtype eq '') {
1.591 raeburn 3401: if (defined($in{'mode'})) {
1.587 raeburn 3402: if ($in{'mode'} eq 'modifycourse') {
3403: if ($authnum == 1) {
1.1104 raeburn 3404: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 3405: }
3406: }
3407: }
1.586 raeburn 3408: }
3409: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3410: if ($authtype eq '') {
3411: $authtype = '<input type="radio" name="login" value="fsys" '.
3412: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
3413: $jscall.'" />';
3414: }
3415: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
3416: ' onchange="'.$jscall.'" />';
3417: $result = &mt
1.144 matthew 3418: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3419: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 3420: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 3421: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 3422: 'onchange="'.$jscall.'" />');
1.32 matthew 3423: return $result;
3424: }
3425:
1.586 raeburn 3426: sub get_assignable_auth {
3427: my ($dom) = @_;
3428: if ($dom eq '') {
3429: $dom = $env{'request.role.domain'};
3430: }
3431: my %can_assign = (
3432: krb4 => 1,
3433: krb5 => 1,
3434: int => 1,
3435: loc => 1,
3436: );
3437: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3438: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3439: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3440: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3441: my $context;
3442: if ($env{'request.role'} =~ /^au/) {
3443: $context = 'author';
3444: } elsif ($env{'request.role'} =~ /^dc/) {
3445: $context = 'domain';
3446: } elsif ($env{'request.course.id'}) {
3447: $context = 'course';
3448: }
3449: if ($context) {
3450: if (ref($authhash->{$context}) eq 'HASH') {
3451: %can_assign = %{$authhash->{$context}};
3452: }
3453: }
3454: }
3455: }
3456: my $authnum = 0;
3457: foreach my $key (keys(%can_assign)) {
3458: if ($can_assign{$key}) {
3459: $authnum ++;
3460: }
3461: }
3462: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3463: $authnum --;
3464: }
3465: return ($authnum,%can_assign);
3466: }
3467:
1.80 albertel 3468: ###############################################################
3469: ## Get Kerberos Defaults for Domain ##
3470: ###############################################################
3471: ##
3472: ## Returns default kerberos version and an associated argument
3473: ## as listed in file domain.tab. If not listed, provides
3474: ## appropriate default domain and kerberos version.
3475: ##
3476: #-------------------------------------------
3477:
3478: =pod
3479:
1.648 raeburn 3480: =item * &get_kerberos_defaults()
1.80 albertel 3481:
3482: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3483: version and domain. If not found, it defaults to version 4 and the
3484: domain of the server.
1.80 albertel 3485:
1.648 raeburn 3486: =over 4
3487:
1.80 albertel 3488: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3489:
1.648 raeburn 3490: =back
3491:
3492: =back
3493:
1.80 albertel 3494: =cut
3495:
3496: #-------------------------------------------
3497: sub get_kerberos_defaults {
3498: my $domain=shift;
1.641 raeburn 3499: my ($krbdef,$krbdefdom);
3500: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3501: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3502: $krbdef = $domdefaults{'auth_def'};
3503: $krbdefdom = $domdefaults{'auth_arg_def'};
3504: } else {
1.80 albertel 3505: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3506: my $krbdefdom=$1;
3507: $krbdefdom=~tr/a-z/A-Z/;
3508: $krbdef = "krb4";
3509: }
3510: return ($krbdef,$krbdefdom);
3511: }
1.112 bowersj2 3512:
1.32 matthew 3513:
1.46 matthew 3514: ###############################################################
3515: ## Thesaurus Functions ##
3516: ###############################################################
1.20 www 3517:
1.46 matthew 3518: =pod
1.20 www 3519:
1.112 bowersj2 3520: =head1 Thesaurus Functions
3521:
3522: =over 4
3523:
1.648 raeburn 3524: =item * &initialize_keywords()
1.46 matthew 3525:
3526: Initializes the package variable %Keywords if it is empty. Uses the
3527: package variable $thesaurus_db_file.
3528:
3529: =cut
3530:
3531: ###################################################
3532:
3533: sub initialize_keywords {
3534: return 1 if (scalar keys(%Keywords));
3535: # If we are here, %Keywords is empty, so fill it up
3536: # Make sure the file we need exists...
3537: if (! -e $thesaurus_db_file) {
3538: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3539: " failed because it does not exist");
3540: return 0;
3541: }
3542: # Set up the hash as a database
3543: my %thesaurus_db;
3544: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3545: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3546: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3547: $thesaurus_db_file);
3548: return 0;
3549: }
3550: # Get the average number of appearances of a word.
3551: my $avecount = $thesaurus_db{'average.count'};
3552: # Put keywords (those that appear > average) into %Keywords
3553: while (my ($word,$data)=each (%thesaurus_db)) {
3554: my ($count,undef) = split /:/,$data;
3555: $Keywords{$word}++ if ($count > $avecount);
3556: }
3557: untie %thesaurus_db;
3558: # Remove special values from %Keywords.
1.356 albertel 3559: foreach my $value ('total.count','average.count') {
3560: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3561: }
1.46 matthew 3562: return 1;
3563: }
3564:
3565: ###################################################
3566:
3567: =pod
3568:
1.648 raeburn 3569: =item * &keyword($word)
1.46 matthew 3570:
3571: Returns true if $word is a keyword. A keyword is a word that appears more
3572: than the average number of times in the thesaurus database. Calls
3573: &initialize_keywords
3574:
3575: =cut
3576:
3577: ###################################################
1.20 www 3578:
3579: sub keyword {
1.46 matthew 3580: return if (!&initialize_keywords());
3581: my $word=lc(shift());
3582: $word=~s/\W//g;
3583: return exists($Keywords{$word});
1.20 www 3584: }
1.46 matthew 3585:
3586: ###############################################################
3587:
3588: =pod
1.20 www 3589:
1.648 raeburn 3590: =item * &get_related_words()
1.46 matthew 3591:
1.160 matthew 3592: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3593: an array of words. If the keyword is not in the thesaurus, an empty array
3594: will be returned. The order of the words returned is determined by the
3595: database which holds them.
3596:
3597: Uses global $thesaurus_db_file.
3598:
1.1057 foxr 3599:
1.46 matthew 3600: =cut
3601:
3602: ###############################################################
3603: sub get_related_words {
3604: my $keyword = shift;
3605: my %thesaurus_db;
3606: if (! -e $thesaurus_db_file) {
3607: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3608: "failed because the file does not exist");
3609: return ();
3610: }
3611: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3612: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3613: return ();
3614: }
3615: my @Words=();
1.429 www 3616: my $count=0;
1.46 matthew 3617: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3618: # The first element is the number of times
3619: # the word appears. We do not need it now.
1.429 www 3620: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3621: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3622: my $threshold=$mostfrequentcount/10;
3623: foreach my $possibleword (@RelatedWords) {
3624: my ($word,$wordcount)=split(/\,/,$possibleword);
3625: if ($wordcount>$threshold) {
3626: push(@Words,$word);
3627: $count++;
3628: if ($count>10) { last; }
3629: }
1.20 www 3630: }
3631: }
1.46 matthew 3632: untie %thesaurus_db;
3633: return @Words;
1.14 harris41 3634: }
1.1090 foxr 3635: ###############################################################
3636: #
3637: # Spell checking
3638: #
3639:
3640: =pod
3641:
1.1142 raeburn 3642: =back
3643:
1.1090 foxr 3644: =head1 Spell checking
3645:
3646: =over 4
3647:
3648: =item * &check_spelling($wordlist $language)
3649:
3650: Takes a string containing words and feeds it to an external
3651: spellcheck program via a pipeline. Returns a string containing
3652: them mis-spelled words.
3653:
3654: Parameters:
3655:
3656: =over 4
3657:
3658: =item - $wordlist
3659:
3660: String that will be fed into the spellcheck program.
3661:
3662: =item - $language
3663:
3664: Language string that specifies the language for which the spell
3665: check will be performed.
3666:
3667: =back
3668:
3669: =back
3670:
3671: Note: This sub assumes that aspell is installed.
3672:
3673:
3674: =cut
3675:
1.46 matthew 3676:
1.1090 foxr 3677: sub check_spelling {
3678: my ($wordlist, $language) = @_;
1.1091 foxr 3679: my @misspellings;
3680:
3681: # Generate the speller and set the langauge.
3682: # if explicitly selected:
1.1090 foxr 3683:
1.1091 foxr 3684: my $speller = Text::Aspell->new;
1.1090 foxr 3685: if ($language) {
1.1091 foxr 3686: $speller->set_option('lang', $language);
1.1090 foxr 3687: }
3688:
1.1091 foxr 3689: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3690:
1.1091 foxr 3691: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3692:
1.1091 foxr 3693: foreach my $word (@words) {
3694: if(! $speller->check($word)) {
3695: push(@misspellings, $word);
1.1090 foxr 3696: }
3697: }
1.1091 foxr 3698: return join(' ', @misspellings);
3699:
1.1090 foxr 3700: }
3701:
1.61 www 3702: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3703: =pod
3704:
1.112 bowersj2 3705: =head1 User Name Functions
3706:
3707: =over 4
3708:
1.648 raeburn 3709: =item * &plainname($uname,$udom,$first)
1.81 albertel 3710:
1.112 bowersj2 3711: Takes a users logon name and returns it as a string in
1.226 albertel 3712: "first middle last generation" form
3713: if $first is set to 'lastname' then it returns it as
3714: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3715:
3716: =cut
1.61 www 3717:
1.295 www 3718:
1.81 albertel 3719: ###############################################################
1.61 www 3720: sub plainname {
1.226 albertel 3721: my ($uname,$udom,$first)=@_;
1.537 albertel 3722: return if (!defined($uname) || !defined($udom));
1.295 www 3723: my %names=&getnames($uname,$udom);
1.226 albertel 3724: my $name=&Apache::lonnet::format_name($names{'firstname'},
3725: $names{'middlename'},
3726: $names{'lastname'},
3727: $names{'generation'},$first);
3728: $name=~s/^\s+//;
1.62 www 3729: $name=~s/\s+$//;
3730: $name=~s/\s+/ /g;
1.353 albertel 3731: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3732: return $name;
1.61 www 3733: }
1.66 www 3734:
3735: # -------------------------------------------------------------------- Nickname
1.81 albertel 3736: =pod
3737:
1.648 raeburn 3738: =item * &nickname($uname,$udom)
1.81 albertel 3739:
3740: Gets a users name and returns it as a string as
3741:
3742: ""nickname""
1.66 www 3743:
1.81 albertel 3744: if the user has a nickname or
3745:
3746: "first middle last generation"
3747:
3748: if the user does not
3749:
3750: =cut
1.66 www 3751:
3752: sub nickname {
3753: my ($uname,$udom)=@_;
1.537 albertel 3754: return if (!defined($uname) || !defined($udom));
1.295 www 3755: my %names=&getnames($uname,$udom);
1.68 albertel 3756: my $name=$names{'nickname'};
1.66 www 3757: if ($name) {
3758: $name='"'.$name.'"';
3759: } else {
3760: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3761: $names{'lastname'}.' '.$names{'generation'};
3762: $name=~s/\s+$//;
3763: $name=~s/\s+/ /g;
3764: }
3765: return $name;
3766: }
3767:
1.295 www 3768: sub getnames {
3769: my ($uname,$udom)=@_;
1.537 albertel 3770: return if (!defined($uname) || !defined($udom));
1.433 albertel 3771: if ($udom eq 'public' && $uname eq 'public') {
3772: return ('lastname' => &mt('Public'));
3773: }
1.295 www 3774: my $id=$uname.':'.$udom;
3775: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3776: if ($cached) {
3777: return %{$names};
3778: } else {
3779: my %loadnames=&Apache::lonnet::get('environment',
3780: ['firstname','middlename','lastname','generation','nickname'],
3781: $udom,$uname);
3782: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3783: return %loadnames;
3784: }
3785: }
1.61 www 3786:
1.542 raeburn 3787: # -------------------------------------------------------------------- getemails
1.648 raeburn 3788:
1.542 raeburn 3789: =pod
3790:
1.648 raeburn 3791: =item * &getemails($uname,$udom)
1.542 raeburn 3792:
3793: Gets a user's email information and returns it as a hash with keys:
3794: notification, critnotification, permanentemail
3795:
3796: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3797: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3798:
1.648 raeburn 3799:
1.542 raeburn 3800: =cut
3801:
1.648 raeburn 3802:
1.466 albertel 3803: sub getemails {
3804: my ($uname,$udom)=@_;
3805: if ($udom eq 'public' && $uname eq 'public') {
3806: return;
3807: }
1.467 www 3808: if (!$udom) { $udom=$env{'user.domain'}; }
3809: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3810: my $id=$uname.':'.$udom;
3811: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3812: if ($cached) {
3813: return %{$names};
3814: } else {
3815: my %loadnames=&Apache::lonnet::get('environment',
3816: ['notification','critnotification',
3817: 'permanentemail'],
3818: $udom,$uname);
3819: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3820: return %loadnames;
3821: }
3822: }
3823:
1.551 albertel 3824: sub flush_email_cache {
3825: my ($uname,$udom)=@_;
3826: if (!$udom) { $udom =$env{'user.domain'}; }
3827: if (!$uname) { $uname=$env{'user.name'}; }
3828: return if ($udom eq 'public' && $uname eq 'public');
3829: my $id=$uname.':'.$udom;
3830: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3831: }
3832:
1.728 raeburn 3833: # -------------------------------------------------------------------- getlangs
3834:
3835: =pod
3836:
3837: =item * &getlangs($uname,$udom)
3838:
3839: Gets a user's language preference and returns it as a hash with key:
3840: language.
3841:
3842: =cut
3843:
3844:
3845: sub getlangs {
3846: my ($uname,$udom) = @_;
3847: if (!$udom) { $udom =$env{'user.domain'}; }
3848: if (!$uname) { $uname=$env{'user.name'}; }
3849: my $id=$uname.':'.$udom;
3850: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3851: if ($cached) {
3852: return %{$langs};
3853: } else {
3854: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3855: $udom,$uname);
3856: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3857: return %loadlangs;
3858: }
3859: }
3860:
3861: sub flush_langs_cache {
3862: my ($uname,$udom)=@_;
3863: if (!$udom) { $udom =$env{'user.domain'}; }
3864: if (!$uname) { $uname=$env{'user.name'}; }
3865: return if ($udom eq 'public' && $uname eq 'public');
3866: my $id=$uname.':'.$udom;
3867: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3868: }
3869:
1.61 www 3870: # ------------------------------------------------------------------ Screenname
1.81 albertel 3871:
3872: =pod
3873:
1.648 raeburn 3874: =item * &screenname($uname,$udom)
1.81 albertel 3875:
3876: Gets a users screenname and returns it as a string
3877:
3878: =cut
1.61 www 3879:
3880: sub screenname {
3881: my ($uname,$udom)=@_;
1.258 albertel 3882: if ($uname eq $env{'user.name'} &&
3883: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3884: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3885: return $names{'screenname'};
1.62 www 3886: }
3887:
1.212 albertel 3888:
1.802 bisitz 3889: # ------------------------------------------------------------- Confirm Wrapper
3890: =pod
3891:
1.1142 raeburn 3892: =item * &confirmwrapper($message)
1.802 bisitz 3893:
3894: Wrap messages about completion of operation in box
3895:
3896: =cut
3897:
3898: sub confirmwrapper {
3899: my ($message)=@_;
3900: if ($message) {
3901: return "\n".'<div class="LC_confirm_box">'."\n"
3902: .$message."\n"
3903: .'</div>'."\n";
3904: } else {
3905: return $message;
3906: }
3907: }
3908:
1.62 www 3909: # ------------------------------------------------------------- Message Wrapper
3910:
3911: sub messagewrapper {
1.369 www 3912: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3913: return
1.441 albertel 3914: '<a href="/adm/email?compose=individual&'.
3915: 'recname='.$username.'&recdom='.$domain.
3916: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3917: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3918: }
1.802 bisitz 3919:
1.74 www 3920: # --------------------------------------------------------------- Notes Wrapper
3921:
3922: sub noteswrapper {
3923: my ($link,$un,$do)=@_;
3924: return
1.896 amueller 3925: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3926: }
1.802 bisitz 3927:
1.62 www 3928: # ------------------------------------------------------------- Aboutme Wrapper
3929:
3930: sub aboutmewrapper {
1.1070 raeburn 3931: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3932: if (!defined($username) && !defined($domain)) {
3933: return;
3934: }
1.1096 raeburn 3935: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3936: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3937: }
3938:
3939: # ------------------------------------------------------------ Syllabus Wrapper
3940:
3941: sub syllabuswrapper {
1.707 bisitz 3942: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3943: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3944: }
1.14 harris41 3945:
1.802 bisitz 3946: # -----------------------------------------------------------------------------
3947:
1.208 matthew 3948: sub track_student_link {
1.887 raeburn 3949: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3950: my $link ="/adm/trackstudent?";
1.208 matthew 3951: my $title = 'View recent activity';
3952: if (defined($sname) && $sname !~ /^\s*$/ &&
3953: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3954: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3955: $title .= ' of this student';
1.268 albertel 3956: }
1.208 matthew 3957: if (defined($target) && $target !~ /^\s*$/) {
3958: $target = qq{target="$target"};
3959: } else {
3960: $target = '';
3961: }
1.268 albertel 3962: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3963: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3964: $title = &mt($title);
3965: $linktext = &mt($linktext);
1.448 albertel 3966: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3967: &help_open_topic('View_recent_activity');
1.208 matthew 3968: }
3969:
1.781 raeburn 3970: sub slot_reservations_link {
3971: my ($linktext,$sname,$sdom,$target) = @_;
3972: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3973: my $title = 'View slot reservation history';
3974: if (defined($sname) && $sname !~ /^\s*$/ &&
3975: defined($sdom) && $sdom !~ /^\s*$/) {
3976: $link .= "&uname=$sname&udom=$sdom";
3977: $title .= ' of this student';
3978: }
3979: if (defined($target) && $target !~ /^\s*$/) {
3980: $target = qq{target="$target"};
3981: } else {
3982: $target = '';
3983: }
3984: $title = &mt($title);
3985: $linktext = &mt($linktext);
3986: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3987: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3988:
3989: }
3990:
1.508 www 3991: # ===================================================== Display a student photo
3992:
3993:
1.509 albertel 3994: sub student_image_tag {
1.508 www 3995: my ($domain,$user)=@_;
3996: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3997: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3998: return '<img src="'.$imgsrc.'" align="right" />';
3999: } else {
4000: return '';
4001: }
4002: }
4003:
1.112 bowersj2 4004: =pod
4005:
4006: =back
4007:
4008: =head1 Access .tab File Data
4009:
4010: =over 4
4011:
1.648 raeburn 4012: =item * &languageids()
1.112 bowersj2 4013:
4014: returns list of all language ids
4015:
4016: =cut
4017:
1.14 harris41 4018: sub languageids {
1.16 harris41 4019: return sort(keys(%language));
1.14 harris41 4020: }
4021:
1.112 bowersj2 4022: =pod
4023:
1.648 raeburn 4024: =item * &languagedescription()
1.112 bowersj2 4025:
4026: returns description of a specified language id
4027:
4028: =cut
4029:
1.14 harris41 4030: sub languagedescription {
1.125 www 4031: my $code=shift;
4032: return ($supported_language{$code}?'* ':'').
4033: $language{$code}.
1.126 www 4034: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4035: }
4036:
1.1048 foxr 4037: =pod
4038:
4039: =item * &plainlanguagedescription
4040:
4041: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4042: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4043:
4044: =cut
4045:
1.145 www 4046: sub plainlanguagedescription {
4047: my $code=shift;
4048: return $language{$code};
4049: }
4050:
1.1048 foxr 4051: =pod
4052:
4053: =item * &supportedlanguagecode
4054:
4055: Returns the supported language code (e.g. sptutf maps to pt) given a language
4056: code.
4057:
4058: =cut
4059:
1.145 www 4060: sub supportedlanguagecode {
4061: my $code=shift;
4062: return $supported_language{$code};
1.97 www 4063: }
4064:
1.112 bowersj2 4065: =pod
4066:
1.1048 foxr 4067: =item * &latexlanguage()
4068:
4069: Given a language key code returns the correspondnig language to use
4070: to select the correct hyphenation on LaTeX printouts. This is undef if there
4071: is no supported hyphenation for the language code.
4072:
4073: =cut
4074:
4075: sub latexlanguage {
4076: my $code = shift;
4077: return $latex_language{$code};
4078: }
4079:
4080: =pod
4081:
4082: =item * &latexhyphenation()
4083:
4084: Same as above but what's supplied is the language as it might be stored
4085: in the metadata.
4086:
4087: =cut
4088:
4089: sub latexhyphenation {
4090: my $key = shift;
4091: return $latex_language_bykey{$key};
4092: }
4093:
4094: =pod
4095:
1.648 raeburn 4096: =item * ©rightids()
1.112 bowersj2 4097:
4098: returns list of all copyrights
4099:
4100: =cut
4101:
4102: sub copyrightids {
4103: return sort(keys(%cprtag));
4104: }
4105:
4106: =pod
4107:
1.648 raeburn 4108: =item * ©rightdescription()
1.112 bowersj2 4109:
4110: returns description of a specified copyright id
4111:
4112: =cut
4113:
4114: sub copyrightdescription {
1.166 www 4115: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4116: }
1.197 matthew 4117:
4118: =pod
4119:
1.648 raeburn 4120: =item * &source_copyrightids()
1.192 taceyjo1 4121:
4122: returns list of all source copyrights
4123:
4124: =cut
4125:
4126: sub source_copyrightids {
4127: return sort(keys(%scprtag));
4128: }
4129:
4130: =pod
4131:
1.648 raeburn 4132: =item * &source_copyrightdescription()
1.192 taceyjo1 4133:
4134: returns description of a specified source copyright id
4135:
4136: =cut
4137:
4138: sub source_copyrightdescription {
4139: return &mt($scprtag{shift(@_)});
4140: }
1.112 bowersj2 4141:
4142: =pod
4143:
1.648 raeburn 4144: =item * &filecategories()
1.112 bowersj2 4145:
4146: returns list of all file categories
4147:
4148: =cut
4149:
4150: sub filecategories {
4151: return sort(keys(%category_extensions));
4152: }
4153:
4154: =pod
4155:
1.648 raeburn 4156: =item * &filecategorytypes()
1.112 bowersj2 4157:
4158: returns list of file types belonging to a given file
4159: category
4160:
4161: =cut
4162:
4163: sub filecategorytypes {
1.356 albertel 4164: my ($cat) = @_;
1.1248 raeburn 4165: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4166: return @{$category_extensions{lc($cat)}};
4167: } else {
4168: return ();
4169: }
1.112 bowersj2 4170: }
4171:
4172: =pod
4173:
1.648 raeburn 4174: =item * &fileembstyle()
1.112 bowersj2 4175:
4176: returns embedding style for a specified file type
4177:
4178: =cut
4179:
4180: sub fileembstyle {
4181: return $fe{lc(shift(@_))};
1.169 www 4182: }
4183:
1.351 www 4184: sub filemimetype {
4185: return $fm{lc(shift(@_))};
4186: }
4187:
1.169 www 4188:
4189: sub filecategoryselect {
4190: my ($name,$value)=@_;
1.189 matthew 4191: return &select_form($value,$name,
1.970 raeburn 4192: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4193: }
4194:
4195: =pod
4196:
1.648 raeburn 4197: =item * &filedescription()
1.112 bowersj2 4198:
4199: returns description for a specified file type
4200:
4201: =cut
4202:
4203: sub filedescription {
1.188 matthew 4204: my $file_description = $fd{lc(shift())};
4205: $file_description =~ s:([\[\]]):~$1:g;
4206: return &mt($file_description);
1.112 bowersj2 4207: }
4208:
4209: =pod
4210:
1.648 raeburn 4211: =item * &filedescriptionex()
1.112 bowersj2 4212:
4213: returns description for a specified file type with
4214: extra formatting
4215:
4216: =cut
4217:
4218: sub filedescriptionex {
4219: my $ex=shift;
1.188 matthew 4220: my $file_description = $fd{lc($ex)};
4221: $file_description =~ s:([\[\]]):~$1:g;
4222: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4223: }
4224:
4225: # End of .tab access
4226: =pod
4227:
4228: =back
4229:
4230: =cut
4231:
4232: # ------------------------------------------------------------------ File Types
4233: sub fileextensions {
4234: return sort(keys(%fe));
4235: }
4236:
1.97 www 4237: # ----------------------------------------------------------- Display Languages
4238: # returns a hash with all desired display languages
4239: #
4240:
4241: sub display_languages {
4242: my %languages=();
1.695 raeburn 4243: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4244: $languages{$lang}=1;
1.97 www 4245: }
4246: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4247: if ($env{'form.displaylanguage'}) {
1.356 albertel 4248: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4249: $languages{$lang}=1;
1.97 www 4250: }
4251: }
4252: return %languages;
1.14 harris41 4253: }
4254:
1.582 albertel 4255: sub languages {
4256: my ($possible_langs) = @_;
1.695 raeburn 4257: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4258: if (!ref($possible_langs)) {
4259: if( wantarray ) {
4260: return @preferred_langs;
4261: } else {
4262: return $preferred_langs[0];
4263: }
4264: }
4265: my %possibilities = map { $_ => 1 } (@$possible_langs);
4266: my @preferred_possibilities;
4267: foreach my $preferred_lang (@preferred_langs) {
4268: if (exists($possibilities{$preferred_lang})) {
4269: push(@preferred_possibilities, $preferred_lang);
4270: }
4271: }
4272: if( wantarray ) {
4273: return @preferred_possibilities;
4274: }
4275: return $preferred_possibilities[0];
4276: }
4277:
1.742 raeburn 4278: sub user_lang {
4279: my ($touname,$toudom,$fromcid) = @_;
4280: my @userlangs;
4281: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4282: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4283: $env{'course.'.$fromcid.'.languages'}));
4284: } else {
4285: my %langhash = &getlangs($touname,$toudom);
4286: if ($langhash{'languages'} ne '') {
4287: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4288: } else {
4289: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4290: if ($domdefs{'lang_def'} ne '') {
4291: @userlangs = ($domdefs{'lang_def'});
4292: }
4293: }
4294: }
4295: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4296: my $user_lh = Apache::localize->get_handle(@languages);
4297: return $user_lh;
4298: }
4299:
4300:
1.112 bowersj2 4301: ###############################################################
4302: ## Student Answer Attempts ##
4303: ###############################################################
4304:
4305: =pod
4306:
4307: =head1 Alternate Problem Views
4308:
4309: =over 4
4310:
1.648 raeburn 4311: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4312: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4313:
4314: Return string with previous attempt on problem. Arguments:
4315:
4316: =over 4
4317:
4318: =item * $symb: Problem, including path
4319:
4320: =item * $username: username of the desired student
4321:
4322: =item * $domain: domain of the desired student
1.14 harris41 4323:
1.112 bowersj2 4324: =item * $course: Course ID
1.14 harris41 4325:
1.112 bowersj2 4326: =item * $getattempt: Leave blank for all attempts, otherwise put
4327: something
1.14 harris41 4328:
1.112 bowersj2 4329: =item * $regexp: if string matches this regexp, the string will be
4330: sent to $gradesub
1.14 harris41 4331:
1.112 bowersj2 4332: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4333:
1.1199 raeburn 4334: =item * $usec: section of the desired student
4335:
4336: =item * $identifier: counter for student (multiple students one problem) or
4337: problem (one student; whole sequence).
4338:
1.112 bowersj2 4339: =back
1.14 harris41 4340:
1.112 bowersj2 4341: The output string is a table containing all desired attempts, if any.
1.16 harris41 4342:
1.112 bowersj2 4343: =cut
1.1 albertel 4344:
4345: sub get_previous_attempt {
1.1199 raeburn 4346: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4347: my $prevattempts='';
1.43 ng 4348: no strict 'refs';
1.1 albertel 4349: if ($symb) {
1.3 albertel 4350: my (%returnhash)=
4351: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4352: if ($returnhash{'version'}) {
4353: my %lasthash=();
4354: my $version;
4355: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4356: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4357: if ($key =~ /\.rawrndseed$/) {
4358: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4359: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4360: } else {
4361: $lasthash{$key}=$returnhash{$version.':'.$key};
4362: }
1.19 harris41 4363: }
1.1 albertel 4364: }
1.596 albertel 4365: $prevattempts=&start_data_table().&start_data_table_header_row();
4366: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4367: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4368: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4369: foreach my $key (sort(keys(%lasthash))) {
4370: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4371: if ($#parts > 0) {
1.31 albertel 4372: my $data=$parts[-1];
1.989 raeburn 4373: next if ($data eq 'foilorder');
1.31 albertel 4374: pop(@parts);
1.1010 www 4375: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4376: if ($data eq 'type') {
4377: unless ($showsurv) {
4378: my $id = join(',',@parts);
4379: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4380: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4381: $lasthidden{$ign.'.'.$id} = 1;
4382: }
1.945 raeburn 4383: }
1.1199 raeburn 4384: if ($identifier ne '') {
4385: my $id = join(',',@parts);
4386: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4387: $domain,$username,$usec,undef,$course) =~ /^no/) {
4388: $hidestatus{$ign.'.'.$id} = 1;
4389: }
4390: }
4391: } elsif ($data eq 'regrader') {
4392: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4393: my $id = join(',',@parts);
4394: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4395: }
1.1010 www 4396: }
1.31 albertel 4397: } else {
1.41 ng 4398: if ($#parts == 0) {
4399: $prevattempts.='<th>'.$parts[0].'</th>';
4400: } else {
4401: $prevattempts.='<th>'.$ign.'</th>';
4402: }
1.31 albertel 4403: }
1.16 harris41 4404: }
1.596 albertel 4405: $prevattempts.=&end_data_table_header_row();
1.40 ng 4406: if ($getattempt eq '') {
1.1199 raeburn 4407: my (%solved,%resets,%probstatus);
1.1200 raeburn 4408: if (($identifier ne '') && (keys(%regraded) > 0)) {
4409: for ($version=1;$version<=$returnhash{'version'};$version++) {
4410: foreach my $id (keys(%regraded)) {
4411: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4412: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4413: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4414: push(@{$resets{$id}},$version);
1.1199 raeburn 4415: }
4416: }
4417: }
1.1200 raeburn 4418: }
4419: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4420: my (@hidden,@unsolved);
1.945 raeburn 4421: if (%typeparts) {
4422: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4423: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4424: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4425: push(@hidden,$id);
1.1199 raeburn 4426: } elsif ($identifier ne '') {
4427: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4428: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4429: ($hidestatus{$id})) {
1.1200 raeburn 4430: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4431: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4432: push(@{$solved{$id}},$version);
4433: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4434: (ref($solved{$id}) eq 'ARRAY')) {
4435: my $skip;
4436: if (ref($resets{$id}) eq 'ARRAY') {
4437: foreach my $reset (@{$resets{$id}}) {
4438: if ($reset > $solved{$id}[-1]) {
4439: $skip=1;
4440: last;
4441: }
4442: }
4443: }
4444: unless ($skip) {
4445: my ($ign,$partslist) = split(/\./,$id,2);
4446: push(@unsolved,$partslist);
4447: }
4448: }
4449: }
1.945 raeburn 4450: }
4451: }
4452: }
4453: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4454: '<td>'.&mt('Transaction [_1]',$version);
4455: if (@unsolved) {
4456: $prevattempts .= '<span class="LC_nobreak"><label>'.
4457: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4458: &mt('Hide').'</label></span>';
4459: }
4460: $prevattempts .= '</td>';
1.945 raeburn 4461: if (@hidden) {
4462: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4463: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4464: my $hide;
4465: foreach my $id (@hidden) {
4466: if ($key =~ /^\Q$id\E/) {
4467: $hide = 1;
4468: last;
4469: }
4470: }
4471: if ($hide) {
4472: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4473: if (($data eq 'award') || ($data eq 'awarddetail')) {
4474: my $value = &format_previous_attempt_value($key,
4475: $returnhash{$version.':'.$key});
1.1173 kruse 4476: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4477: } else {
4478: $prevattempts.='<td> </td>';
4479: }
4480: } else {
4481: if ($key =~ /\./) {
1.1212 raeburn 4482: my $value = $returnhash{$version.':'.$key};
4483: if ($key =~ /\.rndseed$/) {
4484: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4485: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4486: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4487: }
4488: }
4489: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4490: ' </td>';
1.945 raeburn 4491: } else {
4492: $prevattempts.='<td> </td>';
4493: }
4494: }
4495: }
4496: } else {
4497: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4498: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4499: my $value = $returnhash{$version.':'.$key};
4500: if ($key =~ /\.rndseed$/) {
4501: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4502: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4503: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4504: }
4505: }
4506: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4507: ' </td>';
1.945 raeburn 4508: }
4509: }
4510: $prevattempts.=&end_data_table_row();
1.40 ng 4511: }
1.1 albertel 4512: }
1.945 raeburn 4513: my @currhidden = keys(%lasthidden);
1.596 albertel 4514: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4515: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4516: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4517: if (%typeparts) {
4518: my $hidden;
4519: foreach my $id (@currhidden) {
4520: if ($key =~ /^\Q$id\E/) {
4521: $hidden = 1;
4522: last;
4523: }
4524: }
4525: if ($hidden) {
4526: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4527: if (($data eq 'award') || ($data eq 'awarddetail')) {
4528: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4529: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4530: $value = &$gradesub($value);
4531: }
1.1173 kruse 4532: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4533: } else {
4534: $prevattempts.='<td> </td>';
4535: }
4536: } else {
4537: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4538: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4539: $value = &$gradesub($value);
4540: }
1.1173 kruse 4541: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4542: }
4543: } else {
4544: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4545: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4546: $value = &$gradesub($value);
4547: }
1.1173 kruse 4548: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4549: }
1.16 harris41 4550: }
1.596 albertel 4551: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4552: } else {
1.596 albertel 4553: $prevattempts=
4554: &start_data_table().&start_data_table_row().
4555: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4556: &end_data_table_row().&end_data_table();
1.1 albertel 4557: }
4558: } else {
1.596 albertel 4559: $prevattempts=
4560: &start_data_table().&start_data_table_row().
4561: '<td>'.&mt('No data.').'</td>'.
4562: &end_data_table_row().&end_data_table();
1.1 albertel 4563: }
1.10 albertel 4564: }
4565:
1.581 albertel 4566: sub format_previous_attempt_value {
4567: my ($key,$value) = @_;
1.1011 www 4568: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4569: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4570: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4571: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4572: } elsif ($key =~ /answerstring$/) {
4573: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4574: my @answer = %answers;
4575: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4576: my @anskeys = sort(keys(%answers));
4577: if (@anskeys == 1) {
4578: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4579: if ($answer =~ m{\0}) {
4580: $answer =~ s{\0}{,}g;
1.988 raeburn 4581: }
4582: my $tag_internal_answer_name = 'INTERNAL';
4583: if ($anskeys[0] eq $tag_internal_answer_name) {
4584: $value = $answer;
4585: } else {
4586: $value = $anskeys[0].'='.$answer;
4587: }
4588: } else {
4589: foreach my $ans (@anskeys) {
4590: my $answer = $answers{$ans};
1.1001 raeburn 4591: if ($answer =~ m{\0}) {
4592: $answer =~ s{\0}{,}g;
1.988 raeburn 4593: }
4594: $value .= $ans.'='.$answer.'<br />';;
4595: }
4596: }
1.581 albertel 4597: } else {
1.1173 kruse 4598: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4599: }
4600: return $value;
4601: }
4602:
4603:
1.107 albertel 4604: sub relative_to_absolute {
4605: my ($url,$output)=@_;
4606: my $parser=HTML::TokeParser->new(\$output);
4607: my $token;
4608: my $thisdir=$url;
4609: my @rlinks=();
4610: while ($token=$parser->get_token) {
4611: if ($token->[0] eq 'S') {
4612: if ($token->[1] eq 'a') {
4613: if ($token->[2]->{'href'}) {
4614: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4615: }
4616: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4617: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4618: } elsif ($token->[1] eq 'base') {
4619: $thisdir=$token->[2]->{'href'};
4620: }
4621: }
4622: }
4623: $thisdir=~s-/[^/]*$--;
1.356 albertel 4624: foreach my $link (@rlinks) {
1.726 raeburn 4625: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4626: ($link=~/^\//) ||
4627: ($link=~/^javascript:/i) ||
4628: ($link=~/^mailto:/i) ||
4629: ($link=~/^\#/)) {
4630: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4631: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4632: }
4633: }
4634: # -------------------------------------------------- Deal with Applet codebases
4635: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4636: return $output;
4637: }
4638:
1.112 bowersj2 4639: =pod
4640:
1.648 raeburn 4641: =item * &get_student_view()
1.112 bowersj2 4642:
4643: show a snapshot of what student was looking at
4644:
4645: =cut
4646:
1.10 albertel 4647: sub get_student_view {
1.186 albertel 4648: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4649: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4650: my (%form);
1.10 albertel 4651: my @elements=('symb','courseid','domain','username');
4652: foreach my $element (@elements) {
1.186 albertel 4653: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4654: }
1.186 albertel 4655: if (defined($moreenv)) {
4656: %form=(%form,%{$moreenv});
4657: }
1.236 albertel 4658: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4659: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4660: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4661: $userview=~s/\<body[^\>]*\>//gi;
4662: $userview=~s/\<\/body\>//gi;
4663: $userview=~s/\<html\>//gi;
4664: $userview=~s/\<\/html\>//gi;
4665: $userview=~s/\<head\>//gi;
4666: $userview=~s/\<\/head\>//gi;
4667: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4668: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4669: if (wantarray) {
4670: return ($userview,$response);
4671: } else {
4672: return $userview;
4673: }
4674: }
4675:
4676: sub get_student_view_with_retries {
4677: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4678:
4679: my $ok = 0; # True if we got a good response.
4680: my $content;
4681: my $response;
4682:
4683: # Try to get the student_view done. within the retries count:
4684:
4685: do {
4686: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4687: $ok = $response->is_success;
4688: if (!$ok) {
4689: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4690: }
4691: $retries--;
4692: } while (!$ok && ($retries > 0));
4693:
4694: if (!$ok) {
4695: $content = ''; # On error return an empty content.
4696: }
1.651 www 4697: if (wantarray) {
4698: return ($content, $response);
4699: } else {
4700: return $content;
4701: }
1.11 albertel 4702: }
4703:
1.112 bowersj2 4704: =pod
4705:
1.648 raeburn 4706: =item * &get_student_answers()
1.112 bowersj2 4707:
4708: show a snapshot of how student was answering problem
4709:
4710: =cut
4711:
1.11 albertel 4712: sub get_student_answers {
1.100 sakharuk 4713: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4714: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4715: my (%moreenv);
1.11 albertel 4716: my @elements=('symb','courseid','domain','username');
4717: foreach my $element (@elements) {
1.186 albertel 4718: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4719: }
1.186 albertel 4720: $moreenv{'grade_target'}='answer';
4721: %moreenv=(%form,%moreenv);
1.497 raeburn 4722: $feedurl = &Apache::lonnet::clutter($feedurl);
4723: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4724: return $userview;
1.1 albertel 4725: }
1.116 albertel 4726:
4727: =pod
4728:
4729: =item * &submlink()
4730:
1.242 albertel 4731: Inputs: $text $uname $udom $symb $target
1.116 albertel 4732:
4733: Returns: A link to grades.pm such as to see the SUBM view of a student
4734:
4735: =cut
4736:
4737: ###############################################
4738: sub submlink {
1.242 albertel 4739: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4740: if (!($uname && $udom)) {
4741: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4742: &Apache::lonnet::whichuser($symb);
1.116 albertel 4743: if (!$symb) { $symb=$cursymb; }
4744: }
1.254 matthew 4745: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4746: $symb=&escape($symb);
1.960 bisitz 4747: if ($target) { $target=" target=\"$target\""; }
4748: return
4749: '<a href="/adm/grades?command=submission'.
4750: '&symb='.$symb.
4751: '&student='.$uname.
4752: '&userdom='.$udom.'"'.
4753: $target.'>'.$text.'</a>';
1.242 albertel 4754: }
4755: ##############################################
4756:
4757: =pod
4758:
4759: =item * &pgrdlink()
4760:
4761: Inputs: $text $uname $udom $symb $target
4762:
4763: Returns: A link to grades.pm such as to see the PGRD view of a student
4764:
4765: =cut
4766:
4767: ###############################################
4768: sub pgrdlink {
4769: my $link=&submlink(@_);
4770: $link=~s/(&command=submission)/$1&showgrading=yes/;
4771: return $link;
4772: }
4773: ##############################################
4774:
4775: =pod
4776:
4777: =item * &pprmlink()
4778:
4779: Inputs: $text $uname $udom $symb $target
4780:
4781: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4782: student and a specific resource
1.242 albertel 4783:
4784: =cut
4785:
4786: ###############################################
4787: sub pprmlink {
4788: my ($text,$uname,$udom,$symb,$target)=@_;
4789: if (!($uname && $udom)) {
4790: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4791: &Apache::lonnet::whichuser($symb);
1.242 albertel 4792: if (!$symb) { $symb=$cursymb; }
4793: }
1.254 matthew 4794: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4795: $symb=&escape($symb);
1.242 albertel 4796: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4797: return '<a href="/adm/parmset?command=set&'.
4798: 'symb='.$symb.'&uname='.$uname.
4799: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4800: }
4801: ##############################################
1.37 matthew 4802:
1.112 bowersj2 4803: =pod
4804:
4805: =back
4806:
4807: =cut
4808:
1.37 matthew 4809: ###############################################
1.51 www 4810:
4811:
4812: sub timehash {
1.687 raeburn 4813: my ($thistime) = @_;
4814: my $timezone = &Apache::lonlocal::gettimezone();
4815: my $dt = DateTime->from_epoch(epoch => $thistime)
4816: ->set_time_zone($timezone);
4817: my $wday = $dt->day_of_week();
4818: if ($wday == 7) { $wday = 0; }
4819: return ( 'second' => $dt->second(),
4820: 'minute' => $dt->minute(),
4821: 'hour' => $dt->hour(),
4822: 'day' => $dt->day_of_month(),
4823: 'month' => $dt->month(),
4824: 'year' => $dt->year(),
4825: 'weekday' => $wday,
4826: 'dayyear' => $dt->day_of_year(),
4827: 'dlsav' => $dt->is_dst() );
1.51 www 4828: }
4829:
1.370 www 4830: sub utc_string {
4831: my ($date)=@_;
1.371 www 4832: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4833: }
4834:
1.51 www 4835: sub maketime {
4836: my %th=@_;
1.687 raeburn 4837: my ($epoch_time,$timezone,$dt);
4838: $timezone = &Apache::lonlocal::gettimezone();
4839: eval {
4840: $dt = DateTime->new( year => $th{'year'},
4841: month => $th{'month'},
4842: day => $th{'day'},
4843: hour => $th{'hour'},
4844: minute => $th{'minute'},
4845: second => $th{'second'},
4846: time_zone => $timezone,
4847: );
4848: };
4849: if (!$@) {
4850: $epoch_time = $dt->epoch;
4851: if ($epoch_time) {
4852: return $epoch_time;
4853: }
4854: }
1.51 www 4855: return POSIX::mktime(
4856: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4857: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4858: }
4859:
4860: #########################################
1.51 www 4861:
4862: sub findallcourses {
1.482 raeburn 4863: my ($roles,$uname,$udom) = @_;
1.355 albertel 4864: my %roles;
4865: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4866: my %courses;
1.51 www 4867: my $now=time;
1.482 raeburn 4868: if (!defined($uname)) {
4869: $uname = $env{'user.name'};
4870: }
4871: if (!defined($udom)) {
4872: $udom = $env{'user.domain'};
4873: }
4874: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4875: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4876: if (!%roles) {
4877: %roles = (
4878: cc => 1,
1.907 raeburn 4879: co => 1,
1.482 raeburn 4880: in => 1,
4881: ep => 1,
4882: ta => 1,
4883: cr => 1,
4884: st => 1,
4885: );
4886: }
4887: foreach my $entry (keys(%roleshash)) {
4888: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4889: if ($trole =~ /^cr/) {
4890: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4891: } else {
4892: next if (!exists($roles{$trole}));
4893: }
4894: if ($tend) {
4895: next if ($tend < $now);
4896: }
4897: if ($tstart) {
4898: next if ($tstart > $now);
4899: }
1.1058 raeburn 4900: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4901: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4902: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4903: if ($secpart eq '') {
4904: ($cnum,$role) = split(/_/,$cnumpart);
4905: $sec = 'none';
1.1058 raeburn 4906: $value .= $cnum.'/';
1.482 raeburn 4907: } else {
4908: $cnum = $cnumpart;
4909: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4910: $value .= $cnum.'/'.$sec;
4911: }
4912: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4913: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4914: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4915: }
4916: } else {
4917: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4918: }
1.482 raeburn 4919: }
4920: } else {
4921: foreach my $key (keys(%env)) {
1.483 albertel 4922: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4923: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4924: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4925: next if ($role eq 'ca' || $role eq 'aa');
4926: next if (%roles && !exists($roles{$role}));
4927: my ($starttime,$endtime)=split(/\./,$env{$key});
4928: my $active=1;
4929: if ($starttime) {
4930: if ($now<$starttime) { $active=0; }
4931: }
4932: if ($endtime) {
4933: if ($now>$endtime) { $active=0; }
4934: }
4935: if ($active) {
1.1058 raeburn 4936: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4937: if ($sec eq '') {
4938: $sec = 'none';
1.1058 raeburn 4939: } else {
4940: $value .= $sec;
4941: }
4942: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4943: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4944: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4945: }
4946: } else {
4947: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4948: }
1.474 raeburn 4949: }
4950: }
1.51 www 4951: }
4952: }
1.474 raeburn 4953: return %courses;
1.51 www 4954: }
1.37 matthew 4955:
1.54 www 4956: ###############################################
1.474 raeburn 4957:
4958: sub blockcheck {
1.1189 raeburn 4959: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4960:
1.1189 raeburn 4961: if (defined($udom) && defined($uname)) {
4962: # If uname and udom are for a course, check for blocks in the course.
4963: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4964: my ($startblock,$endblock,$triggerblock) =
4965: &get_blocks($setters,$activity,$udom,$uname,$url);
4966: return ($startblock,$endblock,$triggerblock);
4967: }
4968: } else {
1.490 raeburn 4969: $udom = $env{'user.domain'};
4970: $uname = $env{'user.name'};
4971: }
4972:
1.502 raeburn 4973: my $startblock = 0;
4974: my $endblock = 0;
1.1062 raeburn 4975: my $triggerblock = '';
1.482 raeburn 4976: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4977:
1.490 raeburn 4978: # If uname is for a user, and activity is course-specific, i.e.,
4979: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4980:
1.490 raeburn 4981: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1189 raeburn 4982: $activity eq 'groups' || $activity eq 'printout') &&
4983: ($env{'request.course.id'})) {
1.490 raeburn 4984: foreach my $key (keys(%live_courses)) {
4985: if ($key ne $env{'request.course.id'}) {
4986: delete($live_courses{$key});
4987: }
4988: }
4989: }
4990:
4991: my $otheruser = 0;
4992: my %own_courses;
4993: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4994: # Resource belongs to user other than current user.
4995: $otheruser = 1;
4996: # Gather courses for current user
4997: %own_courses =
4998: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4999: }
5000:
5001: # Gather active course roles - course coordinator, instructor,
5002: # exam proctor, ta, student, or custom role.
1.474 raeburn 5003:
5004: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5005: my ($cdom,$cnum);
5006: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5007: $cdom = $env{'course.'.$course.'.domain'};
5008: $cnum = $env{'course.'.$course.'.num'};
5009: } else {
1.490 raeburn 5010: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5011: }
5012: my $no_ownblock = 0;
5013: my $no_userblock = 0;
1.533 raeburn 5014: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5015: # Check if current user has 'evb' priv for this
5016: if (defined($own_courses{$course})) {
5017: foreach my $sec (keys(%{$own_courses{$course}})) {
5018: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5019: if ($sec ne 'none') {
5020: $checkrole .= '/'.$sec;
5021: }
5022: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5023: $no_ownblock = 1;
5024: last;
5025: }
5026: }
5027: }
5028: # if they have 'evb' priv and are currently not playing student
5029: next if (($no_ownblock) &&
5030: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5031: }
1.474 raeburn 5032: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5033: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5034: if ($sec ne 'none') {
1.482 raeburn 5035: $checkrole .= '/'.$sec;
1.474 raeburn 5036: }
1.490 raeburn 5037: if ($otheruser) {
5038: # Resource belongs to user other than current user.
5039: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5040: my (%allroles,%userroles);
5041: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5042: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5043: my ($trole,$tdom,$tnum,$tsec);
5044: if ($entry =~ /^cr/) {
5045: ($trole,$tdom,$tnum,$tsec) =
5046: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5047: } else {
5048: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5049: }
5050: my ($spec,$area,$trest);
5051: $area = '/'.$tdom.'/'.$tnum;
5052: $trest = $tnum;
5053: if ($tsec ne '') {
5054: $area .= '/'.$tsec;
5055: $trest .= '/'.$tsec;
5056: }
5057: $spec = $trole.'.'.$area;
5058: if ($trole =~ /^cr/) {
5059: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5060: $tdom,$spec,$trest,$area);
5061: } else {
5062: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5063: $tdom,$spec,$trest,$area);
5064: }
5065: }
5066: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
5067: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5068: if ($1) {
5069: $no_userblock = 1;
5070: last;
5071: }
1.486 raeburn 5072: }
5073: }
1.490 raeburn 5074: } else {
5075: # Resource belongs to current user
5076: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5077: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5078: $no_ownblock = 1;
5079: last;
5080: }
1.474 raeburn 5081: }
5082: }
5083: # if they have the evb priv and are currently not playing student
1.482 raeburn 5084: next if (($no_ownblock) &&
1.491 albertel 5085: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5086: next if ($no_userblock);
1.474 raeburn 5087:
1.866 kalberla 5088: # Retrieve blocking times and identity of locker for course
1.490 raeburn 5089: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 5090:
1.1062 raeburn 5091: my ($start,$end,$trigger) =
5092: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 5093: if (($start != 0) &&
5094: (($startblock == 0) || ($startblock > $start))) {
5095: $startblock = $start;
1.1062 raeburn 5096: if ($trigger ne '') {
5097: $triggerblock = $trigger;
5098: }
1.502 raeburn 5099: }
5100: if (($end != 0) &&
5101: (($endblock == 0) || ($endblock < $end))) {
5102: $endblock = $end;
1.1062 raeburn 5103: if ($trigger ne '') {
5104: $triggerblock = $trigger;
5105: }
1.502 raeburn 5106: }
1.490 raeburn 5107: }
1.1062 raeburn 5108: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5109: }
5110:
5111: sub get_blocks {
1.1062 raeburn 5112: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 5113: my $startblock = 0;
5114: my $endblock = 0;
1.1062 raeburn 5115: my $triggerblock = '';
1.490 raeburn 5116: my $course = $cdom.'_'.$cnum;
5117: $setters->{$course} = {};
5118: $setters->{$course}{'staff'} = [];
5119: $setters->{$course}{'times'} = [];
1.1062 raeburn 5120: $setters->{$course}{'triggers'} = [];
5121: my (@blockers,%triggered);
5122: my $now = time;
5123: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5124: if ($activity eq 'docs') {
5125: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
5126: foreach my $block (@blockers) {
5127: if ($block =~ /^firstaccess____(.+)$/) {
5128: my $item = $1;
5129: my $type = 'map';
5130: my $timersymb = $item;
5131: if ($item eq 'course') {
5132: $type = 'course';
5133: } elsif ($item =~ /___\d+___/) {
5134: $type = 'resource';
5135: } else {
5136: $timersymb = &Apache::lonnet::symbread($item);
5137: }
5138: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5139: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5140: $triggered{$block} = {
5141: start => $start,
5142: end => $end,
5143: type => $type,
5144: };
5145: }
5146: }
5147: } else {
5148: foreach my $block (keys(%commblocks)) {
5149: if ($block =~ m/^(\d+)____(\d+)$/) {
5150: my ($start,$end) = ($1,$2);
5151: if ($start <= time && $end >= time) {
5152: if (ref($commblocks{$block}) eq 'HASH') {
5153: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5154: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5155: unless(grep(/^\Q$block\E$/,@blockers)) {
5156: push(@blockers,$block);
5157: }
5158: }
5159: }
5160: }
5161: }
5162: } elsif ($block =~ /^firstaccess____(.+)$/) {
5163: my $item = $1;
5164: my $timersymb = $item;
5165: my $type = 'map';
5166: if ($item eq 'course') {
5167: $type = 'course';
5168: } elsif ($item =~ /___\d+___/) {
5169: $type = 'resource';
5170: } else {
5171: $timersymb = &Apache::lonnet::symbread($item);
5172: }
5173: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5174: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5175: if ($start && $end) {
5176: if (($start <= time) && ($end >= time)) {
5177: unless (grep(/^\Q$block\E$/,@blockers)) {
5178: push(@blockers,$block);
5179: $triggered{$block} = {
5180: start => $start,
5181: end => $end,
5182: type => $type,
5183: };
5184: }
5185: }
1.490 raeburn 5186: }
1.1062 raeburn 5187: }
5188: }
5189: }
5190: foreach my $blocker (@blockers) {
5191: my ($staff_name,$staff_dom,$title,$blocks) =
5192: &parse_block_record($commblocks{$blocker});
5193: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5194: my ($start,$end,$triggertype);
5195: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5196: ($start,$end) = ($1,$2);
5197: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5198: $start = $triggered{$blocker}{'start'};
5199: $end = $triggered{$blocker}{'end'};
5200: $triggertype = $triggered{$blocker}{'type'};
5201: }
5202: if ($start) {
5203: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5204: if ($triggertype) {
5205: push(@{$$setters{$course}{'triggers'}},$triggertype);
5206: } else {
5207: push(@{$$setters{$course}{'triggers'}},0);
5208: }
5209: if ( ($startblock == 0) || ($startblock > $start) ) {
5210: $startblock = $start;
5211: if ($triggertype) {
5212: $triggerblock = $blocker;
1.474 raeburn 5213: }
5214: }
1.1062 raeburn 5215: if ( ($endblock == 0) || ($endblock < $end) ) {
5216: $endblock = $end;
5217: if ($triggertype) {
5218: $triggerblock = $blocker;
5219: }
5220: }
1.474 raeburn 5221: }
5222: }
1.1062 raeburn 5223: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5224: }
5225:
5226: sub parse_block_record {
5227: my ($record) = @_;
5228: my ($setuname,$setudom,$title,$blocks);
5229: if (ref($record) eq 'HASH') {
5230: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5231: $title = &unescape($record->{'event'});
5232: $blocks = $record->{'blocks'};
5233: } else {
5234: my @data = split(/:/,$record,3);
5235: if (scalar(@data) eq 2) {
5236: $title = $data[1];
5237: ($setuname,$setudom) = split(/@/,$data[0]);
5238: } else {
5239: ($setuname,$setudom,$title) = @data;
5240: }
5241: $blocks = { 'com' => 'on' };
5242: }
5243: return ($setuname,$setudom,$title,$blocks);
5244: }
5245:
1.854 kalberla 5246: sub blocking_status {
1.1189 raeburn 5247: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 5248: my %setters;
1.890 droeschl 5249:
1.1061 raeburn 5250: # check for active blocking
1.1062 raeburn 5251: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 5252: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 5253: my $blocked = 0;
5254: if ($startblock && $endblock) {
5255: $blocked = 1;
5256: }
1.890 droeschl 5257:
1.1061 raeburn 5258: # caller just wants to know whether a block is active
5259: if (!wantarray) { return $blocked; }
5260:
5261: # build a link to a popup window containing the details
5262: my $querystring = "?activity=$activity";
5263: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 raeburn 5264: if (($activity eq 'port') || ($activity eq 'passwd')) {
5265: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5266: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5267: } elsif ($activity eq 'docs') {
5268: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
5269: }
1.1061 raeburn 5270:
5271: my $output .= <<'END_MYBLOCK';
5272: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5273: var options = "width=" + w + ",height=" + h + ",";
5274: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5275: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5276: var newWin = window.open(url, wdwName, options);
5277: newWin.focus();
5278: }
1.890 droeschl 5279: END_MYBLOCK
1.854 kalberla 5280:
1.1061 raeburn 5281: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5282:
1.1061 raeburn 5283: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5284: my $text = &mt('Communication Blocked');
1.1217 raeburn 5285: my $class = 'LC_comblock';
1.1062 raeburn 5286: if ($activity eq 'docs') {
5287: $text = &mt('Content Access Blocked');
1.1217 raeburn 5288: $class = '';
1.1063 raeburn 5289: } elsif ($activity eq 'printout') {
5290: $text = &mt('Printing Blocked');
1.1232 raeburn 5291: } elsif ($activity eq 'passwd') {
5292: $text = &mt('Password Changing Blocked');
1.1062 raeburn 5293: }
1.1061 raeburn 5294: $output .= <<"END_BLOCK";
1.1217 raeburn 5295: <div class='$class'>
1.869 kalberla 5296: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5297: title='$text'>
5298: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5299: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5300: title='$text'>$text</a>
1.867 kalberla 5301: </div>
5302:
5303: END_BLOCK
1.474 raeburn 5304:
1.1061 raeburn 5305: return ($blocked, $output);
1.854 kalberla 5306: }
1.490 raeburn 5307:
1.60 matthew 5308: ###############################################
5309:
1.682 raeburn 5310: sub check_ip_acc {
1.1201 raeburn 5311: my ($acc,$clientip)=@_;
1.682 raeburn 5312: &Apache::lonxml::debug("acc is $acc");
5313: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5314: return 1;
5315: }
1.1219 raeburn 5316: my $allowed;
1.1252 raeburn 5317: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 5318:
5319: my $name;
1.1219 raeburn 5320: my %access = (
5321: allowfrom => 1,
5322: denyfrom => 0,
5323: );
5324: my @allows;
5325: my @denies;
5326: foreach my $item (split(',',$acc)) {
5327: $item =~ s/^\s*//;
5328: $item =~ s/\s*$//;
5329: my $pattern;
5330: if ($item =~ /^\!(.+)$/) {
5331: push(@denies,$1);
5332: } else {
5333: push(@allows,$item);
5334: }
5335: }
5336: my $numdenies = scalar(@denies);
5337: my $numallows = scalar(@allows);
5338: my $count = 0;
5339: foreach my $pattern (@denies,@allows) {
5340: $count ++;
5341: my $acctype = 'allowfrom';
5342: if ($count <= $numdenies) {
5343: $acctype = 'denyfrom';
5344: }
1.682 raeburn 5345: if ($pattern =~ /\*$/) {
5346: #35.8.*
5347: $pattern=~s/\*//;
1.1219 raeburn 5348: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5349: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5350: #35.8.3.[34-56]
5351: my $low=$2;
5352: my $high=$3;
5353: $pattern=$1;
5354: if ($ip =~ /^\Q$pattern\E/) {
5355: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5356: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5357: }
5358: } elsif ($pattern =~ /^\*/) {
5359: #*.msu.edu
5360: $pattern=~s/\*//;
5361: if (!defined($name)) {
5362: use Socket;
5363: my $netaddr=inet_aton($ip);
5364: ($name)=gethostbyaddr($netaddr,AF_INET);
5365: }
1.1219 raeburn 5366: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5367: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5368: #127.0.0.1
1.1219 raeburn 5369: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5370: } else {
5371: #some.name.com
5372: if (!defined($name)) {
5373: use Socket;
5374: my $netaddr=inet_aton($ip);
5375: ($name)=gethostbyaddr($netaddr,AF_INET);
5376: }
1.1219 raeburn 5377: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5378: }
5379: if ($allowed =~ /^(0|1)$/) { last; }
5380: }
5381: if ($allowed eq '') {
5382: if ($numdenies && !$numallows) {
5383: $allowed = 1;
5384: } else {
5385: $allowed = 0;
1.682 raeburn 5386: }
5387: }
5388: return $allowed;
5389: }
5390:
5391: ###############################################
5392:
1.60 matthew 5393: =pod
5394:
1.112 bowersj2 5395: =head1 Domain Template Functions
5396:
5397: =over 4
5398:
5399: =item * &determinedomain()
1.60 matthew 5400:
5401: Inputs: $domain (usually will be undef)
5402:
1.63 www 5403: Returns: Determines which domain should be used for designs
1.60 matthew 5404:
5405: =cut
1.54 www 5406:
1.60 matthew 5407: ###############################################
1.63 www 5408: sub determinedomain {
5409: my $domain=shift;
1.531 albertel 5410: if (! $domain) {
1.60 matthew 5411: # Determine domain if we have not been given one
1.893 raeburn 5412: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5413: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5414: if ($env{'request.role.domain'}) {
5415: $domain=$env{'request.role.domain'};
1.60 matthew 5416: }
5417: }
1.63 www 5418: return $domain;
5419: }
5420: ###############################################
1.517 raeburn 5421:
1.518 albertel 5422: sub devalidate_domconfig_cache {
5423: my ($udom)=@_;
5424: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5425: }
5426:
5427: # ---------------------- Get domain configuration for a domain
5428: sub get_domainconf {
5429: my ($udom) = @_;
5430: my $cachetime=1800;
5431: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5432: if (defined($cached)) { return %{$result}; }
5433:
5434: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5435: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5436: my (%designhash,%legacy);
1.518 albertel 5437: if (keys(%domconfig) > 0) {
5438: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5439: if (keys(%{$domconfig{'login'}})) {
5440: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5441: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5442: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5443: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5444: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5445: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5446: if ($key eq 'loginvia') {
5447: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5448: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5449: $designhash{$udom.'.login.loginvia'} = $server;
5450: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5451:
5452: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5453: } else {
5454: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5455: }
1.948 raeburn 5456: }
1.1208 raeburn 5457: } elsif ($key eq 'headtag') {
5458: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5459: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5460: }
1.946 raeburn 5461: }
1.1208 raeburn 5462: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5463: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5464: }
1.946 raeburn 5465: }
5466: }
5467: }
5468: } else {
5469: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5470: $designhash{$udom.'.login.'.$key.'_'.$img} =
5471: $domconfig{'login'}{$key}{$img};
5472: }
1.699 raeburn 5473: }
5474: } else {
5475: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5476: }
1.632 raeburn 5477: }
5478: } else {
5479: $legacy{'login'} = 1;
1.518 albertel 5480: }
1.632 raeburn 5481: } else {
5482: $legacy{'login'} = 1;
1.518 albertel 5483: }
5484: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5485: if (keys(%{$domconfig{'rolecolors'}})) {
5486: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5487: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5488: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5489: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5490: }
1.518 albertel 5491: }
5492: }
1.632 raeburn 5493: } else {
5494: $legacy{'rolecolors'} = 1;
1.518 albertel 5495: }
1.632 raeburn 5496: } else {
5497: $legacy{'rolecolors'} = 1;
1.518 albertel 5498: }
1.948 raeburn 5499: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5500: if ($domconfig{'autoenroll'}{'co-owners'}) {
5501: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5502: }
5503: }
1.632 raeburn 5504: if (keys(%legacy) > 0) {
5505: my %legacyhash = &get_legacy_domconf($udom);
5506: foreach my $item (keys(%legacyhash)) {
5507: if ($item =~ /^\Q$udom\E\.login/) {
5508: if ($legacy{'login'}) {
5509: $designhash{$item} = $legacyhash{$item};
5510: }
5511: } else {
5512: if ($legacy{'rolecolors'}) {
5513: $designhash{$item} = $legacyhash{$item};
5514: }
1.518 albertel 5515: }
5516: }
5517: }
1.632 raeburn 5518: } else {
5519: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5520: }
5521: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5522: $cachetime);
5523: return %designhash;
5524: }
5525:
1.632 raeburn 5526: sub get_legacy_domconf {
5527: my ($udom) = @_;
5528: my %legacyhash;
5529: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5530: my $designfile = $designdir.'/'.$udom.'.tab';
5531: if (-e $designfile) {
5532: if ( open (my $fh,"<$designfile") ) {
5533: while (my $line = <$fh>) {
5534: next if ($line =~ /^\#/);
5535: chomp($line);
5536: my ($key,$val)=(split(/\=/,$line));
5537: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5538: }
5539: close($fh);
5540: }
5541: }
1.1026 raeburn 5542: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5543: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5544: }
5545: return %legacyhash;
5546: }
5547:
1.63 www 5548: =pod
5549:
1.112 bowersj2 5550: =item * &domainlogo()
1.63 www 5551:
5552: Inputs: $domain (usually will be undef)
5553:
5554: Returns: A link to a domain logo, if the domain logo exists.
5555: If the domain logo does not exist, a description of the domain.
5556:
5557: =cut
1.112 bowersj2 5558:
1.63 www 5559: ###############################################
5560: sub domainlogo {
1.517 raeburn 5561: my $domain = &determinedomain(shift);
1.518 albertel 5562: my %designhash = &get_domainconf($domain);
1.517 raeburn 5563: # See if there is a logo
5564: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5565: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5566: if ($imgsrc =~ m{^/(adm|res)/}) {
5567: if ($imgsrc =~ m{^/res/}) {
5568: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5569: &Apache::lonnet::repcopy($local_name);
5570: }
5571: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5572: }
5573: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5574: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5575: return &Apache::lonnet::domain($domain,'description');
1.59 www 5576: } else {
1.60 matthew 5577: return '';
1.59 www 5578: }
5579: }
1.63 www 5580: ##############################################
5581:
5582: =pod
5583:
1.112 bowersj2 5584: =item * &designparm()
1.63 www 5585:
5586: Inputs: $which parameter; $domain (usually will be undef)
5587:
5588: Returns: value of designparamter $which
5589:
5590: =cut
1.112 bowersj2 5591:
1.397 albertel 5592:
1.400 albertel 5593: ##############################################
1.397 albertel 5594: sub designparm {
5595: my ($which,$domain)=@_;
5596: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5597: return $env{'environment.color.'.$which};
1.96 www 5598: }
1.63 www 5599: $domain=&determinedomain($domain);
1.1016 raeburn 5600: my %domdesign;
5601: unless ($domain eq 'public') {
5602: %domdesign = &get_domainconf($domain);
5603: }
1.520 raeburn 5604: my $output;
1.517 raeburn 5605: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5606: $output = $domdesign{$domain.'.'.$which};
1.63 www 5607: } else {
1.520 raeburn 5608: $output = $defaultdesign{$which};
5609: }
5610: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5611: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5612: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5613: if ($output =~ m{^/res/}) {
5614: my $local_name = &Apache::lonnet::filelocation('',$output);
5615: &Apache::lonnet::repcopy($local_name);
5616: }
1.520 raeburn 5617: $output = &lonhttpdurl($output);
5618: }
1.63 www 5619: }
1.520 raeburn 5620: return $output;
1.63 www 5621: }
1.59 www 5622:
1.822 bisitz 5623: ##############################################
5624: =pod
5625:
1.832 bisitz 5626: =item * &authorspace()
5627:
1.1028 raeburn 5628: Inputs: $url (usually will be undef).
1.832 bisitz 5629:
1.1132 raeburn 5630: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5631: directory being viewed (or for which action is being taken).
5632: If $url is provided, and begins /priv/<domain>/<uname>
5633: the path will be that portion of the $context argument.
5634: Otherwise the path will be for the author space of the current
5635: user when the current role is author, or for that of the
5636: co-author/assistant co-author space when the current role
5637: is co-author or assistant co-author.
1.832 bisitz 5638:
5639: =cut
5640:
5641: sub authorspace {
1.1028 raeburn 5642: my ($url) = @_;
5643: if ($url ne '') {
5644: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5645: return $1;
5646: }
5647: }
1.832 bisitz 5648: my $caname = '';
1.1024 www 5649: my $cadom = '';
1.1028 raeburn 5650: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5651: ($cadom,$caname) =
1.832 bisitz 5652: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5653: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5654: $caname = $env{'user.name'};
1.1024 www 5655: $cadom = $env{'user.domain'};
1.832 bisitz 5656: }
1.1028 raeburn 5657: if (($caname ne '') && ($cadom ne '')) {
5658: return "/priv/$cadom/$caname/";
5659: }
5660: return;
1.832 bisitz 5661: }
5662:
5663: ##############################################
5664: =pod
5665:
1.822 bisitz 5666: =item * &head_subbox()
5667:
5668: Inputs: $content (contains HTML code with page functions, etc.)
5669:
5670: Returns: HTML div with $content
5671: To be included in page header
5672:
5673: =cut
5674:
5675: sub head_subbox {
5676: my ($content)=@_;
5677: my $output =
1.993 raeburn 5678: '<div class="LC_head_subbox">'
1.822 bisitz 5679: .$content
5680: .'</div>'
5681: }
5682:
5683: ##############################################
5684: =pod
5685:
5686: =item * &CSTR_pageheader()
5687:
1.1026 raeburn 5688: Input: (optional) filename from which breadcrumb trail is built.
5689: In most cases no input as needed, as $env{'request.filename'}
5690: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5691:
5692: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5693: To be included on Authoring Space pages
1.822 bisitz 5694:
5695: =cut
5696:
5697: sub CSTR_pageheader {
1.1026 raeburn 5698: my ($trailfile) = @_;
5699: if ($trailfile eq '') {
5700: $trailfile = $env{'request.filename'};
5701: }
5702:
5703: # this is for resources; directories have customtitle, and crumbs
5704: # and select recent are created in lonpubdir.pm
5705:
5706: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5707: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5708: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5709: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5710: $formaction =~ s{/+}{/}g;
1.822 bisitz 5711:
5712: my $parentpath = '';
5713: my $lastitem = '';
5714: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5715: $parentpath = $1;
5716: $lastitem = $2;
5717: } else {
5718: $lastitem = $thisdisfn;
5719: }
1.921 bisitz 5720:
1.1246 raeburn 5721: my ($crsauthor,$title);
5722: if (($env{'request.course.id'}) &&
5723: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 5724: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 5725: $crsauthor = 1;
5726: $title = &mt('Course Authoring Space');
5727: } else {
5728: $title = &mt('Authoring Space');
5729: }
5730:
1.921 bisitz 5731: my $output =
1.822 bisitz 5732: '<div>'
5733: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 5734: .'<b>'.$title.'</b> '
1.822 bisitz 5735: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5736: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5737: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5738:
5739: if ($lastitem) {
5740: $output .=
5741: '<span class="LC_filename">'
5742: .$lastitem
5743: .'</span>';
5744: }
1.1245 raeburn 5745:
1.1246 raeburn 5746: if ($crsauthor) {
5747: $output .= '</form>'.&Apache::lonmenu::constspaceform();
5748: } else {
5749: $output .=
5750: '<br />'
5751: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5752: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5753: .'</form>'
5754: .&Apache::lonmenu::constspaceform();
5755: }
5756: $output .= '</div>';
1.921 bisitz 5757:
5758: return $output;
1.822 bisitz 5759: }
5760:
1.60 matthew 5761: ###############################################
5762: ###############################################
5763:
5764: =pod
5765:
1.112 bowersj2 5766: =back
5767:
1.549 albertel 5768: =head1 HTML Helpers
1.112 bowersj2 5769:
5770: =over 4
5771:
5772: =item * &bodytag()
1.60 matthew 5773:
5774: Returns a uniform header for LON-CAPA web pages.
5775:
5776: Inputs:
5777:
1.112 bowersj2 5778: =over 4
5779:
5780: =item * $title, A title to be displayed on the page.
5781:
5782: =item * $function, the current role (can be undef).
5783:
5784: =item * $addentries, extra parameters for the <body> tag.
5785:
5786: =item * $bodyonly, if defined, only return the <body> tag.
5787:
5788: =item * $domain, if defined, force a given domain.
5789:
5790: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5791: text interface only)
1.60 matthew 5792:
1.814 bisitz 5793: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5794: navigational links
1.317 albertel 5795:
1.338 albertel 5796: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5797:
1.460 albertel 5798: =item * $args, optional argument valid values are
5799: no_auto_mt_title -> prevents &mt()ing the title arg
5800:
1.1096 raeburn 5801: =item * $advtoolsref, optional argument, ref to an array containing
5802: inlineremote items to be added in "Functions" menu below
5803: breadcrumbs.
5804:
1.112 bowersj2 5805: =back
5806:
1.60 matthew 5807: Returns: A uniform header for LON-CAPA web pages.
5808: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5809: If $bodyonly is undef or zero, an html string containing a <body> tag and
5810: other decorations will be returned.
5811:
5812: =cut
5813:
1.54 www 5814: sub bodytag {
1.831 bisitz 5815: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5816: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5817:
1.954 raeburn 5818: my $public;
5819: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5820: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5821: $public = 1;
5822: }
1.460 albertel 5823: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5824: my $httphost = $args->{'use_absolute'};
1.339 albertel 5825:
1.183 matthew 5826: $function = &get_users_function() if (!$function);
1.339 albertel 5827: my $img = &designparm($function.'.img',$domain);
5828: my $font = &designparm($function.'.font',$domain);
5829: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5830:
1.803 bisitz 5831: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5832: 'bgcolor' => $pgbg,
1.339 albertel 5833: 'text' => $font,
5834: 'alink' => &designparm($function.'.alink',$domain),
5835: 'vlink' => &designparm($function.'.vlink',$domain),
5836: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5837: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5838:
1.63 www 5839: # role and realm
1.1178 raeburn 5840: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5841: if ($realm) {
5842: $realm = '/'.$realm;
5843: }
1.378 raeburn 5844: if ($role eq 'ca') {
1.479 albertel 5845: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5846: $realm = &plainname($rname,$rdom);
1.378 raeburn 5847: }
1.55 www 5848: # realm
1.258 albertel 5849: if ($env{'request.course.id'}) {
1.378 raeburn 5850: if ($env{'request.role'} !~ /^cr/) {
5851: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 5852: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
5853: $role = &mt('Helpdesk[_1]',' '.$2);
5854: } else {
5855: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5856: }
1.898 raeburn 5857: if ($env{'request.course.sec'}) {
5858: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5859: }
1.359 albertel 5860: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5861: } else {
5862: $role = &Apache::lonnet::plaintext($role);
1.54 www 5863: }
1.433 albertel 5864:
1.359 albertel 5865: if (!$realm) { $realm=' '; }
1.330 albertel 5866:
1.438 albertel 5867: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5868:
1.101 www 5869: # construct main body tag
1.359 albertel 5870: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 5871: &Apache::lontexconvert::init_math_support();
1.252 albertel 5872:
1.1131 raeburn 5873: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5874:
1.1130 raeburn 5875: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5876: return $bodytag;
1.1130 raeburn 5877: }
1.359 albertel 5878:
1.954 raeburn 5879: if ($public) {
1.433 albertel 5880: undef($role);
5881: }
1.359 albertel 5882:
1.762 bisitz 5883: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5884: #
5885: # Extra info if you are the DC
5886: my $dc_info = '';
5887: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5888: $env{'course.'.$env{'request.course.id'}.
5889: '.domain'}.'/'})) {
5890: my $cid = $env{'request.course.id'};
1.917 raeburn 5891: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5892: $dc_info =~ s/\s+$//;
1.359 albertel 5893: }
5894:
1.1237 raeburn 5895: my $crstype;
5896: if ($env{'request.course.id'}) {
5897: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
5898: } elsif ($args->{'crstype'}) {
5899: $crstype = $args->{'crstype'};
5900: }
5901: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
5902: undef($role);
5903: } else {
1.1242 raeburn 5904: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 5905: }
1.853 droeschl 5906:
1.903 droeschl 5907: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5908:
5909: # if ($env{'request.state'} eq 'construct') {
5910: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5911: # }
5912:
1.1130 raeburn 5913: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 5914: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5915:
1.1237 raeburn 5916: my ($left,$right) = Apache::lonmenu::primary_menu($crstype);
1.359 albertel 5917:
1.916 droeschl 5918: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5919: if ($dc_info) {
5920: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5921: }
1.1130 raeburn 5922: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5923: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5924: return $bodytag;
5925: }
1.894 droeschl 5926:
1.927 raeburn 5927: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5928: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5929: }
1.916 droeschl 5930:
1.1130 raeburn 5931: $bodytag .= $right;
1.852 droeschl 5932:
1.917 raeburn 5933: if ($dc_info) {
5934: $dc_info = &dc_courseid_toggle($dc_info);
5935: }
5936: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5937:
1.1169 raeburn 5938: #if directed to not display the secondary menu, don't.
1.1168 raeburn 5939: if ($args->{'no_secondary_menu'}) {
5940: return $bodytag;
5941: }
1.1169 raeburn 5942: #don't show menus for public users
1.954 raeburn 5943: if (!$public){
1.1154 raeburn 5944: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5945: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5946: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5947: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5948: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5949: $args->{'bread_crumbs'});
1.1096 raeburn 5950: } elsif ($forcereg) {
5951: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 ! raeburn 5952: $args->{'group'},
! 5953: $args->{'hide_buttons'});
1.1096 raeburn 5954: } else {
5955: $bodytag .=
5956: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5957: $forcereg,$args->{'group'},
5958: $args->{'bread_crumbs'},
5959: $advtoolsref);
1.920 raeburn 5960: }
1.903 droeschl 5961: }else{
5962: # this is to seperate menu from content when there's no secondary
5963: # menu. Especially needed for public accessible ressources.
5964: $bodytag .= '<hr style="clear:both" />';
5965: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5966: }
1.903 droeschl 5967:
1.235 raeburn 5968: return $bodytag;
1.182 matthew 5969: }
5970:
1.917 raeburn 5971: sub dc_courseid_toggle {
5972: my ($dc_info) = @_;
1.980 raeburn 5973: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5974: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5975: &mt('(More ...)').'</a></span>'.
5976: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5977: }
5978:
1.330 albertel 5979: sub make_attr_string {
5980: my ($register,$attr_ref) = @_;
5981:
5982: if ($attr_ref && !ref($attr_ref)) {
5983: die("addentries Must be a hash ref ".
5984: join(':',caller(1))." ".
5985: join(':',caller(0))." ");
5986: }
5987:
5988: if ($register) {
1.339 albertel 5989: my ($on_load,$on_unload);
5990: foreach my $key (keys(%{$attr_ref})) {
5991: if (lc($key) eq 'onload') {
5992: $on_load.=$attr_ref->{$key}.';';
5993: delete($attr_ref->{$key});
5994:
5995: } elsif (lc($key) eq 'onunload') {
5996: $on_unload.=$attr_ref->{$key}.';';
5997: delete($attr_ref->{$key});
5998: }
5999: }
1.953 droeschl 6000: $attr_ref->{'onload'} = $on_load;
6001: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6002: }
1.339 albertel 6003:
1.330 albertel 6004: my $attr_string;
1.1159 raeburn 6005: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6006: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6007: }
6008: return $attr_string;
6009: }
6010:
6011:
1.182 matthew 6012: ###############################################
1.251 albertel 6013: ###############################################
6014:
6015: =pod
6016:
6017: =item * &endbodytag()
6018:
6019: Returns a uniform footer for LON-CAPA web pages.
6020:
1.635 raeburn 6021: Inputs: 1 - optional reference to an args hash
6022: If in the hash, key for noredirectlink has a value which evaluates to true,
6023: a 'Continue' link is not displayed if the page contains an
6024: internal redirect in the <head></head> section,
6025: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6026:
6027: =cut
6028:
6029: sub endbodytag {
1.635 raeburn 6030: my ($args) = @_;
1.1080 raeburn 6031: my $endbodytag;
6032: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6033: $endbodytag='</body>';
6034: }
1.315 albertel 6035: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6036: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6037: $endbodytag=
6038: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6039: &mt('Continue').'</a>'.
6040: $endbodytag;
6041: }
1.315 albertel 6042: }
1.251 albertel 6043: return $endbodytag;
6044: }
6045:
1.352 albertel 6046: =pod
6047:
6048: =item * &standard_css()
6049:
6050: Returns a style sheet
6051:
6052: Inputs: (all optional)
6053: domain -> force to color decorate a page for a specific
6054: domain
6055: function -> force usage of a specific rolish color scheme
6056: bgcolor -> override the default page bgcolor
6057:
6058: =cut
6059:
1.343 albertel 6060: sub standard_css {
1.345 albertel 6061: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6062: $function = &get_users_function() if (!$function);
6063: my $img = &designparm($function.'.img', $domain);
6064: my $tabbg = &designparm($function.'.tabbg', $domain);
6065: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6066: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6067: #second colour for later usage
1.345 albertel 6068: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6069: my $pgbg_or_bgcolor =
6070: $bgcolor ||
1.352 albertel 6071: &designparm($function.'.pgbg', $domain);
1.382 albertel 6072: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6073: my $alink = &designparm($function.'.alink', $domain);
6074: my $vlink = &designparm($function.'.vlink', $domain);
6075: my $link = &designparm($function.'.link', $domain);
6076:
1.602 albertel 6077: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6078: my $mono = 'monospace';
1.850 bisitz 6079: my $data_table_head = $sidebg;
6080: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6081: my $data_table_dark = '#E0E0E0';
1.470 banghart 6082: my $data_table_darker = '#CCCCCC';
1.349 albertel 6083: my $data_table_highlight = '#FFFF00';
1.352 albertel 6084: my $mail_new = '#FFBB77';
6085: my $mail_new_hover = '#DD9955';
6086: my $mail_read = '#BBBB77';
6087: my $mail_read_hover = '#999944';
6088: my $mail_replied = '#AAAA88';
6089: my $mail_replied_hover = '#888855';
6090: my $mail_other = '#99BBBB';
6091: my $mail_other_hover = '#669999';
1.391 albertel 6092: my $table_header = '#DDDDDD';
1.489 raeburn 6093: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6094: my $lg_border_color = '#C8C8C8';
1.952 onken 6095: my $button_hover = '#BF2317';
1.392 albertel 6096:
1.608 albertel 6097: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6098: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6099: : '0 3px 0 4px';
1.448 albertel 6100:
1.523 albertel 6101:
1.343 albertel 6102: return <<END;
1.947 droeschl 6103:
6104: /* needed for iframe to allow 100% height in FF */
6105: body, html {
6106: margin: 0;
6107: padding: 0 0.5%;
6108: height: 99%; /* to avoid scrollbars */
6109: }
6110:
1.795 www 6111: body {
1.911 bisitz 6112: font-family: $sans;
6113: line-height:130%;
6114: font-size:0.83em;
6115: color:$font;
1.795 www 6116: }
6117:
1.959 onken 6118: a:focus,
6119: a:focus img {
1.795 www 6120: color: red;
6121: }
1.698 harmsja 6122:
1.911 bisitz 6123: form, .inline {
6124: display: inline;
1.795 www 6125: }
1.721 harmsja 6126:
1.795 www 6127: .LC_right {
1.911 bisitz 6128: text-align:right;
1.795 www 6129: }
6130:
6131: .LC_middle {
1.911 bisitz 6132: vertical-align:middle;
1.795 www 6133: }
1.721 harmsja 6134:
1.1130 raeburn 6135: .LC_floatleft {
6136: float: left;
6137: }
6138:
6139: .LC_floatright {
6140: float: right;
6141: }
6142:
1.911 bisitz 6143: .LC_400Box {
6144: width:400px;
6145: }
1.721 harmsja 6146:
1.947 droeschl 6147: .LC_iframecontainer {
6148: width: 98%;
6149: margin: 0;
6150: position: fixed;
6151: top: 8.5em;
6152: bottom: 0;
6153: }
6154:
6155: .LC_iframecontainer iframe{
6156: border: none;
6157: width: 100%;
6158: height: 100%;
6159: }
6160:
1.778 bisitz 6161: .LC_filename {
6162: font-family: $mono;
6163: white-space:pre;
1.921 bisitz 6164: font-size: 120%;
1.778 bisitz 6165: }
6166:
6167: .LC_fileicon {
6168: border: none;
6169: height: 1.3em;
6170: vertical-align: text-bottom;
6171: margin-right: 0.3em;
6172: text-decoration:none;
6173: }
6174:
1.1008 www 6175: .LC_setting {
6176: text-decoration:underline;
6177: }
6178:
1.350 albertel 6179: .LC_error {
6180: color: red;
6181: }
1.795 www 6182:
1.1097 bisitz 6183: .LC_warning {
6184: color: darkorange;
6185: }
6186:
1.457 albertel 6187: .LC_diff_removed {
1.733 bisitz 6188: color: red;
1.394 albertel 6189: }
1.532 albertel 6190:
6191: .LC_info,
1.457 albertel 6192: .LC_success,
6193: .LC_diff_added {
1.350 albertel 6194: color: green;
6195: }
1.795 www 6196:
1.802 bisitz 6197: div.LC_confirm_box {
6198: background-color: #FAFAFA;
6199: border: 1px solid $lg_border_color;
6200: margin-right: 0;
6201: padding: 5px;
6202: }
6203:
6204: div.LC_confirm_box .LC_error img,
6205: div.LC_confirm_box .LC_success img {
6206: vertical-align: middle;
6207: }
6208:
1.1242 raeburn 6209: .LC_maxwidth {
6210: max-width: 100%;
6211: height: auto;
6212: }
6213:
1.1243 raeburn 6214: .LC_textsize_mobile {
6215: \@media only screen and (max-device-width: 480px) {
6216: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6217: }
6218: }
6219:
1.440 albertel 6220: .LC_icon {
1.771 droeschl 6221: border: none;
1.790 droeschl 6222: vertical-align: middle;
1.771 droeschl 6223: }
6224:
1.543 albertel 6225: .LC_docs_spacer {
6226: width: 25px;
6227: height: 1px;
1.771 droeschl 6228: border: none;
1.543 albertel 6229: }
1.346 albertel 6230:
1.532 albertel 6231: .LC_internal_info {
1.735 bisitz 6232: color: #999999;
1.532 albertel 6233: }
6234:
1.794 www 6235: .LC_discussion {
1.1050 www 6236: background: $data_table_dark;
1.911 bisitz 6237: border: 1px solid black;
6238: margin: 2px;
1.794 www 6239: }
6240:
6241: .LC_disc_action_left {
1.1050 www 6242: background: $sidebg;
1.911 bisitz 6243: text-align: left;
1.1050 www 6244: padding: 4px;
6245: margin: 2px;
1.794 www 6246: }
6247:
6248: .LC_disc_action_right {
1.1050 www 6249: background: $sidebg;
1.911 bisitz 6250: text-align: right;
1.1050 www 6251: padding: 4px;
6252: margin: 2px;
1.794 www 6253: }
6254:
6255: .LC_disc_new_item {
1.911 bisitz 6256: background: white;
6257: border: 2px solid red;
1.1050 www 6258: margin: 4px;
6259: padding: 4px;
1.794 www 6260: }
6261:
6262: .LC_disc_old_item {
1.911 bisitz 6263: background: white;
1.1050 www 6264: margin: 4px;
6265: padding: 4px;
1.794 www 6266: }
6267:
1.458 albertel 6268: table.LC_pastsubmission {
6269: border: 1px solid black;
6270: margin: 2px;
6271: }
6272:
1.924 bisitz 6273: table#LC_menubuttons {
1.345 albertel 6274: width: 100%;
6275: background: $pgbg;
1.392 albertel 6276: border: 2px;
1.402 albertel 6277: border-collapse: separate;
1.803 bisitz 6278: padding: 0;
1.345 albertel 6279: }
1.392 albertel 6280:
1.801 tempelho 6281: table#LC_title_bar a {
6282: color: $fontmenu;
6283: }
1.836 bisitz 6284:
1.807 droeschl 6285: table#LC_title_bar {
1.819 tempelho 6286: clear: both;
1.836 bisitz 6287: display: none;
1.807 droeschl 6288: }
6289:
1.795 www 6290: table#LC_title_bar,
1.933 droeschl 6291: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6292: table#LC_title_bar.LC_with_remote {
1.359 albertel 6293: width: 100%;
1.392 albertel 6294: border-color: $pgbg;
6295: border-style: solid;
6296: border-width: $border;
1.379 albertel 6297: background: $pgbg;
1.801 tempelho 6298: color: $fontmenu;
1.392 albertel 6299: border-collapse: collapse;
1.803 bisitz 6300: padding: 0;
1.819 tempelho 6301: margin: 0;
1.359 albertel 6302: }
1.795 www 6303:
1.933 droeschl 6304: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6305: margin: 0;
6306: padding: 0;
1.933 droeschl 6307: position: relative;
6308: list-style: none;
1.913 droeschl 6309: }
1.933 droeschl 6310: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6311: display: inline;
6312: }
1.933 droeschl 6313:
6314: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6315: padding: 0;
1.933 droeschl 6316: margin: 0;
6317: float: left;
1.913 droeschl 6318: }
1.933 droeschl 6319: .LC_breadcrumb_tools_tools {
6320: padding: 0;
6321: margin: 0;
1.913 droeschl 6322: float: right;
6323: }
6324:
1.1240 raeburn 6325: .LC_placement_prog {
6326: padding-right: 20px;
6327: font-weight: bold;
6328: font-size: 90%;
6329: }
6330:
1.359 albertel 6331: table#LC_title_bar td {
6332: background: $tabbg;
6333: }
1.795 www 6334:
1.911 bisitz 6335: table#LC_menubuttons img {
1.803 bisitz 6336: border: none;
1.346 albertel 6337: }
1.795 www 6338:
1.842 droeschl 6339: .LC_breadcrumbs_component {
1.911 bisitz 6340: float: right;
6341: margin: 0 1em;
1.357 albertel 6342: }
1.842 droeschl 6343: .LC_breadcrumbs_component img {
1.911 bisitz 6344: vertical-align: middle;
1.777 tempelho 6345: }
1.795 www 6346:
1.1243 raeburn 6347: .LC_breadcrumbs_hoverable {
6348: background: $sidebg;
6349: }
6350:
1.383 albertel 6351: td.LC_table_cell_checkbox {
6352: text-align: center;
6353: }
1.795 www 6354:
6355: .LC_fontsize_small {
1.911 bisitz 6356: font-size: 70%;
1.705 tempelho 6357: }
6358:
1.844 bisitz 6359: #LC_breadcrumbs {
1.911 bisitz 6360: clear:both;
6361: background: $sidebg;
6362: border-bottom: 1px solid $lg_border_color;
6363: line-height: 2.5em;
1.933 droeschl 6364: overflow: hidden;
1.911 bisitz 6365: margin: 0;
6366: padding: 0;
1.995 raeburn 6367: text-align: left;
1.819 tempelho 6368: }
1.862 bisitz 6369:
1.1098 bisitz 6370: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6371: clear:both;
6372: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6373: border: 1px solid $sidebg;
1.1098 bisitz 6374: margin: 0 0 10px 0;
1.966 bisitz 6375: padding: 3px;
1.995 raeburn 6376: text-align: left;
1.822 bisitz 6377: }
6378:
1.795 www 6379: .LC_fontsize_medium {
1.911 bisitz 6380: font-size: 85%;
1.705 tempelho 6381: }
6382:
1.795 www 6383: .LC_fontsize_large {
1.911 bisitz 6384: font-size: 120%;
1.705 tempelho 6385: }
6386:
1.346 albertel 6387: .LC_menubuttons_inline_text {
6388: color: $font;
1.698 harmsja 6389: font-size: 90%;
1.701 harmsja 6390: padding-left:3px;
1.346 albertel 6391: }
6392:
1.934 droeschl 6393: .LC_menubuttons_inline_text img{
6394: vertical-align: middle;
6395: }
6396:
1.1051 www 6397: li.LC_menubuttons_inline_text img {
1.951 onken 6398: cursor:pointer;
1.1002 droeschl 6399: text-decoration: none;
1.951 onken 6400: }
6401:
1.526 www 6402: .LC_menubuttons_link {
6403: text-decoration: none;
6404: }
1.795 www 6405:
1.522 albertel 6406: .LC_menubuttons_category {
1.521 www 6407: color: $font;
1.526 www 6408: background: $pgbg;
1.521 www 6409: font-size: larger;
6410: font-weight: bold;
6411: }
6412:
1.346 albertel 6413: td.LC_menubuttons_text {
1.911 bisitz 6414: color: $font;
1.346 albertel 6415: }
1.706 harmsja 6416:
1.346 albertel 6417: .LC_current_location {
6418: background: $tabbg;
6419: }
1.795 www 6420:
1.938 bisitz 6421: table.LC_data_table {
1.347 albertel 6422: border: 1px solid #000000;
1.402 albertel 6423: border-collapse: separate;
1.426 albertel 6424: border-spacing: 1px;
1.610 albertel 6425: background: $pgbg;
1.347 albertel 6426: }
1.795 www 6427:
1.422 albertel 6428: .LC_data_table_dense {
6429: font-size: small;
6430: }
1.795 www 6431:
1.507 raeburn 6432: table.LC_nested_outer {
6433: border: 1px solid #000000;
1.589 raeburn 6434: border-collapse: collapse;
1.803 bisitz 6435: border-spacing: 0;
1.507 raeburn 6436: width: 100%;
6437: }
1.795 www 6438:
1.879 raeburn 6439: table.LC_innerpickbox,
1.507 raeburn 6440: table.LC_nested {
1.803 bisitz 6441: border: none;
1.589 raeburn 6442: border-collapse: collapse;
1.803 bisitz 6443: border-spacing: 0;
1.507 raeburn 6444: width: 100%;
6445: }
1.795 www 6446:
1.911 bisitz 6447: table.LC_data_table tr th,
6448: table.LC_calendar tr th,
1.879 raeburn 6449: table.LC_prior_tries tr th,
6450: table.LC_innerpickbox tr th {
1.349 albertel 6451: font-weight: bold;
6452: background-color: $data_table_head;
1.801 tempelho 6453: color:$fontmenu;
1.701 harmsja 6454: font-size:90%;
1.347 albertel 6455: }
1.795 www 6456:
1.879 raeburn 6457: table.LC_innerpickbox tr th,
6458: table.LC_innerpickbox tr td {
6459: vertical-align: top;
6460: }
6461:
1.711 raeburn 6462: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6463: background-color: #CCCCCC;
1.711 raeburn 6464: font-weight: bold;
6465: text-align: left;
6466: }
1.795 www 6467:
1.912 bisitz 6468: table.LC_data_table tr.LC_odd_row > td {
6469: background-color: $data_table_light;
6470: padding: 2px;
6471: vertical-align: top;
6472: }
6473:
1.809 bisitz 6474: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6475: background-color: $data_table_light;
1.912 bisitz 6476: vertical-align: top;
6477: }
6478:
6479: table.LC_data_table tr.LC_even_row > td {
6480: background-color: $data_table_dark;
1.425 albertel 6481: padding: 2px;
1.900 bisitz 6482: vertical-align: top;
1.347 albertel 6483: }
1.795 www 6484:
1.809 bisitz 6485: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6486: background-color: $data_table_dark;
1.900 bisitz 6487: vertical-align: top;
1.347 albertel 6488: }
1.795 www 6489:
1.425 albertel 6490: table.LC_data_table tr.LC_data_table_highlight td {
6491: background-color: $data_table_darker;
6492: }
1.795 www 6493:
1.639 raeburn 6494: table.LC_data_table tr td.LC_leftcol_header {
6495: background-color: $data_table_head;
6496: font-weight: bold;
6497: }
1.795 www 6498:
1.451 albertel 6499: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6500: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6501: font-weight: bold;
6502: font-style: italic;
6503: text-align: center;
6504: padding: 8px;
1.347 albertel 6505: }
1.795 www 6506:
1.1114 raeburn 6507: table.LC_data_table tr.LC_empty_row td,
6508: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6509: background-color: $sidebg;
6510: }
6511:
6512: table.LC_nested tr.LC_empty_row td {
6513: background-color: #FFFFFF;
6514: }
6515:
1.890 droeschl 6516: table.LC_caption {
6517: }
6518:
1.507 raeburn 6519: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6520: padding: 4ex
6521: }
1.795 www 6522:
1.507 raeburn 6523: table.LC_nested_outer tr th {
6524: font-weight: bold;
1.801 tempelho 6525: color:$fontmenu;
1.507 raeburn 6526: background-color: $data_table_head;
1.701 harmsja 6527: font-size: small;
1.507 raeburn 6528: border-bottom: 1px solid #000000;
6529: }
1.795 www 6530:
1.507 raeburn 6531: table.LC_nested_outer tr td.LC_subheader {
6532: background-color: $data_table_head;
6533: font-weight: bold;
6534: font-size: small;
6535: border-bottom: 1px solid #000000;
6536: text-align: right;
1.451 albertel 6537: }
1.795 www 6538:
1.507 raeburn 6539: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6540: background-color: #CCCCCC;
1.451 albertel 6541: font-weight: bold;
6542: font-size: small;
1.507 raeburn 6543: text-align: center;
6544: }
1.795 www 6545:
1.589 raeburn 6546: table.LC_nested tr.LC_info_row td.LC_left_item,
6547: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6548: text-align: left;
1.451 albertel 6549: }
1.795 www 6550:
1.507 raeburn 6551: table.LC_nested td {
1.735 bisitz 6552: background-color: #FFFFFF;
1.451 albertel 6553: font-size: small;
1.507 raeburn 6554: }
1.795 www 6555:
1.507 raeburn 6556: table.LC_nested_outer tr th.LC_right_item,
6557: table.LC_nested tr.LC_info_row td.LC_right_item,
6558: table.LC_nested tr.LC_odd_row td.LC_right_item,
6559: table.LC_nested tr td.LC_right_item {
1.451 albertel 6560: text-align: right;
6561: }
6562:
1.507 raeburn 6563: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6564: background-color: #EEEEEE;
1.451 albertel 6565: }
6566:
1.473 raeburn 6567: table.LC_createuser {
6568: }
6569:
6570: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6571: font-size: small;
1.473 raeburn 6572: }
6573:
6574: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6575: background-color: #CCCCCC;
1.473 raeburn 6576: font-weight: bold;
6577: text-align: center;
6578: }
6579:
1.349 albertel 6580: table.LC_calendar {
6581: border: 1px solid #000000;
6582: border-collapse: collapse;
1.917 raeburn 6583: width: 98%;
1.349 albertel 6584: }
1.795 www 6585:
1.349 albertel 6586: table.LC_calendar_pickdate {
6587: font-size: xx-small;
6588: }
1.795 www 6589:
1.349 albertel 6590: table.LC_calendar tr td {
6591: border: 1px solid #000000;
6592: vertical-align: top;
1.917 raeburn 6593: width: 14%;
1.349 albertel 6594: }
1.795 www 6595:
1.349 albertel 6596: table.LC_calendar tr td.LC_calendar_day_empty {
6597: background-color: $data_table_dark;
6598: }
1.795 www 6599:
1.779 bisitz 6600: table.LC_calendar tr td.LC_calendar_day_current {
6601: background-color: $data_table_highlight;
1.777 tempelho 6602: }
1.795 www 6603:
1.938 bisitz 6604: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6605: background-color: $mail_new;
6606: }
1.795 www 6607:
1.938 bisitz 6608: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6609: background-color: $mail_new_hover;
6610: }
1.795 www 6611:
1.938 bisitz 6612: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6613: background-color: $mail_read;
6614: }
1.795 www 6615:
1.938 bisitz 6616: /*
6617: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6618: background-color: $mail_read_hover;
6619: }
1.938 bisitz 6620: */
1.795 www 6621:
1.938 bisitz 6622: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6623: background-color: $mail_replied;
6624: }
1.795 www 6625:
1.938 bisitz 6626: /*
6627: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6628: background-color: $mail_replied_hover;
6629: }
1.938 bisitz 6630: */
1.795 www 6631:
1.938 bisitz 6632: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6633: background-color: $mail_other;
6634: }
1.795 www 6635:
1.938 bisitz 6636: /*
6637: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6638: background-color: $mail_other_hover;
6639: }
1.938 bisitz 6640: */
1.494 raeburn 6641:
1.777 tempelho 6642: table.LC_data_table tr > td.LC_browser_file,
6643: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6644: background: #AAEE77;
1.389 albertel 6645: }
1.795 www 6646:
1.777 tempelho 6647: table.LC_data_table tr > td.LC_browser_file_locked,
6648: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6649: background: #FFAA99;
1.387 albertel 6650: }
1.795 www 6651:
1.777 tempelho 6652: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6653: background: #888888;
1.779 bisitz 6654: }
1.795 www 6655:
1.777 tempelho 6656: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6657: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6658: background: #F8F866;
1.777 tempelho 6659: }
1.795 www 6660:
1.696 bisitz 6661: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6662: background: #E0E8FF;
1.387 albertel 6663: }
1.696 bisitz 6664:
1.707 bisitz 6665: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6666: /* background: #77FF77; */
1.707 bisitz 6667: }
1.795 www 6668:
1.707 bisitz 6669: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6670: border-right: 8px solid #FFFF77;
1.707 bisitz 6671: }
1.795 www 6672:
1.707 bisitz 6673: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6674: border-right: 8px solid #FFAA77;
1.707 bisitz 6675: }
1.795 www 6676:
1.707 bisitz 6677: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6678: border-right: 8px solid #FF7777;
1.707 bisitz 6679: }
1.795 www 6680:
1.707 bisitz 6681: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6682: border-right: 8px solid #AAFF77;
1.707 bisitz 6683: }
1.795 www 6684:
1.707 bisitz 6685: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6686: border-right: 8px solid #11CC55;
1.707 bisitz 6687: }
6688:
1.388 albertel 6689: span.LC_current_location {
1.701 harmsja 6690: font-size:larger;
1.388 albertel 6691: background: $pgbg;
6692: }
1.387 albertel 6693:
1.1029 www 6694: span.LC_current_nav_location {
6695: font-weight:bold;
6696: background: $sidebg;
6697: }
6698:
1.395 albertel 6699: span.LC_parm_menu_item {
6700: font-size: larger;
6701: }
1.795 www 6702:
1.395 albertel 6703: span.LC_parm_scope_all {
6704: color: red;
6705: }
1.795 www 6706:
1.395 albertel 6707: span.LC_parm_scope_folder {
6708: color: green;
6709: }
1.795 www 6710:
1.395 albertel 6711: span.LC_parm_scope_resource {
6712: color: orange;
6713: }
1.795 www 6714:
1.395 albertel 6715: span.LC_parm_part {
6716: color: blue;
6717: }
1.795 www 6718:
1.911 bisitz 6719: span.LC_parm_folder,
6720: span.LC_parm_symb {
1.395 albertel 6721: font-size: x-small;
6722: font-family: $mono;
6723: color: #AAAAAA;
6724: }
6725:
1.977 bisitz 6726: ul.LC_parm_parmlist li {
6727: display: inline-block;
6728: padding: 0.3em 0.8em;
6729: vertical-align: top;
6730: width: 150px;
6731: border-top:1px solid $lg_border_color;
6732: }
6733:
1.795 www 6734: td.LC_parm_overview_level_menu,
6735: td.LC_parm_overview_map_menu,
6736: td.LC_parm_overview_parm_selectors,
6737: td.LC_parm_overview_restrictions {
1.396 albertel 6738: border: 1px solid black;
6739: border-collapse: collapse;
6740: }
1.795 www 6741:
1.396 albertel 6742: table.LC_parm_overview_restrictions td {
6743: border-width: 1px 4px 1px 4px;
6744: border-style: solid;
6745: border-color: $pgbg;
6746: text-align: center;
6747: }
1.795 www 6748:
1.396 albertel 6749: table.LC_parm_overview_restrictions th {
6750: background: $tabbg;
6751: border-width: 1px 4px 1px 4px;
6752: border-style: solid;
6753: border-color: $pgbg;
6754: }
1.795 www 6755:
1.398 albertel 6756: table#LC_helpmenu {
1.803 bisitz 6757: border: none;
1.398 albertel 6758: height: 55px;
1.803 bisitz 6759: border-spacing: 0;
1.398 albertel 6760: }
6761:
6762: table#LC_helpmenu fieldset legend {
6763: font-size: larger;
6764: }
1.795 www 6765:
1.397 albertel 6766: table#LC_helpmenu_links {
6767: width: 100%;
6768: border: 1px solid black;
6769: background: $pgbg;
1.803 bisitz 6770: padding: 0;
1.397 albertel 6771: border-spacing: 1px;
6772: }
1.795 www 6773:
1.397 albertel 6774: table#LC_helpmenu_links tr td {
6775: padding: 1px;
6776: background: $tabbg;
1.399 albertel 6777: text-align: center;
6778: font-weight: bold;
1.397 albertel 6779: }
1.396 albertel 6780:
1.795 www 6781: table#LC_helpmenu_links a:link,
6782: table#LC_helpmenu_links a:visited,
1.397 albertel 6783: table#LC_helpmenu_links a:active {
6784: text-decoration: none;
6785: color: $font;
6786: }
1.795 www 6787:
1.397 albertel 6788: table#LC_helpmenu_links a:hover {
6789: text-decoration: underline;
6790: color: $vlink;
6791: }
1.396 albertel 6792:
1.417 albertel 6793: .LC_chrt_popup_exists {
6794: border: 1px solid #339933;
6795: margin: -1px;
6796: }
1.795 www 6797:
1.417 albertel 6798: .LC_chrt_popup_up {
6799: border: 1px solid yellow;
6800: margin: -1px;
6801: }
1.795 www 6802:
1.417 albertel 6803: .LC_chrt_popup {
6804: border: 1px solid #8888FF;
6805: background: #CCCCFF;
6806: }
1.795 www 6807:
1.421 albertel 6808: table.LC_pick_box {
6809: border-collapse: separate;
6810: background: white;
6811: border: 1px solid black;
6812: border-spacing: 1px;
6813: }
1.795 www 6814:
1.421 albertel 6815: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6816: background: $sidebg;
1.421 albertel 6817: font-weight: bold;
1.900 bisitz 6818: text-align: left;
1.740 bisitz 6819: vertical-align: top;
1.421 albertel 6820: width: 184px;
6821: padding: 8px;
6822: }
1.795 www 6823:
1.579 raeburn 6824: table.LC_pick_box td.LC_pick_box_value {
6825: text-align: left;
6826: padding: 8px;
6827: }
1.795 www 6828:
1.579 raeburn 6829: table.LC_pick_box td.LC_pick_box_select {
6830: text-align: left;
6831: padding: 8px;
6832: }
1.795 www 6833:
1.424 albertel 6834: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6835: padding: 0;
1.421 albertel 6836: height: 1px;
6837: background: black;
6838: }
1.795 www 6839:
1.421 albertel 6840: table.LC_pick_box td.LC_pick_box_submit {
6841: text-align: right;
6842: }
1.795 www 6843:
1.579 raeburn 6844: table.LC_pick_box td.LC_evenrow_value {
6845: text-align: left;
6846: padding: 8px;
6847: background-color: $data_table_light;
6848: }
1.795 www 6849:
1.579 raeburn 6850: table.LC_pick_box td.LC_oddrow_value {
6851: text-align: left;
6852: padding: 8px;
6853: background-color: $data_table_light;
6854: }
1.795 www 6855:
1.579 raeburn 6856: span.LC_helpform_receipt_cat {
6857: font-weight: bold;
6858: }
1.795 www 6859:
1.424 albertel 6860: table.LC_group_priv_box {
6861: background: white;
6862: border: 1px solid black;
6863: border-spacing: 1px;
6864: }
1.795 www 6865:
1.424 albertel 6866: table.LC_group_priv_box td.LC_pick_box_title {
6867: background: $tabbg;
6868: font-weight: bold;
6869: text-align: right;
6870: width: 184px;
6871: }
1.795 www 6872:
1.424 albertel 6873: table.LC_group_priv_box td.LC_groups_fixed {
6874: background: $data_table_light;
6875: text-align: center;
6876: }
1.795 www 6877:
1.424 albertel 6878: table.LC_group_priv_box td.LC_groups_optional {
6879: background: $data_table_dark;
6880: text-align: center;
6881: }
1.795 www 6882:
1.424 albertel 6883: table.LC_group_priv_box td.LC_groups_functionality {
6884: background: $data_table_darker;
6885: text-align: center;
6886: font-weight: bold;
6887: }
1.795 www 6888:
1.424 albertel 6889: table.LC_group_priv td {
6890: text-align: left;
1.803 bisitz 6891: padding: 0;
1.424 albertel 6892: }
6893:
6894: .LC_navbuttons {
6895: margin: 2ex 0ex 2ex 0ex;
6896: }
1.795 www 6897:
1.423 albertel 6898: .LC_topic_bar {
6899: font-weight: bold;
6900: background: $tabbg;
1.918 wenzelju 6901: margin: 1em 0em 1em 2em;
1.805 bisitz 6902: padding: 3px;
1.918 wenzelju 6903: font-size: 1.2em;
1.423 albertel 6904: }
1.795 www 6905:
1.423 albertel 6906: .LC_topic_bar span {
1.918 wenzelju 6907: left: 0.5em;
6908: position: absolute;
1.423 albertel 6909: vertical-align: middle;
1.918 wenzelju 6910: font-size: 1.2em;
1.423 albertel 6911: }
1.795 www 6912:
1.423 albertel 6913: table.LC_course_group_status {
6914: margin: 20px;
6915: }
1.795 www 6916:
1.423 albertel 6917: table.LC_status_selector td {
6918: vertical-align: top;
6919: text-align: center;
1.424 albertel 6920: padding: 4px;
6921: }
1.795 www 6922:
1.599 albertel 6923: div.LC_feedback_link {
1.616 albertel 6924: clear: both;
1.829 kalberla 6925: background: $sidebg;
1.779 bisitz 6926: width: 100%;
1.829 kalberla 6927: padding-bottom: 10px;
6928: border: 1px $tabbg solid;
1.833 kalberla 6929: height: 22px;
6930: line-height: 22px;
6931: padding-top: 5px;
6932: }
6933:
6934: div.LC_feedback_link img {
6935: height: 22px;
1.867 kalberla 6936: vertical-align:middle;
1.829 kalberla 6937: }
6938:
1.911 bisitz 6939: div.LC_feedback_link a {
1.829 kalberla 6940: text-decoration: none;
1.489 raeburn 6941: }
1.795 www 6942:
1.867 kalberla 6943: div.LC_comblock {
1.911 bisitz 6944: display:inline;
1.867 kalberla 6945: color:$font;
6946: font-size:90%;
6947: }
6948:
6949: div.LC_feedback_link div.LC_comblock {
6950: padding-left:5px;
6951: }
6952:
6953: div.LC_feedback_link div.LC_comblock a {
6954: color:$font;
6955: }
6956:
1.489 raeburn 6957: span.LC_feedback_link {
1.858 bisitz 6958: /* background: $feedback_link_bg; */
1.599 albertel 6959: font-size: larger;
6960: }
1.795 www 6961:
1.599 albertel 6962: span.LC_message_link {
1.858 bisitz 6963: /* background: $feedback_link_bg; */
1.599 albertel 6964: font-size: larger;
6965: position: absolute;
6966: right: 1em;
1.489 raeburn 6967: }
1.421 albertel 6968:
1.515 albertel 6969: table.LC_prior_tries {
1.524 albertel 6970: border: 1px solid #000000;
6971: border-collapse: separate;
6972: border-spacing: 1px;
1.515 albertel 6973: }
1.523 albertel 6974:
1.515 albertel 6975: table.LC_prior_tries td {
1.524 albertel 6976: padding: 2px;
1.515 albertel 6977: }
1.523 albertel 6978:
6979: .LC_answer_correct {
1.795 www 6980: background: lightgreen;
6981: color: darkgreen;
6982: padding: 6px;
1.523 albertel 6983: }
1.795 www 6984:
1.523 albertel 6985: .LC_answer_charged_try {
1.797 www 6986: background: #FFAAAA;
1.795 www 6987: color: darkred;
6988: padding: 6px;
1.523 albertel 6989: }
1.795 www 6990:
1.779 bisitz 6991: .LC_answer_not_charged_try,
1.523 albertel 6992: .LC_answer_no_grade,
6993: .LC_answer_late {
1.795 www 6994: background: lightyellow;
1.523 albertel 6995: color: black;
1.795 www 6996: padding: 6px;
1.523 albertel 6997: }
1.795 www 6998:
1.523 albertel 6999: .LC_answer_previous {
1.795 www 7000: background: lightblue;
7001: color: darkblue;
7002: padding: 6px;
1.523 albertel 7003: }
1.795 www 7004:
1.779 bisitz 7005: .LC_answer_no_message {
1.777 tempelho 7006: background: #FFFFFF;
7007: color: black;
1.795 www 7008: padding: 6px;
1.779 bisitz 7009: }
1.795 www 7010:
1.779 bisitz 7011: .LC_answer_unknown {
7012: background: orange;
7013: color: black;
1.795 www 7014: padding: 6px;
1.777 tempelho 7015: }
1.795 www 7016:
1.529 albertel 7017: span.LC_prior_numerical,
7018: span.LC_prior_string,
7019: span.LC_prior_custom,
7020: span.LC_prior_reaction,
7021: span.LC_prior_math {
1.925 bisitz 7022: font-family: $mono;
1.523 albertel 7023: white-space: pre;
7024: }
7025:
1.525 albertel 7026: span.LC_prior_string {
1.925 bisitz 7027: font-family: $mono;
1.525 albertel 7028: white-space: pre;
7029: }
7030:
1.523 albertel 7031: table.LC_prior_option {
7032: width: 100%;
7033: border-collapse: collapse;
7034: }
1.795 www 7035:
1.911 bisitz 7036: table.LC_prior_rank,
1.795 www 7037: table.LC_prior_match {
1.528 albertel 7038: border-collapse: collapse;
7039: }
1.795 www 7040:
1.528 albertel 7041: table.LC_prior_option tr td,
7042: table.LC_prior_rank tr td,
7043: table.LC_prior_match tr td {
1.524 albertel 7044: border: 1px solid #000000;
1.515 albertel 7045: }
7046:
1.855 bisitz 7047: .LC_nobreak {
1.544 albertel 7048: white-space: nowrap;
1.519 raeburn 7049: }
7050:
1.576 raeburn 7051: span.LC_cusr_emph {
7052: font-style: italic;
7053: }
7054:
1.633 raeburn 7055: span.LC_cusr_subheading {
7056: font-weight: normal;
7057: font-size: 85%;
7058: }
7059:
1.861 bisitz 7060: div.LC_docs_entry_move {
1.859 bisitz 7061: border: 1px solid #BBBBBB;
1.545 albertel 7062: background: #DDDDDD;
1.861 bisitz 7063: width: 22px;
1.859 bisitz 7064: padding: 1px;
7065: margin: 0;
1.545 albertel 7066: }
7067:
1.861 bisitz 7068: table.LC_data_table tr > td.LC_docs_entry_commands,
7069: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7070: font-size: x-small;
7071: }
1.795 www 7072:
1.861 bisitz 7073: .LC_docs_entry_parameter {
7074: white-space: nowrap;
7075: }
7076:
1.544 albertel 7077: .LC_docs_copy {
1.545 albertel 7078: color: #000099;
1.544 albertel 7079: }
1.795 www 7080:
1.544 albertel 7081: .LC_docs_cut {
1.545 albertel 7082: color: #550044;
1.544 albertel 7083: }
1.795 www 7084:
1.544 albertel 7085: .LC_docs_rename {
1.545 albertel 7086: color: #009900;
1.544 albertel 7087: }
1.795 www 7088:
1.544 albertel 7089: .LC_docs_remove {
1.545 albertel 7090: color: #990000;
7091: }
7092:
1.547 albertel 7093: .LC_docs_reinit_warn,
7094: .LC_docs_ext_edit {
7095: font-size: x-small;
7096: }
7097:
1.545 albertel 7098: table.LC_docs_adddocs td,
7099: table.LC_docs_adddocs th {
7100: border: 1px solid #BBBBBB;
7101: padding: 4px;
7102: background: #DDDDDD;
1.543 albertel 7103: }
7104:
1.584 albertel 7105: table.LC_sty_begin {
7106: background: #BBFFBB;
7107: }
1.795 www 7108:
1.584 albertel 7109: table.LC_sty_end {
7110: background: #FFBBBB;
7111: }
7112:
1.589 raeburn 7113: table.LC_double_column {
1.803 bisitz 7114: border-width: 0;
1.589 raeburn 7115: border-collapse: collapse;
7116: width: 100%;
7117: padding: 2px;
7118: }
7119:
7120: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7121: top: 2px;
1.589 raeburn 7122: left: 2px;
7123: width: 47%;
7124: vertical-align: top;
7125: }
7126:
7127: table.LC_double_column tr td.LC_right_col {
7128: top: 2px;
1.779 bisitz 7129: right: 2px;
1.589 raeburn 7130: width: 47%;
7131: vertical-align: top;
7132: }
7133:
1.591 raeburn 7134: div.LC_left_float {
7135: float: left;
7136: padding-right: 5%;
1.597 albertel 7137: padding-bottom: 4px;
1.591 raeburn 7138: }
7139:
7140: div.LC_clear_float_header {
1.597 albertel 7141: padding-bottom: 2px;
1.591 raeburn 7142: }
7143:
7144: div.LC_clear_float_footer {
1.597 albertel 7145: padding-top: 10px;
1.591 raeburn 7146: clear: both;
7147: }
7148:
1.597 albertel 7149: div.LC_grade_show_user {
1.941 bisitz 7150: /* border-left: 5px solid $sidebg; */
7151: border-top: 5px solid #000000;
7152: margin: 50px 0 0 0;
1.936 bisitz 7153: padding: 15px 0 5px 10px;
1.597 albertel 7154: }
1.795 www 7155:
1.936 bisitz 7156: div.LC_grade_show_user_odd_row {
1.941 bisitz 7157: /* border-left: 5px solid #000000; */
7158: }
7159:
7160: div.LC_grade_show_user div.LC_Box {
7161: margin-right: 50px;
1.597 albertel 7162: }
7163:
7164: div.LC_grade_submissions,
7165: div.LC_grade_message_center,
1.936 bisitz 7166: div.LC_grade_info_links {
1.597 albertel 7167: margin: 5px;
7168: width: 99%;
7169: background: #FFFFFF;
7170: }
1.795 www 7171:
1.597 albertel 7172: div.LC_grade_submissions_header,
1.936 bisitz 7173: div.LC_grade_message_center_header {
1.705 tempelho 7174: font-weight: bold;
7175: font-size: large;
1.597 albertel 7176: }
1.795 www 7177:
1.597 albertel 7178: div.LC_grade_submissions_body,
1.936 bisitz 7179: div.LC_grade_message_center_body {
1.597 albertel 7180: border: 1px solid black;
7181: width: 99%;
7182: background: #FFFFFF;
7183: }
1.795 www 7184:
1.613 albertel 7185: table.LC_scantron_action {
7186: width: 100%;
7187: }
1.795 www 7188:
1.613 albertel 7189: table.LC_scantron_action tr th {
1.698 harmsja 7190: font-weight:bold;
7191: font-style:normal;
1.613 albertel 7192: }
1.795 www 7193:
1.779 bisitz 7194: .LC_edit_problem_header,
1.614 albertel 7195: div.LC_edit_problem_footer {
1.705 tempelho 7196: font-weight: normal;
7197: font-size: medium;
1.602 albertel 7198: margin: 2px;
1.1060 bisitz 7199: background-color: $sidebg;
1.600 albertel 7200: }
1.795 www 7201:
1.600 albertel 7202: div.LC_edit_problem_header,
1.602 albertel 7203: div.LC_edit_problem_header div,
1.614 albertel 7204: div.LC_edit_problem_footer,
7205: div.LC_edit_problem_footer div,
1.602 albertel 7206: div.LC_edit_problem_editxml_header,
7207: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7208: z-index: 100;
1.600 albertel 7209: }
1.795 www 7210:
1.600 albertel 7211: div.LC_edit_problem_header_title {
1.705 tempelho 7212: font-weight: bold;
7213: font-size: larger;
1.602 albertel 7214: background: $tabbg;
7215: padding: 3px;
1.1060 bisitz 7216: margin: 0 0 5px 0;
1.602 albertel 7217: }
1.795 www 7218:
1.602 albertel 7219: table.LC_edit_problem_header_title {
7220: width: 100%;
1.600 albertel 7221: background: $tabbg;
1.602 albertel 7222: }
7223:
1.1205 golterma 7224: div.LC_edit_actionbar {
7225: background-color: $sidebg;
1.1218 droeschl 7226: margin: 0;
7227: padding: 0;
7228: line-height: 200%;
1.602 albertel 7229: }
1.795 www 7230:
1.1218 droeschl 7231: div.LC_edit_actionbar div{
7232: padding: 0;
7233: margin: 0;
7234: display: inline-block;
1.600 albertel 7235: }
1.795 www 7236:
1.1124 bisitz 7237: .LC_edit_opt {
7238: padding-left: 1em;
7239: white-space: nowrap;
7240: }
7241:
1.1152 golterma 7242: .LC_edit_problem_latexhelper{
7243: text-align: right;
7244: }
7245:
7246: #LC_edit_problem_colorful div{
7247: margin-left: 40px;
7248: }
7249:
1.1205 golterma 7250: #LC_edit_problem_codemirror div{
7251: margin-left: 0px;
7252: }
7253:
1.911 bisitz 7254: img.stift {
1.803 bisitz 7255: border-width: 0;
7256: vertical-align: middle;
1.677 riegler 7257: }
1.680 riegler 7258:
1.923 bisitz 7259: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7260: vertical-align: top;
1.777 tempelho 7261: }
1.795 www 7262:
1.716 raeburn 7263: div.LC_createcourse {
1.911 bisitz 7264: margin: 10px 10px 10px 10px;
1.716 raeburn 7265: }
7266:
1.917 raeburn 7267: .LC_dccid {
1.1130 raeburn 7268: float: right;
1.917 raeburn 7269: margin: 0.2em 0 0 0;
7270: padding: 0;
7271: font-size: 90%;
7272: display:none;
7273: }
7274:
1.897 wenzelju 7275: ol.LC_primary_menu a:hover,
1.721 harmsja 7276: ol#LC_MenuBreadcrumbs a:hover,
7277: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7278: ul#LC_secondary_menu a:hover,
1.721 harmsja 7279: .LC_FormSectionClearButton input:hover
1.795 www 7280: ul.LC_TabContent li:hover a {
1.952 onken 7281: color:$button_hover;
1.911 bisitz 7282: text-decoration:none;
1.693 droeschl 7283: }
7284:
1.779 bisitz 7285: h1 {
1.911 bisitz 7286: padding: 0;
7287: line-height:130%;
1.693 droeschl 7288: }
1.698 harmsja 7289:
1.911 bisitz 7290: h2,
7291: h3,
7292: h4,
7293: h5,
7294: h6 {
7295: margin: 5px 0 5px 0;
7296: padding: 0;
7297: line-height:130%;
1.693 droeschl 7298: }
1.795 www 7299:
7300: .LC_hcell {
1.911 bisitz 7301: padding:3px 15px 3px 15px;
7302: margin: 0;
7303: background-color:$tabbg;
7304: color:$fontmenu;
7305: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7306: }
1.795 www 7307:
1.840 bisitz 7308: .LC_Box > .LC_hcell {
1.911 bisitz 7309: margin: 0 -10px 10px -10px;
1.835 bisitz 7310: }
7311:
1.721 harmsja 7312: .LC_noBorder {
1.911 bisitz 7313: border: 0;
1.698 harmsja 7314: }
1.693 droeschl 7315:
1.721 harmsja 7316: .LC_FormSectionClearButton input {
1.911 bisitz 7317: background-color:transparent;
7318: border: none;
7319: cursor:pointer;
7320: text-decoration:underline;
1.693 droeschl 7321: }
1.763 bisitz 7322:
7323: .LC_help_open_topic {
1.911 bisitz 7324: color: #FFFFFF;
7325: background-color: #EEEEFF;
7326: margin: 1px;
7327: padding: 4px;
7328: border: 1px solid #000033;
7329: white-space: nowrap;
7330: /* vertical-align: middle; */
1.759 neumanie 7331: }
1.693 droeschl 7332:
1.911 bisitz 7333: dl,
7334: ul,
7335: div,
7336: fieldset {
7337: margin: 10px 10px 10px 0;
7338: /* overflow: hidden; */
1.693 droeschl 7339: }
1.795 www 7340:
1.1211 raeburn 7341: article.geogebraweb div {
7342: margin: 0;
7343: }
7344:
1.838 bisitz 7345: fieldset > legend {
1.911 bisitz 7346: font-weight: bold;
7347: padding: 0 5px 0 5px;
1.838 bisitz 7348: }
7349:
1.813 bisitz 7350: #LC_nav_bar {
1.911 bisitz 7351: float: left;
1.995 raeburn 7352: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7353: margin: 0 0 2px 0;
1.807 droeschl 7354: }
7355:
1.916 droeschl 7356: #LC_realm {
7357: margin: 0.2em 0 0 0;
7358: padding: 0;
7359: font-weight: bold;
7360: text-align: center;
1.995 raeburn 7361: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7362: }
7363:
1.911 bisitz 7364: #LC_nav_bar em {
7365: font-weight: bold;
7366: font-style: normal;
1.807 droeschl 7367: }
7368:
1.897 wenzelju 7369: ol.LC_primary_menu {
1.934 droeschl 7370: margin: 0;
1.1076 raeburn 7371: padding: 0;
1.807 droeschl 7372: }
7373:
1.852 droeschl 7374: ol#LC_PathBreadcrumbs {
1.911 bisitz 7375: margin: 0;
1.693 droeschl 7376: }
7377:
1.897 wenzelju 7378: ol.LC_primary_menu li {
1.1076 raeburn 7379: color: RGB(80, 80, 80);
7380: vertical-align: middle;
7381: text-align: left;
7382: list-style: none;
1.1205 golterma 7383: position: relative;
1.1076 raeburn 7384: float: left;
1.1205 golterma 7385: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7386: line-height: 1.5em;
1.1076 raeburn 7387: }
7388:
1.1205 golterma 7389: ol.LC_primary_menu li a,
7390: ol.LC_primary_menu li p {
1.1076 raeburn 7391: display: block;
7392: margin: 0;
7393: padding: 0 5px 0 10px;
7394: text-decoration: none;
7395: }
7396:
1.1205 golterma 7397: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7398: display: inline-block;
7399: width: 95%;
7400: text-align: left;
7401: }
7402:
7403: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7404: display: inline-block;
7405: width: 5%;
7406: float: right;
7407: text-align: right;
7408: font-size: 70%;
7409: }
7410:
7411: ol.LC_primary_menu ul {
1.1076 raeburn 7412: display: none;
1.1205 golterma 7413: width: 15em;
1.1076 raeburn 7414: background-color: $data_table_light;
1.1205 golterma 7415: position: absolute;
7416: top: 100%;
1.1076 raeburn 7417: }
7418:
1.1205 golterma 7419: ol.LC_primary_menu ul ul {
7420: left: 100%;
7421: top: 0;
7422: }
7423:
7424: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7425: display: block;
7426: position: absolute;
7427: margin: 0;
7428: padding: 0;
1.1078 raeburn 7429: z-index: 2;
1.1076 raeburn 7430: }
7431:
7432: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7433: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7434: font-size: 90%;
1.911 bisitz 7435: vertical-align: top;
1.1076 raeburn 7436: float: none;
1.1079 raeburn 7437: border-left: 1px solid black;
7438: border-right: 1px solid black;
1.1205 golterma 7439: /* A dark bottom border to visualize different menu options;
7440: overwritten in the create_submenu routine for the last border-bottom of the menu */
7441: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7442: }
7443:
1.1205 golterma 7444: ol.LC_primary_menu li li p:hover {
7445: color:$button_hover;
7446: text-decoration:none;
7447: background-color:$data_table_dark;
1.1076 raeburn 7448: }
7449:
7450: ol.LC_primary_menu li li a:hover {
7451: color:$button_hover;
7452: background-color:$data_table_dark;
1.693 droeschl 7453: }
7454:
1.1205 golterma 7455: /* Font-size equal to the size of the predecessors*/
7456: ol.LC_primary_menu li:hover li li {
7457: font-size: 100%;
7458: }
7459:
1.897 wenzelju 7460: ol.LC_primary_menu li img {
1.911 bisitz 7461: vertical-align: bottom;
1.934 droeschl 7462: height: 1.1em;
1.1077 raeburn 7463: margin: 0.2em 0 0 0;
1.693 droeschl 7464: }
7465:
1.897 wenzelju 7466: ol.LC_primary_menu a {
1.911 bisitz 7467: color: RGB(80, 80, 80);
7468: text-decoration: none;
1.693 droeschl 7469: }
1.795 www 7470:
1.949 droeschl 7471: ol.LC_primary_menu a.LC_new_message {
7472: font-weight:bold;
7473: color: darkred;
7474: }
7475:
1.975 raeburn 7476: ol.LC_docs_parameters {
7477: margin-left: 0;
7478: padding: 0;
7479: list-style: none;
7480: }
7481:
7482: ol.LC_docs_parameters li {
7483: margin: 0;
7484: padding-right: 20px;
7485: display: inline;
7486: }
7487:
1.976 raeburn 7488: ol.LC_docs_parameters li:before {
7489: content: "\\002022 \\0020";
7490: }
7491:
7492: li.LC_docs_parameters_title {
7493: font-weight: bold;
7494: }
7495:
7496: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7497: content: "";
7498: }
7499:
1.897 wenzelju 7500: ul#LC_secondary_menu {
1.1107 raeburn 7501: clear: right;
1.911 bisitz 7502: color: $fontmenu;
7503: background: $tabbg;
7504: list-style: none;
7505: padding: 0;
7506: margin: 0;
7507: width: 100%;
1.995 raeburn 7508: text-align: left;
1.1107 raeburn 7509: float: left;
1.808 droeschl 7510: }
7511:
1.897 wenzelju 7512: ul#LC_secondary_menu li {
1.911 bisitz 7513: font-weight: bold;
7514: line-height: 1.8em;
1.1107 raeburn 7515: border-right: 1px solid black;
7516: float: left;
7517: }
7518:
7519: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7520: background-color: $data_table_light;
7521: }
7522:
7523: ul#LC_secondary_menu li a {
1.911 bisitz 7524: padding: 0 0.8em;
1.1107 raeburn 7525: }
7526:
7527: ul#LC_secondary_menu li ul {
7528: display: none;
7529: }
7530:
7531: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7532: display: block;
7533: position: absolute;
7534: margin: 0;
7535: padding: 0;
7536: list-style:none;
7537: float: none;
7538: background-color: $data_table_light;
7539: z-index: 2;
7540: margin-left: -1px;
7541: }
7542:
7543: ul#LC_secondary_menu li ul li {
7544: font-size: 90%;
7545: vertical-align: top;
7546: border-left: 1px solid black;
1.911 bisitz 7547: border-right: 1px solid black;
1.1119 raeburn 7548: background-color: $data_table_light;
1.1107 raeburn 7549: list-style:none;
7550: float: none;
7551: }
7552:
7553: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7554: background-color: $data_table_dark;
1.807 droeschl 7555: }
7556:
1.847 tempelho 7557: ul.LC_TabContent {
1.911 bisitz 7558: display:block;
7559: background: $sidebg;
7560: border-bottom: solid 1px $lg_border_color;
7561: list-style:none;
1.1020 raeburn 7562: margin: -1px -10px 0 -10px;
1.911 bisitz 7563: padding: 0;
1.693 droeschl 7564: }
7565:
1.795 www 7566: ul.LC_TabContent li,
7567: ul.LC_TabContentBigger li {
1.911 bisitz 7568: float:left;
1.741 harmsja 7569: }
1.795 www 7570:
1.897 wenzelju 7571: ul#LC_secondary_menu li a {
1.911 bisitz 7572: color: $fontmenu;
7573: text-decoration: none;
1.693 droeschl 7574: }
1.795 www 7575:
1.721 harmsja 7576: ul.LC_TabContent {
1.952 onken 7577: min-height:20px;
1.721 harmsja 7578: }
1.795 www 7579:
7580: ul.LC_TabContent li {
1.911 bisitz 7581: vertical-align:middle;
1.959 onken 7582: padding: 0 16px 0 10px;
1.911 bisitz 7583: background-color:$tabbg;
7584: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7585: border-left: solid 1px $font;
1.721 harmsja 7586: }
1.795 www 7587:
1.847 tempelho 7588: ul.LC_TabContent .right {
1.911 bisitz 7589: float:right;
1.847 tempelho 7590: }
7591:
1.911 bisitz 7592: ul.LC_TabContent li a,
7593: ul.LC_TabContent li {
7594: color:rgb(47,47,47);
7595: text-decoration:none;
7596: font-size:95%;
7597: font-weight:bold;
1.952 onken 7598: min-height:20px;
7599: }
7600:
1.959 onken 7601: ul.LC_TabContent li a:hover,
7602: ul.LC_TabContent li a:focus {
1.952 onken 7603: color: $button_hover;
1.959 onken 7604: background:none;
7605: outline:none;
1.952 onken 7606: }
7607:
7608: ul.LC_TabContent li:hover {
7609: color: $button_hover;
7610: cursor:pointer;
1.721 harmsja 7611: }
1.795 www 7612:
1.911 bisitz 7613: ul.LC_TabContent li.active {
1.952 onken 7614: color: $font;
1.911 bisitz 7615: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7616: border-bottom:solid 1px #FFFFFF;
7617: cursor: default;
1.744 ehlerst 7618: }
1.795 www 7619:
1.959 onken 7620: ul.LC_TabContent li.active a {
7621: color:$font;
7622: background:#FFFFFF;
7623: outline: none;
7624: }
1.1047 raeburn 7625:
7626: ul.LC_TabContent li.goback {
7627: float: left;
7628: border-left: none;
7629: }
7630:
1.870 tempelho 7631: #maincoursedoc {
1.911 bisitz 7632: clear:both;
1.870 tempelho 7633: }
7634:
7635: ul.LC_TabContentBigger {
1.911 bisitz 7636: display:block;
7637: list-style:none;
7638: padding: 0;
1.870 tempelho 7639: }
7640:
1.795 www 7641: ul.LC_TabContentBigger li {
1.911 bisitz 7642: vertical-align:bottom;
7643: height: 30px;
7644: font-size:110%;
7645: font-weight:bold;
7646: color: #737373;
1.841 tempelho 7647: }
7648:
1.957 onken 7649: ul.LC_TabContentBigger li.active {
7650: position: relative;
7651: top: 1px;
7652: }
7653:
1.870 tempelho 7654: ul.LC_TabContentBigger li a {
1.911 bisitz 7655: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7656: height: 30px;
7657: line-height: 30px;
7658: text-align: center;
7659: display: block;
7660: text-decoration: none;
1.958 onken 7661: outline: none;
1.741 harmsja 7662: }
1.795 www 7663:
1.870 tempelho 7664: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7665: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7666: color:$font;
1.744 ehlerst 7667: }
1.795 www 7668:
1.870 tempelho 7669: ul.LC_TabContentBigger li b {
1.911 bisitz 7670: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7671: display: block;
7672: float: left;
7673: padding: 0 30px;
1.957 onken 7674: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7675: }
7676:
1.956 onken 7677: ul.LC_TabContentBigger li:hover b {
7678: color:$button_hover;
7679: }
7680:
1.870 tempelho 7681: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7682: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7683: color:$font;
1.957 onken 7684: border: 0;
1.741 harmsja 7685: }
1.693 droeschl 7686:
1.870 tempelho 7687:
1.862 bisitz 7688: ul.LC_CourseBreadcrumbs {
7689: background: $sidebg;
1.1020 raeburn 7690: height: 2em;
1.862 bisitz 7691: padding-left: 10px;
1.1020 raeburn 7692: margin: 0;
1.862 bisitz 7693: list-style-position: inside;
7694: }
7695:
1.911 bisitz 7696: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7697: ol#LC_PathBreadcrumbs {
1.911 bisitz 7698: padding-left: 10px;
7699: margin: 0;
1.933 droeschl 7700: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7701: }
7702:
1.911 bisitz 7703: ol#LC_MenuBreadcrumbs li,
7704: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7705: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7706: display: inline;
1.933 droeschl 7707: white-space: normal;
1.693 droeschl 7708: }
7709:
1.823 bisitz 7710: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7711: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7712: text-decoration: none;
7713: font-size:90%;
1.693 droeschl 7714: }
1.795 www 7715:
1.969 droeschl 7716: ol#LC_MenuBreadcrumbs h1 {
7717: display: inline;
7718: font-size: 90%;
7719: line-height: 2.5em;
7720: margin: 0;
7721: padding: 0;
7722: }
7723:
1.795 www 7724: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7725: text-decoration:none;
7726: font-size:100%;
7727: font-weight:bold;
1.693 droeschl 7728: }
1.795 www 7729:
1.840 bisitz 7730: .LC_Box {
1.911 bisitz 7731: border: solid 1px $lg_border_color;
7732: padding: 0 10px 10px 10px;
1.746 neumanie 7733: }
1.795 www 7734:
1.1020 raeburn 7735: .LC_DocsBox {
7736: border: solid 1px $lg_border_color;
7737: padding: 0 0 10px 10px;
7738: }
7739:
1.795 www 7740: .LC_AboutMe_Image {
1.911 bisitz 7741: float:left;
7742: margin-right:10px;
1.747 neumanie 7743: }
1.795 www 7744:
7745: .LC_Clear_AboutMe_Image {
1.911 bisitz 7746: clear:left;
1.747 neumanie 7747: }
1.795 www 7748:
1.721 harmsja 7749: dl.LC_ListStyleClean dt {
1.911 bisitz 7750: padding-right: 5px;
7751: display: table-header-group;
1.693 droeschl 7752: }
7753:
1.721 harmsja 7754: dl.LC_ListStyleClean dd {
1.911 bisitz 7755: display: table-row;
1.693 droeschl 7756: }
7757:
1.721 harmsja 7758: .LC_ListStyleClean,
7759: .LC_ListStyleSimple,
7760: .LC_ListStyleNormal,
1.795 www 7761: .LC_ListStyleSpecial {
1.911 bisitz 7762: /* display:block; */
7763: list-style-position: inside;
7764: list-style-type: none;
7765: overflow: hidden;
7766: padding: 0;
1.693 droeschl 7767: }
7768:
1.721 harmsja 7769: .LC_ListStyleSimple li,
7770: .LC_ListStyleSimple dd,
7771: .LC_ListStyleNormal li,
7772: .LC_ListStyleNormal dd,
7773: .LC_ListStyleSpecial li,
1.795 www 7774: .LC_ListStyleSpecial dd {
1.911 bisitz 7775: margin: 0;
7776: padding: 5px 5px 5px 10px;
7777: clear: both;
1.693 droeschl 7778: }
7779:
1.721 harmsja 7780: .LC_ListStyleClean li,
7781: .LC_ListStyleClean dd {
1.911 bisitz 7782: padding-top: 0;
7783: padding-bottom: 0;
1.693 droeschl 7784: }
7785:
1.721 harmsja 7786: .LC_ListStyleSimple dd,
1.795 www 7787: .LC_ListStyleSimple li {
1.911 bisitz 7788: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7789: }
7790:
1.721 harmsja 7791: .LC_ListStyleSpecial li,
7792: .LC_ListStyleSpecial dd {
1.911 bisitz 7793: list-style-type: none;
7794: background-color: RGB(220, 220, 220);
7795: margin-bottom: 4px;
1.693 droeschl 7796: }
7797:
1.721 harmsja 7798: table.LC_SimpleTable {
1.911 bisitz 7799: margin:5px;
7800: border:solid 1px $lg_border_color;
1.795 www 7801: }
1.693 droeschl 7802:
1.721 harmsja 7803: table.LC_SimpleTable tr {
1.911 bisitz 7804: padding: 0;
7805: border:solid 1px $lg_border_color;
1.693 droeschl 7806: }
1.795 www 7807:
7808: table.LC_SimpleTable thead {
1.911 bisitz 7809: background:rgb(220,220,220);
1.693 droeschl 7810: }
7811:
1.721 harmsja 7812: div.LC_columnSection {
1.911 bisitz 7813: display: block;
7814: clear: both;
7815: overflow: hidden;
7816: margin: 0;
1.693 droeschl 7817: }
7818:
1.721 harmsja 7819: div.LC_columnSection>* {
1.911 bisitz 7820: float: left;
7821: margin: 10px 20px 10px 0;
7822: overflow:hidden;
1.693 droeschl 7823: }
1.721 harmsja 7824:
1.795 www 7825: table em {
1.911 bisitz 7826: font-weight: bold;
7827: font-style: normal;
1.748 schulted 7828: }
1.795 www 7829:
1.779 bisitz 7830: table.LC_tableBrowseRes,
1.795 www 7831: table.LC_tableOfContent {
1.911 bisitz 7832: border:none;
7833: border-spacing: 1px;
7834: padding: 3px;
7835: background-color: #FFFFFF;
7836: font-size: 90%;
1.753 droeschl 7837: }
1.789 droeschl 7838:
1.911 bisitz 7839: table.LC_tableOfContent {
7840: border-collapse: collapse;
1.789 droeschl 7841: }
7842:
1.771 droeschl 7843: table.LC_tableBrowseRes a,
1.768 schulted 7844: table.LC_tableOfContent a {
1.911 bisitz 7845: background-color: transparent;
7846: text-decoration: none;
1.753 droeschl 7847: }
7848:
1.795 www 7849: table.LC_tableOfContent img {
1.911 bisitz 7850: border: none;
7851: height: 1.3em;
7852: vertical-align: text-bottom;
7853: margin-right: 0.3em;
1.753 droeschl 7854: }
1.757 schulted 7855:
1.795 www 7856: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7857: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7858: }
7859:
1.795 www 7860: a#LC_content_toolbar_everything {
1.911 bisitz 7861: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7862: }
7863:
1.795 www 7864: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7865: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7866: }
7867:
1.795 www 7868: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7869: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7870: }
7871:
1.795 www 7872: a#LC_content_toolbar_changefolder {
1.911 bisitz 7873: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7874: }
7875:
1.795 www 7876: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7877: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7878: }
7879:
1.1043 raeburn 7880: a#LC_content_toolbar_edittoplevel {
7881: background-image:url(/res/adm/pages/edittoplevel.gif);
7882: }
7883:
1.795 www 7884: ul#LC_toolbar li a:hover {
1.911 bisitz 7885: background-position: bottom center;
1.757 schulted 7886: }
7887:
1.795 www 7888: ul#LC_toolbar {
1.911 bisitz 7889: padding: 0;
7890: margin: 2px;
7891: list-style:none;
7892: position:relative;
7893: background-color:white;
1.1082 raeburn 7894: overflow: auto;
1.757 schulted 7895: }
7896:
1.795 www 7897: ul#LC_toolbar li {
1.911 bisitz 7898: border:1px solid white;
7899: padding: 0;
7900: margin: 0;
7901: float: left;
7902: display:inline;
7903: vertical-align:middle;
1.1082 raeburn 7904: white-space: nowrap;
1.911 bisitz 7905: }
1.757 schulted 7906:
1.783 amueller 7907:
1.795 www 7908: a.LC_toolbarItem {
1.911 bisitz 7909: display:block;
7910: padding: 0;
7911: margin: 0;
7912: height: 32px;
7913: width: 32px;
7914: color:white;
7915: border: none;
7916: background-repeat:no-repeat;
7917: background-color:transparent;
1.757 schulted 7918: }
7919:
1.915 droeschl 7920: ul.LC_funclist {
7921: margin: 0;
7922: padding: 0.5em 1em 0.5em 0;
7923: }
7924:
1.933 droeschl 7925: ul.LC_funclist > li:first-child {
7926: font-weight:bold;
7927: margin-left:0.8em;
7928: }
7929:
1.915 droeschl 7930: ul.LC_funclist + ul.LC_funclist {
7931: /*
7932: left border as a seperator if we have more than
7933: one list
7934: */
7935: border-left: 1px solid $sidebg;
7936: /*
7937: this hides the left border behind the border of the
7938: outer box if element is wrapped to the next 'line'
7939: */
7940: margin-left: -1px;
7941: }
7942:
1.843 bisitz 7943: ul.LC_funclist li {
1.915 droeschl 7944: display: inline;
1.782 bisitz 7945: white-space: nowrap;
1.915 droeschl 7946: margin: 0 0 0 25px;
7947: line-height: 150%;
1.782 bisitz 7948: }
7949:
1.974 wenzelju 7950: .LC_hidden {
7951: display: none;
7952: }
7953:
1.1030 www 7954: .LCmodal-overlay {
7955: position:fixed;
7956: top:0;
7957: right:0;
7958: bottom:0;
7959: left:0;
7960: height:100%;
7961: width:100%;
7962: margin:0;
7963: padding:0;
7964: background:#999;
7965: opacity:.75;
7966: filter: alpha(opacity=75);
7967: -moz-opacity: 0.75;
7968: z-index:101;
7969: }
7970:
7971: * html .LCmodal-overlay {
7972: position: absolute;
7973: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7974: }
7975:
7976: .LCmodal-window {
7977: position:fixed;
7978: top:50%;
7979: left:50%;
7980: margin:0;
7981: padding:0;
7982: z-index:102;
7983: }
7984:
7985: * html .LCmodal-window {
7986: position:absolute;
7987: }
7988:
7989: .LCclose-window {
7990: position:absolute;
7991: width:32px;
7992: height:32px;
7993: right:8px;
7994: top:8px;
7995: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7996: text-indent:-99999px;
7997: overflow:hidden;
7998: cursor:pointer;
7999: }
8000:
1.1100 raeburn 8001: /*
1.1231 damieng 8002: styles used for response display
8003: */
8004: div.LC_radiofoil, div.LC_rankfoil {
8005: margin: .5em 0em .5em 0em;
8006: }
8007: table.LC_itemgroup {
8008: margin-top: 1em;
8009: }
8010:
8011: /*
1.1100 raeburn 8012: styles used by TTH when "Default set of options to pass to tth/m
8013: when converting TeX" in course settings has been set
8014:
8015: option passed: -t
8016:
8017: */
8018:
8019: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8020: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8021: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8022: td div.norm {line-height:normal;}
8023:
8024: /*
8025: option passed -y3
8026: */
8027:
8028: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8029: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8030: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8031:
1.1230 damieng 8032: /*
8033: sections with roles, for content only
8034: */
8035: section[class^="role-"] {
8036: padding-left: 10px;
8037: padding-right: 5px;
8038: margin-top: 8px;
8039: margin-bottom: 8px;
8040: border: 1px solid #2A4;
8041: border-radius: 5px;
8042: box-shadow: 0px 1px 1px #BBB;
8043: }
8044: section[class^="role-"]>h1 {
8045: position: relative;
8046: margin: 0px;
8047: padding-top: 10px;
8048: padding-left: 40px;
8049: }
8050: section[class^="role-"]>h1:before {
8051: position: absolute;
8052: left: -5px;
8053: top: 5px;
8054: }
8055: section.role-activity>h1:before {
8056: content:url('/adm/daxe/images/section_icons/activity.png');
8057: }
8058: section.role-advice>h1:before {
8059: content:url('/adm/daxe/images/section_icons/advice.png');
8060: }
8061: section.role-bibliography>h1:before {
8062: content:url('/adm/daxe/images/section_icons/bibliography.png');
8063: }
8064: section.role-citation>h1:before {
8065: content:url('/adm/daxe/images/section_icons/citation.png');
8066: }
8067: section.role-conclusion>h1:before {
8068: content:url('/adm/daxe/images/section_icons/conclusion.png');
8069: }
8070: section.role-definition>h1:before {
8071: content:url('/adm/daxe/images/section_icons/definition.png');
8072: }
8073: section.role-demonstration>h1:before {
8074: content:url('/adm/daxe/images/section_icons/demonstration.png');
8075: }
8076: section.role-example>h1:before {
8077: content:url('/adm/daxe/images/section_icons/example.png');
8078: }
8079: section.role-explanation>h1:before {
8080: content:url('/adm/daxe/images/section_icons/explanation.png');
8081: }
8082: section.role-introduction>h1:before {
8083: content:url('/adm/daxe/images/section_icons/introduction.png');
8084: }
8085: section.role-method>h1:before {
8086: content:url('/adm/daxe/images/section_icons/method.png');
8087: }
8088: section.role-more_information>h1:before {
8089: content:url('/adm/daxe/images/section_icons/more_information.png');
8090: }
8091: section.role-objectives>h1:before {
8092: content:url('/adm/daxe/images/section_icons/objectives.png');
8093: }
8094: section.role-prerequisites>h1:before {
8095: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8096: }
8097: section.role-remark>h1:before {
8098: content:url('/adm/daxe/images/section_icons/remark.png');
8099: }
8100: section.role-reminder>h1:before {
8101: content:url('/adm/daxe/images/section_icons/reminder.png');
8102: }
8103: section.role-summary>h1:before {
8104: content:url('/adm/daxe/images/section_icons/summary.png');
8105: }
8106: section.role-syntax>h1:before {
8107: content:url('/adm/daxe/images/section_icons/syntax.png');
8108: }
8109: section.role-warning>h1:before {
8110: content:url('/adm/daxe/images/section_icons/warning.png');
8111: }
8112:
1.343 albertel 8113: END
8114: }
8115:
1.306 albertel 8116: =pod
8117:
8118: =item * &headtag()
8119:
8120: Returns a uniform footer for LON-CAPA web pages.
8121:
1.307 albertel 8122: Inputs: $title - optional title for the head
8123: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8124: $args - optional arguments
1.319 albertel 8125: force_register - if is true call registerurl so the remote is
8126: informed
1.415 albertel 8127: redirect -> array ref of
8128: 1- seconds before redirect occurs
8129: 2- url to redirect to
8130: 3- whether the side effect should occur
1.315 albertel 8131: (side effect of setting
8132: $env{'internal.head.redirect'} to the url
8133: redirected too)
1.352 albertel 8134: domain -> force to color decorate a page for a specific
8135: domain
8136: function -> force usage of a specific rolish color scheme
8137: bgcolor -> override the default page bgcolor
1.460 albertel 8138: no_auto_mt_title
8139: -> prevent &mt()ing the title arg
1.464 albertel 8140:
1.306 albertel 8141: =cut
8142:
8143: sub headtag {
1.313 albertel 8144: my ($title,$head_extra,$args) = @_;
1.306 albertel 8145:
1.363 albertel 8146: my $function = $args->{'function'} || &get_users_function();
8147: my $domain = $args->{'domain'} || &determinedomain();
8148: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8149: my $httphost = $args->{'use_absolute'};
1.418 albertel 8150: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8151: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8152: #time(),
1.418 albertel 8153: $env{'environment.color.timestamp'},
1.363 albertel 8154: $function,$domain,$bgcolor);
8155:
1.369 www 8156: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8157:
1.308 albertel 8158: my $result =
8159: '<head>'.
1.1160 raeburn 8160: &font_settings($args);
1.319 albertel 8161:
1.1188 raeburn 8162: my $inhibitprint;
8163: if ($args->{'print_suppress'}) {
8164: $inhibitprint = &print_suppression();
8165: }
1.1064 raeburn 8166:
1.461 albertel 8167: if (!$args->{'frameset'}) {
8168: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8169: }
1.962 droeschl 8170: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8171: $result .= Apache::lonxml::display_title();
1.319 albertel 8172: }
1.436 albertel 8173: if (!$args->{'no_nav_bar'}
8174: && !$args->{'only_body'}
8175: && !$args->{'frameset'}) {
1.1154 raeburn 8176: $result .= &help_menu_js($httphost);
1.1032 www 8177: $result.=&modal_window();
1.1038 www 8178: $result.=&togglebox_script();
1.1034 www 8179: $result.=&wishlist_window();
1.1041 www 8180: $result.=&LCprogressbarUpdate_script();
1.1034 www 8181: } else {
8182: if ($args->{'add_modal'}) {
8183: $result.=&modal_window();
8184: }
8185: if ($args->{'add_wishlist'}) {
8186: $result.=&wishlist_window();
8187: }
1.1038 www 8188: if ($args->{'add_togglebox'}) {
8189: $result.=&togglebox_script();
8190: }
1.1041 www 8191: if ($args->{'add_progressbar'}) {
8192: $result.=&LCprogressbarUpdate_script();
8193: }
1.436 albertel 8194: }
1.314 albertel 8195: if (ref($args->{'redirect'})) {
1.414 albertel 8196: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8197: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8198: if (!$inhibit_continue) {
8199: $env{'internal.head.redirect'} = $url;
8200: }
1.313 albertel 8201: $result.=<<ADDMETA
8202: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8203: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8204: ADDMETA
1.1210 raeburn 8205: } else {
8206: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8207: my $requrl = $env{'request.uri'};
8208: if ($requrl eq '') {
8209: $requrl = $ENV{'REQUEST_URI'};
8210: $requrl =~ s/\?.+$//;
8211: }
8212: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8213: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8214: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8215: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8216: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8217: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
8218: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8219: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8220: if ($domdefs{'offloadnow'}{$lonhost}) {
8221: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8222: if (($newserver) && ($newserver ne $lonhost)) {
8223: my $numsec = 5;
8224: my $timeout = $numsec * 1000;
8225: my ($newurl,$locknum,%locks,$msg);
8226: if ($env{'request.role.adv'}) {
8227: ($locknum,%locks) = &Apache::lonnet::get_locks();
8228: }
8229: my $disable_submit = 0;
8230: if ($requrl =~ /$LONCAPA::assess_re/) {
8231: $disable_submit = 1;
8232: }
8233: if ($locknum) {
8234: my @lockinfo = sort(values(%locks));
8235: $msg = &mt('Once the following tasks are complete: ')."\\n".
8236: join(", ",sort(values(%locks)))."\\n".
8237: &mt('your session will be transferred to a different server, after you click "Roles".');
8238: } else {
8239: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8240: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
8241: }
8242: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8243: $newurl = '/adm/switchserver?otherserver='.$newserver;
8244: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8245: $newurl .= '&role='.$env{'request.role'};
8246: }
8247: if ($env{'request.symb'}) {
8248: $newurl .= '&symb='.$env{'request.symb'};
8249: } else {
8250: $newurl .= '&origurl='.$requrl;
8251: }
8252: }
1.1222 damieng 8253: &js_escape(\$msg);
1.1210 raeburn 8254: $result.=<<OFFLOAD
8255: <meta http-equiv="pragma" content="no-cache" />
8256: <script type="text/javascript">
1.1215 raeburn 8257: // <![CDATA[
1.1210 raeburn 8258: function LC_Offload_Now() {
8259: var dest = "$newurl";
8260: if (dest != '') {
8261: window.location.href="$newurl";
8262: }
8263: }
1.1214 raeburn 8264: \$(document).ready(function () {
8265: window.alert('$msg');
8266: if ($disable_submit) {
1.1210 raeburn 8267: \$(".LC_hwk_submit").prop("disabled", true);
8268: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8269: }
8270: setTimeout('LC_Offload_Now()', $timeout);
8271: });
1.1215 raeburn 8272: // ]]>
1.1210 raeburn 8273: </script>
8274: OFFLOAD
8275: }
8276: }
8277: }
8278: }
8279: }
8280: }
1.313 albertel 8281: }
1.306 albertel 8282: if (!defined($title)) {
8283: $title = 'The LearningOnline Network with CAPA';
8284: }
1.460 albertel 8285: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8286: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8287: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8288: if (!$args->{'frameset'}) {
8289: $result .= ' /';
8290: }
8291: $result .= '>'
1.1064 raeburn 8292: .$inhibitprint
1.414 albertel 8293: .$head_extra;
1.1242 raeburn 8294: my $clientmobile;
8295: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8296: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8297: } else {
8298: $clientmobile = $env{'browser.mobile'};
8299: }
8300: if ($clientmobile) {
1.1137 raeburn 8301: $result .= '
8302: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8303: <meta name="apple-mobile-web-app-capable" content="yes" />';
8304: }
1.962 droeschl 8305: return $result.'</head>';
1.306 albertel 8306: }
8307:
8308: =pod
8309:
1.340 albertel 8310: =item * &font_settings()
8311:
8312: Returns neccessary <meta> to set the proper encoding
8313:
1.1160 raeburn 8314: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8315:
8316: =cut
8317:
8318: sub font_settings {
1.1160 raeburn 8319: my ($args) = @_;
1.340 albertel 8320: my $headerstring='';
1.1160 raeburn 8321: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8322: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8323: $headerstring.=
8324: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8325: if (!$args->{'frameset'}) {
8326: $headerstring.= ' /';
8327: }
8328: $headerstring .= '>'."\n";
1.340 albertel 8329: }
8330: return $headerstring;
8331: }
8332:
1.341 albertel 8333: =pod
8334:
1.1064 raeburn 8335: =item * &print_suppression()
8336:
8337: In course context returns css which causes the body to be blank when media="print",
8338: if printout generation is unavailable for the current resource.
8339:
8340: This could be because:
8341:
8342: (a) printstartdate is in the future
8343:
8344: (b) printenddate is in the past
8345:
8346: (c) there is an active exam block with "printout"
8347: functionality blocked
8348:
8349: Users with pav, pfo or evb privileges are exempt.
8350:
8351: Inputs: none
8352:
8353: =cut
8354:
8355:
8356: sub print_suppression {
8357: my $noprint;
8358: if ($env{'request.course.id'}) {
8359: my $scope = $env{'request.course.id'};
8360: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8361: (&Apache::lonnet::allowed('pfo',$scope))) {
8362: return;
8363: }
8364: if ($env{'request.course.sec'} ne '') {
8365: $scope .= "/$env{'request.course.sec'}";
8366: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8367: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8368: return;
1.1064 raeburn 8369: }
8370: }
8371: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8372: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8373: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8374: if ($blocked) {
8375: my $checkrole = "cm./$cdom/$cnum";
8376: if ($env{'request.course.sec'} ne '') {
8377: $checkrole .= "/$env{'request.course.sec'}";
8378: }
8379: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8380: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8381: $noprint = 1;
8382: }
8383: }
8384: unless ($noprint) {
8385: my $symb = &Apache::lonnet::symbread();
8386: if ($symb ne '') {
8387: my $navmap = Apache::lonnavmaps::navmap->new();
8388: if (ref($navmap)) {
8389: my $res = $navmap->getBySymb($symb);
8390: if (ref($res)) {
8391: if (!$res->resprintable()) {
8392: $noprint = 1;
8393: }
8394: }
8395: }
8396: }
8397: }
8398: if ($noprint) {
8399: return <<"ENDSTYLE";
8400: <style type="text/css" media="print">
8401: body { display:none }
8402: </style>
8403: ENDSTYLE
8404: }
8405: }
8406: return;
8407: }
8408:
8409: =pod
8410:
1.341 albertel 8411: =item * &xml_begin()
8412:
8413: Returns the needed doctype and <html>
8414:
8415: Inputs: none
8416:
8417: =cut
8418:
8419: sub xml_begin {
1.1168 raeburn 8420: my ($is_frameset) = @_;
1.341 albertel 8421: my $output='';
8422:
8423: if ($env{'browser.mathml'}) {
8424: $output='<?xml version="1.0"?>'
8425: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8426: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8427:
8428: # .'<!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">] >'
8429: .'<!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">'
8430: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8431: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8432: } elsif ($is_frameset) {
8433: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8434: '<html>'."\n";
1.341 albertel 8435: } else {
1.1168 raeburn 8436: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8437: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8438: }
8439: return $output;
8440: }
1.340 albertel 8441:
8442: =pod
8443:
1.306 albertel 8444: =item * &start_page()
8445:
8446: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8447:
1.648 raeburn 8448: Inputs:
8449:
8450: =over 4
8451:
8452: $title - optional title for the page
8453:
8454: $head_extra - optional extra HTML to incude inside the <head>
8455:
8456: $args - additional optional args supported are:
8457:
8458: =over 8
8459:
8460: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8461: arg on
1.814 bisitz 8462: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8463: add_entries -> additional attributes to add to the <body>
8464: domain -> force to color decorate a page for a
1.317 albertel 8465: specific domain
1.648 raeburn 8466: function -> force usage of a specific rolish color
1.317 albertel 8467: scheme
1.648 raeburn 8468: redirect -> see &headtag()
8469: bgcolor -> override the default page bg color
8470: js_ready -> return a string ready for being used in
1.317 albertel 8471: a javascript writeln
1.648 raeburn 8472: html_encode -> return a string ready for being used in
1.320 albertel 8473: a html attribute
1.648 raeburn 8474: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8475: $forcereg arg
1.648 raeburn 8476: frameset -> if true will start with a <frameset>
1.330 albertel 8477: rather than <body>
1.648 raeburn 8478: skip_phases -> hash ref of
1.338 albertel 8479: head -> skip the <html><head> generation
8480: body -> skip all <body> generation
1.648 raeburn 8481: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8482: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8483: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 8484: group -> includes the current group, if page is for a
8485: specific group
1.361 albertel 8486:
1.648 raeburn 8487: =back
1.460 albertel 8488:
1.648 raeburn 8489: =back
1.562 albertel 8490:
1.306 albertel 8491: =cut
8492:
8493: sub start_page {
1.309 albertel 8494: my ($title,$head_extra,$args) = @_;
1.318 albertel 8495: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8496:
1.315 albertel 8497: $env{'internal.start_page'}++;
1.1096 raeburn 8498: my ($result,@advtools);
1.964 droeschl 8499:
1.338 albertel 8500: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8501: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8502: }
8503:
8504: if (! exists($args->{'skip_phases'}{'body'}) ) {
8505: if ($args->{'frameset'}) {
8506: my $attr_string = &make_attr_string($args->{'force_register'},
8507: $args->{'add_entries'});
8508: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8509: } else {
8510: $result .=
8511: &bodytag($title,
8512: $args->{'function'}, $args->{'add_entries'},
8513: $args->{'only_body'}, $args->{'domain'},
8514: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8515: $args->{'bgcolor'}, $args,
8516: \@advtools);
1.831 bisitz 8517: }
1.330 albertel 8518: }
1.338 albertel 8519:
1.315 albertel 8520: if ($args->{'js_ready'}) {
1.713 kaisler 8521: $result = &js_ready($result);
1.315 albertel 8522: }
1.320 albertel 8523: if ($args->{'html_encode'}) {
1.713 kaisler 8524: $result = &html_encode($result);
8525: }
8526:
1.813 bisitz 8527: # Preparation for new and consistent functionlist at top of screen
8528: # if ($args->{'functionlist'}) {
8529: # $result .= &build_functionlist();
8530: #}
8531:
1.964 droeschl 8532: # Don't add anything more if only_body wanted or in const space
8533: return $result if $args->{'only_body'}
8534: || $env{'request.state'} eq 'construct';
1.813 bisitz 8535:
8536: #Breadcrumbs
1.758 kaisler 8537: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8538: &Apache::lonhtmlcommon::clear_breadcrumbs();
8539: #if any br links exists, add them to the breadcrumbs
8540: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8541: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8542: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8543: }
8544: }
1.1096 raeburn 8545: # if @advtools array contains items add then to the breadcrumbs
8546: if (@advtools > 0) {
8547: &Apache::lonmenu::advtools_crumbs(@advtools);
8548: }
1.758 kaisler 8549:
8550: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8551: if(exists($args->{'bread_crumbs_component'})){
8552: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
1.1237 raeburn 8553: } elsif ($args->{'crstype'} eq 'Placement') {
8554: $result .= &Apache::lonhtmlcommon::breadcrumbs('','','','','','','','','',
8555: $args->{'crstype'});
8556: } else {
1.758 kaisler 8557: $result .= &Apache::lonhtmlcommon::breadcrumbs();
8558: }
1.320 albertel 8559: }
1.315 albertel 8560: return $result;
1.306 albertel 8561: }
8562:
8563: sub end_page {
1.315 albertel 8564: my ($args) = @_;
8565: $env{'internal.end_page'}++;
1.330 albertel 8566: my $result;
1.335 albertel 8567: if ($args->{'discussion'}) {
8568: my ($target,$parser);
8569: if (ref($args->{'discussion'})) {
8570: ($target,$parser) =($args->{'discussion'}{'target'},
8571: $args->{'discussion'}{'parser'});
8572: }
8573: $result .= &Apache::lonxml::xmlend($target,$parser);
8574: }
1.330 albertel 8575: if ($args->{'frameset'}) {
8576: $result .= '</frameset>';
8577: } else {
1.635 raeburn 8578: $result .= &endbodytag($args);
1.330 albertel 8579: }
1.1080 raeburn 8580: unless ($args->{'notbody'}) {
8581: $result .= "\n</html>";
8582: }
1.330 albertel 8583:
1.315 albertel 8584: if ($args->{'js_ready'}) {
1.317 albertel 8585: $result = &js_ready($result);
1.315 albertel 8586: }
1.335 albertel 8587:
1.320 albertel 8588: if ($args->{'html_encode'}) {
8589: $result = &html_encode($result);
8590: }
1.335 albertel 8591:
1.315 albertel 8592: return $result;
8593: }
8594:
1.1034 www 8595: sub wishlist_window {
8596: return(<<'ENDWISHLIST');
1.1046 raeburn 8597: <script type="text/javascript">
1.1034 www 8598: // <![CDATA[
8599: // <!-- BEGIN LON-CAPA Internal
8600: function set_wishlistlink(title, path) {
8601: if (!title) {
8602: title = document.title;
8603: title = title.replace(/^LON-CAPA /,'');
8604: }
1.1175 raeburn 8605: title = encodeURIComponent(title);
1.1203 raeburn 8606: title = title.replace("'","\\\'");
1.1034 www 8607: if (!path) {
8608: path = location.pathname;
8609: }
1.1175 raeburn 8610: path = encodeURIComponent(path);
1.1203 raeburn 8611: path = path.replace("'","\\\'");
1.1034 www 8612: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8613: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8614: }
8615: // END LON-CAPA Internal -->
8616: // ]]>
8617: </script>
8618: ENDWISHLIST
8619: }
8620:
1.1030 www 8621: sub modal_window {
8622: return(<<'ENDMODAL');
1.1046 raeburn 8623: <script type="text/javascript">
1.1030 www 8624: // <![CDATA[
8625: // <!-- BEGIN LON-CAPA Internal
8626: var modalWindow = {
8627: parent:"body",
8628: windowId:null,
8629: content:null,
8630: width:null,
8631: height:null,
8632: close:function()
8633: {
8634: $(".LCmodal-window").remove();
8635: $(".LCmodal-overlay").remove();
8636: },
8637: open:function()
8638: {
8639: var modal = "";
8640: modal += "<div class=\"LCmodal-overlay\"></div>";
8641: 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;\">";
8642: modal += this.content;
8643: modal += "</div>";
8644:
8645: $(this.parent).append(modal);
8646:
8647: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8648: $(".LCclose-window").click(function(){modalWindow.close();});
8649: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8650: }
8651: };
1.1140 raeburn 8652: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8653: {
1.1203 raeburn 8654: source = source.replace("'","'");
1.1030 www 8655: modalWindow.windowId = "myModal";
8656: modalWindow.width = width;
8657: modalWindow.height = height;
1.1196 raeburn 8658: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8659: modalWindow.open();
1.1208 raeburn 8660: };
1.1030 www 8661: // END LON-CAPA Internal -->
8662: // ]]>
8663: </script>
8664: ENDMODAL
8665: }
8666:
8667: sub modal_link {
1.1140 raeburn 8668: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8669: unless ($width) { $width=480; }
8670: unless ($height) { $height=400; }
1.1031 www 8671: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8672: unless ($transparency) { $transparency='true'; }
8673:
1.1074 raeburn 8674: my $target_attr;
8675: if (defined($target)) {
8676: $target_attr = 'target="'.$target.'"';
8677: }
8678: return <<"ENDLINK";
1.1140 raeburn 8679: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8680: $linktext</a>
8681: ENDLINK
1.1030 www 8682: }
8683:
1.1032 www 8684: sub modal_adhoc_script {
8685: my ($funcname,$width,$height,$content)=@_;
8686: return (<<ENDADHOC);
1.1046 raeburn 8687: <script type="text/javascript">
1.1032 www 8688: // <![CDATA[
8689: var $funcname = function()
8690: {
8691: modalWindow.windowId = "myModal";
8692: modalWindow.width = $width;
8693: modalWindow.height = $height;
8694: modalWindow.content = '$content';
8695: modalWindow.open();
8696: };
8697: // ]]>
8698: </script>
8699: ENDADHOC
8700: }
8701:
1.1041 www 8702: sub modal_adhoc_inner {
8703: my ($funcname,$width,$height,$content)=@_;
8704: my $innerwidth=$width-20;
8705: $content=&js_ready(
1.1140 raeburn 8706: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8707: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8708: $content.
1.1041 www 8709: &end_scrollbox().
1.1140 raeburn 8710: &end_page()
1.1041 www 8711: );
8712: return &modal_adhoc_script($funcname,$width,$height,$content);
8713: }
8714:
8715: sub modal_adhoc_window {
8716: my ($funcname,$width,$height,$content,$linktext)=@_;
8717: return &modal_adhoc_inner($funcname,$width,$height,$content).
8718: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8719: }
8720:
8721: sub modal_adhoc_launch {
8722: my ($funcname,$width,$height,$content)=@_;
8723: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8724: <script type="text/javascript">
8725: // <![CDATA[
8726: $funcname();
8727: // ]]>
8728: </script>
8729: ENDLAUNCH
8730: }
8731:
8732: sub modal_adhoc_close {
8733: return (<<ENDCLOSE);
8734: <script type="text/javascript">
8735: // <![CDATA[
8736: modalWindow.close();
8737: // ]]>
8738: </script>
8739: ENDCLOSE
8740: }
8741:
1.1038 www 8742: sub togglebox_script {
8743: return(<<ENDTOGGLE);
8744: <script type="text/javascript">
8745: // <![CDATA[
8746: function LCtoggleDisplay(id,hidetext,showtext) {
8747: link = document.getElementById(id + "link").childNodes[0];
8748: with (document.getElementById(id).style) {
8749: if (display == "none" ) {
8750: display = "inline";
8751: link.nodeValue = hidetext;
8752: } else {
8753: display = "none";
8754: link.nodeValue = showtext;
8755: }
8756: }
8757: }
8758: // ]]>
8759: </script>
8760: ENDTOGGLE
8761: }
8762:
1.1039 www 8763: sub start_togglebox {
8764: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8765: unless ($heading) { $heading=''; } else { $heading.=' '; }
8766: unless ($showtext) { $showtext=&mt('show'); }
8767: unless ($hidetext) { $hidetext=&mt('hide'); }
8768: unless ($headerbg) { $headerbg='#FFFFFF'; }
8769: return &start_data_table().
8770: &start_data_table_header_row().
8771: '<td bgcolor="'.$headerbg.'">'.$heading.
8772: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8773: $showtext.'\')">'.$showtext.'</a>]</td>'.
8774: &end_data_table_header_row().
8775: '<tr id="'.$id.'" style="display:none""><td>';
8776: }
8777:
8778: sub end_togglebox {
8779: return '</td></tr>'.&end_data_table();
8780: }
8781:
1.1041 www 8782: sub LCprogressbar_script {
1.1045 www 8783: my ($id)=@_;
1.1041 www 8784: return(<<ENDPROGRESS);
8785: <script type="text/javascript">
8786: // <![CDATA[
1.1045 www 8787: \$('#progressbar$id').progressbar({
1.1041 www 8788: value: 0,
8789: change: function(event, ui) {
8790: var newVal = \$(this).progressbar('option', 'value');
8791: \$('.pblabel', this).text(LCprogressTxt);
8792: }
8793: });
8794: // ]]>
8795: </script>
8796: ENDPROGRESS
8797: }
8798:
8799: sub LCprogressbarUpdate_script {
8800: return(<<ENDPROGRESSUPDATE);
8801: <style type="text/css">
8802: .ui-progressbar { position:relative; }
8803: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8804: </style>
8805: <script type="text/javascript">
8806: // <![CDATA[
1.1045 www 8807: var LCprogressTxt='---';
8808:
8809: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8810: LCprogressTxt=progresstext;
1.1045 www 8811: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8812: }
8813: // ]]>
8814: </script>
8815: ENDPROGRESSUPDATE
8816: }
8817:
1.1042 www 8818: my $LClastpercent;
1.1045 www 8819: my $LCidcnt;
8820: my $LCcurrentid;
1.1042 www 8821:
1.1041 www 8822: sub LCprogressbar {
1.1042 www 8823: my ($r)=(@_);
8824: $LClastpercent=0;
1.1045 www 8825: $LCidcnt++;
8826: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8827: my $starting=&mt('Starting');
8828: my $content=(<<ENDPROGBAR);
1.1045 www 8829: <div id="progressbar$LCcurrentid">
1.1041 www 8830: <span class="pblabel">$starting</span>
8831: </div>
8832: ENDPROGBAR
1.1045 www 8833: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8834: }
8835:
8836: sub LCprogressbarUpdate {
1.1042 www 8837: my ($r,$val,$text)=@_;
8838: unless ($val) {
8839: if ($LClastpercent) {
8840: $val=$LClastpercent;
8841: } else {
8842: $val=0;
8843: }
8844: }
1.1041 www 8845: if ($val<0) { $val=0; }
8846: if ($val>100) { $val=0; }
1.1042 www 8847: $LClastpercent=$val;
1.1041 www 8848: unless ($text) { $text=$val.'%'; }
8849: $text=&js_ready($text);
1.1044 www 8850: &r_print($r,<<ENDUPDATE);
1.1041 www 8851: <script type="text/javascript">
8852: // <![CDATA[
1.1045 www 8853: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8854: // ]]>
8855: </script>
8856: ENDUPDATE
1.1035 www 8857: }
8858:
1.1042 www 8859: sub LCprogressbarClose {
8860: my ($r)=@_;
8861: $LClastpercent=0;
1.1044 www 8862: &r_print($r,<<ENDCLOSE);
1.1042 www 8863: <script type="text/javascript">
8864: // <![CDATA[
1.1045 www 8865: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8866: // ]]>
8867: </script>
8868: ENDCLOSE
1.1044 www 8869: }
8870:
8871: sub r_print {
8872: my ($r,$to_print)=@_;
8873: if ($r) {
8874: $r->print($to_print);
8875: $r->rflush();
8876: } else {
8877: print($to_print);
8878: }
1.1042 www 8879: }
8880:
1.320 albertel 8881: sub html_encode {
8882: my ($result) = @_;
8883:
1.322 albertel 8884: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8885:
8886: return $result;
8887: }
1.1044 www 8888:
1.317 albertel 8889: sub js_ready {
8890: my ($result) = @_;
8891:
1.323 albertel 8892: $result =~ s/[\n\r]/ /xmsg;
8893: $result =~ s/\\/\\\\/xmsg;
8894: $result =~ s/'/\\'/xmsg;
1.372 albertel 8895: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8896:
8897: return $result;
8898: }
8899:
1.315 albertel 8900: sub validate_page {
8901: if ( exists($env{'internal.start_page'})
1.316 albertel 8902: && $env{'internal.start_page'} > 1) {
8903: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8904: $env{'internal.start_page'}.' '.
1.316 albertel 8905: $ENV{'request.filename'});
1.315 albertel 8906: }
8907: if ( exists($env{'internal.end_page'})
1.316 albertel 8908: && $env{'internal.end_page'} > 1) {
8909: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8910: $env{'internal.end_page'}.' '.
1.316 albertel 8911: $env{'request.filename'});
1.315 albertel 8912: }
8913: if ( exists($env{'internal.start_page'})
8914: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8915: &Apache::lonnet::logthis('start_page called without end_page '.
8916: $env{'request.filename'});
1.315 albertel 8917: }
8918: if ( ! exists($env{'internal.start_page'})
8919: && exists($env{'internal.end_page'})) {
1.316 albertel 8920: &Apache::lonnet::logthis('end_page called without start_page'.
8921: $env{'request.filename'});
1.315 albertel 8922: }
1.306 albertel 8923: }
1.315 albertel 8924:
1.996 www 8925:
8926: sub start_scrollbox {
1.1140 raeburn 8927: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8928: unless ($outerwidth) { $outerwidth='520px'; }
8929: unless ($width) { $width='500px'; }
8930: unless ($height) { $height='200px'; }
1.1075 raeburn 8931: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8932: if ($id ne '') {
1.1140 raeburn 8933: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 8934: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8935: }
1.1075 raeburn 8936: if ($bgcolor ne '') {
8937: $tdcol = "background-color: $bgcolor;";
8938: }
1.1137 raeburn 8939: my $nicescroll_js;
8940: if ($env{'browser.mobile'}) {
1.1140 raeburn 8941: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8942: }
8943: return <<"END";
8944: $nicescroll_js
8945:
8946: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
8947: <div style="overflow:auto; width:$width; height:$height;"$div_id>
8948: END
8949: }
8950:
8951: sub end_scrollbox {
8952: return '</div></td></tr></table>';
8953: }
8954:
8955: sub nicescroll_javascript {
8956: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8957: my %options;
8958: if (ref($cursor) eq 'HASH') {
8959: %options = %{$cursor};
8960: }
8961: unless ($options{'railalign'} =~ /^left|right$/) {
8962: $options{'railalign'} = 'left';
8963: }
8964: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8965: my $function = &get_users_function();
8966: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 8967: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 8968: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 8969: }
1.1140 raeburn 8970: }
8971: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8972: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 8973: $options{'cursoropacity'}='1.0';
8974: }
1.1140 raeburn 8975: } else {
8976: $options{'cursoropacity'}='1.0';
8977: }
8978: if ($options{'cursorfixedheight'} eq 'none') {
8979: delete($options{'cursorfixedheight'});
8980: } else {
8981: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8982: }
8983: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8984: delete($options{'railoffset'});
8985: }
8986: my @niceoptions;
8987: while (my($key,$value) = each(%options)) {
8988: if ($value =~ /^\{.+\}$/) {
8989: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 8990: } else {
1.1140 raeburn 8991: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 8992: }
1.1140 raeburn 8993: }
8994: my $nicescroll_js = '
1.1137 raeburn 8995: $(document).ready(
1.1140 raeburn 8996: function() {
8997: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8998: }
1.1137 raeburn 8999: );
9000: ';
1.1140 raeburn 9001: if ($framecheck) {
9002: $nicescroll_js .= '
9003: function expand_div(caller) {
9004: if (top === self) {
9005: document.getElementById("'.$id.'").style.width = "auto";
9006: document.getElementById("'.$id.'").style.height = "auto";
9007: } else {
9008: try {
9009: if (parent.frames) {
9010: if (parent.frames.length > 1) {
9011: var framesrc = parent.frames[1].location.href;
9012: var currsrc = framesrc.replace(/\#.*$/,"");
9013: if ((caller == "search") || (currsrc == "'.$location.'")) {
9014: document.getElementById("'.$id.'").style.width = "auto";
9015: document.getElementById("'.$id.'").style.height = "auto";
9016: }
9017: }
9018: }
9019: } catch (e) {
9020: return;
9021: }
1.1137 raeburn 9022: }
1.1140 raeburn 9023: return;
1.996 www 9024: }
1.1140 raeburn 9025: ';
9026: }
9027: if ($needjsready) {
9028: $nicescroll_js = '
9029: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9030: } else {
9031: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9032: }
9033: return $nicescroll_js;
1.996 www 9034: }
9035:
1.318 albertel 9036: sub simple_error_page {
1.1150 bisitz 9037: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 9038: if (ref($args) eq 'HASH') {
9039: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
9040: } else {
9041: $msg = &mt($msg);
9042: }
1.1150 bisitz 9043:
1.318 albertel 9044: my $page =
9045: &Apache::loncommon::start_page($title).
1.1150 bisitz 9046: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9047: &Apache::loncommon::end_page();
9048: if (ref($r)) {
9049: $r->print($page);
1.327 albertel 9050: return;
1.318 albertel 9051: }
9052: return $page;
9053: }
1.347 albertel 9054:
9055: {
1.610 albertel 9056: my @row_count;
1.961 onken 9057:
9058: sub start_data_table_count {
9059: unshift(@row_count, 0);
9060: return;
9061: }
9062:
9063: sub end_data_table_count {
9064: shift(@row_count);
9065: return;
9066: }
9067:
1.347 albertel 9068: sub start_data_table {
1.1018 raeburn 9069: my ($add_class,$id) = @_;
1.422 albertel 9070: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9071: my $table_id;
9072: if (defined($id)) {
9073: $table_id = ' id="'.$id.'"';
9074: }
1.961 onken 9075: &start_data_table_count();
1.1018 raeburn 9076: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9077: }
9078:
9079: sub end_data_table {
1.961 onken 9080: &end_data_table_count();
1.389 albertel 9081: return '</table>'."\n";;
1.347 albertel 9082: }
9083:
9084: sub start_data_table_row {
1.974 wenzelju 9085: my ($add_class, $id) = @_;
1.610 albertel 9086: $row_count[0]++;
9087: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9088: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9089: $id = (' id="'.$id.'"') unless ($id eq '');
9090: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9091: }
1.471 banghart 9092:
9093: sub continue_data_table_row {
1.974 wenzelju 9094: my ($add_class, $id) = @_;
1.610 albertel 9095: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9096: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9097: $id = (' id="'.$id.'"') unless ($id eq '');
9098: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9099: }
1.347 albertel 9100:
9101: sub end_data_table_row {
1.389 albertel 9102: return '</tr>'."\n";;
1.347 albertel 9103: }
1.367 www 9104:
1.421 albertel 9105: sub start_data_table_empty_row {
1.707 bisitz 9106: # $row_count[0]++;
1.421 albertel 9107: return '<tr class="LC_empty_row" >'."\n";;
9108: }
9109:
9110: sub end_data_table_empty_row {
9111: return '</tr>'."\n";;
9112: }
9113:
1.367 www 9114: sub start_data_table_header_row {
1.389 albertel 9115: return '<tr class="LC_header_row">'."\n";;
1.367 www 9116: }
9117:
9118: sub end_data_table_header_row {
1.389 albertel 9119: return '</tr>'."\n";;
1.367 www 9120: }
1.890 droeschl 9121:
9122: sub data_table_caption {
9123: my $caption = shift;
9124: return "<caption class=\"LC_caption\">$caption</caption>";
9125: }
1.347 albertel 9126: }
9127:
1.548 albertel 9128: =pod
9129:
9130: =item * &inhibit_menu_check($arg)
9131:
9132: Checks for a inhibitmenu state and generates output to preserve it
9133:
9134: Inputs: $arg - can be any of
9135: - undef - in which case the return value is a string
9136: to add into arguments list of a uri
9137: - 'input' - in which case the return value is a HTML
9138: <form> <input> field of type hidden to
9139: preserve the value
9140: - a url - in which case the return value is the url with
9141: the neccesary cgi args added to preserve the
9142: inhibitmenu state
9143: - a ref to a url - no return value, but the string is
9144: updated to include the neccessary cgi
9145: args to preserve the inhibitmenu state
9146:
9147: =cut
9148:
9149: sub inhibit_menu_check {
9150: my ($arg) = @_;
9151: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9152: if ($arg eq 'input') {
9153: if ($env{'form.inhibitmenu'}) {
9154: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9155: } else {
9156: return
9157: }
9158: }
9159: if ($env{'form.inhibitmenu'}) {
9160: if (ref($arg)) {
9161: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9162: } elsif ($arg eq '') {
9163: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9164: } else {
9165: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9166: }
9167: }
9168: if (!ref($arg)) {
9169: return $arg;
9170: }
9171: }
9172:
1.251 albertel 9173: ###############################################
1.182 matthew 9174:
9175: =pod
9176:
1.549 albertel 9177: =back
9178:
9179: =head1 User Information Routines
9180:
9181: =over 4
9182:
1.405 albertel 9183: =item * &get_users_function()
1.182 matthew 9184:
9185: Used by &bodytag to determine the current users primary role.
9186: Returns either 'student','coordinator','admin', or 'author'.
9187:
9188: =cut
9189:
9190: ###############################################
9191: sub get_users_function {
1.815 tempelho 9192: my $function = 'norole';
1.818 tempelho 9193: if ($env{'request.role'}=~/^(st)/) {
9194: $function='student';
9195: }
1.907 raeburn 9196: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9197: $function='coordinator';
9198: }
1.258 albertel 9199: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9200: $function='admin';
9201: }
1.826 bisitz 9202: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9203: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9204: $function='author';
9205: }
9206: return $function;
1.54 www 9207: }
1.99 www 9208:
9209: ###############################################
9210:
1.233 raeburn 9211: =pod
9212:
1.821 raeburn 9213: =item * &show_course()
9214:
9215: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9216: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9217:
9218: Inputs:
9219: None
9220:
9221: Outputs:
9222: Scalar: 1 if 'Course' to be used, 0 otherwise.
9223:
9224: =cut
9225:
9226: ###############################################
9227: sub show_course {
9228: my $course = !$env{'user.adv'};
9229: if (!$env{'user.adv'}) {
9230: foreach my $env (keys(%env)) {
9231: next if ($env !~ m/^user\.priv\./);
9232: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9233: $course = 0;
9234: last;
9235: }
9236: }
9237: }
9238: return $course;
9239: }
9240:
9241: ###############################################
9242:
9243: =pod
9244:
1.542 raeburn 9245: =item * &check_user_status()
1.274 raeburn 9246:
9247: Determines current status of supplied role for a
9248: specific user. Roles can be active, previous or future.
9249:
9250: Inputs:
9251: user's domain, user's username, course's domain,
1.375 raeburn 9252: course's number, optional section ID.
1.274 raeburn 9253:
9254: Outputs:
9255: role status: active, previous or future.
9256:
9257: =cut
9258:
9259: sub check_user_status {
1.412 raeburn 9260: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9261: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9262: my @uroles = keys(%userinfo);
1.274 raeburn 9263: my $srchstr;
9264: my $active_chk = 'none';
1.412 raeburn 9265: my $now = time;
1.274 raeburn 9266: if (@uroles > 0) {
1.908 raeburn 9267: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9268: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9269: } else {
1.412 raeburn 9270: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9271: }
9272: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9273: my $role_end = 0;
9274: my $role_start = 0;
9275: $active_chk = 'active';
1.412 raeburn 9276: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9277: $role_end = $1;
9278: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9279: $role_start = $1;
1.274 raeburn 9280: }
9281: }
9282: if ($role_start > 0) {
1.412 raeburn 9283: if ($now < $role_start) {
1.274 raeburn 9284: $active_chk = 'future';
9285: }
9286: }
9287: if ($role_end > 0) {
1.412 raeburn 9288: if ($now > $role_end) {
1.274 raeburn 9289: $active_chk = 'previous';
9290: }
9291: }
9292: }
9293: }
9294: return $active_chk;
9295: }
9296:
9297: ###############################################
9298:
9299: =pod
9300:
1.405 albertel 9301: =item * &get_sections()
1.233 raeburn 9302:
9303: Determines all the sections for a course including
9304: sections with students and sections containing other roles.
1.419 raeburn 9305: Incoming parameters:
9306:
9307: 1. domain
9308: 2. course number
9309: 3. reference to array containing roles for which sections should
9310: be gathered (optional).
9311: 4. reference to array containing status types for which sections
9312: should be gathered (optional).
9313:
9314: If the third argument is undefined, sections are gathered for any role.
9315: If the fourth argument is undefined, sections are gathered for any status.
9316: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9317:
1.374 raeburn 9318: Returns section hash (keys are section IDs, values are
9319: number of users in each section), subject to the
1.419 raeburn 9320: optional roles filter, optional status filter
1.233 raeburn 9321:
9322: =cut
9323:
9324: ###############################################
9325: sub get_sections {
1.419 raeburn 9326: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9327: if (!defined($cdom) || !defined($cnum)) {
9328: my $cid = $env{'request.course.id'};
9329:
9330: return if (!defined($cid));
9331:
9332: $cdom = $env{'course.'.$cid.'.domain'};
9333: $cnum = $env{'course.'.$cid.'.num'};
9334: }
9335:
9336: my %sectioncount;
1.419 raeburn 9337: my $now = time;
1.240 albertel 9338:
1.1118 raeburn 9339: my $check_students = 1;
9340: my $only_students = 0;
9341: if (ref($possible_roles) eq 'ARRAY') {
9342: if (grep(/^st$/,@{$possible_roles})) {
9343: if (@{$possible_roles} == 1) {
9344: $only_students = 1;
9345: }
9346: } else {
9347: $check_students = 0;
9348: }
9349: }
9350:
9351: if ($check_students) {
1.276 albertel 9352: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9353: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9354: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9355: my $start_index = &Apache::loncoursedata::CL_START();
9356: my $end_index = &Apache::loncoursedata::CL_END();
9357: my $status;
1.366 albertel 9358: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9359: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9360: $data->[$status_index],
9361: $data->[$start_index],
9362: $data->[$end_index]);
9363: if ($stu_status eq 'Active') {
9364: $status = 'active';
9365: } elsif ($end < $now) {
9366: $status = 'previous';
9367: } elsif ($start > $now) {
9368: $status = 'future';
9369: }
9370: if ($section ne '-1' && $section !~ /^\s*$/) {
9371: if ((!defined($possible_status)) || (($status ne '') &&
9372: (grep/^\Q$status\E$/,@{$possible_status}))) {
9373: $sectioncount{$section}++;
9374: }
1.240 albertel 9375: }
9376: }
9377: }
1.1118 raeburn 9378: if ($only_students) {
9379: return %sectioncount;
9380: }
1.240 albertel 9381: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9382: foreach my $user (sort(keys(%courseroles))) {
9383: if ($user !~ /^(\w{2})/) { next; }
9384: my ($role) = ($user =~ /^(\w{2})/);
9385: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9386: my ($section,$status);
1.240 albertel 9387: if ($role eq 'cr' &&
9388: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9389: $section=$1;
9390: }
9391: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9392: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9393: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9394: if ($end == -1 && $start == -1) {
9395: next; #deleted role
9396: }
9397: if (!defined($possible_status)) {
9398: $sectioncount{$section}++;
9399: } else {
9400: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9401: $status = 'active';
9402: } elsif ($end < $now) {
9403: $status = 'future';
9404: } elsif ($start > $now) {
9405: $status = 'previous';
9406: }
9407: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9408: $sectioncount{$section}++;
9409: }
9410: }
1.233 raeburn 9411: }
1.366 albertel 9412: return %sectioncount;
1.233 raeburn 9413: }
9414:
1.274 raeburn 9415: ###############################################
1.294 raeburn 9416:
9417: =pod
1.405 albertel 9418:
9419: =item * &get_course_users()
9420:
1.275 raeburn 9421: Retrieves usernames:domains for users in the specified course
9422: with specific role(s), and access status.
9423:
9424: Incoming parameters:
1.277 albertel 9425: 1. course domain
9426: 2. course number
9427: 3. access status: users must have - either active,
1.275 raeburn 9428: previous, future, or all.
1.277 albertel 9429: 4. reference to array of permissible roles
1.288 raeburn 9430: 5. reference to array of section restrictions (optional)
9431: 6. reference to results object (hash of hashes).
9432: 7. reference to optional userdata hash
1.609 raeburn 9433: 8. reference to optional statushash
1.630 raeburn 9434: 9. flag if privileged users (except those set to unhide in
9435: course settings) should be excluded
1.609 raeburn 9436: Keys of top level results hash are roles.
1.275 raeburn 9437: Keys of inner hashes are username:domain, with
9438: values set to access type.
1.288 raeburn 9439: Optional userdata hash returns an array with arguments in the
9440: same order as loncoursedata::get_classlist() for student data.
9441:
1.609 raeburn 9442: Optional statushash returns
9443:
1.288 raeburn 9444: Entries for end, start, section and status are blank because
9445: of the possibility of multiple values for non-student roles.
9446:
1.275 raeburn 9447: =cut
1.405 albertel 9448:
1.275 raeburn 9449: ###############################################
1.405 albertel 9450:
1.275 raeburn 9451: sub get_course_users {
1.630 raeburn 9452: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9453: my %idx = ();
1.419 raeburn 9454: my %seclists;
1.288 raeburn 9455:
9456: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9457: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9458: $idx{end} = &Apache::loncoursedata::CL_END();
9459: $idx{start} = &Apache::loncoursedata::CL_START();
9460: $idx{id} = &Apache::loncoursedata::CL_ID();
9461: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9462: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9463: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9464:
1.290 albertel 9465: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9466: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9467: my $now = time;
1.277 albertel 9468: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9469: my $match = 0;
1.412 raeburn 9470: my $secmatch = 0;
1.419 raeburn 9471: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9472: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9473: if ($section eq '') {
9474: $section = 'none';
9475: }
1.291 albertel 9476: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9477: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9478: $secmatch = 1;
9479: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9480: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9481: $secmatch = 1;
9482: }
9483: } else {
1.419 raeburn 9484: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9485: $secmatch = 1;
9486: }
1.290 albertel 9487: }
1.412 raeburn 9488: if (!$secmatch) {
9489: next;
9490: }
1.419 raeburn 9491: }
1.275 raeburn 9492: if (defined($$types{'active'})) {
1.288 raeburn 9493: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9494: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9495: $match = 1;
1.275 raeburn 9496: }
9497: }
9498: if (defined($$types{'previous'})) {
1.609 raeburn 9499: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9500: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9501: $match = 1;
1.275 raeburn 9502: }
9503: }
9504: if (defined($$types{'future'})) {
1.609 raeburn 9505: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9506: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9507: $match = 1;
1.275 raeburn 9508: }
9509: }
1.609 raeburn 9510: if ($match) {
9511: push(@{$seclists{$student}},$section);
9512: if (ref($userdata) eq 'HASH') {
9513: $$userdata{$student} = $$classlist{$student};
9514: }
9515: if (ref($statushash) eq 'HASH') {
9516: $statushash->{$student}{'st'}{$section} = $status;
9517: }
1.288 raeburn 9518: }
1.275 raeburn 9519: }
9520: }
1.412 raeburn 9521: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9522: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9523: my $now = time;
1.609 raeburn 9524: my %displaystatus = ( previous => 'Expired',
9525: active => 'Active',
9526: future => 'Future',
9527: );
1.1121 raeburn 9528: my (%nothide,@possdoms);
1.630 raeburn 9529: if ($hidepriv) {
9530: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9531: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9532: if ($user !~ /:/) {
9533: $nothide{join(':',split(/[\@]/,$user))}=1;
9534: } else {
9535: $nothide{$user} = 1;
9536: }
9537: }
1.1121 raeburn 9538: my @possdoms = ($cdom);
9539: if ($coursehash{'checkforpriv'}) {
9540: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9541: }
1.630 raeburn 9542: }
1.439 raeburn 9543: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9544: my $match = 0;
1.412 raeburn 9545: my $secmatch = 0;
1.439 raeburn 9546: my $status;
1.412 raeburn 9547: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9548: $user =~ s/:$//;
1.439 raeburn 9549: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9550: if ($end == -1 || $start == -1) {
9551: next;
9552: }
9553: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9554: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9555: my ($uname,$udom) = split(/:/,$user);
9556: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9557: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9558: $secmatch = 1;
9559: } elsif ($usec eq '') {
1.420 albertel 9560: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9561: $secmatch = 1;
9562: }
9563: } else {
9564: if (grep(/^\Q$usec\E$/,@{$sections})) {
9565: $secmatch = 1;
9566: }
9567: }
9568: if (!$secmatch) {
9569: next;
9570: }
1.288 raeburn 9571: }
1.419 raeburn 9572: if ($usec eq '') {
9573: $usec = 'none';
9574: }
1.275 raeburn 9575: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9576: if ($hidepriv) {
1.1121 raeburn 9577: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9578: (!$nothide{$uname.':'.$udom})) {
9579: next;
9580: }
9581: }
1.503 raeburn 9582: if ($end > 0 && $end < $now) {
1.439 raeburn 9583: $status = 'previous';
9584: } elsif ($start > $now) {
9585: $status = 'future';
9586: } else {
9587: $status = 'active';
9588: }
1.277 albertel 9589: foreach my $type (keys(%{$types})) {
1.275 raeburn 9590: if ($status eq $type) {
1.420 albertel 9591: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9592: push(@{$$users{$role}{$user}},$type);
9593: }
1.288 raeburn 9594: $match = 1;
9595: }
9596: }
1.419 raeburn 9597: if (($match) && (ref($userdata) eq 'HASH')) {
9598: if (!exists($$userdata{$uname.':'.$udom})) {
9599: &get_user_info($udom,$uname,\%idx,$userdata);
9600: }
1.420 albertel 9601: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9602: push(@{$seclists{$uname.':'.$udom}},$usec);
9603: }
1.609 raeburn 9604: if (ref($statushash) eq 'HASH') {
9605: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9606: }
1.275 raeburn 9607: }
9608: }
9609: }
9610: }
1.290 albertel 9611: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9612: if ((defined($cdom)) && (defined($cnum))) {
9613: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9614: if ( defined($csettings{'internal.courseowner'}) ) {
9615: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9616: next if ($owner eq '');
9617: my ($ownername,$ownerdom);
9618: if ($owner =~ /^([^:]+):([^:]+)$/) {
9619: $ownername = $1;
9620: $ownerdom = $2;
9621: } else {
9622: $ownername = $owner;
9623: $ownerdom = $cdom;
9624: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9625: }
9626: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9627: if (defined($userdata) &&
1.609 raeburn 9628: !exists($$userdata{$owner})) {
9629: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9630: if (!grep(/^none$/,@{$seclists{$owner}})) {
9631: push(@{$seclists{$owner}},'none');
9632: }
9633: if (ref($statushash) eq 'HASH') {
9634: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9635: }
1.290 albertel 9636: }
1.279 raeburn 9637: }
9638: }
9639: }
1.419 raeburn 9640: foreach my $user (keys(%seclists)) {
9641: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9642: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9643: }
1.275 raeburn 9644: }
9645: return;
9646: }
9647:
1.288 raeburn 9648: sub get_user_info {
9649: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9650: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9651: &plainname($uname,$udom,'lastname');
1.291 albertel 9652: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9653: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9654: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9655: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9656: return;
9657: }
1.275 raeburn 9658:
1.472 raeburn 9659: ###############################################
9660:
9661: =pod
9662:
9663: =item * &get_user_quota()
9664:
1.1134 raeburn 9665: Retrieves quota assigned for storage of user files.
9666: Default is to report quota for portfolio files.
1.472 raeburn 9667:
9668: Incoming parameters:
9669: 1. user's username
9670: 2. user's domain
1.1134 raeburn 9671: 3. quota name - portfolio, author, or course
1.1136 raeburn 9672: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 9673: 4. crstype - official, unofficial, textbook, placement or community,
9674: if quota name is course
1.472 raeburn 9675:
9676: Returns:
1.1163 raeburn 9677: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9678: 2. (Optional) Type of setting: custom or default
9679: (individually assigned or default for user's
9680: institutional status).
9681: 3. (Optional) - User's institutional status (e.g., faculty, staff
9682: or student - types as defined in localenroll::inst_usertypes
9683: for user's domain, which determines default quota for user.
9684: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9685:
9686: If a value has been stored in the user's environment,
1.536 raeburn 9687: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9688: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9689:
9690: =cut
9691:
9692: ###############################################
9693:
9694:
9695: sub get_user_quota {
1.1136 raeburn 9696: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9697: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9698: if (!defined($udom)) {
9699: $udom = $env{'user.domain'};
9700: }
9701: if (!defined($uname)) {
9702: $uname = $env{'user.name'};
9703: }
9704: if (($udom eq '' || $uname eq '') ||
9705: ($udom eq 'public') && ($uname eq 'public')) {
9706: $quota = 0;
1.536 raeburn 9707: $quotatype = 'default';
9708: $defquota = 0;
1.472 raeburn 9709: } else {
1.536 raeburn 9710: my $inststatus;
1.1134 raeburn 9711: if ($quotaname eq 'course') {
9712: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9713: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9714: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9715: } else {
9716: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9717: $quota = $cenv{'internal.uploadquota'};
9718: }
1.536 raeburn 9719: } else {
1.1134 raeburn 9720: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9721: if ($quotaname eq 'author') {
9722: $quota = $env{'environment.authorquota'};
9723: } else {
9724: $quota = $env{'environment.portfolioquota'};
9725: }
9726: $inststatus = $env{'environment.inststatus'};
9727: } else {
9728: my %userenv =
9729: &Apache::lonnet::get('environment',['portfolioquota',
9730: 'authorquota','inststatus'],$udom,$uname);
9731: my ($tmp) = keys(%userenv);
9732: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9733: if ($quotaname eq 'author') {
9734: $quota = $userenv{'authorquota'};
9735: } else {
9736: $quota = $userenv{'portfolioquota'};
9737: }
9738: $inststatus = $userenv{'inststatus'};
9739: } else {
9740: undef(%userenv);
9741: }
9742: }
9743: }
9744: if ($quota eq '' || wantarray) {
9745: if ($quotaname eq 'course') {
9746: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 9747: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 9748: ($crstype eq 'community') || ($crstype eq 'textbook') ||
9749: ($crstype eq 'placement')) {
1.1136 raeburn 9750: $defquota = $domdefs{$crstype.'quota'};
9751: }
9752: if ($defquota eq '') {
9753: $defquota = 500;
9754: }
1.1134 raeburn 9755: } else {
9756: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9757: }
9758: if ($quota eq '') {
9759: $quota = $defquota;
9760: $quotatype = 'default';
9761: } else {
9762: $quotatype = 'custom';
9763: }
1.472 raeburn 9764: }
9765: }
1.536 raeburn 9766: if (wantarray) {
9767: return ($quota,$quotatype,$settingstatus,$defquota);
9768: } else {
9769: return $quota;
9770: }
1.472 raeburn 9771: }
9772:
9773: ###############################################
9774:
9775: =pod
9776:
9777: =item * &default_quota()
9778:
1.536 raeburn 9779: Retrieves default quota assigned for storage of user portfolio files,
9780: given an (optional) user's institutional status.
1.472 raeburn 9781:
9782: Incoming parameters:
1.1142 raeburn 9783:
1.472 raeburn 9784: 1. domain
1.536 raeburn 9785: 2. (Optional) institutional status(es). This is a : separated list of
9786: status types (e.g., faculty, staff, student etc.)
9787: which apply to the user for whom the default is being retrieved.
9788: If the institutional status string in undefined, the domain
1.1134 raeburn 9789: default quota will be returned.
9790: 3. quota name - portfolio, author, or course
9791: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9792:
9793: Returns:
1.1142 raeburn 9794:
1.1163 raeburn 9795: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9796: 2. (Optional) institutional type which determined the value of the
9797: default quota.
1.472 raeburn 9798:
9799: If a value has been stored in the domain's configuration db,
9800: it will return that, otherwise it returns 20 (for backwards
9801: compatibility with domains which have not set up a configuration
1.1163 raeburn 9802: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9803:
1.536 raeburn 9804: If the user's status includes multiple types (e.g., staff and student),
9805: the largest default quota which applies to the user determines the
9806: default quota returned.
9807:
1.472 raeburn 9808: =cut
9809:
9810: ###############################################
9811:
9812:
9813: sub default_quota {
1.1134 raeburn 9814: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9815: my ($defquota,$settingstatus);
9816: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9817: ['quotas'],$udom);
1.1134 raeburn 9818: my $key = 'defaultquota';
9819: if ($quotaname eq 'author') {
9820: $key = 'authorquota';
9821: }
1.622 raeburn 9822: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9823: if ($inststatus ne '') {
1.765 raeburn 9824: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9825: foreach my $item (@statuses) {
1.1134 raeburn 9826: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9827: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9828: if ($defquota eq '') {
1.1134 raeburn 9829: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9830: $settingstatus = $item;
1.1134 raeburn 9831: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9832: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9833: $settingstatus = $item;
9834: }
9835: }
1.1134 raeburn 9836: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9837: if ($quotahash{'quotas'}{$item} ne '') {
9838: if ($defquota eq '') {
9839: $defquota = $quotahash{'quotas'}{$item};
9840: $settingstatus = $item;
9841: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9842: $defquota = $quotahash{'quotas'}{$item};
9843: $settingstatus = $item;
9844: }
1.536 raeburn 9845: }
9846: }
9847: }
9848: }
9849: if ($defquota eq '') {
1.1134 raeburn 9850: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9851: $defquota = $quotahash{'quotas'}{$key}{'default'};
9852: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9853: $defquota = $quotahash{'quotas'}{'default'};
9854: }
1.536 raeburn 9855: $settingstatus = 'default';
1.1139 raeburn 9856: if ($defquota eq '') {
9857: if ($quotaname eq 'author') {
9858: $defquota = 500;
9859: }
9860: }
1.536 raeburn 9861: }
9862: } else {
9863: $settingstatus = 'default';
1.1134 raeburn 9864: if ($quotaname eq 'author') {
9865: $defquota = 500;
9866: } else {
9867: $defquota = 20;
9868: }
1.536 raeburn 9869: }
9870: if (wantarray) {
9871: return ($defquota,$settingstatus);
1.472 raeburn 9872: } else {
1.536 raeburn 9873: return $defquota;
1.472 raeburn 9874: }
9875: }
9876:
1.1135 raeburn 9877: ###############################################
9878:
9879: =pod
9880:
1.1136 raeburn 9881: =item * &excess_filesize_warning()
1.1135 raeburn 9882:
9883: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 9884: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 9885: space to be exceeded.
1.1136 raeburn 9886:
9887: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 9888: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 9889:
1.1165 raeburn 9890: Inputs: 7
1.1136 raeburn 9891: 1. username or coursenum
1.1135 raeburn 9892: 2. domain
1.1136 raeburn 9893: 3. context ('author' or 'course')
1.1135 raeburn 9894: 4. filename of file for which action is being requested
9895: 5. filesize (kB) of file
9896: 6. action being taken: copy or upload.
1.1237 raeburn 9897: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 9898:
9899: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 9900: otherwise return null.
9901:
9902: =back
1.1135 raeburn 9903:
9904: =cut
9905:
1.1136 raeburn 9906: sub excess_filesize_warning {
1.1165 raeburn 9907: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 9908: my $current_disk_usage = 0;
1.1165 raeburn 9909: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 9910: if ($context eq 'author') {
9911: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9912: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9913: } else {
9914: foreach my $subdir ('docs','supplemental') {
9915: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9916: }
9917: }
1.1135 raeburn 9918: $disk_quota = int($disk_quota * 1000);
9919: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 9920: return '<p class="LC_warning">'.
1.1135 raeburn 9921: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 9922: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9923: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 9924: $disk_quota,$current_disk_usage).
9925: '</p>';
9926: }
9927: return;
9928: }
9929:
9930: ###############################################
9931:
9932:
1.1136 raeburn 9933:
9934:
1.384 raeburn 9935: sub get_secgrprole_info {
9936: my ($cdom,$cnum,$needroles,$type) = @_;
9937: my %sections_count = &get_sections($cdom,$cnum);
9938: my @sections = (sort {$a <=> $b} keys(%sections_count));
9939: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9940: my @groups = sort(keys(%curr_groups));
9941: my $allroles = [];
9942: my $rolehash;
9943: my $accesshash = {
9944: active => 'Currently has access',
9945: future => 'Will have future access',
9946: previous => 'Previously had access',
9947: };
9948: if ($needroles) {
9949: $rolehash = {'all' => 'all'};
1.385 albertel 9950: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9951: if (&Apache::lonnet::error(%user_roles)) {
9952: undef(%user_roles);
9953: }
9954: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9955: my ($role)=split(/\:/,$item,2);
9956: if ($role eq 'cr') { next; }
9957: if ($role =~ /^cr/) {
9958: $$rolehash{$role} = (split('/',$role))[3];
9959: } else {
9960: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9961: }
9962: }
9963: foreach my $key (sort(keys(%{$rolehash}))) {
9964: push(@{$allroles},$key);
9965: }
9966: push (@{$allroles},'st');
9967: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9968: }
9969: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9970: }
9971:
1.555 raeburn 9972: sub user_picker {
1.1255 raeburn 9973: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom) = @_;
1.555 raeburn 9974: my $currdom = $dom;
1.1253 raeburn 9975: my @alldoms = &Apache::lonnet::all_domains();
9976: if (@alldoms == 1) {
9977: my %domsrch = &Apache::lonnet::get_dom('configuration',
9978: ['directorysrch'],$alldoms[0]);
9979: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
9980: my $showdom = $domdesc;
9981: if ($showdom eq '') {
9982: $showdom = $dom;
9983: }
9984: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
9985: if ((!$domsrch{'directorysrch'}{'available'}) &&
9986: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
9987: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
9988: }
9989: }
9990: }
1.555 raeburn 9991: my %curr_selected = (
9992: srchin => 'dom',
1.580 raeburn 9993: srchby => 'lastname',
1.555 raeburn 9994: );
9995: my $srchterm;
1.625 raeburn 9996: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9997: if ($srch->{'srchby'} ne '') {
9998: $curr_selected{'srchby'} = $srch->{'srchby'};
9999: }
10000: if ($srch->{'srchin'} ne '') {
10001: $curr_selected{'srchin'} = $srch->{'srchin'};
10002: }
10003: if ($srch->{'srchtype'} ne '') {
10004: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10005: }
10006: if ($srch->{'srchdomain'} ne '') {
10007: $currdom = $srch->{'srchdomain'};
10008: }
10009: $srchterm = $srch->{'srchterm'};
10010: }
1.1222 damieng 10011: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10012: 'usr' => 'Search criteria',
1.563 raeburn 10013: 'doma' => 'Domain/institution to search',
1.558 albertel 10014: 'uname' => 'username',
10015: 'lastname' => 'last name',
1.555 raeburn 10016: 'lastfirst' => 'last name, first name',
1.558 albertel 10017: 'crs' => 'in this course',
1.576 raeburn 10018: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10019: 'alc' => 'all LON-CAPA',
1.573 raeburn 10020: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10021: 'exact' => 'is',
10022: 'contains' => 'contains',
1.569 raeburn 10023: 'begins' => 'begins with',
1.1222 damieng 10024: );
10025: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10026: 'youm' => "You must include some text to search for.",
10027: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10028: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10029: 'yomc' => "You must choose a domain when using an institutional directory search.",
10030: 'ymcd' => "You must choose a domain when using a domain search.",
10031: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10032: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10033: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10034: );
1.1222 damieng 10035: &html_escape(\%html_lt);
10036: &js_escape(\%js_lt);
1.1255 raeburn 10037: my $domform;
10038: if ($fixeddom) {
10039: $domform = &select_dom_form($currdom,'srchdomain',1,1,undef,[$currdom]);
10040: } else {
10041: $domform = &select_dom_form($currdom,'srchdomain',1,1);
10042: }
1.563 raeburn 10043: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10044:
10045: my @srchins = ('crs','dom','alc','instd');
10046:
10047: foreach my $option (@srchins) {
10048: # FIXME 'alc' option unavailable until
10049: # loncreateuser::print_user_query_page()
10050: # has been completed.
10051: next if ($option eq 'alc');
1.880 raeburn 10052: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10053: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 10054: if ($curr_selected{'srchin'} eq $option) {
10055: $srchinsel .= '
1.1222 damieng 10056: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10057: } else {
10058: $srchinsel .= '
1.1222 damieng 10059: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10060: }
1.555 raeburn 10061: }
1.563 raeburn 10062: $srchinsel .= "\n </select>\n";
1.555 raeburn 10063:
10064: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10065: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10066: if ($curr_selected{'srchby'} eq $option) {
10067: $srchbysel .= '
1.1222 damieng 10068: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10069: } else {
10070: $srchbysel .= '
1.1222 damieng 10071: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10072: }
10073: }
10074: $srchbysel .= "\n </select>\n";
10075:
10076: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10077: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10078: if ($curr_selected{'srchtype'} eq $option) {
10079: $srchtypesel .= '
1.1222 damieng 10080: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10081: } else {
10082: $srchtypesel .= '
1.1222 damieng 10083: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10084: }
10085: }
10086: $srchtypesel .= "\n </select>\n";
10087:
1.558 albertel 10088: my ($newuserscript,$new_user_create);
1.994 raeburn 10089: my $context_dom = $env{'request.role.domain'};
10090: if ($context eq 'requestcrs') {
10091: if ($env{'form.coursedom'} ne '') {
10092: $context_dom = $env{'form.coursedom'};
10093: }
10094: }
1.556 raeburn 10095: if ($forcenewuser) {
1.576 raeburn 10096: if (ref($srch) eq 'HASH') {
1.994 raeburn 10097: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10098: if ($cancreate) {
10099: $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>';
10100: } else {
1.799 bisitz 10101: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10102: my %usertypetext = (
10103: official => 'institutional',
10104: unofficial => 'non-institutional',
10105: );
1.799 bisitz 10106: $new_user_create = '<p class="LC_warning">'
10107: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10108: .' '
10109: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10110: ,'<a href="'.$helplink.'">','</a>')
10111: .'</p><br />';
1.627 raeburn 10112: }
1.576 raeburn 10113: }
10114: }
10115:
1.556 raeburn 10116: $newuserscript = <<"ENDSCRIPT";
10117:
1.570 raeburn 10118: function setSearch(createnew,callingForm) {
1.556 raeburn 10119: if (createnew == 1) {
1.570 raeburn 10120: for (var i=0; i<callingForm.srchby.length; i++) {
10121: if (callingForm.srchby.options[i].value == 'uname') {
10122: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10123: }
10124: }
1.570 raeburn 10125: for (var i=0; i<callingForm.srchin.length; i++) {
10126: if ( callingForm.srchin.options[i].value == 'dom') {
10127: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10128: }
10129: }
1.570 raeburn 10130: for (var i=0; i<callingForm.srchtype.length; i++) {
10131: if (callingForm.srchtype.options[i].value == 'exact') {
10132: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10133: }
10134: }
1.570 raeburn 10135: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10136: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10137: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10138: }
10139: }
10140: }
10141: }
10142: ENDSCRIPT
1.558 albertel 10143:
1.556 raeburn 10144: }
10145:
1.555 raeburn 10146: my $output = <<"END_BLOCK";
1.556 raeburn 10147: <script type="text/javascript">
1.824 bisitz 10148: // <![CDATA[
1.570 raeburn 10149: function validateEntry(callingForm) {
1.558 albertel 10150:
1.556 raeburn 10151: var checkok = 1;
1.558 albertel 10152: var srchin;
1.570 raeburn 10153: for (var i=0; i<callingForm.srchin.length; i++) {
10154: if ( callingForm.srchin[i].checked ) {
10155: srchin = callingForm.srchin[i].value;
1.558 albertel 10156: }
10157: }
10158:
1.570 raeburn 10159: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10160: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10161: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10162: var srchterm = callingForm.srchterm.value;
10163: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10164: var msg = "";
10165:
10166: if (srchterm == "") {
10167: checkok = 0;
1.1222 damieng 10168: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10169: }
10170:
1.569 raeburn 10171: if (srchtype== 'begins') {
10172: if (srchterm.length < 2) {
10173: checkok = 0;
1.1222 damieng 10174: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10175: }
10176: }
10177:
1.556 raeburn 10178: if (srchtype== 'contains') {
10179: if (srchterm.length < 3) {
10180: checkok = 0;
1.1222 damieng 10181: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10182: }
10183: }
10184: if (srchin == 'instd') {
10185: if (srchdomain == '') {
10186: checkok = 0;
1.1222 damieng 10187: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10188: }
10189: }
10190: if (srchin == 'dom') {
10191: if (srchdomain == '') {
10192: checkok = 0;
1.1222 damieng 10193: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10194: }
10195: }
10196: if (srchby == 'lastfirst') {
10197: if (srchterm.indexOf(",") == -1) {
10198: checkok = 0;
1.1222 damieng 10199: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10200: }
10201: if (srchterm.indexOf(",") == srchterm.length -1) {
10202: checkok = 0;
1.1222 damieng 10203: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10204: }
10205: }
10206: if (checkok == 0) {
1.1222 damieng 10207: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10208: return;
10209: }
10210: if (checkok == 1) {
1.570 raeburn 10211: callingForm.submit();
1.556 raeburn 10212: }
10213: }
10214:
10215: $newuserscript
10216:
1.824 bisitz 10217: // ]]>
1.556 raeburn 10218: </script>
1.558 albertel 10219:
10220: $new_user_create
10221:
1.555 raeburn 10222: END_BLOCK
1.558 albertel 10223:
1.876 raeburn 10224: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10225: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10226: $domform.
10227: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10228: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10229: $srchbysel.
10230: $srchtypesel.
10231: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10232: $srchinsel.
10233: &Apache::lonhtmlcommon::row_closure(1).
10234: &Apache::lonhtmlcommon::end_pick_box().
10235: '<br />';
1.1253 raeburn 10236: return ($output,1);
1.555 raeburn 10237: }
10238:
1.612 raeburn 10239: sub user_rule_check {
1.615 raeburn 10240: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10241: my ($response,%inst_response);
1.612 raeburn 10242: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10243: if (keys(%{$usershash}) > 1) {
10244: my (%by_username,%by_id,%userdoms);
10245: my $checkid;
10246: if (ref($checks) eq 'HASH') {
10247: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10248: $checkid = 1;
10249: }
10250: }
10251: foreach my $user (keys(%{$usershash})) {
10252: my ($uname,$udom) = split(/:/,$user);
10253: if ($checkid) {
10254: if (ref($usershash->{$user}) eq 'HASH') {
10255: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10256: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10257: $userdoms{$udom} = 1;
1.1227 raeburn 10258: if (ref($inst_results) eq 'HASH') {
10259: $inst_results->{$uname.':'.$udom} = {};
10260: }
1.1226 raeburn 10261: }
10262: }
10263: } else {
10264: $by_username{$udom}{$uname} = 1;
10265: $userdoms{$udom} = 1;
1.1227 raeburn 10266: if (ref($inst_results) eq 'HASH') {
10267: $inst_results->{$uname.':'.$udom} = {};
10268: }
1.1226 raeburn 10269: }
10270: }
10271: foreach my $udom (keys(%userdoms)) {
10272: if (!$got_rules->{$udom}) {
10273: my %domconfig = &Apache::lonnet::get_dom('configuration',
10274: ['usercreation'],$udom);
10275: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10276: foreach my $item ('username','id') {
10277: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10278: $$curr_rules{$udom}{$item} =
10279: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10280: }
10281: }
10282: }
10283: $got_rules->{$udom} = 1;
10284: }
1.612 raeburn 10285: }
1.1226 raeburn 10286: if ($checkid) {
10287: foreach my $udom (keys(%by_id)) {
10288: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10289: if ($outcome eq 'ok') {
1.1227 raeburn 10290: foreach my $id (keys(%{$by_id{$udom}})) {
10291: my $uname = $by_id{$udom}{$id};
10292: $inst_response{$uname.':'.$udom} = $outcome;
10293: }
1.1226 raeburn 10294: if (ref($results) eq 'HASH') {
10295: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10296: if (exists($inst_response{$uname.':'.$udom})) {
10297: $inst_response{$uname.':'.$udom} = $outcome;
10298: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10299: }
1.1226 raeburn 10300: }
10301: }
10302: }
1.612 raeburn 10303: }
1.615 raeburn 10304: } else {
1.1226 raeburn 10305: foreach my $udom (keys(%by_username)) {
10306: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10307: if ($outcome eq 'ok') {
1.1227 raeburn 10308: foreach my $uname (keys(%{$by_username{$udom}})) {
10309: $inst_response{$uname.':'.$udom} = $outcome;
10310: }
1.1226 raeburn 10311: if (ref($results) eq 'HASH') {
10312: foreach my $uname (keys(%{$results})) {
10313: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10314: }
10315: }
10316: }
10317: }
1.612 raeburn 10318: }
1.1226 raeburn 10319: } elsif (keys(%{$usershash}) == 1) {
10320: my $user = (keys(%{$usershash}))[0];
10321: my ($uname,$udom) = split(/:/,$user);
10322: if (($udom ne '') && ($uname ne '')) {
10323: if (ref($usershash->{$user}) eq 'HASH') {
10324: if (ref($checks) eq 'HASH') {
10325: if (defined($checks->{'username'})) {
10326: ($inst_response{$user},%{$inst_results->{$user}}) =
10327: &Apache::lonnet::get_instuser($udom,$uname);
10328: } elsif (defined($checks->{'id'})) {
10329: if ($usershash->{$user}->{'id'} ne '') {
10330: ($inst_response{$user},%{$inst_results->{$user}}) =
10331: &Apache::lonnet::get_instuser($udom,undef,
10332: $usershash->{$user}->{'id'});
10333: } else {
10334: ($inst_response{$user},%{$inst_results->{$user}}) =
10335: &Apache::lonnet::get_instuser($udom,$uname);
10336: }
1.585 raeburn 10337: }
1.1226 raeburn 10338: } else {
10339: ($inst_response{$user},%{$inst_results->{$user}}) =
10340: &Apache::lonnet::get_instuser($udom,$uname);
10341: return;
10342: }
10343: if (!$got_rules->{$udom}) {
10344: my %domconfig = &Apache::lonnet::get_dom('configuration',
10345: ['usercreation'],$udom);
10346: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10347: foreach my $item ('username','id') {
10348: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10349: $$curr_rules{$udom}{$item} =
10350: $domconfig{'usercreation'}{$item.'_rule'};
10351: }
10352: }
10353: }
10354: $got_rules->{$udom} = 1;
1.585 raeburn 10355: }
10356: }
1.1226 raeburn 10357: } else {
10358: return;
10359: }
10360: } else {
10361: return;
10362: }
10363: foreach my $user (keys(%{$usershash})) {
10364: my ($uname,$udom) = split(/:/,$user);
10365: next if (($udom eq '') || ($uname eq ''));
10366: my $id;
1.1227 raeburn 10367: if (ref($inst_results) eq 'HASH') {
10368: if (ref($inst_results->{$user}) eq 'HASH') {
10369: $id = $inst_results->{$user}->{'id'};
10370: }
10371: }
10372: if ($id eq '') {
10373: if (ref($usershash->{$user})) {
10374: $id = $usershash->{$user}->{'id'};
10375: }
1.585 raeburn 10376: }
1.612 raeburn 10377: foreach my $item (keys(%{$checks})) {
10378: if (ref($$curr_rules{$udom}) eq 'HASH') {
10379: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10380: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10381: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10382: $$curr_rules{$udom}{$item});
1.612 raeburn 10383: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10384: if ($rule_check{$rule}) {
10385: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10386: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10387: if (ref($inst_results) eq 'HASH') {
10388: if (ref($inst_results->{$user}) eq 'HASH') {
10389: if (keys(%{$inst_results->{$user}}) == 0) {
10390: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10391: } elsif ($item eq 'id') {
10392: if ($inst_results->{$user}->{'id'} eq '') {
10393: $$alerts{$item}{$udom}{$uname} = 1;
10394: }
1.615 raeburn 10395: }
1.612 raeburn 10396: }
10397: }
1.615 raeburn 10398: }
10399: last;
1.585 raeburn 10400: }
10401: }
10402: }
10403: }
10404: }
10405: }
10406: }
10407: }
1.612 raeburn 10408: return;
10409: }
10410:
10411: sub user_rule_formats {
10412: my ($domain,$domdesc,$curr_rules,$check) = @_;
10413: my %text = (
10414: 'username' => 'Usernames',
10415: 'id' => 'IDs',
10416: );
10417: my $output;
10418: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10419: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10420: if (@{$ruleorder} > 0) {
1.1102 raeburn 10421: $output = '<br />'.
10422: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10423: '<span class="LC_cusr_emph">','</span>',$domdesc).
10424: ' <ul>';
1.612 raeburn 10425: foreach my $rule (@{$ruleorder}) {
10426: if (ref($curr_rules) eq 'ARRAY') {
10427: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10428: if (ref($rules->{$rule}) eq 'HASH') {
10429: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10430: $rules->{$rule}{'desc'}.'</li>';
10431: }
10432: }
10433: }
10434: }
10435: $output .= '</ul>';
10436: }
10437: }
10438: return $output;
10439: }
10440:
10441: sub instrule_disallow_msg {
1.615 raeburn 10442: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10443: my $response;
10444: my %text = (
10445: item => 'username',
10446: items => 'usernames',
10447: match => 'matches',
10448: do => 'does',
10449: action => 'a username',
10450: one => 'one',
10451: );
10452: if ($count > 1) {
10453: $text{'item'} = 'usernames';
10454: $text{'match'} ='match';
10455: $text{'do'} = 'do';
10456: $text{'action'} = 'usernames',
10457: $text{'one'} = 'ones';
10458: }
10459: if ($checkitem eq 'id') {
10460: $text{'items'} = 'IDs';
10461: $text{'item'} = 'ID';
10462: $text{'action'} = 'an ID';
1.615 raeburn 10463: if ($count > 1) {
10464: $text{'item'} = 'IDs';
10465: $text{'action'} = 'IDs';
10466: }
1.612 raeburn 10467: }
1.674 bisitz 10468: $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 10469: if ($mode eq 'upload') {
10470: if ($checkitem eq 'username') {
10471: $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'}.");
10472: } elsif ($checkitem eq 'id') {
1.674 bisitz 10473: $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 10474: }
1.669 raeburn 10475: } elsif ($mode eq 'selfcreate') {
10476: if ($checkitem eq 'id') {
10477: $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.");
10478: }
1.615 raeburn 10479: } else {
10480: if ($checkitem eq 'username') {
10481: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10482: } elsif ($checkitem eq 'id') {
10483: $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.");
10484: }
1.612 raeburn 10485: }
10486: return $response;
1.585 raeburn 10487: }
10488:
1.624 raeburn 10489: sub personal_data_fieldtitles {
10490: my %fieldtitles = &Apache::lonlocal::texthash (
10491: id => 'Student/Employee ID',
10492: permanentemail => 'E-mail address',
10493: lastname => 'Last Name',
10494: firstname => 'First Name',
10495: middlename => 'Middle Name',
10496: generation => 'Generation',
10497: gen => 'Generation',
1.765 raeburn 10498: inststatus => 'Affiliation',
1.624 raeburn 10499: );
10500: return %fieldtitles;
10501: }
10502:
1.642 raeburn 10503: sub sorted_inst_types {
10504: my ($dom) = @_;
1.1185 raeburn 10505: my ($usertypes,$order);
10506: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10507: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10508: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10509: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10510: } else {
10511: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10512: }
1.642 raeburn 10513: my $othertitle = &mt('All users');
10514: if ($env{'request.course.id'}) {
1.668 raeburn 10515: $othertitle = &mt('Any users');
1.642 raeburn 10516: }
10517: my @types;
10518: if (ref($order) eq 'ARRAY') {
10519: @types = @{$order};
10520: }
10521: if (@types == 0) {
10522: if (ref($usertypes) eq 'HASH') {
10523: @types = sort(keys(%{$usertypes}));
10524: }
10525: }
10526: if (keys(%{$usertypes}) > 0) {
10527: $othertitle = &mt('Other users');
10528: }
10529: return ($othertitle,$usertypes,\@types);
10530: }
10531:
1.645 raeburn 10532: sub get_institutional_codes {
10533: my ($settings,$allcourses,$LC_code) = @_;
10534: # Get complete list of course sections to update
10535: my @currsections = ();
10536: my @currxlists = ();
10537: my $coursecode = $$settings{'internal.coursecode'};
10538:
10539: if ($$settings{'internal.sectionnums'} ne '') {
10540: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10541: }
10542:
10543: if ($$settings{'internal.crosslistings'} ne '') {
10544: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10545: }
10546:
10547: if (@currxlists > 0) {
10548: foreach (@currxlists) {
10549: if (m/^([^:]+):(\w*)$/) {
10550: unless (grep/^$1$/,@{$allcourses}) {
10551: push @{$allcourses},$1;
10552: $$LC_code{$1} = $2;
10553: }
10554: }
10555: }
10556: }
10557:
10558: if (@currsections > 0) {
10559: foreach (@currsections) {
10560: if (m/^(\w+):(\w*)$/) {
10561: my $sec = $coursecode.$1;
10562: my $lc_sec = $2;
10563: unless (grep/^$sec$/,@{$allcourses}) {
10564: push @{$allcourses},$sec;
10565: $$LC_code{$sec} = $lc_sec;
10566: }
10567: }
10568: }
10569: }
10570: return;
10571: }
10572:
1.971 raeburn 10573: sub get_standard_codeitems {
10574: return ('Year','Semester','Department','Number','Section');
10575: }
10576:
1.112 bowersj2 10577: =pod
10578:
1.780 raeburn 10579: =head1 Slot Helpers
10580:
10581: =over 4
10582:
10583: =item * sorted_slots()
10584:
1.1040 raeburn 10585: Sorts an array of slot names in order of an optional sort key,
10586: default sort is by slot start time (earliest first).
1.780 raeburn 10587:
10588: Inputs:
10589:
10590: =over 4
10591:
10592: slotsarr - Reference to array of unsorted slot names.
10593:
10594: slots - Reference to hash of hash, where outer hash keys are slot names.
10595:
1.1040 raeburn 10596: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10597:
1.549 albertel 10598: =back
10599:
1.780 raeburn 10600: Returns:
10601:
10602: =over 4
10603:
1.1040 raeburn 10604: sorted - An array of slot names sorted by a specified sort key
10605: (default sort key is start time of the slot).
1.780 raeburn 10606:
10607: =back
10608:
10609: =cut
10610:
10611:
10612: sub sorted_slots {
1.1040 raeburn 10613: my ($slotsarr,$slots,$sortkey) = @_;
10614: if ($sortkey eq '') {
10615: $sortkey = 'starttime';
10616: }
1.780 raeburn 10617: my @sorted;
10618: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10619: @sorted =
10620: sort {
10621: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10622: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10623: }
10624: if (ref($slots->{$a})) { return -1;}
10625: if (ref($slots->{$b})) { return 1;}
10626: return 0;
10627: } @{$slotsarr};
10628: }
10629: return @sorted;
10630: }
10631:
1.1040 raeburn 10632: =pod
10633:
10634: =item * get_future_slots()
10635:
10636: Inputs:
10637:
10638: =over 4
10639:
10640: cnum - course number
10641:
10642: cdom - course domain
10643:
10644: now - current UNIX time
10645:
10646: symb - optional symb
10647:
10648: =back
10649:
10650: Returns:
10651:
10652: =over 4
10653:
10654: sorted_reservable - ref to array of student_schedulable slots currently
10655: reservable, ordered by end date of reservation period.
10656:
10657: reservable_now - ref to hash of student_schedulable slots currently
10658: reservable.
10659:
10660: Keys in inner hash are:
10661: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10662: (b) endreserve: end date of reservation period.
10663: (c) uniqueperiod: start,end dates when slot is to be uniquely
10664: selected.
1.1040 raeburn 10665:
10666: sorted_future - ref to array of student_schedulable slots reservable in
10667: the future, ordered by start date of reservation period.
10668:
10669: future_reservable - ref to hash of student_schedulable slots reservable
10670: in the future.
10671:
10672: Keys in inner hash are:
10673: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10674: (b) startreserve: start date of reservation period.
10675: (c) uniqueperiod: start,end dates when slot is to be uniquely
10676: selected.
1.1040 raeburn 10677:
10678: =back
10679:
10680: =cut
10681:
10682: sub get_future_slots {
10683: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 10684: my $map;
10685: if ($symb) {
10686: ($map) = &Apache::lonnet::decode_symb($symb);
10687: }
1.1040 raeburn 10688: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10689: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10690: foreach my $slot (keys(%slots)) {
10691: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10692: if ($symb) {
1.1229 raeburn 10693: if ($slots{$slot}->{'symb'} ne '') {
10694: my $canuse;
10695: my %oksymbs;
10696: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
10697: map { $oksymbs{$_} = 1; } @slotsymbs;
10698: if ($oksymbs{$symb}) {
10699: $canuse = 1;
10700: } else {
10701: foreach my $item (@slotsymbs) {
10702: if ($item =~ /\.(page|sequence)$/) {
10703: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
10704: if (($map ne '') && ($map eq $sloturl)) {
10705: $canuse = 1;
10706: last;
10707: }
10708: }
10709: }
10710: }
10711: next unless ($canuse);
10712: }
1.1040 raeburn 10713: }
10714: if (($slots{$slot}->{'starttime'} > $now) &&
10715: ($slots{$slot}->{'endtime'} > $now)) {
10716: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10717: my $userallowed = 0;
10718: if ($slots{$slot}->{'allowedsections'}) {
10719: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10720: if (!defined($env{'request.role.sec'})
10721: && grep(/^No section assigned$/,@allowed_sec)) {
10722: $userallowed=1;
10723: } else {
10724: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10725: $userallowed=1;
10726: }
10727: }
10728: unless ($userallowed) {
10729: if (defined($env{'request.course.groups'})) {
10730: my @groups = split(/:/,$env{'request.course.groups'});
10731: foreach my $group (@groups) {
10732: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10733: $userallowed=1;
10734: last;
10735: }
10736: }
10737: }
10738: }
10739: }
10740: if ($slots{$slot}->{'allowedusers'}) {
10741: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10742: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10743: if (grep(/^\Q$user\E$/,@allowed_users)) {
10744: $userallowed = 1;
10745: }
10746: }
10747: next unless($userallowed);
10748: }
10749: my $startreserve = $slots{$slot}->{'startreserve'};
10750: my $endreserve = $slots{$slot}->{'endreserve'};
10751: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 10752: my $uniqueperiod;
10753: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10754: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10755: }
1.1040 raeburn 10756: if (($startreserve < $now) &&
10757: (!$endreserve || $endreserve > $now)) {
10758: my $lastres = $endreserve;
10759: if (!$lastres) {
10760: $lastres = $slots{$slot}->{'starttime'};
10761: }
10762: $reservable_now{$slot} = {
10763: symb => $symb,
1.1250 raeburn 10764: endreserve => $lastres,
10765: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10766: };
10767: } elsif (($startreserve > $now) &&
10768: (!$endreserve || $endreserve > $startreserve)) {
10769: $future_reservable{$slot} = {
10770: symb => $symb,
1.1250 raeburn 10771: startreserve => $startreserve,
10772: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10773: };
10774: }
10775: }
10776: }
10777: my @unsorted_reservable = keys(%reservable_now);
10778: if (@unsorted_reservable > 0) {
10779: @sorted_reservable =
10780: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10781: }
10782: my @unsorted_future = keys(%future_reservable);
10783: if (@unsorted_future > 0) {
10784: @sorted_future =
10785: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10786: }
10787: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10788: }
1.780 raeburn 10789:
10790: =pod
10791:
1.1057 foxr 10792: =back
10793:
1.549 albertel 10794: =head1 HTTP Helpers
10795:
10796: =over 4
10797:
1.648 raeburn 10798: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10799:
1.258 albertel 10800: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10801: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10802: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10803:
10804: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10805: $possible_names is an ref to an array of form element names. As an example:
10806: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10807: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10808:
10809: =cut
1.1 albertel 10810:
1.6 albertel 10811: sub get_unprocessed_cgi {
1.25 albertel 10812: my ($query,$possible_names)= @_;
1.26 matthew 10813: # $Apache::lonxml::debug=1;
1.356 albertel 10814: foreach my $pair (split(/&/,$query)) {
10815: my ($name, $value) = split(/=/,$pair);
1.369 www 10816: $name = &unescape($name);
1.25 albertel 10817: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10818: $value =~ tr/+/ /;
10819: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10820: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10821: }
1.16 harris41 10822: }
1.6 albertel 10823: }
10824:
1.112 bowersj2 10825: =pod
10826:
1.648 raeburn 10827: =item * &cacheheader()
1.112 bowersj2 10828:
10829: returns cache-controlling header code
10830:
10831: =cut
10832:
1.7 albertel 10833: sub cacheheader {
1.258 albertel 10834: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10835: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10836: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10837: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10838: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10839: return $output;
1.7 albertel 10840: }
10841:
1.112 bowersj2 10842: =pod
10843:
1.648 raeburn 10844: =item * &no_cache($r)
1.112 bowersj2 10845:
10846: specifies header code to not have cache
10847:
10848: =cut
10849:
1.9 albertel 10850: sub no_cache {
1.216 albertel 10851: my ($r) = @_;
10852: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10853: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10854: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10855: $r->no_cache(1);
10856: $r->header_out("Expires" => $date);
10857: $r->header_out("Pragma" => "no-cache");
1.123 www 10858: }
10859:
10860: sub content_type {
1.181 albertel 10861: my ($r,$type,$charset) = @_;
1.299 foxr 10862: if ($r) {
10863: # Note that printout.pl calls this with undef for $r.
10864: &no_cache($r);
10865: }
1.258 albertel 10866: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10867: unless ($charset) {
10868: $charset=&Apache::lonlocal::current_encoding;
10869: }
10870: if ($charset) { $type.='; charset='.$charset; }
10871: if ($r) {
10872: $r->content_type($type);
10873: } else {
10874: print("Content-type: $type\n\n");
10875: }
1.9 albertel 10876: }
1.25 albertel 10877:
1.112 bowersj2 10878: =pod
10879:
1.648 raeburn 10880: =item * &add_to_env($name,$value)
1.112 bowersj2 10881:
1.258 albertel 10882: adds $name to the %env hash with value
1.112 bowersj2 10883: $value, if $name already exists, the entry is converted to an array
10884: reference and $value is added to the array.
10885:
10886: =cut
10887:
1.25 albertel 10888: sub add_to_env {
10889: my ($name,$value)=@_;
1.258 albertel 10890: if (defined($env{$name})) {
10891: if (ref($env{$name})) {
1.25 albertel 10892: #already have multiple values
1.258 albertel 10893: push(@{ $env{$name} },$value);
1.25 albertel 10894: } else {
10895: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10896: my $first=$env{$name};
10897: undef($env{$name});
10898: push(@{ $env{$name} },$first,$value);
1.25 albertel 10899: }
10900: } else {
1.258 albertel 10901: $env{$name}=$value;
1.25 albertel 10902: }
1.31 albertel 10903: }
1.149 albertel 10904:
10905: =pod
10906:
1.648 raeburn 10907: =item * &get_env_multiple($name)
1.149 albertel 10908:
1.258 albertel 10909: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10910: values may be defined and end up as an array ref.
10911:
10912: returns an array of values
10913:
10914: =cut
10915:
10916: sub get_env_multiple {
10917: my ($name) = @_;
10918: my @values;
1.258 albertel 10919: if (defined($env{$name})) {
1.149 albertel 10920: # exists is it an array
1.258 albertel 10921: if (ref($env{$name})) {
10922: @values=@{ $env{$name} };
1.149 albertel 10923: } else {
1.258 albertel 10924: $values[0]=$env{$name};
1.149 albertel 10925: }
10926: }
10927: return(@values);
10928: }
10929:
1.1249 damieng 10930: # Looks at given dependencies, and returns something depending on the context.
10931: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
10932: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
10933: # For all other contexts, returns ($output, $counter, $numpathchg).
10934: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
10935: # $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.
10936: # $numpathchg: integer with the number of cleaned up dependency paths.
10937: # \%existing: hash reference clean path -> 1 only for existing dependencies.
10938: # \%mapping: hash reference clean path -> original path for all dependencies.
10939: # @param {string} actionurl - The path to the handler, indicative of the context.
10940: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
10941: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
10942: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
10943: # @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)
10944: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 10945: sub ask_for_embedded_content {
1.1249 damieng 10946: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 10947: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10948: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 10949: %currsubfile,%unused,$rem);
1.1071 raeburn 10950: my $counter = 0;
10951: my $numnew = 0;
1.987 raeburn 10952: my $numremref = 0;
10953: my $numinvalid = 0;
10954: my $numpathchg = 0;
10955: my $numexisting = 0;
1.1071 raeburn 10956: my $numunused = 0;
10957: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 10958: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10959: my $heading = &mt('Upload embedded files');
10960: my $buttontext = &mt('Upload');
10961:
1.1249 damieng 10962: # fills these variables based on the context:
10963: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
10964: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 10965: if ($env{'request.course.id'}) {
1.1123 raeburn 10966: if ($actionurl eq '/adm/dependencies') {
10967: $navmap = Apache::lonnavmaps::navmap->new();
10968: }
10969: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10970: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 10971: }
1.1123 raeburn 10972: if (($actionurl eq '/adm/portfolio') ||
10973: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10974: my $current_path='/';
10975: if ($env{'form.currentpath'}) {
10976: $current_path = $env{'form.currentpath'};
10977: }
10978: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 10979: $udom = $cdom;
10980: $uname = $cnum;
1.984 raeburn 10981: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10982: } else {
10983: $udom = $env{'user.domain'};
10984: $uname = $env{'user.name'};
10985: $url = '/userfiles/portfolio';
10986: }
1.987 raeburn 10987: $toplevel = $url.'/';
1.984 raeburn 10988: $url .= $current_path;
10989: $getpropath = 1;
1.987 raeburn 10990: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10991: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10992: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10993: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10994: $toplevel = $url;
1.984 raeburn 10995: if ($rest ne '') {
1.987 raeburn 10996: $url .= $rest;
10997: }
10998: } elsif ($actionurl eq '/adm/coursedocs') {
10999: if (ref($args) eq 'HASH') {
1.1071 raeburn 11000: $url = $args->{'docs_url'};
11001: $toplevel = $url;
1.1084 raeburn 11002: if ($args->{'context'} eq 'paste') {
11003: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11004: ($path) =
11005: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11006: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11007: $fileloc =~ s{^/}{};
11008: }
1.1071 raeburn 11009: }
1.1084 raeburn 11010: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11011: if ($env{'request.course.id'} ne '') {
11012: if (ref($args) eq 'HASH') {
11013: $url = $args->{'docs_url'};
11014: $title = $args->{'docs_title'};
1.1126 raeburn 11015: $toplevel = $url;
11016: unless ($toplevel =~ m{^/}) {
11017: $toplevel = "/$url";
11018: }
1.1085 raeburn 11019: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11020: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11021: $path = $1;
11022: } else {
11023: ($path) =
11024: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11025: }
1.1195 raeburn 11026: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11027: $fileloc = $toplevel;
11028: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11029: my ($udom,$uname,$fname) =
11030: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11031: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11032: } else {
11033: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11034: }
1.1071 raeburn 11035: $fileloc =~ s{^/}{};
11036: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11037: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11038: }
1.987 raeburn 11039: }
1.1123 raeburn 11040: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11041: $udom = $cdom;
11042: $uname = $cnum;
11043: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11044: $toplevel = $url;
11045: $path = $url;
11046: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11047: $fileloc =~ s{^/}{};
1.987 raeburn 11048: }
1.1249 damieng 11049:
11050: # parses the dependency paths to get some info
11051: # fills $newfiles, $mapping, $subdependencies, $dependencies
11052: # $newfiles: hash URL -> 1 for new files or external URLs
11053: # (will be completed later)
11054: # $mapping:
11055: # for external URLs: external URL -> external URL
11056: # for relative paths: clean path -> original path
11057: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11058: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11059: foreach my $file (keys(%{$allfiles})) {
11060: my $embed_file;
11061: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11062: $embed_file = $1;
11063: } else {
11064: $embed_file = $file;
11065: }
1.1158 raeburn 11066: my ($absolutepath,$cleaned_file);
11067: if ($embed_file =~ m{^\w+://}) {
11068: $cleaned_file = $embed_file;
1.1147 raeburn 11069: $newfiles{$cleaned_file} = 1;
11070: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11071: } else {
1.1158 raeburn 11072: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11073: if ($embed_file =~ m{^/}) {
11074: $absolutepath = $embed_file;
11075: }
1.1147 raeburn 11076: if ($cleaned_file =~ m{/}) {
11077: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11078: $path = &check_for_traversal($path,$url,$toplevel);
11079: my $item = $fname;
11080: if ($path ne '') {
11081: $item = $path.'/'.$fname;
11082: $subdependencies{$path}{$fname} = 1;
11083: } else {
11084: $dependencies{$item} = 1;
11085: }
11086: if ($absolutepath) {
11087: $mapping{$item} = $absolutepath;
11088: } else {
11089: $mapping{$item} = $embed_file;
11090: }
11091: } else {
11092: $dependencies{$embed_file} = 1;
11093: if ($absolutepath) {
1.1147 raeburn 11094: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11095: } else {
1.1147 raeburn 11096: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11097: }
11098: }
1.984 raeburn 11099: }
11100: }
1.1249 damieng 11101:
11102: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11103: # and lists
11104: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11105: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11106: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11107: # the path had to be cleaned up
11108: # $existing: hash clean path -> 1 if the file exists
11109: # $numexisting: number of keys in $existing
11110: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11111: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11112: # dependency subdirectories that are
11113: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11114: my $dirptr = 16384;
1.984 raeburn 11115: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11116: $currsubfile{$path} = {};
1.1123 raeburn 11117: if (($actionurl eq '/adm/portfolio') ||
11118: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11119: my ($sublistref,$listerror) =
11120: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11121: if (ref($sublistref) eq 'ARRAY') {
11122: foreach my $line (@{$sublistref}) {
11123: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11124: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11125: }
1.984 raeburn 11126: }
1.987 raeburn 11127: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11128: if (opendir(my $dir,$url.'/'.$path)) {
11129: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11130: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11131: }
1.1084 raeburn 11132: } elsif (($actionurl eq '/adm/dependencies') ||
11133: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11134: ($args->{'context'} eq 'paste')) ||
11135: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11136: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11137: my $dir;
11138: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11139: $dir = $fileloc;
11140: } else {
11141: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11142: }
1.1071 raeburn 11143: if ($dir ne '') {
11144: my ($sublistref,$listerror) =
11145: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11146: if (ref($sublistref) eq 'ARRAY') {
11147: foreach my $line (@{$sublistref}) {
11148: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11149: undef,$mtime)=split(/\&/,$line,12);
11150: unless (($testdir&$dirptr) ||
11151: ($file_name =~ /^\.\.?$/)) {
11152: $currsubfile{$path}{$file_name} = [$size,$mtime];
11153: }
11154: }
11155: }
11156: }
1.984 raeburn 11157: }
11158: }
11159: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11160: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11161: my $item = $path.'/'.$file;
11162: unless ($mapping{$item} eq $item) {
11163: $pathchanges{$item} = 1;
11164: }
11165: $existing{$item} = 1;
11166: $numexisting ++;
11167: } else {
11168: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11169: }
11170: }
1.1071 raeburn 11171: if ($actionurl eq '/adm/dependencies') {
11172: foreach my $path (keys(%currsubfile)) {
11173: if (ref($currsubfile{$path}) eq 'HASH') {
11174: foreach my $file (keys(%{$currsubfile{$path}})) {
11175: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11176: next if (($rem ne '') &&
11177: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11178: (ref($navmap) &&
11179: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11180: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11181: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11182: $unused{$path.'/'.$file} = 1;
11183: }
11184: }
11185: }
11186: }
11187: }
1.984 raeburn 11188: }
1.1249 damieng 11189:
11190: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11191: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11192: my %currfile;
1.1123 raeburn 11193: if (($actionurl eq '/adm/portfolio') ||
11194: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11195: my ($dirlistref,$listerror) =
11196: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11197: if (ref($dirlistref) eq 'ARRAY') {
11198: foreach my $line (@{$dirlistref}) {
11199: my ($file_name,$rest) = split(/\&/,$line,2);
11200: $currfile{$file_name} = 1;
11201: }
1.984 raeburn 11202: }
1.987 raeburn 11203: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11204: if (opendir(my $dir,$url)) {
1.987 raeburn 11205: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11206: map {$currfile{$_} = 1;} @dir_list;
11207: }
1.1084 raeburn 11208: } elsif (($actionurl eq '/adm/dependencies') ||
11209: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11210: ($args->{'context'} eq 'paste')) ||
11211: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11212: if ($env{'request.course.id'} ne '') {
11213: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11214: if ($dir ne '') {
11215: my ($dirlistref,$listerror) =
11216: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11217: if (ref($dirlistref) eq 'ARRAY') {
11218: foreach my $line (@{$dirlistref}) {
11219: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11220: $size,undef,$mtime)=split(/\&/,$line,12);
11221: unless (($testdir&$dirptr) ||
11222: ($file_name =~ /^\.\.?$/)) {
11223: $currfile{$file_name} = [$size,$mtime];
11224: }
11225: }
11226: }
11227: }
11228: }
1.984 raeburn 11229: }
1.1249 damieng 11230: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11231: # are not in subdirectories, using $currfile
1.984 raeburn 11232: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11233: if (exists($currfile{$file})) {
1.987 raeburn 11234: unless ($mapping{$file} eq $file) {
11235: $pathchanges{$file} = 1;
11236: }
11237: $existing{$file} = 1;
11238: $numexisting ++;
11239: } else {
1.984 raeburn 11240: $newfiles{$file} = 1;
11241: }
11242: }
1.1071 raeburn 11243: foreach my $file (keys(%currfile)) {
11244: unless (($file eq $filename) ||
11245: ($file eq $filename.'.bak') ||
11246: ($dependencies{$file})) {
1.1085 raeburn 11247: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11248: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11249: next if (($rem ne '') &&
11250: (($env{"httpref.$rem".$file} ne '') ||
11251: (ref($navmap) &&
11252: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11253: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11254: ($navmap->getResourceByUrl($rem.$1)))))));
11255: }
1.1085 raeburn 11256: }
1.1071 raeburn 11257: $unused{$file} = 1;
11258: }
11259: }
1.1249 damieng 11260:
11261: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11262: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11263: ($args->{'context'} eq 'paste')) {
11264: $counter = scalar(keys(%existing));
11265: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11266: return ($output,$counter,$numpathchg,\%existing);
11267: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11268: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11269: $counter = scalar(keys(%existing));
11270: $numpathchg = scalar(keys(%pathchanges));
11271: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11272: }
1.1249 damieng 11273:
11274: # returns HTML otherwise, with dependency results and to ask for more uploads
11275:
11276: # $upload_output: missing dependencies (with upload form)
11277: # $modify_output: uploaded dependencies (in use)
11278: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11279: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11280: if ($actionurl eq '/adm/dependencies') {
11281: next if ($embed_file =~ m{^\w+://});
11282: }
1.660 raeburn 11283: $upload_output .= &start_data_table_row().
1.1123 raeburn 11284: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11285: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11286: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11287: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11288: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11289: }
1.1123 raeburn 11290: $upload_output .= '</td>';
1.1071 raeburn 11291: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11292: $upload_output.='<td align="right">'.
11293: '<span class="LC_info LC_fontsize_medium">'.
11294: &mt("URL points to web address").'</span>';
1.987 raeburn 11295: $numremref++;
1.660 raeburn 11296: } elsif ($args->{'error_on_invalid_names'}
11297: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11298: $upload_output.='<td align="right"><span class="LC_warning">'.
11299: &mt('Invalid characters').'</span>';
1.987 raeburn 11300: $numinvalid++;
1.660 raeburn 11301: } else {
1.1123 raeburn 11302: $upload_output .= '<td>'.
11303: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11304: $embed_file,\%mapping,
1.1071 raeburn 11305: $allfiles,$codebase,'upload');
11306: $counter ++;
11307: $numnew ++;
1.987 raeburn 11308: }
11309: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11310: }
11311: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11312: if ($actionurl eq '/adm/dependencies') {
11313: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11314: $modify_output .= &start_data_table_row().
11315: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11316: '<img src="'.&icon($embed_file).'" border="0" />'.
11317: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11318: '<td>'.$size.'</td>'.
11319: '<td>'.$mtime.'</td>'.
11320: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11321: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11322: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11323: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11324: &embedded_file_element('upload_embedded',$counter,
11325: $embed_file,\%mapping,
11326: $allfiles,$codebase,'modify').
11327: '</div></td>'.
11328: &end_data_table_row()."\n";
11329: $counter ++;
11330: } else {
11331: $upload_output .= &start_data_table_row().
1.1123 raeburn 11332: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11333: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11334: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11335: &Apache::loncommon::end_data_table_row()."\n";
11336: }
11337: }
11338: my $delidx = $counter;
11339: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11340: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11341: $delete_output .= &start_data_table_row().
11342: '<td><img src="'.&icon($oldfile).'" />'.
11343: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11344: '<td>'.$size.'</td>'.
11345: '<td>'.$mtime.'</td>'.
11346: '<td><label><input type="checkbox" name="del_upload_dep" '.
11347: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11348: &embedded_file_element('upload_embedded',$delidx,
11349: $oldfile,\%mapping,$allfiles,
11350: $codebase,'delete').'</td>'.
11351: &end_data_table_row()."\n";
11352: $numunused ++;
11353: $delidx ++;
1.987 raeburn 11354: }
11355: if ($upload_output) {
11356: $upload_output = &start_data_table().
11357: $upload_output.
11358: &end_data_table()."\n";
11359: }
1.1071 raeburn 11360: if ($modify_output) {
11361: $modify_output = &start_data_table().
11362: &start_data_table_header_row().
11363: '<th>'.&mt('File').'</th>'.
11364: '<th>'.&mt('Size (KB)').'</th>'.
11365: '<th>'.&mt('Modified').'</th>'.
11366: '<th>'.&mt('Upload replacement?').'</th>'.
11367: &end_data_table_header_row().
11368: $modify_output.
11369: &end_data_table()."\n";
11370: }
11371: if ($delete_output) {
11372: $delete_output = &start_data_table().
11373: &start_data_table_header_row().
11374: '<th>'.&mt('File').'</th>'.
11375: '<th>'.&mt('Size (KB)').'</th>'.
11376: '<th>'.&mt('Modified').'</th>'.
11377: '<th>'.&mt('Delete?').'</th>'.
11378: &end_data_table_header_row().
11379: $delete_output.
11380: &end_data_table()."\n";
11381: }
1.987 raeburn 11382: my $applies = 0;
11383: if ($numremref) {
11384: $applies ++;
11385: }
11386: if ($numinvalid) {
11387: $applies ++;
11388: }
11389: if ($numexisting) {
11390: $applies ++;
11391: }
1.1071 raeburn 11392: if ($counter || $numunused) {
1.987 raeburn 11393: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11394: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11395: $state.'<h3>'.$heading.'</h3>';
11396: if ($actionurl eq '/adm/dependencies') {
11397: if ($numnew) {
11398: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11399: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11400: $upload_output.'<br />'."\n";
11401: }
11402: if ($numexisting) {
11403: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11404: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11405: $modify_output.'<br />'."\n";
11406: $buttontext = &mt('Save changes');
11407: }
11408: if ($numunused) {
11409: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11410: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11411: $delete_output.'<br />'."\n";
11412: $buttontext = &mt('Save changes');
11413: }
11414: } else {
11415: $output .= $upload_output.'<br />'."\n";
11416: }
11417: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11418: $counter.'" />'."\n";
11419: if ($actionurl eq '/adm/dependencies') {
11420: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11421: $numnew.'" />'."\n";
11422: } elsif ($actionurl eq '') {
1.987 raeburn 11423: $output .= '<input type="hidden" name="phase" value="three" />';
11424: }
11425: } elsif ($applies) {
11426: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11427: if ($applies > 1) {
11428: $output .=
1.1123 raeburn 11429: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11430: if ($numremref) {
11431: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11432: }
11433: if ($numinvalid) {
11434: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11435: }
11436: if ($numexisting) {
11437: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11438: }
11439: $output .= '</ul><br />';
11440: } elsif ($numremref) {
11441: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11442: } elsif ($numinvalid) {
11443: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11444: } elsif ($numexisting) {
11445: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11446: }
11447: $output .= $upload_output.'<br />';
11448: }
11449: my ($pathchange_output,$chgcount);
1.1071 raeburn 11450: $chgcount = $counter;
1.987 raeburn 11451: if (keys(%pathchanges) > 0) {
11452: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11453: if ($counter) {
1.987 raeburn 11454: $output .= &embedded_file_element('pathchange',$chgcount,
11455: $embed_file,\%mapping,
1.1071 raeburn 11456: $allfiles,$codebase,'change');
1.987 raeburn 11457: } else {
11458: $pathchange_output .=
11459: &start_data_table_row().
11460: '<td><input type ="checkbox" name="namechange" value="'.
11461: $chgcount.'" checked="checked" /></td>'.
11462: '<td>'.$mapping{$embed_file}.'</td>'.
11463: '<td>'.$embed_file.
11464: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11465: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11466: '</td>'.&end_data_table_row();
1.660 raeburn 11467: }
1.987 raeburn 11468: $numpathchg ++;
11469: $chgcount ++;
1.660 raeburn 11470: }
11471: }
1.1127 raeburn 11472: if (($counter) || ($numunused)) {
1.987 raeburn 11473: if ($numpathchg) {
11474: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11475: $numpathchg.'" />'."\n";
11476: }
11477: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11478: ($actionurl eq '/adm/imsimport')) {
11479: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11480: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11481: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11482: } elsif ($actionurl eq '/adm/dependencies') {
11483: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11484: }
1.1123 raeburn 11485: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11486: } elsif ($numpathchg) {
11487: my %pathchange = ();
11488: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11489: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11490: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11491: }
1.987 raeburn 11492: }
1.1071 raeburn 11493: return ($output,$counter,$numpathchg);
1.987 raeburn 11494: }
11495:
1.1147 raeburn 11496: =pod
11497:
11498: =item * clean_path($name)
11499:
11500: Performs clean-up of directories, subdirectories and filename in an
11501: embedded object, referenced in an HTML file which is being uploaded
11502: to a course or portfolio, where
11503: "Upload embedded images/multimedia files if HTML file" checkbox was
11504: checked.
11505:
11506: Clean-up is similar to replacements in lonnet::clean_filename()
11507: except each / between sub-directory and next level is preserved.
11508:
11509: =cut
11510:
11511: sub clean_path {
11512: my ($embed_file) = @_;
11513: $embed_file =~s{^/+}{};
11514: my @contents;
11515: if ($embed_file =~ m{/}) {
11516: @contents = split(/\//,$embed_file);
11517: } else {
11518: @contents = ($embed_file);
11519: }
11520: my $lastidx = scalar(@contents)-1;
11521: for (my $i=0; $i<=$lastidx; $i++) {
11522: $contents[$i]=~s{\\}{/}g;
11523: $contents[$i]=~s/\s+/\_/g;
11524: $contents[$i]=~s{[^/\w\.\-]}{}g;
11525: if ($i == $lastidx) {
11526: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11527: }
11528: }
11529: if ($lastidx > 0) {
11530: return join('/',@contents);
11531: } else {
11532: return $contents[0];
11533: }
11534: }
11535:
1.987 raeburn 11536: sub embedded_file_element {
1.1071 raeburn 11537: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11538: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11539: (ref($codebase) eq 'HASH'));
11540: my $output;
1.1071 raeburn 11541: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11542: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11543: }
11544: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11545: &escape($embed_file).'" />';
11546: unless (($context eq 'upload_embedded') &&
11547: ($mapping->{$embed_file} eq $embed_file)) {
11548: $output .='
11549: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11550: }
11551: my $attrib;
11552: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11553: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11554: }
11555: $output .=
11556: "\n\t\t".
11557: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11558: $attrib.'" />';
11559: if (exists($codebase->{$mapping->{$embed_file}})) {
11560: $output .=
11561: "\n\t\t".
11562: '<input name="codebase_'.$num.'" type="hidden" value="'.
11563: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11564: }
1.987 raeburn 11565: return $output;
1.660 raeburn 11566: }
11567:
1.1071 raeburn 11568: sub get_dependency_details {
11569: my ($currfile,$currsubfile,$embed_file) = @_;
11570: my ($size,$mtime,$showsize,$showmtime);
11571: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11572: if ($embed_file =~ m{/}) {
11573: my ($path,$fname) = split(/\//,$embed_file);
11574: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11575: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11576: }
11577: } else {
11578: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11579: ($size,$mtime) = @{$currfile->{$embed_file}};
11580: }
11581: }
11582: $showsize = $size/1024.0;
11583: $showsize = sprintf("%.1f",$showsize);
11584: if ($mtime > 0) {
11585: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11586: }
11587: }
11588: return ($showsize,$showmtime);
11589: }
11590:
11591: sub ask_embedded_js {
11592: return <<"END";
11593: <script type="text/javascript"">
11594: // <![CDATA[
11595: function toggleBrowse(counter) {
11596: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11597: var fileid = document.getElementById('embedded_item_'+counter);
11598: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11599: if (chkboxid.checked == true) {
11600: uploaddivid.style.display='block';
11601: } else {
11602: uploaddivid.style.display='none';
11603: fileid.value = '';
11604: }
11605: }
11606: // ]]>
11607: </script>
11608:
11609: END
11610: }
11611:
1.661 raeburn 11612: sub upload_embedded {
11613: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11614: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11615: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11616: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11617: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11618: my $orig_uploaded_filename =
11619: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11620: foreach my $type ('orig','ref','attrib','codebase') {
11621: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11622: $env{'form.embedded_'.$type.'_'.$i} =
11623: &unescape($env{'form.embedded_'.$type.'_'.$i});
11624: }
11625: }
1.661 raeburn 11626: my ($path,$fname) =
11627: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11628: # no path, whole string is fname
11629: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11630: $fname = &Apache::lonnet::clean_filename($fname);
11631: # See if there is anything left
11632: next if ($fname eq '');
11633:
11634: # Check if file already exists as a file or directory.
11635: my ($state,$msg);
11636: if ($context eq 'portfolio') {
11637: my $port_path = $dirpath;
11638: if ($group ne '') {
11639: $port_path = "groups/$group/$port_path";
11640: }
1.987 raeburn 11641: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11642: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11643: $dir_root,$port_path,$disk_quota,
11644: $current_disk_usage,$uname,$udom);
11645: if ($state eq 'will_exceed_quota'
1.984 raeburn 11646: || $state eq 'file_locked') {
1.661 raeburn 11647: $output .= $msg;
11648: next;
11649: }
11650: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11651: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11652: if ($state eq 'exists') {
11653: $output .= $msg;
11654: next;
11655: }
11656: }
11657: # Check if extension is valid
11658: if (($fname =~ /\.(\w+)$/) &&
11659: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11660: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11661: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11662: next;
11663: } elsif (($fname =~ /\.(\w+)$/) &&
11664: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11665: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11666: next;
11667: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11668: $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 11669: next;
11670: }
11671: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11672: my $subdir = $path;
11673: $subdir =~ s{/+$}{};
1.661 raeburn 11674: if ($context eq 'portfolio') {
1.984 raeburn 11675: my $result;
11676: if ($state eq 'existingfile') {
11677: $result=
11678: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11679: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11680: } else {
1.984 raeburn 11681: $result=
11682: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11683: $dirpath.
1.1123 raeburn 11684: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11685: if ($result !~ m|^/uploaded/|) {
11686: $output .= '<span class="LC_error">'
11687: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11688: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11689: .'</span><br />';
11690: next;
11691: } else {
1.987 raeburn 11692: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11693: $path.$fname.'</span>').'<br />';
1.984 raeburn 11694: }
1.661 raeburn 11695: }
1.1123 raeburn 11696: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 11697: my $extendedsubdir = $dirpath.'/'.$subdir;
11698: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11699: my $result =
1.1126 raeburn 11700: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11701: if ($result !~ m|^/uploaded/|) {
11702: $output .= '<span class="LC_error">'
11703: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11704: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11705: .'</span><br />';
11706: next;
11707: } else {
11708: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11709: $path.$fname.'</span>').'<br />';
1.1125 raeburn 11710: if ($context eq 'syllabus') {
11711: &Apache::lonnet::make_public_indefinitely($result);
11712: }
1.987 raeburn 11713: }
1.661 raeburn 11714: } else {
11715: # Save the file
11716: my $target = $env{'form.embedded_item_'.$i};
11717: my $fullpath = $dir_root.$dirpath.'/'.$path;
11718: my $dest = $fullpath.$fname;
11719: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11720: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11721: my $count;
11722: my $filepath = $dir_root;
1.1027 raeburn 11723: foreach my $subdir (@parts) {
11724: $filepath .= "/$subdir";
11725: if (!-e $filepath) {
1.661 raeburn 11726: mkdir($filepath,0770);
11727: }
11728: }
11729: my $fh;
11730: if (!open($fh,'>'.$dest)) {
11731: &Apache::lonnet::logthis('Failed to create '.$dest);
11732: $output .= '<span class="LC_error">'.
1.1071 raeburn 11733: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11734: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11735: '</span><br />';
11736: } else {
11737: if (!print $fh $env{'form.embedded_item_'.$i}) {
11738: &Apache::lonnet::logthis('Failed to write to '.$dest);
11739: $output .= '<span class="LC_error">'.
1.1071 raeburn 11740: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11741: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11742: '</span><br />';
11743: } else {
1.987 raeburn 11744: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11745: $url.'</span>').'<br />';
11746: unless ($context eq 'testbank') {
11747: $footer .= &mt('View embedded file: [_1]',
11748: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11749: }
11750: }
11751: close($fh);
11752: }
11753: }
11754: if ($env{'form.embedded_ref_'.$i}) {
11755: $pathchange{$i} = 1;
11756: }
11757: }
11758: if ($output) {
11759: $output = '<p>'.$output.'</p>';
11760: }
11761: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11762: $returnflag = 'ok';
1.1071 raeburn 11763: my $numpathchgs = scalar(keys(%pathchange));
11764: if ($numpathchgs > 0) {
1.987 raeburn 11765: if ($context eq 'portfolio') {
11766: $output .= '<p>'.&mt('or').'</p>';
11767: } elsif ($context eq 'testbank') {
1.1071 raeburn 11768: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11769: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11770: $returnflag = 'modify_orightml';
11771: }
11772: }
1.1071 raeburn 11773: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11774: }
11775:
11776: sub modify_html_form {
11777: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11778: my $end = 0;
11779: my $modifyform;
11780: if ($context eq 'upload_embedded') {
11781: return unless (ref($pathchange) eq 'HASH');
11782: if ($env{'form.number_embedded_items'}) {
11783: $end += $env{'form.number_embedded_items'};
11784: }
11785: if ($env{'form.number_pathchange_items'}) {
11786: $end += $env{'form.number_pathchange_items'};
11787: }
11788: if ($end) {
11789: for (my $i=0; $i<$end; $i++) {
11790: if ($i < $env{'form.number_embedded_items'}) {
11791: next unless($pathchange->{$i});
11792: }
11793: $modifyform .=
11794: &start_data_table_row().
11795: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11796: 'checked="checked" /></td>'.
11797: '<td>'.$env{'form.embedded_ref_'.$i}.
11798: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11799: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11800: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11801: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11802: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11803: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11804: '<td>'.$env{'form.embedded_orig_'.$i}.
11805: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11806: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11807: &end_data_table_row();
1.1071 raeburn 11808: }
1.987 raeburn 11809: }
11810: } else {
11811: $modifyform = $pathchgtable;
11812: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11813: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11814: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11815: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11816: }
11817: }
11818: if ($modifyform) {
1.1071 raeburn 11819: if ($actionurl eq '/adm/dependencies') {
11820: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11821: }
1.987 raeburn 11822: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11823: '<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".
11824: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11825: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11826: '</ol></p>'."\n".'<p>'.
11827: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11828: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11829: &start_data_table()."\n".
11830: &start_data_table_header_row().
11831: '<th>'.&mt('Change?').'</th>'.
11832: '<th>'.&mt('Current reference').'</th>'.
11833: '<th>'.&mt('Required reference').'</th>'.
11834: &end_data_table_header_row()."\n".
11835: $modifyform.
11836: &end_data_table().'<br />'."\n".$hiddenstate.
11837: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11838: '</form>'."\n";
11839: }
11840: return;
11841: }
11842:
11843: sub modify_html_refs {
1.1123 raeburn 11844: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11845: my $container;
11846: if ($context eq 'portfolio') {
11847: $container = $env{'form.container'};
11848: } elsif ($context eq 'coursedoc') {
11849: $container = $env{'form.primaryurl'};
1.1071 raeburn 11850: } elsif ($context eq 'manage_dependencies') {
11851: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11852: $container = "/$container";
1.1123 raeburn 11853: } elsif ($context eq 'syllabus') {
11854: $container = $url;
1.987 raeburn 11855: } else {
1.1027 raeburn 11856: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11857: }
11858: my (%allfiles,%codebase,$output,$content);
11859: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 11860: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11861: if (wantarray) {
11862: return ('',0,0);
11863: } else {
11864: return;
11865: }
11866: }
11867: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11868: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11869: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11870: if (wantarray) {
11871: return ('',0,0);
11872: } else {
11873: return;
11874: }
11875: }
1.987 raeburn 11876: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11877: if ($content eq '-1') {
11878: if (wantarray) {
11879: return ('',0,0);
11880: } else {
11881: return;
11882: }
11883: }
1.987 raeburn 11884: } else {
1.1071 raeburn 11885: unless ($container =~ /^\Q$dir_root\E/) {
11886: if (wantarray) {
11887: return ('',0,0);
11888: } else {
11889: return;
11890: }
11891: }
1.987 raeburn 11892: if (open(my $fh,"<$container")) {
11893: $content = join('', <$fh>);
11894: close($fh);
11895: } else {
1.1071 raeburn 11896: if (wantarray) {
11897: return ('',0,0);
11898: } else {
11899: return;
11900: }
1.987 raeburn 11901: }
11902: }
11903: my ($count,$codebasecount) = (0,0);
11904: my $mm = new File::MMagic;
11905: my $mime_type = $mm->checktype_contents($content);
11906: if ($mime_type eq 'text/html') {
11907: my $parse_result =
11908: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11909: \%codebase,\$content);
11910: if ($parse_result eq 'ok') {
11911: foreach my $i (@changes) {
11912: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11913: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11914: if ($allfiles{$ref}) {
11915: my $newname = $orig;
11916: my ($attrib_regexp,$codebase);
1.1006 raeburn 11917: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11918: if ($attrib_regexp =~ /:/) {
11919: $attrib_regexp =~ s/\:/|/g;
11920: }
11921: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11922: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11923: $count += $numchg;
1.1123 raeburn 11924: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 11925: delete($allfiles{$ref});
1.987 raeburn 11926: }
11927: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11928: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11929: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11930: $codebasecount ++;
11931: }
11932: }
11933: }
1.1123 raeburn 11934: my $skiprewrites;
1.987 raeburn 11935: if ($count || $codebasecount) {
11936: my $saveresult;
1.1071 raeburn 11937: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11938: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11939: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11940: if ($url eq $container) {
11941: my ($fname) = ($container =~ m{/([^/]+)$});
11942: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11943: $count,'<span class="LC_filename">'.
1.1071 raeburn 11944: $fname.'</span>').'</p>';
1.987 raeburn 11945: } else {
11946: $output = '<p class="LC_error">'.
11947: &mt('Error: update failed for: [_1].',
11948: '<span class="LC_filename">'.
11949: $container.'</span>').'</p>';
11950: }
1.1123 raeburn 11951: if ($context eq 'syllabus') {
11952: unless ($saveresult eq 'ok') {
11953: $skiprewrites = 1;
11954: }
11955: }
1.987 raeburn 11956: } else {
11957: if (open(my $fh,">$container")) {
11958: print $fh $content;
11959: close($fh);
11960: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11961: $count,'<span class="LC_filename">'.
11962: $container.'</span>').'</p>';
1.661 raeburn 11963: } else {
1.987 raeburn 11964: $output = '<p class="LC_error">'.
11965: &mt('Error: could not update [_1].',
11966: '<span class="LC_filename">'.
11967: $container.'</span>').'</p>';
1.661 raeburn 11968: }
11969: }
11970: }
1.1123 raeburn 11971: if (($context eq 'syllabus') && (!$skiprewrites)) {
11972: my ($actionurl,$state);
11973: $actionurl = "/public/$udom/$uname/syllabus";
11974: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11975: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11976: \%codebase,
11977: {'context' => 'rewrites',
11978: 'ignore_remote_references' => 1,});
11979: if (ref($mapping) eq 'HASH') {
11980: my $rewrites = 0;
11981: foreach my $key (keys(%{$mapping})) {
11982: next if ($key =~ m{^https?://});
11983: my $ref = $mapping->{$key};
11984: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11985: my $attrib;
11986: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11987: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11988: }
11989: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11990: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11991: $rewrites += $numchg;
11992: }
11993: }
11994: if ($rewrites) {
11995: my $saveresult;
11996: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11997: if ($url eq $container) {
11998: my ($fname) = ($container =~ m{/([^/]+)$});
11999: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12000: $count,'<span class="LC_filename">'.
12001: $fname.'</span>').'</p>';
12002: } else {
12003: $output .= '<p class="LC_error">'.
12004: &mt('Error: could not update links in [_1].',
12005: '<span class="LC_filename">'.
12006: $container.'</span>').'</p>';
12007:
12008: }
12009: }
12010: }
12011: }
1.987 raeburn 12012: } else {
12013: &logthis('Failed to parse '.$container.
12014: ' to modify references: '.$parse_result);
1.661 raeburn 12015: }
12016: }
1.1071 raeburn 12017: if (wantarray) {
12018: return ($output,$count,$codebasecount);
12019: } else {
12020: return $output;
12021: }
1.661 raeburn 12022: }
12023:
12024: sub check_for_existing {
12025: my ($path,$fname,$element) = @_;
12026: my ($state,$msg);
12027: if (-d $path.'/'.$fname) {
12028: $state = 'exists';
12029: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12030: } elsif (-e $path.'/'.$fname) {
12031: $state = 'exists';
12032: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12033: }
12034: if ($state eq 'exists') {
12035: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12036: }
12037: return ($state,$msg);
12038: }
12039:
12040: sub check_for_upload {
12041: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12042: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12043: my $filesize = length($env{'form.'.$element});
12044: if (!$filesize) {
12045: my $msg = '<span class="LC_error">'.
12046: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12047: '<span class="LC_filename">'.$fname.'</span>',
12048: $filesize).'<br />'.
1.1007 raeburn 12049: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12050: '</span>';
12051: return ('zero_bytes',$msg);
12052: }
12053: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12054: my $getpropath = 1;
1.1021 raeburn 12055: my ($dirlistref,$listerror) =
12056: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12057: my $found_file = 0;
12058: my $locked_file = 0;
1.991 raeburn 12059: my @lockers;
12060: my $navmap;
12061: if ($env{'request.course.id'}) {
12062: $navmap = Apache::lonnavmaps::navmap->new();
12063: }
1.1021 raeburn 12064: if (ref($dirlistref) eq 'ARRAY') {
12065: foreach my $line (@{$dirlistref}) {
12066: my ($file_name,$rest)=split(/\&/,$line,2);
12067: if ($file_name eq $fname){
12068: $file_name = $path.$file_name;
12069: if ($group ne '') {
12070: $file_name = $group.$file_name;
12071: }
12072: $found_file = 1;
12073: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12074: foreach my $lock (@lockers) {
12075: if (ref($lock) eq 'ARRAY') {
12076: my ($symb,$crsid) = @{$lock};
12077: if ($crsid eq $env{'request.course.id'}) {
12078: if (ref($navmap)) {
12079: my $res = $navmap->getBySymb($symb);
12080: foreach my $part (@{$res->parts()}) {
12081: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12082: unless (($slot_status == $res->RESERVED) ||
12083: ($slot_status == $res->RESERVED_LOCATION)) {
12084: $locked_file = 1;
12085: }
1.991 raeburn 12086: }
1.1021 raeburn 12087: } else {
12088: $locked_file = 1;
1.991 raeburn 12089: }
12090: } else {
12091: $locked_file = 1;
12092: }
12093: }
1.1021 raeburn 12094: }
12095: } else {
12096: my @info = split(/\&/,$rest);
12097: my $currsize = $info[6]/1000;
12098: if ($currsize < $filesize) {
12099: my $extra = $filesize - $currsize;
12100: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12101: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12102: &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 12103: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12104: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12105: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12106: return ('will_exceed_quota',$msg);
12107: }
1.984 raeburn 12108: }
12109: }
1.661 raeburn 12110: }
12111: }
12112: }
12113: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12114: my $msg = '<p class="LC_warning">'.
12115: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12116: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12117: return ('will_exceed_quota',$msg);
12118: } elsif ($found_file) {
12119: if ($locked_file) {
1.1179 bisitz 12120: my $msg = '<p class="LC_warning">';
1.661 raeburn 12121: $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 12122: $msg .= '</p>';
1.661 raeburn 12123: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12124: return ('file_locked',$msg);
12125: } else {
1.1179 bisitz 12126: my $msg = '<p class="LC_error">';
1.984 raeburn 12127: $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 12128: $msg .= '</p>';
1.984 raeburn 12129: return ('existingfile',$msg);
1.661 raeburn 12130: }
12131: }
12132: }
12133:
1.987 raeburn 12134: sub check_for_traversal {
12135: my ($path,$url,$toplevel) = @_;
12136: my @parts=split(/\//,$path);
12137: my $cleanpath;
12138: my $fullpath = $url;
12139: for (my $i=0;$i<@parts;$i++) {
12140: next if ($parts[$i] eq '.');
12141: if ($parts[$i] eq '..') {
12142: $fullpath =~ s{([^/]+/)$}{};
12143: } else {
12144: $fullpath .= $parts[$i].'/';
12145: }
12146: }
12147: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12148: $cleanpath = $1;
12149: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12150: my $curr_toprel = $1;
12151: my @parts = split(/\//,$curr_toprel);
12152: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12153: my @urlparts = split(/\//,$url_toprel);
12154: my $doubledots;
12155: my $startdiff = -1;
12156: for (my $i=0; $i<@urlparts; $i++) {
12157: if ($startdiff == -1) {
12158: unless ($urlparts[$i] eq $parts[$i]) {
12159: $startdiff = $i;
12160: $doubledots .= '../';
12161: }
12162: } else {
12163: $doubledots .= '../';
12164: }
12165: }
12166: if ($startdiff > -1) {
12167: $cleanpath = $doubledots;
12168: for (my $i=$startdiff; $i<@parts; $i++) {
12169: $cleanpath .= $parts[$i].'/';
12170: }
12171: }
12172: }
12173: $cleanpath =~ s{(/)$}{};
12174: return $cleanpath;
12175: }
1.31 albertel 12176:
1.1053 raeburn 12177: sub is_archive_file {
12178: my ($mimetype) = @_;
12179: if (($mimetype eq 'application/octet-stream') ||
12180: ($mimetype eq 'application/x-stuffit') ||
12181: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12182: return 1;
12183: }
12184: return;
12185: }
12186:
12187: sub decompress_form {
1.1065 raeburn 12188: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12189: my %lt = &Apache::lonlocal::texthash (
12190: this => 'This file is an archive file.',
1.1067 raeburn 12191: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12192: itsc => 'Its contents are as follows:',
1.1053 raeburn 12193: youm => 'You may wish to extract its contents.',
12194: extr => 'Extract contents',
1.1067 raeburn 12195: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12196: proa => 'Process automatically?',
1.1053 raeburn 12197: yes => 'Yes',
12198: no => 'No',
1.1067 raeburn 12199: fold => 'Title for folder containing movie',
12200: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12201: );
1.1065 raeburn 12202: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12203: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12204: my $info = &list_archive_contents($fileloc,\@paths);
12205: if (@paths) {
12206: foreach my $path (@paths) {
12207: $path =~ s{^/}{};
1.1067 raeburn 12208: if ($path =~ m{^([^/]+)/$}) {
12209: $topdir = $1;
12210: }
1.1065 raeburn 12211: if ($path =~ m{^([^/]+)/}) {
12212: $toplevel{$1} = $path;
12213: } else {
12214: $toplevel{$path} = $path;
12215: }
12216: }
12217: }
1.1067 raeburn 12218: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12219: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12220: "$topdir/media/",
12221: "$topdir/media/$topdir.mp4",
12222: "$topdir/media/FirstFrame.png",
12223: "$topdir/media/player.swf",
12224: "$topdir/media/swfobject.js",
12225: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12226: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12227: "$topdir/$topdir.mp4",
12228: "$topdir/$topdir\_config.xml",
12229: "$topdir/$topdir\_controller.swf",
12230: "$topdir/$topdir\_embed.css",
12231: "$topdir/$topdir\_First_Frame.png",
12232: "$topdir/$topdir\_player.html",
12233: "$topdir/$topdir\_Thumbnails.png",
12234: "$topdir/playerProductInstall.swf",
12235: "$topdir/scripts/",
12236: "$topdir/scripts/config_xml.js",
12237: "$topdir/scripts/handlebars.js",
12238: "$topdir/scripts/jquery-1.7.1.min.js",
12239: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12240: "$topdir/scripts/modernizr.js",
12241: "$topdir/scripts/player-min.js",
12242: "$topdir/scripts/swfobject.js",
12243: "$topdir/skins/",
12244: "$topdir/skins/configuration_express.xml",
12245: "$topdir/skins/express_show/",
12246: "$topdir/skins/express_show/player-min.css",
12247: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12248: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12249: "$topdir/$topdir.mp4",
12250: "$topdir/$topdir\_config.xml",
12251: "$topdir/$topdir\_controller.swf",
12252: "$topdir/$topdir\_embed.css",
12253: "$topdir/$topdir\_First_Frame.png",
12254: "$topdir/$topdir\_player.html",
12255: "$topdir/$topdir\_Thumbnails.png",
12256: "$topdir/playerProductInstall.swf",
12257: "$topdir/scripts/",
12258: "$topdir/scripts/config_xml.js",
12259: "$topdir/scripts/techsmith-smart-player.min.js",
12260: "$topdir/skins/",
12261: "$topdir/skins/configuration_express.xml",
12262: "$topdir/skins/express_show/",
12263: "$topdir/skins/express_show/spritesheet.min.css",
12264: "$topdir/skins/express_show/spritesheet.png",
12265: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12266: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12267: if (@diffs == 0) {
1.1164 raeburn 12268: $is_camtasia = 6;
12269: } else {
1.1197 raeburn 12270: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12271: if (@diffs == 0) {
12272: $is_camtasia = 8;
1.1197 raeburn 12273: } else {
12274: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12275: if (@diffs == 0) {
12276: $is_camtasia = 8;
12277: }
1.1164 raeburn 12278: }
1.1067 raeburn 12279: }
12280: }
12281: my $output;
12282: if ($is_camtasia) {
12283: $output = <<"ENDCAM";
12284: <script type="text/javascript" language="Javascript">
12285: // <![CDATA[
12286:
12287: function camtasiaToggle() {
12288: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12289: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12290: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12291: document.getElementById('camtasia_titles').style.display='block';
12292: } else {
12293: document.getElementById('camtasia_titles').style.display='none';
12294: }
12295: }
12296: }
12297: return;
12298: }
12299:
12300: // ]]>
12301: </script>
12302: <p>$lt{'camt'}</p>
12303: ENDCAM
1.1065 raeburn 12304: } else {
1.1067 raeburn 12305: $output = '<p>'.$lt{'this'};
12306: if ($info eq '') {
12307: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12308: } else {
12309: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12310: '<div><pre>'.$info.'</pre></div>';
12311: }
1.1065 raeburn 12312: }
1.1067 raeburn 12313: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12314: my $duplicates;
12315: my $num = 0;
12316: if (ref($dirlist) eq 'ARRAY') {
12317: foreach my $item (@{$dirlist}) {
12318: if (ref($item) eq 'ARRAY') {
12319: if (exists($toplevel{$item->[0]})) {
12320: $duplicates .=
12321: &start_data_table_row().
12322: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12323: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12324: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12325: 'value="1" />'.&mt('Yes').'</label>'.
12326: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12327: '<td>'.$item->[0].'</td>';
12328: if ($item->[2]) {
12329: $duplicates .= '<td>'.&mt('Directory').'</td>';
12330: } else {
12331: $duplicates .= '<td>'.&mt('File').'</td>';
12332: }
12333: $duplicates .= '<td>'.$item->[3].'</td>'.
12334: '<td>'.
12335: &Apache::lonlocal::locallocaltime($item->[4]).
12336: '</td>'.
12337: &end_data_table_row();
12338: $num ++;
12339: }
12340: }
12341: }
12342: }
12343: my $itemcount;
12344: if (@paths > 0) {
12345: $itemcount = scalar(@paths);
12346: } else {
12347: $itemcount = 1;
12348: }
1.1067 raeburn 12349: if ($is_camtasia) {
12350: $output .= $lt{'auto'}.'<br />'.
12351: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12352: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12353: $lt{'yes'}.'</label> <label>'.
12354: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12355: $lt{'no'}.'</label></span><br />'.
12356: '<div id="camtasia_titles" style="display:block">'.
12357: &Apache::lonhtmlcommon::start_pick_box().
12358: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12359: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12360: &Apache::lonhtmlcommon::row_closure().
12361: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12362: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12363: &Apache::lonhtmlcommon::row_closure(1).
12364: &Apache::lonhtmlcommon::end_pick_box().
12365: '</div>';
12366: }
1.1065 raeburn 12367: $output .=
12368: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12369: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12370: "\n";
1.1065 raeburn 12371: if ($duplicates ne '') {
12372: $output .= '<p><span class="LC_warning">'.
12373: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12374: &start_data_table().
12375: &start_data_table_header_row().
12376: '<th>'.&mt('Overwrite?').'</th>'.
12377: '<th>'.&mt('Name').'</th>'.
12378: '<th>'.&mt('Type').'</th>'.
12379: '<th>'.&mt('Size').'</th>'.
12380: '<th>'.&mt('Last modified').'</th>'.
12381: &end_data_table_header_row().
12382: $duplicates.
12383: &end_data_table().
12384: '</p>';
12385: }
1.1067 raeburn 12386: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12387: if (ref($hiddenelements) eq 'HASH') {
12388: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12389: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12390: }
12391: }
12392: $output .= <<"END";
1.1067 raeburn 12393: <br />
1.1053 raeburn 12394: <input type="submit" name="decompress" value="$lt{'extr'}" />
12395: </form>
12396: $noextract
12397: END
12398: return $output;
12399: }
12400:
1.1065 raeburn 12401: sub decompression_utility {
12402: my ($program) = @_;
12403: my @utilities = ('tar','gunzip','bunzip2','unzip');
12404: my $location;
12405: if (grep(/^\Q$program\E$/,@utilities)) {
12406: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12407: '/usr/sbin/') {
12408: if (-x $dir.$program) {
12409: $location = $dir.$program;
12410: last;
12411: }
12412: }
12413: }
12414: return $location;
12415: }
12416:
12417: sub list_archive_contents {
12418: my ($file,$pathsref) = @_;
12419: my (@cmd,$output);
12420: my $needsregexp;
12421: if ($file =~ /\.zip$/) {
12422: @cmd = (&decompression_utility('unzip'),"-l");
12423: $needsregexp = 1;
12424: } elsif (($file =~ m/\.tar\.gz$/) ||
12425: ($file =~ /\.tgz$/)) {
12426: @cmd = (&decompression_utility('tar'),"-ztf");
12427: } elsif ($file =~ /\.tar\.bz2$/) {
12428: @cmd = (&decompression_utility('tar'),"-jtf");
12429: } elsif ($file =~ m|\.tar$|) {
12430: @cmd = (&decompression_utility('tar'),"-tf");
12431: }
12432: if (@cmd) {
12433: undef($!);
12434: undef($@);
12435: if (open(my $fh,"-|", @cmd, $file)) {
12436: while (my $line = <$fh>) {
12437: $output .= $line;
12438: chomp($line);
12439: my $item;
12440: if ($needsregexp) {
12441: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12442: } else {
12443: $item = $line;
12444: }
12445: if ($item ne '') {
12446: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12447: push(@{$pathsref},$item);
12448: }
12449: }
12450: }
12451: close($fh);
12452: }
12453: }
12454: return $output;
12455: }
12456:
1.1053 raeburn 12457: sub decompress_uploaded_file {
12458: my ($file,$dir) = @_;
12459: &Apache::lonnet::appenv({'cgi.file' => $file});
12460: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12461: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12462: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12463: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12464: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12465: my $decompressed = $env{'cgi.decompressed'};
12466: &Apache::lonnet::delenv('cgi.file');
12467: &Apache::lonnet::delenv('cgi.dir');
12468: &Apache::lonnet::delenv('cgi.decompressed');
12469: return ($decompressed,$result);
12470: }
12471:
1.1055 raeburn 12472: sub process_decompression {
12473: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
12474: my ($dir,$error,$warning,$output);
1.1180 raeburn 12475: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12476: $error = &mt('Filename not a supported archive file type.').
12477: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12478: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12479: } else {
12480: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12481: if ($docuhome eq 'no_host') {
12482: $error = &mt('Could not determine home server for course.');
12483: } else {
12484: my @ids=&Apache::lonnet::current_machine_ids();
12485: my $currdir = "$dir_root/$destination";
12486: if (grep(/^\Q$docuhome\E$/,@ids)) {
12487: $dir = &LONCAPA::propath($docudom,$docuname).
12488: "$dir_root/$destination";
12489: } else {
12490: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12491: "$dir_root/$docudom/$docuname/$destination";
12492: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12493: $error = &mt('Archive file not found.');
12494: }
12495: }
1.1065 raeburn 12496: my (@to_overwrite,@to_skip);
12497: if ($env{'form.archive_overwrite_total'} > 0) {
12498: my $total = $env{'form.archive_overwrite_total'};
12499: for (my $i=0; $i<$total; $i++) {
12500: if ($env{'form.archive_overwrite_'.$i} == 1) {
12501: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12502: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12503: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12504: }
12505: }
12506: }
12507: my $numskip = scalar(@to_skip);
12508: if (($numskip > 0) &&
12509: ($numskip == $env{'form.archive_itemcount'})) {
12510: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12511: } elsif ($dir eq '') {
1.1055 raeburn 12512: $error = &mt('Directory containing archive file unavailable.');
12513: } elsif (!$error) {
1.1065 raeburn 12514: my ($decompressed,$display);
12515: if ($numskip > 0) {
12516: my $tempdir = time.'_'.$$.int(rand(10000));
12517: mkdir("$dir/$tempdir",0755);
12518: system("mv $dir/$file $dir/$tempdir/$file");
12519: ($decompressed,$display) =
12520: &decompress_uploaded_file($file,"$dir/$tempdir");
12521: foreach my $item (@to_skip) {
12522: if (($item ne '') && ($item !~ /\.\./)) {
12523: if (-f "$dir/$tempdir/$item") {
12524: unlink("$dir/$tempdir/$item");
12525: } elsif (-d "$dir/$tempdir/$item") {
12526: system("rm -rf $dir/$tempdir/$item");
12527: }
12528: }
12529: }
12530: system("mv $dir/$tempdir/* $dir");
12531: rmdir("$dir/$tempdir");
12532: } else {
12533: ($decompressed,$display) =
12534: &decompress_uploaded_file($file,$dir);
12535: }
1.1055 raeburn 12536: if ($decompressed eq 'ok') {
1.1065 raeburn 12537: $output = '<p class="LC_info">'.
12538: &mt('Files extracted successfully from archive.').
12539: '</p>'."\n";
1.1055 raeburn 12540: my ($warning,$result,@contents);
12541: my ($newdirlistref,$newlisterror) =
12542: &Apache::lonnet::dirlist($currdir,$docudom,
12543: $docuname,1);
12544: my (%is_dir,%changes,@newitems);
12545: my $dirptr = 16384;
1.1065 raeburn 12546: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12547: foreach my $dir_line (@{$newdirlistref}) {
12548: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 12549: unless (($item =~ /^\.+$/) || ($item eq $file) ||
12550: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 12551: push(@newitems,$item);
12552: if ($dirptr&$testdir) {
12553: $is_dir{$item} = 1;
12554: }
12555: $changes{$item} = 1;
12556: }
12557: }
12558: }
12559: if (keys(%changes) > 0) {
12560: foreach my $item (sort(@newitems)) {
12561: if ($changes{$item}) {
12562: push(@contents,$item);
12563: }
12564: }
12565: }
12566: if (@contents > 0) {
1.1067 raeburn 12567: my $wantform;
12568: unless ($env{'form.autoextract_camtasia'}) {
12569: $wantform = 1;
12570: }
1.1056 raeburn 12571: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12572: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12573: $currdir,\%is_dir,
12574: \%children,\%parent,
1.1056 raeburn 12575: \@contents,\%dirorder,
12576: \%titles,$wantform);
1.1055 raeburn 12577: if ($datatable ne '') {
12578: $output .= &archive_options_form('decompressed',$datatable,
12579: $count,$hiddenelem);
1.1065 raeburn 12580: my $startcount = 6;
1.1055 raeburn 12581: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12582: \%titles,\%children);
1.1055 raeburn 12583: }
1.1067 raeburn 12584: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 12585: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12586: my %displayed;
12587: my $total = 1;
12588: $env{'form.archive_directory'} = [];
12589: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12590: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12591: $path =~ s{/$}{};
12592: my $item;
12593: if ($path ne '') {
12594: $item = "$path/$titles{$i}";
12595: } else {
12596: $item = $titles{$i};
12597: }
12598: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12599: if ($item eq $contents[0]) {
12600: push(@{$env{'form.archive_directory'}},$i);
12601: $env{'form.archive_'.$i} = 'display';
12602: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12603: $displayed{'folder'} = $i;
1.1164 raeburn 12604: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12605: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12606: $env{'form.archive_'.$i} = 'display';
12607: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12608: $displayed{'web'} = $i;
12609: } else {
1.1164 raeburn 12610: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12611: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12612: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12613: push(@{$env{'form.archive_directory'}},$i);
12614: }
12615: $env{'form.archive_'.$i} = 'dependency';
12616: }
12617: $total ++;
12618: }
12619: for (my $i=1; $i<$total; $i++) {
12620: next if ($i == $displayed{'web'});
12621: next if ($i == $displayed{'folder'});
12622: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12623: }
12624: $env{'form.phase'} = 'decompress_cleanup';
12625: $env{'form.archivedelete'} = 1;
12626: $env{'form.archive_count'} = $total-1;
12627: $output .=
12628: &process_extracted_files('coursedocs',$docudom,
12629: $docuname,$destination,
12630: $dir_root,$hiddenelem);
12631: }
1.1055 raeburn 12632: } else {
12633: $warning = &mt('No new items extracted from archive file.');
12634: }
12635: } else {
12636: $output = $display;
12637: $error = &mt('An error occurred during extraction from the archive file.');
12638: }
12639: }
12640: }
12641: }
12642: if ($error) {
12643: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12644: $error.'</p>'."\n";
12645: }
12646: if ($warning) {
12647: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12648: }
12649: return $output;
12650: }
12651:
12652: sub get_extracted {
1.1056 raeburn 12653: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12654: $titles,$wantform) = @_;
1.1055 raeburn 12655: my $count = 0;
12656: my $depth = 0;
12657: my $datatable;
1.1056 raeburn 12658: my @hierarchy;
1.1055 raeburn 12659: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12660: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12661: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12662: foreach my $item (@{$contents}) {
12663: $count ++;
1.1056 raeburn 12664: @{$dirorder->{$count}} = @hierarchy;
12665: $titles->{$count} = $item;
1.1055 raeburn 12666: &archive_hierarchy($depth,$count,$parent,$children);
12667: if ($wantform) {
12668: $datatable .= &archive_row($is_dir->{$item},$item,
12669: $currdir,$depth,$count);
12670: }
12671: if ($is_dir->{$item}) {
12672: $depth ++;
1.1056 raeburn 12673: push(@hierarchy,$count);
12674: $parent->{$depth} = $count;
1.1055 raeburn 12675: $datatable .=
12676: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12677: \$depth,\$count,\@hierarchy,$dirorder,
12678: $children,$parent,$titles,$wantform);
1.1055 raeburn 12679: $depth --;
1.1056 raeburn 12680: pop(@hierarchy);
1.1055 raeburn 12681: }
12682: }
12683: return ($count,$datatable);
12684: }
12685:
12686: sub recurse_extracted_archive {
1.1056 raeburn 12687: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12688: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12689: my $result='';
1.1056 raeburn 12690: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12691: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12692: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12693: return $result;
12694: }
12695: my $dirptr = 16384;
12696: my ($newdirlistref,$newlisterror) =
12697: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12698: if (ref($newdirlistref) eq 'ARRAY') {
12699: foreach my $dir_line (@{$newdirlistref}) {
12700: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12701: unless ($item =~ /^\.+$/) {
12702: $$count ++;
1.1056 raeburn 12703: @{$dirorder->{$$count}} = @{$hierarchy};
12704: $titles->{$$count} = $item;
1.1055 raeburn 12705: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12706:
1.1055 raeburn 12707: my $is_dir;
12708: if ($dirptr&$testdir) {
12709: $is_dir = 1;
12710: }
12711: if ($wantform) {
12712: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12713: }
12714: if ($is_dir) {
12715: $$depth ++;
1.1056 raeburn 12716: push(@{$hierarchy},$$count);
12717: $parent->{$$depth} = $$count;
1.1055 raeburn 12718: $result .=
12719: &recurse_extracted_archive("$currdir/$item",$docudom,
12720: $docuname,$depth,$count,
1.1056 raeburn 12721: $hierarchy,$dirorder,$children,
12722: $parent,$titles,$wantform);
1.1055 raeburn 12723: $$depth --;
1.1056 raeburn 12724: pop(@{$hierarchy});
1.1055 raeburn 12725: }
12726: }
12727: }
12728: }
12729: return $result;
12730: }
12731:
12732: sub archive_hierarchy {
12733: my ($depth,$count,$parent,$children) =@_;
12734: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12735: if (exists($parent->{$depth})) {
12736: $children->{$parent->{$depth}} .= $count.':';
12737: }
12738: }
12739: return;
12740: }
12741:
12742: sub archive_row {
12743: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12744: my ($name) = ($item =~ m{([^/]+)$});
12745: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12746: 'display' => 'Add as file',
1.1055 raeburn 12747: 'dependency' => 'Include as dependency',
12748: 'discard' => 'Discard',
12749: );
12750: if ($is_dir) {
1.1059 raeburn 12751: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12752: }
1.1056 raeburn 12753: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12754: my $offset = 0;
1.1055 raeburn 12755: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12756: $offset ++;
1.1065 raeburn 12757: if ($action ne 'display') {
12758: $offset ++;
12759: }
1.1055 raeburn 12760: $output .= '<td><span class="LC_nobreak">'.
12761: '<label><input type="radio" name="archive_'.$count.
12762: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12763: my $text = $choices{$action};
12764: if ($is_dir) {
12765: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12766: if ($action eq 'display') {
1.1059 raeburn 12767: $text = &mt('Add as folder');
1.1055 raeburn 12768: }
1.1056 raeburn 12769: } else {
12770: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12771:
12772: }
12773: $output .= ' /> '.$choices{$action}.'</label></span>';
12774: if ($action eq 'dependency') {
12775: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12776: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12777: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12778: '<option value=""></option>'."\n".
12779: '</select>'."\n".
12780: '</div>';
1.1059 raeburn 12781: } elsif ($action eq 'display') {
12782: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12783: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12784: '</div>';
1.1055 raeburn 12785: }
1.1056 raeburn 12786: $output .= '</td>';
1.1055 raeburn 12787: }
12788: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12789: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12790: for (my $i=0; $i<$depth; $i++) {
12791: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12792: }
12793: if ($is_dir) {
12794: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12795: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12796: } else {
12797: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12798: }
12799: $output .= ' '.$name.'</td>'."\n".
12800: &end_data_table_row();
12801: return $output;
12802: }
12803:
12804: sub archive_options_form {
1.1065 raeburn 12805: my ($form,$display,$count,$hiddenelem) = @_;
12806: my %lt = &Apache::lonlocal::texthash(
12807: perm => 'Permanently remove archive file?',
12808: hows => 'How should each extracted item be incorporated in the course?',
12809: cont => 'Content actions for all',
12810: addf => 'Add as folder/file',
12811: incd => 'Include as dependency for a displayed file',
12812: disc => 'Discard',
12813: no => 'No',
12814: yes => 'Yes',
12815: save => 'Save',
12816: );
12817: my $output = <<"END";
12818: <form name="$form" method="post" action="">
12819: <p><span class="LC_nobreak">$lt{'perm'}
12820: <label>
12821: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12822: </label>
12823:
12824: <label>
12825: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12826: </span>
12827: </p>
12828: <input type="hidden" name="phase" value="decompress_cleanup" />
12829: <br />$lt{'hows'}
12830: <div class="LC_columnSection">
12831: <fieldset>
12832: <legend>$lt{'cont'}</legend>
12833: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12834: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12835: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12836: </fieldset>
12837: </div>
12838: END
12839: return $output.
1.1055 raeburn 12840: &start_data_table()."\n".
1.1065 raeburn 12841: $display."\n".
1.1055 raeburn 12842: &end_data_table()."\n".
12843: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12844: $hiddenelem.
1.1065 raeburn 12845: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12846: '</form>';
12847: }
12848:
12849: sub archive_javascript {
1.1056 raeburn 12850: my ($startcount,$numitems,$titles,$children) = @_;
12851: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12852: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12853: my $scripttag = <<START;
12854: <script type="text/javascript">
12855: // <![CDATA[
12856:
12857: function checkAll(form,prefix) {
12858: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12859: for (var i=0; i < form.elements.length; i++) {
12860: var id = form.elements[i].id;
12861: if ((id != '') && (id != undefined)) {
12862: if (idstr.test(id)) {
12863: if (form.elements[i].type == 'radio') {
12864: form.elements[i].checked = true;
1.1056 raeburn 12865: var nostart = i-$startcount;
1.1059 raeburn 12866: var offset = nostart%7;
12867: var count = (nostart-offset)/7;
1.1056 raeburn 12868: dependencyCheck(form,count,offset);
1.1055 raeburn 12869: }
12870: }
12871: }
12872: }
12873: }
12874:
12875: function propagateCheck(form,count) {
12876: if (count > 0) {
1.1059 raeburn 12877: var startelement = $startcount + ((count-1) * 7);
12878: for (var j=1; j<6; j++) {
12879: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12880: var item = startelement + j;
12881: if (form.elements[item].type == 'radio') {
12882: if (form.elements[item].checked) {
12883: containerCheck(form,count,j);
12884: break;
12885: }
1.1055 raeburn 12886: }
12887: }
12888: }
12889: }
12890: }
12891:
12892: numitems = $numitems
1.1056 raeburn 12893: var titles = new Array(numitems);
12894: var parents = new Array(numitems);
1.1055 raeburn 12895: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12896: parents[i] = new Array;
1.1055 raeburn 12897: }
1.1059 raeburn 12898: var maintitle = '$maintitle';
1.1055 raeburn 12899:
12900: START
12901:
1.1056 raeburn 12902: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12903: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12904: for (my $i=0; $i<@contents; $i ++) {
12905: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12906: }
12907: }
12908:
1.1056 raeburn 12909: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12910: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12911: }
12912:
1.1055 raeburn 12913: $scripttag .= <<END;
12914:
12915: function containerCheck(form,count,offset) {
12916: if (count > 0) {
1.1056 raeburn 12917: dependencyCheck(form,count,offset);
1.1059 raeburn 12918: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12919: form.elements[item].checked = true;
12920: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12921: if (parents[count].length > 0) {
12922: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12923: containerCheck(form,parents[count][j],offset);
12924: }
12925: }
12926: }
12927: }
12928: }
12929:
12930: function dependencyCheck(form,count,offset) {
12931: if (count > 0) {
1.1059 raeburn 12932: var chosen = (offset+$startcount)+7*(count-1);
12933: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12934: var currtype = form.elements[depitem].type;
12935: if (form.elements[chosen].value == 'dependency') {
12936: document.getElementById('arc_depon_'+count).style.display='block';
12937: form.elements[depitem].options.length = 0;
12938: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 12939: for (var i=1; i<=numitems; i++) {
12940: if (i == count) {
12941: continue;
12942: }
1.1059 raeburn 12943: var startelement = $startcount + (i-1) * 7;
12944: for (var j=1; j<6; j++) {
12945: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12946: var item = startelement + j;
12947: if (form.elements[item].type == 'radio') {
12948: if (form.elements[item].checked) {
12949: if (form.elements[item].value == 'display') {
12950: var n = form.elements[depitem].options.length;
12951: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12952: }
12953: }
12954: }
12955: }
12956: }
12957: }
12958: } else {
12959: document.getElementById('arc_depon_'+count).style.display='none';
12960: form.elements[depitem].options.length = 0;
12961: form.elements[depitem].options[0] = new Option('Select','',true,true);
12962: }
1.1059 raeburn 12963: titleCheck(form,count,offset);
1.1056 raeburn 12964: }
12965: }
12966:
12967: function propagateSelect(form,count,offset) {
12968: if (count > 0) {
1.1065 raeburn 12969: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12970: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12971: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12972: if (parents[count].length > 0) {
12973: for (var j=0; j<parents[count].length; j++) {
12974: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12975: }
12976: }
12977: }
12978: }
12979: }
1.1056 raeburn 12980:
12981: function containerSelect(form,count,offset,picked) {
12982: if (count > 0) {
1.1065 raeburn 12983: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12984: if (form.elements[item].type == 'radio') {
12985: if (form.elements[item].value == 'dependency') {
12986: if (form.elements[item+1].type == 'select-one') {
12987: for (var i=0; i<form.elements[item+1].options.length; i++) {
12988: if (form.elements[item+1].options[i].value == picked) {
12989: form.elements[item+1].selectedIndex = i;
12990: break;
12991: }
12992: }
12993: }
12994: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12995: if (parents[count].length > 0) {
12996: for (var j=0; j<parents[count].length; j++) {
12997: containerSelect(form,parents[count][j],offset,picked);
12998: }
12999: }
13000: }
13001: }
13002: }
13003: }
13004: }
13005:
1.1059 raeburn 13006: function titleCheck(form,count,offset) {
13007: if (count > 0) {
13008: var chosen = (offset+$startcount)+7*(count-1);
13009: var depitem = $startcount + ((count-1) * 7) + 2;
13010: var currtype = form.elements[depitem].type;
13011: if (form.elements[chosen].value == 'display') {
13012: document.getElementById('arc_title_'+count).style.display='block';
13013: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13014: document.getElementById('archive_title_'+count).value=maintitle;
13015: }
13016: } else {
13017: document.getElementById('arc_title_'+count).style.display='none';
13018: if (currtype == 'text') {
13019: document.getElementById('archive_title_'+count).value='';
13020: }
13021: }
13022: }
13023: return;
13024: }
13025:
1.1055 raeburn 13026: // ]]>
13027: </script>
13028: END
13029: return $scripttag;
13030: }
13031:
13032: sub process_extracted_files {
1.1067 raeburn 13033: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13034: my $numitems = $env{'form.archive_count'};
13035: return unless ($numitems);
13036: my @ids=&Apache::lonnet::current_machine_ids();
13037: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13038: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13039: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13040: if (grep(/^\Q$docuhome\E$/,@ids)) {
13041: $prefix = &LONCAPA::propath($docudom,$docuname);
13042: $pathtocheck = "$dir_root/$destination";
13043: $dir = $dir_root;
13044: $ishome = 1;
13045: } else {
13046: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13047: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
13048: $dir = "$dir_root/$docudom/$docuname";
13049: }
13050: my $currdir = "$dir_root/$destination";
13051: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13052: if ($env{'form.folderpath'}) {
13053: my @items = split('&',$env{'form.folderpath'});
13054: $folders{'0'} = $items[-2];
1.1099 raeburn 13055: if ($env{'form.folderpath'} =~ /\:1$/) {
13056: $containers{'0'}='page';
13057: } else {
13058: $containers{'0'}='sequence';
13059: }
1.1055 raeburn 13060: }
13061: my @archdirs = &get_env_multiple('form.archive_directory');
13062: if ($numitems) {
13063: for (my $i=1; $i<=$numitems; $i++) {
13064: my $path = $env{'form.archive_content_'.$i};
13065: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13066: my $item = $1;
13067: $toplevelitems{$item} = $i;
13068: if (grep(/^\Q$i\E$/,@archdirs)) {
13069: $is_dir{$item} = 1;
13070: }
13071: }
13072: }
13073: }
1.1067 raeburn 13074: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13075: if (keys(%toplevelitems) > 0) {
13076: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13077: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13078: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13079: }
1.1066 raeburn 13080: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13081: if ($numitems) {
13082: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13083: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13084: my $path = $env{'form.archive_content_'.$i};
13085: if ($path =~ /^\Q$pathtocheck\E/) {
13086: if ($env{'form.archive_'.$i} eq 'discard') {
13087: if ($prefix ne '' && $path ne '') {
13088: if (-e $prefix.$path) {
1.1066 raeburn 13089: if ((@archdirs > 0) &&
13090: (grep(/^\Q$i\E$/,@archdirs))) {
13091: $todeletedir{$prefix.$path} = 1;
13092: } else {
13093: $todelete{$prefix.$path} = 1;
13094: }
1.1055 raeburn 13095: }
13096: }
13097: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13098: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13099: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13100: $docstitle = $env{'form.archive_title_'.$i};
13101: if ($docstitle eq '') {
13102: $docstitle = $title;
13103: }
1.1055 raeburn 13104: $outer = 0;
1.1056 raeburn 13105: if (ref($dirorder{$i}) eq 'ARRAY') {
13106: if (@{$dirorder{$i}} > 0) {
13107: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13108: if ($env{'form.archive_'.$item} eq 'display') {
13109: $outer = $item;
13110: last;
13111: }
13112: }
13113: }
13114: }
13115: my ($errtext,$fatal) =
13116: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13117: '/'.$folders{$outer}.'.'.
13118: $containers{$outer});
13119: next if ($fatal);
13120: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13121: if ($context eq 'coursedocs') {
1.1056 raeburn 13122: $mapinner{$i} = time;
1.1055 raeburn 13123: $folders{$i} = 'default_'.$mapinner{$i};
13124: $containers{$i} = 'sequence';
13125: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13126: $folders{$i}.'.'.$containers{$i};
13127: my $newidx = &LONCAPA::map::getresidx();
13128: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13129: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13130: push(@LONCAPA::map::order,$newidx);
13131: my ($outtext,$errtext) =
13132: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13133: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13134: '.'.$containers{$outer},1,1);
1.1056 raeburn 13135: $newseqid{$i} = $newidx;
1.1067 raeburn 13136: unless ($errtext) {
13137: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
13138: }
1.1055 raeburn 13139: }
13140: } else {
13141: if ($context eq 'coursedocs') {
13142: my $newidx=&LONCAPA::map::getresidx();
13143: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13144: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13145: $title;
13146: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13147: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13148: }
13149: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13150: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13151: }
13152: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13153: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 13154: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 13155: unless ($ishome) {
13156: my $fetch = "$newdest{$i}/$title";
13157: $fetch =~ s/^\Q$prefix$dir\E//;
13158: $prompttofetch{$fetch} = 1;
13159: }
1.1055 raeburn 13160: }
13161: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13162: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13163: push(@LONCAPA::map::order, $newidx);
13164: my ($outtext,$errtext)=
13165: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13166: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13167: '.'.$containers{$outer},1,1);
1.1067 raeburn 13168: unless ($errtext) {
13169: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13170: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
13171: }
13172: }
1.1055 raeburn 13173: }
13174: }
1.1086 raeburn 13175: }
13176: } else {
13177: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13178: }
13179: }
13180: for (my $i=1; $i<=$numitems; $i++) {
13181: next unless ($env{'form.archive_'.$i} eq 'dependency');
13182: my $path = $env{'form.archive_content_'.$i};
13183: if ($path =~ /^\Q$pathtocheck\E/) {
13184: my ($title) = ($path =~ m{/([^/]+)$});
13185: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13186: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13187: if (ref($dirorder{$i}) eq 'ARRAY') {
13188: my ($itemidx,$fullpath,$relpath);
13189: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13190: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13191: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13192: if ($dirorder{$i}->[$j] eq $container) {
13193: $itemidx = $j;
1.1056 raeburn 13194: }
13195: }
1.1086 raeburn 13196: }
13197: if ($itemidx eq '') {
13198: $itemidx = 0;
13199: }
13200: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13201: if ($mapinner{$referrer{$i}}) {
13202: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13203: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13204: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13205: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13206: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13207: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13208: if (!-e $fullpath) {
13209: mkdir($fullpath,0755);
1.1056 raeburn 13210: }
13211: }
1.1086 raeburn 13212: } else {
13213: last;
1.1056 raeburn 13214: }
1.1086 raeburn 13215: }
13216: }
13217: } elsif ($newdest{$referrer{$i}}) {
13218: $fullpath = $newdest{$referrer{$i}};
13219: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13220: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13221: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13222: last;
13223: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13224: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13225: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13226: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13227: if (!-e $fullpath) {
13228: mkdir($fullpath,0755);
1.1056 raeburn 13229: }
13230: }
1.1086 raeburn 13231: } else {
13232: last;
1.1056 raeburn 13233: }
1.1055 raeburn 13234: }
13235: }
1.1086 raeburn 13236: if ($fullpath ne '') {
13237: if (-e "$prefix$path") {
13238: system("mv $prefix$path $fullpath/$title");
13239: }
13240: if (-e "$fullpath/$title") {
13241: my $showpath;
13242: if ($relpath ne '') {
13243: $showpath = "$relpath/$title";
13244: } else {
13245: $showpath = "/$title";
13246: }
13247: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
13248: }
13249: unless ($ishome) {
13250: my $fetch = "$fullpath/$title";
13251: $fetch =~ s/^\Q$prefix$dir\E//;
13252: $prompttofetch{$fetch} = 1;
13253: }
13254: }
1.1055 raeburn 13255: }
1.1086 raeburn 13256: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13257: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
13258: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 13259: }
13260: } else {
13261: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13262: }
13263: }
13264: if (keys(%todelete)) {
13265: foreach my $key (keys(%todelete)) {
13266: unlink($key);
1.1066 raeburn 13267: }
13268: }
13269: if (keys(%todeletedir)) {
13270: foreach my $key (keys(%todeletedir)) {
13271: rmdir($key);
13272: }
13273: }
13274: foreach my $dir (sort(keys(%is_dir))) {
13275: if (($pathtocheck ne '') && ($dir ne '')) {
13276: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13277: }
13278: }
1.1067 raeburn 13279: if ($result ne '') {
13280: $output .= '<ul>'."\n".
13281: $result."\n".
13282: '</ul>';
13283: }
13284: unless ($ishome) {
13285: my $replicationfail;
13286: foreach my $item (keys(%prompttofetch)) {
13287: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13288: unless ($fetchresult eq 'ok') {
13289: $replicationfail .= '<li>'.$item.'</li>'."\n";
13290: }
13291: }
13292: if ($replicationfail) {
13293: $output .= '<p class="LC_error">'.
13294: &mt('Course home server failed to retrieve:').'<ul>'.
13295: $replicationfail.
13296: '</ul></p>';
13297: }
13298: }
1.1055 raeburn 13299: } else {
13300: $warning = &mt('No items found in archive.');
13301: }
13302: if ($error) {
13303: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13304: $error.'</p>'."\n";
13305: }
13306: if ($warning) {
13307: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13308: }
13309: return $output;
13310: }
13311:
1.1066 raeburn 13312: sub cleanup_empty_dirs {
13313: my ($path) = @_;
13314: if (($path ne '') && (-d $path)) {
13315: if (opendir(my $dirh,$path)) {
13316: my @dircontents = grep(!/^\./,readdir($dirh));
13317: my $numitems = 0;
13318: foreach my $item (@dircontents) {
13319: if (-d "$path/$item") {
1.1111 raeburn 13320: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13321: if (-e "$path/$item") {
13322: $numitems ++;
13323: }
13324: } else {
13325: $numitems ++;
13326: }
13327: }
13328: if ($numitems == 0) {
13329: rmdir($path);
13330: }
13331: closedir($dirh);
13332: }
13333: }
13334: return;
13335: }
13336:
1.41 ng 13337: =pod
1.45 matthew 13338:
1.1162 raeburn 13339: =item * &get_folder_hierarchy()
1.1068 raeburn 13340:
13341: Provides hierarchy of names of folders/sub-folders containing the current
13342: item,
13343:
13344: Inputs: 3
13345: - $navmap - navmaps object
13346:
13347: - $map - url for map (either the trigger itself, or map containing
13348: the resource, which is the trigger).
13349:
13350: - $showitem - 1 => show title for map itself; 0 => do not show.
13351:
13352: Outputs: 1 @pathitems - array of folder/subfolder names.
13353:
13354: =cut
13355:
13356: sub get_folder_hierarchy {
13357: my ($navmap,$map,$showitem) = @_;
13358: my @pathitems;
13359: if (ref($navmap)) {
13360: my $mapres = $navmap->getResourceByUrl($map);
13361: if (ref($mapres)) {
13362: my $pcslist = $mapres->map_hierarchy();
13363: if ($pcslist ne '') {
13364: my @pcs = split(/,/,$pcslist);
13365: foreach my $pc (@pcs) {
13366: if ($pc == 1) {
1.1129 raeburn 13367: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13368: } else {
13369: my $res = $navmap->getByMapPc($pc);
13370: if (ref($res)) {
13371: my $title = $res->compTitle();
13372: $title =~ s/\W+/_/g;
13373: if ($title ne '') {
13374: push(@pathitems,$title);
13375: }
13376: }
13377: }
13378: }
13379: }
1.1071 raeburn 13380: if ($showitem) {
13381: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13382: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13383: } else {
13384: my $maptitle = $mapres->compTitle();
13385: $maptitle =~ s/\W+/_/g;
13386: if ($maptitle ne '') {
13387: push(@pathitems,$maptitle);
13388: }
1.1068 raeburn 13389: }
13390: }
13391: }
13392: }
13393: return @pathitems;
13394: }
13395:
13396: =pod
13397:
1.1015 raeburn 13398: =item * &get_turnedin_filepath()
13399:
13400: Determines path in a user's portfolio file for storage of files uploaded
13401: to a specific essayresponse or dropbox item.
13402:
13403: Inputs: 3 required + 1 optional.
13404: $symb is symb for resource, $uname and $udom are for current user (required).
13405: $caller is optional (can be "submission", if routine is called when storing
13406: an upoaded file when "Submit Answer" button was pressed).
13407:
13408: Returns array containing $path and $multiresp.
13409: $path is path in portfolio. $multiresp is 1 if this resource contains more
13410: than one file upload item. Callers of routine should append partid as a
13411: subdirectory to $path in cases where $multiresp is 1.
13412:
13413: Called by: homework/essayresponse.pm and homework/structuretags.pm
13414:
13415: =cut
13416:
13417: sub get_turnedin_filepath {
13418: my ($symb,$uname,$udom,$caller) = @_;
13419: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13420: my $turnindir;
13421: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13422: $turnindir = $userhash{'turnindir'};
13423: my ($path,$multiresp);
13424: if ($turnindir eq '') {
13425: if ($caller eq 'submission') {
13426: $turnindir = &mt('turned in');
13427: $turnindir =~ s/\W+/_/g;
13428: my %newhash = (
13429: 'turnindir' => $turnindir,
13430: );
13431: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13432: }
13433: }
13434: if ($turnindir ne '') {
13435: $path = '/'.$turnindir.'/';
13436: my ($multipart,$turnin,@pathitems);
13437: my $navmap = Apache::lonnavmaps::navmap->new();
13438: if (defined($navmap)) {
13439: my $mapres = $navmap->getResourceByUrl($map);
13440: if (ref($mapres)) {
13441: my $pcslist = $mapres->map_hierarchy();
13442: if ($pcslist ne '') {
13443: foreach my $pc (split(/,/,$pcslist)) {
13444: my $res = $navmap->getByMapPc($pc);
13445: if (ref($res)) {
13446: my $title = $res->compTitle();
13447: $title =~ s/\W+/_/g;
13448: if ($title ne '') {
1.1149 raeburn 13449: if (($pc > 1) && (length($title) > 12)) {
13450: $title = substr($title,0,12);
13451: }
1.1015 raeburn 13452: push(@pathitems,$title);
13453: }
13454: }
13455: }
13456: }
13457: my $maptitle = $mapres->compTitle();
13458: $maptitle =~ s/\W+/_/g;
13459: if ($maptitle ne '') {
1.1149 raeburn 13460: if (length($maptitle) > 12) {
13461: $maptitle = substr($maptitle,0,12);
13462: }
1.1015 raeburn 13463: push(@pathitems,$maptitle);
13464: }
13465: unless ($env{'request.state'} eq 'construct') {
13466: my $res = $navmap->getBySymb($symb);
13467: if (ref($res)) {
13468: my $partlist = $res->parts();
13469: my $totaluploads = 0;
13470: if (ref($partlist) eq 'ARRAY') {
13471: foreach my $part (@{$partlist}) {
13472: my @types = $res->responseType($part);
13473: my @ids = $res->responseIds($part);
13474: for (my $i=0; $i < scalar(@ids); $i++) {
13475: if ($types[$i] eq 'essay') {
13476: my $partid = $part.'_'.$ids[$i];
13477: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13478: $totaluploads ++;
13479: }
13480: }
13481: }
13482: }
13483: if ($totaluploads > 1) {
13484: $multiresp = 1;
13485: }
13486: }
13487: }
13488: }
13489: } else {
13490: return;
13491: }
13492: } else {
13493: return;
13494: }
13495: my $restitle=&Apache::lonnet::gettitle($symb);
13496: $restitle =~ s/\W+/_/g;
13497: if ($restitle eq '') {
13498: $restitle = ($resurl =~ m{/[^/]+$});
13499: if ($restitle eq '') {
13500: $restitle = time;
13501: }
13502: }
1.1149 raeburn 13503: if (length($restitle) > 12) {
13504: $restitle = substr($restitle,0,12);
13505: }
1.1015 raeburn 13506: push(@pathitems,$restitle);
13507: $path .= join('/',@pathitems);
13508: }
13509: return ($path,$multiresp);
13510: }
13511:
13512: =pod
13513:
1.464 albertel 13514: =back
1.41 ng 13515:
1.112 bowersj2 13516: =head1 CSV Upload/Handling functions
1.38 albertel 13517:
1.41 ng 13518: =over 4
13519:
1.648 raeburn 13520: =item * &upfile_store($r)
1.41 ng 13521:
13522: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13523: needs $env{'form.upfile'}
1.41 ng 13524: returns $datatoken to be put into hidden field
13525:
13526: =cut
1.31 albertel 13527:
13528: sub upfile_store {
13529: my $r=shift;
1.258 albertel 13530: $env{'form.upfile'}=~s/\r/\n/gs;
13531: $env{'form.upfile'}=~s/\f/\n/gs;
13532: $env{'form.upfile'}=~s/\n+/\n/gs;
13533: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13534:
1.258 albertel 13535: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
13536: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 13537: {
1.158 raeburn 13538: my $datafile = $r->dir_config('lonDaemons').
13539: '/tmp/'.$datatoken.'.tmp';
13540: if ( open(my $fh,">$datafile") ) {
1.258 albertel 13541: print $fh $env{'form.upfile'};
1.158 raeburn 13542: close($fh);
13543: }
1.31 albertel 13544: }
13545: return $datatoken;
13546: }
13547:
1.56 matthew 13548: =pod
13549:
1.648 raeburn 13550: =item * &load_tmp_file($r)
1.41 ng 13551:
13552: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 13553: needs $env{'form.datatoken'},
13554: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13555:
13556: =cut
1.31 albertel 13557:
13558: sub load_tmp_file {
13559: my $r=shift;
13560: my @studentdata=();
13561: {
1.158 raeburn 13562: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 13563: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 13564: if ( open(my $fh,"<$studentfile") ) {
13565: @studentdata=<$fh>;
13566: close($fh);
13567: }
1.31 albertel 13568: }
1.258 albertel 13569: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13570: }
13571:
1.56 matthew 13572: =pod
13573:
1.648 raeburn 13574: =item * &upfile_record_sep()
1.41 ng 13575:
13576: Separate uploaded file into records
13577: returns array of records,
1.258 albertel 13578: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13579:
13580: =cut
1.31 albertel 13581:
13582: sub upfile_record_sep {
1.258 albertel 13583: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13584: } else {
1.248 albertel 13585: my @records;
1.258 albertel 13586: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13587: if ($line=~/^\s*$/) { next; }
13588: push(@records,$line);
13589: }
13590: return @records;
1.31 albertel 13591: }
13592: }
13593:
1.56 matthew 13594: =pod
13595:
1.648 raeburn 13596: =item * &record_sep($record)
1.41 ng 13597:
1.258 albertel 13598: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13599:
13600: =cut
13601:
1.263 www 13602: sub takeleft {
13603: my $index=shift;
13604: return substr('0000'.$index,-4,4);
13605: }
13606:
1.31 albertel 13607: sub record_sep {
13608: my $record=shift;
13609: my %components=();
1.258 albertel 13610: if ($env{'form.upfiletype'} eq 'xml') {
13611: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13612: my $i=0;
1.356 albertel 13613: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13614: $field=~s/^(\"|\')//;
13615: $field=~s/(\"|\')$//;
1.263 www 13616: $components{&takeleft($i)}=$field;
1.31 albertel 13617: $i++;
13618: }
1.258 albertel 13619: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13620: my $i=0;
1.356 albertel 13621: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13622: $field=~s/^(\"|\')//;
13623: $field=~s/(\"|\')$//;
1.263 www 13624: $components{&takeleft($i)}=$field;
1.31 albertel 13625: $i++;
13626: }
13627: } else {
1.561 www 13628: my $separator=',';
1.480 banghart 13629: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13630: $separator=';';
1.480 banghart 13631: }
1.31 albertel 13632: my $i=0;
1.561 www 13633: # the character we are looking for to indicate the end of a quote or a record
13634: my $looking_for=$separator;
13635: # do not add the characters to the fields
13636: my $ignore=0;
13637: # we just encountered a separator (or the beginning of the record)
13638: my $just_found_separator=1;
13639: # store the field we are working on here
13640: my $field='';
13641: # work our way through all characters in record
13642: foreach my $character ($record=~/(.)/g) {
13643: if ($character eq $looking_for) {
13644: if ($character ne $separator) {
13645: # Found the end of a quote, again looking for separator
13646: $looking_for=$separator;
13647: $ignore=1;
13648: } else {
13649: # Found a separator, store away what we got
13650: $components{&takeleft($i)}=$field;
13651: $i++;
13652: $just_found_separator=1;
13653: $ignore=0;
13654: $field='';
13655: }
13656: next;
13657: }
13658: # single or double quotation marks after a separator indicate beginning of a quote
13659: # we are now looking for the end of the quote and need to ignore separators
13660: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13661: $looking_for=$character;
13662: next;
13663: }
13664: # ignore would be true after we reached the end of a quote
13665: if ($ignore) { next; }
13666: if (($just_found_separator) && ($character=~/\s/)) { next; }
13667: $field.=$character;
13668: $just_found_separator=0;
1.31 albertel 13669: }
1.561 www 13670: # catch the very last entry, since we never encountered the separator
13671: $components{&takeleft($i)}=$field;
1.31 albertel 13672: }
13673: return %components;
13674: }
13675:
1.144 matthew 13676: ######################################################
13677: ######################################################
13678:
1.56 matthew 13679: =pod
13680:
1.648 raeburn 13681: =item * &upfile_select_html()
1.41 ng 13682:
1.144 matthew 13683: Return HTML code to select a file from the users machine and specify
13684: the file type.
1.41 ng 13685:
13686: =cut
13687:
1.144 matthew 13688: ######################################################
13689: ######################################################
1.31 albertel 13690: sub upfile_select_html {
1.144 matthew 13691: my %Types = (
13692: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13693: semisv => &mt('Semicolon separated values'),
1.144 matthew 13694: space => &mt('Space separated'),
13695: tab => &mt('Tabulator separated'),
13696: # xml => &mt('HTML/XML'),
13697: );
13698: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13699: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13700: foreach my $type (sort(keys(%Types))) {
13701: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13702: }
13703: $Str .= "</select>\n";
13704: return $Str;
1.31 albertel 13705: }
13706:
1.301 albertel 13707: sub get_samples {
13708: my ($records,$toget) = @_;
13709: my @samples=({});
13710: my $got=0;
13711: foreach my $rec (@$records) {
13712: my %temp = &record_sep($rec);
13713: if (! grep(/\S/, values(%temp))) { next; }
13714: if (%temp) {
13715: $samples[$got]=\%temp;
13716: $got++;
13717: if ($got == $toget) { last; }
13718: }
13719: }
13720: return \@samples;
13721: }
13722:
1.144 matthew 13723: ######################################################
13724: ######################################################
13725:
1.56 matthew 13726: =pod
13727:
1.648 raeburn 13728: =item * &csv_print_samples($r,$records)
1.41 ng 13729:
13730: Prints a table of sample values from each column uploaded $r is an
13731: Apache Request ref, $records is an arrayref from
13732: &Apache::loncommon::upfile_record_sep
13733:
13734: =cut
13735:
1.144 matthew 13736: ######################################################
13737: ######################################################
1.31 albertel 13738: sub csv_print_samples {
13739: my ($r,$records) = @_;
1.662 bisitz 13740: my $samples = &get_samples($records,5);
1.301 albertel 13741:
1.594 raeburn 13742: $r->print(&mt('Samples').'<br />'.&start_data_table().
13743: &start_data_table_header_row());
1.356 albertel 13744: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13745: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13746: $r->print(&end_data_table_header_row());
1.301 albertel 13747: foreach my $hash (@$samples) {
1.594 raeburn 13748: $r->print(&start_data_table_row());
1.356 albertel 13749: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13750: $r->print('<td>');
1.356 albertel 13751: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13752: $r->print('</td>');
13753: }
1.594 raeburn 13754: $r->print(&end_data_table_row());
1.31 albertel 13755: }
1.594 raeburn 13756: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13757: }
13758:
1.144 matthew 13759: ######################################################
13760: ######################################################
13761:
1.56 matthew 13762: =pod
13763:
1.648 raeburn 13764: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13765:
13766: Prints a table to create associations between values and table columns.
1.144 matthew 13767:
1.41 ng 13768: $r is an Apache Request ref,
13769: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13770: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13771:
13772: =cut
13773:
1.144 matthew 13774: ######################################################
13775: ######################################################
1.31 albertel 13776: sub csv_print_select_table {
13777: my ($r,$records,$d) = @_;
1.301 albertel 13778: my $i=0;
13779: my $samples = &get_samples($records,1);
1.144 matthew 13780: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13781: &start_data_table().&start_data_table_header_row().
1.144 matthew 13782: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13783: '<th>'.&mt('Column').'</th>'.
13784: &end_data_table_header_row()."\n");
1.356 albertel 13785: foreach my $array_ref (@$d) {
13786: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13787: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13788:
1.875 bisitz 13789: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13790: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13791: $r->print('<option value="none"></option>');
1.356 albertel 13792: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13793: $r->print('<option value="'.$sample.'"'.
13794: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13795: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13796: }
1.594 raeburn 13797: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13798: $i++;
13799: }
1.594 raeburn 13800: $r->print(&end_data_table());
1.31 albertel 13801: $i--;
13802: return $i;
13803: }
1.56 matthew 13804:
1.144 matthew 13805: ######################################################
13806: ######################################################
13807:
1.56 matthew 13808: =pod
1.31 albertel 13809:
1.648 raeburn 13810: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13811:
13812: Prints a table of sample values from the upload and can make associate samples to internal names.
13813:
13814: $r is an Apache Request ref,
13815: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13816: $d is an array of 2 element arrays (internal name, displayed name)
13817:
13818: =cut
13819:
1.144 matthew 13820: ######################################################
13821: ######################################################
1.31 albertel 13822: sub csv_samples_select_table {
13823: my ($r,$records,$d) = @_;
13824: my $i=0;
1.144 matthew 13825: #
1.662 bisitz 13826: my $max_samples = 5;
13827: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13828: $r->print(&start_data_table().
13829: &start_data_table_header_row().'<th>'.
13830: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13831: &end_data_table_header_row());
1.301 albertel 13832:
13833: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13834: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13835: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13836: foreach my $option (@$d) {
13837: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13838: $r->print('<option value="'.$value.'"'.
1.253 albertel 13839: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13840: $display.'</option>');
1.31 albertel 13841: }
13842: $r->print('</select></td><td>');
1.662 bisitz 13843: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13844: if (defined($samples->[$line]{$key})) {
13845: $r->print($samples->[$line]{$key}."<br />\n");
13846: }
13847: }
1.594 raeburn 13848: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13849: $i++;
13850: }
1.594 raeburn 13851: $r->print(&end_data_table());
1.31 albertel 13852: $i--;
13853: return($i);
1.115 matthew 13854: }
13855:
1.144 matthew 13856: ######################################################
13857: ######################################################
13858:
1.115 matthew 13859: =pod
13860:
1.648 raeburn 13861: =item * &clean_excel_name($name)
1.115 matthew 13862:
13863: Returns a replacement for $name which does not contain any illegal characters.
13864:
13865: =cut
13866:
1.144 matthew 13867: ######################################################
13868: ######################################################
1.115 matthew 13869: sub clean_excel_name {
13870: my ($name) = @_;
13871: $name =~ s/[:\*\?\/\\]//g;
13872: if (length($name) > 31) {
13873: $name = substr($name,0,31);
13874: }
13875: return $name;
1.25 albertel 13876: }
1.84 albertel 13877:
1.85 albertel 13878: =pod
13879:
1.648 raeburn 13880: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13881:
13882: Returns either 1 or undef
13883:
13884: 1 if the part is to be hidden, undef if it is to be shown
13885:
13886: Arguments are:
13887:
13888: $id the id of the part to be checked
13889: $symb, optional the symb of the resource to check
13890: $udom, optional the domain of the user to check for
13891: $uname, optional the username of the user to check for
13892:
13893: =cut
1.84 albertel 13894:
13895: sub check_if_partid_hidden {
13896: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13897: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13898: $symb,$udom,$uname);
1.141 albertel 13899: my $truth=1;
13900: #if the string starts with !, then the list is the list to show not hide
13901: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13902: my @hiddenlist=split(/,/,$hiddenparts);
13903: foreach my $checkid (@hiddenlist) {
1.141 albertel 13904: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13905: }
1.141 albertel 13906: return !$truth;
1.84 albertel 13907: }
1.127 matthew 13908:
1.138 matthew 13909:
13910: ############################################################
13911: ############################################################
13912:
13913: =pod
13914:
1.157 matthew 13915: =back
13916:
1.138 matthew 13917: =head1 cgi-bin script and graphing routines
13918:
1.157 matthew 13919: =over 4
13920:
1.648 raeburn 13921: =item * &get_cgi_id()
1.138 matthew 13922:
13923: Inputs: none
13924:
13925: Returns an id which can be used to pass environment variables
13926: to various cgi-bin scripts. These environment variables will
13927: be removed from the users environment after a given time by
13928: the routine &Apache::lonnet::transfer_profile_to_env.
13929:
13930: =cut
13931:
13932: ############################################################
13933: ############################################################
1.152 albertel 13934: my $uniq=0;
1.136 matthew 13935: sub get_cgi_id {
1.154 albertel 13936: $uniq=($uniq+1)%100000;
1.280 albertel 13937: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13938: }
13939:
1.127 matthew 13940: ############################################################
13941: ############################################################
13942:
13943: =pod
13944:
1.648 raeburn 13945: =item * &DrawBarGraph()
1.127 matthew 13946:
1.138 matthew 13947: Facilitates the plotting of data in a (stacked) bar graph.
13948: Puts plot definition data into the users environment in order for
13949: graph.png to plot it. Returns an <img> tag for the plot.
13950: The bars on the plot are labeled '1','2',...,'n'.
13951:
13952: Inputs:
13953:
13954: =over 4
13955:
13956: =item $Title: string, the title of the plot
13957:
13958: =item $xlabel: string, text describing the X-axis of the plot
13959:
13960: =item $ylabel: string, text describing the Y-axis of the plot
13961:
13962: =item $Max: scalar, the maximum Y value to use in the plot
13963: If $Max is < any data point, the graph will not be rendered.
13964:
1.140 matthew 13965: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13966: they are plotted. If undefined, default values will be used.
13967:
1.178 matthew 13968: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13969:
1.138 matthew 13970: =item @Values: An array of array references. Each array reference holds data
13971: to be plotted in a stacked bar chart.
13972:
1.239 matthew 13973: =item If the final element of @Values is a hash reference the key/value
13974: pairs will be added to the graph definition.
13975:
1.138 matthew 13976: =back
13977:
13978: Returns:
13979:
13980: An <img> tag which references graph.png and the appropriate identifying
13981: information for the plot.
13982:
1.127 matthew 13983: =cut
13984:
13985: ############################################################
13986: ############################################################
1.134 matthew 13987: sub DrawBarGraph {
1.178 matthew 13988: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13989: #
13990: if (! defined($colors)) {
13991: $colors = ['#33ff00',
13992: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13993: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13994: ];
13995: }
1.228 matthew 13996: my $extra_settings = {};
13997: if (ref($Values[-1]) eq 'HASH') {
13998: $extra_settings = pop(@Values);
13999: }
1.127 matthew 14000: #
1.136 matthew 14001: my $identifier = &get_cgi_id();
14002: my $id = 'cgi.'.$identifier;
1.129 matthew 14003: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14004: return '';
14005: }
1.225 matthew 14006: #
14007: my @Labels;
14008: if (defined($labels)) {
14009: @Labels = @$labels;
14010: } else {
14011: for (my $i=0;$i<@{$Values[0]};$i++) {
14012: push (@Labels,$i+1);
14013: }
14014: }
14015: #
1.129 matthew 14016: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14017: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14018: my %ValuesHash;
14019: my $NumSets=1;
14020: foreach my $array (@Values) {
14021: next if (! ref($array));
1.136 matthew 14022: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14023: join(',',@$array);
1.129 matthew 14024: }
1.127 matthew 14025: #
1.136 matthew 14026: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14027: if ($NumBars < 3) {
14028: $width = 120+$NumBars*32;
1.220 matthew 14029: $xskip = 1;
1.225 matthew 14030: $bar_width = 30;
14031: } elsif ($NumBars < 5) {
14032: $width = 120+$NumBars*20;
14033: $xskip = 1;
14034: $bar_width = 20;
1.220 matthew 14035: } elsif ($NumBars < 10) {
1.136 matthew 14036: $width = 120+$NumBars*15;
14037: $xskip = 1;
14038: $bar_width = 15;
14039: } elsif ($NumBars <= 25) {
14040: $width = 120+$NumBars*11;
14041: $xskip = 5;
14042: $bar_width = 8;
14043: } elsif ($NumBars <= 50) {
14044: $width = 120+$NumBars*8;
14045: $xskip = 5;
14046: $bar_width = 4;
14047: } else {
14048: $width = 120+$NumBars*8;
14049: $xskip = 5;
14050: $bar_width = 4;
14051: }
14052: #
1.137 matthew 14053: $Max = 1 if ($Max < 1);
14054: if ( int($Max) < $Max ) {
14055: $Max++;
14056: $Max = int($Max);
14057: }
1.127 matthew 14058: $Title = '' if (! defined($Title));
14059: $xlabel = '' if (! defined($xlabel));
14060: $ylabel = '' if (! defined($ylabel));
1.369 www 14061: $ValuesHash{$id.'.title'} = &escape($Title);
14062: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14063: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14064: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14065: $ValuesHash{$id.'.NumBars'} = $NumBars;
14066: $ValuesHash{$id.'.NumSets'} = $NumSets;
14067: $ValuesHash{$id.'.PlotType'} = 'bar';
14068: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14069: $ValuesHash{$id.'.height'} = $height;
14070: $ValuesHash{$id.'.width'} = $width;
14071: $ValuesHash{$id.'.xskip'} = $xskip;
14072: $ValuesHash{$id.'.bar_width'} = $bar_width;
14073: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14074: #
1.228 matthew 14075: # Deal with other parameters
14076: while (my ($key,$value) = each(%$extra_settings)) {
14077: $ValuesHash{$id.'.'.$key} = $value;
14078: }
14079: #
1.646 raeburn 14080: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14081: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14082: }
14083:
14084: ############################################################
14085: ############################################################
14086:
14087: =pod
14088:
1.648 raeburn 14089: =item * &DrawXYGraph()
1.137 matthew 14090:
1.138 matthew 14091: Facilitates the plotting of data in an XY graph.
14092: Puts plot definition data into the users environment in order for
14093: graph.png to plot it. Returns an <img> tag for the plot.
14094:
14095: Inputs:
14096:
14097: =over 4
14098:
14099: =item $Title: string, the title of the plot
14100:
14101: =item $xlabel: string, text describing the X-axis of the plot
14102:
14103: =item $ylabel: string, text describing the Y-axis of the plot
14104:
14105: =item $Max: scalar, the maximum Y value to use in the plot
14106: If $Max is < any data point, the graph will not be rendered.
14107:
14108: =item $colors: Array ref containing the hex color codes for the data to be
14109: plotted in. If undefined, default values will be used.
14110:
14111: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14112:
14113: =item $Ydata: Array ref containing Array refs.
1.185 www 14114: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14115:
14116: =item %Values: hash indicating or overriding any default values which are
14117: passed to graph.png.
14118: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14119:
14120: =back
14121:
14122: Returns:
14123:
14124: An <img> tag which references graph.png and the appropriate identifying
14125: information for the plot.
14126:
1.137 matthew 14127: =cut
14128:
14129: ############################################################
14130: ############################################################
14131: sub DrawXYGraph {
14132: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14133: #
14134: # Create the identifier for the graph
14135: my $identifier = &get_cgi_id();
14136: my $id = 'cgi.'.$identifier;
14137: #
14138: $Title = '' if (! defined($Title));
14139: $xlabel = '' if (! defined($xlabel));
14140: $ylabel = '' if (! defined($ylabel));
14141: my %ValuesHash =
14142: (
1.369 www 14143: $id.'.title' => &escape($Title),
14144: $id.'.xlabel' => &escape($xlabel),
14145: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14146: $id.'.y_max_value'=> $Max,
14147: $id.'.labels' => join(',',@$Xlabels),
14148: $id.'.PlotType' => 'XY',
14149: );
14150: #
14151: if (defined($colors) && ref($colors) eq 'ARRAY') {
14152: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14153: }
14154: #
14155: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14156: return '';
14157: }
14158: my $NumSets=1;
1.138 matthew 14159: foreach my $array (@{$Ydata}){
1.137 matthew 14160: next if (! ref($array));
14161: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14162: }
1.138 matthew 14163: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14164: #
14165: # Deal with other parameters
14166: while (my ($key,$value) = each(%Values)) {
14167: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14168: }
14169: #
1.646 raeburn 14170: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14171: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14172: }
14173:
14174: ############################################################
14175: ############################################################
14176:
14177: =pod
14178:
1.648 raeburn 14179: =item * &DrawXYYGraph()
1.138 matthew 14180:
14181: Facilitates the plotting of data in an XY graph with two Y axes.
14182: Puts plot definition data into the users environment in order for
14183: graph.png to plot it. Returns an <img> tag for the plot.
14184:
14185: Inputs:
14186:
14187: =over 4
14188:
14189: =item $Title: string, the title of the plot
14190:
14191: =item $xlabel: string, text describing the X-axis of the plot
14192:
14193: =item $ylabel: string, text describing the Y-axis of the plot
14194:
14195: =item $colors: Array ref containing the hex color codes for the data to be
14196: plotted in. If undefined, default values will be used.
14197:
14198: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14199:
14200: =item $Ydata1: The first data set
14201:
14202: =item $Min1: The minimum value of the left Y-axis
14203:
14204: =item $Max1: The maximum value of the left Y-axis
14205:
14206: =item $Ydata2: The second data set
14207:
14208: =item $Min2: The minimum value of the right Y-axis
14209:
14210: =item $Max2: The maximum value of the left Y-axis
14211:
14212: =item %Values: hash indicating or overriding any default values which are
14213: passed to graph.png.
14214: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14215:
14216: =back
14217:
14218: Returns:
14219:
14220: An <img> tag which references graph.png and the appropriate identifying
14221: information for the plot.
1.136 matthew 14222:
14223: =cut
14224:
14225: ############################################################
14226: ############################################################
1.137 matthew 14227: sub DrawXYYGraph {
14228: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14229: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14230: #
14231: # Create the identifier for the graph
14232: my $identifier = &get_cgi_id();
14233: my $id = 'cgi.'.$identifier;
14234: #
14235: $Title = '' if (! defined($Title));
14236: $xlabel = '' if (! defined($xlabel));
14237: $ylabel = '' if (! defined($ylabel));
14238: my %ValuesHash =
14239: (
1.369 www 14240: $id.'.title' => &escape($Title),
14241: $id.'.xlabel' => &escape($xlabel),
14242: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14243: $id.'.labels' => join(',',@$Xlabels),
14244: $id.'.PlotType' => 'XY',
14245: $id.'.NumSets' => 2,
1.137 matthew 14246: $id.'.two_axes' => 1,
14247: $id.'.y1_max_value' => $Max1,
14248: $id.'.y1_min_value' => $Min1,
14249: $id.'.y2_max_value' => $Max2,
14250: $id.'.y2_min_value' => $Min2,
1.136 matthew 14251: );
14252: #
1.137 matthew 14253: if (defined($colors) && ref($colors) eq 'ARRAY') {
14254: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14255: }
14256: #
14257: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14258: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14259: return '';
14260: }
14261: my $NumSets=1;
1.137 matthew 14262: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14263: next if (! ref($array));
14264: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14265: }
14266: #
14267: # Deal with other parameters
14268: while (my ($key,$value) = each(%Values)) {
14269: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14270: }
14271: #
1.646 raeburn 14272: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14273: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14274: }
14275:
14276: ############################################################
14277: ############################################################
14278:
14279: =pod
14280:
1.157 matthew 14281: =back
14282:
1.139 matthew 14283: =head1 Statistics helper routines?
14284:
14285: Bad place for them but what the hell.
14286:
1.157 matthew 14287: =over 4
14288:
1.648 raeburn 14289: =item * &chartlink()
1.139 matthew 14290:
14291: Returns a link to the chart for a specific student.
14292:
14293: Inputs:
14294:
14295: =over 4
14296:
14297: =item $linktext: The text of the link
14298:
14299: =item $sname: The students username
14300:
14301: =item $sdomain: The students domain
14302:
14303: =back
14304:
1.157 matthew 14305: =back
14306:
1.139 matthew 14307: =cut
14308:
14309: ############################################################
14310: ############################################################
14311: sub chartlink {
14312: my ($linktext, $sname, $sdomain) = @_;
14313: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14314: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14315: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14316: '">'.$linktext.'</a>';
1.153 matthew 14317: }
14318:
14319: #######################################################
14320: #######################################################
14321:
14322: =pod
14323:
14324: =head1 Course Environment Routines
1.157 matthew 14325:
14326: =over 4
1.153 matthew 14327:
1.648 raeburn 14328: =item * &restore_course_settings()
1.153 matthew 14329:
1.648 raeburn 14330: =item * &store_course_settings()
1.153 matthew 14331:
14332: Restores/Store indicated form parameters from the course environment.
14333: Will not overwrite existing values of the form parameters.
14334:
14335: Inputs:
14336: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14337:
14338: a hash ref describing the data to be stored. For example:
14339:
14340: %Save_Parameters = ('Status' => 'scalar',
14341: 'chartoutputmode' => 'scalar',
14342: 'chartoutputdata' => 'scalar',
14343: 'Section' => 'array',
1.373 raeburn 14344: 'Group' => 'array',
1.153 matthew 14345: 'StudentData' => 'array',
14346: 'Maps' => 'array');
14347:
14348: Returns: both routines return nothing
14349:
1.631 raeburn 14350: =back
14351:
1.153 matthew 14352: =cut
14353:
14354: #######################################################
14355: #######################################################
14356: sub store_course_settings {
1.496 albertel 14357: return &store_settings($env{'request.course.id'},@_);
14358: }
14359:
14360: sub store_settings {
1.153 matthew 14361: # save to the environment
14362: # appenv the same items, just to be safe
1.300 albertel 14363: my $udom = $env{'user.domain'};
14364: my $uname = $env{'user.name'};
1.496 albertel 14365: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14366: my %SaveHash;
14367: my %AppHash;
14368: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14369: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14370: my $envname = 'environment.'.$basename;
1.258 albertel 14371: if (exists($env{'form.'.$setting})) {
1.153 matthew 14372: # Save this value away
14373: if ($type eq 'scalar' &&
1.258 albertel 14374: (! exists($env{$envname}) ||
14375: $env{$envname} ne $env{'form.'.$setting})) {
14376: $SaveHash{$basename} = $env{'form.'.$setting};
14377: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14378: } elsif ($type eq 'array') {
14379: my $stored_form;
1.258 albertel 14380: if (ref($env{'form.'.$setting})) {
1.153 matthew 14381: $stored_form = join(',',
14382: map {
1.369 www 14383: &escape($_);
1.258 albertel 14384: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14385: } else {
14386: $stored_form =
1.369 www 14387: &escape($env{'form.'.$setting});
1.153 matthew 14388: }
14389: # Determine if the array contents are the same.
1.258 albertel 14390: if ($stored_form ne $env{$envname}) {
1.153 matthew 14391: $SaveHash{$basename} = $stored_form;
14392: $AppHash{$envname} = $stored_form;
14393: }
14394: }
14395: }
14396: }
14397: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14398: $udom,$uname);
1.153 matthew 14399: if ($put_result !~ /^(ok|delayed)/) {
14400: &Apache::lonnet::logthis('unable to save form parameters, '.
14401: 'got error:'.$put_result);
14402: }
14403: # Make sure these settings stick around in this session, too
1.646 raeburn 14404: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14405: return;
14406: }
14407:
14408: sub restore_course_settings {
1.499 albertel 14409: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14410: }
14411:
14412: sub restore_settings {
14413: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14414: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14415: next if (exists($env{'form.'.$setting}));
1.496 albertel 14416: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14417: '.'.$setting;
1.258 albertel 14418: if (exists($env{$envname})) {
1.153 matthew 14419: if ($type eq 'scalar') {
1.258 albertel 14420: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14421: } elsif ($type eq 'array') {
1.258 albertel 14422: $env{'form.'.$setting} = [
1.153 matthew 14423: map {
1.369 www 14424: &unescape($_);
1.258 albertel 14425: } split(',',$env{$envname})
1.153 matthew 14426: ];
14427: }
14428: }
14429: }
1.127 matthew 14430: }
14431:
1.618 raeburn 14432: #######################################################
14433: #######################################################
14434:
14435: =pod
14436:
14437: =head1 Domain E-mail Routines
14438:
14439: =over 4
14440:
1.648 raeburn 14441: =item * &build_recipient_list()
1.618 raeburn 14442:
1.1144 raeburn 14443: Build recipient lists for following types of e-mail:
1.766 raeburn 14444: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14445: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14446: module change checking, student/employee ID conflict checks, as
14447: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14448: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14449:
14450: Inputs:
1.619 raeburn 14451: defmail (scalar - email address of default recipient),
1.1144 raeburn 14452: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14453: requestsmail, updatesmail, or idconflictsmail).
14454:
1.619 raeburn 14455: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14456:
1.619 raeburn 14457: origmail (scalar - email address of recipient from loncapa.conf,
14458: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14459:
1.655 raeburn 14460: Returns: comma separated list of addresses to which to send e-mail.
14461:
14462: =back
1.618 raeburn 14463:
14464: =cut
14465:
14466: ############################################################
14467: ############################################################
14468: sub build_recipient_list {
1.619 raeburn 14469: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 14470: my @recipients;
14471: my $otheremails;
14472: my %domconfig =
14473: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
14474: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14475: if (exists($domconfig{'contacts'}{$mailing})) {
14476: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14477: my @contacts = ('adminemail','supportemail');
14478: foreach my $item (@contacts) {
14479: if ($domconfig{'contacts'}{$mailing}{$item}) {
14480: my $addr = $domconfig{'contacts'}{$item};
14481: if (!grep(/^\Q$addr\E$/,@recipients)) {
14482: push(@recipients,$addr);
14483: }
1.619 raeburn 14484: }
1.766 raeburn 14485: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 14486: }
14487: }
1.766 raeburn 14488: } elsif ($origmail ne '') {
14489: push(@recipients,$origmail);
1.618 raeburn 14490: }
1.619 raeburn 14491: } elsif ($origmail ne '') {
14492: push(@recipients,$origmail);
1.618 raeburn 14493: }
1.688 raeburn 14494: if (defined($defmail)) {
14495: if ($defmail ne '') {
14496: push(@recipients,$defmail);
14497: }
1.618 raeburn 14498: }
14499: if ($otheremails) {
1.619 raeburn 14500: my @others;
14501: if ($otheremails =~ /,/) {
14502: @others = split(/,/,$otheremails);
1.618 raeburn 14503: } else {
1.619 raeburn 14504: push(@others,$otheremails);
14505: }
14506: foreach my $addr (@others) {
14507: if (!grep(/^\Q$addr\E$/,@recipients)) {
14508: push(@recipients,$addr);
14509: }
1.618 raeburn 14510: }
14511: }
1.619 raeburn 14512: my $recipientlist = join(',',@recipients);
1.618 raeburn 14513: return $recipientlist;
14514: }
14515:
1.127 matthew 14516: ############################################################
14517: ############################################################
1.154 albertel 14518:
1.655 raeburn 14519: =pod
14520:
1.1224 musolffc 14521: =over 4
14522:
1.1223 musolffc 14523: =item * &mime_email()
14524:
14525: Sends an email with a possible attachment
14526:
14527: Inputs:
14528:
14529: =over 4
14530:
14531: from - Sender's email address
14532:
14533: to - Email address of recipient
14534:
14535: subject - Subject of email
14536:
14537: body - Body of email
14538:
14539: cc_string - Carbon copy email address
14540:
14541: bcc - Blind carbon copy email address
14542:
14543: type - File type of attachment
14544:
14545: attachment_path - Path of file to be attached
14546:
14547: file_name - Name of file to be attached
14548:
14549: attachment_text - The body of an attachment of type "TEXT"
14550:
14551: =back
14552:
14553: =back
14554:
14555: =cut
14556:
14557: ############################################################
14558: ############################################################
14559:
14560: sub mime_email {
14561: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
14562: $file_name, $attachment_text) = @_;
14563: my $msg = MIME::Lite->new(
14564: From => $from,
14565: To => $to,
14566: Subject => $subject,
14567: Type =>'TEXT',
14568: Data => $body,
14569: );
14570: if ($cc_string ne '') {
14571: $msg->add("Cc" => $cc_string);
14572: }
14573: if ($bcc ne '') {
14574: $msg->add("Bcc" => $bcc);
14575: }
14576: $msg->attr("content-type" => "text/plain");
14577: $msg->attr("content-type.charset" => "UTF-8");
14578: # Attach file if given
14579: if ($attachment_path) {
14580: unless ($file_name) {
14581: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
14582: }
14583: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
14584: $msg->attach(Type => $type,
14585: Path => $attachment_path,
14586: Filename => $file_name
14587: );
14588: # Otherwise attach text if given
14589: } elsif ($attachment_text) {
14590: $msg->attach(Type => 'TEXT',
14591: Data => $attachment_text);
14592: }
14593: # Send it
14594: $msg->send('sendmail');
14595: }
14596:
14597: ############################################################
14598: ############################################################
14599:
14600: =pod
14601:
1.655 raeburn 14602: =head1 Course Catalog Routines
14603:
14604: =over 4
14605:
14606: =item * &gather_categories()
14607:
14608: Converts category definitions - keys of categories hash stored in
14609: coursecategories in configuration.db on the primary library server in a
14610: domain - to an array. Also generates javascript and idx hash used to
14611: generate Domain Coordinator interface for editing Course Categories.
14612:
14613: Inputs:
1.663 raeburn 14614:
1.655 raeburn 14615: categories (reference to hash of category definitions).
1.663 raeburn 14616:
1.655 raeburn 14617: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14618: categories and subcategories).
1.663 raeburn 14619:
1.655 raeburn 14620: idx (reference to hash of counters used in Domain Coordinator interface for
14621: editing Course Categories).
1.663 raeburn 14622:
1.655 raeburn 14623: jsarray (reference to array of categories used to create Javascript arrays for
14624: Domain Coordinator interface for editing Course Categories).
14625:
14626: Returns: nothing
14627:
14628: Side effects: populates cats, idx and jsarray.
14629:
14630: =cut
14631:
14632: sub gather_categories {
14633: my ($categories,$cats,$idx,$jsarray) = @_;
14634: my %counters;
14635: my $num = 0;
14636: foreach my $item (keys(%{$categories})) {
14637: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14638: if ($container eq '' && $depth == 0) {
14639: $cats->[$depth][$categories->{$item}] = $cat;
14640: } else {
14641: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14642: }
14643: my ($escitem,$tail) = split(/:/,$item,2);
14644: if ($counters{$tail} eq '') {
14645: $counters{$tail} = $num;
14646: $num ++;
14647: }
14648: if (ref($idx) eq 'HASH') {
14649: $idx->{$item} = $counters{$tail};
14650: }
14651: if (ref($jsarray) eq 'ARRAY') {
14652: push(@{$jsarray->[$counters{$tail}]},$item);
14653: }
14654: }
14655: return;
14656: }
14657:
14658: =pod
14659:
14660: =item * &extract_categories()
14661:
14662: Used to generate breadcrumb trails for course categories.
14663:
14664: Inputs:
1.663 raeburn 14665:
1.655 raeburn 14666: categories (reference to hash of category definitions).
1.663 raeburn 14667:
1.655 raeburn 14668: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14669: categories and subcategories).
1.663 raeburn 14670:
1.655 raeburn 14671: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14672:
1.655 raeburn 14673: allitems (reference to hash - key is category key
14674: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14675:
1.655 raeburn 14676: idx (reference to hash of counters used in Domain Coordinator interface for
14677: editing Course Categories).
1.663 raeburn 14678:
1.655 raeburn 14679: jsarray (reference to array of categories used to create Javascript arrays for
14680: Domain Coordinator interface for editing Course Categories).
14681:
1.665 raeburn 14682: subcats (reference to hash of arrays containing all subcategories within each
14683: category, -recursive)
14684:
1.655 raeburn 14685: Returns: nothing
14686:
14687: Side effects: populates trails and allitems hash references.
14688:
14689: =cut
14690:
14691: sub extract_categories {
1.665 raeburn 14692: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14693: if (ref($categories) eq 'HASH') {
14694: &gather_categories($categories,$cats,$idx,$jsarray);
14695: if (ref($cats->[0]) eq 'ARRAY') {
14696: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14697: my $name = $cats->[0][$i];
14698: my $item = &escape($name).'::0';
14699: my $trailstr;
14700: if ($name eq 'instcode') {
14701: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14702: } elsif ($name eq 'communities') {
14703: $trailstr = &mt('Communities');
1.1239 raeburn 14704: } elsif ($name eq 'placement') {
14705: $trailstr = &mt('Placement Tests');
1.655 raeburn 14706: } else {
14707: $trailstr = $name;
14708: }
14709: if ($allitems->{$item} eq '') {
14710: push(@{$trails},$trailstr);
14711: $allitems->{$item} = scalar(@{$trails})-1;
14712: }
14713: my @parents = ($name);
14714: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14715: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14716: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14717: if (ref($subcats) eq 'HASH') {
14718: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14719: }
14720: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14721: }
14722: } else {
14723: if (ref($subcats) eq 'HASH') {
14724: $subcats->{$item} = [];
1.655 raeburn 14725: }
14726: }
14727: }
14728: }
14729: }
14730: return;
14731: }
14732:
14733: =pod
14734:
1.1162 raeburn 14735: =item * &recurse_categories()
1.655 raeburn 14736:
14737: Recursively used to generate breadcrumb trails for course categories.
14738:
14739: Inputs:
1.663 raeburn 14740:
1.655 raeburn 14741: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14742: categories and subcategories).
1.663 raeburn 14743:
1.655 raeburn 14744: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14745:
14746: category (current course category, for which breadcrumb trail is being generated).
14747:
14748: trails (reference to array of breadcrumb trails for each category).
14749:
1.655 raeburn 14750: allitems (reference to hash - key is category key
14751: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14752:
1.655 raeburn 14753: parents (array containing containers directories for current category,
14754: back to top level).
14755:
14756: Returns: nothing
14757:
14758: Side effects: populates trails and allitems hash references
14759:
14760: =cut
14761:
14762: sub recurse_categories {
1.665 raeburn 14763: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14764: my $shallower = $depth - 1;
14765: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14766: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14767: my $name = $cats->[$depth]{$category}[$k];
14768: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14769: my $trailstr = join(' -> ',(@{$parents},$category));
14770: if ($allitems->{$item} eq '') {
14771: push(@{$trails},$trailstr);
14772: $allitems->{$item} = scalar(@{$trails})-1;
14773: }
14774: my $deeper = $depth+1;
14775: push(@{$parents},$category);
1.665 raeburn 14776: if (ref($subcats) eq 'HASH') {
14777: my $subcat = &escape($name).':'.$category.':'.$depth;
14778: for (my $j=@{$parents}; $j>=0; $j--) {
14779: my $higher;
14780: if ($j > 0) {
14781: $higher = &escape($parents->[$j]).':'.
14782: &escape($parents->[$j-1]).':'.$j;
14783: } else {
14784: $higher = &escape($parents->[$j]).'::'.$j;
14785: }
14786: push(@{$subcats->{$higher}},$subcat);
14787: }
14788: }
14789: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14790: $subcats);
1.655 raeburn 14791: pop(@{$parents});
14792: }
14793: } else {
14794: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14795: my $trailstr = join(' -> ',(@{$parents},$category));
14796: if ($allitems->{$item} eq '') {
14797: push(@{$trails},$trailstr);
14798: $allitems->{$item} = scalar(@{$trails})-1;
14799: }
14800: }
14801: return;
14802: }
14803:
1.663 raeburn 14804: =pod
14805:
1.1162 raeburn 14806: =item * &assign_categories_table()
1.663 raeburn 14807:
14808: Create a datatable for display of hierarchical categories in a domain,
14809: with checkboxes to allow a course to be categorized.
14810:
14811: Inputs:
14812:
14813: cathash - reference to hash of categories defined for the domain (from
14814: configuration.db)
14815:
14816: currcat - scalar with an & separated list of categories assigned to a course.
14817:
1.919 raeburn 14818: type - scalar contains course type (Course or Community).
14819:
1.663 raeburn 14820: Returns: $output (markup to be displayed)
14821:
14822: =cut
14823:
14824: sub assign_categories_table {
1.919 raeburn 14825: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 14826: my $output;
14827: if (ref($cathash) eq 'HASH') {
14828: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
14829: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
14830: $maxdepth = scalar(@cats);
14831: if (@cats > 0) {
14832: my $itemcount = 0;
14833: if (ref($cats[0]) eq 'ARRAY') {
14834: my @currcategories;
14835: if ($currcat ne '') {
14836: @currcategories = split('&',$currcat);
14837: }
1.919 raeburn 14838: my $table;
1.663 raeburn 14839: for (my $i=0; $i<@{$cats[0]}; $i++) {
14840: my $parent = $cats[0][$i];
1.919 raeburn 14841: next if ($parent eq 'instcode');
14842: if ($type eq 'Community') {
14843: next unless ($parent eq 'communities');
1.1239 raeburn 14844: } elsif ($type eq 'Placement') {
14845: next unless ($parent eq 'placement');
1.919 raeburn 14846: } else {
1.1239 raeburn 14847: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 14848: }
1.663 raeburn 14849: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14850: my $item = &escape($parent).'::0';
14851: my $checked = '';
14852: if (@currcategories > 0) {
14853: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14854: $checked = ' checked="checked"';
1.663 raeburn 14855: }
14856: }
1.919 raeburn 14857: my $parent_title = $parent;
14858: if ($parent eq 'communities') {
14859: $parent_title = &mt('Communities');
1.1239 raeburn 14860: } elsif ($parent eq 'placement') {
14861: $parent_title = &mt('Placement Tests');
1.919 raeburn 14862: }
14863: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14864: '<input type="checkbox" name="usecategory" value="'.
14865: $item.'"'.$checked.' />'.$parent_title.'</span>'.
14866: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14867: my $depth = 1;
14868: push(@path,$parent);
1.919 raeburn 14869: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 14870: pop(@path);
1.919 raeburn 14871: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14872: $itemcount ++;
14873: }
1.919 raeburn 14874: if ($itemcount) {
14875: $output = &Apache::loncommon::start_data_table().
14876: $table.
14877: &Apache::loncommon::end_data_table();
14878: }
1.663 raeburn 14879: }
14880: }
14881: }
14882: return $output;
14883: }
14884:
14885: =pod
14886:
1.1162 raeburn 14887: =item * &assign_category_rows()
1.663 raeburn 14888:
14889: Create a datatable row for display of nested categories in a domain,
14890: with checkboxes to allow a course to be categorized,called recursively.
14891:
14892: Inputs:
14893:
14894: itemcount - track row number for alternating colors
14895:
14896: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14897: categories and subcategories.
14898:
14899: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14900:
14901: parent - parent of current category item
14902:
14903: path - Array containing all categories back up through the hierarchy from the
14904: current category to the top level.
14905:
14906: currcategories - reference to array of current categories assigned to the course
14907:
14908: Returns: $output (markup to be displayed).
14909:
14910: =cut
14911:
14912: sub assign_category_rows {
14913: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
14914: my ($text,$name,$item,$chgstr);
14915: if (ref($cats) eq 'ARRAY') {
14916: my $maxdepth = scalar(@{$cats});
14917: if (ref($cats->[$depth]) eq 'HASH') {
14918: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14919: my $numchildren = @{$cats->[$depth]{$parent}};
14920: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 14921: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14922: for (my $j=0; $j<$numchildren; $j++) {
14923: $name = $cats->[$depth]{$parent}[$j];
14924: $item = &escape($name).':'.&escape($parent).':'.$depth;
14925: my $deeper = $depth+1;
14926: my $checked = '';
14927: if (ref($currcategories) eq 'ARRAY') {
14928: if (@{$currcategories} > 0) {
14929: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14930: $checked = ' checked="checked"';
1.663 raeburn 14931: }
14932: }
14933: }
1.664 raeburn 14934: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14935: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 14936: $item.'"'.$checked.' />'.$name.'</label></span>'.
14937: '<input type="hidden" name="catname" value="'.$name.'" />'.
14938: '</td><td>';
1.663 raeburn 14939: if (ref($path) eq 'ARRAY') {
14940: push(@{$path},$name);
14941: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
14942: pop(@{$path});
14943: }
14944: $text .= '</td></tr>';
14945: }
14946: $text .= '</table></td>';
14947: }
14948: }
14949: }
14950: return $text;
14951: }
14952:
1.1181 raeburn 14953: =pod
14954:
14955: =back
14956:
14957: =cut
14958:
1.655 raeburn 14959: ############################################################
14960: ############################################################
14961:
14962:
1.443 albertel 14963: sub commit_customrole {
1.664 raeburn 14964: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14965: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14966: ($start?', '.&mt('starting').' '.localtime($start):'').
14967: ($end?', ending '.localtime($end):'').': <b>'.
14968: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14969: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14970: '</b><br />';
14971: return $output;
14972: }
14973:
14974: sub commit_standardrole {
1.1116 raeburn 14975: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14976: my ($output,$logmsg,$linefeed);
14977: if ($context eq 'auto') {
14978: $linefeed = "\n";
14979: } else {
14980: $linefeed = "<br />\n";
14981: }
1.443 albertel 14982: if ($three eq 'st') {
1.541 raeburn 14983: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 14984: $one,$two,$sec,$context,$credits);
1.541 raeburn 14985: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14986: ($result eq 'unknown_course') || ($result eq 'refused')) {
14987: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14988: } else {
1.541 raeburn 14989: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14990: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14991: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14992: if ($context eq 'auto') {
14993: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14994: } else {
14995: $output .= '<b>'.$result.'</b>'.$linefeed.
14996: &mt('Add to classlist').': <b>ok</b>';
14997: }
14998: $output .= $linefeed;
1.443 albertel 14999: }
15000: } else {
15001: $output = &mt('Assigning').' '.$three.' in '.$url.
15002: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15003: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15004: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15005: if ($context eq 'auto') {
15006: $output .= $result.$linefeed;
15007: } else {
15008: $output .= '<b>'.$result.'</b>'.$linefeed;
15009: }
1.443 albertel 15010: }
15011: return $output;
15012: }
15013:
15014: sub commit_studentrole {
1.1116 raeburn 15015: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15016: $credits) = @_;
1.626 raeburn 15017: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15018: if ($context eq 'auto') {
15019: $linefeed = "\n";
15020: } else {
15021: $linefeed = '<br />'."\n";
15022: }
1.443 albertel 15023: if (defined($one) && defined($two)) {
15024: my $cid=$one.'_'.$two;
15025: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15026: my $secchange = 0;
15027: my $expire_role_result;
15028: my $modify_section_result;
1.628 raeburn 15029: if ($oldsec ne '-1') {
15030: if ($oldsec ne $sec) {
1.443 albertel 15031: $secchange = 1;
1.628 raeburn 15032: my $now = time;
1.443 albertel 15033: my $uurl='/'.$cid;
15034: $uurl=~s/\_/\//g;
15035: if ($oldsec) {
15036: $uurl.='/'.$oldsec;
15037: }
1.626 raeburn 15038: $oldsecurl = $uurl;
1.628 raeburn 15039: $expire_role_result =
1.652 raeburn 15040: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15041: if ($env{'request.course.sec'} ne '') {
15042: if ($expire_role_result eq 'refused') {
15043: my @roles = ('st');
15044: my @statuses = ('previous');
15045: my @roledoms = ($one);
15046: my $withsec = 1;
15047: my %roleshash =
15048: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15049: \@statuses,\@roles,\@roledoms,$withsec);
15050: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15051: my ($oldstart,$oldend) =
15052: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15053: if ($oldend > 0 && $oldend <= $now) {
15054: $expire_role_result = 'ok';
15055: }
15056: }
15057: }
15058: }
1.443 albertel 15059: $result = $expire_role_result;
15060: }
15061: }
15062: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15063: $modify_section_result =
15064: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15065: undef,undef,undef,$sec,
15066: $end,$start,'','',$cid,
15067: '',$context,$credits);
1.443 albertel 15068: if ($modify_section_result =~ /^ok/) {
15069: if ($secchange == 1) {
1.628 raeburn 15070: if ($sec eq '') {
15071: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15072: } else {
15073: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15074: }
1.443 albertel 15075: } elsif ($oldsec eq '-1') {
1.628 raeburn 15076: if ($sec eq '') {
15077: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15078: } else {
15079: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15080: }
1.443 albertel 15081: } else {
1.628 raeburn 15082: if ($sec eq '') {
15083: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15084: } else {
15085: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15086: }
1.443 albertel 15087: }
15088: } else {
1.1115 raeburn 15089: if ($secchange) {
1.628 raeburn 15090: $$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;
15091: } else {
15092: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15093: }
1.443 albertel 15094: }
15095: $result = $modify_section_result;
15096: } elsif ($secchange == 1) {
1.628 raeburn 15097: if ($oldsec eq '') {
1.1103 raeburn 15098: $$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 15099: } else {
15100: $$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;
15101: }
1.626 raeburn 15102: if ($expire_role_result eq 'refused') {
15103: my $newsecurl = '/'.$cid;
15104: $newsecurl =~ s/\_/\//g;
15105: if ($sec ne '') {
15106: $newsecurl.='/'.$sec;
15107: }
15108: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15109: if ($sec eq '') {
15110: $$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;
15111: } else {
15112: $$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;
15113: }
15114: }
15115: }
1.443 albertel 15116: }
15117: } else {
1.626 raeburn 15118: $$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 15119: $result = "error: incomplete course id\n";
15120: }
15121: return $result;
15122: }
15123:
1.1108 raeburn 15124: sub show_role_extent {
15125: my ($scope,$context,$role) = @_;
15126: $scope =~ s{^/}{};
15127: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15128: push(@courseroles,'co');
15129: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15130: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15131: $scope =~ s{/}{_};
15132: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15133: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15134: my ($audom,$auname) = split(/\//,$scope);
15135: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15136: &Apache::loncommon::plainname($auname,$audom).'</span>');
15137: } else {
15138: $scope =~ s{/$}{};
15139: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15140: &Apache::lonnet::domain($scope,'description').'</span>');
15141: }
15142: }
15143:
1.443 albertel 15144: ############################################################
15145: ############################################################
15146:
1.566 albertel 15147: sub check_clone {
1.578 raeburn 15148: my ($args,$linefeed) = @_;
1.566 albertel 15149: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15150: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15151: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15152: my $clonemsg;
15153: my $can_clone = 0;
1.944 raeburn 15154: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15155: if ($lctype ne 'community') {
15156: $lctype = 'course';
15157: }
1.566 albertel 15158: if ($clonehome eq 'no_host') {
1.944 raeburn 15159: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15160: $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'});
15161: } else {
15162: $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'});
15163: }
1.566 albertel 15164: } else {
15165: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15166: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15167: if ($clonedesc{'type'} ne 'Community') {
15168: $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'});
15169: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15170: }
15171: }
1.882 raeburn 15172: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
15173: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15174: $can_clone = 1;
15175: } else {
1.1221 raeburn 15176: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15177: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15178: if ($clonehash{'cloners'} eq '') {
15179: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15180: if ($domdefs{'canclone'}) {
15181: unless ($domdefs{'canclone'} eq 'none') {
15182: if ($domdefs{'canclone'} eq 'domain') {
15183: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15184: $can_clone = 1;
15185: }
15186: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15187: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15188: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15189: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15190: $can_clone = 1;
15191: }
15192: }
15193: }
15194: }
1.578 raeburn 15195: } else {
1.1221 raeburn 15196: my @cloners = split(/,/,$clonehash{'cloners'});
15197: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15198: $can_clone = 1;
1.1221 raeburn 15199: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15200: $can_clone = 1;
1.1225 raeburn 15201: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15202: $can_clone = 1;
1.1221 raeburn 15203: }
15204: unless ($can_clone) {
1.1225 raeburn 15205: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15206: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15207: my (%gotdomdefaults,%gotcodedefaults);
15208: foreach my $cloner (@cloners) {
15209: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15210: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15211: my (%codedefaults,@code_order);
15212: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15213: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15214: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15215: }
15216: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15217: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15218: }
15219: } else {
15220: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15221: \%codedefaults,
15222: \@code_order);
15223: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15224: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15225: }
15226: if (@code_order > 0) {
15227: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15228: $cloner,$clonehash{'internal.coursecode'},
15229: $args->{'crscode'})) {
15230: $can_clone = 1;
15231: last;
15232: }
15233: }
15234: }
15235: }
15236: }
1.1225 raeburn 15237: }
15238: }
15239: unless ($can_clone) {
15240: my $ccrole = 'cc';
15241: if ($args->{'crstype'} eq 'Community') {
15242: $ccrole = 'co';
15243: }
15244: my %roleshash =
15245: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15246: $args->{'ccdomain'},
15247: 'userroles',['active'],[$ccrole],
15248: [$args->{'clonedomain'}]);
15249: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15250: $can_clone = 1;
15251: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15252: $args->{'ccuname'},$args->{'ccdomain'})) {
15253: $can_clone = 1;
1.1221 raeburn 15254: }
15255: }
15256: unless ($can_clone) {
15257: if ($args->{'crstype'} eq 'Community') {
15258: $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 15259: } else {
1.1221 raeburn 15260: $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'});
15261: }
1.566 albertel 15262: }
1.578 raeburn 15263: }
1.566 albertel 15264: }
15265: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15266: }
15267:
1.444 albertel 15268: sub construct_course {
1.1166 raeburn 15269: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 15270: my $outcome;
1.541 raeburn 15271: my $linefeed = '<br />'."\n";
15272: if ($context eq 'auto') {
15273: $linefeed = "\n";
15274: }
1.566 albertel 15275:
15276: #
15277: # Are we cloning?
15278: #
15279: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15280: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15281: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15282: if ($context ne 'auto') {
1.578 raeburn 15283: if ($clonemsg ne '') {
15284: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15285: }
1.566 albertel 15286: }
15287: $outcome .= $clonemsg.$linefeed;
15288:
15289: if (!$can_clone) {
15290: return (0,$outcome);
15291: }
15292: }
15293:
1.444 albertel 15294: #
15295: # Open course
15296: #
1.1239 raeburn 15297: my $showncrstype;
15298: if ($args->{'crstype'} eq 'Placement') {
15299: $showncrstype = 'placement test';
15300: } else {
15301: $showncrstype = lc($args->{'crstype'});
15302: }
1.444 albertel 15303: my %cenv=();
15304: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15305: $args->{'cdescr'},
15306: $args->{'curl'},
15307: $args->{'course_home'},
15308: $args->{'nonstandard'},
15309: $args->{'crscode'},
15310: $args->{'ccuname'}.':'.
15311: $args->{'ccdomain'},
1.882 raeburn 15312: $args->{'crstype'},
1.885 raeburn 15313: $cnum,$context,$category);
1.444 albertel 15314:
15315: # Note: The testing routines depend on this being output; see
15316: # Utils::Course. This needs to at least be output as a comment
15317: # if anyone ever decides to not show this, and Utils::Course::new
15318: # will need to be suitably modified.
1.1239 raeburn 15319: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15320: if ($$courseid =~ /^error:/) {
15321: return (0,$outcome);
15322: }
15323:
1.444 albertel 15324: #
15325: # Check if created correctly
15326: #
1.479 albertel 15327: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15328: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15329: if ($crsuhome eq 'no_host') {
15330: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15331: return (0,$outcome);
15332: }
1.541 raeburn 15333: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15334:
1.444 albertel 15335: #
1.566 albertel 15336: # Do the cloning
15337: #
15338: if ($can_clone && $cloneid) {
1.1239 raeburn 15339: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 15340: if ($context ne 'auto') {
15341: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15342: }
15343: $outcome .= $clonemsg.$linefeed;
15344: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15345: # Copy all files
1.637 www 15346: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15347: # Restore URL
1.566 albertel 15348: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15349: # Restore title
1.566 albertel 15350: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15351: # Restore creation date, creator and creation context.
15352: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15353: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15354: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15355: # Mark as cloned
1.566 albertel 15356: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15357: # Need to clone grading mode
15358: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15359: $cenv{'grading'}=$newenv{'grading'};
15360: # Do not clone these environment entries
15361: &Apache::lonnet::del('environment',
15362: ['default_enrollment_start_date',
15363: 'default_enrollment_end_date',
15364: 'question.email',
15365: 'policy.email',
15366: 'comment.email',
15367: 'pch.users.denied',
1.725 raeburn 15368: 'plc.users.denied',
15369: 'hidefromcat',
1.1121 raeburn 15370: 'checkforpriv',
1.1166 raeburn 15371: 'categories',
15372: 'internal.uniquecode'],
1.638 www 15373: $$crsudom,$$crsunum);
1.1170 raeburn 15374: if ($args->{'textbook'}) {
15375: $cenv{'internal.textbook'} = $args->{'textbook'};
15376: }
1.444 albertel 15377: }
1.566 albertel 15378:
1.444 albertel 15379: #
15380: # Set environment (will override cloned, if existing)
15381: #
15382: my @sections = ();
15383: my @xlists = ();
15384: if ($args->{'crstype'}) {
15385: $cenv{'type'}=$args->{'crstype'};
15386: }
15387: if ($args->{'crsid'}) {
15388: $cenv{'courseid'}=$args->{'crsid'};
15389: }
15390: if ($args->{'crscode'}) {
15391: $cenv{'internal.coursecode'}=$args->{'crscode'};
15392: }
15393: if ($args->{'crsquota'} ne '') {
15394: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15395: } else {
15396: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15397: }
15398: if ($args->{'ccuname'}) {
15399: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15400: ':'.$args->{'ccdomain'};
15401: } else {
15402: $cenv{'internal.courseowner'} = $args->{'curruser'};
15403: }
1.1116 raeburn 15404: if ($args->{'defaultcredits'}) {
15405: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15406: }
1.444 albertel 15407: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15408: if ($args->{'crssections'}) {
15409: $cenv{'internal.sectionnums'} = '';
15410: if ($args->{'crssections'} =~ m/,/) {
15411: @sections = split/,/,$args->{'crssections'};
15412: } else {
15413: $sections[0] = $args->{'crssections'};
15414: }
15415: if (@sections > 0) {
15416: foreach my $item (@sections) {
15417: my ($sec,$gp) = split/:/,$item;
15418: my $class = $args->{'crscode'}.$sec;
15419: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15420: $cenv{'internal.sectionnums'} .= $item.',';
15421: unless ($addcheck eq 'ok') {
15422: push @badclasses, $class;
15423: }
15424: }
15425: $cenv{'internal.sectionnums'} =~ s/,$//;
15426: }
15427: }
15428: # do not hide course coordinator from staff listing,
15429: # even if privileged
15430: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 15431: # add course coordinator's domain to domains to check for privileged users
15432: # if different to course domain
15433: if ($$crsudom ne $args->{'ccdomain'}) {
15434: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15435: }
1.444 albertel 15436: # add crosslistings
15437: if ($args->{'crsxlist'}) {
15438: $cenv{'internal.crosslistings'}='';
15439: if ($args->{'crsxlist'} =~ m/,/) {
15440: @xlists = split/,/,$args->{'crsxlist'};
15441: } else {
15442: $xlists[0] = $args->{'crsxlist'};
15443: }
15444: if (@xlists > 0) {
15445: foreach my $item (@xlists) {
15446: my ($xl,$gp) = split/:/,$item;
15447: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15448: $cenv{'internal.crosslistings'} .= $item.',';
15449: unless ($addcheck eq 'ok') {
15450: push @badclasses, $xl;
15451: }
15452: }
15453: $cenv{'internal.crosslistings'} =~ s/,$//;
15454: }
15455: }
15456: if ($args->{'autoadds'}) {
15457: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15458: }
15459: if ($args->{'autodrops'}) {
15460: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15461: }
15462: # check for notification of enrollment changes
15463: my @notified = ();
15464: if ($args->{'notify_owner'}) {
15465: if ($args->{'ccuname'} ne '') {
15466: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15467: }
15468: }
15469: if ($args->{'notify_dc'}) {
15470: if ($uname ne '') {
1.630 raeburn 15471: push(@notified,$uname.':'.$udom);
1.444 albertel 15472: }
15473: }
15474: if (@notified > 0) {
15475: my $notifylist;
15476: if (@notified > 1) {
15477: $notifylist = join(',',@notified);
15478: } else {
15479: $notifylist = $notified[0];
15480: }
15481: $cenv{'internal.notifylist'} = $notifylist;
15482: }
15483: if (@badclasses > 0) {
15484: my %lt=&Apache::lonlocal::texthash(
15485: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course. However, if automated course roster updates are enabled for this class, these particular sections/crosslistings will not contribute towards enrollment, because the user identified as the course owner for this LON-CAPA course',
15486: 'dnhr' => 'does not have rights to access enrollment in these classes',
15487: 'adby' => 'as determined by the policies of your institution on access to official classlists'
15488: );
1.541 raeburn 15489: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
15490: ' ('.$lt{'adby'}.')';
15491: if ($context eq 'auto') {
15492: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 15493: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 15494: foreach my $item (@badclasses) {
15495: if ($context eq 'auto') {
15496: $outcome .= " - $item\n";
15497: } else {
15498: $outcome .= "<li>$item</li>\n";
15499: }
15500: }
15501: if ($context eq 'auto') {
15502: $outcome .= $linefeed;
15503: } else {
1.566 albertel 15504: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 15505: }
15506: }
1.444 albertel 15507: }
15508: if ($args->{'no_end_date'}) {
15509: $args->{'endaccess'} = 0;
15510: }
15511: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15512: $cenv{'internal.autoend'}=$args->{'enrollend'};
15513: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15514: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15515: if ($args->{'showphotos'}) {
15516: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15517: }
15518: $cenv{'internal.authtype'} = $args->{'authtype'};
15519: $cenv{'internal.autharg'} = $args->{'autharg'};
15520: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15521: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15522: 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');
15523: if ($context eq 'auto') {
15524: $outcome .= $krb_msg;
15525: } else {
1.566 albertel 15526: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15527: }
15528: $outcome .= $linefeed;
1.444 albertel 15529: }
15530: }
15531: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15532: if ($args->{'setpolicy'}) {
15533: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15534: }
15535: if ($args->{'setcontent'}) {
15536: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15537: }
1.1251 raeburn 15538: if ($args->{'setcomment'}) {
15539: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15540: }
1.444 albertel 15541: }
15542: if ($args->{'reshome'}) {
15543: $cenv{'reshome'}=$args->{'reshome'}.'/';
15544: $cenv{'reshome'}=~s/\/+$/\//;
15545: }
15546: #
15547: # course has keyed access
15548: #
15549: if ($args->{'setkeys'}) {
15550: $cenv{'keyaccess'}='yes';
15551: }
15552: # if specified, key authority is not course, but user
15553: # only active if keyaccess is yes
15554: if ($args->{'keyauth'}) {
1.487 albertel 15555: my ($user,$domain) = split(':',$args->{'keyauth'});
15556: $user = &LONCAPA::clean_username($user);
15557: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15558: if ($user ne '' && $domain ne '') {
1.487 albertel 15559: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15560: }
15561: }
15562:
1.1166 raeburn 15563: #
1.1167 raeburn 15564: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 15565: #
15566: if ($args->{'uniquecode'}) {
15567: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15568: if ($code) {
15569: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 15570: my %crsinfo =
15571: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15572: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15573: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15574: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15575: }
1.1166 raeburn 15576: if (ref($coderef)) {
15577: $$coderef = $code;
15578: }
15579: }
15580: }
15581:
1.444 albertel 15582: if ($args->{'disresdis'}) {
15583: $cenv{'pch.roles.denied'}='st';
15584: }
15585: if ($args->{'disablechat'}) {
15586: $cenv{'plc.roles.denied'}='st';
15587: }
15588:
15589: # Record we've not yet viewed the Course Initialization Helper for this
15590: # course
15591: $cenv{'course.helper.not.run'} = 1;
15592: #
15593: # Use new Randomseed
15594: #
15595: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15596: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15597: #
15598: # The encryption code and receipt prefix for this course
15599: #
15600: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15601: $cenv{'internal.encpref'}=100+int(9*rand(99));
15602: #
15603: # By default, use standard grading
15604: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15605:
1.541 raeburn 15606: $outcome .= $linefeed.&mt('Setting environment').': '.
15607: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15608: #
15609: # Open all assignments
15610: #
15611: if ($args->{'openall'}) {
15612: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15613: my %storecontent = ($storeunder => time,
15614: $storeunder.'.type' => 'date_start');
15615:
15616: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15617: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15618: }
15619: #
15620: # Set first page
15621: #
15622: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15623: || ($cloneid)) {
1.445 albertel 15624: use LONCAPA::map;
1.444 albertel 15625: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15626:
15627: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15628: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15629:
1.444 albertel 15630: $outcome .= ($fatal?$errtext:'read ok').' - ';
15631: my $title; my $url;
15632: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15633: $title=&mt('Syllabus');
1.444 albertel 15634: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15635: } else {
1.963 raeburn 15636: $title=&mt('Table of Contents');
1.444 albertel 15637: $url='/adm/navmaps';
15638: }
1.445 albertel 15639:
15640: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15641: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15642:
15643: if ($errtext) { $fatal=2; }
1.541 raeburn 15644: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15645: }
1.566 albertel 15646:
1.1237 raeburn 15647: #
15648: # Set params for Placement Tests
15649: #
1.1239 raeburn 15650: if ($args->{'crstype'} eq 'Placement') {
15651: my %storecontent;
15652: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
15653: my %defaults = (
15654: buttonshide => { value => 'yes',
15655: type => 'string_yesno',},
15656: type => { value => 'randomizetry',
15657: type => 'string_questiontype',},
15658: maxtries => { value => 1,
15659: type => 'int_pos',},
15660: problemstatus => { value => 'no',
15661: type => 'string_problemstatus',},
15662: );
15663: foreach my $key (keys(%defaults)) {
15664: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
15665: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
15666: }
1.1237 raeburn 15667: &Apache::lonnet::cput
15668: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
15669: }
15670:
1.566 albertel 15671: return (1,$outcome);
1.444 albertel 15672: }
15673:
1.1166 raeburn 15674: sub make_unique_code {
15675: my ($cdom,$cnum) = @_;
15676: # get lock on uniquecodes db
15677: my $lockhash = {
15678: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15679: ':'.$env{'user.domain'},
15680: };
15681: my $tries = 0;
15682: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15683: my ($code,$error);
15684:
15685: while (($gotlock ne 'ok') && ($tries<3)) {
15686: $tries ++;
15687: sleep 1;
15688: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15689: }
15690: if ($gotlock eq 'ok') {
15691: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15692: my $gotcode;
15693: my $attempts = 0;
15694: while ((!$gotcode) && ($attempts < 100)) {
15695: $code = &generate_code();
15696: if (!exists($currcodes{$code})) {
15697: $gotcode = 1;
15698: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15699: $error = 'nostore';
15700: }
15701: }
15702: $attempts ++;
15703: }
15704: my @del_lock = ($cnum."\0".'uniquecodes');
15705: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15706: } else {
15707: $error = 'nolock';
15708: }
15709: return ($code,$error);
15710: }
15711:
15712: sub generate_code {
15713: my $code;
15714: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15715: for (my $i=0; $i<6; $i++) {
15716: my $lettnum = int (rand 2);
15717: my $item = '';
15718: if ($lettnum) {
15719: $item = $letts[int( rand(18) )];
15720: } else {
15721: $item = 1+int( rand(8) );
15722: }
15723: $code .= $item;
15724: }
15725: return $code;
15726: }
15727:
1.444 albertel 15728: ############################################################
15729: ############################################################
15730:
1.1237 raeburn 15731: # Community, Course and Placement Test
1.378 raeburn 15732: sub course_type {
15733: my ($cid) = @_;
15734: if (!defined($cid)) {
15735: $cid = $env{'request.course.id'};
15736: }
1.404 albertel 15737: if (defined($env{'course.'.$cid.'.type'})) {
15738: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15739: } else {
15740: return 'Course';
1.377 raeburn 15741: }
15742: }
1.156 albertel 15743:
1.406 raeburn 15744: sub group_term {
15745: my $crstype = &course_type();
15746: my %names = (
15747: 'Course' => 'group',
1.865 raeburn 15748: 'Community' => 'group',
1.1237 raeburn 15749: 'Placement' => 'group',
1.406 raeburn 15750: );
15751: return $names{$crstype};
15752: }
15753:
1.902 raeburn 15754: sub course_types {
1.1237 raeburn 15755: my @types = ('official','unofficial','community','textbook','placement');
1.902 raeburn 15756: my %typename = (
15757: official => 'Official course',
15758: unofficial => 'Unofficial course',
15759: community => 'Community',
1.1165 raeburn 15760: textbook => 'Textbook course',
1.1237 raeburn 15761: placement => 'Placement test',
1.902 raeburn 15762: );
15763: return (\@types,\%typename);
15764: }
15765:
1.156 albertel 15766: sub icon {
15767: my ($file)=@_;
1.505 albertel 15768: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15769: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15770: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15771: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15772: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15773: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15774: $curfext.".gif") {
15775: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15776: $curfext.".gif";
15777: }
15778: }
1.249 albertel 15779: return &lonhttpdurl($iconname);
1.154 albertel 15780: }
1.84 albertel 15781:
1.575 albertel 15782: sub lonhttpdurl {
1.692 www 15783: #
15784: # Had been used for "small fry" static images on separate port 8080.
15785: # Modify here if lightweight http functionality desired again.
15786: # Currently eliminated due to increasing firewall issues.
15787: #
1.575 albertel 15788: my ($url)=@_;
1.692 www 15789: return $url;
1.215 albertel 15790: }
15791:
1.213 albertel 15792: sub connection_aborted {
15793: my ($r)=@_;
15794: $r->print(" ");$r->rflush();
15795: my $c = $r->connection;
15796: return $c->aborted();
15797: }
15798:
1.221 foxr 15799: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15800: # strings as 'strings'.
15801: sub escape_single {
1.221 foxr 15802: my ($input) = @_;
1.223 albertel 15803: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15804: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15805: return $input;
15806: }
1.223 albertel 15807:
1.222 foxr 15808: # Same as escape_single, but escape's "'s This
15809: # can be used for "strings"
15810: sub escape_double {
15811: my ($input) = @_;
15812: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15813: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15814: return $input;
15815: }
1.223 albertel 15816:
1.222 foxr 15817: # Escapes the last element of a full URL.
15818: sub escape_url {
15819: my ($url) = @_;
1.238 raeburn 15820: my @urlslices = split(/\//, $url,-1);
1.369 www 15821: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 15822: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15823: }
1.462 albertel 15824:
1.820 raeburn 15825: sub compare_arrays {
15826: my ($arrayref1,$arrayref2) = @_;
15827: my (@difference,%count);
15828: @difference = ();
15829: %count = ();
15830: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15831: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15832: foreach my $element (keys(%count)) {
15833: if ($count{$element} == 1) {
15834: push(@difference,$element);
15835: }
15836: }
15837: }
15838: return @difference;
15839: }
15840:
1.817 bisitz 15841: # -------------------------------------------------------- Initialize user login
1.462 albertel 15842: sub init_user_environment {
1.463 albertel 15843: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15844: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15845:
15846: my $public=($username eq 'public' && $domain eq 'public');
15847:
15848: # See if old ID present, if so, remove
15849:
1.1062 raeburn 15850: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15851: my $now=time;
15852:
15853: if ($public) {
15854: my $max_public=100;
15855: my $oldest;
15856: my $oldest_time=0;
15857: for(my $next=1;$next<=$max_public;$next++) {
15858: if (-e $lonids."/publicuser_$next.id") {
15859: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15860: if ($mtime<$oldest_time || !$oldest_time) {
15861: $oldest_time=$mtime;
15862: $oldest=$next;
15863: }
15864: } else {
15865: $cookie="publicuser_$next";
15866: last;
15867: }
15868: }
15869: if (!$cookie) { $cookie="publicuser_$oldest"; }
15870: } else {
1.463 albertel 15871: # if this isn't a robot, kill any existing non-robot sessions
15872: if (!$args->{'robot'}) {
15873: opendir(DIR,$lonids);
15874: while ($filename=readdir(DIR)) {
15875: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
15876: unlink($lonids.'/'.$filename);
15877: }
1.462 albertel 15878: }
1.463 albertel 15879: closedir(DIR);
1.1204 raeburn 15880: # If there is a undeleted lockfile for the user's paste buffer remove it.
15881: my $namespace = 'nohist_courseeditor';
15882: my $lockingkey = 'paste'."\0".'locked_num';
15883: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15884: $domain,$username);
15885: if (exists($lockhash{$lockingkey})) {
15886: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15887: unless ($delresult eq 'ok') {
15888: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15889: }
15890: }
1.462 albertel 15891: }
15892: # Give them a new cookie
1.463 albertel 15893: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15894: : $now.$$.int(rand(10000)));
1.463 albertel 15895: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15896:
15897: # Initialize roles
15898:
1.1062 raeburn 15899: ($userroles,$firstaccenv,$timerintenv) =
15900: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15901: }
15902: # ------------------------------------ Check browser type and MathML capability
15903:
1.1194 raeburn 15904: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15905: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15906:
15907: # ------------------------------------------------------------- Get environment
15908:
15909: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15910: my ($tmp) = keys(%userenv);
15911: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15912: } else {
15913: undef(%userenv);
15914: }
15915: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15916: $form->{'interface'}=$userenv{'interface'};
15917: }
15918: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15919:
15920: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15921: foreach my $option ('interface','localpath','localres') {
15922: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15923: }
15924: # --------------------------------------------------------- Write first profile
15925:
15926: {
15927: my %initial_env =
15928: ("user.name" => $username,
15929: "user.domain" => $domain,
15930: "user.home" => $authhost,
15931: "browser.type" => $clientbrowser,
15932: "browser.version" => $clientversion,
15933: "browser.mathml" => $clientmathml,
15934: "browser.unicode" => $clientunicode,
15935: "browser.os" => $clientos,
1.1137 raeburn 15936: "browser.mobile" => $clientmobile,
1.1141 raeburn 15937: "browser.info" => $clientinfo,
1.1194 raeburn 15938: "browser.osversion" => $clientosversion,
1.462 albertel 15939: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15940: "request.course.fn" => '',
15941: "request.course.uri" => '',
15942: "request.course.sec" => '',
15943: "request.role" => 'cm',
15944: "request.role.adv" => $env{'user.adv'},
15945: "request.host" => $ENV{'REMOTE_ADDR'},);
15946:
15947: if ($form->{'localpath'}) {
15948: $initial_env{"browser.localpath"} = $form->{'localpath'};
15949: $initial_env{"browser.localres"} = $form->{'localres'};
15950: }
15951:
15952: if ($form->{'interface'}) {
15953: $form->{'interface'}=~s/\W//gs;
15954: $initial_env{"browser.interface"} = $form->{'interface'};
15955: $env{'browser.interface'}=$form->{'interface'};
15956: }
15957:
1.1157 raeburn 15958: if ($form->{'iptoken'}) {
15959: my $lonhost = $r->dir_config('lonHostID');
15960: $initial_env{"user.noloadbalance"} = $lonhost;
15961: $env{'user.noloadbalance'} = $lonhost;
15962: }
15963:
1.981 raeburn 15964: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 15965: my %domdef;
15966: unless ($domain eq 'public') {
15967: %domdef = &Apache::lonnet::get_domain_defaults($domain);
15968: }
1.980 raeburn 15969:
1.1081 raeburn 15970: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 15971: $userenv{'availabletools.'.$tool} =
1.980 raeburn 15972: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15973: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 15974: }
15975:
1.1237 raeburn 15976: foreach my $crstype ('official','unofficial','community','textbook','placement') {
1.765 raeburn 15977: $userenv{'canrequest.'.$crstype} =
15978: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 15979: 'reload','requestcourses',
15980: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 15981: }
15982:
1.1092 raeburn 15983: $userenv{'canrequest.author'} =
15984: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15985: 'reload','requestauthor',
15986: \%userenv,\%domdef,\%is_adv);
15987: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15988: $domain,$username);
15989: my $reqstatus = $reqauthor{'author_status'};
15990: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15991: if (ref($reqauthor{'author'}) eq 'HASH') {
15992: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15993: $reqauthor{'author'}{'timestamp'};
15994: }
15995: }
15996:
1.462 albertel 15997: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15998:
1.462 albertel 15999: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16000: &GDBM_WRCREAT(),0640)) {
16001: &_add_to_env(\%disk_env,\%initial_env);
16002: &_add_to_env(\%disk_env,\%userenv,'environment.');
16003: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16004: if (ref($firstaccenv) eq 'HASH') {
16005: &_add_to_env(\%disk_env,$firstaccenv);
16006: }
16007: if (ref($timerintenv) eq 'HASH') {
16008: &_add_to_env(\%disk_env,$timerintenv);
16009: }
1.463 albertel 16010: if (ref($args->{'extra_env'})) {
16011: &_add_to_env(\%disk_env,$args->{'extra_env'});
16012: }
1.462 albertel 16013: untie(%disk_env);
16014: } else {
1.705 tempelho 16015: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16016: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16017: return 'error: '.$!;
16018: }
16019: }
16020: $env{'request.role'}='cm';
16021: $env{'request.role.adv'}=$env{'user.adv'};
16022: $env{'browser.type'}=$clientbrowser;
16023:
16024: return $cookie;
16025:
16026: }
16027:
16028: sub _add_to_env {
16029: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16030: if (ref($env_data) eq 'HASH') {
16031: while (my ($key,$value) = each(%$env_data)) {
16032: $idf->{$prefix.$key} = $value;
16033: $env{$prefix.$key} = $value;
16034: }
1.462 albertel 16035: }
16036: }
16037:
1.685 tempelho 16038: # --- Get the symbolic name of a problem and the url
16039: sub get_symb {
16040: my ($request,$silent) = @_;
1.726 raeburn 16041: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16042: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16043: if ($symb eq '') {
16044: if (!$silent) {
1.1071 raeburn 16045: if (ref($request)) {
16046: $request->print("Unable to handle ambiguous references:$url:.");
16047: }
1.685 tempelho 16048: return ();
16049: }
16050: }
16051: &Apache::lonenc::check_decrypt(\$symb);
16052: return ($symb);
16053: }
16054:
16055: # --------------------------------------------------------------Get annotation
16056:
16057: sub get_annotation {
16058: my ($symb,$enc) = @_;
16059:
16060: my $key = $symb;
16061: if (!$enc) {
16062: $key =
16063: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16064: }
16065: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16066: return $annotation{$key};
16067: }
16068:
16069: sub clean_symb {
1.731 raeburn 16070: my ($symb,$delete_enc) = @_;
1.685 tempelho 16071:
16072: &Apache::lonenc::check_decrypt(\$symb);
16073: my $enc = $env{'request.enc'};
1.731 raeburn 16074: if ($delete_enc) {
1.730 raeburn 16075: delete($env{'request.enc'});
16076: }
1.685 tempelho 16077:
16078: return ($symb,$enc);
16079: }
1.462 albertel 16080:
1.1181 raeburn 16081: ############################################################
16082: ############################################################
16083:
16084: =pod
16085:
16086: =head1 Routines for building display used to search for courses
16087:
16088:
16089: =over 4
16090:
16091: =item * &build_filters()
16092:
16093: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16094: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16095: and quotacheck.pl
16096:
1.1181 raeburn 16097:
16098: Inputs:
16099:
16100: filterlist - anonymous array of fields to include as potential filters
16101:
16102: crstype - course type
16103:
16104: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16105: to pop-open a course selector (will contain "extra element").
16106:
16107: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16108:
16109: filter - anonymous hash of criteria and their values
16110:
16111: action - form action
16112:
16113: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16114:
1.1182 raeburn 16115: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16116:
16117: cloneruname - username of owner of new course who wants to clone
16118:
16119: clonerudom - domain of owner of new course who wants to clone
16120:
16121: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16122:
16123: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16124:
16125: codedom - domain
16126:
16127: formname - value of form element named "form".
16128:
16129: fixeddom - domain, if fixed.
16130:
16131: prevphase - value to assign to form element named "phase" when going back to the previous screen
16132:
16133: cnameelement - name of form element in form on opener page which will receive title of selected course
16134:
16135: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16136:
16137: cdomelement - name of form element in form on opener page which will receive domain of selected course
16138:
16139: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16140:
16141: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16142:
16143: clonewarning - warning message about missing information for intended course owner when DC creates a course
16144:
1.1182 raeburn 16145:
1.1181 raeburn 16146: Returns: $output - HTML for display of search criteria, and hidden form elements.
16147:
1.1182 raeburn 16148:
1.1181 raeburn 16149: Side Effects: None
16150:
16151: =cut
16152:
16153: # ---------------------------------------------- search for courses based on last activity etc.
16154:
16155: sub build_filters {
16156: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16157: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16158: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16159: $cnameelement,$cnumelement,$cdomelement,$setroles,
16160: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16161: my ($list,$jscript);
1.1181 raeburn 16162: my $onchange = 'javascript:updateFilters(this)';
16163: my ($domainselectform,$sincefilterform,$createdfilterform,
16164: $ownerdomselectform,$persondomselectform,$instcodeform,
16165: $typeselectform,$instcodetitle);
16166: if ($formname eq '') {
16167: $formname = $caller;
16168: }
16169: foreach my $item (@{$filterlist}) {
16170: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16171: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16172: if ($item eq 'domainfilter') {
16173: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16174: } elsif ($item eq 'coursefilter') {
16175: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16176: } elsif ($item eq 'ownerfilter') {
16177: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16178: } elsif ($item eq 'ownerdomfilter') {
16179: $filter->{'ownerdomfilter'} =
16180: &LONCAPA::clean_domain($filter->{$item});
16181: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16182: 'ownerdomfilter',1);
16183: } elsif ($item eq 'personfilter') {
16184: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16185: } elsif ($item eq 'persondomfilter') {
16186: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16187: 'persondomfilter',1);
16188: } else {
16189: $filter->{$item} =~ s/\W//g;
16190: }
16191: if (!$filter->{$item}) {
16192: $filter->{$item} = '';
16193: }
16194: }
16195: if ($item eq 'domainfilter') {
16196: my $allow_blank = 1;
16197: if ($formname eq 'portform') {
16198: $allow_blank=0;
16199: } elsif ($formname eq 'studentform') {
16200: $allow_blank=0;
16201: }
16202: if ($fixeddom) {
16203: $domainselectform = '<input type="hidden" name="domainfilter"'.
16204: ' value="'.$codedom.'" />'.
16205: &Apache::lonnet::domain($codedom,'description');
16206: } else {
16207: $domainselectform = &select_dom_form($filter->{$item},
16208: 'domainfilter',
16209: $allow_blank,'',$onchange);
16210: }
16211: } else {
16212: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16213: }
16214: }
16215:
16216: # last course activity filter and selection
16217: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16218:
16219: # course created filter and selection
16220: if (exists($filter->{'createdfilter'})) {
16221: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16222: }
16223:
1.1239 raeburn 16224: my $prefix = $crstype;
16225: if ($crstype eq 'Placement') {
16226: $prefix = 'Placement Test'
16227: }
1.1181 raeburn 16228: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16229: 'cac' => "$prefix Activity",
16230: 'ccr' => "$prefix Created",
16231: 'cde' => "$prefix Title",
16232: 'cdo' => "$prefix Domain",
1.1181 raeburn 16233: 'ins' => 'Institutional Code',
16234: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16235: 'cow' => "$prefix Owner/Co-owner",
16236: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16237: 'cog' => 'Type',
16238: );
16239:
16240: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16241: my $typeval = 'Course';
16242: if ($crstype eq 'Community') {
16243: $typeval = 'Community';
1.1239 raeburn 16244: } elsif ($crstype eq 'Placement') {
16245: $typeval = 'Placement';
1.1181 raeburn 16246: }
16247: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16248: } else {
16249: $typeselectform = '<select name="type" size="1"';
16250: if ($onchange) {
16251: $typeselectform .= ' onchange="'.$onchange.'"';
16252: }
16253: $typeselectform .= '>'."\n";
1.1237 raeburn 16254: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16255: my $shown;
16256: if ($posstype eq 'Placement') {
16257: $shown = &mt('Placement Test');
16258: } else {
16259: $shown = &mt($posstype);
16260: }
1.1181 raeburn 16261: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 16262: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 16263: }
16264: $typeselectform.="</select>";
16265: }
16266:
16267: my ($cloneableonlyform,$cloneabletitle);
16268: if (exists($filter->{'cloneableonly'})) {
16269: my $cloneableon = '';
16270: my $cloneableoff = ' checked="checked"';
16271: if ($filter->{'cloneableonly'}) {
16272: $cloneableon = $cloneableoff;
16273: $cloneableoff = '';
16274: }
16275: $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>';
16276: if ($formname eq 'ccrs') {
1.1187 bisitz 16277: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 16278: } else {
16279: $cloneabletitle = &mt('Cloneable by you');
16280: }
16281: }
16282: my $officialjs;
16283: if ($crstype eq 'Course') {
16284: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 16285: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16286: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16287: if ($codedom) {
1.1181 raeburn 16288: $officialjs = 1;
16289: ($instcodeform,$jscript,$$numtitlesref) =
16290: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16291: $officialjs,$codetitlesref);
16292: if ($jscript) {
1.1182 raeburn 16293: $jscript = '<script type="text/javascript">'."\n".
16294: '// <![CDATA['."\n".
16295: $jscript."\n".
16296: '// ]]>'."\n".
16297: '</script>'."\n";
1.1181 raeburn 16298: }
16299: }
16300: if ($instcodeform eq '') {
16301: $instcodeform =
16302: '<input type="text" name="instcodefilter" size="10" value="'.
16303: $list->{'instcodefilter'}.'" />';
16304: $instcodetitle = $lt{'ins'};
16305: } else {
16306: $instcodetitle = $lt{'inc'};
16307: }
16308: if ($fixeddom) {
16309: $instcodetitle .= '<br />('.$codedom.')';
16310: }
16311: }
16312: }
16313: my $output = qq|
16314: <form method="post" name="filterpicker" action="$action">
16315: <input type="hidden" name="form" value="$formname" />
16316: |;
16317: if ($formname eq 'modifycourse') {
16318: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16319: '<input type="hidden" name="prevphase" value="'.
16320: $prevphase.'" />'."\n";
1.1198 musolffc 16321: } elsif ($formname eq 'quotacheck') {
16322: $output .= qq|
16323: <input type="hidden" name="sortby" value="" />
16324: <input type="hidden" name="sortorder" value="" />
16325: |;
16326: } else {
1.1181 raeburn 16327: my $name_input;
16328: if ($cnameelement ne '') {
16329: $name_input = '<input type="hidden" name="cnameelement" value="'.
16330: $cnameelement.'" />';
16331: }
16332: $output .= qq|
1.1182 raeburn 16333: <input type="hidden" name="cnumelement" value="$cnumelement" />
16334: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 16335: $name_input
16336: $roleelement
16337: $multelement
16338: $typeelement
16339: |;
16340: if ($formname eq 'portform') {
16341: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16342: }
16343: }
16344: if ($fixeddom) {
16345: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16346: }
16347: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16348: if ($sincefilterform) {
16349: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16350: .$sincefilterform
16351: .&Apache::lonhtmlcommon::row_closure();
16352: }
16353: if ($createdfilterform) {
16354: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16355: .$createdfilterform
16356: .&Apache::lonhtmlcommon::row_closure();
16357: }
16358: if ($domainselectform) {
16359: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16360: .$domainselectform
16361: .&Apache::lonhtmlcommon::row_closure();
16362: }
16363: if ($typeselectform) {
16364: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16365: $output .= $typeselectform;
16366: } else {
16367: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16368: .$typeselectform
16369: .&Apache::lonhtmlcommon::row_closure();
16370: }
16371: }
16372: if ($instcodeform) {
16373: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16374: .$instcodeform
16375: .&Apache::lonhtmlcommon::row_closure();
16376: }
16377: if (exists($filter->{'ownerfilter'})) {
16378: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16379: '<table><tr><td>'.&mt('Username').'<br />'.
16380: '<input type="text" name="ownerfilter" size="20" value="'.
16381: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16382: $ownerdomselectform.'</td></tr></table>'.
16383: &Apache::lonhtmlcommon::row_closure();
16384: }
16385: if (exists($filter->{'personfilter'})) {
16386: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16387: '<table><tr><td>'.&mt('Username').'<br />'.
16388: '<input type="text" name="personfilter" size="20" value="'.
16389: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16390: $persondomselectform.'</td></tr></table>'.
16391: &Apache::lonhtmlcommon::row_closure();
16392: }
16393: if (exists($filter->{'coursefilter'})) {
16394: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16395: .'<input type="text" name="coursefilter" size="25" value="'
16396: .$list->{'coursefilter'}.'" />'
16397: .&Apache::lonhtmlcommon::row_closure();
16398: }
16399: if ($cloneableonlyform) {
16400: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16401: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16402: }
16403: if (exists($filter->{'descriptfilter'})) {
16404: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16405: .'<input type="text" name="descriptfilter" size="40" value="'
16406: .$list->{'descriptfilter'}.'" />'
16407: .&Apache::lonhtmlcommon::row_closure(1);
16408: }
16409: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16410: '<input type="hidden" name="updater" value="" />'."\n".
16411: '<input type="submit" name="gosearch" value="'.
16412: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16413: return $jscript.$clonewarning.$output;
16414: }
16415:
16416: =pod
16417:
16418: =item * &timebased_select_form()
16419:
1.1182 raeburn 16420: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 16421: filter e.g., Course Activity, Course Created, when searching for courses
16422: or communities
16423:
16424: Inputs:
16425:
16426: item - name of form element (sincefilter or createdfilter)
16427:
16428: filter - anonymous hash of criteria and their values
16429:
16430: Returns: HTML for a select box contained a blank, then six time selections,
16431: with value set in incoming form variables currently selected.
16432:
16433: Side Effects: None
16434:
16435: =cut
16436:
16437: sub timebased_select_form {
16438: my ($item,$filter) = @_;
16439: if (ref($filter) eq 'HASH') {
16440: $filter->{$item} =~ s/[^\d-]//g;
16441: if (!$filter->{$item}) { $filter->{$item}=-1; }
16442: return &select_form(
16443: $filter->{$item},
16444: $item,
16445: { '-1' => '',
16446: '86400' => &mt('today'),
16447: '604800' => &mt('last week'),
16448: '2592000' => &mt('last month'),
16449: '7776000' => &mt('last three months'),
16450: '15552000' => &mt('last six months'),
16451: '31104000' => &mt('last year'),
16452: 'select_form_order' =>
16453: ['-1','86400','604800','2592000','7776000',
16454: '15552000','31104000']});
16455: }
16456: }
16457:
16458: =pod
16459:
16460: =item * &js_changer()
16461:
16462: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 16463: when course type or domain is changed, and also to hide 'Searching ...' on
16464: page load completion for page showing search result.
1.1181 raeburn 16465:
16466: Inputs: None
16467:
1.1183 raeburn 16468: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 16469:
16470: Side Effects: None
16471:
16472: =cut
16473:
16474: sub js_changer {
16475: return <<ENDJS;
16476: <script type="text/javascript">
16477: // <![CDATA[
16478: function updateFilters(caller) {
16479: if (typeof(caller) != "undefined") {
16480: document.filterpicker.updater.value = caller.name;
16481: }
16482: document.filterpicker.submit();
16483: }
1.1183 raeburn 16484:
16485: function hideSearching() {
16486: if (document.getElementById('searching')) {
16487: document.getElementById('searching').style.display = 'none';
16488: }
16489: return;
16490: }
16491:
1.1181 raeburn 16492: // ]]>
16493: </script>
16494:
16495: ENDJS
16496: }
16497:
16498: =pod
16499:
1.1182 raeburn 16500: =item * &search_courses()
16501:
16502: Process selected filters form course search form and pass to lonnet::courseiddump
16503: to retrieve a hash for which keys are courseIDs which match the selected filters.
16504:
16505: Inputs:
16506:
16507: dom - domain being searched
16508:
16509: type - course type ('Course' or 'Community' or '.' if any).
16510:
16511: filter - anonymous hash of criteria and their values
16512:
16513: numtitles - for institutional codes - number of categories
16514:
16515: cloneruname - optional username of new course owner
16516:
16517: clonerudom - optional domain of new course owner
16518:
1.1221 raeburn 16519: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 16520: (used when DC is using course creation form)
16521:
16522: codetitles - reference to array of titles of components in institutional codes (official courses).
16523:
1.1221 raeburn 16524: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16525: (and so can clone automatically)
16526:
16527: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16528:
16529: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16530: courses to clone
1.1182 raeburn 16531:
16532: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16533:
16534:
16535: Side Effects: None
16536:
16537: =cut
16538:
16539:
16540: sub search_courses {
1.1221 raeburn 16541: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16542: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 16543: my (%courses,%showcourses,$cloner);
16544: if (($filter->{'ownerfilter'} ne '') ||
16545: ($filter->{'ownerdomfilter'} ne '')) {
16546: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16547: $filter->{'ownerdomfilter'};
16548: }
16549: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16550: if (!$filter->{$item}) {
16551: $filter->{$item}='.';
16552: }
16553: }
16554: my $now = time;
16555: my $timefilter =
16556: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16557: my ($createdbefore,$createdafter);
16558: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16559: $createdbefore = $now;
16560: $createdafter = $now-$filter->{'createdfilter'};
16561: }
16562: my ($instcodefilter,$regexpok);
16563: if ($numtitles) {
16564: if ($env{'form.official'} eq 'on') {
16565: $instcodefilter =
16566: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16567: $regexpok = 1;
16568: } elsif ($env{'form.official'} eq 'off') {
16569: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16570: unless ($instcodefilter eq '') {
16571: $regexpok = -1;
16572: }
16573: }
16574: } else {
16575: $instcodefilter = $filter->{'instcodefilter'};
16576: }
16577: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16578: if ($type eq '') { $type = '.'; }
16579:
16580: if (($clonerudom ne '') && ($cloneruname ne '')) {
16581: $cloner = $cloneruname.':'.$clonerudom;
16582: }
16583: %courses = &Apache::lonnet::courseiddump($dom,
16584: $filter->{'descriptfilter'},
16585: $timefilter,
16586: $instcodefilter,
16587: $filter->{'combownerfilter'},
16588: $filter->{'coursefilter'},
16589: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 16590: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 16591: $filter->{'cloneableonly'},
16592: $createdbefore,$createdafter,undef,
1.1221 raeburn 16593: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 16594: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16595: my $ccrole;
16596: if ($type eq 'Community') {
16597: $ccrole = 'co';
16598: } else {
16599: $ccrole = 'cc';
16600: }
16601: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16602: $filter->{'persondomfilter'},
16603: 'userroles',undef,
16604: [$ccrole,'in','ad','ep','ta','cr'],
16605: $dom);
16606: foreach my $role (keys(%rolehash)) {
16607: my ($cnum,$cdom,$courserole) = split(':',$role);
16608: my $cid = $cdom.'_'.$cnum;
16609: if (exists($courses{$cid})) {
16610: if (ref($courses{$cid}) eq 'HASH') {
16611: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16612: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
16613: push (@{$courses{$cid}{roles}},$courserole);
16614: }
16615: } else {
16616: $courses{$cid}{roles} = [$courserole];
16617: }
16618: $showcourses{$cid} = $courses{$cid};
16619: }
16620: }
16621: }
16622: %courses = %showcourses;
16623: }
16624: return %courses;
16625: }
16626:
16627: =pod
16628:
1.1181 raeburn 16629: =back
16630:
1.1207 raeburn 16631: =head1 Routines for version requirements for current course.
16632:
16633: =over 4
16634:
16635: =item * &check_release_required()
16636:
16637: Compares required LON-CAPA version with version on server, and
16638: if required version is newer looks for a server with the required version.
16639:
16640: Looks first at servers in user's owen domain; if none suitable, looks at
16641: servers in course's domain are permitted to host sessions for user's domain.
16642:
16643: Inputs:
16644:
16645: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16646:
16647: $courseid - Course ID of current course
16648:
16649: $rolecode - User's current role in course (for switchserver query string).
16650:
16651: $required - LON-CAPA version needed by course (format: Major.Minor).
16652:
16653:
16654: Returns:
16655:
16656: $switchserver - query string tp append to /adm/switchserver call (if
16657: current server's LON-CAPA version is too old.
16658:
16659: $warning - Message is displayed if no suitable server could be found.
16660:
16661: =cut
16662:
16663: sub check_release_required {
16664: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16665: my ($switchserver,$warning);
16666: if ($required ne '') {
16667: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16668: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16669: if ($reqdmajor ne '' && $reqdminor ne '') {
16670: my $otherserver;
16671: if (($major eq '' && $minor eq '') ||
16672: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16673: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16674: my $switchlcrev =
16675: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16676: $userdomserver);
16677: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16678: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16679: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16680: my $cdom = $env{'course.'.$courseid.'.domain'};
16681: if ($cdom ne $env{'user.domain'}) {
16682: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16683: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16684: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16685: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16686: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16687: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16688: my $canhost =
16689: &Apache::lonnet::can_host_session($env{'user.domain'},
16690: $coursedomserver,
16691: $remoterev,
16692: $udomdefaults{'remotesessions'},
16693: $defdomdefaults{'hostedsessions'});
16694:
16695: if ($canhost) {
16696: $otherserver = $coursedomserver;
16697: } else {
16698: $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.");
16699: }
16700: } else {
16701: $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).");
16702: }
16703: } else {
16704: $otherserver = $userdomserver;
16705: }
16706: }
16707: if ($otherserver ne '') {
16708: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16709: }
16710: }
16711: }
16712: return ($switchserver,$warning);
16713: }
16714:
16715: =pod
16716:
16717: =item * &check_release_result()
16718:
16719: Inputs:
16720:
16721: $switchwarning - Warning message if no suitable server found to host session.
16722:
16723: $switchserver - query string to append to /adm/switchserver containing lonHostID
16724: and current role.
16725:
16726: Returns: HTML to display with information about requirement to switch server.
16727: Either displaying warning with link to Roles/Courses screen or
16728: display link to switchserver.
16729:
1.1181 raeburn 16730: =cut
16731:
1.1207 raeburn 16732: sub check_release_result {
16733: my ($switchwarning,$switchserver) = @_;
16734: my $output = &start_page('Selected course unavailable on this server').
16735: '<p class="LC_warning">';
16736: if ($switchwarning) {
16737: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16738: if (&show_course()) {
16739: $output .= &mt('Display courses');
16740: } else {
16741: $output .= &mt('Display roles');
16742: }
16743: $output .= '</a>';
16744: } elsif ($switchserver) {
16745: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16746: '<br />'.
16747: '<a href="/adm/switchserver?'.$switchserver.'">'.
16748: &mt('Switch Server').
16749: '</a>';
16750: }
16751: $output .= '</p>'.&end_page();
16752: return $output;
16753: }
16754:
16755: =pod
16756:
16757: =item * &needs_coursereinit()
16758:
16759: Determine if course contents stored for user's session needs to be
16760: refreshed, because content has changed since "Big Hash" last tied.
16761:
16762: Check for change is made if time last checked is more than 10 minutes ago
16763: (by default).
16764:
16765: Inputs:
16766:
16767: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16768:
16769: $interval (optional) - Time which may elapse (in s) between last check for content
16770: change in current course. (default: 600 s).
16771:
16772: Returns: an array; first element is:
16773:
16774: =over 4
16775:
16776: 'switch' - if content updates mean user's session
16777: needs to be switched to a server running a newer LON-CAPA version
16778:
16779: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16780: on current server hosting user's session
16781:
16782: '' - if no action required.
16783:
16784: =back
16785:
16786: If first item element is 'switch':
16787:
16788: second item is $switchwarning - Warning message if no suitable server found to host session.
16789:
16790: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16791: and current role.
16792:
16793: otherwise: no other elements returned.
16794:
16795: =back
16796:
16797: =cut
16798:
16799: sub needs_coursereinit {
16800: my ($loncaparev,$interval) = @_;
16801: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16802: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16803: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16804: my $now = time;
16805: if ($interval eq '') {
16806: $interval = 600;
16807: }
16808: if (($now-$env{'request.course.timechecked'})>$interval) {
16809: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16810: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16811: if ($lastchange > $env{'request.course.tied'}) {
16812: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16813: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16814: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16815: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16816: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16817: $curr_reqd_hash{'internal.releaserequired'}});
16818: my ($switchserver,$switchwarning) =
16819: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16820: $curr_reqd_hash{'internal.releaserequired'});
16821: if ($switchwarning ne '' || $switchserver ne '') {
16822: return ('switch',$switchwarning,$switchserver);
16823: }
16824: }
16825: }
16826: return ('update');
16827: }
16828: }
16829: return ();
16830: }
1.1181 raeburn 16831:
1.1083 raeburn 16832: sub update_content_constraints {
16833: my ($cdom,$cnum,$chome,$cid) = @_;
16834: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16835: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16836: my %checkresponsetypes;
16837: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 16838: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 16839: if ($item eq 'resourcetag') {
16840: if ($name eq 'responsetype') {
16841: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16842: }
16843: }
16844: }
16845: my $navmap = Apache::lonnavmaps::navmap->new();
16846: if (defined($navmap)) {
16847: my %allresponses;
16848: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16849: my %responses = $res->responseTypes();
16850: foreach my $key (keys(%responses)) {
16851: next unless(exists($checkresponsetypes{$key}));
16852: $allresponses{$key} += $responses{$key};
16853: }
16854: }
16855: foreach my $key (keys(%allresponses)) {
16856: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16857: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16858: ($reqdmajor,$reqdminor) = ($major,$minor);
16859: }
16860: }
16861: undef($navmap);
16862: }
16863: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16864: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16865: }
16866: return;
16867: }
16868:
1.1110 raeburn 16869: sub allmaps_incourse {
16870: my ($cdom,$cnum,$chome,$cid) = @_;
16871: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16872: $cid = $env{'request.course.id'};
16873: $cdom = $env{'course.'.$cid.'.domain'};
16874: $cnum = $env{'course.'.$cid.'.num'};
16875: $chome = $env{'course.'.$cid.'.home'};
16876: }
16877: my %allmaps = ();
16878: my $lastchange =
16879: &Apache::lonnet::get_coursechange($cdom,$cnum);
16880: if ($lastchange > $env{'request.course.tied'}) {
16881: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16882: unless ($ferr) {
16883: &update_content_constraints($cdom,$cnum,$chome,$cid);
16884: }
16885: }
16886: my $navmap = Apache::lonnavmaps::navmap->new();
16887: if (defined($navmap)) {
16888: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16889: $allmaps{$res->src()} = 1;
16890: }
16891: }
16892: return \%allmaps;
16893: }
16894:
1.1083 raeburn 16895: sub parse_supplemental_title {
16896: my ($title) = @_;
16897:
16898: my ($foldertitle,$renametitle);
16899: if ($title =~ /&&&/) {
16900: $title = &HTML::Entites::decode($title);
16901: }
16902: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16903: $renametitle=$4;
16904: my ($time,$uname,$udom) = ($1,$2,$3);
16905: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16906: my $name = &plainname($uname,$udom);
16907: $name = &HTML::Entities::encode($name,'"<>&\'');
16908: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16909: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16910: $name.': <br />'.$foldertitle;
16911: }
16912: if (wantarray) {
16913: return ($title,$foldertitle,$renametitle);
16914: }
16915: return $title;
16916: }
16917:
1.1143 raeburn 16918: sub recurse_supplemental {
16919: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16920: if ($suppmap) {
16921: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16922: if ($fatal) {
16923: $errors ++;
16924: } else {
16925: if ($#LONCAPA::map::resources > 0) {
16926: foreach my $res (@LONCAPA::map::resources) {
16927: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16928: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 16929: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16930: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 16931: } else {
16932: $numfiles ++;
16933: }
16934: }
16935: }
16936: }
16937: }
16938: }
16939: return ($numfiles,$errors);
16940: }
16941:
1.1101 raeburn 16942: sub symb_to_docspath {
16943: my ($symb) = @_;
16944: return unless ($symb);
16945: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16946: if ($resurl=~/\.(sequence|page)$/) {
16947: $mapurl=$resurl;
16948: } elsif ($resurl eq 'adm/navmaps') {
16949: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16950: }
16951: my $mapresobj;
16952: my $navmap = Apache::lonnavmaps::navmap->new();
16953: if (ref($navmap)) {
16954: $mapresobj = $navmap->getResourceByUrl($mapurl);
16955: }
16956: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16957: my $type=$2;
16958: my $path;
16959: if (ref($mapresobj)) {
16960: my $pcslist = $mapresobj->map_hierarchy();
16961: if ($pcslist ne '') {
16962: foreach my $pc (split(/,/,$pcslist)) {
16963: next if ($pc <= 1);
16964: my $res = $navmap->getByMapPc($pc);
16965: if (ref($res)) {
16966: my $thisurl = $res->src();
16967: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16968: my $thistitle = $res->title();
16969: $path .= '&'.
16970: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 16971: &escape($thistitle).
1.1101 raeburn 16972: ':'.$res->randompick().
16973: ':'.$res->randomout().
16974: ':'.$res->encrypted().
16975: ':'.$res->randomorder().
16976: ':'.$res->is_page();
16977: }
16978: }
16979: }
16980: $path =~ s/^\&//;
16981: my $maptitle = $mapresobj->title();
16982: if ($mapurl eq 'default') {
1.1129 raeburn 16983: $maptitle = 'Main Content';
1.1101 raeburn 16984: }
16985: $path .= (($path ne '')? '&' : '').
16986: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 16987: &escape($maptitle).
1.1101 raeburn 16988: ':'.$mapresobj->randompick().
16989: ':'.$mapresobj->randomout().
16990: ':'.$mapresobj->encrypted().
16991: ':'.$mapresobj->randomorder().
16992: ':'.$mapresobj->is_page();
16993: } else {
16994: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16995: my $ispage = (($type eq 'page')? 1 : '');
16996: if ($mapurl eq 'default') {
1.1129 raeburn 16997: $maptitle = 'Main Content';
1.1101 raeburn 16998: }
16999: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17000: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17001: }
17002: unless ($mapurl eq 'default') {
17003: $path = 'default&'.
1.1146 raeburn 17004: &escape('Main Content').
1.1101 raeburn 17005: ':::::&'.$path;
17006: }
17007: return $path;
17008: }
17009:
1.1094 raeburn 17010: sub captcha_display {
17011: my ($context,$lonhost) = @_;
17012: my ($output,$error);
1.1234 raeburn 17013: my ($captcha,$pubkey,$privkey,$version) =
17014: &get_captcha_config($context,$lonhost);
1.1095 raeburn 17015: if ($captcha eq 'original') {
1.1094 raeburn 17016: $output = &create_captcha();
17017: unless ($output) {
1.1172 raeburn 17018: $error = 'captcha';
1.1094 raeburn 17019: }
17020: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17021: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17022: unless ($output) {
1.1172 raeburn 17023: $error = 'recaptcha';
1.1094 raeburn 17024: }
17025: }
1.1234 raeburn 17026: return ($output,$error,$captcha,$version);
1.1094 raeburn 17027: }
17028:
17029: sub captcha_response {
17030: my ($context,$lonhost) = @_;
17031: my ($captcha_chk,$captcha_error);
1.1234 raeburn 17032: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 17033: if ($captcha eq 'original') {
1.1094 raeburn 17034: ($captcha_chk,$captcha_error) = &check_captcha();
17035: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17036: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17037: } else {
17038: $captcha_chk = 1;
17039: }
17040: return ($captcha_chk,$captcha_error);
17041: }
17042:
17043: sub get_captcha_config {
17044: my ($context,$lonhost) = @_;
1.1234 raeburn 17045: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17046: my $hostname = &Apache::lonnet::hostname($lonhost);
17047: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17048: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17049: if ($context eq 'usercreation') {
17050: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17051: if (ref($domconfig{$context}) eq 'HASH') {
17052: $hashtocheck = $domconfig{$context}{'cancreate'};
17053: if (ref($hashtocheck) eq 'HASH') {
17054: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17055: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17056: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17057: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17058: }
17059: if ($privkey && $pubkey) {
17060: $captcha = 'recaptcha';
1.1234 raeburn 17061: $version = $hashtocheck->{'recaptchaversion'};
17062: if ($version ne '2') {
17063: $version = 1;
17064: }
1.1095 raeburn 17065: } else {
17066: $captcha = 'original';
17067: }
17068: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17069: $captcha = 'original';
17070: }
1.1094 raeburn 17071: }
1.1095 raeburn 17072: } else {
17073: $captcha = 'captcha';
17074: }
17075: } elsif ($context eq 'login') {
17076: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17077: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17078: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17079: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17080: if ($privkey && $pubkey) {
17081: $captcha = 'recaptcha';
1.1234 raeburn 17082: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17083: if ($version ne '2') {
17084: $version = 1;
17085: }
1.1095 raeburn 17086: } else {
17087: $captcha = 'original';
1.1094 raeburn 17088: }
1.1095 raeburn 17089: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17090: $captcha = 'original';
1.1094 raeburn 17091: }
17092: }
1.1234 raeburn 17093: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17094: }
17095:
17096: sub create_captcha {
17097: my %captcha_params = &captcha_settings();
17098: my ($output,$maxtries,$tries) = ('',10,0);
17099: while ($tries < $maxtries) {
17100: $tries ++;
17101: my $captcha = Authen::Captcha->new (
17102: output_folder => $captcha_params{'output_dir'},
17103: data_folder => $captcha_params{'db_dir'},
17104: );
17105: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17106:
17107: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17108: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17109: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17110: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17111: '<br />'.
17112: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17113: last;
17114: }
17115: }
17116: return $output;
17117: }
17118:
17119: sub captcha_settings {
17120: my %captcha_params = (
17121: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17122: www_output_dir => "/captchaspool",
17123: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17124: numchars => '5',
17125: );
17126: return %captcha_params;
17127: }
17128:
17129: sub check_captcha {
17130: my ($captcha_chk,$captcha_error);
17131: my $code = $env{'form.code'};
17132: my $md5sum = $env{'form.crypt'};
17133: my %captcha_params = &captcha_settings();
17134: my $captcha = Authen::Captcha->new(
17135: output_folder => $captcha_params{'output_dir'},
17136: data_folder => $captcha_params{'db_dir'},
17137: );
1.1109 raeburn 17138: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17139: my %captcha_hash = (
17140: 0 => 'Code not checked (file error)',
17141: -1 => 'Failed: code expired',
17142: -2 => 'Failed: invalid code (not in database)',
17143: -3 => 'Failed: invalid code (code does not match crypt)',
17144: );
17145: if ($captcha_chk != 1) {
17146: $captcha_error = $captcha_hash{$captcha_chk}
17147: }
17148: return ($captcha_chk,$captcha_error);
17149: }
17150:
17151: sub create_recaptcha {
1.1234 raeburn 17152: my ($pubkey,$version) = @_;
17153: if ($version >= 2) {
17154: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17155: } else {
17156: my $use_ssl;
17157: if ($ENV{'SERVER_PORT'} == 443) {
17158: $use_ssl = 1;
17159: }
17160: my $captcha = Captcha::reCAPTCHA->new;
17161: return $captcha->get_options_setter({theme => 'white'})."\n".
17162: $captcha->get_html($pubkey,undef,$use_ssl).
17163: &mt('If the text is hard to read, [_1] will replace them.',
17164: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17165: '<br /><br />';
17166: }
1.1094 raeburn 17167: }
17168:
17169: sub check_recaptcha {
1.1234 raeburn 17170: my ($privkey,$version) = @_;
1.1094 raeburn 17171: my $captcha_chk;
1.1234 raeburn 17172: if ($version >= 2) {
17173: my $ua = LWP::UserAgent->new;
17174: $ua->timeout(10);
17175: my %info = (
17176: secret => $privkey,
17177: response => $env{'form.g-recaptcha-response'},
17178: remoteip => $ENV{'REMOTE_ADDR'},
17179: );
17180: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17181: if ($response->is_success) {
17182: my $data = JSON::DWIW->from_json($response->decoded_content);
17183: if (ref($data) eq 'HASH') {
17184: if ($data->{'success'}) {
17185: $captcha_chk = 1;
17186: }
17187: }
17188: }
17189: } else {
17190: my $captcha = Captcha::reCAPTCHA->new;
17191: my $captcha_result =
17192: $captcha->check_answer(
17193: $privkey,
17194: $ENV{'REMOTE_ADDR'},
17195: $env{'form.recaptcha_challenge_field'},
17196: $env{'form.recaptcha_response_field'},
17197: );
17198: if ($captcha_result->{is_valid}) {
17199: $captcha_chk = 1;
17200: }
1.1094 raeburn 17201: }
17202: return $captcha_chk;
17203: }
17204:
1.1174 raeburn 17205: sub emailusername_info {
1.1244 raeburn 17206: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 17207: my %titles = &Apache::lonlocal::texthash (
17208: lastname => 'Last Name',
17209: firstname => 'First Name',
17210: institution => 'School/college/university',
17211: location => "School's city, state/province, country",
17212: web => "School's web address",
17213: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 17214: id => 'Student/Employee ID',
1.1174 raeburn 17215: );
17216: return (\@fields,\%titles);
17217: }
17218:
1.1161 raeburn 17219: sub cleanup_html {
17220: my ($incoming) = @_;
17221: my $outgoing;
17222: if ($incoming ne '') {
17223: $outgoing = $incoming;
17224: $outgoing =~ s/;/;/g;
17225: $outgoing =~ s/\#/#/g;
17226: $outgoing =~ s/\&/&/g;
17227: $outgoing =~ s/</</g;
17228: $outgoing =~ s/>/>/g;
17229: $outgoing =~ s/\(/(/g;
17230: $outgoing =~ s/\)/)/g;
17231: $outgoing =~ s/"/"/g;
17232: $outgoing =~ s/'/'/g;
17233: $outgoing =~ s/\$/$/g;
17234: $outgoing =~ s{/}{/}g;
17235: $outgoing =~ s/=/=/g;
17236: $outgoing =~ s/\\/\/g
17237: }
17238: return $outgoing;
17239: }
17240:
1.1190 musolffc 17241: # Checks for critical messages and returns a redirect url if one exists.
17242: # $interval indicates how often to check for messages.
17243: sub critical_redirect {
17244: my ($interval) = @_;
17245: if ((time-$env{'user.criticalcheck.time'})>$interval) {
17246: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17247: $env{'user.name'});
17248: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 17249: my $redirecturl;
1.1190 musolffc 17250: if ($what[0]) {
17251: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17252: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 17253: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17254: return (1, $url);
1.1190 musolffc 17255: }
1.1191 raeburn 17256: }
17257: }
17258: return ();
1.1190 musolffc 17259: }
17260:
1.1174 raeburn 17261: # Use:
17262: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17263: #
17264: ##################################################
17265: # password associated functions #
17266: ##################################################
17267: sub des_keys {
17268: # Make a new key for DES encryption.
17269: # Each key has two parts which are returned separately.
17270: # Please note: Each key must be passed through the &hex function
17271: # before it is output to the web browser. The hex versions cannot
17272: # be used to decrypt.
17273: my @hexstr=('0','1','2','3','4','5','6','7',
17274: '8','9','a','b','c','d','e','f');
17275: my $lkey='';
17276: for (0..7) {
17277: $lkey.=$hexstr[rand(15)];
17278: }
17279: my $ukey='';
17280: for (0..7) {
17281: $ukey.=$hexstr[rand(15)];
17282: }
17283: return ($lkey,$ukey);
17284: }
17285:
17286: sub des_decrypt {
17287: my ($key,$cyphertext) = @_;
17288: my $keybin=pack("H16",$key);
17289: my $cypher;
17290: if ($Crypt::DES::VERSION>=2.03) {
17291: $cypher=new Crypt::DES $keybin;
17292: } else {
17293: $cypher=new DES $keybin;
17294: }
1.1233 raeburn 17295: my $plaintext='';
17296: my $cypherlength = length($cyphertext);
17297: my $numchunks = int($cypherlength/32);
17298: for (my $j=0; $j<$numchunks; $j++) {
17299: my $start = $j*32;
17300: my $cypherblock = substr($cyphertext,$start,32);
17301: my $chunk =
17302: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17303: $chunk .=
17304: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17305: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17306: $plaintext .= $chunk;
17307: }
1.1174 raeburn 17308: return $plaintext;
17309: }
17310:
1.112 bowersj2 17311: 1;
17312: __END__;
1.41 ng 17313:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>