Annotation of loncom/interface/loncommon.pm, revision 1.1257
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1257 ! raeburn 4: # $Id: loncommon.pm,v 1.1256 2016/10/11 22:58:55 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,
5952: $args->{'group'});
5953: } else {
5954: $bodytag .=
5955: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5956: $forcereg,$args->{'group'},
5957: $args->{'bread_crumbs'},
5958: $advtoolsref);
1.920 raeburn 5959: }
1.903 droeschl 5960: }else{
5961: # this is to seperate menu from content when there's no secondary
5962: # menu. Especially needed for public accessible ressources.
5963: $bodytag .= '<hr style="clear:both" />';
5964: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5965: }
1.903 droeschl 5966:
1.235 raeburn 5967: return $bodytag;
1.182 matthew 5968: }
5969:
1.917 raeburn 5970: sub dc_courseid_toggle {
5971: my ($dc_info) = @_;
1.980 raeburn 5972: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5973: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5974: &mt('(More ...)').'</a></span>'.
5975: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5976: }
5977:
1.330 albertel 5978: sub make_attr_string {
5979: my ($register,$attr_ref) = @_;
5980:
5981: if ($attr_ref && !ref($attr_ref)) {
5982: die("addentries Must be a hash ref ".
5983: join(':',caller(1))." ".
5984: join(':',caller(0))." ");
5985: }
5986:
5987: if ($register) {
1.339 albertel 5988: my ($on_load,$on_unload);
5989: foreach my $key (keys(%{$attr_ref})) {
5990: if (lc($key) eq 'onload') {
5991: $on_load.=$attr_ref->{$key}.';';
5992: delete($attr_ref->{$key});
5993:
5994: } elsif (lc($key) eq 'onunload') {
5995: $on_unload.=$attr_ref->{$key}.';';
5996: delete($attr_ref->{$key});
5997: }
5998: }
1.953 droeschl 5999: $attr_ref->{'onload'} = $on_load;
6000: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6001: }
1.339 albertel 6002:
1.330 albertel 6003: my $attr_string;
1.1159 raeburn 6004: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6005: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6006: }
6007: return $attr_string;
6008: }
6009:
6010:
1.182 matthew 6011: ###############################################
1.251 albertel 6012: ###############################################
6013:
6014: =pod
6015:
6016: =item * &endbodytag()
6017:
6018: Returns a uniform footer for LON-CAPA web pages.
6019:
1.635 raeburn 6020: Inputs: 1 - optional reference to an args hash
6021: If in the hash, key for noredirectlink has a value which evaluates to true,
6022: a 'Continue' link is not displayed if the page contains an
6023: internal redirect in the <head></head> section,
6024: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6025:
6026: =cut
6027:
6028: sub endbodytag {
1.635 raeburn 6029: my ($args) = @_;
1.1080 raeburn 6030: my $endbodytag;
6031: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6032: $endbodytag='</body>';
6033: }
1.315 albertel 6034: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6035: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6036: $endbodytag=
6037: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6038: &mt('Continue').'</a>'.
6039: $endbodytag;
6040: }
1.315 albertel 6041: }
1.251 albertel 6042: return $endbodytag;
6043: }
6044:
1.352 albertel 6045: =pod
6046:
6047: =item * &standard_css()
6048:
6049: Returns a style sheet
6050:
6051: Inputs: (all optional)
6052: domain -> force to color decorate a page for a specific
6053: domain
6054: function -> force usage of a specific rolish color scheme
6055: bgcolor -> override the default page bgcolor
6056:
6057: =cut
6058:
1.343 albertel 6059: sub standard_css {
1.345 albertel 6060: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6061: $function = &get_users_function() if (!$function);
6062: my $img = &designparm($function.'.img', $domain);
6063: my $tabbg = &designparm($function.'.tabbg', $domain);
6064: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6065: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6066: #second colour for later usage
1.345 albertel 6067: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6068: my $pgbg_or_bgcolor =
6069: $bgcolor ||
1.352 albertel 6070: &designparm($function.'.pgbg', $domain);
1.382 albertel 6071: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6072: my $alink = &designparm($function.'.alink', $domain);
6073: my $vlink = &designparm($function.'.vlink', $domain);
6074: my $link = &designparm($function.'.link', $domain);
6075:
1.602 albertel 6076: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6077: my $mono = 'monospace';
1.850 bisitz 6078: my $data_table_head = $sidebg;
6079: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6080: my $data_table_dark = '#E0E0E0';
1.470 banghart 6081: my $data_table_darker = '#CCCCCC';
1.349 albertel 6082: my $data_table_highlight = '#FFFF00';
1.352 albertel 6083: my $mail_new = '#FFBB77';
6084: my $mail_new_hover = '#DD9955';
6085: my $mail_read = '#BBBB77';
6086: my $mail_read_hover = '#999944';
6087: my $mail_replied = '#AAAA88';
6088: my $mail_replied_hover = '#888855';
6089: my $mail_other = '#99BBBB';
6090: my $mail_other_hover = '#669999';
1.391 albertel 6091: my $table_header = '#DDDDDD';
1.489 raeburn 6092: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6093: my $lg_border_color = '#C8C8C8';
1.952 onken 6094: my $button_hover = '#BF2317';
1.392 albertel 6095:
1.608 albertel 6096: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6097: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6098: : '0 3px 0 4px';
1.448 albertel 6099:
1.523 albertel 6100:
1.343 albertel 6101: return <<END;
1.947 droeschl 6102:
6103: /* needed for iframe to allow 100% height in FF */
6104: body, html {
6105: margin: 0;
6106: padding: 0 0.5%;
6107: height: 99%; /* to avoid scrollbars */
6108: }
6109:
1.795 www 6110: body {
1.911 bisitz 6111: font-family: $sans;
6112: line-height:130%;
6113: font-size:0.83em;
6114: color:$font;
1.795 www 6115: }
6116:
1.959 onken 6117: a:focus,
6118: a:focus img {
1.795 www 6119: color: red;
6120: }
1.698 harmsja 6121:
1.911 bisitz 6122: form, .inline {
6123: display: inline;
1.795 www 6124: }
1.721 harmsja 6125:
1.795 www 6126: .LC_right {
1.911 bisitz 6127: text-align:right;
1.795 www 6128: }
6129:
6130: .LC_middle {
1.911 bisitz 6131: vertical-align:middle;
1.795 www 6132: }
1.721 harmsja 6133:
1.1130 raeburn 6134: .LC_floatleft {
6135: float: left;
6136: }
6137:
6138: .LC_floatright {
6139: float: right;
6140: }
6141:
1.911 bisitz 6142: .LC_400Box {
6143: width:400px;
6144: }
1.721 harmsja 6145:
1.947 droeschl 6146: .LC_iframecontainer {
6147: width: 98%;
6148: margin: 0;
6149: position: fixed;
6150: top: 8.5em;
6151: bottom: 0;
6152: }
6153:
6154: .LC_iframecontainer iframe{
6155: border: none;
6156: width: 100%;
6157: height: 100%;
6158: }
6159:
1.778 bisitz 6160: .LC_filename {
6161: font-family: $mono;
6162: white-space:pre;
1.921 bisitz 6163: font-size: 120%;
1.778 bisitz 6164: }
6165:
6166: .LC_fileicon {
6167: border: none;
6168: height: 1.3em;
6169: vertical-align: text-bottom;
6170: margin-right: 0.3em;
6171: text-decoration:none;
6172: }
6173:
1.1008 www 6174: .LC_setting {
6175: text-decoration:underline;
6176: }
6177:
1.350 albertel 6178: .LC_error {
6179: color: red;
6180: }
1.795 www 6181:
1.1097 bisitz 6182: .LC_warning {
6183: color: darkorange;
6184: }
6185:
1.457 albertel 6186: .LC_diff_removed {
1.733 bisitz 6187: color: red;
1.394 albertel 6188: }
1.532 albertel 6189:
6190: .LC_info,
1.457 albertel 6191: .LC_success,
6192: .LC_diff_added {
1.350 albertel 6193: color: green;
6194: }
1.795 www 6195:
1.802 bisitz 6196: div.LC_confirm_box {
6197: background-color: #FAFAFA;
6198: border: 1px solid $lg_border_color;
6199: margin-right: 0;
6200: padding: 5px;
6201: }
6202:
6203: div.LC_confirm_box .LC_error img,
6204: div.LC_confirm_box .LC_success img {
6205: vertical-align: middle;
6206: }
6207:
1.1242 raeburn 6208: .LC_maxwidth {
6209: max-width: 100%;
6210: height: auto;
6211: }
6212:
1.1243 raeburn 6213: .LC_textsize_mobile {
6214: \@media only screen and (max-device-width: 480px) {
6215: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6216: }
6217: }
6218:
1.440 albertel 6219: .LC_icon {
1.771 droeschl 6220: border: none;
1.790 droeschl 6221: vertical-align: middle;
1.771 droeschl 6222: }
6223:
1.543 albertel 6224: .LC_docs_spacer {
6225: width: 25px;
6226: height: 1px;
1.771 droeschl 6227: border: none;
1.543 albertel 6228: }
1.346 albertel 6229:
1.532 albertel 6230: .LC_internal_info {
1.735 bisitz 6231: color: #999999;
1.532 albertel 6232: }
6233:
1.794 www 6234: .LC_discussion {
1.1050 www 6235: background: $data_table_dark;
1.911 bisitz 6236: border: 1px solid black;
6237: margin: 2px;
1.794 www 6238: }
6239:
6240: .LC_disc_action_left {
1.1050 www 6241: background: $sidebg;
1.911 bisitz 6242: text-align: left;
1.1050 www 6243: padding: 4px;
6244: margin: 2px;
1.794 www 6245: }
6246:
6247: .LC_disc_action_right {
1.1050 www 6248: background: $sidebg;
1.911 bisitz 6249: text-align: right;
1.1050 www 6250: padding: 4px;
6251: margin: 2px;
1.794 www 6252: }
6253:
6254: .LC_disc_new_item {
1.911 bisitz 6255: background: white;
6256: border: 2px solid red;
1.1050 www 6257: margin: 4px;
6258: padding: 4px;
1.794 www 6259: }
6260:
6261: .LC_disc_old_item {
1.911 bisitz 6262: background: white;
1.1050 www 6263: margin: 4px;
6264: padding: 4px;
1.794 www 6265: }
6266:
1.458 albertel 6267: table.LC_pastsubmission {
6268: border: 1px solid black;
6269: margin: 2px;
6270: }
6271:
1.924 bisitz 6272: table#LC_menubuttons {
1.345 albertel 6273: width: 100%;
6274: background: $pgbg;
1.392 albertel 6275: border: 2px;
1.402 albertel 6276: border-collapse: separate;
1.803 bisitz 6277: padding: 0;
1.345 albertel 6278: }
1.392 albertel 6279:
1.801 tempelho 6280: table#LC_title_bar a {
6281: color: $fontmenu;
6282: }
1.836 bisitz 6283:
1.807 droeschl 6284: table#LC_title_bar {
1.819 tempelho 6285: clear: both;
1.836 bisitz 6286: display: none;
1.807 droeschl 6287: }
6288:
1.795 www 6289: table#LC_title_bar,
1.933 droeschl 6290: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6291: table#LC_title_bar.LC_with_remote {
1.359 albertel 6292: width: 100%;
1.392 albertel 6293: border-color: $pgbg;
6294: border-style: solid;
6295: border-width: $border;
1.379 albertel 6296: background: $pgbg;
1.801 tempelho 6297: color: $fontmenu;
1.392 albertel 6298: border-collapse: collapse;
1.803 bisitz 6299: padding: 0;
1.819 tempelho 6300: margin: 0;
1.359 albertel 6301: }
1.795 www 6302:
1.933 droeschl 6303: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6304: margin: 0;
6305: padding: 0;
1.933 droeschl 6306: position: relative;
6307: list-style: none;
1.913 droeschl 6308: }
1.933 droeschl 6309: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6310: display: inline;
6311: }
1.933 droeschl 6312:
6313: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6314: padding: 0;
1.933 droeschl 6315: margin: 0;
6316: float: left;
1.913 droeschl 6317: }
1.933 droeschl 6318: .LC_breadcrumb_tools_tools {
6319: padding: 0;
6320: margin: 0;
1.913 droeschl 6321: float: right;
6322: }
6323:
1.1240 raeburn 6324: .LC_placement_prog {
6325: padding-right: 20px;
6326: font-weight: bold;
6327: font-size: 90%;
6328: }
6329:
1.359 albertel 6330: table#LC_title_bar td {
6331: background: $tabbg;
6332: }
1.795 www 6333:
1.911 bisitz 6334: table#LC_menubuttons img {
1.803 bisitz 6335: border: none;
1.346 albertel 6336: }
1.795 www 6337:
1.842 droeschl 6338: .LC_breadcrumbs_component {
1.911 bisitz 6339: float: right;
6340: margin: 0 1em;
1.357 albertel 6341: }
1.842 droeschl 6342: .LC_breadcrumbs_component img {
1.911 bisitz 6343: vertical-align: middle;
1.777 tempelho 6344: }
1.795 www 6345:
1.1243 raeburn 6346: .LC_breadcrumbs_hoverable {
6347: background: $sidebg;
6348: }
6349:
1.383 albertel 6350: td.LC_table_cell_checkbox {
6351: text-align: center;
6352: }
1.795 www 6353:
6354: .LC_fontsize_small {
1.911 bisitz 6355: font-size: 70%;
1.705 tempelho 6356: }
6357:
1.844 bisitz 6358: #LC_breadcrumbs {
1.911 bisitz 6359: clear:both;
6360: background: $sidebg;
6361: border-bottom: 1px solid $lg_border_color;
6362: line-height: 2.5em;
1.933 droeschl 6363: overflow: hidden;
1.911 bisitz 6364: margin: 0;
6365: padding: 0;
1.995 raeburn 6366: text-align: left;
1.819 tempelho 6367: }
1.862 bisitz 6368:
1.1098 bisitz 6369: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6370: clear:both;
6371: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6372: border: 1px solid $sidebg;
1.1098 bisitz 6373: margin: 0 0 10px 0;
1.966 bisitz 6374: padding: 3px;
1.995 raeburn 6375: text-align: left;
1.822 bisitz 6376: }
6377:
1.795 www 6378: .LC_fontsize_medium {
1.911 bisitz 6379: font-size: 85%;
1.705 tempelho 6380: }
6381:
1.795 www 6382: .LC_fontsize_large {
1.911 bisitz 6383: font-size: 120%;
1.705 tempelho 6384: }
6385:
1.346 albertel 6386: .LC_menubuttons_inline_text {
6387: color: $font;
1.698 harmsja 6388: font-size: 90%;
1.701 harmsja 6389: padding-left:3px;
1.346 albertel 6390: }
6391:
1.934 droeschl 6392: .LC_menubuttons_inline_text img{
6393: vertical-align: middle;
6394: }
6395:
1.1051 www 6396: li.LC_menubuttons_inline_text img {
1.951 onken 6397: cursor:pointer;
1.1002 droeschl 6398: text-decoration: none;
1.951 onken 6399: }
6400:
1.526 www 6401: .LC_menubuttons_link {
6402: text-decoration: none;
6403: }
1.795 www 6404:
1.522 albertel 6405: .LC_menubuttons_category {
1.521 www 6406: color: $font;
1.526 www 6407: background: $pgbg;
1.521 www 6408: font-size: larger;
6409: font-weight: bold;
6410: }
6411:
1.346 albertel 6412: td.LC_menubuttons_text {
1.911 bisitz 6413: color: $font;
1.346 albertel 6414: }
1.706 harmsja 6415:
1.346 albertel 6416: .LC_current_location {
6417: background: $tabbg;
6418: }
1.795 www 6419:
1.938 bisitz 6420: table.LC_data_table {
1.347 albertel 6421: border: 1px solid #000000;
1.402 albertel 6422: border-collapse: separate;
1.426 albertel 6423: border-spacing: 1px;
1.610 albertel 6424: background: $pgbg;
1.347 albertel 6425: }
1.795 www 6426:
1.422 albertel 6427: .LC_data_table_dense {
6428: font-size: small;
6429: }
1.795 www 6430:
1.507 raeburn 6431: table.LC_nested_outer {
6432: border: 1px solid #000000;
1.589 raeburn 6433: border-collapse: collapse;
1.803 bisitz 6434: border-spacing: 0;
1.507 raeburn 6435: width: 100%;
6436: }
1.795 www 6437:
1.879 raeburn 6438: table.LC_innerpickbox,
1.507 raeburn 6439: table.LC_nested {
1.803 bisitz 6440: border: none;
1.589 raeburn 6441: border-collapse: collapse;
1.803 bisitz 6442: border-spacing: 0;
1.507 raeburn 6443: width: 100%;
6444: }
1.795 www 6445:
1.911 bisitz 6446: table.LC_data_table tr th,
6447: table.LC_calendar tr th,
1.879 raeburn 6448: table.LC_prior_tries tr th,
6449: table.LC_innerpickbox tr th {
1.349 albertel 6450: font-weight: bold;
6451: background-color: $data_table_head;
1.801 tempelho 6452: color:$fontmenu;
1.701 harmsja 6453: font-size:90%;
1.347 albertel 6454: }
1.795 www 6455:
1.879 raeburn 6456: table.LC_innerpickbox tr th,
6457: table.LC_innerpickbox tr td {
6458: vertical-align: top;
6459: }
6460:
1.711 raeburn 6461: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6462: background-color: #CCCCCC;
1.711 raeburn 6463: font-weight: bold;
6464: text-align: left;
6465: }
1.795 www 6466:
1.912 bisitz 6467: table.LC_data_table tr.LC_odd_row > td {
6468: background-color: $data_table_light;
6469: padding: 2px;
6470: vertical-align: top;
6471: }
6472:
1.809 bisitz 6473: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6474: background-color: $data_table_light;
1.912 bisitz 6475: vertical-align: top;
6476: }
6477:
6478: table.LC_data_table tr.LC_even_row > td {
6479: background-color: $data_table_dark;
1.425 albertel 6480: padding: 2px;
1.900 bisitz 6481: vertical-align: top;
1.347 albertel 6482: }
1.795 www 6483:
1.809 bisitz 6484: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6485: background-color: $data_table_dark;
1.900 bisitz 6486: vertical-align: top;
1.347 albertel 6487: }
1.795 www 6488:
1.425 albertel 6489: table.LC_data_table tr.LC_data_table_highlight td {
6490: background-color: $data_table_darker;
6491: }
1.795 www 6492:
1.639 raeburn 6493: table.LC_data_table tr td.LC_leftcol_header {
6494: background-color: $data_table_head;
6495: font-weight: bold;
6496: }
1.795 www 6497:
1.451 albertel 6498: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6499: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6500: font-weight: bold;
6501: font-style: italic;
6502: text-align: center;
6503: padding: 8px;
1.347 albertel 6504: }
1.795 www 6505:
1.1114 raeburn 6506: table.LC_data_table tr.LC_empty_row td,
6507: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6508: background-color: $sidebg;
6509: }
6510:
6511: table.LC_nested tr.LC_empty_row td {
6512: background-color: #FFFFFF;
6513: }
6514:
1.890 droeschl 6515: table.LC_caption {
6516: }
6517:
1.507 raeburn 6518: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6519: padding: 4ex
6520: }
1.795 www 6521:
1.507 raeburn 6522: table.LC_nested_outer tr th {
6523: font-weight: bold;
1.801 tempelho 6524: color:$fontmenu;
1.507 raeburn 6525: background-color: $data_table_head;
1.701 harmsja 6526: font-size: small;
1.507 raeburn 6527: border-bottom: 1px solid #000000;
6528: }
1.795 www 6529:
1.507 raeburn 6530: table.LC_nested_outer tr td.LC_subheader {
6531: background-color: $data_table_head;
6532: font-weight: bold;
6533: font-size: small;
6534: border-bottom: 1px solid #000000;
6535: text-align: right;
1.451 albertel 6536: }
1.795 www 6537:
1.507 raeburn 6538: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6539: background-color: #CCCCCC;
1.451 albertel 6540: font-weight: bold;
6541: font-size: small;
1.507 raeburn 6542: text-align: center;
6543: }
1.795 www 6544:
1.589 raeburn 6545: table.LC_nested tr.LC_info_row td.LC_left_item,
6546: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6547: text-align: left;
1.451 albertel 6548: }
1.795 www 6549:
1.507 raeburn 6550: table.LC_nested td {
1.735 bisitz 6551: background-color: #FFFFFF;
1.451 albertel 6552: font-size: small;
1.507 raeburn 6553: }
1.795 www 6554:
1.507 raeburn 6555: table.LC_nested_outer tr th.LC_right_item,
6556: table.LC_nested tr.LC_info_row td.LC_right_item,
6557: table.LC_nested tr.LC_odd_row td.LC_right_item,
6558: table.LC_nested tr td.LC_right_item {
1.451 albertel 6559: text-align: right;
6560: }
6561:
1.507 raeburn 6562: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6563: background-color: #EEEEEE;
1.451 albertel 6564: }
6565:
1.473 raeburn 6566: table.LC_createuser {
6567: }
6568:
6569: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6570: font-size: small;
1.473 raeburn 6571: }
6572:
6573: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6574: background-color: #CCCCCC;
1.473 raeburn 6575: font-weight: bold;
6576: text-align: center;
6577: }
6578:
1.349 albertel 6579: table.LC_calendar {
6580: border: 1px solid #000000;
6581: border-collapse: collapse;
1.917 raeburn 6582: width: 98%;
1.349 albertel 6583: }
1.795 www 6584:
1.349 albertel 6585: table.LC_calendar_pickdate {
6586: font-size: xx-small;
6587: }
1.795 www 6588:
1.349 albertel 6589: table.LC_calendar tr td {
6590: border: 1px solid #000000;
6591: vertical-align: top;
1.917 raeburn 6592: width: 14%;
1.349 albertel 6593: }
1.795 www 6594:
1.349 albertel 6595: table.LC_calendar tr td.LC_calendar_day_empty {
6596: background-color: $data_table_dark;
6597: }
1.795 www 6598:
1.779 bisitz 6599: table.LC_calendar tr td.LC_calendar_day_current {
6600: background-color: $data_table_highlight;
1.777 tempelho 6601: }
1.795 www 6602:
1.938 bisitz 6603: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6604: background-color: $mail_new;
6605: }
1.795 www 6606:
1.938 bisitz 6607: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6608: background-color: $mail_new_hover;
6609: }
1.795 www 6610:
1.938 bisitz 6611: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6612: background-color: $mail_read;
6613: }
1.795 www 6614:
1.938 bisitz 6615: /*
6616: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6617: background-color: $mail_read_hover;
6618: }
1.938 bisitz 6619: */
1.795 www 6620:
1.938 bisitz 6621: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6622: background-color: $mail_replied;
6623: }
1.795 www 6624:
1.938 bisitz 6625: /*
6626: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6627: background-color: $mail_replied_hover;
6628: }
1.938 bisitz 6629: */
1.795 www 6630:
1.938 bisitz 6631: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6632: background-color: $mail_other;
6633: }
1.795 www 6634:
1.938 bisitz 6635: /*
6636: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6637: background-color: $mail_other_hover;
6638: }
1.938 bisitz 6639: */
1.494 raeburn 6640:
1.777 tempelho 6641: table.LC_data_table tr > td.LC_browser_file,
6642: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6643: background: #AAEE77;
1.389 albertel 6644: }
1.795 www 6645:
1.777 tempelho 6646: table.LC_data_table tr > td.LC_browser_file_locked,
6647: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6648: background: #FFAA99;
1.387 albertel 6649: }
1.795 www 6650:
1.777 tempelho 6651: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6652: background: #888888;
1.779 bisitz 6653: }
1.795 www 6654:
1.777 tempelho 6655: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6656: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6657: background: #F8F866;
1.777 tempelho 6658: }
1.795 www 6659:
1.696 bisitz 6660: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6661: background: #E0E8FF;
1.387 albertel 6662: }
1.696 bisitz 6663:
1.707 bisitz 6664: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6665: /* background: #77FF77; */
1.707 bisitz 6666: }
1.795 www 6667:
1.707 bisitz 6668: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6669: border-right: 8px solid #FFFF77;
1.707 bisitz 6670: }
1.795 www 6671:
1.707 bisitz 6672: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6673: border-right: 8px solid #FFAA77;
1.707 bisitz 6674: }
1.795 www 6675:
1.707 bisitz 6676: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6677: border-right: 8px solid #FF7777;
1.707 bisitz 6678: }
1.795 www 6679:
1.707 bisitz 6680: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6681: border-right: 8px solid #AAFF77;
1.707 bisitz 6682: }
1.795 www 6683:
1.707 bisitz 6684: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6685: border-right: 8px solid #11CC55;
1.707 bisitz 6686: }
6687:
1.388 albertel 6688: span.LC_current_location {
1.701 harmsja 6689: font-size:larger;
1.388 albertel 6690: background: $pgbg;
6691: }
1.387 albertel 6692:
1.1029 www 6693: span.LC_current_nav_location {
6694: font-weight:bold;
6695: background: $sidebg;
6696: }
6697:
1.395 albertel 6698: span.LC_parm_menu_item {
6699: font-size: larger;
6700: }
1.795 www 6701:
1.395 albertel 6702: span.LC_parm_scope_all {
6703: color: red;
6704: }
1.795 www 6705:
1.395 albertel 6706: span.LC_parm_scope_folder {
6707: color: green;
6708: }
1.795 www 6709:
1.395 albertel 6710: span.LC_parm_scope_resource {
6711: color: orange;
6712: }
1.795 www 6713:
1.395 albertel 6714: span.LC_parm_part {
6715: color: blue;
6716: }
1.795 www 6717:
1.911 bisitz 6718: span.LC_parm_folder,
6719: span.LC_parm_symb {
1.395 albertel 6720: font-size: x-small;
6721: font-family: $mono;
6722: color: #AAAAAA;
6723: }
6724:
1.977 bisitz 6725: ul.LC_parm_parmlist li {
6726: display: inline-block;
6727: padding: 0.3em 0.8em;
6728: vertical-align: top;
6729: width: 150px;
6730: border-top:1px solid $lg_border_color;
6731: }
6732:
1.795 www 6733: td.LC_parm_overview_level_menu,
6734: td.LC_parm_overview_map_menu,
6735: td.LC_parm_overview_parm_selectors,
6736: td.LC_parm_overview_restrictions {
1.396 albertel 6737: border: 1px solid black;
6738: border-collapse: collapse;
6739: }
1.795 www 6740:
1.396 albertel 6741: table.LC_parm_overview_restrictions td {
6742: border-width: 1px 4px 1px 4px;
6743: border-style: solid;
6744: border-color: $pgbg;
6745: text-align: center;
6746: }
1.795 www 6747:
1.396 albertel 6748: table.LC_parm_overview_restrictions th {
6749: background: $tabbg;
6750: border-width: 1px 4px 1px 4px;
6751: border-style: solid;
6752: border-color: $pgbg;
6753: }
1.795 www 6754:
1.398 albertel 6755: table#LC_helpmenu {
1.803 bisitz 6756: border: none;
1.398 albertel 6757: height: 55px;
1.803 bisitz 6758: border-spacing: 0;
1.398 albertel 6759: }
6760:
6761: table#LC_helpmenu fieldset legend {
6762: font-size: larger;
6763: }
1.795 www 6764:
1.397 albertel 6765: table#LC_helpmenu_links {
6766: width: 100%;
6767: border: 1px solid black;
6768: background: $pgbg;
1.803 bisitz 6769: padding: 0;
1.397 albertel 6770: border-spacing: 1px;
6771: }
1.795 www 6772:
1.397 albertel 6773: table#LC_helpmenu_links tr td {
6774: padding: 1px;
6775: background: $tabbg;
1.399 albertel 6776: text-align: center;
6777: font-weight: bold;
1.397 albertel 6778: }
1.396 albertel 6779:
1.795 www 6780: table#LC_helpmenu_links a:link,
6781: table#LC_helpmenu_links a:visited,
1.397 albertel 6782: table#LC_helpmenu_links a:active {
6783: text-decoration: none;
6784: color: $font;
6785: }
1.795 www 6786:
1.397 albertel 6787: table#LC_helpmenu_links a:hover {
6788: text-decoration: underline;
6789: color: $vlink;
6790: }
1.396 albertel 6791:
1.417 albertel 6792: .LC_chrt_popup_exists {
6793: border: 1px solid #339933;
6794: margin: -1px;
6795: }
1.795 www 6796:
1.417 albertel 6797: .LC_chrt_popup_up {
6798: border: 1px solid yellow;
6799: margin: -1px;
6800: }
1.795 www 6801:
1.417 albertel 6802: .LC_chrt_popup {
6803: border: 1px solid #8888FF;
6804: background: #CCCCFF;
6805: }
1.795 www 6806:
1.421 albertel 6807: table.LC_pick_box {
6808: border-collapse: separate;
6809: background: white;
6810: border: 1px solid black;
6811: border-spacing: 1px;
6812: }
1.795 www 6813:
1.421 albertel 6814: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6815: background: $sidebg;
1.421 albertel 6816: font-weight: bold;
1.900 bisitz 6817: text-align: left;
1.740 bisitz 6818: vertical-align: top;
1.421 albertel 6819: width: 184px;
6820: padding: 8px;
6821: }
1.795 www 6822:
1.579 raeburn 6823: table.LC_pick_box td.LC_pick_box_value {
6824: text-align: left;
6825: padding: 8px;
6826: }
1.795 www 6827:
1.579 raeburn 6828: table.LC_pick_box td.LC_pick_box_select {
6829: text-align: left;
6830: padding: 8px;
6831: }
1.795 www 6832:
1.424 albertel 6833: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6834: padding: 0;
1.421 albertel 6835: height: 1px;
6836: background: black;
6837: }
1.795 www 6838:
1.421 albertel 6839: table.LC_pick_box td.LC_pick_box_submit {
6840: text-align: right;
6841: }
1.795 www 6842:
1.579 raeburn 6843: table.LC_pick_box td.LC_evenrow_value {
6844: text-align: left;
6845: padding: 8px;
6846: background-color: $data_table_light;
6847: }
1.795 www 6848:
1.579 raeburn 6849: table.LC_pick_box td.LC_oddrow_value {
6850: text-align: left;
6851: padding: 8px;
6852: background-color: $data_table_light;
6853: }
1.795 www 6854:
1.579 raeburn 6855: span.LC_helpform_receipt_cat {
6856: font-weight: bold;
6857: }
1.795 www 6858:
1.424 albertel 6859: table.LC_group_priv_box {
6860: background: white;
6861: border: 1px solid black;
6862: border-spacing: 1px;
6863: }
1.795 www 6864:
1.424 albertel 6865: table.LC_group_priv_box td.LC_pick_box_title {
6866: background: $tabbg;
6867: font-weight: bold;
6868: text-align: right;
6869: width: 184px;
6870: }
1.795 www 6871:
1.424 albertel 6872: table.LC_group_priv_box td.LC_groups_fixed {
6873: background: $data_table_light;
6874: text-align: center;
6875: }
1.795 www 6876:
1.424 albertel 6877: table.LC_group_priv_box td.LC_groups_optional {
6878: background: $data_table_dark;
6879: text-align: center;
6880: }
1.795 www 6881:
1.424 albertel 6882: table.LC_group_priv_box td.LC_groups_functionality {
6883: background: $data_table_darker;
6884: text-align: center;
6885: font-weight: bold;
6886: }
1.795 www 6887:
1.424 albertel 6888: table.LC_group_priv td {
6889: text-align: left;
1.803 bisitz 6890: padding: 0;
1.424 albertel 6891: }
6892:
6893: .LC_navbuttons {
6894: margin: 2ex 0ex 2ex 0ex;
6895: }
1.795 www 6896:
1.423 albertel 6897: .LC_topic_bar {
6898: font-weight: bold;
6899: background: $tabbg;
1.918 wenzelju 6900: margin: 1em 0em 1em 2em;
1.805 bisitz 6901: padding: 3px;
1.918 wenzelju 6902: font-size: 1.2em;
1.423 albertel 6903: }
1.795 www 6904:
1.423 albertel 6905: .LC_topic_bar span {
1.918 wenzelju 6906: left: 0.5em;
6907: position: absolute;
1.423 albertel 6908: vertical-align: middle;
1.918 wenzelju 6909: font-size: 1.2em;
1.423 albertel 6910: }
1.795 www 6911:
1.423 albertel 6912: table.LC_course_group_status {
6913: margin: 20px;
6914: }
1.795 www 6915:
1.423 albertel 6916: table.LC_status_selector td {
6917: vertical-align: top;
6918: text-align: center;
1.424 albertel 6919: padding: 4px;
6920: }
1.795 www 6921:
1.599 albertel 6922: div.LC_feedback_link {
1.616 albertel 6923: clear: both;
1.829 kalberla 6924: background: $sidebg;
1.779 bisitz 6925: width: 100%;
1.829 kalberla 6926: padding-bottom: 10px;
6927: border: 1px $tabbg solid;
1.833 kalberla 6928: height: 22px;
6929: line-height: 22px;
6930: padding-top: 5px;
6931: }
6932:
6933: div.LC_feedback_link img {
6934: height: 22px;
1.867 kalberla 6935: vertical-align:middle;
1.829 kalberla 6936: }
6937:
1.911 bisitz 6938: div.LC_feedback_link a {
1.829 kalberla 6939: text-decoration: none;
1.489 raeburn 6940: }
1.795 www 6941:
1.867 kalberla 6942: div.LC_comblock {
1.911 bisitz 6943: display:inline;
1.867 kalberla 6944: color:$font;
6945: font-size:90%;
6946: }
6947:
6948: div.LC_feedback_link div.LC_comblock {
6949: padding-left:5px;
6950: }
6951:
6952: div.LC_feedback_link div.LC_comblock a {
6953: color:$font;
6954: }
6955:
1.489 raeburn 6956: span.LC_feedback_link {
1.858 bisitz 6957: /* background: $feedback_link_bg; */
1.599 albertel 6958: font-size: larger;
6959: }
1.795 www 6960:
1.599 albertel 6961: span.LC_message_link {
1.858 bisitz 6962: /* background: $feedback_link_bg; */
1.599 albertel 6963: font-size: larger;
6964: position: absolute;
6965: right: 1em;
1.489 raeburn 6966: }
1.421 albertel 6967:
1.515 albertel 6968: table.LC_prior_tries {
1.524 albertel 6969: border: 1px solid #000000;
6970: border-collapse: separate;
6971: border-spacing: 1px;
1.515 albertel 6972: }
1.523 albertel 6973:
1.515 albertel 6974: table.LC_prior_tries td {
1.524 albertel 6975: padding: 2px;
1.515 albertel 6976: }
1.523 albertel 6977:
6978: .LC_answer_correct {
1.795 www 6979: background: lightgreen;
6980: color: darkgreen;
6981: padding: 6px;
1.523 albertel 6982: }
1.795 www 6983:
1.523 albertel 6984: .LC_answer_charged_try {
1.797 www 6985: background: #FFAAAA;
1.795 www 6986: color: darkred;
6987: padding: 6px;
1.523 albertel 6988: }
1.795 www 6989:
1.779 bisitz 6990: .LC_answer_not_charged_try,
1.523 albertel 6991: .LC_answer_no_grade,
6992: .LC_answer_late {
1.795 www 6993: background: lightyellow;
1.523 albertel 6994: color: black;
1.795 www 6995: padding: 6px;
1.523 albertel 6996: }
1.795 www 6997:
1.523 albertel 6998: .LC_answer_previous {
1.795 www 6999: background: lightblue;
7000: color: darkblue;
7001: padding: 6px;
1.523 albertel 7002: }
1.795 www 7003:
1.779 bisitz 7004: .LC_answer_no_message {
1.777 tempelho 7005: background: #FFFFFF;
7006: color: black;
1.795 www 7007: padding: 6px;
1.779 bisitz 7008: }
1.795 www 7009:
1.779 bisitz 7010: .LC_answer_unknown {
7011: background: orange;
7012: color: black;
1.795 www 7013: padding: 6px;
1.777 tempelho 7014: }
1.795 www 7015:
1.529 albertel 7016: span.LC_prior_numerical,
7017: span.LC_prior_string,
7018: span.LC_prior_custom,
7019: span.LC_prior_reaction,
7020: span.LC_prior_math {
1.925 bisitz 7021: font-family: $mono;
1.523 albertel 7022: white-space: pre;
7023: }
7024:
1.525 albertel 7025: span.LC_prior_string {
1.925 bisitz 7026: font-family: $mono;
1.525 albertel 7027: white-space: pre;
7028: }
7029:
1.523 albertel 7030: table.LC_prior_option {
7031: width: 100%;
7032: border-collapse: collapse;
7033: }
1.795 www 7034:
1.911 bisitz 7035: table.LC_prior_rank,
1.795 www 7036: table.LC_prior_match {
1.528 albertel 7037: border-collapse: collapse;
7038: }
1.795 www 7039:
1.528 albertel 7040: table.LC_prior_option tr td,
7041: table.LC_prior_rank tr td,
7042: table.LC_prior_match tr td {
1.524 albertel 7043: border: 1px solid #000000;
1.515 albertel 7044: }
7045:
1.855 bisitz 7046: .LC_nobreak {
1.544 albertel 7047: white-space: nowrap;
1.519 raeburn 7048: }
7049:
1.576 raeburn 7050: span.LC_cusr_emph {
7051: font-style: italic;
7052: }
7053:
1.633 raeburn 7054: span.LC_cusr_subheading {
7055: font-weight: normal;
7056: font-size: 85%;
7057: }
7058:
1.861 bisitz 7059: div.LC_docs_entry_move {
1.859 bisitz 7060: border: 1px solid #BBBBBB;
1.545 albertel 7061: background: #DDDDDD;
1.861 bisitz 7062: width: 22px;
1.859 bisitz 7063: padding: 1px;
7064: margin: 0;
1.545 albertel 7065: }
7066:
1.861 bisitz 7067: table.LC_data_table tr > td.LC_docs_entry_commands,
7068: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7069: font-size: x-small;
7070: }
1.795 www 7071:
1.861 bisitz 7072: .LC_docs_entry_parameter {
7073: white-space: nowrap;
7074: }
7075:
1.544 albertel 7076: .LC_docs_copy {
1.545 albertel 7077: color: #000099;
1.544 albertel 7078: }
1.795 www 7079:
1.544 albertel 7080: .LC_docs_cut {
1.545 albertel 7081: color: #550044;
1.544 albertel 7082: }
1.795 www 7083:
1.544 albertel 7084: .LC_docs_rename {
1.545 albertel 7085: color: #009900;
1.544 albertel 7086: }
1.795 www 7087:
1.544 albertel 7088: .LC_docs_remove {
1.545 albertel 7089: color: #990000;
7090: }
7091:
1.547 albertel 7092: .LC_docs_reinit_warn,
7093: .LC_docs_ext_edit {
7094: font-size: x-small;
7095: }
7096:
1.545 albertel 7097: table.LC_docs_adddocs td,
7098: table.LC_docs_adddocs th {
7099: border: 1px solid #BBBBBB;
7100: padding: 4px;
7101: background: #DDDDDD;
1.543 albertel 7102: }
7103:
1.584 albertel 7104: table.LC_sty_begin {
7105: background: #BBFFBB;
7106: }
1.795 www 7107:
1.584 albertel 7108: table.LC_sty_end {
7109: background: #FFBBBB;
7110: }
7111:
1.589 raeburn 7112: table.LC_double_column {
1.803 bisitz 7113: border-width: 0;
1.589 raeburn 7114: border-collapse: collapse;
7115: width: 100%;
7116: padding: 2px;
7117: }
7118:
7119: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7120: top: 2px;
1.589 raeburn 7121: left: 2px;
7122: width: 47%;
7123: vertical-align: top;
7124: }
7125:
7126: table.LC_double_column tr td.LC_right_col {
7127: top: 2px;
1.779 bisitz 7128: right: 2px;
1.589 raeburn 7129: width: 47%;
7130: vertical-align: top;
7131: }
7132:
1.591 raeburn 7133: div.LC_left_float {
7134: float: left;
7135: padding-right: 5%;
1.597 albertel 7136: padding-bottom: 4px;
1.591 raeburn 7137: }
7138:
7139: div.LC_clear_float_header {
1.597 albertel 7140: padding-bottom: 2px;
1.591 raeburn 7141: }
7142:
7143: div.LC_clear_float_footer {
1.597 albertel 7144: padding-top: 10px;
1.591 raeburn 7145: clear: both;
7146: }
7147:
1.597 albertel 7148: div.LC_grade_show_user {
1.941 bisitz 7149: /* border-left: 5px solid $sidebg; */
7150: border-top: 5px solid #000000;
7151: margin: 50px 0 0 0;
1.936 bisitz 7152: padding: 15px 0 5px 10px;
1.597 albertel 7153: }
1.795 www 7154:
1.936 bisitz 7155: div.LC_grade_show_user_odd_row {
1.941 bisitz 7156: /* border-left: 5px solid #000000; */
7157: }
7158:
7159: div.LC_grade_show_user div.LC_Box {
7160: margin-right: 50px;
1.597 albertel 7161: }
7162:
7163: div.LC_grade_submissions,
7164: div.LC_grade_message_center,
1.936 bisitz 7165: div.LC_grade_info_links {
1.597 albertel 7166: margin: 5px;
7167: width: 99%;
7168: background: #FFFFFF;
7169: }
1.795 www 7170:
1.597 albertel 7171: div.LC_grade_submissions_header,
1.936 bisitz 7172: div.LC_grade_message_center_header {
1.705 tempelho 7173: font-weight: bold;
7174: font-size: large;
1.597 albertel 7175: }
1.795 www 7176:
1.597 albertel 7177: div.LC_grade_submissions_body,
1.936 bisitz 7178: div.LC_grade_message_center_body {
1.597 albertel 7179: border: 1px solid black;
7180: width: 99%;
7181: background: #FFFFFF;
7182: }
1.795 www 7183:
1.613 albertel 7184: table.LC_scantron_action {
7185: width: 100%;
7186: }
1.795 www 7187:
1.613 albertel 7188: table.LC_scantron_action tr th {
1.698 harmsja 7189: font-weight:bold;
7190: font-style:normal;
1.613 albertel 7191: }
1.795 www 7192:
1.779 bisitz 7193: .LC_edit_problem_header,
1.614 albertel 7194: div.LC_edit_problem_footer {
1.705 tempelho 7195: font-weight: normal;
7196: font-size: medium;
1.602 albertel 7197: margin: 2px;
1.1060 bisitz 7198: background-color: $sidebg;
1.600 albertel 7199: }
1.795 www 7200:
1.600 albertel 7201: div.LC_edit_problem_header,
1.602 albertel 7202: div.LC_edit_problem_header div,
1.614 albertel 7203: div.LC_edit_problem_footer,
7204: div.LC_edit_problem_footer div,
1.602 albertel 7205: div.LC_edit_problem_editxml_header,
7206: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7207: z-index: 100;
1.600 albertel 7208: }
1.795 www 7209:
1.600 albertel 7210: div.LC_edit_problem_header_title {
1.705 tempelho 7211: font-weight: bold;
7212: font-size: larger;
1.602 albertel 7213: background: $tabbg;
7214: padding: 3px;
1.1060 bisitz 7215: margin: 0 0 5px 0;
1.602 albertel 7216: }
1.795 www 7217:
1.602 albertel 7218: table.LC_edit_problem_header_title {
7219: width: 100%;
1.600 albertel 7220: background: $tabbg;
1.602 albertel 7221: }
7222:
1.1205 golterma 7223: div.LC_edit_actionbar {
7224: background-color: $sidebg;
1.1218 droeschl 7225: margin: 0;
7226: padding: 0;
7227: line-height: 200%;
1.602 albertel 7228: }
1.795 www 7229:
1.1218 droeschl 7230: div.LC_edit_actionbar div{
7231: padding: 0;
7232: margin: 0;
7233: display: inline-block;
1.600 albertel 7234: }
1.795 www 7235:
1.1124 bisitz 7236: .LC_edit_opt {
7237: padding-left: 1em;
7238: white-space: nowrap;
7239: }
7240:
1.1152 golterma 7241: .LC_edit_problem_latexhelper{
7242: text-align: right;
7243: }
7244:
7245: #LC_edit_problem_colorful div{
7246: margin-left: 40px;
7247: }
7248:
1.1205 golterma 7249: #LC_edit_problem_codemirror div{
7250: margin-left: 0px;
7251: }
7252:
1.911 bisitz 7253: img.stift {
1.803 bisitz 7254: border-width: 0;
7255: vertical-align: middle;
1.677 riegler 7256: }
1.680 riegler 7257:
1.923 bisitz 7258: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7259: vertical-align: top;
1.777 tempelho 7260: }
1.795 www 7261:
1.716 raeburn 7262: div.LC_createcourse {
1.911 bisitz 7263: margin: 10px 10px 10px 10px;
1.716 raeburn 7264: }
7265:
1.917 raeburn 7266: .LC_dccid {
1.1130 raeburn 7267: float: right;
1.917 raeburn 7268: margin: 0.2em 0 0 0;
7269: padding: 0;
7270: font-size: 90%;
7271: display:none;
7272: }
7273:
1.897 wenzelju 7274: ol.LC_primary_menu a:hover,
1.721 harmsja 7275: ol#LC_MenuBreadcrumbs a:hover,
7276: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7277: ul#LC_secondary_menu a:hover,
1.721 harmsja 7278: .LC_FormSectionClearButton input:hover
1.795 www 7279: ul.LC_TabContent li:hover a {
1.952 onken 7280: color:$button_hover;
1.911 bisitz 7281: text-decoration:none;
1.693 droeschl 7282: }
7283:
1.779 bisitz 7284: h1 {
1.911 bisitz 7285: padding: 0;
7286: line-height:130%;
1.693 droeschl 7287: }
1.698 harmsja 7288:
1.911 bisitz 7289: h2,
7290: h3,
7291: h4,
7292: h5,
7293: h6 {
7294: margin: 5px 0 5px 0;
7295: padding: 0;
7296: line-height:130%;
1.693 droeschl 7297: }
1.795 www 7298:
7299: .LC_hcell {
1.911 bisitz 7300: padding:3px 15px 3px 15px;
7301: margin: 0;
7302: background-color:$tabbg;
7303: color:$fontmenu;
7304: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7305: }
1.795 www 7306:
1.840 bisitz 7307: .LC_Box > .LC_hcell {
1.911 bisitz 7308: margin: 0 -10px 10px -10px;
1.835 bisitz 7309: }
7310:
1.721 harmsja 7311: .LC_noBorder {
1.911 bisitz 7312: border: 0;
1.698 harmsja 7313: }
1.693 droeschl 7314:
1.721 harmsja 7315: .LC_FormSectionClearButton input {
1.911 bisitz 7316: background-color:transparent;
7317: border: none;
7318: cursor:pointer;
7319: text-decoration:underline;
1.693 droeschl 7320: }
1.763 bisitz 7321:
7322: .LC_help_open_topic {
1.911 bisitz 7323: color: #FFFFFF;
7324: background-color: #EEEEFF;
7325: margin: 1px;
7326: padding: 4px;
7327: border: 1px solid #000033;
7328: white-space: nowrap;
7329: /* vertical-align: middle; */
1.759 neumanie 7330: }
1.693 droeschl 7331:
1.911 bisitz 7332: dl,
7333: ul,
7334: div,
7335: fieldset {
7336: margin: 10px 10px 10px 0;
7337: /* overflow: hidden; */
1.693 droeschl 7338: }
1.795 www 7339:
1.1211 raeburn 7340: article.geogebraweb div {
7341: margin: 0;
7342: }
7343:
1.838 bisitz 7344: fieldset > legend {
1.911 bisitz 7345: font-weight: bold;
7346: padding: 0 5px 0 5px;
1.838 bisitz 7347: }
7348:
1.813 bisitz 7349: #LC_nav_bar {
1.911 bisitz 7350: float: left;
1.995 raeburn 7351: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7352: margin: 0 0 2px 0;
1.807 droeschl 7353: }
7354:
1.916 droeschl 7355: #LC_realm {
7356: margin: 0.2em 0 0 0;
7357: padding: 0;
7358: font-weight: bold;
7359: text-align: center;
1.995 raeburn 7360: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7361: }
7362:
1.911 bisitz 7363: #LC_nav_bar em {
7364: font-weight: bold;
7365: font-style: normal;
1.807 droeschl 7366: }
7367:
1.897 wenzelju 7368: ol.LC_primary_menu {
1.934 droeschl 7369: margin: 0;
1.1076 raeburn 7370: padding: 0;
1.807 droeschl 7371: }
7372:
1.852 droeschl 7373: ol#LC_PathBreadcrumbs {
1.911 bisitz 7374: margin: 0;
1.693 droeschl 7375: }
7376:
1.897 wenzelju 7377: ol.LC_primary_menu li {
1.1076 raeburn 7378: color: RGB(80, 80, 80);
7379: vertical-align: middle;
7380: text-align: left;
7381: list-style: none;
1.1205 golterma 7382: position: relative;
1.1076 raeburn 7383: float: left;
1.1205 golterma 7384: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7385: line-height: 1.5em;
1.1076 raeburn 7386: }
7387:
1.1205 golterma 7388: ol.LC_primary_menu li a,
7389: ol.LC_primary_menu li p {
1.1076 raeburn 7390: display: block;
7391: margin: 0;
7392: padding: 0 5px 0 10px;
7393: text-decoration: none;
7394: }
7395:
1.1205 golterma 7396: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7397: display: inline-block;
7398: width: 95%;
7399: text-align: left;
7400: }
7401:
7402: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7403: display: inline-block;
7404: width: 5%;
7405: float: right;
7406: text-align: right;
7407: font-size: 70%;
7408: }
7409:
7410: ol.LC_primary_menu ul {
1.1076 raeburn 7411: display: none;
1.1205 golterma 7412: width: 15em;
1.1076 raeburn 7413: background-color: $data_table_light;
1.1205 golterma 7414: position: absolute;
7415: top: 100%;
1.1076 raeburn 7416: }
7417:
1.1205 golterma 7418: ol.LC_primary_menu ul ul {
7419: left: 100%;
7420: top: 0;
7421: }
7422:
7423: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7424: display: block;
7425: position: absolute;
7426: margin: 0;
7427: padding: 0;
1.1078 raeburn 7428: z-index: 2;
1.1076 raeburn 7429: }
7430:
7431: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7432: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7433: font-size: 90%;
1.911 bisitz 7434: vertical-align: top;
1.1076 raeburn 7435: float: none;
1.1079 raeburn 7436: border-left: 1px solid black;
7437: border-right: 1px solid black;
1.1205 golterma 7438: /* A dark bottom border to visualize different menu options;
7439: overwritten in the create_submenu routine for the last border-bottom of the menu */
7440: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7441: }
7442:
1.1205 golterma 7443: ol.LC_primary_menu li li p:hover {
7444: color:$button_hover;
7445: text-decoration:none;
7446: background-color:$data_table_dark;
1.1076 raeburn 7447: }
7448:
7449: ol.LC_primary_menu li li a:hover {
7450: color:$button_hover;
7451: background-color:$data_table_dark;
1.693 droeschl 7452: }
7453:
1.1205 golterma 7454: /* Font-size equal to the size of the predecessors*/
7455: ol.LC_primary_menu li:hover li li {
7456: font-size: 100%;
7457: }
7458:
1.897 wenzelju 7459: ol.LC_primary_menu li img {
1.911 bisitz 7460: vertical-align: bottom;
1.934 droeschl 7461: height: 1.1em;
1.1077 raeburn 7462: margin: 0.2em 0 0 0;
1.693 droeschl 7463: }
7464:
1.897 wenzelju 7465: ol.LC_primary_menu a {
1.911 bisitz 7466: color: RGB(80, 80, 80);
7467: text-decoration: none;
1.693 droeschl 7468: }
1.795 www 7469:
1.949 droeschl 7470: ol.LC_primary_menu a.LC_new_message {
7471: font-weight:bold;
7472: color: darkred;
7473: }
7474:
1.975 raeburn 7475: ol.LC_docs_parameters {
7476: margin-left: 0;
7477: padding: 0;
7478: list-style: none;
7479: }
7480:
7481: ol.LC_docs_parameters li {
7482: margin: 0;
7483: padding-right: 20px;
7484: display: inline;
7485: }
7486:
1.976 raeburn 7487: ol.LC_docs_parameters li:before {
7488: content: "\\002022 \\0020";
7489: }
7490:
7491: li.LC_docs_parameters_title {
7492: font-weight: bold;
7493: }
7494:
7495: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7496: content: "";
7497: }
7498:
1.897 wenzelju 7499: ul#LC_secondary_menu {
1.1107 raeburn 7500: clear: right;
1.911 bisitz 7501: color: $fontmenu;
7502: background: $tabbg;
7503: list-style: none;
7504: padding: 0;
7505: margin: 0;
7506: width: 100%;
1.995 raeburn 7507: text-align: left;
1.1107 raeburn 7508: float: left;
1.808 droeschl 7509: }
7510:
1.897 wenzelju 7511: ul#LC_secondary_menu li {
1.911 bisitz 7512: font-weight: bold;
7513: line-height: 1.8em;
1.1107 raeburn 7514: border-right: 1px solid black;
7515: float: left;
7516: }
7517:
7518: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7519: background-color: $data_table_light;
7520: }
7521:
7522: ul#LC_secondary_menu li a {
1.911 bisitz 7523: padding: 0 0.8em;
1.1107 raeburn 7524: }
7525:
7526: ul#LC_secondary_menu li ul {
7527: display: none;
7528: }
7529:
7530: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7531: display: block;
7532: position: absolute;
7533: margin: 0;
7534: padding: 0;
7535: list-style:none;
7536: float: none;
7537: background-color: $data_table_light;
7538: z-index: 2;
7539: margin-left: -1px;
7540: }
7541:
7542: ul#LC_secondary_menu li ul li {
7543: font-size: 90%;
7544: vertical-align: top;
7545: border-left: 1px solid black;
1.911 bisitz 7546: border-right: 1px solid black;
1.1119 raeburn 7547: background-color: $data_table_light;
1.1107 raeburn 7548: list-style:none;
7549: float: none;
7550: }
7551:
7552: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7553: background-color: $data_table_dark;
1.807 droeschl 7554: }
7555:
1.847 tempelho 7556: ul.LC_TabContent {
1.911 bisitz 7557: display:block;
7558: background: $sidebg;
7559: border-bottom: solid 1px $lg_border_color;
7560: list-style:none;
1.1020 raeburn 7561: margin: -1px -10px 0 -10px;
1.911 bisitz 7562: padding: 0;
1.693 droeschl 7563: }
7564:
1.795 www 7565: ul.LC_TabContent li,
7566: ul.LC_TabContentBigger li {
1.911 bisitz 7567: float:left;
1.741 harmsja 7568: }
1.795 www 7569:
1.897 wenzelju 7570: ul#LC_secondary_menu li a {
1.911 bisitz 7571: color: $fontmenu;
7572: text-decoration: none;
1.693 droeschl 7573: }
1.795 www 7574:
1.721 harmsja 7575: ul.LC_TabContent {
1.952 onken 7576: min-height:20px;
1.721 harmsja 7577: }
1.795 www 7578:
7579: ul.LC_TabContent li {
1.911 bisitz 7580: vertical-align:middle;
1.959 onken 7581: padding: 0 16px 0 10px;
1.911 bisitz 7582: background-color:$tabbg;
7583: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7584: border-left: solid 1px $font;
1.721 harmsja 7585: }
1.795 www 7586:
1.847 tempelho 7587: ul.LC_TabContent .right {
1.911 bisitz 7588: float:right;
1.847 tempelho 7589: }
7590:
1.911 bisitz 7591: ul.LC_TabContent li a,
7592: ul.LC_TabContent li {
7593: color:rgb(47,47,47);
7594: text-decoration:none;
7595: font-size:95%;
7596: font-weight:bold;
1.952 onken 7597: min-height:20px;
7598: }
7599:
1.959 onken 7600: ul.LC_TabContent li a:hover,
7601: ul.LC_TabContent li a:focus {
1.952 onken 7602: color: $button_hover;
1.959 onken 7603: background:none;
7604: outline:none;
1.952 onken 7605: }
7606:
7607: ul.LC_TabContent li:hover {
7608: color: $button_hover;
7609: cursor:pointer;
1.721 harmsja 7610: }
1.795 www 7611:
1.911 bisitz 7612: ul.LC_TabContent li.active {
1.952 onken 7613: color: $font;
1.911 bisitz 7614: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7615: border-bottom:solid 1px #FFFFFF;
7616: cursor: default;
1.744 ehlerst 7617: }
1.795 www 7618:
1.959 onken 7619: ul.LC_TabContent li.active a {
7620: color:$font;
7621: background:#FFFFFF;
7622: outline: none;
7623: }
1.1047 raeburn 7624:
7625: ul.LC_TabContent li.goback {
7626: float: left;
7627: border-left: none;
7628: }
7629:
1.870 tempelho 7630: #maincoursedoc {
1.911 bisitz 7631: clear:both;
1.870 tempelho 7632: }
7633:
7634: ul.LC_TabContentBigger {
1.911 bisitz 7635: display:block;
7636: list-style:none;
7637: padding: 0;
1.870 tempelho 7638: }
7639:
1.795 www 7640: ul.LC_TabContentBigger li {
1.911 bisitz 7641: vertical-align:bottom;
7642: height: 30px;
7643: font-size:110%;
7644: font-weight:bold;
7645: color: #737373;
1.841 tempelho 7646: }
7647:
1.957 onken 7648: ul.LC_TabContentBigger li.active {
7649: position: relative;
7650: top: 1px;
7651: }
7652:
1.870 tempelho 7653: ul.LC_TabContentBigger li a {
1.911 bisitz 7654: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7655: height: 30px;
7656: line-height: 30px;
7657: text-align: center;
7658: display: block;
7659: text-decoration: none;
1.958 onken 7660: outline: none;
1.741 harmsja 7661: }
1.795 www 7662:
1.870 tempelho 7663: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7664: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7665: color:$font;
1.744 ehlerst 7666: }
1.795 www 7667:
1.870 tempelho 7668: ul.LC_TabContentBigger li b {
1.911 bisitz 7669: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7670: display: block;
7671: float: left;
7672: padding: 0 30px;
1.957 onken 7673: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7674: }
7675:
1.956 onken 7676: ul.LC_TabContentBigger li:hover b {
7677: color:$button_hover;
7678: }
7679:
1.870 tempelho 7680: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7681: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7682: color:$font;
1.957 onken 7683: border: 0;
1.741 harmsja 7684: }
1.693 droeschl 7685:
1.870 tempelho 7686:
1.862 bisitz 7687: ul.LC_CourseBreadcrumbs {
7688: background: $sidebg;
1.1020 raeburn 7689: height: 2em;
1.862 bisitz 7690: padding-left: 10px;
1.1020 raeburn 7691: margin: 0;
1.862 bisitz 7692: list-style-position: inside;
7693: }
7694:
1.911 bisitz 7695: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7696: ol#LC_PathBreadcrumbs {
1.911 bisitz 7697: padding-left: 10px;
7698: margin: 0;
1.933 droeschl 7699: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7700: }
7701:
1.911 bisitz 7702: ol#LC_MenuBreadcrumbs li,
7703: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7704: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7705: display: inline;
1.933 droeschl 7706: white-space: normal;
1.693 droeschl 7707: }
7708:
1.823 bisitz 7709: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7710: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7711: text-decoration: none;
7712: font-size:90%;
1.693 droeschl 7713: }
1.795 www 7714:
1.969 droeschl 7715: ol#LC_MenuBreadcrumbs h1 {
7716: display: inline;
7717: font-size: 90%;
7718: line-height: 2.5em;
7719: margin: 0;
7720: padding: 0;
7721: }
7722:
1.795 www 7723: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7724: text-decoration:none;
7725: font-size:100%;
7726: font-weight:bold;
1.693 droeschl 7727: }
1.795 www 7728:
1.840 bisitz 7729: .LC_Box {
1.911 bisitz 7730: border: solid 1px $lg_border_color;
7731: padding: 0 10px 10px 10px;
1.746 neumanie 7732: }
1.795 www 7733:
1.1020 raeburn 7734: .LC_DocsBox {
7735: border: solid 1px $lg_border_color;
7736: padding: 0 0 10px 10px;
7737: }
7738:
1.795 www 7739: .LC_AboutMe_Image {
1.911 bisitz 7740: float:left;
7741: margin-right:10px;
1.747 neumanie 7742: }
1.795 www 7743:
7744: .LC_Clear_AboutMe_Image {
1.911 bisitz 7745: clear:left;
1.747 neumanie 7746: }
1.795 www 7747:
1.721 harmsja 7748: dl.LC_ListStyleClean dt {
1.911 bisitz 7749: padding-right: 5px;
7750: display: table-header-group;
1.693 droeschl 7751: }
7752:
1.721 harmsja 7753: dl.LC_ListStyleClean dd {
1.911 bisitz 7754: display: table-row;
1.693 droeschl 7755: }
7756:
1.721 harmsja 7757: .LC_ListStyleClean,
7758: .LC_ListStyleSimple,
7759: .LC_ListStyleNormal,
1.795 www 7760: .LC_ListStyleSpecial {
1.911 bisitz 7761: /* display:block; */
7762: list-style-position: inside;
7763: list-style-type: none;
7764: overflow: hidden;
7765: padding: 0;
1.693 droeschl 7766: }
7767:
1.721 harmsja 7768: .LC_ListStyleSimple li,
7769: .LC_ListStyleSimple dd,
7770: .LC_ListStyleNormal li,
7771: .LC_ListStyleNormal dd,
7772: .LC_ListStyleSpecial li,
1.795 www 7773: .LC_ListStyleSpecial dd {
1.911 bisitz 7774: margin: 0;
7775: padding: 5px 5px 5px 10px;
7776: clear: both;
1.693 droeschl 7777: }
7778:
1.721 harmsja 7779: .LC_ListStyleClean li,
7780: .LC_ListStyleClean dd {
1.911 bisitz 7781: padding-top: 0;
7782: padding-bottom: 0;
1.693 droeschl 7783: }
7784:
1.721 harmsja 7785: .LC_ListStyleSimple dd,
1.795 www 7786: .LC_ListStyleSimple li {
1.911 bisitz 7787: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7788: }
7789:
1.721 harmsja 7790: .LC_ListStyleSpecial li,
7791: .LC_ListStyleSpecial dd {
1.911 bisitz 7792: list-style-type: none;
7793: background-color: RGB(220, 220, 220);
7794: margin-bottom: 4px;
1.693 droeschl 7795: }
7796:
1.721 harmsja 7797: table.LC_SimpleTable {
1.911 bisitz 7798: margin:5px;
7799: border:solid 1px $lg_border_color;
1.795 www 7800: }
1.693 droeschl 7801:
1.721 harmsja 7802: table.LC_SimpleTable tr {
1.911 bisitz 7803: padding: 0;
7804: border:solid 1px $lg_border_color;
1.693 droeschl 7805: }
1.795 www 7806:
7807: table.LC_SimpleTable thead {
1.911 bisitz 7808: background:rgb(220,220,220);
1.693 droeschl 7809: }
7810:
1.721 harmsja 7811: div.LC_columnSection {
1.911 bisitz 7812: display: block;
7813: clear: both;
7814: overflow: hidden;
7815: margin: 0;
1.693 droeschl 7816: }
7817:
1.721 harmsja 7818: div.LC_columnSection>* {
1.911 bisitz 7819: float: left;
7820: margin: 10px 20px 10px 0;
7821: overflow:hidden;
1.693 droeschl 7822: }
1.721 harmsja 7823:
1.795 www 7824: table em {
1.911 bisitz 7825: font-weight: bold;
7826: font-style: normal;
1.748 schulted 7827: }
1.795 www 7828:
1.779 bisitz 7829: table.LC_tableBrowseRes,
1.795 www 7830: table.LC_tableOfContent {
1.911 bisitz 7831: border:none;
7832: border-spacing: 1px;
7833: padding: 3px;
7834: background-color: #FFFFFF;
7835: font-size: 90%;
1.753 droeschl 7836: }
1.789 droeschl 7837:
1.911 bisitz 7838: table.LC_tableOfContent {
7839: border-collapse: collapse;
1.789 droeschl 7840: }
7841:
1.771 droeschl 7842: table.LC_tableBrowseRes a,
1.768 schulted 7843: table.LC_tableOfContent a {
1.911 bisitz 7844: background-color: transparent;
7845: text-decoration: none;
1.753 droeschl 7846: }
7847:
1.795 www 7848: table.LC_tableOfContent img {
1.911 bisitz 7849: border: none;
7850: height: 1.3em;
7851: vertical-align: text-bottom;
7852: margin-right: 0.3em;
1.753 droeschl 7853: }
1.757 schulted 7854:
1.795 www 7855: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7856: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7857: }
7858:
1.795 www 7859: a#LC_content_toolbar_everything {
1.911 bisitz 7860: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7861: }
7862:
1.795 www 7863: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7864: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7865: }
7866:
1.795 www 7867: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7868: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7869: }
7870:
1.795 www 7871: a#LC_content_toolbar_changefolder {
1.911 bisitz 7872: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7873: }
7874:
1.795 www 7875: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7876: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7877: }
7878:
1.1043 raeburn 7879: a#LC_content_toolbar_edittoplevel {
7880: background-image:url(/res/adm/pages/edittoplevel.gif);
7881: }
7882:
1.795 www 7883: ul#LC_toolbar li a:hover {
1.911 bisitz 7884: background-position: bottom center;
1.757 schulted 7885: }
7886:
1.795 www 7887: ul#LC_toolbar {
1.911 bisitz 7888: padding: 0;
7889: margin: 2px;
7890: list-style:none;
7891: position:relative;
7892: background-color:white;
1.1082 raeburn 7893: overflow: auto;
1.757 schulted 7894: }
7895:
1.795 www 7896: ul#LC_toolbar li {
1.911 bisitz 7897: border:1px solid white;
7898: padding: 0;
7899: margin: 0;
7900: float: left;
7901: display:inline;
7902: vertical-align:middle;
1.1082 raeburn 7903: white-space: nowrap;
1.911 bisitz 7904: }
1.757 schulted 7905:
1.783 amueller 7906:
1.795 www 7907: a.LC_toolbarItem {
1.911 bisitz 7908: display:block;
7909: padding: 0;
7910: margin: 0;
7911: height: 32px;
7912: width: 32px;
7913: color:white;
7914: border: none;
7915: background-repeat:no-repeat;
7916: background-color:transparent;
1.757 schulted 7917: }
7918:
1.915 droeschl 7919: ul.LC_funclist {
7920: margin: 0;
7921: padding: 0.5em 1em 0.5em 0;
7922: }
7923:
1.933 droeschl 7924: ul.LC_funclist > li:first-child {
7925: font-weight:bold;
7926: margin-left:0.8em;
7927: }
7928:
1.915 droeschl 7929: ul.LC_funclist + ul.LC_funclist {
7930: /*
7931: left border as a seperator if we have more than
7932: one list
7933: */
7934: border-left: 1px solid $sidebg;
7935: /*
7936: this hides the left border behind the border of the
7937: outer box if element is wrapped to the next 'line'
7938: */
7939: margin-left: -1px;
7940: }
7941:
1.843 bisitz 7942: ul.LC_funclist li {
1.915 droeschl 7943: display: inline;
1.782 bisitz 7944: white-space: nowrap;
1.915 droeschl 7945: margin: 0 0 0 25px;
7946: line-height: 150%;
1.782 bisitz 7947: }
7948:
1.974 wenzelju 7949: .LC_hidden {
7950: display: none;
7951: }
7952:
1.1030 www 7953: .LCmodal-overlay {
7954: position:fixed;
7955: top:0;
7956: right:0;
7957: bottom:0;
7958: left:0;
7959: height:100%;
7960: width:100%;
7961: margin:0;
7962: padding:0;
7963: background:#999;
7964: opacity:.75;
7965: filter: alpha(opacity=75);
7966: -moz-opacity: 0.75;
7967: z-index:101;
7968: }
7969:
7970: * html .LCmodal-overlay {
7971: position: absolute;
7972: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7973: }
7974:
7975: .LCmodal-window {
7976: position:fixed;
7977: top:50%;
7978: left:50%;
7979: margin:0;
7980: padding:0;
7981: z-index:102;
7982: }
7983:
7984: * html .LCmodal-window {
7985: position:absolute;
7986: }
7987:
7988: .LCclose-window {
7989: position:absolute;
7990: width:32px;
7991: height:32px;
7992: right:8px;
7993: top:8px;
7994: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7995: text-indent:-99999px;
7996: overflow:hidden;
7997: cursor:pointer;
7998: }
7999:
1.1100 raeburn 8000: /*
1.1231 damieng 8001: styles used for response display
8002: */
8003: div.LC_radiofoil, div.LC_rankfoil {
8004: margin: .5em 0em .5em 0em;
8005: }
8006: table.LC_itemgroup {
8007: margin-top: 1em;
8008: }
8009:
8010: /*
1.1100 raeburn 8011: styles used by TTH when "Default set of options to pass to tth/m
8012: when converting TeX" in course settings has been set
8013:
8014: option passed: -t
8015:
8016: */
8017:
8018: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8019: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8020: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8021: td div.norm {line-height:normal;}
8022:
8023: /*
8024: option passed -y3
8025: */
8026:
8027: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8028: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8029: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8030:
1.1230 damieng 8031: /*
8032: sections with roles, for content only
8033: */
8034: section[class^="role-"] {
8035: padding-left: 10px;
8036: padding-right: 5px;
8037: margin-top: 8px;
8038: margin-bottom: 8px;
8039: border: 1px solid #2A4;
8040: border-radius: 5px;
8041: box-shadow: 0px 1px 1px #BBB;
8042: }
8043: section[class^="role-"]>h1 {
8044: position: relative;
8045: margin: 0px;
8046: padding-top: 10px;
8047: padding-left: 40px;
8048: }
8049: section[class^="role-"]>h1:before {
8050: position: absolute;
8051: left: -5px;
8052: top: 5px;
8053: }
8054: section.role-activity>h1:before {
8055: content:url('/adm/daxe/images/section_icons/activity.png');
8056: }
8057: section.role-advice>h1:before {
8058: content:url('/adm/daxe/images/section_icons/advice.png');
8059: }
8060: section.role-bibliography>h1:before {
8061: content:url('/adm/daxe/images/section_icons/bibliography.png');
8062: }
8063: section.role-citation>h1:before {
8064: content:url('/adm/daxe/images/section_icons/citation.png');
8065: }
8066: section.role-conclusion>h1:before {
8067: content:url('/adm/daxe/images/section_icons/conclusion.png');
8068: }
8069: section.role-definition>h1:before {
8070: content:url('/adm/daxe/images/section_icons/definition.png');
8071: }
8072: section.role-demonstration>h1:before {
8073: content:url('/adm/daxe/images/section_icons/demonstration.png');
8074: }
8075: section.role-example>h1:before {
8076: content:url('/adm/daxe/images/section_icons/example.png');
8077: }
8078: section.role-explanation>h1:before {
8079: content:url('/adm/daxe/images/section_icons/explanation.png');
8080: }
8081: section.role-introduction>h1:before {
8082: content:url('/adm/daxe/images/section_icons/introduction.png');
8083: }
8084: section.role-method>h1:before {
8085: content:url('/adm/daxe/images/section_icons/method.png');
8086: }
8087: section.role-more_information>h1:before {
8088: content:url('/adm/daxe/images/section_icons/more_information.png');
8089: }
8090: section.role-objectives>h1:before {
8091: content:url('/adm/daxe/images/section_icons/objectives.png');
8092: }
8093: section.role-prerequisites>h1:before {
8094: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8095: }
8096: section.role-remark>h1:before {
8097: content:url('/adm/daxe/images/section_icons/remark.png');
8098: }
8099: section.role-reminder>h1:before {
8100: content:url('/adm/daxe/images/section_icons/reminder.png');
8101: }
8102: section.role-summary>h1:before {
8103: content:url('/adm/daxe/images/section_icons/summary.png');
8104: }
8105: section.role-syntax>h1:before {
8106: content:url('/adm/daxe/images/section_icons/syntax.png');
8107: }
8108: section.role-warning>h1:before {
8109: content:url('/adm/daxe/images/section_icons/warning.png');
8110: }
8111:
1.343 albertel 8112: END
8113: }
8114:
1.306 albertel 8115: =pod
8116:
8117: =item * &headtag()
8118:
8119: Returns a uniform footer for LON-CAPA web pages.
8120:
1.307 albertel 8121: Inputs: $title - optional title for the head
8122: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8123: $args - optional arguments
1.319 albertel 8124: force_register - if is true call registerurl so the remote is
8125: informed
1.415 albertel 8126: redirect -> array ref of
8127: 1- seconds before redirect occurs
8128: 2- url to redirect to
8129: 3- whether the side effect should occur
1.315 albertel 8130: (side effect of setting
8131: $env{'internal.head.redirect'} to the url
8132: redirected too)
1.352 albertel 8133: domain -> force to color decorate a page for a specific
8134: domain
8135: function -> force usage of a specific rolish color scheme
8136: bgcolor -> override the default page bgcolor
1.460 albertel 8137: no_auto_mt_title
8138: -> prevent &mt()ing the title arg
1.464 albertel 8139:
1.306 albertel 8140: =cut
8141:
8142: sub headtag {
1.313 albertel 8143: my ($title,$head_extra,$args) = @_;
1.306 albertel 8144:
1.363 albertel 8145: my $function = $args->{'function'} || &get_users_function();
8146: my $domain = $args->{'domain'} || &determinedomain();
8147: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8148: my $httphost = $args->{'use_absolute'};
1.418 albertel 8149: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8150: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8151: #time(),
1.418 albertel 8152: $env{'environment.color.timestamp'},
1.363 albertel 8153: $function,$domain,$bgcolor);
8154:
1.369 www 8155: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8156:
1.308 albertel 8157: my $result =
8158: '<head>'.
1.1160 raeburn 8159: &font_settings($args);
1.319 albertel 8160:
1.1188 raeburn 8161: my $inhibitprint;
8162: if ($args->{'print_suppress'}) {
8163: $inhibitprint = &print_suppression();
8164: }
1.1064 raeburn 8165:
1.461 albertel 8166: if (!$args->{'frameset'}) {
8167: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8168: }
1.962 droeschl 8169: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8170: $result .= Apache::lonxml::display_title();
1.319 albertel 8171: }
1.436 albertel 8172: if (!$args->{'no_nav_bar'}
8173: && !$args->{'only_body'}
8174: && !$args->{'frameset'}) {
1.1154 raeburn 8175: $result .= &help_menu_js($httphost);
1.1032 www 8176: $result.=&modal_window();
1.1038 www 8177: $result.=&togglebox_script();
1.1034 www 8178: $result.=&wishlist_window();
1.1041 www 8179: $result.=&LCprogressbarUpdate_script();
1.1034 www 8180: } else {
8181: if ($args->{'add_modal'}) {
8182: $result.=&modal_window();
8183: }
8184: if ($args->{'add_wishlist'}) {
8185: $result.=&wishlist_window();
8186: }
1.1038 www 8187: if ($args->{'add_togglebox'}) {
8188: $result.=&togglebox_script();
8189: }
1.1041 www 8190: if ($args->{'add_progressbar'}) {
8191: $result.=&LCprogressbarUpdate_script();
8192: }
1.436 albertel 8193: }
1.314 albertel 8194: if (ref($args->{'redirect'})) {
1.414 albertel 8195: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8196: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8197: if (!$inhibit_continue) {
8198: $env{'internal.head.redirect'} = $url;
8199: }
1.313 albertel 8200: $result.=<<ADDMETA
8201: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8202: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8203: ADDMETA
1.1210 raeburn 8204: } else {
8205: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8206: my $requrl = $env{'request.uri'};
8207: if ($requrl eq '') {
8208: $requrl = $ENV{'REQUEST_URI'};
8209: $requrl =~ s/\?.+$//;
8210: }
8211: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8212: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8213: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8214: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8215: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8216: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
8217: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8218: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8219: if ($domdefs{'offloadnow'}{$lonhost}) {
8220: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8221: if (($newserver) && ($newserver ne $lonhost)) {
8222: my $numsec = 5;
8223: my $timeout = $numsec * 1000;
8224: my ($newurl,$locknum,%locks,$msg);
8225: if ($env{'request.role.adv'}) {
8226: ($locknum,%locks) = &Apache::lonnet::get_locks();
8227: }
8228: my $disable_submit = 0;
8229: if ($requrl =~ /$LONCAPA::assess_re/) {
8230: $disable_submit = 1;
8231: }
8232: if ($locknum) {
8233: my @lockinfo = sort(values(%locks));
8234: $msg = &mt('Once the following tasks are complete: ')."\\n".
8235: join(", ",sort(values(%locks)))."\\n".
8236: &mt('your session will be transferred to a different server, after you click "Roles".');
8237: } else {
8238: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8239: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
8240: }
8241: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8242: $newurl = '/adm/switchserver?otherserver='.$newserver;
8243: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8244: $newurl .= '&role='.$env{'request.role'};
8245: }
8246: if ($env{'request.symb'}) {
8247: $newurl .= '&symb='.$env{'request.symb'};
8248: } else {
8249: $newurl .= '&origurl='.$requrl;
8250: }
8251: }
1.1222 damieng 8252: &js_escape(\$msg);
1.1210 raeburn 8253: $result.=<<OFFLOAD
8254: <meta http-equiv="pragma" content="no-cache" />
8255: <script type="text/javascript">
1.1215 raeburn 8256: // <![CDATA[
1.1210 raeburn 8257: function LC_Offload_Now() {
8258: var dest = "$newurl";
8259: if (dest != '') {
8260: window.location.href="$newurl";
8261: }
8262: }
1.1214 raeburn 8263: \$(document).ready(function () {
8264: window.alert('$msg');
8265: if ($disable_submit) {
1.1210 raeburn 8266: \$(".LC_hwk_submit").prop("disabled", true);
8267: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8268: }
8269: setTimeout('LC_Offload_Now()', $timeout);
8270: });
1.1215 raeburn 8271: // ]]>
1.1210 raeburn 8272: </script>
8273: OFFLOAD
8274: }
8275: }
8276: }
8277: }
8278: }
8279: }
1.313 albertel 8280: }
1.306 albertel 8281: if (!defined($title)) {
8282: $title = 'The LearningOnline Network with CAPA';
8283: }
1.460 albertel 8284: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8285: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8286: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8287: if (!$args->{'frameset'}) {
8288: $result .= ' /';
8289: }
8290: $result .= '>'
1.1064 raeburn 8291: .$inhibitprint
1.414 albertel 8292: .$head_extra;
1.1242 raeburn 8293: my $clientmobile;
8294: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8295: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8296: } else {
8297: $clientmobile = $env{'browser.mobile'};
8298: }
8299: if ($clientmobile) {
1.1137 raeburn 8300: $result .= '
8301: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8302: <meta name="apple-mobile-web-app-capable" content="yes" />';
8303: }
1.962 droeschl 8304: return $result.'</head>';
1.306 albertel 8305: }
8306:
8307: =pod
8308:
1.340 albertel 8309: =item * &font_settings()
8310:
8311: Returns neccessary <meta> to set the proper encoding
8312:
1.1160 raeburn 8313: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8314:
8315: =cut
8316:
8317: sub font_settings {
1.1160 raeburn 8318: my ($args) = @_;
1.340 albertel 8319: my $headerstring='';
1.1160 raeburn 8320: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8321: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8322: $headerstring.=
8323: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8324: if (!$args->{'frameset'}) {
8325: $headerstring.= ' /';
8326: }
8327: $headerstring .= '>'."\n";
1.340 albertel 8328: }
8329: return $headerstring;
8330: }
8331:
1.341 albertel 8332: =pod
8333:
1.1064 raeburn 8334: =item * &print_suppression()
8335:
8336: In course context returns css which causes the body to be blank when media="print",
8337: if printout generation is unavailable for the current resource.
8338:
8339: This could be because:
8340:
8341: (a) printstartdate is in the future
8342:
8343: (b) printenddate is in the past
8344:
8345: (c) there is an active exam block with "printout"
8346: functionality blocked
8347:
8348: Users with pav, pfo or evb privileges are exempt.
8349:
8350: Inputs: none
8351:
8352: =cut
8353:
8354:
8355: sub print_suppression {
8356: my $noprint;
8357: if ($env{'request.course.id'}) {
8358: my $scope = $env{'request.course.id'};
8359: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8360: (&Apache::lonnet::allowed('pfo',$scope))) {
8361: return;
8362: }
8363: if ($env{'request.course.sec'} ne '') {
8364: $scope .= "/$env{'request.course.sec'}";
8365: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8366: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8367: return;
1.1064 raeburn 8368: }
8369: }
8370: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8371: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8372: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8373: if ($blocked) {
8374: my $checkrole = "cm./$cdom/$cnum";
8375: if ($env{'request.course.sec'} ne '') {
8376: $checkrole .= "/$env{'request.course.sec'}";
8377: }
8378: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8379: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8380: $noprint = 1;
8381: }
8382: }
8383: unless ($noprint) {
8384: my $symb = &Apache::lonnet::symbread();
8385: if ($symb ne '') {
8386: my $navmap = Apache::lonnavmaps::navmap->new();
8387: if (ref($navmap)) {
8388: my $res = $navmap->getBySymb($symb);
8389: if (ref($res)) {
8390: if (!$res->resprintable()) {
8391: $noprint = 1;
8392: }
8393: }
8394: }
8395: }
8396: }
8397: if ($noprint) {
8398: return <<"ENDSTYLE";
8399: <style type="text/css" media="print">
8400: body { display:none }
8401: </style>
8402: ENDSTYLE
8403: }
8404: }
8405: return;
8406: }
8407:
8408: =pod
8409:
1.341 albertel 8410: =item * &xml_begin()
8411:
8412: Returns the needed doctype and <html>
8413:
8414: Inputs: none
8415:
8416: =cut
8417:
8418: sub xml_begin {
1.1168 raeburn 8419: my ($is_frameset) = @_;
1.341 albertel 8420: my $output='';
8421:
8422: if ($env{'browser.mathml'}) {
8423: $output='<?xml version="1.0"?>'
8424: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8425: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8426:
8427: # .'<!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">] >'
8428: .'<!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">'
8429: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8430: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8431: } elsif ($is_frameset) {
8432: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8433: '<html>'."\n";
1.341 albertel 8434: } else {
1.1168 raeburn 8435: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8436: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8437: }
8438: return $output;
8439: }
1.340 albertel 8440:
8441: =pod
8442:
1.306 albertel 8443: =item * &start_page()
8444:
8445: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8446:
1.648 raeburn 8447: Inputs:
8448:
8449: =over 4
8450:
8451: $title - optional title for the page
8452:
8453: $head_extra - optional extra HTML to incude inside the <head>
8454:
8455: $args - additional optional args supported are:
8456:
8457: =over 8
8458:
8459: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8460: arg on
1.814 bisitz 8461: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8462: add_entries -> additional attributes to add to the <body>
8463: domain -> force to color decorate a page for a
1.317 albertel 8464: specific domain
1.648 raeburn 8465: function -> force usage of a specific rolish color
1.317 albertel 8466: scheme
1.648 raeburn 8467: redirect -> see &headtag()
8468: bgcolor -> override the default page bg color
8469: js_ready -> return a string ready for being used in
1.317 albertel 8470: a javascript writeln
1.648 raeburn 8471: html_encode -> return a string ready for being used in
1.320 albertel 8472: a html attribute
1.648 raeburn 8473: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8474: $forcereg arg
1.648 raeburn 8475: frameset -> if true will start with a <frameset>
1.330 albertel 8476: rather than <body>
1.648 raeburn 8477: skip_phases -> hash ref of
1.338 albertel 8478: head -> skip the <html><head> generation
8479: body -> skip all <body> generation
1.648 raeburn 8480: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8481: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8482: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 8483: group -> includes the current group, if page is for a
8484: specific group
1.361 albertel 8485:
1.648 raeburn 8486: =back
1.460 albertel 8487:
1.648 raeburn 8488: =back
1.562 albertel 8489:
1.306 albertel 8490: =cut
8491:
8492: sub start_page {
1.309 albertel 8493: my ($title,$head_extra,$args) = @_;
1.318 albertel 8494: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8495:
1.315 albertel 8496: $env{'internal.start_page'}++;
1.1096 raeburn 8497: my ($result,@advtools);
1.964 droeschl 8498:
1.338 albertel 8499: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8500: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8501: }
8502:
8503: if (! exists($args->{'skip_phases'}{'body'}) ) {
8504: if ($args->{'frameset'}) {
8505: my $attr_string = &make_attr_string($args->{'force_register'},
8506: $args->{'add_entries'});
8507: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8508: } else {
8509: $result .=
8510: &bodytag($title,
8511: $args->{'function'}, $args->{'add_entries'},
8512: $args->{'only_body'}, $args->{'domain'},
8513: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8514: $args->{'bgcolor'}, $args,
8515: \@advtools);
1.831 bisitz 8516: }
1.330 albertel 8517: }
1.338 albertel 8518:
1.315 albertel 8519: if ($args->{'js_ready'}) {
1.713 kaisler 8520: $result = &js_ready($result);
1.315 albertel 8521: }
1.320 albertel 8522: if ($args->{'html_encode'}) {
1.713 kaisler 8523: $result = &html_encode($result);
8524: }
8525:
1.813 bisitz 8526: # Preparation for new and consistent functionlist at top of screen
8527: # if ($args->{'functionlist'}) {
8528: # $result .= &build_functionlist();
8529: #}
8530:
1.964 droeschl 8531: # Don't add anything more if only_body wanted or in const space
8532: return $result if $args->{'only_body'}
8533: || $env{'request.state'} eq 'construct';
1.813 bisitz 8534:
8535: #Breadcrumbs
1.758 kaisler 8536: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8537: &Apache::lonhtmlcommon::clear_breadcrumbs();
8538: #if any br links exists, add them to the breadcrumbs
8539: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8540: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8541: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8542: }
8543: }
1.1096 raeburn 8544: # if @advtools array contains items add then to the breadcrumbs
8545: if (@advtools > 0) {
8546: &Apache::lonmenu::advtools_crumbs(@advtools);
8547: }
1.758 kaisler 8548:
8549: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8550: if(exists($args->{'bread_crumbs_component'})){
8551: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
1.1237 raeburn 8552: } elsif ($args->{'crstype'} eq 'Placement') {
8553: $result .= &Apache::lonhtmlcommon::breadcrumbs('','','','','','','','','',
8554: $args->{'crstype'});
8555: } else {
1.758 kaisler 8556: $result .= &Apache::lonhtmlcommon::breadcrumbs();
8557: }
1.320 albertel 8558: }
1.315 albertel 8559: return $result;
1.306 albertel 8560: }
8561:
8562: sub end_page {
1.315 albertel 8563: my ($args) = @_;
8564: $env{'internal.end_page'}++;
1.330 albertel 8565: my $result;
1.335 albertel 8566: if ($args->{'discussion'}) {
8567: my ($target,$parser);
8568: if (ref($args->{'discussion'})) {
8569: ($target,$parser) =($args->{'discussion'}{'target'},
8570: $args->{'discussion'}{'parser'});
8571: }
8572: $result .= &Apache::lonxml::xmlend($target,$parser);
8573: }
1.330 albertel 8574: if ($args->{'frameset'}) {
8575: $result .= '</frameset>';
8576: } else {
1.635 raeburn 8577: $result .= &endbodytag($args);
1.330 albertel 8578: }
1.1080 raeburn 8579: unless ($args->{'notbody'}) {
8580: $result .= "\n</html>";
8581: }
1.330 albertel 8582:
1.315 albertel 8583: if ($args->{'js_ready'}) {
1.317 albertel 8584: $result = &js_ready($result);
1.315 albertel 8585: }
1.335 albertel 8586:
1.320 albertel 8587: if ($args->{'html_encode'}) {
8588: $result = &html_encode($result);
8589: }
1.335 albertel 8590:
1.315 albertel 8591: return $result;
8592: }
8593:
1.1034 www 8594: sub wishlist_window {
8595: return(<<'ENDWISHLIST');
1.1046 raeburn 8596: <script type="text/javascript">
1.1034 www 8597: // <![CDATA[
8598: // <!-- BEGIN LON-CAPA Internal
8599: function set_wishlistlink(title, path) {
8600: if (!title) {
8601: title = document.title;
8602: title = title.replace(/^LON-CAPA /,'');
8603: }
1.1175 raeburn 8604: title = encodeURIComponent(title);
1.1203 raeburn 8605: title = title.replace("'","\\\'");
1.1034 www 8606: if (!path) {
8607: path = location.pathname;
8608: }
1.1175 raeburn 8609: path = encodeURIComponent(path);
1.1203 raeburn 8610: path = path.replace("'","\\\'");
1.1034 www 8611: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8612: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8613: }
8614: // END LON-CAPA Internal -->
8615: // ]]>
8616: </script>
8617: ENDWISHLIST
8618: }
8619:
1.1030 www 8620: sub modal_window {
8621: return(<<'ENDMODAL');
1.1046 raeburn 8622: <script type="text/javascript">
1.1030 www 8623: // <![CDATA[
8624: // <!-- BEGIN LON-CAPA Internal
8625: var modalWindow = {
8626: parent:"body",
8627: windowId:null,
8628: content:null,
8629: width:null,
8630: height:null,
8631: close:function()
8632: {
8633: $(".LCmodal-window").remove();
8634: $(".LCmodal-overlay").remove();
8635: },
8636: open:function()
8637: {
8638: var modal = "";
8639: modal += "<div class=\"LCmodal-overlay\"></div>";
8640: 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;\">";
8641: modal += this.content;
8642: modal += "</div>";
8643:
8644: $(this.parent).append(modal);
8645:
8646: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8647: $(".LCclose-window").click(function(){modalWindow.close();});
8648: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8649: }
8650: };
1.1140 raeburn 8651: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8652: {
1.1203 raeburn 8653: source = source.replace("'","'");
1.1030 www 8654: modalWindow.windowId = "myModal";
8655: modalWindow.width = width;
8656: modalWindow.height = height;
1.1196 raeburn 8657: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8658: modalWindow.open();
1.1208 raeburn 8659: };
1.1030 www 8660: // END LON-CAPA Internal -->
8661: // ]]>
8662: </script>
8663: ENDMODAL
8664: }
8665:
8666: sub modal_link {
1.1140 raeburn 8667: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8668: unless ($width) { $width=480; }
8669: unless ($height) { $height=400; }
1.1031 www 8670: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8671: unless ($transparency) { $transparency='true'; }
8672:
1.1074 raeburn 8673: my $target_attr;
8674: if (defined($target)) {
8675: $target_attr = 'target="'.$target.'"';
8676: }
8677: return <<"ENDLINK";
1.1140 raeburn 8678: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8679: $linktext</a>
8680: ENDLINK
1.1030 www 8681: }
8682:
1.1032 www 8683: sub modal_adhoc_script {
8684: my ($funcname,$width,$height,$content)=@_;
8685: return (<<ENDADHOC);
1.1046 raeburn 8686: <script type="text/javascript">
1.1032 www 8687: // <![CDATA[
8688: var $funcname = function()
8689: {
8690: modalWindow.windowId = "myModal";
8691: modalWindow.width = $width;
8692: modalWindow.height = $height;
8693: modalWindow.content = '$content';
8694: modalWindow.open();
8695: };
8696: // ]]>
8697: </script>
8698: ENDADHOC
8699: }
8700:
1.1041 www 8701: sub modal_adhoc_inner {
8702: my ($funcname,$width,$height,$content)=@_;
8703: my $innerwidth=$width-20;
8704: $content=&js_ready(
1.1140 raeburn 8705: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8706: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8707: $content.
1.1041 www 8708: &end_scrollbox().
1.1140 raeburn 8709: &end_page()
1.1041 www 8710: );
8711: return &modal_adhoc_script($funcname,$width,$height,$content);
8712: }
8713:
8714: sub modal_adhoc_window {
8715: my ($funcname,$width,$height,$content,$linktext)=@_;
8716: return &modal_adhoc_inner($funcname,$width,$height,$content).
8717: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8718: }
8719:
8720: sub modal_adhoc_launch {
8721: my ($funcname,$width,$height,$content)=@_;
8722: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8723: <script type="text/javascript">
8724: // <![CDATA[
8725: $funcname();
8726: // ]]>
8727: </script>
8728: ENDLAUNCH
8729: }
8730:
8731: sub modal_adhoc_close {
8732: return (<<ENDCLOSE);
8733: <script type="text/javascript">
8734: // <![CDATA[
8735: modalWindow.close();
8736: // ]]>
8737: </script>
8738: ENDCLOSE
8739: }
8740:
1.1038 www 8741: sub togglebox_script {
8742: return(<<ENDTOGGLE);
8743: <script type="text/javascript">
8744: // <![CDATA[
8745: function LCtoggleDisplay(id,hidetext,showtext) {
8746: link = document.getElementById(id + "link").childNodes[0];
8747: with (document.getElementById(id).style) {
8748: if (display == "none" ) {
8749: display = "inline";
8750: link.nodeValue = hidetext;
8751: } else {
8752: display = "none";
8753: link.nodeValue = showtext;
8754: }
8755: }
8756: }
8757: // ]]>
8758: </script>
8759: ENDTOGGLE
8760: }
8761:
1.1039 www 8762: sub start_togglebox {
8763: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8764: unless ($heading) { $heading=''; } else { $heading.=' '; }
8765: unless ($showtext) { $showtext=&mt('show'); }
8766: unless ($hidetext) { $hidetext=&mt('hide'); }
8767: unless ($headerbg) { $headerbg='#FFFFFF'; }
8768: return &start_data_table().
8769: &start_data_table_header_row().
8770: '<td bgcolor="'.$headerbg.'">'.$heading.
8771: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8772: $showtext.'\')">'.$showtext.'</a>]</td>'.
8773: &end_data_table_header_row().
8774: '<tr id="'.$id.'" style="display:none""><td>';
8775: }
8776:
8777: sub end_togglebox {
8778: return '</td></tr>'.&end_data_table();
8779: }
8780:
1.1041 www 8781: sub LCprogressbar_script {
1.1045 www 8782: my ($id)=@_;
1.1041 www 8783: return(<<ENDPROGRESS);
8784: <script type="text/javascript">
8785: // <![CDATA[
1.1045 www 8786: \$('#progressbar$id').progressbar({
1.1041 www 8787: value: 0,
8788: change: function(event, ui) {
8789: var newVal = \$(this).progressbar('option', 'value');
8790: \$('.pblabel', this).text(LCprogressTxt);
8791: }
8792: });
8793: // ]]>
8794: </script>
8795: ENDPROGRESS
8796: }
8797:
8798: sub LCprogressbarUpdate_script {
8799: return(<<ENDPROGRESSUPDATE);
8800: <style type="text/css">
8801: .ui-progressbar { position:relative; }
8802: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8803: </style>
8804: <script type="text/javascript">
8805: // <![CDATA[
1.1045 www 8806: var LCprogressTxt='---';
8807:
8808: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8809: LCprogressTxt=progresstext;
1.1045 www 8810: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8811: }
8812: // ]]>
8813: </script>
8814: ENDPROGRESSUPDATE
8815: }
8816:
1.1042 www 8817: my $LClastpercent;
1.1045 www 8818: my $LCidcnt;
8819: my $LCcurrentid;
1.1042 www 8820:
1.1041 www 8821: sub LCprogressbar {
1.1042 www 8822: my ($r)=(@_);
8823: $LClastpercent=0;
1.1045 www 8824: $LCidcnt++;
8825: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8826: my $starting=&mt('Starting');
8827: my $content=(<<ENDPROGBAR);
1.1045 www 8828: <div id="progressbar$LCcurrentid">
1.1041 www 8829: <span class="pblabel">$starting</span>
8830: </div>
8831: ENDPROGBAR
1.1045 www 8832: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8833: }
8834:
8835: sub LCprogressbarUpdate {
1.1042 www 8836: my ($r,$val,$text)=@_;
8837: unless ($val) {
8838: if ($LClastpercent) {
8839: $val=$LClastpercent;
8840: } else {
8841: $val=0;
8842: }
8843: }
1.1041 www 8844: if ($val<0) { $val=0; }
8845: if ($val>100) { $val=0; }
1.1042 www 8846: $LClastpercent=$val;
1.1041 www 8847: unless ($text) { $text=$val.'%'; }
8848: $text=&js_ready($text);
1.1044 www 8849: &r_print($r,<<ENDUPDATE);
1.1041 www 8850: <script type="text/javascript">
8851: // <![CDATA[
1.1045 www 8852: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8853: // ]]>
8854: </script>
8855: ENDUPDATE
1.1035 www 8856: }
8857:
1.1042 www 8858: sub LCprogressbarClose {
8859: my ($r)=@_;
8860: $LClastpercent=0;
1.1044 www 8861: &r_print($r,<<ENDCLOSE);
1.1042 www 8862: <script type="text/javascript">
8863: // <![CDATA[
1.1045 www 8864: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8865: // ]]>
8866: </script>
8867: ENDCLOSE
1.1044 www 8868: }
8869:
8870: sub r_print {
8871: my ($r,$to_print)=@_;
8872: if ($r) {
8873: $r->print($to_print);
8874: $r->rflush();
8875: } else {
8876: print($to_print);
8877: }
1.1042 www 8878: }
8879:
1.320 albertel 8880: sub html_encode {
8881: my ($result) = @_;
8882:
1.322 albertel 8883: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8884:
8885: return $result;
8886: }
1.1044 www 8887:
1.317 albertel 8888: sub js_ready {
8889: my ($result) = @_;
8890:
1.323 albertel 8891: $result =~ s/[\n\r]/ /xmsg;
8892: $result =~ s/\\/\\\\/xmsg;
8893: $result =~ s/'/\\'/xmsg;
1.372 albertel 8894: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8895:
8896: return $result;
8897: }
8898:
1.315 albertel 8899: sub validate_page {
8900: if ( exists($env{'internal.start_page'})
1.316 albertel 8901: && $env{'internal.start_page'} > 1) {
8902: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8903: $env{'internal.start_page'}.' '.
1.316 albertel 8904: $ENV{'request.filename'});
1.315 albertel 8905: }
8906: if ( exists($env{'internal.end_page'})
1.316 albertel 8907: && $env{'internal.end_page'} > 1) {
8908: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8909: $env{'internal.end_page'}.' '.
1.316 albertel 8910: $env{'request.filename'});
1.315 albertel 8911: }
8912: if ( exists($env{'internal.start_page'})
8913: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8914: &Apache::lonnet::logthis('start_page called without end_page '.
8915: $env{'request.filename'});
1.315 albertel 8916: }
8917: if ( ! exists($env{'internal.start_page'})
8918: && exists($env{'internal.end_page'})) {
1.316 albertel 8919: &Apache::lonnet::logthis('end_page called without start_page'.
8920: $env{'request.filename'});
1.315 albertel 8921: }
1.306 albertel 8922: }
1.315 albertel 8923:
1.996 www 8924:
8925: sub start_scrollbox {
1.1140 raeburn 8926: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8927: unless ($outerwidth) { $outerwidth='520px'; }
8928: unless ($width) { $width='500px'; }
8929: unless ($height) { $height='200px'; }
1.1075 raeburn 8930: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8931: if ($id ne '') {
1.1140 raeburn 8932: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 8933: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8934: }
1.1075 raeburn 8935: if ($bgcolor ne '') {
8936: $tdcol = "background-color: $bgcolor;";
8937: }
1.1137 raeburn 8938: my $nicescroll_js;
8939: if ($env{'browser.mobile'}) {
1.1140 raeburn 8940: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8941: }
8942: return <<"END";
8943: $nicescroll_js
8944:
8945: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
8946: <div style="overflow:auto; width:$width; height:$height;"$div_id>
8947: END
8948: }
8949:
8950: sub end_scrollbox {
8951: return '</div></td></tr></table>';
8952: }
8953:
8954: sub nicescroll_javascript {
8955: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8956: my %options;
8957: if (ref($cursor) eq 'HASH') {
8958: %options = %{$cursor};
8959: }
8960: unless ($options{'railalign'} =~ /^left|right$/) {
8961: $options{'railalign'} = 'left';
8962: }
8963: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8964: my $function = &get_users_function();
8965: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 8966: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 8967: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 8968: }
1.1140 raeburn 8969: }
8970: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8971: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 8972: $options{'cursoropacity'}='1.0';
8973: }
1.1140 raeburn 8974: } else {
8975: $options{'cursoropacity'}='1.0';
8976: }
8977: if ($options{'cursorfixedheight'} eq 'none') {
8978: delete($options{'cursorfixedheight'});
8979: } else {
8980: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8981: }
8982: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8983: delete($options{'railoffset'});
8984: }
8985: my @niceoptions;
8986: while (my($key,$value) = each(%options)) {
8987: if ($value =~ /^\{.+\}$/) {
8988: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 8989: } else {
1.1140 raeburn 8990: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 8991: }
1.1140 raeburn 8992: }
8993: my $nicescroll_js = '
1.1137 raeburn 8994: $(document).ready(
1.1140 raeburn 8995: function() {
8996: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8997: }
1.1137 raeburn 8998: );
8999: ';
1.1140 raeburn 9000: if ($framecheck) {
9001: $nicescroll_js .= '
9002: function expand_div(caller) {
9003: if (top === self) {
9004: document.getElementById("'.$id.'").style.width = "auto";
9005: document.getElementById("'.$id.'").style.height = "auto";
9006: } else {
9007: try {
9008: if (parent.frames) {
9009: if (parent.frames.length > 1) {
9010: var framesrc = parent.frames[1].location.href;
9011: var currsrc = framesrc.replace(/\#.*$/,"");
9012: if ((caller == "search") || (currsrc == "'.$location.'")) {
9013: document.getElementById("'.$id.'").style.width = "auto";
9014: document.getElementById("'.$id.'").style.height = "auto";
9015: }
9016: }
9017: }
9018: } catch (e) {
9019: return;
9020: }
1.1137 raeburn 9021: }
1.1140 raeburn 9022: return;
1.996 www 9023: }
1.1140 raeburn 9024: ';
9025: }
9026: if ($needjsready) {
9027: $nicescroll_js = '
9028: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9029: } else {
9030: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9031: }
9032: return $nicescroll_js;
1.996 www 9033: }
9034:
1.318 albertel 9035: sub simple_error_page {
1.1150 bisitz 9036: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 9037: if (ref($args) eq 'HASH') {
9038: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
9039: } else {
9040: $msg = &mt($msg);
9041: }
1.1150 bisitz 9042:
1.318 albertel 9043: my $page =
9044: &Apache::loncommon::start_page($title).
1.1150 bisitz 9045: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9046: &Apache::loncommon::end_page();
9047: if (ref($r)) {
9048: $r->print($page);
1.327 albertel 9049: return;
1.318 albertel 9050: }
9051: return $page;
9052: }
1.347 albertel 9053:
9054: {
1.610 albertel 9055: my @row_count;
1.961 onken 9056:
9057: sub start_data_table_count {
9058: unshift(@row_count, 0);
9059: return;
9060: }
9061:
9062: sub end_data_table_count {
9063: shift(@row_count);
9064: return;
9065: }
9066:
1.347 albertel 9067: sub start_data_table {
1.1018 raeburn 9068: my ($add_class,$id) = @_;
1.422 albertel 9069: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9070: my $table_id;
9071: if (defined($id)) {
9072: $table_id = ' id="'.$id.'"';
9073: }
1.961 onken 9074: &start_data_table_count();
1.1018 raeburn 9075: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9076: }
9077:
9078: sub end_data_table {
1.961 onken 9079: &end_data_table_count();
1.389 albertel 9080: return '</table>'."\n";;
1.347 albertel 9081: }
9082:
9083: sub start_data_table_row {
1.974 wenzelju 9084: my ($add_class, $id) = @_;
1.610 albertel 9085: $row_count[0]++;
9086: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9087: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9088: $id = (' id="'.$id.'"') unless ($id eq '');
9089: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9090: }
1.471 banghart 9091:
9092: sub continue_data_table_row {
1.974 wenzelju 9093: my ($add_class, $id) = @_;
1.610 albertel 9094: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9095: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9096: $id = (' id="'.$id.'"') unless ($id eq '');
9097: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9098: }
1.347 albertel 9099:
9100: sub end_data_table_row {
1.389 albertel 9101: return '</tr>'."\n";;
1.347 albertel 9102: }
1.367 www 9103:
1.421 albertel 9104: sub start_data_table_empty_row {
1.707 bisitz 9105: # $row_count[0]++;
1.421 albertel 9106: return '<tr class="LC_empty_row" >'."\n";;
9107: }
9108:
9109: sub end_data_table_empty_row {
9110: return '</tr>'."\n";;
9111: }
9112:
1.367 www 9113: sub start_data_table_header_row {
1.389 albertel 9114: return '<tr class="LC_header_row">'."\n";;
1.367 www 9115: }
9116:
9117: sub end_data_table_header_row {
1.389 albertel 9118: return '</tr>'."\n";;
1.367 www 9119: }
1.890 droeschl 9120:
9121: sub data_table_caption {
9122: my $caption = shift;
9123: return "<caption class=\"LC_caption\">$caption</caption>";
9124: }
1.347 albertel 9125: }
9126:
1.548 albertel 9127: =pod
9128:
9129: =item * &inhibit_menu_check($arg)
9130:
9131: Checks for a inhibitmenu state and generates output to preserve it
9132:
9133: Inputs: $arg - can be any of
9134: - undef - in which case the return value is a string
9135: to add into arguments list of a uri
9136: - 'input' - in which case the return value is a HTML
9137: <form> <input> field of type hidden to
9138: preserve the value
9139: - a url - in which case the return value is the url with
9140: the neccesary cgi args added to preserve the
9141: inhibitmenu state
9142: - a ref to a url - no return value, but the string is
9143: updated to include the neccessary cgi
9144: args to preserve the inhibitmenu state
9145:
9146: =cut
9147:
9148: sub inhibit_menu_check {
9149: my ($arg) = @_;
9150: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9151: if ($arg eq 'input') {
9152: if ($env{'form.inhibitmenu'}) {
9153: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9154: } else {
9155: return
9156: }
9157: }
9158: if ($env{'form.inhibitmenu'}) {
9159: if (ref($arg)) {
9160: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9161: } elsif ($arg eq '') {
9162: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9163: } else {
9164: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9165: }
9166: }
9167: if (!ref($arg)) {
9168: return $arg;
9169: }
9170: }
9171:
1.251 albertel 9172: ###############################################
1.182 matthew 9173:
9174: =pod
9175:
1.549 albertel 9176: =back
9177:
9178: =head1 User Information Routines
9179:
9180: =over 4
9181:
1.405 albertel 9182: =item * &get_users_function()
1.182 matthew 9183:
9184: Used by &bodytag to determine the current users primary role.
9185: Returns either 'student','coordinator','admin', or 'author'.
9186:
9187: =cut
9188:
9189: ###############################################
9190: sub get_users_function {
1.815 tempelho 9191: my $function = 'norole';
1.818 tempelho 9192: if ($env{'request.role'}=~/^(st)/) {
9193: $function='student';
9194: }
1.907 raeburn 9195: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9196: $function='coordinator';
9197: }
1.258 albertel 9198: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9199: $function='admin';
9200: }
1.826 bisitz 9201: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9202: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9203: $function='author';
9204: }
9205: return $function;
1.54 www 9206: }
1.99 www 9207:
9208: ###############################################
9209:
1.233 raeburn 9210: =pod
9211:
1.821 raeburn 9212: =item * &show_course()
9213:
9214: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9215: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9216:
9217: Inputs:
9218: None
9219:
9220: Outputs:
9221: Scalar: 1 if 'Course' to be used, 0 otherwise.
9222:
9223: =cut
9224:
9225: ###############################################
9226: sub show_course {
9227: my $course = !$env{'user.adv'};
9228: if (!$env{'user.adv'}) {
9229: foreach my $env (keys(%env)) {
9230: next if ($env !~ m/^user\.priv\./);
9231: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9232: $course = 0;
9233: last;
9234: }
9235: }
9236: }
9237: return $course;
9238: }
9239:
9240: ###############################################
9241:
9242: =pod
9243:
1.542 raeburn 9244: =item * &check_user_status()
1.274 raeburn 9245:
9246: Determines current status of supplied role for a
9247: specific user. Roles can be active, previous or future.
9248:
9249: Inputs:
9250: user's domain, user's username, course's domain,
1.375 raeburn 9251: course's number, optional section ID.
1.274 raeburn 9252:
9253: Outputs:
9254: role status: active, previous or future.
9255:
9256: =cut
9257:
9258: sub check_user_status {
1.412 raeburn 9259: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9260: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9261: my @uroles = keys(%userinfo);
1.274 raeburn 9262: my $srchstr;
9263: my $active_chk = 'none';
1.412 raeburn 9264: my $now = time;
1.274 raeburn 9265: if (@uroles > 0) {
1.908 raeburn 9266: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9267: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9268: } else {
1.412 raeburn 9269: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9270: }
9271: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9272: my $role_end = 0;
9273: my $role_start = 0;
9274: $active_chk = 'active';
1.412 raeburn 9275: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9276: $role_end = $1;
9277: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9278: $role_start = $1;
1.274 raeburn 9279: }
9280: }
9281: if ($role_start > 0) {
1.412 raeburn 9282: if ($now < $role_start) {
1.274 raeburn 9283: $active_chk = 'future';
9284: }
9285: }
9286: if ($role_end > 0) {
1.412 raeburn 9287: if ($now > $role_end) {
1.274 raeburn 9288: $active_chk = 'previous';
9289: }
9290: }
9291: }
9292: }
9293: return $active_chk;
9294: }
9295:
9296: ###############################################
9297:
9298: =pod
9299:
1.405 albertel 9300: =item * &get_sections()
1.233 raeburn 9301:
9302: Determines all the sections for a course including
9303: sections with students and sections containing other roles.
1.419 raeburn 9304: Incoming parameters:
9305:
9306: 1. domain
9307: 2. course number
9308: 3. reference to array containing roles for which sections should
9309: be gathered (optional).
9310: 4. reference to array containing status types for which sections
9311: should be gathered (optional).
9312:
9313: If the third argument is undefined, sections are gathered for any role.
9314: If the fourth argument is undefined, sections are gathered for any status.
9315: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9316:
1.374 raeburn 9317: Returns section hash (keys are section IDs, values are
9318: number of users in each section), subject to the
1.419 raeburn 9319: optional roles filter, optional status filter
1.233 raeburn 9320:
9321: =cut
9322:
9323: ###############################################
9324: sub get_sections {
1.419 raeburn 9325: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9326: if (!defined($cdom) || !defined($cnum)) {
9327: my $cid = $env{'request.course.id'};
9328:
9329: return if (!defined($cid));
9330:
9331: $cdom = $env{'course.'.$cid.'.domain'};
9332: $cnum = $env{'course.'.$cid.'.num'};
9333: }
9334:
9335: my %sectioncount;
1.419 raeburn 9336: my $now = time;
1.240 albertel 9337:
1.1118 raeburn 9338: my $check_students = 1;
9339: my $only_students = 0;
9340: if (ref($possible_roles) eq 'ARRAY') {
9341: if (grep(/^st$/,@{$possible_roles})) {
9342: if (@{$possible_roles} == 1) {
9343: $only_students = 1;
9344: }
9345: } else {
9346: $check_students = 0;
9347: }
9348: }
9349:
9350: if ($check_students) {
1.276 albertel 9351: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9352: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9353: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9354: my $start_index = &Apache::loncoursedata::CL_START();
9355: my $end_index = &Apache::loncoursedata::CL_END();
9356: my $status;
1.366 albertel 9357: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9358: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9359: $data->[$status_index],
9360: $data->[$start_index],
9361: $data->[$end_index]);
9362: if ($stu_status eq 'Active') {
9363: $status = 'active';
9364: } elsif ($end < $now) {
9365: $status = 'previous';
9366: } elsif ($start > $now) {
9367: $status = 'future';
9368: }
9369: if ($section ne '-1' && $section !~ /^\s*$/) {
9370: if ((!defined($possible_status)) || (($status ne '') &&
9371: (grep/^\Q$status\E$/,@{$possible_status}))) {
9372: $sectioncount{$section}++;
9373: }
1.240 albertel 9374: }
9375: }
9376: }
1.1118 raeburn 9377: if ($only_students) {
9378: return %sectioncount;
9379: }
1.240 albertel 9380: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9381: foreach my $user (sort(keys(%courseroles))) {
9382: if ($user !~ /^(\w{2})/) { next; }
9383: my ($role) = ($user =~ /^(\w{2})/);
9384: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9385: my ($section,$status);
1.240 albertel 9386: if ($role eq 'cr' &&
9387: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9388: $section=$1;
9389: }
9390: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9391: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9392: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9393: if ($end == -1 && $start == -1) {
9394: next; #deleted role
9395: }
9396: if (!defined($possible_status)) {
9397: $sectioncount{$section}++;
9398: } else {
9399: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9400: $status = 'active';
9401: } elsif ($end < $now) {
9402: $status = 'future';
9403: } elsif ($start > $now) {
9404: $status = 'previous';
9405: }
9406: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9407: $sectioncount{$section}++;
9408: }
9409: }
1.233 raeburn 9410: }
1.366 albertel 9411: return %sectioncount;
1.233 raeburn 9412: }
9413:
1.274 raeburn 9414: ###############################################
1.294 raeburn 9415:
9416: =pod
1.405 albertel 9417:
9418: =item * &get_course_users()
9419:
1.275 raeburn 9420: Retrieves usernames:domains for users in the specified course
9421: with specific role(s), and access status.
9422:
9423: Incoming parameters:
1.277 albertel 9424: 1. course domain
9425: 2. course number
9426: 3. access status: users must have - either active,
1.275 raeburn 9427: previous, future, or all.
1.277 albertel 9428: 4. reference to array of permissible roles
1.288 raeburn 9429: 5. reference to array of section restrictions (optional)
9430: 6. reference to results object (hash of hashes).
9431: 7. reference to optional userdata hash
1.609 raeburn 9432: 8. reference to optional statushash
1.630 raeburn 9433: 9. flag if privileged users (except those set to unhide in
9434: course settings) should be excluded
1.609 raeburn 9435: Keys of top level results hash are roles.
1.275 raeburn 9436: Keys of inner hashes are username:domain, with
9437: values set to access type.
1.288 raeburn 9438: Optional userdata hash returns an array with arguments in the
9439: same order as loncoursedata::get_classlist() for student data.
9440:
1.609 raeburn 9441: Optional statushash returns
9442:
1.288 raeburn 9443: Entries for end, start, section and status are blank because
9444: of the possibility of multiple values for non-student roles.
9445:
1.275 raeburn 9446: =cut
1.405 albertel 9447:
1.275 raeburn 9448: ###############################################
1.405 albertel 9449:
1.275 raeburn 9450: sub get_course_users {
1.630 raeburn 9451: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9452: my %idx = ();
1.419 raeburn 9453: my %seclists;
1.288 raeburn 9454:
9455: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9456: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9457: $idx{end} = &Apache::loncoursedata::CL_END();
9458: $idx{start} = &Apache::loncoursedata::CL_START();
9459: $idx{id} = &Apache::loncoursedata::CL_ID();
9460: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9461: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9462: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9463:
1.290 albertel 9464: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9465: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9466: my $now = time;
1.277 albertel 9467: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9468: my $match = 0;
1.412 raeburn 9469: my $secmatch = 0;
1.419 raeburn 9470: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9471: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9472: if ($section eq '') {
9473: $section = 'none';
9474: }
1.291 albertel 9475: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9476: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9477: $secmatch = 1;
9478: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9479: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9480: $secmatch = 1;
9481: }
9482: } else {
1.419 raeburn 9483: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9484: $secmatch = 1;
9485: }
1.290 albertel 9486: }
1.412 raeburn 9487: if (!$secmatch) {
9488: next;
9489: }
1.419 raeburn 9490: }
1.275 raeburn 9491: if (defined($$types{'active'})) {
1.288 raeburn 9492: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9493: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9494: $match = 1;
1.275 raeburn 9495: }
9496: }
9497: if (defined($$types{'previous'})) {
1.609 raeburn 9498: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9499: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9500: $match = 1;
1.275 raeburn 9501: }
9502: }
9503: if (defined($$types{'future'})) {
1.609 raeburn 9504: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9505: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9506: $match = 1;
1.275 raeburn 9507: }
9508: }
1.609 raeburn 9509: if ($match) {
9510: push(@{$seclists{$student}},$section);
9511: if (ref($userdata) eq 'HASH') {
9512: $$userdata{$student} = $$classlist{$student};
9513: }
9514: if (ref($statushash) eq 'HASH') {
9515: $statushash->{$student}{'st'}{$section} = $status;
9516: }
1.288 raeburn 9517: }
1.275 raeburn 9518: }
9519: }
1.412 raeburn 9520: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9521: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9522: my $now = time;
1.609 raeburn 9523: my %displaystatus = ( previous => 'Expired',
9524: active => 'Active',
9525: future => 'Future',
9526: );
1.1121 raeburn 9527: my (%nothide,@possdoms);
1.630 raeburn 9528: if ($hidepriv) {
9529: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9530: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9531: if ($user !~ /:/) {
9532: $nothide{join(':',split(/[\@]/,$user))}=1;
9533: } else {
9534: $nothide{$user} = 1;
9535: }
9536: }
1.1121 raeburn 9537: my @possdoms = ($cdom);
9538: if ($coursehash{'checkforpriv'}) {
9539: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9540: }
1.630 raeburn 9541: }
1.439 raeburn 9542: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9543: my $match = 0;
1.412 raeburn 9544: my $secmatch = 0;
1.439 raeburn 9545: my $status;
1.412 raeburn 9546: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9547: $user =~ s/:$//;
1.439 raeburn 9548: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9549: if ($end == -1 || $start == -1) {
9550: next;
9551: }
9552: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9553: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9554: my ($uname,$udom) = split(/:/,$user);
9555: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9556: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9557: $secmatch = 1;
9558: } elsif ($usec eq '') {
1.420 albertel 9559: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9560: $secmatch = 1;
9561: }
9562: } else {
9563: if (grep(/^\Q$usec\E$/,@{$sections})) {
9564: $secmatch = 1;
9565: }
9566: }
9567: if (!$secmatch) {
9568: next;
9569: }
1.288 raeburn 9570: }
1.419 raeburn 9571: if ($usec eq '') {
9572: $usec = 'none';
9573: }
1.275 raeburn 9574: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9575: if ($hidepriv) {
1.1121 raeburn 9576: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9577: (!$nothide{$uname.':'.$udom})) {
9578: next;
9579: }
9580: }
1.503 raeburn 9581: if ($end > 0 && $end < $now) {
1.439 raeburn 9582: $status = 'previous';
9583: } elsif ($start > $now) {
9584: $status = 'future';
9585: } else {
9586: $status = 'active';
9587: }
1.277 albertel 9588: foreach my $type (keys(%{$types})) {
1.275 raeburn 9589: if ($status eq $type) {
1.420 albertel 9590: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9591: push(@{$$users{$role}{$user}},$type);
9592: }
1.288 raeburn 9593: $match = 1;
9594: }
9595: }
1.419 raeburn 9596: if (($match) && (ref($userdata) eq 'HASH')) {
9597: if (!exists($$userdata{$uname.':'.$udom})) {
9598: &get_user_info($udom,$uname,\%idx,$userdata);
9599: }
1.420 albertel 9600: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9601: push(@{$seclists{$uname.':'.$udom}},$usec);
9602: }
1.609 raeburn 9603: if (ref($statushash) eq 'HASH') {
9604: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9605: }
1.275 raeburn 9606: }
9607: }
9608: }
9609: }
1.290 albertel 9610: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9611: if ((defined($cdom)) && (defined($cnum))) {
9612: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9613: if ( defined($csettings{'internal.courseowner'}) ) {
9614: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9615: next if ($owner eq '');
9616: my ($ownername,$ownerdom);
9617: if ($owner =~ /^([^:]+):([^:]+)$/) {
9618: $ownername = $1;
9619: $ownerdom = $2;
9620: } else {
9621: $ownername = $owner;
9622: $ownerdom = $cdom;
9623: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9624: }
9625: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9626: if (defined($userdata) &&
1.609 raeburn 9627: !exists($$userdata{$owner})) {
9628: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9629: if (!grep(/^none$/,@{$seclists{$owner}})) {
9630: push(@{$seclists{$owner}},'none');
9631: }
9632: if (ref($statushash) eq 'HASH') {
9633: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9634: }
1.290 albertel 9635: }
1.279 raeburn 9636: }
9637: }
9638: }
1.419 raeburn 9639: foreach my $user (keys(%seclists)) {
9640: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9641: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9642: }
1.275 raeburn 9643: }
9644: return;
9645: }
9646:
1.288 raeburn 9647: sub get_user_info {
9648: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9649: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9650: &plainname($uname,$udom,'lastname');
1.291 albertel 9651: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9652: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9653: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9654: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9655: return;
9656: }
1.275 raeburn 9657:
1.472 raeburn 9658: ###############################################
9659:
9660: =pod
9661:
9662: =item * &get_user_quota()
9663:
1.1134 raeburn 9664: Retrieves quota assigned for storage of user files.
9665: Default is to report quota for portfolio files.
1.472 raeburn 9666:
9667: Incoming parameters:
9668: 1. user's username
9669: 2. user's domain
1.1134 raeburn 9670: 3. quota name - portfolio, author, or course
1.1136 raeburn 9671: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 9672: 4. crstype - official, unofficial, textbook, placement or community,
9673: if quota name is course
1.472 raeburn 9674:
9675: Returns:
1.1163 raeburn 9676: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9677: 2. (Optional) Type of setting: custom or default
9678: (individually assigned or default for user's
9679: institutional status).
9680: 3. (Optional) - User's institutional status (e.g., faculty, staff
9681: or student - types as defined in localenroll::inst_usertypes
9682: for user's domain, which determines default quota for user.
9683: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9684:
9685: If a value has been stored in the user's environment,
1.536 raeburn 9686: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9687: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9688:
9689: =cut
9690:
9691: ###############################################
9692:
9693:
9694: sub get_user_quota {
1.1136 raeburn 9695: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9696: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9697: if (!defined($udom)) {
9698: $udom = $env{'user.domain'};
9699: }
9700: if (!defined($uname)) {
9701: $uname = $env{'user.name'};
9702: }
9703: if (($udom eq '' || $uname eq '') ||
9704: ($udom eq 'public') && ($uname eq 'public')) {
9705: $quota = 0;
1.536 raeburn 9706: $quotatype = 'default';
9707: $defquota = 0;
1.472 raeburn 9708: } else {
1.536 raeburn 9709: my $inststatus;
1.1134 raeburn 9710: if ($quotaname eq 'course') {
9711: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9712: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9713: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9714: } else {
9715: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9716: $quota = $cenv{'internal.uploadquota'};
9717: }
1.536 raeburn 9718: } else {
1.1134 raeburn 9719: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9720: if ($quotaname eq 'author') {
9721: $quota = $env{'environment.authorquota'};
9722: } else {
9723: $quota = $env{'environment.portfolioquota'};
9724: }
9725: $inststatus = $env{'environment.inststatus'};
9726: } else {
9727: my %userenv =
9728: &Apache::lonnet::get('environment',['portfolioquota',
9729: 'authorquota','inststatus'],$udom,$uname);
9730: my ($tmp) = keys(%userenv);
9731: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9732: if ($quotaname eq 'author') {
9733: $quota = $userenv{'authorquota'};
9734: } else {
9735: $quota = $userenv{'portfolioquota'};
9736: }
9737: $inststatus = $userenv{'inststatus'};
9738: } else {
9739: undef(%userenv);
9740: }
9741: }
9742: }
9743: if ($quota eq '' || wantarray) {
9744: if ($quotaname eq 'course') {
9745: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 9746: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 9747: ($crstype eq 'community') || ($crstype eq 'textbook') ||
9748: ($crstype eq 'placement')) {
1.1136 raeburn 9749: $defquota = $domdefs{$crstype.'quota'};
9750: }
9751: if ($defquota eq '') {
9752: $defquota = 500;
9753: }
1.1134 raeburn 9754: } else {
9755: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9756: }
9757: if ($quota eq '') {
9758: $quota = $defquota;
9759: $quotatype = 'default';
9760: } else {
9761: $quotatype = 'custom';
9762: }
1.472 raeburn 9763: }
9764: }
1.536 raeburn 9765: if (wantarray) {
9766: return ($quota,$quotatype,$settingstatus,$defquota);
9767: } else {
9768: return $quota;
9769: }
1.472 raeburn 9770: }
9771:
9772: ###############################################
9773:
9774: =pod
9775:
9776: =item * &default_quota()
9777:
1.536 raeburn 9778: Retrieves default quota assigned for storage of user portfolio files,
9779: given an (optional) user's institutional status.
1.472 raeburn 9780:
9781: Incoming parameters:
1.1142 raeburn 9782:
1.472 raeburn 9783: 1. domain
1.536 raeburn 9784: 2. (Optional) institutional status(es). This is a : separated list of
9785: status types (e.g., faculty, staff, student etc.)
9786: which apply to the user for whom the default is being retrieved.
9787: If the institutional status string in undefined, the domain
1.1134 raeburn 9788: default quota will be returned.
9789: 3. quota name - portfolio, author, or course
9790: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9791:
9792: Returns:
1.1142 raeburn 9793:
1.1163 raeburn 9794: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9795: 2. (Optional) institutional type which determined the value of the
9796: default quota.
1.472 raeburn 9797:
9798: If a value has been stored in the domain's configuration db,
9799: it will return that, otherwise it returns 20 (for backwards
9800: compatibility with domains which have not set up a configuration
1.1163 raeburn 9801: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9802:
1.536 raeburn 9803: If the user's status includes multiple types (e.g., staff and student),
9804: the largest default quota which applies to the user determines the
9805: default quota returned.
9806:
1.472 raeburn 9807: =cut
9808:
9809: ###############################################
9810:
9811:
9812: sub default_quota {
1.1134 raeburn 9813: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9814: my ($defquota,$settingstatus);
9815: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9816: ['quotas'],$udom);
1.1134 raeburn 9817: my $key = 'defaultquota';
9818: if ($quotaname eq 'author') {
9819: $key = 'authorquota';
9820: }
1.622 raeburn 9821: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9822: if ($inststatus ne '') {
1.765 raeburn 9823: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9824: foreach my $item (@statuses) {
1.1134 raeburn 9825: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9826: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9827: if ($defquota eq '') {
1.1134 raeburn 9828: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9829: $settingstatus = $item;
1.1134 raeburn 9830: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9831: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9832: $settingstatus = $item;
9833: }
9834: }
1.1134 raeburn 9835: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9836: if ($quotahash{'quotas'}{$item} ne '') {
9837: if ($defquota eq '') {
9838: $defquota = $quotahash{'quotas'}{$item};
9839: $settingstatus = $item;
9840: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9841: $defquota = $quotahash{'quotas'}{$item};
9842: $settingstatus = $item;
9843: }
1.536 raeburn 9844: }
9845: }
9846: }
9847: }
9848: if ($defquota eq '') {
1.1134 raeburn 9849: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9850: $defquota = $quotahash{'quotas'}{$key}{'default'};
9851: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9852: $defquota = $quotahash{'quotas'}{'default'};
9853: }
1.536 raeburn 9854: $settingstatus = 'default';
1.1139 raeburn 9855: if ($defquota eq '') {
9856: if ($quotaname eq 'author') {
9857: $defquota = 500;
9858: }
9859: }
1.536 raeburn 9860: }
9861: } else {
9862: $settingstatus = 'default';
1.1134 raeburn 9863: if ($quotaname eq 'author') {
9864: $defquota = 500;
9865: } else {
9866: $defquota = 20;
9867: }
1.536 raeburn 9868: }
9869: if (wantarray) {
9870: return ($defquota,$settingstatus);
1.472 raeburn 9871: } else {
1.536 raeburn 9872: return $defquota;
1.472 raeburn 9873: }
9874: }
9875:
1.1135 raeburn 9876: ###############################################
9877:
9878: =pod
9879:
1.1136 raeburn 9880: =item * &excess_filesize_warning()
1.1135 raeburn 9881:
9882: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 9883: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 9884: space to be exceeded.
1.1136 raeburn 9885:
9886: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 9887: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 9888:
1.1165 raeburn 9889: Inputs: 7
1.1136 raeburn 9890: 1. username or coursenum
1.1135 raeburn 9891: 2. domain
1.1136 raeburn 9892: 3. context ('author' or 'course')
1.1135 raeburn 9893: 4. filename of file for which action is being requested
9894: 5. filesize (kB) of file
9895: 6. action being taken: copy or upload.
1.1237 raeburn 9896: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 9897:
9898: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 9899: otherwise return null.
9900:
9901: =back
1.1135 raeburn 9902:
9903: =cut
9904:
1.1136 raeburn 9905: sub excess_filesize_warning {
1.1165 raeburn 9906: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 9907: my $current_disk_usage = 0;
1.1165 raeburn 9908: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 9909: if ($context eq 'author') {
9910: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9911: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9912: } else {
9913: foreach my $subdir ('docs','supplemental') {
9914: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9915: }
9916: }
1.1135 raeburn 9917: $disk_quota = int($disk_quota * 1000);
9918: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 9919: return '<p class="LC_warning">'.
1.1135 raeburn 9920: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 9921: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9922: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 9923: $disk_quota,$current_disk_usage).
9924: '</p>';
9925: }
9926: return;
9927: }
9928:
9929: ###############################################
9930:
9931:
1.1136 raeburn 9932:
9933:
1.384 raeburn 9934: sub get_secgrprole_info {
9935: my ($cdom,$cnum,$needroles,$type) = @_;
9936: my %sections_count = &get_sections($cdom,$cnum);
9937: my @sections = (sort {$a <=> $b} keys(%sections_count));
9938: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9939: my @groups = sort(keys(%curr_groups));
9940: my $allroles = [];
9941: my $rolehash;
9942: my $accesshash = {
9943: active => 'Currently has access',
9944: future => 'Will have future access',
9945: previous => 'Previously had access',
9946: };
9947: if ($needroles) {
9948: $rolehash = {'all' => 'all'};
1.385 albertel 9949: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9950: if (&Apache::lonnet::error(%user_roles)) {
9951: undef(%user_roles);
9952: }
9953: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9954: my ($role)=split(/\:/,$item,2);
9955: if ($role eq 'cr') { next; }
9956: if ($role =~ /^cr/) {
9957: $$rolehash{$role} = (split('/',$role))[3];
9958: } else {
9959: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9960: }
9961: }
9962: foreach my $key (sort(keys(%{$rolehash}))) {
9963: push(@{$allroles},$key);
9964: }
9965: push (@{$allroles},'st');
9966: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9967: }
9968: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9969: }
9970:
1.555 raeburn 9971: sub user_picker {
1.1255 raeburn 9972: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom) = @_;
1.555 raeburn 9973: my $currdom = $dom;
1.1253 raeburn 9974: my @alldoms = &Apache::lonnet::all_domains();
9975: if (@alldoms == 1) {
9976: my %domsrch = &Apache::lonnet::get_dom('configuration',
9977: ['directorysrch'],$alldoms[0]);
9978: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
9979: my $showdom = $domdesc;
9980: if ($showdom eq '') {
9981: $showdom = $dom;
9982: }
9983: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
9984: if ((!$domsrch{'directorysrch'}{'available'}) &&
9985: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
9986: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
9987: }
9988: }
9989: }
1.555 raeburn 9990: my %curr_selected = (
9991: srchin => 'dom',
1.580 raeburn 9992: srchby => 'lastname',
1.555 raeburn 9993: );
9994: my $srchterm;
1.625 raeburn 9995: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9996: if ($srch->{'srchby'} ne '') {
9997: $curr_selected{'srchby'} = $srch->{'srchby'};
9998: }
9999: if ($srch->{'srchin'} ne '') {
10000: $curr_selected{'srchin'} = $srch->{'srchin'};
10001: }
10002: if ($srch->{'srchtype'} ne '') {
10003: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10004: }
10005: if ($srch->{'srchdomain'} ne '') {
10006: $currdom = $srch->{'srchdomain'};
10007: }
10008: $srchterm = $srch->{'srchterm'};
10009: }
1.1222 damieng 10010: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10011: 'usr' => 'Search criteria',
1.563 raeburn 10012: 'doma' => 'Domain/institution to search',
1.558 albertel 10013: 'uname' => 'username',
10014: 'lastname' => 'last name',
1.555 raeburn 10015: 'lastfirst' => 'last name, first name',
1.558 albertel 10016: 'crs' => 'in this course',
1.576 raeburn 10017: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10018: 'alc' => 'all LON-CAPA',
1.573 raeburn 10019: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10020: 'exact' => 'is',
10021: 'contains' => 'contains',
1.569 raeburn 10022: 'begins' => 'begins with',
1.1222 damieng 10023: );
10024: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10025: 'youm' => "You must include some text to search for.",
10026: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10027: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10028: 'yomc' => "You must choose a domain when using an institutional directory search.",
10029: 'ymcd' => "You must choose a domain when using a domain search.",
10030: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10031: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10032: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10033: );
1.1222 damieng 10034: &html_escape(\%html_lt);
10035: &js_escape(\%js_lt);
1.1255 raeburn 10036: my $domform;
10037: if ($fixeddom) {
10038: $domform = &select_dom_form($currdom,'srchdomain',1,1,undef,[$currdom]);
10039: } else {
10040: $domform = &select_dom_form($currdom,'srchdomain',1,1);
10041: }
1.563 raeburn 10042: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10043:
10044: my @srchins = ('crs','dom','alc','instd');
10045:
10046: foreach my $option (@srchins) {
10047: # FIXME 'alc' option unavailable until
10048: # loncreateuser::print_user_query_page()
10049: # has been completed.
10050: next if ($option eq 'alc');
1.880 raeburn 10051: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10052: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 10053: if ($curr_selected{'srchin'} eq $option) {
10054: $srchinsel .= '
1.1222 damieng 10055: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10056: } else {
10057: $srchinsel .= '
1.1222 damieng 10058: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10059: }
1.555 raeburn 10060: }
1.563 raeburn 10061: $srchinsel .= "\n </select>\n";
1.555 raeburn 10062:
10063: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10064: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10065: if ($curr_selected{'srchby'} eq $option) {
10066: $srchbysel .= '
1.1222 damieng 10067: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10068: } else {
10069: $srchbysel .= '
1.1222 damieng 10070: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10071: }
10072: }
10073: $srchbysel .= "\n </select>\n";
10074:
10075: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10076: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10077: if ($curr_selected{'srchtype'} eq $option) {
10078: $srchtypesel .= '
1.1222 damieng 10079: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10080: } else {
10081: $srchtypesel .= '
1.1222 damieng 10082: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10083: }
10084: }
10085: $srchtypesel .= "\n </select>\n";
10086:
1.558 albertel 10087: my ($newuserscript,$new_user_create);
1.994 raeburn 10088: my $context_dom = $env{'request.role.domain'};
10089: if ($context eq 'requestcrs') {
10090: if ($env{'form.coursedom'} ne '') {
10091: $context_dom = $env{'form.coursedom'};
10092: }
10093: }
1.556 raeburn 10094: if ($forcenewuser) {
1.576 raeburn 10095: if (ref($srch) eq 'HASH') {
1.994 raeburn 10096: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10097: if ($cancreate) {
10098: $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>';
10099: } else {
1.799 bisitz 10100: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10101: my %usertypetext = (
10102: official => 'institutional',
10103: unofficial => 'non-institutional',
10104: );
1.799 bisitz 10105: $new_user_create = '<p class="LC_warning">'
10106: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10107: .' '
10108: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10109: ,'<a href="'.$helplink.'">','</a>')
10110: .'</p><br />';
1.627 raeburn 10111: }
1.576 raeburn 10112: }
10113: }
10114:
1.556 raeburn 10115: $newuserscript = <<"ENDSCRIPT";
10116:
1.570 raeburn 10117: function setSearch(createnew,callingForm) {
1.556 raeburn 10118: if (createnew == 1) {
1.570 raeburn 10119: for (var i=0; i<callingForm.srchby.length; i++) {
10120: if (callingForm.srchby.options[i].value == 'uname') {
10121: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10122: }
10123: }
1.570 raeburn 10124: for (var i=0; i<callingForm.srchin.length; i++) {
10125: if ( callingForm.srchin.options[i].value == 'dom') {
10126: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10127: }
10128: }
1.570 raeburn 10129: for (var i=0; i<callingForm.srchtype.length; i++) {
10130: if (callingForm.srchtype.options[i].value == 'exact') {
10131: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10132: }
10133: }
1.570 raeburn 10134: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10135: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10136: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10137: }
10138: }
10139: }
10140: }
10141: ENDSCRIPT
1.558 albertel 10142:
1.556 raeburn 10143: }
10144:
1.555 raeburn 10145: my $output = <<"END_BLOCK";
1.556 raeburn 10146: <script type="text/javascript">
1.824 bisitz 10147: // <![CDATA[
1.570 raeburn 10148: function validateEntry(callingForm) {
1.558 albertel 10149:
1.556 raeburn 10150: var checkok = 1;
1.558 albertel 10151: var srchin;
1.570 raeburn 10152: for (var i=0; i<callingForm.srchin.length; i++) {
10153: if ( callingForm.srchin[i].checked ) {
10154: srchin = callingForm.srchin[i].value;
1.558 albertel 10155: }
10156: }
10157:
1.570 raeburn 10158: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10159: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10160: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10161: var srchterm = callingForm.srchterm.value;
10162: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10163: var msg = "";
10164:
10165: if (srchterm == "") {
10166: checkok = 0;
1.1222 damieng 10167: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10168: }
10169:
1.569 raeburn 10170: if (srchtype== 'begins') {
10171: if (srchterm.length < 2) {
10172: checkok = 0;
1.1222 damieng 10173: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10174: }
10175: }
10176:
1.556 raeburn 10177: if (srchtype== 'contains') {
10178: if (srchterm.length < 3) {
10179: checkok = 0;
1.1222 damieng 10180: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10181: }
10182: }
10183: if (srchin == 'instd') {
10184: if (srchdomain == '') {
10185: checkok = 0;
1.1222 damieng 10186: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10187: }
10188: }
10189: if (srchin == 'dom') {
10190: if (srchdomain == '') {
10191: checkok = 0;
1.1222 damieng 10192: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10193: }
10194: }
10195: if (srchby == 'lastfirst') {
10196: if (srchterm.indexOf(",") == -1) {
10197: checkok = 0;
1.1222 damieng 10198: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10199: }
10200: if (srchterm.indexOf(",") == srchterm.length -1) {
10201: checkok = 0;
1.1222 damieng 10202: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10203: }
10204: }
10205: if (checkok == 0) {
1.1222 damieng 10206: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10207: return;
10208: }
10209: if (checkok == 1) {
1.570 raeburn 10210: callingForm.submit();
1.556 raeburn 10211: }
10212: }
10213:
10214: $newuserscript
10215:
1.824 bisitz 10216: // ]]>
1.556 raeburn 10217: </script>
1.558 albertel 10218:
10219: $new_user_create
10220:
1.555 raeburn 10221: END_BLOCK
1.558 albertel 10222:
1.876 raeburn 10223: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10224: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10225: $domform.
10226: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10227: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10228: $srchbysel.
10229: $srchtypesel.
10230: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10231: $srchinsel.
10232: &Apache::lonhtmlcommon::row_closure(1).
10233: &Apache::lonhtmlcommon::end_pick_box().
10234: '<br />';
1.1253 raeburn 10235: return ($output,1);
1.555 raeburn 10236: }
10237:
1.612 raeburn 10238: sub user_rule_check {
1.615 raeburn 10239: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10240: my ($response,%inst_response);
1.612 raeburn 10241: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10242: if (keys(%{$usershash}) > 1) {
10243: my (%by_username,%by_id,%userdoms);
10244: my $checkid;
10245: if (ref($checks) eq 'HASH') {
10246: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10247: $checkid = 1;
10248: }
10249: }
10250: foreach my $user (keys(%{$usershash})) {
10251: my ($uname,$udom) = split(/:/,$user);
10252: if ($checkid) {
10253: if (ref($usershash->{$user}) eq 'HASH') {
10254: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10255: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10256: $userdoms{$udom} = 1;
1.1227 raeburn 10257: if (ref($inst_results) eq 'HASH') {
10258: $inst_results->{$uname.':'.$udom} = {};
10259: }
1.1226 raeburn 10260: }
10261: }
10262: } else {
10263: $by_username{$udom}{$uname} = 1;
10264: $userdoms{$udom} = 1;
1.1227 raeburn 10265: if (ref($inst_results) eq 'HASH') {
10266: $inst_results->{$uname.':'.$udom} = {};
10267: }
1.1226 raeburn 10268: }
10269: }
10270: foreach my $udom (keys(%userdoms)) {
10271: if (!$got_rules->{$udom}) {
10272: my %domconfig = &Apache::lonnet::get_dom('configuration',
10273: ['usercreation'],$udom);
10274: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10275: foreach my $item ('username','id') {
10276: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10277: $$curr_rules{$udom}{$item} =
10278: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10279: }
10280: }
10281: }
10282: $got_rules->{$udom} = 1;
10283: }
1.612 raeburn 10284: }
1.1226 raeburn 10285: if ($checkid) {
10286: foreach my $udom (keys(%by_id)) {
10287: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10288: if ($outcome eq 'ok') {
1.1227 raeburn 10289: foreach my $id (keys(%{$by_id{$udom}})) {
10290: my $uname = $by_id{$udom}{$id};
10291: $inst_response{$uname.':'.$udom} = $outcome;
10292: }
1.1226 raeburn 10293: if (ref($results) eq 'HASH') {
10294: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10295: if (exists($inst_response{$uname.':'.$udom})) {
10296: $inst_response{$uname.':'.$udom} = $outcome;
10297: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10298: }
1.1226 raeburn 10299: }
10300: }
10301: }
1.612 raeburn 10302: }
1.615 raeburn 10303: } else {
1.1226 raeburn 10304: foreach my $udom (keys(%by_username)) {
10305: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10306: if ($outcome eq 'ok') {
1.1227 raeburn 10307: foreach my $uname (keys(%{$by_username{$udom}})) {
10308: $inst_response{$uname.':'.$udom} = $outcome;
10309: }
1.1226 raeburn 10310: if (ref($results) eq 'HASH') {
10311: foreach my $uname (keys(%{$results})) {
10312: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10313: }
10314: }
10315: }
10316: }
1.612 raeburn 10317: }
1.1226 raeburn 10318: } elsif (keys(%{$usershash}) == 1) {
10319: my $user = (keys(%{$usershash}))[0];
10320: my ($uname,$udom) = split(/:/,$user);
10321: if (($udom ne '') && ($uname ne '')) {
10322: if (ref($usershash->{$user}) eq 'HASH') {
10323: if (ref($checks) eq 'HASH') {
10324: if (defined($checks->{'username'})) {
10325: ($inst_response{$user},%{$inst_results->{$user}}) =
10326: &Apache::lonnet::get_instuser($udom,$uname);
10327: } elsif (defined($checks->{'id'})) {
10328: if ($usershash->{$user}->{'id'} ne '') {
10329: ($inst_response{$user},%{$inst_results->{$user}}) =
10330: &Apache::lonnet::get_instuser($udom,undef,
10331: $usershash->{$user}->{'id'});
10332: } else {
10333: ($inst_response{$user},%{$inst_results->{$user}}) =
10334: &Apache::lonnet::get_instuser($udom,$uname);
10335: }
1.585 raeburn 10336: }
1.1226 raeburn 10337: } else {
10338: ($inst_response{$user},%{$inst_results->{$user}}) =
10339: &Apache::lonnet::get_instuser($udom,$uname);
10340: return;
10341: }
10342: if (!$got_rules->{$udom}) {
10343: my %domconfig = &Apache::lonnet::get_dom('configuration',
10344: ['usercreation'],$udom);
10345: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10346: foreach my $item ('username','id') {
10347: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10348: $$curr_rules{$udom}{$item} =
10349: $domconfig{'usercreation'}{$item.'_rule'};
10350: }
10351: }
10352: }
10353: $got_rules->{$udom} = 1;
1.585 raeburn 10354: }
10355: }
1.1226 raeburn 10356: } else {
10357: return;
10358: }
10359: } else {
10360: return;
10361: }
10362: foreach my $user (keys(%{$usershash})) {
10363: my ($uname,$udom) = split(/:/,$user);
10364: next if (($udom eq '') || ($uname eq ''));
10365: my $id;
1.1227 raeburn 10366: if (ref($inst_results) eq 'HASH') {
10367: if (ref($inst_results->{$user}) eq 'HASH') {
10368: $id = $inst_results->{$user}->{'id'};
10369: }
10370: }
10371: if ($id eq '') {
10372: if (ref($usershash->{$user})) {
10373: $id = $usershash->{$user}->{'id'};
10374: }
1.585 raeburn 10375: }
1.612 raeburn 10376: foreach my $item (keys(%{$checks})) {
10377: if (ref($$curr_rules{$udom}) eq 'HASH') {
10378: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10379: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10380: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10381: $$curr_rules{$udom}{$item});
1.612 raeburn 10382: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10383: if ($rule_check{$rule}) {
10384: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10385: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10386: if (ref($inst_results) eq 'HASH') {
10387: if (ref($inst_results->{$user}) eq 'HASH') {
10388: if (keys(%{$inst_results->{$user}}) == 0) {
10389: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10390: } elsif ($item eq 'id') {
10391: if ($inst_results->{$user}->{'id'} eq '') {
10392: $$alerts{$item}{$udom}{$uname} = 1;
10393: }
1.615 raeburn 10394: }
1.612 raeburn 10395: }
10396: }
1.615 raeburn 10397: }
10398: last;
1.585 raeburn 10399: }
10400: }
10401: }
10402: }
10403: }
10404: }
10405: }
10406: }
1.612 raeburn 10407: return;
10408: }
10409:
10410: sub user_rule_formats {
10411: my ($domain,$domdesc,$curr_rules,$check) = @_;
10412: my %text = (
10413: 'username' => 'Usernames',
10414: 'id' => 'IDs',
10415: );
10416: my $output;
10417: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10418: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10419: if (@{$ruleorder} > 0) {
1.1102 raeburn 10420: $output = '<br />'.
10421: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10422: '<span class="LC_cusr_emph">','</span>',$domdesc).
10423: ' <ul>';
1.612 raeburn 10424: foreach my $rule (@{$ruleorder}) {
10425: if (ref($curr_rules) eq 'ARRAY') {
10426: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10427: if (ref($rules->{$rule}) eq 'HASH') {
10428: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10429: $rules->{$rule}{'desc'}.'</li>';
10430: }
10431: }
10432: }
10433: }
10434: $output .= '</ul>';
10435: }
10436: }
10437: return $output;
10438: }
10439:
10440: sub instrule_disallow_msg {
1.615 raeburn 10441: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10442: my $response;
10443: my %text = (
10444: item => 'username',
10445: items => 'usernames',
10446: match => 'matches',
10447: do => 'does',
10448: action => 'a username',
10449: one => 'one',
10450: );
10451: if ($count > 1) {
10452: $text{'item'} = 'usernames';
10453: $text{'match'} ='match';
10454: $text{'do'} = 'do';
10455: $text{'action'} = 'usernames',
10456: $text{'one'} = 'ones';
10457: }
10458: if ($checkitem eq 'id') {
10459: $text{'items'} = 'IDs';
10460: $text{'item'} = 'ID';
10461: $text{'action'} = 'an ID';
1.615 raeburn 10462: if ($count > 1) {
10463: $text{'item'} = 'IDs';
10464: $text{'action'} = 'IDs';
10465: }
1.612 raeburn 10466: }
1.674 bisitz 10467: $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 10468: if ($mode eq 'upload') {
10469: if ($checkitem eq 'username') {
10470: $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'}.");
10471: } elsif ($checkitem eq 'id') {
1.674 bisitz 10472: $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 10473: }
1.669 raeburn 10474: } elsif ($mode eq 'selfcreate') {
10475: if ($checkitem eq 'id') {
10476: $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.");
10477: }
1.615 raeburn 10478: } else {
10479: if ($checkitem eq 'username') {
10480: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10481: } elsif ($checkitem eq 'id') {
10482: $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.");
10483: }
1.612 raeburn 10484: }
10485: return $response;
1.585 raeburn 10486: }
10487:
1.624 raeburn 10488: sub personal_data_fieldtitles {
10489: my %fieldtitles = &Apache::lonlocal::texthash (
10490: id => 'Student/Employee ID',
10491: permanentemail => 'E-mail address',
10492: lastname => 'Last Name',
10493: firstname => 'First Name',
10494: middlename => 'Middle Name',
10495: generation => 'Generation',
10496: gen => 'Generation',
1.765 raeburn 10497: inststatus => 'Affiliation',
1.624 raeburn 10498: );
10499: return %fieldtitles;
10500: }
10501:
1.642 raeburn 10502: sub sorted_inst_types {
10503: my ($dom) = @_;
1.1185 raeburn 10504: my ($usertypes,$order);
10505: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10506: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10507: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10508: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10509: } else {
10510: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10511: }
1.642 raeburn 10512: my $othertitle = &mt('All users');
10513: if ($env{'request.course.id'}) {
1.668 raeburn 10514: $othertitle = &mt('Any users');
1.642 raeburn 10515: }
10516: my @types;
10517: if (ref($order) eq 'ARRAY') {
10518: @types = @{$order};
10519: }
10520: if (@types == 0) {
10521: if (ref($usertypes) eq 'HASH') {
10522: @types = sort(keys(%{$usertypes}));
10523: }
10524: }
10525: if (keys(%{$usertypes}) > 0) {
10526: $othertitle = &mt('Other users');
10527: }
10528: return ($othertitle,$usertypes,\@types);
10529: }
10530:
1.645 raeburn 10531: sub get_institutional_codes {
10532: my ($settings,$allcourses,$LC_code) = @_;
10533: # Get complete list of course sections to update
10534: my @currsections = ();
10535: my @currxlists = ();
10536: my $coursecode = $$settings{'internal.coursecode'};
10537:
10538: if ($$settings{'internal.sectionnums'} ne '') {
10539: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10540: }
10541:
10542: if ($$settings{'internal.crosslistings'} ne '') {
10543: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10544: }
10545:
10546: if (@currxlists > 0) {
10547: foreach (@currxlists) {
10548: if (m/^([^:]+):(\w*)$/) {
10549: unless (grep/^$1$/,@{$allcourses}) {
10550: push @{$allcourses},$1;
10551: $$LC_code{$1} = $2;
10552: }
10553: }
10554: }
10555: }
10556:
10557: if (@currsections > 0) {
10558: foreach (@currsections) {
10559: if (m/^(\w+):(\w*)$/) {
10560: my $sec = $coursecode.$1;
10561: my $lc_sec = $2;
10562: unless (grep/^$sec$/,@{$allcourses}) {
10563: push @{$allcourses},$sec;
10564: $$LC_code{$sec} = $lc_sec;
10565: }
10566: }
10567: }
10568: }
10569: return;
10570: }
10571:
1.971 raeburn 10572: sub get_standard_codeitems {
10573: return ('Year','Semester','Department','Number','Section');
10574: }
10575:
1.112 bowersj2 10576: =pod
10577:
1.780 raeburn 10578: =head1 Slot Helpers
10579:
10580: =over 4
10581:
10582: =item * sorted_slots()
10583:
1.1040 raeburn 10584: Sorts an array of slot names in order of an optional sort key,
10585: default sort is by slot start time (earliest first).
1.780 raeburn 10586:
10587: Inputs:
10588:
10589: =over 4
10590:
10591: slotsarr - Reference to array of unsorted slot names.
10592:
10593: slots - Reference to hash of hash, where outer hash keys are slot names.
10594:
1.1040 raeburn 10595: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10596:
1.549 albertel 10597: =back
10598:
1.780 raeburn 10599: Returns:
10600:
10601: =over 4
10602:
1.1040 raeburn 10603: sorted - An array of slot names sorted by a specified sort key
10604: (default sort key is start time of the slot).
1.780 raeburn 10605:
10606: =back
10607:
10608: =cut
10609:
10610:
10611: sub sorted_slots {
1.1040 raeburn 10612: my ($slotsarr,$slots,$sortkey) = @_;
10613: if ($sortkey eq '') {
10614: $sortkey = 'starttime';
10615: }
1.780 raeburn 10616: my @sorted;
10617: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10618: @sorted =
10619: sort {
10620: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10621: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10622: }
10623: if (ref($slots->{$a})) { return -1;}
10624: if (ref($slots->{$b})) { return 1;}
10625: return 0;
10626: } @{$slotsarr};
10627: }
10628: return @sorted;
10629: }
10630:
1.1040 raeburn 10631: =pod
10632:
10633: =item * get_future_slots()
10634:
10635: Inputs:
10636:
10637: =over 4
10638:
10639: cnum - course number
10640:
10641: cdom - course domain
10642:
10643: now - current UNIX time
10644:
10645: symb - optional symb
10646:
10647: =back
10648:
10649: Returns:
10650:
10651: =over 4
10652:
10653: sorted_reservable - ref to array of student_schedulable slots currently
10654: reservable, ordered by end date of reservation period.
10655:
10656: reservable_now - ref to hash of student_schedulable slots currently
10657: reservable.
10658:
10659: Keys in inner hash are:
10660: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10661: (b) endreserve: end date of reservation period.
10662: (c) uniqueperiod: start,end dates when slot is to be uniquely
10663: selected.
1.1040 raeburn 10664:
10665: sorted_future - ref to array of student_schedulable slots reservable in
10666: the future, ordered by start date of reservation period.
10667:
10668: future_reservable - ref to hash of student_schedulable slots reservable
10669: in the future.
10670:
10671: Keys in inner hash are:
10672: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10673: (b) startreserve: start date of reservation period.
10674: (c) uniqueperiod: start,end dates when slot is to be uniquely
10675: selected.
1.1040 raeburn 10676:
10677: =back
10678:
10679: =cut
10680:
10681: sub get_future_slots {
10682: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 10683: my $map;
10684: if ($symb) {
10685: ($map) = &Apache::lonnet::decode_symb($symb);
10686: }
1.1040 raeburn 10687: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10688: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10689: foreach my $slot (keys(%slots)) {
10690: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10691: if ($symb) {
1.1229 raeburn 10692: if ($slots{$slot}->{'symb'} ne '') {
10693: my $canuse;
10694: my %oksymbs;
10695: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
10696: map { $oksymbs{$_} = 1; } @slotsymbs;
10697: if ($oksymbs{$symb}) {
10698: $canuse = 1;
10699: } else {
10700: foreach my $item (@slotsymbs) {
10701: if ($item =~ /\.(page|sequence)$/) {
10702: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
10703: if (($map ne '') && ($map eq $sloturl)) {
10704: $canuse = 1;
10705: last;
10706: }
10707: }
10708: }
10709: }
10710: next unless ($canuse);
10711: }
1.1040 raeburn 10712: }
10713: if (($slots{$slot}->{'starttime'} > $now) &&
10714: ($slots{$slot}->{'endtime'} > $now)) {
10715: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10716: my $userallowed = 0;
10717: if ($slots{$slot}->{'allowedsections'}) {
10718: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10719: if (!defined($env{'request.role.sec'})
10720: && grep(/^No section assigned$/,@allowed_sec)) {
10721: $userallowed=1;
10722: } else {
10723: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10724: $userallowed=1;
10725: }
10726: }
10727: unless ($userallowed) {
10728: if (defined($env{'request.course.groups'})) {
10729: my @groups = split(/:/,$env{'request.course.groups'});
10730: foreach my $group (@groups) {
10731: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10732: $userallowed=1;
10733: last;
10734: }
10735: }
10736: }
10737: }
10738: }
10739: if ($slots{$slot}->{'allowedusers'}) {
10740: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10741: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10742: if (grep(/^\Q$user\E$/,@allowed_users)) {
10743: $userallowed = 1;
10744: }
10745: }
10746: next unless($userallowed);
10747: }
10748: my $startreserve = $slots{$slot}->{'startreserve'};
10749: my $endreserve = $slots{$slot}->{'endreserve'};
10750: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 10751: my $uniqueperiod;
10752: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10753: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10754: }
1.1040 raeburn 10755: if (($startreserve < $now) &&
10756: (!$endreserve || $endreserve > $now)) {
10757: my $lastres = $endreserve;
10758: if (!$lastres) {
10759: $lastres = $slots{$slot}->{'starttime'};
10760: }
10761: $reservable_now{$slot} = {
10762: symb => $symb,
1.1250 raeburn 10763: endreserve => $lastres,
10764: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10765: };
10766: } elsif (($startreserve > $now) &&
10767: (!$endreserve || $endreserve > $startreserve)) {
10768: $future_reservable{$slot} = {
10769: symb => $symb,
1.1250 raeburn 10770: startreserve => $startreserve,
10771: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10772: };
10773: }
10774: }
10775: }
10776: my @unsorted_reservable = keys(%reservable_now);
10777: if (@unsorted_reservable > 0) {
10778: @sorted_reservable =
10779: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10780: }
10781: my @unsorted_future = keys(%future_reservable);
10782: if (@unsorted_future > 0) {
10783: @sorted_future =
10784: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10785: }
10786: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10787: }
1.780 raeburn 10788:
10789: =pod
10790:
1.1057 foxr 10791: =back
10792:
1.549 albertel 10793: =head1 HTTP Helpers
10794:
10795: =over 4
10796:
1.648 raeburn 10797: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10798:
1.258 albertel 10799: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10800: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10801: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10802:
10803: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10804: $possible_names is an ref to an array of form element names. As an example:
10805: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10806: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10807:
10808: =cut
1.1 albertel 10809:
1.6 albertel 10810: sub get_unprocessed_cgi {
1.25 albertel 10811: my ($query,$possible_names)= @_;
1.26 matthew 10812: # $Apache::lonxml::debug=1;
1.356 albertel 10813: foreach my $pair (split(/&/,$query)) {
10814: my ($name, $value) = split(/=/,$pair);
1.369 www 10815: $name = &unescape($name);
1.25 albertel 10816: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10817: $value =~ tr/+/ /;
10818: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10819: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10820: }
1.16 harris41 10821: }
1.6 albertel 10822: }
10823:
1.112 bowersj2 10824: =pod
10825:
1.648 raeburn 10826: =item * &cacheheader()
1.112 bowersj2 10827:
10828: returns cache-controlling header code
10829:
10830: =cut
10831:
1.7 albertel 10832: sub cacheheader {
1.258 albertel 10833: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10834: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10835: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10836: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10837: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10838: return $output;
1.7 albertel 10839: }
10840:
1.112 bowersj2 10841: =pod
10842:
1.648 raeburn 10843: =item * &no_cache($r)
1.112 bowersj2 10844:
10845: specifies header code to not have cache
10846:
10847: =cut
10848:
1.9 albertel 10849: sub no_cache {
1.216 albertel 10850: my ($r) = @_;
10851: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10852: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10853: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10854: $r->no_cache(1);
10855: $r->header_out("Expires" => $date);
10856: $r->header_out("Pragma" => "no-cache");
1.123 www 10857: }
10858:
10859: sub content_type {
1.181 albertel 10860: my ($r,$type,$charset) = @_;
1.299 foxr 10861: if ($r) {
10862: # Note that printout.pl calls this with undef for $r.
10863: &no_cache($r);
10864: }
1.258 albertel 10865: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10866: unless ($charset) {
10867: $charset=&Apache::lonlocal::current_encoding;
10868: }
10869: if ($charset) { $type.='; charset='.$charset; }
10870: if ($r) {
10871: $r->content_type($type);
10872: } else {
10873: print("Content-type: $type\n\n");
10874: }
1.9 albertel 10875: }
1.25 albertel 10876:
1.112 bowersj2 10877: =pod
10878:
1.648 raeburn 10879: =item * &add_to_env($name,$value)
1.112 bowersj2 10880:
1.258 albertel 10881: adds $name to the %env hash with value
1.112 bowersj2 10882: $value, if $name already exists, the entry is converted to an array
10883: reference and $value is added to the array.
10884:
10885: =cut
10886:
1.25 albertel 10887: sub add_to_env {
10888: my ($name,$value)=@_;
1.258 albertel 10889: if (defined($env{$name})) {
10890: if (ref($env{$name})) {
1.25 albertel 10891: #already have multiple values
1.258 albertel 10892: push(@{ $env{$name} },$value);
1.25 albertel 10893: } else {
10894: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10895: my $first=$env{$name};
10896: undef($env{$name});
10897: push(@{ $env{$name} },$first,$value);
1.25 albertel 10898: }
10899: } else {
1.258 albertel 10900: $env{$name}=$value;
1.25 albertel 10901: }
1.31 albertel 10902: }
1.149 albertel 10903:
10904: =pod
10905:
1.648 raeburn 10906: =item * &get_env_multiple($name)
1.149 albertel 10907:
1.258 albertel 10908: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10909: values may be defined and end up as an array ref.
10910:
10911: returns an array of values
10912:
10913: =cut
10914:
10915: sub get_env_multiple {
10916: my ($name) = @_;
10917: my @values;
1.258 albertel 10918: if (defined($env{$name})) {
1.149 albertel 10919: # exists is it an array
1.258 albertel 10920: if (ref($env{$name})) {
10921: @values=@{ $env{$name} };
1.149 albertel 10922: } else {
1.258 albertel 10923: $values[0]=$env{$name};
1.149 albertel 10924: }
10925: }
10926: return(@values);
10927: }
10928:
1.1249 damieng 10929: # Looks at given dependencies, and returns something depending on the context.
10930: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
10931: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
10932: # For all other contexts, returns ($output, $counter, $numpathchg).
10933: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
10934: # $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.
10935: # $numpathchg: integer with the number of cleaned up dependency paths.
10936: # \%existing: hash reference clean path -> 1 only for existing dependencies.
10937: # \%mapping: hash reference clean path -> original path for all dependencies.
10938: # @param {string} actionurl - The path to the handler, indicative of the context.
10939: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
10940: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
10941: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
10942: # @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)
10943: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 10944: sub ask_for_embedded_content {
1.1249 damieng 10945: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 10946: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10947: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 10948: %currsubfile,%unused,$rem);
1.1071 raeburn 10949: my $counter = 0;
10950: my $numnew = 0;
1.987 raeburn 10951: my $numremref = 0;
10952: my $numinvalid = 0;
10953: my $numpathchg = 0;
10954: my $numexisting = 0;
1.1071 raeburn 10955: my $numunused = 0;
10956: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 10957: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10958: my $heading = &mt('Upload embedded files');
10959: my $buttontext = &mt('Upload');
10960:
1.1249 damieng 10961: # fills these variables based on the context:
10962: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
10963: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 10964: if ($env{'request.course.id'}) {
1.1123 raeburn 10965: if ($actionurl eq '/adm/dependencies') {
10966: $navmap = Apache::lonnavmaps::navmap->new();
10967: }
10968: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10969: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 10970: }
1.1123 raeburn 10971: if (($actionurl eq '/adm/portfolio') ||
10972: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10973: my $current_path='/';
10974: if ($env{'form.currentpath'}) {
10975: $current_path = $env{'form.currentpath'};
10976: }
10977: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 10978: $udom = $cdom;
10979: $uname = $cnum;
1.984 raeburn 10980: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10981: } else {
10982: $udom = $env{'user.domain'};
10983: $uname = $env{'user.name'};
10984: $url = '/userfiles/portfolio';
10985: }
1.987 raeburn 10986: $toplevel = $url.'/';
1.984 raeburn 10987: $url .= $current_path;
10988: $getpropath = 1;
1.987 raeburn 10989: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10990: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10991: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10992: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10993: $toplevel = $url;
1.984 raeburn 10994: if ($rest ne '') {
1.987 raeburn 10995: $url .= $rest;
10996: }
10997: } elsif ($actionurl eq '/adm/coursedocs') {
10998: if (ref($args) eq 'HASH') {
1.1071 raeburn 10999: $url = $args->{'docs_url'};
11000: $toplevel = $url;
1.1084 raeburn 11001: if ($args->{'context'} eq 'paste') {
11002: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11003: ($path) =
11004: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11005: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11006: $fileloc =~ s{^/}{};
11007: }
1.1071 raeburn 11008: }
1.1084 raeburn 11009: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11010: if ($env{'request.course.id'} ne '') {
11011: if (ref($args) eq 'HASH') {
11012: $url = $args->{'docs_url'};
11013: $title = $args->{'docs_title'};
1.1126 raeburn 11014: $toplevel = $url;
11015: unless ($toplevel =~ m{^/}) {
11016: $toplevel = "/$url";
11017: }
1.1085 raeburn 11018: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11019: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11020: $path = $1;
11021: } else {
11022: ($path) =
11023: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11024: }
1.1195 raeburn 11025: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11026: $fileloc = $toplevel;
11027: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11028: my ($udom,$uname,$fname) =
11029: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11030: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11031: } else {
11032: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11033: }
1.1071 raeburn 11034: $fileloc =~ s{^/}{};
11035: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11036: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11037: }
1.987 raeburn 11038: }
1.1123 raeburn 11039: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11040: $udom = $cdom;
11041: $uname = $cnum;
11042: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11043: $toplevel = $url;
11044: $path = $url;
11045: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11046: $fileloc =~ s{^/}{};
1.987 raeburn 11047: }
1.1249 damieng 11048:
11049: # parses the dependency paths to get some info
11050: # fills $newfiles, $mapping, $subdependencies, $dependencies
11051: # $newfiles: hash URL -> 1 for new files or external URLs
11052: # (will be completed later)
11053: # $mapping:
11054: # for external URLs: external URL -> external URL
11055: # for relative paths: clean path -> original path
11056: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11057: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11058: foreach my $file (keys(%{$allfiles})) {
11059: my $embed_file;
11060: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11061: $embed_file = $1;
11062: } else {
11063: $embed_file = $file;
11064: }
1.1158 raeburn 11065: my ($absolutepath,$cleaned_file);
11066: if ($embed_file =~ m{^\w+://}) {
11067: $cleaned_file = $embed_file;
1.1147 raeburn 11068: $newfiles{$cleaned_file} = 1;
11069: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11070: } else {
1.1158 raeburn 11071: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11072: if ($embed_file =~ m{^/}) {
11073: $absolutepath = $embed_file;
11074: }
1.1147 raeburn 11075: if ($cleaned_file =~ m{/}) {
11076: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11077: $path = &check_for_traversal($path,$url,$toplevel);
11078: my $item = $fname;
11079: if ($path ne '') {
11080: $item = $path.'/'.$fname;
11081: $subdependencies{$path}{$fname} = 1;
11082: } else {
11083: $dependencies{$item} = 1;
11084: }
11085: if ($absolutepath) {
11086: $mapping{$item} = $absolutepath;
11087: } else {
11088: $mapping{$item} = $embed_file;
11089: }
11090: } else {
11091: $dependencies{$embed_file} = 1;
11092: if ($absolutepath) {
1.1147 raeburn 11093: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11094: } else {
1.1147 raeburn 11095: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11096: }
11097: }
1.984 raeburn 11098: }
11099: }
1.1249 damieng 11100:
11101: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11102: # and lists
11103: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11104: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11105: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11106: # the path had to be cleaned up
11107: # $existing: hash clean path -> 1 if the file exists
11108: # $numexisting: number of keys in $existing
11109: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11110: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11111: # dependency subdirectories that are
11112: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11113: my $dirptr = 16384;
1.984 raeburn 11114: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11115: $currsubfile{$path} = {};
1.1123 raeburn 11116: if (($actionurl eq '/adm/portfolio') ||
11117: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11118: my ($sublistref,$listerror) =
11119: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11120: if (ref($sublistref) eq 'ARRAY') {
11121: foreach my $line (@{$sublistref}) {
11122: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11123: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11124: }
1.984 raeburn 11125: }
1.987 raeburn 11126: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11127: if (opendir(my $dir,$url.'/'.$path)) {
11128: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11129: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11130: }
1.1084 raeburn 11131: } elsif (($actionurl eq '/adm/dependencies') ||
11132: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11133: ($args->{'context'} eq 'paste')) ||
11134: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11135: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11136: my $dir;
11137: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11138: $dir = $fileloc;
11139: } else {
11140: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11141: }
1.1071 raeburn 11142: if ($dir ne '') {
11143: my ($sublistref,$listerror) =
11144: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11145: if (ref($sublistref) eq 'ARRAY') {
11146: foreach my $line (@{$sublistref}) {
11147: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11148: undef,$mtime)=split(/\&/,$line,12);
11149: unless (($testdir&$dirptr) ||
11150: ($file_name =~ /^\.\.?$/)) {
11151: $currsubfile{$path}{$file_name} = [$size,$mtime];
11152: }
11153: }
11154: }
11155: }
1.984 raeburn 11156: }
11157: }
11158: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11159: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11160: my $item = $path.'/'.$file;
11161: unless ($mapping{$item} eq $item) {
11162: $pathchanges{$item} = 1;
11163: }
11164: $existing{$item} = 1;
11165: $numexisting ++;
11166: } else {
11167: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11168: }
11169: }
1.1071 raeburn 11170: if ($actionurl eq '/adm/dependencies') {
11171: foreach my $path (keys(%currsubfile)) {
11172: if (ref($currsubfile{$path}) eq 'HASH') {
11173: foreach my $file (keys(%{$currsubfile{$path}})) {
11174: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11175: next if (($rem ne '') &&
11176: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11177: (ref($navmap) &&
11178: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11179: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11180: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11181: $unused{$path.'/'.$file} = 1;
11182: }
11183: }
11184: }
11185: }
11186: }
1.984 raeburn 11187: }
1.1249 damieng 11188:
11189: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11190: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11191: my %currfile;
1.1123 raeburn 11192: if (($actionurl eq '/adm/portfolio') ||
11193: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11194: my ($dirlistref,$listerror) =
11195: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11196: if (ref($dirlistref) eq 'ARRAY') {
11197: foreach my $line (@{$dirlistref}) {
11198: my ($file_name,$rest) = split(/\&/,$line,2);
11199: $currfile{$file_name} = 1;
11200: }
1.984 raeburn 11201: }
1.987 raeburn 11202: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11203: if (opendir(my $dir,$url)) {
1.987 raeburn 11204: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11205: map {$currfile{$_} = 1;} @dir_list;
11206: }
1.1084 raeburn 11207: } elsif (($actionurl eq '/adm/dependencies') ||
11208: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11209: ($args->{'context'} eq 'paste')) ||
11210: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11211: if ($env{'request.course.id'} ne '') {
11212: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11213: if ($dir ne '') {
11214: my ($dirlistref,$listerror) =
11215: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11216: if (ref($dirlistref) eq 'ARRAY') {
11217: foreach my $line (@{$dirlistref}) {
11218: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11219: $size,undef,$mtime)=split(/\&/,$line,12);
11220: unless (($testdir&$dirptr) ||
11221: ($file_name =~ /^\.\.?$/)) {
11222: $currfile{$file_name} = [$size,$mtime];
11223: }
11224: }
11225: }
11226: }
11227: }
1.984 raeburn 11228: }
1.1249 damieng 11229: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11230: # are not in subdirectories, using $currfile
1.984 raeburn 11231: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11232: if (exists($currfile{$file})) {
1.987 raeburn 11233: unless ($mapping{$file} eq $file) {
11234: $pathchanges{$file} = 1;
11235: }
11236: $existing{$file} = 1;
11237: $numexisting ++;
11238: } else {
1.984 raeburn 11239: $newfiles{$file} = 1;
11240: }
11241: }
1.1071 raeburn 11242: foreach my $file (keys(%currfile)) {
11243: unless (($file eq $filename) ||
11244: ($file eq $filename.'.bak') ||
11245: ($dependencies{$file})) {
1.1085 raeburn 11246: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11247: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11248: next if (($rem ne '') &&
11249: (($env{"httpref.$rem".$file} ne '') ||
11250: (ref($navmap) &&
11251: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11252: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11253: ($navmap->getResourceByUrl($rem.$1)))))));
11254: }
1.1085 raeburn 11255: }
1.1071 raeburn 11256: $unused{$file} = 1;
11257: }
11258: }
1.1249 damieng 11259:
11260: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11261: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11262: ($args->{'context'} eq 'paste')) {
11263: $counter = scalar(keys(%existing));
11264: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11265: return ($output,$counter,$numpathchg,\%existing);
11266: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11267: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11268: $counter = scalar(keys(%existing));
11269: $numpathchg = scalar(keys(%pathchanges));
11270: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11271: }
1.1249 damieng 11272:
11273: # returns HTML otherwise, with dependency results and to ask for more uploads
11274:
11275: # $upload_output: missing dependencies (with upload form)
11276: # $modify_output: uploaded dependencies (in use)
11277: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11278: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11279: if ($actionurl eq '/adm/dependencies') {
11280: next if ($embed_file =~ m{^\w+://});
11281: }
1.660 raeburn 11282: $upload_output .= &start_data_table_row().
1.1123 raeburn 11283: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11284: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11285: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11286: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11287: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11288: }
1.1123 raeburn 11289: $upload_output .= '</td>';
1.1071 raeburn 11290: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11291: $upload_output.='<td align="right">'.
11292: '<span class="LC_info LC_fontsize_medium">'.
11293: &mt("URL points to web address").'</span>';
1.987 raeburn 11294: $numremref++;
1.660 raeburn 11295: } elsif ($args->{'error_on_invalid_names'}
11296: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11297: $upload_output.='<td align="right"><span class="LC_warning">'.
11298: &mt('Invalid characters').'</span>';
1.987 raeburn 11299: $numinvalid++;
1.660 raeburn 11300: } else {
1.1123 raeburn 11301: $upload_output .= '<td>'.
11302: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11303: $embed_file,\%mapping,
1.1071 raeburn 11304: $allfiles,$codebase,'upload');
11305: $counter ++;
11306: $numnew ++;
1.987 raeburn 11307: }
11308: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11309: }
11310: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11311: if ($actionurl eq '/adm/dependencies') {
11312: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11313: $modify_output .= &start_data_table_row().
11314: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11315: '<img src="'.&icon($embed_file).'" border="0" />'.
11316: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11317: '<td>'.$size.'</td>'.
11318: '<td>'.$mtime.'</td>'.
11319: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11320: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11321: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11322: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11323: &embedded_file_element('upload_embedded',$counter,
11324: $embed_file,\%mapping,
11325: $allfiles,$codebase,'modify').
11326: '</div></td>'.
11327: &end_data_table_row()."\n";
11328: $counter ++;
11329: } else {
11330: $upload_output .= &start_data_table_row().
1.1123 raeburn 11331: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11332: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11333: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11334: &Apache::loncommon::end_data_table_row()."\n";
11335: }
11336: }
11337: my $delidx = $counter;
11338: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11339: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11340: $delete_output .= &start_data_table_row().
11341: '<td><img src="'.&icon($oldfile).'" />'.
11342: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11343: '<td>'.$size.'</td>'.
11344: '<td>'.$mtime.'</td>'.
11345: '<td><label><input type="checkbox" name="del_upload_dep" '.
11346: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11347: &embedded_file_element('upload_embedded',$delidx,
11348: $oldfile,\%mapping,$allfiles,
11349: $codebase,'delete').'</td>'.
11350: &end_data_table_row()."\n";
11351: $numunused ++;
11352: $delidx ++;
1.987 raeburn 11353: }
11354: if ($upload_output) {
11355: $upload_output = &start_data_table().
11356: $upload_output.
11357: &end_data_table()."\n";
11358: }
1.1071 raeburn 11359: if ($modify_output) {
11360: $modify_output = &start_data_table().
11361: &start_data_table_header_row().
11362: '<th>'.&mt('File').'</th>'.
11363: '<th>'.&mt('Size (KB)').'</th>'.
11364: '<th>'.&mt('Modified').'</th>'.
11365: '<th>'.&mt('Upload replacement?').'</th>'.
11366: &end_data_table_header_row().
11367: $modify_output.
11368: &end_data_table()."\n";
11369: }
11370: if ($delete_output) {
11371: $delete_output = &start_data_table().
11372: &start_data_table_header_row().
11373: '<th>'.&mt('File').'</th>'.
11374: '<th>'.&mt('Size (KB)').'</th>'.
11375: '<th>'.&mt('Modified').'</th>'.
11376: '<th>'.&mt('Delete?').'</th>'.
11377: &end_data_table_header_row().
11378: $delete_output.
11379: &end_data_table()."\n";
11380: }
1.987 raeburn 11381: my $applies = 0;
11382: if ($numremref) {
11383: $applies ++;
11384: }
11385: if ($numinvalid) {
11386: $applies ++;
11387: }
11388: if ($numexisting) {
11389: $applies ++;
11390: }
1.1071 raeburn 11391: if ($counter || $numunused) {
1.987 raeburn 11392: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11393: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11394: $state.'<h3>'.$heading.'</h3>';
11395: if ($actionurl eq '/adm/dependencies') {
11396: if ($numnew) {
11397: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11398: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11399: $upload_output.'<br />'."\n";
11400: }
11401: if ($numexisting) {
11402: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11403: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11404: $modify_output.'<br />'."\n";
11405: $buttontext = &mt('Save changes');
11406: }
11407: if ($numunused) {
11408: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11409: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11410: $delete_output.'<br />'."\n";
11411: $buttontext = &mt('Save changes');
11412: }
11413: } else {
11414: $output .= $upload_output.'<br />'."\n";
11415: }
11416: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11417: $counter.'" />'."\n";
11418: if ($actionurl eq '/adm/dependencies') {
11419: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11420: $numnew.'" />'."\n";
11421: } elsif ($actionurl eq '') {
1.987 raeburn 11422: $output .= '<input type="hidden" name="phase" value="three" />';
11423: }
11424: } elsif ($applies) {
11425: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11426: if ($applies > 1) {
11427: $output .=
1.1123 raeburn 11428: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11429: if ($numremref) {
11430: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11431: }
11432: if ($numinvalid) {
11433: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11434: }
11435: if ($numexisting) {
11436: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11437: }
11438: $output .= '</ul><br />';
11439: } elsif ($numremref) {
11440: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11441: } elsif ($numinvalid) {
11442: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11443: } elsif ($numexisting) {
11444: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11445: }
11446: $output .= $upload_output.'<br />';
11447: }
11448: my ($pathchange_output,$chgcount);
1.1071 raeburn 11449: $chgcount = $counter;
1.987 raeburn 11450: if (keys(%pathchanges) > 0) {
11451: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11452: if ($counter) {
1.987 raeburn 11453: $output .= &embedded_file_element('pathchange',$chgcount,
11454: $embed_file,\%mapping,
1.1071 raeburn 11455: $allfiles,$codebase,'change');
1.987 raeburn 11456: } else {
11457: $pathchange_output .=
11458: &start_data_table_row().
11459: '<td><input type ="checkbox" name="namechange" value="'.
11460: $chgcount.'" checked="checked" /></td>'.
11461: '<td>'.$mapping{$embed_file}.'</td>'.
11462: '<td>'.$embed_file.
11463: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11464: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11465: '</td>'.&end_data_table_row();
1.660 raeburn 11466: }
1.987 raeburn 11467: $numpathchg ++;
11468: $chgcount ++;
1.660 raeburn 11469: }
11470: }
1.1127 raeburn 11471: if (($counter) || ($numunused)) {
1.987 raeburn 11472: if ($numpathchg) {
11473: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11474: $numpathchg.'" />'."\n";
11475: }
11476: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11477: ($actionurl eq '/adm/imsimport')) {
11478: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11479: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11480: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11481: } elsif ($actionurl eq '/adm/dependencies') {
11482: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11483: }
1.1123 raeburn 11484: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11485: } elsif ($numpathchg) {
11486: my %pathchange = ();
11487: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11488: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11489: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11490: }
1.987 raeburn 11491: }
1.1071 raeburn 11492: return ($output,$counter,$numpathchg);
1.987 raeburn 11493: }
11494:
1.1147 raeburn 11495: =pod
11496:
11497: =item * clean_path($name)
11498:
11499: Performs clean-up of directories, subdirectories and filename in an
11500: embedded object, referenced in an HTML file which is being uploaded
11501: to a course or portfolio, where
11502: "Upload embedded images/multimedia files if HTML file" checkbox was
11503: checked.
11504:
11505: Clean-up is similar to replacements in lonnet::clean_filename()
11506: except each / between sub-directory and next level is preserved.
11507:
11508: =cut
11509:
11510: sub clean_path {
11511: my ($embed_file) = @_;
11512: $embed_file =~s{^/+}{};
11513: my @contents;
11514: if ($embed_file =~ m{/}) {
11515: @contents = split(/\//,$embed_file);
11516: } else {
11517: @contents = ($embed_file);
11518: }
11519: my $lastidx = scalar(@contents)-1;
11520: for (my $i=0; $i<=$lastidx; $i++) {
11521: $contents[$i]=~s{\\}{/}g;
11522: $contents[$i]=~s/\s+/\_/g;
11523: $contents[$i]=~s{[^/\w\.\-]}{}g;
11524: if ($i == $lastidx) {
11525: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11526: }
11527: }
11528: if ($lastidx > 0) {
11529: return join('/',@contents);
11530: } else {
11531: return $contents[0];
11532: }
11533: }
11534:
1.987 raeburn 11535: sub embedded_file_element {
1.1071 raeburn 11536: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11537: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11538: (ref($codebase) eq 'HASH'));
11539: my $output;
1.1071 raeburn 11540: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11541: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11542: }
11543: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11544: &escape($embed_file).'" />';
11545: unless (($context eq 'upload_embedded') &&
11546: ($mapping->{$embed_file} eq $embed_file)) {
11547: $output .='
11548: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11549: }
11550: my $attrib;
11551: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11552: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11553: }
11554: $output .=
11555: "\n\t\t".
11556: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11557: $attrib.'" />';
11558: if (exists($codebase->{$mapping->{$embed_file}})) {
11559: $output .=
11560: "\n\t\t".
11561: '<input name="codebase_'.$num.'" type="hidden" value="'.
11562: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11563: }
1.987 raeburn 11564: return $output;
1.660 raeburn 11565: }
11566:
1.1071 raeburn 11567: sub get_dependency_details {
11568: my ($currfile,$currsubfile,$embed_file) = @_;
11569: my ($size,$mtime,$showsize,$showmtime);
11570: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11571: if ($embed_file =~ m{/}) {
11572: my ($path,$fname) = split(/\//,$embed_file);
11573: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11574: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11575: }
11576: } else {
11577: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11578: ($size,$mtime) = @{$currfile->{$embed_file}};
11579: }
11580: }
11581: $showsize = $size/1024.0;
11582: $showsize = sprintf("%.1f",$showsize);
11583: if ($mtime > 0) {
11584: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11585: }
11586: }
11587: return ($showsize,$showmtime);
11588: }
11589:
11590: sub ask_embedded_js {
11591: return <<"END";
11592: <script type="text/javascript"">
11593: // <![CDATA[
11594: function toggleBrowse(counter) {
11595: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11596: var fileid = document.getElementById('embedded_item_'+counter);
11597: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11598: if (chkboxid.checked == true) {
11599: uploaddivid.style.display='block';
11600: } else {
11601: uploaddivid.style.display='none';
11602: fileid.value = '';
11603: }
11604: }
11605: // ]]>
11606: </script>
11607:
11608: END
11609: }
11610:
1.661 raeburn 11611: sub upload_embedded {
11612: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11613: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11614: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11615: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11616: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11617: my $orig_uploaded_filename =
11618: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11619: foreach my $type ('orig','ref','attrib','codebase') {
11620: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11621: $env{'form.embedded_'.$type.'_'.$i} =
11622: &unescape($env{'form.embedded_'.$type.'_'.$i});
11623: }
11624: }
1.661 raeburn 11625: my ($path,$fname) =
11626: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11627: # no path, whole string is fname
11628: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11629: $fname = &Apache::lonnet::clean_filename($fname);
11630: # See if there is anything left
11631: next if ($fname eq '');
11632:
11633: # Check if file already exists as a file or directory.
11634: my ($state,$msg);
11635: if ($context eq 'portfolio') {
11636: my $port_path = $dirpath;
11637: if ($group ne '') {
11638: $port_path = "groups/$group/$port_path";
11639: }
1.987 raeburn 11640: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11641: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11642: $dir_root,$port_path,$disk_quota,
11643: $current_disk_usage,$uname,$udom);
11644: if ($state eq 'will_exceed_quota'
1.984 raeburn 11645: || $state eq 'file_locked') {
1.661 raeburn 11646: $output .= $msg;
11647: next;
11648: }
11649: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11650: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11651: if ($state eq 'exists') {
11652: $output .= $msg;
11653: next;
11654: }
11655: }
11656: # Check if extension is valid
11657: if (($fname =~ /\.(\w+)$/) &&
11658: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11659: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11660: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11661: next;
11662: } elsif (($fname =~ /\.(\w+)$/) &&
11663: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11664: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11665: next;
11666: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11667: $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 11668: next;
11669: }
11670: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11671: my $subdir = $path;
11672: $subdir =~ s{/+$}{};
1.661 raeburn 11673: if ($context eq 'portfolio') {
1.984 raeburn 11674: my $result;
11675: if ($state eq 'existingfile') {
11676: $result=
11677: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11678: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11679: } else {
1.984 raeburn 11680: $result=
11681: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11682: $dirpath.
1.1123 raeburn 11683: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11684: if ($result !~ m|^/uploaded/|) {
11685: $output .= '<span class="LC_error">'
11686: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11687: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11688: .'</span><br />';
11689: next;
11690: } else {
1.987 raeburn 11691: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11692: $path.$fname.'</span>').'<br />';
1.984 raeburn 11693: }
1.661 raeburn 11694: }
1.1123 raeburn 11695: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 11696: my $extendedsubdir = $dirpath.'/'.$subdir;
11697: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11698: my $result =
1.1126 raeburn 11699: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11700: if ($result !~ m|^/uploaded/|) {
11701: $output .= '<span class="LC_error">'
11702: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11703: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11704: .'</span><br />';
11705: next;
11706: } else {
11707: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11708: $path.$fname.'</span>').'<br />';
1.1125 raeburn 11709: if ($context eq 'syllabus') {
11710: &Apache::lonnet::make_public_indefinitely($result);
11711: }
1.987 raeburn 11712: }
1.661 raeburn 11713: } else {
11714: # Save the file
11715: my $target = $env{'form.embedded_item_'.$i};
11716: my $fullpath = $dir_root.$dirpath.'/'.$path;
11717: my $dest = $fullpath.$fname;
11718: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11719: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11720: my $count;
11721: my $filepath = $dir_root;
1.1027 raeburn 11722: foreach my $subdir (@parts) {
11723: $filepath .= "/$subdir";
11724: if (!-e $filepath) {
1.661 raeburn 11725: mkdir($filepath,0770);
11726: }
11727: }
11728: my $fh;
11729: if (!open($fh,'>'.$dest)) {
11730: &Apache::lonnet::logthis('Failed to create '.$dest);
11731: $output .= '<span class="LC_error">'.
1.1071 raeburn 11732: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11733: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11734: '</span><br />';
11735: } else {
11736: if (!print $fh $env{'form.embedded_item_'.$i}) {
11737: &Apache::lonnet::logthis('Failed to write to '.$dest);
11738: $output .= '<span class="LC_error">'.
1.1071 raeburn 11739: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11740: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11741: '</span><br />';
11742: } else {
1.987 raeburn 11743: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11744: $url.'</span>').'<br />';
11745: unless ($context eq 'testbank') {
11746: $footer .= &mt('View embedded file: [_1]',
11747: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11748: }
11749: }
11750: close($fh);
11751: }
11752: }
11753: if ($env{'form.embedded_ref_'.$i}) {
11754: $pathchange{$i} = 1;
11755: }
11756: }
11757: if ($output) {
11758: $output = '<p>'.$output.'</p>';
11759: }
11760: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11761: $returnflag = 'ok';
1.1071 raeburn 11762: my $numpathchgs = scalar(keys(%pathchange));
11763: if ($numpathchgs > 0) {
1.987 raeburn 11764: if ($context eq 'portfolio') {
11765: $output .= '<p>'.&mt('or').'</p>';
11766: } elsif ($context eq 'testbank') {
1.1071 raeburn 11767: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11768: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11769: $returnflag = 'modify_orightml';
11770: }
11771: }
1.1071 raeburn 11772: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11773: }
11774:
11775: sub modify_html_form {
11776: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11777: my $end = 0;
11778: my $modifyform;
11779: if ($context eq 'upload_embedded') {
11780: return unless (ref($pathchange) eq 'HASH');
11781: if ($env{'form.number_embedded_items'}) {
11782: $end += $env{'form.number_embedded_items'};
11783: }
11784: if ($env{'form.number_pathchange_items'}) {
11785: $end += $env{'form.number_pathchange_items'};
11786: }
11787: if ($end) {
11788: for (my $i=0; $i<$end; $i++) {
11789: if ($i < $env{'form.number_embedded_items'}) {
11790: next unless($pathchange->{$i});
11791: }
11792: $modifyform .=
11793: &start_data_table_row().
11794: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11795: 'checked="checked" /></td>'.
11796: '<td>'.$env{'form.embedded_ref_'.$i}.
11797: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11798: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11799: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11800: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11801: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11802: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11803: '<td>'.$env{'form.embedded_orig_'.$i}.
11804: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11805: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11806: &end_data_table_row();
1.1071 raeburn 11807: }
1.987 raeburn 11808: }
11809: } else {
11810: $modifyform = $pathchgtable;
11811: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11812: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11813: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11814: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11815: }
11816: }
11817: if ($modifyform) {
1.1071 raeburn 11818: if ($actionurl eq '/adm/dependencies') {
11819: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11820: }
1.987 raeburn 11821: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11822: '<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".
11823: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11824: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11825: '</ol></p>'."\n".'<p>'.
11826: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11827: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11828: &start_data_table()."\n".
11829: &start_data_table_header_row().
11830: '<th>'.&mt('Change?').'</th>'.
11831: '<th>'.&mt('Current reference').'</th>'.
11832: '<th>'.&mt('Required reference').'</th>'.
11833: &end_data_table_header_row()."\n".
11834: $modifyform.
11835: &end_data_table().'<br />'."\n".$hiddenstate.
11836: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11837: '</form>'."\n";
11838: }
11839: return;
11840: }
11841:
11842: sub modify_html_refs {
1.1123 raeburn 11843: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11844: my $container;
11845: if ($context eq 'portfolio') {
11846: $container = $env{'form.container'};
11847: } elsif ($context eq 'coursedoc') {
11848: $container = $env{'form.primaryurl'};
1.1071 raeburn 11849: } elsif ($context eq 'manage_dependencies') {
11850: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11851: $container = "/$container";
1.1123 raeburn 11852: } elsif ($context eq 'syllabus') {
11853: $container = $url;
1.987 raeburn 11854: } else {
1.1027 raeburn 11855: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11856: }
11857: my (%allfiles,%codebase,$output,$content);
11858: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 11859: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11860: if (wantarray) {
11861: return ('',0,0);
11862: } else {
11863: return;
11864: }
11865: }
11866: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11867: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11868: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11869: if (wantarray) {
11870: return ('',0,0);
11871: } else {
11872: return;
11873: }
11874: }
1.987 raeburn 11875: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11876: if ($content eq '-1') {
11877: if (wantarray) {
11878: return ('',0,0);
11879: } else {
11880: return;
11881: }
11882: }
1.987 raeburn 11883: } else {
1.1071 raeburn 11884: unless ($container =~ /^\Q$dir_root\E/) {
11885: if (wantarray) {
11886: return ('',0,0);
11887: } else {
11888: return;
11889: }
11890: }
1.987 raeburn 11891: if (open(my $fh,"<$container")) {
11892: $content = join('', <$fh>);
11893: close($fh);
11894: } else {
1.1071 raeburn 11895: if (wantarray) {
11896: return ('',0,0);
11897: } else {
11898: return;
11899: }
1.987 raeburn 11900: }
11901: }
11902: my ($count,$codebasecount) = (0,0);
11903: my $mm = new File::MMagic;
11904: my $mime_type = $mm->checktype_contents($content);
11905: if ($mime_type eq 'text/html') {
11906: my $parse_result =
11907: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11908: \%codebase,\$content);
11909: if ($parse_result eq 'ok') {
11910: foreach my $i (@changes) {
11911: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11912: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11913: if ($allfiles{$ref}) {
11914: my $newname = $orig;
11915: my ($attrib_regexp,$codebase);
1.1006 raeburn 11916: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11917: if ($attrib_regexp =~ /:/) {
11918: $attrib_regexp =~ s/\:/|/g;
11919: }
11920: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11921: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11922: $count += $numchg;
1.1123 raeburn 11923: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 11924: delete($allfiles{$ref});
1.987 raeburn 11925: }
11926: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11927: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11928: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11929: $codebasecount ++;
11930: }
11931: }
11932: }
1.1123 raeburn 11933: my $skiprewrites;
1.987 raeburn 11934: if ($count || $codebasecount) {
11935: my $saveresult;
1.1071 raeburn 11936: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11937: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11938: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11939: if ($url eq $container) {
11940: my ($fname) = ($container =~ m{/([^/]+)$});
11941: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11942: $count,'<span class="LC_filename">'.
1.1071 raeburn 11943: $fname.'</span>').'</p>';
1.987 raeburn 11944: } else {
11945: $output = '<p class="LC_error">'.
11946: &mt('Error: update failed for: [_1].',
11947: '<span class="LC_filename">'.
11948: $container.'</span>').'</p>';
11949: }
1.1123 raeburn 11950: if ($context eq 'syllabus') {
11951: unless ($saveresult eq 'ok') {
11952: $skiprewrites = 1;
11953: }
11954: }
1.987 raeburn 11955: } else {
11956: if (open(my $fh,">$container")) {
11957: print $fh $content;
11958: close($fh);
11959: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11960: $count,'<span class="LC_filename">'.
11961: $container.'</span>').'</p>';
1.661 raeburn 11962: } else {
1.987 raeburn 11963: $output = '<p class="LC_error">'.
11964: &mt('Error: could not update [_1].',
11965: '<span class="LC_filename">'.
11966: $container.'</span>').'</p>';
1.661 raeburn 11967: }
11968: }
11969: }
1.1123 raeburn 11970: if (($context eq 'syllabus') && (!$skiprewrites)) {
11971: my ($actionurl,$state);
11972: $actionurl = "/public/$udom/$uname/syllabus";
11973: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11974: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11975: \%codebase,
11976: {'context' => 'rewrites',
11977: 'ignore_remote_references' => 1,});
11978: if (ref($mapping) eq 'HASH') {
11979: my $rewrites = 0;
11980: foreach my $key (keys(%{$mapping})) {
11981: next if ($key =~ m{^https?://});
11982: my $ref = $mapping->{$key};
11983: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11984: my $attrib;
11985: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11986: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11987: }
11988: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11989: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11990: $rewrites += $numchg;
11991: }
11992: }
11993: if ($rewrites) {
11994: my $saveresult;
11995: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11996: if ($url eq $container) {
11997: my ($fname) = ($container =~ m{/([^/]+)$});
11998: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11999: $count,'<span class="LC_filename">'.
12000: $fname.'</span>').'</p>';
12001: } else {
12002: $output .= '<p class="LC_error">'.
12003: &mt('Error: could not update links in [_1].',
12004: '<span class="LC_filename">'.
12005: $container.'</span>').'</p>';
12006:
12007: }
12008: }
12009: }
12010: }
1.987 raeburn 12011: } else {
12012: &logthis('Failed to parse '.$container.
12013: ' to modify references: '.$parse_result);
1.661 raeburn 12014: }
12015: }
1.1071 raeburn 12016: if (wantarray) {
12017: return ($output,$count,$codebasecount);
12018: } else {
12019: return $output;
12020: }
1.661 raeburn 12021: }
12022:
12023: sub check_for_existing {
12024: my ($path,$fname,$element) = @_;
12025: my ($state,$msg);
12026: if (-d $path.'/'.$fname) {
12027: $state = 'exists';
12028: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12029: } elsif (-e $path.'/'.$fname) {
12030: $state = 'exists';
12031: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12032: }
12033: if ($state eq 'exists') {
12034: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12035: }
12036: return ($state,$msg);
12037: }
12038:
12039: sub check_for_upload {
12040: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12041: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12042: my $filesize = length($env{'form.'.$element});
12043: if (!$filesize) {
12044: my $msg = '<span class="LC_error">'.
12045: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12046: '<span class="LC_filename">'.$fname.'</span>',
12047: $filesize).'<br />'.
1.1007 raeburn 12048: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12049: '</span>';
12050: return ('zero_bytes',$msg);
12051: }
12052: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12053: my $getpropath = 1;
1.1021 raeburn 12054: my ($dirlistref,$listerror) =
12055: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12056: my $found_file = 0;
12057: my $locked_file = 0;
1.991 raeburn 12058: my @lockers;
12059: my $navmap;
12060: if ($env{'request.course.id'}) {
12061: $navmap = Apache::lonnavmaps::navmap->new();
12062: }
1.1021 raeburn 12063: if (ref($dirlistref) eq 'ARRAY') {
12064: foreach my $line (@{$dirlistref}) {
12065: my ($file_name,$rest)=split(/\&/,$line,2);
12066: if ($file_name eq $fname){
12067: $file_name = $path.$file_name;
12068: if ($group ne '') {
12069: $file_name = $group.$file_name;
12070: }
12071: $found_file = 1;
12072: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12073: foreach my $lock (@lockers) {
12074: if (ref($lock) eq 'ARRAY') {
12075: my ($symb,$crsid) = @{$lock};
12076: if ($crsid eq $env{'request.course.id'}) {
12077: if (ref($navmap)) {
12078: my $res = $navmap->getBySymb($symb);
12079: foreach my $part (@{$res->parts()}) {
12080: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12081: unless (($slot_status == $res->RESERVED) ||
12082: ($slot_status == $res->RESERVED_LOCATION)) {
12083: $locked_file = 1;
12084: }
1.991 raeburn 12085: }
1.1021 raeburn 12086: } else {
12087: $locked_file = 1;
1.991 raeburn 12088: }
12089: } else {
12090: $locked_file = 1;
12091: }
12092: }
1.1021 raeburn 12093: }
12094: } else {
12095: my @info = split(/\&/,$rest);
12096: my $currsize = $info[6]/1000;
12097: if ($currsize < $filesize) {
12098: my $extra = $filesize - $currsize;
12099: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12100: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12101: &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 12102: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12103: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12104: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12105: return ('will_exceed_quota',$msg);
12106: }
1.984 raeburn 12107: }
12108: }
1.661 raeburn 12109: }
12110: }
12111: }
12112: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12113: my $msg = '<p class="LC_warning">'.
12114: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12115: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12116: return ('will_exceed_quota',$msg);
12117: } elsif ($found_file) {
12118: if ($locked_file) {
1.1179 bisitz 12119: my $msg = '<p class="LC_warning">';
1.661 raeburn 12120: $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 12121: $msg .= '</p>';
1.661 raeburn 12122: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12123: return ('file_locked',$msg);
12124: } else {
1.1179 bisitz 12125: my $msg = '<p class="LC_error">';
1.984 raeburn 12126: $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 12127: $msg .= '</p>';
1.984 raeburn 12128: return ('existingfile',$msg);
1.661 raeburn 12129: }
12130: }
12131: }
12132:
1.987 raeburn 12133: sub check_for_traversal {
12134: my ($path,$url,$toplevel) = @_;
12135: my @parts=split(/\//,$path);
12136: my $cleanpath;
12137: my $fullpath = $url;
12138: for (my $i=0;$i<@parts;$i++) {
12139: next if ($parts[$i] eq '.');
12140: if ($parts[$i] eq '..') {
12141: $fullpath =~ s{([^/]+/)$}{};
12142: } else {
12143: $fullpath .= $parts[$i].'/';
12144: }
12145: }
12146: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12147: $cleanpath = $1;
12148: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12149: my $curr_toprel = $1;
12150: my @parts = split(/\//,$curr_toprel);
12151: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12152: my @urlparts = split(/\//,$url_toprel);
12153: my $doubledots;
12154: my $startdiff = -1;
12155: for (my $i=0; $i<@urlparts; $i++) {
12156: if ($startdiff == -1) {
12157: unless ($urlparts[$i] eq $parts[$i]) {
12158: $startdiff = $i;
12159: $doubledots .= '../';
12160: }
12161: } else {
12162: $doubledots .= '../';
12163: }
12164: }
12165: if ($startdiff > -1) {
12166: $cleanpath = $doubledots;
12167: for (my $i=$startdiff; $i<@parts; $i++) {
12168: $cleanpath .= $parts[$i].'/';
12169: }
12170: }
12171: }
12172: $cleanpath =~ s{(/)$}{};
12173: return $cleanpath;
12174: }
1.31 albertel 12175:
1.1053 raeburn 12176: sub is_archive_file {
12177: my ($mimetype) = @_;
12178: if (($mimetype eq 'application/octet-stream') ||
12179: ($mimetype eq 'application/x-stuffit') ||
12180: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12181: return 1;
12182: }
12183: return;
12184: }
12185:
12186: sub decompress_form {
1.1065 raeburn 12187: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12188: my %lt = &Apache::lonlocal::texthash (
12189: this => 'This file is an archive file.',
1.1067 raeburn 12190: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12191: itsc => 'Its contents are as follows:',
1.1053 raeburn 12192: youm => 'You may wish to extract its contents.',
12193: extr => 'Extract contents',
1.1067 raeburn 12194: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12195: proa => 'Process automatically?',
1.1053 raeburn 12196: yes => 'Yes',
12197: no => 'No',
1.1067 raeburn 12198: fold => 'Title for folder containing movie',
12199: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12200: );
1.1065 raeburn 12201: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12202: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12203: my $info = &list_archive_contents($fileloc,\@paths);
12204: if (@paths) {
12205: foreach my $path (@paths) {
12206: $path =~ s{^/}{};
1.1067 raeburn 12207: if ($path =~ m{^([^/]+)/$}) {
12208: $topdir = $1;
12209: }
1.1065 raeburn 12210: if ($path =~ m{^([^/]+)/}) {
12211: $toplevel{$1} = $path;
12212: } else {
12213: $toplevel{$path} = $path;
12214: }
12215: }
12216: }
1.1067 raeburn 12217: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12218: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12219: "$topdir/media/",
12220: "$topdir/media/$topdir.mp4",
12221: "$topdir/media/FirstFrame.png",
12222: "$topdir/media/player.swf",
12223: "$topdir/media/swfobject.js",
12224: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12225: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12226: "$topdir/$topdir.mp4",
12227: "$topdir/$topdir\_config.xml",
12228: "$topdir/$topdir\_controller.swf",
12229: "$topdir/$topdir\_embed.css",
12230: "$topdir/$topdir\_First_Frame.png",
12231: "$topdir/$topdir\_player.html",
12232: "$topdir/$topdir\_Thumbnails.png",
12233: "$topdir/playerProductInstall.swf",
12234: "$topdir/scripts/",
12235: "$topdir/scripts/config_xml.js",
12236: "$topdir/scripts/handlebars.js",
12237: "$topdir/scripts/jquery-1.7.1.min.js",
12238: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12239: "$topdir/scripts/modernizr.js",
12240: "$topdir/scripts/player-min.js",
12241: "$topdir/scripts/swfobject.js",
12242: "$topdir/skins/",
12243: "$topdir/skins/configuration_express.xml",
12244: "$topdir/skins/express_show/",
12245: "$topdir/skins/express_show/player-min.css",
12246: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12247: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12248: "$topdir/$topdir.mp4",
12249: "$topdir/$topdir\_config.xml",
12250: "$topdir/$topdir\_controller.swf",
12251: "$topdir/$topdir\_embed.css",
12252: "$topdir/$topdir\_First_Frame.png",
12253: "$topdir/$topdir\_player.html",
12254: "$topdir/$topdir\_Thumbnails.png",
12255: "$topdir/playerProductInstall.swf",
12256: "$topdir/scripts/",
12257: "$topdir/scripts/config_xml.js",
12258: "$topdir/scripts/techsmith-smart-player.min.js",
12259: "$topdir/skins/",
12260: "$topdir/skins/configuration_express.xml",
12261: "$topdir/skins/express_show/",
12262: "$topdir/skins/express_show/spritesheet.min.css",
12263: "$topdir/skins/express_show/spritesheet.png",
12264: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12265: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12266: if (@diffs == 0) {
1.1164 raeburn 12267: $is_camtasia = 6;
12268: } else {
1.1197 raeburn 12269: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12270: if (@diffs == 0) {
12271: $is_camtasia = 8;
1.1197 raeburn 12272: } else {
12273: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12274: if (@diffs == 0) {
12275: $is_camtasia = 8;
12276: }
1.1164 raeburn 12277: }
1.1067 raeburn 12278: }
12279: }
12280: my $output;
12281: if ($is_camtasia) {
12282: $output = <<"ENDCAM";
12283: <script type="text/javascript" language="Javascript">
12284: // <![CDATA[
12285:
12286: function camtasiaToggle() {
12287: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12288: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12289: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12290: document.getElementById('camtasia_titles').style.display='block';
12291: } else {
12292: document.getElementById('camtasia_titles').style.display='none';
12293: }
12294: }
12295: }
12296: return;
12297: }
12298:
12299: // ]]>
12300: </script>
12301: <p>$lt{'camt'}</p>
12302: ENDCAM
1.1065 raeburn 12303: } else {
1.1067 raeburn 12304: $output = '<p>'.$lt{'this'};
12305: if ($info eq '') {
12306: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12307: } else {
12308: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12309: '<div><pre>'.$info.'</pre></div>';
12310: }
1.1065 raeburn 12311: }
1.1067 raeburn 12312: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12313: my $duplicates;
12314: my $num = 0;
12315: if (ref($dirlist) eq 'ARRAY') {
12316: foreach my $item (@{$dirlist}) {
12317: if (ref($item) eq 'ARRAY') {
12318: if (exists($toplevel{$item->[0]})) {
12319: $duplicates .=
12320: &start_data_table_row().
12321: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12322: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12323: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12324: 'value="1" />'.&mt('Yes').'</label>'.
12325: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12326: '<td>'.$item->[0].'</td>';
12327: if ($item->[2]) {
12328: $duplicates .= '<td>'.&mt('Directory').'</td>';
12329: } else {
12330: $duplicates .= '<td>'.&mt('File').'</td>';
12331: }
12332: $duplicates .= '<td>'.$item->[3].'</td>'.
12333: '<td>'.
12334: &Apache::lonlocal::locallocaltime($item->[4]).
12335: '</td>'.
12336: &end_data_table_row();
12337: $num ++;
12338: }
12339: }
12340: }
12341: }
12342: my $itemcount;
12343: if (@paths > 0) {
12344: $itemcount = scalar(@paths);
12345: } else {
12346: $itemcount = 1;
12347: }
1.1067 raeburn 12348: if ($is_camtasia) {
12349: $output .= $lt{'auto'}.'<br />'.
12350: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12351: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12352: $lt{'yes'}.'</label> <label>'.
12353: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12354: $lt{'no'}.'</label></span><br />'.
12355: '<div id="camtasia_titles" style="display:block">'.
12356: &Apache::lonhtmlcommon::start_pick_box().
12357: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12358: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12359: &Apache::lonhtmlcommon::row_closure().
12360: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12361: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12362: &Apache::lonhtmlcommon::row_closure(1).
12363: &Apache::lonhtmlcommon::end_pick_box().
12364: '</div>';
12365: }
1.1065 raeburn 12366: $output .=
12367: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12368: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12369: "\n";
1.1065 raeburn 12370: if ($duplicates ne '') {
12371: $output .= '<p><span class="LC_warning">'.
12372: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12373: &start_data_table().
12374: &start_data_table_header_row().
12375: '<th>'.&mt('Overwrite?').'</th>'.
12376: '<th>'.&mt('Name').'</th>'.
12377: '<th>'.&mt('Type').'</th>'.
12378: '<th>'.&mt('Size').'</th>'.
12379: '<th>'.&mt('Last modified').'</th>'.
12380: &end_data_table_header_row().
12381: $duplicates.
12382: &end_data_table().
12383: '</p>';
12384: }
1.1067 raeburn 12385: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12386: if (ref($hiddenelements) eq 'HASH') {
12387: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12388: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12389: }
12390: }
12391: $output .= <<"END";
1.1067 raeburn 12392: <br />
1.1053 raeburn 12393: <input type="submit" name="decompress" value="$lt{'extr'}" />
12394: </form>
12395: $noextract
12396: END
12397: return $output;
12398: }
12399:
1.1065 raeburn 12400: sub decompression_utility {
12401: my ($program) = @_;
12402: my @utilities = ('tar','gunzip','bunzip2','unzip');
12403: my $location;
12404: if (grep(/^\Q$program\E$/,@utilities)) {
12405: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12406: '/usr/sbin/') {
12407: if (-x $dir.$program) {
12408: $location = $dir.$program;
12409: last;
12410: }
12411: }
12412: }
12413: return $location;
12414: }
12415:
12416: sub list_archive_contents {
12417: my ($file,$pathsref) = @_;
12418: my (@cmd,$output);
12419: my $needsregexp;
12420: if ($file =~ /\.zip$/) {
12421: @cmd = (&decompression_utility('unzip'),"-l");
12422: $needsregexp = 1;
12423: } elsif (($file =~ m/\.tar\.gz$/) ||
12424: ($file =~ /\.tgz$/)) {
12425: @cmd = (&decompression_utility('tar'),"-ztf");
12426: } elsif ($file =~ /\.tar\.bz2$/) {
12427: @cmd = (&decompression_utility('tar'),"-jtf");
12428: } elsif ($file =~ m|\.tar$|) {
12429: @cmd = (&decompression_utility('tar'),"-tf");
12430: }
12431: if (@cmd) {
12432: undef($!);
12433: undef($@);
12434: if (open(my $fh,"-|", @cmd, $file)) {
12435: while (my $line = <$fh>) {
12436: $output .= $line;
12437: chomp($line);
12438: my $item;
12439: if ($needsregexp) {
12440: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12441: } else {
12442: $item = $line;
12443: }
12444: if ($item ne '') {
12445: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12446: push(@{$pathsref},$item);
12447: }
12448: }
12449: }
12450: close($fh);
12451: }
12452: }
12453: return $output;
12454: }
12455:
1.1053 raeburn 12456: sub decompress_uploaded_file {
12457: my ($file,$dir) = @_;
12458: &Apache::lonnet::appenv({'cgi.file' => $file});
12459: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12460: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12461: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12462: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12463: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12464: my $decompressed = $env{'cgi.decompressed'};
12465: &Apache::lonnet::delenv('cgi.file');
12466: &Apache::lonnet::delenv('cgi.dir');
12467: &Apache::lonnet::delenv('cgi.decompressed');
12468: return ($decompressed,$result);
12469: }
12470:
1.1055 raeburn 12471: sub process_decompression {
12472: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
12473: my ($dir,$error,$warning,$output);
1.1180 raeburn 12474: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12475: $error = &mt('Filename not a supported archive file type.').
12476: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12477: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12478: } else {
12479: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12480: if ($docuhome eq 'no_host') {
12481: $error = &mt('Could not determine home server for course.');
12482: } else {
12483: my @ids=&Apache::lonnet::current_machine_ids();
12484: my $currdir = "$dir_root/$destination";
12485: if (grep(/^\Q$docuhome\E$/,@ids)) {
12486: $dir = &LONCAPA::propath($docudom,$docuname).
12487: "$dir_root/$destination";
12488: } else {
12489: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12490: "$dir_root/$docudom/$docuname/$destination";
12491: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12492: $error = &mt('Archive file not found.');
12493: }
12494: }
1.1065 raeburn 12495: my (@to_overwrite,@to_skip);
12496: if ($env{'form.archive_overwrite_total'} > 0) {
12497: my $total = $env{'form.archive_overwrite_total'};
12498: for (my $i=0; $i<$total; $i++) {
12499: if ($env{'form.archive_overwrite_'.$i} == 1) {
12500: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12501: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12502: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12503: }
12504: }
12505: }
12506: my $numskip = scalar(@to_skip);
12507: if (($numskip > 0) &&
12508: ($numskip == $env{'form.archive_itemcount'})) {
12509: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12510: } elsif ($dir eq '') {
1.1055 raeburn 12511: $error = &mt('Directory containing archive file unavailable.');
12512: } elsif (!$error) {
1.1065 raeburn 12513: my ($decompressed,$display);
12514: if ($numskip > 0) {
12515: my $tempdir = time.'_'.$$.int(rand(10000));
12516: mkdir("$dir/$tempdir",0755);
12517: system("mv $dir/$file $dir/$tempdir/$file");
12518: ($decompressed,$display) =
12519: &decompress_uploaded_file($file,"$dir/$tempdir");
12520: foreach my $item (@to_skip) {
12521: if (($item ne '') && ($item !~ /\.\./)) {
12522: if (-f "$dir/$tempdir/$item") {
12523: unlink("$dir/$tempdir/$item");
12524: } elsif (-d "$dir/$tempdir/$item") {
12525: system("rm -rf $dir/$tempdir/$item");
12526: }
12527: }
12528: }
12529: system("mv $dir/$tempdir/* $dir");
12530: rmdir("$dir/$tempdir");
12531: } else {
12532: ($decompressed,$display) =
12533: &decompress_uploaded_file($file,$dir);
12534: }
1.1055 raeburn 12535: if ($decompressed eq 'ok') {
1.1065 raeburn 12536: $output = '<p class="LC_info">'.
12537: &mt('Files extracted successfully from archive.').
12538: '</p>'."\n";
1.1055 raeburn 12539: my ($warning,$result,@contents);
12540: my ($newdirlistref,$newlisterror) =
12541: &Apache::lonnet::dirlist($currdir,$docudom,
12542: $docuname,1);
12543: my (%is_dir,%changes,@newitems);
12544: my $dirptr = 16384;
1.1065 raeburn 12545: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12546: foreach my $dir_line (@{$newdirlistref}) {
12547: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 12548: unless (($item =~ /^\.+$/) || ($item eq $file) ||
12549: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 12550: push(@newitems,$item);
12551: if ($dirptr&$testdir) {
12552: $is_dir{$item} = 1;
12553: }
12554: $changes{$item} = 1;
12555: }
12556: }
12557: }
12558: if (keys(%changes) > 0) {
12559: foreach my $item (sort(@newitems)) {
12560: if ($changes{$item}) {
12561: push(@contents,$item);
12562: }
12563: }
12564: }
12565: if (@contents > 0) {
1.1067 raeburn 12566: my $wantform;
12567: unless ($env{'form.autoextract_camtasia'}) {
12568: $wantform = 1;
12569: }
1.1056 raeburn 12570: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12571: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12572: $currdir,\%is_dir,
12573: \%children,\%parent,
1.1056 raeburn 12574: \@contents,\%dirorder,
12575: \%titles,$wantform);
1.1055 raeburn 12576: if ($datatable ne '') {
12577: $output .= &archive_options_form('decompressed',$datatable,
12578: $count,$hiddenelem);
1.1065 raeburn 12579: my $startcount = 6;
1.1055 raeburn 12580: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12581: \%titles,\%children);
1.1055 raeburn 12582: }
1.1067 raeburn 12583: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 12584: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12585: my %displayed;
12586: my $total = 1;
12587: $env{'form.archive_directory'} = [];
12588: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12589: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12590: $path =~ s{/$}{};
12591: my $item;
12592: if ($path ne '') {
12593: $item = "$path/$titles{$i}";
12594: } else {
12595: $item = $titles{$i};
12596: }
12597: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12598: if ($item eq $contents[0]) {
12599: push(@{$env{'form.archive_directory'}},$i);
12600: $env{'form.archive_'.$i} = 'display';
12601: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12602: $displayed{'folder'} = $i;
1.1164 raeburn 12603: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12604: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12605: $env{'form.archive_'.$i} = 'display';
12606: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12607: $displayed{'web'} = $i;
12608: } else {
1.1164 raeburn 12609: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12610: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12611: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12612: push(@{$env{'form.archive_directory'}},$i);
12613: }
12614: $env{'form.archive_'.$i} = 'dependency';
12615: }
12616: $total ++;
12617: }
12618: for (my $i=1; $i<$total; $i++) {
12619: next if ($i == $displayed{'web'});
12620: next if ($i == $displayed{'folder'});
12621: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12622: }
12623: $env{'form.phase'} = 'decompress_cleanup';
12624: $env{'form.archivedelete'} = 1;
12625: $env{'form.archive_count'} = $total-1;
12626: $output .=
12627: &process_extracted_files('coursedocs',$docudom,
12628: $docuname,$destination,
12629: $dir_root,$hiddenelem);
12630: }
1.1055 raeburn 12631: } else {
12632: $warning = &mt('No new items extracted from archive file.');
12633: }
12634: } else {
12635: $output = $display;
12636: $error = &mt('An error occurred during extraction from the archive file.');
12637: }
12638: }
12639: }
12640: }
12641: if ($error) {
12642: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12643: $error.'</p>'."\n";
12644: }
12645: if ($warning) {
12646: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12647: }
12648: return $output;
12649: }
12650:
12651: sub get_extracted {
1.1056 raeburn 12652: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12653: $titles,$wantform) = @_;
1.1055 raeburn 12654: my $count = 0;
12655: my $depth = 0;
12656: my $datatable;
1.1056 raeburn 12657: my @hierarchy;
1.1055 raeburn 12658: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12659: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12660: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12661: foreach my $item (@{$contents}) {
12662: $count ++;
1.1056 raeburn 12663: @{$dirorder->{$count}} = @hierarchy;
12664: $titles->{$count} = $item;
1.1055 raeburn 12665: &archive_hierarchy($depth,$count,$parent,$children);
12666: if ($wantform) {
12667: $datatable .= &archive_row($is_dir->{$item},$item,
12668: $currdir,$depth,$count);
12669: }
12670: if ($is_dir->{$item}) {
12671: $depth ++;
1.1056 raeburn 12672: push(@hierarchy,$count);
12673: $parent->{$depth} = $count;
1.1055 raeburn 12674: $datatable .=
12675: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12676: \$depth,\$count,\@hierarchy,$dirorder,
12677: $children,$parent,$titles,$wantform);
1.1055 raeburn 12678: $depth --;
1.1056 raeburn 12679: pop(@hierarchy);
1.1055 raeburn 12680: }
12681: }
12682: return ($count,$datatable);
12683: }
12684:
12685: sub recurse_extracted_archive {
1.1056 raeburn 12686: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12687: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12688: my $result='';
1.1056 raeburn 12689: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12690: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12691: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12692: return $result;
12693: }
12694: my $dirptr = 16384;
12695: my ($newdirlistref,$newlisterror) =
12696: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12697: if (ref($newdirlistref) eq 'ARRAY') {
12698: foreach my $dir_line (@{$newdirlistref}) {
12699: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12700: unless ($item =~ /^\.+$/) {
12701: $$count ++;
1.1056 raeburn 12702: @{$dirorder->{$$count}} = @{$hierarchy};
12703: $titles->{$$count} = $item;
1.1055 raeburn 12704: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12705:
1.1055 raeburn 12706: my $is_dir;
12707: if ($dirptr&$testdir) {
12708: $is_dir = 1;
12709: }
12710: if ($wantform) {
12711: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12712: }
12713: if ($is_dir) {
12714: $$depth ++;
1.1056 raeburn 12715: push(@{$hierarchy},$$count);
12716: $parent->{$$depth} = $$count;
1.1055 raeburn 12717: $result .=
12718: &recurse_extracted_archive("$currdir/$item",$docudom,
12719: $docuname,$depth,$count,
1.1056 raeburn 12720: $hierarchy,$dirorder,$children,
12721: $parent,$titles,$wantform);
1.1055 raeburn 12722: $$depth --;
1.1056 raeburn 12723: pop(@{$hierarchy});
1.1055 raeburn 12724: }
12725: }
12726: }
12727: }
12728: return $result;
12729: }
12730:
12731: sub archive_hierarchy {
12732: my ($depth,$count,$parent,$children) =@_;
12733: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12734: if (exists($parent->{$depth})) {
12735: $children->{$parent->{$depth}} .= $count.':';
12736: }
12737: }
12738: return;
12739: }
12740:
12741: sub archive_row {
12742: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12743: my ($name) = ($item =~ m{([^/]+)$});
12744: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12745: 'display' => 'Add as file',
1.1055 raeburn 12746: 'dependency' => 'Include as dependency',
12747: 'discard' => 'Discard',
12748: );
12749: if ($is_dir) {
1.1059 raeburn 12750: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12751: }
1.1056 raeburn 12752: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12753: my $offset = 0;
1.1055 raeburn 12754: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12755: $offset ++;
1.1065 raeburn 12756: if ($action ne 'display') {
12757: $offset ++;
12758: }
1.1055 raeburn 12759: $output .= '<td><span class="LC_nobreak">'.
12760: '<label><input type="radio" name="archive_'.$count.
12761: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12762: my $text = $choices{$action};
12763: if ($is_dir) {
12764: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12765: if ($action eq 'display') {
1.1059 raeburn 12766: $text = &mt('Add as folder');
1.1055 raeburn 12767: }
1.1056 raeburn 12768: } else {
12769: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12770:
12771: }
12772: $output .= ' /> '.$choices{$action}.'</label></span>';
12773: if ($action eq 'dependency') {
12774: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12775: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12776: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12777: '<option value=""></option>'."\n".
12778: '</select>'."\n".
12779: '</div>';
1.1059 raeburn 12780: } elsif ($action eq 'display') {
12781: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12782: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12783: '</div>';
1.1055 raeburn 12784: }
1.1056 raeburn 12785: $output .= '</td>';
1.1055 raeburn 12786: }
12787: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12788: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12789: for (my $i=0; $i<$depth; $i++) {
12790: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12791: }
12792: if ($is_dir) {
12793: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12794: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12795: } else {
12796: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12797: }
12798: $output .= ' '.$name.'</td>'."\n".
12799: &end_data_table_row();
12800: return $output;
12801: }
12802:
12803: sub archive_options_form {
1.1065 raeburn 12804: my ($form,$display,$count,$hiddenelem) = @_;
12805: my %lt = &Apache::lonlocal::texthash(
12806: perm => 'Permanently remove archive file?',
12807: hows => 'How should each extracted item be incorporated in the course?',
12808: cont => 'Content actions for all',
12809: addf => 'Add as folder/file',
12810: incd => 'Include as dependency for a displayed file',
12811: disc => 'Discard',
12812: no => 'No',
12813: yes => 'Yes',
12814: save => 'Save',
12815: );
12816: my $output = <<"END";
12817: <form name="$form" method="post" action="">
12818: <p><span class="LC_nobreak">$lt{'perm'}
12819: <label>
12820: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12821: </label>
12822:
12823: <label>
12824: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12825: </span>
12826: </p>
12827: <input type="hidden" name="phase" value="decompress_cleanup" />
12828: <br />$lt{'hows'}
12829: <div class="LC_columnSection">
12830: <fieldset>
12831: <legend>$lt{'cont'}</legend>
12832: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12833: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12834: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12835: </fieldset>
12836: </div>
12837: END
12838: return $output.
1.1055 raeburn 12839: &start_data_table()."\n".
1.1065 raeburn 12840: $display."\n".
1.1055 raeburn 12841: &end_data_table()."\n".
12842: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12843: $hiddenelem.
1.1065 raeburn 12844: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12845: '</form>';
12846: }
12847:
12848: sub archive_javascript {
1.1056 raeburn 12849: my ($startcount,$numitems,$titles,$children) = @_;
12850: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12851: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12852: my $scripttag = <<START;
12853: <script type="text/javascript">
12854: // <![CDATA[
12855:
12856: function checkAll(form,prefix) {
12857: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12858: for (var i=0; i < form.elements.length; i++) {
12859: var id = form.elements[i].id;
12860: if ((id != '') && (id != undefined)) {
12861: if (idstr.test(id)) {
12862: if (form.elements[i].type == 'radio') {
12863: form.elements[i].checked = true;
1.1056 raeburn 12864: var nostart = i-$startcount;
1.1059 raeburn 12865: var offset = nostart%7;
12866: var count = (nostart-offset)/7;
1.1056 raeburn 12867: dependencyCheck(form,count,offset);
1.1055 raeburn 12868: }
12869: }
12870: }
12871: }
12872: }
12873:
12874: function propagateCheck(form,count) {
12875: if (count > 0) {
1.1059 raeburn 12876: var startelement = $startcount + ((count-1) * 7);
12877: for (var j=1; j<6; j++) {
12878: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12879: var item = startelement + j;
12880: if (form.elements[item].type == 'radio') {
12881: if (form.elements[item].checked) {
12882: containerCheck(form,count,j);
12883: break;
12884: }
1.1055 raeburn 12885: }
12886: }
12887: }
12888: }
12889: }
12890:
12891: numitems = $numitems
1.1056 raeburn 12892: var titles = new Array(numitems);
12893: var parents = new Array(numitems);
1.1055 raeburn 12894: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12895: parents[i] = new Array;
1.1055 raeburn 12896: }
1.1059 raeburn 12897: var maintitle = '$maintitle';
1.1055 raeburn 12898:
12899: START
12900:
1.1056 raeburn 12901: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12902: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12903: for (my $i=0; $i<@contents; $i ++) {
12904: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12905: }
12906: }
12907:
1.1056 raeburn 12908: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12909: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12910: }
12911:
1.1055 raeburn 12912: $scripttag .= <<END;
12913:
12914: function containerCheck(form,count,offset) {
12915: if (count > 0) {
1.1056 raeburn 12916: dependencyCheck(form,count,offset);
1.1059 raeburn 12917: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12918: form.elements[item].checked = true;
12919: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12920: if (parents[count].length > 0) {
12921: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12922: containerCheck(form,parents[count][j],offset);
12923: }
12924: }
12925: }
12926: }
12927: }
12928:
12929: function dependencyCheck(form,count,offset) {
12930: if (count > 0) {
1.1059 raeburn 12931: var chosen = (offset+$startcount)+7*(count-1);
12932: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12933: var currtype = form.elements[depitem].type;
12934: if (form.elements[chosen].value == 'dependency') {
12935: document.getElementById('arc_depon_'+count).style.display='block';
12936: form.elements[depitem].options.length = 0;
12937: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 12938: for (var i=1; i<=numitems; i++) {
12939: if (i == count) {
12940: continue;
12941: }
1.1059 raeburn 12942: var startelement = $startcount + (i-1) * 7;
12943: for (var j=1; j<6; j++) {
12944: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12945: var item = startelement + j;
12946: if (form.elements[item].type == 'radio') {
12947: if (form.elements[item].checked) {
12948: if (form.elements[item].value == 'display') {
12949: var n = form.elements[depitem].options.length;
12950: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12951: }
12952: }
12953: }
12954: }
12955: }
12956: }
12957: } else {
12958: document.getElementById('arc_depon_'+count).style.display='none';
12959: form.elements[depitem].options.length = 0;
12960: form.elements[depitem].options[0] = new Option('Select','',true,true);
12961: }
1.1059 raeburn 12962: titleCheck(form,count,offset);
1.1056 raeburn 12963: }
12964: }
12965:
12966: function propagateSelect(form,count,offset) {
12967: if (count > 0) {
1.1065 raeburn 12968: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12969: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12970: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12971: if (parents[count].length > 0) {
12972: for (var j=0; j<parents[count].length; j++) {
12973: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12974: }
12975: }
12976: }
12977: }
12978: }
1.1056 raeburn 12979:
12980: function containerSelect(form,count,offset,picked) {
12981: if (count > 0) {
1.1065 raeburn 12982: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12983: if (form.elements[item].type == 'radio') {
12984: if (form.elements[item].value == 'dependency') {
12985: if (form.elements[item+1].type == 'select-one') {
12986: for (var i=0; i<form.elements[item+1].options.length; i++) {
12987: if (form.elements[item+1].options[i].value == picked) {
12988: form.elements[item+1].selectedIndex = i;
12989: break;
12990: }
12991: }
12992: }
12993: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12994: if (parents[count].length > 0) {
12995: for (var j=0; j<parents[count].length; j++) {
12996: containerSelect(form,parents[count][j],offset,picked);
12997: }
12998: }
12999: }
13000: }
13001: }
13002: }
13003: }
13004:
1.1059 raeburn 13005: function titleCheck(form,count,offset) {
13006: if (count > 0) {
13007: var chosen = (offset+$startcount)+7*(count-1);
13008: var depitem = $startcount + ((count-1) * 7) + 2;
13009: var currtype = form.elements[depitem].type;
13010: if (form.elements[chosen].value == 'display') {
13011: document.getElementById('arc_title_'+count).style.display='block';
13012: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13013: document.getElementById('archive_title_'+count).value=maintitle;
13014: }
13015: } else {
13016: document.getElementById('arc_title_'+count).style.display='none';
13017: if (currtype == 'text') {
13018: document.getElementById('archive_title_'+count).value='';
13019: }
13020: }
13021: }
13022: return;
13023: }
13024:
1.1055 raeburn 13025: // ]]>
13026: </script>
13027: END
13028: return $scripttag;
13029: }
13030:
13031: sub process_extracted_files {
1.1067 raeburn 13032: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13033: my $numitems = $env{'form.archive_count'};
13034: return unless ($numitems);
13035: my @ids=&Apache::lonnet::current_machine_ids();
13036: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13037: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13038: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13039: if (grep(/^\Q$docuhome\E$/,@ids)) {
13040: $prefix = &LONCAPA::propath($docudom,$docuname);
13041: $pathtocheck = "$dir_root/$destination";
13042: $dir = $dir_root;
13043: $ishome = 1;
13044: } else {
13045: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13046: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
13047: $dir = "$dir_root/$docudom/$docuname";
13048: }
13049: my $currdir = "$dir_root/$destination";
13050: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13051: if ($env{'form.folderpath'}) {
13052: my @items = split('&',$env{'form.folderpath'});
13053: $folders{'0'} = $items[-2];
1.1099 raeburn 13054: if ($env{'form.folderpath'} =~ /\:1$/) {
13055: $containers{'0'}='page';
13056: } else {
13057: $containers{'0'}='sequence';
13058: }
1.1055 raeburn 13059: }
13060: my @archdirs = &get_env_multiple('form.archive_directory');
13061: if ($numitems) {
13062: for (my $i=1; $i<=$numitems; $i++) {
13063: my $path = $env{'form.archive_content_'.$i};
13064: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13065: my $item = $1;
13066: $toplevelitems{$item} = $i;
13067: if (grep(/^\Q$i\E$/,@archdirs)) {
13068: $is_dir{$item} = 1;
13069: }
13070: }
13071: }
13072: }
1.1067 raeburn 13073: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13074: if (keys(%toplevelitems) > 0) {
13075: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13076: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13077: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13078: }
1.1066 raeburn 13079: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13080: if ($numitems) {
13081: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13082: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13083: my $path = $env{'form.archive_content_'.$i};
13084: if ($path =~ /^\Q$pathtocheck\E/) {
13085: if ($env{'form.archive_'.$i} eq 'discard') {
13086: if ($prefix ne '' && $path ne '') {
13087: if (-e $prefix.$path) {
1.1066 raeburn 13088: if ((@archdirs > 0) &&
13089: (grep(/^\Q$i\E$/,@archdirs))) {
13090: $todeletedir{$prefix.$path} = 1;
13091: } else {
13092: $todelete{$prefix.$path} = 1;
13093: }
1.1055 raeburn 13094: }
13095: }
13096: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13097: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13098: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13099: $docstitle = $env{'form.archive_title_'.$i};
13100: if ($docstitle eq '') {
13101: $docstitle = $title;
13102: }
1.1055 raeburn 13103: $outer = 0;
1.1056 raeburn 13104: if (ref($dirorder{$i}) eq 'ARRAY') {
13105: if (@{$dirorder{$i}} > 0) {
13106: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13107: if ($env{'form.archive_'.$item} eq 'display') {
13108: $outer = $item;
13109: last;
13110: }
13111: }
13112: }
13113: }
13114: my ($errtext,$fatal) =
13115: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13116: '/'.$folders{$outer}.'.'.
13117: $containers{$outer});
13118: next if ($fatal);
13119: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13120: if ($context eq 'coursedocs') {
1.1056 raeburn 13121: $mapinner{$i} = time;
1.1055 raeburn 13122: $folders{$i} = 'default_'.$mapinner{$i};
13123: $containers{$i} = 'sequence';
13124: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13125: $folders{$i}.'.'.$containers{$i};
13126: my $newidx = &LONCAPA::map::getresidx();
13127: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13128: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13129: push(@LONCAPA::map::order,$newidx);
13130: my ($outtext,$errtext) =
13131: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13132: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13133: '.'.$containers{$outer},1,1);
1.1056 raeburn 13134: $newseqid{$i} = $newidx;
1.1067 raeburn 13135: unless ($errtext) {
13136: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
13137: }
1.1055 raeburn 13138: }
13139: } else {
13140: if ($context eq 'coursedocs') {
13141: my $newidx=&LONCAPA::map::getresidx();
13142: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13143: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13144: $title;
13145: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13146: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13147: }
13148: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13149: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13150: }
13151: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13152: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 13153: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 13154: unless ($ishome) {
13155: my $fetch = "$newdest{$i}/$title";
13156: $fetch =~ s/^\Q$prefix$dir\E//;
13157: $prompttofetch{$fetch} = 1;
13158: }
1.1055 raeburn 13159: }
13160: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13161: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13162: push(@LONCAPA::map::order, $newidx);
13163: my ($outtext,$errtext)=
13164: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13165: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13166: '.'.$containers{$outer},1,1);
1.1067 raeburn 13167: unless ($errtext) {
13168: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13169: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
13170: }
13171: }
1.1055 raeburn 13172: }
13173: }
1.1086 raeburn 13174: }
13175: } else {
13176: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13177: }
13178: }
13179: for (my $i=1; $i<=$numitems; $i++) {
13180: next unless ($env{'form.archive_'.$i} eq 'dependency');
13181: my $path = $env{'form.archive_content_'.$i};
13182: if ($path =~ /^\Q$pathtocheck\E/) {
13183: my ($title) = ($path =~ m{/([^/]+)$});
13184: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13185: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13186: if (ref($dirorder{$i}) eq 'ARRAY') {
13187: my ($itemidx,$fullpath,$relpath);
13188: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13189: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13190: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13191: if ($dirorder{$i}->[$j] eq $container) {
13192: $itemidx = $j;
1.1056 raeburn 13193: }
13194: }
1.1086 raeburn 13195: }
13196: if ($itemidx eq '') {
13197: $itemidx = 0;
13198: }
13199: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13200: if ($mapinner{$referrer{$i}}) {
13201: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13202: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13203: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13204: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13205: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13206: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13207: if (!-e $fullpath) {
13208: mkdir($fullpath,0755);
1.1056 raeburn 13209: }
13210: }
1.1086 raeburn 13211: } else {
13212: last;
1.1056 raeburn 13213: }
1.1086 raeburn 13214: }
13215: }
13216: } elsif ($newdest{$referrer{$i}}) {
13217: $fullpath = $newdest{$referrer{$i}};
13218: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13219: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13220: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13221: last;
13222: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13223: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13224: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13225: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13226: if (!-e $fullpath) {
13227: mkdir($fullpath,0755);
1.1056 raeburn 13228: }
13229: }
1.1086 raeburn 13230: } else {
13231: last;
1.1056 raeburn 13232: }
1.1055 raeburn 13233: }
13234: }
1.1086 raeburn 13235: if ($fullpath ne '') {
13236: if (-e "$prefix$path") {
13237: system("mv $prefix$path $fullpath/$title");
13238: }
13239: if (-e "$fullpath/$title") {
13240: my $showpath;
13241: if ($relpath ne '') {
13242: $showpath = "$relpath/$title";
13243: } else {
13244: $showpath = "/$title";
13245: }
13246: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
13247: }
13248: unless ($ishome) {
13249: my $fetch = "$fullpath/$title";
13250: $fetch =~ s/^\Q$prefix$dir\E//;
13251: $prompttofetch{$fetch} = 1;
13252: }
13253: }
1.1055 raeburn 13254: }
1.1086 raeburn 13255: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13256: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
13257: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 13258: }
13259: } else {
13260: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13261: }
13262: }
13263: if (keys(%todelete)) {
13264: foreach my $key (keys(%todelete)) {
13265: unlink($key);
1.1066 raeburn 13266: }
13267: }
13268: if (keys(%todeletedir)) {
13269: foreach my $key (keys(%todeletedir)) {
13270: rmdir($key);
13271: }
13272: }
13273: foreach my $dir (sort(keys(%is_dir))) {
13274: if (($pathtocheck ne '') && ($dir ne '')) {
13275: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13276: }
13277: }
1.1067 raeburn 13278: if ($result ne '') {
13279: $output .= '<ul>'."\n".
13280: $result."\n".
13281: '</ul>';
13282: }
13283: unless ($ishome) {
13284: my $replicationfail;
13285: foreach my $item (keys(%prompttofetch)) {
13286: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13287: unless ($fetchresult eq 'ok') {
13288: $replicationfail .= '<li>'.$item.'</li>'."\n";
13289: }
13290: }
13291: if ($replicationfail) {
13292: $output .= '<p class="LC_error">'.
13293: &mt('Course home server failed to retrieve:').'<ul>'.
13294: $replicationfail.
13295: '</ul></p>';
13296: }
13297: }
1.1055 raeburn 13298: } else {
13299: $warning = &mt('No items found in archive.');
13300: }
13301: if ($error) {
13302: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13303: $error.'</p>'."\n";
13304: }
13305: if ($warning) {
13306: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13307: }
13308: return $output;
13309: }
13310:
1.1066 raeburn 13311: sub cleanup_empty_dirs {
13312: my ($path) = @_;
13313: if (($path ne '') && (-d $path)) {
13314: if (opendir(my $dirh,$path)) {
13315: my @dircontents = grep(!/^\./,readdir($dirh));
13316: my $numitems = 0;
13317: foreach my $item (@dircontents) {
13318: if (-d "$path/$item") {
1.1111 raeburn 13319: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13320: if (-e "$path/$item") {
13321: $numitems ++;
13322: }
13323: } else {
13324: $numitems ++;
13325: }
13326: }
13327: if ($numitems == 0) {
13328: rmdir($path);
13329: }
13330: closedir($dirh);
13331: }
13332: }
13333: return;
13334: }
13335:
1.41 ng 13336: =pod
1.45 matthew 13337:
1.1162 raeburn 13338: =item * &get_folder_hierarchy()
1.1068 raeburn 13339:
13340: Provides hierarchy of names of folders/sub-folders containing the current
13341: item,
13342:
13343: Inputs: 3
13344: - $navmap - navmaps object
13345:
13346: - $map - url for map (either the trigger itself, or map containing
13347: the resource, which is the trigger).
13348:
13349: - $showitem - 1 => show title for map itself; 0 => do not show.
13350:
13351: Outputs: 1 @pathitems - array of folder/subfolder names.
13352:
13353: =cut
13354:
13355: sub get_folder_hierarchy {
13356: my ($navmap,$map,$showitem) = @_;
13357: my @pathitems;
13358: if (ref($navmap)) {
13359: my $mapres = $navmap->getResourceByUrl($map);
13360: if (ref($mapres)) {
13361: my $pcslist = $mapres->map_hierarchy();
13362: if ($pcslist ne '') {
13363: my @pcs = split(/,/,$pcslist);
13364: foreach my $pc (@pcs) {
13365: if ($pc == 1) {
1.1129 raeburn 13366: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13367: } else {
13368: my $res = $navmap->getByMapPc($pc);
13369: if (ref($res)) {
13370: my $title = $res->compTitle();
13371: $title =~ s/\W+/_/g;
13372: if ($title ne '') {
13373: push(@pathitems,$title);
13374: }
13375: }
13376: }
13377: }
13378: }
1.1071 raeburn 13379: if ($showitem) {
13380: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13381: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13382: } else {
13383: my $maptitle = $mapres->compTitle();
13384: $maptitle =~ s/\W+/_/g;
13385: if ($maptitle ne '') {
13386: push(@pathitems,$maptitle);
13387: }
1.1068 raeburn 13388: }
13389: }
13390: }
13391: }
13392: return @pathitems;
13393: }
13394:
13395: =pod
13396:
1.1015 raeburn 13397: =item * &get_turnedin_filepath()
13398:
13399: Determines path in a user's portfolio file for storage of files uploaded
13400: to a specific essayresponse or dropbox item.
13401:
13402: Inputs: 3 required + 1 optional.
13403: $symb is symb for resource, $uname and $udom are for current user (required).
13404: $caller is optional (can be "submission", if routine is called when storing
13405: an upoaded file when "Submit Answer" button was pressed).
13406:
13407: Returns array containing $path and $multiresp.
13408: $path is path in portfolio. $multiresp is 1 if this resource contains more
13409: than one file upload item. Callers of routine should append partid as a
13410: subdirectory to $path in cases where $multiresp is 1.
13411:
13412: Called by: homework/essayresponse.pm and homework/structuretags.pm
13413:
13414: =cut
13415:
13416: sub get_turnedin_filepath {
13417: my ($symb,$uname,$udom,$caller) = @_;
13418: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13419: my $turnindir;
13420: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13421: $turnindir = $userhash{'turnindir'};
13422: my ($path,$multiresp);
13423: if ($turnindir eq '') {
13424: if ($caller eq 'submission') {
13425: $turnindir = &mt('turned in');
13426: $turnindir =~ s/\W+/_/g;
13427: my %newhash = (
13428: 'turnindir' => $turnindir,
13429: );
13430: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13431: }
13432: }
13433: if ($turnindir ne '') {
13434: $path = '/'.$turnindir.'/';
13435: my ($multipart,$turnin,@pathitems);
13436: my $navmap = Apache::lonnavmaps::navmap->new();
13437: if (defined($navmap)) {
13438: my $mapres = $navmap->getResourceByUrl($map);
13439: if (ref($mapres)) {
13440: my $pcslist = $mapres->map_hierarchy();
13441: if ($pcslist ne '') {
13442: foreach my $pc (split(/,/,$pcslist)) {
13443: my $res = $navmap->getByMapPc($pc);
13444: if (ref($res)) {
13445: my $title = $res->compTitle();
13446: $title =~ s/\W+/_/g;
13447: if ($title ne '') {
1.1149 raeburn 13448: if (($pc > 1) && (length($title) > 12)) {
13449: $title = substr($title,0,12);
13450: }
1.1015 raeburn 13451: push(@pathitems,$title);
13452: }
13453: }
13454: }
13455: }
13456: my $maptitle = $mapres->compTitle();
13457: $maptitle =~ s/\W+/_/g;
13458: if ($maptitle ne '') {
1.1149 raeburn 13459: if (length($maptitle) > 12) {
13460: $maptitle = substr($maptitle,0,12);
13461: }
1.1015 raeburn 13462: push(@pathitems,$maptitle);
13463: }
13464: unless ($env{'request.state'} eq 'construct') {
13465: my $res = $navmap->getBySymb($symb);
13466: if (ref($res)) {
13467: my $partlist = $res->parts();
13468: my $totaluploads = 0;
13469: if (ref($partlist) eq 'ARRAY') {
13470: foreach my $part (@{$partlist}) {
13471: my @types = $res->responseType($part);
13472: my @ids = $res->responseIds($part);
13473: for (my $i=0; $i < scalar(@ids); $i++) {
13474: if ($types[$i] eq 'essay') {
13475: my $partid = $part.'_'.$ids[$i];
13476: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13477: $totaluploads ++;
13478: }
13479: }
13480: }
13481: }
13482: if ($totaluploads > 1) {
13483: $multiresp = 1;
13484: }
13485: }
13486: }
13487: }
13488: } else {
13489: return;
13490: }
13491: } else {
13492: return;
13493: }
13494: my $restitle=&Apache::lonnet::gettitle($symb);
13495: $restitle =~ s/\W+/_/g;
13496: if ($restitle eq '') {
13497: $restitle = ($resurl =~ m{/[^/]+$});
13498: if ($restitle eq '') {
13499: $restitle = time;
13500: }
13501: }
1.1149 raeburn 13502: if (length($restitle) > 12) {
13503: $restitle = substr($restitle,0,12);
13504: }
1.1015 raeburn 13505: push(@pathitems,$restitle);
13506: $path .= join('/',@pathitems);
13507: }
13508: return ($path,$multiresp);
13509: }
13510:
13511: =pod
13512:
1.464 albertel 13513: =back
1.41 ng 13514:
1.112 bowersj2 13515: =head1 CSV Upload/Handling functions
1.38 albertel 13516:
1.41 ng 13517: =over 4
13518:
1.648 raeburn 13519: =item * &upfile_store($r)
1.41 ng 13520:
13521: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13522: needs $env{'form.upfile'}
1.41 ng 13523: returns $datatoken to be put into hidden field
13524:
13525: =cut
1.31 albertel 13526:
13527: sub upfile_store {
13528: my $r=shift;
1.258 albertel 13529: $env{'form.upfile'}=~s/\r/\n/gs;
13530: $env{'form.upfile'}=~s/\f/\n/gs;
13531: $env{'form.upfile'}=~s/\n+/\n/gs;
13532: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13533:
1.258 albertel 13534: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
13535: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 13536: {
1.158 raeburn 13537: my $datafile = $r->dir_config('lonDaemons').
13538: '/tmp/'.$datatoken.'.tmp';
13539: if ( open(my $fh,">$datafile") ) {
1.258 albertel 13540: print $fh $env{'form.upfile'};
1.158 raeburn 13541: close($fh);
13542: }
1.31 albertel 13543: }
13544: return $datatoken;
13545: }
13546:
1.56 matthew 13547: =pod
13548:
1.648 raeburn 13549: =item * &load_tmp_file($r)
1.41 ng 13550:
13551: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 13552: needs $env{'form.datatoken'},
13553: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13554:
13555: =cut
1.31 albertel 13556:
13557: sub load_tmp_file {
13558: my $r=shift;
13559: my @studentdata=();
13560: {
1.158 raeburn 13561: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 13562: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 13563: if ( open(my $fh,"<$studentfile") ) {
13564: @studentdata=<$fh>;
13565: close($fh);
13566: }
1.31 albertel 13567: }
1.258 albertel 13568: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13569: }
13570:
1.56 matthew 13571: =pod
13572:
1.648 raeburn 13573: =item * &upfile_record_sep()
1.41 ng 13574:
13575: Separate uploaded file into records
13576: returns array of records,
1.258 albertel 13577: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13578:
13579: =cut
1.31 albertel 13580:
13581: sub upfile_record_sep {
1.258 albertel 13582: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13583: } else {
1.248 albertel 13584: my @records;
1.258 albertel 13585: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13586: if ($line=~/^\s*$/) { next; }
13587: push(@records,$line);
13588: }
13589: return @records;
1.31 albertel 13590: }
13591: }
13592:
1.56 matthew 13593: =pod
13594:
1.648 raeburn 13595: =item * &record_sep($record)
1.41 ng 13596:
1.258 albertel 13597: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13598:
13599: =cut
13600:
1.263 www 13601: sub takeleft {
13602: my $index=shift;
13603: return substr('0000'.$index,-4,4);
13604: }
13605:
1.31 albertel 13606: sub record_sep {
13607: my $record=shift;
13608: my %components=();
1.258 albertel 13609: if ($env{'form.upfiletype'} eq 'xml') {
13610: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13611: my $i=0;
1.356 albertel 13612: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13613: $field=~s/^(\"|\')//;
13614: $field=~s/(\"|\')$//;
1.263 www 13615: $components{&takeleft($i)}=$field;
1.31 albertel 13616: $i++;
13617: }
1.258 albertel 13618: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13619: my $i=0;
1.356 albertel 13620: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13621: $field=~s/^(\"|\')//;
13622: $field=~s/(\"|\')$//;
1.263 www 13623: $components{&takeleft($i)}=$field;
1.31 albertel 13624: $i++;
13625: }
13626: } else {
1.561 www 13627: my $separator=',';
1.480 banghart 13628: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13629: $separator=';';
1.480 banghart 13630: }
1.31 albertel 13631: my $i=0;
1.561 www 13632: # the character we are looking for to indicate the end of a quote or a record
13633: my $looking_for=$separator;
13634: # do not add the characters to the fields
13635: my $ignore=0;
13636: # we just encountered a separator (or the beginning of the record)
13637: my $just_found_separator=1;
13638: # store the field we are working on here
13639: my $field='';
13640: # work our way through all characters in record
13641: foreach my $character ($record=~/(.)/g) {
13642: if ($character eq $looking_for) {
13643: if ($character ne $separator) {
13644: # Found the end of a quote, again looking for separator
13645: $looking_for=$separator;
13646: $ignore=1;
13647: } else {
13648: # Found a separator, store away what we got
13649: $components{&takeleft($i)}=$field;
13650: $i++;
13651: $just_found_separator=1;
13652: $ignore=0;
13653: $field='';
13654: }
13655: next;
13656: }
13657: # single or double quotation marks after a separator indicate beginning of a quote
13658: # we are now looking for the end of the quote and need to ignore separators
13659: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13660: $looking_for=$character;
13661: next;
13662: }
13663: # ignore would be true after we reached the end of a quote
13664: if ($ignore) { next; }
13665: if (($just_found_separator) && ($character=~/\s/)) { next; }
13666: $field.=$character;
13667: $just_found_separator=0;
1.31 albertel 13668: }
1.561 www 13669: # catch the very last entry, since we never encountered the separator
13670: $components{&takeleft($i)}=$field;
1.31 albertel 13671: }
13672: return %components;
13673: }
13674:
1.144 matthew 13675: ######################################################
13676: ######################################################
13677:
1.56 matthew 13678: =pod
13679:
1.648 raeburn 13680: =item * &upfile_select_html()
1.41 ng 13681:
1.144 matthew 13682: Return HTML code to select a file from the users machine and specify
13683: the file type.
1.41 ng 13684:
13685: =cut
13686:
1.144 matthew 13687: ######################################################
13688: ######################################################
1.31 albertel 13689: sub upfile_select_html {
1.144 matthew 13690: my %Types = (
13691: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13692: semisv => &mt('Semicolon separated values'),
1.144 matthew 13693: space => &mt('Space separated'),
13694: tab => &mt('Tabulator separated'),
13695: # xml => &mt('HTML/XML'),
13696: );
13697: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13698: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13699: foreach my $type (sort(keys(%Types))) {
13700: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13701: }
13702: $Str .= "</select>\n";
13703: return $Str;
1.31 albertel 13704: }
13705:
1.301 albertel 13706: sub get_samples {
13707: my ($records,$toget) = @_;
13708: my @samples=({});
13709: my $got=0;
13710: foreach my $rec (@$records) {
13711: my %temp = &record_sep($rec);
13712: if (! grep(/\S/, values(%temp))) { next; }
13713: if (%temp) {
13714: $samples[$got]=\%temp;
13715: $got++;
13716: if ($got == $toget) { last; }
13717: }
13718: }
13719: return \@samples;
13720: }
13721:
1.144 matthew 13722: ######################################################
13723: ######################################################
13724:
1.56 matthew 13725: =pod
13726:
1.648 raeburn 13727: =item * &csv_print_samples($r,$records)
1.41 ng 13728:
13729: Prints a table of sample values from each column uploaded $r is an
13730: Apache Request ref, $records is an arrayref from
13731: &Apache::loncommon::upfile_record_sep
13732:
13733: =cut
13734:
1.144 matthew 13735: ######################################################
13736: ######################################################
1.31 albertel 13737: sub csv_print_samples {
13738: my ($r,$records) = @_;
1.662 bisitz 13739: my $samples = &get_samples($records,5);
1.301 albertel 13740:
1.594 raeburn 13741: $r->print(&mt('Samples').'<br />'.&start_data_table().
13742: &start_data_table_header_row());
1.356 albertel 13743: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13744: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13745: $r->print(&end_data_table_header_row());
1.301 albertel 13746: foreach my $hash (@$samples) {
1.594 raeburn 13747: $r->print(&start_data_table_row());
1.356 albertel 13748: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13749: $r->print('<td>');
1.356 albertel 13750: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13751: $r->print('</td>');
13752: }
1.594 raeburn 13753: $r->print(&end_data_table_row());
1.31 albertel 13754: }
1.594 raeburn 13755: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13756: }
13757:
1.144 matthew 13758: ######################################################
13759: ######################################################
13760:
1.56 matthew 13761: =pod
13762:
1.648 raeburn 13763: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13764:
13765: Prints a table to create associations between values and table columns.
1.144 matthew 13766:
1.41 ng 13767: $r is an Apache Request ref,
13768: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13769: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13770:
13771: =cut
13772:
1.144 matthew 13773: ######################################################
13774: ######################################################
1.31 albertel 13775: sub csv_print_select_table {
13776: my ($r,$records,$d) = @_;
1.301 albertel 13777: my $i=0;
13778: my $samples = &get_samples($records,1);
1.144 matthew 13779: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13780: &start_data_table().&start_data_table_header_row().
1.144 matthew 13781: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13782: '<th>'.&mt('Column').'</th>'.
13783: &end_data_table_header_row()."\n");
1.356 albertel 13784: foreach my $array_ref (@$d) {
13785: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13786: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13787:
1.875 bisitz 13788: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13789: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13790: $r->print('<option value="none"></option>');
1.356 albertel 13791: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13792: $r->print('<option value="'.$sample.'"'.
13793: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13794: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13795: }
1.594 raeburn 13796: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13797: $i++;
13798: }
1.594 raeburn 13799: $r->print(&end_data_table());
1.31 albertel 13800: $i--;
13801: return $i;
13802: }
1.56 matthew 13803:
1.144 matthew 13804: ######################################################
13805: ######################################################
13806:
1.56 matthew 13807: =pod
1.31 albertel 13808:
1.648 raeburn 13809: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13810:
13811: Prints a table of sample values from the upload and can make associate samples to internal names.
13812:
13813: $r is an Apache Request ref,
13814: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13815: $d is an array of 2 element arrays (internal name, displayed name)
13816:
13817: =cut
13818:
1.144 matthew 13819: ######################################################
13820: ######################################################
1.31 albertel 13821: sub csv_samples_select_table {
13822: my ($r,$records,$d) = @_;
13823: my $i=0;
1.144 matthew 13824: #
1.662 bisitz 13825: my $max_samples = 5;
13826: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13827: $r->print(&start_data_table().
13828: &start_data_table_header_row().'<th>'.
13829: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13830: &end_data_table_header_row());
1.301 albertel 13831:
13832: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13833: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13834: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13835: foreach my $option (@$d) {
13836: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13837: $r->print('<option value="'.$value.'"'.
1.253 albertel 13838: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13839: $display.'</option>');
1.31 albertel 13840: }
13841: $r->print('</select></td><td>');
1.662 bisitz 13842: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13843: if (defined($samples->[$line]{$key})) {
13844: $r->print($samples->[$line]{$key}."<br />\n");
13845: }
13846: }
1.594 raeburn 13847: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13848: $i++;
13849: }
1.594 raeburn 13850: $r->print(&end_data_table());
1.31 albertel 13851: $i--;
13852: return($i);
1.115 matthew 13853: }
13854:
1.144 matthew 13855: ######################################################
13856: ######################################################
13857:
1.115 matthew 13858: =pod
13859:
1.648 raeburn 13860: =item * &clean_excel_name($name)
1.115 matthew 13861:
13862: Returns a replacement for $name which does not contain any illegal characters.
13863:
13864: =cut
13865:
1.144 matthew 13866: ######################################################
13867: ######################################################
1.115 matthew 13868: sub clean_excel_name {
13869: my ($name) = @_;
13870: $name =~ s/[:\*\?\/\\]//g;
13871: if (length($name) > 31) {
13872: $name = substr($name,0,31);
13873: }
13874: return $name;
1.25 albertel 13875: }
1.84 albertel 13876:
1.85 albertel 13877: =pod
13878:
1.648 raeburn 13879: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13880:
13881: Returns either 1 or undef
13882:
13883: 1 if the part is to be hidden, undef if it is to be shown
13884:
13885: Arguments are:
13886:
13887: $id the id of the part to be checked
13888: $symb, optional the symb of the resource to check
13889: $udom, optional the domain of the user to check for
13890: $uname, optional the username of the user to check for
13891:
13892: =cut
1.84 albertel 13893:
13894: sub check_if_partid_hidden {
13895: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13896: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13897: $symb,$udom,$uname);
1.141 albertel 13898: my $truth=1;
13899: #if the string starts with !, then the list is the list to show not hide
13900: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13901: my @hiddenlist=split(/,/,$hiddenparts);
13902: foreach my $checkid (@hiddenlist) {
1.141 albertel 13903: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13904: }
1.141 albertel 13905: return !$truth;
1.84 albertel 13906: }
1.127 matthew 13907:
1.138 matthew 13908:
13909: ############################################################
13910: ############################################################
13911:
13912: =pod
13913:
1.157 matthew 13914: =back
13915:
1.138 matthew 13916: =head1 cgi-bin script and graphing routines
13917:
1.157 matthew 13918: =over 4
13919:
1.648 raeburn 13920: =item * &get_cgi_id()
1.138 matthew 13921:
13922: Inputs: none
13923:
13924: Returns an id which can be used to pass environment variables
13925: to various cgi-bin scripts. These environment variables will
13926: be removed from the users environment after a given time by
13927: the routine &Apache::lonnet::transfer_profile_to_env.
13928:
13929: =cut
13930:
13931: ############################################################
13932: ############################################################
1.152 albertel 13933: my $uniq=0;
1.136 matthew 13934: sub get_cgi_id {
1.154 albertel 13935: $uniq=($uniq+1)%100000;
1.280 albertel 13936: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13937: }
13938:
1.127 matthew 13939: ############################################################
13940: ############################################################
13941:
13942: =pod
13943:
1.648 raeburn 13944: =item * &DrawBarGraph()
1.127 matthew 13945:
1.138 matthew 13946: Facilitates the plotting of data in a (stacked) bar graph.
13947: Puts plot definition data into the users environment in order for
13948: graph.png to plot it. Returns an <img> tag for the plot.
13949: The bars on the plot are labeled '1','2',...,'n'.
13950:
13951: Inputs:
13952:
13953: =over 4
13954:
13955: =item $Title: string, the title of the plot
13956:
13957: =item $xlabel: string, text describing the X-axis of the plot
13958:
13959: =item $ylabel: string, text describing the Y-axis of the plot
13960:
13961: =item $Max: scalar, the maximum Y value to use in the plot
13962: If $Max is < any data point, the graph will not be rendered.
13963:
1.140 matthew 13964: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13965: they are plotted. If undefined, default values will be used.
13966:
1.178 matthew 13967: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13968:
1.138 matthew 13969: =item @Values: An array of array references. Each array reference holds data
13970: to be plotted in a stacked bar chart.
13971:
1.239 matthew 13972: =item If the final element of @Values is a hash reference the key/value
13973: pairs will be added to the graph definition.
13974:
1.138 matthew 13975: =back
13976:
13977: Returns:
13978:
13979: An <img> tag which references graph.png and the appropriate identifying
13980: information for the plot.
13981:
1.127 matthew 13982: =cut
13983:
13984: ############################################################
13985: ############################################################
1.134 matthew 13986: sub DrawBarGraph {
1.178 matthew 13987: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13988: #
13989: if (! defined($colors)) {
13990: $colors = ['#33ff00',
13991: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13992: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13993: ];
13994: }
1.228 matthew 13995: my $extra_settings = {};
13996: if (ref($Values[-1]) eq 'HASH') {
13997: $extra_settings = pop(@Values);
13998: }
1.127 matthew 13999: #
1.136 matthew 14000: my $identifier = &get_cgi_id();
14001: my $id = 'cgi.'.$identifier;
1.129 matthew 14002: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14003: return '';
14004: }
1.225 matthew 14005: #
14006: my @Labels;
14007: if (defined($labels)) {
14008: @Labels = @$labels;
14009: } else {
14010: for (my $i=0;$i<@{$Values[0]};$i++) {
14011: push (@Labels,$i+1);
14012: }
14013: }
14014: #
1.129 matthew 14015: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14016: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14017: my %ValuesHash;
14018: my $NumSets=1;
14019: foreach my $array (@Values) {
14020: next if (! ref($array));
1.136 matthew 14021: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14022: join(',',@$array);
1.129 matthew 14023: }
1.127 matthew 14024: #
1.136 matthew 14025: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14026: if ($NumBars < 3) {
14027: $width = 120+$NumBars*32;
1.220 matthew 14028: $xskip = 1;
1.225 matthew 14029: $bar_width = 30;
14030: } elsif ($NumBars < 5) {
14031: $width = 120+$NumBars*20;
14032: $xskip = 1;
14033: $bar_width = 20;
1.220 matthew 14034: } elsif ($NumBars < 10) {
1.136 matthew 14035: $width = 120+$NumBars*15;
14036: $xskip = 1;
14037: $bar_width = 15;
14038: } elsif ($NumBars <= 25) {
14039: $width = 120+$NumBars*11;
14040: $xskip = 5;
14041: $bar_width = 8;
14042: } elsif ($NumBars <= 50) {
14043: $width = 120+$NumBars*8;
14044: $xskip = 5;
14045: $bar_width = 4;
14046: } else {
14047: $width = 120+$NumBars*8;
14048: $xskip = 5;
14049: $bar_width = 4;
14050: }
14051: #
1.137 matthew 14052: $Max = 1 if ($Max < 1);
14053: if ( int($Max) < $Max ) {
14054: $Max++;
14055: $Max = int($Max);
14056: }
1.127 matthew 14057: $Title = '' if (! defined($Title));
14058: $xlabel = '' if (! defined($xlabel));
14059: $ylabel = '' if (! defined($ylabel));
1.369 www 14060: $ValuesHash{$id.'.title'} = &escape($Title);
14061: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14062: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14063: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14064: $ValuesHash{$id.'.NumBars'} = $NumBars;
14065: $ValuesHash{$id.'.NumSets'} = $NumSets;
14066: $ValuesHash{$id.'.PlotType'} = 'bar';
14067: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14068: $ValuesHash{$id.'.height'} = $height;
14069: $ValuesHash{$id.'.width'} = $width;
14070: $ValuesHash{$id.'.xskip'} = $xskip;
14071: $ValuesHash{$id.'.bar_width'} = $bar_width;
14072: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14073: #
1.228 matthew 14074: # Deal with other parameters
14075: while (my ($key,$value) = each(%$extra_settings)) {
14076: $ValuesHash{$id.'.'.$key} = $value;
14077: }
14078: #
1.646 raeburn 14079: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14080: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14081: }
14082:
14083: ############################################################
14084: ############################################################
14085:
14086: =pod
14087:
1.648 raeburn 14088: =item * &DrawXYGraph()
1.137 matthew 14089:
1.138 matthew 14090: Facilitates the plotting of data in an XY graph.
14091: Puts plot definition data into the users environment in order for
14092: graph.png to plot it. Returns an <img> tag for the plot.
14093:
14094: Inputs:
14095:
14096: =over 4
14097:
14098: =item $Title: string, the title of the plot
14099:
14100: =item $xlabel: string, text describing the X-axis of the plot
14101:
14102: =item $ylabel: string, text describing the Y-axis of the plot
14103:
14104: =item $Max: scalar, the maximum Y value to use in the plot
14105: If $Max is < any data point, the graph will not be rendered.
14106:
14107: =item $colors: Array ref containing the hex color codes for the data to be
14108: plotted in. If undefined, default values will be used.
14109:
14110: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14111:
14112: =item $Ydata: Array ref containing Array refs.
1.185 www 14113: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14114:
14115: =item %Values: hash indicating or overriding any default values which are
14116: passed to graph.png.
14117: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14118:
14119: =back
14120:
14121: Returns:
14122:
14123: An <img> tag which references graph.png and the appropriate identifying
14124: information for the plot.
14125:
1.137 matthew 14126: =cut
14127:
14128: ############################################################
14129: ############################################################
14130: sub DrawXYGraph {
14131: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14132: #
14133: # Create the identifier for the graph
14134: my $identifier = &get_cgi_id();
14135: my $id = 'cgi.'.$identifier;
14136: #
14137: $Title = '' if (! defined($Title));
14138: $xlabel = '' if (! defined($xlabel));
14139: $ylabel = '' if (! defined($ylabel));
14140: my %ValuesHash =
14141: (
1.369 www 14142: $id.'.title' => &escape($Title),
14143: $id.'.xlabel' => &escape($xlabel),
14144: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14145: $id.'.y_max_value'=> $Max,
14146: $id.'.labels' => join(',',@$Xlabels),
14147: $id.'.PlotType' => 'XY',
14148: );
14149: #
14150: if (defined($colors) && ref($colors) eq 'ARRAY') {
14151: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14152: }
14153: #
14154: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14155: return '';
14156: }
14157: my $NumSets=1;
1.138 matthew 14158: foreach my $array (@{$Ydata}){
1.137 matthew 14159: next if (! ref($array));
14160: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14161: }
1.138 matthew 14162: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14163: #
14164: # Deal with other parameters
14165: while (my ($key,$value) = each(%Values)) {
14166: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14167: }
14168: #
1.646 raeburn 14169: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14170: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14171: }
14172:
14173: ############################################################
14174: ############################################################
14175:
14176: =pod
14177:
1.648 raeburn 14178: =item * &DrawXYYGraph()
1.138 matthew 14179:
14180: Facilitates the plotting of data in an XY graph with two Y axes.
14181: Puts plot definition data into the users environment in order for
14182: graph.png to plot it. Returns an <img> tag for the plot.
14183:
14184: Inputs:
14185:
14186: =over 4
14187:
14188: =item $Title: string, the title of the plot
14189:
14190: =item $xlabel: string, text describing the X-axis of the plot
14191:
14192: =item $ylabel: string, text describing the Y-axis of the plot
14193:
14194: =item $colors: Array ref containing the hex color codes for the data to be
14195: plotted in. If undefined, default values will be used.
14196:
14197: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14198:
14199: =item $Ydata1: The first data set
14200:
14201: =item $Min1: The minimum value of the left Y-axis
14202:
14203: =item $Max1: The maximum value of the left Y-axis
14204:
14205: =item $Ydata2: The second data set
14206:
14207: =item $Min2: The minimum value of the right Y-axis
14208:
14209: =item $Max2: The maximum value of the left Y-axis
14210:
14211: =item %Values: hash indicating or overriding any default values which are
14212: passed to graph.png.
14213: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14214:
14215: =back
14216:
14217: Returns:
14218:
14219: An <img> tag which references graph.png and the appropriate identifying
14220: information for the plot.
1.136 matthew 14221:
14222: =cut
14223:
14224: ############################################################
14225: ############################################################
1.137 matthew 14226: sub DrawXYYGraph {
14227: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14228: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14229: #
14230: # Create the identifier for the graph
14231: my $identifier = &get_cgi_id();
14232: my $id = 'cgi.'.$identifier;
14233: #
14234: $Title = '' if (! defined($Title));
14235: $xlabel = '' if (! defined($xlabel));
14236: $ylabel = '' if (! defined($ylabel));
14237: my %ValuesHash =
14238: (
1.369 www 14239: $id.'.title' => &escape($Title),
14240: $id.'.xlabel' => &escape($xlabel),
14241: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14242: $id.'.labels' => join(',',@$Xlabels),
14243: $id.'.PlotType' => 'XY',
14244: $id.'.NumSets' => 2,
1.137 matthew 14245: $id.'.two_axes' => 1,
14246: $id.'.y1_max_value' => $Max1,
14247: $id.'.y1_min_value' => $Min1,
14248: $id.'.y2_max_value' => $Max2,
14249: $id.'.y2_min_value' => $Min2,
1.136 matthew 14250: );
14251: #
1.137 matthew 14252: if (defined($colors) && ref($colors) eq 'ARRAY') {
14253: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14254: }
14255: #
14256: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14257: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14258: return '';
14259: }
14260: my $NumSets=1;
1.137 matthew 14261: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14262: next if (! ref($array));
14263: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14264: }
14265: #
14266: # Deal with other parameters
14267: while (my ($key,$value) = each(%Values)) {
14268: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14269: }
14270: #
1.646 raeburn 14271: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14272: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14273: }
14274:
14275: ############################################################
14276: ############################################################
14277:
14278: =pod
14279:
1.157 matthew 14280: =back
14281:
1.139 matthew 14282: =head1 Statistics helper routines?
14283:
14284: Bad place for them but what the hell.
14285:
1.157 matthew 14286: =over 4
14287:
1.648 raeburn 14288: =item * &chartlink()
1.139 matthew 14289:
14290: Returns a link to the chart for a specific student.
14291:
14292: Inputs:
14293:
14294: =over 4
14295:
14296: =item $linktext: The text of the link
14297:
14298: =item $sname: The students username
14299:
14300: =item $sdomain: The students domain
14301:
14302: =back
14303:
1.157 matthew 14304: =back
14305:
1.139 matthew 14306: =cut
14307:
14308: ############################################################
14309: ############################################################
14310: sub chartlink {
14311: my ($linktext, $sname, $sdomain) = @_;
14312: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14313: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14314: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14315: '">'.$linktext.'</a>';
1.153 matthew 14316: }
14317:
14318: #######################################################
14319: #######################################################
14320:
14321: =pod
14322:
14323: =head1 Course Environment Routines
1.157 matthew 14324:
14325: =over 4
1.153 matthew 14326:
1.648 raeburn 14327: =item * &restore_course_settings()
1.153 matthew 14328:
1.648 raeburn 14329: =item * &store_course_settings()
1.153 matthew 14330:
14331: Restores/Store indicated form parameters from the course environment.
14332: Will not overwrite existing values of the form parameters.
14333:
14334: Inputs:
14335: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14336:
14337: a hash ref describing the data to be stored. For example:
14338:
14339: %Save_Parameters = ('Status' => 'scalar',
14340: 'chartoutputmode' => 'scalar',
14341: 'chartoutputdata' => 'scalar',
14342: 'Section' => 'array',
1.373 raeburn 14343: 'Group' => 'array',
1.153 matthew 14344: 'StudentData' => 'array',
14345: 'Maps' => 'array');
14346:
14347: Returns: both routines return nothing
14348:
1.631 raeburn 14349: =back
14350:
1.153 matthew 14351: =cut
14352:
14353: #######################################################
14354: #######################################################
14355: sub store_course_settings {
1.496 albertel 14356: return &store_settings($env{'request.course.id'},@_);
14357: }
14358:
14359: sub store_settings {
1.153 matthew 14360: # save to the environment
14361: # appenv the same items, just to be safe
1.300 albertel 14362: my $udom = $env{'user.domain'};
14363: my $uname = $env{'user.name'};
1.496 albertel 14364: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14365: my %SaveHash;
14366: my %AppHash;
14367: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14368: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14369: my $envname = 'environment.'.$basename;
1.258 albertel 14370: if (exists($env{'form.'.$setting})) {
1.153 matthew 14371: # Save this value away
14372: if ($type eq 'scalar' &&
1.258 albertel 14373: (! exists($env{$envname}) ||
14374: $env{$envname} ne $env{'form.'.$setting})) {
14375: $SaveHash{$basename} = $env{'form.'.$setting};
14376: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14377: } elsif ($type eq 'array') {
14378: my $stored_form;
1.258 albertel 14379: if (ref($env{'form.'.$setting})) {
1.153 matthew 14380: $stored_form = join(',',
14381: map {
1.369 www 14382: &escape($_);
1.258 albertel 14383: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14384: } else {
14385: $stored_form =
1.369 www 14386: &escape($env{'form.'.$setting});
1.153 matthew 14387: }
14388: # Determine if the array contents are the same.
1.258 albertel 14389: if ($stored_form ne $env{$envname}) {
1.153 matthew 14390: $SaveHash{$basename} = $stored_form;
14391: $AppHash{$envname} = $stored_form;
14392: }
14393: }
14394: }
14395: }
14396: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14397: $udom,$uname);
1.153 matthew 14398: if ($put_result !~ /^(ok|delayed)/) {
14399: &Apache::lonnet::logthis('unable to save form parameters, '.
14400: 'got error:'.$put_result);
14401: }
14402: # Make sure these settings stick around in this session, too
1.646 raeburn 14403: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14404: return;
14405: }
14406:
14407: sub restore_course_settings {
1.499 albertel 14408: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14409: }
14410:
14411: sub restore_settings {
14412: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14413: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14414: next if (exists($env{'form.'.$setting}));
1.496 albertel 14415: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14416: '.'.$setting;
1.258 albertel 14417: if (exists($env{$envname})) {
1.153 matthew 14418: if ($type eq 'scalar') {
1.258 albertel 14419: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14420: } elsif ($type eq 'array') {
1.258 albertel 14421: $env{'form.'.$setting} = [
1.153 matthew 14422: map {
1.369 www 14423: &unescape($_);
1.258 albertel 14424: } split(',',$env{$envname})
1.153 matthew 14425: ];
14426: }
14427: }
14428: }
1.127 matthew 14429: }
14430:
1.618 raeburn 14431: #######################################################
14432: #######################################################
14433:
14434: =pod
14435:
14436: =head1 Domain E-mail Routines
14437:
14438: =over 4
14439:
1.648 raeburn 14440: =item * &build_recipient_list()
1.618 raeburn 14441:
1.1144 raeburn 14442: Build recipient lists for following types of e-mail:
1.766 raeburn 14443: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14444: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14445: module change checking, student/employee ID conflict checks, as
14446: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14447: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14448:
14449: Inputs:
1.619 raeburn 14450: defmail (scalar - email address of default recipient),
1.1144 raeburn 14451: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14452: requestsmail, updatesmail, or idconflictsmail).
14453:
1.619 raeburn 14454: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14455:
1.619 raeburn 14456: origmail (scalar - email address of recipient from loncapa.conf,
14457: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14458:
1.655 raeburn 14459: Returns: comma separated list of addresses to which to send e-mail.
14460:
14461: =back
1.618 raeburn 14462:
14463: =cut
14464:
14465: ############################################################
14466: ############################################################
14467: sub build_recipient_list {
1.619 raeburn 14468: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 14469: my @recipients;
14470: my $otheremails;
14471: my %domconfig =
14472: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
14473: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14474: if (exists($domconfig{'contacts'}{$mailing})) {
14475: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14476: my @contacts = ('adminemail','supportemail');
14477: foreach my $item (@contacts) {
14478: if ($domconfig{'contacts'}{$mailing}{$item}) {
14479: my $addr = $domconfig{'contacts'}{$item};
14480: if (!grep(/^\Q$addr\E$/,@recipients)) {
14481: push(@recipients,$addr);
14482: }
1.619 raeburn 14483: }
1.766 raeburn 14484: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 14485: }
14486: }
1.766 raeburn 14487: } elsif ($origmail ne '') {
14488: push(@recipients,$origmail);
1.618 raeburn 14489: }
1.619 raeburn 14490: } elsif ($origmail ne '') {
14491: push(@recipients,$origmail);
1.618 raeburn 14492: }
1.688 raeburn 14493: if (defined($defmail)) {
14494: if ($defmail ne '') {
14495: push(@recipients,$defmail);
14496: }
1.618 raeburn 14497: }
14498: if ($otheremails) {
1.619 raeburn 14499: my @others;
14500: if ($otheremails =~ /,/) {
14501: @others = split(/,/,$otheremails);
1.618 raeburn 14502: } else {
1.619 raeburn 14503: push(@others,$otheremails);
14504: }
14505: foreach my $addr (@others) {
14506: if (!grep(/^\Q$addr\E$/,@recipients)) {
14507: push(@recipients,$addr);
14508: }
1.618 raeburn 14509: }
14510: }
1.619 raeburn 14511: my $recipientlist = join(',',@recipients);
1.618 raeburn 14512: return $recipientlist;
14513: }
14514:
1.127 matthew 14515: ############################################################
14516: ############################################################
1.154 albertel 14517:
1.655 raeburn 14518: =pod
14519:
1.1224 musolffc 14520: =over 4
14521:
1.1223 musolffc 14522: =item * &mime_email()
14523:
14524: Sends an email with a possible attachment
14525:
14526: Inputs:
14527:
14528: =over 4
14529:
14530: from - Sender's email address
14531:
14532: to - Email address of recipient
14533:
14534: subject - Subject of email
14535:
14536: body - Body of email
14537:
14538: cc_string - Carbon copy email address
14539:
14540: bcc - Blind carbon copy email address
14541:
14542: type - File type of attachment
14543:
14544: attachment_path - Path of file to be attached
14545:
14546: file_name - Name of file to be attached
14547:
14548: attachment_text - The body of an attachment of type "TEXT"
14549:
14550: =back
14551:
14552: =back
14553:
14554: =cut
14555:
14556: ############################################################
14557: ############################################################
14558:
14559: sub mime_email {
14560: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
14561: $file_name, $attachment_text) = @_;
14562: my $msg = MIME::Lite->new(
14563: From => $from,
14564: To => $to,
14565: Subject => $subject,
14566: Type =>'TEXT',
14567: Data => $body,
14568: );
14569: if ($cc_string ne '') {
14570: $msg->add("Cc" => $cc_string);
14571: }
14572: if ($bcc ne '') {
14573: $msg->add("Bcc" => $bcc);
14574: }
14575: $msg->attr("content-type" => "text/plain");
14576: $msg->attr("content-type.charset" => "UTF-8");
14577: # Attach file if given
14578: if ($attachment_path) {
14579: unless ($file_name) {
14580: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
14581: }
14582: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
14583: $msg->attach(Type => $type,
14584: Path => $attachment_path,
14585: Filename => $file_name
14586: );
14587: # Otherwise attach text if given
14588: } elsif ($attachment_text) {
14589: $msg->attach(Type => 'TEXT',
14590: Data => $attachment_text);
14591: }
14592: # Send it
14593: $msg->send('sendmail');
14594: }
14595:
14596: ############################################################
14597: ############################################################
14598:
14599: =pod
14600:
1.655 raeburn 14601: =head1 Course Catalog Routines
14602:
14603: =over 4
14604:
14605: =item * &gather_categories()
14606:
14607: Converts category definitions - keys of categories hash stored in
14608: coursecategories in configuration.db on the primary library server in a
14609: domain - to an array. Also generates javascript and idx hash used to
14610: generate Domain Coordinator interface for editing Course Categories.
14611:
14612: Inputs:
1.663 raeburn 14613:
1.655 raeburn 14614: categories (reference to hash of category definitions).
1.663 raeburn 14615:
1.655 raeburn 14616: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14617: categories and subcategories).
1.663 raeburn 14618:
1.655 raeburn 14619: idx (reference to hash of counters used in Domain Coordinator interface for
14620: editing Course Categories).
1.663 raeburn 14621:
1.655 raeburn 14622: jsarray (reference to array of categories used to create Javascript arrays for
14623: Domain Coordinator interface for editing Course Categories).
14624:
14625: Returns: nothing
14626:
14627: Side effects: populates cats, idx and jsarray.
14628:
14629: =cut
14630:
14631: sub gather_categories {
14632: my ($categories,$cats,$idx,$jsarray) = @_;
14633: my %counters;
14634: my $num = 0;
14635: foreach my $item (keys(%{$categories})) {
14636: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14637: if ($container eq '' && $depth == 0) {
14638: $cats->[$depth][$categories->{$item}] = $cat;
14639: } else {
14640: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14641: }
14642: my ($escitem,$tail) = split(/:/,$item,2);
14643: if ($counters{$tail} eq '') {
14644: $counters{$tail} = $num;
14645: $num ++;
14646: }
14647: if (ref($idx) eq 'HASH') {
14648: $idx->{$item} = $counters{$tail};
14649: }
14650: if (ref($jsarray) eq 'ARRAY') {
14651: push(@{$jsarray->[$counters{$tail}]},$item);
14652: }
14653: }
14654: return;
14655: }
14656:
14657: =pod
14658:
14659: =item * &extract_categories()
14660:
14661: Used to generate breadcrumb trails for course categories.
14662:
14663: Inputs:
1.663 raeburn 14664:
1.655 raeburn 14665: categories (reference to hash of category definitions).
1.663 raeburn 14666:
1.655 raeburn 14667: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14668: categories and subcategories).
1.663 raeburn 14669:
1.655 raeburn 14670: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14671:
1.655 raeburn 14672: allitems (reference to hash - key is category key
14673: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14674:
1.655 raeburn 14675: idx (reference to hash of counters used in Domain Coordinator interface for
14676: editing Course Categories).
1.663 raeburn 14677:
1.655 raeburn 14678: jsarray (reference to array of categories used to create Javascript arrays for
14679: Domain Coordinator interface for editing Course Categories).
14680:
1.665 raeburn 14681: subcats (reference to hash of arrays containing all subcategories within each
14682: category, -recursive)
14683:
1.655 raeburn 14684: Returns: nothing
14685:
14686: Side effects: populates trails and allitems hash references.
14687:
14688: =cut
14689:
14690: sub extract_categories {
1.665 raeburn 14691: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14692: if (ref($categories) eq 'HASH') {
14693: &gather_categories($categories,$cats,$idx,$jsarray);
14694: if (ref($cats->[0]) eq 'ARRAY') {
14695: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14696: my $name = $cats->[0][$i];
14697: my $item = &escape($name).'::0';
14698: my $trailstr;
14699: if ($name eq 'instcode') {
14700: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14701: } elsif ($name eq 'communities') {
14702: $trailstr = &mt('Communities');
1.1239 raeburn 14703: } elsif ($name eq 'placement') {
14704: $trailstr = &mt('Placement Tests');
1.655 raeburn 14705: } else {
14706: $trailstr = $name;
14707: }
14708: if ($allitems->{$item} eq '') {
14709: push(@{$trails},$trailstr);
14710: $allitems->{$item} = scalar(@{$trails})-1;
14711: }
14712: my @parents = ($name);
14713: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14714: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14715: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14716: if (ref($subcats) eq 'HASH') {
14717: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14718: }
14719: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14720: }
14721: } else {
14722: if (ref($subcats) eq 'HASH') {
14723: $subcats->{$item} = [];
1.655 raeburn 14724: }
14725: }
14726: }
14727: }
14728: }
14729: return;
14730: }
14731:
14732: =pod
14733:
1.1162 raeburn 14734: =item * &recurse_categories()
1.655 raeburn 14735:
14736: Recursively used to generate breadcrumb trails for course categories.
14737:
14738: Inputs:
1.663 raeburn 14739:
1.655 raeburn 14740: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14741: categories and subcategories).
1.663 raeburn 14742:
1.655 raeburn 14743: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14744:
14745: category (current course category, for which breadcrumb trail is being generated).
14746:
14747: trails (reference to array of breadcrumb trails for each category).
14748:
1.655 raeburn 14749: allitems (reference to hash - key is category key
14750: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14751:
1.655 raeburn 14752: parents (array containing containers directories for current category,
14753: back to top level).
14754:
14755: Returns: nothing
14756:
14757: Side effects: populates trails and allitems hash references
14758:
14759: =cut
14760:
14761: sub recurse_categories {
1.665 raeburn 14762: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14763: my $shallower = $depth - 1;
14764: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14765: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14766: my $name = $cats->[$depth]{$category}[$k];
14767: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14768: my $trailstr = join(' -> ',(@{$parents},$category));
14769: if ($allitems->{$item} eq '') {
14770: push(@{$trails},$trailstr);
14771: $allitems->{$item} = scalar(@{$trails})-1;
14772: }
14773: my $deeper = $depth+1;
14774: push(@{$parents},$category);
1.665 raeburn 14775: if (ref($subcats) eq 'HASH') {
14776: my $subcat = &escape($name).':'.$category.':'.$depth;
14777: for (my $j=@{$parents}; $j>=0; $j--) {
14778: my $higher;
14779: if ($j > 0) {
14780: $higher = &escape($parents->[$j]).':'.
14781: &escape($parents->[$j-1]).':'.$j;
14782: } else {
14783: $higher = &escape($parents->[$j]).'::'.$j;
14784: }
14785: push(@{$subcats->{$higher}},$subcat);
14786: }
14787: }
14788: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14789: $subcats);
1.655 raeburn 14790: pop(@{$parents});
14791: }
14792: } else {
14793: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14794: my $trailstr = join(' -> ',(@{$parents},$category));
14795: if ($allitems->{$item} eq '') {
14796: push(@{$trails},$trailstr);
14797: $allitems->{$item} = scalar(@{$trails})-1;
14798: }
14799: }
14800: return;
14801: }
14802:
1.663 raeburn 14803: =pod
14804:
1.1162 raeburn 14805: =item * &assign_categories_table()
1.663 raeburn 14806:
14807: Create a datatable for display of hierarchical categories in a domain,
14808: with checkboxes to allow a course to be categorized.
14809:
14810: Inputs:
14811:
14812: cathash - reference to hash of categories defined for the domain (from
14813: configuration.db)
14814:
14815: currcat - scalar with an & separated list of categories assigned to a course.
14816:
1.919 raeburn 14817: type - scalar contains course type (Course or Community).
14818:
1.663 raeburn 14819: Returns: $output (markup to be displayed)
14820:
14821: =cut
14822:
14823: sub assign_categories_table {
1.919 raeburn 14824: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 14825: my $output;
14826: if (ref($cathash) eq 'HASH') {
14827: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
14828: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
14829: $maxdepth = scalar(@cats);
14830: if (@cats > 0) {
14831: my $itemcount = 0;
14832: if (ref($cats[0]) eq 'ARRAY') {
14833: my @currcategories;
14834: if ($currcat ne '') {
14835: @currcategories = split('&',$currcat);
14836: }
1.919 raeburn 14837: my $table;
1.663 raeburn 14838: for (my $i=0; $i<@{$cats[0]}; $i++) {
14839: my $parent = $cats[0][$i];
1.919 raeburn 14840: next if ($parent eq 'instcode');
14841: if ($type eq 'Community') {
14842: next unless ($parent eq 'communities');
1.1239 raeburn 14843: } elsif ($type eq 'Placement') {
14844: next unless ($parent eq 'placement');
1.919 raeburn 14845: } else {
1.1239 raeburn 14846: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 14847: }
1.663 raeburn 14848: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14849: my $item = &escape($parent).'::0';
14850: my $checked = '';
14851: if (@currcategories > 0) {
14852: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14853: $checked = ' checked="checked"';
1.663 raeburn 14854: }
14855: }
1.919 raeburn 14856: my $parent_title = $parent;
14857: if ($parent eq 'communities') {
14858: $parent_title = &mt('Communities');
1.1239 raeburn 14859: } elsif ($parent eq 'placement') {
14860: $parent_title = &mt('Placement Tests');
1.919 raeburn 14861: }
14862: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14863: '<input type="checkbox" name="usecategory" value="'.
14864: $item.'"'.$checked.' />'.$parent_title.'</span>'.
14865: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14866: my $depth = 1;
14867: push(@path,$parent);
1.919 raeburn 14868: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 14869: pop(@path);
1.919 raeburn 14870: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14871: $itemcount ++;
14872: }
1.919 raeburn 14873: if ($itemcount) {
14874: $output = &Apache::loncommon::start_data_table().
14875: $table.
14876: &Apache::loncommon::end_data_table();
14877: }
1.663 raeburn 14878: }
14879: }
14880: }
14881: return $output;
14882: }
14883:
14884: =pod
14885:
1.1162 raeburn 14886: =item * &assign_category_rows()
1.663 raeburn 14887:
14888: Create a datatable row for display of nested categories in a domain,
14889: with checkboxes to allow a course to be categorized,called recursively.
14890:
14891: Inputs:
14892:
14893: itemcount - track row number for alternating colors
14894:
14895: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14896: categories and subcategories.
14897:
14898: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14899:
14900: parent - parent of current category item
14901:
14902: path - Array containing all categories back up through the hierarchy from the
14903: current category to the top level.
14904:
14905: currcategories - reference to array of current categories assigned to the course
14906:
14907: Returns: $output (markup to be displayed).
14908:
14909: =cut
14910:
14911: sub assign_category_rows {
14912: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
14913: my ($text,$name,$item,$chgstr);
14914: if (ref($cats) eq 'ARRAY') {
14915: my $maxdepth = scalar(@{$cats});
14916: if (ref($cats->[$depth]) eq 'HASH') {
14917: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14918: my $numchildren = @{$cats->[$depth]{$parent}};
14919: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 14920: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14921: for (my $j=0; $j<$numchildren; $j++) {
14922: $name = $cats->[$depth]{$parent}[$j];
14923: $item = &escape($name).':'.&escape($parent).':'.$depth;
14924: my $deeper = $depth+1;
14925: my $checked = '';
14926: if (ref($currcategories) eq 'ARRAY') {
14927: if (@{$currcategories} > 0) {
14928: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14929: $checked = ' checked="checked"';
1.663 raeburn 14930: }
14931: }
14932: }
1.664 raeburn 14933: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14934: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 14935: $item.'"'.$checked.' />'.$name.'</label></span>'.
14936: '<input type="hidden" name="catname" value="'.$name.'" />'.
14937: '</td><td>';
1.663 raeburn 14938: if (ref($path) eq 'ARRAY') {
14939: push(@{$path},$name);
14940: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
14941: pop(@{$path});
14942: }
14943: $text .= '</td></tr>';
14944: }
14945: $text .= '</table></td>';
14946: }
14947: }
14948: }
14949: return $text;
14950: }
14951:
1.1181 raeburn 14952: =pod
14953:
14954: =back
14955:
14956: =cut
14957:
1.655 raeburn 14958: ############################################################
14959: ############################################################
14960:
14961:
1.443 albertel 14962: sub commit_customrole {
1.664 raeburn 14963: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14964: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14965: ($start?', '.&mt('starting').' '.localtime($start):'').
14966: ($end?', ending '.localtime($end):'').': <b>'.
14967: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14968: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14969: '</b><br />';
14970: return $output;
14971: }
14972:
14973: sub commit_standardrole {
1.1116 raeburn 14974: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14975: my ($output,$logmsg,$linefeed);
14976: if ($context eq 'auto') {
14977: $linefeed = "\n";
14978: } else {
14979: $linefeed = "<br />\n";
14980: }
1.443 albertel 14981: if ($three eq 'st') {
1.541 raeburn 14982: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 14983: $one,$two,$sec,$context,$credits);
1.541 raeburn 14984: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14985: ($result eq 'unknown_course') || ($result eq 'refused')) {
14986: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14987: } else {
1.541 raeburn 14988: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14989: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14990: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14991: if ($context eq 'auto') {
14992: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14993: } else {
14994: $output .= '<b>'.$result.'</b>'.$linefeed.
14995: &mt('Add to classlist').': <b>ok</b>';
14996: }
14997: $output .= $linefeed;
1.443 albertel 14998: }
14999: } else {
15000: $output = &mt('Assigning').' '.$three.' in '.$url.
15001: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15002: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15003: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15004: if ($context eq 'auto') {
15005: $output .= $result.$linefeed;
15006: } else {
15007: $output .= '<b>'.$result.'</b>'.$linefeed;
15008: }
1.443 albertel 15009: }
15010: return $output;
15011: }
15012:
15013: sub commit_studentrole {
1.1116 raeburn 15014: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15015: $credits) = @_;
1.626 raeburn 15016: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15017: if ($context eq 'auto') {
15018: $linefeed = "\n";
15019: } else {
15020: $linefeed = '<br />'."\n";
15021: }
1.443 albertel 15022: if (defined($one) && defined($two)) {
15023: my $cid=$one.'_'.$two;
15024: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15025: my $secchange = 0;
15026: my $expire_role_result;
15027: my $modify_section_result;
1.628 raeburn 15028: if ($oldsec ne '-1') {
15029: if ($oldsec ne $sec) {
1.443 albertel 15030: $secchange = 1;
1.628 raeburn 15031: my $now = time;
1.443 albertel 15032: my $uurl='/'.$cid;
15033: $uurl=~s/\_/\//g;
15034: if ($oldsec) {
15035: $uurl.='/'.$oldsec;
15036: }
1.626 raeburn 15037: $oldsecurl = $uurl;
1.628 raeburn 15038: $expire_role_result =
1.652 raeburn 15039: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15040: if ($env{'request.course.sec'} ne '') {
15041: if ($expire_role_result eq 'refused') {
15042: my @roles = ('st');
15043: my @statuses = ('previous');
15044: my @roledoms = ($one);
15045: my $withsec = 1;
15046: my %roleshash =
15047: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15048: \@statuses,\@roles,\@roledoms,$withsec);
15049: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15050: my ($oldstart,$oldend) =
15051: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15052: if ($oldend > 0 && $oldend <= $now) {
15053: $expire_role_result = 'ok';
15054: }
15055: }
15056: }
15057: }
1.443 albertel 15058: $result = $expire_role_result;
15059: }
15060: }
15061: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15062: $modify_section_result =
15063: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15064: undef,undef,undef,$sec,
15065: $end,$start,'','',$cid,
15066: '',$context,$credits);
1.443 albertel 15067: if ($modify_section_result =~ /^ok/) {
15068: if ($secchange == 1) {
1.628 raeburn 15069: if ($sec eq '') {
15070: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15071: } else {
15072: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15073: }
1.443 albertel 15074: } elsif ($oldsec eq '-1') {
1.628 raeburn 15075: if ($sec eq '') {
15076: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15077: } else {
15078: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15079: }
1.443 albertel 15080: } else {
1.628 raeburn 15081: if ($sec eq '') {
15082: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15083: } else {
15084: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15085: }
1.443 albertel 15086: }
15087: } else {
1.1115 raeburn 15088: if ($secchange) {
1.628 raeburn 15089: $$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;
15090: } else {
15091: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15092: }
1.443 albertel 15093: }
15094: $result = $modify_section_result;
15095: } elsif ($secchange == 1) {
1.628 raeburn 15096: if ($oldsec eq '') {
1.1103 raeburn 15097: $$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 15098: } else {
15099: $$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;
15100: }
1.626 raeburn 15101: if ($expire_role_result eq 'refused') {
15102: my $newsecurl = '/'.$cid;
15103: $newsecurl =~ s/\_/\//g;
15104: if ($sec ne '') {
15105: $newsecurl.='/'.$sec;
15106: }
15107: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15108: if ($sec eq '') {
15109: $$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;
15110: } else {
15111: $$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;
15112: }
15113: }
15114: }
1.443 albertel 15115: }
15116: } else {
1.626 raeburn 15117: $$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 15118: $result = "error: incomplete course id\n";
15119: }
15120: return $result;
15121: }
15122:
1.1108 raeburn 15123: sub show_role_extent {
15124: my ($scope,$context,$role) = @_;
15125: $scope =~ s{^/}{};
15126: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15127: push(@courseroles,'co');
15128: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15129: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15130: $scope =~ s{/}{_};
15131: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15132: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15133: my ($audom,$auname) = split(/\//,$scope);
15134: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15135: &Apache::loncommon::plainname($auname,$audom).'</span>');
15136: } else {
15137: $scope =~ s{/$}{};
15138: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15139: &Apache::lonnet::domain($scope,'description').'</span>');
15140: }
15141: }
15142:
1.443 albertel 15143: ############################################################
15144: ############################################################
15145:
1.566 albertel 15146: sub check_clone {
1.578 raeburn 15147: my ($args,$linefeed) = @_;
1.566 albertel 15148: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15149: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15150: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15151: my $clonemsg;
15152: my $can_clone = 0;
1.944 raeburn 15153: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15154: if ($lctype ne 'community') {
15155: $lctype = 'course';
15156: }
1.566 albertel 15157: if ($clonehome eq 'no_host') {
1.944 raeburn 15158: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15159: $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'});
15160: } else {
15161: $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'});
15162: }
1.566 albertel 15163: } else {
15164: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15165: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15166: if ($clonedesc{'type'} ne 'Community') {
15167: $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'});
15168: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15169: }
15170: }
1.882 raeburn 15171: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
15172: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15173: $can_clone = 1;
15174: } else {
1.1221 raeburn 15175: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15176: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15177: if ($clonehash{'cloners'} eq '') {
15178: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15179: if ($domdefs{'canclone'}) {
15180: unless ($domdefs{'canclone'} eq 'none') {
15181: if ($domdefs{'canclone'} eq 'domain') {
15182: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15183: $can_clone = 1;
15184: }
15185: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15186: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15187: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15188: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15189: $can_clone = 1;
15190: }
15191: }
15192: }
15193: }
1.578 raeburn 15194: } else {
1.1221 raeburn 15195: my @cloners = split(/,/,$clonehash{'cloners'});
15196: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15197: $can_clone = 1;
1.1221 raeburn 15198: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15199: $can_clone = 1;
1.1225 raeburn 15200: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15201: $can_clone = 1;
1.1221 raeburn 15202: }
15203: unless ($can_clone) {
1.1225 raeburn 15204: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15205: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15206: my (%gotdomdefaults,%gotcodedefaults);
15207: foreach my $cloner (@cloners) {
15208: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15209: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15210: my (%codedefaults,@code_order);
15211: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15212: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15213: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15214: }
15215: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15216: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15217: }
15218: } else {
15219: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15220: \%codedefaults,
15221: \@code_order);
15222: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15223: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15224: }
15225: if (@code_order > 0) {
15226: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15227: $cloner,$clonehash{'internal.coursecode'},
15228: $args->{'crscode'})) {
15229: $can_clone = 1;
15230: last;
15231: }
15232: }
15233: }
15234: }
15235: }
1.1225 raeburn 15236: }
15237: }
15238: unless ($can_clone) {
15239: my $ccrole = 'cc';
15240: if ($args->{'crstype'} eq 'Community') {
15241: $ccrole = 'co';
15242: }
15243: my %roleshash =
15244: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15245: $args->{'ccdomain'},
15246: 'userroles',['active'],[$ccrole],
15247: [$args->{'clonedomain'}]);
15248: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15249: $can_clone = 1;
15250: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15251: $args->{'ccuname'},$args->{'ccdomain'})) {
15252: $can_clone = 1;
1.1221 raeburn 15253: }
15254: }
15255: unless ($can_clone) {
15256: if ($args->{'crstype'} eq 'Community') {
15257: $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 15258: } else {
1.1221 raeburn 15259: $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'});
15260: }
1.566 albertel 15261: }
1.578 raeburn 15262: }
1.566 albertel 15263: }
15264: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15265: }
15266:
1.444 albertel 15267: sub construct_course {
1.1166 raeburn 15268: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 15269: my $outcome;
1.541 raeburn 15270: my $linefeed = '<br />'."\n";
15271: if ($context eq 'auto') {
15272: $linefeed = "\n";
15273: }
1.566 albertel 15274:
15275: #
15276: # Are we cloning?
15277: #
15278: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15279: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15280: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15281: if ($context ne 'auto') {
1.578 raeburn 15282: if ($clonemsg ne '') {
15283: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15284: }
1.566 albertel 15285: }
15286: $outcome .= $clonemsg.$linefeed;
15287:
15288: if (!$can_clone) {
15289: return (0,$outcome);
15290: }
15291: }
15292:
1.444 albertel 15293: #
15294: # Open course
15295: #
1.1239 raeburn 15296: my $showncrstype;
15297: if ($args->{'crstype'} eq 'Placement') {
15298: $showncrstype = 'placement test';
15299: } else {
15300: $showncrstype = lc($args->{'crstype'});
15301: }
1.444 albertel 15302: my %cenv=();
15303: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15304: $args->{'cdescr'},
15305: $args->{'curl'},
15306: $args->{'course_home'},
15307: $args->{'nonstandard'},
15308: $args->{'crscode'},
15309: $args->{'ccuname'}.':'.
15310: $args->{'ccdomain'},
1.882 raeburn 15311: $args->{'crstype'},
1.885 raeburn 15312: $cnum,$context,$category);
1.444 albertel 15313:
15314: # Note: The testing routines depend on this being output; see
15315: # Utils::Course. This needs to at least be output as a comment
15316: # if anyone ever decides to not show this, and Utils::Course::new
15317: # will need to be suitably modified.
1.1239 raeburn 15318: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15319: if ($$courseid =~ /^error:/) {
15320: return (0,$outcome);
15321: }
15322:
1.444 albertel 15323: #
15324: # Check if created correctly
15325: #
1.479 albertel 15326: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15327: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15328: if ($crsuhome eq 'no_host') {
15329: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15330: return (0,$outcome);
15331: }
1.541 raeburn 15332: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15333:
1.444 albertel 15334: #
1.566 albertel 15335: # Do the cloning
15336: #
15337: if ($can_clone && $cloneid) {
1.1239 raeburn 15338: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 15339: if ($context ne 'auto') {
15340: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15341: }
15342: $outcome .= $clonemsg.$linefeed;
15343: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15344: # Copy all files
1.637 www 15345: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15346: # Restore URL
1.566 albertel 15347: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15348: # Restore title
1.566 albertel 15349: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15350: # Restore creation date, creator and creation context.
15351: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15352: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15353: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15354: # Mark as cloned
1.566 albertel 15355: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15356: # Need to clone grading mode
15357: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15358: $cenv{'grading'}=$newenv{'grading'};
15359: # Do not clone these environment entries
15360: &Apache::lonnet::del('environment',
15361: ['default_enrollment_start_date',
15362: 'default_enrollment_end_date',
15363: 'question.email',
15364: 'policy.email',
15365: 'comment.email',
15366: 'pch.users.denied',
1.725 raeburn 15367: 'plc.users.denied',
15368: 'hidefromcat',
1.1121 raeburn 15369: 'checkforpriv',
1.1166 raeburn 15370: 'categories',
15371: 'internal.uniquecode'],
1.638 www 15372: $$crsudom,$$crsunum);
1.1170 raeburn 15373: if ($args->{'textbook'}) {
15374: $cenv{'internal.textbook'} = $args->{'textbook'};
15375: }
1.444 albertel 15376: }
1.566 albertel 15377:
1.444 albertel 15378: #
15379: # Set environment (will override cloned, if existing)
15380: #
15381: my @sections = ();
15382: my @xlists = ();
15383: if ($args->{'crstype'}) {
15384: $cenv{'type'}=$args->{'crstype'};
15385: }
15386: if ($args->{'crsid'}) {
15387: $cenv{'courseid'}=$args->{'crsid'};
15388: }
15389: if ($args->{'crscode'}) {
15390: $cenv{'internal.coursecode'}=$args->{'crscode'};
15391: }
15392: if ($args->{'crsquota'} ne '') {
15393: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15394: } else {
15395: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15396: }
15397: if ($args->{'ccuname'}) {
15398: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15399: ':'.$args->{'ccdomain'};
15400: } else {
15401: $cenv{'internal.courseowner'} = $args->{'curruser'};
15402: }
1.1116 raeburn 15403: if ($args->{'defaultcredits'}) {
15404: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15405: }
1.444 albertel 15406: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15407: if ($args->{'crssections'}) {
15408: $cenv{'internal.sectionnums'} = '';
15409: if ($args->{'crssections'} =~ m/,/) {
15410: @sections = split/,/,$args->{'crssections'};
15411: } else {
15412: $sections[0] = $args->{'crssections'};
15413: }
15414: if (@sections > 0) {
15415: foreach my $item (@sections) {
15416: my ($sec,$gp) = split/:/,$item;
15417: my $class = $args->{'crscode'}.$sec;
15418: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15419: $cenv{'internal.sectionnums'} .= $item.',';
15420: unless ($addcheck eq 'ok') {
15421: push @badclasses, $class;
15422: }
15423: }
15424: $cenv{'internal.sectionnums'} =~ s/,$//;
15425: }
15426: }
15427: # do not hide course coordinator from staff listing,
15428: # even if privileged
15429: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 15430: # add course coordinator's domain to domains to check for privileged users
15431: # if different to course domain
15432: if ($$crsudom ne $args->{'ccdomain'}) {
15433: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15434: }
1.444 albertel 15435: # add crosslistings
15436: if ($args->{'crsxlist'}) {
15437: $cenv{'internal.crosslistings'}='';
15438: if ($args->{'crsxlist'} =~ m/,/) {
15439: @xlists = split/,/,$args->{'crsxlist'};
15440: } else {
15441: $xlists[0] = $args->{'crsxlist'};
15442: }
15443: if (@xlists > 0) {
15444: foreach my $item (@xlists) {
15445: my ($xl,$gp) = split/:/,$item;
15446: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15447: $cenv{'internal.crosslistings'} .= $item.',';
15448: unless ($addcheck eq 'ok') {
15449: push @badclasses, $xl;
15450: }
15451: }
15452: $cenv{'internal.crosslistings'} =~ s/,$//;
15453: }
15454: }
15455: if ($args->{'autoadds'}) {
15456: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15457: }
15458: if ($args->{'autodrops'}) {
15459: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15460: }
15461: # check for notification of enrollment changes
15462: my @notified = ();
15463: if ($args->{'notify_owner'}) {
15464: if ($args->{'ccuname'} ne '') {
15465: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15466: }
15467: }
15468: if ($args->{'notify_dc'}) {
15469: if ($uname ne '') {
1.630 raeburn 15470: push(@notified,$uname.':'.$udom);
1.444 albertel 15471: }
15472: }
15473: if (@notified > 0) {
15474: my $notifylist;
15475: if (@notified > 1) {
15476: $notifylist = join(',',@notified);
15477: } else {
15478: $notifylist = $notified[0];
15479: }
15480: $cenv{'internal.notifylist'} = $notifylist;
15481: }
15482: if (@badclasses > 0) {
15483: my %lt=&Apache::lonlocal::texthash(
15484: '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',
15485: 'dnhr' => 'does not have rights to access enrollment in these classes',
15486: 'adby' => 'as determined by the policies of your institution on access to official classlists'
15487: );
1.541 raeburn 15488: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
15489: ' ('.$lt{'adby'}.')';
15490: if ($context eq 'auto') {
15491: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 15492: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 15493: foreach my $item (@badclasses) {
15494: if ($context eq 'auto') {
15495: $outcome .= " - $item\n";
15496: } else {
15497: $outcome .= "<li>$item</li>\n";
15498: }
15499: }
15500: if ($context eq 'auto') {
15501: $outcome .= $linefeed;
15502: } else {
1.566 albertel 15503: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 15504: }
15505: }
1.444 albertel 15506: }
15507: if ($args->{'no_end_date'}) {
15508: $args->{'endaccess'} = 0;
15509: }
15510: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15511: $cenv{'internal.autoend'}=$args->{'enrollend'};
15512: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15513: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15514: if ($args->{'showphotos'}) {
15515: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15516: }
15517: $cenv{'internal.authtype'} = $args->{'authtype'};
15518: $cenv{'internal.autharg'} = $args->{'autharg'};
15519: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15520: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15521: 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');
15522: if ($context eq 'auto') {
15523: $outcome .= $krb_msg;
15524: } else {
1.566 albertel 15525: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15526: }
15527: $outcome .= $linefeed;
1.444 albertel 15528: }
15529: }
15530: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15531: if ($args->{'setpolicy'}) {
15532: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15533: }
15534: if ($args->{'setcontent'}) {
15535: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15536: }
1.1251 raeburn 15537: if ($args->{'setcomment'}) {
15538: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15539: }
1.444 albertel 15540: }
15541: if ($args->{'reshome'}) {
15542: $cenv{'reshome'}=$args->{'reshome'}.'/';
15543: $cenv{'reshome'}=~s/\/+$/\//;
15544: }
15545: #
15546: # course has keyed access
15547: #
15548: if ($args->{'setkeys'}) {
15549: $cenv{'keyaccess'}='yes';
15550: }
15551: # if specified, key authority is not course, but user
15552: # only active if keyaccess is yes
15553: if ($args->{'keyauth'}) {
1.487 albertel 15554: my ($user,$domain) = split(':',$args->{'keyauth'});
15555: $user = &LONCAPA::clean_username($user);
15556: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15557: if ($user ne '' && $domain ne '') {
1.487 albertel 15558: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15559: }
15560: }
15561:
1.1166 raeburn 15562: #
1.1167 raeburn 15563: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 15564: #
15565: if ($args->{'uniquecode'}) {
15566: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15567: if ($code) {
15568: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 15569: my %crsinfo =
15570: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15571: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15572: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15573: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15574: }
1.1166 raeburn 15575: if (ref($coderef)) {
15576: $$coderef = $code;
15577: }
15578: }
15579: }
15580:
1.444 albertel 15581: if ($args->{'disresdis'}) {
15582: $cenv{'pch.roles.denied'}='st';
15583: }
15584: if ($args->{'disablechat'}) {
15585: $cenv{'plc.roles.denied'}='st';
15586: }
15587:
15588: # Record we've not yet viewed the Course Initialization Helper for this
15589: # course
15590: $cenv{'course.helper.not.run'} = 1;
15591: #
15592: # Use new Randomseed
15593: #
15594: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15595: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15596: #
15597: # The encryption code and receipt prefix for this course
15598: #
15599: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15600: $cenv{'internal.encpref'}=100+int(9*rand(99));
15601: #
15602: # By default, use standard grading
15603: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15604:
1.541 raeburn 15605: $outcome .= $linefeed.&mt('Setting environment').': '.
15606: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15607: #
15608: # Open all assignments
15609: #
15610: if ($args->{'openall'}) {
15611: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15612: my %storecontent = ($storeunder => time,
15613: $storeunder.'.type' => 'date_start');
15614:
15615: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15616: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15617: }
15618: #
15619: # Set first page
15620: #
15621: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15622: || ($cloneid)) {
1.445 albertel 15623: use LONCAPA::map;
1.444 albertel 15624: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15625:
15626: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15627: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15628:
1.444 albertel 15629: $outcome .= ($fatal?$errtext:'read ok').' - ';
15630: my $title; my $url;
15631: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15632: $title=&mt('Syllabus');
1.444 albertel 15633: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15634: } else {
1.963 raeburn 15635: $title=&mt('Table of Contents');
1.444 albertel 15636: $url='/adm/navmaps';
15637: }
1.445 albertel 15638:
15639: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15640: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15641:
15642: if ($errtext) { $fatal=2; }
1.541 raeburn 15643: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15644: }
1.566 albertel 15645:
1.1237 raeburn 15646: #
15647: # Set params for Placement Tests
15648: #
1.1239 raeburn 15649: if ($args->{'crstype'} eq 'Placement') {
15650: my %storecontent;
15651: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
15652: my %defaults = (
15653: buttonshide => { value => 'yes',
15654: type => 'string_yesno',},
15655: type => { value => 'randomizetry',
15656: type => 'string_questiontype',},
15657: maxtries => { value => 1,
15658: type => 'int_pos',},
15659: problemstatus => { value => 'no',
15660: type => 'string_problemstatus',},
15661: );
15662: foreach my $key (keys(%defaults)) {
15663: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
15664: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
15665: }
1.1237 raeburn 15666: &Apache::lonnet::cput
15667: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
15668: }
15669:
1.566 albertel 15670: return (1,$outcome);
1.444 albertel 15671: }
15672:
1.1166 raeburn 15673: sub make_unique_code {
15674: my ($cdom,$cnum) = @_;
15675: # get lock on uniquecodes db
15676: my $lockhash = {
15677: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15678: ':'.$env{'user.domain'},
15679: };
15680: my $tries = 0;
15681: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15682: my ($code,$error);
15683:
15684: while (($gotlock ne 'ok') && ($tries<3)) {
15685: $tries ++;
15686: sleep 1;
15687: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15688: }
15689: if ($gotlock eq 'ok') {
15690: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15691: my $gotcode;
15692: my $attempts = 0;
15693: while ((!$gotcode) && ($attempts < 100)) {
15694: $code = &generate_code();
15695: if (!exists($currcodes{$code})) {
15696: $gotcode = 1;
15697: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15698: $error = 'nostore';
15699: }
15700: }
15701: $attempts ++;
15702: }
15703: my @del_lock = ($cnum."\0".'uniquecodes');
15704: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15705: } else {
15706: $error = 'nolock';
15707: }
15708: return ($code,$error);
15709: }
15710:
15711: sub generate_code {
15712: my $code;
15713: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15714: for (my $i=0; $i<6; $i++) {
15715: my $lettnum = int (rand 2);
15716: my $item = '';
15717: if ($lettnum) {
15718: $item = $letts[int( rand(18) )];
15719: } else {
15720: $item = 1+int( rand(8) );
15721: }
15722: $code .= $item;
15723: }
15724: return $code;
15725: }
15726:
1.444 albertel 15727: ############################################################
15728: ############################################################
15729:
1.1237 raeburn 15730: # Community, Course and Placement Test
1.378 raeburn 15731: sub course_type {
15732: my ($cid) = @_;
15733: if (!defined($cid)) {
15734: $cid = $env{'request.course.id'};
15735: }
1.404 albertel 15736: if (defined($env{'course.'.$cid.'.type'})) {
15737: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15738: } else {
15739: return 'Course';
1.377 raeburn 15740: }
15741: }
1.156 albertel 15742:
1.406 raeburn 15743: sub group_term {
15744: my $crstype = &course_type();
15745: my %names = (
15746: 'Course' => 'group',
1.865 raeburn 15747: 'Community' => 'group',
1.1237 raeburn 15748: 'Placement' => 'group',
1.406 raeburn 15749: );
15750: return $names{$crstype};
15751: }
15752:
1.902 raeburn 15753: sub course_types {
1.1237 raeburn 15754: my @types = ('official','unofficial','community','textbook','placement');
1.902 raeburn 15755: my %typename = (
15756: official => 'Official course',
15757: unofficial => 'Unofficial course',
15758: community => 'Community',
1.1165 raeburn 15759: textbook => 'Textbook course',
1.1237 raeburn 15760: placement => 'Placement test',
1.902 raeburn 15761: );
15762: return (\@types,\%typename);
15763: }
15764:
1.156 albertel 15765: sub icon {
15766: my ($file)=@_;
1.505 albertel 15767: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15768: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15769: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15770: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15771: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15772: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15773: $curfext.".gif") {
15774: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15775: $curfext.".gif";
15776: }
15777: }
1.249 albertel 15778: return &lonhttpdurl($iconname);
1.154 albertel 15779: }
1.84 albertel 15780:
1.575 albertel 15781: sub lonhttpdurl {
1.692 www 15782: #
15783: # Had been used for "small fry" static images on separate port 8080.
15784: # Modify here if lightweight http functionality desired again.
15785: # Currently eliminated due to increasing firewall issues.
15786: #
1.575 albertel 15787: my ($url)=@_;
1.692 www 15788: return $url;
1.215 albertel 15789: }
15790:
1.213 albertel 15791: sub connection_aborted {
15792: my ($r)=@_;
15793: $r->print(" ");$r->rflush();
15794: my $c = $r->connection;
15795: return $c->aborted();
15796: }
15797:
1.221 foxr 15798: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15799: # strings as 'strings'.
15800: sub escape_single {
1.221 foxr 15801: my ($input) = @_;
1.223 albertel 15802: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15803: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15804: return $input;
15805: }
1.223 albertel 15806:
1.222 foxr 15807: # Same as escape_single, but escape's "'s This
15808: # can be used for "strings"
15809: sub escape_double {
15810: my ($input) = @_;
15811: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15812: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15813: return $input;
15814: }
1.223 albertel 15815:
1.222 foxr 15816: # Escapes the last element of a full URL.
15817: sub escape_url {
15818: my ($url) = @_;
1.238 raeburn 15819: my @urlslices = split(/\//, $url,-1);
1.369 www 15820: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 15821: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15822: }
1.462 albertel 15823:
1.820 raeburn 15824: sub compare_arrays {
15825: my ($arrayref1,$arrayref2) = @_;
15826: my (@difference,%count);
15827: @difference = ();
15828: %count = ();
15829: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15830: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15831: foreach my $element (keys(%count)) {
15832: if ($count{$element} == 1) {
15833: push(@difference,$element);
15834: }
15835: }
15836: }
15837: return @difference;
15838: }
15839:
1.817 bisitz 15840: # -------------------------------------------------------- Initialize user login
1.462 albertel 15841: sub init_user_environment {
1.463 albertel 15842: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15843: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15844:
15845: my $public=($username eq 'public' && $domain eq 'public');
15846:
15847: # See if old ID present, if so, remove
15848:
1.1062 raeburn 15849: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15850: my $now=time;
15851:
15852: if ($public) {
15853: my $max_public=100;
15854: my $oldest;
15855: my $oldest_time=0;
15856: for(my $next=1;$next<=$max_public;$next++) {
15857: if (-e $lonids."/publicuser_$next.id") {
15858: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15859: if ($mtime<$oldest_time || !$oldest_time) {
15860: $oldest_time=$mtime;
15861: $oldest=$next;
15862: }
15863: } else {
15864: $cookie="publicuser_$next";
15865: last;
15866: }
15867: }
15868: if (!$cookie) { $cookie="publicuser_$oldest"; }
15869: } else {
1.463 albertel 15870: # if this isn't a robot, kill any existing non-robot sessions
15871: if (!$args->{'robot'}) {
15872: opendir(DIR,$lonids);
15873: while ($filename=readdir(DIR)) {
15874: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
15875: unlink($lonids.'/'.$filename);
15876: }
1.462 albertel 15877: }
1.463 albertel 15878: closedir(DIR);
1.1204 raeburn 15879: # If there is a undeleted lockfile for the user's paste buffer remove it.
15880: my $namespace = 'nohist_courseeditor';
15881: my $lockingkey = 'paste'."\0".'locked_num';
15882: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15883: $domain,$username);
15884: if (exists($lockhash{$lockingkey})) {
15885: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15886: unless ($delresult eq 'ok') {
15887: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15888: }
15889: }
1.462 albertel 15890: }
15891: # Give them a new cookie
1.463 albertel 15892: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15893: : $now.$$.int(rand(10000)));
1.463 albertel 15894: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15895:
15896: # Initialize roles
15897:
1.1062 raeburn 15898: ($userroles,$firstaccenv,$timerintenv) =
15899: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15900: }
15901: # ------------------------------------ Check browser type and MathML capability
15902:
1.1194 raeburn 15903: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15904: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15905:
15906: # ------------------------------------------------------------- Get environment
15907:
15908: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15909: my ($tmp) = keys(%userenv);
15910: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15911: } else {
15912: undef(%userenv);
15913: }
15914: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15915: $form->{'interface'}=$userenv{'interface'};
15916: }
15917: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15918:
15919: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15920: foreach my $option ('interface','localpath','localres') {
15921: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15922: }
15923: # --------------------------------------------------------- Write first profile
15924:
15925: {
15926: my %initial_env =
15927: ("user.name" => $username,
15928: "user.domain" => $domain,
15929: "user.home" => $authhost,
15930: "browser.type" => $clientbrowser,
15931: "browser.version" => $clientversion,
15932: "browser.mathml" => $clientmathml,
15933: "browser.unicode" => $clientunicode,
15934: "browser.os" => $clientos,
1.1137 raeburn 15935: "browser.mobile" => $clientmobile,
1.1141 raeburn 15936: "browser.info" => $clientinfo,
1.1194 raeburn 15937: "browser.osversion" => $clientosversion,
1.462 albertel 15938: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15939: "request.course.fn" => '',
15940: "request.course.uri" => '',
15941: "request.course.sec" => '',
15942: "request.role" => 'cm',
15943: "request.role.adv" => $env{'user.adv'},
15944: "request.host" => $ENV{'REMOTE_ADDR'},);
15945:
15946: if ($form->{'localpath'}) {
15947: $initial_env{"browser.localpath"} = $form->{'localpath'};
15948: $initial_env{"browser.localres"} = $form->{'localres'};
15949: }
15950:
15951: if ($form->{'interface'}) {
15952: $form->{'interface'}=~s/\W//gs;
15953: $initial_env{"browser.interface"} = $form->{'interface'};
15954: $env{'browser.interface'}=$form->{'interface'};
15955: }
15956:
1.1157 raeburn 15957: if ($form->{'iptoken'}) {
15958: my $lonhost = $r->dir_config('lonHostID');
15959: $initial_env{"user.noloadbalance"} = $lonhost;
15960: $env{'user.noloadbalance'} = $lonhost;
15961: }
15962:
1.981 raeburn 15963: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 15964: my %domdef;
15965: unless ($domain eq 'public') {
15966: %domdef = &Apache::lonnet::get_domain_defaults($domain);
15967: }
1.980 raeburn 15968:
1.1081 raeburn 15969: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 15970: $userenv{'availabletools.'.$tool} =
1.980 raeburn 15971: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15972: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 15973: }
15974:
1.1237 raeburn 15975: foreach my $crstype ('official','unofficial','community','textbook','placement') {
1.765 raeburn 15976: $userenv{'canrequest.'.$crstype} =
15977: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 15978: 'reload','requestcourses',
15979: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 15980: }
15981:
1.1092 raeburn 15982: $userenv{'canrequest.author'} =
15983: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15984: 'reload','requestauthor',
15985: \%userenv,\%domdef,\%is_adv);
15986: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15987: $domain,$username);
15988: my $reqstatus = $reqauthor{'author_status'};
15989: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15990: if (ref($reqauthor{'author'}) eq 'HASH') {
15991: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15992: $reqauthor{'author'}{'timestamp'};
15993: }
15994: }
15995:
1.462 albertel 15996: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15997:
1.462 albertel 15998: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15999: &GDBM_WRCREAT(),0640)) {
16000: &_add_to_env(\%disk_env,\%initial_env);
16001: &_add_to_env(\%disk_env,\%userenv,'environment.');
16002: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16003: if (ref($firstaccenv) eq 'HASH') {
16004: &_add_to_env(\%disk_env,$firstaccenv);
16005: }
16006: if (ref($timerintenv) eq 'HASH') {
16007: &_add_to_env(\%disk_env,$timerintenv);
16008: }
1.463 albertel 16009: if (ref($args->{'extra_env'})) {
16010: &_add_to_env(\%disk_env,$args->{'extra_env'});
16011: }
1.462 albertel 16012: untie(%disk_env);
16013: } else {
1.705 tempelho 16014: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16015: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16016: return 'error: '.$!;
16017: }
16018: }
16019: $env{'request.role'}='cm';
16020: $env{'request.role.adv'}=$env{'user.adv'};
16021: $env{'browser.type'}=$clientbrowser;
16022:
16023: return $cookie;
16024:
16025: }
16026:
16027: sub _add_to_env {
16028: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16029: if (ref($env_data) eq 'HASH') {
16030: while (my ($key,$value) = each(%$env_data)) {
16031: $idf->{$prefix.$key} = $value;
16032: $env{$prefix.$key} = $value;
16033: }
1.462 albertel 16034: }
16035: }
16036:
1.685 tempelho 16037: # --- Get the symbolic name of a problem and the url
16038: sub get_symb {
16039: my ($request,$silent) = @_;
1.726 raeburn 16040: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16041: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16042: if ($symb eq '') {
16043: if (!$silent) {
1.1071 raeburn 16044: if (ref($request)) {
16045: $request->print("Unable to handle ambiguous references:$url:.");
16046: }
1.685 tempelho 16047: return ();
16048: }
16049: }
16050: &Apache::lonenc::check_decrypt(\$symb);
16051: return ($symb);
16052: }
16053:
16054: # --------------------------------------------------------------Get annotation
16055:
16056: sub get_annotation {
16057: my ($symb,$enc) = @_;
16058:
16059: my $key = $symb;
16060: if (!$enc) {
16061: $key =
16062: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16063: }
16064: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16065: return $annotation{$key};
16066: }
16067:
16068: sub clean_symb {
1.731 raeburn 16069: my ($symb,$delete_enc) = @_;
1.685 tempelho 16070:
16071: &Apache::lonenc::check_decrypt(\$symb);
16072: my $enc = $env{'request.enc'};
1.731 raeburn 16073: if ($delete_enc) {
1.730 raeburn 16074: delete($env{'request.enc'});
16075: }
1.685 tempelho 16076:
16077: return ($symb,$enc);
16078: }
1.462 albertel 16079:
1.1181 raeburn 16080: ############################################################
16081: ############################################################
16082:
16083: =pod
16084:
16085: =head1 Routines for building display used to search for courses
16086:
16087:
16088: =over 4
16089:
16090: =item * &build_filters()
16091:
16092: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16093: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16094: and quotacheck.pl
16095:
1.1181 raeburn 16096:
16097: Inputs:
16098:
16099: filterlist - anonymous array of fields to include as potential filters
16100:
16101: crstype - course type
16102:
16103: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16104: to pop-open a course selector (will contain "extra element").
16105:
16106: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16107:
16108: filter - anonymous hash of criteria and their values
16109:
16110: action - form action
16111:
16112: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16113:
1.1182 raeburn 16114: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16115:
16116: cloneruname - username of owner of new course who wants to clone
16117:
16118: clonerudom - domain of owner of new course who wants to clone
16119:
16120: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16121:
16122: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16123:
16124: codedom - domain
16125:
16126: formname - value of form element named "form".
16127:
16128: fixeddom - domain, if fixed.
16129:
16130: prevphase - value to assign to form element named "phase" when going back to the previous screen
16131:
16132: cnameelement - name of form element in form on opener page which will receive title of selected course
16133:
16134: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16135:
16136: cdomelement - name of form element in form on opener page which will receive domain of selected course
16137:
16138: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16139:
16140: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16141:
16142: clonewarning - warning message about missing information for intended course owner when DC creates a course
16143:
1.1182 raeburn 16144:
1.1181 raeburn 16145: Returns: $output - HTML for display of search criteria, and hidden form elements.
16146:
1.1182 raeburn 16147:
1.1181 raeburn 16148: Side Effects: None
16149:
16150: =cut
16151:
16152: # ---------------------------------------------- search for courses based on last activity etc.
16153:
16154: sub build_filters {
16155: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16156: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16157: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16158: $cnameelement,$cnumelement,$cdomelement,$setroles,
16159: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16160: my ($list,$jscript);
1.1181 raeburn 16161: my $onchange = 'javascript:updateFilters(this)';
16162: my ($domainselectform,$sincefilterform,$createdfilterform,
16163: $ownerdomselectform,$persondomselectform,$instcodeform,
16164: $typeselectform,$instcodetitle);
16165: if ($formname eq '') {
16166: $formname = $caller;
16167: }
16168: foreach my $item (@{$filterlist}) {
16169: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16170: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16171: if ($item eq 'domainfilter') {
16172: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16173: } elsif ($item eq 'coursefilter') {
16174: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16175: } elsif ($item eq 'ownerfilter') {
16176: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16177: } elsif ($item eq 'ownerdomfilter') {
16178: $filter->{'ownerdomfilter'} =
16179: &LONCAPA::clean_domain($filter->{$item});
16180: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16181: 'ownerdomfilter',1);
16182: } elsif ($item eq 'personfilter') {
16183: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16184: } elsif ($item eq 'persondomfilter') {
16185: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16186: 'persondomfilter',1);
16187: } else {
16188: $filter->{$item} =~ s/\W//g;
16189: }
16190: if (!$filter->{$item}) {
16191: $filter->{$item} = '';
16192: }
16193: }
16194: if ($item eq 'domainfilter') {
16195: my $allow_blank = 1;
16196: if ($formname eq 'portform') {
16197: $allow_blank=0;
16198: } elsif ($formname eq 'studentform') {
16199: $allow_blank=0;
16200: }
16201: if ($fixeddom) {
16202: $domainselectform = '<input type="hidden" name="domainfilter"'.
16203: ' value="'.$codedom.'" />'.
16204: &Apache::lonnet::domain($codedom,'description');
16205: } else {
16206: $domainselectform = &select_dom_form($filter->{$item},
16207: 'domainfilter',
16208: $allow_blank,'',$onchange);
16209: }
16210: } else {
16211: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16212: }
16213: }
16214:
16215: # last course activity filter and selection
16216: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16217:
16218: # course created filter and selection
16219: if (exists($filter->{'createdfilter'})) {
16220: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16221: }
16222:
1.1239 raeburn 16223: my $prefix = $crstype;
16224: if ($crstype eq 'Placement') {
16225: $prefix = 'Placement Test'
16226: }
1.1181 raeburn 16227: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16228: 'cac' => "$prefix Activity",
16229: 'ccr' => "$prefix Created",
16230: 'cde' => "$prefix Title",
16231: 'cdo' => "$prefix Domain",
1.1181 raeburn 16232: 'ins' => 'Institutional Code',
16233: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16234: 'cow' => "$prefix Owner/Co-owner",
16235: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16236: 'cog' => 'Type',
16237: );
16238:
16239: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16240: my $typeval = 'Course';
16241: if ($crstype eq 'Community') {
16242: $typeval = 'Community';
1.1239 raeburn 16243: } elsif ($crstype eq 'Placement') {
16244: $typeval = 'Placement';
1.1181 raeburn 16245: }
16246: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16247: } else {
16248: $typeselectform = '<select name="type" size="1"';
16249: if ($onchange) {
16250: $typeselectform .= ' onchange="'.$onchange.'"';
16251: }
16252: $typeselectform .= '>'."\n";
1.1237 raeburn 16253: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16254: my $shown;
16255: if ($posstype eq 'Placement') {
16256: $shown = &mt('Placement Test');
16257: } else {
16258: $shown = &mt($posstype);
16259: }
1.1181 raeburn 16260: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 16261: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 16262: }
16263: $typeselectform.="</select>";
16264: }
16265:
16266: my ($cloneableonlyform,$cloneabletitle);
16267: if (exists($filter->{'cloneableonly'})) {
16268: my $cloneableon = '';
16269: my $cloneableoff = ' checked="checked"';
16270: if ($filter->{'cloneableonly'}) {
16271: $cloneableon = $cloneableoff;
16272: $cloneableoff = '';
16273: }
16274: $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>';
16275: if ($formname eq 'ccrs') {
1.1187 bisitz 16276: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 16277: } else {
16278: $cloneabletitle = &mt('Cloneable by you');
16279: }
16280: }
16281: my $officialjs;
16282: if ($crstype eq 'Course') {
16283: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 16284: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16285: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16286: if ($codedom) {
1.1181 raeburn 16287: $officialjs = 1;
16288: ($instcodeform,$jscript,$$numtitlesref) =
16289: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16290: $officialjs,$codetitlesref);
16291: if ($jscript) {
1.1182 raeburn 16292: $jscript = '<script type="text/javascript">'."\n".
16293: '// <![CDATA['."\n".
16294: $jscript."\n".
16295: '// ]]>'."\n".
16296: '</script>'."\n";
1.1181 raeburn 16297: }
16298: }
16299: if ($instcodeform eq '') {
16300: $instcodeform =
16301: '<input type="text" name="instcodefilter" size="10" value="'.
16302: $list->{'instcodefilter'}.'" />';
16303: $instcodetitle = $lt{'ins'};
16304: } else {
16305: $instcodetitle = $lt{'inc'};
16306: }
16307: if ($fixeddom) {
16308: $instcodetitle .= '<br />('.$codedom.')';
16309: }
16310: }
16311: }
16312: my $output = qq|
16313: <form method="post" name="filterpicker" action="$action">
16314: <input type="hidden" name="form" value="$formname" />
16315: |;
16316: if ($formname eq 'modifycourse') {
16317: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16318: '<input type="hidden" name="prevphase" value="'.
16319: $prevphase.'" />'."\n";
1.1198 musolffc 16320: } elsif ($formname eq 'quotacheck') {
16321: $output .= qq|
16322: <input type="hidden" name="sortby" value="" />
16323: <input type="hidden" name="sortorder" value="" />
16324: |;
16325: } else {
1.1181 raeburn 16326: my $name_input;
16327: if ($cnameelement ne '') {
16328: $name_input = '<input type="hidden" name="cnameelement" value="'.
16329: $cnameelement.'" />';
16330: }
16331: $output .= qq|
1.1182 raeburn 16332: <input type="hidden" name="cnumelement" value="$cnumelement" />
16333: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 16334: $name_input
16335: $roleelement
16336: $multelement
16337: $typeelement
16338: |;
16339: if ($formname eq 'portform') {
16340: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16341: }
16342: }
16343: if ($fixeddom) {
16344: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16345: }
16346: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16347: if ($sincefilterform) {
16348: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16349: .$sincefilterform
16350: .&Apache::lonhtmlcommon::row_closure();
16351: }
16352: if ($createdfilterform) {
16353: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16354: .$createdfilterform
16355: .&Apache::lonhtmlcommon::row_closure();
16356: }
16357: if ($domainselectform) {
16358: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16359: .$domainselectform
16360: .&Apache::lonhtmlcommon::row_closure();
16361: }
16362: if ($typeselectform) {
16363: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16364: $output .= $typeselectform;
16365: } else {
16366: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16367: .$typeselectform
16368: .&Apache::lonhtmlcommon::row_closure();
16369: }
16370: }
16371: if ($instcodeform) {
16372: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16373: .$instcodeform
16374: .&Apache::lonhtmlcommon::row_closure();
16375: }
16376: if (exists($filter->{'ownerfilter'})) {
16377: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16378: '<table><tr><td>'.&mt('Username').'<br />'.
16379: '<input type="text" name="ownerfilter" size="20" value="'.
16380: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16381: $ownerdomselectform.'</td></tr></table>'.
16382: &Apache::lonhtmlcommon::row_closure();
16383: }
16384: if (exists($filter->{'personfilter'})) {
16385: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16386: '<table><tr><td>'.&mt('Username').'<br />'.
16387: '<input type="text" name="personfilter" size="20" value="'.
16388: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16389: $persondomselectform.'</td></tr></table>'.
16390: &Apache::lonhtmlcommon::row_closure();
16391: }
16392: if (exists($filter->{'coursefilter'})) {
16393: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16394: .'<input type="text" name="coursefilter" size="25" value="'
16395: .$list->{'coursefilter'}.'" />'
16396: .&Apache::lonhtmlcommon::row_closure();
16397: }
16398: if ($cloneableonlyform) {
16399: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16400: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16401: }
16402: if (exists($filter->{'descriptfilter'})) {
16403: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16404: .'<input type="text" name="descriptfilter" size="40" value="'
16405: .$list->{'descriptfilter'}.'" />'
16406: .&Apache::lonhtmlcommon::row_closure(1);
16407: }
16408: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16409: '<input type="hidden" name="updater" value="" />'."\n".
16410: '<input type="submit" name="gosearch" value="'.
16411: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16412: return $jscript.$clonewarning.$output;
16413: }
16414:
16415: =pod
16416:
16417: =item * &timebased_select_form()
16418:
1.1182 raeburn 16419: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 16420: filter e.g., Course Activity, Course Created, when searching for courses
16421: or communities
16422:
16423: Inputs:
16424:
16425: item - name of form element (sincefilter or createdfilter)
16426:
16427: filter - anonymous hash of criteria and their values
16428:
16429: Returns: HTML for a select box contained a blank, then six time selections,
16430: with value set in incoming form variables currently selected.
16431:
16432: Side Effects: None
16433:
16434: =cut
16435:
16436: sub timebased_select_form {
16437: my ($item,$filter) = @_;
16438: if (ref($filter) eq 'HASH') {
16439: $filter->{$item} =~ s/[^\d-]//g;
16440: if (!$filter->{$item}) { $filter->{$item}=-1; }
16441: return &select_form(
16442: $filter->{$item},
16443: $item,
16444: { '-1' => '',
16445: '86400' => &mt('today'),
16446: '604800' => &mt('last week'),
16447: '2592000' => &mt('last month'),
16448: '7776000' => &mt('last three months'),
16449: '15552000' => &mt('last six months'),
16450: '31104000' => &mt('last year'),
16451: 'select_form_order' =>
16452: ['-1','86400','604800','2592000','7776000',
16453: '15552000','31104000']});
16454: }
16455: }
16456:
16457: =pod
16458:
16459: =item * &js_changer()
16460:
16461: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 16462: when course type or domain is changed, and also to hide 'Searching ...' on
16463: page load completion for page showing search result.
1.1181 raeburn 16464:
16465: Inputs: None
16466:
1.1183 raeburn 16467: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 16468:
16469: Side Effects: None
16470:
16471: =cut
16472:
16473: sub js_changer {
16474: return <<ENDJS;
16475: <script type="text/javascript">
16476: // <![CDATA[
16477: function updateFilters(caller) {
16478: if (typeof(caller) != "undefined") {
16479: document.filterpicker.updater.value = caller.name;
16480: }
16481: document.filterpicker.submit();
16482: }
1.1183 raeburn 16483:
16484: function hideSearching() {
16485: if (document.getElementById('searching')) {
16486: document.getElementById('searching').style.display = 'none';
16487: }
16488: return;
16489: }
16490:
1.1181 raeburn 16491: // ]]>
16492: </script>
16493:
16494: ENDJS
16495: }
16496:
16497: =pod
16498:
1.1182 raeburn 16499: =item * &search_courses()
16500:
16501: Process selected filters form course search form and pass to lonnet::courseiddump
16502: to retrieve a hash for which keys are courseIDs which match the selected filters.
16503:
16504: Inputs:
16505:
16506: dom - domain being searched
16507:
16508: type - course type ('Course' or 'Community' or '.' if any).
16509:
16510: filter - anonymous hash of criteria and their values
16511:
16512: numtitles - for institutional codes - number of categories
16513:
16514: cloneruname - optional username of new course owner
16515:
16516: clonerudom - optional domain of new course owner
16517:
1.1221 raeburn 16518: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 16519: (used when DC is using course creation form)
16520:
16521: codetitles - reference to array of titles of components in institutional codes (official courses).
16522:
1.1221 raeburn 16523: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16524: (and so can clone automatically)
16525:
16526: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16527:
16528: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16529: courses to clone
1.1182 raeburn 16530:
16531: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16532:
16533:
16534: Side Effects: None
16535:
16536: =cut
16537:
16538:
16539: sub search_courses {
1.1221 raeburn 16540: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16541: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 16542: my (%courses,%showcourses,$cloner);
16543: if (($filter->{'ownerfilter'} ne '') ||
16544: ($filter->{'ownerdomfilter'} ne '')) {
16545: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16546: $filter->{'ownerdomfilter'};
16547: }
16548: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16549: if (!$filter->{$item}) {
16550: $filter->{$item}='.';
16551: }
16552: }
16553: my $now = time;
16554: my $timefilter =
16555: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16556: my ($createdbefore,$createdafter);
16557: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16558: $createdbefore = $now;
16559: $createdafter = $now-$filter->{'createdfilter'};
16560: }
16561: my ($instcodefilter,$regexpok);
16562: if ($numtitles) {
16563: if ($env{'form.official'} eq 'on') {
16564: $instcodefilter =
16565: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16566: $regexpok = 1;
16567: } elsif ($env{'form.official'} eq 'off') {
16568: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16569: unless ($instcodefilter eq '') {
16570: $regexpok = -1;
16571: }
16572: }
16573: } else {
16574: $instcodefilter = $filter->{'instcodefilter'};
16575: }
16576: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16577: if ($type eq '') { $type = '.'; }
16578:
16579: if (($clonerudom ne '') && ($cloneruname ne '')) {
16580: $cloner = $cloneruname.':'.$clonerudom;
16581: }
16582: %courses = &Apache::lonnet::courseiddump($dom,
16583: $filter->{'descriptfilter'},
16584: $timefilter,
16585: $instcodefilter,
16586: $filter->{'combownerfilter'},
16587: $filter->{'coursefilter'},
16588: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 16589: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 16590: $filter->{'cloneableonly'},
16591: $createdbefore,$createdafter,undef,
1.1221 raeburn 16592: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 16593: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16594: my $ccrole;
16595: if ($type eq 'Community') {
16596: $ccrole = 'co';
16597: } else {
16598: $ccrole = 'cc';
16599: }
16600: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16601: $filter->{'persondomfilter'},
16602: 'userroles',undef,
16603: [$ccrole,'in','ad','ep','ta','cr'],
16604: $dom);
16605: foreach my $role (keys(%rolehash)) {
16606: my ($cnum,$cdom,$courserole) = split(':',$role);
16607: my $cid = $cdom.'_'.$cnum;
16608: if (exists($courses{$cid})) {
16609: if (ref($courses{$cid}) eq 'HASH') {
16610: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16611: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
16612: push (@{$courses{$cid}{roles}},$courserole);
16613: }
16614: } else {
16615: $courses{$cid}{roles} = [$courserole];
16616: }
16617: $showcourses{$cid} = $courses{$cid};
16618: }
16619: }
16620: }
16621: %courses = %showcourses;
16622: }
16623: return %courses;
16624: }
16625:
16626: =pod
16627:
1.1181 raeburn 16628: =back
16629:
1.1207 raeburn 16630: =head1 Routines for version requirements for current course.
16631:
16632: =over 4
16633:
16634: =item * &check_release_required()
16635:
16636: Compares required LON-CAPA version with version on server, and
16637: if required version is newer looks for a server with the required version.
16638:
16639: Looks first at servers in user's owen domain; if none suitable, looks at
16640: servers in course's domain are permitted to host sessions for user's domain.
16641:
16642: Inputs:
16643:
16644: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16645:
16646: $courseid - Course ID of current course
16647:
16648: $rolecode - User's current role in course (for switchserver query string).
16649:
16650: $required - LON-CAPA version needed by course (format: Major.Minor).
16651:
16652:
16653: Returns:
16654:
16655: $switchserver - query string tp append to /adm/switchserver call (if
16656: current server's LON-CAPA version is too old.
16657:
16658: $warning - Message is displayed if no suitable server could be found.
16659:
16660: =cut
16661:
16662: sub check_release_required {
16663: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16664: my ($switchserver,$warning);
16665: if ($required ne '') {
16666: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16667: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16668: if ($reqdmajor ne '' && $reqdminor ne '') {
16669: my $otherserver;
16670: if (($major eq '' && $minor eq '') ||
16671: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16672: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16673: my $switchlcrev =
16674: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16675: $userdomserver);
16676: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16677: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16678: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16679: my $cdom = $env{'course.'.$courseid.'.domain'};
16680: if ($cdom ne $env{'user.domain'}) {
16681: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16682: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16683: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16684: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16685: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16686: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16687: my $canhost =
16688: &Apache::lonnet::can_host_session($env{'user.domain'},
16689: $coursedomserver,
16690: $remoterev,
16691: $udomdefaults{'remotesessions'},
16692: $defdomdefaults{'hostedsessions'});
16693:
16694: if ($canhost) {
16695: $otherserver = $coursedomserver;
16696: } else {
16697: $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.");
16698: }
16699: } else {
16700: $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).");
16701: }
16702: } else {
16703: $otherserver = $userdomserver;
16704: }
16705: }
16706: if ($otherserver ne '') {
16707: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16708: }
16709: }
16710: }
16711: return ($switchserver,$warning);
16712: }
16713:
16714: =pod
16715:
16716: =item * &check_release_result()
16717:
16718: Inputs:
16719:
16720: $switchwarning - Warning message if no suitable server found to host session.
16721:
16722: $switchserver - query string to append to /adm/switchserver containing lonHostID
16723: and current role.
16724:
16725: Returns: HTML to display with information about requirement to switch server.
16726: Either displaying warning with link to Roles/Courses screen or
16727: display link to switchserver.
16728:
1.1181 raeburn 16729: =cut
16730:
1.1207 raeburn 16731: sub check_release_result {
16732: my ($switchwarning,$switchserver) = @_;
16733: my $output = &start_page('Selected course unavailable on this server').
16734: '<p class="LC_warning">';
16735: if ($switchwarning) {
16736: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16737: if (&show_course()) {
16738: $output .= &mt('Display courses');
16739: } else {
16740: $output .= &mt('Display roles');
16741: }
16742: $output .= '</a>';
16743: } elsif ($switchserver) {
16744: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16745: '<br />'.
16746: '<a href="/adm/switchserver?'.$switchserver.'">'.
16747: &mt('Switch Server').
16748: '</a>';
16749: }
16750: $output .= '</p>'.&end_page();
16751: return $output;
16752: }
16753:
16754: =pod
16755:
16756: =item * &needs_coursereinit()
16757:
16758: Determine if course contents stored for user's session needs to be
16759: refreshed, because content has changed since "Big Hash" last tied.
16760:
16761: Check for change is made if time last checked is more than 10 minutes ago
16762: (by default).
16763:
16764: Inputs:
16765:
16766: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16767:
16768: $interval (optional) - Time which may elapse (in s) between last check for content
16769: change in current course. (default: 600 s).
16770:
16771: Returns: an array; first element is:
16772:
16773: =over 4
16774:
16775: 'switch' - if content updates mean user's session
16776: needs to be switched to a server running a newer LON-CAPA version
16777:
16778: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16779: on current server hosting user's session
16780:
16781: '' - if no action required.
16782:
16783: =back
16784:
16785: If first item element is 'switch':
16786:
16787: second item is $switchwarning - Warning message if no suitable server found to host session.
16788:
16789: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16790: and current role.
16791:
16792: otherwise: no other elements returned.
16793:
16794: =back
16795:
16796: =cut
16797:
16798: sub needs_coursereinit {
16799: my ($loncaparev,$interval) = @_;
16800: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16801: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16802: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16803: my $now = time;
16804: if ($interval eq '') {
16805: $interval = 600;
16806: }
16807: if (($now-$env{'request.course.timechecked'})>$interval) {
16808: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16809: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16810: if ($lastchange > $env{'request.course.tied'}) {
16811: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16812: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16813: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16814: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16815: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16816: $curr_reqd_hash{'internal.releaserequired'}});
16817: my ($switchserver,$switchwarning) =
16818: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16819: $curr_reqd_hash{'internal.releaserequired'});
16820: if ($switchwarning ne '' || $switchserver ne '') {
16821: return ('switch',$switchwarning,$switchserver);
16822: }
16823: }
16824: }
16825: return ('update');
16826: }
16827: }
16828: return ();
16829: }
1.1181 raeburn 16830:
1.1083 raeburn 16831: sub update_content_constraints {
16832: my ($cdom,$cnum,$chome,$cid) = @_;
16833: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16834: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16835: my %checkresponsetypes;
16836: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 16837: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 16838: if ($item eq 'resourcetag') {
16839: if ($name eq 'responsetype') {
16840: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16841: }
16842: }
16843: }
16844: my $navmap = Apache::lonnavmaps::navmap->new();
16845: if (defined($navmap)) {
16846: my %allresponses;
16847: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16848: my %responses = $res->responseTypes();
16849: foreach my $key (keys(%responses)) {
16850: next unless(exists($checkresponsetypes{$key}));
16851: $allresponses{$key} += $responses{$key};
16852: }
16853: }
16854: foreach my $key (keys(%allresponses)) {
16855: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16856: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16857: ($reqdmajor,$reqdminor) = ($major,$minor);
16858: }
16859: }
16860: undef($navmap);
16861: }
16862: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16863: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16864: }
16865: return;
16866: }
16867:
1.1110 raeburn 16868: sub allmaps_incourse {
16869: my ($cdom,$cnum,$chome,$cid) = @_;
16870: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16871: $cid = $env{'request.course.id'};
16872: $cdom = $env{'course.'.$cid.'.domain'};
16873: $cnum = $env{'course.'.$cid.'.num'};
16874: $chome = $env{'course.'.$cid.'.home'};
16875: }
16876: my %allmaps = ();
16877: my $lastchange =
16878: &Apache::lonnet::get_coursechange($cdom,$cnum);
16879: if ($lastchange > $env{'request.course.tied'}) {
16880: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16881: unless ($ferr) {
16882: &update_content_constraints($cdom,$cnum,$chome,$cid);
16883: }
16884: }
16885: my $navmap = Apache::lonnavmaps::navmap->new();
16886: if (defined($navmap)) {
16887: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16888: $allmaps{$res->src()} = 1;
16889: }
16890: }
16891: return \%allmaps;
16892: }
16893:
1.1083 raeburn 16894: sub parse_supplemental_title {
16895: my ($title) = @_;
16896:
16897: my ($foldertitle,$renametitle);
16898: if ($title =~ /&&&/) {
16899: $title = &HTML::Entites::decode($title);
16900: }
16901: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16902: $renametitle=$4;
16903: my ($time,$uname,$udom) = ($1,$2,$3);
16904: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16905: my $name = &plainname($uname,$udom);
16906: $name = &HTML::Entities::encode($name,'"<>&\'');
16907: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16908: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16909: $name.': <br />'.$foldertitle;
16910: }
16911: if (wantarray) {
16912: return ($title,$foldertitle,$renametitle);
16913: }
16914: return $title;
16915: }
16916:
1.1143 raeburn 16917: sub recurse_supplemental {
16918: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16919: if ($suppmap) {
16920: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16921: if ($fatal) {
16922: $errors ++;
16923: } else {
16924: if ($#LONCAPA::map::resources > 0) {
16925: foreach my $res (@LONCAPA::map::resources) {
16926: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16927: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 16928: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16929: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 16930: } else {
16931: $numfiles ++;
16932: }
16933: }
16934: }
16935: }
16936: }
16937: }
16938: return ($numfiles,$errors);
16939: }
16940:
1.1101 raeburn 16941: sub symb_to_docspath {
16942: my ($symb) = @_;
16943: return unless ($symb);
16944: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16945: if ($resurl=~/\.(sequence|page)$/) {
16946: $mapurl=$resurl;
16947: } elsif ($resurl eq 'adm/navmaps') {
16948: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16949: }
16950: my $mapresobj;
16951: my $navmap = Apache::lonnavmaps::navmap->new();
16952: if (ref($navmap)) {
16953: $mapresobj = $navmap->getResourceByUrl($mapurl);
16954: }
16955: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16956: my $type=$2;
16957: my $path;
16958: if (ref($mapresobj)) {
16959: my $pcslist = $mapresobj->map_hierarchy();
16960: if ($pcslist ne '') {
16961: foreach my $pc (split(/,/,$pcslist)) {
16962: next if ($pc <= 1);
16963: my $res = $navmap->getByMapPc($pc);
16964: if (ref($res)) {
16965: my $thisurl = $res->src();
16966: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16967: my $thistitle = $res->title();
16968: $path .= '&'.
16969: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 16970: &escape($thistitle).
1.1101 raeburn 16971: ':'.$res->randompick().
16972: ':'.$res->randomout().
16973: ':'.$res->encrypted().
16974: ':'.$res->randomorder().
16975: ':'.$res->is_page();
16976: }
16977: }
16978: }
16979: $path =~ s/^\&//;
16980: my $maptitle = $mapresobj->title();
16981: if ($mapurl eq 'default') {
1.1129 raeburn 16982: $maptitle = 'Main Content';
1.1101 raeburn 16983: }
16984: $path .= (($path ne '')? '&' : '').
16985: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 16986: &escape($maptitle).
1.1101 raeburn 16987: ':'.$mapresobj->randompick().
16988: ':'.$mapresobj->randomout().
16989: ':'.$mapresobj->encrypted().
16990: ':'.$mapresobj->randomorder().
16991: ':'.$mapresobj->is_page();
16992: } else {
16993: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16994: my $ispage = (($type eq 'page')? 1 : '');
16995: if ($mapurl eq 'default') {
1.1129 raeburn 16996: $maptitle = 'Main Content';
1.1101 raeburn 16997: }
16998: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 16999: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17000: }
17001: unless ($mapurl eq 'default') {
17002: $path = 'default&'.
1.1146 raeburn 17003: &escape('Main Content').
1.1101 raeburn 17004: ':::::&'.$path;
17005: }
17006: return $path;
17007: }
17008:
1.1094 raeburn 17009: sub captcha_display {
17010: my ($context,$lonhost) = @_;
17011: my ($output,$error);
1.1234 raeburn 17012: my ($captcha,$pubkey,$privkey,$version) =
17013: &get_captcha_config($context,$lonhost);
1.1095 raeburn 17014: if ($captcha eq 'original') {
1.1094 raeburn 17015: $output = &create_captcha();
17016: unless ($output) {
1.1172 raeburn 17017: $error = 'captcha';
1.1094 raeburn 17018: }
17019: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17020: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17021: unless ($output) {
1.1172 raeburn 17022: $error = 'recaptcha';
1.1094 raeburn 17023: }
17024: }
1.1234 raeburn 17025: return ($output,$error,$captcha,$version);
1.1094 raeburn 17026: }
17027:
17028: sub captcha_response {
17029: my ($context,$lonhost) = @_;
17030: my ($captcha_chk,$captcha_error);
1.1234 raeburn 17031: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 17032: if ($captcha eq 'original') {
1.1094 raeburn 17033: ($captcha_chk,$captcha_error) = &check_captcha();
17034: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17035: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17036: } else {
17037: $captcha_chk = 1;
17038: }
17039: return ($captcha_chk,$captcha_error);
17040: }
17041:
17042: sub get_captcha_config {
17043: my ($context,$lonhost) = @_;
1.1234 raeburn 17044: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17045: my $hostname = &Apache::lonnet::hostname($lonhost);
17046: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17047: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17048: if ($context eq 'usercreation') {
17049: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17050: if (ref($domconfig{$context}) eq 'HASH') {
17051: $hashtocheck = $domconfig{$context}{'cancreate'};
17052: if (ref($hashtocheck) eq 'HASH') {
17053: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17054: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17055: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17056: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17057: }
17058: if ($privkey && $pubkey) {
17059: $captcha = 'recaptcha';
1.1234 raeburn 17060: $version = $hashtocheck->{'recaptchaversion'};
17061: if ($version ne '2') {
17062: $version = 1;
17063: }
1.1095 raeburn 17064: } else {
17065: $captcha = 'original';
17066: }
17067: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17068: $captcha = 'original';
17069: }
1.1094 raeburn 17070: }
1.1095 raeburn 17071: } else {
17072: $captcha = 'captcha';
17073: }
17074: } elsif ($context eq 'login') {
17075: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17076: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17077: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17078: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17079: if ($privkey && $pubkey) {
17080: $captcha = 'recaptcha';
1.1234 raeburn 17081: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17082: if ($version ne '2') {
17083: $version = 1;
17084: }
1.1095 raeburn 17085: } else {
17086: $captcha = 'original';
1.1094 raeburn 17087: }
1.1095 raeburn 17088: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17089: $captcha = 'original';
1.1094 raeburn 17090: }
17091: }
1.1234 raeburn 17092: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17093: }
17094:
17095: sub create_captcha {
17096: my %captcha_params = &captcha_settings();
17097: my ($output,$maxtries,$tries) = ('',10,0);
17098: while ($tries < $maxtries) {
17099: $tries ++;
17100: my $captcha = Authen::Captcha->new (
17101: output_folder => $captcha_params{'output_dir'},
17102: data_folder => $captcha_params{'db_dir'},
17103: );
17104: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17105:
17106: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17107: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17108: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17109: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17110: '<br />'.
17111: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17112: last;
17113: }
17114: }
17115: return $output;
17116: }
17117:
17118: sub captcha_settings {
17119: my %captcha_params = (
17120: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17121: www_output_dir => "/captchaspool",
17122: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17123: numchars => '5',
17124: );
17125: return %captcha_params;
17126: }
17127:
17128: sub check_captcha {
17129: my ($captcha_chk,$captcha_error);
17130: my $code = $env{'form.code'};
17131: my $md5sum = $env{'form.crypt'};
17132: my %captcha_params = &captcha_settings();
17133: my $captcha = Authen::Captcha->new(
17134: output_folder => $captcha_params{'output_dir'},
17135: data_folder => $captcha_params{'db_dir'},
17136: );
1.1109 raeburn 17137: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17138: my %captcha_hash = (
17139: 0 => 'Code not checked (file error)',
17140: -1 => 'Failed: code expired',
17141: -2 => 'Failed: invalid code (not in database)',
17142: -3 => 'Failed: invalid code (code does not match crypt)',
17143: );
17144: if ($captcha_chk != 1) {
17145: $captcha_error = $captcha_hash{$captcha_chk}
17146: }
17147: return ($captcha_chk,$captcha_error);
17148: }
17149:
17150: sub create_recaptcha {
1.1234 raeburn 17151: my ($pubkey,$version) = @_;
17152: if ($version >= 2) {
17153: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17154: } else {
17155: my $use_ssl;
17156: if ($ENV{'SERVER_PORT'} == 443) {
17157: $use_ssl = 1;
17158: }
17159: my $captcha = Captcha::reCAPTCHA->new;
17160: return $captcha->get_options_setter({theme => 'white'})."\n".
17161: $captcha->get_html($pubkey,undef,$use_ssl).
17162: &mt('If the text is hard to read, [_1] will replace them.',
17163: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17164: '<br /><br />';
17165: }
1.1094 raeburn 17166: }
17167:
17168: sub check_recaptcha {
1.1234 raeburn 17169: my ($privkey,$version) = @_;
1.1094 raeburn 17170: my $captcha_chk;
1.1234 raeburn 17171: if ($version >= 2) {
17172: my $ua = LWP::UserAgent->new;
17173: $ua->timeout(10);
17174: my %info = (
17175: secret => $privkey,
17176: response => $env{'form.g-recaptcha-response'},
17177: remoteip => $ENV{'REMOTE_ADDR'},
17178: );
17179: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17180: if ($response->is_success) {
17181: my $data = JSON::DWIW->from_json($response->decoded_content);
17182: if (ref($data) eq 'HASH') {
17183: if ($data->{'success'}) {
17184: $captcha_chk = 1;
17185: }
17186: }
17187: }
17188: } else {
17189: my $captcha = Captcha::reCAPTCHA->new;
17190: my $captcha_result =
17191: $captcha->check_answer(
17192: $privkey,
17193: $ENV{'REMOTE_ADDR'},
17194: $env{'form.recaptcha_challenge_field'},
17195: $env{'form.recaptcha_response_field'},
17196: );
17197: if ($captcha_result->{is_valid}) {
17198: $captcha_chk = 1;
17199: }
1.1094 raeburn 17200: }
17201: return $captcha_chk;
17202: }
17203:
1.1174 raeburn 17204: sub emailusername_info {
1.1244 raeburn 17205: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 17206: my %titles = &Apache::lonlocal::texthash (
17207: lastname => 'Last Name',
17208: firstname => 'First Name',
17209: institution => 'School/college/university',
17210: location => "School's city, state/province, country",
17211: web => "School's web address",
17212: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 17213: id => 'Student/Employee ID',
1.1174 raeburn 17214: );
17215: return (\@fields,\%titles);
17216: }
17217:
1.1161 raeburn 17218: sub cleanup_html {
17219: my ($incoming) = @_;
17220: my $outgoing;
17221: if ($incoming ne '') {
17222: $outgoing = $incoming;
17223: $outgoing =~ s/;/;/g;
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: }
17237: return $outgoing;
17238: }
17239:
1.1190 musolffc 17240: # Checks for critical messages and returns a redirect url if one exists.
17241: # $interval indicates how often to check for messages.
17242: sub critical_redirect {
17243: my ($interval) = @_;
17244: if ((time-$env{'user.criticalcheck.time'})>$interval) {
17245: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17246: $env{'user.name'});
17247: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 17248: my $redirecturl;
1.1190 musolffc 17249: if ($what[0]) {
17250: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17251: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 17252: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17253: return (1, $url);
1.1190 musolffc 17254: }
1.1191 raeburn 17255: }
17256: }
17257: return ();
1.1190 musolffc 17258: }
17259:
1.1174 raeburn 17260: # Use:
17261: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17262: #
17263: ##################################################
17264: # password associated functions #
17265: ##################################################
17266: sub des_keys {
17267: # Make a new key for DES encryption.
17268: # Each key has two parts which are returned separately.
17269: # Please note: Each key must be passed through the &hex function
17270: # before it is output to the web browser. The hex versions cannot
17271: # be used to decrypt.
17272: my @hexstr=('0','1','2','3','4','5','6','7',
17273: '8','9','a','b','c','d','e','f');
17274: my $lkey='';
17275: for (0..7) {
17276: $lkey.=$hexstr[rand(15)];
17277: }
17278: my $ukey='';
17279: for (0..7) {
17280: $ukey.=$hexstr[rand(15)];
17281: }
17282: return ($lkey,$ukey);
17283: }
17284:
17285: sub des_decrypt {
17286: my ($key,$cyphertext) = @_;
17287: my $keybin=pack("H16",$key);
17288: my $cypher;
17289: if ($Crypt::DES::VERSION>=2.03) {
17290: $cypher=new Crypt::DES $keybin;
17291: } else {
17292: $cypher=new DES $keybin;
17293: }
1.1233 raeburn 17294: my $plaintext='';
17295: my $cypherlength = length($cyphertext);
17296: my $numchunks = int($cypherlength/32);
17297: for (my $j=0; $j<$numchunks; $j++) {
17298: my $start = $j*32;
17299: my $cypherblock = substr($cyphertext,$start,32);
17300: my $chunk =
17301: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17302: $chunk .=
17303: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17304: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17305: $plaintext .= $chunk;
17306: }
1.1174 raeburn 17307: return $plaintext;
17308: }
17309:
1.112 bowersj2 17310: 1;
17311: __END__;
1.41 ng 17312:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>