Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.137
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.137! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.136 2019/08/04 01:02:40 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.1075.2.137! raeburn 3174: sub check_passwd_rules {
! 3175: my ($domain,$plainpass) = @_;
! 3176: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
! 3177: my ($min,$max,@chars,@brokerule,$warning);
! 3178: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
! 3179: if ($passwdconf{'min'} =~ /^\d+$/) {
! 3180: $min = $passwdconf{'min'};
! 3181: }
! 3182: if ($passwdconf{'max'} =~ /^\d+$/) {
! 3183: $max = $passwdconf{'max'};
! 3184: }
! 3185: @chars = @{$passwdconf{'chars'}};
! 3186: } else {
! 3187: $min = 7;
! 3188: }
! 3189: if (($min) && (length($plainpass) < $min)) {
! 3190: push(@brokerule,'min');
! 3191: }
! 3192: if (($max) && (length($plainpass) > $max)) {
! 3193: push(@brokerule,'max');
! 3194: }
! 3195: if (@chars) {
! 3196: my %rules;
! 3197: map { $rules{$_} = 1; } @chars;
! 3198: if ($rules{'uc'}) {
! 3199: unless ($plainpass =~ /[A-Z]/) {
! 3200: push(@brokerule,'uc');
! 3201: }
! 3202: }
! 3203: if ($rules{'lc'}) {
! 3204: unless ($plainpass =~ /[a-z]/) {
! 3205: push(@brokerule,'lc');
! 3206: }
! 3207: }
! 3208: if ($rules{'num'}) {
! 3209: unless ($plainpass =~ /\d/) {
! 3210: push(@brokerule,'num');
! 3211: }
! 3212: }
! 3213: if ($rules{'spec'}) {
! 3214: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
! 3215: push(@brokerule,'spec');
! 3216: }
! 3217: }
! 3218: }
! 3219: if (@brokerule) {
! 3220: my %rulenames = &Apache::lonlocal::texthash(
! 3221: uc => 'At least one upper case letter',
! 3222: lc => 'At least one lower case letter',
! 3223: num => 'At least one number',
! 3224: spec => 'At least one non-alphanumeric',
! 3225: );
! 3226: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
! 3227: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
! 3228: $rulenames{'num'} .= ': 0123456789';
! 3229: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
! 3230: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
! 3231: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
! 3232: $warning = &mt('Password did not satisfy the following:').'<ul>';
! 3233: foreach my $rule ('min','max','uc','ls','num','spec') {
! 3234: if (grep(/^$rule$/,@brokerule)) {
! 3235: $warning .= '<li>'.$rulenames{$rule}.'</li>';
! 3236: }
! 3237: }
! 3238: $warning .= '</ul>';
! 3239: }
! 3240: if (wantarray) {
! 3241: return @brokerule;
! 3242: }
! 3243: return $warning;
! 3244: }
! 3245:
1.80 albertel 3246: ###############################################################
3247: ## Get Kerberos Defaults for Domain ##
3248: ###############################################################
3249: ##
3250: ## Returns default kerberos version and an associated argument
3251: ## as listed in file domain.tab. If not listed, provides
3252: ## appropriate default domain and kerberos version.
3253: ##
3254: #-------------------------------------------
3255:
3256: =pod
3257:
1.648 raeburn 3258: =item * &get_kerberos_defaults()
1.80 albertel 3259:
3260: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3261: version and domain. If not found, it defaults to version 4 and the
3262: domain of the server.
1.80 albertel 3263:
1.648 raeburn 3264: =over 4
3265:
1.80 albertel 3266: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3267:
1.648 raeburn 3268: =back
3269:
3270: =back
3271:
1.80 albertel 3272: =cut
3273:
3274: #-------------------------------------------
3275: sub get_kerberos_defaults {
3276: my $domain=shift;
1.641 raeburn 3277: my ($krbdef,$krbdefdom);
3278: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3279: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3280: $krbdef = $domdefaults{'auth_def'};
3281: $krbdefdom = $domdefaults{'auth_arg_def'};
3282: } else {
1.80 albertel 3283: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3284: my $krbdefdom=$1;
3285: $krbdefdom=~tr/a-z/A-Z/;
3286: $krbdef = "krb4";
3287: }
3288: return ($krbdef,$krbdefdom);
3289: }
1.112 bowersj2 3290:
1.32 matthew 3291:
1.46 matthew 3292: ###############################################################
3293: ## Thesaurus Functions ##
3294: ###############################################################
1.20 www 3295:
1.46 matthew 3296: =pod
1.20 www 3297:
1.112 bowersj2 3298: =head1 Thesaurus Functions
3299:
3300: =over 4
3301:
1.648 raeburn 3302: =item * &initialize_keywords()
1.46 matthew 3303:
3304: Initializes the package variable %Keywords if it is empty. Uses the
3305: package variable $thesaurus_db_file.
3306:
3307: =cut
3308:
3309: ###################################################
3310:
3311: sub initialize_keywords {
3312: return 1 if (scalar keys(%Keywords));
3313: # If we are here, %Keywords is empty, so fill it up
3314: # Make sure the file we need exists...
3315: if (! -e $thesaurus_db_file) {
3316: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3317: " failed because it does not exist");
3318: return 0;
3319: }
3320: # Set up the hash as a database
3321: my %thesaurus_db;
3322: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3323: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3324: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3325: $thesaurus_db_file);
3326: return 0;
3327: }
3328: # Get the average number of appearances of a word.
3329: my $avecount = $thesaurus_db{'average.count'};
3330: # Put keywords (those that appear > average) into %Keywords
3331: while (my ($word,$data)=each (%thesaurus_db)) {
3332: my ($count,undef) = split /:/,$data;
3333: $Keywords{$word}++ if ($count > $avecount);
3334: }
3335: untie %thesaurus_db;
3336: # Remove special values from %Keywords.
1.356 albertel 3337: foreach my $value ('total.count','average.count') {
3338: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3339: }
1.46 matthew 3340: return 1;
3341: }
3342:
3343: ###################################################
3344:
3345: =pod
3346:
1.648 raeburn 3347: =item * &keyword($word)
1.46 matthew 3348:
3349: Returns true if $word is a keyword. A keyword is a word that appears more
3350: than the average number of times in the thesaurus database. Calls
3351: &initialize_keywords
3352:
3353: =cut
3354:
3355: ###################################################
1.20 www 3356:
3357: sub keyword {
1.46 matthew 3358: return if (!&initialize_keywords());
3359: my $word=lc(shift());
3360: $word=~s/\W//g;
3361: return exists($Keywords{$word});
1.20 www 3362: }
1.46 matthew 3363:
3364: ###############################################################
3365:
3366: =pod
1.20 www 3367:
1.648 raeburn 3368: =item * &get_related_words()
1.46 matthew 3369:
1.160 matthew 3370: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3371: an array of words. If the keyword is not in the thesaurus, an empty array
3372: will be returned. The order of the words returned is determined by the
3373: database which holds them.
3374:
3375: Uses global $thesaurus_db_file.
3376:
1.1057 foxr 3377:
1.46 matthew 3378: =cut
3379:
3380: ###############################################################
3381: sub get_related_words {
3382: my $keyword = shift;
3383: my %thesaurus_db;
3384: if (! -e $thesaurus_db_file) {
3385: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3386: "failed because the file does not exist");
3387: return ();
3388: }
3389: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3390: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3391: return ();
3392: }
3393: my @Words=();
1.429 www 3394: my $count=0;
1.46 matthew 3395: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3396: # The first element is the number of times
3397: # the word appears. We do not need it now.
1.429 www 3398: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3399: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3400: my $threshold=$mostfrequentcount/10;
3401: foreach my $possibleword (@RelatedWords) {
3402: my ($word,$wordcount)=split(/\,/,$possibleword);
3403: if ($wordcount>$threshold) {
3404: push(@Words,$word);
3405: $count++;
3406: if ($count>10) { last; }
3407: }
1.20 www 3408: }
3409: }
1.46 matthew 3410: untie %thesaurus_db;
3411: return @Words;
1.14 harris41 3412: }
1.46 matthew 3413:
1.112 bowersj2 3414: =pod
3415:
3416: =back
3417:
3418: =cut
1.61 www 3419:
3420: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3421: =pod
3422:
1.112 bowersj2 3423: =head1 User Name Functions
3424:
3425: =over 4
3426:
1.648 raeburn 3427: =item * &plainname($uname,$udom,$first)
1.81 albertel 3428:
1.112 bowersj2 3429: Takes a users logon name and returns it as a string in
1.226 albertel 3430: "first middle last generation" form
3431: if $first is set to 'lastname' then it returns it as
3432: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3433:
3434: =cut
1.61 www 3435:
1.295 www 3436:
1.81 albertel 3437: ###############################################################
1.61 www 3438: sub plainname {
1.226 albertel 3439: my ($uname,$udom,$first)=@_;
1.537 albertel 3440: return if (!defined($uname) || !defined($udom));
1.295 www 3441: my %names=&getnames($uname,$udom);
1.226 albertel 3442: my $name=&Apache::lonnet::format_name($names{'firstname'},
3443: $names{'middlename'},
3444: $names{'lastname'},
3445: $names{'generation'},$first);
3446: $name=~s/^\s+//;
1.62 www 3447: $name=~s/\s+$//;
3448: $name=~s/\s+/ /g;
1.353 albertel 3449: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3450: return $name;
1.61 www 3451: }
1.66 www 3452:
3453: # -------------------------------------------------------------------- Nickname
1.81 albertel 3454: =pod
3455:
1.648 raeburn 3456: =item * &nickname($uname,$udom)
1.81 albertel 3457:
3458: Gets a users name and returns it as a string as
3459:
3460: ""nickname""
1.66 www 3461:
1.81 albertel 3462: if the user has a nickname or
3463:
3464: "first middle last generation"
3465:
3466: if the user does not
3467:
3468: =cut
1.66 www 3469:
3470: sub nickname {
3471: my ($uname,$udom)=@_;
1.537 albertel 3472: return if (!defined($uname) || !defined($udom));
1.295 www 3473: my %names=&getnames($uname,$udom);
1.68 albertel 3474: my $name=$names{'nickname'};
1.66 www 3475: if ($name) {
3476: $name='"'.$name.'"';
3477: } else {
3478: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3479: $names{'lastname'}.' '.$names{'generation'};
3480: $name=~s/\s+$//;
3481: $name=~s/\s+/ /g;
3482: }
3483: return $name;
3484: }
3485:
1.295 www 3486: sub getnames {
3487: my ($uname,$udom)=@_;
1.537 albertel 3488: return if (!defined($uname) || !defined($udom));
1.433 albertel 3489: if ($udom eq 'public' && $uname eq 'public') {
3490: return ('lastname' => &mt('Public'));
3491: }
1.295 www 3492: my $id=$uname.':'.$udom;
3493: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3494: if ($cached) {
3495: return %{$names};
3496: } else {
3497: my %loadnames=&Apache::lonnet::get('environment',
3498: ['firstname','middlename','lastname','generation','nickname'],
3499: $udom,$uname);
3500: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3501: return %loadnames;
3502: }
3503: }
1.61 www 3504:
1.542 raeburn 3505: # -------------------------------------------------------------------- getemails
1.648 raeburn 3506:
1.542 raeburn 3507: =pod
3508:
1.648 raeburn 3509: =item * &getemails($uname,$udom)
1.542 raeburn 3510:
3511: Gets a user's email information and returns it as a hash with keys:
3512: notification, critnotification, permanentemail
3513:
3514: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3515: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3516:
1.648 raeburn 3517:
1.542 raeburn 3518: =cut
3519:
1.648 raeburn 3520:
1.466 albertel 3521: sub getemails {
3522: my ($uname,$udom)=@_;
3523: if ($udom eq 'public' && $uname eq 'public') {
3524: return;
3525: }
1.467 www 3526: if (!$udom) { $udom=$env{'user.domain'}; }
3527: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3528: my $id=$uname.':'.$udom;
3529: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3530: if ($cached) {
3531: return %{$names};
3532: } else {
3533: my %loadnames=&Apache::lonnet::get('environment',
3534: ['notification','critnotification',
3535: 'permanentemail'],
3536: $udom,$uname);
3537: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3538: return %loadnames;
3539: }
3540: }
3541:
1.551 albertel 3542: sub flush_email_cache {
3543: my ($uname,$udom)=@_;
3544: if (!$udom) { $udom =$env{'user.domain'}; }
3545: if (!$uname) { $uname=$env{'user.name'}; }
3546: return if ($udom eq 'public' && $uname eq 'public');
3547: my $id=$uname.':'.$udom;
3548: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3549: }
3550:
1.728 raeburn 3551: # -------------------------------------------------------------------- getlangs
3552:
3553: =pod
3554:
3555: =item * &getlangs($uname,$udom)
3556:
3557: Gets a user's language preference and returns it as a hash with key:
3558: language.
3559:
3560: =cut
3561:
3562:
3563: sub getlangs {
3564: my ($uname,$udom) = @_;
3565: if (!$udom) { $udom =$env{'user.domain'}; }
3566: if (!$uname) { $uname=$env{'user.name'}; }
3567: my $id=$uname.':'.$udom;
3568: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3569: if ($cached) {
3570: return %{$langs};
3571: } else {
3572: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3573: $udom,$uname);
3574: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3575: return %loadlangs;
3576: }
3577: }
3578:
3579: sub flush_langs_cache {
3580: my ($uname,$udom)=@_;
3581: if (!$udom) { $udom =$env{'user.domain'}; }
3582: if (!$uname) { $uname=$env{'user.name'}; }
3583: return if ($udom eq 'public' && $uname eq 'public');
3584: my $id=$uname.':'.$udom;
3585: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3586: }
3587:
1.61 www 3588: # ------------------------------------------------------------------ Screenname
1.81 albertel 3589:
3590: =pod
3591:
1.648 raeburn 3592: =item * &screenname($uname,$udom)
1.81 albertel 3593:
3594: Gets a users screenname and returns it as a string
3595:
3596: =cut
1.61 www 3597:
3598: sub screenname {
3599: my ($uname,$udom)=@_;
1.258 albertel 3600: if ($uname eq $env{'user.name'} &&
3601: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3602: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3603: return $names{'screenname'};
1.62 www 3604: }
3605:
1.212 albertel 3606:
1.802 bisitz 3607: # ------------------------------------------------------------- Confirm Wrapper
3608: =pod
3609:
1.1075.2.42 raeburn 3610: =item * &confirmwrapper($message)
1.802 bisitz 3611:
3612: Wrap messages about completion of operation in box
3613:
3614: =cut
3615:
3616: sub confirmwrapper {
3617: my ($message)=@_;
3618: if ($message) {
3619: return "\n".'<div class="LC_confirm_box">'."\n"
3620: .$message."\n"
3621: .'</div>'."\n";
3622: } else {
3623: return $message;
3624: }
3625: }
3626:
1.62 www 3627: # ------------------------------------------------------------- Message Wrapper
3628:
3629: sub messagewrapper {
1.369 www 3630: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3631: return
1.441 albertel 3632: '<a href="/adm/email?compose=individual&'.
3633: 'recname='.$username.'&recdom='.$domain.
3634: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3635: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3636: }
1.802 bisitz 3637:
1.74 www 3638: # --------------------------------------------------------------- Notes Wrapper
3639:
3640: sub noteswrapper {
3641: my ($link,$un,$do)=@_;
3642: return
1.896 amueller 3643: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3644: }
1.802 bisitz 3645:
1.62 www 3646: # ------------------------------------------------------------- Aboutme Wrapper
3647:
3648: sub aboutmewrapper {
1.1070 raeburn 3649: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3650: if (!defined($username) && !defined($domain)) {
3651: return;
3652: }
1.1075.2.15 raeburn 3653: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3654: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3655: }
3656:
3657: # ------------------------------------------------------------ Syllabus Wrapper
3658:
3659: sub syllabuswrapper {
1.707 bisitz 3660: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3661: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3662: }
1.14 harris41 3663:
1.802 bisitz 3664: # -----------------------------------------------------------------------------
3665:
1.208 matthew 3666: sub track_student_link {
1.887 raeburn 3667: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3668: my $link ="/adm/trackstudent?";
1.208 matthew 3669: my $title = 'View recent activity';
3670: if (defined($sname) && $sname !~ /^\s*$/ &&
3671: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3672: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3673: $title .= ' of this student';
1.268 albertel 3674: }
1.208 matthew 3675: if (defined($target) && $target !~ /^\s*$/) {
3676: $target = qq{target="$target"};
3677: } else {
3678: $target = '';
3679: }
1.268 albertel 3680: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3681: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3682: $title = &mt($title);
3683: $linktext = &mt($linktext);
1.448 albertel 3684: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3685: &help_open_topic('View_recent_activity');
1.208 matthew 3686: }
3687:
1.781 raeburn 3688: sub slot_reservations_link {
3689: my ($linktext,$sname,$sdom,$target) = @_;
3690: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3691: my $title = 'View slot reservation history';
3692: if (defined($sname) && $sname !~ /^\s*$/ &&
3693: defined($sdom) && $sdom !~ /^\s*$/) {
3694: $link .= "&uname=$sname&udom=$sdom";
3695: $title .= ' of this student';
3696: }
3697: if (defined($target) && $target !~ /^\s*$/) {
3698: $target = qq{target="$target"};
3699: } else {
3700: $target = '';
3701: }
3702: $title = &mt($title);
3703: $linktext = &mt($linktext);
3704: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3705: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3706:
3707: }
3708:
1.508 www 3709: # ===================================================== Display a student photo
3710:
3711:
1.509 albertel 3712: sub student_image_tag {
1.508 www 3713: my ($domain,$user)=@_;
3714: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3715: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3716: return '<img src="'.$imgsrc.'" align="right" />';
3717: } else {
3718: return '';
3719: }
3720: }
3721:
1.112 bowersj2 3722: =pod
3723:
3724: =back
3725:
3726: =head1 Access .tab File Data
3727:
3728: =over 4
3729:
1.648 raeburn 3730: =item * &languageids()
1.112 bowersj2 3731:
3732: returns list of all language ids
3733:
3734: =cut
3735:
1.14 harris41 3736: sub languageids {
1.16 harris41 3737: return sort(keys(%language));
1.14 harris41 3738: }
3739:
1.112 bowersj2 3740: =pod
3741:
1.648 raeburn 3742: =item * &languagedescription()
1.112 bowersj2 3743:
3744: returns description of a specified language id
3745:
3746: =cut
3747:
1.14 harris41 3748: sub languagedescription {
1.125 www 3749: my $code=shift;
3750: return ($supported_language{$code}?'* ':'').
3751: $language{$code}.
1.126 www 3752: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3753: }
3754:
1.1048 foxr 3755: =pod
3756:
3757: =item * &plainlanguagedescription
3758:
3759: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3760: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3761:
3762: =cut
3763:
1.145 www 3764: sub plainlanguagedescription {
3765: my $code=shift;
3766: return $language{$code};
3767: }
3768:
1.1048 foxr 3769: =pod
3770:
3771: =item * &supportedlanguagecode
3772:
3773: Returns the supported language code (e.g. sptutf maps to pt) given a language
3774: code.
3775:
3776: =cut
3777:
1.145 www 3778: sub supportedlanguagecode {
3779: my $code=shift;
3780: return $supported_language{$code};
1.97 www 3781: }
3782:
1.112 bowersj2 3783: =pod
3784:
1.1048 foxr 3785: =item * &latexlanguage()
3786:
3787: Given a language key code returns the correspondnig language to use
3788: to select the correct hyphenation on LaTeX printouts. This is undef if there
3789: is no supported hyphenation for the language code.
3790:
3791: =cut
3792:
3793: sub latexlanguage {
3794: my $code = shift;
3795: return $latex_language{$code};
3796: }
3797:
3798: =pod
3799:
3800: =item * &latexhyphenation()
3801:
3802: Same as above but what's supplied is the language as it might be stored
3803: in the metadata.
3804:
3805: =cut
3806:
3807: sub latexhyphenation {
3808: my $key = shift;
3809: return $latex_language_bykey{$key};
3810: }
3811:
3812: =pod
3813:
1.648 raeburn 3814: =item * ©rightids()
1.112 bowersj2 3815:
3816: returns list of all copyrights
3817:
3818: =cut
3819:
3820: sub copyrightids {
3821: return sort(keys(%cprtag));
3822: }
3823:
3824: =pod
3825:
1.648 raeburn 3826: =item * ©rightdescription()
1.112 bowersj2 3827:
3828: returns description of a specified copyright id
3829:
3830: =cut
3831:
3832: sub copyrightdescription {
1.166 www 3833: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3834: }
1.197 matthew 3835:
3836: =pod
3837:
1.648 raeburn 3838: =item * &source_copyrightids()
1.192 taceyjo1 3839:
3840: returns list of all source copyrights
3841:
3842: =cut
3843:
3844: sub source_copyrightids {
3845: return sort(keys(%scprtag));
3846: }
3847:
3848: =pod
3849:
1.648 raeburn 3850: =item * &source_copyrightdescription()
1.192 taceyjo1 3851:
3852: returns description of a specified source copyright id
3853:
3854: =cut
3855:
3856: sub source_copyrightdescription {
3857: return &mt($scprtag{shift(@_)});
3858: }
1.112 bowersj2 3859:
3860: =pod
3861:
1.648 raeburn 3862: =item * &filecategories()
1.112 bowersj2 3863:
3864: returns list of all file categories
3865:
3866: =cut
3867:
3868: sub filecategories {
3869: return sort(keys(%category_extensions));
3870: }
3871:
3872: =pod
3873:
1.648 raeburn 3874: =item * &filecategorytypes()
1.112 bowersj2 3875:
3876: returns list of file types belonging to a given file
3877: category
3878:
3879: =cut
3880:
3881: sub filecategorytypes {
1.356 albertel 3882: my ($cat) = @_;
3883: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3884: }
3885:
3886: =pod
3887:
1.648 raeburn 3888: =item * &fileembstyle()
1.112 bowersj2 3889:
3890: returns embedding style for a specified file type
3891:
3892: =cut
3893:
3894: sub fileembstyle {
3895: return $fe{lc(shift(@_))};
1.169 www 3896: }
3897:
1.351 www 3898: sub filemimetype {
3899: return $fm{lc(shift(@_))};
3900: }
3901:
1.169 www 3902:
3903: sub filecategoryselect {
3904: my ($name,$value)=@_;
1.189 matthew 3905: return &select_form($value,$name,
1.970 raeburn 3906: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3907: }
3908:
3909: =pod
3910:
1.648 raeburn 3911: =item * &filedescription()
1.112 bowersj2 3912:
3913: returns description for a specified file type
3914:
3915: =cut
3916:
3917: sub filedescription {
1.188 matthew 3918: my $file_description = $fd{lc(shift())};
3919: $file_description =~ s:([\[\]]):~$1:g;
3920: return &mt($file_description);
1.112 bowersj2 3921: }
3922:
3923: =pod
3924:
1.648 raeburn 3925: =item * &filedescriptionex()
1.112 bowersj2 3926:
3927: returns description for a specified file type with
3928: extra formatting
3929:
3930: =cut
3931:
3932: sub filedescriptionex {
3933: my $ex=shift;
1.188 matthew 3934: my $file_description = $fd{lc($ex)};
3935: $file_description =~ s:([\[\]]):~$1:g;
3936: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3937: }
3938:
3939: # End of .tab access
3940: =pod
3941:
3942: =back
3943:
3944: =cut
3945:
3946: # ------------------------------------------------------------------ File Types
3947: sub fileextensions {
3948: return sort(keys(%fe));
3949: }
3950:
1.97 www 3951: # ----------------------------------------------------------- Display Languages
3952: # returns a hash with all desired display languages
3953: #
3954:
3955: sub display_languages {
3956: my %languages=();
1.695 raeburn 3957: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3958: $languages{$lang}=1;
1.97 www 3959: }
3960: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3961: if ($env{'form.displaylanguage'}) {
1.356 albertel 3962: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3963: $languages{$lang}=1;
1.97 www 3964: }
3965: }
3966: return %languages;
1.14 harris41 3967: }
3968:
1.582 albertel 3969: sub languages {
3970: my ($possible_langs) = @_;
1.695 raeburn 3971: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3972: if (!ref($possible_langs)) {
3973: if( wantarray ) {
3974: return @preferred_langs;
3975: } else {
3976: return $preferred_langs[0];
3977: }
3978: }
3979: my %possibilities = map { $_ => 1 } (@$possible_langs);
3980: my @preferred_possibilities;
3981: foreach my $preferred_lang (@preferred_langs) {
3982: if (exists($possibilities{$preferred_lang})) {
3983: push(@preferred_possibilities, $preferred_lang);
3984: }
3985: }
3986: if( wantarray ) {
3987: return @preferred_possibilities;
3988: }
3989: return $preferred_possibilities[0];
3990: }
3991:
1.742 raeburn 3992: sub user_lang {
3993: my ($touname,$toudom,$fromcid) = @_;
3994: my @userlangs;
3995: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3996: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3997: $env{'course.'.$fromcid.'.languages'}));
3998: } else {
3999: my %langhash = &getlangs($touname,$toudom);
4000: if ($langhash{'languages'} ne '') {
4001: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4002: } else {
4003: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4004: if ($domdefs{'lang_def'} ne '') {
4005: @userlangs = ($domdefs{'lang_def'});
4006: }
4007: }
4008: }
4009: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4010: my $user_lh = Apache::localize->get_handle(@languages);
4011: return $user_lh;
4012: }
4013:
4014:
1.112 bowersj2 4015: ###############################################################
4016: ## Student Answer Attempts ##
4017: ###############################################################
4018:
4019: =pod
4020:
4021: =head1 Alternate Problem Views
4022:
4023: =over 4
4024:
1.648 raeburn 4025: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 4026: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4027:
4028: Return string with previous attempt on problem. Arguments:
4029:
4030: =over 4
4031:
4032: =item * $symb: Problem, including path
4033:
4034: =item * $username: username of the desired student
4035:
4036: =item * $domain: domain of the desired student
1.14 harris41 4037:
1.112 bowersj2 4038: =item * $course: Course ID
1.14 harris41 4039:
1.112 bowersj2 4040: =item * $getattempt: Leave blank for all attempts, otherwise put
4041: something
1.14 harris41 4042:
1.112 bowersj2 4043: =item * $regexp: if string matches this regexp, the string will be
4044: sent to $gradesub
1.14 harris41 4045:
1.112 bowersj2 4046: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4047:
1.1075.2.86 raeburn 4048: =item * $usec: section of the desired student
4049:
4050: =item * $identifier: counter for student (multiple students one problem) or
4051: problem (one student; whole sequence).
4052:
1.112 bowersj2 4053: =back
1.14 harris41 4054:
1.112 bowersj2 4055: The output string is a table containing all desired attempts, if any.
1.16 harris41 4056:
1.112 bowersj2 4057: =cut
1.1 albertel 4058:
4059: sub get_previous_attempt {
1.1075.2.86 raeburn 4060: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4061: my $prevattempts='';
1.43 ng 4062: no strict 'refs';
1.1 albertel 4063: if ($symb) {
1.3 albertel 4064: my (%returnhash)=
4065: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4066: if ($returnhash{'version'}) {
4067: my %lasthash=();
4068: my $version;
4069: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 4070: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4071: if ($key =~ /\.rawrndseed$/) {
4072: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4073: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4074: } else {
4075: $lasthash{$key}=$returnhash{$version.':'.$key};
4076: }
1.19 harris41 4077: }
1.1 albertel 4078: }
1.596 albertel 4079: $prevattempts=&start_data_table().&start_data_table_header_row();
4080: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 4081: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4082: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4083: foreach my $key (sort(keys(%lasthash))) {
4084: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4085: if ($#parts > 0) {
1.31 albertel 4086: my $data=$parts[-1];
1.989 raeburn 4087: next if ($data eq 'foilorder');
1.31 albertel 4088: pop(@parts);
1.1010 www 4089: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4090: if ($data eq 'type') {
4091: unless ($showsurv) {
4092: my $id = join(',',@parts);
4093: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4094: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4095: $lasthidden{$ign.'.'.$id} = 1;
4096: }
1.945 raeburn 4097: }
1.1075.2.86 raeburn 4098: if ($identifier ne '') {
4099: my $id = join(',',@parts);
4100: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4101: $domain,$username,$usec,undef,$course) =~ /^no/) {
4102: $hidestatus{$ign.'.'.$id} = 1;
4103: }
4104: }
4105: } elsif ($data eq 'regrader') {
4106: if (($identifier ne '') && (@parts)) {
4107: my $id = join(',',@parts);
4108: $regraded{$ign.'.'.$id} = 1;
4109: }
1.1010 www 4110: }
1.31 albertel 4111: } else {
1.41 ng 4112: if ($#parts == 0) {
4113: $prevattempts.='<th>'.$parts[0].'</th>';
4114: } else {
4115: $prevattempts.='<th>'.$ign.'</th>';
4116: }
1.31 albertel 4117: }
1.16 harris41 4118: }
1.596 albertel 4119: $prevattempts.=&end_data_table_header_row();
1.40 ng 4120: if ($getattempt eq '') {
1.1075.2.86 raeburn 4121: my (%solved,%resets,%probstatus);
4122: if (($identifier ne '') && (keys(%regraded) > 0)) {
4123: for ($version=1;$version<=$returnhash{'version'};$version++) {
4124: foreach my $id (keys(%regraded)) {
4125: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4126: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4127: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4128: push(@{$resets{$id}},$version);
4129: }
4130: }
4131: }
4132: }
1.40 ng 4133: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4134: my (@hidden,@unsolved);
1.945 raeburn 4135: if (%typeparts) {
4136: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4137: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4138: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4139: push(@hidden,$id);
1.1075.2.86 raeburn 4140: } elsif ($identifier ne '') {
4141: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4142: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4143: ($hidestatus{$id})) {
4144: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4145: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4146: push(@{$solved{$id}},$version);
4147: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4148: (ref($solved{$id}) eq 'ARRAY')) {
4149: my $skip;
4150: if (ref($resets{$id}) eq 'ARRAY') {
4151: foreach my $reset (@{$resets{$id}}) {
4152: if ($reset > $solved{$id}[-1]) {
4153: $skip=1;
4154: last;
4155: }
4156: }
4157: }
4158: unless ($skip) {
4159: my ($ign,$partslist) = split(/\./,$id,2);
4160: push(@unsolved,$partslist);
4161: }
4162: }
4163: }
1.945 raeburn 4164: }
4165: }
4166: }
4167: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4168: '<td>'.&mt('Transaction [_1]',$version);
4169: if (@unsolved) {
4170: $prevattempts .= '<span class="LC_nobreak"><label>'.
4171: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4172: &mt('Hide').'</label></span>';
4173: }
4174: $prevattempts .= '</td>';
1.945 raeburn 4175: if (@hidden) {
4176: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4177: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4178: my $hide;
4179: foreach my $id (@hidden) {
4180: if ($key =~ /^\Q$id\E/) {
4181: $hide = 1;
4182: last;
4183: }
4184: }
4185: if ($hide) {
4186: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4187: if (($data eq 'award') || ($data eq 'awarddetail')) {
4188: my $value = &format_previous_attempt_value($key,
4189: $returnhash{$version.':'.$key});
4190: $prevattempts.='<td>'.$value.' </td>';
4191: } else {
4192: $prevattempts.='<td> </td>';
4193: }
4194: } else {
4195: if ($key =~ /\./) {
1.1075.2.91 raeburn 4196: my $value = $returnhash{$version.':'.$key};
4197: if ($key =~ /\.rndseed$/) {
4198: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4199: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4200: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4201: }
4202: }
4203: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4204: ' </td>';
1.945 raeburn 4205: } else {
4206: $prevattempts.='<td> </td>';
4207: }
4208: }
4209: }
4210: } else {
4211: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4212: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4213: my $value = $returnhash{$version.':'.$key};
4214: if ($key =~ /\.rndseed$/) {
4215: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4216: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4217: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4218: }
4219: }
4220: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4221: ' </td>';
1.945 raeburn 4222: }
4223: }
4224: $prevattempts.=&end_data_table_row();
1.40 ng 4225: }
1.1 albertel 4226: }
1.945 raeburn 4227: my @currhidden = keys(%lasthidden);
1.596 albertel 4228: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4229: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4230: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4231: if (%typeparts) {
4232: my $hidden;
4233: foreach my $id (@currhidden) {
4234: if ($key =~ /^\Q$id\E/) {
4235: $hidden = 1;
4236: last;
4237: }
4238: }
4239: if ($hidden) {
4240: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4241: if (($data eq 'award') || ($data eq 'awarddetail')) {
4242: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4243: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4244: $value = &$gradesub($value);
4245: }
4246: $prevattempts.='<td>'.$value.' </td>';
4247: } else {
4248: $prevattempts.='<td> </td>';
4249: }
4250: } else {
4251: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4252: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4253: $value = &$gradesub($value);
4254: }
4255: $prevattempts.='<td>'.$value.' </td>';
4256: }
4257: } else {
4258: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4259: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4260: $value = &$gradesub($value);
4261: }
4262: $prevattempts.='<td>'.$value.' </td>';
4263: }
1.16 harris41 4264: }
1.596 albertel 4265: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4266: } else {
1.596 albertel 4267: $prevattempts=
4268: &start_data_table().&start_data_table_row().
4269: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4270: &end_data_table_row().&end_data_table();
1.1 albertel 4271: }
4272: } else {
1.596 albertel 4273: $prevattempts=
4274: &start_data_table().&start_data_table_row().
4275: '<td>'.&mt('No data.').'</td>'.
4276: &end_data_table_row().&end_data_table();
1.1 albertel 4277: }
1.10 albertel 4278: }
4279:
1.581 albertel 4280: sub format_previous_attempt_value {
4281: my ($key,$value) = @_;
1.1011 www 4282: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4283: $value = &Apache::lonlocal::locallocaltime($value);
4284: } elsif (ref($value) eq 'ARRAY') {
4285: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4286: } elsif ($key =~ /answerstring$/) {
4287: my %answers = &Apache::lonnet::str2hash($value);
4288: my @anskeys = sort(keys(%answers));
4289: if (@anskeys == 1) {
4290: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4291: if ($answer =~ m{\0}) {
4292: $answer =~ s{\0}{,}g;
1.988 raeburn 4293: }
4294: my $tag_internal_answer_name = 'INTERNAL';
4295: if ($anskeys[0] eq $tag_internal_answer_name) {
4296: $value = $answer;
4297: } else {
4298: $value = $anskeys[0].'='.$answer;
4299: }
4300: } else {
4301: foreach my $ans (@anskeys) {
4302: my $answer = $answers{$ans};
1.1001 raeburn 4303: if ($answer =~ m{\0}) {
4304: $answer =~ s{\0}{,}g;
1.988 raeburn 4305: }
4306: $value .= $ans.'='.$answer.'<br />';;
4307: }
4308: }
1.581 albertel 4309: } else {
4310: $value = &unescape($value);
4311: }
4312: return $value;
4313: }
4314:
4315:
1.107 albertel 4316: sub relative_to_absolute {
4317: my ($url,$output)=@_;
4318: my $parser=HTML::TokeParser->new(\$output);
4319: my $token;
4320: my $thisdir=$url;
4321: my @rlinks=();
4322: while ($token=$parser->get_token) {
4323: if ($token->[0] eq 'S') {
4324: if ($token->[1] eq 'a') {
4325: if ($token->[2]->{'href'}) {
4326: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4327: }
4328: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4329: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4330: } elsif ($token->[1] eq 'base') {
4331: $thisdir=$token->[2]->{'href'};
4332: }
4333: }
4334: }
4335: $thisdir=~s-/[^/]*$--;
1.356 albertel 4336: foreach my $link (@rlinks) {
1.726 raeburn 4337: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4338: ($link=~/^\//) ||
4339: ($link=~/^javascript:/i) ||
4340: ($link=~/^mailto:/i) ||
4341: ($link=~/^\#/)) {
4342: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4343: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4344: }
4345: }
4346: # -------------------------------------------------- Deal with Applet codebases
4347: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4348: return $output;
4349: }
4350:
1.112 bowersj2 4351: =pod
4352:
1.648 raeburn 4353: =item * &get_student_view()
1.112 bowersj2 4354:
4355: show a snapshot of what student was looking at
4356:
4357: =cut
4358:
1.10 albertel 4359: sub get_student_view {
1.186 albertel 4360: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4361: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4362: my (%form);
1.10 albertel 4363: my @elements=('symb','courseid','domain','username');
4364: foreach my $element (@elements) {
1.186 albertel 4365: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4366: }
1.186 albertel 4367: if (defined($moreenv)) {
4368: %form=(%form,%{$moreenv});
4369: }
1.236 albertel 4370: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4371: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4372: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4373: $userview=~s/\<body[^\>]*\>//gi;
4374: $userview=~s/\<\/body\>//gi;
4375: $userview=~s/\<html\>//gi;
4376: $userview=~s/\<\/html\>//gi;
4377: $userview=~s/\<head\>//gi;
4378: $userview=~s/\<\/head\>//gi;
4379: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4380: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4381: if (wantarray) {
4382: return ($userview,$response);
4383: } else {
4384: return $userview;
4385: }
4386: }
4387:
4388: sub get_student_view_with_retries {
4389: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4390:
4391: my $ok = 0; # True if we got a good response.
4392: my $content;
4393: my $response;
4394:
4395: # Try to get the student_view done. within the retries count:
4396:
4397: do {
4398: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4399: $ok = $response->is_success;
4400: if (!$ok) {
4401: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4402: }
4403: $retries--;
4404: } while (!$ok && ($retries > 0));
4405:
4406: if (!$ok) {
4407: $content = ''; # On error return an empty content.
4408: }
1.651 www 4409: if (wantarray) {
4410: return ($content, $response);
4411: } else {
4412: return $content;
4413: }
1.11 albertel 4414: }
4415:
1.112 bowersj2 4416: =pod
4417:
1.648 raeburn 4418: =item * &get_student_answers()
1.112 bowersj2 4419:
4420: show a snapshot of how student was answering problem
4421:
4422: =cut
4423:
1.11 albertel 4424: sub get_student_answers {
1.100 sakharuk 4425: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4426: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4427: my (%moreenv);
1.11 albertel 4428: my @elements=('symb','courseid','domain','username');
4429: foreach my $element (@elements) {
1.186 albertel 4430: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4431: }
1.186 albertel 4432: $moreenv{'grade_target'}='answer';
4433: %moreenv=(%form,%moreenv);
1.497 raeburn 4434: $feedurl = &Apache::lonnet::clutter($feedurl);
4435: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4436: return $userview;
1.1 albertel 4437: }
1.116 albertel 4438:
4439: =pod
4440:
4441: =item * &submlink()
4442:
1.242 albertel 4443: Inputs: $text $uname $udom $symb $target
1.116 albertel 4444:
4445: Returns: A link to grades.pm such as to see the SUBM view of a student
4446:
4447: =cut
4448:
4449: ###############################################
4450: sub submlink {
1.242 albertel 4451: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4452: if (!($uname && $udom)) {
4453: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4454: &Apache::lonnet::whichuser($symb);
1.116 albertel 4455: if (!$symb) { $symb=$cursymb; }
4456: }
1.254 matthew 4457: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4458: $symb=&escape($symb);
1.960 bisitz 4459: if ($target) { $target=" target=\"$target\""; }
4460: return
4461: '<a href="/adm/grades?command=submission'.
4462: '&symb='.$symb.
4463: '&student='.$uname.
4464: '&userdom='.$udom.'"'.
4465: $target.'>'.$text.'</a>';
1.242 albertel 4466: }
4467: ##############################################
4468:
4469: =pod
4470:
4471: =item * &pgrdlink()
4472:
4473: Inputs: $text $uname $udom $symb $target
4474:
4475: Returns: A link to grades.pm such as to see the PGRD view of a student
4476:
4477: =cut
4478:
4479: ###############################################
4480: sub pgrdlink {
4481: my $link=&submlink(@_);
4482: $link=~s/(&command=submission)/$1&showgrading=yes/;
4483: return $link;
4484: }
4485: ##############################################
4486:
4487: =pod
4488:
4489: =item * &pprmlink()
4490:
4491: Inputs: $text $uname $udom $symb $target
4492:
4493: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4494: student and a specific resource
1.242 albertel 4495:
4496: =cut
4497:
4498: ###############################################
4499: sub pprmlink {
4500: my ($text,$uname,$udom,$symb,$target)=@_;
4501: if (!($uname && $udom)) {
4502: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4503: &Apache::lonnet::whichuser($symb);
1.242 albertel 4504: if (!$symb) { $symb=$cursymb; }
4505: }
1.254 matthew 4506: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4507: $symb=&escape($symb);
1.242 albertel 4508: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4509: return '<a href="/adm/parmset?command=set&'.
4510: 'symb='.$symb.'&uname='.$uname.
4511: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4512: }
4513: ##############################################
1.37 matthew 4514:
1.112 bowersj2 4515: =pod
4516:
4517: =back
4518:
4519: =cut
4520:
1.37 matthew 4521: ###############################################
1.51 www 4522:
4523:
4524: sub timehash {
1.687 raeburn 4525: my ($thistime) = @_;
4526: my $timezone = &Apache::lonlocal::gettimezone();
4527: my $dt = DateTime->from_epoch(epoch => $thistime)
4528: ->set_time_zone($timezone);
4529: my $wday = $dt->day_of_week();
4530: if ($wday == 7) { $wday = 0; }
4531: return ( 'second' => $dt->second(),
4532: 'minute' => $dt->minute(),
4533: 'hour' => $dt->hour(),
4534: 'day' => $dt->day_of_month(),
4535: 'month' => $dt->month(),
4536: 'year' => $dt->year(),
4537: 'weekday' => $wday,
4538: 'dayyear' => $dt->day_of_year(),
4539: 'dlsav' => $dt->is_dst() );
1.51 www 4540: }
4541:
1.370 www 4542: sub utc_string {
4543: my ($date)=@_;
1.371 www 4544: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4545: }
4546:
1.51 www 4547: sub maketime {
4548: my %th=@_;
1.687 raeburn 4549: my ($epoch_time,$timezone,$dt);
4550: $timezone = &Apache::lonlocal::gettimezone();
4551: eval {
4552: $dt = DateTime->new( year => $th{'year'},
4553: month => $th{'month'},
4554: day => $th{'day'},
4555: hour => $th{'hour'},
4556: minute => $th{'minute'},
4557: second => $th{'second'},
4558: time_zone => $timezone,
4559: );
4560: };
4561: if (!$@) {
4562: $epoch_time = $dt->epoch;
4563: if ($epoch_time) {
4564: return $epoch_time;
4565: }
4566: }
1.51 www 4567: return POSIX::mktime(
4568: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4569: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4570: }
4571:
4572: #########################################
1.51 www 4573:
4574: sub findallcourses {
1.482 raeburn 4575: my ($roles,$uname,$udom) = @_;
1.355 albertel 4576: my %roles;
4577: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4578: my %courses;
1.51 www 4579: my $now=time;
1.482 raeburn 4580: if (!defined($uname)) {
4581: $uname = $env{'user.name'};
4582: }
4583: if (!defined($udom)) {
4584: $udom = $env{'user.domain'};
4585: }
4586: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4587: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4588: if (!%roles) {
4589: %roles = (
4590: cc => 1,
1.907 raeburn 4591: co => 1,
1.482 raeburn 4592: in => 1,
4593: ep => 1,
4594: ta => 1,
4595: cr => 1,
4596: st => 1,
4597: );
4598: }
4599: foreach my $entry (keys(%roleshash)) {
4600: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4601: if ($trole =~ /^cr/) {
4602: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4603: } else {
4604: next if (!exists($roles{$trole}));
4605: }
4606: if ($tend) {
4607: next if ($tend < $now);
4608: }
4609: if ($tstart) {
4610: next if ($tstart > $now);
4611: }
1.1058 raeburn 4612: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4613: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4614: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4615: if ($secpart eq '') {
4616: ($cnum,$role) = split(/_/,$cnumpart);
4617: $sec = 'none';
1.1058 raeburn 4618: $value .= $cnum.'/';
1.482 raeburn 4619: } else {
4620: $cnum = $cnumpart;
4621: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4622: $value .= $cnum.'/'.$sec;
4623: }
4624: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4625: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4626: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4627: }
4628: } else {
4629: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4630: }
1.482 raeburn 4631: }
4632: } else {
4633: foreach my $key (keys(%env)) {
1.483 albertel 4634: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4635: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4636: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4637: next if ($role eq 'ca' || $role eq 'aa');
4638: next if (%roles && !exists($roles{$role}));
4639: my ($starttime,$endtime)=split(/\./,$env{$key});
4640: my $active=1;
4641: if ($starttime) {
4642: if ($now<$starttime) { $active=0; }
4643: }
4644: if ($endtime) {
4645: if ($now>$endtime) { $active=0; }
4646: }
4647: if ($active) {
1.1058 raeburn 4648: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4649: if ($sec eq '') {
4650: $sec = 'none';
1.1058 raeburn 4651: } else {
4652: $value .= $sec;
4653: }
4654: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4655: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4656: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4657: }
4658: } else {
4659: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4660: }
1.474 raeburn 4661: }
4662: }
1.51 www 4663: }
4664: }
1.474 raeburn 4665: return %courses;
1.51 www 4666: }
1.37 matthew 4667:
1.54 www 4668: ###############################################
1.474 raeburn 4669:
4670: sub blockcheck {
1.1075.2.73 raeburn 4671: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4672:
1.1075.2.73 raeburn 4673: if (defined($udom) && defined($uname)) {
4674: # If uname and udom are for a course, check for blocks in the course.
4675: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4676: my ($startblock,$endblock,$triggerblock) =
4677: &get_blocks($setters,$activity,$udom,$uname,$url);
4678: return ($startblock,$endblock,$triggerblock);
4679: }
4680: } else {
1.490 raeburn 4681: $udom = $env{'user.domain'};
4682: $uname = $env{'user.name'};
4683: }
4684:
1.502 raeburn 4685: my $startblock = 0;
4686: my $endblock = 0;
1.1062 raeburn 4687: my $triggerblock = '';
1.482 raeburn 4688: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4689:
1.490 raeburn 4690: # If uname is for a user, and activity is course-specific, i.e.,
4691: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4692:
1.490 raeburn 4693: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.73 raeburn 4694: $activity eq 'groups' || $activity eq 'printout') &&
4695: ($env{'request.course.id'})) {
1.490 raeburn 4696: foreach my $key (keys(%live_courses)) {
4697: if ($key ne $env{'request.course.id'}) {
4698: delete($live_courses{$key});
4699: }
4700: }
4701: }
4702:
4703: my $otheruser = 0;
4704: my %own_courses;
4705: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4706: # Resource belongs to user other than current user.
4707: $otheruser = 1;
4708: # Gather courses for current user
4709: %own_courses =
4710: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4711: }
4712:
4713: # Gather active course roles - course coordinator, instructor,
4714: # exam proctor, ta, student, or custom role.
1.474 raeburn 4715:
4716: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4717: my ($cdom,$cnum);
4718: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4719: $cdom = $env{'course.'.$course.'.domain'};
4720: $cnum = $env{'course.'.$course.'.num'};
4721: } else {
1.490 raeburn 4722: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4723: }
4724: my $no_ownblock = 0;
4725: my $no_userblock = 0;
1.533 raeburn 4726: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4727: # Check if current user has 'evb' priv for this
4728: if (defined($own_courses{$course})) {
4729: foreach my $sec (keys(%{$own_courses{$course}})) {
4730: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4731: if ($sec ne 'none') {
4732: $checkrole .= '/'.$sec;
4733: }
4734: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4735: $no_ownblock = 1;
4736: last;
4737: }
4738: }
4739: }
4740: # if they have 'evb' priv and are currently not playing student
4741: next if (($no_ownblock) &&
4742: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4743: }
1.474 raeburn 4744: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4745: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4746: if ($sec ne 'none') {
1.482 raeburn 4747: $checkrole .= '/'.$sec;
1.474 raeburn 4748: }
1.490 raeburn 4749: if ($otheruser) {
4750: # Resource belongs to user other than current user.
4751: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4752: my (%allroles,%userroles);
4753: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4754: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4755: my ($trole,$tdom,$tnum,$tsec);
4756: if ($entry =~ /^cr/) {
4757: ($trole,$tdom,$tnum,$tsec) =
4758: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4759: } else {
4760: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4761: }
4762: my ($spec,$area,$trest);
4763: $area = '/'.$tdom.'/'.$tnum;
4764: $trest = $tnum;
4765: if ($tsec ne '') {
4766: $area .= '/'.$tsec;
4767: $trest .= '/'.$tsec;
4768: }
4769: $spec = $trole.'.'.$area;
4770: if ($trole =~ /^cr/) {
4771: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4772: $tdom,$spec,$trest,$area);
4773: } else {
4774: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4775: $tdom,$spec,$trest,$area);
4776: }
4777: }
1.1075.2.124 raeburn 4778: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 4779: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4780: if ($1) {
4781: $no_userblock = 1;
4782: last;
4783: }
1.486 raeburn 4784: }
4785: }
1.490 raeburn 4786: } else {
4787: # Resource belongs to current user
4788: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4789: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4790: $no_ownblock = 1;
4791: last;
4792: }
1.474 raeburn 4793: }
4794: }
4795: # if they have the evb priv and are currently not playing student
1.482 raeburn 4796: next if (($no_ownblock) &&
1.491 albertel 4797: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4798: next if ($no_userblock);
1.474 raeburn 4799:
1.1075.2.128 raeburn 4800: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 4801: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4802:
1.1062 raeburn 4803: my ($start,$end,$trigger) =
4804: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4805: if (($start != 0) &&
4806: (($startblock == 0) || ($startblock > $start))) {
4807: $startblock = $start;
1.1062 raeburn 4808: if ($trigger ne '') {
4809: $triggerblock = $trigger;
4810: }
1.502 raeburn 4811: }
4812: if (($end != 0) &&
4813: (($endblock == 0) || ($endblock < $end))) {
4814: $endblock = $end;
1.1062 raeburn 4815: if ($trigger ne '') {
4816: $triggerblock = $trigger;
4817: }
1.502 raeburn 4818: }
1.490 raeburn 4819: }
1.1062 raeburn 4820: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4821: }
4822:
4823: sub get_blocks {
1.1062 raeburn 4824: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4825: my $startblock = 0;
4826: my $endblock = 0;
1.1062 raeburn 4827: my $triggerblock = '';
1.490 raeburn 4828: my $course = $cdom.'_'.$cnum;
4829: $setters->{$course} = {};
4830: $setters->{$course}{'staff'} = [];
4831: $setters->{$course}{'times'} = [];
1.1062 raeburn 4832: $setters->{$course}{'triggers'} = [];
4833: my (@blockers,%triggered);
4834: my $now = time;
4835: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4836: if ($activity eq 'docs') {
4837: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4838: foreach my $block (@blockers) {
4839: if ($block =~ /^firstaccess____(.+)$/) {
4840: my $item = $1;
4841: my $type = 'map';
4842: my $timersymb = $item;
4843: if ($item eq 'course') {
4844: $type = 'course';
4845: } elsif ($item =~ /___\d+___/) {
4846: $type = 'resource';
4847: } else {
4848: $timersymb = &Apache::lonnet::symbread($item);
4849: }
4850: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4851: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4852: $triggered{$block} = {
4853: start => $start,
4854: end => $end,
4855: type => $type,
4856: };
4857: }
4858: }
4859: } else {
4860: foreach my $block (keys(%commblocks)) {
4861: if ($block =~ m/^(\d+)____(\d+)$/) {
4862: my ($start,$end) = ($1,$2);
4863: if ($start <= time && $end >= time) {
4864: if (ref($commblocks{$block}) eq 'HASH') {
4865: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4866: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4867: unless(grep(/^\Q$block\E$/,@blockers)) {
4868: push(@blockers,$block);
4869: }
4870: }
4871: }
4872: }
4873: }
4874: } elsif ($block =~ /^firstaccess____(.+)$/) {
4875: my $item = $1;
4876: my $timersymb = $item;
4877: my $type = 'map';
4878: if ($item eq 'course') {
4879: $type = 'course';
4880: } elsif ($item =~ /___\d+___/) {
4881: $type = 'resource';
4882: } else {
4883: $timersymb = &Apache::lonnet::symbread($item);
4884: }
4885: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4886: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4887: if ($start && $end) {
4888: if (($start <= time) && ($end >= time)) {
4889: unless (grep(/^\Q$block\E$/,@blockers)) {
4890: push(@blockers,$block);
4891: $triggered{$block} = {
4892: start => $start,
4893: end => $end,
4894: type => $type,
4895: };
4896: }
4897: }
1.490 raeburn 4898: }
1.1062 raeburn 4899: }
4900: }
4901: }
4902: foreach my $blocker (@blockers) {
4903: my ($staff_name,$staff_dom,$title,$blocks) =
4904: &parse_block_record($commblocks{$blocker});
4905: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4906: my ($start,$end,$triggertype);
4907: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4908: ($start,$end) = ($1,$2);
4909: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4910: $start = $triggered{$blocker}{'start'};
4911: $end = $triggered{$blocker}{'end'};
4912: $triggertype = $triggered{$blocker}{'type'};
4913: }
4914: if ($start) {
4915: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4916: if ($triggertype) {
4917: push(@{$$setters{$course}{'triggers'}},$triggertype);
4918: } else {
4919: push(@{$$setters{$course}{'triggers'}},0);
4920: }
4921: if ( ($startblock == 0) || ($startblock > $start) ) {
4922: $startblock = $start;
4923: if ($triggertype) {
4924: $triggerblock = $blocker;
1.474 raeburn 4925: }
4926: }
1.1062 raeburn 4927: if ( ($endblock == 0) || ($endblock < $end) ) {
4928: $endblock = $end;
4929: if ($triggertype) {
4930: $triggerblock = $blocker;
4931: }
4932: }
1.474 raeburn 4933: }
4934: }
1.1062 raeburn 4935: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4936: }
4937:
4938: sub parse_block_record {
4939: my ($record) = @_;
4940: my ($setuname,$setudom,$title,$blocks);
4941: if (ref($record) eq 'HASH') {
4942: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4943: $title = &unescape($record->{'event'});
4944: $blocks = $record->{'blocks'};
4945: } else {
4946: my @data = split(/:/,$record,3);
4947: if (scalar(@data) eq 2) {
4948: $title = $data[1];
4949: ($setuname,$setudom) = split(/@/,$data[0]);
4950: } else {
4951: ($setuname,$setudom,$title) = @data;
4952: }
4953: $blocks = { 'com' => 'on' };
4954: }
4955: return ($setuname,$setudom,$title,$blocks);
4956: }
4957:
1.854 kalberla 4958: sub blocking_status {
1.1075.2.73 raeburn 4959: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4960: my %setters;
1.890 droeschl 4961:
1.1061 raeburn 4962: # check for active blocking
1.1062 raeburn 4963: my ($startblock,$endblock,$triggerblock) =
1.1075.2.73 raeburn 4964: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4965: my $blocked = 0;
4966: if ($startblock && $endblock) {
4967: $blocked = 1;
4968: }
1.890 droeschl 4969:
1.1061 raeburn 4970: # caller just wants to know whether a block is active
4971: if (!wantarray) { return $blocked; }
4972:
4973: # build a link to a popup window containing the details
4974: my $querystring = "?activity=$activity";
4975: # $uname and $udom decide whose portfolio the user is trying to look at
1.1075.2.97 raeburn 4976: if (($activity eq 'port') || ($activity eq 'passwd')) {
4977: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
4978: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 4979: } elsif ($activity eq 'docs') {
4980: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4981: }
1.1061 raeburn 4982:
4983: my $output .= <<'END_MYBLOCK';
4984: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4985: var options = "width=" + w + ",height=" + h + ",";
4986: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4987: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4988: var newWin = window.open(url, wdwName, options);
4989: newWin.focus();
4990: }
1.890 droeschl 4991: END_MYBLOCK
1.854 kalberla 4992:
1.1061 raeburn 4993: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4994:
1.1061 raeburn 4995: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4996: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 4997: my $class = 'LC_comblock';
1.1062 raeburn 4998: if ($activity eq 'docs') {
4999: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 5000: $class = '';
1.1063 raeburn 5001: } elsif ($activity eq 'printout') {
5002: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 5003: } elsif ($activity eq 'passwd') {
5004: $text = &mt('Password Changing Blocked');
1.1062 raeburn 5005: }
1.1061 raeburn 5006: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 5007: <div class='$class'>
1.869 kalberla 5008: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5009: title='$text'>
5010: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5011: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5012: title='$text'>$text</a>
1.867 kalberla 5013: </div>
5014:
5015: END_BLOCK
1.474 raeburn 5016:
1.1061 raeburn 5017: return ($blocked, $output);
1.854 kalberla 5018: }
1.490 raeburn 5019:
1.60 matthew 5020: ###############################################
5021:
1.682 raeburn 5022: sub check_ip_acc {
1.1075.2.105 raeburn 5023: my ($acc,$clientip)=@_;
1.682 raeburn 5024: &Apache::lonxml::debug("acc is $acc");
5025: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5026: return 1;
5027: }
5028: my $allowed=0;
1.1075.2.111 raeburn 5029: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 5030:
5031: my $name;
5032: foreach my $pattern (split(',',$acc)) {
5033: $pattern =~ s/^\s*//;
5034: $pattern =~ s/\s*$//;
5035: if ($pattern =~ /\*$/) {
5036: #35.8.*
5037: $pattern=~s/\*//;
5038: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
5039: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5040: #35.8.3.[34-56]
5041: my $low=$2;
5042: my $high=$3;
5043: $pattern=$1;
5044: if ($ip =~ /^\Q$pattern\E/) {
5045: my $last=(split(/\./,$ip))[3];
5046: if ($last <=$high && $last >=$low) { $allowed=1; }
5047: }
5048: } elsif ($pattern =~ /^\*/) {
5049: #*.msu.edu
5050: $pattern=~s/\*//;
5051: if (!defined($name)) {
5052: use Socket;
5053: my $netaddr=inet_aton($ip);
5054: ($name)=gethostbyaddr($netaddr,AF_INET);
5055: }
5056: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
5057: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5058: #127.0.0.1
5059: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
5060: } else {
5061: #some.name.com
5062: if (!defined($name)) {
5063: use Socket;
5064: my $netaddr=inet_aton($ip);
5065: ($name)=gethostbyaddr($netaddr,AF_INET);
5066: }
5067: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
5068: }
5069: if ($allowed) { last; }
5070: }
5071: return $allowed;
5072: }
5073:
5074: ###############################################
5075:
1.60 matthew 5076: =pod
5077:
1.112 bowersj2 5078: =head1 Domain Template Functions
5079:
5080: =over 4
5081:
5082: =item * &determinedomain()
1.60 matthew 5083:
5084: Inputs: $domain (usually will be undef)
5085:
1.63 www 5086: Returns: Determines which domain should be used for designs
1.60 matthew 5087:
5088: =cut
1.54 www 5089:
1.60 matthew 5090: ###############################################
1.63 www 5091: sub determinedomain {
5092: my $domain=shift;
1.531 albertel 5093: if (! $domain) {
1.60 matthew 5094: # Determine domain if we have not been given one
1.893 raeburn 5095: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5096: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5097: if ($env{'request.role.domain'}) {
5098: $domain=$env{'request.role.domain'};
1.60 matthew 5099: }
5100: }
1.63 www 5101: return $domain;
5102: }
5103: ###############################################
1.517 raeburn 5104:
1.518 albertel 5105: sub devalidate_domconfig_cache {
5106: my ($udom)=@_;
5107: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5108: }
5109:
5110: # ---------------------- Get domain configuration for a domain
5111: sub get_domainconf {
5112: my ($udom) = @_;
5113: my $cachetime=1800;
5114: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5115: if (defined($cached)) { return %{$result}; }
5116:
5117: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5118: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5119: my (%designhash,%legacy);
1.518 albertel 5120: if (keys(%domconfig) > 0) {
5121: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5122: if (keys(%{$domconfig{'login'}})) {
5123: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5124: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5125: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5126: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5127: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5128: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5129: if ($key eq 'loginvia') {
5130: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5131: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5132: $designhash{$udom.'.login.loginvia'} = $server;
5133: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5134: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5135: } else {
5136: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5137: }
1.948 raeburn 5138: }
1.1075.2.87 raeburn 5139: } elsif ($key eq 'headtag') {
5140: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5141: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5142: }
1.946 raeburn 5143: }
1.1075.2.87 raeburn 5144: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5145: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5146: }
1.946 raeburn 5147: }
5148: }
5149: }
5150: } else {
5151: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5152: $designhash{$udom.'.login.'.$key.'_'.$img} =
5153: $domconfig{'login'}{$key}{$img};
5154: }
1.699 raeburn 5155: }
5156: } else {
5157: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5158: }
1.632 raeburn 5159: }
5160: } else {
5161: $legacy{'login'} = 1;
1.518 albertel 5162: }
1.632 raeburn 5163: } else {
5164: $legacy{'login'} = 1;
1.518 albertel 5165: }
5166: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5167: if (keys(%{$domconfig{'rolecolors'}})) {
5168: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5169: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5170: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5171: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5172: }
1.518 albertel 5173: }
5174: }
1.632 raeburn 5175: } else {
5176: $legacy{'rolecolors'} = 1;
1.518 albertel 5177: }
1.632 raeburn 5178: } else {
5179: $legacy{'rolecolors'} = 1;
1.518 albertel 5180: }
1.948 raeburn 5181: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5182: if ($domconfig{'autoenroll'}{'co-owners'}) {
5183: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5184: }
5185: }
1.632 raeburn 5186: if (keys(%legacy) > 0) {
5187: my %legacyhash = &get_legacy_domconf($udom);
5188: foreach my $item (keys(%legacyhash)) {
5189: if ($item =~ /^\Q$udom\E\.login/) {
5190: if ($legacy{'login'}) {
5191: $designhash{$item} = $legacyhash{$item};
5192: }
5193: } else {
5194: if ($legacy{'rolecolors'}) {
5195: $designhash{$item} = $legacyhash{$item};
5196: }
1.518 albertel 5197: }
5198: }
5199: }
1.632 raeburn 5200: } else {
5201: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5202: }
5203: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5204: $cachetime);
5205: return %designhash;
5206: }
5207:
1.632 raeburn 5208: sub get_legacy_domconf {
5209: my ($udom) = @_;
5210: my %legacyhash;
5211: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5212: my $designfile = $designdir.'/'.$udom.'.tab';
5213: if (-e $designfile) {
1.1075.2.128 raeburn 5214: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5215: while (my $line = <$fh>) {
5216: next if ($line =~ /^\#/);
5217: chomp($line);
5218: my ($key,$val)=(split(/\=/,$line));
5219: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5220: }
5221: close($fh);
5222: }
5223: }
1.1026 raeburn 5224: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5225: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5226: }
5227: return %legacyhash;
5228: }
5229:
1.63 www 5230: =pod
5231:
1.112 bowersj2 5232: =item * &domainlogo()
1.63 www 5233:
5234: Inputs: $domain (usually will be undef)
5235:
5236: Returns: A link to a domain logo, if the domain logo exists.
5237: If the domain logo does not exist, a description of the domain.
5238:
5239: =cut
1.112 bowersj2 5240:
1.63 www 5241: ###############################################
5242: sub domainlogo {
1.517 raeburn 5243: my $domain = &determinedomain(shift);
1.518 albertel 5244: my %designhash = &get_domainconf($domain);
1.517 raeburn 5245: # See if there is a logo
5246: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5247: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5248: if ($imgsrc =~ m{^/(adm|res)/}) {
5249: if ($imgsrc =~ m{^/res/}) {
5250: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5251: &Apache::lonnet::repcopy($local_name);
5252: }
5253: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5254: }
5255: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5256: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5257: return &Apache::lonnet::domain($domain,'description');
1.59 www 5258: } else {
1.60 matthew 5259: return '';
1.59 www 5260: }
5261: }
1.63 www 5262: ##############################################
5263:
5264: =pod
5265:
1.112 bowersj2 5266: =item * &designparm()
1.63 www 5267:
5268: Inputs: $which parameter; $domain (usually will be undef)
5269:
5270: Returns: value of designparamter $which
5271:
5272: =cut
1.112 bowersj2 5273:
1.397 albertel 5274:
1.400 albertel 5275: ##############################################
1.397 albertel 5276: sub designparm {
5277: my ($which,$domain)=@_;
5278: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5279: return $env{'environment.color.'.$which};
1.96 www 5280: }
1.63 www 5281: $domain=&determinedomain($domain);
1.1016 raeburn 5282: my %domdesign;
5283: unless ($domain eq 'public') {
5284: %domdesign = &get_domainconf($domain);
5285: }
1.520 raeburn 5286: my $output;
1.517 raeburn 5287: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5288: $output = $domdesign{$domain.'.'.$which};
1.63 www 5289: } else {
1.520 raeburn 5290: $output = $defaultdesign{$which};
5291: }
5292: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5293: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5294: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5295: if ($output =~ m{^/res/}) {
5296: my $local_name = &Apache::lonnet::filelocation('',$output);
5297: &Apache::lonnet::repcopy($local_name);
5298: }
1.520 raeburn 5299: $output = &lonhttpdurl($output);
5300: }
1.63 www 5301: }
1.520 raeburn 5302: return $output;
1.63 www 5303: }
1.59 www 5304:
1.822 bisitz 5305: ##############################################
5306: =pod
5307:
1.832 bisitz 5308: =item * &authorspace()
5309:
1.1028 raeburn 5310: Inputs: $url (usually will be undef).
1.832 bisitz 5311:
1.1075.2.40 raeburn 5312: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5313: directory being viewed (or for which action is being taken).
5314: If $url is provided, and begins /priv/<domain>/<uname>
5315: the path will be that portion of the $context argument.
5316: Otherwise the path will be for the author space of the current
5317: user when the current role is author, or for that of the
5318: co-author/assistant co-author space when the current role
5319: is co-author or assistant co-author.
1.832 bisitz 5320:
5321: =cut
5322:
5323: sub authorspace {
1.1028 raeburn 5324: my ($url) = @_;
5325: if ($url ne '') {
5326: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5327: return $1;
5328: }
5329: }
1.832 bisitz 5330: my $caname = '';
1.1024 www 5331: my $cadom = '';
1.1028 raeburn 5332: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5333: ($cadom,$caname) =
1.832 bisitz 5334: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5335: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5336: $caname = $env{'user.name'};
1.1024 www 5337: $cadom = $env{'user.domain'};
1.832 bisitz 5338: }
1.1028 raeburn 5339: if (($caname ne '') && ($cadom ne '')) {
5340: return "/priv/$cadom/$caname/";
5341: }
5342: return;
1.832 bisitz 5343: }
5344:
5345: ##############################################
5346: =pod
5347:
1.822 bisitz 5348: =item * &head_subbox()
5349:
5350: Inputs: $content (contains HTML code with page functions, etc.)
5351:
5352: Returns: HTML div with $content
5353: To be included in page header
5354:
5355: =cut
5356:
5357: sub head_subbox {
5358: my ($content)=@_;
5359: my $output =
1.993 raeburn 5360: '<div class="LC_head_subbox">'
1.822 bisitz 5361: .$content
5362: .'</div>'
5363: }
5364:
5365: ##############################################
5366: =pod
5367:
5368: =item * &CSTR_pageheader()
5369:
1.1026 raeburn 5370: Input: (optional) filename from which breadcrumb trail is built.
5371: In most cases no input as needed, as $env{'request.filename'}
5372: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5373:
5374: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5375: To be included on Authoring Space pages
1.822 bisitz 5376:
5377: =cut
5378:
5379: sub CSTR_pageheader {
1.1026 raeburn 5380: my ($trailfile) = @_;
5381: if ($trailfile eq '') {
5382: $trailfile = $env{'request.filename'};
5383: }
5384:
5385: # this is for resources; directories have customtitle, and crumbs
5386: # and select recent are created in lonpubdir.pm
5387:
5388: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5389: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5390: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5391: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5392: $formaction =~ s{/+}{/}g;
1.822 bisitz 5393:
5394: my $parentpath = '';
5395: my $lastitem = '';
5396: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5397: $parentpath = $1;
5398: $lastitem = $2;
5399: } else {
5400: $lastitem = $thisdisfn;
5401: }
1.921 bisitz 5402:
5403: my $output =
1.822 bisitz 5404: '<div>'
5405: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5406: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5407: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5408: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5409: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5410:
5411: if ($lastitem) {
5412: $output .=
5413: '<span class="LC_filename">'
5414: .$lastitem
5415: .'</span>';
5416: }
5417: $output .=
5418: '<br />'
1.822 bisitz 5419: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5420: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5421: .'</form>'
5422: .&Apache::lonmenu::constspaceform()
5423: .'</div>';
1.921 bisitz 5424:
5425: return $output;
1.822 bisitz 5426: }
5427:
1.60 matthew 5428: ###############################################
5429: ###############################################
5430:
5431: =pod
5432:
1.112 bowersj2 5433: =back
5434:
1.549 albertel 5435: =head1 HTML Helpers
1.112 bowersj2 5436:
5437: =over 4
5438:
5439: =item * &bodytag()
1.60 matthew 5440:
5441: Returns a uniform header for LON-CAPA web pages.
5442:
5443: Inputs:
5444:
1.112 bowersj2 5445: =over 4
5446:
5447: =item * $title, A title to be displayed on the page.
5448:
5449: =item * $function, the current role (can be undef).
5450:
5451: =item * $addentries, extra parameters for the <body> tag.
5452:
5453: =item * $bodyonly, if defined, only return the <body> tag.
5454:
5455: =item * $domain, if defined, force a given domain.
5456:
5457: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5458: text interface only)
1.60 matthew 5459:
1.814 bisitz 5460: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5461: navigational links
1.317 albertel 5462:
1.338 albertel 5463: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5464:
1.1075.2.12 raeburn 5465: =item * $no_inline_link, if true and in remote mode, don't show the
5466: 'Switch To Inline Menu' link
5467:
1.460 albertel 5468: =item * $args, optional argument valid values are
5469: no_auto_mt_title -> prevents &mt()ing the title arg
1.1075.2.133 raeburn 5470: use_absolute -> for external resource or syllabus, this will
5471: contain https://<hostname> if server uses
5472: https (as per hosts.tab), but request is for http
5473: hostname -> hostname, from $r->hostname().
1.460 albertel 5474:
1.1075.2.15 raeburn 5475: =item * $advtoolsref, optional argument, ref to an array containing
5476: inlineremote items to be added in "Functions" menu below
5477: breadcrumbs.
5478:
1.112 bowersj2 5479: =back
5480:
1.60 matthew 5481: Returns: A uniform header for LON-CAPA web pages.
5482: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5483: If $bodyonly is undef or zero, an html string containing a <body> tag and
5484: other decorations will be returned.
5485:
5486: =cut
5487:
1.54 www 5488: sub bodytag {
1.831 bisitz 5489: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5490: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5491:
1.954 raeburn 5492: my $public;
5493: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5494: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5495: $public = 1;
5496: }
1.460 albertel 5497: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5498: my $httphost = $args->{'use_absolute'};
1.1075.2.133 raeburn 5499: my $hostname = $args->{'hostname'};
1.339 albertel 5500:
1.183 matthew 5501: $function = &get_users_function() if (!$function);
1.339 albertel 5502: my $img = &designparm($function.'.img',$domain);
5503: my $font = &designparm($function.'.font',$domain);
5504: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5505:
1.803 bisitz 5506: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5507: 'bgcolor' => $pgbg,
1.339 albertel 5508: 'text' => $font,
5509: 'alink' => &designparm($function.'.alink',$domain),
5510: 'vlink' => &designparm($function.'.vlink',$domain),
5511: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5512: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5513:
1.63 www 5514: # role and realm
1.1075.2.68 raeburn 5515: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5516: if ($realm) {
5517: $realm = '/'.$realm;
5518: }
1.378 raeburn 5519: if ($role eq 'ca') {
1.479 albertel 5520: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5521: $realm = &plainname($rname,$rdom);
1.378 raeburn 5522: }
1.55 www 5523: # realm
1.258 albertel 5524: if ($env{'request.course.id'}) {
1.378 raeburn 5525: if ($env{'request.role'} !~ /^cr/) {
5526: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 5527: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 5528: if ($env{'request.role.desc'}) {
5529: $role = $env{'request.role.desc'};
5530: } else {
5531: $role = &mt('Helpdesk[_1]',' '.$2);
5532: }
1.1075.2.115 raeburn 5533: } else {
5534: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5535: }
1.898 raeburn 5536: if ($env{'request.course.sec'}) {
5537: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5538: }
1.359 albertel 5539: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5540: } else {
5541: $role = &Apache::lonnet::plaintext($role);
1.54 www 5542: }
1.433 albertel 5543:
1.359 albertel 5544: if (!$realm) { $realm=' '; }
1.330 albertel 5545:
1.438 albertel 5546: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5547:
1.101 www 5548: # construct main body tag
1.359 albertel 5549: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5550: &Apache::lontexconvert::init_math_support();
1.252 albertel 5551:
1.1075.2.38 raeburn 5552: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5553:
5554: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5555: return $bodytag;
1.1075.2.38 raeburn 5556: }
1.359 albertel 5557:
1.954 raeburn 5558: if ($public) {
1.433 albertel 5559: undef($role);
5560: }
1.359 albertel 5561:
1.762 bisitz 5562: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5563: #
5564: # Extra info if you are the DC
5565: my $dc_info = '';
5566: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5567: $env{'course.'.$env{'request.course.id'}.
5568: '.domain'}.'/'})) {
5569: my $cid = $env{'request.course.id'};
1.917 raeburn 5570: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5571: $dc_info =~ s/\s+$//;
1.359 albertel 5572: }
5573:
1.1075.2.108 raeburn 5574: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 5575:
1.1075.2.13 raeburn 5576: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5577:
1.1075.2.38 raeburn 5578:
5579:
1.1075.2.21 raeburn 5580: my $funclist;
5581: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5582: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5583: Apache::lonmenu::serverform();
5584: my $forbodytag;
5585: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5586: $forcereg,$args->{'group'},
5587: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5588: $advtoolsref,'','',\$forbodytag);
1.1075.2.21 raeburn 5589: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5590: $funclist = $forbodytag;
5591: }
5592: } else {
1.903 droeschl 5593:
5594: # if ($env{'request.state'} eq 'construct') {
5595: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5596: # }
5597:
1.1075.2.38 raeburn 5598: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5599: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5600:
1.1075.2.38 raeburn 5601: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5602:
1.916 droeschl 5603: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5604: if ($dc_info) {
5605: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5606: }
1.1075.2.38 raeburn 5607: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5608: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5609: return $bodytag;
5610: }
1.894 droeschl 5611:
1.927 raeburn 5612: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5613: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5614: }
1.916 droeschl 5615:
1.1075.2.38 raeburn 5616: $bodytag .= $right;
1.852 droeschl 5617:
1.917 raeburn 5618: if ($dc_info) {
5619: $dc_info = &dc_courseid_toggle($dc_info);
5620: }
5621: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5622:
1.1075.2.61 raeburn 5623: #if directed to not display the secondary menu, don't.
5624: if ($args->{'no_secondary_menu'}) {
5625: return $bodytag;
5626: }
1.903 droeschl 5627: #don't show menus for public users
1.954 raeburn 5628: if (!$public){
1.1075.2.52 raeburn 5629: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5630: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5631: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5632: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5633: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.133 raeburn 5634: $args->{'bread_crumbs'},'','',$hostname);
1.1075.2.116 raeburn 5635: } elsif ($forcereg) {
1.1075.2.22 raeburn 5636: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5637: $args->{'group'},
1.1075.2.133 raeburn 5638: $args->{'hide_buttons',
5639: $hostname});
1.1075.2.15 raeburn 5640: } else {
1.1075.2.21 raeburn 5641: my $forbodytag;
5642: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5643: $forcereg,$args->{'group'},
5644: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5645: $advtoolsref,'',$hostname,
5646: \$forbodytag);
1.1075.2.21 raeburn 5647: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5648: $bodytag .= $forbodytag;
5649: }
1.920 raeburn 5650: }
1.903 droeschl 5651: }else{
5652: # this is to seperate menu from content when there's no secondary
5653: # menu. Especially needed for public accessible ressources.
5654: $bodytag .= '<hr style="clear:both" />';
5655: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5656: }
1.903 droeschl 5657:
1.235 raeburn 5658: return $bodytag;
1.1075.2.12 raeburn 5659: }
5660:
5661: #
5662: # Top frame rendering, Remote is up
5663: #
5664:
5665: my $imgsrc = $img;
5666: if ($img =~ /^\/adm/) {
5667: $imgsrc = &lonhttpdurl($img);
5668: }
5669: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5670:
1.1075.2.60 raeburn 5671: my $help=($no_inline_link?''
5672: :&Apache::loncommon::top_nav_help('Help'));
5673:
1.1075.2.12 raeburn 5674: # Explicit link to get inline menu
5675: my $menu= ($no_inline_link?''
5676: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5677:
5678: if ($dc_info) {
5679: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5680: }
5681:
1.1075.2.38 raeburn 5682: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5683: unless ($public) {
5684: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5685: undef,'LC_menubuttons_link');
5686: }
5687:
1.1075.2.12 raeburn 5688: unless ($env{'form.inhibitmenu'}) {
5689: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5690: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5691: <li>$help</li>
1.1075.2.12 raeburn 5692: <li>$menu</li>
5693: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5694: }
1.1075.2.13 raeburn 5695: if ($env{'request.state'} eq 'construct') {
5696: if (!$public){
5697: if ($env{'request.state'} eq 'construct') {
5698: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5699: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5700: &Apache::lonhtmlcommon::scripttag('','end').
5701: &Apache::lonmenu::innerregister($forcereg,
5702: $args->{'bread_crumbs'});
5703: }
5704: }
5705: }
1.1075.2.21 raeburn 5706: return $bodytag."\n".$funclist;
1.182 matthew 5707: }
5708:
1.917 raeburn 5709: sub dc_courseid_toggle {
5710: my ($dc_info) = @_;
1.980 raeburn 5711: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5712: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5713: &mt('(More ...)').'</a></span>'.
5714: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5715: }
5716:
1.330 albertel 5717: sub make_attr_string {
5718: my ($register,$attr_ref) = @_;
5719:
5720: if ($attr_ref && !ref($attr_ref)) {
5721: die("addentries Must be a hash ref ".
5722: join(':',caller(1))." ".
5723: join(':',caller(0))." ");
5724: }
5725:
5726: if ($register) {
1.339 albertel 5727: my ($on_load,$on_unload);
5728: foreach my $key (keys(%{$attr_ref})) {
5729: if (lc($key) eq 'onload') {
5730: $on_load.=$attr_ref->{$key}.';';
5731: delete($attr_ref->{$key});
5732:
5733: } elsif (lc($key) eq 'onunload') {
5734: $on_unload.=$attr_ref->{$key}.';';
5735: delete($attr_ref->{$key});
5736: }
5737: }
1.1075.2.12 raeburn 5738: if ($env{'environment.remote'} eq 'on') {
5739: $attr_ref->{'onload'} =
5740: &Apache::lonmenu::loadevents(). $on_load;
5741: $attr_ref->{'onunload'}=
5742: &Apache::lonmenu::unloadevents().$on_unload;
5743: } else {
5744: $attr_ref->{'onload'} = $on_load;
5745: $attr_ref->{'onunload'}= $on_unload;
5746: }
1.330 albertel 5747: }
1.339 albertel 5748:
1.330 albertel 5749: my $attr_string;
1.1075.2.56 raeburn 5750: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5751: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5752: }
5753: return $attr_string;
5754: }
5755:
5756:
1.182 matthew 5757: ###############################################
1.251 albertel 5758: ###############################################
5759:
5760: =pod
5761:
5762: =item * &endbodytag()
5763:
5764: Returns a uniform footer for LON-CAPA web pages.
5765:
1.635 raeburn 5766: Inputs: 1 - optional reference to an args hash
5767: If in the hash, key for noredirectlink has a value which evaluates to true,
5768: a 'Continue' link is not displayed if the page contains an
5769: internal redirect in the <head></head> section,
5770: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5771:
5772: =cut
5773:
5774: sub endbodytag {
1.635 raeburn 5775: my ($args) = @_;
1.1075.2.6 raeburn 5776: my $endbodytag;
5777: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5778: $endbodytag='</body>';
5779: }
1.315 albertel 5780: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5781: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5782: $endbodytag=
5783: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5784: &mt('Continue').'</a>'.
5785: $endbodytag;
5786: }
1.315 albertel 5787: }
1.251 albertel 5788: return $endbodytag;
5789: }
5790:
1.352 albertel 5791: =pod
5792:
5793: =item * &standard_css()
5794:
5795: Returns a style sheet
5796:
5797: Inputs: (all optional)
5798: domain -> force to color decorate a page for a specific
5799: domain
5800: function -> force usage of a specific rolish color scheme
5801: bgcolor -> override the default page bgcolor
5802:
5803: =cut
5804:
1.343 albertel 5805: sub standard_css {
1.345 albertel 5806: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5807: $function = &get_users_function() if (!$function);
5808: my $img = &designparm($function.'.img', $domain);
5809: my $tabbg = &designparm($function.'.tabbg', $domain);
5810: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5811: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5812: #second colour for later usage
1.345 albertel 5813: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5814: my $pgbg_or_bgcolor =
5815: $bgcolor ||
1.352 albertel 5816: &designparm($function.'.pgbg', $domain);
1.382 albertel 5817: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5818: my $alink = &designparm($function.'.alink', $domain);
5819: my $vlink = &designparm($function.'.vlink', $domain);
5820: my $link = &designparm($function.'.link', $domain);
5821:
1.602 albertel 5822: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5823: my $mono = 'monospace';
1.850 bisitz 5824: my $data_table_head = $sidebg;
5825: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5826: my $data_table_dark = '#E0E0E0';
1.470 banghart 5827: my $data_table_darker = '#CCCCCC';
1.349 albertel 5828: my $data_table_highlight = '#FFFF00';
1.352 albertel 5829: my $mail_new = '#FFBB77';
5830: my $mail_new_hover = '#DD9955';
5831: my $mail_read = '#BBBB77';
5832: my $mail_read_hover = '#999944';
5833: my $mail_replied = '#AAAA88';
5834: my $mail_replied_hover = '#888855';
5835: my $mail_other = '#99BBBB';
5836: my $mail_other_hover = '#669999';
1.391 albertel 5837: my $table_header = '#DDDDDD';
1.489 raeburn 5838: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5839: my $lg_border_color = '#C8C8C8';
1.952 onken 5840: my $button_hover = '#BF2317';
1.392 albertel 5841:
1.608 albertel 5842: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5843: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5844: : '0 3px 0 4px';
1.448 albertel 5845:
1.523 albertel 5846:
1.343 albertel 5847: return <<END;
1.947 droeschl 5848:
5849: /* needed for iframe to allow 100% height in FF */
5850: body, html {
5851: margin: 0;
5852: padding: 0 0.5%;
5853: height: 99%; /* to avoid scrollbars */
5854: }
5855:
1.795 www 5856: body {
1.911 bisitz 5857: font-family: $sans;
5858: line-height:130%;
5859: font-size:0.83em;
5860: color:$font;
1.795 www 5861: }
5862:
1.959 onken 5863: a:focus,
5864: a:focus img {
1.795 www 5865: color: red;
5866: }
1.698 harmsja 5867:
1.911 bisitz 5868: form, .inline {
5869: display: inline;
1.795 www 5870: }
1.721 harmsja 5871:
1.795 www 5872: .LC_right {
1.911 bisitz 5873: text-align:right;
1.795 www 5874: }
5875:
5876: .LC_middle {
1.911 bisitz 5877: vertical-align:middle;
1.795 www 5878: }
1.721 harmsja 5879:
1.1075.2.38 raeburn 5880: .LC_floatleft {
5881: float: left;
5882: }
5883:
5884: .LC_floatright {
5885: float: right;
5886: }
5887:
1.911 bisitz 5888: .LC_400Box {
5889: width:400px;
5890: }
1.721 harmsja 5891:
1.947 droeschl 5892: .LC_iframecontainer {
5893: width: 98%;
5894: margin: 0;
5895: position: fixed;
5896: top: 8.5em;
5897: bottom: 0;
5898: }
5899:
5900: .LC_iframecontainer iframe{
5901: border: none;
5902: width: 100%;
5903: height: 100%;
5904: }
5905:
1.778 bisitz 5906: .LC_filename {
5907: font-family: $mono;
5908: white-space:pre;
1.921 bisitz 5909: font-size: 120%;
1.778 bisitz 5910: }
5911:
5912: .LC_fileicon {
5913: border: none;
5914: height: 1.3em;
5915: vertical-align: text-bottom;
5916: margin-right: 0.3em;
5917: text-decoration:none;
5918: }
5919:
1.1008 www 5920: .LC_setting {
5921: text-decoration:underline;
5922: }
5923:
1.350 albertel 5924: .LC_error {
5925: color: red;
5926: }
1.795 www 5927:
1.1075.2.15 raeburn 5928: .LC_warning {
5929: color: darkorange;
5930: }
5931:
1.457 albertel 5932: .LC_diff_removed {
1.733 bisitz 5933: color: red;
1.394 albertel 5934: }
1.532 albertel 5935:
5936: .LC_info,
1.457 albertel 5937: .LC_success,
5938: .LC_diff_added {
1.350 albertel 5939: color: green;
5940: }
1.795 www 5941:
1.802 bisitz 5942: div.LC_confirm_box {
5943: background-color: #FAFAFA;
5944: border: 1px solid $lg_border_color;
5945: margin-right: 0;
5946: padding: 5px;
5947: }
5948:
5949: div.LC_confirm_box .LC_error img,
5950: div.LC_confirm_box .LC_success img {
5951: vertical-align: middle;
5952: }
5953:
1.1075.2.108 raeburn 5954: .LC_maxwidth {
5955: max-width: 100%;
5956: height: auto;
5957: }
5958:
5959: .LC_textsize_mobile {
5960: \@media only screen and (max-device-width: 480px) {
5961: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
5962: }
5963: }
5964:
1.440 albertel 5965: .LC_icon {
1.771 droeschl 5966: border: none;
1.790 droeschl 5967: vertical-align: middle;
1.771 droeschl 5968: }
5969:
1.543 albertel 5970: .LC_docs_spacer {
5971: width: 25px;
5972: height: 1px;
1.771 droeschl 5973: border: none;
1.543 albertel 5974: }
1.346 albertel 5975:
1.532 albertel 5976: .LC_internal_info {
1.735 bisitz 5977: color: #999999;
1.532 albertel 5978: }
5979:
1.794 www 5980: .LC_discussion {
1.1050 www 5981: background: $data_table_dark;
1.911 bisitz 5982: border: 1px solid black;
5983: margin: 2px;
1.794 www 5984: }
5985:
5986: .LC_disc_action_left {
1.1050 www 5987: background: $sidebg;
1.911 bisitz 5988: text-align: left;
1.1050 www 5989: padding: 4px;
5990: margin: 2px;
1.794 www 5991: }
5992:
5993: .LC_disc_action_right {
1.1050 www 5994: background: $sidebg;
1.911 bisitz 5995: text-align: right;
1.1050 www 5996: padding: 4px;
5997: margin: 2px;
1.794 www 5998: }
5999:
6000: .LC_disc_new_item {
1.911 bisitz 6001: background: white;
6002: border: 2px solid red;
1.1050 www 6003: margin: 4px;
6004: padding: 4px;
1.794 www 6005: }
6006:
6007: .LC_disc_old_item {
1.911 bisitz 6008: background: white;
1.1050 www 6009: margin: 4px;
6010: padding: 4px;
1.794 www 6011: }
6012:
1.458 albertel 6013: table.LC_pastsubmission {
6014: border: 1px solid black;
6015: margin: 2px;
6016: }
6017:
1.924 bisitz 6018: table#LC_menubuttons {
1.345 albertel 6019: width: 100%;
6020: background: $pgbg;
1.392 albertel 6021: border: 2px;
1.402 albertel 6022: border-collapse: separate;
1.803 bisitz 6023: padding: 0;
1.345 albertel 6024: }
1.392 albertel 6025:
1.801 tempelho 6026: table#LC_title_bar a {
6027: color: $fontmenu;
6028: }
1.836 bisitz 6029:
1.807 droeschl 6030: table#LC_title_bar {
1.819 tempelho 6031: clear: both;
1.836 bisitz 6032: display: none;
1.807 droeschl 6033: }
6034:
1.795 www 6035: table#LC_title_bar,
1.933 droeschl 6036: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6037: table#LC_title_bar.LC_with_remote {
1.359 albertel 6038: width: 100%;
1.392 albertel 6039: border-color: $pgbg;
6040: border-style: solid;
6041: border-width: $border;
1.379 albertel 6042: background: $pgbg;
1.801 tempelho 6043: color: $fontmenu;
1.392 albertel 6044: border-collapse: collapse;
1.803 bisitz 6045: padding: 0;
1.819 tempelho 6046: margin: 0;
1.359 albertel 6047: }
1.795 www 6048:
1.933 droeschl 6049: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6050: margin: 0;
6051: padding: 0;
1.933 droeschl 6052: position: relative;
6053: list-style: none;
1.913 droeschl 6054: }
1.933 droeschl 6055: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6056: display: inline;
6057: }
1.933 droeschl 6058:
6059: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6060: padding: 0;
1.933 droeschl 6061: margin: 0;
6062: float: left;
1.913 droeschl 6063: }
1.933 droeschl 6064: .LC_breadcrumb_tools_tools {
6065: padding: 0;
6066: margin: 0;
1.913 droeschl 6067: float: right;
6068: }
6069:
1.359 albertel 6070: table#LC_title_bar td {
6071: background: $tabbg;
6072: }
1.795 www 6073:
1.911 bisitz 6074: table#LC_menubuttons img {
1.803 bisitz 6075: border: none;
1.346 albertel 6076: }
1.795 www 6077:
1.842 droeschl 6078: .LC_breadcrumbs_component {
1.911 bisitz 6079: float: right;
6080: margin: 0 1em;
1.357 albertel 6081: }
1.842 droeschl 6082: .LC_breadcrumbs_component img {
1.911 bisitz 6083: vertical-align: middle;
1.777 tempelho 6084: }
1.795 www 6085:
1.1075.2.108 raeburn 6086: .LC_breadcrumbs_hoverable {
6087: background: $sidebg;
6088: }
6089:
1.383 albertel 6090: td.LC_table_cell_checkbox {
6091: text-align: center;
6092: }
1.795 www 6093:
6094: .LC_fontsize_small {
1.911 bisitz 6095: font-size: 70%;
1.705 tempelho 6096: }
6097:
1.844 bisitz 6098: #LC_breadcrumbs {
1.911 bisitz 6099: clear:both;
6100: background: $sidebg;
6101: border-bottom: 1px solid $lg_border_color;
6102: line-height: 2.5em;
1.933 droeschl 6103: overflow: hidden;
1.911 bisitz 6104: margin: 0;
6105: padding: 0;
1.995 raeburn 6106: text-align: left;
1.819 tempelho 6107: }
1.862 bisitz 6108:
1.1075.2.16 raeburn 6109: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6110: clear:both;
6111: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6112: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6113: margin: 0 0 10px 0;
1.966 bisitz 6114: padding: 3px;
1.995 raeburn 6115: text-align: left;
1.822 bisitz 6116: }
6117:
1.795 www 6118: .LC_fontsize_medium {
1.911 bisitz 6119: font-size: 85%;
1.705 tempelho 6120: }
6121:
1.795 www 6122: .LC_fontsize_large {
1.911 bisitz 6123: font-size: 120%;
1.705 tempelho 6124: }
6125:
1.346 albertel 6126: .LC_menubuttons_inline_text {
6127: color: $font;
1.698 harmsja 6128: font-size: 90%;
1.701 harmsja 6129: padding-left:3px;
1.346 albertel 6130: }
6131:
1.934 droeschl 6132: .LC_menubuttons_inline_text img{
6133: vertical-align: middle;
6134: }
6135:
1.1051 www 6136: li.LC_menubuttons_inline_text img {
1.951 onken 6137: cursor:pointer;
1.1002 droeschl 6138: text-decoration: none;
1.951 onken 6139: }
6140:
1.526 www 6141: .LC_menubuttons_link {
6142: text-decoration: none;
6143: }
1.795 www 6144:
1.522 albertel 6145: .LC_menubuttons_category {
1.521 www 6146: color: $font;
1.526 www 6147: background: $pgbg;
1.521 www 6148: font-size: larger;
6149: font-weight: bold;
6150: }
6151:
1.346 albertel 6152: td.LC_menubuttons_text {
1.911 bisitz 6153: color: $font;
1.346 albertel 6154: }
1.706 harmsja 6155:
1.346 albertel 6156: .LC_current_location {
6157: background: $tabbg;
6158: }
1.795 www 6159:
1.1075.2.134 raeburn 6160: td.LC_zero_height {
6161: line-height: 0;
6162: cellpadding: 0;
6163: }
6164:
1.938 bisitz 6165: table.LC_data_table {
1.347 albertel 6166: border: 1px solid #000000;
1.402 albertel 6167: border-collapse: separate;
1.426 albertel 6168: border-spacing: 1px;
1.610 albertel 6169: background: $pgbg;
1.347 albertel 6170: }
1.795 www 6171:
1.422 albertel 6172: .LC_data_table_dense {
6173: font-size: small;
6174: }
1.795 www 6175:
1.507 raeburn 6176: table.LC_nested_outer {
6177: border: 1px solid #000000;
1.589 raeburn 6178: border-collapse: collapse;
1.803 bisitz 6179: border-spacing: 0;
1.507 raeburn 6180: width: 100%;
6181: }
1.795 www 6182:
1.879 raeburn 6183: table.LC_innerpickbox,
1.507 raeburn 6184: table.LC_nested {
1.803 bisitz 6185: border: none;
1.589 raeburn 6186: border-collapse: collapse;
1.803 bisitz 6187: border-spacing: 0;
1.507 raeburn 6188: width: 100%;
6189: }
1.795 www 6190:
1.911 bisitz 6191: table.LC_data_table tr th,
6192: table.LC_calendar tr th,
1.879 raeburn 6193: table.LC_prior_tries tr th,
6194: table.LC_innerpickbox tr th {
1.349 albertel 6195: font-weight: bold;
6196: background-color: $data_table_head;
1.801 tempelho 6197: color:$fontmenu;
1.701 harmsja 6198: font-size:90%;
1.347 albertel 6199: }
1.795 www 6200:
1.879 raeburn 6201: table.LC_innerpickbox tr th,
6202: table.LC_innerpickbox tr td {
6203: vertical-align: top;
6204: }
6205:
1.711 raeburn 6206: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6207: background-color: #CCCCCC;
1.711 raeburn 6208: font-weight: bold;
6209: text-align: left;
6210: }
1.795 www 6211:
1.912 bisitz 6212: table.LC_data_table tr.LC_odd_row > td {
6213: background-color: $data_table_light;
6214: padding: 2px;
6215: vertical-align: top;
6216: }
6217:
1.809 bisitz 6218: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6219: background-color: $data_table_light;
1.912 bisitz 6220: vertical-align: top;
6221: }
6222:
6223: table.LC_data_table tr.LC_even_row > td {
6224: background-color: $data_table_dark;
1.425 albertel 6225: padding: 2px;
1.900 bisitz 6226: vertical-align: top;
1.347 albertel 6227: }
1.795 www 6228:
1.809 bisitz 6229: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6230: background-color: $data_table_dark;
1.900 bisitz 6231: vertical-align: top;
1.347 albertel 6232: }
1.795 www 6233:
1.425 albertel 6234: table.LC_data_table tr.LC_data_table_highlight td {
6235: background-color: $data_table_darker;
6236: }
1.795 www 6237:
1.639 raeburn 6238: table.LC_data_table tr td.LC_leftcol_header {
6239: background-color: $data_table_head;
6240: font-weight: bold;
6241: }
1.795 www 6242:
1.451 albertel 6243: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6244: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6245: font-weight: bold;
6246: font-style: italic;
6247: text-align: center;
6248: padding: 8px;
1.347 albertel 6249: }
1.795 www 6250:
1.1075.2.30 raeburn 6251: table.LC_data_table tr.LC_empty_row td,
6252: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6253: background-color: $sidebg;
6254: }
6255:
6256: table.LC_nested tr.LC_empty_row td {
6257: background-color: #FFFFFF;
6258: }
6259:
1.890 droeschl 6260: table.LC_caption {
6261: }
6262:
1.507 raeburn 6263: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6264: padding: 4ex
6265: }
1.795 www 6266:
1.507 raeburn 6267: table.LC_nested_outer tr th {
6268: font-weight: bold;
1.801 tempelho 6269: color:$fontmenu;
1.507 raeburn 6270: background-color: $data_table_head;
1.701 harmsja 6271: font-size: small;
1.507 raeburn 6272: border-bottom: 1px solid #000000;
6273: }
1.795 www 6274:
1.507 raeburn 6275: table.LC_nested_outer tr td.LC_subheader {
6276: background-color: $data_table_head;
6277: font-weight: bold;
6278: font-size: small;
6279: border-bottom: 1px solid #000000;
6280: text-align: right;
1.451 albertel 6281: }
1.795 www 6282:
1.507 raeburn 6283: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6284: background-color: #CCCCCC;
1.451 albertel 6285: font-weight: bold;
6286: font-size: small;
1.507 raeburn 6287: text-align: center;
6288: }
1.795 www 6289:
1.589 raeburn 6290: table.LC_nested tr.LC_info_row td.LC_left_item,
6291: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6292: text-align: left;
1.451 albertel 6293: }
1.795 www 6294:
1.507 raeburn 6295: table.LC_nested td {
1.735 bisitz 6296: background-color: #FFFFFF;
1.451 albertel 6297: font-size: small;
1.507 raeburn 6298: }
1.795 www 6299:
1.507 raeburn 6300: table.LC_nested_outer tr th.LC_right_item,
6301: table.LC_nested tr.LC_info_row td.LC_right_item,
6302: table.LC_nested tr.LC_odd_row td.LC_right_item,
6303: table.LC_nested tr td.LC_right_item {
1.451 albertel 6304: text-align: right;
6305: }
6306:
1.507 raeburn 6307: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6308: background-color: #EEEEEE;
1.451 albertel 6309: }
6310:
1.473 raeburn 6311: table.LC_createuser {
6312: }
6313:
6314: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6315: font-size: small;
1.473 raeburn 6316: }
6317:
6318: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6319: background-color: #CCCCCC;
1.473 raeburn 6320: font-weight: bold;
6321: text-align: center;
6322: }
6323:
1.349 albertel 6324: table.LC_calendar {
6325: border: 1px solid #000000;
6326: border-collapse: collapse;
1.917 raeburn 6327: width: 98%;
1.349 albertel 6328: }
1.795 www 6329:
1.349 albertel 6330: table.LC_calendar_pickdate {
6331: font-size: xx-small;
6332: }
1.795 www 6333:
1.349 albertel 6334: table.LC_calendar tr td {
6335: border: 1px solid #000000;
6336: vertical-align: top;
1.917 raeburn 6337: width: 14%;
1.349 albertel 6338: }
1.795 www 6339:
1.349 albertel 6340: table.LC_calendar tr td.LC_calendar_day_empty {
6341: background-color: $data_table_dark;
6342: }
1.795 www 6343:
1.779 bisitz 6344: table.LC_calendar tr td.LC_calendar_day_current {
6345: background-color: $data_table_highlight;
1.777 tempelho 6346: }
1.795 www 6347:
1.938 bisitz 6348: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6349: background-color: $mail_new;
6350: }
1.795 www 6351:
1.938 bisitz 6352: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6353: background-color: $mail_new_hover;
6354: }
1.795 www 6355:
1.938 bisitz 6356: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6357: background-color: $mail_read;
6358: }
1.795 www 6359:
1.938 bisitz 6360: /*
6361: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6362: background-color: $mail_read_hover;
6363: }
1.938 bisitz 6364: */
1.795 www 6365:
1.938 bisitz 6366: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6367: background-color: $mail_replied;
6368: }
1.795 www 6369:
1.938 bisitz 6370: /*
6371: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6372: background-color: $mail_replied_hover;
6373: }
1.938 bisitz 6374: */
1.795 www 6375:
1.938 bisitz 6376: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6377: background-color: $mail_other;
6378: }
1.795 www 6379:
1.938 bisitz 6380: /*
6381: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6382: background-color: $mail_other_hover;
6383: }
1.938 bisitz 6384: */
1.494 raeburn 6385:
1.777 tempelho 6386: table.LC_data_table tr > td.LC_browser_file,
6387: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6388: background: #AAEE77;
1.389 albertel 6389: }
1.795 www 6390:
1.777 tempelho 6391: table.LC_data_table tr > td.LC_browser_file_locked,
6392: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6393: background: #FFAA99;
1.387 albertel 6394: }
1.795 www 6395:
1.777 tempelho 6396: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6397: background: #888888;
1.779 bisitz 6398: }
1.795 www 6399:
1.777 tempelho 6400: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6401: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6402: background: #F8F866;
1.777 tempelho 6403: }
1.795 www 6404:
1.696 bisitz 6405: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6406: background: #E0E8FF;
1.387 albertel 6407: }
1.696 bisitz 6408:
1.707 bisitz 6409: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6410: /* background: #77FF77; */
1.707 bisitz 6411: }
1.795 www 6412:
1.707 bisitz 6413: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6414: border-right: 8px solid #FFFF77;
1.707 bisitz 6415: }
1.795 www 6416:
1.707 bisitz 6417: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6418: border-right: 8px solid #FFAA77;
1.707 bisitz 6419: }
1.795 www 6420:
1.707 bisitz 6421: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6422: border-right: 8px solid #FF7777;
1.707 bisitz 6423: }
1.795 www 6424:
1.707 bisitz 6425: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6426: border-right: 8px solid #AAFF77;
1.707 bisitz 6427: }
1.795 www 6428:
1.707 bisitz 6429: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6430: border-right: 8px solid #11CC55;
1.707 bisitz 6431: }
6432:
1.388 albertel 6433: span.LC_current_location {
1.701 harmsja 6434: font-size:larger;
1.388 albertel 6435: background: $pgbg;
6436: }
1.387 albertel 6437:
1.1029 www 6438: span.LC_current_nav_location {
6439: font-weight:bold;
6440: background: $sidebg;
6441: }
6442:
1.395 albertel 6443: span.LC_parm_menu_item {
6444: font-size: larger;
6445: }
1.795 www 6446:
1.395 albertel 6447: span.LC_parm_scope_all {
6448: color: red;
6449: }
1.795 www 6450:
1.395 albertel 6451: span.LC_parm_scope_folder {
6452: color: green;
6453: }
1.795 www 6454:
1.395 albertel 6455: span.LC_parm_scope_resource {
6456: color: orange;
6457: }
1.795 www 6458:
1.395 albertel 6459: span.LC_parm_part {
6460: color: blue;
6461: }
1.795 www 6462:
1.911 bisitz 6463: span.LC_parm_folder,
6464: span.LC_parm_symb {
1.395 albertel 6465: font-size: x-small;
6466: font-family: $mono;
6467: color: #AAAAAA;
6468: }
6469:
1.977 bisitz 6470: ul.LC_parm_parmlist li {
6471: display: inline-block;
6472: padding: 0.3em 0.8em;
6473: vertical-align: top;
6474: width: 150px;
6475: border-top:1px solid $lg_border_color;
6476: }
6477:
1.795 www 6478: td.LC_parm_overview_level_menu,
6479: td.LC_parm_overview_map_menu,
6480: td.LC_parm_overview_parm_selectors,
6481: td.LC_parm_overview_restrictions {
1.396 albertel 6482: border: 1px solid black;
6483: border-collapse: collapse;
6484: }
1.795 www 6485:
1.396 albertel 6486: table.LC_parm_overview_restrictions td {
6487: border-width: 1px 4px 1px 4px;
6488: border-style: solid;
6489: border-color: $pgbg;
6490: text-align: center;
6491: }
1.795 www 6492:
1.396 albertel 6493: table.LC_parm_overview_restrictions th {
6494: background: $tabbg;
6495: border-width: 1px 4px 1px 4px;
6496: border-style: solid;
6497: border-color: $pgbg;
6498: }
1.795 www 6499:
1.398 albertel 6500: table#LC_helpmenu {
1.803 bisitz 6501: border: none;
1.398 albertel 6502: height: 55px;
1.803 bisitz 6503: border-spacing: 0;
1.398 albertel 6504: }
6505:
6506: table#LC_helpmenu fieldset legend {
6507: font-size: larger;
6508: }
1.795 www 6509:
1.397 albertel 6510: table#LC_helpmenu_links {
6511: width: 100%;
6512: border: 1px solid black;
6513: background: $pgbg;
1.803 bisitz 6514: padding: 0;
1.397 albertel 6515: border-spacing: 1px;
6516: }
1.795 www 6517:
1.397 albertel 6518: table#LC_helpmenu_links tr td {
6519: padding: 1px;
6520: background: $tabbg;
1.399 albertel 6521: text-align: center;
6522: font-weight: bold;
1.397 albertel 6523: }
1.396 albertel 6524:
1.795 www 6525: table#LC_helpmenu_links a:link,
6526: table#LC_helpmenu_links a:visited,
1.397 albertel 6527: table#LC_helpmenu_links a:active {
6528: text-decoration: none;
6529: color: $font;
6530: }
1.795 www 6531:
1.397 albertel 6532: table#LC_helpmenu_links a:hover {
6533: text-decoration: underline;
6534: color: $vlink;
6535: }
1.396 albertel 6536:
1.417 albertel 6537: .LC_chrt_popup_exists {
6538: border: 1px solid #339933;
6539: margin: -1px;
6540: }
1.795 www 6541:
1.417 albertel 6542: .LC_chrt_popup_up {
6543: border: 1px solid yellow;
6544: margin: -1px;
6545: }
1.795 www 6546:
1.417 albertel 6547: .LC_chrt_popup {
6548: border: 1px solid #8888FF;
6549: background: #CCCCFF;
6550: }
1.795 www 6551:
1.421 albertel 6552: table.LC_pick_box {
6553: border-collapse: separate;
6554: background: white;
6555: border: 1px solid black;
6556: border-spacing: 1px;
6557: }
1.795 www 6558:
1.421 albertel 6559: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6560: background: $sidebg;
1.421 albertel 6561: font-weight: bold;
1.900 bisitz 6562: text-align: left;
1.740 bisitz 6563: vertical-align: top;
1.421 albertel 6564: width: 184px;
6565: padding: 8px;
6566: }
1.795 www 6567:
1.579 raeburn 6568: table.LC_pick_box td.LC_pick_box_value {
6569: text-align: left;
6570: padding: 8px;
6571: }
1.795 www 6572:
1.579 raeburn 6573: table.LC_pick_box td.LC_pick_box_select {
6574: text-align: left;
6575: padding: 8px;
6576: }
1.795 www 6577:
1.424 albertel 6578: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6579: padding: 0;
1.421 albertel 6580: height: 1px;
6581: background: black;
6582: }
1.795 www 6583:
1.421 albertel 6584: table.LC_pick_box td.LC_pick_box_submit {
6585: text-align: right;
6586: }
1.795 www 6587:
1.579 raeburn 6588: table.LC_pick_box td.LC_evenrow_value {
6589: text-align: left;
6590: padding: 8px;
6591: background-color: $data_table_light;
6592: }
1.795 www 6593:
1.579 raeburn 6594: table.LC_pick_box td.LC_oddrow_value {
6595: text-align: left;
6596: padding: 8px;
6597: background-color: $data_table_light;
6598: }
1.795 www 6599:
1.579 raeburn 6600: span.LC_helpform_receipt_cat {
6601: font-weight: bold;
6602: }
1.795 www 6603:
1.424 albertel 6604: table.LC_group_priv_box {
6605: background: white;
6606: border: 1px solid black;
6607: border-spacing: 1px;
6608: }
1.795 www 6609:
1.424 albertel 6610: table.LC_group_priv_box td.LC_pick_box_title {
6611: background: $tabbg;
6612: font-weight: bold;
6613: text-align: right;
6614: width: 184px;
6615: }
1.795 www 6616:
1.424 albertel 6617: table.LC_group_priv_box td.LC_groups_fixed {
6618: background: $data_table_light;
6619: text-align: center;
6620: }
1.795 www 6621:
1.424 albertel 6622: table.LC_group_priv_box td.LC_groups_optional {
6623: background: $data_table_dark;
6624: text-align: center;
6625: }
1.795 www 6626:
1.424 albertel 6627: table.LC_group_priv_box td.LC_groups_functionality {
6628: background: $data_table_darker;
6629: text-align: center;
6630: font-weight: bold;
6631: }
1.795 www 6632:
1.424 albertel 6633: table.LC_group_priv td {
6634: text-align: left;
1.803 bisitz 6635: padding: 0;
1.424 albertel 6636: }
6637:
6638: .LC_navbuttons {
6639: margin: 2ex 0ex 2ex 0ex;
6640: }
1.795 www 6641:
1.423 albertel 6642: .LC_topic_bar {
6643: font-weight: bold;
6644: background: $tabbg;
1.918 wenzelju 6645: margin: 1em 0em 1em 2em;
1.805 bisitz 6646: padding: 3px;
1.918 wenzelju 6647: font-size: 1.2em;
1.423 albertel 6648: }
1.795 www 6649:
1.423 albertel 6650: .LC_topic_bar span {
1.918 wenzelju 6651: left: 0.5em;
6652: position: absolute;
1.423 albertel 6653: vertical-align: middle;
1.918 wenzelju 6654: font-size: 1.2em;
1.423 albertel 6655: }
1.795 www 6656:
1.423 albertel 6657: table.LC_course_group_status {
6658: margin: 20px;
6659: }
1.795 www 6660:
1.423 albertel 6661: table.LC_status_selector td {
6662: vertical-align: top;
6663: text-align: center;
1.424 albertel 6664: padding: 4px;
6665: }
1.795 www 6666:
1.599 albertel 6667: div.LC_feedback_link {
1.616 albertel 6668: clear: both;
1.829 kalberla 6669: background: $sidebg;
1.779 bisitz 6670: width: 100%;
1.829 kalberla 6671: padding-bottom: 10px;
6672: border: 1px $tabbg solid;
1.833 kalberla 6673: height: 22px;
6674: line-height: 22px;
6675: padding-top: 5px;
6676: }
6677:
6678: div.LC_feedback_link img {
6679: height: 22px;
1.867 kalberla 6680: vertical-align:middle;
1.829 kalberla 6681: }
6682:
1.911 bisitz 6683: div.LC_feedback_link a {
1.829 kalberla 6684: text-decoration: none;
1.489 raeburn 6685: }
1.795 www 6686:
1.867 kalberla 6687: div.LC_comblock {
1.911 bisitz 6688: display:inline;
1.867 kalberla 6689: color:$font;
6690: font-size:90%;
6691: }
6692:
6693: div.LC_feedback_link div.LC_comblock {
6694: padding-left:5px;
6695: }
6696:
6697: div.LC_feedback_link div.LC_comblock a {
6698: color:$font;
6699: }
6700:
1.489 raeburn 6701: span.LC_feedback_link {
1.858 bisitz 6702: /* background: $feedback_link_bg; */
1.599 albertel 6703: font-size: larger;
6704: }
1.795 www 6705:
1.599 albertel 6706: span.LC_message_link {
1.858 bisitz 6707: /* background: $feedback_link_bg; */
1.599 albertel 6708: font-size: larger;
6709: position: absolute;
6710: right: 1em;
1.489 raeburn 6711: }
1.421 albertel 6712:
1.515 albertel 6713: table.LC_prior_tries {
1.524 albertel 6714: border: 1px solid #000000;
6715: border-collapse: separate;
6716: border-spacing: 1px;
1.515 albertel 6717: }
1.523 albertel 6718:
1.515 albertel 6719: table.LC_prior_tries td {
1.524 albertel 6720: padding: 2px;
1.515 albertel 6721: }
1.523 albertel 6722:
6723: .LC_answer_correct {
1.795 www 6724: background: lightgreen;
6725: color: darkgreen;
6726: padding: 6px;
1.523 albertel 6727: }
1.795 www 6728:
1.523 albertel 6729: .LC_answer_charged_try {
1.797 www 6730: background: #FFAAAA;
1.795 www 6731: color: darkred;
6732: padding: 6px;
1.523 albertel 6733: }
1.795 www 6734:
1.779 bisitz 6735: .LC_answer_not_charged_try,
1.523 albertel 6736: .LC_answer_no_grade,
6737: .LC_answer_late {
1.795 www 6738: background: lightyellow;
1.523 albertel 6739: color: black;
1.795 www 6740: padding: 6px;
1.523 albertel 6741: }
1.795 www 6742:
1.523 albertel 6743: .LC_answer_previous {
1.795 www 6744: background: lightblue;
6745: color: darkblue;
6746: padding: 6px;
1.523 albertel 6747: }
1.795 www 6748:
1.779 bisitz 6749: .LC_answer_no_message {
1.777 tempelho 6750: background: #FFFFFF;
6751: color: black;
1.795 www 6752: padding: 6px;
1.779 bisitz 6753: }
1.795 www 6754:
1.779 bisitz 6755: .LC_answer_unknown {
6756: background: orange;
6757: color: black;
1.795 www 6758: padding: 6px;
1.777 tempelho 6759: }
1.795 www 6760:
1.529 albertel 6761: span.LC_prior_numerical,
6762: span.LC_prior_string,
6763: span.LC_prior_custom,
6764: span.LC_prior_reaction,
6765: span.LC_prior_math {
1.925 bisitz 6766: font-family: $mono;
1.523 albertel 6767: white-space: pre;
6768: }
6769:
1.525 albertel 6770: span.LC_prior_string {
1.925 bisitz 6771: font-family: $mono;
1.525 albertel 6772: white-space: pre;
6773: }
6774:
1.523 albertel 6775: table.LC_prior_option {
6776: width: 100%;
6777: border-collapse: collapse;
6778: }
1.795 www 6779:
1.911 bisitz 6780: table.LC_prior_rank,
1.795 www 6781: table.LC_prior_match {
1.528 albertel 6782: border-collapse: collapse;
6783: }
1.795 www 6784:
1.528 albertel 6785: table.LC_prior_option tr td,
6786: table.LC_prior_rank tr td,
6787: table.LC_prior_match tr td {
1.524 albertel 6788: border: 1px solid #000000;
1.515 albertel 6789: }
6790:
1.855 bisitz 6791: .LC_nobreak {
1.544 albertel 6792: white-space: nowrap;
1.519 raeburn 6793: }
6794:
1.576 raeburn 6795: span.LC_cusr_emph {
6796: font-style: italic;
6797: }
6798:
1.633 raeburn 6799: span.LC_cusr_subheading {
6800: font-weight: normal;
6801: font-size: 85%;
6802: }
6803:
1.861 bisitz 6804: div.LC_docs_entry_move {
1.859 bisitz 6805: border: 1px solid #BBBBBB;
1.545 albertel 6806: background: #DDDDDD;
1.861 bisitz 6807: width: 22px;
1.859 bisitz 6808: padding: 1px;
6809: margin: 0;
1.545 albertel 6810: }
6811:
1.861 bisitz 6812: table.LC_data_table tr > td.LC_docs_entry_commands,
6813: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6814: font-size: x-small;
6815: }
1.795 www 6816:
1.861 bisitz 6817: .LC_docs_entry_parameter {
6818: white-space: nowrap;
6819: }
6820:
1.544 albertel 6821: .LC_docs_copy {
1.545 albertel 6822: color: #000099;
1.544 albertel 6823: }
1.795 www 6824:
1.544 albertel 6825: .LC_docs_cut {
1.545 albertel 6826: color: #550044;
1.544 albertel 6827: }
1.795 www 6828:
1.544 albertel 6829: .LC_docs_rename {
1.545 albertel 6830: color: #009900;
1.544 albertel 6831: }
1.795 www 6832:
1.544 albertel 6833: .LC_docs_remove {
1.545 albertel 6834: color: #990000;
6835: }
6836:
1.1075.2.134 raeburn 6837: .LC_domprefs_email,
1.547 albertel 6838: .LC_docs_reinit_warn,
6839: .LC_docs_ext_edit {
6840: font-size: x-small;
6841: }
6842:
1.545 albertel 6843: table.LC_docs_adddocs td,
6844: table.LC_docs_adddocs th {
6845: border: 1px solid #BBBBBB;
6846: padding: 4px;
6847: background: #DDDDDD;
1.543 albertel 6848: }
6849:
1.584 albertel 6850: table.LC_sty_begin {
6851: background: #BBFFBB;
6852: }
1.795 www 6853:
1.584 albertel 6854: table.LC_sty_end {
6855: background: #FFBBBB;
6856: }
6857:
1.589 raeburn 6858: table.LC_double_column {
1.803 bisitz 6859: border-width: 0;
1.589 raeburn 6860: border-collapse: collapse;
6861: width: 100%;
6862: padding: 2px;
6863: }
6864:
6865: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6866: top: 2px;
1.589 raeburn 6867: left: 2px;
6868: width: 47%;
6869: vertical-align: top;
6870: }
6871:
6872: table.LC_double_column tr td.LC_right_col {
6873: top: 2px;
1.779 bisitz 6874: right: 2px;
1.589 raeburn 6875: width: 47%;
6876: vertical-align: top;
6877: }
6878:
1.591 raeburn 6879: div.LC_left_float {
6880: float: left;
6881: padding-right: 5%;
1.597 albertel 6882: padding-bottom: 4px;
1.591 raeburn 6883: }
6884:
6885: div.LC_clear_float_header {
1.597 albertel 6886: padding-bottom: 2px;
1.591 raeburn 6887: }
6888:
6889: div.LC_clear_float_footer {
1.597 albertel 6890: padding-top: 10px;
1.591 raeburn 6891: clear: both;
6892: }
6893:
1.597 albertel 6894: div.LC_grade_show_user {
1.941 bisitz 6895: /* border-left: 5px solid $sidebg; */
6896: border-top: 5px solid #000000;
6897: margin: 50px 0 0 0;
1.936 bisitz 6898: padding: 15px 0 5px 10px;
1.597 albertel 6899: }
1.795 www 6900:
1.936 bisitz 6901: div.LC_grade_show_user_odd_row {
1.941 bisitz 6902: /* border-left: 5px solid #000000; */
6903: }
6904:
6905: div.LC_grade_show_user div.LC_Box {
6906: margin-right: 50px;
1.597 albertel 6907: }
6908:
6909: div.LC_grade_submissions,
6910: div.LC_grade_message_center,
1.936 bisitz 6911: div.LC_grade_info_links {
1.597 albertel 6912: margin: 5px;
6913: width: 99%;
6914: background: #FFFFFF;
6915: }
1.795 www 6916:
1.597 albertel 6917: div.LC_grade_submissions_header,
1.936 bisitz 6918: div.LC_grade_message_center_header {
1.705 tempelho 6919: font-weight: bold;
6920: font-size: large;
1.597 albertel 6921: }
1.795 www 6922:
1.597 albertel 6923: div.LC_grade_submissions_body,
1.936 bisitz 6924: div.LC_grade_message_center_body {
1.597 albertel 6925: border: 1px solid black;
6926: width: 99%;
6927: background: #FFFFFF;
6928: }
1.795 www 6929:
1.613 albertel 6930: table.LC_scantron_action {
6931: width: 100%;
6932: }
1.795 www 6933:
1.613 albertel 6934: table.LC_scantron_action tr th {
1.698 harmsja 6935: font-weight:bold;
6936: font-style:normal;
1.613 albertel 6937: }
1.795 www 6938:
1.779 bisitz 6939: .LC_edit_problem_header,
1.614 albertel 6940: div.LC_edit_problem_footer {
1.705 tempelho 6941: font-weight: normal;
6942: font-size: medium;
1.602 albertel 6943: margin: 2px;
1.1060 bisitz 6944: background-color: $sidebg;
1.600 albertel 6945: }
1.795 www 6946:
1.600 albertel 6947: div.LC_edit_problem_header,
1.602 albertel 6948: div.LC_edit_problem_header div,
1.614 albertel 6949: div.LC_edit_problem_footer,
6950: div.LC_edit_problem_footer div,
1.602 albertel 6951: div.LC_edit_problem_editxml_header,
6952: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 6953: z-index: 100;
1.600 albertel 6954: }
1.795 www 6955:
1.600 albertel 6956: div.LC_edit_problem_header_title {
1.705 tempelho 6957: font-weight: bold;
6958: font-size: larger;
1.602 albertel 6959: background: $tabbg;
6960: padding: 3px;
1.1060 bisitz 6961: margin: 0 0 5px 0;
1.602 albertel 6962: }
1.795 www 6963:
1.602 albertel 6964: table.LC_edit_problem_header_title {
6965: width: 100%;
1.600 albertel 6966: background: $tabbg;
1.602 albertel 6967: }
6968:
1.1075.2.112 raeburn 6969: div.LC_edit_actionbar {
6970: background-color: $sidebg;
6971: margin: 0;
6972: padding: 0;
6973: line-height: 200%;
1.602 albertel 6974: }
1.795 www 6975:
1.1075.2.112 raeburn 6976: div.LC_edit_actionbar div{
6977: padding: 0;
6978: margin: 0;
6979: display: inline-block;
1.600 albertel 6980: }
1.795 www 6981:
1.1075.2.34 raeburn 6982: .LC_edit_opt {
6983: padding-left: 1em;
6984: white-space: nowrap;
6985: }
6986:
1.1075.2.57 raeburn 6987: .LC_edit_problem_latexhelper{
6988: text-align: right;
6989: }
6990:
6991: #LC_edit_problem_colorful div{
6992: margin-left: 40px;
6993: }
6994:
1.1075.2.112 raeburn 6995: #LC_edit_problem_codemirror div{
6996: margin-left: 0px;
6997: }
6998:
1.911 bisitz 6999: img.stift {
1.803 bisitz 7000: border-width: 0;
7001: vertical-align: middle;
1.677 riegler 7002: }
1.680 riegler 7003:
1.923 bisitz 7004: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7005: vertical-align: top;
1.777 tempelho 7006: }
1.795 www 7007:
1.716 raeburn 7008: div.LC_createcourse {
1.911 bisitz 7009: margin: 10px 10px 10px 10px;
1.716 raeburn 7010: }
7011:
1.917 raeburn 7012: .LC_dccid {
1.1075.2.38 raeburn 7013: float: right;
1.917 raeburn 7014: margin: 0.2em 0 0 0;
7015: padding: 0;
7016: font-size: 90%;
7017: display:none;
7018: }
7019:
1.897 wenzelju 7020: ol.LC_primary_menu a:hover,
1.721 harmsja 7021: ol#LC_MenuBreadcrumbs a:hover,
7022: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7023: ul#LC_secondary_menu a:hover,
1.721 harmsja 7024: .LC_FormSectionClearButton input:hover
1.795 www 7025: ul.LC_TabContent li:hover a {
1.952 onken 7026: color:$button_hover;
1.911 bisitz 7027: text-decoration:none;
1.693 droeschl 7028: }
7029:
1.779 bisitz 7030: h1 {
1.911 bisitz 7031: padding: 0;
7032: line-height:130%;
1.693 droeschl 7033: }
1.698 harmsja 7034:
1.911 bisitz 7035: h2,
7036: h3,
7037: h4,
7038: h5,
7039: h6 {
7040: margin: 5px 0 5px 0;
7041: padding: 0;
7042: line-height:130%;
1.693 droeschl 7043: }
1.795 www 7044:
7045: .LC_hcell {
1.911 bisitz 7046: padding:3px 15px 3px 15px;
7047: margin: 0;
7048: background-color:$tabbg;
7049: color:$fontmenu;
7050: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7051: }
1.795 www 7052:
1.840 bisitz 7053: .LC_Box > .LC_hcell {
1.911 bisitz 7054: margin: 0 -10px 10px -10px;
1.835 bisitz 7055: }
7056:
1.721 harmsja 7057: .LC_noBorder {
1.911 bisitz 7058: border: 0;
1.698 harmsja 7059: }
1.693 droeschl 7060:
1.721 harmsja 7061: .LC_FormSectionClearButton input {
1.911 bisitz 7062: background-color:transparent;
7063: border: none;
7064: cursor:pointer;
7065: text-decoration:underline;
1.693 droeschl 7066: }
1.763 bisitz 7067:
7068: .LC_help_open_topic {
1.911 bisitz 7069: color: #FFFFFF;
7070: background-color: #EEEEFF;
7071: margin: 1px;
7072: padding: 4px;
7073: border: 1px solid #000033;
7074: white-space: nowrap;
7075: /* vertical-align: middle; */
1.759 neumanie 7076: }
1.693 droeschl 7077:
1.911 bisitz 7078: dl,
7079: ul,
7080: div,
7081: fieldset {
7082: margin: 10px 10px 10px 0;
7083: /* overflow: hidden; */
1.693 droeschl 7084: }
1.795 www 7085:
1.1075.2.90 raeburn 7086: article.geogebraweb div {
7087: margin: 0;
7088: }
7089:
1.838 bisitz 7090: fieldset > legend {
1.911 bisitz 7091: font-weight: bold;
7092: padding: 0 5px 0 5px;
1.838 bisitz 7093: }
7094:
1.813 bisitz 7095: #LC_nav_bar {
1.911 bisitz 7096: float: left;
1.995 raeburn 7097: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7098: margin: 0 0 2px 0;
1.807 droeschl 7099: }
7100:
1.916 droeschl 7101: #LC_realm {
7102: margin: 0.2em 0 0 0;
7103: padding: 0;
7104: font-weight: bold;
7105: text-align: center;
1.995 raeburn 7106: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7107: }
7108:
1.911 bisitz 7109: #LC_nav_bar em {
7110: font-weight: bold;
7111: font-style: normal;
1.807 droeschl 7112: }
7113:
1.897 wenzelju 7114: ol.LC_primary_menu {
1.934 droeschl 7115: margin: 0;
1.1075.2.2 raeburn 7116: padding: 0;
1.807 droeschl 7117: }
7118:
1.852 droeschl 7119: ol#LC_PathBreadcrumbs {
1.911 bisitz 7120: margin: 0;
1.693 droeschl 7121: }
7122:
1.897 wenzelju 7123: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7124: color: RGB(80, 80, 80);
7125: vertical-align: middle;
7126: text-align: left;
7127: list-style: none;
1.1075.2.112 raeburn 7128: position: relative;
1.1075.2.2 raeburn 7129: float: left;
1.1075.2.112 raeburn 7130: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7131: line-height: 1.5em;
1.1075.2.2 raeburn 7132: }
7133:
1.1075.2.113 raeburn 7134: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7135: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7136: display: block;
7137: margin: 0;
7138: padding: 0 5px 0 10px;
7139: text-decoration: none;
7140: }
7141:
1.1075.2.112 raeburn 7142: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7143: display: inline-block;
7144: width: 95%;
7145: text-align: left;
7146: }
7147:
7148: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7149: display: inline-block;
7150: width: 5%;
7151: float: right;
7152: text-align: right;
7153: font-size: 70%;
7154: }
7155:
7156: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7157: display: none;
1.1075.2.112 raeburn 7158: width: 15em;
1.1075.2.2 raeburn 7159: background-color: $data_table_light;
1.1075.2.112 raeburn 7160: position: absolute;
7161: top: 100%;
7162: }
7163:
7164: ol.LC_primary_menu ul ul {
7165: left: 100%;
7166: top: 0;
1.1075.2.2 raeburn 7167: }
7168:
1.1075.2.112 raeburn 7169: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7170: display: block;
7171: position: absolute;
7172: margin: 0;
7173: padding: 0;
1.1075.2.5 raeburn 7174: z-index: 2;
1.1075.2.2 raeburn 7175: }
7176:
7177: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7178: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7179: font-size: 90%;
1.911 bisitz 7180: vertical-align: top;
1.1075.2.2 raeburn 7181: float: none;
1.1075.2.5 raeburn 7182: border-left: 1px solid black;
7183: border-right: 1px solid black;
1.1075.2.112 raeburn 7184: /* A dark bottom border to visualize different menu options;
7185: overwritten in the create_submenu routine for the last border-bottom of the menu */
7186: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7187: }
7188:
1.1075.2.112 raeburn 7189: ol.LC_primary_menu li li p:hover {
7190: color:$button_hover;
7191: text-decoration:none;
7192: background-color:$data_table_dark;
1.1075.2.2 raeburn 7193: }
7194:
7195: ol.LC_primary_menu li li a:hover {
7196: color:$button_hover;
7197: background-color:$data_table_dark;
1.693 droeschl 7198: }
7199:
1.1075.2.112 raeburn 7200: /* Font-size equal to the size of the predecessors*/
7201: ol.LC_primary_menu li:hover li li {
7202: font-size: 100%;
7203: }
7204:
1.897 wenzelju 7205: ol.LC_primary_menu li img {
1.911 bisitz 7206: vertical-align: bottom;
1.934 droeschl 7207: height: 1.1em;
1.1075.2.3 raeburn 7208: margin: 0.2em 0 0 0;
1.693 droeschl 7209: }
7210:
1.897 wenzelju 7211: ol.LC_primary_menu a {
1.911 bisitz 7212: color: RGB(80, 80, 80);
7213: text-decoration: none;
1.693 droeschl 7214: }
1.795 www 7215:
1.949 droeschl 7216: ol.LC_primary_menu a.LC_new_message {
7217: font-weight:bold;
7218: color: darkred;
7219: }
7220:
1.975 raeburn 7221: ol.LC_docs_parameters {
7222: margin-left: 0;
7223: padding: 0;
7224: list-style: none;
7225: }
7226:
7227: ol.LC_docs_parameters li {
7228: margin: 0;
7229: padding-right: 20px;
7230: display: inline;
7231: }
7232:
1.976 raeburn 7233: ol.LC_docs_parameters li:before {
7234: content: "\\002022 \\0020";
7235: }
7236:
7237: li.LC_docs_parameters_title {
7238: font-weight: bold;
7239: }
7240:
7241: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7242: content: "";
7243: }
7244:
1.897 wenzelju 7245: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7246: clear: right;
1.911 bisitz 7247: color: $fontmenu;
7248: background: $tabbg;
7249: list-style: none;
7250: padding: 0;
7251: margin: 0;
7252: width: 100%;
1.995 raeburn 7253: text-align: left;
1.1075.2.4 raeburn 7254: float: left;
1.808 droeschl 7255: }
7256:
1.897 wenzelju 7257: ul#LC_secondary_menu li {
1.911 bisitz 7258: font-weight: bold;
7259: line-height: 1.8em;
7260: border-right: 1px solid black;
1.1075.2.4 raeburn 7261: float: left;
7262: }
7263:
7264: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7265: background-color: $data_table_light;
7266: }
7267:
7268: ul#LC_secondary_menu li a {
7269: padding: 0 0.8em;
7270: }
7271:
7272: ul#LC_secondary_menu li ul {
7273: display: none;
7274: }
7275:
7276: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7277: display: block;
7278: position: absolute;
7279: margin: 0;
7280: padding: 0;
7281: list-style:none;
7282: float: none;
7283: background-color: $data_table_light;
1.1075.2.5 raeburn 7284: z-index: 2;
1.1075.2.10 raeburn 7285: margin-left: -1px;
1.1075.2.4 raeburn 7286: }
7287:
7288: ul#LC_secondary_menu li ul li {
7289: font-size: 90%;
7290: vertical-align: top;
7291: border-left: 1px solid black;
7292: border-right: 1px solid black;
1.1075.2.33 raeburn 7293: background-color: $data_table_light;
1.1075.2.4 raeburn 7294: list-style:none;
7295: float: none;
7296: }
7297:
7298: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7299: background-color: $data_table_dark;
1.807 droeschl 7300: }
7301:
1.847 tempelho 7302: ul.LC_TabContent {
1.911 bisitz 7303: display:block;
7304: background: $sidebg;
7305: border-bottom: solid 1px $lg_border_color;
7306: list-style:none;
1.1020 raeburn 7307: margin: -1px -10px 0 -10px;
1.911 bisitz 7308: padding: 0;
1.693 droeschl 7309: }
7310:
1.795 www 7311: ul.LC_TabContent li,
7312: ul.LC_TabContentBigger li {
1.911 bisitz 7313: float:left;
1.741 harmsja 7314: }
1.795 www 7315:
1.897 wenzelju 7316: ul#LC_secondary_menu li a {
1.911 bisitz 7317: color: $fontmenu;
7318: text-decoration: none;
1.693 droeschl 7319: }
1.795 www 7320:
1.721 harmsja 7321: ul.LC_TabContent {
1.952 onken 7322: min-height:20px;
1.721 harmsja 7323: }
1.795 www 7324:
7325: ul.LC_TabContent li {
1.911 bisitz 7326: vertical-align:middle;
1.959 onken 7327: padding: 0 16px 0 10px;
1.911 bisitz 7328: background-color:$tabbg;
7329: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7330: border-left: solid 1px $font;
1.721 harmsja 7331: }
1.795 www 7332:
1.847 tempelho 7333: ul.LC_TabContent .right {
1.911 bisitz 7334: float:right;
1.847 tempelho 7335: }
7336:
1.911 bisitz 7337: ul.LC_TabContent li a,
7338: ul.LC_TabContent li {
7339: color:rgb(47,47,47);
7340: text-decoration:none;
7341: font-size:95%;
7342: font-weight:bold;
1.952 onken 7343: min-height:20px;
7344: }
7345:
1.959 onken 7346: ul.LC_TabContent li a:hover,
7347: ul.LC_TabContent li a:focus {
1.952 onken 7348: color: $button_hover;
1.959 onken 7349: background:none;
7350: outline:none;
1.952 onken 7351: }
7352:
7353: ul.LC_TabContent li:hover {
7354: color: $button_hover;
7355: cursor:pointer;
1.721 harmsja 7356: }
1.795 www 7357:
1.911 bisitz 7358: ul.LC_TabContent li.active {
1.952 onken 7359: color: $font;
1.911 bisitz 7360: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7361: border-bottom:solid 1px #FFFFFF;
7362: cursor: default;
1.744 ehlerst 7363: }
1.795 www 7364:
1.959 onken 7365: ul.LC_TabContent li.active a {
7366: color:$font;
7367: background:#FFFFFF;
7368: outline: none;
7369: }
1.1047 raeburn 7370:
7371: ul.LC_TabContent li.goback {
7372: float: left;
7373: border-left: none;
7374: }
7375:
1.870 tempelho 7376: #maincoursedoc {
1.911 bisitz 7377: clear:both;
1.870 tempelho 7378: }
7379:
7380: ul.LC_TabContentBigger {
1.911 bisitz 7381: display:block;
7382: list-style:none;
7383: padding: 0;
1.870 tempelho 7384: }
7385:
1.795 www 7386: ul.LC_TabContentBigger li {
1.911 bisitz 7387: vertical-align:bottom;
7388: height: 30px;
7389: font-size:110%;
7390: font-weight:bold;
7391: color: #737373;
1.841 tempelho 7392: }
7393:
1.957 onken 7394: ul.LC_TabContentBigger li.active {
7395: position: relative;
7396: top: 1px;
7397: }
7398:
1.870 tempelho 7399: ul.LC_TabContentBigger li a {
1.911 bisitz 7400: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7401: height: 30px;
7402: line-height: 30px;
7403: text-align: center;
7404: display: block;
7405: text-decoration: none;
1.958 onken 7406: outline: none;
1.741 harmsja 7407: }
1.795 www 7408:
1.870 tempelho 7409: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7410: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7411: color:$font;
1.744 ehlerst 7412: }
1.795 www 7413:
1.870 tempelho 7414: ul.LC_TabContentBigger li b {
1.911 bisitz 7415: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7416: display: block;
7417: float: left;
7418: padding: 0 30px;
1.957 onken 7419: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7420: }
7421:
1.956 onken 7422: ul.LC_TabContentBigger li:hover b {
7423: color:$button_hover;
7424: }
7425:
1.870 tempelho 7426: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7427: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7428: color:$font;
1.957 onken 7429: border: 0;
1.741 harmsja 7430: }
1.693 droeschl 7431:
1.870 tempelho 7432:
1.862 bisitz 7433: ul.LC_CourseBreadcrumbs {
7434: background: $sidebg;
1.1020 raeburn 7435: height: 2em;
1.862 bisitz 7436: padding-left: 10px;
1.1020 raeburn 7437: margin: 0;
1.862 bisitz 7438: list-style-position: inside;
7439: }
7440:
1.911 bisitz 7441: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7442: ol#LC_PathBreadcrumbs {
1.911 bisitz 7443: padding-left: 10px;
7444: margin: 0;
1.933 droeschl 7445: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7446: }
7447:
1.911 bisitz 7448: ol#LC_MenuBreadcrumbs li,
7449: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7450: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7451: display: inline;
1.933 droeschl 7452: white-space: normal;
1.693 droeschl 7453: }
7454:
1.823 bisitz 7455: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7456: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7457: text-decoration: none;
7458: font-size:90%;
1.693 droeschl 7459: }
1.795 www 7460:
1.969 droeschl 7461: ol#LC_MenuBreadcrumbs h1 {
7462: display: inline;
7463: font-size: 90%;
7464: line-height: 2.5em;
7465: margin: 0;
7466: padding: 0;
7467: }
7468:
1.795 www 7469: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7470: text-decoration:none;
7471: font-size:100%;
7472: font-weight:bold;
1.693 droeschl 7473: }
1.795 www 7474:
1.840 bisitz 7475: .LC_Box {
1.911 bisitz 7476: border: solid 1px $lg_border_color;
7477: padding: 0 10px 10px 10px;
1.746 neumanie 7478: }
1.795 www 7479:
1.1020 raeburn 7480: .LC_DocsBox {
7481: border: solid 1px $lg_border_color;
7482: padding: 0 0 10px 10px;
7483: }
7484:
1.795 www 7485: .LC_AboutMe_Image {
1.911 bisitz 7486: float:left;
7487: margin-right:10px;
1.747 neumanie 7488: }
1.795 www 7489:
7490: .LC_Clear_AboutMe_Image {
1.911 bisitz 7491: clear:left;
1.747 neumanie 7492: }
1.795 www 7493:
1.721 harmsja 7494: dl.LC_ListStyleClean dt {
1.911 bisitz 7495: padding-right: 5px;
7496: display: table-header-group;
1.693 droeschl 7497: }
7498:
1.721 harmsja 7499: dl.LC_ListStyleClean dd {
1.911 bisitz 7500: display: table-row;
1.693 droeschl 7501: }
7502:
1.721 harmsja 7503: .LC_ListStyleClean,
7504: .LC_ListStyleSimple,
7505: .LC_ListStyleNormal,
1.795 www 7506: .LC_ListStyleSpecial {
1.911 bisitz 7507: /* display:block; */
7508: list-style-position: inside;
7509: list-style-type: none;
7510: overflow: hidden;
7511: padding: 0;
1.693 droeschl 7512: }
7513:
1.721 harmsja 7514: .LC_ListStyleSimple li,
7515: .LC_ListStyleSimple dd,
7516: .LC_ListStyleNormal li,
7517: .LC_ListStyleNormal dd,
7518: .LC_ListStyleSpecial li,
1.795 www 7519: .LC_ListStyleSpecial dd {
1.911 bisitz 7520: margin: 0;
7521: padding: 5px 5px 5px 10px;
7522: clear: both;
1.693 droeschl 7523: }
7524:
1.721 harmsja 7525: .LC_ListStyleClean li,
7526: .LC_ListStyleClean dd {
1.911 bisitz 7527: padding-top: 0;
7528: padding-bottom: 0;
1.693 droeschl 7529: }
7530:
1.721 harmsja 7531: .LC_ListStyleSimple dd,
1.795 www 7532: .LC_ListStyleSimple li {
1.911 bisitz 7533: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7534: }
7535:
1.721 harmsja 7536: .LC_ListStyleSpecial li,
7537: .LC_ListStyleSpecial dd {
1.911 bisitz 7538: list-style-type: none;
7539: background-color: RGB(220, 220, 220);
7540: margin-bottom: 4px;
1.693 droeschl 7541: }
7542:
1.721 harmsja 7543: table.LC_SimpleTable {
1.911 bisitz 7544: margin:5px;
7545: border:solid 1px $lg_border_color;
1.795 www 7546: }
1.693 droeschl 7547:
1.721 harmsja 7548: table.LC_SimpleTable tr {
1.911 bisitz 7549: padding: 0;
7550: border:solid 1px $lg_border_color;
1.693 droeschl 7551: }
1.795 www 7552:
7553: table.LC_SimpleTable thead {
1.911 bisitz 7554: background:rgb(220,220,220);
1.693 droeschl 7555: }
7556:
1.721 harmsja 7557: div.LC_columnSection {
1.911 bisitz 7558: display: block;
7559: clear: both;
7560: overflow: hidden;
7561: margin: 0;
1.693 droeschl 7562: }
7563:
1.721 harmsja 7564: div.LC_columnSection>* {
1.911 bisitz 7565: float: left;
7566: margin: 10px 20px 10px 0;
7567: overflow:hidden;
1.693 droeschl 7568: }
1.721 harmsja 7569:
1.795 www 7570: table em {
1.911 bisitz 7571: font-weight: bold;
7572: font-style: normal;
1.748 schulted 7573: }
1.795 www 7574:
1.779 bisitz 7575: table.LC_tableBrowseRes,
1.795 www 7576: table.LC_tableOfContent {
1.911 bisitz 7577: border:none;
7578: border-spacing: 1px;
7579: padding: 3px;
7580: background-color: #FFFFFF;
7581: font-size: 90%;
1.753 droeschl 7582: }
1.789 droeschl 7583:
1.911 bisitz 7584: table.LC_tableOfContent {
7585: border-collapse: collapse;
1.789 droeschl 7586: }
7587:
1.771 droeschl 7588: table.LC_tableBrowseRes a,
1.768 schulted 7589: table.LC_tableOfContent a {
1.911 bisitz 7590: background-color: transparent;
7591: text-decoration: none;
1.753 droeschl 7592: }
7593:
1.795 www 7594: table.LC_tableOfContent img {
1.911 bisitz 7595: border: none;
7596: height: 1.3em;
7597: vertical-align: text-bottom;
7598: margin-right: 0.3em;
1.753 droeschl 7599: }
1.757 schulted 7600:
1.795 www 7601: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7602: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7603: }
7604:
1.795 www 7605: a#LC_content_toolbar_everything {
1.911 bisitz 7606: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7607: }
7608:
1.795 www 7609: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7610: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7611: }
7612:
1.795 www 7613: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7614: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7615: }
7616:
1.795 www 7617: a#LC_content_toolbar_changefolder {
1.911 bisitz 7618: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7619: }
7620:
1.795 www 7621: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7622: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7623: }
7624:
1.1043 raeburn 7625: a#LC_content_toolbar_edittoplevel {
7626: background-image:url(/res/adm/pages/edittoplevel.gif);
7627: }
7628:
1.795 www 7629: ul#LC_toolbar li a:hover {
1.911 bisitz 7630: background-position: bottom center;
1.757 schulted 7631: }
7632:
1.795 www 7633: ul#LC_toolbar {
1.911 bisitz 7634: padding: 0;
7635: margin: 2px;
7636: list-style:none;
7637: position:relative;
7638: background-color:white;
1.1075.2.9 raeburn 7639: overflow: auto;
1.757 schulted 7640: }
7641:
1.795 www 7642: ul#LC_toolbar li {
1.911 bisitz 7643: border:1px solid white;
7644: padding: 0;
7645: margin: 0;
7646: float: left;
7647: display:inline;
7648: vertical-align:middle;
1.1075.2.9 raeburn 7649: white-space: nowrap;
1.911 bisitz 7650: }
1.757 schulted 7651:
1.783 amueller 7652:
1.795 www 7653: a.LC_toolbarItem {
1.911 bisitz 7654: display:block;
7655: padding: 0;
7656: margin: 0;
7657: height: 32px;
7658: width: 32px;
7659: color:white;
7660: border: none;
7661: background-repeat:no-repeat;
7662: background-color:transparent;
1.757 schulted 7663: }
7664:
1.915 droeschl 7665: ul.LC_funclist {
7666: margin: 0;
7667: padding: 0.5em 1em 0.5em 0;
7668: }
7669:
1.933 droeschl 7670: ul.LC_funclist > li:first-child {
7671: font-weight:bold;
7672: margin-left:0.8em;
7673: }
7674:
1.915 droeschl 7675: ul.LC_funclist + ul.LC_funclist {
7676: /*
7677: left border as a seperator if we have more than
7678: one list
7679: */
7680: border-left: 1px solid $sidebg;
7681: /*
7682: this hides the left border behind the border of the
7683: outer box if element is wrapped to the next 'line'
7684: */
7685: margin-left: -1px;
7686: }
7687:
1.843 bisitz 7688: ul.LC_funclist li {
1.915 droeschl 7689: display: inline;
1.782 bisitz 7690: white-space: nowrap;
1.915 droeschl 7691: margin: 0 0 0 25px;
7692: line-height: 150%;
1.782 bisitz 7693: }
7694:
1.974 wenzelju 7695: .LC_hidden {
7696: display: none;
7697: }
7698:
1.1030 www 7699: .LCmodal-overlay {
7700: position:fixed;
7701: top:0;
7702: right:0;
7703: bottom:0;
7704: left:0;
7705: height:100%;
7706: width:100%;
7707: margin:0;
7708: padding:0;
7709: background:#999;
7710: opacity:.75;
7711: filter: alpha(opacity=75);
7712: -moz-opacity: 0.75;
7713: z-index:101;
7714: }
7715:
7716: * html .LCmodal-overlay {
7717: position: absolute;
7718: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7719: }
7720:
7721: .LCmodal-window {
7722: position:fixed;
7723: top:50%;
7724: left:50%;
7725: margin:0;
7726: padding:0;
7727: z-index:102;
7728: }
7729:
7730: * html .LCmodal-window {
7731: position:absolute;
7732: }
7733:
7734: .LCclose-window {
7735: position:absolute;
7736: width:32px;
7737: height:32px;
7738: right:8px;
7739: top:8px;
7740: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7741: text-indent:-99999px;
7742: overflow:hidden;
7743: cursor:pointer;
7744: }
7745:
1.1075.2.17 raeburn 7746: /*
7747: styles used by TTH when "Default set of options to pass to tth/m
7748: when converting TeX" in course settings has been set
7749:
7750: option passed: -t
7751:
7752: */
7753:
7754: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7755: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7756: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7757: td div.norm {line-height:normal;}
7758:
7759: /*
7760: option passed -y3
7761: */
7762:
7763: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7764: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7765: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7766:
1.1075.2.121 raeburn 7767: #LC_minitab_header {
7768: float:left;
7769: width:100%;
7770: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
7771: font-size:93%;
7772: line-height:normal;
7773: margin: 0.5em 0 0.5em 0;
7774: }
7775: #LC_minitab_header ul {
7776: margin:0;
7777: padding:10px 10px 0;
7778: list-style:none;
7779: }
7780: #LC_minitab_header li {
7781: float:left;
7782: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
7783: margin:0;
7784: padding:0 0 0 9px;
7785: }
7786: #LC_minitab_header a {
7787: display:block;
7788: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
7789: padding:5px 15px 4px 6px;
7790: }
7791: #LC_minitab_header #LC_current_minitab {
7792: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
7793: }
7794: #LC_minitab_header #LC_current_minitab a {
7795: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
7796: padding-bottom:5px;
7797: }
7798:
7799:
1.343 albertel 7800: END
7801: }
7802:
1.306 albertel 7803: =pod
7804:
7805: =item * &headtag()
7806:
7807: Returns a uniform footer for LON-CAPA web pages.
7808:
1.307 albertel 7809: Inputs: $title - optional title for the head
7810: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7811: $args - optional arguments
1.319 albertel 7812: force_register - if is true call registerurl so the remote is
7813: informed
1.415 albertel 7814: redirect -> array ref of
7815: 1- seconds before redirect occurs
7816: 2- url to redirect to
7817: 3- whether the side effect should occur
1.315 albertel 7818: (side effect of setting
7819: $env{'internal.head.redirect'} to the url
7820: redirected too)
1.352 albertel 7821: domain -> force to color decorate a page for a specific
7822: domain
7823: function -> force usage of a specific rolish color scheme
7824: bgcolor -> override the default page bgcolor
1.460 albertel 7825: no_auto_mt_title
7826: -> prevent &mt()ing the title arg
1.464 albertel 7827:
1.306 albertel 7828: =cut
7829:
7830: sub headtag {
1.313 albertel 7831: my ($title,$head_extra,$args) = @_;
1.306 albertel 7832:
1.363 albertel 7833: my $function = $args->{'function'} || &get_users_function();
7834: my $domain = $args->{'domain'} || &determinedomain();
7835: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7836: my $httphost = $args->{'use_absolute'};
1.418 albertel 7837: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7838: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7839: #time(),
1.418 albertel 7840: $env{'environment.color.timestamp'},
1.363 albertel 7841: $function,$domain,$bgcolor);
7842:
1.369 www 7843: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7844:
1.308 albertel 7845: my $result =
7846: '<head>'.
1.1075.2.56 raeburn 7847: &font_settings($args);
1.319 albertel 7848:
1.1075.2.72 raeburn 7849: my $inhibitprint;
7850: if ($args->{'print_suppress'}) {
7851: $inhibitprint = &print_suppression();
7852: }
1.1064 raeburn 7853:
1.461 albertel 7854: if (!$args->{'frameset'}) {
7855: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7856: }
1.1075.2.12 raeburn 7857: if ($args->{'force_register'}) {
7858: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7859: }
1.436 albertel 7860: if (!$args->{'no_nav_bar'}
7861: && !$args->{'only_body'}
7862: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7863: $result .= &help_menu_js($httphost);
1.1032 www 7864: $result.=&modal_window();
1.1038 www 7865: $result.=&togglebox_script();
1.1034 www 7866: $result.=&wishlist_window();
1.1041 www 7867: $result.=&LCprogressbarUpdate_script();
1.1034 www 7868: } else {
7869: if ($args->{'add_modal'}) {
7870: $result.=&modal_window();
7871: }
7872: if ($args->{'add_wishlist'}) {
7873: $result.=&wishlist_window();
7874: }
1.1038 www 7875: if ($args->{'add_togglebox'}) {
7876: $result.=&togglebox_script();
7877: }
1.1041 www 7878: if ($args->{'add_progressbar'}) {
7879: $result.=&LCprogressbarUpdate_script();
7880: }
1.436 albertel 7881: }
1.314 albertel 7882: if (ref($args->{'redirect'})) {
1.414 albertel 7883: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7884: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7885: if (!$inhibit_continue) {
7886: $env{'internal.head.redirect'} = $url;
7887: }
1.313 albertel 7888: $result.=<<ADDMETA
7889: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7890: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7891: ADDMETA
1.1075.2.89 raeburn 7892: } else {
7893: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7894: my $requrl = $env{'request.uri'};
7895: if ($requrl eq '') {
7896: $requrl = $ENV{'REQUEST_URI'};
7897: $requrl =~ s/\?.+$//;
7898: }
7899: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7900: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7901: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7902: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7903: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7904: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7905: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7906: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7907: if ($domdefs{'offloadnow'}{$lonhost}) {
7908: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7909: if (($newserver) && ($newserver ne $lonhost)) {
7910: my $numsec = 5;
7911: my $timeout = $numsec * 1000;
7912: my ($newurl,$locknum,%locks,$msg);
7913: if ($env{'request.role.adv'}) {
7914: ($locknum,%locks) = &Apache::lonnet::get_locks();
7915: }
7916: my $disable_submit = 0;
7917: if ($requrl =~ /$LONCAPA::assess_re/) {
7918: $disable_submit = 1;
7919: }
7920: if ($locknum) {
7921: my @lockinfo = sort(values(%locks));
7922: $msg = &mt('Once the following tasks are complete: ')."\\n".
7923: join(", ",sort(values(%locks)))."\\n".
7924: &mt('your session will be transferred to a different server, after you click "Roles".');
7925: } else {
7926: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7927: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7928: }
7929: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7930: $newurl = '/adm/switchserver?otherserver='.$newserver;
7931: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7932: $newurl .= '&role='.$env{'request.role'};
7933: }
7934: if ($env{'request.symb'}) {
7935: $newurl .= '&symb='.$env{'request.symb'};
7936: } else {
7937: $newurl .= '&origurl='.$requrl;
7938: }
7939: }
1.1075.2.98 raeburn 7940: &js_escape(\$msg);
1.1075.2.89 raeburn 7941: $result.=<<OFFLOAD
7942: <meta http-equiv="pragma" content="no-cache" />
7943: <script type="text/javascript">
1.1075.2.92 raeburn 7944: // <![CDATA[
1.1075.2.89 raeburn 7945: function LC_Offload_Now() {
7946: var dest = "$newurl";
7947: if (dest != '') {
7948: window.location.href="$newurl";
7949: }
7950: }
1.1075.2.92 raeburn 7951: \$(document).ready(function () {
7952: window.alert('$msg');
7953: if ($disable_submit) {
1.1075.2.89 raeburn 7954: \$(".LC_hwk_submit").prop("disabled", true);
7955: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 7956: }
7957: setTimeout('LC_Offload_Now()', $timeout);
7958: });
7959: // ]]>
1.1075.2.89 raeburn 7960: </script>
7961: OFFLOAD
7962: }
7963: }
7964: }
7965: }
7966: }
7967: }
1.313 albertel 7968: }
1.306 albertel 7969: if (!defined($title)) {
7970: $title = 'The LearningOnline Network with CAPA';
7971: }
1.460 albertel 7972: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7973: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7974: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7975: if (!$args->{'frameset'}) {
7976: $result .= ' /';
7977: }
7978: $result .= '>'
1.1064 raeburn 7979: .$inhibitprint
1.414 albertel 7980: .$head_extra;
1.1075.2.108 raeburn 7981: my $clientmobile;
7982: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
7983: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
7984: } else {
7985: $clientmobile = $env{'browser.mobile'};
7986: }
7987: if ($clientmobile) {
1.1075.2.42 raeburn 7988: $result .= '
7989: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7990: <meta name="apple-mobile-web-app-capable" content="yes" />';
7991: }
1.1075.2.126 raeburn 7992: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 7993: return $result.'</head>';
1.306 albertel 7994: }
7995:
7996: =pod
7997:
1.340 albertel 7998: =item * &font_settings()
7999:
8000: Returns neccessary <meta> to set the proper encoding
8001:
1.1075.2.56 raeburn 8002: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8003:
8004: =cut
8005:
8006: sub font_settings {
1.1075.2.56 raeburn 8007: my ($args) = @_;
1.340 albertel 8008: my $headerstring='';
1.1075.2.56 raeburn 8009: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8010: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8011: $headerstring.=
1.1075.2.61 raeburn 8012: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8013: if (!$args->{'frameset'}) {
8014: $headerstring.= ' /';
8015: }
8016: $headerstring .= '>'."\n";
1.340 albertel 8017: }
8018: return $headerstring;
8019: }
8020:
1.341 albertel 8021: =pod
8022:
1.1064 raeburn 8023: =item * &print_suppression()
8024:
8025: In course context returns css which causes the body to be blank when media="print",
8026: if printout generation is unavailable for the current resource.
8027:
8028: This could be because:
8029:
8030: (a) printstartdate is in the future
8031:
8032: (b) printenddate is in the past
8033:
8034: (c) there is an active exam block with "printout"
8035: functionality blocked
8036:
8037: Users with pav, pfo or evb privileges are exempt.
8038:
8039: Inputs: none
8040:
8041: =cut
8042:
8043:
8044: sub print_suppression {
8045: my $noprint;
8046: if ($env{'request.course.id'}) {
8047: my $scope = $env{'request.course.id'};
8048: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8049: (&Apache::lonnet::allowed('pfo',$scope))) {
8050: return;
8051: }
8052: if ($env{'request.course.sec'} ne '') {
8053: $scope .= "/$env{'request.course.sec'}";
8054: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8055: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8056: return;
1.1064 raeburn 8057: }
8058: }
8059: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8060: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 8061: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8062: if ($blocked) {
8063: my $checkrole = "cm./$cdom/$cnum";
8064: if ($env{'request.course.sec'} ne '') {
8065: $checkrole .= "/$env{'request.course.sec'}";
8066: }
8067: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8068: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8069: $noprint = 1;
8070: }
8071: }
8072: unless ($noprint) {
8073: my $symb = &Apache::lonnet::symbread();
8074: if ($symb ne '') {
8075: my $navmap = Apache::lonnavmaps::navmap->new();
8076: if (ref($navmap)) {
8077: my $res = $navmap->getBySymb($symb);
8078: if (ref($res)) {
8079: if (!$res->resprintable()) {
8080: $noprint = 1;
8081: }
8082: }
8083: }
8084: }
8085: }
8086: if ($noprint) {
8087: return <<"ENDSTYLE";
8088: <style type="text/css" media="print">
8089: body { display:none }
8090: </style>
8091: ENDSTYLE
8092: }
8093: }
8094: return;
8095: }
8096:
8097: =pod
8098:
1.341 albertel 8099: =item * &xml_begin()
8100:
8101: Returns the needed doctype and <html>
8102:
8103: Inputs: none
8104:
8105: =cut
8106:
8107: sub xml_begin {
1.1075.2.61 raeburn 8108: my ($is_frameset) = @_;
1.341 albertel 8109: my $output='';
8110:
8111: if ($env{'browser.mathml'}) {
8112: $output='<?xml version="1.0"?>'
8113: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8114: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8115:
8116: # .'<!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">] >'
8117: .'<!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">'
8118: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8119: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8120: } elsif ($is_frameset) {
8121: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8122: '<html>'."\n";
1.341 albertel 8123: } else {
1.1075.2.61 raeburn 8124: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8125: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8126: }
8127: return $output;
8128: }
1.340 albertel 8129:
8130: =pod
8131:
1.306 albertel 8132: =item * &start_page()
8133:
8134: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8135:
1.648 raeburn 8136: Inputs:
8137:
8138: =over 4
8139:
8140: $title - optional title for the page
8141:
8142: $head_extra - optional extra HTML to incude inside the <head>
8143:
8144: $args - additional optional args supported are:
8145:
8146: =over 8
8147:
8148: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8149: arg on
1.814 bisitz 8150: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8151: add_entries -> additional attributes to add to the <body>
8152: domain -> force to color decorate a page for a
1.317 albertel 8153: specific domain
1.648 raeburn 8154: function -> force usage of a specific rolish color
1.317 albertel 8155: scheme
1.648 raeburn 8156: redirect -> see &headtag()
8157: bgcolor -> override the default page bg color
8158: js_ready -> return a string ready for being used in
1.317 albertel 8159: a javascript writeln
1.648 raeburn 8160: html_encode -> return a string ready for being used in
1.320 albertel 8161: a html attribute
1.648 raeburn 8162: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8163: $forcereg arg
1.648 raeburn 8164: frameset -> if true will start with a <frameset>
1.330 albertel 8165: rather than <body>
1.648 raeburn 8166: skip_phases -> hash ref of
1.338 albertel 8167: head -> skip the <html><head> generation
8168: body -> skip all <body> generation
1.1075.2.12 raeburn 8169: no_inline_link -> if true and in remote mode, don't show the
8170: 'Switch To Inline Menu' link
1.648 raeburn 8171: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8172: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8173: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8174: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8175: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8176: group -> includes the current group, if page is for a
8177: specific group
1.1075.2.133 raeburn 8178: use_absolute -> for request for external resource or syllabus, this
8179: will contain https://<hostname> if server uses
8180: https (as per hosts.tab), but request is for http
8181: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8182:
1.648 raeburn 8183: =back
1.460 albertel 8184:
1.648 raeburn 8185: =back
1.562 albertel 8186:
1.306 albertel 8187: =cut
8188:
8189: sub start_page {
1.309 albertel 8190: my ($title,$head_extra,$args) = @_;
1.318 albertel 8191: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8192:
1.315 albertel 8193: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8194: my ($result,@advtools);
1.964 droeschl 8195:
1.338 albertel 8196: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8197: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8198: }
8199:
8200: if (! exists($args->{'skip_phases'}{'body'}) ) {
8201: if ($args->{'frameset'}) {
8202: my $attr_string = &make_attr_string($args->{'force_register'},
8203: $args->{'add_entries'});
8204: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8205: } else {
8206: $result .=
8207: &bodytag($title,
8208: $args->{'function'}, $args->{'add_entries'},
8209: $args->{'only_body'}, $args->{'domain'},
8210: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8211: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8212: $args, \@advtools);
1.831 bisitz 8213: }
1.330 albertel 8214: }
1.338 albertel 8215:
1.315 albertel 8216: if ($args->{'js_ready'}) {
1.713 kaisler 8217: $result = &js_ready($result);
1.315 albertel 8218: }
1.320 albertel 8219: if ($args->{'html_encode'}) {
1.713 kaisler 8220: $result = &html_encode($result);
8221: }
8222:
1.813 bisitz 8223: # Preparation for new and consistent functionlist at top of screen
8224: # if ($args->{'functionlist'}) {
8225: # $result .= &build_functionlist();
8226: #}
8227:
1.964 droeschl 8228: # Don't add anything more if only_body wanted or in const space
8229: return $result if $args->{'only_body'}
8230: || $env{'request.state'} eq 'construct';
1.813 bisitz 8231:
8232: #Breadcrumbs
1.758 kaisler 8233: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8234: &Apache::lonhtmlcommon::clear_breadcrumbs();
8235: #if any br links exists, add them to the breadcrumbs
8236: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8237: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8238: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8239: }
8240: }
1.1075.2.19 raeburn 8241: # if @advtools array contains items add then to the breadcrumbs
8242: if (@advtools > 0) {
8243: &Apache::lonmenu::advtools_crumbs(@advtools);
8244: }
1.1075.2.123 raeburn 8245: my $menulink;
8246: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8247: if (exists($args->{'bread_crumbs_nomenu'})) {
8248: $menulink = 0;
8249: } else {
8250: undef($menulink);
8251: }
1.758 kaisler 8252: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8253: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8254: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8255: }else{
1.1075.2.123 raeburn 8256: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8257: }
1.1075.2.24 raeburn 8258: } elsif (($env{'environment.remote'} eq 'on') &&
8259: ($env{'form.inhibitmenu'} ne 'yes') &&
8260: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8261: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8262: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8263: }
1.315 albertel 8264: return $result;
1.306 albertel 8265: }
8266:
8267: sub end_page {
1.315 albertel 8268: my ($args) = @_;
8269: $env{'internal.end_page'}++;
1.330 albertel 8270: my $result;
1.335 albertel 8271: if ($args->{'discussion'}) {
8272: my ($target,$parser);
8273: if (ref($args->{'discussion'})) {
8274: ($target,$parser) =($args->{'discussion'}{'target'},
8275: $args->{'discussion'}{'parser'});
8276: }
8277: $result .= &Apache::lonxml::xmlend($target,$parser);
8278: }
1.330 albertel 8279: if ($args->{'frameset'}) {
8280: $result .= '</frameset>';
8281: } else {
1.635 raeburn 8282: $result .= &endbodytag($args);
1.330 albertel 8283: }
1.1075.2.6 raeburn 8284: unless ($args->{'notbody'}) {
8285: $result .= "\n</html>";
8286: }
1.330 albertel 8287:
1.315 albertel 8288: if ($args->{'js_ready'}) {
1.317 albertel 8289: $result = &js_ready($result);
1.315 albertel 8290: }
1.335 albertel 8291:
1.320 albertel 8292: if ($args->{'html_encode'}) {
8293: $result = &html_encode($result);
8294: }
1.335 albertel 8295:
1.315 albertel 8296: return $result;
8297: }
8298:
1.1034 www 8299: sub wishlist_window {
8300: return(<<'ENDWISHLIST');
1.1046 raeburn 8301: <script type="text/javascript">
1.1034 www 8302: // <![CDATA[
8303: // <!-- BEGIN LON-CAPA Internal
8304: function set_wishlistlink(title, path) {
8305: if (!title) {
8306: title = document.title;
8307: title = title.replace(/^LON-CAPA /,'');
8308: }
1.1075.2.65 raeburn 8309: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8310: title = title.replace("'","\\\'");
1.1034 www 8311: if (!path) {
8312: path = location.pathname;
8313: }
1.1075.2.65 raeburn 8314: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8315: path = path.replace("'","\\\'");
1.1034 www 8316: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8317: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8318: }
8319: // END LON-CAPA Internal -->
8320: // ]]>
8321: </script>
8322: ENDWISHLIST
8323: }
8324:
1.1030 www 8325: sub modal_window {
8326: return(<<'ENDMODAL');
1.1046 raeburn 8327: <script type="text/javascript">
1.1030 www 8328: // <![CDATA[
8329: // <!-- BEGIN LON-CAPA Internal
8330: var modalWindow = {
8331: parent:"body",
8332: windowId:null,
8333: content:null,
8334: width:null,
8335: height:null,
8336: close:function()
8337: {
8338: $(".LCmodal-window").remove();
8339: $(".LCmodal-overlay").remove();
8340: },
8341: open:function()
8342: {
8343: var modal = "";
8344: modal += "<div class=\"LCmodal-overlay\"></div>";
8345: 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;\">";
8346: modal += this.content;
8347: modal += "</div>";
8348:
8349: $(this.parent).append(modal);
8350:
8351: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8352: $(".LCclose-window").click(function(){modalWindow.close();});
8353: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8354: }
8355: };
1.1075.2.42 raeburn 8356: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8357: {
1.1075.2.119 raeburn 8358: source = source.replace(/'/g,"'");
1.1030 www 8359: modalWindow.windowId = "myModal";
8360: modalWindow.width = width;
8361: modalWindow.height = height;
1.1075.2.80 raeburn 8362: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8363: modalWindow.open();
1.1075.2.87 raeburn 8364: };
1.1030 www 8365: // END LON-CAPA Internal -->
8366: // ]]>
8367: </script>
8368: ENDMODAL
8369: }
8370:
8371: sub modal_link {
1.1075.2.42 raeburn 8372: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8373: unless ($width) { $width=480; }
8374: unless ($height) { $height=400; }
1.1031 www 8375: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8376: unless ($transparency) { $transparency='true'; }
8377:
1.1074 raeburn 8378: my $target_attr;
8379: if (defined($target)) {
8380: $target_attr = 'target="'.$target.'"';
8381: }
8382: return <<"ENDLINK";
1.1075.2.42 raeburn 8383: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8384: $linktext</a>
8385: ENDLINK
1.1030 www 8386: }
8387:
1.1032 www 8388: sub modal_adhoc_script {
8389: my ($funcname,$width,$height,$content)=@_;
8390: return (<<ENDADHOC);
1.1046 raeburn 8391: <script type="text/javascript">
1.1032 www 8392: // <![CDATA[
8393: var $funcname = function()
8394: {
8395: modalWindow.windowId = "myModal";
8396: modalWindow.width = $width;
8397: modalWindow.height = $height;
8398: modalWindow.content = '$content';
8399: modalWindow.open();
8400: };
8401: // ]]>
8402: </script>
8403: ENDADHOC
8404: }
8405:
1.1041 www 8406: sub modal_adhoc_inner {
8407: my ($funcname,$width,$height,$content)=@_;
8408: my $innerwidth=$width-20;
8409: $content=&js_ready(
1.1042 www 8410: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8411: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8412: $content.
1.1041 www 8413: &end_scrollbox().
1.1075.2.42 raeburn 8414: &end_page()
1.1041 www 8415: );
8416: return &modal_adhoc_script($funcname,$width,$height,$content);
8417: }
8418:
8419: sub modal_adhoc_window {
8420: my ($funcname,$width,$height,$content,$linktext)=@_;
8421: return &modal_adhoc_inner($funcname,$width,$height,$content).
8422: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8423: }
8424:
8425: sub modal_adhoc_launch {
8426: my ($funcname,$width,$height,$content)=@_;
8427: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8428: <script type="text/javascript">
8429: // <![CDATA[
8430: $funcname();
8431: // ]]>
8432: </script>
8433: ENDLAUNCH
8434: }
8435:
8436: sub modal_adhoc_close {
8437: return (<<ENDCLOSE);
8438: <script type="text/javascript">
8439: // <![CDATA[
8440: modalWindow.close();
8441: // ]]>
8442: </script>
8443: ENDCLOSE
8444: }
8445:
1.1038 www 8446: sub togglebox_script {
8447: return(<<ENDTOGGLE);
8448: <script type="text/javascript">
8449: // <![CDATA[
8450: function LCtoggleDisplay(id,hidetext,showtext) {
8451: link = document.getElementById(id + "link").childNodes[0];
8452: with (document.getElementById(id).style) {
8453: if (display == "none" ) {
8454: display = "inline";
8455: link.nodeValue = hidetext;
8456: } else {
8457: display = "none";
8458: link.nodeValue = showtext;
8459: }
8460: }
8461: }
8462: // ]]>
8463: </script>
8464: ENDTOGGLE
8465: }
8466:
1.1039 www 8467: sub start_togglebox {
8468: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8469: unless ($heading) { $heading=''; } else { $heading.=' '; }
8470: unless ($showtext) { $showtext=&mt('show'); }
8471: unless ($hidetext) { $hidetext=&mt('hide'); }
8472: unless ($headerbg) { $headerbg='#FFFFFF'; }
8473: return &start_data_table().
8474: &start_data_table_header_row().
8475: '<td bgcolor="'.$headerbg.'">'.$heading.
8476: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8477: $showtext.'\')">'.$showtext.'</a>]</td>'.
8478: &end_data_table_header_row().
8479: '<tr id="'.$id.'" style="display:none""><td>';
8480: }
8481:
8482: sub end_togglebox {
8483: return '</td></tr>'.&end_data_table();
8484: }
8485:
1.1041 www 8486: sub LCprogressbar_script {
1.1075.2.130 raeburn 8487: my ($id,$number_to_do)=@_;
8488: if ($number_to_do) {
8489: return(<<ENDPROGRESS);
1.1041 www 8490: <script type="text/javascript">
8491: // <![CDATA[
1.1045 www 8492: \$('#progressbar$id').progressbar({
1.1041 www 8493: value: 0,
8494: change: function(event, ui) {
8495: var newVal = \$(this).progressbar('option', 'value');
8496: \$('.pblabel', this).text(LCprogressTxt);
8497: }
8498: });
8499: // ]]>
8500: </script>
8501: ENDPROGRESS
1.1075.2.130 raeburn 8502: } else {
8503: return(<<ENDPROGRESS);
8504: <script type="text/javascript">
8505: // <![CDATA[
8506: \$('#progressbar$id').progressbar({
8507: value: false,
8508: create: function(event, ui) {
8509: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8510: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8511: }
8512: });
8513: // ]]>
8514: </script>
8515: ENDPROGRESS
8516: }
1.1041 www 8517: }
8518:
8519: sub LCprogressbarUpdate_script {
8520: return(<<ENDPROGRESSUPDATE);
8521: <style type="text/css">
8522: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 8523: .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 8524: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8525: </style>
8526: <script type="text/javascript">
8527: // <![CDATA[
1.1045 www 8528: var LCprogressTxt='---';
8529:
1.1075.2.130 raeburn 8530: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 8531: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 8532: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
8533: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
8534: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
8535: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
8536: } else {
8537: \$('#progressbar'+id).progressbar('value',percent);
8538: }
1.1041 www 8539: }
8540: // ]]>
8541: </script>
8542: ENDPROGRESSUPDATE
8543: }
8544:
1.1042 www 8545: my $LClastpercent;
1.1045 www 8546: my $LCidcnt;
8547: my $LCcurrentid;
1.1042 www 8548:
1.1041 www 8549: sub LCprogressbar {
1.1075.2.130 raeburn 8550: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 8551: $LClastpercent=0;
1.1045 www 8552: $LCidcnt++;
8553: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 8554: my ($starting,$content);
8555: if ($number_to_do) {
8556: $starting=&mt('Starting');
8557: $content=(<<ENDPROGBAR);
8558: $preamble
1.1045 www 8559: <div id="progressbar$LCcurrentid">
1.1041 www 8560: <span class="pblabel">$starting</span>
8561: </div>
8562: ENDPROGBAR
1.1075.2.130 raeburn 8563: } else {
8564: $starting=&mt('Loading...');
8565: $LClastpercent='false';
8566: $content=(<<ENDPROGBAR);
8567: $preamble
8568: <div id="progressbar$LCcurrentid">
8569: <div class="progress-label">$starting</div>
8570: </div>
8571: ENDPROGBAR
8572: }
8573: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 8574: }
8575:
8576: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 8577: my ($r,$val,$text,$number_to_do)=@_;
8578: if ($number_to_do) {
8579: unless ($val) {
8580: if ($LClastpercent) {
8581: $val=$LClastpercent;
8582: } else {
8583: $val=0;
8584: }
8585: }
8586: if ($val<0) { $val=0; }
8587: if ($val>100) { $val=0; }
8588: $LClastpercent=$val;
8589: unless ($text) { $text=$val.'%'; }
8590: } else {
8591: $val = 'false';
1.1042 www 8592: }
1.1041 www 8593: $text=&js_ready($text);
1.1044 www 8594: &r_print($r,<<ENDUPDATE);
1.1041 www 8595: <script type="text/javascript">
8596: // <![CDATA[
1.1075.2.130 raeburn 8597: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 8598: // ]]>
8599: </script>
8600: ENDUPDATE
1.1035 www 8601: }
8602:
1.1042 www 8603: sub LCprogressbarClose {
8604: my ($r)=@_;
8605: $LClastpercent=0;
1.1044 www 8606: &r_print($r,<<ENDCLOSE);
1.1042 www 8607: <script type="text/javascript">
8608: // <![CDATA[
1.1045 www 8609: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8610: // ]]>
8611: </script>
8612: ENDCLOSE
1.1044 www 8613: }
8614:
8615: sub r_print {
8616: my ($r,$to_print)=@_;
8617: if ($r) {
8618: $r->print($to_print);
8619: $r->rflush();
8620: } else {
8621: print($to_print);
8622: }
1.1042 www 8623: }
8624:
1.320 albertel 8625: sub html_encode {
8626: my ($result) = @_;
8627:
1.322 albertel 8628: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8629:
8630: return $result;
8631: }
1.1044 www 8632:
1.317 albertel 8633: sub js_ready {
8634: my ($result) = @_;
8635:
1.323 albertel 8636: $result =~ s/[\n\r]/ /xmsg;
8637: $result =~ s/\\/\\\\/xmsg;
8638: $result =~ s/'/\\'/xmsg;
1.372 albertel 8639: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8640:
8641: return $result;
8642: }
8643:
1.315 albertel 8644: sub validate_page {
8645: if ( exists($env{'internal.start_page'})
1.316 albertel 8646: && $env{'internal.start_page'} > 1) {
8647: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8648: $env{'internal.start_page'}.' '.
1.316 albertel 8649: $ENV{'request.filename'});
1.315 albertel 8650: }
8651: if ( exists($env{'internal.end_page'})
1.316 albertel 8652: && $env{'internal.end_page'} > 1) {
8653: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8654: $env{'internal.end_page'}.' '.
1.316 albertel 8655: $env{'request.filename'});
1.315 albertel 8656: }
8657: if ( exists($env{'internal.start_page'})
8658: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8659: &Apache::lonnet::logthis('start_page called without end_page '.
8660: $env{'request.filename'});
1.315 albertel 8661: }
8662: if ( ! exists($env{'internal.start_page'})
8663: && exists($env{'internal.end_page'})) {
1.316 albertel 8664: &Apache::lonnet::logthis('end_page called without start_page'.
8665: $env{'request.filename'});
1.315 albertel 8666: }
1.306 albertel 8667: }
1.315 albertel 8668:
1.996 www 8669:
8670: sub start_scrollbox {
1.1075.2.56 raeburn 8671: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8672: unless ($outerwidth) { $outerwidth='520px'; }
8673: unless ($width) { $width='500px'; }
8674: unless ($height) { $height='200px'; }
1.1075 raeburn 8675: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8676: if ($id ne '') {
1.1075.2.42 raeburn 8677: $table_id = ' id="table_'.$id.'"';
8678: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8679: }
1.1075 raeburn 8680: if ($bgcolor ne '') {
8681: $tdcol = "background-color: $bgcolor;";
8682: }
1.1075.2.42 raeburn 8683: my $nicescroll_js;
8684: if ($env{'browser.mobile'}) {
8685: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8686: }
1.1075 raeburn 8687: return <<"END";
1.1075.2.42 raeburn 8688: $nicescroll_js
8689:
8690: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8691: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8692: END
1.996 www 8693: }
8694:
8695: sub end_scrollbox {
1.1036 www 8696: return '</div></td></tr></table>';
1.996 www 8697: }
8698:
1.1075.2.42 raeburn 8699: sub nicescroll_javascript {
8700: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8701: my %options;
8702: if (ref($cursor) eq 'HASH') {
8703: %options = %{$cursor};
8704: }
8705: unless ($options{'railalign'} =~ /^left|right$/) {
8706: $options{'railalign'} = 'left';
8707: }
8708: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8709: my $function = &get_users_function();
8710: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8711: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8712: $options{'cursorcolor'} = '#00F';
8713: }
8714: }
8715: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8716: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8717: $options{'cursoropacity'}='1.0';
8718: }
8719: } else {
8720: $options{'cursoropacity'}='1.0';
8721: }
8722: if ($options{'cursorfixedheight'} eq 'none') {
8723: delete($options{'cursorfixedheight'});
8724: } else {
8725: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8726: }
8727: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8728: delete($options{'railoffset'});
8729: }
8730: my @niceoptions;
8731: while (my($key,$value) = each(%options)) {
8732: if ($value =~ /^\{.+\}$/) {
8733: push(@niceoptions,$key.':'.$value);
8734: } else {
8735: push(@niceoptions,$key.':"'.$value.'"');
8736: }
8737: }
8738: my $nicescroll_js = '
8739: $(document).ready(
8740: function() {
8741: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8742: }
8743: );
8744: ';
8745: if ($framecheck) {
8746: $nicescroll_js .= '
8747: function expand_div(caller) {
8748: if (top === self) {
8749: document.getElementById("'.$id.'").style.width = "auto";
8750: document.getElementById("'.$id.'").style.height = "auto";
8751: } else {
8752: try {
8753: if (parent.frames) {
8754: if (parent.frames.length > 1) {
8755: var framesrc = parent.frames[1].location.href;
8756: var currsrc = framesrc.replace(/\#.*$/,"");
8757: if ((caller == "search") || (currsrc == "'.$location.'")) {
8758: document.getElementById("'.$id.'").style.width = "auto";
8759: document.getElementById("'.$id.'").style.height = "auto";
8760: }
8761: }
8762: }
8763: } catch (e) {
8764: return;
8765: }
8766: }
8767: return;
8768: }
8769: ';
8770: }
8771: if ($needjsready) {
8772: $nicescroll_js = '
8773: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8774: } else {
8775: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8776: }
8777: return $nicescroll_js;
8778: }
8779:
1.318 albertel 8780: sub simple_error_page {
1.1075.2.49 raeburn 8781: my ($r,$title,$msg,$args) = @_;
8782: if (ref($args) eq 'HASH') {
8783: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8784: } else {
8785: $msg = &mt($msg);
8786: }
8787:
1.318 albertel 8788: my $page =
8789: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8790: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8791: &Apache::loncommon::end_page();
8792: if (ref($r)) {
8793: $r->print($page);
1.327 albertel 8794: return;
1.318 albertel 8795: }
8796: return $page;
8797: }
1.347 albertel 8798:
8799: {
1.610 albertel 8800: my @row_count;
1.961 onken 8801:
8802: sub start_data_table_count {
8803: unshift(@row_count, 0);
8804: return;
8805: }
8806:
8807: sub end_data_table_count {
8808: shift(@row_count);
8809: return;
8810: }
8811:
1.347 albertel 8812: sub start_data_table {
1.1018 raeburn 8813: my ($add_class,$id) = @_;
1.422 albertel 8814: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8815: my $table_id;
8816: if (defined($id)) {
8817: $table_id = ' id="'.$id.'"';
8818: }
1.961 onken 8819: &start_data_table_count();
1.1018 raeburn 8820: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8821: }
8822:
8823: sub end_data_table {
1.961 onken 8824: &end_data_table_count();
1.389 albertel 8825: return '</table>'."\n";;
1.347 albertel 8826: }
8827:
8828: sub start_data_table_row {
1.974 wenzelju 8829: my ($add_class, $id) = @_;
1.610 albertel 8830: $row_count[0]++;
8831: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8832: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8833: $id = (' id="'.$id.'"') unless ($id eq '');
8834: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8835: }
1.471 banghart 8836:
8837: sub continue_data_table_row {
1.974 wenzelju 8838: my ($add_class, $id) = @_;
1.610 albertel 8839: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8840: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8841: $id = (' id="'.$id.'"') unless ($id eq '');
8842: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8843: }
1.347 albertel 8844:
8845: sub end_data_table_row {
1.389 albertel 8846: return '</tr>'."\n";;
1.347 albertel 8847: }
1.367 www 8848:
1.421 albertel 8849: sub start_data_table_empty_row {
1.707 bisitz 8850: # $row_count[0]++;
1.421 albertel 8851: return '<tr class="LC_empty_row" >'."\n";;
8852: }
8853:
8854: sub end_data_table_empty_row {
8855: return '</tr>'."\n";;
8856: }
8857:
1.367 www 8858: sub start_data_table_header_row {
1.389 albertel 8859: return '<tr class="LC_header_row">'."\n";;
1.367 www 8860: }
8861:
8862: sub end_data_table_header_row {
1.389 albertel 8863: return '</tr>'."\n";;
1.367 www 8864: }
1.890 droeschl 8865:
8866: sub data_table_caption {
8867: my $caption = shift;
8868: return "<caption class=\"LC_caption\">$caption</caption>";
8869: }
1.347 albertel 8870: }
8871:
1.548 albertel 8872: =pod
8873:
8874: =item * &inhibit_menu_check($arg)
8875:
8876: Checks for a inhibitmenu state and generates output to preserve it
8877:
8878: Inputs: $arg - can be any of
8879: - undef - in which case the return value is a string
8880: to add into arguments list of a uri
8881: - 'input' - in which case the return value is a HTML
8882: <form> <input> field of type hidden to
8883: preserve the value
8884: - a url - in which case the return value is the url with
8885: the neccesary cgi args added to preserve the
8886: inhibitmenu state
8887: - a ref to a url - no return value, but the string is
8888: updated to include the neccessary cgi
8889: args to preserve the inhibitmenu state
8890:
8891: =cut
8892:
8893: sub inhibit_menu_check {
8894: my ($arg) = @_;
8895: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8896: if ($arg eq 'input') {
8897: if ($env{'form.inhibitmenu'}) {
8898: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8899: } else {
8900: return
8901: }
8902: }
8903: if ($env{'form.inhibitmenu'}) {
8904: if (ref($arg)) {
8905: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8906: } elsif ($arg eq '') {
8907: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8908: } else {
8909: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8910: }
8911: }
8912: if (!ref($arg)) {
8913: return $arg;
8914: }
8915: }
8916:
1.251 albertel 8917: ###############################################
1.182 matthew 8918:
8919: =pod
8920:
1.549 albertel 8921: =back
8922:
8923: =head1 User Information Routines
8924:
8925: =over 4
8926:
1.405 albertel 8927: =item * &get_users_function()
1.182 matthew 8928:
8929: Used by &bodytag to determine the current users primary role.
8930: Returns either 'student','coordinator','admin', or 'author'.
8931:
8932: =cut
8933:
8934: ###############################################
8935: sub get_users_function {
1.815 tempelho 8936: my $function = 'norole';
1.818 tempelho 8937: if ($env{'request.role'}=~/^(st)/) {
8938: $function='student';
8939: }
1.907 raeburn 8940: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8941: $function='coordinator';
8942: }
1.258 albertel 8943: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8944: $function='admin';
8945: }
1.826 bisitz 8946: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8947: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8948: $function='author';
8949: }
8950: return $function;
1.54 www 8951: }
1.99 www 8952:
8953: ###############################################
8954:
1.233 raeburn 8955: =pod
8956:
1.821 raeburn 8957: =item * &show_course()
8958:
8959: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8960: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8961:
8962: Inputs:
8963: None
8964:
8965: Outputs:
8966: Scalar: 1 if 'Course' to be used, 0 otherwise.
8967:
8968: =cut
8969:
8970: ###############################################
8971: sub show_course {
8972: my $course = !$env{'user.adv'};
8973: if (!$env{'user.adv'}) {
8974: foreach my $env (keys(%env)) {
8975: next if ($env !~ m/^user\.priv\./);
8976: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8977: $course = 0;
8978: last;
8979: }
8980: }
8981: }
8982: return $course;
8983: }
8984:
8985: ###############################################
8986:
8987: =pod
8988:
1.542 raeburn 8989: =item * &check_user_status()
1.274 raeburn 8990:
8991: Determines current status of supplied role for a
8992: specific user. Roles can be active, previous or future.
8993:
8994: Inputs:
8995: user's domain, user's username, course's domain,
1.375 raeburn 8996: course's number, optional section ID.
1.274 raeburn 8997:
8998: Outputs:
8999: role status: active, previous or future.
9000:
9001: =cut
9002:
9003: sub check_user_status {
1.412 raeburn 9004: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9005: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9006: my @uroles = keys(%userinfo);
1.274 raeburn 9007: my $srchstr;
9008: my $active_chk = 'none';
1.412 raeburn 9009: my $now = time;
1.274 raeburn 9010: if (@uroles > 0) {
1.908 raeburn 9011: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9012: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9013: } else {
1.412 raeburn 9014: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9015: }
9016: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9017: my $role_end = 0;
9018: my $role_start = 0;
9019: $active_chk = 'active';
1.412 raeburn 9020: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9021: $role_end = $1;
9022: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9023: $role_start = $1;
1.274 raeburn 9024: }
9025: }
9026: if ($role_start > 0) {
1.412 raeburn 9027: if ($now < $role_start) {
1.274 raeburn 9028: $active_chk = 'future';
9029: }
9030: }
9031: if ($role_end > 0) {
1.412 raeburn 9032: if ($now > $role_end) {
1.274 raeburn 9033: $active_chk = 'previous';
9034: }
9035: }
9036: }
9037: }
9038: return $active_chk;
9039: }
9040:
9041: ###############################################
9042:
9043: =pod
9044:
1.405 albertel 9045: =item * &get_sections()
1.233 raeburn 9046:
9047: Determines all the sections for a course including
9048: sections with students and sections containing other roles.
1.419 raeburn 9049: Incoming parameters:
9050:
9051: 1. domain
9052: 2. course number
9053: 3. reference to array containing roles for which sections should
9054: be gathered (optional).
9055: 4. reference to array containing status types for which sections
9056: should be gathered (optional).
9057:
9058: If the third argument is undefined, sections are gathered for any role.
9059: If the fourth argument is undefined, sections are gathered for any status.
9060: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9061:
1.374 raeburn 9062: Returns section hash (keys are section IDs, values are
9063: number of users in each section), subject to the
1.419 raeburn 9064: optional roles filter, optional status filter
1.233 raeburn 9065:
9066: =cut
9067:
9068: ###############################################
9069: sub get_sections {
1.419 raeburn 9070: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9071: if (!defined($cdom) || !defined($cnum)) {
9072: my $cid = $env{'request.course.id'};
9073:
9074: return if (!defined($cid));
9075:
9076: $cdom = $env{'course.'.$cid.'.domain'};
9077: $cnum = $env{'course.'.$cid.'.num'};
9078: }
9079:
9080: my %sectioncount;
1.419 raeburn 9081: my $now = time;
1.240 albertel 9082:
1.1075.2.33 raeburn 9083: my $check_students = 1;
9084: my $only_students = 0;
9085: if (ref($possible_roles) eq 'ARRAY') {
9086: if (grep(/^st$/,@{$possible_roles})) {
9087: if (@{$possible_roles} == 1) {
9088: $only_students = 1;
9089: }
9090: } else {
9091: $check_students = 0;
9092: }
9093: }
9094:
9095: if ($check_students) {
1.276 albertel 9096: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9097: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9098: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9099: my $start_index = &Apache::loncoursedata::CL_START();
9100: my $end_index = &Apache::loncoursedata::CL_END();
9101: my $status;
1.366 albertel 9102: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9103: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9104: $data->[$status_index],
9105: $data->[$start_index],
9106: $data->[$end_index]);
9107: if ($stu_status eq 'Active') {
9108: $status = 'active';
9109: } elsif ($end < $now) {
9110: $status = 'previous';
9111: } elsif ($start > $now) {
9112: $status = 'future';
9113: }
9114: if ($section ne '-1' && $section !~ /^\s*$/) {
9115: if ((!defined($possible_status)) || (($status ne '') &&
9116: (grep/^\Q$status\E$/,@{$possible_status}))) {
9117: $sectioncount{$section}++;
9118: }
1.240 albertel 9119: }
9120: }
9121: }
1.1075.2.33 raeburn 9122: if ($only_students) {
9123: return %sectioncount;
9124: }
1.240 albertel 9125: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9126: foreach my $user (sort(keys(%courseroles))) {
9127: if ($user !~ /^(\w{2})/) { next; }
9128: my ($role) = ($user =~ /^(\w{2})/);
9129: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9130: my ($section,$status);
1.240 albertel 9131: if ($role eq 'cr' &&
9132: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9133: $section=$1;
9134: }
9135: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9136: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9137: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9138: if ($end == -1 && $start == -1) {
9139: next; #deleted role
9140: }
9141: if (!defined($possible_status)) {
9142: $sectioncount{$section}++;
9143: } else {
9144: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9145: $status = 'active';
9146: } elsif ($end < $now) {
9147: $status = 'future';
9148: } elsif ($start > $now) {
9149: $status = 'previous';
9150: }
9151: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9152: $sectioncount{$section}++;
9153: }
9154: }
1.233 raeburn 9155: }
1.366 albertel 9156: return %sectioncount;
1.233 raeburn 9157: }
9158:
1.274 raeburn 9159: ###############################################
1.294 raeburn 9160:
9161: =pod
1.405 albertel 9162:
9163: =item * &get_course_users()
9164:
1.275 raeburn 9165: Retrieves usernames:domains for users in the specified course
9166: with specific role(s), and access status.
9167:
9168: Incoming parameters:
1.277 albertel 9169: 1. course domain
9170: 2. course number
9171: 3. access status: users must have - either active,
1.275 raeburn 9172: previous, future, or all.
1.277 albertel 9173: 4. reference to array of permissible roles
1.288 raeburn 9174: 5. reference to array of section restrictions (optional)
9175: 6. reference to results object (hash of hashes).
9176: 7. reference to optional userdata hash
1.609 raeburn 9177: 8. reference to optional statushash
1.630 raeburn 9178: 9. flag if privileged users (except those set to unhide in
9179: course settings) should be excluded
1.609 raeburn 9180: Keys of top level results hash are roles.
1.275 raeburn 9181: Keys of inner hashes are username:domain, with
9182: values set to access type.
1.288 raeburn 9183: Optional userdata hash returns an array with arguments in the
9184: same order as loncoursedata::get_classlist() for student data.
9185:
1.609 raeburn 9186: Optional statushash returns
9187:
1.288 raeburn 9188: Entries for end, start, section and status are blank because
9189: of the possibility of multiple values for non-student roles.
9190:
1.275 raeburn 9191: =cut
1.405 albertel 9192:
1.275 raeburn 9193: ###############################################
1.405 albertel 9194:
1.275 raeburn 9195: sub get_course_users {
1.630 raeburn 9196: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9197: my %idx = ();
1.419 raeburn 9198: my %seclists;
1.288 raeburn 9199:
9200: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9201: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9202: $idx{end} = &Apache::loncoursedata::CL_END();
9203: $idx{start} = &Apache::loncoursedata::CL_START();
9204: $idx{id} = &Apache::loncoursedata::CL_ID();
9205: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9206: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9207: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9208:
1.290 albertel 9209: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9210: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9211: my $now = time;
1.277 albertel 9212: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9213: my $match = 0;
1.412 raeburn 9214: my $secmatch = 0;
1.419 raeburn 9215: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9216: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9217: if ($section eq '') {
9218: $section = 'none';
9219: }
1.291 albertel 9220: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9221: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9222: $secmatch = 1;
9223: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9224: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9225: $secmatch = 1;
9226: }
9227: } else {
1.419 raeburn 9228: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9229: $secmatch = 1;
9230: }
1.290 albertel 9231: }
1.412 raeburn 9232: if (!$secmatch) {
9233: next;
9234: }
1.419 raeburn 9235: }
1.275 raeburn 9236: if (defined($$types{'active'})) {
1.288 raeburn 9237: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9238: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9239: $match = 1;
1.275 raeburn 9240: }
9241: }
9242: if (defined($$types{'previous'})) {
1.609 raeburn 9243: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9244: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9245: $match = 1;
1.275 raeburn 9246: }
9247: }
9248: if (defined($$types{'future'})) {
1.609 raeburn 9249: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9250: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9251: $match = 1;
1.275 raeburn 9252: }
9253: }
1.609 raeburn 9254: if ($match) {
9255: push(@{$seclists{$student}},$section);
9256: if (ref($userdata) eq 'HASH') {
9257: $$userdata{$student} = $$classlist{$student};
9258: }
9259: if (ref($statushash) eq 'HASH') {
9260: $statushash->{$student}{'st'}{$section} = $status;
9261: }
1.288 raeburn 9262: }
1.275 raeburn 9263: }
9264: }
1.412 raeburn 9265: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9266: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9267: my $now = time;
1.609 raeburn 9268: my %displaystatus = ( previous => 'Expired',
9269: active => 'Active',
9270: future => 'Future',
9271: );
1.1075.2.36 raeburn 9272: my (%nothide,@possdoms);
1.630 raeburn 9273: if ($hidepriv) {
9274: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9275: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9276: if ($user !~ /:/) {
9277: $nothide{join(':',split(/[\@]/,$user))}=1;
9278: } else {
9279: $nothide{$user} = 1;
9280: }
9281: }
1.1075.2.36 raeburn 9282: my @possdoms = ($cdom);
9283: if ($coursehash{'checkforpriv'}) {
9284: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9285: }
1.630 raeburn 9286: }
1.439 raeburn 9287: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9288: my $match = 0;
1.412 raeburn 9289: my $secmatch = 0;
1.439 raeburn 9290: my $status;
1.412 raeburn 9291: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9292: $user =~ s/:$//;
1.439 raeburn 9293: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9294: if ($end == -1 || $start == -1) {
9295: next;
9296: }
9297: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9298: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9299: my ($uname,$udom) = split(/:/,$user);
9300: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9301: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9302: $secmatch = 1;
9303: } elsif ($usec eq '') {
1.420 albertel 9304: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9305: $secmatch = 1;
9306: }
9307: } else {
9308: if (grep(/^\Q$usec\E$/,@{$sections})) {
9309: $secmatch = 1;
9310: }
9311: }
9312: if (!$secmatch) {
9313: next;
9314: }
1.288 raeburn 9315: }
1.419 raeburn 9316: if ($usec eq '') {
9317: $usec = 'none';
9318: }
1.275 raeburn 9319: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9320: if ($hidepriv) {
1.1075.2.36 raeburn 9321: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9322: (!$nothide{$uname.':'.$udom})) {
9323: next;
9324: }
9325: }
1.503 raeburn 9326: if ($end > 0 && $end < $now) {
1.439 raeburn 9327: $status = 'previous';
9328: } elsif ($start > $now) {
9329: $status = 'future';
9330: } else {
9331: $status = 'active';
9332: }
1.277 albertel 9333: foreach my $type (keys(%{$types})) {
1.275 raeburn 9334: if ($status eq $type) {
1.420 albertel 9335: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9336: push(@{$$users{$role}{$user}},$type);
9337: }
1.288 raeburn 9338: $match = 1;
9339: }
9340: }
1.419 raeburn 9341: if (($match) && (ref($userdata) eq 'HASH')) {
9342: if (!exists($$userdata{$uname.':'.$udom})) {
9343: &get_user_info($udom,$uname,\%idx,$userdata);
9344: }
1.420 albertel 9345: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9346: push(@{$seclists{$uname.':'.$udom}},$usec);
9347: }
1.609 raeburn 9348: if (ref($statushash) eq 'HASH') {
9349: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9350: }
1.275 raeburn 9351: }
9352: }
9353: }
9354: }
1.290 albertel 9355: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9356: if ((defined($cdom)) && (defined($cnum))) {
9357: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9358: if ( defined($csettings{'internal.courseowner'}) ) {
9359: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9360: next if ($owner eq '');
9361: my ($ownername,$ownerdom);
9362: if ($owner =~ /^([^:]+):([^:]+)$/) {
9363: $ownername = $1;
9364: $ownerdom = $2;
9365: } else {
9366: $ownername = $owner;
9367: $ownerdom = $cdom;
9368: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9369: }
9370: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9371: if (defined($userdata) &&
1.609 raeburn 9372: !exists($$userdata{$owner})) {
9373: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9374: if (!grep(/^none$/,@{$seclists{$owner}})) {
9375: push(@{$seclists{$owner}},'none');
9376: }
9377: if (ref($statushash) eq 'HASH') {
9378: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9379: }
1.290 albertel 9380: }
1.279 raeburn 9381: }
9382: }
9383: }
1.419 raeburn 9384: foreach my $user (keys(%seclists)) {
9385: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9386: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9387: }
1.275 raeburn 9388: }
9389: return;
9390: }
9391:
1.288 raeburn 9392: sub get_user_info {
9393: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9394: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9395: &plainname($uname,$udom,'lastname');
1.291 albertel 9396: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9397: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9398: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9399: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9400: return;
9401: }
1.275 raeburn 9402:
1.472 raeburn 9403: ###############################################
9404:
9405: =pod
9406:
9407: =item * &get_user_quota()
9408:
1.1075.2.41 raeburn 9409: Retrieves quota assigned for storage of user files.
9410: Default is to report quota for portfolio files.
1.472 raeburn 9411:
9412: Incoming parameters:
9413: 1. user's username
9414: 2. user's domain
1.1075.2.41 raeburn 9415: 3. quota name - portfolio, author, or course
9416: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9417: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9418: course
1.472 raeburn 9419:
9420: Returns:
1.1075.2.58 raeburn 9421: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9422: 2. (Optional) Type of setting: custom or default
9423: (individually assigned or default for user's
9424: institutional status).
9425: 3. (Optional) - User's institutional status (e.g., faculty, staff
9426: or student - types as defined in localenroll::inst_usertypes
9427: for user's domain, which determines default quota for user.
9428: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9429:
9430: If a value has been stored in the user's environment,
1.536 raeburn 9431: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9432: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9433:
9434: =cut
9435:
9436: ###############################################
9437:
9438:
9439: sub get_user_quota {
1.1075.2.42 raeburn 9440: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9441: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9442: if (!defined($udom)) {
9443: $udom = $env{'user.domain'};
9444: }
9445: if (!defined($uname)) {
9446: $uname = $env{'user.name'};
9447: }
9448: if (($udom eq '' || $uname eq '') ||
9449: ($udom eq 'public') && ($uname eq 'public')) {
9450: $quota = 0;
1.536 raeburn 9451: $quotatype = 'default';
9452: $defquota = 0;
1.472 raeburn 9453: } else {
1.536 raeburn 9454: my $inststatus;
1.1075.2.41 raeburn 9455: if ($quotaname eq 'course') {
9456: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9457: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9458: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9459: } else {
9460: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9461: $quota = $cenv{'internal.uploadquota'};
9462: }
1.536 raeburn 9463: } else {
1.1075.2.41 raeburn 9464: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9465: if ($quotaname eq 'author') {
9466: $quota = $env{'environment.authorquota'};
9467: } else {
9468: $quota = $env{'environment.portfolioquota'};
9469: }
9470: $inststatus = $env{'environment.inststatus'};
9471: } else {
9472: my %userenv =
9473: &Apache::lonnet::get('environment',['portfolioquota',
9474: 'authorquota','inststatus'],$udom,$uname);
9475: my ($tmp) = keys(%userenv);
9476: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9477: if ($quotaname eq 'author') {
9478: $quota = $userenv{'authorquota'};
9479: } else {
9480: $quota = $userenv{'portfolioquota'};
9481: }
9482: $inststatus = $userenv{'inststatus'};
9483: } else {
9484: undef(%userenv);
9485: }
9486: }
9487: }
9488: if ($quota eq '' || wantarray) {
9489: if ($quotaname eq 'course') {
9490: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9491: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9492: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9493: $defquota = $domdefs{$crstype.'quota'};
9494: }
9495: if ($defquota eq '') {
9496: $defquota = 500;
9497: }
1.1075.2.41 raeburn 9498: } else {
9499: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9500: }
9501: if ($quota eq '') {
9502: $quota = $defquota;
9503: $quotatype = 'default';
9504: } else {
9505: $quotatype = 'custom';
9506: }
1.472 raeburn 9507: }
9508: }
1.536 raeburn 9509: if (wantarray) {
9510: return ($quota,$quotatype,$settingstatus,$defquota);
9511: } else {
9512: return $quota;
9513: }
1.472 raeburn 9514: }
9515:
9516: ###############################################
9517:
9518: =pod
9519:
9520: =item * &default_quota()
9521:
1.536 raeburn 9522: Retrieves default quota assigned for storage of user portfolio files,
9523: given an (optional) user's institutional status.
1.472 raeburn 9524:
9525: Incoming parameters:
1.1075.2.42 raeburn 9526:
1.472 raeburn 9527: 1. domain
1.536 raeburn 9528: 2. (Optional) institutional status(es). This is a : separated list of
9529: status types (e.g., faculty, staff, student etc.)
9530: which apply to the user for whom the default is being retrieved.
9531: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9532: default quota will be returned.
9533: 3. quota name - portfolio, author, or course
9534: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9535:
9536: Returns:
1.1075.2.42 raeburn 9537:
1.1075.2.58 raeburn 9538: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9539: 2. (Optional) institutional type which determined the value of the
9540: default quota.
1.472 raeburn 9541:
9542: If a value has been stored in the domain's configuration db,
9543: it will return that, otherwise it returns 20 (for backwards
9544: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9545: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9546:
1.536 raeburn 9547: If the user's status includes multiple types (e.g., staff and student),
9548: the largest default quota which applies to the user determines the
9549: default quota returned.
9550:
1.472 raeburn 9551: =cut
9552:
9553: ###############################################
9554:
9555:
9556: sub default_quota {
1.1075.2.41 raeburn 9557: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9558: my ($defquota,$settingstatus);
9559: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9560: ['quotas'],$udom);
1.1075.2.41 raeburn 9561: my $key = 'defaultquota';
9562: if ($quotaname eq 'author') {
9563: $key = 'authorquota';
9564: }
1.622 raeburn 9565: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9566: if ($inststatus ne '') {
1.765 raeburn 9567: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9568: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9569: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9570: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9571: if ($defquota eq '') {
1.1075.2.41 raeburn 9572: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9573: $settingstatus = $item;
1.1075.2.41 raeburn 9574: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9575: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9576: $settingstatus = $item;
9577: }
9578: }
1.1075.2.41 raeburn 9579: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9580: if ($quotahash{'quotas'}{$item} ne '') {
9581: if ($defquota eq '') {
9582: $defquota = $quotahash{'quotas'}{$item};
9583: $settingstatus = $item;
9584: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9585: $defquota = $quotahash{'quotas'}{$item};
9586: $settingstatus = $item;
9587: }
1.536 raeburn 9588: }
9589: }
9590: }
9591: }
9592: if ($defquota eq '') {
1.1075.2.41 raeburn 9593: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9594: $defquota = $quotahash{'quotas'}{$key}{'default'};
9595: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9596: $defquota = $quotahash{'quotas'}{'default'};
9597: }
1.536 raeburn 9598: $settingstatus = 'default';
1.1075.2.42 raeburn 9599: if ($defquota eq '') {
9600: if ($quotaname eq 'author') {
9601: $defquota = 500;
9602: }
9603: }
1.536 raeburn 9604: }
9605: } else {
9606: $settingstatus = 'default';
1.1075.2.41 raeburn 9607: if ($quotaname eq 'author') {
9608: $defquota = 500;
9609: } else {
9610: $defquota = 20;
9611: }
1.536 raeburn 9612: }
9613: if (wantarray) {
9614: return ($defquota,$settingstatus);
1.472 raeburn 9615: } else {
1.536 raeburn 9616: return $defquota;
1.472 raeburn 9617: }
9618: }
9619:
1.1075.2.41 raeburn 9620: ###############################################
9621:
9622: =pod
9623:
1.1075.2.42 raeburn 9624: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9625:
9626: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9627: of existing file within authoring space will cause quota for the authoring
9628: space to be exceeded.
9629:
9630: Same, if upload of a file directly to a course/community via Course Editor
9631: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9632:
1.1075.2.61 raeburn 9633: Inputs: 7
1.1075.2.42 raeburn 9634: 1. username or coursenum
1.1075.2.41 raeburn 9635: 2. domain
1.1075.2.42 raeburn 9636: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9637: 4. filename of file for which action is being requested
9638: 5. filesize (kB) of file
9639: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9640: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9641:
9642: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9643: otherwise return null.
9644:
1.1075.2.42 raeburn 9645: =back
9646:
1.1075.2.41 raeburn 9647: =cut
9648:
1.1075.2.42 raeburn 9649: sub excess_filesize_warning {
1.1075.2.59 raeburn 9650: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9651: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9652: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9653: if ($context eq 'author') {
9654: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9655: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9656: } else {
9657: foreach my $subdir ('docs','supplemental') {
9658: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9659: }
9660: }
1.1075.2.41 raeburn 9661: $disk_quota = int($disk_quota * 1000);
9662: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9663: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9664: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9665: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9666: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9667: $disk_quota,$current_disk_usage).
9668: '</p>';
9669: }
9670: return;
9671: }
9672:
9673: ###############################################
9674:
9675:
1.384 raeburn 9676: sub get_secgrprole_info {
9677: my ($cdom,$cnum,$needroles,$type) = @_;
9678: my %sections_count = &get_sections($cdom,$cnum);
9679: my @sections = (sort {$a <=> $b} keys(%sections_count));
9680: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9681: my @groups = sort(keys(%curr_groups));
9682: my $allroles = [];
9683: my $rolehash;
9684: my $accesshash = {
9685: active => 'Currently has access',
9686: future => 'Will have future access',
9687: previous => 'Previously had access',
9688: };
9689: if ($needroles) {
9690: $rolehash = {'all' => 'all'};
1.385 albertel 9691: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9692: if (&Apache::lonnet::error(%user_roles)) {
9693: undef(%user_roles);
9694: }
9695: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9696: my ($role)=split(/\:/,$item,2);
9697: if ($role eq 'cr') { next; }
9698: if ($role =~ /^cr/) {
9699: $$rolehash{$role} = (split('/',$role))[3];
9700: } else {
9701: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9702: }
9703: }
9704: foreach my $key (sort(keys(%{$rolehash}))) {
9705: push(@{$allroles},$key);
9706: }
9707: push (@{$allroles},'st');
9708: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9709: }
9710: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9711: }
9712:
1.555 raeburn 9713: sub user_picker {
1.1075.2.127 raeburn 9714: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 9715: my $currdom = $dom;
1.1075.2.114 raeburn 9716: my @alldoms = &Apache::lonnet::all_domains();
9717: if (@alldoms == 1) {
9718: my %domsrch = &Apache::lonnet::get_dom('configuration',
9719: ['directorysrch'],$alldoms[0]);
9720: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
9721: my $showdom = $domdesc;
9722: if ($showdom eq '') {
9723: $showdom = $dom;
9724: }
9725: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
9726: if ((!$domsrch{'directorysrch'}{'available'}) &&
9727: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
9728: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
9729: }
9730: }
9731: }
1.555 raeburn 9732: my %curr_selected = (
9733: srchin => 'dom',
1.580 raeburn 9734: srchby => 'lastname',
1.555 raeburn 9735: );
9736: my $srchterm;
1.625 raeburn 9737: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9738: if ($srch->{'srchby'} ne '') {
9739: $curr_selected{'srchby'} = $srch->{'srchby'};
9740: }
9741: if ($srch->{'srchin'} ne '') {
9742: $curr_selected{'srchin'} = $srch->{'srchin'};
9743: }
9744: if ($srch->{'srchtype'} ne '') {
9745: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9746: }
9747: if ($srch->{'srchdomain'} ne '') {
9748: $currdom = $srch->{'srchdomain'};
9749: }
9750: $srchterm = $srch->{'srchterm'};
9751: }
1.1075.2.98 raeburn 9752: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9753: 'usr' => 'Search criteria',
1.563 raeburn 9754: 'doma' => 'Domain/institution to search',
1.558 albertel 9755: 'uname' => 'username',
9756: 'lastname' => 'last name',
1.555 raeburn 9757: 'lastfirst' => 'last name, first name',
1.558 albertel 9758: 'crs' => 'in this course',
1.576 raeburn 9759: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9760: 'alc' => 'all LON-CAPA',
1.573 raeburn 9761: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9762: 'exact' => 'is',
9763: 'contains' => 'contains',
1.569 raeburn 9764: 'begins' => 'begins with',
1.1075.2.98 raeburn 9765: );
9766: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9767: 'youm' => "You must include some text to search for.",
9768: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9769: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9770: 'yomc' => "You must choose a domain when using an institutional directory search.",
9771: 'ymcd' => "You must choose a domain when using a domain search.",
9772: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9773: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9774: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9775: );
1.1075.2.98 raeburn 9776: &html_escape(\%html_lt);
9777: &js_escape(\%js_lt);
1.1075.2.115 raeburn 9778: my $domform;
1.1075.2.126 raeburn 9779: my $allow_blank = 1;
1.1075.2.115 raeburn 9780: if ($fixeddom) {
1.1075.2.126 raeburn 9781: $allow_blank = 0;
9782: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 9783: } else {
1.1075.2.126 raeburn 9784: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 9785: }
1.563 raeburn 9786: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9787:
9788: my @srchins = ('crs','dom','alc','instd');
9789:
9790: foreach my $option (@srchins) {
9791: # FIXME 'alc' option unavailable until
9792: # loncreateuser::print_user_query_page()
9793: # has been completed.
9794: next if ($option eq 'alc');
1.880 raeburn 9795: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9796: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 9797: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 9798: if ($curr_selected{'srchin'} eq $option) {
9799: $srchinsel .= '
1.1075.2.98 raeburn 9800: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9801: } else {
9802: $srchinsel .= '
1.1075.2.98 raeburn 9803: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9804: }
1.555 raeburn 9805: }
1.563 raeburn 9806: $srchinsel .= "\n </select>\n";
1.555 raeburn 9807:
9808: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9809: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9810: if ($curr_selected{'srchby'} eq $option) {
9811: $srchbysel .= '
1.1075.2.98 raeburn 9812: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9813: } else {
9814: $srchbysel .= '
1.1075.2.98 raeburn 9815: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9816: }
9817: }
9818: $srchbysel .= "\n </select>\n";
9819:
9820: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9821: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9822: if ($curr_selected{'srchtype'} eq $option) {
9823: $srchtypesel .= '
1.1075.2.98 raeburn 9824: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9825: } else {
9826: $srchtypesel .= '
1.1075.2.98 raeburn 9827: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9828: }
9829: }
9830: $srchtypesel .= "\n </select>\n";
9831:
1.558 albertel 9832: my ($newuserscript,$new_user_create);
1.994 raeburn 9833: my $context_dom = $env{'request.role.domain'};
9834: if ($context eq 'requestcrs') {
9835: if ($env{'form.coursedom'} ne '') {
9836: $context_dom = $env{'form.coursedom'};
9837: }
9838: }
1.556 raeburn 9839: if ($forcenewuser) {
1.576 raeburn 9840: if (ref($srch) eq 'HASH') {
1.994 raeburn 9841: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9842: if ($cancreate) {
9843: $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>';
9844: } else {
1.799 bisitz 9845: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9846: my %usertypetext = (
9847: official => 'institutional',
9848: unofficial => 'non-institutional',
9849: );
1.799 bisitz 9850: $new_user_create = '<p class="LC_warning">'
9851: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9852: .' '
9853: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9854: ,'<a href="'.$helplink.'">','</a>')
9855: .'</p><br />';
1.627 raeburn 9856: }
1.576 raeburn 9857: }
9858: }
9859:
1.556 raeburn 9860: $newuserscript = <<"ENDSCRIPT";
9861:
1.570 raeburn 9862: function setSearch(createnew,callingForm) {
1.556 raeburn 9863: if (createnew == 1) {
1.570 raeburn 9864: for (var i=0; i<callingForm.srchby.length; i++) {
9865: if (callingForm.srchby.options[i].value == 'uname') {
9866: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9867: }
9868: }
1.570 raeburn 9869: for (var i=0; i<callingForm.srchin.length; i++) {
9870: if ( callingForm.srchin.options[i].value == 'dom') {
9871: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9872: }
9873: }
1.570 raeburn 9874: for (var i=0; i<callingForm.srchtype.length; i++) {
9875: if (callingForm.srchtype.options[i].value == 'exact') {
9876: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9877: }
9878: }
1.570 raeburn 9879: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9880: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9881: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9882: }
9883: }
9884: }
9885: }
9886: ENDSCRIPT
1.558 albertel 9887:
1.556 raeburn 9888: }
9889:
1.555 raeburn 9890: my $output = <<"END_BLOCK";
1.556 raeburn 9891: <script type="text/javascript">
1.824 bisitz 9892: // <![CDATA[
1.570 raeburn 9893: function validateEntry(callingForm) {
1.558 albertel 9894:
1.556 raeburn 9895: var checkok = 1;
1.558 albertel 9896: var srchin;
1.570 raeburn 9897: for (var i=0; i<callingForm.srchin.length; i++) {
9898: if ( callingForm.srchin[i].checked ) {
9899: srchin = callingForm.srchin[i].value;
1.558 albertel 9900: }
9901: }
9902:
1.570 raeburn 9903: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9904: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9905: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9906: var srchterm = callingForm.srchterm.value;
9907: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9908: var msg = "";
9909:
9910: if (srchterm == "") {
9911: checkok = 0;
1.1075.2.98 raeburn 9912: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9913: }
9914:
1.569 raeburn 9915: if (srchtype== 'begins') {
9916: if (srchterm.length < 2) {
9917: checkok = 0;
1.1075.2.98 raeburn 9918: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9919: }
9920: }
9921:
1.556 raeburn 9922: if (srchtype== 'contains') {
9923: if (srchterm.length < 3) {
9924: checkok = 0;
1.1075.2.98 raeburn 9925: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 9926: }
9927: }
9928: if (srchin == 'instd') {
9929: if (srchdomain == '') {
9930: checkok = 0;
1.1075.2.98 raeburn 9931: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 9932: }
9933: }
9934: if (srchin == 'dom') {
9935: if (srchdomain == '') {
9936: checkok = 0;
1.1075.2.98 raeburn 9937: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 9938: }
9939: }
9940: if (srchby == 'lastfirst') {
9941: if (srchterm.indexOf(",") == -1) {
9942: checkok = 0;
1.1075.2.98 raeburn 9943: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 9944: }
9945: if (srchterm.indexOf(",") == srchterm.length -1) {
9946: checkok = 0;
1.1075.2.98 raeburn 9947: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 9948: }
9949: }
9950: if (checkok == 0) {
1.1075.2.98 raeburn 9951: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 9952: return;
9953: }
9954: if (checkok == 1) {
1.570 raeburn 9955: callingForm.submit();
1.556 raeburn 9956: }
9957: }
9958:
9959: $newuserscript
9960:
1.824 bisitz 9961: // ]]>
1.556 raeburn 9962: </script>
1.558 albertel 9963:
9964: $new_user_create
9965:
1.555 raeburn 9966: END_BLOCK
1.558 albertel 9967:
1.876 raeburn 9968: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 9969: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 9970: $domform.
9971: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 9972: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 9973: $srchbysel.
9974: $srchtypesel.
9975: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9976: $srchinsel.
9977: &Apache::lonhtmlcommon::row_closure(1).
9978: &Apache::lonhtmlcommon::end_pick_box().
9979: '<br />';
1.1075.2.114 raeburn 9980: return ($output,1);
1.555 raeburn 9981: }
9982:
1.612 raeburn 9983: sub user_rule_check {
1.615 raeburn 9984: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 9985: my ($response,%inst_response);
1.612 raeburn 9986: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 9987: if (keys(%{$usershash}) > 1) {
9988: my (%by_username,%by_id,%userdoms);
9989: my $checkid;
1.612 raeburn 9990: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 9991: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
9992: $checkid = 1;
9993: }
9994: }
9995: foreach my $user (keys(%{$usershash})) {
9996: my ($uname,$udom) = split(/:/,$user);
9997: if ($checkid) {
9998: if (ref($usershash->{$user}) eq 'HASH') {
9999: if ($usershash->{$user}->{'id'} ne '') {
10000: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10001: $userdoms{$udom} = 1;
10002: if (ref($inst_results) eq 'HASH') {
10003: $inst_results->{$uname.':'.$udom} = {};
10004: }
10005: }
10006: }
10007: } else {
10008: $by_username{$udom}{$uname} = 1;
10009: $userdoms{$udom} = 1;
10010: if (ref($inst_results) eq 'HASH') {
10011: $inst_results->{$uname.':'.$udom} = {};
10012: }
10013: }
10014: }
10015: foreach my $udom (keys(%userdoms)) {
10016: if (!$got_rules->{$udom}) {
10017: my %domconfig = &Apache::lonnet::get_dom('configuration',
10018: ['usercreation'],$udom);
10019: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10020: foreach my $item ('username','id') {
10021: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10022: $$curr_rules{$udom}{$item} =
10023: $domconfig{'usercreation'}{$item.'_rule'};
10024: }
10025: }
10026: }
10027: $got_rules->{$udom} = 1;
10028: }
10029: }
10030: if ($checkid) {
10031: foreach my $udom (keys(%by_id)) {
10032: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10033: if ($outcome eq 'ok') {
10034: foreach my $id (keys(%{$by_id{$udom}})) {
10035: my $uname = $by_id{$udom}{$id};
10036: $inst_response{$uname.':'.$udom} = $outcome;
10037: }
10038: if (ref($results) eq 'HASH') {
10039: foreach my $uname (keys(%{$results})) {
10040: if (exists($inst_response{$uname.':'.$udom})) {
10041: $inst_response{$uname.':'.$udom} = $outcome;
10042: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10043: }
10044: }
10045: }
10046: }
1.612 raeburn 10047: }
1.615 raeburn 10048: } else {
1.1075.2.99 raeburn 10049: foreach my $udom (keys(%by_username)) {
10050: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10051: if ($outcome eq 'ok') {
10052: foreach my $uname (keys(%{$by_username{$udom}})) {
10053: $inst_response{$uname.':'.$udom} = $outcome;
10054: }
10055: if (ref($results) eq 'HASH') {
10056: foreach my $uname (keys(%{$results})) {
10057: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10058: }
10059: }
10060: }
10061: }
1.612 raeburn 10062: }
1.1075.2.99 raeburn 10063: } elsif (keys(%{$usershash}) == 1) {
10064: my $user = (keys(%{$usershash}))[0];
10065: my ($uname,$udom) = split(/:/,$user);
10066: if (($udom ne '') && ($uname ne '')) {
10067: if (ref($usershash->{$user}) eq 'HASH') {
10068: if (ref($checks) eq 'HASH') {
10069: if (defined($checks->{'username'})) {
10070: ($inst_response{$user},%{$inst_results->{$user}}) =
10071: &Apache::lonnet::get_instuser($udom,$uname);
10072: } elsif (defined($checks->{'id'})) {
10073: if ($usershash->{$user}->{'id'} ne '') {
10074: ($inst_response{$user},%{$inst_results->{$user}}) =
10075: &Apache::lonnet::get_instuser($udom,undef,
10076: $usershash->{$user}->{'id'});
10077: } else {
10078: ($inst_response{$user},%{$inst_results->{$user}}) =
10079: &Apache::lonnet::get_instuser($udom,$uname);
10080: }
10081: }
10082: } else {
10083: ($inst_response{$user},%{$inst_results->{$user}}) =
10084: &Apache::lonnet::get_instuser($udom,$uname);
10085: return;
10086: }
10087: if (!$got_rules->{$udom}) {
10088: my %domconfig = &Apache::lonnet::get_dom('configuration',
10089: ['usercreation'],$udom);
10090: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10091: foreach my $item ('username','id') {
10092: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10093: $$curr_rules{$udom}{$item} =
10094: $domconfig{'usercreation'}{$item.'_rule'};
10095: }
10096: }
1.585 raeburn 10097: }
1.1075.2.99 raeburn 10098: $got_rules->{$udom} = 1;
1.585 raeburn 10099: }
10100: }
1.1075.2.99 raeburn 10101: } else {
10102: return;
10103: }
10104: } else {
10105: return;
10106: }
10107: foreach my $user (keys(%{$usershash})) {
10108: my ($uname,$udom) = split(/:/,$user);
10109: next if (($udom eq '') || ($uname eq ''));
10110: my $id;
10111: if (ref($inst_results) eq 'HASH') {
10112: if (ref($inst_results->{$user}) eq 'HASH') {
10113: $id = $inst_results->{$user}->{'id'};
10114: }
10115: }
10116: if ($id eq '') {
10117: if (ref($usershash->{$user})) {
10118: $id = $usershash->{$user}->{'id'};
10119: }
1.585 raeburn 10120: }
1.612 raeburn 10121: foreach my $item (keys(%{$checks})) {
10122: if (ref($$curr_rules{$udom}) eq 'HASH') {
10123: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10124: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10125: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10126: $$curr_rules{$udom}{$item});
1.612 raeburn 10127: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10128: if ($rule_check{$rule}) {
10129: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10130: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10131: if (ref($inst_results) eq 'HASH') {
10132: if (ref($inst_results->{$user}) eq 'HASH') {
10133: if (keys(%{$inst_results->{$user}}) == 0) {
10134: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10135: } elsif ($item eq 'id') {
10136: if ($inst_results->{$user}->{'id'} eq '') {
10137: $$alerts{$item}{$udom}{$uname} = 1;
10138: }
1.615 raeburn 10139: }
1.612 raeburn 10140: }
10141: }
1.615 raeburn 10142: }
10143: last;
1.585 raeburn 10144: }
10145: }
10146: }
10147: }
10148: }
10149: }
10150: }
10151: }
1.612 raeburn 10152: return;
10153: }
10154:
10155: sub user_rule_formats {
10156: my ($domain,$domdesc,$curr_rules,$check) = @_;
10157: my %text = (
10158: 'username' => 'Usernames',
10159: 'id' => 'IDs',
10160: );
10161: my $output;
10162: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10163: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10164: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10165: $output = '<br />'.
10166: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10167: '<span class="LC_cusr_emph">','</span>',$domdesc).
10168: ' <ul>';
1.612 raeburn 10169: foreach my $rule (@{$ruleorder}) {
10170: if (ref($curr_rules) eq 'ARRAY') {
10171: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10172: if (ref($rules->{$rule}) eq 'HASH') {
10173: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10174: $rules->{$rule}{'desc'}.'</li>';
10175: }
10176: }
10177: }
10178: }
10179: $output .= '</ul>';
10180: }
10181: }
10182: return $output;
10183: }
10184:
10185: sub instrule_disallow_msg {
1.615 raeburn 10186: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10187: my $response;
10188: my %text = (
10189: item => 'username',
10190: items => 'usernames',
10191: match => 'matches',
10192: do => 'does',
10193: action => 'a username',
10194: one => 'one',
10195: );
10196: if ($count > 1) {
10197: $text{'item'} = 'usernames';
10198: $text{'match'} ='match';
10199: $text{'do'} = 'do';
10200: $text{'action'} = 'usernames',
10201: $text{'one'} = 'ones';
10202: }
10203: if ($checkitem eq 'id') {
10204: $text{'items'} = 'IDs';
10205: $text{'item'} = 'ID';
10206: $text{'action'} = 'an ID';
1.615 raeburn 10207: if ($count > 1) {
10208: $text{'item'} = 'IDs';
10209: $text{'action'} = 'IDs';
10210: }
1.612 raeburn 10211: }
1.674 bisitz 10212: $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 10213: if ($mode eq 'upload') {
10214: if ($checkitem eq 'username') {
10215: $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'}.");
10216: } elsif ($checkitem eq 'id') {
1.674 bisitz 10217: $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 10218: }
1.669 raeburn 10219: } elsif ($mode eq 'selfcreate') {
10220: if ($checkitem eq 'id') {
10221: $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.");
10222: }
1.615 raeburn 10223: } else {
10224: if ($checkitem eq 'username') {
10225: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10226: } elsif ($checkitem eq 'id') {
10227: $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.");
10228: }
1.612 raeburn 10229: }
10230: return $response;
1.585 raeburn 10231: }
10232:
1.624 raeburn 10233: sub personal_data_fieldtitles {
10234: my %fieldtitles = &Apache::lonlocal::texthash (
10235: id => 'Student/Employee ID',
10236: permanentemail => 'E-mail address',
10237: lastname => 'Last Name',
10238: firstname => 'First Name',
10239: middlename => 'Middle Name',
10240: generation => 'Generation',
10241: gen => 'Generation',
1.765 raeburn 10242: inststatus => 'Affiliation',
1.624 raeburn 10243: );
10244: return %fieldtitles;
10245: }
10246:
1.642 raeburn 10247: sub sorted_inst_types {
10248: my ($dom) = @_;
1.1075.2.70 raeburn 10249: my ($usertypes,$order);
10250: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10251: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10252: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10253: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10254: } else {
10255: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10256: }
1.642 raeburn 10257: my $othertitle = &mt('All users');
10258: if ($env{'request.course.id'}) {
1.668 raeburn 10259: $othertitle = &mt('Any users');
1.642 raeburn 10260: }
10261: my @types;
10262: if (ref($order) eq 'ARRAY') {
10263: @types = @{$order};
10264: }
10265: if (@types == 0) {
10266: if (ref($usertypes) eq 'HASH') {
10267: @types = sort(keys(%{$usertypes}));
10268: }
10269: }
10270: if (keys(%{$usertypes}) > 0) {
10271: $othertitle = &mt('Other users');
10272: }
10273: return ($othertitle,$usertypes,\@types);
10274: }
10275:
1.645 raeburn 10276: sub get_institutional_codes {
10277: my ($settings,$allcourses,$LC_code) = @_;
10278: # Get complete list of course sections to update
10279: my @currsections = ();
10280: my @currxlists = ();
10281: my $coursecode = $$settings{'internal.coursecode'};
10282:
10283: if ($$settings{'internal.sectionnums'} ne '') {
10284: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10285: }
10286:
10287: if ($$settings{'internal.crosslistings'} ne '') {
10288: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10289: }
10290:
10291: if (@currxlists > 0) {
10292: foreach (@currxlists) {
10293: if (m/^([^:]+):(\w*)$/) {
10294: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10295: push(@{$allcourses},$1);
1.645 raeburn 10296: $$LC_code{$1} = $2;
10297: }
10298: }
10299: }
10300: }
10301:
10302: if (@currsections > 0) {
10303: foreach (@currsections) {
10304: if (m/^(\w+):(\w*)$/) {
10305: my $sec = $coursecode.$1;
10306: my $lc_sec = $2;
10307: unless (grep/^$sec$/,@{$allcourses}) {
1.1075.2.119 raeburn 10308: push(@{$allcourses},$sec);
1.645 raeburn 10309: $$LC_code{$sec} = $lc_sec;
10310: }
10311: }
10312: }
10313: }
10314: return;
10315: }
10316:
1.971 raeburn 10317: sub get_standard_codeitems {
10318: return ('Year','Semester','Department','Number','Section');
10319: }
10320:
1.112 bowersj2 10321: =pod
10322:
1.780 raeburn 10323: =head1 Slot Helpers
10324:
10325: =over 4
10326:
10327: =item * sorted_slots()
10328:
1.1040 raeburn 10329: Sorts an array of slot names in order of an optional sort key,
10330: default sort is by slot start time (earliest first).
1.780 raeburn 10331:
10332: Inputs:
10333:
10334: =over 4
10335:
10336: slotsarr - Reference to array of unsorted slot names.
10337:
10338: slots - Reference to hash of hash, where outer hash keys are slot names.
10339:
1.1040 raeburn 10340: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10341:
1.549 albertel 10342: =back
10343:
1.780 raeburn 10344: Returns:
10345:
10346: =over 4
10347:
1.1040 raeburn 10348: sorted - An array of slot names sorted by a specified sort key
10349: (default sort key is start time of the slot).
1.780 raeburn 10350:
10351: =back
10352:
10353: =cut
10354:
10355:
10356: sub sorted_slots {
1.1040 raeburn 10357: my ($slotsarr,$slots,$sortkey) = @_;
10358: if ($sortkey eq '') {
10359: $sortkey = 'starttime';
10360: }
1.780 raeburn 10361: my @sorted;
10362: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10363: @sorted =
10364: sort {
10365: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10366: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10367: }
10368: if (ref($slots->{$a})) { return -1;}
10369: if (ref($slots->{$b})) { return 1;}
10370: return 0;
10371: } @{$slotsarr};
10372: }
10373: return @sorted;
10374: }
10375:
1.1040 raeburn 10376: =pod
10377:
10378: =item * get_future_slots()
10379:
10380: Inputs:
10381:
10382: =over 4
10383:
10384: cnum - course number
10385:
10386: cdom - course domain
10387:
10388: now - current UNIX time
10389:
10390: symb - optional symb
10391:
10392: =back
10393:
10394: Returns:
10395:
10396: =over 4
10397:
10398: sorted_reservable - ref to array of student_schedulable slots currently
10399: reservable, ordered by end date of reservation period.
10400:
10401: reservable_now - ref to hash of student_schedulable slots currently
10402: reservable.
10403:
10404: Keys in inner hash are:
10405: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10406: (b) endreserve: end date of reservation period.
10407: (c) uniqueperiod: start,end dates when slot is to be uniquely
10408: selected.
1.1040 raeburn 10409:
10410: sorted_future - ref to array of student_schedulable slots reservable in
10411: the future, ordered by start date of reservation period.
10412:
10413: future_reservable - ref to hash of student_schedulable slots reservable
10414: in the future.
10415:
10416: Keys in inner hash are:
10417: (a) symb: either blank or symb to which slot use is restricted.
10418: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10419: (c) uniqueperiod: start,end dates when slot is to be uniquely
10420: selected.
1.1040 raeburn 10421:
10422: =back
10423:
10424: =cut
10425:
10426: sub get_future_slots {
10427: my ($cnum,$cdom,$now,$symb) = @_;
10428: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10429: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10430: foreach my $slot (keys(%slots)) {
10431: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10432: if ($symb) {
10433: next if (($slots{$slot}->{'symb'} ne '') &&
10434: ($slots{$slot}->{'symb'} ne $symb));
10435: }
10436: if (($slots{$slot}->{'starttime'} > $now) &&
10437: ($slots{$slot}->{'endtime'} > $now)) {
10438: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10439: my $userallowed = 0;
10440: if ($slots{$slot}->{'allowedsections'}) {
10441: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10442: if (!defined($env{'request.role.sec'})
10443: && grep(/^No section assigned$/,@allowed_sec)) {
10444: $userallowed=1;
10445: } else {
10446: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10447: $userallowed=1;
10448: }
10449: }
10450: unless ($userallowed) {
10451: if (defined($env{'request.course.groups'})) {
10452: my @groups = split(/:/,$env{'request.course.groups'});
10453: foreach my $group (@groups) {
10454: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10455: $userallowed=1;
10456: last;
10457: }
10458: }
10459: }
10460: }
10461: }
10462: if ($slots{$slot}->{'allowedusers'}) {
10463: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10464: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10465: if (grep(/^\Q$user\E$/,@allowed_users)) {
10466: $userallowed = 1;
10467: }
10468: }
10469: next unless($userallowed);
10470: }
10471: my $startreserve = $slots{$slot}->{'startreserve'};
10472: my $endreserve = $slots{$slot}->{'endreserve'};
10473: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10474: my $uniqueperiod;
10475: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10476: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10477: }
1.1040 raeburn 10478: if (($startreserve < $now) &&
10479: (!$endreserve || $endreserve > $now)) {
10480: my $lastres = $endreserve;
10481: if (!$lastres) {
10482: $lastres = $slots{$slot}->{'starttime'};
10483: }
10484: $reservable_now{$slot} = {
10485: symb => $symb,
1.1075.2.104 raeburn 10486: endreserve => $lastres,
10487: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10488: };
10489: } elsif (($startreserve > $now) &&
10490: (!$endreserve || $endreserve > $startreserve)) {
10491: $future_reservable{$slot} = {
10492: symb => $symb,
1.1075.2.104 raeburn 10493: startreserve => $startreserve,
10494: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10495: };
10496: }
10497: }
10498: }
10499: my @unsorted_reservable = keys(%reservable_now);
10500: if (@unsorted_reservable > 0) {
10501: @sorted_reservable =
10502: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10503: }
10504: my @unsorted_future = keys(%future_reservable);
10505: if (@unsorted_future > 0) {
10506: @sorted_future =
10507: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10508: }
10509: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10510: }
1.780 raeburn 10511:
10512: =pod
10513:
1.1057 foxr 10514: =back
10515:
1.549 albertel 10516: =head1 HTTP Helpers
10517:
10518: =over 4
10519:
1.648 raeburn 10520: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10521:
1.258 albertel 10522: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10523: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10524: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10525:
10526: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10527: $possible_names is an ref to an array of form element names. As an example:
10528: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10529: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10530:
10531: =cut
1.1 albertel 10532:
1.6 albertel 10533: sub get_unprocessed_cgi {
1.25 albertel 10534: my ($query,$possible_names)= @_;
1.26 matthew 10535: # $Apache::lonxml::debug=1;
1.356 albertel 10536: foreach my $pair (split(/&/,$query)) {
10537: my ($name, $value) = split(/=/,$pair);
1.369 www 10538: $name = &unescape($name);
1.25 albertel 10539: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10540: $value =~ tr/+/ /;
10541: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10542: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10543: }
1.16 harris41 10544: }
1.6 albertel 10545: }
10546:
1.112 bowersj2 10547: =pod
10548:
1.648 raeburn 10549: =item * &cacheheader()
1.112 bowersj2 10550:
10551: returns cache-controlling header code
10552:
10553: =cut
10554:
1.7 albertel 10555: sub cacheheader {
1.258 albertel 10556: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10557: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10558: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10559: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10560: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10561: return $output;
1.7 albertel 10562: }
10563:
1.112 bowersj2 10564: =pod
10565:
1.648 raeburn 10566: =item * &no_cache($r)
1.112 bowersj2 10567:
10568: specifies header code to not have cache
10569:
10570: =cut
10571:
1.9 albertel 10572: sub no_cache {
1.216 albertel 10573: my ($r) = @_;
10574: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10575: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10576: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10577: $r->no_cache(1);
10578: $r->header_out("Expires" => $date);
10579: $r->header_out("Pragma" => "no-cache");
1.123 www 10580: }
10581:
10582: sub content_type {
1.181 albertel 10583: my ($r,$type,$charset) = @_;
1.299 foxr 10584: if ($r) {
10585: # Note that printout.pl calls this with undef for $r.
10586: &no_cache($r);
10587: }
1.258 albertel 10588: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10589: unless ($charset) {
10590: $charset=&Apache::lonlocal::current_encoding;
10591: }
10592: if ($charset) { $type.='; charset='.$charset; }
10593: if ($r) {
10594: $r->content_type($type);
10595: } else {
10596: print("Content-type: $type\n\n");
10597: }
1.9 albertel 10598: }
1.25 albertel 10599:
1.112 bowersj2 10600: =pod
10601:
1.648 raeburn 10602: =item * &add_to_env($name,$value)
1.112 bowersj2 10603:
1.258 albertel 10604: adds $name to the %env hash with value
1.112 bowersj2 10605: $value, if $name already exists, the entry is converted to an array
10606: reference and $value is added to the array.
10607:
10608: =cut
10609:
1.25 albertel 10610: sub add_to_env {
10611: my ($name,$value)=@_;
1.258 albertel 10612: if (defined($env{$name})) {
10613: if (ref($env{$name})) {
1.25 albertel 10614: #already have multiple values
1.258 albertel 10615: push(@{ $env{$name} },$value);
1.25 albertel 10616: } else {
10617: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10618: my $first=$env{$name};
10619: undef($env{$name});
10620: push(@{ $env{$name} },$first,$value);
1.25 albertel 10621: }
10622: } else {
1.258 albertel 10623: $env{$name}=$value;
1.25 albertel 10624: }
1.31 albertel 10625: }
1.149 albertel 10626:
10627: =pod
10628:
1.648 raeburn 10629: =item * &get_env_multiple($name)
1.149 albertel 10630:
1.258 albertel 10631: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10632: values may be defined and end up as an array ref.
10633:
10634: returns an array of values
10635:
10636: =cut
10637:
10638: sub get_env_multiple {
10639: my ($name) = @_;
10640: my @values;
1.258 albertel 10641: if (defined($env{$name})) {
1.149 albertel 10642: # exists is it an array
1.258 albertel 10643: if (ref($env{$name})) {
10644: @values=@{ $env{$name} };
1.149 albertel 10645: } else {
1.258 albertel 10646: $values[0]=$env{$name};
1.149 albertel 10647: }
10648: }
10649: return(@values);
10650: }
10651:
1.660 raeburn 10652: sub ask_for_embedded_content {
10653: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10654: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10655: %currsubfile,%unused,$rem);
1.1071 raeburn 10656: my $counter = 0;
10657: my $numnew = 0;
1.987 raeburn 10658: my $numremref = 0;
10659: my $numinvalid = 0;
10660: my $numpathchg = 0;
10661: my $numexisting = 0;
1.1071 raeburn 10662: my $numunused = 0;
10663: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10664: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10665: my $heading = &mt('Upload embedded files');
10666: my $buttontext = &mt('Upload');
10667:
1.1075.2.11 raeburn 10668: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10669: if ($actionurl eq '/adm/dependencies') {
10670: $navmap = Apache::lonnavmaps::navmap->new();
10671: }
10672: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10673: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10674: }
1.1075.2.35 raeburn 10675: if (($actionurl eq '/adm/portfolio') ||
10676: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10677: my $current_path='/';
10678: if ($env{'form.currentpath'}) {
10679: $current_path = $env{'form.currentpath'};
10680: }
10681: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10682: $udom = $cdom;
10683: $uname = $cnum;
1.984 raeburn 10684: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10685: } else {
10686: $udom = $env{'user.domain'};
10687: $uname = $env{'user.name'};
10688: $url = '/userfiles/portfolio';
10689: }
1.987 raeburn 10690: $toplevel = $url.'/';
1.984 raeburn 10691: $url .= $current_path;
10692: $getpropath = 1;
1.987 raeburn 10693: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10694: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10695: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10696: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10697: $toplevel = $url;
1.984 raeburn 10698: if ($rest ne '') {
1.987 raeburn 10699: $url .= $rest;
10700: }
10701: } elsif ($actionurl eq '/adm/coursedocs') {
10702: if (ref($args) eq 'HASH') {
1.1071 raeburn 10703: $url = $args->{'docs_url'};
10704: $toplevel = $url;
1.1075.2.11 raeburn 10705: if ($args->{'context'} eq 'paste') {
10706: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10707: ($path) =
10708: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10709: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10710: $fileloc =~ s{^/}{};
10711: }
1.1071 raeburn 10712: }
10713: } elsif ($actionurl eq '/adm/dependencies') {
10714: if ($env{'request.course.id'} ne '') {
10715: if (ref($args) eq 'HASH') {
10716: $url = $args->{'docs_url'};
10717: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10718: $toplevel = $url;
10719: unless ($toplevel =~ m{^/}) {
10720: $toplevel = "/$url";
10721: }
1.1075.2.11 raeburn 10722: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10723: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10724: $path = $1;
10725: } else {
10726: ($path) =
10727: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10728: }
1.1075.2.79 raeburn 10729: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10730: $fileloc = $toplevel;
10731: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10732: my ($udom,$uname,$fname) =
10733: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10734: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10735: } else {
10736: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10737: }
1.1071 raeburn 10738: $fileloc =~ s{^/}{};
10739: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10740: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10741: }
1.987 raeburn 10742: }
1.1075.2.35 raeburn 10743: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10744: $udom = $cdom;
10745: $uname = $cnum;
10746: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10747: $toplevel = $url;
10748: $path = $url;
10749: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10750: $fileloc =~ s{^/}{};
10751: }
10752: foreach my $file (keys(%{$allfiles})) {
10753: my $embed_file;
10754: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10755: $embed_file = $1;
10756: } else {
10757: $embed_file = $file;
10758: }
1.1075.2.55 raeburn 10759: my ($absolutepath,$cleaned_file);
10760: if ($embed_file =~ m{^\w+://}) {
10761: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10762: $newfiles{$cleaned_file} = 1;
10763: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10764: } else {
1.1075.2.55 raeburn 10765: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10766: if ($embed_file =~ m{^/}) {
10767: $absolutepath = $embed_file;
10768: }
1.1075.2.47 raeburn 10769: if ($cleaned_file =~ m{/}) {
10770: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10771: $path = &check_for_traversal($path,$url,$toplevel);
10772: my $item = $fname;
10773: if ($path ne '') {
10774: $item = $path.'/'.$fname;
10775: $subdependencies{$path}{$fname} = 1;
10776: } else {
10777: $dependencies{$item} = 1;
10778: }
10779: if ($absolutepath) {
10780: $mapping{$item} = $absolutepath;
10781: } else {
10782: $mapping{$item} = $embed_file;
10783: }
10784: } else {
10785: $dependencies{$embed_file} = 1;
10786: if ($absolutepath) {
1.1075.2.47 raeburn 10787: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10788: } else {
1.1075.2.47 raeburn 10789: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10790: }
10791: }
1.984 raeburn 10792: }
10793: }
1.1071 raeburn 10794: my $dirptr = 16384;
1.984 raeburn 10795: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10796: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10797: if (($actionurl eq '/adm/portfolio') ||
10798: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10799: my ($sublistref,$listerror) =
10800: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10801: if (ref($sublistref) eq 'ARRAY') {
10802: foreach my $line (@{$sublistref}) {
10803: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10804: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10805: }
1.984 raeburn 10806: }
1.987 raeburn 10807: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10808: if (opendir(my $dir,$url.'/'.$path)) {
10809: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10810: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10811: }
1.1075.2.11 raeburn 10812: } elsif (($actionurl eq '/adm/dependencies') ||
10813: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10814: ($args->{'context'} eq 'paste')) ||
10815: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10816: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10817: my $dir;
10818: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10819: $dir = $fileloc;
10820: } else {
10821: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10822: }
1.1071 raeburn 10823: if ($dir ne '') {
10824: my ($sublistref,$listerror) =
10825: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10826: if (ref($sublistref) eq 'ARRAY') {
10827: foreach my $line (@{$sublistref}) {
10828: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10829: undef,$mtime)=split(/\&/,$line,12);
10830: unless (($testdir&$dirptr) ||
10831: ($file_name =~ /^\.\.?$/)) {
10832: $currsubfile{$path}{$file_name} = [$size,$mtime];
10833: }
10834: }
10835: }
10836: }
1.984 raeburn 10837: }
10838: }
10839: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10840: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10841: my $item = $path.'/'.$file;
10842: unless ($mapping{$item} eq $item) {
10843: $pathchanges{$item} = 1;
10844: }
10845: $existing{$item} = 1;
10846: $numexisting ++;
10847: } else {
10848: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10849: }
10850: }
1.1071 raeburn 10851: if ($actionurl eq '/adm/dependencies') {
10852: foreach my $path (keys(%currsubfile)) {
10853: if (ref($currsubfile{$path}) eq 'HASH') {
10854: foreach my $file (keys(%{$currsubfile{$path}})) {
10855: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10856: next if (($rem ne '') &&
10857: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10858: (ref($navmap) &&
10859: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10860: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10861: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10862: $unused{$path.'/'.$file} = 1;
10863: }
10864: }
10865: }
10866: }
10867: }
1.984 raeburn 10868: }
1.987 raeburn 10869: my %currfile;
1.1075.2.35 raeburn 10870: if (($actionurl eq '/adm/portfolio') ||
10871: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10872: my ($dirlistref,$listerror) =
10873: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10874: if (ref($dirlistref) eq 'ARRAY') {
10875: foreach my $line (@{$dirlistref}) {
10876: my ($file_name,$rest) = split(/\&/,$line,2);
10877: $currfile{$file_name} = 1;
10878: }
1.984 raeburn 10879: }
1.987 raeburn 10880: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10881: if (opendir(my $dir,$url)) {
1.987 raeburn 10882: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10883: map {$currfile{$_} = 1;} @dir_list;
10884: }
1.1075.2.11 raeburn 10885: } elsif (($actionurl eq '/adm/dependencies') ||
10886: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10887: ($args->{'context'} eq 'paste')) ||
10888: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10889: if ($env{'request.course.id'} ne '') {
10890: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10891: if ($dir ne '') {
10892: my ($dirlistref,$listerror) =
10893: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10894: if (ref($dirlistref) eq 'ARRAY') {
10895: foreach my $line (@{$dirlistref}) {
10896: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10897: $size,undef,$mtime)=split(/\&/,$line,12);
10898: unless (($testdir&$dirptr) ||
10899: ($file_name =~ /^\.\.?$/)) {
10900: $currfile{$file_name} = [$size,$mtime];
10901: }
10902: }
10903: }
10904: }
10905: }
1.984 raeburn 10906: }
10907: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10908: if (exists($currfile{$file})) {
1.987 raeburn 10909: unless ($mapping{$file} eq $file) {
10910: $pathchanges{$file} = 1;
10911: }
10912: $existing{$file} = 1;
10913: $numexisting ++;
10914: } else {
1.984 raeburn 10915: $newfiles{$file} = 1;
10916: }
10917: }
1.1071 raeburn 10918: foreach my $file (keys(%currfile)) {
10919: unless (($file eq $filename) ||
10920: ($file eq $filename.'.bak') ||
10921: ($dependencies{$file})) {
1.1075.2.11 raeburn 10922: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10923: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10924: next if (($rem ne '') &&
10925: (($env{"httpref.$rem".$file} ne '') ||
10926: (ref($navmap) &&
10927: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10928: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10929: ($navmap->getResourceByUrl($rem.$1)))))));
10930: }
1.1075.2.11 raeburn 10931: }
1.1071 raeburn 10932: $unused{$file} = 1;
10933: }
10934: }
1.1075.2.11 raeburn 10935: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10936: ($args->{'context'} eq 'paste')) {
10937: $counter = scalar(keys(%existing));
10938: $numpathchg = scalar(keys(%pathchanges));
10939: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10940: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10941: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10942: $counter = scalar(keys(%existing));
10943: $numpathchg = scalar(keys(%pathchanges));
10944: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10945: }
1.984 raeburn 10946: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10947: if ($actionurl eq '/adm/dependencies') {
10948: next if ($embed_file =~ m{^\w+://});
10949: }
1.660 raeburn 10950: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10951: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10952: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10953: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10954: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10955: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10956: }
1.1075.2.35 raeburn 10957: $upload_output .= '</td>';
1.1071 raeburn 10958: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10959: $upload_output.='<td align="right">'.
10960: '<span class="LC_info LC_fontsize_medium">'.
10961: &mt("URL points to web address").'</span>';
1.987 raeburn 10962: $numremref++;
1.660 raeburn 10963: } elsif ($args->{'error_on_invalid_names'}
10964: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10965: $upload_output.='<td align="right"><span class="LC_warning">'.
10966: &mt('Invalid characters').'</span>';
1.987 raeburn 10967: $numinvalid++;
1.660 raeburn 10968: } else {
1.1075.2.35 raeburn 10969: $upload_output .= '<td>'.
10970: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10971: $embed_file,\%mapping,
1.1071 raeburn 10972: $allfiles,$codebase,'upload');
10973: $counter ++;
10974: $numnew ++;
1.987 raeburn 10975: }
10976: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10977: }
10978: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10979: if ($actionurl eq '/adm/dependencies') {
10980: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10981: $modify_output .= &start_data_table_row().
10982: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10983: '<img src="'.&icon($embed_file).'" border="0" />'.
10984: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10985: '<td>'.$size.'</td>'.
10986: '<td>'.$mtime.'</td>'.
10987: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10988: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10989: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10990: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10991: &embedded_file_element('upload_embedded',$counter,
10992: $embed_file,\%mapping,
10993: $allfiles,$codebase,'modify').
10994: '</div></td>'.
10995: &end_data_table_row()."\n";
10996: $counter ++;
10997: } else {
10998: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10999: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11000: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11001: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11002: &Apache::loncommon::end_data_table_row()."\n";
11003: }
11004: }
11005: my $delidx = $counter;
11006: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11007: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11008: $delete_output .= &start_data_table_row().
11009: '<td><img src="'.&icon($oldfile).'" />'.
11010: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11011: '<td>'.$size.'</td>'.
11012: '<td>'.$mtime.'</td>'.
11013: '<td><label><input type="checkbox" name="del_upload_dep" '.
11014: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11015: &embedded_file_element('upload_embedded',$delidx,
11016: $oldfile,\%mapping,$allfiles,
11017: $codebase,'delete').'</td>'.
11018: &end_data_table_row()."\n";
11019: $numunused ++;
11020: $delidx ++;
1.987 raeburn 11021: }
11022: if ($upload_output) {
11023: $upload_output = &start_data_table().
11024: $upload_output.
11025: &end_data_table()."\n";
11026: }
1.1071 raeburn 11027: if ($modify_output) {
11028: $modify_output = &start_data_table().
11029: &start_data_table_header_row().
11030: '<th>'.&mt('File').'</th>'.
11031: '<th>'.&mt('Size (KB)').'</th>'.
11032: '<th>'.&mt('Modified').'</th>'.
11033: '<th>'.&mt('Upload replacement?').'</th>'.
11034: &end_data_table_header_row().
11035: $modify_output.
11036: &end_data_table()."\n";
11037: }
11038: if ($delete_output) {
11039: $delete_output = &start_data_table().
11040: &start_data_table_header_row().
11041: '<th>'.&mt('File').'</th>'.
11042: '<th>'.&mt('Size (KB)').'</th>'.
11043: '<th>'.&mt('Modified').'</th>'.
11044: '<th>'.&mt('Delete?').'</th>'.
11045: &end_data_table_header_row().
11046: $delete_output.
11047: &end_data_table()."\n";
11048: }
1.987 raeburn 11049: my $applies = 0;
11050: if ($numremref) {
11051: $applies ++;
11052: }
11053: if ($numinvalid) {
11054: $applies ++;
11055: }
11056: if ($numexisting) {
11057: $applies ++;
11058: }
1.1071 raeburn 11059: if ($counter || $numunused) {
1.987 raeburn 11060: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11061: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11062: $state.'<h3>'.$heading.'</h3>';
11063: if ($actionurl eq '/adm/dependencies') {
11064: if ($numnew) {
11065: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11066: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11067: $upload_output.'<br />'."\n";
11068: }
11069: if ($numexisting) {
11070: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11071: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11072: $modify_output.'<br />'."\n";
11073: $buttontext = &mt('Save changes');
11074: }
11075: if ($numunused) {
11076: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11077: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11078: $delete_output.'<br />'."\n";
11079: $buttontext = &mt('Save changes');
11080: }
11081: } else {
11082: $output .= $upload_output.'<br />'."\n";
11083: }
11084: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11085: $counter.'" />'."\n";
11086: if ($actionurl eq '/adm/dependencies') {
11087: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11088: $numnew.'" />'."\n";
11089: } elsif ($actionurl eq '') {
1.987 raeburn 11090: $output .= '<input type="hidden" name="phase" value="three" />';
11091: }
11092: } elsif ($applies) {
11093: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11094: if ($applies > 1) {
11095: $output .=
1.1075.2.35 raeburn 11096: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11097: if ($numremref) {
11098: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11099: }
11100: if ($numinvalid) {
11101: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11102: }
11103: if ($numexisting) {
11104: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11105: }
11106: $output .= '</ul><br />';
11107: } elsif ($numremref) {
11108: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11109: } elsif ($numinvalid) {
11110: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11111: } elsif ($numexisting) {
11112: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11113: }
11114: $output .= $upload_output.'<br />';
11115: }
11116: my ($pathchange_output,$chgcount);
1.1071 raeburn 11117: $chgcount = $counter;
1.987 raeburn 11118: if (keys(%pathchanges) > 0) {
11119: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11120: if ($counter) {
1.987 raeburn 11121: $output .= &embedded_file_element('pathchange',$chgcount,
11122: $embed_file,\%mapping,
1.1071 raeburn 11123: $allfiles,$codebase,'change');
1.987 raeburn 11124: } else {
11125: $pathchange_output .=
11126: &start_data_table_row().
11127: '<td><input type ="checkbox" name="namechange" value="'.
11128: $chgcount.'" checked="checked" /></td>'.
11129: '<td>'.$mapping{$embed_file}.'</td>'.
11130: '<td>'.$embed_file.
11131: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11132: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11133: '</td>'.&end_data_table_row();
1.660 raeburn 11134: }
1.987 raeburn 11135: $numpathchg ++;
11136: $chgcount ++;
1.660 raeburn 11137: }
11138: }
1.1075.2.35 raeburn 11139: if (($counter) || ($numunused)) {
1.987 raeburn 11140: if ($numpathchg) {
11141: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11142: $numpathchg.'" />'."\n";
11143: }
11144: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11145: ($actionurl eq '/adm/imsimport')) {
11146: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11147: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11148: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11149: } elsif ($actionurl eq '/adm/dependencies') {
11150: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11151: }
1.1075.2.35 raeburn 11152: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11153: } elsif ($numpathchg) {
11154: my %pathchange = ();
11155: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11156: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11157: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11158: }
1.987 raeburn 11159: }
1.1071 raeburn 11160: return ($output,$counter,$numpathchg);
1.987 raeburn 11161: }
11162:
1.1075.2.47 raeburn 11163: =pod
11164:
11165: =item * clean_path($name)
11166:
11167: Performs clean-up of directories, subdirectories and filename in an
11168: embedded object, referenced in an HTML file which is being uploaded
11169: to a course or portfolio, where
11170: "Upload embedded images/multimedia files if HTML file" checkbox was
11171: checked.
11172:
11173: Clean-up is similar to replacements in lonnet::clean_filename()
11174: except each / between sub-directory and next level is preserved.
11175:
11176: =cut
11177:
11178: sub clean_path {
11179: my ($embed_file) = @_;
11180: $embed_file =~s{^/+}{};
11181: my @contents;
11182: if ($embed_file =~ m{/}) {
11183: @contents = split(/\//,$embed_file);
11184: } else {
11185: @contents = ($embed_file);
11186: }
11187: my $lastidx = scalar(@contents)-1;
11188: for (my $i=0; $i<=$lastidx; $i++) {
11189: $contents[$i]=~s{\\}{/}g;
11190: $contents[$i]=~s/\s+/\_/g;
11191: $contents[$i]=~s{[^/\w\.\-]}{}g;
11192: if ($i == $lastidx) {
11193: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11194: }
11195: }
11196: if ($lastidx > 0) {
11197: return join('/',@contents);
11198: } else {
11199: return $contents[0];
11200: }
11201: }
11202:
1.987 raeburn 11203: sub embedded_file_element {
1.1071 raeburn 11204: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11205: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11206: (ref($codebase) eq 'HASH'));
11207: my $output;
1.1071 raeburn 11208: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11209: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11210: }
11211: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11212: &escape($embed_file).'" />';
11213: unless (($context eq 'upload_embedded') &&
11214: ($mapping->{$embed_file} eq $embed_file)) {
11215: $output .='
11216: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11217: }
11218: my $attrib;
11219: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11220: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11221: }
11222: $output .=
11223: "\n\t\t".
11224: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11225: $attrib.'" />';
11226: if (exists($codebase->{$mapping->{$embed_file}})) {
11227: $output .=
11228: "\n\t\t".
11229: '<input name="codebase_'.$num.'" type="hidden" value="'.
11230: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11231: }
1.987 raeburn 11232: return $output;
1.660 raeburn 11233: }
11234:
1.1071 raeburn 11235: sub get_dependency_details {
11236: my ($currfile,$currsubfile,$embed_file) = @_;
11237: my ($size,$mtime,$showsize,$showmtime);
11238: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11239: if ($embed_file =~ m{/}) {
11240: my ($path,$fname) = split(/\//,$embed_file);
11241: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11242: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11243: }
11244: } else {
11245: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11246: ($size,$mtime) = @{$currfile->{$embed_file}};
11247: }
11248: }
11249: $showsize = $size/1024.0;
11250: $showsize = sprintf("%.1f",$showsize);
11251: if ($mtime > 0) {
11252: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11253: }
11254: }
11255: return ($showsize,$showmtime);
11256: }
11257:
11258: sub ask_embedded_js {
11259: return <<"END";
11260: <script type="text/javascript"">
11261: // <![CDATA[
11262: function toggleBrowse(counter) {
11263: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11264: var fileid = document.getElementById('embedded_item_'+counter);
11265: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11266: if (chkboxid.checked == true) {
11267: uploaddivid.style.display='block';
11268: } else {
11269: uploaddivid.style.display='none';
11270: fileid.value = '';
11271: }
11272: }
11273: // ]]>
11274: </script>
11275:
11276: END
11277: }
11278:
1.661 raeburn 11279: sub upload_embedded {
11280: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11281: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11282: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11283: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11284: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11285: my $orig_uploaded_filename =
11286: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11287: foreach my $type ('orig','ref','attrib','codebase') {
11288: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11289: $env{'form.embedded_'.$type.'_'.$i} =
11290: &unescape($env{'form.embedded_'.$type.'_'.$i});
11291: }
11292: }
1.661 raeburn 11293: my ($path,$fname) =
11294: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11295: # no path, whole string is fname
11296: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11297: $fname = &Apache::lonnet::clean_filename($fname);
11298: # See if there is anything left
11299: next if ($fname eq '');
11300:
11301: # Check if file already exists as a file or directory.
11302: my ($state,$msg);
11303: if ($context eq 'portfolio') {
11304: my $port_path = $dirpath;
11305: if ($group ne '') {
11306: $port_path = "groups/$group/$port_path";
11307: }
1.987 raeburn 11308: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11309: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11310: $dir_root,$port_path,$disk_quota,
11311: $current_disk_usage,$uname,$udom);
11312: if ($state eq 'will_exceed_quota'
1.984 raeburn 11313: || $state eq 'file_locked') {
1.661 raeburn 11314: $output .= $msg;
11315: next;
11316: }
11317: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11318: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11319: if ($state eq 'exists') {
11320: $output .= $msg;
11321: next;
11322: }
11323: }
11324: # Check if extension is valid
11325: if (($fname =~ /\.(\w+)$/) &&
11326: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11327: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11328: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11329: next;
11330: } elsif (($fname =~ /\.(\w+)$/) &&
11331: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11332: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11333: next;
11334: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11335: $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 11336: next;
11337: }
11338: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11339: my $subdir = $path;
11340: $subdir =~ s{/+$}{};
1.661 raeburn 11341: if ($context eq 'portfolio') {
1.984 raeburn 11342: my $result;
11343: if ($state eq 'existingfile') {
11344: $result=
11345: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11346: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11347: } else {
1.984 raeburn 11348: $result=
11349: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11350: $dirpath.
1.1075.2.35 raeburn 11351: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11352: if ($result !~ m|^/uploaded/|) {
11353: $output .= '<span class="LC_error">'
11354: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11355: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11356: .'</span><br />';
11357: next;
11358: } else {
1.987 raeburn 11359: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11360: $path.$fname.'</span>').'<br />';
1.984 raeburn 11361: }
1.661 raeburn 11362: }
1.1075.2.35 raeburn 11363: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11364: my $extendedsubdir = $dirpath.'/'.$subdir;
11365: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11366: my $result =
1.1075.2.35 raeburn 11367: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11368: if ($result !~ m|^/uploaded/|) {
11369: $output .= '<span class="LC_error">'
11370: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11371: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11372: .'</span><br />';
11373: next;
11374: } else {
11375: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11376: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11377: if ($context eq 'syllabus') {
11378: &Apache::lonnet::make_public_indefinitely($result);
11379: }
1.987 raeburn 11380: }
1.661 raeburn 11381: } else {
11382: # Save the file
11383: my $target = $env{'form.embedded_item_'.$i};
11384: my $fullpath = $dir_root.$dirpath.'/'.$path;
11385: my $dest = $fullpath.$fname;
11386: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11387: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11388: my $count;
11389: my $filepath = $dir_root;
1.1027 raeburn 11390: foreach my $subdir (@parts) {
11391: $filepath .= "/$subdir";
11392: if (!-e $filepath) {
1.661 raeburn 11393: mkdir($filepath,0770);
11394: }
11395: }
11396: my $fh;
11397: if (!open($fh,'>'.$dest)) {
11398: &Apache::lonnet::logthis('Failed to create '.$dest);
11399: $output .= '<span class="LC_error">'.
1.1071 raeburn 11400: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11401: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11402: '</span><br />';
11403: } else {
11404: if (!print $fh $env{'form.embedded_item_'.$i}) {
11405: &Apache::lonnet::logthis('Failed to write to '.$dest);
11406: $output .= '<span class="LC_error">'.
1.1071 raeburn 11407: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11408: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11409: '</span><br />';
11410: } else {
1.987 raeburn 11411: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11412: $url.'</span>').'<br />';
11413: unless ($context eq 'testbank') {
11414: $footer .= &mt('View embedded file: [_1]',
11415: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11416: }
11417: }
11418: close($fh);
11419: }
11420: }
11421: if ($env{'form.embedded_ref_'.$i}) {
11422: $pathchange{$i} = 1;
11423: }
11424: }
11425: if ($output) {
11426: $output = '<p>'.$output.'</p>';
11427: }
11428: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11429: $returnflag = 'ok';
1.1071 raeburn 11430: my $numpathchgs = scalar(keys(%pathchange));
11431: if ($numpathchgs > 0) {
1.987 raeburn 11432: if ($context eq 'portfolio') {
11433: $output .= '<p>'.&mt('or').'</p>';
11434: } elsif ($context eq 'testbank') {
1.1071 raeburn 11435: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11436: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11437: $returnflag = 'modify_orightml';
11438: }
11439: }
1.1071 raeburn 11440: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11441: }
11442:
11443: sub modify_html_form {
11444: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11445: my $end = 0;
11446: my $modifyform;
11447: if ($context eq 'upload_embedded') {
11448: return unless (ref($pathchange) eq 'HASH');
11449: if ($env{'form.number_embedded_items'}) {
11450: $end += $env{'form.number_embedded_items'};
11451: }
11452: if ($env{'form.number_pathchange_items'}) {
11453: $end += $env{'form.number_pathchange_items'};
11454: }
11455: if ($end) {
11456: for (my $i=0; $i<$end; $i++) {
11457: if ($i < $env{'form.number_embedded_items'}) {
11458: next unless($pathchange->{$i});
11459: }
11460: $modifyform .=
11461: &start_data_table_row().
11462: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11463: 'checked="checked" /></td>'.
11464: '<td>'.$env{'form.embedded_ref_'.$i}.
11465: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11466: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11467: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11468: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11469: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11470: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11471: '<td>'.$env{'form.embedded_orig_'.$i}.
11472: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11473: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11474: &end_data_table_row();
1.1071 raeburn 11475: }
1.987 raeburn 11476: }
11477: } else {
11478: $modifyform = $pathchgtable;
11479: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11480: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11481: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11482: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11483: }
11484: }
11485: if ($modifyform) {
1.1071 raeburn 11486: if ($actionurl eq '/adm/dependencies') {
11487: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11488: }
1.987 raeburn 11489: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11490: '<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".
11491: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11492: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11493: '</ol></p>'."\n".'<p>'.
11494: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11495: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11496: &start_data_table()."\n".
11497: &start_data_table_header_row().
11498: '<th>'.&mt('Change?').'</th>'.
11499: '<th>'.&mt('Current reference').'</th>'.
11500: '<th>'.&mt('Required reference').'</th>'.
11501: &end_data_table_header_row()."\n".
11502: $modifyform.
11503: &end_data_table().'<br />'."\n".$hiddenstate.
11504: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11505: '</form>'."\n";
11506: }
11507: return;
11508: }
11509:
11510: sub modify_html_refs {
1.1075.2.35 raeburn 11511: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11512: my $container;
11513: if ($context eq 'portfolio') {
11514: $container = $env{'form.container'};
11515: } elsif ($context eq 'coursedoc') {
11516: $container = $env{'form.primaryurl'};
1.1071 raeburn 11517: } elsif ($context eq 'manage_dependencies') {
11518: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11519: $container = "/$container";
1.1075.2.35 raeburn 11520: } elsif ($context eq 'syllabus') {
11521: $container = $url;
1.987 raeburn 11522: } else {
1.1027 raeburn 11523: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11524: }
11525: my (%allfiles,%codebase,$output,$content);
11526: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11527: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11528: if (wantarray) {
11529: return ('',0,0);
11530: } else {
11531: return;
11532: }
11533: }
11534: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11535: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11536: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11537: if (wantarray) {
11538: return ('',0,0);
11539: } else {
11540: return;
11541: }
11542: }
1.987 raeburn 11543: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11544: if ($content eq '-1') {
11545: if (wantarray) {
11546: return ('',0,0);
11547: } else {
11548: return;
11549: }
11550: }
1.987 raeburn 11551: } else {
1.1071 raeburn 11552: unless ($container =~ /^\Q$dir_root\E/) {
11553: if (wantarray) {
11554: return ('',0,0);
11555: } else {
11556: return;
11557: }
11558: }
1.1075.2.128 raeburn 11559: if (open(my $fh,'<',$container)) {
1.987 raeburn 11560: $content = join('', <$fh>);
11561: close($fh);
11562: } else {
1.1071 raeburn 11563: if (wantarray) {
11564: return ('',0,0);
11565: } else {
11566: return;
11567: }
1.987 raeburn 11568: }
11569: }
11570: my ($count,$codebasecount) = (0,0);
11571: my $mm = new File::MMagic;
11572: my $mime_type = $mm->checktype_contents($content);
11573: if ($mime_type eq 'text/html') {
11574: my $parse_result =
11575: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11576: \%codebase,\$content);
11577: if ($parse_result eq 'ok') {
11578: foreach my $i (@changes) {
11579: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11580: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11581: if ($allfiles{$ref}) {
11582: my $newname = $orig;
11583: my ($attrib_regexp,$codebase);
1.1006 raeburn 11584: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11585: if ($attrib_regexp =~ /:/) {
11586: $attrib_regexp =~ s/\:/|/g;
11587: }
11588: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11589: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11590: $count += $numchg;
1.1075.2.35 raeburn 11591: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11592: delete($allfiles{$ref});
1.987 raeburn 11593: }
11594: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11595: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11596: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11597: $codebasecount ++;
11598: }
11599: }
11600: }
1.1075.2.35 raeburn 11601: my $skiprewrites;
1.987 raeburn 11602: if ($count || $codebasecount) {
11603: my $saveresult;
1.1071 raeburn 11604: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11605: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11606: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11607: if ($url eq $container) {
11608: my ($fname) = ($container =~ m{/([^/]+)$});
11609: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11610: $count,'<span class="LC_filename">'.
1.1071 raeburn 11611: $fname.'</span>').'</p>';
1.987 raeburn 11612: } else {
11613: $output = '<p class="LC_error">'.
11614: &mt('Error: update failed for: [_1].',
11615: '<span class="LC_filename">'.
11616: $container.'</span>').'</p>';
11617: }
1.1075.2.35 raeburn 11618: if ($context eq 'syllabus') {
11619: unless ($saveresult eq 'ok') {
11620: $skiprewrites = 1;
11621: }
11622: }
1.987 raeburn 11623: } else {
1.1075.2.128 raeburn 11624: if (open(my $fh,'>',$container)) {
1.987 raeburn 11625: print $fh $content;
11626: close($fh);
11627: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11628: $count,'<span class="LC_filename">'.
11629: $container.'</span>').'</p>';
1.661 raeburn 11630: } else {
1.987 raeburn 11631: $output = '<p class="LC_error">'.
11632: &mt('Error: could not update [_1].',
11633: '<span class="LC_filename">'.
11634: $container.'</span>').'</p>';
1.661 raeburn 11635: }
11636: }
11637: }
1.1075.2.35 raeburn 11638: if (($context eq 'syllabus') && (!$skiprewrites)) {
11639: my ($actionurl,$state);
11640: $actionurl = "/public/$udom/$uname/syllabus";
11641: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11642: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11643: \%codebase,
11644: {'context' => 'rewrites',
11645: 'ignore_remote_references' => 1,});
11646: if (ref($mapping) eq 'HASH') {
11647: my $rewrites = 0;
11648: foreach my $key (keys(%{$mapping})) {
11649: next if ($key =~ m{^https?://});
11650: my $ref = $mapping->{$key};
11651: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11652: my $attrib;
11653: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11654: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11655: }
11656: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11657: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11658: $rewrites += $numchg;
11659: }
11660: }
11661: if ($rewrites) {
11662: my $saveresult;
11663: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11664: if ($url eq $container) {
11665: my ($fname) = ($container =~ m{/([^/]+)$});
11666: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11667: $count,'<span class="LC_filename">'.
11668: $fname.'</span>').'</p>';
11669: } else {
11670: $output .= '<p class="LC_error">'.
11671: &mt('Error: could not update links in [_1].',
11672: '<span class="LC_filename">'.
11673: $container.'</span>').'</p>';
11674:
11675: }
11676: }
11677: }
11678: }
1.987 raeburn 11679: } else {
11680: &logthis('Failed to parse '.$container.
11681: ' to modify references: '.$parse_result);
1.661 raeburn 11682: }
11683: }
1.1071 raeburn 11684: if (wantarray) {
11685: return ($output,$count,$codebasecount);
11686: } else {
11687: return $output;
11688: }
1.661 raeburn 11689: }
11690:
11691: sub check_for_existing {
11692: my ($path,$fname,$element) = @_;
11693: my ($state,$msg);
11694: if (-d $path.'/'.$fname) {
11695: $state = 'exists';
11696: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11697: } elsif (-e $path.'/'.$fname) {
11698: $state = 'exists';
11699: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11700: }
11701: if ($state eq 'exists') {
11702: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11703: }
11704: return ($state,$msg);
11705: }
11706:
11707: sub check_for_upload {
11708: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11709: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11710: my $filesize = length($env{'form.'.$element});
11711: if (!$filesize) {
11712: my $msg = '<span class="LC_error">'.
11713: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11714: '<span class="LC_filename">'.$fname.'</span>',
11715: $filesize).'<br />'.
1.1007 raeburn 11716: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11717: '</span>';
11718: return ('zero_bytes',$msg);
11719: }
11720: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11721: my $getpropath = 1;
1.1021 raeburn 11722: my ($dirlistref,$listerror) =
11723: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11724: my $found_file = 0;
11725: my $locked_file = 0;
1.991 raeburn 11726: my @lockers;
11727: my $navmap;
11728: if ($env{'request.course.id'}) {
11729: $navmap = Apache::lonnavmaps::navmap->new();
11730: }
1.1021 raeburn 11731: if (ref($dirlistref) eq 'ARRAY') {
11732: foreach my $line (@{$dirlistref}) {
11733: my ($file_name,$rest)=split(/\&/,$line,2);
11734: if ($file_name eq $fname){
11735: $file_name = $path.$file_name;
11736: if ($group ne '') {
11737: $file_name = $group.$file_name;
11738: }
11739: $found_file = 1;
11740: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11741: foreach my $lock (@lockers) {
11742: if (ref($lock) eq 'ARRAY') {
11743: my ($symb,$crsid) = @{$lock};
11744: if ($crsid eq $env{'request.course.id'}) {
11745: if (ref($navmap)) {
11746: my $res = $navmap->getBySymb($symb);
11747: foreach my $part (@{$res->parts()}) {
11748: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11749: unless (($slot_status == $res->RESERVED) ||
11750: ($slot_status == $res->RESERVED_LOCATION)) {
11751: $locked_file = 1;
11752: }
1.991 raeburn 11753: }
1.1021 raeburn 11754: } else {
11755: $locked_file = 1;
1.991 raeburn 11756: }
11757: } else {
11758: $locked_file = 1;
11759: }
11760: }
1.1021 raeburn 11761: }
11762: } else {
11763: my @info = split(/\&/,$rest);
11764: my $currsize = $info[6]/1000;
11765: if ($currsize < $filesize) {
11766: my $extra = $filesize - $currsize;
11767: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11768: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11769: &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 11770: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11771: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11772: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11773: return ('will_exceed_quota',$msg);
11774: }
1.984 raeburn 11775: }
11776: }
1.661 raeburn 11777: }
11778: }
11779: }
11780: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11781: my $msg = '<p class="LC_warning">'.
11782: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11783: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11784: return ('will_exceed_quota',$msg);
11785: } elsif ($found_file) {
11786: if ($locked_file) {
1.1075.2.69 raeburn 11787: my $msg = '<p class="LC_warning">';
1.661 raeburn 11788: $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 11789: $msg .= '</p>';
1.661 raeburn 11790: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11791: return ('file_locked',$msg);
11792: } else {
1.1075.2.69 raeburn 11793: my $msg = '<p class="LC_error">';
1.984 raeburn 11794: $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 11795: $msg .= '</p>';
1.984 raeburn 11796: return ('existingfile',$msg);
1.661 raeburn 11797: }
11798: }
11799: }
11800:
1.987 raeburn 11801: sub check_for_traversal {
11802: my ($path,$url,$toplevel) = @_;
11803: my @parts=split(/\//,$path);
11804: my $cleanpath;
11805: my $fullpath = $url;
11806: for (my $i=0;$i<@parts;$i++) {
11807: next if ($parts[$i] eq '.');
11808: if ($parts[$i] eq '..') {
11809: $fullpath =~ s{([^/]+/)$}{};
11810: } else {
11811: $fullpath .= $parts[$i].'/';
11812: }
11813: }
11814: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11815: $cleanpath = $1;
11816: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11817: my $curr_toprel = $1;
11818: my @parts = split(/\//,$curr_toprel);
11819: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11820: my @urlparts = split(/\//,$url_toprel);
11821: my $doubledots;
11822: my $startdiff = -1;
11823: for (my $i=0; $i<@urlparts; $i++) {
11824: if ($startdiff == -1) {
11825: unless ($urlparts[$i] eq $parts[$i]) {
11826: $startdiff = $i;
11827: $doubledots .= '../';
11828: }
11829: } else {
11830: $doubledots .= '../';
11831: }
11832: }
11833: if ($startdiff > -1) {
11834: $cleanpath = $doubledots;
11835: for (my $i=$startdiff; $i<@parts; $i++) {
11836: $cleanpath .= $parts[$i].'/';
11837: }
11838: }
11839: }
11840: $cleanpath =~ s{(/)$}{};
11841: return $cleanpath;
11842: }
1.31 albertel 11843:
1.1053 raeburn 11844: sub is_archive_file {
11845: my ($mimetype) = @_;
11846: if (($mimetype eq 'application/octet-stream') ||
11847: ($mimetype eq 'application/x-stuffit') ||
11848: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11849: return 1;
11850: }
11851: return;
11852: }
11853:
11854: sub decompress_form {
1.1065 raeburn 11855: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11856: my %lt = &Apache::lonlocal::texthash (
11857: this => 'This file is an archive file.',
1.1067 raeburn 11858: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11859: itsc => 'Its contents are as follows:',
1.1053 raeburn 11860: youm => 'You may wish to extract its contents.',
11861: extr => 'Extract contents',
1.1067 raeburn 11862: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11863: proa => 'Process automatically?',
1.1053 raeburn 11864: yes => 'Yes',
11865: no => 'No',
1.1067 raeburn 11866: fold => 'Title for folder containing movie',
11867: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11868: );
1.1065 raeburn 11869: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11870: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11871: my $info = &list_archive_contents($fileloc,\@paths);
11872: if (@paths) {
11873: foreach my $path (@paths) {
11874: $path =~ s{^/}{};
1.1067 raeburn 11875: if ($path =~ m{^([^/]+)/$}) {
11876: $topdir = $1;
11877: }
1.1065 raeburn 11878: if ($path =~ m{^([^/]+)/}) {
11879: $toplevel{$1} = $path;
11880: } else {
11881: $toplevel{$path} = $path;
11882: }
11883: }
11884: }
1.1067 raeburn 11885: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11886: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11887: "$topdir/media/",
11888: "$topdir/media/$topdir.mp4",
11889: "$topdir/media/FirstFrame.png",
11890: "$topdir/media/player.swf",
11891: "$topdir/media/swfobject.js",
11892: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 11893: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 11894: "$topdir/$topdir.mp4",
11895: "$topdir/$topdir\_config.xml",
11896: "$topdir/$topdir\_controller.swf",
11897: "$topdir/$topdir\_embed.css",
11898: "$topdir/$topdir\_First_Frame.png",
11899: "$topdir/$topdir\_player.html",
11900: "$topdir/$topdir\_Thumbnails.png",
11901: "$topdir/playerProductInstall.swf",
11902: "$topdir/scripts/",
11903: "$topdir/scripts/config_xml.js",
11904: "$topdir/scripts/handlebars.js",
11905: "$topdir/scripts/jquery-1.7.1.min.js",
11906: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11907: "$topdir/scripts/modernizr.js",
11908: "$topdir/scripts/player-min.js",
11909: "$topdir/scripts/swfobject.js",
11910: "$topdir/skins/",
11911: "$topdir/skins/configuration_express.xml",
11912: "$topdir/skins/express_show/",
11913: "$topdir/skins/express_show/player-min.css",
11914: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 11915: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11916: "$topdir/$topdir.mp4",
11917: "$topdir/$topdir\_config.xml",
11918: "$topdir/$topdir\_controller.swf",
11919: "$topdir/$topdir\_embed.css",
11920: "$topdir/$topdir\_First_Frame.png",
11921: "$topdir/$topdir\_player.html",
11922: "$topdir/$topdir\_Thumbnails.png",
11923: "$topdir/playerProductInstall.swf",
11924: "$topdir/scripts/",
11925: "$topdir/scripts/config_xml.js",
11926: "$topdir/scripts/techsmith-smart-player.min.js",
11927: "$topdir/skins/",
11928: "$topdir/skins/configuration_express.xml",
11929: "$topdir/skins/express_show/",
11930: "$topdir/skins/express_show/spritesheet.min.css",
11931: "$topdir/skins/express_show/spritesheet.png",
11932: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 11933: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11934: if (@diffs == 0) {
1.1075.2.59 raeburn 11935: $is_camtasia = 6;
11936: } else {
1.1075.2.81 raeburn 11937: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 11938: if (@diffs == 0) {
11939: $is_camtasia = 8;
1.1075.2.81 raeburn 11940: } else {
11941: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11942: if (@diffs == 0) {
11943: $is_camtasia = 8;
11944: }
1.1075.2.59 raeburn 11945: }
1.1067 raeburn 11946: }
11947: }
11948: my $output;
11949: if ($is_camtasia) {
11950: $output = <<"ENDCAM";
11951: <script type="text/javascript" language="Javascript">
11952: // <![CDATA[
11953:
11954: function camtasiaToggle() {
11955: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11956: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11957: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11958: document.getElementById('camtasia_titles').style.display='block';
11959: } else {
11960: document.getElementById('camtasia_titles').style.display='none';
11961: }
11962: }
11963: }
11964: return;
11965: }
11966:
11967: // ]]>
11968: </script>
11969: <p>$lt{'camt'}</p>
11970: ENDCAM
1.1065 raeburn 11971: } else {
1.1067 raeburn 11972: $output = '<p>'.$lt{'this'};
11973: if ($info eq '') {
11974: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11975: } else {
11976: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11977: '<div><pre>'.$info.'</pre></div>';
11978: }
1.1065 raeburn 11979: }
1.1067 raeburn 11980: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11981: my $duplicates;
11982: my $num = 0;
11983: if (ref($dirlist) eq 'ARRAY') {
11984: foreach my $item (@{$dirlist}) {
11985: if (ref($item) eq 'ARRAY') {
11986: if (exists($toplevel{$item->[0]})) {
11987: $duplicates .=
11988: &start_data_table_row().
11989: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11990: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11991: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11992: 'value="1" />'.&mt('Yes').'</label>'.
11993: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11994: '<td>'.$item->[0].'</td>';
11995: if ($item->[2]) {
11996: $duplicates .= '<td>'.&mt('Directory').'</td>';
11997: } else {
11998: $duplicates .= '<td>'.&mt('File').'</td>';
11999: }
12000: $duplicates .= '<td>'.$item->[3].'</td>'.
12001: '<td>'.
12002: &Apache::lonlocal::locallocaltime($item->[4]).
12003: '</td>'.
12004: &end_data_table_row();
12005: $num ++;
12006: }
12007: }
12008: }
12009: }
12010: my $itemcount;
12011: if (@paths > 0) {
12012: $itemcount = scalar(@paths);
12013: } else {
12014: $itemcount = 1;
12015: }
1.1067 raeburn 12016: if ($is_camtasia) {
12017: $output .= $lt{'auto'}.'<br />'.
12018: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 12019: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12020: $lt{'yes'}.'</label> <label>'.
12021: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12022: $lt{'no'}.'</label></span><br />'.
12023: '<div id="camtasia_titles" style="display:block">'.
12024: &Apache::lonhtmlcommon::start_pick_box().
12025: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12026: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12027: &Apache::lonhtmlcommon::row_closure().
12028: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12029: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12030: &Apache::lonhtmlcommon::row_closure(1).
12031: &Apache::lonhtmlcommon::end_pick_box().
12032: '</div>';
12033: }
1.1065 raeburn 12034: $output .=
12035: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12036: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12037: "\n";
1.1065 raeburn 12038: if ($duplicates ne '') {
12039: $output .= '<p><span class="LC_warning">'.
12040: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12041: &start_data_table().
12042: &start_data_table_header_row().
12043: '<th>'.&mt('Overwrite?').'</th>'.
12044: '<th>'.&mt('Name').'</th>'.
12045: '<th>'.&mt('Type').'</th>'.
12046: '<th>'.&mt('Size').'</th>'.
12047: '<th>'.&mt('Last modified').'</th>'.
12048: &end_data_table_header_row().
12049: $duplicates.
12050: &end_data_table().
12051: '</p>';
12052: }
1.1067 raeburn 12053: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12054: if (ref($hiddenelements) eq 'HASH') {
12055: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12056: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12057: }
12058: }
12059: $output .= <<"END";
1.1067 raeburn 12060: <br />
1.1053 raeburn 12061: <input type="submit" name="decompress" value="$lt{'extr'}" />
12062: </form>
12063: $noextract
12064: END
12065: return $output;
12066: }
12067:
1.1065 raeburn 12068: sub decompression_utility {
12069: my ($program) = @_;
12070: my @utilities = ('tar','gunzip','bunzip2','unzip');
12071: my $location;
12072: if (grep(/^\Q$program\E$/,@utilities)) {
12073: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12074: '/usr/sbin/') {
12075: if (-x $dir.$program) {
12076: $location = $dir.$program;
12077: last;
12078: }
12079: }
12080: }
12081: return $location;
12082: }
12083:
12084: sub list_archive_contents {
12085: my ($file,$pathsref) = @_;
12086: my (@cmd,$output);
12087: my $needsregexp;
12088: if ($file =~ /\.zip$/) {
12089: @cmd = (&decompression_utility('unzip'),"-l");
12090: $needsregexp = 1;
12091: } elsif (($file =~ m/\.tar\.gz$/) ||
12092: ($file =~ /\.tgz$/)) {
12093: @cmd = (&decompression_utility('tar'),"-ztf");
12094: } elsif ($file =~ /\.tar\.bz2$/) {
12095: @cmd = (&decompression_utility('tar'),"-jtf");
12096: } elsif ($file =~ m|\.tar$|) {
12097: @cmd = (&decompression_utility('tar'),"-tf");
12098: }
12099: if (@cmd) {
12100: undef($!);
12101: undef($@);
12102: if (open(my $fh,"-|", @cmd, $file)) {
12103: while (my $line = <$fh>) {
12104: $output .= $line;
12105: chomp($line);
12106: my $item;
12107: if ($needsregexp) {
12108: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12109: } else {
12110: $item = $line;
12111: }
12112: if ($item ne '') {
12113: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12114: push(@{$pathsref},$item);
12115: }
12116: }
12117: }
12118: close($fh);
12119: }
12120: }
12121: return $output;
12122: }
12123:
1.1053 raeburn 12124: sub decompress_uploaded_file {
12125: my ($file,$dir) = @_;
12126: &Apache::lonnet::appenv({'cgi.file' => $file});
12127: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12128: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12129: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12130: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12131: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12132: my $decompressed = $env{'cgi.decompressed'};
12133: &Apache::lonnet::delenv('cgi.file');
12134: &Apache::lonnet::delenv('cgi.dir');
12135: &Apache::lonnet::delenv('cgi.decompressed');
12136: return ($decompressed,$result);
12137: }
12138:
1.1055 raeburn 12139: sub process_decompression {
12140: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 12141: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12142: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12143: &mt('Unexpected file path.').'</p>'."\n";
12144: }
12145: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12146: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12147: &mt('Unexpected course context.').'</p>'."\n";
12148: }
12149: unless ($file eq &Apache::lonnet::clean_filename($file)) {
12150: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12151: &mt('Filename contained unexpected characters.').'</p>'."\n";
12152: }
1.1055 raeburn 12153: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12154: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12155: $error = &mt('Filename not a supported archive file type.').
12156: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12157: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12158: } else {
12159: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12160: if ($docuhome eq 'no_host') {
12161: $error = &mt('Could not determine home server for course.');
12162: } else {
12163: my @ids=&Apache::lonnet::current_machine_ids();
12164: my $currdir = "$dir_root/$destination";
12165: if (grep(/^\Q$docuhome\E$/,@ids)) {
12166: $dir = &LONCAPA::propath($docudom,$docuname).
12167: "$dir_root/$destination";
12168: } else {
12169: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12170: "$dir_root/$docudom/$docuname/$destination";
12171: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12172: $error = &mt('Archive file not found.');
12173: }
12174: }
1.1065 raeburn 12175: my (@to_overwrite,@to_skip);
12176: if ($env{'form.archive_overwrite_total'} > 0) {
12177: my $total = $env{'form.archive_overwrite_total'};
12178: for (my $i=0; $i<$total; $i++) {
12179: if ($env{'form.archive_overwrite_'.$i} == 1) {
12180: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12181: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12182: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12183: }
12184: }
12185: }
12186: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 12187: my $numoverwrite = scalar(@to_overwrite);
12188: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12189: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12190: } elsif ($dir eq '') {
1.1055 raeburn 12191: $error = &mt('Directory containing archive file unavailable.');
12192: } elsif (!$error) {
1.1065 raeburn 12193: my ($decompressed,$display);
1.1075.2.128 raeburn 12194: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12195: my $tempdir = time.'_'.$$.int(rand(10000));
12196: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 12197: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12198: ($decompressed,$display) =
12199: &decompress_uploaded_file($file,"$dir/$tempdir");
12200: foreach my $item (@to_skip) {
12201: if (($item ne '') && ($item !~ /\.\./)) {
12202: if (-f "$dir/$tempdir/$item") {
12203: unlink("$dir/$tempdir/$item");
12204: } elsif (-d "$dir/$tempdir/$item") {
12205: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
12206: }
12207: }
12208: }
12209: foreach my $item (@to_overwrite) {
12210: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12211: if (($item ne '') && ($item !~ /\.\./)) {
12212: if (-f "$dir/$item") {
12213: unlink("$dir/$item");
12214: } elsif (-d "$dir/$item") {
12215: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
12216: }
12217: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12218: }
1.1065 raeburn 12219: }
12220: }
1.1075.2.128 raeburn 12221: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
12222: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
12223: }
1.1065 raeburn 12224: }
12225: } else {
12226: ($decompressed,$display) =
12227: &decompress_uploaded_file($file,$dir);
12228: }
1.1055 raeburn 12229: if ($decompressed eq 'ok') {
1.1065 raeburn 12230: $output = '<p class="LC_info">'.
12231: &mt('Files extracted successfully from archive.').
12232: '</p>'."\n";
1.1055 raeburn 12233: my ($warning,$result,@contents);
12234: my ($newdirlistref,$newlisterror) =
12235: &Apache::lonnet::dirlist($currdir,$docudom,
12236: $docuname,1);
12237: my (%is_dir,%changes,@newitems);
12238: my $dirptr = 16384;
1.1065 raeburn 12239: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12240: foreach my $dir_line (@{$newdirlistref}) {
12241: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 12242: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12243: push(@newitems,$item);
12244: if ($dirptr&$testdir) {
12245: $is_dir{$item} = 1;
12246: }
12247: $changes{$item} = 1;
12248: }
12249: }
12250: }
12251: if (keys(%changes) > 0) {
12252: foreach my $item (sort(@newitems)) {
12253: if ($changes{$item}) {
12254: push(@contents,$item);
12255: }
12256: }
12257: }
12258: if (@contents > 0) {
1.1067 raeburn 12259: my $wantform;
12260: unless ($env{'form.autoextract_camtasia'}) {
12261: $wantform = 1;
12262: }
1.1056 raeburn 12263: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12264: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12265: $currdir,\%is_dir,
12266: \%children,\%parent,
1.1056 raeburn 12267: \@contents,\%dirorder,
12268: \%titles,$wantform);
1.1055 raeburn 12269: if ($datatable ne '') {
12270: $output .= &archive_options_form('decompressed',$datatable,
12271: $count,$hiddenelem);
1.1065 raeburn 12272: my $startcount = 6;
1.1055 raeburn 12273: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12274: \%titles,\%children);
1.1055 raeburn 12275: }
1.1067 raeburn 12276: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12277: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12278: my %displayed;
12279: my $total = 1;
12280: $env{'form.archive_directory'} = [];
12281: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12282: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12283: $path =~ s{/$}{};
12284: my $item;
12285: if ($path ne '') {
12286: $item = "$path/$titles{$i}";
12287: } else {
12288: $item = $titles{$i};
12289: }
12290: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12291: if ($item eq $contents[0]) {
12292: push(@{$env{'form.archive_directory'}},$i);
12293: $env{'form.archive_'.$i} = 'display';
12294: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12295: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12296: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12297: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12298: $env{'form.archive_'.$i} = 'display';
12299: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12300: $displayed{'web'} = $i;
12301: } else {
1.1075.2.59 raeburn 12302: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12303: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12304: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12305: push(@{$env{'form.archive_directory'}},$i);
12306: }
12307: $env{'form.archive_'.$i} = 'dependency';
12308: }
12309: $total ++;
12310: }
12311: for (my $i=1; $i<$total; $i++) {
12312: next if ($i == $displayed{'web'});
12313: next if ($i == $displayed{'folder'});
12314: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12315: }
12316: $env{'form.phase'} = 'decompress_cleanup';
12317: $env{'form.archivedelete'} = 1;
12318: $env{'form.archive_count'} = $total-1;
12319: $output .=
12320: &process_extracted_files('coursedocs',$docudom,
12321: $docuname,$destination,
12322: $dir_root,$hiddenelem);
12323: }
1.1055 raeburn 12324: } else {
12325: $warning = &mt('No new items extracted from archive file.');
12326: }
12327: } else {
12328: $output = $display;
12329: $error = &mt('An error occurred during extraction from the archive file.');
12330: }
12331: }
12332: }
12333: }
12334: if ($error) {
12335: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12336: $error.'</p>'."\n";
12337: }
12338: if ($warning) {
12339: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12340: }
12341: return $output;
12342: }
12343:
12344: sub get_extracted {
1.1056 raeburn 12345: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12346: $titles,$wantform) = @_;
1.1055 raeburn 12347: my $count = 0;
12348: my $depth = 0;
12349: my $datatable;
1.1056 raeburn 12350: my @hierarchy;
1.1055 raeburn 12351: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12352: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12353: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12354: foreach my $item (@{$contents}) {
12355: $count ++;
1.1056 raeburn 12356: @{$dirorder->{$count}} = @hierarchy;
12357: $titles->{$count} = $item;
1.1055 raeburn 12358: &archive_hierarchy($depth,$count,$parent,$children);
12359: if ($wantform) {
12360: $datatable .= &archive_row($is_dir->{$item},$item,
12361: $currdir,$depth,$count);
12362: }
12363: if ($is_dir->{$item}) {
12364: $depth ++;
1.1056 raeburn 12365: push(@hierarchy,$count);
12366: $parent->{$depth} = $count;
1.1055 raeburn 12367: $datatable .=
12368: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12369: \$depth,\$count,\@hierarchy,$dirorder,
12370: $children,$parent,$titles,$wantform);
1.1055 raeburn 12371: $depth --;
1.1056 raeburn 12372: pop(@hierarchy);
1.1055 raeburn 12373: }
12374: }
12375: return ($count,$datatable);
12376: }
12377:
12378: sub recurse_extracted_archive {
1.1056 raeburn 12379: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12380: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12381: my $result='';
1.1056 raeburn 12382: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12383: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12384: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12385: return $result;
12386: }
12387: my $dirptr = 16384;
12388: my ($newdirlistref,$newlisterror) =
12389: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12390: if (ref($newdirlistref) eq 'ARRAY') {
12391: foreach my $dir_line (@{$newdirlistref}) {
12392: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12393: unless ($item =~ /^\.+$/) {
12394: $$count ++;
1.1056 raeburn 12395: @{$dirorder->{$$count}} = @{$hierarchy};
12396: $titles->{$$count} = $item;
1.1055 raeburn 12397: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12398:
1.1055 raeburn 12399: my $is_dir;
12400: if ($dirptr&$testdir) {
12401: $is_dir = 1;
12402: }
12403: if ($wantform) {
12404: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12405: }
12406: if ($is_dir) {
12407: $$depth ++;
1.1056 raeburn 12408: push(@{$hierarchy},$$count);
12409: $parent->{$$depth} = $$count;
1.1055 raeburn 12410: $result .=
12411: &recurse_extracted_archive("$currdir/$item",$docudom,
12412: $docuname,$depth,$count,
1.1056 raeburn 12413: $hierarchy,$dirorder,$children,
12414: $parent,$titles,$wantform);
1.1055 raeburn 12415: $$depth --;
1.1056 raeburn 12416: pop(@{$hierarchy});
1.1055 raeburn 12417: }
12418: }
12419: }
12420: }
12421: return $result;
12422: }
12423:
12424: sub archive_hierarchy {
12425: my ($depth,$count,$parent,$children) =@_;
12426: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12427: if (exists($parent->{$depth})) {
12428: $children->{$parent->{$depth}} .= $count.':';
12429: }
12430: }
12431: return;
12432: }
12433:
12434: sub archive_row {
12435: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12436: my ($name) = ($item =~ m{([^/]+)$});
12437: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12438: 'display' => 'Add as file',
1.1055 raeburn 12439: 'dependency' => 'Include as dependency',
12440: 'discard' => 'Discard',
12441: );
12442: if ($is_dir) {
1.1059 raeburn 12443: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12444: }
1.1056 raeburn 12445: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12446: my $offset = 0;
1.1055 raeburn 12447: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12448: $offset ++;
1.1065 raeburn 12449: if ($action ne 'display') {
12450: $offset ++;
12451: }
1.1055 raeburn 12452: $output .= '<td><span class="LC_nobreak">'.
12453: '<label><input type="radio" name="archive_'.$count.
12454: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12455: my $text = $choices{$action};
12456: if ($is_dir) {
12457: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12458: if ($action eq 'display') {
1.1059 raeburn 12459: $text = &mt('Add as folder');
1.1055 raeburn 12460: }
1.1056 raeburn 12461: } else {
12462: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12463:
12464: }
12465: $output .= ' /> '.$choices{$action}.'</label></span>';
12466: if ($action eq 'dependency') {
12467: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12468: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12469: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12470: '<option value=""></option>'."\n".
12471: '</select>'."\n".
12472: '</div>';
1.1059 raeburn 12473: } elsif ($action eq 'display') {
12474: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12475: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12476: '</div>';
1.1055 raeburn 12477: }
1.1056 raeburn 12478: $output .= '</td>';
1.1055 raeburn 12479: }
12480: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12481: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12482: for (my $i=0; $i<$depth; $i++) {
12483: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12484: }
12485: if ($is_dir) {
12486: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12487: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12488: } else {
12489: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12490: }
12491: $output .= ' '.$name.'</td>'."\n".
12492: &end_data_table_row();
12493: return $output;
12494: }
12495:
12496: sub archive_options_form {
1.1065 raeburn 12497: my ($form,$display,$count,$hiddenelem) = @_;
12498: my %lt = &Apache::lonlocal::texthash(
12499: perm => 'Permanently remove archive file?',
12500: hows => 'How should each extracted item be incorporated in the course?',
12501: cont => 'Content actions for all',
12502: addf => 'Add as folder/file',
12503: incd => 'Include as dependency for a displayed file',
12504: disc => 'Discard',
12505: no => 'No',
12506: yes => 'Yes',
12507: save => 'Save',
12508: );
12509: my $output = <<"END";
12510: <form name="$form" method="post" action="">
12511: <p><span class="LC_nobreak">$lt{'perm'}
12512: <label>
12513: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12514: </label>
12515:
12516: <label>
12517: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12518: </span>
12519: </p>
12520: <input type="hidden" name="phase" value="decompress_cleanup" />
12521: <br />$lt{'hows'}
12522: <div class="LC_columnSection">
12523: <fieldset>
12524: <legend>$lt{'cont'}</legend>
12525: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12526: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12527: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12528: </fieldset>
12529: </div>
12530: END
12531: return $output.
1.1055 raeburn 12532: &start_data_table()."\n".
1.1065 raeburn 12533: $display."\n".
1.1055 raeburn 12534: &end_data_table()."\n".
12535: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12536: $hiddenelem.
1.1065 raeburn 12537: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12538: '</form>';
12539: }
12540:
12541: sub archive_javascript {
1.1056 raeburn 12542: my ($startcount,$numitems,$titles,$children) = @_;
12543: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12544: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12545: my $scripttag = <<START;
12546: <script type="text/javascript">
12547: // <![CDATA[
12548:
12549: function checkAll(form,prefix) {
12550: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12551: for (var i=0; i < form.elements.length; i++) {
12552: var id = form.elements[i].id;
12553: if ((id != '') && (id != undefined)) {
12554: if (idstr.test(id)) {
12555: if (form.elements[i].type == 'radio') {
12556: form.elements[i].checked = true;
1.1056 raeburn 12557: var nostart = i-$startcount;
1.1059 raeburn 12558: var offset = nostart%7;
12559: var count = (nostart-offset)/7;
1.1056 raeburn 12560: dependencyCheck(form,count,offset);
1.1055 raeburn 12561: }
12562: }
12563: }
12564: }
12565: }
12566:
12567: function propagateCheck(form,count) {
12568: if (count > 0) {
1.1059 raeburn 12569: var startelement = $startcount + ((count-1) * 7);
12570: for (var j=1; j<6; j++) {
12571: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12572: var item = startelement + j;
12573: if (form.elements[item].type == 'radio') {
12574: if (form.elements[item].checked) {
12575: containerCheck(form,count,j);
12576: break;
12577: }
1.1055 raeburn 12578: }
12579: }
12580: }
12581: }
12582: }
12583:
12584: numitems = $numitems
1.1056 raeburn 12585: var titles = new Array(numitems);
12586: var parents = new Array(numitems);
1.1055 raeburn 12587: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12588: parents[i] = new Array;
1.1055 raeburn 12589: }
1.1059 raeburn 12590: var maintitle = '$maintitle';
1.1055 raeburn 12591:
12592: START
12593:
1.1056 raeburn 12594: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12595: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12596: for (my $i=0; $i<@contents; $i ++) {
12597: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12598: }
12599: }
12600:
1.1056 raeburn 12601: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12602: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12603: }
12604:
1.1055 raeburn 12605: $scripttag .= <<END;
12606:
12607: function containerCheck(form,count,offset) {
12608: if (count > 0) {
1.1056 raeburn 12609: dependencyCheck(form,count,offset);
1.1059 raeburn 12610: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12611: form.elements[item].checked = true;
12612: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12613: if (parents[count].length > 0) {
12614: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12615: containerCheck(form,parents[count][j],offset);
12616: }
12617: }
12618: }
12619: }
12620: }
12621:
12622: function dependencyCheck(form,count,offset) {
12623: if (count > 0) {
1.1059 raeburn 12624: var chosen = (offset+$startcount)+7*(count-1);
12625: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12626: var currtype = form.elements[depitem].type;
12627: if (form.elements[chosen].value == 'dependency') {
12628: document.getElementById('arc_depon_'+count).style.display='block';
12629: form.elements[depitem].options.length = 0;
12630: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12631: for (var i=1; i<=numitems; i++) {
12632: if (i == count) {
12633: continue;
12634: }
1.1059 raeburn 12635: var startelement = $startcount + (i-1) * 7;
12636: for (var j=1; j<6; j++) {
12637: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12638: var item = startelement + j;
12639: if (form.elements[item].type == 'radio') {
12640: if (form.elements[item].checked) {
12641: if (form.elements[item].value == 'display') {
12642: var n = form.elements[depitem].options.length;
12643: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12644: }
12645: }
12646: }
12647: }
12648: }
12649: }
12650: } else {
12651: document.getElementById('arc_depon_'+count).style.display='none';
12652: form.elements[depitem].options.length = 0;
12653: form.elements[depitem].options[0] = new Option('Select','',true,true);
12654: }
1.1059 raeburn 12655: titleCheck(form,count,offset);
1.1056 raeburn 12656: }
12657: }
12658:
12659: function propagateSelect(form,count,offset) {
12660: if (count > 0) {
1.1065 raeburn 12661: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12662: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12663: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12664: if (parents[count].length > 0) {
12665: for (var j=0; j<parents[count].length; j++) {
12666: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12667: }
12668: }
12669: }
12670: }
12671: }
1.1056 raeburn 12672:
12673: function containerSelect(form,count,offset,picked) {
12674: if (count > 0) {
1.1065 raeburn 12675: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12676: if (form.elements[item].type == 'radio') {
12677: if (form.elements[item].value == 'dependency') {
12678: if (form.elements[item+1].type == 'select-one') {
12679: for (var i=0; i<form.elements[item+1].options.length; i++) {
12680: if (form.elements[item+1].options[i].value == picked) {
12681: form.elements[item+1].selectedIndex = i;
12682: break;
12683: }
12684: }
12685: }
12686: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12687: if (parents[count].length > 0) {
12688: for (var j=0; j<parents[count].length; j++) {
12689: containerSelect(form,parents[count][j],offset,picked);
12690: }
12691: }
12692: }
12693: }
12694: }
12695: }
12696: }
12697:
1.1059 raeburn 12698: function titleCheck(form,count,offset) {
12699: if (count > 0) {
12700: var chosen = (offset+$startcount)+7*(count-1);
12701: var depitem = $startcount + ((count-1) * 7) + 2;
12702: var currtype = form.elements[depitem].type;
12703: if (form.elements[chosen].value == 'display') {
12704: document.getElementById('arc_title_'+count).style.display='block';
12705: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12706: document.getElementById('archive_title_'+count).value=maintitle;
12707: }
12708: } else {
12709: document.getElementById('arc_title_'+count).style.display='none';
12710: if (currtype == 'text') {
12711: document.getElementById('archive_title_'+count).value='';
12712: }
12713: }
12714: }
12715: return;
12716: }
12717:
1.1055 raeburn 12718: // ]]>
12719: </script>
12720: END
12721: return $scripttag;
12722: }
12723:
12724: sub process_extracted_files {
1.1067 raeburn 12725: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12726: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 12727: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 12728: my @ids=&Apache::lonnet::current_machine_ids();
12729: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12730: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12731: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12732: if (grep(/^\Q$docuhome\E$/,@ids)) {
12733: $prefix = &LONCAPA::propath($docudom,$docuname);
12734: $pathtocheck = "$dir_root/$destination";
12735: $dir = $dir_root;
12736: $ishome = 1;
12737: } else {
12738: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12739: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 12740: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 12741: }
12742: my $currdir = "$dir_root/$destination";
12743: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12744: if ($env{'form.folderpath'}) {
12745: my @items = split('&',$env{'form.folderpath'});
12746: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12747: if ($env{'form.folderpath'} =~ /\:1$/) {
12748: $containers{'0'}='page';
12749: } else {
12750: $containers{'0'}='sequence';
12751: }
1.1055 raeburn 12752: }
12753: my @archdirs = &get_env_multiple('form.archive_directory');
12754: if ($numitems) {
12755: for (my $i=1; $i<=$numitems; $i++) {
12756: my $path = $env{'form.archive_content_'.$i};
12757: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12758: my $item = $1;
12759: $toplevelitems{$item} = $i;
12760: if (grep(/^\Q$i\E$/,@archdirs)) {
12761: $is_dir{$item} = 1;
12762: }
12763: }
12764: }
12765: }
1.1067 raeburn 12766: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12767: if (keys(%toplevelitems) > 0) {
12768: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12769: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12770: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12771: }
1.1066 raeburn 12772: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12773: if ($numitems) {
12774: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12775: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12776: my $path = $env{'form.archive_content_'.$i};
12777: if ($path =~ /^\Q$pathtocheck\E/) {
12778: if ($env{'form.archive_'.$i} eq 'discard') {
12779: if ($prefix ne '' && $path ne '') {
12780: if (-e $prefix.$path) {
1.1066 raeburn 12781: if ((@archdirs > 0) &&
12782: (grep(/^\Q$i\E$/,@archdirs))) {
12783: $todeletedir{$prefix.$path} = 1;
12784: } else {
12785: $todelete{$prefix.$path} = 1;
12786: }
1.1055 raeburn 12787: }
12788: }
12789: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12790: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12791: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12792: $docstitle = $env{'form.archive_title_'.$i};
12793: if ($docstitle eq '') {
12794: $docstitle = $title;
12795: }
1.1055 raeburn 12796: $outer = 0;
1.1056 raeburn 12797: if (ref($dirorder{$i}) eq 'ARRAY') {
12798: if (@{$dirorder{$i}} > 0) {
12799: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12800: if ($env{'form.archive_'.$item} eq 'display') {
12801: $outer = $item;
12802: last;
12803: }
12804: }
12805: }
12806: }
12807: my ($errtext,$fatal) =
12808: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12809: '/'.$folders{$outer}.'.'.
12810: $containers{$outer});
12811: next if ($fatal);
12812: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12813: if ($context eq 'coursedocs') {
1.1056 raeburn 12814: $mapinner{$i} = time;
1.1055 raeburn 12815: $folders{$i} = 'default_'.$mapinner{$i};
12816: $containers{$i} = 'sequence';
12817: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12818: $folders{$i}.'.'.$containers{$i};
12819: my $newidx = &LONCAPA::map::getresidx();
12820: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12821: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12822: push(@LONCAPA::map::order,$newidx);
12823: my ($outtext,$errtext) =
12824: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12825: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12826: '.'.$containers{$outer},1,1);
1.1056 raeburn 12827: $newseqid{$i} = $newidx;
1.1067 raeburn 12828: unless ($errtext) {
1.1075.2.128 raeburn 12829: $result .= '<li>'.&mt('Folder: [_1] added to course',
12830: &HTML::Entities::encode($docstitle,'<>&"'))..
12831: '</li>'."\n";
1.1067 raeburn 12832: }
1.1055 raeburn 12833: }
12834: } else {
12835: if ($context eq 'coursedocs') {
12836: my $newidx=&LONCAPA::map::getresidx();
12837: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12838: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12839: $title;
1.1075.2.128 raeburn 12840: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
12841: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12842: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 12843: }
1.1075.2.128 raeburn 12844: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12845: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12846: }
12847: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12848: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
12849: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
12850: unless ($ishome) {
12851: my $fetch = "$newdest{$i}/$title";
12852: $fetch =~ s/^\Q$prefix$dir\E//;
12853: $prompttofetch{$fetch} = 1;
12854: }
12855: }
12856: }
12857: $LONCAPA::map::resources[$newidx]=
12858: $docstitle.':'.$url.':false:normal:res';
12859: push(@LONCAPA::map::order, $newidx);
12860: my ($outtext,$errtext)=
12861: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12862: $docuname.'/'.$folders{$outer}.
12863: '.'.$containers{$outer},1,1);
12864: unless ($errtext) {
12865: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12866: $result .= '<li>'.&mt('File: [_1] added to course',
12867: &HTML::Entities::encode($docstitle,'<>&"')).
12868: '</li>'."\n";
12869: }
1.1067 raeburn 12870: }
1.1075.2.128 raeburn 12871: } else {
12872: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12873: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 12874: }
1.1055 raeburn 12875: }
12876: }
1.1075.2.11 raeburn 12877: }
12878: } else {
1.1075.2.128 raeburn 12879: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12880: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 12881: }
12882: }
12883: for (my $i=1; $i<=$numitems; $i++) {
12884: next unless ($env{'form.archive_'.$i} eq 'dependency');
12885: my $path = $env{'form.archive_content_'.$i};
12886: if ($path =~ /^\Q$pathtocheck\E/) {
12887: my ($title) = ($path =~ m{/([^/]+)$});
12888: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12889: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12890: if (ref($dirorder{$i}) eq 'ARRAY') {
12891: my ($itemidx,$fullpath,$relpath);
12892: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12893: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12894: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12895: if ($dirorder{$i}->[$j] eq $container) {
12896: $itemidx = $j;
1.1056 raeburn 12897: }
12898: }
1.1075.2.11 raeburn 12899: }
12900: if ($itemidx eq '') {
12901: $itemidx = 0;
12902: }
12903: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12904: if ($mapinner{$referrer{$i}}) {
12905: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12906: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12907: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12908: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12909: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12910: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12911: if (!-e $fullpath) {
12912: mkdir($fullpath,0755);
1.1056 raeburn 12913: }
12914: }
1.1075.2.11 raeburn 12915: } else {
12916: last;
1.1056 raeburn 12917: }
1.1075.2.11 raeburn 12918: }
12919: }
12920: } elsif ($newdest{$referrer{$i}}) {
12921: $fullpath = $newdest{$referrer{$i}};
12922: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12923: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12924: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12925: last;
12926: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12927: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12928: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12929: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12930: if (!-e $fullpath) {
12931: mkdir($fullpath,0755);
1.1056 raeburn 12932: }
12933: }
1.1075.2.11 raeburn 12934: } else {
12935: last;
1.1056 raeburn 12936: }
1.1075.2.11 raeburn 12937: }
12938: }
12939: if ($fullpath ne '') {
12940: if (-e "$prefix$path") {
1.1075.2.128 raeburn 12941: unless (rename("$prefix$path","$fullpath/$title")) {
12942: $warning .= &mt('Failed to rename dependency').'<br />';
12943: }
1.1075.2.11 raeburn 12944: }
12945: if (-e "$fullpath/$title") {
12946: my $showpath;
12947: if ($relpath ne '') {
12948: $showpath = "$relpath/$title";
12949: } else {
12950: $showpath = "/$title";
1.1056 raeburn 12951: }
1.1075.2.128 raeburn 12952: $result .= '<li>'.&mt('[_1] included as a dependency',
12953: &HTML::Entities::encode($showpath,'<>&"')).
12954: '</li>'."\n";
12955: unless ($ishome) {
12956: my $fetch = "$fullpath/$title";
12957: $fetch =~ s/^\Q$prefix$dir\E//;
12958: $prompttofetch{$fetch} = 1;
12959: }
1.1055 raeburn 12960: }
12961: }
12962: }
1.1075.2.11 raeburn 12963: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12964: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 12965: &HTML::Entities::encode($path,'<>&"'),
12966: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
12967: '<br />';
1.1055 raeburn 12968: }
12969: } else {
1.1075.2.128 raeburn 12970: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12971: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 12972: }
12973: }
12974: if (keys(%todelete)) {
12975: foreach my $key (keys(%todelete)) {
12976: unlink($key);
1.1066 raeburn 12977: }
12978: }
12979: if (keys(%todeletedir)) {
12980: foreach my $key (keys(%todeletedir)) {
12981: rmdir($key);
12982: }
12983: }
12984: foreach my $dir (sort(keys(%is_dir))) {
12985: if (($pathtocheck ne '') && ($dir ne '')) {
12986: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12987: }
12988: }
1.1067 raeburn 12989: if ($result ne '') {
12990: $output .= '<ul>'."\n".
12991: $result."\n".
12992: '</ul>';
12993: }
12994: unless ($ishome) {
12995: my $replicationfail;
12996: foreach my $item (keys(%prompttofetch)) {
12997: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12998: unless ($fetchresult eq 'ok') {
12999: $replicationfail .= '<li>'.$item.'</li>'."\n";
13000: }
13001: }
13002: if ($replicationfail) {
13003: $output .= '<p class="LC_error">'.
13004: &mt('Course home server failed to retrieve:').'<ul>'.
13005: $replicationfail.
13006: '</ul></p>';
13007: }
13008: }
1.1055 raeburn 13009: } else {
13010: $warning = &mt('No items found in archive.');
13011: }
13012: if ($error) {
13013: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13014: $error.'</p>'."\n";
13015: }
13016: if ($warning) {
13017: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13018: }
13019: return $output;
13020: }
13021:
1.1066 raeburn 13022: sub cleanup_empty_dirs {
13023: my ($path) = @_;
13024: if (($path ne '') && (-d $path)) {
13025: if (opendir(my $dirh,$path)) {
13026: my @dircontents = grep(!/^\./,readdir($dirh));
13027: my $numitems = 0;
13028: foreach my $item (@dircontents) {
13029: if (-d "$path/$item") {
1.1075.2.28 raeburn 13030: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13031: if (-e "$path/$item") {
13032: $numitems ++;
13033: }
13034: } else {
13035: $numitems ++;
13036: }
13037: }
13038: if ($numitems == 0) {
13039: rmdir($path);
13040: }
13041: closedir($dirh);
13042: }
13043: }
13044: return;
13045: }
13046:
1.41 ng 13047: =pod
1.45 matthew 13048:
1.1075.2.56 raeburn 13049: =item * &get_folder_hierarchy()
1.1068 raeburn 13050:
13051: Provides hierarchy of names of folders/sub-folders containing the current
13052: item,
13053:
13054: Inputs: 3
13055: - $navmap - navmaps object
13056:
13057: - $map - url for map (either the trigger itself, or map containing
13058: the resource, which is the trigger).
13059:
13060: - $showitem - 1 => show title for map itself; 0 => do not show.
13061:
13062: Outputs: 1 @pathitems - array of folder/subfolder names.
13063:
13064: =cut
13065:
13066: sub get_folder_hierarchy {
13067: my ($navmap,$map,$showitem) = @_;
13068: my @pathitems;
13069: if (ref($navmap)) {
13070: my $mapres = $navmap->getResourceByUrl($map);
13071: if (ref($mapres)) {
13072: my $pcslist = $mapres->map_hierarchy();
13073: if ($pcslist ne '') {
13074: my @pcs = split(/,/,$pcslist);
13075: foreach my $pc (@pcs) {
13076: if ($pc == 1) {
1.1075.2.38 raeburn 13077: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13078: } else {
13079: my $res = $navmap->getByMapPc($pc);
13080: if (ref($res)) {
13081: my $title = $res->compTitle();
13082: $title =~ s/\W+/_/g;
13083: if ($title ne '') {
13084: push(@pathitems,$title);
13085: }
13086: }
13087: }
13088: }
13089: }
1.1071 raeburn 13090: if ($showitem) {
13091: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13092: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13093: } else {
13094: my $maptitle = $mapres->compTitle();
13095: $maptitle =~ s/\W+/_/g;
13096: if ($maptitle ne '') {
13097: push(@pathitems,$maptitle);
13098: }
1.1068 raeburn 13099: }
13100: }
13101: }
13102: }
13103: return @pathitems;
13104: }
13105:
13106: =pod
13107:
1.1015 raeburn 13108: =item * &get_turnedin_filepath()
13109:
13110: Determines path in a user's portfolio file for storage of files uploaded
13111: to a specific essayresponse or dropbox item.
13112:
13113: Inputs: 3 required + 1 optional.
13114: $symb is symb for resource, $uname and $udom are for current user (required).
13115: $caller is optional (can be "submission", if routine is called when storing
13116: an upoaded file when "Submit Answer" button was pressed).
13117:
13118: Returns array containing $path and $multiresp.
13119: $path is path in portfolio. $multiresp is 1 if this resource contains more
13120: than one file upload item. Callers of routine should append partid as a
13121: subdirectory to $path in cases where $multiresp is 1.
13122:
13123: Called by: homework/essayresponse.pm and homework/structuretags.pm
13124:
13125: =cut
13126:
13127: sub get_turnedin_filepath {
13128: my ($symb,$uname,$udom,$caller) = @_;
13129: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13130: my $turnindir;
13131: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13132: $turnindir = $userhash{'turnindir'};
13133: my ($path,$multiresp);
13134: if ($turnindir eq '') {
13135: if ($caller eq 'submission') {
13136: $turnindir = &mt('turned in');
13137: $turnindir =~ s/\W+/_/g;
13138: my %newhash = (
13139: 'turnindir' => $turnindir,
13140: );
13141: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13142: }
13143: }
13144: if ($turnindir ne '') {
13145: $path = '/'.$turnindir.'/';
13146: my ($multipart,$turnin,@pathitems);
13147: my $navmap = Apache::lonnavmaps::navmap->new();
13148: if (defined($navmap)) {
13149: my $mapres = $navmap->getResourceByUrl($map);
13150: if (ref($mapres)) {
13151: my $pcslist = $mapres->map_hierarchy();
13152: if ($pcslist ne '') {
13153: foreach my $pc (split(/,/,$pcslist)) {
13154: my $res = $navmap->getByMapPc($pc);
13155: if (ref($res)) {
13156: my $title = $res->compTitle();
13157: $title =~ s/\W+/_/g;
13158: if ($title ne '') {
1.1075.2.48 raeburn 13159: if (($pc > 1) && (length($title) > 12)) {
13160: $title = substr($title,0,12);
13161: }
1.1015 raeburn 13162: push(@pathitems,$title);
13163: }
13164: }
13165: }
13166: }
13167: my $maptitle = $mapres->compTitle();
13168: $maptitle =~ s/\W+/_/g;
13169: if ($maptitle ne '') {
1.1075.2.48 raeburn 13170: if (length($maptitle) > 12) {
13171: $maptitle = substr($maptitle,0,12);
13172: }
1.1015 raeburn 13173: push(@pathitems,$maptitle);
13174: }
13175: unless ($env{'request.state'} eq 'construct') {
13176: my $res = $navmap->getBySymb($symb);
13177: if (ref($res)) {
13178: my $partlist = $res->parts();
13179: my $totaluploads = 0;
13180: if (ref($partlist) eq 'ARRAY') {
13181: foreach my $part (@{$partlist}) {
13182: my @types = $res->responseType($part);
13183: my @ids = $res->responseIds($part);
13184: for (my $i=0; $i < scalar(@ids); $i++) {
13185: if ($types[$i] eq 'essay') {
13186: my $partid = $part.'_'.$ids[$i];
13187: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13188: $totaluploads ++;
13189: }
13190: }
13191: }
13192: }
13193: if ($totaluploads > 1) {
13194: $multiresp = 1;
13195: }
13196: }
13197: }
13198: }
13199: } else {
13200: return;
13201: }
13202: } else {
13203: return;
13204: }
13205: my $restitle=&Apache::lonnet::gettitle($symb);
13206: $restitle =~ s/\W+/_/g;
13207: if ($restitle eq '') {
13208: $restitle = ($resurl =~ m{/[^/]+$});
13209: if ($restitle eq '') {
13210: $restitle = time;
13211: }
13212: }
1.1075.2.48 raeburn 13213: if (length($restitle) > 12) {
13214: $restitle = substr($restitle,0,12);
13215: }
1.1015 raeburn 13216: push(@pathitems,$restitle);
13217: $path .= join('/',@pathitems);
13218: }
13219: return ($path,$multiresp);
13220: }
13221:
13222: =pod
13223:
1.464 albertel 13224: =back
1.41 ng 13225:
1.112 bowersj2 13226: =head1 CSV Upload/Handling functions
1.38 albertel 13227:
1.41 ng 13228: =over 4
13229:
1.648 raeburn 13230: =item * &upfile_store($r)
1.41 ng 13231:
13232: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13233: needs $env{'form.upfile'}
1.41 ng 13234: returns $datatoken to be put into hidden field
13235:
13236: =cut
1.31 albertel 13237:
13238: sub upfile_store {
13239: my $r=shift;
1.258 albertel 13240: $env{'form.upfile'}=~s/\r/\n/gs;
13241: $env{'form.upfile'}=~s/\f/\n/gs;
13242: $env{'form.upfile'}=~s/\n+/\n/gs;
13243: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13244:
1.1075.2.128 raeburn 13245: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13246: '_enroll_'.$env{'request.course.id'}.'_'.
13247: time.'_'.$$);
13248: return if ($datatoken eq '');
13249:
1.31 albertel 13250: {
1.158 raeburn 13251: my $datafile = $r->dir_config('lonDaemons').
13252: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 13253: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13254: print $fh $env{'form.upfile'};
1.158 raeburn 13255: close($fh);
13256: }
1.31 albertel 13257: }
13258: return $datatoken;
13259: }
13260:
1.56 matthew 13261: =pod
13262:
1.1075.2.128 raeburn 13263: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13264:
13265: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 13266: $datatoken is the name to assign to the temporary file.
1.258 albertel 13267: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13268:
13269: =cut
1.31 albertel 13270:
13271: sub load_tmp_file {
1.1075.2.128 raeburn 13272: my ($r,$datatoken) = @_;
13273: return if ($datatoken eq '');
1.31 albertel 13274: my @studentdata=();
13275: {
1.158 raeburn 13276: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 13277: '/tmp/'.$datatoken.'.tmp';
13278: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13279: @studentdata=<$fh>;
13280: close($fh);
13281: }
1.31 albertel 13282: }
1.258 albertel 13283: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13284: }
13285:
1.1075.2.128 raeburn 13286: sub valid_datatoken {
13287: my ($datatoken) = @_;
1.1075.2.131 raeburn 13288: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 13289: return $datatoken;
13290: }
13291: return;
13292: }
13293:
1.56 matthew 13294: =pod
13295:
1.648 raeburn 13296: =item * &upfile_record_sep()
1.41 ng 13297:
13298: Separate uploaded file into records
13299: returns array of records,
1.258 albertel 13300: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13301:
13302: =cut
1.31 albertel 13303:
13304: sub upfile_record_sep {
1.258 albertel 13305: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13306: } else {
1.248 albertel 13307: my @records;
1.258 albertel 13308: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13309: if ($line=~/^\s*$/) { next; }
13310: push(@records,$line);
13311: }
13312: return @records;
1.31 albertel 13313: }
13314: }
13315:
1.56 matthew 13316: =pod
13317:
1.648 raeburn 13318: =item * &record_sep($record)
1.41 ng 13319:
1.258 albertel 13320: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13321:
13322: =cut
13323:
1.263 www 13324: sub takeleft {
13325: my $index=shift;
13326: return substr('0000'.$index,-4,4);
13327: }
13328:
1.31 albertel 13329: sub record_sep {
13330: my $record=shift;
13331: my %components=();
1.258 albertel 13332: if ($env{'form.upfiletype'} eq 'xml') {
13333: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13334: my $i=0;
1.356 albertel 13335: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13336: $field=~s/^(\"|\')//;
13337: $field=~s/(\"|\')$//;
1.263 www 13338: $components{&takeleft($i)}=$field;
1.31 albertel 13339: $i++;
13340: }
1.258 albertel 13341: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13342: my $i=0;
1.356 albertel 13343: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13344: $field=~s/^(\"|\')//;
13345: $field=~s/(\"|\')$//;
1.263 www 13346: $components{&takeleft($i)}=$field;
1.31 albertel 13347: $i++;
13348: }
13349: } else {
1.561 www 13350: my $separator=',';
1.480 banghart 13351: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13352: $separator=';';
1.480 banghart 13353: }
1.31 albertel 13354: my $i=0;
1.561 www 13355: # the character we are looking for to indicate the end of a quote or a record
13356: my $looking_for=$separator;
13357: # do not add the characters to the fields
13358: my $ignore=0;
13359: # we just encountered a separator (or the beginning of the record)
13360: my $just_found_separator=1;
13361: # store the field we are working on here
13362: my $field='';
13363: # work our way through all characters in record
13364: foreach my $character ($record=~/(.)/g) {
13365: if ($character eq $looking_for) {
13366: if ($character ne $separator) {
13367: # Found the end of a quote, again looking for separator
13368: $looking_for=$separator;
13369: $ignore=1;
13370: } else {
13371: # Found a separator, store away what we got
13372: $components{&takeleft($i)}=$field;
13373: $i++;
13374: $just_found_separator=1;
13375: $ignore=0;
13376: $field='';
13377: }
13378: next;
13379: }
13380: # single or double quotation marks after a separator indicate beginning of a quote
13381: # we are now looking for the end of the quote and need to ignore separators
13382: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13383: $looking_for=$character;
13384: next;
13385: }
13386: # ignore would be true after we reached the end of a quote
13387: if ($ignore) { next; }
13388: if (($just_found_separator) && ($character=~/\s/)) { next; }
13389: $field.=$character;
13390: $just_found_separator=0;
1.31 albertel 13391: }
1.561 www 13392: # catch the very last entry, since we never encountered the separator
13393: $components{&takeleft($i)}=$field;
1.31 albertel 13394: }
13395: return %components;
13396: }
13397:
1.144 matthew 13398: ######################################################
13399: ######################################################
13400:
1.56 matthew 13401: =pod
13402:
1.648 raeburn 13403: =item * &upfile_select_html()
1.41 ng 13404:
1.144 matthew 13405: Return HTML code to select a file from the users machine and specify
13406: the file type.
1.41 ng 13407:
13408: =cut
13409:
1.144 matthew 13410: ######################################################
13411: ######################################################
1.31 albertel 13412: sub upfile_select_html {
1.144 matthew 13413: my %Types = (
13414: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13415: semisv => &mt('Semicolon separated values'),
1.144 matthew 13416: space => &mt('Space separated'),
13417: tab => &mt('Tabulator separated'),
13418: # xml => &mt('HTML/XML'),
13419: );
13420: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13421: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13422: foreach my $type (sort(keys(%Types))) {
13423: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13424: }
13425: $Str .= "</select>\n";
13426: return $Str;
1.31 albertel 13427: }
13428:
1.301 albertel 13429: sub get_samples {
13430: my ($records,$toget) = @_;
13431: my @samples=({});
13432: my $got=0;
13433: foreach my $rec (@$records) {
13434: my %temp = &record_sep($rec);
13435: if (! grep(/\S/, values(%temp))) { next; }
13436: if (%temp) {
13437: $samples[$got]=\%temp;
13438: $got++;
13439: if ($got == $toget) { last; }
13440: }
13441: }
13442: return \@samples;
13443: }
13444:
1.144 matthew 13445: ######################################################
13446: ######################################################
13447:
1.56 matthew 13448: =pod
13449:
1.648 raeburn 13450: =item * &csv_print_samples($r,$records)
1.41 ng 13451:
13452: Prints a table of sample values from each column uploaded $r is an
13453: Apache Request ref, $records is an arrayref from
13454: &Apache::loncommon::upfile_record_sep
13455:
13456: =cut
13457:
1.144 matthew 13458: ######################################################
13459: ######################################################
1.31 albertel 13460: sub csv_print_samples {
13461: my ($r,$records) = @_;
1.662 bisitz 13462: my $samples = &get_samples($records,5);
1.301 albertel 13463:
1.594 raeburn 13464: $r->print(&mt('Samples').'<br />'.&start_data_table().
13465: &start_data_table_header_row());
1.356 albertel 13466: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13467: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13468: $r->print(&end_data_table_header_row());
1.301 albertel 13469: foreach my $hash (@$samples) {
1.594 raeburn 13470: $r->print(&start_data_table_row());
1.356 albertel 13471: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13472: $r->print('<td>');
1.356 albertel 13473: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13474: $r->print('</td>');
13475: }
1.594 raeburn 13476: $r->print(&end_data_table_row());
1.31 albertel 13477: }
1.594 raeburn 13478: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13479: }
13480:
1.144 matthew 13481: ######################################################
13482: ######################################################
13483:
1.56 matthew 13484: =pod
13485:
1.648 raeburn 13486: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13487:
13488: Prints a table to create associations between values and table columns.
1.144 matthew 13489:
1.41 ng 13490: $r is an Apache Request ref,
13491: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13492: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13493:
13494: =cut
13495:
1.144 matthew 13496: ######################################################
13497: ######################################################
1.31 albertel 13498: sub csv_print_select_table {
13499: my ($r,$records,$d) = @_;
1.301 albertel 13500: my $i=0;
13501: my $samples = &get_samples($records,1);
1.144 matthew 13502: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13503: &start_data_table().&start_data_table_header_row().
1.144 matthew 13504: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13505: '<th>'.&mt('Column').'</th>'.
13506: &end_data_table_header_row()."\n");
1.356 albertel 13507: foreach my $array_ref (@$d) {
13508: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13509: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13510:
1.875 bisitz 13511: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13512: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13513: $r->print('<option value="none"></option>');
1.356 albertel 13514: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13515: $r->print('<option value="'.$sample.'"'.
13516: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13517: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13518: }
1.594 raeburn 13519: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13520: $i++;
13521: }
1.594 raeburn 13522: $r->print(&end_data_table());
1.31 albertel 13523: $i--;
13524: return $i;
13525: }
1.56 matthew 13526:
1.144 matthew 13527: ######################################################
13528: ######################################################
13529:
1.56 matthew 13530: =pod
1.31 albertel 13531:
1.648 raeburn 13532: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13533:
13534: Prints a table of sample values from the upload and can make associate samples to internal names.
13535:
13536: $r is an Apache Request ref,
13537: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13538: $d is an array of 2 element arrays (internal name, displayed name)
13539:
13540: =cut
13541:
1.144 matthew 13542: ######################################################
13543: ######################################################
1.31 albertel 13544: sub csv_samples_select_table {
13545: my ($r,$records,$d) = @_;
13546: my $i=0;
1.144 matthew 13547: #
1.662 bisitz 13548: my $max_samples = 5;
13549: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13550: $r->print(&start_data_table().
13551: &start_data_table_header_row().'<th>'.
13552: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13553: &end_data_table_header_row());
1.301 albertel 13554:
13555: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13556: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13557: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13558: foreach my $option (@$d) {
13559: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13560: $r->print('<option value="'.$value.'"'.
1.253 albertel 13561: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13562: $display.'</option>');
1.31 albertel 13563: }
13564: $r->print('</select></td><td>');
1.662 bisitz 13565: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13566: if (defined($samples->[$line]{$key})) {
13567: $r->print($samples->[$line]{$key}."<br />\n");
13568: }
13569: }
1.594 raeburn 13570: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13571: $i++;
13572: }
1.594 raeburn 13573: $r->print(&end_data_table());
1.31 albertel 13574: $i--;
13575: return($i);
1.115 matthew 13576: }
13577:
1.144 matthew 13578: ######################################################
13579: ######################################################
13580:
1.115 matthew 13581: =pod
13582:
1.648 raeburn 13583: =item * &clean_excel_name($name)
1.115 matthew 13584:
13585: Returns a replacement for $name which does not contain any illegal characters.
13586:
13587: =cut
13588:
1.144 matthew 13589: ######################################################
13590: ######################################################
1.115 matthew 13591: sub clean_excel_name {
13592: my ($name) = @_;
13593: $name =~ s/[:\*\?\/\\]//g;
13594: if (length($name) > 31) {
13595: $name = substr($name,0,31);
13596: }
13597: return $name;
1.25 albertel 13598: }
1.84 albertel 13599:
1.85 albertel 13600: =pod
13601:
1.648 raeburn 13602: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13603:
13604: Returns either 1 or undef
13605:
13606: 1 if the part is to be hidden, undef if it is to be shown
13607:
13608: Arguments are:
13609:
13610: $id the id of the part to be checked
13611: $symb, optional the symb of the resource to check
13612: $udom, optional the domain of the user to check for
13613: $uname, optional the username of the user to check for
13614:
13615: =cut
1.84 albertel 13616:
13617: sub check_if_partid_hidden {
13618: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13619: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13620: $symb,$udom,$uname);
1.141 albertel 13621: my $truth=1;
13622: #if the string starts with !, then the list is the list to show not hide
13623: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13624: my @hiddenlist=split(/,/,$hiddenparts);
13625: foreach my $checkid (@hiddenlist) {
1.141 albertel 13626: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13627: }
1.141 albertel 13628: return !$truth;
1.84 albertel 13629: }
1.127 matthew 13630:
1.138 matthew 13631:
13632: ############################################################
13633: ############################################################
13634:
13635: =pod
13636:
1.157 matthew 13637: =back
13638:
1.138 matthew 13639: =head1 cgi-bin script and graphing routines
13640:
1.157 matthew 13641: =over 4
13642:
1.648 raeburn 13643: =item * &get_cgi_id()
1.138 matthew 13644:
13645: Inputs: none
13646:
13647: Returns an id which can be used to pass environment variables
13648: to various cgi-bin scripts. These environment variables will
13649: be removed from the users environment after a given time by
13650: the routine &Apache::lonnet::transfer_profile_to_env.
13651:
13652: =cut
13653:
13654: ############################################################
13655: ############################################################
1.152 albertel 13656: my $uniq=0;
1.136 matthew 13657: sub get_cgi_id {
1.154 albertel 13658: $uniq=($uniq+1)%100000;
1.280 albertel 13659: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13660: }
13661:
1.127 matthew 13662: ############################################################
13663: ############################################################
13664:
13665: =pod
13666:
1.648 raeburn 13667: =item * &DrawBarGraph()
1.127 matthew 13668:
1.138 matthew 13669: Facilitates the plotting of data in a (stacked) bar graph.
13670: Puts plot definition data into the users environment in order for
13671: graph.png to plot it. Returns an <img> tag for the plot.
13672: The bars on the plot are labeled '1','2',...,'n'.
13673:
13674: Inputs:
13675:
13676: =over 4
13677:
13678: =item $Title: string, the title of the plot
13679:
13680: =item $xlabel: string, text describing the X-axis of the plot
13681:
13682: =item $ylabel: string, text describing the Y-axis of the plot
13683:
13684: =item $Max: scalar, the maximum Y value to use in the plot
13685: If $Max is < any data point, the graph will not be rendered.
13686:
1.140 matthew 13687: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13688: they are plotted. If undefined, default values will be used.
13689:
1.178 matthew 13690: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13691:
1.138 matthew 13692: =item @Values: An array of array references. Each array reference holds data
13693: to be plotted in a stacked bar chart.
13694:
1.239 matthew 13695: =item If the final element of @Values is a hash reference the key/value
13696: pairs will be added to the graph definition.
13697:
1.138 matthew 13698: =back
13699:
13700: Returns:
13701:
13702: An <img> tag which references graph.png and the appropriate identifying
13703: information for the plot.
13704:
1.127 matthew 13705: =cut
13706:
13707: ############################################################
13708: ############################################################
1.134 matthew 13709: sub DrawBarGraph {
1.178 matthew 13710: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13711: #
13712: if (! defined($colors)) {
13713: $colors = ['#33ff00',
13714: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13715: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13716: ];
13717: }
1.228 matthew 13718: my $extra_settings = {};
13719: if (ref($Values[-1]) eq 'HASH') {
13720: $extra_settings = pop(@Values);
13721: }
1.127 matthew 13722: #
1.136 matthew 13723: my $identifier = &get_cgi_id();
13724: my $id = 'cgi.'.$identifier;
1.129 matthew 13725: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13726: return '';
13727: }
1.225 matthew 13728: #
13729: my @Labels;
13730: if (defined($labels)) {
13731: @Labels = @$labels;
13732: } else {
13733: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 13734: push(@Labels,$i+1);
1.225 matthew 13735: }
13736: }
13737: #
1.129 matthew 13738: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13739: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13740: my %ValuesHash;
13741: my $NumSets=1;
13742: foreach my $array (@Values) {
13743: next if (! ref($array));
1.136 matthew 13744: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13745: join(',',@$array);
1.129 matthew 13746: }
1.127 matthew 13747: #
1.136 matthew 13748: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13749: if ($NumBars < 3) {
13750: $width = 120+$NumBars*32;
1.220 matthew 13751: $xskip = 1;
1.225 matthew 13752: $bar_width = 30;
13753: } elsif ($NumBars < 5) {
13754: $width = 120+$NumBars*20;
13755: $xskip = 1;
13756: $bar_width = 20;
1.220 matthew 13757: } elsif ($NumBars < 10) {
1.136 matthew 13758: $width = 120+$NumBars*15;
13759: $xskip = 1;
13760: $bar_width = 15;
13761: } elsif ($NumBars <= 25) {
13762: $width = 120+$NumBars*11;
13763: $xskip = 5;
13764: $bar_width = 8;
13765: } elsif ($NumBars <= 50) {
13766: $width = 120+$NumBars*8;
13767: $xskip = 5;
13768: $bar_width = 4;
13769: } else {
13770: $width = 120+$NumBars*8;
13771: $xskip = 5;
13772: $bar_width = 4;
13773: }
13774: #
1.137 matthew 13775: $Max = 1 if ($Max < 1);
13776: if ( int($Max) < $Max ) {
13777: $Max++;
13778: $Max = int($Max);
13779: }
1.127 matthew 13780: $Title = '' if (! defined($Title));
13781: $xlabel = '' if (! defined($xlabel));
13782: $ylabel = '' if (! defined($ylabel));
1.369 www 13783: $ValuesHash{$id.'.title'} = &escape($Title);
13784: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13785: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13786: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13787: $ValuesHash{$id.'.NumBars'} = $NumBars;
13788: $ValuesHash{$id.'.NumSets'} = $NumSets;
13789: $ValuesHash{$id.'.PlotType'} = 'bar';
13790: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13791: $ValuesHash{$id.'.height'} = $height;
13792: $ValuesHash{$id.'.width'} = $width;
13793: $ValuesHash{$id.'.xskip'} = $xskip;
13794: $ValuesHash{$id.'.bar_width'} = $bar_width;
13795: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13796: #
1.228 matthew 13797: # Deal with other parameters
13798: while (my ($key,$value) = each(%$extra_settings)) {
13799: $ValuesHash{$id.'.'.$key} = $value;
13800: }
13801: #
1.646 raeburn 13802: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13803: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13804: }
13805:
13806: ############################################################
13807: ############################################################
13808:
13809: =pod
13810:
1.648 raeburn 13811: =item * &DrawXYGraph()
1.137 matthew 13812:
1.138 matthew 13813: Facilitates the plotting of data in an XY graph.
13814: Puts plot definition data into the users environment in order for
13815: graph.png to plot it. Returns an <img> tag for the plot.
13816:
13817: Inputs:
13818:
13819: =over 4
13820:
13821: =item $Title: string, the title of the plot
13822:
13823: =item $xlabel: string, text describing the X-axis of the plot
13824:
13825: =item $ylabel: string, text describing the Y-axis of the plot
13826:
13827: =item $Max: scalar, the maximum Y value to use in the plot
13828: If $Max is < any data point, the graph will not be rendered.
13829:
13830: =item $colors: Array ref containing the hex color codes for the data to be
13831: plotted in. If undefined, default values will be used.
13832:
13833: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13834:
13835: =item $Ydata: Array ref containing Array refs.
1.185 www 13836: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13837:
13838: =item %Values: hash indicating or overriding any default values which are
13839: passed to graph.png.
13840: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13841:
13842: =back
13843:
13844: Returns:
13845:
13846: An <img> tag which references graph.png and the appropriate identifying
13847: information for the plot.
13848:
1.137 matthew 13849: =cut
13850:
13851: ############################################################
13852: ############################################################
13853: sub DrawXYGraph {
13854: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13855: #
13856: # Create the identifier for the graph
13857: my $identifier = &get_cgi_id();
13858: my $id = 'cgi.'.$identifier;
13859: #
13860: $Title = '' if (! defined($Title));
13861: $xlabel = '' if (! defined($xlabel));
13862: $ylabel = '' if (! defined($ylabel));
13863: my %ValuesHash =
13864: (
1.369 www 13865: $id.'.title' => &escape($Title),
13866: $id.'.xlabel' => &escape($xlabel),
13867: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13868: $id.'.y_max_value'=> $Max,
13869: $id.'.labels' => join(',',@$Xlabels),
13870: $id.'.PlotType' => 'XY',
13871: );
13872: #
13873: if (defined($colors) && ref($colors) eq 'ARRAY') {
13874: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13875: }
13876: #
13877: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13878: return '';
13879: }
13880: my $NumSets=1;
1.138 matthew 13881: foreach my $array (@{$Ydata}){
1.137 matthew 13882: next if (! ref($array));
13883: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13884: }
1.138 matthew 13885: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13886: #
13887: # Deal with other parameters
13888: while (my ($key,$value) = each(%Values)) {
13889: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13890: }
13891: #
1.646 raeburn 13892: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13893: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13894: }
13895:
13896: ############################################################
13897: ############################################################
13898:
13899: =pod
13900:
1.648 raeburn 13901: =item * &DrawXYYGraph()
1.138 matthew 13902:
13903: Facilitates the plotting of data in an XY graph with two Y axes.
13904: Puts plot definition data into the users environment in order for
13905: graph.png to plot it. Returns an <img> tag for the plot.
13906:
13907: Inputs:
13908:
13909: =over 4
13910:
13911: =item $Title: string, the title of the plot
13912:
13913: =item $xlabel: string, text describing the X-axis of the plot
13914:
13915: =item $ylabel: string, text describing the Y-axis of the plot
13916:
13917: =item $colors: Array ref containing the hex color codes for the data to be
13918: plotted in. If undefined, default values will be used.
13919:
13920: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13921:
13922: =item $Ydata1: The first data set
13923:
13924: =item $Min1: The minimum value of the left Y-axis
13925:
13926: =item $Max1: The maximum value of the left Y-axis
13927:
13928: =item $Ydata2: The second data set
13929:
13930: =item $Min2: The minimum value of the right Y-axis
13931:
13932: =item $Max2: The maximum value of the left Y-axis
13933:
13934: =item %Values: hash indicating or overriding any default values which are
13935: passed to graph.png.
13936: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13937:
13938: =back
13939:
13940: Returns:
13941:
13942: An <img> tag which references graph.png and the appropriate identifying
13943: information for the plot.
1.136 matthew 13944:
13945: =cut
13946:
13947: ############################################################
13948: ############################################################
1.137 matthew 13949: sub DrawXYYGraph {
13950: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13951: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13952: #
13953: # Create the identifier for the graph
13954: my $identifier = &get_cgi_id();
13955: my $id = 'cgi.'.$identifier;
13956: #
13957: $Title = '' if (! defined($Title));
13958: $xlabel = '' if (! defined($xlabel));
13959: $ylabel = '' if (! defined($ylabel));
13960: my %ValuesHash =
13961: (
1.369 www 13962: $id.'.title' => &escape($Title),
13963: $id.'.xlabel' => &escape($xlabel),
13964: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13965: $id.'.labels' => join(',',@$Xlabels),
13966: $id.'.PlotType' => 'XY',
13967: $id.'.NumSets' => 2,
1.137 matthew 13968: $id.'.two_axes' => 1,
13969: $id.'.y1_max_value' => $Max1,
13970: $id.'.y1_min_value' => $Min1,
13971: $id.'.y2_max_value' => $Max2,
13972: $id.'.y2_min_value' => $Min2,
1.136 matthew 13973: );
13974: #
1.137 matthew 13975: if (defined($colors) && ref($colors) eq 'ARRAY') {
13976: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13977: }
13978: #
13979: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13980: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13981: return '';
13982: }
13983: my $NumSets=1;
1.137 matthew 13984: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13985: next if (! ref($array));
13986: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13987: }
13988: #
13989: # Deal with other parameters
13990: while (my ($key,$value) = each(%Values)) {
13991: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13992: }
13993: #
1.646 raeburn 13994: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13995: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13996: }
13997:
13998: ############################################################
13999: ############################################################
14000:
14001: =pod
14002:
1.157 matthew 14003: =back
14004:
1.139 matthew 14005: =head1 Statistics helper routines?
14006:
14007: Bad place for them but what the hell.
14008:
1.157 matthew 14009: =over 4
14010:
1.648 raeburn 14011: =item * &chartlink()
1.139 matthew 14012:
14013: Returns a link to the chart for a specific student.
14014:
14015: Inputs:
14016:
14017: =over 4
14018:
14019: =item $linktext: The text of the link
14020:
14021: =item $sname: The students username
14022:
14023: =item $sdomain: The students domain
14024:
14025: =back
14026:
1.157 matthew 14027: =back
14028:
1.139 matthew 14029: =cut
14030:
14031: ############################################################
14032: ############################################################
14033: sub chartlink {
14034: my ($linktext, $sname, $sdomain) = @_;
14035: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14036: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14037: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14038: '">'.$linktext.'</a>';
1.153 matthew 14039: }
14040:
14041: #######################################################
14042: #######################################################
14043:
14044: =pod
14045:
14046: =head1 Course Environment Routines
1.157 matthew 14047:
14048: =over 4
1.153 matthew 14049:
1.648 raeburn 14050: =item * &restore_course_settings()
1.153 matthew 14051:
1.648 raeburn 14052: =item * &store_course_settings()
1.153 matthew 14053:
14054: Restores/Store indicated form parameters from the course environment.
14055: Will not overwrite existing values of the form parameters.
14056:
14057: Inputs:
14058: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14059:
14060: a hash ref describing the data to be stored. For example:
14061:
14062: %Save_Parameters = ('Status' => 'scalar',
14063: 'chartoutputmode' => 'scalar',
14064: 'chartoutputdata' => 'scalar',
14065: 'Section' => 'array',
1.373 raeburn 14066: 'Group' => 'array',
1.153 matthew 14067: 'StudentData' => 'array',
14068: 'Maps' => 'array');
14069:
14070: Returns: both routines return nothing
14071:
1.631 raeburn 14072: =back
14073:
1.153 matthew 14074: =cut
14075:
14076: #######################################################
14077: #######################################################
14078: sub store_course_settings {
1.496 albertel 14079: return &store_settings($env{'request.course.id'},@_);
14080: }
14081:
14082: sub store_settings {
1.153 matthew 14083: # save to the environment
14084: # appenv the same items, just to be safe
1.300 albertel 14085: my $udom = $env{'user.domain'};
14086: my $uname = $env{'user.name'};
1.496 albertel 14087: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14088: my %SaveHash;
14089: my %AppHash;
14090: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14091: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14092: my $envname = 'environment.'.$basename;
1.258 albertel 14093: if (exists($env{'form.'.$setting})) {
1.153 matthew 14094: # Save this value away
14095: if ($type eq 'scalar' &&
1.258 albertel 14096: (! exists($env{$envname}) ||
14097: $env{$envname} ne $env{'form.'.$setting})) {
14098: $SaveHash{$basename} = $env{'form.'.$setting};
14099: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14100: } elsif ($type eq 'array') {
14101: my $stored_form;
1.258 albertel 14102: if (ref($env{'form.'.$setting})) {
1.153 matthew 14103: $stored_form = join(',',
14104: map {
1.369 www 14105: &escape($_);
1.258 albertel 14106: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14107: } else {
14108: $stored_form =
1.369 www 14109: &escape($env{'form.'.$setting});
1.153 matthew 14110: }
14111: # Determine if the array contents are the same.
1.258 albertel 14112: if ($stored_form ne $env{$envname}) {
1.153 matthew 14113: $SaveHash{$basename} = $stored_form;
14114: $AppHash{$envname} = $stored_form;
14115: }
14116: }
14117: }
14118: }
14119: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14120: $udom,$uname);
1.153 matthew 14121: if ($put_result !~ /^(ok|delayed)/) {
14122: &Apache::lonnet::logthis('unable to save form parameters, '.
14123: 'got error:'.$put_result);
14124: }
14125: # Make sure these settings stick around in this session, too
1.646 raeburn 14126: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14127: return;
14128: }
14129:
14130: sub restore_course_settings {
1.499 albertel 14131: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14132: }
14133:
14134: sub restore_settings {
14135: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14136: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14137: next if (exists($env{'form.'.$setting}));
1.496 albertel 14138: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14139: '.'.$setting;
1.258 albertel 14140: if (exists($env{$envname})) {
1.153 matthew 14141: if ($type eq 'scalar') {
1.258 albertel 14142: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14143: } elsif ($type eq 'array') {
1.258 albertel 14144: $env{'form.'.$setting} = [
1.153 matthew 14145: map {
1.369 www 14146: &unescape($_);
1.258 albertel 14147: } split(',',$env{$envname})
1.153 matthew 14148: ];
14149: }
14150: }
14151: }
1.127 matthew 14152: }
14153:
1.618 raeburn 14154: #######################################################
14155: #######################################################
14156:
14157: =pod
14158:
14159: =head1 Domain E-mail Routines
14160:
14161: =over 4
14162:
1.648 raeburn 14163: =item * &build_recipient_list()
1.618 raeburn 14164:
1.1075.2.44 raeburn 14165: Build recipient lists for following types of e-mail:
1.766 raeburn 14166: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14167: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14168: module change checking, student/employee ID conflict checks, as
14169: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14170: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14171:
14172: Inputs:
1.1075.2.44 raeburn 14173: defmail (scalar - email address of default recipient),
14174: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14175: requestsmail, updatesmail, or idconflictsmail).
14176:
1.619 raeburn 14177: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14178:
14179: origmail (scalar - email address of recipient from loncapa.conf,
14180: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14181:
1.655 raeburn 14182: Returns: comma separated list of addresses to which to send e-mail.
14183:
14184: =back
1.618 raeburn 14185:
14186: =cut
14187:
14188: ############################################################
14189: ############################################################
14190: sub build_recipient_list {
1.619 raeburn 14191: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 14192: my @recipients;
1.1075.2.122 raeburn 14193: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14194: my %domconfig =
1.1075.2.122 raeburn 14195: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14196: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14197: if (exists($domconfig{'contacts'}{$mailing})) {
14198: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14199: my @contacts = ('adminemail','supportemail');
14200: foreach my $item (@contacts) {
14201: if ($domconfig{'contacts'}{$mailing}{$item}) {
14202: my $addr = $domconfig{'contacts'}{$item};
14203: if (!grep(/^\Q$addr\E$/,@recipients)) {
14204: push(@recipients,$addr);
14205: }
1.619 raeburn 14206: }
1.1075.2.122 raeburn 14207: }
14208: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14209: if ($mailing eq 'helpdeskmail') {
14210: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14211: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14212: my @ok_bccs;
14213: foreach my $bcc (@bccs) {
14214: $bcc =~ s/^\s+//g;
14215: $bcc =~ s/\s+$//g;
14216: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14217: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14218: push(@ok_bccs,$bcc);
14219: }
14220: }
14221: }
14222: if (@ok_bccs > 0) {
14223: $allbcc = join(', ',@ok_bccs);
14224: }
14225: }
14226: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14227: }
14228: }
1.766 raeburn 14229: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14230: $lastresort = $origmail;
1.618 raeburn 14231: }
1.619 raeburn 14232: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14233: $lastresort = $origmail;
14234: }
14235:
1.1075.2.128 raeburn 14236: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14237: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14238: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14239: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14240: my %what = (
14241: perlvar => 1,
14242: );
14243: my $primary = &Apache::lonnet::domain($defdom,'primary');
14244: if ($primary) {
14245: my $gotaddr;
14246: my ($result,$returnhash) =
14247: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14248: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14249: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14250: $lastresort = $returnhash->{'lonSupportEMail'};
14251: $gotaddr = 1;
14252: }
14253: }
14254: unless ($gotaddr) {
14255: my $uintdom = &Apache::lonnet::internet_dom($primary);
14256: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14257: unless ($uintdom eq $intdom) {
14258: my %domconfig =
14259: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14260: if (ref($domconfig{'contacts'}) eq 'HASH') {
14261: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14262: my @contacts = ('adminemail','supportemail');
14263: foreach my $item (@contacts) {
14264: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14265: my $addr = $domconfig{'contacts'}{$item};
14266: if (!grep(/^\Q$addr\E$/,@recipients)) {
14267: push(@recipients,$addr);
14268: }
14269: }
14270: }
14271: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14272: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14273: }
14274: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14275: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14276: my @ok_bccs;
14277: foreach my $bcc (@bccs) {
14278: $bcc =~ s/^\s+//g;
14279: $bcc =~ s/\s+$//g;
14280: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14281: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14282: push(@ok_bccs,$bcc);
14283: }
14284: }
14285: }
14286: if (@ok_bccs > 0) {
14287: $allbcc = join(', ',@ok_bccs);
14288: }
14289: }
14290: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14291: }
14292: }
14293: }
14294: }
14295: }
14296: }
1.618 raeburn 14297: }
1.688 raeburn 14298: if (defined($defmail)) {
14299: if ($defmail ne '') {
14300: push(@recipients,$defmail);
14301: }
1.618 raeburn 14302: }
14303: if ($otheremails) {
1.619 raeburn 14304: my @others;
14305: if ($otheremails =~ /,/) {
14306: @others = split(/,/,$otheremails);
1.618 raeburn 14307: } else {
1.619 raeburn 14308: push(@others,$otheremails);
14309: }
14310: foreach my $addr (@others) {
14311: if (!grep(/^\Q$addr\E$/,@recipients)) {
14312: push(@recipients,$addr);
14313: }
1.618 raeburn 14314: }
14315: }
1.1075.2.128 raeburn 14316: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14317: if ((!@recipients) && ($lastresort ne '')) {
14318: push(@recipients,$lastresort);
14319: }
14320: } elsif ($lastresort ne '') {
14321: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14322: push(@recipients,$lastresort);
14323: }
14324: }
14325: my $recipientlist = join(',',@recipients);
14326: if (wantarray) {
14327: return ($recipientlist,$allbcc,$addtext);
14328: } else {
14329: return $recipientlist;
14330: }
1.618 raeburn 14331: }
14332:
1.127 matthew 14333: ############################################################
14334: ############################################################
1.154 albertel 14335:
1.655 raeburn 14336: =pod
14337:
14338: =head1 Course Catalog Routines
14339:
14340: =over 4
14341:
14342: =item * &gather_categories()
14343:
14344: Converts category definitions - keys of categories hash stored in
14345: coursecategories in configuration.db on the primary library server in a
14346: domain - to an array. Also generates javascript and idx hash used to
14347: generate Domain Coordinator interface for editing Course Categories.
14348:
14349: Inputs:
1.663 raeburn 14350:
1.655 raeburn 14351: categories (reference to hash of category definitions).
1.663 raeburn 14352:
1.655 raeburn 14353: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14354: categories and subcategories).
1.663 raeburn 14355:
1.655 raeburn 14356: idx (reference to hash of counters used in Domain Coordinator interface for
14357: editing Course Categories).
1.663 raeburn 14358:
1.655 raeburn 14359: jsarray (reference to array of categories used to create Javascript arrays for
14360: Domain Coordinator interface for editing Course Categories).
14361:
14362: Returns: nothing
14363:
14364: Side effects: populates cats, idx and jsarray.
14365:
14366: =cut
14367:
14368: sub gather_categories {
14369: my ($categories,$cats,$idx,$jsarray) = @_;
14370: my %counters;
14371: my $num = 0;
14372: foreach my $item (keys(%{$categories})) {
14373: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14374: if ($container eq '' && $depth == 0) {
14375: $cats->[$depth][$categories->{$item}] = $cat;
14376: } else {
14377: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14378: }
14379: my ($escitem,$tail) = split(/:/,$item,2);
14380: if ($counters{$tail} eq '') {
14381: $counters{$tail} = $num;
14382: $num ++;
14383: }
14384: if (ref($idx) eq 'HASH') {
14385: $idx->{$item} = $counters{$tail};
14386: }
14387: if (ref($jsarray) eq 'ARRAY') {
14388: push(@{$jsarray->[$counters{$tail}]},$item);
14389: }
14390: }
14391: return;
14392: }
14393:
14394: =pod
14395:
14396: =item * &extract_categories()
14397:
14398: Used to generate breadcrumb trails for course categories.
14399:
14400: Inputs:
1.663 raeburn 14401:
1.655 raeburn 14402: categories (reference to hash of category definitions).
1.663 raeburn 14403:
1.655 raeburn 14404: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14405: categories and subcategories).
1.663 raeburn 14406:
1.655 raeburn 14407: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14408:
1.655 raeburn 14409: allitems (reference to hash - key is category key
14410: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14411:
1.655 raeburn 14412: idx (reference to hash of counters used in Domain Coordinator interface for
14413: editing Course Categories).
1.663 raeburn 14414:
1.655 raeburn 14415: jsarray (reference to array of categories used to create Javascript arrays for
14416: Domain Coordinator interface for editing Course Categories).
14417:
1.665 raeburn 14418: subcats (reference to hash of arrays containing all subcategories within each
14419: category, -recursive)
14420:
1.1075.2.132 raeburn 14421: maxd (reference to hash used to hold max depth for all top-level categories).
14422:
1.655 raeburn 14423: Returns: nothing
14424:
14425: Side effects: populates trails and allitems hash references.
14426:
14427: =cut
14428:
14429: sub extract_categories {
1.1075.2.132 raeburn 14430: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 14431: if (ref($categories) eq 'HASH') {
14432: &gather_categories($categories,$cats,$idx,$jsarray);
14433: if (ref($cats->[0]) eq 'ARRAY') {
14434: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14435: my $name = $cats->[0][$i];
14436: my $item = &escape($name).'::0';
14437: my $trailstr;
14438: if ($name eq 'instcode') {
14439: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14440: } elsif ($name eq 'communities') {
14441: $trailstr = &mt('Communities');
1.655 raeburn 14442: } else {
14443: $trailstr = $name;
14444: }
14445: if ($allitems->{$item} eq '') {
14446: push(@{$trails},$trailstr);
14447: $allitems->{$item} = scalar(@{$trails})-1;
14448: }
14449: my @parents = ($name);
14450: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14451: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14452: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14453: if (ref($subcats) eq 'HASH') {
14454: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14455: }
1.1075.2.132 raeburn 14456: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 14457: }
14458: } else {
14459: if (ref($subcats) eq 'HASH') {
14460: $subcats->{$item} = [];
1.655 raeburn 14461: }
1.1075.2.132 raeburn 14462: if (ref($maxd) eq 'HASH') {
14463: $maxd->{$name} = 1;
14464: }
1.655 raeburn 14465: }
14466: }
14467: }
14468: }
14469: return;
14470: }
14471:
14472: =pod
14473:
1.1075.2.56 raeburn 14474: =item * &recurse_categories()
1.655 raeburn 14475:
14476: Recursively used to generate breadcrumb trails for course categories.
14477:
14478: Inputs:
1.663 raeburn 14479:
1.655 raeburn 14480: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14481: categories and subcategories).
1.663 raeburn 14482:
1.655 raeburn 14483: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14484:
14485: category (current course category, for which breadcrumb trail is being generated).
14486:
14487: trails (reference to array of breadcrumb trails for each category).
14488:
1.655 raeburn 14489: allitems (reference to hash - key is category key
14490: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14491:
1.655 raeburn 14492: parents (array containing containers directories for current category,
14493: back to top level).
14494:
14495: Returns: nothing
14496:
14497: Side effects: populates trails and allitems hash references
14498:
14499: =cut
14500:
14501: sub recurse_categories {
1.1075.2.132 raeburn 14502: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 14503: my $shallower = $depth - 1;
14504: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14505: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14506: my $name = $cats->[$depth]{$category}[$k];
14507: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14508: my $trailstr = join(' -> ',(@{$parents},$category));
14509: if ($allitems->{$item} eq '') {
14510: push(@{$trails},$trailstr);
14511: $allitems->{$item} = scalar(@{$trails})-1;
14512: }
14513: my $deeper = $depth+1;
14514: push(@{$parents},$category);
1.665 raeburn 14515: if (ref($subcats) eq 'HASH') {
14516: my $subcat = &escape($name).':'.$category.':'.$depth;
14517: for (my $j=@{$parents}; $j>=0; $j--) {
14518: my $higher;
14519: if ($j > 0) {
14520: $higher = &escape($parents->[$j]).':'.
14521: &escape($parents->[$j-1]).':'.$j;
14522: } else {
14523: $higher = &escape($parents->[$j]).'::'.$j;
14524: }
14525: push(@{$subcats->{$higher}},$subcat);
14526: }
14527: }
14528: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 14529: $subcats,$maxd);
1.655 raeburn 14530: pop(@{$parents});
14531: }
14532: } else {
14533: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 14534: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14535: if ($allitems->{$item} eq '') {
14536: push(@{$trails},$trailstr);
14537: $allitems->{$item} = scalar(@{$trails})-1;
14538: }
1.1075.2.132 raeburn 14539: if (ref($maxd) eq 'HASH') {
14540: if ($depth > $maxd->{$parents->[0]}) {
14541: $maxd->{$parents->[0]} = $depth;
14542: }
14543: }
1.655 raeburn 14544: }
14545: return;
14546: }
14547:
1.663 raeburn 14548: =pod
14549:
1.1075.2.56 raeburn 14550: =item * &assign_categories_table()
1.663 raeburn 14551:
14552: Create a datatable for display of hierarchical categories in a domain,
14553: with checkboxes to allow a course to be categorized.
14554:
14555: Inputs:
14556:
14557: cathash - reference to hash of categories defined for the domain (from
14558: configuration.db)
14559:
14560: currcat - scalar with an & separated list of categories assigned to a course.
14561:
1.919 raeburn 14562: type - scalar contains course type (Course or Community).
14563:
1.1075.2.117 raeburn 14564: disabled - scalar (optional) contains disabled="disabled" if input elements are
14565: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14566:
1.663 raeburn 14567: Returns: $output (markup to be displayed)
14568:
14569: =cut
14570:
14571: sub assign_categories_table {
1.1075.2.117 raeburn 14572: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14573: my $output;
14574: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 14575: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
14576: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 14577: $maxdepth = scalar(@cats);
14578: if (@cats > 0) {
14579: my $itemcount = 0;
14580: if (ref($cats[0]) eq 'ARRAY') {
14581: my @currcategories;
14582: if ($currcat ne '') {
14583: @currcategories = split('&',$currcat);
14584: }
1.919 raeburn 14585: my $table;
1.663 raeburn 14586: for (my $i=0; $i<@{$cats[0]}; $i++) {
14587: my $parent = $cats[0][$i];
1.919 raeburn 14588: next if ($parent eq 'instcode');
14589: if ($type eq 'Community') {
14590: next unless ($parent eq 'communities');
14591: } else {
14592: next if ($parent eq 'communities');
14593: }
1.663 raeburn 14594: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14595: my $item = &escape($parent).'::0';
14596: my $checked = '';
14597: if (@currcategories > 0) {
14598: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14599: $checked = ' checked="checked"';
1.663 raeburn 14600: }
14601: }
1.919 raeburn 14602: my $parent_title = $parent;
14603: if ($parent eq 'communities') {
14604: $parent_title = &mt('Communities');
14605: }
14606: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14607: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14608: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 14609: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14610: my $depth = 1;
14611: push(@path,$parent);
1.1075.2.117 raeburn 14612: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 14613: pop(@path);
1.919 raeburn 14614: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14615: $itemcount ++;
14616: }
1.919 raeburn 14617: if ($itemcount) {
14618: $output = &Apache::loncommon::start_data_table().
14619: $table.
14620: &Apache::loncommon::end_data_table();
14621: }
1.663 raeburn 14622: }
14623: }
14624: }
14625: return $output;
14626: }
14627:
14628: =pod
14629:
1.1075.2.56 raeburn 14630: =item * &assign_category_rows()
1.663 raeburn 14631:
14632: Create a datatable row for display of nested categories in a domain,
14633: with checkboxes to allow a course to be categorized,called recursively.
14634:
14635: Inputs:
14636:
14637: itemcount - track row number for alternating colors
14638:
14639: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14640: categories and subcategories.
14641:
14642: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14643:
14644: parent - parent of current category item
14645:
14646: path - Array containing all categories back up through the hierarchy from the
14647: current category to the top level.
14648:
14649: currcategories - reference to array of current categories assigned to the course
14650:
1.1075.2.117 raeburn 14651: disabled - scalar (optional) contains disabled="disabled" if input elements are
14652: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14653:
1.663 raeburn 14654: Returns: $output (markup to be displayed).
14655:
14656: =cut
14657:
14658: sub assign_category_rows {
1.1075.2.117 raeburn 14659: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 14660: my ($text,$name,$item,$chgstr);
14661: if (ref($cats) eq 'ARRAY') {
14662: my $maxdepth = scalar(@{$cats});
14663: if (ref($cats->[$depth]) eq 'HASH') {
14664: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14665: my $numchildren = @{$cats->[$depth]{$parent}};
14666: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 14667: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14668: for (my $j=0; $j<$numchildren; $j++) {
14669: $name = $cats->[$depth]{$parent}[$j];
14670: $item = &escape($name).':'.&escape($parent).':'.$depth;
14671: my $deeper = $depth+1;
14672: my $checked = '';
14673: if (ref($currcategories) eq 'ARRAY') {
14674: if (@{$currcategories} > 0) {
14675: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14676: $checked = ' checked="checked"';
1.663 raeburn 14677: }
14678: }
14679: }
1.664 raeburn 14680: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14681: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14682: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 14683: '<input type="hidden" name="catname" value="'.$name.'" />'.
14684: '</td><td>';
1.663 raeburn 14685: if (ref($path) eq 'ARRAY') {
14686: push(@{$path},$name);
1.1075.2.117 raeburn 14687: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 14688: pop(@{$path});
14689: }
14690: $text .= '</td></tr>';
14691: }
14692: $text .= '</table></td>';
14693: }
14694: }
14695: }
14696: return $text;
14697: }
14698:
1.1075.2.69 raeburn 14699: =pod
14700:
14701: =back
14702:
14703: =cut
14704:
1.655 raeburn 14705: ############################################################
14706: ############################################################
14707:
14708:
1.443 albertel 14709: sub commit_customrole {
1.664 raeburn 14710: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14711: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14712: ($start?', '.&mt('starting').' '.localtime($start):'').
14713: ($end?', ending '.localtime($end):'').': <b>'.
14714: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14715: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14716: '</b><br />';
14717: return $output;
14718: }
14719:
14720: sub commit_standardrole {
1.1075.2.31 raeburn 14721: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14722: my ($output,$logmsg,$linefeed);
14723: if ($context eq 'auto') {
14724: $linefeed = "\n";
14725: } else {
14726: $linefeed = "<br />\n";
14727: }
1.443 albertel 14728: if ($three eq 'st') {
1.541 raeburn 14729: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 14730: $one,$two,$sec,$context,$credits);
1.541 raeburn 14731: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14732: ($result eq 'unknown_course') || ($result eq 'refused')) {
14733: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14734: } else {
1.541 raeburn 14735: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14736: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14737: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14738: if ($context eq 'auto') {
14739: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14740: } else {
14741: $output .= '<b>'.$result.'</b>'.$linefeed.
14742: &mt('Add to classlist').': <b>ok</b>';
14743: }
14744: $output .= $linefeed;
1.443 albertel 14745: }
14746: } else {
14747: $output = &mt('Assigning').' '.$three.' in '.$url.
14748: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14749: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14750: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14751: if ($context eq 'auto') {
14752: $output .= $result.$linefeed;
14753: } else {
14754: $output .= '<b>'.$result.'</b>'.$linefeed;
14755: }
1.443 albertel 14756: }
14757: return $output;
14758: }
14759:
14760: sub commit_studentrole {
1.1075.2.31 raeburn 14761: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14762: $credits) = @_;
1.626 raeburn 14763: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14764: if ($context eq 'auto') {
14765: $linefeed = "\n";
14766: } else {
14767: $linefeed = '<br />'."\n";
14768: }
1.443 albertel 14769: if (defined($one) && defined($two)) {
14770: my $cid=$one.'_'.$two;
14771: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14772: my $secchange = 0;
14773: my $expire_role_result;
14774: my $modify_section_result;
1.628 raeburn 14775: if ($oldsec ne '-1') {
14776: if ($oldsec ne $sec) {
1.443 albertel 14777: $secchange = 1;
1.628 raeburn 14778: my $now = time;
1.443 albertel 14779: my $uurl='/'.$cid;
14780: $uurl=~s/\_/\//g;
14781: if ($oldsec) {
14782: $uurl.='/'.$oldsec;
14783: }
1.626 raeburn 14784: $oldsecurl = $uurl;
1.628 raeburn 14785: $expire_role_result =
1.652 raeburn 14786: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14787: if ($env{'request.course.sec'} ne '') {
14788: if ($expire_role_result eq 'refused') {
14789: my @roles = ('st');
14790: my @statuses = ('previous');
14791: my @roledoms = ($one);
14792: my $withsec = 1;
14793: my %roleshash =
14794: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14795: \@statuses,\@roles,\@roledoms,$withsec);
14796: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14797: my ($oldstart,$oldend) =
14798: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14799: if ($oldend > 0 && $oldend <= $now) {
14800: $expire_role_result = 'ok';
14801: }
14802: }
14803: }
14804: }
1.443 albertel 14805: $result = $expire_role_result;
14806: }
14807: }
14808: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 14809: $modify_section_result =
14810: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14811: undef,undef,undef,$sec,
14812: $end,$start,'','',$cid,
14813: '',$context,$credits);
1.443 albertel 14814: if ($modify_section_result =~ /^ok/) {
14815: if ($secchange == 1) {
1.628 raeburn 14816: if ($sec eq '') {
14817: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14818: } else {
14819: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14820: }
1.443 albertel 14821: } elsif ($oldsec eq '-1') {
1.628 raeburn 14822: if ($sec eq '') {
14823: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14824: } else {
14825: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14826: }
1.443 albertel 14827: } else {
1.628 raeburn 14828: if ($sec eq '') {
14829: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14830: } else {
14831: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14832: }
1.443 albertel 14833: }
14834: } else {
1.628 raeburn 14835: if ($secchange) {
14836: $$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;
14837: } else {
14838: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14839: }
1.443 albertel 14840: }
14841: $result = $modify_section_result;
14842: } elsif ($secchange == 1) {
1.628 raeburn 14843: if ($oldsec eq '') {
1.1075.2.20 raeburn 14844: $$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 14845: } else {
14846: $$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;
14847: }
1.626 raeburn 14848: if ($expire_role_result eq 'refused') {
14849: my $newsecurl = '/'.$cid;
14850: $newsecurl =~ s/\_/\//g;
14851: if ($sec ne '') {
14852: $newsecurl.='/'.$sec;
14853: }
14854: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14855: if ($sec eq '') {
14856: $$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;
14857: } else {
14858: $$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;
14859: }
14860: }
14861: }
1.443 albertel 14862: }
14863: } else {
1.626 raeburn 14864: $$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 14865: $result = "error: incomplete course id\n";
14866: }
14867: return $result;
14868: }
14869:
1.1075.2.25 raeburn 14870: sub show_role_extent {
14871: my ($scope,$context,$role) = @_;
14872: $scope =~ s{^/}{};
14873: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14874: push(@courseroles,'co');
14875: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14876: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14877: $scope =~ s{/}{_};
14878: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14879: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14880: my ($audom,$auname) = split(/\//,$scope);
14881: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14882: &Apache::loncommon::plainname($auname,$audom).'</span>');
14883: } else {
14884: $scope =~ s{/$}{};
14885: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14886: &Apache::lonnet::domain($scope,'description').'</span>');
14887: }
14888: }
14889:
1.443 albertel 14890: ############################################################
14891: ############################################################
14892:
1.566 albertel 14893: sub check_clone {
1.578 raeburn 14894: my ($args,$linefeed) = @_;
1.566 albertel 14895: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14896: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14897: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14898: my $clonemsg;
14899: my $can_clone = 0;
1.944 raeburn 14900: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14901: if ($lctype ne 'community') {
14902: $lctype = 'course';
14903: }
1.566 albertel 14904: if ($clonehome eq 'no_host') {
1.944 raeburn 14905: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14906: $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'});
14907: } else {
14908: $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'});
14909: }
1.566 albertel 14910: } else {
14911: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 14912: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14913: if ($clonedesc{'type'} ne 'Community') {
14914: $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'});
14915: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14916: }
14917: }
1.1075.2.119 raeburn 14918: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 14919: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 14920: $can_clone = 1;
14921: } else {
1.1075.2.95 raeburn 14922: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 14923: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 14924: if ($clonehash{'cloners'} eq '') {
14925: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
14926: if ($domdefs{'canclone'}) {
14927: unless ($domdefs{'canclone'} eq 'none') {
14928: if ($domdefs{'canclone'} eq 'domain') {
14929: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
14930: $can_clone = 1;
14931: }
14932: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14933: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
14934: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
14935: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
14936: $can_clone = 1;
14937: }
14938: }
14939: }
1.908 raeburn 14940: }
1.1075.2.95 raeburn 14941: } else {
14942: my @cloners = split(/,/,$clonehash{'cloners'});
14943: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 14944: $can_clone = 1;
1.1075.2.95 raeburn 14945: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 14946: $can_clone = 1;
1.1075.2.96 raeburn 14947: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
14948: $can_clone = 1;
1.1075.2.95 raeburn 14949: }
14950: unless ($can_clone) {
1.1075.2.96 raeburn 14951: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14952: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 14953: my (%gotdomdefaults,%gotcodedefaults);
14954: foreach my $cloner (@cloners) {
14955: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
14956: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
14957: my (%codedefaults,@code_order);
14958: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
14959: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
14960: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
14961: }
14962: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
14963: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
14964: }
14965: } else {
14966: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
14967: \%codedefaults,
14968: \@code_order);
14969: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
14970: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
14971: }
14972: if (@code_order > 0) {
14973: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
14974: $cloner,$clonehash{'internal.coursecode'},
14975: $args->{'crscode'})) {
14976: $can_clone = 1;
14977: last;
14978: }
14979: }
14980: }
14981: }
14982: }
1.1075.2.96 raeburn 14983: }
14984: }
14985: unless ($can_clone) {
14986: my $ccrole = 'cc';
14987: if ($args->{'crstype'} eq 'Community') {
14988: $ccrole = 'co';
14989: }
14990: my %roleshash =
14991: &Apache::lonnet::get_my_roles($args->{'ccuname'},
14992: $args->{'ccdomain'},
14993: 'userroles',['active'],[$ccrole],
14994: [$args->{'clonedomain'}]);
14995: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
14996: $can_clone = 1;
14997: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
14998: $args->{'ccuname'},$args->{'ccdomain'})) {
14999: $can_clone = 1;
1.1075.2.95 raeburn 15000: }
15001: }
15002: unless ($can_clone) {
15003: if ($args->{'crstype'} eq 'Community') {
15004: $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'});
15005: } else {
15006: $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 15007: }
1.566 albertel 15008: }
1.578 raeburn 15009: }
1.566 albertel 15010: }
15011: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15012: }
15013:
1.444 albertel 15014: sub construct_course {
1.1075.2.119 raeburn 15015: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15016: $cnum,$category,$coderef) = @_;
1.444 albertel 15017: my $outcome;
1.541 raeburn 15018: my $linefeed = '<br />'."\n";
15019: if ($context eq 'auto') {
15020: $linefeed = "\n";
15021: }
1.566 albertel 15022:
15023: #
15024: # Are we cloning?
15025: #
15026: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15027: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15028: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15029: if ($context ne 'auto') {
1.578 raeburn 15030: if ($clonemsg ne '') {
15031: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15032: }
1.566 albertel 15033: }
15034: $outcome .= $clonemsg.$linefeed;
15035:
15036: if (!$can_clone) {
15037: return (0,$outcome);
15038: }
15039: }
15040:
1.444 albertel 15041: #
15042: # Open course
15043: #
15044: my $crstype = lc($args->{'crstype'});
15045: my %cenv=();
15046: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15047: $args->{'cdescr'},
15048: $args->{'curl'},
15049: $args->{'course_home'},
15050: $args->{'nonstandard'},
15051: $args->{'crscode'},
15052: $args->{'ccuname'}.':'.
15053: $args->{'ccdomain'},
1.882 raeburn 15054: $args->{'crstype'},
1.885 raeburn 15055: $cnum,$context,$category);
1.444 albertel 15056:
15057: # Note: The testing routines depend on this being output; see
15058: # Utils::Course. This needs to at least be output as a comment
15059: # if anyone ever decides to not show this, and Utils::Course::new
15060: # will need to be suitably modified.
1.541 raeburn 15061: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 15062: if ($$courseid =~ /^error:/) {
15063: return (0,$outcome);
15064: }
15065:
1.444 albertel 15066: #
15067: # Check if created correctly
15068: #
1.479 albertel 15069: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15070: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15071: if ($crsuhome eq 'no_host') {
15072: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15073: return (0,$outcome);
15074: }
1.541 raeburn 15075: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15076:
1.444 albertel 15077: #
1.566 albertel 15078: # Do the cloning
15079: #
15080: if ($can_clone && $cloneid) {
15081: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
15082: if ($context ne 'auto') {
15083: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15084: }
15085: $outcome .= $clonemsg.$linefeed;
15086: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15087: # Copy all files
1.637 www 15088: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15089: # Restore URL
1.566 albertel 15090: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15091: # Restore title
1.566 albertel 15092: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15093: # Restore creation date, creator and creation context.
15094: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15095: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15096: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15097: # Mark as cloned
1.566 albertel 15098: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15099: # Need to clone grading mode
15100: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15101: $cenv{'grading'}=$newenv{'grading'};
15102: # Do not clone these environment entries
15103: &Apache::lonnet::del('environment',
15104: ['default_enrollment_start_date',
15105: 'default_enrollment_end_date',
15106: 'question.email',
15107: 'policy.email',
15108: 'comment.email',
15109: 'pch.users.denied',
1.725 raeburn 15110: 'plc.users.denied',
15111: 'hidefromcat',
1.1075.2.36 raeburn 15112: 'checkforpriv',
1.1075.2.59 raeburn 15113: 'categories',
15114: 'internal.uniquecode'],
1.638 www 15115: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 15116: if ($args->{'textbook'}) {
15117: $cenv{'internal.textbook'} = $args->{'textbook'};
15118: }
1.444 albertel 15119: }
1.566 albertel 15120:
1.444 albertel 15121: #
15122: # Set environment (will override cloned, if existing)
15123: #
15124: my @sections = ();
15125: my @xlists = ();
15126: if ($args->{'crstype'}) {
15127: $cenv{'type'}=$args->{'crstype'};
15128: }
15129: if ($args->{'crsid'}) {
15130: $cenv{'courseid'}=$args->{'crsid'};
15131: }
15132: if ($args->{'crscode'}) {
15133: $cenv{'internal.coursecode'}=$args->{'crscode'};
15134: }
15135: if ($args->{'crsquota'} ne '') {
15136: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15137: } else {
15138: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15139: }
15140: if ($args->{'ccuname'}) {
15141: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15142: ':'.$args->{'ccdomain'};
15143: } else {
15144: $cenv{'internal.courseowner'} = $args->{'curruser'};
15145: }
1.1075.2.31 raeburn 15146: if ($args->{'defaultcredits'}) {
15147: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15148: }
1.444 albertel 15149: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15150: if ($args->{'crssections'}) {
15151: $cenv{'internal.sectionnums'} = '';
15152: if ($args->{'crssections'} =~ m/,/) {
15153: @sections = split/,/,$args->{'crssections'};
15154: } else {
15155: $sections[0] = $args->{'crssections'};
15156: }
15157: if (@sections > 0) {
15158: foreach my $item (@sections) {
15159: my ($sec,$gp) = split/:/,$item;
15160: my $class = $args->{'crscode'}.$sec;
15161: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15162: $cenv{'internal.sectionnums'} .= $item.',';
15163: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15164: push(@badclasses,$class);
1.444 albertel 15165: }
15166: }
15167: $cenv{'internal.sectionnums'} =~ s/,$//;
15168: }
15169: }
15170: # do not hide course coordinator from staff listing,
15171: # even if privileged
15172: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15173: # add course coordinator's domain to domains to check for privileged users
15174: # if different to course domain
15175: if ($$crsudom ne $args->{'ccdomain'}) {
15176: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15177: }
1.444 albertel 15178: # add crosslistings
15179: if ($args->{'crsxlist'}) {
15180: $cenv{'internal.crosslistings'}='';
15181: if ($args->{'crsxlist'} =~ m/,/) {
15182: @xlists = split/,/,$args->{'crsxlist'};
15183: } else {
15184: $xlists[0] = $args->{'crsxlist'};
15185: }
15186: if (@xlists > 0) {
15187: foreach my $item (@xlists) {
15188: my ($xl,$gp) = split/:/,$item;
15189: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15190: $cenv{'internal.crosslistings'} .= $item.',';
15191: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15192: push(@badclasses,$xl);
1.444 albertel 15193: }
15194: }
15195: $cenv{'internal.crosslistings'} =~ s/,$//;
15196: }
15197: }
15198: if ($args->{'autoadds'}) {
15199: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15200: }
15201: if ($args->{'autodrops'}) {
15202: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15203: }
15204: # check for notification of enrollment changes
15205: my @notified = ();
15206: if ($args->{'notify_owner'}) {
15207: if ($args->{'ccuname'} ne '') {
15208: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15209: }
15210: }
15211: if ($args->{'notify_dc'}) {
15212: if ($uname ne '') {
1.630 raeburn 15213: push(@notified,$uname.':'.$udom);
1.444 albertel 15214: }
15215: }
15216: if (@notified > 0) {
15217: my $notifylist;
15218: if (@notified > 1) {
15219: $notifylist = join(',',@notified);
15220: } else {
15221: $notifylist = $notified[0];
15222: }
15223: $cenv{'internal.notifylist'} = $notifylist;
15224: }
15225: if (@badclasses > 0) {
15226: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15227: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15228: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15229: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15230: );
1.1075.2.119 raeburn 15231: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15232: &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 15233: if ($context eq 'auto') {
15234: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15235: } else {
1.566 albertel 15236: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15237: }
15238: foreach my $item (@badclasses) {
1.541 raeburn 15239: if ($context eq 'auto') {
1.1075.2.119 raeburn 15240: $outcome .= " - $item\n";
1.541 raeburn 15241: } else {
1.1075.2.119 raeburn 15242: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15243: }
1.1075.2.119 raeburn 15244: }
15245: if ($context eq 'auto') {
15246: $outcome .= $linefeed;
15247: } else {
15248: $outcome .= "</ul><br /><br /></div>\n";
15249: }
1.444 albertel 15250: }
15251: if ($args->{'no_end_date'}) {
15252: $args->{'endaccess'} = 0;
15253: }
15254: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15255: $cenv{'internal.autoend'}=$args->{'enrollend'};
15256: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15257: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15258: if ($args->{'showphotos'}) {
15259: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15260: }
15261: $cenv{'internal.authtype'} = $args->{'authtype'};
15262: $cenv{'internal.autharg'} = $args->{'autharg'};
15263: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15264: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15265: 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');
15266: if ($context eq 'auto') {
15267: $outcome .= $krb_msg;
15268: } else {
1.566 albertel 15269: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15270: }
15271: $outcome .= $linefeed;
1.444 albertel 15272: }
15273: }
15274: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15275: if ($args->{'setpolicy'}) {
15276: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15277: }
15278: if ($args->{'setcontent'}) {
15279: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15280: }
1.1075.2.110 raeburn 15281: if ($args->{'setcomment'}) {
15282: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15283: }
1.444 albertel 15284: }
15285: if ($args->{'reshome'}) {
15286: $cenv{'reshome'}=$args->{'reshome'}.'/';
15287: $cenv{'reshome'}=~s/\/+$/\//;
15288: }
15289: #
15290: # course has keyed access
15291: #
15292: if ($args->{'setkeys'}) {
15293: $cenv{'keyaccess'}='yes';
15294: }
15295: # if specified, key authority is not course, but user
15296: # only active if keyaccess is yes
15297: if ($args->{'keyauth'}) {
1.487 albertel 15298: my ($user,$domain) = split(':',$args->{'keyauth'});
15299: $user = &LONCAPA::clean_username($user);
15300: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15301: if ($user ne '' && $domain ne '') {
1.487 albertel 15302: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15303: }
15304: }
15305:
1.1075.2.59 raeburn 15306: #
15307: # generate and store uniquecode (available to course requester), if course should have one.
15308: #
15309: if ($args->{'uniquecode'}) {
15310: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15311: if ($code) {
15312: $cenv{'internal.uniquecode'} = $code;
15313: my %crsinfo =
15314: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15315: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15316: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15317: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15318: }
15319: if (ref($coderef)) {
15320: $$coderef = $code;
15321: }
15322: }
15323: }
15324:
1.444 albertel 15325: if ($args->{'disresdis'}) {
15326: $cenv{'pch.roles.denied'}='st';
15327: }
15328: if ($args->{'disablechat'}) {
15329: $cenv{'plc.roles.denied'}='st';
15330: }
15331:
15332: # Record we've not yet viewed the Course Initialization Helper for this
15333: # course
15334: $cenv{'course.helper.not.run'} = 1;
15335: #
15336: # Use new Randomseed
15337: #
15338: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15339: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15340: #
15341: # The encryption code and receipt prefix for this course
15342: #
15343: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15344: $cenv{'internal.encpref'}=100+int(9*rand(99));
15345: #
15346: # By default, use standard grading
15347: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15348:
1.541 raeburn 15349: $outcome .= $linefeed.&mt('Setting environment').': '.
15350: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15351: #
15352: # Open all assignments
15353: #
15354: if ($args->{'openall'}) {
15355: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15356: my %storecontent = ($storeunder => time,
15357: $storeunder.'.type' => 'date_start');
15358:
15359: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15360: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15361: }
15362: #
15363: # Set first page
15364: #
15365: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15366: || ($cloneid)) {
1.445 albertel 15367: use LONCAPA::map;
1.444 albertel 15368: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15369:
15370: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15371: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15372:
1.444 albertel 15373: $outcome .= ($fatal?$errtext:'read ok').' - ';
15374: my $title; my $url;
15375: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15376: $title=&mt('Syllabus');
1.444 albertel 15377: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15378: } else {
1.963 raeburn 15379: $title=&mt('Table of Contents');
1.444 albertel 15380: $url='/adm/navmaps';
15381: }
1.445 albertel 15382:
15383: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15384: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15385:
15386: if ($errtext) { $fatal=2; }
1.541 raeburn 15387: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15388: }
1.566 albertel 15389:
15390: return (1,$outcome);
1.444 albertel 15391: }
15392:
1.1075.2.59 raeburn 15393: sub make_unique_code {
15394: my ($cdom,$cnum) = @_;
15395: # get lock on uniquecodes db
15396: my $lockhash = {
15397: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15398: ':'.$env{'user.domain'},
15399: };
15400: my $tries = 0;
15401: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15402: my ($code,$error);
15403:
15404: while (($gotlock ne 'ok') && ($tries<3)) {
15405: $tries ++;
15406: sleep 1;
15407: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15408: }
15409: if ($gotlock eq 'ok') {
15410: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15411: my $gotcode;
15412: my $attempts = 0;
15413: while ((!$gotcode) && ($attempts < 100)) {
15414: $code = &generate_code();
15415: if (!exists($currcodes{$code})) {
15416: $gotcode = 1;
15417: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15418: $error = 'nostore';
15419: }
15420: }
15421: $attempts ++;
15422: }
15423: my @del_lock = ($cnum."\0".'uniquecodes');
15424: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15425: } else {
15426: $error = 'nolock';
15427: }
15428: return ($code,$error);
15429: }
15430:
15431: sub generate_code {
15432: my $code;
15433: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15434: for (my $i=0; $i<6; $i++) {
15435: my $lettnum = int (rand 2);
15436: my $item = '';
15437: if ($lettnum) {
15438: $item = $letts[int( rand(18) )];
15439: } else {
15440: $item = 1+int( rand(8) );
15441: }
15442: $code .= $item;
15443: }
15444: return $code;
15445: }
15446:
1.444 albertel 15447: ############################################################
15448: ############################################################
15449:
1.953 droeschl 15450: #SD
15451: # only Community and Course, or anything else?
1.378 raeburn 15452: sub course_type {
15453: my ($cid) = @_;
15454: if (!defined($cid)) {
15455: $cid = $env{'request.course.id'};
15456: }
1.404 albertel 15457: if (defined($env{'course.'.$cid.'.type'})) {
15458: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15459: } else {
15460: return 'Course';
1.377 raeburn 15461: }
15462: }
1.156 albertel 15463:
1.406 raeburn 15464: sub group_term {
15465: my $crstype = &course_type();
15466: my %names = (
15467: 'Course' => 'group',
1.865 raeburn 15468: 'Community' => 'group',
1.406 raeburn 15469: );
15470: return $names{$crstype};
15471: }
15472:
1.902 raeburn 15473: sub course_types {
1.1075.2.59 raeburn 15474: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15475: my %typename = (
15476: official => 'Official course',
15477: unofficial => 'Unofficial course',
15478: community => 'Community',
1.1075.2.59 raeburn 15479: textbook => 'Textbook course',
1.902 raeburn 15480: );
15481: return (\@types,\%typename);
15482: }
15483:
1.156 albertel 15484: sub icon {
15485: my ($file)=@_;
1.505 albertel 15486: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15487: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15488: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15489: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15490: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15491: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15492: $curfext.".gif") {
15493: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15494: $curfext.".gif";
15495: }
15496: }
1.249 albertel 15497: return &lonhttpdurl($iconname);
1.154 albertel 15498: }
1.84 albertel 15499:
1.575 albertel 15500: sub lonhttpdurl {
1.692 www 15501: #
15502: # Had been used for "small fry" static images on separate port 8080.
15503: # Modify here if lightweight http functionality desired again.
15504: # Currently eliminated due to increasing firewall issues.
15505: #
1.575 albertel 15506: my ($url)=@_;
1.692 www 15507: return $url;
1.215 albertel 15508: }
15509:
1.213 albertel 15510: sub connection_aborted {
15511: my ($r)=@_;
15512: $r->print(" ");$r->rflush();
15513: my $c = $r->connection;
15514: return $c->aborted();
15515: }
15516:
1.221 foxr 15517: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15518: # strings as 'strings'.
15519: sub escape_single {
1.221 foxr 15520: my ($input) = @_;
1.223 albertel 15521: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15522: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15523: return $input;
15524: }
1.223 albertel 15525:
1.222 foxr 15526: # Same as escape_single, but escape's "'s This
15527: # can be used for "strings"
15528: sub escape_double {
15529: my ($input) = @_;
15530: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15531: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15532: return $input;
15533: }
1.223 albertel 15534:
1.222 foxr 15535: # Escapes the last element of a full URL.
15536: sub escape_url {
15537: my ($url) = @_;
1.238 raeburn 15538: my @urlslices = split(/\//, $url,-1);
1.369 www 15539: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15540: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15541: }
1.462 albertel 15542:
1.820 raeburn 15543: sub compare_arrays {
15544: my ($arrayref1,$arrayref2) = @_;
15545: my (@difference,%count);
15546: @difference = ();
15547: %count = ();
15548: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15549: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15550: foreach my $element (keys(%count)) {
15551: if ($count{$element} == 1) {
15552: push(@difference,$element);
15553: }
15554: }
15555: }
15556: return @difference;
15557: }
15558:
1.817 bisitz 15559: # -------------------------------------------------------- Initialize user login
1.462 albertel 15560: sub init_user_environment {
1.463 albertel 15561: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15562: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15563:
15564: my $public=($username eq 'public' && $domain eq 'public');
15565:
15566: # See if old ID present, if so, remove
15567:
1.1062 raeburn 15568: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15569: my $now=time;
15570:
15571: if ($public) {
15572: my $max_public=100;
15573: my $oldest;
15574: my $oldest_time=0;
15575: for(my $next=1;$next<=$max_public;$next++) {
15576: if (-e $lonids."/publicuser_$next.id") {
15577: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15578: if ($mtime<$oldest_time || !$oldest_time) {
15579: $oldest_time=$mtime;
15580: $oldest=$next;
15581: }
15582: } else {
15583: $cookie="publicuser_$next";
15584: last;
15585: }
15586: }
15587: if (!$cookie) { $cookie="publicuser_$oldest"; }
15588: } else {
1.463 albertel 15589: # if this isn't a robot, kill any existing non-robot sessions
15590: if (!$args->{'robot'}) {
15591: opendir(DIR,$lonids);
15592: while ($filename=readdir(DIR)) {
15593: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 15594: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
15595: &GDBM_READER(),0640)) {
15596: my $linkedfile;
15597: if (exists($oldenv{'user.linkedenv'})) {
15598: $linkedfile = $oldenv{'user.linkedenv'};
15599: }
15600: untie(%oldenv);
15601: if (unlink("$lonids/$filename")) {
15602: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
15603: if (-l "$lonids/$linkedfile.id") {
15604: unlink("$lonids/$linkedfile.id");
15605: }
15606: }
15607: }
15608: } else {
15609: unlink($lonids.'/'.$filename);
15610: }
1.463 albertel 15611: }
1.462 albertel 15612: }
1.463 albertel 15613: closedir(DIR);
1.1075.2.84 raeburn 15614: # If there is a undeleted lockfile for the user's paste buffer remove it.
15615: my $namespace = 'nohist_courseeditor';
15616: my $lockingkey = 'paste'."\0".'locked_num';
15617: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15618: $domain,$username);
15619: if (exists($lockhash{$lockingkey})) {
15620: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15621: unless ($delresult eq 'ok') {
15622: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15623: }
15624: }
1.462 albertel 15625: }
15626: # Give them a new cookie
1.463 albertel 15627: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15628: : $now.$$.int(rand(10000)));
1.463 albertel 15629: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15630:
15631: # Initialize roles
15632:
1.1062 raeburn 15633: ($userroles,$firstaccenv,$timerintenv) =
15634: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15635: }
15636: # ------------------------------------ Check browser type and MathML capability
15637:
1.1075.2.77 raeburn 15638: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15639: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15640:
15641: # ------------------------------------------------------------- Get environment
15642:
15643: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15644: my ($tmp) = keys(%userenv);
15645: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15646: } else {
15647: undef(%userenv);
15648: }
15649: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15650: $form->{'interface'}=$userenv{'interface'};
15651: }
15652: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15653:
15654: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15655: foreach my $option ('interface','localpath','localres') {
15656: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15657: }
15658: # --------------------------------------------------------- Write first profile
15659:
15660: {
15661: my %initial_env =
15662: ("user.name" => $username,
15663: "user.domain" => $domain,
15664: "user.home" => $authhost,
15665: "browser.type" => $clientbrowser,
15666: "browser.version" => $clientversion,
15667: "browser.mathml" => $clientmathml,
15668: "browser.unicode" => $clientunicode,
15669: "browser.os" => $clientos,
1.1075.2.42 raeburn 15670: "browser.mobile" => $clientmobile,
15671: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 15672: "browser.osversion" => $clientosversion,
1.462 albertel 15673: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15674: "request.course.fn" => '',
15675: "request.course.uri" => '',
15676: "request.course.sec" => '',
15677: "request.role" => 'cm',
15678: "request.role.adv" => $env{'user.adv'},
15679: "request.host" => $ENV{'REMOTE_ADDR'},);
15680:
15681: if ($form->{'localpath'}) {
15682: $initial_env{"browser.localpath"} = $form->{'localpath'};
15683: $initial_env{"browser.localres"} = $form->{'localres'};
15684: }
15685:
15686: if ($form->{'interface'}) {
15687: $form->{'interface'}=~s/\W//gs;
15688: $initial_env{"browser.interface"} = $form->{'interface'};
15689: $env{'browser.interface'}=$form->{'interface'};
15690: }
15691:
1.1075.2.54 raeburn 15692: if ($form->{'iptoken'}) {
15693: my $lonhost = $r->dir_config('lonHostID');
15694: $initial_env{"user.noloadbalance"} = $lonhost;
15695: $env{'user.noloadbalance'} = $lonhost;
15696: }
15697:
1.1075.2.120 raeburn 15698: if ($form->{'noloadbalance'}) {
15699: my @hosts = &Apache::lonnet::current_machine_ids();
15700: my $hosthere = $form->{'noloadbalance'};
15701: if (grep(/^\Q$hosthere\E$/,@hosts)) {
15702: $initial_env{"user.noloadbalance"} = $hosthere;
15703: $env{'user.noloadbalance'} = $hosthere;
15704: }
15705: }
15706:
1.1016 raeburn 15707: unless ($domain eq 'public') {
1.1075.2.125 raeburn 15708: my %is_adv = ( is_adv => $env{'user.adv'} );
15709: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 15710:
1.1075.2.125 raeburn 15711: foreach my $tool ('aboutme','blog','webdav','portfolio') {
15712: $userenv{'availabletools.'.$tool} =
15713: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15714: undef,\%userenv,\%domdef,\%is_adv);
15715: }
1.724 raeburn 15716:
1.1075.2.125 raeburn 15717: foreach my $crstype ('official','unofficial','community','textbook') {
15718: $userenv{'canrequest.'.$crstype} =
15719: &Apache::lonnet::usertools_access($username,$domain,$crstype,
15720: 'reload','requestcourses',
15721: \%userenv,\%domdef,\%is_adv);
15722: }
1.765 raeburn 15723:
1.1075.2.125 raeburn 15724: $userenv{'canrequest.author'} =
15725: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15726: 'reload','requestauthor',
15727: \%userenv,\%domdef,\%is_adv);
15728: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15729: $domain,$username);
15730: my $reqstatus = $reqauthor{'author_status'};
15731: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15732: if (ref($reqauthor{'author'}) eq 'HASH') {
15733: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15734: $reqauthor{'author'}{'timestamp'};
15735: }
1.1075.2.14 raeburn 15736: }
15737: }
15738:
1.462 albertel 15739: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15740:
1.462 albertel 15741: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15742: &GDBM_WRCREAT(),0640)) {
15743: &_add_to_env(\%disk_env,\%initial_env);
15744: &_add_to_env(\%disk_env,\%userenv,'environment.');
15745: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15746: if (ref($firstaccenv) eq 'HASH') {
15747: &_add_to_env(\%disk_env,$firstaccenv);
15748: }
15749: if (ref($timerintenv) eq 'HASH') {
15750: &_add_to_env(\%disk_env,$timerintenv);
15751: }
1.463 albertel 15752: if (ref($args->{'extra_env'})) {
15753: &_add_to_env(\%disk_env,$args->{'extra_env'});
15754: }
1.462 albertel 15755: untie(%disk_env);
15756: } else {
1.705 tempelho 15757: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15758: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15759: return 'error: '.$!;
15760: }
15761: }
15762: $env{'request.role'}='cm';
15763: $env{'request.role.adv'}=$env{'user.adv'};
15764: $env{'browser.type'}=$clientbrowser;
15765:
15766: return $cookie;
15767:
15768: }
15769:
15770: sub _add_to_env {
15771: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15772: if (ref($env_data) eq 'HASH') {
15773: while (my ($key,$value) = each(%$env_data)) {
15774: $idf->{$prefix.$key} = $value;
15775: $env{$prefix.$key} = $value;
15776: }
1.462 albertel 15777: }
15778: }
15779:
1.685 tempelho 15780: # --- Get the symbolic name of a problem and the url
15781: sub get_symb {
15782: my ($request,$silent) = @_;
1.726 raeburn 15783: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15784: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15785: if ($symb eq '') {
15786: if (!$silent) {
1.1071 raeburn 15787: if (ref($request)) {
15788: $request->print("Unable to handle ambiguous references:$url:.");
15789: }
1.685 tempelho 15790: return ();
15791: }
15792: }
15793: &Apache::lonenc::check_decrypt(\$symb);
15794: return ($symb);
15795: }
15796:
15797: # --------------------------------------------------------------Get annotation
15798:
15799: sub get_annotation {
15800: my ($symb,$enc) = @_;
15801:
15802: my $key = $symb;
15803: if (!$enc) {
15804: $key =
15805: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15806: }
15807: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15808: return $annotation{$key};
15809: }
15810:
15811: sub clean_symb {
1.731 raeburn 15812: my ($symb,$delete_enc) = @_;
1.685 tempelho 15813:
15814: &Apache::lonenc::check_decrypt(\$symb);
15815: my $enc = $env{'request.enc'};
1.731 raeburn 15816: if ($delete_enc) {
1.730 raeburn 15817: delete($env{'request.enc'});
15818: }
1.685 tempelho 15819:
15820: return ($symb,$enc);
15821: }
1.462 albertel 15822:
1.1075.2.69 raeburn 15823: ############################################################
15824: ############################################################
15825:
15826: =pod
15827:
15828: =head1 Routines for building display used to search for courses
15829:
15830:
15831: =over 4
15832:
15833: =item * &build_filters()
15834:
15835: Create markup for a table used to set filters to use when selecting
15836: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15837: and quotacheck.pl
15838:
15839:
15840: Inputs:
15841:
15842: filterlist - anonymous array of fields to include as potential filters
15843:
15844: crstype - course type
15845:
15846: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15847: to pop-open a course selector (will contain "extra element").
15848:
15849: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15850:
15851: filter - anonymous hash of criteria and their values
15852:
15853: action - form action
15854:
15855: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15856:
15857: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
15858:
15859: cloneruname - username of owner of new course who wants to clone
15860:
15861: clonerudom - domain of owner of new course who wants to clone
15862:
15863: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15864:
15865: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15866:
15867: codedom - domain
15868:
15869: formname - value of form element named "form".
15870:
15871: fixeddom - domain, if fixed.
15872:
15873: prevphase - value to assign to form element named "phase" when going back to the previous screen
15874:
15875: cnameelement - name of form element in form on opener page which will receive title of selected course
15876:
15877: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15878:
15879: cdomelement - name of form element in form on opener page which will receive domain of selected course
15880:
15881: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15882:
15883: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
15884:
15885: clonewarning - warning message about missing information for intended course owner when DC creates a course
15886:
15887:
15888: Returns: $output - HTML for display of search criteria, and hidden form elements.
15889:
15890:
15891: Side Effects: None
15892:
15893: =cut
15894:
15895: # ---------------------------------------------- search for courses based on last activity etc.
15896:
15897: sub build_filters {
15898: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
15899: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
15900: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
15901: $cnameelement,$cnumelement,$cdomelement,$setroles,
15902: $clonetext,$clonewarning) = @_;
15903: my ($list,$jscript);
15904: my $onchange = 'javascript:updateFilters(this)';
15905: my ($domainselectform,$sincefilterform,$createdfilterform,
15906: $ownerdomselectform,$persondomselectform,$instcodeform,
15907: $typeselectform,$instcodetitle);
15908: if ($formname eq '') {
15909: $formname = $caller;
15910: }
15911: foreach my $item (@{$filterlist}) {
15912: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
15913: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
15914: if ($item eq 'domainfilter') {
15915: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
15916: } elsif ($item eq 'coursefilter') {
15917: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
15918: } elsif ($item eq 'ownerfilter') {
15919: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15920: } elsif ($item eq 'ownerdomfilter') {
15921: $filter->{'ownerdomfilter'} =
15922: &LONCAPA::clean_domain($filter->{$item});
15923: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
15924: 'ownerdomfilter',1);
15925: } elsif ($item eq 'personfilter') {
15926: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15927: } elsif ($item eq 'persondomfilter') {
15928: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
15929: 'persondomfilter',1);
15930: } else {
15931: $filter->{$item} =~ s/\W//g;
15932: }
15933: if (!$filter->{$item}) {
15934: $filter->{$item} = '';
15935: }
15936: }
15937: if ($item eq 'domainfilter') {
15938: my $allow_blank = 1;
15939: if ($formname eq 'portform') {
15940: $allow_blank=0;
15941: } elsif ($formname eq 'studentform') {
15942: $allow_blank=0;
15943: }
15944: if ($fixeddom) {
15945: $domainselectform = '<input type="hidden" name="domainfilter"'.
15946: ' value="'.$codedom.'" />'.
15947: &Apache::lonnet::domain($codedom,'description');
15948: } else {
15949: $domainselectform = &select_dom_form($filter->{$item},
15950: 'domainfilter',
15951: $allow_blank,'',$onchange);
15952: }
15953: } else {
15954: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
15955: }
15956: }
15957:
15958: # last course activity filter and selection
15959: $sincefilterform = &timebased_select_form('sincefilter',$filter);
15960:
15961: # course created filter and selection
15962: if (exists($filter->{'createdfilter'})) {
15963: $createdfilterform = &timebased_select_form('createdfilter',$filter);
15964: }
15965:
15966: my %lt = &Apache::lonlocal::texthash(
15967: 'cac' => "$crstype Activity",
15968: 'ccr' => "$crstype Created",
15969: 'cde' => "$crstype Title",
15970: 'cdo' => "$crstype Domain",
15971: 'ins' => 'Institutional Code',
15972: 'inc' => 'Institutional Categorization',
15973: 'cow' => "$crstype Owner/Co-owner",
15974: 'cop' => "$crstype Personnel Includes",
15975: 'cog' => 'Type',
15976: );
15977:
15978: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15979: my $typeval = 'Course';
15980: if ($crstype eq 'Community') {
15981: $typeval = 'Community';
15982: }
15983: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
15984: } else {
15985: $typeselectform = '<select name="type" size="1"';
15986: if ($onchange) {
15987: $typeselectform .= ' onchange="'.$onchange.'"';
15988: }
15989: $typeselectform .= '>'."\n";
15990: foreach my $posstype ('Course','Community') {
15991: $typeselectform.='<option value="'.$posstype.'"'.
15992: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
15993: }
15994: $typeselectform.="</select>";
15995: }
15996:
15997: my ($cloneableonlyform,$cloneabletitle);
15998: if (exists($filter->{'cloneableonly'})) {
15999: my $cloneableon = '';
16000: my $cloneableoff = ' checked="checked"';
16001: if ($filter->{'cloneableonly'}) {
16002: $cloneableon = $cloneableoff;
16003: $cloneableoff = '';
16004: }
16005: $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>';
16006: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 16007: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 16008: } else {
16009: $cloneabletitle = &mt('Cloneable by you');
16010: }
16011: }
16012: my $officialjs;
16013: if ($crstype eq 'Course') {
16014: if (exists($filter->{'instcodefilter'})) {
16015: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16016: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16017: if ($codedom) {
16018: $officialjs = 1;
16019: ($instcodeform,$jscript,$$numtitlesref) =
16020: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16021: $officialjs,$codetitlesref);
16022: if ($jscript) {
16023: $jscript = '<script type="text/javascript">'."\n".
16024: '// <![CDATA['."\n".
16025: $jscript."\n".
16026: '// ]]>'."\n".
16027: '</script>'."\n";
16028: }
16029: }
16030: if ($instcodeform eq '') {
16031: $instcodeform =
16032: '<input type="text" name="instcodefilter" size="10" value="'.
16033: $list->{'instcodefilter'}.'" />';
16034: $instcodetitle = $lt{'ins'};
16035: } else {
16036: $instcodetitle = $lt{'inc'};
16037: }
16038: if ($fixeddom) {
16039: $instcodetitle .= '<br />('.$codedom.')';
16040: }
16041: }
16042: }
16043: my $output = qq|
16044: <form method="post" name="filterpicker" action="$action">
16045: <input type="hidden" name="form" value="$formname" />
16046: |;
16047: if ($formname eq 'modifycourse') {
16048: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16049: '<input type="hidden" name="prevphase" value="'.
16050: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 16051: } elsif ($formname eq 'quotacheck') {
16052: $output .= qq|
16053: <input type="hidden" name="sortby" value="" />
16054: <input type="hidden" name="sortorder" value="" />
16055: |;
16056: } else {
1.1075.2.69 raeburn 16057: my $name_input;
16058: if ($cnameelement ne '') {
16059: $name_input = '<input type="hidden" name="cnameelement" value="'.
16060: $cnameelement.'" />';
16061: }
16062: $output .= qq|
16063: <input type="hidden" name="cnumelement" value="$cnumelement" />
16064: <input type="hidden" name="cdomelement" value="$cdomelement" />
16065: $name_input
16066: $roleelement
16067: $multelement
16068: $typeelement
16069: |;
16070: if ($formname eq 'portform') {
16071: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16072: }
16073: }
16074: if ($fixeddom) {
16075: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16076: }
16077: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16078: if ($sincefilterform) {
16079: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16080: .$sincefilterform
16081: .&Apache::lonhtmlcommon::row_closure();
16082: }
16083: if ($createdfilterform) {
16084: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16085: .$createdfilterform
16086: .&Apache::lonhtmlcommon::row_closure();
16087: }
16088: if ($domainselectform) {
16089: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16090: .$domainselectform
16091: .&Apache::lonhtmlcommon::row_closure();
16092: }
16093: if ($typeselectform) {
16094: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16095: $output .= $typeselectform;
16096: } else {
16097: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16098: .$typeselectform
16099: .&Apache::lonhtmlcommon::row_closure();
16100: }
16101: }
16102: if ($instcodeform) {
16103: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16104: .$instcodeform
16105: .&Apache::lonhtmlcommon::row_closure();
16106: }
16107: if (exists($filter->{'ownerfilter'})) {
16108: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16109: '<table><tr><td>'.&mt('Username').'<br />'.
16110: '<input type="text" name="ownerfilter" size="20" value="'.
16111: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16112: $ownerdomselectform.'</td></tr></table>'.
16113: &Apache::lonhtmlcommon::row_closure();
16114: }
16115: if (exists($filter->{'personfilter'})) {
16116: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16117: '<table><tr><td>'.&mt('Username').'<br />'.
16118: '<input type="text" name="personfilter" size="20" value="'.
16119: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16120: $persondomselectform.'</td></tr></table>'.
16121: &Apache::lonhtmlcommon::row_closure();
16122: }
16123: if (exists($filter->{'coursefilter'})) {
16124: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16125: .'<input type="text" name="coursefilter" size="25" value="'
16126: .$list->{'coursefilter'}.'" />'
16127: .&Apache::lonhtmlcommon::row_closure();
16128: }
16129: if ($cloneableonlyform) {
16130: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16131: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16132: }
16133: if (exists($filter->{'descriptfilter'})) {
16134: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16135: .'<input type="text" name="descriptfilter" size="40" value="'
16136: .$list->{'descriptfilter'}.'" />'
16137: .&Apache::lonhtmlcommon::row_closure(1);
16138: }
16139: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16140: '<input type="hidden" name="updater" value="" />'."\n".
16141: '<input type="submit" name="gosearch" value="'.
16142: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16143: return $jscript.$clonewarning.$output;
16144: }
16145:
16146: =pod
16147:
16148: =item * &timebased_select_form()
16149:
16150: Create markup for a dropdown list used to select a time-based
16151: filter e.g., Course Activity, Course Created, when searching for courses
16152: or communities
16153:
16154: Inputs:
16155:
16156: item - name of form element (sincefilter or createdfilter)
16157:
16158: filter - anonymous hash of criteria and their values
16159:
16160: Returns: HTML for a select box contained a blank, then six time selections,
16161: with value set in incoming form variables currently selected.
16162:
16163: Side Effects: None
16164:
16165: =cut
16166:
16167: sub timebased_select_form {
16168: my ($item,$filter) = @_;
16169: if (ref($filter) eq 'HASH') {
16170: $filter->{$item} =~ s/[^\d-]//g;
16171: if (!$filter->{$item}) { $filter->{$item}=-1; }
16172: return &select_form(
16173: $filter->{$item},
16174: $item,
16175: { '-1' => '',
16176: '86400' => &mt('today'),
16177: '604800' => &mt('last week'),
16178: '2592000' => &mt('last month'),
16179: '7776000' => &mt('last three months'),
16180: '15552000' => &mt('last six months'),
16181: '31104000' => &mt('last year'),
16182: 'select_form_order' =>
16183: ['-1','86400','604800','2592000','7776000',
16184: '15552000','31104000']});
16185: }
16186: }
16187:
16188: =pod
16189:
16190: =item * &js_changer()
16191:
16192: Create script tag containing Javascript used to submit course search form
16193: when course type or domain is changed, and also to hide 'Searching ...' on
16194: page load completion for page showing search result.
16195:
16196: Inputs: None
16197:
16198: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16199:
16200: Side Effects: None
16201:
16202: =cut
16203:
16204: sub js_changer {
16205: return <<ENDJS;
16206: <script type="text/javascript">
16207: // <![CDATA[
16208: function updateFilters(caller) {
16209: if (typeof(caller) != "undefined") {
16210: document.filterpicker.updater.value = caller.name;
16211: }
16212: document.filterpicker.submit();
16213: }
16214:
16215: function hideSearching() {
16216: if (document.getElementById('searching')) {
16217: document.getElementById('searching').style.display = 'none';
16218: }
16219: return;
16220: }
16221:
16222: // ]]>
16223: </script>
16224:
16225: ENDJS
16226: }
16227:
16228: =pod
16229:
16230: =item * &search_courses()
16231:
16232: Process selected filters form course search form and pass to lonnet::courseiddump
16233: to retrieve a hash for which keys are courseIDs which match the selected filters.
16234:
16235: Inputs:
16236:
16237: dom - domain being searched
16238:
16239: type - course type ('Course' or 'Community' or '.' if any).
16240:
16241: filter - anonymous hash of criteria and their values
16242:
16243: numtitles - for institutional codes - number of categories
16244:
16245: cloneruname - optional username of new course owner
16246:
16247: clonerudom - optional domain of new course owner
16248:
1.1075.2.95 raeburn 16249: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16250: (used when DC is using course creation form)
16251:
16252: codetitles - reference to array of titles of components in institutional codes (official courses).
16253:
1.1075.2.95 raeburn 16254: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16255: (and so can clone automatically)
16256:
16257: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16258:
16259: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16260: courses to clone
1.1075.2.69 raeburn 16261:
16262: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16263:
16264:
16265: Side Effects: None
16266:
16267: =cut
16268:
16269:
16270: sub search_courses {
1.1075.2.95 raeburn 16271: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16272: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16273: my (%courses,%showcourses,$cloner);
16274: if (($filter->{'ownerfilter'} ne '') ||
16275: ($filter->{'ownerdomfilter'} ne '')) {
16276: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16277: $filter->{'ownerdomfilter'};
16278: }
16279: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16280: if (!$filter->{$item}) {
16281: $filter->{$item}='.';
16282: }
16283: }
16284: my $now = time;
16285: my $timefilter =
16286: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16287: my ($createdbefore,$createdafter);
16288: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16289: $createdbefore = $now;
16290: $createdafter = $now-$filter->{'createdfilter'};
16291: }
16292: my ($instcodefilter,$regexpok);
16293: if ($numtitles) {
16294: if ($env{'form.official'} eq 'on') {
16295: $instcodefilter =
16296: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16297: $regexpok = 1;
16298: } elsif ($env{'form.official'} eq 'off') {
16299: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16300: unless ($instcodefilter eq '') {
16301: $regexpok = -1;
16302: }
16303: }
16304: } else {
16305: $instcodefilter = $filter->{'instcodefilter'};
16306: }
16307: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16308: if ($type eq '') { $type = '.'; }
16309:
16310: if (($clonerudom ne '') && ($cloneruname ne '')) {
16311: $cloner = $cloneruname.':'.$clonerudom;
16312: }
16313: %courses = &Apache::lonnet::courseiddump($dom,
16314: $filter->{'descriptfilter'},
16315: $timefilter,
16316: $instcodefilter,
16317: $filter->{'combownerfilter'},
16318: $filter->{'coursefilter'},
16319: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16320: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16321: $filter->{'cloneableonly'},
16322: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16323: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16324: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16325: my $ccrole;
16326: if ($type eq 'Community') {
16327: $ccrole = 'co';
16328: } else {
16329: $ccrole = 'cc';
16330: }
16331: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16332: $filter->{'persondomfilter'},
16333: 'userroles',undef,
16334: [$ccrole,'in','ad','ep','ta','cr'],
16335: $dom);
16336: foreach my $role (keys(%rolehash)) {
16337: my ($cnum,$cdom,$courserole) = split(':',$role);
16338: my $cid = $cdom.'_'.$cnum;
16339: if (exists($courses{$cid})) {
16340: if (ref($courses{$cid}) eq 'HASH') {
16341: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16342: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16343: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16344: }
16345: } else {
16346: $courses{$cid}{roles} = [$courserole];
16347: }
16348: $showcourses{$cid} = $courses{$cid};
16349: }
16350: }
16351: }
16352: %courses = %showcourses;
16353: }
16354: return %courses;
16355: }
16356:
16357: =pod
16358:
16359: =back
16360:
1.1075.2.88 raeburn 16361: =head1 Routines for version requirements for current course.
16362:
16363: =over 4
16364:
16365: =item * &check_release_required()
16366:
16367: Compares required LON-CAPA version with version on server, and
16368: if required version is newer looks for a server with the required version.
16369:
16370: Looks first at servers in user's owen domain; if none suitable, looks at
16371: servers in course's domain are permitted to host sessions for user's domain.
16372:
16373: Inputs:
16374:
16375: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16376:
16377: $courseid - Course ID of current course
16378:
16379: $rolecode - User's current role in course (for switchserver query string).
16380:
16381: $required - LON-CAPA version needed by course (format: Major.Minor).
16382:
16383:
16384: Returns:
16385:
16386: $switchserver - query string tp append to /adm/switchserver call (if
16387: current server's LON-CAPA version is too old.
16388:
16389: $warning - Message is displayed if no suitable server could be found.
16390:
16391: =cut
16392:
16393: sub check_release_required {
16394: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16395: my ($switchserver,$warning);
16396: if ($required ne '') {
16397: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16398: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16399: if ($reqdmajor ne '' && $reqdminor ne '') {
16400: my $otherserver;
16401: if (($major eq '' && $minor eq '') ||
16402: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16403: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16404: my $switchlcrev =
16405: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16406: $userdomserver);
16407: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16408: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16409: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16410: my $cdom = $env{'course.'.$courseid.'.domain'};
16411: if ($cdom ne $env{'user.domain'}) {
16412: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16413: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16414: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16415: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16416: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16417: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16418: my $canhost =
16419: &Apache::lonnet::can_host_session($env{'user.domain'},
16420: $coursedomserver,
16421: $remoterev,
16422: $udomdefaults{'remotesessions'},
16423: $defdomdefaults{'hostedsessions'});
16424:
16425: if ($canhost) {
16426: $otherserver = $coursedomserver;
16427: } else {
16428: $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.");
16429: }
16430: } else {
16431: $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).");
16432: }
16433: } else {
16434: $otherserver = $userdomserver;
16435: }
16436: }
16437: if ($otherserver ne '') {
16438: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16439: }
16440: }
16441: }
16442: return ($switchserver,$warning);
16443: }
16444:
16445: =pod
16446:
16447: =item * &check_release_result()
16448:
16449: Inputs:
16450:
16451: $switchwarning - Warning message if no suitable server found to host session.
16452:
16453: $switchserver - query string to append to /adm/switchserver containing lonHostID
16454: and current role.
16455:
16456: Returns: HTML to display with information about requirement to switch server.
16457: Either displaying warning with link to Roles/Courses screen or
16458: display link to switchserver.
16459:
1.1075.2.69 raeburn 16460: =cut
16461:
1.1075.2.88 raeburn 16462: sub check_release_result {
16463: my ($switchwarning,$switchserver) = @_;
16464: my $output = &start_page('Selected course unavailable on this server').
16465: '<p class="LC_warning">';
16466: if ($switchwarning) {
16467: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16468: if (&show_course()) {
16469: $output .= &mt('Display courses');
16470: } else {
16471: $output .= &mt('Display roles');
16472: }
16473: $output .= '</a>';
16474: } elsif ($switchserver) {
16475: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16476: '<br />'.
16477: '<a href="/adm/switchserver?'.$switchserver.'">'.
16478: &mt('Switch Server').
16479: '</a>';
16480: }
16481: $output .= '</p>'.&end_page();
16482: return $output;
16483: }
16484:
16485: =pod
16486:
16487: =item * &needs_coursereinit()
16488:
16489: Determine if course contents stored for user's session needs to be
16490: refreshed, because content has changed since "Big Hash" last tied.
16491:
16492: Check for change is made if time last checked is more than 10 minutes ago
16493: (by default).
16494:
16495: Inputs:
16496:
16497: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16498:
16499: $interval (optional) - Time which may elapse (in s) between last check for content
16500: change in current course. (default: 600 s).
16501:
16502: Returns: an array; first element is:
16503:
16504: =over 4
16505:
16506: 'switch' - if content updates mean user's session
16507: needs to be switched to a server running a newer LON-CAPA version
16508:
16509: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16510: on current server hosting user's session
16511:
16512: '' - if no action required.
16513:
16514: =back
16515:
16516: If first item element is 'switch':
16517:
16518: second item is $switchwarning - Warning message if no suitable server found to host session.
16519:
16520: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16521: and current role.
16522:
16523: otherwise: no other elements returned.
16524:
16525: =back
16526:
16527: =cut
16528:
16529: sub needs_coursereinit {
16530: my ($loncaparev,$interval) = @_;
16531: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16532: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16533: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16534: my $now = time;
16535: if ($interval eq '') {
16536: $interval = 600;
16537: }
16538: if (($now-$env{'request.course.timechecked'})>$interval) {
16539: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16540: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16541: if ($lastchange > $env{'request.course.tied'}) {
16542: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16543: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16544: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16545: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16546: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16547: $curr_reqd_hash{'internal.releaserequired'}});
16548: my ($switchserver,$switchwarning) =
16549: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16550: $curr_reqd_hash{'internal.releaserequired'});
16551: if ($switchwarning ne '' || $switchserver ne '') {
16552: return ('switch',$switchwarning,$switchserver);
16553: }
16554: }
16555: }
16556: return ('update');
16557: }
16558: }
16559: return ();
16560: }
1.1075.2.69 raeburn 16561:
1.1075.2.11 raeburn 16562: sub update_content_constraints {
16563: my ($cdom,$cnum,$chome,$cid) = @_;
16564: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16565: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16566: my %checkresponsetypes;
16567: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
16568: my ($item,$name,$value) = split(/:/,$key);
16569: if ($item eq 'resourcetag') {
16570: if ($name eq 'responsetype') {
16571: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16572: }
16573: }
16574: }
16575: my $navmap = Apache::lonnavmaps::navmap->new();
16576: if (defined($navmap)) {
16577: my %allresponses;
16578: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16579: my %responses = $res->responseTypes();
16580: foreach my $key (keys(%responses)) {
16581: next unless(exists($checkresponsetypes{$key}));
16582: $allresponses{$key} += $responses{$key};
16583: }
16584: }
16585: foreach my $key (keys(%allresponses)) {
16586: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16587: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16588: ($reqdmajor,$reqdminor) = ($major,$minor);
16589: }
16590: }
16591: undef($navmap);
16592: }
16593: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16594: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16595: }
16596: return;
16597: }
16598:
1.1075.2.27 raeburn 16599: sub allmaps_incourse {
16600: my ($cdom,$cnum,$chome,$cid) = @_;
16601: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16602: $cid = $env{'request.course.id'};
16603: $cdom = $env{'course.'.$cid.'.domain'};
16604: $cnum = $env{'course.'.$cid.'.num'};
16605: $chome = $env{'course.'.$cid.'.home'};
16606: }
16607: my %allmaps = ();
16608: my $lastchange =
16609: &Apache::lonnet::get_coursechange($cdom,$cnum);
16610: if ($lastchange > $env{'request.course.tied'}) {
16611: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16612: unless ($ferr) {
16613: &update_content_constraints($cdom,$cnum,$chome,$cid);
16614: }
16615: }
16616: my $navmap = Apache::lonnavmaps::navmap->new();
16617: if (defined($navmap)) {
16618: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16619: $allmaps{$res->src()} = 1;
16620: }
16621: }
16622: return \%allmaps;
16623: }
16624:
1.1075.2.11 raeburn 16625: sub parse_supplemental_title {
16626: my ($title) = @_;
16627:
16628: my ($foldertitle,$renametitle);
16629: if ($title =~ /&&&/) {
16630: $title = &HTML::Entites::decode($title);
16631: }
16632: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16633: $renametitle=$4;
16634: my ($time,$uname,$udom) = ($1,$2,$3);
16635: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16636: my $name = &plainname($uname,$udom);
16637: $name = &HTML::Entities::encode($name,'"<>&\'');
16638: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16639: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16640: $name.': <br />'.$foldertitle;
16641: }
16642: if (wantarray) {
16643: return ($title,$foldertitle,$renametitle);
16644: }
16645: return $title;
16646: }
16647:
1.1075.2.43 raeburn 16648: sub recurse_supplemental {
16649: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16650: if ($suppmap) {
16651: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16652: if ($fatal) {
16653: $errors ++;
16654: } else {
16655: if ($#LONCAPA::map::resources > 0) {
16656: foreach my $res (@LONCAPA::map::resources) {
16657: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16658: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 16659: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16660: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 16661: } else {
16662: $numfiles ++;
16663: }
16664: }
16665: }
16666: }
16667: }
16668: }
16669: return ($numfiles,$errors);
16670: }
16671:
1.1075.2.18 raeburn 16672: sub symb_to_docspath {
1.1075.2.119 raeburn 16673: my ($symb,$navmapref) = @_;
16674: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 16675: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16676: if ($resurl=~/\.(sequence|page)$/) {
16677: $mapurl=$resurl;
16678: } elsif ($resurl eq 'adm/navmaps') {
16679: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16680: }
16681: my $mapresobj;
1.1075.2.119 raeburn 16682: unless (ref($$navmapref)) {
16683: $$navmapref = Apache::lonnavmaps::navmap->new();
16684: }
16685: if (ref($$navmapref)) {
16686: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 16687: }
16688: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16689: my $type=$2;
16690: my $path;
16691: if (ref($mapresobj)) {
16692: my $pcslist = $mapresobj->map_hierarchy();
16693: if ($pcslist ne '') {
16694: foreach my $pc (split(/,/,$pcslist)) {
16695: next if ($pc <= 1);
1.1075.2.119 raeburn 16696: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 16697: if (ref($res)) {
16698: my $thisurl = $res->src();
16699: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16700: my $thistitle = $res->title();
16701: $path .= '&'.
16702: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 16703: &escape($thistitle).
1.1075.2.18 raeburn 16704: ':'.$res->randompick().
16705: ':'.$res->randomout().
16706: ':'.$res->encrypted().
16707: ':'.$res->randomorder().
16708: ':'.$res->is_page();
16709: }
16710: }
16711: }
16712: $path =~ s/^\&//;
16713: my $maptitle = $mapresobj->title();
16714: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16715: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16716: }
16717: $path .= (($path ne '')? '&' : '').
16718: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16719: &escape($maptitle).
1.1075.2.18 raeburn 16720: ':'.$mapresobj->randompick().
16721: ':'.$mapresobj->randomout().
16722: ':'.$mapresobj->encrypted().
16723: ':'.$mapresobj->randomorder().
16724: ':'.$mapresobj->is_page();
16725: } else {
16726: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16727: my $ispage = (($type eq 'page')? 1 : '');
16728: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16729: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16730: }
16731: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16732: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 16733: }
16734: unless ($mapurl eq 'default') {
16735: $path = 'default&'.
1.1075.2.46 raeburn 16736: &escape('Main Content').
1.1075.2.18 raeburn 16737: ':::::&'.$path;
16738: }
16739: return $path;
16740: }
16741:
1.1075.2.14 raeburn 16742: sub captcha_display {
1.1075.2.137! raeburn 16743: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 16744: my ($output,$error);
1.1075.2.107 raeburn 16745: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137! raeburn 16746: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 16747: if ($captcha eq 'original') {
16748: $output = &create_captcha();
16749: unless ($output) {
16750: $error = 'captcha';
16751: }
16752: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16753: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 16754: unless ($output) {
16755: $error = 'recaptcha';
16756: }
16757: }
1.1075.2.107 raeburn 16758: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 16759: }
16760:
16761: sub captcha_response {
1.1075.2.137! raeburn 16762: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 16763: my ($captcha_chk,$captcha_error);
1.1075.2.137! raeburn 16764: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 16765: if ($captcha eq 'original') {
16766: ($captcha_chk,$captcha_error) = &check_captcha();
16767: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16768: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 16769: } else {
16770: $captcha_chk = 1;
16771: }
16772: return ($captcha_chk,$captcha_error);
16773: }
16774:
16775: sub get_captcha_config {
1.1075.2.137! raeburn 16776: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 16777: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 16778: my $hostname = &Apache::lonnet::hostname($lonhost);
16779: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16780: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16781: if ($context eq 'usercreation') {
16782: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16783: if (ref($domconfig{$context}) eq 'HASH') {
16784: $hashtocheck = $domconfig{$context}{'cancreate'};
16785: if (ref($hashtocheck) eq 'HASH') {
16786: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16787: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16788: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16789: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16790: }
16791: if ($privkey && $pubkey) {
16792: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16793: $version = $hashtocheck->{'recaptchaversion'};
16794: if ($version ne '2') {
16795: $version = 1;
16796: }
1.1075.2.14 raeburn 16797: } else {
16798: $captcha = 'original';
16799: }
16800: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16801: $captcha = 'original';
16802: }
16803: }
16804: } else {
16805: $captcha = 'captcha';
16806: }
16807: } elsif ($context eq 'login') {
16808: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16809: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16810: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16811: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
16812: if ($privkey && $pubkey) {
16813: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16814: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
16815: if ($version ne '2') {
16816: $version = 1;
16817: }
1.1075.2.14 raeburn 16818: } else {
16819: $captcha = 'original';
16820: }
16821: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16822: $captcha = 'original';
16823: }
1.1075.2.137! raeburn 16824: } elsif ($context eq 'passwords') {
! 16825: if ($dom_in_effect) {
! 16826: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
! 16827: if ($passwdconf{'captcha'} eq 'recaptcha') {
! 16828: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
! 16829: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
! 16830: $privkey = $passwdconf{'recaptchakeys'}{'private'};
! 16831: }
! 16832: if ($privkey && $pubkey) {
! 16833: $captcha = 'recaptcha';
! 16834: $version = $passwdconf{'recaptchaversion'};
! 16835: if ($version ne '2') {
! 16836: $version = 1;
! 16837: }
! 16838: } else {
! 16839: $captcha = 'original';
! 16840: }
! 16841: } elsif ($passwdconf{'captcha'} ne 'notused') {
! 16842: $captcha = 'original';
! 16843: }
! 16844: }
1.1075.2.14 raeburn 16845: }
1.1075.2.107 raeburn 16846: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 16847: }
16848:
16849: sub create_captcha {
16850: my %captcha_params = &captcha_settings();
16851: my ($output,$maxtries,$tries) = ('',10,0);
16852: while ($tries < $maxtries) {
16853: $tries ++;
16854: my $captcha = Authen::Captcha->new (
16855: output_folder => $captcha_params{'output_dir'},
16856: data_folder => $captcha_params{'db_dir'},
16857: );
16858: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
16859:
16860: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
16861: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
16862: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 16863: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
16864: '<br />'.
16865: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 16866: last;
16867: }
16868: }
16869: return $output;
16870: }
16871:
16872: sub captcha_settings {
16873: my %captcha_params = (
16874: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
16875: www_output_dir => "/captchaspool",
16876: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16877: numchars => '5',
16878: );
16879: return %captcha_params;
16880: }
16881:
16882: sub check_captcha {
16883: my ($captcha_chk,$captcha_error);
16884: my $code = $env{'form.code'};
16885: my $md5sum = $env{'form.crypt'};
16886: my %captcha_params = &captcha_settings();
16887: my $captcha = Authen::Captcha->new(
16888: output_folder => $captcha_params{'output_dir'},
16889: data_folder => $captcha_params{'db_dir'},
16890: );
1.1075.2.26 raeburn 16891: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 16892: my %captcha_hash = (
16893: 0 => 'Code not checked (file error)',
16894: -1 => 'Failed: code expired',
16895: -2 => 'Failed: invalid code (not in database)',
16896: -3 => 'Failed: invalid code (code does not match crypt)',
16897: );
16898: if ($captcha_chk != 1) {
16899: $captcha_error = $captcha_hash{$captcha_chk}
16900: }
16901: return ($captcha_chk,$captcha_error);
16902: }
16903:
16904: sub create_recaptcha {
1.1075.2.107 raeburn 16905: my ($pubkey,$version) = @_;
16906: if ($version >= 2) {
16907: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
16908: } else {
16909: my $use_ssl;
16910: if ($ENV{'SERVER_PORT'} == 443) {
16911: $use_ssl = 1;
16912: }
16913: my $captcha = Captcha::reCAPTCHA->new;
16914: return $captcha->get_options_setter({theme => 'white'})."\n".
16915: $captcha->get_html($pubkey,undef,$use_ssl).
16916: &mt('If the text is hard to read, [_1] will replace them.',
16917: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
16918: '<br /><br />';
16919: }
1.1075.2.14 raeburn 16920: }
16921:
16922: sub check_recaptcha {
1.1075.2.107 raeburn 16923: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 16924: my $captcha_chk;
1.1075.2.107 raeburn 16925: if ($version >= 2) {
16926: my $ua = LWP::UserAgent->new;
16927: $ua->timeout(10);
16928: my %info = (
16929: secret => $privkey,
16930: response => $env{'form.g-recaptcha-response'},
16931: remoteip => $ENV{'REMOTE_ADDR'},
16932: );
16933: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
16934: if ($response->is_success) {
16935: my $data = JSON::DWIW->from_json($response->decoded_content);
16936: if (ref($data) eq 'HASH') {
16937: if ($data->{'success'}) {
16938: $captcha_chk = 1;
16939: }
16940: }
16941: }
16942: } else {
16943: my $captcha = Captcha::reCAPTCHA->new;
16944: my $captcha_result =
16945: $captcha->check_answer(
16946: $privkey,
16947: $ENV{'REMOTE_ADDR'},
16948: $env{'form.recaptcha_challenge_field'},
16949: $env{'form.recaptcha_response_field'},
16950: );
16951: if ($captcha_result->{is_valid}) {
16952: $captcha_chk = 1;
16953: }
1.1075.2.14 raeburn 16954: }
16955: return $captcha_chk;
16956: }
16957:
1.1075.2.64 raeburn 16958: sub emailusername_info {
1.1075.2.103 raeburn 16959: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 16960: my %titles = &Apache::lonlocal::texthash (
16961: lastname => 'Last Name',
16962: firstname => 'First Name',
16963: institution => 'School/college/university',
16964: location => "School's city, state/province, country",
16965: web => "School's web address",
16966: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 16967: id => 'Student/Employee ID',
1.1075.2.64 raeburn 16968: );
16969: return (\@fields,\%titles);
16970: }
16971:
1.1075.2.56 raeburn 16972: sub cleanup_html {
16973: my ($incoming) = @_;
16974: my $outgoing;
16975: if ($incoming ne '') {
16976: $outgoing = $incoming;
16977: $outgoing =~ s/;/;/g;
16978: $outgoing =~ s/\#/#/g;
16979: $outgoing =~ s/\&/&/g;
16980: $outgoing =~ s/</</g;
16981: $outgoing =~ s/>/>/g;
16982: $outgoing =~ s/\(/(/g;
16983: $outgoing =~ s/\)/)/g;
16984: $outgoing =~ s/"/"/g;
16985: $outgoing =~ s/'/'/g;
16986: $outgoing =~ s/\$/$/g;
16987: $outgoing =~ s{/}{/}g;
16988: $outgoing =~ s/=/=/g;
16989: $outgoing =~ s/\\/\/g
16990: }
16991: return $outgoing;
16992: }
16993:
1.1075.2.74 raeburn 16994: # Checks for critical messages and returns a redirect url if one exists.
16995: # $interval indicates how often to check for messages.
16996: sub critical_redirect {
16997: my ($interval) = @_;
16998: if ((time-$env{'user.criticalcheck.time'})>$interval) {
16999: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17000: $env{'user.name'});
17001: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
17002: my $redirecturl;
17003: if ($what[0]) {
17004: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17005: $redirecturl='/adm/email?critical=display';
17006: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17007: return (1, $url);
17008: }
17009: }
17010: }
17011: return ();
17012: }
17013:
1.1075.2.64 raeburn 17014: # Use:
17015: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17016: #
17017: ##################################################
17018: # password associated functions #
17019: ##################################################
17020: sub des_keys {
17021: # Make a new key for DES encryption.
17022: # Each key has two parts which are returned separately.
17023: # Please note: Each key must be passed through the &hex function
17024: # before it is output to the web browser. The hex versions cannot
17025: # be used to decrypt.
17026: my @hexstr=('0','1','2','3','4','5','6','7',
17027: '8','9','a','b','c','d','e','f');
17028: my $lkey='';
17029: for (0..7) {
17030: $lkey.=$hexstr[rand(15)];
17031: }
17032: my $ukey='';
17033: for (0..7) {
17034: $ukey.=$hexstr[rand(15)];
17035: }
17036: return ($lkey,$ukey);
17037: }
17038:
17039: sub des_decrypt {
17040: my ($key,$cyphertext) = @_;
17041: my $keybin=pack("H16",$key);
17042: my $cypher;
17043: if ($Crypt::DES::VERSION>=2.03) {
17044: $cypher=new Crypt::DES $keybin;
17045: } else {
17046: $cypher=new DES $keybin;
17047: }
1.1075.2.106 raeburn 17048: my $plaintext='';
17049: my $cypherlength = length($cyphertext);
17050: my $numchunks = int($cypherlength/32);
17051: for (my $j=0; $j<$numchunks; $j++) {
17052: my $start = $j*32;
17053: my $cypherblock = substr($cyphertext,$start,32);
17054: my $chunk =
17055: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17056: $chunk .=
17057: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17058: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17059: $plaintext .= $chunk;
17060: }
1.1075.2.64 raeburn 17061: return $plaintext;
17062: }
17063:
1.1075.2.135 raeburn 17064: sub is_nonframeable {
17065: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
17066: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
17067: return if (($remprotocol eq '') || ($remhost eq ''));
17068:
17069: $remprotocol = lc($remprotocol);
17070: $remhost = lc($remhost);
17071: my $remport = 80;
17072: if ($remprotocol eq 'https') {
17073: $remport = 443;
17074: }
17075: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
17076: if ($cached) {
17077: unless ($nocache) {
17078: if ($result) {
17079: return 1;
17080: } else {
17081: return 0;
17082: }
17083: }
17084: }
17085: my $uselink;
17086: my $request = new HTTP::Request('HEAD',$url);
17087: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
17088: if ($response->is_success()) {
17089: my $secpolicy = lc($response->header('content-security-policy'));
17090: my $xframeop = lc($response->header('x-frame-options'));
17091: $secpolicy =~ s/^\s+|\s+$//g;
17092: $xframeop =~ s/^\s+|\s+$//g;
17093: if (($secpolicy ne '') || ($xframeop ne '')) {
17094: my $remotehost = $remprotocol.'://'.$remhost;
17095: my ($origin,$protocol,$port);
17096: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
17097: $port = $ENV{'SERVER_PORT'};
17098: } else {
17099: $port = 80;
17100: }
17101: if ($absolute eq '') {
17102: $protocol = 'http:';
17103: if ($port == 443) {
17104: $protocol = 'https:';
17105: }
17106: $origin = $protocol.'//'.lc($hostname);
17107: } else {
17108: $origin = lc($absolute);
17109: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
17110: }
17111: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
17112: my $framepolicy = $1;
17113: $framepolicy =~ s/^\s+|\s+$//g;
17114: my @policies = split(/\s+/,$framepolicy);
17115: if (@policies) {
17116: if (grep(/^\Q'none'\E$/,@policies)) {
17117: $uselink = 1;
17118: } else {
17119: $uselink = 1;
17120: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
17121: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
17122: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
17123: undef($uselink);
17124: }
17125: if ($uselink) {
17126: if (grep(/^\Q'self'\E$/,@policies)) {
17127: if (($origin ne '') && ($remotehost eq $origin)) {
17128: undef($uselink);
17129: }
17130: }
17131: }
17132: if ($uselink) {
17133: my @possok;
17134: if ($ip ne '') {
17135: push(@possok,$ip);
17136: }
17137: my $hoststr = '';
17138: foreach my $part (reverse(split(/\./,$hostname))) {
17139: if ($hoststr eq '') {
17140: $hoststr = $part;
17141: } else {
17142: $hoststr = "$part.$hoststr";
17143: }
17144: if ($hoststr eq $hostname) {
17145: push(@possok,$hostname);
17146: } else {
17147: push(@possok,"*.$hoststr");
17148: }
17149: }
17150: if (@possok) {
17151: foreach my $poss (@possok) {
17152: last if (!$uselink);
17153: foreach my $policy (@policies) {
17154: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
17155: undef($uselink);
17156: last;
17157: }
17158: }
17159: }
17160: }
17161: }
17162: }
17163: }
17164: } elsif ($xframeop ne '') {
17165: $uselink = 1;
17166: my @policies = split(/\s*,\s*/,$xframeop);
17167: if (@policies) {
17168: unless (grep(/^deny$/,@policies)) {
17169: if ($origin ne '') {
17170: if (grep(/^sameorigin$/,@policies)) {
17171: if ($remotehost eq $origin) {
17172: undef($uselink);
17173: }
17174: }
17175: if ($uselink) {
17176: foreach my $policy (@policies) {
17177: if ($policy =~ /^allow-from\s*(.+)$/) {
17178: my $allowfrom = $1;
17179: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
17180: undef($uselink);
17181: last;
17182: }
17183: }
17184: }
17185: }
17186: }
17187: }
17188: }
17189: }
17190: }
17191: }
17192: if ($nocache) {
17193: if ($cached) {
17194: my $devalidate;
17195: if ($uselink && !$result) {
17196: $devalidate = 1;
17197: } elsif (!$uselink && $result) {
17198: $devalidate = 1;
17199: }
17200: if ($devalidate) {
17201: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
17202: }
17203: }
17204: } else {
17205: if ($uselink) {
17206: $result = 1;
17207: } else {
17208: $result = 0;
17209: }
17210: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
17211: }
17212: return $uselink;
17213: }
17214:
1.112 bowersj2 17215: 1;
17216: __END__;
1.41 ng 17217:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>