Annotation of loncom/interface/loncommon.pm, revision 1.1228
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1228 ! raeburn 4: # $Id: loncommon.pm,v 1.1227 2015/08/09 21:43:18 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 74: use DateTime::TimeZone;
1.687 raeburn 75: use DateTime::Locale::Catalog;
1.1220 raeburn 76: use Encode();
1.1091 foxr 77: use Text::Aspell;
1.1094 raeburn 78: use Authen::Captcha;
79: use Captcha::reCAPTCHA;
1.1174 raeburn 80: use Crypt::DES;
81: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 82: use MIME::Lite;
83: use MIME::Types;
1.117 www 84:
1.517 raeburn 85: # ---------------------------------------------- Designs
86: use vars qw(%defaultdesign);
87:
1.22 www 88: my $readit;
89:
1.517 raeburn 90:
1.157 matthew 91: ##
92: ## Global Variables
93: ##
1.46 matthew 94:
1.643 foxr 95:
96: # ----------------------------------------------- SSI with retries:
97: #
98:
99: =pod
100:
1.648 raeburn 101: =head1 Server Side include with retries:
1.643 foxr 102:
103: =over 4
104:
1.648 raeburn 105: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 106:
107: Performs an ssi with some number of retries. Retries continue either
108: until the result is ok or until the retry count supplied by the
109: caller is exhausted.
110:
111: Inputs:
1.648 raeburn 112:
113: =over 4
114:
1.643 foxr 115: resource - Identifies the resource to insert.
1.648 raeburn 116:
1.643 foxr 117: retries - Count of the number of retries allowed.
1.648 raeburn 118:
1.643 foxr 119: form - Hash that identifies the rendering options.
120:
1.648 raeburn 121: =back
122:
123: Returns:
124:
125: =over 4
126:
1.643 foxr 127: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 128:
1.643 foxr 129: response - The response from the last attempt (which may or may not have been successful.
130:
1.648 raeburn 131: =back
132:
133: =back
134:
1.643 foxr 135: =cut
136:
137: sub ssi_with_retries {
138: my ($resource, $retries, %form) = @_;
139:
140:
141: my $ok = 0; # True if we got a good response.
142: my $content;
143: my $response;
144:
145: # Try to get the ssi done. within the retries count:
146:
147: do {
148: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
149: $ok = $response->is_success;
1.650 www 150: if (!$ok) {
151: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
152: }
1.643 foxr 153: $retries--;
154: } while (!$ok && ($retries > 0));
155:
156: if (!$ok) {
157: $content = ''; # On error return an empty content.
158: }
159: return ($content, $response);
160:
161: }
162:
163:
164:
1.20 www 165: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 166: my %language;
1.124 www 167: my %supported_language;
1.1088 foxr 168: my %supported_codes;
1.1048 foxr 169: my %latex_language; # For choosing hyphenation in <transl..>
170: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 171: my %cprtag;
1.192 taceyjo1 172: my %scprtag;
1.351 www 173: my %fe; my %fd; my %fm;
1.41 ng 174: my %category_extensions;
1.12 harris41 175:
1.46 matthew 176: # ---------------------------------------------- Thesaurus variables
1.144 matthew 177: #
178: # %Keywords:
179: # A hash used by &keyword to determine if a word is considered a keyword.
180: # $thesaurus_db_file
181: # Scalar containing the full path to the thesaurus database.
1.46 matthew 182:
183: my %Keywords;
184: my $thesaurus_db_file;
185:
1.144 matthew 186: #
187: # Initialize values from language.tab, copyright.tab, filetypes.tab,
188: # thesaurus.tab, and filecategories.tab.
189: #
1.18 www 190: BEGIN {
1.46 matthew 191: # Variable initialization
192: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
193: #
1.22 www 194: unless ($readit) {
1.12 harris41 195: # ------------------------------------------------------------------- languages
196: {
1.158 raeburn 197: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
198: '/language.tab';
199: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 200: while (my $line = <$fh>) {
201: next if ($line=~/^\#/);
202: chomp($line);
1.1088 foxr 203: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 204: $language{$key}=$val.' - '.$enc;
205: if ($sup) {
206: $supported_language{$key}=$sup;
1.1088 foxr 207: $supported_codes{$key} = $code;
1.158 raeburn 208: }
1.1048 foxr 209: if ($latex) {
210: $latex_language_bykey{$key} = $latex;
1.1088 foxr 211: $latex_language{$code} = $latex;
1.1048 foxr 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';
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';
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';
249: if ( open (my $fh,"<$designfile") ) {
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';
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.158 raeburn 268: push @{$category_extensions{lc($category)}},$extension;
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';
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.1116 raeburn 540: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 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.1221 raeburn 591: url += '&cloner='+ownername+':'+ownerdom+'&crscode='+document.forms[formid].crscode.value;
592: }
593: if (formname == 'requestcrs') {
594: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 595: }
1.293 raeburn 596: if (multflag !=null && multflag != '') {
597: url += '&multiple='+multflag;
598: }
1.909 raeburn 599: var title = '$wintitle';
1.91 www 600: var options = 'scrollbars=1,resizable=1,menubar=0';
601: options += ',width=700,height=600';
602: stdeditbrowser = open(url,title,options,'1');
603: stdeditbrowser.focus();
604: }
1.876 raeburn 605: $id_functions
606: ENDSTDBRW
1.1116 raeburn 607: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
608: $output .= &setsec_javascript($sec_element,$formname,$role_element,
609: $credits_element);
1.876 raeburn 610: }
611: $output .= '
612: // ]]>
613: </script>';
614: return $output;
615: }
616:
617: sub javascript_index_functions {
618: return <<"ENDJS";
619:
620: function getFormIdByName(formname) {
621: for (var i=0;i<document.forms.length;i++) {
622: if (document.forms[i].name == formname) {
623: return i;
624: }
625: }
626: return -1;
627: }
628:
629: function getIndexByName(formid,item) {
630: for (var i=0;i<document.forms[formid].elements.length;i++) {
631: if (document.forms[formid].elements[i].name == item) {
632: return i;
633: }
634: }
635: return -1;
636: }
1.468 raeburn 637:
1.876 raeburn 638: function getDomainFromSelectbox(formname,udom) {
639: var userdom;
640: var formid = getFormIdByName(formname);
641: if (formid > -1) {
642: var domid = getIndexByName(formid,udom);
643: if (domid > -1) {
644: if (document.forms[formid].elements[domid].type == 'select-one') {
645: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
646: }
647: if (document.forms[formid].elements[domid].type == 'hidden') {
648: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 649: }
650: }
651: }
1.876 raeburn 652: return userdom;
653: }
654:
655: ENDJS
1.468 raeburn 656:
1.876 raeburn 657: }
658:
1.1017 raeburn 659: sub javascript_array_indexof {
1.1018 raeburn 660: return <<ENDJS;
1.1017 raeburn 661: <script type="text/javascript" language="JavaScript">
662: // <![CDATA[
663:
664: if (!Array.prototype.indexOf) {
665: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
666: "use strict";
667: if (this === void 0 || this === null) {
668: throw new TypeError();
669: }
670: var t = Object(this);
671: var len = t.length >>> 0;
672: if (len === 0) {
673: return -1;
674: }
675: var n = 0;
676: if (arguments.length > 0) {
677: n = Number(arguments[1]);
1.1088 foxr 678: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 679: n = 0;
680: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
681: n = (n > 0 || -1) * Math.floor(Math.abs(n));
682: }
683: }
684: if (n >= len) {
685: return -1;
686: }
687: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
688: for (; k < len; k++) {
689: if (k in t && t[k] === searchElement) {
690: return k;
691: }
692: }
693: return -1;
694: }
695: }
696:
697: // ]]>
698: </script>
699:
700: ENDJS
701:
702: }
703:
1.876 raeburn 704: sub userbrowser_javascript {
705: my $id_functions = &javascript_index_functions();
706: return <<"ENDUSERBRW";
707:
1.888 raeburn 708: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 709: var url = '/adm/pickuser?';
710: var userdom = getDomainFromSelectbox(formname,udom);
711: if (userdom != null) {
712: if (userdom != '') {
713: url += 'srchdom='+userdom+'&';
714: }
715: }
716: url += 'form=' + formname + '&unameelement='+uname+
717: '&udomelement='+udom+
718: '&ulastelement='+ulast+
719: '&ufirstelement='+ufirst+
720: '&uemailelement='+uemail+
1.881 raeburn 721: '&hideudomelement='+hideudom+
722: '&coursedom='+crsdom;
1.888 raeburn 723: if ((caller != null) && (caller != undefined)) {
724: url += '&caller='+caller;
725: }
1.876 raeburn 726: var title = 'User_Browser';
727: var options = 'scrollbars=1,resizable=1,menubar=0';
728: options += ',width=700,height=600';
729: var stdeditbrowser = open(url,title,options,'1');
730: stdeditbrowser.focus();
731: }
732:
1.888 raeburn 733: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 734: var formid = getFormIdByName(formname);
735: if (formid > -1) {
1.888 raeburn 736: var unameid = getIndexByName(formid,uname);
1.876 raeburn 737: var domid = getIndexByName(formid,udom);
738: var hidedomid = getIndexByName(formid,origdom);
739: if (hidedomid > -1) {
740: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 741: var unameval = document.forms[formid].elements[unameid].value;
742: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
743: if (domid > -1) {
744: var slct = document.forms[formid].elements[domid];
745: if (slct.type == 'select-one') {
746: var i;
747: for (i=0;i<slct.length;i++) {
748: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
749: }
750: }
751: if (slct.type == 'hidden') {
752: slct.value = fixeddom;
1.876 raeburn 753: }
754: }
1.468 raeburn 755: }
756: }
757: }
1.876 raeburn 758: return;
759: }
760:
761: $id_functions
762: ENDUSERBRW
1.468 raeburn 763: }
764:
765: sub setsec_javascript {
1.1116 raeburn 766: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 767: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
768: $communityrolestr);
769: if ($role_element ne '') {
770: my @allroles = ('st','ta','ep','in','ad');
771: foreach my $crstype ('Course','Community') {
772: if ($crstype eq 'Community') {
773: foreach my $role (@allroles) {
774: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
775: }
776: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
777: } else {
778: foreach my $role (@allroles) {
779: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
780: }
781: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
782: }
783: }
784: $rolestr = '"'.join('","',@allroles).'"';
785: $courserolestr = '"'.join('","',@courserolenames).'"';
786: $communityrolestr = '"'.join('","',@communityrolenames).'"';
787: }
1.468 raeburn 788: my $setsections = qq|
789: function setSect(sectionlist) {
1.629 raeburn 790: var sectionsArray = new Array();
791: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
792: sectionsArray = sectionlist.split(",");
793: }
1.468 raeburn 794: var numSections = sectionsArray.length;
795: document.$formname.$sec_element.length = 0;
796: if (numSections == 0) {
797: document.$formname.$sec_element.multiple=false;
798: document.$formname.$sec_element.size=1;
799: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
800: } else {
801: if (numSections == 1) {
802: document.$formname.$sec_element.multiple=false;
803: document.$formname.$sec_element.size=1;
804: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
805: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
806: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
807: } else {
808: for (var i=0; i<numSections; i++) {
809: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
810: }
811: document.$formname.$sec_element.multiple=true
812: if (numSections < 3) {
813: document.$formname.$sec_element.size=numSections;
814: } else {
815: document.$formname.$sec_element.size=3;
816: }
817: document.$formname.$sec_element.options[0].selected = false
818: }
819: }
1.91 www 820: }
1.905 raeburn 821:
822: function setRole(crstype) {
1.468 raeburn 823: |;
1.905 raeburn 824: if ($role_element eq '') {
825: $setsections .= ' return;
826: }
827: ';
828: } else {
829: $setsections .= qq|
830: var elementLength = document.$formname.$role_element.length;
831: var allroles = Array($rolestr);
832: var courserolenames = Array($courserolestr);
833: var communityrolenames = Array($communityrolestr);
834: if (elementLength != undefined) {
835: if (document.$formname.$role_element.options[5].value == 'cc') {
836: if (crstype == 'Course') {
837: return;
838: } else {
839: allroles[5] = 'co';
840: for (var i=0; i<6; i++) {
841: document.$formname.$role_element.options[i].value = allroles[i];
842: document.$formname.$role_element.options[i].text = communityrolenames[i];
843: }
844: }
845: } else {
846: if (crstype == 'Community') {
847: return;
848: } else {
849: allroles[5] = 'cc';
850: for (var i=0; i<6; i++) {
851: document.$formname.$role_element.options[i].value = allroles[i];
852: document.$formname.$role_element.options[i].text = courserolenames[i];
853: }
854: }
855: }
856: }
857: return;
858: }
859: |;
860: }
1.1116 raeburn 861: if ($credits_element) {
862: $setsections .= qq|
863: function setCredits(defaultcredits) {
864: document.$formname.$credits_element.value = defaultcredits;
865: return;
866: }
867: |;
868: }
1.468 raeburn 869: return $setsections;
870: }
871:
1.91 www 872: sub selectcourse_link {
1.909 raeburn 873: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
874: $typeelement) = @_;
875: my $type = $selecttype;
1.871 raeburn 876: my $linktext = &mt('Select Course');
877: if ($selecttype eq 'Community') {
1.909 raeburn 878: $linktext = &mt('Select Community');
1.906 raeburn 879: } elsif ($selecttype eq 'Course/Community') {
880: $linktext = &mt('Select Course/Community');
1.909 raeburn 881: $type = '';
1.1019 raeburn 882: } elsif ($selecttype eq 'Select') {
883: $linktext = &mt('Select');
884: $type = '';
1.871 raeburn 885: }
1.787 bisitz 886: return '<span class="LC_nobreak">'
887: ."<a href='"
888: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
889: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 890: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 891: ."'>".$linktext.'</a>'
1.787 bisitz 892: .'</span>';
1.74 www 893: }
1.42 matthew 894:
1.653 raeburn 895: sub selectauthor_link {
896: my ($form,$udom)=@_;
897: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
898: &mt('Select Author').'</a>';
899: }
900:
1.876 raeburn 901: sub selectuser_link {
1.881 raeburn 902: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 903: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 904: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 905: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 906: ');">'.$linktext.'</a>';
1.876 raeburn 907: }
908:
1.273 raeburn 909: sub check_uncheck_jscript {
910: my $jscript = <<"ENDSCRT";
911: function checkAll(field) {
912: if (field.length > 0) {
913: for (i = 0; i < field.length; i++) {
1.1093 raeburn 914: if (!field[i].disabled) {
915: field[i].checked = true;
916: }
1.273 raeburn 917: }
918: } else {
1.1093 raeburn 919: if (!field.disabled) {
920: field.checked = true;
921: }
1.273 raeburn 922: }
923: }
924:
925: function uncheckAll(field) {
926: if (field.length > 0) {
927: for (i = 0; i < field.length; i++) {
928: field[i].checked = false ;
1.543 albertel 929: }
930: } else {
1.273 raeburn 931: field.checked = false ;
932: }
933: }
934: ENDSCRT
935: return $jscript;
936: }
937:
1.656 www 938: sub select_timezone {
1.659 raeburn 939: my ($name,$selected,$onchange,$includeempty)=@_;
940: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
941: if ($includeempty) {
942: $output .= '<option value=""';
943: if (($selected eq '') || ($selected eq 'local')) {
944: $output .= ' selected="selected" ';
945: }
946: $output .= '> </option>';
947: }
1.657 raeburn 948: my @timezones = DateTime::TimeZone->all_names;
949: foreach my $tzone (@timezones) {
950: $output.= '<option value="'.$tzone.'"';
951: if ($tzone eq $selected) {
952: $output.=' selected="selected"';
953: }
954: $output.=">$tzone</option>\n";
1.656 www 955: }
956: $output.="</select>";
957: return $output;
958: }
1.273 raeburn 959:
1.687 raeburn 960: sub select_datelocale {
961: my ($name,$selected,$onchange,$includeempty)=@_;
962: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
963: if ($includeempty) {
964: $output .= '<option value=""';
965: if ($selected eq '') {
966: $output .= ' selected="selected" ';
967: }
968: $output .= '> </option>';
969: }
970: my (@possibles,%locale_names);
971: my @locales = DateTime::Locale::Catalog::Locales;
972: foreach my $locale (@locales) {
973: if (ref($locale) eq 'HASH') {
974: my $id = $locale->{'id'};
975: if ($id ne '') {
976: my $en_terr = $locale->{'en_territory'};
977: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 978: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 979: if (grep(/^en$/,@languages) || !@languages) {
980: if ($en_terr ne '') {
981: $locale_names{$id} = '('.$en_terr.')';
982: } elsif ($native_terr ne '') {
983: $locale_names{$id} = $native_terr;
984: }
985: } else {
986: if ($native_terr ne '') {
987: $locale_names{$id} = $native_terr.' ';
988: } elsif ($en_terr ne '') {
989: $locale_names{$id} = '('.$en_terr.')';
990: }
991: }
1.1220 raeburn 992: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.687 raeburn 993: push (@possibles,$id);
994: }
995: }
996: }
997: foreach my $item (sort(@possibles)) {
998: $output.= '<option value="'.$item.'"';
999: if ($item eq $selected) {
1000: $output.=' selected="selected"';
1001: }
1002: $output.=">$item";
1003: if ($locale_names{$item} ne '') {
1.1220 raeburn 1004: $output.=' '.$locale_names{$item};
1.687 raeburn 1005: }
1006: $output.="</option>\n";
1007: }
1008: $output.="</select>";
1009: return $output;
1010: }
1011:
1.792 raeburn 1012: sub select_language {
1013: my ($name,$selected,$includeempty) = @_;
1014: my %langchoices;
1015: if ($includeempty) {
1.1117 raeburn 1016: %langchoices = ('' => 'No language preference');
1.792 raeburn 1017: }
1018: foreach my $id (&languageids()) {
1019: my $code = &supportedlanguagecode($id);
1020: if ($code) {
1021: $langchoices{$code} = &plainlanguagedescription($id);
1022: }
1023: }
1.1117 raeburn 1024: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970 raeburn 1025: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1026: }
1027:
1.42 matthew 1028: =pod
1.36 matthew 1029:
1.1088 foxr 1030:
1031: =item * &list_languages()
1032:
1033: Returns an array reference that is suitable for use in language prompters.
1034: Each array element is itself a two element array. The first element
1035: is the language code. The second element a descsriptiuon of the
1036: language itself. This is suitable for use in e.g.
1037: &Apache::edit::select_arg (once dereferenced that is).
1038:
1039: =cut
1040:
1041: sub list_languages {
1042: my @lang_choices;
1043:
1044: foreach my $id (&languageids()) {
1045: my $code = &supportedlanguagecode($id);
1046: if ($code) {
1047: my $selector = $supported_codes{$id};
1048: my $description = &plainlanguagedescription($id);
1049: push (@lang_choices, [$selector, $description]);
1050: }
1051: }
1052: return \@lang_choices;
1053: }
1054:
1055: =pod
1056:
1.648 raeburn 1057: =item * &linked_select_forms(...)
1.36 matthew 1058:
1059: linked_select_forms returns a string containing a <script></script> block
1060: and html for two <select> menus. The select menus will be linked in that
1061: changing the value of the first menu will result in new values being placed
1062: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1063: order unless a defined order is provided.
1.36 matthew 1064:
1065: linked_select_forms takes the following ordered inputs:
1066:
1067: =over 4
1068:
1.112 bowersj2 1069: =item * $formname, the name of the <form> tag
1.36 matthew 1070:
1.112 bowersj2 1071: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1072:
1.112 bowersj2 1073: =item * $firstdefault, the default value for the first menu
1.36 matthew 1074:
1.112 bowersj2 1075: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1076:
1.112 bowersj2 1077: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1078:
1.112 bowersj2 1079: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1080:
1.609 raeburn 1081: =item * $menuorder, the order of values in the first menu
1082:
1.1115 raeburn 1083: =item * $onchangefirst, additional javascript call to execute for an onchange
1084: event for the first <select> tag
1085:
1086: =item * $onchangesecond, additional javascript call to execute for an onchange
1087: event for the second <select> tag
1088:
1.41 ng 1089: =back
1090:
1.36 matthew 1091: Below is an example of such a hash. Only the 'text', 'default', and
1092: 'select2' keys must appear as stated. keys(%menu) are the possible
1093: values for the first select menu. The text that coincides with the
1.41 ng 1094: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1095: and text for the second menu are given in the hash pointed to by
1096: $menu{$choice1}->{'select2'}.
1097:
1.112 bowersj2 1098: my %menu = ( A1 => { text =>"Choice A1" ,
1099: default => "B3",
1100: select2 => {
1101: B1 => "Choice B1",
1102: B2 => "Choice B2",
1103: B3 => "Choice B3",
1104: B4 => "Choice B4"
1.609 raeburn 1105: },
1106: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1107: },
1108: A2 => { text =>"Choice A2" ,
1109: default => "C2",
1110: select2 => {
1111: C1 => "Choice C1",
1112: C2 => "Choice C2",
1113: C3 => "Choice C3"
1.609 raeburn 1114: },
1115: order => ['C2','C1','C3'],
1.112 bowersj2 1116: },
1117: A3 => { text =>"Choice A3" ,
1118: default => "D6",
1119: select2 => {
1120: D1 => "Choice D1",
1121: D2 => "Choice D2",
1122: D3 => "Choice D3",
1123: D4 => "Choice D4",
1124: D5 => "Choice D5",
1125: D6 => "Choice D6",
1126: D7 => "Choice D7"
1.609 raeburn 1127: },
1128: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1129: }
1130: );
1.36 matthew 1131:
1132: =cut
1133:
1134: sub linked_select_forms {
1135: my ($formname,
1136: $middletext,
1137: $firstdefault,
1138: $firstselectname,
1139: $secondselectname,
1.609 raeburn 1140: $hashref,
1141: $menuorder,
1.1115 raeburn 1142: $onchangefirst,
1143: $onchangesecond
1.36 matthew 1144: ) = @_;
1145: my $second = "document.$formname.$secondselectname";
1146: my $first = "document.$formname.$firstselectname";
1147: # output the javascript to do the changing
1148: my $result = '';
1.776 bisitz 1149: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1150: $result.="// <![CDATA[\n";
1.36 matthew 1151: $result.="var select2data = new Object();\n";
1152: $" = '","';
1153: my $debug = '';
1154: foreach my $s1 (sort(keys(%$hashref))) {
1155: $result.="select2data.d_$s1 = new Object();\n";
1156: $result.="select2data.d_$s1.def = new String('".
1157: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1158: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1159: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1160: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1161: @s2values = @{$hashref->{$s1}->{'order'}};
1162: }
1.36 matthew 1163: $result.="\"@s2values\");\n";
1164: $result.="select2data.d_$s1.texts = new Array(";
1165: my @s2texts;
1166: foreach my $value (@s2values) {
1167: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1168: }
1169: $result.="\"@s2texts\");\n";
1170: }
1171: $"=' ';
1172: $result.= <<"END";
1173:
1174: function select1_changed() {
1175: // Determine new choice
1176: var newvalue = "d_" + $first.value;
1177: // update select2
1178: var values = select2data[newvalue].values;
1179: var texts = select2data[newvalue].texts;
1180: var select2def = select2data[newvalue].def;
1181: var i;
1182: // out with the old
1183: for (i = 0; i < $second.options.length; i++) {
1184: $second.options[i] = null;
1185: }
1186: // in with the nuclear
1187: for (i=0;i<values.length; i++) {
1188: $second.options[i] = new Option(values[i]);
1.143 matthew 1189: $second.options[i].value = values[i];
1.36 matthew 1190: $second.options[i].text = texts[i];
1191: if (values[i] == select2def) {
1192: $second.options[i].selected = true;
1193: }
1194: }
1195: }
1.824 bisitz 1196: // ]]>
1.36 matthew 1197: </script>
1198: END
1199: # output the initial values for the selection lists
1.1115 raeburn 1200: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1201: my @order = sort(keys(%{$hashref}));
1202: if (ref($menuorder) eq 'ARRAY') {
1203: @order = @{$menuorder};
1204: }
1205: foreach my $value (@order) {
1.36 matthew 1206: $result.=" <option value=\"$value\" ";
1.253 albertel 1207: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1208: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1209: }
1210: $result .= "</select>\n";
1211: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1212: $result .= $middletext;
1.1115 raeburn 1213: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1214: if ($onchangesecond) {
1215: $result .= ' onchange="'.$onchangesecond.'"';
1216: }
1217: $result .= ">\n";
1.36 matthew 1218: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1219:
1220: my @secondorder = sort(keys(%select2));
1221: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1222: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1223: }
1224: foreach my $value (@secondorder) {
1.36 matthew 1225: $result.=" <option value=\"$value\" ";
1.253 albertel 1226: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1227: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1228: }
1229: $result .= "</select>\n";
1230: # return $debug;
1231: return $result;
1232: } # end of sub linked_select_forms {
1233:
1.45 matthew 1234: =pod
1.44 bowersj2 1235:
1.973 raeburn 1236: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1237:
1.112 bowersj2 1238: Returns a string corresponding to an HTML link to the given help
1239: $topic, where $topic corresponds to the name of a .tex file in
1240: /home/httpd/html/adm/help/tex, with underscores replaced by
1241: spaces.
1242:
1243: $text will optionally be linked to the same topic, allowing you to
1244: link text in addition to the graphic. If you do not want to link
1245: text, but wish to specify one of the later parameters, pass an
1246: empty string.
1247:
1248: $stayOnPage is a value that will be interpreted as a boolean. If true,
1249: the link will not open a new window. If false, the link will open
1250: a new window using Javascript. (Default is false.)
1251:
1252: $width and $height are optional numerical parameters that will
1253: override the width and height of the popped up window, which may
1.973 raeburn 1254: be useful for certain help topics with big pictures included.
1255:
1256: $imgid is the id of the img tag used for the help icon. This may be
1257: used in a javascript call to switch the image src. See
1258: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1259:
1260: =cut
1261:
1262: sub help_open_topic {
1.973 raeburn 1263: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1264: $text = "" if (not defined $text);
1.44 bowersj2 1265: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1266: $width = 500 if (not defined $width);
1.44 bowersj2 1267: $height = 400 if (not defined $height);
1268: my $filename = $topic;
1269: $filename =~ s/ /_/g;
1270:
1.48 bowersj2 1271: my $template = "";
1272: my $link;
1.572 banghart 1273:
1.159 www 1274: $topic=~s/\W/\_/g;
1.44 bowersj2 1275:
1.572 banghart 1276: if (!$stayOnPage) {
1.1033 www 1277: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1278: } elsif ($stayOnPage eq 'popup') {
1279: $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 1280: } else {
1.48 bowersj2 1281: $link = "/adm/help/${filename}.hlp";
1282: }
1283:
1284: # Add the text
1.755 neumanie 1285: if ($text ne "") {
1.763 bisitz 1286: $template.='<span class="LC_help_open_topic">'
1287: .'<a target="_top" href="'.$link.'">'
1288: .$text.'</a>';
1.48 bowersj2 1289: }
1290:
1.763 bisitz 1291: # (Always) Add the graphic
1.179 matthew 1292: my $title = &mt('Online Help');
1.667 raeburn 1293: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1294: if ($imgid ne '') {
1295: $imgid = ' id="'.$imgid.'"';
1296: }
1.763 bisitz 1297: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1298: .'<img src="'.$helpicon.'" border="0"'
1299: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1300: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1301: .' /></a>';
1302: if ($text ne "") {
1303: $template.='</span>';
1304: }
1.44 bowersj2 1305: return $template;
1306:
1.106 bowersj2 1307: }
1308:
1309: # This is a quicky function for Latex cheatsheet editing, since it
1310: # appears in at least four places
1311: sub helpLatexCheatsheet {
1.1037 www 1312: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1313: my $out;
1.106 bowersj2 1314: my $addOther = '';
1.732 raeburn 1315: if ($topic) {
1.1037 www 1316: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1317: }
1318: $out = '<span>' # Start cheatsheet
1319: .$addOther
1320: .'<span>'
1.1037 www 1321: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1322: .'</span> <span>'
1.1037 www 1323: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1324: .'</span>';
1.732 raeburn 1325: unless ($not_author) {
1.1186 kruse 1326: $out .= '<span>'
1327: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1328: .'</span> <span>'
1329: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1330: .'</span>';
1.732 raeburn 1331: }
1.763 bisitz 1332: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1333: return $out;
1.172 www 1334: }
1335:
1.430 albertel 1336: sub general_help {
1337: my $helptopic='Student_Intro';
1338: if ($env{'request.role'}=~/^(ca|au)/) {
1339: $helptopic='Authoring_Intro';
1.907 raeburn 1340: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1341: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1342: } elsif ($env{'request.role'}=~/^dc/) {
1343: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1344: }
1345: return $helptopic;
1346: }
1347:
1348: sub update_help_link {
1349: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1350: my $origurl = $ENV{'REQUEST_URI'};
1351: $origurl=~s|^/~|/priv/|;
1352: my $timestamp = time;
1353: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1354: $$datum = &escape($$datum);
1355: }
1356:
1357: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1358: my $output .= <<"ENDOUTPUT";
1359: <script type="text/javascript">
1.824 bisitz 1360: // <![CDATA[
1.430 albertel 1361: banner_link = '$banner_link';
1.824 bisitz 1362: // ]]>
1.430 albertel 1363: </script>
1364: ENDOUTPUT
1365: return $output;
1366: }
1367:
1368: # now just updates the help link and generates a blue icon
1.193 raeburn 1369: sub help_open_menu {
1.430 albertel 1370: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1371: = @_;
1.949 droeschl 1372: $stayOnPage = 1;
1.430 albertel 1373: my $output;
1374: if ($component_help) {
1375: if (!$text) {
1376: $output=&help_open_topic($component_help,undef,$stayOnPage,
1377: $width,$height);
1378: } else {
1379: my $help_text;
1380: $help_text=&unescape($topic);
1381: $output='<table><tr><td>'.
1382: &help_open_topic($component_help,$help_text,$stayOnPage,
1383: $width,$height).'</td></tr></table>';
1384: }
1385: }
1386: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1387: return $output.$banner_link;
1388: }
1389:
1390: sub top_nav_help {
1391: my ($text) = @_;
1.436 albertel 1392: $text = &mt($text);
1.949 droeschl 1393: my $stay_on_page = 1;
1394:
1.1168 raeburn 1395: my ($link,$banner_link);
1396: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1397: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1398: : "javascript:helpMenu('open')";
1399: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1400: }
1.201 raeburn 1401: my $title = &mt('Get help');
1.1168 raeburn 1402: if ($link) {
1403: return <<"END";
1.436 albertel 1404: $banner_link
1.1159 raeburn 1405: <a href="$link" title="$title">$text</a>
1.436 albertel 1406: END
1.1168 raeburn 1407: } else {
1408: return ' '.$text.' ';
1409: }
1.436 albertel 1410: }
1411:
1412: sub help_menu_js {
1.1154 raeburn 1413: my ($httphost) = @_;
1.949 droeschl 1414: my $stayOnPage = 1;
1.436 albertel 1415: my $width = 620;
1416: my $height = 600;
1.430 albertel 1417: my $helptopic=&general_help();
1.1154 raeburn 1418: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1419: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1420: my $start_page =
1421: &Apache::loncommon::start_page('Help Menu', undef,
1422: {'frameset' => 1,
1423: 'js_ready' => 1,
1.1154 raeburn 1424: 'use_absolute' => $httphost,
1.331 albertel 1425: 'add_entries' => {
1.1168 raeburn 1426: 'border' => '0',
1.579 raeburn 1427: 'rows' => "110,*",},});
1.331 albertel 1428: my $end_page =
1429: &Apache::loncommon::end_page({'frameset' => 1,
1430: 'js_ready' => 1,});
1431:
1.436 albertel 1432: my $template .= <<"ENDTEMPLATE";
1433: <script type="text/javascript">
1.877 bisitz 1434: // <![CDATA[
1.253 albertel 1435: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1436: var banner_link = '';
1.243 raeburn 1437: function helpMenu(target) {
1438: var caller = this;
1439: if (target == 'open') {
1440: var newWindow = null;
1441: try {
1.262 albertel 1442: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1443: }
1444: catch(error) {
1445: writeHelp(caller);
1446: return;
1447: }
1448: if (newWindow) {
1449: caller = newWindow;
1450: }
1.193 raeburn 1451: }
1.243 raeburn 1452: writeHelp(caller);
1453: return;
1454: }
1455: function writeHelp(caller) {
1.1168 raeburn 1456: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1457: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1458: caller.document.close();
1459: caller.focus();
1.193 raeburn 1460: }
1.877 bisitz 1461: // END LON-CAPA Internal -->
1.253 albertel 1462: // ]]>
1.436 albertel 1463: </script>
1.193 raeburn 1464: ENDTEMPLATE
1465: return $template;
1466: }
1467:
1.172 www 1468: sub help_open_bug {
1469: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1470: unless ($env{'user.adv'}) { return ''; }
1.172 www 1471: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1472: $text = "" if (not defined $text);
1473: $stayOnPage=1;
1.184 albertel 1474: $width = 600 if (not defined $width);
1475: $height = 600 if (not defined $height);
1.172 www 1476:
1477: $topic=~s/\W+/\+/g;
1478: my $link='';
1479: my $template='';
1.379 albertel 1480: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1481: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1482: if (!$stayOnPage)
1483: {
1484: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1485: }
1486: else
1487: {
1488: $link = $url;
1489: }
1490: # Add the text
1491: if ($text ne "")
1492: {
1493: $template .=
1494: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1495: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1496: }
1497:
1498: # Add the graphic
1.179 matthew 1499: my $title = &mt('Report a Bug');
1.215 albertel 1500: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1501: $template .= <<"ENDTEMPLATE";
1.436 albertel 1502: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1503: ENDTEMPLATE
1504: if ($text ne '') { $template.='</td></tr></table>' };
1505: return $template;
1506:
1507: }
1508:
1509: sub help_open_faq {
1510: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1511: unless ($env{'user.adv'}) { return ''; }
1.172 www 1512: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1513: $text = "" if (not defined $text);
1514: $stayOnPage=1;
1515: $width = 350 if (not defined $width);
1516: $height = 400 if (not defined $height);
1517:
1518: $topic=~s/\W+/\+/g;
1519: my $link='';
1520: my $template='';
1521: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1522: if (!$stayOnPage)
1523: {
1524: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1525: }
1526: else
1527: {
1528: $link = $url;
1529: }
1530:
1531: # Add the text
1532: if ($text ne "")
1533: {
1534: $template .=
1.173 www 1535: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1536: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1537: }
1538:
1539: # Add the graphic
1.179 matthew 1540: my $title = &mt('View the FAQ');
1.215 albertel 1541: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1542: $template .= <<"ENDTEMPLATE";
1.436 albertel 1543: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1544: ENDTEMPLATE
1545: if ($text ne '') { $template.='</td></tr></table>' };
1546: return $template;
1547:
1.44 bowersj2 1548: }
1.37 matthew 1549:
1.180 matthew 1550: ###############################################################
1551: ###############################################################
1552:
1.45 matthew 1553: =pod
1554:
1.648 raeburn 1555: =item * &change_content_javascript():
1.256 matthew 1556:
1557: This and the next function allow you to create small sections of an
1558: otherwise static HTML page that you can update on the fly with
1559: Javascript, even in Netscape 4.
1560:
1561: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1562: must be written to the HTML page once. It will prove the Javascript
1563: function "change(name, content)". Calling the change function with the
1564: name of the section
1565: you want to update, matching the name passed to C<changable_area>, and
1566: the new content you want to put in there, will put the content into
1567: that area.
1568:
1569: B<Note>: Netscape 4 only reserves enough space for the changable area
1570: to contain room for the original contents. You need to "make space"
1571: for whatever changes you wish to make, and be B<sure> to check your
1572: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1573: it's adequate for updating a one-line status display, but little more.
1574: This script will set the space to 100% width, so you only need to
1575: worry about height in Netscape 4.
1576:
1577: Modern browsers are much less limiting, and if you can commit to the
1578: user not using Netscape 4, this feature may be used freely with
1579: pretty much any HTML.
1580:
1581: =cut
1582:
1583: sub change_content_javascript {
1584: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1585: if ($env{'browser.type'} eq 'netscape' &&
1586: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1587: return (<<NETSCAPE4);
1588: function change(name, content) {
1589: doc = document.layers[name+"___escape"].layers[0].document;
1590: doc.open();
1591: doc.write(content);
1592: doc.close();
1593: }
1594: NETSCAPE4
1595: } else {
1596: # Otherwise, we need to use semi-standards-compliant code
1597: # (technically, "innerHTML" isn't standard but the equivalent
1598: # is really scary, and every useful browser supports it
1599: return (<<DOMBASED);
1600: function change(name, content) {
1601: element = document.getElementById(name);
1602: element.innerHTML = content;
1603: }
1604: DOMBASED
1605: }
1606: }
1607:
1608: =pod
1609:
1.648 raeburn 1610: =item * &changable_area($name,$origContent):
1.256 matthew 1611:
1612: This provides a "changable area" that can be modified on the fly via
1613: the Javascript code provided in C<change_content_javascript>. $name is
1614: the name you will use to reference the area later; do not repeat the
1615: same name on a given HTML page more then once. $origContent is what
1616: the area will originally contain, which can be left blank.
1617:
1618: =cut
1619:
1620: sub changable_area {
1621: my ($name, $origContent) = @_;
1622:
1.258 albertel 1623: if ($env{'browser.type'} eq 'netscape' &&
1624: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1625: # If this is netscape 4, we need to use the Layer tag
1626: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1627: } else {
1628: return "<span id='$name'>$origContent</span>";
1629: }
1630: }
1631:
1632: =pod
1633:
1.648 raeburn 1634: =item * &viewport_geometry_js
1.590 raeburn 1635:
1636: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1637:
1638: =cut
1639:
1640:
1641: sub viewport_geometry_js {
1642: return <<"GEOMETRY";
1643: var Geometry = {};
1644: function init_geometry() {
1645: if (Geometry.init) { return };
1646: Geometry.init=1;
1647: if (window.innerHeight) {
1648: Geometry.getViewportHeight = function() { return window.innerHeight; };
1649: Geometry.getViewportWidth = function() { return window.innerWidth; };
1650: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1651: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1652: }
1653: else if (document.documentElement && document.documentElement.clientHeight) {
1654: Geometry.getViewportHeight =
1655: function() { return document.documentElement.clientHeight; };
1656: Geometry.getViewportWidth =
1657: function() { return document.documentElement.clientWidth; };
1658:
1659: Geometry.getHorizontalScroll =
1660: function() { return document.documentElement.scrollLeft; };
1661: Geometry.getVerticalScroll =
1662: function() { return document.documentElement.scrollTop; };
1663: }
1664: else if (document.body.clientHeight) {
1665: Geometry.getViewportHeight =
1666: function() { return document.body.clientHeight; };
1667: Geometry.getViewportWidth =
1668: function() { return document.body.clientWidth; };
1669: Geometry.getHorizontalScroll =
1670: function() { return document.body.scrollLeft; };
1671: Geometry.getVerticalScroll =
1672: function() { return document.body.scrollTop; };
1673: }
1674: }
1675:
1676: GEOMETRY
1677: }
1678:
1679: =pod
1680:
1.648 raeburn 1681: =item * &viewport_size_js()
1.590 raeburn 1682:
1683: 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.
1684:
1685: =cut
1686:
1687: sub viewport_size_js {
1688: my $geometry = &viewport_geometry_js();
1689: return <<"DIMS";
1690:
1691: $geometry
1692:
1693: function getViewportDims(width,height) {
1694: init_geometry();
1695: width.value = Geometry.getViewportWidth();
1696: height.value = Geometry.getViewportHeight();
1697: return;
1698: }
1699:
1700: DIMS
1701: }
1702:
1703: =pod
1704:
1.648 raeburn 1705: =item * &resize_textarea_js()
1.565 albertel 1706:
1707: emits the needed javascript to resize a textarea to be as big as possible
1708:
1709: creates a function resize_textrea that takes two IDs first should be
1710: the id of the element to resize, second should be the id of a div that
1711: surrounds everything that comes after the textarea, this routine needs
1712: to be attached to the <body> for the onload and onresize events.
1713:
1.648 raeburn 1714: =back
1.565 albertel 1715:
1716: =cut
1717:
1718: sub resize_textarea_js {
1.590 raeburn 1719: my $geometry = &viewport_geometry_js();
1.565 albertel 1720: return <<"RESIZE";
1721: <script type="text/javascript">
1.824 bisitz 1722: // <![CDATA[
1.590 raeburn 1723: $geometry
1.565 albertel 1724:
1.588 albertel 1725: function getX(element) {
1726: var x = 0;
1727: while (element) {
1728: x += element.offsetLeft;
1729: element = element.offsetParent;
1730: }
1731: return x;
1732: }
1733: function getY(element) {
1734: var y = 0;
1735: while (element) {
1736: y += element.offsetTop;
1737: element = element.offsetParent;
1738: }
1739: return y;
1740: }
1741:
1742:
1.565 albertel 1743: function resize_textarea(textarea_id,bottom_id) {
1744: init_geometry();
1745: var textarea = document.getElementById(textarea_id);
1746: //alert(textarea);
1747:
1.588 albertel 1748: var textarea_top = getY(textarea);
1.565 albertel 1749: var textarea_height = textarea.offsetHeight;
1750: var bottom = document.getElementById(bottom_id);
1.588 albertel 1751: var bottom_top = getY(bottom);
1.565 albertel 1752: var bottom_height = bottom.offsetHeight;
1753: var window_height = Geometry.getViewportHeight();
1.588 albertel 1754: var fudge = 23;
1.565 albertel 1755: var new_height = window_height-fudge-textarea_top-bottom_height;
1756: if (new_height < 300) {
1757: new_height = 300;
1758: }
1759: textarea.style.height=new_height+'px';
1760: }
1.824 bisitz 1761: // ]]>
1.565 albertel 1762: </script>
1763: RESIZE
1764:
1765: }
1766:
1.1205 golterma 1767: sub colorfuleditor_js {
1768: return <<"COLORFULEDIT"
1769: <script type="text/javascript">
1770: // <![CDATA[>
1771: function fold_box(curDepth, lastresource){
1772:
1773: // we need a list because there can be several blocks you need to fold in one tag
1774: var block = document.getElementsByName('foldblock_'+curDepth);
1775: // but there is only one folding button per tag
1776: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1777:
1778: if(block.item(0).style.display == 'none'){
1779:
1780: foldbutton.value = '@{[&mt("Hide")]}';
1781: for (i = 0; i < block.length; i++){
1782: block.item(i).style.display = '';
1783: }
1784: }else{
1785:
1786: foldbutton.value = '@{[&mt("Show")]}';
1787: for (i = 0; i < block.length; i++){
1788: // block.item(i).style.visibility = 'collapse';
1789: block.item(i).style.display = 'none';
1790: }
1791: };
1792: saveState(lastresource);
1793: }
1794:
1795: function saveState (lastresource) {
1796:
1797: var tag_list = getTagList();
1798: if(tag_list != null){
1799: var timestamp = new Date().getTime();
1800: var key = lastresource;
1801:
1802: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1803: // starting with timestamp
1804: var value = timestamp+';';
1805:
1806: // building the list of key-value pairs
1807: for(var i = 0; i < tag_list.length; i++){
1808: value += tag_list[i]+',';
1809: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1810: }
1811:
1812: // only iterate whole storage if nothing to override
1813: if(localStorage.getItem(key) == null){
1814:
1815: // prevent storage from growing large
1816: if(localStorage.length > 50){
1817: var regex_getTimestamp = /^(?:\d)+;/;
1818: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1819: var oldest_key;
1820:
1821: for(var i = 1; i < localStorage.length; i++){
1822: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1823: oldest_key = localStorage.key(i);
1824: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1825: }
1826: }
1827: localStorage.removeItem(oldest_key);
1828: }
1829: }
1830: localStorage.setItem(key,value);
1831: }
1832: }
1833:
1834: // restore folding status of blocks (on page load)
1835: function restoreState (lastresource) {
1836: if(localStorage.getItem(lastresource) != null){
1837: var key = lastresource;
1838: var value = localStorage.getItem(key);
1839: var regex_delTimestamp = /^\d+;/;
1840:
1841: value.replace(regex_delTimestamp, '');
1842:
1843: var valueArr = value.split(';');
1844: var pairs;
1845: var elements;
1846: for (var i = 0; i < valueArr.length; i++){
1847: pairs = valueArr[i].split(',');
1848: elements = document.getElementsByName(pairs[0]);
1849:
1850: for (var j = 0; j < elements.length; j++){
1851: elements[j].style.display = pairs[1];
1852: if (pairs[1] == "none"){
1853: var regex_id = /([_\\d]+)\$/;
1854: regex_id.exec(pairs[0]);
1855: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1856: }
1857: }
1858: }
1859: }
1860: }
1861:
1862: function getTagList () {
1863:
1864: var stringToSearch = document.lonhomework.innerHTML;
1865:
1866: var ret = new Array();
1867: var regex_findBlock = /(foldblock_.*?)"/g;
1868: var tag_list = stringToSearch.match(regex_findBlock);
1869:
1870: if(tag_list != null){
1871: for(var i = 0; i < tag_list.length; i++){
1872: ret.push(tag_list[i].replace(/"/, ''));
1873: }
1874: }
1875: return ret;
1876: }
1877:
1878: function saveScrollPosition (resource) {
1879: var tag_list = getTagList();
1880:
1881: // we dont always want to jump to the first block
1882: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1883: if(\$(window).scrollTop() > 170){
1884: if(tag_list != null){
1885: var result;
1886: for(var i = 0; i < tag_list.length; i++){
1887: if(isElementInViewport(tag_list[i])){
1888: result += tag_list[i]+';';
1889: }
1890: }
1891: sessionStorage.setItem('anchor_'+resource, result);
1892: }
1893: } else {
1894: // we dont need to save zero, just delete the item to leave everything tidy
1895: sessionStorage.removeItem('anchor_'+resource);
1896: }
1897: }
1898:
1899: function restoreScrollPosition(resource){
1900:
1901: var elem = sessionStorage.getItem('anchor_'+resource);
1902: if(elem != null){
1903: var tag_list = elem.split(';');
1904: var elem_list;
1905:
1906: for(var i = 0; i < tag_list.length; i++){
1907: elem_list = document.getElementsByName(tag_list[i]);
1908:
1909: if(elem_list.length > 0){
1910: elem = elem_list[0];
1911: break;
1912: }
1913: }
1914: elem.scrollIntoView();
1915: }
1916: }
1917:
1918: function isElementInViewport(el) {
1919:
1920: // change to last element instead of first
1921: var elem = document.getElementsByName(el);
1922: var rect = elem[0].getBoundingClientRect();
1923:
1924: return (
1925: rect.top >= 0 &&
1926: rect.left >= 0 &&
1927: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1928: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1929: );
1930: }
1931:
1932: function autosize(depth){
1933: var cmInst = window['cm'+depth];
1934: var fitsizeButton = document.getElementById('fitsize'+depth);
1935:
1936: // is fixed size, switching to dynamic
1937: if (sessionStorage.getItem("autosized_"+depth) == null) {
1938: cmInst.setSize("","auto");
1939: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1940: sessionStorage.setItem("autosized_"+depth, "yes");
1941:
1942: // is dynamic size, switching to fixed
1943: } else {
1944: cmInst.setSize("","300px");
1945: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1946: sessionStorage.removeItem("autosized_"+depth);
1947: }
1948: }
1949:
1950:
1951:
1952: // ]]>
1953: </script>
1954: COLORFULEDIT
1955: }
1956:
1957: sub xmleditor_js {
1958: return <<XMLEDIT
1959: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1960: <script type="text/javascript">
1961: // <![CDATA[>
1962:
1963: function saveScrollPosition (resource) {
1964:
1965: var scrollPos = \$(window).scrollTop();
1966: sessionStorage.setItem(resource,scrollPos);
1967: }
1968:
1969: function restoreScrollPosition(resource){
1970:
1971: var scrollPos = sessionStorage.getItem(resource);
1972: \$(window).scrollTop(scrollPos);
1973: }
1974:
1975: // unless internet explorer
1976: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1977:
1978: \$(document).ready(function() {
1979: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1980: });
1981: }
1982:
1983: // inserts text at cursor position into codemirror (xml editor only)
1984: function insertText(text){
1985: cm.focus();
1986: var curPos = cm.getCursor();
1987: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
1988: }
1989: // ]]>
1990: </script>
1991: XMLEDIT
1992: }
1993:
1994: sub insert_folding_button {
1995: my $curDepth = $Apache::lonxml::curdepth;
1996: my $lastresource = $env{'request.ambiguous'};
1997:
1998: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
1999: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2000: }
2001:
1.565 albertel 2002: =pod
2003:
1.256 matthew 2004: =head1 Excel and CSV file utility routines
2005:
2006: =cut
2007:
2008: ###############################################################
2009: ###############################################################
2010:
2011: =pod
2012:
1.1162 raeburn 2013: =over 4
2014:
1.648 raeburn 2015: =item * &csv_translate($text)
1.37 matthew 2016:
1.185 www 2017: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2018: format.
2019:
2020: =cut
2021:
1.180 matthew 2022: ###############################################################
2023: ###############################################################
1.37 matthew 2024: sub csv_translate {
2025: my $text = shift;
2026: $text =~ s/\"/\"\"/g;
1.209 albertel 2027: $text =~ s/\n/ /g;
1.37 matthew 2028: return $text;
2029: }
1.180 matthew 2030:
2031: ###############################################################
2032: ###############################################################
2033:
2034: =pod
2035:
1.648 raeburn 2036: =item * &define_excel_formats()
1.180 matthew 2037:
2038: Define some commonly used Excel cell formats.
2039:
2040: Currently supported formats:
2041:
2042: =over 4
2043:
2044: =item header
2045:
2046: =item bold
2047:
2048: =item h1
2049:
2050: =item h2
2051:
2052: =item h3
2053:
1.256 matthew 2054: =item h4
2055:
2056: =item i
2057:
1.180 matthew 2058: =item date
2059:
2060: =back
2061:
2062: Inputs: $workbook
2063:
2064: Returns: $format, a hash reference.
2065:
1.1057 foxr 2066:
1.180 matthew 2067: =cut
2068:
2069: ###############################################################
2070: ###############################################################
2071: sub define_excel_formats {
2072: my ($workbook) = @_;
2073: my $format;
2074: $format->{'header'} = $workbook->add_format(bold => 1,
2075: bottom => 1,
2076: align => 'center');
2077: $format->{'bold'} = $workbook->add_format(bold=>1);
2078: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2079: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2080: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2081: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2082: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2083: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2084: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2085: return $format;
2086: }
2087:
2088: ###############################################################
2089: ###############################################################
1.113 bowersj2 2090:
2091: =pod
2092:
1.648 raeburn 2093: =item * &create_workbook()
1.255 matthew 2094:
2095: Create an Excel worksheet. If it fails, output message on the
2096: request object and return undefs.
2097:
2098: Inputs: Apache request object
2099:
2100: Returns (undef) on failure,
2101: Excel worksheet object, scalar with filename, and formats
2102: from &Apache::loncommon::define_excel_formats on success
2103:
2104: =cut
2105:
2106: ###############################################################
2107: ###############################################################
2108: sub create_workbook {
2109: my ($r) = @_;
2110: #
2111: # Create the excel spreadsheet
2112: my $filename = '/prtspool/'.
1.258 albertel 2113: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2114: time.'_'.rand(1000000000).'.xls';
2115: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2116: if (! defined($workbook)) {
2117: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2118: $r->print(
2119: '<p class="LC_error">'
2120: .&mt('Problems occurred in creating the new Excel file.')
2121: .' '.&mt('This error has been logged.')
2122: .' '.&mt('Please alert your LON-CAPA administrator.')
2123: .'</p>'
2124: );
1.255 matthew 2125: return (undef);
2126: }
2127: #
1.1014 foxr 2128: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2129: #
2130: my $format = &Apache::loncommon::define_excel_formats($workbook);
2131: return ($workbook,$filename,$format);
2132: }
2133:
2134: ###############################################################
2135: ###############################################################
2136:
2137: =pod
2138:
1.648 raeburn 2139: =item * &create_text_file()
1.113 bowersj2 2140:
1.542 raeburn 2141: Create a file to write to and eventually make available to the user.
1.256 matthew 2142: If file creation fails, outputs an error message on the request object and
2143: return undefs.
1.113 bowersj2 2144:
1.256 matthew 2145: Inputs: Apache request object, and file suffix
1.113 bowersj2 2146:
1.256 matthew 2147: Returns (undef) on failure,
2148: Filehandle and filename on success.
1.113 bowersj2 2149:
2150: =cut
2151:
1.256 matthew 2152: ###############################################################
2153: ###############################################################
2154: sub create_text_file {
2155: my ($r,$suffix) = @_;
2156: if (! defined($suffix)) { $suffix = 'txt'; };
2157: my $fh;
2158: my $filename = '/prtspool/'.
1.258 albertel 2159: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2160: time.'_'.rand(1000000000).'.'.$suffix;
2161: $fh = Apache::File->new('>/home/httpd'.$filename);
2162: if (! defined($fh)) {
2163: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2164: $r->print(
2165: '<p class="LC_error">'
2166: .&mt('Problems occurred in creating the output file.')
2167: .' '.&mt('This error has been logged.')
2168: .' '.&mt('Please alert your LON-CAPA administrator.')
2169: .'</p>'
2170: );
1.113 bowersj2 2171: }
1.256 matthew 2172: return ($fh,$filename)
1.113 bowersj2 2173: }
2174:
2175:
1.256 matthew 2176: =pod
1.113 bowersj2 2177:
2178: =back
2179:
2180: =cut
1.37 matthew 2181:
2182: ###############################################################
1.33 matthew 2183: ## Home server <option> list generating code ##
2184: ###############################################################
1.35 matthew 2185:
1.169 www 2186: # ------------------------------------------
2187:
2188: sub domain_select {
2189: my ($name,$value,$multiple)=@_;
2190: my %domains=map {
1.514 albertel 2191: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2192: } &Apache::lonnet::all_domains();
1.169 www 2193: if ($multiple) {
2194: $domains{''}=&mt('Any domain');
1.550 albertel 2195: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2196: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2197: } else {
1.550 albertel 2198: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2199: return &select_form($name,$value,\%domains);
1.169 www 2200: }
2201: }
2202:
1.282 albertel 2203: #-------------------------------------------
2204:
2205: =pod
2206:
1.519 raeburn 2207: =head1 Routines for form select boxes
2208:
2209: =over 4
2210:
1.648 raeburn 2211: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2212:
2213: Returns a string containing a <select> element int multiple mode
2214:
2215:
2216: Args:
2217: $name - name of the <select> element
1.506 raeburn 2218: $value - scalar or array ref of values that should already be selected
1.282 albertel 2219: $size - number of rows long the select element is
1.283 albertel 2220: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2221: (shown text should already have been &mt())
1.506 raeburn 2222: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2223:
1.282 albertel 2224: =cut
2225:
2226: #-------------------------------------------
1.169 www 2227: sub multiple_select_form {
1.284 albertel 2228: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2229: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2230: my $output='';
1.191 matthew 2231: if (! defined($size)) {
2232: $size = 4;
1.283 albertel 2233: if (scalar(keys(%$hash))<4) {
2234: $size = scalar(keys(%$hash));
1.191 matthew 2235: }
2236: }
1.734 bisitz 2237: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2238: my @order;
1.506 raeburn 2239: if (ref($order) eq 'ARRAY') {
2240: @order = @{$order};
2241: } else {
2242: @order = sort(keys(%$hash));
1.501 banghart 2243: }
2244: if (exists($$hash{'select_form_order'})) {
2245: @order = @{$$hash{'select_form_order'}};
2246: }
2247:
1.284 albertel 2248: foreach my $key (@order) {
1.356 albertel 2249: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2250: $output.='selected="selected" ' if ($selected{$key});
2251: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2252: }
2253: $output.="</select>\n";
2254: return $output;
2255: }
2256:
1.88 www 2257: #-------------------------------------------
2258:
2259: =pod
2260:
1.970 raeburn 2261: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 2262:
2263: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2264: allow a user to select options from a ref to a hash containing:
2265: option_name => displayed text. An optional $onchange can include
2266: a javascript onchange item, e.g., onchange="this.form.submit();"
2267:
1.88 www 2268: See lonrights.pm for an example invocation and use.
2269:
2270: =cut
2271:
2272: #-------------------------------------------
2273: sub select_form {
1.1228 ! raeburn 2274: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2275: return unless (ref($hashref) eq 'HASH');
2276: if ($onchange) {
2277: $onchange = ' onchange="'.$onchange.'"';
2278: }
1.1228 ! raeburn 2279: my $disabled;
! 2280: if ($readonly) {
! 2281: $disabled = ' disabled="disabled"';
! 2282: }
! 2283: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2284: my @keys;
1.970 raeburn 2285: if (exists($hashref->{'select_form_order'})) {
2286: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2287: } else {
1.970 raeburn 2288: @keys=sort(keys(%{$hashref}));
1.128 albertel 2289: }
1.356 albertel 2290: foreach my $key (@keys) {
2291: $selectform.=
2292: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2293: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2294: ">".$hashref->{$key}."</option>\n";
1.88 www 2295: }
2296: $selectform.="</select>";
2297: return $selectform;
2298: }
2299:
1.475 www 2300: # For display filters
2301:
2302: sub display_filter {
1.1074 raeburn 2303: my ($context) = @_;
1.475 www 2304: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2305: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2306: my $phraseinput = 'hidden';
2307: my $includeinput = 'hidden';
2308: my ($checked,$includetypestext);
2309: if ($env{'form.displayfilter'} eq 'containing') {
2310: $phraseinput = 'text';
2311: if ($context eq 'parmslog') {
2312: $includeinput = 'checkbox';
2313: if ($env{'form.includetypes'}) {
2314: $checked = ' checked="checked"';
2315: }
2316: $includetypestext = &mt('Include parameter types');
2317: }
2318: } else {
2319: $includetypestext = ' ';
2320: }
2321: my ($additional,$secondid,$thirdid);
2322: if ($context eq 'parmslog') {
2323: $additional =
2324: '<label><input type="'.$includeinput.'" name="includetypes"'.
2325: $checked.' name="includetypes" value="1" id="includetypes" />'.
2326: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2327: '</label>';
2328: $secondid = 'includetypes';
2329: $thirdid = 'includetypestext';
2330: }
2331: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2332: '$secondid','$thirdid')";
2333: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2334: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2335: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2336: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2337: &mt('Filter: [_1]',
1.477 www 2338: &select_form($env{'form.displayfilter'},
2339: 'displayfilter',
1.970 raeburn 2340: {'currentfolder' => 'Current folder/page',
1.477 www 2341: 'containing' => 'Containing phrase',
1.1074 raeburn 2342: 'none' => 'None'},$onchange)).' '.
2343: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2344: &HTML::Entities::encode($env{'form.containingphrase'}).
2345: '" />'.$additional;
2346: }
2347:
2348: sub display_filter_js {
2349: my $includetext = &mt('Include parameter types');
2350: return <<"ENDJS";
2351:
2352: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2353: var firstType = 'hidden';
2354: if (setter.options[setter.selectedIndex].value == 'containing') {
2355: firstType = 'text';
2356: }
2357: firstObject = document.getElementById(firstid);
2358: if (typeof(firstObject) == 'object') {
2359: if (firstObject.type != firstType) {
2360: changeInputType(firstObject,firstType);
2361: }
2362: }
2363: if (context == 'parmslog') {
2364: var secondType = 'hidden';
2365: if (firstType == 'text') {
2366: secondType = 'checkbox';
2367: }
2368: secondObject = document.getElementById(secondid);
2369: if (typeof(secondObject) == 'object') {
2370: if (secondObject.type != secondType) {
2371: changeInputType(secondObject,secondType);
2372: }
2373: }
2374: var textItem = document.getElementById(thirdid);
2375: var currtext = textItem.innerHTML;
2376: var newtext;
2377: if (firstType == 'text') {
2378: newtext = '$includetext';
2379: } else {
2380: newtext = ' ';
2381: }
2382: if (currtext != newtext) {
2383: textItem.innerHTML = newtext;
2384: }
2385: }
2386: return;
2387: }
2388:
2389: function changeInputType(oldObject,newType) {
2390: var newObject = document.createElement('input');
2391: newObject.type = newType;
2392: if (oldObject.size) {
2393: newObject.size = oldObject.size;
2394: }
2395: if (oldObject.value) {
2396: newObject.value = oldObject.value;
2397: }
2398: if (oldObject.name) {
2399: newObject.name = oldObject.name;
2400: }
2401: if (oldObject.id) {
2402: newObject.id = oldObject.id;
2403: }
2404: oldObject.parentNode.replaceChild(newObject,oldObject);
2405: return;
2406: }
2407:
2408: ENDJS
1.475 www 2409: }
2410:
1.167 www 2411: sub gradeleveldescription {
2412: my $gradelevel=shift;
2413: my %gradelevels=(0 => 'Not specified',
2414: 1 => 'Grade 1',
2415: 2 => 'Grade 2',
2416: 3 => 'Grade 3',
2417: 4 => 'Grade 4',
2418: 5 => 'Grade 5',
2419: 6 => 'Grade 6',
2420: 7 => 'Grade 7',
2421: 8 => 'Grade 8',
2422: 9 => 'Grade 9',
2423: 10 => 'Grade 10',
2424: 11 => 'Grade 11',
2425: 12 => 'Grade 12',
2426: 13 => 'Grade 13',
2427: 14 => '100 Level',
2428: 15 => '200 Level',
2429: 16 => '300 Level',
2430: 17 => '400 Level',
2431: 18 => 'Graduate Level');
2432: return &mt($gradelevels{$gradelevel});
2433: }
2434:
1.163 www 2435: sub select_level_form {
2436: my ($deflevel,$name)=@_;
2437: unless ($deflevel) { $deflevel=0; }
1.167 www 2438: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2439: for (my $i=0; $i<=18; $i++) {
2440: $selectform.="<option value=\"$i\" ".
1.253 albertel 2441: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2442: ">".&gradeleveldescription($i)."</option>\n";
2443: }
2444: $selectform.="</select>";
2445: return $selectform;
1.163 www 2446: }
1.167 www 2447:
1.35 matthew 2448: #-------------------------------------------
2449:
1.45 matthew 2450: =pod
2451:
1.1121 raeburn 2452: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2453:
2454: Returns a string containing a <select name='$name' size='1'> form to
2455: allow a user to select the domain to preform an operation in.
2456: See loncreateuser.pm for an example invocation and use.
2457:
1.90 www 2458: If the $includeempty flag is set, it also includes an empty choice ("no domain
2459: selected");
2460:
1.743 raeburn 2461: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2462:
1.910 raeburn 2463: 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.
2464:
1.1121 raeburn 2465: The optional $incdoms is a reference to an array of domains which will be the only available options.
2466:
2467: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2468:
1.35 matthew 2469: =cut
2470:
2471: #-------------------------------------------
1.34 matthew 2472: sub select_dom_form {
1.1121 raeburn 2473: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2474: if ($onchange) {
1.874 raeburn 2475: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2476: }
1.1121 raeburn 2477: my (@domains,%exclude);
1.910 raeburn 2478: if (ref($incdoms) eq 'ARRAY') {
2479: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2480: } else {
2481: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2482: }
1.90 www 2483: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2484: if (ref($excdoms) eq 'ARRAY') {
2485: map { $exclude{$_} = 1; } @{$excdoms};
2486: }
1.743 raeburn 2487: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2488: foreach my $dom (@domains) {
1.1121 raeburn 2489: next if ($exclude{$dom});
1.356 albertel 2490: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2491: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2492: if ($showdomdesc) {
2493: if ($dom ne '') {
2494: my $domdesc = &Apache::lonnet::domain($dom,'description');
2495: if ($domdesc ne '') {
2496: $selectdomain .= ' ('.$domdesc.')';
2497: }
2498: }
2499: }
2500: $selectdomain .= "</option>\n";
1.34 matthew 2501: }
2502: $selectdomain.="</select>";
2503: return $selectdomain;
2504: }
2505:
1.35 matthew 2506: #-------------------------------------------
2507:
1.45 matthew 2508: =pod
2509:
1.648 raeburn 2510: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2511:
1.586 raeburn 2512: input: 4 arguments (two required, two optional) -
2513: $domain - domain of new user
2514: $name - name of form element
2515: $default - Value of 'default' causes a default item to be first
2516: option, and selected by default.
2517: $hide - Value of 'hide' causes hiding of the name of the server,
2518: if 1 server found, or default, if 0 found.
1.594 raeburn 2519: output: returns 2 items:
1.586 raeburn 2520: (a) form element which contains either:
2521: (i) <select name="$name">
2522: <option value="$hostid1">$hostid $servers{$hostid}</option>
2523: <option value="$hostid2">$hostid $servers{$hostid}</option>
2524: </select>
2525: form item if there are multiple library servers in $domain, or
2526: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2527: if there is only one library server in $domain.
2528:
2529: (b) number of library servers found.
2530:
2531: See loncreateuser.pm for example of use.
1.35 matthew 2532:
2533: =cut
2534:
2535: #-------------------------------------------
1.586 raeburn 2536: sub home_server_form_item {
2537: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2538: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2539: my $result;
2540: my $numlib = keys(%servers);
2541: if ($numlib > 1) {
2542: $result .= '<select name="'.$name.'" />'."\n";
2543: if ($default) {
1.804 bisitz 2544: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2545: '</option>'."\n";
2546: }
2547: foreach my $hostid (sort(keys(%servers))) {
2548: $result.= '<option value="'.$hostid.'">'.
2549: $hostid.' '.$servers{$hostid}."</option>\n";
2550: }
2551: $result .= '</select>'."\n";
2552: } elsif ($numlib == 1) {
2553: my $hostid;
2554: foreach my $item (keys(%servers)) {
2555: $hostid = $item;
2556: }
2557: $result .= '<input type="hidden" name="'.$name.'" value="'.
2558: $hostid.'" />';
2559: if (!$hide) {
2560: $result .= $hostid.' '.$servers{$hostid};
2561: }
2562: $result .= "\n";
2563: } elsif ($default) {
2564: $result .= '<input type="hidden" name="'.$name.
2565: '" value="default" />';
2566: if (!$hide) {
2567: $result .= &mt('default');
2568: }
2569: $result .= "\n";
1.33 matthew 2570: }
1.586 raeburn 2571: return ($result,$numlib);
1.33 matthew 2572: }
1.112 bowersj2 2573:
2574: =pod
2575:
1.534 albertel 2576: =back
2577:
1.112 bowersj2 2578: =cut
1.87 matthew 2579:
2580: ###############################################################
1.112 bowersj2 2581: ## Decoding User Agent ##
1.87 matthew 2582: ###############################################################
2583:
2584: =pod
2585:
1.112 bowersj2 2586: =head1 Decoding the User Agent
2587:
2588: =over 4
2589:
2590: =item * &decode_user_agent()
1.87 matthew 2591:
2592: Inputs: $r
2593:
2594: Outputs:
2595:
2596: =over 4
2597:
1.112 bowersj2 2598: =item * $httpbrowser
1.87 matthew 2599:
1.112 bowersj2 2600: =item * $clientbrowser
1.87 matthew 2601:
1.112 bowersj2 2602: =item * $clientversion
1.87 matthew 2603:
1.112 bowersj2 2604: =item * $clientmathml
1.87 matthew 2605:
1.112 bowersj2 2606: =item * $clientunicode
1.87 matthew 2607:
1.112 bowersj2 2608: =item * $clientos
1.87 matthew 2609:
1.1137 raeburn 2610: =item * $clientmobile
2611:
1.1141 raeburn 2612: =item * $clientinfo
2613:
1.1194 raeburn 2614: =item * $clientosversion
2615:
1.87 matthew 2616: =back
2617:
1.157 matthew 2618: =back
2619:
1.87 matthew 2620: =cut
2621:
2622: ###############################################################
2623: ###############################################################
2624: sub decode_user_agent {
1.247 albertel 2625: my ($r)=@_;
1.87 matthew 2626: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2627: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2628: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2629: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2630: my $clientbrowser='unknown';
2631: my $clientversion='0';
2632: my $clientmathml='';
2633: my $clientunicode='0';
1.1137 raeburn 2634: my $clientmobile=0;
1.1194 raeburn 2635: my $clientosversion='';
1.87 matthew 2636: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2637: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2638: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2639: $clientbrowser=$bname;
2640: $httpbrowser=~/$vreg/i;
2641: $clientversion=$1;
2642: $clientmathml=($clientversion>=$minv);
2643: $clientunicode=($clientversion>=$univ);
2644: }
2645: }
2646: my $clientos='unknown';
1.1141 raeburn 2647: my $clientinfo;
1.87 matthew 2648: if (($httpbrowser=~/linux/i) ||
2649: ($httpbrowser=~/unix/i) ||
2650: ($httpbrowser=~/ux/i) ||
2651: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2652: if (($httpbrowser=~/vax/i) ||
2653: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2654: if ($httpbrowser=~/next/i) { $clientos='next'; }
2655: if (($httpbrowser=~/mac/i) ||
2656: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2657: if ($httpbrowser=~/win/i) {
2658: $clientos='win';
2659: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2660: $clientosversion = $1;
2661: }
2662: }
1.87 matthew 2663: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2664: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2665: $clientmobile=lc($1);
2666: }
1.1141 raeburn 2667: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2668: $clientinfo = 'firefox-'.$1;
2669: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2670: $clientinfo = 'chromeframe-'.$1;
2671: }
1.87 matthew 2672: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 2673: $clientunicode,$clientos,$clientmobile,$clientinfo,
2674: $clientosversion);
1.87 matthew 2675: }
2676:
1.32 matthew 2677: ###############################################################
2678: ## Authentication changing form generation subroutines ##
2679: ###############################################################
2680: ##
2681: ## All of the authform_xxxxxxx subroutines take their inputs in a
2682: ## hash, and have reasonable default values.
2683: ##
2684: ## formname = the name given in the <form> tag.
1.35 matthew 2685: #-------------------------------------------
2686:
1.45 matthew 2687: =pod
2688:
1.112 bowersj2 2689: =head1 Authentication Routines
2690:
2691: =over 4
2692:
1.648 raeburn 2693: =item * &authform_xxxxxx()
1.35 matthew 2694:
2695: The authform_xxxxxx subroutines provide javascript and html forms which
2696: handle some of the conveniences required for authentication forms.
2697: This is not an optimal method, but it works.
2698:
2699: =over 4
2700:
1.112 bowersj2 2701: =item * authform_header
1.35 matthew 2702:
1.112 bowersj2 2703: =item * authform_authorwarning
1.35 matthew 2704:
1.112 bowersj2 2705: =item * authform_nochange
1.35 matthew 2706:
1.112 bowersj2 2707: =item * authform_kerberos
1.35 matthew 2708:
1.112 bowersj2 2709: =item * authform_internal
1.35 matthew 2710:
1.112 bowersj2 2711: =item * authform_filesystem
1.35 matthew 2712:
2713: =back
2714:
1.648 raeburn 2715: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2716:
1.35 matthew 2717: =cut
2718:
2719: #-------------------------------------------
1.32 matthew 2720: sub authform_header{
2721: my %in = (
2722: formname => 'cu',
1.80 albertel 2723: kerb_def_dom => '',
1.32 matthew 2724: @_,
2725: );
2726: $in{'formname'} = 'document.' . $in{'formname'};
2727: my $result='';
1.80 albertel 2728:
2729: #---------------------------------------------- Code for upper case translation
2730: my $Javascript_toUpperCase;
2731: unless ($in{kerb_def_dom}) {
2732: $Javascript_toUpperCase =<<"END";
2733: switch (choice) {
2734: case 'krb': currentform.elements[choicearg].value =
2735: currentform.elements[choicearg].value.toUpperCase();
2736: break;
2737: default:
2738: }
2739: END
2740: } else {
2741: $Javascript_toUpperCase = "";
2742: }
2743:
1.165 raeburn 2744: my $radioval = "'nochange'";
1.591 raeburn 2745: if (defined($in{'curr_authtype'})) {
2746: if ($in{'curr_authtype'} ne '') {
2747: $radioval = "'".$in{'curr_authtype'}."arg'";
2748: }
1.174 matthew 2749: }
1.165 raeburn 2750: my $argfield = 'null';
1.591 raeburn 2751: if (defined($in{'mode'})) {
1.165 raeburn 2752: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2753: if (defined($in{'curr_autharg'})) {
2754: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2755: $argfield = "'$in{'curr_autharg'}'";
2756: }
2757: }
2758: }
2759: }
2760:
1.32 matthew 2761: $result.=<<"END";
2762: var current = new Object();
1.165 raeburn 2763: current.radiovalue = $radioval;
2764: current.argfield = $argfield;
1.32 matthew 2765:
2766: function changed_radio(choice,currentform) {
2767: var choicearg = choice + 'arg';
2768: // If a radio button in changed, we need to change the argfield
2769: if (current.radiovalue != choice) {
2770: current.radiovalue = choice;
2771: if (current.argfield != null) {
2772: currentform.elements[current.argfield].value = '';
2773: }
2774: if (choice == 'nochange') {
2775: current.argfield = null;
2776: } else {
2777: current.argfield = choicearg;
2778: switch(choice) {
2779: case 'krb':
2780: currentform.elements[current.argfield].value =
2781: "$in{'kerb_def_dom'}";
2782: break;
2783: default:
2784: break;
2785: }
2786: }
2787: }
2788: return;
2789: }
1.22 www 2790:
1.32 matthew 2791: function changed_text(choice,currentform) {
2792: var choicearg = choice + 'arg';
2793: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2794: $Javascript_toUpperCase
1.32 matthew 2795: // clear old field
2796: if ((current.argfield != choicearg) && (current.argfield != null)) {
2797: currentform.elements[current.argfield].value = '';
2798: }
2799: current.argfield = choicearg;
2800: }
2801: set_auth_radio_buttons(choice,currentform);
2802: return;
1.20 www 2803: }
1.32 matthew 2804:
2805: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2806: var numauthchoices = currentform.login.length;
2807: if (typeof numauthchoices == "undefined") {
2808: return;
2809: }
1.32 matthew 2810: var i=0;
1.986 raeburn 2811: while (i < numauthchoices) {
1.32 matthew 2812: if (currentform.login[i].value == newvalue) { break; }
2813: i++;
2814: }
1.986 raeburn 2815: if (i == numauthchoices) {
1.32 matthew 2816: return;
2817: }
2818: current.radiovalue = newvalue;
2819: currentform.login[i].checked = true;
2820: return;
2821: }
2822: END
2823: return $result;
2824: }
2825:
1.1106 raeburn 2826: sub authform_authorwarning {
1.32 matthew 2827: my $result='';
1.144 matthew 2828: $result='<i>'.
2829: &mt('As a general rule, only authors or co-authors should be '.
2830: 'filesystem authenticated '.
2831: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2832: return $result;
2833: }
2834:
1.1106 raeburn 2835: sub authform_nochange {
1.32 matthew 2836: my %in = (
2837: formname => 'document.cu',
2838: kerb_def_dom => 'MSU.EDU',
2839: @_,
2840: );
1.1106 raeburn 2841: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2842: my $result;
1.1104 raeburn 2843: if (!$authnum) {
1.1105 raeburn 2844: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2845: } else {
2846: $result = '<label>'.&mt('[_1] Do not change login data',
2847: '<input type="radio" name="login" value="nochange" '.
2848: 'checked="checked" onclick="'.
1.281 albertel 2849: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2850: '</label>';
1.586 raeburn 2851: }
1.32 matthew 2852: return $result;
2853: }
2854:
1.591 raeburn 2855: sub authform_kerberos {
1.32 matthew 2856: my %in = (
2857: formname => 'document.cu',
2858: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2859: kerb_def_auth => 'krb4',
1.32 matthew 2860: @_,
2861: );
1.586 raeburn 2862: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2863: $autharg,$jscall);
1.1106 raeburn 2864: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2865: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2866: $check5 = ' checked="checked"';
1.80 albertel 2867: } else {
1.772 bisitz 2868: $check4 = ' checked="checked"';
1.80 albertel 2869: }
1.165 raeburn 2870: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2871: if (defined($in{'curr_authtype'})) {
2872: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2873: $krbcheck = ' checked="checked"';
1.623 raeburn 2874: if (defined($in{'mode'})) {
2875: if ($in{'mode'} eq 'modifyuser') {
2876: $krbcheck = '';
2877: }
2878: }
1.591 raeburn 2879: if (defined($in{'curr_kerb_ver'})) {
2880: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2881: $check5 = ' checked="checked"';
1.591 raeburn 2882: $check4 = '';
2883: } else {
1.772 bisitz 2884: $check4 = ' checked="checked"';
1.591 raeburn 2885: $check5 = '';
2886: }
1.586 raeburn 2887: }
1.591 raeburn 2888: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2889: $krbarg = $in{'curr_autharg'};
2890: }
1.586 raeburn 2891: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2892: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2893: $result =
2894: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2895: $in{'curr_autharg'},$krbver);
2896: } else {
2897: $result =
2898: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2899: }
2900: return $result;
2901: }
2902: }
2903: } else {
2904: if ($authnum == 1) {
1.784 bisitz 2905: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2906: }
2907: }
1.586 raeburn 2908: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2909: return;
1.587 raeburn 2910: } elsif ($authtype eq '') {
1.591 raeburn 2911: if (defined($in{'mode'})) {
1.587 raeburn 2912: if ($in{'mode'} eq 'modifycourse') {
2913: if ($authnum == 1) {
1.1104 raeburn 2914: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2915: }
2916: }
2917: }
1.586 raeburn 2918: }
2919: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2920: if ($authtype eq '') {
2921: $authtype = '<input type="radio" name="login" value="krb" '.
2922: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2923: $krbcheck.' />';
2924: }
2925: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 2926: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2927: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 2928: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2929: $in{'curr_authtype'} eq 'krb4')) {
2930: $result .= &mt
1.144 matthew 2931: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2932: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2933: '<label>'.$authtype,
1.281 albertel 2934: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2935: 'value="'.$krbarg.'" '.
1.144 matthew 2936: 'onchange="'.$jscall.'" />',
1.281 albertel 2937: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2938: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2939: '</label>');
1.586 raeburn 2940: } elsif ($can_assign{'krb4'}) {
2941: $result .= &mt
2942: ('[_1] Kerberos authenticated with domain [_2] '.
2943: '[_3] Version 4 [_4]',
2944: '<label>'.$authtype,
2945: '</label><input type="text" size="10" name="krbarg" '.
2946: 'value="'.$krbarg.'" '.
2947: 'onchange="'.$jscall.'" />',
2948: '<label><input type="hidden" name="krbver" value="4" />',
2949: '</label>');
2950: } elsif ($can_assign{'krb5'}) {
2951: $result .= &mt
2952: ('[_1] Kerberos authenticated with domain [_2] '.
2953: '[_3] Version 5 [_4]',
2954: '<label>'.$authtype,
2955: '</label><input type="text" size="10" name="krbarg" '.
2956: 'value="'.$krbarg.'" '.
2957: 'onchange="'.$jscall.'" />',
2958: '<label><input type="hidden" name="krbver" value="5" />',
2959: '</label>');
2960: }
1.32 matthew 2961: return $result;
2962: }
2963:
1.1106 raeburn 2964: sub authform_internal {
1.586 raeburn 2965: my %in = (
1.32 matthew 2966: formname => 'document.cu',
2967: kerb_def_dom => 'MSU.EDU',
2968: @_,
2969: );
1.586 raeburn 2970: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2971: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2972: if (defined($in{'curr_authtype'})) {
2973: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2974: if ($can_assign{'int'}) {
1.772 bisitz 2975: $intcheck = 'checked="checked" ';
1.623 raeburn 2976: if (defined($in{'mode'})) {
2977: if ($in{'mode'} eq 'modifyuser') {
2978: $intcheck = '';
2979: }
2980: }
1.591 raeburn 2981: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2982: $intarg = $in{'curr_autharg'};
2983: }
2984: } else {
2985: $result = &mt('Currently internally authenticated.');
2986: return $result;
1.165 raeburn 2987: }
2988: }
1.586 raeburn 2989: } else {
2990: if ($authnum == 1) {
1.784 bisitz 2991: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2992: }
2993: }
2994: if (!$can_assign{'int'}) {
2995: return;
1.587 raeburn 2996: } elsif ($authtype eq '') {
1.591 raeburn 2997: if (defined($in{'mode'})) {
1.587 raeburn 2998: if ($in{'mode'} eq 'modifycourse') {
2999: if ($authnum == 1) {
1.1104 raeburn 3000: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 3001: }
3002: }
3003: }
1.165 raeburn 3004: }
1.586 raeburn 3005: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3006: if ($authtype eq '') {
3007: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
3008: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
3009: }
1.605 bisitz 3010: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 3011: $intarg.'" onchange="'.$jscall.'" />';
3012: $result = &mt
1.144 matthew 3013: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3014: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 3015: $result.="<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 3016: return $result;
3017: }
3018:
1.1104 raeburn 3019: sub authform_local {
1.32 matthew 3020: my %in = (
3021: formname => 'document.cu',
3022: kerb_def_dom => 'MSU.EDU',
3023: @_,
3024: );
1.586 raeburn 3025: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 3026: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3027: if (defined($in{'curr_authtype'})) {
3028: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3029: if ($can_assign{'loc'}) {
1.772 bisitz 3030: $loccheck = 'checked="checked" ';
1.623 raeburn 3031: if (defined($in{'mode'})) {
3032: if ($in{'mode'} eq 'modifyuser') {
3033: $loccheck = '';
3034: }
3035: }
1.591 raeburn 3036: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3037: $locarg = $in{'curr_autharg'};
3038: }
3039: } else {
3040: $result = &mt('Currently using local (institutional) authentication.');
3041: return $result;
1.165 raeburn 3042: }
3043: }
1.586 raeburn 3044: } else {
3045: if ($authnum == 1) {
1.784 bisitz 3046: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3047: }
3048: }
3049: if (!$can_assign{'loc'}) {
3050: return;
1.587 raeburn 3051: } elsif ($authtype eq '') {
1.591 raeburn 3052: if (defined($in{'mode'})) {
1.587 raeburn 3053: if ($in{'mode'} eq 'modifycourse') {
3054: if ($authnum == 1) {
1.1104 raeburn 3055: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 3056: }
3057: }
3058: }
1.165 raeburn 3059: }
1.586 raeburn 3060: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3061: if ($authtype eq '') {
3062: $authtype = '<input type="radio" name="login" value="loc" '.
3063: $loccheck.' onchange="'.$jscall.'" onclick="'.
3064: $jscall.'" />';
3065: }
3066: $autharg = '<input type="text" size="10" name="locarg" value="'.
3067: $locarg.'" onchange="'.$jscall.'" />';
3068: $result = &mt('[_1] Local Authentication with argument [_2]',
3069: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3070: return $result;
3071: }
3072:
1.1106 raeburn 3073: sub authform_filesystem {
1.32 matthew 3074: my %in = (
3075: formname => 'document.cu',
3076: kerb_def_dom => 'MSU.EDU',
3077: @_,
3078: );
1.586 raeburn 3079: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 3080: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3081: if (defined($in{'curr_authtype'})) {
3082: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3083: if ($can_assign{'fsys'}) {
1.772 bisitz 3084: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3085: if (defined($in{'mode'})) {
3086: if ($in{'mode'} eq 'modifyuser') {
3087: $fsyscheck = '';
3088: }
3089: }
1.586 raeburn 3090: } else {
3091: $result = &mt('Currently Filesystem Authenticated.');
3092: return $result;
3093: }
3094: }
3095: } else {
3096: if ($authnum == 1) {
1.784 bisitz 3097: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3098: }
3099: }
3100: if (!$can_assign{'fsys'}) {
3101: return;
1.587 raeburn 3102: } elsif ($authtype eq '') {
1.591 raeburn 3103: if (defined($in{'mode'})) {
1.587 raeburn 3104: if ($in{'mode'} eq 'modifycourse') {
3105: if ($authnum == 1) {
1.1104 raeburn 3106: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 3107: }
3108: }
3109: }
1.586 raeburn 3110: }
3111: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3112: if ($authtype eq '') {
3113: $authtype = '<input type="radio" name="login" value="fsys" '.
3114: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
3115: $jscall.'" />';
3116: }
3117: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
3118: ' onchange="'.$jscall.'" />';
3119: $result = &mt
1.144 matthew 3120: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3121: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 3122: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 3123: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 3124: 'onchange="'.$jscall.'" />');
1.32 matthew 3125: return $result;
3126: }
3127:
1.586 raeburn 3128: sub get_assignable_auth {
3129: my ($dom) = @_;
3130: if ($dom eq '') {
3131: $dom = $env{'request.role.domain'};
3132: }
3133: my %can_assign = (
3134: krb4 => 1,
3135: krb5 => 1,
3136: int => 1,
3137: loc => 1,
3138: );
3139: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3140: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3141: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3142: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3143: my $context;
3144: if ($env{'request.role'} =~ /^au/) {
3145: $context = 'author';
3146: } elsif ($env{'request.role'} =~ /^dc/) {
3147: $context = 'domain';
3148: } elsif ($env{'request.course.id'}) {
3149: $context = 'course';
3150: }
3151: if ($context) {
3152: if (ref($authhash->{$context}) eq 'HASH') {
3153: %can_assign = %{$authhash->{$context}};
3154: }
3155: }
3156: }
3157: }
3158: my $authnum = 0;
3159: foreach my $key (keys(%can_assign)) {
3160: if ($can_assign{$key}) {
3161: $authnum ++;
3162: }
3163: }
3164: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3165: $authnum --;
3166: }
3167: return ($authnum,%can_assign);
3168: }
3169:
1.80 albertel 3170: ###############################################################
3171: ## Get Kerberos Defaults for Domain ##
3172: ###############################################################
3173: ##
3174: ## Returns default kerberos version and an associated argument
3175: ## as listed in file domain.tab. If not listed, provides
3176: ## appropriate default domain and kerberos version.
3177: ##
3178: #-------------------------------------------
3179:
3180: =pod
3181:
1.648 raeburn 3182: =item * &get_kerberos_defaults()
1.80 albertel 3183:
3184: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3185: version and domain. If not found, it defaults to version 4 and the
3186: domain of the server.
1.80 albertel 3187:
1.648 raeburn 3188: =over 4
3189:
1.80 albertel 3190: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3191:
1.648 raeburn 3192: =back
3193:
3194: =back
3195:
1.80 albertel 3196: =cut
3197:
3198: #-------------------------------------------
3199: sub get_kerberos_defaults {
3200: my $domain=shift;
1.641 raeburn 3201: my ($krbdef,$krbdefdom);
3202: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3203: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3204: $krbdef = $domdefaults{'auth_def'};
3205: $krbdefdom = $domdefaults{'auth_arg_def'};
3206: } else {
1.80 albertel 3207: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3208: my $krbdefdom=$1;
3209: $krbdefdom=~tr/a-z/A-Z/;
3210: $krbdef = "krb4";
3211: }
3212: return ($krbdef,$krbdefdom);
3213: }
1.112 bowersj2 3214:
1.32 matthew 3215:
1.46 matthew 3216: ###############################################################
3217: ## Thesaurus Functions ##
3218: ###############################################################
1.20 www 3219:
1.46 matthew 3220: =pod
1.20 www 3221:
1.112 bowersj2 3222: =head1 Thesaurus Functions
3223:
3224: =over 4
3225:
1.648 raeburn 3226: =item * &initialize_keywords()
1.46 matthew 3227:
3228: Initializes the package variable %Keywords if it is empty. Uses the
3229: package variable $thesaurus_db_file.
3230:
3231: =cut
3232:
3233: ###################################################
3234:
3235: sub initialize_keywords {
3236: return 1 if (scalar keys(%Keywords));
3237: # If we are here, %Keywords is empty, so fill it up
3238: # Make sure the file we need exists...
3239: if (! -e $thesaurus_db_file) {
3240: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3241: " failed because it does not exist");
3242: return 0;
3243: }
3244: # Set up the hash as a database
3245: my %thesaurus_db;
3246: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3247: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3248: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3249: $thesaurus_db_file);
3250: return 0;
3251: }
3252: # Get the average number of appearances of a word.
3253: my $avecount = $thesaurus_db{'average.count'};
3254: # Put keywords (those that appear > average) into %Keywords
3255: while (my ($word,$data)=each (%thesaurus_db)) {
3256: my ($count,undef) = split /:/,$data;
3257: $Keywords{$word}++ if ($count > $avecount);
3258: }
3259: untie %thesaurus_db;
3260: # Remove special values from %Keywords.
1.356 albertel 3261: foreach my $value ('total.count','average.count') {
3262: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3263: }
1.46 matthew 3264: return 1;
3265: }
3266:
3267: ###################################################
3268:
3269: =pod
3270:
1.648 raeburn 3271: =item * &keyword($word)
1.46 matthew 3272:
3273: Returns true if $word is a keyword. A keyword is a word that appears more
3274: than the average number of times in the thesaurus database. Calls
3275: &initialize_keywords
3276:
3277: =cut
3278:
3279: ###################################################
1.20 www 3280:
3281: sub keyword {
1.46 matthew 3282: return if (!&initialize_keywords());
3283: my $word=lc(shift());
3284: $word=~s/\W//g;
3285: return exists($Keywords{$word});
1.20 www 3286: }
1.46 matthew 3287:
3288: ###############################################################
3289:
3290: =pod
1.20 www 3291:
1.648 raeburn 3292: =item * &get_related_words()
1.46 matthew 3293:
1.160 matthew 3294: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3295: an array of words. If the keyword is not in the thesaurus, an empty array
3296: will be returned. The order of the words returned is determined by the
3297: database which holds them.
3298:
3299: Uses global $thesaurus_db_file.
3300:
1.1057 foxr 3301:
1.46 matthew 3302: =cut
3303:
3304: ###############################################################
3305: sub get_related_words {
3306: my $keyword = shift;
3307: my %thesaurus_db;
3308: if (! -e $thesaurus_db_file) {
3309: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3310: "failed because the file does not exist");
3311: return ();
3312: }
3313: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3314: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3315: return ();
3316: }
3317: my @Words=();
1.429 www 3318: my $count=0;
1.46 matthew 3319: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3320: # The first element is the number of times
3321: # the word appears. We do not need it now.
1.429 www 3322: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3323: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3324: my $threshold=$mostfrequentcount/10;
3325: foreach my $possibleword (@RelatedWords) {
3326: my ($word,$wordcount)=split(/\,/,$possibleword);
3327: if ($wordcount>$threshold) {
3328: push(@Words,$word);
3329: $count++;
3330: if ($count>10) { last; }
3331: }
1.20 www 3332: }
3333: }
1.46 matthew 3334: untie %thesaurus_db;
3335: return @Words;
1.14 harris41 3336: }
1.1090 foxr 3337: ###############################################################
3338: #
3339: # Spell checking
3340: #
3341:
3342: =pod
3343:
1.1142 raeburn 3344: =back
3345:
1.1090 foxr 3346: =head1 Spell checking
3347:
3348: =over 4
3349:
3350: =item * &check_spelling($wordlist $language)
3351:
3352: Takes a string containing words and feeds it to an external
3353: spellcheck program via a pipeline. Returns a string containing
3354: them mis-spelled words.
3355:
3356: Parameters:
3357:
3358: =over 4
3359:
3360: =item - $wordlist
3361:
3362: String that will be fed into the spellcheck program.
3363:
3364: =item - $language
3365:
3366: Language string that specifies the language for which the spell
3367: check will be performed.
3368:
3369: =back
3370:
3371: =back
3372:
3373: Note: This sub assumes that aspell is installed.
3374:
3375:
3376: =cut
3377:
1.46 matthew 3378:
1.1090 foxr 3379: sub check_spelling {
3380: my ($wordlist, $language) = @_;
1.1091 foxr 3381: my @misspellings;
3382:
3383: # Generate the speller and set the langauge.
3384: # if explicitly selected:
1.1090 foxr 3385:
1.1091 foxr 3386: my $speller = Text::Aspell->new;
1.1090 foxr 3387: if ($language) {
1.1091 foxr 3388: $speller->set_option('lang', $language);
1.1090 foxr 3389: }
3390:
1.1091 foxr 3391: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3392:
1.1091 foxr 3393: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3394:
1.1091 foxr 3395: foreach my $word (@words) {
3396: if(! $speller->check($word)) {
3397: push(@misspellings, $word);
1.1090 foxr 3398: }
3399: }
1.1091 foxr 3400: return join(' ', @misspellings);
3401:
1.1090 foxr 3402: }
3403:
1.61 www 3404: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3405: =pod
3406:
1.112 bowersj2 3407: =head1 User Name Functions
3408:
3409: =over 4
3410:
1.648 raeburn 3411: =item * &plainname($uname,$udom,$first)
1.81 albertel 3412:
1.112 bowersj2 3413: Takes a users logon name and returns it as a string in
1.226 albertel 3414: "first middle last generation" form
3415: if $first is set to 'lastname' then it returns it as
3416: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3417:
3418: =cut
1.61 www 3419:
1.295 www 3420:
1.81 albertel 3421: ###############################################################
1.61 www 3422: sub plainname {
1.226 albertel 3423: my ($uname,$udom,$first)=@_;
1.537 albertel 3424: return if (!defined($uname) || !defined($udom));
1.295 www 3425: my %names=&getnames($uname,$udom);
1.226 albertel 3426: my $name=&Apache::lonnet::format_name($names{'firstname'},
3427: $names{'middlename'},
3428: $names{'lastname'},
3429: $names{'generation'},$first);
3430: $name=~s/^\s+//;
1.62 www 3431: $name=~s/\s+$//;
3432: $name=~s/\s+/ /g;
1.353 albertel 3433: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3434: return $name;
1.61 www 3435: }
1.66 www 3436:
3437: # -------------------------------------------------------------------- Nickname
1.81 albertel 3438: =pod
3439:
1.648 raeburn 3440: =item * &nickname($uname,$udom)
1.81 albertel 3441:
3442: Gets a users name and returns it as a string as
3443:
3444: ""nickname""
1.66 www 3445:
1.81 albertel 3446: if the user has a nickname or
3447:
3448: "first middle last generation"
3449:
3450: if the user does not
3451:
3452: =cut
1.66 www 3453:
3454: sub nickname {
3455: my ($uname,$udom)=@_;
1.537 albertel 3456: return if (!defined($uname) || !defined($udom));
1.295 www 3457: my %names=&getnames($uname,$udom);
1.68 albertel 3458: my $name=$names{'nickname'};
1.66 www 3459: if ($name) {
3460: $name='"'.$name.'"';
3461: } else {
3462: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3463: $names{'lastname'}.' '.$names{'generation'};
3464: $name=~s/\s+$//;
3465: $name=~s/\s+/ /g;
3466: }
3467: return $name;
3468: }
3469:
1.295 www 3470: sub getnames {
3471: my ($uname,$udom)=@_;
1.537 albertel 3472: return if (!defined($uname) || !defined($udom));
1.433 albertel 3473: if ($udom eq 'public' && $uname eq 'public') {
3474: return ('lastname' => &mt('Public'));
3475: }
1.295 www 3476: my $id=$uname.':'.$udom;
3477: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3478: if ($cached) {
3479: return %{$names};
3480: } else {
3481: my %loadnames=&Apache::lonnet::get('environment',
3482: ['firstname','middlename','lastname','generation','nickname'],
3483: $udom,$uname);
3484: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3485: return %loadnames;
3486: }
3487: }
1.61 www 3488:
1.542 raeburn 3489: # -------------------------------------------------------------------- getemails
1.648 raeburn 3490:
1.542 raeburn 3491: =pod
3492:
1.648 raeburn 3493: =item * &getemails($uname,$udom)
1.542 raeburn 3494:
3495: Gets a user's email information and returns it as a hash with keys:
3496: notification, critnotification, permanentemail
3497:
3498: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3499: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3500:
1.648 raeburn 3501:
1.542 raeburn 3502: =cut
3503:
1.648 raeburn 3504:
1.466 albertel 3505: sub getemails {
3506: my ($uname,$udom)=@_;
3507: if ($udom eq 'public' && $uname eq 'public') {
3508: return;
3509: }
1.467 www 3510: if (!$udom) { $udom=$env{'user.domain'}; }
3511: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3512: my $id=$uname.':'.$udom;
3513: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3514: if ($cached) {
3515: return %{$names};
3516: } else {
3517: my %loadnames=&Apache::lonnet::get('environment',
3518: ['notification','critnotification',
3519: 'permanentemail'],
3520: $udom,$uname);
3521: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3522: return %loadnames;
3523: }
3524: }
3525:
1.551 albertel 3526: sub flush_email_cache {
3527: my ($uname,$udom)=@_;
3528: if (!$udom) { $udom =$env{'user.domain'}; }
3529: if (!$uname) { $uname=$env{'user.name'}; }
3530: return if ($udom eq 'public' && $uname eq 'public');
3531: my $id=$uname.':'.$udom;
3532: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3533: }
3534:
1.728 raeburn 3535: # -------------------------------------------------------------------- getlangs
3536:
3537: =pod
3538:
3539: =item * &getlangs($uname,$udom)
3540:
3541: Gets a user's language preference and returns it as a hash with key:
3542: language.
3543:
3544: =cut
3545:
3546:
3547: sub getlangs {
3548: my ($uname,$udom) = @_;
3549: if (!$udom) { $udom =$env{'user.domain'}; }
3550: if (!$uname) { $uname=$env{'user.name'}; }
3551: my $id=$uname.':'.$udom;
3552: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3553: if ($cached) {
3554: return %{$langs};
3555: } else {
3556: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3557: $udom,$uname);
3558: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3559: return %loadlangs;
3560: }
3561: }
3562:
3563: sub flush_langs_cache {
3564: my ($uname,$udom)=@_;
3565: if (!$udom) { $udom =$env{'user.domain'}; }
3566: if (!$uname) { $uname=$env{'user.name'}; }
3567: return if ($udom eq 'public' && $uname eq 'public');
3568: my $id=$uname.':'.$udom;
3569: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3570: }
3571:
1.61 www 3572: # ------------------------------------------------------------------ Screenname
1.81 albertel 3573:
3574: =pod
3575:
1.648 raeburn 3576: =item * &screenname($uname,$udom)
1.81 albertel 3577:
3578: Gets a users screenname and returns it as a string
3579:
3580: =cut
1.61 www 3581:
3582: sub screenname {
3583: my ($uname,$udom)=@_;
1.258 albertel 3584: if ($uname eq $env{'user.name'} &&
3585: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3586: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3587: return $names{'screenname'};
1.62 www 3588: }
3589:
1.212 albertel 3590:
1.802 bisitz 3591: # ------------------------------------------------------------- Confirm Wrapper
3592: =pod
3593:
1.1142 raeburn 3594: =item * &confirmwrapper($message)
1.802 bisitz 3595:
3596: Wrap messages about completion of operation in box
3597:
3598: =cut
3599:
3600: sub confirmwrapper {
3601: my ($message)=@_;
3602: if ($message) {
3603: return "\n".'<div class="LC_confirm_box">'."\n"
3604: .$message."\n"
3605: .'</div>'."\n";
3606: } else {
3607: return $message;
3608: }
3609: }
3610:
1.62 www 3611: # ------------------------------------------------------------- Message Wrapper
3612:
3613: sub messagewrapper {
1.369 www 3614: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3615: return
1.441 albertel 3616: '<a href="/adm/email?compose=individual&'.
3617: 'recname='.$username.'&recdom='.$domain.
3618: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3619: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3620: }
1.802 bisitz 3621:
1.74 www 3622: # --------------------------------------------------------------- Notes Wrapper
3623:
3624: sub noteswrapper {
3625: my ($link,$un,$do)=@_;
3626: return
1.896 amueller 3627: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3628: }
1.802 bisitz 3629:
1.62 www 3630: # ------------------------------------------------------------- Aboutme Wrapper
3631:
3632: sub aboutmewrapper {
1.1070 raeburn 3633: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3634: if (!defined($username) && !defined($domain)) {
3635: return;
3636: }
1.1096 raeburn 3637: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3638: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3639: }
3640:
3641: # ------------------------------------------------------------ Syllabus Wrapper
3642:
3643: sub syllabuswrapper {
1.707 bisitz 3644: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3645: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3646: }
1.14 harris41 3647:
1.802 bisitz 3648: # -----------------------------------------------------------------------------
3649:
1.208 matthew 3650: sub track_student_link {
1.887 raeburn 3651: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3652: my $link ="/adm/trackstudent?";
1.208 matthew 3653: my $title = 'View recent activity';
3654: if (defined($sname) && $sname !~ /^\s*$/ &&
3655: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3656: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3657: $title .= ' of this student';
1.268 albertel 3658: }
1.208 matthew 3659: if (defined($target) && $target !~ /^\s*$/) {
3660: $target = qq{target="$target"};
3661: } else {
3662: $target = '';
3663: }
1.268 albertel 3664: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3665: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3666: $title = &mt($title);
3667: $linktext = &mt($linktext);
1.448 albertel 3668: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3669: &help_open_topic('View_recent_activity');
1.208 matthew 3670: }
3671:
1.781 raeburn 3672: sub slot_reservations_link {
3673: my ($linktext,$sname,$sdom,$target) = @_;
3674: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3675: my $title = 'View slot reservation history';
3676: if (defined($sname) && $sname !~ /^\s*$/ &&
3677: defined($sdom) && $sdom !~ /^\s*$/) {
3678: $link .= "&uname=$sname&udom=$sdom";
3679: $title .= ' of this student';
3680: }
3681: if (defined($target) && $target !~ /^\s*$/) {
3682: $target = qq{target="$target"};
3683: } else {
3684: $target = '';
3685: }
3686: $title = &mt($title);
3687: $linktext = &mt($linktext);
3688: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3689: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3690:
3691: }
3692:
1.508 www 3693: # ===================================================== Display a student photo
3694:
3695:
1.509 albertel 3696: sub student_image_tag {
1.508 www 3697: my ($domain,$user)=@_;
3698: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3699: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3700: return '<img src="'.$imgsrc.'" align="right" />';
3701: } else {
3702: return '';
3703: }
3704: }
3705:
1.112 bowersj2 3706: =pod
3707:
3708: =back
3709:
3710: =head1 Access .tab File Data
3711:
3712: =over 4
3713:
1.648 raeburn 3714: =item * &languageids()
1.112 bowersj2 3715:
3716: returns list of all language ids
3717:
3718: =cut
3719:
1.14 harris41 3720: sub languageids {
1.16 harris41 3721: return sort(keys(%language));
1.14 harris41 3722: }
3723:
1.112 bowersj2 3724: =pod
3725:
1.648 raeburn 3726: =item * &languagedescription()
1.112 bowersj2 3727:
3728: returns description of a specified language id
3729:
3730: =cut
3731:
1.14 harris41 3732: sub languagedescription {
1.125 www 3733: my $code=shift;
3734: return ($supported_language{$code}?'* ':'').
3735: $language{$code}.
1.126 www 3736: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3737: }
3738:
1.1048 foxr 3739: =pod
3740:
3741: =item * &plainlanguagedescription
3742:
3743: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3744: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3745:
3746: =cut
3747:
1.145 www 3748: sub plainlanguagedescription {
3749: my $code=shift;
3750: return $language{$code};
3751: }
3752:
1.1048 foxr 3753: =pod
3754:
3755: =item * &supportedlanguagecode
3756:
3757: Returns the supported language code (e.g. sptutf maps to pt) given a language
3758: code.
3759:
3760: =cut
3761:
1.145 www 3762: sub supportedlanguagecode {
3763: my $code=shift;
3764: return $supported_language{$code};
1.97 www 3765: }
3766:
1.112 bowersj2 3767: =pod
3768:
1.1048 foxr 3769: =item * &latexlanguage()
3770:
3771: Given a language key code returns the correspondnig language to use
3772: to select the correct hyphenation on LaTeX printouts. This is undef if there
3773: is no supported hyphenation for the language code.
3774:
3775: =cut
3776:
3777: sub latexlanguage {
3778: my $code = shift;
3779: return $latex_language{$code};
3780: }
3781:
3782: =pod
3783:
3784: =item * &latexhyphenation()
3785:
3786: Same as above but what's supplied is the language as it might be stored
3787: in the metadata.
3788:
3789: =cut
3790:
3791: sub latexhyphenation {
3792: my $key = shift;
3793: return $latex_language_bykey{$key};
3794: }
3795:
3796: =pod
3797:
1.648 raeburn 3798: =item * ©rightids()
1.112 bowersj2 3799:
3800: returns list of all copyrights
3801:
3802: =cut
3803:
3804: sub copyrightids {
3805: return sort(keys(%cprtag));
3806: }
3807:
3808: =pod
3809:
1.648 raeburn 3810: =item * ©rightdescription()
1.112 bowersj2 3811:
3812: returns description of a specified copyright id
3813:
3814: =cut
3815:
3816: sub copyrightdescription {
1.166 www 3817: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3818: }
1.197 matthew 3819:
3820: =pod
3821:
1.648 raeburn 3822: =item * &source_copyrightids()
1.192 taceyjo1 3823:
3824: returns list of all source copyrights
3825:
3826: =cut
3827:
3828: sub source_copyrightids {
3829: return sort(keys(%scprtag));
3830: }
3831:
3832: =pod
3833:
1.648 raeburn 3834: =item * &source_copyrightdescription()
1.192 taceyjo1 3835:
3836: returns description of a specified source copyright id
3837:
3838: =cut
3839:
3840: sub source_copyrightdescription {
3841: return &mt($scprtag{shift(@_)});
3842: }
1.112 bowersj2 3843:
3844: =pod
3845:
1.648 raeburn 3846: =item * &filecategories()
1.112 bowersj2 3847:
3848: returns list of all file categories
3849:
3850: =cut
3851:
3852: sub filecategories {
3853: return sort(keys(%category_extensions));
3854: }
3855:
3856: =pod
3857:
1.648 raeburn 3858: =item * &filecategorytypes()
1.112 bowersj2 3859:
3860: returns list of file types belonging to a given file
3861: category
3862:
3863: =cut
3864:
3865: sub filecategorytypes {
1.356 albertel 3866: my ($cat) = @_;
3867: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3868: }
3869:
3870: =pod
3871:
1.648 raeburn 3872: =item * &fileembstyle()
1.112 bowersj2 3873:
3874: returns embedding style for a specified file type
3875:
3876: =cut
3877:
3878: sub fileembstyle {
3879: return $fe{lc(shift(@_))};
1.169 www 3880: }
3881:
1.351 www 3882: sub filemimetype {
3883: return $fm{lc(shift(@_))};
3884: }
3885:
1.169 www 3886:
3887: sub filecategoryselect {
3888: my ($name,$value)=@_;
1.189 matthew 3889: return &select_form($value,$name,
1.970 raeburn 3890: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3891: }
3892:
3893: =pod
3894:
1.648 raeburn 3895: =item * &filedescription()
1.112 bowersj2 3896:
3897: returns description for a specified file type
3898:
3899: =cut
3900:
3901: sub filedescription {
1.188 matthew 3902: my $file_description = $fd{lc(shift())};
3903: $file_description =~ s:([\[\]]):~$1:g;
3904: return &mt($file_description);
1.112 bowersj2 3905: }
3906:
3907: =pod
3908:
1.648 raeburn 3909: =item * &filedescriptionex()
1.112 bowersj2 3910:
3911: returns description for a specified file type with
3912: extra formatting
3913:
3914: =cut
3915:
3916: sub filedescriptionex {
3917: my $ex=shift;
1.188 matthew 3918: my $file_description = $fd{lc($ex)};
3919: $file_description =~ s:([\[\]]):~$1:g;
3920: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3921: }
3922:
3923: # End of .tab access
3924: =pod
3925:
3926: =back
3927:
3928: =cut
3929:
3930: # ------------------------------------------------------------------ File Types
3931: sub fileextensions {
3932: return sort(keys(%fe));
3933: }
3934:
1.97 www 3935: # ----------------------------------------------------------- Display Languages
3936: # returns a hash with all desired display languages
3937: #
3938:
3939: sub display_languages {
3940: my %languages=();
1.695 raeburn 3941: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3942: $languages{$lang}=1;
1.97 www 3943: }
3944: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3945: if ($env{'form.displaylanguage'}) {
1.356 albertel 3946: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3947: $languages{$lang}=1;
1.97 www 3948: }
3949: }
3950: return %languages;
1.14 harris41 3951: }
3952:
1.582 albertel 3953: sub languages {
3954: my ($possible_langs) = @_;
1.695 raeburn 3955: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3956: if (!ref($possible_langs)) {
3957: if( wantarray ) {
3958: return @preferred_langs;
3959: } else {
3960: return $preferred_langs[0];
3961: }
3962: }
3963: my %possibilities = map { $_ => 1 } (@$possible_langs);
3964: my @preferred_possibilities;
3965: foreach my $preferred_lang (@preferred_langs) {
3966: if (exists($possibilities{$preferred_lang})) {
3967: push(@preferred_possibilities, $preferred_lang);
3968: }
3969: }
3970: if( wantarray ) {
3971: return @preferred_possibilities;
3972: }
3973: return $preferred_possibilities[0];
3974: }
3975:
1.742 raeburn 3976: sub user_lang {
3977: my ($touname,$toudom,$fromcid) = @_;
3978: my @userlangs;
3979: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3980: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3981: $env{'course.'.$fromcid.'.languages'}));
3982: } else {
3983: my %langhash = &getlangs($touname,$toudom);
3984: if ($langhash{'languages'} ne '') {
3985: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3986: } else {
3987: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3988: if ($domdefs{'lang_def'} ne '') {
3989: @userlangs = ($domdefs{'lang_def'});
3990: }
3991: }
3992: }
3993: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3994: my $user_lh = Apache::localize->get_handle(@languages);
3995: return $user_lh;
3996: }
3997:
3998:
1.112 bowersj2 3999: ###############################################################
4000: ## Student Answer Attempts ##
4001: ###############################################################
4002:
4003: =pod
4004:
4005: =head1 Alternate Problem Views
4006:
4007: =over 4
4008:
1.648 raeburn 4009: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4010: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4011:
4012: Return string with previous attempt on problem. Arguments:
4013:
4014: =over 4
4015:
4016: =item * $symb: Problem, including path
4017:
4018: =item * $username: username of the desired student
4019:
4020: =item * $domain: domain of the desired student
1.14 harris41 4021:
1.112 bowersj2 4022: =item * $course: Course ID
1.14 harris41 4023:
1.112 bowersj2 4024: =item * $getattempt: Leave blank for all attempts, otherwise put
4025: something
1.14 harris41 4026:
1.112 bowersj2 4027: =item * $regexp: if string matches this regexp, the string will be
4028: sent to $gradesub
1.14 harris41 4029:
1.112 bowersj2 4030: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4031:
1.1199 raeburn 4032: =item * $usec: section of the desired student
4033:
4034: =item * $identifier: counter for student (multiple students one problem) or
4035: problem (one student; whole sequence).
4036:
1.112 bowersj2 4037: =back
1.14 harris41 4038:
1.112 bowersj2 4039: The output string is a table containing all desired attempts, if any.
1.16 harris41 4040:
1.112 bowersj2 4041: =cut
1.1 albertel 4042:
4043: sub get_previous_attempt {
1.1199 raeburn 4044: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4045: my $prevattempts='';
1.43 ng 4046: no strict 'refs';
1.1 albertel 4047: if ($symb) {
1.3 albertel 4048: my (%returnhash)=
4049: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4050: if ($returnhash{'version'}) {
4051: my %lasthash=();
4052: my $version;
4053: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4054: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4055: if ($key =~ /\.rawrndseed$/) {
4056: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4057: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4058: } else {
4059: $lasthash{$key}=$returnhash{$version.':'.$key};
4060: }
1.19 harris41 4061: }
1.1 albertel 4062: }
1.596 albertel 4063: $prevattempts=&start_data_table().&start_data_table_header_row();
4064: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4065: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4066: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4067: foreach my $key (sort(keys(%lasthash))) {
4068: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4069: if ($#parts > 0) {
1.31 albertel 4070: my $data=$parts[-1];
1.989 raeburn 4071: next if ($data eq 'foilorder');
1.31 albertel 4072: pop(@parts);
1.1010 www 4073: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4074: if ($data eq 'type') {
4075: unless ($showsurv) {
4076: my $id = join(',',@parts);
4077: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4078: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4079: $lasthidden{$ign.'.'.$id} = 1;
4080: }
1.945 raeburn 4081: }
1.1199 raeburn 4082: if ($identifier ne '') {
4083: my $id = join(',',@parts);
4084: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4085: $domain,$username,$usec,undef,$course) =~ /^no/) {
4086: $hidestatus{$ign.'.'.$id} = 1;
4087: }
4088: }
4089: } elsif ($data eq 'regrader') {
4090: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4091: my $id = join(',',@parts);
4092: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4093: }
1.1010 www 4094: }
1.31 albertel 4095: } else {
1.41 ng 4096: if ($#parts == 0) {
4097: $prevattempts.='<th>'.$parts[0].'</th>';
4098: } else {
4099: $prevattempts.='<th>'.$ign.'</th>';
4100: }
1.31 albertel 4101: }
1.16 harris41 4102: }
1.596 albertel 4103: $prevattempts.=&end_data_table_header_row();
1.40 ng 4104: if ($getattempt eq '') {
1.1199 raeburn 4105: my (%solved,%resets,%probstatus);
1.1200 raeburn 4106: if (($identifier ne '') && (keys(%regraded) > 0)) {
4107: for ($version=1;$version<=$returnhash{'version'};$version++) {
4108: foreach my $id (keys(%regraded)) {
4109: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4110: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4111: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4112: push(@{$resets{$id}},$version);
1.1199 raeburn 4113: }
4114: }
4115: }
1.1200 raeburn 4116: }
4117: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4118: my (@hidden,@unsolved);
1.945 raeburn 4119: if (%typeparts) {
4120: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4121: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4122: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4123: push(@hidden,$id);
1.1199 raeburn 4124: } elsif ($identifier ne '') {
4125: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4126: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4127: ($hidestatus{$id})) {
1.1200 raeburn 4128: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4129: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4130: push(@{$solved{$id}},$version);
4131: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4132: (ref($solved{$id}) eq 'ARRAY')) {
4133: my $skip;
4134: if (ref($resets{$id}) eq 'ARRAY') {
4135: foreach my $reset (@{$resets{$id}}) {
4136: if ($reset > $solved{$id}[-1]) {
4137: $skip=1;
4138: last;
4139: }
4140: }
4141: }
4142: unless ($skip) {
4143: my ($ign,$partslist) = split(/\./,$id,2);
4144: push(@unsolved,$partslist);
4145: }
4146: }
4147: }
1.945 raeburn 4148: }
4149: }
4150: }
4151: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4152: '<td>'.&mt('Transaction [_1]',$version);
4153: if (@unsolved) {
4154: $prevattempts .= '<span class="LC_nobreak"><label>'.
4155: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4156: &mt('Hide').'</label></span>';
4157: }
4158: $prevattempts .= '</td>';
1.945 raeburn 4159: if (@hidden) {
4160: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4161: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4162: my $hide;
4163: foreach my $id (@hidden) {
4164: if ($key =~ /^\Q$id\E/) {
4165: $hide = 1;
4166: last;
4167: }
4168: }
4169: if ($hide) {
4170: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4171: if (($data eq 'award') || ($data eq 'awarddetail')) {
4172: my $value = &format_previous_attempt_value($key,
4173: $returnhash{$version.':'.$key});
1.1173 kruse 4174: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4175: } else {
4176: $prevattempts.='<td> </td>';
4177: }
4178: } else {
4179: if ($key =~ /\./) {
1.1212 raeburn 4180: my $value = $returnhash{$version.':'.$key};
4181: if ($key =~ /\.rndseed$/) {
4182: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4183: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4184: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4185: }
4186: }
4187: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4188: ' </td>';
1.945 raeburn 4189: } else {
4190: $prevattempts.='<td> </td>';
4191: }
4192: }
4193: }
4194: } else {
4195: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4196: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4197: my $value = $returnhash{$version.':'.$key};
4198: if ($key =~ /\.rndseed$/) {
4199: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4200: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4201: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4202: }
4203: }
4204: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4205: ' </td>';
1.945 raeburn 4206: }
4207: }
4208: $prevattempts.=&end_data_table_row();
1.40 ng 4209: }
1.1 albertel 4210: }
1.945 raeburn 4211: my @currhidden = keys(%lasthidden);
1.596 albertel 4212: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4213: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4214: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4215: if (%typeparts) {
4216: my $hidden;
4217: foreach my $id (@currhidden) {
4218: if ($key =~ /^\Q$id\E/) {
4219: $hidden = 1;
4220: last;
4221: }
4222: }
4223: if ($hidden) {
4224: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4225: if (($data eq 'award') || ($data eq 'awarddetail')) {
4226: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4227: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4228: $value = &$gradesub($value);
4229: }
1.1173 kruse 4230: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4231: } else {
4232: $prevattempts.='<td> </td>';
4233: }
4234: } else {
4235: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4236: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4237: $value = &$gradesub($value);
4238: }
1.1173 kruse 4239: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4240: }
4241: } else {
4242: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4243: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4244: $value = &$gradesub($value);
4245: }
1.1173 kruse 4246: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4247: }
1.16 harris41 4248: }
1.596 albertel 4249: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4250: } else {
1.596 albertel 4251: $prevattempts=
4252: &start_data_table().&start_data_table_row().
4253: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4254: &end_data_table_row().&end_data_table();
1.1 albertel 4255: }
4256: } else {
1.596 albertel 4257: $prevattempts=
4258: &start_data_table().&start_data_table_row().
4259: '<td>'.&mt('No data.').'</td>'.
4260: &end_data_table_row().&end_data_table();
1.1 albertel 4261: }
1.10 albertel 4262: }
4263:
1.581 albertel 4264: sub format_previous_attempt_value {
4265: my ($key,$value) = @_;
1.1011 www 4266: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4267: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4268: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4269: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4270: } elsif ($key =~ /answerstring$/) {
4271: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4272: my @answer = %answers;
4273: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4274: my @anskeys = sort(keys(%answers));
4275: if (@anskeys == 1) {
4276: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4277: if ($answer =~ m{\0}) {
4278: $answer =~ s{\0}{,}g;
1.988 raeburn 4279: }
4280: my $tag_internal_answer_name = 'INTERNAL';
4281: if ($anskeys[0] eq $tag_internal_answer_name) {
4282: $value = $answer;
4283: } else {
4284: $value = $anskeys[0].'='.$answer;
4285: }
4286: } else {
4287: foreach my $ans (@anskeys) {
4288: my $answer = $answers{$ans};
1.1001 raeburn 4289: if ($answer =~ m{\0}) {
4290: $answer =~ s{\0}{,}g;
1.988 raeburn 4291: }
4292: $value .= $ans.'='.$answer.'<br />';;
4293: }
4294: }
1.581 albertel 4295: } else {
1.1173 kruse 4296: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4297: }
4298: return $value;
4299: }
4300:
4301:
1.107 albertel 4302: sub relative_to_absolute {
4303: my ($url,$output)=@_;
4304: my $parser=HTML::TokeParser->new(\$output);
4305: my $token;
4306: my $thisdir=$url;
4307: my @rlinks=();
4308: while ($token=$parser->get_token) {
4309: if ($token->[0] eq 'S') {
4310: if ($token->[1] eq 'a') {
4311: if ($token->[2]->{'href'}) {
4312: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4313: }
4314: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4315: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4316: } elsif ($token->[1] eq 'base') {
4317: $thisdir=$token->[2]->{'href'};
4318: }
4319: }
4320: }
4321: $thisdir=~s-/[^/]*$--;
1.356 albertel 4322: foreach my $link (@rlinks) {
1.726 raeburn 4323: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4324: ($link=~/^\//) ||
4325: ($link=~/^javascript:/i) ||
4326: ($link=~/^mailto:/i) ||
4327: ($link=~/^\#/)) {
4328: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4329: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4330: }
4331: }
4332: # -------------------------------------------------- Deal with Applet codebases
4333: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4334: return $output;
4335: }
4336:
1.112 bowersj2 4337: =pod
4338:
1.648 raeburn 4339: =item * &get_student_view()
1.112 bowersj2 4340:
4341: show a snapshot of what student was looking at
4342:
4343: =cut
4344:
1.10 albertel 4345: sub get_student_view {
1.186 albertel 4346: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4347: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4348: my (%form);
1.10 albertel 4349: my @elements=('symb','courseid','domain','username');
4350: foreach my $element (@elements) {
1.186 albertel 4351: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4352: }
1.186 albertel 4353: if (defined($moreenv)) {
4354: %form=(%form,%{$moreenv});
4355: }
1.236 albertel 4356: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4357: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4358: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4359: $userview=~s/\<body[^\>]*\>//gi;
4360: $userview=~s/\<\/body\>//gi;
4361: $userview=~s/\<html\>//gi;
4362: $userview=~s/\<\/html\>//gi;
4363: $userview=~s/\<head\>//gi;
4364: $userview=~s/\<\/head\>//gi;
4365: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4366: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4367: if (wantarray) {
4368: return ($userview,$response);
4369: } else {
4370: return $userview;
4371: }
4372: }
4373:
4374: sub get_student_view_with_retries {
4375: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4376:
4377: my $ok = 0; # True if we got a good response.
4378: my $content;
4379: my $response;
4380:
4381: # Try to get the student_view done. within the retries count:
4382:
4383: do {
4384: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4385: $ok = $response->is_success;
4386: if (!$ok) {
4387: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4388: }
4389: $retries--;
4390: } while (!$ok && ($retries > 0));
4391:
4392: if (!$ok) {
4393: $content = ''; # On error return an empty content.
4394: }
1.651 www 4395: if (wantarray) {
4396: return ($content, $response);
4397: } else {
4398: return $content;
4399: }
1.11 albertel 4400: }
4401:
1.112 bowersj2 4402: =pod
4403:
1.648 raeburn 4404: =item * &get_student_answers()
1.112 bowersj2 4405:
4406: show a snapshot of how student was answering problem
4407:
4408: =cut
4409:
1.11 albertel 4410: sub get_student_answers {
1.100 sakharuk 4411: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4412: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4413: my (%moreenv);
1.11 albertel 4414: my @elements=('symb','courseid','domain','username');
4415: foreach my $element (@elements) {
1.186 albertel 4416: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4417: }
1.186 albertel 4418: $moreenv{'grade_target'}='answer';
4419: %moreenv=(%form,%moreenv);
1.497 raeburn 4420: $feedurl = &Apache::lonnet::clutter($feedurl);
4421: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4422: return $userview;
1.1 albertel 4423: }
1.116 albertel 4424:
4425: =pod
4426:
4427: =item * &submlink()
4428:
1.242 albertel 4429: Inputs: $text $uname $udom $symb $target
1.116 albertel 4430:
4431: Returns: A link to grades.pm such as to see the SUBM view of a student
4432:
4433: =cut
4434:
4435: ###############################################
4436: sub submlink {
1.242 albertel 4437: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4438: if (!($uname && $udom)) {
4439: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4440: &Apache::lonnet::whichuser($symb);
1.116 albertel 4441: if (!$symb) { $symb=$cursymb; }
4442: }
1.254 matthew 4443: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4444: $symb=&escape($symb);
1.960 bisitz 4445: if ($target) { $target=" target=\"$target\""; }
4446: return
4447: '<a href="/adm/grades?command=submission'.
4448: '&symb='.$symb.
4449: '&student='.$uname.
4450: '&userdom='.$udom.'"'.
4451: $target.'>'.$text.'</a>';
1.242 albertel 4452: }
4453: ##############################################
4454:
4455: =pod
4456:
4457: =item * &pgrdlink()
4458:
4459: Inputs: $text $uname $udom $symb $target
4460:
4461: Returns: A link to grades.pm such as to see the PGRD view of a student
4462:
4463: =cut
4464:
4465: ###############################################
4466: sub pgrdlink {
4467: my $link=&submlink(@_);
4468: $link=~s/(&command=submission)/$1&showgrading=yes/;
4469: return $link;
4470: }
4471: ##############################################
4472:
4473: =pod
4474:
4475: =item * &pprmlink()
4476:
4477: Inputs: $text $uname $udom $symb $target
4478:
4479: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4480: student and a specific resource
1.242 albertel 4481:
4482: =cut
4483:
4484: ###############################################
4485: sub pprmlink {
4486: my ($text,$uname,$udom,$symb,$target)=@_;
4487: if (!($uname && $udom)) {
4488: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4489: &Apache::lonnet::whichuser($symb);
1.242 albertel 4490: if (!$symb) { $symb=$cursymb; }
4491: }
1.254 matthew 4492: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4493: $symb=&escape($symb);
1.242 albertel 4494: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4495: return '<a href="/adm/parmset?command=set&'.
4496: 'symb='.$symb.'&uname='.$uname.
4497: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4498: }
4499: ##############################################
1.37 matthew 4500:
1.112 bowersj2 4501: =pod
4502:
4503: =back
4504:
4505: =cut
4506:
1.37 matthew 4507: ###############################################
1.51 www 4508:
4509:
4510: sub timehash {
1.687 raeburn 4511: my ($thistime) = @_;
4512: my $timezone = &Apache::lonlocal::gettimezone();
4513: my $dt = DateTime->from_epoch(epoch => $thistime)
4514: ->set_time_zone($timezone);
4515: my $wday = $dt->day_of_week();
4516: if ($wday == 7) { $wday = 0; }
4517: return ( 'second' => $dt->second(),
4518: 'minute' => $dt->minute(),
4519: 'hour' => $dt->hour(),
4520: 'day' => $dt->day_of_month(),
4521: 'month' => $dt->month(),
4522: 'year' => $dt->year(),
4523: 'weekday' => $wday,
4524: 'dayyear' => $dt->day_of_year(),
4525: 'dlsav' => $dt->is_dst() );
1.51 www 4526: }
4527:
1.370 www 4528: sub utc_string {
4529: my ($date)=@_;
1.371 www 4530: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4531: }
4532:
1.51 www 4533: sub maketime {
4534: my %th=@_;
1.687 raeburn 4535: my ($epoch_time,$timezone,$dt);
4536: $timezone = &Apache::lonlocal::gettimezone();
4537: eval {
4538: $dt = DateTime->new( year => $th{'year'},
4539: month => $th{'month'},
4540: day => $th{'day'},
4541: hour => $th{'hour'},
4542: minute => $th{'minute'},
4543: second => $th{'second'},
4544: time_zone => $timezone,
4545: );
4546: };
4547: if (!$@) {
4548: $epoch_time = $dt->epoch;
4549: if ($epoch_time) {
4550: return $epoch_time;
4551: }
4552: }
1.51 www 4553: return POSIX::mktime(
4554: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4555: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4556: }
4557:
4558: #########################################
1.51 www 4559:
4560: sub findallcourses {
1.482 raeburn 4561: my ($roles,$uname,$udom) = @_;
1.355 albertel 4562: my %roles;
4563: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4564: my %courses;
1.51 www 4565: my $now=time;
1.482 raeburn 4566: if (!defined($uname)) {
4567: $uname = $env{'user.name'};
4568: }
4569: if (!defined($udom)) {
4570: $udom = $env{'user.domain'};
4571: }
4572: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4573: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4574: if (!%roles) {
4575: %roles = (
4576: cc => 1,
1.907 raeburn 4577: co => 1,
1.482 raeburn 4578: in => 1,
4579: ep => 1,
4580: ta => 1,
4581: cr => 1,
4582: st => 1,
4583: );
4584: }
4585: foreach my $entry (keys(%roleshash)) {
4586: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4587: if ($trole =~ /^cr/) {
4588: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4589: } else {
4590: next if (!exists($roles{$trole}));
4591: }
4592: if ($tend) {
4593: next if ($tend < $now);
4594: }
4595: if ($tstart) {
4596: next if ($tstart > $now);
4597: }
1.1058 raeburn 4598: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4599: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4600: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4601: if ($secpart eq '') {
4602: ($cnum,$role) = split(/_/,$cnumpart);
4603: $sec = 'none';
1.1058 raeburn 4604: $value .= $cnum.'/';
1.482 raeburn 4605: } else {
4606: $cnum = $cnumpart;
4607: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4608: $value .= $cnum.'/'.$sec;
4609: }
4610: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4611: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4612: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4613: }
4614: } else {
4615: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4616: }
1.482 raeburn 4617: }
4618: } else {
4619: foreach my $key (keys(%env)) {
1.483 albertel 4620: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4621: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4622: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4623: next if ($role eq 'ca' || $role eq 'aa');
4624: next if (%roles && !exists($roles{$role}));
4625: my ($starttime,$endtime)=split(/\./,$env{$key});
4626: my $active=1;
4627: if ($starttime) {
4628: if ($now<$starttime) { $active=0; }
4629: }
4630: if ($endtime) {
4631: if ($now>$endtime) { $active=0; }
4632: }
4633: if ($active) {
1.1058 raeburn 4634: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4635: if ($sec eq '') {
4636: $sec = 'none';
1.1058 raeburn 4637: } else {
4638: $value .= $sec;
4639: }
4640: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4641: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4642: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4643: }
4644: } else {
4645: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4646: }
1.474 raeburn 4647: }
4648: }
1.51 www 4649: }
4650: }
1.474 raeburn 4651: return %courses;
1.51 www 4652: }
1.37 matthew 4653:
1.54 www 4654: ###############################################
1.474 raeburn 4655:
4656: sub blockcheck {
1.1189 raeburn 4657: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4658:
1.1189 raeburn 4659: if (defined($udom) && defined($uname)) {
4660: # If uname and udom are for a course, check for blocks in the course.
4661: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4662: my ($startblock,$endblock,$triggerblock) =
4663: &get_blocks($setters,$activity,$udom,$uname,$url);
4664: return ($startblock,$endblock,$triggerblock);
4665: }
4666: } else {
1.490 raeburn 4667: $udom = $env{'user.domain'};
4668: $uname = $env{'user.name'};
4669: }
4670:
1.502 raeburn 4671: my $startblock = 0;
4672: my $endblock = 0;
1.1062 raeburn 4673: my $triggerblock = '';
1.482 raeburn 4674: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4675:
1.490 raeburn 4676: # If uname is for a user, and activity is course-specific, i.e.,
4677: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4678:
1.490 raeburn 4679: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1189 raeburn 4680: $activity eq 'groups' || $activity eq 'printout') &&
4681: ($env{'request.course.id'})) {
1.490 raeburn 4682: foreach my $key (keys(%live_courses)) {
4683: if ($key ne $env{'request.course.id'}) {
4684: delete($live_courses{$key});
4685: }
4686: }
4687: }
4688:
4689: my $otheruser = 0;
4690: my %own_courses;
4691: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4692: # Resource belongs to user other than current user.
4693: $otheruser = 1;
4694: # Gather courses for current user
4695: %own_courses =
4696: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4697: }
4698:
4699: # Gather active course roles - course coordinator, instructor,
4700: # exam proctor, ta, student, or custom role.
1.474 raeburn 4701:
4702: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4703: my ($cdom,$cnum);
4704: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4705: $cdom = $env{'course.'.$course.'.domain'};
4706: $cnum = $env{'course.'.$course.'.num'};
4707: } else {
1.490 raeburn 4708: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4709: }
4710: my $no_ownblock = 0;
4711: my $no_userblock = 0;
1.533 raeburn 4712: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4713: # Check if current user has 'evb' priv for this
4714: if (defined($own_courses{$course})) {
4715: foreach my $sec (keys(%{$own_courses{$course}})) {
4716: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4717: if ($sec ne 'none') {
4718: $checkrole .= '/'.$sec;
4719: }
4720: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4721: $no_ownblock = 1;
4722: last;
4723: }
4724: }
4725: }
4726: # if they have 'evb' priv and are currently not playing student
4727: next if (($no_ownblock) &&
4728: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4729: }
1.474 raeburn 4730: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4731: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4732: if ($sec ne 'none') {
1.482 raeburn 4733: $checkrole .= '/'.$sec;
1.474 raeburn 4734: }
1.490 raeburn 4735: if ($otheruser) {
4736: # Resource belongs to user other than current user.
4737: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4738: my (%allroles,%userroles);
4739: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4740: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4741: my ($trole,$tdom,$tnum,$tsec);
4742: if ($entry =~ /^cr/) {
4743: ($trole,$tdom,$tnum,$tsec) =
4744: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4745: } else {
4746: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4747: }
4748: my ($spec,$area,$trest);
4749: $area = '/'.$tdom.'/'.$tnum;
4750: $trest = $tnum;
4751: if ($tsec ne '') {
4752: $area .= '/'.$tsec;
4753: $trest .= '/'.$tsec;
4754: }
4755: $spec = $trole.'.'.$area;
4756: if ($trole =~ /^cr/) {
4757: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4758: $tdom,$spec,$trest,$area);
4759: } else {
4760: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4761: $tdom,$spec,$trest,$area);
4762: }
4763: }
4764: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4765: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4766: if ($1) {
4767: $no_userblock = 1;
4768: last;
4769: }
1.486 raeburn 4770: }
4771: }
1.490 raeburn 4772: } else {
4773: # Resource belongs to current user
4774: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4775: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4776: $no_ownblock = 1;
4777: last;
4778: }
1.474 raeburn 4779: }
4780: }
4781: # if they have the evb priv and are currently not playing student
1.482 raeburn 4782: next if (($no_ownblock) &&
1.491 albertel 4783: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4784: next if ($no_userblock);
1.474 raeburn 4785:
1.866 kalberla 4786: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4787: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4788:
1.1062 raeburn 4789: my ($start,$end,$trigger) =
4790: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4791: if (($start != 0) &&
4792: (($startblock == 0) || ($startblock > $start))) {
4793: $startblock = $start;
1.1062 raeburn 4794: if ($trigger ne '') {
4795: $triggerblock = $trigger;
4796: }
1.502 raeburn 4797: }
4798: if (($end != 0) &&
4799: (($endblock == 0) || ($endblock < $end))) {
4800: $endblock = $end;
1.1062 raeburn 4801: if ($trigger ne '') {
4802: $triggerblock = $trigger;
4803: }
1.502 raeburn 4804: }
1.490 raeburn 4805: }
1.1062 raeburn 4806: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4807: }
4808:
4809: sub get_blocks {
1.1062 raeburn 4810: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4811: my $startblock = 0;
4812: my $endblock = 0;
1.1062 raeburn 4813: my $triggerblock = '';
1.490 raeburn 4814: my $course = $cdom.'_'.$cnum;
4815: $setters->{$course} = {};
4816: $setters->{$course}{'staff'} = [];
4817: $setters->{$course}{'times'} = [];
1.1062 raeburn 4818: $setters->{$course}{'triggers'} = [];
4819: my (@blockers,%triggered);
4820: my $now = time;
4821: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4822: if ($activity eq 'docs') {
4823: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4824: foreach my $block (@blockers) {
4825: if ($block =~ /^firstaccess____(.+)$/) {
4826: my $item = $1;
4827: my $type = 'map';
4828: my $timersymb = $item;
4829: if ($item eq 'course') {
4830: $type = 'course';
4831: } elsif ($item =~ /___\d+___/) {
4832: $type = 'resource';
4833: } else {
4834: $timersymb = &Apache::lonnet::symbread($item);
4835: }
4836: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4837: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4838: $triggered{$block} = {
4839: start => $start,
4840: end => $end,
4841: type => $type,
4842: };
4843: }
4844: }
4845: } else {
4846: foreach my $block (keys(%commblocks)) {
4847: if ($block =~ m/^(\d+)____(\d+)$/) {
4848: my ($start,$end) = ($1,$2);
4849: if ($start <= time && $end >= time) {
4850: if (ref($commblocks{$block}) eq 'HASH') {
4851: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4852: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4853: unless(grep(/^\Q$block\E$/,@blockers)) {
4854: push(@blockers,$block);
4855: }
4856: }
4857: }
4858: }
4859: }
4860: } elsif ($block =~ /^firstaccess____(.+)$/) {
4861: my $item = $1;
4862: my $timersymb = $item;
4863: my $type = 'map';
4864: if ($item eq 'course') {
4865: $type = 'course';
4866: } elsif ($item =~ /___\d+___/) {
4867: $type = 'resource';
4868: } else {
4869: $timersymb = &Apache::lonnet::symbread($item);
4870: }
4871: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4872: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4873: if ($start && $end) {
4874: if (($start <= time) && ($end >= time)) {
4875: unless (grep(/^\Q$block\E$/,@blockers)) {
4876: push(@blockers,$block);
4877: $triggered{$block} = {
4878: start => $start,
4879: end => $end,
4880: type => $type,
4881: };
4882: }
4883: }
1.490 raeburn 4884: }
1.1062 raeburn 4885: }
4886: }
4887: }
4888: foreach my $blocker (@blockers) {
4889: my ($staff_name,$staff_dom,$title,$blocks) =
4890: &parse_block_record($commblocks{$blocker});
4891: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4892: my ($start,$end,$triggertype);
4893: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4894: ($start,$end) = ($1,$2);
4895: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4896: $start = $triggered{$blocker}{'start'};
4897: $end = $triggered{$blocker}{'end'};
4898: $triggertype = $triggered{$blocker}{'type'};
4899: }
4900: if ($start) {
4901: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4902: if ($triggertype) {
4903: push(@{$$setters{$course}{'triggers'}},$triggertype);
4904: } else {
4905: push(@{$$setters{$course}{'triggers'}},0);
4906: }
4907: if ( ($startblock == 0) || ($startblock > $start) ) {
4908: $startblock = $start;
4909: if ($triggertype) {
4910: $triggerblock = $blocker;
1.474 raeburn 4911: }
4912: }
1.1062 raeburn 4913: if ( ($endblock == 0) || ($endblock < $end) ) {
4914: $endblock = $end;
4915: if ($triggertype) {
4916: $triggerblock = $blocker;
4917: }
4918: }
1.474 raeburn 4919: }
4920: }
1.1062 raeburn 4921: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4922: }
4923:
4924: sub parse_block_record {
4925: my ($record) = @_;
4926: my ($setuname,$setudom,$title,$blocks);
4927: if (ref($record) eq 'HASH') {
4928: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4929: $title = &unescape($record->{'event'});
4930: $blocks = $record->{'blocks'};
4931: } else {
4932: my @data = split(/:/,$record,3);
4933: if (scalar(@data) eq 2) {
4934: $title = $data[1];
4935: ($setuname,$setudom) = split(/@/,$data[0]);
4936: } else {
4937: ($setuname,$setudom,$title) = @data;
4938: }
4939: $blocks = { 'com' => 'on' };
4940: }
4941: return ($setuname,$setudom,$title,$blocks);
4942: }
4943:
1.854 kalberla 4944: sub blocking_status {
1.1189 raeburn 4945: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4946: my %setters;
1.890 droeschl 4947:
1.1061 raeburn 4948: # check for active blocking
1.1062 raeburn 4949: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 4950: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4951: my $blocked = 0;
4952: if ($startblock && $endblock) {
4953: $blocked = 1;
4954: }
1.890 droeschl 4955:
1.1061 raeburn 4956: # caller just wants to know whether a block is active
4957: if (!wantarray) { return $blocked; }
4958:
4959: # build a link to a popup window containing the details
4960: my $querystring = "?activity=$activity";
4961: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4962: if ($activity eq 'port') {
4963: $querystring .= "&udom=$udom" if $udom;
4964: $querystring .= "&uname=$uname" if $uname;
4965: } elsif ($activity eq 'docs') {
4966: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4967: }
1.1061 raeburn 4968:
4969: my $output .= <<'END_MYBLOCK';
4970: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4971: var options = "width=" + w + ",height=" + h + ",";
4972: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4973: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4974: var newWin = window.open(url, wdwName, options);
4975: newWin.focus();
4976: }
1.890 droeschl 4977: END_MYBLOCK
1.854 kalberla 4978:
1.1061 raeburn 4979: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4980:
1.1061 raeburn 4981: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4982: my $text = &mt('Communication Blocked');
1.1217 raeburn 4983: my $class = 'LC_comblock';
1.1062 raeburn 4984: if ($activity eq 'docs') {
4985: $text = &mt('Content Access Blocked');
1.1217 raeburn 4986: $class = '';
1.1063 raeburn 4987: } elsif ($activity eq 'printout') {
4988: $text = &mt('Printing Blocked');
1.1062 raeburn 4989: }
1.1061 raeburn 4990: $output .= <<"END_BLOCK";
1.1217 raeburn 4991: <div class='$class'>
1.869 kalberla 4992: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4993: title='$text'>
4994: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4995: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4996: title='$text'>$text</a>
1.867 kalberla 4997: </div>
4998:
4999: END_BLOCK
1.474 raeburn 5000:
1.1061 raeburn 5001: return ($blocked, $output);
1.854 kalberla 5002: }
1.490 raeburn 5003:
1.60 matthew 5004: ###############################################
5005:
1.682 raeburn 5006: sub check_ip_acc {
1.1201 raeburn 5007: my ($acc,$clientip)=@_;
1.682 raeburn 5008: &Apache::lonxml::debug("acc is $acc");
5009: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5010: return 1;
5011: }
1.1219 raeburn 5012: my $allowed;
1.1201 raeburn 5013: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
1.682 raeburn 5014:
5015: my $name;
1.1219 raeburn 5016: my %access = (
5017: allowfrom => 1,
5018: denyfrom => 0,
5019: );
5020: my @allows;
5021: my @denies;
5022: foreach my $item (split(',',$acc)) {
5023: $item =~ s/^\s*//;
5024: $item =~ s/\s*$//;
5025: my $pattern;
5026: if ($item =~ /^\!(.+)$/) {
5027: push(@denies,$1);
5028: } else {
5029: push(@allows,$item);
5030: }
5031: }
5032: my $numdenies = scalar(@denies);
5033: my $numallows = scalar(@allows);
5034: my $count = 0;
5035: foreach my $pattern (@denies,@allows) {
5036: $count ++;
5037: my $acctype = 'allowfrom';
5038: if ($count <= $numdenies) {
5039: $acctype = 'denyfrom';
5040: }
1.682 raeburn 5041: if ($pattern =~ /\*$/) {
5042: #35.8.*
5043: $pattern=~s/\*//;
1.1219 raeburn 5044: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5045: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5046: #35.8.3.[34-56]
5047: my $low=$2;
5048: my $high=$3;
5049: $pattern=$1;
5050: if ($ip =~ /^\Q$pattern\E/) {
5051: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5052: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5053: }
5054: } elsif ($pattern =~ /^\*/) {
5055: #*.msu.edu
5056: $pattern=~s/\*//;
5057: if (!defined($name)) {
5058: use Socket;
5059: my $netaddr=inet_aton($ip);
5060: ($name)=gethostbyaddr($netaddr,AF_INET);
5061: }
1.1219 raeburn 5062: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5063: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5064: #127.0.0.1
1.1219 raeburn 5065: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5066: } else {
5067: #some.name.com
5068: if (!defined($name)) {
5069: use Socket;
5070: my $netaddr=inet_aton($ip);
5071: ($name)=gethostbyaddr($netaddr,AF_INET);
5072: }
1.1219 raeburn 5073: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5074: }
5075: if ($allowed =~ /^(0|1)$/) { last; }
5076: }
5077: if ($allowed eq '') {
5078: if ($numdenies && !$numallows) {
5079: $allowed = 1;
5080: } else {
5081: $allowed = 0;
1.682 raeburn 5082: }
5083: }
5084: return $allowed;
5085: }
5086:
5087: ###############################################
5088:
1.60 matthew 5089: =pod
5090:
1.112 bowersj2 5091: =head1 Domain Template Functions
5092:
5093: =over 4
5094:
5095: =item * &determinedomain()
1.60 matthew 5096:
5097: Inputs: $domain (usually will be undef)
5098:
1.63 www 5099: Returns: Determines which domain should be used for designs
1.60 matthew 5100:
5101: =cut
1.54 www 5102:
1.60 matthew 5103: ###############################################
1.63 www 5104: sub determinedomain {
5105: my $domain=shift;
1.531 albertel 5106: if (! $domain) {
1.60 matthew 5107: # Determine domain if we have not been given one
1.893 raeburn 5108: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5109: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5110: if ($env{'request.role.domain'}) {
5111: $domain=$env{'request.role.domain'};
1.60 matthew 5112: }
5113: }
1.63 www 5114: return $domain;
5115: }
5116: ###############################################
1.517 raeburn 5117:
1.518 albertel 5118: sub devalidate_domconfig_cache {
5119: my ($udom)=@_;
5120: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5121: }
5122:
5123: # ---------------------- Get domain configuration for a domain
5124: sub get_domainconf {
5125: my ($udom) = @_;
5126: my $cachetime=1800;
5127: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5128: if (defined($cached)) { return %{$result}; }
5129:
5130: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5131: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5132: my (%designhash,%legacy);
1.518 albertel 5133: if (keys(%domconfig) > 0) {
5134: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5135: if (keys(%{$domconfig{'login'}})) {
5136: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5137: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5138: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5139: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5140: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5141: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5142: if ($key eq 'loginvia') {
5143: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5144: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5145: $designhash{$udom.'.login.loginvia'} = $server;
5146: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5147:
5148: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5149: } else {
5150: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5151: }
1.948 raeburn 5152: }
1.1208 raeburn 5153: } elsif ($key eq 'headtag') {
5154: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5155: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5156: }
1.946 raeburn 5157: }
1.1208 raeburn 5158: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5159: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5160: }
1.946 raeburn 5161: }
5162: }
5163: }
5164: } else {
5165: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5166: $designhash{$udom.'.login.'.$key.'_'.$img} =
5167: $domconfig{'login'}{$key}{$img};
5168: }
1.699 raeburn 5169: }
5170: } else {
5171: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5172: }
1.632 raeburn 5173: }
5174: } else {
5175: $legacy{'login'} = 1;
1.518 albertel 5176: }
1.632 raeburn 5177: } else {
5178: $legacy{'login'} = 1;
1.518 albertel 5179: }
5180: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5181: if (keys(%{$domconfig{'rolecolors'}})) {
5182: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5183: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5184: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5185: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5186: }
1.518 albertel 5187: }
5188: }
1.632 raeburn 5189: } else {
5190: $legacy{'rolecolors'} = 1;
1.518 albertel 5191: }
1.632 raeburn 5192: } else {
5193: $legacy{'rolecolors'} = 1;
1.518 albertel 5194: }
1.948 raeburn 5195: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5196: if ($domconfig{'autoenroll'}{'co-owners'}) {
5197: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5198: }
5199: }
1.632 raeburn 5200: if (keys(%legacy) > 0) {
5201: my %legacyhash = &get_legacy_domconf($udom);
5202: foreach my $item (keys(%legacyhash)) {
5203: if ($item =~ /^\Q$udom\E\.login/) {
5204: if ($legacy{'login'}) {
5205: $designhash{$item} = $legacyhash{$item};
5206: }
5207: } else {
5208: if ($legacy{'rolecolors'}) {
5209: $designhash{$item} = $legacyhash{$item};
5210: }
1.518 albertel 5211: }
5212: }
5213: }
1.632 raeburn 5214: } else {
5215: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5216: }
5217: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5218: $cachetime);
5219: return %designhash;
5220: }
5221:
1.632 raeburn 5222: sub get_legacy_domconf {
5223: my ($udom) = @_;
5224: my %legacyhash;
5225: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5226: my $designfile = $designdir.'/'.$udom.'.tab';
5227: if (-e $designfile) {
5228: if ( open (my $fh,"<$designfile") ) {
5229: while (my $line = <$fh>) {
5230: next if ($line =~ /^\#/);
5231: chomp($line);
5232: my ($key,$val)=(split(/\=/,$line));
5233: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5234: }
5235: close($fh);
5236: }
5237: }
1.1026 raeburn 5238: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5239: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5240: }
5241: return %legacyhash;
5242: }
5243:
1.63 www 5244: =pod
5245:
1.112 bowersj2 5246: =item * &domainlogo()
1.63 www 5247:
5248: Inputs: $domain (usually will be undef)
5249:
5250: Returns: A link to a domain logo, if the domain logo exists.
5251: If the domain logo does not exist, a description of the domain.
5252:
5253: =cut
1.112 bowersj2 5254:
1.63 www 5255: ###############################################
5256: sub domainlogo {
1.517 raeburn 5257: my $domain = &determinedomain(shift);
1.518 albertel 5258: my %designhash = &get_domainconf($domain);
1.517 raeburn 5259: # See if there is a logo
5260: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5261: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5262: if ($imgsrc =~ m{^/(adm|res)/}) {
5263: if ($imgsrc =~ m{^/res/}) {
5264: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5265: &Apache::lonnet::repcopy($local_name);
5266: }
5267: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5268: }
5269: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5270: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5271: return &Apache::lonnet::domain($domain,'description');
1.59 www 5272: } else {
1.60 matthew 5273: return '';
1.59 www 5274: }
5275: }
1.63 www 5276: ##############################################
5277:
5278: =pod
5279:
1.112 bowersj2 5280: =item * &designparm()
1.63 www 5281:
5282: Inputs: $which parameter; $domain (usually will be undef)
5283:
5284: Returns: value of designparamter $which
5285:
5286: =cut
1.112 bowersj2 5287:
1.397 albertel 5288:
1.400 albertel 5289: ##############################################
1.397 albertel 5290: sub designparm {
5291: my ($which,$domain)=@_;
5292: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5293: return $env{'environment.color.'.$which};
1.96 www 5294: }
1.63 www 5295: $domain=&determinedomain($domain);
1.1016 raeburn 5296: my %domdesign;
5297: unless ($domain eq 'public') {
5298: %domdesign = &get_domainconf($domain);
5299: }
1.520 raeburn 5300: my $output;
1.517 raeburn 5301: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5302: $output = $domdesign{$domain.'.'.$which};
1.63 www 5303: } else {
1.520 raeburn 5304: $output = $defaultdesign{$which};
5305: }
5306: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5307: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5308: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5309: if ($output =~ m{^/res/}) {
5310: my $local_name = &Apache::lonnet::filelocation('',$output);
5311: &Apache::lonnet::repcopy($local_name);
5312: }
1.520 raeburn 5313: $output = &lonhttpdurl($output);
5314: }
1.63 www 5315: }
1.520 raeburn 5316: return $output;
1.63 www 5317: }
1.59 www 5318:
1.822 bisitz 5319: ##############################################
5320: =pod
5321:
1.832 bisitz 5322: =item * &authorspace()
5323:
1.1028 raeburn 5324: Inputs: $url (usually will be undef).
1.832 bisitz 5325:
1.1132 raeburn 5326: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5327: directory being viewed (or for which action is being taken).
5328: If $url is provided, and begins /priv/<domain>/<uname>
5329: the path will be that portion of the $context argument.
5330: Otherwise the path will be for the author space of the current
5331: user when the current role is author, or for that of the
5332: co-author/assistant co-author space when the current role
5333: is co-author or assistant co-author.
1.832 bisitz 5334:
5335: =cut
5336:
5337: sub authorspace {
1.1028 raeburn 5338: my ($url) = @_;
5339: if ($url ne '') {
5340: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5341: return $1;
5342: }
5343: }
1.832 bisitz 5344: my $caname = '';
1.1024 www 5345: my $cadom = '';
1.1028 raeburn 5346: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5347: ($cadom,$caname) =
1.832 bisitz 5348: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5349: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5350: $caname = $env{'user.name'};
1.1024 www 5351: $cadom = $env{'user.domain'};
1.832 bisitz 5352: }
1.1028 raeburn 5353: if (($caname ne '') && ($cadom ne '')) {
5354: return "/priv/$cadom/$caname/";
5355: }
5356: return;
1.832 bisitz 5357: }
5358:
5359: ##############################################
5360: =pod
5361:
1.822 bisitz 5362: =item * &head_subbox()
5363:
5364: Inputs: $content (contains HTML code with page functions, etc.)
5365:
5366: Returns: HTML div with $content
5367: To be included in page header
5368:
5369: =cut
5370:
5371: sub head_subbox {
5372: my ($content)=@_;
5373: my $output =
1.993 raeburn 5374: '<div class="LC_head_subbox">'
1.822 bisitz 5375: .$content
5376: .'</div>'
5377: }
5378:
5379: ##############################################
5380: =pod
5381:
5382: =item * &CSTR_pageheader()
5383:
1.1026 raeburn 5384: Input: (optional) filename from which breadcrumb trail is built.
5385: In most cases no input as needed, as $env{'request.filename'}
5386: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5387:
5388: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5389: To be included on Authoring Space pages
1.822 bisitz 5390:
5391: =cut
5392:
5393: sub CSTR_pageheader {
1.1026 raeburn 5394: my ($trailfile) = @_;
5395: if ($trailfile eq '') {
5396: $trailfile = $env{'request.filename'};
5397: }
5398:
5399: # this is for resources; directories have customtitle, and crumbs
5400: # and select recent are created in lonpubdir.pm
5401:
5402: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5403: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5404: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5405: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5406: $formaction =~ s{/+}{/}g;
1.822 bisitz 5407:
5408: my $parentpath = '';
5409: my $lastitem = '';
5410: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5411: $parentpath = $1;
5412: $lastitem = $2;
5413: } else {
5414: $lastitem = $thisdisfn;
5415: }
1.921 bisitz 5416:
5417: my $output =
1.822 bisitz 5418: '<div>'
5419: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1132 raeburn 5420: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5421: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5422: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5423: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5424:
5425: if ($lastitem) {
5426: $output .=
5427: '<span class="LC_filename">'
5428: .$lastitem
5429: .'</span>';
5430: }
5431: $output .=
5432: '<br />'
1.822 bisitz 5433: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5434: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5435: .'</form>'
5436: .&Apache::lonmenu::constspaceform()
5437: .'</div>';
1.921 bisitz 5438:
5439: return $output;
1.822 bisitz 5440: }
5441:
1.60 matthew 5442: ###############################################
5443: ###############################################
5444:
5445: =pod
5446:
1.112 bowersj2 5447: =back
5448:
1.549 albertel 5449: =head1 HTML Helpers
1.112 bowersj2 5450:
5451: =over 4
5452:
5453: =item * &bodytag()
1.60 matthew 5454:
5455: Returns a uniform header for LON-CAPA web pages.
5456:
5457: Inputs:
5458:
1.112 bowersj2 5459: =over 4
5460:
5461: =item * $title, A title to be displayed on the page.
5462:
5463: =item * $function, the current role (can be undef).
5464:
5465: =item * $addentries, extra parameters for the <body> tag.
5466:
5467: =item * $bodyonly, if defined, only return the <body> tag.
5468:
5469: =item * $domain, if defined, force a given domain.
5470:
5471: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5472: text interface only)
1.60 matthew 5473:
1.814 bisitz 5474: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5475: navigational links
1.317 albertel 5476:
1.338 albertel 5477: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5478:
1.460 albertel 5479: =item * $args, optional argument valid values are
5480: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5481: inherit_jsmath -> when creating popup window in a page,
5482: should it have jsmath forced on by the
5483: current page
1.460 albertel 5484:
1.1096 raeburn 5485: =item * $advtoolsref, optional argument, ref to an array containing
5486: inlineremote items to be added in "Functions" menu below
5487: breadcrumbs.
5488:
1.112 bowersj2 5489: =back
5490:
1.60 matthew 5491: Returns: A uniform header for LON-CAPA web pages.
5492: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5493: If $bodyonly is undef or zero, an html string containing a <body> tag and
5494: other decorations will be returned.
5495:
5496: =cut
5497:
1.54 www 5498: sub bodytag {
1.831 bisitz 5499: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5500: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5501:
1.954 raeburn 5502: my $public;
5503: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5504: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5505: $public = 1;
5506: }
1.460 albertel 5507: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5508: my $httphost = $args->{'use_absolute'};
1.339 albertel 5509:
1.183 matthew 5510: $function = &get_users_function() if (!$function);
1.339 albertel 5511: my $img = &designparm($function.'.img',$domain);
5512: my $font = &designparm($function.'.font',$domain);
5513: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5514:
1.803 bisitz 5515: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5516: 'bgcolor' => $pgbg,
1.339 albertel 5517: 'text' => $font,
5518: 'alink' => &designparm($function.'.alink',$domain),
5519: 'vlink' => &designparm($function.'.vlink',$domain),
5520: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5521: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5522:
1.63 www 5523: # role and realm
1.1178 raeburn 5524: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5525: if ($realm) {
5526: $realm = '/'.$realm;
5527: }
1.378 raeburn 5528: if ($role eq 'ca') {
1.479 albertel 5529: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5530: $realm = &plainname($rname,$rdom);
1.378 raeburn 5531: }
1.55 www 5532: # realm
1.258 albertel 5533: if ($env{'request.course.id'}) {
1.378 raeburn 5534: if ($env{'request.role'} !~ /^cr/) {
5535: $role = &Apache::lonnet::plaintext($role,&course_type());
5536: }
1.898 raeburn 5537: if ($env{'request.course.sec'}) {
5538: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5539: }
1.359 albertel 5540: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5541: } else {
5542: $role = &Apache::lonnet::plaintext($role);
1.54 www 5543: }
1.433 albertel 5544:
1.359 albertel 5545: if (!$realm) { $realm=' '; }
1.330 albertel 5546:
1.438 albertel 5547: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5548:
1.101 www 5549: # construct main body tag
1.359 albertel 5550: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5551: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5552:
1.1131 raeburn 5553: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5554:
1.1130 raeburn 5555: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5556: return $bodytag;
1.1130 raeburn 5557: }
1.359 albertel 5558:
1.954 raeburn 5559: if ($public) {
1.433 albertel 5560: undef($role);
5561: }
1.359 albertel 5562:
1.762 bisitz 5563: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5564: #
5565: # Extra info if you are the DC
5566: my $dc_info = '';
5567: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5568: $env{'course.'.$env{'request.course.id'}.
5569: '.domain'}.'/'})) {
5570: my $cid = $env{'request.course.id'};
1.917 raeburn 5571: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5572: $dc_info =~ s/\s+$//;
1.359 albertel 5573: }
5574:
1.898 raeburn 5575: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5576:
1.903 droeschl 5577: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5578:
5579: # if ($env{'request.state'} eq 'construct') {
5580: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5581: # }
5582:
1.1130 raeburn 5583: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 5584: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5585:
1.1130 raeburn 5586: my ($left,$right) = Apache::lonmenu::primary_menu();
1.359 albertel 5587:
1.916 droeschl 5588: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5589: if ($dc_info) {
5590: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5591: }
1.1130 raeburn 5592: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5593: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5594: return $bodytag;
5595: }
1.894 droeschl 5596:
1.927 raeburn 5597: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5598: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5599: }
1.916 droeschl 5600:
1.1130 raeburn 5601: $bodytag .= $right;
1.852 droeschl 5602:
1.917 raeburn 5603: if ($dc_info) {
5604: $dc_info = &dc_courseid_toggle($dc_info);
5605: }
5606: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5607:
1.1169 raeburn 5608: #if directed to not display the secondary menu, don't.
1.1168 raeburn 5609: if ($args->{'no_secondary_menu'}) {
5610: return $bodytag;
5611: }
1.1169 raeburn 5612: #don't show menus for public users
1.954 raeburn 5613: if (!$public){
1.1154 raeburn 5614: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5615: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5616: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5617: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5618: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5619: $args->{'bread_crumbs'});
1.1096 raeburn 5620: } elsif ($forcereg) {
5621: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5622: $args->{'group'});
5623: } else {
5624: $bodytag .=
5625: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5626: $forcereg,$args->{'group'},
5627: $args->{'bread_crumbs'},
5628: $advtoolsref);
1.920 raeburn 5629: }
1.903 droeschl 5630: }else{
5631: # this is to seperate menu from content when there's no secondary
5632: # menu. Especially needed for public accessible ressources.
5633: $bodytag .= '<hr style="clear:both" />';
5634: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5635: }
1.903 droeschl 5636:
1.235 raeburn 5637: return $bodytag;
1.182 matthew 5638: }
5639:
1.917 raeburn 5640: sub dc_courseid_toggle {
5641: my ($dc_info) = @_;
1.980 raeburn 5642: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5643: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5644: &mt('(More ...)').'</a></span>'.
5645: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5646: }
5647:
1.330 albertel 5648: sub make_attr_string {
5649: my ($register,$attr_ref) = @_;
5650:
5651: if ($attr_ref && !ref($attr_ref)) {
5652: die("addentries Must be a hash ref ".
5653: join(':',caller(1))." ".
5654: join(':',caller(0))." ");
5655: }
5656:
5657: if ($register) {
1.339 albertel 5658: my ($on_load,$on_unload);
5659: foreach my $key (keys(%{$attr_ref})) {
5660: if (lc($key) eq 'onload') {
5661: $on_load.=$attr_ref->{$key}.';';
5662: delete($attr_ref->{$key});
5663:
5664: } elsif (lc($key) eq 'onunload') {
5665: $on_unload.=$attr_ref->{$key}.';';
5666: delete($attr_ref->{$key});
5667: }
5668: }
1.953 droeschl 5669: $attr_ref->{'onload'} = $on_load;
5670: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5671: }
1.339 albertel 5672:
1.330 albertel 5673: my $attr_string;
1.1159 raeburn 5674: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5675: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5676: }
5677: return $attr_string;
5678: }
5679:
5680:
1.182 matthew 5681: ###############################################
1.251 albertel 5682: ###############################################
5683:
5684: =pod
5685:
5686: =item * &endbodytag()
5687:
5688: Returns a uniform footer for LON-CAPA web pages.
5689:
1.635 raeburn 5690: Inputs: 1 - optional reference to an args hash
5691: If in the hash, key for noredirectlink has a value which evaluates to true,
5692: a 'Continue' link is not displayed if the page contains an
5693: internal redirect in the <head></head> section,
5694: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5695:
5696: =cut
5697:
5698: sub endbodytag {
1.635 raeburn 5699: my ($args) = @_;
1.1080 raeburn 5700: my $endbodytag;
5701: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5702: $endbodytag='</body>';
5703: }
1.269 albertel 5704: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5705: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5706: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5707: $endbodytag=
5708: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5709: &mt('Continue').'</a>'.
5710: $endbodytag;
5711: }
1.315 albertel 5712: }
1.251 albertel 5713: return $endbodytag;
5714: }
5715:
1.352 albertel 5716: =pod
5717:
5718: =item * &standard_css()
5719:
5720: Returns a style sheet
5721:
5722: Inputs: (all optional)
5723: domain -> force to color decorate a page for a specific
5724: domain
5725: function -> force usage of a specific rolish color scheme
5726: bgcolor -> override the default page bgcolor
5727:
5728: =cut
5729:
1.343 albertel 5730: sub standard_css {
1.345 albertel 5731: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5732: $function = &get_users_function() if (!$function);
5733: my $img = &designparm($function.'.img', $domain);
5734: my $tabbg = &designparm($function.'.tabbg', $domain);
5735: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5736: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5737: #second colour for later usage
1.345 albertel 5738: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5739: my $pgbg_or_bgcolor =
5740: $bgcolor ||
1.352 albertel 5741: &designparm($function.'.pgbg', $domain);
1.382 albertel 5742: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5743: my $alink = &designparm($function.'.alink', $domain);
5744: my $vlink = &designparm($function.'.vlink', $domain);
5745: my $link = &designparm($function.'.link', $domain);
5746:
1.602 albertel 5747: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5748: my $mono = 'monospace';
1.850 bisitz 5749: my $data_table_head = $sidebg;
5750: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5751: my $data_table_dark = '#E0E0E0';
1.470 banghart 5752: my $data_table_darker = '#CCCCCC';
1.349 albertel 5753: my $data_table_highlight = '#FFFF00';
1.352 albertel 5754: my $mail_new = '#FFBB77';
5755: my $mail_new_hover = '#DD9955';
5756: my $mail_read = '#BBBB77';
5757: my $mail_read_hover = '#999944';
5758: my $mail_replied = '#AAAA88';
5759: my $mail_replied_hover = '#888855';
5760: my $mail_other = '#99BBBB';
5761: my $mail_other_hover = '#669999';
1.391 albertel 5762: my $table_header = '#DDDDDD';
1.489 raeburn 5763: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5764: my $lg_border_color = '#C8C8C8';
1.952 onken 5765: my $button_hover = '#BF2317';
1.392 albertel 5766:
1.608 albertel 5767: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5768: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5769: : '0 3px 0 4px';
1.448 albertel 5770:
1.523 albertel 5771:
1.343 albertel 5772: return <<END;
1.947 droeschl 5773:
5774: /* needed for iframe to allow 100% height in FF */
5775: body, html {
5776: margin: 0;
5777: padding: 0 0.5%;
5778: height: 99%; /* to avoid scrollbars */
5779: }
5780:
1.795 www 5781: body {
1.911 bisitz 5782: font-family: $sans;
5783: line-height:130%;
5784: font-size:0.83em;
5785: color:$font;
1.795 www 5786: }
5787:
1.959 onken 5788: a:focus,
5789: a:focus img {
1.795 www 5790: color: red;
5791: }
1.698 harmsja 5792:
1.911 bisitz 5793: form, .inline {
5794: display: inline;
1.795 www 5795: }
1.721 harmsja 5796:
1.795 www 5797: .LC_right {
1.911 bisitz 5798: text-align:right;
1.795 www 5799: }
5800:
5801: .LC_middle {
1.911 bisitz 5802: vertical-align:middle;
1.795 www 5803: }
1.721 harmsja 5804:
1.1130 raeburn 5805: .LC_floatleft {
5806: float: left;
5807: }
5808:
5809: .LC_floatright {
5810: float: right;
5811: }
5812:
1.911 bisitz 5813: .LC_400Box {
5814: width:400px;
5815: }
1.721 harmsja 5816:
1.947 droeschl 5817: .LC_iframecontainer {
5818: width: 98%;
5819: margin: 0;
5820: position: fixed;
5821: top: 8.5em;
5822: bottom: 0;
5823: }
5824:
5825: .LC_iframecontainer iframe{
5826: border: none;
5827: width: 100%;
5828: height: 100%;
5829: }
5830:
1.778 bisitz 5831: .LC_filename {
5832: font-family: $mono;
5833: white-space:pre;
1.921 bisitz 5834: font-size: 120%;
1.778 bisitz 5835: }
5836:
5837: .LC_fileicon {
5838: border: none;
5839: height: 1.3em;
5840: vertical-align: text-bottom;
5841: margin-right: 0.3em;
5842: text-decoration:none;
5843: }
5844:
1.1008 www 5845: .LC_setting {
5846: text-decoration:underline;
5847: }
5848:
1.350 albertel 5849: .LC_error {
5850: color: red;
5851: }
1.795 www 5852:
1.1097 bisitz 5853: .LC_warning {
5854: color: darkorange;
5855: }
5856:
1.457 albertel 5857: .LC_diff_removed {
1.733 bisitz 5858: color: red;
1.394 albertel 5859: }
1.532 albertel 5860:
5861: .LC_info,
1.457 albertel 5862: .LC_success,
5863: .LC_diff_added {
1.350 albertel 5864: color: green;
5865: }
1.795 www 5866:
1.802 bisitz 5867: div.LC_confirm_box {
5868: background-color: #FAFAFA;
5869: border: 1px solid $lg_border_color;
5870: margin-right: 0;
5871: padding: 5px;
5872: }
5873:
5874: div.LC_confirm_box .LC_error img,
5875: div.LC_confirm_box .LC_success img {
5876: vertical-align: middle;
5877: }
5878:
1.440 albertel 5879: .LC_icon {
1.771 droeschl 5880: border: none;
1.790 droeschl 5881: vertical-align: middle;
1.771 droeschl 5882: }
5883:
1.543 albertel 5884: .LC_docs_spacer {
5885: width: 25px;
5886: height: 1px;
1.771 droeschl 5887: border: none;
1.543 albertel 5888: }
1.346 albertel 5889:
1.532 albertel 5890: .LC_internal_info {
1.735 bisitz 5891: color: #999999;
1.532 albertel 5892: }
5893:
1.794 www 5894: .LC_discussion {
1.1050 www 5895: background: $data_table_dark;
1.911 bisitz 5896: border: 1px solid black;
5897: margin: 2px;
1.794 www 5898: }
5899:
5900: .LC_disc_action_left {
1.1050 www 5901: background: $sidebg;
1.911 bisitz 5902: text-align: left;
1.1050 www 5903: padding: 4px;
5904: margin: 2px;
1.794 www 5905: }
5906:
5907: .LC_disc_action_right {
1.1050 www 5908: background: $sidebg;
1.911 bisitz 5909: text-align: right;
1.1050 www 5910: padding: 4px;
5911: margin: 2px;
1.794 www 5912: }
5913:
5914: .LC_disc_new_item {
1.911 bisitz 5915: background: white;
5916: border: 2px solid red;
1.1050 www 5917: margin: 4px;
5918: padding: 4px;
1.794 www 5919: }
5920:
5921: .LC_disc_old_item {
1.911 bisitz 5922: background: white;
1.1050 www 5923: margin: 4px;
5924: padding: 4px;
1.794 www 5925: }
5926:
1.458 albertel 5927: table.LC_pastsubmission {
5928: border: 1px solid black;
5929: margin: 2px;
5930: }
5931:
1.924 bisitz 5932: table#LC_menubuttons {
1.345 albertel 5933: width: 100%;
5934: background: $pgbg;
1.392 albertel 5935: border: 2px;
1.402 albertel 5936: border-collapse: separate;
1.803 bisitz 5937: padding: 0;
1.345 albertel 5938: }
1.392 albertel 5939:
1.801 tempelho 5940: table#LC_title_bar a {
5941: color: $fontmenu;
5942: }
1.836 bisitz 5943:
1.807 droeschl 5944: table#LC_title_bar {
1.819 tempelho 5945: clear: both;
1.836 bisitz 5946: display: none;
1.807 droeschl 5947: }
5948:
1.795 www 5949: table#LC_title_bar,
1.933 droeschl 5950: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5951: table#LC_title_bar.LC_with_remote {
1.359 albertel 5952: width: 100%;
1.392 albertel 5953: border-color: $pgbg;
5954: border-style: solid;
5955: border-width: $border;
1.379 albertel 5956: background: $pgbg;
1.801 tempelho 5957: color: $fontmenu;
1.392 albertel 5958: border-collapse: collapse;
1.803 bisitz 5959: padding: 0;
1.819 tempelho 5960: margin: 0;
1.359 albertel 5961: }
1.795 www 5962:
1.933 droeschl 5963: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5964: margin: 0;
5965: padding: 0;
1.933 droeschl 5966: position: relative;
5967: list-style: none;
1.913 droeschl 5968: }
1.933 droeschl 5969: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5970: display: inline;
5971: }
1.933 droeschl 5972:
5973: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5974: padding: 0;
1.933 droeschl 5975: margin: 0;
5976: float: left;
1.913 droeschl 5977: }
1.933 droeschl 5978: .LC_breadcrumb_tools_tools {
5979: padding: 0;
5980: margin: 0;
1.913 droeschl 5981: float: right;
5982: }
5983:
1.359 albertel 5984: table#LC_title_bar td {
5985: background: $tabbg;
5986: }
1.795 www 5987:
1.911 bisitz 5988: table#LC_menubuttons img {
1.803 bisitz 5989: border: none;
1.346 albertel 5990: }
1.795 www 5991:
1.842 droeschl 5992: .LC_breadcrumbs_component {
1.911 bisitz 5993: float: right;
5994: margin: 0 1em;
1.357 albertel 5995: }
1.842 droeschl 5996: .LC_breadcrumbs_component img {
1.911 bisitz 5997: vertical-align: middle;
1.777 tempelho 5998: }
1.795 www 5999:
1.383 albertel 6000: td.LC_table_cell_checkbox {
6001: text-align: center;
6002: }
1.795 www 6003:
6004: .LC_fontsize_small {
1.911 bisitz 6005: font-size: 70%;
1.705 tempelho 6006: }
6007:
1.844 bisitz 6008: #LC_breadcrumbs {
1.911 bisitz 6009: clear:both;
6010: background: $sidebg;
6011: border-bottom: 1px solid $lg_border_color;
6012: line-height: 2.5em;
1.933 droeschl 6013: overflow: hidden;
1.911 bisitz 6014: margin: 0;
6015: padding: 0;
1.995 raeburn 6016: text-align: left;
1.819 tempelho 6017: }
1.862 bisitz 6018:
1.1098 bisitz 6019: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6020: clear:both;
6021: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6022: border: 1px solid $sidebg;
1.1098 bisitz 6023: margin: 0 0 10px 0;
1.966 bisitz 6024: padding: 3px;
1.995 raeburn 6025: text-align: left;
1.822 bisitz 6026: }
6027:
1.795 www 6028: .LC_fontsize_medium {
1.911 bisitz 6029: font-size: 85%;
1.705 tempelho 6030: }
6031:
1.795 www 6032: .LC_fontsize_large {
1.911 bisitz 6033: font-size: 120%;
1.705 tempelho 6034: }
6035:
1.346 albertel 6036: .LC_menubuttons_inline_text {
6037: color: $font;
1.698 harmsja 6038: font-size: 90%;
1.701 harmsja 6039: padding-left:3px;
1.346 albertel 6040: }
6041:
1.934 droeschl 6042: .LC_menubuttons_inline_text img{
6043: vertical-align: middle;
6044: }
6045:
1.1051 www 6046: li.LC_menubuttons_inline_text img {
1.951 onken 6047: cursor:pointer;
1.1002 droeschl 6048: text-decoration: none;
1.951 onken 6049: }
6050:
1.526 www 6051: .LC_menubuttons_link {
6052: text-decoration: none;
6053: }
1.795 www 6054:
1.522 albertel 6055: .LC_menubuttons_category {
1.521 www 6056: color: $font;
1.526 www 6057: background: $pgbg;
1.521 www 6058: font-size: larger;
6059: font-weight: bold;
6060: }
6061:
1.346 albertel 6062: td.LC_menubuttons_text {
1.911 bisitz 6063: color: $font;
1.346 albertel 6064: }
1.706 harmsja 6065:
1.346 albertel 6066: .LC_current_location {
6067: background: $tabbg;
6068: }
1.795 www 6069:
1.938 bisitz 6070: table.LC_data_table {
1.347 albertel 6071: border: 1px solid #000000;
1.402 albertel 6072: border-collapse: separate;
1.426 albertel 6073: border-spacing: 1px;
1.610 albertel 6074: background: $pgbg;
1.347 albertel 6075: }
1.795 www 6076:
1.422 albertel 6077: .LC_data_table_dense {
6078: font-size: small;
6079: }
1.795 www 6080:
1.507 raeburn 6081: table.LC_nested_outer {
6082: border: 1px solid #000000;
1.589 raeburn 6083: border-collapse: collapse;
1.803 bisitz 6084: border-spacing: 0;
1.507 raeburn 6085: width: 100%;
6086: }
1.795 www 6087:
1.879 raeburn 6088: table.LC_innerpickbox,
1.507 raeburn 6089: table.LC_nested {
1.803 bisitz 6090: border: none;
1.589 raeburn 6091: border-collapse: collapse;
1.803 bisitz 6092: border-spacing: 0;
1.507 raeburn 6093: width: 100%;
6094: }
1.795 www 6095:
1.911 bisitz 6096: table.LC_data_table tr th,
6097: table.LC_calendar tr th,
1.879 raeburn 6098: table.LC_prior_tries tr th,
6099: table.LC_innerpickbox tr th {
1.349 albertel 6100: font-weight: bold;
6101: background-color: $data_table_head;
1.801 tempelho 6102: color:$fontmenu;
1.701 harmsja 6103: font-size:90%;
1.347 albertel 6104: }
1.795 www 6105:
1.879 raeburn 6106: table.LC_innerpickbox tr th,
6107: table.LC_innerpickbox tr td {
6108: vertical-align: top;
6109: }
6110:
1.711 raeburn 6111: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6112: background-color: #CCCCCC;
1.711 raeburn 6113: font-weight: bold;
6114: text-align: left;
6115: }
1.795 www 6116:
1.912 bisitz 6117: table.LC_data_table tr.LC_odd_row > td {
6118: background-color: $data_table_light;
6119: padding: 2px;
6120: vertical-align: top;
6121: }
6122:
1.809 bisitz 6123: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6124: background-color: $data_table_light;
1.912 bisitz 6125: vertical-align: top;
6126: }
6127:
6128: table.LC_data_table tr.LC_even_row > td {
6129: background-color: $data_table_dark;
1.425 albertel 6130: padding: 2px;
1.900 bisitz 6131: vertical-align: top;
1.347 albertel 6132: }
1.795 www 6133:
1.809 bisitz 6134: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6135: background-color: $data_table_dark;
1.900 bisitz 6136: vertical-align: top;
1.347 albertel 6137: }
1.795 www 6138:
1.425 albertel 6139: table.LC_data_table tr.LC_data_table_highlight td {
6140: background-color: $data_table_darker;
6141: }
1.795 www 6142:
1.639 raeburn 6143: table.LC_data_table tr td.LC_leftcol_header {
6144: background-color: $data_table_head;
6145: font-weight: bold;
6146: }
1.795 www 6147:
1.451 albertel 6148: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6149: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6150: font-weight: bold;
6151: font-style: italic;
6152: text-align: center;
6153: padding: 8px;
1.347 albertel 6154: }
1.795 www 6155:
1.1114 raeburn 6156: table.LC_data_table tr.LC_empty_row td,
6157: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6158: background-color: $sidebg;
6159: }
6160:
6161: table.LC_nested tr.LC_empty_row td {
6162: background-color: #FFFFFF;
6163: }
6164:
1.890 droeschl 6165: table.LC_caption {
6166: }
6167:
1.507 raeburn 6168: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6169: padding: 4ex
6170: }
1.795 www 6171:
1.507 raeburn 6172: table.LC_nested_outer tr th {
6173: font-weight: bold;
1.801 tempelho 6174: color:$fontmenu;
1.507 raeburn 6175: background-color: $data_table_head;
1.701 harmsja 6176: font-size: small;
1.507 raeburn 6177: border-bottom: 1px solid #000000;
6178: }
1.795 www 6179:
1.507 raeburn 6180: table.LC_nested_outer tr td.LC_subheader {
6181: background-color: $data_table_head;
6182: font-weight: bold;
6183: font-size: small;
6184: border-bottom: 1px solid #000000;
6185: text-align: right;
1.451 albertel 6186: }
1.795 www 6187:
1.507 raeburn 6188: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6189: background-color: #CCCCCC;
1.451 albertel 6190: font-weight: bold;
6191: font-size: small;
1.507 raeburn 6192: text-align: center;
6193: }
1.795 www 6194:
1.589 raeburn 6195: table.LC_nested tr.LC_info_row td.LC_left_item,
6196: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6197: text-align: left;
1.451 albertel 6198: }
1.795 www 6199:
1.507 raeburn 6200: table.LC_nested td {
1.735 bisitz 6201: background-color: #FFFFFF;
1.451 albertel 6202: font-size: small;
1.507 raeburn 6203: }
1.795 www 6204:
1.507 raeburn 6205: table.LC_nested_outer tr th.LC_right_item,
6206: table.LC_nested tr.LC_info_row td.LC_right_item,
6207: table.LC_nested tr.LC_odd_row td.LC_right_item,
6208: table.LC_nested tr td.LC_right_item {
1.451 albertel 6209: text-align: right;
6210: }
6211:
1.507 raeburn 6212: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6213: background-color: #EEEEEE;
1.451 albertel 6214: }
6215:
1.473 raeburn 6216: table.LC_createuser {
6217: }
6218:
6219: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6220: font-size: small;
1.473 raeburn 6221: }
6222:
6223: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6224: background-color: #CCCCCC;
1.473 raeburn 6225: font-weight: bold;
6226: text-align: center;
6227: }
6228:
1.349 albertel 6229: table.LC_calendar {
6230: border: 1px solid #000000;
6231: border-collapse: collapse;
1.917 raeburn 6232: width: 98%;
1.349 albertel 6233: }
1.795 www 6234:
1.349 albertel 6235: table.LC_calendar_pickdate {
6236: font-size: xx-small;
6237: }
1.795 www 6238:
1.349 albertel 6239: table.LC_calendar tr td {
6240: border: 1px solid #000000;
6241: vertical-align: top;
1.917 raeburn 6242: width: 14%;
1.349 albertel 6243: }
1.795 www 6244:
1.349 albertel 6245: table.LC_calendar tr td.LC_calendar_day_empty {
6246: background-color: $data_table_dark;
6247: }
1.795 www 6248:
1.779 bisitz 6249: table.LC_calendar tr td.LC_calendar_day_current {
6250: background-color: $data_table_highlight;
1.777 tempelho 6251: }
1.795 www 6252:
1.938 bisitz 6253: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6254: background-color: $mail_new;
6255: }
1.795 www 6256:
1.938 bisitz 6257: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6258: background-color: $mail_new_hover;
6259: }
1.795 www 6260:
1.938 bisitz 6261: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6262: background-color: $mail_read;
6263: }
1.795 www 6264:
1.938 bisitz 6265: /*
6266: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6267: background-color: $mail_read_hover;
6268: }
1.938 bisitz 6269: */
1.795 www 6270:
1.938 bisitz 6271: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6272: background-color: $mail_replied;
6273: }
1.795 www 6274:
1.938 bisitz 6275: /*
6276: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6277: background-color: $mail_replied_hover;
6278: }
1.938 bisitz 6279: */
1.795 www 6280:
1.938 bisitz 6281: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6282: background-color: $mail_other;
6283: }
1.795 www 6284:
1.938 bisitz 6285: /*
6286: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6287: background-color: $mail_other_hover;
6288: }
1.938 bisitz 6289: */
1.494 raeburn 6290:
1.777 tempelho 6291: table.LC_data_table tr > td.LC_browser_file,
6292: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6293: background: #AAEE77;
1.389 albertel 6294: }
1.795 www 6295:
1.777 tempelho 6296: table.LC_data_table tr > td.LC_browser_file_locked,
6297: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6298: background: #FFAA99;
1.387 albertel 6299: }
1.795 www 6300:
1.777 tempelho 6301: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6302: background: #888888;
1.779 bisitz 6303: }
1.795 www 6304:
1.777 tempelho 6305: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6306: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6307: background: #F8F866;
1.777 tempelho 6308: }
1.795 www 6309:
1.696 bisitz 6310: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6311: background: #E0E8FF;
1.387 albertel 6312: }
1.696 bisitz 6313:
1.707 bisitz 6314: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6315: /* background: #77FF77; */
1.707 bisitz 6316: }
1.795 www 6317:
1.707 bisitz 6318: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6319: border-right: 8px solid #FFFF77;
1.707 bisitz 6320: }
1.795 www 6321:
1.707 bisitz 6322: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6323: border-right: 8px solid #FFAA77;
1.707 bisitz 6324: }
1.795 www 6325:
1.707 bisitz 6326: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6327: border-right: 8px solid #FF7777;
1.707 bisitz 6328: }
1.795 www 6329:
1.707 bisitz 6330: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6331: border-right: 8px solid #AAFF77;
1.707 bisitz 6332: }
1.795 www 6333:
1.707 bisitz 6334: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6335: border-right: 8px solid #11CC55;
1.707 bisitz 6336: }
6337:
1.388 albertel 6338: span.LC_current_location {
1.701 harmsja 6339: font-size:larger;
1.388 albertel 6340: background: $pgbg;
6341: }
1.387 albertel 6342:
1.1029 www 6343: span.LC_current_nav_location {
6344: font-weight:bold;
6345: background: $sidebg;
6346: }
6347:
1.395 albertel 6348: span.LC_parm_menu_item {
6349: font-size: larger;
6350: }
1.795 www 6351:
1.395 albertel 6352: span.LC_parm_scope_all {
6353: color: red;
6354: }
1.795 www 6355:
1.395 albertel 6356: span.LC_parm_scope_folder {
6357: color: green;
6358: }
1.795 www 6359:
1.395 albertel 6360: span.LC_parm_scope_resource {
6361: color: orange;
6362: }
1.795 www 6363:
1.395 albertel 6364: span.LC_parm_part {
6365: color: blue;
6366: }
1.795 www 6367:
1.911 bisitz 6368: span.LC_parm_folder,
6369: span.LC_parm_symb {
1.395 albertel 6370: font-size: x-small;
6371: font-family: $mono;
6372: color: #AAAAAA;
6373: }
6374:
1.977 bisitz 6375: ul.LC_parm_parmlist li {
6376: display: inline-block;
6377: padding: 0.3em 0.8em;
6378: vertical-align: top;
6379: width: 150px;
6380: border-top:1px solid $lg_border_color;
6381: }
6382:
1.795 www 6383: td.LC_parm_overview_level_menu,
6384: td.LC_parm_overview_map_menu,
6385: td.LC_parm_overview_parm_selectors,
6386: td.LC_parm_overview_restrictions {
1.396 albertel 6387: border: 1px solid black;
6388: border-collapse: collapse;
6389: }
1.795 www 6390:
1.396 albertel 6391: table.LC_parm_overview_restrictions td {
6392: border-width: 1px 4px 1px 4px;
6393: border-style: solid;
6394: border-color: $pgbg;
6395: text-align: center;
6396: }
1.795 www 6397:
1.396 albertel 6398: table.LC_parm_overview_restrictions th {
6399: background: $tabbg;
6400: border-width: 1px 4px 1px 4px;
6401: border-style: solid;
6402: border-color: $pgbg;
6403: }
1.795 www 6404:
1.398 albertel 6405: table#LC_helpmenu {
1.803 bisitz 6406: border: none;
1.398 albertel 6407: height: 55px;
1.803 bisitz 6408: border-spacing: 0;
1.398 albertel 6409: }
6410:
6411: table#LC_helpmenu fieldset legend {
6412: font-size: larger;
6413: }
1.795 www 6414:
1.397 albertel 6415: table#LC_helpmenu_links {
6416: width: 100%;
6417: border: 1px solid black;
6418: background: $pgbg;
1.803 bisitz 6419: padding: 0;
1.397 albertel 6420: border-spacing: 1px;
6421: }
1.795 www 6422:
1.397 albertel 6423: table#LC_helpmenu_links tr td {
6424: padding: 1px;
6425: background: $tabbg;
1.399 albertel 6426: text-align: center;
6427: font-weight: bold;
1.397 albertel 6428: }
1.396 albertel 6429:
1.795 www 6430: table#LC_helpmenu_links a:link,
6431: table#LC_helpmenu_links a:visited,
1.397 albertel 6432: table#LC_helpmenu_links a:active {
6433: text-decoration: none;
6434: color: $font;
6435: }
1.795 www 6436:
1.397 albertel 6437: table#LC_helpmenu_links a:hover {
6438: text-decoration: underline;
6439: color: $vlink;
6440: }
1.396 albertel 6441:
1.417 albertel 6442: .LC_chrt_popup_exists {
6443: border: 1px solid #339933;
6444: margin: -1px;
6445: }
1.795 www 6446:
1.417 albertel 6447: .LC_chrt_popup_up {
6448: border: 1px solid yellow;
6449: margin: -1px;
6450: }
1.795 www 6451:
1.417 albertel 6452: .LC_chrt_popup {
6453: border: 1px solid #8888FF;
6454: background: #CCCCFF;
6455: }
1.795 www 6456:
1.421 albertel 6457: table.LC_pick_box {
6458: border-collapse: separate;
6459: background: white;
6460: border: 1px solid black;
6461: border-spacing: 1px;
6462: }
1.795 www 6463:
1.421 albertel 6464: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6465: background: $sidebg;
1.421 albertel 6466: font-weight: bold;
1.900 bisitz 6467: text-align: left;
1.740 bisitz 6468: vertical-align: top;
1.421 albertel 6469: width: 184px;
6470: padding: 8px;
6471: }
1.795 www 6472:
1.579 raeburn 6473: table.LC_pick_box td.LC_pick_box_value {
6474: text-align: left;
6475: padding: 8px;
6476: }
1.795 www 6477:
1.579 raeburn 6478: table.LC_pick_box td.LC_pick_box_select {
6479: text-align: left;
6480: padding: 8px;
6481: }
1.795 www 6482:
1.424 albertel 6483: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6484: padding: 0;
1.421 albertel 6485: height: 1px;
6486: background: black;
6487: }
1.795 www 6488:
1.421 albertel 6489: table.LC_pick_box td.LC_pick_box_submit {
6490: text-align: right;
6491: }
1.795 www 6492:
1.579 raeburn 6493: table.LC_pick_box td.LC_evenrow_value {
6494: text-align: left;
6495: padding: 8px;
6496: background-color: $data_table_light;
6497: }
1.795 www 6498:
1.579 raeburn 6499: table.LC_pick_box td.LC_oddrow_value {
6500: text-align: left;
6501: padding: 8px;
6502: background-color: $data_table_light;
6503: }
1.795 www 6504:
1.579 raeburn 6505: span.LC_helpform_receipt_cat {
6506: font-weight: bold;
6507: }
1.795 www 6508:
1.424 albertel 6509: table.LC_group_priv_box {
6510: background: white;
6511: border: 1px solid black;
6512: border-spacing: 1px;
6513: }
1.795 www 6514:
1.424 albertel 6515: table.LC_group_priv_box td.LC_pick_box_title {
6516: background: $tabbg;
6517: font-weight: bold;
6518: text-align: right;
6519: width: 184px;
6520: }
1.795 www 6521:
1.424 albertel 6522: table.LC_group_priv_box td.LC_groups_fixed {
6523: background: $data_table_light;
6524: text-align: center;
6525: }
1.795 www 6526:
1.424 albertel 6527: table.LC_group_priv_box td.LC_groups_optional {
6528: background: $data_table_dark;
6529: text-align: center;
6530: }
1.795 www 6531:
1.424 albertel 6532: table.LC_group_priv_box td.LC_groups_functionality {
6533: background: $data_table_darker;
6534: text-align: center;
6535: font-weight: bold;
6536: }
1.795 www 6537:
1.424 albertel 6538: table.LC_group_priv td {
6539: text-align: left;
1.803 bisitz 6540: padding: 0;
1.424 albertel 6541: }
6542:
6543: .LC_navbuttons {
6544: margin: 2ex 0ex 2ex 0ex;
6545: }
1.795 www 6546:
1.423 albertel 6547: .LC_topic_bar {
6548: font-weight: bold;
6549: background: $tabbg;
1.918 wenzelju 6550: margin: 1em 0em 1em 2em;
1.805 bisitz 6551: padding: 3px;
1.918 wenzelju 6552: font-size: 1.2em;
1.423 albertel 6553: }
1.795 www 6554:
1.423 albertel 6555: .LC_topic_bar span {
1.918 wenzelju 6556: left: 0.5em;
6557: position: absolute;
1.423 albertel 6558: vertical-align: middle;
1.918 wenzelju 6559: font-size: 1.2em;
1.423 albertel 6560: }
1.795 www 6561:
1.423 albertel 6562: table.LC_course_group_status {
6563: margin: 20px;
6564: }
1.795 www 6565:
1.423 albertel 6566: table.LC_status_selector td {
6567: vertical-align: top;
6568: text-align: center;
1.424 albertel 6569: padding: 4px;
6570: }
1.795 www 6571:
1.599 albertel 6572: div.LC_feedback_link {
1.616 albertel 6573: clear: both;
1.829 kalberla 6574: background: $sidebg;
1.779 bisitz 6575: width: 100%;
1.829 kalberla 6576: padding-bottom: 10px;
6577: border: 1px $tabbg solid;
1.833 kalberla 6578: height: 22px;
6579: line-height: 22px;
6580: padding-top: 5px;
6581: }
6582:
6583: div.LC_feedback_link img {
6584: height: 22px;
1.867 kalberla 6585: vertical-align:middle;
1.829 kalberla 6586: }
6587:
1.911 bisitz 6588: div.LC_feedback_link a {
1.829 kalberla 6589: text-decoration: none;
1.489 raeburn 6590: }
1.795 www 6591:
1.867 kalberla 6592: div.LC_comblock {
1.911 bisitz 6593: display:inline;
1.867 kalberla 6594: color:$font;
6595: font-size:90%;
6596: }
6597:
6598: div.LC_feedback_link div.LC_comblock {
6599: padding-left:5px;
6600: }
6601:
6602: div.LC_feedback_link div.LC_comblock a {
6603: color:$font;
6604: }
6605:
1.489 raeburn 6606: span.LC_feedback_link {
1.858 bisitz 6607: /* background: $feedback_link_bg; */
1.599 albertel 6608: font-size: larger;
6609: }
1.795 www 6610:
1.599 albertel 6611: span.LC_message_link {
1.858 bisitz 6612: /* background: $feedback_link_bg; */
1.599 albertel 6613: font-size: larger;
6614: position: absolute;
6615: right: 1em;
1.489 raeburn 6616: }
1.421 albertel 6617:
1.515 albertel 6618: table.LC_prior_tries {
1.524 albertel 6619: border: 1px solid #000000;
6620: border-collapse: separate;
6621: border-spacing: 1px;
1.515 albertel 6622: }
1.523 albertel 6623:
1.515 albertel 6624: table.LC_prior_tries td {
1.524 albertel 6625: padding: 2px;
1.515 albertel 6626: }
1.523 albertel 6627:
6628: .LC_answer_correct {
1.795 www 6629: background: lightgreen;
6630: color: darkgreen;
6631: padding: 6px;
1.523 albertel 6632: }
1.795 www 6633:
1.523 albertel 6634: .LC_answer_charged_try {
1.797 www 6635: background: #FFAAAA;
1.795 www 6636: color: darkred;
6637: padding: 6px;
1.523 albertel 6638: }
1.795 www 6639:
1.779 bisitz 6640: .LC_answer_not_charged_try,
1.523 albertel 6641: .LC_answer_no_grade,
6642: .LC_answer_late {
1.795 www 6643: background: lightyellow;
1.523 albertel 6644: color: black;
1.795 www 6645: padding: 6px;
1.523 albertel 6646: }
1.795 www 6647:
1.523 albertel 6648: .LC_answer_previous {
1.795 www 6649: background: lightblue;
6650: color: darkblue;
6651: padding: 6px;
1.523 albertel 6652: }
1.795 www 6653:
1.779 bisitz 6654: .LC_answer_no_message {
1.777 tempelho 6655: background: #FFFFFF;
6656: color: black;
1.795 www 6657: padding: 6px;
1.779 bisitz 6658: }
1.795 www 6659:
1.779 bisitz 6660: .LC_answer_unknown {
6661: background: orange;
6662: color: black;
1.795 www 6663: padding: 6px;
1.777 tempelho 6664: }
1.795 www 6665:
1.529 albertel 6666: span.LC_prior_numerical,
6667: span.LC_prior_string,
6668: span.LC_prior_custom,
6669: span.LC_prior_reaction,
6670: span.LC_prior_math {
1.925 bisitz 6671: font-family: $mono;
1.523 albertel 6672: white-space: pre;
6673: }
6674:
1.525 albertel 6675: span.LC_prior_string {
1.925 bisitz 6676: font-family: $mono;
1.525 albertel 6677: white-space: pre;
6678: }
6679:
1.523 albertel 6680: table.LC_prior_option {
6681: width: 100%;
6682: border-collapse: collapse;
6683: }
1.795 www 6684:
1.911 bisitz 6685: table.LC_prior_rank,
1.795 www 6686: table.LC_prior_match {
1.528 albertel 6687: border-collapse: collapse;
6688: }
1.795 www 6689:
1.528 albertel 6690: table.LC_prior_option tr td,
6691: table.LC_prior_rank tr td,
6692: table.LC_prior_match tr td {
1.524 albertel 6693: border: 1px solid #000000;
1.515 albertel 6694: }
6695:
1.855 bisitz 6696: .LC_nobreak {
1.544 albertel 6697: white-space: nowrap;
1.519 raeburn 6698: }
6699:
1.576 raeburn 6700: span.LC_cusr_emph {
6701: font-style: italic;
6702: }
6703:
1.633 raeburn 6704: span.LC_cusr_subheading {
6705: font-weight: normal;
6706: font-size: 85%;
6707: }
6708:
1.861 bisitz 6709: div.LC_docs_entry_move {
1.859 bisitz 6710: border: 1px solid #BBBBBB;
1.545 albertel 6711: background: #DDDDDD;
1.861 bisitz 6712: width: 22px;
1.859 bisitz 6713: padding: 1px;
6714: margin: 0;
1.545 albertel 6715: }
6716:
1.861 bisitz 6717: table.LC_data_table tr > td.LC_docs_entry_commands,
6718: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6719: font-size: x-small;
6720: }
1.795 www 6721:
1.861 bisitz 6722: .LC_docs_entry_parameter {
6723: white-space: nowrap;
6724: }
6725:
1.544 albertel 6726: .LC_docs_copy {
1.545 albertel 6727: color: #000099;
1.544 albertel 6728: }
1.795 www 6729:
1.544 albertel 6730: .LC_docs_cut {
1.545 albertel 6731: color: #550044;
1.544 albertel 6732: }
1.795 www 6733:
1.544 albertel 6734: .LC_docs_rename {
1.545 albertel 6735: color: #009900;
1.544 albertel 6736: }
1.795 www 6737:
1.544 albertel 6738: .LC_docs_remove {
1.545 albertel 6739: color: #990000;
6740: }
6741:
1.547 albertel 6742: .LC_docs_reinit_warn,
6743: .LC_docs_ext_edit {
6744: font-size: x-small;
6745: }
6746:
1.545 albertel 6747: table.LC_docs_adddocs td,
6748: table.LC_docs_adddocs th {
6749: border: 1px solid #BBBBBB;
6750: padding: 4px;
6751: background: #DDDDDD;
1.543 albertel 6752: }
6753:
1.584 albertel 6754: table.LC_sty_begin {
6755: background: #BBFFBB;
6756: }
1.795 www 6757:
1.584 albertel 6758: table.LC_sty_end {
6759: background: #FFBBBB;
6760: }
6761:
1.589 raeburn 6762: table.LC_double_column {
1.803 bisitz 6763: border-width: 0;
1.589 raeburn 6764: border-collapse: collapse;
6765: width: 100%;
6766: padding: 2px;
6767: }
6768:
6769: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6770: top: 2px;
1.589 raeburn 6771: left: 2px;
6772: width: 47%;
6773: vertical-align: top;
6774: }
6775:
6776: table.LC_double_column tr td.LC_right_col {
6777: top: 2px;
1.779 bisitz 6778: right: 2px;
1.589 raeburn 6779: width: 47%;
6780: vertical-align: top;
6781: }
6782:
1.591 raeburn 6783: div.LC_left_float {
6784: float: left;
6785: padding-right: 5%;
1.597 albertel 6786: padding-bottom: 4px;
1.591 raeburn 6787: }
6788:
6789: div.LC_clear_float_header {
1.597 albertel 6790: padding-bottom: 2px;
1.591 raeburn 6791: }
6792:
6793: div.LC_clear_float_footer {
1.597 albertel 6794: padding-top: 10px;
1.591 raeburn 6795: clear: both;
6796: }
6797:
1.597 albertel 6798: div.LC_grade_show_user {
1.941 bisitz 6799: /* border-left: 5px solid $sidebg; */
6800: border-top: 5px solid #000000;
6801: margin: 50px 0 0 0;
1.936 bisitz 6802: padding: 15px 0 5px 10px;
1.597 albertel 6803: }
1.795 www 6804:
1.936 bisitz 6805: div.LC_grade_show_user_odd_row {
1.941 bisitz 6806: /* border-left: 5px solid #000000; */
6807: }
6808:
6809: div.LC_grade_show_user div.LC_Box {
6810: margin-right: 50px;
1.597 albertel 6811: }
6812:
6813: div.LC_grade_submissions,
6814: div.LC_grade_message_center,
1.936 bisitz 6815: div.LC_grade_info_links {
1.597 albertel 6816: margin: 5px;
6817: width: 99%;
6818: background: #FFFFFF;
6819: }
1.795 www 6820:
1.597 albertel 6821: div.LC_grade_submissions_header,
1.936 bisitz 6822: div.LC_grade_message_center_header {
1.705 tempelho 6823: font-weight: bold;
6824: font-size: large;
1.597 albertel 6825: }
1.795 www 6826:
1.597 albertel 6827: div.LC_grade_submissions_body,
1.936 bisitz 6828: div.LC_grade_message_center_body {
1.597 albertel 6829: border: 1px solid black;
6830: width: 99%;
6831: background: #FFFFFF;
6832: }
1.795 www 6833:
1.613 albertel 6834: table.LC_scantron_action {
6835: width: 100%;
6836: }
1.795 www 6837:
1.613 albertel 6838: table.LC_scantron_action tr th {
1.698 harmsja 6839: font-weight:bold;
6840: font-style:normal;
1.613 albertel 6841: }
1.795 www 6842:
1.779 bisitz 6843: .LC_edit_problem_header,
1.614 albertel 6844: div.LC_edit_problem_footer {
1.705 tempelho 6845: font-weight: normal;
6846: font-size: medium;
1.602 albertel 6847: margin: 2px;
1.1060 bisitz 6848: background-color: $sidebg;
1.600 albertel 6849: }
1.795 www 6850:
1.600 albertel 6851: div.LC_edit_problem_header,
1.602 albertel 6852: div.LC_edit_problem_header div,
1.614 albertel 6853: div.LC_edit_problem_footer,
6854: div.LC_edit_problem_footer div,
1.602 albertel 6855: div.LC_edit_problem_editxml_header,
6856: div.LC_edit_problem_editxml_header div {
1.1205 golterma 6857: z-index: 100;
1.600 albertel 6858: }
1.795 www 6859:
1.600 albertel 6860: div.LC_edit_problem_header_title {
1.705 tempelho 6861: font-weight: bold;
6862: font-size: larger;
1.602 albertel 6863: background: $tabbg;
6864: padding: 3px;
1.1060 bisitz 6865: margin: 0 0 5px 0;
1.602 albertel 6866: }
1.795 www 6867:
1.602 albertel 6868: table.LC_edit_problem_header_title {
6869: width: 100%;
1.600 albertel 6870: background: $tabbg;
1.602 albertel 6871: }
6872:
1.1205 golterma 6873: div.LC_edit_actionbar {
6874: background-color: $sidebg;
1.1218 droeschl 6875: margin: 0;
6876: padding: 0;
6877: line-height: 200%;
1.602 albertel 6878: }
1.795 www 6879:
1.1218 droeschl 6880: div.LC_edit_actionbar div{
6881: padding: 0;
6882: margin: 0;
6883: display: inline-block;
1.600 albertel 6884: }
1.795 www 6885:
1.1124 bisitz 6886: .LC_edit_opt {
6887: padding-left: 1em;
6888: white-space: nowrap;
6889: }
6890:
1.1152 golterma 6891: .LC_edit_problem_latexhelper{
6892: text-align: right;
6893: }
6894:
6895: #LC_edit_problem_colorful div{
6896: margin-left: 40px;
6897: }
6898:
1.1205 golterma 6899: #LC_edit_problem_codemirror div{
6900: margin-left: 0px;
6901: }
6902:
1.911 bisitz 6903: img.stift {
1.803 bisitz 6904: border-width: 0;
6905: vertical-align: middle;
1.677 riegler 6906: }
1.680 riegler 6907:
1.923 bisitz 6908: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6909: vertical-align: top;
1.777 tempelho 6910: }
1.795 www 6911:
1.716 raeburn 6912: div.LC_createcourse {
1.911 bisitz 6913: margin: 10px 10px 10px 10px;
1.716 raeburn 6914: }
6915:
1.917 raeburn 6916: .LC_dccid {
1.1130 raeburn 6917: float: right;
1.917 raeburn 6918: margin: 0.2em 0 0 0;
6919: padding: 0;
6920: font-size: 90%;
6921: display:none;
6922: }
6923:
1.897 wenzelju 6924: ol.LC_primary_menu a:hover,
1.721 harmsja 6925: ol#LC_MenuBreadcrumbs a:hover,
6926: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6927: ul#LC_secondary_menu a:hover,
1.721 harmsja 6928: .LC_FormSectionClearButton input:hover
1.795 www 6929: ul.LC_TabContent li:hover a {
1.952 onken 6930: color:$button_hover;
1.911 bisitz 6931: text-decoration:none;
1.693 droeschl 6932: }
6933:
1.779 bisitz 6934: h1 {
1.911 bisitz 6935: padding: 0;
6936: line-height:130%;
1.693 droeschl 6937: }
1.698 harmsja 6938:
1.911 bisitz 6939: h2,
6940: h3,
6941: h4,
6942: h5,
6943: h6 {
6944: margin: 5px 0 5px 0;
6945: padding: 0;
6946: line-height:130%;
1.693 droeschl 6947: }
1.795 www 6948:
6949: .LC_hcell {
1.911 bisitz 6950: padding:3px 15px 3px 15px;
6951: margin: 0;
6952: background-color:$tabbg;
6953: color:$fontmenu;
6954: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6955: }
1.795 www 6956:
1.840 bisitz 6957: .LC_Box > .LC_hcell {
1.911 bisitz 6958: margin: 0 -10px 10px -10px;
1.835 bisitz 6959: }
6960:
1.721 harmsja 6961: .LC_noBorder {
1.911 bisitz 6962: border: 0;
1.698 harmsja 6963: }
1.693 droeschl 6964:
1.721 harmsja 6965: .LC_FormSectionClearButton input {
1.911 bisitz 6966: background-color:transparent;
6967: border: none;
6968: cursor:pointer;
6969: text-decoration:underline;
1.693 droeschl 6970: }
1.763 bisitz 6971:
6972: .LC_help_open_topic {
1.911 bisitz 6973: color: #FFFFFF;
6974: background-color: #EEEEFF;
6975: margin: 1px;
6976: padding: 4px;
6977: border: 1px solid #000033;
6978: white-space: nowrap;
6979: /* vertical-align: middle; */
1.759 neumanie 6980: }
1.693 droeschl 6981:
1.911 bisitz 6982: dl,
6983: ul,
6984: div,
6985: fieldset {
6986: margin: 10px 10px 10px 0;
6987: /* overflow: hidden; */
1.693 droeschl 6988: }
1.795 www 6989:
1.1211 raeburn 6990: article.geogebraweb div {
6991: margin: 0;
6992: }
6993:
1.838 bisitz 6994: fieldset > legend {
1.911 bisitz 6995: font-weight: bold;
6996: padding: 0 5px 0 5px;
1.838 bisitz 6997: }
6998:
1.813 bisitz 6999: #LC_nav_bar {
1.911 bisitz 7000: float: left;
1.995 raeburn 7001: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7002: margin: 0 0 2px 0;
1.807 droeschl 7003: }
7004:
1.916 droeschl 7005: #LC_realm {
7006: margin: 0.2em 0 0 0;
7007: padding: 0;
7008: font-weight: bold;
7009: text-align: center;
1.995 raeburn 7010: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7011: }
7012:
1.911 bisitz 7013: #LC_nav_bar em {
7014: font-weight: bold;
7015: font-style: normal;
1.807 droeschl 7016: }
7017:
1.897 wenzelju 7018: ol.LC_primary_menu {
1.934 droeschl 7019: margin: 0;
1.1076 raeburn 7020: padding: 0;
1.807 droeschl 7021: }
7022:
1.852 droeschl 7023: ol#LC_PathBreadcrumbs {
1.911 bisitz 7024: margin: 0;
1.693 droeschl 7025: }
7026:
1.897 wenzelju 7027: ol.LC_primary_menu li {
1.1076 raeburn 7028: color: RGB(80, 80, 80);
7029: vertical-align: middle;
7030: text-align: left;
7031: list-style: none;
1.1205 golterma 7032: position: relative;
1.1076 raeburn 7033: float: left;
1.1205 golterma 7034: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7035: line-height: 1.5em;
1.1076 raeburn 7036: }
7037:
1.1205 golterma 7038: ol.LC_primary_menu li a,
7039: ol.LC_primary_menu li p {
1.1076 raeburn 7040: display: block;
7041: margin: 0;
7042: padding: 0 5px 0 10px;
7043: text-decoration: none;
7044: }
7045:
1.1205 golterma 7046: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7047: display: inline-block;
7048: width: 95%;
7049: text-align: left;
7050: }
7051:
7052: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7053: display: inline-block;
7054: width: 5%;
7055: float: right;
7056: text-align: right;
7057: font-size: 70%;
7058: }
7059:
7060: ol.LC_primary_menu ul {
1.1076 raeburn 7061: display: none;
1.1205 golterma 7062: width: 15em;
1.1076 raeburn 7063: background-color: $data_table_light;
1.1205 golterma 7064: position: absolute;
7065: top: 100%;
1.1076 raeburn 7066: }
7067:
1.1205 golterma 7068: ol.LC_primary_menu ul ul {
7069: left: 100%;
7070: top: 0;
7071: }
7072:
7073: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7074: display: block;
7075: position: absolute;
7076: margin: 0;
7077: padding: 0;
1.1078 raeburn 7078: z-index: 2;
1.1076 raeburn 7079: }
7080:
7081: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7082: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7083: font-size: 90%;
1.911 bisitz 7084: vertical-align: top;
1.1076 raeburn 7085: float: none;
1.1079 raeburn 7086: border-left: 1px solid black;
7087: border-right: 1px solid black;
1.1205 golterma 7088: /* A dark bottom border to visualize different menu options;
7089: overwritten in the create_submenu routine for the last border-bottom of the menu */
7090: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7091: }
7092:
1.1205 golterma 7093: ol.LC_primary_menu li li p:hover {
7094: color:$button_hover;
7095: text-decoration:none;
7096: background-color:$data_table_dark;
1.1076 raeburn 7097: }
7098:
7099: ol.LC_primary_menu li li a:hover {
7100: color:$button_hover;
7101: background-color:$data_table_dark;
1.693 droeschl 7102: }
7103:
1.1205 golterma 7104: /* Font-size equal to the size of the predecessors*/
7105: ol.LC_primary_menu li:hover li li {
7106: font-size: 100%;
7107: }
7108:
1.897 wenzelju 7109: ol.LC_primary_menu li img {
1.911 bisitz 7110: vertical-align: bottom;
1.934 droeschl 7111: height: 1.1em;
1.1077 raeburn 7112: margin: 0.2em 0 0 0;
1.693 droeschl 7113: }
7114:
1.897 wenzelju 7115: ol.LC_primary_menu a {
1.911 bisitz 7116: color: RGB(80, 80, 80);
7117: text-decoration: none;
1.693 droeschl 7118: }
1.795 www 7119:
1.949 droeschl 7120: ol.LC_primary_menu a.LC_new_message {
7121: font-weight:bold;
7122: color: darkred;
7123: }
7124:
1.975 raeburn 7125: ol.LC_docs_parameters {
7126: margin-left: 0;
7127: padding: 0;
7128: list-style: none;
7129: }
7130:
7131: ol.LC_docs_parameters li {
7132: margin: 0;
7133: padding-right: 20px;
7134: display: inline;
7135: }
7136:
1.976 raeburn 7137: ol.LC_docs_parameters li:before {
7138: content: "\\002022 \\0020";
7139: }
7140:
7141: li.LC_docs_parameters_title {
7142: font-weight: bold;
7143: }
7144:
7145: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7146: content: "";
7147: }
7148:
1.897 wenzelju 7149: ul#LC_secondary_menu {
1.1107 raeburn 7150: clear: right;
1.911 bisitz 7151: color: $fontmenu;
7152: background: $tabbg;
7153: list-style: none;
7154: padding: 0;
7155: margin: 0;
7156: width: 100%;
1.995 raeburn 7157: text-align: left;
1.1107 raeburn 7158: float: left;
1.808 droeschl 7159: }
7160:
1.897 wenzelju 7161: ul#LC_secondary_menu li {
1.911 bisitz 7162: font-weight: bold;
7163: line-height: 1.8em;
1.1107 raeburn 7164: border-right: 1px solid black;
7165: float: left;
7166: }
7167:
7168: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7169: background-color: $data_table_light;
7170: }
7171:
7172: ul#LC_secondary_menu li a {
1.911 bisitz 7173: padding: 0 0.8em;
1.1107 raeburn 7174: }
7175:
7176: ul#LC_secondary_menu li ul {
7177: display: none;
7178: }
7179:
7180: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7181: display: block;
7182: position: absolute;
7183: margin: 0;
7184: padding: 0;
7185: list-style:none;
7186: float: none;
7187: background-color: $data_table_light;
7188: z-index: 2;
7189: margin-left: -1px;
7190: }
7191:
7192: ul#LC_secondary_menu li ul li {
7193: font-size: 90%;
7194: vertical-align: top;
7195: border-left: 1px solid black;
1.911 bisitz 7196: border-right: 1px solid black;
1.1119 raeburn 7197: background-color: $data_table_light;
1.1107 raeburn 7198: list-style:none;
7199: float: none;
7200: }
7201:
7202: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7203: background-color: $data_table_dark;
1.807 droeschl 7204: }
7205:
1.847 tempelho 7206: ul.LC_TabContent {
1.911 bisitz 7207: display:block;
7208: background: $sidebg;
7209: border-bottom: solid 1px $lg_border_color;
7210: list-style:none;
1.1020 raeburn 7211: margin: -1px -10px 0 -10px;
1.911 bisitz 7212: padding: 0;
1.693 droeschl 7213: }
7214:
1.795 www 7215: ul.LC_TabContent li,
7216: ul.LC_TabContentBigger li {
1.911 bisitz 7217: float:left;
1.741 harmsja 7218: }
1.795 www 7219:
1.897 wenzelju 7220: ul#LC_secondary_menu li a {
1.911 bisitz 7221: color: $fontmenu;
7222: text-decoration: none;
1.693 droeschl 7223: }
1.795 www 7224:
1.721 harmsja 7225: ul.LC_TabContent {
1.952 onken 7226: min-height:20px;
1.721 harmsja 7227: }
1.795 www 7228:
7229: ul.LC_TabContent li {
1.911 bisitz 7230: vertical-align:middle;
1.959 onken 7231: padding: 0 16px 0 10px;
1.911 bisitz 7232: background-color:$tabbg;
7233: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7234: border-left: solid 1px $font;
1.721 harmsja 7235: }
1.795 www 7236:
1.847 tempelho 7237: ul.LC_TabContent .right {
1.911 bisitz 7238: float:right;
1.847 tempelho 7239: }
7240:
1.911 bisitz 7241: ul.LC_TabContent li a,
7242: ul.LC_TabContent li {
7243: color:rgb(47,47,47);
7244: text-decoration:none;
7245: font-size:95%;
7246: font-weight:bold;
1.952 onken 7247: min-height:20px;
7248: }
7249:
1.959 onken 7250: ul.LC_TabContent li a:hover,
7251: ul.LC_TabContent li a:focus {
1.952 onken 7252: color: $button_hover;
1.959 onken 7253: background:none;
7254: outline:none;
1.952 onken 7255: }
7256:
7257: ul.LC_TabContent li:hover {
7258: color: $button_hover;
7259: cursor:pointer;
1.721 harmsja 7260: }
1.795 www 7261:
1.911 bisitz 7262: ul.LC_TabContent li.active {
1.952 onken 7263: color: $font;
1.911 bisitz 7264: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7265: border-bottom:solid 1px #FFFFFF;
7266: cursor: default;
1.744 ehlerst 7267: }
1.795 www 7268:
1.959 onken 7269: ul.LC_TabContent li.active a {
7270: color:$font;
7271: background:#FFFFFF;
7272: outline: none;
7273: }
1.1047 raeburn 7274:
7275: ul.LC_TabContent li.goback {
7276: float: left;
7277: border-left: none;
7278: }
7279:
1.870 tempelho 7280: #maincoursedoc {
1.911 bisitz 7281: clear:both;
1.870 tempelho 7282: }
7283:
7284: ul.LC_TabContentBigger {
1.911 bisitz 7285: display:block;
7286: list-style:none;
7287: padding: 0;
1.870 tempelho 7288: }
7289:
1.795 www 7290: ul.LC_TabContentBigger li {
1.911 bisitz 7291: vertical-align:bottom;
7292: height: 30px;
7293: font-size:110%;
7294: font-weight:bold;
7295: color: #737373;
1.841 tempelho 7296: }
7297:
1.957 onken 7298: ul.LC_TabContentBigger li.active {
7299: position: relative;
7300: top: 1px;
7301: }
7302:
1.870 tempelho 7303: ul.LC_TabContentBigger li a {
1.911 bisitz 7304: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7305: height: 30px;
7306: line-height: 30px;
7307: text-align: center;
7308: display: block;
7309: text-decoration: none;
1.958 onken 7310: outline: none;
1.741 harmsja 7311: }
1.795 www 7312:
1.870 tempelho 7313: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7314: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7315: color:$font;
1.744 ehlerst 7316: }
1.795 www 7317:
1.870 tempelho 7318: ul.LC_TabContentBigger li b {
1.911 bisitz 7319: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7320: display: block;
7321: float: left;
7322: padding: 0 30px;
1.957 onken 7323: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7324: }
7325:
1.956 onken 7326: ul.LC_TabContentBigger li:hover b {
7327: color:$button_hover;
7328: }
7329:
1.870 tempelho 7330: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7331: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7332: color:$font;
1.957 onken 7333: border: 0;
1.741 harmsja 7334: }
1.693 droeschl 7335:
1.870 tempelho 7336:
1.862 bisitz 7337: ul.LC_CourseBreadcrumbs {
7338: background: $sidebg;
1.1020 raeburn 7339: height: 2em;
1.862 bisitz 7340: padding-left: 10px;
1.1020 raeburn 7341: margin: 0;
1.862 bisitz 7342: list-style-position: inside;
7343: }
7344:
1.911 bisitz 7345: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7346: ol#LC_PathBreadcrumbs {
1.911 bisitz 7347: padding-left: 10px;
7348: margin: 0;
1.933 droeschl 7349: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7350: }
7351:
1.911 bisitz 7352: ol#LC_MenuBreadcrumbs li,
7353: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7354: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7355: display: inline;
1.933 droeschl 7356: white-space: normal;
1.693 droeschl 7357: }
7358:
1.823 bisitz 7359: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7360: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7361: text-decoration: none;
7362: font-size:90%;
1.693 droeschl 7363: }
1.795 www 7364:
1.969 droeschl 7365: ol#LC_MenuBreadcrumbs h1 {
7366: display: inline;
7367: font-size: 90%;
7368: line-height: 2.5em;
7369: margin: 0;
7370: padding: 0;
7371: }
7372:
1.795 www 7373: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7374: text-decoration:none;
7375: font-size:100%;
7376: font-weight:bold;
1.693 droeschl 7377: }
1.795 www 7378:
1.840 bisitz 7379: .LC_Box {
1.911 bisitz 7380: border: solid 1px $lg_border_color;
7381: padding: 0 10px 10px 10px;
1.746 neumanie 7382: }
1.795 www 7383:
1.1020 raeburn 7384: .LC_DocsBox {
7385: border: solid 1px $lg_border_color;
7386: padding: 0 0 10px 10px;
7387: }
7388:
1.795 www 7389: .LC_AboutMe_Image {
1.911 bisitz 7390: float:left;
7391: margin-right:10px;
1.747 neumanie 7392: }
1.795 www 7393:
7394: .LC_Clear_AboutMe_Image {
1.911 bisitz 7395: clear:left;
1.747 neumanie 7396: }
1.795 www 7397:
1.721 harmsja 7398: dl.LC_ListStyleClean dt {
1.911 bisitz 7399: padding-right: 5px;
7400: display: table-header-group;
1.693 droeschl 7401: }
7402:
1.721 harmsja 7403: dl.LC_ListStyleClean dd {
1.911 bisitz 7404: display: table-row;
1.693 droeschl 7405: }
7406:
1.721 harmsja 7407: .LC_ListStyleClean,
7408: .LC_ListStyleSimple,
7409: .LC_ListStyleNormal,
1.795 www 7410: .LC_ListStyleSpecial {
1.911 bisitz 7411: /* display:block; */
7412: list-style-position: inside;
7413: list-style-type: none;
7414: overflow: hidden;
7415: padding: 0;
1.693 droeschl 7416: }
7417:
1.721 harmsja 7418: .LC_ListStyleSimple li,
7419: .LC_ListStyleSimple dd,
7420: .LC_ListStyleNormal li,
7421: .LC_ListStyleNormal dd,
7422: .LC_ListStyleSpecial li,
1.795 www 7423: .LC_ListStyleSpecial dd {
1.911 bisitz 7424: margin: 0;
7425: padding: 5px 5px 5px 10px;
7426: clear: both;
1.693 droeschl 7427: }
7428:
1.721 harmsja 7429: .LC_ListStyleClean li,
7430: .LC_ListStyleClean dd {
1.911 bisitz 7431: padding-top: 0;
7432: padding-bottom: 0;
1.693 droeschl 7433: }
7434:
1.721 harmsja 7435: .LC_ListStyleSimple dd,
1.795 www 7436: .LC_ListStyleSimple li {
1.911 bisitz 7437: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7438: }
7439:
1.721 harmsja 7440: .LC_ListStyleSpecial li,
7441: .LC_ListStyleSpecial dd {
1.911 bisitz 7442: list-style-type: none;
7443: background-color: RGB(220, 220, 220);
7444: margin-bottom: 4px;
1.693 droeschl 7445: }
7446:
1.721 harmsja 7447: table.LC_SimpleTable {
1.911 bisitz 7448: margin:5px;
7449: border:solid 1px $lg_border_color;
1.795 www 7450: }
1.693 droeschl 7451:
1.721 harmsja 7452: table.LC_SimpleTable tr {
1.911 bisitz 7453: padding: 0;
7454: border:solid 1px $lg_border_color;
1.693 droeschl 7455: }
1.795 www 7456:
7457: table.LC_SimpleTable thead {
1.911 bisitz 7458: background:rgb(220,220,220);
1.693 droeschl 7459: }
7460:
1.721 harmsja 7461: div.LC_columnSection {
1.911 bisitz 7462: display: block;
7463: clear: both;
7464: overflow: hidden;
7465: margin: 0;
1.693 droeschl 7466: }
7467:
1.721 harmsja 7468: div.LC_columnSection>* {
1.911 bisitz 7469: float: left;
7470: margin: 10px 20px 10px 0;
7471: overflow:hidden;
1.693 droeschl 7472: }
1.721 harmsja 7473:
1.795 www 7474: table em {
1.911 bisitz 7475: font-weight: bold;
7476: font-style: normal;
1.748 schulted 7477: }
1.795 www 7478:
1.779 bisitz 7479: table.LC_tableBrowseRes,
1.795 www 7480: table.LC_tableOfContent {
1.911 bisitz 7481: border:none;
7482: border-spacing: 1px;
7483: padding: 3px;
7484: background-color: #FFFFFF;
7485: font-size: 90%;
1.753 droeschl 7486: }
1.789 droeschl 7487:
1.911 bisitz 7488: table.LC_tableOfContent {
7489: border-collapse: collapse;
1.789 droeschl 7490: }
7491:
1.771 droeschl 7492: table.LC_tableBrowseRes a,
1.768 schulted 7493: table.LC_tableOfContent a {
1.911 bisitz 7494: background-color: transparent;
7495: text-decoration: none;
1.753 droeschl 7496: }
7497:
1.795 www 7498: table.LC_tableOfContent img {
1.911 bisitz 7499: border: none;
7500: height: 1.3em;
7501: vertical-align: text-bottom;
7502: margin-right: 0.3em;
1.753 droeschl 7503: }
1.757 schulted 7504:
1.795 www 7505: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7506: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7507: }
7508:
1.795 www 7509: a#LC_content_toolbar_everything {
1.911 bisitz 7510: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7511: }
7512:
1.795 www 7513: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7514: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7515: }
7516:
1.795 www 7517: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7518: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7519: }
7520:
1.795 www 7521: a#LC_content_toolbar_changefolder {
1.911 bisitz 7522: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7523: }
7524:
1.795 www 7525: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7526: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7527: }
7528:
1.1043 raeburn 7529: a#LC_content_toolbar_edittoplevel {
7530: background-image:url(/res/adm/pages/edittoplevel.gif);
7531: }
7532:
1.795 www 7533: ul#LC_toolbar li a:hover {
1.911 bisitz 7534: background-position: bottom center;
1.757 schulted 7535: }
7536:
1.795 www 7537: ul#LC_toolbar {
1.911 bisitz 7538: padding: 0;
7539: margin: 2px;
7540: list-style:none;
7541: position:relative;
7542: background-color:white;
1.1082 raeburn 7543: overflow: auto;
1.757 schulted 7544: }
7545:
1.795 www 7546: ul#LC_toolbar li {
1.911 bisitz 7547: border:1px solid white;
7548: padding: 0;
7549: margin: 0;
7550: float: left;
7551: display:inline;
7552: vertical-align:middle;
1.1082 raeburn 7553: white-space: nowrap;
1.911 bisitz 7554: }
1.757 schulted 7555:
1.783 amueller 7556:
1.795 www 7557: a.LC_toolbarItem {
1.911 bisitz 7558: display:block;
7559: padding: 0;
7560: margin: 0;
7561: height: 32px;
7562: width: 32px;
7563: color:white;
7564: border: none;
7565: background-repeat:no-repeat;
7566: background-color:transparent;
1.757 schulted 7567: }
7568:
1.915 droeschl 7569: ul.LC_funclist {
7570: margin: 0;
7571: padding: 0.5em 1em 0.5em 0;
7572: }
7573:
1.933 droeschl 7574: ul.LC_funclist > li:first-child {
7575: font-weight:bold;
7576: margin-left:0.8em;
7577: }
7578:
1.915 droeschl 7579: ul.LC_funclist + ul.LC_funclist {
7580: /*
7581: left border as a seperator if we have more than
7582: one list
7583: */
7584: border-left: 1px solid $sidebg;
7585: /*
7586: this hides the left border behind the border of the
7587: outer box if element is wrapped to the next 'line'
7588: */
7589: margin-left: -1px;
7590: }
7591:
1.843 bisitz 7592: ul.LC_funclist li {
1.915 droeschl 7593: display: inline;
1.782 bisitz 7594: white-space: nowrap;
1.915 droeschl 7595: margin: 0 0 0 25px;
7596: line-height: 150%;
1.782 bisitz 7597: }
7598:
1.974 wenzelju 7599: .LC_hidden {
7600: display: none;
7601: }
7602:
1.1030 www 7603: .LCmodal-overlay {
7604: position:fixed;
7605: top:0;
7606: right:0;
7607: bottom:0;
7608: left:0;
7609: height:100%;
7610: width:100%;
7611: margin:0;
7612: padding:0;
7613: background:#999;
7614: opacity:.75;
7615: filter: alpha(opacity=75);
7616: -moz-opacity: 0.75;
7617: z-index:101;
7618: }
7619:
7620: * html .LCmodal-overlay {
7621: position: absolute;
7622: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7623: }
7624:
7625: .LCmodal-window {
7626: position:fixed;
7627: top:50%;
7628: left:50%;
7629: margin:0;
7630: padding:0;
7631: z-index:102;
7632: }
7633:
7634: * html .LCmodal-window {
7635: position:absolute;
7636: }
7637:
7638: .LCclose-window {
7639: position:absolute;
7640: width:32px;
7641: height:32px;
7642: right:8px;
7643: top:8px;
7644: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7645: text-indent:-99999px;
7646: overflow:hidden;
7647: cursor:pointer;
7648: }
7649:
1.1100 raeburn 7650: /*
7651: styles used by TTH when "Default set of options to pass to tth/m
7652: when converting TeX" in course settings has been set
7653:
7654: option passed: -t
7655:
7656: */
7657:
7658: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7659: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7660: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7661: td div.norm {line-height:normal;}
7662:
7663: /*
7664: option passed -y3
7665: */
7666:
7667: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7668: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7669: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7670:
1.343 albertel 7671: END
7672: }
7673:
1.306 albertel 7674: =pod
7675:
7676: =item * &headtag()
7677:
7678: Returns a uniform footer for LON-CAPA web pages.
7679:
1.307 albertel 7680: Inputs: $title - optional title for the head
7681: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7682: $args - optional arguments
1.319 albertel 7683: force_register - if is true call registerurl so the remote is
7684: informed
1.415 albertel 7685: redirect -> array ref of
7686: 1- seconds before redirect occurs
7687: 2- url to redirect to
7688: 3- whether the side effect should occur
1.315 albertel 7689: (side effect of setting
7690: $env{'internal.head.redirect'} to the url
7691: redirected too)
1.352 albertel 7692: domain -> force to color decorate a page for a specific
7693: domain
7694: function -> force usage of a specific rolish color scheme
7695: bgcolor -> override the default page bgcolor
1.460 albertel 7696: no_auto_mt_title
7697: -> prevent &mt()ing the title arg
1.464 albertel 7698:
1.306 albertel 7699: =cut
7700:
7701: sub headtag {
1.313 albertel 7702: my ($title,$head_extra,$args) = @_;
1.306 albertel 7703:
1.363 albertel 7704: my $function = $args->{'function'} || &get_users_function();
7705: my $domain = $args->{'domain'} || &determinedomain();
7706: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 7707: my $httphost = $args->{'use_absolute'};
1.418 albertel 7708: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7709: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7710: #time(),
1.418 albertel 7711: $env{'environment.color.timestamp'},
1.363 albertel 7712: $function,$domain,$bgcolor);
7713:
1.369 www 7714: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7715:
1.308 albertel 7716: my $result =
7717: '<head>'.
1.1160 raeburn 7718: &font_settings($args);
1.319 albertel 7719:
1.1188 raeburn 7720: my $inhibitprint;
7721: if ($args->{'print_suppress'}) {
7722: $inhibitprint = &print_suppression();
7723: }
1.1064 raeburn 7724:
1.461 albertel 7725: if (!$args->{'frameset'}) {
7726: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7727: }
1.962 droeschl 7728: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7729: $result .= Apache::lonxml::display_title();
1.319 albertel 7730: }
1.436 albertel 7731: if (!$args->{'no_nav_bar'}
7732: && !$args->{'only_body'}
7733: && !$args->{'frameset'}) {
1.1154 raeburn 7734: $result .= &help_menu_js($httphost);
1.1032 www 7735: $result.=&modal_window();
1.1038 www 7736: $result.=&togglebox_script();
1.1034 www 7737: $result.=&wishlist_window();
1.1041 www 7738: $result.=&LCprogressbarUpdate_script();
1.1034 www 7739: } else {
7740: if ($args->{'add_modal'}) {
7741: $result.=&modal_window();
7742: }
7743: if ($args->{'add_wishlist'}) {
7744: $result.=&wishlist_window();
7745: }
1.1038 www 7746: if ($args->{'add_togglebox'}) {
7747: $result.=&togglebox_script();
7748: }
1.1041 www 7749: if ($args->{'add_progressbar'}) {
7750: $result.=&LCprogressbarUpdate_script();
7751: }
1.436 albertel 7752: }
1.314 albertel 7753: if (ref($args->{'redirect'})) {
1.414 albertel 7754: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7755: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7756: if (!$inhibit_continue) {
7757: $env{'internal.head.redirect'} = $url;
7758: }
1.313 albertel 7759: $result.=<<ADDMETA
7760: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7761: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7762: ADDMETA
1.1210 raeburn 7763: } else {
7764: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7765: my $requrl = $env{'request.uri'};
7766: if ($requrl eq '') {
7767: $requrl = $ENV{'REQUEST_URI'};
7768: $requrl =~ s/\?.+$//;
7769: }
7770: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7771: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7772: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7773: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7774: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7775: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7776: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7777: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7778: if ($domdefs{'offloadnow'}{$lonhost}) {
7779: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7780: if (($newserver) && ($newserver ne $lonhost)) {
7781: my $numsec = 5;
7782: my $timeout = $numsec * 1000;
7783: my ($newurl,$locknum,%locks,$msg);
7784: if ($env{'request.role.adv'}) {
7785: ($locknum,%locks) = &Apache::lonnet::get_locks();
7786: }
7787: my $disable_submit = 0;
7788: if ($requrl =~ /$LONCAPA::assess_re/) {
7789: $disable_submit = 1;
7790: }
7791: if ($locknum) {
7792: my @lockinfo = sort(values(%locks));
7793: $msg = &mt('Once the following tasks are complete: ')."\\n".
7794: join(", ",sort(values(%locks)))."\\n".
7795: &mt('your session will be transferred to a different server, after you click "Roles".');
7796: } else {
7797: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7798: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7799: }
7800: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7801: $newurl = '/adm/switchserver?otherserver='.$newserver;
7802: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7803: $newurl .= '&role='.$env{'request.role'};
7804: }
7805: if ($env{'request.symb'}) {
7806: $newurl .= '&symb='.$env{'request.symb'};
7807: } else {
7808: $newurl .= '&origurl='.$requrl;
7809: }
7810: }
1.1222 damieng 7811: &js_escape(\$msg);
1.1210 raeburn 7812: $result.=<<OFFLOAD
7813: <meta http-equiv="pragma" content="no-cache" />
7814: <script type="text/javascript">
1.1215 raeburn 7815: // <![CDATA[
1.1210 raeburn 7816: function LC_Offload_Now() {
7817: var dest = "$newurl";
7818: if (dest != '') {
7819: window.location.href="$newurl";
7820: }
7821: }
1.1214 raeburn 7822: \$(document).ready(function () {
7823: window.alert('$msg');
7824: if ($disable_submit) {
1.1210 raeburn 7825: \$(".LC_hwk_submit").prop("disabled", true);
7826: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 7827: }
7828: setTimeout('LC_Offload_Now()', $timeout);
7829: });
1.1215 raeburn 7830: // ]]>
1.1210 raeburn 7831: </script>
7832: OFFLOAD
7833: }
7834: }
7835: }
7836: }
7837: }
7838: }
1.313 albertel 7839: }
1.306 albertel 7840: if (!defined($title)) {
7841: $title = 'The LearningOnline Network with CAPA';
7842: }
1.460 albertel 7843: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7844: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 7845: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7846: if (!$args->{'frameset'}) {
7847: $result .= ' /';
7848: }
7849: $result .= '>'
1.1064 raeburn 7850: .$inhibitprint
1.414 albertel 7851: .$head_extra;
1.1137 raeburn 7852: if ($env{'browser.mobile'}) {
7853: $result .= '
7854: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7855: <meta name="apple-mobile-web-app-capable" content="yes" />';
7856: }
1.962 droeschl 7857: return $result.'</head>';
1.306 albertel 7858: }
7859:
7860: =pod
7861:
1.340 albertel 7862: =item * &font_settings()
7863:
7864: Returns neccessary <meta> to set the proper encoding
7865:
1.1160 raeburn 7866: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7867:
7868: =cut
7869:
7870: sub font_settings {
1.1160 raeburn 7871: my ($args) = @_;
1.340 albertel 7872: my $headerstring='';
1.1160 raeburn 7873: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7874: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 7875: $headerstring.=
7876: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7877: if (!$args->{'frameset'}) {
7878: $headerstring.= ' /';
7879: }
7880: $headerstring .= '>'."\n";
1.340 albertel 7881: }
7882: return $headerstring;
7883: }
7884:
1.341 albertel 7885: =pod
7886:
1.1064 raeburn 7887: =item * &print_suppression()
7888:
7889: In course context returns css which causes the body to be blank when media="print",
7890: if printout generation is unavailable for the current resource.
7891:
7892: This could be because:
7893:
7894: (a) printstartdate is in the future
7895:
7896: (b) printenddate is in the past
7897:
7898: (c) there is an active exam block with "printout"
7899: functionality blocked
7900:
7901: Users with pav, pfo or evb privileges are exempt.
7902:
7903: Inputs: none
7904:
7905: =cut
7906:
7907:
7908: sub print_suppression {
7909: my $noprint;
7910: if ($env{'request.course.id'}) {
7911: my $scope = $env{'request.course.id'};
7912: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7913: (&Apache::lonnet::allowed('pfo',$scope))) {
7914: return;
7915: }
7916: if ($env{'request.course.sec'} ne '') {
7917: $scope .= "/$env{'request.course.sec'}";
7918: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7919: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7920: return;
1.1064 raeburn 7921: }
7922: }
7923: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7924: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 7925: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 7926: if ($blocked) {
7927: my $checkrole = "cm./$cdom/$cnum";
7928: if ($env{'request.course.sec'} ne '') {
7929: $checkrole .= "/$env{'request.course.sec'}";
7930: }
7931: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7932: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7933: $noprint = 1;
7934: }
7935: }
7936: unless ($noprint) {
7937: my $symb = &Apache::lonnet::symbread();
7938: if ($symb ne '') {
7939: my $navmap = Apache::lonnavmaps::navmap->new();
7940: if (ref($navmap)) {
7941: my $res = $navmap->getBySymb($symb);
7942: if (ref($res)) {
7943: if (!$res->resprintable()) {
7944: $noprint = 1;
7945: }
7946: }
7947: }
7948: }
7949: }
7950: if ($noprint) {
7951: return <<"ENDSTYLE";
7952: <style type="text/css" media="print">
7953: body { display:none }
7954: </style>
7955: ENDSTYLE
7956: }
7957: }
7958: return;
7959: }
7960:
7961: =pod
7962:
1.341 albertel 7963: =item * &xml_begin()
7964:
7965: Returns the needed doctype and <html>
7966:
7967: Inputs: none
7968:
7969: =cut
7970:
7971: sub xml_begin {
1.1168 raeburn 7972: my ($is_frameset) = @_;
1.341 albertel 7973: my $output='';
7974:
7975: if ($env{'browser.mathml'}) {
7976: $output='<?xml version="1.0"?>'
7977: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7978: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7979:
7980: # .'<!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">] >'
7981: .'<!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">'
7982: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7983: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 7984: } elsif ($is_frameset) {
7985: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7986: '<html>'."\n";
1.341 albertel 7987: } else {
1.1168 raeburn 7988: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7989: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7990: }
7991: return $output;
7992: }
1.340 albertel 7993:
7994: =pod
7995:
1.306 albertel 7996: =item * &start_page()
7997:
7998: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7999:
1.648 raeburn 8000: Inputs:
8001:
8002: =over 4
8003:
8004: $title - optional title for the page
8005:
8006: $head_extra - optional extra HTML to incude inside the <head>
8007:
8008: $args - additional optional args supported are:
8009:
8010: =over 8
8011:
8012: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8013: arg on
1.814 bisitz 8014: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8015: add_entries -> additional attributes to add to the <body>
8016: domain -> force to color decorate a page for a
1.317 albertel 8017: specific domain
1.648 raeburn 8018: function -> force usage of a specific rolish color
1.317 albertel 8019: scheme
1.648 raeburn 8020: redirect -> see &headtag()
8021: bgcolor -> override the default page bg color
8022: js_ready -> return a string ready for being used in
1.317 albertel 8023: a javascript writeln
1.648 raeburn 8024: html_encode -> return a string ready for being used in
1.320 albertel 8025: a html attribute
1.648 raeburn 8026: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8027: $forcereg arg
1.648 raeburn 8028: frameset -> if true will start with a <frameset>
1.330 albertel 8029: rather than <body>
1.648 raeburn 8030: skip_phases -> hash ref of
1.338 albertel 8031: head -> skip the <html><head> generation
8032: body -> skip all <body> generation
1.648 raeburn 8033: no_auto_mt_title -> prevent &mt()ing the title arg
8034: inherit_jsmath -> when creating popup window in a page,
8035: should it have jsmath forced on by the
8036: current page
1.867 kalberla 8037: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8038: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 8039: group -> includes the current group, if page is for a
8040: specific group
1.361 albertel 8041:
1.648 raeburn 8042: =back
1.460 albertel 8043:
1.648 raeburn 8044: =back
1.562 albertel 8045:
1.306 albertel 8046: =cut
8047:
8048: sub start_page {
1.309 albertel 8049: my ($title,$head_extra,$args) = @_;
1.318 albertel 8050: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8051:
1.315 albertel 8052: $env{'internal.start_page'}++;
1.1096 raeburn 8053: my ($result,@advtools);
1.964 droeschl 8054:
1.338 albertel 8055: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8056: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8057: }
8058:
8059: if (! exists($args->{'skip_phases'}{'body'}) ) {
8060: if ($args->{'frameset'}) {
8061: my $attr_string = &make_attr_string($args->{'force_register'},
8062: $args->{'add_entries'});
8063: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8064: } else {
8065: $result .=
8066: &bodytag($title,
8067: $args->{'function'}, $args->{'add_entries'},
8068: $args->{'only_body'}, $args->{'domain'},
8069: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8070: $args->{'bgcolor'}, $args,
8071: \@advtools);
1.831 bisitz 8072: }
1.330 albertel 8073: }
1.338 albertel 8074:
1.315 albertel 8075: if ($args->{'js_ready'}) {
1.713 kaisler 8076: $result = &js_ready($result);
1.315 albertel 8077: }
1.320 albertel 8078: if ($args->{'html_encode'}) {
1.713 kaisler 8079: $result = &html_encode($result);
8080: }
8081:
1.813 bisitz 8082: # Preparation for new and consistent functionlist at top of screen
8083: # if ($args->{'functionlist'}) {
8084: # $result .= &build_functionlist();
8085: #}
8086:
1.964 droeschl 8087: # Don't add anything more if only_body wanted or in const space
8088: return $result if $args->{'only_body'}
8089: || $env{'request.state'} eq 'construct';
1.813 bisitz 8090:
8091: #Breadcrumbs
1.758 kaisler 8092: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8093: &Apache::lonhtmlcommon::clear_breadcrumbs();
8094: #if any br links exists, add them to the breadcrumbs
8095: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8096: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8097: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8098: }
8099: }
1.1096 raeburn 8100: # if @advtools array contains items add then to the breadcrumbs
8101: if (@advtools > 0) {
8102: &Apache::lonmenu::advtools_crumbs(@advtools);
8103: }
1.758 kaisler 8104:
8105: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8106: if(exists($args->{'bread_crumbs_component'})){
8107: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
8108: }else{
8109: $result .= &Apache::lonhtmlcommon::breadcrumbs();
8110: }
1.320 albertel 8111: }
1.315 albertel 8112: return $result;
1.306 albertel 8113: }
8114:
8115: sub end_page {
1.315 albertel 8116: my ($args) = @_;
8117: $env{'internal.end_page'}++;
1.330 albertel 8118: my $result;
1.335 albertel 8119: if ($args->{'discussion'}) {
8120: my ($target,$parser);
8121: if (ref($args->{'discussion'})) {
8122: ($target,$parser) =($args->{'discussion'}{'target'},
8123: $args->{'discussion'}{'parser'});
8124: }
8125: $result .= &Apache::lonxml::xmlend($target,$parser);
8126: }
1.330 albertel 8127: if ($args->{'frameset'}) {
8128: $result .= '</frameset>';
8129: } else {
1.635 raeburn 8130: $result .= &endbodytag($args);
1.330 albertel 8131: }
1.1080 raeburn 8132: unless ($args->{'notbody'}) {
8133: $result .= "\n</html>";
8134: }
1.330 albertel 8135:
1.315 albertel 8136: if ($args->{'js_ready'}) {
1.317 albertel 8137: $result = &js_ready($result);
1.315 albertel 8138: }
1.335 albertel 8139:
1.320 albertel 8140: if ($args->{'html_encode'}) {
8141: $result = &html_encode($result);
8142: }
1.335 albertel 8143:
1.315 albertel 8144: return $result;
8145: }
8146:
1.1034 www 8147: sub wishlist_window {
8148: return(<<'ENDWISHLIST');
1.1046 raeburn 8149: <script type="text/javascript">
1.1034 www 8150: // <![CDATA[
8151: // <!-- BEGIN LON-CAPA Internal
8152: function set_wishlistlink(title, path) {
8153: if (!title) {
8154: title = document.title;
8155: title = title.replace(/^LON-CAPA /,'');
8156: }
1.1175 raeburn 8157: title = encodeURIComponent(title);
1.1203 raeburn 8158: title = title.replace("'","\\\'");
1.1034 www 8159: if (!path) {
8160: path = location.pathname;
8161: }
1.1175 raeburn 8162: path = encodeURIComponent(path);
1.1203 raeburn 8163: path = path.replace("'","\\\'");
1.1034 www 8164: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8165: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8166: }
8167: // END LON-CAPA Internal -->
8168: // ]]>
8169: </script>
8170: ENDWISHLIST
8171: }
8172:
1.1030 www 8173: sub modal_window {
8174: return(<<'ENDMODAL');
1.1046 raeburn 8175: <script type="text/javascript">
1.1030 www 8176: // <![CDATA[
8177: // <!-- BEGIN LON-CAPA Internal
8178: var modalWindow = {
8179: parent:"body",
8180: windowId:null,
8181: content:null,
8182: width:null,
8183: height:null,
8184: close:function()
8185: {
8186: $(".LCmodal-window").remove();
8187: $(".LCmodal-overlay").remove();
8188: },
8189: open:function()
8190: {
8191: var modal = "";
8192: modal += "<div class=\"LCmodal-overlay\"></div>";
8193: 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;\">";
8194: modal += this.content;
8195: modal += "</div>";
8196:
8197: $(this.parent).append(modal);
8198:
8199: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8200: $(".LCclose-window").click(function(){modalWindow.close();});
8201: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8202: }
8203: };
1.1140 raeburn 8204: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8205: {
1.1203 raeburn 8206: source = source.replace("'","'");
1.1030 www 8207: modalWindow.windowId = "myModal";
8208: modalWindow.width = width;
8209: modalWindow.height = height;
1.1196 raeburn 8210: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8211: modalWindow.open();
1.1208 raeburn 8212: };
1.1030 www 8213: // END LON-CAPA Internal -->
8214: // ]]>
8215: </script>
8216: ENDMODAL
8217: }
8218:
8219: sub modal_link {
1.1140 raeburn 8220: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8221: unless ($width) { $width=480; }
8222: unless ($height) { $height=400; }
1.1031 www 8223: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8224: unless ($transparency) { $transparency='true'; }
8225:
1.1074 raeburn 8226: my $target_attr;
8227: if (defined($target)) {
8228: $target_attr = 'target="'.$target.'"';
8229: }
8230: return <<"ENDLINK";
1.1140 raeburn 8231: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8232: $linktext</a>
8233: ENDLINK
1.1030 www 8234: }
8235:
1.1032 www 8236: sub modal_adhoc_script {
8237: my ($funcname,$width,$height,$content)=@_;
8238: return (<<ENDADHOC);
1.1046 raeburn 8239: <script type="text/javascript">
1.1032 www 8240: // <![CDATA[
8241: var $funcname = function()
8242: {
8243: modalWindow.windowId = "myModal";
8244: modalWindow.width = $width;
8245: modalWindow.height = $height;
8246: modalWindow.content = '$content';
8247: modalWindow.open();
8248: };
8249: // ]]>
8250: </script>
8251: ENDADHOC
8252: }
8253:
1.1041 www 8254: sub modal_adhoc_inner {
8255: my ($funcname,$width,$height,$content)=@_;
8256: my $innerwidth=$width-20;
8257: $content=&js_ready(
1.1140 raeburn 8258: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8259: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8260: $content.
1.1041 www 8261: &end_scrollbox().
1.1140 raeburn 8262: &end_page()
1.1041 www 8263: );
8264: return &modal_adhoc_script($funcname,$width,$height,$content);
8265: }
8266:
8267: sub modal_adhoc_window {
8268: my ($funcname,$width,$height,$content,$linktext)=@_;
8269: return &modal_adhoc_inner($funcname,$width,$height,$content).
8270: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8271: }
8272:
8273: sub modal_adhoc_launch {
8274: my ($funcname,$width,$height,$content)=@_;
8275: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8276: <script type="text/javascript">
8277: // <![CDATA[
8278: $funcname();
8279: // ]]>
8280: </script>
8281: ENDLAUNCH
8282: }
8283:
8284: sub modal_adhoc_close {
8285: return (<<ENDCLOSE);
8286: <script type="text/javascript">
8287: // <![CDATA[
8288: modalWindow.close();
8289: // ]]>
8290: </script>
8291: ENDCLOSE
8292: }
8293:
1.1038 www 8294: sub togglebox_script {
8295: return(<<ENDTOGGLE);
8296: <script type="text/javascript">
8297: // <![CDATA[
8298: function LCtoggleDisplay(id,hidetext,showtext) {
8299: link = document.getElementById(id + "link").childNodes[0];
8300: with (document.getElementById(id).style) {
8301: if (display == "none" ) {
8302: display = "inline";
8303: link.nodeValue = hidetext;
8304: } else {
8305: display = "none";
8306: link.nodeValue = showtext;
8307: }
8308: }
8309: }
8310: // ]]>
8311: </script>
8312: ENDTOGGLE
8313: }
8314:
1.1039 www 8315: sub start_togglebox {
8316: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8317: unless ($heading) { $heading=''; } else { $heading.=' '; }
8318: unless ($showtext) { $showtext=&mt('show'); }
8319: unless ($hidetext) { $hidetext=&mt('hide'); }
8320: unless ($headerbg) { $headerbg='#FFFFFF'; }
8321: return &start_data_table().
8322: &start_data_table_header_row().
8323: '<td bgcolor="'.$headerbg.'">'.$heading.
8324: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8325: $showtext.'\')">'.$showtext.'</a>]</td>'.
8326: &end_data_table_header_row().
8327: '<tr id="'.$id.'" style="display:none""><td>';
8328: }
8329:
8330: sub end_togglebox {
8331: return '</td></tr>'.&end_data_table();
8332: }
8333:
1.1041 www 8334: sub LCprogressbar_script {
1.1045 www 8335: my ($id)=@_;
1.1041 www 8336: return(<<ENDPROGRESS);
8337: <script type="text/javascript">
8338: // <![CDATA[
1.1045 www 8339: \$('#progressbar$id').progressbar({
1.1041 www 8340: value: 0,
8341: change: function(event, ui) {
8342: var newVal = \$(this).progressbar('option', 'value');
8343: \$('.pblabel', this).text(LCprogressTxt);
8344: }
8345: });
8346: // ]]>
8347: </script>
8348: ENDPROGRESS
8349: }
8350:
8351: sub LCprogressbarUpdate_script {
8352: return(<<ENDPROGRESSUPDATE);
8353: <style type="text/css">
8354: .ui-progressbar { position:relative; }
8355: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8356: </style>
8357: <script type="text/javascript">
8358: // <![CDATA[
1.1045 www 8359: var LCprogressTxt='---';
8360:
8361: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8362: LCprogressTxt=progresstext;
1.1045 www 8363: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8364: }
8365: // ]]>
8366: </script>
8367: ENDPROGRESSUPDATE
8368: }
8369:
1.1042 www 8370: my $LClastpercent;
1.1045 www 8371: my $LCidcnt;
8372: my $LCcurrentid;
1.1042 www 8373:
1.1041 www 8374: sub LCprogressbar {
1.1042 www 8375: my ($r)=(@_);
8376: $LClastpercent=0;
1.1045 www 8377: $LCidcnt++;
8378: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8379: my $starting=&mt('Starting');
8380: my $content=(<<ENDPROGBAR);
1.1045 www 8381: <div id="progressbar$LCcurrentid">
1.1041 www 8382: <span class="pblabel">$starting</span>
8383: </div>
8384: ENDPROGBAR
1.1045 www 8385: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8386: }
8387:
8388: sub LCprogressbarUpdate {
1.1042 www 8389: my ($r,$val,$text)=@_;
8390: unless ($val) {
8391: if ($LClastpercent) {
8392: $val=$LClastpercent;
8393: } else {
8394: $val=0;
8395: }
8396: }
1.1041 www 8397: if ($val<0) { $val=0; }
8398: if ($val>100) { $val=0; }
1.1042 www 8399: $LClastpercent=$val;
1.1041 www 8400: unless ($text) { $text=$val.'%'; }
8401: $text=&js_ready($text);
1.1044 www 8402: &r_print($r,<<ENDUPDATE);
1.1041 www 8403: <script type="text/javascript">
8404: // <![CDATA[
1.1045 www 8405: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8406: // ]]>
8407: </script>
8408: ENDUPDATE
1.1035 www 8409: }
8410:
1.1042 www 8411: sub LCprogressbarClose {
8412: my ($r)=@_;
8413: $LClastpercent=0;
1.1044 www 8414: &r_print($r,<<ENDCLOSE);
1.1042 www 8415: <script type="text/javascript">
8416: // <![CDATA[
1.1045 www 8417: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8418: // ]]>
8419: </script>
8420: ENDCLOSE
1.1044 www 8421: }
8422:
8423: sub r_print {
8424: my ($r,$to_print)=@_;
8425: if ($r) {
8426: $r->print($to_print);
8427: $r->rflush();
8428: } else {
8429: print($to_print);
8430: }
1.1042 www 8431: }
8432:
1.320 albertel 8433: sub html_encode {
8434: my ($result) = @_;
8435:
1.322 albertel 8436: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8437:
8438: return $result;
8439: }
1.1044 www 8440:
1.317 albertel 8441: sub js_ready {
8442: my ($result) = @_;
8443:
1.323 albertel 8444: $result =~ s/[\n\r]/ /xmsg;
8445: $result =~ s/\\/\\\\/xmsg;
8446: $result =~ s/'/\\'/xmsg;
1.372 albertel 8447: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8448:
8449: return $result;
8450: }
8451:
1.315 albertel 8452: sub validate_page {
8453: if ( exists($env{'internal.start_page'})
1.316 albertel 8454: && $env{'internal.start_page'} > 1) {
8455: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8456: $env{'internal.start_page'}.' '.
1.316 albertel 8457: $ENV{'request.filename'});
1.315 albertel 8458: }
8459: if ( exists($env{'internal.end_page'})
1.316 albertel 8460: && $env{'internal.end_page'} > 1) {
8461: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8462: $env{'internal.end_page'}.' '.
1.316 albertel 8463: $env{'request.filename'});
1.315 albertel 8464: }
8465: if ( exists($env{'internal.start_page'})
8466: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8467: &Apache::lonnet::logthis('start_page called without end_page '.
8468: $env{'request.filename'});
1.315 albertel 8469: }
8470: if ( ! exists($env{'internal.start_page'})
8471: && exists($env{'internal.end_page'})) {
1.316 albertel 8472: &Apache::lonnet::logthis('end_page called without start_page'.
8473: $env{'request.filename'});
1.315 albertel 8474: }
1.306 albertel 8475: }
1.315 albertel 8476:
1.996 www 8477:
8478: sub start_scrollbox {
1.1140 raeburn 8479: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8480: unless ($outerwidth) { $outerwidth='520px'; }
8481: unless ($width) { $width='500px'; }
8482: unless ($height) { $height='200px'; }
1.1075 raeburn 8483: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8484: if ($id ne '') {
1.1140 raeburn 8485: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 8486: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8487: }
1.1075 raeburn 8488: if ($bgcolor ne '') {
8489: $tdcol = "background-color: $bgcolor;";
8490: }
1.1137 raeburn 8491: my $nicescroll_js;
8492: if ($env{'browser.mobile'}) {
1.1140 raeburn 8493: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8494: }
8495: return <<"END";
8496: $nicescroll_js
8497:
8498: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
8499: <div style="overflow:auto; width:$width; height:$height;"$div_id>
8500: END
8501: }
8502:
8503: sub end_scrollbox {
8504: return '</div></td></tr></table>';
8505: }
8506:
8507: sub nicescroll_javascript {
8508: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8509: my %options;
8510: if (ref($cursor) eq 'HASH') {
8511: %options = %{$cursor};
8512: }
8513: unless ($options{'railalign'} =~ /^left|right$/) {
8514: $options{'railalign'} = 'left';
8515: }
8516: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8517: my $function = &get_users_function();
8518: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 8519: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 8520: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 8521: }
1.1140 raeburn 8522: }
8523: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8524: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 8525: $options{'cursoropacity'}='1.0';
8526: }
1.1140 raeburn 8527: } else {
8528: $options{'cursoropacity'}='1.0';
8529: }
8530: if ($options{'cursorfixedheight'} eq 'none') {
8531: delete($options{'cursorfixedheight'});
8532: } else {
8533: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8534: }
8535: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8536: delete($options{'railoffset'});
8537: }
8538: my @niceoptions;
8539: while (my($key,$value) = each(%options)) {
8540: if ($value =~ /^\{.+\}$/) {
8541: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 8542: } else {
1.1140 raeburn 8543: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 8544: }
1.1140 raeburn 8545: }
8546: my $nicescroll_js = '
1.1137 raeburn 8547: $(document).ready(
1.1140 raeburn 8548: function() {
8549: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8550: }
1.1137 raeburn 8551: );
8552: ';
1.1140 raeburn 8553: if ($framecheck) {
8554: $nicescroll_js .= '
8555: function expand_div(caller) {
8556: if (top === self) {
8557: document.getElementById("'.$id.'").style.width = "auto";
8558: document.getElementById("'.$id.'").style.height = "auto";
8559: } else {
8560: try {
8561: if (parent.frames) {
8562: if (parent.frames.length > 1) {
8563: var framesrc = parent.frames[1].location.href;
8564: var currsrc = framesrc.replace(/\#.*$/,"");
8565: if ((caller == "search") || (currsrc == "'.$location.'")) {
8566: document.getElementById("'.$id.'").style.width = "auto";
8567: document.getElementById("'.$id.'").style.height = "auto";
8568: }
8569: }
8570: }
8571: } catch (e) {
8572: return;
8573: }
1.1137 raeburn 8574: }
1.1140 raeburn 8575: return;
1.996 www 8576: }
1.1140 raeburn 8577: ';
8578: }
8579: if ($needjsready) {
8580: $nicescroll_js = '
8581: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8582: } else {
8583: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8584: }
8585: return $nicescroll_js;
1.996 www 8586: }
8587:
1.318 albertel 8588: sub simple_error_page {
1.1150 bisitz 8589: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 8590: if (ref($args) eq 'HASH') {
8591: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8592: } else {
8593: $msg = &mt($msg);
8594: }
1.1150 bisitz 8595:
1.318 albertel 8596: my $page =
8597: &Apache::loncommon::start_page($title).
1.1150 bisitz 8598: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8599: &Apache::loncommon::end_page();
8600: if (ref($r)) {
8601: $r->print($page);
1.327 albertel 8602: return;
1.318 albertel 8603: }
8604: return $page;
8605: }
1.347 albertel 8606:
8607: {
1.610 albertel 8608: my @row_count;
1.961 onken 8609:
8610: sub start_data_table_count {
8611: unshift(@row_count, 0);
8612: return;
8613: }
8614:
8615: sub end_data_table_count {
8616: shift(@row_count);
8617: return;
8618: }
8619:
1.347 albertel 8620: sub start_data_table {
1.1018 raeburn 8621: my ($add_class,$id) = @_;
1.422 albertel 8622: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8623: my $table_id;
8624: if (defined($id)) {
8625: $table_id = ' id="'.$id.'"';
8626: }
1.961 onken 8627: &start_data_table_count();
1.1018 raeburn 8628: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8629: }
8630:
8631: sub end_data_table {
1.961 onken 8632: &end_data_table_count();
1.389 albertel 8633: return '</table>'."\n";;
1.347 albertel 8634: }
8635:
8636: sub start_data_table_row {
1.974 wenzelju 8637: my ($add_class, $id) = @_;
1.610 albertel 8638: $row_count[0]++;
8639: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8640: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8641: $id = (' id="'.$id.'"') unless ($id eq '');
8642: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8643: }
1.471 banghart 8644:
8645: sub continue_data_table_row {
1.974 wenzelju 8646: my ($add_class, $id) = @_;
1.610 albertel 8647: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8648: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8649: $id = (' id="'.$id.'"') unless ($id eq '');
8650: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8651: }
1.347 albertel 8652:
8653: sub end_data_table_row {
1.389 albertel 8654: return '</tr>'."\n";;
1.347 albertel 8655: }
1.367 www 8656:
1.421 albertel 8657: sub start_data_table_empty_row {
1.707 bisitz 8658: # $row_count[0]++;
1.421 albertel 8659: return '<tr class="LC_empty_row" >'."\n";;
8660: }
8661:
8662: sub end_data_table_empty_row {
8663: return '</tr>'."\n";;
8664: }
8665:
1.367 www 8666: sub start_data_table_header_row {
1.389 albertel 8667: return '<tr class="LC_header_row">'."\n";;
1.367 www 8668: }
8669:
8670: sub end_data_table_header_row {
1.389 albertel 8671: return '</tr>'."\n";;
1.367 www 8672: }
1.890 droeschl 8673:
8674: sub data_table_caption {
8675: my $caption = shift;
8676: return "<caption class=\"LC_caption\">$caption</caption>";
8677: }
1.347 albertel 8678: }
8679:
1.548 albertel 8680: =pod
8681:
8682: =item * &inhibit_menu_check($arg)
8683:
8684: Checks for a inhibitmenu state and generates output to preserve it
8685:
8686: Inputs: $arg - can be any of
8687: - undef - in which case the return value is a string
8688: to add into arguments list of a uri
8689: - 'input' - in which case the return value is a HTML
8690: <form> <input> field of type hidden to
8691: preserve the value
8692: - a url - in which case the return value is the url with
8693: the neccesary cgi args added to preserve the
8694: inhibitmenu state
8695: - a ref to a url - no return value, but the string is
8696: updated to include the neccessary cgi
8697: args to preserve the inhibitmenu state
8698:
8699: =cut
8700:
8701: sub inhibit_menu_check {
8702: my ($arg) = @_;
8703: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8704: if ($arg eq 'input') {
8705: if ($env{'form.inhibitmenu'}) {
8706: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8707: } else {
8708: return
8709: }
8710: }
8711: if ($env{'form.inhibitmenu'}) {
8712: if (ref($arg)) {
8713: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8714: } elsif ($arg eq '') {
8715: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8716: } else {
8717: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8718: }
8719: }
8720: if (!ref($arg)) {
8721: return $arg;
8722: }
8723: }
8724:
1.251 albertel 8725: ###############################################
1.182 matthew 8726:
8727: =pod
8728:
1.549 albertel 8729: =back
8730:
8731: =head1 User Information Routines
8732:
8733: =over 4
8734:
1.405 albertel 8735: =item * &get_users_function()
1.182 matthew 8736:
8737: Used by &bodytag to determine the current users primary role.
8738: Returns either 'student','coordinator','admin', or 'author'.
8739:
8740: =cut
8741:
8742: ###############################################
8743: sub get_users_function {
1.815 tempelho 8744: my $function = 'norole';
1.818 tempelho 8745: if ($env{'request.role'}=~/^(st)/) {
8746: $function='student';
8747: }
1.907 raeburn 8748: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8749: $function='coordinator';
8750: }
1.258 albertel 8751: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8752: $function='admin';
8753: }
1.826 bisitz 8754: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8755: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8756: $function='author';
8757: }
8758: return $function;
1.54 www 8759: }
1.99 www 8760:
8761: ###############################################
8762:
1.233 raeburn 8763: =pod
8764:
1.821 raeburn 8765: =item * &show_course()
8766:
8767: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8768: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8769:
8770: Inputs:
8771: None
8772:
8773: Outputs:
8774: Scalar: 1 if 'Course' to be used, 0 otherwise.
8775:
8776: =cut
8777:
8778: ###############################################
8779: sub show_course {
8780: my $course = !$env{'user.adv'};
8781: if (!$env{'user.adv'}) {
8782: foreach my $env (keys(%env)) {
8783: next if ($env !~ m/^user\.priv\./);
8784: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8785: $course = 0;
8786: last;
8787: }
8788: }
8789: }
8790: return $course;
8791: }
8792:
8793: ###############################################
8794:
8795: =pod
8796:
1.542 raeburn 8797: =item * &check_user_status()
1.274 raeburn 8798:
8799: Determines current status of supplied role for a
8800: specific user. Roles can be active, previous or future.
8801:
8802: Inputs:
8803: user's domain, user's username, course's domain,
1.375 raeburn 8804: course's number, optional section ID.
1.274 raeburn 8805:
8806: Outputs:
8807: role status: active, previous or future.
8808:
8809: =cut
8810:
8811: sub check_user_status {
1.412 raeburn 8812: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8813: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 8814: my @uroles = keys(%userinfo);
1.274 raeburn 8815: my $srchstr;
8816: my $active_chk = 'none';
1.412 raeburn 8817: my $now = time;
1.274 raeburn 8818: if (@uroles > 0) {
1.908 raeburn 8819: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8820: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8821: } else {
1.412 raeburn 8822: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8823: }
8824: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8825: my $role_end = 0;
8826: my $role_start = 0;
8827: $active_chk = 'active';
1.412 raeburn 8828: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8829: $role_end = $1;
8830: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8831: $role_start = $1;
1.274 raeburn 8832: }
8833: }
8834: if ($role_start > 0) {
1.412 raeburn 8835: if ($now < $role_start) {
1.274 raeburn 8836: $active_chk = 'future';
8837: }
8838: }
8839: if ($role_end > 0) {
1.412 raeburn 8840: if ($now > $role_end) {
1.274 raeburn 8841: $active_chk = 'previous';
8842: }
8843: }
8844: }
8845: }
8846: return $active_chk;
8847: }
8848:
8849: ###############################################
8850:
8851: =pod
8852:
1.405 albertel 8853: =item * &get_sections()
1.233 raeburn 8854:
8855: Determines all the sections for a course including
8856: sections with students and sections containing other roles.
1.419 raeburn 8857: Incoming parameters:
8858:
8859: 1. domain
8860: 2. course number
8861: 3. reference to array containing roles for which sections should
8862: be gathered (optional).
8863: 4. reference to array containing status types for which sections
8864: should be gathered (optional).
8865:
8866: If the third argument is undefined, sections are gathered for any role.
8867: If the fourth argument is undefined, sections are gathered for any status.
8868: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8869:
1.374 raeburn 8870: Returns section hash (keys are section IDs, values are
8871: number of users in each section), subject to the
1.419 raeburn 8872: optional roles filter, optional status filter
1.233 raeburn 8873:
8874: =cut
8875:
8876: ###############################################
8877: sub get_sections {
1.419 raeburn 8878: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8879: if (!defined($cdom) || !defined($cnum)) {
8880: my $cid = $env{'request.course.id'};
8881:
8882: return if (!defined($cid));
8883:
8884: $cdom = $env{'course.'.$cid.'.domain'};
8885: $cnum = $env{'course.'.$cid.'.num'};
8886: }
8887:
8888: my %sectioncount;
1.419 raeburn 8889: my $now = time;
1.240 albertel 8890:
1.1118 raeburn 8891: my $check_students = 1;
8892: my $only_students = 0;
8893: if (ref($possible_roles) eq 'ARRAY') {
8894: if (grep(/^st$/,@{$possible_roles})) {
8895: if (@{$possible_roles} == 1) {
8896: $only_students = 1;
8897: }
8898: } else {
8899: $check_students = 0;
8900: }
8901: }
8902:
8903: if ($check_students) {
1.276 albertel 8904: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8905: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8906: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8907: my $start_index = &Apache::loncoursedata::CL_START();
8908: my $end_index = &Apache::loncoursedata::CL_END();
8909: my $status;
1.366 albertel 8910: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8911: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8912: $data->[$status_index],
8913: $data->[$start_index],
8914: $data->[$end_index]);
8915: if ($stu_status eq 'Active') {
8916: $status = 'active';
8917: } elsif ($end < $now) {
8918: $status = 'previous';
8919: } elsif ($start > $now) {
8920: $status = 'future';
8921: }
8922: if ($section ne '-1' && $section !~ /^\s*$/) {
8923: if ((!defined($possible_status)) || (($status ne '') &&
8924: (grep/^\Q$status\E$/,@{$possible_status}))) {
8925: $sectioncount{$section}++;
8926: }
1.240 albertel 8927: }
8928: }
8929: }
1.1118 raeburn 8930: if ($only_students) {
8931: return %sectioncount;
8932: }
1.240 albertel 8933: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8934: foreach my $user (sort(keys(%courseroles))) {
8935: if ($user !~ /^(\w{2})/) { next; }
8936: my ($role) = ($user =~ /^(\w{2})/);
8937: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8938: my ($section,$status);
1.240 albertel 8939: if ($role eq 'cr' &&
8940: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8941: $section=$1;
8942: }
8943: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8944: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8945: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8946: if ($end == -1 && $start == -1) {
8947: next; #deleted role
8948: }
8949: if (!defined($possible_status)) {
8950: $sectioncount{$section}++;
8951: } else {
8952: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8953: $status = 'active';
8954: } elsif ($end < $now) {
8955: $status = 'future';
8956: } elsif ($start > $now) {
8957: $status = 'previous';
8958: }
8959: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8960: $sectioncount{$section}++;
8961: }
8962: }
1.233 raeburn 8963: }
1.366 albertel 8964: return %sectioncount;
1.233 raeburn 8965: }
8966:
1.274 raeburn 8967: ###############################################
1.294 raeburn 8968:
8969: =pod
1.405 albertel 8970:
8971: =item * &get_course_users()
8972:
1.275 raeburn 8973: Retrieves usernames:domains for users in the specified course
8974: with specific role(s), and access status.
8975:
8976: Incoming parameters:
1.277 albertel 8977: 1. course domain
8978: 2. course number
8979: 3. access status: users must have - either active,
1.275 raeburn 8980: previous, future, or all.
1.277 albertel 8981: 4. reference to array of permissible roles
1.288 raeburn 8982: 5. reference to array of section restrictions (optional)
8983: 6. reference to results object (hash of hashes).
8984: 7. reference to optional userdata hash
1.609 raeburn 8985: 8. reference to optional statushash
1.630 raeburn 8986: 9. flag if privileged users (except those set to unhide in
8987: course settings) should be excluded
1.609 raeburn 8988: Keys of top level results hash are roles.
1.275 raeburn 8989: Keys of inner hashes are username:domain, with
8990: values set to access type.
1.288 raeburn 8991: Optional userdata hash returns an array with arguments in the
8992: same order as loncoursedata::get_classlist() for student data.
8993:
1.609 raeburn 8994: Optional statushash returns
8995:
1.288 raeburn 8996: Entries for end, start, section and status are blank because
8997: of the possibility of multiple values for non-student roles.
8998:
1.275 raeburn 8999: =cut
1.405 albertel 9000:
1.275 raeburn 9001: ###############################################
1.405 albertel 9002:
1.275 raeburn 9003: sub get_course_users {
1.630 raeburn 9004: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9005: my %idx = ();
1.419 raeburn 9006: my %seclists;
1.288 raeburn 9007:
9008: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9009: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9010: $idx{end} = &Apache::loncoursedata::CL_END();
9011: $idx{start} = &Apache::loncoursedata::CL_START();
9012: $idx{id} = &Apache::loncoursedata::CL_ID();
9013: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9014: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9015: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9016:
1.290 albertel 9017: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9018: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9019: my $now = time;
1.277 albertel 9020: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9021: my $match = 0;
1.412 raeburn 9022: my $secmatch = 0;
1.419 raeburn 9023: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9024: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9025: if ($section eq '') {
9026: $section = 'none';
9027: }
1.291 albertel 9028: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9029: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9030: $secmatch = 1;
9031: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9032: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9033: $secmatch = 1;
9034: }
9035: } else {
1.419 raeburn 9036: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9037: $secmatch = 1;
9038: }
1.290 albertel 9039: }
1.412 raeburn 9040: if (!$secmatch) {
9041: next;
9042: }
1.419 raeburn 9043: }
1.275 raeburn 9044: if (defined($$types{'active'})) {
1.288 raeburn 9045: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9046: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9047: $match = 1;
1.275 raeburn 9048: }
9049: }
9050: if (defined($$types{'previous'})) {
1.609 raeburn 9051: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9052: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9053: $match = 1;
1.275 raeburn 9054: }
9055: }
9056: if (defined($$types{'future'})) {
1.609 raeburn 9057: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9058: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9059: $match = 1;
1.275 raeburn 9060: }
9061: }
1.609 raeburn 9062: if ($match) {
9063: push(@{$seclists{$student}},$section);
9064: if (ref($userdata) eq 'HASH') {
9065: $$userdata{$student} = $$classlist{$student};
9066: }
9067: if (ref($statushash) eq 'HASH') {
9068: $statushash->{$student}{'st'}{$section} = $status;
9069: }
1.288 raeburn 9070: }
1.275 raeburn 9071: }
9072: }
1.412 raeburn 9073: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9074: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9075: my $now = time;
1.609 raeburn 9076: my %displaystatus = ( previous => 'Expired',
9077: active => 'Active',
9078: future => 'Future',
9079: );
1.1121 raeburn 9080: my (%nothide,@possdoms);
1.630 raeburn 9081: if ($hidepriv) {
9082: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9083: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9084: if ($user !~ /:/) {
9085: $nothide{join(':',split(/[\@]/,$user))}=1;
9086: } else {
9087: $nothide{$user} = 1;
9088: }
9089: }
1.1121 raeburn 9090: my @possdoms = ($cdom);
9091: if ($coursehash{'checkforpriv'}) {
9092: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9093: }
1.630 raeburn 9094: }
1.439 raeburn 9095: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9096: my $match = 0;
1.412 raeburn 9097: my $secmatch = 0;
1.439 raeburn 9098: my $status;
1.412 raeburn 9099: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9100: $user =~ s/:$//;
1.439 raeburn 9101: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9102: if ($end == -1 || $start == -1) {
9103: next;
9104: }
9105: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9106: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9107: my ($uname,$udom) = split(/:/,$user);
9108: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9109: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9110: $secmatch = 1;
9111: } elsif ($usec eq '') {
1.420 albertel 9112: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9113: $secmatch = 1;
9114: }
9115: } else {
9116: if (grep(/^\Q$usec\E$/,@{$sections})) {
9117: $secmatch = 1;
9118: }
9119: }
9120: if (!$secmatch) {
9121: next;
9122: }
1.288 raeburn 9123: }
1.419 raeburn 9124: if ($usec eq '') {
9125: $usec = 'none';
9126: }
1.275 raeburn 9127: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9128: if ($hidepriv) {
1.1121 raeburn 9129: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9130: (!$nothide{$uname.':'.$udom})) {
9131: next;
9132: }
9133: }
1.503 raeburn 9134: if ($end > 0 && $end < $now) {
1.439 raeburn 9135: $status = 'previous';
9136: } elsif ($start > $now) {
9137: $status = 'future';
9138: } else {
9139: $status = 'active';
9140: }
1.277 albertel 9141: foreach my $type (keys(%{$types})) {
1.275 raeburn 9142: if ($status eq $type) {
1.420 albertel 9143: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9144: push(@{$$users{$role}{$user}},$type);
9145: }
1.288 raeburn 9146: $match = 1;
9147: }
9148: }
1.419 raeburn 9149: if (($match) && (ref($userdata) eq 'HASH')) {
9150: if (!exists($$userdata{$uname.':'.$udom})) {
9151: &get_user_info($udom,$uname,\%idx,$userdata);
9152: }
1.420 albertel 9153: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9154: push(@{$seclists{$uname.':'.$udom}},$usec);
9155: }
1.609 raeburn 9156: if (ref($statushash) eq 'HASH') {
9157: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9158: }
1.275 raeburn 9159: }
9160: }
9161: }
9162: }
1.290 albertel 9163: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9164: if ((defined($cdom)) && (defined($cnum))) {
9165: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9166: if ( defined($csettings{'internal.courseowner'}) ) {
9167: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9168: next if ($owner eq '');
9169: my ($ownername,$ownerdom);
9170: if ($owner =~ /^([^:]+):([^:]+)$/) {
9171: $ownername = $1;
9172: $ownerdom = $2;
9173: } else {
9174: $ownername = $owner;
9175: $ownerdom = $cdom;
9176: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9177: }
9178: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9179: if (defined($userdata) &&
1.609 raeburn 9180: !exists($$userdata{$owner})) {
9181: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9182: if (!grep(/^none$/,@{$seclists{$owner}})) {
9183: push(@{$seclists{$owner}},'none');
9184: }
9185: if (ref($statushash) eq 'HASH') {
9186: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9187: }
1.290 albertel 9188: }
1.279 raeburn 9189: }
9190: }
9191: }
1.419 raeburn 9192: foreach my $user (keys(%seclists)) {
9193: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9194: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9195: }
1.275 raeburn 9196: }
9197: return;
9198: }
9199:
1.288 raeburn 9200: sub get_user_info {
9201: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9202: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9203: &plainname($uname,$udom,'lastname');
1.291 albertel 9204: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9205: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9206: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9207: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9208: return;
9209: }
1.275 raeburn 9210:
1.472 raeburn 9211: ###############################################
9212:
9213: =pod
9214:
9215: =item * &get_user_quota()
9216:
1.1134 raeburn 9217: Retrieves quota assigned for storage of user files.
9218: Default is to report quota for portfolio files.
1.472 raeburn 9219:
9220: Incoming parameters:
9221: 1. user's username
9222: 2. user's domain
1.1134 raeburn 9223: 3. quota name - portfolio, author, or course
1.1136 raeburn 9224: (if no quota name provided, defaults to portfolio).
1.1165 raeburn 9225: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1136 raeburn 9226: course
1.472 raeburn 9227:
9228: Returns:
1.1163 raeburn 9229: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9230: 2. (Optional) Type of setting: custom or default
9231: (individually assigned or default for user's
9232: institutional status).
9233: 3. (Optional) - User's institutional status (e.g., faculty, staff
9234: or student - types as defined in localenroll::inst_usertypes
9235: for user's domain, which determines default quota for user.
9236: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9237:
9238: If a value has been stored in the user's environment,
1.536 raeburn 9239: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9240: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9241:
9242: =cut
9243:
9244: ###############################################
9245:
9246:
9247: sub get_user_quota {
1.1136 raeburn 9248: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9249: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9250: if (!defined($udom)) {
9251: $udom = $env{'user.domain'};
9252: }
9253: if (!defined($uname)) {
9254: $uname = $env{'user.name'};
9255: }
9256: if (($udom eq '' || $uname eq '') ||
9257: ($udom eq 'public') && ($uname eq 'public')) {
9258: $quota = 0;
1.536 raeburn 9259: $quotatype = 'default';
9260: $defquota = 0;
1.472 raeburn 9261: } else {
1.536 raeburn 9262: my $inststatus;
1.1134 raeburn 9263: if ($quotaname eq 'course') {
9264: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9265: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9266: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9267: } else {
9268: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9269: $quota = $cenv{'internal.uploadquota'};
9270: }
1.536 raeburn 9271: } else {
1.1134 raeburn 9272: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9273: if ($quotaname eq 'author') {
9274: $quota = $env{'environment.authorquota'};
9275: } else {
9276: $quota = $env{'environment.portfolioquota'};
9277: }
9278: $inststatus = $env{'environment.inststatus'};
9279: } else {
9280: my %userenv =
9281: &Apache::lonnet::get('environment',['portfolioquota',
9282: 'authorquota','inststatus'],$udom,$uname);
9283: my ($tmp) = keys(%userenv);
9284: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9285: if ($quotaname eq 'author') {
9286: $quota = $userenv{'authorquota'};
9287: } else {
9288: $quota = $userenv{'portfolioquota'};
9289: }
9290: $inststatus = $userenv{'inststatus'};
9291: } else {
9292: undef(%userenv);
9293: }
9294: }
9295: }
9296: if ($quota eq '' || wantarray) {
9297: if ($quotaname eq 'course') {
9298: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 9299: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9300: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1136 raeburn 9301: $defquota = $domdefs{$crstype.'quota'};
9302: }
9303: if ($defquota eq '') {
9304: $defquota = 500;
9305: }
1.1134 raeburn 9306: } else {
9307: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9308: }
9309: if ($quota eq '') {
9310: $quota = $defquota;
9311: $quotatype = 'default';
9312: } else {
9313: $quotatype = 'custom';
9314: }
1.472 raeburn 9315: }
9316: }
1.536 raeburn 9317: if (wantarray) {
9318: return ($quota,$quotatype,$settingstatus,$defquota);
9319: } else {
9320: return $quota;
9321: }
1.472 raeburn 9322: }
9323:
9324: ###############################################
9325:
9326: =pod
9327:
9328: =item * &default_quota()
9329:
1.536 raeburn 9330: Retrieves default quota assigned for storage of user portfolio files,
9331: given an (optional) user's institutional status.
1.472 raeburn 9332:
9333: Incoming parameters:
1.1142 raeburn 9334:
1.472 raeburn 9335: 1. domain
1.536 raeburn 9336: 2. (Optional) institutional status(es). This is a : separated list of
9337: status types (e.g., faculty, staff, student etc.)
9338: which apply to the user for whom the default is being retrieved.
9339: If the institutional status string in undefined, the domain
1.1134 raeburn 9340: default quota will be returned.
9341: 3. quota name - portfolio, author, or course
9342: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9343:
9344: Returns:
1.1142 raeburn 9345:
1.1163 raeburn 9346: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9347: 2. (Optional) institutional type which determined the value of the
9348: default quota.
1.472 raeburn 9349:
9350: If a value has been stored in the domain's configuration db,
9351: it will return that, otherwise it returns 20 (for backwards
9352: compatibility with domains which have not set up a configuration
1.1163 raeburn 9353: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9354:
1.536 raeburn 9355: If the user's status includes multiple types (e.g., staff and student),
9356: the largest default quota which applies to the user determines the
9357: default quota returned.
9358:
1.472 raeburn 9359: =cut
9360:
9361: ###############################################
9362:
9363:
9364: sub default_quota {
1.1134 raeburn 9365: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9366: my ($defquota,$settingstatus);
9367: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9368: ['quotas'],$udom);
1.1134 raeburn 9369: my $key = 'defaultquota';
9370: if ($quotaname eq 'author') {
9371: $key = 'authorquota';
9372: }
1.622 raeburn 9373: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9374: if ($inststatus ne '') {
1.765 raeburn 9375: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9376: foreach my $item (@statuses) {
1.1134 raeburn 9377: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9378: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9379: if ($defquota eq '') {
1.1134 raeburn 9380: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9381: $settingstatus = $item;
1.1134 raeburn 9382: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9383: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9384: $settingstatus = $item;
9385: }
9386: }
1.1134 raeburn 9387: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9388: if ($quotahash{'quotas'}{$item} ne '') {
9389: if ($defquota eq '') {
9390: $defquota = $quotahash{'quotas'}{$item};
9391: $settingstatus = $item;
9392: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9393: $defquota = $quotahash{'quotas'}{$item};
9394: $settingstatus = $item;
9395: }
1.536 raeburn 9396: }
9397: }
9398: }
9399: }
9400: if ($defquota eq '') {
1.1134 raeburn 9401: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9402: $defquota = $quotahash{'quotas'}{$key}{'default'};
9403: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9404: $defquota = $quotahash{'quotas'}{'default'};
9405: }
1.536 raeburn 9406: $settingstatus = 'default';
1.1139 raeburn 9407: if ($defquota eq '') {
9408: if ($quotaname eq 'author') {
9409: $defquota = 500;
9410: }
9411: }
1.536 raeburn 9412: }
9413: } else {
9414: $settingstatus = 'default';
1.1134 raeburn 9415: if ($quotaname eq 'author') {
9416: $defquota = 500;
9417: } else {
9418: $defquota = 20;
9419: }
1.536 raeburn 9420: }
9421: if (wantarray) {
9422: return ($defquota,$settingstatus);
1.472 raeburn 9423: } else {
1.536 raeburn 9424: return $defquota;
1.472 raeburn 9425: }
9426: }
9427:
1.1135 raeburn 9428: ###############################################
9429:
9430: =pod
9431:
1.1136 raeburn 9432: =item * &excess_filesize_warning()
1.1135 raeburn 9433:
9434: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 9435: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 9436: space to be exceeded.
1.1136 raeburn 9437:
9438: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 9439: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 9440:
1.1165 raeburn 9441: Inputs: 7
1.1136 raeburn 9442: 1. username or coursenum
1.1135 raeburn 9443: 2. domain
1.1136 raeburn 9444: 3. context ('author' or 'course')
1.1135 raeburn 9445: 4. filename of file for which action is being requested
9446: 5. filesize (kB) of file
9447: 6. action being taken: copy or upload.
1.1165 raeburn 9448: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1135 raeburn 9449:
9450: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 9451: otherwise return null.
9452:
9453: =back
1.1135 raeburn 9454:
9455: =cut
9456:
1.1136 raeburn 9457: sub excess_filesize_warning {
1.1165 raeburn 9458: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 9459: my $current_disk_usage = 0;
1.1165 raeburn 9460: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 9461: if ($context eq 'author') {
9462: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9463: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9464: } else {
9465: foreach my $subdir ('docs','supplemental') {
9466: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9467: }
9468: }
1.1135 raeburn 9469: $disk_quota = int($disk_quota * 1000);
9470: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 9471: return '<p class="LC_warning">'.
1.1135 raeburn 9472: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 9473: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9474: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 9475: $disk_quota,$current_disk_usage).
9476: '</p>';
9477: }
9478: return;
9479: }
9480:
9481: ###############################################
9482:
9483:
1.1136 raeburn 9484:
9485:
1.384 raeburn 9486: sub get_secgrprole_info {
9487: my ($cdom,$cnum,$needroles,$type) = @_;
9488: my %sections_count = &get_sections($cdom,$cnum);
9489: my @sections = (sort {$a <=> $b} keys(%sections_count));
9490: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9491: my @groups = sort(keys(%curr_groups));
9492: my $allroles = [];
9493: my $rolehash;
9494: my $accesshash = {
9495: active => 'Currently has access',
9496: future => 'Will have future access',
9497: previous => 'Previously had access',
9498: };
9499: if ($needroles) {
9500: $rolehash = {'all' => 'all'};
1.385 albertel 9501: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9502: if (&Apache::lonnet::error(%user_roles)) {
9503: undef(%user_roles);
9504: }
9505: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9506: my ($role)=split(/\:/,$item,2);
9507: if ($role eq 'cr') { next; }
9508: if ($role =~ /^cr/) {
9509: $$rolehash{$role} = (split('/',$role))[3];
9510: } else {
9511: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9512: }
9513: }
9514: foreach my $key (sort(keys(%{$rolehash}))) {
9515: push(@{$allroles},$key);
9516: }
9517: push (@{$allroles},'st');
9518: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9519: }
9520: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9521: }
9522:
1.555 raeburn 9523: sub user_picker {
1.994 raeburn 9524: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9525: my $currdom = $dom;
9526: my %curr_selected = (
9527: srchin => 'dom',
1.580 raeburn 9528: srchby => 'lastname',
1.555 raeburn 9529: );
9530: my $srchterm;
1.625 raeburn 9531: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9532: if ($srch->{'srchby'} ne '') {
9533: $curr_selected{'srchby'} = $srch->{'srchby'};
9534: }
9535: if ($srch->{'srchin'} ne '') {
9536: $curr_selected{'srchin'} = $srch->{'srchin'};
9537: }
9538: if ($srch->{'srchtype'} ne '') {
9539: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9540: }
9541: if ($srch->{'srchdomain'} ne '') {
9542: $currdom = $srch->{'srchdomain'};
9543: }
9544: $srchterm = $srch->{'srchterm'};
9545: }
1.1222 damieng 9546: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9547: 'usr' => 'Search criteria',
1.563 raeburn 9548: 'doma' => 'Domain/institution to search',
1.558 albertel 9549: 'uname' => 'username',
9550: 'lastname' => 'last name',
1.555 raeburn 9551: 'lastfirst' => 'last name, first name',
1.558 albertel 9552: 'crs' => 'in this course',
1.576 raeburn 9553: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9554: 'alc' => 'all LON-CAPA',
1.573 raeburn 9555: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9556: 'exact' => 'is',
9557: 'contains' => 'contains',
1.569 raeburn 9558: 'begins' => 'begins with',
1.1222 damieng 9559: );
9560: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9561: 'youm' => "You must include some text to search for.",
9562: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9563: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9564: 'yomc' => "You must choose a domain when using an institutional directory search.",
9565: 'ymcd' => "You must choose a domain when using a domain search.",
9566: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9567: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9568: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9569: );
1.1222 damieng 9570: &html_escape(\%html_lt);
9571: &js_escape(\%js_lt);
1.563 raeburn 9572: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9573: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9574:
9575: my @srchins = ('crs','dom','alc','instd');
9576:
9577: foreach my $option (@srchins) {
9578: # FIXME 'alc' option unavailable until
9579: # loncreateuser::print_user_query_page()
9580: # has been completed.
9581: next if ($option eq 'alc');
1.880 raeburn 9582: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9583: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9584: if ($curr_selected{'srchin'} eq $option) {
9585: $srchinsel .= '
1.1222 damieng 9586: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9587: } else {
9588: $srchinsel .= '
1.1222 damieng 9589: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9590: }
1.555 raeburn 9591: }
1.563 raeburn 9592: $srchinsel .= "\n </select>\n";
1.555 raeburn 9593:
9594: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9595: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9596: if ($curr_selected{'srchby'} eq $option) {
9597: $srchbysel .= '
1.1222 damieng 9598: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9599: } else {
9600: $srchbysel .= '
1.1222 damieng 9601: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9602: }
9603: }
9604: $srchbysel .= "\n </select>\n";
9605:
9606: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9607: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9608: if ($curr_selected{'srchtype'} eq $option) {
9609: $srchtypesel .= '
1.1222 damieng 9610: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9611: } else {
9612: $srchtypesel .= '
1.1222 damieng 9613: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9614: }
9615: }
9616: $srchtypesel .= "\n </select>\n";
9617:
1.558 albertel 9618: my ($newuserscript,$new_user_create);
1.994 raeburn 9619: my $context_dom = $env{'request.role.domain'};
9620: if ($context eq 'requestcrs') {
9621: if ($env{'form.coursedom'} ne '') {
9622: $context_dom = $env{'form.coursedom'};
9623: }
9624: }
1.556 raeburn 9625: if ($forcenewuser) {
1.576 raeburn 9626: if (ref($srch) eq 'HASH') {
1.994 raeburn 9627: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9628: if ($cancreate) {
9629: $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>';
9630: } else {
1.799 bisitz 9631: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9632: my %usertypetext = (
9633: official => 'institutional',
9634: unofficial => 'non-institutional',
9635: );
1.799 bisitz 9636: $new_user_create = '<p class="LC_warning">'
9637: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9638: .' '
9639: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9640: ,'<a href="'.$helplink.'">','</a>')
9641: .'</p><br />';
1.627 raeburn 9642: }
1.576 raeburn 9643: }
9644: }
9645:
1.556 raeburn 9646: $newuserscript = <<"ENDSCRIPT";
9647:
1.570 raeburn 9648: function setSearch(createnew,callingForm) {
1.556 raeburn 9649: if (createnew == 1) {
1.570 raeburn 9650: for (var i=0; i<callingForm.srchby.length; i++) {
9651: if (callingForm.srchby.options[i].value == 'uname') {
9652: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9653: }
9654: }
1.570 raeburn 9655: for (var i=0; i<callingForm.srchin.length; i++) {
9656: if ( callingForm.srchin.options[i].value == 'dom') {
9657: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9658: }
9659: }
1.570 raeburn 9660: for (var i=0; i<callingForm.srchtype.length; i++) {
9661: if (callingForm.srchtype.options[i].value == 'exact') {
9662: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9663: }
9664: }
1.570 raeburn 9665: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9666: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9667: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9668: }
9669: }
9670: }
9671: }
9672: ENDSCRIPT
1.558 albertel 9673:
1.556 raeburn 9674: }
9675:
1.555 raeburn 9676: my $output = <<"END_BLOCK";
1.556 raeburn 9677: <script type="text/javascript">
1.824 bisitz 9678: // <![CDATA[
1.570 raeburn 9679: function validateEntry(callingForm) {
1.558 albertel 9680:
1.556 raeburn 9681: var checkok = 1;
1.558 albertel 9682: var srchin;
1.570 raeburn 9683: for (var i=0; i<callingForm.srchin.length; i++) {
9684: if ( callingForm.srchin[i].checked ) {
9685: srchin = callingForm.srchin[i].value;
1.558 albertel 9686: }
9687: }
9688:
1.570 raeburn 9689: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9690: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9691: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9692: var srchterm = callingForm.srchterm.value;
9693: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9694: var msg = "";
9695:
9696: if (srchterm == "") {
9697: checkok = 0;
1.1222 damieng 9698: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9699: }
9700:
1.569 raeburn 9701: if (srchtype== 'begins') {
9702: if (srchterm.length < 2) {
9703: checkok = 0;
1.1222 damieng 9704: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9705: }
9706: }
9707:
1.556 raeburn 9708: if (srchtype== 'contains') {
9709: if (srchterm.length < 3) {
9710: checkok = 0;
1.1222 damieng 9711: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 9712: }
9713: }
9714: if (srchin == 'instd') {
9715: if (srchdomain == '') {
9716: checkok = 0;
1.1222 damieng 9717: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 9718: }
9719: }
9720: if (srchin == 'dom') {
9721: if (srchdomain == '') {
9722: checkok = 0;
1.1222 damieng 9723: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 9724: }
9725: }
9726: if (srchby == 'lastfirst') {
9727: if (srchterm.indexOf(",") == -1) {
9728: checkok = 0;
1.1222 damieng 9729: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 9730: }
9731: if (srchterm.indexOf(",") == srchterm.length -1) {
9732: checkok = 0;
1.1222 damieng 9733: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 9734: }
9735: }
9736: if (checkok == 0) {
1.1222 damieng 9737: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 9738: return;
9739: }
9740: if (checkok == 1) {
1.570 raeburn 9741: callingForm.submit();
1.556 raeburn 9742: }
9743: }
9744:
9745: $newuserscript
9746:
1.824 bisitz 9747: // ]]>
1.556 raeburn 9748: </script>
1.558 albertel 9749:
9750: $new_user_create
9751:
1.555 raeburn 9752: END_BLOCK
1.558 albertel 9753:
1.876 raeburn 9754: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 9755: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 9756: $domform.
9757: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 9758: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 9759: $srchbysel.
9760: $srchtypesel.
9761: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9762: $srchinsel.
9763: &Apache::lonhtmlcommon::row_closure(1).
9764: &Apache::lonhtmlcommon::end_pick_box().
9765: '<br />';
1.555 raeburn 9766: return $output;
9767: }
9768:
1.612 raeburn 9769: sub user_rule_check {
1.615 raeburn 9770: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 9771: my ($response,%inst_response);
1.612 raeburn 9772: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 9773: if (keys(%{$usershash}) > 1) {
9774: my (%by_username,%by_id,%userdoms);
9775: my $checkid;
9776: if (ref($checks) eq 'HASH') {
9777: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
9778: $checkid = 1;
9779: }
9780: }
9781: foreach my $user (keys(%{$usershash})) {
9782: my ($uname,$udom) = split(/:/,$user);
9783: if ($checkid) {
9784: if (ref($usershash->{$user}) eq 'HASH') {
9785: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 9786: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 9787: $userdoms{$udom} = 1;
1.1227 raeburn 9788: if (ref($inst_results) eq 'HASH') {
9789: $inst_results->{$uname.':'.$udom} = {};
9790: }
1.1226 raeburn 9791: }
9792: }
9793: } else {
9794: $by_username{$udom}{$uname} = 1;
9795: $userdoms{$udom} = 1;
1.1227 raeburn 9796: if (ref($inst_results) eq 'HASH') {
9797: $inst_results->{$uname.':'.$udom} = {};
9798: }
1.1226 raeburn 9799: }
9800: }
9801: foreach my $udom (keys(%userdoms)) {
9802: if (!$got_rules->{$udom}) {
9803: my %domconfig = &Apache::lonnet::get_dom('configuration',
9804: ['usercreation'],$udom);
9805: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9806: foreach my $item ('username','id') {
9807: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 9808: $$curr_rules{$udom}{$item} =
9809: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 9810: }
9811: }
9812: }
9813: $got_rules->{$udom} = 1;
9814: }
1.612 raeburn 9815: }
1.1226 raeburn 9816: if ($checkid) {
9817: foreach my $udom (keys(%by_id)) {
9818: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
9819: if ($outcome eq 'ok') {
1.1227 raeburn 9820: foreach my $id (keys(%{$by_id{$udom}})) {
9821: my $uname = $by_id{$udom}{$id};
9822: $inst_response{$uname.':'.$udom} = $outcome;
9823: }
1.1226 raeburn 9824: if (ref($results) eq 'HASH') {
9825: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 9826: if (exists($inst_response{$uname.':'.$udom})) {
9827: $inst_response{$uname.':'.$udom} = $outcome;
9828: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9829: }
1.1226 raeburn 9830: }
9831: }
9832: }
1.612 raeburn 9833: }
1.615 raeburn 9834: } else {
1.1226 raeburn 9835: foreach my $udom (keys(%by_username)) {
9836: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
9837: if ($outcome eq 'ok') {
1.1227 raeburn 9838: foreach my $uname (keys(%{$by_username{$udom}})) {
9839: $inst_response{$uname.':'.$udom} = $outcome;
9840: }
1.1226 raeburn 9841: if (ref($results) eq 'HASH') {
9842: foreach my $uname (keys(%{$results})) {
9843: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9844: }
9845: }
9846: }
9847: }
1.612 raeburn 9848: }
1.1226 raeburn 9849: } elsif (keys(%{$usershash}) == 1) {
9850: my $user = (keys(%{$usershash}))[0];
9851: my ($uname,$udom) = split(/:/,$user);
9852: if (($udom ne '') && ($uname ne '')) {
9853: if (ref($usershash->{$user}) eq 'HASH') {
9854: if (ref($checks) eq 'HASH') {
9855: if (defined($checks->{'username'})) {
9856: ($inst_response{$user},%{$inst_results->{$user}}) =
9857: &Apache::lonnet::get_instuser($udom,$uname);
9858: } elsif (defined($checks->{'id'})) {
9859: if ($usershash->{$user}->{'id'} ne '') {
9860: ($inst_response{$user},%{$inst_results->{$user}}) =
9861: &Apache::lonnet::get_instuser($udom,undef,
9862: $usershash->{$user}->{'id'});
9863: } else {
9864: ($inst_response{$user},%{$inst_results->{$user}}) =
9865: &Apache::lonnet::get_instuser($udom,$uname);
9866: }
1.585 raeburn 9867: }
1.1226 raeburn 9868: } else {
9869: ($inst_response{$user},%{$inst_results->{$user}}) =
9870: &Apache::lonnet::get_instuser($udom,$uname);
9871: return;
9872: }
9873: if (!$got_rules->{$udom}) {
9874: my %domconfig = &Apache::lonnet::get_dom('configuration',
9875: ['usercreation'],$udom);
9876: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9877: foreach my $item ('username','id') {
9878: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9879: $$curr_rules{$udom}{$item} =
9880: $domconfig{'usercreation'}{$item.'_rule'};
9881: }
9882: }
9883: }
9884: $got_rules->{$udom} = 1;
1.585 raeburn 9885: }
9886: }
1.1226 raeburn 9887: } else {
9888: return;
9889: }
9890: } else {
9891: return;
9892: }
9893: foreach my $user (keys(%{$usershash})) {
9894: my ($uname,$udom) = split(/:/,$user);
9895: next if (($udom eq '') || ($uname eq ''));
9896: my $id;
1.1227 raeburn 9897: if (ref($inst_results) eq 'HASH') {
9898: if (ref($inst_results->{$user}) eq 'HASH') {
9899: $id = $inst_results->{$user}->{'id'};
9900: }
9901: }
9902: if ($id eq '') {
9903: if (ref($usershash->{$user})) {
9904: $id = $usershash->{$user}->{'id'};
9905: }
1.585 raeburn 9906: }
1.612 raeburn 9907: foreach my $item (keys(%{$checks})) {
9908: if (ref($$curr_rules{$udom}) eq 'HASH') {
9909: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9910: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 9911: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
9912: $$curr_rules{$udom}{$item});
1.612 raeburn 9913: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9914: if ($rule_check{$rule}) {
9915: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 9916: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 9917: if (ref($inst_results) eq 'HASH') {
9918: if (ref($inst_results->{$user}) eq 'HASH') {
9919: if (keys(%{$inst_results->{$user}}) == 0) {
9920: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 9921: } elsif ($item eq 'id') {
9922: if ($inst_results->{$user}->{'id'} eq '') {
9923: $$alerts{$item}{$udom}{$uname} = 1;
9924: }
1.615 raeburn 9925: }
1.612 raeburn 9926: }
9927: }
1.615 raeburn 9928: }
9929: last;
1.585 raeburn 9930: }
9931: }
9932: }
9933: }
9934: }
9935: }
9936: }
9937: }
1.612 raeburn 9938: return;
9939: }
9940:
9941: sub user_rule_formats {
9942: my ($domain,$domdesc,$curr_rules,$check) = @_;
9943: my %text = (
9944: 'username' => 'Usernames',
9945: 'id' => 'IDs',
9946: );
9947: my $output;
9948: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9949: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9950: if (@{$ruleorder} > 0) {
1.1102 raeburn 9951: $output = '<br />'.
9952: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9953: '<span class="LC_cusr_emph">','</span>',$domdesc).
9954: ' <ul>';
1.612 raeburn 9955: foreach my $rule (@{$ruleorder}) {
9956: if (ref($curr_rules) eq 'ARRAY') {
9957: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9958: if (ref($rules->{$rule}) eq 'HASH') {
9959: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9960: $rules->{$rule}{'desc'}.'</li>';
9961: }
9962: }
9963: }
9964: }
9965: $output .= '</ul>';
9966: }
9967: }
9968: return $output;
9969: }
9970:
9971: sub instrule_disallow_msg {
1.615 raeburn 9972: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9973: my $response;
9974: my %text = (
9975: item => 'username',
9976: items => 'usernames',
9977: match => 'matches',
9978: do => 'does',
9979: action => 'a username',
9980: one => 'one',
9981: );
9982: if ($count > 1) {
9983: $text{'item'} = 'usernames';
9984: $text{'match'} ='match';
9985: $text{'do'} = 'do';
9986: $text{'action'} = 'usernames',
9987: $text{'one'} = 'ones';
9988: }
9989: if ($checkitem eq 'id') {
9990: $text{'items'} = 'IDs';
9991: $text{'item'} = 'ID';
9992: $text{'action'} = 'an ID';
1.615 raeburn 9993: if ($count > 1) {
9994: $text{'item'} = 'IDs';
9995: $text{'action'} = 'IDs';
9996: }
1.612 raeburn 9997: }
1.674 bisitz 9998: $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 9999: if ($mode eq 'upload') {
10000: if ($checkitem eq 'username') {
10001: $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'}.");
10002: } elsif ($checkitem eq 'id') {
1.674 bisitz 10003: $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 10004: }
1.669 raeburn 10005: } elsif ($mode eq 'selfcreate') {
10006: if ($checkitem eq 'id') {
10007: $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.");
10008: }
1.615 raeburn 10009: } else {
10010: if ($checkitem eq 'username') {
10011: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10012: } elsif ($checkitem eq 'id') {
10013: $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.");
10014: }
1.612 raeburn 10015: }
10016: return $response;
1.585 raeburn 10017: }
10018:
1.624 raeburn 10019: sub personal_data_fieldtitles {
10020: my %fieldtitles = &Apache::lonlocal::texthash (
10021: id => 'Student/Employee ID',
10022: permanentemail => 'E-mail address',
10023: lastname => 'Last Name',
10024: firstname => 'First Name',
10025: middlename => 'Middle Name',
10026: generation => 'Generation',
10027: gen => 'Generation',
1.765 raeburn 10028: inststatus => 'Affiliation',
1.624 raeburn 10029: );
10030: return %fieldtitles;
10031: }
10032:
1.642 raeburn 10033: sub sorted_inst_types {
10034: my ($dom) = @_;
1.1185 raeburn 10035: my ($usertypes,$order);
10036: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10037: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10038: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10039: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10040: } else {
10041: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10042: }
1.642 raeburn 10043: my $othertitle = &mt('All users');
10044: if ($env{'request.course.id'}) {
1.668 raeburn 10045: $othertitle = &mt('Any users');
1.642 raeburn 10046: }
10047: my @types;
10048: if (ref($order) eq 'ARRAY') {
10049: @types = @{$order};
10050: }
10051: if (@types == 0) {
10052: if (ref($usertypes) eq 'HASH') {
10053: @types = sort(keys(%{$usertypes}));
10054: }
10055: }
10056: if (keys(%{$usertypes}) > 0) {
10057: $othertitle = &mt('Other users');
10058: }
10059: return ($othertitle,$usertypes,\@types);
10060: }
10061:
1.645 raeburn 10062: sub get_institutional_codes {
10063: my ($settings,$allcourses,$LC_code) = @_;
10064: # Get complete list of course sections to update
10065: my @currsections = ();
10066: my @currxlists = ();
10067: my $coursecode = $$settings{'internal.coursecode'};
10068:
10069: if ($$settings{'internal.sectionnums'} ne '') {
10070: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10071: }
10072:
10073: if ($$settings{'internal.crosslistings'} ne '') {
10074: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10075: }
10076:
10077: if (@currxlists > 0) {
10078: foreach (@currxlists) {
10079: if (m/^([^:]+):(\w*)$/) {
10080: unless (grep/^$1$/,@{$allcourses}) {
10081: push @{$allcourses},$1;
10082: $$LC_code{$1} = $2;
10083: }
10084: }
10085: }
10086: }
10087:
10088: if (@currsections > 0) {
10089: foreach (@currsections) {
10090: if (m/^(\w+):(\w*)$/) {
10091: my $sec = $coursecode.$1;
10092: my $lc_sec = $2;
10093: unless (grep/^$sec$/,@{$allcourses}) {
10094: push @{$allcourses},$sec;
10095: $$LC_code{$sec} = $lc_sec;
10096: }
10097: }
10098: }
10099: }
10100: return;
10101: }
10102:
1.971 raeburn 10103: sub get_standard_codeitems {
10104: return ('Year','Semester','Department','Number','Section');
10105: }
10106:
1.112 bowersj2 10107: =pod
10108:
1.780 raeburn 10109: =head1 Slot Helpers
10110:
10111: =over 4
10112:
10113: =item * sorted_slots()
10114:
1.1040 raeburn 10115: Sorts an array of slot names in order of an optional sort key,
10116: default sort is by slot start time (earliest first).
1.780 raeburn 10117:
10118: Inputs:
10119:
10120: =over 4
10121:
10122: slotsarr - Reference to array of unsorted slot names.
10123:
10124: slots - Reference to hash of hash, where outer hash keys are slot names.
10125:
1.1040 raeburn 10126: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10127:
1.549 albertel 10128: =back
10129:
1.780 raeburn 10130: Returns:
10131:
10132: =over 4
10133:
1.1040 raeburn 10134: sorted - An array of slot names sorted by a specified sort key
10135: (default sort key is start time of the slot).
1.780 raeburn 10136:
10137: =back
10138:
10139: =cut
10140:
10141:
10142: sub sorted_slots {
1.1040 raeburn 10143: my ($slotsarr,$slots,$sortkey) = @_;
10144: if ($sortkey eq '') {
10145: $sortkey = 'starttime';
10146: }
1.780 raeburn 10147: my @sorted;
10148: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10149: @sorted =
10150: sort {
10151: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10152: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10153: }
10154: if (ref($slots->{$a})) { return -1;}
10155: if (ref($slots->{$b})) { return 1;}
10156: return 0;
10157: } @{$slotsarr};
10158: }
10159: return @sorted;
10160: }
10161:
1.1040 raeburn 10162: =pod
10163:
10164: =item * get_future_slots()
10165:
10166: Inputs:
10167:
10168: =over 4
10169:
10170: cnum - course number
10171:
10172: cdom - course domain
10173:
10174: now - current UNIX time
10175:
10176: symb - optional symb
10177:
10178: =back
10179:
10180: Returns:
10181:
10182: =over 4
10183:
10184: sorted_reservable - ref to array of student_schedulable slots currently
10185: reservable, ordered by end date of reservation period.
10186:
10187: reservable_now - ref to hash of student_schedulable slots currently
10188: reservable.
10189:
10190: Keys in inner hash are:
10191: (a) symb: either blank or symb to which slot use is restricted.
10192: (b) endreserve: end date of reservation period.
10193:
10194: sorted_future - ref to array of student_schedulable slots reservable in
10195: the future, ordered by start date of reservation period.
10196:
10197: future_reservable - ref to hash of student_schedulable slots reservable
10198: in the future.
10199:
10200: Keys in inner hash are:
10201: (a) symb: either blank or symb to which slot use is restricted.
10202: (b) startreserve: start date of reservation period.
10203:
10204: =back
10205:
10206: =cut
10207:
10208: sub get_future_slots {
10209: my ($cnum,$cdom,$now,$symb) = @_;
10210: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10211: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10212: foreach my $slot (keys(%slots)) {
10213: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10214: if ($symb) {
10215: next if (($slots{$slot}->{'symb'} ne '') &&
10216: ($slots{$slot}->{'symb'} ne $symb));
10217: }
10218: if (($slots{$slot}->{'starttime'} > $now) &&
10219: ($slots{$slot}->{'endtime'} > $now)) {
10220: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10221: my $userallowed = 0;
10222: if ($slots{$slot}->{'allowedsections'}) {
10223: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10224: if (!defined($env{'request.role.sec'})
10225: && grep(/^No section assigned$/,@allowed_sec)) {
10226: $userallowed=1;
10227: } else {
10228: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10229: $userallowed=1;
10230: }
10231: }
10232: unless ($userallowed) {
10233: if (defined($env{'request.course.groups'})) {
10234: my @groups = split(/:/,$env{'request.course.groups'});
10235: foreach my $group (@groups) {
10236: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10237: $userallowed=1;
10238: last;
10239: }
10240: }
10241: }
10242: }
10243: }
10244: if ($slots{$slot}->{'allowedusers'}) {
10245: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10246: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10247: if (grep(/^\Q$user\E$/,@allowed_users)) {
10248: $userallowed = 1;
10249: }
10250: }
10251: next unless($userallowed);
10252: }
10253: my $startreserve = $slots{$slot}->{'startreserve'};
10254: my $endreserve = $slots{$slot}->{'endreserve'};
10255: my $symb = $slots{$slot}->{'symb'};
10256: if (($startreserve < $now) &&
10257: (!$endreserve || $endreserve > $now)) {
10258: my $lastres = $endreserve;
10259: if (!$lastres) {
10260: $lastres = $slots{$slot}->{'starttime'};
10261: }
10262: $reservable_now{$slot} = {
10263: symb => $symb,
10264: endreserve => $lastres
10265: };
10266: } elsif (($startreserve > $now) &&
10267: (!$endreserve || $endreserve > $startreserve)) {
10268: $future_reservable{$slot} = {
10269: symb => $symb,
10270: startreserve => $startreserve
10271: };
10272: }
10273: }
10274: }
10275: my @unsorted_reservable = keys(%reservable_now);
10276: if (@unsorted_reservable > 0) {
10277: @sorted_reservable =
10278: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10279: }
10280: my @unsorted_future = keys(%future_reservable);
10281: if (@unsorted_future > 0) {
10282: @sorted_future =
10283: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10284: }
10285: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10286: }
1.780 raeburn 10287:
10288: =pod
10289:
1.1057 foxr 10290: =back
10291:
1.549 albertel 10292: =head1 HTTP Helpers
10293:
10294: =over 4
10295:
1.648 raeburn 10296: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10297:
1.258 albertel 10298: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10299: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10300: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10301:
10302: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10303: $possible_names is an ref to an array of form element names. As an example:
10304: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10305: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10306:
10307: =cut
1.1 albertel 10308:
1.6 albertel 10309: sub get_unprocessed_cgi {
1.25 albertel 10310: my ($query,$possible_names)= @_;
1.26 matthew 10311: # $Apache::lonxml::debug=1;
1.356 albertel 10312: foreach my $pair (split(/&/,$query)) {
10313: my ($name, $value) = split(/=/,$pair);
1.369 www 10314: $name = &unescape($name);
1.25 albertel 10315: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10316: $value =~ tr/+/ /;
10317: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10318: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10319: }
1.16 harris41 10320: }
1.6 albertel 10321: }
10322:
1.112 bowersj2 10323: =pod
10324:
1.648 raeburn 10325: =item * &cacheheader()
1.112 bowersj2 10326:
10327: returns cache-controlling header code
10328:
10329: =cut
10330:
1.7 albertel 10331: sub cacheheader {
1.258 albertel 10332: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10333: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10334: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10335: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10336: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10337: return $output;
1.7 albertel 10338: }
10339:
1.112 bowersj2 10340: =pod
10341:
1.648 raeburn 10342: =item * &no_cache($r)
1.112 bowersj2 10343:
10344: specifies header code to not have cache
10345:
10346: =cut
10347:
1.9 albertel 10348: sub no_cache {
1.216 albertel 10349: my ($r) = @_;
10350: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10351: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10352: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10353: $r->no_cache(1);
10354: $r->header_out("Expires" => $date);
10355: $r->header_out("Pragma" => "no-cache");
1.123 www 10356: }
10357:
10358: sub content_type {
1.181 albertel 10359: my ($r,$type,$charset) = @_;
1.299 foxr 10360: if ($r) {
10361: # Note that printout.pl calls this with undef for $r.
10362: &no_cache($r);
10363: }
1.258 albertel 10364: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10365: unless ($charset) {
10366: $charset=&Apache::lonlocal::current_encoding;
10367: }
10368: if ($charset) { $type.='; charset='.$charset; }
10369: if ($r) {
10370: $r->content_type($type);
10371: } else {
10372: print("Content-type: $type\n\n");
10373: }
1.9 albertel 10374: }
1.25 albertel 10375:
1.112 bowersj2 10376: =pod
10377:
1.648 raeburn 10378: =item * &add_to_env($name,$value)
1.112 bowersj2 10379:
1.258 albertel 10380: adds $name to the %env hash with value
1.112 bowersj2 10381: $value, if $name already exists, the entry is converted to an array
10382: reference and $value is added to the array.
10383:
10384: =cut
10385:
1.25 albertel 10386: sub add_to_env {
10387: my ($name,$value)=@_;
1.258 albertel 10388: if (defined($env{$name})) {
10389: if (ref($env{$name})) {
1.25 albertel 10390: #already have multiple values
1.258 albertel 10391: push(@{ $env{$name} },$value);
1.25 albertel 10392: } else {
10393: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10394: my $first=$env{$name};
10395: undef($env{$name});
10396: push(@{ $env{$name} },$first,$value);
1.25 albertel 10397: }
10398: } else {
1.258 albertel 10399: $env{$name}=$value;
1.25 albertel 10400: }
1.31 albertel 10401: }
1.149 albertel 10402:
10403: =pod
10404:
1.648 raeburn 10405: =item * &get_env_multiple($name)
1.149 albertel 10406:
1.258 albertel 10407: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10408: values may be defined and end up as an array ref.
10409:
10410: returns an array of values
10411:
10412: =cut
10413:
10414: sub get_env_multiple {
10415: my ($name) = @_;
10416: my @values;
1.258 albertel 10417: if (defined($env{$name})) {
1.149 albertel 10418: # exists is it an array
1.258 albertel 10419: if (ref($env{$name})) {
10420: @values=@{ $env{$name} };
1.149 albertel 10421: } else {
1.258 albertel 10422: $values[0]=$env{$name};
1.149 albertel 10423: }
10424: }
10425: return(@values);
10426: }
10427:
1.660 raeburn 10428: sub ask_for_embedded_content {
10429: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10430: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 10431: %currsubfile,%unused,$rem);
1.1071 raeburn 10432: my $counter = 0;
10433: my $numnew = 0;
1.987 raeburn 10434: my $numremref = 0;
10435: my $numinvalid = 0;
10436: my $numpathchg = 0;
10437: my $numexisting = 0;
1.1071 raeburn 10438: my $numunused = 0;
10439: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 10440: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10441: my $heading = &mt('Upload embedded files');
10442: my $buttontext = &mt('Upload');
10443:
1.1085 raeburn 10444: if ($env{'request.course.id'}) {
1.1123 raeburn 10445: if ($actionurl eq '/adm/dependencies') {
10446: $navmap = Apache::lonnavmaps::navmap->new();
10447: }
10448: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10449: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 10450: }
1.1123 raeburn 10451: if (($actionurl eq '/adm/portfolio') ||
10452: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10453: my $current_path='/';
10454: if ($env{'form.currentpath'}) {
10455: $current_path = $env{'form.currentpath'};
10456: }
10457: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 10458: $udom = $cdom;
10459: $uname = $cnum;
1.984 raeburn 10460: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10461: } else {
10462: $udom = $env{'user.domain'};
10463: $uname = $env{'user.name'};
10464: $url = '/userfiles/portfolio';
10465: }
1.987 raeburn 10466: $toplevel = $url.'/';
1.984 raeburn 10467: $url .= $current_path;
10468: $getpropath = 1;
1.987 raeburn 10469: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10470: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10471: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10472: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10473: $toplevel = $url;
1.984 raeburn 10474: if ($rest ne '') {
1.987 raeburn 10475: $url .= $rest;
10476: }
10477: } elsif ($actionurl eq '/adm/coursedocs') {
10478: if (ref($args) eq 'HASH') {
1.1071 raeburn 10479: $url = $args->{'docs_url'};
10480: $toplevel = $url;
1.1084 raeburn 10481: if ($args->{'context'} eq 'paste') {
10482: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10483: ($path) =
10484: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10485: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10486: $fileloc =~ s{^/}{};
10487: }
1.1071 raeburn 10488: }
1.1084 raeburn 10489: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 10490: if ($env{'request.course.id'} ne '') {
10491: if (ref($args) eq 'HASH') {
10492: $url = $args->{'docs_url'};
10493: $title = $args->{'docs_title'};
1.1126 raeburn 10494: $toplevel = $url;
10495: unless ($toplevel =~ m{^/}) {
10496: $toplevel = "/$url";
10497: }
1.1085 raeburn 10498: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 10499: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10500: $path = $1;
10501: } else {
10502: ($path) =
10503: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10504: }
1.1195 raeburn 10505: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10506: $fileloc = $toplevel;
10507: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10508: my ($udom,$uname,$fname) =
10509: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10510: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10511: } else {
10512: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10513: }
1.1071 raeburn 10514: $fileloc =~ s{^/}{};
10515: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10516: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10517: }
1.987 raeburn 10518: }
1.1123 raeburn 10519: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10520: $udom = $cdom;
10521: $uname = $cnum;
10522: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10523: $toplevel = $url;
10524: $path = $url;
10525: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10526: $fileloc =~ s{^/}{};
1.987 raeburn 10527: }
1.1126 raeburn 10528: foreach my $file (keys(%{$allfiles})) {
10529: my $embed_file;
10530: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10531: $embed_file = $1;
10532: } else {
10533: $embed_file = $file;
10534: }
1.1158 raeburn 10535: my ($absolutepath,$cleaned_file);
10536: if ($embed_file =~ m{^\w+://}) {
10537: $cleaned_file = $embed_file;
1.1147 raeburn 10538: $newfiles{$cleaned_file} = 1;
10539: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10540: } else {
1.1158 raeburn 10541: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10542: if ($embed_file =~ m{^/}) {
10543: $absolutepath = $embed_file;
10544: }
1.1147 raeburn 10545: if ($cleaned_file =~ m{/}) {
10546: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10547: $path = &check_for_traversal($path,$url,$toplevel);
10548: my $item = $fname;
10549: if ($path ne '') {
10550: $item = $path.'/'.$fname;
10551: $subdependencies{$path}{$fname} = 1;
10552: } else {
10553: $dependencies{$item} = 1;
10554: }
10555: if ($absolutepath) {
10556: $mapping{$item} = $absolutepath;
10557: } else {
10558: $mapping{$item} = $embed_file;
10559: }
10560: } else {
10561: $dependencies{$embed_file} = 1;
10562: if ($absolutepath) {
1.1147 raeburn 10563: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10564: } else {
1.1147 raeburn 10565: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10566: }
10567: }
1.984 raeburn 10568: }
10569: }
1.1071 raeburn 10570: my $dirptr = 16384;
1.984 raeburn 10571: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10572: $currsubfile{$path} = {};
1.1123 raeburn 10573: if (($actionurl eq '/adm/portfolio') ||
10574: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10575: my ($sublistref,$listerror) =
10576: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10577: if (ref($sublistref) eq 'ARRAY') {
10578: foreach my $line (@{$sublistref}) {
10579: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10580: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10581: }
1.984 raeburn 10582: }
1.987 raeburn 10583: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10584: if (opendir(my $dir,$url.'/'.$path)) {
10585: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10586: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10587: }
1.1084 raeburn 10588: } elsif (($actionurl eq '/adm/dependencies') ||
10589: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 10590: ($args->{'context'} eq 'paste')) ||
10591: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10592: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 10593: my $dir;
10594: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10595: $dir = $fileloc;
10596: } else {
10597: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10598: }
1.1071 raeburn 10599: if ($dir ne '') {
10600: my ($sublistref,$listerror) =
10601: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10602: if (ref($sublistref) eq 'ARRAY') {
10603: foreach my $line (@{$sublistref}) {
10604: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10605: undef,$mtime)=split(/\&/,$line,12);
10606: unless (($testdir&$dirptr) ||
10607: ($file_name =~ /^\.\.?$/)) {
10608: $currsubfile{$path}{$file_name} = [$size,$mtime];
10609: }
10610: }
10611: }
10612: }
1.984 raeburn 10613: }
10614: }
10615: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10616: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10617: my $item = $path.'/'.$file;
10618: unless ($mapping{$item} eq $item) {
10619: $pathchanges{$item} = 1;
10620: }
10621: $existing{$item} = 1;
10622: $numexisting ++;
10623: } else {
10624: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10625: }
10626: }
1.1071 raeburn 10627: if ($actionurl eq '/adm/dependencies') {
10628: foreach my $path (keys(%currsubfile)) {
10629: if (ref($currsubfile{$path}) eq 'HASH') {
10630: foreach my $file (keys(%{$currsubfile{$path}})) {
10631: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 10632: next if (($rem ne '') &&
10633: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10634: (ref($navmap) &&
10635: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10636: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10637: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10638: $unused{$path.'/'.$file} = 1;
10639: }
10640: }
10641: }
10642: }
10643: }
1.984 raeburn 10644: }
1.987 raeburn 10645: my %currfile;
1.1123 raeburn 10646: if (($actionurl eq '/adm/portfolio') ||
10647: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10648: my ($dirlistref,$listerror) =
10649: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10650: if (ref($dirlistref) eq 'ARRAY') {
10651: foreach my $line (@{$dirlistref}) {
10652: my ($file_name,$rest) = split(/\&/,$line,2);
10653: $currfile{$file_name} = 1;
10654: }
1.984 raeburn 10655: }
1.987 raeburn 10656: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10657: if (opendir(my $dir,$url)) {
1.987 raeburn 10658: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10659: map {$currfile{$_} = 1;} @dir_list;
10660: }
1.1084 raeburn 10661: } elsif (($actionurl eq '/adm/dependencies') ||
10662: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 10663: ($args->{'context'} eq 'paste')) ||
10664: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10665: if ($env{'request.course.id'} ne '') {
10666: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10667: if ($dir ne '') {
10668: my ($dirlistref,$listerror) =
10669: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10670: if (ref($dirlistref) eq 'ARRAY') {
10671: foreach my $line (@{$dirlistref}) {
10672: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10673: $size,undef,$mtime)=split(/\&/,$line,12);
10674: unless (($testdir&$dirptr) ||
10675: ($file_name =~ /^\.\.?$/)) {
10676: $currfile{$file_name} = [$size,$mtime];
10677: }
10678: }
10679: }
10680: }
10681: }
1.984 raeburn 10682: }
10683: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10684: if (exists($currfile{$file})) {
1.987 raeburn 10685: unless ($mapping{$file} eq $file) {
10686: $pathchanges{$file} = 1;
10687: }
10688: $existing{$file} = 1;
10689: $numexisting ++;
10690: } else {
1.984 raeburn 10691: $newfiles{$file} = 1;
10692: }
10693: }
1.1071 raeburn 10694: foreach my $file (keys(%currfile)) {
10695: unless (($file eq $filename) ||
10696: ($file eq $filename.'.bak') ||
10697: ($dependencies{$file})) {
1.1085 raeburn 10698: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 10699: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10700: next if (($rem ne '') &&
10701: (($env{"httpref.$rem".$file} ne '') ||
10702: (ref($navmap) &&
10703: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10704: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10705: ($navmap->getResourceByUrl($rem.$1)))))));
10706: }
1.1085 raeburn 10707: }
1.1071 raeburn 10708: $unused{$file} = 1;
10709: }
10710: }
1.1084 raeburn 10711: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10712: ($args->{'context'} eq 'paste')) {
10713: $counter = scalar(keys(%existing));
10714: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 10715: return ($output,$counter,$numpathchg,\%existing);
10716: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10717: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10718: $counter = scalar(keys(%existing));
10719: $numpathchg = scalar(keys(%pathchanges));
10720: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 10721: }
1.984 raeburn 10722: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10723: if ($actionurl eq '/adm/dependencies') {
10724: next if ($embed_file =~ m{^\w+://});
10725: }
1.660 raeburn 10726: $upload_output .= &start_data_table_row().
1.1123 raeburn 10727: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10728: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10729: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 10730: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10731: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10732: }
1.1123 raeburn 10733: $upload_output .= '</td>';
1.1071 raeburn 10734: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 10735: $upload_output.='<td align="right">'.
10736: '<span class="LC_info LC_fontsize_medium">'.
10737: &mt("URL points to web address").'</span>';
1.987 raeburn 10738: $numremref++;
1.660 raeburn 10739: } elsif ($args->{'error_on_invalid_names'}
10740: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 10741: $upload_output.='<td align="right"><span class="LC_warning">'.
10742: &mt('Invalid characters').'</span>';
1.987 raeburn 10743: $numinvalid++;
1.660 raeburn 10744: } else {
1.1123 raeburn 10745: $upload_output .= '<td>'.
10746: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10747: $embed_file,\%mapping,
1.1071 raeburn 10748: $allfiles,$codebase,'upload');
10749: $counter ++;
10750: $numnew ++;
1.987 raeburn 10751: }
10752: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10753: }
10754: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10755: if ($actionurl eq '/adm/dependencies') {
10756: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10757: $modify_output .= &start_data_table_row().
10758: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10759: '<img src="'.&icon($embed_file).'" border="0" />'.
10760: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10761: '<td>'.$size.'</td>'.
10762: '<td>'.$mtime.'</td>'.
10763: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10764: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10765: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10766: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10767: &embedded_file_element('upload_embedded',$counter,
10768: $embed_file,\%mapping,
10769: $allfiles,$codebase,'modify').
10770: '</div></td>'.
10771: &end_data_table_row()."\n";
10772: $counter ++;
10773: } else {
10774: $upload_output .= &start_data_table_row().
1.1123 raeburn 10775: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10776: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10777: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10778: &Apache::loncommon::end_data_table_row()."\n";
10779: }
10780: }
10781: my $delidx = $counter;
10782: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10783: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10784: $delete_output .= &start_data_table_row().
10785: '<td><img src="'.&icon($oldfile).'" />'.
10786: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10787: '<td>'.$size.'</td>'.
10788: '<td>'.$mtime.'</td>'.
10789: '<td><label><input type="checkbox" name="del_upload_dep" '.
10790: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10791: &embedded_file_element('upload_embedded',$delidx,
10792: $oldfile,\%mapping,$allfiles,
10793: $codebase,'delete').'</td>'.
10794: &end_data_table_row()."\n";
10795: $numunused ++;
10796: $delidx ++;
1.987 raeburn 10797: }
10798: if ($upload_output) {
10799: $upload_output = &start_data_table().
10800: $upload_output.
10801: &end_data_table()."\n";
10802: }
1.1071 raeburn 10803: if ($modify_output) {
10804: $modify_output = &start_data_table().
10805: &start_data_table_header_row().
10806: '<th>'.&mt('File').'</th>'.
10807: '<th>'.&mt('Size (KB)').'</th>'.
10808: '<th>'.&mt('Modified').'</th>'.
10809: '<th>'.&mt('Upload replacement?').'</th>'.
10810: &end_data_table_header_row().
10811: $modify_output.
10812: &end_data_table()."\n";
10813: }
10814: if ($delete_output) {
10815: $delete_output = &start_data_table().
10816: &start_data_table_header_row().
10817: '<th>'.&mt('File').'</th>'.
10818: '<th>'.&mt('Size (KB)').'</th>'.
10819: '<th>'.&mt('Modified').'</th>'.
10820: '<th>'.&mt('Delete?').'</th>'.
10821: &end_data_table_header_row().
10822: $delete_output.
10823: &end_data_table()."\n";
10824: }
1.987 raeburn 10825: my $applies = 0;
10826: if ($numremref) {
10827: $applies ++;
10828: }
10829: if ($numinvalid) {
10830: $applies ++;
10831: }
10832: if ($numexisting) {
10833: $applies ++;
10834: }
1.1071 raeburn 10835: if ($counter || $numunused) {
1.987 raeburn 10836: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10837: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10838: $state.'<h3>'.$heading.'</h3>';
10839: if ($actionurl eq '/adm/dependencies') {
10840: if ($numnew) {
10841: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10842: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10843: $upload_output.'<br />'."\n";
10844: }
10845: if ($numexisting) {
10846: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10847: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10848: $modify_output.'<br />'."\n";
10849: $buttontext = &mt('Save changes');
10850: }
10851: if ($numunused) {
10852: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10853: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10854: $delete_output.'<br />'."\n";
10855: $buttontext = &mt('Save changes');
10856: }
10857: } else {
10858: $output .= $upload_output.'<br />'."\n";
10859: }
10860: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10861: $counter.'" />'."\n";
10862: if ($actionurl eq '/adm/dependencies') {
10863: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10864: $numnew.'" />'."\n";
10865: } elsif ($actionurl eq '') {
1.987 raeburn 10866: $output .= '<input type="hidden" name="phase" value="three" />';
10867: }
10868: } elsif ($applies) {
10869: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10870: if ($applies > 1) {
10871: $output .=
1.1123 raeburn 10872: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10873: if ($numremref) {
10874: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10875: }
10876: if ($numinvalid) {
10877: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10878: }
10879: if ($numexisting) {
10880: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10881: }
10882: $output .= '</ul><br />';
10883: } elsif ($numremref) {
10884: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10885: } elsif ($numinvalid) {
10886: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10887: } elsif ($numexisting) {
10888: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10889: }
10890: $output .= $upload_output.'<br />';
10891: }
10892: my ($pathchange_output,$chgcount);
1.1071 raeburn 10893: $chgcount = $counter;
1.987 raeburn 10894: if (keys(%pathchanges) > 0) {
10895: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10896: if ($counter) {
1.987 raeburn 10897: $output .= &embedded_file_element('pathchange',$chgcount,
10898: $embed_file,\%mapping,
1.1071 raeburn 10899: $allfiles,$codebase,'change');
1.987 raeburn 10900: } else {
10901: $pathchange_output .=
10902: &start_data_table_row().
10903: '<td><input type ="checkbox" name="namechange" value="'.
10904: $chgcount.'" checked="checked" /></td>'.
10905: '<td>'.$mapping{$embed_file}.'</td>'.
10906: '<td>'.$embed_file.
10907: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10908: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10909: '</td>'.&end_data_table_row();
1.660 raeburn 10910: }
1.987 raeburn 10911: $numpathchg ++;
10912: $chgcount ++;
1.660 raeburn 10913: }
10914: }
1.1127 raeburn 10915: if (($counter) || ($numunused)) {
1.987 raeburn 10916: if ($numpathchg) {
10917: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10918: $numpathchg.'" />'."\n";
10919: }
10920: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10921: ($actionurl eq '/adm/imsimport')) {
10922: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10923: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10924: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10925: } elsif ($actionurl eq '/adm/dependencies') {
10926: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10927: }
1.1123 raeburn 10928: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10929: } elsif ($numpathchg) {
10930: my %pathchange = ();
10931: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10932: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10933: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 10934: }
1.987 raeburn 10935: }
1.1071 raeburn 10936: return ($output,$counter,$numpathchg);
1.987 raeburn 10937: }
10938:
1.1147 raeburn 10939: =pod
10940:
10941: =item * clean_path($name)
10942:
10943: Performs clean-up of directories, subdirectories and filename in an
10944: embedded object, referenced in an HTML file which is being uploaded
10945: to a course or portfolio, where
10946: "Upload embedded images/multimedia files if HTML file" checkbox was
10947: checked.
10948:
10949: Clean-up is similar to replacements in lonnet::clean_filename()
10950: except each / between sub-directory and next level is preserved.
10951:
10952: =cut
10953:
10954: sub clean_path {
10955: my ($embed_file) = @_;
10956: $embed_file =~s{^/+}{};
10957: my @contents;
10958: if ($embed_file =~ m{/}) {
10959: @contents = split(/\//,$embed_file);
10960: } else {
10961: @contents = ($embed_file);
10962: }
10963: my $lastidx = scalar(@contents)-1;
10964: for (my $i=0; $i<=$lastidx; $i++) {
10965: $contents[$i]=~s{\\}{/}g;
10966: $contents[$i]=~s/\s+/\_/g;
10967: $contents[$i]=~s{[^/\w\.\-]}{}g;
10968: if ($i == $lastidx) {
10969: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10970: }
10971: }
10972: if ($lastidx > 0) {
10973: return join('/',@contents);
10974: } else {
10975: return $contents[0];
10976: }
10977: }
10978:
1.987 raeburn 10979: sub embedded_file_element {
1.1071 raeburn 10980: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10981: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10982: (ref($codebase) eq 'HASH'));
10983: my $output;
1.1071 raeburn 10984: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10985: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10986: }
10987: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10988: &escape($embed_file).'" />';
10989: unless (($context eq 'upload_embedded') &&
10990: ($mapping->{$embed_file} eq $embed_file)) {
10991: $output .='
10992: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10993: }
10994: my $attrib;
10995: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10996: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10997: }
10998: $output .=
10999: "\n\t\t".
11000: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11001: $attrib.'" />';
11002: if (exists($codebase->{$mapping->{$embed_file}})) {
11003: $output .=
11004: "\n\t\t".
11005: '<input name="codebase_'.$num.'" type="hidden" value="'.
11006: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11007: }
1.987 raeburn 11008: return $output;
1.660 raeburn 11009: }
11010:
1.1071 raeburn 11011: sub get_dependency_details {
11012: my ($currfile,$currsubfile,$embed_file) = @_;
11013: my ($size,$mtime,$showsize,$showmtime);
11014: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11015: if ($embed_file =~ m{/}) {
11016: my ($path,$fname) = split(/\//,$embed_file);
11017: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11018: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11019: }
11020: } else {
11021: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11022: ($size,$mtime) = @{$currfile->{$embed_file}};
11023: }
11024: }
11025: $showsize = $size/1024.0;
11026: $showsize = sprintf("%.1f",$showsize);
11027: if ($mtime > 0) {
11028: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11029: }
11030: }
11031: return ($showsize,$showmtime);
11032: }
11033:
11034: sub ask_embedded_js {
11035: return <<"END";
11036: <script type="text/javascript"">
11037: // <![CDATA[
11038: function toggleBrowse(counter) {
11039: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11040: var fileid = document.getElementById('embedded_item_'+counter);
11041: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11042: if (chkboxid.checked == true) {
11043: uploaddivid.style.display='block';
11044: } else {
11045: uploaddivid.style.display='none';
11046: fileid.value = '';
11047: }
11048: }
11049: // ]]>
11050: </script>
11051:
11052: END
11053: }
11054:
1.661 raeburn 11055: sub upload_embedded {
11056: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11057: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11058: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11059: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11060: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11061: my $orig_uploaded_filename =
11062: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11063: foreach my $type ('orig','ref','attrib','codebase') {
11064: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11065: $env{'form.embedded_'.$type.'_'.$i} =
11066: &unescape($env{'form.embedded_'.$type.'_'.$i});
11067: }
11068: }
1.661 raeburn 11069: my ($path,$fname) =
11070: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11071: # no path, whole string is fname
11072: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11073: $fname = &Apache::lonnet::clean_filename($fname);
11074: # See if there is anything left
11075: next if ($fname eq '');
11076:
11077: # Check if file already exists as a file or directory.
11078: my ($state,$msg);
11079: if ($context eq 'portfolio') {
11080: my $port_path = $dirpath;
11081: if ($group ne '') {
11082: $port_path = "groups/$group/$port_path";
11083: }
1.987 raeburn 11084: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11085: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11086: $dir_root,$port_path,$disk_quota,
11087: $current_disk_usage,$uname,$udom);
11088: if ($state eq 'will_exceed_quota'
1.984 raeburn 11089: || $state eq 'file_locked') {
1.661 raeburn 11090: $output .= $msg;
11091: next;
11092: }
11093: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11094: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11095: if ($state eq 'exists') {
11096: $output .= $msg;
11097: next;
11098: }
11099: }
11100: # Check if extension is valid
11101: if (($fname =~ /\.(\w+)$/) &&
11102: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11103: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11104: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11105: next;
11106: } elsif (($fname =~ /\.(\w+)$/) &&
11107: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11108: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11109: next;
11110: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11111: $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 11112: next;
11113: }
11114: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11115: my $subdir = $path;
11116: $subdir =~ s{/+$}{};
1.661 raeburn 11117: if ($context eq 'portfolio') {
1.984 raeburn 11118: my $result;
11119: if ($state eq 'existingfile') {
11120: $result=
11121: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11122: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11123: } else {
1.984 raeburn 11124: $result=
11125: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11126: $dirpath.
1.1123 raeburn 11127: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11128: if ($result !~ m|^/uploaded/|) {
11129: $output .= '<span class="LC_error">'
11130: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11131: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11132: .'</span><br />';
11133: next;
11134: } else {
1.987 raeburn 11135: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11136: $path.$fname.'</span>').'<br />';
1.984 raeburn 11137: }
1.661 raeburn 11138: }
1.1123 raeburn 11139: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 11140: my $extendedsubdir = $dirpath.'/'.$subdir;
11141: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11142: my $result =
1.1126 raeburn 11143: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11144: if ($result !~ m|^/uploaded/|) {
11145: $output .= '<span class="LC_error">'
11146: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11147: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11148: .'</span><br />';
11149: next;
11150: } else {
11151: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11152: $path.$fname.'</span>').'<br />';
1.1125 raeburn 11153: if ($context eq 'syllabus') {
11154: &Apache::lonnet::make_public_indefinitely($result);
11155: }
1.987 raeburn 11156: }
1.661 raeburn 11157: } else {
11158: # Save the file
11159: my $target = $env{'form.embedded_item_'.$i};
11160: my $fullpath = $dir_root.$dirpath.'/'.$path;
11161: my $dest = $fullpath.$fname;
11162: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11163: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11164: my $count;
11165: my $filepath = $dir_root;
1.1027 raeburn 11166: foreach my $subdir (@parts) {
11167: $filepath .= "/$subdir";
11168: if (!-e $filepath) {
1.661 raeburn 11169: mkdir($filepath,0770);
11170: }
11171: }
11172: my $fh;
11173: if (!open($fh,'>'.$dest)) {
11174: &Apache::lonnet::logthis('Failed to create '.$dest);
11175: $output .= '<span class="LC_error">'.
1.1071 raeburn 11176: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11177: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11178: '</span><br />';
11179: } else {
11180: if (!print $fh $env{'form.embedded_item_'.$i}) {
11181: &Apache::lonnet::logthis('Failed to write to '.$dest);
11182: $output .= '<span class="LC_error">'.
1.1071 raeburn 11183: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11184: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11185: '</span><br />';
11186: } else {
1.987 raeburn 11187: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11188: $url.'</span>').'<br />';
11189: unless ($context eq 'testbank') {
11190: $footer .= &mt('View embedded file: [_1]',
11191: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11192: }
11193: }
11194: close($fh);
11195: }
11196: }
11197: if ($env{'form.embedded_ref_'.$i}) {
11198: $pathchange{$i} = 1;
11199: }
11200: }
11201: if ($output) {
11202: $output = '<p>'.$output.'</p>';
11203: }
11204: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11205: $returnflag = 'ok';
1.1071 raeburn 11206: my $numpathchgs = scalar(keys(%pathchange));
11207: if ($numpathchgs > 0) {
1.987 raeburn 11208: if ($context eq 'portfolio') {
11209: $output .= '<p>'.&mt('or').'</p>';
11210: } elsif ($context eq 'testbank') {
1.1071 raeburn 11211: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11212: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11213: $returnflag = 'modify_orightml';
11214: }
11215: }
1.1071 raeburn 11216: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11217: }
11218:
11219: sub modify_html_form {
11220: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11221: my $end = 0;
11222: my $modifyform;
11223: if ($context eq 'upload_embedded') {
11224: return unless (ref($pathchange) eq 'HASH');
11225: if ($env{'form.number_embedded_items'}) {
11226: $end += $env{'form.number_embedded_items'};
11227: }
11228: if ($env{'form.number_pathchange_items'}) {
11229: $end += $env{'form.number_pathchange_items'};
11230: }
11231: if ($end) {
11232: for (my $i=0; $i<$end; $i++) {
11233: if ($i < $env{'form.number_embedded_items'}) {
11234: next unless($pathchange->{$i});
11235: }
11236: $modifyform .=
11237: &start_data_table_row().
11238: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11239: 'checked="checked" /></td>'.
11240: '<td>'.$env{'form.embedded_ref_'.$i}.
11241: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11242: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11243: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11244: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11245: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11246: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11247: '<td>'.$env{'form.embedded_orig_'.$i}.
11248: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11249: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11250: &end_data_table_row();
1.1071 raeburn 11251: }
1.987 raeburn 11252: }
11253: } else {
11254: $modifyform = $pathchgtable;
11255: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11256: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11257: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11258: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11259: }
11260: }
11261: if ($modifyform) {
1.1071 raeburn 11262: if ($actionurl eq '/adm/dependencies') {
11263: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11264: }
1.987 raeburn 11265: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11266: '<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".
11267: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11268: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11269: '</ol></p>'."\n".'<p>'.
11270: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11271: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11272: &start_data_table()."\n".
11273: &start_data_table_header_row().
11274: '<th>'.&mt('Change?').'</th>'.
11275: '<th>'.&mt('Current reference').'</th>'.
11276: '<th>'.&mt('Required reference').'</th>'.
11277: &end_data_table_header_row()."\n".
11278: $modifyform.
11279: &end_data_table().'<br />'."\n".$hiddenstate.
11280: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11281: '</form>'."\n";
11282: }
11283: return;
11284: }
11285:
11286: sub modify_html_refs {
1.1123 raeburn 11287: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11288: my $container;
11289: if ($context eq 'portfolio') {
11290: $container = $env{'form.container'};
11291: } elsif ($context eq 'coursedoc') {
11292: $container = $env{'form.primaryurl'};
1.1071 raeburn 11293: } elsif ($context eq 'manage_dependencies') {
11294: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11295: $container = "/$container";
1.1123 raeburn 11296: } elsif ($context eq 'syllabus') {
11297: $container = $url;
1.987 raeburn 11298: } else {
1.1027 raeburn 11299: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11300: }
11301: my (%allfiles,%codebase,$output,$content);
11302: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 11303: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11304: if (wantarray) {
11305: return ('',0,0);
11306: } else {
11307: return;
11308: }
11309: }
11310: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11311: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11312: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11313: if (wantarray) {
11314: return ('',0,0);
11315: } else {
11316: return;
11317: }
11318: }
1.987 raeburn 11319: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11320: if ($content eq '-1') {
11321: if (wantarray) {
11322: return ('',0,0);
11323: } else {
11324: return;
11325: }
11326: }
1.987 raeburn 11327: } else {
1.1071 raeburn 11328: unless ($container =~ /^\Q$dir_root\E/) {
11329: if (wantarray) {
11330: return ('',0,0);
11331: } else {
11332: return;
11333: }
11334: }
1.987 raeburn 11335: if (open(my $fh,"<$container")) {
11336: $content = join('', <$fh>);
11337: close($fh);
11338: } else {
1.1071 raeburn 11339: if (wantarray) {
11340: return ('',0,0);
11341: } else {
11342: return;
11343: }
1.987 raeburn 11344: }
11345: }
11346: my ($count,$codebasecount) = (0,0);
11347: my $mm = new File::MMagic;
11348: my $mime_type = $mm->checktype_contents($content);
11349: if ($mime_type eq 'text/html') {
11350: my $parse_result =
11351: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11352: \%codebase,\$content);
11353: if ($parse_result eq 'ok') {
11354: foreach my $i (@changes) {
11355: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11356: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11357: if ($allfiles{$ref}) {
11358: my $newname = $orig;
11359: my ($attrib_regexp,$codebase);
1.1006 raeburn 11360: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11361: if ($attrib_regexp =~ /:/) {
11362: $attrib_regexp =~ s/\:/|/g;
11363: }
11364: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11365: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11366: $count += $numchg;
1.1123 raeburn 11367: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 11368: delete($allfiles{$ref});
1.987 raeburn 11369: }
11370: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11371: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11372: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11373: $codebasecount ++;
11374: }
11375: }
11376: }
1.1123 raeburn 11377: my $skiprewrites;
1.987 raeburn 11378: if ($count || $codebasecount) {
11379: my $saveresult;
1.1071 raeburn 11380: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11381: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11382: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11383: if ($url eq $container) {
11384: my ($fname) = ($container =~ m{/([^/]+)$});
11385: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11386: $count,'<span class="LC_filename">'.
1.1071 raeburn 11387: $fname.'</span>').'</p>';
1.987 raeburn 11388: } else {
11389: $output = '<p class="LC_error">'.
11390: &mt('Error: update failed for: [_1].',
11391: '<span class="LC_filename">'.
11392: $container.'</span>').'</p>';
11393: }
1.1123 raeburn 11394: if ($context eq 'syllabus') {
11395: unless ($saveresult eq 'ok') {
11396: $skiprewrites = 1;
11397: }
11398: }
1.987 raeburn 11399: } else {
11400: if (open(my $fh,">$container")) {
11401: print $fh $content;
11402: close($fh);
11403: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11404: $count,'<span class="LC_filename">'.
11405: $container.'</span>').'</p>';
1.661 raeburn 11406: } else {
1.987 raeburn 11407: $output = '<p class="LC_error">'.
11408: &mt('Error: could not update [_1].',
11409: '<span class="LC_filename">'.
11410: $container.'</span>').'</p>';
1.661 raeburn 11411: }
11412: }
11413: }
1.1123 raeburn 11414: if (($context eq 'syllabus') && (!$skiprewrites)) {
11415: my ($actionurl,$state);
11416: $actionurl = "/public/$udom/$uname/syllabus";
11417: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11418: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11419: \%codebase,
11420: {'context' => 'rewrites',
11421: 'ignore_remote_references' => 1,});
11422: if (ref($mapping) eq 'HASH') {
11423: my $rewrites = 0;
11424: foreach my $key (keys(%{$mapping})) {
11425: next if ($key =~ m{^https?://});
11426: my $ref = $mapping->{$key};
11427: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11428: my $attrib;
11429: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11430: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11431: }
11432: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11433: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11434: $rewrites += $numchg;
11435: }
11436: }
11437: if ($rewrites) {
11438: my $saveresult;
11439: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11440: if ($url eq $container) {
11441: my ($fname) = ($container =~ m{/([^/]+)$});
11442: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11443: $count,'<span class="LC_filename">'.
11444: $fname.'</span>').'</p>';
11445: } else {
11446: $output .= '<p class="LC_error">'.
11447: &mt('Error: could not update links in [_1].',
11448: '<span class="LC_filename">'.
11449: $container.'</span>').'</p>';
11450:
11451: }
11452: }
11453: }
11454: }
1.987 raeburn 11455: } else {
11456: &logthis('Failed to parse '.$container.
11457: ' to modify references: '.$parse_result);
1.661 raeburn 11458: }
11459: }
1.1071 raeburn 11460: if (wantarray) {
11461: return ($output,$count,$codebasecount);
11462: } else {
11463: return $output;
11464: }
1.661 raeburn 11465: }
11466:
11467: sub check_for_existing {
11468: my ($path,$fname,$element) = @_;
11469: my ($state,$msg);
11470: if (-d $path.'/'.$fname) {
11471: $state = 'exists';
11472: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11473: } elsif (-e $path.'/'.$fname) {
11474: $state = 'exists';
11475: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11476: }
11477: if ($state eq 'exists') {
11478: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11479: }
11480: return ($state,$msg);
11481: }
11482:
11483: sub check_for_upload {
11484: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11485: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11486: my $filesize = length($env{'form.'.$element});
11487: if (!$filesize) {
11488: my $msg = '<span class="LC_error">'.
11489: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11490: '<span class="LC_filename">'.$fname.'</span>',
11491: $filesize).'<br />'.
1.1007 raeburn 11492: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11493: '</span>';
11494: return ('zero_bytes',$msg);
11495: }
11496: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11497: my $getpropath = 1;
1.1021 raeburn 11498: my ($dirlistref,$listerror) =
11499: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11500: my $found_file = 0;
11501: my $locked_file = 0;
1.991 raeburn 11502: my @lockers;
11503: my $navmap;
11504: if ($env{'request.course.id'}) {
11505: $navmap = Apache::lonnavmaps::navmap->new();
11506: }
1.1021 raeburn 11507: if (ref($dirlistref) eq 'ARRAY') {
11508: foreach my $line (@{$dirlistref}) {
11509: my ($file_name,$rest)=split(/\&/,$line,2);
11510: if ($file_name eq $fname){
11511: $file_name = $path.$file_name;
11512: if ($group ne '') {
11513: $file_name = $group.$file_name;
11514: }
11515: $found_file = 1;
11516: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11517: foreach my $lock (@lockers) {
11518: if (ref($lock) eq 'ARRAY') {
11519: my ($symb,$crsid) = @{$lock};
11520: if ($crsid eq $env{'request.course.id'}) {
11521: if (ref($navmap)) {
11522: my $res = $navmap->getBySymb($symb);
11523: foreach my $part (@{$res->parts()}) {
11524: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11525: unless (($slot_status == $res->RESERVED) ||
11526: ($slot_status == $res->RESERVED_LOCATION)) {
11527: $locked_file = 1;
11528: }
1.991 raeburn 11529: }
1.1021 raeburn 11530: } else {
11531: $locked_file = 1;
1.991 raeburn 11532: }
11533: } else {
11534: $locked_file = 1;
11535: }
11536: }
1.1021 raeburn 11537: }
11538: } else {
11539: my @info = split(/\&/,$rest);
11540: my $currsize = $info[6]/1000;
11541: if ($currsize < $filesize) {
11542: my $extra = $filesize - $currsize;
11543: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 11544: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11545: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.',
1.1179 bisitz 11546: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11547: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11548: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11549: return ('will_exceed_quota',$msg);
11550: }
1.984 raeburn 11551: }
11552: }
1.661 raeburn 11553: }
11554: }
11555: }
11556: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 11557: my $msg = '<p class="LC_warning">'.
11558: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 11559: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11560: return ('will_exceed_quota',$msg);
11561: } elsif ($found_file) {
11562: if ($locked_file) {
1.1179 bisitz 11563: my $msg = '<p class="LC_warning">';
1.661 raeburn 11564: $msg .= &mt('Unable to upload [_1]. A locked file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>','<span class="LC_filename">'.$port_path.$env{'form.currentpath'}.'</span>');
1.1179 bisitz 11565: $msg .= '</p>';
1.661 raeburn 11566: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11567: return ('file_locked',$msg);
11568: } else {
1.1179 bisitz 11569: my $msg = '<p class="LC_error">';
1.984 raeburn 11570: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.1179 bisitz 11571: $msg .= '</p>';
1.984 raeburn 11572: return ('existingfile',$msg);
1.661 raeburn 11573: }
11574: }
11575: }
11576:
1.987 raeburn 11577: sub check_for_traversal {
11578: my ($path,$url,$toplevel) = @_;
11579: my @parts=split(/\//,$path);
11580: my $cleanpath;
11581: my $fullpath = $url;
11582: for (my $i=0;$i<@parts;$i++) {
11583: next if ($parts[$i] eq '.');
11584: if ($parts[$i] eq '..') {
11585: $fullpath =~ s{([^/]+/)$}{};
11586: } else {
11587: $fullpath .= $parts[$i].'/';
11588: }
11589: }
11590: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11591: $cleanpath = $1;
11592: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11593: my $curr_toprel = $1;
11594: my @parts = split(/\//,$curr_toprel);
11595: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11596: my @urlparts = split(/\//,$url_toprel);
11597: my $doubledots;
11598: my $startdiff = -1;
11599: for (my $i=0; $i<@urlparts; $i++) {
11600: if ($startdiff == -1) {
11601: unless ($urlparts[$i] eq $parts[$i]) {
11602: $startdiff = $i;
11603: $doubledots .= '../';
11604: }
11605: } else {
11606: $doubledots .= '../';
11607: }
11608: }
11609: if ($startdiff > -1) {
11610: $cleanpath = $doubledots;
11611: for (my $i=$startdiff; $i<@parts; $i++) {
11612: $cleanpath .= $parts[$i].'/';
11613: }
11614: }
11615: }
11616: $cleanpath =~ s{(/)$}{};
11617: return $cleanpath;
11618: }
1.31 albertel 11619:
1.1053 raeburn 11620: sub is_archive_file {
11621: my ($mimetype) = @_;
11622: if (($mimetype eq 'application/octet-stream') ||
11623: ($mimetype eq 'application/x-stuffit') ||
11624: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11625: return 1;
11626: }
11627: return;
11628: }
11629:
11630: sub decompress_form {
1.1065 raeburn 11631: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11632: my %lt = &Apache::lonlocal::texthash (
11633: this => 'This file is an archive file.',
1.1067 raeburn 11634: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11635: itsc => 'Its contents are as follows:',
1.1053 raeburn 11636: youm => 'You may wish to extract its contents.',
11637: extr => 'Extract contents',
1.1067 raeburn 11638: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11639: proa => 'Process automatically?',
1.1053 raeburn 11640: yes => 'Yes',
11641: no => 'No',
1.1067 raeburn 11642: fold => 'Title for folder containing movie',
11643: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11644: );
1.1065 raeburn 11645: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11646: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11647: my $info = &list_archive_contents($fileloc,\@paths);
11648: if (@paths) {
11649: foreach my $path (@paths) {
11650: $path =~ s{^/}{};
1.1067 raeburn 11651: if ($path =~ m{^([^/]+)/$}) {
11652: $topdir = $1;
11653: }
1.1065 raeburn 11654: if ($path =~ m{^([^/]+)/}) {
11655: $toplevel{$1} = $path;
11656: } else {
11657: $toplevel{$path} = $path;
11658: }
11659: }
11660: }
1.1067 raeburn 11661: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 11662: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11663: "$topdir/media/",
11664: "$topdir/media/$topdir.mp4",
11665: "$topdir/media/FirstFrame.png",
11666: "$topdir/media/player.swf",
11667: "$topdir/media/swfobject.js",
11668: "$topdir/media/expressInstall.swf");
1.1197 raeburn 11669: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 11670: "$topdir/$topdir.mp4",
11671: "$topdir/$topdir\_config.xml",
11672: "$topdir/$topdir\_controller.swf",
11673: "$topdir/$topdir\_embed.css",
11674: "$topdir/$topdir\_First_Frame.png",
11675: "$topdir/$topdir\_player.html",
11676: "$topdir/$topdir\_Thumbnails.png",
11677: "$topdir/playerProductInstall.swf",
11678: "$topdir/scripts/",
11679: "$topdir/scripts/config_xml.js",
11680: "$topdir/scripts/handlebars.js",
11681: "$topdir/scripts/jquery-1.7.1.min.js",
11682: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11683: "$topdir/scripts/modernizr.js",
11684: "$topdir/scripts/player-min.js",
11685: "$topdir/scripts/swfobject.js",
11686: "$topdir/skins/",
11687: "$topdir/skins/configuration_express.xml",
11688: "$topdir/skins/express_show/",
11689: "$topdir/skins/express_show/player-min.css",
11690: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 11691: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11692: "$topdir/$topdir.mp4",
11693: "$topdir/$topdir\_config.xml",
11694: "$topdir/$topdir\_controller.swf",
11695: "$topdir/$topdir\_embed.css",
11696: "$topdir/$topdir\_First_Frame.png",
11697: "$topdir/$topdir\_player.html",
11698: "$topdir/$topdir\_Thumbnails.png",
11699: "$topdir/playerProductInstall.swf",
11700: "$topdir/scripts/",
11701: "$topdir/scripts/config_xml.js",
11702: "$topdir/scripts/techsmith-smart-player.min.js",
11703: "$topdir/skins/",
11704: "$topdir/skins/configuration_express.xml",
11705: "$topdir/skins/express_show/",
11706: "$topdir/skins/express_show/spritesheet.min.css",
11707: "$topdir/skins/express_show/spritesheet.png",
11708: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 11709: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11710: if (@diffs == 0) {
1.1164 raeburn 11711: $is_camtasia = 6;
11712: } else {
1.1197 raeburn 11713: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 11714: if (@diffs == 0) {
11715: $is_camtasia = 8;
1.1197 raeburn 11716: } else {
11717: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11718: if (@diffs == 0) {
11719: $is_camtasia = 8;
11720: }
1.1164 raeburn 11721: }
1.1067 raeburn 11722: }
11723: }
11724: my $output;
11725: if ($is_camtasia) {
11726: $output = <<"ENDCAM";
11727: <script type="text/javascript" language="Javascript">
11728: // <![CDATA[
11729:
11730: function camtasiaToggle() {
11731: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11732: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 11733: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11734: document.getElementById('camtasia_titles').style.display='block';
11735: } else {
11736: document.getElementById('camtasia_titles').style.display='none';
11737: }
11738: }
11739: }
11740: return;
11741: }
11742:
11743: // ]]>
11744: </script>
11745: <p>$lt{'camt'}</p>
11746: ENDCAM
1.1065 raeburn 11747: } else {
1.1067 raeburn 11748: $output = '<p>'.$lt{'this'};
11749: if ($info eq '') {
11750: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11751: } else {
11752: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11753: '<div><pre>'.$info.'</pre></div>';
11754: }
1.1065 raeburn 11755: }
1.1067 raeburn 11756: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11757: my $duplicates;
11758: my $num = 0;
11759: if (ref($dirlist) eq 'ARRAY') {
11760: foreach my $item (@{$dirlist}) {
11761: if (ref($item) eq 'ARRAY') {
11762: if (exists($toplevel{$item->[0]})) {
11763: $duplicates .=
11764: &start_data_table_row().
11765: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11766: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11767: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11768: 'value="1" />'.&mt('Yes').'</label>'.
11769: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11770: '<td>'.$item->[0].'</td>';
11771: if ($item->[2]) {
11772: $duplicates .= '<td>'.&mt('Directory').'</td>';
11773: } else {
11774: $duplicates .= '<td>'.&mt('File').'</td>';
11775: }
11776: $duplicates .= '<td>'.$item->[3].'</td>'.
11777: '<td>'.
11778: &Apache::lonlocal::locallocaltime($item->[4]).
11779: '</td>'.
11780: &end_data_table_row();
11781: $num ++;
11782: }
11783: }
11784: }
11785: }
11786: my $itemcount;
11787: if (@paths > 0) {
11788: $itemcount = scalar(@paths);
11789: } else {
11790: $itemcount = 1;
11791: }
1.1067 raeburn 11792: if ($is_camtasia) {
11793: $output .= $lt{'auto'}.'<br />'.
11794: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 11795: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11796: $lt{'yes'}.'</label> <label>'.
11797: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11798: $lt{'no'}.'</label></span><br />'.
11799: '<div id="camtasia_titles" style="display:block">'.
11800: &Apache::lonhtmlcommon::start_pick_box().
11801: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11802: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11803: &Apache::lonhtmlcommon::row_closure().
11804: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11805: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11806: &Apache::lonhtmlcommon::row_closure(1).
11807: &Apache::lonhtmlcommon::end_pick_box().
11808: '</div>';
11809: }
1.1065 raeburn 11810: $output .=
11811: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11812: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11813: "\n";
1.1065 raeburn 11814: if ($duplicates ne '') {
11815: $output .= '<p><span class="LC_warning">'.
11816: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11817: &start_data_table().
11818: &start_data_table_header_row().
11819: '<th>'.&mt('Overwrite?').'</th>'.
11820: '<th>'.&mt('Name').'</th>'.
11821: '<th>'.&mt('Type').'</th>'.
11822: '<th>'.&mt('Size').'</th>'.
11823: '<th>'.&mt('Last modified').'</th>'.
11824: &end_data_table_header_row().
11825: $duplicates.
11826: &end_data_table().
11827: '</p>';
11828: }
1.1067 raeburn 11829: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11830: if (ref($hiddenelements) eq 'HASH') {
11831: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11832: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11833: }
11834: }
11835: $output .= <<"END";
1.1067 raeburn 11836: <br />
1.1053 raeburn 11837: <input type="submit" name="decompress" value="$lt{'extr'}" />
11838: </form>
11839: $noextract
11840: END
11841: return $output;
11842: }
11843:
1.1065 raeburn 11844: sub decompression_utility {
11845: my ($program) = @_;
11846: my @utilities = ('tar','gunzip','bunzip2','unzip');
11847: my $location;
11848: if (grep(/^\Q$program\E$/,@utilities)) {
11849: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11850: '/usr/sbin/') {
11851: if (-x $dir.$program) {
11852: $location = $dir.$program;
11853: last;
11854: }
11855: }
11856: }
11857: return $location;
11858: }
11859:
11860: sub list_archive_contents {
11861: my ($file,$pathsref) = @_;
11862: my (@cmd,$output);
11863: my $needsregexp;
11864: if ($file =~ /\.zip$/) {
11865: @cmd = (&decompression_utility('unzip'),"-l");
11866: $needsregexp = 1;
11867: } elsif (($file =~ m/\.tar\.gz$/) ||
11868: ($file =~ /\.tgz$/)) {
11869: @cmd = (&decompression_utility('tar'),"-ztf");
11870: } elsif ($file =~ /\.tar\.bz2$/) {
11871: @cmd = (&decompression_utility('tar'),"-jtf");
11872: } elsif ($file =~ m|\.tar$|) {
11873: @cmd = (&decompression_utility('tar'),"-tf");
11874: }
11875: if (@cmd) {
11876: undef($!);
11877: undef($@);
11878: if (open(my $fh,"-|", @cmd, $file)) {
11879: while (my $line = <$fh>) {
11880: $output .= $line;
11881: chomp($line);
11882: my $item;
11883: if ($needsregexp) {
11884: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11885: } else {
11886: $item = $line;
11887: }
11888: if ($item ne '') {
11889: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11890: push(@{$pathsref},$item);
11891: }
11892: }
11893: }
11894: close($fh);
11895: }
11896: }
11897: return $output;
11898: }
11899:
1.1053 raeburn 11900: sub decompress_uploaded_file {
11901: my ($file,$dir) = @_;
11902: &Apache::lonnet::appenv({'cgi.file' => $file});
11903: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11904: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11905: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11906: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11907: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11908: my $decompressed = $env{'cgi.decompressed'};
11909: &Apache::lonnet::delenv('cgi.file');
11910: &Apache::lonnet::delenv('cgi.dir');
11911: &Apache::lonnet::delenv('cgi.decompressed');
11912: return ($decompressed,$result);
11913: }
11914:
1.1055 raeburn 11915: sub process_decompression {
11916: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11917: my ($dir,$error,$warning,$output);
1.1180 raeburn 11918: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 11919: $error = &mt('Filename not a supported archive file type.').
11920: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11921: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11922: } else {
11923: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11924: if ($docuhome eq 'no_host') {
11925: $error = &mt('Could not determine home server for course.');
11926: } else {
11927: my @ids=&Apache::lonnet::current_machine_ids();
11928: my $currdir = "$dir_root/$destination";
11929: if (grep(/^\Q$docuhome\E$/,@ids)) {
11930: $dir = &LONCAPA::propath($docudom,$docuname).
11931: "$dir_root/$destination";
11932: } else {
11933: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11934: "$dir_root/$docudom/$docuname/$destination";
11935: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11936: $error = &mt('Archive file not found.');
11937: }
11938: }
1.1065 raeburn 11939: my (@to_overwrite,@to_skip);
11940: if ($env{'form.archive_overwrite_total'} > 0) {
11941: my $total = $env{'form.archive_overwrite_total'};
11942: for (my $i=0; $i<$total; $i++) {
11943: if ($env{'form.archive_overwrite_'.$i} == 1) {
11944: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11945: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11946: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11947: }
11948: }
11949: }
11950: my $numskip = scalar(@to_skip);
11951: if (($numskip > 0) &&
11952: ($numskip == $env{'form.archive_itemcount'})) {
11953: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11954: } elsif ($dir eq '') {
1.1055 raeburn 11955: $error = &mt('Directory containing archive file unavailable.');
11956: } elsif (!$error) {
1.1065 raeburn 11957: my ($decompressed,$display);
11958: if ($numskip > 0) {
11959: my $tempdir = time.'_'.$$.int(rand(10000));
11960: mkdir("$dir/$tempdir",0755);
11961: system("mv $dir/$file $dir/$tempdir/$file");
11962: ($decompressed,$display) =
11963: &decompress_uploaded_file($file,"$dir/$tempdir");
11964: foreach my $item (@to_skip) {
11965: if (($item ne '') && ($item !~ /\.\./)) {
11966: if (-f "$dir/$tempdir/$item") {
11967: unlink("$dir/$tempdir/$item");
11968: } elsif (-d "$dir/$tempdir/$item") {
11969: system("rm -rf $dir/$tempdir/$item");
11970: }
11971: }
11972: }
11973: system("mv $dir/$tempdir/* $dir");
11974: rmdir("$dir/$tempdir");
11975: } else {
11976: ($decompressed,$display) =
11977: &decompress_uploaded_file($file,$dir);
11978: }
1.1055 raeburn 11979: if ($decompressed eq 'ok') {
1.1065 raeburn 11980: $output = '<p class="LC_info">'.
11981: &mt('Files extracted successfully from archive.').
11982: '</p>'."\n";
1.1055 raeburn 11983: my ($warning,$result,@contents);
11984: my ($newdirlistref,$newlisterror) =
11985: &Apache::lonnet::dirlist($currdir,$docudom,
11986: $docuname,1);
11987: my (%is_dir,%changes,@newitems);
11988: my $dirptr = 16384;
1.1065 raeburn 11989: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11990: foreach my $dir_line (@{$newdirlistref}) {
11991: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11992: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11993: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11994: push(@newitems,$item);
11995: if ($dirptr&$testdir) {
11996: $is_dir{$item} = 1;
11997: }
11998: $changes{$item} = 1;
11999: }
12000: }
12001: }
12002: if (keys(%changes) > 0) {
12003: foreach my $item (sort(@newitems)) {
12004: if ($changes{$item}) {
12005: push(@contents,$item);
12006: }
12007: }
12008: }
12009: if (@contents > 0) {
1.1067 raeburn 12010: my $wantform;
12011: unless ($env{'form.autoextract_camtasia'}) {
12012: $wantform = 1;
12013: }
1.1056 raeburn 12014: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12015: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12016: $currdir,\%is_dir,
12017: \%children,\%parent,
1.1056 raeburn 12018: \@contents,\%dirorder,
12019: \%titles,$wantform);
1.1055 raeburn 12020: if ($datatable ne '') {
12021: $output .= &archive_options_form('decompressed',$datatable,
12022: $count,$hiddenelem);
1.1065 raeburn 12023: my $startcount = 6;
1.1055 raeburn 12024: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12025: \%titles,\%children);
1.1055 raeburn 12026: }
1.1067 raeburn 12027: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 12028: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12029: my %displayed;
12030: my $total = 1;
12031: $env{'form.archive_directory'} = [];
12032: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12033: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12034: $path =~ s{/$}{};
12035: my $item;
12036: if ($path ne '') {
12037: $item = "$path/$titles{$i}";
12038: } else {
12039: $item = $titles{$i};
12040: }
12041: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12042: if ($item eq $contents[0]) {
12043: push(@{$env{'form.archive_directory'}},$i);
12044: $env{'form.archive_'.$i} = 'display';
12045: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12046: $displayed{'folder'} = $i;
1.1164 raeburn 12047: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12048: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12049: $env{'form.archive_'.$i} = 'display';
12050: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12051: $displayed{'web'} = $i;
12052: } else {
1.1164 raeburn 12053: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12054: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12055: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12056: push(@{$env{'form.archive_directory'}},$i);
12057: }
12058: $env{'form.archive_'.$i} = 'dependency';
12059: }
12060: $total ++;
12061: }
12062: for (my $i=1; $i<$total; $i++) {
12063: next if ($i == $displayed{'web'});
12064: next if ($i == $displayed{'folder'});
12065: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12066: }
12067: $env{'form.phase'} = 'decompress_cleanup';
12068: $env{'form.archivedelete'} = 1;
12069: $env{'form.archive_count'} = $total-1;
12070: $output .=
12071: &process_extracted_files('coursedocs',$docudom,
12072: $docuname,$destination,
12073: $dir_root,$hiddenelem);
12074: }
1.1055 raeburn 12075: } else {
12076: $warning = &mt('No new items extracted from archive file.');
12077: }
12078: } else {
12079: $output = $display;
12080: $error = &mt('An error occurred during extraction from the archive file.');
12081: }
12082: }
12083: }
12084: }
12085: if ($error) {
12086: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12087: $error.'</p>'."\n";
12088: }
12089: if ($warning) {
12090: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12091: }
12092: return $output;
12093: }
12094:
12095: sub get_extracted {
1.1056 raeburn 12096: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12097: $titles,$wantform) = @_;
1.1055 raeburn 12098: my $count = 0;
12099: my $depth = 0;
12100: my $datatable;
1.1056 raeburn 12101: my @hierarchy;
1.1055 raeburn 12102: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12103: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12104: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12105: foreach my $item (@{$contents}) {
12106: $count ++;
1.1056 raeburn 12107: @{$dirorder->{$count}} = @hierarchy;
12108: $titles->{$count} = $item;
1.1055 raeburn 12109: &archive_hierarchy($depth,$count,$parent,$children);
12110: if ($wantform) {
12111: $datatable .= &archive_row($is_dir->{$item},$item,
12112: $currdir,$depth,$count);
12113: }
12114: if ($is_dir->{$item}) {
12115: $depth ++;
1.1056 raeburn 12116: push(@hierarchy,$count);
12117: $parent->{$depth} = $count;
1.1055 raeburn 12118: $datatable .=
12119: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12120: \$depth,\$count,\@hierarchy,$dirorder,
12121: $children,$parent,$titles,$wantform);
1.1055 raeburn 12122: $depth --;
1.1056 raeburn 12123: pop(@hierarchy);
1.1055 raeburn 12124: }
12125: }
12126: return ($count,$datatable);
12127: }
12128:
12129: sub recurse_extracted_archive {
1.1056 raeburn 12130: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12131: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12132: my $result='';
1.1056 raeburn 12133: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12134: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12135: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12136: return $result;
12137: }
12138: my $dirptr = 16384;
12139: my ($newdirlistref,$newlisterror) =
12140: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12141: if (ref($newdirlistref) eq 'ARRAY') {
12142: foreach my $dir_line (@{$newdirlistref}) {
12143: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12144: unless ($item =~ /^\.+$/) {
12145: $$count ++;
1.1056 raeburn 12146: @{$dirorder->{$$count}} = @{$hierarchy};
12147: $titles->{$$count} = $item;
1.1055 raeburn 12148: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12149:
1.1055 raeburn 12150: my $is_dir;
12151: if ($dirptr&$testdir) {
12152: $is_dir = 1;
12153: }
12154: if ($wantform) {
12155: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12156: }
12157: if ($is_dir) {
12158: $$depth ++;
1.1056 raeburn 12159: push(@{$hierarchy},$$count);
12160: $parent->{$$depth} = $$count;
1.1055 raeburn 12161: $result .=
12162: &recurse_extracted_archive("$currdir/$item",$docudom,
12163: $docuname,$depth,$count,
1.1056 raeburn 12164: $hierarchy,$dirorder,$children,
12165: $parent,$titles,$wantform);
1.1055 raeburn 12166: $$depth --;
1.1056 raeburn 12167: pop(@{$hierarchy});
1.1055 raeburn 12168: }
12169: }
12170: }
12171: }
12172: return $result;
12173: }
12174:
12175: sub archive_hierarchy {
12176: my ($depth,$count,$parent,$children) =@_;
12177: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12178: if (exists($parent->{$depth})) {
12179: $children->{$parent->{$depth}} .= $count.':';
12180: }
12181: }
12182: return;
12183: }
12184:
12185: sub archive_row {
12186: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12187: my ($name) = ($item =~ m{([^/]+)$});
12188: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12189: 'display' => 'Add as file',
1.1055 raeburn 12190: 'dependency' => 'Include as dependency',
12191: 'discard' => 'Discard',
12192: );
12193: if ($is_dir) {
1.1059 raeburn 12194: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12195: }
1.1056 raeburn 12196: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12197: my $offset = 0;
1.1055 raeburn 12198: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12199: $offset ++;
1.1065 raeburn 12200: if ($action ne 'display') {
12201: $offset ++;
12202: }
1.1055 raeburn 12203: $output .= '<td><span class="LC_nobreak">'.
12204: '<label><input type="radio" name="archive_'.$count.
12205: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12206: my $text = $choices{$action};
12207: if ($is_dir) {
12208: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12209: if ($action eq 'display') {
1.1059 raeburn 12210: $text = &mt('Add as folder');
1.1055 raeburn 12211: }
1.1056 raeburn 12212: } else {
12213: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12214:
12215: }
12216: $output .= ' /> '.$choices{$action}.'</label></span>';
12217: if ($action eq 'dependency') {
12218: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12219: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12220: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12221: '<option value=""></option>'."\n".
12222: '</select>'."\n".
12223: '</div>';
1.1059 raeburn 12224: } elsif ($action eq 'display') {
12225: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12226: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12227: '</div>';
1.1055 raeburn 12228: }
1.1056 raeburn 12229: $output .= '</td>';
1.1055 raeburn 12230: }
12231: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12232: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12233: for (my $i=0; $i<$depth; $i++) {
12234: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12235: }
12236: if ($is_dir) {
12237: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12238: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12239: } else {
12240: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12241: }
12242: $output .= ' '.$name.'</td>'."\n".
12243: &end_data_table_row();
12244: return $output;
12245: }
12246:
12247: sub archive_options_form {
1.1065 raeburn 12248: my ($form,$display,$count,$hiddenelem) = @_;
12249: my %lt = &Apache::lonlocal::texthash(
12250: perm => 'Permanently remove archive file?',
12251: hows => 'How should each extracted item be incorporated in the course?',
12252: cont => 'Content actions for all',
12253: addf => 'Add as folder/file',
12254: incd => 'Include as dependency for a displayed file',
12255: disc => 'Discard',
12256: no => 'No',
12257: yes => 'Yes',
12258: save => 'Save',
12259: );
12260: my $output = <<"END";
12261: <form name="$form" method="post" action="">
12262: <p><span class="LC_nobreak">$lt{'perm'}
12263: <label>
12264: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12265: </label>
12266:
12267: <label>
12268: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12269: </span>
12270: </p>
12271: <input type="hidden" name="phase" value="decompress_cleanup" />
12272: <br />$lt{'hows'}
12273: <div class="LC_columnSection">
12274: <fieldset>
12275: <legend>$lt{'cont'}</legend>
12276: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12277: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12278: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12279: </fieldset>
12280: </div>
12281: END
12282: return $output.
1.1055 raeburn 12283: &start_data_table()."\n".
1.1065 raeburn 12284: $display."\n".
1.1055 raeburn 12285: &end_data_table()."\n".
12286: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12287: $hiddenelem.
1.1065 raeburn 12288: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12289: '</form>';
12290: }
12291:
12292: sub archive_javascript {
1.1056 raeburn 12293: my ($startcount,$numitems,$titles,$children) = @_;
12294: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12295: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12296: my $scripttag = <<START;
12297: <script type="text/javascript">
12298: // <![CDATA[
12299:
12300: function checkAll(form,prefix) {
12301: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12302: for (var i=0; i < form.elements.length; i++) {
12303: var id = form.elements[i].id;
12304: if ((id != '') && (id != undefined)) {
12305: if (idstr.test(id)) {
12306: if (form.elements[i].type == 'radio') {
12307: form.elements[i].checked = true;
1.1056 raeburn 12308: var nostart = i-$startcount;
1.1059 raeburn 12309: var offset = nostart%7;
12310: var count = (nostart-offset)/7;
1.1056 raeburn 12311: dependencyCheck(form,count,offset);
1.1055 raeburn 12312: }
12313: }
12314: }
12315: }
12316: }
12317:
12318: function propagateCheck(form,count) {
12319: if (count > 0) {
1.1059 raeburn 12320: var startelement = $startcount + ((count-1) * 7);
12321: for (var j=1; j<6; j++) {
12322: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12323: var item = startelement + j;
12324: if (form.elements[item].type == 'radio') {
12325: if (form.elements[item].checked) {
12326: containerCheck(form,count,j);
12327: break;
12328: }
1.1055 raeburn 12329: }
12330: }
12331: }
12332: }
12333: }
12334:
12335: numitems = $numitems
1.1056 raeburn 12336: var titles = new Array(numitems);
12337: var parents = new Array(numitems);
1.1055 raeburn 12338: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12339: parents[i] = new Array;
1.1055 raeburn 12340: }
1.1059 raeburn 12341: var maintitle = '$maintitle';
1.1055 raeburn 12342:
12343: START
12344:
1.1056 raeburn 12345: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12346: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12347: for (my $i=0; $i<@contents; $i ++) {
12348: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12349: }
12350: }
12351:
1.1056 raeburn 12352: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12353: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12354: }
12355:
1.1055 raeburn 12356: $scripttag .= <<END;
12357:
12358: function containerCheck(form,count,offset) {
12359: if (count > 0) {
1.1056 raeburn 12360: dependencyCheck(form,count,offset);
1.1059 raeburn 12361: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12362: form.elements[item].checked = true;
12363: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12364: if (parents[count].length > 0) {
12365: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12366: containerCheck(form,parents[count][j],offset);
12367: }
12368: }
12369: }
12370: }
12371: }
12372:
12373: function dependencyCheck(form,count,offset) {
12374: if (count > 0) {
1.1059 raeburn 12375: var chosen = (offset+$startcount)+7*(count-1);
12376: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12377: var currtype = form.elements[depitem].type;
12378: if (form.elements[chosen].value == 'dependency') {
12379: document.getElementById('arc_depon_'+count).style.display='block';
12380: form.elements[depitem].options.length = 0;
12381: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 12382: for (var i=1; i<=numitems; i++) {
12383: if (i == count) {
12384: continue;
12385: }
1.1059 raeburn 12386: var startelement = $startcount + (i-1) * 7;
12387: for (var j=1; j<6; j++) {
12388: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12389: var item = startelement + j;
12390: if (form.elements[item].type == 'radio') {
12391: if (form.elements[item].checked) {
12392: if (form.elements[item].value == 'display') {
12393: var n = form.elements[depitem].options.length;
12394: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12395: }
12396: }
12397: }
12398: }
12399: }
12400: }
12401: } else {
12402: document.getElementById('arc_depon_'+count).style.display='none';
12403: form.elements[depitem].options.length = 0;
12404: form.elements[depitem].options[0] = new Option('Select','',true,true);
12405: }
1.1059 raeburn 12406: titleCheck(form,count,offset);
1.1056 raeburn 12407: }
12408: }
12409:
12410: function propagateSelect(form,count,offset) {
12411: if (count > 0) {
1.1065 raeburn 12412: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12413: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12414: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12415: if (parents[count].length > 0) {
12416: for (var j=0; j<parents[count].length; j++) {
12417: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12418: }
12419: }
12420: }
12421: }
12422: }
1.1056 raeburn 12423:
12424: function containerSelect(form,count,offset,picked) {
12425: if (count > 0) {
1.1065 raeburn 12426: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12427: if (form.elements[item].type == 'radio') {
12428: if (form.elements[item].value == 'dependency') {
12429: if (form.elements[item+1].type == 'select-one') {
12430: for (var i=0; i<form.elements[item+1].options.length; i++) {
12431: if (form.elements[item+1].options[i].value == picked) {
12432: form.elements[item+1].selectedIndex = i;
12433: break;
12434: }
12435: }
12436: }
12437: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12438: if (parents[count].length > 0) {
12439: for (var j=0; j<parents[count].length; j++) {
12440: containerSelect(form,parents[count][j],offset,picked);
12441: }
12442: }
12443: }
12444: }
12445: }
12446: }
12447: }
12448:
1.1059 raeburn 12449: function titleCheck(form,count,offset) {
12450: if (count > 0) {
12451: var chosen = (offset+$startcount)+7*(count-1);
12452: var depitem = $startcount + ((count-1) * 7) + 2;
12453: var currtype = form.elements[depitem].type;
12454: if (form.elements[chosen].value == 'display') {
12455: document.getElementById('arc_title_'+count).style.display='block';
12456: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12457: document.getElementById('archive_title_'+count).value=maintitle;
12458: }
12459: } else {
12460: document.getElementById('arc_title_'+count).style.display='none';
12461: if (currtype == 'text') {
12462: document.getElementById('archive_title_'+count).value='';
12463: }
12464: }
12465: }
12466: return;
12467: }
12468:
1.1055 raeburn 12469: // ]]>
12470: </script>
12471: END
12472: return $scripttag;
12473: }
12474:
12475: sub process_extracted_files {
1.1067 raeburn 12476: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12477: my $numitems = $env{'form.archive_count'};
12478: return unless ($numitems);
12479: my @ids=&Apache::lonnet::current_machine_ids();
12480: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12481: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12482: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12483: if (grep(/^\Q$docuhome\E$/,@ids)) {
12484: $prefix = &LONCAPA::propath($docudom,$docuname);
12485: $pathtocheck = "$dir_root/$destination";
12486: $dir = $dir_root;
12487: $ishome = 1;
12488: } else {
12489: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12490: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
12491: $dir = "$dir_root/$docudom/$docuname";
12492: }
12493: my $currdir = "$dir_root/$destination";
12494: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12495: if ($env{'form.folderpath'}) {
12496: my @items = split('&',$env{'form.folderpath'});
12497: $folders{'0'} = $items[-2];
1.1099 raeburn 12498: if ($env{'form.folderpath'} =~ /\:1$/) {
12499: $containers{'0'}='page';
12500: } else {
12501: $containers{'0'}='sequence';
12502: }
1.1055 raeburn 12503: }
12504: my @archdirs = &get_env_multiple('form.archive_directory');
12505: if ($numitems) {
12506: for (my $i=1; $i<=$numitems; $i++) {
12507: my $path = $env{'form.archive_content_'.$i};
12508: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12509: my $item = $1;
12510: $toplevelitems{$item} = $i;
12511: if (grep(/^\Q$i\E$/,@archdirs)) {
12512: $is_dir{$item} = 1;
12513: }
12514: }
12515: }
12516: }
1.1067 raeburn 12517: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12518: if (keys(%toplevelitems) > 0) {
12519: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12520: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12521: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12522: }
1.1066 raeburn 12523: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12524: if ($numitems) {
12525: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 12526: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12527: my $path = $env{'form.archive_content_'.$i};
12528: if ($path =~ /^\Q$pathtocheck\E/) {
12529: if ($env{'form.archive_'.$i} eq 'discard') {
12530: if ($prefix ne '' && $path ne '') {
12531: if (-e $prefix.$path) {
1.1066 raeburn 12532: if ((@archdirs > 0) &&
12533: (grep(/^\Q$i\E$/,@archdirs))) {
12534: $todeletedir{$prefix.$path} = 1;
12535: } else {
12536: $todelete{$prefix.$path} = 1;
12537: }
1.1055 raeburn 12538: }
12539: }
12540: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12541: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12542: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12543: $docstitle = $env{'form.archive_title_'.$i};
12544: if ($docstitle eq '') {
12545: $docstitle = $title;
12546: }
1.1055 raeburn 12547: $outer = 0;
1.1056 raeburn 12548: if (ref($dirorder{$i}) eq 'ARRAY') {
12549: if (@{$dirorder{$i}} > 0) {
12550: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12551: if ($env{'form.archive_'.$item} eq 'display') {
12552: $outer = $item;
12553: last;
12554: }
12555: }
12556: }
12557: }
12558: my ($errtext,$fatal) =
12559: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12560: '/'.$folders{$outer}.'.'.
12561: $containers{$outer});
12562: next if ($fatal);
12563: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12564: if ($context eq 'coursedocs') {
1.1056 raeburn 12565: $mapinner{$i} = time;
1.1055 raeburn 12566: $folders{$i} = 'default_'.$mapinner{$i};
12567: $containers{$i} = 'sequence';
12568: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12569: $folders{$i}.'.'.$containers{$i};
12570: my $newidx = &LONCAPA::map::getresidx();
12571: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12572: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12573: push(@LONCAPA::map::order,$newidx);
12574: my ($outtext,$errtext) =
12575: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12576: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 12577: '.'.$containers{$outer},1,1);
1.1056 raeburn 12578: $newseqid{$i} = $newidx;
1.1067 raeburn 12579: unless ($errtext) {
12580: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
12581: }
1.1055 raeburn 12582: }
12583: } else {
12584: if ($context eq 'coursedocs') {
12585: my $newidx=&LONCAPA::map::getresidx();
12586: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12587: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12588: $title;
12589: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12590: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
12591: }
12592: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12593: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12594: }
12595: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12596: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 12597: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 12598: unless ($ishome) {
12599: my $fetch = "$newdest{$i}/$title";
12600: $fetch =~ s/^\Q$prefix$dir\E//;
12601: $prompttofetch{$fetch} = 1;
12602: }
1.1055 raeburn 12603: }
12604: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12605: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12606: push(@LONCAPA::map::order, $newidx);
12607: my ($outtext,$errtext)=
12608: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12609: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 12610: '.'.$containers{$outer},1,1);
1.1067 raeburn 12611: unless ($errtext) {
12612: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12613: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
12614: }
12615: }
1.1055 raeburn 12616: }
12617: }
1.1086 raeburn 12618: }
12619: } else {
12620: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12621: }
12622: }
12623: for (my $i=1; $i<=$numitems; $i++) {
12624: next unless ($env{'form.archive_'.$i} eq 'dependency');
12625: my $path = $env{'form.archive_content_'.$i};
12626: if ($path =~ /^\Q$pathtocheck\E/) {
12627: my ($title) = ($path =~ m{/([^/]+)$});
12628: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12629: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12630: if (ref($dirorder{$i}) eq 'ARRAY') {
12631: my ($itemidx,$fullpath,$relpath);
12632: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12633: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12634: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 12635: if ($dirorder{$i}->[$j] eq $container) {
12636: $itemidx = $j;
1.1056 raeburn 12637: }
12638: }
1.1086 raeburn 12639: }
12640: if ($itemidx eq '') {
12641: $itemidx = 0;
12642: }
12643: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12644: if ($mapinner{$referrer{$i}}) {
12645: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12646: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12647: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12648: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12649: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12650: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12651: if (!-e $fullpath) {
12652: mkdir($fullpath,0755);
1.1056 raeburn 12653: }
12654: }
1.1086 raeburn 12655: } else {
12656: last;
1.1056 raeburn 12657: }
1.1086 raeburn 12658: }
12659: }
12660: } elsif ($newdest{$referrer{$i}}) {
12661: $fullpath = $newdest{$referrer{$i}};
12662: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12663: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12664: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12665: last;
12666: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12667: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12668: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12669: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12670: if (!-e $fullpath) {
12671: mkdir($fullpath,0755);
1.1056 raeburn 12672: }
12673: }
1.1086 raeburn 12674: } else {
12675: last;
1.1056 raeburn 12676: }
1.1055 raeburn 12677: }
12678: }
1.1086 raeburn 12679: if ($fullpath ne '') {
12680: if (-e "$prefix$path") {
12681: system("mv $prefix$path $fullpath/$title");
12682: }
12683: if (-e "$fullpath/$title") {
12684: my $showpath;
12685: if ($relpath ne '') {
12686: $showpath = "$relpath/$title";
12687: } else {
12688: $showpath = "/$title";
12689: }
12690: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12691: }
12692: unless ($ishome) {
12693: my $fetch = "$fullpath/$title";
12694: $fetch =~ s/^\Q$prefix$dir\E//;
12695: $prompttofetch{$fetch} = 1;
12696: }
12697: }
1.1055 raeburn 12698: }
1.1086 raeburn 12699: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12700: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12701: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12702: }
12703: } else {
12704: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12705: }
12706: }
12707: if (keys(%todelete)) {
12708: foreach my $key (keys(%todelete)) {
12709: unlink($key);
1.1066 raeburn 12710: }
12711: }
12712: if (keys(%todeletedir)) {
12713: foreach my $key (keys(%todeletedir)) {
12714: rmdir($key);
12715: }
12716: }
12717: foreach my $dir (sort(keys(%is_dir))) {
12718: if (($pathtocheck ne '') && ($dir ne '')) {
12719: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12720: }
12721: }
1.1067 raeburn 12722: if ($result ne '') {
12723: $output .= '<ul>'."\n".
12724: $result."\n".
12725: '</ul>';
12726: }
12727: unless ($ishome) {
12728: my $replicationfail;
12729: foreach my $item (keys(%prompttofetch)) {
12730: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12731: unless ($fetchresult eq 'ok') {
12732: $replicationfail .= '<li>'.$item.'</li>'."\n";
12733: }
12734: }
12735: if ($replicationfail) {
12736: $output .= '<p class="LC_error">'.
12737: &mt('Course home server failed to retrieve:').'<ul>'.
12738: $replicationfail.
12739: '</ul></p>';
12740: }
12741: }
1.1055 raeburn 12742: } else {
12743: $warning = &mt('No items found in archive.');
12744: }
12745: if ($error) {
12746: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12747: $error.'</p>'."\n";
12748: }
12749: if ($warning) {
12750: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12751: }
12752: return $output;
12753: }
12754:
1.1066 raeburn 12755: sub cleanup_empty_dirs {
12756: my ($path) = @_;
12757: if (($path ne '') && (-d $path)) {
12758: if (opendir(my $dirh,$path)) {
12759: my @dircontents = grep(!/^\./,readdir($dirh));
12760: my $numitems = 0;
12761: foreach my $item (@dircontents) {
12762: if (-d "$path/$item") {
1.1111 raeburn 12763: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12764: if (-e "$path/$item") {
12765: $numitems ++;
12766: }
12767: } else {
12768: $numitems ++;
12769: }
12770: }
12771: if ($numitems == 0) {
12772: rmdir($path);
12773: }
12774: closedir($dirh);
12775: }
12776: }
12777: return;
12778: }
12779:
1.41 ng 12780: =pod
1.45 matthew 12781:
1.1162 raeburn 12782: =item * &get_folder_hierarchy()
1.1068 raeburn 12783:
12784: Provides hierarchy of names of folders/sub-folders containing the current
12785: item,
12786:
12787: Inputs: 3
12788: - $navmap - navmaps object
12789:
12790: - $map - url for map (either the trigger itself, or map containing
12791: the resource, which is the trigger).
12792:
12793: - $showitem - 1 => show title for map itself; 0 => do not show.
12794:
12795: Outputs: 1 @pathitems - array of folder/subfolder names.
12796:
12797: =cut
12798:
12799: sub get_folder_hierarchy {
12800: my ($navmap,$map,$showitem) = @_;
12801: my @pathitems;
12802: if (ref($navmap)) {
12803: my $mapres = $navmap->getResourceByUrl($map);
12804: if (ref($mapres)) {
12805: my $pcslist = $mapres->map_hierarchy();
12806: if ($pcslist ne '') {
12807: my @pcs = split(/,/,$pcslist);
12808: foreach my $pc (@pcs) {
12809: if ($pc == 1) {
1.1129 raeburn 12810: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12811: } else {
12812: my $res = $navmap->getByMapPc($pc);
12813: if (ref($res)) {
12814: my $title = $res->compTitle();
12815: $title =~ s/\W+/_/g;
12816: if ($title ne '') {
12817: push(@pathitems,$title);
12818: }
12819: }
12820: }
12821: }
12822: }
1.1071 raeburn 12823: if ($showitem) {
12824: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 12825: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12826: } else {
12827: my $maptitle = $mapres->compTitle();
12828: $maptitle =~ s/\W+/_/g;
12829: if ($maptitle ne '') {
12830: push(@pathitems,$maptitle);
12831: }
1.1068 raeburn 12832: }
12833: }
12834: }
12835: }
12836: return @pathitems;
12837: }
12838:
12839: =pod
12840:
1.1015 raeburn 12841: =item * &get_turnedin_filepath()
12842:
12843: Determines path in a user's portfolio file for storage of files uploaded
12844: to a specific essayresponse or dropbox item.
12845:
12846: Inputs: 3 required + 1 optional.
12847: $symb is symb for resource, $uname and $udom are for current user (required).
12848: $caller is optional (can be "submission", if routine is called when storing
12849: an upoaded file when "Submit Answer" button was pressed).
12850:
12851: Returns array containing $path and $multiresp.
12852: $path is path in portfolio. $multiresp is 1 if this resource contains more
12853: than one file upload item. Callers of routine should append partid as a
12854: subdirectory to $path in cases where $multiresp is 1.
12855:
12856: Called by: homework/essayresponse.pm and homework/structuretags.pm
12857:
12858: =cut
12859:
12860: sub get_turnedin_filepath {
12861: my ($symb,$uname,$udom,$caller) = @_;
12862: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12863: my $turnindir;
12864: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12865: $turnindir = $userhash{'turnindir'};
12866: my ($path,$multiresp);
12867: if ($turnindir eq '') {
12868: if ($caller eq 'submission') {
12869: $turnindir = &mt('turned in');
12870: $turnindir =~ s/\W+/_/g;
12871: my %newhash = (
12872: 'turnindir' => $turnindir,
12873: );
12874: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12875: }
12876: }
12877: if ($turnindir ne '') {
12878: $path = '/'.$turnindir.'/';
12879: my ($multipart,$turnin,@pathitems);
12880: my $navmap = Apache::lonnavmaps::navmap->new();
12881: if (defined($navmap)) {
12882: my $mapres = $navmap->getResourceByUrl($map);
12883: if (ref($mapres)) {
12884: my $pcslist = $mapres->map_hierarchy();
12885: if ($pcslist ne '') {
12886: foreach my $pc (split(/,/,$pcslist)) {
12887: my $res = $navmap->getByMapPc($pc);
12888: if (ref($res)) {
12889: my $title = $res->compTitle();
12890: $title =~ s/\W+/_/g;
12891: if ($title ne '') {
1.1149 raeburn 12892: if (($pc > 1) && (length($title) > 12)) {
12893: $title = substr($title,0,12);
12894: }
1.1015 raeburn 12895: push(@pathitems,$title);
12896: }
12897: }
12898: }
12899: }
12900: my $maptitle = $mapres->compTitle();
12901: $maptitle =~ s/\W+/_/g;
12902: if ($maptitle ne '') {
1.1149 raeburn 12903: if (length($maptitle) > 12) {
12904: $maptitle = substr($maptitle,0,12);
12905: }
1.1015 raeburn 12906: push(@pathitems,$maptitle);
12907: }
12908: unless ($env{'request.state'} eq 'construct') {
12909: my $res = $navmap->getBySymb($symb);
12910: if (ref($res)) {
12911: my $partlist = $res->parts();
12912: my $totaluploads = 0;
12913: if (ref($partlist) eq 'ARRAY') {
12914: foreach my $part (@{$partlist}) {
12915: my @types = $res->responseType($part);
12916: my @ids = $res->responseIds($part);
12917: for (my $i=0; $i < scalar(@ids); $i++) {
12918: if ($types[$i] eq 'essay') {
12919: my $partid = $part.'_'.$ids[$i];
12920: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12921: $totaluploads ++;
12922: }
12923: }
12924: }
12925: }
12926: if ($totaluploads > 1) {
12927: $multiresp = 1;
12928: }
12929: }
12930: }
12931: }
12932: } else {
12933: return;
12934: }
12935: } else {
12936: return;
12937: }
12938: my $restitle=&Apache::lonnet::gettitle($symb);
12939: $restitle =~ s/\W+/_/g;
12940: if ($restitle eq '') {
12941: $restitle = ($resurl =~ m{/[^/]+$});
12942: if ($restitle eq '') {
12943: $restitle = time;
12944: }
12945: }
1.1149 raeburn 12946: if (length($restitle) > 12) {
12947: $restitle = substr($restitle,0,12);
12948: }
1.1015 raeburn 12949: push(@pathitems,$restitle);
12950: $path .= join('/',@pathitems);
12951: }
12952: return ($path,$multiresp);
12953: }
12954:
12955: =pod
12956:
1.464 albertel 12957: =back
1.41 ng 12958:
1.112 bowersj2 12959: =head1 CSV Upload/Handling functions
1.38 albertel 12960:
1.41 ng 12961: =over 4
12962:
1.648 raeburn 12963: =item * &upfile_store($r)
1.41 ng 12964:
12965: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12966: needs $env{'form.upfile'}
1.41 ng 12967: returns $datatoken to be put into hidden field
12968:
12969: =cut
1.31 albertel 12970:
12971: sub upfile_store {
12972: my $r=shift;
1.258 albertel 12973: $env{'form.upfile'}=~s/\r/\n/gs;
12974: $env{'form.upfile'}=~s/\f/\n/gs;
12975: $env{'form.upfile'}=~s/\n+/\n/gs;
12976: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12977:
1.258 albertel 12978: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12979: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12980: {
1.158 raeburn 12981: my $datafile = $r->dir_config('lonDaemons').
12982: '/tmp/'.$datatoken.'.tmp';
12983: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12984: print $fh $env{'form.upfile'};
1.158 raeburn 12985: close($fh);
12986: }
1.31 albertel 12987: }
12988: return $datatoken;
12989: }
12990:
1.56 matthew 12991: =pod
12992:
1.648 raeburn 12993: =item * &load_tmp_file($r)
1.41 ng 12994:
12995: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12996: needs $env{'form.datatoken'},
12997: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12998:
12999: =cut
1.31 albertel 13000:
13001: sub load_tmp_file {
13002: my $r=shift;
13003: my @studentdata=();
13004: {
1.158 raeburn 13005: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 13006: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 13007: if ( open(my $fh,"<$studentfile") ) {
13008: @studentdata=<$fh>;
13009: close($fh);
13010: }
1.31 albertel 13011: }
1.258 albertel 13012: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13013: }
13014:
1.56 matthew 13015: =pod
13016:
1.648 raeburn 13017: =item * &upfile_record_sep()
1.41 ng 13018:
13019: Separate uploaded file into records
13020: returns array of records,
1.258 albertel 13021: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13022:
13023: =cut
1.31 albertel 13024:
13025: sub upfile_record_sep {
1.258 albertel 13026: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13027: } else {
1.248 albertel 13028: my @records;
1.258 albertel 13029: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13030: if ($line=~/^\s*$/) { next; }
13031: push(@records,$line);
13032: }
13033: return @records;
1.31 albertel 13034: }
13035: }
13036:
1.56 matthew 13037: =pod
13038:
1.648 raeburn 13039: =item * &record_sep($record)
1.41 ng 13040:
1.258 albertel 13041: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13042:
13043: =cut
13044:
1.263 www 13045: sub takeleft {
13046: my $index=shift;
13047: return substr('0000'.$index,-4,4);
13048: }
13049:
1.31 albertel 13050: sub record_sep {
13051: my $record=shift;
13052: my %components=();
1.258 albertel 13053: if ($env{'form.upfiletype'} eq 'xml') {
13054: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13055: my $i=0;
1.356 albertel 13056: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13057: $field=~s/^(\"|\')//;
13058: $field=~s/(\"|\')$//;
1.263 www 13059: $components{&takeleft($i)}=$field;
1.31 albertel 13060: $i++;
13061: }
1.258 albertel 13062: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13063: my $i=0;
1.356 albertel 13064: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13065: $field=~s/^(\"|\')//;
13066: $field=~s/(\"|\')$//;
1.263 www 13067: $components{&takeleft($i)}=$field;
1.31 albertel 13068: $i++;
13069: }
13070: } else {
1.561 www 13071: my $separator=',';
1.480 banghart 13072: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13073: $separator=';';
1.480 banghart 13074: }
1.31 albertel 13075: my $i=0;
1.561 www 13076: # the character we are looking for to indicate the end of a quote or a record
13077: my $looking_for=$separator;
13078: # do not add the characters to the fields
13079: my $ignore=0;
13080: # we just encountered a separator (or the beginning of the record)
13081: my $just_found_separator=1;
13082: # store the field we are working on here
13083: my $field='';
13084: # work our way through all characters in record
13085: foreach my $character ($record=~/(.)/g) {
13086: if ($character eq $looking_for) {
13087: if ($character ne $separator) {
13088: # Found the end of a quote, again looking for separator
13089: $looking_for=$separator;
13090: $ignore=1;
13091: } else {
13092: # Found a separator, store away what we got
13093: $components{&takeleft($i)}=$field;
13094: $i++;
13095: $just_found_separator=1;
13096: $ignore=0;
13097: $field='';
13098: }
13099: next;
13100: }
13101: # single or double quotation marks after a separator indicate beginning of a quote
13102: # we are now looking for the end of the quote and need to ignore separators
13103: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13104: $looking_for=$character;
13105: next;
13106: }
13107: # ignore would be true after we reached the end of a quote
13108: if ($ignore) { next; }
13109: if (($just_found_separator) && ($character=~/\s/)) { next; }
13110: $field.=$character;
13111: $just_found_separator=0;
1.31 albertel 13112: }
1.561 www 13113: # catch the very last entry, since we never encountered the separator
13114: $components{&takeleft($i)}=$field;
1.31 albertel 13115: }
13116: return %components;
13117: }
13118:
1.144 matthew 13119: ######################################################
13120: ######################################################
13121:
1.56 matthew 13122: =pod
13123:
1.648 raeburn 13124: =item * &upfile_select_html()
1.41 ng 13125:
1.144 matthew 13126: Return HTML code to select a file from the users machine and specify
13127: the file type.
1.41 ng 13128:
13129: =cut
13130:
1.144 matthew 13131: ######################################################
13132: ######################################################
1.31 albertel 13133: sub upfile_select_html {
1.144 matthew 13134: my %Types = (
13135: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13136: semisv => &mt('Semicolon separated values'),
1.144 matthew 13137: space => &mt('Space separated'),
13138: tab => &mt('Tabulator separated'),
13139: # xml => &mt('HTML/XML'),
13140: );
13141: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13142: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13143: foreach my $type (sort(keys(%Types))) {
13144: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13145: }
13146: $Str .= "</select>\n";
13147: return $Str;
1.31 albertel 13148: }
13149:
1.301 albertel 13150: sub get_samples {
13151: my ($records,$toget) = @_;
13152: my @samples=({});
13153: my $got=0;
13154: foreach my $rec (@$records) {
13155: my %temp = &record_sep($rec);
13156: if (! grep(/\S/, values(%temp))) { next; }
13157: if (%temp) {
13158: $samples[$got]=\%temp;
13159: $got++;
13160: if ($got == $toget) { last; }
13161: }
13162: }
13163: return \@samples;
13164: }
13165:
1.144 matthew 13166: ######################################################
13167: ######################################################
13168:
1.56 matthew 13169: =pod
13170:
1.648 raeburn 13171: =item * &csv_print_samples($r,$records)
1.41 ng 13172:
13173: Prints a table of sample values from each column uploaded $r is an
13174: Apache Request ref, $records is an arrayref from
13175: &Apache::loncommon::upfile_record_sep
13176:
13177: =cut
13178:
1.144 matthew 13179: ######################################################
13180: ######################################################
1.31 albertel 13181: sub csv_print_samples {
13182: my ($r,$records) = @_;
1.662 bisitz 13183: my $samples = &get_samples($records,5);
1.301 albertel 13184:
1.594 raeburn 13185: $r->print(&mt('Samples').'<br />'.&start_data_table().
13186: &start_data_table_header_row());
1.356 albertel 13187: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13188: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13189: $r->print(&end_data_table_header_row());
1.301 albertel 13190: foreach my $hash (@$samples) {
1.594 raeburn 13191: $r->print(&start_data_table_row());
1.356 albertel 13192: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13193: $r->print('<td>');
1.356 albertel 13194: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13195: $r->print('</td>');
13196: }
1.594 raeburn 13197: $r->print(&end_data_table_row());
1.31 albertel 13198: }
1.594 raeburn 13199: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13200: }
13201:
1.144 matthew 13202: ######################################################
13203: ######################################################
13204:
1.56 matthew 13205: =pod
13206:
1.648 raeburn 13207: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13208:
13209: Prints a table to create associations between values and table columns.
1.144 matthew 13210:
1.41 ng 13211: $r is an Apache Request ref,
13212: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13213: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13214:
13215: =cut
13216:
1.144 matthew 13217: ######################################################
13218: ######################################################
1.31 albertel 13219: sub csv_print_select_table {
13220: my ($r,$records,$d) = @_;
1.301 albertel 13221: my $i=0;
13222: my $samples = &get_samples($records,1);
1.144 matthew 13223: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13224: &start_data_table().&start_data_table_header_row().
1.144 matthew 13225: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13226: '<th>'.&mt('Column').'</th>'.
13227: &end_data_table_header_row()."\n");
1.356 albertel 13228: foreach my $array_ref (@$d) {
13229: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13230: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13231:
1.875 bisitz 13232: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13233: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13234: $r->print('<option value="none"></option>');
1.356 albertel 13235: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13236: $r->print('<option value="'.$sample.'"'.
13237: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13238: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13239: }
1.594 raeburn 13240: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13241: $i++;
13242: }
1.594 raeburn 13243: $r->print(&end_data_table());
1.31 albertel 13244: $i--;
13245: return $i;
13246: }
1.56 matthew 13247:
1.144 matthew 13248: ######################################################
13249: ######################################################
13250:
1.56 matthew 13251: =pod
1.31 albertel 13252:
1.648 raeburn 13253: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13254:
13255: Prints a table of sample values from the upload and can make associate samples to internal names.
13256:
13257: $r is an Apache Request ref,
13258: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13259: $d is an array of 2 element arrays (internal name, displayed name)
13260:
13261: =cut
13262:
1.144 matthew 13263: ######################################################
13264: ######################################################
1.31 albertel 13265: sub csv_samples_select_table {
13266: my ($r,$records,$d) = @_;
13267: my $i=0;
1.144 matthew 13268: #
1.662 bisitz 13269: my $max_samples = 5;
13270: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13271: $r->print(&start_data_table().
13272: &start_data_table_header_row().'<th>'.
13273: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13274: &end_data_table_header_row());
1.301 albertel 13275:
13276: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13277: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13278: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13279: foreach my $option (@$d) {
13280: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13281: $r->print('<option value="'.$value.'"'.
1.253 albertel 13282: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13283: $display.'</option>');
1.31 albertel 13284: }
13285: $r->print('</select></td><td>');
1.662 bisitz 13286: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13287: if (defined($samples->[$line]{$key})) {
13288: $r->print($samples->[$line]{$key}."<br />\n");
13289: }
13290: }
1.594 raeburn 13291: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13292: $i++;
13293: }
1.594 raeburn 13294: $r->print(&end_data_table());
1.31 albertel 13295: $i--;
13296: return($i);
1.115 matthew 13297: }
13298:
1.144 matthew 13299: ######################################################
13300: ######################################################
13301:
1.115 matthew 13302: =pod
13303:
1.648 raeburn 13304: =item * &clean_excel_name($name)
1.115 matthew 13305:
13306: Returns a replacement for $name which does not contain any illegal characters.
13307:
13308: =cut
13309:
1.144 matthew 13310: ######################################################
13311: ######################################################
1.115 matthew 13312: sub clean_excel_name {
13313: my ($name) = @_;
13314: $name =~ s/[:\*\?\/\\]//g;
13315: if (length($name) > 31) {
13316: $name = substr($name,0,31);
13317: }
13318: return $name;
1.25 albertel 13319: }
1.84 albertel 13320:
1.85 albertel 13321: =pod
13322:
1.648 raeburn 13323: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13324:
13325: Returns either 1 or undef
13326:
13327: 1 if the part is to be hidden, undef if it is to be shown
13328:
13329: Arguments are:
13330:
13331: $id the id of the part to be checked
13332: $symb, optional the symb of the resource to check
13333: $udom, optional the domain of the user to check for
13334: $uname, optional the username of the user to check for
13335:
13336: =cut
1.84 albertel 13337:
13338: sub check_if_partid_hidden {
13339: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13340: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13341: $symb,$udom,$uname);
1.141 albertel 13342: my $truth=1;
13343: #if the string starts with !, then the list is the list to show not hide
13344: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13345: my @hiddenlist=split(/,/,$hiddenparts);
13346: foreach my $checkid (@hiddenlist) {
1.141 albertel 13347: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13348: }
1.141 albertel 13349: return !$truth;
1.84 albertel 13350: }
1.127 matthew 13351:
1.138 matthew 13352:
13353: ############################################################
13354: ############################################################
13355:
13356: =pod
13357:
1.157 matthew 13358: =back
13359:
1.138 matthew 13360: =head1 cgi-bin script and graphing routines
13361:
1.157 matthew 13362: =over 4
13363:
1.648 raeburn 13364: =item * &get_cgi_id()
1.138 matthew 13365:
13366: Inputs: none
13367:
13368: Returns an id which can be used to pass environment variables
13369: to various cgi-bin scripts. These environment variables will
13370: be removed from the users environment after a given time by
13371: the routine &Apache::lonnet::transfer_profile_to_env.
13372:
13373: =cut
13374:
13375: ############################################################
13376: ############################################################
1.152 albertel 13377: my $uniq=0;
1.136 matthew 13378: sub get_cgi_id {
1.154 albertel 13379: $uniq=($uniq+1)%100000;
1.280 albertel 13380: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13381: }
13382:
1.127 matthew 13383: ############################################################
13384: ############################################################
13385:
13386: =pod
13387:
1.648 raeburn 13388: =item * &DrawBarGraph()
1.127 matthew 13389:
1.138 matthew 13390: Facilitates the plotting of data in a (stacked) bar graph.
13391: Puts plot definition data into the users environment in order for
13392: graph.png to plot it. Returns an <img> tag for the plot.
13393: The bars on the plot are labeled '1','2',...,'n'.
13394:
13395: Inputs:
13396:
13397: =over 4
13398:
13399: =item $Title: string, the title of the plot
13400:
13401: =item $xlabel: string, text describing the X-axis of the plot
13402:
13403: =item $ylabel: string, text describing the Y-axis of the plot
13404:
13405: =item $Max: scalar, the maximum Y value to use in the plot
13406: If $Max is < any data point, the graph will not be rendered.
13407:
1.140 matthew 13408: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13409: they are plotted. If undefined, default values will be used.
13410:
1.178 matthew 13411: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13412:
1.138 matthew 13413: =item @Values: An array of array references. Each array reference holds data
13414: to be plotted in a stacked bar chart.
13415:
1.239 matthew 13416: =item If the final element of @Values is a hash reference the key/value
13417: pairs will be added to the graph definition.
13418:
1.138 matthew 13419: =back
13420:
13421: Returns:
13422:
13423: An <img> tag which references graph.png and the appropriate identifying
13424: information for the plot.
13425:
1.127 matthew 13426: =cut
13427:
13428: ############################################################
13429: ############################################################
1.134 matthew 13430: sub DrawBarGraph {
1.178 matthew 13431: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13432: #
13433: if (! defined($colors)) {
13434: $colors = ['#33ff00',
13435: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13436: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13437: ];
13438: }
1.228 matthew 13439: my $extra_settings = {};
13440: if (ref($Values[-1]) eq 'HASH') {
13441: $extra_settings = pop(@Values);
13442: }
1.127 matthew 13443: #
1.136 matthew 13444: my $identifier = &get_cgi_id();
13445: my $id = 'cgi.'.$identifier;
1.129 matthew 13446: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13447: return '';
13448: }
1.225 matthew 13449: #
13450: my @Labels;
13451: if (defined($labels)) {
13452: @Labels = @$labels;
13453: } else {
13454: for (my $i=0;$i<@{$Values[0]};$i++) {
13455: push (@Labels,$i+1);
13456: }
13457: }
13458: #
1.129 matthew 13459: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13460: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13461: my %ValuesHash;
13462: my $NumSets=1;
13463: foreach my $array (@Values) {
13464: next if (! ref($array));
1.136 matthew 13465: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13466: join(',',@$array);
1.129 matthew 13467: }
1.127 matthew 13468: #
1.136 matthew 13469: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13470: if ($NumBars < 3) {
13471: $width = 120+$NumBars*32;
1.220 matthew 13472: $xskip = 1;
1.225 matthew 13473: $bar_width = 30;
13474: } elsif ($NumBars < 5) {
13475: $width = 120+$NumBars*20;
13476: $xskip = 1;
13477: $bar_width = 20;
1.220 matthew 13478: } elsif ($NumBars < 10) {
1.136 matthew 13479: $width = 120+$NumBars*15;
13480: $xskip = 1;
13481: $bar_width = 15;
13482: } elsif ($NumBars <= 25) {
13483: $width = 120+$NumBars*11;
13484: $xskip = 5;
13485: $bar_width = 8;
13486: } elsif ($NumBars <= 50) {
13487: $width = 120+$NumBars*8;
13488: $xskip = 5;
13489: $bar_width = 4;
13490: } else {
13491: $width = 120+$NumBars*8;
13492: $xskip = 5;
13493: $bar_width = 4;
13494: }
13495: #
1.137 matthew 13496: $Max = 1 if ($Max < 1);
13497: if ( int($Max) < $Max ) {
13498: $Max++;
13499: $Max = int($Max);
13500: }
1.127 matthew 13501: $Title = '' if (! defined($Title));
13502: $xlabel = '' if (! defined($xlabel));
13503: $ylabel = '' if (! defined($ylabel));
1.369 www 13504: $ValuesHash{$id.'.title'} = &escape($Title);
13505: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13506: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13507: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13508: $ValuesHash{$id.'.NumBars'} = $NumBars;
13509: $ValuesHash{$id.'.NumSets'} = $NumSets;
13510: $ValuesHash{$id.'.PlotType'} = 'bar';
13511: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13512: $ValuesHash{$id.'.height'} = $height;
13513: $ValuesHash{$id.'.width'} = $width;
13514: $ValuesHash{$id.'.xskip'} = $xskip;
13515: $ValuesHash{$id.'.bar_width'} = $bar_width;
13516: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13517: #
1.228 matthew 13518: # Deal with other parameters
13519: while (my ($key,$value) = each(%$extra_settings)) {
13520: $ValuesHash{$id.'.'.$key} = $value;
13521: }
13522: #
1.646 raeburn 13523: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13524: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13525: }
13526:
13527: ############################################################
13528: ############################################################
13529:
13530: =pod
13531:
1.648 raeburn 13532: =item * &DrawXYGraph()
1.137 matthew 13533:
1.138 matthew 13534: Facilitates the plotting of data in an XY graph.
13535: Puts plot definition data into the users environment in order for
13536: graph.png to plot it. Returns an <img> tag for the plot.
13537:
13538: Inputs:
13539:
13540: =over 4
13541:
13542: =item $Title: string, the title of the plot
13543:
13544: =item $xlabel: string, text describing the X-axis of the plot
13545:
13546: =item $ylabel: string, text describing the Y-axis of the plot
13547:
13548: =item $Max: scalar, the maximum Y value to use in the plot
13549: If $Max is < any data point, the graph will not be rendered.
13550:
13551: =item $colors: Array ref containing the hex color codes for the data to be
13552: plotted in. If undefined, default values will be used.
13553:
13554: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13555:
13556: =item $Ydata: Array ref containing Array refs.
1.185 www 13557: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13558:
13559: =item %Values: hash indicating or overriding any default values which are
13560: passed to graph.png.
13561: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13562:
13563: =back
13564:
13565: Returns:
13566:
13567: An <img> tag which references graph.png and the appropriate identifying
13568: information for the plot.
13569:
1.137 matthew 13570: =cut
13571:
13572: ############################################################
13573: ############################################################
13574: sub DrawXYGraph {
13575: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13576: #
13577: # Create the identifier for the graph
13578: my $identifier = &get_cgi_id();
13579: my $id = 'cgi.'.$identifier;
13580: #
13581: $Title = '' if (! defined($Title));
13582: $xlabel = '' if (! defined($xlabel));
13583: $ylabel = '' if (! defined($ylabel));
13584: my %ValuesHash =
13585: (
1.369 www 13586: $id.'.title' => &escape($Title),
13587: $id.'.xlabel' => &escape($xlabel),
13588: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13589: $id.'.y_max_value'=> $Max,
13590: $id.'.labels' => join(',',@$Xlabels),
13591: $id.'.PlotType' => 'XY',
13592: );
13593: #
13594: if (defined($colors) && ref($colors) eq 'ARRAY') {
13595: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13596: }
13597: #
13598: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13599: return '';
13600: }
13601: my $NumSets=1;
1.138 matthew 13602: foreach my $array (@{$Ydata}){
1.137 matthew 13603: next if (! ref($array));
13604: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13605: }
1.138 matthew 13606: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13607: #
13608: # Deal with other parameters
13609: while (my ($key,$value) = each(%Values)) {
13610: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13611: }
13612: #
1.646 raeburn 13613: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13614: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13615: }
13616:
13617: ############################################################
13618: ############################################################
13619:
13620: =pod
13621:
1.648 raeburn 13622: =item * &DrawXYYGraph()
1.138 matthew 13623:
13624: Facilitates the plotting of data in an XY graph with two Y axes.
13625: Puts plot definition data into the users environment in order for
13626: graph.png to plot it. Returns an <img> tag for the plot.
13627:
13628: Inputs:
13629:
13630: =over 4
13631:
13632: =item $Title: string, the title of the plot
13633:
13634: =item $xlabel: string, text describing the X-axis of the plot
13635:
13636: =item $ylabel: string, text describing the Y-axis of the plot
13637:
13638: =item $colors: Array ref containing the hex color codes for the data to be
13639: plotted in. If undefined, default values will be used.
13640:
13641: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13642:
13643: =item $Ydata1: The first data set
13644:
13645: =item $Min1: The minimum value of the left Y-axis
13646:
13647: =item $Max1: The maximum value of the left Y-axis
13648:
13649: =item $Ydata2: The second data set
13650:
13651: =item $Min2: The minimum value of the right Y-axis
13652:
13653: =item $Max2: The maximum value of the left Y-axis
13654:
13655: =item %Values: hash indicating or overriding any default values which are
13656: passed to graph.png.
13657: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13658:
13659: =back
13660:
13661: Returns:
13662:
13663: An <img> tag which references graph.png and the appropriate identifying
13664: information for the plot.
1.136 matthew 13665:
13666: =cut
13667:
13668: ############################################################
13669: ############################################################
1.137 matthew 13670: sub DrawXYYGraph {
13671: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13672: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13673: #
13674: # Create the identifier for the graph
13675: my $identifier = &get_cgi_id();
13676: my $id = 'cgi.'.$identifier;
13677: #
13678: $Title = '' if (! defined($Title));
13679: $xlabel = '' if (! defined($xlabel));
13680: $ylabel = '' if (! defined($ylabel));
13681: my %ValuesHash =
13682: (
1.369 www 13683: $id.'.title' => &escape($Title),
13684: $id.'.xlabel' => &escape($xlabel),
13685: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13686: $id.'.labels' => join(',',@$Xlabels),
13687: $id.'.PlotType' => 'XY',
13688: $id.'.NumSets' => 2,
1.137 matthew 13689: $id.'.two_axes' => 1,
13690: $id.'.y1_max_value' => $Max1,
13691: $id.'.y1_min_value' => $Min1,
13692: $id.'.y2_max_value' => $Max2,
13693: $id.'.y2_min_value' => $Min2,
1.136 matthew 13694: );
13695: #
1.137 matthew 13696: if (defined($colors) && ref($colors) eq 'ARRAY') {
13697: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13698: }
13699: #
13700: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13701: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13702: return '';
13703: }
13704: my $NumSets=1;
1.137 matthew 13705: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13706: next if (! ref($array));
13707: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13708: }
13709: #
13710: # Deal with other parameters
13711: while (my ($key,$value) = each(%Values)) {
13712: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13713: }
13714: #
1.646 raeburn 13715: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13716: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13717: }
13718:
13719: ############################################################
13720: ############################################################
13721:
13722: =pod
13723:
1.157 matthew 13724: =back
13725:
1.139 matthew 13726: =head1 Statistics helper routines?
13727:
13728: Bad place for them but what the hell.
13729:
1.157 matthew 13730: =over 4
13731:
1.648 raeburn 13732: =item * &chartlink()
1.139 matthew 13733:
13734: Returns a link to the chart for a specific student.
13735:
13736: Inputs:
13737:
13738: =over 4
13739:
13740: =item $linktext: The text of the link
13741:
13742: =item $sname: The students username
13743:
13744: =item $sdomain: The students domain
13745:
13746: =back
13747:
1.157 matthew 13748: =back
13749:
1.139 matthew 13750: =cut
13751:
13752: ############################################################
13753: ############################################################
13754: sub chartlink {
13755: my ($linktext, $sname, $sdomain) = @_;
13756: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13757: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13758: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13759: '">'.$linktext.'</a>';
1.153 matthew 13760: }
13761:
13762: #######################################################
13763: #######################################################
13764:
13765: =pod
13766:
13767: =head1 Course Environment Routines
1.157 matthew 13768:
13769: =over 4
1.153 matthew 13770:
1.648 raeburn 13771: =item * &restore_course_settings()
1.153 matthew 13772:
1.648 raeburn 13773: =item * &store_course_settings()
1.153 matthew 13774:
13775: Restores/Store indicated form parameters from the course environment.
13776: Will not overwrite existing values of the form parameters.
13777:
13778: Inputs:
13779: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13780:
13781: a hash ref describing the data to be stored. For example:
13782:
13783: %Save_Parameters = ('Status' => 'scalar',
13784: 'chartoutputmode' => 'scalar',
13785: 'chartoutputdata' => 'scalar',
13786: 'Section' => 'array',
1.373 raeburn 13787: 'Group' => 'array',
1.153 matthew 13788: 'StudentData' => 'array',
13789: 'Maps' => 'array');
13790:
13791: Returns: both routines return nothing
13792:
1.631 raeburn 13793: =back
13794:
1.153 matthew 13795: =cut
13796:
13797: #######################################################
13798: #######################################################
13799: sub store_course_settings {
1.496 albertel 13800: return &store_settings($env{'request.course.id'},@_);
13801: }
13802:
13803: sub store_settings {
1.153 matthew 13804: # save to the environment
13805: # appenv the same items, just to be safe
1.300 albertel 13806: my $udom = $env{'user.domain'};
13807: my $uname = $env{'user.name'};
1.496 albertel 13808: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13809: my %SaveHash;
13810: my %AppHash;
13811: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13812: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13813: my $envname = 'environment.'.$basename;
1.258 albertel 13814: if (exists($env{'form.'.$setting})) {
1.153 matthew 13815: # Save this value away
13816: if ($type eq 'scalar' &&
1.258 albertel 13817: (! exists($env{$envname}) ||
13818: $env{$envname} ne $env{'form.'.$setting})) {
13819: $SaveHash{$basename} = $env{'form.'.$setting};
13820: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13821: } elsif ($type eq 'array') {
13822: my $stored_form;
1.258 albertel 13823: if (ref($env{'form.'.$setting})) {
1.153 matthew 13824: $stored_form = join(',',
13825: map {
1.369 www 13826: &escape($_);
1.258 albertel 13827: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13828: } else {
13829: $stored_form =
1.369 www 13830: &escape($env{'form.'.$setting});
1.153 matthew 13831: }
13832: # Determine if the array contents are the same.
1.258 albertel 13833: if ($stored_form ne $env{$envname}) {
1.153 matthew 13834: $SaveHash{$basename} = $stored_form;
13835: $AppHash{$envname} = $stored_form;
13836: }
13837: }
13838: }
13839: }
13840: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13841: $udom,$uname);
1.153 matthew 13842: if ($put_result !~ /^(ok|delayed)/) {
13843: &Apache::lonnet::logthis('unable to save form parameters, '.
13844: 'got error:'.$put_result);
13845: }
13846: # Make sure these settings stick around in this session, too
1.646 raeburn 13847: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13848: return;
13849: }
13850:
13851: sub restore_course_settings {
1.499 albertel 13852: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13853: }
13854:
13855: sub restore_settings {
13856: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13857: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13858: next if (exists($env{'form.'.$setting}));
1.496 albertel 13859: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13860: '.'.$setting;
1.258 albertel 13861: if (exists($env{$envname})) {
1.153 matthew 13862: if ($type eq 'scalar') {
1.258 albertel 13863: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13864: } elsif ($type eq 'array') {
1.258 albertel 13865: $env{'form.'.$setting} = [
1.153 matthew 13866: map {
1.369 www 13867: &unescape($_);
1.258 albertel 13868: } split(',',$env{$envname})
1.153 matthew 13869: ];
13870: }
13871: }
13872: }
1.127 matthew 13873: }
13874:
1.618 raeburn 13875: #######################################################
13876: #######################################################
13877:
13878: =pod
13879:
13880: =head1 Domain E-mail Routines
13881:
13882: =over 4
13883:
1.648 raeburn 13884: =item * &build_recipient_list()
1.618 raeburn 13885:
1.1144 raeburn 13886: Build recipient lists for following types of e-mail:
1.766 raeburn 13887: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 13888: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13889: module change checking, student/employee ID conflict checks, as
13890: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13891: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13892:
13893: Inputs:
1.619 raeburn 13894: defmail (scalar - email address of default recipient),
1.1144 raeburn 13895: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13896: requestsmail, updatesmail, or idconflictsmail).
13897:
1.619 raeburn 13898: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 13899:
1.619 raeburn 13900: origmail (scalar - email address of recipient from loncapa.conf,
13901: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13902:
1.655 raeburn 13903: Returns: comma separated list of addresses to which to send e-mail.
13904:
13905: =back
1.618 raeburn 13906:
13907: =cut
13908:
13909: ############################################################
13910: ############################################################
13911: sub build_recipient_list {
1.619 raeburn 13912: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13913: my @recipients;
13914: my $otheremails;
13915: my %domconfig =
13916: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13917: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13918: if (exists($domconfig{'contacts'}{$mailing})) {
13919: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13920: my @contacts = ('adminemail','supportemail');
13921: foreach my $item (@contacts) {
13922: if ($domconfig{'contacts'}{$mailing}{$item}) {
13923: my $addr = $domconfig{'contacts'}{$item};
13924: if (!grep(/^\Q$addr\E$/,@recipients)) {
13925: push(@recipients,$addr);
13926: }
1.619 raeburn 13927: }
1.766 raeburn 13928: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13929: }
13930: }
1.766 raeburn 13931: } elsif ($origmail ne '') {
13932: push(@recipients,$origmail);
1.618 raeburn 13933: }
1.619 raeburn 13934: } elsif ($origmail ne '') {
13935: push(@recipients,$origmail);
1.618 raeburn 13936: }
1.688 raeburn 13937: if (defined($defmail)) {
13938: if ($defmail ne '') {
13939: push(@recipients,$defmail);
13940: }
1.618 raeburn 13941: }
13942: if ($otheremails) {
1.619 raeburn 13943: my @others;
13944: if ($otheremails =~ /,/) {
13945: @others = split(/,/,$otheremails);
1.618 raeburn 13946: } else {
1.619 raeburn 13947: push(@others,$otheremails);
13948: }
13949: foreach my $addr (@others) {
13950: if (!grep(/^\Q$addr\E$/,@recipients)) {
13951: push(@recipients,$addr);
13952: }
1.618 raeburn 13953: }
13954: }
1.619 raeburn 13955: my $recipientlist = join(',',@recipients);
1.618 raeburn 13956: return $recipientlist;
13957: }
13958:
1.127 matthew 13959: ############################################################
13960: ############################################################
1.154 albertel 13961:
1.655 raeburn 13962: =pod
13963:
1.1224 musolffc 13964: =over 4
13965:
1.1223 musolffc 13966: =item * &mime_email()
13967:
13968: Sends an email with a possible attachment
13969:
13970: Inputs:
13971:
13972: =over 4
13973:
13974: from - Sender's email address
13975:
13976: to - Email address of recipient
13977:
13978: subject - Subject of email
13979:
13980: body - Body of email
13981:
13982: cc_string - Carbon copy email address
13983:
13984: bcc - Blind carbon copy email address
13985:
13986: type - File type of attachment
13987:
13988: attachment_path - Path of file to be attached
13989:
13990: file_name - Name of file to be attached
13991:
13992: attachment_text - The body of an attachment of type "TEXT"
13993:
13994: =back
13995:
13996: =back
13997:
13998: =cut
13999:
14000: ############################################################
14001: ############################################################
14002:
14003: sub mime_email {
14004: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
14005: $file_name, $attachment_text) = @_;
14006: my $msg = MIME::Lite->new(
14007: From => $from,
14008: To => $to,
14009: Subject => $subject,
14010: Type =>'TEXT',
14011: Data => $body,
14012: );
14013: if ($cc_string ne '') {
14014: $msg->add("Cc" => $cc_string);
14015: }
14016: if ($bcc ne '') {
14017: $msg->add("Bcc" => $bcc);
14018: }
14019: $msg->attr("content-type" => "text/plain");
14020: $msg->attr("content-type.charset" => "UTF-8");
14021: # Attach file if given
14022: if ($attachment_path) {
14023: unless ($file_name) {
14024: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
14025: }
14026: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
14027: $msg->attach(Type => $type,
14028: Path => $attachment_path,
14029: Filename => $file_name
14030: );
14031: # Otherwise attach text if given
14032: } elsif ($attachment_text) {
14033: $msg->attach(Type => 'TEXT',
14034: Data => $attachment_text);
14035: }
14036: # Send it
14037: $msg->send('sendmail');
14038: }
14039:
14040: ############################################################
14041: ############################################################
14042:
14043: =pod
14044:
1.655 raeburn 14045: =head1 Course Catalog Routines
14046:
14047: =over 4
14048:
14049: =item * &gather_categories()
14050:
14051: Converts category definitions - keys of categories hash stored in
14052: coursecategories in configuration.db on the primary library server in a
14053: domain - to an array. Also generates javascript and idx hash used to
14054: generate Domain Coordinator interface for editing Course Categories.
14055:
14056: Inputs:
1.663 raeburn 14057:
1.655 raeburn 14058: categories (reference to hash of category definitions).
1.663 raeburn 14059:
1.655 raeburn 14060: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14061: categories and subcategories).
1.663 raeburn 14062:
1.655 raeburn 14063: idx (reference to hash of counters used in Domain Coordinator interface for
14064: editing Course Categories).
1.663 raeburn 14065:
1.655 raeburn 14066: jsarray (reference to array of categories used to create Javascript arrays for
14067: Domain Coordinator interface for editing Course Categories).
14068:
14069: Returns: nothing
14070:
14071: Side effects: populates cats, idx and jsarray.
14072:
14073: =cut
14074:
14075: sub gather_categories {
14076: my ($categories,$cats,$idx,$jsarray) = @_;
14077: my %counters;
14078: my $num = 0;
14079: foreach my $item (keys(%{$categories})) {
14080: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14081: if ($container eq '' && $depth == 0) {
14082: $cats->[$depth][$categories->{$item}] = $cat;
14083: } else {
14084: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14085: }
14086: my ($escitem,$tail) = split(/:/,$item,2);
14087: if ($counters{$tail} eq '') {
14088: $counters{$tail} = $num;
14089: $num ++;
14090: }
14091: if (ref($idx) eq 'HASH') {
14092: $idx->{$item} = $counters{$tail};
14093: }
14094: if (ref($jsarray) eq 'ARRAY') {
14095: push(@{$jsarray->[$counters{$tail}]},$item);
14096: }
14097: }
14098: return;
14099: }
14100:
14101: =pod
14102:
14103: =item * &extract_categories()
14104:
14105: Used to generate breadcrumb trails for course categories.
14106:
14107: Inputs:
1.663 raeburn 14108:
1.655 raeburn 14109: categories (reference to hash of category definitions).
1.663 raeburn 14110:
1.655 raeburn 14111: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14112: categories and subcategories).
1.663 raeburn 14113:
1.655 raeburn 14114: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14115:
1.655 raeburn 14116: allitems (reference to hash - key is category key
14117: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14118:
1.655 raeburn 14119: idx (reference to hash of counters used in Domain Coordinator interface for
14120: editing Course Categories).
1.663 raeburn 14121:
1.655 raeburn 14122: jsarray (reference to array of categories used to create Javascript arrays for
14123: Domain Coordinator interface for editing Course Categories).
14124:
1.665 raeburn 14125: subcats (reference to hash of arrays containing all subcategories within each
14126: category, -recursive)
14127:
1.655 raeburn 14128: Returns: nothing
14129:
14130: Side effects: populates trails and allitems hash references.
14131:
14132: =cut
14133:
14134: sub extract_categories {
1.665 raeburn 14135: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14136: if (ref($categories) eq 'HASH') {
14137: &gather_categories($categories,$cats,$idx,$jsarray);
14138: if (ref($cats->[0]) eq 'ARRAY') {
14139: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14140: my $name = $cats->[0][$i];
14141: my $item = &escape($name).'::0';
14142: my $trailstr;
14143: if ($name eq 'instcode') {
14144: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14145: } elsif ($name eq 'communities') {
14146: $trailstr = &mt('Communities');
1.655 raeburn 14147: } else {
14148: $trailstr = $name;
14149: }
14150: if ($allitems->{$item} eq '') {
14151: push(@{$trails},$trailstr);
14152: $allitems->{$item} = scalar(@{$trails})-1;
14153: }
14154: my @parents = ($name);
14155: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14156: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14157: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14158: if (ref($subcats) eq 'HASH') {
14159: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14160: }
14161: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14162: }
14163: } else {
14164: if (ref($subcats) eq 'HASH') {
14165: $subcats->{$item} = [];
1.655 raeburn 14166: }
14167: }
14168: }
14169: }
14170: }
14171: return;
14172: }
14173:
14174: =pod
14175:
1.1162 raeburn 14176: =item * &recurse_categories()
1.655 raeburn 14177:
14178: Recursively used to generate breadcrumb trails for course categories.
14179:
14180: Inputs:
1.663 raeburn 14181:
1.655 raeburn 14182: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14183: categories and subcategories).
1.663 raeburn 14184:
1.655 raeburn 14185: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14186:
14187: category (current course category, for which breadcrumb trail is being generated).
14188:
14189: trails (reference to array of breadcrumb trails for each category).
14190:
1.655 raeburn 14191: allitems (reference to hash - key is category key
14192: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14193:
1.655 raeburn 14194: parents (array containing containers directories for current category,
14195: back to top level).
14196:
14197: Returns: nothing
14198:
14199: Side effects: populates trails and allitems hash references
14200:
14201: =cut
14202:
14203: sub recurse_categories {
1.665 raeburn 14204: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14205: my $shallower = $depth - 1;
14206: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14207: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14208: my $name = $cats->[$depth]{$category}[$k];
14209: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14210: my $trailstr = join(' -> ',(@{$parents},$category));
14211: if ($allitems->{$item} eq '') {
14212: push(@{$trails},$trailstr);
14213: $allitems->{$item} = scalar(@{$trails})-1;
14214: }
14215: my $deeper = $depth+1;
14216: push(@{$parents},$category);
1.665 raeburn 14217: if (ref($subcats) eq 'HASH') {
14218: my $subcat = &escape($name).':'.$category.':'.$depth;
14219: for (my $j=@{$parents}; $j>=0; $j--) {
14220: my $higher;
14221: if ($j > 0) {
14222: $higher = &escape($parents->[$j]).':'.
14223: &escape($parents->[$j-1]).':'.$j;
14224: } else {
14225: $higher = &escape($parents->[$j]).'::'.$j;
14226: }
14227: push(@{$subcats->{$higher}},$subcat);
14228: }
14229: }
14230: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14231: $subcats);
1.655 raeburn 14232: pop(@{$parents});
14233: }
14234: } else {
14235: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14236: my $trailstr = join(' -> ',(@{$parents},$category));
14237: if ($allitems->{$item} eq '') {
14238: push(@{$trails},$trailstr);
14239: $allitems->{$item} = scalar(@{$trails})-1;
14240: }
14241: }
14242: return;
14243: }
14244:
1.663 raeburn 14245: =pod
14246:
1.1162 raeburn 14247: =item * &assign_categories_table()
1.663 raeburn 14248:
14249: Create a datatable for display of hierarchical categories in a domain,
14250: with checkboxes to allow a course to be categorized.
14251:
14252: Inputs:
14253:
14254: cathash - reference to hash of categories defined for the domain (from
14255: configuration.db)
14256:
14257: currcat - scalar with an & separated list of categories assigned to a course.
14258:
1.919 raeburn 14259: type - scalar contains course type (Course or Community).
14260:
1.663 raeburn 14261: Returns: $output (markup to be displayed)
14262:
14263: =cut
14264:
14265: sub assign_categories_table {
1.919 raeburn 14266: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 14267: my $output;
14268: if (ref($cathash) eq 'HASH') {
14269: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
14270: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
14271: $maxdepth = scalar(@cats);
14272: if (@cats > 0) {
14273: my $itemcount = 0;
14274: if (ref($cats[0]) eq 'ARRAY') {
14275: my @currcategories;
14276: if ($currcat ne '') {
14277: @currcategories = split('&',$currcat);
14278: }
1.919 raeburn 14279: my $table;
1.663 raeburn 14280: for (my $i=0; $i<@{$cats[0]}; $i++) {
14281: my $parent = $cats[0][$i];
1.919 raeburn 14282: next if ($parent eq 'instcode');
14283: if ($type eq 'Community') {
14284: next unless ($parent eq 'communities');
14285: } else {
14286: next if ($parent eq 'communities');
14287: }
1.663 raeburn 14288: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14289: my $item = &escape($parent).'::0';
14290: my $checked = '';
14291: if (@currcategories > 0) {
14292: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14293: $checked = ' checked="checked"';
1.663 raeburn 14294: }
14295: }
1.919 raeburn 14296: my $parent_title = $parent;
14297: if ($parent eq 'communities') {
14298: $parent_title = &mt('Communities');
14299: }
14300: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14301: '<input type="checkbox" name="usecategory" value="'.
14302: $item.'"'.$checked.' />'.$parent_title.'</span>'.
14303: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14304: my $depth = 1;
14305: push(@path,$parent);
1.919 raeburn 14306: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 14307: pop(@path);
1.919 raeburn 14308: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14309: $itemcount ++;
14310: }
1.919 raeburn 14311: if ($itemcount) {
14312: $output = &Apache::loncommon::start_data_table().
14313: $table.
14314: &Apache::loncommon::end_data_table();
14315: }
1.663 raeburn 14316: }
14317: }
14318: }
14319: return $output;
14320: }
14321:
14322: =pod
14323:
1.1162 raeburn 14324: =item * &assign_category_rows()
1.663 raeburn 14325:
14326: Create a datatable row for display of nested categories in a domain,
14327: with checkboxes to allow a course to be categorized,called recursively.
14328:
14329: Inputs:
14330:
14331: itemcount - track row number for alternating colors
14332:
14333: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14334: categories and subcategories.
14335:
14336: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14337:
14338: parent - parent of current category item
14339:
14340: path - Array containing all categories back up through the hierarchy from the
14341: current category to the top level.
14342:
14343: currcategories - reference to array of current categories assigned to the course
14344:
14345: Returns: $output (markup to be displayed).
14346:
14347: =cut
14348:
14349: sub assign_category_rows {
14350: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
14351: my ($text,$name,$item,$chgstr);
14352: if (ref($cats) eq 'ARRAY') {
14353: my $maxdepth = scalar(@{$cats});
14354: if (ref($cats->[$depth]) eq 'HASH') {
14355: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14356: my $numchildren = @{$cats->[$depth]{$parent}};
14357: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 14358: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14359: for (my $j=0; $j<$numchildren; $j++) {
14360: $name = $cats->[$depth]{$parent}[$j];
14361: $item = &escape($name).':'.&escape($parent).':'.$depth;
14362: my $deeper = $depth+1;
14363: my $checked = '';
14364: if (ref($currcategories) eq 'ARRAY') {
14365: if (@{$currcategories} > 0) {
14366: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14367: $checked = ' checked="checked"';
1.663 raeburn 14368: }
14369: }
14370: }
1.664 raeburn 14371: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14372: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 14373: $item.'"'.$checked.' />'.$name.'</label></span>'.
14374: '<input type="hidden" name="catname" value="'.$name.'" />'.
14375: '</td><td>';
1.663 raeburn 14376: if (ref($path) eq 'ARRAY') {
14377: push(@{$path},$name);
14378: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
14379: pop(@{$path});
14380: }
14381: $text .= '</td></tr>';
14382: }
14383: $text .= '</table></td>';
14384: }
14385: }
14386: }
14387: return $text;
14388: }
14389:
1.1181 raeburn 14390: =pod
14391:
14392: =back
14393:
14394: =cut
14395:
1.655 raeburn 14396: ############################################################
14397: ############################################################
14398:
14399:
1.443 albertel 14400: sub commit_customrole {
1.664 raeburn 14401: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14402: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14403: ($start?', '.&mt('starting').' '.localtime($start):'').
14404: ($end?', ending '.localtime($end):'').': <b>'.
14405: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14406: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14407: '</b><br />';
14408: return $output;
14409: }
14410:
14411: sub commit_standardrole {
1.1116 raeburn 14412: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14413: my ($output,$logmsg,$linefeed);
14414: if ($context eq 'auto') {
14415: $linefeed = "\n";
14416: } else {
14417: $linefeed = "<br />\n";
14418: }
1.443 albertel 14419: if ($three eq 'st') {
1.541 raeburn 14420: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 14421: $one,$two,$sec,$context,$credits);
1.541 raeburn 14422: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14423: ($result eq 'unknown_course') || ($result eq 'refused')) {
14424: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14425: } else {
1.541 raeburn 14426: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14427: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14428: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14429: if ($context eq 'auto') {
14430: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14431: } else {
14432: $output .= '<b>'.$result.'</b>'.$linefeed.
14433: &mt('Add to classlist').': <b>ok</b>';
14434: }
14435: $output .= $linefeed;
1.443 albertel 14436: }
14437: } else {
14438: $output = &mt('Assigning').' '.$three.' in '.$url.
14439: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14440: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14441: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14442: if ($context eq 'auto') {
14443: $output .= $result.$linefeed;
14444: } else {
14445: $output .= '<b>'.$result.'</b>'.$linefeed;
14446: }
1.443 albertel 14447: }
14448: return $output;
14449: }
14450:
14451: sub commit_studentrole {
1.1116 raeburn 14452: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14453: $credits) = @_;
1.626 raeburn 14454: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14455: if ($context eq 'auto') {
14456: $linefeed = "\n";
14457: } else {
14458: $linefeed = '<br />'."\n";
14459: }
1.443 albertel 14460: if (defined($one) && defined($two)) {
14461: my $cid=$one.'_'.$two;
14462: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14463: my $secchange = 0;
14464: my $expire_role_result;
14465: my $modify_section_result;
1.628 raeburn 14466: if ($oldsec ne '-1') {
14467: if ($oldsec ne $sec) {
1.443 albertel 14468: $secchange = 1;
1.628 raeburn 14469: my $now = time;
1.443 albertel 14470: my $uurl='/'.$cid;
14471: $uurl=~s/\_/\//g;
14472: if ($oldsec) {
14473: $uurl.='/'.$oldsec;
14474: }
1.626 raeburn 14475: $oldsecurl = $uurl;
1.628 raeburn 14476: $expire_role_result =
1.652 raeburn 14477: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14478: if ($env{'request.course.sec'} ne '') {
14479: if ($expire_role_result eq 'refused') {
14480: my @roles = ('st');
14481: my @statuses = ('previous');
14482: my @roledoms = ($one);
14483: my $withsec = 1;
14484: my %roleshash =
14485: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14486: \@statuses,\@roles,\@roledoms,$withsec);
14487: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14488: my ($oldstart,$oldend) =
14489: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14490: if ($oldend > 0 && $oldend <= $now) {
14491: $expire_role_result = 'ok';
14492: }
14493: }
14494: }
14495: }
1.443 albertel 14496: $result = $expire_role_result;
14497: }
14498: }
14499: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 14500: $modify_section_result =
14501: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14502: undef,undef,undef,$sec,
14503: $end,$start,'','',$cid,
14504: '',$context,$credits);
1.443 albertel 14505: if ($modify_section_result =~ /^ok/) {
14506: if ($secchange == 1) {
1.628 raeburn 14507: if ($sec eq '') {
14508: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14509: } else {
14510: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14511: }
1.443 albertel 14512: } elsif ($oldsec eq '-1') {
1.628 raeburn 14513: if ($sec eq '') {
14514: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14515: } else {
14516: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14517: }
1.443 albertel 14518: } else {
1.628 raeburn 14519: if ($sec eq '') {
14520: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14521: } else {
14522: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14523: }
1.443 albertel 14524: }
14525: } else {
1.1115 raeburn 14526: if ($secchange) {
1.628 raeburn 14527: $$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;
14528: } else {
14529: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14530: }
1.443 albertel 14531: }
14532: $result = $modify_section_result;
14533: } elsif ($secchange == 1) {
1.628 raeburn 14534: if ($oldsec eq '') {
1.1103 raeburn 14535: $$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 14536: } else {
14537: $$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;
14538: }
1.626 raeburn 14539: if ($expire_role_result eq 'refused') {
14540: my $newsecurl = '/'.$cid;
14541: $newsecurl =~ s/\_/\//g;
14542: if ($sec ne '') {
14543: $newsecurl.='/'.$sec;
14544: }
14545: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14546: if ($sec eq '') {
14547: $$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;
14548: } else {
14549: $$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;
14550: }
14551: }
14552: }
1.443 albertel 14553: }
14554: } else {
1.626 raeburn 14555: $$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 14556: $result = "error: incomplete course id\n";
14557: }
14558: return $result;
14559: }
14560:
1.1108 raeburn 14561: sub show_role_extent {
14562: my ($scope,$context,$role) = @_;
14563: $scope =~ s{^/}{};
14564: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14565: push(@courseroles,'co');
14566: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14567: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14568: $scope =~ s{/}{_};
14569: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14570: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14571: my ($audom,$auname) = split(/\//,$scope);
14572: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14573: &Apache::loncommon::plainname($auname,$audom).'</span>');
14574: } else {
14575: $scope =~ s{/$}{};
14576: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14577: &Apache::lonnet::domain($scope,'description').'</span>');
14578: }
14579: }
14580:
1.443 albertel 14581: ############################################################
14582: ############################################################
14583:
1.566 albertel 14584: sub check_clone {
1.578 raeburn 14585: my ($args,$linefeed) = @_;
1.566 albertel 14586: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14587: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14588: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14589: my $clonemsg;
14590: my $can_clone = 0;
1.944 raeburn 14591: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14592: if ($lctype ne 'community') {
14593: $lctype = 'course';
14594: }
1.566 albertel 14595: if ($clonehome eq 'no_host') {
1.944 raeburn 14596: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14597: $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'});
14598: } else {
14599: $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'});
14600: }
1.566 albertel 14601: } else {
14602: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 14603: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14604: if ($clonedesc{'type'} ne 'Community') {
14605: $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'});
14606: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14607: }
14608: }
1.882 raeburn 14609: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
14610: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 14611: $can_clone = 1;
14612: } else {
1.1221 raeburn 14613: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 14614: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 14615: if ($clonehash{'cloners'} eq '') {
14616: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
14617: if ($domdefs{'canclone'}) {
14618: unless ($domdefs{'canclone'} eq 'none') {
14619: if ($domdefs{'canclone'} eq 'domain') {
14620: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
14621: $can_clone = 1;
14622: }
14623: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14624: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
14625: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
14626: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
14627: $can_clone = 1;
14628: }
14629: }
14630: }
14631: }
1.578 raeburn 14632: } else {
1.1221 raeburn 14633: my @cloners = split(/,/,$clonehash{'cloners'});
14634: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 14635: $can_clone = 1;
1.1221 raeburn 14636: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 14637: $can_clone = 1;
1.1225 raeburn 14638: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
14639: $can_clone = 1;
1.1221 raeburn 14640: }
14641: unless ($can_clone) {
1.1225 raeburn 14642: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14643: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 14644: my (%gotdomdefaults,%gotcodedefaults);
14645: foreach my $cloner (@cloners) {
14646: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
14647: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
14648: my (%codedefaults,@code_order);
14649: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
14650: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
14651: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
14652: }
14653: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
14654: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
14655: }
14656: } else {
14657: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
14658: \%codedefaults,
14659: \@code_order);
14660: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
14661: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
14662: }
14663: if (@code_order > 0) {
14664: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
14665: $cloner,$clonehash{'internal.coursecode'},
14666: $args->{'crscode'})) {
14667: $can_clone = 1;
14668: last;
14669: }
14670: }
14671: }
14672: }
14673: }
1.1225 raeburn 14674: }
14675: }
14676: unless ($can_clone) {
14677: my $ccrole = 'cc';
14678: if ($args->{'crstype'} eq 'Community') {
14679: $ccrole = 'co';
14680: }
14681: my %roleshash =
14682: &Apache::lonnet::get_my_roles($args->{'ccuname'},
14683: $args->{'ccdomain'},
14684: 'userroles',['active'],[$ccrole],
14685: [$args->{'clonedomain'}]);
14686: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
14687: $can_clone = 1;
14688: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
14689: $args->{'ccuname'},$args->{'ccdomain'})) {
14690: $can_clone = 1;
1.1221 raeburn 14691: }
14692: }
14693: unless ($can_clone) {
14694: if ($args->{'crstype'} eq 'Community') {
14695: $clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
1.942 raeburn 14696: } else {
1.1221 raeburn 14697: $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'});
14698: }
1.566 albertel 14699: }
1.578 raeburn 14700: }
1.566 albertel 14701: }
14702: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14703: }
14704:
1.444 albertel 14705: sub construct_course {
1.1166 raeburn 14706: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 14707: my $outcome;
1.541 raeburn 14708: my $linefeed = '<br />'."\n";
14709: if ($context eq 'auto') {
14710: $linefeed = "\n";
14711: }
1.566 albertel 14712:
14713: #
14714: # Are we cloning?
14715: #
14716: my ($can_clone, $clonemsg, $cloneid, $clonehome);
14717: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 14718: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 14719: if ($context ne 'auto') {
1.578 raeburn 14720: if ($clonemsg ne '') {
14721: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
14722: }
1.566 albertel 14723: }
14724: $outcome .= $clonemsg.$linefeed;
14725:
14726: if (!$can_clone) {
14727: return (0,$outcome);
14728: }
14729: }
14730:
1.444 albertel 14731: #
14732: # Open course
14733: #
14734: my $crstype = lc($args->{'crstype'});
14735: my %cenv=();
14736: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
14737: $args->{'cdescr'},
14738: $args->{'curl'},
14739: $args->{'course_home'},
14740: $args->{'nonstandard'},
14741: $args->{'crscode'},
14742: $args->{'ccuname'}.':'.
14743: $args->{'ccdomain'},
1.882 raeburn 14744: $args->{'crstype'},
1.885 raeburn 14745: $cnum,$context,$category);
1.444 albertel 14746:
14747: # Note: The testing routines depend on this being output; see
14748: # Utils::Course. This needs to at least be output as a comment
14749: # if anyone ever decides to not show this, and Utils::Course::new
14750: # will need to be suitably modified.
1.541 raeburn 14751: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 14752: if ($$courseid =~ /^error:/) {
14753: return (0,$outcome);
14754: }
14755:
1.444 albertel 14756: #
14757: # Check if created correctly
14758: #
1.479 albertel 14759: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 14760: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 14761: if ($crsuhome eq 'no_host') {
14762: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
14763: return (0,$outcome);
14764: }
1.541 raeburn 14765: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 14766:
1.444 albertel 14767: #
1.566 albertel 14768: # Do the cloning
14769: #
14770: if ($can_clone && $cloneid) {
14771: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14772: if ($context ne 'auto') {
14773: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14774: }
14775: $outcome .= $clonemsg.$linefeed;
14776: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14777: # Copy all files
1.637 www 14778: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14779: # Restore URL
1.566 albertel 14780: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14781: # Restore title
1.566 albertel 14782: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14783: # Restore creation date, creator and creation context.
14784: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14785: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14786: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14787: # Mark as cloned
1.566 albertel 14788: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14789: # Need to clone grading mode
14790: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14791: $cenv{'grading'}=$newenv{'grading'};
14792: # Do not clone these environment entries
14793: &Apache::lonnet::del('environment',
14794: ['default_enrollment_start_date',
14795: 'default_enrollment_end_date',
14796: 'question.email',
14797: 'policy.email',
14798: 'comment.email',
14799: 'pch.users.denied',
1.725 raeburn 14800: 'plc.users.denied',
14801: 'hidefromcat',
1.1121 raeburn 14802: 'checkforpriv',
1.1166 raeburn 14803: 'categories',
14804: 'internal.uniquecode'],
1.638 www 14805: $$crsudom,$$crsunum);
1.1170 raeburn 14806: if ($args->{'textbook'}) {
14807: $cenv{'internal.textbook'} = $args->{'textbook'};
14808: }
1.444 albertel 14809: }
1.566 albertel 14810:
1.444 albertel 14811: #
14812: # Set environment (will override cloned, if existing)
14813: #
14814: my @sections = ();
14815: my @xlists = ();
14816: if ($args->{'crstype'}) {
14817: $cenv{'type'}=$args->{'crstype'};
14818: }
14819: if ($args->{'crsid'}) {
14820: $cenv{'courseid'}=$args->{'crsid'};
14821: }
14822: if ($args->{'crscode'}) {
14823: $cenv{'internal.coursecode'}=$args->{'crscode'};
14824: }
14825: if ($args->{'crsquota'} ne '') {
14826: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14827: } else {
14828: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14829: }
14830: if ($args->{'ccuname'}) {
14831: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14832: ':'.$args->{'ccdomain'};
14833: } else {
14834: $cenv{'internal.courseowner'} = $args->{'curruser'};
14835: }
1.1116 raeburn 14836: if ($args->{'defaultcredits'}) {
14837: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14838: }
1.444 albertel 14839: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14840: if ($args->{'crssections'}) {
14841: $cenv{'internal.sectionnums'} = '';
14842: if ($args->{'crssections'} =~ m/,/) {
14843: @sections = split/,/,$args->{'crssections'};
14844: } else {
14845: $sections[0] = $args->{'crssections'};
14846: }
14847: if (@sections > 0) {
14848: foreach my $item (@sections) {
14849: my ($sec,$gp) = split/:/,$item;
14850: my $class = $args->{'crscode'}.$sec;
14851: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14852: $cenv{'internal.sectionnums'} .= $item.',';
14853: unless ($addcheck eq 'ok') {
14854: push @badclasses, $class;
14855: }
14856: }
14857: $cenv{'internal.sectionnums'} =~ s/,$//;
14858: }
14859: }
14860: # do not hide course coordinator from staff listing,
14861: # even if privileged
14862: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 14863: # add course coordinator's domain to domains to check for privileged users
14864: # if different to course domain
14865: if ($$crsudom ne $args->{'ccdomain'}) {
14866: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14867: }
1.444 albertel 14868: # add crosslistings
14869: if ($args->{'crsxlist'}) {
14870: $cenv{'internal.crosslistings'}='';
14871: if ($args->{'crsxlist'} =~ m/,/) {
14872: @xlists = split/,/,$args->{'crsxlist'};
14873: } else {
14874: $xlists[0] = $args->{'crsxlist'};
14875: }
14876: if (@xlists > 0) {
14877: foreach my $item (@xlists) {
14878: my ($xl,$gp) = split/:/,$item;
14879: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14880: $cenv{'internal.crosslistings'} .= $item.',';
14881: unless ($addcheck eq 'ok') {
14882: push @badclasses, $xl;
14883: }
14884: }
14885: $cenv{'internal.crosslistings'} =~ s/,$//;
14886: }
14887: }
14888: if ($args->{'autoadds'}) {
14889: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14890: }
14891: if ($args->{'autodrops'}) {
14892: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14893: }
14894: # check for notification of enrollment changes
14895: my @notified = ();
14896: if ($args->{'notify_owner'}) {
14897: if ($args->{'ccuname'} ne '') {
14898: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14899: }
14900: }
14901: if ($args->{'notify_dc'}) {
14902: if ($uname ne '') {
1.630 raeburn 14903: push(@notified,$uname.':'.$udom);
1.444 albertel 14904: }
14905: }
14906: if (@notified > 0) {
14907: my $notifylist;
14908: if (@notified > 1) {
14909: $notifylist = join(',',@notified);
14910: } else {
14911: $notifylist = $notified[0];
14912: }
14913: $cenv{'internal.notifylist'} = $notifylist;
14914: }
14915: if (@badclasses > 0) {
14916: my %lt=&Apache::lonlocal::texthash(
14917: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course. However, if automated course roster updates are enabled for this class, these particular sections/crosslistings will not contribute towards enrollment, because the user identified as the course owner for this LON-CAPA course',
14918: 'dnhr' => 'does not have rights to access enrollment in these classes',
14919: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14920: );
1.541 raeburn 14921: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14922: ' ('.$lt{'adby'}.')';
14923: if ($context eq 'auto') {
14924: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14925: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14926: foreach my $item (@badclasses) {
14927: if ($context eq 'auto') {
14928: $outcome .= " - $item\n";
14929: } else {
14930: $outcome .= "<li>$item</li>\n";
14931: }
14932: }
14933: if ($context eq 'auto') {
14934: $outcome .= $linefeed;
14935: } else {
1.566 albertel 14936: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14937: }
14938: }
1.444 albertel 14939: }
14940: if ($args->{'no_end_date'}) {
14941: $args->{'endaccess'} = 0;
14942: }
14943: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14944: $cenv{'internal.autoend'}=$args->{'enrollend'};
14945: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14946: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14947: if ($args->{'showphotos'}) {
14948: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14949: }
14950: $cenv{'internal.authtype'} = $args->{'authtype'};
14951: $cenv{'internal.autharg'} = $args->{'autharg'};
14952: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14953: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14954: 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');
14955: if ($context eq 'auto') {
14956: $outcome .= $krb_msg;
14957: } else {
1.566 albertel 14958: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14959: }
14960: $outcome .= $linefeed;
1.444 albertel 14961: }
14962: }
14963: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14964: if ($args->{'setpolicy'}) {
14965: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14966: }
14967: if ($args->{'setcontent'}) {
14968: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14969: }
14970: }
14971: if ($args->{'reshome'}) {
14972: $cenv{'reshome'}=$args->{'reshome'}.'/';
14973: $cenv{'reshome'}=~s/\/+$/\//;
14974: }
14975: #
14976: # course has keyed access
14977: #
14978: if ($args->{'setkeys'}) {
14979: $cenv{'keyaccess'}='yes';
14980: }
14981: # if specified, key authority is not course, but user
14982: # only active if keyaccess is yes
14983: if ($args->{'keyauth'}) {
1.487 albertel 14984: my ($user,$domain) = split(':',$args->{'keyauth'});
14985: $user = &LONCAPA::clean_username($user);
14986: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14987: if ($user ne '' && $domain ne '') {
1.487 albertel 14988: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14989: }
14990: }
14991:
1.1166 raeburn 14992: #
1.1167 raeburn 14993: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 14994: #
14995: if ($args->{'uniquecode'}) {
14996: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14997: if ($code) {
14998: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 14999: my %crsinfo =
15000: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15001: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15002: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15003: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15004: }
1.1166 raeburn 15005: if (ref($coderef)) {
15006: $$coderef = $code;
15007: }
15008: }
15009: }
15010:
1.444 albertel 15011: if ($args->{'disresdis'}) {
15012: $cenv{'pch.roles.denied'}='st';
15013: }
15014: if ($args->{'disablechat'}) {
15015: $cenv{'plc.roles.denied'}='st';
15016: }
15017:
15018: # Record we've not yet viewed the Course Initialization Helper for this
15019: # course
15020: $cenv{'course.helper.not.run'} = 1;
15021: #
15022: # Use new Randomseed
15023: #
15024: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15025: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15026: #
15027: # The encryption code and receipt prefix for this course
15028: #
15029: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15030: $cenv{'internal.encpref'}=100+int(9*rand(99));
15031: #
15032: # By default, use standard grading
15033: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15034:
1.541 raeburn 15035: $outcome .= $linefeed.&mt('Setting environment').': '.
15036: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15037: #
15038: # Open all assignments
15039: #
15040: if ($args->{'openall'}) {
15041: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15042: my %storecontent = ($storeunder => time,
15043: $storeunder.'.type' => 'date_start');
15044:
15045: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15046: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15047: }
15048: #
15049: # Set first page
15050: #
15051: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15052: || ($cloneid)) {
1.445 albertel 15053: use LONCAPA::map;
1.444 albertel 15054: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15055:
15056: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15057: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15058:
1.444 albertel 15059: $outcome .= ($fatal?$errtext:'read ok').' - ';
15060: my $title; my $url;
15061: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15062: $title=&mt('Syllabus');
1.444 albertel 15063: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15064: } else {
1.963 raeburn 15065: $title=&mt('Table of Contents');
1.444 albertel 15066: $url='/adm/navmaps';
15067: }
1.445 albertel 15068:
15069: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15070: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15071:
15072: if ($errtext) { $fatal=2; }
1.541 raeburn 15073: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15074: }
1.566 albertel 15075:
15076: return (1,$outcome);
1.444 albertel 15077: }
15078:
1.1166 raeburn 15079: sub make_unique_code {
15080: my ($cdom,$cnum) = @_;
15081: # get lock on uniquecodes db
15082: my $lockhash = {
15083: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15084: ':'.$env{'user.domain'},
15085: };
15086: my $tries = 0;
15087: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15088: my ($code,$error);
15089:
15090: while (($gotlock ne 'ok') && ($tries<3)) {
15091: $tries ++;
15092: sleep 1;
15093: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15094: }
15095: if ($gotlock eq 'ok') {
15096: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15097: my $gotcode;
15098: my $attempts = 0;
15099: while ((!$gotcode) && ($attempts < 100)) {
15100: $code = &generate_code();
15101: if (!exists($currcodes{$code})) {
15102: $gotcode = 1;
15103: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15104: $error = 'nostore';
15105: }
15106: }
15107: $attempts ++;
15108: }
15109: my @del_lock = ($cnum."\0".'uniquecodes');
15110: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15111: } else {
15112: $error = 'nolock';
15113: }
15114: return ($code,$error);
15115: }
15116:
15117: sub generate_code {
15118: my $code;
15119: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15120: for (my $i=0; $i<6; $i++) {
15121: my $lettnum = int (rand 2);
15122: my $item = '';
15123: if ($lettnum) {
15124: $item = $letts[int( rand(18) )];
15125: } else {
15126: $item = 1+int( rand(8) );
15127: }
15128: $code .= $item;
15129: }
15130: return $code;
15131: }
15132:
1.444 albertel 15133: ############################################################
15134: ############################################################
15135:
1.953 droeschl 15136: #SD
15137: # only Community and Course, or anything else?
1.378 raeburn 15138: sub course_type {
15139: my ($cid) = @_;
15140: if (!defined($cid)) {
15141: $cid = $env{'request.course.id'};
15142: }
1.404 albertel 15143: if (defined($env{'course.'.$cid.'.type'})) {
15144: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15145: } else {
15146: return 'Course';
1.377 raeburn 15147: }
15148: }
1.156 albertel 15149:
1.406 raeburn 15150: sub group_term {
15151: my $crstype = &course_type();
15152: my %names = (
15153: 'Course' => 'group',
1.865 raeburn 15154: 'Community' => 'group',
1.406 raeburn 15155: );
15156: return $names{$crstype};
15157: }
15158:
1.902 raeburn 15159: sub course_types {
1.1165 raeburn 15160: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15161: my %typename = (
15162: official => 'Official course',
15163: unofficial => 'Unofficial course',
15164: community => 'Community',
1.1165 raeburn 15165: textbook => 'Textbook course',
1.902 raeburn 15166: );
15167: return (\@types,\%typename);
15168: }
15169:
1.156 albertel 15170: sub icon {
15171: my ($file)=@_;
1.505 albertel 15172: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15173: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15174: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15175: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15176: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15177: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15178: $curfext.".gif") {
15179: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15180: $curfext.".gif";
15181: }
15182: }
1.249 albertel 15183: return &lonhttpdurl($iconname);
1.154 albertel 15184: }
1.84 albertel 15185:
1.575 albertel 15186: sub lonhttpdurl {
1.692 www 15187: #
15188: # Had been used for "small fry" static images on separate port 8080.
15189: # Modify here if lightweight http functionality desired again.
15190: # Currently eliminated due to increasing firewall issues.
15191: #
1.575 albertel 15192: my ($url)=@_;
1.692 www 15193: return $url;
1.215 albertel 15194: }
15195:
1.213 albertel 15196: sub connection_aborted {
15197: my ($r)=@_;
15198: $r->print(" ");$r->rflush();
15199: my $c = $r->connection;
15200: return $c->aborted();
15201: }
15202:
1.221 foxr 15203: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15204: # strings as 'strings'.
15205: sub escape_single {
1.221 foxr 15206: my ($input) = @_;
1.223 albertel 15207: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15208: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15209: return $input;
15210: }
1.223 albertel 15211:
1.222 foxr 15212: # Same as escape_single, but escape's "'s This
15213: # can be used for "strings"
15214: sub escape_double {
15215: my ($input) = @_;
15216: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15217: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15218: return $input;
15219: }
1.223 albertel 15220:
1.222 foxr 15221: # Escapes the last element of a full URL.
15222: sub escape_url {
15223: my ($url) = @_;
1.238 raeburn 15224: my @urlslices = split(/\//, $url,-1);
1.369 www 15225: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 15226: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15227: }
1.462 albertel 15228:
1.820 raeburn 15229: sub compare_arrays {
15230: my ($arrayref1,$arrayref2) = @_;
15231: my (@difference,%count);
15232: @difference = ();
15233: %count = ();
15234: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15235: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15236: foreach my $element (keys(%count)) {
15237: if ($count{$element} == 1) {
15238: push(@difference,$element);
15239: }
15240: }
15241: }
15242: return @difference;
15243: }
15244:
1.817 bisitz 15245: # -------------------------------------------------------- Initialize user login
1.462 albertel 15246: sub init_user_environment {
1.463 albertel 15247: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15248: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15249:
15250: my $public=($username eq 'public' && $domain eq 'public');
15251:
15252: # See if old ID present, if so, remove
15253:
1.1062 raeburn 15254: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15255: my $now=time;
15256:
15257: if ($public) {
15258: my $max_public=100;
15259: my $oldest;
15260: my $oldest_time=0;
15261: for(my $next=1;$next<=$max_public;$next++) {
15262: if (-e $lonids."/publicuser_$next.id") {
15263: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15264: if ($mtime<$oldest_time || !$oldest_time) {
15265: $oldest_time=$mtime;
15266: $oldest=$next;
15267: }
15268: } else {
15269: $cookie="publicuser_$next";
15270: last;
15271: }
15272: }
15273: if (!$cookie) { $cookie="publicuser_$oldest"; }
15274: } else {
1.463 albertel 15275: # if this isn't a robot, kill any existing non-robot sessions
15276: if (!$args->{'robot'}) {
15277: opendir(DIR,$lonids);
15278: while ($filename=readdir(DIR)) {
15279: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
15280: unlink($lonids.'/'.$filename);
15281: }
1.462 albertel 15282: }
1.463 albertel 15283: closedir(DIR);
1.1204 raeburn 15284: # If there is a undeleted lockfile for the user's paste buffer remove it.
15285: my $namespace = 'nohist_courseeditor';
15286: my $lockingkey = 'paste'."\0".'locked_num';
15287: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15288: $domain,$username);
15289: if (exists($lockhash{$lockingkey})) {
15290: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15291: unless ($delresult eq 'ok') {
15292: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15293: }
15294: }
1.462 albertel 15295: }
15296: # Give them a new cookie
1.463 albertel 15297: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15298: : $now.$$.int(rand(10000)));
1.463 albertel 15299: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15300:
15301: # Initialize roles
15302:
1.1062 raeburn 15303: ($userroles,$firstaccenv,$timerintenv) =
15304: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15305: }
15306: # ------------------------------------ Check browser type and MathML capability
15307:
1.1194 raeburn 15308: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15309: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15310:
15311: # ------------------------------------------------------------- Get environment
15312:
15313: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15314: my ($tmp) = keys(%userenv);
15315: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15316: } else {
15317: undef(%userenv);
15318: }
15319: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15320: $form->{'interface'}=$userenv{'interface'};
15321: }
15322: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15323:
15324: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15325: foreach my $option ('interface','localpath','localres') {
15326: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15327: }
15328: # --------------------------------------------------------- Write first profile
15329:
15330: {
15331: my %initial_env =
15332: ("user.name" => $username,
15333: "user.domain" => $domain,
15334: "user.home" => $authhost,
15335: "browser.type" => $clientbrowser,
15336: "browser.version" => $clientversion,
15337: "browser.mathml" => $clientmathml,
15338: "browser.unicode" => $clientunicode,
15339: "browser.os" => $clientos,
1.1137 raeburn 15340: "browser.mobile" => $clientmobile,
1.1141 raeburn 15341: "browser.info" => $clientinfo,
1.1194 raeburn 15342: "browser.osversion" => $clientosversion,
1.462 albertel 15343: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15344: "request.course.fn" => '',
15345: "request.course.uri" => '',
15346: "request.course.sec" => '',
15347: "request.role" => 'cm',
15348: "request.role.adv" => $env{'user.adv'},
15349: "request.host" => $ENV{'REMOTE_ADDR'},);
15350:
15351: if ($form->{'localpath'}) {
15352: $initial_env{"browser.localpath"} = $form->{'localpath'};
15353: $initial_env{"browser.localres"} = $form->{'localres'};
15354: }
15355:
15356: if ($form->{'interface'}) {
15357: $form->{'interface'}=~s/\W//gs;
15358: $initial_env{"browser.interface"} = $form->{'interface'};
15359: $env{'browser.interface'}=$form->{'interface'};
15360: }
15361:
1.1157 raeburn 15362: if ($form->{'iptoken'}) {
15363: my $lonhost = $r->dir_config('lonHostID');
15364: $initial_env{"user.noloadbalance"} = $lonhost;
15365: $env{'user.noloadbalance'} = $lonhost;
15366: }
15367:
1.981 raeburn 15368: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 15369: my %domdef;
15370: unless ($domain eq 'public') {
15371: %domdef = &Apache::lonnet::get_domain_defaults($domain);
15372: }
1.980 raeburn 15373:
1.1081 raeburn 15374: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 15375: $userenv{'availabletools.'.$tool} =
1.980 raeburn 15376: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15377: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 15378: }
15379:
1.1165 raeburn 15380: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 15381: $userenv{'canrequest.'.$crstype} =
15382: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 15383: 'reload','requestcourses',
15384: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 15385: }
15386:
1.1092 raeburn 15387: $userenv{'canrequest.author'} =
15388: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15389: 'reload','requestauthor',
15390: \%userenv,\%domdef,\%is_adv);
15391: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15392: $domain,$username);
15393: my $reqstatus = $reqauthor{'author_status'};
15394: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15395: if (ref($reqauthor{'author'}) eq 'HASH') {
15396: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15397: $reqauthor{'author'}{'timestamp'};
15398: }
15399: }
15400:
1.462 albertel 15401: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15402:
1.462 albertel 15403: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15404: &GDBM_WRCREAT(),0640)) {
15405: &_add_to_env(\%disk_env,\%initial_env);
15406: &_add_to_env(\%disk_env,\%userenv,'environment.');
15407: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15408: if (ref($firstaccenv) eq 'HASH') {
15409: &_add_to_env(\%disk_env,$firstaccenv);
15410: }
15411: if (ref($timerintenv) eq 'HASH') {
15412: &_add_to_env(\%disk_env,$timerintenv);
15413: }
1.463 albertel 15414: if (ref($args->{'extra_env'})) {
15415: &_add_to_env(\%disk_env,$args->{'extra_env'});
15416: }
1.462 albertel 15417: untie(%disk_env);
15418: } else {
1.705 tempelho 15419: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15420: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15421: return 'error: '.$!;
15422: }
15423: }
15424: $env{'request.role'}='cm';
15425: $env{'request.role.adv'}=$env{'user.adv'};
15426: $env{'browser.type'}=$clientbrowser;
15427:
15428: return $cookie;
15429:
15430: }
15431:
15432: sub _add_to_env {
15433: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15434: if (ref($env_data) eq 'HASH') {
15435: while (my ($key,$value) = each(%$env_data)) {
15436: $idf->{$prefix.$key} = $value;
15437: $env{$prefix.$key} = $value;
15438: }
1.462 albertel 15439: }
15440: }
15441:
1.685 tempelho 15442: # --- Get the symbolic name of a problem and the url
15443: sub get_symb {
15444: my ($request,$silent) = @_;
1.726 raeburn 15445: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15446: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15447: if ($symb eq '') {
15448: if (!$silent) {
1.1071 raeburn 15449: if (ref($request)) {
15450: $request->print("Unable to handle ambiguous references:$url:.");
15451: }
1.685 tempelho 15452: return ();
15453: }
15454: }
15455: &Apache::lonenc::check_decrypt(\$symb);
15456: return ($symb);
15457: }
15458:
15459: # --------------------------------------------------------------Get annotation
15460:
15461: sub get_annotation {
15462: my ($symb,$enc) = @_;
15463:
15464: my $key = $symb;
15465: if (!$enc) {
15466: $key =
15467: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15468: }
15469: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15470: return $annotation{$key};
15471: }
15472:
15473: sub clean_symb {
1.731 raeburn 15474: my ($symb,$delete_enc) = @_;
1.685 tempelho 15475:
15476: &Apache::lonenc::check_decrypt(\$symb);
15477: my $enc = $env{'request.enc'};
1.731 raeburn 15478: if ($delete_enc) {
1.730 raeburn 15479: delete($env{'request.enc'});
15480: }
1.685 tempelho 15481:
15482: return ($symb,$enc);
15483: }
1.462 albertel 15484:
1.1181 raeburn 15485: ############################################################
15486: ############################################################
15487:
15488: =pod
15489:
15490: =head1 Routines for building display used to search for courses
15491:
15492:
15493: =over 4
15494:
15495: =item * &build_filters()
15496:
15497: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 15498: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15499: and quotacheck.pl
15500:
1.1181 raeburn 15501:
15502: Inputs:
15503:
15504: filterlist - anonymous array of fields to include as potential filters
15505:
15506: crstype - course type
15507:
15508: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15509: to pop-open a course selector (will contain "extra element").
15510:
15511: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15512:
15513: filter - anonymous hash of criteria and their values
15514:
15515: action - form action
15516:
15517: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15518:
1.1182 raeburn 15519: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 15520:
15521: cloneruname - username of owner of new course who wants to clone
15522:
15523: clonerudom - domain of owner of new course who wants to clone
15524:
15525: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15526:
15527: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15528:
15529: codedom - domain
15530:
15531: formname - value of form element named "form".
15532:
15533: fixeddom - domain, if fixed.
15534:
15535: prevphase - value to assign to form element named "phase" when going back to the previous screen
15536:
15537: cnameelement - name of form element in form on opener page which will receive title of selected course
15538:
15539: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15540:
15541: cdomelement - name of form element in form on opener page which will receive domain of selected course
15542:
15543: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15544:
15545: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
15546:
15547: clonewarning - warning message about missing information for intended course owner when DC creates a course
15548:
1.1182 raeburn 15549:
1.1181 raeburn 15550: Returns: $output - HTML for display of search criteria, and hidden form elements.
15551:
1.1182 raeburn 15552:
1.1181 raeburn 15553: Side Effects: None
15554:
15555: =cut
15556:
15557: # ---------------------------------------------- search for courses based on last activity etc.
15558:
15559: sub build_filters {
15560: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
15561: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
15562: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
15563: $cnameelement,$cnumelement,$cdomelement,$setroles,
15564: $clonetext,$clonewarning) = @_;
1.1182 raeburn 15565: my ($list,$jscript);
1.1181 raeburn 15566: my $onchange = 'javascript:updateFilters(this)';
15567: my ($domainselectform,$sincefilterform,$createdfilterform,
15568: $ownerdomselectform,$persondomselectform,$instcodeform,
15569: $typeselectform,$instcodetitle);
15570: if ($formname eq '') {
15571: $formname = $caller;
15572: }
15573: foreach my $item (@{$filterlist}) {
15574: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
15575: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
15576: if ($item eq 'domainfilter') {
15577: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
15578: } elsif ($item eq 'coursefilter') {
15579: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
15580: } elsif ($item eq 'ownerfilter') {
15581: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15582: } elsif ($item eq 'ownerdomfilter') {
15583: $filter->{'ownerdomfilter'} =
15584: &LONCAPA::clean_domain($filter->{$item});
15585: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
15586: 'ownerdomfilter',1);
15587: } elsif ($item eq 'personfilter') {
15588: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15589: } elsif ($item eq 'persondomfilter') {
15590: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
15591: 'persondomfilter',1);
15592: } else {
15593: $filter->{$item} =~ s/\W//g;
15594: }
15595: if (!$filter->{$item}) {
15596: $filter->{$item} = '';
15597: }
15598: }
15599: if ($item eq 'domainfilter') {
15600: my $allow_blank = 1;
15601: if ($formname eq 'portform') {
15602: $allow_blank=0;
15603: } elsif ($formname eq 'studentform') {
15604: $allow_blank=0;
15605: }
15606: if ($fixeddom) {
15607: $domainselectform = '<input type="hidden" name="domainfilter"'.
15608: ' value="'.$codedom.'" />'.
15609: &Apache::lonnet::domain($codedom,'description');
15610: } else {
15611: $domainselectform = &select_dom_form($filter->{$item},
15612: 'domainfilter',
15613: $allow_blank,'',$onchange);
15614: }
15615: } else {
15616: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
15617: }
15618: }
15619:
15620: # last course activity filter and selection
15621: $sincefilterform = &timebased_select_form('sincefilter',$filter);
15622:
15623: # course created filter and selection
15624: if (exists($filter->{'createdfilter'})) {
15625: $createdfilterform = &timebased_select_form('createdfilter',$filter);
15626: }
15627:
15628: my %lt = &Apache::lonlocal::texthash(
15629: 'cac' => "$crstype Activity",
15630: 'ccr' => "$crstype Created",
15631: 'cde' => "$crstype Title",
15632: 'cdo' => "$crstype Domain",
15633: 'ins' => 'Institutional Code',
15634: 'inc' => 'Institutional Categorization',
15635: 'cow' => "$crstype Owner/Co-owner",
15636: 'cop' => "$crstype Personnel Includes",
15637: 'cog' => 'Type',
15638: );
15639:
15640: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15641: my $typeval = 'Course';
15642: if ($crstype eq 'Community') {
15643: $typeval = 'Community';
15644: }
15645: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
15646: } else {
15647: $typeselectform = '<select name="type" size="1"';
15648: if ($onchange) {
15649: $typeselectform .= ' onchange="'.$onchange.'"';
15650: }
15651: $typeselectform .= '>'."\n";
15652: foreach my $posstype ('Course','Community') {
15653: $typeselectform.='<option value="'.$posstype.'"'.
15654: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
15655: }
15656: $typeselectform.="</select>";
15657: }
15658:
15659: my ($cloneableonlyform,$cloneabletitle);
15660: if (exists($filter->{'cloneableonly'})) {
15661: my $cloneableon = '';
15662: my $cloneableoff = ' checked="checked"';
15663: if ($filter->{'cloneableonly'}) {
15664: $cloneableon = $cloneableoff;
15665: $cloneableoff = '';
15666: }
15667: $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>';
15668: if ($formname eq 'ccrs') {
1.1187 bisitz 15669: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 15670: } else {
15671: $cloneabletitle = &mt('Cloneable by you');
15672: }
15673: }
15674: my $officialjs;
15675: if ($crstype eq 'Course') {
15676: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 15677: # if (($fixeddom) || ($formname eq 'requestcrs') ||
15678: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
15679: if ($codedom) {
1.1181 raeburn 15680: $officialjs = 1;
15681: ($instcodeform,$jscript,$$numtitlesref) =
15682: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
15683: $officialjs,$codetitlesref);
15684: if ($jscript) {
1.1182 raeburn 15685: $jscript = '<script type="text/javascript">'."\n".
15686: '// <![CDATA['."\n".
15687: $jscript."\n".
15688: '// ]]>'."\n".
15689: '</script>'."\n";
1.1181 raeburn 15690: }
15691: }
15692: if ($instcodeform eq '') {
15693: $instcodeform =
15694: '<input type="text" name="instcodefilter" size="10" value="'.
15695: $list->{'instcodefilter'}.'" />';
15696: $instcodetitle = $lt{'ins'};
15697: } else {
15698: $instcodetitle = $lt{'inc'};
15699: }
15700: if ($fixeddom) {
15701: $instcodetitle .= '<br />('.$codedom.')';
15702: }
15703: }
15704: }
15705: my $output = qq|
15706: <form method="post" name="filterpicker" action="$action">
15707: <input type="hidden" name="form" value="$formname" />
15708: |;
15709: if ($formname eq 'modifycourse') {
15710: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
15711: '<input type="hidden" name="prevphase" value="'.
15712: $prevphase.'" />'."\n";
1.1198 musolffc 15713: } elsif ($formname eq 'quotacheck') {
15714: $output .= qq|
15715: <input type="hidden" name="sortby" value="" />
15716: <input type="hidden" name="sortorder" value="" />
15717: |;
15718: } else {
1.1181 raeburn 15719: my $name_input;
15720: if ($cnameelement ne '') {
15721: $name_input = '<input type="hidden" name="cnameelement" value="'.
15722: $cnameelement.'" />';
15723: }
15724: $output .= qq|
1.1182 raeburn 15725: <input type="hidden" name="cnumelement" value="$cnumelement" />
15726: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 15727: $name_input
15728: $roleelement
15729: $multelement
15730: $typeelement
15731: |;
15732: if ($formname eq 'portform') {
15733: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
15734: }
15735: }
15736: if ($fixeddom) {
15737: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
15738: }
15739: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
15740: if ($sincefilterform) {
15741: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
15742: .$sincefilterform
15743: .&Apache::lonhtmlcommon::row_closure();
15744: }
15745: if ($createdfilterform) {
15746: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
15747: .$createdfilterform
15748: .&Apache::lonhtmlcommon::row_closure();
15749: }
15750: if ($domainselectform) {
15751: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
15752: .$domainselectform
15753: .&Apache::lonhtmlcommon::row_closure();
15754: }
15755: if ($typeselectform) {
15756: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15757: $output .= $typeselectform;
15758: } else {
15759: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
15760: .$typeselectform
15761: .&Apache::lonhtmlcommon::row_closure();
15762: }
15763: }
15764: if ($instcodeform) {
15765: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
15766: .$instcodeform
15767: .&Apache::lonhtmlcommon::row_closure();
15768: }
15769: if (exists($filter->{'ownerfilter'})) {
15770: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
15771: '<table><tr><td>'.&mt('Username').'<br />'.
15772: '<input type="text" name="ownerfilter" size="20" value="'.
15773: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15774: $ownerdomselectform.'</td></tr></table>'.
15775: &Apache::lonhtmlcommon::row_closure();
15776: }
15777: if (exists($filter->{'personfilter'})) {
15778: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
15779: '<table><tr><td>'.&mt('Username').'<br />'.
15780: '<input type="text" name="personfilter" size="20" value="'.
15781: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15782: $persondomselectform.'</td></tr></table>'.
15783: &Apache::lonhtmlcommon::row_closure();
15784: }
15785: if (exists($filter->{'coursefilter'})) {
15786: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15787: .'<input type="text" name="coursefilter" size="25" value="'
15788: .$list->{'coursefilter'}.'" />'
15789: .&Apache::lonhtmlcommon::row_closure();
15790: }
15791: if ($cloneableonlyform) {
15792: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15793: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15794: }
15795: if (exists($filter->{'descriptfilter'})) {
15796: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15797: .'<input type="text" name="descriptfilter" size="40" value="'
15798: .$list->{'descriptfilter'}.'" />'
15799: .&Apache::lonhtmlcommon::row_closure(1);
15800: }
15801: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15802: '<input type="hidden" name="updater" value="" />'."\n".
15803: '<input type="submit" name="gosearch" value="'.
15804: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15805: return $jscript.$clonewarning.$output;
15806: }
15807:
15808: =pod
15809:
15810: =item * &timebased_select_form()
15811:
1.1182 raeburn 15812: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 15813: filter e.g., Course Activity, Course Created, when searching for courses
15814: or communities
15815:
15816: Inputs:
15817:
15818: item - name of form element (sincefilter or createdfilter)
15819:
15820: filter - anonymous hash of criteria and their values
15821:
15822: Returns: HTML for a select box contained a blank, then six time selections,
15823: with value set in incoming form variables currently selected.
15824:
15825: Side Effects: None
15826:
15827: =cut
15828:
15829: sub timebased_select_form {
15830: my ($item,$filter) = @_;
15831: if (ref($filter) eq 'HASH') {
15832: $filter->{$item} =~ s/[^\d-]//g;
15833: if (!$filter->{$item}) { $filter->{$item}=-1; }
15834: return &select_form(
15835: $filter->{$item},
15836: $item,
15837: { '-1' => '',
15838: '86400' => &mt('today'),
15839: '604800' => &mt('last week'),
15840: '2592000' => &mt('last month'),
15841: '7776000' => &mt('last three months'),
15842: '15552000' => &mt('last six months'),
15843: '31104000' => &mt('last year'),
15844: 'select_form_order' =>
15845: ['-1','86400','604800','2592000','7776000',
15846: '15552000','31104000']});
15847: }
15848: }
15849:
15850: =pod
15851:
15852: =item * &js_changer()
15853:
15854: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 15855: when course type or domain is changed, and also to hide 'Searching ...' on
15856: page load completion for page showing search result.
1.1181 raeburn 15857:
15858: Inputs: None
15859:
1.1183 raeburn 15860: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 15861:
15862: Side Effects: None
15863:
15864: =cut
15865:
15866: sub js_changer {
15867: return <<ENDJS;
15868: <script type="text/javascript">
15869: // <![CDATA[
15870: function updateFilters(caller) {
15871: if (typeof(caller) != "undefined") {
15872: document.filterpicker.updater.value = caller.name;
15873: }
15874: document.filterpicker.submit();
15875: }
1.1183 raeburn 15876:
15877: function hideSearching() {
15878: if (document.getElementById('searching')) {
15879: document.getElementById('searching').style.display = 'none';
15880: }
15881: return;
15882: }
15883:
1.1181 raeburn 15884: // ]]>
15885: </script>
15886:
15887: ENDJS
15888: }
15889:
15890: =pod
15891:
1.1182 raeburn 15892: =item * &search_courses()
15893:
15894: Process selected filters form course search form and pass to lonnet::courseiddump
15895: to retrieve a hash for which keys are courseIDs which match the selected filters.
15896:
15897: Inputs:
15898:
15899: dom - domain being searched
15900:
15901: type - course type ('Course' or 'Community' or '.' if any).
15902:
15903: filter - anonymous hash of criteria and their values
15904:
15905: numtitles - for institutional codes - number of categories
15906:
15907: cloneruname - optional username of new course owner
15908:
15909: clonerudom - optional domain of new course owner
15910:
1.1221 raeburn 15911: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 15912: (used when DC is using course creation form)
15913:
15914: codetitles - reference to array of titles of components in institutional codes (official courses).
15915:
1.1221 raeburn 15916: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
15917: (and so can clone automatically)
15918:
15919: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
15920:
15921: reqinstcode - institutional code of new course, where search_courses is used to identify potential
15922: courses to clone
1.1182 raeburn 15923:
15924: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
15925:
15926:
15927: Side Effects: None
15928:
15929: =cut
15930:
15931:
15932: sub search_courses {
1.1221 raeburn 15933: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
15934: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 15935: my (%courses,%showcourses,$cloner);
15936: if (($filter->{'ownerfilter'} ne '') ||
15937: ($filter->{'ownerdomfilter'} ne '')) {
15938: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
15939: $filter->{'ownerdomfilter'};
15940: }
15941: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
15942: if (!$filter->{$item}) {
15943: $filter->{$item}='.';
15944: }
15945: }
15946: my $now = time;
15947: my $timefilter =
15948: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
15949: my ($createdbefore,$createdafter);
15950: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
15951: $createdbefore = $now;
15952: $createdafter = $now-$filter->{'createdfilter'};
15953: }
15954: my ($instcodefilter,$regexpok);
15955: if ($numtitles) {
15956: if ($env{'form.official'} eq 'on') {
15957: $instcodefilter =
15958: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15959: $regexpok = 1;
15960: } elsif ($env{'form.official'} eq 'off') {
15961: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15962: unless ($instcodefilter eq '') {
15963: $regexpok = -1;
15964: }
15965: }
15966: } else {
15967: $instcodefilter = $filter->{'instcodefilter'};
15968: }
15969: if ($instcodefilter eq '') { $instcodefilter = '.'; }
15970: if ($type eq '') { $type = '.'; }
15971:
15972: if (($clonerudom ne '') && ($cloneruname ne '')) {
15973: $cloner = $cloneruname.':'.$clonerudom;
15974: }
15975: %courses = &Apache::lonnet::courseiddump($dom,
15976: $filter->{'descriptfilter'},
15977: $timefilter,
15978: $instcodefilter,
15979: $filter->{'combownerfilter'},
15980: $filter->{'coursefilter'},
15981: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 15982: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 15983: $filter->{'cloneableonly'},
15984: $createdbefore,$createdafter,undef,
1.1221 raeburn 15985: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 15986: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
15987: my $ccrole;
15988: if ($type eq 'Community') {
15989: $ccrole = 'co';
15990: } else {
15991: $ccrole = 'cc';
15992: }
15993: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
15994: $filter->{'persondomfilter'},
15995: 'userroles',undef,
15996: [$ccrole,'in','ad','ep','ta','cr'],
15997: $dom);
15998: foreach my $role (keys(%rolehash)) {
15999: my ($cnum,$cdom,$courserole) = split(':',$role);
16000: my $cid = $cdom.'_'.$cnum;
16001: if (exists($courses{$cid})) {
16002: if (ref($courses{$cid}) eq 'HASH') {
16003: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16004: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
16005: push (@{$courses{$cid}{roles}},$courserole);
16006: }
16007: } else {
16008: $courses{$cid}{roles} = [$courserole];
16009: }
16010: $showcourses{$cid} = $courses{$cid};
16011: }
16012: }
16013: }
16014: %courses = %showcourses;
16015: }
16016: return %courses;
16017: }
16018:
16019: =pod
16020:
1.1181 raeburn 16021: =back
16022:
1.1207 raeburn 16023: =head1 Routines for version requirements for current course.
16024:
16025: =over 4
16026:
16027: =item * &check_release_required()
16028:
16029: Compares required LON-CAPA version with version on server, and
16030: if required version is newer looks for a server with the required version.
16031:
16032: Looks first at servers in user's owen domain; if none suitable, looks at
16033: servers in course's domain are permitted to host sessions for user's domain.
16034:
16035: Inputs:
16036:
16037: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16038:
16039: $courseid - Course ID of current course
16040:
16041: $rolecode - User's current role in course (for switchserver query string).
16042:
16043: $required - LON-CAPA version needed by course (format: Major.Minor).
16044:
16045:
16046: Returns:
16047:
16048: $switchserver - query string tp append to /adm/switchserver call (if
16049: current server's LON-CAPA version is too old.
16050:
16051: $warning - Message is displayed if no suitable server could be found.
16052:
16053: =cut
16054:
16055: sub check_release_required {
16056: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16057: my ($switchserver,$warning);
16058: if ($required ne '') {
16059: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16060: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16061: if ($reqdmajor ne '' && $reqdminor ne '') {
16062: my $otherserver;
16063: if (($major eq '' && $minor eq '') ||
16064: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16065: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16066: my $switchlcrev =
16067: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16068: $userdomserver);
16069: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16070: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16071: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16072: my $cdom = $env{'course.'.$courseid.'.domain'};
16073: if ($cdom ne $env{'user.domain'}) {
16074: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16075: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16076: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16077: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16078: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16079: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16080: my $canhost =
16081: &Apache::lonnet::can_host_session($env{'user.domain'},
16082: $coursedomserver,
16083: $remoterev,
16084: $udomdefaults{'remotesessions'},
16085: $defdomdefaults{'hostedsessions'});
16086:
16087: if ($canhost) {
16088: $otherserver = $coursedomserver;
16089: } else {
16090: $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.");
16091: }
16092: } else {
16093: $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).");
16094: }
16095: } else {
16096: $otherserver = $userdomserver;
16097: }
16098: }
16099: if ($otherserver ne '') {
16100: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16101: }
16102: }
16103: }
16104: return ($switchserver,$warning);
16105: }
16106:
16107: =pod
16108:
16109: =item * &check_release_result()
16110:
16111: Inputs:
16112:
16113: $switchwarning - Warning message if no suitable server found to host session.
16114:
16115: $switchserver - query string to append to /adm/switchserver containing lonHostID
16116: and current role.
16117:
16118: Returns: HTML to display with information about requirement to switch server.
16119: Either displaying warning with link to Roles/Courses screen or
16120: display link to switchserver.
16121:
1.1181 raeburn 16122: =cut
16123:
1.1207 raeburn 16124: sub check_release_result {
16125: my ($switchwarning,$switchserver) = @_;
16126: my $output = &start_page('Selected course unavailable on this server').
16127: '<p class="LC_warning">';
16128: if ($switchwarning) {
16129: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16130: if (&show_course()) {
16131: $output .= &mt('Display courses');
16132: } else {
16133: $output .= &mt('Display roles');
16134: }
16135: $output .= '</a>';
16136: } elsif ($switchserver) {
16137: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16138: '<br />'.
16139: '<a href="/adm/switchserver?'.$switchserver.'">'.
16140: &mt('Switch Server').
16141: '</a>';
16142: }
16143: $output .= '</p>'.&end_page();
16144: return $output;
16145: }
16146:
16147: =pod
16148:
16149: =item * &needs_coursereinit()
16150:
16151: Determine if course contents stored for user's session needs to be
16152: refreshed, because content has changed since "Big Hash" last tied.
16153:
16154: Check for change is made if time last checked is more than 10 minutes ago
16155: (by default).
16156:
16157: Inputs:
16158:
16159: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16160:
16161: $interval (optional) - Time which may elapse (in s) between last check for content
16162: change in current course. (default: 600 s).
16163:
16164: Returns: an array; first element is:
16165:
16166: =over 4
16167:
16168: 'switch' - if content updates mean user's session
16169: needs to be switched to a server running a newer LON-CAPA version
16170:
16171: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16172: on current server hosting user's session
16173:
16174: '' - if no action required.
16175:
16176: =back
16177:
16178: If first item element is 'switch':
16179:
16180: second item is $switchwarning - Warning message if no suitable server found to host session.
16181:
16182: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16183: and current role.
16184:
16185: otherwise: no other elements returned.
16186:
16187: =back
16188:
16189: =cut
16190:
16191: sub needs_coursereinit {
16192: my ($loncaparev,$interval) = @_;
16193: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16194: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16195: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16196: my $now = time;
16197: if ($interval eq '') {
16198: $interval = 600;
16199: }
16200: if (($now-$env{'request.course.timechecked'})>$interval) {
16201: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16202: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16203: if ($lastchange > $env{'request.course.tied'}) {
16204: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16205: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16206: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16207: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16208: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16209: $curr_reqd_hash{'internal.releaserequired'}});
16210: my ($switchserver,$switchwarning) =
16211: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16212: $curr_reqd_hash{'internal.releaserequired'});
16213: if ($switchwarning ne '' || $switchserver ne '') {
16214: return ('switch',$switchwarning,$switchserver);
16215: }
16216: }
16217: }
16218: return ('update');
16219: }
16220: }
16221: return ();
16222: }
1.1181 raeburn 16223:
1.1083 raeburn 16224: sub update_content_constraints {
16225: my ($cdom,$cnum,$chome,$cid) = @_;
16226: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16227: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16228: my %checkresponsetypes;
16229: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1219 raeburn 16230: my ($item,$name,$value,$valmatch) = split(/:/,$key);
1.1083 raeburn 16231: if ($item eq 'resourcetag') {
16232: if ($name eq 'responsetype') {
16233: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16234: }
16235: }
16236: }
16237: my $navmap = Apache::lonnavmaps::navmap->new();
16238: if (defined($navmap)) {
16239: my %allresponses;
16240: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16241: my %responses = $res->responseTypes();
16242: foreach my $key (keys(%responses)) {
16243: next unless(exists($checkresponsetypes{$key}));
16244: $allresponses{$key} += $responses{$key};
16245: }
16246: }
16247: foreach my $key (keys(%allresponses)) {
16248: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16249: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16250: ($reqdmajor,$reqdminor) = ($major,$minor);
16251: }
16252: }
16253: undef($navmap);
16254: }
16255: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16256: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16257: }
16258: return;
16259: }
16260:
1.1110 raeburn 16261: sub allmaps_incourse {
16262: my ($cdom,$cnum,$chome,$cid) = @_;
16263: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16264: $cid = $env{'request.course.id'};
16265: $cdom = $env{'course.'.$cid.'.domain'};
16266: $cnum = $env{'course.'.$cid.'.num'};
16267: $chome = $env{'course.'.$cid.'.home'};
16268: }
16269: my %allmaps = ();
16270: my $lastchange =
16271: &Apache::lonnet::get_coursechange($cdom,$cnum);
16272: if ($lastchange > $env{'request.course.tied'}) {
16273: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16274: unless ($ferr) {
16275: &update_content_constraints($cdom,$cnum,$chome,$cid);
16276: }
16277: }
16278: my $navmap = Apache::lonnavmaps::navmap->new();
16279: if (defined($navmap)) {
16280: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16281: $allmaps{$res->src()} = 1;
16282: }
16283: }
16284: return \%allmaps;
16285: }
16286:
1.1083 raeburn 16287: sub parse_supplemental_title {
16288: my ($title) = @_;
16289:
16290: my ($foldertitle,$renametitle);
16291: if ($title =~ /&&&/) {
16292: $title = &HTML::Entites::decode($title);
16293: }
16294: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16295: $renametitle=$4;
16296: my ($time,$uname,$udom) = ($1,$2,$3);
16297: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16298: my $name = &plainname($uname,$udom);
16299: $name = &HTML::Entities::encode($name,'"<>&\'');
16300: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16301: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16302: $name.': <br />'.$foldertitle;
16303: }
16304: if (wantarray) {
16305: return ($title,$foldertitle,$renametitle);
16306: }
16307: return $title;
16308: }
16309:
1.1143 raeburn 16310: sub recurse_supplemental {
16311: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16312: if ($suppmap) {
16313: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16314: if ($fatal) {
16315: $errors ++;
16316: } else {
16317: if ($#LONCAPA::map::resources > 0) {
16318: foreach my $res (@LONCAPA::map::resources) {
16319: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16320: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 16321: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16322: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 16323: } else {
16324: $numfiles ++;
16325: }
16326: }
16327: }
16328: }
16329: }
16330: }
16331: return ($numfiles,$errors);
16332: }
16333:
1.1101 raeburn 16334: sub symb_to_docspath {
16335: my ($symb) = @_;
16336: return unless ($symb);
16337: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16338: if ($resurl=~/\.(sequence|page)$/) {
16339: $mapurl=$resurl;
16340: } elsif ($resurl eq 'adm/navmaps') {
16341: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16342: }
16343: my $mapresobj;
16344: my $navmap = Apache::lonnavmaps::navmap->new();
16345: if (ref($navmap)) {
16346: $mapresobj = $navmap->getResourceByUrl($mapurl);
16347: }
16348: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16349: my $type=$2;
16350: my $path;
16351: if (ref($mapresobj)) {
16352: my $pcslist = $mapresobj->map_hierarchy();
16353: if ($pcslist ne '') {
16354: foreach my $pc (split(/,/,$pcslist)) {
16355: next if ($pc <= 1);
16356: my $res = $navmap->getByMapPc($pc);
16357: if (ref($res)) {
16358: my $thisurl = $res->src();
16359: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16360: my $thistitle = $res->title();
16361: $path .= '&'.
16362: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 16363: &escape($thistitle).
1.1101 raeburn 16364: ':'.$res->randompick().
16365: ':'.$res->randomout().
16366: ':'.$res->encrypted().
16367: ':'.$res->randomorder().
16368: ':'.$res->is_page();
16369: }
16370: }
16371: }
16372: $path =~ s/^\&//;
16373: my $maptitle = $mapresobj->title();
16374: if ($mapurl eq 'default') {
1.1129 raeburn 16375: $maptitle = 'Main Content';
1.1101 raeburn 16376: }
16377: $path .= (($path ne '')? '&' : '').
16378: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 16379: &escape($maptitle).
1.1101 raeburn 16380: ':'.$mapresobj->randompick().
16381: ':'.$mapresobj->randomout().
16382: ':'.$mapresobj->encrypted().
16383: ':'.$mapresobj->randomorder().
16384: ':'.$mapresobj->is_page();
16385: } else {
16386: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16387: my $ispage = (($type eq 'page')? 1 : '');
16388: if ($mapurl eq 'default') {
1.1129 raeburn 16389: $maptitle = 'Main Content';
1.1101 raeburn 16390: }
16391: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 16392: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 16393: }
16394: unless ($mapurl eq 'default') {
16395: $path = 'default&'.
1.1146 raeburn 16396: &escape('Main Content').
1.1101 raeburn 16397: ':::::&'.$path;
16398: }
16399: return $path;
16400: }
16401:
1.1094 raeburn 16402: sub captcha_display {
16403: my ($context,$lonhost) = @_;
16404: my ($output,$error);
16405: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 16406: if ($captcha eq 'original') {
1.1094 raeburn 16407: $output = &create_captcha();
16408: unless ($output) {
1.1172 raeburn 16409: $error = 'captcha';
1.1094 raeburn 16410: }
16411: } elsif ($captcha eq 'recaptcha') {
16412: $output = &create_recaptcha($pubkey);
16413: unless ($output) {
1.1172 raeburn 16414: $error = 'recaptcha';
1.1094 raeburn 16415: }
16416: }
1.1176 raeburn 16417: return ($output,$error,$captcha);
1.1094 raeburn 16418: }
16419:
16420: sub captcha_response {
16421: my ($context,$lonhost) = @_;
16422: my ($captcha_chk,$captcha_error);
16423: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 16424: if ($captcha eq 'original') {
1.1094 raeburn 16425: ($captcha_chk,$captcha_error) = &check_captcha();
16426: } elsif ($captcha eq 'recaptcha') {
16427: $captcha_chk = &check_recaptcha($privkey);
16428: } else {
16429: $captcha_chk = 1;
16430: }
16431: return ($captcha_chk,$captcha_error);
16432: }
16433:
16434: sub get_captcha_config {
16435: my ($context,$lonhost) = @_;
1.1095 raeburn 16436: my ($captcha,$pubkey,$privkey,$hashtocheck);
1.1094 raeburn 16437: my $hostname = &Apache::lonnet::hostname($lonhost);
16438: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16439: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 16440: if ($context eq 'usercreation') {
16441: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16442: if (ref($domconfig{$context}) eq 'HASH') {
16443: $hashtocheck = $domconfig{$context}{'cancreate'};
16444: if (ref($hashtocheck) eq 'HASH') {
16445: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16446: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16447: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16448: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16449: }
16450: if ($privkey && $pubkey) {
16451: $captcha = 'recaptcha';
16452: } else {
16453: $captcha = 'original';
16454: }
16455: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16456: $captcha = 'original';
16457: }
1.1094 raeburn 16458: }
1.1095 raeburn 16459: } else {
16460: $captcha = 'captcha';
16461: }
16462: } elsif ($context eq 'login') {
16463: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16464: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16465: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16466: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 16467: if ($privkey && $pubkey) {
16468: $captcha = 'recaptcha';
1.1095 raeburn 16469: } else {
16470: $captcha = 'original';
1.1094 raeburn 16471: }
1.1095 raeburn 16472: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16473: $captcha = 'original';
1.1094 raeburn 16474: }
16475: }
16476: return ($captcha,$pubkey,$privkey);
16477: }
16478:
16479: sub create_captcha {
16480: my %captcha_params = &captcha_settings();
16481: my ($output,$maxtries,$tries) = ('',10,0);
16482: while ($tries < $maxtries) {
16483: $tries ++;
16484: my $captcha = Authen::Captcha->new (
16485: output_folder => $captcha_params{'output_dir'},
16486: data_folder => $captcha_params{'db_dir'},
16487: );
16488: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
16489:
16490: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
16491: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
16492: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 16493: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
16494: '<br />'.
16495: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 16496: last;
16497: }
16498: }
16499: return $output;
16500: }
16501:
16502: sub captcha_settings {
16503: my %captcha_params = (
16504: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
16505: www_output_dir => "/captchaspool",
16506: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16507: numchars => '5',
16508: );
16509: return %captcha_params;
16510: }
16511:
16512: sub check_captcha {
16513: my ($captcha_chk,$captcha_error);
16514: my $code = $env{'form.code'};
16515: my $md5sum = $env{'form.crypt'};
16516: my %captcha_params = &captcha_settings();
16517: my $captcha = Authen::Captcha->new(
16518: output_folder => $captcha_params{'output_dir'},
16519: data_folder => $captcha_params{'db_dir'},
16520: );
1.1109 raeburn 16521: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 16522: my %captcha_hash = (
16523: 0 => 'Code not checked (file error)',
16524: -1 => 'Failed: code expired',
16525: -2 => 'Failed: invalid code (not in database)',
16526: -3 => 'Failed: invalid code (code does not match crypt)',
16527: );
16528: if ($captcha_chk != 1) {
16529: $captcha_error = $captcha_hash{$captcha_chk}
16530: }
16531: return ($captcha_chk,$captcha_error);
16532: }
16533:
16534: sub create_recaptcha {
16535: my ($pubkey) = @_;
1.1153 raeburn 16536: my $use_ssl;
16537: if ($ENV{'SERVER_PORT'} == 443) {
16538: $use_ssl = 1;
16539: }
1.1094 raeburn 16540: my $captcha = Captcha::reCAPTCHA->new;
16541: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1153 raeburn 16542: $captcha->get_html($pubkey,undef,$use_ssl).
1.1213 raeburn 16543: &mt('If the text is hard to read, [_1] will replace them.',
1.1133 raeburn 16544: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1094 raeburn 16545: '<br /><br />';
16546: }
16547:
16548: sub check_recaptcha {
16549: my ($privkey) = @_;
16550: my $captcha_chk;
16551: my $captcha = Captcha::reCAPTCHA->new;
16552: my $captcha_result =
16553: $captcha->check_answer(
16554: $privkey,
16555: $ENV{'REMOTE_ADDR'},
16556: $env{'form.recaptcha_challenge_field'},
16557: $env{'form.recaptcha_response_field'},
16558: );
16559: if ($captcha_result->{is_valid}) {
16560: $captcha_chk = 1;
16561: }
16562: return $captcha_chk;
16563: }
16564:
1.1174 raeburn 16565: sub emailusername_info {
1.1177 raeburn 16566: my @fields = ('firstname','lastname','institution','web','location','officialemail');
1.1174 raeburn 16567: my %titles = &Apache::lonlocal::texthash (
16568: lastname => 'Last Name',
16569: firstname => 'First Name',
16570: institution => 'School/college/university',
16571: location => "School's city, state/province, country",
16572: web => "School's web address",
16573: officialemail => 'E-mail address at institution (if different)',
16574: );
16575: return (\@fields,\%titles);
16576: }
16577:
1.1161 raeburn 16578: sub cleanup_html {
16579: my ($incoming) = @_;
16580: my $outgoing;
16581: if ($incoming ne '') {
16582: $outgoing = $incoming;
16583: $outgoing =~ s/;/;/g;
16584: $outgoing =~ s/\#/#/g;
16585: $outgoing =~ s/\&/&/g;
16586: $outgoing =~ s/</</g;
16587: $outgoing =~ s/>/>/g;
16588: $outgoing =~ s/\(/(/g;
16589: $outgoing =~ s/\)/)/g;
16590: $outgoing =~ s/"/"/g;
16591: $outgoing =~ s/'/'/g;
16592: $outgoing =~ s/\$/$/g;
16593: $outgoing =~ s{/}{/}g;
16594: $outgoing =~ s/=/=/g;
16595: $outgoing =~ s/\\/\/g
16596: }
16597: return $outgoing;
16598: }
16599:
1.1190 musolffc 16600: # Checks for critical messages and returns a redirect url if one exists.
16601: # $interval indicates how often to check for messages.
16602: sub critical_redirect {
16603: my ($interval) = @_;
16604: if ((time-$env{'user.criticalcheck.time'})>$interval) {
16605: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
16606: $env{'user.name'});
16607: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 16608: my $redirecturl;
1.1190 musolffc 16609: if ($what[0]) {
16610: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
16611: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 16612: my $url=&Apache::lonnet::absolute_url().$redirecturl;
16613: return (1, $url);
1.1190 musolffc 16614: }
1.1191 raeburn 16615: }
16616: }
16617: return ();
1.1190 musolffc 16618: }
16619:
1.1174 raeburn 16620: # Use:
16621: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
16622: #
16623: ##################################################
16624: # password associated functions #
16625: ##################################################
16626: sub des_keys {
16627: # Make a new key for DES encryption.
16628: # Each key has two parts which are returned separately.
16629: # Please note: Each key must be passed through the &hex function
16630: # before it is output to the web browser. The hex versions cannot
16631: # be used to decrypt.
16632: my @hexstr=('0','1','2','3','4','5','6','7',
16633: '8','9','a','b','c','d','e','f');
16634: my $lkey='';
16635: for (0..7) {
16636: $lkey.=$hexstr[rand(15)];
16637: }
16638: my $ukey='';
16639: for (0..7) {
16640: $ukey.=$hexstr[rand(15)];
16641: }
16642: return ($lkey,$ukey);
16643: }
16644:
16645: sub des_decrypt {
16646: my ($key,$cyphertext) = @_;
16647: my $keybin=pack("H16",$key);
16648: my $cypher;
16649: if ($Crypt::DES::VERSION>=2.03) {
16650: $cypher=new Crypt::DES $keybin;
16651: } else {
16652: $cypher=new DES $keybin;
16653: }
16654: my $plaintext=
16655: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
16656: $plaintext.=
16657: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
16658: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
16659: return $plaintext;
16660: }
16661:
1.112 bowersj2 16662: 1;
16663: __END__;
1.41 ng 16664:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>