Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.136
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1075.2.136! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.135 2019/07/30 21:13:54 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.1075.2.25 raeburn 70: use Apache::lonuserutils();
1.1075.2.27 raeburn 71: use Apache::lonuserstate();
1.1075.2.69 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1075.2.135 raeburn 74: use HTTP::Request;
1.657 raeburn 75: use DateTime::TimeZone;
1.1075.2.102 raeburn 76: use DateTime::Locale;
1.1075.2.94 raeburn 77: use Encode();
1.1075.2.14 raeburn 78: use Authen::Captcha;
79: use Captcha::reCAPTCHA;
1.1075.2.107 raeburn 80: use JSON::DWIW;
81: use LWP::UserAgent;
1.1075.2.64 raeburn 82: use Crypt::DES;
83: use DynaLoader; # for Crypt::DES version
1.1075.2.128 raeburn 84: use File::Copy();
85: use File::Path();
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.1048 foxr 170: my %latex_language; # For choosing hyphenation in <transl..>
171: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 172: my %cprtag;
1.192 taceyjo1 173: my %scprtag;
1.351 www 174: my %fe; my %fd; my %fm;
1.41 ng 175: my %category_extensions;
1.12 harris41 176:
1.46 matthew 177: # ---------------------------------------------- Thesaurus variables
1.144 matthew 178: #
179: # %Keywords:
180: # A hash used by &keyword to determine if a word is considered a keyword.
181: # $thesaurus_db_file
182: # Scalar containing the full path to the thesaurus database.
1.46 matthew 183:
184: my %Keywords;
185: my $thesaurus_db_file;
186:
1.144 matthew 187: #
188: # Initialize values from language.tab, copyright.tab, filetypes.tab,
189: # thesaurus.tab, and filecategories.tab.
190: #
1.18 www 191: BEGIN {
1.46 matthew 192: # Variable initialization
193: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
194: #
1.22 www 195: unless ($readit) {
1.12 harris41 196: # ------------------------------------------------------------------- languages
197: {
1.158 raeburn 198: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
199: '/language.tab';
1.1075.2.128 raeburn 200: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 201: while (my $line = <$fh>) {
202: next if ($line=~/^\#/);
203: chomp($line);
1.1048 foxr 204: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 205: $language{$key}=$val.' - '.$enc;
206: if ($sup) {
207: $supported_language{$key}=$sup;
208: }
1.1048 foxr 209: if ($latex) {
210: $latex_language_bykey{$key} = $latex;
211: $latex_language{$two} = $latex;
212: }
1.158 raeburn 213: }
214: close($fh);
215: }
1.12 harris41 216: }
217: # ------------------------------------------------------------------ copyrights
218: {
1.158 raeburn 219: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
220: '/copyright.tab';
1.1075.2.128 raeburn 221: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 222: while (my $line = <$fh>) {
223: next if ($line=~/^\#/);
224: chomp($line);
225: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 226: $cprtag{$key}=$val;
227: }
228: close($fh);
229: }
1.12 harris41 230: }
1.351 www 231: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 232: {
233: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
234: '/source_copyright.tab';
1.1075.2.128 raeburn 235: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 236: while (my $line = <$fh>) {
237: next if ($line =~ /^\#/);
238: chomp($line);
239: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 240: $scprtag{$key}=$val;
241: }
242: close($fh);
243: }
244: }
1.63 www 245:
1.517 raeburn 246: # -------------------------------------------------------------- default domain designs
1.63 www 247: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 248: my $designfile = $designdir.'/default.tab';
1.1075.2.128 raeburn 249: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 250: while (my $line = <$fh>) {
251: next if ($line =~ /^\#/);
252: chomp($line);
253: my ($key,$val)=(split(/\=/,$line));
254: if ($val) { $defaultdesign{$key}=$val; }
255: }
256: close($fh);
1.63 www 257: }
258:
1.15 harris41 259: # ------------------------------------------------------------- file categories
260: {
1.158 raeburn 261: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
262: '/filecategories.tab';
1.1075.2.128 raeburn 263: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 264: while (my $line = <$fh>) {
265: next if ($line =~ /^\#/);
266: chomp($line);
267: my ($extension,$category)=(split(/\s+/,$line,2));
1.1075.2.119 raeburn 268: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 269: }
270: close($fh);
271: }
272:
1.15 harris41 273: }
1.12 harris41 274: # ------------------------------------------------------------------ file types
275: {
1.158 raeburn 276: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
277: '/filetypes.tab';
1.1075.2.128 raeburn 278: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 279: while (my $line = <$fh>) {
280: next if ($line =~ /^\#/);
281: chomp($line);
282: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 283: if ($descr ne '') {
284: $fe{$ending}=lc($emb);
285: $fd{$ending}=$descr;
1.351 www 286: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 287: }
288: }
289: close($fh);
290: }
1.12 harris41 291: }
1.22 www 292: &Apache::lonnet::logthis(
1.705 tempelho 293: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 294: $readit=1;
1.46 matthew 295: } # end of unless($readit)
1.32 matthew 296:
297: }
1.112 bowersj2 298:
1.42 matthew 299: ###############################################################
300: ## HTML and Javascript Helper Functions ##
301: ###############################################################
302:
303: =pod
304:
1.112 bowersj2 305: =head1 HTML and Javascript Functions
1.42 matthew 306:
1.112 bowersj2 307: =over 4
308:
1.648 raeburn 309: =item * &browser_and_searcher_javascript()
1.112 bowersj2 310:
311: X<browsing, javascript>X<searching, javascript>Returns a string
312: containing javascript with two functions, C<openbrowser> and
313: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
314: tags.
1.42 matthew 315:
1.648 raeburn 316: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 317:
318: inputs: formname, elementname, only, omit
319:
320: formname and elementname indicate the name of the html form and name of
321: the element that the results of the browsing selection are to be placed in.
322:
323: Specifying 'only' will restrict the browser to displaying only files
1.185 www 324: with the given extension. Can be a comma separated list.
1.42 matthew 325:
326: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 327: with the given extension. Can be a comma separated list.
1.42 matthew 328:
1.648 raeburn 329: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 330:
331: Inputs: formname, elementname
332:
333: formname and elementname specify the name of the html form and the name
334: of the element the selection from the search results will be placed in.
1.542 raeburn 335:
1.42 matthew 336: =cut
337:
338: sub browser_and_searcher_javascript {
1.199 albertel 339: my ($mode)=@_;
340: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 341: my $resurl=&escape_single(&lastresurl());
1.42 matthew 342: return <<END;
1.219 albertel 343: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 344: var editbrowser = null;
1.135 albertel 345: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 346: var url = '$resurl/?';
1.42 matthew 347: if (editbrowser == null) {
348: url += 'launch=1&';
349: }
350: url += 'catalogmode=interactive&';
1.199 albertel 351: url += 'mode=$mode&';
1.611 albertel 352: url += 'inhibitmenu=yes&';
1.42 matthew 353: url += 'form=' + formname + '&';
354: if (only != null) {
355: url += 'only=' + only + '&';
1.217 albertel 356: } else {
357: url += 'only=&';
358: }
1.42 matthew 359: if (omit != null) {
360: url += 'omit=' + omit + '&';
1.217 albertel 361: } else {
362: url += 'omit=&';
363: }
1.135 albertel 364: if (titleelement != null) {
365: url += 'titleelement=' + titleelement + '&';
1.217 albertel 366: } else {
367: url += 'titleelement=&';
368: }
1.42 matthew 369: url += 'element=' + elementname + '';
370: var title = 'Browser';
1.435 albertel 371: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 372: options += ',width=700,height=600';
373: editbrowser = open(url,title,options,'1');
374: editbrowser.focus();
375: }
376: var editsearcher;
1.135 albertel 377: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 378: var url = '/adm/searchcat?';
379: if (editsearcher == null) {
380: url += 'launch=1&';
381: }
382: url += 'catalogmode=interactive&';
1.199 albertel 383: url += 'mode=$mode&';
1.42 matthew 384: url += 'form=' + formname + '&';
1.135 albertel 385: if (titleelement != null) {
386: url += 'titleelement=' + titleelement + '&';
1.217 albertel 387: } else {
388: url += 'titleelement=&';
389: }
1.42 matthew 390: url += 'element=' + elementname + '';
391: var title = 'Search';
1.435 albertel 392: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 393: options += ',width=700,height=600';
394: editsearcher = open(url,title,options,'1');
395: editsearcher.focus();
396: }
1.219 albertel 397: // END LON-CAPA Internal -->
1.42 matthew 398: END
1.170 www 399: }
400:
401: sub lastresurl {
1.258 albertel 402: if ($env{'environment.lastresurl'}) {
403: return $env{'environment.lastresurl'}
1.170 www 404: } else {
405: return '/res';
406: }
407: }
408:
409: sub storeresurl {
410: my $resurl=&Apache::lonnet::clutter(shift);
411: unless ($resurl=~/^\/res/) { return 0; }
412: $resurl=~s/\/$//;
413: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 414: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 415: return 1;
1.42 matthew 416: }
417:
1.74 www 418: sub studentbrowser_javascript {
1.111 www 419: unless (
1.258 albertel 420: (($env{'request.course.id'}) &&
1.302 albertel 421: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
422: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
423: '/'.$env{'request.course.sec'})
424: ))
1.258 albertel 425: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 426: ) { return ''; }
1.74 www 427: return (<<'ENDSTDBRW');
1.776 bisitz 428: <script type="text/javascript" language="Javascript">
1.824 bisitz 429: // <![CDATA[
1.74 www 430: var stdeditbrowser;
1.999 www 431: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 432: var url = '/adm/pickstudent?';
433: var filter;
1.558 albertel 434: if (!ignorefilter) {
435: eval('filter=document.'+formname+'.'+uname+'.value;');
436: }
1.74 www 437: if (filter != null) {
438: if (filter != '') {
439: url += 'filter='+filter+'&';
440: }
441: }
442: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 443: '&udomelement='+udom+
444: '&clicker='+clicker;
1.111 www 445: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 446: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 447: var title = 'Student_Browser';
1.74 www 448: var options = 'scrollbars=1,resizable=1,menubar=0';
449: options += ',width=700,height=600';
450: stdeditbrowser = open(url,title,options,'1');
451: stdeditbrowser.focus();
452: }
1.824 bisitz 453: // ]]>
1.74 www 454: </script>
455: ENDSTDBRW
456: }
1.42 matthew 457:
1.1003 www 458: sub resourcebrowser_javascript {
459: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 460: return (<<'ENDRESBRW');
1.1003 www 461: <script type="text/javascript" language="Javascript">
462: // <![CDATA[
463: var reseditbrowser;
1.1004 www 464: function openresbrowser(formname,reslink) {
1.1005 www 465: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 466: var title = 'Resource_Browser';
467: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 468: options += ',width=700,height=500';
1.1004 www 469: reseditbrowser = open(url,title,options,'1');
470: reseditbrowser.focus();
1.1003 www 471: }
472: // ]]>
473: </script>
1.1004 www 474: ENDRESBRW
1.1003 www 475: }
476:
1.74 www 477: sub selectstudent_link {
1.999 www 478: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
479: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
480: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
481: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 482: if ($env{'request.course.id'}) {
1.302 albertel 483: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
484: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
485: '/'.$env{'request.course.sec'})) {
1.111 www 486: return '';
487: }
1.999 www 488: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 489: if ($courseadvonly) {
490: $callargs .= ",'',1,1";
491: }
492: return '<span class="LC_nobreak">'.
493: '<a href="javascript:openstdbrowser('.$callargs.');">'.
494: &mt('Select User').'</a></span>';
1.74 www 495: }
1.258 albertel 496: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 497: $callargs .= ",'',1";
1.793 raeburn 498: return '<span class="LC_nobreak">'.
499: '<a href="javascript:openstdbrowser('.$callargs.');">'.
500: &mt('Select User').'</a></span>';
1.111 www 501: }
502: return '';
1.91 www 503: }
504:
1.1004 www 505: sub selectresource_link {
506: my ($form,$reslink,$arg)=@_;
507:
508: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
509: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
510: unless ($env{'request.course.id'}) { return $arg; }
511: return '<span class="LC_nobreak">'.
512: '<a href="javascript:openresbrowser('.$callargs.');">'.
513: $arg.'</a></span>';
514: }
515:
516:
517:
1.653 raeburn 518: sub authorbrowser_javascript {
519: return <<"ENDAUTHORBRW";
1.776 bisitz 520: <script type="text/javascript" language="JavaScript">
1.824 bisitz 521: // <![CDATA[
1.653 raeburn 522: var stdeditbrowser;
523:
524: function openauthorbrowser(formname,udom) {
525: var url = '/adm/pickauthor?';
526: url += 'form='+formname+'&roledom='+udom;
527: var title = 'Author_Browser';
528: var options = 'scrollbars=1,resizable=1,menubar=0';
529: options += ',width=700,height=600';
530: stdeditbrowser = open(url,title,options,'1');
531: stdeditbrowser.focus();
532: }
533:
1.824 bisitz 534: // ]]>
1.653 raeburn 535: </script>
536: ENDAUTHORBRW
537: }
538:
1.91 www 539: sub coursebrowser_javascript {
1.1075.2.31 raeburn 540: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1075.2.95 raeburn 541: $credits_element,$instcode) = @_;
1.932 raeburn 542: my $wintitle = 'Course_Browser';
1.931 raeburn 543: if ($crstype eq 'Community') {
1.932 raeburn 544: $wintitle = 'Community_Browser';
1.909 raeburn 545: }
1.876 raeburn 546: my $id_functions = &javascript_index_functions();
547: my $output = '
1.776 bisitz 548: <script type="text/javascript" language="JavaScript">
1.824 bisitz 549: // <![CDATA[
1.468 raeburn 550: var stdeditbrowser;'."\n";
1.876 raeburn 551:
552: $output .= <<"ENDSTDBRW";
1.909 raeburn 553: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 554: var url = '/adm/pickcourse?';
1.895 raeburn 555: var formid = getFormIdByName(formname);
1.876 raeburn 556: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 557: if (domainfilter != null) {
558: if (domainfilter != '') {
559: url += 'domainfilter='+domainfilter+'&';
560: }
561: }
1.91 www 562: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 563: '&cdomelement='+udom+
564: '&cnameelement='+desc;
1.468 raeburn 565: if (extra_element !=null && extra_element != '') {
1.594 raeburn 566: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 567: url += '&roleelement='+extra_element;
568: if (domainfilter == null || domainfilter == '') {
569: url += '&domainfilter='+extra_element;
570: }
1.234 raeburn 571: }
1.468 raeburn 572: else {
573: if (formname == 'portform') {
574: url += '&setroles='+extra_element;
1.800 raeburn 575: } else {
576: if (formname == 'rules') {
577: url += '&fixeddom='+extra_element;
578: }
1.468 raeburn 579: }
580: }
1.230 raeburn 581: }
1.909 raeburn 582: if (type != null && type != '') {
583: url += '&type='+type;
584: }
585: if (type_elem != null && type_elem != '') {
586: url += '&typeelement='+type_elem;
587: }
1.872 raeburn 588: if (formname == 'ccrs') {
589: var ownername = document.forms[formid].ccuname.value;
590: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1075.2.101 raeburn 591: url += '&cloner='+ownername+':'+ownerdom;
592: if (type == 'Course') {
593: url += '&crscode='+document.forms[formid].crscode.value;
594: }
1.1075.2.95 raeburn 595: }
596: if (formname == 'requestcrs') {
597: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 598: }
1.293 raeburn 599: if (multflag !=null && multflag != '') {
600: url += '&multiple='+multflag;
601: }
1.909 raeburn 602: var title = '$wintitle';
1.91 www 603: var options = 'scrollbars=1,resizable=1,menubar=0';
604: options += ',width=700,height=600';
605: stdeditbrowser = open(url,title,options,'1');
606: stdeditbrowser.focus();
607: }
1.876 raeburn 608: $id_functions
609: ENDSTDBRW
1.1075.2.31 raeburn 610: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
611: $output .= &setsec_javascript($sec_element,$formname,$role_element,
612: $credits_element);
1.876 raeburn 613: }
614: $output .= '
615: // ]]>
616: </script>';
617: return $output;
618: }
619:
620: sub javascript_index_functions {
621: return <<"ENDJS";
622:
623: function getFormIdByName(formname) {
624: for (var i=0;i<document.forms.length;i++) {
625: if (document.forms[i].name == formname) {
626: return i;
627: }
628: }
629: return -1;
630: }
631:
632: function getIndexByName(formid,item) {
633: for (var i=0;i<document.forms[formid].elements.length;i++) {
634: if (document.forms[formid].elements[i].name == item) {
635: return i;
636: }
637: }
638: return -1;
639: }
1.468 raeburn 640:
1.876 raeburn 641: function getDomainFromSelectbox(formname,udom) {
642: var userdom;
643: var formid = getFormIdByName(formname);
644: if (formid > -1) {
645: var domid = getIndexByName(formid,udom);
646: if (domid > -1) {
647: if (document.forms[formid].elements[domid].type == 'select-one') {
648: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
649: }
650: if (document.forms[formid].elements[domid].type == 'hidden') {
651: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 652: }
653: }
654: }
1.876 raeburn 655: return userdom;
656: }
657:
658: ENDJS
1.468 raeburn 659:
1.876 raeburn 660: }
661:
1.1017 raeburn 662: sub javascript_array_indexof {
1.1018 raeburn 663: return <<ENDJS;
1.1017 raeburn 664: <script type="text/javascript" language="JavaScript">
665: // <![CDATA[
666:
667: if (!Array.prototype.indexOf) {
668: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
669: "use strict";
670: if (this === void 0 || this === null) {
671: throw new TypeError();
672: }
673: var t = Object(this);
674: var len = t.length >>> 0;
675: if (len === 0) {
676: return -1;
677: }
678: var n = 0;
679: if (arguments.length > 0) {
680: n = Number(arguments[1]);
681: if (n !== n) { // shortcut for verifying if it's NaN
682: n = 0;
683: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
684: n = (n > 0 || -1) * Math.floor(Math.abs(n));
685: }
686: }
687: if (n >= len) {
688: return -1;
689: }
690: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
691: for (; k < len; k++) {
692: if (k in t && t[k] === searchElement) {
693: return k;
694: }
695: }
696: return -1;
697: }
698: }
699:
700: // ]]>
701: </script>
702:
703: ENDJS
704:
705: }
706:
1.876 raeburn 707: sub userbrowser_javascript {
708: my $id_functions = &javascript_index_functions();
709: return <<"ENDUSERBRW";
710:
1.888 raeburn 711: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 712: var url = '/adm/pickuser?';
713: var userdom = getDomainFromSelectbox(formname,udom);
714: if (userdom != null) {
715: if (userdom != '') {
716: url += 'srchdom='+userdom+'&';
717: }
718: }
719: url += 'form=' + formname + '&unameelement='+uname+
720: '&udomelement='+udom+
721: '&ulastelement='+ulast+
722: '&ufirstelement='+ufirst+
723: '&uemailelement='+uemail+
1.881 raeburn 724: '&hideudomelement='+hideudom+
725: '&coursedom='+crsdom;
1.888 raeburn 726: if ((caller != null) && (caller != undefined)) {
727: url += '&caller='+caller;
728: }
1.876 raeburn 729: var title = 'User_Browser';
730: var options = 'scrollbars=1,resizable=1,menubar=0';
731: options += ',width=700,height=600';
732: var stdeditbrowser = open(url,title,options,'1');
733: stdeditbrowser.focus();
734: }
735:
1.888 raeburn 736: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 737: var formid = getFormIdByName(formname);
738: if (formid > -1) {
1.888 raeburn 739: var unameid = getIndexByName(formid,uname);
1.876 raeburn 740: var domid = getIndexByName(formid,udom);
741: var hidedomid = getIndexByName(formid,origdom);
742: if (hidedomid > -1) {
743: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 744: var unameval = document.forms[formid].elements[unameid].value;
745: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
746: if (domid > -1) {
747: var slct = document.forms[formid].elements[domid];
748: if (slct.type == 'select-one') {
749: var i;
750: for (i=0;i<slct.length;i++) {
751: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
752: }
753: }
754: if (slct.type == 'hidden') {
755: slct.value = fixeddom;
1.876 raeburn 756: }
757: }
1.468 raeburn 758: }
759: }
760: }
1.876 raeburn 761: return;
762: }
763:
764: $id_functions
765: ENDUSERBRW
1.468 raeburn 766: }
767:
768: sub setsec_javascript {
1.1075.2.31 raeburn 769: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 770: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
771: $communityrolestr);
772: if ($role_element ne '') {
773: my @allroles = ('st','ta','ep','in','ad');
774: foreach my $crstype ('Course','Community') {
775: if ($crstype eq 'Community') {
776: foreach my $role (@allroles) {
777: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
778: }
779: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
780: } else {
781: foreach my $role (@allroles) {
782: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
783: }
784: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
785: }
786: }
787: $rolestr = '"'.join('","',@allroles).'"';
788: $courserolestr = '"'.join('","',@courserolenames).'"';
789: $communityrolestr = '"'.join('","',@communityrolenames).'"';
790: }
1.468 raeburn 791: my $setsections = qq|
792: function setSect(sectionlist) {
1.629 raeburn 793: var sectionsArray = new Array();
794: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
795: sectionsArray = sectionlist.split(",");
796: }
1.468 raeburn 797: var numSections = sectionsArray.length;
798: document.$formname.$sec_element.length = 0;
799: if (numSections == 0) {
800: document.$formname.$sec_element.multiple=false;
801: document.$formname.$sec_element.size=1;
802: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
803: } else {
804: if (numSections == 1) {
805: document.$formname.$sec_element.multiple=false;
806: document.$formname.$sec_element.size=1;
807: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
808: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
809: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
810: } else {
811: for (var i=0; i<numSections; i++) {
812: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
813: }
814: document.$formname.$sec_element.multiple=true
815: if (numSections < 3) {
816: document.$formname.$sec_element.size=numSections;
817: } else {
818: document.$formname.$sec_element.size=3;
819: }
820: document.$formname.$sec_element.options[0].selected = false
821: }
822: }
1.91 www 823: }
1.905 raeburn 824:
825: function setRole(crstype) {
1.468 raeburn 826: |;
1.905 raeburn 827: if ($role_element eq '') {
828: $setsections .= ' return;
829: }
830: ';
831: } else {
832: $setsections .= qq|
833: var elementLength = document.$formname.$role_element.length;
834: var allroles = Array($rolestr);
835: var courserolenames = Array($courserolestr);
836: var communityrolenames = Array($communityrolestr);
837: if (elementLength != undefined) {
838: if (document.$formname.$role_element.options[5].value == 'cc') {
839: if (crstype == 'Course') {
840: return;
841: } else {
842: allroles[5] = 'co';
843: for (var i=0; i<6; i++) {
844: document.$formname.$role_element.options[i].value = allroles[i];
845: document.$formname.$role_element.options[i].text = communityrolenames[i];
846: }
847: }
848: } else {
849: if (crstype == 'Community') {
850: return;
851: } else {
852: allroles[5] = 'cc';
853: for (var i=0; i<6; i++) {
854: document.$formname.$role_element.options[i].value = allroles[i];
855: document.$formname.$role_element.options[i].text = courserolenames[i];
856: }
857: }
858: }
859: }
860: return;
861: }
862: |;
863: }
1.1075.2.31 raeburn 864: if ($credits_element) {
865: $setsections .= qq|
866: function setCredits(defaultcredits) {
867: document.$formname.$credits_element.value = defaultcredits;
868: return;
869: }
870: |;
871: }
1.468 raeburn 872: return $setsections;
873: }
874:
1.91 www 875: sub selectcourse_link {
1.909 raeburn 876: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
877: $typeelement) = @_;
878: my $type = $selecttype;
1.871 raeburn 879: my $linktext = &mt('Select Course');
880: if ($selecttype eq 'Community') {
1.909 raeburn 881: $linktext = &mt('Select Community');
1.906 raeburn 882: } elsif ($selecttype eq 'Course/Community') {
883: $linktext = &mt('Select Course/Community');
1.909 raeburn 884: $type = '';
1.1019 raeburn 885: } elsif ($selecttype eq 'Select') {
886: $linktext = &mt('Select');
887: $type = '';
1.871 raeburn 888: }
1.787 bisitz 889: return '<span class="LC_nobreak">'
890: ."<a href='"
891: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
892: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 893: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 894: ."'>".$linktext.'</a>'
1.787 bisitz 895: .'</span>';
1.74 www 896: }
1.42 matthew 897:
1.653 raeburn 898: sub selectauthor_link {
899: my ($form,$udom)=@_;
900: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
901: &mt('Select Author').'</a>';
902: }
903:
1.876 raeburn 904: sub selectuser_link {
1.881 raeburn 905: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 906: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 907: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 908: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 909: ');">'.$linktext.'</a>';
1.876 raeburn 910: }
911:
1.273 raeburn 912: sub check_uncheck_jscript {
913: my $jscript = <<"ENDSCRT";
914: function checkAll(field) {
915: if (field.length > 0) {
916: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 917: if (!field[i].disabled) {
918: field[i].checked = true;
919: }
1.273 raeburn 920: }
921: } else {
1.1075.2.14 raeburn 922: if (!field.disabled) {
923: field.checked = true;
924: }
1.273 raeburn 925: }
926: }
927:
928: function uncheckAll(field) {
929: if (field.length > 0) {
930: for (i = 0; i < field.length; i++) {
931: field[i].checked = false ;
1.543 albertel 932: }
933: } else {
1.273 raeburn 934: field.checked = false ;
935: }
936: }
937: ENDSCRT
938: return $jscript;
939: }
940:
1.656 www 941: sub select_timezone {
1.1075.2.115 raeburn 942: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
943: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 944: if ($includeempty) {
945: $output .= '<option value=""';
946: if (($selected eq '') || ($selected eq 'local')) {
947: $output .= ' selected="selected" ';
948: }
949: $output .= '> </option>';
950: }
1.657 raeburn 951: my @timezones = DateTime::TimeZone->all_names;
952: foreach my $tzone (@timezones) {
953: $output.= '<option value="'.$tzone.'"';
954: if ($tzone eq $selected) {
955: $output.=' selected="selected"';
956: }
957: $output.=">$tzone</option>\n";
1.656 www 958: }
959: $output.="</select>";
960: return $output;
961: }
1.273 raeburn 962:
1.687 raeburn 963: sub select_datelocale {
1.1075.2.115 raeburn 964: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
965: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 966: if ($includeempty) {
967: $output .= '<option value=""';
968: if ($selected eq '') {
969: $output .= ' selected="selected" ';
970: }
971: $output .= '> </option>';
972: }
1.1075.2.102 raeburn 973: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 974: my (@possibles,%locale_names);
1.1075.2.102 raeburn 975: my @locales = DateTime::Locale->ids();
976: foreach my $id (@locales) {
977: if ($id ne '') {
978: my ($en_terr,$native_terr);
979: my $loc = DateTime::Locale->load($id);
980: if (ref($loc)) {
981: $en_terr = $loc->name();
982: $native_terr = $loc->native_name();
1.687 raeburn 983: if (grep(/^en$/,@languages) || !@languages) {
984: if ($en_terr ne '') {
985: $locale_names{$id} = '('.$en_terr.')';
986: } elsif ($native_terr ne '') {
987: $locale_names{$id} = $native_terr;
988: }
989: } else {
990: if ($native_terr ne '') {
991: $locale_names{$id} = $native_terr.' ';
992: } elsif ($en_terr ne '') {
993: $locale_names{$id} = '('.$en_terr.')';
994: }
995: }
1.1075.2.94 raeburn 996: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1075.2.102 raeburn 997: push(@possibles,$id);
1.687 raeburn 998: }
999: }
1000: }
1001: foreach my $item (sort(@possibles)) {
1002: $output.= '<option value="'.$item.'"';
1003: if ($item eq $selected) {
1004: $output.=' selected="selected"';
1005: }
1006: $output.=">$item";
1007: if ($locale_names{$item} ne '') {
1.1075.2.94 raeburn 1008: $output.=' '.$locale_names{$item};
1.687 raeburn 1009: }
1010: $output.="</option>\n";
1011: }
1012: $output.="</select>";
1013: return $output;
1014: }
1015:
1.792 raeburn 1016: sub select_language {
1.1075.2.115 raeburn 1017: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1018: my %langchoices;
1019: if ($includeempty) {
1.1075.2.32 raeburn 1020: %langchoices = ('' => 'No language preference');
1.792 raeburn 1021: }
1022: foreach my $id (&languageids()) {
1023: my $code = &supportedlanguagecode($id);
1024: if ($code) {
1025: $langchoices{$code} = &plainlanguagedescription($id);
1026: }
1027: }
1.1075.2.32 raeburn 1028: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1075.2.115 raeburn 1029: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1030: }
1031:
1.42 matthew 1032: =pod
1.36 matthew 1033:
1.648 raeburn 1034: =item * &linked_select_forms(...)
1.36 matthew 1035:
1036: linked_select_forms returns a string containing a <script></script> block
1037: and html for two <select> menus. The select menus will be linked in that
1038: changing the value of the first menu will result in new values being placed
1039: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1040: order unless a defined order is provided.
1.36 matthew 1041:
1042: linked_select_forms takes the following ordered inputs:
1043:
1044: =over 4
1045:
1.112 bowersj2 1046: =item * $formname, the name of the <form> tag
1.36 matthew 1047:
1.112 bowersj2 1048: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1049:
1.112 bowersj2 1050: =item * $firstdefault, the default value for the first menu
1.36 matthew 1051:
1.112 bowersj2 1052: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1053:
1.112 bowersj2 1054: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1055:
1.112 bowersj2 1056: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1057:
1.609 raeburn 1058: =item * $menuorder, the order of values in the first menu
1059:
1.1075.2.31 raeburn 1060: =item * $onchangefirst, additional javascript call to execute for an onchange
1061: event for the first <select> tag
1062:
1063: =item * $onchangesecond, additional javascript call to execute for an onchange
1064: event for the second <select> tag
1065:
1.41 ng 1066: =back
1067:
1.36 matthew 1068: Below is an example of such a hash. Only the 'text', 'default', and
1069: 'select2' keys must appear as stated. keys(%menu) are the possible
1070: values for the first select menu. The text that coincides with the
1.41 ng 1071: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1072: and text for the second menu are given in the hash pointed to by
1073: $menu{$choice1}->{'select2'}.
1074:
1.112 bowersj2 1075: my %menu = ( A1 => { text =>"Choice A1" ,
1076: default => "B3",
1077: select2 => {
1078: B1 => "Choice B1",
1079: B2 => "Choice B2",
1080: B3 => "Choice B3",
1081: B4 => "Choice B4"
1.609 raeburn 1082: },
1083: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1084: },
1085: A2 => { text =>"Choice A2" ,
1086: default => "C2",
1087: select2 => {
1088: C1 => "Choice C1",
1089: C2 => "Choice C2",
1090: C3 => "Choice C3"
1.609 raeburn 1091: },
1092: order => ['C2','C1','C3'],
1.112 bowersj2 1093: },
1094: A3 => { text =>"Choice A3" ,
1095: default => "D6",
1096: select2 => {
1097: D1 => "Choice D1",
1098: D2 => "Choice D2",
1099: D3 => "Choice D3",
1100: D4 => "Choice D4",
1101: D5 => "Choice D5",
1102: D6 => "Choice D6",
1103: D7 => "Choice D7"
1.609 raeburn 1104: },
1105: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1106: }
1107: );
1.36 matthew 1108:
1109: =cut
1110:
1111: sub linked_select_forms {
1112: my ($formname,
1113: $middletext,
1114: $firstdefault,
1115: $firstselectname,
1116: $secondselectname,
1.609 raeburn 1117: $hashref,
1118: $menuorder,
1.1075.2.31 raeburn 1119: $onchangefirst,
1120: $onchangesecond
1.36 matthew 1121: ) = @_;
1122: my $second = "document.$formname.$secondselectname";
1123: my $first = "document.$formname.$firstselectname";
1124: # output the javascript to do the changing
1125: my $result = '';
1.776 bisitz 1126: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1127: $result.="// <![CDATA[\n";
1.36 matthew 1128: $result.="var select2data = new Object();\n";
1129: $" = '","';
1130: my $debug = '';
1131: foreach my $s1 (sort(keys(%$hashref))) {
1132: $result.="select2data.d_$s1 = new Object();\n";
1133: $result.="select2data.d_$s1.def = new String('".
1134: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1135: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1136: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1137: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1138: @s2values = @{$hashref->{$s1}->{'order'}};
1139: }
1.36 matthew 1140: $result.="\"@s2values\");\n";
1141: $result.="select2data.d_$s1.texts = new Array(";
1142: my @s2texts;
1143: foreach my $value (@s2values) {
1.1075.2.119 raeburn 1144: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1145: }
1146: $result.="\"@s2texts\");\n";
1147: }
1148: $"=' ';
1149: $result.= <<"END";
1150:
1151: function select1_changed() {
1152: // Determine new choice
1153: var newvalue = "d_" + $first.value;
1154: // update select2
1155: var values = select2data[newvalue].values;
1156: var texts = select2data[newvalue].texts;
1157: var select2def = select2data[newvalue].def;
1158: var i;
1159: // out with the old
1160: for (i = 0; i < $second.options.length; i++) {
1161: $second.options[i] = null;
1162: }
1163: // in with the nuclear
1164: for (i=0;i<values.length; i++) {
1165: $second.options[i] = new Option(values[i]);
1.143 matthew 1166: $second.options[i].value = values[i];
1.36 matthew 1167: $second.options[i].text = texts[i];
1168: if (values[i] == select2def) {
1169: $second.options[i].selected = true;
1170: }
1171: }
1172: }
1.824 bisitz 1173: // ]]>
1.36 matthew 1174: </script>
1175: END
1176: # output the initial values for the selection lists
1.1075.2.31 raeburn 1177: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1178: my @order = sort(keys(%{$hashref}));
1179: if (ref($menuorder) eq 'ARRAY') {
1180: @order = @{$menuorder};
1181: }
1182: foreach my $value (@order) {
1.36 matthew 1183: $result.=" <option value=\"$value\" ";
1.253 albertel 1184: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1185: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1186: }
1187: $result .= "</select>\n";
1188: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1189: $result .= $middletext;
1.1075.2.31 raeburn 1190: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1191: if ($onchangesecond) {
1192: $result .= ' onchange="'.$onchangesecond.'"';
1193: }
1194: $result .= ">\n";
1.36 matthew 1195: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1196:
1197: my @secondorder = sort(keys(%select2));
1198: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1199: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1200: }
1201: foreach my $value (@secondorder) {
1.36 matthew 1202: $result.=" <option value=\"$value\" ";
1.253 albertel 1203: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1204: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1205: }
1206: $result .= "</select>\n";
1207: # return $debug;
1208: return $result;
1209: } # end of sub linked_select_forms {
1210:
1.45 matthew 1211: =pod
1.44 bowersj2 1212:
1.973 raeburn 1213: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1214:
1.112 bowersj2 1215: Returns a string corresponding to an HTML link to the given help
1216: $topic, where $topic corresponds to the name of a .tex file in
1217: /home/httpd/html/adm/help/tex, with underscores replaced by
1218: spaces.
1219:
1220: $text will optionally be linked to the same topic, allowing you to
1221: link text in addition to the graphic. If you do not want to link
1222: text, but wish to specify one of the later parameters, pass an
1223: empty string.
1224:
1225: $stayOnPage is a value that will be interpreted as a boolean. If true,
1226: the link will not open a new window. If false, the link will open
1227: a new window using Javascript. (Default is false.)
1228:
1229: $width and $height are optional numerical parameters that will
1230: override the width and height of the popped up window, which may
1.973 raeburn 1231: be useful for certain help topics with big pictures included.
1232:
1233: $imgid is the id of the img tag used for the help icon. This may be
1234: used in a javascript call to switch the image src. See
1235: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1236:
1237: =cut
1238:
1239: sub help_open_topic {
1.973 raeburn 1240: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1241: $text = "" if (not defined $text);
1.44 bowersj2 1242: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1243: $width = 500 if (not defined $width);
1.44 bowersj2 1244: $height = 400 if (not defined $height);
1245: my $filename = $topic;
1246: $filename =~ s/ /_/g;
1247:
1.48 bowersj2 1248: my $template = "";
1249: my $link;
1.572 banghart 1250:
1.159 www 1251: $topic=~s/\W/\_/g;
1.44 bowersj2 1252:
1.572 banghart 1253: if (!$stayOnPage) {
1.1075.2.50 raeburn 1254: if ($env{'browser.mobile'}) {
1255: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1256: } else {
1257: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1258: }
1.1037 www 1259: } elsif ($stayOnPage eq 'popup') {
1260: $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 1261: } else {
1.48 bowersj2 1262: $link = "/adm/help/${filename}.hlp";
1263: }
1264:
1265: # Add the text
1.755 neumanie 1266: if ($text ne "") {
1.763 bisitz 1267: $template.='<span class="LC_help_open_topic">'
1268: .'<a target="_top" href="'.$link.'">'
1269: .$text.'</a>';
1.48 bowersj2 1270: }
1271:
1.763 bisitz 1272: # (Always) Add the graphic
1.179 matthew 1273: my $title = &mt('Online Help');
1.667 raeburn 1274: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1275: if ($imgid ne '') {
1276: $imgid = ' id="'.$imgid.'"';
1277: }
1.763 bisitz 1278: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1279: .'<img src="'.$helpicon.'" border="0"'
1280: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1281: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1282: .' /></a>';
1283: if ($text ne "") {
1284: $template.='</span>';
1285: }
1.44 bowersj2 1286: return $template;
1287:
1.106 bowersj2 1288: }
1289:
1290: # This is a quicky function for Latex cheatsheet editing, since it
1291: # appears in at least four places
1292: sub helpLatexCheatsheet {
1.1037 www 1293: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1294: my $out;
1.106 bowersj2 1295: my $addOther = '';
1.732 raeburn 1296: if ($topic) {
1.1037 www 1297: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1298: }
1299: $out = '<span>' # Start cheatsheet
1300: .$addOther
1301: .'<span>'
1.1037 www 1302: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1303: .'</span> <span>'
1.1037 www 1304: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1305: .'</span>';
1.732 raeburn 1306: unless ($not_author) {
1.763 bisitz 1307: $out .= ' <span>'
1.1037 www 1308: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1309: .'</span> <span>'
1.1075.2.78 raeburn 1310: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1311: .'</span>';
1.732 raeburn 1312: }
1.763 bisitz 1313: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1314: return $out;
1.172 www 1315: }
1316:
1.430 albertel 1317: sub general_help {
1318: my $helptopic='Student_Intro';
1319: if ($env{'request.role'}=~/^(ca|au)/) {
1320: $helptopic='Authoring_Intro';
1.907 raeburn 1321: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1322: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1323: } elsif ($env{'request.role'}=~/^dc/) {
1324: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1325: }
1326: return $helptopic;
1327: }
1328:
1329: sub update_help_link {
1330: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1331: my $origurl = $ENV{'REQUEST_URI'};
1332: $origurl=~s|^/~|/priv/|;
1333: my $timestamp = time;
1334: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1335: $$datum = &escape($$datum);
1336: }
1337:
1338: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1339: my $output .= <<"ENDOUTPUT";
1340: <script type="text/javascript">
1.824 bisitz 1341: // <![CDATA[
1.430 albertel 1342: banner_link = '$banner_link';
1.824 bisitz 1343: // ]]>
1.430 albertel 1344: </script>
1345: ENDOUTPUT
1346: return $output;
1347: }
1348:
1349: # now just updates the help link and generates a blue icon
1.193 raeburn 1350: sub help_open_menu {
1.430 albertel 1351: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1352: = @_;
1.949 droeschl 1353: $stayOnPage = 1;
1.430 albertel 1354: my $output;
1355: if ($component_help) {
1356: if (!$text) {
1357: $output=&help_open_topic($component_help,undef,$stayOnPage,
1358: $width,$height);
1359: } else {
1360: my $help_text;
1361: $help_text=&unescape($topic);
1362: $output='<table><tr><td>'.
1363: &help_open_topic($component_help,$help_text,$stayOnPage,
1364: $width,$height).'</td></tr></table>';
1365: }
1366: }
1367: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1368: return $output.$banner_link;
1369: }
1370:
1371: sub top_nav_help {
1372: my ($text) = @_;
1.436 albertel 1373: $text = &mt($text);
1.1075.2.60 raeburn 1374: my $stay_on_page;
1375: unless ($env{'environment.remote'} eq 'on') {
1376: $stay_on_page = 1;
1377: }
1.1075.2.61 raeburn 1378: my ($link,$banner_link);
1379: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1380: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1381: : "javascript:helpMenu('open')";
1382: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1383: }
1.201 raeburn 1384: my $title = &mt('Get help');
1.1075.2.61 raeburn 1385: if ($link) {
1386: return <<"END";
1.436 albertel 1387: $banner_link
1.1075.2.56 raeburn 1388: <a href="$link" title="$title">$text</a>
1.436 albertel 1389: END
1.1075.2.61 raeburn 1390: } else {
1391: return ' '.$text.' ';
1392: }
1.436 albertel 1393: }
1394:
1395: sub help_menu_js {
1.1075.2.52 raeburn 1396: my ($httphost) = @_;
1.949 droeschl 1397: my $stayOnPage = 1;
1.436 albertel 1398: my $width = 620;
1399: my $height = 600;
1.430 albertel 1400: my $helptopic=&general_help();
1.1075.2.52 raeburn 1401: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1402: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1403: my $start_page =
1404: &Apache::loncommon::start_page('Help Menu', undef,
1405: {'frameset' => 1,
1406: 'js_ready' => 1,
1.1075.2.136! raeburn 1407: 'use_absolute' => $httphost,
1.331 albertel 1408: 'add_entries' => {
1409: 'border' => '0',
1.579 raeburn 1410: 'rows' => "110,*",},});
1.331 albertel 1411: my $end_page =
1412: &Apache::loncommon::end_page({'frameset' => 1,
1413: 'js_ready' => 1,});
1414:
1.436 albertel 1415: my $template .= <<"ENDTEMPLATE";
1416: <script type="text/javascript">
1.877 bisitz 1417: // <![CDATA[
1.253 albertel 1418: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1419: var banner_link = '';
1.243 raeburn 1420: function helpMenu(target) {
1421: var caller = this;
1422: if (target == 'open') {
1423: var newWindow = null;
1424: try {
1.262 albertel 1425: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1426: }
1427: catch(error) {
1428: writeHelp(caller);
1429: return;
1430: }
1431: if (newWindow) {
1432: caller = newWindow;
1433: }
1.193 raeburn 1434: }
1.243 raeburn 1435: writeHelp(caller);
1436: return;
1437: }
1438: function writeHelp(caller) {
1.1075.2.61 raeburn 1439: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1440: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1441: caller.document.close();
1442: caller.focus();
1.193 raeburn 1443: }
1.877 bisitz 1444: // END LON-CAPA Internal -->
1.253 albertel 1445: // ]]>
1.436 albertel 1446: </script>
1.193 raeburn 1447: ENDTEMPLATE
1448: return $template;
1449: }
1450:
1.172 www 1451: sub help_open_bug {
1452: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1453: unless ($env{'user.adv'}) { return ''; }
1.172 www 1454: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1455: $text = "" if (not defined $text);
1456: $stayOnPage=1;
1.184 albertel 1457: $width = 600 if (not defined $width);
1458: $height = 600 if (not defined $height);
1.172 www 1459:
1460: $topic=~s/\W+/\+/g;
1461: my $link='';
1462: my $template='';
1.379 albertel 1463: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1464: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1465: if (!$stayOnPage)
1466: {
1467: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1468: }
1469: else
1470: {
1471: $link = $url;
1472: }
1473: # Add the text
1474: if ($text ne "")
1475: {
1476: $template .=
1477: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1478: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1479: }
1480:
1481: # Add the graphic
1.179 matthew 1482: my $title = &mt('Report a Bug');
1.215 albertel 1483: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1484: $template .= <<"ENDTEMPLATE";
1.436 albertel 1485: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1486: ENDTEMPLATE
1487: if ($text ne '') { $template.='</td></tr></table>' };
1488: return $template;
1489:
1490: }
1491:
1492: sub help_open_faq {
1493: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1494: unless ($env{'user.adv'}) { return ''; }
1.172 www 1495: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1496: $text = "" if (not defined $text);
1497: $stayOnPage=1;
1498: $width = 350 if (not defined $width);
1499: $height = 400 if (not defined $height);
1500:
1501: $topic=~s/\W+/\+/g;
1502: my $link='';
1503: my $template='';
1504: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1505: if (!$stayOnPage)
1506: {
1507: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1508: }
1509: else
1510: {
1511: $link = $url;
1512: }
1513:
1514: # Add the text
1515: if ($text ne "")
1516: {
1517: $template .=
1.173 www 1518: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1519: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1520: }
1521:
1522: # Add the graphic
1.179 matthew 1523: my $title = &mt('View the FAQ');
1.215 albertel 1524: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1525: $template .= <<"ENDTEMPLATE";
1.436 albertel 1526: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1527: ENDTEMPLATE
1528: if ($text ne '') { $template.='</td></tr></table>' };
1529: return $template;
1530:
1.44 bowersj2 1531: }
1.37 matthew 1532:
1.180 matthew 1533: ###############################################################
1534: ###############################################################
1535:
1.45 matthew 1536: =pod
1537:
1.648 raeburn 1538: =item * &change_content_javascript():
1.256 matthew 1539:
1540: This and the next function allow you to create small sections of an
1541: otherwise static HTML page that you can update on the fly with
1542: Javascript, even in Netscape 4.
1543:
1544: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1545: must be written to the HTML page once. It will prove the Javascript
1546: function "change(name, content)". Calling the change function with the
1547: name of the section
1548: you want to update, matching the name passed to C<changable_area>, and
1549: the new content you want to put in there, will put the content into
1550: that area.
1551:
1552: B<Note>: Netscape 4 only reserves enough space for the changable area
1553: to contain room for the original contents. You need to "make space"
1554: for whatever changes you wish to make, and be B<sure> to check your
1555: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1556: it's adequate for updating a one-line status display, but little more.
1557: This script will set the space to 100% width, so you only need to
1558: worry about height in Netscape 4.
1559:
1560: Modern browsers are much less limiting, and if you can commit to the
1561: user not using Netscape 4, this feature may be used freely with
1562: pretty much any HTML.
1563:
1564: =cut
1565:
1566: sub change_content_javascript {
1567: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1568: if ($env{'browser.type'} eq 'netscape' &&
1569: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1570: return (<<NETSCAPE4);
1571: function change(name, content) {
1572: doc = document.layers[name+"___escape"].layers[0].document;
1573: doc.open();
1574: doc.write(content);
1575: doc.close();
1576: }
1577: NETSCAPE4
1578: } else {
1579: # Otherwise, we need to use semi-standards-compliant code
1580: # (technically, "innerHTML" isn't standard but the equivalent
1581: # is really scary, and every useful browser supports it
1582: return (<<DOMBASED);
1583: function change(name, content) {
1584: element = document.getElementById(name);
1585: element.innerHTML = content;
1586: }
1587: DOMBASED
1588: }
1589: }
1590:
1591: =pod
1592:
1.648 raeburn 1593: =item * &changable_area($name,$origContent):
1.256 matthew 1594:
1595: This provides a "changable area" that can be modified on the fly via
1596: the Javascript code provided in C<change_content_javascript>. $name is
1597: the name you will use to reference the area later; do not repeat the
1598: same name on a given HTML page more then once. $origContent is what
1599: the area will originally contain, which can be left blank.
1600:
1601: =cut
1602:
1603: sub changable_area {
1604: my ($name, $origContent) = @_;
1605:
1.258 albertel 1606: if ($env{'browser.type'} eq 'netscape' &&
1607: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1608: # If this is netscape 4, we need to use the Layer tag
1609: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1610: } else {
1611: return "<span id='$name'>$origContent</span>";
1612: }
1613: }
1614:
1615: =pod
1616:
1.648 raeburn 1617: =item * &viewport_geometry_js
1.590 raeburn 1618:
1619: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1620:
1621: =cut
1622:
1623:
1624: sub viewport_geometry_js {
1625: return <<"GEOMETRY";
1626: var Geometry = {};
1627: function init_geometry() {
1628: if (Geometry.init) { return };
1629: Geometry.init=1;
1630: if (window.innerHeight) {
1631: Geometry.getViewportHeight = function() { return window.innerHeight; };
1632: Geometry.getViewportWidth = function() { return window.innerWidth; };
1633: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1634: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1635: }
1636: else if (document.documentElement && document.documentElement.clientHeight) {
1637: Geometry.getViewportHeight =
1638: function() { return document.documentElement.clientHeight; };
1639: Geometry.getViewportWidth =
1640: function() { return document.documentElement.clientWidth; };
1641:
1642: Geometry.getHorizontalScroll =
1643: function() { return document.documentElement.scrollLeft; };
1644: Geometry.getVerticalScroll =
1645: function() { return document.documentElement.scrollTop; };
1646: }
1647: else if (document.body.clientHeight) {
1648: Geometry.getViewportHeight =
1649: function() { return document.body.clientHeight; };
1650: Geometry.getViewportWidth =
1651: function() { return document.body.clientWidth; };
1652: Geometry.getHorizontalScroll =
1653: function() { return document.body.scrollLeft; };
1654: Geometry.getVerticalScroll =
1655: function() { return document.body.scrollTop; };
1656: }
1657: }
1658:
1659: GEOMETRY
1660: }
1661:
1662: =pod
1663:
1.648 raeburn 1664: =item * &viewport_size_js()
1.590 raeburn 1665:
1666: 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.
1667:
1668: =cut
1669:
1670: sub viewport_size_js {
1671: my $geometry = &viewport_geometry_js();
1672: return <<"DIMS";
1673:
1674: $geometry
1675:
1676: function getViewportDims(width,height) {
1677: init_geometry();
1678: width.value = Geometry.getViewportWidth();
1679: height.value = Geometry.getViewportHeight();
1680: return;
1681: }
1682:
1683: DIMS
1684: }
1685:
1686: =pod
1687:
1.648 raeburn 1688: =item * &resize_textarea_js()
1.565 albertel 1689:
1690: emits the needed javascript to resize a textarea to be as big as possible
1691:
1692: creates a function resize_textrea that takes two IDs first should be
1693: the id of the element to resize, second should be the id of a div that
1694: surrounds everything that comes after the textarea, this routine needs
1695: to be attached to the <body> for the onload and onresize events.
1696:
1.648 raeburn 1697: =back
1.565 albertel 1698:
1699: =cut
1700:
1701: sub resize_textarea_js {
1.590 raeburn 1702: my $geometry = &viewport_geometry_js();
1.565 albertel 1703: return <<"RESIZE";
1704: <script type="text/javascript">
1.824 bisitz 1705: // <![CDATA[
1.590 raeburn 1706: $geometry
1.565 albertel 1707:
1.588 albertel 1708: function getX(element) {
1709: var x = 0;
1710: while (element) {
1711: x += element.offsetLeft;
1712: element = element.offsetParent;
1713: }
1714: return x;
1715: }
1716: function getY(element) {
1717: var y = 0;
1718: while (element) {
1719: y += element.offsetTop;
1720: element = element.offsetParent;
1721: }
1722: return y;
1723: }
1724:
1725:
1.565 albertel 1726: function resize_textarea(textarea_id,bottom_id) {
1727: init_geometry();
1728: var textarea = document.getElementById(textarea_id);
1729: //alert(textarea);
1730:
1.588 albertel 1731: var textarea_top = getY(textarea);
1.565 albertel 1732: var textarea_height = textarea.offsetHeight;
1733: var bottom = document.getElementById(bottom_id);
1.588 albertel 1734: var bottom_top = getY(bottom);
1.565 albertel 1735: var bottom_height = bottom.offsetHeight;
1736: var window_height = Geometry.getViewportHeight();
1.588 albertel 1737: var fudge = 23;
1.565 albertel 1738: var new_height = window_height-fudge-textarea_top-bottom_height;
1739: if (new_height < 300) {
1740: new_height = 300;
1741: }
1742: textarea.style.height=new_height+'px';
1743: }
1.824 bisitz 1744: // ]]>
1.565 albertel 1745: </script>
1746: RESIZE
1747:
1748: }
1749:
1.1075.2.112 raeburn 1750: sub colorfuleditor_js {
1751: return <<"COLORFULEDIT"
1752: <script type="text/javascript">
1753: // <![CDATA[>
1754: function fold_box(curDepth, lastresource){
1755:
1756: // we need a list because there can be several blocks you need to fold in one tag
1757: var block = document.getElementsByName('foldblock_'+curDepth);
1758: // but there is only one folding button per tag
1759: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1760:
1761: if(block.item(0).style.display == 'none'){
1762:
1763: foldbutton.value = '@{[&mt("Hide")]}';
1764: for (i = 0; i < block.length; i++){
1765: block.item(i).style.display = '';
1766: }
1767: }else{
1768:
1769: foldbutton.value = '@{[&mt("Show")]}';
1770: for (i = 0; i < block.length; i++){
1771: // block.item(i).style.visibility = 'collapse';
1772: block.item(i).style.display = 'none';
1773: }
1774: };
1775: saveState(lastresource);
1776: }
1777:
1778: function saveState (lastresource) {
1779:
1780: var tag_list = getTagList();
1781: if(tag_list != null){
1782: var timestamp = new Date().getTime();
1783: var key = lastresource;
1784:
1785: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1786: // starting with timestamp
1787: var value = timestamp+';';
1788:
1789: // building the list of key-value pairs
1790: for(var i = 0; i < tag_list.length; i++){
1791: value += tag_list[i]+',';
1792: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1793: }
1794:
1795: // only iterate whole storage if nothing to override
1796: if(localStorage.getItem(key) == null){
1797:
1798: // prevent storage from growing large
1799: if(localStorage.length > 50){
1800: var regex_getTimestamp = /^(?:\d)+;/;
1801: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1802: var oldest_key;
1803:
1804: for(var i = 1; i < localStorage.length; i++){
1805: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1806: oldest_key = localStorage.key(i);
1807: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1808: }
1809: }
1810: localStorage.removeItem(oldest_key);
1811: }
1812: }
1813: localStorage.setItem(key,value);
1814: }
1815: }
1816:
1817: // restore folding status of blocks (on page load)
1818: function restoreState (lastresource) {
1819: if(localStorage.getItem(lastresource) != null){
1820: var key = lastresource;
1821: var value = localStorage.getItem(key);
1822: var regex_delTimestamp = /^\d+;/;
1823:
1824: value.replace(regex_delTimestamp, '');
1825:
1826: var valueArr = value.split(';');
1827: var pairs;
1828: var elements;
1829: for (var i = 0; i < valueArr.length; i++){
1830: pairs = valueArr[i].split(',');
1831: elements = document.getElementsByName(pairs[0]);
1832:
1833: for (var j = 0; j < elements.length; j++){
1834: elements[j].style.display = pairs[1];
1835: if (pairs[1] == "none"){
1836: var regex_id = /([_\\d]+)\$/;
1837: regex_id.exec(pairs[0]);
1838: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1839: }
1840: }
1841: }
1842: }
1843: }
1844:
1845: function getTagList () {
1846:
1847: var stringToSearch = document.lonhomework.innerHTML;
1848:
1849: var ret = new Array();
1850: var regex_findBlock = /(foldblock_.*?)"/g;
1851: var tag_list = stringToSearch.match(regex_findBlock);
1852:
1853: if(tag_list != null){
1854: for(var i = 0; i < tag_list.length; i++){
1855: ret.push(tag_list[i].replace(/"/, ''));
1856: }
1857: }
1858: return ret;
1859: }
1860:
1861: function saveScrollPosition (resource) {
1862: var tag_list = getTagList();
1863:
1864: // we dont always want to jump to the first block
1865: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1866: if(\$(window).scrollTop() > 170){
1867: if(tag_list != null){
1868: var result;
1869: for(var i = 0; i < tag_list.length; i++){
1870: if(isElementInViewport(tag_list[i])){
1871: result += tag_list[i]+';';
1872: }
1873: }
1874: sessionStorage.setItem('anchor_'+resource, result);
1875: }
1876: } else {
1877: // we dont need to save zero, just delete the item to leave everything tidy
1878: sessionStorage.removeItem('anchor_'+resource);
1879: }
1880: }
1881:
1882: function restoreScrollPosition(resource){
1883:
1884: var elem = sessionStorage.getItem('anchor_'+resource);
1885: if(elem != null){
1886: var tag_list = elem.split(';');
1887: var elem_list;
1888:
1889: for(var i = 0; i < tag_list.length; i++){
1890: elem_list = document.getElementsByName(tag_list[i]);
1891:
1892: if(elem_list.length > 0){
1893: elem = elem_list[0];
1894: break;
1895: }
1896: }
1897: elem.scrollIntoView();
1898: }
1899: }
1900:
1901: function isElementInViewport(el) {
1902:
1903: // change to last element instead of first
1904: var elem = document.getElementsByName(el);
1905: var rect = elem[0].getBoundingClientRect();
1906:
1907: return (
1908: rect.top >= 0 &&
1909: rect.left >= 0 &&
1910: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1911: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1912: );
1913: }
1914:
1915: function autosize(depth){
1916: var cmInst = window['cm'+depth];
1917: var fitsizeButton = document.getElementById('fitsize'+depth);
1918:
1919: // is fixed size, switching to dynamic
1920: if (sessionStorage.getItem("autosized_"+depth) == null) {
1921: cmInst.setSize("","auto");
1922: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1923: sessionStorage.setItem("autosized_"+depth, "yes");
1924:
1925: // is dynamic size, switching to fixed
1926: } else {
1927: cmInst.setSize("","300px");
1928: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1929: sessionStorage.removeItem("autosized_"+depth);
1930: }
1931: }
1932:
1933:
1934:
1935: // ]]>
1936: </script>
1937: COLORFULEDIT
1938: }
1939:
1940: sub xmleditor_js {
1941: return <<XMLEDIT
1942: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1943: <script type="text/javascript">
1944: // <![CDATA[>
1945:
1946: function saveScrollPosition (resource) {
1947:
1948: var scrollPos = \$(window).scrollTop();
1949: sessionStorage.setItem(resource,scrollPos);
1950: }
1951:
1952: function restoreScrollPosition(resource){
1953:
1954: var scrollPos = sessionStorage.getItem(resource);
1955: \$(window).scrollTop(scrollPos);
1956: }
1957:
1958: // unless internet explorer
1959: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1960:
1961: \$(document).ready(function() {
1962: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1963: });
1964: }
1965:
1966: // inserts text at cursor position into codemirror (xml editor only)
1967: function insertText(text){
1968: cm.focus();
1969: var curPos = cm.getCursor();
1970: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
1971: }
1972: // ]]>
1973: </script>
1974: XMLEDIT
1975: }
1976:
1977: sub insert_folding_button {
1978: my $curDepth = $Apache::lonxml::curdepth;
1979: my $lastresource = $env{'request.ambiguous'};
1980:
1981: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
1982: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
1983: }
1984:
1985:
1.565 albertel 1986: =pod
1987:
1.256 matthew 1988: =head1 Excel and CSV file utility routines
1989:
1990: =cut
1991:
1992: ###############################################################
1993: ###############################################################
1994:
1995: =pod
1996:
1.1075.2.56 raeburn 1997: =over 4
1998:
1.648 raeburn 1999: =item * &csv_translate($text)
1.37 matthew 2000:
1.185 www 2001: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2002: format.
2003:
2004: =cut
2005:
1.180 matthew 2006: ###############################################################
2007: ###############################################################
1.37 matthew 2008: sub csv_translate {
2009: my $text = shift;
2010: $text =~ s/\"/\"\"/g;
1.209 albertel 2011: $text =~ s/\n/ /g;
1.37 matthew 2012: return $text;
2013: }
1.180 matthew 2014:
2015: ###############################################################
2016: ###############################################################
2017:
2018: =pod
2019:
1.648 raeburn 2020: =item * &define_excel_formats()
1.180 matthew 2021:
2022: Define some commonly used Excel cell formats.
2023:
2024: Currently supported formats:
2025:
2026: =over 4
2027:
2028: =item header
2029:
2030: =item bold
2031:
2032: =item h1
2033:
2034: =item h2
2035:
2036: =item h3
2037:
1.256 matthew 2038: =item h4
2039:
2040: =item i
2041:
1.180 matthew 2042: =item date
2043:
2044: =back
2045:
2046: Inputs: $workbook
2047:
2048: Returns: $format, a hash reference.
2049:
1.1057 foxr 2050:
1.180 matthew 2051: =cut
2052:
2053: ###############################################################
2054: ###############################################################
2055: sub define_excel_formats {
2056: my ($workbook) = @_;
2057: my $format;
2058: $format->{'header'} = $workbook->add_format(bold => 1,
2059: bottom => 1,
2060: align => 'center');
2061: $format->{'bold'} = $workbook->add_format(bold=>1);
2062: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2063: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2064: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2065: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2066: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2067: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2068: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2069: return $format;
2070: }
2071:
2072: ###############################################################
2073: ###############################################################
1.113 bowersj2 2074:
2075: =pod
2076:
1.648 raeburn 2077: =item * &create_workbook()
1.255 matthew 2078:
2079: Create an Excel worksheet. If it fails, output message on the
2080: request object and return undefs.
2081:
2082: Inputs: Apache request object
2083:
2084: Returns (undef) on failure,
2085: Excel worksheet object, scalar with filename, and formats
2086: from &Apache::loncommon::define_excel_formats on success
2087:
2088: =cut
2089:
2090: ###############################################################
2091: ###############################################################
2092: sub create_workbook {
2093: my ($r) = @_;
2094: #
2095: # Create the excel spreadsheet
2096: my $filename = '/prtspool/'.
1.258 albertel 2097: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2098: time.'_'.rand(1000000000).'.xls';
2099: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2100: if (! defined($workbook)) {
2101: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2102: $r->print(
2103: '<p class="LC_error">'
2104: .&mt('Problems occurred in creating the new Excel file.')
2105: .' '.&mt('This error has been logged.')
2106: .' '.&mt('Please alert your LON-CAPA administrator.')
2107: .'</p>'
2108: );
1.255 matthew 2109: return (undef);
2110: }
2111: #
1.1014 foxr 2112: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2113: #
2114: my $format = &Apache::loncommon::define_excel_formats($workbook);
2115: return ($workbook,$filename,$format);
2116: }
2117:
2118: ###############################################################
2119: ###############################################################
2120:
2121: =pod
2122:
1.648 raeburn 2123: =item * &create_text_file()
1.113 bowersj2 2124:
1.542 raeburn 2125: Create a file to write to and eventually make available to the user.
1.256 matthew 2126: If file creation fails, outputs an error message on the request object and
2127: return undefs.
1.113 bowersj2 2128:
1.256 matthew 2129: Inputs: Apache request object, and file suffix
1.113 bowersj2 2130:
1.256 matthew 2131: Returns (undef) on failure,
2132: Filehandle and filename on success.
1.113 bowersj2 2133:
2134: =cut
2135:
1.256 matthew 2136: ###############################################################
2137: ###############################################################
2138: sub create_text_file {
2139: my ($r,$suffix) = @_;
2140: if (! defined($suffix)) { $suffix = 'txt'; };
2141: my $fh;
2142: my $filename = '/prtspool/'.
1.258 albertel 2143: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2144: time.'_'.rand(1000000000).'.'.$suffix;
2145: $fh = Apache::File->new('>/home/httpd'.$filename);
2146: if (! defined($fh)) {
2147: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2148: $r->print(
2149: '<p class="LC_error">'
2150: .&mt('Problems occurred in creating the output file.')
2151: .' '.&mt('This error has been logged.')
2152: .' '.&mt('Please alert your LON-CAPA administrator.')
2153: .'</p>'
2154: );
1.113 bowersj2 2155: }
1.256 matthew 2156: return ($fh,$filename)
1.113 bowersj2 2157: }
2158:
2159:
1.256 matthew 2160: =pod
1.113 bowersj2 2161:
2162: =back
2163:
2164: =cut
1.37 matthew 2165:
2166: ###############################################################
1.33 matthew 2167: ## Home server <option> list generating code ##
2168: ###############################################################
1.35 matthew 2169:
1.169 www 2170: # ------------------------------------------
2171:
2172: sub domain_select {
2173: my ($name,$value,$multiple)=@_;
2174: my %domains=map {
1.514 albertel 2175: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2176: } &Apache::lonnet::all_domains();
1.169 www 2177: if ($multiple) {
2178: $domains{''}=&mt('Any domain');
1.550 albertel 2179: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2180: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2181: } else {
1.550 albertel 2182: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2183: return &select_form($name,$value,\%domains);
1.169 www 2184: }
2185: }
2186:
1.282 albertel 2187: #-------------------------------------------
2188:
2189: =pod
2190:
1.519 raeburn 2191: =head1 Routines for form select boxes
2192:
2193: =over 4
2194:
1.648 raeburn 2195: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2196:
2197: Returns a string containing a <select> element int multiple mode
2198:
2199:
2200: Args:
2201: $name - name of the <select> element
1.506 raeburn 2202: $value - scalar or array ref of values that should already be selected
1.282 albertel 2203: $size - number of rows long the select element is
1.283 albertel 2204: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2205: (shown text should already have been &mt())
1.506 raeburn 2206: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2207:
1.282 albertel 2208: =cut
2209:
2210: #-------------------------------------------
1.169 www 2211: sub multiple_select_form {
1.284 albertel 2212: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2213: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2214: my $output='';
1.191 matthew 2215: if (! defined($size)) {
2216: $size = 4;
1.283 albertel 2217: if (scalar(keys(%$hash))<4) {
2218: $size = scalar(keys(%$hash));
1.191 matthew 2219: }
2220: }
1.734 bisitz 2221: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2222: my @order;
1.506 raeburn 2223: if (ref($order) eq 'ARRAY') {
2224: @order = @{$order};
2225: } else {
2226: @order = sort(keys(%$hash));
1.501 banghart 2227: }
2228: if (exists($$hash{'select_form_order'})) {
2229: @order = @{$$hash{'select_form_order'}};
2230: }
2231:
1.284 albertel 2232: foreach my $key (@order) {
1.356 albertel 2233: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2234: $output.='selected="selected" ' if ($selected{$key});
2235: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2236: }
2237: $output.="</select>\n";
2238: return $output;
2239: }
2240:
1.88 www 2241: #-------------------------------------------
2242:
2243: =pod
2244:
1.1075.2.115 raeburn 2245: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2246:
2247: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2248: allow a user to select options from a ref to a hash containing:
2249: option_name => displayed text. An optional $onchange can include
1.1075.2.115 raeburn 2250: a javascript onchange item, e.g., onchange="this.form.submit();".
2251: An optional arg -- $readonly -- if true will cause the select form
2252: to be disabled, e.g., for the case where an instructor has a section-
2253: specific role, and is viewing/modifying parameters.
1.970 raeburn 2254:
1.88 www 2255: See lonrights.pm for an example invocation and use.
2256:
2257: =cut
2258:
2259: #-------------------------------------------
2260: sub select_form {
1.1075.2.115 raeburn 2261: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2262: return unless (ref($hashref) eq 'HASH');
2263: if ($onchange) {
2264: $onchange = ' onchange="'.$onchange.'"';
2265: }
1.1075.2.129 raeburn 2266: my $disabled;
2267: if ($readonly) {
2268: $disabled = ' disabled="disabled"';
2269: }
2270: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2271: my @keys;
1.970 raeburn 2272: if (exists($hashref->{'select_form_order'})) {
2273: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2274: } else {
1.970 raeburn 2275: @keys=sort(keys(%{$hashref}));
1.128 albertel 2276: }
1.356 albertel 2277: foreach my $key (@keys) {
2278: $selectform.=
2279: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2280: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2281: ">".$hashref->{$key}."</option>\n";
1.88 www 2282: }
2283: $selectform.="</select>";
2284: return $selectform;
2285: }
2286:
1.475 www 2287: # For display filters
2288:
2289: sub display_filter {
1.1074 raeburn 2290: my ($context) = @_;
1.475 www 2291: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2292: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2293: my $phraseinput = 'hidden';
2294: my $includeinput = 'hidden';
2295: my ($checked,$includetypestext);
2296: if ($env{'form.displayfilter'} eq 'containing') {
2297: $phraseinput = 'text';
2298: if ($context eq 'parmslog') {
2299: $includeinput = 'checkbox';
2300: if ($env{'form.includetypes'}) {
2301: $checked = ' checked="checked"';
2302: }
2303: $includetypestext = &mt('Include parameter types');
2304: }
2305: } else {
2306: $includetypestext = ' ';
2307: }
2308: my ($additional,$secondid,$thirdid);
2309: if ($context eq 'parmslog') {
2310: $additional =
2311: '<label><input type="'.$includeinput.'" name="includetypes"'.
2312: $checked.' name="includetypes" value="1" id="includetypes" />'.
2313: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2314: '</label>';
2315: $secondid = 'includetypes';
2316: $thirdid = 'includetypestext';
2317: }
2318: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2319: '$secondid','$thirdid')";
2320: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2321: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2322: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2323: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2324: &mt('Filter: [_1]',
1.477 www 2325: &select_form($env{'form.displayfilter'},
2326: 'displayfilter',
1.970 raeburn 2327: {'currentfolder' => 'Current folder/page',
1.477 www 2328: 'containing' => 'Containing phrase',
1.1074 raeburn 2329: 'none' => 'None'},$onchange)).' '.
2330: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2331: &HTML::Entities::encode($env{'form.containingphrase'}).
2332: '" />'.$additional;
2333: }
2334:
2335: sub display_filter_js {
2336: my $includetext = &mt('Include parameter types');
2337: return <<"ENDJS";
2338:
2339: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2340: var firstType = 'hidden';
2341: if (setter.options[setter.selectedIndex].value == 'containing') {
2342: firstType = 'text';
2343: }
2344: firstObject = document.getElementById(firstid);
2345: if (typeof(firstObject) == 'object') {
2346: if (firstObject.type != firstType) {
2347: changeInputType(firstObject,firstType);
2348: }
2349: }
2350: if (context == 'parmslog') {
2351: var secondType = 'hidden';
2352: if (firstType == 'text') {
2353: secondType = 'checkbox';
2354: }
2355: secondObject = document.getElementById(secondid);
2356: if (typeof(secondObject) == 'object') {
2357: if (secondObject.type != secondType) {
2358: changeInputType(secondObject,secondType);
2359: }
2360: }
2361: var textItem = document.getElementById(thirdid);
2362: var currtext = textItem.innerHTML;
2363: var newtext;
2364: if (firstType == 'text') {
2365: newtext = '$includetext';
2366: } else {
2367: newtext = ' ';
2368: }
2369: if (currtext != newtext) {
2370: textItem.innerHTML = newtext;
2371: }
2372: }
2373: return;
2374: }
2375:
2376: function changeInputType(oldObject,newType) {
2377: var newObject = document.createElement('input');
2378: newObject.type = newType;
2379: if (oldObject.size) {
2380: newObject.size = oldObject.size;
2381: }
2382: if (oldObject.value) {
2383: newObject.value = oldObject.value;
2384: }
2385: if (oldObject.name) {
2386: newObject.name = oldObject.name;
2387: }
2388: if (oldObject.id) {
2389: newObject.id = oldObject.id;
2390: }
2391: oldObject.parentNode.replaceChild(newObject,oldObject);
2392: return;
2393: }
2394:
2395: ENDJS
1.475 www 2396: }
2397:
1.167 www 2398: sub gradeleveldescription {
2399: my $gradelevel=shift;
2400: my %gradelevels=(0 => 'Not specified',
2401: 1 => 'Grade 1',
2402: 2 => 'Grade 2',
2403: 3 => 'Grade 3',
2404: 4 => 'Grade 4',
2405: 5 => 'Grade 5',
2406: 6 => 'Grade 6',
2407: 7 => 'Grade 7',
2408: 8 => 'Grade 8',
2409: 9 => 'Grade 9',
2410: 10 => 'Grade 10',
2411: 11 => 'Grade 11',
2412: 12 => 'Grade 12',
2413: 13 => 'Grade 13',
2414: 14 => '100 Level',
2415: 15 => '200 Level',
2416: 16 => '300 Level',
2417: 17 => '400 Level',
2418: 18 => 'Graduate Level');
2419: return &mt($gradelevels{$gradelevel});
2420: }
2421:
1.163 www 2422: sub select_level_form {
2423: my ($deflevel,$name)=@_;
2424: unless ($deflevel) { $deflevel=0; }
1.167 www 2425: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2426: for (my $i=0; $i<=18; $i++) {
2427: $selectform.="<option value=\"$i\" ".
1.253 albertel 2428: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2429: ">".&gradeleveldescription($i)."</option>\n";
2430: }
2431: $selectform.="</select>";
2432: return $selectform;
1.163 www 2433: }
1.167 www 2434:
1.35 matthew 2435: #-------------------------------------------
2436:
1.45 matthew 2437: =pod
2438:
1.1075.2.115 raeburn 2439: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2440:
2441: Returns a string containing a <select name='$name' size='1'> form to
2442: allow a user to select the domain to preform an operation in.
2443: See loncreateuser.pm for an example invocation and use.
2444:
1.90 www 2445: If the $includeempty flag is set, it also includes an empty choice ("no domain
2446: selected");
2447:
1.743 raeburn 2448: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2449:
1.910 raeburn 2450: 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.
2451:
1.1075.2.36 raeburn 2452: The optional $incdoms is a reference to an array of domains which will be the only available options.
2453:
1.1075.2.115 raeburn 2454: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
2455:
2456: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
1.563 raeburn 2457:
1.35 matthew 2458: =cut
2459:
2460: #-------------------------------------------
1.34 matthew 2461: sub select_dom_form {
1.1075.2.115 raeburn 2462: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2463: if ($onchange) {
1.874 raeburn 2464: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2465: }
1.1075.2.115 raeburn 2466: if ($disabled) {
2467: $disabled = ' disabled="disabled"';
2468: }
1.1075.2.36 raeburn 2469: my (@domains,%exclude);
1.910 raeburn 2470: if (ref($incdoms) eq 'ARRAY') {
2471: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2472: } else {
2473: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2474: }
1.90 www 2475: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2476: if (ref($excdoms) eq 'ARRAY') {
2477: map { $exclude{$_} = 1; } @{$excdoms};
2478: }
1.1075.2.115 raeburn 2479: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2480: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2481: next if ($exclude{$dom});
1.356 albertel 2482: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2483: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2484: if ($showdomdesc) {
2485: if ($dom ne '') {
2486: my $domdesc = &Apache::lonnet::domain($dom,'description');
2487: if ($domdesc ne '') {
2488: $selectdomain .= ' ('.$domdesc.')';
2489: }
2490: }
2491: }
2492: $selectdomain .= "</option>\n";
1.34 matthew 2493: }
2494: $selectdomain.="</select>";
2495: return $selectdomain;
2496: }
2497:
1.35 matthew 2498: #-------------------------------------------
2499:
1.45 matthew 2500: =pod
2501:
1.648 raeburn 2502: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2503:
1.586 raeburn 2504: input: 4 arguments (two required, two optional) -
2505: $domain - domain of new user
2506: $name - name of form element
2507: $default - Value of 'default' causes a default item to be first
2508: option, and selected by default.
2509: $hide - Value of 'hide' causes hiding of the name of the server,
2510: if 1 server found, or default, if 0 found.
1.594 raeburn 2511: output: returns 2 items:
1.586 raeburn 2512: (a) form element which contains either:
2513: (i) <select name="$name">
2514: <option value="$hostid1">$hostid $servers{$hostid}</option>
2515: <option value="$hostid2">$hostid $servers{$hostid}</option>
2516: </select>
2517: form item if there are multiple library servers in $domain, or
2518: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2519: if there is only one library server in $domain.
2520:
2521: (b) number of library servers found.
2522:
2523: See loncreateuser.pm for example of use.
1.35 matthew 2524:
2525: =cut
2526:
2527: #-------------------------------------------
1.586 raeburn 2528: sub home_server_form_item {
2529: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2530: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2531: my $result;
2532: my $numlib = keys(%servers);
2533: if ($numlib > 1) {
2534: $result .= '<select name="'.$name.'" />'."\n";
2535: if ($default) {
1.804 bisitz 2536: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2537: '</option>'."\n";
2538: }
2539: foreach my $hostid (sort(keys(%servers))) {
2540: $result.= '<option value="'.$hostid.'">'.
2541: $hostid.' '.$servers{$hostid}."</option>\n";
2542: }
2543: $result .= '</select>'."\n";
2544: } elsif ($numlib == 1) {
2545: my $hostid;
2546: foreach my $item (keys(%servers)) {
2547: $hostid = $item;
2548: }
2549: $result .= '<input type="hidden" name="'.$name.'" value="'.
2550: $hostid.'" />';
2551: if (!$hide) {
2552: $result .= $hostid.' '.$servers{$hostid};
2553: }
2554: $result .= "\n";
2555: } elsif ($default) {
2556: $result .= '<input type="hidden" name="'.$name.
2557: '" value="default" />';
2558: if (!$hide) {
2559: $result .= &mt('default');
2560: }
2561: $result .= "\n";
1.33 matthew 2562: }
1.586 raeburn 2563: return ($result,$numlib);
1.33 matthew 2564: }
1.112 bowersj2 2565:
2566: =pod
2567:
1.534 albertel 2568: =back
2569:
1.112 bowersj2 2570: =cut
1.87 matthew 2571:
2572: ###############################################################
1.112 bowersj2 2573: ## Decoding User Agent ##
1.87 matthew 2574: ###############################################################
2575:
2576: =pod
2577:
1.112 bowersj2 2578: =head1 Decoding the User Agent
2579:
2580: =over 4
2581:
2582: =item * &decode_user_agent()
1.87 matthew 2583:
2584: Inputs: $r
2585:
2586: Outputs:
2587:
2588: =over 4
2589:
1.112 bowersj2 2590: =item * $httpbrowser
1.87 matthew 2591:
1.112 bowersj2 2592: =item * $clientbrowser
1.87 matthew 2593:
1.112 bowersj2 2594: =item * $clientversion
1.87 matthew 2595:
1.112 bowersj2 2596: =item * $clientmathml
1.87 matthew 2597:
1.112 bowersj2 2598: =item * $clientunicode
1.87 matthew 2599:
1.112 bowersj2 2600: =item * $clientos
1.87 matthew 2601:
1.1075.2.42 raeburn 2602: =item * $clientmobile
2603:
2604: =item * $clientinfo
2605:
1.1075.2.77 raeburn 2606: =item * $clientosversion
2607:
1.87 matthew 2608: =back
2609:
1.157 matthew 2610: =back
2611:
1.87 matthew 2612: =cut
2613:
2614: ###############################################################
2615: ###############################################################
2616: sub decode_user_agent {
1.247 albertel 2617: my ($r)=@_;
1.87 matthew 2618: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2619: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2620: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2621: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2622: my $clientbrowser='unknown';
2623: my $clientversion='0';
2624: my $clientmathml='';
2625: my $clientunicode='0';
1.1075.2.42 raeburn 2626: my $clientmobile=0;
1.1075.2.77 raeburn 2627: my $clientosversion='';
1.87 matthew 2628: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2629: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2630: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2631: $clientbrowser=$bname;
2632: $httpbrowser=~/$vreg/i;
2633: $clientversion=$1;
2634: $clientmathml=($clientversion>=$minv);
2635: $clientunicode=($clientversion>=$univ);
2636: }
2637: }
2638: my $clientos='unknown';
1.1075.2.42 raeburn 2639: my $clientinfo;
1.87 matthew 2640: if (($httpbrowser=~/linux/i) ||
2641: ($httpbrowser=~/unix/i) ||
2642: ($httpbrowser=~/ux/i) ||
2643: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2644: if (($httpbrowser=~/vax/i) ||
2645: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2646: if ($httpbrowser=~/next/i) { $clientos='next'; }
2647: if (($httpbrowser=~/mac/i) ||
2648: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2649: if ($httpbrowser=~/win/i) {
2650: $clientos='win';
2651: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2652: $clientosversion = $1;
2653: }
2654: }
1.87 matthew 2655: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2656: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2657: $clientmobile=lc($1);
2658: }
2659: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2660: $clientinfo = 'firefox-'.$1;
2661: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2662: $clientinfo = 'chromeframe-'.$1;
2663: }
1.87 matthew 2664: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2665: $clientunicode,$clientos,$clientmobile,$clientinfo,
2666: $clientosversion);
1.87 matthew 2667: }
2668:
1.32 matthew 2669: ###############################################################
2670: ## Authentication changing form generation subroutines ##
2671: ###############################################################
2672: ##
2673: ## All of the authform_xxxxxxx subroutines take their inputs in a
2674: ## hash, and have reasonable default values.
2675: ##
2676: ## formname = the name given in the <form> tag.
1.35 matthew 2677: #-------------------------------------------
2678:
1.45 matthew 2679: =pod
2680:
1.112 bowersj2 2681: =head1 Authentication Routines
2682:
2683: =over 4
2684:
1.648 raeburn 2685: =item * &authform_xxxxxx()
1.35 matthew 2686:
2687: The authform_xxxxxx subroutines provide javascript and html forms which
2688: handle some of the conveniences required for authentication forms.
2689: This is not an optimal method, but it works.
2690:
2691: =over 4
2692:
1.112 bowersj2 2693: =item * authform_header
1.35 matthew 2694:
1.112 bowersj2 2695: =item * authform_authorwarning
1.35 matthew 2696:
1.112 bowersj2 2697: =item * authform_nochange
1.35 matthew 2698:
1.112 bowersj2 2699: =item * authform_kerberos
1.35 matthew 2700:
1.112 bowersj2 2701: =item * authform_internal
1.35 matthew 2702:
1.112 bowersj2 2703: =item * authform_filesystem
1.35 matthew 2704:
2705: =back
2706:
1.648 raeburn 2707: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2708:
1.35 matthew 2709: =cut
2710:
2711: #-------------------------------------------
1.32 matthew 2712: sub authform_header{
2713: my %in = (
2714: formname => 'cu',
1.80 albertel 2715: kerb_def_dom => '',
1.32 matthew 2716: @_,
2717: );
2718: $in{'formname'} = 'document.' . $in{'formname'};
2719: my $result='';
1.80 albertel 2720:
2721: #---------------------------------------------- Code for upper case translation
2722: my $Javascript_toUpperCase;
2723: unless ($in{kerb_def_dom}) {
2724: $Javascript_toUpperCase =<<"END";
2725: switch (choice) {
2726: case 'krb': currentform.elements[choicearg].value =
2727: currentform.elements[choicearg].value.toUpperCase();
2728: break;
2729: default:
2730: }
2731: END
2732: } else {
2733: $Javascript_toUpperCase = "";
2734: }
2735:
1.165 raeburn 2736: my $radioval = "'nochange'";
1.591 raeburn 2737: if (defined($in{'curr_authtype'})) {
2738: if ($in{'curr_authtype'} ne '') {
2739: $radioval = "'".$in{'curr_authtype'}."arg'";
2740: }
1.174 matthew 2741: }
1.165 raeburn 2742: my $argfield = 'null';
1.591 raeburn 2743: if (defined($in{'mode'})) {
1.165 raeburn 2744: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2745: if (defined($in{'curr_autharg'})) {
2746: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2747: $argfield = "'$in{'curr_autharg'}'";
2748: }
2749: }
2750: }
2751: }
2752:
1.32 matthew 2753: $result.=<<"END";
2754: var current = new Object();
1.165 raeburn 2755: current.radiovalue = $radioval;
2756: current.argfield = $argfield;
1.32 matthew 2757:
2758: function changed_radio(choice,currentform) {
2759: var choicearg = choice + 'arg';
2760: // If a radio button in changed, we need to change the argfield
2761: if (current.radiovalue != choice) {
2762: current.radiovalue = choice;
2763: if (current.argfield != null) {
2764: currentform.elements[current.argfield].value = '';
2765: }
2766: if (choice == 'nochange') {
2767: current.argfield = null;
2768: } else {
2769: current.argfield = choicearg;
2770: switch(choice) {
2771: case 'krb':
2772: currentform.elements[current.argfield].value =
2773: "$in{'kerb_def_dom'}";
2774: break;
2775: default:
2776: break;
2777: }
2778: }
2779: }
2780: return;
2781: }
1.22 www 2782:
1.32 matthew 2783: function changed_text(choice,currentform) {
2784: var choicearg = choice + 'arg';
2785: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2786: $Javascript_toUpperCase
1.32 matthew 2787: // clear old field
2788: if ((current.argfield != choicearg) && (current.argfield != null)) {
2789: currentform.elements[current.argfield].value = '';
2790: }
2791: current.argfield = choicearg;
2792: }
2793: set_auth_radio_buttons(choice,currentform);
2794: return;
1.20 www 2795: }
1.32 matthew 2796:
2797: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2798: var numauthchoices = currentform.login.length;
2799: if (typeof numauthchoices == "undefined") {
2800: return;
2801: }
1.32 matthew 2802: var i=0;
1.986 raeburn 2803: while (i < numauthchoices) {
1.32 matthew 2804: if (currentform.login[i].value == newvalue) { break; }
2805: i++;
2806: }
1.986 raeburn 2807: if (i == numauthchoices) {
1.32 matthew 2808: return;
2809: }
2810: current.radiovalue = newvalue;
2811: currentform.login[i].checked = true;
2812: return;
2813: }
2814: END
2815: return $result;
2816: }
2817:
1.1075.2.20 raeburn 2818: sub authform_authorwarning {
1.32 matthew 2819: my $result='';
1.144 matthew 2820: $result='<i>'.
2821: &mt('As a general rule, only authors or co-authors should be '.
2822: 'filesystem authenticated '.
2823: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2824: return $result;
2825: }
2826:
1.1075.2.20 raeburn 2827: sub authform_nochange {
1.32 matthew 2828: my %in = (
2829: formname => 'document.cu',
2830: kerb_def_dom => 'MSU.EDU',
2831: @_,
2832: );
1.1075.2.20 raeburn 2833: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2834: my $result;
1.1075.2.20 raeburn 2835: if (!$authnum) {
2836: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2837: } else {
2838: $result = '<label>'.&mt('[_1] Do not change login data',
2839: '<input type="radio" name="login" value="nochange" '.
2840: 'checked="checked" onclick="'.
1.281 albertel 2841: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2842: '</label>';
1.586 raeburn 2843: }
1.32 matthew 2844: return $result;
2845: }
2846:
1.591 raeburn 2847: sub authform_kerberos {
1.32 matthew 2848: my %in = (
2849: formname => 'document.cu',
2850: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2851: kerb_def_auth => 'krb4',
1.32 matthew 2852: @_,
2853: );
1.586 raeburn 2854: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1075.2.117 raeburn 2855: $autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2856: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2857: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2858: $check5 = ' checked="checked"';
1.80 albertel 2859: } else {
1.772 bisitz 2860: $check4 = ' checked="checked"';
1.80 albertel 2861: }
1.1075.2.117 raeburn 2862: if ($in{'readonly'}) {
2863: $disabled = ' disabled="disabled"';
2864: }
1.165 raeburn 2865: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2866: if (defined($in{'curr_authtype'})) {
2867: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2868: $krbcheck = ' checked="checked"';
1.623 raeburn 2869: if (defined($in{'mode'})) {
2870: if ($in{'mode'} eq 'modifyuser') {
2871: $krbcheck = '';
2872: }
2873: }
1.591 raeburn 2874: if (defined($in{'curr_kerb_ver'})) {
2875: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2876: $check5 = ' checked="checked"';
1.591 raeburn 2877: $check4 = '';
2878: } else {
1.772 bisitz 2879: $check4 = ' checked="checked"';
1.591 raeburn 2880: $check5 = '';
2881: }
1.586 raeburn 2882: }
1.591 raeburn 2883: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2884: $krbarg = $in{'curr_autharg'};
2885: }
1.586 raeburn 2886: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2887: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2888: $result =
2889: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2890: $in{'curr_autharg'},$krbver);
2891: } else {
2892: $result =
2893: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2894: }
2895: return $result;
2896: }
2897: }
2898: } else {
2899: if ($authnum == 1) {
1.784 bisitz 2900: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2901: }
2902: }
1.586 raeburn 2903: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2904: return;
1.587 raeburn 2905: } elsif ($authtype eq '') {
1.591 raeburn 2906: if (defined($in{'mode'})) {
1.587 raeburn 2907: if ($in{'mode'} eq 'modifycourse') {
2908: if ($authnum == 1) {
1.1075.2.117 raeburn 2909: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 2910: }
2911: }
2912: }
1.586 raeburn 2913: }
2914: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2915: if ($authtype eq '') {
2916: $authtype = '<input type="radio" name="login" value="krb" '.
2917: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1075.2.117 raeburn 2918: $krbcheck.$disabled.' />';
1.586 raeburn 2919: }
2920: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2921: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2922: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2923: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2924: $in{'curr_authtype'} eq 'krb4')) {
2925: $result .= &mt
1.144 matthew 2926: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2927: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2928: '<label>'.$authtype,
1.281 albertel 2929: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2930: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2931: 'onchange="'.$jscall.'"'.$disabled.' />',
2932: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
2933: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 2934: '</label>');
1.586 raeburn 2935: } elsif ($can_assign{'krb4'}) {
2936: $result .= &mt
2937: ('[_1] Kerberos authenticated with domain [_2] '.
2938: '[_3] Version 4 [_4]',
2939: '<label>'.$authtype,
2940: '</label><input type="text" size="10" name="krbarg" '.
2941: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2942: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2943: '<label><input type="hidden" name="krbver" value="4" />',
2944: '</label>');
2945: } elsif ($can_assign{'krb5'}) {
2946: $result .= &mt
2947: ('[_1] Kerberos authenticated with domain [_2] '.
2948: '[_3] Version 5 [_4]',
2949: '<label>'.$authtype,
2950: '</label><input type="text" size="10" name="krbarg" '.
2951: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2952: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2953: '<label><input type="hidden" name="krbver" value="5" />',
2954: '</label>');
2955: }
1.32 matthew 2956: return $result;
2957: }
2958:
1.1075.2.20 raeburn 2959: sub authform_internal {
1.586 raeburn 2960: my %in = (
1.32 matthew 2961: formname => 'document.cu',
2962: kerb_def_dom => 'MSU.EDU',
2963: @_,
2964: );
1.1075.2.117 raeburn 2965: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2966: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 2967: if ($in{'readonly'}) {
2968: $disabled = ' disabled="disabled"';
2969: }
1.591 raeburn 2970: if (defined($in{'curr_authtype'})) {
2971: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2972: if ($can_assign{'int'}) {
1.772 bisitz 2973: $intcheck = 'checked="checked" ';
1.623 raeburn 2974: if (defined($in{'mode'})) {
2975: if ($in{'mode'} eq 'modifyuser') {
2976: $intcheck = '';
2977: }
2978: }
1.591 raeburn 2979: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2980: $intarg = $in{'curr_autharg'};
2981: }
2982: } else {
2983: $result = &mt('Currently internally authenticated.');
2984: return $result;
1.165 raeburn 2985: }
2986: }
1.586 raeburn 2987: } else {
2988: if ($authnum == 1) {
1.784 bisitz 2989: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2990: }
2991: }
2992: if (!$can_assign{'int'}) {
2993: return;
1.587 raeburn 2994: } elsif ($authtype eq '') {
1.591 raeburn 2995: if (defined($in{'mode'})) {
1.587 raeburn 2996: if ($in{'mode'} eq 'modifycourse') {
2997: if ($authnum == 1) {
1.1075.2.117 raeburn 2998: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 2999: }
3000: }
3001: }
1.165 raeburn 3002: }
1.586 raeburn 3003: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3004: if ($authtype eq '') {
3005: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1075.2.117 raeburn 3006: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3007: }
1.605 bisitz 3008: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1075.2.117 raeburn 3009: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3010: $result = &mt
1.144 matthew 3011: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3012: '<label>'.$authtype,'</label>'.$autharg);
1.1075.2.118 raeburn 3013: $result.='<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>';
1.32 matthew 3014: return $result;
3015: }
3016:
1.1075.2.20 raeburn 3017: sub authform_local {
1.32 matthew 3018: my %in = (
3019: formname => 'document.cu',
3020: kerb_def_dom => 'MSU.EDU',
3021: @_,
3022: );
1.1075.2.117 raeburn 3023: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3024: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3025: if ($in{'readonly'}) {
3026: $disabled = ' disabled="disabled"';
3027: }
1.591 raeburn 3028: if (defined($in{'curr_authtype'})) {
3029: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3030: if ($can_assign{'loc'}) {
1.772 bisitz 3031: $loccheck = 'checked="checked" ';
1.623 raeburn 3032: if (defined($in{'mode'})) {
3033: if ($in{'mode'} eq 'modifyuser') {
3034: $loccheck = '';
3035: }
3036: }
1.591 raeburn 3037: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3038: $locarg = $in{'curr_autharg'};
3039: }
3040: } else {
3041: $result = &mt('Currently using local (institutional) authentication.');
3042: return $result;
1.165 raeburn 3043: }
3044: }
1.586 raeburn 3045: } else {
3046: if ($authnum == 1) {
1.784 bisitz 3047: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3048: }
3049: }
3050: if (!$can_assign{'loc'}) {
3051: return;
1.587 raeburn 3052: } elsif ($authtype eq '') {
1.591 raeburn 3053: if (defined($in{'mode'})) {
1.587 raeburn 3054: if ($in{'mode'} eq 'modifycourse') {
3055: if ($authnum == 1) {
1.1075.2.117 raeburn 3056: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3057: }
3058: }
3059: }
1.165 raeburn 3060: }
1.586 raeburn 3061: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3062: if ($authtype eq '') {
3063: $authtype = '<input type="radio" name="login" value="loc" '.
3064: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3065: $jscall.'"'.$disabled.' />';
1.586 raeburn 3066: }
3067: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1075.2.117 raeburn 3068: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3069: $result = &mt('[_1] Local Authentication with argument [_2]',
3070: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3071: return $result;
3072: }
3073:
1.1075.2.20 raeburn 3074: sub authform_filesystem {
1.32 matthew 3075: my %in = (
3076: formname => 'document.cu',
3077: kerb_def_dom => 'MSU.EDU',
3078: @_,
3079: );
1.1075.2.117 raeburn 3080: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3081: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3082: if ($in{'readonly'}) {
3083: $disabled = ' disabled="disabled"';
3084: }
1.591 raeburn 3085: if (defined($in{'curr_authtype'})) {
3086: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3087: if ($can_assign{'fsys'}) {
1.772 bisitz 3088: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3089: if (defined($in{'mode'})) {
3090: if ($in{'mode'} eq 'modifyuser') {
3091: $fsyscheck = '';
3092: }
3093: }
1.586 raeburn 3094: } else {
3095: $result = &mt('Currently Filesystem Authenticated.');
3096: return $result;
3097: }
3098: }
3099: } else {
3100: if ($authnum == 1) {
1.784 bisitz 3101: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3102: }
3103: }
3104: if (!$can_assign{'fsys'}) {
3105: return;
1.587 raeburn 3106: } elsif ($authtype eq '') {
1.591 raeburn 3107: if (defined($in{'mode'})) {
1.587 raeburn 3108: if ($in{'mode'} eq 'modifycourse') {
3109: if ($authnum == 1) {
1.1075.2.117 raeburn 3110: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3111: }
3112: }
3113: }
1.586 raeburn 3114: }
3115: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3116: if ($authtype eq '') {
3117: $authtype = '<input type="radio" name="login" value="fsys" '.
3118: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3119: $jscall.'"'.$disabled.' />';
1.586 raeburn 3120: }
3121: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
1.1075.2.117 raeburn 3122: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3123: $result = &mt
1.144 matthew 3124: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3125: '<label><input type="radio" name="login" value="fsys" '.
1.1075.2.117 raeburn 3126: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />',
1.605 bisitz 3127: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.1075.2.117 raeburn 3128: 'onchange="'.$jscall.'"'.$disabled.' />');
1.32 matthew 3129: return $result;
3130: }
3131:
1.586 raeburn 3132: sub get_assignable_auth {
3133: my ($dom) = @_;
3134: if ($dom eq '') {
3135: $dom = $env{'request.role.domain'};
3136: }
3137: my %can_assign = (
3138: krb4 => 1,
3139: krb5 => 1,
3140: int => 1,
3141: loc => 1,
3142: );
3143: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3144: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3145: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3146: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3147: my $context;
3148: if ($env{'request.role'} =~ /^au/) {
3149: $context = 'author';
1.1075.2.117 raeburn 3150: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3151: $context = 'domain';
3152: } elsif ($env{'request.course.id'}) {
3153: $context = 'course';
3154: }
3155: if ($context) {
3156: if (ref($authhash->{$context}) eq 'HASH') {
3157: %can_assign = %{$authhash->{$context}};
3158: }
3159: }
3160: }
3161: }
3162: my $authnum = 0;
3163: foreach my $key (keys(%can_assign)) {
3164: if ($can_assign{$key}) {
3165: $authnum ++;
3166: }
3167: }
3168: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3169: $authnum --;
3170: }
3171: return ($authnum,%can_assign);
3172: }
3173:
1.80 albertel 3174: ###############################################################
3175: ## Get Kerberos Defaults for Domain ##
3176: ###############################################################
3177: ##
3178: ## Returns default kerberos version and an associated argument
3179: ## as listed in file domain.tab. If not listed, provides
3180: ## appropriate default domain and kerberos version.
3181: ##
3182: #-------------------------------------------
3183:
3184: =pod
3185:
1.648 raeburn 3186: =item * &get_kerberos_defaults()
1.80 albertel 3187:
3188: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3189: version and domain. If not found, it defaults to version 4 and the
3190: domain of the server.
1.80 albertel 3191:
1.648 raeburn 3192: =over 4
3193:
1.80 albertel 3194: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3195:
1.648 raeburn 3196: =back
3197:
3198: =back
3199:
1.80 albertel 3200: =cut
3201:
3202: #-------------------------------------------
3203: sub get_kerberos_defaults {
3204: my $domain=shift;
1.641 raeburn 3205: my ($krbdef,$krbdefdom);
3206: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3207: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3208: $krbdef = $domdefaults{'auth_def'};
3209: $krbdefdom = $domdefaults{'auth_arg_def'};
3210: } else {
1.80 albertel 3211: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3212: my $krbdefdom=$1;
3213: $krbdefdom=~tr/a-z/A-Z/;
3214: $krbdef = "krb4";
3215: }
3216: return ($krbdef,$krbdefdom);
3217: }
1.112 bowersj2 3218:
1.32 matthew 3219:
1.46 matthew 3220: ###############################################################
3221: ## Thesaurus Functions ##
3222: ###############################################################
1.20 www 3223:
1.46 matthew 3224: =pod
1.20 www 3225:
1.112 bowersj2 3226: =head1 Thesaurus Functions
3227:
3228: =over 4
3229:
1.648 raeburn 3230: =item * &initialize_keywords()
1.46 matthew 3231:
3232: Initializes the package variable %Keywords if it is empty. Uses the
3233: package variable $thesaurus_db_file.
3234:
3235: =cut
3236:
3237: ###################################################
3238:
3239: sub initialize_keywords {
3240: return 1 if (scalar keys(%Keywords));
3241: # If we are here, %Keywords is empty, so fill it up
3242: # Make sure the file we need exists...
3243: if (! -e $thesaurus_db_file) {
3244: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3245: " failed because it does not exist");
3246: return 0;
3247: }
3248: # Set up the hash as a database
3249: my %thesaurus_db;
3250: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3251: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3252: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3253: $thesaurus_db_file);
3254: return 0;
3255: }
3256: # Get the average number of appearances of a word.
3257: my $avecount = $thesaurus_db{'average.count'};
3258: # Put keywords (those that appear > average) into %Keywords
3259: while (my ($word,$data)=each (%thesaurus_db)) {
3260: my ($count,undef) = split /:/,$data;
3261: $Keywords{$word}++ if ($count > $avecount);
3262: }
3263: untie %thesaurus_db;
3264: # Remove special values from %Keywords.
1.356 albertel 3265: foreach my $value ('total.count','average.count') {
3266: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3267: }
1.46 matthew 3268: return 1;
3269: }
3270:
3271: ###################################################
3272:
3273: =pod
3274:
1.648 raeburn 3275: =item * &keyword($word)
1.46 matthew 3276:
3277: Returns true if $word is a keyword. A keyword is a word that appears more
3278: than the average number of times in the thesaurus database. Calls
3279: &initialize_keywords
3280:
3281: =cut
3282:
3283: ###################################################
1.20 www 3284:
3285: sub keyword {
1.46 matthew 3286: return if (!&initialize_keywords());
3287: my $word=lc(shift());
3288: $word=~s/\W//g;
3289: return exists($Keywords{$word});
1.20 www 3290: }
1.46 matthew 3291:
3292: ###############################################################
3293:
3294: =pod
1.20 www 3295:
1.648 raeburn 3296: =item * &get_related_words()
1.46 matthew 3297:
1.160 matthew 3298: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3299: an array of words. If the keyword is not in the thesaurus, an empty array
3300: will be returned. The order of the words returned is determined by the
3301: database which holds them.
3302:
3303: Uses global $thesaurus_db_file.
3304:
1.1057 foxr 3305:
1.46 matthew 3306: =cut
3307:
3308: ###############################################################
3309: sub get_related_words {
3310: my $keyword = shift;
3311: my %thesaurus_db;
3312: if (! -e $thesaurus_db_file) {
3313: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3314: "failed because the file does not exist");
3315: return ();
3316: }
3317: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3318: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3319: return ();
3320: }
3321: my @Words=();
1.429 www 3322: my $count=0;
1.46 matthew 3323: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3324: # The first element is the number of times
3325: # the word appears. We do not need it now.
1.429 www 3326: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3327: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3328: my $threshold=$mostfrequentcount/10;
3329: foreach my $possibleword (@RelatedWords) {
3330: my ($word,$wordcount)=split(/\,/,$possibleword);
3331: if ($wordcount>$threshold) {
3332: push(@Words,$word);
3333: $count++;
3334: if ($count>10) { last; }
3335: }
1.20 www 3336: }
3337: }
1.46 matthew 3338: untie %thesaurus_db;
3339: return @Words;
1.14 harris41 3340: }
1.46 matthew 3341:
1.112 bowersj2 3342: =pod
3343:
3344: =back
3345:
3346: =cut
1.61 www 3347:
3348: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3349: =pod
3350:
1.112 bowersj2 3351: =head1 User Name Functions
3352:
3353: =over 4
3354:
1.648 raeburn 3355: =item * &plainname($uname,$udom,$first)
1.81 albertel 3356:
1.112 bowersj2 3357: Takes a users logon name and returns it as a string in
1.226 albertel 3358: "first middle last generation" form
3359: if $first is set to 'lastname' then it returns it as
3360: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3361:
3362: =cut
1.61 www 3363:
1.295 www 3364:
1.81 albertel 3365: ###############################################################
1.61 www 3366: sub plainname {
1.226 albertel 3367: my ($uname,$udom,$first)=@_;
1.537 albertel 3368: return if (!defined($uname) || !defined($udom));
1.295 www 3369: my %names=&getnames($uname,$udom);
1.226 albertel 3370: my $name=&Apache::lonnet::format_name($names{'firstname'},
3371: $names{'middlename'},
3372: $names{'lastname'},
3373: $names{'generation'},$first);
3374: $name=~s/^\s+//;
1.62 www 3375: $name=~s/\s+$//;
3376: $name=~s/\s+/ /g;
1.353 albertel 3377: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3378: return $name;
1.61 www 3379: }
1.66 www 3380:
3381: # -------------------------------------------------------------------- Nickname
1.81 albertel 3382: =pod
3383:
1.648 raeburn 3384: =item * &nickname($uname,$udom)
1.81 albertel 3385:
3386: Gets a users name and returns it as a string as
3387:
3388: ""nickname""
1.66 www 3389:
1.81 albertel 3390: if the user has a nickname or
3391:
3392: "first middle last generation"
3393:
3394: if the user does not
3395:
3396: =cut
1.66 www 3397:
3398: sub nickname {
3399: my ($uname,$udom)=@_;
1.537 albertel 3400: return if (!defined($uname) || !defined($udom));
1.295 www 3401: my %names=&getnames($uname,$udom);
1.68 albertel 3402: my $name=$names{'nickname'};
1.66 www 3403: if ($name) {
3404: $name='"'.$name.'"';
3405: } else {
3406: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3407: $names{'lastname'}.' '.$names{'generation'};
3408: $name=~s/\s+$//;
3409: $name=~s/\s+/ /g;
3410: }
3411: return $name;
3412: }
3413:
1.295 www 3414: sub getnames {
3415: my ($uname,$udom)=@_;
1.537 albertel 3416: return if (!defined($uname) || !defined($udom));
1.433 albertel 3417: if ($udom eq 'public' && $uname eq 'public') {
3418: return ('lastname' => &mt('Public'));
3419: }
1.295 www 3420: my $id=$uname.':'.$udom;
3421: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3422: if ($cached) {
3423: return %{$names};
3424: } else {
3425: my %loadnames=&Apache::lonnet::get('environment',
3426: ['firstname','middlename','lastname','generation','nickname'],
3427: $udom,$uname);
3428: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3429: return %loadnames;
3430: }
3431: }
1.61 www 3432:
1.542 raeburn 3433: # -------------------------------------------------------------------- getemails
1.648 raeburn 3434:
1.542 raeburn 3435: =pod
3436:
1.648 raeburn 3437: =item * &getemails($uname,$udom)
1.542 raeburn 3438:
3439: Gets a user's email information and returns it as a hash with keys:
3440: notification, critnotification, permanentemail
3441:
3442: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3443: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3444:
1.648 raeburn 3445:
1.542 raeburn 3446: =cut
3447:
1.648 raeburn 3448:
1.466 albertel 3449: sub getemails {
3450: my ($uname,$udom)=@_;
3451: if ($udom eq 'public' && $uname eq 'public') {
3452: return;
3453: }
1.467 www 3454: if (!$udom) { $udom=$env{'user.domain'}; }
3455: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3456: my $id=$uname.':'.$udom;
3457: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3458: if ($cached) {
3459: return %{$names};
3460: } else {
3461: my %loadnames=&Apache::lonnet::get('environment',
3462: ['notification','critnotification',
3463: 'permanentemail'],
3464: $udom,$uname);
3465: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3466: return %loadnames;
3467: }
3468: }
3469:
1.551 albertel 3470: sub flush_email_cache {
3471: my ($uname,$udom)=@_;
3472: if (!$udom) { $udom =$env{'user.domain'}; }
3473: if (!$uname) { $uname=$env{'user.name'}; }
3474: return if ($udom eq 'public' && $uname eq 'public');
3475: my $id=$uname.':'.$udom;
3476: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3477: }
3478:
1.728 raeburn 3479: # -------------------------------------------------------------------- getlangs
3480:
3481: =pod
3482:
3483: =item * &getlangs($uname,$udom)
3484:
3485: Gets a user's language preference and returns it as a hash with key:
3486: language.
3487:
3488: =cut
3489:
3490:
3491: sub getlangs {
3492: my ($uname,$udom) = @_;
3493: if (!$udom) { $udom =$env{'user.domain'}; }
3494: if (!$uname) { $uname=$env{'user.name'}; }
3495: my $id=$uname.':'.$udom;
3496: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3497: if ($cached) {
3498: return %{$langs};
3499: } else {
3500: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3501: $udom,$uname);
3502: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3503: return %loadlangs;
3504: }
3505: }
3506:
3507: sub flush_langs_cache {
3508: my ($uname,$udom)=@_;
3509: if (!$udom) { $udom =$env{'user.domain'}; }
3510: if (!$uname) { $uname=$env{'user.name'}; }
3511: return if ($udom eq 'public' && $uname eq 'public');
3512: my $id=$uname.':'.$udom;
3513: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3514: }
3515:
1.61 www 3516: # ------------------------------------------------------------------ Screenname
1.81 albertel 3517:
3518: =pod
3519:
1.648 raeburn 3520: =item * &screenname($uname,$udom)
1.81 albertel 3521:
3522: Gets a users screenname and returns it as a string
3523:
3524: =cut
1.61 www 3525:
3526: sub screenname {
3527: my ($uname,$udom)=@_;
1.258 albertel 3528: if ($uname eq $env{'user.name'} &&
3529: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3530: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3531: return $names{'screenname'};
1.62 www 3532: }
3533:
1.212 albertel 3534:
1.802 bisitz 3535: # ------------------------------------------------------------- Confirm Wrapper
3536: =pod
3537:
1.1075.2.42 raeburn 3538: =item * &confirmwrapper($message)
1.802 bisitz 3539:
3540: Wrap messages about completion of operation in box
3541:
3542: =cut
3543:
3544: sub confirmwrapper {
3545: my ($message)=@_;
3546: if ($message) {
3547: return "\n".'<div class="LC_confirm_box">'."\n"
3548: .$message."\n"
3549: .'</div>'."\n";
3550: } else {
3551: return $message;
3552: }
3553: }
3554:
1.62 www 3555: # ------------------------------------------------------------- Message Wrapper
3556:
3557: sub messagewrapper {
1.369 www 3558: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3559: return
1.441 albertel 3560: '<a href="/adm/email?compose=individual&'.
3561: 'recname='.$username.'&recdom='.$domain.
3562: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3563: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3564: }
1.802 bisitz 3565:
1.74 www 3566: # --------------------------------------------------------------- Notes Wrapper
3567:
3568: sub noteswrapper {
3569: my ($link,$un,$do)=@_;
3570: return
1.896 amueller 3571: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3572: }
1.802 bisitz 3573:
1.62 www 3574: # ------------------------------------------------------------- Aboutme Wrapper
3575:
3576: sub aboutmewrapper {
1.1070 raeburn 3577: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3578: if (!defined($username) && !defined($domain)) {
3579: return;
3580: }
1.1075.2.15 raeburn 3581: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3582: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3583: }
3584:
3585: # ------------------------------------------------------------ Syllabus Wrapper
3586:
3587: sub syllabuswrapper {
1.707 bisitz 3588: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3589: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3590: }
1.14 harris41 3591:
1.802 bisitz 3592: # -----------------------------------------------------------------------------
3593:
1.208 matthew 3594: sub track_student_link {
1.887 raeburn 3595: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3596: my $link ="/adm/trackstudent?";
1.208 matthew 3597: my $title = 'View recent activity';
3598: if (defined($sname) && $sname !~ /^\s*$/ &&
3599: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3600: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3601: $title .= ' of this student';
1.268 albertel 3602: }
1.208 matthew 3603: if (defined($target) && $target !~ /^\s*$/) {
3604: $target = qq{target="$target"};
3605: } else {
3606: $target = '';
3607: }
1.268 albertel 3608: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3609: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3610: $title = &mt($title);
3611: $linktext = &mt($linktext);
1.448 albertel 3612: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3613: &help_open_topic('View_recent_activity');
1.208 matthew 3614: }
3615:
1.781 raeburn 3616: sub slot_reservations_link {
3617: my ($linktext,$sname,$sdom,$target) = @_;
3618: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3619: my $title = 'View slot reservation history';
3620: if (defined($sname) && $sname !~ /^\s*$/ &&
3621: defined($sdom) && $sdom !~ /^\s*$/) {
3622: $link .= "&uname=$sname&udom=$sdom";
3623: $title .= ' of this student';
3624: }
3625: if (defined($target) && $target !~ /^\s*$/) {
3626: $target = qq{target="$target"};
3627: } else {
3628: $target = '';
3629: }
3630: $title = &mt($title);
3631: $linktext = &mt($linktext);
3632: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3633: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3634:
3635: }
3636:
1.508 www 3637: # ===================================================== Display a student photo
3638:
3639:
1.509 albertel 3640: sub student_image_tag {
1.508 www 3641: my ($domain,$user)=@_;
3642: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3643: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3644: return '<img src="'.$imgsrc.'" align="right" />';
3645: } else {
3646: return '';
3647: }
3648: }
3649:
1.112 bowersj2 3650: =pod
3651:
3652: =back
3653:
3654: =head1 Access .tab File Data
3655:
3656: =over 4
3657:
1.648 raeburn 3658: =item * &languageids()
1.112 bowersj2 3659:
3660: returns list of all language ids
3661:
3662: =cut
3663:
1.14 harris41 3664: sub languageids {
1.16 harris41 3665: return sort(keys(%language));
1.14 harris41 3666: }
3667:
1.112 bowersj2 3668: =pod
3669:
1.648 raeburn 3670: =item * &languagedescription()
1.112 bowersj2 3671:
3672: returns description of a specified language id
3673:
3674: =cut
3675:
1.14 harris41 3676: sub languagedescription {
1.125 www 3677: my $code=shift;
3678: return ($supported_language{$code}?'* ':'').
3679: $language{$code}.
1.126 www 3680: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3681: }
3682:
1.1048 foxr 3683: =pod
3684:
3685: =item * &plainlanguagedescription
3686:
3687: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3688: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3689:
3690: =cut
3691:
1.145 www 3692: sub plainlanguagedescription {
3693: my $code=shift;
3694: return $language{$code};
3695: }
3696:
1.1048 foxr 3697: =pod
3698:
3699: =item * &supportedlanguagecode
3700:
3701: Returns the supported language code (e.g. sptutf maps to pt) given a language
3702: code.
3703:
3704: =cut
3705:
1.145 www 3706: sub supportedlanguagecode {
3707: my $code=shift;
3708: return $supported_language{$code};
1.97 www 3709: }
3710:
1.112 bowersj2 3711: =pod
3712:
1.1048 foxr 3713: =item * &latexlanguage()
3714:
3715: Given a language key code returns the correspondnig language to use
3716: to select the correct hyphenation on LaTeX printouts. This is undef if there
3717: is no supported hyphenation for the language code.
3718:
3719: =cut
3720:
3721: sub latexlanguage {
3722: my $code = shift;
3723: return $latex_language{$code};
3724: }
3725:
3726: =pod
3727:
3728: =item * &latexhyphenation()
3729:
3730: Same as above but what's supplied is the language as it might be stored
3731: in the metadata.
3732:
3733: =cut
3734:
3735: sub latexhyphenation {
3736: my $key = shift;
3737: return $latex_language_bykey{$key};
3738: }
3739:
3740: =pod
3741:
1.648 raeburn 3742: =item * ©rightids()
1.112 bowersj2 3743:
3744: returns list of all copyrights
3745:
3746: =cut
3747:
3748: sub copyrightids {
3749: return sort(keys(%cprtag));
3750: }
3751:
3752: =pod
3753:
1.648 raeburn 3754: =item * ©rightdescription()
1.112 bowersj2 3755:
3756: returns description of a specified copyright id
3757:
3758: =cut
3759:
3760: sub copyrightdescription {
1.166 www 3761: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3762: }
1.197 matthew 3763:
3764: =pod
3765:
1.648 raeburn 3766: =item * &source_copyrightids()
1.192 taceyjo1 3767:
3768: returns list of all source copyrights
3769:
3770: =cut
3771:
3772: sub source_copyrightids {
3773: return sort(keys(%scprtag));
3774: }
3775:
3776: =pod
3777:
1.648 raeburn 3778: =item * &source_copyrightdescription()
1.192 taceyjo1 3779:
3780: returns description of a specified source copyright id
3781:
3782: =cut
3783:
3784: sub source_copyrightdescription {
3785: return &mt($scprtag{shift(@_)});
3786: }
1.112 bowersj2 3787:
3788: =pod
3789:
1.648 raeburn 3790: =item * &filecategories()
1.112 bowersj2 3791:
3792: returns list of all file categories
3793:
3794: =cut
3795:
3796: sub filecategories {
3797: return sort(keys(%category_extensions));
3798: }
3799:
3800: =pod
3801:
1.648 raeburn 3802: =item * &filecategorytypes()
1.112 bowersj2 3803:
3804: returns list of file types belonging to a given file
3805: category
3806:
3807: =cut
3808:
3809: sub filecategorytypes {
1.356 albertel 3810: my ($cat) = @_;
3811: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3812: }
3813:
3814: =pod
3815:
1.648 raeburn 3816: =item * &fileembstyle()
1.112 bowersj2 3817:
3818: returns embedding style for a specified file type
3819:
3820: =cut
3821:
3822: sub fileembstyle {
3823: return $fe{lc(shift(@_))};
1.169 www 3824: }
3825:
1.351 www 3826: sub filemimetype {
3827: return $fm{lc(shift(@_))};
3828: }
3829:
1.169 www 3830:
3831: sub filecategoryselect {
3832: my ($name,$value)=@_;
1.189 matthew 3833: return &select_form($value,$name,
1.970 raeburn 3834: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3835: }
3836:
3837: =pod
3838:
1.648 raeburn 3839: =item * &filedescription()
1.112 bowersj2 3840:
3841: returns description for a specified file type
3842:
3843: =cut
3844:
3845: sub filedescription {
1.188 matthew 3846: my $file_description = $fd{lc(shift())};
3847: $file_description =~ s:([\[\]]):~$1:g;
3848: return &mt($file_description);
1.112 bowersj2 3849: }
3850:
3851: =pod
3852:
1.648 raeburn 3853: =item * &filedescriptionex()
1.112 bowersj2 3854:
3855: returns description for a specified file type with
3856: extra formatting
3857:
3858: =cut
3859:
3860: sub filedescriptionex {
3861: my $ex=shift;
1.188 matthew 3862: my $file_description = $fd{lc($ex)};
3863: $file_description =~ s:([\[\]]):~$1:g;
3864: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3865: }
3866:
3867: # End of .tab access
3868: =pod
3869:
3870: =back
3871:
3872: =cut
3873:
3874: # ------------------------------------------------------------------ File Types
3875: sub fileextensions {
3876: return sort(keys(%fe));
3877: }
3878:
1.97 www 3879: # ----------------------------------------------------------- Display Languages
3880: # returns a hash with all desired display languages
3881: #
3882:
3883: sub display_languages {
3884: my %languages=();
1.695 raeburn 3885: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3886: $languages{$lang}=1;
1.97 www 3887: }
3888: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3889: if ($env{'form.displaylanguage'}) {
1.356 albertel 3890: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3891: $languages{$lang}=1;
1.97 www 3892: }
3893: }
3894: return %languages;
1.14 harris41 3895: }
3896:
1.582 albertel 3897: sub languages {
3898: my ($possible_langs) = @_;
1.695 raeburn 3899: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3900: if (!ref($possible_langs)) {
3901: if( wantarray ) {
3902: return @preferred_langs;
3903: } else {
3904: return $preferred_langs[0];
3905: }
3906: }
3907: my %possibilities = map { $_ => 1 } (@$possible_langs);
3908: my @preferred_possibilities;
3909: foreach my $preferred_lang (@preferred_langs) {
3910: if (exists($possibilities{$preferred_lang})) {
3911: push(@preferred_possibilities, $preferred_lang);
3912: }
3913: }
3914: if( wantarray ) {
3915: return @preferred_possibilities;
3916: }
3917: return $preferred_possibilities[0];
3918: }
3919:
1.742 raeburn 3920: sub user_lang {
3921: my ($touname,$toudom,$fromcid) = @_;
3922: my @userlangs;
3923: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3924: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3925: $env{'course.'.$fromcid.'.languages'}));
3926: } else {
3927: my %langhash = &getlangs($touname,$toudom);
3928: if ($langhash{'languages'} ne '') {
3929: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3930: } else {
3931: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3932: if ($domdefs{'lang_def'} ne '') {
3933: @userlangs = ($domdefs{'lang_def'});
3934: }
3935: }
3936: }
3937: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3938: my $user_lh = Apache::localize->get_handle(@languages);
3939: return $user_lh;
3940: }
3941:
3942:
1.112 bowersj2 3943: ###############################################################
3944: ## Student Answer Attempts ##
3945: ###############################################################
3946:
3947: =pod
3948:
3949: =head1 Alternate Problem Views
3950:
3951: =over 4
3952:
1.648 raeburn 3953: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 3954: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 3955:
3956: Return string with previous attempt on problem. Arguments:
3957:
3958: =over 4
3959:
3960: =item * $symb: Problem, including path
3961:
3962: =item * $username: username of the desired student
3963:
3964: =item * $domain: domain of the desired student
1.14 harris41 3965:
1.112 bowersj2 3966: =item * $course: Course ID
1.14 harris41 3967:
1.112 bowersj2 3968: =item * $getattempt: Leave blank for all attempts, otherwise put
3969: something
1.14 harris41 3970:
1.112 bowersj2 3971: =item * $regexp: if string matches this regexp, the string will be
3972: sent to $gradesub
1.14 harris41 3973:
1.112 bowersj2 3974: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3975:
1.1075.2.86 raeburn 3976: =item * $usec: section of the desired student
3977:
3978: =item * $identifier: counter for student (multiple students one problem) or
3979: problem (one student; whole sequence).
3980:
1.112 bowersj2 3981: =back
1.14 harris41 3982:
1.112 bowersj2 3983: The output string is a table containing all desired attempts, if any.
1.16 harris41 3984:
1.112 bowersj2 3985: =cut
1.1 albertel 3986:
3987: sub get_previous_attempt {
1.1075.2.86 raeburn 3988: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 3989: my $prevattempts='';
1.43 ng 3990: no strict 'refs';
1.1 albertel 3991: if ($symb) {
1.3 albertel 3992: my (%returnhash)=
3993: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3994: if ($returnhash{'version'}) {
3995: my %lasthash=();
3996: my $version;
3997: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 3998: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
3999: if ($key =~ /\.rawrndseed$/) {
4000: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4001: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4002: } else {
4003: $lasthash{$key}=$returnhash{$version.':'.$key};
4004: }
1.19 harris41 4005: }
1.1 albertel 4006: }
1.596 albertel 4007: $prevattempts=&start_data_table().&start_data_table_header_row();
4008: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 4009: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4010: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4011: foreach my $key (sort(keys(%lasthash))) {
4012: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4013: if ($#parts > 0) {
1.31 albertel 4014: my $data=$parts[-1];
1.989 raeburn 4015: next if ($data eq 'foilorder');
1.31 albertel 4016: pop(@parts);
1.1010 www 4017: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4018: if ($data eq 'type') {
4019: unless ($showsurv) {
4020: my $id = join(',',@parts);
4021: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4022: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4023: $lasthidden{$ign.'.'.$id} = 1;
4024: }
1.945 raeburn 4025: }
1.1075.2.86 raeburn 4026: if ($identifier ne '') {
4027: my $id = join(',',@parts);
4028: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4029: $domain,$username,$usec,undef,$course) =~ /^no/) {
4030: $hidestatus{$ign.'.'.$id} = 1;
4031: }
4032: }
4033: } elsif ($data eq 'regrader') {
4034: if (($identifier ne '') && (@parts)) {
4035: my $id = join(',',@parts);
4036: $regraded{$ign.'.'.$id} = 1;
4037: }
1.1010 www 4038: }
1.31 albertel 4039: } else {
1.41 ng 4040: if ($#parts == 0) {
4041: $prevattempts.='<th>'.$parts[0].'</th>';
4042: } else {
4043: $prevattempts.='<th>'.$ign.'</th>';
4044: }
1.31 albertel 4045: }
1.16 harris41 4046: }
1.596 albertel 4047: $prevattempts.=&end_data_table_header_row();
1.40 ng 4048: if ($getattempt eq '') {
1.1075.2.86 raeburn 4049: my (%solved,%resets,%probstatus);
4050: if (($identifier ne '') && (keys(%regraded) > 0)) {
4051: for ($version=1;$version<=$returnhash{'version'};$version++) {
4052: foreach my $id (keys(%regraded)) {
4053: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4054: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4055: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4056: push(@{$resets{$id}},$version);
4057: }
4058: }
4059: }
4060: }
1.40 ng 4061: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4062: my (@hidden,@unsolved);
1.945 raeburn 4063: if (%typeparts) {
4064: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4065: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4066: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4067: push(@hidden,$id);
1.1075.2.86 raeburn 4068: } elsif ($identifier ne '') {
4069: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4070: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4071: ($hidestatus{$id})) {
4072: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4073: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4074: push(@{$solved{$id}},$version);
4075: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4076: (ref($solved{$id}) eq 'ARRAY')) {
4077: my $skip;
4078: if (ref($resets{$id}) eq 'ARRAY') {
4079: foreach my $reset (@{$resets{$id}}) {
4080: if ($reset > $solved{$id}[-1]) {
4081: $skip=1;
4082: last;
4083: }
4084: }
4085: }
4086: unless ($skip) {
4087: my ($ign,$partslist) = split(/\./,$id,2);
4088: push(@unsolved,$partslist);
4089: }
4090: }
4091: }
1.945 raeburn 4092: }
4093: }
4094: }
4095: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4096: '<td>'.&mt('Transaction [_1]',$version);
4097: if (@unsolved) {
4098: $prevattempts .= '<span class="LC_nobreak"><label>'.
4099: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4100: &mt('Hide').'</label></span>';
4101: }
4102: $prevattempts .= '</td>';
1.945 raeburn 4103: if (@hidden) {
4104: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4105: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4106: my $hide;
4107: foreach my $id (@hidden) {
4108: if ($key =~ /^\Q$id\E/) {
4109: $hide = 1;
4110: last;
4111: }
4112: }
4113: if ($hide) {
4114: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4115: if (($data eq 'award') || ($data eq 'awarddetail')) {
4116: my $value = &format_previous_attempt_value($key,
4117: $returnhash{$version.':'.$key});
4118: $prevattempts.='<td>'.$value.' </td>';
4119: } else {
4120: $prevattempts.='<td> </td>';
4121: }
4122: } else {
4123: if ($key =~ /\./) {
1.1075.2.91 raeburn 4124: my $value = $returnhash{$version.':'.$key};
4125: if ($key =~ /\.rndseed$/) {
4126: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4127: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4128: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4129: }
4130: }
4131: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4132: ' </td>';
1.945 raeburn 4133: } else {
4134: $prevattempts.='<td> </td>';
4135: }
4136: }
4137: }
4138: } else {
4139: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4140: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4141: my $value = $returnhash{$version.':'.$key};
4142: if ($key =~ /\.rndseed$/) {
4143: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4144: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4145: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4146: }
4147: }
4148: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4149: ' </td>';
1.945 raeburn 4150: }
4151: }
4152: $prevattempts.=&end_data_table_row();
1.40 ng 4153: }
1.1 albertel 4154: }
1.945 raeburn 4155: my @currhidden = keys(%lasthidden);
1.596 albertel 4156: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4157: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4158: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4159: if (%typeparts) {
4160: my $hidden;
4161: foreach my $id (@currhidden) {
4162: if ($key =~ /^\Q$id\E/) {
4163: $hidden = 1;
4164: last;
4165: }
4166: }
4167: if ($hidden) {
4168: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4169: if (($data eq 'award') || ($data eq 'awarddetail')) {
4170: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4171: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4172: $value = &$gradesub($value);
4173: }
4174: $prevattempts.='<td>'.$value.' </td>';
4175: } else {
4176: $prevattempts.='<td> </td>';
4177: }
4178: } else {
4179: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4180: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4181: $value = &$gradesub($value);
4182: }
4183: $prevattempts.='<td>'.$value.' </td>';
4184: }
4185: } else {
4186: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4187: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4188: $value = &$gradesub($value);
4189: }
4190: $prevattempts.='<td>'.$value.' </td>';
4191: }
1.16 harris41 4192: }
1.596 albertel 4193: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4194: } else {
1.596 albertel 4195: $prevattempts=
4196: &start_data_table().&start_data_table_row().
4197: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4198: &end_data_table_row().&end_data_table();
1.1 albertel 4199: }
4200: } else {
1.596 albertel 4201: $prevattempts=
4202: &start_data_table().&start_data_table_row().
4203: '<td>'.&mt('No data.').'</td>'.
4204: &end_data_table_row().&end_data_table();
1.1 albertel 4205: }
1.10 albertel 4206: }
4207:
1.581 albertel 4208: sub format_previous_attempt_value {
4209: my ($key,$value) = @_;
1.1011 www 4210: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4211: $value = &Apache::lonlocal::locallocaltime($value);
4212: } elsif (ref($value) eq 'ARRAY') {
4213: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4214: } elsif ($key =~ /answerstring$/) {
4215: my %answers = &Apache::lonnet::str2hash($value);
4216: my @anskeys = sort(keys(%answers));
4217: if (@anskeys == 1) {
4218: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4219: if ($answer =~ m{\0}) {
4220: $answer =~ s{\0}{,}g;
1.988 raeburn 4221: }
4222: my $tag_internal_answer_name = 'INTERNAL';
4223: if ($anskeys[0] eq $tag_internal_answer_name) {
4224: $value = $answer;
4225: } else {
4226: $value = $anskeys[0].'='.$answer;
4227: }
4228: } else {
4229: foreach my $ans (@anskeys) {
4230: my $answer = $answers{$ans};
1.1001 raeburn 4231: if ($answer =~ m{\0}) {
4232: $answer =~ s{\0}{,}g;
1.988 raeburn 4233: }
4234: $value .= $ans.'='.$answer.'<br />';;
4235: }
4236: }
1.581 albertel 4237: } else {
4238: $value = &unescape($value);
4239: }
4240: return $value;
4241: }
4242:
4243:
1.107 albertel 4244: sub relative_to_absolute {
4245: my ($url,$output)=@_;
4246: my $parser=HTML::TokeParser->new(\$output);
4247: my $token;
4248: my $thisdir=$url;
4249: my @rlinks=();
4250: while ($token=$parser->get_token) {
4251: if ($token->[0] eq 'S') {
4252: if ($token->[1] eq 'a') {
4253: if ($token->[2]->{'href'}) {
4254: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4255: }
4256: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4257: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4258: } elsif ($token->[1] eq 'base') {
4259: $thisdir=$token->[2]->{'href'};
4260: }
4261: }
4262: }
4263: $thisdir=~s-/[^/]*$--;
1.356 albertel 4264: foreach my $link (@rlinks) {
1.726 raeburn 4265: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4266: ($link=~/^\//) ||
4267: ($link=~/^javascript:/i) ||
4268: ($link=~/^mailto:/i) ||
4269: ($link=~/^\#/)) {
4270: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4271: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4272: }
4273: }
4274: # -------------------------------------------------- Deal with Applet codebases
4275: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4276: return $output;
4277: }
4278:
1.112 bowersj2 4279: =pod
4280:
1.648 raeburn 4281: =item * &get_student_view()
1.112 bowersj2 4282:
4283: show a snapshot of what student was looking at
4284:
4285: =cut
4286:
1.10 albertel 4287: sub get_student_view {
1.186 albertel 4288: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4289: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4290: my (%form);
1.10 albertel 4291: my @elements=('symb','courseid','domain','username');
4292: foreach my $element (@elements) {
1.186 albertel 4293: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4294: }
1.186 albertel 4295: if (defined($moreenv)) {
4296: %form=(%form,%{$moreenv});
4297: }
1.236 albertel 4298: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4299: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4300: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4301: $userview=~s/\<body[^\>]*\>//gi;
4302: $userview=~s/\<\/body\>//gi;
4303: $userview=~s/\<html\>//gi;
4304: $userview=~s/\<\/html\>//gi;
4305: $userview=~s/\<head\>//gi;
4306: $userview=~s/\<\/head\>//gi;
4307: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4308: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4309: if (wantarray) {
4310: return ($userview,$response);
4311: } else {
4312: return $userview;
4313: }
4314: }
4315:
4316: sub get_student_view_with_retries {
4317: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4318:
4319: my $ok = 0; # True if we got a good response.
4320: my $content;
4321: my $response;
4322:
4323: # Try to get the student_view done. within the retries count:
4324:
4325: do {
4326: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4327: $ok = $response->is_success;
4328: if (!$ok) {
4329: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4330: }
4331: $retries--;
4332: } while (!$ok && ($retries > 0));
4333:
4334: if (!$ok) {
4335: $content = ''; # On error return an empty content.
4336: }
1.651 www 4337: if (wantarray) {
4338: return ($content, $response);
4339: } else {
4340: return $content;
4341: }
1.11 albertel 4342: }
4343:
1.112 bowersj2 4344: =pod
4345:
1.648 raeburn 4346: =item * &get_student_answers()
1.112 bowersj2 4347:
4348: show a snapshot of how student was answering problem
4349:
4350: =cut
4351:
1.11 albertel 4352: sub get_student_answers {
1.100 sakharuk 4353: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4354: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4355: my (%moreenv);
1.11 albertel 4356: my @elements=('symb','courseid','domain','username');
4357: foreach my $element (@elements) {
1.186 albertel 4358: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4359: }
1.186 albertel 4360: $moreenv{'grade_target'}='answer';
4361: %moreenv=(%form,%moreenv);
1.497 raeburn 4362: $feedurl = &Apache::lonnet::clutter($feedurl);
4363: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4364: return $userview;
1.1 albertel 4365: }
1.116 albertel 4366:
4367: =pod
4368:
4369: =item * &submlink()
4370:
1.242 albertel 4371: Inputs: $text $uname $udom $symb $target
1.116 albertel 4372:
4373: Returns: A link to grades.pm such as to see the SUBM view of a student
4374:
4375: =cut
4376:
4377: ###############################################
4378: sub submlink {
1.242 albertel 4379: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4380: if (!($uname && $udom)) {
4381: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4382: &Apache::lonnet::whichuser($symb);
1.116 albertel 4383: if (!$symb) { $symb=$cursymb; }
4384: }
1.254 matthew 4385: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4386: $symb=&escape($symb);
1.960 bisitz 4387: if ($target) { $target=" target=\"$target\""; }
4388: return
4389: '<a href="/adm/grades?command=submission'.
4390: '&symb='.$symb.
4391: '&student='.$uname.
4392: '&userdom='.$udom.'"'.
4393: $target.'>'.$text.'</a>';
1.242 albertel 4394: }
4395: ##############################################
4396:
4397: =pod
4398:
4399: =item * &pgrdlink()
4400:
4401: Inputs: $text $uname $udom $symb $target
4402:
4403: Returns: A link to grades.pm such as to see the PGRD view of a student
4404:
4405: =cut
4406:
4407: ###############################################
4408: sub pgrdlink {
4409: my $link=&submlink(@_);
4410: $link=~s/(&command=submission)/$1&showgrading=yes/;
4411: return $link;
4412: }
4413: ##############################################
4414:
4415: =pod
4416:
4417: =item * &pprmlink()
4418:
4419: Inputs: $text $uname $udom $symb $target
4420:
4421: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4422: student and a specific resource
1.242 albertel 4423:
4424: =cut
4425:
4426: ###############################################
4427: sub pprmlink {
4428: my ($text,$uname,$udom,$symb,$target)=@_;
4429: if (!($uname && $udom)) {
4430: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4431: &Apache::lonnet::whichuser($symb);
1.242 albertel 4432: if (!$symb) { $symb=$cursymb; }
4433: }
1.254 matthew 4434: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4435: $symb=&escape($symb);
1.242 albertel 4436: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4437: return '<a href="/adm/parmset?command=set&'.
4438: 'symb='.$symb.'&uname='.$uname.
4439: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4440: }
4441: ##############################################
1.37 matthew 4442:
1.112 bowersj2 4443: =pod
4444:
4445: =back
4446:
4447: =cut
4448:
1.37 matthew 4449: ###############################################
1.51 www 4450:
4451:
4452: sub timehash {
1.687 raeburn 4453: my ($thistime) = @_;
4454: my $timezone = &Apache::lonlocal::gettimezone();
4455: my $dt = DateTime->from_epoch(epoch => $thistime)
4456: ->set_time_zone($timezone);
4457: my $wday = $dt->day_of_week();
4458: if ($wday == 7) { $wday = 0; }
4459: return ( 'second' => $dt->second(),
4460: 'minute' => $dt->minute(),
4461: 'hour' => $dt->hour(),
4462: 'day' => $dt->day_of_month(),
4463: 'month' => $dt->month(),
4464: 'year' => $dt->year(),
4465: 'weekday' => $wday,
4466: 'dayyear' => $dt->day_of_year(),
4467: 'dlsav' => $dt->is_dst() );
1.51 www 4468: }
4469:
1.370 www 4470: sub utc_string {
4471: my ($date)=@_;
1.371 www 4472: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4473: }
4474:
1.51 www 4475: sub maketime {
4476: my %th=@_;
1.687 raeburn 4477: my ($epoch_time,$timezone,$dt);
4478: $timezone = &Apache::lonlocal::gettimezone();
4479: eval {
4480: $dt = DateTime->new( year => $th{'year'},
4481: month => $th{'month'},
4482: day => $th{'day'},
4483: hour => $th{'hour'},
4484: minute => $th{'minute'},
4485: second => $th{'second'},
4486: time_zone => $timezone,
4487: );
4488: };
4489: if (!$@) {
4490: $epoch_time = $dt->epoch;
4491: if ($epoch_time) {
4492: return $epoch_time;
4493: }
4494: }
1.51 www 4495: return POSIX::mktime(
4496: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4497: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4498: }
4499:
4500: #########################################
1.51 www 4501:
4502: sub findallcourses {
1.482 raeburn 4503: my ($roles,$uname,$udom) = @_;
1.355 albertel 4504: my %roles;
4505: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4506: my %courses;
1.51 www 4507: my $now=time;
1.482 raeburn 4508: if (!defined($uname)) {
4509: $uname = $env{'user.name'};
4510: }
4511: if (!defined($udom)) {
4512: $udom = $env{'user.domain'};
4513: }
4514: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4515: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4516: if (!%roles) {
4517: %roles = (
4518: cc => 1,
1.907 raeburn 4519: co => 1,
1.482 raeburn 4520: in => 1,
4521: ep => 1,
4522: ta => 1,
4523: cr => 1,
4524: st => 1,
4525: );
4526: }
4527: foreach my $entry (keys(%roleshash)) {
4528: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4529: if ($trole =~ /^cr/) {
4530: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4531: } else {
4532: next if (!exists($roles{$trole}));
4533: }
4534: if ($tend) {
4535: next if ($tend < $now);
4536: }
4537: if ($tstart) {
4538: next if ($tstart > $now);
4539: }
1.1058 raeburn 4540: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4541: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4542: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4543: if ($secpart eq '') {
4544: ($cnum,$role) = split(/_/,$cnumpart);
4545: $sec = 'none';
1.1058 raeburn 4546: $value .= $cnum.'/';
1.482 raeburn 4547: } else {
4548: $cnum = $cnumpart;
4549: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4550: $value .= $cnum.'/'.$sec;
4551: }
4552: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4553: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4554: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4555: }
4556: } else {
4557: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4558: }
1.482 raeburn 4559: }
4560: } else {
4561: foreach my $key (keys(%env)) {
1.483 albertel 4562: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4563: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4564: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4565: next if ($role eq 'ca' || $role eq 'aa');
4566: next if (%roles && !exists($roles{$role}));
4567: my ($starttime,$endtime)=split(/\./,$env{$key});
4568: my $active=1;
4569: if ($starttime) {
4570: if ($now<$starttime) { $active=0; }
4571: }
4572: if ($endtime) {
4573: if ($now>$endtime) { $active=0; }
4574: }
4575: if ($active) {
1.1058 raeburn 4576: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4577: if ($sec eq '') {
4578: $sec = 'none';
1.1058 raeburn 4579: } else {
4580: $value .= $sec;
4581: }
4582: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4583: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4584: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4585: }
4586: } else {
4587: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4588: }
1.474 raeburn 4589: }
4590: }
1.51 www 4591: }
4592: }
1.474 raeburn 4593: return %courses;
1.51 www 4594: }
1.37 matthew 4595:
1.54 www 4596: ###############################################
1.474 raeburn 4597:
4598: sub blockcheck {
1.1075.2.73 raeburn 4599: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4600:
1.1075.2.73 raeburn 4601: if (defined($udom) && defined($uname)) {
4602: # If uname and udom are for a course, check for blocks in the course.
4603: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4604: my ($startblock,$endblock,$triggerblock) =
4605: &get_blocks($setters,$activity,$udom,$uname,$url);
4606: return ($startblock,$endblock,$triggerblock);
4607: }
4608: } else {
1.490 raeburn 4609: $udom = $env{'user.domain'};
4610: $uname = $env{'user.name'};
4611: }
4612:
1.502 raeburn 4613: my $startblock = 0;
4614: my $endblock = 0;
1.1062 raeburn 4615: my $triggerblock = '';
1.482 raeburn 4616: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4617:
1.490 raeburn 4618: # If uname is for a user, and activity is course-specific, i.e.,
4619: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4620:
1.490 raeburn 4621: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.73 raeburn 4622: $activity eq 'groups' || $activity eq 'printout') &&
4623: ($env{'request.course.id'})) {
1.490 raeburn 4624: foreach my $key (keys(%live_courses)) {
4625: if ($key ne $env{'request.course.id'}) {
4626: delete($live_courses{$key});
4627: }
4628: }
4629: }
4630:
4631: my $otheruser = 0;
4632: my %own_courses;
4633: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4634: # Resource belongs to user other than current user.
4635: $otheruser = 1;
4636: # Gather courses for current user
4637: %own_courses =
4638: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4639: }
4640:
4641: # Gather active course roles - course coordinator, instructor,
4642: # exam proctor, ta, student, or custom role.
1.474 raeburn 4643:
4644: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4645: my ($cdom,$cnum);
4646: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4647: $cdom = $env{'course.'.$course.'.domain'};
4648: $cnum = $env{'course.'.$course.'.num'};
4649: } else {
1.490 raeburn 4650: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4651: }
4652: my $no_ownblock = 0;
4653: my $no_userblock = 0;
1.533 raeburn 4654: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4655: # Check if current user has 'evb' priv for this
4656: if (defined($own_courses{$course})) {
4657: foreach my $sec (keys(%{$own_courses{$course}})) {
4658: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4659: if ($sec ne 'none') {
4660: $checkrole .= '/'.$sec;
4661: }
4662: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4663: $no_ownblock = 1;
4664: last;
4665: }
4666: }
4667: }
4668: # if they have 'evb' priv and are currently not playing student
4669: next if (($no_ownblock) &&
4670: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4671: }
1.474 raeburn 4672: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4673: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4674: if ($sec ne 'none') {
1.482 raeburn 4675: $checkrole .= '/'.$sec;
1.474 raeburn 4676: }
1.490 raeburn 4677: if ($otheruser) {
4678: # Resource belongs to user other than current user.
4679: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4680: my (%allroles,%userroles);
4681: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4682: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4683: my ($trole,$tdom,$tnum,$tsec);
4684: if ($entry =~ /^cr/) {
4685: ($trole,$tdom,$tnum,$tsec) =
4686: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4687: } else {
4688: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4689: }
4690: my ($spec,$area,$trest);
4691: $area = '/'.$tdom.'/'.$tnum;
4692: $trest = $tnum;
4693: if ($tsec ne '') {
4694: $area .= '/'.$tsec;
4695: $trest .= '/'.$tsec;
4696: }
4697: $spec = $trole.'.'.$area;
4698: if ($trole =~ /^cr/) {
4699: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4700: $tdom,$spec,$trest,$area);
4701: } else {
4702: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4703: $tdom,$spec,$trest,$area);
4704: }
4705: }
1.1075.2.124 raeburn 4706: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 4707: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4708: if ($1) {
4709: $no_userblock = 1;
4710: last;
4711: }
1.486 raeburn 4712: }
4713: }
1.490 raeburn 4714: } else {
4715: # Resource belongs to current user
4716: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4717: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4718: $no_ownblock = 1;
4719: last;
4720: }
1.474 raeburn 4721: }
4722: }
4723: # if they have the evb priv and are currently not playing student
1.482 raeburn 4724: next if (($no_ownblock) &&
1.491 albertel 4725: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4726: next if ($no_userblock);
1.474 raeburn 4727:
1.1075.2.128 raeburn 4728: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 4729: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4730:
1.1062 raeburn 4731: my ($start,$end,$trigger) =
4732: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4733: if (($start != 0) &&
4734: (($startblock == 0) || ($startblock > $start))) {
4735: $startblock = $start;
1.1062 raeburn 4736: if ($trigger ne '') {
4737: $triggerblock = $trigger;
4738: }
1.502 raeburn 4739: }
4740: if (($end != 0) &&
4741: (($endblock == 0) || ($endblock < $end))) {
4742: $endblock = $end;
1.1062 raeburn 4743: if ($trigger ne '') {
4744: $triggerblock = $trigger;
4745: }
1.502 raeburn 4746: }
1.490 raeburn 4747: }
1.1062 raeburn 4748: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4749: }
4750:
4751: sub get_blocks {
1.1062 raeburn 4752: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4753: my $startblock = 0;
4754: my $endblock = 0;
1.1062 raeburn 4755: my $triggerblock = '';
1.490 raeburn 4756: my $course = $cdom.'_'.$cnum;
4757: $setters->{$course} = {};
4758: $setters->{$course}{'staff'} = [];
4759: $setters->{$course}{'times'} = [];
1.1062 raeburn 4760: $setters->{$course}{'triggers'} = [];
4761: my (@blockers,%triggered);
4762: my $now = time;
4763: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4764: if ($activity eq 'docs') {
4765: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4766: foreach my $block (@blockers) {
4767: if ($block =~ /^firstaccess____(.+)$/) {
4768: my $item = $1;
4769: my $type = 'map';
4770: my $timersymb = $item;
4771: if ($item eq 'course') {
4772: $type = 'course';
4773: } elsif ($item =~ /___\d+___/) {
4774: $type = 'resource';
4775: } else {
4776: $timersymb = &Apache::lonnet::symbread($item);
4777: }
4778: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4779: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4780: $triggered{$block} = {
4781: start => $start,
4782: end => $end,
4783: type => $type,
4784: };
4785: }
4786: }
4787: } else {
4788: foreach my $block (keys(%commblocks)) {
4789: if ($block =~ m/^(\d+)____(\d+)$/) {
4790: my ($start,$end) = ($1,$2);
4791: if ($start <= time && $end >= time) {
4792: if (ref($commblocks{$block}) eq 'HASH') {
4793: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4794: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4795: unless(grep(/^\Q$block\E$/,@blockers)) {
4796: push(@blockers,$block);
4797: }
4798: }
4799: }
4800: }
4801: }
4802: } elsif ($block =~ /^firstaccess____(.+)$/) {
4803: my $item = $1;
4804: my $timersymb = $item;
4805: my $type = 'map';
4806: if ($item eq 'course') {
4807: $type = 'course';
4808: } elsif ($item =~ /___\d+___/) {
4809: $type = 'resource';
4810: } else {
4811: $timersymb = &Apache::lonnet::symbread($item);
4812: }
4813: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4814: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4815: if ($start && $end) {
4816: if (($start <= time) && ($end >= time)) {
4817: unless (grep(/^\Q$block\E$/,@blockers)) {
4818: push(@blockers,$block);
4819: $triggered{$block} = {
4820: start => $start,
4821: end => $end,
4822: type => $type,
4823: };
4824: }
4825: }
1.490 raeburn 4826: }
1.1062 raeburn 4827: }
4828: }
4829: }
4830: foreach my $blocker (@blockers) {
4831: my ($staff_name,$staff_dom,$title,$blocks) =
4832: &parse_block_record($commblocks{$blocker});
4833: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4834: my ($start,$end,$triggertype);
4835: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4836: ($start,$end) = ($1,$2);
4837: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4838: $start = $triggered{$blocker}{'start'};
4839: $end = $triggered{$blocker}{'end'};
4840: $triggertype = $triggered{$blocker}{'type'};
4841: }
4842: if ($start) {
4843: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4844: if ($triggertype) {
4845: push(@{$$setters{$course}{'triggers'}},$triggertype);
4846: } else {
4847: push(@{$$setters{$course}{'triggers'}},0);
4848: }
4849: if ( ($startblock == 0) || ($startblock > $start) ) {
4850: $startblock = $start;
4851: if ($triggertype) {
4852: $triggerblock = $blocker;
1.474 raeburn 4853: }
4854: }
1.1062 raeburn 4855: if ( ($endblock == 0) || ($endblock < $end) ) {
4856: $endblock = $end;
4857: if ($triggertype) {
4858: $triggerblock = $blocker;
4859: }
4860: }
1.474 raeburn 4861: }
4862: }
1.1062 raeburn 4863: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4864: }
4865:
4866: sub parse_block_record {
4867: my ($record) = @_;
4868: my ($setuname,$setudom,$title,$blocks);
4869: if (ref($record) eq 'HASH') {
4870: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4871: $title = &unescape($record->{'event'});
4872: $blocks = $record->{'blocks'};
4873: } else {
4874: my @data = split(/:/,$record,3);
4875: if (scalar(@data) eq 2) {
4876: $title = $data[1];
4877: ($setuname,$setudom) = split(/@/,$data[0]);
4878: } else {
4879: ($setuname,$setudom,$title) = @data;
4880: }
4881: $blocks = { 'com' => 'on' };
4882: }
4883: return ($setuname,$setudom,$title,$blocks);
4884: }
4885:
1.854 kalberla 4886: sub blocking_status {
1.1075.2.73 raeburn 4887: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4888: my %setters;
1.890 droeschl 4889:
1.1061 raeburn 4890: # check for active blocking
1.1062 raeburn 4891: my ($startblock,$endblock,$triggerblock) =
1.1075.2.73 raeburn 4892: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4893: my $blocked = 0;
4894: if ($startblock && $endblock) {
4895: $blocked = 1;
4896: }
1.890 droeschl 4897:
1.1061 raeburn 4898: # caller just wants to know whether a block is active
4899: if (!wantarray) { return $blocked; }
4900:
4901: # build a link to a popup window containing the details
4902: my $querystring = "?activity=$activity";
4903: # $uname and $udom decide whose portfolio the user is trying to look at
1.1075.2.97 raeburn 4904: if (($activity eq 'port') || ($activity eq 'passwd')) {
4905: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
4906: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 4907: } elsif ($activity eq 'docs') {
4908: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4909: }
1.1061 raeburn 4910:
4911: my $output .= <<'END_MYBLOCK';
4912: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4913: var options = "width=" + w + ",height=" + h + ",";
4914: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4915: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4916: var newWin = window.open(url, wdwName, options);
4917: newWin.focus();
4918: }
1.890 droeschl 4919: END_MYBLOCK
1.854 kalberla 4920:
1.1061 raeburn 4921: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4922:
1.1061 raeburn 4923: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4924: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 4925: my $class = 'LC_comblock';
1.1062 raeburn 4926: if ($activity eq 'docs') {
4927: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 4928: $class = '';
1.1063 raeburn 4929: } elsif ($activity eq 'printout') {
4930: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 4931: } elsif ($activity eq 'passwd') {
4932: $text = &mt('Password Changing Blocked');
1.1062 raeburn 4933: }
1.1061 raeburn 4934: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 4935: <div class='$class'>
1.869 kalberla 4936: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4937: title='$text'>
4938: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4939: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4940: title='$text'>$text</a>
1.867 kalberla 4941: </div>
4942:
4943: END_BLOCK
1.474 raeburn 4944:
1.1061 raeburn 4945: return ($blocked, $output);
1.854 kalberla 4946: }
1.490 raeburn 4947:
1.60 matthew 4948: ###############################################
4949:
1.682 raeburn 4950: sub check_ip_acc {
1.1075.2.105 raeburn 4951: my ($acc,$clientip)=@_;
1.682 raeburn 4952: &Apache::lonxml::debug("acc is $acc");
4953: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4954: return 1;
4955: }
4956: my $allowed=0;
1.1075.2.111 raeburn 4957: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 4958:
4959: my $name;
4960: foreach my $pattern (split(',',$acc)) {
4961: $pattern =~ s/^\s*//;
4962: $pattern =~ s/\s*$//;
4963: if ($pattern =~ /\*$/) {
4964: #35.8.*
4965: $pattern=~s/\*//;
4966: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4967: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4968: #35.8.3.[34-56]
4969: my $low=$2;
4970: my $high=$3;
4971: $pattern=$1;
4972: if ($ip =~ /^\Q$pattern\E/) {
4973: my $last=(split(/\./,$ip))[3];
4974: if ($last <=$high && $last >=$low) { $allowed=1; }
4975: }
4976: } elsif ($pattern =~ /^\*/) {
4977: #*.msu.edu
4978: $pattern=~s/\*//;
4979: if (!defined($name)) {
4980: use Socket;
4981: my $netaddr=inet_aton($ip);
4982: ($name)=gethostbyaddr($netaddr,AF_INET);
4983: }
4984: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4985: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4986: #127.0.0.1
4987: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4988: } else {
4989: #some.name.com
4990: if (!defined($name)) {
4991: use Socket;
4992: my $netaddr=inet_aton($ip);
4993: ($name)=gethostbyaddr($netaddr,AF_INET);
4994: }
4995: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4996: }
4997: if ($allowed) { last; }
4998: }
4999: return $allowed;
5000: }
5001:
5002: ###############################################
5003:
1.60 matthew 5004: =pod
5005:
1.112 bowersj2 5006: =head1 Domain Template Functions
5007:
5008: =over 4
5009:
5010: =item * &determinedomain()
1.60 matthew 5011:
5012: Inputs: $domain (usually will be undef)
5013:
1.63 www 5014: Returns: Determines which domain should be used for designs
1.60 matthew 5015:
5016: =cut
1.54 www 5017:
1.60 matthew 5018: ###############################################
1.63 www 5019: sub determinedomain {
5020: my $domain=shift;
1.531 albertel 5021: if (! $domain) {
1.60 matthew 5022: # Determine domain if we have not been given one
1.893 raeburn 5023: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5024: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5025: if ($env{'request.role.domain'}) {
5026: $domain=$env{'request.role.domain'};
1.60 matthew 5027: }
5028: }
1.63 www 5029: return $domain;
5030: }
5031: ###############################################
1.517 raeburn 5032:
1.518 albertel 5033: sub devalidate_domconfig_cache {
5034: my ($udom)=@_;
5035: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5036: }
5037:
5038: # ---------------------- Get domain configuration for a domain
5039: sub get_domainconf {
5040: my ($udom) = @_;
5041: my $cachetime=1800;
5042: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5043: if (defined($cached)) { return %{$result}; }
5044:
5045: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5046: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5047: my (%designhash,%legacy);
1.518 albertel 5048: if (keys(%domconfig) > 0) {
5049: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5050: if (keys(%{$domconfig{'login'}})) {
5051: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5052: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5053: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5054: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5055: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5056: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5057: if ($key eq 'loginvia') {
5058: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5059: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5060: $designhash{$udom.'.login.loginvia'} = $server;
5061: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5062: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5063: } else {
5064: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5065: }
1.948 raeburn 5066: }
1.1075.2.87 raeburn 5067: } elsif ($key eq 'headtag') {
5068: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5069: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5070: }
1.946 raeburn 5071: }
1.1075.2.87 raeburn 5072: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5073: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5074: }
1.946 raeburn 5075: }
5076: }
5077: }
5078: } else {
5079: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5080: $designhash{$udom.'.login.'.$key.'_'.$img} =
5081: $domconfig{'login'}{$key}{$img};
5082: }
1.699 raeburn 5083: }
5084: } else {
5085: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5086: }
1.632 raeburn 5087: }
5088: } else {
5089: $legacy{'login'} = 1;
1.518 albertel 5090: }
1.632 raeburn 5091: } else {
5092: $legacy{'login'} = 1;
1.518 albertel 5093: }
5094: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5095: if (keys(%{$domconfig{'rolecolors'}})) {
5096: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5097: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5098: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5099: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5100: }
1.518 albertel 5101: }
5102: }
1.632 raeburn 5103: } else {
5104: $legacy{'rolecolors'} = 1;
1.518 albertel 5105: }
1.632 raeburn 5106: } else {
5107: $legacy{'rolecolors'} = 1;
1.518 albertel 5108: }
1.948 raeburn 5109: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5110: if ($domconfig{'autoenroll'}{'co-owners'}) {
5111: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5112: }
5113: }
1.632 raeburn 5114: if (keys(%legacy) > 0) {
5115: my %legacyhash = &get_legacy_domconf($udom);
5116: foreach my $item (keys(%legacyhash)) {
5117: if ($item =~ /^\Q$udom\E\.login/) {
5118: if ($legacy{'login'}) {
5119: $designhash{$item} = $legacyhash{$item};
5120: }
5121: } else {
5122: if ($legacy{'rolecolors'}) {
5123: $designhash{$item} = $legacyhash{$item};
5124: }
1.518 albertel 5125: }
5126: }
5127: }
1.632 raeburn 5128: } else {
5129: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5130: }
5131: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5132: $cachetime);
5133: return %designhash;
5134: }
5135:
1.632 raeburn 5136: sub get_legacy_domconf {
5137: my ($udom) = @_;
5138: my %legacyhash;
5139: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5140: my $designfile = $designdir.'/'.$udom.'.tab';
5141: if (-e $designfile) {
1.1075.2.128 raeburn 5142: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5143: while (my $line = <$fh>) {
5144: next if ($line =~ /^\#/);
5145: chomp($line);
5146: my ($key,$val)=(split(/\=/,$line));
5147: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5148: }
5149: close($fh);
5150: }
5151: }
1.1026 raeburn 5152: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5153: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5154: }
5155: return %legacyhash;
5156: }
5157:
1.63 www 5158: =pod
5159:
1.112 bowersj2 5160: =item * &domainlogo()
1.63 www 5161:
5162: Inputs: $domain (usually will be undef)
5163:
5164: Returns: A link to a domain logo, if the domain logo exists.
5165: If the domain logo does not exist, a description of the domain.
5166:
5167: =cut
1.112 bowersj2 5168:
1.63 www 5169: ###############################################
5170: sub domainlogo {
1.517 raeburn 5171: my $domain = &determinedomain(shift);
1.518 albertel 5172: my %designhash = &get_domainconf($domain);
1.517 raeburn 5173: # See if there is a logo
5174: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5175: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5176: if ($imgsrc =~ m{^/(adm|res)/}) {
5177: if ($imgsrc =~ m{^/res/}) {
5178: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5179: &Apache::lonnet::repcopy($local_name);
5180: }
5181: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5182: }
5183: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5184: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5185: return &Apache::lonnet::domain($domain,'description');
1.59 www 5186: } else {
1.60 matthew 5187: return '';
1.59 www 5188: }
5189: }
1.63 www 5190: ##############################################
5191:
5192: =pod
5193:
1.112 bowersj2 5194: =item * &designparm()
1.63 www 5195:
5196: Inputs: $which parameter; $domain (usually will be undef)
5197:
5198: Returns: value of designparamter $which
5199:
5200: =cut
1.112 bowersj2 5201:
1.397 albertel 5202:
1.400 albertel 5203: ##############################################
1.397 albertel 5204: sub designparm {
5205: my ($which,$domain)=@_;
5206: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5207: return $env{'environment.color.'.$which};
1.96 www 5208: }
1.63 www 5209: $domain=&determinedomain($domain);
1.1016 raeburn 5210: my %domdesign;
5211: unless ($domain eq 'public') {
5212: %domdesign = &get_domainconf($domain);
5213: }
1.520 raeburn 5214: my $output;
1.517 raeburn 5215: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5216: $output = $domdesign{$domain.'.'.$which};
1.63 www 5217: } else {
1.520 raeburn 5218: $output = $defaultdesign{$which};
5219: }
5220: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5221: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5222: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5223: if ($output =~ m{^/res/}) {
5224: my $local_name = &Apache::lonnet::filelocation('',$output);
5225: &Apache::lonnet::repcopy($local_name);
5226: }
1.520 raeburn 5227: $output = &lonhttpdurl($output);
5228: }
1.63 www 5229: }
1.520 raeburn 5230: return $output;
1.63 www 5231: }
1.59 www 5232:
1.822 bisitz 5233: ##############################################
5234: =pod
5235:
1.832 bisitz 5236: =item * &authorspace()
5237:
1.1028 raeburn 5238: Inputs: $url (usually will be undef).
1.832 bisitz 5239:
1.1075.2.40 raeburn 5240: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5241: directory being viewed (or for which action is being taken).
5242: If $url is provided, and begins /priv/<domain>/<uname>
5243: the path will be that portion of the $context argument.
5244: Otherwise the path will be for the author space of the current
5245: user when the current role is author, or for that of the
5246: co-author/assistant co-author space when the current role
5247: is co-author or assistant co-author.
1.832 bisitz 5248:
5249: =cut
5250:
5251: sub authorspace {
1.1028 raeburn 5252: my ($url) = @_;
5253: if ($url ne '') {
5254: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5255: return $1;
5256: }
5257: }
1.832 bisitz 5258: my $caname = '';
1.1024 www 5259: my $cadom = '';
1.1028 raeburn 5260: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5261: ($cadom,$caname) =
1.832 bisitz 5262: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5263: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5264: $caname = $env{'user.name'};
1.1024 www 5265: $cadom = $env{'user.domain'};
1.832 bisitz 5266: }
1.1028 raeburn 5267: if (($caname ne '') && ($cadom ne '')) {
5268: return "/priv/$cadom/$caname/";
5269: }
5270: return;
1.832 bisitz 5271: }
5272:
5273: ##############################################
5274: =pod
5275:
1.822 bisitz 5276: =item * &head_subbox()
5277:
5278: Inputs: $content (contains HTML code with page functions, etc.)
5279:
5280: Returns: HTML div with $content
5281: To be included in page header
5282:
5283: =cut
5284:
5285: sub head_subbox {
5286: my ($content)=@_;
5287: my $output =
1.993 raeburn 5288: '<div class="LC_head_subbox">'
1.822 bisitz 5289: .$content
5290: .'</div>'
5291: }
5292:
5293: ##############################################
5294: =pod
5295:
5296: =item * &CSTR_pageheader()
5297:
1.1026 raeburn 5298: Input: (optional) filename from which breadcrumb trail is built.
5299: In most cases no input as needed, as $env{'request.filename'}
5300: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5301:
5302: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5303: To be included on Authoring Space pages
1.822 bisitz 5304:
5305: =cut
5306:
5307: sub CSTR_pageheader {
1.1026 raeburn 5308: my ($trailfile) = @_;
5309: if ($trailfile eq '') {
5310: $trailfile = $env{'request.filename'};
5311: }
5312:
5313: # this is for resources; directories have customtitle, and crumbs
5314: # and select recent are created in lonpubdir.pm
5315:
5316: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5317: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5318: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5319: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5320: $formaction =~ s{/+}{/}g;
1.822 bisitz 5321:
5322: my $parentpath = '';
5323: my $lastitem = '';
5324: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5325: $parentpath = $1;
5326: $lastitem = $2;
5327: } else {
5328: $lastitem = $thisdisfn;
5329: }
1.921 bisitz 5330:
5331: my $output =
1.822 bisitz 5332: '<div>'
5333: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5334: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5335: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5336: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5337: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5338:
5339: if ($lastitem) {
5340: $output .=
5341: '<span class="LC_filename">'
5342: .$lastitem
5343: .'</span>';
5344: }
5345: $output .=
5346: '<br />'
1.822 bisitz 5347: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5348: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5349: .'</form>'
5350: .&Apache::lonmenu::constspaceform()
5351: .'</div>';
1.921 bisitz 5352:
5353: return $output;
1.822 bisitz 5354: }
5355:
1.60 matthew 5356: ###############################################
5357: ###############################################
5358:
5359: =pod
5360:
1.112 bowersj2 5361: =back
5362:
1.549 albertel 5363: =head1 HTML Helpers
1.112 bowersj2 5364:
5365: =over 4
5366:
5367: =item * &bodytag()
1.60 matthew 5368:
5369: Returns a uniform header for LON-CAPA web pages.
5370:
5371: Inputs:
5372:
1.112 bowersj2 5373: =over 4
5374:
5375: =item * $title, A title to be displayed on the page.
5376:
5377: =item * $function, the current role (can be undef).
5378:
5379: =item * $addentries, extra parameters for the <body> tag.
5380:
5381: =item * $bodyonly, if defined, only return the <body> tag.
5382:
5383: =item * $domain, if defined, force a given domain.
5384:
5385: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5386: text interface only)
1.60 matthew 5387:
1.814 bisitz 5388: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5389: navigational links
1.317 albertel 5390:
1.338 albertel 5391: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5392:
1.1075.2.12 raeburn 5393: =item * $no_inline_link, if true and in remote mode, don't show the
5394: 'Switch To Inline Menu' link
5395:
1.460 albertel 5396: =item * $args, optional argument valid values are
5397: no_auto_mt_title -> prevents &mt()ing the title arg
1.1075.2.133 raeburn 5398: use_absolute -> for external resource or syllabus, this will
5399: contain https://<hostname> if server uses
5400: https (as per hosts.tab), but request is for http
5401: hostname -> hostname, from $r->hostname().
1.460 albertel 5402:
1.1075.2.15 raeburn 5403: =item * $advtoolsref, optional argument, ref to an array containing
5404: inlineremote items to be added in "Functions" menu below
5405: breadcrumbs.
5406:
1.112 bowersj2 5407: =back
5408:
1.60 matthew 5409: Returns: A uniform header for LON-CAPA web pages.
5410: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5411: If $bodyonly is undef or zero, an html string containing a <body> tag and
5412: other decorations will be returned.
5413:
5414: =cut
5415:
1.54 www 5416: sub bodytag {
1.831 bisitz 5417: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5418: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5419:
1.954 raeburn 5420: my $public;
5421: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5422: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5423: $public = 1;
5424: }
1.460 albertel 5425: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5426: my $httphost = $args->{'use_absolute'};
1.1075.2.133 raeburn 5427: my $hostname = $args->{'hostname'};
1.339 albertel 5428:
1.183 matthew 5429: $function = &get_users_function() if (!$function);
1.339 albertel 5430: my $img = &designparm($function.'.img',$domain);
5431: my $font = &designparm($function.'.font',$domain);
5432: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5433:
1.803 bisitz 5434: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5435: 'bgcolor' => $pgbg,
1.339 albertel 5436: 'text' => $font,
5437: 'alink' => &designparm($function.'.alink',$domain),
5438: 'vlink' => &designparm($function.'.vlink',$domain),
5439: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5440: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5441:
1.63 www 5442: # role and realm
1.1075.2.68 raeburn 5443: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5444: if ($realm) {
5445: $realm = '/'.$realm;
5446: }
1.378 raeburn 5447: if ($role eq 'ca') {
1.479 albertel 5448: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5449: $realm = &plainname($rname,$rdom);
1.378 raeburn 5450: }
1.55 www 5451: # realm
1.258 albertel 5452: if ($env{'request.course.id'}) {
1.378 raeburn 5453: if ($env{'request.role'} !~ /^cr/) {
5454: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 5455: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 5456: if ($env{'request.role.desc'}) {
5457: $role = $env{'request.role.desc'};
5458: } else {
5459: $role = &mt('Helpdesk[_1]',' '.$2);
5460: }
1.1075.2.115 raeburn 5461: } else {
5462: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5463: }
1.898 raeburn 5464: if ($env{'request.course.sec'}) {
5465: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5466: }
1.359 albertel 5467: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5468: } else {
5469: $role = &Apache::lonnet::plaintext($role);
1.54 www 5470: }
1.433 albertel 5471:
1.359 albertel 5472: if (!$realm) { $realm=' '; }
1.330 albertel 5473:
1.438 albertel 5474: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5475:
1.101 www 5476: # construct main body tag
1.359 albertel 5477: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5478: &Apache::lontexconvert::init_math_support();
1.252 albertel 5479:
1.1075.2.38 raeburn 5480: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5481:
5482: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5483: return $bodytag;
1.1075.2.38 raeburn 5484: }
1.359 albertel 5485:
1.954 raeburn 5486: if ($public) {
1.433 albertel 5487: undef($role);
5488: }
1.359 albertel 5489:
1.762 bisitz 5490: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5491: #
5492: # Extra info if you are the DC
5493: my $dc_info = '';
5494: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5495: $env{'course.'.$env{'request.course.id'}.
5496: '.domain'}.'/'})) {
5497: my $cid = $env{'request.course.id'};
1.917 raeburn 5498: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5499: $dc_info =~ s/\s+$//;
1.359 albertel 5500: }
5501:
1.1075.2.108 raeburn 5502: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 5503:
1.1075.2.13 raeburn 5504: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5505:
1.1075.2.38 raeburn 5506:
5507:
1.1075.2.21 raeburn 5508: my $funclist;
5509: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5510: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5511: Apache::lonmenu::serverform();
5512: my $forbodytag;
5513: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5514: $forcereg,$args->{'group'},
5515: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5516: $advtoolsref,'','',\$forbodytag);
1.1075.2.21 raeburn 5517: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5518: $funclist = $forbodytag;
5519: }
5520: } else {
1.903 droeschl 5521:
5522: # if ($env{'request.state'} eq 'construct') {
5523: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5524: # }
5525:
1.1075.2.38 raeburn 5526: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5527: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5528:
1.1075.2.38 raeburn 5529: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5530:
1.916 droeschl 5531: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5532: if ($dc_info) {
5533: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5534: }
1.1075.2.38 raeburn 5535: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5536: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5537: return $bodytag;
5538: }
1.894 droeschl 5539:
1.927 raeburn 5540: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5541: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5542: }
1.916 droeschl 5543:
1.1075.2.38 raeburn 5544: $bodytag .= $right;
1.852 droeschl 5545:
1.917 raeburn 5546: if ($dc_info) {
5547: $dc_info = &dc_courseid_toggle($dc_info);
5548: }
5549: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5550:
1.1075.2.61 raeburn 5551: #if directed to not display the secondary menu, don't.
5552: if ($args->{'no_secondary_menu'}) {
5553: return $bodytag;
5554: }
1.903 droeschl 5555: #don't show menus for public users
1.954 raeburn 5556: if (!$public){
1.1075.2.52 raeburn 5557: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5558: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5559: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5560: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5561: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.133 raeburn 5562: $args->{'bread_crumbs'},'','',$hostname);
1.1075.2.116 raeburn 5563: } elsif ($forcereg) {
1.1075.2.22 raeburn 5564: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5565: $args->{'group'},
1.1075.2.133 raeburn 5566: $args->{'hide_buttons',
5567: $hostname});
1.1075.2.15 raeburn 5568: } else {
1.1075.2.21 raeburn 5569: my $forbodytag;
5570: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5571: $forcereg,$args->{'group'},
5572: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5573: $advtoolsref,'',$hostname,
5574: \$forbodytag);
1.1075.2.21 raeburn 5575: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5576: $bodytag .= $forbodytag;
5577: }
1.920 raeburn 5578: }
1.903 droeschl 5579: }else{
5580: # this is to seperate menu from content when there's no secondary
5581: # menu. Especially needed for public accessible ressources.
5582: $bodytag .= '<hr style="clear:both" />';
5583: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5584: }
1.903 droeschl 5585:
1.235 raeburn 5586: return $bodytag;
1.1075.2.12 raeburn 5587: }
5588:
5589: #
5590: # Top frame rendering, Remote is up
5591: #
5592:
5593: my $imgsrc = $img;
5594: if ($img =~ /^\/adm/) {
5595: $imgsrc = &lonhttpdurl($img);
5596: }
5597: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5598:
1.1075.2.60 raeburn 5599: my $help=($no_inline_link?''
5600: :&Apache::loncommon::top_nav_help('Help'));
5601:
1.1075.2.12 raeburn 5602: # Explicit link to get inline menu
5603: my $menu= ($no_inline_link?''
5604: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5605:
5606: if ($dc_info) {
5607: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5608: }
5609:
1.1075.2.38 raeburn 5610: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5611: unless ($public) {
5612: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5613: undef,'LC_menubuttons_link');
5614: }
5615:
1.1075.2.12 raeburn 5616: unless ($env{'form.inhibitmenu'}) {
5617: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5618: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5619: <li>$help</li>
1.1075.2.12 raeburn 5620: <li>$menu</li>
5621: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5622: }
1.1075.2.13 raeburn 5623: if ($env{'request.state'} eq 'construct') {
5624: if (!$public){
5625: if ($env{'request.state'} eq 'construct') {
5626: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5627: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5628: &Apache::lonhtmlcommon::scripttag('','end').
5629: &Apache::lonmenu::innerregister($forcereg,
5630: $args->{'bread_crumbs'});
5631: }
5632: }
5633: }
1.1075.2.21 raeburn 5634: return $bodytag."\n".$funclist;
1.182 matthew 5635: }
5636:
1.917 raeburn 5637: sub dc_courseid_toggle {
5638: my ($dc_info) = @_;
1.980 raeburn 5639: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5640: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5641: &mt('(More ...)').'</a></span>'.
5642: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5643: }
5644:
1.330 albertel 5645: sub make_attr_string {
5646: my ($register,$attr_ref) = @_;
5647:
5648: if ($attr_ref && !ref($attr_ref)) {
5649: die("addentries Must be a hash ref ".
5650: join(':',caller(1))." ".
5651: join(':',caller(0))." ");
5652: }
5653:
5654: if ($register) {
1.339 albertel 5655: my ($on_load,$on_unload);
5656: foreach my $key (keys(%{$attr_ref})) {
5657: if (lc($key) eq 'onload') {
5658: $on_load.=$attr_ref->{$key}.';';
5659: delete($attr_ref->{$key});
5660:
5661: } elsif (lc($key) eq 'onunload') {
5662: $on_unload.=$attr_ref->{$key}.';';
5663: delete($attr_ref->{$key});
5664: }
5665: }
1.1075.2.12 raeburn 5666: if ($env{'environment.remote'} eq 'on') {
5667: $attr_ref->{'onload'} =
5668: &Apache::lonmenu::loadevents(). $on_load;
5669: $attr_ref->{'onunload'}=
5670: &Apache::lonmenu::unloadevents().$on_unload;
5671: } else {
5672: $attr_ref->{'onload'} = $on_load;
5673: $attr_ref->{'onunload'}= $on_unload;
5674: }
1.330 albertel 5675: }
1.339 albertel 5676:
1.330 albertel 5677: my $attr_string;
1.1075.2.56 raeburn 5678: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5679: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5680: }
5681: return $attr_string;
5682: }
5683:
5684:
1.182 matthew 5685: ###############################################
1.251 albertel 5686: ###############################################
5687:
5688: =pod
5689:
5690: =item * &endbodytag()
5691:
5692: Returns a uniform footer for LON-CAPA web pages.
5693:
1.635 raeburn 5694: Inputs: 1 - optional reference to an args hash
5695: If in the hash, key for noredirectlink has a value which evaluates to true,
5696: a 'Continue' link is not displayed if the page contains an
5697: internal redirect in the <head></head> section,
5698: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5699:
5700: =cut
5701:
5702: sub endbodytag {
1.635 raeburn 5703: my ($args) = @_;
1.1075.2.6 raeburn 5704: my $endbodytag;
5705: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5706: $endbodytag='</body>';
5707: }
1.315 albertel 5708: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5709: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5710: $endbodytag=
5711: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5712: &mt('Continue').'</a>'.
5713: $endbodytag;
5714: }
1.315 albertel 5715: }
1.251 albertel 5716: return $endbodytag;
5717: }
5718:
1.352 albertel 5719: =pod
5720:
5721: =item * &standard_css()
5722:
5723: Returns a style sheet
5724:
5725: Inputs: (all optional)
5726: domain -> force to color decorate a page for a specific
5727: domain
5728: function -> force usage of a specific rolish color scheme
5729: bgcolor -> override the default page bgcolor
5730:
5731: =cut
5732:
1.343 albertel 5733: sub standard_css {
1.345 albertel 5734: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5735: $function = &get_users_function() if (!$function);
5736: my $img = &designparm($function.'.img', $domain);
5737: my $tabbg = &designparm($function.'.tabbg', $domain);
5738: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5739: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5740: #second colour for later usage
1.345 albertel 5741: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5742: my $pgbg_or_bgcolor =
5743: $bgcolor ||
1.352 albertel 5744: &designparm($function.'.pgbg', $domain);
1.382 albertel 5745: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5746: my $alink = &designparm($function.'.alink', $domain);
5747: my $vlink = &designparm($function.'.vlink', $domain);
5748: my $link = &designparm($function.'.link', $domain);
5749:
1.602 albertel 5750: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5751: my $mono = 'monospace';
1.850 bisitz 5752: my $data_table_head = $sidebg;
5753: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5754: my $data_table_dark = '#E0E0E0';
1.470 banghart 5755: my $data_table_darker = '#CCCCCC';
1.349 albertel 5756: my $data_table_highlight = '#FFFF00';
1.352 albertel 5757: my $mail_new = '#FFBB77';
5758: my $mail_new_hover = '#DD9955';
5759: my $mail_read = '#BBBB77';
5760: my $mail_read_hover = '#999944';
5761: my $mail_replied = '#AAAA88';
5762: my $mail_replied_hover = '#888855';
5763: my $mail_other = '#99BBBB';
5764: my $mail_other_hover = '#669999';
1.391 albertel 5765: my $table_header = '#DDDDDD';
1.489 raeburn 5766: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5767: my $lg_border_color = '#C8C8C8';
1.952 onken 5768: my $button_hover = '#BF2317';
1.392 albertel 5769:
1.608 albertel 5770: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5771: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5772: : '0 3px 0 4px';
1.448 albertel 5773:
1.523 albertel 5774:
1.343 albertel 5775: return <<END;
1.947 droeschl 5776:
5777: /* needed for iframe to allow 100% height in FF */
5778: body, html {
5779: margin: 0;
5780: padding: 0 0.5%;
5781: height: 99%; /* to avoid scrollbars */
5782: }
5783:
1.795 www 5784: body {
1.911 bisitz 5785: font-family: $sans;
5786: line-height:130%;
5787: font-size:0.83em;
5788: color:$font;
1.795 www 5789: }
5790:
1.959 onken 5791: a:focus,
5792: a:focus img {
1.795 www 5793: color: red;
5794: }
1.698 harmsja 5795:
1.911 bisitz 5796: form, .inline {
5797: display: inline;
1.795 www 5798: }
1.721 harmsja 5799:
1.795 www 5800: .LC_right {
1.911 bisitz 5801: text-align:right;
1.795 www 5802: }
5803:
5804: .LC_middle {
1.911 bisitz 5805: vertical-align:middle;
1.795 www 5806: }
1.721 harmsja 5807:
1.1075.2.38 raeburn 5808: .LC_floatleft {
5809: float: left;
5810: }
5811:
5812: .LC_floatright {
5813: float: right;
5814: }
5815:
1.911 bisitz 5816: .LC_400Box {
5817: width:400px;
5818: }
1.721 harmsja 5819:
1.947 droeschl 5820: .LC_iframecontainer {
5821: width: 98%;
5822: margin: 0;
5823: position: fixed;
5824: top: 8.5em;
5825: bottom: 0;
5826: }
5827:
5828: .LC_iframecontainer iframe{
5829: border: none;
5830: width: 100%;
5831: height: 100%;
5832: }
5833:
1.778 bisitz 5834: .LC_filename {
5835: font-family: $mono;
5836: white-space:pre;
1.921 bisitz 5837: font-size: 120%;
1.778 bisitz 5838: }
5839:
5840: .LC_fileicon {
5841: border: none;
5842: height: 1.3em;
5843: vertical-align: text-bottom;
5844: margin-right: 0.3em;
5845: text-decoration:none;
5846: }
5847:
1.1008 www 5848: .LC_setting {
5849: text-decoration:underline;
5850: }
5851:
1.350 albertel 5852: .LC_error {
5853: color: red;
5854: }
1.795 www 5855:
1.1075.2.15 raeburn 5856: .LC_warning {
5857: color: darkorange;
5858: }
5859:
1.457 albertel 5860: .LC_diff_removed {
1.733 bisitz 5861: color: red;
1.394 albertel 5862: }
1.532 albertel 5863:
5864: .LC_info,
1.457 albertel 5865: .LC_success,
5866: .LC_diff_added {
1.350 albertel 5867: color: green;
5868: }
1.795 www 5869:
1.802 bisitz 5870: div.LC_confirm_box {
5871: background-color: #FAFAFA;
5872: border: 1px solid $lg_border_color;
5873: margin-right: 0;
5874: padding: 5px;
5875: }
5876:
5877: div.LC_confirm_box .LC_error img,
5878: div.LC_confirm_box .LC_success img {
5879: vertical-align: middle;
5880: }
5881:
1.1075.2.108 raeburn 5882: .LC_maxwidth {
5883: max-width: 100%;
5884: height: auto;
5885: }
5886:
5887: .LC_textsize_mobile {
5888: \@media only screen and (max-device-width: 480px) {
5889: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
5890: }
5891: }
5892:
1.440 albertel 5893: .LC_icon {
1.771 droeschl 5894: border: none;
1.790 droeschl 5895: vertical-align: middle;
1.771 droeschl 5896: }
5897:
1.543 albertel 5898: .LC_docs_spacer {
5899: width: 25px;
5900: height: 1px;
1.771 droeschl 5901: border: none;
1.543 albertel 5902: }
1.346 albertel 5903:
1.532 albertel 5904: .LC_internal_info {
1.735 bisitz 5905: color: #999999;
1.532 albertel 5906: }
5907:
1.794 www 5908: .LC_discussion {
1.1050 www 5909: background: $data_table_dark;
1.911 bisitz 5910: border: 1px solid black;
5911: margin: 2px;
1.794 www 5912: }
5913:
5914: .LC_disc_action_left {
1.1050 www 5915: background: $sidebg;
1.911 bisitz 5916: text-align: left;
1.1050 www 5917: padding: 4px;
5918: margin: 2px;
1.794 www 5919: }
5920:
5921: .LC_disc_action_right {
1.1050 www 5922: background: $sidebg;
1.911 bisitz 5923: text-align: right;
1.1050 www 5924: padding: 4px;
5925: margin: 2px;
1.794 www 5926: }
5927:
5928: .LC_disc_new_item {
1.911 bisitz 5929: background: white;
5930: border: 2px solid red;
1.1050 www 5931: margin: 4px;
5932: padding: 4px;
1.794 www 5933: }
5934:
5935: .LC_disc_old_item {
1.911 bisitz 5936: background: white;
1.1050 www 5937: margin: 4px;
5938: padding: 4px;
1.794 www 5939: }
5940:
1.458 albertel 5941: table.LC_pastsubmission {
5942: border: 1px solid black;
5943: margin: 2px;
5944: }
5945:
1.924 bisitz 5946: table#LC_menubuttons {
1.345 albertel 5947: width: 100%;
5948: background: $pgbg;
1.392 albertel 5949: border: 2px;
1.402 albertel 5950: border-collapse: separate;
1.803 bisitz 5951: padding: 0;
1.345 albertel 5952: }
1.392 albertel 5953:
1.801 tempelho 5954: table#LC_title_bar a {
5955: color: $fontmenu;
5956: }
1.836 bisitz 5957:
1.807 droeschl 5958: table#LC_title_bar {
1.819 tempelho 5959: clear: both;
1.836 bisitz 5960: display: none;
1.807 droeschl 5961: }
5962:
1.795 www 5963: table#LC_title_bar,
1.933 droeschl 5964: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5965: table#LC_title_bar.LC_with_remote {
1.359 albertel 5966: width: 100%;
1.392 albertel 5967: border-color: $pgbg;
5968: border-style: solid;
5969: border-width: $border;
1.379 albertel 5970: background: $pgbg;
1.801 tempelho 5971: color: $fontmenu;
1.392 albertel 5972: border-collapse: collapse;
1.803 bisitz 5973: padding: 0;
1.819 tempelho 5974: margin: 0;
1.359 albertel 5975: }
1.795 www 5976:
1.933 droeschl 5977: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5978: margin: 0;
5979: padding: 0;
1.933 droeschl 5980: position: relative;
5981: list-style: none;
1.913 droeschl 5982: }
1.933 droeschl 5983: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5984: display: inline;
5985: }
1.933 droeschl 5986:
5987: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5988: padding: 0;
1.933 droeschl 5989: margin: 0;
5990: float: left;
1.913 droeschl 5991: }
1.933 droeschl 5992: .LC_breadcrumb_tools_tools {
5993: padding: 0;
5994: margin: 0;
1.913 droeschl 5995: float: right;
5996: }
5997:
1.359 albertel 5998: table#LC_title_bar td {
5999: background: $tabbg;
6000: }
1.795 www 6001:
1.911 bisitz 6002: table#LC_menubuttons img {
1.803 bisitz 6003: border: none;
1.346 albertel 6004: }
1.795 www 6005:
1.842 droeschl 6006: .LC_breadcrumbs_component {
1.911 bisitz 6007: float: right;
6008: margin: 0 1em;
1.357 albertel 6009: }
1.842 droeschl 6010: .LC_breadcrumbs_component img {
1.911 bisitz 6011: vertical-align: middle;
1.777 tempelho 6012: }
1.795 www 6013:
1.1075.2.108 raeburn 6014: .LC_breadcrumbs_hoverable {
6015: background: $sidebg;
6016: }
6017:
1.383 albertel 6018: td.LC_table_cell_checkbox {
6019: text-align: center;
6020: }
1.795 www 6021:
6022: .LC_fontsize_small {
1.911 bisitz 6023: font-size: 70%;
1.705 tempelho 6024: }
6025:
1.844 bisitz 6026: #LC_breadcrumbs {
1.911 bisitz 6027: clear:both;
6028: background: $sidebg;
6029: border-bottom: 1px solid $lg_border_color;
6030: line-height: 2.5em;
1.933 droeschl 6031: overflow: hidden;
1.911 bisitz 6032: margin: 0;
6033: padding: 0;
1.995 raeburn 6034: text-align: left;
1.819 tempelho 6035: }
1.862 bisitz 6036:
1.1075.2.16 raeburn 6037: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6038: clear:both;
6039: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6040: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6041: margin: 0 0 10px 0;
1.966 bisitz 6042: padding: 3px;
1.995 raeburn 6043: text-align: left;
1.822 bisitz 6044: }
6045:
1.795 www 6046: .LC_fontsize_medium {
1.911 bisitz 6047: font-size: 85%;
1.705 tempelho 6048: }
6049:
1.795 www 6050: .LC_fontsize_large {
1.911 bisitz 6051: font-size: 120%;
1.705 tempelho 6052: }
6053:
1.346 albertel 6054: .LC_menubuttons_inline_text {
6055: color: $font;
1.698 harmsja 6056: font-size: 90%;
1.701 harmsja 6057: padding-left:3px;
1.346 albertel 6058: }
6059:
1.934 droeschl 6060: .LC_menubuttons_inline_text img{
6061: vertical-align: middle;
6062: }
6063:
1.1051 www 6064: li.LC_menubuttons_inline_text img {
1.951 onken 6065: cursor:pointer;
1.1002 droeschl 6066: text-decoration: none;
1.951 onken 6067: }
6068:
1.526 www 6069: .LC_menubuttons_link {
6070: text-decoration: none;
6071: }
1.795 www 6072:
1.522 albertel 6073: .LC_menubuttons_category {
1.521 www 6074: color: $font;
1.526 www 6075: background: $pgbg;
1.521 www 6076: font-size: larger;
6077: font-weight: bold;
6078: }
6079:
1.346 albertel 6080: td.LC_menubuttons_text {
1.911 bisitz 6081: color: $font;
1.346 albertel 6082: }
1.706 harmsja 6083:
1.346 albertel 6084: .LC_current_location {
6085: background: $tabbg;
6086: }
1.795 www 6087:
1.1075.2.134 raeburn 6088: td.LC_zero_height {
6089: line-height: 0;
6090: cellpadding: 0;
6091: }
6092:
1.938 bisitz 6093: table.LC_data_table {
1.347 albertel 6094: border: 1px solid #000000;
1.402 albertel 6095: border-collapse: separate;
1.426 albertel 6096: border-spacing: 1px;
1.610 albertel 6097: background: $pgbg;
1.347 albertel 6098: }
1.795 www 6099:
1.422 albertel 6100: .LC_data_table_dense {
6101: font-size: small;
6102: }
1.795 www 6103:
1.507 raeburn 6104: table.LC_nested_outer {
6105: border: 1px solid #000000;
1.589 raeburn 6106: border-collapse: collapse;
1.803 bisitz 6107: border-spacing: 0;
1.507 raeburn 6108: width: 100%;
6109: }
1.795 www 6110:
1.879 raeburn 6111: table.LC_innerpickbox,
1.507 raeburn 6112: table.LC_nested {
1.803 bisitz 6113: border: none;
1.589 raeburn 6114: border-collapse: collapse;
1.803 bisitz 6115: border-spacing: 0;
1.507 raeburn 6116: width: 100%;
6117: }
1.795 www 6118:
1.911 bisitz 6119: table.LC_data_table tr th,
6120: table.LC_calendar tr th,
1.879 raeburn 6121: table.LC_prior_tries tr th,
6122: table.LC_innerpickbox tr th {
1.349 albertel 6123: font-weight: bold;
6124: background-color: $data_table_head;
1.801 tempelho 6125: color:$fontmenu;
1.701 harmsja 6126: font-size:90%;
1.347 albertel 6127: }
1.795 www 6128:
1.879 raeburn 6129: table.LC_innerpickbox tr th,
6130: table.LC_innerpickbox tr td {
6131: vertical-align: top;
6132: }
6133:
1.711 raeburn 6134: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6135: background-color: #CCCCCC;
1.711 raeburn 6136: font-weight: bold;
6137: text-align: left;
6138: }
1.795 www 6139:
1.912 bisitz 6140: table.LC_data_table tr.LC_odd_row > td {
6141: background-color: $data_table_light;
6142: padding: 2px;
6143: vertical-align: top;
6144: }
6145:
1.809 bisitz 6146: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6147: background-color: $data_table_light;
1.912 bisitz 6148: vertical-align: top;
6149: }
6150:
6151: table.LC_data_table tr.LC_even_row > td {
6152: background-color: $data_table_dark;
1.425 albertel 6153: padding: 2px;
1.900 bisitz 6154: vertical-align: top;
1.347 albertel 6155: }
1.795 www 6156:
1.809 bisitz 6157: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6158: background-color: $data_table_dark;
1.900 bisitz 6159: vertical-align: top;
1.347 albertel 6160: }
1.795 www 6161:
1.425 albertel 6162: table.LC_data_table tr.LC_data_table_highlight td {
6163: background-color: $data_table_darker;
6164: }
1.795 www 6165:
1.639 raeburn 6166: table.LC_data_table tr td.LC_leftcol_header {
6167: background-color: $data_table_head;
6168: font-weight: bold;
6169: }
1.795 www 6170:
1.451 albertel 6171: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6172: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6173: font-weight: bold;
6174: font-style: italic;
6175: text-align: center;
6176: padding: 8px;
1.347 albertel 6177: }
1.795 www 6178:
1.1075.2.30 raeburn 6179: table.LC_data_table tr.LC_empty_row td,
6180: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6181: background-color: $sidebg;
6182: }
6183:
6184: table.LC_nested tr.LC_empty_row td {
6185: background-color: #FFFFFF;
6186: }
6187:
1.890 droeschl 6188: table.LC_caption {
6189: }
6190:
1.507 raeburn 6191: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6192: padding: 4ex
6193: }
1.795 www 6194:
1.507 raeburn 6195: table.LC_nested_outer tr th {
6196: font-weight: bold;
1.801 tempelho 6197: color:$fontmenu;
1.507 raeburn 6198: background-color: $data_table_head;
1.701 harmsja 6199: font-size: small;
1.507 raeburn 6200: border-bottom: 1px solid #000000;
6201: }
1.795 www 6202:
1.507 raeburn 6203: table.LC_nested_outer tr td.LC_subheader {
6204: background-color: $data_table_head;
6205: font-weight: bold;
6206: font-size: small;
6207: border-bottom: 1px solid #000000;
6208: text-align: right;
1.451 albertel 6209: }
1.795 www 6210:
1.507 raeburn 6211: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6212: background-color: #CCCCCC;
1.451 albertel 6213: font-weight: bold;
6214: font-size: small;
1.507 raeburn 6215: text-align: center;
6216: }
1.795 www 6217:
1.589 raeburn 6218: table.LC_nested tr.LC_info_row td.LC_left_item,
6219: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6220: text-align: left;
1.451 albertel 6221: }
1.795 www 6222:
1.507 raeburn 6223: table.LC_nested td {
1.735 bisitz 6224: background-color: #FFFFFF;
1.451 albertel 6225: font-size: small;
1.507 raeburn 6226: }
1.795 www 6227:
1.507 raeburn 6228: table.LC_nested_outer tr th.LC_right_item,
6229: table.LC_nested tr.LC_info_row td.LC_right_item,
6230: table.LC_nested tr.LC_odd_row td.LC_right_item,
6231: table.LC_nested tr td.LC_right_item {
1.451 albertel 6232: text-align: right;
6233: }
6234:
1.507 raeburn 6235: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6236: background-color: #EEEEEE;
1.451 albertel 6237: }
6238:
1.473 raeburn 6239: table.LC_createuser {
6240: }
6241:
6242: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6243: font-size: small;
1.473 raeburn 6244: }
6245:
6246: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6247: background-color: #CCCCCC;
1.473 raeburn 6248: font-weight: bold;
6249: text-align: center;
6250: }
6251:
1.349 albertel 6252: table.LC_calendar {
6253: border: 1px solid #000000;
6254: border-collapse: collapse;
1.917 raeburn 6255: width: 98%;
1.349 albertel 6256: }
1.795 www 6257:
1.349 albertel 6258: table.LC_calendar_pickdate {
6259: font-size: xx-small;
6260: }
1.795 www 6261:
1.349 albertel 6262: table.LC_calendar tr td {
6263: border: 1px solid #000000;
6264: vertical-align: top;
1.917 raeburn 6265: width: 14%;
1.349 albertel 6266: }
1.795 www 6267:
1.349 albertel 6268: table.LC_calendar tr td.LC_calendar_day_empty {
6269: background-color: $data_table_dark;
6270: }
1.795 www 6271:
1.779 bisitz 6272: table.LC_calendar tr td.LC_calendar_day_current {
6273: background-color: $data_table_highlight;
1.777 tempelho 6274: }
1.795 www 6275:
1.938 bisitz 6276: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6277: background-color: $mail_new;
6278: }
1.795 www 6279:
1.938 bisitz 6280: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6281: background-color: $mail_new_hover;
6282: }
1.795 www 6283:
1.938 bisitz 6284: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6285: background-color: $mail_read;
6286: }
1.795 www 6287:
1.938 bisitz 6288: /*
6289: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6290: background-color: $mail_read_hover;
6291: }
1.938 bisitz 6292: */
1.795 www 6293:
1.938 bisitz 6294: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6295: background-color: $mail_replied;
6296: }
1.795 www 6297:
1.938 bisitz 6298: /*
6299: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6300: background-color: $mail_replied_hover;
6301: }
1.938 bisitz 6302: */
1.795 www 6303:
1.938 bisitz 6304: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6305: background-color: $mail_other;
6306: }
1.795 www 6307:
1.938 bisitz 6308: /*
6309: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6310: background-color: $mail_other_hover;
6311: }
1.938 bisitz 6312: */
1.494 raeburn 6313:
1.777 tempelho 6314: table.LC_data_table tr > td.LC_browser_file,
6315: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6316: background: #AAEE77;
1.389 albertel 6317: }
1.795 www 6318:
1.777 tempelho 6319: table.LC_data_table tr > td.LC_browser_file_locked,
6320: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6321: background: #FFAA99;
1.387 albertel 6322: }
1.795 www 6323:
1.777 tempelho 6324: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6325: background: #888888;
1.779 bisitz 6326: }
1.795 www 6327:
1.777 tempelho 6328: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6329: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6330: background: #F8F866;
1.777 tempelho 6331: }
1.795 www 6332:
1.696 bisitz 6333: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6334: background: #E0E8FF;
1.387 albertel 6335: }
1.696 bisitz 6336:
1.707 bisitz 6337: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6338: /* background: #77FF77; */
1.707 bisitz 6339: }
1.795 www 6340:
1.707 bisitz 6341: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6342: border-right: 8px solid #FFFF77;
1.707 bisitz 6343: }
1.795 www 6344:
1.707 bisitz 6345: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6346: border-right: 8px solid #FFAA77;
1.707 bisitz 6347: }
1.795 www 6348:
1.707 bisitz 6349: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6350: border-right: 8px solid #FF7777;
1.707 bisitz 6351: }
1.795 www 6352:
1.707 bisitz 6353: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6354: border-right: 8px solid #AAFF77;
1.707 bisitz 6355: }
1.795 www 6356:
1.707 bisitz 6357: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6358: border-right: 8px solid #11CC55;
1.707 bisitz 6359: }
6360:
1.388 albertel 6361: span.LC_current_location {
1.701 harmsja 6362: font-size:larger;
1.388 albertel 6363: background: $pgbg;
6364: }
1.387 albertel 6365:
1.1029 www 6366: span.LC_current_nav_location {
6367: font-weight:bold;
6368: background: $sidebg;
6369: }
6370:
1.395 albertel 6371: span.LC_parm_menu_item {
6372: font-size: larger;
6373: }
1.795 www 6374:
1.395 albertel 6375: span.LC_parm_scope_all {
6376: color: red;
6377: }
1.795 www 6378:
1.395 albertel 6379: span.LC_parm_scope_folder {
6380: color: green;
6381: }
1.795 www 6382:
1.395 albertel 6383: span.LC_parm_scope_resource {
6384: color: orange;
6385: }
1.795 www 6386:
1.395 albertel 6387: span.LC_parm_part {
6388: color: blue;
6389: }
1.795 www 6390:
1.911 bisitz 6391: span.LC_parm_folder,
6392: span.LC_parm_symb {
1.395 albertel 6393: font-size: x-small;
6394: font-family: $mono;
6395: color: #AAAAAA;
6396: }
6397:
1.977 bisitz 6398: ul.LC_parm_parmlist li {
6399: display: inline-block;
6400: padding: 0.3em 0.8em;
6401: vertical-align: top;
6402: width: 150px;
6403: border-top:1px solid $lg_border_color;
6404: }
6405:
1.795 www 6406: td.LC_parm_overview_level_menu,
6407: td.LC_parm_overview_map_menu,
6408: td.LC_parm_overview_parm_selectors,
6409: td.LC_parm_overview_restrictions {
1.396 albertel 6410: border: 1px solid black;
6411: border-collapse: collapse;
6412: }
1.795 www 6413:
1.396 albertel 6414: table.LC_parm_overview_restrictions td {
6415: border-width: 1px 4px 1px 4px;
6416: border-style: solid;
6417: border-color: $pgbg;
6418: text-align: center;
6419: }
1.795 www 6420:
1.396 albertel 6421: table.LC_parm_overview_restrictions th {
6422: background: $tabbg;
6423: border-width: 1px 4px 1px 4px;
6424: border-style: solid;
6425: border-color: $pgbg;
6426: }
1.795 www 6427:
1.398 albertel 6428: table#LC_helpmenu {
1.803 bisitz 6429: border: none;
1.398 albertel 6430: height: 55px;
1.803 bisitz 6431: border-spacing: 0;
1.398 albertel 6432: }
6433:
6434: table#LC_helpmenu fieldset legend {
6435: font-size: larger;
6436: }
1.795 www 6437:
1.397 albertel 6438: table#LC_helpmenu_links {
6439: width: 100%;
6440: border: 1px solid black;
6441: background: $pgbg;
1.803 bisitz 6442: padding: 0;
1.397 albertel 6443: border-spacing: 1px;
6444: }
1.795 www 6445:
1.397 albertel 6446: table#LC_helpmenu_links tr td {
6447: padding: 1px;
6448: background: $tabbg;
1.399 albertel 6449: text-align: center;
6450: font-weight: bold;
1.397 albertel 6451: }
1.396 albertel 6452:
1.795 www 6453: table#LC_helpmenu_links a:link,
6454: table#LC_helpmenu_links a:visited,
1.397 albertel 6455: table#LC_helpmenu_links a:active {
6456: text-decoration: none;
6457: color: $font;
6458: }
1.795 www 6459:
1.397 albertel 6460: table#LC_helpmenu_links a:hover {
6461: text-decoration: underline;
6462: color: $vlink;
6463: }
1.396 albertel 6464:
1.417 albertel 6465: .LC_chrt_popup_exists {
6466: border: 1px solid #339933;
6467: margin: -1px;
6468: }
1.795 www 6469:
1.417 albertel 6470: .LC_chrt_popup_up {
6471: border: 1px solid yellow;
6472: margin: -1px;
6473: }
1.795 www 6474:
1.417 albertel 6475: .LC_chrt_popup {
6476: border: 1px solid #8888FF;
6477: background: #CCCCFF;
6478: }
1.795 www 6479:
1.421 albertel 6480: table.LC_pick_box {
6481: border-collapse: separate;
6482: background: white;
6483: border: 1px solid black;
6484: border-spacing: 1px;
6485: }
1.795 www 6486:
1.421 albertel 6487: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6488: background: $sidebg;
1.421 albertel 6489: font-weight: bold;
1.900 bisitz 6490: text-align: left;
1.740 bisitz 6491: vertical-align: top;
1.421 albertel 6492: width: 184px;
6493: padding: 8px;
6494: }
1.795 www 6495:
1.579 raeburn 6496: table.LC_pick_box td.LC_pick_box_value {
6497: text-align: left;
6498: padding: 8px;
6499: }
1.795 www 6500:
1.579 raeburn 6501: table.LC_pick_box td.LC_pick_box_select {
6502: text-align: left;
6503: padding: 8px;
6504: }
1.795 www 6505:
1.424 albertel 6506: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6507: padding: 0;
1.421 albertel 6508: height: 1px;
6509: background: black;
6510: }
1.795 www 6511:
1.421 albertel 6512: table.LC_pick_box td.LC_pick_box_submit {
6513: text-align: right;
6514: }
1.795 www 6515:
1.579 raeburn 6516: table.LC_pick_box td.LC_evenrow_value {
6517: text-align: left;
6518: padding: 8px;
6519: background-color: $data_table_light;
6520: }
1.795 www 6521:
1.579 raeburn 6522: table.LC_pick_box td.LC_oddrow_value {
6523: text-align: left;
6524: padding: 8px;
6525: background-color: $data_table_light;
6526: }
1.795 www 6527:
1.579 raeburn 6528: span.LC_helpform_receipt_cat {
6529: font-weight: bold;
6530: }
1.795 www 6531:
1.424 albertel 6532: table.LC_group_priv_box {
6533: background: white;
6534: border: 1px solid black;
6535: border-spacing: 1px;
6536: }
1.795 www 6537:
1.424 albertel 6538: table.LC_group_priv_box td.LC_pick_box_title {
6539: background: $tabbg;
6540: font-weight: bold;
6541: text-align: right;
6542: width: 184px;
6543: }
1.795 www 6544:
1.424 albertel 6545: table.LC_group_priv_box td.LC_groups_fixed {
6546: background: $data_table_light;
6547: text-align: center;
6548: }
1.795 www 6549:
1.424 albertel 6550: table.LC_group_priv_box td.LC_groups_optional {
6551: background: $data_table_dark;
6552: text-align: center;
6553: }
1.795 www 6554:
1.424 albertel 6555: table.LC_group_priv_box td.LC_groups_functionality {
6556: background: $data_table_darker;
6557: text-align: center;
6558: font-weight: bold;
6559: }
1.795 www 6560:
1.424 albertel 6561: table.LC_group_priv td {
6562: text-align: left;
1.803 bisitz 6563: padding: 0;
1.424 albertel 6564: }
6565:
6566: .LC_navbuttons {
6567: margin: 2ex 0ex 2ex 0ex;
6568: }
1.795 www 6569:
1.423 albertel 6570: .LC_topic_bar {
6571: font-weight: bold;
6572: background: $tabbg;
1.918 wenzelju 6573: margin: 1em 0em 1em 2em;
1.805 bisitz 6574: padding: 3px;
1.918 wenzelju 6575: font-size: 1.2em;
1.423 albertel 6576: }
1.795 www 6577:
1.423 albertel 6578: .LC_topic_bar span {
1.918 wenzelju 6579: left: 0.5em;
6580: position: absolute;
1.423 albertel 6581: vertical-align: middle;
1.918 wenzelju 6582: font-size: 1.2em;
1.423 albertel 6583: }
1.795 www 6584:
1.423 albertel 6585: table.LC_course_group_status {
6586: margin: 20px;
6587: }
1.795 www 6588:
1.423 albertel 6589: table.LC_status_selector td {
6590: vertical-align: top;
6591: text-align: center;
1.424 albertel 6592: padding: 4px;
6593: }
1.795 www 6594:
1.599 albertel 6595: div.LC_feedback_link {
1.616 albertel 6596: clear: both;
1.829 kalberla 6597: background: $sidebg;
1.779 bisitz 6598: width: 100%;
1.829 kalberla 6599: padding-bottom: 10px;
6600: border: 1px $tabbg solid;
1.833 kalberla 6601: height: 22px;
6602: line-height: 22px;
6603: padding-top: 5px;
6604: }
6605:
6606: div.LC_feedback_link img {
6607: height: 22px;
1.867 kalberla 6608: vertical-align:middle;
1.829 kalberla 6609: }
6610:
1.911 bisitz 6611: div.LC_feedback_link a {
1.829 kalberla 6612: text-decoration: none;
1.489 raeburn 6613: }
1.795 www 6614:
1.867 kalberla 6615: div.LC_comblock {
1.911 bisitz 6616: display:inline;
1.867 kalberla 6617: color:$font;
6618: font-size:90%;
6619: }
6620:
6621: div.LC_feedback_link div.LC_comblock {
6622: padding-left:5px;
6623: }
6624:
6625: div.LC_feedback_link div.LC_comblock a {
6626: color:$font;
6627: }
6628:
1.489 raeburn 6629: span.LC_feedback_link {
1.858 bisitz 6630: /* background: $feedback_link_bg; */
1.599 albertel 6631: font-size: larger;
6632: }
1.795 www 6633:
1.599 albertel 6634: span.LC_message_link {
1.858 bisitz 6635: /* background: $feedback_link_bg; */
1.599 albertel 6636: font-size: larger;
6637: position: absolute;
6638: right: 1em;
1.489 raeburn 6639: }
1.421 albertel 6640:
1.515 albertel 6641: table.LC_prior_tries {
1.524 albertel 6642: border: 1px solid #000000;
6643: border-collapse: separate;
6644: border-spacing: 1px;
1.515 albertel 6645: }
1.523 albertel 6646:
1.515 albertel 6647: table.LC_prior_tries td {
1.524 albertel 6648: padding: 2px;
1.515 albertel 6649: }
1.523 albertel 6650:
6651: .LC_answer_correct {
1.795 www 6652: background: lightgreen;
6653: color: darkgreen;
6654: padding: 6px;
1.523 albertel 6655: }
1.795 www 6656:
1.523 albertel 6657: .LC_answer_charged_try {
1.797 www 6658: background: #FFAAAA;
1.795 www 6659: color: darkred;
6660: padding: 6px;
1.523 albertel 6661: }
1.795 www 6662:
1.779 bisitz 6663: .LC_answer_not_charged_try,
1.523 albertel 6664: .LC_answer_no_grade,
6665: .LC_answer_late {
1.795 www 6666: background: lightyellow;
1.523 albertel 6667: color: black;
1.795 www 6668: padding: 6px;
1.523 albertel 6669: }
1.795 www 6670:
1.523 albertel 6671: .LC_answer_previous {
1.795 www 6672: background: lightblue;
6673: color: darkblue;
6674: padding: 6px;
1.523 albertel 6675: }
1.795 www 6676:
1.779 bisitz 6677: .LC_answer_no_message {
1.777 tempelho 6678: background: #FFFFFF;
6679: color: black;
1.795 www 6680: padding: 6px;
1.779 bisitz 6681: }
1.795 www 6682:
1.779 bisitz 6683: .LC_answer_unknown {
6684: background: orange;
6685: color: black;
1.795 www 6686: padding: 6px;
1.777 tempelho 6687: }
1.795 www 6688:
1.529 albertel 6689: span.LC_prior_numerical,
6690: span.LC_prior_string,
6691: span.LC_prior_custom,
6692: span.LC_prior_reaction,
6693: span.LC_prior_math {
1.925 bisitz 6694: font-family: $mono;
1.523 albertel 6695: white-space: pre;
6696: }
6697:
1.525 albertel 6698: span.LC_prior_string {
1.925 bisitz 6699: font-family: $mono;
1.525 albertel 6700: white-space: pre;
6701: }
6702:
1.523 albertel 6703: table.LC_prior_option {
6704: width: 100%;
6705: border-collapse: collapse;
6706: }
1.795 www 6707:
1.911 bisitz 6708: table.LC_prior_rank,
1.795 www 6709: table.LC_prior_match {
1.528 albertel 6710: border-collapse: collapse;
6711: }
1.795 www 6712:
1.528 albertel 6713: table.LC_prior_option tr td,
6714: table.LC_prior_rank tr td,
6715: table.LC_prior_match tr td {
1.524 albertel 6716: border: 1px solid #000000;
1.515 albertel 6717: }
6718:
1.855 bisitz 6719: .LC_nobreak {
1.544 albertel 6720: white-space: nowrap;
1.519 raeburn 6721: }
6722:
1.576 raeburn 6723: span.LC_cusr_emph {
6724: font-style: italic;
6725: }
6726:
1.633 raeburn 6727: span.LC_cusr_subheading {
6728: font-weight: normal;
6729: font-size: 85%;
6730: }
6731:
1.861 bisitz 6732: div.LC_docs_entry_move {
1.859 bisitz 6733: border: 1px solid #BBBBBB;
1.545 albertel 6734: background: #DDDDDD;
1.861 bisitz 6735: width: 22px;
1.859 bisitz 6736: padding: 1px;
6737: margin: 0;
1.545 albertel 6738: }
6739:
1.861 bisitz 6740: table.LC_data_table tr > td.LC_docs_entry_commands,
6741: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6742: font-size: x-small;
6743: }
1.795 www 6744:
1.861 bisitz 6745: .LC_docs_entry_parameter {
6746: white-space: nowrap;
6747: }
6748:
1.544 albertel 6749: .LC_docs_copy {
1.545 albertel 6750: color: #000099;
1.544 albertel 6751: }
1.795 www 6752:
1.544 albertel 6753: .LC_docs_cut {
1.545 albertel 6754: color: #550044;
1.544 albertel 6755: }
1.795 www 6756:
1.544 albertel 6757: .LC_docs_rename {
1.545 albertel 6758: color: #009900;
1.544 albertel 6759: }
1.795 www 6760:
1.544 albertel 6761: .LC_docs_remove {
1.545 albertel 6762: color: #990000;
6763: }
6764:
1.1075.2.134 raeburn 6765: .LC_domprefs_email,
1.547 albertel 6766: .LC_docs_reinit_warn,
6767: .LC_docs_ext_edit {
6768: font-size: x-small;
6769: }
6770:
1.545 albertel 6771: table.LC_docs_adddocs td,
6772: table.LC_docs_adddocs th {
6773: border: 1px solid #BBBBBB;
6774: padding: 4px;
6775: background: #DDDDDD;
1.543 albertel 6776: }
6777:
1.584 albertel 6778: table.LC_sty_begin {
6779: background: #BBFFBB;
6780: }
1.795 www 6781:
1.584 albertel 6782: table.LC_sty_end {
6783: background: #FFBBBB;
6784: }
6785:
1.589 raeburn 6786: table.LC_double_column {
1.803 bisitz 6787: border-width: 0;
1.589 raeburn 6788: border-collapse: collapse;
6789: width: 100%;
6790: padding: 2px;
6791: }
6792:
6793: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6794: top: 2px;
1.589 raeburn 6795: left: 2px;
6796: width: 47%;
6797: vertical-align: top;
6798: }
6799:
6800: table.LC_double_column tr td.LC_right_col {
6801: top: 2px;
1.779 bisitz 6802: right: 2px;
1.589 raeburn 6803: width: 47%;
6804: vertical-align: top;
6805: }
6806:
1.591 raeburn 6807: div.LC_left_float {
6808: float: left;
6809: padding-right: 5%;
1.597 albertel 6810: padding-bottom: 4px;
1.591 raeburn 6811: }
6812:
6813: div.LC_clear_float_header {
1.597 albertel 6814: padding-bottom: 2px;
1.591 raeburn 6815: }
6816:
6817: div.LC_clear_float_footer {
1.597 albertel 6818: padding-top: 10px;
1.591 raeburn 6819: clear: both;
6820: }
6821:
1.597 albertel 6822: div.LC_grade_show_user {
1.941 bisitz 6823: /* border-left: 5px solid $sidebg; */
6824: border-top: 5px solid #000000;
6825: margin: 50px 0 0 0;
1.936 bisitz 6826: padding: 15px 0 5px 10px;
1.597 albertel 6827: }
1.795 www 6828:
1.936 bisitz 6829: div.LC_grade_show_user_odd_row {
1.941 bisitz 6830: /* border-left: 5px solid #000000; */
6831: }
6832:
6833: div.LC_grade_show_user div.LC_Box {
6834: margin-right: 50px;
1.597 albertel 6835: }
6836:
6837: div.LC_grade_submissions,
6838: div.LC_grade_message_center,
1.936 bisitz 6839: div.LC_grade_info_links {
1.597 albertel 6840: margin: 5px;
6841: width: 99%;
6842: background: #FFFFFF;
6843: }
1.795 www 6844:
1.597 albertel 6845: div.LC_grade_submissions_header,
1.936 bisitz 6846: div.LC_grade_message_center_header {
1.705 tempelho 6847: font-weight: bold;
6848: font-size: large;
1.597 albertel 6849: }
1.795 www 6850:
1.597 albertel 6851: div.LC_grade_submissions_body,
1.936 bisitz 6852: div.LC_grade_message_center_body {
1.597 albertel 6853: border: 1px solid black;
6854: width: 99%;
6855: background: #FFFFFF;
6856: }
1.795 www 6857:
1.613 albertel 6858: table.LC_scantron_action {
6859: width: 100%;
6860: }
1.795 www 6861:
1.613 albertel 6862: table.LC_scantron_action tr th {
1.698 harmsja 6863: font-weight:bold;
6864: font-style:normal;
1.613 albertel 6865: }
1.795 www 6866:
1.779 bisitz 6867: .LC_edit_problem_header,
1.614 albertel 6868: div.LC_edit_problem_footer {
1.705 tempelho 6869: font-weight: normal;
6870: font-size: medium;
1.602 albertel 6871: margin: 2px;
1.1060 bisitz 6872: background-color: $sidebg;
1.600 albertel 6873: }
1.795 www 6874:
1.600 albertel 6875: div.LC_edit_problem_header,
1.602 albertel 6876: div.LC_edit_problem_header div,
1.614 albertel 6877: div.LC_edit_problem_footer,
6878: div.LC_edit_problem_footer div,
1.602 albertel 6879: div.LC_edit_problem_editxml_header,
6880: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 6881: z-index: 100;
1.600 albertel 6882: }
1.795 www 6883:
1.600 albertel 6884: div.LC_edit_problem_header_title {
1.705 tempelho 6885: font-weight: bold;
6886: font-size: larger;
1.602 albertel 6887: background: $tabbg;
6888: padding: 3px;
1.1060 bisitz 6889: margin: 0 0 5px 0;
1.602 albertel 6890: }
1.795 www 6891:
1.602 albertel 6892: table.LC_edit_problem_header_title {
6893: width: 100%;
1.600 albertel 6894: background: $tabbg;
1.602 albertel 6895: }
6896:
1.1075.2.112 raeburn 6897: div.LC_edit_actionbar {
6898: background-color: $sidebg;
6899: margin: 0;
6900: padding: 0;
6901: line-height: 200%;
1.602 albertel 6902: }
1.795 www 6903:
1.1075.2.112 raeburn 6904: div.LC_edit_actionbar div{
6905: padding: 0;
6906: margin: 0;
6907: display: inline-block;
1.600 albertel 6908: }
1.795 www 6909:
1.1075.2.34 raeburn 6910: .LC_edit_opt {
6911: padding-left: 1em;
6912: white-space: nowrap;
6913: }
6914:
1.1075.2.57 raeburn 6915: .LC_edit_problem_latexhelper{
6916: text-align: right;
6917: }
6918:
6919: #LC_edit_problem_colorful div{
6920: margin-left: 40px;
6921: }
6922:
1.1075.2.112 raeburn 6923: #LC_edit_problem_codemirror div{
6924: margin-left: 0px;
6925: }
6926:
1.911 bisitz 6927: img.stift {
1.803 bisitz 6928: border-width: 0;
6929: vertical-align: middle;
1.677 riegler 6930: }
1.680 riegler 6931:
1.923 bisitz 6932: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6933: vertical-align: top;
1.777 tempelho 6934: }
1.795 www 6935:
1.716 raeburn 6936: div.LC_createcourse {
1.911 bisitz 6937: margin: 10px 10px 10px 10px;
1.716 raeburn 6938: }
6939:
1.917 raeburn 6940: .LC_dccid {
1.1075.2.38 raeburn 6941: float: right;
1.917 raeburn 6942: margin: 0.2em 0 0 0;
6943: padding: 0;
6944: font-size: 90%;
6945: display:none;
6946: }
6947:
1.897 wenzelju 6948: ol.LC_primary_menu a:hover,
1.721 harmsja 6949: ol#LC_MenuBreadcrumbs a:hover,
6950: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6951: ul#LC_secondary_menu a:hover,
1.721 harmsja 6952: .LC_FormSectionClearButton input:hover
1.795 www 6953: ul.LC_TabContent li:hover a {
1.952 onken 6954: color:$button_hover;
1.911 bisitz 6955: text-decoration:none;
1.693 droeschl 6956: }
6957:
1.779 bisitz 6958: h1 {
1.911 bisitz 6959: padding: 0;
6960: line-height:130%;
1.693 droeschl 6961: }
1.698 harmsja 6962:
1.911 bisitz 6963: h2,
6964: h3,
6965: h4,
6966: h5,
6967: h6 {
6968: margin: 5px 0 5px 0;
6969: padding: 0;
6970: line-height:130%;
1.693 droeschl 6971: }
1.795 www 6972:
6973: .LC_hcell {
1.911 bisitz 6974: padding:3px 15px 3px 15px;
6975: margin: 0;
6976: background-color:$tabbg;
6977: color:$fontmenu;
6978: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6979: }
1.795 www 6980:
1.840 bisitz 6981: .LC_Box > .LC_hcell {
1.911 bisitz 6982: margin: 0 -10px 10px -10px;
1.835 bisitz 6983: }
6984:
1.721 harmsja 6985: .LC_noBorder {
1.911 bisitz 6986: border: 0;
1.698 harmsja 6987: }
1.693 droeschl 6988:
1.721 harmsja 6989: .LC_FormSectionClearButton input {
1.911 bisitz 6990: background-color:transparent;
6991: border: none;
6992: cursor:pointer;
6993: text-decoration:underline;
1.693 droeschl 6994: }
1.763 bisitz 6995:
6996: .LC_help_open_topic {
1.911 bisitz 6997: color: #FFFFFF;
6998: background-color: #EEEEFF;
6999: margin: 1px;
7000: padding: 4px;
7001: border: 1px solid #000033;
7002: white-space: nowrap;
7003: /* vertical-align: middle; */
1.759 neumanie 7004: }
1.693 droeschl 7005:
1.911 bisitz 7006: dl,
7007: ul,
7008: div,
7009: fieldset {
7010: margin: 10px 10px 10px 0;
7011: /* overflow: hidden; */
1.693 droeschl 7012: }
1.795 www 7013:
1.1075.2.90 raeburn 7014: article.geogebraweb div {
7015: margin: 0;
7016: }
7017:
1.838 bisitz 7018: fieldset > legend {
1.911 bisitz 7019: font-weight: bold;
7020: padding: 0 5px 0 5px;
1.838 bisitz 7021: }
7022:
1.813 bisitz 7023: #LC_nav_bar {
1.911 bisitz 7024: float: left;
1.995 raeburn 7025: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7026: margin: 0 0 2px 0;
1.807 droeschl 7027: }
7028:
1.916 droeschl 7029: #LC_realm {
7030: margin: 0.2em 0 0 0;
7031: padding: 0;
7032: font-weight: bold;
7033: text-align: center;
1.995 raeburn 7034: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7035: }
7036:
1.911 bisitz 7037: #LC_nav_bar em {
7038: font-weight: bold;
7039: font-style: normal;
1.807 droeschl 7040: }
7041:
1.897 wenzelju 7042: ol.LC_primary_menu {
1.934 droeschl 7043: margin: 0;
1.1075.2.2 raeburn 7044: padding: 0;
1.807 droeschl 7045: }
7046:
1.852 droeschl 7047: ol#LC_PathBreadcrumbs {
1.911 bisitz 7048: margin: 0;
1.693 droeschl 7049: }
7050:
1.897 wenzelju 7051: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7052: color: RGB(80, 80, 80);
7053: vertical-align: middle;
7054: text-align: left;
7055: list-style: none;
1.1075.2.112 raeburn 7056: position: relative;
1.1075.2.2 raeburn 7057: float: left;
1.1075.2.112 raeburn 7058: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7059: line-height: 1.5em;
1.1075.2.2 raeburn 7060: }
7061:
1.1075.2.113 raeburn 7062: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7063: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7064: display: block;
7065: margin: 0;
7066: padding: 0 5px 0 10px;
7067: text-decoration: none;
7068: }
7069:
1.1075.2.112 raeburn 7070: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7071: display: inline-block;
7072: width: 95%;
7073: text-align: left;
7074: }
7075:
7076: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7077: display: inline-block;
7078: width: 5%;
7079: float: right;
7080: text-align: right;
7081: font-size: 70%;
7082: }
7083:
7084: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7085: display: none;
1.1075.2.112 raeburn 7086: width: 15em;
1.1075.2.2 raeburn 7087: background-color: $data_table_light;
1.1075.2.112 raeburn 7088: position: absolute;
7089: top: 100%;
7090: }
7091:
7092: ol.LC_primary_menu ul ul {
7093: left: 100%;
7094: top: 0;
1.1075.2.2 raeburn 7095: }
7096:
1.1075.2.112 raeburn 7097: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7098: display: block;
7099: position: absolute;
7100: margin: 0;
7101: padding: 0;
1.1075.2.5 raeburn 7102: z-index: 2;
1.1075.2.2 raeburn 7103: }
7104:
7105: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7106: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7107: font-size: 90%;
1.911 bisitz 7108: vertical-align: top;
1.1075.2.2 raeburn 7109: float: none;
1.1075.2.5 raeburn 7110: border-left: 1px solid black;
7111: border-right: 1px solid black;
1.1075.2.112 raeburn 7112: /* A dark bottom border to visualize different menu options;
7113: overwritten in the create_submenu routine for the last border-bottom of the menu */
7114: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7115: }
7116:
1.1075.2.112 raeburn 7117: ol.LC_primary_menu li li p:hover {
7118: color:$button_hover;
7119: text-decoration:none;
7120: background-color:$data_table_dark;
1.1075.2.2 raeburn 7121: }
7122:
7123: ol.LC_primary_menu li li a:hover {
7124: color:$button_hover;
7125: background-color:$data_table_dark;
1.693 droeschl 7126: }
7127:
1.1075.2.112 raeburn 7128: /* Font-size equal to the size of the predecessors*/
7129: ol.LC_primary_menu li:hover li li {
7130: font-size: 100%;
7131: }
7132:
1.897 wenzelju 7133: ol.LC_primary_menu li img {
1.911 bisitz 7134: vertical-align: bottom;
1.934 droeschl 7135: height: 1.1em;
1.1075.2.3 raeburn 7136: margin: 0.2em 0 0 0;
1.693 droeschl 7137: }
7138:
1.897 wenzelju 7139: ol.LC_primary_menu a {
1.911 bisitz 7140: color: RGB(80, 80, 80);
7141: text-decoration: none;
1.693 droeschl 7142: }
1.795 www 7143:
1.949 droeschl 7144: ol.LC_primary_menu a.LC_new_message {
7145: font-weight:bold;
7146: color: darkred;
7147: }
7148:
1.975 raeburn 7149: ol.LC_docs_parameters {
7150: margin-left: 0;
7151: padding: 0;
7152: list-style: none;
7153: }
7154:
7155: ol.LC_docs_parameters li {
7156: margin: 0;
7157: padding-right: 20px;
7158: display: inline;
7159: }
7160:
1.976 raeburn 7161: ol.LC_docs_parameters li:before {
7162: content: "\\002022 \\0020";
7163: }
7164:
7165: li.LC_docs_parameters_title {
7166: font-weight: bold;
7167: }
7168:
7169: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7170: content: "";
7171: }
7172:
1.897 wenzelju 7173: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7174: clear: right;
1.911 bisitz 7175: color: $fontmenu;
7176: background: $tabbg;
7177: list-style: none;
7178: padding: 0;
7179: margin: 0;
7180: width: 100%;
1.995 raeburn 7181: text-align: left;
1.1075.2.4 raeburn 7182: float: left;
1.808 droeschl 7183: }
7184:
1.897 wenzelju 7185: ul#LC_secondary_menu li {
1.911 bisitz 7186: font-weight: bold;
7187: line-height: 1.8em;
7188: border-right: 1px solid black;
1.1075.2.4 raeburn 7189: float: left;
7190: }
7191:
7192: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7193: background-color: $data_table_light;
7194: }
7195:
7196: ul#LC_secondary_menu li a {
7197: padding: 0 0.8em;
7198: }
7199:
7200: ul#LC_secondary_menu li ul {
7201: display: none;
7202: }
7203:
7204: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7205: display: block;
7206: position: absolute;
7207: margin: 0;
7208: padding: 0;
7209: list-style:none;
7210: float: none;
7211: background-color: $data_table_light;
1.1075.2.5 raeburn 7212: z-index: 2;
1.1075.2.10 raeburn 7213: margin-left: -1px;
1.1075.2.4 raeburn 7214: }
7215:
7216: ul#LC_secondary_menu li ul li {
7217: font-size: 90%;
7218: vertical-align: top;
7219: border-left: 1px solid black;
7220: border-right: 1px solid black;
1.1075.2.33 raeburn 7221: background-color: $data_table_light;
1.1075.2.4 raeburn 7222: list-style:none;
7223: float: none;
7224: }
7225:
7226: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7227: background-color: $data_table_dark;
1.807 droeschl 7228: }
7229:
1.847 tempelho 7230: ul.LC_TabContent {
1.911 bisitz 7231: display:block;
7232: background: $sidebg;
7233: border-bottom: solid 1px $lg_border_color;
7234: list-style:none;
1.1020 raeburn 7235: margin: -1px -10px 0 -10px;
1.911 bisitz 7236: padding: 0;
1.693 droeschl 7237: }
7238:
1.795 www 7239: ul.LC_TabContent li,
7240: ul.LC_TabContentBigger li {
1.911 bisitz 7241: float:left;
1.741 harmsja 7242: }
1.795 www 7243:
1.897 wenzelju 7244: ul#LC_secondary_menu li a {
1.911 bisitz 7245: color: $fontmenu;
7246: text-decoration: none;
1.693 droeschl 7247: }
1.795 www 7248:
1.721 harmsja 7249: ul.LC_TabContent {
1.952 onken 7250: min-height:20px;
1.721 harmsja 7251: }
1.795 www 7252:
7253: ul.LC_TabContent li {
1.911 bisitz 7254: vertical-align:middle;
1.959 onken 7255: padding: 0 16px 0 10px;
1.911 bisitz 7256: background-color:$tabbg;
7257: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7258: border-left: solid 1px $font;
1.721 harmsja 7259: }
1.795 www 7260:
1.847 tempelho 7261: ul.LC_TabContent .right {
1.911 bisitz 7262: float:right;
1.847 tempelho 7263: }
7264:
1.911 bisitz 7265: ul.LC_TabContent li a,
7266: ul.LC_TabContent li {
7267: color:rgb(47,47,47);
7268: text-decoration:none;
7269: font-size:95%;
7270: font-weight:bold;
1.952 onken 7271: min-height:20px;
7272: }
7273:
1.959 onken 7274: ul.LC_TabContent li a:hover,
7275: ul.LC_TabContent li a:focus {
1.952 onken 7276: color: $button_hover;
1.959 onken 7277: background:none;
7278: outline:none;
1.952 onken 7279: }
7280:
7281: ul.LC_TabContent li:hover {
7282: color: $button_hover;
7283: cursor:pointer;
1.721 harmsja 7284: }
1.795 www 7285:
1.911 bisitz 7286: ul.LC_TabContent li.active {
1.952 onken 7287: color: $font;
1.911 bisitz 7288: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7289: border-bottom:solid 1px #FFFFFF;
7290: cursor: default;
1.744 ehlerst 7291: }
1.795 www 7292:
1.959 onken 7293: ul.LC_TabContent li.active a {
7294: color:$font;
7295: background:#FFFFFF;
7296: outline: none;
7297: }
1.1047 raeburn 7298:
7299: ul.LC_TabContent li.goback {
7300: float: left;
7301: border-left: none;
7302: }
7303:
1.870 tempelho 7304: #maincoursedoc {
1.911 bisitz 7305: clear:both;
1.870 tempelho 7306: }
7307:
7308: ul.LC_TabContentBigger {
1.911 bisitz 7309: display:block;
7310: list-style:none;
7311: padding: 0;
1.870 tempelho 7312: }
7313:
1.795 www 7314: ul.LC_TabContentBigger li {
1.911 bisitz 7315: vertical-align:bottom;
7316: height: 30px;
7317: font-size:110%;
7318: font-weight:bold;
7319: color: #737373;
1.841 tempelho 7320: }
7321:
1.957 onken 7322: ul.LC_TabContentBigger li.active {
7323: position: relative;
7324: top: 1px;
7325: }
7326:
1.870 tempelho 7327: ul.LC_TabContentBigger li a {
1.911 bisitz 7328: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7329: height: 30px;
7330: line-height: 30px;
7331: text-align: center;
7332: display: block;
7333: text-decoration: none;
1.958 onken 7334: outline: none;
1.741 harmsja 7335: }
1.795 www 7336:
1.870 tempelho 7337: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7338: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7339: color:$font;
1.744 ehlerst 7340: }
1.795 www 7341:
1.870 tempelho 7342: ul.LC_TabContentBigger li b {
1.911 bisitz 7343: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7344: display: block;
7345: float: left;
7346: padding: 0 30px;
1.957 onken 7347: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7348: }
7349:
1.956 onken 7350: ul.LC_TabContentBigger li:hover b {
7351: color:$button_hover;
7352: }
7353:
1.870 tempelho 7354: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7355: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7356: color:$font;
1.957 onken 7357: border: 0;
1.741 harmsja 7358: }
1.693 droeschl 7359:
1.870 tempelho 7360:
1.862 bisitz 7361: ul.LC_CourseBreadcrumbs {
7362: background: $sidebg;
1.1020 raeburn 7363: height: 2em;
1.862 bisitz 7364: padding-left: 10px;
1.1020 raeburn 7365: margin: 0;
1.862 bisitz 7366: list-style-position: inside;
7367: }
7368:
1.911 bisitz 7369: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7370: ol#LC_PathBreadcrumbs {
1.911 bisitz 7371: padding-left: 10px;
7372: margin: 0;
1.933 droeschl 7373: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7374: }
7375:
1.911 bisitz 7376: ol#LC_MenuBreadcrumbs li,
7377: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7378: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7379: display: inline;
1.933 droeschl 7380: white-space: normal;
1.693 droeschl 7381: }
7382:
1.823 bisitz 7383: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7384: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7385: text-decoration: none;
7386: font-size:90%;
1.693 droeschl 7387: }
1.795 www 7388:
1.969 droeschl 7389: ol#LC_MenuBreadcrumbs h1 {
7390: display: inline;
7391: font-size: 90%;
7392: line-height: 2.5em;
7393: margin: 0;
7394: padding: 0;
7395: }
7396:
1.795 www 7397: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7398: text-decoration:none;
7399: font-size:100%;
7400: font-weight:bold;
1.693 droeschl 7401: }
1.795 www 7402:
1.840 bisitz 7403: .LC_Box {
1.911 bisitz 7404: border: solid 1px $lg_border_color;
7405: padding: 0 10px 10px 10px;
1.746 neumanie 7406: }
1.795 www 7407:
1.1020 raeburn 7408: .LC_DocsBox {
7409: border: solid 1px $lg_border_color;
7410: padding: 0 0 10px 10px;
7411: }
7412:
1.795 www 7413: .LC_AboutMe_Image {
1.911 bisitz 7414: float:left;
7415: margin-right:10px;
1.747 neumanie 7416: }
1.795 www 7417:
7418: .LC_Clear_AboutMe_Image {
1.911 bisitz 7419: clear:left;
1.747 neumanie 7420: }
1.795 www 7421:
1.721 harmsja 7422: dl.LC_ListStyleClean dt {
1.911 bisitz 7423: padding-right: 5px;
7424: display: table-header-group;
1.693 droeschl 7425: }
7426:
1.721 harmsja 7427: dl.LC_ListStyleClean dd {
1.911 bisitz 7428: display: table-row;
1.693 droeschl 7429: }
7430:
1.721 harmsja 7431: .LC_ListStyleClean,
7432: .LC_ListStyleSimple,
7433: .LC_ListStyleNormal,
1.795 www 7434: .LC_ListStyleSpecial {
1.911 bisitz 7435: /* display:block; */
7436: list-style-position: inside;
7437: list-style-type: none;
7438: overflow: hidden;
7439: padding: 0;
1.693 droeschl 7440: }
7441:
1.721 harmsja 7442: .LC_ListStyleSimple li,
7443: .LC_ListStyleSimple dd,
7444: .LC_ListStyleNormal li,
7445: .LC_ListStyleNormal dd,
7446: .LC_ListStyleSpecial li,
1.795 www 7447: .LC_ListStyleSpecial dd {
1.911 bisitz 7448: margin: 0;
7449: padding: 5px 5px 5px 10px;
7450: clear: both;
1.693 droeschl 7451: }
7452:
1.721 harmsja 7453: .LC_ListStyleClean li,
7454: .LC_ListStyleClean dd {
1.911 bisitz 7455: padding-top: 0;
7456: padding-bottom: 0;
1.693 droeschl 7457: }
7458:
1.721 harmsja 7459: .LC_ListStyleSimple dd,
1.795 www 7460: .LC_ListStyleSimple li {
1.911 bisitz 7461: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7462: }
7463:
1.721 harmsja 7464: .LC_ListStyleSpecial li,
7465: .LC_ListStyleSpecial dd {
1.911 bisitz 7466: list-style-type: none;
7467: background-color: RGB(220, 220, 220);
7468: margin-bottom: 4px;
1.693 droeschl 7469: }
7470:
1.721 harmsja 7471: table.LC_SimpleTable {
1.911 bisitz 7472: margin:5px;
7473: border:solid 1px $lg_border_color;
1.795 www 7474: }
1.693 droeschl 7475:
1.721 harmsja 7476: table.LC_SimpleTable tr {
1.911 bisitz 7477: padding: 0;
7478: border:solid 1px $lg_border_color;
1.693 droeschl 7479: }
1.795 www 7480:
7481: table.LC_SimpleTable thead {
1.911 bisitz 7482: background:rgb(220,220,220);
1.693 droeschl 7483: }
7484:
1.721 harmsja 7485: div.LC_columnSection {
1.911 bisitz 7486: display: block;
7487: clear: both;
7488: overflow: hidden;
7489: margin: 0;
1.693 droeschl 7490: }
7491:
1.721 harmsja 7492: div.LC_columnSection>* {
1.911 bisitz 7493: float: left;
7494: margin: 10px 20px 10px 0;
7495: overflow:hidden;
1.693 droeschl 7496: }
1.721 harmsja 7497:
1.795 www 7498: table em {
1.911 bisitz 7499: font-weight: bold;
7500: font-style: normal;
1.748 schulted 7501: }
1.795 www 7502:
1.779 bisitz 7503: table.LC_tableBrowseRes,
1.795 www 7504: table.LC_tableOfContent {
1.911 bisitz 7505: border:none;
7506: border-spacing: 1px;
7507: padding: 3px;
7508: background-color: #FFFFFF;
7509: font-size: 90%;
1.753 droeschl 7510: }
1.789 droeschl 7511:
1.911 bisitz 7512: table.LC_tableOfContent {
7513: border-collapse: collapse;
1.789 droeschl 7514: }
7515:
1.771 droeschl 7516: table.LC_tableBrowseRes a,
1.768 schulted 7517: table.LC_tableOfContent a {
1.911 bisitz 7518: background-color: transparent;
7519: text-decoration: none;
1.753 droeschl 7520: }
7521:
1.795 www 7522: table.LC_tableOfContent img {
1.911 bisitz 7523: border: none;
7524: height: 1.3em;
7525: vertical-align: text-bottom;
7526: margin-right: 0.3em;
1.753 droeschl 7527: }
1.757 schulted 7528:
1.795 www 7529: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7530: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7531: }
7532:
1.795 www 7533: a#LC_content_toolbar_everything {
1.911 bisitz 7534: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7535: }
7536:
1.795 www 7537: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7538: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7539: }
7540:
1.795 www 7541: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7542: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7543: }
7544:
1.795 www 7545: a#LC_content_toolbar_changefolder {
1.911 bisitz 7546: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7547: }
7548:
1.795 www 7549: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7550: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7551: }
7552:
1.1043 raeburn 7553: a#LC_content_toolbar_edittoplevel {
7554: background-image:url(/res/adm/pages/edittoplevel.gif);
7555: }
7556:
1.795 www 7557: ul#LC_toolbar li a:hover {
1.911 bisitz 7558: background-position: bottom center;
1.757 schulted 7559: }
7560:
1.795 www 7561: ul#LC_toolbar {
1.911 bisitz 7562: padding: 0;
7563: margin: 2px;
7564: list-style:none;
7565: position:relative;
7566: background-color:white;
1.1075.2.9 raeburn 7567: overflow: auto;
1.757 schulted 7568: }
7569:
1.795 www 7570: ul#LC_toolbar li {
1.911 bisitz 7571: border:1px solid white;
7572: padding: 0;
7573: margin: 0;
7574: float: left;
7575: display:inline;
7576: vertical-align:middle;
1.1075.2.9 raeburn 7577: white-space: nowrap;
1.911 bisitz 7578: }
1.757 schulted 7579:
1.783 amueller 7580:
1.795 www 7581: a.LC_toolbarItem {
1.911 bisitz 7582: display:block;
7583: padding: 0;
7584: margin: 0;
7585: height: 32px;
7586: width: 32px;
7587: color:white;
7588: border: none;
7589: background-repeat:no-repeat;
7590: background-color:transparent;
1.757 schulted 7591: }
7592:
1.915 droeschl 7593: ul.LC_funclist {
7594: margin: 0;
7595: padding: 0.5em 1em 0.5em 0;
7596: }
7597:
1.933 droeschl 7598: ul.LC_funclist > li:first-child {
7599: font-weight:bold;
7600: margin-left:0.8em;
7601: }
7602:
1.915 droeschl 7603: ul.LC_funclist + ul.LC_funclist {
7604: /*
7605: left border as a seperator if we have more than
7606: one list
7607: */
7608: border-left: 1px solid $sidebg;
7609: /*
7610: this hides the left border behind the border of the
7611: outer box if element is wrapped to the next 'line'
7612: */
7613: margin-left: -1px;
7614: }
7615:
1.843 bisitz 7616: ul.LC_funclist li {
1.915 droeschl 7617: display: inline;
1.782 bisitz 7618: white-space: nowrap;
1.915 droeschl 7619: margin: 0 0 0 25px;
7620: line-height: 150%;
1.782 bisitz 7621: }
7622:
1.974 wenzelju 7623: .LC_hidden {
7624: display: none;
7625: }
7626:
1.1030 www 7627: .LCmodal-overlay {
7628: position:fixed;
7629: top:0;
7630: right:0;
7631: bottom:0;
7632: left:0;
7633: height:100%;
7634: width:100%;
7635: margin:0;
7636: padding:0;
7637: background:#999;
7638: opacity:.75;
7639: filter: alpha(opacity=75);
7640: -moz-opacity: 0.75;
7641: z-index:101;
7642: }
7643:
7644: * html .LCmodal-overlay {
7645: position: absolute;
7646: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7647: }
7648:
7649: .LCmodal-window {
7650: position:fixed;
7651: top:50%;
7652: left:50%;
7653: margin:0;
7654: padding:0;
7655: z-index:102;
7656: }
7657:
7658: * html .LCmodal-window {
7659: position:absolute;
7660: }
7661:
7662: .LCclose-window {
7663: position:absolute;
7664: width:32px;
7665: height:32px;
7666: right:8px;
7667: top:8px;
7668: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7669: text-indent:-99999px;
7670: overflow:hidden;
7671: cursor:pointer;
7672: }
7673:
1.1075.2.17 raeburn 7674: /*
7675: styles used by TTH when "Default set of options to pass to tth/m
7676: when converting TeX" in course settings has been set
7677:
7678: option passed: -t
7679:
7680: */
7681:
7682: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7683: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7684: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7685: td div.norm {line-height:normal;}
7686:
7687: /*
7688: option passed -y3
7689: */
7690:
7691: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7692: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7693: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7694:
1.1075.2.121 raeburn 7695: #LC_minitab_header {
7696: float:left;
7697: width:100%;
7698: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
7699: font-size:93%;
7700: line-height:normal;
7701: margin: 0.5em 0 0.5em 0;
7702: }
7703: #LC_minitab_header ul {
7704: margin:0;
7705: padding:10px 10px 0;
7706: list-style:none;
7707: }
7708: #LC_minitab_header li {
7709: float:left;
7710: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
7711: margin:0;
7712: padding:0 0 0 9px;
7713: }
7714: #LC_minitab_header a {
7715: display:block;
7716: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
7717: padding:5px 15px 4px 6px;
7718: }
7719: #LC_minitab_header #LC_current_minitab {
7720: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
7721: }
7722: #LC_minitab_header #LC_current_minitab a {
7723: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
7724: padding-bottom:5px;
7725: }
7726:
7727:
1.343 albertel 7728: END
7729: }
7730:
1.306 albertel 7731: =pod
7732:
7733: =item * &headtag()
7734:
7735: Returns a uniform footer for LON-CAPA web pages.
7736:
1.307 albertel 7737: Inputs: $title - optional title for the head
7738: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7739: $args - optional arguments
1.319 albertel 7740: force_register - if is true call registerurl so the remote is
7741: informed
1.415 albertel 7742: redirect -> array ref of
7743: 1- seconds before redirect occurs
7744: 2- url to redirect to
7745: 3- whether the side effect should occur
1.315 albertel 7746: (side effect of setting
7747: $env{'internal.head.redirect'} to the url
7748: redirected too)
1.352 albertel 7749: domain -> force to color decorate a page for a specific
7750: domain
7751: function -> force usage of a specific rolish color scheme
7752: bgcolor -> override the default page bgcolor
1.460 albertel 7753: no_auto_mt_title
7754: -> prevent &mt()ing the title arg
1.464 albertel 7755:
1.306 albertel 7756: =cut
7757:
7758: sub headtag {
1.313 albertel 7759: my ($title,$head_extra,$args) = @_;
1.306 albertel 7760:
1.363 albertel 7761: my $function = $args->{'function'} || &get_users_function();
7762: my $domain = $args->{'domain'} || &determinedomain();
7763: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7764: my $httphost = $args->{'use_absolute'};
1.418 albertel 7765: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7766: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7767: #time(),
1.418 albertel 7768: $env{'environment.color.timestamp'},
1.363 albertel 7769: $function,$domain,$bgcolor);
7770:
1.369 www 7771: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7772:
1.308 albertel 7773: my $result =
7774: '<head>'.
1.1075.2.56 raeburn 7775: &font_settings($args);
1.319 albertel 7776:
1.1075.2.72 raeburn 7777: my $inhibitprint;
7778: if ($args->{'print_suppress'}) {
7779: $inhibitprint = &print_suppression();
7780: }
1.1064 raeburn 7781:
1.461 albertel 7782: if (!$args->{'frameset'}) {
7783: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7784: }
1.1075.2.12 raeburn 7785: if ($args->{'force_register'}) {
7786: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7787: }
1.436 albertel 7788: if (!$args->{'no_nav_bar'}
7789: && !$args->{'only_body'}
7790: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7791: $result .= &help_menu_js($httphost);
1.1032 www 7792: $result.=&modal_window();
1.1038 www 7793: $result.=&togglebox_script();
1.1034 www 7794: $result.=&wishlist_window();
1.1041 www 7795: $result.=&LCprogressbarUpdate_script();
1.1034 www 7796: } else {
7797: if ($args->{'add_modal'}) {
7798: $result.=&modal_window();
7799: }
7800: if ($args->{'add_wishlist'}) {
7801: $result.=&wishlist_window();
7802: }
1.1038 www 7803: if ($args->{'add_togglebox'}) {
7804: $result.=&togglebox_script();
7805: }
1.1041 www 7806: if ($args->{'add_progressbar'}) {
7807: $result.=&LCprogressbarUpdate_script();
7808: }
1.436 albertel 7809: }
1.314 albertel 7810: if (ref($args->{'redirect'})) {
1.414 albertel 7811: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7812: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7813: if (!$inhibit_continue) {
7814: $env{'internal.head.redirect'} = $url;
7815: }
1.313 albertel 7816: $result.=<<ADDMETA
7817: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7818: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7819: ADDMETA
1.1075.2.89 raeburn 7820: } else {
7821: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7822: my $requrl = $env{'request.uri'};
7823: if ($requrl eq '') {
7824: $requrl = $ENV{'REQUEST_URI'};
7825: $requrl =~ s/\?.+$//;
7826: }
7827: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7828: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7829: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7830: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7831: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7832: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7833: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7834: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7835: if ($domdefs{'offloadnow'}{$lonhost}) {
7836: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7837: if (($newserver) && ($newserver ne $lonhost)) {
7838: my $numsec = 5;
7839: my $timeout = $numsec * 1000;
7840: my ($newurl,$locknum,%locks,$msg);
7841: if ($env{'request.role.adv'}) {
7842: ($locknum,%locks) = &Apache::lonnet::get_locks();
7843: }
7844: my $disable_submit = 0;
7845: if ($requrl =~ /$LONCAPA::assess_re/) {
7846: $disable_submit = 1;
7847: }
7848: if ($locknum) {
7849: my @lockinfo = sort(values(%locks));
7850: $msg = &mt('Once the following tasks are complete: ')."\\n".
7851: join(", ",sort(values(%locks)))."\\n".
7852: &mt('your session will be transferred to a different server, after you click "Roles".');
7853: } else {
7854: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7855: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7856: }
7857: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7858: $newurl = '/adm/switchserver?otherserver='.$newserver;
7859: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7860: $newurl .= '&role='.$env{'request.role'};
7861: }
7862: if ($env{'request.symb'}) {
7863: $newurl .= '&symb='.$env{'request.symb'};
7864: } else {
7865: $newurl .= '&origurl='.$requrl;
7866: }
7867: }
1.1075.2.98 raeburn 7868: &js_escape(\$msg);
1.1075.2.89 raeburn 7869: $result.=<<OFFLOAD
7870: <meta http-equiv="pragma" content="no-cache" />
7871: <script type="text/javascript">
1.1075.2.92 raeburn 7872: // <![CDATA[
1.1075.2.89 raeburn 7873: function LC_Offload_Now() {
7874: var dest = "$newurl";
7875: if (dest != '') {
7876: window.location.href="$newurl";
7877: }
7878: }
1.1075.2.92 raeburn 7879: \$(document).ready(function () {
7880: window.alert('$msg');
7881: if ($disable_submit) {
1.1075.2.89 raeburn 7882: \$(".LC_hwk_submit").prop("disabled", true);
7883: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 7884: }
7885: setTimeout('LC_Offload_Now()', $timeout);
7886: });
7887: // ]]>
1.1075.2.89 raeburn 7888: </script>
7889: OFFLOAD
7890: }
7891: }
7892: }
7893: }
7894: }
7895: }
1.313 albertel 7896: }
1.306 albertel 7897: if (!defined($title)) {
7898: $title = 'The LearningOnline Network with CAPA';
7899: }
1.460 albertel 7900: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7901: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7902: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7903: if (!$args->{'frameset'}) {
7904: $result .= ' /';
7905: }
7906: $result .= '>'
1.1064 raeburn 7907: .$inhibitprint
1.414 albertel 7908: .$head_extra;
1.1075.2.108 raeburn 7909: my $clientmobile;
7910: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
7911: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
7912: } else {
7913: $clientmobile = $env{'browser.mobile'};
7914: }
7915: if ($clientmobile) {
1.1075.2.42 raeburn 7916: $result .= '
7917: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7918: <meta name="apple-mobile-web-app-capable" content="yes" />';
7919: }
1.1075.2.126 raeburn 7920: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 7921: return $result.'</head>';
1.306 albertel 7922: }
7923:
7924: =pod
7925:
1.340 albertel 7926: =item * &font_settings()
7927:
7928: Returns neccessary <meta> to set the proper encoding
7929:
1.1075.2.56 raeburn 7930: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7931:
7932: =cut
7933:
7934: sub font_settings {
1.1075.2.56 raeburn 7935: my ($args) = @_;
1.340 albertel 7936: my $headerstring='';
1.1075.2.56 raeburn 7937: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7938: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7939: $headerstring.=
1.1075.2.61 raeburn 7940: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7941: if (!$args->{'frameset'}) {
7942: $headerstring.= ' /';
7943: }
7944: $headerstring .= '>'."\n";
1.340 albertel 7945: }
7946: return $headerstring;
7947: }
7948:
1.341 albertel 7949: =pod
7950:
1.1064 raeburn 7951: =item * &print_suppression()
7952:
7953: In course context returns css which causes the body to be blank when media="print",
7954: if printout generation is unavailable for the current resource.
7955:
7956: This could be because:
7957:
7958: (a) printstartdate is in the future
7959:
7960: (b) printenddate is in the past
7961:
7962: (c) there is an active exam block with "printout"
7963: functionality blocked
7964:
7965: Users with pav, pfo or evb privileges are exempt.
7966:
7967: Inputs: none
7968:
7969: =cut
7970:
7971:
7972: sub print_suppression {
7973: my $noprint;
7974: if ($env{'request.course.id'}) {
7975: my $scope = $env{'request.course.id'};
7976: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7977: (&Apache::lonnet::allowed('pfo',$scope))) {
7978: return;
7979: }
7980: if ($env{'request.course.sec'} ne '') {
7981: $scope .= "/$env{'request.course.sec'}";
7982: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7983: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7984: return;
1.1064 raeburn 7985: }
7986: }
7987: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7988: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 7989: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 7990: if ($blocked) {
7991: my $checkrole = "cm./$cdom/$cnum";
7992: if ($env{'request.course.sec'} ne '') {
7993: $checkrole .= "/$env{'request.course.sec'}";
7994: }
7995: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7996: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7997: $noprint = 1;
7998: }
7999: }
8000: unless ($noprint) {
8001: my $symb = &Apache::lonnet::symbread();
8002: if ($symb ne '') {
8003: my $navmap = Apache::lonnavmaps::navmap->new();
8004: if (ref($navmap)) {
8005: my $res = $navmap->getBySymb($symb);
8006: if (ref($res)) {
8007: if (!$res->resprintable()) {
8008: $noprint = 1;
8009: }
8010: }
8011: }
8012: }
8013: }
8014: if ($noprint) {
8015: return <<"ENDSTYLE";
8016: <style type="text/css" media="print">
8017: body { display:none }
8018: </style>
8019: ENDSTYLE
8020: }
8021: }
8022: return;
8023: }
8024:
8025: =pod
8026:
1.341 albertel 8027: =item * &xml_begin()
8028:
8029: Returns the needed doctype and <html>
8030:
8031: Inputs: none
8032:
8033: =cut
8034:
8035: sub xml_begin {
1.1075.2.61 raeburn 8036: my ($is_frameset) = @_;
1.341 albertel 8037: my $output='';
8038:
8039: if ($env{'browser.mathml'}) {
8040: $output='<?xml version="1.0"?>'
8041: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8042: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8043:
8044: # .'<!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">] >'
8045: .'<!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">'
8046: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8047: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8048: } elsif ($is_frameset) {
8049: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8050: '<html>'."\n";
1.341 albertel 8051: } else {
1.1075.2.61 raeburn 8052: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8053: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8054: }
8055: return $output;
8056: }
1.340 albertel 8057:
8058: =pod
8059:
1.306 albertel 8060: =item * &start_page()
8061:
8062: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8063:
1.648 raeburn 8064: Inputs:
8065:
8066: =over 4
8067:
8068: $title - optional title for the page
8069:
8070: $head_extra - optional extra HTML to incude inside the <head>
8071:
8072: $args - additional optional args supported are:
8073:
8074: =over 8
8075:
8076: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8077: arg on
1.814 bisitz 8078: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8079: add_entries -> additional attributes to add to the <body>
8080: domain -> force to color decorate a page for a
1.317 albertel 8081: specific domain
1.648 raeburn 8082: function -> force usage of a specific rolish color
1.317 albertel 8083: scheme
1.648 raeburn 8084: redirect -> see &headtag()
8085: bgcolor -> override the default page bg color
8086: js_ready -> return a string ready for being used in
1.317 albertel 8087: a javascript writeln
1.648 raeburn 8088: html_encode -> return a string ready for being used in
1.320 albertel 8089: a html attribute
1.648 raeburn 8090: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8091: $forcereg arg
1.648 raeburn 8092: frameset -> if true will start with a <frameset>
1.330 albertel 8093: rather than <body>
1.648 raeburn 8094: skip_phases -> hash ref of
1.338 albertel 8095: head -> skip the <html><head> generation
8096: body -> skip all <body> generation
1.1075.2.12 raeburn 8097: no_inline_link -> if true and in remote mode, don't show the
8098: 'Switch To Inline Menu' link
1.648 raeburn 8099: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8100: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8101: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8102: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8103: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8104: group -> includes the current group, if page is for a
8105: specific group
1.1075.2.133 raeburn 8106: use_absolute -> for request for external resource or syllabus, this
8107: will contain https://<hostname> if server uses
8108: https (as per hosts.tab), but request is for http
8109: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8110:
1.648 raeburn 8111: =back
1.460 albertel 8112:
1.648 raeburn 8113: =back
1.562 albertel 8114:
1.306 albertel 8115: =cut
8116:
8117: sub start_page {
1.309 albertel 8118: my ($title,$head_extra,$args) = @_;
1.318 albertel 8119: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8120:
1.315 albertel 8121: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8122: my ($result,@advtools);
1.964 droeschl 8123:
1.338 albertel 8124: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8125: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8126: }
8127:
8128: if (! exists($args->{'skip_phases'}{'body'}) ) {
8129: if ($args->{'frameset'}) {
8130: my $attr_string = &make_attr_string($args->{'force_register'},
8131: $args->{'add_entries'});
8132: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8133: } else {
8134: $result .=
8135: &bodytag($title,
8136: $args->{'function'}, $args->{'add_entries'},
8137: $args->{'only_body'}, $args->{'domain'},
8138: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8139: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8140: $args, \@advtools);
1.831 bisitz 8141: }
1.330 albertel 8142: }
1.338 albertel 8143:
1.315 albertel 8144: if ($args->{'js_ready'}) {
1.713 kaisler 8145: $result = &js_ready($result);
1.315 albertel 8146: }
1.320 albertel 8147: if ($args->{'html_encode'}) {
1.713 kaisler 8148: $result = &html_encode($result);
8149: }
8150:
1.813 bisitz 8151: # Preparation for new and consistent functionlist at top of screen
8152: # if ($args->{'functionlist'}) {
8153: # $result .= &build_functionlist();
8154: #}
8155:
1.964 droeschl 8156: # Don't add anything more if only_body wanted or in const space
8157: return $result if $args->{'only_body'}
8158: || $env{'request.state'} eq 'construct';
1.813 bisitz 8159:
8160: #Breadcrumbs
1.758 kaisler 8161: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8162: &Apache::lonhtmlcommon::clear_breadcrumbs();
8163: #if any br links exists, add them to the breadcrumbs
8164: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8165: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8166: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8167: }
8168: }
1.1075.2.19 raeburn 8169: # if @advtools array contains items add then to the breadcrumbs
8170: if (@advtools > 0) {
8171: &Apache::lonmenu::advtools_crumbs(@advtools);
8172: }
1.1075.2.123 raeburn 8173: my $menulink;
8174: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8175: if (exists($args->{'bread_crumbs_nomenu'})) {
8176: $menulink = 0;
8177: } else {
8178: undef($menulink);
8179: }
1.758 kaisler 8180: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8181: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8182: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8183: }else{
1.1075.2.123 raeburn 8184: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8185: }
1.1075.2.24 raeburn 8186: } elsif (($env{'environment.remote'} eq 'on') &&
8187: ($env{'form.inhibitmenu'} ne 'yes') &&
8188: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8189: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8190: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8191: }
1.315 albertel 8192: return $result;
1.306 albertel 8193: }
8194:
8195: sub end_page {
1.315 albertel 8196: my ($args) = @_;
8197: $env{'internal.end_page'}++;
1.330 albertel 8198: my $result;
1.335 albertel 8199: if ($args->{'discussion'}) {
8200: my ($target,$parser);
8201: if (ref($args->{'discussion'})) {
8202: ($target,$parser) =($args->{'discussion'}{'target'},
8203: $args->{'discussion'}{'parser'});
8204: }
8205: $result .= &Apache::lonxml::xmlend($target,$parser);
8206: }
1.330 albertel 8207: if ($args->{'frameset'}) {
8208: $result .= '</frameset>';
8209: } else {
1.635 raeburn 8210: $result .= &endbodytag($args);
1.330 albertel 8211: }
1.1075.2.6 raeburn 8212: unless ($args->{'notbody'}) {
8213: $result .= "\n</html>";
8214: }
1.330 albertel 8215:
1.315 albertel 8216: if ($args->{'js_ready'}) {
1.317 albertel 8217: $result = &js_ready($result);
1.315 albertel 8218: }
1.335 albertel 8219:
1.320 albertel 8220: if ($args->{'html_encode'}) {
8221: $result = &html_encode($result);
8222: }
1.335 albertel 8223:
1.315 albertel 8224: return $result;
8225: }
8226:
1.1034 www 8227: sub wishlist_window {
8228: return(<<'ENDWISHLIST');
1.1046 raeburn 8229: <script type="text/javascript">
1.1034 www 8230: // <![CDATA[
8231: // <!-- BEGIN LON-CAPA Internal
8232: function set_wishlistlink(title, path) {
8233: if (!title) {
8234: title = document.title;
8235: title = title.replace(/^LON-CAPA /,'');
8236: }
1.1075.2.65 raeburn 8237: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8238: title = title.replace("'","\\\'");
1.1034 www 8239: if (!path) {
8240: path = location.pathname;
8241: }
1.1075.2.65 raeburn 8242: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8243: path = path.replace("'","\\\'");
1.1034 www 8244: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8245: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8246: }
8247: // END LON-CAPA Internal -->
8248: // ]]>
8249: </script>
8250: ENDWISHLIST
8251: }
8252:
1.1030 www 8253: sub modal_window {
8254: return(<<'ENDMODAL');
1.1046 raeburn 8255: <script type="text/javascript">
1.1030 www 8256: // <![CDATA[
8257: // <!-- BEGIN LON-CAPA Internal
8258: var modalWindow = {
8259: parent:"body",
8260: windowId:null,
8261: content:null,
8262: width:null,
8263: height:null,
8264: close:function()
8265: {
8266: $(".LCmodal-window").remove();
8267: $(".LCmodal-overlay").remove();
8268: },
8269: open:function()
8270: {
8271: var modal = "";
8272: modal += "<div class=\"LCmodal-overlay\"></div>";
8273: 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;\">";
8274: modal += this.content;
8275: modal += "</div>";
8276:
8277: $(this.parent).append(modal);
8278:
8279: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8280: $(".LCclose-window").click(function(){modalWindow.close();});
8281: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8282: }
8283: };
1.1075.2.42 raeburn 8284: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8285: {
1.1075.2.119 raeburn 8286: source = source.replace(/'/g,"'");
1.1030 www 8287: modalWindow.windowId = "myModal";
8288: modalWindow.width = width;
8289: modalWindow.height = height;
1.1075.2.80 raeburn 8290: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8291: modalWindow.open();
1.1075.2.87 raeburn 8292: };
1.1030 www 8293: // END LON-CAPA Internal -->
8294: // ]]>
8295: </script>
8296: ENDMODAL
8297: }
8298:
8299: sub modal_link {
1.1075.2.42 raeburn 8300: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8301: unless ($width) { $width=480; }
8302: unless ($height) { $height=400; }
1.1031 www 8303: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8304: unless ($transparency) { $transparency='true'; }
8305:
1.1074 raeburn 8306: my $target_attr;
8307: if (defined($target)) {
8308: $target_attr = 'target="'.$target.'"';
8309: }
8310: return <<"ENDLINK";
1.1075.2.42 raeburn 8311: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8312: $linktext</a>
8313: ENDLINK
1.1030 www 8314: }
8315:
1.1032 www 8316: sub modal_adhoc_script {
8317: my ($funcname,$width,$height,$content)=@_;
8318: return (<<ENDADHOC);
1.1046 raeburn 8319: <script type="text/javascript">
1.1032 www 8320: // <![CDATA[
8321: var $funcname = function()
8322: {
8323: modalWindow.windowId = "myModal";
8324: modalWindow.width = $width;
8325: modalWindow.height = $height;
8326: modalWindow.content = '$content';
8327: modalWindow.open();
8328: };
8329: // ]]>
8330: </script>
8331: ENDADHOC
8332: }
8333:
1.1041 www 8334: sub modal_adhoc_inner {
8335: my ($funcname,$width,$height,$content)=@_;
8336: my $innerwidth=$width-20;
8337: $content=&js_ready(
1.1042 www 8338: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8339: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8340: $content.
1.1041 www 8341: &end_scrollbox().
1.1075.2.42 raeburn 8342: &end_page()
1.1041 www 8343: );
8344: return &modal_adhoc_script($funcname,$width,$height,$content);
8345: }
8346:
8347: sub modal_adhoc_window {
8348: my ($funcname,$width,$height,$content,$linktext)=@_;
8349: return &modal_adhoc_inner($funcname,$width,$height,$content).
8350: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8351: }
8352:
8353: sub modal_adhoc_launch {
8354: my ($funcname,$width,$height,$content)=@_;
8355: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8356: <script type="text/javascript">
8357: // <![CDATA[
8358: $funcname();
8359: // ]]>
8360: </script>
8361: ENDLAUNCH
8362: }
8363:
8364: sub modal_adhoc_close {
8365: return (<<ENDCLOSE);
8366: <script type="text/javascript">
8367: // <![CDATA[
8368: modalWindow.close();
8369: // ]]>
8370: </script>
8371: ENDCLOSE
8372: }
8373:
1.1038 www 8374: sub togglebox_script {
8375: return(<<ENDTOGGLE);
8376: <script type="text/javascript">
8377: // <![CDATA[
8378: function LCtoggleDisplay(id,hidetext,showtext) {
8379: link = document.getElementById(id + "link").childNodes[0];
8380: with (document.getElementById(id).style) {
8381: if (display == "none" ) {
8382: display = "inline";
8383: link.nodeValue = hidetext;
8384: } else {
8385: display = "none";
8386: link.nodeValue = showtext;
8387: }
8388: }
8389: }
8390: // ]]>
8391: </script>
8392: ENDTOGGLE
8393: }
8394:
1.1039 www 8395: sub start_togglebox {
8396: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8397: unless ($heading) { $heading=''; } else { $heading.=' '; }
8398: unless ($showtext) { $showtext=&mt('show'); }
8399: unless ($hidetext) { $hidetext=&mt('hide'); }
8400: unless ($headerbg) { $headerbg='#FFFFFF'; }
8401: return &start_data_table().
8402: &start_data_table_header_row().
8403: '<td bgcolor="'.$headerbg.'">'.$heading.
8404: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8405: $showtext.'\')">'.$showtext.'</a>]</td>'.
8406: &end_data_table_header_row().
8407: '<tr id="'.$id.'" style="display:none""><td>';
8408: }
8409:
8410: sub end_togglebox {
8411: return '</td></tr>'.&end_data_table();
8412: }
8413:
1.1041 www 8414: sub LCprogressbar_script {
1.1075.2.130 raeburn 8415: my ($id,$number_to_do)=@_;
8416: if ($number_to_do) {
8417: return(<<ENDPROGRESS);
1.1041 www 8418: <script type="text/javascript">
8419: // <![CDATA[
1.1045 www 8420: \$('#progressbar$id').progressbar({
1.1041 www 8421: value: 0,
8422: change: function(event, ui) {
8423: var newVal = \$(this).progressbar('option', 'value');
8424: \$('.pblabel', this).text(LCprogressTxt);
8425: }
8426: });
8427: // ]]>
8428: </script>
8429: ENDPROGRESS
1.1075.2.130 raeburn 8430: } else {
8431: return(<<ENDPROGRESS);
8432: <script type="text/javascript">
8433: // <![CDATA[
8434: \$('#progressbar$id').progressbar({
8435: value: false,
8436: create: function(event, ui) {
8437: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8438: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8439: }
8440: });
8441: // ]]>
8442: </script>
8443: ENDPROGRESS
8444: }
1.1041 www 8445: }
8446:
8447: sub LCprogressbarUpdate_script {
8448: return(<<ENDPROGRESSUPDATE);
8449: <style type="text/css">
8450: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 8451: .progress-label {position: absolute; width: 100%; text-align: center; top: 1px; font-weight: bold; text-shadow: 1px 1px 0 #fff;margin: 0; line-height: 200%; }
1.1041 www 8452: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8453: </style>
8454: <script type="text/javascript">
8455: // <![CDATA[
1.1045 www 8456: var LCprogressTxt='---';
8457:
1.1075.2.130 raeburn 8458: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 8459: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 8460: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
8461: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
8462: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
8463: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
8464: } else {
8465: \$('#progressbar'+id).progressbar('value',percent);
8466: }
1.1041 www 8467: }
8468: // ]]>
8469: </script>
8470: ENDPROGRESSUPDATE
8471: }
8472:
1.1042 www 8473: my $LClastpercent;
1.1045 www 8474: my $LCidcnt;
8475: my $LCcurrentid;
1.1042 www 8476:
1.1041 www 8477: sub LCprogressbar {
1.1075.2.130 raeburn 8478: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 8479: $LClastpercent=0;
1.1045 www 8480: $LCidcnt++;
8481: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 8482: my ($starting,$content);
8483: if ($number_to_do) {
8484: $starting=&mt('Starting');
8485: $content=(<<ENDPROGBAR);
8486: $preamble
1.1045 www 8487: <div id="progressbar$LCcurrentid">
1.1041 www 8488: <span class="pblabel">$starting</span>
8489: </div>
8490: ENDPROGBAR
1.1075.2.130 raeburn 8491: } else {
8492: $starting=&mt('Loading...');
8493: $LClastpercent='false';
8494: $content=(<<ENDPROGBAR);
8495: $preamble
8496: <div id="progressbar$LCcurrentid">
8497: <div class="progress-label">$starting</div>
8498: </div>
8499: ENDPROGBAR
8500: }
8501: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 8502: }
8503:
8504: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 8505: my ($r,$val,$text,$number_to_do)=@_;
8506: if ($number_to_do) {
8507: unless ($val) {
8508: if ($LClastpercent) {
8509: $val=$LClastpercent;
8510: } else {
8511: $val=0;
8512: }
8513: }
8514: if ($val<0) { $val=0; }
8515: if ($val>100) { $val=0; }
8516: $LClastpercent=$val;
8517: unless ($text) { $text=$val.'%'; }
8518: } else {
8519: $val = 'false';
1.1042 www 8520: }
1.1041 www 8521: $text=&js_ready($text);
1.1044 www 8522: &r_print($r,<<ENDUPDATE);
1.1041 www 8523: <script type="text/javascript">
8524: // <![CDATA[
1.1075.2.130 raeburn 8525: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 8526: // ]]>
8527: </script>
8528: ENDUPDATE
1.1035 www 8529: }
8530:
1.1042 www 8531: sub LCprogressbarClose {
8532: my ($r)=@_;
8533: $LClastpercent=0;
1.1044 www 8534: &r_print($r,<<ENDCLOSE);
1.1042 www 8535: <script type="text/javascript">
8536: // <![CDATA[
1.1045 www 8537: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8538: // ]]>
8539: </script>
8540: ENDCLOSE
1.1044 www 8541: }
8542:
8543: sub r_print {
8544: my ($r,$to_print)=@_;
8545: if ($r) {
8546: $r->print($to_print);
8547: $r->rflush();
8548: } else {
8549: print($to_print);
8550: }
1.1042 www 8551: }
8552:
1.320 albertel 8553: sub html_encode {
8554: my ($result) = @_;
8555:
1.322 albertel 8556: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8557:
8558: return $result;
8559: }
1.1044 www 8560:
1.317 albertel 8561: sub js_ready {
8562: my ($result) = @_;
8563:
1.323 albertel 8564: $result =~ s/[\n\r]/ /xmsg;
8565: $result =~ s/\\/\\\\/xmsg;
8566: $result =~ s/'/\\'/xmsg;
1.372 albertel 8567: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8568:
8569: return $result;
8570: }
8571:
1.315 albertel 8572: sub validate_page {
8573: if ( exists($env{'internal.start_page'})
1.316 albertel 8574: && $env{'internal.start_page'} > 1) {
8575: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8576: $env{'internal.start_page'}.' '.
1.316 albertel 8577: $ENV{'request.filename'});
1.315 albertel 8578: }
8579: if ( exists($env{'internal.end_page'})
1.316 albertel 8580: && $env{'internal.end_page'} > 1) {
8581: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8582: $env{'internal.end_page'}.' '.
1.316 albertel 8583: $env{'request.filename'});
1.315 albertel 8584: }
8585: if ( exists($env{'internal.start_page'})
8586: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8587: &Apache::lonnet::logthis('start_page called without end_page '.
8588: $env{'request.filename'});
1.315 albertel 8589: }
8590: if ( ! exists($env{'internal.start_page'})
8591: && exists($env{'internal.end_page'})) {
1.316 albertel 8592: &Apache::lonnet::logthis('end_page called without start_page'.
8593: $env{'request.filename'});
1.315 albertel 8594: }
1.306 albertel 8595: }
1.315 albertel 8596:
1.996 www 8597:
8598: sub start_scrollbox {
1.1075.2.56 raeburn 8599: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8600: unless ($outerwidth) { $outerwidth='520px'; }
8601: unless ($width) { $width='500px'; }
8602: unless ($height) { $height='200px'; }
1.1075 raeburn 8603: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8604: if ($id ne '') {
1.1075.2.42 raeburn 8605: $table_id = ' id="table_'.$id.'"';
8606: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8607: }
1.1075 raeburn 8608: if ($bgcolor ne '') {
8609: $tdcol = "background-color: $bgcolor;";
8610: }
1.1075.2.42 raeburn 8611: my $nicescroll_js;
8612: if ($env{'browser.mobile'}) {
8613: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8614: }
1.1075 raeburn 8615: return <<"END";
1.1075.2.42 raeburn 8616: $nicescroll_js
8617:
8618: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8619: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8620: END
1.996 www 8621: }
8622:
8623: sub end_scrollbox {
1.1036 www 8624: return '</div></td></tr></table>';
1.996 www 8625: }
8626:
1.1075.2.42 raeburn 8627: sub nicescroll_javascript {
8628: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8629: my %options;
8630: if (ref($cursor) eq 'HASH') {
8631: %options = %{$cursor};
8632: }
8633: unless ($options{'railalign'} =~ /^left|right$/) {
8634: $options{'railalign'} = 'left';
8635: }
8636: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8637: my $function = &get_users_function();
8638: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8639: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8640: $options{'cursorcolor'} = '#00F';
8641: }
8642: }
8643: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8644: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8645: $options{'cursoropacity'}='1.0';
8646: }
8647: } else {
8648: $options{'cursoropacity'}='1.0';
8649: }
8650: if ($options{'cursorfixedheight'} eq 'none') {
8651: delete($options{'cursorfixedheight'});
8652: } else {
8653: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8654: }
8655: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8656: delete($options{'railoffset'});
8657: }
8658: my @niceoptions;
8659: while (my($key,$value) = each(%options)) {
8660: if ($value =~ /^\{.+\}$/) {
8661: push(@niceoptions,$key.':'.$value);
8662: } else {
8663: push(@niceoptions,$key.':"'.$value.'"');
8664: }
8665: }
8666: my $nicescroll_js = '
8667: $(document).ready(
8668: function() {
8669: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8670: }
8671: );
8672: ';
8673: if ($framecheck) {
8674: $nicescroll_js .= '
8675: function expand_div(caller) {
8676: if (top === self) {
8677: document.getElementById("'.$id.'").style.width = "auto";
8678: document.getElementById("'.$id.'").style.height = "auto";
8679: } else {
8680: try {
8681: if (parent.frames) {
8682: if (parent.frames.length > 1) {
8683: var framesrc = parent.frames[1].location.href;
8684: var currsrc = framesrc.replace(/\#.*$/,"");
8685: if ((caller == "search") || (currsrc == "'.$location.'")) {
8686: document.getElementById("'.$id.'").style.width = "auto";
8687: document.getElementById("'.$id.'").style.height = "auto";
8688: }
8689: }
8690: }
8691: } catch (e) {
8692: return;
8693: }
8694: }
8695: return;
8696: }
8697: ';
8698: }
8699: if ($needjsready) {
8700: $nicescroll_js = '
8701: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8702: } else {
8703: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8704: }
8705: return $nicescroll_js;
8706: }
8707:
1.318 albertel 8708: sub simple_error_page {
1.1075.2.49 raeburn 8709: my ($r,$title,$msg,$args) = @_;
8710: if (ref($args) eq 'HASH') {
8711: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8712: } else {
8713: $msg = &mt($msg);
8714: }
8715:
1.318 albertel 8716: my $page =
8717: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8718: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8719: &Apache::loncommon::end_page();
8720: if (ref($r)) {
8721: $r->print($page);
1.327 albertel 8722: return;
1.318 albertel 8723: }
8724: return $page;
8725: }
1.347 albertel 8726:
8727: {
1.610 albertel 8728: my @row_count;
1.961 onken 8729:
8730: sub start_data_table_count {
8731: unshift(@row_count, 0);
8732: return;
8733: }
8734:
8735: sub end_data_table_count {
8736: shift(@row_count);
8737: return;
8738: }
8739:
1.347 albertel 8740: sub start_data_table {
1.1018 raeburn 8741: my ($add_class,$id) = @_;
1.422 albertel 8742: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8743: my $table_id;
8744: if (defined($id)) {
8745: $table_id = ' id="'.$id.'"';
8746: }
1.961 onken 8747: &start_data_table_count();
1.1018 raeburn 8748: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8749: }
8750:
8751: sub end_data_table {
1.961 onken 8752: &end_data_table_count();
1.389 albertel 8753: return '</table>'."\n";;
1.347 albertel 8754: }
8755:
8756: sub start_data_table_row {
1.974 wenzelju 8757: my ($add_class, $id) = @_;
1.610 albertel 8758: $row_count[0]++;
8759: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8760: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8761: $id = (' id="'.$id.'"') unless ($id eq '');
8762: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8763: }
1.471 banghart 8764:
8765: sub continue_data_table_row {
1.974 wenzelju 8766: my ($add_class, $id) = @_;
1.610 albertel 8767: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8768: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8769: $id = (' id="'.$id.'"') unless ($id eq '');
8770: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8771: }
1.347 albertel 8772:
8773: sub end_data_table_row {
1.389 albertel 8774: return '</tr>'."\n";;
1.347 albertel 8775: }
1.367 www 8776:
1.421 albertel 8777: sub start_data_table_empty_row {
1.707 bisitz 8778: # $row_count[0]++;
1.421 albertel 8779: return '<tr class="LC_empty_row" >'."\n";;
8780: }
8781:
8782: sub end_data_table_empty_row {
8783: return '</tr>'."\n";;
8784: }
8785:
1.367 www 8786: sub start_data_table_header_row {
1.389 albertel 8787: return '<tr class="LC_header_row">'."\n";;
1.367 www 8788: }
8789:
8790: sub end_data_table_header_row {
1.389 albertel 8791: return '</tr>'."\n";;
1.367 www 8792: }
1.890 droeschl 8793:
8794: sub data_table_caption {
8795: my $caption = shift;
8796: return "<caption class=\"LC_caption\">$caption</caption>";
8797: }
1.347 albertel 8798: }
8799:
1.548 albertel 8800: =pod
8801:
8802: =item * &inhibit_menu_check($arg)
8803:
8804: Checks for a inhibitmenu state and generates output to preserve it
8805:
8806: Inputs: $arg - can be any of
8807: - undef - in which case the return value is a string
8808: to add into arguments list of a uri
8809: - 'input' - in which case the return value is a HTML
8810: <form> <input> field of type hidden to
8811: preserve the value
8812: - a url - in which case the return value is the url with
8813: the neccesary cgi args added to preserve the
8814: inhibitmenu state
8815: - a ref to a url - no return value, but the string is
8816: updated to include the neccessary cgi
8817: args to preserve the inhibitmenu state
8818:
8819: =cut
8820:
8821: sub inhibit_menu_check {
8822: my ($arg) = @_;
8823: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8824: if ($arg eq 'input') {
8825: if ($env{'form.inhibitmenu'}) {
8826: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8827: } else {
8828: return
8829: }
8830: }
8831: if ($env{'form.inhibitmenu'}) {
8832: if (ref($arg)) {
8833: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8834: } elsif ($arg eq '') {
8835: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8836: } else {
8837: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8838: }
8839: }
8840: if (!ref($arg)) {
8841: return $arg;
8842: }
8843: }
8844:
1.251 albertel 8845: ###############################################
1.182 matthew 8846:
8847: =pod
8848:
1.549 albertel 8849: =back
8850:
8851: =head1 User Information Routines
8852:
8853: =over 4
8854:
1.405 albertel 8855: =item * &get_users_function()
1.182 matthew 8856:
8857: Used by &bodytag to determine the current users primary role.
8858: Returns either 'student','coordinator','admin', or 'author'.
8859:
8860: =cut
8861:
8862: ###############################################
8863: sub get_users_function {
1.815 tempelho 8864: my $function = 'norole';
1.818 tempelho 8865: if ($env{'request.role'}=~/^(st)/) {
8866: $function='student';
8867: }
1.907 raeburn 8868: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8869: $function='coordinator';
8870: }
1.258 albertel 8871: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8872: $function='admin';
8873: }
1.826 bisitz 8874: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8875: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8876: $function='author';
8877: }
8878: return $function;
1.54 www 8879: }
1.99 www 8880:
8881: ###############################################
8882:
1.233 raeburn 8883: =pod
8884:
1.821 raeburn 8885: =item * &show_course()
8886:
8887: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8888: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8889:
8890: Inputs:
8891: None
8892:
8893: Outputs:
8894: Scalar: 1 if 'Course' to be used, 0 otherwise.
8895:
8896: =cut
8897:
8898: ###############################################
8899: sub show_course {
8900: my $course = !$env{'user.adv'};
8901: if (!$env{'user.adv'}) {
8902: foreach my $env (keys(%env)) {
8903: next if ($env !~ m/^user\.priv\./);
8904: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8905: $course = 0;
8906: last;
8907: }
8908: }
8909: }
8910: return $course;
8911: }
8912:
8913: ###############################################
8914:
8915: =pod
8916:
1.542 raeburn 8917: =item * &check_user_status()
1.274 raeburn 8918:
8919: Determines current status of supplied role for a
8920: specific user. Roles can be active, previous or future.
8921:
8922: Inputs:
8923: user's domain, user's username, course's domain,
1.375 raeburn 8924: course's number, optional section ID.
1.274 raeburn 8925:
8926: Outputs:
8927: role status: active, previous or future.
8928:
8929: =cut
8930:
8931: sub check_user_status {
1.412 raeburn 8932: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8933: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 8934: my @uroles = keys(%userinfo);
1.274 raeburn 8935: my $srchstr;
8936: my $active_chk = 'none';
1.412 raeburn 8937: my $now = time;
1.274 raeburn 8938: if (@uroles > 0) {
1.908 raeburn 8939: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8940: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8941: } else {
1.412 raeburn 8942: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8943: }
8944: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8945: my $role_end = 0;
8946: my $role_start = 0;
8947: $active_chk = 'active';
1.412 raeburn 8948: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8949: $role_end = $1;
8950: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8951: $role_start = $1;
1.274 raeburn 8952: }
8953: }
8954: if ($role_start > 0) {
1.412 raeburn 8955: if ($now < $role_start) {
1.274 raeburn 8956: $active_chk = 'future';
8957: }
8958: }
8959: if ($role_end > 0) {
1.412 raeburn 8960: if ($now > $role_end) {
1.274 raeburn 8961: $active_chk = 'previous';
8962: }
8963: }
8964: }
8965: }
8966: return $active_chk;
8967: }
8968:
8969: ###############################################
8970:
8971: =pod
8972:
1.405 albertel 8973: =item * &get_sections()
1.233 raeburn 8974:
8975: Determines all the sections for a course including
8976: sections with students and sections containing other roles.
1.419 raeburn 8977: Incoming parameters:
8978:
8979: 1. domain
8980: 2. course number
8981: 3. reference to array containing roles for which sections should
8982: be gathered (optional).
8983: 4. reference to array containing status types for which sections
8984: should be gathered (optional).
8985:
8986: If the third argument is undefined, sections are gathered for any role.
8987: If the fourth argument is undefined, sections are gathered for any status.
8988: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8989:
1.374 raeburn 8990: Returns section hash (keys are section IDs, values are
8991: number of users in each section), subject to the
1.419 raeburn 8992: optional roles filter, optional status filter
1.233 raeburn 8993:
8994: =cut
8995:
8996: ###############################################
8997: sub get_sections {
1.419 raeburn 8998: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8999: if (!defined($cdom) || !defined($cnum)) {
9000: my $cid = $env{'request.course.id'};
9001:
9002: return if (!defined($cid));
9003:
9004: $cdom = $env{'course.'.$cid.'.domain'};
9005: $cnum = $env{'course.'.$cid.'.num'};
9006: }
9007:
9008: my %sectioncount;
1.419 raeburn 9009: my $now = time;
1.240 albertel 9010:
1.1075.2.33 raeburn 9011: my $check_students = 1;
9012: my $only_students = 0;
9013: if (ref($possible_roles) eq 'ARRAY') {
9014: if (grep(/^st$/,@{$possible_roles})) {
9015: if (@{$possible_roles} == 1) {
9016: $only_students = 1;
9017: }
9018: } else {
9019: $check_students = 0;
9020: }
9021: }
9022:
9023: if ($check_students) {
1.276 albertel 9024: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9025: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9026: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9027: my $start_index = &Apache::loncoursedata::CL_START();
9028: my $end_index = &Apache::loncoursedata::CL_END();
9029: my $status;
1.366 albertel 9030: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9031: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9032: $data->[$status_index],
9033: $data->[$start_index],
9034: $data->[$end_index]);
9035: if ($stu_status eq 'Active') {
9036: $status = 'active';
9037: } elsif ($end < $now) {
9038: $status = 'previous';
9039: } elsif ($start > $now) {
9040: $status = 'future';
9041: }
9042: if ($section ne '-1' && $section !~ /^\s*$/) {
9043: if ((!defined($possible_status)) || (($status ne '') &&
9044: (grep/^\Q$status\E$/,@{$possible_status}))) {
9045: $sectioncount{$section}++;
9046: }
1.240 albertel 9047: }
9048: }
9049: }
1.1075.2.33 raeburn 9050: if ($only_students) {
9051: return %sectioncount;
9052: }
1.240 albertel 9053: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9054: foreach my $user (sort(keys(%courseroles))) {
9055: if ($user !~ /^(\w{2})/) { next; }
9056: my ($role) = ($user =~ /^(\w{2})/);
9057: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9058: my ($section,$status);
1.240 albertel 9059: if ($role eq 'cr' &&
9060: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9061: $section=$1;
9062: }
9063: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9064: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9065: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9066: if ($end == -1 && $start == -1) {
9067: next; #deleted role
9068: }
9069: if (!defined($possible_status)) {
9070: $sectioncount{$section}++;
9071: } else {
9072: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9073: $status = 'active';
9074: } elsif ($end < $now) {
9075: $status = 'future';
9076: } elsif ($start > $now) {
9077: $status = 'previous';
9078: }
9079: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9080: $sectioncount{$section}++;
9081: }
9082: }
1.233 raeburn 9083: }
1.366 albertel 9084: return %sectioncount;
1.233 raeburn 9085: }
9086:
1.274 raeburn 9087: ###############################################
1.294 raeburn 9088:
9089: =pod
1.405 albertel 9090:
9091: =item * &get_course_users()
9092:
1.275 raeburn 9093: Retrieves usernames:domains for users in the specified course
9094: with specific role(s), and access status.
9095:
9096: Incoming parameters:
1.277 albertel 9097: 1. course domain
9098: 2. course number
9099: 3. access status: users must have - either active,
1.275 raeburn 9100: previous, future, or all.
1.277 albertel 9101: 4. reference to array of permissible roles
1.288 raeburn 9102: 5. reference to array of section restrictions (optional)
9103: 6. reference to results object (hash of hashes).
9104: 7. reference to optional userdata hash
1.609 raeburn 9105: 8. reference to optional statushash
1.630 raeburn 9106: 9. flag if privileged users (except those set to unhide in
9107: course settings) should be excluded
1.609 raeburn 9108: Keys of top level results hash are roles.
1.275 raeburn 9109: Keys of inner hashes are username:domain, with
9110: values set to access type.
1.288 raeburn 9111: Optional userdata hash returns an array with arguments in the
9112: same order as loncoursedata::get_classlist() for student data.
9113:
1.609 raeburn 9114: Optional statushash returns
9115:
1.288 raeburn 9116: Entries for end, start, section and status are blank because
9117: of the possibility of multiple values for non-student roles.
9118:
1.275 raeburn 9119: =cut
1.405 albertel 9120:
1.275 raeburn 9121: ###############################################
1.405 albertel 9122:
1.275 raeburn 9123: sub get_course_users {
1.630 raeburn 9124: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9125: my %idx = ();
1.419 raeburn 9126: my %seclists;
1.288 raeburn 9127:
9128: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9129: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9130: $idx{end} = &Apache::loncoursedata::CL_END();
9131: $idx{start} = &Apache::loncoursedata::CL_START();
9132: $idx{id} = &Apache::loncoursedata::CL_ID();
9133: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9134: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9135: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9136:
1.290 albertel 9137: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9138: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9139: my $now = time;
1.277 albertel 9140: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9141: my $match = 0;
1.412 raeburn 9142: my $secmatch = 0;
1.419 raeburn 9143: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9144: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9145: if ($section eq '') {
9146: $section = 'none';
9147: }
1.291 albertel 9148: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9149: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9150: $secmatch = 1;
9151: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9152: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9153: $secmatch = 1;
9154: }
9155: } else {
1.419 raeburn 9156: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9157: $secmatch = 1;
9158: }
1.290 albertel 9159: }
1.412 raeburn 9160: if (!$secmatch) {
9161: next;
9162: }
1.419 raeburn 9163: }
1.275 raeburn 9164: if (defined($$types{'active'})) {
1.288 raeburn 9165: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9166: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9167: $match = 1;
1.275 raeburn 9168: }
9169: }
9170: if (defined($$types{'previous'})) {
1.609 raeburn 9171: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9172: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9173: $match = 1;
1.275 raeburn 9174: }
9175: }
9176: if (defined($$types{'future'})) {
1.609 raeburn 9177: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9178: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9179: $match = 1;
1.275 raeburn 9180: }
9181: }
1.609 raeburn 9182: if ($match) {
9183: push(@{$seclists{$student}},$section);
9184: if (ref($userdata) eq 'HASH') {
9185: $$userdata{$student} = $$classlist{$student};
9186: }
9187: if (ref($statushash) eq 'HASH') {
9188: $statushash->{$student}{'st'}{$section} = $status;
9189: }
1.288 raeburn 9190: }
1.275 raeburn 9191: }
9192: }
1.412 raeburn 9193: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9194: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9195: my $now = time;
1.609 raeburn 9196: my %displaystatus = ( previous => 'Expired',
9197: active => 'Active',
9198: future => 'Future',
9199: );
1.1075.2.36 raeburn 9200: my (%nothide,@possdoms);
1.630 raeburn 9201: if ($hidepriv) {
9202: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9203: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9204: if ($user !~ /:/) {
9205: $nothide{join(':',split(/[\@]/,$user))}=1;
9206: } else {
9207: $nothide{$user} = 1;
9208: }
9209: }
1.1075.2.36 raeburn 9210: my @possdoms = ($cdom);
9211: if ($coursehash{'checkforpriv'}) {
9212: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9213: }
1.630 raeburn 9214: }
1.439 raeburn 9215: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9216: my $match = 0;
1.412 raeburn 9217: my $secmatch = 0;
1.439 raeburn 9218: my $status;
1.412 raeburn 9219: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9220: $user =~ s/:$//;
1.439 raeburn 9221: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9222: if ($end == -1 || $start == -1) {
9223: next;
9224: }
9225: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9226: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9227: my ($uname,$udom) = split(/:/,$user);
9228: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9229: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9230: $secmatch = 1;
9231: } elsif ($usec eq '') {
1.420 albertel 9232: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9233: $secmatch = 1;
9234: }
9235: } else {
9236: if (grep(/^\Q$usec\E$/,@{$sections})) {
9237: $secmatch = 1;
9238: }
9239: }
9240: if (!$secmatch) {
9241: next;
9242: }
1.288 raeburn 9243: }
1.419 raeburn 9244: if ($usec eq '') {
9245: $usec = 'none';
9246: }
1.275 raeburn 9247: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9248: if ($hidepriv) {
1.1075.2.36 raeburn 9249: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9250: (!$nothide{$uname.':'.$udom})) {
9251: next;
9252: }
9253: }
1.503 raeburn 9254: if ($end > 0 && $end < $now) {
1.439 raeburn 9255: $status = 'previous';
9256: } elsif ($start > $now) {
9257: $status = 'future';
9258: } else {
9259: $status = 'active';
9260: }
1.277 albertel 9261: foreach my $type (keys(%{$types})) {
1.275 raeburn 9262: if ($status eq $type) {
1.420 albertel 9263: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9264: push(@{$$users{$role}{$user}},$type);
9265: }
1.288 raeburn 9266: $match = 1;
9267: }
9268: }
1.419 raeburn 9269: if (($match) && (ref($userdata) eq 'HASH')) {
9270: if (!exists($$userdata{$uname.':'.$udom})) {
9271: &get_user_info($udom,$uname,\%idx,$userdata);
9272: }
1.420 albertel 9273: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9274: push(@{$seclists{$uname.':'.$udom}},$usec);
9275: }
1.609 raeburn 9276: if (ref($statushash) eq 'HASH') {
9277: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9278: }
1.275 raeburn 9279: }
9280: }
9281: }
9282: }
1.290 albertel 9283: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9284: if ((defined($cdom)) && (defined($cnum))) {
9285: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9286: if ( defined($csettings{'internal.courseowner'}) ) {
9287: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9288: next if ($owner eq '');
9289: my ($ownername,$ownerdom);
9290: if ($owner =~ /^([^:]+):([^:]+)$/) {
9291: $ownername = $1;
9292: $ownerdom = $2;
9293: } else {
9294: $ownername = $owner;
9295: $ownerdom = $cdom;
9296: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9297: }
9298: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9299: if (defined($userdata) &&
1.609 raeburn 9300: !exists($$userdata{$owner})) {
9301: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9302: if (!grep(/^none$/,@{$seclists{$owner}})) {
9303: push(@{$seclists{$owner}},'none');
9304: }
9305: if (ref($statushash) eq 'HASH') {
9306: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9307: }
1.290 albertel 9308: }
1.279 raeburn 9309: }
9310: }
9311: }
1.419 raeburn 9312: foreach my $user (keys(%seclists)) {
9313: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9314: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9315: }
1.275 raeburn 9316: }
9317: return;
9318: }
9319:
1.288 raeburn 9320: sub get_user_info {
9321: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9322: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9323: &plainname($uname,$udom,'lastname');
1.291 albertel 9324: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9325: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9326: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9327: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9328: return;
9329: }
1.275 raeburn 9330:
1.472 raeburn 9331: ###############################################
9332:
9333: =pod
9334:
9335: =item * &get_user_quota()
9336:
1.1075.2.41 raeburn 9337: Retrieves quota assigned for storage of user files.
9338: Default is to report quota for portfolio files.
1.472 raeburn 9339:
9340: Incoming parameters:
9341: 1. user's username
9342: 2. user's domain
1.1075.2.41 raeburn 9343: 3. quota name - portfolio, author, or course
9344: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9345: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9346: course
1.472 raeburn 9347:
9348: Returns:
1.1075.2.58 raeburn 9349: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9350: 2. (Optional) Type of setting: custom or default
9351: (individually assigned or default for user's
9352: institutional status).
9353: 3. (Optional) - User's institutional status (e.g., faculty, staff
9354: or student - types as defined in localenroll::inst_usertypes
9355: for user's domain, which determines default quota for user.
9356: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9357:
9358: If a value has been stored in the user's environment,
1.536 raeburn 9359: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9360: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9361:
9362: =cut
9363:
9364: ###############################################
9365:
9366:
9367: sub get_user_quota {
1.1075.2.42 raeburn 9368: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9369: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9370: if (!defined($udom)) {
9371: $udom = $env{'user.domain'};
9372: }
9373: if (!defined($uname)) {
9374: $uname = $env{'user.name'};
9375: }
9376: if (($udom eq '' || $uname eq '') ||
9377: ($udom eq 'public') && ($uname eq 'public')) {
9378: $quota = 0;
1.536 raeburn 9379: $quotatype = 'default';
9380: $defquota = 0;
1.472 raeburn 9381: } else {
1.536 raeburn 9382: my $inststatus;
1.1075.2.41 raeburn 9383: if ($quotaname eq 'course') {
9384: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9385: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9386: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9387: } else {
9388: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9389: $quota = $cenv{'internal.uploadquota'};
9390: }
1.536 raeburn 9391: } else {
1.1075.2.41 raeburn 9392: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9393: if ($quotaname eq 'author') {
9394: $quota = $env{'environment.authorquota'};
9395: } else {
9396: $quota = $env{'environment.portfolioquota'};
9397: }
9398: $inststatus = $env{'environment.inststatus'};
9399: } else {
9400: my %userenv =
9401: &Apache::lonnet::get('environment',['portfolioquota',
9402: 'authorquota','inststatus'],$udom,$uname);
9403: my ($tmp) = keys(%userenv);
9404: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9405: if ($quotaname eq 'author') {
9406: $quota = $userenv{'authorquota'};
9407: } else {
9408: $quota = $userenv{'portfolioquota'};
9409: }
9410: $inststatus = $userenv{'inststatus'};
9411: } else {
9412: undef(%userenv);
9413: }
9414: }
9415: }
9416: if ($quota eq '' || wantarray) {
9417: if ($quotaname eq 'course') {
9418: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9419: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9420: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9421: $defquota = $domdefs{$crstype.'quota'};
9422: }
9423: if ($defquota eq '') {
9424: $defquota = 500;
9425: }
1.1075.2.41 raeburn 9426: } else {
9427: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9428: }
9429: if ($quota eq '') {
9430: $quota = $defquota;
9431: $quotatype = 'default';
9432: } else {
9433: $quotatype = 'custom';
9434: }
1.472 raeburn 9435: }
9436: }
1.536 raeburn 9437: if (wantarray) {
9438: return ($quota,$quotatype,$settingstatus,$defquota);
9439: } else {
9440: return $quota;
9441: }
1.472 raeburn 9442: }
9443:
9444: ###############################################
9445:
9446: =pod
9447:
9448: =item * &default_quota()
9449:
1.536 raeburn 9450: Retrieves default quota assigned for storage of user portfolio files,
9451: given an (optional) user's institutional status.
1.472 raeburn 9452:
9453: Incoming parameters:
1.1075.2.42 raeburn 9454:
1.472 raeburn 9455: 1. domain
1.536 raeburn 9456: 2. (Optional) institutional status(es). This is a : separated list of
9457: status types (e.g., faculty, staff, student etc.)
9458: which apply to the user for whom the default is being retrieved.
9459: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9460: default quota will be returned.
9461: 3. quota name - portfolio, author, or course
9462: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9463:
9464: Returns:
1.1075.2.42 raeburn 9465:
1.1075.2.58 raeburn 9466: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9467: 2. (Optional) institutional type which determined the value of the
9468: default quota.
1.472 raeburn 9469:
9470: If a value has been stored in the domain's configuration db,
9471: it will return that, otherwise it returns 20 (for backwards
9472: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9473: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9474:
1.536 raeburn 9475: If the user's status includes multiple types (e.g., staff and student),
9476: the largest default quota which applies to the user determines the
9477: default quota returned.
9478:
1.472 raeburn 9479: =cut
9480:
9481: ###############################################
9482:
9483:
9484: sub default_quota {
1.1075.2.41 raeburn 9485: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9486: my ($defquota,$settingstatus);
9487: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9488: ['quotas'],$udom);
1.1075.2.41 raeburn 9489: my $key = 'defaultquota';
9490: if ($quotaname eq 'author') {
9491: $key = 'authorquota';
9492: }
1.622 raeburn 9493: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9494: if ($inststatus ne '') {
1.765 raeburn 9495: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9496: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9497: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9498: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9499: if ($defquota eq '') {
1.1075.2.41 raeburn 9500: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9501: $settingstatus = $item;
1.1075.2.41 raeburn 9502: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9503: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9504: $settingstatus = $item;
9505: }
9506: }
1.1075.2.41 raeburn 9507: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9508: if ($quotahash{'quotas'}{$item} ne '') {
9509: if ($defquota eq '') {
9510: $defquota = $quotahash{'quotas'}{$item};
9511: $settingstatus = $item;
9512: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9513: $defquota = $quotahash{'quotas'}{$item};
9514: $settingstatus = $item;
9515: }
1.536 raeburn 9516: }
9517: }
9518: }
9519: }
9520: if ($defquota eq '') {
1.1075.2.41 raeburn 9521: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9522: $defquota = $quotahash{'quotas'}{$key}{'default'};
9523: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9524: $defquota = $quotahash{'quotas'}{'default'};
9525: }
1.536 raeburn 9526: $settingstatus = 'default';
1.1075.2.42 raeburn 9527: if ($defquota eq '') {
9528: if ($quotaname eq 'author') {
9529: $defquota = 500;
9530: }
9531: }
1.536 raeburn 9532: }
9533: } else {
9534: $settingstatus = 'default';
1.1075.2.41 raeburn 9535: if ($quotaname eq 'author') {
9536: $defquota = 500;
9537: } else {
9538: $defquota = 20;
9539: }
1.536 raeburn 9540: }
9541: if (wantarray) {
9542: return ($defquota,$settingstatus);
1.472 raeburn 9543: } else {
1.536 raeburn 9544: return $defquota;
1.472 raeburn 9545: }
9546: }
9547:
1.1075.2.41 raeburn 9548: ###############################################
9549:
9550: =pod
9551:
1.1075.2.42 raeburn 9552: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9553:
9554: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9555: of existing file within authoring space will cause quota for the authoring
9556: space to be exceeded.
9557:
9558: Same, if upload of a file directly to a course/community via Course Editor
9559: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9560:
1.1075.2.61 raeburn 9561: Inputs: 7
1.1075.2.42 raeburn 9562: 1. username or coursenum
1.1075.2.41 raeburn 9563: 2. domain
1.1075.2.42 raeburn 9564: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9565: 4. filename of file for which action is being requested
9566: 5. filesize (kB) of file
9567: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9568: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9569:
9570: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9571: otherwise return null.
9572:
1.1075.2.42 raeburn 9573: =back
9574:
1.1075.2.41 raeburn 9575: =cut
9576:
1.1075.2.42 raeburn 9577: sub excess_filesize_warning {
1.1075.2.59 raeburn 9578: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9579: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9580: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9581: if ($context eq 'author') {
9582: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9583: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9584: } else {
9585: foreach my $subdir ('docs','supplemental') {
9586: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9587: }
9588: }
1.1075.2.41 raeburn 9589: $disk_quota = int($disk_quota * 1000);
9590: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9591: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9592: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9593: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9594: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9595: $disk_quota,$current_disk_usage).
9596: '</p>';
9597: }
9598: return;
9599: }
9600:
9601: ###############################################
9602:
9603:
1.384 raeburn 9604: sub get_secgrprole_info {
9605: my ($cdom,$cnum,$needroles,$type) = @_;
9606: my %sections_count = &get_sections($cdom,$cnum);
9607: my @sections = (sort {$a <=> $b} keys(%sections_count));
9608: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9609: my @groups = sort(keys(%curr_groups));
9610: my $allroles = [];
9611: my $rolehash;
9612: my $accesshash = {
9613: active => 'Currently has access',
9614: future => 'Will have future access',
9615: previous => 'Previously had access',
9616: };
9617: if ($needroles) {
9618: $rolehash = {'all' => 'all'};
1.385 albertel 9619: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9620: if (&Apache::lonnet::error(%user_roles)) {
9621: undef(%user_roles);
9622: }
9623: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9624: my ($role)=split(/\:/,$item,2);
9625: if ($role eq 'cr') { next; }
9626: if ($role =~ /^cr/) {
9627: $$rolehash{$role} = (split('/',$role))[3];
9628: } else {
9629: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9630: }
9631: }
9632: foreach my $key (sort(keys(%{$rolehash}))) {
9633: push(@{$allroles},$key);
9634: }
9635: push (@{$allroles},'st');
9636: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9637: }
9638: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9639: }
9640:
1.555 raeburn 9641: sub user_picker {
1.1075.2.127 raeburn 9642: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 9643: my $currdom = $dom;
1.1075.2.114 raeburn 9644: my @alldoms = &Apache::lonnet::all_domains();
9645: if (@alldoms == 1) {
9646: my %domsrch = &Apache::lonnet::get_dom('configuration',
9647: ['directorysrch'],$alldoms[0]);
9648: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
9649: my $showdom = $domdesc;
9650: if ($showdom eq '') {
9651: $showdom = $dom;
9652: }
9653: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
9654: if ((!$domsrch{'directorysrch'}{'available'}) &&
9655: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
9656: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
9657: }
9658: }
9659: }
1.555 raeburn 9660: my %curr_selected = (
9661: srchin => 'dom',
1.580 raeburn 9662: srchby => 'lastname',
1.555 raeburn 9663: );
9664: my $srchterm;
1.625 raeburn 9665: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9666: if ($srch->{'srchby'} ne '') {
9667: $curr_selected{'srchby'} = $srch->{'srchby'};
9668: }
9669: if ($srch->{'srchin'} ne '') {
9670: $curr_selected{'srchin'} = $srch->{'srchin'};
9671: }
9672: if ($srch->{'srchtype'} ne '') {
9673: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9674: }
9675: if ($srch->{'srchdomain'} ne '') {
9676: $currdom = $srch->{'srchdomain'};
9677: }
9678: $srchterm = $srch->{'srchterm'};
9679: }
1.1075.2.98 raeburn 9680: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9681: 'usr' => 'Search criteria',
1.563 raeburn 9682: 'doma' => 'Domain/institution to search',
1.558 albertel 9683: 'uname' => 'username',
9684: 'lastname' => 'last name',
1.555 raeburn 9685: 'lastfirst' => 'last name, first name',
1.558 albertel 9686: 'crs' => 'in this course',
1.576 raeburn 9687: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9688: 'alc' => 'all LON-CAPA',
1.573 raeburn 9689: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9690: 'exact' => 'is',
9691: 'contains' => 'contains',
1.569 raeburn 9692: 'begins' => 'begins with',
1.1075.2.98 raeburn 9693: );
9694: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9695: 'youm' => "You must include some text to search for.",
9696: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9697: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9698: 'yomc' => "You must choose a domain when using an institutional directory search.",
9699: 'ymcd' => "You must choose a domain when using a domain search.",
9700: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9701: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9702: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9703: );
1.1075.2.98 raeburn 9704: &html_escape(\%html_lt);
9705: &js_escape(\%js_lt);
1.1075.2.115 raeburn 9706: my $domform;
1.1075.2.126 raeburn 9707: my $allow_blank = 1;
1.1075.2.115 raeburn 9708: if ($fixeddom) {
1.1075.2.126 raeburn 9709: $allow_blank = 0;
9710: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 9711: } else {
1.1075.2.126 raeburn 9712: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 9713: }
1.563 raeburn 9714: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9715:
9716: my @srchins = ('crs','dom','alc','instd');
9717:
9718: foreach my $option (@srchins) {
9719: # FIXME 'alc' option unavailable until
9720: # loncreateuser::print_user_query_page()
9721: # has been completed.
9722: next if ($option eq 'alc');
1.880 raeburn 9723: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9724: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 9725: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 9726: if ($curr_selected{'srchin'} eq $option) {
9727: $srchinsel .= '
1.1075.2.98 raeburn 9728: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9729: } else {
9730: $srchinsel .= '
1.1075.2.98 raeburn 9731: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9732: }
1.555 raeburn 9733: }
1.563 raeburn 9734: $srchinsel .= "\n </select>\n";
1.555 raeburn 9735:
9736: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9737: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9738: if ($curr_selected{'srchby'} eq $option) {
9739: $srchbysel .= '
1.1075.2.98 raeburn 9740: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9741: } else {
9742: $srchbysel .= '
1.1075.2.98 raeburn 9743: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9744: }
9745: }
9746: $srchbysel .= "\n </select>\n";
9747:
9748: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9749: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9750: if ($curr_selected{'srchtype'} eq $option) {
9751: $srchtypesel .= '
1.1075.2.98 raeburn 9752: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9753: } else {
9754: $srchtypesel .= '
1.1075.2.98 raeburn 9755: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9756: }
9757: }
9758: $srchtypesel .= "\n </select>\n";
9759:
1.558 albertel 9760: my ($newuserscript,$new_user_create);
1.994 raeburn 9761: my $context_dom = $env{'request.role.domain'};
9762: if ($context eq 'requestcrs') {
9763: if ($env{'form.coursedom'} ne '') {
9764: $context_dom = $env{'form.coursedom'};
9765: }
9766: }
1.556 raeburn 9767: if ($forcenewuser) {
1.576 raeburn 9768: if (ref($srch) eq 'HASH') {
1.994 raeburn 9769: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9770: if ($cancreate) {
9771: $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>';
9772: } else {
1.799 bisitz 9773: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9774: my %usertypetext = (
9775: official => 'institutional',
9776: unofficial => 'non-institutional',
9777: );
1.799 bisitz 9778: $new_user_create = '<p class="LC_warning">'
9779: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9780: .' '
9781: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9782: ,'<a href="'.$helplink.'">','</a>')
9783: .'</p><br />';
1.627 raeburn 9784: }
1.576 raeburn 9785: }
9786: }
9787:
1.556 raeburn 9788: $newuserscript = <<"ENDSCRIPT";
9789:
1.570 raeburn 9790: function setSearch(createnew,callingForm) {
1.556 raeburn 9791: if (createnew == 1) {
1.570 raeburn 9792: for (var i=0; i<callingForm.srchby.length; i++) {
9793: if (callingForm.srchby.options[i].value == 'uname') {
9794: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9795: }
9796: }
1.570 raeburn 9797: for (var i=0; i<callingForm.srchin.length; i++) {
9798: if ( callingForm.srchin.options[i].value == 'dom') {
9799: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9800: }
9801: }
1.570 raeburn 9802: for (var i=0; i<callingForm.srchtype.length; i++) {
9803: if (callingForm.srchtype.options[i].value == 'exact') {
9804: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9805: }
9806: }
1.570 raeburn 9807: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9808: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9809: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9810: }
9811: }
9812: }
9813: }
9814: ENDSCRIPT
1.558 albertel 9815:
1.556 raeburn 9816: }
9817:
1.555 raeburn 9818: my $output = <<"END_BLOCK";
1.556 raeburn 9819: <script type="text/javascript">
1.824 bisitz 9820: // <![CDATA[
1.570 raeburn 9821: function validateEntry(callingForm) {
1.558 albertel 9822:
1.556 raeburn 9823: var checkok = 1;
1.558 albertel 9824: var srchin;
1.570 raeburn 9825: for (var i=0; i<callingForm.srchin.length; i++) {
9826: if ( callingForm.srchin[i].checked ) {
9827: srchin = callingForm.srchin[i].value;
1.558 albertel 9828: }
9829: }
9830:
1.570 raeburn 9831: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9832: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9833: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9834: var srchterm = callingForm.srchterm.value;
9835: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9836: var msg = "";
9837:
9838: if (srchterm == "") {
9839: checkok = 0;
1.1075.2.98 raeburn 9840: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9841: }
9842:
1.569 raeburn 9843: if (srchtype== 'begins') {
9844: if (srchterm.length < 2) {
9845: checkok = 0;
1.1075.2.98 raeburn 9846: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9847: }
9848: }
9849:
1.556 raeburn 9850: if (srchtype== 'contains') {
9851: if (srchterm.length < 3) {
9852: checkok = 0;
1.1075.2.98 raeburn 9853: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 9854: }
9855: }
9856: if (srchin == 'instd') {
9857: if (srchdomain == '') {
9858: checkok = 0;
1.1075.2.98 raeburn 9859: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 9860: }
9861: }
9862: if (srchin == 'dom') {
9863: if (srchdomain == '') {
9864: checkok = 0;
1.1075.2.98 raeburn 9865: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 9866: }
9867: }
9868: if (srchby == 'lastfirst') {
9869: if (srchterm.indexOf(",") == -1) {
9870: checkok = 0;
1.1075.2.98 raeburn 9871: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 9872: }
9873: if (srchterm.indexOf(",") == srchterm.length -1) {
9874: checkok = 0;
1.1075.2.98 raeburn 9875: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 9876: }
9877: }
9878: if (checkok == 0) {
1.1075.2.98 raeburn 9879: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 9880: return;
9881: }
9882: if (checkok == 1) {
1.570 raeburn 9883: callingForm.submit();
1.556 raeburn 9884: }
9885: }
9886:
9887: $newuserscript
9888:
1.824 bisitz 9889: // ]]>
1.556 raeburn 9890: </script>
1.558 albertel 9891:
9892: $new_user_create
9893:
1.555 raeburn 9894: END_BLOCK
1.558 albertel 9895:
1.876 raeburn 9896: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 9897: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 9898: $domform.
9899: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 9900: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 9901: $srchbysel.
9902: $srchtypesel.
9903: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9904: $srchinsel.
9905: &Apache::lonhtmlcommon::row_closure(1).
9906: &Apache::lonhtmlcommon::end_pick_box().
9907: '<br />';
1.1075.2.114 raeburn 9908: return ($output,1);
1.555 raeburn 9909: }
9910:
1.612 raeburn 9911: sub user_rule_check {
1.615 raeburn 9912: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 9913: my ($response,%inst_response);
1.612 raeburn 9914: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 9915: if (keys(%{$usershash}) > 1) {
9916: my (%by_username,%by_id,%userdoms);
9917: my $checkid;
1.612 raeburn 9918: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 9919: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
9920: $checkid = 1;
9921: }
9922: }
9923: foreach my $user (keys(%{$usershash})) {
9924: my ($uname,$udom) = split(/:/,$user);
9925: if ($checkid) {
9926: if (ref($usershash->{$user}) eq 'HASH') {
9927: if ($usershash->{$user}->{'id'} ne '') {
9928: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
9929: $userdoms{$udom} = 1;
9930: if (ref($inst_results) eq 'HASH') {
9931: $inst_results->{$uname.':'.$udom} = {};
9932: }
9933: }
9934: }
9935: } else {
9936: $by_username{$udom}{$uname} = 1;
9937: $userdoms{$udom} = 1;
9938: if (ref($inst_results) eq 'HASH') {
9939: $inst_results->{$uname.':'.$udom} = {};
9940: }
9941: }
9942: }
9943: foreach my $udom (keys(%userdoms)) {
9944: if (!$got_rules->{$udom}) {
9945: my %domconfig = &Apache::lonnet::get_dom('configuration',
9946: ['usercreation'],$udom);
9947: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9948: foreach my $item ('username','id') {
9949: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9950: $$curr_rules{$udom}{$item} =
9951: $domconfig{'usercreation'}{$item.'_rule'};
9952: }
9953: }
9954: }
9955: $got_rules->{$udom} = 1;
9956: }
9957: }
9958: if ($checkid) {
9959: foreach my $udom (keys(%by_id)) {
9960: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
9961: if ($outcome eq 'ok') {
9962: foreach my $id (keys(%{$by_id{$udom}})) {
9963: my $uname = $by_id{$udom}{$id};
9964: $inst_response{$uname.':'.$udom} = $outcome;
9965: }
9966: if (ref($results) eq 'HASH') {
9967: foreach my $uname (keys(%{$results})) {
9968: if (exists($inst_response{$uname.':'.$udom})) {
9969: $inst_response{$uname.':'.$udom} = $outcome;
9970: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9971: }
9972: }
9973: }
9974: }
1.612 raeburn 9975: }
1.615 raeburn 9976: } else {
1.1075.2.99 raeburn 9977: foreach my $udom (keys(%by_username)) {
9978: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
9979: if ($outcome eq 'ok') {
9980: foreach my $uname (keys(%{$by_username{$udom}})) {
9981: $inst_response{$uname.':'.$udom} = $outcome;
9982: }
9983: if (ref($results) eq 'HASH') {
9984: foreach my $uname (keys(%{$results})) {
9985: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9986: }
9987: }
9988: }
9989: }
1.612 raeburn 9990: }
1.1075.2.99 raeburn 9991: } elsif (keys(%{$usershash}) == 1) {
9992: my $user = (keys(%{$usershash}))[0];
9993: my ($uname,$udom) = split(/:/,$user);
9994: if (($udom ne '') && ($uname ne '')) {
9995: if (ref($usershash->{$user}) eq 'HASH') {
9996: if (ref($checks) eq 'HASH') {
9997: if (defined($checks->{'username'})) {
9998: ($inst_response{$user},%{$inst_results->{$user}}) =
9999: &Apache::lonnet::get_instuser($udom,$uname);
10000: } elsif (defined($checks->{'id'})) {
10001: if ($usershash->{$user}->{'id'} ne '') {
10002: ($inst_response{$user},%{$inst_results->{$user}}) =
10003: &Apache::lonnet::get_instuser($udom,undef,
10004: $usershash->{$user}->{'id'});
10005: } else {
10006: ($inst_response{$user},%{$inst_results->{$user}}) =
10007: &Apache::lonnet::get_instuser($udom,$uname);
10008: }
10009: }
10010: } else {
10011: ($inst_response{$user},%{$inst_results->{$user}}) =
10012: &Apache::lonnet::get_instuser($udom,$uname);
10013: return;
10014: }
10015: if (!$got_rules->{$udom}) {
10016: my %domconfig = &Apache::lonnet::get_dom('configuration',
10017: ['usercreation'],$udom);
10018: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10019: foreach my $item ('username','id') {
10020: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10021: $$curr_rules{$udom}{$item} =
10022: $domconfig{'usercreation'}{$item.'_rule'};
10023: }
10024: }
1.585 raeburn 10025: }
1.1075.2.99 raeburn 10026: $got_rules->{$udom} = 1;
1.585 raeburn 10027: }
10028: }
1.1075.2.99 raeburn 10029: } else {
10030: return;
10031: }
10032: } else {
10033: return;
10034: }
10035: foreach my $user (keys(%{$usershash})) {
10036: my ($uname,$udom) = split(/:/,$user);
10037: next if (($udom eq '') || ($uname eq ''));
10038: my $id;
10039: if (ref($inst_results) eq 'HASH') {
10040: if (ref($inst_results->{$user}) eq 'HASH') {
10041: $id = $inst_results->{$user}->{'id'};
10042: }
10043: }
10044: if ($id eq '') {
10045: if (ref($usershash->{$user})) {
10046: $id = $usershash->{$user}->{'id'};
10047: }
1.585 raeburn 10048: }
1.612 raeburn 10049: foreach my $item (keys(%{$checks})) {
10050: if (ref($$curr_rules{$udom}) eq 'HASH') {
10051: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10052: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10053: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10054: $$curr_rules{$udom}{$item});
1.612 raeburn 10055: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10056: if ($rule_check{$rule}) {
10057: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10058: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10059: if (ref($inst_results) eq 'HASH') {
10060: if (ref($inst_results->{$user}) eq 'HASH') {
10061: if (keys(%{$inst_results->{$user}}) == 0) {
10062: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10063: } elsif ($item eq 'id') {
10064: if ($inst_results->{$user}->{'id'} eq '') {
10065: $$alerts{$item}{$udom}{$uname} = 1;
10066: }
1.615 raeburn 10067: }
1.612 raeburn 10068: }
10069: }
1.615 raeburn 10070: }
10071: last;
1.585 raeburn 10072: }
10073: }
10074: }
10075: }
10076: }
10077: }
10078: }
10079: }
1.612 raeburn 10080: return;
10081: }
10082:
10083: sub user_rule_formats {
10084: my ($domain,$domdesc,$curr_rules,$check) = @_;
10085: my %text = (
10086: 'username' => 'Usernames',
10087: 'id' => 'IDs',
10088: );
10089: my $output;
10090: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10091: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10092: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10093: $output = '<br />'.
10094: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10095: '<span class="LC_cusr_emph">','</span>',$domdesc).
10096: ' <ul>';
1.612 raeburn 10097: foreach my $rule (@{$ruleorder}) {
10098: if (ref($curr_rules) eq 'ARRAY') {
10099: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10100: if (ref($rules->{$rule}) eq 'HASH') {
10101: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10102: $rules->{$rule}{'desc'}.'</li>';
10103: }
10104: }
10105: }
10106: }
10107: $output .= '</ul>';
10108: }
10109: }
10110: return $output;
10111: }
10112:
10113: sub instrule_disallow_msg {
1.615 raeburn 10114: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10115: my $response;
10116: my %text = (
10117: item => 'username',
10118: items => 'usernames',
10119: match => 'matches',
10120: do => 'does',
10121: action => 'a username',
10122: one => 'one',
10123: );
10124: if ($count > 1) {
10125: $text{'item'} = 'usernames';
10126: $text{'match'} ='match';
10127: $text{'do'} = 'do';
10128: $text{'action'} = 'usernames',
10129: $text{'one'} = 'ones';
10130: }
10131: if ($checkitem eq 'id') {
10132: $text{'items'} = 'IDs';
10133: $text{'item'} = 'ID';
10134: $text{'action'} = 'an ID';
1.615 raeburn 10135: if ($count > 1) {
10136: $text{'item'} = 'IDs';
10137: $text{'action'} = 'IDs';
10138: }
1.612 raeburn 10139: }
1.674 bisitz 10140: $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 10141: if ($mode eq 'upload') {
10142: if ($checkitem eq 'username') {
10143: $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'}.");
10144: } elsif ($checkitem eq 'id') {
1.674 bisitz 10145: $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 10146: }
1.669 raeburn 10147: } elsif ($mode eq 'selfcreate') {
10148: if ($checkitem eq 'id') {
10149: $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.");
10150: }
1.615 raeburn 10151: } else {
10152: if ($checkitem eq 'username') {
10153: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10154: } elsif ($checkitem eq 'id') {
10155: $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.");
10156: }
1.612 raeburn 10157: }
10158: return $response;
1.585 raeburn 10159: }
10160:
1.624 raeburn 10161: sub personal_data_fieldtitles {
10162: my %fieldtitles = &Apache::lonlocal::texthash (
10163: id => 'Student/Employee ID',
10164: permanentemail => 'E-mail address',
10165: lastname => 'Last Name',
10166: firstname => 'First Name',
10167: middlename => 'Middle Name',
10168: generation => 'Generation',
10169: gen => 'Generation',
1.765 raeburn 10170: inststatus => 'Affiliation',
1.624 raeburn 10171: );
10172: return %fieldtitles;
10173: }
10174:
1.642 raeburn 10175: sub sorted_inst_types {
10176: my ($dom) = @_;
1.1075.2.70 raeburn 10177: my ($usertypes,$order);
10178: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10179: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10180: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10181: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10182: } else {
10183: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10184: }
1.642 raeburn 10185: my $othertitle = &mt('All users');
10186: if ($env{'request.course.id'}) {
1.668 raeburn 10187: $othertitle = &mt('Any users');
1.642 raeburn 10188: }
10189: my @types;
10190: if (ref($order) eq 'ARRAY') {
10191: @types = @{$order};
10192: }
10193: if (@types == 0) {
10194: if (ref($usertypes) eq 'HASH') {
10195: @types = sort(keys(%{$usertypes}));
10196: }
10197: }
10198: if (keys(%{$usertypes}) > 0) {
10199: $othertitle = &mt('Other users');
10200: }
10201: return ($othertitle,$usertypes,\@types);
10202: }
10203:
1.645 raeburn 10204: sub get_institutional_codes {
10205: my ($settings,$allcourses,$LC_code) = @_;
10206: # Get complete list of course sections to update
10207: my @currsections = ();
10208: my @currxlists = ();
10209: my $coursecode = $$settings{'internal.coursecode'};
10210:
10211: if ($$settings{'internal.sectionnums'} ne '') {
10212: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10213: }
10214:
10215: if ($$settings{'internal.crosslistings'} ne '') {
10216: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10217: }
10218:
10219: if (@currxlists > 0) {
10220: foreach (@currxlists) {
10221: if (m/^([^:]+):(\w*)$/) {
10222: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10223: push(@{$allcourses},$1);
1.645 raeburn 10224: $$LC_code{$1} = $2;
10225: }
10226: }
10227: }
10228: }
10229:
10230: if (@currsections > 0) {
10231: foreach (@currsections) {
10232: if (m/^(\w+):(\w*)$/) {
10233: my $sec = $coursecode.$1;
10234: my $lc_sec = $2;
10235: unless (grep/^$sec$/,@{$allcourses}) {
1.1075.2.119 raeburn 10236: push(@{$allcourses},$sec);
1.645 raeburn 10237: $$LC_code{$sec} = $lc_sec;
10238: }
10239: }
10240: }
10241: }
10242: return;
10243: }
10244:
1.971 raeburn 10245: sub get_standard_codeitems {
10246: return ('Year','Semester','Department','Number','Section');
10247: }
10248:
1.112 bowersj2 10249: =pod
10250:
1.780 raeburn 10251: =head1 Slot Helpers
10252:
10253: =over 4
10254:
10255: =item * sorted_slots()
10256:
1.1040 raeburn 10257: Sorts an array of slot names in order of an optional sort key,
10258: default sort is by slot start time (earliest first).
1.780 raeburn 10259:
10260: Inputs:
10261:
10262: =over 4
10263:
10264: slotsarr - Reference to array of unsorted slot names.
10265:
10266: slots - Reference to hash of hash, where outer hash keys are slot names.
10267:
1.1040 raeburn 10268: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10269:
1.549 albertel 10270: =back
10271:
1.780 raeburn 10272: Returns:
10273:
10274: =over 4
10275:
1.1040 raeburn 10276: sorted - An array of slot names sorted by a specified sort key
10277: (default sort key is start time of the slot).
1.780 raeburn 10278:
10279: =back
10280:
10281: =cut
10282:
10283:
10284: sub sorted_slots {
1.1040 raeburn 10285: my ($slotsarr,$slots,$sortkey) = @_;
10286: if ($sortkey eq '') {
10287: $sortkey = 'starttime';
10288: }
1.780 raeburn 10289: my @sorted;
10290: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10291: @sorted =
10292: sort {
10293: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10294: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10295: }
10296: if (ref($slots->{$a})) { return -1;}
10297: if (ref($slots->{$b})) { return 1;}
10298: return 0;
10299: } @{$slotsarr};
10300: }
10301: return @sorted;
10302: }
10303:
1.1040 raeburn 10304: =pod
10305:
10306: =item * get_future_slots()
10307:
10308: Inputs:
10309:
10310: =over 4
10311:
10312: cnum - course number
10313:
10314: cdom - course domain
10315:
10316: now - current UNIX time
10317:
10318: symb - optional symb
10319:
10320: =back
10321:
10322: Returns:
10323:
10324: =over 4
10325:
10326: sorted_reservable - ref to array of student_schedulable slots currently
10327: reservable, ordered by end date of reservation period.
10328:
10329: reservable_now - ref to hash of student_schedulable slots currently
10330: reservable.
10331:
10332: Keys in inner hash are:
10333: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10334: (b) endreserve: end date of reservation period.
10335: (c) uniqueperiod: start,end dates when slot is to be uniquely
10336: selected.
1.1040 raeburn 10337:
10338: sorted_future - ref to array of student_schedulable slots reservable in
10339: the future, ordered by start date of reservation period.
10340:
10341: future_reservable - ref to hash of student_schedulable slots reservable
10342: in the future.
10343:
10344: Keys in inner hash are:
10345: (a) symb: either blank or symb to which slot use is restricted.
10346: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10347: (c) uniqueperiod: start,end dates when slot is to be uniquely
10348: selected.
1.1040 raeburn 10349:
10350: =back
10351:
10352: =cut
10353:
10354: sub get_future_slots {
10355: my ($cnum,$cdom,$now,$symb) = @_;
10356: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10357: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10358: foreach my $slot (keys(%slots)) {
10359: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10360: if ($symb) {
10361: next if (($slots{$slot}->{'symb'} ne '') &&
10362: ($slots{$slot}->{'symb'} ne $symb));
10363: }
10364: if (($slots{$slot}->{'starttime'} > $now) &&
10365: ($slots{$slot}->{'endtime'} > $now)) {
10366: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10367: my $userallowed = 0;
10368: if ($slots{$slot}->{'allowedsections'}) {
10369: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10370: if (!defined($env{'request.role.sec'})
10371: && grep(/^No section assigned$/,@allowed_sec)) {
10372: $userallowed=1;
10373: } else {
10374: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10375: $userallowed=1;
10376: }
10377: }
10378: unless ($userallowed) {
10379: if (defined($env{'request.course.groups'})) {
10380: my @groups = split(/:/,$env{'request.course.groups'});
10381: foreach my $group (@groups) {
10382: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10383: $userallowed=1;
10384: last;
10385: }
10386: }
10387: }
10388: }
10389: }
10390: if ($slots{$slot}->{'allowedusers'}) {
10391: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10392: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10393: if (grep(/^\Q$user\E$/,@allowed_users)) {
10394: $userallowed = 1;
10395: }
10396: }
10397: next unless($userallowed);
10398: }
10399: my $startreserve = $slots{$slot}->{'startreserve'};
10400: my $endreserve = $slots{$slot}->{'endreserve'};
10401: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10402: my $uniqueperiod;
10403: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10404: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10405: }
1.1040 raeburn 10406: if (($startreserve < $now) &&
10407: (!$endreserve || $endreserve > $now)) {
10408: my $lastres = $endreserve;
10409: if (!$lastres) {
10410: $lastres = $slots{$slot}->{'starttime'};
10411: }
10412: $reservable_now{$slot} = {
10413: symb => $symb,
1.1075.2.104 raeburn 10414: endreserve => $lastres,
10415: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10416: };
10417: } elsif (($startreserve > $now) &&
10418: (!$endreserve || $endreserve > $startreserve)) {
10419: $future_reservable{$slot} = {
10420: symb => $symb,
1.1075.2.104 raeburn 10421: startreserve => $startreserve,
10422: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10423: };
10424: }
10425: }
10426: }
10427: my @unsorted_reservable = keys(%reservable_now);
10428: if (@unsorted_reservable > 0) {
10429: @sorted_reservable =
10430: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10431: }
10432: my @unsorted_future = keys(%future_reservable);
10433: if (@unsorted_future > 0) {
10434: @sorted_future =
10435: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10436: }
10437: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10438: }
1.780 raeburn 10439:
10440: =pod
10441:
1.1057 foxr 10442: =back
10443:
1.549 albertel 10444: =head1 HTTP Helpers
10445:
10446: =over 4
10447:
1.648 raeburn 10448: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10449:
1.258 albertel 10450: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10451: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10452: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10453:
10454: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10455: $possible_names is an ref to an array of form element names. As an example:
10456: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10457: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10458:
10459: =cut
1.1 albertel 10460:
1.6 albertel 10461: sub get_unprocessed_cgi {
1.25 albertel 10462: my ($query,$possible_names)= @_;
1.26 matthew 10463: # $Apache::lonxml::debug=1;
1.356 albertel 10464: foreach my $pair (split(/&/,$query)) {
10465: my ($name, $value) = split(/=/,$pair);
1.369 www 10466: $name = &unescape($name);
1.25 albertel 10467: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10468: $value =~ tr/+/ /;
10469: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10470: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10471: }
1.16 harris41 10472: }
1.6 albertel 10473: }
10474:
1.112 bowersj2 10475: =pod
10476:
1.648 raeburn 10477: =item * &cacheheader()
1.112 bowersj2 10478:
10479: returns cache-controlling header code
10480:
10481: =cut
10482:
1.7 albertel 10483: sub cacheheader {
1.258 albertel 10484: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10485: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10486: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10487: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10488: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10489: return $output;
1.7 albertel 10490: }
10491:
1.112 bowersj2 10492: =pod
10493:
1.648 raeburn 10494: =item * &no_cache($r)
1.112 bowersj2 10495:
10496: specifies header code to not have cache
10497:
10498: =cut
10499:
1.9 albertel 10500: sub no_cache {
1.216 albertel 10501: my ($r) = @_;
10502: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10503: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10504: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10505: $r->no_cache(1);
10506: $r->header_out("Expires" => $date);
10507: $r->header_out("Pragma" => "no-cache");
1.123 www 10508: }
10509:
10510: sub content_type {
1.181 albertel 10511: my ($r,$type,$charset) = @_;
1.299 foxr 10512: if ($r) {
10513: # Note that printout.pl calls this with undef for $r.
10514: &no_cache($r);
10515: }
1.258 albertel 10516: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10517: unless ($charset) {
10518: $charset=&Apache::lonlocal::current_encoding;
10519: }
10520: if ($charset) { $type.='; charset='.$charset; }
10521: if ($r) {
10522: $r->content_type($type);
10523: } else {
10524: print("Content-type: $type\n\n");
10525: }
1.9 albertel 10526: }
1.25 albertel 10527:
1.112 bowersj2 10528: =pod
10529:
1.648 raeburn 10530: =item * &add_to_env($name,$value)
1.112 bowersj2 10531:
1.258 albertel 10532: adds $name to the %env hash with value
1.112 bowersj2 10533: $value, if $name already exists, the entry is converted to an array
10534: reference and $value is added to the array.
10535:
10536: =cut
10537:
1.25 albertel 10538: sub add_to_env {
10539: my ($name,$value)=@_;
1.258 albertel 10540: if (defined($env{$name})) {
10541: if (ref($env{$name})) {
1.25 albertel 10542: #already have multiple values
1.258 albertel 10543: push(@{ $env{$name} },$value);
1.25 albertel 10544: } else {
10545: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10546: my $first=$env{$name};
10547: undef($env{$name});
10548: push(@{ $env{$name} },$first,$value);
1.25 albertel 10549: }
10550: } else {
1.258 albertel 10551: $env{$name}=$value;
1.25 albertel 10552: }
1.31 albertel 10553: }
1.149 albertel 10554:
10555: =pod
10556:
1.648 raeburn 10557: =item * &get_env_multiple($name)
1.149 albertel 10558:
1.258 albertel 10559: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10560: values may be defined and end up as an array ref.
10561:
10562: returns an array of values
10563:
10564: =cut
10565:
10566: sub get_env_multiple {
10567: my ($name) = @_;
10568: my @values;
1.258 albertel 10569: if (defined($env{$name})) {
1.149 albertel 10570: # exists is it an array
1.258 albertel 10571: if (ref($env{$name})) {
10572: @values=@{ $env{$name} };
1.149 albertel 10573: } else {
1.258 albertel 10574: $values[0]=$env{$name};
1.149 albertel 10575: }
10576: }
10577: return(@values);
10578: }
10579:
1.660 raeburn 10580: sub ask_for_embedded_content {
10581: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10582: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10583: %currsubfile,%unused,$rem);
1.1071 raeburn 10584: my $counter = 0;
10585: my $numnew = 0;
1.987 raeburn 10586: my $numremref = 0;
10587: my $numinvalid = 0;
10588: my $numpathchg = 0;
10589: my $numexisting = 0;
1.1071 raeburn 10590: my $numunused = 0;
10591: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10592: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10593: my $heading = &mt('Upload embedded files');
10594: my $buttontext = &mt('Upload');
10595:
1.1075.2.11 raeburn 10596: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10597: if ($actionurl eq '/adm/dependencies') {
10598: $navmap = Apache::lonnavmaps::navmap->new();
10599: }
10600: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10601: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10602: }
1.1075.2.35 raeburn 10603: if (($actionurl eq '/adm/portfolio') ||
10604: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10605: my $current_path='/';
10606: if ($env{'form.currentpath'}) {
10607: $current_path = $env{'form.currentpath'};
10608: }
10609: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10610: $udom = $cdom;
10611: $uname = $cnum;
1.984 raeburn 10612: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10613: } else {
10614: $udom = $env{'user.domain'};
10615: $uname = $env{'user.name'};
10616: $url = '/userfiles/portfolio';
10617: }
1.987 raeburn 10618: $toplevel = $url.'/';
1.984 raeburn 10619: $url .= $current_path;
10620: $getpropath = 1;
1.987 raeburn 10621: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10622: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10623: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10624: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10625: $toplevel = $url;
1.984 raeburn 10626: if ($rest ne '') {
1.987 raeburn 10627: $url .= $rest;
10628: }
10629: } elsif ($actionurl eq '/adm/coursedocs') {
10630: if (ref($args) eq 'HASH') {
1.1071 raeburn 10631: $url = $args->{'docs_url'};
10632: $toplevel = $url;
1.1075.2.11 raeburn 10633: if ($args->{'context'} eq 'paste') {
10634: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10635: ($path) =
10636: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10637: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10638: $fileloc =~ s{^/}{};
10639: }
1.1071 raeburn 10640: }
10641: } elsif ($actionurl eq '/adm/dependencies') {
10642: if ($env{'request.course.id'} ne '') {
10643: if (ref($args) eq 'HASH') {
10644: $url = $args->{'docs_url'};
10645: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10646: $toplevel = $url;
10647: unless ($toplevel =~ m{^/}) {
10648: $toplevel = "/$url";
10649: }
1.1075.2.11 raeburn 10650: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10651: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10652: $path = $1;
10653: } else {
10654: ($path) =
10655: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10656: }
1.1075.2.79 raeburn 10657: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10658: $fileloc = $toplevel;
10659: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10660: my ($udom,$uname,$fname) =
10661: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10662: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10663: } else {
10664: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10665: }
1.1071 raeburn 10666: $fileloc =~ s{^/}{};
10667: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10668: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10669: }
1.987 raeburn 10670: }
1.1075.2.35 raeburn 10671: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10672: $udom = $cdom;
10673: $uname = $cnum;
10674: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10675: $toplevel = $url;
10676: $path = $url;
10677: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10678: $fileloc =~ s{^/}{};
10679: }
10680: foreach my $file (keys(%{$allfiles})) {
10681: my $embed_file;
10682: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10683: $embed_file = $1;
10684: } else {
10685: $embed_file = $file;
10686: }
1.1075.2.55 raeburn 10687: my ($absolutepath,$cleaned_file);
10688: if ($embed_file =~ m{^\w+://}) {
10689: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10690: $newfiles{$cleaned_file} = 1;
10691: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10692: } else {
1.1075.2.55 raeburn 10693: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10694: if ($embed_file =~ m{^/}) {
10695: $absolutepath = $embed_file;
10696: }
1.1075.2.47 raeburn 10697: if ($cleaned_file =~ m{/}) {
10698: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10699: $path = &check_for_traversal($path,$url,$toplevel);
10700: my $item = $fname;
10701: if ($path ne '') {
10702: $item = $path.'/'.$fname;
10703: $subdependencies{$path}{$fname} = 1;
10704: } else {
10705: $dependencies{$item} = 1;
10706: }
10707: if ($absolutepath) {
10708: $mapping{$item} = $absolutepath;
10709: } else {
10710: $mapping{$item} = $embed_file;
10711: }
10712: } else {
10713: $dependencies{$embed_file} = 1;
10714: if ($absolutepath) {
1.1075.2.47 raeburn 10715: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10716: } else {
1.1075.2.47 raeburn 10717: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10718: }
10719: }
1.984 raeburn 10720: }
10721: }
1.1071 raeburn 10722: my $dirptr = 16384;
1.984 raeburn 10723: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10724: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10725: if (($actionurl eq '/adm/portfolio') ||
10726: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10727: my ($sublistref,$listerror) =
10728: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10729: if (ref($sublistref) eq 'ARRAY') {
10730: foreach my $line (@{$sublistref}) {
10731: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10732: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10733: }
1.984 raeburn 10734: }
1.987 raeburn 10735: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10736: if (opendir(my $dir,$url.'/'.$path)) {
10737: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10738: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10739: }
1.1075.2.11 raeburn 10740: } elsif (($actionurl eq '/adm/dependencies') ||
10741: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10742: ($args->{'context'} eq 'paste')) ||
10743: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10744: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10745: my $dir;
10746: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10747: $dir = $fileloc;
10748: } else {
10749: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10750: }
1.1071 raeburn 10751: if ($dir ne '') {
10752: my ($sublistref,$listerror) =
10753: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10754: if (ref($sublistref) eq 'ARRAY') {
10755: foreach my $line (@{$sublistref}) {
10756: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10757: undef,$mtime)=split(/\&/,$line,12);
10758: unless (($testdir&$dirptr) ||
10759: ($file_name =~ /^\.\.?$/)) {
10760: $currsubfile{$path}{$file_name} = [$size,$mtime];
10761: }
10762: }
10763: }
10764: }
1.984 raeburn 10765: }
10766: }
10767: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10768: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10769: my $item = $path.'/'.$file;
10770: unless ($mapping{$item} eq $item) {
10771: $pathchanges{$item} = 1;
10772: }
10773: $existing{$item} = 1;
10774: $numexisting ++;
10775: } else {
10776: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10777: }
10778: }
1.1071 raeburn 10779: if ($actionurl eq '/adm/dependencies') {
10780: foreach my $path (keys(%currsubfile)) {
10781: if (ref($currsubfile{$path}) eq 'HASH') {
10782: foreach my $file (keys(%{$currsubfile{$path}})) {
10783: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10784: next if (($rem ne '') &&
10785: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10786: (ref($navmap) &&
10787: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10788: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10789: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10790: $unused{$path.'/'.$file} = 1;
10791: }
10792: }
10793: }
10794: }
10795: }
1.984 raeburn 10796: }
1.987 raeburn 10797: my %currfile;
1.1075.2.35 raeburn 10798: if (($actionurl eq '/adm/portfolio') ||
10799: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10800: my ($dirlistref,$listerror) =
10801: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10802: if (ref($dirlistref) eq 'ARRAY') {
10803: foreach my $line (@{$dirlistref}) {
10804: my ($file_name,$rest) = split(/\&/,$line,2);
10805: $currfile{$file_name} = 1;
10806: }
1.984 raeburn 10807: }
1.987 raeburn 10808: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10809: if (opendir(my $dir,$url)) {
1.987 raeburn 10810: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10811: map {$currfile{$_} = 1;} @dir_list;
10812: }
1.1075.2.11 raeburn 10813: } elsif (($actionurl eq '/adm/dependencies') ||
10814: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10815: ($args->{'context'} eq 'paste')) ||
10816: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10817: if ($env{'request.course.id'} ne '') {
10818: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10819: if ($dir ne '') {
10820: my ($dirlistref,$listerror) =
10821: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10822: if (ref($dirlistref) eq 'ARRAY') {
10823: foreach my $line (@{$dirlistref}) {
10824: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10825: $size,undef,$mtime)=split(/\&/,$line,12);
10826: unless (($testdir&$dirptr) ||
10827: ($file_name =~ /^\.\.?$/)) {
10828: $currfile{$file_name} = [$size,$mtime];
10829: }
10830: }
10831: }
10832: }
10833: }
1.984 raeburn 10834: }
10835: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10836: if (exists($currfile{$file})) {
1.987 raeburn 10837: unless ($mapping{$file} eq $file) {
10838: $pathchanges{$file} = 1;
10839: }
10840: $existing{$file} = 1;
10841: $numexisting ++;
10842: } else {
1.984 raeburn 10843: $newfiles{$file} = 1;
10844: }
10845: }
1.1071 raeburn 10846: foreach my $file (keys(%currfile)) {
10847: unless (($file eq $filename) ||
10848: ($file eq $filename.'.bak') ||
10849: ($dependencies{$file})) {
1.1075.2.11 raeburn 10850: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10851: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10852: next if (($rem ne '') &&
10853: (($env{"httpref.$rem".$file} ne '') ||
10854: (ref($navmap) &&
10855: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10856: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10857: ($navmap->getResourceByUrl($rem.$1)))))));
10858: }
1.1075.2.11 raeburn 10859: }
1.1071 raeburn 10860: $unused{$file} = 1;
10861: }
10862: }
1.1075.2.11 raeburn 10863: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10864: ($args->{'context'} eq 'paste')) {
10865: $counter = scalar(keys(%existing));
10866: $numpathchg = scalar(keys(%pathchanges));
10867: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10868: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10869: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10870: $counter = scalar(keys(%existing));
10871: $numpathchg = scalar(keys(%pathchanges));
10872: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10873: }
1.984 raeburn 10874: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10875: if ($actionurl eq '/adm/dependencies') {
10876: next if ($embed_file =~ m{^\w+://});
10877: }
1.660 raeburn 10878: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10879: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10880: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10881: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10882: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10883: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10884: }
1.1075.2.35 raeburn 10885: $upload_output .= '</td>';
1.1071 raeburn 10886: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10887: $upload_output.='<td align="right">'.
10888: '<span class="LC_info LC_fontsize_medium">'.
10889: &mt("URL points to web address").'</span>';
1.987 raeburn 10890: $numremref++;
1.660 raeburn 10891: } elsif ($args->{'error_on_invalid_names'}
10892: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10893: $upload_output.='<td align="right"><span class="LC_warning">'.
10894: &mt('Invalid characters').'</span>';
1.987 raeburn 10895: $numinvalid++;
1.660 raeburn 10896: } else {
1.1075.2.35 raeburn 10897: $upload_output .= '<td>'.
10898: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10899: $embed_file,\%mapping,
1.1071 raeburn 10900: $allfiles,$codebase,'upload');
10901: $counter ++;
10902: $numnew ++;
1.987 raeburn 10903: }
10904: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10905: }
10906: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10907: if ($actionurl eq '/adm/dependencies') {
10908: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10909: $modify_output .= &start_data_table_row().
10910: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10911: '<img src="'.&icon($embed_file).'" border="0" />'.
10912: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10913: '<td>'.$size.'</td>'.
10914: '<td>'.$mtime.'</td>'.
10915: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10916: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10917: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10918: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10919: &embedded_file_element('upload_embedded',$counter,
10920: $embed_file,\%mapping,
10921: $allfiles,$codebase,'modify').
10922: '</div></td>'.
10923: &end_data_table_row()."\n";
10924: $counter ++;
10925: } else {
10926: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10927: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10928: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10929: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10930: &Apache::loncommon::end_data_table_row()."\n";
10931: }
10932: }
10933: my $delidx = $counter;
10934: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10935: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10936: $delete_output .= &start_data_table_row().
10937: '<td><img src="'.&icon($oldfile).'" />'.
10938: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10939: '<td>'.$size.'</td>'.
10940: '<td>'.$mtime.'</td>'.
10941: '<td><label><input type="checkbox" name="del_upload_dep" '.
10942: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10943: &embedded_file_element('upload_embedded',$delidx,
10944: $oldfile,\%mapping,$allfiles,
10945: $codebase,'delete').'</td>'.
10946: &end_data_table_row()."\n";
10947: $numunused ++;
10948: $delidx ++;
1.987 raeburn 10949: }
10950: if ($upload_output) {
10951: $upload_output = &start_data_table().
10952: $upload_output.
10953: &end_data_table()."\n";
10954: }
1.1071 raeburn 10955: if ($modify_output) {
10956: $modify_output = &start_data_table().
10957: &start_data_table_header_row().
10958: '<th>'.&mt('File').'</th>'.
10959: '<th>'.&mt('Size (KB)').'</th>'.
10960: '<th>'.&mt('Modified').'</th>'.
10961: '<th>'.&mt('Upload replacement?').'</th>'.
10962: &end_data_table_header_row().
10963: $modify_output.
10964: &end_data_table()."\n";
10965: }
10966: if ($delete_output) {
10967: $delete_output = &start_data_table().
10968: &start_data_table_header_row().
10969: '<th>'.&mt('File').'</th>'.
10970: '<th>'.&mt('Size (KB)').'</th>'.
10971: '<th>'.&mt('Modified').'</th>'.
10972: '<th>'.&mt('Delete?').'</th>'.
10973: &end_data_table_header_row().
10974: $delete_output.
10975: &end_data_table()."\n";
10976: }
1.987 raeburn 10977: my $applies = 0;
10978: if ($numremref) {
10979: $applies ++;
10980: }
10981: if ($numinvalid) {
10982: $applies ++;
10983: }
10984: if ($numexisting) {
10985: $applies ++;
10986: }
1.1071 raeburn 10987: if ($counter || $numunused) {
1.987 raeburn 10988: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10989: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10990: $state.'<h3>'.$heading.'</h3>';
10991: if ($actionurl eq '/adm/dependencies') {
10992: if ($numnew) {
10993: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10994: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10995: $upload_output.'<br />'."\n";
10996: }
10997: if ($numexisting) {
10998: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10999: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11000: $modify_output.'<br />'."\n";
11001: $buttontext = &mt('Save changes');
11002: }
11003: if ($numunused) {
11004: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11005: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11006: $delete_output.'<br />'."\n";
11007: $buttontext = &mt('Save changes');
11008: }
11009: } else {
11010: $output .= $upload_output.'<br />'."\n";
11011: }
11012: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11013: $counter.'" />'."\n";
11014: if ($actionurl eq '/adm/dependencies') {
11015: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11016: $numnew.'" />'."\n";
11017: } elsif ($actionurl eq '') {
1.987 raeburn 11018: $output .= '<input type="hidden" name="phase" value="three" />';
11019: }
11020: } elsif ($applies) {
11021: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11022: if ($applies > 1) {
11023: $output .=
1.1075.2.35 raeburn 11024: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11025: if ($numremref) {
11026: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11027: }
11028: if ($numinvalid) {
11029: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11030: }
11031: if ($numexisting) {
11032: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11033: }
11034: $output .= '</ul><br />';
11035: } elsif ($numremref) {
11036: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11037: } elsif ($numinvalid) {
11038: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11039: } elsif ($numexisting) {
11040: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11041: }
11042: $output .= $upload_output.'<br />';
11043: }
11044: my ($pathchange_output,$chgcount);
1.1071 raeburn 11045: $chgcount = $counter;
1.987 raeburn 11046: if (keys(%pathchanges) > 0) {
11047: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11048: if ($counter) {
1.987 raeburn 11049: $output .= &embedded_file_element('pathchange',$chgcount,
11050: $embed_file,\%mapping,
1.1071 raeburn 11051: $allfiles,$codebase,'change');
1.987 raeburn 11052: } else {
11053: $pathchange_output .=
11054: &start_data_table_row().
11055: '<td><input type ="checkbox" name="namechange" value="'.
11056: $chgcount.'" checked="checked" /></td>'.
11057: '<td>'.$mapping{$embed_file}.'</td>'.
11058: '<td>'.$embed_file.
11059: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11060: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11061: '</td>'.&end_data_table_row();
1.660 raeburn 11062: }
1.987 raeburn 11063: $numpathchg ++;
11064: $chgcount ++;
1.660 raeburn 11065: }
11066: }
1.1075.2.35 raeburn 11067: if (($counter) || ($numunused)) {
1.987 raeburn 11068: if ($numpathchg) {
11069: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11070: $numpathchg.'" />'."\n";
11071: }
11072: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11073: ($actionurl eq '/adm/imsimport')) {
11074: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11075: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11076: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11077: } elsif ($actionurl eq '/adm/dependencies') {
11078: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11079: }
1.1075.2.35 raeburn 11080: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11081: } elsif ($numpathchg) {
11082: my %pathchange = ();
11083: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11084: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11085: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11086: }
1.987 raeburn 11087: }
1.1071 raeburn 11088: return ($output,$counter,$numpathchg);
1.987 raeburn 11089: }
11090:
1.1075.2.47 raeburn 11091: =pod
11092:
11093: =item * clean_path($name)
11094:
11095: Performs clean-up of directories, subdirectories and filename in an
11096: embedded object, referenced in an HTML file which is being uploaded
11097: to a course or portfolio, where
11098: "Upload embedded images/multimedia files if HTML file" checkbox was
11099: checked.
11100:
11101: Clean-up is similar to replacements in lonnet::clean_filename()
11102: except each / between sub-directory and next level is preserved.
11103:
11104: =cut
11105:
11106: sub clean_path {
11107: my ($embed_file) = @_;
11108: $embed_file =~s{^/+}{};
11109: my @contents;
11110: if ($embed_file =~ m{/}) {
11111: @contents = split(/\//,$embed_file);
11112: } else {
11113: @contents = ($embed_file);
11114: }
11115: my $lastidx = scalar(@contents)-1;
11116: for (my $i=0; $i<=$lastidx; $i++) {
11117: $contents[$i]=~s{\\}{/}g;
11118: $contents[$i]=~s/\s+/\_/g;
11119: $contents[$i]=~s{[^/\w\.\-]}{}g;
11120: if ($i == $lastidx) {
11121: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11122: }
11123: }
11124: if ($lastidx > 0) {
11125: return join('/',@contents);
11126: } else {
11127: return $contents[0];
11128: }
11129: }
11130:
1.987 raeburn 11131: sub embedded_file_element {
1.1071 raeburn 11132: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11133: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11134: (ref($codebase) eq 'HASH'));
11135: my $output;
1.1071 raeburn 11136: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11137: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11138: }
11139: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11140: &escape($embed_file).'" />';
11141: unless (($context eq 'upload_embedded') &&
11142: ($mapping->{$embed_file} eq $embed_file)) {
11143: $output .='
11144: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11145: }
11146: my $attrib;
11147: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11148: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11149: }
11150: $output .=
11151: "\n\t\t".
11152: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11153: $attrib.'" />';
11154: if (exists($codebase->{$mapping->{$embed_file}})) {
11155: $output .=
11156: "\n\t\t".
11157: '<input name="codebase_'.$num.'" type="hidden" value="'.
11158: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11159: }
1.987 raeburn 11160: return $output;
1.660 raeburn 11161: }
11162:
1.1071 raeburn 11163: sub get_dependency_details {
11164: my ($currfile,$currsubfile,$embed_file) = @_;
11165: my ($size,$mtime,$showsize,$showmtime);
11166: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11167: if ($embed_file =~ m{/}) {
11168: my ($path,$fname) = split(/\//,$embed_file);
11169: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11170: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11171: }
11172: } else {
11173: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11174: ($size,$mtime) = @{$currfile->{$embed_file}};
11175: }
11176: }
11177: $showsize = $size/1024.0;
11178: $showsize = sprintf("%.1f",$showsize);
11179: if ($mtime > 0) {
11180: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11181: }
11182: }
11183: return ($showsize,$showmtime);
11184: }
11185:
11186: sub ask_embedded_js {
11187: return <<"END";
11188: <script type="text/javascript"">
11189: // <![CDATA[
11190: function toggleBrowse(counter) {
11191: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11192: var fileid = document.getElementById('embedded_item_'+counter);
11193: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11194: if (chkboxid.checked == true) {
11195: uploaddivid.style.display='block';
11196: } else {
11197: uploaddivid.style.display='none';
11198: fileid.value = '';
11199: }
11200: }
11201: // ]]>
11202: </script>
11203:
11204: END
11205: }
11206:
1.661 raeburn 11207: sub upload_embedded {
11208: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11209: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11210: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11211: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11212: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11213: my $orig_uploaded_filename =
11214: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11215: foreach my $type ('orig','ref','attrib','codebase') {
11216: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11217: $env{'form.embedded_'.$type.'_'.$i} =
11218: &unescape($env{'form.embedded_'.$type.'_'.$i});
11219: }
11220: }
1.661 raeburn 11221: my ($path,$fname) =
11222: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11223: # no path, whole string is fname
11224: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11225: $fname = &Apache::lonnet::clean_filename($fname);
11226: # See if there is anything left
11227: next if ($fname eq '');
11228:
11229: # Check if file already exists as a file or directory.
11230: my ($state,$msg);
11231: if ($context eq 'portfolio') {
11232: my $port_path = $dirpath;
11233: if ($group ne '') {
11234: $port_path = "groups/$group/$port_path";
11235: }
1.987 raeburn 11236: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11237: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11238: $dir_root,$port_path,$disk_quota,
11239: $current_disk_usage,$uname,$udom);
11240: if ($state eq 'will_exceed_quota'
1.984 raeburn 11241: || $state eq 'file_locked') {
1.661 raeburn 11242: $output .= $msg;
11243: next;
11244: }
11245: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11246: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11247: if ($state eq 'exists') {
11248: $output .= $msg;
11249: next;
11250: }
11251: }
11252: # Check if extension is valid
11253: if (($fname =~ /\.(\w+)$/) &&
11254: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11255: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11256: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11257: next;
11258: } elsif (($fname =~ /\.(\w+)$/) &&
11259: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11260: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11261: next;
11262: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11263: $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 11264: next;
11265: }
11266: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11267: my $subdir = $path;
11268: $subdir =~ s{/+$}{};
1.661 raeburn 11269: if ($context eq 'portfolio') {
1.984 raeburn 11270: my $result;
11271: if ($state eq 'existingfile') {
11272: $result=
11273: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11274: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11275: } else {
1.984 raeburn 11276: $result=
11277: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11278: $dirpath.
1.1075.2.35 raeburn 11279: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11280: if ($result !~ m|^/uploaded/|) {
11281: $output .= '<span class="LC_error">'
11282: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11283: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11284: .'</span><br />';
11285: next;
11286: } else {
1.987 raeburn 11287: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11288: $path.$fname.'</span>').'<br />';
1.984 raeburn 11289: }
1.661 raeburn 11290: }
1.1075.2.35 raeburn 11291: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11292: my $extendedsubdir = $dirpath.'/'.$subdir;
11293: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11294: my $result =
1.1075.2.35 raeburn 11295: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11296: if ($result !~ m|^/uploaded/|) {
11297: $output .= '<span class="LC_error">'
11298: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11299: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11300: .'</span><br />';
11301: next;
11302: } else {
11303: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11304: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11305: if ($context eq 'syllabus') {
11306: &Apache::lonnet::make_public_indefinitely($result);
11307: }
1.987 raeburn 11308: }
1.661 raeburn 11309: } else {
11310: # Save the file
11311: my $target = $env{'form.embedded_item_'.$i};
11312: my $fullpath = $dir_root.$dirpath.'/'.$path;
11313: my $dest = $fullpath.$fname;
11314: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11315: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11316: my $count;
11317: my $filepath = $dir_root;
1.1027 raeburn 11318: foreach my $subdir (@parts) {
11319: $filepath .= "/$subdir";
11320: if (!-e $filepath) {
1.661 raeburn 11321: mkdir($filepath,0770);
11322: }
11323: }
11324: my $fh;
11325: if (!open($fh,'>'.$dest)) {
11326: &Apache::lonnet::logthis('Failed to create '.$dest);
11327: $output .= '<span class="LC_error">'.
1.1071 raeburn 11328: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11329: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11330: '</span><br />';
11331: } else {
11332: if (!print $fh $env{'form.embedded_item_'.$i}) {
11333: &Apache::lonnet::logthis('Failed to write to '.$dest);
11334: $output .= '<span class="LC_error">'.
1.1071 raeburn 11335: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11336: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11337: '</span><br />';
11338: } else {
1.987 raeburn 11339: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11340: $url.'</span>').'<br />';
11341: unless ($context eq 'testbank') {
11342: $footer .= &mt('View embedded file: [_1]',
11343: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11344: }
11345: }
11346: close($fh);
11347: }
11348: }
11349: if ($env{'form.embedded_ref_'.$i}) {
11350: $pathchange{$i} = 1;
11351: }
11352: }
11353: if ($output) {
11354: $output = '<p>'.$output.'</p>';
11355: }
11356: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11357: $returnflag = 'ok';
1.1071 raeburn 11358: my $numpathchgs = scalar(keys(%pathchange));
11359: if ($numpathchgs > 0) {
1.987 raeburn 11360: if ($context eq 'portfolio') {
11361: $output .= '<p>'.&mt('or').'</p>';
11362: } elsif ($context eq 'testbank') {
1.1071 raeburn 11363: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11364: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11365: $returnflag = 'modify_orightml';
11366: }
11367: }
1.1071 raeburn 11368: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11369: }
11370:
11371: sub modify_html_form {
11372: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11373: my $end = 0;
11374: my $modifyform;
11375: if ($context eq 'upload_embedded') {
11376: return unless (ref($pathchange) eq 'HASH');
11377: if ($env{'form.number_embedded_items'}) {
11378: $end += $env{'form.number_embedded_items'};
11379: }
11380: if ($env{'form.number_pathchange_items'}) {
11381: $end += $env{'form.number_pathchange_items'};
11382: }
11383: if ($end) {
11384: for (my $i=0; $i<$end; $i++) {
11385: if ($i < $env{'form.number_embedded_items'}) {
11386: next unless($pathchange->{$i});
11387: }
11388: $modifyform .=
11389: &start_data_table_row().
11390: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11391: 'checked="checked" /></td>'.
11392: '<td>'.$env{'form.embedded_ref_'.$i}.
11393: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11394: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11395: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11396: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11397: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11398: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11399: '<td>'.$env{'form.embedded_orig_'.$i}.
11400: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11401: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11402: &end_data_table_row();
1.1071 raeburn 11403: }
1.987 raeburn 11404: }
11405: } else {
11406: $modifyform = $pathchgtable;
11407: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11408: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11409: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11410: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11411: }
11412: }
11413: if ($modifyform) {
1.1071 raeburn 11414: if ($actionurl eq '/adm/dependencies') {
11415: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11416: }
1.987 raeburn 11417: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11418: '<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".
11419: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11420: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11421: '</ol></p>'."\n".'<p>'.
11422: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11423: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11424: &start_data_table()."\n".
11425: &start_data_table_header_row().
11426: '<th>'.&mt('Change?').'</th>'.
11427: '<th>'.&mt('Current reference').'</th>'.
11428: '<th>'.&mt('Required reference').'</th>'.
11429: &end_data_table_header_row()."\n".
11430: $modifyform.
11431: &end_data_table().'<br />'."\n".$hiddenstate.
11432: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11433: '</form>'."\n";
11434: }
11435: return;
11436: }
11437:
11438: sub modify_html_refs {
1.1075.2.35 raeburn 11439: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11440: my $container;
11441: if ($context eq 'portfolio') {
11442: $container = $env{'form.container'};
11443: } elsif ($context eq 'coursedoc') {
11444: $container = $env{'form.primaryurl'};
1.1071 raeburn 11445: } elsif ($context eq 'manage_dependencies') {
11446: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11447: $container = "/$container";
1.1075.2.35 raeburn 11448: } elsif ($context eq 'syllabus') {
11449: $container = $url;
1.987 raeburn 11450: } else {
1.1027 raeburn 11451: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11452: }
11453: my (%allfiles,%codebase,$output,$content);
11454: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11455: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11456: if (wantarray) {
11457: return ('',0,0);
11458: } else {
11459: return;
11460: }
11461: }
11462: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11463: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11464: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11465: if (wantarray) {
11466: return ('',0,0);
11467: } else {
11468: return;
11469: }
11470: }
1.987 raeburn 11471: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11472: if ($content eq '-1') {
11473: if (wantarray) {
11474: return ('',0,0);
11475: } else {
11476: return;
11477: }
11478: }
1.987 raeburn 11479: } else {
1.1071 raeburn 11480: unless ($container =~ /^\Q$dir_root\E/) {
11481: if (wantarray) {
11482: return ('',0,0);
11483: } else {
11484: return;
11485: }
11486: }
1.1075.2.128 raeburn 11487: if (open(my $fh,'<',$container)) {
1.987 raeburn 11488: $content = join('', <$fh>);
11489: close($fh);
11490: } else {
1.1071 raeburn 11491: if (wantarray) {
11492: return ('',0,0);
11493: } else {
11494: return;
11495: }
1.987 raeburn 11496: }
11497: }
11498: my ($count,$codebasecount) = (0,0);
11499: my $mm = new File::MMagic;
11500: my $mime_type = $mm->checktype_contents($content);
11501: if ($mime_type eq 'text/html') {
11502: my $parse_result =
11503: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11504: \%codebase,\$content);
11505: if ($parse_result eq 'ok') {
11506: foreach my $i (@changes) {
11507: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11508: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11509: if ($allfiles{$ref}) {
11510: my $newname = $orig;
11511: my ($attrib_regexp,$codebase);
1.1006 raeburn 11512: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11513: if ($attrib_regexp =~ /:/) {
11514: $attrib_regexp =~ s/\:/|/g;
11515: }
11516: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11517: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11518: $count += $numchg;
1.1075.2.35 raeburn 11519: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11520: delete($allfiles{$ref});
1.987 raeburn 11521: }
11522: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11523: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11524: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11525: $codebasecount ++;
11526: }
11527: }
11528: }
1.1075.2.35 raeburn 11529: my $skiprewrites;
1.987 raeburn 11530: if ($count || $codebasecount) {
11531: my $saveresult;
1.1071 raeburn 11532: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11533: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11534: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11535: if ($url eq $container) {
11536: my ($fname) = ($container =~ m{/([^/]+)$});
11537: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11538: $count,'<span class="LC_filename">'.
1.1071 raeburn 11539: $fname.'</span>').'</p>';
1.987 raeburn 11540: } else {
11541: $output = '<p class="LC_error">'.
11542: &mt('Error: update failed for: [_1].',
11543: '<span class="LC_filename">'.
11544: $container.'</span>').'</p>';
11545: }
1.1075.2.35 raeburn 11546: if ($context eq 'syllabus') {
11547: unless ($saveresult eq 'ok') {
11548: $skiprewrites = 1;
11549: }
11550: }
1.987 raeburn 11551: } else {
1.1075.2.128 raeburn 11552: if (open(my $fh,'>',$container)) {
1.987 raeburn 11553: print $fh $content;
11554: close($fh);
11555: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11556: $count,'<span class="LC_filename">'.
11557: $container.'</span>').'</p>';
1.661 raeburn 11558: } else {
1.987 raeburn 11559: $output = '<p class="LC_error">'.
11560: &mt('Error: could not update [_1].',
11561: '<span class="LC_filename">'.
11562: $container.'</span>').'</p>';
1.661 raeburn 11563: }
11564: }
11565: }
1.1075.2.35 raeburn 11566: if (($context eq 'syllabus') && (!$skiprewrites)) {
11567: my ($actionurl,$state);
11568: $actionurl = "/public/$udom/$uname/syllabus";
11569: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11570: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11571: \%codebase,
11572: {'context' => 'rewrites',
11573: 'ignore_remote_references' => 1,});
11574: if (ref($mapping) eq 'HASH') {
11575: my $rewrites = 0;
11576: foreach my $key (keys(%{$mapping})) {
11577: next if ($key =~ m{^https?://});
11578: my $ref = $mapping->{$key};
11579: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11580: my $attrib;
11581: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11582: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11583: }
11584: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11585: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11586: $rewrites += $numchg;
11587: }
11588: }
11589: if ($rewrites) {
11590: my $saveresult;
11591: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11592: if ($url eq $container) {
11593: my ($fname) = ($container =~ m{/([^/]+)$});
11594: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11595: $count,'<span class="LC_filename">'.
11596: $fname.'</span>').'</p>';
11597: } else {
11598: $output .= '<p class="LC_error">'.
11599: &mt('Error: could not update links in [_1].',
11600: '<span class="LC_filename">'.
11601: $container.'</span>').'</p>';
11602:
11603: }
11604: }
11605: }
11606: }
1.987 raeburn 11607: } else {
11608: &logthis('Failed to parse '.$container.
11609: ' to modify references: '.$parse_result);
1.661 raeburn 11610: }
11611: }
1.1071 raeburn 11612: if (wantarray) {
11613: return ($output,$count,$codebasecount);
11614: } else {
11615: return $output;
11616: }
1.661 raeburn 11617: }
11618:
11619: sub check_for_existing {
11620: my ($path,$fname,$element) = @_;
11621: my ($state,$msg);
11622: if (-d $path.'/'.$fname) {
11623: $state = 'exists';
11624: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11625: } elsif (-e $path.'/'.$fname) {
11626: $state = 'exists';
11627: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11628: }
11629: if ($state eq 'exists') {
11630: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11631: }
11632: return ($state,$msg);
11633: }
11634:
11635: sub check_for_upload {
11636: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11637: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11638: my $filesize = length($env{'form.'.$element});
11639: if (!$filesize) {
11640: my $msg = '<span class="LC_error">'.
11641: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11642: '<span class="LC_filename">'.$fname.'</span>',
11643: $filesize).'<br />'.
1.1007 raeburn 11644: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11645: '</span>';
11646: return ('zero_bytes',$msg);
11647: }
11648: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11649: my $getpropath = 1;
1.1021 raeburn 11650: my ($dirlistref,$listerror) =
11651: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11652: my $found_file = 0;
11653: my $locked_file = 0;
1.991 raeburn 11654: my @lockers;
11655: my $navmap;
11656: if ($env{'request.course.id'}) {
11657: $navmap = Apache::lonnavmaps::navmap->new();
11658: }
1.1021 raeburn 11659: if (ref($dirlistref) eq 'ARRAY') {
11660: foreach my $line (@{$dirlistref}) {
11661: my ($file_name,$rest)=split(/\&/,$line,2);
11662: if ($file_name eq $fname){
11663: $file_name = $path.$file_name;
11664: if ($group ne '') {
11665: $file_name = $group.$file_name;
11666: }
11667: $found_file = 1;
11668: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11669: foreach my $lock (@lockers) {
11670: if (ref($lock) eq 'ARRAY') {
11671: my ($symb,$crsid) = @{$lock};
11672: if ($crsid eq $env{'request.course.id'}) {
11673: if (ref($navmap)) {
11674: my $res = $navmap->getBySymb($symb);
11675: foreach my $part (@{$res->parts()}) {
11676: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11677: unless (($slot_status == $res->RESERVED) ||
11678: ($slot_status == $res->RESERVED_LOCATION)) {
11679: $locked_file = 1;
11680: }
1.991 raeburn 11681: }
1.1021 raeburn 11682: } else {
11683: $locked_file = 1;
1.991 raeburn 11684: }
11685: } else {
11686: $locked_file = 1;
11687: }
11688: }
1.1021 raeburn 11689: }
11690: } else {
11691: my @info = split(/\&/,$rest);
11692: my $currsize = $info[6]/1000;
11693: if ($currsize < $filesize) {
11694: my $extra = $filesize - $currsize;
11695: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11696: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11697: &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.1075.2.69 raeburn 11698: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11699: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11700: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11701: return ('will_exceed_quota',$msg);
11702: }
1.984 raeburn 11703: }
11704: }
1.661 raeburn 11705: }
11706: }
11707: }
11708: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11709: my $msg = '<p class="LC_warning">'.
11710: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11711: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11712: return ('will_exceed_quota',$msg);
11713: } elsif ($found_file) {
11714: if ($locked_file) {
1.1075.2.69 raeburn 11715: my $msg = '<p class="LC_warning">';
1.661 raeburn 11716: $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.1075.2.69 raeburn 11717: $msg .= '</p>';
1.661 raeburn 11718: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11719: return ('file_locked',$msg);
11720: } else {
1.1075.2.69 raeburn 11721: my $msg = '<p class="LC_error">';
1.984 raeburn 11722: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.1075.2.69 raeburn 11723: $msg .= '</p>';
1.984 raeburn 11724: return ('existingfile',$msg);
1.661 raeburn 11725: }
11726: }
11727: }
11728:
1.987 raeburn 11729: sub check_for_traversal {
11730: my ($path,$url,$toplevel) = @_;
11731: my @parts=split(/\//,$path);
11732: my $cleanpath;
11733: my $fullpath = $url;
11734: for (my $i=0;$i<@parts;$i++) {
11735: next if ($parts[$i] eq '.');
11736: if ($parts[$i] eq '..') {
11737: $fullpath =~ s{([^/]+/)$}{};
11738: } else {
11739: $fullpath .= $parts[$i].'/';
11740: }
11741: }
11742: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11743: $cleanpath = $1;
11744: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11745: my $curr_toprel = $1;
11746: my @parts = split(/\//,$curr_toprel);
11747: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11748: my @urlparts = split(/\//,$url_toprel);
11749: my $doubledots;
11750: my $startdiff = -1;
11751: for (my $i=0; $i<@urlparts; $i++) {
11752: if ($startdiff == -1) {
11753: unless ($urlparts[$i] eq $parts[$i]) {
11754: $startdiff = $i;
11755: $doubledots .= '../';
11756: }
11757: } else {
11758: $doubledots .= '../';
11759: }
11760: }
11761: if ($startdiff > -1) {
11762: $cleanpath = $doubledots;
11763: for (my $i=$startdiff; $i<@parts; $i++) {
11764: $cleanpath .= $parts[$i].'/';
11765: }
11766: }
11767: }
11768: $cleanpath =~ s{(/)$}{};
11769: return $cleanpath;
11770: }
1.31 albertel 11771:
1.1053 raeburn 11772: sub is_archive_file {
11773: my ($mimetype) = @_;
11774: if (($mimetype eq 'application/octet-stream') ||
11775: ($mimetype eq 'application/x-stuffit') ||
11776: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11777: return 1;
11778: }
11779: return;
11780: }
11781:
11782: sub decompress_form {
1.1065 raeburn 11783: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11784: my %lt = &Apache::lonlocal::texthash (
11785: this => 'This file is an archive file.',
1.1067 raeburn 11786: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11787: itsc => 'Its contents are as follows:',
1.1053 raeburn 11788: youm => 'You may wish to extract its contents.',
11789: extr => 'Extract contents',
1.1067 raeburn 11790: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11791: proa => 'Process automatically?',
1.1053 raeburn 11792: yes => 'Yes',
11793: no => 'No',
1.1067 raeburn 11794: fold => 'Title for folder containing movie',
11795: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11796: );
1.1065 raeburn 11797: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11798: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11799: my $info = &list_archive_contents($fileloc,\@paths);
11800: if (@paths) {
11801: foreach my $path (@paths) {
11802: $path =~ s{^/}{};
1.1067 raeburn 11803: if ($path =~ m{^([^/]+)/$}) {
11804: $topdir = $1;
11805: }
1.1065 raeburn 11806: if ($path =~ m{^([^/]+)/}) {
11807: $toplevel{$1} = $path;
11808: } else {
11809: $toplevel{$path} = $path;
11810: }
11811: }
11812: }
1.1067 raeburn 11813: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11814: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11815: "$topdir/media/",
11816: "$topdir/media/$topdir.mp4",
11817: "$topdir/media/FirstFrame.png",
11818: "$topdir/media/player.swf",
11819: "$topdir/media/swfobject.js",
11820: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 11821: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 11822: "$topdir/$topdir.mp4",
11823: "$topdir/$topdir\_config.xml",
11824: "$topdir/$topdir\_controller.swf",
11825: "$topdir/$topdir\_embed.css",
11826: "$topdir/$topdir\_First_Frame.png",
11827: "$topdir/$topdir\_player.html",
11828: "$topdir/$topdir\_Thumbnails.png",
11829: "$topdir/playerProductInstall.swf",
11830: "$topdir/scripts/",
11831: "$topdir/scripts/config_xml.js",
11832: "$topdir/scripts/handlebars.js",
11833: "$topdir/scripts/jquery-1.7.1.min.js",
11834: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11835: "$topdir/scripts/modernizr.js",
11836: "$topdir/scripts/player-min.js",
11837: "$topdir/scripts/swfobject.js",
11838: "$topdir/skins/",
11839: "$topdir/skins/configuration_express.xml",
11840: "$topdir/skins/express_show/",
11841: "$topdir/skins/express_show/player-min.css",
11842: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 11843: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11844: "$topdir/$topdir.mp4",
11845: "$topdir/$topdir\_config.xml",
11846: "$topdir/$topdir\_controller.swf",
11847: "$topdir/$topdir\_embed.css",
11848: "$topdir/$topdir\_First_Frame.png",
11849: "$topdir/$topdir\_player.html",
11850: "$topdir/$topdir\_Thumbnails.png",
11851: "$topdir/playerProductInstall.swf",
11852: "$topdir/scripts/",
11853: "$topdir/scripts/config_xml.js",
11854: "$topdir/scripts/techsmith-smart-player.min.js",
11855: "$topdir/skins/",
11856: "$topdir/skins/configuration_express.xml",
11857: "$topdir/skins/express_show/",
11858: "$topdir/skins/express_show/spritesheet.min.css",
11859: "$topdir/skins/express_show/spritesheet.png",
11860: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 11861: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11862: if (@diffs == 0) {
1.1075.2.59 raeburn 11863: $is_camtasia = 6;
11864: } else {
1.1075.2.81 raeburn 11865: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 11866: if (@diffs == 0) {
11867: $is_camtasia = 8;
1.1075.2.81 raeburn 11868: } else {
11869: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11870: if (@diffs == 0) {
11871: $is_camtasia = 8;
11872: }
1.1075.2.59 raeburn 11873: }
1.1067 raeburn 11874: }
11875: }
11876: my $output;
11877: if ($is_camtasia) {
11878: $output = <<"ENDCAM";
11879: <script type="text/javascript" language="Javascript">
11880: // <![CDATA[
11881:
11882: function camtasiaToggle() {
11883: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11884: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11885: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11886: document.getElementById('camtasia_titles').style.display='block';
11887: } else {
11888: document.getElementById('camtasia_titles').style.display='none';
11889: }
11890: }
11891: }
11892: return;
11893: }
11894:
11895: // ]]>
11896: </script>
11897: <p>$lt{'camt'}</p>
11898: ENDCAM
1.1065 raeburn 11899: } else {
1.1067 raeburn 11900: $output = '<p>'.$lt{'this'};
11901: if ($info eq '') {
11902: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11903: } else {
11904: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11905: '<div><pre>'.$info.'</pre></div>';
11906: }
1.1065 raeburn 11907: }
1.1067 raeburn 11908: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11909: my $duplicates;
11910: my $num = 0;
11911: if (ref($dirlist) eq 'ARRAY') {
11912: foreach my $item (@{$dirlist}) {
11913: if (ref($item) eq 'ARRAY') {
11914: if (exists($toplevel{$item->[0]})) {
11915: $duplicates .=
11916: &start_data_table_row().
11917: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11918: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11919: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11920: 'value="1" />'.&mt('Yes').'</label>'.
11921: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11922: '<td>'.$item->[0].'</td>';
11923: if ($item->[2]) {
11924: $duplicates .= '<td>'.&mt('Directory').'</td>';
11925: } else {
11926: $duplicates .= '<td>'.&mt('File').'</td>';
11927: }
11928: $duplicates .= '<td>'.$item->[3].'</td>'.
11929: '<td>'.
11930: &Apache::lonlocal::locallocaltime($item->[4]).
11931: '</td>'.
11932: &end_data_table_row();
11933: $num ++;
11934: }
11935: }
11936: }
11937: }
11938: my $itemcount;
11939: if (@paths > 0) {
11940: $itemcount = scalar(@paths);
11941: } else {
11942: $itemcount = 1;
11943: }
1.1067 raeburn 11944: if ($is_camtasia) {
11945: $output .= $lt{'auto'}.'<br />'.
11946: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 11947: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11948: $lt{'yes'}.'</label> <label>'.
11949: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11950: $lt{'no'}.'</label></span><br />'.
11951: '<div id="camtasia_titles" style="display:block">'.
11952: &Apache::lonhtmlcommon::start_pick_box().
11953: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11954: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11955: &Apache::lonhtmlcommon::row_closure().
11956: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11957: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11958: &Apache::lonhtmlcommon::row_closure(1).
11959: &Apache::lonhtmlcommon::end_pick_box().
11960: '</div>';
11961: }
1.1065 raeburn 11962: $output .=
11963: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11964: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11965: "\n";
1.1065 raeburn 11966: if ($duplicates ne '') {
11967: $output .= '<p><span class="LC_warning">'.
11968: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11969: &start_data_table().
11970: &start_data_table_header_row().
11971: '<th>'.&mt('Overwrite?').'</th>'.
11972: '<th>'.&mt('Name').'</th>'.
11973: '<th>'.&mt('Type').'</th>'.
11974: '<th>'.&mt('Size').'</th>'.
11975: '<th>'.&mt('Last modified').'</th>'.
11976: &end_data_table_header_row().
11977: $duplicates.
11978: &end_data_table().
11979: '</p>';
11980: }
1.1067 raeburn 11981: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11982: if (ref($hiddenelements) eq 'HASH') {
11983: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11984: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11985: }
11986: }
11987: $output .= <<"END";
1.1067 raeburn 11988: <br />
1.1053 raeburn 11989: <input type="submit" name="decompress" value="$lt{'extr'}" />
11990: </form>
11991: $noextract
11992: END
11993: return $output;
11994: }
11995:
1.1065 raeburn 11996: sub decompression_utility {
11997: my ($program) = @_;
11998: my @utilities = ('tar','gunzip','bunzip2','unzip');
11999: my $location;
12000: if (grep(/^\Q$program\E$/,@utilities)) {
12001: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12002: '/usr/sbin/') {
12003: if (-x $dir.$program) {
12004: $location = $dir.$program;
12005: last;
12006: }
12007: }
12008: }
12009: return $location;
12010: }
12011:
12012: sub list_archive_contents {
12013: my ($file,$pathsref) = @_;
12014: my (@cmd,$output);
12015: my $needsregexp;
12016: if ($file =~ /\.zip$/) {
12017: @cmd = (&decompression_utility('unzip'),"-l");
12018: $needsregexp = 1;
12019: } elsif (($file =~ m/\.tar\.gz$/) ||
12020: ($file =~ /\.tgz$/)) {
12021: @cmd = (&decompression_utility('tar'),"-ztf");
12022: } elsif ($file =~ /\.tar\.bz2$/) {
12023: @cmd = (&decompression_utility('tar'),"-jtf");
12024: } elsif ($file =~ m|\.tar$|) {
12025: @cmd = (&decompression_utility('tar'),"-tf");
12026: }
12027: if (@cmd) {
12028: undef($!);
12029: undef($@);
12030: if (open(my $fh,"-|", @cmd, $file)) {
12031: while (my $line = <$fh>) {
12032: $output .= $line;
12033: chomp($line);
12034: my $item;
12035: if ($needsregexp) {
12036: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12037: } else {
12038: $item = $line;
12039: }
12040: if ($item ne '') {
12041: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12042: push(@{$pathsref},$item);
12043: }
12044: }
12045: }
12046: close($fh);
12047: }
12048: }
12049: return $output;
12050: }
12051:
1.1053 raeburn 12052: sub decompress_uploaded_file {
12053: my ($file,$dir) = @_;
12054: &Apache::lonnet::appenv({'cgi.file' => $file});
12055: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12056: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12057: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12058: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12059: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12060: my $decompressed = $env{'cgi.decompressed'};
12061: &Apache::lonnet::delenv('cgi.file');
12062: &Apache::lonnet::delenv('cgi.dir');
12063: &Apache::lonnet::delenv('cgi.decompressed');
12064: return ($decompressed,$result);
12065: }
12066:
1.1055 raeburn 12067: sub process_decompression {
12068: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 12069: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12070: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12071: &mt('Unexpected file path.').'</p>'."\n";
12072: }
12073: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12074: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12075: &mt('Unexpected course context.').'</p>'."\n";
12076: }
12077: unless ($file eq &Apache::lonnet::clean_filename($file)) {
12078: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12079: &mt('Filename contained unexpected characters.').'</p>'."\n";
12080: }
1.1055 raeburn 12081: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12082: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12083: $error = &mt('Filename not a supported archive file type.').
12084: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12085: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12086: } else {
12087: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12088: if ($docuhome eq 'no_host') {
12089: $error = &mt('Could not determine home server for course.');
12090: } else {
12091: my @ids=&Apache::lonnet::current_machine_ids();
12092: my $currdir = "$dir_root/$destination";
12093: if (grep(/^\Q$docuhome\E$/,@ids)) {
12094: $dir = &LONCAPA::propath($docudom,$docuname).
12095: "$dir_root/$destination";
12096: } else {
12097: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12098: "$dir_root/$docudom/$docuname/$destination";
12099: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12100: $error = &mt('Archive file not found.');
12101: }
12102: }
1.1065 raeburn 12103: my (@to_overwrite,@to_skip);
12104: if ($env{'form.archive_overwrite_total'} > 0) {
12105: my $total = $env{'form.archive_overwrite_total'};
12106: for (my $i=0; $i<$total; $i++) {
12107: if ($env{'form.archive_overwrite_'.$i} == 1) {
12108: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12109: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12110: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12111: }
12112: }
12113: }
12114: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 12115: my $numoverwrite = scalar(@to_overwrite);
12116: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12117: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12118: } elsif ($dir eq '') {
1.1055 raeburn 12119: $error = &mt('Directory containing archive file unavailable.');
12120: } elsif (!$error) {
1.1065 raeburn 12121: my ($decompressed,$display);
1.1075.2.128 raeburn 12122: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12123: my $tempdir = time.'_'.$$.int(rand(10000));
12124: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 12125: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12126: ($decompressed,$display) =
12127: &decompress_uploaded_file($file,"$dir/$tempdir");
12128: foreach my $item (@to_skip) {
12129: if (($item ne '') && ($item !~ /\.\./)) {
12130: if (-f "$dir/$tempdir/$item") {
12131: unlink("$dir/$tempdir/$item");
12132: } elsif (-d "$dir/$tempdir/$item") {
12133: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
12134: }
12135: }
12136: }
12137: foreach my $item (@to_overwrite) {
12138: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12139: if (($item ne '') && ($item !~ /\.\./)) {
12140: if (-f "$dir/$item") {
12141: unlink("$dir/$item");
12142: } elsif (-d "$dir/$item") {
12143: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
12144: }
12145: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12146: }
1.1065 raeburn 12147: }
12148: }
1.1075.2.128 raeburn 12149: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
12150: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
12151: }
1.1065 raeburn 12152: }
12153: } else {
12154: ($decompressed,$display) =
12155: &decompress_uploaded_file($file,$dir);
12156: }
1.1055 raeburn 12157: if ($decompressed eq 'ok') {
1.1065 raeburn 12158: $output = '<p class="LC_info">'.
12159: &mt('Files extracted successfully from archive.').
12160: '</p>'."\n";
1.1055 raeburn 12161: my ($warning,$result,@contents);
12162: my ($newdirlistref,$newlisterror) =
12163: &Apache::lonnet::dirlist($currdir,$docudom,
12164: $docuname,1);
12165: my (%is_dir,%changes,@newitems);
12166: my $dirptr = 16384;
1.1065 raeburn 12167: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12168: foreach my $dir_line (@{$newdirlistref}) {
12169: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 12170: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12171: push(@newitems,$item);
12172: if ($dirptr&$testdir) {
12173: $is_dir{$item} = 1;
12174: }
12175: $changes{$item} = 1;
12176: }
12177: }
12178: }
12179: if (keys(%changes) > 0) {
12180: foreach my $item (sort(@newitems)) {
12181: if ($changes{$item}) {
12182: push(@contents,$item);
12183: }
12184: }
12185: }
12186: if (@contents > 0) {
1.1067 raeburn 12187: my $wantform;
12188: unless ($env{'form.autoextract_camtasia'}) {
12189: $wantform = 1;
12190: }
1.1056 raeburn 12191: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12192: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12193: $currdir,\%is_dir,
12194: \%children,\%parent,
1.1056 raeburn 12195: \@contents,\%dirorder,
12196: \%titles,$wantform);
1.1055 raeburn 12197: if ($datatable ne '') {
12198: $output .= &archive_options_form('decompressed',$datatable,
12199: $count,$hiddenelem);
1.1065 raeburn 12200: my $startcount = 6;
1.1055 raeburn 12201: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12202: \%titles,\%children);
1.1055 raeburn 12203: }
1.1067 raeburn 12204: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12205: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12206: my %displayed;
12207: my $total = 1;
12208: $env{'form.archive_directory'} = [];
12209: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12210: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12211: $path =~ s{/$}{};
12212: my $item;
12213: if ($path ne '') {
12214: $item = "$path/$titles{$i}";
12215: } else {
12216: $item = $titles{$i};
12217: }
12218: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12219: if ($item eq $contents[0]) {
12220: push(@{$env{'form.archive_directory'}},$i);
12221: $env{'form.archive_'.$i} = 'display';
12222: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12223: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12224: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12225: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12226: $env{'form.archive_'.$i} = 'display';
12227: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12228: $displayed{'web'} = $i;
12229: } else {
1.1075.2.59 raeburn 12230: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12231: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12232: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12233: push(@{$env{'form.archive_directory'}},$i);
12234: }
12235: $env{'form.archive_'.$i} = 'dependency';
12236: }
12237: $total ++;
12238: }
12239: for (my $i=1; $i<$total; $i++) {
12240: next if ($i == $displayed{'web'});
12241: next if ($i == $displayed{'folder'});
12242: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12243: }
12244: $env{'form.phase'} = 'decompress_cleanup';
12245: $env{'form.archivedelete'} = 1;
12246: $env{'form.archive_count'} = $total-1;
12247: $output .=
12248: &process_extracted_files('coursedocs',$docudom,
12249: $docuname,$destination,
12250: $dir_root,$hiddenelem);
12251: }
1.1055 raeburn 12252: } else {
12253: $warning = &mt('No new items extracted from archive file.');
12254: }
12255: } else {
12256: $output = $display;
12257: $error = &mt('An error occurred during extraction from the archive file.');
12258: }
12259: }
12260: }
12261: }
12262: if ($error) {
12263: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12264: $error.'</p>'."\n";
12265: }
12266: if ($warning) {
12267: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12268: }
12269: return $output;
12270: }
12271:
12272: sub get_extracted {
1.1056 raeburn 12273: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12274: $titles,$wantform) = @_;
1.1055 raeburn 12275: my $count = 0;
12276: my $depth = 0;
12277: my $datatable;
1.1056 raeburn 12278: my @hierarchy;
1.1055 raeburn 12279: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12280: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12281: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12282: foreach my $item (@{$contents}) {
12283: $count ++;
1.1056 raeburn 12284: @{$dirorder->{$count}} = @hierarchy;
12285: $titles->{$count} = $item;
1.1055 raeburn 12286: &archive_hierarchy($depth,$count,$parent,$children);
12287: if ($wantform) {
12288: $datatable .= &archive_row($is_dir->{$item},$item,
12289: $currdir,$depth,$count);
12290: }
12291: if ($is_dir->{$item}) {
12292: $depth ++;
1.1056 raeburn 12293: push(@hierarchy,$count);
12294: $parent->{$depth} = $count;
1.1055 raeburn 12295: $datatable .=
12296: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12297: \$depth,\$count,\@hierarchy,$dirorder,
12298: $children,$parent,$titles,$wantform);
1.1055 raeburn 12299: $depth --;
1.1056 raeburn 12300: pop(@hierarchy);
1.1055 raeburn 12301: }
12302: }
12303: return ($count,$datatable);
12304: }
12305:
12306: sub recurse_extracted_archive {
1.1056 raeburn 12307: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12308: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12309: my $result='';
1.1056 raeburn 12310: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12311: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12312: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12313: return $result;
12314: }
12315: my $dirptr = 16384;
12316: my ($newdirlistref,$newlisterror) =
12317: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12318: if (ref($newdirlistref) eq 'ARRAY') {
12319: foreach my $dir_line (@{$newdirlistref}) {
12320: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12321: unless ($item =~ /^\.+$/) {
12322: $$count ++;
1.1056 raeburn 12323: @{$dirorder->{$$count}} = @{$hierarchy};
12324: $titles->{$$count} = $item;
1.1055 raeburn 12325: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12326:
1.1055 raeburn 12327: my $is_dir;
12328: if ($dirptr&$testdir) {
12329: $is_dir = 1;
12330: }
12331: if ($wantform) {
12332: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12333: }
12334: if ($is_dir) {
12335: $$depth ++;
1.1056 raeburn 12336: push(@{$hierarchy},$$count);
12337: $parent->{$$depth} = $$count;
1.1055 raeburn 12338: $result .=
12339: &recurse_extracted_archive("$currdir/$item",$docudom,
12340: $docuname,$depth,$count,
1.1056 raeburn 12341: $hierarchy,$dirorder,$children,
12342: $parent,$titles,$wantform);
1.1055 raeburn 12343: $$depth --;
1.1056 raeburn 12344: pop(@{$hierarchy});
1.1055 raeburn 12345: }
12346: }
12347: }
12348: }
12349: return $result;
12350: }
12351:
12352: sub archive_hierarchy {
12353: my ($depth,$count,$parent,$children) =@_;
12354: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12355: if (exists($parent->{$depth})) {
12356: $children->{$parent->{$depth}} .= $count.':';
12357: }
12358: }
12359: return;
12360: }
12361:
12362: sub archive_row {
12363: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12364: my ($name) = ($item =~ m{([^/]+)$});
12365: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12366: 'display' => 'Add as file',
1.1055 raeburn 12367: 'dependency' => 'Include as dependency',
12368: 'discard' => 'Discard',
12369: );
12370: if ($is_dir) {
1.1059 raeburn 12371: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12372: }
1.1056 raeburn 12373: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12374: my $offset = 0;
1.1055 raeburn 12375: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12376: $offset ++;
1.1065 raeburn 12377: if ($action ne 'display') {
12378: $offset ++;
12379: }
1.1055 raeburn 12380: $output .= '<td><span class="LC_nobreak">'.
12381: '<label><input type="radio" name="archive_'.$count.
12382: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12383: my $text = $choices{$action};
12384: if ($is_dir) {
12385: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12386: if ($action eq 'display') {
1.1059 raeburn 12387: $text = &mt('Add as folder');
1.1055 raeburn 12388: }
1.1056 raeburn 12389: } else {
12390: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12391:
12392: }
12393: $output .= ' /> '.$choices{$action}.'</label></span>';
12394: if ($action eq 'dependency') {
12395: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12396: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12397: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12398: '<option value=""></option>'."\n".
12399: '</select>'."\n".
12400: '</div>';
1.1059 raeburn 12401: } elsif ($action eq 'display') {
12402: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12403: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12404: '</div>';
1.1055 raeburn 12405: }
1.1056 raeburn 12406: $output .= '</td>';
1.1055 raeburn 12407: }
12408: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12409: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12410: for (my $i=0; $i<$depth; $i++) {
12411: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12412: }
12413: if ($is_dir) {
12414: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12415: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12416: } else {
12417: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12418: }
12419: $output .= ' '.$name.'</td>'."\n".
12420: &end_data_table_row();
12421: return $output;
12422: }
12423:
12424: sub archive_options_form {
1.1065 raeburn 12425: my ($form,$display,$count,$hiddenelem) = @_;
12426: my %lt = &Apache::lonlocal::texthash(
12427: perm => 'Permanently remove archive file?',
12428: hows => 'How should each extracted item be incorporated in the course?',
12429: cont => 'Content actions for all',
12430: addf => 'Add as folder/file',
12431: incd => 'Include as dependency for a displayed file',
12432: disc => 'Discard',
12433: no => 'No',
12434: yes => 'Yes',
12435: save => 'Save',
12436: );
12437: my $output = <<"END";
12438: <form name="$form" method="post" action="">
12439: <p><span class="LC_nobreak">$lt{'perm'}
12440: <label>
12441: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12442: </label>
12443:
12444: <label>
12445: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12446: </span>
12447: </p>
12448: <input type="hidden" name="phase" value="decompress_cleanup" />
12449: <br />$lt{'hows'}
12450: <div class="LC_columnSection">
12451: <fieldset>
12452: <legend>$lt{'cont'}</legend>
12453: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12454: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12455: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12456: </fieldset>
12457: </div>
12458: END
12459: return $output.
1.1055 raeburn 12460: &start_data_table()."\n".
1.1065 raeburn 12461: $display."\n".
1.1055 raeburn 12462: &end_data_table()."\n".
12463: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12464: $hiddenelem.
1.1065 raeburn 12465: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12466: '</form>';
12467: }
12468:
12469: sub archive_javascript {
1.1056 raeburn 12470: my ($startcount,$numitems,$titles,$children) = @_;
12471: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12472: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12473: my $scripttag = <<START;
12474: <script type="text/javascript">
12475: // <![CDATA[
12476:
12477: function checkAll(form,prefix) {
12478: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12479: for (var i=0; i < form.elements.length; i++) {
12480: var id = form.elements[i].id;
12481: if ((id != '') && (id != undefined)) {
12482: if (idstr.test(id)) {
12483: if (form.elements[i].type == 'radio') {
12484: form.elements[i].checked = true;
1.1056 raeburn 12485: var nostart = i-$startcount;
1.1059 raeburn 12486: var offset = nostart%7;
12487: var count = (nostart-offset)/7;
1.1056 raeburn 12488: dependencyCheck(form,count,offset);
1.1055 raeburn 12489: }
12490: }
12491: }
12492: }
12493: }
12494:
12495: function propagateCheck(form,count) {
12496: if (count > 0) {
1.1059 raeburn 12497: var startelement = $startcount + ((count-1) * 7);
12498: for (var j=1; j<6; j++) {
12499: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12500: var item = startelement + j;
12501: if (form.elements[item].type == 'radio') {
12502: if (form.elements[item].checked) {
12503: containerCheck(form,count,j);
12504: break;
12505: }
1.1055 raeburn 12506: }
12507: }
12508: }
12509: }
12510: }
12511:
12512: numitems = $numitems
1.1056 raeburn 12513: var titles = new Array(numitems);
12514: var parents = new Array(numitems);
1.1055 raeburn 12515: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12516: parents[i] = new Array;
1.1055 raeburn 12517: }
1.1059 raeburn 12518: var maintitle = '$maintitle';
1.1055 raeburn 12519:
12520: START
12521:
1.1056 raeburn 12522: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12523: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12524: for (my $i=0; $i<@contents; $i ++) {
12525: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12526: }
12527: }
12528:
1.1056 raeburn 12529: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12530: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12531: }
12532:
1.1055 raeburn 12533: $scripttag .= <<END;
12534:
12535: function containerCheck(form,count,offset) {
12536: if (count > 0) {
1.1056 raeburn 12537: dependencyCheck(form,count,offset);
1.1059 raeburn 12538: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12539: form.elements[item].checked = true;
12540: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12541: if (parents[count].length > 0) {
12542: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12543: containerCheck(form,parents[count][j],offset);
12544: }
12545: }
12546: }
12547: }
12548: }
12549:
12550: function dependencyCheck(form,count,offset) {
12551: if (count > 0) {
1.1059 raeburn 12552: var chosen = (offset+$startcount)+7*(count-1);
12553: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12554: var currtype = form.elements[depitem].type;
12555: if (form.elements[chosen].value == 'dependency') {
12556: document.getElementById('arc_depon_'+count).style.display='block';
12557: form.elements[depitem].options.length = 0;
12558: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12559: for (var i=1; i<=numitems; i++) {
12560: if (i == count) {
12561: continue;
12562: }
1.1059 raeburn 12563: var startelement = $startcount + (i-1) * 7;
12564: for (var j=1; j<6; j++) {
12565: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12566: var item = startelement + j;
12567: if (form.elements[item].type == 'radio') {
12568: if (form.elements[item].checked) {
12569: if (form.elements[item].value == 'display') {
12570: var n = form.elements[depitem].options.length;
12571: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12572: }
12573: }
12574: }
12575: }
12576: }
12577: }
12578: } else {
12579: document.getElementById('arc_depon_'+count).style.display='none';
12580: form.elements[depitem].options.length = 0;
12581: form.elements[depitem].options[0] = new Option('Select','',true,true);
12582: }
1.1059 raeburn 12583: titleCheck(form,count,offset);
1.1056 raeburn 12584: }
12585: }
12586:
12587: function propagateSelect(form,count,offset) {
12588: if (count > 0) {
1.1065 raeburn 12589: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12590: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12591: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12592: if (parents[count].length > 0) {
12593: for (var j=0; j<parents[count].length; j++) {
12594: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12595: }
12596: }
12597: }
12598: }
12599: }
1.1056 raeburn 12600:
12601: function containerSelect(form,count,offset,picked) {
12602: if (count > 0) {
1.1065 raeburn 12603: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12604: if (form.elements[item].type == 'radio') {
12605: if (form.elements[item].value == 'dependency') {
12606: if (form.elements[item+1].type == 'select-one') {
12607: for (var i=0; i<form.elements[item+1].options.length; i++) {
12608: if (form.elements[item+1].options[i].value == picked) {
12609: form.elements[item+1].selectedIndex = i;
12610: break;
12611: }
12612: }
12613: }
12614: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12615: if (parents[count].length > 0) {
12616: for (var j=0; j<parents[count].length; j++) {
12617: containerSelect(form,parents[count][j],offset,picked);
12618: }
12619: }
12620: }
12621: }
12622: }
12623: }
12624: }
12625:
1.1059 raeburn 12626: function titleCheck(form,count,offset) {
12627: if (count > 0) {
12628: var chosen = (offset+$startcount)+7*(count-1);
12629: var depitem = $startcount + ((count-1) * 7) + 2;
12630: var currtype = form.elements[depitem].type;
12631: if (form.elements[chosen].value == 'display') {
12632: document.getElementById('arc_title_'+count).style.display='block';
12633: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12634: document.getElementById('archive_title_'+count).value=maintitle;
12635: }
12636: } else {
12637: document.getElementById('arc_title_'+count).style.display='none';
12638: if (currtype == 'text') {
12639: document.getElementById('archive_title_'+count).value='';
12640: }
12641: }
12642: }
12643: return;
12644: }
12645:
1.1055 raeburn 12646: // ]]>
12647: </script>
12648: END
12649: return $scripttag;
12650: }
12651:
12652: sub process_extracted_files {
1.1067 raeburn 12653: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12654: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 12655: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 12656: my @ids=&Apache::lonnet::current_machine_ids();
12657: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12658: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12659: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12660: if (grep(/^\Q$docuhome\E$/,@ids)) {
12661: $prefix = &LONCAPA::propath($docudom,$docuname);
12662: $pathtocheck = "$dir_root/$destination";
12663: $dir = $dir_root;
12664: $ishome = 1;
12665: } else {
12666: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12667: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 12668: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 12669: }
12670: my $currdir = "$dir_root/$destination";
12671: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12672: if ($env{'form.folderpath'}) {
12673: my @items = split('&',$env{'form.folderpath'});
12674: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12675: if ($env{'form.folderpath'} =~ /\:1$/) {
12676: $containers{'0'}='page';
12677: } else {
12678: $containers{'0'}='sequence';
12679: }
1.1055 raeburn 12680: }
12681: my @archdirs = &get_env_multiple('form.archive_directory');
12682: if ($numitems) {
12683: for (my $i=1; $i<=$numitems; $i++) {
12684: my $path = $env{'form.archive_content_'.$i};
12685: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12686: my $item = $1;
12687: $toplevelitems{$item} = $i;
12688: if (grep(/^\Q$i\E$/,@archdirs)) {
12689: $is_dir{$item} = 1;
12690: }
12691: }
12692: }
12693: }
1.1067 raeburn 12694: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12695: if (keys(%toplevelitems) > 0) {
12696: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12697: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12698: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12699: }
1.1066 raeburn 12700: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12701: if ($numitems) {
12702: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12703: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12704: my $path = $env{'form.archive_content_'.$i};
12705: if ($path =~ /^\Q$pathtocheck\E/) {
12706: if ($env{'form.archive_'.$i} eq 'discard') {
12707: if ($prefix ne '' && $path ne '') {
12708: if (-e $prefix.$path) {
1.1066 raeburn 12709: if ((@archdirs > 0) &&
12710: (grep(/^\Q$i\E$/,@archdirs))) {
12711: $todeletedir{$prefix.$path} = 1;
12712: } else {
12713: $todelete{$prefix.$path} = 1;
12714: }
1.1055 raeburn 12715: }
12716: }
12717: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12718: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12719: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12720: $docstitle = $env{'form.archive_title_'.$i};
12721: if ($docstitle eq '') {
12722: $docstitle = $title;
12723: }
1.1055 raeburn 12724: $outer = 0;
1.1056 raeburn 12725: if (ref($dirorder{$i}) eq 'ARRAY') {
12726: if (@{$dirorder{$i}} > 0) {
12727: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12728: if ($env{'form.archive_'.$item} eq 'display') {
12729: $outer = $item;
12730: last;
12731: }
12732: }
12733: }
12734: }
12735: my ($errtext,$fatal) =
12736: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12737: '/'.$folders{$outer}.'.'.
12738: $containers{$outer});
12739: next if ($fatal);
12740: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12741: if ($context eq 'coursedocs') {
1.1056 raeburn 12742: $mapinner{$i} = time;
1.1055 raeburn 12743: $folders{$i} = 'default_'.$mapinner{$i};
12744: $containers{$i} = 'sequence';
12745: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12746: $folders{$i}.'.'.$containers{$i};
12747: my $newidx = &LONCAPA::map::getresidx();
12748: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12749: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12750: push(@LONCAPA::map::order,$newidx);
12751: my ($outtext,$errtext) =
12752: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12753: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12754: '.'.$containers{$outer},1,1);
1.1056 raeburn 12755: $newseqid{$i} = $newidx;
1.1067 raeburn 12756: unless ($errtext) {
1.1075.2.128 raeburn 12757: $result .= '<li>'.&mt('Folder: [_1] added to course',
12758: &HTML::Entities::encode($docstitle,'<>&"'))..
12759: '</li>'."\n";
1.1067 raeburn 12760: }
1.1055 raeburn 12761: }
12762: } else {
12763: if ($context eq 'coursedocs') {
12764: my $newidx=&LONCAPA::map::getresidx();
12765: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12766: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12767: $title;
1.1075.2.128 raeburn 12768: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
12769: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12770: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 12771: }
1.1075.2.128 raeburn 12772: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12773: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12774: }
12775: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12776: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
12777: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
12778: unless ($ishome) {
12779: my $fetch = "$newdest{$i}/$title";
12780: $fetch =~ s/^\Q$prefix$dir\E//;
12781: $prompttofetch{$fetch} = 1;
12782: }
12783: }
12784: }
12785: $LONCAPA::map::resources[$newidx]=
12786: $docstitle.':'.$url.':false:normal:res';
12787: push(@LONCAPA::map::order, $newidx);
12788: my ($outtext,$errtext)=
12789: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12790: $docuname.'/'.$folders{$outer}.
12791: '.'.$containers{$outer},1,1);
12792: unless ($errtext) {
12793: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12794: $result .= '<li>'.&mt('File: [_1] added to course',
12795: &HTML::Entities::encode($docstitle,'<>&"')).
12796: '</li>'."\n";
12797: }
1.1067 raeburn 12798: }
1.1075.2.128 raeburn 12799: } else {
12800: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12801: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 12802: }
1.1055 raeburn 12803: }
12804: }
1.1075.2.11 raeburn 12805: }
12806: } else {
1.1075.2.128 raeburn 12807: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12808: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 12809: }
12810: }
12811: for (my $i=1; $i<=$numitems; $i++) {
12812: next unless ($env{'form.archive_'.$i} eq 'dependency');
12813: my $path = $env{'form.archive_content_'.$i};
12814: if ($path =~ /^\Q$pathtocheck\E/) {
12815: my ($title) = ($path =~ m{/([^/]+)$});
12816: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12817: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12818: if (ref($dirorder{$i}) eq 'ARRAY') {
12819: my ($itemidx,$fullpath,$relpath);
12820: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12821: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12822: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12823: if ($dirorder{$i}->[$j] eq $container) {
12824: $itemidx = $j;
1.1056 raeburn 12825: }
12826: }
1.1075.2.11 raeburn 12827: }
12828: if ($itemidx eq '') {
12829: $itemidx = 0;
12830: }
12831: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12832: if ($mapinner{$referrer{$i}}) {
12833: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12834: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12835: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12836: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12837: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12838: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12839: if (!-e $fullpath) {
12840: mkdir($fullpath,0755);
1.1056 raeburn 12841: }
12842: }
1.1075.2.11 raeburn 12843: } else {
12844: last;
1.1056 raeburn 12845: }
1.1075.2.11 raeburn 12846: }
12847: }
12848: } elsif ($newdest{$referrer{$i}}) {
12849: $fullpath = $newdest{$referrer{$i}};
12850: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12851: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12852: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12853: last;
12854: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12855: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12856: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12857: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12858: if (!-e $fullpath) {
12859: mkdir($fullpath,0755);
1.1056 raeburn 12860: }
12861: }
1.1075.2.11 raeburn 12862: } else {
12863: last;
1.1056 raeburn 12864: }
1.1075.2.11 raeburn 12865: }
12866: }
12867: if ($fullpath ne '') {
12868: if (-e "$prefix$path") {
1.1075.2.128 raeburn 12869: unless (rename("$prefix$path","$fullpath/$title")) {
12870: $warning .= &mt('Failed to rename dependency').'<br />';
12871: }
1.1075.2.11 raeburn 12872: }
12873: if (-e "$fullpath/$title") {
12874: my $showpath;
12875: if ($relpath ne '') {
12876: $showpath = "$relpath/$title";
12877: } else {
12878: $showpath = "/$title";
1.1056 raeburn 12879: }
1.1075.2.128 raeburn 12880: $result .= '<li>'.&mt('[_1] included as a dependency',
12881: &HTML::Entities::encode($showpath,'<>&"')).
12882: '</li>'."\n";
12883: unless ($ishome) {
12884: my $fetch = "$fullpath/$title";
12885: $fetch =~ s/^\Q$prefix$dir\E//;
12886: $prompttofetch{$fetch} = 1;
12887: }
1.1055 raeburn 12888: }
12889: }
12890: }
1.1075.2.11 raeburn 12891: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12892: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 12893: &HTML::Entities::encode($path,'<>&"'),
12894: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
12895: '<br />';
1.1055 raeburn 12896: }
12897: } else {
1.1075.2.128 raeburn 12898: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12899: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 12900: }
12901: }
12902: if (keys(%todelete)) {
12903: foreach my $key (keys(%todelete)) {
12904: unlink($key);
1.1066 raeburn 12905: }
12906: }
12907: if (keys(%todeletedir)) {
12908: foreach my $key (keys(%todeletedir)) {
12909: rmdir($key);
12910: }
12911: }
12912: foreach my $dir (sort(keys(%is_dir))) {
12913: if (($pathtocheck ne '') && ($dir ne '')) {
12914: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12915: }
12916: }
1.1067 raeburn 12917: if ($result ne '') {
12918: $output .= '<ul>'."\n".
12919: $result."\n".
12920: '</ul>';
12921: }
12922: unless ($ishome) {
12923: my $replicationfail;
12924: foreach my $item (keys(%prompttofetch)) {
12925: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12926: unless ($fetchresult eq 'ok') {
12927: $replicationfail .= '<li>'.$item.'</li>'."\n";
12928: }
12929: }
12930: if ($replicationfail) {
12931: $output .= '<p class="LC_error">'.
12932: &mt('Course home server failed to retrieve:').'<ul>'.
12933: $replicationfail.
12934: '</ul></p>';
12935: }
12936: }
1.1055 raeburn 12937: } else {
12938: $warning = &mt('No items found in archive.');
12939: }
12940: if ($error) {
12941: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12942: $error.'</p>'."\n";
12943: }
12944: if ($warning) {
12945: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12946: }
12947: return $output;
12948: }
12949:
1.1066 raeburn 12950: sub cleanup_empty_dirs {
12951: my ($path) = @_;
12952: if (($path ne '') && (-d $path)) {
12953: if (opendir(my $dirh,$path)) {
12954: my @dircontents = grep(!/^\./,readdir($dirh));
12955: my $numitems = 0;
12956: foreach my $item (@dircontents) {
12957: if (-d "$path/$item") {
1.1075.2.28 raeburn 12958: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12959: if (-e "$path/$item") {
12960: $numitems ++;
12961: }
12962: } else {
12963: $numitems ++;
12964: }
12965: }
12966: if ($numitems == 0) {
12967: rmdir($path);
12968: }
12969: closedir($dirh);
12970: }
12971: }
12972: return;
12973: }
12974:
1.41 ng 12975: =pod
1.45 matthew 12976:
1.1075.2.56 raeburn 12977: =item * &get_folder_hierarchy()
1.1068 raeburn 12978:
12979: Provides hierarchy of names of folders/sub-folders containing the current
12980: item,
12981:
12982: Inputs: 3
12983: - $navmap - navmaps object
12984:
12985: - $map - url for map (either the trigger itself, or map containing
12986: the resource, which is the trigger).
12987:
12988: - $showitem - 1 => show title for map itself; 0 => do not show.
12989:
12990: Outputs: 1 @pathitems - array of folder/subfolder names.
12991:
12992: =cut
12993:
12994: sub get_folder_hierarchy {
12995: my ($navmap,$map,$showitem) = @_;
12996: my @pathitems;
12997: if (ref($navmap)) {
12998: my $mapres = $navmap->getResourceByUrl($map);
12999: if (ref($mapres)) {
13000: my $pcslist = $mapres->map_hierarchy();
13001: if ($pcslist ne '') {
13002: my @pcs = split(/,/,$pcslist);
13003: foreach my $pc (@pcs) {
13004: if ($pc == 1) {
1.1075.2.38 raeburn 13005: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13006: } else {
13007: my $res = $navmap->getByMapPc($pc);
13008: if (ref($res)) {
13009: my $title = $res->compTitle();
13010: $title =~ s/\W+/_/g;
13011: if ($title ne '') {
13012: push(@pathitems,$title);
13013: }
13014: }
13015: }
13016: }
13017: }
1.1071 raeburn 13018: if ($showitem) {
13019: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13020: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13021: } else {
13022: my $maptitle = $mapres->compTitle();
13023: $maptitle =~ s/\W+/_/g;
13024: if ($maptitle ne '') {
13025: push(@pathitems,$maptitle);
13026: }
1.1068 raeburn 13027: }
13028: }
13029: }
13030: }
13031: return @pathitems;
13032: }
13033:
13034: =pod
13035:
1.1015 raeburn 13036: =item * &get_turnedin_filepath()
13037:
13038: Determines path in a user's portfolio file for storage of files uploaded
13039: to a specific essayresponse or dropbox item.
13040:
13041: Inputs: 3 required + 1 optional.
13042: $symb is symb for resource, $uname and $udom are for current user (required).
13043: $caller is optional (can be "submission", if routine is called when storing
13044: an upoaded file when "Submit Answer" button was pressed).
13045:
13046: Returns array containing $path and $multiresp.
13047: $path is path in portfolio. $multiresp is 1 if this resource contains more
13048: than one file upload item. Callers of routine should append partid as a
13049: subdirectory to $path in cases where $multiresp is 1.
13050:
13051: Called by: homework/essayresponse.pm and homework/structuretags.pm
13052:
13053: =cut
13054:
13055: sub get_turnedin_filepath {
13056: my ($symb,$uname,$udom,$caller) = @_;
13057: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13058: my $turnindir;
13059: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13060: $turnindir = $userhash{'turnindir'};
13061: my ($path,$multiresp);
13062: if ($turnindir eq '') {
13063: if ($caller eq 'submission') {
13064: $turnindir = &mt('turned in');
13065: $turnindir =~ s/\W+/_/g;
13066: my %newhash = (
13067: 'turnindir' => $turnindir,
13068: );
13069: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13070: }
13071: }
13072: if ($turnindir ne '') {
13073: $path = '/'.$turnindir.'/';
13074: my ($multipart,$turnin,@pathitems);
13075: my $navmap = Apache::lonnavmaps::navmap->new();
13076: if (defined($navmap)) {
13077: my $mapres = $navmap->getResourceByUrl($map);
13078: if (ref($mapres)) {
13079: my $pcslist = $mapres->map_hierarchy();
13080: if ($pcslist ne '') {
13081: foreach my $pc (split(/,/,$pcslist)) {
13082: my $res = $navmap->getByMapPc($pc);
13083: if (ref($res)) {
13084: my $title = $res->compTitle();
13085: $title =~ s/\W+/_/g;
13086: if ($title ne '') {
1.1075.2.48 raeburn 13087: if (($pc > 1) && (length($title) > 12)) {
13088: $title = substr($title,0,12);
13089: }
1.1015 raeburn 13090: push(@pathitems,$title);
13091: }
13092: }
13093: }
13094: }
13095: my $maptitle = $mapres->compTitle();
13096: $maptitle =~ s/\W+/_/g;
13097: if ($maptitle ne '') {
1.1075.2.48 raeburn 13098: if (length($maptitle) > 12) {
13099: $maptitle = substr($maptitle,0,12);
13100: }
1.1015 raeburn 13101: push(@pathitems,$maptitle);
13102: }
13103: unless ($env{'request.state'} eq 'construct') {
13104: my $res = $navmap->getBySymb($symb);
13105: if (ref($res)) {
13106: my $partlist = $res->parts();
13107: my $totaluploads = 0;
13108: if (ref($partlist) eq 'ARRAY') {
13109: foreach my $part (@{$partlist}) {
13110: my @types = $res->responseType($part);
13111: my @ids = $res->responseIds($part);
13112: for (my $i=0; $i < scalar(@ids); $i++) {
13113: if ($types[$i] eq 'essay') {
13114: my $partid = $part.'_'.$ids[$i];
13115: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13116: $totaluploads ++;
13117: }
13118: }
13119: }
13120: }
13121: if ($totaluploads > 1) {
13122: $multiresp = 1;
13123: }
13124: }
13125: }
13126: }
13127: } else {
13128: return;
13129: }
13130: } else {
13131: return;
13132: }
13133: my $restitle=&Apache::lonnet::gettitle($symb);
13134: $restitle =~ s/\W+/_/g;
13135: if ($restitle eq '') {
13136: $restitle = ($resurl =~ m{/[^/]+$});
13137: if ($restitle eq '') {
13138: $restitle = time;
13139: }
13140: }
1.1075.2.48 raeburn 13141: if (length($restitle) > 12) {
13142: $restitle = substr($restitle,0,12);
13143: }
1.1015 raeburn 13144: push(@pathitems,$restitle);
13145: $path .= join('/',@pathitems);
13146: }
13147: return ($path,$multiresp);
13148: }
13149:
13150: =pod
13151:
1.464 albertel 13152: =back
1.41 ng 13153:
1.112 bowersj2 13154: =head1 CSV Upload/Handling functions
1.38 albertel 13155:
1.41 ng 13156: =over 4
13157:
1.648 raeburn 13158: =item * &upfile_store($r)
1.41 ng 13159:
13160: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13161: needs $env{'form.upfile'}
1.41 ng 13162: returns $datatoken to be put into hidden field
13163:
13164: =cut
1.31 albertel 13165:
13166: sub upfile_store {
13167: my $r=shift;
1.258 albertel 13168: $env{'form.upfile'}=~s/\r/\n/gs;
13169: $env{'form.upfile'}=~s/\f/\n/gs;
13170: $env{'form.upfile'}=~s/\n+/\n/gs;
13171: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13172:
1.1075.2.128 raeburn 13173: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13174: '_enroll_'.$env{'request.course.id'}.'_'.
13175: time.'_'.$$);
13176: return if ($datatoken eq '');
13177:
1.31 albertel 13178: {
1.158 raeburn 13179: my $datafile = $r->dir_config('lonDaemons').
13180: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 13181: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13182: print $fh $env{'form.upfile'};
1.158 raeburn 13183: close($fh);
13184: }
1.31 albertel 13185: }
13186: return $datatoken;
13187: }
13188:
1.56 matthew 13189: =pod
13190:
1.1075.2.128 raeburn 13191: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13192:
13193: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 13194: $datatoken is the name to assign to the temporary file.
1.258 albertel 13195: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13196:
13197: =cut
1.31 albertel 13198:
13199: sub load_tmp_file {
1.1075.2.128 raeburn 13200: my ($r,$datatoken) = @_;
13201: return if ($datatoken eq '');
1.31 albertel 13202: my @studentdata=();
13203: {
1.158 raeburn 13204: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 13205: '/tmp/'.$datatoken.'.tmp';
13206: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13207: @studentdata=<$fh>;
13208: close($fh);
13209: }
1.31 albertel 13210: }
1.258 albertel 13211: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13212: }
13213:
1.1075.2.128 raeburn 13214: sub valid_datatoken {
13215: my ($datatoken) = @_;
1.1075.2.131 raeburn 13216: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 13217: return $datatoken;
13218: }
13219: return;
13220: }
13221:
1.56 matthew 13222: =pod
13223:
1.648 raeburn 13224: =item * &upfile_record_sep()
1.41 ng 13225:
13226: Separate uploaded file into records
13227: returns array of records,
1.258 albertel 13228: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13229:
13230: =cut
1.31 albertel 13231:
13232: sub upfile_record_sep {
1.258 albertel 13233: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13234: } else {
1.248 albertel 13235: my @records;
1.258 albertel 13236: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13237: if ($line=~/^\s*$/) { next; }
13238: push(@records,$line);
13239: }
13240: return @records;
1.31 albertel 13241: }
13242: }
13243:
1.56 matthew 13244: =pod
13245:
1.648 raeburn 13246: =item * &record_sep($record)
1.41 ng 13247:
1.258 albertel 13248: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13249:
13250: =cut
13251:
1.263 www 13252: sub takeleft {
13253: my $index=shift;
13254: return substr('0000'.$index,-4,4);
13255: }
13256:
1.31 albertel 13257: sub record_sep {
13258: my $record=shift;
13259: my %components=();
1.258 albertel 13260: if ($env{'form.upfiletype'} eq 'xml') {
13261: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13262: my $i=0;
1.356 albertel 13263: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13264: $field=~s/^(\"|\')//;
13265: $field=~s/(\"|\')$//;
1.263 www 13266: $components{&takeleft($i)}=$field;
1.31 albertel 13267: $i++;
13268: }
1.258 albertel 13269: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13270: my $i=0;
1.356 albertel 13271: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13272: $field=~s/^(\"|\')//;
13273: $field=~s/(\"|\')$//;
1.263 www 13274: $components{&takeleft($i)}=$field;
1.31 albertel 13275: $i++;
13276: }
13277: } else {
1.561 www 13278: my $separator=',';
1.480 banghart 13279: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13280: $separator=';';
1.480 banghart 13281: }
1.31 albertel 13282: my $i=0;
1.561 www 13283: # the character we are looking for to indicate the end of a quote or a record
13284: my $looking_for=$separator;
13285: # do not add the characters to the fields
13286: my $ignore=0;
13287: # we just encountered a separator (or the beginning of the record)
13288: my $just_found_separator=1;
13289: # store the field we are working on here
13290: my $field='';
13291: # work our way through all characters in record
13292: foreach my $character ($record=~/(.)/g) {
13293: if ($character eq $looking_for) {
13294: if ($character ne $separator) {
13295: # Found the end of a quote, again looking for separator
13296: $looking_for=$separator;
13297: $ignore=1;
13298: } else {
13299: # Found a separator, store away what we got
13300: $components{&takeleft($i)}=$field;
13301: $i++;
13302: $just_found_separator=1;
13303: $ignore=0;
13304: $field='';
13305: }
13306: next;
13307: }
13308: # single or double quotation marks after a separator indicate beginning of a quote
13309: # we are now looking for the end of the quote and need to ignore separators
13310: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13311: $looking_for=$character;
13312: next;
13313: }
13314: # ignore would be true after we reached the end of a quote
13315: if ($ignore) { next; }
13316: if (($just_found_separator) && ($character=~/\s/)) { next; }
13317: $field.=$character;
13318: $just_found_separator=0;
1.31 albertel 13319: }
1.561 www 13320: # catch the very last entry, since we never encountered the separator
13321: $components{&takeleft($i)}=$field;
1.31 albertel 13322: }
13323: return %components;
13324: }
13325:
1.144 matthew 13326: ######################################################
13327: ######################################################
13328:
1.56 matthew 13329: =pod
13330:
1.648 raeburn 13331: =item * &upfile_select_html()
1.41 ng 13332:
1.144 matthew 13333: Return HTML code to select a file from the users machine and specify
13334: the file type.
1.41 ng 13335:
13336: =cut
13337:
1.144 matthew 13338: ######################################################
13339: ######################################################
1.31 albertel 13340: sub upfile_select_html {
1.144 matthew 13341: my %Types = (
13342: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13343: semisv => &mt('Semicolon separated values'),
1.144 matthew 13344: space => &mt('Space separated'),
13345: tab => &mt('Tabulator separated'),
13346: # xml => &mt('HTML/XML'),
13347: );
13348: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13349: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13350: foreach my $type (sort(keys(%Types))) {
13351: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13352: }
13353: $Str .= "</select>\n";
13354: return $Str;
1.31 albertel 13355: }
13356:
1.301 albertel 13357: sub get_samples {
13358: my ($records,$toget) = @_;
13359: my @samples=({});
13360: my $got=0;
13361: foreach my $rec (@$records) {
13362: my %temp = &record_sep($rec);
13363: if (! grep(/\S/, values(%temp))) { next; }
13364: if (%temp) {
13365: $samples[$got]=\%temp;
13366: $got++;
13367: if ($got == $toget) { last; }
13368: }
13369: }
13370: return \@samples;
13371: }
13372:
1.144 matthew 13373: ######################################################
13374: ######################################################
13375:
1.56 matthew 13376: =pod
13377:
1.648 raeburn 13378: =item * &csv_print_samples($r,$records)
1.41 ng 13379:
13380: Prints a table of sample values from each column uploaded $r is an
13381: Apache Request ref, $records is an arrayref from
13382: &Apache::loncommon::upfile_record_sep
13383:
13384: =cut
13385:
1.144 matthew 13386: ######################################################
13387: ######################################################
1.31 albertel 13388: sub csv_print_samples {
13389: my ($r,$records) = @_;
1.662 bisitz 13390: my $samples = &get_samples($records,5);
1.301 albertel 13391:
1.594 raeburn 13392: $r->print(&mt('Samples').'<br />'.&start_data_table().
13393: &start_data_table_header_row());
1.356 albertel 13394: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13395: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13396: $r->print(&end_data_table_header_row());
1.301 albertel 13397: foreach my $hash (@$samples) {
1.594 raeburn 13398: $r->print(&start_data_table_row());
1.356 albertel 13399: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13400: $r->print('<td>');
1.356 albertel 13401: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13402: $r->print('</td>');
13403: }
1.594 raeburn 13404: $r->print(&end_data_table_row());
1.31 albertel 13405: }
1.594 raeburn 13406: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13407: }
13408:
1.144 matthew 13409: ######################################################
13410: ######################################################
13411:
1.56 matthew 13412: =pod
13413:
1.648 raeburn 13414: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13415:
13416: Prints a table to create associations between values and table columns.
1.144 matthew 13417:
1.41 ng 13418: $r is an Apache Request ref,
13419: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13420: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13421:
13422: =cut
13423:
1.144 matthew 13424: ######################################################
13425: ######################################################
1.31 albertel 13426: sub csv_print_select_table {
13427: my ($r,$records,$d) = @_;
1.301 albertel 13428: my $i=0;
13429: my $samples = &get_samples($records,1);
1.144 matthew 13430: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13431: &start_data_table().&start_data_table_header_row().
1.144 matthew 13432: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13433: '<th>'.&mt('Column').'</th>'.
13434: &end_data_table_header_row()."\n");
1.356 albertel 13435: foreach my $array_ref (@$d) {
13436: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13437: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13438:
1.875 bisitz 13439: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13440: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13441: $r->print('<option value="none"></option>');
1.356 albertel 13442: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13443: $r->print('<option value="'.$sample.'"'.
13444: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13445: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13446: }
1.594 raeburn 13447: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13448: $i++;
13449: }
1.594 raeburn 13450: $r->print(&end_data_table());
1.31 albertel 13451: $i--;
13452: return $i;
13453: }
1.56 matthew 13454:
1.144 matthew 13455: ######################################################
13456: ######################################################
13457:
1.56 matthew 13458: =pod
1.31 albertel 13459:
1.648 raeburn 13460: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13461:
13462: Prints a table of sample values from the upload and can make associate samples to internal names.
13463:
13464: $r is an Apache Request ref,
13465: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13466: $d is an array of 2 element arrays (internal name, displayed name)
13467:
13468: =cut
13469:
1.144 matthew 13470: ######################################################
13471: ######################################################
1.31 albertel 13472: sub csv_samples_select_table {
13473: my ($r,$records,$d) = @_;
13474: my $i=0;
1.144 matthew 13475: #
1.662 bisitz 13476: my $max_samples = 5;
13477: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13478: $r->print(&start_data_table().
13479: &start_data_table_header_row().'<th>'.
13480: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13481: &end_data_table_header_row());
1.301 albertel 13482:
13483: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13484: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13485: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13486: foreach my $option (@$d) {
13487: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13488: $r->print('<option value="'.$value.'"'.
1.253 albertel 13489: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13490: $display.'</option>');
1.31 albertel 13491: }
13492: $r->print('</select></td><td>');
1.662 bisitz 13493: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13494: if (defined($samples->[$line]{$key})) {
13495: $r->print($samples->[$line]{$key}."<br />\n");
13496: }
13497: }
1.594 raeburn 13498: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13499: $i++;
13500: }
1.594 raeburn 13501: $r->print(&end_data_table());
1.31 albertel 13502: $i--;
13503: return($i);
1.115 matthew 13504: }
13505:
1.144 matthew 13506: ######################################################
13507: ######################################################
13508:
1.115 matthew 13509: =pod
13510:
1.648 raeburn 13511: =item * &clean_excel_name($name)
1.115 matthew 13512:
13513: Returns a replacement for $name which does not contain any illegal characters.
13514:
13515: =cut
13516:
1.144 matthew 13517: ######################################################
13518: ######################################################
1.115 matthew 13519: sub clean_excel_name {
13520: my ($name) = @_;
13521: $name =~ s/[:\*\?\/\\]//g;
13522: if (length($name) > 31) {
13523: $name = substr($name,0,31);
13524: }
13525: return $name;
1.25 albertel 13526: }
1.84 albertel 13527:
1.85 albertel 13528: =pod
13529:
1.648 raeburn 13530: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13531:
13532: Returns either 1 or undef
13533:
13534: 1 if the part is to be hidden, undef if it is to be shown
13535:
13536: Arguments are:
13537:
13538: $id the id of the part to be checked
13539: $symb, optional the symb of the resource to check
13540: $udom, optional the domain of the user to check for
13541: $uname, optional the username of the user to check for
13542:
13543: =cut
1.84 albertel 13544:
13545: sub check_if_partid_hidden {
13546: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13547: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13548: $symb,$udom,$uname);
1.141 albertel 13549: my $truth=1;
13550: #if the string starts with !, then the list is the list to show not hide
13551: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13552: my @hiddenlist=split(/,/,$hiddenparts);
13553: foreach my $checkid (@hiddenlist) {
1.141 albertel 13554: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13555: }
1.141 albertel 13556: return !$truth;
1.84 albertel 13557: }
1.127 matthew 13558:
1.138 matthew 13559:
13560: ############################################################
13561: ############################################################
13562:
13563: =pod
13564:
1.157 matthew 13565: =back
13566:
1.138 matthew 13567: =head1 cgi-bin script and graphing routines
13568:
1.157 matthew 13569: =over 4
13570:
1.648 raeburn 13571: =item * &get_cgi_id()
1.138 matthew 13572:
13573: Inputs: none
13574:
13575: Returns an id which can be used to pass environment variables
13576: to various cgi-bin scripts. These environment variables will
13577: be removed from the users environment after a given time by
13578: the routine &Apache::lonnet::transfer_profile_to_env.
13579:
13580: =cut
13581:
13582: ############################################################
13583: ############################################################
1.152 albertel 13584: my $uniq=0;
1.136 matthew 13585: sub get_cgi_id {
1.154 albertel 13586: $uniq=($uniq+1)%100000;
1.280 albertel 13587: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13588: }
13589:
1.127 matthew 13590: ############################################################
13591: ############################################################
13592:
13593: =pod
13594:
1.648 raeburn 13595: =item * &DrawBarGraph()
1.127 matthew 13596:
1.138 matthew 13597: Facilitates the plotting of data in a (stacked) bar graph.
13598: Puts plot definition data into the users environment in order for
13599: graph.png to plot it. Returns an <img> tag for the plot.
13600: The bars on the plot are labeled '1','2',...,'n'.
13601:
13602: Inputs:
13603:
13604: =over 4
13605:
13606: =item $Title: string, the title of the plot
13607:
13608: =item $xlabel: string, text describing the X-axis of the plot
13609:
13610: =item $ylabel: string, text describing the Y-axis of the plot
13611:
13612: =item $Max: scalar, the maximum Y value to use in the plot
13613: If $Max is < any data point, the graph will not be rendered.
13614:
1.140 matthew 13615: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13616: they are plotted. If undefined, default values will be used.
13617:
1.178 matthew 13618: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13619:
1.138 matthew 13620: =item @Values: An array of array references. Each array reference holds data
13621: to be plotted in a stacked bar chart.
13622:
1.239 matthew 13623: =item If the final element of @Values is a hash reference the key/value
13624: pairs will be added to the graph definition.
13625:
1.138 matthew 13626: =back
13627:
13628: Returns:
13629:
13630: An <img> tag which references graph.png and the appropriate identifying
13631: information for the plot.
13632:
1.127 matthew 13633: =cut
13634:
13635: ############################################################
13636: ############################################################
1.134 matthew 13637: sub DrawBarGraph {
1.178 matthew 13638: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13639: #
13640: if (! defined($colors)) {
13641: $colors = ['#33ff00',
13642: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13643: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13644: ];
13645: }
1.228 matthew 13646: my $extra_settings = {};
13647: if (ref($Values[-1]) eq 'HASH') {
13648: $extra_settings = pop(@Values);
13649: }
1.127 matthew 13650: #
1.136 matthew 13651: my $identifier = &get_cgi_id();
13652: my $id = 'cgi.'.$identifier;
1.129 matthew 13653: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13654: return '';
13655: }
1.225 matthew 13656: #
13657: my @Labels;
13658: if (defined($labels)) {
13659: @Labels = @$labels;
13660: } else {
13661: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 13662: push(@Labels,$i+1);
1.225 matthew 13663: }
13664: }
13665: #
1.129 matthew 13666: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13667: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13668: my %ValuesHash;
13669: my $NumSets=1;
13670: foreach my $array (@Values) {
13671: next if (! ref($array));
1.136 matthew 13672: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13673: join(',',@$array);
1.129 matthew 13674: }
1.127 matthew 13675: #
1.136 matthew 13676: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13677: if ($NumBars < 3) {
13678: $width = 120+$NumBars*32;
1.220 matthew 13679: $xskip = 1;
1.225 matthew 13680: $bar_width = 30;
13681: } elsif ($NumBars < 5) {
13682: $width = 120+$NumBars*20;
13683: $xskip = 1;
13684: $bar_width = 20;
1.220 matthew 13685: } elsif ($NumBars < 10) {
1.136 matthew 13686: $width = 120+$NumBars*15;
13687: $xskip = 1;
13688: $bar_width = 15;
13689: } elsif ($NumBars <= 25) {
13690: $width = 120+$NumBars*11;
13691: $xskip = 5;
13692: $bar_width = 8;
13693: } elsif ($NumBars <= 50) {
13694: $width = 120+$NumBars*8;
13695: $xskip = 5;
13696: $bar_width = 4;
13697: } else {
13698: $width = 120+$NumBars*8;
13699: $xskip = 5;
13700: $bar_width = 4;
13701: }
13702: #
1.137 matthew 13703: $Max = 1 if ($Max < 1);
13704: if ( int($Max) < $Max ) {
13705: $Max++;
13706: $Max = int($Max);
13707: }
1.127 matthew 13708: $Title = '' if (! defined($Title));
13709: $xlabel = '' if (! defined($xlabel));
13710: $ylabel = '' if (! defined($ylabel));
1.369 www 13711: $ValuesHash{$id.'.title'} = &escape($Title);
13712: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13713: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13714: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13715: $ValuesHash{$id.'.NumBars'} = $NumBars;
13716: $ValuesHash{$id.'.NumSets'} = $NumSets;
13717: $ValuesHash{$id.'.PlotType'} = 'bar';
13718: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13719: $ValuesHash{$id.'.height'} = $height;
13720: $ValuesHash{$id.'.width'} = $width;
13721: $ValuesHash{$id.'.xskip'} = $xskip;
13722: $ValuesHash{$id.'.bar_width'} = $bar_width;
13723: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13724: #
1.228 matthew 13725: # Deal with other parameters
13726: while (my ($key,$value) = each(%$extra_settings)) {
13727: $ValuesHash{$id.'.'.$key} = $value;
13728: }
13729: #
1.646 raeburn 13730: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13731: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13732: }
13733:
13734: ############################################################
13735: ############################################################
13736:
13737: =pod
13738:
1.648 raeburn 13739: =item * &DrawXYGraph()
1.137 matthew 13740:
1.138 matthew 13741: Facilitates the plotting of data in an XY graph.
13742: Puts plot definition data into the users environment in order for
13743: graph.png to plot it. Returns an <img> tag for the plot.
13744:
13745: Inputs:
13746:
13747: =over 4
13748:
13749: =item $Title: string, the title of the plot
13750:
13751: =item $xlabel: string, text describing the X-axis of the plot
13752:
13753: =item $ylabel: string, text describing the Y-axis of the plot
13754:
13755: =item $Max: scalar, the maximum Y value to use in the plot
13756: If $Max is < any data point, the graph will not be rendered.
13757:
13758: =item $colors: Array ref containing the hex color codes for the data to be
13759: plotted in. If undefined, default values will be used.
13760:
13761: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13762:
13763: =item $Ydata: Array ref containing Array refs.
1.185 www 13764: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13765:
13766: =item %Values: hash indicating or overriding any default values which are
13767: passed to graph.png.
13768: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13769:
13770: =back
13771:
13772: Returns:
13773:
13774: An <img> tag which references graph.png and the appropriate identifying
13775: information for the plot.
13776:
1.137 matthew 13777: =cut
13778:
13779: ############################################################
13780: ############################################################
13781: sub DrawXYGraph {
13782: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13783: #
13784: # Create the identifier for the graph
13785: my $identifier = &get_cgi_id();
13786: my $id = 'cgi.'.$identifier;
13787: #
13788: $Title = '' if (! defined($Title));
13789: $xlabel = '' if (! defined($xlabel));
13790: $ylabel = '' if (! defined($ylabel));
13791: my %ValuesHash =
13792: (
1.369 www 13793: $id.'.title' => &escape($Title),
13794: $id.'.xlabel' => &escape($xlabel),
13795: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13796: $id.'.y_max_value'=> $Max,
13797: $id.'.labels' => join(',',@$Xlabels),
13798: $id.'.PlotType' => 'XY',
13799: );
13800: #
13801: if (defined($colors) && ref($colors) eq 'ARRAY') {
13802: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13803: }
13804: #
13805: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13806: return '';
13807: }
13808: my $NumSets=1;
1.138 matthew 13809: foreach my $array (@{$Ydata}){
1.137 matthew 13810: next if (! ref($array));
13811: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13812: }
1.138 matthew 13813: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13814: #
13815: # Deal with other parameters
13816: while (my ($key,$value) = each(%Values)) {
13817: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13818: }
13819: #
1.646 raeburn 13820: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13821: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13822: }
13823:
13824: ############################################################
13825: ############################################################
13826:
13827: =pod
13828:
1.648 raeburn 13829: =item * &DrawXYYGraph()
1.138 matthew 13830:
13831: Facilitates the plotting of data in an XY graph with two Y axes.
13832: Puts plot definition data into the users environment in order for
13833: graph.png to plot it. Returns an <img> tag for the plot.
13834:
13835: Inputs:
13836:
13837: =over 4
13838:
13839: =item $Title: string, the title of the plot
13840:
13841: =item $xlabel: string, text describing the X-axis of the plot
13842:
13843: =item $ylabel: string, text describing the Y-axis of the plot
13844:
13845: =item $colors: Array ref containing the hex color codes for the data to be
13846: plotted in. If undefined, default values will be used.
13847:
13848: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13849:
13850: =item $Ydata1: The first data set
13851:
13852: =item $Min1: The minimum value of the left Y-axis
13853:
13854: =item $Max1: The maximum value of the left Y-axis
13855:
13856: =item $Ydata2: The second data set
13857:
13858: =item $Min2: The minimum value of the right Y-axis
13859:
13860: =item $Max2: The maximum value of the left Y-axis
13861:
13862: =item %Values: hash indicating or overriding any default values which are
13863: passed to graph.png.
13864: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13865:
13866: =back
13867:
13868: Returns:
13869:
13870: An <img> tag which references graph.png and the appropriate identifying
13871: information for the plot.
1.136 matthew 13872:
13873: =cut
13874:
13875: ############################################################
13876: ############################################################
1.137 matthew 13877: sub DrawXYYGraph {
13878: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13879: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13880: #
13881: # Create the identifier for the graph
13882: my $identifier = &get_cgi_id();
13883: my $id = 'cgi.'.$identifier;
13884: #
13885: $Title = '' if (! defined($Title));
13886: $xlabel = '' if (! defined($xlabel));
13887: $ylabel = '' if (! defined($ylabel));
13888: my %ValuesHash =
13889: (
1.369 www 13890: $id.'.title' => &escape($Title),
13891: $id.'.xlabel' => &escape($xlabel),
13892: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13893: $id.'.labels' => join(',',@$Xlabels),
13894: $id.'.PlotType' => 'XY',
13895: $id.'.NumSets' => 2,
1.137 matthew 13896: $id.'.two_axes' => 1,
13897: $id.'.y1_max_value' => $Max1,
13898: $id.'.y1_min_value' => $Min1,
13899: $id.'.y2_max_value' => $Max2,
13900: $id.'.y2_min_value' => $Min2,
1.136 matthew 13901: );
13902: #
1.137 matthew 13903: if (defined($colors) && ref($colors) eq 'ARRAY') {
13904: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13905: }
13906: #
13907: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13908: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13909: return '';
13910: }
13911: my $NumSets=1;
1.137 matthew 13912: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13913: next if (! ref($array));
13914: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13915: }
13916: #
13917: # Deal with other parameters
13918: while (my ($key,$value) = each(%Values)) {
13919: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13920: }
13921: #
1.646 raeburn 13922: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13923: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13924: }
13925:
13926: ############################################################
13927: ############################################################
13928:
13929: =pod
13930:
1.157 matthew 13931: =back
13932:
1.139 matthew 13933: =head1 Statistics helper routines?
13934:
13935: Bad place for them but what the hell.
13936:
1.157 matthew 13937: =over 4
13938:
1.648 raeburn 13939: =item * &chartlink()
1.139 matthew 13940:
13941: Returns a link to the chart for a specific student.
13942:
13943: Inputs:
13944:
13945: =over 4
13946:
13947: =item $linktext: The text of the link
13948:
13949: =item $sname: The students username
13950:
13951: =item $sdomain: The students domain
13952:
13953: =back
13954:
1.157 matthew 13955: =back
13956:
1.139 matthew 13957: =cut
13958:
13959: ############################################################
13960: ############################################################
13961: sub chartlink {
13962: my ($linktext, $sname, $sdomain) = @_;
13963: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13964: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13965: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13966: '">'.$linktext.'</a>';
1.153 matthew 13967: }
13968:
13969: #######################################################
13970: #######################################################
13971:
13972: =pod
13973:
13974: =head1 Course Environment Routines
1.157 matthew 13975:
13976: =over 4
1.153 matthew 13977:
1.648 raeburn 13978: =item * &restore_course_settings()
1.153 matthew 13979:
1.648 raeburn 13980: =item * &store_course_settings()
1.153 matthew 13981:
13982: Restores/Store indicated form parameters from the course environment.
13983: Will not overwrite existing values of the form parameters.
13984:
13985: Inputs:
13986: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13987:
13988: a hash ref describing the data to be stored. For example:
13989:
13990: %Save_Parameters = ('Status' => 'scalar',
13991: 'chartoutputmode' => 'scalar',
13992: 'chartoutputdata' => 'scalar',
13993: 'Section' => 'array',
1.373 raeburn 13994: 'Group' => 'array',
1.153 matthew 13995: 'StudentData' => 'array',
13996: 'Maps' => 'array');
13997:
13998: Returns: both routines return nothing
13999:
1.631 raeburn 14000: =back
14001:
1.153 matthew 14002: =cut
14003:
14004: #######################################################
14005: #######################################################
14006: sub store_course_settings {
1.496 albertel 14007: return &store_settings($env{'request.course.id'},@_);
14008: }
14009:
14010: sub store_settings {
1.153 matthew 14011: # save to the environment
14012: # appenv the same items, just to be safe
1.300 albertel 14013: my $udom = $env{'user.domain'};
14014: my $uname = $env{'user.name'};
1.496 albertel 14015: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14016: my %SaveHash;
14017: my %AppHash;
14018: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14019: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14020: my $envname = 'environment.'.$basename;
1.258 albertel 14021: if (exists($env{'form.'.$setting})) {
1.153 matthew 14022: # Save this value away
14023: if ($type eq 'scalar' &&
1.258 albertel 14024: (! exists($env{$envname}) ||
14025: $env{$envname} ne $env{'form.'.$setting})) {
14026: $SaveHash{$basename} = $env{'form.'.$setting};
14027: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14028: } elsif ($type eq 'array') {
14029: my $stored_form;
1.258 albertel 14030: if (ref($env{'form.'.$setting})) {
1.153 matthew 14031: $stored_form = join(',',
14032: map {
1.369 www 14033: &escape($_);
1.258 albertel 14034: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14035: } else {
14036: $stored_form =
1.369 www 14037: &escape($env{'form.'.$setting});
1.153 matthew 14038: }
14039: # Determine if the array contents are the same.
1.258 albertel 14040: if ($stored_form ne $env{$envname}) {
1.153 matthew 14041: $SaveHash{$basename} = $stored_form;
14042: $AppHash{$envname} = $stored_form;
14043: }
14044: }
14045: }
14046: }
14047: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14048: $udom,$uname);
1.153 matthew 14049: if ($put_result !~ /^(ok|delayed)/) {
14050: &Apache::lonnet::logthis('unable to save form parameters, '.
14051: 'got error:'.$put_result);
14052: }
14053: # Make sure these settings stick around in this session, too
1.646 raeburn 14054: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14055: return;
14056: }
14057:
14058: sub restore_course_settings {
1.499 albertel 14059: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14060: }
14061:
14062: sub restore_settings {
14063: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14064: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14065: next if (exists($env{'form.'.$setting}));
1.496 albertel 14066: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14067: '.'.$setting;
1.258 albertel 14068: if (exists($env{$envname})) {
1.153 matthew 14069: if ($type eq 'scalar') {
1.258 albertel 14070: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14071: } elsif ($type eq 'array') {
1.258 albertel 14072: $env{'form.'.$setting} = [
1.153 matthew 14073: map {
1.369 www 14074: &unescape($_);
1.258 albertel 14075: } split(',',$env{$envname})
1.153 matthew 14076: ];
14077: }
14078: }
14079: }
1.127 matthew 14080: }
14081:
1.618 raeburn 14082: #######################################################
14083: #######################################################
14084:
14085: =pod
14086:
14087: =head1 Domain E-mail Routines
14088:
14089: =over 4
14090:
1.648 raeburn 14091: =item * &build_recipient_list()
1.618 raeburn 14092:
1.1075.2.44 raeburn 14093: Build recipient lists for following types of e-mail:
1.766 raeburn 14094: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14095: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14096: module change checking, student/employee ID conflict checks, as
14097: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14098: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14099:
14100: Inputs:
1.1075.2.44 raeburn 14101: defmail (scalar - email address of default recipient),
14102: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14103: requestsmail, updatesmail, or idconflictsmail).
14104:
1.619 raeburn 14105: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14106:
14107: origmail (scalar - email address of recipient from loncapa.conf,
14108: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14109:
1.655 raeburn 14110: Returns: comma separated list of addresses to which to send e-mail.
14111:
14112: =back
1.618 raeburn 14113:
14114: =cut
14115:
14116: ############################################################
14117: ############################################################
14118: sub build_recipient_list {
1.619 raeburn 14119: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 14120: my @recipients;
1.1075.2.122 raeburn 14121: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14122: my %domconfig =
1.1075.2.122 raeburn 14123: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14124: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14125: if (exists($domconfig{'contacts'}{$mailing})) {
14126: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14127: my @contacts = ('adminemail','supportemail');
14128: foreach my $item (@contacts) {
14129: if ($domconfig{'contacts'}{$mailing}{$item}) {
14130: my $addr = $domconfig{'contacts'}{$item};
14131: if (!grep(/^\Q$addr\E$/,@recipients)) {
14132: push(@recipients,$addr);
14133: }
1.619 raeburn 14134: }
1.1075.2.122 raeburn 14135: }
14136: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14137: if ($mailing eq 'helpdeskmail') {
14138: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14139: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14140: my @ok_bccs;
14141: foreach my $bcc (@bccs) {
14142: $bcc =~ s/^\s+//g;
14143: $bcc =~ s/\s+$//g;
14144: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14145: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14146: push(@ok_bccs,$bcc);
14147: }
14148: }
14149: }
14150: if (@ok_bccs > 0) {
14151: $allbcc = join(', ',@ok_bccs);
14152: }
14153: }
14154: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14155: }
14156: }
1.766 raeburn 14157: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14158: $lastresort = $origmail;
1.618 raeburn 14159: }
1.619 raeburn 14160: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14161: $lastresort = $origmail;
14162: }
14163:
1.1075.2.128 raeburn 14164: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14165: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14166: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14167: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14168: my %what = (
14169: perlvar => 1,
14170: );
14171: my $primary = &Apache::lonnet::domain($defdom,'primary');
14172: if ($primary) {
14173: my $gotaddr;
14174: my ($result,$returnhash) =
14175: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14176: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14177: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14178: $lastresort = $returnhash->{'lonSupportEMail'};
14179: $gotaddr = 1;
14180: }
14181: }
14182: unless ($gotaddr) {
14183: my $uintdom = &Apache::lonnet::internet_dom($primary);
14184: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14185: unless ($uintdom eq $intdom) {
14186: my %domconfig =
14187: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14188: if (ref($domconfig{'contacts'}) eq 'HASH') {
14189: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14190: my @contacts = ('adminemail','supportemail');
14191: foreach my $item (@contacts) {
14192: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14193: my $addr = $domconfig{'contacts'}{$item};
14194: if (!grep(/^\Q$addr\E$/,@recipients)) {
14195: push(@recipients,$addr);
14196: }
14197: }
14198: }
14199: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14200: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14201: }
14202: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14203: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14204: my @ok_bccs;
14205: foreach my $bcc (@bccs) {
14206: $bcc =~ s/^\s+//g;
14207: $bcc =~ s/\s+$//g;
14208: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14209: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14210: push(@ok_bccs,$bcc);
14211: }
14212: }
14213: }
14214: if (@ok_bccs > 0) {
14215: $allbcc = join(', ',@ok_bccs);
14216: }
14217: }
14218: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14219: }
14220: }
14221: }
14222: }
14223: }
14224: }
1.618 raeburn 14225: }
1.688 raeburn 14226: if (defined($defmail)) {
14227: if ($defmail ne '') {
14228: push(@recipients,$defmail);
14229: }
1.618 raeburn 14230: }
14231: if ($otheremails) {
1.619 raeburn 14232: my @others;
14233: if ($otheremails =~ /,/) {
14234: @others = split(/,/,$otheremails);
1.618 raeburn 14235: } else {
1.619 raeburn 14236: push(@others,$otheremails);
14237: }
14238: foreach my $addr (@others) {
14239: if (!grep(/^\Q$addr\E$/,@recipients)) {
14240: push(@recipients,$addr);
14241: }
1.618 raeburn 14242: }
14243: }
1.1075.2.128 raeburn 14244: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14245: if ((!@recipients) && ($lastresort ne '')) {
14246: push(@recipients,$lastresort);
14247: }
14248: } elsif ($lastresort ne '') {
14249: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14250: push(@recipients,$lastresort);
14251: }
14252: }
14253: my $recipientlist = join(',',@recipients);
14254: if (wantarray) {
14255: return ($recipientlist,$allbcc,$addtext);
14256: } else {
14257: return $recipientlist;
14258: }
1.618 raeburn 14259: }
14260:
1.127 matthew 14261: ############################################################
14262: ############################################################
1.154 albertel 14263:
1.655 raeburn 14264: =pod
14265:
14266: =head1 Course Catalog Routines
14267:
14268: =over 4
14269:
14270: =item * &gather_categories()
14271:
14272: Converts category definitions - keys of categories hash stored in
14273: coursecategories in configuration.db on the primary library server in a
14274: domain - to an array. Also generates javascript and idx hash used to
14275: generate Domain Coordinator interface for editing Course Categories.
14276:
14277: Inputs:
1.663 raeburn 14278:
1.655 raeburn 14279: categories (reference to hash of category definitions).
1.663 raeburn 14280:
1.655 raeburn 14281: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14282: categories and subcategories).
1.663 raeburn 14283:
1.655 raeburn 14284: idx (reference to hash of counters used in Domain Coordinator interface for
14285: editing Course Categories).
1.663 raeburn 14286:
1.655 raeburn 14287: jsarray (reference to array of categories used to create Javascript arrays for
14288: Domain Coordinator interface for editing Course Categories).
14289:
14290: Returns: nothing
14291:
14292: Side effects: populates cats, idx and jsarray.
14293:
14294: =cut
14295:
14296: sub gather_categories {
14297: my ($categories,$cats,$idx,$jsarray) = @_;
14298: my %counters;
14299: my $num = 0;
14300: foreach my $item (keys(%{$categories})) {
14301: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14302: if ($container eq '' && $depth == 0) {
14303: $cats->[$depth][$categories->{$item}] = $cat;
14304: } else {
14305: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14306: }
14307: my ($escitem,$tail) = split(/:/,$item,2);
14308: if ($counters{$tail} eq '') {
14309: $counters{$tail} = $num;
14310: $num ++;
14311: }
14312: if (ref($idx) eq 'HASH') {
14313: $idx->{$item} = $counters{$tail};
14314: }
14315: if (ref($jsarray) eq 'ARRAY') {
14316: push(@{$jsarray->[$counters{$tail}]},$item);
14317: }
14318: }
14319: return;
14320: }
14321:
14322: =pod
14323:
14324: =item * &extract_categories()
14325:
14326: Used to generate breadcrumb trails for course categories.
14327:
14328: Inputs:
1.663 raeburn 14329:
1.655 raeburn 14330: categories (reference to hash of category definitions).
1.663 raeburn 14331:
1.655 raeburn 14332: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14333: categories and subcategories).
1.663 raeburn 14334:
1.655 raeburn 14335: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14336:
1.655 raeburn 14337: allitems (reference to hash - key is category key
14338: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14339:
1.655 raeburn 14340: idx (reference to hash of counters used in Domain Coordinator interface for
14341: editing Course Categories).
1.663 raeburn 14342:
1.655 raeburn 14343: jsarray (reference to array of categories used to create Javascript arrays for
14344: Domain Coordinator interface for editing Course Categories).
14345:
1.665 raeburn 14346: subcats (reference to hash of arrays containing all subcategories within each
14347: category, -recursive)
14348:
1.1075.2.132 raeburn 14349: maxd (reference to hash used to hold max depth for all top-level categories).
14350:
1.655 raeburn 14351: Returns: nothing
14352:
14353: Side effects: populates trails and allitems hash references.
14354:
14355: =cut
14356:
14357: sub extract_categories {
1.1075.2.132 raeburn 14358: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 14359: if (ref($categories) eq 'HASH') {
14360: &gather_categories($categories,$cats,$idx,$jsarray);
14361: if (ref($cats->[0]) eq 'ARRAY') {
14362: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14363: my $name = $cats->[0][$i];
14364: my $item = &escape($name).'::0';
14365: my $trailstr;
14366: if ($name eq 'instcode') {
14367: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14368: } elsif ($name eq 'communities') {
14369: $trailstr = &mt('Communities');
1.655 raeburn 14370: } else {
14371: $trailstr = $name;
14372: }
14373: if ($allitems->{$item} eq '') {
14374: push(@{$trails},$trailstr);
14375: $allitems->{$item} = scalar(@{$trails})-1;
14376: }
14377: my @parents = ($name);
14378: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14379: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14380: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14381: if (ref($subcats) eq 'HASH') {
14382: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14383: }
1.1075.2.132 raeburn 14384: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 14385: }
14386: } else {
14387: if (ref($subcats) eq 'HASH') {
14388: $subcats->{$item} = [];
1.655 raeburn 14389: }
1.1075.2.132 raeburn 14390: if (ref($maxd) eq 'HASH') {
14391: $maxd->{$name} = 1;
14392: }
1.655 raeburn 14393: }
14394: }
14395: }
14396: }
14397: return;
14398: }
14399:
14400: =pod
14401:
1.1075.2.56 raeburn 14402: =item * &recurse_categories()
1.655 raeburn 14403:
14404: Recursively used to generate breadcrumb trails for course categories.
14405:
14406: Inputs:
1.663 raeburn 14407:
1.655 raeburn 14408: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14409: categories and subcategories).
1.663 raeburn 14410:
1.655 raeburn 14411: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14412:
14413: category (current course category, for which breadcrumb trail is being generated).
14414:
14415: trails (reference to array of breadcrumb trails for each category).
14416:
1.655 raeburn 14417: allitems (reference to hash - key is category key
14418: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14419:
1.655 raeburn 14420: parents (array containing containers directories for current category,
14421: back to top level).
14422:
14423: Returns: nothing
14424:
14425: Side effects: populates trails and allitems hash references
14426:
14427: =cut
14428:
14429: sub recurse_categories {
1.1075.2.132 raeburn 14430: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 14431: my $shallower = $depth - 1;
14432: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14433: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14434: my $name = $cats->[$depth]{$category}[$k];
14435: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14436: my $trailstr = join(' -> ',(@{$parents},$category));
14437: if ($allitems->{$item} eq '') {
14438: push(@{$trails},$trailstr);
14439: $allitems->{$item} = scalar(@{$trails})-1;
14440: }
14441: my $deeper = $depth+1;
14442: push(@{$parents},$category);
1.665 raeburn 14443: if (ref($subcats) eq 'HASH') {
14444: my $subcat = &escape($name).':'.$category.':'.$depth;
14445: for (my $j=@{$parents}; $j>=0; $j--) {
14446: my $higher;
14447: if ($j > 0) {
14448: $higher = &escape($parents->[$j]).':'.
14449: &escape($parents->[$j-1]).':'.$j;
14450: } else {
14451: $higher = &escape($parents->[$j]).'::'.$j;
14452: }
14453: push(@{$subcats->{$higher}},$subcat);
14454: }
14455: }
14456: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 14457: $subcats,$maxd);
1.655 raeburn 14458: pop(@{$parents});
14459: }
14460: } else {
14461: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 14462: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14463: if ($allitems->{$item} eq '') {
14464: push(@{$trails},$trailstr);
14465: $allitems->{$item} = scalar(@{$trails})-1;
14466: }
1.1075.2.132 raeburn 14467: if (ref($maxd) eq 'HASH') {
14468: if ($depth > $maxd->{$parents->[0]}) {
14469: $maxd->{$parents->[0]} = $depth;
14470: }
14471: }
1.655 raeburn 14472: }
14473: return;
14474: }
14475:
1.663 raeburn 14476: =pod
14477:
1.1075.2.56 raeburn 14478: =item * &assign_categories_table()
1.663 raeburn 14479:
14480: Create a datatable for display of hierarchical categories in a domain,
14481: with checkboxes to allow a course to be categorized.
14482:
14483: Inputs:
14484:
14485: cathash - reference to hash of categories defined for the domain (from
14486: configuration.db)
14487:
14488: currcat - scalar with an & separated list of categories assigned to a course.
14489:
1.919 raeburn 14490: type - scalar contains course type (Course or Community).
14491:
1.1075.2.117 raeburn 14492: disabled - scalar (optional) contains disabled="disabled" if input elements are
14493: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14494:
1.663 raeburn 14495: Returns: $output (markup to be displayed)
14496:
14497: =cut
14498:
14499: sub assign_categories_table {
1.1075.2.117 raeburn 14500: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14501: my $output;
14502: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 14503: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
14504: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 14505: $maxdepth = scalar(@cats);
14506: if (@cats > 0) {
14507: my $itemcount = 0;
14508: if (ref($cats[0]) eq 'ARRAY') {
14509: my @currcategories;
14510: if ($currcat ne '') {
14511: @currcategories = split('&',$currcat);
14512: }
1.919 raeburn 14513: my $table;
1.663 raeburn 14514: for (my $i=0; $i<@{$cats[0]}; $i++) {
14515: my $parent = $cats[0][$i];
1.919 raeburn 14516: next if ($parent eq 'instcode');
14517: if ($type eq 'Community') {
14518: next unless ($parent eq 'communities');
14519: } else {
14520: next if ($parent eq 'communities');
14521: }
1.663 raeburn 14522: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14523: my $item = &escape($parent).'::0';
14524: my $checked = '';
14525: if (@currcategories > 0) {
14526: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14527: $checked = ' checked="checked"';
1.663 raeburn 14528: }
14529: }
1.919 raeburn 14530: my $parent_title = $parent;
14531: if ($parent eq 'communities') {
14532: $parent_title = &mt('Communities');
14533: }
14534: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14535: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14536: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 14537: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14538: my $depth = 1;
14539: push(@path,$parent);
1.1075.2.117 raeburn 14540: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 14541: pop(@path);
1.919 raeburn 14542: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14543: $itemcount ++;
14544: }
1.919 raeburn 14545: if ($itemcount) {
14546: $output = &Apache::loncommon::start_data_table().
14547: $table.
14548: &Apache::loncommon::end_data_table();
14549: }
1.663 raeburn 14550: }
14551: }
14552: }
14553: return $output;
14554: }
14555:
14556: =pod
14557:
1.1075.2.56 raeburn 14558: =item * &assign_category_rows()
1.663 raeburn 14559:
14560: Create a datatable row for display of nested categories in a domain,
14561: with checkboxes to allow a course to be categorized,called recursively.
14562:
14563: Inputs:
14564:
14565: itemcount - track row number for alternating colors
14566:
14567: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14568: categories and subcategories.
14569:
14570: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14571:
14572: parent - parent of current category item
14573:
14574: path - Array containing all categories back up through the hierarchy from the
14575: current category to the top level.
14576:
14577: currcategories - reference to array of current categories assigned to the course
14578:
1.1075.2.117 raeburn 14579: disabled - scalar (optional) contains disabled="disabled" if input elements are
14580: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14581:
1.663 raeburn 14582: Returns: $output (markup to be displayed).
14583:
14584: =cut
14585:
14586: sub assign_category_rows {
1.1075.2.117 raeburn 14587: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 14588: my ($text,$name,$item,$chgstr);
14589: if (ref($cats) eq 'ARRAY') {
14590: my $maxdepth = scalar(@{$cats});
14591: if (ref($cats->[$depth]) eq 'HASH') {
14592: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14593: my $numchildren = @{$cats->[$depth]{$parent}};
14594: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 14595: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14596: for (my $j=0; $j<$numchildren; $j++) {
14597: $name = $cats->[$depth]{$parent}[$j];
14598: $item = &escape($name).':'.&escape($parent).':'.$depth;
14599: my $deeper = $depth+1;
14600: my $checked = '';
14601: if (ref($currcategories) eq 'ARRAY') {
14602: if (@{$currcategories} > 0) {
14603: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14604: $checked = ' checked="checked"';
1.663 raeburn 14605: }
14606: }
14607: }
1.664 raeburn 14608: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14609: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14610: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 14611: '<input type="hidden" name="catname" value="'.$name.'" />'.
14612: '</td><td>';
1.663 raeburn 14613: if (ref($path) eq 'ARRAY') {
14614: push(@{$path},$name);
1.1075.2.117 raeburn 14615: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 14616: pop(@{$path});
14617: }
14618: $text .= '</td></tr>';
14619: }
14620: $text .= '</table></td>';
14621: }
14622: }
14623: }
14624: return $text;
14625: }
14626:
1.1075.2.69 raeburn 14627: =pod
14628:
14629: =back
14630:
14631: =cut
14632:
1.655 raeburn 14633: ############################################################
14634: ############################################################
14635:
14636:
1.443 albertel 14637: sub commit_customrole {
1.664 raeburn 14638: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14639: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14640: ($start?', '.&mt('starting').' '.localtime($start):'').
14641: ($end?', ending '.localtime($end):'').': <b>'.
14642: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14643: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14644: '</b><br />';
14645: return $output;
14646: }
14647:
14648: sub commit_standardrole {
1.1075.2.31 raeburn 14649: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14650: my ($output,$logmsg,$linefeed);
14651: if ($context eq 'auto') {
14652: $linefeed = "\n";
14653: } else {
14654: $linefeed = "<br />\n";
14655: }
1.443 albertel 14656: if ($three eq 'st') {
1.541 raeburn 14657: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 14658: $one,$two,$sec,$context,$credits);
1.541 raeburn 14659: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14660: ($result eq 'unknown_course') || ($result eq 'refused')) {
14661: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14662: } else {
1.541 raeburn 14663: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14664: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14665: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14666: if ($context eq 'auto') {
14667: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14668: } else {
14669: $output .= '<b>'.$result.'</b>'.$linefeed.
14670: &mt('Add to classlist').': <b>ok</b>';
14671: }
14672: $output .= $linefeed;
1.443 albertel 14673: }
14674: } else {
14675: $output = &mt('Assigning').' '.$three.' in '.$url.
14676: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14677: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14678: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14679: if ($context eq 'auto') {
14680: $output .= $result.$linefeed;
14681: } else {
14682: $output .= '<b>'.$result.'</b>'.$linefeed;
14683: }
1.443 albertel 14684: }
14685: return $output;
14686: }
14687:
14688: sub commit_studentrole {
1.1075.2.31 raeburn 14689: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14690: $credits) = @_;
1.626 raeburn 14691: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14692: if ($context eq 'auto') {
14693: $linefeed = "\n";
14694: } else {
14695: $linefeed = '<br />'."\n";
14696: }
1.443 albertel 14697: if (defined($one) && defined($two)) {
14698: my $cid=$one.'_'.$two;
14699: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14700: my $secchange = 0;
14701: my $expire_role_result;
14702: my $modify_section_result;
1.628 raeburn 14703: if ($oldsec ne '-1') {
14704: if ($oldsec ne $sec) {
1.443 albertel 14705: $secchange = 1;
1.628 raeburn 14706: my $now = time;
1.443 albertel 14707: my $uurl='/'.$cid;
14708: $uurl=~s/\_/\//g;
14709: if ($oldsec) {
14710: $uurl.='/'.$oldsec;
14711: }
1.626 raeburn 14712: $oldsecurl = $uurl;
1.628 raeburn 14713: $expire_role_result =
1.652 raeburn 14714: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14715: if ($env{'request.course.sec'} ne '') {
14716: if ($expire_role_result eq 'refused') {
14717: my @roles = ('st');
14718: my @statuses = ('previous');
14719: my @roledoms = ($one);
14720: my $withsec = 1;
14721: my %roleshash =
14722: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14723: \@statuses,\@roles,\@roledoms,$withsec);
14724: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14725: my ($oldstart,$oldend) =
14726: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14727: if ($oldend > 0 && $oldend <= $now) {
14728: $expire_role_result = 'ok';
14729: }
14730: }
14731: }
14732: }
1.443 albertel 14733: $result = $expire_role_result;
14734: }
14735: }
14736: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 14737: $modify_section_result =
14738: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14739: undef,undef,undef,$sec,
14740: $end,$start,'','',$cid,
14741: '',$context,$credits);
1.443 albertel 14742: if ($modify_section_result =~ /^ok/) {
14743: if ($secchange == 1) {
1.628 raeburn 14744: if ($sec eq '') {
14745: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14746: } else {
14747: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14748: }
1.443 albertel 14749: } elsif ($oldsec eq '-1') {
1.628 raeburn 14750: if ($sec eq '') {
14751: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14752: } else {
14753: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14754: }
1.443 albertel 14755: } else {
1.628 raeburn 14756: if ($sec eq '') {
14757: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14758: } else {
14759: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14760: }
1.443 albertel 14761: }
14762: } else {
1.628 raeburn 14763: if ($secchange) {
14764: $$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;
14765: } else {
14766: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14767: }
1.443 albertel 14768: }
14769: $result = $modify_section_result;
14770: } elsif ($secchange == 1) {
1.628 raeburn 14771: if ($oldsec eq '') {
1.1075.2.20 raeburn 14772: $$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 14773: } else {
14774: $$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;
14775: }
1.626 raeburn 14776: if ($expire_role_result eq 'refused') {
14777: my $newsecurl = '/'.$cid;
14778: $newsecurl =~ s/\_/\//g;
14779: if ($sec ne '') {
14780: $newsecurl.='/'.$sec;
14781: }
14782: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14783: if ($sec eq '') {
14784: $$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;
14785: } else {
14786: $$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;
14787: }
14788: }
14789: }
1.443 albertel 14790: }
14791: } else {
1.626 raeburn 14792: $$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 14793: $result = "error: incomplete course id\n";
14794: }
14795: return $result;
14796: }
14797:
1.1075.2.25 raeburn 14798: sub show_role_extent {
14799: my ($scope,$context,$role) = @_;
14800: $scope =~ s{^/}{};
14801: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14802: push(@courseroles,'co');
14803: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14804: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14805: $scope =~ s{/}{_};
14806: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14807: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14808: my ($audom,$auname) = split(/\//,$scope);
14809: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14810: &Apache::loncommon::plainname($auname,$audom).'</span>');
14811: } else {
14812: $scope =~ s{/$}{};
14813: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14814: &Apache::lonnet::domain($scope,'description').'</span>');
14815: }
14816: }
14817:
1.443 albertel 14818: ############################################################
14819: ############################################################
14820:
1.566 albertel 14821: sub check_clone {
1.578 raeburn 14822: my ($args,$linefeed) = @_;
1.566 albertel 14823: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14824: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14825: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14826: my $clonemsg;
14827: my $can_clone = 0;
1.944 raeburn 14828: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14829: if ($lctype ne 'community') {
14830: $lctype = 'course';
14831: }
1.566 albertel 14832: if ($clonehome eq 'no_host') {
1.944 raeburn 14833: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14834: $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'});
14835: } else {
14836: $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'});
14837: }
1.566 albertel 14838: } else {
14839: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 14840: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14841: if ($clonedesc{'type'} ne 'Community') {
14842: $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'});
14843: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14844: }
14845: }
1.1075.2.119 raeburn 14846: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 14847: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 14848: $can_clone = 1;
14849: } else {
1.1075.2.95 raeburn 14850: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 14851: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 14852: if ($clonehash{'cloners'} eq '') {
14853: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
14854: if ($domdefs{'canclone'}) {
14855: unless ($domdefs{'canclone'} eq 'none') {
14856: if ($domdefs{'canclone'} eq 'domain') {
14857: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
14858: $can_clone = 1;
14859: }
14860: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14861: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
14862: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
14863: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
14864: $can_clone = 1;
14865: }
14866: }
14867: }
1.908 raeburn 14868: }
1.1075.2.95 raeburn 14869: } else {
14870: my @cloners = split(/,/,$clonehash{'cloners'});
14871: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 14872: $can_clone = 1;
1.1075.2.95 raeburn 14873: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 14874: $can_clone = 1;
1.1075.2.96 raeburn 14875: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
14876: $can_clone = 1;
1.1075.2.95 raeburn 14877: }
14878: unless ($can_clone) {
1.1075.2.96 raeburn 14879: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14880: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 14881: my (%gotdomdefaults,%gotcodedefaults);
14882: foreach my $cloner (@cloners) {
14883: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
14884: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
14885: my (%codedefaults,@code_order);
14886: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
14887: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
14888: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
14889: }
14890: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
14891: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
14892: }
14893: } else {
14894: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
14895: \%codedefaults,
14896: \@code_order);
14897: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
14898: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
14899: }
14900: if (@code_order > 0) {
14901: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
14902: $cloner,$clonehash{'internal.coursecode'},
14903: $args->{'crscode'})) {
14904: $can_clone = 1;
14905: last;
14906: }
14907: }
14908: }
14909: }
14910: }
1.1075.2.96 raeburn 14911: }
14912: }
14913: unless ($can_clone) {
14914: my $ccrole = 'cc';
14915: if ($args->{'crstype'} eq 'Community') {
14916: $ccrole = 'co';
14917: }
14918: my %roleshash =
14919: &Apache::lonnet::get_my_roles($args->{'ccuname'},
14920: $args->{'ccdomain'},
14921: 'userroles',['active'],[$ccrole],
14922: [$args->{'clonedomain'}]);
14923: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
14924: $can_clone = 1;
14925: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
14926: $args->{'ccuname'},$args->{'ccdomain'})) {
14927: $can_clone = 1;
1.1075.2.95 raeburn 14928: }
14929: }
14930: unless ($can_clone) {
14931: if ($args->{'crstype'} eq 'Community') {
14932: $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'});
14933: } else {
14934: $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'});
1.578 raeburn 14935: }
1.566 albertel 14936: }
1.578 raeburn 14937: }
1.566 albertel 14938: }
14939: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14940: }
14941:
1.444 albertel 14942: sub construct_course {
1.1075.2.119 raeburn 14943: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
14944: $cnum,$category,$coderef) = @_;
1.444 albertel 14945: my $outcome;
1.541 raeburn 14946: my $linefeed = '<br />'."\n";
14947: if ($context eq 'auto') {
14948: $linefeed = "\n";
14949: }
1.566 albertel 14950:
14951: #
14952: # Are we cloning?
14953: #
14954: my ($can_clone, $clonemsg, $cloneid, $clonehome);
14955: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 14956: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 14957: if ($context ne 'auto') {
1.578 raeburn 14958: if ($clonemsg ne '') {
14959: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
14960: }
1.566 albertel 14961: }
14962: $outcome .= $clonemsg.$linefeed;
14963:
14964: if (!$can_clone) {
14965: return (0,$outcome);
14966: }
14967: }
14968:
1.444 albertel 14969: #
14970: # Open course
14971: #
14972: my $crstype = lc($args->{'crstype'});
14973: my %cenv=();
14974: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
14975: $args->{'cdescr'},
14976: $args->{'curl'},
14977: $args->{'course_home'},
14978: $args->{'nonstandard'},
14979: $args->{'crscode'},
14980: $args->{'ccuname'}.':'.
14981: $args->{'ccdomain'},
1.882 raeburn 14982: $args->{'crstype'},
1.885 raeburn 14983: $cnum,$context,$category);
1.444 albertel 14984:
14985: # Note: The testing routines depend on this being output; see
14986: # Utils::Course. This needs to at least be output as a comment
14987: # if anyone ever decides to not show this, and Utils::Course::new
14988: # will need to be suitably modified.
1.541 raeburn 14989: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 14990: if ($$courseid =~ /^error:/) {
14991: return (0,$outcome);
14992: }
14993:
1.444 albertel 14994: #
14995: # Check if created correctly
14996: #
1.479 albertel 14997: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 14998: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 14999: if ($crsuhome eq 'no_host') {
15000: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15001: return (0,$outcome);
15002: }
1.541 raeburn 15003: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15004:
1.444 albertel 15005: #
1.566 albertel 15006: # Do the cloning
15007: #
15008: if ($can_clone && $cloneid) {
15009: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
15010: if ($context ne 'auto') {
15011: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15012: }
15013: $outcome .= $clonemsg.$linefeed;
15014: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15015: # Copy all files
1.637 www 15016: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15017: # Restore URL
1.566 albertel 15018: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15019: # Restore title
1.566 albertel 15020: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15021: # Restore creation date, creator and creation context.
15022: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15023: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15024: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15025: # Mark as cloned
1.566 albertel 15026: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15027: # Need to clone grading mode
15028: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15029: $cenv{'grading'}=$newenv{'grading'};
15030: # Do not clone these environment entries
15031: &Apache::lonnet::del('environment',
15032: ['default_enrollment_start_date',
15033: 'default_enrollment_end_date',
15034: 'question.email',
15035: 'policy.email',
15036: 'comment.email',
15037: 'pch.users.denied',
1.725 raeburn 15038: 'plc.users.denied',
15039: 'hidefromcat',
1.1075.2.36 raeburn 15040: 'checkforpriv',
1.1075.2.59 raeburn 15041: 'categories',
15042: 'internal.uniquecode'],
1.638 www 15043: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 15044: if ($args->{'textbook'}) {
15045: $cenv{'internal.textbook'} = $args->{'textbook'};
15046: }
1.444 albertel 15047: }
1.566 albertel 15048:
1.444 albertel 15049: #
15050: # Set environment (will override cloned, if existing)
15051: #
15052: my @sections = ();
15053: my @xlists = ();
15054: if ($args->{'crstype'}) {
15055: $cenv{'type'}=$args->{'crstype'};
15056: }
15057: if ($args->{'crsid'}) {
15058: $cenv{'courseid'}=$args->{'crsid'};
15059: }
15060: if ($args->{'crscode'}) {
15061: $cenv{'internal.coursecode'}=$args->{'crscode'};
15062: }
15063: if ($args->{'crsquota'} ne '') {
15064: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15065: } else {
15066: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15067: }
15068: if ($args->{'ccuname'}) {
15069: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15070: ':'.$args->{'ccdomain'};
15071: } else {
15072: $cenv{'internal.courseowner'} = $args->{'curruser'};
15073: }
1.1075.2.31 raeburn 15074: if ($args->{'defaultcredits'}) {
15075: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15076: }
1.444 albertel 15077: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15078: if ($args->{'crssections'}) {
15079: $cenv{'internal.sectionnums'} = '';
15080: if ($args->{'crssections'} =~ m/,/) {
15081: @sections = split/,/,$args->{'crssections'};
15082: } else {
15083: $sections[0] = $args->{'crssections'};
15084: }
15085: if (@sections > 0) {
15086: foreach my $item (@sections) {
15087: my ($sec,$gp) = split/:/,$item;
15088: my $class = $args->{'crscode'}.$sec;
15089: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15090: $cenv{'internal.sectionnums'} .= $item.',';
15091: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15092: push(@badclasses,$class);
1.444 albertel 15093: }
15094: }
15095: $cenv{'internal.sectionnums'} =~ s/,$//;
15096: }
15097: }
15098: # do not hide course coordinator from staff listing,
15099: # even if privileged
15100: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15101: # add course coordinator's domain to domains to check for privileged users
15102: # if different to course domain
15103: if ($$crsudom ne $args->{'ccdomain'}) {
15104: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15105: }
1.444 albertel 15106: # add crosslistings
15107: if ($args->{'crsxlist'}) {
15108: $cenv{'internal.crosslistings'}='';
15109: if ($args->{'crsxlist'} =~ m/,/) {
15110: @xlists = split/,/,$args->{'crsxlist'};
15111: } else {
15112: $xlists[0] = $args->{'crsxlist'};
15113: }
15114: if (@xlists > 0) {
15115: foreach my $item (@xlists) {
15116: my ($xl,$gp) = split/:/,$item;
15117: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15118: $cenv{'internal.crosslistings'} .= $item.',';
15119: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15120: push(@badclasses,$xl);
1.444 albertel 15121: }
15122: }
15123: $cenv{'internal.crosslistings'} =~ s/,$//;
15124: }
15125: }
15126: if ($args->{'autoadds'}) {
15127: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15128: }
15129: if ($args->{'autodrops'}) {
15130: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15131: }
15132: # check for notification of enrollment changes
15133: my @notified = ();
15134: if ($args->{'notify_owner'}) {
15135: if ($args->{'ccuname'} ne '') {
15136: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15137: }
15138: }
15139: if ($args->{'notify_dc'}) {
15140: if ($uname ne '') {
1.630 raeburn 15141: push(@notified,$uname.':'.$udom);
1.444 albertel 15142: }
15143: }
15144: if (@notified > 0) {
15145: my $notifylist;
15146: if (@notified > 1) {
15147: $notifylist = join(',',@notified);
15148: } else {
15149: $notifylist = $notified[0];
15150: }
15151: $cenv{'internal.notifylist'} = $notifylist;
15152: }
15153: if (@badclasses > 0) {
15154: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15155: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15156: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15157: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15158: );
1.1075.2.119 raeburn 15159: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15160: &mt('That is because the user identified as the course owner ([_1]) does not have rights to access enrollment in these classes, as determined by the policies of your institution on access to official classlists',$cenv{'internal.courseowner'}).$linefeed.$lt{'itis'};
1.541 raeburn 15161: if ($context eq 'auto') {
15162: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15163: } else {
1.566 albertel 15164: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15165: }
15166: foreach my $item (@badclasses) {
1.541 raeburn 15167: if ($context eq 'auto') {
1.1075.2.119 raeburn 15168: $outcome .= " - $item\n";
1.541 raeburn 15169: } else {
1.1075.2.119 raeburn 15170: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15171: }
1.1075.2.119 raeburn 15172: }
15173: if ($context eq 'auto') {
15174: $outcome .= $linefeed;
15175: } else {
15176: $outcome .= "</ul><br /><br /></div>\n";
15177: }
1.444 albertel 15178: }
15179: if ($args->{'no_end_date'}) {
15180: $args->{'endaccess'} = 0;
15181: }
15182: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15183: $cenv{'internal.autoend'}=$args->{'enrollend'};
15184: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15185: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15186: if ($args->{'showphotos'}) {
15187: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15188: }
15189: $cenv{'internal.authtype'} = $args->{'authtype'};
15190: $cenv{'internal.autharg'} = $args->{'autharg'};
15191: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15192: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15193: 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');
15194: if ($context eq 'auto') {
15195: $outcome .= $krb_msg;
15196: } else {
1.566 albertel 15197: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15198: }
15199: $outcome .= $linefeed;
1.444 albertel 15200: }
15201: }
15202: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15203: if ($args->{'setpolicy'}) {
15204: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15205: }
15206: if ($args->{'setcontent'}) {
15207: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15208: }
1.1075.2.110 raeburn 15209: if ($args->{'setcomment'}) {
15210: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15211: }
1.444 albertel 15212: }
15213: if ($args->{'reshome'}) {
15214: $cenv{'reshome'}=$args->{'reshome'}.'/';
15215: $cenv{'reshome'}=~s/\/+$/\//;
15216: }
15217: #
15218: # course has keyed access
15219: #
15220: if ($args->{'setkeys'}) {
15221: $cenv{'keyaccess'}='yes';
15222: }
15223: # if specified, key authority is not course, but user
15224: # only active if keyaccess is yes
15225: if ($args->{'keyauth'}) {
1.487 albertel 15226: my ($user,$domain) = split(':',$args->{'keyauth'});
15227: $user = &LONCAPA::clean_username($user);
15228: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15229: if ($user ne '' && $domain ne '') {
1.487 albertel 15230: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15231: }
15232: }
15233:
1.1075.2.59 raeburn 15234: #
15235: # generate and store uniquecode (available to course requester), if course should have one.
15236: #
15237: if ($args->{'uniquecode'}) {
15238: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15239: if ($code) {
15240: $cenv{'internal.uniquecode'} = $code;
15241: my %crsinfo =
15242: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15243: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15244: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15245: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15246: }
15247: if (ref($coderef)) {
15248: $$coderef = $code;
15249: }
15250: }
15251: }
15252:
1.444 albertel 15253: if ($args->{'disresdis'}) {
15254: $cenv{'pch.roles.denied'}='st';
15255: }
15256: if ($args->{'disablechat'}) {
15257: $cenv{'plc.roles.denied'}='st';
15258: }
15259:
15260: # Record we've not yet viewed the Course Initialization Helper for this
15261: # course
15262: $cenv{'course.helper.not.run'} = 1;
15263: #
15264: # Use new Randomseed
15265: #
15266: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15267: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15268: #
15269: # The encryption code and receipt prefix for this course
15270: #
15271: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15272: $cenv{'internal.encpref'}=100+int(9*rand(99));
15273: #
15274: # By default, use standard grading
15275: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15276:
1.541 raeburn 15277: $outcome .= $linefeed.&mt('Setting environment').': '.
15278: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15279: #
15280: # Open all assignments
15281: #
15282: if ($args->{'openall'}) {
15283: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15284: my %storecontent = ($storeunder => time,
15285: $storeunder.'.type' => 'date_start');
15286:
15287: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15288: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15289: }
15290: #
15291: # Set first page
15292: #
15293: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15294: || ($cloneid)) {
1.445 albertel 15295: use LONCAPA::map;
1.444 albertel 15296: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15297:
15298: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15299: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15300:
1.444 albertel 15301: $outcome .= ($fatal?$errtext:'read ok').' - ';
15302: my $title; my $url;
15303: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15304: $title=&mt('Syllabus');
1.444 albertel 15305: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15306: } else {
1.963 raeburn 15307: $title=&mt('Table of Contents');
1.444 albertel 15308: $url='/adm/navmaps';
15309: }
1.445 albertel 15310:
15311: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15312: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15313:
15314: if ($errtext) { $fatal=2; }
1.541 raeburn 15315: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15316: }
1.566 albertel 15317:
15318: return (1,$outcome);
1.444 albertel 15319: }
15320:
1.1075.2.59 raeburn 15321: sub make_unique_code {
15322: my ($cdom,$cnum) = @_;
15323: # get lock on uniquecodes db
15324: my $lockhash = {
15325: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15326: ':'.$env{'user.domain'},
15327: };
15328: my $tries = 0;
15329: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15330: my ($code,$error);
15331:
15332: while (($gotlock ne 'ok') && ($tries<3)) {
15333: $tries ++;
15334: sleep 1;
15335: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15336: }
15337: if ($gotlock eq 'ok') {
15338: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15339: my $gotcode;
15340: my $attempts = 0;
15341: while ((!$gotcode) && ($attempts < 100)) {
15342: $code = &generate_code();
15343: if (!exists($currcodes{$code})) {
15344: $gotcode = 1;
15345: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15346: $error = 'nostore';
15347: }
15348: }
15349: $attempts ++;
15350: }
15351: my @del_lock = ($cnum."\0".'uniquecodes');
15352: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15353: } else {
15354: $error = 'nolock';
15355: }
15356: return ($code,$error);
15357: }
15358:
15359: sub generate_code {
15360: my $code;
15361: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15362: for (my $i=0; $i<6; $i++) {
15363: my $lettnum = int (rand 2);
15364: my $item = '';
15365: if ($lettnum) {
15366: $item = $letts[int( rand(18) )];
15367: } else {
15368: $item = 1+int( rand(8) );
15369: }
15370: $code .= $item;
15371: }
15372: return $code;
15373: }
15374:
1.444 albertel 15375: ############################################################
15376: ############################################################
15377:
1.953 droeschl 15378: #SD
15379: # only Community and Course, or anything else?
1.378 raeburn 15380: sub course_type {
15381: my ($cid) = @_;
15382: if (!defined($cid)) {
15383: $cid = $env{'request.course.id'};
15384: }
1.404 albertel 15385: if (defined($env{'course.'.$cid.'.type'})) {
15386: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15387: } else {
15388: return 'Course';
1.377 raeburn 15389: }
15390: }
1.156 albertel 15391:
1.406 raeburn 15392: sub group_term {
15393: my $crstype = &course_type();
15394: my %names = (
15395: 'Course' => 'group',
1.865 raeburn 15396: 'Community' => 'group',
1.406 raeburn 15397: );
15398: return $names{$crstype};
15399: }
15400:
1.902 raeburn 15401: sub course_types {
1.1075.2.59 raeburn 15402: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15403: my %typename = (
15404: official => 'Official course',
15405: unofficial => 'Unofficial course',
15406: community => 'Community',
1.1075.2.59 raeburn 15407: textbook => 'Textbook course',
1.902 raeburn 15408: );
15409: return (\@types,\%typename);
15410: }
15411:
1.156 albertel 15412: sub icon {
15413: my ($file)=@_;
1.505 albertel 15414: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15415: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15416: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15417: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15418: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15419: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15420: $curfext.".gif") {
15421: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15422: $curfext.".gif";
15423: }
15424: }
1.249 albertel 15425: return &lonhttpdurl($iconname);
1.154 albertel 15426: }
1.84 albertel 15427:
1.575 albertel 15428: sub lonhttpdurl {
1.692 www 15429: #
15430: # Had been used for "small fry" static images on separate port 8080.
15431: # Modify here if lightweight http functionality desired again.
15432: # Currently eliminated due to increasing firewall issues.
15433: #
1.575 albertel 15434: my ($url)=@_;
1.692 www 15435: return $url;
1.215 albertel 15436: }
15437:
1.213 albertel 15438: sub connection_aborted {
15439: my ($r)=@_;
15440: $r->print(" ");$r->rflush();
15441: my $c = $r->connection;
15442: return $c->aborted();
15443: }
15444:
1.221 foxr 15445: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15446: # strings as 'strings'.
15447: sub escape_single {
1.221 foxr 15448: my ($input) = @_;
1.223 albertel 15449: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15450: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15451: return $input;
15452: }
1.223 albertel 15453:
1.222 foxr 15454: # Same as escape_single, but escape's "'s This
15455: # can be used for "strings"
15456: sub escape_double {
15457: my ($input) = @_;
15458: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15459: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15460: return $input;
15461: }
1.223 albertel 15462:
1.222 foxr 15463: # Escapes the last element of a full URL.
15464: sub escape_url {
15465: my ($url) = @_;
1.238 raeburn 15466: my @urlslices = split(/\//, $url,-1);
1.369 www 15467: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15468: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15469: }
1.462 albertel 15470:
1.820 raeburn 15471: sub compare_arrays {
15472: my ($arrayref1,$arrayref2) = @_;
15473: my (@difference,%count);
15474: @difference = ();
15475: %count = ();
15476: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15477: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15478: foreach my $element (keys(%count)) {
15479: if ($count{$element} == 1) {
15480: push(@difference,$element);
15481: }
15482: }
15483: }
15484: return @difference;
15485: }
15486:
1.817 bisitz 15487: # -------------------------------------------------------- Initialize user login
1.462 albertel 15488: sub init_user_environment {
1.463 albertel 15489: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15490: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15491:
15492: my $public=($username eq 'public' && $domain eq 'public');
15493:
15494: # See if old ID present, if so, remove
15495:
1.1062 raeburn 15496: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15497: my $now=time;
15498:
15499: if ($public) {
15500: my $max_public=100;
15501: my $oldest;
15502: my $oldest_time=0;
15503: for(my $next=1;$next<=$max_public;$next++) {
15504: if (-e $lonids."/publicuser_$next.id") {
15505: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15506: if ($mtime<$oldest_time || !$oldest_time) {
15507: $oldest_time=$mtime;
15508: $oldest=$next;
15509: }
15510: } else {
15511: $cookie="publicuser_$next";
15512: last;
15513: }
15514: }
15515: if (!$cookie) { $cookie="publicuser_$oldest"; }
15516: } else {
1.463 albertel 15517: # if this isn't a robot, kill any existing non-robot sessions
15518: if (!$args->{'robot'}) {
15519: opendir(DIR,$lonids);
15520: while ($filename=readdir(DIR)) {
15521: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136! raeburn 15522: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
! 15523: &GDBM_READER(),0640)) {
! 15524: my $linkedfile;
! 15525: if (exists($oldenv{'user.linkedenv'})) {
! 15526: $linkedfile = $oldenv{'user.linkedenv'};
! 15527: }
! 15528: untie(%oldenv);
! 15529: if (unlink("$lonids/$filename")) {
! 15530: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
! 15531: if (-l "$lonids/$linkedfile.id") {
! 15532: unlink("$lonids/$linkedfile.id");
! 15533: }
! 15534: }
! 15535: }
! 15536: } else {
! 15537: unlink($lonids.'/'.$filename);
! 15538: }
1.463 albertel 15539: }
1.462 albertel 15540: }
1.463 albertel 15541: closedir(DIR);
1.1075.2.84 raeburn 15542: # If there is a undeleted lockfile for the user's paste buffer remove it.
15543: my $namespace = 'nohist_courseeditor';
15544: my $lockingkey = 'paste'."\0".'locked_num';
15545: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15546: $domain,$username);
15547: if (exists($lockhash{$lockingkey})) {
15548: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15549: unless ($delresult eq 'ok') {
15550: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15551: }
15552: }
1.462 albertel 15553: }
15554: # Give them a new cookie
1.463 albertel 15555: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15556: : $now.$$.int(rand(10000)));
1.463 albertel 15557: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15558:
15559: # Initialize roles
15560:
1.1062 raeburn 15561: ($userroles,$firstaccenv,$timerintenv) =
15562: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15563: }
15564: # ------------------------------------ Check browser type and MathML capability
15565:
1.1075.2.77 raeburn 15566: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15567: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15568:
15569: # ------------------------------------------------------------- Get environment
15570:
15571: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15572: my ($tmp) = keys(%userenv);
15573: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15574: } else {
15575: undef(%userenv);
15576: }
15577: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15578: $form->{'interface'}=$userenv{'interface'};
15579: }
15580: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15581:
15582: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15583: foreach my $option ('interface','localpath','localres') {
15584: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15585: }
15586: # --------------------------------------------------------- Write first profile
15587:
15588: {
15589: my %initial_env =
15590: ("user.name" => $username,
15591: "user.domain" => $domain,
15592: "user.home" => $authhost,
15593: "browser.type" => $clientbrowser,
15594: "browser.version" => $clientversion,
15595: "browser.mathml" => $clientmathml,
15596: "browser.unicode" => $clientunicode,
15597: "browser.os" => $clientos,
1.1075.2.42 raeburn 15598: "browser.mobile" => $clientmobile,
15599: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 15600: "browser.osversion" => $clientosversion,
1.462 albertel 15601: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15602: "request.course.fn" => '',
15603: "request.course.uri" => '',
15604: "request.course.sec" => '',
15605: "request.role" => 'cm',
15606: "request.role.adv" => $env{'user.adv'},
15607: "request.host" => $ENV{'REMOTE_ADDR'},);
15608:
15609: if ($form->{'localpath'}) {
15610: $initial_env{"browser.localpath"} = $form->{'localpath'};
15611: $initial_env{"browser.localres"} = $form->{'localres'};
15612: }
15613:
15614: if ($form->{'interface'}) {
15615: $form->{'interface'}=~s/\W//gs;
15616: $initial_env{"browser.interface"} = $form->{'interface'};
15617: $env{'browser.interface'}=$form->{'interface'};
15618: }
15619:
1.1075.2.54 raeburn 15620: if ($form->{'iptoken'}) {
15621: my $lonhost = $r->dir_config('lonHostID');
15622: $initial_env{"user.noloadbalance"} = $lonhost;
15623: $env{'user.noloadbalance'} = $lonhost;
15624: }
15625:
1.1075.2.120 raeburn 15626: if ($form->{'noloadbalance'}) {
15627: my @hosts = &Apache::lonnet::current_machine_ids();
15628: my $hosthere = $form->{'noloadbalance'};
15629: if (grep(/^\Q$hosthere\E$/,@hosts)) {
15630: $initial_env{"user.noloadbalance"} = $hosthere;
15631: $env{'user.noloadbalance'} = $hosthere;
15632: }
15633: }
15634:
1.1016 raeburn 15635: unless ($domain eq 'public') {
1.1075.2.125 raeburn 15636: my %is_adv = ( is_adv => $env{'user.adv'} );
15637: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 15638:
1.1075.2.125 raeburn 15639: foreach my $tool ('aboutme','blog','webdav','portfolio') {
15640: $userenv{'availabletools.'.$tool} =
15641: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15642: undef,\%userenv,\%domdef,\%is_adv);
15643: }
1.724 raeburn 15644:
1.1075.2.125 raeburn 15645: foreach my $crstype ('official','unofficial','community','textbook') {
15646: $userenv{'canrequest.'.$crstype} =
15647: &Apache::lonnet::usertools_access($username,$domain,$crstype,
15648: 'reload','requestcourses',
15649: \%userenv,\%domdef,\%is_adv);
15650: }
1.765 raeburn 15651:
1.1075.2.125 raeburn 15652: $userenv{'canrequest.author'} =
15653: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15654: 'reload','requestauthor',
15655: \%userenv,\%domdef,\%is_adv);
15656: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15657: $domain,$username);
15658: my $reqstatus = $reqauthor{'author_status'};
15659: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15660: if (ref($reqauthor{'author'}) eq 'HASH') {
15661: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15662: $reqauthor{'author'}{'timestamp'};
15663: }
1.1075.2.14 raeburn 15664: }
15665: }
15666:
1.462 albertel 15667: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15668:
1.462 albertel 15669: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15670: &GDBM_WRCREAT(),0640)) {
15671: &_add_to_env(\%disk_env,\%initial_env);
15672: &_add_to_env(\%disk_env,\%userenv,'environment.');
15673: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15674: if (ref($firstaccenv) eq 'HASH') {
15675: &_add_to_env(\%disk_env,$firstaccenv);
15676: }
15677: if (ref($timerintenv) eq 'HASH') {
15678: &_add_to_env(\%disk_env,$timerintenv);
15679: }
1.463 albertel 15680: if (ref($args->{'extra_env'})) {
15681: &_add_to_env(\%disk_env,$args->{'extra_env'});
15682: }
1.462 albertel 15683: untie(%disk_env);
15684: } else {
1.705 tempelho 15685: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15686: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15687: return 'error: '.$!;
15688: }
15689: }
15690: $env{'request.role'}='cm';
15691: $env{'request.role.adv'}=$env{'user.adv'};
15692: $env{'browser.type'}=$clientbrowser;
15693:
15694: return $cookie;
15695:
15696: }
15697:
15698: sub _add_to_env {
15699: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15700: if (ref($env_data) eq 'HASH') {
15701: while (my ($key,$value) = each(%$env_data)) {
15702: $idf->{$prefix.$key} = $value;
15703: $env{$prefix.$key} = $value;
15704: }
1.462 albertel 15705: }
15706: }
15707:
1.685 tempelho 15708: # --- Get the symbolic name of a problem and the url
15709: sub get_symb {
15710: my ($request,$silent) = @_;
1.726 raeburn 15711: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15712: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15713: if ($symb eq '') {
15714: if (!$silent) {
1.1071 raeburn 15715: if (ref($request)) {
15716: $request->print("Unable to handle ambiguous references:$url:.");
15717: }
1.685 tempelho 15718: return ();
15719: }
15720: }
15721: &Apache::lonenc::check_decrypt(\$symb);
15722: return ($symb);
15723: }
15724:
15725: # --------------------------------------------------------------Get annotation
15726:
15727: sub get_annotation {
15728: my ($symb,$enc) = @_;
15729:
15730: my $key = $symb;
15731: if (!$enc) {
15732: $key =
15733: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15734: }
15735: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15736: return $annotation{$key};
15737: }
15738:
15739: sub clean_symb {
1.731 raeburn 15740: my ($symb,$delete_enc) = @_;
1.685 tempelho 15741:
15742: &Apache::lonenc::check_decrypt(\$symb);
15743: my $enc = $env{'request.enc'};
1.731 raeburn 15744: if ($delete_enc) {
1.730 raeburn 15745: delete($env{'request.enc'});
15746: }
1.685 tempelho 15747:
15748: return ($symb,$enc);
15749: }
1.462 albertel 15750:
1.1075.2.69 raeburn 15751: ############################################################
15752: ############################################################
15753:
15754: =pod
15755:
15756: =head1 Routines for building display used to search for courses
15757:
15758:
15759: =over 4
15760:
15761: =item * &build_filters()
15762:
15763: Create markup for a table used to set filters to use when selecting
15764: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15765: and quotacheck.pl
15766:
15767:
15768: Inputs:
15769:
15770: filterlist - anonymous array of fields to include as potential filters
15771:
15772: crstype - course type
15773:
15774: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15775: to pop-open a course selector (will contain "extra element").
15776:
15777: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15778:
15779: filter - anonymous hash of criteria and their values
15780:
15781: action - form action
15782:
15783: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15784:
15785: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
15786:
15787: cloneruname - username of owner of new course who wants to clone
15788:
15789: clonerudom - domain of owner of new course who wants to clone
15790:
15791: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15792:
15793: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15794:
15795: codedom - domain
15796:
15797: formname - value of form element named "form".
15798:
15799: fixeddom - domain, if fixed.
15800:
15801: prevphase - value to assign to form element named "phase" when going back to the previous screen
15802:
15803: cnameelement - name of form element in form on opener page which will receive title of selected course
15804:
15805: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15806:
15807: cdomelement - name of form element in form on opener page which will receive domain of selected course
15808:
15809: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15810:
15811: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
15812:
15813: clonewarning - warning message about missing information for intended course owner when DC creates a course
15814:
15815:
15816: Returns: $output - HTML for display of search criteria, and hidden form elements.
15817:
15818:
15819: Side Effects: None
15820:
15821: =cut
15822:
15823: # ---------------------------------------------- search for courses based on last activity etc.
15824:
15825: sub build_filters {
15826: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
15827: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
15828: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
15829: $cnameelement,$cnumelement,$cdomelement,$setroles,
15830: $clonetext,$clonewarning) = @_;
15831: my ($list,$jscript);
15832: my $onchange = 'javascript:updateFilters(this)';
15833: my ($domainselectform,$sincefilterform,$createdfilterform,
15834: $ownerdomselectform,$persondomselectform,$instcodeform,
15835: $typeselectform,$instcodetitle);
15836: if ($formname eq '') {
15837: $formname = $caller;
15838: }
15839: foreach my $item (@{$filterlist}) {
15840: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
15841: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
15842: if ($item eq 'domainfilter') {
15843: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
15844: } elsif ($item eq 'coursefilter') {
15845: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
15846: } elsif ($item eq 'ownerfilter') {
15847: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15848: } elsif ($item eq 'ownerdomfilter') {
15849: $filter->{'ownerdomfilter'} =
15850: &LONCAPA::clean_domain($filter->{$item});
15851: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
15852: 'ownerdomfilter',1);
15853: } elsif ($item eq 'personfilter') {
15854: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15855: } elsif ($item eq 'persondomfilter') {
15856: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
15857: 'persondomfilter',1);
15858: } else {
15859: $filter->{$item} =~ s/\W//g;
15860: }
15861: if (!$filter->{$item}) {
15862: $filter->{$item} = '';
15863: }
15864: }
15865: if ($item eq 'domainfilter') {
15866: my $allow_blank = 1;
15867: if ($formname eq 'portform') {
15868: $allow_blank=0;
15869: } elsif ($formname eq 'studentform') {
15870: $allow_blank=0;
15871: }
15872: if ($fixeddom) {
15873: $domainselectform = '<input type="hidden" name="domainfilter"'.
15874: ' value="'.$codedom.'" />'.
15875: &Apache::lonnet::domain($codedom,'description');
15876: } else {
15877: $domainselectform = &select_dom_form($filter->{$item},
15878: 'domainfilter',
15879: $allow_blank,'',$onchange);
15880: }
15881: } else {
15882: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
15883: }
15884: }
15885:
15886: # last course activity filter and selection
15887: $sincefilterform = &timebased_select_form('sincefilter',$filter);
15888:
15889: # course created filter and selection
15890: if (exists($filter->{'createdfilter'})) {
15891: $createdfilterform = &timebased_select_form('createdfilter',$filter);
15892: }
15893:
15894: my %lt = &Apache::lonlocal::texthash(
15895: 'cac' => "$crstype Activity",
15896: 'ccr' => "$crstype Created",
15897: 'cde' => "$crstype Title",
15898: 'cdo' => "$crstype Domain",
15899: 'ins' => 'Institutional Code',
15900: 'inc' => 'Institutional Categorization',
15901: 'cow' => "$crstype Owner/Co-owner",
15902: 'cop' => "$crstype Personnel Includes",
15903: 'cog' => 'Type',
15904: );
15905:
15906: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15907: my $typeval = 'Course';
15908: if ($crstype eq 'Community') {
15909: $typeval = 'Community';
15910: }
15911: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
15912: } else {
15913: $typeselectform = '<select name="type" size="1"';
15914: if ($onchange) {
15915: $typeselectform .= ' onchange="'.$onchange.'"';
15916: }
15917: $typeselectform .= '>'."\n";
15918: foreach my $posstype ('Course','Community') {
15919: $typeselectform.='<option value="'.$posstype.'"'.
15920: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
15921: }
15922: $typeselectform.="</select>";
15923: }
15924:
15925: my ($cloneableonlyform,$cloneabletitle);
15926: if (exists($filter->{'cloneableonly'})) {
15927: my $cloneableon = '';
15928: my $cloneableoff = ' checked="checked"';
15929: if ($filter->{'cloneableonly'}) {
15930: $cloneableon = $cloneableoff;
15931: $cloneableoff = '';
15932: }
15933: $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>';
15934: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 15935: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 15936: } else {
15937: $cloneabletitle = &mt('Cloneable by you');
15938: }
15939: }
15940: my $officialjs;
15941: if ($crstype eq 'Course') {
15942: if (exists($filter->{'instcodefilter'})) {
15943: # if (($fixeddom) || ($formname eq 'requestcrs') ||
15944: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
15945: if ($codedom) {
15946: $officialjs = 1;
15947: ($instcodeform,$jscript,$$numtitlesref) =
15948: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
15949: $officialjs,$codetitlesref);
15950: if ($jscript) {
15951: $jscript = '<script type="text/javascript">'."\n".
15952: '// <![CDATA['."\n".
15953: $jscript."\n".
15954: '// ]]>'."\n".
15955: '</script>'."\n";
15956: }
15957: }
15958: if ($instcodeform eq '') {
15959: $instcodeform =
15960: '<input type="text" name="instcodefilter" size="10" value="'.
15961: $list->{'instcodefilter'}.'" />';
15962: $instcodetitle = $lt{'ins'};
15963: } else {
15964: $instcodetitle = $lt{'inc'};
15965: }
15966: if ($fixeddom) {
15967: $instcodetitle .= '<br />('.$codedom.')';
15968: }
15969: }
15970: }
15971: my $output = qq|
15972: <form method="post" name="filterpicker" action="$action">
15973: <input type="hidden" name="form" value="$formname" />
15974: |;
15975: if ($formname eq 'modifycourse') {
15976: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
15977: '<input type="hidden" name="prevphase" value="'.
15978: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 15979: } elsif ($formname eq 'quotacheck') {
15980: $output .= qq|
15981: <input type="hidden" name="sortby" value="" />
15982: <input type="hidden" name="sortorder" value="" />
15983: |;
15984: } else {
1.1075.2.69 raeburn 15985: my $name_input;
15986: if ($cnameelement ne '') {
15987: $name_input = '<input type="hidden" name="cnameelement" value="'.
15988: $cnameelement.'" />';
15989: }
15990: $output .= qq|
15991: <input type="hidden" name="cnumelement" value="$cnumelement" />
15992: <input type="hidden" name="cdomelement" value="$cdomelement" />
15993: $name_input
15994: $roleelement
15995: $multelement
15996: $typeelement
15997: |;
15998: if ($formname eq 'portform') {
15999: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16000: }
16001: }
16002: if ($fixeddom) {
16003: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16004: }
16005: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16006: if ($sincefilterform) {
16007: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16008: .$sincefilterform
16009: .&Apache::lonhtmlcommon::row_closure();
16010: }
16011: if ($createdfilterform) {
16012: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16013: .$createdfilterform
16014: .&Apache::lonhtmlcommon::row_closure();
16015: }
16016: if ($domainselectform) {
16017: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16018: .$domainselectform
16019: .&Apache::lonhtmlcommon::row_closure();
16020: }
16021: if ($typeselectform) {
16022: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16023: $output .= $typeselectform;
16024: } else {
16025: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16026: .$typeselectform
16027: .&Apache::lonhtmlcommon::row_closure();
16028: }
16029: }
16030: if ($instcodeform) {
16031: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16032: .$instcodeform
16033: .&Apache::lonhtmlcommon::row_closure();
16034: }
16035: if (exists($filter->{'ownerfilter'})) {
16036: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16037: '<table><tr><td>'.&mt('Username').'<br />'.
16038: '<input type="text" name="ownerfilter" size="20" value="'.
16039: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16040: $ownerdomselectform.'</td></tr></table>'.
16041: &Apache::lonhtmlcommon::row_closure();
16042: }
16043: if (exists($filter->{'personfilter'})) {
16044: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16045: '<table><tr><td>'.&mt('Username').'<br />'.
16046: '<input type="text" name="personfilter" size="20" value="'.
16047: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16048: $persondomselectform.'</td></tr></table>'.
16049: &Apache::lonhtmlcommon::row_closure();
16050: }
16051: if (exists($filter->{'coursefilter'})) {
16052: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16053: .'<input type="text" name="coursefilter" size="25" value="'
16054: .$list->{'coursefilter'}.'" />'
16055: .&Apache::lonhtmlcommon::row_closure();
16056: }
16057: if ($cloneableonlyform) {
16058: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16059: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16060: }
16061: if (exists($filter->{'descriptfilter'})) {
16062: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16063: .'<input type="text" name="descriptfilter" size="40" value="'
16064: .$list->{'descriptfilter'}.'" />'
16065: .&Apache::lonhtmlcommon::row_closure(1);
16066: }
16067: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16068: '<input type="hidden" name="updater" value="" />'."\n".
16069: '<input type="submit" name="gosearch" value="'.
16070: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16071: return $jscript.$clonewarning.$output;
16072: }
16073:
16074: =pod
16075:
16076: =item * &timebased_select_form()
16077:
16078: Create markup for a dropdown list used to select a time-based
16079: filter e.g., Course Activity, Course Created, when searching for courses
16080: or communities
16081:
16082: Inputs:
16083:
16084: item - name of form element (sincefilter or createdfilter)
16085:
16086: filter - anonymous hash of criteria and their values
16087:
16088: Returns: HTML for a select box contained a blank, then six time selections,
16089: with value set in incoming form variables currently selected.
16090:
16091: Side Effects: None
16092:
16093: =cut
16094:
16095: sub timebased_select_form {
16096: my ($item,$filter) = @_;
16097: if (ref($filter) eq 'HASH') {
16098: $filter->{$item} =~ s/[^\d-]//g;
16099: if (!$filter->{$item}) { $filter->{$item}=-1; }
16100: return &select_form(
16101: $filter->{$item},
16102: $item,
16103: { '-1' => '',
16104: '86400' => &mt('today'),
16105: '604800' => &mt('last week'),
16106: '2592000' => &mt('last month'),
16107: '7776000' => &mt('last three months'),
16108: '15552000' => &mt('last six months'),
16109: '31104000' => &mt('last year'),
16110: 'select_form_order' =>
16111: ['-1','86400','604800','2592000','7776000',
16112: '15552000','31104000']});
16113: }
16114: }
16115:
16116: =pod
16117:
16118: =item * &js_changer()
16119:
16120: Create script tag containing Javascript used to submit course search form
16121: when course type or domain is changed, and also to hide 'Searching ...' on
16122: page load completion for page showing search result.
16123:
16124: Inputs: None
16125:
16126: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16127:
16128: Side Effects: None
16129:
16130: =cut
16131:
16132: sub js_changer {
16133: return <<ENDJS;
16134: <script type="text/javascript">
16135: // <![CDATA[
16136: function updateFilters(caller) {
16137: if (typeof(caller) != "undefined") {
16138: document.filterpicker.updater.value = caller.name;
16139: }
16140: document.filterpicker.submit();
16141: }
16142:
16143: function hideSearching() {
16144: if (document.getElementById('searching')) {
16145: document.getElementById('searching').style.display = 'none';
16146: }
16147: return;
16148: }
16149:
16150: // ]]>
16151: </script>
16152:
16153: ENDJS
16154: }
16155:
16156: =pod
16157:
16158: =item * &search_courses()
16159:
16160: Process selected filters form course search form and pass to lonnet::courseiddump
16161: to retrieve a hash for which keys are courseIDs which match the selected filters.
16162:
16163: Inputs:
16164:
16165: dom - domain being searched
16166:
16167: type - course type ('Course' or 'Community' or '.' if any).
16168:
16169: filter - anonymous hash of criteria and their values
16170:
16171: numtitles - for institutional codes - number of categories
16172:
16173: cloneruname - optional username of new course owner
16174:
16175: clonerudom - optional domain of new course owner
16176:
1.1075.2.95 raeburn 16177: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16178: (used when DC is using course creation form)
16179:
16180: codetitles - reference to array of titles of components in institutional codes (official courses).
16181:
1.1075.2.95 raeburn 16182: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16183: (and so can clone automatically)
16184:
16185: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16186:
16187: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16188: courses to clone
1.1075.2.69 raeburn 16189:
16190: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16191:
16192:
16193: Side Effects: None
16194:
16195: =cut
16196:
16197:
16198: sub search_courses {
1.1075.2.95 raeburn 16199: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16200: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16201: my (%courses,%showcourses,$cloner);
16202: if (($filter->{'ownerfilter'} ne '') ||
16203: ($filter->{'ownerdomfilter'} ne '')) {
16204: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16205: $filter->{'ownerdomfilter'};
16206: }
16207: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16208: if (!$filter->{$item}) {
16209: $filter->{$item}='.';
16210: }
16211: }
16212: my $now = time;
16213: my $timefilter =
16214: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16215: my ($createdbefore,$createdafter);
16216: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16217: $createdbefore = $now;
16218: $createdafter = $now-$filter->{'createdfilter'};
16219: }
16220: my ($instcodefilter,$regexpok);
16221: if ($numtitles) {
16222: if ($env{'form.official'} eq 'on') {
16223: $instcodefilter =
16224: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16225: $regexpok = 1;
16226: } elsif ($env{'form.official'} eq 'off') {
16227: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16228: unless ($instcodefilter eq '') {
16229: $regexpok = -1;
16230: }
16231: }
16232: } else {
16233: $instcodefilter = $filter->{'instcodefilter'};
16234: }
16235: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16236: if ($type eq '') { $type = '.'; }
16237:
16238: if (($clonerudom ne '') && ($cloneruname ne '')) {
16239: $cloner = $cloneruname.':'.$clonerudom;
16240: }
16241: %courses = &Apache::lonnet::courseiddump($dom,
16242: $filter->{'descriptfilter'},
16243: $timefilter,
16244: $instcodefilter,
16245: $filter->{'combownerfilter'},
16246: $filter->{'coursefilter'},
16247: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16248: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16249: $filter->{'cloneableonly'},
16250: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16251: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16252: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16253: my $ccrole;
16254: if ($type eq 'Community') {
16255: $ccrole = 'co';
16256: } else {
16257: $ccrole = 'cc';
16258: }
16259: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16260: $filter->{'persondomfilter'},
16261: 'userroles',undef,
16262: [$ccrole,'in','ad','ep','ta','cr'],
16263: $dom);
16264: foreach my $role (keys(%rolehash)) {
16265: my ($cnum,$cdom,$courserole) = split(':',$role);
16266: my $cid = $cdom.'_'.$cnum;
16267: if (exists($courses{$cid})) {
16268: if (ref($courses{$cid}) eq 'HASH') {
16269: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16270: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16271: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16272: }
16273: } else {
16274: $courses{$cid}{roles} = [$courserole];
16275: }
16276: $showcourses{$cid} = $courses{$cid};
16277: }
16278: }
16279: }
16280: %courses = %showcourses;
16281: }
16282: return %courses;
16283: }
16284:
16285: =pod
16286:
16287: =back
16288:
1.1075.2.88 raeburn 16289: =head1 Routines for version requirements for current course.
16290:
16291: =over 4
16292:
16293: =item * &check_release_required()
16294:
16295: Compares required LON-CAPA version with version on server, and
16296: if required version is newer looks for a server with the required version.
16297:
16298: Looks first at servers in user's owen domain; if none suitable, looks at
16299: servers in course's domain are permitted to host sessions for user's domain.
16300:
16301: Inputs:
16302:
16303: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16304:
16305: $courseid - Course ID of current course
16306:
16307: $rolecode - User's current role in course (for switchserver query string).
16308:
16309: $required - LON-CAPA version needed by course (format: Major.Minor).
16310:
16311:
16312: Returns:
16313:
16314: $switchserver - query string tp append to /adm/switchserver call (if
16315: current server's LON-CAPA version is too old.
16316:
16317: $warning - Message is displayed if no suitable server could be found.
16318:
16319: =cut
16320:
16321: sub check_release_required {
16322: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16323: my ($switchserver,$warning);
16324: if ($required ne '') {
16325: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16326: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16327: if ($reqdmajor ne '' && $reqdminor ne '') {
16328: my $otherserver;
16329: if (($major eq '' && $minor eq '') ||
16330: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16331: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16332: my $switchlcrev =
16333: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16334: $userdomserver);
16335: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16336: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16337: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16338: my $cdom = $env{'course.'.$courseid.'.domain'};
16339: if ($cdom ne $env{'user.domain'}) {
16340: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16341: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16342: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16343: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16344: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16345: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16346: my $canhost =
16347: &Apache::lonnet::can_host_session($env{'user.domain'},
16348: $coursedomserver,
16349: $remoterev,
16350: $udomdefaults{'remotesessions'},
16351: $defdomdefaults{'hostedsessions'});
16352:
16353: if ($canhost) {
16354: $otherserver = $coursedomserver;
16355: } else {
16356: $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.");
16357: }
16358: } else {
16359: $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).");
16360: }
16361: } else {
16362: $otherserver = $userdomserver;
16363: }
16364: }
16365: if ($otherserver ne '') {
16366: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16367: }
16368: }
16369: }
16370: return ($switchserver,$warning);
16371: }
16372:
16373: =pod
16374:
16375: =item * &check_release_result()
16376:
16377: Inputs:
16378:
16379: $switchwarning - Warning message if no suitable server found to host session.
16380:
16381: $switchserver - query string to append to /adm/switchserver containing lonHostID
16382: and current role.
16383:
16384: Returns: HTML to display with information about requirement to switch server.
16385: Either displaying warning with link to Roles/Courses screen or
16386: display link to switchserver.
16387:
1.1075.2.69 raeburn 16388: =cut
16389:
1.1075.2.88 raeburn 16390: sub check_release_result {
16391: my ($switchwarning,$switchserver) = @_;
16392: my $output = &start_page('Selected course unavailable on this server').
16393: '<p class="LC_warning">';
16394: if ($switchwarning) {
16395: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16396: if (&show_course()) {
16397: $output .= &mt('Display courses');
16398: } else {
16399: $output .= &mt('Display roles');
16400: }
16401: $output .= '</a>';
16402: } elsif ($switchserver) {
16403: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16404: '<br />'.
16405: '<a href="/adm/switchserver?'.$switchserver.'">'.
16406: &mt('Switch Server').
16407: '</a>';
16408: }
16409: $output .= '</p>'.&end_page();
16410: return $output;
16411: }
16412:
16413: =pod
16414:
16415: =item * &needs_coursereinit()
16416:
16417: Determine if course contents stored for user's session needs to be
16418: refreshed, because content has changed since "Big Hash" last tied.
16419:
16420: Check for change is made if time last checked is more than 10 minutes ago
16421: (by default).
16422:
16423: Inputs:
16424:
16425: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16426:
16427: $interval (optional) - Time which may elapse (in s) between last check for content
16428: change in current course. (default: 600 s).
16429:
16430: Returns: an array; first element is:
16431:
16432: =over 4
16433:
16434: 'switch' - if content updates mean user's session
16435: needs to be switched to a server running a newer LON-CAPA version
16436:
16437: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16438: on current server hosting user's session
16439:
16440: '' - if no action required.
16441:
16442: =back
16443:
16444: If first item element is 'switch':
16445:
16446: second item is $switchwarning - Warning message if no suitable server found to host session.
16447:
16448: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16449: and current role.
16450:
16451: otherwise: no other elements returned.
16452:
16453: =back
16454:
16455: =cut
16456:
16457: sub needs_coursereinit {
16458: my ($loncaparev,$interval) = @_;
16459: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16460: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16461: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16462: my $now = time;
16463: if ($interval eq '') {
16464: $interval = 600;
16465: }
16466: if (($now-$env{'request.course.timechecked'})>$interval) {
16467: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16468: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16469: if ($lastchange > $env{'request.course.tied'}) {
16470: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16471: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16472: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16473: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16474: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16475: $curr_reqd_hash{'internal.releaserequired'}});
16476: my ($switchserver,$switchwarning) =
16477: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16478: $curr_reqd_hash{'internal.releaserequired'});
16479: if ($switchwarning ne '' || $switchserver ne '') {
16480: return ('switch',$switchwarning,$switchserver);
16481: }
16482: }
16483: }
16484: return ('update');
16485: }
16486: }
16487: return ();
16488: }
1.1075.2.69 raeburn 16489:
1.1075.2.11 raeburn 16490: sub update_content_constraints {
16491: my ($cdom,$cnum,$chome,$cid) = @_;
16492: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16493: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16494: my %checkresponsetypes;
16495: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
16496: my ($item,$name,$value) = split(/:/,$key);
16497: if ($item eq 'resourcetag') {
16498: if ($name eq 'responsetype') {
16499: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16500: }
16501: }
16502: }
16503: my $navmap = Apache::lonnavmaps::navmap->new();
16504: if (defined($navmap)) {
16505: my %allresponses;
16506: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16507: my %responses = $res->responseTypes();
16508: foreach my $key (keys(%responses)) {
16509: next unless(exists($checkresponsetypes{$key}));
16510: $allresponses{$key} += $responses{$key};
16511: }
16512: }
16513: foreach my $key (keys(%allresponses)) {
16514: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16515: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16516: ($reqdmajor,$reqdminor) = ($major,$minor);
16517: }
16518: }
16519: undef($navmap);
16520: }
16521: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16522: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16523: }
16524: return;
16525: }
16526:
1.1075.2.27 raeburn 16527: sub allmaps_incourse {
16528: my ($cdom,$cnum,$chome,$cid) = @_;
16529: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16530: $cid = $env{'request.course.id'};
16531: $cdom = $env{'course.'.$cid.'.domain'};
16532: $cnum = $env{'course.'.$cid.'.num'};
16533: $chome = $env{'course.'.$cid.'.home'};
16534: }
16535: my %allmaps = ();
16536: my $lastchange =
16537: &Apache::lonnet::get_coursechange($cdom,$cnum);
16538: if ($lastchange > $env{'request.course.tied'}) {
16539: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16540: unless ($ferr) {
16541: &update_content_constraints($cdom,$cnum,$chome,$cid);
16542: }
16543: }
16544: my $navmap = Apache::lonnavmaps::navmap->new();
16545: if (defined($navmap)) {
16546: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16547: $allmaps{$res->src()} = 1;
16548: }
16549: }
16550: return \%allmaps;
16551: }
16552:
1.1075.2.11 raeburn 16553: sub parse_supplemental_title {
16554: my ($title) = @_;
16555:
16556: my ($foldertitle,$renametitle);
16557: if ($title =~ /&&&/) {
16558: $title = &HTML::Entites::decode($title);
16559: }
16560: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16561: $renametitle=$4;
16562: my ($time,$uname,$udom) = ($1,$2,$3);
16563: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16564: my $name = &plainname($uname,$udom);
16565: $name = &HTML::Entities::encode($name,'"<>&\'');
16566: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16567: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16568: $name.': <br />'.$foldertitle;
16569: }
16570: if (wantarray) {
16571: return ($title,$foldertitle,$renametitle);
16572: }
16573: return $title;
16574: }
16575:
1.1075.2.43 raeburn 16576: sub recurse_supplemental {
16577: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16578: if ($suppmap) {
16579: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16580: if ($fatal) {
16581: $errors ++;
16582: } else {
16583: if ($#LONCAPA::map::resources > 0) {
16584: foreach my $res (@LONCAPA::map::resources) {
16585: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16586: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 16587: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16588: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 16589: } else {
16590: $numfiles ++;
16591: }
16592: }
16593: }
16594: }
16595: }
16596: }
16597: return ($numfiles,$errors);
16598: }
16599:
1.1075.2.18 raeburn 16600: sub symb_to_docspath {
1.1075.2.119 raeburn 16601: my ($symb,$navmapref) = @_;
16602: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 16603: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16604: if ($resurl=~/\.(sequence|page)$/) {
16605: $mapurl=$resurl;
16606: } elsif ($resurl eq 'adm/navmaps') {
16607: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16608: }
16609: my $mapresobj;
1.1075.2.119 raeburn 16610: unless (ref($$navmapref)) {
16611: $$navmapref = Apache::lonnavmaps::navmap->new();
16612: }
16613: if (ref($$navmapref)) {
16614: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 16615: }
16616: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16617: my $type=$2;
16618: my $path;
16619: if (ref($mapresobj)) {
16620: my $pcslist = $mapresobj->map_hierarchy();
16621: if ($pcslist ne '') {
16622: foreach my $pc (split(/,/,$pcslist)) {
16623: next if ($pc <= 1);
1.1075.2.119 raeburn 16624: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 16625: if (ref($res)) {
16626: my $thisurl = $res->src();
16627: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16628: my $thistitle = $res->title();
16629: $path .= '&'.
16630: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 16631: &escape($thistitle).
1.1075.2.18 raeburn 16632: ':'.$res->randompick().
16633: ':'.$res->randomout().
16634: ':'.$res->encrypted().
16635: ':'.$res->randomorder().
16636: ':'.$res->is_page();
16637: }
16638: }
16639: }
16640: $path =~ s/^\&//;
16641: my $maptitle = $mapresobj->title();
16642: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16643: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16644: }
16645: $path .= (($path ne '')? '&' : '').
16646: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16647: &escape($maptitle).
1.1075.2.18 raeburn 16648: ':'.$mapresobj->randompick().
16649: ':'.$mapresobj->randomout().
16650: ':'.$mapresobj->encrypted().
16651: ':'.$mapresobj->randomorder().
16652: ':'.$mapresobj->is_page();
16653: } else {
16654: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16655: my $ispage = (($type eq 'page')? 1 : '');
16656: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16657: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16658: }
16659: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16660: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 16661: }
16662: unless ($mapurl eq 'default') {
16663: $path = 'default&'.
1.1075.2.46 raeburn 16664: &escape('Main Content').
1.1075.2.18 raeburn 16665: ':::::&'.$path;
16666: }
16667: return $path;
16668: }
16669:
1.1075.2.14 raeburn 16670: sub captcha_display {
16671: my ($context,$lonhost) = @_;
16672: my ($output,$error);
1.1075.2.107 raeburn 16673: my ($captcha,$pubkey,$privkey,$version) =
16674: &get_captcha_config($context,$lonhost);
1.1075.2.14 raeburn 16675: if ($captcha eq 'original') {
16676: $output = &create_captcha();
16677: unless ($output) {
16678: $error = 'captcha';
16679: }
16680: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16681: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 16682: unless ($output) {
16683: $error = 'recaptcha';
16684: }
16685: }
1.1075.2.107 raeburn 16686: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 16687: }
16688:
16689: sub captcha_response {
16690: my ($context,$lonhost) = @_;
16691: my ($captcha_chk,$captcha_error);
1.1075.2.109 raeburn 16692: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1075.2.14 raeburn 16693: if ($captcha eq 'original') {
16694: ($captcha_chk,$captcha_error) = &check_captcha();
16695: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16696: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 16697: } else {
16698: $captcha_chk = 1;
16699: }
16700: return ($captcha_chk,$captcha_error);
16701: }
16702:
16703: sub get_captcha_config {
16704: my ($context,$lonhost) = @_;
1.1075.2.107 raeburn 16705: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 16706: my $hostname = &Apache::lonnet::hostname($lonhost);
16707: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16708: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16709: if ($context eq 'usercreation') {
16710: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16711: if (ref($domconfig{$context}) eq 'HASH') {
16712: $hashtocheck = $domconfig{$context}{'cancreate'};
16713: if (ref($hashtocheck) eq 'HASH') {
16714: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16715: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16716: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16717: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16718: }
16719: if ($privkey && $pubkey) {
16720: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16721: $version = $hashtocheck->{'recaptchaversion'};
16722: if ($version ne '2') {
16723: $version = 1;
16724: }
1.1075.2.14 raeburn 16725: } else {
16726: $captcha = 'original';
16727: }
16728: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16729: $captcha = 'original';
16730: }
16731: }
16732: } else {
16733: $captcha = 'captcha';
16734: }
16735: } elsif ($context eq 'login') {
16736: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16737: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16738: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16739: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
16740: if ($privkey && $pubkey) {
16741: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16742: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
16743: if ($version ne '2') {
16744: $version = 1;
16745: }
1.1075.2.14 raeburn 16746: } else {
16747: $captcha = 'original';
16748: }
16749: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16750: $captcha = 'original';
16751: }
16752: }
1.1075.2.107 raeburn 16753: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 16754: }
16755:
16756: sub create_captcha {
16757: my %captcha_params = &captcha_settings();
16758: my ($output,$maxtries,$tries) = ('',10,0);
16759: while ($tries < $maxtries) {
16760: $tries ++;
16761: my $captcha = Authen::Captcha->new (
16762: output_folder => $captcha_params{'output_dir'},
16763: data_folder => $captcha_params{'db_dir'},
16764: );
16765: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
16766:
16767: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
16768: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
16769: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 16770: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
16771: '<br />'.
16772: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 16773: last;
16774: }
16775: }
16776: return $output;
16777: }
16778:
16779: sub captcha_settings {
16780: my %captcha_params = (
16781: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
16782: www_output_dir => "/captchaspool",
16783: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16784: numchars => '5',
16785: );
16786: return %captcha_params;
16787: }
16788:
16789: sub check_captcha {
16790: my ($captcha_chk,$captcha_error);
16791: my $code = $env{'form.code'};
16792: my $md5sum = $env{'form.crypt'};
16793: my %captcha_params = &captcha_settings();
16794: my $captcha = Authen::Captcha->new(
16795: output_folder => $captcha_params{'output_dir'},
16796: data_folder => $captcha_params{'db_dir'},
16797: );
1.1075.2.26 raeburn 16798: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 16799: my %captcha_hash = (
16800: 0 => 'Code not checked (file error)',
16801: -1 => 'Failed: code expired',
16802: -2 => 'Failed: invalid code (not in database)',
16803: -3 => 'Failed: invalid code (code does not match crypt)',
16804: );
16805: if ($captcha_chk != 1) {
16806: $captcha_error = $captcha_hash{$captcha_chk}
16807: }
16808: return ($captcha_chk,$captcha_error);
16809: }
16810:
16811: sub create_recaptcha {
1.1075.2.107 raeburn 16812: my ($pubkey,$version) = @_;
16813: if ($version >= 2) {
16814: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
16815: } else {
16816: my $use_ssl;
16817: if ($ENV{'SERVER_PORT'} == 443) {
16818: $use_ssl = 1;
16819: }
16820: my $captcha = Captcha::reCAPTCHA->new;
16821: return $captcha->get_options_setter({theme => 'white'})."\n".
16822: $captcha->get_html($pubkey,undef,$use_ssl).
16823: &mt('If the text is hard to read, [_1] will replace them.',
16824: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
16825: '<br /><br />';
16826: }
1.1075.2.14 raeburn 16827: }
16828:
16829: sub check_recaptcha {
1.1075.2.107 raeburn 16830: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 16831: my $captcha_chk;
1.1075.2.107 raeburn 16832: if ($version >= 2) {
16833: my $ua = LWP::UserAgent->new;
16834: $ua->timeout(10);
16835: my %info = (
16836: secret => $privkey,
16837: response => $env{'form.g-recaptcha-response'},
16838: remoteip => $ENV{'REMOTE_ADDR'},
16839: );
16840: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
16841: if ($response->is_success) {
16842: my $data = JSON::DWIW->from_json($response->decoded_content);
16843: if (ref($data) eq 'HASH') {
16844: if ($data->{'success'}) {
16845: $captcha_chk = 1;
16846: }
16847: }
16848: }
16849: } else {
16850: my $captcha = Captcha::reCAPTCHA->new;
16851: my $captcha_result =
16852: $captcha->check_answer(
16853: $privkey,
16854: $ENV{'REMOTE_ADDR'},
16855: $env{'form.recaptcha_challenge_field'},
16856: $env{'form.recaptcha_response_field'},
16857: );
16858: if ($captcha_result->{is_valid}) {
16859: $captcha_chk = 1;
16860: }
1.1075.2.14 raeburn 16861: }
16862: return $captcha_chk;
16863: }
16864:
1.1075.2.64 raeburn 16865: sub emailusername_info {
1.1075.2.103 raeburn 16866: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 16867: my %titles = &Apache::lonlocal::texthash (
16868: lastname => 'Last Name',
16869: firstname => 'First Name',
16870: institution => 'School/college/university',
16871: location => "School's city, state/province, country",
16872: web => "School's web address",
16873: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 16874: id => 'Student/Employee ID',
1.1075.2.64 raeburn 16875: );
16876: return (\@fields,\%titles);
16877: }
16878:
1.1075.2.56 raeburn 16879: sub cleanup_html {
16880: my ($incoming) = @_;
16881: my $outgoing;
16882: if ($incoming ne '') {
16883: $outgoing = $incoming;
16884: $outgoing =~ s/;/;/g;
16885: $outgoing =~ s/\#/#/g;
16886: $outgoing =~ s/\&/&/g;
16887: $outgoing =~ s/</</g;
16888: $outgoing =~ s/>/>/g;
16889: $outgoing =~ s/\(/(/g;
16890: $outgoing =~ s/\)/)/g;
16891: $outgoing =~ s/"/"/g;
16892: $outgoing =~ s/'/'/g;
16893: $outgoing =~ s/\$/$/g;
16894: $outgoing =~ s{/}{/}g;
16895: $outgoing =~ s/=/=/g;
16896: $outgoing =~ s/\\/\/g
16897: }
16898: return $outgoing;
16899: }
16900:
1.1075.2.74 raeburn 16901: # Checks for critical messages and returns a redirect url if one exists.
16902: # $interval indicates how often to check for messages.
16903: sub critical_redirect {
16904: my ($interval) = @_;
16905: if ((time-$env{'user.criticalcheck.time'})>$interval) {
16906: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
16907: $env{'user.name'});
16908: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
16909: my $redirecturl;
16910: if ($what[0]) {
16911: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
16912: $redirecturl='/adm/email?critical=display';
16913: my $url=&Apache::lonnet::absolute_url().$redirecturl;
16914: return (1, $url);
16915: }
16916: }
16917: }
16918: return ();
16919: }
16920:
1.1075.2.64 raeburn 16921: # Use:
16922: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
16923: #
16924: ##################################################
16925: # password associated functions #
16926: ##################################################
16927: sub des_keys {
16928: # Make a new key for DES encryption.
16929: # Each key has two parts which are returned separately.
16930: # Please note: Each key must be passed through the &hex function
16931: # before it is output to the web browser. The hex versions cannot
16932: # be used to decrypt.
16933: my @hexstr=('0','1','2','3','4','5','6','7',
16934: '8','9','a','b','c','d','e','f');
16935: my $lkey='';
16936: for (0..7) {
16937: $lkey.=$hexstr[rand(15)];
16938: }
16939: my $ukey='';
16940: for (0..7) {
16941: $ukey.=$hexstr[rand(15)];
16942: }
16943: return ($lkey,$ukey);
16944: }
16945:
16946: sub des_decrypt {
16947: my ($key,$cyphertext) = @_;
16948: my $keybin=pack("H16",$key);
16949: my $cypher;
16950: if ($Crypt::DES::VERSION>=2.03) {
16951: $cypher=new Crypt::DES $keybin;
16952: } else {
16953: $cypher=new DES $keybin;
16954: }
1.1075.2.106 raeburn 16955: my $plaintext='';
16956: my $cypherlength = length($cyphertext);
16957: my $numchunks = int($cypherlength/32);
16958: for (my $j=0; $j<$numchunks; $j++) {
16959: my $start = $j*32;
16960: my $cypherblock = substr($cyphertext,$start,32);
16961: my $chunk =
16962: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
16963: $chunk .=
16964: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
16965: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
16966: $plaintext .= $chunk;
16967: }
1.1075.2.64 raeburn 16968: return $plaintext;
16969: }
16970:
1.1075.2.135 raeburn 16971: sub is_nonframeable {
16972: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
16973: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
16974: return if (($remprotocol eq '') || ($remhost eq ''));
16975:
16976: $remprotocol = lc($remprotocol);
16977: $remhost = lc($remhost);
16978: my $remport = 80;
16979: if ($remprotocol eq 'https') {
16980: $remport = 443;
16981: }
16982: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
16983: if ($cached) {
16984: unless ($nocache) {
16985: if ($result) {
16986: return 1;
16987: } else {
16988: return 0;
16989: }
16990: }
16991: }
16992: my $uselink;
16993: my $request = new HTTP::Request('HEAD',$url);
16994: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
16995: if ($response->is_success()) {
16996: my $secpolicy = lc($response->header('content-security-policy'));
16997: my $xframeop = lc($response->header('x-frame-options'));
16998: $secpolicy =~ s/^\s+|\s+$//g;
16999: $xframeop =~ s/^\s+|\s+$//g;
17000: if (($secpolicy ne '') || ($xframeop ne '')) {
17001: my $remotehost = $remprotocol.'://'.$remhost;
17002: my ($origin,$protocol,$port);
17003: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
17004: $port = $ENV{'SERVER_PORT'};
17005: } else {
17006: $port = 80;
17007: }
17008: if ($absolute eq '') {
17009: $protocol = 'http:';
17010: if ($port == 443) {
17011: $protocol = 'https:';
17012: }
17013: $origin = $protocol.'//'.lc($hostname);
17014: } else {
17015: $origin = lc($absolute);
17016: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
17017: }
17018: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
17019: my $framepolicy = $1;
17020: $framepolicy =~ s/^\s+|\s+$//g;
17021: my @policies = split(/\s+/,$framepolicy);
17022: if (@policies) {
17023: if (grep(/^\Q'none'\E$/,@policies)) {
17024: $uselink = 1;
17025: } else {
17026: $uselink = 1;
17027: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
17028: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
17029: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
17030: undef($uselink);
17031: }
17032: if ($uselink) {
17033: if (grep(/^\Q'self'\E$/,@policies)) {
17034: if (($origin ne '') && ($remotehost eq $origin)) {
17035: undef($uselink);
17036: }
17037: }
17038: }
17039: if ($uselink) {
17040: my @possok;
17041: if ($ip ne '') {
17042: push(@possok,$ip);
17043: }
17044: my $hoststr = '';
17045: foreach my $part (reverse(split(/\./,$hostname))) {
17046: if ($hoststr eq '') {
17047: $hoststr = $part;
17048: } else {
17049: $hoststr = "$part.$hoststr";
17050: }
17051: if ($hoststr eq $hostname) {
17052: push(@possok,$hostname);
17053: } else {
17054: push(@possok,"*.$hoststr");
17055: }
17056: }
17057: if (@possok) {
17058: foreach my $poss (@possok) {
17059: last if (!$uselink);
17060: foreach my $policy (@policies) {
17061: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
17062: undef($uselink);
17063: last;
17064: }
17065: }
17066: }
17067: }
17068: }
17069: }
17070: }
17071: } elsif ($xframeop ne '') {
17072: $uselink = 1;
17073: my @policies = split(/\s*,\s*/,$xframeop);
17074: if (@policies) {
17075: unless (grep(/^deny$/,@policies)) {
17076: if ($origin ne '') {
17077: if (grep(/^sameorigin$/,@policies)) {
17078: if ($remotehost eq $origin) {
17079: undef($uselink);
17080: }
17081: }
17082: if ($uselink) {
17083: foreach my $policy (@policies) {
17084: if ($policy =~ /^allow-from\s*(.+)$/) {
17085: my $allowfrom = $1;
17086: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
17087: undef($uselink);
17088: last;
17089: }
17090: }
17091: }
17092: }
17093: }
17094: }
17095: }
17096: }
17097: }
17098: }
17099: if ($nocache) {
17100: if ($cached) {
17101: my $devalidate;
17102: if ($uselink && !$result) {
17103: $devalidate = 1;
17104: } elsif (!$uselink && $result) {
17105: $devalidate = 1;
17106: }
17107: if ($devalidate) {
17108: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
17109: }
17110: }
17111: } else {
17112: if ($uselink) {
17113: $result = 1;
17114: } else {
17115: $result = 0;
17116: }
17117: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
17118: }
17119: return $uselink;
17120: }
17121:
1.112 bowersj2 17122: 1;
17123: __END__;
1.41 ng 17124:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>