Annotation of loncom/interface/loncommon.pm, revision 1.1248
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1248 ! raeburn 4: # $Id: loncommon.pm,v 1.1247 2016/06/20 15:35:42 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.659 raeburn 946: my ($name,$selected,$onchange,$includeempty)=@_;
947: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
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 {
968: my ($name,$selected,$onchange,$includeempty)=@_;
969: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
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 {
1021: my ($name,$selected,$includeempty) = @_;
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.970 raeburn 1033: return &select_form($selected,$name,\%langchoices);
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.970 raeburn 2551: =item * &select_form($defdom,$name,$hashref,$onchange)
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
2556: a javascript onchange item, e.g., onchange="this.form.submit();"
2557:
1.88 www 2558: See lonrights.pm for an example invocation and use.
2559:
2560: =cut
2561:
2562: #-------------------------------------------
2563: sub select_form {
1.1228 raeburn 2564: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2565: return unless (ref($hashref) eq 'HASH');
2566: if ($onchange) {
2567: $onchange = ' onchange="'.$onchange.'"';
2568: }
1.1228 raeburn 2569: my $disabled;
2570: if ($readonly) {
2571: $disabled = ' disabled="disabled"';
2572: }
2573: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2574: my @keys;
1.970 raeburn 2575: if (exists($hashref->{'select_form_order'})) {
2576: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2577: } else {
1.970 raeburn 2578: @keys=sort(keys(%{$hashref}));
1.128 albertel 2579: }
1.356 albertel 2580: foreach my $key (@keys) {
2581: $selectform.=
2582: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2583: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2584: ">".$hashref->{$key}."</option>\n";
1.88 www 2585: }
2586: $selectform.="</select>";
2587: return $selectform;
2588: }
2589:
1.475 www 2590: # For display filters
2591:
2592: sub display_filter {
1.1074 raeburn 2593: my ($context) = @_;
1.475 www 2594: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2595: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2596: my $phraseinput = 'hidden';
2597: my $includeinput = 'hidden';
2598: my ($checked,$includetypestext);
2599: if ($env{'form.displayfilter'} eq 'containing') {
2600: $phraseinput = 'text';
2601: if ($context eq 'parmslog') {
2602: $includeinput = 'checkbox';
2603: if ($env{'form.includetypes'}) {
2604: $checked = ' checked="checked"';
2605: }
2606: $includetypestext = &mt('Include parameter types');
2607: }
2608: } else {
2609: $includetypestext = ' ';
2610: }
2611: my ($additional,$secondid,$thirdid);
2612: if ($context eq 'parmslog') {
2613: $additional =
2614: '<label><input type="'.$includeinput.'" name="includetypes"'.
2615: $checked.' name="includetypes" value="1" id="includetypes" />'.
2616: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2617: '</label>';
2618: $secondid = 'includetypes';
2619: $thirdid = 'includetypestext';
2620: }
2621: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2622: '$secondid','$thirdid')";
2623: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2624: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2625: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2626: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2627: &mt('Filter: [_1]',
1.477 www 2628: &select_form($env{'form.displayfilter'},
2629: 'displayfilter',
1.970 raeburn 2630: {'currentfolder' => 'Current folder/page',
1.477 www 2631: 'containing' => 'Containing phrase',
1.1074 raeburn 2632: 'none' => 'None'},$onchange)).' '.
2633: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2634: &HTML::Entities::encode($env{'form.containingphrase'}).
2635: '" />'.$additional;
2636: }
2637:
2638: sub display_filter_js {
2639: my $includetext = &mt('Include parameter types');
2640: return <<"ENDJS";
2641:
2642: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2643: var firstType = 'hidden';
2644: if (setter.options[setter.selectedIndex].value == 'containing') {
2645: firstType = 'text';
2646: }
2647: firstObject = document.getElementById(firstid);
2648: if (typeof(firstObject) == 'object') {
2649: if (firstObject.type != firstType) {
2650: changeInputType(firstObject,firstType);
2651: }
2652: }
2653: if (context == 'parmslog') {
2654: var secondType = 'hidden';
2655: if (firstType == 'text') {
2656: secondType = 'checkbox';
2657: }
2658: secondObject = document.getElementById(secondid);
2659: if (typeof(secondObject) == 'object') {
2660: if (secondObject.type != secondType) {
2661: changeInputType(secondObject,secondType);
2662: }
2663: }
2664: var textItem = document.getElementById(thirdid);
2665: var currtext = textItem.innerHTML;
2666: var newtext;
2667: if (firstType == 'text') {
2668: newtext = '$includetext';
2669: } else {
2670: newtext = ' ';
2671: }
2672: if (currtext != newtext) {
2673: textItem.innerHTML = newtext;
2674: }
2675: }
2676: return;
2677: }
2678:
2679: function changeInputType(oldObject,newType) {
2680: var newObject = document.createElement('input');
2681: newObject.type = newType;
2682: if (oldObject.size) {
2683: newObject.size = oldObject.size;
2684: }
2685: if (oldObject.value) {
2686: newObject.value = oldObject.value;
2687: }
2688: if (oldObject.name) {
2689: newObject.name = oldObject.name;
2690: }
2691: if (oldObject.id) {
2692: newObject.id = oldObject.id;
2693: }
2694: oldObject.parentNode.replaceChild(newObject,oldObject);
2695: return;
2696: }
2697:
2698: ENDJS
1.475 www 2699: }
2700:
1.167 www 2701: sub gradeleveldescription {
2702: my $gradelevel=shift;
2703: my %gradelevels=(0 => 'Not specified',
2704: 1 => 'Grade 1',
2705: 2 => 'Grade 2',
2706: 3 => 'Grade 3',
2707: 4 => 'Grade 4',
2708: 5 => 'Grade 5',
2709: 6 => 'Grade 6',
2710: 7 => 'Grade 7',
2711: 8 => 'Grade 8',
2712: 9 => 'Grade 9',
2713: 10 => 'Grade 10',
2714: 11 => 'Grade 11',
2715: 12 => 'Grade 12',
2716: 13 => 'Grade 13',
2717: 14 => '100 Level',
2718: 15 => '200 Level',
2719: 16 => '300 Level',
2720: 17 => '400 Level',
2721: 18 => 'Graduate Level');
2722: return &mt($gradelevels{$gradelevel});
2723: }
2724:
1.163 www 2725: sub select_level_form {
2726: my ($deflevel,$name)=@_;
2727: unless ($deflevel) { $deflevel=0; }
1.167 www 2728: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2729: for (my $i=0; $i<=18; $i++) {
2730: $selectform.="<option value=\"$i\" ".
1.253 albertel 2731: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2732: ">".&gradeleveldescription($i)."</option>\n";
2733: }
2734: $selectform.="</select>";
2735: return $selectform;
1.163 www 2736: }
1.167 www 2737:
1.35 matthew 2738: #-------------------------------------------
2739:
1.45 matthew 2740: =pod
2741:
1.1121 raeburn 2742: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2743:
2744: Returns a string containing a <select name='$name' size='1'> form to
2745: allow a user to select the domain to preform an operation in.
2746: See loncreateuser.pm for an example invocation and use.
2747:
1.90 www 2748: If the $includeempty flag is set, it also includes an empty choice ("no domain
2749: selected");
2750:
1.743 raeburn 2751: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2752:
1.910 raeburn 2753: 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.
2754:
1.1121 raeburn 2755: The optional $incdoms is a reference to an array of domains which will be the only available options.
2756:
2757: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2758:
1.35 matthew 2759: =cut
2760:
2761: #-------------------------------------------
1.34 matthew 2762: sub select_dom_form {
1.1121 raeburn 2763: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2764: if ($onchange) {
1.874 raeburn 2765: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2766: }
1.1121 raeburn 2767: my (@domains,%exclude);
1.910 raeburn 2768: if (ref($incdoms) eq 'ARRAY') {
2769: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2770: } else {
2771: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2772: }
1.90 www 2773: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2774: if (ref($excdoms) eq 'ARRAY') {
2775: map { $exclude{$_} = 1; } @{$excdoms};
2776: }
1.743 raeburn 2777: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2778: foreach my $dom (@domains) {
1.1121 raeburn 2779: next if ($exclude{$dom});
1.356 albertel 2780: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2781: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2782: if ($showdomdesc) {
2783: if ($dom ne '') {
2784: my $domdesc = &Apache::lonnet::domain($dom,'description');
2785: if ($domdesc ne '') {
2786: $selectdomain .= ' ('.$domdesc.')';
2787: }
2788: }
2789: }
2790: $selectdomain .= "</option>\n";
1.34 matthew 2791: }
2792: $selectdomain.="</select>";
2793: return $selectdomain;
2794: }
2795:
1.35 matthew 2796: #-------------------------------------------
2797:
1.45 matthew 2798: =pod
2799:
1.648 raeburn 2800: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2801:
1.586 raeburn 2802: input: 4 arguments (two required, two optional) -
2803: $domain - domain of new user
2804: $name - name of form element
2805: $default - Value of 'default' causes a default item to be first
2806: option, and selected by default.
2807: $hide - Value of 'hide' causes hiding of the name of the server,
2808: if 1 server found, or default, if 0 found.
1.594 raeburn 2809: output: returns 2 items:
1.586 raeburn 2810: (a) form element which contains either:
2811: (i) <select name="$name">
2812: <option value="$hostid1">$hostid $servers{$hostid}</option>
2813: <option value="$hostid2">$hostid $servers{$hostid}</option>
2814: </select>
2815: form item if there are multiple library servers in $domain, or
2816: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2817: if there is only one library server in $domain.
2818:
2819: (b) number of library servers found.
2820:
2821: See loncreateuser.pm for example of use.
1.35 matthew 2822:
2823: =cut
2824:
2825: #-------------------------------------------
1.586 raeburn 2826: sub home_server_form_item {
2827: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2828: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2829: my $result;
2830: my $numlib = keys(%servers);
2831: if ($numlib > 1) {
2832: $result .= '<select name="'.$name.'" />'."\n";
2833: if ($default) {
1.804 bisitz 2834: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2835: '</option>'."\n";
2836: }
2837: foreach my $hostid (sort(keys(%servers))) {
2838: $result.= '<option value="'.$hostid.'">'.
2839: $hostid.' '.$servers{$hostid}."</option>\n";
2840: }
2841: $result .= '</select>'."\n";
2842: } elsif ($numlib == 1) {
2843: my $hostid;
2844: foreach my $item (keys(%servers)) {
2845: $hostid = $item;
2846: }
2847: $result .= '<input type="hidden" name="'.$name.'" value="'.
2848: $hostid.'" />';
2849: if (!$hide) {
2850: $result .= $hostid.' '.$servers{$hostid};
2851: }
2852: $result .= "\n";
2853: } elsif ($default) {
2854: $result .= '<input type="hidden" name="'.$name.
2855: '" value="default" />';
2856: if (!$hide) {
2857: $result .= &mt('default');
2858: }
2859: $result .= "\n";
1.33 matthew 2860: }
1.586 raeburn 2861: return ($result,$numlib);
1.33 matthew 2862: }
1.112 bowersj2 2863:
2864: =pod
2865:
1.534 albertel 2866: =back
2867:
1.112 bowersj2 2868: =cut
1.87 matthew 2869:
2870: ###############################################################
1.112 bowersj2 2871: ## Decoding User Agent ##
1.87 matthew 2872: ###############################################################
2873:
2874: =pod
2875:
1.112 bowersj2 2876: =head1 Decoding the User Agent
2877:
2878: =over 4
2879:
2880: =item * &decode_user_agent()
1.87 matthew 2881:
2882: Inputs: $r
2883:
2884: Outputs:
2885:
2886: =over 4
2887:
1.112 bowersj2 2888: =item * $httpbrowser
1.87 matthew 2889:
1.112 bowersj2 2890: =item * $clientbrowser
1.87 matthew 2891:
1.112 bowersj2 2892: =item * $clientversion
1.87 matthew 2893:
1.112 bowersj2 2894: =item * $clientmathml
1.87 matthew 2895:
1.112 bowersj2 2896: =item * $clientunicode
1.87 matthew 2897:
1.112 bowersj2 2898: =item * $clientos
1.87 matthew 2899:
1.1137 raeburn 2900: =item * $clientmobile
2901:
1.1141 raeburn 2902: =item * $clientinfo
2903:
1.1194 raeburn 2904: =item * $clientosversion
2905:
1.87 matthew 2906: =back
2907:
1.157 matthew 2908: =back
2909:
1.87 matthew 2910: =cut
2911:
2912: ###############################################################
2913: ###############################################################
2914: sub decode_user_agent {
1.247 albertel 2915: my ($r)=@_;
1.87 matthew 2916: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2917: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2918: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2919: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2920: my $clientbrowser='unknown';
2921: my $clientversion='0';
2922: my $clientmathml='';
2923: my $clientunicode='0';
1.1137 raeburn 2924: my $clientmobile=0;
1.1194 raeburn 2925: my $clientosversion='';
1.87 matthew 2926: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2927: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2928: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2929: $clientbrowser=$bname;
2930: $httpbrowser=~/$vreg/i;
2931: $clientversion=$1;
2932: $clientmathml=($clientversion>=$minv);
2933: $clientunicode=($clientversion>=$univ);
2934: }
2935: }
2936: my $clientos='unknown';
1.1141 raeburn 2937: my $clientinfo;
1.87 matthew 2938: if (($httpbrowser=~/linux/i) ||
2939: ($httpbrowser=~/unix/i) ||
2940: ($httpbrowser=~/ux/i) ||
2941: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2942: if (($httpbrowser=~/vax/i) ||
2943: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2944: if ($httpbrowser=~/next/i) { $clientos='next'; }
2945: if (($httpbrowser=~/mac/i) ||
2946: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2947: if ($httpbrowser=~/win/i) {
2948: $clientos='win';
2949: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2950: $clientosversion = $1;
2951: }
2952: }
1.87 matthew 2953: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2954: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2955: $clientmobile=lc($1);
2956: }
1.1141 raeburn 2957: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2958: $clientinfo = 'firefox-'.$1;
2959: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2960: $clientinfo = 'chromeframe-'.$1;
2961: }
1.87 matthew 2962: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 2963: $clientunicode,$clientos,$clientmobile,$clientinfo,
2964: $clientosversion);
1.87 matthew 2965: }
2966:
1.32 matthew 2967: ###############################################################
2968: ## Authentication changing form generation subroutines ##
2969: ###############################################################
2970: ##
2971: ## All of the authform_xxxxxxx subroutines take their inputs in a
2972: ## hash, and have reasonable default values.
2973: ##
2974: ## formname = the name given in the <form> tag.
1.35 matthew 2975: #-------------------------------------------
2976:
1.45 matthew 2977: =pod
2978:
1.112 bowersj2 2979: =head1 Authentication Routines
2980:
2981: =over 4
2982:
1.648 raeburn 2983: =item * &authform_xxxxxx()
1.35 matthew 2984:
2985: The authform_xxxxxx subroutines provide javascript and html forms which
2986: handle some of the conveniences required for authentication forms.
2987: This is not an optimal method, but it works.
2988:
2989: =over 4
2990:
1.112 bowersj2 2991: =item * authform_header
1.35 matthew 2992:
1.112 bowersj2 2993: =item * authform_authorwarning
1.35 matthew 2994:
1.112 bowersj2 2995: =item * authform_nochange
1.35 matthew 2996:
1.112 bowersj2 2997: =item * authform_kerberos
1.35 matthew 2998:
1.112 bowersj2 2999: =item * authform_internal
1.35 matthew 3000:
1.112 bowersj2 3001: =item * authform_filesystem
1.35 matthew 3002:
3003: =back
3004:
1.648 raeburn 3005: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3006:
1.35 matthew 3007: =cut
3008:
3009: #-------------------------------------------
1.32 matthew 3010: sub authform_header{
3011: my %in = (
3012: formname => 'cu',
1.80 albertel 3013: kerb_def_dom => '',
1.32 matthew 3014: @_,
3015: );
3016: $in{'formname'} = 'document.' . $in{'formname'};
3017: my $result='';
1.80 albertel 3018:
3019: #---------------------------------------------- Code for upper case translation
3020: my $Javascript_toUpperCase;
3021: unless ($in{kerb_def_dom}) {
3022: $Javascript_toUpperCase =<<"END";
3023: switch (choice) {
3024: case 'krb': currentform.elements[choicearg].value =
3025: currentform.elements[choicearg].value.toUpperCase();
3026: break;
3027: default:
3028: }
3029: END
3030: } else {
3031: $Javascript_toUpperCase = "";
3032: }
3033:
1.165 raeburn 3034: my $radioval = "'nochange'";
1.591 raeburn 3035: if (defined($in{'curr_authtype'})) {
3036: if ($in{'curr_authtype'} ne '') {
3037: $radioval = "'".$in{'curr_authtype'}."arg'";
3038: }
1.174 matthew 3039: }
1.165 raeburn 3040: my $argfield = 'null';
1.591 raeburn 3041: if (defined($in{'mode'})) {
1.165 raeburn 3042: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3043: if (defined($in{'curr_autharg'})) {
3044: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3045: $argfield = "'$in{'curr_autharg'}'";
3046: }
3047: }
3048: }
3049: }
3050:
1.32 matthew 3051: $result.=<<"END";
3052: var current = new Object();
1.165 raeburn 3053: current.radiovalue = $radioval;
3054: current.argfield = $argfield;
1.32 matthew 3055:
3056: function changed_radio(choice,currentform) {
3057: var choicearg = choice + 'arg';
3058: // If a radio button in changed, we need to change the argfield
3059: if (current.radiovalue != choice) {
3060: current.radiovalue = choice;
3061: if (current.argfield != null) {
3062: currentform.elements[current.argfield].value = '';
3063: }
3064: if (choice == 'nochange') {
3065: current.argfield = null;
3066: } else {
3067: current.argfield = choicearg;
3068: switch(choice) {
3069: case 'krb':
3070: currentform.elements[current.argfield].value =
3071: "$in{'kerb_def_dom'}";
3072: break;
3073: default:
3074: break;
3075: }
3076: }
3077: }
3078: return;
3079: }
1.22 www 3080:
1.32 matthew 3081: function changed_text(choice,currentform) {
3082: var choicearg = choice + 'arg';
3083: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3084: $Javascript_toUpperCase
1.32 matthew 3085: // clear old field
3086: if ((current.argfield != choicearg) && (current.argfield != null)) {
3087: currentform.elements[current.argfield].value = '';
3088: }
3089: current.argfield = choicearg;
3090: }
3091: set_auth_radio_buttons(choice,currentform);
3092: return;
1.20 www 3093: }
1.32 matthew 3094:
3095: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3096: var numauthchoices = currentform.login.length;
3097: if (typeof numauthchoices == "undefined") {
3098: return;
3099: }
1.32 matthew 3100: var i=0;
1.986 raeburn 3101: while (i < numauthchoices) {
1.32 matthew 3102: if (currentform.login[i].value == newvalue) { break; }
3103: i++;
3104: }
1.986 raeburn 3105: if (i == numauthchoices) {
1.32 matthew 3106: return;
3107: }
3108: current.radiovalue = newvalue;
3109: currentform.login[i].checked = true;
3110: return;
3111: }
3112: END
3113: return $result;
3114: }
3115:
1.1106 raeburn 3116: sub authform_authorwarning {
1.32 matthew 3117: my $result='';
1.144 matthew 3118: $result='<i>'.
3119: &mt('As a general rule, only authors or co-authors should be '.
3120: 'filesystem authenticated '.
3121: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3122: return $result;
3123: }
3124:
1.1106 raeburn 3125: sub authform_nochange {
1.32 matthew 3126: my %in = (
3127: formname => 'document.cu',
3128: kerb_def_dom => 'MSU.EDU',
3129: @_,
3130: );
1.1106 raeburn 3131: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3132: my $result;
1.1104 raeburn 3133: if (!$authnum) {
1.1105 raeburn 3134: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3135: } else {
3136: $result = '<label>'.&mt('[_1] Do not change login data',
3137: '<input type="radio" name="login" value="nochange" '.
3138: 'checked="checked" onclick="'.
1.281 albertel 3139: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3140: '</label>';
1.586 raeburn 3141: }
1.32 matthew 3142: return $result;
3143: }
3144:
1.591 raeburn 3145: sub authform_kerberos {
1.32 matthew 3146: my %in = (
3147: formname => 'document.cu',
3148: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3149: kerb_def_auth => 'krb4',
1.32 matthew 3150: @_,
3151: );
1.586 raeburn 3152: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
3153: $autharg,$jscall);
1.1106 raeburn 3154: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3155: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3156: $check5 = ' checked="checked"';
1.80 albertel 3157: } else {
1.772 bisitz 3158: $check4 = ' checked="checked"';
1.80 albertel 3159: }
1.165 raeburn 3160: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3161: if (defined($in{'curr_authtype'})) {
3162: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3163: $krbcheck = ' checked="checked"';
1.623 raeburn 3164: if (defined($in{'mode'})) {
3165: if ($in{'mode'} eq 'modifyuser') {
3166: $krbcheck = '';
3167: }
3168: }
1.591 raeburn 3169: if (defined($in{'curr_kerb_ver'})) {
3170: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3171: $check5 = ' checked="checked"';
1.591 raeburn 3172: $check4 = '';
3173: } else {
1.772 bisitz 3174: $check4 = ' checked="checked"';
1.591 raeburn 3175: $check5 = '';
3176: }
1.586 raeburn 3177: }
1.591 raeburn 3178: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3179: $krbarg = $in{'curr_autharg'};
3180: }
1.586 raeburn 3181: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3182: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3183: $result =
3184: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3185: $in{'curr_autharg'},$krbver);
3186: } else {
3187: $result =
3188: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3189: }
3190: return $result;
3191: }
3192: }
3193: } else {
3194: if ($authnum == 1) {
1.784 bisitz 3195: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3196: }
3197: }
1.586 raeburn 3198: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3199: return;
1.587 raeburn 3200: } elsif ($authtype eq '') {
1.591 raeburn 3201: if (defined($in{'mode'})) {
1.587 raeburn 3202: if ($in{'mode'} eq 'modifycourse') {
3203: if ($authnum == 1) {
1.1104 raeburn 3204: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 3205: }
3206: }
3207: }
1.586 raeburn 3208: }
3209: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3210: if ($authtype eq '') {
3211: $authtype = '<input type="radio" name="login" value="krb" '.
3212: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
3213: $krbcheck.' />';
3214: }
3215: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3216: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3217: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3218: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3219: $in{'curr_authtype'} eq 'krb4')) {
3220: $result .= &mt
1.144 matthew 3221: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3222: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3223: '<label>'.$authtype,
1.281 albertel 3224: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3225: 'value="'.$krbarg.'" '.
1.144 matthew 3226: 'onchange="'.$jscall.'" />',
1.281 albertel 3227: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
3228: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
3229: '</label>');
1.586 raeburn 3230: } elsif ($can_assign{'krb4'}) {
3231: $result .= &mt
3232: ('[_1] Kerberos authenticated with domain [_2] '.
3233: '[_3] Version 4 [_4]',
3234: '<label>'.$authtype,
3235: '</label><input type="text" size="10" name="krbarg" '.
3236: 'value="'.$krbarg.'" '.
3237: 'onchange="'.$jscall.'" />',
3238: '<label><input type="hidden" name="krbver" value="4" />',
3239: '</label>');
3240: } elsif ($can_assign{'krb5'}) {
3241: $result .= &mt
3242: ('[_1] Kerberos authenticated with domain [_2] '.
3243: '[_3] Version 5 [_4]',
3244: '<label>'.$authtype,
3245: '</label><input type="text" size="10" name="krbarg" '.
3246: 'value="'.$krbarg.'" '.
3247: 'onchange="'.$jscall.'" />',
3248: '<label><input type="hidden" name="krbver" value="5" />',
3249: '</label>');
3250: }
1.32 matthew 3251: return $result;
3252: }
3253:
1.1106 raeburn 3254: sub authform_internal {
1.586 raeburn 3255: my %in = (
1.32 matthew 3256: formname => 'document.cu',
3257: kerb_def_dom => 'MSU.EDU',
3258: @_,
3259: );
1.586 raeburn 3260: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 3261: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3262: if (defined($in{'curr_authtype'})) {
3263: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3264: if ($can_assign{'int'}) {
1.772 bisitz 3265: $intcheck = 'checked="checked" ';
1.623 raeburn 3266: if (defined($in{'mode'})) {
3267: if ($in{'mode'} eq 'modifyuser') {
3268: $intcheck = '';
3269: }
3270: }
1.591 raeburn 3271: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3272: $intarg = $in{'curr_autharg'};
3273: }
3274: } else {
3275: $result = &mt('Currently internally authenticated.');
3276: return $result;
1.165 raeburn 3277: }
3278: }
1.586 raeburn 3279: } else {
3280: if ($authnum == 1) {
1.784 bisitz 3281: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3282: }
3283: }
3284: if (!$can_assign{'int'}) {
3285: return;
1.587 raeburn 3286: } elsif ($authtype eq '') {
1.591 raeburn 3287: if (defined($in{'mode'})) {
1.587 raeburn 3288: if ($in{'mode'} eq 'modifycourse') {
3289: if ($authnum == 1) {
1.1104 raeburn 3290: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 3291: }
3292: }
3293: }
1.165 raeburn 3294: }
1.586 raeburn 3295: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3296: if ($authtype eq '') {
3297: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
3298: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
3299: }
1.605 bisitz 3300: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 3301: $intarg.'" onchange="'.$jscall.'" />';
3302: $result = &mt
1.144 matthew 3303: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3304: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 3305: $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 3306: return $result;
3307: }
3308:
1.1104 raeburn 3309: sub authform_local {
1.32 matthew 3310: my %in = (
3311: formname => 'document.cu',
3312: kerb_def_dom => 'MSU.EDU',
3313: @_,
3314: );
1.586 raeburn 3315: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 3316: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3317: if (defined($in{'curr_authtype'})) {
3318: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3319: if ($can_assign{'loc'}) {
1.772 bisitz 3320: $loccheck = 'checked="checked" ';
1.623 raeburn 3321: if (defined($in{'mode'})) {
3322: if ($in{'mode'} eq 'modifyuser') {
3323: $loccheck = '';
3324: }
3325: }
1.591 raeburn 3326: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3327: $locarg = $in{'curr_autharg'};
3328: }
3329: } else {
3330: $result = &mt('Currently using local (institutional) authentication.');
3331: return $result;
1.165 raeburn 3332: }
3333: }
1.586 raeburn 3334: } else {
3335: if ($authnum == 1) {
1.784 bisitz 3336: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3337: }
3338: }
3339: if (!$can_assign{'loc'}) {
3340: return;
1.587 raeburn 3341: } elsif ($authtype eq '') {
1.591 raeburn 3342: if (defined($in{'mode'})) {
1.587 raeburn 3343: if ($in{'mode'} eq 'modifycourse') {
3344: if ($authnum == 1) {
1.1104 raeburn 3345: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 3346: }
3347: }
3348: }
1.165 raeburn 3349: }
1.586 raeburn 3350: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3351: if ($authtype eq '') {
3352: $authtype = '<input type="radio" name="login" value="loc" '.
3353: $loccheck.' onchange="'.$jscall.'" onclick="'.
3354: $jscall.'" />';
3355: }
3356: $autharg = '<input type="text" size="10" name="locarg" value="'.
3357: $locarg.'" onchange="'.$jscall.'" />';
3358: $result = &mt('[_1] Local Authentication with argument [_2]',
3359: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3360: return $result;
3361: }
3362:
1.1106 raeburn 3363: sub authform_filesystem {
1.32 matthew 3364: my %in = (
3365: formname => 'document.cu',
3366: kerb_def_dom => 'MSU.EDU',
3367: @_,
3368: );
1.586 raeburn 3369: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 3370: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3371: if (defined($in{'curr_authtype'})) {
3372: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3373: if ($can_assign{'fsys'}) {
1.772 bisitz 3374: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3375: if (defined($in{'mode'})) {
3376: if ($in{'mode'} eq 'modifyuser') {
3377: $fsyscheck = '';
3378: }
3379: }
1.586 raeburn 3380: } else {
3381: $result = &mt('Currently Filesystem Authenticated.');
3382: return $result;
3383: }
3384: }
3385: } else {
3386: if ($authnum == 1) {
1.784 bisitz 3387: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3388: }
3389: }
3390: if (!$can_assign{'fsys'}) {
3391: return;
1.587 raeburn 3392: } elsif ($authtype eq '') {
1.591 raeburn 3393: if (defined($in{'mode'})) {
1.587 raeburn 3394: if ($in{'mode'} eq 'modifycourse') {
3395: if ($authnum == 1) {
1.1104 raeburn 3396: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 3397: }
3398: }
3399: }
1.586 raeburn 3400: }
3401: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3402: if ($authtype eq '') {
3403: $authtype = '<input type="radio" name="login" value="fsys" '.
3404: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
3405: $jscall.'" />';
3406: }
3407: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
3408: ' onchange="'.$jscall.'" />';
3409: $result = &mt
1.144 matthew 3410: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3411: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 3412: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 3413: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 3414: 'onchange="'.$jscall.'" />');
1.32 matthew 3415: return $result;
3416: }
3417:
1.586 raeburn 3418: sub get_assignable_auth {
3419: my ($dom) = @_;
3420: if ($dom eq '') {
3421: $dom = $env{'request.role.domain'};
3422: }
3423: my %can_assign = (
3424: krb4 => 1,
3425: krb5 => 1,
3426: int => 1,
3427: loc => 1,
3428: );
3429: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3430: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3431: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3432: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3433: my $context;
3434: if ($env{'request.role'} =~ /^au/) {
3435: $context = 'author';
3436: } elsif ($env{'request.role'} =~ /^dc/) {
3437: $context = 'domain';
3438: } elsif ($env{'request.course.id'}) {
3439: $context = 'course';
3440: }
3441: if ($context) {
3442: if (ref($authhash->{$context}) eq 'HASH') {
3443: %can_assign = %{$authhash->{$context}};
3444: }
3445: }
3446: }
3447: }
3448: my $authnum = 0;
3449: foreach my $key (keys(%can_assign)) {
3450: if ($can_assign{$key}) {
3451: $authnum ++;
3452: }
3453: }
3454: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3455: $authnum --;
3456: }
3457: return ($authnum,%can_assign);
3458: }
3459:
1.80 albertel 3460: ###############################################################
3461: ## Get Kerberos Defaults for Domain ##
3462: ###############################################################
3463: ##
3464: ## Returns default kerberos version and an associated argument
3465: ## as listed in file domain.tab. If not listed, provides
3466: ## appropriate default domain and kerberos version.
3467: ##
3468: #-------------------------------------------
3469:
3470: =pod
3471:
1.648 raeburn 3472: =item * &get_kerberos_defaults()
1.80 albertel 3473:
3474: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3475: version and domain. If not found, it defaults to version 4 and the
3476: domain of the server.
1.80 albertel 3477:
1.648 raeburn 3478: =over 4
3479:
1.80 albertel 3480: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3481:
1.648 raeburn 3482: =back
3483:
3484: =back
3485:
1.80 albertel 3486: =cut
3487:
3488: #-------------------------------------------
3489: sub get_kerberos_defaults {
3490: my $domain=shift;
1.641 raeburn 3491: my ($krbdef,$krbdefdom);
3492: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3493: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3494: $krbdef = $domdefaults{'auth_def'};
3495: $krbdefdom = $domdefaults{'auth_arg_def'};
3496: } else {
1.80 albertel 3497: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3498: my $krbdefdom=$1;
3499: $krbdefdom=~tr/a-z/A-Z/;
3500: $krbdef = "krb4";
3501: }
3502: return ($krbdef,$krbdefdom);
3503: }
1.112 bowersj2 3504:
1.32 matthew 3505:
1.46 matthew 3506: ###############################################################
3507: ## Thesaurus Functions ##
3508: ###############################################################
1.20 www 3509:
1.46 matthew 3510: =pod
1.20 www 3511:
1.112 bowersj2 3512: =head1 Thesaurus Functions
3513:
3514: =over 4
3515:
1.648 raeburn 3516: =item * &initialize_keywords()
1.46 matthew 3517:
3518: Initializes the package variable %Keywords if it is empty. Uses the
3519: package variable $thesaurus_db_file.
3520:
3521: =cut
3522:
3523: ###################################################
3524:
3525: sub initialize_keywords {
3526: return 1 if (scalar keys(%Keywords));
3527: # If we are here, %Keywords is empty, so fill it up
3528: # Make sure the file we need exists...
3529: if (! -e $thesaurus_db_file) {
3530: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3531: " failed because it does not exist");
3532: return 0;
3533: }
3534: # Set up the hash as a database
3535: my %thesaurus_db;
3536: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3537: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3538: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3539: $thesaurus_db_file);
3540: return 0;
3541: }
3542: # Get the average number of appearances of a word.
3543: my $avecount = $thesaurus_db{'average.count'};
3544: # Put keywords (those that appear > average) into %Keywords
3545: while (my ($word,$data)=each (%thesaurus_db)) {
3546: my ($count,undef) = split /:/,$data;
3547: $Keywords{$word}++ if ($count > $avecount);
3548: }
3549: untie %thesaurus_db;
3550: # Remove special values from %Keywords.
1.356 albertel 3551: foreach my $value ('total.count','average.count') {
3552: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3553: }
1.46 matthew 3554: return 1;
3555: }
3556:
3557: ###################################################
3558:
3559: =pod
3560:
1.648 raeburn 3561: =item * &keyword($word)
1.46 matthew 3562:
3563: Returns true if $word is a keyword. A keyword is a word that appears more
3564: than the average number of times in the thesaurus database. Calls
3565: &initialize_keywords
3566:
3567: =cut
3568:
3569: ###################################################
1.20 www 3570:
3571: sub keyword {
1.46 matthew 3572: return if (!&initialize_keywords());
3573: my $word=lc(shift());
3574: $word=~s/\W//g;
3575: return exists($Keywords{$word});
1.20 www 3576: }
1.46 matthew 3577:
3578: ###############################################################
3579:
3580: =pod
1.20 www 3581:
1.648 raeburn 3582: =item * &get_related_words()
1.46 matthew 3583:
1.160 matthew 3584: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3585: an array of words. If the keyword is not in the thesaurus, an empty array
3586: will be returned. The order of the words returned is determined by the
3587: database which holds them.
3588:
3589: Uses global $thesaurus_db_file.
3590:
1.1057 foxr 3591:
1.46 matthew 3592: =cut
3593:
3594: ###############################################################
3595: sub get_related_words {
3596: my $keyword = shift;
3597: my %thesaurus_db;
3598: if (! -e $thesaurus_db_file) {
3599: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3600: "failed because the file does not exist");
3601: return ();
3602: }
3603: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3604: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3605: return ();
3606: }
3607: my @Words=();
1.429 www 3608: my $count=0;
1.46 matthew 3609: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3610: # The first element is the number of times
3611: # the word appears. We do not need it now.
1.429 www 3612: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3613: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3614: my $threshold=$mostfrequentcount/10;
3615: foreach my $possibleword (@RelatedWords) {
3616: my ($word,$wordcount)=split(/\,/,$possibleword);
3617: if ($wordcount>$threshold) {
3618: push(@Words,$word);
3619: $count++;
3620: if ($count>10) { last; }
3621: }
1.20 www 3622: }
3623: }
1.46 matthew 3624: untie %thesaurus_db;
3625: return @Words;
1.14 harris41 3626: }
1.1090 foxr 3627: ###############################################################
3628: #
3629: # Spell checking
3630: #
3631:
3632: =pod
3633:
1.1142 raeburn 3634: =back
3635:
1.1090 foxr 3636: =head1 Spell checking
3637:
3638: =over 4
3639:
3640: =item * &check_spelling($wordlist $language)
3641:
3642: Takes a string containing words and feeds it to an external
3643: spellcheck program via a pipeline. Returns a string containing
3644: them mis-spelled words.
3645:
3646: Parameters:
3647:
3648: =over 4
3649:
3650: =item - $wordlist
3651:
3652: String that will be fed into the spellcheck program.
3653:
3654: =item - $language
3655:
3656: Language string that specifies the language for which the spell
3657: check will be performed.
3658:
3659: =back
3660:
3661: =back
3662:
3663: Note: This sub assumes that aspell is installed.
3664:
3665:
3666: =cut
3667:
1.46 matthew 3668:
1.1090 foxr 3669: sub check_spelling {
3670: my ($wordlist, $language) = @_;
1.1091 foxr 3671: my @misspellings;
3672:
3673: # Generate the speller and set the langauge.
3674: # if explicitly selected:
1.1090 foxr 3675:
1.1091 foxr 3676: my $speller = Text::Aspell->new;
1.1090 foxr 3677: if ($language) {
1.1091 foxr 3678: $speller->set_option('lang', $language);
1.1090 foxr 3679: }
3680:
1.1091 foxr 3681: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3682:
1.1091 foxr 3683: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3684:
1.1091 foxr 3685: foreach my $word (@words) {
3686: if(! $speller->check($word)) {
3687: push(@misspellings, $word);
1.1090 foxr 3688: }
3689: }
1.1091 foxr 3690: return join(' ', @misspellings);
3691:
1.1090 foxr 3692: }
3693:
1.61 www 3694: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3695: =pod
3696:
1.112 bowersj2 3697: =head1 User Name Functions
3698:
3699: =over 4
3700:
1.648 raeburn 3701: =item * &plainname($uname,$udom,$first)
1.81 albertel 3702:
1.112 bowersj2 3703: Takes a users logon name and returns it as a string in
1.226 albertel 3704: "first middle last generation" form
3705: if $first is set to 'lastname' then it returns it as
3706: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3707:
3708: =cut
1.61 www 3709:
1.295 www 3710:
1.81 albertel 3711: ###############################################################
1.61 www 3712: sub plainname {
1.226 albertel 3713: my ($uname,$udom,$first)=@_;
1.537 albertel 3714: return if (!defined($uname) || !defined($udom));
1.295 www 3715: my %names=&getnames($uname,$udom);
1.226 albertel 3716: my $name=&Apache::lonnet::format_name($names{'firstname'},
3717: $names{'middlename'},
3718: $names{'lastname'},
3719: $names{'generation'},$first);
3720: $name=~s/^\s+//;
1.62 www 3721: $name=~s/\s+$//;
3722: $name=~s/\s+/ /g;
1.353 albertel 3723: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3724: return $name;
1.61 www 3725: }
1.66 www 3726:
3727: # -------------------------------------------------------------------- Nickname
1.81 albertel 3728: =pod
3729:
1.648 raeburn 3730: =item * &nickname($uname,$udom)
1.81 albertel 3731:
3732: Gets a users name and returns it as a string as
3733:
3734: ""nickname""
1.66 www 3735:
1.81 albertel 3736: if the user has a nickname or
3737:
3738: "first middle last generation"
3739:
3740: if the user does not
3741:
3742: =cut
1.66 www 3743:
3744: sub nickname {
3745: my ($uname,$udom)=@_;
1.537 albertel 3746: return if (!defined($uname) || !defined($udom));
1.295 www 3747: my %names=&getnames($uname,$udom);
1.68 albertel 3748: my $name=$names{'nickname'};
1.66 www 3749: if ($name) {
3750: $name='"'.$name.'"';
3751: } else {
3752: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3753: $names{'lastname'}.' '.$names{'generation'};
3754: $name=~s/\s+$//;
3755: $name=~s/\s+/ /g;
3756: }
3757: return $name;
3758: }
3759:
1.295 www 3760: sub getnames {
3761: my ($uname,$udom)=@_;
1.537 albertel 3762: return if (!defined($uname) || !defined($udom));
1.433 albertel 3763: if ($udom eq 'public' && $uname eq 'public') {
3764: return ('lastname' => &mt('Public'));
3765: }
1.295 www 3766: my $id=$uname.':'.$udom;
3767: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3768: if ($cached) {
3769: return %{$names};
3770: } else {
3771: my %loadnames=&Apache::lonnet::get('environment',
3772: ['firstname','middlename','lastname','generation','nickname'],
3773: $udom,$uname);
3774: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3775: return %loadnames;
3776: }
3777: }
1.61 www 3778:
1.542 raeburn 3779: # -------------------------------------------------------------------- getemails
1.648 raeburn 3780:
1.542 raeburn 3781: =pod
3782:
1.648 raeburn 3783: =item * &getemails($uname,$udom)
1.542 raeburn 3784:
3785: Gets a user's email information and returns it as a hash with keys:
3786: notification, critnotification, permanentemail
3787:
3788: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3789: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3790:
1.648 raeburn 3791:
1.542 raeburn 3792: =cut
3793:
1.648 raeburn 3794:
1.466 albertel 3795: sub getemails {
3796: my ($uname,$udom)=@_;
3797: if ($udom eq 'public' && $uname eq 'public') {
3798: return;
3799: }
1.467 www 3800: if (!$udom) { $udom=$env{'user.domain'}; }
3801: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3802: my $id=$uname.':'.$udom;
3803: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3804: if ($cached) {
3805: return %{$names};
3806: } else {
3807: my %loadnames=&Apache::lonnet::get('environment',
3808: ['notification','critnotification',
3809: 'permanentemail'],
3810: $udom,$uname);
3811: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3812: return %loadnames;
3813: }
3814: }
3815:
1.551 albertel 3816: sub flush_email_cache {
3817: my ($uname,$udom)=@_;
3818: if (!$udom) { $udom =$env{'user.domain'}; }
3819: if (!$uname) { $uname=$env{'user.name'}; }
3820: return if ($udom eq 'public' && $uname eq 'public');
3821: my $id=$uname.':'.$udom;
3822: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3823: }
3824:
1.728 raeburn 3825: # -------------------------------------------------------------------- getlangs
3826:
3827: =pod
3828:
3829: =item * &getlangs($uname,$udom)
3830:
3831: Gets a user's language preference and returns it as a hash with key:
3832: language.
3833:
3834: =cut
3835:
3836:
3837: sub getlangs {
3838: my ($uname,$udom) = @_;
3839: if (!$udom) { $udom =$env{'user.domain'}; }
3840: if (!$uname) { $uname=$env{'user.name'}; }
3841: my $id=$uname.':'.$udom;
3842: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3843: if ($cached) {
3844: return %{$langs};
3845: } else {
3846: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3847: $udom,$uname);
3848: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3849: return %loadlangs;
3850: }
3851: }
3852:
3853: sub flush_langs_cache {
3854: my ($uname,$udom)=@_;
3855: if (!$udom) { $udom =$env{'user.domain'}; }
3856: if (!$uname) { $uname=$env{'user.name'}; }
3857: return if ($udom eq 'public' && $uname eq 'public');
3858: my $id=$uname.':'.$udom;
3859: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3860: }
3861:
1.61 www 3862: # ------------------------------------------------------------------ Screenname
1.81 albertel 3863:
3864: =pod
3865:
1.648 raeburn 3866: =item * &screenname($uname,$udom)
1.81 albertel 3867:
3868: Gets a users screenname and returns it as a string
3869:
3870: =cut
1.61 www 3871:
3872: sub screenname {
3873: my ($uname,$udom)=@_;
1.258 albertel 3874: if ($uname eq $env{'user.name'} &&
3875: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3876: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3877: return $names{'screenname'};
1.62 www 3878: }
3879:
1.212 albertel 3880:
1.802 bisitz 3881: # ------------------------------------------------------------- Confirm Wrapper
3882: =pod
3883:
1.1142 raeburn 3884: =item * &confirmwrapper($message)
1.802 bisitz 3885:
3886: Wrap messages about completion of operation in box
3887:
3888: =cut
3889:
3890: sub confirmwrapper {
3891: my ($message)=@_;
3892: if ($message) {
3893: return "\n".'<div class="LC_confirm_box">'."\n"
3894: .$message."\n"
3895: .'</div>'."\n";
3896: } else {
3897: return $message;
3898: }
3899: }
3900:
1.62 www 3901: # ------------------------------------------------------------- Message Wrapper
3902:
3903: sub messagewrapper {
1.369 www 3904: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3905: return
1.441 albertel 3906: '<a href="/adm/email?compose=individual&'.
3907: 'recname='.$username.'&recdom='.$domain.
3908: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3909: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3910: }
1.802 bisitz 3911:
1.74 www 3912: # --------------------------------------------------------------- Notes Wrapper
3913:
3914: sub noteswrapper {
3915: my ($link,$un,$do)=@_;
3916: return
1.896 amueller 3917: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3918: }
1.802 bisitz 3919:
1.62 www 3920: # ------------------------------------------------------------- Aboutme Wrapper
3921:
3922: sub aboutmewrapper {
1.1070 raeburn 3923: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3924: if (!defined($username) && !defined($domain)) {
3925: return;
3926: }
1.1096 raeburn 3927: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3928: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3929: }
3930:
3931: # ------------------------------------------------------------ Syllabus Wrapper
3932:
3933: sub syllabuswrapper {
1.707 bisitz 3934: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3935: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3936: }
1.14 harris41 3937:
1.802 bisitz 3938: # -----------------------------------------------------------------------------
3939:
1.208 matthew 3940: sub track_student_link {
1.887 raeburn 3941: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3942: my $link ="/adm/trackstudent?";
1.208 matthew 3943: my $title = 'View recent activity';
3944: if (defined($sname) && $sname !~ /^\s*$/ &&
3945: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3946: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3947: $title .= ' of this student';
1.268 albertel 3948: }
1.208 matthew 3949: if (defined($target) && $target !~ /^\s*$/) {
3950: $target = qq{target="$target"};
3951: } else {
3952: $target = '';
3953: }
1.268 albertel 3954: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3955: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3956: $title = &mt($title);
3957: $linktext = &mt($linktext);
1.448 albertel 3958: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3959: &help_open_topic('View_recent_activity');
1.208 matthew 3960: }
3961:
1.781 raeburn 3962: sub slot_reservations_link {
3963: my ($linktext,$sname,$sdom,$target) = @_;
3964: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3965: my $title = 'View slot reservation history';
3966: if (defined($sname) && $sname !~ /^\s*$/ &&
3967: defined($sdom) && $sdom !~ /^\s*$/) {
3968: $link .= "&uname=$sname&udom=$sdom";
3969: $title .= ' of this student';
3970: }
3971: if (defined($target) && $target !~ /^\s*$/) {
3972: $target = qq{target="$target"};
3973: } else {
3974: $target = '';
3975: }
3976: $title = &mt($title);
3977: $linktext = &mt($linktext);
3978: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3979: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3980:
3981: }
3982:
1.508 www 3983: # ===================================================== Display a student photo
3984:
3985:
1.509 albertel 3986: sub student_image_tag {
1.508 www 3987: my ($domain,$user)=@_;
3988: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3989: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3990: return '<img src="'.$imgsrc.'" align="right" />';
3991: } else {
3992: return '';
3993: }
3994: }
3995:
1.112 bowersj2 3996: =pod
3997:
3998: =back
3999:
4000: =head1 Access .tab File Data
4001:
4002: =over 4
4003:
1.648 raeburn 4004: =item * &languageids()
1.112 bowersj2 4005:
4006: returns list of all language ids
4007:
4008: =cut
4009:
1.14 harris41 4010: sub languageids {
1.16 harris41 4011: return sort(keys(%language));
1.14 harris41 4012: }
4013:
1.112 bowersj2 4014: =pod
4015:
1.648 raeburn 4016: =item * &languagedescription()
1.112 bowersj2 4017:
4018: returns description of a specified language id
4019:
4020: =cut
4021:
1.14 harris41 4022: sub languagedescription {
1.125 www 4023: my $code=shift;
4024: return ($supported_language{$code}?'* ':'').
4025: $language{$code}.
1.126 www 4026: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4027: }
4028:
1.1048 foxr 4029: =pod
4030:
4031: =item * &plainlanguagedescription
4032:
4033: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4034: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4035:
4036: =cut
4037:
1.145 www 4038: sub plainlanguagedescription {
4039: my $code=shift;
4040: return $language{$code};
4041: }
4042:
1.1048 foxr 4043: =pod
4044:
4045: =item * &supportedlanguagecode
4046:
4047: Returns the supported language code (e.g. sptutf maps to pt) given a language
4048: code.
4049:
4050: =cut
4051:
1.145 www 4052: sub supportedlanguagecode {
4053: my $code=shift;
4054: return $supported_language{$code};
1.97 www 4055: }
4056:
1.112 bowersj2 4057: =pod
4058:
1.1048 foxr 4059: =item * &latexlanguage()
4060:
4061: Given a language key code returns the correspondnig language to use
4062: to select the correct hyphenation on LaTeX printouts. This is undef if there
4063: is no supported hyphenation for the language code.
4064:
4065: =cut
4066:
4067: sub latexlanguage {
4068: my $code = shift;
4069: return $latex_language{$code};
4070: }
4071:
4072: =pod
4073:
4074: =item * &latexhyphenation()
4075:
4076: Same as above but what's supplied is the language as it might be stored
4077: in the metadata.
4078:
4079: =cut
4080:
4081: sub latexhyphenation {
4082: my $key = shift;
4083: return $latex_language_bykey{$key};
4084: }
4085:
4086: =pod
4087:
1.648 raeburn 4088: =item * ©rightids()
1.112 bowersj2 4089:
4090: returns list of all copyrights
4091:
4092: =cut
4093:
4094: sub copyrightids {
4095: return sort(keys(%cprtag));
4096: }
4097:
4098: =pod
4099:
1.648 raeburn 4100: =item * ©rightdescription()
1.112 bowersj2 4101:
4102: returns description of a specified copyright id
4103:
4104: =cut
4105:
4106: sub copyrightdescription {
1.166 www 4107: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4108: }
1.197 matthew 4109:
4110: =pod
4111:
1.648 raeburn 4112: =item * &source_copyrightids()
1.192 taceyjo1 4113:
4114: returns list of all source copyrights
4115:
4116: =cut
4117:
4118: sub source_copyrightids {
4119: return sort(keys(%scprtag));
4120: }
4121:
4122: =pod
4123:
1.648 raeburn 4124: =item * &source_copyrightdescription()
1.192 taceyjo1 4125:
4126: returns description of a specified source copyright id
4127:
4128: =cut
4129:
4130: sub source_copyrightdescription {
4131: return &mt($scprtag{shift(@_)});
4132: }
1.112 bowersj2 4133:
4134: =pod
4135:
1.648 raeburn 4136: =item * &filecategories()
1.112 bowersj2 4137:
4138: returns list of all file categories
4139:
4140: =cut
4141:
4142: sub filecategories {
4143: return sort(keys(%category_extensions));
4144: }
4145:
4146: =pod
4147:
1.648 raeburn 4148: =item * &filecategorytypes()
1.112 bowersj2 4149:
4150: returns list of file types belonging to a given file
4151: category
4152:
4153: =cut
4154:
4155: sub filecategorytypes {
1.356 albertel 4156: my ($cat) = @_;
1.1248 ! raeburn 4157: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
! 4158: return @{$category_extensions{lc($cat)}};
! 4159: } else {
! 4160: return ();
! 4161: }
1.112 bowersj2 4162: }
4163:
4164: =pod
4165:
1.648 raeburn 4166: =item * &fileembstyle()
1.112 bowersj2 4167:
4168: returns embedding style for a specified file type
4169:
4170: =cut
4171:
4172: sub fileembstyle {
4173: return $fe{lc(shift(@_))};
1.169 www 4174: }
4175:
1.351 www 4176: sub filemimetype {
4177: return $fm{lc(shift(@_))};
4178: }
4179:
1.169 www 4180:
4181: sub filecategoryselect {
4182: my ($name,$value)=@_;
1.189 matthew 4183: return &select_form($value,$name,
1.970 raeburn 4184: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4185: }
4186:
4187: =pod
4188:
1.648 raeburn 4189: =item * &filedescription()
1.112 bowersj2 4190:
4191: returns description for a specified file type
4192:
4193: =cut
4194:
4195: sub filedescription {
1.188 matthew 4196: my $file_description = $fd{lc(shift())};
4197: $file_description =~ s:([\[\]]):~$1:g;
4198: return &mt($file_description);
1.112 bowersj2 4199: }
4200:
4201: =pod
4202:
1.648 raeburn 4203: =item * &filedescriptionex()
1.112 bowersj2 4204:
4205: returns description for a specified file type with
4206: extra formatting
4207:
4208: =cut
4209:
4210: sub filedescriptionex {
4211: my $ex=shift;
1.188 matthew 4212: my $file_description = $fd{lc($ex)};
4213: $file_description =~ s:([\[\]]):~$1:g;
4214: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4215: }
4216:
4217: # End of .tab access
4218: =pod
4219:
4220: =back
4221:
4222: =cut
4223:
4224: # ------------------------------------------------------------------ File Types
4225: sub fileextensions {
4226: return sort(keys(%fe));
4227: }
4228:
1.97 www 4229: # ----------------------------------------------------------- Display Languages
4230: # returns a hash with all desired display languages
4231: #
4232:
4233: sub display_languages {
4234: my %languages=();
1.695 raeburn 4235: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4236: $languages{$lang}=1;
1.97 www 4237: }
4238: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4239: if ($env{'form.displaylanguage'}) {
1.356 albertel 4240: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4241: $languages{$lang}=1;
1.97 www 4242: }
4243: }
4244: return %languages;
1.14 harris41 4245: }
4246:
1.582 albertel 4247: sub languages {
4248: my ($possible_langs) = @_;
1.695 raeburn 4249: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4250: if (!ref($possible_langs)) {
4251: if( wantarray ) {
4252: return @preferred_langs;
4253: } else {
4254: return $preferred_langs[0];
4255: }
4256: }
4257: my %possibilities = map { $_ => 1 } (@$possible_langs);
4258: my @preferred_possibilities;
4259: foreach my $preferred_lang (@preferred_langs) {
4260: if (exists($possibilities{$preferred_lang})) {
4261: push(@preferred_possibilities, $preferred_lang);
4262: }
4263: }
4264: if( wantarray ) {
4265: return @preferred_possibilities;
4266: }
4267: return $preferred_possibilities[0];
4268: }
4269:
1.742 raeburn 4270: sub user_lang {
4271: my ($touname,$toudom,$fromcid) = @_;
4272: my @userlangs;
4273: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4274: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4275: $env{'course.'.$fromcid.'.languages'}));
4276: } else {
4277: my %langhash = &getlangs($touname,$toudom);
4278: if ($langhash{'languages'} ne '') {
4279: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4280: } else {
4281: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4282: if ($domdefs{'lang_def'} ne '') {
4283: @userlangs = ($domdefs{'lang_def'});
4284: }
4285: }
4286: }
4287: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4288: my $user_lh = Apache::localize->get_handle(@languages);
4289: return $user_lh;
4290: }
4291:
4292:
1.112 bowersj2 4293: ###############################################################
4294: ## Student Answer Attempts ##
4295: ###############################################################
4296:
4297: =pod
4298:
4299: =head1 Alternate Problem Views
4300:
4301: =over 4
4302:
1.648 raeburn 4303: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4304: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4305:
4306: Return string with previous attempt on problem. Arguments:
4307:
4308: =over 4
4309:
4310: =item * $symb: Problem, including path
4311:
4312: =item * $username: username of the desired student
4313:
4314: =item * $domain: domain of the desired student
1.14 harris41 4315:
1.112 bowersj2 4316: =item * $course: Course ID
1.14 harris41 4317:
1.112 bowersj2 4318: =item * $getattempt: Leave blank for all attempts, otherwise put
4319: something
1.14 harris41 4320:
1.112 bowersj2 4321: =item * $regexp: if string matches this regexp, the string will be
4322: sent to $gradesub
1.14 harris41 4323:
1.112 bowersj2 4324: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4325:
1.1199 raeburn 4326: =item * $usec: section of the desired student
4327:
4328: =item * $identifier: counter for student (multiple students one problem) or
4329: problem (one student; whole sequence).
4330:
1.112 bowersj2 4331: =back
1.14 harris41 4332:
1.112 bowersj2 4333: The output string is a table containing all desired attempts, if any.
1.16 harris41 4334:
1.112 bowersj2 4335: =cut
1.1 albertel 4336:
4337: sub get_previous_attempt {
1.1199 raeburn 4338: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4339: my $prevattempts='';
1.43 ng 4340: no strict 'refs';
1.1 albertel 4341: if ($symb) {
1.3 albertel 4342: my (%returnhash)=
4343: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4344: if ($returnhash{'version'}) {
4345: my %lasthash=();
4346: my $version;
4347: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4348: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4349: if ($key =~ /\.rawrndseed$/) {
4350: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4351: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4352: } else {
4353: $lasthash{$key}=$returnhash{$version.':'.$key};
4354: }
1.19 harris41 4355: }
1.1 albertel 4356: }
1.596 albertel 4357: $prevattempts=&start_data_table().&start_data_table_header_row();
4358: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4359: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4360: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4361: foreach my $key (sort(keys(%lasthash))) {
4362: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4363: if ($#parts > 0) {
1.31 albertel 4364: my $data=$parts[-1];
1.989 raeburn 4365: next if ($data eq 'foilorder');
1.31 albertel 4366: pop(@parts);
1.1010 www 4367: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4368: if ($data eq 'type') {
4369: unless ($showsurv) {
4370: my $id = join(',',@parts);
4371: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4372: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4373: $lasthidden{$ign.'.'.$id} = 1;
4374: }
1.945 raeburn 4375: }
1.1199 raeburn 4376: if ($identifier ne '') {
4377: my $id = join(',',@parts);
4378: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4379: $domain,$username,$usec,undef,$course) =~ /^no/) {
4380: $hidestatus{$ign.'.'.$id} = 1;
4381: }
4382: }
4383: } elsif ($data eq 'regrader') {
4384: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4385: my $id = join(',',@parts);
4386: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4387: }
1.1010 www 4388: }
1.31 albertel 4389: } else {
1.41 ng 4390: if ($#parts == 0) {
4391: $prevattempts.='<th>'.$parts[0].'</th>';
4392: } else {
4393: $prevattempts.='<th>'.$ign.'</th>';
4394: }
1.31 albertel 4395: }
1.16 harris41 4396: }
1.596 albertel 4397: $prevattempts.=&end_data_table_header_row();
1.40 ng 4398: if ($getattempt eq '') {
1.1199 raeburn 4399: my (%solved,%resets,%probstatus);
1.1200 raeburn 4400: if (($identifier ne '') && (keys(%regraded) > 0)) {
4401: for ($version=1;$version<=$returnhash{'version'};$version++) {
4402: foreach my $id (keys(%regraded)) {
4403: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4404: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4405: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4406: push(@{$resets{$id}},$version);
1.1199 raeburn 4407: }
4408: }
4409: }
1.1200 raeburn 4410: }
4411: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4412: my (@hidden,@unsolved);
1.945 raeburn 4413: if (%typeparts) {
4414: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4415: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4416: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4417: push(@hidden,$id);
1.1199 raeburn 4418: } elsif ($identifier ne '') {
4419: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4420: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4421: ($hidestatus{$id})) {
1.1200 raeburn 4422: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4423: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4424: push(@{$solved{$id}},$version);
4425: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4426: (ref($solved{$id}) eq 'ARRAY')) {
4427: my $skip;
4428: if (ref($resets{$id}) eq 'ARRAY') {
4429: foreach my $reset (@{$resets{$id}}) {
4430: if ($reset > $solved{$id}[-1]) {
4431: $skip=1;
4432: last;
4433: }
4434: }
4435: }
4436: unless ($skip) {
4437: my ($ign,$partslist) = split(/\./,$id,2);
4438: push(@unsolved,$partslist);
4439: }
4440: }
4441: }
1.945 raeburn 4442: }
4443: }
4444: }
4445: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4446: '<td>'.&mt('Transaction [_1]',$version);
4447: if (@unsolved) {
4448: $prevattempts .= '<span class="LC_nobreak"><label>'.
4449: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4450: &mt('Hide').'</label></span>';
4451: }
4452: $prevattempts .= '</td>';
1.945 raeburn 4453: if (@hidden) {
4454: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4455: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4456: my $hide;
4457: foreach my $id (@hidden) {
4458: if ($key =~ /^\Q$id\E/) {
4459: $hide = 1;
4460: last;
4461: }
4462: }
4463: if ($hide) {
4464: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4465: if (($data eq 'award') || ($data eq 'awarddetail')) {
4466: my $value = &format_previous_attempt_value($key,
4467: $returnhash{$version.':'.$key});
1.1173 kruse 4468: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4469: } else {
4470: $prevattempts.='<td> </td>';
4471: }
4472: } else {
4473: if ($key =~ /\./) {
1.1212 raeburn 4474: my $value = $returnhash{$version.':'.$key};
4475: if ($key =~ /\.rndseed$/) {
4476: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4477: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4478: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4479: }
4480: }
4481: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4482: ' </td>';
1.945 raeburn 4483: } else {
4484: $prevattempts.='<td> </td>';
4485: }
4486: }
4487: }
4488: } else {
4489: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4490: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4491: my $value = $returnhash{$version.':'.$key};
4492: if ($key =~ /\.rndseed$/) {
4493: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4494: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4495: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4496: }
4497: }
4498: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4499: ' </td>';
1.945 raeburn 4500: }
4501: }
4502: $prevattempts.=&end_data_table_row();
1.40 ng 4503: }
1.1 albertel 4504: }
1.945 raeburn 4505: my @currhidden = keys(%lasthidden);
1.596 albertel 4506: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4507: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4508: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4509: if (%typeparts) {
4510: my $hidden;
4511: foreach my $id (@currhidden) {
4512: if ($key =~ /^\Q$id\E/) {
4513: $hidden = 1;
4514: last;
4515: }
4516: }
4517: if ($hidden) {
4518: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4519: if (($data eq 'award') || ($data eq 'awarddetail')) {
4520: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4521: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4522: $value = &$gradesub($value);
4523: }
1.1173 kruse 4524: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4525: } else {
4526: $prevattempts.='<td> </td>';
4527: }
4528: } else {
4529: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4530: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4531: $value = &$gradesub($value);
4532: }
1.1173 kruse 4533: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4534: }
4535: } else {
4536: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4537: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4538: $value = &$gradesub($value);
4539: }
1.1173 kruse 4540: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4541: }
1.16 harris41 4542: }
1.596 albertel 4543: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4544: } else {
1.596 albertel 4545: $prevattempts=
4546: &start_data_table().&start_data_table_row().
4547: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4548: &end_data_table_row().&end_data_table();
1.1 albertel 4549: }
4550: } else {
1.596 albertel 4551: $prevattempts=
4552: &start_data_table().&start_data_table_row().
4553: '<td>'.&mt('No data.').'</td>'.
4554: &end_data_table_row().&end_data_table();
1.1 albertel 4555: }
1.10 albertel 4556: }
4557:
1.581 albertel 4558: sub format_previous_attempt_value {
4559: my ($key,$value) = @_;
1.1011 www 4560: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4561: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4562: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4563: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4564: } elsif ($key =~ /answerstring$/) {
4565: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4566: my @answer = %answers;
4567: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4568: my @anskeys = sort(keys(%answers));
4569: if (@anskeys == 1) {
4570: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4571: if ($answer =~ m{\0}) {
4572: $answer =~ s{\0}{,}g;
1.988 raeburn 4573: }
4574: my $tag_internal_answer_name = 'INTERNAL';
4575: if ($anskeys[0] eq $tag_internal_answer_name) {
4576: $value = $answer;
4577: } else {
4578: $value = $anskeys[0].'='.$answer;
4579: }
4580: } else {
4581: foreach my $ans (@anskeys) {
4582: my $answer = $answers{$ans};
1.1001 raeburn 4583: if ($answer =~ m{\0}) {
4584: $answer =~ s{\0}{,}g;
1.988 raeburn 4585: }
4586: $value .= $ans.'='.$answer.'<br />';;
4587: }
4588: }
1.581 albertel 4589: } else {
1.1173 kruse 4590: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4591: }
4592: return $value;
4593: }
4594:
4595:
1.107 albertel 4596: sub relative_to_absolute {
4597: my ($url,$output)=@_;
4598: my $parser=HTML::TokeParser->new(\$output);
4599: my $token;
4600: my $thisdir=$url;
4601: my @rlinks=();
4602: while ($token=$parser->get_token) {
4603: if ($token->[0] eq 'S') {
4604: if ($token->[1] eq 'a') {
4605: if ($token->[2]->{'href'}) {
4606: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4607: }
4608: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4609: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4610: } elsif ($token->[1] eq 'base') {
4611: $thisdir=$token->[2]->{'href'};
4612: }
4613: }
4614: }
4615: $thisdir=~s-/[^/]*$--;
1.356 albertel 4616: foreach my $link (@rlinks) {
1.726 raeburn 4617: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4618: ($link=~/^\//) ||
4619: ($link=~/^javascript:/i) ||
4620: ($link=~/^mailto:/i) ||
4621: ($link=~/^\#/)) {
4622: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4623: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4624: }
4625: }
4626: # -------------------------------------------------- Deal with Applet codebases
4627: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4628: return $output;
4629: }
4630:
1.112 bowersj2 4631: =pod
4632:
1.648 raeburn 4633: =item * &get_student_view()
1.112 bowersj2 4634:
4635: show a snapshot of what student was looking at
4636:
4637: =cut
4638:
1.10 albertel 4639: sub get_student_view {
1.186 albertel 4640: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4641: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4642: my (%form);
1.10 albertel 4643: my @elements=('symb','courseid','domain','username');
4644: foreach my $element (@elements) {
1.186 albertel 4645: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4646: }
1.186 albertel 4647: if (defined($moreenv)) {
4648: %form=(%form,%{$moreenv});
4649: }
1.236 albertel 4650: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4651: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4652: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4653: $userview=~s/\<body[^\>]*\>//gi;
4654: $userview=~s/\<\/body\>//gi;
4655: $userview=~s/\<html\>//gi;
4656: $userview=~s/\<\/html\>//gi;
4657: $userview=~s/\<head\>//gi;
4658: $userview=~s/\<\/head\>//gi;
4659: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4660: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4661: if (wantarray) {
4662: return ($userview,$response);
4663: } else {
4664: return $userview;
4665: }
4666: }
4667:
4668: sub get_student_view_with_retries {
4669: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4670:
4671: my $ok = 0; # True if we got a good response.
4672: my $content;
4673: my $response;
4674:
4675: # Try to get the student_view done. within the retries count:
4676:
4677: do {
4678: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4679: $ok = $response->is_success;
4680: if (!$ok) {
4681: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4682: }
4683: $retries--;
4684: } while (!$ok && ($retries > 0));
4685:
4686: if (!$ok) {
4687: $content = ''; # On error return an empty content.
4688: }
1.651 www 4689: if (wantarray) {
4690: return ($content, $response);
4691: } else {
4692: return $content;
4693: }
1.11 albertel 4694: }
4695:
1.112 bowersj2 4696: =pod
4697:
1.648 raeburn 4698: =item * &get_student_answers()
1.112 bowersj2 4699:
4700: show a snapshot of how student was answering problem
4701:
4702: =cut
4703:
1.11 albertel 4704: sub get_student_answers {
1.100 sakharuk 4705: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4706: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4707: my (%moreenv);
1.11 albertel 4708: my @elements=('symb','courseid','domain','username');
4709: foreach my $element (@elements) {
1.186 albertel 4710: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4711: }
1.186 albertel 4712: $moreenv{'grade_target'}='answer';
4713: %moreenv=(%form,%moreenv);
1.497 raeburn 4714: $feedurl = &Apache::lonnet::clutter($feedurl);
4715: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4716: return $userview;
1.1 albertel 4717: }
1.116 albertel 4718:
4719: =pod
4720:
4721: =item * &submlink()
4722:
1.242 albertel 4723: Inputs: $text $uname $udom $symb $target
1.116 albertel 4724:
4725: Returns: A link to grades.pm such as to see the SUBM view of a student
4726:
4727: =cut
4728:
4729: ###############################################
4730: sub submlink {
1.242 albertel 4731: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4732: if (!($uname && $udom)) {
4733: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4734: &Apache::lonnet::whichuser($symb);
1.116 albertel 4735: if (!$symb) { $symb=$cursymb; }
4736: }
1.254 matthew 4737: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4738: $symb=&escape($symb);
1.960 bisitz 4739: if ($target) { $target=" target=\"$target\""; }
4740: return
4741: '<a href="/adm/grades?command=submission'.
4742: '&symb='.$symb.
4743: '&student='.$uname.
4744: '&userdom='.$udom.'"'.
4745: $target.'>'.$text.'</a>';
1.242 albertel 4746: }
4747: ##############################################
4748:
4749: =pod
4750:
4751: =item * &pgrdlink()
4752:
4753: Inputs: $text $uname $udom $symb $target
4754:
4755: Returns: A link to grades.pm such as to see the PGRD view of a student
4756:
4757: =cut
4758:
4759: ###############################################
4760: sub pgrdlink {
4761: my $link=&submlink(@_);
4762: $link=~s/(&command=submission)/$1&showgrading=yes/;
4763: return $link;
4764: }
4765: ##############################################
4766:
4767: =pod
4768:
4769: =item * &pprmlink()
4770:
4771: Inputs: $text $uname $udom $symb $target
4772:
4773: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4774: student and a specific resource
1.242 albertel 4775:
4776: =cut
4777:
4778: ###############################################
4779: sub pprmlink {
4780: my ($text,$uname,$udom,$symb,$target)=@_;
4781: if (!($uname && $udom)) {
4782: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4783: &Apache::lonnet::whichuser($symb);
1.242 albertel 4784: if (!$symb) { $symb=$cursymb; }
4785: }
1.254 matthew 4786: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4787: $symb=&escape($symb);
1.242 albertel 4788: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4789: return '<a href="/adm/parmset?command=set&'.
4790: 'symb='.$symb.'&uname='.$uname.
4791: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4792: }
4793: ##############################################
1.37 matthew 4794:
1.112 bowersj2 4795: =pod
4796:
4797: =back
4798:
4799: =cut
4800:
1.37 matthew 4801: ###############################################
1.51 www 4802:
4803:
4804: sub timehash {
1.687 raeburn 4805: my ($thistime) = @_;
4806: my $timezone = &Apache::lonlocal::gettimezone();
4807: my $dt = DateTime->from_epoch(epoch => $thistime)
4808: ->set_time_zone($timezone);
4809: my $wday = $dt->day_of_week();
4810: if ($wday == 7) { $wday = 0; }
4811: return ( 'second' => $dt->second(),
4812: 'minute' => $dt->minute(),
4813: 'hour' => $dt->hour(),
4814: 'day' => $dt->day_of_month(),
4815: 'month' => $dt->month(),
4816: 'year' => $dt->year(),
4817: 'weekday' => $wday,
4818: 'dayyear' => $dt->day_of_year(),
4819: 'dlsav' => $dt->is_dst() );
1.51 www 4820: }
4821:
1.370 www 4822: sub utc_string {
4823: my ($date)=@_;
1.371 www 4824: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4825: }
4826:
1.51 www 4827: sub maketime {
4828: my %th=@_;
1.687 raeburn 4829: my ($epoch_time,$timezone,$dt);
4830: $timezone = &Apache::lonlocal::gettimezone();
4831: eval {
4832: $dt = DateTime->new( year => $th{'year'},
4833: month => $th{'month'},
4834: day => $th{'day'},
4835: hour => $th{'hour'},
4836: minute => $th{'minute'},
4837: second => $th{'second'},
4838: time_zone => $timezone,
4839: );
4840: };
4841: if (!$@) {
4842: $epoch_time = $dt->epoch;
4843: if ($epoch_time) {
4844: return $epoch_time;
4845: }
4846: }
1.51 www 4847: return POSIX::mktime(
4848: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4849: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4850: }
4851:
4852: #########################################
1.51 www 4853:
4854: sub findallcourses {
1.482 raeburn 4855: my ($roles,$uname,$udom) = @_;
1.355 albertel 4856: my %roles;
4857: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4858: my %courses;
1.51 www 4859: my $now=time;
1.482 raeburn 4860: if (!defined($uname)) {
4861: $uname = $env{'user.name'};
4862: }
4863: if (!defined($udom)) {
4864: $udom = $env{'user.domain'};
4865: }
4866: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4867: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4868: if (!%roles) {
4869: %roles = (
4870: cc => 1,
1.907 raeburn 4871: co => 1,
1.482 raeburn 4872: in => 1,
4873: ep => 1,
4874: ta => 1,
4875: cr => 1,
4876: st => 1,
4877: );
4878: }
4879: foreach my $entry (keys(%roleshash)) {
4880: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4881: if ($trole =~ /^cr/) {
4882: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4883: } else {
4884: next if (!exists($roles{$trole}));
4885: }
4886: if ($tend) {
4887: next if ($tend < $now);
4888: }
4889: if ($tstart) {
4890: next if ($tstart > $now);
4891: }
1.1058 raeburn 4892: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4893: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4894: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4895: if ($secpart eq '') {
4896: ($cnum,$role) = split(/_/,$cnumpart);
4897: $sec = 'none';
1.1058 raeburn 4898: $value .= $cnum.'/';
1.482 raeburn 4899: } else {
4900: $cnum = $cnumpart;
4901: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4902: $value .= $cnum.'/'.$sec;
4903: }
4904: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4905: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4906: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4907: }
4908: } else {
4909: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4910: }
1.482 raeburn 4911: }
4912: } else {
4913: foreach my $key (keys(%env)) {
1.483 albertel 4914: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4915: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4916: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4917: next if ($role eq 'ca' || $role eq 'aa');
4918: next if (%roles && !exists($roles{$role}));
4919: my ($starttime,$endtime)=split(/\./,$env{$key});
4920: my $active=1;
4921: if ($starttime) {
4922: if ($now<$starttime) { $active=0; }
4923: }
4924: if ($endtime) {
4925: if ($now>$endtime) { $active=0; }
4926: }
4927: if ($active) {
1.1058 raeburn 4928: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4929: if ($sec eq '') {
4930: $sec = 'none';
1.1058 raeburn 4931: } else {
4932: $value .= $sec;
4933: }
4934: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4935: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4936: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4937: }
4938: } else {
4939: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4940: }
1.474 raeburn 4941: }
4942: }
1.51 www 4943: }
4944: }
1.474 raeburn 4945: return %courses;
1.51 www 4946: }
1.37 matthew 4947:
1.54 www 4948: ###############################################
1.474 raeburn 4949:
4950: sub blockcheck {
1.1189 raeburn 4951: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4952:
1.1189 raeburn 4953: if (defined($udom) && defined($uname)) {
4954: # If uname and udom are for a course, check for blocks in the course.
4955: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4956: my ($startblock,$endblock,$triggerblock) =
4957: &get_blocks($setters,$activity,$udom,$uname,$url);
4958: return ($startblock,$endblock,$triggerblock);
4959: }
4960: } else {
1.490 raeburn 4961: $udom = $env{'user.domain'};
4962: $uname = $env{'user.name'};
4963: }
4964:
1.502 raeburn 4965: my $startblock = 0;
4966: my $endblock = 0;
1.1062 raeburn 4967: my $triggerblock = '';
1.482 raeburn 4968: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4969:
1.490 raeburn 4970: # If uname is for a user, and activity is course-specific, i.e.,
4971: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4972:
1.490 raeburn 4973: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1189 raeburn 4974: $activity eq 'groups' || $activity eq 'printout') &&
4975: ($env{'request.course.id'})) {
1.490 raeburn 4976: foreach my $key (keys(%live_courses)) {
4977: if ($key ne $env{'request.course.id'}) {
4978: delete($live_courses{$key});
4979: }
4980: }
4981: }
4982:
4983: my $otheruser = 0;
4984: my %own_courses;
4985: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4986: # Resource belongs to user other than current user.
4987: $otheruser = 1;
4988: # Gather courses for current user
4989: %own_courses =
4990: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4991: }
4992:
4993: # Gather active course roles - course coordinator, instructor,
4994: # exam proctor, ta, student, or custom role.
1.474 raeburn 4995:
4996: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4997: my ($cdom,$cnum);
4998: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4999: $cdom = $env{'course.'.$course.'.domain'};
5000: $cnum = $env{'course.'.$course.'.num'};
5001: } else {
1.490 raeburn 5002: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5003: }
5004: my $no_ownblock = 0;
5005: my $no_userblock = 0;
1.533 raeburn 5006: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5007: # Check if current user has 'evb' priv for this
5008: if (defined($own_courses{$course})) {
5009: foreach my $sec (keys(%{$own_courses{$course}})) {
5010: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5011: if ($sec ne 'none') {
5012: $checkrole .= '/'.$sec;
5013: }
5014: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5015: $no_ownblock = 1;
5016: last;
5017: }
5018: }
5019: }
5020: # if they have 'evb' priv and are currently not playing student
5021: next if (($no_ownblock) &&
5022: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5023: }
1.474 raeburn 5024: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5025: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5026: if ($sec ne 'none') {
1.482 raeburn 5027: $checkrole .= '/'.$sec;
1.474 raeburn 5028: }
1.490 raeburn 5029: if ($otheruser) {
5030: # Resource belongs to user other than current user.
5031: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5032: my (%allroles,%userroles);
5033: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5034: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5035: my ($trole,$tdom,$tnum,$tsec);
5036: if ($entry =~ /^cr/) {
5037: ($trole,$tdom,$tnum,$tsec) =
5038: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5039: } else {
5040: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5041: }
5042: my ($spec,$area,$trest);
5043: $area = '/'.$tdom.'/'.$tnum;
5044: $trest = $tnum;
5045: if ($tsec ne '') {
5046: $area .= '/'.$tsec;
5047: $trest .= '/'.$tsec;
5048: }
5049: $spec = $trole.'.'.$area;
5050: if ($trole =~ /^cr/) {
5051: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5052: $tdom,$spec,$trest,$area);
5053: } else {
5054: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5055: $tdom,$spec,$trest,$area);
5056: }
5057: }
5058: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
5059: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5060: if ($1) {
5061: $no_userblock = 1;
5062: last;
5063: }
1.486 raeburn 5064: }
5065: }
1.490 raeburn 5066: } else {
5067: # Resource belongs to current user
5068: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5069: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5070: $no_ownblock = 1;
5071: last;
5072: }
1.474 raeburn 5073: }
5074: }
5075: # if they have the evb priv and are currently not playing student
1.482 raeburn 5076: next if (($no_ownblock) &&
1.491 albertel 5077: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5078: next if ($no_userblock);
1.474 raeburn 5079:
1.866 kalberla 5080: # Retrieve blocking times and identity of locker for course
1.490 raeburn 5081: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 5082:
1.1062 raeburn 5083: my ($start,$end,$trigger) =
5084: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 5085: if (($start != 0) &&
5086: (($startblock == 0) || ($startblock > $start))) {
5087: $startblock = $start;
1.1062 raeburn 5088: if ($trigger ne '') {
5089: $triggerblock = $trigger;
5090: }
1.502 raeburn 5091: }
5092: if (($end != 0) &&
5093: (($endblock == 0) || ($endblock < $end))) {
5094: $endblock = $end;
1.1062 raeburn 5095: if ($trigger ne '') {
5096: $triggerblock = $trigger;
5097: }
1.502 raeburn 5098: }
1.490 raeburn 5099: }
1.1062 raeburn 5100: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5101: }
5102:
5103: sub get_blocks {
1.1062 raeburn 5104: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 5105: my $startblock = 0;
5106: my $endblock = 0;
1.1062 raeburn 5107: my $triggerblock = '';
1.490 raeburn 5108: my $course = $cdom.'_'.$cnum;
5109: $setters->{$course} = {};
5110: $setters->{$course}{'staff'} = [];
5111: $setters->{$course}{'times'} = [];
1.1062 raeburn 5112: $setters->{$course}{'triggers'} = [];
5113: my (@blockers,%triggered);
5114: my $now = time;
5115: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5116: if ($activity eq 'docs') {
5117: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
5118: foreach my $block (@blockers) {
5119: if ($block =~ /^firstaccess____(.+)$/) {
5120: my $item = $1;
5121: my $type = 'map';
5122: my $timersymb = $item;
5123: if ($item eq 'course') {
5124: $type = 'course';
5125: } elsif ($item =~ /___\d+___/) {
5126: $type = 'resource';
5127: } else {
5128: $timersymb = &Apache::lonnet::symbread($item);
5129: }
5130: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5131: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5132: $triggered{$block} = {
5133: start => $start,
5134: end => $end,
5135: type => $type,
5136: };
5137: }
5138: }
5139: } else {
5140: foreach my $block (keys(%commblocks)) {
5141: if ($block =~ m/^(\d+)____(\d+)$/) {
5142: my ($start,$end) = ($1,$2);
5143: if ($start <= time && $end >= time) {
5144: if (ref($commblocks{$block}) eq 'HASH') {
5145: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5146: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5147: unless(grep(/^\Q$block\E$/,@blockers)) {
5148: push(@blockers,$block);
5149: }
5150: }
5151: }
5152: }
5153: }
5154: } elsif ($block =~ /^firstaccess____(.+)$/) {
5155: my $item = $1;
5156: my $timersymb = $item;
5157: my $type = 'map';
5158: if ($item eq 'course') {
5159: $type = 'course';
5160: } elsif ($item =~ /___\d+___/) {
5161: $type = 'resource';
5162: } else {
5163: $timersymb = &Apache::lonnet::symbread($item);
5164: }
5165: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5166: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5167: if ($start && $end) {
5168: if (($start <= time) && ($end >= time)) {
5169: unless (grep(/^\Q$block\E$/,@blockers)) {
5170: push(@blockers,$block);
5171: $triggered{$block} = {
5172: start => $start,
5173: end => $end,
5174: type => $type,
5175: };
5176: }
5177: }
1.490 raeburn 5178: }
1.1062 raeburn 5179: }
5180: }
5181: }
5182: foreach my $blocker (@blockers) {
5183: my ($staff_name,$staff_dom,$title,$blocks) =
5184: &parse_block_record($commblocks{$blocker});
5185: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5186: my ($start,$end,$triggertype);
5187: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5188: ($start,$end) = ($1,$2);
5189: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5190: $start = $triggered{$blocker}{'start'};
5191: $end = $triggered{$blocker}{'end'};
5192: $triggertype = $triggered{$blocker}{'type'};
5193: }
5194: if ($start) {
5195: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5196: if ($triggertype) {
5197: push(@{$$setters{$course}{'triggers'}},$triggertype);
5198: } else {
5199: push(@{$$setters{$course}{'triggers'}},0);
5200: }
5201: if ( ($startblock == 0) || ($startblock > $start) ) {
5202: $startblock = $start;
5203: if ($triggertype) {
5204: $triggerblock = $blocker;
1.474 raeburn 5205: }
5206: }
1.1062 raeburn 5207: if ( ($endblock == 0) || ($endblock < $end) ) {
5208: $endblock = $end;
5209: if ($triggertype) {
5210: $triggerblock = $blocker;
5211: }
5212: }
1.474 raeburn 5213: }
5214: }
1.1062 raeburn 5215: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5216: }
5217:
5218: sub parse_block_record {
5219: my ($record) = @_;
5220: my ($setuname,$setudom,$title,$blocks);
5221: if (ref($record) eq 'HASH') {
5222: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5223: $title = &unescape($record->{'event'});
5224: $blocks = $record->{'blocks'};
5225: } else {
5226: my @data = split(/:/,$record,3);
5227: if (scalar(@data) eq 2) {
5228: $title = $data[1];
5229: ($setuname,$setudom) = split(/@/,$data[0]);
5230: } else {
5231: ($setuname,$setudom,$title) = @data;
5232: }
5233: $blocks = { 'com' => 'on' };
5234: }
5235: return ($setuname,$setudom,$title,$blocks);
5236: }
5237:
1.854 kalberla 5238: sub blocking_status {
1.1189 raeburn 5239: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 5240: my %setters;
1.890 droeschl 5241:
1.1061 raeburn 5242: # check for active blocking
1.1062 raeburn 5243: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 5244: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 5245: my $blocked = 0;
5246: if ($startblock && $endblock) {
5247: $blocked = 1;
5248: }
1.890 droeschl 5249:
1.1061 raeburn 5250: # caller just wants to know whether a block is active
5251: if (!wantarray) { return $blocked; }
5252:
5253: # build a link to a popup window containing the details
5254: my $querystring = "?activity=$activity";
5255: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 raeburn 5256: if (($activity eq 'port') || ($activity eq 'passwd')) {
5257: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5258: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5259: } elsif ($activity eq 'docs') {
5260: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
5261: }
1.1061 raeburn 5262:
5263: my $output .= <<'END_MYBLOCK';
5264: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5265: var options = "width=" + w + ",height=" + h + ",";
5266: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5267: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5268: var newWin = window.open(url, wdwName, options);
5269: newWin.focus();
5270: }
1.890 droeschl 5271: END_MYBLOCK
1.854 kalberla 5272:
1.1061 raeburn 5273: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5274:
1.1061 raeburn 5275: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5276: my $text = &mt('Communication Blocked');
1.1217 raeburn 5277: my $class = 'LC_comblock';
1.1062 raeburn 5278: if ($activity eq 'docs') {
5279: $text = &mt('Content Access Blocked');
1.1217 raeburn 5280: $class = '';
1.1063 raeburn 5281: } elsif ($activity eq 'printout') {
5282: $text = &mt('Printing Blocked');
1.1232 raeburn 5283: } elsif ($activity eq 'passwd') {
5284: $text = &mt('Password Changing Blocked');
1.1062 raeburn 5285: }
1.1061 raeburn 5286: $output .= <<"END_BLOCK";
1.1217 raeburn 5287: <div class='$class'>
1.869 kalberla 5288: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5289: title='$text'>
5290: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5291: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5292: title='$text'>$text</a>
1.867 kalberla 5293: </div>
5294:
5295: END_BLOCK
1.474 raeburn 5296:
1.1061 raeburn 5297: return ($blocked, $output);
1.854 kalberla 5298: }
1.490 raeburn 5299:
1.60 matthew 5300: ###############################################
5301:
1.682 raeburn 5302: sub check_ip_acc {
1.1201 raeburn 5303: my ($acc,$clientip)=@_;
1.682 raeburn 5304: &Apache::lonxml::debug("acc is $acc");
5305: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5306: return 1;
5307: }
1.1219 raeburn 5308: my $allowed;
1.1201 raeburn 5309: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
1.682 raeburn 5310:
5311: my $name;
1.1219 raeburn 5312: my %access = (
5313: allowfrom => 1,
5314: denyfrom => 0,
5315: );
5316: my @allows;
5317: my @denies;
5318: foreach my $item (split(',',$acc)) {
5319: $item =~ s/^\s*//;
5320: $item =~ s/\s*$//;
5321: my $pattern;
5322: if ($item =~ /^\!(.+)$/) {
5323: push(@denies,$1);
5324: } else {
5325: push(@allows,$item);
5326: }
5327: }
5328: my $numdenies = scalar(@denies);
5329: my $numallows = scalar(@allows);
5330: my $count = 0;
5331: foreach my $pattern (@denies,@allows) {
5332: $count ++;
5333: my $acctype = 'allowfrom';
5334: if ($count <= $numdenies) {
5335: $acctype = 'denyfrom';
5336: }
1.682 raeburn 5337: if ($pattern =~ /\*$/) {
5338: #35.8.*
5339: $pattern=~s/\*//;
1.1219 raeburn 5340: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5341: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5342: #35.8.3.[34-56]
5343: my $low=$2;
5344: my $high=$3;
5345: $pattern=$1;
5346: if ($ip =~ /^\Q$pattern\E/) {
5347: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5348: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5349: }
5350: } elsif ($pattern =~ /^\*/) {
5351: #*.msu.edu
5352: $pattern=~s/\*//;
5353: if (!defined($name)) {
5354: use Socket;
5355: my $netaddr=inet_aton($ip);
5356: ($name)=gethostbyaddr($netaddr,AF_INET);
5357: }
1.1219 raeburn 5358: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5359: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5360: #127.0.0.1
1.1219 raeburn 5361: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5362: } else {
5363: #some.name.com
5364: if (!defined($name)) {
5365: use Socket;
5366: my $netaddr=inet_aton($ip);
5367: ($name)=gethostbyaddr($netaddr,AF_INET);
5368: }
1.1219 raeburn 5369: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5370: }
5371: if ($allowed =~ /^(0|1)$/) { last; }
5372: }
5373: if ($allowed eq '') {
5374: if ($numdenies && !$numallows) {
5375: $allowed = 1;
5376: } else {
5377: $allowed = 0;
1.682 raeburn 5378: }
5379: }
5380: return $allowed;
5381: }
5382:
5383: ###############################################
5384:
1.60 matthew 5385: =pod
5386:
1.112 bowersj2 5387: =head1 Domain Template Functions
5388:
5389: =over 4
5390:
5391: =item * &determinedomain()
1.60 matthew 5392:
5393: Inputs: $domain (usually will be undef)
5394:
1.63 www 5395: Returns: Determines which domain should be used for designs
1.60 matthew 5396:
5397: =cut
1.54 www 5398:
1.60 matthew 5399: ###############################################
1.63 www 5400: sub determinedomain {
5401: my $domain=shift;
1.531 albertel 5402: if (! $domain) {
1.60 matthew 5403: # Determine domain if we have not been given one
1.893 raeburn 5404: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5405: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5406: if ($env{'request.role.domain'}) {
5407: $domain=$env{'request.role.domain'};
1.60 matthew 5408: }
5409: }
1.63 www 5410: return $domain;
5411: }
5412: ###############################################
1.517 raeburn 5413:
1.518 albertel 5414: sub devalidate_domconfig_cache {
5415: my ($udom)=@_;
5416: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5417: }
5418:
5419: # ---------------------- Get domain configuration for a domain
5420: sub get_domainconf {
5421: my ($udom) = @_;
5422: my $cachetime=1800;
5423: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5424: if (defined($cached)) { return %{$result}; }
5425:
5426: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5427: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5428: my (%designhash,%legacy);
1.518 albertel 5429: if (keys(%domconfig) > 0) {
5430: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5431: if (keys(%{$domconfig{'login'}})) {
5432: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5433: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5434: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5435: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5436: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5437: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5438: if ($key eq 'loginvia') {
5439: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5440: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5441: $designhash{$udom.'.login.loginvia'} = $server;
5442: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5443:
5444: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5445: } else {
5446: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5447: }
1.948 raeburn 5448: }
1.1208 raeburn 5449: } elsif ($key eq 'headtag') {
5450: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5451: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5452: }
1.946 raeburn 5453: }
1.1208 raeburn 5454: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5455: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5456: }
1.946 raeburn 5457: }
5458: }
5459: }
5460: } else {
5461: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5462: $designhash{$udom.'.login.'.$key.'_'.$img} =
5463: $domconfig{'login'}{$key}{$img};
5464: }
1.699 raeburn 5465: }
5466: } else {
5467: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5468: }
1.632 raeburn 5469: }
5470: } else {
5471: $legacy{'login'} = 1;
1.518 albertel 5472: }
1.632 raeburn 5473: } else {
5474: $legacy{'login'} = 1;
1.518 albertel 5475: }
5476: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5477: if (keys(%{$domconfig{'rolecolors'}})) {
5478: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5479: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5480: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5481: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5482: }
1.518 albertel 5483: }
5484: }
1.632 raeburn 5485: } else {
5486: $legacy{'rolecolors'} = 1;
1.518 albertel 5487: }
1.632 raeburn 5488: } else {
5489: $legacy{'rolecolors'} = 1;
1.518 albertel 5490: }
1.948 raeburn 5491: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5492: if ($domconfig{'autoenroll'}{'co-owners'}) {
5493: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5494: }
5495: }
1.632 raeburn 5496: if (keys(%legacy) > 0) {
5497: my %legacyhash = &get_legacy_domconf($udom);
5498: foreach my $item (keys(%legacyhash)) {
5499: if ($item =~ /^\Q$udom\E\.login/) {
5500: if ($legacy{'login'}) {
5501: $designhash{$item} = $legacyhash{$item};
5502: }
5503: } else {
5504: if ($legacy{'rolecolors'}) {
5505: $designhash{$item} = $legacyhash{$item};
5506: }
1.518 albertel 5507: }
5508: }
5509: }
1.632 raeburn 5510: } else {
5511: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5512: }
5513: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5514: $cachetime);
5515: return %designhash;
5516: }
5517:
1.632 raeburn 5518: sub get_legacy_domconf {
5519: my ($udom) = @_;
5520: my %legacyhash;
5521: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5522: my $designfile = $designdir.'/'.$udom.'.tab';
5523: if (-e $designfile) {
5524: if ( open (my $fh,"<$designfile") ) {
5525: while (my $line = <$fh>) {
5526: next if ($line =~ /^\#/);
5527: chomp($line);
5528: my ($key,$val)=(split(/\=/,$line));
5529: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5530: }
5531: close($fh);
5532: }
5533: }
1.1026 raeburn 5534: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5535: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5536: }
5537: return %legacyhash;
5538: }
5539:
1.63 www 5540: =pod
5541:
1.112 bowersj2 5542: =item * &domainlogo()
1.63 www 5543:
5544: Inputs: $domain (usually will be undef)
5545:
5546: Returns: A link to a domain logo, if the domain logo exists.
5547: If the domain logo does not exist, a description of the domain.
5548:
5549: =cut
1.112 bowersj2 5550:
1.63 www 5551: ###############################################
5552: sub domainlogo {
1.517 raeburn 5553: my $domain = &determinedomain(shift);
1.518 albertel 5554: my %designhash = &get_domainconf($domain);
1.517 raeburn 5555: # See if there is a logo
5556: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5557: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5558: if ($imgsrc =~ m{^/(adm|res)/}) {
5559: if ($imgsrc =~ m{^/res/}) {
5560: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5561: &Apache::lonnet::repcopy($local_name);
5562: }
5563: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5564: }
5565: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5566: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5567: return &Apache::lonnet::domain($domain,'description');
1.59 www 5568: } else {
1.60 matthew 5569: return '';
1.59 www 5570: }
5571: }
1.63 www 5572: ##############################################
5573:
5574: =pod
5575:
1.112 bowersj2 5576: =item * &designparm()
1.63 www 5577:
5578: Inputs: $which parameter; $domain (usually will be undef)
5579:
5580: Returns: value of designparamter $which
5581:
5582: =cut
1.112 bowersj2 5583:
1.397 albertel 5584:
1.400 albertel 5585: ##############################################
1.397 albertel 5586: sub designparm {
5587: my ($which,$domain)=@_;
5588: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5589: return $env{'environment.color.'.$which};
1.96 www 5590: }
1.63 www 5591: $domain=&determinedomain($domain);
1.1016 raeburn 5592: my %domdesign;
5593: unless ($domain eq 'public') {
5594: %domdesign = &get_domainconf($domain);
5595: }
1.520 raeburn 5596: my $output;
1.517 raeburn 5597: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5598: $output = $domdesign{$domain.'.'.$which};
1.63 www 5599: } else {
1.520 raeburn 5600: $output = $defaultdesign{$which};
5601: }
5602: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5603: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5604: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5605: if ($output =~ m{^/res/}) {
5606: my $local_name = &Apache::lonnet::filelocation('',$output);
5607: &Apache::lonnet::repcopy($local_name);
5608: }
1.520 raeburn 5609: $output = &lonhttpdurl($output);
5610: }
1.63 www 5611: }
1.520 raeburn 5612: return $output;
1.63 www 5613: }
1.59 www 5614:
1.822 bisitz 5615: ##############################################
5616: =pod
5617:
1.832 bisitz 5618: =item * &authorspace()
5619:
1.1028 raeburn 5620: Inputs: $url (usually will be undef).
1.832 bisitz 5621:
1.1132 raeburn 5622: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5623: directory being viewed (or for which action is being taken).
5624: If $url is provided, and begins /priv/<domain>/<uname>
5625: the path will be that portion of the $context argument.
5626: Otherwise the path will be for the author space of the current
5627: user when the current role is author, or for that of the
5628: co-author/assistant co-author space when the current role
5629: is co-author or assistant co-author.
1.832 bisitz 5630:
5631: =cut
5632:
5633: sub authorspace {
1.1028 raeburn 5634: my ($url) = @_;
5635: if ($url ne '') {
5636: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5637: return $1;
5638: }
5639: }
1.832 bisitz 5640: my $caname = '';
1.1024 www 5641: my $cadom = '';
1.1028 raeburn 5642: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5643: ($cadom,$caname) =
1.832 bisitz 5644: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5645: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5646: $caname = $env{'user.name'};
1.1024 www 5647: $cadom = $env{'user.domain'};
1.832 bisitz 5648: }
1.1028 raeburn 5649: if (($caname ne '') && ($cadom ne '')) {
5650: return "/priv/$cadom/$caname/";
5651: }
5652: return;
1.832 bisitz 5653: }
5654:
5655: ##############################################
5656: =pod
5657:
1.822 bisitz 5658: =item * &head_subbox()
5659:
5660: Inputs: $content (contains HTML code with page functions, etc.)
5661:
5662: Returns: HTML div with $content
5663: To be included in page header
5664:
5665: =cut
5666:
5667: sub head_subbox {
5668: my ($content)=@_;
5669: my $output =
1.993 raeburn 5670: '<div class="LC_head_subbox">'
1.822 bisitz 5671: .$content
5672: .'</div>'
5673: }
5674:
5675: ##############################################
5676: =pod
5677:
5678: =item * &CSTR_pageheader()
5679:
1.1026 raeburn 5680: Input: (optional) filename from which breadcrumb trail is built.
5681: In most cases no input as needed, as $env{'request.filename'}
5682: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5683:
5684: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5685: To be included on Authoring Space pages
1.822 bisitz 5686:
5687: =cut
5688:
5689: sub CSTR_pageheader {
1.1026 raeburn 5690: my ($trailfile) = @_;
5691: if ($trailfile eq '') {
5692: $trailfile = $env{'request.filename'};
5693: }
5694:
5695: # this is for resources; directories have customtitle, and crumbs
5696: # and select recent are created in lonpubdir.pm
5697:
5698: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5699: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5700: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5701: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5702: $formaction =~ s{/+}{/}g;
1.822 bisitz 5703:
5704: my $parentpath = '';
5705: my $lastitem = '';
5706: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5707: $parentpath = $1;
5708: $lastitem = $2;
5709: } else {
5710: $lastitem = $thisdisfn;
5711: }
1.921 bisitz 5712:
1.1246 raeburn 5713: my ($crsauthor,$title);
5714: if (($env{'request.course.id'}) &&
5715: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 5716: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 5717: $crsauthor = 1;
5718: $title = &mt('Course Authoring Space');
5719: } else {
5720: $title = &mt('Authoring Space');
5721: }
5722:
1.921 bisitz 5723: my $output =
1.822 bisitz 5724: '<div>'
5725: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 5726: .'<b>'.$title.'</b> '
1.822 bisitz 5727: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5728: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5729: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5730:
5731: if ($lastitem) {
5732: $output .=
5733: '<span class="LC_filename">'
5734: .$lastitem
5735: .'</span>';
5736: }
1.1245 raeburn 5737:
1.1246 raeburn 5738: if ($crsauthor) {
5739: $output .= '</form>'.&Apache::lonmenu::constspaceform();
5740: } else {
5741: $output .=
5742: '<br />'
5743: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5744: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5745: .'</form>'
5746: .&Apache::lonmenu::constspaceform();
5747: }
5748: $output .= '</div>';
1.921 bisitz 5749:
5750: return $output;
1.822 bisitz 5751: }
5752:
1.60 matthew 5753: ###############################################
5754: ###############################################
5755:
5756: =pod
5757:
1.112 bowersj2 5758: =back
5759:
1.549 albertel 5760: =head1 HTML Helpers
1.112 bowersj2 5761:
5762: =over 4
5763:
5764: =item * &bodytag()
1.60 matthew 5765:
5766: Returns a uniform header for LON-CAPA web pages.
5767:
5768: Inputs:
5769:
1.112 bowersj2 5770: =over 4
5771:
5772: =item * $title, A title to be displayed on the page.
5773:
5774: =item * $function, the current role (can be undef).
5775:
5776: =item * $addentries, extra parameters for the <body> tag.
5777:
5778: =item * $bodyonly, if defined, only return the <body> tag.
5779:
5780: =item * $domain, if defined, force a given domain.
5781:
5782: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5783: text interface only)
1.60 matthew 5784:
1.814 bisitz 5785: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5786: navigational links
1.317 albertel 5787:
1.338 albertel 5788: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5789:
1.460 albertel 5790: =item * $args, optional argument valid values are
5791: no_auto_mt_title -> prevents &mt()ing the title arg
5792:
1.1096 raeburn 5793: =item * $advtoolsref, optional argument, ref to an array containing
5794: inlineremote items to be added in "Functions" menu below
5795: breadcrumbs.
5796:
1.112 bowersj2 5797: =back
5798:
1.60 matthew 5799: Returns: A uniform header for LON-CAPA web pages.
5800: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5801: If $bodyonly is undef or zero, an html string containing a <body> tag and
5802: other decorations will be returned.
5803:
5804: =cut
5805:
1.54 www 5806: sub bodytag {
1.831 bisitz 5807: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5808: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5809:
1.954 raeburn 5810: my $public;
5811: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5812: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5813: $public = 1;
5814: }
1.460 albertel 5815: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5816: my $httphost = $args->{'use_absolute'};
1.339 albertel 5817:
1.183 matthew 5818: $function = &get_users_function() if (!$function);
1.339 albertel 5819: my $img = &designparm($function.'.img',$domain);
5820: my $font = &designparm($function.'.font',$domain);
5821: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5822:
1.803 bisitz 5823: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5824: 'bgcolor' => $pgbg,
1.339 albertel 5825: 'text' => $font,
5826: 'alink' => &designparm($function.'.alink',$domain),
5827: 'vlink' => &designparm($function.'.vlink',$domain),
5828: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5829: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5830:
1.63 www 5831: # role and realm
1.1178 raeburn 5832: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5833: if ($realm) {
5834: $realm = '/'.$realm;
5835: }
1.378 raeburn 5836: if ($role eq 'ca') {
1.479 albertel 5837: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5838: $realm = &plainname($rname,$rdom);
1.378 raeburn 5839: }
1.55 www 5840: # realm
1.258 albertel 5841: if ($env{'request.course.id'}) {
1.378 raeburn 5842: if ($env{'request.role'} !~ /^cr/) {
5843: $role = &Apache::lonnet::plaintext($role,&course_type());
5844: }
1.898 raeburn 5845: if ($env{'request.course.sec'}) {
5846: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5847: }
1.359 albertel 5848: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5849: } else {
5850: $role = &Apache::lonnet::plaintext($role);
1.54 www 5851: }
1.433 albertel 5852:
1.359 albertel 5853: if (!$realm) { $realm=' '; }
1.330 albertel 5854:
1.438 albertel 5855: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5856:
1.101 www 5857: # construct main body tag
1.359 albertel 5858: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 5859: &Apache::lontexconvert::init_math_support();
1.252 albertel 5860:
1.1131 raeburn 5861: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5862:
1.1130 raeburn 5863: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5864: return $bodytag;
1.1130 raeburn 5865: }
1.359 albertel 5866:
1.954 raeburn 5867: if ($public) {
1.433 albertel 5868: undef($role);
5869: }
1.359 albertel 5870:
1.762 bisitz 5871: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5872: #
5873: # Extra info if you are the DC
5874: my $dc_info = '';
5875: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5876: $env{'course.'.$env{'request.course.id'}.
5877: '.domain'}.'/'})) {
5878: my $cid = $env{'request.course.id'};
1.917 raeburn 5879: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5880: $dc_info =~ s/\s+$//;
1.359 albertel 5881: }
5882:
1.1237 raeburn 5883: my $crstype;
5884: if ($env{'request.course.id'}) {
5885: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
5886: } elsif ($args->{'crstype'}) {
5887: $crstype = $args->{'crstype'};
5888: }
5889: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
5890: undef($role);
5891: } else {
1.1242 raeburn 5892: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 5893: }
1.853 droeschl 5894:
1.903 droeschl 5895: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5896:
5897: # if ($env{'request.state'} eq 'construct') {
5898: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5899: # }
5900:
1.1130 raeburn 5901: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 5902: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5903:
1.1237 raeburn 5904: my ($left,$right) = Apache::lonmenu::primary_menu($crstype);
1.359 albertel 5905:
1.916 droeschl 5906: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5907: if ($dc_info) {
5908: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5909: }
1.1130 raeburn 5910: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5911: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5912: return $bodytag;
5913: }
1.894 droeschl 5914:
1.927 raeburn 5915: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5916: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5917: }
1.916 droeschl 5918:
1.1130 raeburn 5919: $bodytag .= $right;
1.852 droeschl 5920:
1.917 raeburn 5921: if ($dc_info) {
5922: $dc_info = &dc_courseid_toggle($dc_info);
5923: }
5924: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5925:
1.1169 raeburn 5926: #if directed to not display the secondary menu, don't.
1.1168 raeburn 5927: if ($args->{'no_secondary_menu'}) {
5928: return $bodytag;
5929: }
1.1169 raeburn 5930: #don't show menus for public users
1.954 raeburn 5931: if (!$public){
1.1154 raeburn 5932: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5933: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5934: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5935: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5936: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5937: $args->{'bread_crumbs'});
1.1096 raeburn 5938: } elsif ($forcereg) {
5939: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5940: $args->{'group'});
5941: } else {
5942: $bodytag .=
5943: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5944: $forcereg,$args->{'group'},
5945: $args->{'bread_crumbs'},
5946: $advtoolsref);
1.920 raeburn 5947: }
1.903 droeschl 5948: }else{
5949: # this is to seperate menu from content when there's no secondary
5950: # menu. Especially needed for public accessible ressources.
5951: $bodytag .= '<hr style="clear:both" />';
5952: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5953: }
1.903 droeschl 5954:
1.235 raeburn 5955: return $bodytag;
1.182 matthew 5956: }
5957:
1.917 raeburn 5958: sub dc_courseid_toggle {
5959: my ($dc_info) = @_;
1.980 raeburn 5960: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5961: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5962: &mt('(More ...)').'</a></span>'.
5963: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5964: }
5965:
1.330 albertel 5966: sub make_attr_string {
5967: my ($register,$attr_ref) = @_;
5968:
5969: if ($attr_ref && !ref($attr_ref)) {
5970: die("addentries Must be a hash ref ".
5971: join(':',caller(1))." ".
5972: join(':',caller(0))." ");
5973: }
5974:
5975: if ($register) {
1.339 albertel 5976: my ($on_load,$on_unload);
5977: foreach my $key (keys(%{$attr_ref})) {
5978: if (lc($key) eq 'onload') {
5979: $on_load.=$attr_ref->{$key}.';';
5980: delete($attr_ref->{$key});
5981:
5982: } elsif (lc($key) eq 'onunload') {
5983: $on_unload.=$attr_ref->{$key}.';';
5984: delete($attr_ref->{$key});
5985: }
5986: }
1.953 droeschl 5987: $attr_ref->{'onload'} = $on_load;
5988: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5989: }
1.339 albertel 5990:
1.330 albertel 5991: my $attr_string;
1.1159 raeburn 5992: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5993: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5994: }
5995: return $attr_string;
5996: }
5997:
5998:
1.182 matthew 5999: ###############################################
1.251 albertel 6000: ###############################################
6001:
6002: =pod
6003:
6004: =item * &endbodytag()
6005:
6006: Returns a uniform footer for LON-CAPA web pages.
6007:
1.635 raeburn 6008: Inputs: 1 - optional reference to an args hash
6009: If in the hash, key for noredirectlink has a value which evaluates to true,
6010: a 'Continue' link is not displayed if the page contains an
6011: internal redirect in the <head></head> section,
6012: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6013:
6014: =cut
6015:
6016: sub endbodytag {
1.635 raeburn 6017: my ($args) = @_;
1.1080 raeburn 6018: my $endbodytag;
6019: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6020: $endbodytag='</body>';
6021: }
1.315 albertel 6022: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6023: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6024: $endbodytag=
6025: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6026: &mt('Continue').'</a>'.
6027: $endbodytag;
6028: }
1.315 albertel 6029: }
1.251 albertel 6030: return $endbodytag;
6031: }
6032:
1.352 albertel 6033: =pod
6034:
6035: =item * &standard_css()
6036:
6037: Returns a style sheet
6038:
6039: Inputs: (all optional)
6040: domain -> force to color decorate a page for a specific
6041: domain
6042: function -> force usage of a specific rolish color scheme
6043: bgcolor -> override the default page bgcolor
6044:
6045: =cut
6046:
1.343 albertel 6047: sub standard_css {
1.345 albertel 6048: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6049: $function = &get_users_function() if (!$function);
6050: my $img = &designparm($function.'.img', $domain);
6051: my $tabbg = &designparm($function.'.tabbg', $domain);
6052: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6053: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6054: #second colour for later usage
1.345 albertel 6055: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6056: my $pgbg_or_bgcolor =
6057: $bgcolor ||
1.352 albertel 6058: &designparm($function.'.pgbg', $domain);
1.382 albertel 6059: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6060: my $alink = &designparm($function.'.alink', $domain);
6061: my $vlink = &designparm($function.'.vlink', $domain);
6062: my $link = &designparm($function.'.link', $domain);
6063:
1.602 albertel 6064: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6065: my $mono = 'monospace';
1.850 bisitz 6066: my $data_table_head = $sidebg;
6067: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6068: my $data_table_dark = '#E0E0E0';
1.470 banghart 6069: my $data_table_darker = '#CCCCCC';
1.349 albertel 6070: my $data_table_highlight = '#FFFF00';
1.352 albertel 6071: my $mail_new = '#FFBB77';
6072: my $mail_new_hover = '#DD9955';
6073: my $mail_read = '#BBBB77';
6074: my $mail_read_hover = '#999944';
6075: my $mail_replied = '#AAAA88';
6076: my $mail_replied_hover = '#888855';
6077: my $mail_other = '#99BBBB';
6078: my $mail_other_hover = '#669999';
1.391 albertel 6079: my $table_header = '#DDDDDD';
1.489 raeburn 6080: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6081: my $lg_border_color = '#C8C8C8';
1.952 onken 6082: my $button_hover = '#BF2317';
1.392 albertel 6083:
1.608 albertel 6084: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6085: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6086: : '0 3px 0 4px';
1.448 albertel 6087:
1.523 albertel 6088:
1.343 albertel 6089: return <<END;
1.947 droeschl 6090:
6091: /* needed for iframe to allow 100% height in FF */
6092: body, html {
6093: margin: 0;
6094: padding: 0 0.5%;
6095: height: 99%; /* to avoid scrollbars */
6096: }
6097:
1.795 www 6098: body {
1.911 bisitz 6099: font-family: $sans;
6100: line-height:130%;
6101: font-size:0.83em;
6102: color:$font;
1.795 www 6103: }
6104:
1.959 onken 6105: a:focus,
6106: a:focus img {
1.795 www 6107: color: red;
6108: }
1.698 harmsja 6109:
1.911 bisitz 6110: form, .inline {
6111: display: inline;
1.795 www 6112: }
1.721 harmsja 6113:
1.795 www 6114: .LC_right {
1.911 bisitz 6115: text-align:right;
1.795 www 6116: }
6117:
6118: .LC_middle {
1.911 bisitz 6119: vertical-align:middle;
1.795 www 6120: }
1.721 harmsja 6121:
1.1130 raeburn 6122: .LC_floatleft {
6123: float: left;
6124: }
6125:
6126: .LC_floatright {
6127: float: right;
6128: }
6129:
1.911 bisitz 6130: .LC_400Box {
6131: width:400px;
6132: }
1.721 harmsja 6133:
1.947 droeschl 6134: .LC_iframecontainer {
6135: width: 98%;
6136: margin: 0;
6137: position: fixed;
6138: top: 8.5em;
6139: bottom: 0;
6140: }
6141:
6142: .LC_iframecontainer iframe{
6143: border: none;
6144: width: 100%;
6145: height: 100%;
6146: }
6147:
1.778 bisitz 6148: .LC_filename {
6149: font-family: $mono;
6150: white-space:pre;
1.921 bisitz 6151: font-size: 120%;
1.778 bisitz 6152: }
6153:
6154: .LC_fileicon {
6155: border: none;
6156: height: 1.3em;
6157: vertical-align: text-bottom;
6158: margin-right: 0.3em;
6159: text-decoration:none;
6160: }
6161:
1.1008 www 6162: .LC_setting {
6163: text-decoration:underline;
6164: }
6165:
1.350 albertel 6166: .LC_error {
6167: color: red;
6168: }
1.795 www 6169:
1.1097 bisitz 6170: .LC_warning {
6171: color: darkorange;
6172: }
6173:
1.457 albertel 6174: .LC_diff_removed {
1.733 bisitz 6175: color: red;
1.394 albertel 6176: }
1.532 albertel 6177:
6178: .LC_info,
1.457 albertel 6179: .LC_success,
6180: .LC_diff_added {
1.350 albertel 6181: color: green;
6182: }
1.795 www 6183:
1.802 bisitz 6184: div.LC_confirm_box {
6185: background-color: #FAFAFA;
6186: border: 1px solid $lg_border_color;
6187: margin-right: 0;
6188: padding: 5px;
6189: }
6190:
6191: div.LC_confirm_box .LC_error img,
6192: div.LC_confirm_box .LC_success img {
6193: vertical-align: middle;
6194: }
6195:
1.1242 raeburn 6196: .LC_maxwidth {
6197: max-width: 100%;
6198: height: auto;
6199: }
6200:
1.1243 raeburn 6201: .LC_textsize_mobile {
6202: \@media only screen and (max-device-width: 480px) {
6203: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6204: }
6205: }
6206:
1.440 albertel 6207: .LC_icon {
1.771 droeschl 6208: border: none;
1.790 droeschl 6209: vertical-align: middle;
1.771 droeschl 6210: }
6211:
1.543 albertel 6212: .LC_docs_spacer {
6213: width: 25px;
6214: height: 1px;
1.771 droeschl 6215: border: none;
1.543 albertel 6216: }
1.346 albertel 6217:
1.532 albertel 6218: .LC_internal_info {
1.735 bisitz 6219: color: #999999;
1.532 albertel 6220: }
6221:
1.794 www 6222: .LC_discussion {
1.1050 www 6223: background: $data_table_dark;
1.911 bisitz 6224: border: 1px solid black;
6225: margin: 2px;
1.794 www 6226: }
6227:
6228: .LC_disc_action_left {
1.1050 www 6229: background: $sidebg;
1.911 bisitz 6230: text-align: left;
1.1050 www 6231: padding: 4px;
6232: margin: 2px;
1.794 www 6233: }
6234:
6235: .LC_disc_action_right {
1.1050 www 6236: background: $sidebg;
1.911 bisitz 6237: text-align: right;
1.1050 www 6238: padding: 4px;
6239: margin: 2px;
1.794 www 6240: }
6241:
6242: .LC_disc_new_item {
1.911 bisitz 6243: background: white;
6244: border: 2px solid red;
1.1050 www 6245: margin: 4px;
6246: padding: 4px;
1.794 www 6247: }
6248:
6249: .LC_disc_old_item {
1.911 bisitz 6250: background: white;
1.1050 www 6251: margin: 4px;
6252: padding: 4px;
1.794 www 6253: }
6254:
1.458 albertel 6255: table.LC_pastsubmission {
6256: border: 1px solid black;
6257: margin: 2px;
6258: }
6259:
1.924 bisitz 6260: table#LC_menubuttons {
1.345 albertel 6261: width: 100%;
6262: background: $pgbg;
1.392 albertel 6263: border: 2px;
1.402 albertel 6264: border-collapse: separate;
1.803 bisitz 6265: padding: 0;
1.345 albertel 6266: }
1.392 albertel 6267:
1.801 tempelho 6268: table#LC_title_bar a {
6269: color: $fontmenu;
6270: }
1.836 bisitz 6271:
1.807 droeschl 6272: table#LC_title_bar {
1.819 tempelho 6273: clear: both;
1.836 bisitz 6274: display: none;
1.807 droeschl 6275: }
6276:
1.795 www 6277: table#LC_title_bar,
1.933 droeschl 6278: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6279: table#LC_title_bar.LC_with_remote {
1.359 albertel 6280: width: 100%;
1.392 albertel 6281: border-color: $pgbg;
6282: border-style: solid;
6283: border-width: $border;
1.379 albertel 6284: background: $pgbg;
1.801 tempelho 6285: color: $fontmenu;
1.392 albertel 6286: border-collapse: collapse;
1.803 bisitz 6287: padding: 0;
1.819 tempelho 6288: margin: 0;
1.359 albertel 6289: }
1.795 www 6290:
1.933 droeschl 6291: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6292: margin: 0;
6293: padding: 0;
1.933 droeschl 6294: position: relative;
6295: list-style: none;
1.913 droeschl 6296: }
1.933 droeschl 6297: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6298: display: inline;
6299: }
1.933 droeschl 6300:
6301: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6302: padding: 0;
1.933 droeschl 6303: margin: 0;
6304: float: left;
1.913 droeschl 6305: }
1.933 droeschl 6306: .LC_breadcrumb_tools_tools {
6307: padding: 0;
6308: margin: 0;
1.913 droeschl 6309: float: right;
6310: }
6311:
1.1240 raeburn 6312: .LC_placement_prog {
6313: padding-right: 20px;
6314: font-weight: bold;
6315: font-size: 90%;
6316: }
6317:
1.359 albertel 6318: table#LC_title_bar td {
6319: background: $tabbg;
6320: }
1.795 www 6321:
1.911 bisitz 6322: table#LC_menubuttons img {
1.803 bisitz 6323: border: none;
1.346 albertel 6324: }
1.795 www 6325:
1.842 droeschl 6326: .LC_breadcrumbs_component {
1.911 bisitz 6327: float: right;
6328: margin: 0 1em;
1.357 albertel 6329: }
1.842 droeschl 6330: .LC_breadcrumbs_component img {
1.911 bisitz 6331: vertical-align: middle;
1.777 tempelho 6332: }
1.795 www 6333:
1.1243 raeburn 6334: .LC_breadcrumbs_hoverable {
6335: background: $sidebg;
6336: }
6337:
1.383 albertel 6338: td.LC_table_cell_checkbox {
6339: text-align: center;
6340: }
1.795 www 6341:
6342: .LC_fontsize_small {
1.911 bisitz 6343: font-size: 70%;
1.705 tempelho 6344: }
6345:
1.844 bisitz 6346: #LC_breadcrumbs {
1.911 bisitz 6347: clear:both;
6348: background: $sidebg;
6349: border-bottom: 1px solid $lg_border_color;
6350: line-height: 2.5em;
1.933 droeschl 6351: overflow: hidden;
1.911 bisitz 6352: margin: 0;
6353: padding: 0;
1.995 raeburn 6354: text-align: left;
1.819 tempelho 6355: }
1.862 bisitz 6356:
1.1098 bisitz 6357: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6358: clear:both;
6359: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6360: border: 1px solid $sidebg;
1.1098 bisitz 6361: margin: 0 0 10px 0;
1.966 bisitz 6362: padding: 3px;
1.995 raeburn 6363: text-align: left;
1.822 bisitz 6364: }
6365:
1.795 www 6366: .LC_fontsize_medium {
1.911 bisitz 6367: font-size: 85%;
1.705 tempelho 6368: }
6369:
1.795 www 6370: .LC_fontsize_large {
1.911 bisitz 6371: font-size: 120%;
1.705 tempelho 6372: }
6373:
1.346 albertel 6374: .LC_menubuttons_inline_text {
6375: color: $font;
1.698 harmsja 6376: font-size: 90%;
1.701 harmsja 6377: padding-left:3px;
1.346 albertel 6378: }
6379:
1.934 droeschl 6380: .LC_menubuttons_inline_text img{
6381: vertical-align: middle;
6382: }
6383:
1.1051 www 6384: li.LC_menubuttons_inline_text img {
1.951 onken 6385: cursor:pointer;
1.1002 droeschl 6386: text-decoration: none;
1.951 onken 6387: }
6388:
1.526 www 6389: .LC_menubuttons_link {
6390: text-decoration: none;
6391: }
1.795 www 6392:
1.522 albertel 6393: .LC_menubuttons_category {
1.521 www 6394: color: $font;
1.526 www 6395: background: $pgbg;
1.521 www 6396: font-size: larger;
6397: font-weight: bold;
6398: }
6399:
1.346 albertel 6400: td.LC_menubuttons_text {
1.911 bisitz 6401: color: $font;
1.346 albertel 6402: }
1.706 harmsja 6403:
1.346 albertel 6404: .LC_current_location {
6405: background: $tabbg;
6406: }
1.795 www 6407:
1.938 bisitz 6408: table.LC_data_table {
1.347 albertel 6409: border: 1px solid #000000;
1.402 albertel 6410: border-collapse: separate;
1.426 albertel 6411: border-spacing: 1px;
1.610 albertel 6412: background: $pgbg;
1.347 albertel 6413: }
1.795 www 6414:
1.422 albertel 6415: .LC_data_table_dense {
6416: font-size: small;
6417: }
1.795 www 6418:
1.507 raeburn 6419: table.LC_nested_outer {
6420: border: 1px solid #000000;
1.589 raeburn 6421: border-collapse: collapse;
1.803 bisitz 6422: border-spacing: 0;
1.507 raeburn 6423: width: 100%;
6424: }
1.795 www 6425:
1.879 raeburn 6426: table.LC_innerpickbox,
1.507 raeburn 6427: table.LC_nested {
1.803 bisitz 6428: border: none;
1.589 raeburn 6429: border-collapse: collapse;
1.803 bisitz 6430: border-spacing: 0;
1.507 raeburn 6431: width: 100%;
6432: }
1.795 www 6433:
1.911 bisitz 6434: table.LC_data_table tr th,
6435: table.LC_calendar tr th,
1.879 raeburn 6436: table.LC_prior_tries tr th,
6437: table.LC_innerpickbox tr th {
1.349 albertel 6438: font-weight: bold;
6439: background-color: $data_table_head;
1.801 tempelho 6440: color:$fontmenu;
1.701 harmsja 6441: font-size:90%;
1.347 albertel 6442: }
1.795 www 6443:
1.879 raeburn 6444: table.LC_innerpickbox tr th,
6445: table.LC_innerpickbox tr td {
6446: vertical-align: top;
6447: }
6448:
1.711 raeburn 6449: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6450: background-color: #CCCCCC;
1.711 raeburn 6451: font-weight: bold;
6452: text-align: left;
6453: }
1.795 www 6454:
1.912 bisitz 6455: table.LC_data_table tr.LC_odd_row > td {
6456: background-color: $data_table_light;
6457: padding: 2px;
6458: vertical-align: top;
6459: }
6460:
1.809 bisitz 6461: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6462: background-color: $data_table_light;
1.912 bisitz 6463: vertical-align: top;
6464: }
6465:
6466: table.LC_data_table tr.LC_even_row > td {
6467: background-color: $data_table_dark;
1.425 albertel 6468: padding: 2px;
1.900 bisitz 6469: vertical-align: top;
1.347 albertel 6470: }
1.795 www 6471:
1.809 bisitz 6472: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6473: background-color: $data_table_dark;
1.900 bisitz 6474: vertical-align: top;
1.347 albertel 6475: }
1.795 www 6476:
1.425 albertel 6477: table.LC_data_table tr.LC_data_table_highlight td {
6478: background-color: $data_table_darker;
6479: }
1.795 www 6480:
1.639 raeburn 6481: table.LC_data_table tr td.LC_leftcol_header {
6482: background-color: $data_table_head;
6483: font-weight: bold;
6484: }
1.795 www 6485:
1.451 albertel 6486: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6487: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6488: font-weight: bold;
6489: font-style: italic;
6490: text-align: center;
6491: padding: 8px;
1.347 albertel 6492: }
1.795 www 6493:
1.1114 raeburn 6494: table.LC_data_table tr.LC_empty_row td,
6495: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6496: background-color: $sidebg;
6497: }
6498:
6499: table.LC_nested tr.LC_empty_row td {
6500: background-color: #FFFFFF;
6501: }
6502:
1.890 droeschl 6503: table.LC_caption {
6504: }
6505:
1.507 raeburn 6506: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6507: padding: 4ex
6508: }
1.795 www 6509:
1.507 raeburn 6510: table.LC_nested_outer tr th {
6511: font-weight: bold;
1.801 tempelho 6512: color:$fontmenu;
1.507 raeburn 6513: background-color: $data_table_head;
1.701 harmsja 6514: font-size: small;
1.507 raeburn 6515: border-bottom: 1px solid #000000;
6516: }
1.795 www 6517:
1.507 raeburn 6518: table.LC_nested_outer tr td.LC_subheader {
6519: background-color: $data_table_head;
6520: font-weight: bold;
6521: font-size: small;
6522: border-bottom: 1px solid #000000;
6523: text-align: right;
1.451 albertel 6524: }
1.795 www 6525:
1.507 raeburn 6526: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6527: background-color: #CCCCCC;
1.451 albertel 6528: font-weight: bold;
6529: font-size: small;
1.507 raeburn 6530: text-align: center;
6531: }
1.795 www 6532:
1.589 raeburn 6533: table.LC_nested tr.LC_info_row td.LC_left_item,
6534: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6535: text-align: left;
1.451 albertel 6536: }
1.795 www 6537:
1.507 raeburn 6538: table.LC_nested td {
1.735 bisitz 6539: background-color: #FFFFFF;
1.451 albertel 6540: font-size: small;
1.507 raeburn 6541: }
1.795 www 6542:
1.507 raeburn 6543: table.LC_nested_outer tr th.LC_right_item,
6544: table.LC_nested tr.LC_info_row td.LC_right_item,
6545: table.LC_nested tr.LC_odd_row td.LC_right_item,
6546: table.LC_nested tr td.LC_right_item {
1.451 albertel 6547: text-align: right;
6548: }
6549:
1.507 raeburn 6550: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6551: background-color: #EEEEEE;
1.451 albertel 6552: }
6553:
1.473 raeburn 6554: table.LC_createuser {
6555: }
6556:
6557: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6558: font-size: small;
1.473 raeburn 6559: }
6560:
6561: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6562: background-color: #CCCCCC;
1.473 raeburn 6563: font-weight: bold;
6564: text-align: center;
6565: }
6566:
1.349 albertel 6567: table.LC_calendar {
6568: border: 1px solid #000000;
6569: border-collapse: collapse;
1.917 raeburn 6570: width: 98%;
1.349 albertel 6571: }
1.795 www 6572:
1.349 albertel 6573: table.LC_calendar_pickdate {
6574: font-size: xx-small;
6575: }
1.795 www 6576:
1.349 albertel 6577: table.LC_calendar tr td {
6578: border: 1px solid #000000;
6579: vertical-align: top;
1.917 raeburn 6580: width: 14%;
1.349 albertel 6581: }
1.795 www 6582:
1.349 albertel 6583: table.LC_calendar tr td.LC_calendar_day_empty {
6584: background-color: $data_table_dark;
6585: }
1.795 www 6586:
1.779 bisitz 6587: table.LC_calendar tr td.LC_calendar_day_current {
6588: background-color: $data_table_highlight;
1.777 tempelho 6589: }
1.795 www 6590:
1.938 bisitz 6591: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6592: background-color: $mail_new;
6593: }
1.795 www 6594:
1.938 bisitz 6595: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6596: background-color: $mail_new_hover;
6597: }
1.795 www 6598:
1.938 bisitz 6599: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6600: background-color: $mail_read;
6601: }
1.795 www 6602:
1.938 bisitz 6603: /*
6604: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6605: background-color: $mail_read_hover;
6606: }
1.938 bisitz 6607: */
1.795 www 6608:
1.938 bisitz 6609: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6610: background-color: $mail_replied;
6611: }
1.795 www 6612:
1.938 bisitz 6613: /*
6614: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6615: background-color: $mail_replied_hover;
6616: }
1.938 bisitz 6617: */
1.795 www 6618:
1.938 bisitz 6619: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6620: background-color: $mail_other;
6621: }
1.795 www 6622:
1.938 bisitz 6623: /*
6624: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6625: background-color: $mail_other_hover;
6626: }
1.938 bisitz 6627: */
1.494 raeburn 6628:
1.777 tempelho 6629: table.LC_data_table tr > td.LC_browser_file,
6630: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6631: background: #AAEE77;
1.389 albertel 6632: }
1.795 www 6633:
1.777 tempelho 6634: table.LC_data_table tr > td.LC_browser_file_locked,
6635: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6636: background: #FFAA99;
1.387 albertel 6637: }
1.795 www 6638:
1.777 tempelho 6639: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6640: background: #888888;
1.779 bisitz 6641: }
1.795 www 6642:
1.777 tempelho 6643: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6644: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6645: background: #F8F866;
1.777 tempelho 6646: }
1.795 www 6647:
1.696 bisitz 6648: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6649: background: #E0E8FF;
1.387 albertel 6650: }
1.696 bisitz 6651:
1.707 bisitz 6652: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6653: /* background: #77FF77; */
1.707 bisitz 6654: }
1.795 www 6655:
1.707 bisitz 6656: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6657: border-right: 8px solid #FFFF77;
1.707 bisitz 6658: }
1.795 www 6659:
1.707 bisitz 6660: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6661: border-right: 8px solid #FFAA77;
1.707 bisitz 6662: }
1.795 www 6663:
1.707 bisitz 6664: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6665: border-right: 8px solid #FF7777;
1.707 bisitz 6666: }
1.795 www 6667:
1.707 bisitz 6668: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6669: border-right: 8px solid #AAFF77;
1.707 bisitz 6670: }
1.795 www 6671:
1.707 bisitz 6672: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6673: border-right: 8px solid #11CC55;
1.707 bisitz 6674: }
6675:
1.388 albertel 6676: span.LC_current_location {
1.701 harmsja 6677: font-size:larger;
1.388 albertel 6678: background: $pgbg;
6679: }
1.387 albertel 6680:
1.1029 www 6681: span.LC_current_nav_location {
6682: font-weight:bold;
6683: background: $sidebg;
6684: }
6685:
1.395 albertel 6686: span.LC_parm_menu_item {
6687: font-size: larger;
6688: }
1.795 www 6689:
1.395 albertel 6690: span.LC_parm_scope_all {
6691: color: red;
6692: }
1.795 www 6693:
1.395 albertel 6694: span.LC_parm_scope_folder {
6695: color: green;
6696: }
1.795 www 6697:
1.395 albertel 6698: span.LC_parm_scope_resource {
6699: color: orange;
6700: }
1.795 www 6701:
1.395 albertel 6702: span.LC_parm_part {
6703: color: blue;
6704: }
1.795 www 6705:
1.911 bisitz 6706: span.LC_parm_folder,
6707: span.LC_parm_symb {
1.395 albertel 6708: font-size: x-small;
6709: font-family: $mono;
6710: color: #AAAAAA;
6711: }
6712:
1.977 bisitz 6713: ul.LC_parm_parmlist li {
6714: display: inline-block;
6715: padding: 0.3em 0.8em;
6716: vertical-align: top;
6717: width: 150px;
6718: border-top:1px solid $lg_border_color;
6719: }
6720:
1.795 www 6721: td.LC_parm_overview_level_menu,
6722: td.LC_parm_overview_map_menu,
6723: td.LC_parm_overview_parm_selectors,
6724: td.LC_parm_overview_restrictions {
1.396 albertel 6725: border: 1px solid black;
6726: border-collapse: collapse;
6727: }
1.795 www 6728:
1.396 albertel 6729: table.LC_parm_overview_restrictions td {
6730: border-width: 1px 4px 1px 4px;
6731: border-style: solid;
6732: border-color: $pgbg;
6733: text-align: center;
6734: }
1.795 www 6735:
1.396 albertel 6736: table.LC_parm_overview_restrictions th {
6737: background: $tabbg;
6738: border-width: 1px 4px 1px 4px;
6739: border-style: solid;
6740: border-color: $pgbg;
6741: }
1.795 www 6742:
1.398 albertel 6743: table#LC_helpmenu {
1.803 bisitz 6744: border: none;
1.398 albertel 6745: height: 55px;
1.803 bisitz 6746: border-spacing: 0;
1.398 albertel 6747: }
6748:
6749: table#LC_helpmenu fieldset legend {
6750: font-size: larger;
6751: }
1.795 www 6752:
1.397 albertel 6753: table#LC_helpmenu_links {
6754: width: 100%;
6755: border: 1px solid black;
6756: background: $pgbg;
1.803 bisitz 6757: padding: 0;
1.397 albertel 6758: border-spacing: 1px;
6759: }
1.795 www 6760:
1.397 albertel 6761: table#LC_helpmenu_links tr td {
6762: padding: 1px;
6763: background: $tabbg;
1.399 albertel 6764: text-align: center;
6765: font-weight: bold;
1.397 albertel 6766: }
1.396 albertel 6767:
1.795 www 6768: table#LC_helpmenu_links a:link,
6769: table#LC_helpmenu_links a:visited,
1.397 albertel 6770: table#LC_helpmenu_links a:active {
6771: text-decoration: none;
6772: color: $font;
6773: }
1.795 www 6774:
1.397 albertel 6775: table#LC_helpmenu_links a:hover {
6776: text-decoration: underline;
6777: color: $vlink;
6778: }
1.396 albertel 6779:
1.417 albertel 6780: .LC_chrt_popup_exists {
6781: border: 1px solid #339933;
6782: margin: -1px;
6783: }
1.795 www 6784:
1.417 albertel 6785: .LC_chrt_popup_up {
6786: border: 1px solid yellow;
6787: margin: -1px;
6788: }
1.795 www 6789:
1.417 albertel 6790: .LC_chrt_popup {
6791: border: 1px solid #8888FF;
6792: background: #CCCCFF;
6793: }
1.795 www 6794:
1.421 albertel 6795: table.LC_pick_box {
6796: border-collapse: separate;
6797: background: white;
6798: border: 1px solid black;
6799: border-spacing: 1px;
6800: }
1.795 www 6801:
1.421 albertel 6802: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6803: background: $sidebg;
1.421 albertel 6804: font-weight: bold;
1.900 bisitz 6805: text-align: left;
1.740 bisitz 6806: vertical-align: top;
1.421 albertel 6807: width: 184px;
6808: padding: 8px;
6809: }
1.795 www 6810:
1.579 raeburn 6811: table.LC_pick_box td.LC_pick_box_value {
6812: text-align: left;
6813: padding: 8px;
6814: }
1.795 www 6815:
1.579 raeburn 6816: table.LC_pick_box td.LC_pick_box_select {
6817: text-align: left;
6818: padding: 8px;
6819: }
1.795 www 6820:
1.424 albertel 6821: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6822: padding: 0;
1.421 albertel 6823: height: 1px;
6824: background: black;
6825: }
1.795 www 6826:
1.421 albertel 6827: table.LC_pick_box td.LC_pick_box_submit {
6828: text-align: right;
6829: }
1.795 www 6830:
1.579 raeburn 6831: table.LC_pick_box td.LC_evenrow_value {
6832: text-align: left;
6833: padding: 8px;
6834: background-color: $data_table_light;
6835: }
1.795 www 6836:
1.579 raeburn 6837: table.LC_pick_box td.LC_oddrow_value {
6838: text-align: left;
6839: padding: 8px;
6840: background-color: $data_table_light;
6841: }
1.795 www 6842:
1.579 raeburn 6843: span.LC_helpform_receipt_cat {
6844: font-weight: bold;
6845: }
1.795 www 6846:
1.424 albertel 6847: table.LC_group_priv_box {
6848: background: white;
6849: border: 1px solid black;
6850: border-spacing: 1px;
6851: }
1.795 www 6852:
1.424 albertel 6853: table.LC_group_priv_box td.LC_pick_box_title {
6854: background: $tabbg;
6855: font-weight: bold;
6856: text-align: right;
6857: width: 184px;
6858: }
1.795 www 6859:
1.424 albertel 6860: table.LC_group_priv_box td.LC_groups_fixed {
6861: background: $data_table_light;
6862: text-align: center;
6863: }
1.795 www 6864:
1.424 albertel 6865: table.LC_group_priv_box td.LC_groups_optional {
6866: background: $data_table_dark;
6867: text-align: center;
6868: }
1.795 www 6869:
1.424 albertel 6870: table.LC_group_priv_box td.LC_groups_functionality {
6871: background: $data_table_darker;
6872: text-align: center;
6873: font-weight: bold;
6874: }
1.795 www 6875:
1.424 albertel 6876: table.LC_group_priv td {
6877: text-align: left;
1.803 bisitz 6878: padding: 0;
1.424 albertel 6879: }
6880:
6881: .LC_navbuttons {
6882: margin: 2ex 0ex 2ex 0ex;
6883: }
1.795 www 6884:
1.423 albertel 6885: .LC_topic_bar {
6886: font-weight: bold;
6887: background: $tabbg;
1.918 wenzelju 6888: margin: 1em 0em 1em 2em;
1.805 bisitz 6889: padding: 3px;
1.918 wenzelju 6890: font-size: 1.2em;
1.423 albertel 6891: }
1.795 www 6892:
1.423 albertel 6893: .LC_topic_bar span {
1.918 wenzelju 6894: left: 0.5em;
6895: position: absolute;
1.423 albertel 6896: vertical-align: middle;
1.918 wenzelju 6897: font-size: 1.2em;
1.423 albertel 6898: }
1.795 www 6899:
1.423 albertel 6900: table.LC_course_group_status {
6901: margin: 20px;
6902: }
1.795 www 6903:
1.423 albertel 6904: table.LC_status_selector td {
6905: vertical-align: top;
6906: text-align: center;
1.424 albertel 6907: padding: 4px;
6908: }
1.795 www 6909:
1.599 albertel 6910: div.LC_feedback_link {
1.616 albertel 6911: clear: both;
1.829 kalberla 6912: background: $sidebg;
1.779 bisitz 6913: width: 100%;
1.829 kalberla 6914: padding-bottom: 10px;
6915: border: 1px $tabbg solid;
1.833 kalberla 6916: height: 22px;
6917: line-height: 22px;
6918: padding-top: 5px;
6919: }
6920:
6921: div.LC_feedback_link img {
6922: height: 22px;
1.867 kalberla 6923: vertical-align:middle;
1.829 kalberla 6924: }
6925:
1.911 bisitz 6926: div.LC_feedback_link a {
1.829 kalberla 6927: text-decoration: none;
1.489 raeburn 6928: }
1.795 www 6929:
1.867 kalberla 6930: div.LC_comblock {
1.911 bisitz 6931: display:inline;
1.867 kalberla 6932: color:$font;
6933: font-size:90%;
6934: }
6935:
6936: div.LC_feedback_link div.LC_comblock {
6937: padding-left:5px;
6938: }
6939:
6940: div.LC_feedback_link div.LC_comblock a {
6941: color:$font;
6942: }
6943:
1.489 raeburn 6944: span.LC_feedback_link {
1.858 bisitz 6945: /* background: $feedback_link_bg; */
1.599 albertel 6946: font-size: larger;
6947: }
1.795 www 6948:
1.599 albertel 6949: span.LC_message_link {
1.858 bisitz 6950: /* background: $feedback_link_bg; */
1.599 albertel 6951: font-size: larger;
6952: position: absolute;
6953: right: 1em;
1.489 raeburn 6954: }
1.421 albertel 6955:
1.515 albertel 6956: table.LC_prior_tries {
1.524 albertel 6957: border: 1px solid #000000;
6958: border-collapse: separate;
6959: border-spacing: 1px;
1.515 albertel 6960: }
1.523 albertel 6961:
1.515 albertel 6962: table.LC_prior_tries td {
1.524 albertel 6963: padding: 2px;
1.515 albertel 6964: }
1.523 albertel 6965:
6966: .LC_answer_correct {
1.795 www 6967: background: lightgreen;
6968: color: darkgreen;
6969: padding: 6px;
1.523 albertel 6970: }
1.795 www 6971:
1.523 albertel 6972: .LC_answer_charged_try {
1.797 www 6973: background: #FFAAAA;
1.795 www 6974: color: darkred;
6975: padding: 6px;
1.523 albertel 6976: }
1.795 www 6977:
1.779 bisitz 6978: .LC_answer_not_charged_try,
1.523 albertel 6979: .LC_answer_no_grade,
6980: .LC_answer_late {
1.795 www 6981: background: lightyellow;
1.523 albertel 6982: color: black;
1.795 www 6983: padding: 6px;
1.523 albertel 6984: }
1.795 www 6985:
1.523 albertel 6986: .LC_answer_previous {
1.795 www 6987: background: lightblue;
6988: color: darkblue;
6989: padding: 6px;
1.523 albertel 6990: }
1.795 www 6991:
1.779 bisitz 6992: .LC_answer_no_message {
1.777 tempelho 6993: background: #FFFFFF;
6994: color: black;
1.795 www 6995: padding: 6px;
1.779 bisitz 6996: }
1.795 www 6997:
1.779 bisitz 6998: .LC_answer_unknown {
6999: background: orange;
7000: color: black;
1.795 www 7001: padding: 6px;
1.777 tempelho 7002: }
1.795 www 7003:
1.529 albertel 7004: span.LC_prior_numerical,
7005: span.LC_prior_string,
7006: span.LC_prior_custom,
7007: span.LC_prior_reaction,
7008: span.LC_prior_math {
1.925 bisitz 7009: font-family: $mono;
1.523 albertel 7010: white-space: pre;
7011: }
7012:
1.525 albertel 7013: span.LC_prior_string {
1.925 bisitz 7014: font-family: $mono;
1.525 albertel 7015: white-space: pre;
7016: }
7017:
1.523 albertel 7018: table.LC_prior_option {
7019: width: 100%;
7020: border-collapse: collapse;
7021: }
1.795 www 7022:
1.911 bisitz 7023: table.LC_prior_rank,
1.795 www 7024: table.LC_prior_match {
1.528 albertel 7025: border-collapse: collapse;
7026: }
1.795 www 7027:
1.528 albertel 7028: table.LC_prior_option tr td,
7029: table.LC_prior_rank tr td,
7030: table.LC_prior_match tr td {
1.524 albertel 7031: border: 1px solid #000000;
1.515 albertel 7032: }
7033:
1.855 bisitz 7034: .LC_nobreak {
1.544 albertel 7035: white-space: nowrap;
1.519 raeburn 7036: }
7037:
1.576 raeburn 7038: span.LC_cusr_emph {
7039: font-style: italic;
7040: }
7041:
1.633 raeburn 7042: span.LC_cusr_subheading {
7043: font-weight: normal;
7044: font-size: 85%;
7045: }
7046:
1.861 bisitz 7047: div.LC_docs_entry_move {
1.859 bisitz 7048: border: 1px solid #BBBBBB;
1.545 albertel 7049: background: #DDDDDD;
1.861 bisitz 7050: width: 22px;
1.859 bisitz 7051: padding: 1px;
7052: margin: 0;
1.545 albertel 7053: }
7054:
1.861 bisitz 7055: table.LC_data_table tr > td.LC_docs_entry_commands,
7056: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7057: font-size: x-small;
7058: }
1.795 www 7059:
1.861 bisitz 7060: .LC_docs_entry_parameter {
7061: white-space: nowrap;
7062: }
7063:
1.544 albertel 7064: .LC_docs_copy {
1.545 albertel 7065: color: #000099;
1.544 albertel 7066: }
1.795 www 7067:
1.544 albertel 7068: .LC_docs_cut {
1.545 albertel 7069: color: #550044;
1.544 albertel 7070: }
1.795 www 7071:
1.544 albertel 7072: .LC_docs_rename {
1.545 albertel 7073: color: #009900;
1.544 albertel 7074: }
1.795 www 7075:
1.544 albertel 7076: .LC_docs_remove {
1.545 albertel 7077: color: #990000;
7078: }
7079:
1.547 albertel 7080: .LC_docs_reinit_warn,
7081: .LC_docs_ext_edit {
7082: font-size: x-small;
7083: }
7084:
1.545 albertel 7085: table.LC_docs_adddocs td,
7086: table.LC_docs_adddocs th {
7087: border: 1px solid #BBBBBB;
7088: padding: 4px;
7089: background: #DDDDDD;
1.543 albertel 7090: }
7091:
1.584 albertel 7092: table.LC_sty_begin {
7093: background: #BBFFBB;
7094: }
1.795 www 7095:
1.584 albertel 7096: table.LC_sty_end {
7097: background: #FFBBBB;
7098: }
7099:
1.589 raeburn 7100: table.LC_double_column {
1.803 bisitz 7101: border-width: 0;
1.589 raeburn 7102: border-collapse: collapse;
7103: width: 100%;
7104: padding: 2px;
7105: }
7106:
7107: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7108: top: 2px;
1.589 raeburn 7109: left: 2px;
7110: width: 47%;
7111: vertical-align: top;
7112: }
7113:
7114: table.LC_double_column tr td.LC_right_col {
7115: top: 2px;
1.779 bisitz 7116: right: 2px;
1.589 raeburn 7117: width: 47%;
7118: vertical-align: top;
7119: }
7120:
1.591 raeburn 7121: div.LC_left_float {
7122: float: left;
7123: padding-right: 5%;
1.597 albertel 7124: padding-bottom: 4px;
1.591 raeburn 7125: }
7126:
7127: div.LC_clear_float_header {
1.597 albertel 7128: padding-bottom: 2px;
1.591 raeburn 7129: }
7130:
7131: div.LC_clear_float_footer {
1.597 albertel 7132: padding-top: 10px;
1.591 raeburn 7133: clear: both;
7134: }
7135:
1.597 albertel 7136: div.LC_grade_show_user {
1.941 bisitz 7137: /* border-left: 5px solid $sidebg; */
7138: border-top: 5px solid #000000;
7139: margin: 50px 0 0 0;
1.936 bisitz 7140: padding: 15px 0 5px 10px;
1.597 albertel 7141: }
1.795 www 7142:
1.936 bisitz 7143: div.LC_grade_show_user_odd_row {
1.941 bisitz 7144: /* border-left: 5px solid #000000; */
7145: }
7146:
7147: div.LC_grade_show_user div.LC_Box {
7148: margin-right: 50px;
1.597 albertel 7149: }
7150:
7151: div.LC_grade_submissions,
7152: div.LC_grade_message_center,
1.936 bisitz 7153: div.LC_grade_info_links {
1.597 albertel 7154: margin: 5px;
7155: width: 99%;
7156: background: #FFFFFF;
7157: }
1.795 www 7158:
1.597 albertel 7159: div.LC_grade_submissions_header,
1.936 bisitz 7160: div.LC_grade_message_center_header {
1.705 tempelho 7161: font-weight: bold;
7162: font-size: large;
1.597 albertel 7163: }
1.795 www 7164:
1.597 albertel 7165: div.LC_grade_submissions_body,
1.936 bisitz 7166: div.LC_grade_message_center_body {
1.597 albertel 7167: border: 1px solid black;
7168: width: 99%;
7169: background: #FFFFFF;
7170: }
1.795 www 7171:
1.613 albertel 7172: table.LC_scantron_action {
7173: width: 100%;
7174: }
1.795 www 7175:
1.613 albertel 7176: table.LC_scantron_action tr th {
1.698 harmsja 7177: font-weight:bold;
7178: font-style:normal;
1.613 albertel 7179: }
1.795 www 7180:
1.779 bisitz 7181: .LC_edit_problem_header,
1.614 albertel 7182: div.LC_edit_problem_footer {
1.705 tempelho 7183: font-weight: normal;
7184: font-size: medium;
1.602 albertel 7185: margin: 2px;
1.1060 bisitz 7186: background-color: $sidebg;
1.600 albertel 7187: }
1.795 www 7188:
1.600 albertel 7189: div.LC_edit_problem_header,
1.602 albertel 7190: div.LC_edit_problem_header div,
1.614 albertel 7191: div.LC_edit_problem_footer,
7192: div.LC_edit_problem_footer div,
1.602 albertel 7193: div.LC_edit_problem_editxml_header,
7194: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7195: z-index: 100;
1.600 albertel 7196: }
1.795 www 7197:
1.600 albertel 7198: div.LC_edit_problem_header_title {
1.705 tempelho 7199: font-weight: bold;
7200: font-size: larger;
1.602 albertel 7201: background: $tabbg;
7202: padding: 3px;
1.1060 bisitz 7203: margin: 0 0 5px 0;
1.602 albertel 7204: }
1.795 www 7205:
1.602 albertel 7206: table.LC_edit_problem_header_title {
7207: width: 100%;
1.600 albertel 7208: background: $tabbg;
1.602 albertel 7209: }
7210:
1.1205 golterma 7211: div.LC_edit_actionbar {
7212: background-color: $sidebg;
1.1218 droeschl 7213: margin: 0;
7214: padding: 0;
7215: line-height: 200%;
1.602 albertel 7216: }
1.795 www 7217:
1.1218 droeschl 7218: div.LC_edit_actionbar div{
7219: padding: 0;
7220: margin: 0;
7221: display: inline-block;
1.600 albertel 7222: }
1.795 www 7223:
1.1124 bisitz 7224: .LC_edit_opt {
7225: padding-left: 1em;
7226: white-space: nowrap;
7227: }
7228:
1.1152 golterma 7229: .LC_edit_problem_latexhelper{
7230: text-align: right;
7231: }
7232:
7233: #LC_edit_problem_colorful div{
7234: margin-left: 40px;
7235: }
7236:
1.1205 golterma 7237: #LC_edit_problem_codemirror div{
7238: margin-left: 0px;
7239: }
7240:
1.911 bisitz 7241: img.stift {
1.803 bisitz 7242: border-width: 0;
7243: vertical-align: middle;
1.677 riegler 7244: }
1.680 riegler 7245:
1.923 bisitz 7246: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7247: vertical-align: top;
1.777 tempelho 7248: }
1.795 www 7249:
1.716 raeburn 7250: div.LC_createcourse {
1.911 bisitz 7251: margin: 10px 10px 10px 10px;
1.716 raeburn 7252: }
7253:
1.917 raeburn 7254: .LC_dccid {
1.1130 raeburn 7255: float: right;
1.917 raeburn 7256: margin: 0.2em 0 0 0;
7257: padding: 0;
7258: font-size: 90%;
7259: display:none;
7260: }
7261:
1.897 wenzelju 7262: ol.LC_primary_menu a:hover,
1.721 harmsja 7263: ol#LC_MenuBreadcrumbs a:hover,
7264: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7265: ul#LC_secondary_menu a:hover,
1.721 harmsja 7266: .LC_FormSectionClearButton input:hover
1.795 www 7267: ul.LC_TabContent li:hover a {
1.952 onken 7268: color:$button_hover;
1.911 bisitz 7269: text-decoration:none;
1.693 droeschl 7270: }
7271:
1.779 bisitz 7272: h1 {
1.911 bisitz 7273: padding: 0;
7274: line-height:130%;
1.693 droeschl 7275: }
1.698 harmsja 7276:
1.911 bisitz 7277: h2,
7278: h3,
7279: h4,
7280: h5,
7281: h6 {
7282: margin: 5px 0 5px 0;
7283: padding: 0;
7284: line-height:130%;
1.693 droeschl 7285: }
1.795 www 7286:
7287: .LC_hcell {
1.911 bisitz 7288: padding:3px 15px 3px 15px;
7289: margin: 0;
7290: background-color:$tabbg;
7291: color:$fontmenu;
7292: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7293: }
1.795 www 7294:
1.840 bisitz 7295: .LC_Box > .LC_hcell {
1.911 bisitz 7296: margin: 0 -10px 10px -10px;
1.835 bisitz 7297: }
7298:
1.721 harmsja 7299: .LC_noBorder {
1.911 bisitz 7300: border: 0;
1.698 harmsja 7301: }
1.693 droeschl 7302:
1.721 harmsja 7303: .LC_FormSectionClearButton input {
1.911 bisitz 7304: background-color:transparent;
7305: border: none;
7306: cursor:pointer;
7307: text-decoration:underline;
1.693 droeschl 7308: }
1.763 bisitz 7309:
7310: .LC_help_open_topic {
1.911 bisitz 7311: color: #FFFFFF;
7312: background-color: #EEEEFF;
7313: margin: 1px;
7314: padding: 4px;
7315: border: 1px solid #000033;
7316: white-space: nowrap;
7317: /* vertical-align: middle; */
1.759 neumanie 7318: }
1.693 droeschl 7319:
1.911 bisitz 7320: dl,
7321: ul,
7322: div,
7323: fieldset {
7324: margin: 10px 10px 10px 0;
7325: /* overflow: hidden; */
1.693 droeschl 7326: }
1.795 www 7327:
1.1211 raeburn 7328: article.geogebraweb div {
7329: margin: 0;
7330: }
7331:
1.838 bisitz 7332: fieldset > legend {
1.911 bisitz 7333: font-weight: bold;
7334: padding: 0 5px 0 5px;
1.838 bisitz 7335: }
7336:
1.813 bisitz 7337: #LC_nav_bar {
1.911 bisitz 7338: float: left;
1.995 raeburn 7339: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7340: margin: 0 0 2px 0;
1.807 droeschl 7341: }
7342:
1.916 droeschl 7343: #LC_realm {
7344: margin: 0.2em 0 0 0;
7345: padding: 0;
7346: font-weight: bold;
7347: text-align: center;
1.995 raeburn 7348: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7349: }
7350:
1.911 bisitz 7351: #LC_nav_bar em {
7352: font-weight: bold;
7353: font-style: normal;
1.807 droeschl 7354: }
7355:
1.897 wenzelju 7356: ol.LC_primary_menu {
1.934 droeschl 7357: margin: 0;
1.1076 raeburn 7358: padding: 0;
1.807 droeschl 7359: }
7360:
1.852 droeschl 7361: ol#LC_PathBreadcrumbs {
1.911 bisitz 7362: margin: 0;
1.693 droeschl 7363: }
7364:
1.897 wenzelju 7365: ol.LC_primary_menu li {
1.1076 raeburn 7366: color: RGB(80, 80, 80);
7367: vertical-align: middle;
7368: text-align: left;
7369: list-style: none;
1.1205 golterma 7370: position: relative;
1.1076 raeburn 7371: float: left;
1.1205 golterma 7372: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7373: line-height: 1.5em;
1.1076 raeburn 7374: }
7375:
1.1205 golterma 7376: ol.LC_primary_menu li a,
7377: ol.LC_primary_menu li p {
1.1076 raeburn 7378: display: block;
7379: margin: 0;
7380: padding: 0 5px 0 10px;
7381: text-decoration: none;
7382: }
7383:
1.1205 golterma 7384: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7385: display: inline-block;
7386: width: 95%;
7387: text-align: left;
7388: }
7389:
7390: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7391: display: inline-block;
7392: width: 5%;
7393: float: right;
7394: text-align: right;
7395: font-size: 70%;
7396: }
7397:
7398: ol.LC_primary_menu ul {
1.1076 raeburn 7399: display: none;
1.1205 golterma 7400: width: 15em;
1.1076 raeburn 7401: background-color: $data_table_light;
1.1205 golterma 7402: position: absolute;
7403: top: 100%;
1.1076 raeburn 7404: }
7405:
1.1205 golterma 7406: ol.LC_primary_menu ul ul {
7407: left: 100%;
7408: top: 0;
7409: }
7410:
7411: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7412: display: block;
7413: position: absolute;
7414: margin: 0;
7415: padding: 0;
1.1078 raeburn 7416: z-index: 2;
1.1076 raeburn 7417: }
7418:
7419: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7420: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7421: font-size: 90%;
1.911 bisitz 7422: vertical-align: top;
1.1076 raeburn 7423: float: none;
1.1079 raeburn 7424: border-left: 1px solid black;
7425: border-right: 1px solid black;
1.1205 golterma 7426: /* A dark bottom border to visualize different menu options;
7427: overwritten in the create_submenu routine for the last border-bottom of the menu */
7428: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7429: }
7430:
1.1205 golterma 7431: ol.LC_primary_menu li li p:hover {
7432: color:$button_hover;
7433: text-decoration:none;
7434: background-color:$data_table_dark;
1.1076 raeburn 7435: }
7436:
7437: ol.LC_primary_menu li li a:hover {
7438: color:$button_hover;
7439: background-color:$data_table_dark;
1.693 droeschl 7440: }
7441:
1.1205 golterma 7442: /* Font-size equal to the size of the predecessors*/
7443: ol.LC_primary_menu li:hover li li {
7444: font-size: 100%;
7445: }
7446:
1.897 wenzelju 7447: ol.LC_primary_menu li img {
1.911 bisitz 7448: vertical-align: bottom;
1.934 droeschl 7449: height: 1.1em;
1.1077 raeburn 7450: margin: 0.2em 0 0 0;
1.693 droeschl 7451: }
7452:
1.897 wenzelju 7453: ol.LC_primary_menu a {
1.911 bisitz 7454: color: RGB(80, 80, 80);
7455: text-decoration: none;
1.693 droeschl 7456: }
1.795 www 7457:
1.949 droeschl 7458: ol.LC_primary_menu a.LC_new_message {
7459: font-weight:bold;
7460: color: darkred;
7461: }
7462:
1.975 raeburn 7463: ol.LC_docs_parameters {
7464: margin-left: 0;
7465: padding: 0;
7466: list-style: none;
7467: }
7468:
7469: ol.LC_docs_parameters li {
7470: margin: 0;
7471: padding-right: 20px;
7472: display: inline;
7473: }
7474:
1.976 raeburn 7475: ol.LC_docs_parameters li:before {
7476: content: "\\002022 \\0020";
7477: }
7478:
7479: li.LC_docs_parameters_title {
7480: font-weight: bold;
7481: }
7482:
7483: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7484: content: "";
7485: }
7486:
1.897 wenzelju 7487: ul#LC_secondary_menu {
1.1107 raeburn 7488: clear: right;
1.911 bisitz 7489: color: $fontmenu;
7490: background: $tabbg;
7491: list-style: none;
7492: padding: 0;
7493: margin: 0;
7494: width: 100%;
1.995 raeburn 7495: text-align: left;
1.1107 raeburn 7496: float: left;
1.808 droeschl 7497: }
7498:
1.897 wenzelju 7499: ul#LC_secondary_menu li {
1.911 bisitz 7500: font-weight: bold;
7501: line-height: 1.8em;
1.1107 raeburn 7502: border-right: 1px solid black;
7503: float: left;
7504: }
7505:
7506: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7507: background-color: $data_table_light;
7508: }
7509:
7510: ul#LC_secondary_menu li a {
1.911 bisitz 7511: padding: 0 0.8em;
1.1107 raeburn 7512: }
7513:
7514: ul#LC_secondary_menu li ul {
7515: display: none;
7516: }
7517:
7518: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7519: display: block;
7520: position: absolute;
7521: margin: 0;
7522: padding: 0;
7523: list-style:none;
7524: float: none;
7525: background-color: $data_table_light;
7526: z-index: 2;
7527: margin-left: -1px;
7528: }
7529:
7530: ul#LC_secondary_menu li ul li {
7531: font-size: 90%;
7532: vertical-align: top;
7533: border-left: 1px solid black;
1.911 bisitz 7534: border-right: 1px solid black;
1.1119 raeburn 7535: background-color: $data_table_light;
1.1107 raeburn 7536: list-style:none;
7537: float: none;
7538: }
7539:
7540: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7541: background-color: $data_table_dark;
1.807 droeschl 7542: }
7543:
1.847 tempelho 7544: ul.LC_TabContent {
1.911 bisitz 7545: display:block;
7546: background: $sidebg;
7547: border-bottom: solid 1px $lg_border_color;
7548: list-style:none;
1.1020 raeburn 7549: margin: -1px -10px 0 -10px;
1.911 bisitz 7550: padding: 0;
1.693 droeschl 7551: }
7552:
1.795 www 7553: ul.LC_TabContent li,
7554: ul.LC_TabContentBigger li {
1.911 bisitz 7555: float:left;
1.741 harmsja 7556: }
1.795 www 7557:
1.897 wenzelju 7558: ul#LC_secondary_menu li a {
1.911 bisitz 7559: color: $fontmenu;
7560: text-decoration: none;
1.693 droeschl 7561: }
1.795 www 7562:
1.721 harmsja 7563: ul.LC_TabContent {
1.952 onken 7564: min-height:20px;
1.721 harmsja 7565: }
1.795 www 7566:
7567: ul.LC_TabContent li {
1.911 bisitz 7568: vertical-align:middle;
1.959 onken 7569: padding: 0 16px 0 10px;
1.911 bisitz 7570: background-color:$tabbg;
7571: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7572: border-left: solid 1px $font;
1.721 harmsja 7573: }
1.795 www 7574:
1.847 tempelho 7575: ul.LC_TabContent .right {
1.911 bisitz 7576: float:right;
1.847 tempelho 7577: }
7578:
1.911 bisitz 7579: ul.LC_TabContent li a,
7580: ul.LC_TabContent li {
7581: color:rgb(47,47,47);
7582: text-decoration:none;
7583: font-size:95%;
7584: font-weight:bold;
1.952 onken 7585: min-height:20px;
7586: }
7587:
1.959 onken 7588: ul.LC_TabContent li a:hover,
7589: ul.LC_TabContent li a:focus {
1.952 onken 7590: color: $button_hover;
1.959 onken 7591: background:none;
7592: outline:none;
1.952 onken 7593: }
7594:
7595: ul.LC_TabContent li:hover {
7596: color: $button_hover;
7597: cursor:pointer;
1.721 harmsja 7598: }
1.795 www 7599:
1.911 bisitz 7600: ul.LC_TabContent li.active {
1.952 onken 7601: color: $font;
1.911 bisitz 7602: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7603: border-bottom:solid 1px #FFFFFF;
7604: cursor: default;
1.744 ehlerst 7605: }
1.795 www 7606:
1.959 onken 7607: ul.LC_TabContent li.active a {
7608: color:$font;
7609: background:#FFFFFF;
7610: outline: none;
7611: }
1.1047 raeburn 7612:
7613: ul.LC_TabContent li.goback {
7614: float: left;
7615: border-left: none;
7616: }
7617:
1.870 tempelho 7618: #maincoursedoc {
1.911 bisitz 7619: clear:both;
1.870 tempelho 7620: }
7621:
7622: ul.LC_TabContentBigger {
1.911 bisitz 7623: display:block;
7624: list-style:none;
7625: padding: 0;
1.870 tempelho 7626: }
7627:
1.795 www 7628: ul.LC_TabContentBigger li {
1.911 bisitz 7629: vertical-align:bottom;
7630: height: 30px;
7631: font-size:110%;
7632: font-weight:bold;
7633: color: #737373;
1.841 tempelho 7634: }
7635:
1.957 onken 7636: ul.LC_TabContentBigger li.active {
7637: position: relative;
7638: top: 1px;
7639: }
7640:
1.870 tempelho 7641: ul.LC_TabContentBigger li a {
1.911 bisitz 7642: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7643: height: 30px;
7644: line-height: 30px;
7645: text-align: center;
7646: display: block;
7647: text-decoration: none;
1.958 onken 7648: outline: none;
1.741 harmsja 7649: }
1.795 www 7650:
1.870 tempelho 7651: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7652: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7653: color:$font;
1.744 ehlerst 7654: }
1.795 www 7655:
1.870 tempelho 7656: ul.LC_TabContentBigger li b {
1.911 bisitz 7657: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7658: display: block;
7659: float: left;
7660: padding: 0 30px;
1.957 onken 7661: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7662: }
7663:
1.956 onken 7664: ul.LC_TabContentBigger li:hover b {
7665: color:$button_hover;
7666: }
7667:
1.870 tempelho 7668: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7669: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7670: color:$font;
1.957 onken 7671: border: 0;
1.741 harmsja 7672: }
1.693 droeschl 7673:
1.870 tempelho 7674:
1.862 bisitz 7675: ul.LC_CourseBreadcrumbs {
7676: background: $sidebg;
1.1020 raeburn 7677: height: 2em;
1.862 bisitz 7678: padding-left: 10px;
1.1020 raeburn 7679: margin: 0;
1.862 bisitz 7680: list-style-position: inside;
7681: }
7682:
1.911 bisitz 7683: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7684: ol#LC_PathBreadcrumbs {
1.911 bisitz 7685: padding-left: 10px;
7686: margin: 0;
1.933 droeschl 7687: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7688: }
7689:
1.911 bisitz 7690: ol#LC_MenuBreadcrumbs li,
7691: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7692: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7693: display: inline;
1.933 droeschl 7694: white-space: normal;
1.693 droeschl 7695: }
7696:
1.823 bisitz 7697: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7698: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7699: text-decoration: none;
7700: font-size:90%;
1.693 droeschl 7701: }
1.795 www 7702:
1.969 droeschl 7703: ol#LC_MenuBreadcrumbs h1 {
7704: display: inline;
7705: font-size: 90%;
7706: line-height: 2.5em;
7707: margin: 0;
7708: padding: 0;
7709: }
7710:
1.795 www 7711: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7712: text-decoration:none;
7713: font-size:100%;
7714: font-weight:bold;
1.693 droeschl 7715: }
1.795 www 7716:
1.840 bisitz 7717: .LC_Box {
1.911 bisitz 7718: border: solid 1px $lg_border_color;
7719: padding: 0 10px 10px 10px;
1.746 neumanie 7720: }
1.795 www 7721:
1.1020 raeburn 7722: .LC_DocsBox {
7723: border: solid 1px $lg_border_color;
7724: padding: 0 0 10px 10px;
7725: }
7726:
1.795 www 7727: .LC_AboutMe_Image {
1.911 bisitz 7728: float:left;
7729: margin-right:10px;
1.747 neumanie 7730: }
1.795 www 7731:
7732: .LC_Clear_AboutMe_Image {
1.911 bisitz 7733: clear:left;
1.747 neumanie 7734: }
1.795 www 7735:
1.721 harmsja 7736: dl.LC_ListStyleClean dt {
1.911 bisitz 7737: padding-right: 5px;
7738: display: table-header-group;
1.693 droeschl 7739: }
7740:
1.721 harmsja 7741: dl.LC_ListStyleClean dd {
1.911 bisitz 7742: display: table-row;
1.693 droeschl 7743: }
7744:
1.721 harmsja 7745: .LC_ListStyleClean,
7746: .LC_ListStyleSimple,
7747: .LC_ListStyleNormal,
1.795 www 7748: .LC_ListStyleSpecial {
1.911 bisitz 7749: /* display:block; */
7750: list-style-position: inside;
7751: list-style-type: none;
7752: overflow: hidden;
7753: padding: 0;
1.693 droeschl 7754: }
7755:
1.721 harmsja 7756: .LC_ListStyleSimple li,
7757: .LC_ListStyleSimple dd,
7758: .LC_ListStyleNormal li,
7759: .LC_ListStyleNormal dd,
7760: .LC_ListStyleSpecial li,
1.795 www 7761: .LC_ListStyleSpecial dd {
1.911 bisitz 7762: margin: 0;
7763: padding: 5px 5px 5px 10px;
7764: clear: both;
1.693 droeschl 7765: }
7766:
1.721 harmsja 7767: .LC_ListStyleClean li,
7768: .LC_ListStyleClean dd {
1.911 bisitz 7769: padding-top: 0;
7770: padding-bottom: 0;
1.693 droeschl 7771: }
7772:
1.721 harmsja 7773: .LC_ListStyleSimple dd,
1.795 www 7774: .LC_ListStyleSimple li {
1.911 bisitz 7775: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7776: }
7777:
1.721 harmsja 7778: .LC_ListStyleSpecial li,
7779: .LC_ListStyleSpecial dd {
1.911 bisitz 7780: list-style-type: none;
7781: background-color: RGB(220, 220, 220);
7782: margin-bottom: 4px;
1.693 droeschl 7783: }
7784:
1.721 harmsja 7785: table.LC_SimpleTable {
1.911 bisitz 7786: margin:5px;
7787: border:solid 1px $lg_border_color;
1.795 www 7788: }
1.693 droeschl 7789:
1.721 harmsja 7790: table.LC_SimpleTable tr {
1.911 bisitz 7791: padding: 0;
7792: border:solid 1px $lg_border_color;
1.693 droeschl 7793: }
1.795 www 7794:
7795: table.LC_SimpleTable thead {
1.911 bisitz 7796: background:rgb(220,220,220);
1.693 droeschl 7797: }
7798:
1.721 harmsja 7799: div.LC_columnSection {
1.911 bisitz 7800: display: block;
7801: clear: both;
7802: overflow: hidden;
7803: margin: 0;
1.693 droeschl 7804: }
7805:
1.721 harmsja 7806: div.LC_columnSection>* {
1.911 bisitz 7807: float: left;
7808: margin: 10px 20px 10px 0;
7809: overflow:hidden;
1.693 droeschl 7810: }
1.721 harmsja 7811:
1.795 www 7812: table em {
1.911 bisitz 7813: font-weight: bold;
7814: font-style: normal;
1.748 schulted 7815: }
1.795 www 7816:
1.779 bisitz 7817: table.LC_tableBrowseRes,
1.795 www 7818: table.LC_tableOfContent {
1.911 bisitz 7819: border:none;
7820: border-spacing: 1px;
7821: padding: 3px;
7822: background-color: #FFFFFF;
7823: font-size: 90%;
1.753 droeschl 7824: }
1.789 droeschl 7825:
1.911 bisitz 7826: table.LC_tableOfContent {
7827: border-collapse: collapse;
1.789 droeschl 7828: }
7829:
1.771 droeschl 7830: table.LC_tableBrowseRes a,
1.768 schulted 7831: table.LC_tableOfContent a {
1.911 bisitz 7832: background-color: transparent;
7833: text-decoration: none;
1.753 droeschl 7834: }
7835:
1.795 www 7836: table.LC_tableOfContent img {
1.911 bisitz 7837: border: none;
7838: height: 1.3em;
7839: vertical-align: text-bottom;
7840: margin-right: 0.3em;
1.753 droeschl 7841: }
1.757 schulted 7842:
1.795 www 7843: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7844: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7845: }
7846:
1.795 www 7847: a#LC_content_toolbar_everything {
1.911 bisitz 7848: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7849: }
7850:
1.795 www 7851: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7852: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7853: }
7854:
1.795 www 7855: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7856: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7857: }
7858:
1.795 www 7859: a#LC_content_toolbar_changefolder {
1.911 bisitz 7860: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7861: }
7862:
1.795 www 7863: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7864: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7865: }
7866:
1.1043 raeburn 7867: a#LC_content_toolbar_edittoplevel {
7868: background-image:url(/res/adm/pages/edittoplevel.gif);
7869: }
7870:
1.795 www 7871: ul#LC_toolbar li a:hover {
1.911 bisitz 7872: background-position: bottom center;
1.757 schulted 7873: }
7874:
1.795 www 7875: ul#LC_toolbar {
1.911 bisitz 7876: padding: 0;
7877: margin: 2px;
7878: list-style:none;
7879: position:relative;
7880: background-color:white;
1.1082 raeburn 7881: overflow: auto;
1.757 schulted 7882: }
7883:
1.795 www 7884: ul#LC_toolbar li {
1.911 bisitz 7885: border:1px solid white;
7886: padding: 0;
7887: margin: 0;
7888: float: left;
7889: display:inline;
7890: vertical-align:middle;
1.1082 raeburn 7891: white-space: nowrap;
1.911 bisitz 7892: }
1.757 schulted 7893:
1.783 amueller 7894:
1.795 www 7895: a.LC_toolbarItem {
1.911 bisitz 7896: display:block;
7897: padding: 0;
7898: margin: 0;
7899: height: 32px;
7900: width: 32px;
7901: color:white;
7902: border: none;
7903: background-repeat:no-repeat;
7904: background-color:transparent;
1.757 schulted 7905: }
7906:
1.915 droeschl 7907: ul.LC_funclist {
7908: margin: 0;
7909: padding: 0.5em 1em 0.5em 0;
7910: }
7911:
1.933 droeschl 7912: ul.LC_funclist > li:first-child {
7913: font-weight:bold;
7914: margin-left:0.8em;
7915: }
7916:
1.915 droeschl 7917: ul.LC_funclist + ul.LC_funclist {
7918: /*
7919: left border as a seperator if we have more than
7920: one list
7921: */
7922: border-left: 1px solid $sidebg;
7923: /*
7924: this hides the left border behind the border of the
7925: outer box if element is wrapped to the next 'line'
7926: */
7927: margin-left: -1px;
7928: }
7929:
1.843 bisitz 7930: ul.LC_funclist li {
1.915 droeschl 7931: display: inline;
1.782 bisitz 7932: white-space: nowrap;
1.915 droeschl 7933: margin: 0 0 0 25px;
7934: line-height: 150%;
1.782 bisitz 7935: }
7936:
1.974 wenzelju 7937: .LC_hidden {
7938: display: none;
7939: }
7940:
1.1030 www 7941: .LCmodal-overlay {
7942: position:fixed;
7943: top:0;
7944: right:0;
7945: bottom:0;
7946: left:0;
7947: height:100%;
7948: width:100%;
7949: margin:0;
7950: padding:0;
7951: background:#999;
7952: opacity:.75;
7953: filter: alpha(opacity=75);
7954: -moz-opacity: 0.75;
7955: z-index:101;
7956: }
7957:
7958: * html .LCmodal-overlay {
7959: position: absolute;
7960: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7961: }
7962:
7963: .LCmodal-window {
7964: position:fixed;
7965: top:50%;
7966: left:50%;
7967: margin:0;
7968: padding:0;
7969: z-index:102;
7970: }
7971:
7972: * html .LCmodal-window {
7973: position:absolute;
7974: }
7975:
7976: .LCclose-window {
7977: position:absolute;
7978: width:32px;
7979: height:32px;
7980: right:8px;
7981: top:8px;
7982: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7983: text-indent:-99999px;
7984: overflow:hidden;
7985: cursor:pointer;
7986: }
7987:
1.1100 raeburn 7988: /*
1.1231 damieng 7989: styles used for response display
7990: */
7991: div.LC_radiofoil, div.LC_rankfoil {
7992: margin: .5em 0em .5em 0em;
7993: }
7994: table.LC_itemgroup {
7995: margin-top: 1em;
7996: }
7997:
7998: /*
1.1100 raeburn 7999: styles used by TTH when "Default set of options to pass to tth/m
8000: when converting TeX" in course settings has been set
8001:
8002: option passed: -t
8003:
8004: */
8005:
8006: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8007: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8008: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8009: td div.norm {line-height:normal;}
8010:
8011: /*
8012: option passed -y3
8013: */
8014:
8015: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8016: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8017: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8018:
1.1230 damieng 8019: /*
8020: sections with roles, for content only
8021: */
8022: section[class^="role-"] {
8023: padding-left: 10px;
8024: padding-right: 5px;
8025: margin-top: 8px;
8026: margin-bottom: 8px;
8027: border: 1px solid #2A4;
8028: border-radius: 5px;
8029: box-shadow: 0px 1px 1px #BBB;
8030: }
8031: section[class^="role-"]>h1 {
8032: position: relative;
8033: margin: 0px;
8034: padding-top: 10px;
8035: padding-left: 40px;
8036: }
8037: section[class^="role-"]>h1:before {
8038: position: absolute;
8039: left: -5px;
8040: top: 5px;
8041: }
8042: section.role-activity>h1:before {
8043: content:url('/adm/daxe/images/section_icons/activity.png');
8044: }
8045: section.role-advice>h1:before {
8046: content:url('/adm/daxe/images/section_icons/advice.png');
8047: }
8048: section.role-bibliography>h1:before {
8049: content:url('/adm/daxe/images/section_icons/bibliography.png');
8050: }
8051: section.role-citation>h1:before {
8052: content:url('/adm/daxe/images/section_icons/citation.png');
8053: }
8054: section.role-conclusion>h1:before {
8055: content:url('/adm/daxe/images/section_icons/conclusion.png');
8056: }
8057: section.role-definition>h1:before {
8058: content:url('/adm/daxe/images/section_icons/definition.png');
8059: }
8060: section.role-demonstration>h1:before {
8061: content:url('/adm/daxe/images/section_icons/demonstration.png');
8062: }
8063: section.role-example>h1:before {
8064: content:url('/adm/daxe/images/section_icons/example.png');
8065: }
8066: section.role-explanation>h1:before {
8067: content:url('/adm/daxe/images/section_icons/explanation.png');
8068: }
8069: section.role-introduction>h1:before {
8070: content:url('/adm/daxe/images/section_icons/introduction.png');
8071: }
8072: section.role-method>h1:before {
8073: content:url('/adm/daxe/images/section_icons/method.png');
8074: }
8075: section.role-more_information>h1:before {
8076: content:url('/adm/daxe/images/section_icons/more_information.png');
8077: }
8078: section.role-objectives>h1:before {
8079: content:url('/adm/daxe/images/section_icons/objectives.png');
8080: }
8081: section.role-prerequisites>h1:before {
8082: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8083: }
8084: section.role-remark>h1:before {
8085: content:url('/adm/daxe/images/section_icons/remark.png');
8086: }
8087: section.role-reminder>h1:before {
8088: content:url('/adm/daxe/images/section_icons/reminder.png');
8089: }
8090: section.role-summary>h1:before {
8091: content:url('/adm/daxe/images/section_icons/summary.png');
8092: }
8093: section.role-syntax>h1:before {
8094: content:url('/adm/daxe/images/section_icons/syntax.png');
8095: }
8096: section.role-warning>h1:before {
8097: content:url('/adm/daxe/images/section_icons/warning.png');
8098: }
8099:
1.343 albertel 8100: END
8101: }
8102:
1.306 albertel 8103: =pod
8104:
8105: =item * &headtag()
8106:
8107: Returns a uniform footer for LON-CAPA web pages.
8108:
1.307 albertel 8109: Inputs: $title - optional title for the head
8110: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8111: $args - optional arguments
1.319 albertel 8112: force_register - if is true call registerurl so the remote is
8113: informed
1.415 albertel 8114: redirect -> array ref of
8115: 1- seconds before redirect occurs
8116: 2- url to redirect to
8117: 3- whether the side effect should occur
1.315 albertel 8118: (side effect of setting
8119: $env{'internal.head.redirect'} to the url
8120: redirected too)
1.352 albertel 8121: domain -> force to color decorate a page for a specific
8122: domain
8123: function -> force usage of a specific rolish color scheme
8124: bgcolor -> override the default page bgcolor
1.460 albertel 8125: no_auto_mt_title
8126: -> prevent &mt()ing the title arg
1.464 albertel 8127:
1.306 albertel 8128: =cut
8129:
8130: sub headtag {
1.313 albertel 8131: my ($title,$head_extra,$args) = @_;
1.306 albertel 8132:
1.363 albertel 8133: my $function = $args->{'function'} || &get_users_function();
8134: my $domain = $args->{'domain'} || &determinedomain();
8135: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8136: my $httphost = $args->{'use_absolute'};
1.418 albertel 8137: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8138: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8139: #time(),
1.418 albertel 8140: $env{'environment.color.timestamp'},
1.363 albertel 8141: $function,$domain,$bgcolor);
8142:
1.369 www 8143: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8144:
1.308 albertel 8145: my $result =
8146: '<head>'.
1.1160 raeburn 8147: &font_settings($args);
1.319 albertel 8148:
1.1188 raeburn 8149: my $inhibitprint;
8150: if ($args->{'print_suppress'}) {
8151: $inhibitprint = &print_suppression();
8152: }
1.1064 raeburn 8153:
1.461 albertel 8154: if (!$args->{'frameset'}) {
8155: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8156: }
1.962 droeschl 8157: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8158: $result .= Apache::lonxml::display_title();
1.319 albertel 8159: }
1.436 albertel 8160: if (!$args->{'no_nav_bar'}
8161: && !$args->{'only_body'}
8162: && !$args->{'frameset'}) {
1.1154 raeburn 8163: $result .= &help_menu_js($httphost);
1.1032 www 8164: $result.=&modal_window();
1.1038 www 8165: $result.=&togglebox_script();
1.1034 www 8166: $result.=&wishlist_window();
1.1041 www 8167: $result.=&LCprogressbarUpdate_script();
1.1034 www 8168: } else {
8169: if ($args->{'add_modal'}) {
8170: $result.=&modal_window();
8171: }
8172: if ($args->{'add_wishlist'}) {
8173: $result.=&wishlist_window();
8174: }
1.1038 www 8175: if ($args->{'add_togglebox'}) {
8176: $result.=&togglebox_script();
8177: }
1.1041 www 8178: if ($args->{'add_progressbar'}) {
8179: $result.=&LCprogressbarUpdate_script();
8180: }
1.436 albertel 8181: }
1.314 albertel 8182: if (ref($args->{'redirect'})) {
1.414 albertel 8183: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8184: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8185: if (!$inhibit_continue) {
8186: $env{'internal.head.redirect'} = $url;
8187: }
1.313 albertel 8188: $result.=<<ADDMETA
8189: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8190: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8191: ADDMETA
1.1210 raeburn 8192: } else {
8193: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8194: my $requrl = $env{'request.uri'};
8195: if ($requrl eq '') {
8196: $requrl = $ENV{'REQUEST_URI'};
8197: $requrl =~ s/\?.+$//;
8198: }
8199: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8200: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8201: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8202: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8203: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8204: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
8205: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8206: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8207: if ($domdefs{'offloadnow'}{$lonhost}) {
8208: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8209: if (($newserver) && ($newserver ne $lonhost)) {
8210: my $numsec = 5;
8211: my $timeout = $numsec * 1000;
8212: my ($newurl,$locknum,%locks,$msg);
8213: if ($env{'request.role.adv'}) {
8214: ($locknum,%locks) = &Apache::lonnet::get_locks();
8215: }
8216: my $disable_submit = 0;
8217: if ($requrl =~ /$LONCAPA::assess_re/) {
8218: $disable_submit = 1;
8219: }
8220: if ($locknum) {
8221: my @lockinfo = sort(values(%locks));
8222: $msg = &mt('Once the following tasks are complete: ')."\\n".
8223: join(", ",sort(values(%locks)))."\\n".
8224: &mt('your session will be transferred to a different server, after you click "Roles".');
8225: } else {
8226: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8227: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
8228: }
8229: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8230: $newurl = '/adm/switchserver?otherserver='.$newserver;
8231: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8232: $newurl .= '&role='.$env{'request.role'};
8233: }
8234: if ($env{'request.symb'}) {
8235: $newurl .= '&symb='.$env{'request.symb'};
8236: } else {
8237: $newurl .= '&origurl='.$requrl;
8238: }
8239: }
1.1222 damieng 8240: &js_escape(\$msg);
1.1210 raeburn 8241: $result.=<<OFFLOAD
8242: <meta http-equiv="pragma" content="no-cache" />
8243: <script type="text/javascript">
1.1215 raeburn 8244: // <![CDATA[
1.1210 raeburn 8245: function LC_Offload_Now() {
8246: var dest = "$newurl";
8247: if (dest != '') {
8248: window.location.href="$newurl";
8249: }
8250: }
1.1214 raeburn 8251: \$(document).ready(function () {
8252: window.alert('$msg');
8253: if ($disable_submit) {
1.1210 raeburn 8254: \$(".LC_hwk_submit").prop("disabled", true);
8255: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8256: }
8257: setTimeout('LC_Offload_Now()', $timeout);
8258: });
1.1215 raeburn 8259: // ]]>
1.1210 raeburn 8260: </script>
8261: OFFLOAD
8262: }
8263: }
8264: }
8265: }
8266: }
8267: }
1.313 albertel 8268: }
1.306 albertel 8269: if (!defined($title)) {
8270: $title = 'The LearningOnline Network with CAPA';
8271: }
1.460 albertel 8272: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8273: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8274: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8275: if (!$args->{'frameset'}) {
8276: $result .= ' /';
8277: }
8278: $result .= '>'
1.1064 raeburn 8279: .$inhibitprint
1.414 albertel 8280: .$head_extra;
1.1242 raeburn 8281: my $clientmobile;
8282: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8283: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8284: } else {
8285: $clientmobile = $env{'browser.mobile'};
8286: }
8287: if ($clientmobile) {
1.1137 raeburn 8288: $result .= '
8289: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8290: <meta name="apple-mobile-web-app-capable" content="yes" />';
8291: }
1.962 droeschl 8292: return $result.'</head>';
1.306 albertel 8293: }
8294:
8295: =pod
8296:
1.340 albertel 8297: =item * &font_settings()
8298:
8299: Returns neccessary <meta> to set the proper encoding
8300:
1.1160 raeburn 8301: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8302:
8303: =cut
8304:
8305: sub font_settings {
1.1160 raeburn 8306: my ($args) = @_;
1.340 albertel 8307: my $headerstring='';
1.1160 raeburn 8308: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8309: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8310: $headerstring.=
8311: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8312: if (!$args->{'frameset'}) {
8313: $headerstring.= ' /';
8314: }
8315: $headerstring .= '>'."\n";
1.340 albertel 8316: }
8317: return $headerstring;
8318: }
8319:
1.341 albertel 8320: =pod
8321:
1.1064 raeburn 8322: =item * &print_suppression()
8323:
8324: In course context returns css which causes the body to be blank when media="print",
8325: if printout generation is unavailable for the current resource.
8326:
8327: This could be because:
8328:
8329: (a) printstartdate is in the future
8330:
8331: (b) printenddate is in the past
8332:
8333: (c) there is an active exam block with "printout"
8334: functionality blocked
8335:
8336: Users with pav, pfo or evb privileges are exempt.
8337:
8338: Inputs: none
8339:
8340: =cut
8341:
8342:
8343: sub print_suppression {
8344: my $noprint;
8345: if ($env{'request.course.id'}) {
8346: my $scope = $env{'request.course.id'};
8347: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8348: (&Apache::lonnet::allowed('pfo',$scope))) {
8349: return;
8350: }
8351: if ($env{'request.course.sec'} ne '') {
8352: $scope .= "/$env{'request.course.sec'}";
8353: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8354: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8355: return;
1.1064 raeburn 8356: }
8357: }
8358: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8359: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8360: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8361: if ($blocked) {
8362: my $checkrole = "cm./$cdom/$cnum";
8363: if ($env{'request.course.sec'} ne '') {
8364: $checkrole .= "/$env{'request.course.sec'}";
8365: }
8366: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8367: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8368: $noprint = 1;
8369: }
8370: }
8371: unless ($noprint) {
8372: my $symb = &Apache::lonnet::symbread();
8373: if ($symb ne '') {
8374: my $navmap = Apache::lonnavmaps::navmap->new();
8375: if (ref($navmap)) {
8376: my $res = $navmap->getBySymb($symb);
8377: if (ref($res)) {
8378: if (!$res->resprintable()) {
8379: $noprint = 1;
8380: }
8381: }
8382: }
8383: }
8384: }
8385: if ($noprint) {
8386: return <<"ENDSTYLE";
8387: <style type="text/css" media="print">
8388: body { display:none }
8389: </style>
8390: ENDSTYLE
8391: }
8392: }
8393: return;
8394: }
8395:
8396: =pod
8397:
1.341 albertel 8398: =item * &xml_begin()
8399:
8400: Returns the needed doctype and <html>
8401:
8402: Inputs: none
8403:
8404: =cut
8405:
8406: sub xml_begin {
1.1168 raeburn 8407: my ($is_frameset) = @_;
1.341 albertel 8408: my $output='';
8409:
8410: if ($env{'browser.mathml'}) {
8411: $output='<?xml version="1.0"?>'
8412: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8413: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8414:
8415: # .'<!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">] >'
8416: .'<!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">'
8417: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8418: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8419: } elsif ($is_frameset) {
8420: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8421: '<html>'."\n";
1.341 albertel 8422: } else {
1.1168 raeburn 8423: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8424: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8425: }
8426: return $output;
8427: }
1.340 albertel 8428:
8429: =pod
8430:
1.306 albertel 8431: =item * &start_page()
8432:
8433: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8434:
1.648 raeburn 8435: Inputs:
8436:
8437: =over 4
8438:
8439: $title - optional title for the page
8440:
8441: $head_extra - optional extra HTML to incude inside the <head>
8442:
8443: $args - additional optional args supported are:
8444:
8445: =over 8
8446:
8447: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8448: arg on
1.814 bisitz 8449: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8450: add_entries -> additional attributes to add to the <body>
8451: domain -> force to color decorate a page for a
1.317 albertel 8452: specific domain
1.648 raeburn 8453: function -> force usage of a specific rolish color
1.317 albertel 8454: scheme
1.648 raeburn 8455: redirect -> see &headtag()
8456: bgcolor -> override the default page bg color
8457: js_ready -> return a string ready for being used in
1.317 albertel 8458: a javascript writeln
1.648 raeburn 8459: html_encode -> return a string ready for being used in
1.320 albertel 8460: a html attribute
1.648 raeburn 8461: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8462: $forcereg arg
1.648 raeburn 8463: frameset -> if true will start with a <frameset>
1.330 albertel 8464: rather than <body>
1.648 raeburn 8465: skip_phases -> hash ref of
1.338 albertel 8466: head -> skip the <html><head> generation
8467: body -> skip all <body> generation
1.648 raeburn 8468: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8469: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8470: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 8471: group -> includes the current group, if page is for a
8472: specific group
1.361 albertel 8473:
1.648 raeburn 8474: =back
1.460 albertel 8475:
1.648 raeburn 8476: =back
1.562 albertel 8477:
1.306 albertel 8478: =cut
8479:
8480: sub start_page {
1.309 albertel 8481: my ($title,$head_extra,$args) = @_;
1.318 albertel 8482: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8483:
1.315 albertel 8484: $env{'internal.start_page'}++;
1.1096 raeburn 8485: my ($result,@advtools);
1.964 droeschl 8486:
1.338 albertel 8487: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8488: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8489: }
8490:
8491: if (! exists($args->{'skip_phases'}{'body'}) ) {
8492: if ($args->{'frameset'}) {
8493: my $attr_string = &make_attr_string($args->{'force_register'},
8494: $args->{'add_entries'});
8495: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8496: } else {
8497: $result .=
8498: &bodytag($title,
8499: $args->{'function'}, $args->{'add_entries'},
8500: $args->{'only_body'}, $args->{'domain'},
8501: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8502: $args->{'bgcolor'}, $args,
8503: \@advtools);
1.831 bisitz 8504: }
1.330 albertel 8505: }
1.338 albertel 8506:
1.315 albertel 8507: if ($args->{'js_ready'}) {
1.713 kaisler 8508: $result = &js_ready($result);
1.315 albertel 8509: }
1.320 albertel 8510: if ($args->{'html_encode'}) {
1.713 kaisler 8511: $result = &html_encode($result);
8512: }
8513:
1.813 bisitz 8514: # Preparation for new and consistent functionlist at top of screen
8515: # if ($args->{'functionlist'}) {
8516: # $result .= &build_functionlist();
8517: #}
8518:
1.964 droeschl 8519: # Don't add anything more if only_body wanted or in const space
8520: return $result if $args->{'only_body'}
8521: || $env{'request.state'} eq 'construct';
1.813 bisitz 8522:
8523: #Breadcrumbs
1.758 kaisler 8524: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8525: &Apache::lonhtmlcommon::clear_breadcrumbs();
8526: #if any br links exists, add them to the breadcrumbs
8527: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8528: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8529: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8530: }
8531: }
1.1096 raeburn 8532: # if @advtools array contains items add then to the breadcrumbs
8533: if (@advtools > 0) {
8534: &Apache::lonmenu::advtools_crumbs(@advtools);
8535: }
1.758 kaisler 8536:
8537: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8538: if(exists($args->{'bread_crumbs_component'})){
8539: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
1.1237 raeburn 8540: } elsif ($args->{'crstype'} eq 'Placement') {
8541: $result .= &Apache::lonhtmlcommon::breadcrumbs('','','','','','','','','',
8542: $args->{'crstype'});
8543: } else {
1.758 kaisler 8544: $result .= &Apache::lonhtmlcommon::breadcrumbs();
8545: }
1.320 albertel 8546: }
1.315 albertel 8547: return $result;
1.306 albertel 8548: }
8549:
8550: sub end_page {
1.315 albertel 8551: my ($args) = @_;
8552: $env{'internal.end_page'}++;
1.330 albertel 8553: my $result;
1.335 albertel 8554: if ($args->{'discussion'}) {
8555: my ($target,$parser);
8556: if (ref($args->{'discussion'})) {
8557: ($target,$parser) =($args->{'discussion'}{'target'},
8558: $args->{'discussion'}{'parser'});
8559: }
8560: $result .= &Apache::lonxml::xmlend($target,$parser);
8561: }
1.330 albertel 8562: if ($args->{'frameset'}) {
8563: $result .= '</frameset>';
8564: } else {
1.635 raeburn 8565: $result .= &endbodytag($args);
1.330 albertel 8566: }
1.1080 raeburn 8567: unless ($args->{'notbody'}) {
8568: $result .= "\n</html>";
8569: }
1.330 albertel 8570:
1.315 albertel 8571: if ($args->{'js_ready'}) {
1.317 albertel 8572: $result = &js_ready($result);
1.315 albertel 8573: }
1.335 albertel 8574:
1.320 albertel 8575: if ($args->{'html_encode'}) {
8576: $result = &html_encode($result);
8577: }
1.335 albertel 8578:
1.315 albertel 8579: return $result;
8580: }
8581:
1.1034 www 8582: sub wishlist_window {
8583: return(<<'ENDWISHLIST');
1.1046 raeburn 8584: <script type="text/javascript">
1.1034 www 8585: // <![CDATA[
8586: // <!-- BEGIN LON-CAPA Internal
8587: function set_wishlistlink(title, path) {
8588: if (!title) {
8589: title = document.title;
8590: title = title.replace(/^LON-CAPA /,'');
8591: }
1.1175 raeburn 8592: title = encodeURIComponent(title);
1.1203 raeburn 8593: title = title.replace("'","\\\'");
1.1034 www 8594: if (!path) {
8595: path = location.pathname;
8596: }
1.1175 raeburn 8597: path = encodeURIComponent(path);
1.1203 raeburn 8598: path = path.replace("'","\\\'");
1.1034 www 8599: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8600: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8601: }
8602: // END LON-CAPA Internal -->
8603: // ]]>
8604: </script>
8605: ENDWISHLIST
8606: }
8607:
1.1030 www 8608: sub modal_window {
8609: return(<<'ENDMODAL');
1.1046 raeburn 8610: <script type="text/javascript">
1.1030 www 8611: // <![CDATA[
8612: // <!-- BEGIN LON-CAPA Internal
8613: var modalWindow = {
8614: parent:"body",
8615: windowId:null,
8616: content:null,
8617: width:null,
8618: height:null,
8619: close:function()
8620: {
8621: $(".LCmodal-window").remove();
8622: $(".LCmodal-overlay").remove();
8623: },
8624: open:function()
8625: {
8626: var modal = "";
8627: modal += "<div class=\"LCmodal-overlay\"></div>";
8628: 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;\">";
8629: modal += this.content;
8630: modal += "</div>";
8631:
8632: $(this.parent).append(modal);
8633:
8634: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8635: $(".LCclose-window").click(function(){modalWindow.close();});
8636: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8637: }
8638: };
1.1140 raeburn 8639: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8640: {
1.1203 raeburn 8641: source = source.replace("'","'");
1.1030 www 8642: modalWindow.windowId = "myModal";
8643: modalWindow.width = width;
8644: modalWindow.height = height;
1.1196 raeburn 8645: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8646: modalWindow.open();
1.1208 raeburn 8647: };
1.1030 www 8648: // END LON-CAPA Internal -->
8649: // ]]>
8650: </script>
8651: ENDMODAL
8652: }
8653:
8654: sub modal_link {
1.1140 raeburn 8655: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8656: unless ($width) { $width=480; }
8657: unless ($height) { $height=400; }
1.1031 www 8658: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8659: unless ($transparency) { $transparency='true'; }
8660:
1.1074 raeburn 8661: my $target_attr;
8662: if (defined($target)) {
8663: $target_attr = 'target="'.$target.'"';
8664: }
8665: return <<"ENDLINK";
1.1140 raeburn 8666: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8667: $linktext</a>
8668: ENDLINK
1.1030 www 8669: }
8670:
1.1032 www 8671: sub modal_adhoc_script {
8672: my ($funcname,$width,$height,$content)=@_;
8673: return (<<ENDADHOC);
1.1046 raeburn 8674: <script type="text/javascript">
1.1032 www 8675: // <![CDATA[
8676: var $funcname = function()
8677: {
8678: modalWindow.windowId = "myModal";
8679: modalWindow.width = $width;
8680: modalWindow.height = $height;
8681: modalWindow.content = '$content';
8682: modalWindow.open();
8683: };
8684: // ]]>
8685: </script>
8686: ENDADHOC
8687: }
8688:
1.1041 www 8689: sub modal_adhoc_inner {
8690: my ($funcname,$width,$height,$content)=@_;
8691: my $innerwidth=$width-20;
8692: $content=&js_ready(
1.1140 raeburn 8693: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8694: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8695: $content.
1.1041 www 8696: &end_scrollbox().
1.1140 raeburn 8697: &end_page()
1.1041 www 8698: );
8699: return &modal_adhoc_script($funcname,$width,$height,$content);
8700: }
8701:
8702: sub modal_adhoc_window {
8703: my ($funcname,$width,$height,$content,$linktext)=@_;
8704: return &modal_adhoc_inner($funcname,$width,$height,$content).
8705: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8706: }
8707:
8708: sub modal_adhoc_launch {
8709: my ($funcname,$width,$height,$content)=@_;
8710: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8711: <script type="text/javascript">
8712: // <![CDATA[
8713: $funcname();
8714: // ]]>
8715: </script>
8716: ENDLAUNCH
8717: }
8718:
8719: sub modal_adhoc_close {
8720: return (<<ENDCLOSE);
8721: <script type="text/javascript">
8722: // <![CDATA[
8723: modalWindow.close();
8724: // ]]>
8725: </script>
8726: ENDCLOSE
8727: }
8728:
1.1038 www 8729: sub togglebox_script {
8730: return(<<ENDTOGGLE);
8731: <script type="text/javascript">
8732: // <![CDATA[
8733: function LCtoggleDisplay(id,hidetext,showtext) {
8734: link = document.getElementById(id + "link").childNodes[0];
8735: with (document.getElementById(id).style) {
8736: if (display == "none" ) {
8737: display = "inline";
8738: link.nodeValue = hidetext;
8739: } else {
8740: display = "none";
8741: link.nodeValue = showtext;
8742: }
8743: }
8744: }
8745: // ]]>
8746: </script>
8747: ENDTOGGLE
8748: }
8749:
1.1039 www 8750: sub start_togglebox {
8751: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8752: unless ($heading) { $heading=''; } else { $heading.=' '; }
8753: unless ($showtext) { $showtext=&mt('show'); }
8754: unless ($hidetext) { $hidetext=&mt('hide'); }
8755: unless ($headerbg) { $headerbg='#FFFFFF'; }
8756: return &start_data_table().
8757: &start_data_table_header_row().
8758: '<td bgcolor="'.$headerbg.'">'.$heading.
8759: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8760: $showtext.'\')">'.$showtext.'</a>]</td>'.
8761: &end_data_table_header_row().
8762: '<tr id="'.$id.'" style="display:none""><td>';
8763: }
8764:
8765: sub end_togglebox {
8766: return '</td></tr>'.&end_data_table();
8767: }
8768:
1.1041 www 8769: sub LCprogressbar_script {
1.1045 www 8770: my ($id)=@_;
1.1041 www 8771: return(<<ENDPROGRESS);
8772: <script type="text/javascript">
8773: // <![CDATA[
1.1045 www 8774: \$('#progressbar$id').progressbar({
1.1041 www 8775: value: 0,
8776: change: function(event, ui) {
8777: var newVal = \$(this).progressbar('option', 'value');
8778: \$('.pblabel', this).text(LCprogressTxt);
8779: }
8780: });
8781: // ]]>
8782: </script>
8783: ENDPROGRESS
8784: }
8785:
8786: sub LCprogressbarUpdate_script {
8787: return(<<ENDPROGRESSUPDATE);
8788: <style type="text/css">
8789: .ui-progressbar { position:relative; }
8790: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8791: </style>
8792: <script type="text/javascript">
8793: // <![CDATA[
1.1045 www 8794: var LCprogressTxt='---';
8795:
8796: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8797: LCprogressTxt=progresstext;
1.1045 www 8798: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8799: }
8800: // ]]>
8801: </script>
8802: ENDPROGRESSUPDATE
8803: }
8804:
1.1042 www 8805: my $LClastpercent;
1.1045 www 8806: my $LCidcnt;
8807: my $LCcurrentid;
1.1042 www 8808:
1.1041 www 8809: sub LCprogressbar {
1.1042 www 8810: my ($r)=(@_);
8811: $LClastpercent=0;
1.1045 www 8812: $LCidcnt++;
8813: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8814: my $starting=&mt('Starting');
8815: my $content=(<<ENDPROGBAR);
1.1045 www 8816: <div id="progressbar$LCcurrentid">
1.1041 www 8817: <span class="pblabel">$starting</span>
8818: </div>
8819: ENDPROGBAR
1.1045 www 8820: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8821: }
8822:
8823: sub LCprogressbarUpdate {
1.1042 www 8824: my ($r,$val,$text)=@_;
8825: unless ($val) {
8826: if ($LClastpercent) {
8827: $val=$LClastpercent;
8828: } else {
8829: $val=0;
8830: }
8831: }
1.1041 www 8832: if ($val<0) { $val=0; }
8833: if ($val>100) { $val=0; }
1.1042 www 8834: $LClastpercent=$val;
1.1041 www 8835: unless ($text) { $text=$val.'%'; }
8836: $text=&js_ready($text);
1.1044 www 8837: &r_print($r,<<ENDUPDATE);
1.1041 www 8838: <script type="text/javascript">
8839: // <![CDATA[
1.1045 www 8840: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8841: // ]]>
8842: </script>
8843: ENDUPDATE
1.1035 www 8844: }
8845:
1.1042 www 8846: sub LCprogressbarClose {
8847: my ($r)=@_;
8848: $LClastpercent=0;
1.1044 www 8849: &r_print($r,<<ENDCLOSE);
1.1042 www 8850: <script type="text/javascript">
8851: // <![CDATA[
1.1045 www 8852: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8853: // ]]>
8854: </script>
8855: ENDCLOSE
1.1044 www 8856: }
8857:
8858: sub r_print {
8859: my ($r,$to_print)=@_;
8860: if ($r) {
8861: $r->print($to_print);
8862: $r->rflush();
8863: } else {
8864: print($to_print);
8865: }
1.1042 www 8866: }
8867:
1.320 albertel 8868: sub html_encode {
8869: my ($result) = @_;
8870:
1.322 albertel 8871: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8872:
8873: return $result;
8874: }
1.1044 www 8875:
1.317 albertel 8876: sub js_ready {
8877: my ($result) = @_;
8878:
1.323 albertel 8879: $result =~ s/[\n\r]/ /xmsg;
8880: $result =~ s/\\/\\\\/xmsg;
8881: $result =~ s/'/\\'/xmsg;
1.372 albertel 8882: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8883:
8884: return $result;
8885: }
8886:
1.315 albertel 8887: sub validate_page {
8888: if ( exists($env{'internal.start_page'})
1.316 albertel 8889: && $env{'internal.start_page'} > 1) {
8890: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8891: $env{'internal.start_page'}.' '.
1.316 albertel 8892: $ENV{'request.filename'});
1.315 albertel 8893: }
8894: if ( exists($env{'internal.end_page'})
1.316 albertel 8895: && $env{'internal.end_page'} > 1) {
8896: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8897: $env{'internal.end_page'}.' '.
1.316 albertel 8898: $env{'request.filename'});
1.315 albertel 8899: }
8900: if ( exists($env{'internal.start_page'})
8901: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8902: &Apache::lonnet::logthis('start_page called without end_page '.
8903: $env{'request.filename'});
1.315 albertel 8904: }
8905: if ( ! exists($env{'internal.start_page'})
8906: && exists($env{'internal.end_page'})) {
1.316 albertel 8907: &Apache::lonnet::logthis('end_page called without start_page'.
8908: $env{'request.filename'});
1.315 albertel 8909: }
1.306 albertel 8910: }
1.315 albertel 8911:
1.996 www 8912:
8913: sub start_scrollbox {
1.1140 raeburn 8914: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8915: unless ($outerwidth) { $outerwidth='520px'; }
8916: unless ($width) { $width='500px'; }
8917: unless ($height) { $height='200px'; }
1.1075 raeburn 8918: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8919: if ($id ne '') {
1.1140 raeburn 8920: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 8921: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8922: }
1.1075 raeburn 8923: if ($bgcolor ne '') {
8924: $tdcol = "background-color: $bgcolor;";
8925: }
1.1137 raeburn 8926: my $nicescroll_js;
8927: if ($env{'browser.mobile'}) {
1.1140 raeburn 8928: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8929: }
8930: return <<"END";
8931: $nicescroll_js
8932:
8933: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
8934: <div style="overflow:auto; width:$width; height:$height;"$div_id>
8935: END
8936: }
8937:
8938: sub end_scrollbox {
8939: return '</div></td></tr></table>';
8940: }
8941:
8942: sub nicescroll_javascript {
8943: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8944: my %options;
8945: if (ref($cursor) eq 'HASH') {
8946: %options = %{$cursor};
8947: }
8948: unless ($options{'railalign'} =~ /^left|right$/) {
8949: $options{'railalign'} = 'left';
8950: }
8951: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8952: my $function = &get_users_function();
8953: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 8954: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 8955: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 8956: }
1.1140 raeburn 8957: }
8958: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8959: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 8960: $options{'cursoropacity'}='1.0';
8961: }
1.1140 raeburn 8962: } else {
8963: $options{'cursoropacity'}='1.0';
8964: }
8965: if ($options{'cursorfixedheight'} eq 'none') {
8966: delete($options{'cursorfixedheight'});
8967: } else {
8968: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8969: }
8970: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8971: delete($options{'railoffset'});
8972: }
8973: my @niceoptions;
8974: while (my($key,$value) = each(%options)) {
8975: if ($value =~ /^\{.+\}$/) {
8976: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 8977: } else {
1.1140 raeburn 8978: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 8979: }
1.1140 raeburn 8980: }
8981: my $nicescroll_js = '
1.1137 raeburn 8982: $(document).ready(
1.1140 raeburn 8983: function() {
8984: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8985: }
1.1137 raeburn 8986: );
8987: ';
1.1140 raeburn 8988: if ($framecheck) {
8989: $nicescroll_js .= '
8990: function expand_div(caller) {
8991: if (top === self) {
8992: document.getElementById("'.$id.'").style.width = "auto";
8993: document.getElementById("'.$id.'").style.height = "auto";
8994: } else {
8995: try {
8996: if (parent.frames) {
8997: if (parent.frames.length > 1) {
8998: var framesrc = parent.frames[1].location.href;
8999: var currsrc = framesrc.replace(/\#.*$/,"");
9000: if ((caller == "search") || (currsrc == "'.$location.'")) {
9001: document.getElementById("'.$id.'").style.width = "auto";
9002: document.getElementById("'.$id.'").style.height = "auto";
9003: }
9004: }
9005: }
9006: } catch (e) {
9007: return;
9008: }
1.1137 raeburn 9009: }
1.1140 raeburn 9010: return;
1.996 www 9011: }
1.1140 raeburn 9012: ';
9013: }
9014: if ($needjsready) {
9015: $nicescroll_js = '
9016: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9017: } else {
9018: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9019: }
9020: return $nicescroll_js;
1.996 www 9021: }
9022:
1.318 albertel 9023: sub simple_error_page {
1.1150 bisitz 9024: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 9025: if (ref($args) eq 'HASH') {
9026: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
9027: } else {
9028: $msg = &mt($msg);
9029: }
1.1150 bisitz 9030:
1.318 albertel 9031: my $page =
9032: &Apache::loncommon::start_page($title).
1.1150 bisitz 9033: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9034: &Apache::loncommon::end_page();
9035: if (ref($r)) {
9036: $r->print($page);
1.327 albertel 9037: return;
1.318 albertel 9038: }
9039: return $page;
9040: }
1.347 albertel 9041:
9042: {
1.610 albertel 9043: my @row_count;
1.961 onken 9044:
9045: sub start_data_table_count {
9046: unshift(@row_count, 0);
9047: return;
9048: }
9049:
9050: sub end_data_table_count {
9051: shift(@row_count);
9052: return;
9053: }
9054:
1.347 albertel 9055: sub start_data_table {
1.1018 raeburn 9056: my ($add_class,$id) = @_;
1.422 albertel 9057: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9058: my $table_id;
9059: if (defined($id)) {
9060: $table_id = ' id="'.$id.'"';
9061: }
1.961 onken 9062: &start_data_table_count();
1.1018 raeburn 9063: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9064: }
9065:
9066: sub end_data_table {
1.961 onken 9067: &end_data_table_count();
1.389 albertel 9068: return '</table>'."\n";;
1.347 albertel 9069: }
9070:
9071: sub start_data_table_row {
1.974 wenzelju 9072: my ($add_class, $id) = @_;
1.610 albertel 9073: $row_count[0]++;
9074: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9075: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9076: $id = (' id="'.$id.'"') unless ($id eq '');
9077: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9078: }
1.471 banghart 9079:
9080: sub continue_data_table_row {
1.974 wenzelju 9081: my ($add_class, $id) = @_;
1.610 albertel 9082: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9083: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9084: $id = (' id="'.$id.'"') unless ($id eq '');
9085: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9086: }
1.347 albertel 9087:
9088: sub end_data_table_row {
1.389 albertel 9089: return '</tr>'."\n";;
1.347 albertel 9090: }
1.367 www 9091:
1.421 albertel 9092: sub start_data_table_empty_row {
1.707 bisitz 9093: # $row_count[0]++;
1.421 albertel 9094: return '<tr class="LC_empty_row" >'."\n";;
9095: }
9096:
9097: sub end_data_table_empty_row {
9098: return '</tr>'."\n";;
9099: }
9100:
1.367 www 9101: sub start_data_table_header_row {
1.389 albertel 9102: return '<tr class="LC_header_row">'."\n";;
1.367 www 9103: }
9104:
9105: sub end_data_table_header_row {
1.389 albertel 9106: return '</tr>'."\n";;
1.367 www 9107: }
1.890 droeschl 9108:
9109: sub data_table_caption {
9110: my $caption = shift;
9111: return "<caption class=\"LC_caption\">$caption</caption>";
9112: }
1.347 albertel 9113: }
9114:
1.548 albertel 9115: =pod
9116:
9117: =item * &inhibit_menu_check($arg)
9118:
9119: Checks for a inhibitmenu state and generates output to preserve it
9120:
9121: Inputs: $arg - can be any of
9122: - undef - in which case the return value is a string
9123: to add into arguments list of a uri
9124: - 'input' - in which case the return value is a HTML
9125: <form> <input> field of type hidden to
9126: preserve the value
9127: - a url - in which case the return value is the url with
9128: the neccesary cgi args added to preserve the
9129: inhibitmenu state
9130: - a ref to a url - no return value, but the string is
9131: updated to include the neccessary cgi
9132: args to preserve the inhibitmenu state
9133:
9134: =cut
9135:
9136: sub inhibit_menu_check {
9137: my ($arg) = @_;
9138: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9139: if ($arg eq 'input') {
9140: if ($env{'form.inhibitmenu'}) {
9141: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9142: } else {
9143: return
9144: }
9145: }
9146: if ($env{'form.inhibitmenu'}) {
9147: if (ref($arg)) {
9148: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9149: } elsif ($arg eq '') {
9150: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9151: } else {
9152: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9153: }
9154: }
9155: if (!ref($arg)) {
9156: return $arg;
9157: }
9158: }
9159:
1.251 albertel 9160: ###############################################
1.182 matthew 9161:
9162: =pod
9163:
1.549 albertel 9164: =back
9165:
9166: =head1 User Information Routines
9167:
9168: =over 4
9169:
1.405 albertel 9170: =item * &get_users_function()
1.182 matthew 9171:
9172: Used by &bodytag to determine the current users primary role.
9173: Returns either 'student','coordinator','admin', or 'author'.
9174:
9175: =cut
9176:
9177: ###############################################
9178: sub get_users_function {
1.815 tempelho 9179: my $function = 'norole';
1.818 tempelho 9180: if ($env{'request.role'}=~/^(st)/) {
9181: $function='student';
9182: }
1.907 raeburn 9183: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9184: $function='coordinator';
9185: }
1.258 albertel 9186: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9187: $function='admin';
9188: }
1.826 bisitz 9189: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9190: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9191: $function='author';
9192: }
9193: return $function;
1.54 www 9194: }
1.99 www 9195:
9196: ###############################################
9197:
1.233 raeburn 9198: =pod
9199:
1.821 raeburn 9200: =item * &show_course()
9201:
9202: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9203: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9204:
9205: Inputs:
9206: None
9207:
9208: Outputs:
9209: Scalar: 1 if 'Course' to be used, 0 otherwise.
9210:
9211: =cut
9212:
9213: ###############################################
9214: sub show_course {
9215: my $course = !$env{'user.adv'};
9216: if (!$env{'user.adv'}) {
9217: foreach my $env (keys(%env)) {
9218: next if ($env !~ m/^user\.priv\./);
9219: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9220: $course = 0;
9221: last;
9222: }
9223: }
9224: }
9225: return $course;
9226: }
9227:
9228: ###############################################
9229:
9230: =pod
9231:
1.542 raeburn 9232: =item * &check_user_status()
1.274 raeburn 9233:
9234: Determines current status of supplied role for a
9235: specific user. Roles can be active, previous or future.
9236:
9237: Inputs:
9238: user's domain, user's username, course's domain,
1.375 raeburn 9239: course's number, optional section ID.
1.274 raeburn 9240:
9241: Outputs:
9242: role status: active, previous or future.
9243:
9244: =cut
9245:
9246: sub check_user_status {
1.412 raeburn 9247: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9248: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9249: my @uroles = keys(%userinfo);
1.274 raeburn 9250: my $srchstr;
9251: my $active_chk = 'none';
1.412 raeburn 9252: my $now = time;
1.274 raeburn 9253: if (@uroles > 0) {
1.908 raeburn 9254: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9255: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9256: } else {
1.412 raeburn 9257: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9258: }
9259: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9260: my $role_end = 0;
9261: my $role_start = 0;
9262: $active_chk = 'active';
1.412 raeburn 9263: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9264: $role_end = $1;
9265: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9266: $role_start = $1;
1.274 raeburn 9267: }
9268: }
9269: if ($role_start > 0) {
1.412 raeburn 9270: if ($now < $role_start) {
1.274 raeburn 9271: $active_chk = 'future';
9272: }
9273: }
9274: if ($role_end > 0) {
1.412 raeburn 9275: if ($now > $role_end) {
1.274 raeburn 9276: $active_chk = 'previous';
9277: }
9278: }
9279: }
9280: }
9281: return $active_chk;
9282: }
9283:
9284: ###############################################
9285:
9286: =pod
9287:
1.405 albertel 9288: =item * &get_sections()
1.233 raeburn 9289:
9290: Determines all the sections for a course including
9291: sections with students and sections containing other roles.
1.419 raeburn 9292: Incoming parameters:
9293:
9294: 1. domain
9295: 2. course number
9296: 3. reference to array containing roles for which sections should
9297: be gathered (optional).
9298: 4. reference to array containing status types for which sections
9299: should be gathered (optional).
9300:
9301: If the third argument is undefined, sections are gathered for any role.
9302: If the fourth argument is undefined, sections are gathered for any status.
9303: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9304:
1.374 raeburn 9305: Returns section hash (keys are section IDs, values are
9306: number of users in each section), subject to the
1.419 raeburn 9307: optional roles filter, optional status filter
1.233 raeburn 9308:
9309: =cut
9310:
9311: ###############################################
9312: sub get_sections {
1.419 raeburn 9313: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9314: if (!defined($cdom) || !defined($cnum)) {
9315: my $cid = $env{'request.course.id'};
9316:
9317: return if (!defined($cid));
9318:
9319: $cdom = $env{'course.'.$cid.'.domain'};
9320: $cnum = $env{'course.'.$cid.'.num'};
9321: }
9322:
9323: my %sectioncount;
1.419 raeburn 9324: my $now = time;
1.240 albertel 9325:
1.1118 raeburn 9326: my $check_students = 1;
9327: my $only_students = 0;
9328: if (ref($possible_roles) eq 'ARRAY') {
9329: if (grep(/^st$/,@{$possible_roles})) {
9330: if (@{$possible_roles} == 1) {
9331: $only_students = 1;
9332: }
9333: } else {
9334: $check_students = 0;
9335: }
9336: }
9337:
9338: if ($check_students) {
1.276 albertel 9339: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9340: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9341: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9342: my $start_index = &Apache::loncoursedata::CL_START();
9343: my $end_index = &Apache::loncoursedata::CL_END();
9344: my $status;
1.366 albertel 9345: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9346: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9347: $data->[$status_index],
9348: $data->[$start_index],
9349: $data->[$end_index]);
9350: if ($stu_status eq 'Active') {
9351: $status = 'active';
9352: } elsif ($end < $now) {
9353: $status = 'previous';
9354: } elsif ($start > $now) {
9355: $status = 'future';
9356: }
9357: if ($section ne '-1' && $section !~ /^\s*$/) {
9358: if ((!defined($possible_status)) || (($status ne '') &&
9359: (grep/^\Q$status\E$/,@{$possible_status}))) {
9360: $sectioncount{$section}++;
9361: }
1.240 albertel 9362: }
9363: }
9364: }
1.1118 raeburn 9365: if ($only_students) {
9366: return %sectioncount;
9367: }
1.240 albertel 9368: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9369: foreach my $user (sort(keys(%courseroles))) {
9370: if ($user !~ /^(\w{2})/) { next; }
9371: my ($role) = ($user =~ /^(\w{2})/);
9372: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9373: my ($section,$status);
1.240 albertel 9374: if ($role eq 'cr' &&
9375: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9376: $section=$1;
9377: }
9378: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9379: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9380: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9381: if ($end == -1 && $start == -1) {
9382: next; #deleted role
9383: }
9384: if (!defined($possible_status)) {
9385: $sectioncount{$section}++;
9386: } else {
9387: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9388: $status = 'active';
9389: } elsif ($end < $now) {
9390: $status = 'future';
9391: } elsif ($start > $now) {
9392: $status = 'previous';
9393: }
9394: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9395: $sectioncount{$section}++;
9396: }
9397: }
1.233 raeburn 9398: }
1.366 albertel 9399: return %sectioncount;
1.233 raeburn 9400: }
9401:
1.274 raeburn 9402: ###############################################
1.294 raeburn 9403:
9404: =pod
1.405 albertel 9405:
9406: =item * &get_course_users()
9407:
1.275 raeburn 9408: Retrieves usernames:domains for users in the specified course
9409: with specific role(s), and access status.
9410:
9411: Incoming parameters:
1.277 albertel 9412: 1. course domain
9413: 2. course number
9414: 3. access status: users must have - either active,
1.275 raeburn 9415: previous, future, or all.
1.277 albertel 9416: 4. reference to array of permissible roles
1.288 raeburn 9417: 5. reference to array of section restrictions (optional)
9418: 6. reference to results object (hash of hashes).
9419: 7. reference to optional userdata hash
1.609 raeburn 9420: 8. reference to optional statushash
1.630 raeburn 9421: 9. flag if privileged users (except those set to unhide in
9422: course settings) should be excluded
1.609 raeburn 9423: Keys of top level results hash are roles.
1.275 raeburn 9424: Keys of inner hashes are username:domain, with
9425: values set to access type.
1.288 raeburn 9426: Optional userdata hash returns an array with arguments in the
9427: same order as loncoursedata::get_classlist() for student data.
9428:
1.609 raeburn 9429: Optional statushash returns
9430:
1.288 raeburn 9431: Entries for end, start, section and status are blank because
9432: of the possibility of multiple values for non-student roles.
9433:
1.275 raeburn 9434: =cut
1.405 albertel 9435:
1.275 raeburn 9436: ###############################################
1.405 albertel 9437:
1.275 raeburn 9438: sub get_course_users {
1.630 raeburn 9439: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9440: my %idx = ();
1.419 raeburn 9441: my %seclists;
1.288 raeburn 9442:
9443: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9444: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9445: $idx{end} = &Apache::loncoursedata::CL_END();
9446: $idx{start} = &Apache::loncoursedata::CL_START();
9447: $idx{id} = &Apache::loncoursedata::CL_ID();
9448: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9449: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9450: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9451:
1.290 albertel 9452: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9453: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9454: my $now = time;
1.277 albertel 9455: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9456: my $match = 0;
1.412 raeburn 9457: my $secmatch = 0;
1.419 raeburn 9458: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9459: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9460: if ($section eq '') {
9461: $section = 'none';
9462: }
1.291 albertel 9463: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9464: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9465: $secmatch = 1;
9466: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9467: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9468: $secmatch = 1;
9469: }
9470: } else {
1.419 raeburn 9471: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9472: $secmatch = 1;
9473: }
1.290 albertel 9474: }
1.412 raeburn 9475: if (!$secmatch) {
9476: next;
9477: }
1.419 raeburn 9478: }
1.275 raeburn 9479: if (defined($$types{'active'})) {
1.288 raeburn 9480: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9481: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9482: $match = 1;
1.275 raeburn 9483: }
9484: }
9485: if (defined($$types{'previous'})) {
1.609 raeburn 9486: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9487: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9488: $match = 1;
1.275 raeburn 9489: }
9490: }
9491: if (defined($$types{'future'})) {
1.609 raeburn 9492: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9493: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9494: $match = 1;
1.275 raeburn 9495: }
9496: }
1.609 raeburn 9497: if ($match) {
9498: push(@{$seclists{$student}},$section);
9499: if (ref($userdata) eq 'HASH') {
9500: $$userdata{$student} = $$classlist{$student};
9501: }
9502: if (ref($statushash) eq 'HASH') {
9503: $statushash->{$student}{'st'}{$section} = $status;
9504: }
1.288 raeburn 9505: }
1.275 raeburn 9506: }
9507: }
1.412 raeburn 9508: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9509: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9510: my $now = time;
1.609 raeburn 9511: my %displaystatus = ( previous => 'Expired',
9512: active => 'Active',
9513: future => 'Future',
9514: );
1.1121 raeburn 9515: my (%nothide,@possdoms);
1.630 raeburn 9516: if ($hidepriv) {
9517: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9518: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9519: if ($user !~ /:/) {
9520: $nothide{join(':',split(/[\@]/,$user))}=1;
9521: } else {
9522: $nothide{$user} = 1;
9523: }
9524: }
1.1121 raeburn 9525: my @possdoms = ($cdom);
9526: if ($coursehash{'checkforpriv'}) {
9527: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9528: }
1.630 raeburn 9529: }
1.439 raeburn 9530: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9531: my $match = 0;
1.412 raeburn 9532: my $secmatch = 0;
1.439 raeburn 9533: my $status;
1.412 raeburn 9534: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9535: $user =~ s/:$//;
1.439 raeburn 9536: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9537: if ($end == -1 || $start == -1) {
9538: next;
9539: }
9540: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9541: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9542: my ($uname,$udom) = split(/:/,$user);
9543: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9544: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9545: $secmatch = 1;
9546: } elsif ($usec eq '') {
1.420 albertel 9547: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9548: $secmatch = 1;
9549: }
9550: } else {
9551: if (grep(/^\Q$usec\E$/,@{$sections})) {
9552: $secmatch = 1;
9553: }
9554: }
9555: if (!$secmatch) {
9556: next;
9557: }
1.288 raeburn 9558: }
1.419 raeburn 9559: if ($usec eq '') {
9560: $usec = 'none';
9561: }
1.275 raeburn 9562: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9563: if ($hidepriv) {
1.1121 raeburn 9564: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9565: (!$nothide{$uname.':'.$udom})) {
9566: next;
9567: }
9568: }
1.503 raeburn 9569: if ($end > 0 && $end < $now) {
1.439 raeburn 9570: $status = 'previous';
9571: } elsif ($start > $now) {
9572: $status = 'future';
9573: } else {
9574: $status = 'active';
9575: }
1.277 albertel 9576: foreach my $type (keys(%{$types})) {
1.275 raeburn 9577: if ($status eq $type) {
1.420 albertel 9578: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9579: push(@{$$users{$role}{$user}},$type);
9580: }
1.288 raeburn 9581: $match = 1;
9582: }
9583: }
1.419 raeburn 9584: if (($match) && (ref($userdata) eq 'HASH')) {
9585: if (!exists($$userdata{$uname.':'.$udom})) {
9586: &get_user_info($udom,$uname,\%idx,$userdata);
9587: }
1.420 albertel 9588: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9589: push(@{$seclists{$uname.':'.$udom}},$usec);
9590: }
1.609 raeburn 9591: if (ref($statushash) eq 'HASH') {
9592: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9593: }
1.275 raeburn 9594: }
9595: }
9596: }
9597: }
1.290 albertel 9598: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9599: if ((defined($cdom)) && (defined($cnum))) {
9600: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9601: if ( defined($csettings{'internal.courseowner'}) ) {
9602: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9603: next if ($owner eq '');
9604: my ($ownername,$ownerdom);
9605: if ($owner =~ /^([^:]+):([^:]+)$/) {
9606: $ownername = $1;
9607: $ownerdom = $2;
9608: } else {
9609: $ownername = $owner;
9610: $ownerdom = $cdom;
9611: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9612: }
9613: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9614: if (defined($userdata) &&
1.609 raeburn 9615: !exists($$userdata{$owner})) {
9616: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9617: if (!grep(/^none$/,@{$seclists{$owner}})) {
9618: push(@{$seclists{$owner}},'none');
9619: }
9620: if (ref($statushash) eq 'HASH') {
9621: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9622: }
1.290 albertel 9623: }
1.279 raeburn 9624: }
9625: }
9626: }
1.419 raeburn 9627: foreach my $user (keys(%seclists)) {
9628: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9629: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9630: }
1.275 raeburn 9631: }
9632: return;
9633: }
9634:
1.288 raeburn 9635: sub get_user_info {
9636: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9637: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9638: &plainname($uname,$udom,'lastname');
1.291 albertel 9639: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9640: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9641: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9642: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9643: return;
9644: }
1.275 raeburn 9645:
1.472 raeburn 9646: ###############################################
9647:
9648: =pod
9649:
9650: =item * &get_user_quota()
9651:
1.1134 raeburn 9652: Retrieves quota assigned for storage of user files.
9653: Default is to report quota for portfolio files.
1.472 raeburn 9654:
9655: Incoming parameters:
9656: 1. user's username
9657: 2. user's domain
1.1134 raeburn 9658: 3. quota name - portfolio, author, or course
1.1136 raeburn 9659: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 9660: 4. crstype - official, unofficial, textbook, placement or community,
9661: if quota name is course
1.472 raeburn 9662:
9663: Returns:
1.1163 raeburn 9664: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9665: 2. (Optional) Type of setting: custom or default
9666: (individually assigned or default for user's
9667: institutional status).
9668: 3. (Optional) - User's institutional status (e.g., faculty, staff
9669: or student - types as defined in localenroll::inst_usertypes
9670: for user's domain, which determines default quota for user.
9671: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9672:
9673: If a value has been stored in the user's environment,
1.536 raeburn 9674: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9675: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9676:
9677: =cut
9678:
9679: ###############################################
9680:
9681:
9682: sub get_user_quota {
1.1136 raeburn 9683: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9684: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9685: if (!defined($udom)) {
9686: $udom = $env{'user.domain'};
9687: }
9688: if (!defined($uname)) {
9689: $uname = $env{'user.name'};
9690: }
9691: if (($udom eq '' || $uname eq '') ||
9692: ($udom eq 'public') && ($uname eq 'public')) {
9693: $quota = 0;
1.536 raeburn 9694: $quotatype = 'default';
9695: $defquota = 0;
1.472 raeburn 9696: } else {
1.536 raeburn 9697: my $inststatus;
1.1134 raeburn 9698: if ($quotaname eq 'course') {
9699: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9700: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9701: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9702: } else {
9703: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9704: $quota = $cenv{'internal.uploadquota'};
9705: }
1.536 raeburn 9706: } else {
1.1134 raeburn 9707: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9708: if ($quotaname eq 'author') {
9709: $quota = $env{'environment.authorquota'};
9710: } else {
9711: $quota = $env{'environment.portfolioquota'};
9712: }
9713: $inststatus = $env{'environment.inststatus'};
9714: } else {
9715: my %userenv =
9716: &Apache::lonnet::get('environment',['portfolioquota',
9717: 'authorquota','inststatus'],$udom,$uname);
9718: my ($tmp) = keys(%userenv);
9719: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9720: if ($quotaname eq 'author') {
9721: $quota = $userenv{'authorquota'};
9722: } else {
9723: $quota = $userenv{'portfolioquota'};
9724: }
9725: $inststatus = $userenv{'inststatus'};
9726: } else {
9727: undef(%userenv);
9728: }
9729: }
9730: }
9731: if ($quota eq '' || wantarray) {
9732: if ($quotaname eq 'course') {
9733: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 9734: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 9735: ($crstype eq 'community') || ($crstype eq 'textbook') ||
9736: ($crstype eq 'placement')) {
1.1136 raeburn 9737: $defquota = $domdefs{$crstype.'quota'};
9738: }
9739: if ($defquota eq '') {
9740: $defquota = 500;
9741: }
1.1134 raeburn 9742: } else {
9743: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9744: }
9745: if ($quota eq '') {
9746: $quota = $defquota;
9747: $quotatype = 'default';
9748: } else {
9749: $quotatype = 'custom';
9750: }
1.472 raeburn 9751: }
9752: }
1.536 raeburn 9753: if (wantarray) {
9754: return ($quota,$quotatype,$settingstatus,$defquota);
9755: } else {
9756: return $quota;
9757: }
1.472 raeburn 9758: }
9759:
9760: ###############################################
9761:
9762: =pod
9763:
9764: =item * &default_quota()
9765:
1.536 raeburn 9766: Retrieves default quota assigned for storage of user portfolio files,
9767: given an (optional) user's institutional status.
1.472 raeburn 9768:
9769: Incoming parameters:
1.1142 raeburn 9770:
1.472 raeburn 9771: 1. domain
1.536 raeburn 9772: 2. (Optional) institutional status(es). This is a : separated list of
9773: status types (e.g., faculty, staff, student etc.)
9774: which apply to the user for whom the default is being retrieved.
9775: If the institutional status string in undefined, the domain
1.1134 raeburn 9776: default quota will be returned.
9777: 3. quota name - portfolio, author, or course
9778: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9779:
9780: Returns:
1.1142 raeburn 9781:
1.1163 raeburn 9782: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9783: 2. (Optional) institutional type which determined the value of the
9784: default quota.
1.472 raeburn 9785:
9786: If a value has been stored in the domain's configuration db,
9787: it will return that, otherwise it returns 20 (for backwards
9788: compatibility with domains which have not set up a configuration
1.1163 raeburn 9789: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9790:
1.536 raeburn 9791: If the user's status includes multiple types (e.g., staff and student),
9792: the largest default quota which applies to the user determines the
9793: default quota returned.
9794:
1.472 raeburn 9795: =cut
9796:
9797: ###############################################
9798:
9799:
9800: sub default_quota {
1.1134 raeburn 9801: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9802: my ($defquota,$settingstatus);
9803: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9804: ['quotas'],$udom);
1.1134 raeburn 9805: my $key = 'defaultquota';
9806: if ($quotaname eq 'author') {
9807: $key = 'authorquota';
9808: }
1.622 raeburn 9809: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9810: if ($inststatus ne '') {
1.765 raeburn 9811: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9812: foreach my $item (@statuses) {
1.1134 raeburn 9813: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9814: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9815: if ($defquota eq '') {
1.1134 raeburn 9816: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9817: $settingstatus = $item;
1.1134 raeburn 9818: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9819: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9820: $settingstatus = $item;
9821: }
9822: }
1.1134 raeburn 9823: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9824: if ($quotahash{'quotas'}{$item} ne '') {
9825: if ($defquota eq '') {
9826: $defquota = $quotahash{'quotas'}{$item};
9827: $settingstatus = $item;
9828: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9829: $defquota = $quotahash{'quotas'}{$item};
9830: $settingstatus = $item;
9831: }
1.536 raeburn 9832: }
9833: }
9834: }
9835: }
9836: if ($defquota eq '') {
1.1134 raeburn 9837: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9838: $defquota = $quotahash{'quotas'}{$key}{'default'};
9839: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9840: $defquota = $quotahash{'quotas'}{'default'};
9841: }
1.536 raeburn 9842: $settingstatus = 'default';
1.1139 raeburn 9843: if ($defquota eq '') {
9844: if ($quotaname eq 'author') {
9845: $defquota = 500;
9846: }
9847: }
1.536 raeburn 9848: }
9849: } else {
9850: $settingstatus = 'default';
1.1134 raeburn 9851: if ($quotaname eq 'author') {
9852: $defquota = 500;
9853: } else {
9854: $defquota = 20;
9855: }
1.536 raeburn 9856: }
9857: if (wantarray) {
9858: return ($defquota,$settingstatus);
1.472 raeburn 9859: } else {
1.536 raeburn 9860: return $defquota;
1.472 raeburn 9861: }
9862: }
9863:
1.1135 raeburn 9864: ###############################################
9865:
9866: =pod
9867:
1.1136 raeburn 9868: =item * &excess_filesize_warning()
1.1135 raeburn 9869:
9870: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 9871: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 9872: space to be exceeded.
1.1136 raeburn 9873:
9874: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 9875: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 9876:
1.1165 raeburn 9877: Inputs: 7
1.1136 raeburn 9878: 1. username or coursenum
1.1135 raeburn 9879: 2. domain
1.1136 raeburn 9880: 3. context ('author' or 'course')
1.1135 raeburn 9881: 4. filename of file for which action is being requested
9882: 5. filesize (kB) of file
9883: 6. action being taken: copy or upload.
1.1237 raeburn 9884: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 9885:
9886: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 9887: otherwise return null.
9888:
9889: =back
1.1135 raeburn 9890:
9891: =cut
9892:
1.1136 raeburn 9893: sub excess_filesize_warning {
1.1165 raeburn 9894: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 9895: my $current_disk_usage = 0;
1.1165 raeburn 9896: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 9897: if ($context eq 'author') {
9898: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9899: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9900: } else {
9901: foreach my $subdir ('docs','supplemental') {
9902: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9903: }
9904: }
1.1135 raeburn 9905: $disk_quota = int($disk_quota * 1000);
9906: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 9907: return '<p class="LC_warning">'.
1.1135 raeburn 9908: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 9909: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9910: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 9911: $disk_quota,$current_disk_usage).
9912: '</p>';
9913: }
9914: return;
9915: }
9916:
9917: ###############################################
9918:
9919:
1.1136 raeburn 9920:
9921:
1.384 raeburn 9922: sub get_secgrprole_info {
9923: my ($cdom,$cnum,$needroles,$type) = @_;
9924: my %sections_count = &get_sections($cdom,$cnum);
9925: my @sections = (sort {$a <=> $b} keys(%sections_count));
9926: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9927: my @groups = sort(keys(%curr_groups));
9928: my $allroles = [];
9929: my $rolehash;
9930: my $accesshash = {
9931: active => 'Currently has access',
9932: future => 'Will have future access',
9933: previous => 'Previously had access',
9934: };
9935: if ($needroles) {
9936: $rolehash = {'all' => 'all'};
1.385 albertel 9937: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9938: if (&Apache::lonnet::error(%user_roles)) {
9939: undef(%user_roles);
9940: }
9941: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9942: my ($role)=split(/\:/,$item,2);
9943: if ($role eq 'cr') { next; }
9944: if ($role =~ /^cr/) {
9945: $$rolehash{$role} = (split('/',$role))[3];
9946: } else {
9947: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9948: }
9949: }
9950: foreach my $key (sort(keys(%{$rolehash}))) {
9951: push(@{$allroles},$key);
9952: }
9953: push (@{$allroles},'st');
9954: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9955: }
9956: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9957: }
9958:
1.555 raeburn 9959: sub user_picker {
1.994 raeburn 9960: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9961: my $currdom = $dom;
9962: my %curr_selected = (
9963: srchin => 'dom',
1.580 raeburn 9964: srchby => 'lastname',
1.555 raeburn 9965: );
9966: my $srchterm;
1.625 raeburn 9967: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9968: if ($srch->{'srchby'} ne '') {
9969: $curr_selected{'srchby'} = $srch->{'srchby'};
9970: }
9971: if ($srch->{'srchin'} ne '') {
9972: $curr_selected{'srchin'} = $srch->{'srchin'};
9973: }
9974: if ($srch->{'srchtype'} ne '') {
9975: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9976: }
9977: if ($srch->{'srchdomain'} ne '') {
9978: $currdom = $srch->{'srchdomain'};
9979: }
9980: $srchterm = $srch->{'srchterm'};
9981: }
1.1222 damieng 9982: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9983: 'usr' => 'Search criteria',
1.563 raeburn 9984: 'doma' => 'Domain/institution to search',
1.558 albertel 9985: 'uname' => 'username',
9986: 'lastname' => 'last name',
1.555 raeburn 9987: 'lastfirst' => 'last name, first name',
1.558 albertel 9988: 'crs' => 'in this course',
1.576 raeburn 9989: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9990: 'alc' => 'all LON-CAPA',
1.573 raeburn 9991: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9992: 'exact' => 'is',
9993: 'contains' => 'contains',
1.569 raeburn 9994: 'begins' => 'begins with',
1.1222 damieng 9995: );
9996: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9997: 'youm' => "You must include some text to search for.",
9998: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9999: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10000: 'yomc' => "You must choose a domain when using an institutional directory search.",
10001: 'ymcd' => "You must choose a domain when using a domain search.",
10002: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10003: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10004: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10005: );
1.1222 damieng 10006: &html_escape(\%html_lt);
10007: &js_escape(\%js_lt);
1.563 raeburn 10008: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
10009: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10010:
10011: my @srchins = ('crs','dom','alc','instd');
10012:
10013: foreach my $option (@srchins) {
10014: # FIXME 'alc' option unavailable until
10015: # loncreateuser::print_user_query_page()
10016: # has been completed.
10017: next if ($option eq 'alc');
1.880 raeburn 10018: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10019: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 10020: if ($curr_selected{'srchin'} eq $option) {
10021: $srchinsel .= '
1.1222 damieng 10022: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10023: } else {
10024: $srchinsel .= '
1.1222 damieng 10025: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10026: }
1.555 raeburn 10027: }
1.563 raeburn 10028: $srchinsel .= "\n </select>\n";
1.555 raeburn 10029:
10030: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10031: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10032: if ($curr_selected{'srchby'} eq $option) {
10033: $srchbysel .= '
1.1222 damieng 10034: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10035: } else {
10036: $srchbysel .= '
1.1222 damieng 10037: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10038: }
10039: }
10040: $srchbysel .= "\n </select>\n";
10041:
10042: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10043: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10044: if ($curr_selected{'srchtype'} eq $option) {
10045: $srchtypesel .= '
1.1222 damieng 10046: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10047: } else {
10048: $srchtypesel .= '
1.1222 damieng 10049: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10050: }
10051: }
10052: $srchtypesel .= "\n </select>\n";
10053:
1.558 albertel 10054: my ($newuserscript,$new_user_create);
1.994 raeburn 10055: my $context_dom = $env{'request.role.domain'};
10056: if ($context eq 'requestcrs') {
10057: if ($env{'form.coursedom'} ne '') {
10058: $context_dom = $env{'form.coursedom'};
10059: }
10060: }
1.556 raeburn 10061: if ($forcenewuser) {
1.576 raeburn 10062: if (ref($srch) eq 'HASH') {
1.994 raeburn 10063: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10064: if ($cancreate) {
10065: $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>';
10066: } else {
1.799 bisitz 10067: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10068: my %usertypetext = (
10069: official => 'institutional',
10070: unofficial => 'non-institutional',
10071: );
1.799 bisitz 10072: $new_user_create = '<p class="LC_warning">'
10073: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10074: .' '
10075: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10076: ,'<a href="'.$helplink.'">','</a>')
10077: .'</p><br />';
1.627 raeburn 10078: }
1.576 raeburn 10079: }
10080: }
10081:
1.556 raeburn 10082: $newuserscript = <<"ENDSCRIPT";
10083:
1.570 raeburn 10084: function setSearch(createnew,callingForm) {
1.556 raeburn 10085: if (createnew == 1) {
1.570 raeburn 10086: for (var i=0; i<callingForm.srchby.length; i++) {
10087: if (callingForm.srchby.options[i].value == 'uname') {
10088: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10089: }
10090: }
1.570 raeburn 10091: for (var i=0; i<callingForm.srchin.length; i++) {
10092: if ( callingForm.srchin.options[i].value == 'dom') {
10093: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10094: }
10095: }
1.570 raeburn 10096: for (var i=0; i<callingForm.srchtype.length; i++) {
10097: if (callingForm.srchtype.options[i].value == 'exact') {
10098: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10099: }
10100: }
1.570 raeburn 10101: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10102: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10103: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10104: }
10105: }
10106: }
10107: }
10108: ENDSCRIPT
1.558 albertel 10109:
1.556 raeburn 10110: }
10111:
1.555 raeburn 10112: my $output = <<"END_BLOCK";
1.556 raeburn 10113: <script type="text/javascript">
1.824 bisitz 10114: // <![CDATA[
1.570 raeburn 10115: function validateEntry(callingForm) {
1.558 albertel 10116:
1.556 raeburn 10117: var checkok = 1;
1.558 albertel 10118: var srchin;
1.570 raeburn 10119: for (var i=0; i<callingForm.srchin.length; i++) {
10120: if ( callingForm.srchin[i].checked ) {
10121: srchin = callingForm.srchin[i].value;
1.558 albertel 10122: }
10123: }
10124:
1.570 raeburn 10125: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10126: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10127: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10128: var srchterm = callingForm.srchterm.value;
10129: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10130: var msg = "";
10131:
10132: if (srchterm == "") {
10133: checkok = 0;
1.1222 damieng 10134: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10135: }
10136:
1.569 raeburn 10137: if (srchtype== 'begins') {
10138: if (srchterm.length < 2) {
10139: checkok = 0;
1.1222 damieng 10140: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10141: }
10142: }
10143:
1.556 raeburn 10144: if (srchtype== 'contains') {
10145: if (srchterm.length < 3) {
10146: checkok = 0;
1.1222 damieng 10147: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10148: }
10149: }
10150: if (srchin == 'instd') {
10151: if (srchdomain == '') {
10152: checkok = 0;
1.1222 damieng 10153: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10154: }
10155: }
10156: if (srchin == 'dom') {
10157: if (srchdomain == '') {
10158: checkok = 0;
1.1222 damieng 10159: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10160: }
10161: }
10162: if (srchby == 'lastfirst') {
10163: if (srchterm.indexOf(",") == -1) {
10164: checkok = 0;
1.1222 damieng 10165: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10166: }
10167: if (srchterm.indexOf(",") == srchterm.length -1) {
10168: checkok = 0;
1.1222 damieng 10169: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10170: }
10171: }
10172: if (checkok == 0) {
1.1222 damieng 10173: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10174: return;
10175: }
10176: if (checkok == 1) {
1.570 raeburn 10177: callingForm.submit();
1.556 raeburn 10178: }
10179: }
10180:
10181: $newuserscript
10182:
1.824 bisitz 10183: // ]]>
1.556 raeburn 10184: </script>
1.558 albertel 10185:
10186: $new_user_create
10187:
1.555 raeburn 10188: END_BLOCK
1.558 albertel 10189:
1.876 raeburn 10190: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10191: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10192: $domform.
10193: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10194: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10195: $srchbysel.
10196: $srchtypesel.
10197: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10198: $srchinsel.
10199: &Apache::lonhtmlcommon::row_closure(1).
10200: &Apache::lonhtmlcommon::end_pick_box().
10201: '<br />';
1.555 raeburn 10202: return $output;
10203: }
10204:
1.612 raeburn 10205: sub user_rule_check {
1.615 raeburn 10206: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10207: my ($response,%inst_response);
1.612 raeburn 10208: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10209: if (keys(%{$usershash}) > 1) {
10210: my (%by_username,%by_id,%userdoms);
10211: my $checkid;
10212: if (ref($checks) eq 'HASH') {
10213: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10214: $checkid = 1;
10215: }
10216: }
10217: foreach my $user (keys(%{$usershash})) {
10218: my ($uname,$udom) = split(/:/,$user);
10219: if ($checkid) {
10220: if (ref($usershash->{$user}) eq 'HASH') {
10221: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10222: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10223: $userdoms{$udom} = 1;
1.1227 raeburn 10224: if (ref($inst_results) eq 'HASH') {
10225: $inst_results->{$uname.':'.$udom} = {};
10226: }
1.1226 raeburn 10227: }
10228: }
10229: } else {
10230: $by_username{$udom}{$uname} = 1;
10231: $userdoms{$udom} = 1;
1.1227 raeburn 10232: if (ref($inst_results) eq 'HASH') {
10233: $inst_results->{$uname.':'.$udom} = {};
10234: }
1.1226 raeburn 10235: }
10236: }
10237: foreach my $udom (keys(%userdoms)) {
10238: if (!$got_rules->{$udom}) {
10239: my %domconfig = &Apache::lonnet::get_dom('configuration',
10240: ['usercreation'],$udom);
10241: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10242: foreach my $item ('username','id') {
10243: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10244: $$curr_rules{$udom}{$item} =
10245: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10246: }
10247: }
10248: }
10249: $got_rules->{$udom} = 1;
10250: }
1.612 raeburn 10251: }
1.1226 raeburn 10252: if ($checkid) {
10253: foreach my $udom (keys(%by_id)) {
10254: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10255: if ($outcome eq 'ok') {
1.1227 raeburn 10256: foreach my $id (keys(%{$by_id{$udom}})) {
10257: my $uname = $by_id{$udom}{$id};
10258: $inst_response{$uname.':'.$udom} = $outcome;
10259: }
1.1226 raeburn 10260: if (ref($results) eq 'HASH') {
10261: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10262: if (exists($inst_response{$uname.':'.$udom})) {
10263: $inst_response{$uname.':'.$udom} = $outcome;
10264: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10265: }
1.1226 raeburn 10266: }
10267: }
10268: }
1.612 raeburn 10269: }
1.615 raeburn 10270: } else {
1.1226 raeburn 10271: foreach my $udom (keys(%by_username)) {
10272: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10273: if ($outcome eq 'ok') {
1.1227 raeburn 10274: foreach my $uname (keys(%{$by_username{$udom}})) {
10275: $inst_response{$uname.':'.$udom} = $outcome;
10276: }
1.1226 raeburn 10277: if (ref($results) eq 'HASH') {
10278: foreach my $uname (keys(%{$results})) {
10279: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10280: }
10281: }
10282: }
10283: }
1.612 raeburn 10284: }
1.1226 raeburn 10285: } elsif (keys(%{$usershash}) == 1) {
10286: my $user = (keys(%{$usershash}))[0];
10287: my ($uname,$udom) = split(/:/,$user);
10288: if (($udom ne '') && ($uname ne '')) {
10289: if (ref($usershash->{$user}) eq 'HASH') {
10290: if (ref($checks) eq 'HASH') {
10291: if (defined($checks->{'username'})) {
10292: ($inst_response{$user},%{$inst_results->{$user}}) =
10293: &Apache::lonnet::get_instuser($udom,$uname);
10294: } elsif (defined($checks->{'id'})) {
10295: if ($usershash->{$user}->{'id'} ne '') {
10296: ($inst_response{$user},%{$inst_results->{$user}}) =
10297: &Apache::lonnet::get_instuser($udom,undef,
10298: $usershash->{$user}->{'id'});
10299: } else {
10300: ($inst_response{$user},%{$inst_results->{$user}}) =
10301: &Apache::lonnet::get_instuser($udom,$uname);
10302: }
1.585 raeburn 10303: }
1.1226 raeburn 10304: } else {
10305: ($inst_response{$user},%{$inst_results->{$user}}) =
10306: &Apache::lonnet::get_instuser($udom,$uname);
10307: return;
10308: }
10309: if (!$got_rules->{$udom}) {
10310: my %domconfig = &Apache::lonnet::get_dom('configuration',
10311: ['usercreation'],$udom);
10312: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10313: foreach my $item ('username','id') {
10314: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10315: $$curr_rules{$udom}{$item} =
10316: $domconfig{'usercreation'}{$item.'_rule'};
10317: }
10318: }
10319: }
10320: $got_rules->{$udom} = 1;
1.585 raeburn 10321: }
10322: }
1.1226 raeburn 10323: } else {
10324: return;
10325: }
10326: } else {
10327: return;
10328: }
10329: foreach my $user (keys(%{$usershash})) {
10330: my ($uname,$udom) = split(/:/,$user);
10331: next if (($udom eq '') || ($uname eq ''));
10332: my $id;
1.1227 raeburn 10333: if (ref($inst_results) eq 'HASH') {
10334: if (ref($inst_results->{$user}) eq 'HASH') {
10335: $id = $inst_results->{$user}->{'id'};
10336: }
10337: }
10338: if ($id eq '') {
10339: if (ref($usershash->{$user})) {
10340: $id = $usershash->{$user}->{'id'};
10341: }
1.585 raeburn 10342: }
1.612 raeburn 10343: foreach my $item (keys(%{$checks})) {
10344: if (ref($$curr_rules{$udom}) eq 'HASH') {
10345: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10346: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10347: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10348: $$curr_rules{$udom}{$item});
1.612 raeburn 10349: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10350: if ($rule_check{$rule}) {
10351: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10352: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10353: if (ref($inst_results) eq 'HASH') {
10354: if (ref($inst_results->{$user}) eq 'HASH') {
10355: if (keys(%{$inst_results->{$user}}) == 0) {
10356: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10357: } elsif ($item eq 'id') {
10358: if ($inst_results->{$user}->{'id'} eq '') {
10359: $$alerts{$item}{$udom}{$uname} = 1;
10360: }
1.615 raeburn 10361: }
1.612 raeburn 10362: }
10363: }
1.615 raeburn 10364: }
10365: last;
1.585 raeburn 10366: }
10367: }
10368: }
10369: }
10370: }
10371: }
10372: }
10373: }
1.612 raeburn 10374: return;
10375: }
10376:
10377: sub user_rule_formats {
10378: my ($domain,$domdesc,$curr_rules,$check) = @_;
10379: my %text = (
10380: 'username' => 'Usernames',
10381: 'id' => 'IDs',
10382: );
10383: my $output;
10384: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10385: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10386: if (@{$ruleorder} > 0) {
1.1102 raeburn 10387: $output = '<br />'.
10388: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10389: '<span class="LC_cusr_emph">','</span>',$domdesc).
10390: ' <ul>';
1.612 raeburn 10391: foreach my $rule (@{$ruleorder}) {
10392: if (ref($curr_rules) eq 'ARRAY') {
10393: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10394: if (ref($rules->{$rule}) eq 'HASH') {
10395: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10396: $rules->{$rule}{'desc'}.'</li>';
10397: }
10398: }
10399: }
10400: }
10401: $output .= '</ul>';
10402: }
10403: }
10404: return $output;
10405: }
10406:
10407: sub instrule_disallow_msg {
1.615 raeburn 10408: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10409: my $response;
10410: my %text = (
10411: item => 'username',
10412: items => 'usernames',
10413: match => 'matches',
10414: do => 'does',
10415: action => 'a username',
10416: one => 'one',
10417: );
10418: if ($count > 1) {
10419: $text{'item'} = 'usernames';
10420: $text{'match'} ='match';
10421: $text{'do'} = 'do';
10422: $text{'action'} = 'usernames',
10423: $text{'one'} = 'ones';
10424: }
10425: if ($checkitem eq 'id') {
10426: $text{'items'} = 'IDs';
10427: $text{'item'} = 'ID';
10428: $text{'action'} = 'an ID';
1.615 raeburn 10429: if ($count > 1) {
10430: $text{'item'} = 'IDs';
10431: $text{'action'} = 'IDs';
10432: }
1.612 raeburn 10433: }
1.674 bisitz 10434: $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 10435: if ($mode eq 'upload') {
10436: if ($checkitem eq 'username') {
10437: $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'}.");
10438: } elsif ($checkitem eq 'id') {
1.674 bisitz 10439: $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 10440: }
1.669 raeburn 10441: } elsif ($mode eq 'selfcreate') {
10442: if ($checkitem eq 'id') {
10443: $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.");
10444: }
1.615 raeburn 10445: } else {
10446: if ($checkitem eq 'username') {
10447: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10448: } elsif ($checkitem eq 'id') {
10449: $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.");
10450: }
1.612 raeburn 10451: }
10452: return $response;
1.585 raeburn 10453: }
10454:
1.624 raeburn 10455: sub personal_data_fieldtitles {
10456: my %fieldtitles = &Apache::lonlocal::texthash (
10457: id => 'Student/Employee ID',
10458: permanentemail => 'E-mail address',
10459: lastname => 'Last Name',
10460: firstname => 'First Name',
10461: middlename => 'Middle Name',
10462: generation => 'Generation',
10463: gen => 'Generation',
1.765 raeburn 10464: inststatus => 'Affiliation',
1.624 raeburn 10465: );
10466: return %fieldtitles;
10467: }
10468:
1.642 raeburn 10469: sub sorted_inst_types {
10470: my ($dom) = @_;
1.1185 raeburn 10471: my ($usertypes,$order);
10472: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10473: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10474: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10475: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10476: } else {
10477: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10478: }
1.642 raeburn 10479: my $othertitle = &mt('All users');
10480: if ($env{'request.course.id'}) {
1.668 raeburn 10481: $othertitle = &mt('Any users');
1.642 raeburn 10482: }
10483: my @types;
10484: if (ref($order) eq 'ARRAY') {
10485: @types = @{$order};
10486: }
10487: if (@types == 0) {
10488: if (ref($usertypes) eq 'HASH') {
10489: @types = sort(keys(%{$usertypes}));
10490: }
10491: }
10492: if (keys(%{$usertypes}) > 0) {
10493: $othertitle = &mt('Other users');
10494: }
10495: return ($othertitle,$usertypes,\@types);
10496: }
10497:
1.645 raeburn 10498: sub get_institutional_codes {
10499: my ($settings,$allcourses,$LC_code) = @_;
10500: # Get complete list of course sections to update
10501: my @currsections = ();
10502: my @currxlists = ();
10503: my $coursecode = $$settings{'internal.coursecode'};
10504:
10505: if ($$settings{'internal.sectionnums'} ne '') {
10506: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10507: }
10508:
10509: if ($$settings{'internal.crosslistings'} ne '') {
10510: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10511: }
10512:
10513: if (@currxlists > 0) {
10514: foreach (@currxlists) {
10515: if (m/^([^:]+):(\w*)$/) {
10516: unless (grep/^$1$/,@{$allcourses}) {
10517: push @{$allcourses},$1;
10518: $$LC_code{$1} = $2;
10519: }
10520: }
10521: }
10522: }
10523:
10524: if (@currsections > 0) {
10525: foreach (@currsections) {
10526: if (m/^(\w+):(\w*)$/) {
10527: my $sec = $coursecode.$1;
10528: my $lc_sec = $2;
10529: unless (grep/^$sec$/,@{$allcourses}) {
10530: push @{$allcourses},$sec;
10531: $$LC_code{$sec} = $lc_sec;
10532: }
10533: }
10534: }
10535: }
10536: return;
10537: }
10538:
1.971 raeburn 10539: sub get_standard_codeitems {
10540: return ('Year','Semester','Department','Number','Section');
10541: }
10542:
1.112 bowersj2 10543: =pod
10544:
1.780 raeburn 10545: =head1 Slot Helpers
10546:
10547: =over 4
10548:
10549: =item * sorted_slots()
10550:
1.1040 raeburn 10551: Sorts an array of slot names in order of an optional sort key,
10552: default sort is by slot start time (earliest first).
1.780 raeburn 10553:
10554: Inputs:
10555:
10556: =over 4
10557:
10558: slotsarr - Reference to array of unsorted slot names.
10559:
10560: slots - Reference to hash of hash, where outer hash keys are slot names.
10561:
1.1040 raeburn 10562: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10563:
1.549 albertel 10564: =back
10565:
1.780 raeburn 10566: Returns:
10567:
10568: =over 4
10569:
1.1040 raeburn 10570: sorted - An array of slot names sorted by a specified sort key
10571: (default sort key is start time of the slot).
1.780 raeburn 10572:
10573: =back
10574:
10575: =cut
10576:
10577:
10578: sub sorted_slots {
1.1040 raeburn 10579: my ($slotsarr,$slots,$sortkey) = @_;
10580: if ($sortkey eq '') {
10581: $sortkey = 'starttime';
10582: }
1.780 raeburn 10583: my @sorted;
10584: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10585: @sorted =
10586: sort {
10587: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10588: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10589: }
10590: if (ref($slots->{$a})) { return -1;}
10591: if (ref($slots->{$b})) { return 1;}
10592: return 0;
10593: } @{$slotsarr};
10594: }
10595: return @sorted;
10596: }
10597:
1.1040 raeburn 10598: =pod
10599:
10600: =item * get_future_slots()
10601:
10602: Inputs:
10603:
10604: =over 4
10605:
10606: cnum - course number
10607:
10608: cdom - course domain
10609:
10610: now - current UNIX time
10611:
10612: symb - optional symb
10613:
10614: =back
10615:
10616: Returns:
10617:
10618: =over 4
10619:
10620: sorted_reservable - ref to array of student_schedulable slots currently
10621: reservable, ordered by end date of reservation period.
10622:
10623: reservable_now - ref to hash of student_schedulable slots currently
10624: reservable.
10625:
10626: Keys in inner hash are:
10627: (a) symb: either blank or symb to which slot use is restricted.
10628: (b) endreserve: end date of reservation period.
10629:
10630: sorted_future - ref to array of student_schedulable slots reservable in
10631: the future, ordered by start date of reservation period.
10632:
10633: future_reservable - ref to hash of student_schedulable slots reservable
10634: in the future.
10635:
10636: Keys in inner hash are:
10637: (a) symb: either blank or symb to which slot use is restricted.
10638: (b) startreserve: start date of reservation period.
10639:
10640: =back
10641:
10642: =cut
10643:
10644: sub get_future_slots {
10645: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 10646: my $map;
10647: if ($symb) {
10648: ($map) = &Apache::lonnet::decode_symb($symb);
10649: }
1.1040 raeburn 10650: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10651: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10652: foreach my $slot (keys(%slots)) {
10653: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10654: if ($symb) {
1.1229 raeburn 10655: if ($slots{$slot}->{'symb'} ne '') {
10656: my $canuse;
10657: my %oksymbs;
10658: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
10659: map { $oksymbs{$_} = 1; } @slotsymbs;
10660: if ($oksymbs{$symb}) {
10661: $canuse = 1;
10662: } else {
10663: foreach my $item (@slotsymbs) {
10664: if ($item =~ /\.(page|sequence)$/) {
10665: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
10666: if (($map ne '') && ($map eq $sloturl)) {
10667: $canuse = 1;
10668: last;
10669: }
10670: }
10671: }
10672: }
10673: next unless ($canuse);
10674: }
1.1040 raeburn 10675: }
10676: if (($slots{$slot}->{'starttime'} > $now) &&
10677: ($slots{$slot}->{'endtime'} > $now)) {
10678: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10679: my $userallowed = 0;
10680: if ($slots{$slot}->{'allowedsections'}) {
10681: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10682: if (!defined($env{'request.role.sec'})
10683: && grep(/^No section assigned$/,@allowed_sec)) {
10684: $userallowed=1;
10685: } else {
10686: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10687: $userallowed=1;
10688: }
10689: }
10690: unless ($userallowed) {
10691: if (defined($env{'request.course.groups'})) {
10692: my @groups = split(/:/,$env{'request.course.groups'});
10693: foreach my $group (@groups) {
10694: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10695: $userallowed=1;
10696: last;
10697: }
10698: }
10699: }
10700: }
10701: }
10702: if ($slots{$slot}->{'allowedusers'}) {
10703: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10704: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10705: if (grep(/^\Q$user\E$/,@allowed_users)) {
10706: $userallowed = 1;
10707: }
10708: }
10709: next unless($userallowed);
10710: }
10711: my $startreserve = $slots{$slot}->{'startreserve'};
10712: my $endreserve = $slots{$slot}->{'endreserve'};
10713: my $symb = $slots{$slot}->{'symb'};
10714: if (($startreserve < $now) &&
10715: (!$endreserve || $endreserve > $now)) {
10716: my $lastres = $endreserve;
10717: if (!$lastres) {
10718: $lastres = $slots{$slot}->{'starttime'};
10719: }
10720: $reservable_now{$slot} = {
10721: symb => $symb,
10722: endreserve => $lastres
10723: };
10724: } elsif (($startreserve > $now) &&
10725: (!$endreserve || $endreserve > $startreserve)) {
10726: $future_reservable{$slot} = {
10727: symb => $symb,
10728: startreserve => $startreserve
10729: };
10730: }
10731: }
10732: }
10733: my @unsorted_reservable = keys(%reservable_now);
10734: if (@unsorted_reservable > 0) {
10735: @sorted_reservable =
10736: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10737: }
10738: my @unsorted_future = keys(%future_reservable);
10739: if (@unsorted_future > 0) {
10740: @sorted_future =
10741: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10742: }
10743: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10744: }
1.780 raeburn 10745:
10746: =pod
10747:
1.1057 foxr 10748: =back
10749:
1.549 albertel 10750: =head1 HTTP Helpers
10751:
10752: =over 4
10753:
1.648 raeburn 10754: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10755:
1.258 albertel 10756: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10757: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10758: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10759:
10760: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10761: $possible_names is an ref to an array of form element names. As an example:
10762: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10763: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10764:
10765: =cut
1.1 albertel 10766:
1.6 albertel 10767: sub get_unprocessed_cgi {
1.25 albertel 10768: my ($query,$possible_names)= @_;
1.26 matthew 10769: # $Apache::lonxml::debug=1;
1.356 albertel 10770: foreach my $pair (split(/&/,$query)) {
10771: my ($name, $value) = split(/=/,$pair);
1.369 www 10772: $name = &unescape($name);
1.25 albertel 10773: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10774: $value =~ tr/+/ /;
10775: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10776: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10777: }
1.16 harris41 10778: }
1.6 albertel 10779: }
10780:
1.112 bowersj2 10781: =pod
10782:
1.648 raeburn 10783: =item * &cacheheader()
1.112 bowersj2 10784:
10785: returns cache-controlling header code
10786:
10787: =cut
10788:
1.7 albertel 10789: sub cacheheader {
1.258 albertel 10790: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10791: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10792: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10793: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10794: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10795: return $output;
1.7 albertel 10796: }
10797:
1.112 bowersj2 10798: =pod
10799:
1.648 raeburn 10800: =item * &no_cache($r)
1.112 bowersj2 10801:
10802: specifies header code to not have cache
10803:
10804: =cut
10805:
1.9 albertel 10806: sub no_cache {
1.216 albertel 10807: my ($r) = @_;
10808: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10809: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10810: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10811: $r->no_cache(1);
10812: $r->header_out("Expires" => $date);
10813: $r->header_out("Pragma" => "no-cache");
1.123 www 10814: }
10815:
10816: sub content_type {
1.181 albertel 10817: my ($r,$type,$charset) = @_;
1.299 foxr 10818: if ($r) {
10819: # Note that printout.pl calls this with undef for $r.
10820: &no_cache($r);
10821: }
1.258 albertel 10822: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10823: unless ($charset) {
10824: $charset=&Apache::lonlocal::current_encoding;
10825: }
10826: if ($charset) { $type.='; charset='.$charset; }
10827: if ($r) {
10828: $r->content_type($type);
10829: } else {
10830: print("Content-type: $type\n\n");
10831: }
1.9 albertel 10832: }
1.25 albertel 10833:
1.112 bowersj2 10834: =pod
10835:
1.648 raeburn 10836: =item * &add_to_env($name,$value)
1.112 bowersj2 10837:
1.258 albertel 10838: adds $name to the %env hash with value
1.112 bowersj2 10839: $value, if $name already exists, the entry is converted to an array
10840: reference and $value is added to the array.
10841:
10842: =cut
10843:
1.25 albertel 10844: sub add_to_env {
10845: my ($name,$value)=@_;
1.258 albertel 10846: if (defined($env{$name})) {
10847: if (ref($env{$name})) {
1.25 albertel 10848: #already have multiple values
1.258 albertel 10849: push(@{ $env{$name} },$value);
1.25 albertel 10850: } else {
10851: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10852: my $first=$env{$name};
10853: undef($env{$name});
10854: push(@{ $env{$name} },$first,$value);
1.25 albertel 10855: }
10856: } else {
1.258 albertel 10857: $env{$name}=$value;
1.25 albertel 10858: }
1.31 albertel 10859: }
1.149 albertel 10860:
10861: =pod
10862:
1.648 raeburn 10863: =item * &get_env_multiple($name)
1.149 albertel 10864:
1.258 albertel 10865: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10866: values may be defined and end up as an array ref.
10867:
10868: returns an array of values
10869:
10870: =cut
10871:
10872: sub get_env_multiple {
10873: my ($name) = @_;
10874: my @values;
1.258 albertel 10875: if (defined($env{$name})) {
1.149 albertel 10876: # exists is it an array
1.258 albertel 10877: if (ref($env{$name})) {
10878: @values=@{ $env{$name} };
1.149 albertel 10879: } else {
1.258 albertel 10880: $values[0]=$env{$name};
1.149 albertel 10881: }
10882: }
10883: return(@values);
10884: }
10885:
1.660 raeburn 10886: sub ask_for_embedded_content {
10887: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10888: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 10889: %currsubfile,%unused,$rem);
1.1071 raeburn 10890: my $counter = 0;
10891: my $numnew = 0;
1.987 raeburn 10892: my $numremref = 0;
10893: my $numinvalid = 0;
10894: my $numpathchg = 0;
10895: my $numexisting = 0;
1.1071 raeburn 10896: my $numunused = 0;
10897: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 10898: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10899: my $heading = &mt('Upload embedded files');
10900: my $buttontext = &mt('Upload');
10901:
1.1085 raeburn 10902: if ($env{'request.course.id'}) {
1.1123 raeburn 10903: if ($actionurl eq '/adm/dependencies') {
10904: $navmap = Apache::lonnavmaps::navmap->new();
10905: }
10906: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10907: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 10908: }
1.1123 raeburn 10909: if (($actionurl eq '/adm/portfolio') ||
10910: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10911: my $current_path='/';
10912: if ($env{'form.currentpath'}) {
10913: $current_path = $env{'form.currentpath'};
10914: }
10915: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 10916: $udom = $cdom;
10917: $uname = $cnum;
1.984 raeburn 10918: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10919: } else {
10920: $udom = $env{'user.domain'};
10921: $uname = $env{'user.name'};
10922: $url = '/userfiles/portfolio';
10923: }
1.987 raeburn 10924: $toplevel = $url.'/';
1.984 raeburn 10925: $url .= $current_path;
10926: $getpropath = 1;
1.987 raeburn 10927: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10928: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10929: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10930: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10931: $toplevel = $url;
1.984 raeburn 10932: if ($rest ne '') {
1.987 raeburn 10933: $url .= $rest;
10934: }
10935: } elsif ($actionurl eq '/adm/coursedocs') {
10936: if (ref($args) eq 'HASH') {
1.1071 raeburn 10937: $url = $args->{'docs_url'};
10938: $toplevel = $url;
1.1084 raeburn 10939: if ($args->{'context'} eq 'paste') {
10940: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10941: ($path) =
10942: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10943: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10944: $fileloc =~ s{^/}{};
10945: }
1.1071 raeburn 10946: }
1.1084 raeburn 10947: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 10948: if ($env{'request.course.id'} ne '') {
10949: if (ref($args) eq 'HASH') {
10950: $url = $args->{'docs_url'};
10951: $title = $args->{'docs_title'};
1.1126 raeburn 10952: $toplevel = $url;
10953: unless ($toplevel =~ m{^/}) {
10954: $toplevel = "/$url";
10955: }
1.1085 raeburn 10956: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 10957: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10958: $path = $1;
10959: } else {
10960: ($path) =
10961: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10962: }
1.1195 raeburn 10963: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10964: $fileloc = $toplevel;
10965: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10966: my ($udom,$uname,$fname) =
10967: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10968: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10969: } else {
10970: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10971: }
1.1071 raeburn 10972: $fileloc =~ s{^/}{};
10973: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10974: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10975: }
1.987 raeburn 10976: }
1.1123 raeburn 10977: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10978: $udom = $cdom;
10979: $uname = $cnum;
10980: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10981: $toplevel = $url;
10982: $path = $url;
10983: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10984: $fileloc =~ s{^/}{};
1.987 raeburn 10985: }
1.1126 raeburn 10986: foreach my $file (keys(%{$allfiles})) {
10987: my $embed_file;
10988: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10989: $embed_file = $1;
10990: } else {
10991: $embed_file = $file;
10992: }
1.1158 raeburn 10993: my ($absolutepath,$cleaned_file);
10994: if ($embed_file =~ m{^\w+://}) {
10995: $cleaned_file = $embed_file;
1.1147 raeburn 10996: $newfiles{$cleaned_file} = 1;
10997: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10998: } else {
1.1158 raeburn 10999: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11000: if ($embed_file =~ m{^/}) {
11001: $absolutepath = $embed_file;
11002: }
1.1147 raeburn 11003: if ($cleaned_file =~ m{/}) {
11004: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11005: $path = &check_for_traversal($path,$url,$toplevel);
11006: my $item = $fname;
11007: if ($path ne '') {
11008: $item = $path.'/'.$fname;
11009: $subdependencies{$path}{$fname} = 1;
11010: } else {
11011: $dependencies{$item} = 1;
11012: }
11013: if ($absolutepath) {
11014: $mapping{$item} = $absolutepath;
11015: } else {
11016: $mapping{$item} = $embed_file;
11017: }
11018: } else {
11019: $dependencies{$embed_file} = 1;
11020: if ($absolutepath) {
1.1147 raeburn 11021: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11022: } else {
1.1147 raeburn 11023: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11024: }
11025: }
1.984 raeburn 11026: }
11027: }
1.1071 raeburn 11028: my $dirptr = 16384;
1.984 raeburn 11029: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11030: $currsubfile{$path} = {};
1.1123 raeburn 11031: if (($actionurl eq '/adm/portfolio') ||
11032: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11033: my ($sublistref,$listerror) =
11034: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11035: if (ref($sublistref) eq 'ARRAY') {
11036: foreach my $line (@{$sublistref}) {
11037: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11038: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11039: }
1.984 raeburn 11040: }
1.987 raeburn 11041: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11042: if (opendir(my $dir,$url.'/'.$path)) {
11043: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11044: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11045: }
1.1084 raeburn 11046: } elsif (($actionurl eq '/adm/dependencies') ||
11047: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11048: ($args->{'context'} eq 'paste')) ||
11049: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11050: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11051: my $dir;
11052: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11053: $dir = $fileloc;
11054: } else {
11055: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11056: }
1.1071 raeburn 11057: if ($dir ne '') {
11058: my ($sublistref,$listerror) =
11059: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11060: if (ref($sublistref) eq 'ARRAY') {
11061: foreach my $line (@{$sublistref}) {
11062: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11063: undef,$mtime)=split(/\&/,$line,12);
11064: unless (($testdir&$dirptr) ||
11065: ($file_name =~ /^\.\.?$/)) {
11066: $currsubfile{$path}{$file_name} = [$size,$mtime];
11067: }
11068: }
11069: }
11070: }
1.984 raeburn 11071: }
11072: }
11073: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11074: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11075: my $item = $path.'/'.$file;
11076: unless ($mapping{$item} eq $item) {
11077: $pathchanges{$item} = 1;
11078: }
11079: $existing{$item} = 1;
11080: $numexisting ++;
11081: } else {
11082: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11083: }
11084: }
1.1071 raeburn 11085: if ($actionurl eq '/adm/dependencies') {
11086: foreach my $path (keys(%currsubfile)) {
11087: if (ref($currsubfile{$path}) eq 'HASH') {
11088: foreach my $file (keys(%{$currsubfile{$path}})) {
11089: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11090: next if (($rem ne '') &&
11091: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11092: (ref($navmap) &&
11093: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11094: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11095: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11096: $unused{$path.'/'.$file} = 1;
11097: }
11098: }
11099: }
11100: }
11101: }
1.984 raeburn 11102: }
1.987 raeburn 11103: my %currfile;
1.1123 raeburn 11104: if (($actionurl eq '/adm/portfolio') ||
11105: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11106: my ($dirlistref,$listerror) =
11107: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11108: if (ref($dirlistref) eq 'ARRAY') {
11109: foreach my $line (@{$dirlistref}) {
11110: my ($file_name,$rest) = split(/\&/,$line,2);
11111: $currfile{$file_name} = 1;
11112: }
1.984 raeburn 11113: }
1.987 raeburn 11114: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11115: if (opendir(my $dir,$url)) {
1.987 raeburn 11116: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11117: map {$currfile{$_} = 1;} @dir_list;
11118: }
1.1084 raeburn 11119: } elsif (($actionurl eq '/adm/dependencies') ||
11120: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11121: ($args->{'context'} eq 'paste')) ||
11122: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11123: if ($env{'request.course.id'} ne '') {
11124: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11125: if ($dir ne '') {
11126: my ($dirlistref,$listerror) =
11127: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11128: if (ref($dirlistref) eq 'ARRAY') {
11129: foreach my $line (@{$dirlistref}) {
11130: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11131: $size,undef,$mtime)=split(/\&/,$line,12);
11132: unless (($testdir&$dirptr) ||
11133: ($file_name =~ /^\.\.?$/)) {
11134: $currfile{$file_name} = [$size,$mtime];
11135: }
11136: }
11137: }
11138: }
11139: }
1.984 raeburn 11140: }
11141: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11142: if (exists($currfile{$file})) {
1.987 raeburn 11143: unless ($mapping{$file} eq $file) {
11144: $pathchanges{$file} = 1;
11145: }
11146: $existing{$file} = 1;
11147: $numexisting ++;
11148: } else {
1.984 raeburn 11149: $newfiles{$file} = 1;
11150: }
11151: }
1.1071 raeburn 11152: foreach my $file (keys(%currfile)) {
11153: unless (($file eq $filename) ||
11154: ($file eq $filename.'.bak') ||
11155: ($dependencies{$file})) {
1.1085 raeburn 11156: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11157: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11158: next if (($rem ne '') &&
11159: (($env{"httpref.$rem".$file} ne '') ||
11160: (ref($navmap) &&
11161: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11162: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11163: ($navmap->getResourceByUrl($rem.$1)))))));
11164: }
1.1085 raeburn 11165: }
1.1071 raeburn 11166: $unused{$file} = 1;
11167: }
11168: }
1.1084 raeburn 11169: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11170: ($args->{'context'} eq 'paste')) {
11171: $counter = scalar(keys(%existing));
11172: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11173: return ($output,$counter,$numpathchg,\%existing);
11174: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11175: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11176: $counter = scalar(keys(%existing));
11177: $numpathchg = scalar(keys(%pathchanges));
11178: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11179: }
1.984 raeburn 11180: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11181: if ($actionurl eq '/adm/dependencies') {
11182: next if ($embed_file =~ m{^\w+://});
11183: }
1.660 raeburn 11184: $upload_output .= &start_data_table_row().
1.1123 raeburn 11185: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11186: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11187: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11188: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11189: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11190: }
1.1123 raeburn 11191: $upload_output .= '</td>';
1.1071 raeburn 11192: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11193: $upload_output.='<td align="right">'.
11194: '<span class="LC_info LC_fontsize_medium">'.
11195: &mt("URL points to web address").'</span>';
1.987 raeburn 11196: $numremref++;
1.660 raeburn 11197: } elsif ($args->{'error_on_invalid_names'}
11198: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11199: $upload_output.='<td align="right"><span class="LC_warning">'.
11200: &mt('Invalid characters').'</span>';
1.987 raeburn 11201: $numinvalid++;
1.660 raeburn 11202: } else {
1.1123 raeburn 11203: $upload_output .= '<td>'.
11204: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11205: $embed_file,\%mapping,
1.1071 raeburn 11206: $allfiles,$codebase,'upload');
11207: $counter ++;
11208: $numnew ++;
1.987 raeburn 11209: }
11210: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11211: }
11212: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11213: if ($actionurl eq '/adm/dependencies') {
11214: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11215: $modify_output .= &start_data_table_row().
11216: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11217: '<img src="'.&icon($embed_file).'" border="0" />'.
11218: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11219: '<td>'.$size.'</td>'.
11220: '<td>'.$mtime.'</td>'.
11221: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11222: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11223: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11224: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11225: &embedded_file_element('upload_embedded',$counter,
11226: $embed_file,\%mapping,
11227: $allfiles,$codebase,'modify').
11228: '</div></td>'.
11229: &end_data_table_row()."\n";
11230: $counter ++;
11231: } else {
11232: $upload_output .= &start_data_table_row().
1.1123 raeburn 11233: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11234: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11235: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11236: &Apache::loncommon::end_data_table_row()."\n";
11237: }
11238: }
11239: my $delidx = $counter;
11240: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11241: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11242: $delete_output .= &start_data_table_row().
11243: '<td><img src="'.&icon($oldfile).'" />'.
11244: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11245: '<td>'.$size.'</td>'.
11246: '<td>'.$mtime.'</td>'.
11247: '<td><label><input type="checkbox" name="del_upload_dep" '.
11248: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11249: &embedded_file_element('upload_embedded',$delidx,
11250: $oldfile,\%mapping,$allfiles,
11251: $codebase,'delete').'</td>'.
11252: &end_data_table_row()."\n";
11253: $numunused ++;
11254: $delidx ++;
1.987 raeburn 11255: }
11256: if ($upload_output) {
11257: $upload_output = &start_data_table().
11258: $upload_output.
11259: &end_data_table()."\n";
11260: }
1.1071 raeburn 11261: if ($modify_output) {
11262: $modify_output = &start_data_table().
11263: &start_data_table_header_row().
11264: '<th>'.&mt('File').'</th>'.
11265: '<th>'.&mt('Size (KB)').'</th>'.
11266: '<th>'.&mt('Modified').'</th>'.
11267: '<th>'.&mt('Upload replacement?').'</th>'.
11268: &end_data_table_header_row().
11269: $modify_output.
11270: &end_data_table()."\n";
11271: }
11272: if ($delete_output) {
11273: $delete_output = &start_data_table().
11274: &start_data_table_header_row().
11275: '<th>'.&mt('File').'</th>'.
11276: '<th>'.&mt('Size (KB)').'</th>'.
11277: '<th>'.&mt('Modified').'</th>'.
11278: '<th>'.&mt('Delete?').'</th>'.
11279: &end_data_table_header_row().
11280: $delete_output.
11281: &end_data_table()."\n";
11282: }
1.987 raeburn 11283: my $applies = 0;
11284: if ($numremref) {
11285: $applies ++;
11286: }
11287: if ($numinvalid) {
11288: $applies ++;
11289: }
11290: if ($numexisting) {
11291: $applies ++;
11292: }
1.1071 raeburn 11293: if ($counter || $numunused) {
1.987 raeburn 11294: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11295: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11296: $state.'<h3>'.$heading.'</h3>';
11297: if ($actionurl eq '/adm/dependencies') {
11298: if ($numnew) {
11299: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11300: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11301: $upload_output.'<br />'."\n";
11302: }
11303: if ($numexisting) {
11304: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11305: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11306: $modify_output.'<br />'."\n";
11307: $buttontext = &mt('Save changes');
11308: }
11309: if ($numunused) {
11310: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11311: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11312: $delete_output.'<br />'."\n";
11313: $buttontext = &mt('Save changes');
11314: }
11315: } else {
11316: $output .= $upload_output.'<br />'."\n";
11317: }
11318: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11319: $counter.'" />'."\n";
11320: if ($actionurl eq '/adm/dependencies') {
11321: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11322: $numnew.'" />'."\n";
11323: } elsif ($actionurl eq '') {
1.987 raeburn 11324: $output .= '<input type="hidden" name="phase" value="three" />';
11325: }
11326: } elsif ($applies) {
11327: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11328: if ($applies > 1) {
11329: $output .=
1.1123 raeburn 11330: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11331: if ($numremref) {
11332: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11333: }
11334: if ($numinvalid) {
11335: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11336: }
11337: if ($numexisting) {
11338: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11339: }
11340: $output .= '</ul><br />';
11341: } elsif ($numremref) {
11342: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11343: } elsif ($numinvalid) {
11344: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11345: } elsif ($numexisting) {
11346: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11347: }
11348: $output .= $upload_output.'<br />';
11349: }
11350: my ($pathchange_output,$chgcount);
1.1071 raeburn 11351: $chgcount = $counter;
1.987 raeburn 11352: if (keys(%pathchanges) > 0) {
11353: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11354: if ($counter) {
1.987 raeburn 11355: $output .= &embedded_file_element('pathchange',$chgcount,
11356: $embed_file,\%mapping,
1.1071 raeburn 11357: $allfiles,$codebase,'change');
1.987 raeburn 11358: } else {
11359: $pathchange_output .=
11360: &start_data_table_row().
11361: '<td><input type ="checkbox" name="namechange" value="'.
11362: $chgcount.'" checked="checked" /></td>'.
11363: '<td>'.$mapping{$embed_file}.'</td>'.
11364: '<td>'.$embed_file.
11365: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11366: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11367: '</td>'.&end_data_table_row();
1.660 raeburn 11368: }
1.987 raeburn 11369: $numpathchg ++;
11370: $chgcount ++;
1.660 raeburn 11371: }
11372: }
1.1127 raeburn 11373: if (($counter) || ($numunused)) {
1.987 raeburn 11374: if ($numpathchg) {
11375: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11376: $numpathchg.'" />'."\n";
11377: }
11378: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11379: ($actionurl eq '/adm/imsimport')) {
11380: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11381: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11382: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11383: } elsif ($actionurl eq '/adm/dependencies') {
11384: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11385: }
1.1123 raeburn 11386: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11387: } elsif ($numpathchg) {
11388: my %pathchange = ();
11389: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11390: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11391: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11392: }
1.987 raeburn 11393: }
1.1071 raeburn 11394: return ($output,$counter,$numpathchg);
1.987 raeburn 11395: }
11396:
1.1147 raeburn 11397: =pod
11398:
11399: =item * clean_path($name)
11400:
11401: Performs clean-up of directories, subdirectories and filename in an
11402: embedded object, referenced in an HTML file which is being uploaded
11403: to a course or portfolio, where
11404: "Upload embedded images/multimedia files if HTML file" checkbox was
11405: checked.
11406:
11407: Clean-up is similar to replacements in lonnet::clean_filename()
11408: except each / between sub-directory and next level is preserved.
11409:
11410: =cut
11411:
11412: sub clean_path {
11413: my ($embed_file) = @_;
11414: $embed_file =~s{^/+}{};
11415: my @contents;
11416: if ($embed_file =~ m{/}) {
11417: @contents = split(/\//,$embed_file);
11418: } else {
11419: @contents = ($embed_file);
11420: }
11421: my $lastidx = scalar(@contents)-1;
11422: for (my $i=0; $i<=$lastidx; $i++) {
11423: $contents[$i]=~s{\\}{/}g;
11424: $contents[$i]=~s/\s+/\_/g;
11425: $contents[$i]=~s{[^/\w\.\-]}{}g;
11426: if ($i == $lastidx) {
11427: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11428: }
11429: }
11430: if ($lastidx > 0) {
11431: return join('/',@contents);
11432: } else {
11433: return $contents[0];
11434: }
11435: }
11436:
1.987 raeburn 11437: sub embedded_file_element {
1.1071 raeburn 11438: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11439: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11440: (ref($codebase) eq 'HASH'));
11441: my $output;
1.1071 raeburn 11442: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11443: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11444: }
11445: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11446: &escape($embed_file).'" />';
11447: unless (($context eq 'upload_embedded') &&
11448: ($mapping->{$embed_file} eq $embed_file)) {
11449: $output .='
11450: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11451: }
11452: my $attrib;
11453: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11454: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11455: }
11456: $output .=
11457: "\n\t\t".
11458: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11459: $attrib.'" />';
11460: if (exists($codebase->{$mapping->{$embed_file}})) {
11461: $output .=
11462: "\n\t\t".
11463: '<input name="codebase_'.$num.'" type="hidden" value="'.
11464: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11465: }
1.987 raeburn 11466: return $output;
1.660 raeburn 11467: }
11468:
1.1071 raeburn 11469: sub get_dependency_details {
11470: my ($currfile,$currsubfile,$embed_file) = @_;
11471: my ($size,$mtime,$showsize,$showmtime);
11472: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11473: if ($embed_file =~ m{/}) {
11474: my ($path,$fname) = split(/\//,$embed_file);
11475: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11476: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11477: }
11478: } else {
11479: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11480: ($size,$mtime) = @{$currfile->{$embed_file}};
11481: }
11482: }
11483: $showsize = $size/1024.0;
11484: $showsize = sprintf("%.1f",$showsize);
11485: if ($mtime > 0) {
11486: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11487: }
11488: }
11489: return ($showsize,$showmtime);
11490: }
11491:
11492: sub ask_embedded_js {
11493: return <<"END";
11494: <script type="text/javascript"">
11495: // <![CDATA[
11496: function toggleBrowse(counter) {
11497: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11498: var fileid = document.getElementById('embedded_item_'+counter);
11499: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11500: if (chkboxid.checked == true) {
11501: uploaddivid.style.display='block';
11502: } else {
11503: uploaddivid.style.display='none';
11504: fileid.value = '';
11505: }
11506: }
11507: // ]]>
11508: </script>
11509:
11510: END
11511: }
11512:
1.661 raeburn 11513: sub upload_embedded {
11514: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11515: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11516: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11517: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11518: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11519: my $orig_uploaded_filename =
11520: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11521: foreach my $type ('orig','ref','attrib','codebase') {
11522: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11523: $env{'form.embedded_'.$type.'_'.$i} =
11524: &unescape($env{'form.embedded_'.$type.'_'.$i});
11525: }
11526: }
1.661 raeburn 11527: my ($path,$fname) =
11528: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11529: # no path, whole string is fname
11530: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11531: $fname = &Apache::lonnet::clean_filename($fname);
11532: # See if there is anything left
11533: next if ($fname eq '');
11534:
11535: # Check if file already exists as a file or directory.
11536: my ($state,$msg);
11537: if ($context eq 'portfolio') {
11538: my $port_path = $dirpath;
11539: if ($group ne '') {
11540: $port_path = "groups/$group/$port_path";
11541: }
1.987 raeburn 11542: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11543: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11544: $dir_root,$port_path,$disk_quota,
11545: $current_disk_usage,$uname,$udom);
11546: if ($state eq 'will_exceed_quota'
1.984 raeburn 11547: || $state eq 'file_locked') {
1.661 raeburn 11548: $output .= $msg;
11549: next;
11550: }
11551: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11552: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11553: if ($state eq 'exists') {
11554: $output .= $msg;
11555: next;
11556: }
11557: }
11558: # Check if extension is valid
11559: if (($fname =~ /\.(\w+)$/) &&
11560: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11561: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11562: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11563: next;
11564: } elsif (($fname =~ /\.(\w+)$/) &&
11565: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11566: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11567: next;
11568: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11569: $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 11570: next;
11571: }
11572: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11573: my $subdir = $path;
11574: $subdir =~ s{/+$}{};
1.661 raeburn 11575: if ($context eq 'portfolio') {
1.984 raeburn 11576: my $result;
11577: if ($state eq 'existingfile') {
11578: $result=
11579: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11580: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11581: } else {
1.984 raeburn 11582: $result=
11583: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11584: $dirpath.
1.1123 raeburn 11585: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11586: if ($result !~ m|^/uploaded/|) {
11587: $output .= '<span class="LC_error">'
11588: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11589: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11590: .'</span><br />';
11591: next;
11592: } else {
1.987 raeburn 11593: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11594: $path.$fname.'</span>').'<br />';
1.984 raeburn 11595: }
1.661 raeburn 11596: }
1.1123 raeburn 11597: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 11598: my $extendedsubdir = $dirpath.'/'.$subdir;
11599: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11600: my $result =
1.1126 raeburn 11601: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11602: if ($result !~ m|^/uploaded/|) {
11603: $output .= '<span class="LC_error">'
11604: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11605: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11606: .'</span><br />';
11607: next;
11608: } else {
11609: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11610: $path.$fname.'</span>').'<br />';
1.1125 raeburn 11611: if ($context eq 'syllabus') {
11612: &Apache::lonnet::make_public_indefinitely($result);
11613: }
1.987 raeburn 11614: }
1.661 raeburn 11615: } else {
11616: # Save the file
11617: my $target = $env{'form.embedded_item_'.$i};
11618: my $fullpath = $dir_root.$dirpath.'/'.$path;
11619: my $dest = $fullpath.$fname;
11620: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11621: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11622: my $count;
11623: my $filepath = $dir_root;
1.1027 raeburn 11624: foreach my $subdir (@parts) {
11625: $filepath .= "/$subdir";
11626: if (!-e $filepath) {
1.661 raeburn 11627: mkdir($filepath,0770);
11628: }
11629: }
11630: my $fh;
11631: if (!open($fh,'>'.$dest)) {
11632: &Apache::lonnet::logthis('Failed to create '.$dest);
11633: $output .= '<span class="LC_error">'.
1.1071 raeburn 11634: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11635: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11636: '</span><br />';
11637: } else {
11638: if (!print $fh $env{'form.embedded_item_'.$i}) {
11639: &Apache::lonnet::logthis('Failed to write to '.$dest);
11640: $output .= '<span class="LC_error">'.
1.1071 raeburn 11641: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11642: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11643: '</span><br />';
11644: } else {
1.987 raeburn 11645: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11646: $url.'</span>').'<br />';
11647: unless ($context eq 'testbank') {
11648: $footer .= &mt('View embedded file: [_1]',
11649: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11650: }
11651: }
11652: close($fh);
11653: }
11654: }
11655: if ($env{'form.embedded_ref_'.$i}) {
11656: $pathchange{$i} = 1;
11657: }
11658: }
11659: if ($output) {
11660: $output = '<p>'.$output.'</p>';
11661: }
11662: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11663: $returnflag = 'ok';
1.1071 raeburn 11664: my $numpathchgs = scalar(keys(%pathchange));
11665: if ($numpathchgs > 0) {
1.987 raeburn 11666: if ($context eq 'portfolio') {
11667: $output .= '<p>'.&mt('or').'</p>';
11668: } elsif ($context eq 'testbank') {
1.1071 raeburn 11669: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11670: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11671: $returnflag = 'modify_orightml';
11672: }
11673: }
1.1071 raeburn 11674: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11675: }
11676:
11677: sub modify_html_form {
11678: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11679: my $end = 0;
11680: my $modifyform;
11681: if ($context eq 'upload_embedded') {
11682: return unless (ref($pathchange) eq 'HASH');
11683: if ($env{'form.number_embedded_items'}) {
11684: $end += $env{'form.number_embedded_items'};
11685: }
11686: if ($env{'form.number_pathchange_items'}) {
11687: $end += $env{'form.number_pathchange_items'};
11688: }
11689: if ($end) {
11690: for (my $i=0; $i<$end; $i++) {
11691: if ($i < $env{'form.number_embedded_items'}) {
11692: next unless($pathchange->{$i});
11693: }
11694: $modifyform .=
11695: &start_data_table_row().
11696: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11697: 'checked="checked" /></td>'.
11698: '<td>'.$env{'form.embedded_ref_'.$i}.
11699: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11700: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11701: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11702: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11703: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11704: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11705: '<td>'.$env{'form.embedded_orig_'.$i}.
11706: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11707: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11708: &end_data_table_row();
1.1071 raeburn 11709: }
1.987 raeburn 11710: }
11711: } else {
11712: $modifyform = $pathchgtable;
11713: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11714: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11715: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11716: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11717: }
11718: }
11719: if ($modifyform) {
1.1071 raeburn 11720: if ($actionurl eq '/adm/dependencies') {
11721: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11722: }
1.987 raeburn 11723: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11724: '<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".
11725: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11726: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11727: '</ol></p>'."\n".'<p>'.
11728: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11729: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11730: &start_data_table()."\n".
11731: &start_data_table_header_row().
11732: '<th>'.&mt('Change?').'</th>'.
11733: '<th>'.&mt('Current reference').'</th>'.
11734: '<th>'.&mt('Required reference').'</th>'.
11735: &end_data_table_header_row()."\n".
11736: $modifyform.
11737: &end_data_table().'<br />'."\n".$hiddenstate.
11738: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11739: '</form>'."\n";
11740: }
11741: return;
11742: }
11743:
11744: sub modify_html_refs {
1.1123 raeburn 11745: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11746: my $container;
11747: if ($context eq 'portfolio') {
11748: $container = $env{'form.container'};
11749: } elsif ($context eq 'coursedoc') {
11750: $container = $env{'form.primaryurl'};
1.1071 raeburn 11751: } elsif ($context eq 'manage_dependencies') {
11752: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11753: $container = "/$container";
1.1123 raeburn 11754: } elsif ($context eq 'syllabus') {
11755: $container = $url;
1.987 raeburn 11756: } else {
1.1027 raeburn 11757: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11758: }
11759: my (%allfiles,%codebase,$output,$content);
11760: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 11761: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11762: if (wantarray) {
11763: return ('',0,0);
11764: } else {
11765: return;
11766: }
11767: }
11768: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11769: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11770: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11771: if (wantarray) {
11772: return ('',0,0);
11773: } else {
11774: return;
11775: }
11776: }
1.987 raeburn 11777: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11778: if ($content eq '-1') {
11779: if (wantarray) {
11780: return ('',0,0);
11781: } else {
11782: return;
11783: }
11784: }
1.987 raeburn 11785: } else {
1.1071 raeburn 11786: unless ($container =~ /^\Q$dir_root\E/) {
11787: if (wantarray) {
11788: return ('',0,0);
11789: } else {
11790: return;
11791: }
11792: }
1.987 raeburn 11793: if (open(my $fh,"<$container")) {
11794: $content = join('', <$fh>);
11795: close($fh);
11796: } else {
1.1071 raeburn 11797: if (wantarray) {
11798: return ('',0,0);
11799: } else {
11800: return;
11801: }
1.987 raeburn 11802: }
11803: }
11804: my ($count,$codebasecount) = (0,0);
11805: my $mm = new File::MMagic;
11806: my $mime_type = $mm->checktype_contents($content);
11807: if ($mime_type eq 'text/html') {
11808: my $parse_result =
11809: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11810: \%codebase,\$content);
11811: if ($parse_result eq 'ok') {
11812: foreach my $i (@changes) {
11813: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11814: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11815: if ($allfiles{$ref}) {
11816: my $newname = $orig;
11817: my ($attrib_regexp,$codebase);
1.1006 raeburn 11818: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11819: if ($attrib_regexp =~ /:/) {
11820: $attrib_regexp =~ s/\:/|/g;
11821: }
11822: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11823: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11824: $count += $numchg;
1.1123 raeburn 11825: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 11826: delete($allfiles{$ref});
1.987 raeburn 11827: }
11828: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11829: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11830: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11831: $codebasecount ++;
11832: }
11833: }
11834: }
1.1123 raeburn 11835: my $skiprewrites;
1.987 raeburn 11836: if ($count || $codebasecount) {
11837: my $saveresult;
1.1071 raeburn 11838: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11839: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11840: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11841: if ($url eq $container) {
11842: my ($fname) = ($container =~ m{/([^/]+)$});
11843: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11844: $count,'<span class="LC_filename">'.
1.1071 raeburn 11845: $fname.'</span>').'</p>';
1.987 raeburn 11846: } else {
11847: $output = '<p class="LC_error">'.
11848: &mt('Error: update failed for: [_1].',
11849: '<span class="LC_filename">'.
11850: $container.'</span>').'</p>';
11851: }
1.1123 raeburn 11852: if ($context eq 'syllabus') {
11853: unless ($saveresult eq 'ok') {
11854: $skiprewrites = 1;
11855: }
11856: }
1.987 raeburn 11857: } else {
11858: if (open(my $fh,">$container")) {
11859: print $fh $content;
11860: close($fh);
11861: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11862: $count,'<span class="LC_filename">'.
11863: $container.'</span>').'</p>';
1.661 raeburn 11864: } else {
1.987 raeburn 11865: $output = '<p class="LC_error">'.
11866: &mt('Error: could not update [_1].',
11867: '<span class="LC_filename">'.
11868: $container.'</span>').'</p>';
1.661 raeburn 11869: }
11870: }
11871: }
1.1123 raeburn 11872: if (($context eq 'syllabus') && (!$skiprewrites)) {
11873: my ($actionurl,$state);
11874: $actionurl = "/public/$udom/$uname/syllabus";
11875: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11876: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11877: \%codebase,
11878: {'context' => 'rewrites',
11879: 'ignore_remote_references' => 1,});
11880: if (ref($mapping) eq 'HASH') {
11881: my $rewrites = 0;
11882: foreach my $key (keys(%{$mapping})) {
11883: next if ($key =~ m{^https?://});
11884: my $ref = $mapping->{$key};
11885: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11886: my $attrib;
11887: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11888: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11889: }
11890: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11891: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11892: $rewrites += $numchg;
11893: }
11894: }
11895: if ($rewrites) {
11896: my $saveresult;
11897: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11898: if ($url eq $container) {
11899: my ($fname) = ($container =~ m{/([^/]+)$});
11900: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11901: $count,'<span class="LC_filename">'.
11902: $fname.'</span>').'</p>';
11903: } else {
11904: $output .= '<p class="LC_error">'.
11905: &mt('Error: could not update links in [_1].',
11906: '<span class="LC_filename">'.
11907: $container.'</span>').'</p>';
11908:
11909: }
11910: }
11911: }
11912: }
1.987 raeburn 11913: } else {
11914: &logthis('Failed to parse '.$container.
11915: ' to modify references: '.$parse_result);
1.661 raeburn 11916: }
11917: }
1.1071 raeburn 11918: if (wantarray) {
11919: return ($output,$count,$codebasecount);
11920: } else {
11921: return $output;
11922: }
1.661 raeburn 11923: }
11924:
11925: sub check_for_existing {
11926: my ($path,$fname,$element) = @_;
11927: my ($state,$msg);
11928: if (-d $path.'/'.$fname) {
11929: $state = 'exists';
11930: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11931: } elsif (-e $path.'/'.$fname) {
11932: $state = 'exists';
11933: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11934: }
11935: if ($state eq 'exists') {
11936: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11937: }
11938: return ($state,$msg);
11939: }
11940:
11941: sub check_for_upload {
11942: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11943: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11944: my $filesize = length($env{'form.'.$element});
11945: if (!$filesize) {
11946: my $msg = '<span class="LC_error">'.
11947: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11948: '<span class="LC_filename">'.$fname.'</span>',
11949: $filesize).'<br />'.
1.1007 raeburn 11950: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11951: '</span>';
11952: return ('zero_bytes',$msg);
11953: }
11954: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11955: my $getpropath = 1;
1.1021 raeburn 11956: my ($dirlistref,$listerror) =
11957: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11958: my $found_file = 0;
11959: my $locked_file = 0;
1.991 raeburn 11960: my @lockers;
11961: my $navmap;
11962: if ($env{'request.course.id'}) {
11963: $navmap = Apache::lonnavmaps::navmap->new();
11964: }
1.1021 raeburn 11965: if (ref($dirlistref) eq 'ARRAY') {
11966: foreach my $line (@{$dirlistref}) {
11967: my ($file_name,$rest)=split(/\&/,$line,2);
11968: if ($file_name eq $fname){
11969: $file_name = $path.$file_name;
11970: if ($group ne '') {
11971: $file_name = $group.$file_name;
11972: }
11973: $found_file = 1;
11974: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11975: foreach my $lock (@lockers) {
11976: if (ref($lock) eq 'ARRAY') {
11977: my ($symb,$crsid) = @{$lock};
11978: if ($crsid eq $env{'request.course.id'}) {
11979: if (ref($navmap)) {
11980: my $res = $navmap->getBySymb($symb);
11981: foreach my $part (@{$res->parts()}) {
11982: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11983: unless (($slot_status == $res->RESERVED) ||
11984: ($slot_status == $res->RESERVED_LOCATION)) {
11985: $locked_file = 1;
11986: }
1.991 raeburn 11987: }
1.1021 raeburn 11988: } else {
11989: $locked_file = 1;
1.991 raeburn 11990: }
11991: } else {
11992: $locked_file = 1;
11993: }
11994: }
1.1021 raeburn 11995: }
11996: } else {
11997: my @info = split(/\&/,$rest);
11998: my $currsize = $info[6]/1000;
11999: if ($currsize < $filesize) {
12000: my $extra = $filesize - $currsize;
12001: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12002: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12003: &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 12004: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12005: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12006: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12007: return ('will_exceed_quota',$msg);
12008: }
1.984 raeburn 12009: }
12010: }
1.661 raeburn 12011: }
12012: }
12013: }
12014: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12015: my $msg = '<p class="LC_warning">'.
12016: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12017: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12018: return ('will_exceed_quota',$msg);
12019: } elsif ($found_file) {
12020: if ($locked_file) {
1.1179 bisitz 12021: my $msg = '<p class="LC_warning">';
1.661 raeburn 12022: $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 12023: $msg .= '</p>';
1.661 raeburn 12024: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12025: return ('file_locked',$msg);
12026: } else {
1.1179 bisitz 12027: my $msg = '<p class="LC_error">';
1.984 raeburn 12028: $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 12029: $msg .= '</p>';
1.984 raeburn 12030: return ('existingfile',$msg);
1.661 raeburn 12031: }
12032: }
12033: }
12034:
1.987 raeburn 12035: sub check_for_traversal {
12036: my ($path,$url,$toplevel) = @_;
12037: my @parts=split(/\//,$path);
12038: my $cleanpath;
12039: my $fullpath = $url;
12040: for (my $i=0;$i<@parts;$i++) {
12041: next if ($parts[$i] eq '.');
12042: if ($parts[$i] eq '..') {
12043: $fullpath =~ s{([^/]+/)$}{};
12044: } else {
12045: $fullpath .= $parts[$i].'/';
12046: }
12047: }
12048: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12049: $cleanpath = $1;
12050: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12051: my $curr_toprel = $1;
12052: my @parts = split(/\//,$curr_toprel);
12053: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12054: my @urlparts = split(/\//,$url_toprel);
12055: my $doubledots;
12056: my $startdiff = -1;
12057: for (my $i=0; $i<@urlparts; $i++) {
12058: if ($startdiff == -1) {
12059: unless ($urlparts[$i] eq $parts[$i]) {
12060: $startdiff = $i;
12061: $doubledots .= '../';
12062: }
12063: } else {
12064: $doubledots .= '../';
12065: }
12066: }
12067: if ($startdiff > -1) {
12068: $cleanpath = $doubledots;
12069: for (my $i=$startdiff; $i<@parts; $i++) {
12070: $cleanpath .= $parts[$i].'/';
12071: }
12072: }
12073: }
12074: $cleanpath =~ s{(/)$}{};
12075: return $cleanpath;
12076: }
1.31 albertel 12077:
1.1053 raeburn 12078: sub is_archive_file {
12079: my ($mimetype) = @_;
12080: if (($mimetype eq 'application/octet-stream') ||
12081: ($mimetype eq 'application/x-stuffit') ||
12082: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12083: return 1;
12084: }
12085: return;
12086: }
12087:
12088: sub decompress_form {
1.1065 raeburn 12089: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12090: my %lt = &Apache::lonlocal::texthash (
12091: this => 'This file is an archive file.',
1.1067 raeburn 12092: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12093: itsc => 'Its contents are as follows:',
1.1053 raeburn 12094: youm => 'You may wish to extract its contents.',
12095: extr => 'Extract contents',
1.1067 raeburn 12096: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12097: proa => 'Process automatically?',
1.1053 raeburn 12098: yes => 'Yes',
12099: no => 'No',
1.1067 raeburn 12100: fold => 'Title for folder containing movie',
12101: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12102: );
1.1065 raeburn 12103: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12104: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12105: my $info = &list_archive_contents($fileloc,\@paths);
12106: if (@paths) {
12107: foreach my $path (@paths) {
12108: $path =~ s{^/}{};
1.1067 raeburn 12109: if ($path =~ m{^([^/]+)/$}) {
12110: $topdir = $1;
12111: }
1.1065 raeburn 12112: if ($path =~ m{^([^/]+)/}) {
12113: $toplevel{$1} = $path;
12114: } else {
12115: $toplevel{$path} = $path;
12116: }
12117: }
12118: }
1.1067 raeburn 12119: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12120: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12121: "$topdir/media/",
12122: "$topdir/media/$topdir.mp4",
12123: "$topdir/media/FirstFrame.png",
12124: "$topdir/media/player.swf",
12125: "$topdir/media/swfobject.js",
12126: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12127: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12128: "$topdir/$topdir.mp4",
12129: "$topdir/$topdir\_config.xml",
12130: "$topdir/$topdir\_controller.swf",
12131: "$topdir/$topdir\_embed.css",
12132: "$topdir/$topdir\_First_Frame.png",
12133: "$topdir/$topdir\_player.html",
12134: "$topdir/$topdir\_Thumbnails.png",
12135: "$topdir/playerProductInstall.swf",
12136: "$topdir/scripts/",
12137: "$topdir/scripts/config_xml.js",
12138: "$topdir/scripts/handlebars.js",
12139: "$topdir/scripts/jquery-1.7.1.min.js",
12140: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12141: "$topdir/scripts/modernizr.js",
12142: "$topdir/scripts/player-min.js",
12143: "$topdir/scripts/swfobject.js",
12144: "$topdir/skins/",
12145: "$topdir/skins/configuration_express.xml",
12146: "$topdir/skins/express_show/",
12147: "$topdir/skins/express_show/player-min.css",
12148: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12149: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12150: "$topdir/$topdir.mp4",
12151: "$topdir/$topdir\_config.xml",
12152: "$topdir/$topdir\_controller.swf",
12153: "$topdir/$topdir\_embed.css",
12154: "$topdir/$topdir\_First_Frame.png",
12155: "$topdir/$topdir\_player.html",
12156: "$topdir/$topdir\_Thumbnails.png",
12157: "$topdir/playerProductInstall.swf",
12158: "$topdir/scripts/",
12159: "$topdir/scripts/config_xml.js",
12160: "$topdir/scripts/techsmith-smart-player.min.js",
12161: "$topdir/skins/",
12162: "$topdir/skins/configuration_express.xml",
12163: "$topdir/skins/express_show/",
12164: "$topdir/skins/express_show/spritesheet.min.css",
12165: "$topdir/skins/express_show/spritesheet.png",
12166: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12167: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12168: if (@diffs == 0) {
1.1164 raeburn 12169: $is_camtasia = 6;
12170: } else {
1.1197 raeburn 12171: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12172: if (@diffs == 0) {
12173: $is_camtasia = 8;
1.1197 raeburn 12174: } else {
12175: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12176: if (@diffs == 0) {
12177: $is_camtasia = 8;
12178: }
1.1164 raeburn 12179: }
1.1067 raeburn 12180: }
12181: }
12182: my $output;
12183: if ($is_camtasia) {
12184: $output = <<"ENDCAM";
12185: <script type="text/javascript" language="Javascript">
12186: // <![CDATA[
12187:
12188: function camtasiaToggle() {
12189: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12190: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12191: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12192: document.getElementById('camtasia_titles').style.display='block';
12193: } else {
12194: document.getElementById('camtasia_titles').style.display='none';
12195: }
12196: }
12197: }
12198: return;
12199: }
12200:
12201: // ]]>
12202: </script>
12203: <p>$lt{'camt'}</p>
12204: ENDCAM
1.1065 raeburn 12205: } else {
1.1067 raeburn 12206: $output = '<p>'.$lt{'this'};
12207: if ($info eq '') {
12208: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12209: } else {
12210: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12211: '<div><pre>'.$info.'</pre></div>';
12212: }
1.1065 raeburn 12213: }
1.1067 raeburn 12214: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12215: my $duplicates;
12216: my $num = 0;
12217: if (ref($dirlist) eq 'ARRAY') {
12218: foreach my $item (@{$dirlist}) {
12219: if (ref($item) eq 'ARRAY') {
12220: if (exists($toplevel{$item->[0]})) {
12221: $duplicates .=
12222: &start_data_table_row().
12223: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12224: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12225: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12226: 'value="1" />'.&mt('Yes').'</label>'.
12227: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12228: '<td>'.$item->[0].'</td>';
12229: if ($item->[2]) {
12230: $duplicates .= '<td>'.&mt('Directory').'</td>';
12231: } else {
12232: $duplicates .= '<td>'.&mt('File').'</td>';
12233: }
12234: $duplicates .= '<td>'.$item->[3].'</td>'.
12235: '<td>'.
12236: &Apache::lonlocal::locallocaltime($item->[4]).
12237: '</td>'.
12238: &end_data_table_row();
12239: $num ++;
12240: }
12241: }
12242: }
12243: }
12244: my $itemcount;
12245: if (@paths > 0) {
12246: $itemcount = scalar(@paths);
12247: } else {
12248: $itemcount = 1;
12249: }
1.1067 raeburn 12250: if ($is_camtasia) {
12251: $output .= $lt{'auto'}.'<br />'.
12252: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12253: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12254: $lt{'yes'}.'</label> <label>'.
12255: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12256: $lt{'no'}.'</label></span><br />'.
12257: '<div id="camtasia_titles" style="display:block">'.
12258: &Apache::lonhtmlcommon::start_pick_box().
12259: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12260: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12261: &Apache::lonhtmlcommon::row_closure().
12262: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12263: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12264: &Apache::lonhtmlcommon::row_closure(1).
12265: &Apache::lonhtmlcommon::end_pick_box().
12266: '</div>';
12267: }
1.1065 raeburn 12268: $output .=
12269: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12270: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12271: "\n";
1.1065 raeburn 12272: if ($duplicates ne '') {
12273: $output .= '<p><span class="LC_warning">'.
12274: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12275: &start_data_table().
12276: &start_data_table_header_row().
12277: '<th>'.&mt('Overwrite?').'</th>'.
12278: '<th>'.&mt('Name').'</th>'.
12279: '<th>'.&mt('Type').'</th>'.
12280: '<th>'.&mt('Size').'</th>'.
12281: '<th>'.&mt('Last modified').'</th>'.
12282: &end_data_table_header_row().
12283: $duplicates.
12284: &end_data_table().
12285: '</p>';
12286: }
1.1067 raeburn 12287: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12288: if (ref($hiddenelements) eq 'HASH') {
12289: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12290: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12291: }
12292: }
12293: $output .= <<"END";
1.1067 raeburn 12294: <br />
1.1053 raeburn 12295: <input type="submit" name="decompress" value="$lt{'extr'}" />
12296: </form>
12297: $noextract
12298: END
12299: return $output;
12300: }
12301:
1.1065 raeburn 12302: sub decompression_utility {
12303: my ($program) = @_;
12304: my @utilities = ('tar','gunzip','bunzip2','unzip');
12305: my $location;
12306: if (grep(/^\Q$program\E$/,@utilities)) {
12307: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12308: '/usr/sbin/') {
12309: if (-x $dir.$program) {
12310: $location = $dir.$program;
12311: last;
12312: }
12313: }
12314: }
12315: return $location;
12316: }
12317:
12318: sub list_archive_contents {
12319: my ($file,$pathsref) = @_;
12320: my (@cmd,$output);
12321: my $needsregexp;
12322: if ($file =~ /\.zip$/) {
12323: @cmd = (&decompression_utility('unzip'),"-l");
12324: $needsregexp = 1;
12325: } elsif (($file =~ m/\.tar\.gz$/) ||
12326: ($file =~ /\.tgz$/)) {
12327: @cmd = (&decompression_utility('tar'),"-ztf");
12328: } elsif ($file =~ /\.tar\.bz2$/) {
12329: @cmd = (&decompression_utility('tar'),"-jtf");
12330: } elsif ($file =~ m|\.tar$|) {
12331: @cmd = (&decompression_utility('tar'),"-tf");
12332: }
12333: if (@cmd) {
12334: undef($!);
12335: undef($@);
12336: if (open(my $fh,"-|", @cmd, $file)) {
12337: while (my $line = <$fh>) {
12338: $output .= $line;
12339: chomp($line);
12340: my $item;
12341: if ($needsregexp) {
12342: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12343: } else {
12344: $item = $line;
12345: }
12346: if ($item ne '') {
12347: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12348: push(@{$pathsref},$item);
12349: }
12350: }
12351: }
12352: close($fh);
12353: }
12354: }
12355: return $output;
12356: }
12357:
1.1053 raeburn 12358: sub decompress_uploaded_file {
12359: my ($file,$dir) = @_;
12360: &Apache::lonnet::appenv({'cgi.file' => $file});
12361: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12362: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12363: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12364: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12365: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12366: my $decompressed = $env{'cgi.decompressed'};
12367: &Apache::lonnet::delenv('cgi.file');
12368: &Apache::lonnet::delenv('cgi.dir');
12369: &Apache::lonnet::delenv('cgi.decompressed');
12370: return ($decompressed,$result);
12371: }
12372:
1.1055 raeburn 12373: sub process_decompression {
12374: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
12375: my ($dir,$error,$warning,$output);
1.1180 raeburn 12376: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12377: $error = &mt('Filename not a supported archive file type.').
12378: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12379: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12380: } else {
12381: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12382: if ($docuhome eq 'no_host') {
12383: $error = &mt('Could not determine home server for course.');
12384: } else {
12385: my @ids=&Apache::lonnet::current_machine_ids();
12386: my $currdir = "$dir_root/$destination";
12387: if (grep(/^\Q$docuhome\E$/,@ids)) {
12388: $dir = &LONCAPA::propath($docudom,$docuname).
12389: "$dir_root/$destination";
12390: } else {
12391: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12392: "$dir_root/$docudom/$docuname/$destination";
12393: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12394: $error = &mt('Archive file not found.');
12395: }
12396: }
1.1065 raeburn 12397: my (@to_overwrite,@to_skip);
12398: if ($env{'form.archive_overwrite_total'} > 0) {
12399: my $total = $env{'form.archive_overwrite_total'};
12400: for (my $i=0; $i<$total; $i++) {
12401: if ($env{'form.archive_overwrite_'.$i} == 1) {
12402: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12403: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12404: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12405: }
12406: }
12407: }
12408: my $numskip = scalar(@to_skip);
12409: if (($numskip > 0) &&
12410: ($numskip == $env{'form.archive_itemcount'})) {
12411: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12412: } elsif ($dir eq '') {
1.1055 raeburn 12413: $error = &mt('Directory containing archive file unavailable.');
12414: } elsif (!$error) {
1.1065 raeburn 12415: my ($decompressed,$display);
12416: if ($numskip > 0) {
12417: my $tempdir = time.'_'.$$.int(rand(10000));
12418: mkdir("$dir/$tempdir",0755);
12419: system("mv $dir/$file $dir/$tempdir/$file");
12420: ($decompressed,$display) =
12421: &decompress_uploaded_file($file,"$dir/$tempdir");
12422: foreach my $item (@to_skip) {
12423: if (($item ne '') && ($item !~ /\.\./)) {
12424: if (-f "$dir/$tempdir/$item") {
12425: unlink("$dir/$tempdir/$item");
12426: } elsif (-d "$dir/$tempdir/$item") {
12427: system("rm -rf $dir/$tempdir/$item");
12428: }
12429: }
12430: }
12431: system("mv $dir/$tempdir/* $dir");
12432: rmdir("$dir/$tempdir");
12433: } else {
12434: ($decompressed,$display) =
12435: &decompress_uploaded_file($file,$dir);
12436: }
1.1055 raeburn 12437: if ($decompressed eq 'ok') {
1.1065 raeburn 12438: $output = '<p class="LC_info">'.
12439: &mt('Files extracted successfully from archive.').
12440: '</p>'."\n";
1.1055 raeburn 12441: my ($warning,$result,@contents);
12442: my ($newdirlistref,$newlisterror) =
12443: &Apache::lonnet::dirlist($currdir,$docudom,
12444: $docuname,1);
12445: my (%is_dir,%changes,@newitems);
12446: my $dirptr = 16384;
1.1065 raeburn 12447: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12448: foreach my $dir_line (@{$newdirlistref}) {
12449: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 12450: unless (($item =~ /^\.+$/) || ($item eq $file) ||
12451: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 12452: push(@newitems,$item);
12453: if ($dirptr&$testdir) {
12454: $is_dir{$item} = 1;
12455: }
12456: $changes{$item} = 1;
12457: }
12458: }
12459: }
12460: if (keys(%changes) > 0) {
12461: foreach my $item (sort(@newitems)) {
12462: if ($changes{$item}) {
12463: push(@contents,$item);
12464: }
12465: }
12466: }
12467: if (@contents > 0) {
1.1067 raeburn 12468: my $wantform;
12469: unless ($env{'form.autoextract_camtasia'}) {
12470: $wantform = 1;
12471: }
1.1056 raeburn 12472: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12473: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12474: $currdir,\%is_dir,
12475: \%children,\%parent,
1.1056 raeburn 12476: \@contents,\%dirorder,
12477: \%titles,$wantform);
1.1055 raeburn 12478: if ($datatable ne '') {
12479: $output .= &archive_options_form('decompressed',$datatable,
12480: $count,$hiddenelem);
1.1065 raeburn 12481: my $startcount = 6;
1.1055 raeburn 12482: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12483: \%titles,\%children);
1.1055 raeburn 12484: }
1.1067 raeburn 12485: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 12486: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12487: my %displayed;
12488: my $total = 1;
12489: $env{'form.archive_directory'} = [];
12490: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12491: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12492: $path =~ s{/$}{};
12493: my $item;
12494: if ($path ne '') {
12495: $item = "$path/$titles{$i}";
12496: } else {
12497: $item = $titles{$i};
12498: }
12499: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12500: if ($item eq $contents[0]) {
12501: push(@{$env{'form.archive_directory'}},$i);
12502: $env{'form.archive_'.$i} = 'display';
12503: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12504: $displayed{'folder'} = $i;
1.1164 raeburn 12505: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12506: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12507: $env{'form.archive_'.$i} = 'display';
12508: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12509: $displayed{'web'} = $i;
12510: } else {
1.1164 raeburn 12511: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12512: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12513: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12514: push(@{$env{'form.archive_directory'}},$i);
12515: }
12516: $env{'form.archive_'.$i} = 'dependency';
12517: }
12518: $total ++;
12519: }
12520: for (my $i=1; $i<$total; $i++) {
12521: next if ($i == $displayed{'web'});
12522: next if ($i == $displayed{'folder'});
12523: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12524: }
12525: $env{'form.phase'} = 'decompress_cleanup';
12526: $env{'form.archivedelete'} = 1;
12527: $env{'form.archive_count'} = $total-1;
12528: $output .=
12529: &process_extracted_files('coursedocs',$docudom,
12530: $docuname,$destination,
12531: $dir_root,$hiddenelem);
12532: }
1.1055 raeburn 12533: } else {
12534: $warning = &mt('No new items extracted from archive file.');
12535: }
12536: } else {
12537: $output = $display;
12538: $error = &mt('An error occurred during extraction from the archive file.');
12539: }
12540: }
12541: }
12542: }
12543: if ($error) {
12544: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12545: $error.'</p>'."\n";
12546: }
12547: if ($warning) {
12548: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12549: }
12550: return $output;
12551: }
12552:
12553: sub get_extracted {
1.1056 raeburn 12554: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12555: $titles,$wantform) = @_;
1.1055 raeburn 12556: my $count = 0;
12557: my $depth = 0;
12558: my $datatable;
1.1056 raeburn 12559: my @hierarchy;
1.1055 raeburn 12560: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12561: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12562: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12563: foreach my $item (@{$contents}) {
12564: $count ++;
1.1056 raeburn 12565: @{$dirorder->{$count}} = @hierarchy;
12566: $titles->{$count} = $item;
1.1055 raeburn 12567: &archive_hierarchy($depth,$count,$parent,$children);
12568: if ($wantform) {
12569: $datatable .= &archive_row($is_dir->{$item},$item,
12570: $currdir,$depth,$count);
12571: }
12572: if ($is_dir->{$item}) {
12573: $depth ++;
1.1056 raeburn 12574: push(@hierarchy,$count);
12575: $parent->{$depth} = $count;
1.1055 raeburn 12576: $datatable .=
12577: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12578: \$depth,\$count,\@hierarchy,$dirorder,
12579: $children,$parent,$titles,$wantform);
1.1055 raeburn 12580: $depth --;
1.1056 raeburn 12581: pop(@hierarchy);
1.1055 raeburn 12582: }
12583: }
12584: return ($count,$datatable);
12585: }
12586:
12587: sub recurse_extracted_archive {
1.1056 raeburn 12588: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12589: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12590: my $result='';
1.1056 raeburn 12591: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12592: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12593: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12594: return $result;
12595: }
12596: my $dirptr = 16384;
12597: my ($newdirlistref,$newlisterror) =
12598: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12599: if (ref($newdirlistref) eq 'ARRAY') {
12600: foreach my $dir_line (@{$newdirlistref}) {
12601: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12602: unless ($item =~ /^\.+$/) {
12603: $$count ++;
1.1056 raeburn 12604: @{$dirorder->{$$count}} = @{$hierarchy};
12605: $titles->{$$count} = $item;
1.1055 raeburn 12606: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12607:
1.1055 raeburn 12608: my $is_dir;
12609: if ($dirptr&$testdir) {
12610: $is_dir = 1;
12611: }
12612: if ($wantform) {
12613: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12614: }
12615: if ($is_dir) {
12616: $$depth ++;
1.1056 raeburn 12617: push(@{$hierarchy},$$count);
12618: $parent->{$$depth} = $$count;
1.1055 raeburn 12619: $result .=
12620: &recurse_extracted_archive("$currdir/$item",$docudom,
12621: $docuname,$depth,$count,
1.1056 raeburn 12622: $hierarchy,$dirorder,$children,
12623: $parent,$titles,$wantform);
1.1055 raeburn 12624: $$depth --;
1.1056 raeburn 12625: pop(@{$hierarchy});
1.1055 raeburn 12626: }
12627: }
12628: }
12629: }
12630: return $result;
12631: }
12632:
12633: sub archive_hierarchy {
12634: my ($depth,$count,$parent,$children) =@_;
12635: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12636: if (exists($parent->{$depth})) {
12637: $children->{$parent->{$depth}} .= $count.':';
12638: }
12639: }
12640: return;
12641: }
12642:
12643: sub archive_row {
12644: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12645: my ($name) = ($item =~ m{([^/]+)$});
12646: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12647: 'display' => 'Add as file',
1.1055 raeburn 12648: 'dependency' => 'Include as dependency',
12649: 'discard' => 'Discard',
12650: );
12651: if ($is_dir) {
1.1059 raeburn 12652: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12653: }
1.1056 raeburn 12654: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12655: my $offset = 0;
1.1055 raeburn 12656: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12657: $offset ++;
1.1065 raeburn 12658: if ($action ne 'display') {
12659: $offset ++;
12660: }
1.1055 raeburn 12661: $output .= '<td><span class="LC_nobreak">'.
12662: '<label><input type="radio" name="archive_'.$count.
12663: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12664: my $text = $choices{$action};
12665: if ($is_dir) {
12666: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12667: if ($action eq 'display') {
1.1059 raeburn 12668: $text = &mt('Add as folder');
1.1055 raeburn 12669: }
1.1056 raeburn 12670: } else {
12671: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12672:
12673: }
12674: $output .= ' /> '.$choices{$action}.'</label></span>';
12675: if ($action eq 'dependency') {
12676: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12677: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12678: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12679: '<option value=""></option>'."\n".
12680: '</select>'."\n".
12681: '</div>';
1.1059 raeburn 12682: } elsif ($action eq 'display') {
12683: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12684: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12685: '</div>';
1.1055 raeburn 12686: }
1.1056 raeburn 12687: $output .= '</td>';
1.1055 raeburn 12688: }
12689: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12690: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12691: for (my $i=0; $i<$depth; $i++) {
12692: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12693: }
12694: if ($is_dir) {
12695: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12696: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12697: } else {
12698: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12699: }
12700: $output .= ' '.$name.'</td>'."\n".
12701: &end_data_table_row();
12702: return $output;
12703: }
12704:
12705: sub archive_options_form {
1.1065 raeburn 12706: my ($form,$display,$count,$hiddenelem) = @_;
12707: my %lt = &Apache::lonlocal::texthash(
12708: perm => 'Permanently remove archive file?',
12709: hows => 'How should each extracted item be incorporated in the course?',
12710: cont => 'Content actions for all',
12711: addf => 'Add as folder/file',
12712: incd => 'Include as dependency for a displayed file',
12713: disc => 'Discard',
12714: no => 'No',
12715: yes => 'Yes',
12716: save => 'Save',
12717: );
12718: my $output = <<"END";
12719: <form name="$form" method="post" action="">
12720: <p><span class="LC_nobreak">$lt{'perm'}
12721: <label>
12722: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12723: </label>
12724:
12725: <label>
12726: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12727: </span>
12728: </p>
12729: <input type="hidden" name="phase" value="decompress_cleanup" />
12730: <br />$lt{'hows'}
12731: <div class="LC_columnSection">
12732: <fieldset>
12733: <legend>$lt{'cont'}</legend>
12734: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12735: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12736: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12737: </fieldset>
12738: </div>
12739: END
12740: return $output.
1.1055 raeburn 12741: &start_data_table()."\n".
1.1065 raeburn 12742: $display."\n".
1.1055 raeburn 12743: &end_data_table()."\n".
12744: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12745: $hiddenelem.
1.1065 raeburn 12746: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12747: '</form>';
12748: }
12749:
12750: sub archive_javascript {
1.1056 raeburn 12751: my ($startcount,$numitems,$titles,$children) = @_;
12752: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12753: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12754: my $scripttag = <<START;
12755: <script type="text/javascript">
12756: // <![CDATA[
12757:
12758: function checkAll(form,prefix) {
12759: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12760: for (var i=0; i < form.elements.length; i++) {
12761: var id = form.elements[i].id;
12762: if ((id != '') && (id != undefined)) {
12763: if (idstr.test(id)) {
12764: if (form.elements[i].type == 'radio') {
12765: form.elements[i].checked = true;
1.1056 raeburn 12766: var nostart = i-$startcount;
1.1059 raeburn 12767: var offset = nostart%7;
12768: var count = (nostart-offset)/7;
1.1056 raeburn 12769: dependencyCheck(form,count,offset);
1.1055 raeburn 12770: }
12771: }
12772: }
12773: }
12774: }
12775:
12776: function propagateCheck(form,count) {
12777: if (count > 0) {
1.1059 raeburn 12778: var startelement = $startcount + ((count-1) * 7);
12779: for (var j=1; j<6; j++) {
12780: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12781: var item = startelement + j;
12782: if (form.elements[item].type == 'radio') {
12783: if (form.elements[item].checked) {
12784: containerCheck(form,count,j);
12785: break;
12786: }
1.1055 raeburn 12787: }
12788: }
12789: }
12790: }
12791: }
12792:
12793: numitems = $numitems
1.1056 raeburn 12794: var titles = new Array(numitems);
12795: var parents = new Array(numitems);
1.1055 raeburn 12796: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12797: parents[i] = new Array;
1.1055 raeburn 12798: }
1.1059 raeburn 12799: var maintitle = '$maintitle';
1.1055 raeburn 12800:
12801: START
12802:
1.1056 raeburn 12803: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12804: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12805: for (my $i=0; $i<@contents; $i ++) {
12806: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12807: }
12808: }
12809:
1.1056 raeburn 12810: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12811: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12812: }
12813:
1.1055 raeburn 12814: $scripttag .= <<END;
12815:
12816: function containerCheck(form,count,offset) {
12817: if (count > 0) {
1.1056 raeburn 12818: dependencyCheck(form,count,offset);
1.1059 raeburn 12819: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12820: form.elements[item].checked = true;
12821: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12822: if (parents[count].length > 0) {
12823: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12824: containerCheck(form,parents[count][j],offset);
12825: }
12826: }
12827: }
12828: }
12829: }
12830:
12831: function dependencyCheck(form,count,offset) {
12832: if (count > 0) {
1.1059 raeburn 12833: var chosen = (offset+$startcount)+7*(count-1);
12834: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12835: var currtype = form.elements[depitem].type;
12836: if (form.elements[chosen].value == 'dependency') {
12837: document.getElementById('arc_depon_'+count).style.display='block';
12838: form.elements[depitem].options.length = 0;
12839: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 12840: for (var i=1; i<=numitems; i++) {
12841: if (i == count) {
12842: continue;
12843: }
1.1059 raeburn 12844: var startelement = $startcount + (i-1) * 7;
12845: for (var j=1; j<6; j++) {
12846: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12847: var item = startelement + j;
12848: if (form.elements[item].type == 'radio') {
12849: if (form.elements[item].checked) {
12850: if (form.elements[item].value == 'display') {
12851: var n = form.elements[depitem].options.length;
12852: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12853: }
12854: }
12855: }
12856: }
12857: }
12858: }
12859: } else {
12860: document.getElementById('arc_depon_'+count).style.display='none';
12861: form.elements[depitem].options.length = 0;
12862: form.elements[depitem].options[0] = new Option('Select','',true,true);
12863: }
1.1059 raeburn 12864: titleCheck(form,count,offset);
1.1056 raeburn 12865: }
12866: }
12867:
12868: function propagateSelect(form,count,offset) {
12869: if (count > 0) {
1.1065 raeburn 12870: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12871: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12872: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12873: if (parents[count].length > 0) {
12874: for (var j=0; j<parents[count].length; j++) {
12875: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12876: }
12877: }
12878: }
12879: }
12880: }
1.1056 raeburn 12881:
12882: function containerSelect(form,count,offset,picked) {
12883: if (count > 0) {
1.1065 raeburn 12884: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12885: if (form.elements[item].type == 'radio') {
12886: if (form.elements[item].value == 'dependency') {
12887: if (form.elements[item+1].type == 'select-one') {
12888: for (var i=0; i<form.elements[item+1].options.length; i++) {
12889: if (form.elements[item+1].options[i].value == picked) {
12890: form.elements[item+1].selectedIndex = i;
12891: break;
12892: }
12893: }
12894: }
12895: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12896: if (parents[count].length > 0) {
12897: for (var j=0; j<parents[count].length; j++) {
12898: containerSelect(form,parents[count][j],offset,picked);
12899: }
12900: }
12901: }
12902: }
12903: }
12904: }
12905: }
12906:
1.1059 raeburn 12907: function titleCheck(form,count,offset) {
12908: if (count > 0) {
12909: var chosen = (offset+$startcount)+7*(count-1);
12910: var depitem = $startcount + ((count-1) * 7) + 2;
12911: var currtype = form.elements[depitem].type;
12912: if (form.elements[chosen].value == 'display') {
12913: document.getElementById('arc_title_'+count).style.display='block';
12914: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12915: document.getElementById('archive_title_'+count).value=maintitle;
12916: }
12917: } else {
12918: document.getElementById('arc_title_'+count).style.display='none';
12919: if (currtype == 'text') {
12920: document.getElementById('archive_title_'+count).value='';
12921: }
12922: }
12923: }
12924: return;
12925: }
12926:
1.1055 raeburn 12927: // ]]>
12928: </script>
12929: END
12930: return $scripttag;
12931: }
12932:
12933: sub process_extracted_files {
1.1067 raeburn 12934: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12935: my $numitems = $env{'form.archive_count'};
12936: return unless ($numitems);
12937: my @ids=&Apache::lonnet::current_machine_ids();
12938: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12939: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12940: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12941: if (grep(/^\Q$docuhome\E$/,@ids)) {
12942: $prefix = &LONCAPA::propath($docudom,$docuname);
12943: $pathtocheck = "$dir_root/$destination";
12944: $dir = $dir_root;
12945: $ishome = 1;
12946: } else {
12947: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12948: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
12949: $dir = "$dir_root/$docudom/$docuname";
12950: }
12951: my $currdir = "$dir_root/$destination";
12952: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12953: if ($env{'form.folderpath'}) {
12954: my @items = split('&',$env{'form.folderpath'});
12955: $folders{'0'} = $items[-2];
1.1099 raeburn 12956: if ($env{'form.folderpath'} =~ /\:1$/) {
12957: $containers{'0'}='page';
12958: } else {
12959: $containers{'0'}='sequence';
12960: }
1.1055 raeburn 12961: }
12962: my @archdirs = &get_env_multiple('form.archive_directory');
12963: if ($numitems) {
12964: for (my $i=1; $i<=$numitems; $i++) {
12965: my $path = $env{'form.archive_content_'.$i};
12966: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12967: my $item = $1;
12968: $toplevelitems{$item} = $i;
12969: if (grep(/^\Q$i\E$/,@archdirs)) {
12970: $is_dir{$item} = 1;
12971: }
12972: }
12973: }
12974: }
1.1067 raeburn 12975: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12976: if (keys(%toplevelitems) > 0) {
12977: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12978: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12979: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12980: }
1.1066 raeburn 12981: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12982: if ($numitems) {
12983: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 12984: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12985: my $path = $env{'form.archive_content_'.$i};
12986: if ($path =~ /^\Q$pathtocheck\E/) {
12987: if ($env{'form.archive_'.$i} eq 'discard') {
12988: if ($prefix ne '' && $path ne '') {
12989: if (-e $prefix.$path) {
1.1066 raeburn 12990: if ((@archdirs > 0) &&
12991: (grep(/^\Q$i\E$/,@archdirs))) {
12992: $todeletedir{$prefix.$path} = 1;
12993: } else {
12994: $todelete{$prefix.$path} = 1;
12995: }
1.1055 raeburn 12996: }
12997: }
12998: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12999: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13000: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13001: $docstitle = $env{'form.archive_title_'.$i};
13002: if ($docstitle eq '') {
13003: $docstitle = $title;
13004: }
1.1055 raeburn 13005: $outer = 0;
1.1056 raeburn 13006: if (ref($dirorder{$i}) eq 'ARRAY') {
13007: if (@{$dirorder{$i}} > 0) {
13008: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13009: if ($env{'form.archive_'.$item} eq 'display') {
13010: $outer = $item;
13011: last;
13012: }
13013: }
13014: }
13015: }
13016: my ($errtext,$fatal) =
13017: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13018: '/'.$folders{$outer}.'.'.
13019: $containers{$outer});
13020: next if ($fatal);
13021: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13022: if ($context eq 'coursedocs') {
1.1056 raeburn 13023: $mapinner{$i} = time;
1.1055 raeburn 13024: $folders{$i} = 'default_'.$mapinner{$i};
13025: $containers{$i} = 'sequence';
13026: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13027: $folders{$i}.'.'.$containers{$i};
13028: my $newidx = &LONCAPA::map::getresidx();
13029: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13030: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13031: push(@LONCAPA::map::order,$newidx);
13032: my ($outtext,$errtext) =
13033: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13034: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13035: '.'.$containers{$outer},1,1);
1.1056 raeburn 13036: $newseqid{$i} = $newidx;
1.1067 raeburn 13037: unless ($errtext) {
13038: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
13039: }
1.1055 raeburn 13040: }
13041: } else {
13042: if ($context eq 'coursedocs') {
13043: my $newidx=&LONCAPA::map::getresidx();
13044: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13045: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13046: $title;
13047: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13048: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13049: }
13050: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13051: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13052: }
13053: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13054: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 13055: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 13056: unless ($ishome) {
13057: my $fetch = "$newdest{$i}/$title";
13058: $fetch =~ s/^\Q$prefix$dir\E//;
13059: $prompttofetch{$fetch} = 1;
13060: }
1.1055 raeburn 13061: }
13062: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13063: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13064: push(@LONCAPA::map::order, $newidx);
13065: my ($outtext,$errtext)=
13066: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13067: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13068: '.'.$containers{$outer},1,1);
1.1067 raeburn 13069: unless ($errtext) {
13070: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13071: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
13072: }
13073: }
1.1055 raeburn 13074: }
13075: }
1.1086 raeburn 13076: }
13077: } else {
13078: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13079: }
13080: }
13081: for (my $i=1; $i<=$numitems; $i++) {
13082: next unless ($env{'form.archive_'.$i} eq 'dependency');
13083: my $path = $env{'form.archive_content_'.$i};
13084: if ($path =~ /^\Q$pathtocheck\E/) {
13085: my ($title) = ($path =~ m{/([^/]+)$});
13086: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13087: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13088: if (ref($dirorder{$i}) eq 'ARRAY') {
13089: my ($itemidx,$fullpath,$relpath);
13090: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13091: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13092: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13093: if ($dirorder{$i}->[$j] eq $container) {
13094: $itemidx = $j;
1.1056 raeburn 13095: }
13096: }
1.1086 raeburn 13097: }
13098: if ($itemidx eq '') {
13099: $itemidx = 0;
13100: }
13101: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13102: if ($mapinner{$referrer{$i}}) {
13103: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13104: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13105: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13106: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13107: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13108: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13109: if (!-e $fullpath) {
13110: mkdir($fullpath,0755);
1.1056 raeburn 13111: }
13112: }
1.1086 raeburn 13113: } else {
13114: last;
1.1056 raeburn 13115: }
1.1086 raeburn 13116: }
13117: }
13118: } elsif ($newdest{$referrer{$i}}) {
13119: $fullpath = $newdest{$referrer{$i}};
13120: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13121: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13122: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13123: last;
13124: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13125: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13126: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13127: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13128: if (!-e $fullpath) {
13129: mkdir($fullpath,0755);
1.1056 raeburn 13130: }
13131: }
1.1086 raeburn 13132: } else {
13133: last;
1.1056 raeburn 13134: }
1.1055 raeburn 13135: }
13136: }
1.1086 raeburn 13137: if ($fullpath ne '') {
13138: if (-e "$prefix$path") {
13139: system("mv $prefix$path $fullpath/$title");
13140: }
13141: if (-e "$fullpath/$title") {
13142: my $showpath;
13143: if ($relpath ne '') {
13144: $showpath = "$relpath/$title";
13145: } else {
13146: $showpath = "/$title";
13147: }
13148: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
13149: }
13150: unless ($ishome) {
13151: my $fetch = "$fullpath/$title";
13152: $fetch =~ s/^\Q$prefix$dir\E//;
13153: $prompttofetch{$fetch} = 1;
13154: }
13155: }
1.1055 raeburn 13156: }
1.1086 raeburn 13157: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13158: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
13159: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 13160: }
13161: } else {
13162: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13163: }
13164: }
13165: if (keys(%todelete)) {
13166: foreach my $key (keys(%todelete)) {
13167: unlink($key);
1.1066 raeburn 13168: }
13169: }
13170: if (keys(%todeletedir)) {
13171: foreach my $key (keys(%todeletedir)) {
13172: rmdir($key);
13173: }
13174: }
13175: foreach my $dir (sort(keys(%is_dir))) {
13176: if (($pathtocheck ne '') && ($dir ne '')) {
13177: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13178: }
13179: }
1.1067 raeburn 13180: if ($result ne '') {
13181: $output .= '<ul>'."\n".
13182: $result."\n".
13183: '</ul>';
13184: }
13185: unless ($ishome) {
13186: my $replicationfail;
13187: foreach my $item (keys(%prompttofetch)) {
13188: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13189: unless ($fetchresult eq 'ok') {
13190: $replicationfail .= '<li>'.$item.'</li>'."\n";
13191: }
13192: }
13193: if ($replicationfail) {
13194: $output .= '<p class="LC_error">'.
13195: &mt('Course home server failed to retrieve:').'<ul>'.
13196: $replicationfail.
13197: '</ul></p>';
13198: }
13199: }
1.1055 raeburn 13200: } else {
13201: $warning = &mt('No items found in archive.');
13202: }
13203: if ($error) {
13204: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13205: $error.'</p>'."\n";
13206: }
13207: if ($warning) {
13208: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13209: }
13210: return $output;
13211: }
13212:
1.1066 raeburn 13213: sub cleanup_empty_dirs {
13214: my ($path) = @_;
13215: if (($path ne '') && (-d $path)) {
13216: if (opendir(my $dirh,$path)) {
13217: my @dircontents = grep(!/^\./,readdir($dirh));
13218: my $numitems = 0;
13219: foreach my $item (@dircontents) {
13220: if (-d "$path/$item") {
1.1111 raeburn 13221: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13222: if (-e "$path/$item") {
13223: $numitems ++;
13224: }
13225: } else {
13226: $numitems ++;
13227: }
13228: }
13229: if ($numitems == 0) {
13230: rmdir($path);
13231: }
13232: closedir($dirh);
13233: }
13234: }
13235: return;
13236: }
13237:
1.41 ng 13238: =pod
1.45 matthew 13239:
1.1162 raeburn 13240: =item * &get_folder_hierarchy()
1.1068 raeburn 13241:
13242: Provides hierarchy of names of folders/sub-folders containing the current
13243: item,
13244:
13245: Inputs: 3
13246: - $navmap - navmaps object
13247:
13248: - $map - url for map (either the trigger itself, or map containing
13249: the resource, which is the trigger).
13250:
13251: - $showitem - 1 => show title for map itself; 0 => do not show.
13252:
13253: Outputs: 1 @pathitems - array of folder/subfolder names.
13254:
13255: =cut
13256:
13257: sub get_folder_hierarchy {
13258: my ($navmap,$map,$showitem) = @_;
13259: my @pathitems;
13260: if (ref($navmap)) {
13261: my $mapres = $navmap->getResourceByUrl($map);
13262: if (ref($mapres)) {
13263: my $pcslist = $mapres->map_hierarchy();
13264: if ($pcslist ne '') {
13265: my @pcs = split(/,/,$pcslist);
13266: foreach my $pc (@pcs) {
13267: if ($pc == 1) {
1.1129 raeburn 13268: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13269: } else {
13270: my $res = $navmap->getByMapPc($pc);
13271: if (ref($res)) {
13272: my $title = $res->compTitle();
13273: $title =~ s/\W+/_/g;
13274: if ($title ne '') {
13275: push(@pathitems,$title);
13276: }
13277: }
13278: }
13279: }
13280: }
1.1071 raeburn 13281: if ($showitem) {
13282: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13283: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13284: } else {
13285: my $maptitle = $mapres->compTitle();
13286: $maptitle =~ s/\W+/_/g;
13287: if ($maptitle ne '') {
13288: push(@pathitems,$maptitle);
13289: }
1.1068 raeburn 13290: }
13291: }
13292: }
13293: }
13294: return @pathitems;
13295: }
13296:
13297: =pod
13298:
1.1015 raeburn 13299: =item * &get_turnedin_filepath()
13300:
13301: Determines path in a user's portfolio file for storage of files uploaded
13302: to a specific essayresponse or dropbox item.
13303:
13304: Inputs: 3 required + 1 optional.
13305: $symb is symb for resource, $uname and $udom are for current user (required).
13306: $caller is optional (can be "submission", if routine is called when storing
13307: an upoaded file when "Submit Answer" button was pressed).
13308:
13309: Returns array containing $path and $multiresp.
13310: $path is path in portfolio. $multiresp is 1 if this resource contains more
13311: than one file upload item. Callers of routine should append partid as a
13312: subdirectory to $path in cases where $multiresp is 1.
13313:
13314: Called by: homework/essayresponse.pm and homework/structuretags.pm
13315:
13316: =cut
13317:
13318: sub get_turnedin_filepath {
13319: my ($symb,$uname,$udom,$caller) = @_;
13320: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13321: my $turnindir;
13322: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13323: $turnindir = $userhash{'turnindir'};
13324: my ($path,$multiresp);
13325: if ($turnindir eq '') {
13326: if ($caller eq 'submission') {
13327: $turnindir = &mt('turned in');
13328: $turnindir =~ s/\W+/_/g;
13329: my %newhash = (
13330: 'turnindir' => $turnindir,
13331: );
13332: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13333: }
13334: }
13335: if ($turnindir ne '') {
13336: $path = '/'.$turnindir.'/';
13337: my ($multipart,$turnin,@pathitems);
13338: my $navmap = Apache::lonnavmaps::navmap->new();
13339: if (defined($navmap)) {
13340: my $mapres = $navmap->getResourceByUrl($map);
13341: if (ref($mapres)) {
13342: my $pcslist = $mapres->map_hierarchy();
13343: if ($pcslist ne '') {
13344: foreach my $pc (split(/,/,$pcslist)) {
13345: my $res = $navmap->getByMapPc($pc);
13346: if (ref($res)) {
13347: my $title = $res->compTitle();
13348: $title =~ s/\W+/_/g;
13349: if ($title ne '') {
1.1149 raeburn 13350: if (($pc > 1) && (length($title) > 12)) {
13351: $title = substr($title,0,12);
13352: }
1.1015 raeburn 13353: push(@pathitems,$title);
13354: }
13355: }
13356: }
13357: }
13358: my $maptitle = $mapres->compTitle();
13359: $maptitle =~ s/\W+/_/g;
13360: if ($maptitle ne '') {
1.1149 raeburn 13361: if (length($maptitle) > 12) {
13362: $maptitle = substr($maptitle,0,12);
13363: }
1.1015 raeburn 13364: push(@pathitems,$maptitle);
13365: }
13366: unless ($env{'request.state'} eq 'construct') {
13367: my $res = $navmap->getBySymb($symb);
13368: if (ref($res)) {
13369: my $partlist = $res->parts();
13370: my $totaluploads = 0;
13371: if (ref($partlist) eq 'ARRAY') {
13372: foreach my $part (@{$partlist}) {
13373: my @types = $res->responseType($part);
13374: my @ids = $res->responseIds($part);
13375: for (my $i=0; $i < scalar(@ids); $i++) {
13376: if ($types[$i] eq 'essay') {
13377: my $partid = $part.'_'.$ids[$i];
13378: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13379: $totaluploads ++;
13380: }
13381: }
13382: }
13383: }
13384: if ($totaluploads > 1) {
13385: $multiresp = 1;
13386: }
13387: }
13388: }
13389: }
13390: } else {
13391: return;
13392: }
13393: } else {
13394: return;
13395: }
13396: my $restitle=&Apache::lonnet::gettitle($symb);
13397: $restitle =~ s/\W+/_/g;
13398: if ($restitle eq '') {
13399: $restitle = ($resurl =~ m{/[^/]+$});
13400: if ($restitle eq '') {
13401: $restitle = time;
13402: }
13403: }
1.1149 raeburn 13404: if (length($restitle) > 12) {
13405: $restitle = substr($restitle,0,12);
13406: }
1.1015 raeburn 13407: push(@pathitems,$restitle);
13408: $path .= join('/',@pathitems);
13409: }
13410: return ($path,$multiresp);
13411: }
13412:
13413: =pod
13414:
1.464 albertel 13415: =back
1.41 ng 13416:
1.112 bowersj2 13417: =head1 CSV Upload/Handling functions
1.38 albertel 13418:
1.41 ng 13419: =over 4
13420:
1.648 raeburn 13421: =item * &upfile_store($r)
1.41 ng 13422:
13423: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13424: needs $env{'form.upfile'}
1.41 ng 13425: returns $datatoken to be put into hidden field
13426:
13427: =cut
1.31 albertel 13428:
13429: sub upfile_store {
13430: my $r=shift;
1.258 albertel 13431: $env{'form.upfile'}=~s/\r/\n/gs;
13432: $env{'form.upfile'}=~s/\f/\n/gs;
13433: $env{'form.upfile'}=~s/\n+/\n/gs;
13434: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13435:
1.258 albertel 13436: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
13437: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 13438: {
1.158 raeburn 13439: my $datafile = $r->dir_config('lonDaemons').
13440: '/tmp/'.$datatoken.'.tmp';
13441: if ( open(my $fh,">$datafile") ) {
1.258 albertel 13442: print $fh $env{'form.upfile'};
1.158 raeburn 13443: close($fh);
13444: }
1.31 albertel 13445: }
13446: return $datatoken;
13447: }
13448:
1.56 matthew 13449: =pod
13450:
1.648 raeburn 13451: =item * &load_tmp_file($r)
1.41 ng 13452:
13453: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 13454: needs $env{'form.datatoken'},
13455: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13456:
13457: =cut
1.31 albertel 13458:
13459: sub load_tmp_file {
13460: my $r=shift;
13461: my @studentdata=();
13462: {
1.158 raeburn 13463: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 13464: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 13465: if ( open(my $fh,"<$studentfile") ) {
13466: @studentdata=<$fh>;
13467: close($fh);
13468: }
1.31 albertel 13469: }
1.258 albertel 13470: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13471: }
13472:
1.56 matthew 13473: =pod
13474:
1.648 raeburn 13475: =item * &upfile_record_sep()
1.41 ng 13476:
13477: Separate uploaded file into records
13478: returns array of records,
1.258 albertel 13479: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13480:
13481: =cut
1.31 albertel 13482:
13483: sub upfile_record_sep {
1.258 albertel 13484: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13485: } else {
1.248 albertel 13486: my @records;
1.258 albertel 13487: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13488: if ($line=~/^\s*$/) { next; }
13489: push(@records,$line);
13490: }
13491: return @records;
1.31 albertel 13492: }
13493: }
13494:
1.56 matthew 13495: =pod
13496:
1.648 raeburn 13497: =item * &record_sep($record)
1.41 ng 13498:
1.258 albertel 13499: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13500:
13501: =cut
13502:
1.263 www 13503: sub takeleft {
13504: my $index=shift;
13505: return substr('0000'.$index,-4,4);
13506: }
13507:
1.31 albertel 13508: sub record_sep {
13509: my $record=shift;
13510: my %components=();
1.258 albertel 13511: if ($env{'form.upfiletype'} eq 'xml') {
13512: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13513: my $i=0;
1.356 albertel 13514: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13515: $field=~s/^(\"|\')//;
13516: $field=~s/(\"|\')$//;
1.263 www 13517: $components{&takeleft($i)}=$field;
1.31 albertel 13518: $i++;
13519: }
1.258 albertel 13520: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13521: my $i=0;
1.356 albertel 13522: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13523: $field=~s/^(\"|\')//;
13524: $field=~s/(\"|\')$//;
1.263 www 13525: $components{&takeleft($i)}=$field;
1.31 albertel 13526: $i++;
13527: }
13528: } else {
1.561 www 13529: my $separator=',';
1.480 banghart 13530: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13531: $separator=';';
1.480 banghart 13532: }
1.31 albertel 13533: my $i=0;
1.561 www 13534: # the character we are looking for to indicate the end of a quote or a record
13535: my $looking_for=$separator;
13536: # do not add the characters to the fields
13537: my $ignore=0;
13538: # we just encountered a separator (or the beginning of the record)
13539: my $just_found_separator=1;
13540: # store the field we are working on here
13541: my $field='';
13542: # work our way through all characters in record
13543: foreach my $character ($record=~/(.)/g) {
13544: if ($character eq $looking_for) {
13545: if ($character ne $separator) {
13546: # Found the end of a quote, again looking for separator
13547: $looking_for=$separator;
13548: $ignore=1;
13549: } else {
13550: # Found a separator, store away what we got
13551: $components{&takeleft($i)}=$field;
13552: $i++;
13553: $just_found_separator=1;
13554: $ignore=0;
13555: $field='';
13556: }
13557: next;
13558: }
13559: # single or double quotation marks after a separator indicate beginning of a quote
13560: # we are now looking for the end of the quote and need to ignore separators
13561: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13562: $looking_for=$character;
13563: next;
13564: }
13565: # ignore would be true after we reached the end of a quote
13566: if ($ignore) { next; }
13567: if (($just_found_separator) && ($character=~/\s/)) { next; }
13568: $field.=$character;
13569: $just_found_separator=0;
1.31 albertel 13570: }
1.561 www 13571: # catch the very last entry, since we never encountered the separator
13572: $components{&takeleft($i)}=$field;
1.31 albertel 13573: }
13574: return %components;
13575: }
13576:
1.144 matthew 13577: ######################################################
13578: ######################################################
13579:
1.56 matthew 13580: =pod
13581:
1.648 raeburn 13582: =item * &upfile_select_html()
1.41 ng 13583:
1.144 matthew 13584: Return HTML code to select a file from the users machine and specify
13585: the file type.
1.41 ng 13586:
13587: =cut
13588:
1.144 matthew 13589: ######################################################
13590: ######################################################
1.31 albertel 13591: sub upfile_select_html {
1.144 matthew 13592: my %Types = (
13593: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13594: semisv => &mt('Semicolon separated values'),
1.144 matthew 13595: space => &mt('Space separated'),
13596: tab => &mt('Tabulator separated'),
13597: # xml => &mt('HTML/XML'),
13598: );
13599: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13600: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13601: foreach my $type (sort(keys(%Types))) {
13602: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13603: }
13604: $Str .= "</select>\n";
13605: return $Str;
1.31 albertel 13606: }
13607:
1.301 albertel 13608: sub get_samples {
13609: my ($records,$toget) = @_;
13610: my @samples=({});
13611: my $got=0;
13612: foreach my $rec (@$records) {
13613: my %temp = &record_sep($rec);
13614: if (! grep(/\S/, values(%temp))) { next; }
13615: if (%temp) {
13616: $samples[$got]=\%temp;
13617: $got++;
13618: if ($got == $toget) { last; }
13619: }
13620: }
13621: return \@samples;
13622: }
13623:
1.144 matthew 13624: ######################################################
13625: ######################################################
13626:
1.56 matthew 13627: =pod
13628:
1.648 raeburn 13629: =item * &csv_print_samples($r,$records)
1.41 ng 13630:
13631: Prints a table of sample values from each column uploaded $r is an
13632: Apache Request ref, $records is an arrayref from
13633: &Apache::loncommon::upfile_record_sep
13634:
13635: =cut
13636:
1.144 matthew 13637: ######################################################
13638: ######################################################
1.31 albertel 13639: sub csv_print_samples {
13640: my ($r,$records) = @_;
1.662 bisitz 13641: my $samples = &get_samples($records,5);
1.301 albertel 13642:
1.594 raeburn 13643: $r->print(&mt('Samples').'<br />'.&start_data_table().
13644: &start_data_table_header_row());
1.356 albertel 13645: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13646: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13647: $r->print(&end_data_table_header_row());
1.301 albertel 13648: foreach my $hash (@$samples) {
1.594 raeburn 13649: $r->print(&start_data_table_row());
1.356 albertel 13650: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13651: $r->print('<td>');
1.356 albertel 13652: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13653: $r->print('</td>');
13654: }
1.594 raeburn 13655: $r->print(&end_data_table_row());
1.31 albertel 13656: }
1.594 raeburn 13657: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13658: }
13659:
1.144 matthew 13660: ######################################################
13661: ######################################################
13662:
1.56 matthew 13663: =pod
13664:
1.648 raeburn 13665: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13666:
13667: Prints a table to create associations between values and table columns.
1.144 matthew 13668:
1.41 ng 13669: $r is an Apache Request ref,
13670: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13671: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13672:
13673: =cut
13674:
1.144 matthew 13675: ######################################################
13676: ######################################################
1.31 albertel 13677: sub csv_print_select_table {
13678: my ($r,$records,$d) = @_;
1.301 albertel 13679: my $i=0;
13680: my $samples = &get_samples($records,1);
1.144 matthew 13681: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13682: &start_data_table().&start_data_table_header_row().
1.144 matthew 13683: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13684: '<th>'.&mt('Column').'</th>'.
13685: &end_data_table_header_row()."\n");
1.356 albertel 13686: foreach my $array_ref (@$d) {
13687: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13688: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13689:
1.875 bisitz 13690: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13691: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13692: $r->print('<option value="none"></option>');
1.356 albertel 13693: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13694: $r->print('<option value="'.$sample.'"'.
13695: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13696: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13697: }
1.594 raeburn 13698: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13699: $i++;
13700: }
1.594 raeburn 13701: $r->print(&end_data_table());
1.31 albertel 13702: $i--;
13703: return $i;
13704: }
1.56 matthew 13705:
1.144 matthew 13706: ######################################################
13707: ######################################################
13708:
1.56 matthew 13709: =pod
1.31 albertel 13710:
1.648 raeburn 13711: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13712:
13713: Prints a table of sample values from the upload and can make associate samples to internal names.
13714:
13715: $r is an Apache Request ref,
13716: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13717: $d is an array of 2 element arrays (internal name, displayed name)
13718:
13719: =cut
13720:
1.144 matthew 13721: ######################################################
13722: ######################################################
1.31 albertel 13723: sub csv_samples_select_table {
13724: my ($r,$records,$d) = @_;
13725: my $i=0;
1.144 matthew 13726: #
1.662 bisitz 13727: my $max_samples = 5;
13728: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13729: $r->print(&start_data_table().
13730: &start_data_table_header_row().'<th>'.
13731: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13732: &end_data_table_header_row());
1.301 albertel 13733:
13734: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13735: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13736: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13737: foreach my $option (@$d) {
13738: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13739: $r->print('<option value="'.$value.'"'.
1.253 albertel 13740: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13741: $display.'</option>');
1.31 albertel 13742: }
13743: $r->print('</select></td><td>');
1.662 bisitz 13744: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13745: if (defined($samples->[$line]{$key})) {
13746: $r->print($samples->[$line]{$key}."<br />\n");
13747: }
13748: }
1.594 raeburn 13749: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13750: $i++;
13751: }
1.594 raeburn 13752: $r->print(&end_data_table());
1.31 albertel 13753: $i--;
13754: return($i);
1.115 matthew 13755: }
13756:
1.144 matthew 13757: ######################################################
13758: ######################################################
13759:
1.115 matthew 13760: =pod
13761:
1.648 raeburn 13762: =item * &clean_excel_name($name)
1.115 matthew 13763:
13764: Returns a replacement for $name which does not contain any illegal characters.
13765:
13766: =cut
13767:
1.144 matthew 13768: ######################################################
13769: ######################################################
1.115 matthew 13770: sub clean_excel_name {
13771: my ($name) = @_;
13772: $name =~ s/[:\*\?\/\\]//g;
13773: if (length($name) > 31) {
13774: $name = substr($name,0,31);
13775: }
13776: return $name;
1.25 albertel 13777: }
1.84 albertel 13778:
1.85 albertel 13779: =pod
13780:
1.648 raeburn 13781: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13782:
13783: Returns either 1 or undef
13784:
13785: 1 if the part is to be hidden, undef if it is to be shown
13786:
13787: Arguments are:
13788:
13789: $id the id of the part to be checked
13790: $symb, optional the symb of the resource to check
13791: $udom, optional the domain of the user to check for
13792: $uname, optional the username of the user to check for
13793:
13794: =cut
1.84 albertel 13795:
13796: sub check_if_partid_hidden {
13797: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13798: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13799: $symb,$udom,$uname);
1.141 albertel 13800: my $truth=1;
13801: #if the string starts with !, then the list is the list to show not hide
13802: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13803: my @hiddenlist=split(/,/,$hiddenparts);
13804: foreach my $checkid (@hiddenlist) {
1.141 albertel 13805: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13806: }
1.141 albertel 13807: return !$truth;
1.84 albertel 13808: }
1.127 matthew 13809:
1.138 matthew 13810:
13811: ############################################################
13812: ############################################################
13813:
13814: =pod
13815:
1.157 matthew 13816: =back
13817:
1.138 matthew 13818: =head1 cgi-bin script and graphing routines
13819:
1.157 matthew 13820: =over 4
13821:
1.648 raeburn 13822: =item * &get_cgi_id()
1.138 matthew 13823:
13824: Inputs: none
13825:
13826: Returns an id which can be used to pass environment variables
13827: to various cgi-bin scripts. These environment variables will
13828: be removed from the users environment after a given time by
13829: the routine &Apache::lonnet::transfer_profile_to_env.
13830:
13831: =cut
13832:
13833: ############################################################
13834: ############################################################
1.152 albertel 13835: my $uniq=0;
1.136 matthew 13836: sub get_cgi_id {
1.154 albertel 13837: $uniq=($uniq+1)%100000;
1.280 albertel 13838: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13839: }
13840:
1.127 matthew 13841: ############################################################
13842: ############################################################
13843:
13844: =pod
13845:
1.648 raeburn 13846: =item * &DrawBarGraph()
1.127 matthew 13847:
1.138 matthew 13848: Facilitates the plotting of data in a (stacked) bar graph.
13849: Puts plot definition data into the users environment in order for
13850: graph.png to plot it. Returns an <img> tag for the plot.
13851: The bars on the plot are labeled '1','2',...,'n'.
13852:
13853: Inputs:
13854:
13855: =over 4
13856:
13857: =item $Title: string, the title of the plot
13858:
13859: =item $xlabel: string, text describing the X-axis of the plot
13860:
13861: =item $ylabel: string, text describing the Y-axis of the plot
13862:
13863: =item $Max: scalar, the maximum Y value to use in the plot
13864: If $Max is < any data point, the graph will not be rendered.
13865:
1.140 matthew 13866: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13867: they are plotted. If undefined, default values will be used.
13868:
1.178 matthew 13869: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13870:
1.138 matthew 13871: =item @Values: An array of array references. Each array reference holds data
13872: to be plotted in a stacked bar chart.
13873:
1.239 matthew 13874: =item If the final element of @Values is a hash reference the key/value
13875: pairs will be added to the graph definition.
13876:
1.138 matthew 13877: =back
13878:
13879: Returns:
13880:
13881: An <img> tag which references graph.png and the appropriate identifying
13882: information for the plot.
13883:
1.127 matthew 13884: =cut
13885:
13886: ############################################################
13887: ############################################################
1.134 matthew 13888: sub DrawBarGraph {
1.178 matthew 13889: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13890: #
13891: if (! defined($colors)) {
13892: $colors = ['#33ff00',
13893: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13894: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13895: ];
13896: }
1.228 matthew 13897: my $extra_settings = {};
13898: if (ref($Values[-1]) eq 'HASH') {
13899: $extra_settings = pop(@Values);
13900: }
1.127 matthew 13901: #
1.136 matthew 13902: my $identifier = &get_cgi_id();
13903: my $id = 'cgi.'.$identifier;
1.129 matthew 13904: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13905: return '';
13906: }
1.225 matthew 13907: #
13908: my @Labels;
13909: if (defined($labels)) {
13910: @Labels = @$labels;
13911: } else {
13912: for (my $i=0;$i<@{$Values[0]};$i++) {
13913: push (@Labels,$i+1);
13914: }
13915: }
13916: #
1.129 matthew 13917: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13918: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13919: my %ValuesHash;
13920: my $NumSets=1;
13921: foreach my $array (@Values) {
13922: next if (! ref($array));
1.136 matthew 13923: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13924: join(',',@$array);
1.129 matthew 13925: }
1.127 matthew 13926: #
1.136 matthew 13927: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13928: if ($NumBars < 3) {
13929: $width = 120+$NumBars*32;
1.220 matthew 13930: $xskip = 1;
1.225 matthew 13931: $bar_width = 30;
13932: } elsif ($NumBars < 5) {
13933: $width = 120+$NumBars*20;
13934: $xskip = 1;
13935: $bar_width = 20;
1.220 matthew 13936: } elsif ($NumBars < 10) {
1.136 matthew 13937: $width = 120+$NumBars*15;
13938: $xskip = 1;
13939: $bar_width = 15;
13940: } elsif ($NumBars <= 25) {
13941: $width = 120+$NumBars*11;
13942: $xskip = 5;
13943: $bar_width = 8;
13944: } elsif ($NumBars <= 50) {
13945: $width = 120+$NumBars*8;
13946: $xskip = 5;
13947: $bar_width = 4;
13948: } else {
13949: $width = 120+$NumBars*8;
13950: $xskip = 5;
13951: $bar_width = 4;
13952: }
13953: #
1.137 matthew 13954: $Max = 1 if ($Max < 1);
13955: if ( int($Max) < $Max ) {
13956: $Max++;
13957: $Max = int($Max);
13958: }
1.127 matthew 13959: $Title = '' if (! defined($Title));
13960: $xlabel = '' if (! defined($xlabel));
13961: $ylabel = '' if (! defined($ylabel));
1.369 www 13962: $ValuesHash{$id.'.title'} = &escape($Title);
13963: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13964: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13965: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13966: $ValuesHash{$id.'.NumBars'} = $NumBars;
13967: $ValuesHash{$id.'.NumSets'} = $NumSets;
13968: $ValuesHash{$id.'.PlotType'} = 'bar';
13969: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13970: $ValuesHash{$id.'.height'} = $height;
13971: $ValuesHash{$id.'.width'} = $width;
13972: $ValuesHash{$id.'.xskip'} = $xskip;
13973: $ValuesHash{$id.'.bar_width'} = $bar_width;
13974: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13975: #
1.228 matthew 13976: # Deal with other parameters
13977: while (my ($key,$value) = each(%$extra_settings)) {
13978: $ValuesHash{$id.'.'.$key} = $value;
13979: }
13980: #
1.646 raeburn 13981: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13982: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13983: }
13984:
13985: ############################################################
13986: ############################################################
13987:
13988: =pod
13989:
1.648 raeburn 13990: =item * &DrawXYGraph()
1.137 matthew 13991:
1.138 matthew 13992: Facilitates the plotting of data in an XY graph.
13993: Puts plot definition data into the users environment in order for
13994: graph.png to plot it. Returns an <img> tag for the plot.
13995:
13996: Inputs:
13997:
13998: =over 4
13999:
14000: =item $Title: string, the title of the plot
14001:
14002: =item $xlabel: string, text describing the X-axis of the plot
14003:
14004: =item $ylabel: string, text describing the Y-axis of the plot
14005:
14006: =item $Max: scalar, the maximum Y value to use in the plot
14007: If $Max is < any data point, the graph will not be rendered.
14008:
14009: =item $colors: Array ref containing the hex color codes for the data to be
14010: plotted in. If undefined, default values will be used.
14011:
14012: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14013:
14014: =item $Ydata: Array ref containing Array refs.
1.185 www 14015: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14016:
14017: =item %Values: hash indicating or overriding any default values which are
14018: passed to graph.png.
14019: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14020:
14021: =back
14022:
14023: Returns:
14024:
14025: An <img> tag which references graph.png and the appropriate identifying
14026: information for the plot.
14027:
1.137 matthew 14028: =cut
14029:
14030: ############################################################
14031: ############################################################
14032: sub DrawXYGraph {
14033: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14034: #
14035: # Create the identifier for the graph
14036: my $identifier = &get_cgi_id();
14037: my $id = 'cgi.'.$identifier;
14038: #
14039: $Title = '' if (! defined($Title));
14040: $xlabel = '' if (! defined($xlabel));
14041: $ylabel = '' if (! defined($ylabel));
14042: my %ValuesHash =
14043: (
1.369 www 14044: $id.'.title' => &escape($Title),
14045: $id.'.xlabel' => &escape($xlabel),
14046: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14047: $id.'.y_max_value'=> $Max,
14048: $id.'.labels' => join(',',@$Xlabels),
14049: $id.'.PlotType' => 'XY',
14050: );
14051: #
14052: if (defined($colors) && ref($colors) eq 'ARRAY') {
14053: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14054: }
14055: #
14056: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14057: return '';
14058: }
14059: my $NumSets=1;
1.138 matthew 14060: foreach my $array (@{$Ydata}){
1.137 matthew 14061: next if (! ref($array));
14062: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14063: }
1.138 matthew 14064: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14065: #
14066: # Deal with other parameters
14067: while (my ($key,$value) = each(%Values)) {
14068: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14069: }
14070: #
1.646 raeburn 14071: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14072: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14073: }
14074:
14075: ############################################################
14076: ############################################################
14077:
14078: =pod
14079:
1.648 raeburn 14080: =item * &DrawXYYGraph()
1.138 matthew 14081:
14082: Facilitates the plotting of data in an XY graph with two Y axes.
14083: Puts plot definition data into the users environment in order for
14084: graph.png to plot it. Returns an <img> tag for the plot.
14085:
14086: Inputs:
14087:
14088: =over 4
14089:
14090: =item $Title: string, the title of the plot
14091:
14092: =item $xlabel: string, text describing the X-axis of the plot
14093:
14094: =item $ylabel: string, text describing the Y-axis of the plot
14095:
14096: =item $colors: Array ref containing the hex color codes for the data to be
14097: plotted in. If undefined, default values will be used.
14098:
14099: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14100:
14101: =item $Ydata1: The first data set
14102:
14103: =item $Min1: The minimum value of the left Y-axis
14104:
14105: =item $Max1: The maximum value of the left Y-axis
14106:
14107: =item $Ydata2: The second data set
14108:
14109: =item $Min2: The minimum value of the right Y-axis
14110:
14111: =item $Max2: The maximum value of the left Y-axis
14112:
14113: =item %Values: hash indicating or overriding any default values which are
14114: passed to graph.png.
14115: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14116:
14117: =back
14118:
14119: Returns:
14120:
14121: An <img> tag which references graph.png and the appropriate identifying
14122: information for the plot.
1.136 matthew 14123:
14124: =cut
14125:
14126: ############################################################
14127: ############################################################
1.137 matthew 14128: sub DrawXYYGraph {
14129: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14130: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14131: #
14132: # Create the identifier for the graph
14133: my $identifier = &get_cgi_id();
14134: my $id = 'cgi.'.$identifier;
14135: #
14136: $Title = '' if (! defined($Title));
14137: $xlabel = '' if (! defined($xlabel));
14138: $ylabel = '' if (! defined($ylabel));
14139: my %ValuesHash =
14140: (
1.369 www 14141: $id.'.title' => &escape($Title),
14142: $id.'.xlabel' => &escape($xlabel),
14143: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14144: $id.'.labels' => join(',',@$Xlabels),
14145: $id.'.PlotType' => 'XY',
14146: $id.'.NumSets' => 2,
1.137 matthew 14147: $id.'.two_axes' => 1,
14148: $id.'.y1_max_value' => $Max1,
14149: $id.'.y1_min_value' => $Min1,
14150: $id.'.y2_max_value' => $Max2,
14151: $id.'.y2_min_value' => $Min2,
1.136 matthew 14152: );
14153: #
1.137 matthew 14154: if (defined($colors) && ref($colors) eq 'ARRAY') {
14155: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14156: }
14157: #
14158: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14159: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14160: return '';
14161: }
14162: my $NumSets=1;
1.137 matthew 14163: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14164: next if (! ref($array));
14165: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14166: }
14167: #
14168: # Deal with other parameters
14169: while (my ($key,$value) = each(%Values)) {
14170: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14171: }
14172: #
1.646 raeburn 14173: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14174: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14175: }
14176:
14177: ############################################################
14178: ############################################################
14179:
14180: =pod
14181:
1.157 matthew 14182: =back
14183:
1.139 matthew 14184: =head1 Statistics helper routines?
14185:
14186: Bad place for them but what the hell.
14187:
1.157 matthew 14188: =over 4
14189:
1.648 raeburn 14190: =item * &chartlink()
1.139 matthew 14191:
14192: Returns a link to the chart for a specific student.
14193:
14194: Inputs:
14195:
14196: =over 4
14197:
14198: =item $linktext: The text of the link
14199:
14200: =item $sname: The students username
14201:
14202: =item $sdomain: The students domain
14203:
14204: =back
14205:
1.157 matthew 14206: =back
14207:
1.139 matthew 14208: =cut
14209:
14210: ############################################################
14211: ############################################################
14212: sub chartlink {
14213: my ($linktext, $sname, $sdomain) = @_;
14214: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14215: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14216: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14217: '">'.$linktext.'</a>';
1.153 matthew 14218: }
14219:
14220: #######################################################
14221: #######################################################
14222:
14223: =pod
14224:
14225: =head1 Course Environment Routines
1.157 matthew 14226:
14227: =over 4
1.153 matthew 14228:
1.648 raeburn 14229: =item * &restore_course_settings()
1.153 matthew 14230:
1.648 raeburn 14231: =item * &store_course_settings()
1.153 matthew 14232:
14233: Restores/Store indicated form parameters from the course environment.
14234: Will not overwrite existing values of the form parameters.
14235:
14236: Inputs:
14237: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14238:
14239: a hash ref describing the data to be stored. For example:
14240:
14241: %Save_Parameters = ('Status' => 'scalar',
14242: 'chartoutputmode' => 'scalar',
14243: 'chartoutputdata' => 'scalar',
14244: 'Section' => 'array',
1.373 raeburn 14245: 'Group' => 'array',
1.153 matthew 14246: 'StudentData' => 'array',
14247: 'Maps' => 'array');
14248:
14249: Returns: both routines return nothing
14250:
1.631 raeburn 14251: =back
14252:
1.153 matthew 14253: =cut
14254:
14255: #######################################################
14256: #######################################################
14257: sub store_course_settings {
1.496 albertel 14258: return &store_settings($env{'request.course.id'},@_);
14259: }
14260:
14261: sub store_settings {
1.153 matthew 14262: # save to the environment
14263: # appenv the same items, just to be safe
1.300 albertel 14264: my $udom = $env{'user.domain'};
14265: my $uname = $env{'user.name'};
1.496 albertel 14266: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14267: my %SaveHash;
14268: my %AppHash;
14269: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14270: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14271: my $envname = 'environment.'.$basename;
1.258 albertel 14272: if (exists($env{'form.'.$setting})) {
1.153 matthew 14273: # Save this value away
14274: if ($type eq 'scalar' &&
1.258 albertel 14275: (! exists($env{$envname}) ||
14276: $env{$envname} ne $env{'form.'.$setting})) {
14277: $SaveHash{$basename} = $env{'form.'.$setting};
14278: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14279: } elsif ($type eq 'array') {
14280: my $stored_form;
1.258 albertel 14281: if (ref($env{'form.'.$setting})) {
1.153 matthew 14282: $stored_form = join(',',
14283: map {
1.369 www 14284: &escape($_);
1.258 albertel 14285: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14286: } else {
14287: $stored_form =
1.369 www 14288: &escape($env{'form.'.$setting});
1.153 matthew 14289: }
14290: # Determine if the array contents are the same.
1.258 albertel 14291: if ($stored_form ne $env{$envname}) {
1.153 matthew 14292: $SaveHash{$basename} = $stored_form;
14293: $AppHash{$envname} = $stored_form;
14294: }
14295: }
14296: }
14297: }
14298: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14299: $udom,$uname);
1.153 matthew 14300: if ($put_result !~ /^(ok|delayed)/) {
14301: &Apache::lonnet::logthis('unable to save form parameters, '.
14302: 'got error:'.$put_result);
14303: }
14304: # Make sure these settings stick around in this session, too
1.646 raeburn 14305: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14306: return;
14307: }
14308:
14309: sub restore_course_settings {
1.499 albertel 14310: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14311: }
14312:
14313: sub restore_settings {
14314: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14315: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14316: next if (exists($env{'form.'.$setting}));
1.496 albertel 14317: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14318: '.'.$setting;
1.258 albertel 14319: if (exists($env{$envname})) {
1.153 matthew 14320: if ($type eq 'scalar') {
1.258 albertel 14321: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14322: } elsif ($type eq 'array') {
1.258 albertel 14323: $env{'form.'.$setting} = [
1.153 matthew 14324: map {
1.369 www 14325: &unescape($_);
1.258 albertel 14326: } split(',',$env{$envname})
1.153 matthew 14327: ];
14328: }
14329: }
14330: }
1.127 matthew 14331: }
14332:
1.618 raeburn 14333: #######################################################
14334: #######################################################
14335:
14336: =pod
14337:
14338: =head1 Domain E-mail Routines
14339:
14340: =over 4
14341:
1.648 raeburn 14342: =item * &build_recipient_list()
1.618 raeburn 14343:
1.1144 raeburn 14344: Build recipient lists for following types of e-mail:
1.766 raeburn 14345: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14346: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14347: module change checking, student/employee ID conflict checks, as
14348: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14349: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14350:
14351: Inputs:
1.619 raeburn 14352: defmail (scalar - email address of default recipient),
1.1144 raeburn 14353: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14354: requestsmail, updatesmail, or idconflictsmail).
14355:
1.619 raeburn 14356: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14357:
1.619 raeburn 14358: origmail (scalar - email address of recipient from loncapa.conf,
14359: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14360:
1.655 raeburn 14361: Returns: comma separated list of addresses to which to send e-mail.
14362:
14363: =back
1.618 raeburn 14364:
14365: =cut
14366:
14367: ############################################################
14368: ############################################################
14369: sub build_recipient_list {
1.619 raeburn 14370: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 14371: my @recipients;
14372: my $otheremails;
14373: my %domconfig =
14374: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
14375: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14376: if (exists($domconfig{'contacts'}{$mailing})) {
14377: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14378: my @contacts = ('adminemail','supportemail');
14379: foreach my $item (@contacts) {
14380: if ($domconfig{'contacts'}{$mailing}{$item}) {
14381: my $addr = $domconfig{'contacts'}{$item};
14382: if (!grep(/^\Q$addr\E$/,@recipients)) {
14383: push(@recipients,$addr);
14384: }
1.619 raeburn 14385: }
1.766 raeburn 14386: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 14387: }
14388: }
1.766 raeburn 14389: } elsif ($origmail ne '') {
14390: push(@recipients,$origmail);
1.618 raeburn 14391: }
1.619 raeburn 14392: } elsif ($origmail ne '') {
14393: push(@recipients,$origmail);
1.618 raeburn 14394: }
1.688 raeburn 14395: if (defined($defmail)) {
14396: if ($defmail ne '') {
14397: push(@recipients,$defmail);
14398: }
1.618 raeburn 14399: }
14400: if ($otheremails) {
1.619 raeburn 14401: my @others;
14402: if ($otheremails =~ /,/) {
14403: @others = split(/,/,$otheremails);
1.618 raeburn 14404: } else {
1.619 raeburn 14405: push(@others,$otheremails);
14406: }
14407: foreach my $addr (@others) {
14408: if (!grep(/^\Q$addr\E$/,@recipients)) {
14409: push(@recipients,$addr);
14410: }
1.618 raeburn 14411: }
14412: }
1.619 raeburn 14413: my $recipientlist = join(',',@recipients);
1.618 raeburn 14414: return $recipientlist;
14415: }
14416:
1.127 matthew 14417: ############################################################
14418: ############################################################
1.154 albertel 14419:
1.655 raeburn 14420: =pod
14421:
1.1224 musolffc 14422: =over 4
14423:
1.1223 musolffc 14424: =item * &mime_email()
14425:
14426: Sends an email with a possible attachment
14427:
14428: Inputs:
14429:
14430: =over 4
14431:
14432: from - Sender's email address
14433:
14434: to - Email address of recipient
14435:
14436: subject - Subject of email
14437:
14438: body - Body of email
14439:
14440: cc_string - Carbon copy email address
14441:
14442: bcc - Blind carbon copy email address
14443:
14444: type - File type of attachment
14445:
14446: attachment_path - Path of file to be attached
14447:
14448: file_name - Name of file to be attached
14449:
14450: attachment_text - The body of an attachment of type "TEXT"
14451:
14452: =back
14453:
14454: =back
14455:
14456: =cut
14457:
14458: ############################################################
14459: ############################################################
14460:
14461: sub mime_email {
14462: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
14463: $file_name, $attachment_text) = @_;
14464: my $msg = MIME::Lite->new(
14465: From => $from,
14466: To => $to,
14467: Subject => $subject,
14468: Type =>'TEXT',
14469: Data => $body,
14470: );
14471: if ($cc_string ne '') {
14472: $msg->add("Cc" => $cc_string);
14473: }
14474: if ($bcc ne '') {
14475: $msg->add("Bcc" => $bcc);
14476: }
14477: $msg->attr("content-type" => "text/plain");
14478: $msg->attr("content-type.charset" => "UTF-8");
14479: # Attach file if given
14480: if ($attachment_path) {
14481: unless ($file_name) {
14482: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
14483: }
14484: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
14485: $msg->attach(Type => $type,
14486: Path => $attachment_path,
14487: Filename => $file_name
14488: );
14489: # Otherwise attach text if given
14490: } elsif ($attachment_text) {
14491: $msg->attach(Type => 'TEXT',
14492: Data => $attachment_text);
14493: }
14494: # Send it
14495: $msg->send('sendmail');
14496: }
14497:
14498: ############################################################
14499: ############################################################
14500:
14501: =pod
14502:
1.655 raeburn 14503: =head1 Course Catalog Routines
14504:
14505: =over 4
14506:
14507: =item * &gather_categories()
14508:
14509: Converts category definitions - keys of categories hash stored in
14510: coursecategories in configuration.db on the primary library server in a
14511: domain - to an array. Also generates javascript and idx hash used to
14512: generate Domain Coordinator interface for editing Course Categories.
14513:
14514: Inputs:
1.663 raeburn 14515:
1.655 raeburn 14516: categories (reference to hash of category definitions).
1.663 raeburn 14517:
1.655 raeburn 14518: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14519: categories and subcategories).
1.663 raeburn 14520:
1.655 raeburn 14521: idx (reference to hash of counters used in Domain Coordinator interface for
14522: editing Course Categories).
1.663 raeburn 14523:
1.655 raeburn 14524: jsarray (reference to array of categories used to create Javascript arrays for
14525: Domain Coordinator interface for editing Course Categories).
14526:
14527: Returns: nothing
14528:
14529: Side effects: populates cats, idx and jsarray.
14530:
14531: =cut
14532:
14533: sub gather_categories {
14534: my ($categories,$cats,$idx,$jsarray) = @_;
14535: my %counters;
14536: my $num = 0;
14537: foreach my $item (keys(%{$categories})) {
14538: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14539: if ($container eq '' && $depth == 0) {
14540: $cats->[$depth][$categories->{$item}] = $cat;
14541: } else {
14542: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14543: }
14544: my ($escitem,$tail) = split(/:/,$item,2);
14545: if ($counters{$tail} eq '') {
14546: $counters{$tail} = $num;
14547: $num ++;
14548: }
14549: if (ref($idx) eq 'HASH') {
14550: $idx->{$item} = $counters{$tail};
14551: }
14552: if (ref($jsarray) eq 'ARRAY') {
14553: push(@{$jsarray->[$counters{$tail}]},$item);
14554: }
14555: }
14556: return;
14557: }
14558:
14559: =pod
14560:
14561: =item * &extract_categories()
14562:
14563: Used to generate breadcrumb trails for course categories.
14564:
14565: Inputs:
1.663 raeburn 14566:
1.655 raeburn 14567: categories (reference to hash of category definitions).
1.663 raeburn 14568:
1.655 raeburn 14569: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14570: categories and subcategories).
1.663 raeburn 14571:
1.655 raeburn 14572: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14573:
1.655 raeburn 14574: allitems (reference to hash - key is category key
14575: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14576:
1.655 raeburn 14577: idx (reference to hash of counters used in Domain Coordinator interface for
14578: editing Course Categories).
1.663 raeburn 14579:
1.655 raeburn 14580: jsarray (reference to array of categories used to create Javascript arrays for
14581: Domain Coordinator interface for editing Course Categories).
14582:
1.665 raeburn 14583: subcats (reference to hash of arrays containing all subcategories within each
14584: category, -recursive)
14585:
1.655 raeburn 14586: Returns: nothing
14587:
14588: Side effects: populates trails and allitems hash references.
14589:
14590: =cut
14591:
14592: sub extract_categories {
1.665 raeburn 14593: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14594: if (ref($categories) eq 'HASH') {
14595: &gather_categories($categories,$cats,$idx,$jsarray);
14596: if (ref($cats->[0]) eq 'ARRAY') {
14597: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14598: my $name = $cats->[0][$i];
14599: my $item = &escape($name).'::0';
14600: my $trailstr;
14601: if ($name eq 'instcode') {
14602: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14603: } elsif ($name eq 'communities') {
14604: $trailstr = &mt('Communities');
1.1239 raeburn 14605: } elsif ($name eq 'placement') {
14606: $trailstr = &mt('Placement Tests');
1.655 raeburn 14607: } else {
14608: $trailstr = $name;
14609: }
14610: if ($allitems->{$item} eq '') {
14611: push(@{$trails},$trailstr);
14612: $allitems->{$item} = scalar(@{$trails})-1;
14613: }
14614: my @parents = ($name);
14615: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14616: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14617: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14618: if (ref($subcats) eq 'HASH') {
14619: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14620: }
14621: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14622: }
14623: } else {
14624: if (ref($subcats) eq 'HASH') {
14625: $subcats->{$item} = [];
1.655 raeburn 14626: }
14627: }
14628: }
14629: }
14630: }
14631: return;
14632: }
14633:
14634: =pod
14635:
1.1162 raeburn 14636: =item * &recurse_categories()
1.655 raeburn 14637:
14638: Recursively used to generate breadcrumb trails for course categories.
14639:
14640: Inputs:
1.663 raeburn 14641:
1.655 raeburn 14642: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14643: categories and subcategories).
1.663 raeburn 14644:
1.655 raeburn 14645: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14646:
14647: category (current course category, for which breadcrumb trail is being generated).
14648:
14649: trails (reference to array of breadcrumb trails for each category).
14650:
1.655 raeburn 14651: allitems (reference to hash - key is category key
14652: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14653:
1.655 raeburn 14654: parents (array containing containers directories for current category,
14655: back to top level).
14656:
14657: Returns: nothing
14658:
14659: Side effects: populates trails and allitems hash references
14660:
14661: =cut
14662:
14663: sub recurse_categories {
1.665 raeburn 14664: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14665: my $shallower = $depth - 1;
14666: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14667: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14668: my $name = $cats->[$depth]{$category}[$k];
14669: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14670: my $trailstr = join(' -> ',(@{$parents},$category));
14671: if ($allitems->{$item} eq '') {
14672: push(@{$trails},$trailstr);
14673: $allitems->{$item} = scalar(@{$trails})-1;
14674: }
14675: my $deeper = $depth+1;
14676: push(@{$parents},$category);
1.665 raeburn 14677: if (ref($subcats) eq 'HASH') {
14678: my $subcat = &escape($name).':'.$category.':'.$depth;
14679: for (my $j=@{$parents}; $j>=0; $j--) {
14680: my $higher;
14681: if ($j > 0) {
14682: $higher = &escape($parents->[$j]).':'.
14683: &escape($parents->[$j-1]).':'.$j;
14684: } else {
14685: $higher = &escape($parents->[$j]).'::'.$j;
14686: }
14687: push(@{$subcats->{$higher}},$subcat);
14688: }
14689: }
14690: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14691: $subcats);
1.655 raeburn 14692: pop(@{$parents});
14693: }
14694: } else {
14695: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14696: my $trailstr = join(' -> ',(@{$parents},$category));
14697: if ($allitems->{$item} eq '') {
14698: push(@{$trails},$trailstr);
14699: $allitems->{$item} = scalar(@{$trails})-1;
14700: }
14701: }
14702: return;
14703: }
14704:
1.663 raeburn 14705: =pod
14706:
1.1162 raeburn 14707: =item * &assign_categories_table()
1.663 raeburn 14708:
14709: Create a datatable for display of hierarchical categories in a domain,
14710: with checkboxes to allow a course to be categorized.
14711:
14712: Inputs:
14713:
14714: cathash - reference to hash of categories defined for the domain (from
14715: configuration.db)
14716:
14717: currcat - scalar with an & separated list of categories assigned to a course.
14718:
1.919 raeburn 14719: type - scalar contains course type (Course or Community).
14720:
1.663 raeburn 14721: Returns: $output (markup to be displayed)
14722:
14723: =cut
14724:
14725: sub assign_categories_table {
1.919 raeburn 14726: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 14727: my $output;
14728: if (ref($cathash) eq 'HASH') {
14729: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
14730: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
14731: $maxdepth = scalar(@cats);
14732: if (@cats > 0) {
14733: my $itemcount = 0;
14734: if (ref($cats[0]) eq 'ARRAY') {
14735: my @currcategories;
14736: if ($currcat ne '') {
14737: @currcategories = split('&',$currcat);
14738: }
1.919 raeburn 14739: my $table;
1.663 raeburn 14740: for (my $i=0; $i<@{$cats[0]}; $i++) {
14741: my $parent = $cats[0][$i];
1.919 raeburn 14742: next if ($parent eq 'instcode');
14743: if ($type eq 'Community') {
14744: next unless ($parent eq 'communities');
1.1239 raeburn 14745: } elsif ($type eq 'Placement') {
14746: next unless ($parent eq 'placement');
1.919 raeburn 14747: } else {
1.1239 raeburn 14748: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 14749: }
1.663 raeburn 14750: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14751: my $item = &escape($parent).'::0';
14752: my $checked = '';
14753: if (@currcategories > 0) {
14754: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14755: $checked = ' checked="checked"';
1.663 raeburn 14756: }
14757: }
1.919 raeburn 14758: my $parent_title = $parent;
14759: if ($parent eq 'communities') {
14760: $parent_title = &mt('Communities');
1.1239 raeburn 14761: } elsif ($parent eq 'placement') {
14762: $parent_title = &mt('Placement Tests');
1.919 raeburn 14763: }
14764: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14765: '<input type="checkbox" name="usecategory" value="'.
14766: $item.'"'.$checked.' />'.$parent_title.'</span>'.
14767: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14768: my $depth = 1;
14769: push(@path,$parent);
1.919 raeburn 14770: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 14771: pop(@path);
1.919 raeburn 14772: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14773: $itemcount ++;
14774: }
1.919 raeburn 14775: if ($itemcount) {
14776: $output = &Apache::loncommon::start_data_table().
14777: $table.
14778: &Apache::loncommon::end_data_table();
14779: }
1.663 raeburn 14780: }
14781: }
14782: }
14783: return $output;
14784: }
14785:
14786: =pod
14787:
1.1162 raeburn 14788: =item * &assign_category_rows()
1.663 raeburn 14789:
14790: Create a datatable row for display of nested categories in a domain,
14791: with checkboxes to allow a course to be categorized,called recursively.
14792:
14793: Inputs:
14794:
14795: itemcount - track row number for alternating colors
14796:
14797: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14798: categories and subcategories.
14799:
14800: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14801:
14802: parent - parent of current category item
14803:
14804: path - Array containing all categories back up through the hierarchy from the
14805: current category to the top level.
14806:
14807: currcategories - reference to array of current categories assigned to the course
14808:
14809: Returns: $output (markup to be displayed).
14810:
14811: =cut
14812:
14813: sub assign_category_rows {
14814: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
14815: my ($text,$name,$item,$chgstr);
14816: if (ref($cats) eq 'ARRAY') {
14817: my $maxdepth = scalar(@{$cats});
14818: if (ref($cats->[$depth]) eq 'HASH') {
14819: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14820: my $numchildren = @{$cats->[$depth]{$parent}};
14821: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 14822: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14823: for (my $j=0; $j<$numchildren; $j++) {
14824: $name = $cats->[$depth]{$parent}[$j];
14825: $item = &escape($name).':'.&escape($parent).':'.$depth;
14826: my $deeper = $depth+1;
14827: my $checked = '';
14828: if (ref($currcategories) eq 'ARRAY') {
14829: if (@{$currcategories} > 0) {
14830: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14831: $checked = ' checked="checked"';
1.663 raeburn 14832: }
14833: }
14834: }
1.664 raeburn 14835: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14836: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 14837: $item.'"'.$checked.' />'.$name.'</label></span>'.
14838: '<input type="hidden" name="catname" value="'.$name.'" />'.
14839: '</td><td>';
1.663 raeburn 14840: if (ref($path) eq 'ARRAY') {
14841: push(@{$path},$name);
14842: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
14843: pop(@{$path});
14844: }
14845: $text .= '</td></tr>';
14846: }
14847: $text .= '</table></td>';
14848: }
14849: }
14850: }
14851: return $text;
14852: }
14853:
1.1181 raeburn 14854: =pod
14855:
14856: =back
14857:
14858: =cut
14859:
1.655 raeburn 14860: ############################################################
14861: ############################################################
14862:
14863:
1.443 albertel 14864: sub commit_customrole {
1.664 raeburn 14865: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14866: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14867: ($start?', '.&mt('starting').' '.localtime($start):'').
14868: ($end?', ending '.localtime($end):'').': <b>'.
14869: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14870: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14871: '</b><br />';
14872: return $output;
14873: }
14874:
14875: sub commit_standardrole {
1.1116 raeburn 14876: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14877: my ($output,$logmsg,$linefeed);
14878: if ($context eq 'auto') {
14879: $linefeed = "\n";
14880: } else {
14881: $linefeed = "<br />\n";
14882: }
1.443 albertel 14883: if ($three eq 'st') {
1.541 raeburn 14884: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 14885: $one,$two,$sec,$context,$credits);
1.541 raeburn 14886: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14887: ($result eq 'unknown_course') || ($result eq 'refused')) {
14888: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14889: } else {
1.541 raeburn 14890: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14891: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14892: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14893: if ($context eq 'auto') {
14894: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14895: } else {
14896: $output .= '<b>'.$result.'</b>'.$linefeed.
14897: &mt('Add to classlist').': <b>ok</b>';
14898: }
14899: $output .= $linefeed;
1.443 albertel 14900: }
14901: } else {
14902: $output = &mt('Assigning').' '.$three.' in '.$url.
14903: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14904: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14905: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14906: if ($context eq 'auto') {
14907: $output .= $result.$linefeed;
14908: } else {
14909: $output .= '<b>'.$result.'</b>'.$linefeed;
14910: }
1.443 albertel 14911: }
14912: return $output;
14913: }
14914:
14915: sub commit_studentrole {
1.1116 raeburn 14916: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14917: $credits) = @_;
1.626 raeburn 14918: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14919: if ($context eq 'auto') {
14920: $linefeed = "\n";
14921: } else {
14922: $linefeed = '<br />'."\n";
14923: }
1.443 albertel 14924: if (defined($one) && defined($two)) {
14925: my $cid=$one.'_'.$two;
14926: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14927: my $secchange = 0;
14928: my $expire_role_result;
14929: my $modify_section_result;
1.628 raeburn 14930: if ($oldsec ne '-1') {
14931: if ($oldsec ne $sec) {
1.443 albertel 14932: $secchange = 1;
1.628 raeburn 14933: my $now = time;
1.443 albertel 14934: my $uurl='/'.$cid;
14935: $uurl=~s/\_/\//g;
14936: if ($oldsec) {
14937: $uurl.='/'.$oldsec;
14938: }
1.626 raeburn 14939: $oldsecurl = $uurl;
1.628 raeburn 14940: $expire_role_result =
1.652 raeburn 14941: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14942: if ($env{'request.course.sec'} ne '') {
14943: if ($expire_role_result eq 'refused') {
14944: my @roles = ('st');
14945: my @statuses = ('previous');
14946: my @roledoms = ($one);
14947: my $withsec = 1;
14948: my %roleshash =
14949: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14950: \@statuses,\@roles,\@roledoms,$withsec);
14951: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14952: my ($oldstart,$oldend) =
14953: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14954: if ($oldend > 0 && $oldend <= $now) {
14955: $expire_role_result = 'ok';
14956: }
14957: }
14958: }
14959: }
1.443 albertel 14960: $result = $expire_role_result;
14961: }
14962: }
14963: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 14964: $modify_section_result =
14965: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14966: undef,undef,undef,$sec,
14967: $end,$start,'','',$cid,
14968: '',$context,$credits);
1.443 albertel 14969: if ($modify_section_result =~ /^ok/) {
14970: if ($secchange == 1) {
1.628 raeburn 14971: if ($sec eq '') {
14972: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14973: } else {
14974: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14975: }
1.443 albertel 14976: } elsif ($oldsec eq '-1') {
1.628 raeburn 14977: if ($sec eq '') {
14978: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14979: } else {
14980: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14981: }
1.443 albertel 14982: } else {
1.628 raeburn 14983: if ($sec eq '') {
14984: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14985: } else {
14986: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14987: }
1.443 albertel 14988: }
14989: } else {
1.1115 raeburn 14990: if ($secchange) {
1.628 raeburn 14991: $$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;
14992: } else {
14993: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14994: }
1.443 albertel 14995: }
14996: $result = $modify_section_result;
14997: } elsif ($secchange == 1) {
1.628 raeburn 14998: if ($oldsec eq '') {
1.1103 raeburn 14999: $$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 15000: } else {
15001: $$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;
15002: }
1.626 raeburn 15003: if ($expire_role_result eq 'refused') {
15004: my $newsecurl = '/'.$cid;
15005: $newsecurl =~ s/\_/\//g;
15006: if ($sec ne '') {
15007: $newsecurl.='/'.$sec;
15008: }
15009: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15010: if ($sec eq '') {
15011: $$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;
15012: } else {
15013: $$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;
15014: }
15015: }
15016: }
1.443 albertel 15017: }
15018: } else {
1.626 raeburn 15019: $$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 15020: $result = "error: incomplete course id\n";
15021: }
15022: return $result;
15023: }
15024:
1.1108 raeburn 15025: sub show_role_extent {
15026: my ($scope,$context,$role) = @_;
15027: $scope =~ s{^/}{};
15028: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15029: push(@courseroles,'co');
15030: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15031: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15032: $scope =~ s{/}{_};
15033: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15034: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15035: my ($audom,$auname) = split(/\//,$scope);
15036: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15037: &Apache::loncommon::plainname($auname,$audom).'</span>');
15038: } else {
15039: $scope =~ s{/$}{};
15040: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15041: &Apache::lonnet::domain($scope,'description').'</span>');
15042: }
15043: }
15044:
1.443 albertel 15045: ############################################################
15046: ############################################################
15047:
1.566 albertel 15048: sub check_clone {
1.578 raeburn 15049: my ($args,$linefeed) = @_;
1.566 albertel 15050: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15051: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15052: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15053: my $clonemsg;
15054: my $can_clone = 0;
1.944 raeburn 15055: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15056: if ($lctype ne 'community') {
15057: $lctype = 'course';
15058: }
1.566 albertel 15059: if ($clonehome eq 'no_host') {
1.944 raeburn 15060: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15061: $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'});
15062: } else {
15063: $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'});
15064: }
1.566 albertel 15065: } else {
15066: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15067: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15068: if ($clonedesc{'type'} ne 'Community') {
15069: $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'});
15070: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15071: }
15072: }
1.882 raeburn 15073: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
15074: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15075: $can_clone = 1;
15076: } else {
1.1221 raeburn 15077: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15078: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15079: if ($clonehash{'cloners'} eq '') {
15080: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15081: if ($domdefs{'canclone'}) {
15082: unless ($domdefs{'canclone'} eq 'none') {
15083: if ($domdefs{'canclone'} eq 'domain') {
15084: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15085: $can_clone = 1;
15086: }
15087: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15088: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15089: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15090: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15091: $can_clone = 1;
15092: }
15093: }
15094: }
15095: }
1.578 raeburn 15096: } else {
1.1221 raeburn 15097: my @cloners = split(/,/,$clonehash{'cloners'});
15098: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15099: $can_clone = 1;
1.1221 raeburn 15100: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15101: $can_clone = 1;
1.1225 raeburn 15102: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15103: $can_clone = 1;
1.1221 raeburn 15104: }
15105: unless ($can_clone) {
1.1225 raeburn 15106: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15107: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15108: my (%gotdomdefaults,%gotcodedefaults);
15109: foreach my $cloner (@cloners) {
15110: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15111: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15112: my (%codedefaults,@code_order);
15113: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15114: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15115: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15116: }
15117: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15118: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15119: }
15120: } else {
15121: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15122: \%codedefaults,
15123: \@code_order);
15124: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15125: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15126: }
15127: if (@code_order > 0) {
15128: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15129: $cloner,$clonehash{'internal.coursecode'},
15130: $args->{'crscode'})) {
15131: $can_clone = 1;
15132: last;
15133: }
15134: }
15135: }
15136: }
15137: }
1.1225 raeburn 15138: }
15139: }
15140: unless ($can_clone) {
15141: my $ccrole = 'cc';
15142: if ($args->{'crstype'} eq 'Community') {
15143: $ccrole = 'co';
15144: }
15145: my %roleshash =
15146: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15147: $args->{'ccdomain'},
15148: 'userroles',['active'],[$ccrole],
15149: [$args->{'clonedomain'}]);
15150: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15151: $can_clone = 1;
15152: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15153: $args->{'ccuname'},$args->{'ccdomain'})) {
15154: $can_clone = 1;
1.1221 raeburn 15155: }
15156: }
15157: unless ($can_clone) {
15158: if ($args->{'crstype'} eq 'Community') {
15159: $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 15160: } else {
1.1221 raeburn 15161: $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'});
15162: }
1.566 albertel 15163: }
1.578 raeburn 15164: }
1.566 albertel 15165: }
15166: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15167: }
15168:
1.444 albertel 15169: sub construct_course {
1.1166 raeburn 15170: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 15171: my $outcome;
1.541 raeburn 15172: my $linefeed = '<br />'."\n";
15173: if ($context eq 'auto') {
15174: $linefeed = "\n";
15175: }
1.566 albertel 15176:
15177: #
15178: # Are we cloning?
15179: #
15180: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15181: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15182: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15183: if ($context ne 'auto') {
1.578 raeburn 15184: if ($clonemsg ne '') {
15185: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15186: }
1.566 albertel 15187: }
15188: $outcome .= $clonemsg.$linefeed;
15189:
15190: if (!$can_clone) {
15191: return (0,$outcome);
15192: }
15193: }
15194:
1.444 albertel 15195: #
15196: # Open course
15197: #
1.1239 raeburn 15198: my $showncrstype;
15199: if ($args->{'crstype'} eq 'Placement') {
15200: $showncrstype = 'placement test';
15201: } else {
15202: $showncrstype = lc($args->{'crstype'});
15203: }
1.444 albertel 15204: my %cenv=();
15205: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15206: $args->{'cdescr'},
15207: $args->{'curl'},
15208: $args->{'course_home'},
15209: $args->{'nonstandard'},
15210: $args->{'crscode'},
15211: $args->{'ccuname'}.':'.
15212: $args->{'ccdomain'},
1.882 raeburn 15213: $args->{'crstype'},
1.885 raeburn 15214: $cnum,$context,$category);
1.444 albertel 15215:
15216: # Note: The testing routines depend on this being output; see
15217: # Utils::Course. This needs to at least be output as a comment
15218: # if anyone ever decides to not show this, and Utils::Course::new
15219: # will need to be suitably modified.
1.1239 raeburn 15220: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15221: if ($$courseid =~ /^error:/) {
15222: return (0,$outcome);
15223: }
15224:
1.444 albertel 15225: #
15226: # Check if created correctly
15227: #
1.479 albertel 15228: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15229: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15230: if ($crsuhome eq 'no_host') {
15231: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15232: return (0,$outcome);
15233: }
1.541 raeburn 15234: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15235:
1.444 albertel 15236: #
1.566 albertel 15237: # Do the cloning
15238: #
15239: if ($can_clone && $cloneid) {
1.1239 raeburn 15240: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 15241: if ($context ne 'auto') {
15242: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15243: }
15244: $outcome .= $clonemsg.$linefeed;
15245: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15246: # Copy all files
1.637 www 15247: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15248: # Restore URL
1.566 albertel 15249: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15250: # Restore title
1.566 albertel 15251: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15252: # Restore creation date, creator and creation context.
15253: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15254: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15255: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15256: # Mark as cloned
1.566 albertel 15257: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15258: # Need to clone grading mode
15259: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15260: $cenv{'grading'}=$newenv{'grading'};
15261: # Do not clone these environment entries
15262: &Apache::lonnet::del('environment',
15263: ['default_enrollment_start_date',
15264: 'default_enrollment_end_date',
15265: 'question.email',
15266: 'policy.email',
15267: 'comment.email',
15268: 'pch.users.denied',
1.725 raeburn 15269: 'plc.users.denied',
15270: 'hidefromcat',
1.1121 raeburn 15271: 'checkforpriv',
1.1166 raeburn 15272: 'categories',
15273: 'internal.uniquecode'],
1.638 www 15274: $$crsudom,$$crsunum);
1.1170 raeburn 15275: if ($args->{'textbook'}) {
15276: $cenv{'internal.textbook'} = $args->{'textbook'};
15277: }
1.444 albertel 15278: }
1.566 albertel 15279:
1.444 albertel 15280: #
15281: # Set environment (will override cloned, if existing)
15282: #
15283: my @sections = ();
15284: my @xlists = ();
15285: if ($args->{'crstype'}) {
15286: $cenv{'type'}=$args->{'crstype'};
15287: }
15288: if ($args->{'crsid'}) {
15289: $cenv{'courseid'}=$args->{'crsid'};
15290: }
15291: if ($args->{'crscode'}) {
15292: $cenv{'internal.coursecode'}=$args->{'crscode'};
15293: }
15294: if ($args->{'crsquota'} ne '') {
15295: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15296: } else {
15297: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15298: }
15299: if ($args->{'ccuname'}) {
15300: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15301: ':'.$args->{'ccdomain'};
15302: } else {
15303: $cenv{'internal.courseowner'} = $args->{'curruser'};
15304: }
1.1116 raeburn 15305: if ($args->{'defaultcredits'}) {
15306: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15307: }
1.444 albertel 15308: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15309: if ($args->{'crssections'}) {
15310: $cenv{'internal.sectionnums'} = '';
15311: if ($args->{'crssections'} =~ m/,/) {
15312: @sections = split/,/,$args->{'crssections'};
15313: } else {
15314: $sections[0] = $args->{'crssections'};
15315: }
15316: if (@sections > 0) {
15317: foreach my $item (@sections) {
15318: my ($sec,$gp) = split/:/,$item;
15319: my $class = $args->{'crscode'}.$sec;
15320: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15321: $cenv{'internal.sectionnums'} .= $item.',';
15322: unless ($addcheck eq 'ok') {
15323: push @badclasses, $class;
15324: }
15325: }
15326: $cenv{'internal.sectionnums'} =~ s/,$//;
15327: }
15328: }
15329: # do not hide course coordinator from staff listing,
15330: # even if privileged
15331: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 15332: # add course coordinator's domain to domains to check for privileged users
15333: # if different to course domain
15334: if ($$crsudom ne $args->{'ccdomain'}) {
15335: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15336: }
1.444 albertel 15337: # add crosslistings
15338: if ($args->{'crsxlist'}) {
15339: $cenv{'internal.crosslistings'}='';
15340: if ($args->{'crsxlist'} =~ m/,/) {
15341: @xlists = split/,/,$args->{'crsxlist'};
15342: } else {
15343: $xlists[0] = $args->{'crsxlist'};
15344: }
15345: if (@xlists > 0) {
15346: foreach my $item (@xlists) {
15347: my ($xl,$gp) = split/:/,$item;
15348: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15349: $cenv{'internal.crosslistings'} .= $item.',';
15350: unless ($addcheck eq 'ok') {
15351: push @badclasses, $xl;
15352: }
15353: }
15354: $cenv{'internal.crosslistings'} =~ s/,$//;
15355: }
15356: }
15357: if ($args->{'autoadds'}) {
15358: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15359: }
15360: if ($args->{'autodrops'}) {
15361: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15362: }
15363: # check for notification of enrollment changes
15364: my @notified = ();
15365: if ($args->{'notify_owner'}) {
15366: if ($args->{'ccuname'} ne '') {
15367: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15368: }
15369: }
15370: if ($args->{'notify_dc'}) {
15371: if ($uname ne '') {
1.630 raeburn 15372: push(@notified,$uname.':'.$udom);
1.444 albertel 15373: }
15374: }
15375: if (@notified > 0) {
15376: my $notifylist;
15377: if (@notified > 1) {
15378: $notifylist = join(',',@notified);
15379: } else {
15380: $notifylist = $notified[0];
15381: }
15382: $cenv{'internal.notifylist'} = $notifylist;
15383: }
15384: if (@badclasses > 0) {
15385: my %lt=&Apache::lonlocal::texthash(
15386: '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',
15387: 'dnhr' => 'does not have rights to access enrollment in these classes',
15388: 'adby' => 'as determined by the policies of your institution on access to official classlists'
15389: );
1.541 raeburn 15390: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
15391: ' ('.$lt{'adby'}.')';
15392: if ($context eq 'auto') {
15393: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 15394: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 15395: foreach my $item (@badclasses) {
15396: if ($context eq 'auto') {
15397: $outcome .= " - $item\n";
15398: } else {
15399: $outcome .= "<li>$item</li>\n";
15400: }
15401: }
15402: if ($context eq 'auto') {
15403: $outcome .= $linefeed;
15404: } else {
1.566 albertel 15405: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 15406: }
15407: }
1.444 albertel 15408: }
15409: if ($args->{'no_end_date'}) {
15410: $args->{'endaccess'} = 0;
15411: }
15412: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15413: $cenv{'internal.autoend'}=$args->{'enrollend'};
15414: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15415: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15416: if ($args->{'showphotos'}) {
15417: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15418: }
15419: $cenv{'internal.authtype'} = $args->{'authtype'};
15420: $cenv{'internal.autharg'} = $args->{'autharg'};
15421: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15422: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15423: 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');
15424: if ($context eq 'auto') {
15425: $outcome .= $krb_msg;
15426: } else {
1.566 albertel 15427: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15428: }
15429: $outcome .= $linefeed;
1.444 albertel 15430: }
15431: }
15432: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15433: if ($args->{'setpolicy'}) {
15434: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15435: }
15436: if ($args->{'setcontent'}) {
15437: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15438: }
15439: }
15440: if ($args->{'reshome'}) {
15441: $cenv{'reshome'}=$args->{'reshome'}.'/';
15442: $cenv{'reshome'}=~s/\/+$/\//;
15443: }
15444: #
15445: # course has keyed access
15446: #
15447: if ($args->{'setkeys'}) {
15448: $cenv{'keyaccess'}='yes';
15449: }
15450: # if specified, key authority is not course, but user
15451: # only active if keyaccess is yes
15452: if ($args->{'keyauth'}) {
1.487 albertel 15453: my ($user,$domain) = split(':',$args->{'keyauth'});
15454: $user = &LONCAPA::clean_username($user);
15455: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15456: if ($user ne '' && $domain ne '') {
1.487 albertel 15457: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15458: }
15459: }
15460:
1.1166 raeburn 15461: #
1.1167 raeburn 15462: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 15463: #
15464: if ($args->{'uniquecode'}) {
15465: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15466: if ($code) {
15467: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 15468: my %crsinfo =
15469: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15470: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15471: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15472: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15473: }
1.1166 raeburn 15474: if (ref($coderef)) {
15475: $$coderef = $code;
15476: }
15477: }
15478: }
15479:
1.444 albertel 15480: if ($args->{'disresdis'}) {
15481: $cenv{'pch.roles.denied'}='st';
15482: }
15483: if ($args->{'disablechat'}) {
15484: $cenv{'plc.roles.denied'}='st';
15485: }
15486:
15487: # Record we've not yet viewed the Course Initialization Helper for this
15488: # course
15489: $cenv{'course.helper.not.run'} = 1;
15490: #
15491: # Use new Randomseed
15492: #
15493: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15494: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15495: #
15496: # The encryption code and receipt prefix for this course
15497: #
15498: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15499: $cenv{'internal.encpref'}=100+int(9*rand(99));
15500: #
15501: # By default, use standard grading
15502: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15503:
1.541 raeburn 15504: $outcome .= $linefeed.&mt('Setting environment').': '.
15505: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15506: #
15507: # Open all assignments
15508: #
15509: if ($args->{'openall'}) {
15510: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15511: my %storecontent = ($storeunder => time,
15512: $storeunder.'.type' => 'date_start');
15513:
15514: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15515: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15516: }
15517: #
15518: # Set first page
15519: #
15520: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15521: || ($cloneid)) {
1.445 albertel 15522: use LONCAPA::map;
1.444 albertel 15523: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15524:
15525: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15526: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15527:
1.444 albertel 15528: $outcome .= ($fatal?$errtext:'read ok').' - ';
15529: my $title; my $url;
15530: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15531: $title=&mt('Syllabus');
1.444 albertel 15532: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15533: } else {
1.963 raeburn 15534: $title=&mt('Table of Contents');
1.444 albertel 15535: $url='/adm/navmaps';
15536: }
1.445 albertel 15537:
15538: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15539: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15540:
15541: if ($errtext) { $fatal=2; }
1.541 raeburn 15542: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15543: }
1.566 albertel 15544:
1.1237 raeburn 15545: #
15546: # Set params for Placement Tests
15547: #
1.1239 raeburn 15548: if ($args->{'crstype'} eq 'Placement') {
15549: my %storecontent;
15550: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
15551: my %defaults = (
15552: buttonshide => { value => 'yes',
15553: type => 'string_yesno',},
15554: type => { value => 'randomizetry',
15555: type => 'string_questiontype',},
15556: maxtries => { value => 1,
15557: type => 'int_pos',},
15558: problemstatus => { value => 'no',
15559: type => 'string_problemstatus',},
15560: );
15561: foreach my $key (keys(%defaults)) {
15562: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
15563: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
15564: }
1.1237 raeburn 15565: &Apache::lonnet::cput
15566: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
15567: }
15568:
1.566 albertel 15569: return (1,$outcome);
1.444 albertel 15570: }
15571:
1.1166 raeburn 15572: sub make_unique_code {
15573: my ($cdom,$cnum) = @_;
15574: # get lock on uniquecodes db
15575: my $lockhash = {
15576: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15577: ':'.$env{'user.domain'},
15578: };
15579: my $tries = 0;
15580: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15581: my ($code,$error);
15582:
15583: while (($gotlock ne 'ok') && ($tries<3)) {
15584: $tries ++;
15585: sleep 1;
15586: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15587: }
15588: if ($gotlock eq 'ok') {
15589: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15590: my $gotcode;
15591: my $attempts = 0;
15592: while ((!$gotcode) && ($attempts < 100)) {
15593: $code = &generate_code();
15594: if (!exists($currcodes{$code})) {
15595: $gotcode = 1;
15596: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15597: $error = 'nostore';
15598: }
15599: }
15600: $attempts ++;
15601: }
15602: my @del_lock = ($cnum."\0".'uniquecodes');
15603: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15604: } else {
15605: $error = 'nolock';
15606: }
15607: return ($code,$error);
15608: }
15609:
15610: sub generate_code {
15611: my $code;
15612: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15613: for (my $i=0; $i<6; $i++) {
15614: my $lettnum = int (rand 2);
15615: my $item = '';
15616: if ($lettnum) {
15617: $item = $letts[int( rand(18) )];
15618: } else {
15619: $item = 1+int( rand(8) );
15620: }
15621: $code .= $item;
15622: }
15623: return $code;
15624: }
15625:
1.444 albertel 15626: ############################################################
15627: ############################################################
15628:
1.1237 raeburn 15629: # Community, Course and Placement Test
1.378 raeburn 15630: sub course_type {
15631: my ($cid) = @_;
15632: if (!defined($cid)) {
15633: $cid = $env{'request.course.id'};
15634: }
1.404 albertel 15635: if (defined($env{'course.'.$cid.'.type'})) {
15636: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15637: } else {
15638: return 'Course';
1.377 raeburn 15639: }
15640: }
1.156 albertel 15641:
1.406 raeburn 15642: sub group_term {
15643: my $crstype = &course_type();
15644: my %names = (
15645: 'Course' => 'group',
1.865 raeburn 15646: 'Community' => 'group',
1.1237 raeburn 15647: 'Placement' => 'group',
1.406 raeburn 15648: );
15649: return $names{$crstype};
15650: }
15651:
1.902 raeburn 15652: sub course_types {
1.1237 raeburn 15653: my @types = ('official','unofficial','community','textbook','placement');
1.902 raeburn 15654: my %typename = (
15655: official => 'Official course',
15656: unofficial => 'Unofficial course',
15657: community => 'Community',
1.1165 raeburn 15658: textbook => 'Textbook course',
1.1237 raeburn 15659: placement => 'Placement test',
1.902 raeburn 15660: );
15661: return (\@types,\%typename);
15662: }
15663:
1.156 albertel 15664: sub icon {
15665: my ($file)=@_;
1.505 albertel 15666: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15667: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15668: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15669: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15670: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15671: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15672: $curfext.".gif") {
15673: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15674: $curfext.".gif";
15675: }
15676: }
1.249 albertel 15677: return &lonhttpdurl($iconname);
1.154 albertel 15678: }
1.84 albertel 15679:
1.575 albertel 15680: sub lonhttpdurl {
1.692 www 15681: #
15682: # Had been used for "small fry" static images on separate port 8080.
15683: # Modify here if lightweight http functionality desired again.
15684: # Currently eliminated due to increasing firewall issues.
15685: #
1.575 albertel 15686: my ($url)=@_;
1.692 www 15687: return $url;
1.215 albertel 15688: }
15689:
1.213 albertel 15690: sub connection_aborted {
15691: my ($r)=@_;
15692: $r->print(" ");$r->rflush();
15693: my $c = $r->connection;
15694: return $c->aborted();
15695: }
15696:
1.221 foxr 15697: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15698: # strings as 'strings'.
15699: sub escape_single {
1.221 foxr 15700: my ($input) = @_;
1.223 albertel 15701: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15702: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15703: return $input;
15704: }
1.223 albertel 15705:
1.222 foxr 15706: # Same as escape_single, but escape's "'s This
15707: # can be used for "strings"
15708: sub escape_double {
15709: my ($input) = @_;
15710: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15711: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15712: return $input;
15713: }
1.223 albertel 15714:
1.222 foxr 15715: # Escapes the last element of a full URL.
15716: sub escape_url {
15717: my ($url) = @_;
1.238 raeburn 15718: my @urlslices = split(/\//, $url,-1);
1.369 www 15719: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 15720: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15721: }
1.462 albertel 15722:
1.820 raeburn 15723: sub compare_arrays {
15724: my ($arrayref1,$arrayref2) = @_;
15725: my (@difference,%count);
15726: @difference = ();
15727: %count = ();
15728: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15729: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15730: foreach my $element (keys(%count)) {
15731: if ($count{$element} == 1) {
15732: push(@difference,$element);
15733: }
15734: }
15735: }
15736: return @difference;
15737: }
15738:
1.817 bisitz 15739: # -------------------------------------------------------- Initialize user login
1.462 albertel 15740: sub init_user_environment {
1.463 albertel 15741: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15742: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15743:
15744: my $public=($username eq 'public' && $domain eq 'public');
15745:
15746: # See if old ID present, if so, remove
15747:
1.1062 raeburn 15748: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15749: my $now=time;
15750:
15751: if ($public) {
15752: my $max_public=100;
15753: my $oldest;
15754: my $oldest_time=0;
15755: for(my $next=1;$next<=$max_public;$next++) {
15756: if (-e $lonids."/publicuser_$next.id") {
15757: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15758: if ($mtime<$oldest_time || !$oldest_time) {
15759: $oldest_time=$mtime;
15760: $oldest=$next;
15761: }
15762: } else {
15763: $cookie="publicuser_$next";
15764: last;
15765: }
15766: }
15767: if (!$cookie) { $cookie="publicuser_$oldest"; }
15768: } else {
1.463 albertel 15769: # if this isn't a robot, kill any existing non-robot sessions
15770: if (!$args->{'robot'}) {
15771: opendir(DIR,$lonids);
15772: while ($filename=readdir(DIR)) {
15773: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
15774: unlink($lonids.'/'.$filename);
15775: }
1.462 albertel 15776: }
1.463 albertel 15777: closedir(DIR);
1.1204 raeburn 15778: # If there is a undeleted lockfile for the user's paste buffer remove it.
15779: my $namespace = 'nohist_courseeditor';
15780: my $lockingkey = 'paste'."\0".'locked_num';
15781: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15782: $domain,$username);
15783: if (exists($lockhash{$lockingkey})) {
15784: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15785: unless ($delresult eq 'ok') {
15786: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15787: }
15788: }
1.462 albertel 15789: }
15790: # Give them a new cookie
1.463 albertel 15791: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15792: : $now.$$.int(rand(10000)));
1.463 albertel 15793: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15794:
15795: # Initialize roles
15796:
1.1062 raeburn 15797: ($userroles,$firstaccenv,$timerintenv) =
15798: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15799: }
15800: # ------------------------------------ Check browser type and MathML capability
15801:
1.1194 raeburn 15802: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15803: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15804:
15805: # ------------------------------------------------------------- Get environment
15806:
15807: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15808: my ($tmp) = keys(%userenv);
15809: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15810: } else {
15811: undef(%userenv);
15812: }
15813: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15814: $form->{'interface'}=$userenv{'interface'};
15815: }
15816: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15817:
15818: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15819: foreach my $option ('interface','localpath','localres') {
15820: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15821: }
15822: # --------------------------------------------------------- Write first profile
15823:
15824: {
15825: my %initial_env =
15826: ("user.name" => $username,
15827: "user.domain" => $domain,
15828: "user.home" => $authhost,
15829: "browser.type" => $clientbrowser,
15830: "browser.version" => $clientversion,
15831: "browser.mathml" => $clientmathml,
15832: "browser.unicode" => $clientunicode,
15833: "browser.os" => $clientos,
1.1137 raeburn 15834: "browser.mobile" => $clientmobile,
1.1141 raeburn 15835: "browser.info" => $clientinfo,
1.1194 raeburn 15836: "browser.osversion" => $clientosversion,
1.462 albertel 15837: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15838: "request.course.fn" => '',
15839: "request.course.uri" => '',
15840: "request.course.sec" => '',
15841: "request.role" => 'cm',
15842: "request.role.adv" => $env{'user.adv'},
15843: "request.host" => $ENV{'REMOTE_ADDR'},);
15844:
15845: if ($form->{'localpath'}) {
15846: $initial_env{"browser.localpath"} = $form->{'localpath'};
15847: $initial_env{"browser.localres"} = $form->{'localres'};
15848: }
15849:
15850: if ($form->{'interface'}) {
15851: $form->{'interface'}=~s/\W//gs;
15852: $initial_env{"browser.interface"} = $form->{'interface'};
15853: $env{'browser.interface'}=$form->{'interface'};
15854: }
15855:
1.1157 raeburn 15856: if ($form->{'iptoken'}) {
15857: my $lonhost = $r->dir_config('lonHostID');
15858: $initial_env{"user.noloadbalance"} = $lonhost;
15859: $env{'user.noloadbalance'} = $lonhost;
15860: }
15861:
1.981 raeburn 15862: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 15863: my %domdef;
15864: unless ($domain eq 'public') {
15865: %domdef = &Apache::lonnet::get_domain_defaults($domain);
15866: }
1.980 raeburn 15867:
1.1081 raeburn 15868: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 15869: $userenv{'availabletools.'.$tool} =
1.980 raeburn 15870: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15871: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 15872: }
15873:
1.1237 raeburn 15874: foreach my $crstype ('official','unofficial','community','textbook','placement') {
1.765 raeburn 15875: $userenv{'canrequest.'.$crstype} =
15876: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 15877: 'reload','requestcourses',
15878: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 15879: }
15880:
1.1092 raeburn 15881: $userenv{'canrequest.author'} =
15882: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15883: 'reload','requestauthor',
15884: \%userenv,\%domdef,\%is_adv);
15885: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15886: $domain,$username);
15887: my $reqstatus = $reqauthor{'author_status'};
15888: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15889: if (ref($reqauthor{'author'}) eq 'HASH') {
15890: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15891: $reqauthor{'author'}{'timestamp'};
15892: }
15893: }
15894:
1.462 albertel 15895: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15896:
1.462 albertel 15897: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15898: &GDBM_WRCREAT(),0640)) {
15899: &_add_to_env(\%disk_env,\%initial_env);
15900: &_add_to_env(\%disk_env,\%userenv,'environment.');
15901: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15902: if (ref($firstaccenv) eq 'HASH') {
15903: &_add_to_env(\%disk_env,$firstaccenv);
15904: }
15905: if (ref($timerintenv) eq 'HASH') {
15906: &_add_to_env(\%disk_env,$timerintenv);
15907: }
1.463 albertel 15908: if (ref($args->{'extra_env'})) {
15909: &_add_to_env(\%disk_env,$args->{'extra_env'});
15910: }
1.462 albertel 15911: untie(%disk_env);
15912: } else {
1.705 tempelho 15913: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15914: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15915: return 'error: '.$!;
15916: }
15917: }
15918: $env{'request.role'}='cm';
15919: $env{'request.role.adv'}=$env{'user.adv'};
15920: $env{'browser.type'}=$clientbrowser;
15921:
15922: return $cookie;
15923:
15924: }
15925:
15926: sub _add_to_env {
15927: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15928: if (ref($env_data) eq 'HASH') {
15929: while (my ($key,$value) = each(%$env_data)) {
15930: $idf->{$prefix.$key} = $value;
15931: $env{$prefix.$key} = $value;
15932: }
1.462 albertel 15933: }
15934: }
15935:
1.685 tempelho 15936: # --- Get the symbolic name of a problem and the url
15937: sub get_symb {
15938: my ($request,$silent) = @_;
1.726 raeburn 15939: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15940: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15941: if ($symb eq '') {
15942: if (!$silent) {
1.1071 raeburn 15943: if (ref($request)) {
15944: $request->print("Unable to handle ambiguous references:$url:.");
15945: }
1.685 tempelho 15946: return ();
15947: }
15948: }
15949: &Apache::lonenc::check_decrypt(\$symb);
15950: return ($symb);
15951: }
15952:
15953: # --------------------------------------------------------------Get annotation
15954:
15955: sub get_annotation {
15956: my ($symb,$enc) = @_;
15957:
15958: my $key = $symb;
15959: if (!$enc) {
15960: $key =
15961: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15962: }
15963: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15964: return $annotation{$key};
15965: }
15966:
15967: sub clean_symb {
1.731 raeburn 15968: my ($symb,$delete_enc) = @_;
1.685 tempelho 15969:
15970: &Apache::lonenc::check_decrypt(\$symb);
15971: my $enc = $env{'request.enc'};
1.731 raeburn 15972: if ($delete_enc) {
1.730 raeburn 15973: delete($env{'request.enc'});
15974: }
1.685 tempelho 15975:
15976: return ($symb,$enc);
15977: }
1.462 albertel 15978:
1.1181 raeburn 15979: ############################################################
15980: ############################################################
15981:
15982: =pod
15983:
15984: =head1 Routines for building display used to search for courses
15985:
15986:
15987: =over 4
15988:
15989: =item * &build_filters()
15990:
15991: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 15992: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15993: and quotacheck.pl
15994:
1.1181 raeburn 15995:
15996: Inputs:
15997:
15998: filterlist - anonymous array of fields to include as potential filters
15999:
16000: crstype - course type
16001:
16002: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16003: to pop-open a course selector (will contain "extra element").
16004:
16005: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16006:
16007: filter - anonymous hash of criteria and their values
16008:
16009: action - form action
16010:
16011: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16012:
1.1182 raeburn 16013: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16014:
16015: cloneruname - username of owner of new course who wants to clone
16016:
16017: clonerudom - domain of owner of new course who wants to clone
16018:
16019: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16020:
16021: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16022:
16023: codedom - domain
16024:
16025: formname - value of form element named "form".
16026:
16027: fixeddom - domain, if fixed.
16028:
16029: prevphase - value to assign to form element named "phase" when going back to the previous screen
16030:
16031: cnameelement - name of form element in form on opener page which will receive title of selected course
16032:
16033: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16034:
16035: cdomelement - name of form element in form on opener page which will receive domain of selected course
16036:
16037: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16038:
16039: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16040:
16041: clonewarning - warning message about missing information for intended course owner when DC creates a course
16042:
1.1182 raeburn 16043:
1.1181 raeburn 16044: Returns: $output - HTML for display of search criteria, and hidden form elements.
16045:
1.1182 raeburn 16046:
1.1181 raeburn 16047: Side Effects: None
16048:
16049: =cut
16050:
16051: # ---------------------------------------------- search for courses based on last activity etc.
16052:
16053: sub build_filters {
16054: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16055: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16056: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16057: $cnameelement,$cnumelement,$cdomelement,$setroles,
16058: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16059: my ($list,$jscript);
1.1181 raeburn 16060: my $onchange = 'javascript:updateFilters(this)';
16061: my ($domainselectform,$sincefilterform,$createdfilterform,
16062: $ownerdomselectform,$persondomselectform,$instcodeform,
16063: $typeselectform,$instcodetitle);
16064: if ($formname eq '') {
16065: $formname = $caller;
16066: }
16067: foreach my $item (@{$filterlist}) {
16068: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16069: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16070: if ($item eq 'domainfilter') {
16071: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16072: } elsif ($item eq 'coursefilter') {
16073: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16074: } elsif ($item eq 'ownerfilter') {
16075: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16076: } elsif ($item eq 'ownerdomfilter') {
16077: $filter->{'ownerdomfilter'} =
16078: &LONCAPA::clean_domain($filter->{$item});
16079: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16080: 'ownerdomfilter',1);
16081: } elsif ($item eq 'personfilter') {
16082: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16083: } elsif ($item eq 'persondomfilter') {
16084: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16085: 'persondomfilter',1);
16086: } else {
16087: $filter->{$item} =~ s/\W//g;
16088: }
16089: if (!$filter->{$item}) {
16090: $filter->{$item} = '';
16091: }
16092: }
16093: if ($item eq 'domainfilter') {
16094: my $allow_blank = 1;
16095: if ($formname eq 'portform') {
16096: $allow_blank=0;
16097: } elsif ($formname eq 'studentform') {
16098: $allow_blank=0;
16099: }
16100: if ($fixeddom) {
16101: $domainselectform = '<input type="hidden" name="domainfilter"'.
16102: ' value="'.$codedom.'" />'.
16103: &Apache::lonnet::domain($codedom,'description');
16104: } else {
16105: $domainselectform = &select_dom_form($filter->{$item},
16106: 'domainfilter',
16107: $allow_blank,'',$onchange);
16108: }
16109: } else {
16110: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16111: }
16112: }
16113:
16114: # last course activity filter and selection
16115: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16116:
16117: # course created filter and selection
16118: if (exists($filter->{'createdfilter'})) {
16119: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16120: }
16121:
1.1239 raeburn 16122: my $prefix = $crstype;
16123: if ($crstype eq 'Placement') {
16124: $prefix = 'Placement Test'
16125: }
1.1181 raeburn 16126: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16127: 'cac' => "$prefix Activity",
16128: 'ccr' => "$prefix Created",
16129: 'cde' => "$prefix Title",
16130: 'cdo' => "$prefix Domain",
1.1181 raeburn 16131: 'ins' => 'Institutional Code',
16132: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16133: 'cow' => "$prefix Owner/Co-owner",
16134: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16135: 'cog' => 'Type',
16136: );
16137:
16138: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16139: my $typeval = 'Course';
16140: if ($crstype eq 'Community') {
16141: $typeval = 'Community';
1.1239 raeburn 16142: } elsif ($crstype eq 'Placement') {
16143: $typeval = 'Placement';
1.1181 raeburn 16144: }
16145: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16146: } else {
16147: $typeselectform = '<select name="type" size="1"';
16148: if ($onchange) {
16149: $typeselectform .= ' onchange="'.$onchange.'"';
16150: }
16151: $typeselectform .= '>'."\n";
1.1237 raeburn 16152: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16153: my $shown;
16154: if ($posstype eq 'Placement') {
16155: $shown = &mt('Placement Test');
16156: } else {
16157: $shown = &mt($posstype);
16158: }
1.1181 raeburn 16159: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 16160: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 16161: }
16162: $typeselectform.="</select>";
16163: }
16164:
16165: my ($cloneableonlyform,$cloneabletitle);
16166: if (exists($filter->{'cloneableonly'})) {
16167: my $cloneableon = '';
16168: my $cloneableoff = ' checked="checked"';
16169: if ($filter->{'cloneableonly'}) {
16170: $cloneableon = $cloneableoff;
16171: $cloneableoff = '';
16172: }
16173: $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>';
16174: if ($formname eq 'ccrs') {
1.1187 bisitz 16175: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 16176: } else {
16177: $cloneabletitle = &mt('Cloneable by you');
16178: }
16179: }
16180: my $officialjs;
16181: if ($crstype eq 'Course') {
16182: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 16183: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16184: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16185: if ($codedom) {
1.1181 raeburn 16186: $officialjs = 1;
16187: ($instcodeform,$jscript,$$numtitlesref) =
16188: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16189: $officialjs,$codetitlesref);
16190: if ($jscript) {
1.1182 raeburn 16191: $jscript = '<script type="text/javascript">'."\n".
16192: '// <![CDATA['."\n".
16193: $jscript."\n".
16194: '// ]]>'."\n".
16195: '</script>'."\n";
1.1181 raeburn 16196: }
16197: }
16198: if ($instcodeform eq '') {
16199: $instcodeform =
16200: '<input type="text" name="instcodefilter" size="10" value="'.
16201: $list->{'instcodefilter'}.'" />';
16202: $instcodetitle = $lt{'ins'};
16203: } else {
16204: $instcodetitle = $lt{'inc'};
16205: }
16206: if ($fixeddom) {
16207: $instcodetitle .= '<br />('.$codedom.')';
16208: }
16209: }
16210: }
16211: my $output = qq|
16212: <form method="post" name="filterpicker" action="$action">
16213: <input type="hidden" name="form" value="$formname" />
16214: |;
16215: if ($formname eq 'modifycourse') {
16216: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16217: '<input type="hidden" name="prevphase" value="'.
16218: $prevphase.'" />'."\n";
1.1198 musolffc 16219: } elsif ($formname eq 'quotacheck') {
16220: $output .= qq|
16221: <input type="hidden" name="sortby" value="" />
16222: <input type="hidden" name="sortorder" value="" />
16223: |;
16224: } else {
1.1181 raeburn 16225: my $name_input;
16226: if ($cnameelement ne '') {
16227: $name_input = '<input type="hidden" name="cnameelement" value="'.
16228: $cnameelement.'" />';
16229: }
16230: $output .= qq|
1.1182 raeburn 16231: <input type="hidden" name="cnumelement" value="$cnumelement" />
16232: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 16233: $name_input
16234: $roleelement
16235: $multelement
16236: $typeelement
16237: |;
16238: if ($formname eq 'portform') {
16239: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16240: }
16241: }
16242: if ($fixeddom) {
16243: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16244: }
16245: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16246: if ($sincefilterform) {
16247: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16248: .$sincefilterform
16249: .&Apache::lonhtmlcommon::row_closure();
16250: }
16251: if ($createdfilterform) {
16252: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16253: .$createdfilterform
16254: .&Apache::lonhtmlcommon::row_closure();
16255: }
16256: if ($domainselectform) {
16257: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16258: .$domainselectform
16259: .&Apache::lonhtmlcommon::row_closure();
16260: }
16261: if ($typeselectform) {
16262: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16263: $output .= $typeselectform;
16264: } else {
16265: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16266: .$typeselectform
16267: .&Apache::lonhtmlcommon::row_closure();
16268: }
16269: }
16270: if ($instcodeform) {
16271: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16272: .$instcodeform
16273: .&Apache::lonhtmlcommon::row_closure();
16274: }
16275: if (exists($filter->{'ownerfilter'})) {
16276: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16277: '<table><tr><td>'.&mt('Username').'<br />'.
16278: '<input type="text" name="ownerfilter" size="20" value="'.
16279: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16280: $ownerdomselectform.'</td></tr></table>'.
16281: &Apache::lonhtmlcommon::row_closure();
16282: }
16283: if (exists($filter->{'personfilter'})) {
16284: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16285: '<table><tr><td>'.&mt('Username').'<br />'.
16286: '<input type="text" name="personfilter" size="20" value="'.
16287: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16288: $persondomselectform.'</td></tr></table>'.
16289: &Apache::lonhtmlcommon::row_closure();
16290: }
16291: if (exists($filter->{'coursefilter'})) {
16292: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16293: .'<input type="text" name="coursefilter" size="25" value="'
16294: .$list->{'coursefilter'}.'" />'
16295: .&Apache::lonhtmlcommon::row_closure();
16296: }
16297: if ($cloneableonlyform) {
16298: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16299: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16300: }
16301: if (exists($filter->{'descriptfilter'})) {
16302: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16303: .'<input type="text" name="descriptfilter" size="40" value="'
16304: .$list->{'descriptfilter'}.'" />'
16305: .&Apache::lonhtmlcommon::row_closure(1);
16306: }
16307: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16308: '<input type="hidden" name="updater" value="" />'."\n".
16309: '<input type="submit" name="gosearch" value="'.
16310: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16311: return $jscript.$clonewarning.$output;
16312: }
16313:
16314: =pod
16315:
16316: =item * &timebased_select_form()
16317:
1.1182 raeburn 16318: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 16319: filter e.g., Course Activity, Course Created, when searching for courses
16320: or communities
16321:
16322: Inputs:
16323:
16324: item - name of form element (sincefilter or createdfilter)
16325:
16326: filter - anonymous hash of criteria and their values
16327:
16328: Returns: HTML for a select box contained a blank, then six time selections,
16329: with value set in incoming form variables currently selected.
16330:
16331: Side Effects: None
16332:
16333: =cut
16334:
16335: sub timebased_select_form {
16336: my ($item,$filter) = @_;
16337: if (ref($filter) eq 'HASH') {
16338: $filter->{$item} =~ s/[^\d-]//g;
16339: if (!$filter->{$item}) { $filter->{$item}=-1; }
16340: return &select_form(
16341: $filter->{$item},
16342: $item,
16343: { '-1' => '',
16344: '86400' => &mt('today'),
16345: '604800' => &mt('last week'),
16346: '2592000' => &mt('last month'),
16347: '7776000' => &mt('last three months'),
16348: '15552000' => &mt('last six months'),
16349: '31104000' => &mt('last year'),
16350: 'select_form_order' =>
16351: ['-1','86400','604800','2592000','7776000',
16352: '15552000','31104000']});
16353: }
16354: }
16355:
16356: =pod
16357:
16358: =item * &js_changer()
16359:
16360: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 16361: when course type or domain is changed, and also to hide 'Searching ...' on
16362: page load completion for page showing search result.
1.1181 raeburn 16363:
16364: Inputs: None
16365:
1.1183 raeburn 16366: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 16367:
16368: Side Effects: None
16369:
16370: =cut
16371:
16372: sub js_changer {
16373: return <<ENDJS;
16374: <script type="text/javascript">
16375: // <![CDATA[
16376: function updateFilters(caller) {
16377: if (typeof(caller) != "undefined") {
16378: document.filterpicker.updater.value = caller.name;
16379: }
16380: document.filterpicker.submit();
16381: }
1.1183 raeburn 16382:
16383: function hideSearching() {
16384: if (document.getElementById('searching')) {
16385: document.getElementById('searching').style.display = 'none';
16386: }
16387: return;
16388: }
16389:
1.1181 raeburn 16390: // ]]>
16391: </script>
16392:
16393: ENDJS
16394: }
16395:
16396: =pod
16397:
1.1182 raeburn 16398: =item * &search_courses()
16399:
16400: Process selected filters form course search form and pass to lonnet::courseiddump
16401: to retrieve a hash for which keys are courseIDs which match the selected filters.
16402:
16403: Inputs:
16404:
16405: dom - domain being searched
16406:
16407: type - course type ('Course' or 'Community' or '.' if any).
16408:
16409: filter - anonymous hash of criteria and their values
16410:
16411: numtitles - for institutional codes - number of categories
16412:
16413: cloneruname - optional username of new course owner
16414:
16415: clonerudom - optional domain of new course owner
16416:
1.1221 raeburn 16417: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 16418: (used when DC is using course creation form)
16419:
16420: codetitles - reference to array of titles of components in institutional codes (official courses).
16421:
1.1221 raeburn 16422: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16423: (and so can clone automatically)
16424:
16425: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16426:
16427: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16428: courses to clone
1.1182 raeburn 16429:
16430: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16431:
16432:
16433: Side Effects: None
16434:
16435: =cut
16436:
16437:
16438: sub search_courses {
1.1221 raeburn 16439: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16440: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 16441: my (%courses,%showcourses,$cloner);
16442: if (($filter->{'ownerfilter'} ne '') ||
16443: ($filter->{'ownerdomfilter'} ne '')) {
16444: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16445: $filter->{'ownerdomfilter'};
16446: }
16447: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16448: if (!$filter->{$item}) {
16449: $filter->{$item}='.';
16450: }
16451: }
16452: my $now = time;
16453: my $timefilter =
16454: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16455: my ($createdbefore,$createdafter);
16456: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16457: $createdbefore = $now;
16458: $createdafter = $now-$filter->{'createdfilter'};
16459: }
16460: my ($instcodefilter,$regexpok);
16461: if ($numtitles) {
16462: if ($env{'form.official'} eq 'on') {
16463: $instcodefilter =
16464: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16465: $regexpok = 1;
16466: } elsif ($env{'form.official'} eq 'off') {
16467: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16468: unless ($instcodefilter eq '') {
16469: $regexpok = -1;
16470: }
16471: }
16472: } else {
16473: $instcodefilter = $filter->{'instcodefilter'};
16474: }
16475: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16476: if ($type eq '') { $type = '.'; }
16477:
16478: if (($clonerudom ne '') && ($cloneruname ne '')) {
16479: $cloner = $cloneruname.':'.$clonerudom;
16480: }
16481: %courses = &Apache::lonnet::courseiddump($dom,
16482: $filter->{'descriptfilter'},
16483: $timefilter,
16484: $instcodefilter,
16485: $filter->{'combownerfilter'},
16486: $filter->{'coursefilter'},
16487: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 16488: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 16489: $filter->{'cloneableonly'},
16490: $createdbefore,$createdafter,undef,
1.1221 raeburn 16491: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 16492: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16493: my $ccrole;
16494: if ($type eq 'Community') {
16495: $ccrole = 'co';
16496: } else {
16497: $ccrole = 'cc';
16498: }
16499: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16500: $filter->{'persondomfilter'},
16501: 'userroles',undef,
16502: [$ccrole,'in','ad','ep','ta','cr'],
16503: $dom);
16504: foreach my $role (keys(%rolehash)) {
16505: my ($cnum,$cdom,$courserole) = split(':',$role);
16506: my $cid = $cdom.'_'.$cnum;
16507: if (exists($courses{$cid})) {
16508: if (ref($courses{$cid}) eq 'HASH') {
16509: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16510: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
16511: push (@{$courses{$cid}{roles}},$courserole);
16512: }
16513: } else {
16514: $courses{$cid}{roles} = [$courserole];
16515: }
16516: $showcourses{$cid} = $courses{$cid};
16517: }
16518: }
16519: }
16520: %courses = %showcourses;
16521: }
16522: return %courses;
16523: }
16524:
16525: =pod
16526:
1.1181 raeburn 16527: =back
16528:
1.1207 raeburn 16529: =head1 Routines for version requirements for current course.
16530:
16531: =over 4
16532:
16533: =item * &check_release_required()
16534:
16535: Compares required LON-CAPA version with version on server, and
16536: if required version is newer looks for a server with the required version.
16537:
16538: Looks first at servers in user's owen domain; if none suitable, looks at
16539: servers in course's domain are permitted to host sessions for user's domain.
16540:
16541: Inputs:
16542:
16543: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16544:
16545: $courseid - Course ID of current course
16546:
16547: $rolecode - User's current role in course (for switchserver query string).
16548:
16549: $required - LON-CAPA version needed by course (format: Major.Minor).
16550:
16551:
16552: Returns:
16553:
16554: $switchserver - query string tp append to /adm/switchserver call (if
16555: current server's LON-CAPA version is too old.
16556:
16557: $warning - Message is displayed if no suitable server could be found.
16558:
16559: =cut
16560:
16561: sub check_release_required {
16562: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16563: my ($switchserver,$warning);
16564: if ($required ne '') {
16565: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16566: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16567: if ($reqdmajor ne '' && $reqdminor ne '') {
16568: my $otherserver;
16569: if (($major eq '' && $minor eq '') ||
16570: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16571: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16572: my $switchlcrev =
16573: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16574: $userdomserver);
16575: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16576: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16577: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16578: my $cdom = $env{'course.'.$courseid.'.domain'};
16579: if ($cdom ne $env{'user.domain'}) {
16580: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16581: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16582: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16583: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16584: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16585: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16586: my $canhost =
16587: &Apache::lonnet::can_host_session($env{'user.domain'},
16588: $coursedomserver,
16589: $remoterev,
16590: $udomdefaults{'remotesessions'},
16591: $defdomdefaults{'hostedsessions'});
16592:
16593: if ($canhost) {
16594: $otherserver = $coursedomserver;
16595: } else {
16596: $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.");
16597: }
16598: } else {
16599: $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).");
16600: }
16601: } else {
16602: $otherserver = $userdomserver;
16603: }
16604: }
16605: if ($otherserver ne '') {
16606: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16607: }
16608: }
16609: }
16610: return ($switchserver,$warning);
16611: }
16612:
16613: =pod
16614:
16615: =item * &check_release_result()
16616:
16617: Inputs:
16618:
16619: $switchwarning - Warning message if no suitable server found to host session.
16620:
16621: $switchserver - query string to append to /adm/switchserver containing lonHostID
16622: and current role.
16623:
16624: Returns: HTML to display with information about requirement to switch server.
16625: Either displaying warning with link to Roles/Courses screen or
16626: display link to switchserver.
16627:
1.1181 raeburn 16628: =cut
16629:
1.1207 raeburn 16630: sub check_release_result {
16631: my ($switchwarning,$switchserver) = @_;
16632: my $output = &start_page('Selected course unavailable on this server').
16633: '<p class="LC_warning">';
16634: if ($switchwarning) {
16635: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16636: if (&show_course()) {
16637: $output .= &mt('Display courses');
16638: } else {
16639: $output .= &mt('Display roles');
16640: }
16641: $output .= '</a>';
16642: } elsif ($switchserver) {
16643: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16644: '<br />'.
16645: '<a href="/adm/switchserver?'.$switchserver.'">'.
16646: &mt('Switch Server').
16647: '</a>';
16648: }
16649: $output .= '</p>'.&end_page();
16650: return $output;
16651: }
16652:
16653: =pod
16654:
16655: =item * &needs_coursereinit()
16656:
16657: Determine if course contents stored for user's session needs to be
16658: refreshed, because content has changed since "Big Hash" last tied.
16659:
16660: Check for change is made if time last checked is more than 10 minutes ago
16661: (by default).
16662:
16663: Inputs:
16664:
16665: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16666:
16667: $interval (optional) - Time which may elapse (in s) between last check for content
16668: change in current course. (default: 600 s).
16669:
16670: Returns: an array; first element is:
16671:
16672: =over 4
16673:
16674: 'switch' - if content updates mean user's session
16675: needs to be switched to a server running a newer LON-CAPA version
16676:
16677: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16678: on current server hosting user's session
16679:
16680: '' - if no action required.
16681:
16682: =back
16683:
16684: If first item element is 'switch':
16685:
16686: second item is $switchwarning - Warning message if no suitable server found to host session.
16687:
16688: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16689: and current role.
16690:
16691: otherwise: no other elements returned.
16692:
16693: =back
16694:
16695: =cut
16696:
16697: sub needs_coursereinit {
16698: my ($loncaparev,$interval) = @_;
16699: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16700: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16701: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16702: my $now = time;
16703: if ($interval eq '') {
16704: $interval = 600;
16705: }
16706: if (($now-$env{'request.course.timechecked'})>$interval) {
16707: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16708: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16709: if ($lastchange > $env{'request.course.tied'}) {
16710: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16711: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16712: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16713: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16714: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16715: $curr_reqd_hash{'internal.releaserequired'}});
16716: my ($switchserver,$switchwarning) =
16717: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16718: $curr_reqd_hash{'internal.releaserequired'});
16719: if ($switchwarning ne '' || $switchserver ne '') {
16720: return ('switch',$switchwarning,$switchserver);
16721: }
16722: }
16723: }
16724: return ('update');
16725: }
16726: }
16727: return ();
16728: }
1.1181 raeburn 16729:
1.1083 raeburn 16730: sub update_content_constraints {
16731: my ($cdom,$cnum,$chome,$cid) = @_;
16732: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16733: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16734: my %checkresponsetypes;
16735: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 16736: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 16737: if ($item eq 'resourcetag') {
16738: if ($name eq 'responsetype') {
16739: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16740: }
16741: }
16742: }
16743: my $navmap = Apache::lonnavmaps::navmap->new();
16744: if (defined($navmap)) {
16745: my %allresponses;
16746: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16747: my %responses = $res->responseTypes();
16748: foreach my $key (keys(%responses)) {
16749: next unless(exists($checkresponsetypes{$key}));
16750: $allresponses{$key} += $responses{$key};
16751: }
16752: }
16753: foreach my $key (keys(%allresponses)) {
16754: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16755: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16756: ($reqdmajor,$reqdminor) = ($major,$minor);
16757: }
16758: }
16759: undef($navmap);
16760: }
16761: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16762: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16763: }
16764: return;
16765: }
16766:
1.1110 raeburn 16767: sub allmaps_incourse {
16768: my ($cdom,$cnum,$chome,$cid) = @_;
16769: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16770: $cid = $env{'request.course.id'};
16771: $cdom = $env{'course.'.$cid.'.domain'};
16772: $cnum = $env{'course.'.$cid.'.num'};
16773: $chome = $env{'course.'.$cid.'.home'};
16774: }
16775: my %allmaps = ();
16776: my $lastchange =
16777: &Apache::lonnet::get_coursechange($cdom,$cnum);
16778: if ($lastchange > $env{'request.course.tied'}) {
16779: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16780: unless ($ferr) {
16781: &update_content_constraints($cdom,$cnum,$chome,$cid);
16782: }
16783: }
16784: my $navmap = Apache::lonnavmaps::navmap->new();
16785: if (defined($navmap)) {
16786: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16787: $allmaps{$res->src()} = 1;
16788: }
16789: }
16790: return \%allmaps;
16791: }
16792:
1.1083 raeburn 16793: sub parse_supplemental_title {
16794: my ($title) = @_;
16795:
16796: my ($foldertitle,$renametitle);
16797: if ($title =~ /&&&/) {
16798: $title = &HTML::Entites::decode($title);
16799: }
16800: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16801: $renametitle=$4;
16802: my ($time,$uname,$udom) = ($1,$2,$3);
16803: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16804: my $name = &plainname($uname,$udom);
16805: $name = &HTML::Entities::encode($name,'"<>&\'');
16806: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16807: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16808: $name.': <br />'.$foldertitle;
16809: }
16810: if (wantarray) {
16811: return ($title,$foldertitle,$renametitle);
16812: }
16813: return $title;
16814: }
16815:
1.1143 raeburn 16816: sub recurse_supplemental {
16817: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16818: if ($suppmap) {
16819: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16820: if ($fatal) {
16821: $errors ++;
16822: } else {
16823: if ($#LONCAPA::map::resources > 0) {
16824: foreach my $res (@LONCAPA::map::resources) {
16825: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16826: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 16827: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16828: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 16829: } else {
16830: $numfiles ++;
16831: }
16832: }
16833: }
16834: }
16835: }
16836: }
16837: return ($numfiles,$errors);
16838: }
16839:
1.1101 raeburn 16840: sub symb_to_docspath {
16841: my ($symb) = @_;
16842: return unless ($symb);
16843: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16844: if ($resurl=~/\.(sequence|page)$/) {
16845: $mapurl=$resurl;
16846: } elsif ($resurl eq 'adm/navmaps') {
16847: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16848: }
16849: my $mapresobj;
16850: my $navmap = Apache::lonnavmaps::navmap->new();
16851: if (ref($navmap)) {
16852: $mapresobj = $navmap->getResourceByUrl($mapurl);
16853: }
16854: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16855: my $type=$2;
16856: my $path;
16857: if (ref($mapresobj)) {
16858: my $pcslist = $mapresobj->map_hierarchy();
16859: if ($pcslist ne '') {
16860: foreach my $pc (split(/,/,$pcslist)) {
16861: next if ($pc <= 1);
16862: my $res = $navmap->getByMapPc($pc);
16863: if (ref($res)) {
16864: my $thisurl = $res->src();
16865: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16866: my $thistitle = $res->title();
16867: $path .= '&'.
16868: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 16869: &escape($thistitle).
1.1101 raeburn 16870: ':'.$res->randompick().
16871: ':'.$res->randomout().
16872: ':'.$res->encrypted().
16873: ':'.$res->randomorder().
16874: ':'.$res->is_page();
16875: }
16876: }
16877: }
16878: $path =~ s/^\&//;
16879: my $maptitle = $mapresobj->title();
16880: if ($mapurl eq 'default') {
1.1129 raeburn 16881: $maptitle = 'Main Content';
1.1101 raeburn 16882: }
16883: $path .= (($path ne '')? '&' : '').
16884: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 16885: &escape($maptitle).
1.1101 raeburn 16886: ':'.$mapresobj->randompick().
16887: ':'.$mapresobj->randomout().
16888: ':'.$mapresobj->encrypted().
16889: ':'.$mapresobj->randomorder().
16890: ':'.$mapresobj->is_page();
16891: } else {
16892: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16893: my $ispage = (($type eq 'page')? 1 : '');
16894: if ($mapurl eq 'default') {
1.1129 raeburn 16895: $maptitle = 'Main Content';
1.1101 raeburn 16896: }
16897: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 16898: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 16899: }
16900: unless ($mapurl eq 'default') {
16901: $path = 'default&'.
1.1146 raeburn 16902: &escape('Main Content').
1.1101 raeburn 16903: ':::::&'.$path;
16904: }
16905: return $path;
16906: }
16907:
1.1094 raeburn 16908: sub captcha_display {
16909: my ($context,$lonhost) = @_;
16910: my ($output,$error);
1.1234 raeburn 16911: my ($captcha,$pubkey,$privkey,$version) =
16912: &get_captcha_config($context,$lonhost);
1.1095 raeburn 16913: if ($captcha eq 'original') {
1.1094 raeburn 16914: $output = &create_captcha();
16915: unless ($output) {
1.1172 raeburn 16916: $error = 'captcha';
1.1094 raeburn 16917: }
16918: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 16919: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 16920: unless ($output) {
1.1172 raeburn 16921: $error = 'recaptcha';
1.1094 raeburn 16922: }
16923: }
1.1234 raeburn 16924: return ($output,$error,$captcha,$version);
1.1094 raeburn 16925: }
16926:
16927: sub captcha_response {
16928: my ($context,$lonhost) = @_;
16929: my ($captcha_chk,$captcha_error);
1.1234 raeburn 16930: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 16931: if ($captcha eq 'original') {
1.1094 raeburn 16932: ($captcha_chk,$captcha_error) = &check_captcha();
16933: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 16934: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 16935: } else {
16936: $captcha_chk = 1;
16937: }
16938: return ($captcha_chk,$captcha_error);
16939: }
16940:
16941: sub get_captcha_config {
16942: my ($context,$lonhost) = @_;
1.1234 raeburn 16943: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 16944: my $hostname = &Apache::lonnet::hostname($lonhost);
16945: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16946: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 16947: if ($context eq 'usercreation') {
16948: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16949: if (ref($domconfig{$context}) eq 'HASH') {
16950: $hashtocheck = $domconfig{$context}{'cancreate'};
16951: if (ref($hashtocheck) eq 'HASH') {
16952: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16953: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16954: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16955: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16956: }
16957: if ($privkey && $pubkey) {
16958: $captcha = 'recaptcha';
1.1234 raeburn 16959: $version = $hashtocheck->{'recaptchaversion'};
16960: if ($version ne '2') {
16961: $version = 1;
16962: }
1.1095 raeburn 16963: } else {
16964: $captcha = 'original';
16965: }
16966: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16967: $captcha = 'original';
16968: }
1.1094 raeburn 16969: }
1.1095 raeburn 16970: } else {
16971: $captcha = 'captcha';
16972: }
16973: } elsif ($context eq 'login') {
16974: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16975: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16976: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16977: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 16978: if ($privkey && $pubkey) {
16979: $captcha = 'recaptcha';
1.1234 raeburn 16980: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
16981: if ($version ne '2') {
16982: $version = 1;
16983: }
1.1095 raeburn 16984: } else {
16985: $captcha = 'original';
1.1094 raeburn 16986: }
1.1095 raeburn 16987: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16988: $captcha = 'original';
1.1094 raeburn 16989: }
16990: }
1.1234 raeburn 16991: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 16992: }
16993:
16994: sub create_captcha {
16995: my %captcha_params = &captcha_settings();
16996: my ($output,$maxtries,$tries) = ('',10,0);
16997: while ($tries < $maxtries) {
16998: $tries ++;
16999: my $captcha = Authen::Captcha->new (
17000: output_folder => $captcha_params{'output_dir'},
17001: data_folder => $captcha_params{'db_dir'},
17002: );
17003: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17004:
17005: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17006: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17007: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17008: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17009: '<br />'.
17010: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17011: last;
17012: }
17013: }
17014: return $output;
17015: }
17016:
17017: sub captcha_settings {
17018: my %captcha_params = (
17019: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17020: www_output_dir => "/captchaspool",
17021: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17022: numchars => '5',
17023: );
17024: return %captcha_params;
17025: }
17026:
17027: sub check_captcha {
17028: my ($captcha_chk,$captcha_error);
17029: my $code = $env{'form.code'};
17030: my $md5sum = $env{'form.crypt'};
17031: my %captcha_params = &captcha_settings();
17032: my $captcha = Authen::Captcha->new(
17033: output_folder => $captcha_params{'output_dir'},
17034: data_folder => $captcha_params{'db_dir'},
17035: );
1.1109 raeburn 17036: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17037: my %captcha_hash = (
17038: 0 => 'Code not checked (file error)',
17039: -1 => 'Failed: code expired',
17040: -2 => 'Failed: invalid code (not in database)',
17041: -3 => 'Failed: invalid code (code does not match crypt)',
17042: );
17043: if ($captcha_chk != 1) {
17044: $captcha_error = $captcha_hash{$captcha_chk}
17045: }
17046: return ($captcha_chk,$captcha_error);
17047: }
17048:
17049: sub create_recaptcha {
1.1234 raeburn 17050: my ($pubkey,$version) = @_;
17051: if ($version >= 2) {
17052: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17053: } else {
17054: my $use_ssl;
17055: if ($ENV{'SERVER_PORT'} == 443) {
17056: $use_ssl = 1;
17057: }
17058: my $captcha = Captcha::reCAPTCHA->new;
17059: return $captcha->get_options_setter({theme => 'white'})."\n".
17060: $captcha->get_html($pubkey,undef,$use_ssl).
17061: &mt('If the text is hard to read, [_1] will replace them.',
17062: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17063: '<br /><br />';
17064: }
1.1094 raeburn 17065: }
17066:
17067: sub check_recaptcha {
1.1234 raeburn 17068: my ($privkey,$version) = @_;
1.1094 raeburn 17069: my $captcha_chk;
1.1234 raeburn 17070: if ($version >= 2) {
17071: my $ua = LWP::UserAgent->new;
17072: $ua->timeout(10);
17073: my %info = (
17074: secret => $privkey,
17075: response => $env{'form.g-recaptcha-response'},
17076: remoteip => $ENV{'REMOTE_ADDR'},
17077: );
17078: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17079: if ($response->is_success) {
17080: my $data = JSON::DWIW->from_json($response->decoded_content);
17081: if (ref($data) eq 'HASH') {
17082: if ($data->{'success'}) {
17083: $captcha_chk = 1;
17084: }
17085: }
17086: }
17087: } else {
17088: my $captcha = Captcha::reCAPTCHA->new;
17089: my $captcha_result =
17090: $captcha->check_answer(
17091: $privkey,
17092: $ENV{'REMOTE_ADDR'},
17093: $env{'form.recaptcha_challenge_field'},
17094: $env{'form.recaptcha_response_field'},
17095: );
17096: if ($captcha_result->{is_valid}) {
17097: $captcha_chk = 1;
17098: }
1.1094 raeburn 17099: }
17100: return $captcha_chk;
17101: }
17102:
1.1174 raeburn 17103: sub emailusername_info {
1.1244 raeburn 17104: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 17105: my %titles = &Apache::lonlocal::texthash (
17106: lastname => 'Last Name',
17107: firstname => 'First Name',
17108: institution => 'School/college/university',
17109: location => "School's city, state/province, country",
17110: web => "School's web address",
17111: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 17112: id => 'Student/Employee ID',
1.1174 raeburn 17113: );
17114: return (\@fields,\%titles);
17115: }
17116:
1.1161 raeburn 17117: sub cleanup_html {
17118: my ($incoming) = @_;
17119: my $outgoing;
17120: if ($incoming ne '') {
17121: $outgoing = $incoming;
17122: $outgoing =~ s/;/;/g;
17123: $outgoing =~ s/\#/#/g;
17124: $outgoing =~ s/\&/&/g;
17125: $outgoing =~ s/</</g;
17126: $outgoing =~ s/>/>/g;
17127: $outgoing =~ s/\(/(/g;
17128: $outgoing =~ s/\)/)/g;
17129: $outgoing =~ s/"/"/g;
17130: $outgoing =~ s/'/'/g;
17131: $outgoing =~ s/\$/$/g;
17132: $outgoing =~ s{/}{/}g;
17133: $outgoing =~ s/=/=/g;
17134: $outgoing =~ s/\\/\/g
17135: }
17136: return $outgoing;
17137: }
17138:
1.1190 musolffc 17139: # Checks for critical messages and returns a redirect url if one exists.
17140: # $interval indicates how often to check for messages.
17141: sub critical_redirect {
17142: my ($interval) = @_;
17143: if ((time-$env{'user.criticalcheck.time'})>$interval) {
17144: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17145: $env{'user.name'});
17146: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 17147: my $redirecturl;
1.1190 musolffc 17148: if ($what[0]) {
17149: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17150: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 17151: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17152: return (1, $url);
1.1190 musolffc 17153: }
1.1191 raeburn 17154: }
17155: }
17156: return ();
1.1190 musolffc 17157: }
17158:
1.1174 raeburn 17159: # Use:
17160: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17161: #
17162: ##################################################
17163: # password associated functions #
17164: ##################################################
17165: sub des_keys {
17166: # Make a new key for DES encryption.
17167: # Each key has two parts which are returned separately.
17168: # Please note: Each key must be passed through the &hex function
17169: # before it is output to the web browser. The hex versions cannot
17170: # be used to decrypt.
17171: my @hexstr=('0','1','2','3','4','5','6','7',
17172: '8','9','a','b','c','d','e','f');
17173: my $lkey='';
17174: for (0..7) {
17175: $lkey.=$hexstr[rand(15)];
17176: }
17177: my $ukey='';
17178: for (0..7) {
17179: $ukey.=$hexstr[rand(15)];
17180: }
17181: return ($lkey,$ukey);
17182: }
17183:
17184: sub des_decrypt {
17185: my ($key,$cyphertext) = @_;
17186: my $keybin=pack("H16",$key);
17187: my $cypher;
17188: if ($Crypt::DES::VERSION>=2.03) {
17189: $cypher=new Crypt::DES $keybin;
17190: } else {
17191: $cypher=new DES $keybin;
17192: }
1.1233 raeburn 17193: my $plaintext='';
17194: my $cypherlength = length($cyphertext);
17195: my $numchunks = int($cypherlength/32);
17196: for (my $j=0; $j<$numchunks; $j++) {
17197: my $start = $j*32;
17198: my $cypherblock = substr($cyphertext,$start,32);
17199: my $chunk =
17200: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17201: $chunk .=
17202: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17203: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17204: $plaintext .= $chunk;
17205: }
1.1174 raeburn 17206: return $plaintext;
17207: }
17208:
1.112 bowersj2 17209: 1;
17210: __END__;
1.41 ng 17211:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>