Annotation of loncom/interface/loncommon.pm, revision 1.1226
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1226 ! raeburn 4: # $Id: loncommon.pm,v 1.1225 2015/07/14 00:08:06 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.970 raeburn 2274: my ($def,$name,$hashref,$onchange) = @_;
2275: return unless (ref($hashref) eq 'HASH');
2276: if ($onchange) {
2277: $onchange = ' onchange="'.$onchange.'"';
2278: }
2279: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2280: my @keys;
1.970 raeburn 2281: if (exists($hashref->{'select_form_order'})) {
2282: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2283: } else {
1.970 raeburn 2284: @keys=sort(keys(%{$hashref}));
1.128 albertel 2285: }
1.356 albertel 2286: foreach my $key (@keys) {
2287: $selectform.=
2288: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2289: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2290: ">".$hashref->{$key}."</option>\n";
1.88 www 2291: }
2292: $selectform.="</select>";
2293: return $selectform;
2294: }
2295:
1.475 www 2296: # For display filters
2297:
2298: sub display_filter {
1.1074 raeburn 2299: my ($context) = @_;
1.475 www 2300: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2301: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2302: my $phraseinput = 'hidden';
2303: my $includeinput = 'hidden';
2304: my ($checked,$includetypestext);
2305: if ($env{'form.displayfilter'} eq 'containing') {
2306: $phraseinput = 'text';
2307: if ($context eq 'parmslog') {
2308: $includeinput = 'checkbox';
2309: if ($env{'form.includetypes'}) {
2310: $checked = ' checked="checked"';
2311: }
2312: $includetypestext = &mt('Include parameter types');
2313: }
2314: } else {
2315: $includetypestext = ' ';
2316: }
2317: my ($additional,$secondid,$thirdid);
2318: if ($context eq 'parmslog') {
2319: $additional =
2320: '<label><input type="'.$includeinput.'" name="includetypes"'.
2321: $checked.' name="includetypes" value="1" id="includetypes" />'.
2322: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2323: '</label>';
2324: $secondid = 'includetypes';
2325: $thirdid = 'includetypestext';
2326: }
2327: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2328: '$secondid','$thirdid')";
2329: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2330: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2331: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2332: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2333: &mt('Filter: [_1]',
1.477 www 2334: &select_form($env{'form.displayfilter'},
2335: 'displayfilter',
1.970 raeburn 2336: {'currentfolder' => 'Current folder/page',
1.477 www 2337: 'containing' => 'Containing phrase',
1.1074 raeburn 2338: 'none' => 'None'},$onchange)).' '.
2339: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2340: &HTML::Entities::encode($env{'form.containingphrase'}).
2341: '" />'.$additional;
2342: }
2343:
2344: sub display_filter_js {
2345: my $includetext = &mt('Include parameter types');
2346: return <<"ENDJS";
2347:
2348: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2349: var firstType = 'hidden';
2350: if (setter.options[setter.selectedIndex].value == 'containing') {
2351: firstType = 'text';
2352: }
2353: firstObject = document.getElementById(firstid);
2354: if (typeof(firstObject) == 'object') {
2355: if (firstObject.type != firstType) {
2356: changeInputType(firstObject,firstType);
2357: }
2358: }
2359: if (context == 'parmslog') {
2360: var secondType = 'hidden';
2361: if (firstType == 'text') {
2362: secondType = 'checkbox';
2363: }
2364: secondObject = document.getElementById(secondid);
2365: if (typeof(secondObject) == 'object') {
2366: if (secondObject.type != secondType) {
2367: changeInputType(secondObject,secondType);
2368: }
2369: }
2370: var textItem = document.getElementById(thirdid);
2371: var currtext = textItem.innerHTML;
2372: var newtext;
2373: if (firstType == 'text') {
2374: newtext = '$includetext';
2375: } else {
2376: newtext = ' ';
2377: }
2378: if (currtext != newtext) {
2379: textItem.innerHTML = newtext;
2380: }
2381: }
2382: return;
2383: }
2384:
2385: function changeInputType(oldObject,newType) {
2386: var newObject = document.createElement('input');
2387: newObject.type = newType;
2388: if (oldObject.size) {
2389: newObject.size = oldObject.size;
2390: }
2391: if (oldObject.value) {
2392: newObject.value = oldObject.value;
2393: }
2394: if (oldObject.name) {
2395: newObject.name = oldObject.name;
2396: }
2397: if (oldObject.id) {
2398: newObject.id = oldObject.id;
2399: }
2400: oldObject.parentNode.replaceChild(newObject,oldObject);
2401: return;
2402: }
2403:
2404: ENDJS
1.475 www 2405: }
2406:
1.167 www 2407: sub gradeleveldescription {
2408: my $gradelevel=shift;
2409: my %gradelevels=(0 => 'Not specified',
2410: 1 => 'Grade 1',
2411: 2 => 'Grade 2',
2412: 3 => 'Grade 3',
2413: 4 => 'Grade 4',
2414: 5 => 'Grade 5',
2415: 6 => 'Grade 6',
2416: 7 => 'Grade 7',
2417: 8 => 'Grade 8',
2418: 9 => 'Grade 9',
2419: 10 => 'Grade 10',
2420: 11 => 'Grade 11',
2421: 12 => 'Grade 12',
2422: 13 => 'Grade 13',
2423: 14 => '100 Level',
2424: 15 => '200 Level',
2425: 16 => '300 Level',
2426: 17 => '400 Level',
2427: 18 => 'Graduate Level');
2428: return &mt($gradelevels{$gradelevel});
2429: }
2430:
1.163 www 2431: sub select_level_form {
2432: my ($deflevel,$name)=@_;
2433: unless ($deflevel) { $deflevel=0; }
1.167 www 2434: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2435: for (my $i=0; $i<=18; $i++) {
2436: $selectform.="<option value=\"$i\" ".
1.253 albertel 2437: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2438: ">".&gradeleveldescription($i)."</option>\n";
2439: }
2440: $selectform.="</select>";
2441: return $selectform;
1.163 www 2442: }
1.167 www 2443:
1.35 matthew 2444: #-------------------------------------------
2445:
1.45 matthew 2446: =pod
2447:
1.1121 raeburn 2448: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2449:
2450: Returns a string containing a <select name='$name' size='1'> form to
2451: allow a user to select the domain to preform an operation in.
2452: See loncreateuser.pm for an example invocation and use.
2453:
1.90 www 2454: If the $includeempty flag is set, it also includes an empty choice ("no domain
2455: selected");
2456:
1.743 raeburn 2457: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2458:
1.910 raeburn 2459: 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.
2460:
1.1121 raeburn 2461: The optional $incdoms is a reference to an array of domains which will be the only available options.
2462:
2463: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2464:
1.35 matthew 2465: =cut
2466:
2467: #-------------------------------------------
1.34 matthew 2468: sub select_dom_form {
1.1121 raeburn 2469: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2470: if ($onchange) {
1.874 raeburn 2471: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2472: }
1.1121 raeburn 2473: my (@domains,%exclude);
1.910 raeburn 2474: if (ref($incdoms) eq 'ARRAY') {
2475: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2476: } else {
2477: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2478: }
1.90 www 2479: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2480: if (ref($excdoms) eq 'ARRAY') {
2481: map { $exclude{$_} = 1; } @{$excdoms};
2482: }
1.743 raeburn 2483: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2484: foreach my $dom (@domains) {
1.1121 raeburn 2485: next if ($exclude{$dom});
1.356 albertel 2486: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2487: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2488: if ($showdomdesc) {
2489: if ($dom ne '') {
2490: my $domdesc = &Apache::lonnet::domain($dom,'description');
2491: if ($domdesc ne '') {
2492: $selectdomain .= ' ('.$domdesc.')';
2493: }
2494: }
2495: }
2496: $selectdomain .= "</option>\n";
1.34 matthew 2497: }
2498: $selectdomain.="</select>";
2499: return $selectdomain;
2500: }
2501:
1.35 matthew 2502: #-------------------------------------------
2503:
1.45 matthew 2504: =pod
2505:
1.648 raeburn 2506: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2507:
1.586 raeburn 2508: input: 4 arguments (two required, two optional) -
2509: $domain - domain of new user
2510: $name - name of form element
2511: $default - Value of 'default' causes a default item to be first
2512: option, and selected by default.
2513: $hide - Value of 'hide' causes hiding of the name of the server,
2514: if 1 server found, or default, if 0 found.
1.594 raeburn 2515: output: returns 2 items:
1.586 raeburn 2516: (a) form element which contains either:
2517: (i) <select name="$name">
2518: <option value="$hostid1">$hostid $servers{$hostid}</option>
2519: <option value="$hostid2">$hostid $servers{$hostid}</option>
2520: </select>
2521: form item if there are multiple library servers in $domain, or
2522: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2523: if there is only one library server in $domain.
2524:
2525: (b) number of library servers found.
2526:
2527: See loncreateuser.pm for example of use.
1.35 matthew 2528:
2529: =cut
2530:
2531: #-------------------------------------------
1.586 raeburn 2532: sub home_server_form_item {
2533: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2534: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2535: my $result;
2536: my $numlib = keys(%servers);
2537: if ($numlib > 1) {
2538: $result .= '<select name="'.$name.'" />'."\n";
2539: if ($default) {
1.804 bisitz 2540: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2541: '</option>'."\n";
2542: }
2543: foreach my $hostid (sort(keys(%servers))) {
2544: $result.= '<option value="'.$hostid.'">'.
2545: $hostid.' '.$servers{$hostid}."</option>\n";
2546: }
2547: $result .= '</select>'."\n";
2548: } elsif ($numlib == 1) {
2549: my $hostid;
2550: foreach my $item (keys(%servers)) {
2551: $hostid = $item;
2552: }
2553: $result .= '<input type="hidden" name="'.$name.'" value="'.
2554: $hostid.'" />';
2555: if (!$hide) {
2556: $result .= $hostid.' '.$servers{$hostid};
2557: }
2558: $result .= "\n";
2559: } elsif ($default) {
2560: $result .= '<input type="hidden" name="'.$name.
2561: '" value="default" />';
2562: if (!$hide) {
2563: $result .= &mt('default');
2564: }
2565: $result .= "\n";
1.33 matthew 2566: }
1.586 raeburn 2567: return ($result,$numlib);
1.33 matthew 2568: }
1.112 bowersj2 2569:
2570: =pod
2571:
1.534 albertel 2572: =back
2573:
1.112 bowersj2 2574: =cut
1.87 matthew 2575:
2576: ###############################################################
1.112 bowersj2 2577: ## Decoding User Agent ##
1.87 matthew 2578: ###############################################################
2579:
2580: =pod
2581:
1.112 bowersj2 2582: =head1 Decoding the User Agent
2583:
2584: =over 4
2585:
2586: =item * &decode_user_agent()
1.87 matthew 2587:
2588: Inputs: $r
2589:
2590: Outputs:
2591:
2592: =over 4
2593:
1.112 bowersj2 2594: =item * $httpbrowser
1.87 matthew 2595:
1.112 bowersj2 2596: =item * $clientbrowser
1.87 matthew 2597:
1.112 bowersj2 2598: =item * $clientversion
1.87 matthew 2599:
1.112 bowersj2 2600: =item * $clientmathml
1.87 matthew 2601:
1.112 bowersj2 2602: =item * $clientunicode
1.87 matthew 2603:
1.112 bowersj2 2604: =item * $clientos
1.87 matthew 2605:
1.1137 raeburn 2606: =item * $clientmobile
2607:
1.1141 raeburn 2608: =item * $clientinfo
2609:
1.1194 raeburn 2610: =item * $clientosversion
2611:
1.87 matthew 2612: =back
2613:
1.157 matthew 2614: =back
2615:
1.87 matthew 2616: =cut
2617:
2618: ###############################################################
2619: ###############################################################
2620: sub decode_user_agent {
1.247 albertel 2621: my ($r)=@_;
1.87 matthew 2622: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2623: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2624: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2625: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2626: my $clientbrowser='unknown';
2627: my $clientversion='0';
2628: my $clientmathml='';
2629: my $clientunicode='0';
1.1137 raeburn 2630: my $clientmobile=0;
1.1194 raeburn 2631: my $clientosversion='';
1.87 matthew 2632: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2633: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2634: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2635: $clientbrowser=$bname;
2636: $httpbrowser=~/$vreg/i;
2637: $clientversion=$1;
2638: $clientmathml=($clientversion>=$minv);
2639: $clientunicode=($clientversion>=$univ);
2640: }
2641: }
2642: my $clientos='unknown';
1.1141 raeburn 2643: my $clientinfo;
1.87 matthew 2644: if (($httpbrowser=~/linux/i) ||
2645: ($httpbrowser=~/unix/i) ||
2646: ($httpbrowser=~/ux/i) ||
2647: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2648: if (($httpbrowser=~/vax/i) ||
2649: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2650: if ($httpbrowser=~/next/i) { $clientos='next'; }
2651: if (($httpbrowser=~/mac/i) ||
2652: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2653: if ($httpbrowser=~/win/i) {
2654: $clientos='win';
2655: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2656: $clientosversion = $1;
2657: }
2658: }
1.87 matthew 2659: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2660: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2661: $clientmobile=lc($1);
2662: }
1.1141 raeburn 2663: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2664: $clientinfo = 'firefox-'.$1;
2665: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2666: $clientinfo = 'chromeframe-'.$1;
2667: }
1.87 matthew 2668: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 2669: $clientunicode,$clientos,$clientmobile,$clientinfo,
2670: $clientosversion);
1.87 matthew 2671: }
2672:
1.32 matthew 2673: ###############################################################
2674: ## Authentication changing form generation subroutines ##
2675: ###############################################################
2676: ##
2677: ## All of the authform_xxxxxxx subroutines take their inputs in a
2678: ## hash, and have reasonable default values.
2679: ##
2680: ## formname = the name given in the <form> tag.
1.35 matthew 2681: #-------------------------------------------
2682:
1.45 matthew 2683: =pod
2684:
1.112 bowersj2 2685: =head1 Authentication Routines
2686:
2687: =over 4
2688:
1.648 raeburn 2689: =item * &authform_xxxxxx()
1.35 matthew 2690:
2691: The authform_xxxxxx subroutines provide javascript and html forms which
2692: handle some of the conveniences required for authentication forms.
2693: This is not an optimal method, but it works.
2694:
2695: =over 4
2696:
1.112 bowersj2 2697: =item * authform_header
1.35 matthew 2698:
1.112 bowersj2 2699: =item * authform_authorwarning
1.35 matthew 2700:
1.112 bowersj2 2701: =item * authform_nochange
1.35 matthew 2702:
1.112 bowersj2 2703: =item * authform_kerberos
1.35 matthew 2704:
1.112 bowersj2 2705: =item * authform_internal
1.35 matthew 2706:
1.112 bowersj2 2707: =item * authform_filesystem
1.35 matthew 2708:
2709: =back
2710:
1.648 raeburn 2711: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2712:
1.35 matthew 2713: =cut
2714:
2715: #-------------------------------------------
1.32 matthew 2716: sub authform_header{
2717: my %in = (
2718: formname => 'cu',
1.80 albertel 2719: kerb_def_dom => '',
1.32 matthew 2720: @_,
2721: );
2722: $in{'formname'} = 'document.' . $in{'formname'};
2723: my $result='';
1.80 albertel 2724:
2725: #---------------------------------------------- Code for upper case translation
2726: my $Javascript_toUpperCase;
2727: unless ($in{kerb_def_dom}) {
2728: $Javascript_toUpperCase =<<"END";
2729: switch (choice) {
2730: case 'krb': currentform.elements[choicearg].value =
2731: currentform.elements[choicearg].value.toUpperCase();
2732: break;
2733: default:
2734: }
2735: END
2736: } else {
2737: $Javascript_toUpperCase = "";
2738: }
2739:
1.165 raeburn 2740: my $radioval = "'nochange'";
1.591 raeburn 2741: if (defined($in{'curr_authtype'})) {
2742: if ($in{'curr_authtype'} ne '') {
2743: $radioval = "'".$in{'curr_authtype'}."arg'";
2744: }
1.174 matthew 2745: }
1.165 raeburn 2746: my $argfield = 'null';
1.591 raeburn 2747: if (defined($in{'mode'})) {
1.165 raeburn 2748: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2749: if (defined($in{'curr_autharg'})) {
2750: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2751: $argfield = "'$in{'curr_autharg'}'";
2752: }
2753: }
2754: }
2755: }
2756:
1.32 matthew 2757: $result.=<<"END";
2758: var current = new Object();
1.165 raeburn 2759: current.radiovalue = $radioval;
2760: current.argfield = $argfield;
1.32 matthew 2761:
2762: function changed_radio(choice,currentform) {
2763: var choicearg = choice + 'arg';
2764: // If a radio button in changed, we need to change the argfield
2765: if (current.radiovalue != choice) {
2766: current.radiovalue = choice;
2767: if (current.argfield != null) {
2768: currentform.elements[current.argfield].value = '';
2769: }
2770: if (choice == 'nochange') {
2771: current.argfield = null;
2772: } else {
2773: current.argfield = choicearg;
2774: switch(choice) {
2775: case 'krb':
2776: currentform.elements[current.argfield].value =
2777: "$in{'kerb_def_dom'}";
2778: break;
2779: default:
2780: break;
2781: }
2782: }
2783: }
2784: return;
2785: }
1.22 www 2786:
1.32 matthew 2787: function changed_text(choice,currentform) {
2788: var choicearg = choice + 'arg';
2789: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2790: $Javascript_toUpperCase
1.32 matthew 2791: // clear old field
2792: if ((current.argfield != choicearg) && (current.argfield != null)) {
2793: currentform.elements[current.argfield].value = '';
2794: }
2795: current.argfield = choicearg;
2796: }
2797: set_auth_radio_buttons(choice,currentform);
2798: return;
1.20 www 2799: }
1.32 matthew 2800:
2801: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2802: var numauthchoices = currentform.login.length;
2803: if (typeof numauthchoices == "undefined") {
2804: return;
2805: }
1.32 matthew 2806: var i=0;
1.986 raeburn 2807: while (i < numauthchoices) {
1.32 matthew 2808: if (currentform.login[i].value == newvalue) { break; }
2809: i++;
2810: }
1.986 raeburn 2811: if (i == numauthchoices) {
1.32 matthew 2812: return;
2813: }
2814: current.radiovalue = newvalue;
2815: currentform.login[i].checked = true;
2816: return;
2817: }
2818: END
2819: return $result;
2820: }
2821:
1.1106 raeburn 2822: sub authform_authorwarning {
1.32 matthew 2823: my $result='';
1.144 matthew 2824: $result='<i>'.
2825: &mt('As a general rule, only authors or co-authors should be '.
2826: 'filesystem authenticated '.
2827: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2828: return $result;
2829: }
2830:
1.1106 raeburn 2831: sub authform_nochange {
1.32 matthew 2832: my %in = (
2833: formname => 'document.cu',
2834: kerb_def_dom => 'MSU.EDU',
2835: @_,
2836: );
1.1106 raeburn 2837: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2838: my $result;
1.1104 raeburn 2839: if (!$authnum) {
1.1105 raeburn 2840: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2841: } else {
2842: $result = '<label>'.&mt('[_1] Do not change login data',
2843: '<input type="radio" name="login" value="nochange" '.
2844: 'checked="checked" onclick="'.
1.281 albertel 2845: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2846: '</label>';
1.586 raeburn 2847: }
1.32 matthew 2848: return $result;
2849: }
2850:
1.591 raeburn 2851: sub authform_kerberos {
1.32 matthew 2852: my %in = (
2853: formname => 'document.cu',
2854: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2855: kerb_def_auth => 'krb4',
1.32 matthew 2856: @_,
2857: );
1.586 raeburn 2858: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2859: $autharg,$jscall);
1.1106 raeburn 2860: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2861: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2862: $check5 = ' checked="checked"';
1.80 albertel 2863: } else {
1.772 bisitz 2864: $check4 = ' checked="checked"';
1.80 albertel 2865: }
1.165 raeburn 2866: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2867: if (defined($in{'curr_authtype'})) {
2868: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2869: $krbcheck = ' checked="checked"';
1.623 raeburn 2870: if (defined($in{'mode'})) {
2871: if ($in{'mode'} eq 'modifyuser') {
2872: $krbcheck = '';
2873: }
2874: }
1.591 raeburn 2875: if (defined($in{'curr_kerb_ver'})) {
2876: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2877: $check5 = ' checked="checked"';
1.591 raeburn 2878: $check4 = '';
2879: } else {
1.772 bisitz 2880: $check4 = ' checked="checked"';
1.591 raeburn 2881: $check5 = '';
2882: }
1.586 raeburn 2883: }
1.591 raeburn 2884: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2885: $krbarg = $in{'curr_autharg'};
2886: }
1.586 raeburn 2887: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2888: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2889: $result =
2890: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2891: $in{'curr_autharg'},$krbver);
2892: } else {
2893: $result =
2894: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2895: }
2896: return $result;
2897: }
2898: }
2899: } else {
2900: if ($authnum == 1) {
1.784 bisitz 2901: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2902: }
2903: }
1.586 raeburn 2904: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2905: return;
1.587 raeburn 2906: } elsif ($authtype eq '') {
1.591 raeburn 2907: if (defined($in{'mode'})) {
1.587 raeburn 2908: if ($in{'mode'} eq 'modifycourse') {
2909: if ($authnum == 1) {
1.1104 raeburn 2910: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2911: }
2912: }
2913: }
1.586 raeburn 2914: }
2915: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2916: if ($authtype eq '') {
2917: $authtype = '<input type="radio" name="login" value="krb" '.
2918: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2919: $krbcheck.' />';
2920: }
2921: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 2922: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2923: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 2924: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2925: $in{'curr_authtype'} eq 'krb4')) {
2926: $result .= &mt
1.144 matthew 2927: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2928: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2929: '<label>'.$authtype,
1.281 albertel 2930: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2931: 'value="'.$krbarg.'" '.
1.144 matthew 2932: 'onchange="'.$jscall.'" />',
1.281 albertel 2933: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2934: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2935: '</label>');
1.586 raeburn 2936: } elsif ($can_assign{'krb4'}) {
2937: $result .= &mt
2938: ('[_1] Kerberos authenticated with domain [_2] '.
2939: '[_3] Version 4 [_4]',
2940: '<label>'.$authtype,
2941: '</label><input type="text" size="10" name="krbarg" '.
2942: 'value="'.$krbarg.'" '.
2943: 'onchange="'.$jscall.'" />',
2944: '<label><input type="hidden" name="krbver" value="4" />',
2945: '</label>');
2946: } elsif ($can_assign{'krb5'}) {
2947: $result .= &mt
2948: ('[_1] Kerberos authenticated with domain [_2] '.
2949: '[_3] Version 5 [_4]',
2950: '<label>'.$authtype,
2951: '</label><input type="text" size="10" name="krbarg" '.
2952: 'value="'.$krbarg.'" '.
2953: 'onchange="'.$jscall.'" />',
2954: '<label><input type="hidden" name="krbver" value="5" />',
2955: '</label>');
2956: }
1.32 matthew 2957: return $result;
2958: }
2959:
1.1106 raeburn 2960: sub authform_internal {
1.586 raeburn 2961: my %in = (
1.32 matthew 2962: formname => 'document.cu',
2963: kerb_def_dom => 'MSU.EDU',
2964: @_,
2965: );
1.586 raeburn 2966: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2967: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2968: if (defined($in{'curr_authtype'})) {
2969: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2970: if ($can_assign{'int'}) {
1.772 bisitz 2971: $intcheck = 'checked="checked" ';
1.623 raeburn 2972: if (defined($in{'mode'})) {
2973: if ($in{'mode'} eq 'modifyuser') {
2974: $intcheck = '';
2975: }
2976: }
1.591 raeburn 2977: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2978: $intarg = $in{'curr_autharg'};
2979: }
2980: } else {
2981: $result = &mt('Currently internally authenticated.');
2982: return $result;
1.165 raeburn 2983: }
2984: }
1.586 raeburn 2985: } else {
2986: if ($authnum == 1) {
1.784 bisitz 2987: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2988: }
2989: }
2990: if (!$can_assign{'int'}) {
2991: return;
1.587 raeburn 2992: } elsif ($authtype eq '') {
1.591 raeburn 2993: if (defined($in{'mode'})) {
1.587 raeburn 2994: if ($in{'mode'} eq 'modifycourse') {
2995: if ($authnum == 1) {
1.1104 raeburn 2996: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2997: }
2998: }
2999: }
1.165 raeburn 3000: }
1.586 raeburn 3001: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3002: if ($authtype eq '') {
3003: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
3004: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
3005: }
1.605 bisitz 3006: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 3007: $intarg.'" onchange="'.$jscall.'" />';
3008: $result = &mt
1.144 matthew 3009: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3010: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 3011: $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 3012: return $result;
3013: }
3014:
1.1104 raeburn 3015: sub authform_local {
1.32 matthew 3016: my %in = (
3017: formname => 'document.cu',
3018: kerb_def_dom => 'MSU.EDU',
3019: @_,
3020: );
1.586 raeburn 3021: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 3022: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3023: if (defined($in{'curr_authtype'})) {
3024: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3025: if ($can_assign{'loc'}) {
1.772 bisitz 3026: $loccheck = 'checked="checked" ';
1.623 raeburn 3027: if (defined($in{'mode'})) {
3028: if ($in{'mode'} eq 'modifyuser') {
3029: $loccheck = '';
3030: }
3031: }
1.591 raeburn 3032: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3033: $locarg = $in{'curr_autharg'};
3034: }
3035: } else {
3036: $result = &mt('Currently using local (institutional) authentication.');
3037: return $result;
1.165 raeburn 3038: }
3039: }
1.586 raeburn 3040: } else {
3041: if ($authnum == 1) {
1.784 bisitz 3042: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3043: }
3044: }
3045: if (!$can_assign{'loc'}) {
3046: return;
1.587 raeburn 3047: } elsif ($authtype eq '') {
1.591 raeburn 3048: if (defined($in{'mode'})) {
1.587 raeburn 3049: if ($in{'mode'} eq 'modifycourse') {
3050: if ($authnum == 1) {
1.1104 raeburn 3051: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 3052: }
3053: }
3054: }
1.165 raeburn 3055: }
1.586 raeburn 3056: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3057: if ($authtype eq '') {
3058: $authtype = '<input type="radio" name="login" value="loc" '.
3059: $loccheck.' onchange="'.$jscall.'" onclick="'.
3060: $jscall.'" />';
3061: }
3062: $autharg = '<input type="text" size="10" name="locarg" value="'.
3063: $locarg.'" onchange="'.$jscall.'" />';
3064: $result = &mt('[_1] Local Authentication with argument [_2]',
3065: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3066: return $result;
3067: }
3068:
1.1106 raeburn 3069: sub authform_filesystem {
1.32 matthew 3070: my %in = (
3071: formname => 'document.cu',
3072: kerb_def_dom => 'MSU.EDU',
3073: @_,
3074: );
1.586 raeburn 3075: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 3076: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3077: if (defined($in{'curr_authtype'})) {
3078: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3079: if ($can_assign{'fsys'}) {
1.772 bisitz 3080: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3081: if (defined($in{'mode'})) {
3082: if ($in{'mode'} eq 'modifyuser') {
3083: $fsyscheck = '';
3084: }
3085: }
1.586 raeburn 3086: } else {
3087: $result = &mt('Currently Filesystem Authenticated.');
3088: return $result;
3089: }
3090: }
3091: } else {
3092: if ($authnum == 1) {
1.784 bisitz 3093: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3094: }
3095: }
3096: if (!$can_assign{'fsys'}) {
3097: return;
1.587 raeburn 3098: } elsif ($authtype eq '') {
1.591 raeburn 3099: if (defined($in{'mode'})) {
1.587 raeburn 3100: if ($in{'mode'} eq 'modifycourse') {
3101: if ($authnum == 1) {
1.1104 raeburn 3102: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 3103: }
3104: }
3105: }
1.586 raeburn 3106: }
3107: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3108: if ($authtype eq '') {
3109: $authtype = '<input type="radio" name="login" value="fsys" '.
3110: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
3111: $jscall.'" />';
3112: }
3113: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
3114: ' onchange="'.$jscall.'" />';
3115: $result = &mt
1.144 matthew 3116: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3117: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 3118: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 3119: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 3120: 'onchange="'.$jscall.'" />');
1.32 matthew 3121: return $result;
3122: }
3123:
1.586 raeburn 3124: sub get_assignable_auth {
3125: my ($dom) = @_;
3126: if ($dom eq '') {
3127: $dom = $env{'request.role.domain'};
3128: }
3129: my %can_assign = (
3130: krb4 => 1,
3131: krb5 => 1,
3132: int => 1,
3133: loc => 1,
3134: );
3135: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3136: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3137: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3138: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3139: my $context;
3140: if ($env{'request.role'} =~ /^au/) {
3141: $context = 'author';
3142: } elsif ($env{'request.role'} =~ /^dc/) {
3143: $context = 'domain';
3144: } elsif ($env{'request.course.id'}) {
3145: $context = 'course';
3146: }
3147: if ($context) {
3148: if (ref($authhash->{$context}) eq 'HASH') {
3149: %can_assign = %{$authhash->{$context}};
3150: }
3151: }
3152: }
3153: }
3154: my $authnum = 0;
3155: foreach my $key (keys(%can_assign)) {
3156: if ($can_assign{$key}) {
3157: $authnum ++;
3158: }
3159: }
3160: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3161: $authnum --;
3162: }
3163: return ($authnum,%can_assign);
3164: }
3165:
1.80 albertel 3166: ###############################################################
3167: ## Get Kerberos Defaults for Domain ##
3168: ###############################################################
3169: ##
3170: ## Returns default kerberos version and an associated argument
3171: ## as listed in file domain.tab. If not listed, provides
3172: ## appropriate default domain and kerberos version.
3173: ##
3174: #-------------------------------------------
3175:
3176: =pod
3177:
1.648 raeburn 3178: =item * &get_kerberos_defaults()
1.80 albertel 3179:
3180: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3181: version and domain. If not found, it defaults to version 4 and the
3182: domain of the server.
1.80 albertel 3183:
1.648 raeburn 3184: =over 4
3185:
1.80 albertel 3186: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3187:
1.648 raeburn 3188: =back
3189:
3190: =back
3191:
1.80 albertel 3192: =cut
3193:
3194: #-------------------------------------------
3195: sub get_kerberos_defaults {
3196: my $domain=shift;
1.641 raeburn 3197: my ($krbdef,$krbdefdom);
3198: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3199: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3200: $krbdef = $domdefaults{'auth_def'};
3201: $krbdefdom = $domdefaults{'auth_arg_def'};
3202: } else {
1.80 albertel 3203: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3204: my $krbdefdom=$1;
3205: $krbdefdom=~tr/a-z/A-Z/;
3206: $krbdef = "krb4";
3207: }
3208: return ($krbdef,$krbdefdom);
3209: }
1.112 bowersj2 3210:
1.32 matthew 3211:
1.46 matthew 3212: ###############################################################
3213: ## Thesaurus Functions ##
3214: ###############################################################
1.20 www 3215:
1.46 matthew 3216: =pod
1.20 www 3217:
1.112 bowersj2 3218: =head1 Thesaurus Functions
3219:
3220: =over 4
3221:
1.648 raeburn 3222: =item * &initialize_keywords()
1.46 matthew 3223:
3224: Initializes the package variable %Keywords if it is empty. Uses the
3225: package variable $thesaurus_db_file.
3226:
3227: =cut
3228:
3229: ###################################################
3230:
3231: sub initialize_keywords {
3232: return 1 if (scalar keys(%Keywords));
3233: # If we are here, %Keywords is empty, so fill it up
3234: # Make sure the file we need exists...
3235: if (! -e $thesaurus_db_file) {
3236: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3237: " failed because it does not exist");
3238: return 0;
3239: }
3240: # Set up the hash as a database
3241: my %thesaurus_db;
3242: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3243: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3244: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3245: $thesaurus_db_file);
3246: return 0;
3247: }
3248: # Get the average number of appearances of a word.
3249: my $avecount = $thesaurus_db{'average.count'};
3250: # Put keywords (those that appear > average) into %Keywords
3251: while (my ($word,$data)=each (%thesaurus_db)) {
3252: my ($count,undef) = split /:/,$data;
3253: $Keywords{$word}++ if ($count > $avecount);
3254: }
3255: untie %thesaurus_db;
3256: # Remove special values from %Keywords.
1.356 albertel 3257: foreach my $value ('total.count','average.count') {
3258: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3259: }
1.46 matthew 3260: return 1;
3261: }
3262:
3263: ###################################################
3264:
3265: =pod
3266:
1.648 raeburn 3267: =item * &keyword($word)
1.46 matthew 3268:
3269: Returns true if $word is a keyword. A keyword is a word that appears more
3270: than the average number of times in the thesaurus database. Calls
3271: &initialize_keywords
3272:
3273: =cut
3274:
3275: ###################################################
1.20 www 3276:
3277: sub keyword {
1.46 matthew 3278: return if (!&initialize_keywords());
3279: my $word=lc(shift());
3280: $word=~s/\W//g;
3281: return exists($Keywords{$word});
1.20 www 3282: }
1.46 matthew 3283:
3284: ###############################################################
3285:
3286: =pod
1.20 www 3287:
1.648 raeburn 3288: =item * &get_related_words()
1.46 matthew 3289:
1.160 matthew 3290: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3291: an array of words. If the keyword is not in the thesaurus, an empty array
3292: will be returned. The order of the words returned is determined by the
3293: database which holds them.
3294:
3295: Uses global $thesaurus_db_file.
3296:
1.1057 foxr 3297:
1.46 matthew 3298: =cut
3299:
3300: ###############################################################
3301: sub get_related_words {
3302: my $keyword = shift;
3303: my %thesaurus_db;
3304: if (! -e $thesaurus_db_file) {
3305: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3306: "failed because the file does not exist");
3307: return ();
3308: }
3309: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3310: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3311: return ();
3312: }
3313: my @Words=();
1.429 www 3314: my $count=0;
1.46 matthew 3315: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3316: # The first element is the number of times
3317: # the word appears. We do not need it now.
1.429 www 3318: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3319: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3320: my $threshold=$mostfrequentcount/10;
3321: foreach my $possibleword (@RelatedWords) {
3322: my ($word,$wordcount)=split(/\,/,$possibleword);
3323: if ($wordcount>$threshold) {
3324: push(@Words,$word);
3325: $count++;
3326: if ($count>10) { last; }
3327: }
1.20 www 3328: }
3329: }
1.46 matthew 3330: untie %thesaurus_db;
3331: return @Words;
1.14 harris41 3332: }
1.1090 foxr 3333: ###############################################################
3334: #
3335: # Spell checking
3336: #
3337:
3338: =pod
3339:
1.1142 raeburn 3340: =back
3341:
1.1090 foxr 3342: =head1 Spell checking
3343:
3344: =over 4
3345:
3346: =item * &check_spelling($wordlist $language)
3347:
3348: Takes a string containing words and feeds it to an external
3349: spellcheck program via a pipeline. Returns a string containing
3350: them mis-spelled words.
3351:
3352: Parameters:
3353:
3354: =over 4
3355:
3356: =item - $wordlist
3357:
3358: String that will be fed into the spellcheck program.
3359:
3360: =item - $language
3361:
3362: Language string that specifies the language for which the spell
3363: check will be performed.
3364:
3365: =back
3366:
3367: =back
3368:
3369: Note: This sub assumes that aspell is installed.
3370:
3371:
3372: =cut
3373:
1.46 matthew 3374:
1.1090 foxr 3375: sub check_spelling {
3376: my ($wordlist, $language) = @_;
1.1091 foxr 3377: my @misspellings;
3378:
3379: # Generate the speller and set the langauge.
3380: # if explicitly selected:
1.1090 foxr 3381:
1.1091 foxr 3382: my $speller = Text::Aspell->new;
1.1090 foxr 3383: if ($language) {
1.1091 foxr 3384: $speller->set_option('lang', $language);
1.1090 foxr 3385: }
3386:
1.1091 foxr 3387: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3388:
1.1091 foxr 3389: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3390:
1.1091 foxr 3391: foreach my $word (@words) {
3392: if(! $speller->check($word)) {
3393: push(@misspellings, $word);
1.1090 foxr 3394: }
3395: }
1.1091 foxr 3396: return join(' ', @misspellings);
3397:
1.1090 foxr 3398: }
3399:
1.61 www 3400: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3401: =pod
3402:
1.112 bowersj2 3403: =head1 User Name Functions
3404:
3405: =over 4
3406:
1.648 raeburn 3407: =item * &plainname($uname,$udom,$first)
1.81 albertel 3408:
1.112 bowersj2 3409: Takes a users logon name and returns it as a string in
1.226 albertel 3410: "first middle last generation" form
3411: if $first is set to 'lastname' then it returns it as
3412: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3413:
3414: =cut
1.61 www 3415:
1.295 www 3416:
1.81 albertel 3417: ###############################################################
1.61 www 3418: sub plainname {
1.226 albertel 3419: my ($uname,$udom,$first)=@_;
1.537 albertel 3420: return if (!defined($uname) || !defined($udom));
1.295 www 3421: my %names=&getnames($uname,$udom);
1.226 albertel 3422: my $name=&Apache::lonnet::format_name($names{'firstname'},
3423: $names{'middlename'},
3424: $names{'lastname'},
3425: $names{'generation'},$first);
3426: $name=~s/^\s+//;
1.62 www 3427: $name=~s/\s+$//;
3428: $name=~s/\s+/ /g;
1.353 albertel 3429: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3430: return $name;
1.61 www 3431: }
1.66 www 3432:
3433: # -------------------------------------------------------------------- Nickname
1.81 albertel 3434: =pod
3435:
1.648 raeburn 3436: =item * &nickname($uname,$udom)
1.81 albertel 3437:
3438: Gets a users name and returns it as a string as
3439:
3440: ""nickname""
1.66 www 3441:
1.81 albertel 3442: if the user has a nickname or
3443:
3444: "first middle last generation"
3445:
3446: if the user does not
3447:
3448: =cut
1.66 www 3449:
3450: sub nickname {
3451: my ($uname,$udom)=@_;
1.537 albertel 3452: return if (!defined($uname) || !defined($udom));
1.295 www 3453: my %names=&getnames($uname,$udom);
1.68 albertel 3454: my $name=$names{'nickname'};
1.66 www 3455: if ($name) {
3456: $name='"'.$name.'"';
3457: } else {
3458: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3459: $names{'lastname'}.' '.$names{'generation'};
3460: $name=~s/\s+$//;
3461: $name=~s/\s+/ /g;
3462: }
3463: return $name;
3464: }
3465:
1.295 www 3466: sub getnames {
3467: my ($uname,$udom)=@_;
1.537 albertel 3468: return if (!defined($uname) || !defined($udom));
1.433 albertel 3469: if ($udom eq 'public' && $uname eq 'public') {
3470: return ('lastname' => &mt('Public'));
3471: }
1.295 www 3472: my $id=$uname.':'.$udom;
3473: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3474: if ($cached) {
3475: return %{$names};
3476: } else {
3477: my %loadnames=&Apache::lonnet::get('environment',
3478: ['firstname','middlename','lastname','generation','nickname'],
3479: $udom,$uname);
3480: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3481: return %loadnames;
3482: }
3483: }
1.61 www 3484:
1.542 raeburn 3485: # -------------------------------------------------------------------- getemails
1.648 raeburn 3486:
1.542 raeburn 3487: =pod
3488:
1.648 raeburn 3489: =item * &getemails($uname,$udom)
1.542 raeburn 3490:
3491: Gets a user's email information and returns it as a hash with keys:
3492: notification, critnotification, permanentemail
3493:
3494: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3495: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3496:
1.648 raeburn 3497:
1.542 raeburn 3498: =cut
3499:
1.648 raeburn 3500:
1.466 albertel 3501: sub getemails {
3502: my ($uname,$udom)=@_;
3503: if ($udom eq 'public' && $uname eq 'public') {
3504: return;
3505: }
1.467 www 3506: if (!$udom) { $udom=$env{'user.domain'}; }
3507: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3508: my $id=$uname.':'.$udom;
3509: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3510: if ($cached) {
3511: return %{$names};
3512: } else {
3513: my %loadnames=&Apache::lonnet::get('environment',
3514: ['notification','critnotification',
3515: 'permanentemail'],
3516: $udom,$uname);
3517: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3518: return %loadnames;
3519: }
3520: }
3521:
1.551 albertel 3522: sub flush_email_cache {
3523: my ($uname,$udom)=@_;
3524: if (!$udom) { $udom =$env{'user.domain'}; }
3525: if (!$uname) { $uname=$env{'user.name'}; }
3526: return if ($udom eq 'public' && $uname eq 'public');
3527: my $id=$uname.':'.$udom;
3528: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3529: }
3530:
1.728 raeburn 3531: # -------------------------------------------------------------------- getlangs
3532:
3533: =pod
3534:
3535: =item * &getlangs($uname,$udom)
3536:
3537: Gets a user's language preference and returns it as a hash with key:
3538: language.
3539:
3540: =cut
3541:
3542:
3543: sub getlangs {
3544: my ($uname,$udom) = @_;
3545: if (!$udom) { $udom =$env{'user.domain'}; }
3546: if (!$uname) { $uname=$env{'user.name'}; }
3547: my $id=$uname.':'.$udom;
3548: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3549: if ($cached) {
3550: return %{$langs};
3551: } else {
3552: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3553: $udom,$uname);
3554: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3555: return %loadlangs;
3556: }
3557: }
3558:
3559: sub flush_langs_cache {
3560: my ($uname,$udom)=@_;
3561: if (!$udom) { $udom =$env{'user.domain'}; }
3562: if (!$uname) { $uname=$env{'user.name'}; }
3563: return if ($udom eq 'public' && $uname eq 'public');
3564: my $id=$uname.':'.$udom;
3565: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3566: }
3567:
1.61 www 3568: # ------------------------------------------------------------------ Screenname
1.81 albertel 3569:
3570: =pod
3571:
1.648 raeburn 3572: =item * &screenname($uname,$udom)
1.81 albertel 3573:
3574: Gets a users screenname and returns it as a string
3575:
3576: =cut
1.61 www 3577:
3578: sub screenname {
3579: my ($uname,$udom)=@_;
1.258 albertel 3580: if ($uname eq $env{'user.name'} &&
3581: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3582: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3583: return $names{'screenname'};
1.62 www 3584: }
3585:
1.212 albertel 3586:
1.802 bisitz 3587: # ------------------------------------------------------------- Confirm Wrapper
3588: =pod
3589:
1.1142 raeburn 3590: =item * &confirmwrapper($message)
1.802 bisitz 3591:
3592: Wrap messages about completion of operation in box
3593:
3594: =cut
3595:
3596: sub confirmwrapper {
3597: my ($message)=@_;
3598: if ($message) {
3599: return "\n".'<div class="LC_confirm_box">'."\n"
3600: .$message."\n"
3601: .'</div>'."\n";
3602: } else {
3603: return $message;
3604: }
3605: }
3606:
1.62 www 3607: # ------------------------------------------------------------- Message Wrapper
3608:
3609: sub messagewrapper {
1.369 www 3610: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3611: return
1.441 albertel 3612: '<a href="/adm/email?compose=individual&'.
3613: 'recname='.$username.'&recdom='.$domain.
3614: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3615: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3616: }
1.802 bisitz 3617:
1.74 www 3618: # --------------------------------------------------------------- Notes Wrapper
3619:
3620: sub noteswrapper {
3621: my ($link,$un,$do)=@_;
3622: return
1.896 amueller 3623: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3624: }
1.802 bisitz 3625:
1.62 www 3626: # ------------------------------------------------------------- Aboutme Wrapper
3627:
3628: sub aboutmewrapper {
1.1070 raeburn 3629: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3630: if (!defined($username) && !defined($domain)) {
3631: return;
3632: }
1.1096 raeburn 3633: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3634: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3635: }
3636:
3637: # ------------------------------------------------------------ Syllabus Wrapper
3638:
3639: sub syllabuswrapper {
1.707 bisitz 3640: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3641: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3642: }
1.14 harris41 3643:
1.802 bisitz 3644: # -----------------------------------------------------------------------------
3645:
1.208 matthew 3646: sub track_student_link {
1.887 raeburn 3647: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3648: my $link ="/adm/trackstudent?";
1.208 matthew 3649: my $title = 'View recent activity';
3650: if (defined($sname) && $sname !~ /^\s*$/ &&
3651: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3652: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3653: $title .= ' of this student';
1.268 albertel 3654: }
1.208 matthew 3655: if (defined($target) && $target !~ /^\s*$/) {
3656: $target = qq{target="$target"};
3657: } else {
3658: $target = '';
3659: }
1.268 albertel 3660: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3661: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3662: $title = &mt($title);
3663: $linktext = &mt($linktext);
1.448 albertel 3664: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3665: &help_open_topic('View_recent_activity');
1.208 matthew 3666: }
3667:
1.781 raeburn 3668: sub slot_reservations_link {
3669: my ($linktext,$sname,$sdom,$target) = @_;
3670: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3671: my $title = 'View slot reservation history';
3672: if (defined($sname) && $sname !~ /^\s*$/ &&
3673: defined($sdom) && $sdom !~ /^\s*$/) {
3674: $link .= "&uname=$sname&udom=$sdom";
3675: $title .= ' of this student';
3676: }
3677: if (defined($target) && $target !~ /^\s*$/) {
3678: $target = qq{target="$target"};
3679: } else {
3680: $target = '';
3681: }
3682: $title = &mt($title);
3683: $linktext = &mt($linktext);
3684: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3685: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3686:
3687: }
3688:
1.508 www 3689: # ===================================================== Display a student photo
3690:
3691:
1.509 albertel 3692: sub student_image_tag {
1.508 www 3693: my ($domain,$user)=@_;
3694: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3695: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3696: return '<img src="'.$imgsrc.'" align="right" />';
3697: } else {
3698: return '';
3699: }
3700: }
3701:
1.112 bowersj2 3702: =pod
3703:
3704: =back
3705:
3706: =head1 Access .tab File Data
3707:
3708: =over 4
3709:
1.648 raeburn 3710: =item * &languageids()
1.112 bowersj2 3711:
3712: returns list of all language ids
3713:
3714: =cut
3715:
1.14 harris41 3716: sub languageids {
1.16 harris41 3717: return sort(keys(%language));
1.14 harris41 3718: }
3719:
1.112 bowersj2 3720: =pod
3721:
1.648 raeburn 3722: =item * &languagedescription()
1.112 bowersj2 3723:
3724: returns description of a specified language id
3725:
3726: =cut
3727:
1.14 harris41 3728: sub languagedescription {
1.125 www 3729: my $code=shift;
3730: return ($supported_language{$code}?'* ':'').
3731: $language{$code}.
1.126 www 3732: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3733: }
3734:
1.1048 foxr 3735: =pod
3736:
3737: =item * &plainlanguagedescription
3738:
3739: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3740: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3741:
3742: =cut
3743:
1.145 www 3744: sub plainlanguagedescription {
3745: my $code=shift;
3746: return $language{$code};
3747: }
3748:
1.1048 foxr 3749: =pod
3750:
3751: =item * &supportedlanguagecode
3752:
3753: Returns the supported language code (e.g. sptutf maps to pt) given a language
3754: code.
3755:
3756: =cut
3757:
1.145 www 3758: sub supportedlanguagecode {
3759: my $code=shift;
3760: return $supported_language{$code};
1.97 www 3761: }
3762:
1.112 bowersj2 3763: =pod
3764:
1.1048 foxr 3765: =item * &latexlanguage()
3766:
3767: Given a language key code returns the correspondnig language to use
3768: to select the correct hyphenation on LaTeX printouts. This is undef if there
3769: is no supported hyphenation for the language code.
3770:
3771: =cut
3772:
3773: sub latexlanguage {
3774: my $code = shift;
3775: return $latex_language{$code};
3776: }
3777:
3778: =pod
3779:
3780: =item * &latexhyphenation()
3781:
3782: Same as above but what's supplied is the language as it might be stored
3783: in the metadata.
3784:
3785: =cut
3786:
3787: sub latexhyphenation {
3788: my $key = shift;
3789: return $latex_language_bykey{$key};
3790: }
3791:
3792: =pod
3793:
1.648 raeburn 3794: =item * ©rightids()
1.112 bowersj2 3795:
3796: returns list of all copyrights
3797:
3798: =cut
3799:
3800: sub copyrightids {
3801: return sort(keys(%cprtag));
3802: }
3803:
3804: =pod
3805:
1.648 raeburn 3806: =item * ©rightdescription()
1.112 bowersj2 3807:
3808: returns description of a specified copyright id
3809:
3810: =cut
3811:
3812: sub copyrightdescription {
1.166 www 3813: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3814: }
1.197 matthew 3815:
3816: =pod
3817:
1.648 raeburn 3818: =item * &source_copyrightids()
1.192 taceyjo1 3819:
3820: returns list of all source copyrights
3821:
3822: =cut
3823:
3824: sub source_copyrightids {
3825: return sort(keys(%scprtag));
3826: }
3827:
3828: =pod
3829:
1.648 raeburn 3830: =item * &source_copyrightdescription()
1.192 taceyjo1 3831:
3832: returns description of a specified source copyright id
3833:
3834: =cut
3835:
3836: sub source_copyrightdescription {
3837: return &mt($scprtag{shift(@_)});
3838: }
1.112 bowersj2 3839:
3840: =pod
3841:
1.648 raeburn 3842: =item * &filecategories()
1.112 bowersj2 3843:
3844: returns list of all file categories
3845:
3846: =cut
3847:
3848: sub filecategories {
3849: return sort(keys(%category_extensions));
3850: }
3851:
3852: =pod
3853:
1.648 raeburn 3854: =item * &filecategorytypes()
1.112 bowersj2 3855:
3856: returns list of file types belonging to a given file
3857: category
3858:
3859: =cut
3860:
3861: sub filecategorytypes {
1.356 albertel 3862: my ($cat) = @_;
3863: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3864: }
3865:
3866: =pod
3867:
1.648 raeburn 3868: =item * &fileembstyle()
1.112 bowersj2 3869:
3870: returns embedding style for a specified file type
3871:
3872: =cut
3873:
3874: sub fileembstyle {
3875: return $fe{lc(shift(@_))};
1.169 www 3876: }
3877:
1.351 www 3878: sub filemimetype {
3879: return $fm{lc(shift(@_))};
3880: }
3881:
1.169 www 3882:
3883: sub filecategoryselect {
3884: my ($name,$value)=@_;
1.189 matthew 3885: return &select_form($value,$name,
1.970 raeburn 3886: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3887: }
3888:
3889: =pod
3890:
1.648 raeburn 3891: =item * &filedescription()
1.112 bowersj2 3892:
3893: returns description for a specified file type
3894:
3895: =cut
3896:
3897: sub filedescription {
1.188 matthew 3898: my $file_description = $fd{lc(shift())};
3899: $file_description =~ s:([\[\]]):~$1:g;
3900: return &mt($file_description);
1.112 bowersj2 3901: }
3902:
3903: =pod
3904:
1.648 raeburn 3905: =item * &filedescriptionex()
1.112 bowersj2 3906:
3907: returns description for a specified file type with
3908: extra formatting
3909:
3910: =cut
3911:
3912: sub filedescriptionex {
3913: my $ex=shift;
1.188 matthew 3914: my $file_description = $fd{lc($ex)};
3915: $file_description =~ s:([\[\]]):~$1:g;
3916: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3917: }
3918:
3919: # End of .tab access
3920: =pod
3921:
3922: =back
3923:
3924: =cut
3925:
3926: # ------------------------------------------------------------------ File Types
3927: sub fileextensions {
3928: return sort(keys(%fe));
3929: }
3930:
1.97 www 3931: # ----------------------------------------------------------- Display Languages
3932: # returns a hash with all desired display languages
3933: #
3934:
3935: sub display_languages {
3936: my %languages=();
1.695 raeburn 3937: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3938: $languages{$lang}=1;
1.97 www 3939: }
3940: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3941: if ($env{'form.displaylanguage'}) {
1.356 albertel 3942: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3943: $languages{$lang}=1;
1.97 www 3944: }
3945: }
3946: return %languages;
1.14 harris41 3947: }
3948:
1.582 albertel 3949: sub languages {
3950: my ($possible_langs) = @_;
1.695 raeburn 3951: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3952: if (!ref($possible_langs)) {
3953: if( wantarray ) {
3954: return @preferred_langs;
3955: } else {
3956: return $preferred_langs[0];
3957: }
3958: }
3959: my %possibilities = map { $_ => 1 } (@$possible_langs);
3960: my @preferred_possibilities;
3961: foreach my $preferred_lang (@preferred_langs) {
3962: if (exists($possibilities{$preferred_lang})) {
3963: push(@preferred_possibilities, $preferred_lang);
3964: }
3965: }
3966: if( wantarray ) {
3967: return @preferred_possibilities;
3968: }
3969: return $preferred_possibilities[0];
3970: }
3971:
1.742 raeburn 3972: sub user_lang {
3973: my ($touname,$toudom,$fromcid) = @_;
3974: my @userlangs;
3975: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3976: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3977: $env{'course.'.$fromcid.'.languages'}));
3978: } else {
3979: my %langhash = &getlangs($touname,$toudom);
3980: if ($langhash{'languages'} ne '') {
3981: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3982: } else {
3983: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3984: if ($domdefs{'lang_def'} ne '') {
3985: @userlangs = ($domdefs{'lang_def'});
3986: }
3987: }
3988: }
3989: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3990: my $user_lh = Apache::localize->get_handle(@languages);
3991: return $user_lh;
3992: }
3993:
3994:
1.112 bowersj2 3995: ###############################################################
3996: ## Student Answer Attempts ##
3997: ###############################################################
3998:
3999: =pod
4000:
4001: =head1 Alternate Problem Views
4002:
4003: =over 4
4004:
1.648 raeburn 4005: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4006: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4007:
4008: Return string with previous attempt on problem. Arguments:
4009:
4010: =over 4
4011:
4012: =item * $symb: Problem, including path
4013:
4014: =item * $username: username of the desired student
4015:
4016: =item * $domain: domain of the desired student
1.14 harris41 4017:
1.112 bowersj2 4018: =item * $course: Course ID
1.14 harris41 4019:
1.112 bowersj2 4020: =item * $getattempt: Leave blank for all attempts, otherwise put
4021: something
1.14 harris41 4022:
1.112 bowersj2 4023: =item * $regexp: if string matches this regexp, the string will be
4024: sent to $gradesub
1.14 harris41 4025:
1.112 bowersj2 4026: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4027:
1.1199 raeburn 4028: =item * $usec: section of the desired student
4029:
4030: =item * $identifier: counter for student (multiple students one problem) or
4031: problem (one student; whole sequence).
4032:
1.112 bowersj2 4033: =back
1.14 harris41 4034:
1.112 bowersj2 4035: The output string is a table containing all desired attempts, if any.
1.16 harris41 4036:
1.112 bowersj2 4037: =cut
1.1 albertel 4038:
4039: sub get_previous_attempt {
1.1199 raeburn 4040: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4041: my $prevattempts='';
1.43 ng 4042: no strict 'refs';
1.1 albertel 4043: if ($symb) {
1.3 albertel 4044: my (%returnhash)=
4045: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4046: if ($returnhash{'version'}) {
4047: my %lasthash=();
4048: my $version;
4049: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4050: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4051: if ($key =~ /\.rawrndseed$/) {
4052: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4053: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4054: } else {
4055: $lasthash{$key}=$returnhash{$version.':'.$key};
4056: }
1.19 harris41 4057: }
1.1 albertel 4058: }
1.596 albertel 4059: $prevattempts=&start_data_table().&start_data_table_header_row();
4060: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4061: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4062: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4063: foreach my $key (sort(keys(%lasthash))) {
4064: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4065: if ($#parts > 0) {
1.31 albertel 4066: my $data=$parts[-1];
1.989 raeburn 4067: next if ($data eq 'foilorder');
1.31 albertel 4068: pop(@parts);
1.1010 www 4069: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4070: if ($data eq 'type') {
4071: unless ($showsurv) {
4072: my $id = join(',',@parts);
4073: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4074: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4075: $lasthidden{$ign.'.'.$id} = 1;
4076: }
1.945 raeburn 4077: }
1.1199 raeburn 4078: if ($identifier ne '') {
4079: my $id = join(',',@parts);
4080: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4081: $domain,$username,$usec,undef,$course) =~ /^no/) {
4082: $hidestatus{$ign.'.'.$id} = 1;
4083: }
4084: }
4085: } elsif ($data eq 'regrader') {
4086: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4087: my $id = join(',',@parts);
4088: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4089: }
1.1010 www 4090: }
1.31 albertel 4091: } else {
1.41 ng 4092: if ($#parts == 0) {
4093: $prevattempts.='<th>'.$parts[0].'</th>';
4094: } else {
4095: $prevattempts.='<th>'.$ign.'</th>';
4096: }
1.31 albertel 4097: }
1.16 harris41 4098: }
1.596 albertel 4099: $prevattempts.=&end_data_table_header_row();
1.40 ng 4100: if ($getattempt eq '') {
1.1199 raeburn 4101: my (%solved,%resets,%probstatus);
1.1200 raeburn 4102: if (($identifier ne '') && (keys(%regraded) > 0)) {
4103: for ($version=1;$version<=$returnhash{'version'};$version++) {
4104: foreach my $id (keys(%regraded)) {
4105: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4106: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4107: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4108: push(@{$resets{$id}},$version);
1.1199 raeburn 4109: }
4110: }
4111: }
1.1200 raeburn 4112: }
4113: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4114: my (@hidden,@unsolved);
1.945 raeburn 4115: if (%typeparts) {
4116: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4117: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4118: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4119: push(@hidden,$id);
1.1199 raeburn 4120: } elsif ($identifier ne '') {
4121: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4122: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4123: ($hidestatus{$id})) {
1.1200 raeburn 4124: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4125: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4126: push(@{$solved{$id}},$version);
4127: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4128: (ref($solved{$id}) eq 'ARRAY')) {
4129: my $skip;
4130: if (ref($resets{$id}) eq 'ARRAY') {
4131: foreach my $reset (@{$resets{$id}}) {
4132: if ($reset > $solved{$id}[-1]) {
4133: $skip=1;
4134: last;
4135: }
4136: }
4137: }
4138: unless ($skip) {
4139: my ($ign,$partslist) = split(/\./,$id,2);
4140: push(@unsolved,$partslist);
4141: }
4142: }
4143: }
1.945 raeburn 4144: }
4145: }
4146: }
4147: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4148: '<td>'.&mt('Transaction [_1]',$version);
4149: if (@unsolved) {
4150: $prevattempts .= '<span class="LC_nobreak"><label>'.
4151: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4152: &mt('Hide').'</label></span>';
4153: }
4154: $prevattempts .= '</td>';
1.945 raeburn 4155: if (@hidden) {
4156: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4157: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4158: my $hide;
4159: foreach my $id (@hidden) {
4160: if ($key =~ /^\Q$id\E/) {
4161: $hide = 1;
4162: last;
4163: }
4164: }
4165: if ($hide) {
4166: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4167: if (($data eq 'award') || ($data eq 'awarddetail')) {
4168: my $value = &format_previous_attempt_value($key,
4169: $returnhash{$version.':'.$key});
1.1173 kruse 4170: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4171: } else {
4172: $prevattempts.='<td> </td>';
4173: }
4174: } else {
4175: if ($key =~ /\./) {
1.1212 raeburn 4176: my $value = $returnhash{$version.':'.$key};
4177: if ($key =~ /\.rndseed$/) {
4178: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4179: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4180: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4181: }
4182: }
4183: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4184: ' </td>';
1.945 raeburn 4185: } else {
4186: $prevattempts.='<td> </td>';
4187: }
4188: }
4189: }
4190: } else {
4191: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4192: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4193: my $value = $returnhash{$version.':'.$key};
4194: if ($key =~ /\.rndseed$/) {
4195: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4196: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4197: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4198: }
4199: }
4200: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4201: ' </td>';
1.945 raeburn 4202: }
4203: }
4204: $prevattempts.=&end_data_table_row();
1.40 ng 4205: }
1.1 albertel 4206: }
1.945 raeburn 4207: my @currhidden = keys(%lasthidden);
1.596 albertel 4208: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4209: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4210: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4211: if (%typeparts) {
4212: my $hidden;
4213: foreach my $id (@currhidden) {
4214: if ($key =~ /^\Q$id\E/) {
4215: $hidden = 1;
4216: last;
4217: }
4218: }
4219: if ($hidden) {
4220: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4221: if (($data eq 'award') || ($data eq 'awarddetail')) {
4222: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4223: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4224: $value = &$gradesub($value);
4225: }
1.1173 kruse 4226: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4227: } else {
4228: $prevattempts.='<td> </td>';
4229: }
4230: } else {
4231: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4232: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4233: $value = &$gradesub($value);
4234: }
1.1173 kruse 4235: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4236: }
4237: } else {
4238: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4239: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4240: $value = &$gradesub($value);
4241: }
1.1173 kruse 4242: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4243: }
1.16 harris41 4244: }
1.596 albertel 4245: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4246: } else {
1.596 albertel 4247: $prevattempts=
4248: &start_data_table().&start_data_table_row().
4249: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4250: &end_data_table_row().&end_data_table();
1.1 albertel 4251: }
4252: } else {
1.596 albertel 4253: $prevattempts=
4254: &start_data_table().&start_data_table_row().
4255: '<td>'.&mt('No data.').'</td>'.
4256: &end_data_table_row().&end_data_table();
1.1 albertel 4257: }
1.10 albertel 4258: }
4259:
1.581 albertel 4260: sub format_previous_attempt_value {
4261: my ($key,$value) = @_;
1.1011 www 4262: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4263: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4264: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4265: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4266: } elsif ($key =~ /answerstring$/) {
4267: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4268: my @answer = %answers;
4269: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4270: my @anskeys = sort(keys(%answers));
4271: if (@anskeys == 1) {
4272: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4273: if ($answer =~ m{\0}) {
4274: $answer =~ s{\0}{,}g;
1.988 raeburn 4275: }
4276: my $tag_internal_answer_name = 'INTERNAL';
4277: if ($anskeys[0] eq $tag_internal_answer_name) {
4278: $value = $answer;
4279: } else {
4280: $value = $anskeys[0].'='.$answer;
4281: }
4282: } else {
4283: foreach my $ans (@anskeys) {
4284: my $answer = $answers{$ans};
1.1001 raeburn 4285: if ($answer =~ m{\0}) {
4286: $answer =~ s{\0}{,}g;
1.988 raeburn 4287: }
4288: $value .= $ans.'='.$answer.'<br />';;
4289: }
4290: }
1.581 albertel 4291: } else {
1.1173 kruse 4292: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4293: }
4294: return $value;
4295: }
4296:
4297:
1.107 albertel 4298: sub relative_to_absolute {
4299: my ($url,$output)=@_;
4300: my $parser=HTML::TokeParser->new(\$output);
4301: my $token;
4302: my $thisdir=$url;
4303: my @rlinks=();
4304: while ($token=$parser->get_token) {
4305: if ($token->[0] eq 'S') {
4306: if ($token->[1] eq 'a') {
4307: if ($token->[2]->{'href'}) {
4308: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4309: }
4310: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4311: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4312: } elsif ($token->[1] eq 'base') {
4313: $thisdir=$token->[2]->{'href'};
4314: }
4315: }
4316: }
4317: $thisdir=~s-/[^/]*$--;
1.356 albertel 4318: foreach my $link (@rlinks) {
1.726 raeburn 4319: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4320: ($link=~/^\//) ||
4321: ($link=~/^javascript:/i) ||
4322: ($link=~/^mailto:/i) ||
4323: ($link=~/^\#/)) {
4324: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4325: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4326: }
4327: }
4328: # -------------------------------------------------- Deal with Applet codebases
4329: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4330: return $output;
4331: }
4332:
1.112 bowersj2 4333: =pod
4334:
1.648 raeburn 4335: =item * &get_student_view()
1.112 bowersj2 4336:
4337: show a snapshot of what student was looking at
4338:
4339: =cut
4340:
1.10 albertel 4341: sub get_student_view {
1.186 albertel 4342: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4343: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4344: my (%form);
1.10 albertel 4345: my @elements=('symb','courseid','domain','username');
4346: foreach my $element (@elements) {
1.186 albertel 4347: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4348: }
1.186 albertel 4349: if (defined($moreenv)) {
4350: %form=(%form,%{$moreenv});
4351: }
1.236 albertel 4352: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4353: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4354: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4355: $userview=~s/\<body[^\>]*\>//gi;
4356: $userview=~s/\<\/body\>//gi;
4357: $userview=~s/\<html\>//gi;
4358: $userview=~s/\<\/html\>//gi;
4359: $userview=~s/\<head\>//gi;
4360: $userview=~s/\<\/head\>//gi;
4361: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4362: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4363: if (wantarray) {
4364: return ($userview,$response);
4365: } else {
4366: return $userview;
4367: }
4368: }
4369:
4370: sub get_student_view_with_retries {
4371: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4372:
4373: my $ok = 0; # True if we got a good response.
4374: my $content;
4375: my $response;
4376:
4377: # Try to get the student_view done. within the retries count:
4378:
4379: do {
4380: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4381: $ok = $response->is_success;
4382: if (!$ok) {
4383: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4384: }
4385: $retries--;
4386: } while (!$ok && ($retries > 0));
4387:
4388: if (!$ok) {
4389: $content = ''; # On error return an empty content.
4390: }
1.651 www 4391: if (wantarray) {
4392: return ($content, $response);
4393: } else {
4394: return $content;
4395: }
1.11 albertel 4396: }
4397:
1.112 bowersj2 4398: =pod
4399:
1.648 raeburn 4400: =item * &get_student_answers()
1.112 bowersj2 4401:
4402: show a snapshot of how student was answering problem
4403:
4404: =cut
4405:
1.11 albertel 4406: sub get_student_answers {
1.100 sakharuk 4407: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4408: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4409: my (%moreenv);
1.11 albertel 4410: my @elements=('symb','courseid','domain','username');
4411: foreach my $element (@elements) {
1.186 albertel 4412: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4413: }
1.186 albertel 4414: $moreenv{'grade_target'}='answer';
4415: %moreenv=(%form,%moreenv);
1.497 raeburn 4416: $feedurl = &Apache::lonnet::clutter($feedurl);
4417: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4418: return $userview;
1.1 albertel 4419: }
1.116 albertel 4420:
4421: =pod
4422:
4423: =item * &submlink()
4424:
1.242 albertel 4425: Inputs: $text $uname $udom $symb $target
1.116 albertel 4426:
4427: Returns: A link to grades.pm such as to see the SUBM view of a student
4428:
4429: =cut
4430:
4431: ###############################################
4432: sub submlink {
1.242 albertel 4433: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4434: if (!($uname && $udom)) {
4435: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4436: &Apache::lonnet::whichuser($symb);
1.116 albertel 4437: if (!$symb) { $symb=$cursymb; }
4438: }
1.254 matthew 4439: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4440: $symb=&escape($symb);
1.960 bisitz 4441: if ($target) { $target=" target=\"$target\""; }
4442: return
4443: '<a href="/adm/grades?command=submission'.
4444: '&symb='.$symb.
4445: '&student='.$uname.
4446: '&userdom='.$udom.'"'.
4447: $target.'>'.$text.'</a>';
1.242 albertel 4448: }
4449: ##############################################
4450:
4451: =pod
4452:
4453: =item * &pgrdlink()
4454:
4455: Inputs: $text $uname $udom $symb $target
4456:
4457: Returns: A link to grades.pm such as to see the PGRD view of a student
4458:
4459: =cut
4460:
4461: ###############################################
4462: sub pgrdlink {
4463: my $link=&submlink(@_);
4464: $link=~s/(&command=submission)/$1&showgrading=yes/;
4465: return $link;
4466: }
4467: ##############################################
4468:
4469: =pod
4470:
4471: =item * &pprmlink()
4472:
4473: Inputs: $text $uname $udom $symb $target
4474:
4475: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4476: student and a specific resource
1.242 albertel 4477:
4478: =cut
4479:
4480: ###############################################
4481: sub pprmlink {
4482: my ($text,$uname,$udom,$symb,$target)=@_;
4483: if (!($uname && $udom)) {
4484: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4485: &Apache::lonnet::whichuser($symb);
1.242 albertel 4486: if (!$symb) { $symb=$cursymb; }
4487: }
1.254 matthew 4488: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4489: $symb=&escape($symb);
1.242 albertel 4490: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4491: return '<a href="/adm/parmset?command=set&'.
4492: 'symb='.$symb.'&uname='.$uname.
4493: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4494: }
4495: ##############################################
1.37 matthew 4496:
1.112 bowersj2 4497: =pod
4498:
4499: =back
4500:
4501: =cut
4502:
1.37 matthew 4503: ###############################################
1.51 www 4504:
4505:
4506: sub timehash {
1.687 raeburn 4507: my ($thistime) = @_;
4508: my $timezone = &Apache::lonlocal::gettimezone();
4509: my $dt = DateTime->from_epoch(epoch => $thistime)
4510: ->set_time_zone($timezone);
4511: my $wday = $dt->day_of_week();
4512: if ($wday == 7) { $wday = 0; }
4513: return ( 'second' => $dt->second(),
4514: 'minute' => $dt->minute(),
4515: 'hour' => $dt->hour(),
4516: 'day' => $dt->day_of_month(),
4517: 'month' => $dt->month(),
4518: 'year' => $dt->year(),
4519: 'weekday' => $wday,
4520: 'dayyear' => $dt->day_of_year(),
4521: 'dlsav' => $dt->is_dst() );
1.51 www 4522: }
4523:
1.370 www 4524: sub utc_string {
4525: my ($date)=@_;
1.371 www 4526: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4527: }
4528:
1.51 www 4529: sub maketime {
4530: my %th=@_;
1.687 raeburn 4531: my ($epoch_time,$timezone,$dt);
4532: $timezone = &Apache::lonlocal::gettimezone();
4533: eval {
4534: $dt = DateTime->new( year => $th{'year'},
4535: month => $th{'month'},
4536: day => $th{'day'},
4537: hour => $th{'hour'},
4538: minute => $th{'minute'},
4539: second => $th{'second'},
4540: time_zone => $timezone,
4541: );
4542: };
4543: if (!$@) {
4544: $epoch_time = $dt->epoch;
4545: if ($epoch_time) {
4546: return $epoch_time;
4547: }
4548: }
1.51 www 4549: return POSIX::mktime(
4550: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4551: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4552: }
4553:
4554: #########################################
1.51 www 4555:
4556: sub findallcourses {
1.482 raeburn 4557: my ($roles,$uname,$udom) = @_;
1.355 albertel 4558: my %roles;
4559: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4560: my %courses;
1.51 www 4561: my $now=time;
1.482 raeburn 4562: if (!defined($uname)) {
4563: $uname = $env{'user.name'};
4564: }
4565: if (!defined($udom)) {
4566: $udom = $env{'user.domain'};
4567: }
4568: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4569: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4570: if (!%roles) {
4571: %roles = (
4572: cc => 1,
1.907 raeburn 4573: co => 1,
1.482 raeburn 4574: in => 1,
4575: ep => 1,
4576: ta => 1,
4577: cr => 1,
4578: st => 1,
4579: );
4580: }
4581: foreach my $entry (keys(%roleshash)) {
4582: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4583: if ($trole =~ /^cr/) {
4584: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4585: } else {
4586: next if (!exists($roles{$trole}));
4587: }
4588: if ($tend) {
4589: next if ($tend < $now);
4590: }
4591: if ($tstart) {
4592: next if ($tstart > $now);
4593: }
1.1058 raeburn 4594: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4595: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4596: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4597: if ($secpart eq '') {
4598: ($cnum,$role) = split(/_/,$cnumpart);
4599: $sec = 'none';
1.1058 raeburn 4600: $value .= $cnum.'/';
1.482 raeburn 4601: } else {
4602: $cnum = $cnumpart;
4603: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4604: $value .= $cnum.'/'.$sec;
4605: }
4606: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4607: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4608: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4609: }
4610: } else {
4611: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4612: }
1.482 raeburn 4613: }
4614: } else {
4615: foreach my $key (keys(%env)) {
1.483 albertel 4616: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4617: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4618: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4619: next if ($role eq 'ca' || $role eq 'aa');
4620: next if (%roles && !exists($roles{$role}));
4621: my ($starttime,$endtime)=split(/\./,$env{$key});
4622: my $active=1;
4623: if ($starttime) {
4624: if ($now<$starttime) { $active=0; }
4625: }
4626: if ($endtime) {
4627: if ($now>$endtime) { $active=0; }
4628: }
4629: if ($active) {
1.1058 raeburn 4630: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4631: if ($sec eq '') {
4632: $sec = 'none';
1.1058 raeburn 4633: } else {
4634: $value .= $sec;
4635: }
4636: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4637: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4638: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4639: }
4640: } else {
4641: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4642: }
1.474 raeburn 4643: }
4644: }
1.51 www 4645: }
4646: }
1.474 raeburn 4647: return %courses;
1.51 www 4648: }
1.37 matthew 4649:
1.54 www 4650: ###############################################
1.474 raeburn 4651:
4652: sub blockcheck {
1.1189 raeburn 4653: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4654:
1.1189 raeburn 4655: if (defined($udom) && defined($uname)) {
4656: # If uname and udom are for a course, check for blocks in the course.
4657: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4658: my ($startblock,$endblock,$triggerblock) =
4659: &get_blocks($setters,$activity,$udom,$uname,$url);
4660: return ($startblock,$endblock,$triggerblock);
4661: }
4662: } else {
1.490 raeburn 4663: $udom = $env{'user.domain'};
4664: $uname = $env{'user.name'};
4665: }
4666:
1.502 raeburn 4667: my $startblock = 0;
4668: my $endblock = 0;
1.1062 raeburn 4669: my $triggerblock = '';
1.482 raeburn 4670: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4671:
1.490 raeburn 4672: # If uname is for a user, and activity is course-specific, i.e.,
4673: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4674:
1.490 raeburn 4675: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1189 raeburn 4676: $activity eq 'groups' || $activity eq 'printout') &&
4677: ($env{'request.course.id'})) {
1.490 raeburn 4678: foreach my $key (keys(%live_courses)) {
4679: if ($key ne $env{'request.course.id'}) {
4680: delete($live_courses{$key});
4681: }
4682: }
4683: }
4684:
4685: my $otheruser = 0;
4686: my %own_courses;
4687: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4688: # Resource belongs to user other than current user.
4689: $otheruser = 1;
4690: # Gather courses for current user
4691: %own_courses =
4692: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4693: }
4694:
4695: # Gather active course roles - course coordinator, instructor,
4696: # exam proctor, ta, student, or custom role.
1.474 raeburn 4697:
4698: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4699: my ($cdom,$cnum);
4700: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4701: $cdom = $env{'course.'.$course.'.domain'};
4702: $cnum = $env{'course.'.$course.'.num'};
4703: } else {
1.490 raeburn 4704: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4705: }
4706: my $no_ownblock = 0;
4707: my $no_userblock = 0;
1.533 raeburn 4708: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4709: # Check if current user has 'evb' priv for this
4710: if (defined($own_courses{$course})) {
4711: foreach my $sec (keys(%{$own_courses{$course}})) {
4712: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4713: if ($sec ne 'none') {
4714: $checkrole .= '/'.$sec;
4715: }
4716: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4717: $no_ownblock = 1;
4718: last;
4719: }
4720: }
4721: }
4722: # if they have 'evb' priv and are currently not playing student
4723: next if (($no_ownblock) &&
4724: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4725: }
1.474 raeburn 4726: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4727: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4728: if ($sec ne 'none') {
1.482 raeburn 4729: $checkrole .= '/'.$sec;
1.474 raeburn 4730: }
1.490 raeburn 4731: if ($otheruser) {
4732: # Resource belongs to user other than current user.
4733: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4734: my (%allroles,%userroles);
4735: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4736: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4737: my ($trole,$tdom,$tnum,$tsec);
4738: if ($entry =~ /^cr/) {
4739: ($trole,$tdom,$tnum,$tsec) =
4740: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4741: } else {
4742: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4743: }
4744: my ($spec,$area,$trest);
4745: $area = '/'.$tdom.'/'.$tnum;
4746: $trest = $tnum;
4747: if ($tsec ne '') {
4748: $area .= '/'.$tsec;
4749: $trest .= '/'.$tsec;
4750: }
4751: $spec = $trole.'.'.$area;
4752: if ($trole =~ /^cr/) {
4753: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4754: $tdom,$spec,$trest,$area);
4755: } else {
4756: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4757: $tdom,$spec,$trest,$area);
4758: }
4759: }
4760: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4761: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4762: if ($1) {
4763: $no_userblock = 1;
4764: last;
4765: }
1.486 raeburn 4766: }
4767: }
1.490 raeburn 4768: } else {
4769: # Resource belongs to current user
4770: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4771: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4772: $no_ownblock = 1;
4773: last;
4774: }
1.474 raeburn 4775: }
4776: }
4777: # if they have the evb priv and are currently not playing student
1.482 raeburn 4778: next if (($no_ownblock) &&
1.491 albertel 4779: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4780: next if ($no_userblock);
1.474 raeburn 4781:
1.866 kalberla 4782: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4783: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4784:
1.1062 raeburn 4785: my ($start,$end,$trigger) =
4786: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4787: if (($start != 0) &&
4788: (($startblock == 0) || ($startblock > $start))) {
4789: $startblock = $start;
1.1062 raeburn 4790: if ($trigger ne '') {
4791: $triggerblock = $trigger;
4792: }
1.502 raeburn 4793: }
4794: if (($end != 0) &&
4795: (($endblock == 0) || ($endblock < $end))) {
4796: $endblock = $end;
1.1062 raeburn 4797: if ($trigger ne '') {
4798: $triggerblock = $trigger;
4799: }
1.502 raeburn 4800: }
1.490 raeburn 4801: }
1.1062 raeburn 4802: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4803: }
4804:
4805: sub get_blocks {
1.1062 raeburn 4806: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4807: my $startblock = 0;
4808: my $endblock = 0;
1.1062 raeburn 4809: my $triggerblock = '';
1.490 raeburn 4810: my $course = $cdom.'_'.$cnum;
4811: $setters->{$course} = {};
4812: $setters->{$course}{'staff'} = [];
4813: $setters->{$course}{'times'} = [];
1.1062 raeburn 4814: $setters->{$course}{'triggers'} = [];
4815: my (@blockers,%triggered);
4816: my $now = time;
4817: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4818: if ($activity eq 'docs') {
4819: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4820: foreach my $block (@blockers) {
4821: if ($block =~ /^firstaccess____(.+)$/) {
4822: my $item = $1;
4823: my $type = 'map';
4824: my $timersymb = $item;
4825: if ($item eq 'course') {
4826: $type = 'course';
4827: } elsif ($item =~ /___\d+___/) {
4828: $type = 'resource';
4829: } else {
4830: $timersymb = &Apache::lonnet::symbread($item);
4831: }
4832: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4833: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4834: $triggered{$block} = {
4835: start => $start,
4836: end => $end,
4837: type => $type,
4838: };
4839: }
4840: }
4841: } else {
4842: foreach my $block (keys(%commblocks)) {
4843: if ($block =~ m/^(\d+)____(\d+)$/) {
4844: my ($start,$end) = ($1,$2);
4845: if ($start <= time && $end >= time) {
4846: if (ref($commblocks{$block}) eq 'HASH') {
4847: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4848: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4849: unless(grep(/^\Q$block\E$/,@blockers)) {
4850: push(@blockers,$block);
4851: }
4852: }
4853: }
4854: }
4855: }
4856: } elsif ($block =~ /^firstaccess____(.+)$/) {
4857: my $item = $1;
4858: my $timersymb = $item;
4859: my $type = 'map';
4860: if ($item eq 'course') {
4861: $type = 'course';
4862: } elsif ($item =~ /___\d+___/) {
4863: $type = 'resource';
4864: } else {
4865: $timersymb = &Apache::lonnet::symbread($item);
4866: }
4867: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4868: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4869: if ($start && $end) {
4870: if (($start <= time) && ($end >= time)) {
4871: unless (grep(/^\Q$block\E$/,@blockers)) {
4872: push(@blockers,$block);
4873: $triggered{$block} = {
4874: start => $start,
4875: end => $end,
4876: type => $type,
4877: };
4878: }
4879: }
1.490 raeburn 4880: }
1.1062 raeburn 4881: }
4882: }
4883: }
4884: foreach my $blocker (@blockers) {
4885: my ($staff_name,$staff_dom,$title,$blocks) =
4886: &parse_block_record($commblocks{$blocker});
4887: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4888: my ($start,$end,$triggertype);
4889: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4890: ($start,$end) = ($1,$2);
4891: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4892: $start = $triggered{$blocker}{'start'};
4893: $end = $triggered{$blocker}{'end'};
4894: $triggertype = $triggered{$blocker}{'type'};
4895: }
4896: if ($start) {
4897: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4898: if ($triggertype) {
4899: push(@{$$setters{$course}{'triggers'}},$triggertype);
4900: } else {
4901: push(@{$$setters{$course}{'triggers'}},0);
4902: }
4903: if ( ($startblock == 0) || ($startblock > $start) ) {
4904: $startblock = $start;
4905: if ($triggertype) {
4906: $triggerblock = $blocker;
1.474 raeburn 4907: }
4908: }
1.1062 raeburn 4909: if ( ($endblock == 0) || ($endblock < $end) ) {
4910: $endblock = $end;
4911: if ($triggertype) {
4912: $triggerblock = $blocker;
4913: }
4914: }
1.474 raeburn 4915: }
4916: }
1.1062 raeburn 4917: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4918: }
4919:
4920: sub parse_block_record {
4921: my ($record) = @_;
4922: my ($setuname,$setudom,$title,$blocks);
4923: if (ref($record) eq 'HASH') {
4924: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4925: $title = &unescape($record->{'event'});
4926: $blocks = $record->{'blocks'};
4927: } else {
4928: my @data = split(/:/,$record,3);
4929: if (scalar(@data) eq 2) {
4930: $title = $data[1];
4931: ($setuname,$setudom) = split(/@/,$data[0]);
4932: } else {
4933: ($setuname,$setudom,$title) = @data;
4934: }
4935: $blocks = { 'com' => 'on' };
4936: }
4937: return ($setuname,$setudom,$title,$blocks);
4938: }
4939:
1.854 kalberla 4940: sub blocking_status {
1.1189 raeburn 4941: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4942: my %setters;
1.890 droeschl 4943:
1.1061 raeburn 4944: # check for active blocking
1.1062 raeburn 4945: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 4946: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4947: my $blocked = 0;
4948: if ($startblock && $endblock) {
4949: $blocked = 1;
4950: }
1.890 droeschl 4951:
1.1061 raeburn 4952: # caller just wants to know whether a block is active
4953: if (!wantarray) { return $blocked; }
4954:
4955: # build a link to a popup window containing the details
4956: my $querystring = "?activity=$activity";
4957: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4958: if ($activity eq 'port') {
4959: $querystring .= "&udom=$udom" if $udom;
4960: $querystring .= "&uname=$uname" if $uname;
4961: } elsif ($activity eq 'docs') {
4962: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4963: }
1.1061 raeburn 4964:
4965: my $output .= <<'END_MYBLOCK';
4966: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4967: var options = "width=" + w + ",height=" + h + ",";
4968: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4969: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4970: var newWin = window.open(url, wdwName, options);
4971: newWin.focus();
4972: }
1.890 droeschl 4973: END_MYBLOCK
1.854 kalberla 4974:
1.1061 raeburn 4975: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4976:
1.1061 raeburn 4977: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4978: my $text = &mt('Communication Blocked');
1.1217 raeburn 4979: my $class = 'LC_comblock';
1.1062 raeburn 4980: if ($activity eq 'docs') {
4981: $text = &mt('Content Access Blocked');
1.1217 raeburn 4982: $class = '';
1.1063 raeburn 4983: } elsif ($activity eq 'printout') {
4984: $text = &mt('Printing Blocked');
1.1062 raeburn 4985: }
1.1061 raeburn 4986: $output .= <<"END_BLOCK";
1.1217 raeburn 4987: <div class='$class'>
1.869 kalberla 4988: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4989: title='$text'>
4990: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4991: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4992: title='$text'>$text</a>
1.867 kalberla 4993: </div>
4994:
4995: END_BLOCK
1.474 raeburn 4996:
1.1061 raeburn 4997: return ($blocked, $output);
1.854 kalberla 4998: }
1.490 raeburn 4999:
1.60 matthew 5000: ###############################################
5001:
1.682 raeburn 5002: sub check_ip_acc {
1.1201 raeburn 5003: my ($acc,$clientip)=@_;
1.682 raeburn 5004: &Apache::lonxml::debug("acc is $acc");
5005: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5006: return 1;
5007: }
1.1219 raeburn 5008: my $allowed;
1.1201 raeburn 5009: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
1.682 raeburn 5010:
5011: my $name;
1.1219 raeburn 5012: my %access = (
5013: allowfrom => 1,
5014: denyfrom => 0,
5015: );
5016: my @allows;
5017: my @denies;
5018: foreach my $item (split(',',$acc)) {
5019: $item =~ s/^\s*//;
5020: $item =~ s/\s*$//;
5021: my $pattern;
5022: if ($item =~ /^\!(.+)$/) {
5023: push(@denies,$1);
5024: } else {
5025: push(@allows,$item);
5026: }
5027: }
5028: my $numdenies = scalar(@denies);
5029: my $numallows = scalar(@allows);
5030: my $count = 0;
5031: foreach my $pattern (@denies,@allows) {
5032: $count ++;
5033: my $acctype = 'allowfrom';
5034: if ($count <= $numdenies) {
5035: $acctype = 'denyfrom';
5036: }
1.682 raeburn 5037: if ($pattern =~ /\*$/) {
5038: #35.8.*
5039: $pattern=~s/\*//;
1.1219 raeburn 5040: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5041: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5042: #35.8.3.[34-56]
5043: my $low=$2;
5044: my $high=$3;
5045: $pattern=$1;
5046: if ($ip =~ /^\Q$pattern\E/) {
5047: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5048: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5049: }
5050: } elsif ($pattern =~ /^\*/) {
5051: #*.msu.edu
5052: $pattern=~s/\*//;
5053: if (!defined($name)) {
5054: use Socket;
5055: my $netaddr=inet_aton($ip);
5056: ($name)=gethostbyaddr($netaddr,AF_INET);
5057: }
1.1219 raeburn 5058: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5059: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5060: #127.0.0.1
1.1219 raeburn 5061: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5062: } else {
5063: #some.name.com
5064: if (!defined($name)) {
5065: use Socket;
5066: my $netaddr=inet_aton($ip);
5067: ($name)=gethostbyaddr($netaddr,AF_INET);
5068: }
1.1219 raeburn 5069: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5070: }
5071: if ($allowed =~ /^(0|1)$/) { last; }
5072: }
5073: if ($allowed eq '') {
5074: if ($numdenies && !$numallows) {
5075: $allowed = 1;
5076: } else {
5077: $allowed = 0;
1.682 raeburn 5078: }
5079: }
5080: return $allowed;
5081: }
5082:
5083: ###############################################
5084:
1.60 matthew 5085: =pod
5086:
1.112 bowersj2 5087: =head1 Domain Template Functions
5088:
5089: =over 4
5090:
5091: =item * &determinedomain()
1.60 matthew 5092:
5093: Inputs: $domain (usually will be undef)
5094:
1.63 www 5095: Returns: Determines which domain should be used for designs
1.60 matthew 5096:
5097: =cut
1.54 www 5098:
1.60 matthew 5099: ###############################################
1.63 www 5100: sub determinedomain {
5101: my $domain=shift;
1.531 albertel 5102: if (! $domain) {
1.60 matthew 5103: # Determine domain if we have not been given one
1.893 raeburn 5104: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5105: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5106: if ($env{'request.role.domain'}) {
5107: $domain=$env{'request.role.domain'};
1.60 matthew 5108: }
5109: }
1.63 www 5110: return $domain;
5111: }
5112: ###############################################
1.517 raeburn 5113:
1.518 albertel 5114: sub devalidate_domconfig_cache {
5115: my ($udom)=@_;
5116: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5117: }
5118:
5119: # ---------------------- Get domain configuration for a domain
5120: sub get_domainconf {
5121: my ($udom) = @_;
5122: my $cachetime=1800;
5123: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5124: if (defined($cached)) { return %{$result}; }
5125:
5126: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5127: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5128: my (%designhash,%legacy);
1.518 albertel 5129: if (keys(%domconfig) > 0) {
5130: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5131: if (keys(%{$domconfig{'login'}})) {
5132: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5133: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5134: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5135: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5136: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5137: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5138: if ($key eq 'loginvia') {
5139: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5140: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5141: $designhash{$udom.'.login.loginvia'} = $server;
5142: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5143:
5144: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5145: } else {
5146: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5147: }
1.948 raeburn 5148: }
1.1208 raeburn 5149: } elsif ($key eq 'headtag') {
5150: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5151: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5152: }
1.946 raeburn 5153: }
1.1208 raeburn 5154: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5155: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5156: }
1.946 raeburn 5157: }
5158: }
5159: }
5160: } else {
5161: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5162: $designhash{$udom.'.login.'.$key.'_'.$img} =
5163: $domconfig{'login'}{$key}{$img};
5164: }
1.699 raeburn 5165: }
5166: } else {
5167: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5168: }
1.632 raeburn 5169: }
5170: } else {
5171: $legacy{'login'} = 1;
1.518 albertel 5172: }
1.632 raeburn 5173: } else {
5174: $legacy{'login'} = 1;
1.518 albertel 5175: }
5176: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5177: if (keys(%{$domconfig{'rolecolors'}})) {
5178: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5179: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5180: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5181: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5182: }
1.518 albertel 5183: }
5184: }
1.632 raeburn 5185: } else {
5186: $legacy{'rolecolors'} = 1;
1.518 albertel 5187: }
1.632 raeburn 5188: } else {
5189: $legacy{'rolecolors'} = 1;
1.518 albertel 5190: }
1.948 raeburn 5191: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5192: if ($domconfig{'autoenroll'}{'co-owners'}) {
5193: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5194: }
5195: }
1.632 raeburn 5196: if (keys(%legacy) > 0) {
5197: my %legacyhash = &get_legacy_domconf($udom);
5198: foreach my $item (keys(%legacyhash)) {
5199: if ($item =~ /^\Q$udom\E\.login/) {
5200: if ($legacy{'login'}) {
5201: $designhash{$item} = $legacyhash{$item};
5202: }
5203: } else {
5204: if ($legacy{'rolecolors'}) {
5205: $designhash{$item} = $legacyhash{$item};
5206: }
1.518 albertel 5207: }
5208: }
5209: }
1.632 raeburn 5210: } else {
5211: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5212: }
5213: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5214: $cachetime);
5215: return %designhash;
5216: }
5217:
1.632 raeburn 5218: sub get_legacy_domconf {
5219: my ($udom) = @_;
5220: my %legacyhash;
5221: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5222: my $designfile = $designdir.'/'.$udom.'.tab';
5223: if (-e $designfile) {
5224: if ( open (my $fh,"<$designfile") ) {
5225: while (my $line = <$fh>) {
5226: next if ($line =~ /^\#/);
5227: chomp($line);
5228: my ($key,$val)=(split(/\=/,$line));
5229: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5230: }
5231: close($fh);
5232: }
5233: }
1.1026 raeburn 5234: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5235: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5236: }
5237: return %legacyhash;
5238: }
5239:
1.63 www 5240: =pod
5241:
1.112 bowersj2 5242: =item * &domainlogo()
1.63 www 5243:
5244: Inputs: $domain (usually will be undef)
5245:
5246: Returns: A link to a domain logo, if the domain logo exists.
5247: If the domain logo does not exist, a description of the domain.
5248:
5249: =cut
1.112 bowersj2 5250:
1.63 www 5251: ###############################################
5252: sub domainlogo {
1.517 raeburn 5253: my $domain = &determinedomain(shift);
1.518 albertel 5254: my %designhash = &get_domainconf($domain);
1.517 raeburn 5255: # See if there is a logo
5256: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5257: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5258: if ($imgsrc =~ m{^/(adm|res)/}) {
5259: if ($imgsrc =~ m{^/res/}) {
5260: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5261: &Apache::lonnet::repcopy($local_name);
5262: }
5263: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5264: }
5265: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5266: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5267: return &Apache::lonnet::domain($domain,'description');
1.59 www 5268: } else {
1.60 matthew 5269: return '';
1.59 www 5270: }
5271: }
1.63 www 5272: ##############################################
5273:
5274: =pod
5275:
1.112 bowersj2 5276: =item * &designparm()
1.63 www 5277:
5278: Inputs: $which parameter; $domain (usually will be undef)
5279:
5280: Returns: value of designparamter $which
5281:
5282: =cut
1.112 bowersj2 5283:
1.397 albertel 5284:
1.400 albertel 5285: ##############################################
1.397 albertel 5286: sub designparm {
5287: my ($which,$domain)=@_;
5288: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5289: return $env{'environment.color.'.$which};
1.96 www 5290: }
1.63 www 5291: $domain=&determinedomain($domain);
1.1016 raeburn 5292: my %domdesign;
5293: unless ($domain eq 'public') {
5294: %domdesign = &get_domainconf($domain);
5295: }
1.520 raeburn 5296: my $output;
1.517 raeburn 5297: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5298: $output = $domdesign{$domain.'.'.$which};
1.63 www 5299: } else {
1.520 raeburn 5300: $output = $defaultdesign{$which};
5301: }
5302: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5303: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5304: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5305: if ($output =~ m{^/res/}) {
5306: my $local_name = &Apache::lonnet::filelocation('',$output);
5307: &Apache::lonnet::repcopy($local_name);
5308: }
1.520 raeburn 5309: $output = &lonhttpdurl($output);
5310: }
1.63 www 5311: }
1.520 raeburn 5312: return $output;
1.63 www 5313: }
1.59 www 5314:
1.822 bisitz 5315: ##############################################
5316: =pod
5317:
1.832 bisitz 5318: =item * &authorspace()
5319:
1.1028 raeburn 5320: Inputs: $url (usually will be undef).
1.832 bisitz 5321:
1.1132 raeburn 5322: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5323: directory being viewed (or for which action is being taken).
5324: If $url is provided, and begins /priv/<domain>/<uname>
5325: the path will be that portion of the $context argument.
5326: Otherwise the path will be for the author space of the current
5327: user when the current role is author, or for that of the
5328: co-author/assistant co-author space when the current role
5329: is co-author or assistant co-author.
1.832 bisitz 5330:
5331: =cut
5332:
5333: sub authorspace {
1.1028 raeburn 5334: my ($url) = @_;
5335: if ($url ne '') {
5336: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5337: return $1;
5338: }
5339: }
1.832 bisitz 5340: my $caname = '';
1.1024 www 5341: my $cadom = '';
1.1028 raeburn 5342: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5343: ($cadom,$caname) =
1.832 bisitz 5344: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5345: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5346: $caname = $env{'user.name'};
1.1024 www 5347: $cadom = $env{'user.domain'};
1.832 bisitz 5348: }
1.1028 raeburn 5349: if (($caname ne '') && ($cadom ne '')) {
5350: return "/priv/$cadom/$caname/";
5351: }
5352: return;
1.832 bisitz 5353: }
5354:
5355: ##############################################
5356: =pod
5357:
1.822 bisitz 5358: =item * &head_subbox()
5359:
5360: Inputs: $content (contains HTML code with page functions, etc.)
5361:
5362: Returns: HTML div with $content
5363: To be included in page header
5364:
5365: =cut
5366:
5367: sub head_subbox {
5368: my ($content)=@_;
5369: my $output =
1.993 raeburn 5370: '<div class="LC_head_subbox">'
1.822 bisitz 5371: .$content
5372: .'</div>'
5373: }
5374:
5375: ##############################################
5376: =pod
5377:
5378: =item * &CSTR_pageheader()
5379:
1.1026 raeburn 5380: Input: (optional) filename from which breadcrumb trail is built.
5381: In most cases no input as needed, as $env{'request.filename'}
5382: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5383:
5384: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5385: To be included on Authoring Space pages
1.822 bisitz 5386:
5387: =cut
5388:
5389: sub CSTR_pageheader {
1.1026 raeburn 5390: my ($trailfile) = @_;
5391: if ($trailfile eq '') {
5392: $trailfile = $env{'request.filename'};
5393: }
5394:
5395: # this is for resources; directories have customtitle, and crumbs
5396: # and select recent are created in lonpubdir.pm
5397:
5398: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5399: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5400: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5401: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5402: $formaction =~ s{/+}{/}g;
1.822 bisitz 5403:
5404: my $parentpath = '';
5405: my $lastitem = '';
5406: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5407: $parentpath = $1;
5408: $lastitem = $2;
5409: } else {
5410: $lastitem = $thisdisfn;
5411: }
1.921 bisitz 5412:
5413: my $output =
1.822 bisitz 5414: '<div>'
5415: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1132 raeburn 5416: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5417: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5418: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5419: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5420:
5421: if ($lastitem) {
5422: $output .=
5423: '<span class="LC_filename">'
5424: .$lastitem
5425: .'</span>';
5426: }
5427: $output .=
5428: '<br />'
1.822 bisitz 5429: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5430: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5431: .'</form>'
5432: .&Apache::lonmenu::constspaceform()
5433: .'</div>';
1.921 bisitz 5434:
5435: return $output;
1.822 bisitz 5436: }
5437:
1.60 matthew 5438: ###############################################
5439: ###############################################
5440:
5441: =pod
5442:
1.112 bowersj2 5443: =back
5444:
1.549 albertel 5445: =head1 HTML Helpers
1.112 bowersj2 5446:
5447: =over 4
5448:
5449: =item * &bodytag()
1.60 matthew 5450:
5451: Returns a uniform header for LON-CAPA web pages.
5452:
5453: Inputs:
5454:
1.112 bowersj2 5455: =over 4
5456:
5457: =item * $title, A title to be displayed on the page.
5458:
5459: =item * $function, the current role (can be undef).
5460:
5461: =item * $addentries, extra parameters for the <body> tag.
5462:
5463: =item * $bodyonly, if defined, only return the <body> tag.
5464:
5465: =item * $domain, if defined, force a given domain.
5466:
5467: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5468: text interface only)
1.60 matthew 5469:
1.814 bisitz 5470: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5471: navigational links
1.317 albertel 5472:
1.338 albertel 5473: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5474:
1.460 albertel 5475: =item * $args, optional argument valid values are
5476: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5477: inherit_jsmath -> when creating popup window in a page,
5478: should it have jsmath forced on by the
5479: current page
1.460 albertel 5480:
1.1096 raeburn 5481: =item * $advtoolsref, optional argument, ref to an array containing
5482: inlineremote items to be added in "Functions" menu below
5483: breadcrumbs.
5484:
1.112 bowersj2 5485: =back
5486:
1.60 matthew 5487: Returns: A uniform header for LON-CAPA web pages.
5488: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5489: If $bodyonly is undef or zero, an html string containing a <body> tag and
5490: other decorations will be returned.
5491:
5492: =cut
5493:
1.54 www 5494: sub bodytag {
1.831 bisitz 5495: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5496: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5497:
1.954 raeburn 5498: my $public;
5499: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5500: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5501: $public = 1;
5502: }
1.460 albertel 5503: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5504: my $httphost = $args->{'use_absolute'};
1.339 albertel 5505:
1.183 matthew 5506: $function = &get_users_function() if (!$function);
1.339 albertel 5507: my $img = &designparm($function.'.img',$domain);
5508: my $font = &designparm($function.'.font',$domain);
5509: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5510:
1.803 bisitz 5511: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5512: 'bgcolor' => $pgbg,
1.339 albertel 5513: 'text' => $font,
5514: 'alink' => &designparm($function.'.alink',$domain),
5515: 'vlink' => &designparm($function.'.vlink',$domain),
5516: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5517: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5518:
1.63 www 5519: # role and realm
1.1178 raeburn 5520: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5521: if ($realm) {
5522: $realm = '/'.$realm;
5523: }
1.378 raeburn 5524: if ($role eq 'ca') {
1.479 albertel 5525: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5526: $realm = &plainname($rname,$rdom);
1.378 raeburn 5527: }
1.55 www 5528: # realm
1.258 albertel 5529: if ($env{'request.course.id'}) {
1.378 raeburn 5530: if ($env{'request.role'} !~ /^cr/) {
5531: $role = &Apache::lonnet::plaintext($role,&course_type());
5532: }
1.898 raeburn 5533: if ($env{'request.course.sec'}) {
5534: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5535: }
1.359 albertel 5536: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5537: } else {
5538: $role = &Apache::lonnet::plaintext($role);
1.54 www 5539: }
1.433 albertel 5540:
1.359 albertel 5541: if (!$realm) { $realm=' '; }
1.330 albertel 5542:
1.438 albertel 5543: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5544:
1.101 www 5545: # construct main body tag
1.359 albertel 5546: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5547: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5548:
1.1131 raeburn 5549: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5550:
1.1130 raeburn 5551: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5552: return $bodytag;
1.1130 raeburn 5553: }
1.359 albertel 5554:
1.954 raeburn 5555: if ($public) {
1.433 albertel 5556: undef($role);
5557: }
1.359 albertel 5558:
1.762 bisitz 5559: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5560: #
5561: # Extra info if you are the DC
5562: my $dc_info = '';
5563: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5564: $env{'course.'.$env{'request.course.id'}.
5565: '.domain'}.'/'})) {
5566: my $cid = $env{'request.course.id'};
1.917 raeburn 5567: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5568: $dc_info =~ s/\s+$//;
1.359 albertel 5569: }
5570:
1.898 raeburn 5571: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5572:
1.903 droeschl 5573: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5574:
5575: # if ($env{'request.state'} eq 'construct') {
5576: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5577: # }
5578:
1.1130 raeburn 5579: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 5580: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5581:
1.1130 raeburn 5582: my ($left,$right) = Apache::lonmenu::primary_menu();
1.359 albertel 5583:
1.916 droeschl 5584: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5585: if ($dc_info) {
5586: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5587: }
1.1130 raeburn 5588: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5589: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5590: return $bodytag;
5591: }
1.894 droeschl 5592:
1.927 raeburn 5593: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5594: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5595: }
1.916 droeschl 5596:
1.1130 raeburn 5597: $bodytag .= $right;
1.852 droeschl 5598:
1.917 raeburn 5599: if ($dc_info) {
5600: $dc_info = &dc_courseid_toggle($dc_info);
5601: }
5602: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5603:
1.1169 raeburn 5604: #if directed to not display the secondary menu, don't.
1.1168 raeburn 5605: if ($args->{'no_secondary_menu'}) {
5606: return $bodytag;
5607: }
1.1169 raeburn 5608: #don't show menus for public users
1.954 raeburn 5609: if (!$public){
1.1154 raeburn 5610: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5611: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5612: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5613: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5614: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5615: $args->{'bread_crumbs'});
1.1096 raeburn 5616: } elsif ($forcereg) {
5617: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5618: $args->{'group'});
5619: } else {
5620: $bodytag .=
5621: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5622: $forcereg,$args->{'group'},
5623: $args->{'bread_crumbs'},
5624: $advtoolsref);
1.920 raeburn 5625: }
1.903 droeschl 5626: }else{
5627: # this is to seperate menu from content when there's no secondary
5628: # menu. Especially needed for public accessible ressources.
5629: $bodytag .= '<hr style="clear:both" />';
5630: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5631: }
1.903 droeschl 5632:
1.235 raeburn 5633: return $bodytag;
1.182 matthew 5634: }
5635:
1.917 raeburn 5636: sub dc_courseid_toggle {
5637: my ($dc_info) = @_;
1.980 raeburn 5638: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5639: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5640: &mt('(More ...)').'</a></span>'.
5641: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5642: }
5643:
1.330 albertel 5644: sub make_attr_string {
5645: my ($register,$attr_ref) = @_;
5646:
5647: if ($attr_ref && !ref($attr_ref)) {
5648: die("addentries Must be a hash ref ".
5649: join(':',caller(1))." ".
5650: join(':',caller(0))." ");
5651: }
5652:
5653: if ($register) {
1.339 albertel 5654: my ($on_load,$on_unload);
5655: foreach my $key (keys(%{$attr_ref})) {
5656: if (lc($key) eq 'onload') {
5657: $on_load.=$attr_ref->{$key}.';';
5658: delete($attr_ref->{$key});
5659:
5660: } elsif (lc($key) eq 'onunload') {
5661: $on_unload.=$attr_ref->{$key}.';';
5662: delete($attr_ref->{$key});
5663: }
5664: }
1.953 droeschl 5665: $attr_ref->{'onload'} = $on_load;
5666: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5667: }
1.339 albertel 5668:
1.330 albertel 5669: my $attr_string;
1.1159 raeburn 5670: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5671: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5672: }
5673: return $attr_string;
5674: }
5675:
5676:
1.182 matthew 5677: ###############################################
1.251 albertel 5678: ###############################################
5679:
5680: =pod
5681:
5682: =item * &endbodytag()
5683:
5684: Returns a uniform footer for LON-CAPA web pages.
5685:
1.635 raeburn 5686: Inputs: 1 - optional reference to an args hash
5687: If in the hash, key for noredirectlink has a value which evaluates to true,
5688: a 'Continue' link is not displayed if the page contains an
5689: internal redirect in the <head></head> section,
5690: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5691:
5692: =cut
5693:
5694: sub endbodytag {
1.635 raeburn 5695: my ($args) = @_;
1.1080 raeburn 5696: my $endbodytag;
5697: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5698: $endbodytag='</body>';
5699: }
1.269 albertel 5700: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5701: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5702: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5703: $endbodytag=
5704: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5705: &mt('Continue').'</a>'.
5706: $endbodytag;
5707: }
1.315 albertel 5708: }
1.251 albertel 5709: return $endbodytag;
5710: }
5711:
1.352 albertel 5712: =pod
5713:
5714: =item * &standard_css()
5715:
5716: Returns a style sheet
5717:
5718: Inputs: (all optional)
5719: domain -> force to color decorate a page for a specific
5720: domain
5721: function -> force usage of a specific rolish color scheme
5722: bgcolor -> override the default page bgcolor
5723:
5724: =cut
5725:
1.343 albertel 5726: sub standard_css {
1.345 albertel 5727: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5728: $function = &get_users_function() if (!$function);
5729: my $img = &designparm($function.'.img', $domain);
5730: my $tabbg = &designparm($function.'.tabbg', $domain);
5731: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5732: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5733: #second colour for later usage
1.345 albertel 5734: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5735: my $pgbg_or_bgcolor =
5736: $bgcolor ||
1.352 albertel 5737: &designparm($function.'.pgbg', $domain);
1.382 albertel 5738: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5739: my $alink = &designparm($function.'.alink', $domain);
5740: my $vlink = &designparm($function.'.vlink', $domain);
5741: my $link = &designparm($function.'.link', $domain);
5742:
1.602 albertel 5743: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5744: my $mono = 'monospace';
1.850 bisitz 5745: my $data_table_head = $sidebg;
5746: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5747: my $data_table_dark = '#E0E0E0';
1.470 banghart 5748: my $data_table_darker = '#CCCCCC';
1.349 albertel 5749: my $data_table_highlight = '#FFFF00';
1.352 albertel 5750: my $mail_new = '#FFBB77';
5751: my $mail_new_hover = '#DD9955';
5752: my $mail_read = '#BBBB77';
5753: my $mail_read_hover = '#999944';
5754: my $mail_replied = '#AAAA88';
5755: my $mail_replied_hover = '#888855';
5756: my $mail_other = '#99BBBB';
5757: my $mail_other_hover = '#669999';
1.391 albertel 5758: my $table_header = '#DDDDDD';
1.489 raeburn 5759: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5760: my $lg_border_color = '#C8C8C8';
1.952 onken 5761: my $button_hover = '#BF2317';
1.392 albertel 5762:
1.608 albertel 5763: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5764: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5765: : '0 3px 0 4px';
1.448 albertel 5766:
1.523 albertel 5767:
1.343 albertel 5768: return <<END;
1.947 droeschl 5769:
5770: /* needed for iframe to allow 100% height in FF */
5771: body, html {
5772: margin: 0;
5773: padding: 0 0.5%;
5774: height: 99%; /* to avoid scrollbars */
5775: }
5776:
1.795 www 5777: body {
1.911 bisitz 5778: font-family: $sans;
5779: line-height:130%;
5780: font-size:0.83em;
5781: color:$font;
1.795 www 5782: }
5783:
1.959 onken 5784: a:focus,
5785: a:focus img {
1.795 www 5786: color: red;
5787: }
1.698 harmsja 5788:
1.911 bisitz 5789: form, .inline {
5790: display: inline;
1.795 www 5791: }
1.721 harmsja 5792:
1.795 www 5793: .LC_right {
1.911 bisitz 5794: text-align:right;
1.795 www 5795: }
5796:
5797: .LC_middle {
1.911 bisitz 5798: vertical-align:middle;
1.795 www 5799: }
1.721 harmsja 5800:
1.1130 raeburn 5801: .LC_floatleft {
5802: float: left;
5803: }
5804:
5805: .LC_floatright {
5806: float: right;
5807: }
5808:
1.911 bisitz 5809: .LC_400Box {
5810: width:400px;
5811: }
1.721 harmsja 5812:
1.947 droeschl 5813: .LC_iframecontainer {
5814: width: 98%;
5815: margin: 0;
5816: position: fixed;
5817: top: 8.5em;
5818: bottom: 0;
5819: }
5820:
5821: .LC_iframecontainer iframe{
5822: border: none;
5823: width: 100%;
5824: height: 100%;
5825: }
5826:
1.778 bisitz 5827: .LC_filename {
5828: font-family: $mono;
5829: white-space:pre;
1.921 bisitz 5830: font-size: 120%;
1.778 bisitz 5831: }
5832:
5833: .LC_fileicon {
5834: border: none;
5835: height: 1.3em;
5836: vertical-align: text-bottom;
5837: margin-right: 0.3em;
5838: text-decoration:none;
5839: }
5840:
1.1008 www 5841: .LC_setting {
5842: text-decoration:underline;
5843: }
5844:
1.350 albertel 5845: .LC_error {
5846: color: red;
5847: }
1.795 www 5848:
1.1097 bisitz 5849: .LC_warning {
5850: color: darkorange;
5851: }
5852:
1.457 albertel 5853: .LC_diff_removed {
1.733 bisitz 5854: color: red;
1.394 albertel 5855: }
1.532 albertel 5856:
5857: .LC_info,
1.457 albertel 5858: .LC_success,
5859: .LC_diff_added {
1.350 albertel 5860: color: green;
5861: }
1.795 www 5862:
1.802 bisitz 5863: div.LC_confirm_box {
5864: background-color: #FAFAFA;
5865: border: 1px solid $lg_border_color;
5866: margin-right: 0;
5867: padding: 5px;
5868: }
5869:
5870: div.LC_confirm_box .LC_error img,
5871: div.LC_confirm_box .LC_success img {
5872: vertical-align: middle;
5873: }
5874:
1.440 albertel 5875: .LC_icon {
1.771 droeschl 5876: border: none;
1.790 droeschl 5877: vertical-align: middle;
1.771 droeschl 5878: }
5879:
1.543 albertel 5880: .LC_docs_spacer {
5881: width: 25px;
5882: height: 1px;
1.771 droeschl 5883: border: none;
1.543 albertel 5884: }
1.346 albertel 5885:
1.532 albertel 5886: .LC_internal_info {
1.735 bisitz 5887: color: #999999;
1.532 albertel 5888: }
5889:
1.794 www 5890: .LC_discussion {
1.1050 www 5891: background: $data_table_dark;
1.911 bisitz 5892: border: 1px solid black;
5893: margin: 2px;
1.794 www 5894: }
5895:
5896: .LC_disc_action_left {
1.1050 www 5897: background: $sidebg;
1.911 bisitz 5898: text-align: left;
1.1050 www 5899: padding: 4px;
5900: margin: 2px;
1.794 www 5901: }
5902:
5903: .LC_disc_action_right {
1.1050 www 5904: background: $sidebg;
1.911 bisitz 5905: text-align: right;
1.1050 www 5906: padding: 4px;
5907: margin: 2px;
1.794 www 5908: }
5909:
5910: .LC_disc_new_item {
1.911 bisitz 5911: background: white;
5912: border: 2px solid red;
1.1050 www 5913: margin: 4px;
5914: padding: 4px;
1.794 www 5915: }
5916:
5917: .LC_disc_old_item {
1.911 bisitz 5918: background: white;
1.1050 www 5919: margin: 4px;
5920: padding: 4px;
1.794 www 5921: }
5922:
1.458 albertel 5923: table.LC_pastsubmission {
5924: border: 1px solid black;
5925: margin: 2px;
5926: }
5927:
1.924 bisitz 5928: table#LC_menubuttons {
1.345 albertel 5929: width: 100%;
5930: background: $pgbg;
1.392 albertel 5931: border: 2px;
1.402 albertel 5932: border-collapse: separate;
1.803 bisitz 5933: padding: 0;
1.345 albertel 5934: }
1.392 albertel 5935:
1.801 tempelho 5936: table#LC_title_bar a {
5937: color: $fontmenu;
5938: }
1.836 bisitz 5939:
1.807 droeschl 5940: table#LC_title_bar {
1.819 tempelho 5941: clear: both;
1.836 bisitz 5942: display: none;
1.807 droeschl 5943: }
5944:
1.795 www 5945: table#LC_title_bar,
1.933 droeschl 5946: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5947: table#LC_title_bar.LC_with_remote {
1.359 albertel 5948: width: 100%;
1.392 albertel 5949: border-color: $pgbg;
5950: border-style: solid;
5951: border-width: $border;
1.379 albertel 5952: background: $pgbg;
1.801 tempelho 5953: color: $fontmenu;
1.392 albertel 5954: border-collapse: collapse;
1.803 bisitz 5955: padding: 0;
1.819 tempelho 5956: margin: 0;
1.359 albertel 5957: }
1.795 www 5958:
1.933 droeschl 5959: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5960: margin: 0;
5961: padding: 0;
1.933 droeschl 5962: position: relative;
5963: list-style: none;
1.913 droeschl 5964: }
1.933 droeschl 5965: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5966: display: inline;
5967: }
1.933 droeschl 5968:
5969: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5970: padding: 0;
1.933 droeschl 5971: margin: 0;
5972: float: left;
1.913 droeschl 5973: }
1.933 droeschl 5974: .LC_breadcrumb_tools_tools {
5975: padding: 0;
5976: margin: 0;
1.913 droeschl 5977: float: right;
5978: }
5979:
1.359 albertel 5980: table#LC_title_bar td {
5981: background: $tabbg;
5982: }
1.795 www 5983:
1.911 bisitz 5984: table#LC_menubuttons img {
1.803 bisitz 5985: border: none;
1.346 albertel 5986: }
1.795 www 5987:
1.842 droeschl 5988: .LC_breadcrumbs_component {
1.911 bisitz 5989: float: right;
5990: margin: 0 1em;
1.357 albertel 5991: }
1.842 droeschl 5992: .LC_breadcrumbs_component img {
1.911 bisitz 5993: vertical-align: middle;
1.777 tempelho 5994: }
1.795 www 5995:
1.383 albertel 5996: td.LC_table_cell_checkbox {
5997: text-align: center;
5998: }
1.795 www 5999:
6000: .LC_fontsize_small {
1.911 bisitz 6001: font-size: 70%;
1.705 tempelho 6002: }
6003:
1.844 bisitz 6004: #LC_breadcrumbs {
1.911 bisitz 6005: clear:both;
6006: background: $sidebg;
6007: border-bottom: 1px solid $lg_border_color;
6008: line-height: 2.5em;
1.933 droeschl 6009: overflow: hidden;
1.911 bisitz 6010: margin: 0;
6011: padding: 0;
1.995 raeburn 6012: text-align: left;
1.819 tempelho 6013: }
1.862 bisitz 6014:
1.1098 bisitz 6015: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6016: clear:both;
6017: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6018: border: 1px solid $sidebg;
1.1098 bisitz 6019: margin: 0 0 10px 0;
1.966 bisitz 6020: padding: 3px;
1.995 raeburn 6021: text-align: left;
1.822 bisitz 6022: }
6023:
1.795 www 6024: .LC_fontsize_medium {
1.911 bisitz 6025: font-size: 85%;
1.705 tempelho 6026: }
6027:
1.795 www 6028: .LC_fontsize_large {
1.911 bisitz 6029: font-size: 120%;
1.705 tempelho 6030: }
6031:
1.346 albertel 6032: .LC_menubuttons_inline_text {
6033: color: $font;
1.698 harmsja 6034: font-size: 90%;
1.701 harmsja 6035: padding-left:3px;
1.346 albertel 6036: }
6037:
1.934 droeschl 6038: .LC_menubuttons_inline_text img{
6039: vertical-align: middle;
6040: }
6041:
1.1051 www 6042: li.LC_menubuttons_inline_text img {
1.951 onken 6043: cursor:pointer;
1.1002 droeschl 6044: text-decoration: none;
1.951 onken 6045: }
6046:
1.526 www 6047: .LC_menubuttons_link {
6048: text-decoration: none;
6049: }
1.795 www 6050:
1.522 albertel 6051: .LC_menubuttons_category {
1.521 www 6052: color: $font;
1.526 www 6053: background: $pgbg;
1.521 www 6054: font-size: larger;
6055: font-weight: bold;
6056: }
6057:
1.346 albertel 6058: td.LC_menubuttons_text {
1.911 bisitz 6059: color: $font;
1.346 albertel 6060: }
1.706 harmsja 6061:
1.346 albertel 6062: .LC_current_location {
6063: background: $tabbg;
6064: }
1.795 www 6065:
1.938 bisitz 6066: table.LC_data_table {
1.347 albertel 6067: border: 1px solid #000000;
1.402 albertel 6068: border-collapse: separate;
1.426 albertel 6069: border-spacing: 1px;
1.610 albertel 6070: background: $pgbg;
1.347 albertel 6071: }
1.795 www 6072:
1.422 albertel 6073: .LC_data_table_dense {
6074: font-size: small;
6075: }
1.795 www 6076:
1.507 raeburn 6077: table.LC_nested_outer {
6078: border: 1px solid #000000;
1.589 raeburn 6079: border-collapse: collapse;
1.803 bisitz 6080: border-spacing: 0;
1.507 raeburn 6081: width: 100%;
6082: }
1.795 www 6083:
1.879 raeburn 6084: table.LC_innerpickbox,
1.507 raeburn 6085: table.LC_nested {
1.803 bisitz 6086: border: none;
1.589 raeburn 6087: border-collapse: collapse;
1.803 bisitz 6088: border-spacing: 0;
1.507 raeburn 6089: width: 100%;
6090: }
1.795 www 6091:
1.911 bisitz 6092: table.LC_data_table tr th,
6093: table.LC_calendar tr th,
1.879 raeburn 6094: table.LC_prior_tries tr th,
6095: table.LC_innerpickbox tr th {
1.349 albertel 6096: font-weight: bold;
6097: background-color: $data_table_head;
1.801 tempelho 6098: color:$fontmenu;
1.701 harmsja 6099: font-size:90%;
1.347 albertel 6100: }
1.795 www 6101:
1.879 raeburn 6102: table.LC_innerpickbox tr th,
6103: table.LC_innerpickbox tr td {
6104: vertical-align: top;
6105: }
6106:
1.711 raeburn 6107: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6108: background-color: #CCCCCC;
1.711 raeburn 6109: font-weight: bold;
6110: text-align: left;
6111: }
1.795 www 6112:
1.912 bisitz 6113: table.LC_data_table tr.LC_odd_row > td {
6114: background-color: $data_table_light;
6115: padding: 2px;
6116: vertical-align: top;
6117: }
6118:
1.809 bisitz 6119: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6120: background-color: $data_table_light;
1.912 bisitz 6121: vertical-align: top;
6122: }
6123:
6124: table.LC_data_table tr.LC_even_row > td {
6125: background-color: $data_table_dark;
1.425 albertel 6126: padding: 2px;
1.900 bisitz 6127: vertical-align: top;
1.347 albertel 6128: }
1.795 www 6129:
1.809 bisitz 6130: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6131: background-color: $data_table_dark;
1.900 bisitz 6132: vertical-align: top;
1.347 albertel 6133: }
1.795 www 6134:
1.425 albertel 6135: table.LC_data_table tr.LC_data_table_highlight td {
6136: background-color: $data_table_darker;
6137: }
1.795 www 6138:
1.639 raeburn 6139: table.LC_data_table tr td.LC_leftcol_header {
6140: background-color: $data_table_head;
6141: font-weight: bold;
6142: }
1.795 www 6143:
1.451 albertel 6144: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6145: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6146: font-weight: bold;
6147: font-style: italic;
6148: text-align: center;
6149: padding: 8px;
1.347 albertel 6150: }
1.795 www 6151:
1.1114 raeburn 6152: table.LC_data_table tr.LC_empty_row td,
6153: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6154: background-color: $sidebg;
6155: }
6156:
6157: table.LC_nested tr.LC_empty_row td {
6158: background-color: #FFFFFF;
6159: }
6160:
1.890 droeschl 6161: table.LC_caption {
6162: }
6163:
1.507 raeburn 6164: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6165: padding: 4ex
6166: }
1.795 www 6167:
1.507 raeburn 6168: table.LC_nested_outer tr th {
6169: font-weight: bold;
1.801 tempelho 6170: color:$fontmenu;
1.507 raeburn 6171: background-color: $data_table_head;
1.701 harmsja 6172: font-size: small;
1.507 raeburn 6173: border-bottom: 1px solid #000000;
6174: }
1.795 www 6175:
1.507 raeburn 6176: table.LC_nested_outer tr td.LC_subheader {
6177: background-color: $data_table_head;
6178: font-weight: bold;
6179: font-size: small;
6180: border-bottom: 1px solid #000000;
6181: text-align: right;
1.451 albertel 6182: }
1.795 www 6183:
1.507 raeburn 6184: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6185: background-color: #CCCCCC;
1.451 albertel 6186: font-weight: bold;
6187: font-size: small;
1.507 raeburn 6188: text-align: center;
6189: }
1.795 www 6190:
1.589 raeburn 6191: table.LC_nested tr.LC_info_row td.LC_left_item,
6192: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6193: text-align: left;
1.451 albertel 6194: }
1.795 www 6195:
1.507 raeburn 6196: table.LC_nested td {
1.735 bisitz 6197: background-color: #FFFFFF;
1.451 albertel 6198: font-size: small;
1.507 raeburn 6199: }
1.795 www 6200:
1.507 raeburn 6201: table.LC_nested_outer tr th.LC_right_item,
6202: table.LC_nested tr.LC_info_row td.LC_right_item,
6203: table.LC_nested tr.LC_odd_row td.LC_right_item,
6204: table.LC_nested tr td.LC_right_item {
1.451 albertel 6205: text-align: right;
6206: }
6207:
1.507 raeburn 6208: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6209: background-color: #EEEEEE;
1.451 albertel 6210: }
6211:
1.473 raeburn 6212: table.LC_createuser {
6213: }
6214:
6215: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6216: font-size: small;
1.473 raeburn 6217: }
6218:
6219: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6220: background-color: #CCCCCC;
1.473 raeburn 6221: font-weight: bold;
6222: text-align: center;
6223: }
6224:
1.349 albertel 6225: table.LC_calendar {
6226: border: 1px solid #000000;
6227: border-collapse: collapse;
1.917 raeburn 6228: width: 98%;
1.349 albertel 6229: }
1.795 www 6230:
1.349 albertel 6231: table.LC_calendar_pickdate {
6232: font-size: xx-small;
6233: }
1.795 www 6234:
1.349 albertel 6235: table.LC_calendar tr td {
6236: border: 1px solid #000000;
6237: vertical-align: top;
1.917 raeburn 6238: width: 14%;
1.349 albertel 6239: }
1.795 www 6240:
1.349 albertel 6241: table.LC_calendar tr td.LC_calendar_day_empty {
6242: background-color: $data_table_dark;
6243: }
1.795 www 6244:
1.779 bisitz 6245: table.LC_calendar tr td.LC_calendar_day_current {
6246: background-color: $data_table_highlight;
1.777 tempelho 6247: }
1.795 www 6248:
1.938 bisitz 6249: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6250: background-color: $mail_new;
6251: }
1.795 www 6252:
1.938 bisitz 6253: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6254: background-color: $mail_new_hover;
6255: }
1.795 www 6256:
1.938 bisitz 6257: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6258: background-color: $mail_read;
6259: }
1.795 www 6260:
1.938 bisitz 6261: /*
6262: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6263: background-color: $mail_read_hover;
6264: }
1.938 bisitz 6265: */
1.795 www 6266:
1.938 bisitz 6267: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6268: background-color: $mail_replied;
6269: }
1.795 www 6270:
1.938 bisitz 6271: /*
6272: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6273: background-color: $mail_replied_hover;
6274: }
1.938 bisitz 6275: */
1.795 www 6276:
1.938 bisitz 6277: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6278: background-color: $mail_other;
6279: }
1.795 www 6280:
1.938 bisitz 6281: /*
6282: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6283: background-color: $mail_other_hover;
6284: }
1.938 bisitz 6285: */
1.494 raeburn 6286:
1.777 tempelho 6287: table.LC_data_table tr > td.LC_browser_file,
6288: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6289: background: #AAEE77;
1.389 albertel 6290: }
1.795 www 6291:
1.777 tempelho 6292: table.LC_data_table tr > td.LC_browser_file_locked,
6293: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6294: background: #FFAA99;
1.387 albertel 6295: }
1.795 www 6296:
1.777 tempelho 6297: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6298: background: #888888;
1.779 bisitz 6299: }
1.795 www 6300:
1.777 tempelho 6301: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6302: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6303: background: #F8F866;
1.777 tempelho 6304: }
1.795 www 6305:
1.696 bisitz 6306: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6307: background: #E0E8FF;
1.387 albertel 6308: }
1.696 bisitz 6309:
1.707 bisitz 6310: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6311: /* background: #77FF77; */
1.707 bisitz 6312: }
1.795 www 6313:
1.707 bisitz 6314: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6315: border-right: 8px solid #FFFF77;
1.707 bisitz 6316: }
1.795 www 6317:
1.707 bisitz 6318: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6319: border-right: 8px solid #FFAA77;
1.707 bisitz 6320: }
1.795 www 6321:
1.707 bisitz 6322: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6323: border-right: 8px solid #FF7777;
1.707 bisitz 6324: }
1.795 www 6325:
1.707 bisitz 6326: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6327: border-right: 8px solid #AAFF77;
1.707 bisitz 6328: }
1.795 www 6329:
1.707 bisitz 6330: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6331: border-right: 8px solid #11CC55;
1.707 bisitz 6332: }
6333:
1.388 albertel 6334: span.LC_current_location {
1.701 harmsja 6335: font-size:larger;
1.388 albertel 6336: background: $pgbg;
6337: }
1.387 albertel 6338:
1.1029 www 6339: span.LC_current_nav_location {
6340: font-weight:bold;
6341: background: $sidebg;
6342: }
6343:
1.395 albertel 6344: span.LC_parm_menu_item {
6345: font-size: larger;
6346: }
1.795 www 6347:
1.395 albertel 6348: span.LC_parm_scope_all {
6349: color: red;
6350: }
1.795 www 6351:
1.395 albertel 6352: span.LC_parm_scope_folder {
6353: color: green;
6354: }
1.795 www 6355:
1.395 albertel 6356: span.LC_parm_scope_resource {
6357: color: orange;
6358: }
1.795 www 6359:
1.395 albertel 6360: span.LC_parm_part {
6361: color: blue;
6362: }
1.795 www 6363:
1.911 bisitz 6364: span.LC_parm_folder,
6365: span.LC_parm_symb {
1.395 albertel 6366: font-size: x-small;
6367: font-family: $mono;
6368: color: #AAAAAA;
6369: }
6370:
1.977 bisitz 6371: ul.LC_parm_parmlist li {
6372: display: inline-block;
6373: padding: 0.3em 0.8em;
6374: vertical-align: top;
6375: width: 150px;
6376: border-top:1px solid $lg_border_color;
6377: }
6378:
1.795 www 6379: td.LC_parm_overview_level_menu,
6380: td.LC_parm_overview_map_menu,
6381: td.LC_parm_overview_parm_selectors,
6382: td.LC_parm_overview_restrictions {
1.396 albertel 6383: border: 1px solid black;
6384: border-collapse: collapse;
6385: }
1.795 www 6386:
1.396 albertel 6387: table.LC_parm_overview_restrictions td {
6388: border-width: 1px 4px 1px 4px;
6389: border-style: solid;
6390: border-color: $pgbg;
6391: text-align: center;
6392: }
1.795 www 6393:
1.396 albertel 6394: table.LC_parm_overview_restrictions th {
6395: background: $tabbg;
6396: border-width: 1px 4px 1px 4px;
6397: border-style: solid;
6398: border-color: $pgbg;
6399: }
1.795 www 6400:
1.398 albertel 6401: table#LC_helpmenu {
1.803 bisitz 6402: border: none;
1.398 albertel 6403: height: 55px;
1.803 bisitz 6404: border-spacing: 0;
1.398 albertel 6405: }
6406:
6407: table#LC_helpmenu fieldset legend {
6408: font-size: larger;
6409: }
1.795 www 6410:
1.397 albertel 6411: table#LC_helpmenu_links {
6412: width: 100%;
6413: border: 1px solid black;
6414: background: $pgbg;
1.803 bisitz 6415: padding: 0;
1.397 albertel 6416: border-spacing: 1px;
6417: }
1.795 www 6418:
1.397 albertel 6419: table#LC_helpmenu_links tr td {
6420: padding: 1px;
6421: background: $tabbg;
1.399 albertel 6422: text-align: center;
6423: font-weight: bold;
1.397 albertel 6424: }
1.396 albertel 6425:
1.795 www 6426: table#LC_helpmenu_links a:link,
6427: table#LC_helpmenu_links a:visited,
1.397 albertel 6428: table#LC_helpmenu_links a:active {
6429: text-decoration: none;
6430: color: $font;
6431: }
1.795 www 6432:
1.397 albertel 6433: table#LC_helpmenu_links a:hover {
6434: text-decoration: underline;
6435: color: $vlink;
6436: }
1.396 albertel 6437:
1.417 albertel 6438: .LC_chrt_popup_exists {
6439: border: 1px solid #339933;
6440: margin: -1px;
6441: }
1.795 www 6442:
1.417 albertel 6443: .LC_chrt_popup_up {
6444: border: 1px solid yellow;
6445: margin: -1px;
6446: }
1.795 www 6447:
1.417 albertel 6448: .LC_chrt_popup {
6449: border: 1px solid #8888FF;
6450: background: #CCCCFF;
6451: }
1.795 www 6452:
1.421 albertel 6453: table.LC_pick_box {
6454: border-collapse: separate;
6455: background: white;
6456: border: 1px solid black;
6457: border-spacing: 1px;
6458: }
1.795 www 6459:
1.421 albertel 6460: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6461: background: $sidebg;
1.421 albertel 6462: font-weight: bold;
1.900 bisitz 6463: text-align: left;
1.740 bisitz 6464: vertical-align: top;
1.421 albertel 6465: width: 184px;
6466: padding: 8px;
6467: }
1.795 www 6468:
1.579 raeburn 6469: table.LC_pick_box td.LC_pick_box_value {
6470: text-align: left;
6471: padding: 8px;
6472: }
1.795 www 6473:
1.579 raeburn 6474: table.LC_pick_box td.LC_pick_box_select {
6475: text-align: left;
6476: padding: 8px;
6477: }
1.795 www 6478:
1.424 albertel 6479: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6480: padding: 0;
1.421 albertel 6481: height: 1px;
6482: background: black;
6483: }
1.795 www 6484:
1.421 albertel 6485: table.LC_pick_box td.LC_pick_box_submit {
6486: text-align: right;
6487: }
1.795 www 6488:
1.579 raeburn 6489: table.LC_pick_box td.LC_evenrow_value {
6490: text-align: left;
6491: padding: 8px;
6492: background-color: $data_table_light;
6493: }
1.795 www 6494:
1.579 raeburn 6495: table.LC_pick_box td.LC_oddrow_value {
6496: text-align: left;
6497: padding: 8px;
6498: background-color: $data_table_light;
6499: }
1.795 www 6500:
1.579 raeburn 6501: span.LC_helpform_receipt_cat {
6502: font-weight: bold;
6503: }
1.795 www 6504:
1.424 albertel 6505: table.LC_group_priv_box {
6506: background: white;
6507: border: 1px solid black;
6508: border-spacing: 1px;
6509: }
1.795 www 6510:
1.424 albertel 6511: table.LC_group_priv_box td.LC_pick_box_title {
6512: background: $tabbg;
6513: font-weight: bold;
6514: text-align: right;
6515: width: 184px;
6516: }
1.795 www 6517:
1.424 albertel 6518: table.LC_group_priv_box td.LC_groups_fixed {
6519: background: $data_table_light;
6520: text-align: center;
6521: }
1.795 www 6522:
1.424 albertel 6523: table.LC_group_priv_box td.LC_groups_optional {
6524: background: $data_table_dark;
6525: text-align: center;
6526: }
1.795 www 6527:
1.424 albertel 6528: table.LC_group_priv_box td.LC_groups_functionality {
6529: background: $data_table_darker;
6530: text-align: center;
6531: font-weight: bold;
6532: }
1.795 www 6533:
1.424 albertel 6534: table.LC_group_priv td {
6535: text-align: left;
1.803 bisitz 6536: padding: 0;
1.424 albertel 6537: }
6538:
6539: .LC_navbuttons {
6540: margin: 2ex 0ex 2ex 0ex;
6541: }
1.795 www 6542:
1.423 albertel 6543: .LC_topic_bar {
6544: font-weight: bold;
6545: background: $tabbg;
1.918 wenzelju 6546: margin: 1em 0em 1em 2em;
1.805 bisitz 6547: padding: 3px;
1.918 wenzelju 6548: font-size: 1.2em;
1.423 albertel 6549: }
1.795 www 6550:
1.423 albertel 6551: .LC_topic_bar span {
1.918 wenzelju 6552: left: 0.5em;
6553: position: absolute;
1.423 albertel 6554: vertical-align: middle;
1.918 wenzelju 6555: font-size: 1.2em;
1.423 albertel 6556: }
1.795 www 6557:
1.423 albertel 6558: table.LC_course_group_status {
6559: margin: 20px;
6560: }
1.795 www 6561:
1.423 albertel 6562: table.LC_status_selector td {
6563: vertical-align: top;
6564: text-align: center;
1.424 albertel 6565: padding: 4px;
6566: }
1.795 www 6567:
1.599 albertel 6568: div.LC_feedback_link {
1.616 albertel 6569: clear: both;
1.829 kalberla 6570: background: $sidebg;
1.779 bisitz 6571: width: 100%;
1.829 kalberla 6572: padding-bottom: 10px;
6573: border: 1px $tabbg solid;
1.833 kalberla 6574: height: 22px;
6575: line-height: 22px;
6576: padding-top: 5px;
6577: }
6578:
6579: div.LC_feedback_link img {
6580: height: 22px;
1.867 kalberla 6581: vertical-align:middle;
1.829 kalberla 6582: }
6583:
1.911 bisitz 6584: div.LC_feedback_link a {
1.829 kalberla 6585: text-decoration: none;
1.489 raeburn 6586: }
1.795 www 6587:
1.867 kalberla 6588: div.LC_comblock {
1.911 bisitz 6589: display:inline;
1.867 kalberla 6590: color:$font;
6591: font-size:90%;
6592: }
6593:
6594: div.LC_feedback_link div.LC_comblock {
6595: padding-left:5px;
6596: }
6597:
6598: div.LC_feedback_link div.LC_comblock a {
6599: color:$font;
6600: }
6601:
1.489 raeburn 6602: span.LC_feedback_link {
1.858 bisitz 6603: /* background: $feedback_link_bg; */
1.599 albertel 6604: font-size: larger;
6605: }
1.795 www 6606:
1.599 albertel 6607: span.LC_message_link {
1.858 bisitz 6608: /* background: $feedback_link_bg; */
1.599 albertel 6609: font-size: larger;
6610: position: absolute;
6611: right: 1em;
1.489 raeburn 6612: }
1.421 albertel 6613:
1.515 albertel 6614: table.LC_prior_tries {
1.524 albertel 6615: border: 1px solid #000000;
6616: border-collapse: separate;
6617: border-spacing: 1px;
1.515 albertel 6618: }
1.523 albertel 6619:
1.515 albertel 6620: table.LC_prior_tries td {
1.524 albertel 6621: padding: 2px;
1.515 albertel 6622: }
1.523 albertel 6623:
6624: .LC_answer_correct {
1.795 www 6625: background: lightgreen;
6626: color: darkgreen;
6627: padding: 6px;
1.523 albertel 6628: }
1.795 www 6629:
1.523 albertel 6630: .LC_answer_charged_try {
1.797 www 6631: background: #FFAAAA;
1.795 www 6632: color: darkred;
6633: padding: 6px;
1.523 albertel 6634: }
1.795 www 6635:
1.779 bisitz 6636: .LC_answer_not_charged_try,
1.523 albertel 6637: .LC_answer_no_grade,
6638: .LC_answer_late {
1.795 www 6639: background: lightyellow;
1.523 albertel 6640: color: black;
1.795 www 6641: padding: 6px;
1.523 albertel 6642: }
1.795 www 6643:
1.523 albertel 6644: .LC_answer_previous {
1.795 www 6645: background: lightblue;
6646: color: darkblue;
6647: padding: 6px;
1.523 albertel 6648: }
1.795 www 6649:
1.779 bisitz 6650: .LC_answer_no_message {
1.777 tempelho 6651: background: #FFFFFF;
6652: color: black;
1.795 www 6653: padding: 6px;
1.779 bisitz 6654: }
1.795 www 6655:
1.779 bisitz 6656: .LC_answer_unknown {
6657: background: orange;
6658: color: black;
1.795 www 6659: padding: 6px;
1.777 tempelho 6660: }
1.795 www 6661:
1.529 albertel 6662: span.LC_prior_numerical,
6663: span.LC_prior_string,
6664: span.LC_prior_custom,
6665: span.LC_prior_reaction,
6666: span.LC_prior_math {
1.925 bisitz 6667: font-family: $mono;
1.523 albertel 6668: white-space: pre;
6669: }
6670:
1.525 albertel 6671: span.LC_prior_string {
1.925 bisitz 6672: font-family: $mono;
1.525 albertel 6673: white-space: pre;
6674: }
6675:
1.523 albertel 6676: table.LC_prior_option {
6677: width: 100%;
6678: border-collapse: collapse;
6679: }
1.795 www 6680:
1.911 bisitz 6681: table.LC_prior_rank,
1.795 www 6682: table.LC_prior_match {
1.528 albertel 6683: border-collapse: collapse;
6684: }
1.795 www 6685:
1.528 albertel 6686: table.LC_prior_option tr td,
6687: table.LC_prior_rank tr td,
6688: table.LC_prior_match tr td {
1.524 albertel 6689: border: 1px solid #000000;
1.515 albertel 6690: }
6691:
1.855 bisitz 6692: .LC_nobreak {
1.544 albertel 6693: white-space: nowrap;
1.519 raeburn 6694: }
6695:
1.576 raeburn 6696: span.LC_cusr_emph {
6697: font-style: italic;
6698: }
6699:
1.633 raeburn 6700: span.LC_cusr_subheading {
6701: font-weight: normal;
6702: font-size: 85%;
6703: }
6704:
1.861 bisitz 6705: div.LC_docs_entry_move {
1.859 bisitz 6706: border: 1px solid #BBBBBB;
1.545 albertel 6707: background: #DDDDDD;
1.861 bisitz 6708: width: 22px;
1.859 bisitz 6709: padding: 1px;
6710: margin: 0;
1.545 albertel 6711: }
6712:
1.861 bisitz 6713: table.LC_data_table tr > td.LC_docs_entry_commands,
6714: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6715: font-size: x-small;
6716: }
1.795 www 6717:
1.861 bisitz 6718: .LC_docs_entry_parameter {
6719: white-space: nowrap;
6720: }
6721:
1.544 albertel 6722: .LC_docs_copy {
1.545 albertel 6723: color: #000099;
1.544 albertel 6724: }
1.795 www 6725:
1.544 albertel 6726: .LC_docs_cut {
1.545 albertel 6727: color: #550044;
1.544 albertel 6728: }
1.795 www 6729:
1.544 albertel 6730: .LC_docs_rename {
1.545 albertel 6731: color: #009900;
1.544 albertel 6732: }
1.795 www 6733:
1.544 albertel 6734: .LC_docs_remove {
1.545 albertel 6735: color: #990000;
6736: }
6737:
1.547 albertel 6738: .LC_docs_reinit_warn,
6739: .LC_docs_ext_edit {
6740: font-size: x-small;
6741: }
6742:
1.545 albertel 6743: table.LC_docs_adddocs td,
6744: table.LC_docs_adddocs th {
6745: border: 1px solid #BBBBBB;
6746: padding: 4px;
6747: background: #DDDDDD;
1.543 albertel 6748: }
6749:
1.584 albertel 6750: table.LC_sty_begin {
6751: background: #BBFFBB;
6752: }
1.795 www 6753:
1.584 albertel 6754: table.LC_sty_end {
6755: background: #FFBBBB;
6756: }
6757:
1.589 raeburn 6758: table.LC_double_column {
1.803 bisitz 6759: border-width: 0;
1.589 raeburn 6760: border-collapse: collapse;
6761: width: 100%;
6762: padding: 2px;
6763: }
6764:
6765: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6766: top: 2px;
1.589 raeburn 6767: left: 2px;
6768: width: 47%;
6769: vertical-align: top;
6770: }
6771:
6772: table.LC_double_column tr td.LC_right_col {
6773: top: 2px;
1.779 bisitz 6774: right: 2px;
1.589 raeburn 6775: width: 47%;
6776: vertical-align: top;
6777: }
6778:
1.591 raeburn 6779: div.LC_left_float {
6780: float: left;
6781: padding-right: 5%;
1.597 albertel 6782: padding-bottom: 4px;
1.591 raeburn 6783: }
6784:
6785: div.LC_clear_float_header {
1.597 albertel 6786: padding-bottom: 2px;
1.591 raeburn 6787: }
6788:
6789: div.LC_clear_float_footer {
1.597 albertel 6790: padding-top: 10px;
1.591 raeburn 6791: clear: both;
6792: }
6793:
1.597 albertel 6794: div.LC_grade_show_user {
1.941 bisitz 6795: /* border-left: 5px solid $sidebg; */
6796: border-top: 5px solid #000000;
6797: margin: 50px 0 0 0;
1.936 bisitz 6798: padding: 15px 0 5px 10px;
1.597 albertel 6799: }
1.795 www 6800:
1.936 bisitz 6801: div.LC_grade_show_user_odd_row {
1.941 bisitz 6802: /* border-left: 5px solid #000000; */
6803: }
6804:
6805: div.LC_grade_show_user div.LC_Box {
6806: margin-right: 50px;
1.597 albertel 6807: }
6808:
6809: div.LC_grade_submissions,
6810: div.LC_grade_message_center,
1.936 bisitz 6811: div.LC_grade_info_links {
1.597 albertel 6812: margin: 5px;
6813: width: 99%;
6814: background: #FFFFFF;
6815: }
1.795 www 6816:
1.597 albertel 6817: div.LC_grade_submissions_header,
1.936 bisitz 6818: div.LC_grade_message_center_header {
1.705 tempelho 6819: font-weight: bold;
6820: font-size: large;
1.597 albertel 6821: }
1.795 www 6822:
1.597 albertel 6823: div.LC_grade_submissions_body,
1.936 bisitz 6824: div.LC_grade_message_center_body {
1.597 albertel 6825: border: 1px solid black;
6826: width: 99%;
6827: background: #FFFFFF;
6828: }
1.795 www 6829:
1.613 albertel 6830: table.LC_scantron_action {
6831: width: 100%;
6832: }
1.795 www 6833:
1.613 albertel 6834: table.LC_scantron_action tr th {
1.698 harmsja 6835: font-weight:bold;
6836: font-style:normal;
1.613 albertel 6837: }
1.795 www 6838:
1.779 bisitz 6839: .LC_edit_problem_header,
1.614 albertel 6840: div.LC_edit_problem_footer {
1.705 tempelho 6841: font-weight: normal;
6842: font-size: medium;
1.602 albertel 6843: margin: 2px;
1.1060 bisitz 6844: background-color: $sidebg;
1.600 albertel 6845: }
1.795 www 6846:
1.600 albertel 6847: div.LC_edit_problem_header,
1.602 albertel 6848: div.LC_edit_problem_header div,
1.614 albertel 6849: div.LC_edit_problem_footer,
6850: div.LC_edit_problem_footer div,
1.602 albertel 6851: div.LC_edit_problem_editxml_header,
6852: div.LC_edit_problem_editxml_header div {
1.1205 golterma 6853: z-index: 100;
1.600 albertel 6854: }
1.795 www 6855:
1.600 albertel 6856: div.LC_edit_problem_header_title {
1.705 tempelho 6857: font-weight: bold;
6858: font-size: larger;
1.602 albertel 6859: background: $tabbg;
6860: padding: 3px;
1.1060 bisitz 6861: margin: 0 0 5px 0;
1.602 albertel 6862: }
1.795 www 6863:
1.602 albertel 6864: table.LC_edit_problem_header_title {
6865: width: 100%;
1.600 albertel 6866: background: $tabbg;
1.602 albertel 6867: }
6868:
1.1205 golterma 6869: div.LC_edit_actionbar {
6870: background-color: $sidebg;
1.1218 droeschl 6871: margin: 0;
6872: padding: 0;
6873: line-height: 200%;
1.602 albertel 6874: }
1.795 www 6875:
1.1218 droeschl 6876: div.LC_edit_actionbar div{
6877: padding: 0;
6878: margin: 0;
6879: display: inline-block;
1.600 albertel 6880: }
1.795 www 6881:
1.1124 bisitz 6882: .LC_edit_opt {
6883: padding-left: 1em;
6884: white-space: nowrap;
6885: }
6886:
1.1152 golterma 6887: .LC_edit_problem_latexhelper{
6888: text-align: right;
6889: }
6890:
6891: #LC_edit_problem_colorful div{
6892: margin-left: 40px;
6893: }
6894:
1.1205 golterma 6895: #LC_edit_problem_codemirror div{
6896: margin-left: 0px;
6897: }
6898:
1.911 bisitz 6899: img.stift {
1.803 bisitz 6900: border-width: 0;
6901: vertical-align: middle;
1.677 riegler 6902: }
1.680 riegler 6903:
1.923 bisitz 6904: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6905: vertical-align: top;
1.777 tempelho 6906: }
1.795 www 6907:
1.716 raeburn 6908: div.LC_createcourse {
1.911 bisitz 6909: margin: 10px 10px 10px 10px;
1.716 raeburn 6910: }
6911:
1.917 raeburn 6912: .LC_dccid {
1.1130 raeburn 6913: float: right;
1.917 raeburn 6914: margin: 0.2em 0 0 0;
6915: padding: 0;
6916: font-size: 90%;
6917: display:none;
6918: }
6919:
1.897 wenzelju 6920: ol.LC_primary_menu a:hover,
1.721 harmsja 6921: ol#LC_MenuBreadcrumbs a:hover,
6922: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6923: ul#LC_secondary_menu a:hover,
1.721 harmsja 6924: .LC_FormSectionClearButton input:hover
1.795 www 6925: ul.LC_TabContent li:hover a {
1.952 onken 6926: color:$button_hover;
1.911 bisitz 6927: text-decoration:none;
1.693 droeschl 6928: }
6929:
1.779 bisitz 6930: h1 {
1.911 bisitz 6931: padding: 0;
6932: line-height:130%;
1.693 droeschl 6933: }
1.698 harmsja 6934:
1.911 bisitz 6935: h2,
6936: h3,
6937: h4,
6938: h5,
6939: h6 {
6940: margin: 5px 0 5px 0;
6941: padding: 0;
6942: line-height:130%;
1.693 droeschl 6943: }
1.795 www 6944:
6945: .LC_hcell {
1.911 bisitz 6946: padding:3px 15px 3px 15px;
6947: margin: 0;
6948: background-color:$tabbg;
6949: color:$fontmenu;
6950: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6951: }
1.795 www 6952:
1.840 bisitz 6953: .LC_Box > .LC_hcell {
1.911 bisitz 6954: margin: 0 -10px 10px -10px;
1.835 bisitz 6955: }
6956:
1.721 harmsja 6957: .LC_noBorder {
1.911 bisitz 6958: border: 0;
1.698 harmsja 6959: }
1.693 droeschl 6960:
1.721 harmsja 6961: .LC_FormSectionClearButton input {
1.911 bisitz 6962: background-color:transparent;
6963: border: none;
6964: cursor:pointer;
6965: text-decoration:underline;
1.693 droeschl 6966: }
1.763 bisitz 6967:
6968: .LC_help_open_topic {
1.911 bisitz 6969: color: #FFFFFF;
6970: background-color: #EEEEFF;
6971: margin: 1px;
6972: padding: 4px;
6973: border: 1px solid #000033;
6974: white-space: nowrap;
6975: /* vertical-align: middle; */
1.759 neumanie 6976: }
1.693 droeschl 6977:
1.911 bisitz 6978: dl,
6979: ul,
6980: div,
6981: fieldset {
6982: margin: 10px 10px 10px 0;
6983: /* overflow: hidden; */
1.693 droeschl 6984: }
1.795 www 6985:
1.1211 raeburn 6986: article.geogebraweb div {
6987: margin: 0;
6988: }
6989:
1.838 bisitz 6990: fieldset > legend {
1.911 bisitz 6991: font-weight: bold;
6992: padding: 0 5px 0 5px;
1.838 bisitz 6993: }
6994:
1.813 bisitz 6995: #LC_nav_bar {
1.911 bisitz 6996: float: left;
1.995 raeburn 6997: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6998: margin: 0 0 2px 0;
1.807 droeschl 6999: }
7000:
1.916 droeschl 7001: #LC_realm {
7002: margin: 0.2em 0 0 0;
7003: padding: 0;
7004: font-weight: bold;
7005: text-align: center;
1.995 raeburn 7006: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7007: }
7008:
1.911 bisitz 7009: #LC_nav_bar em {
7010: font-weight: bold;
7011: font-style: normal;
1.807 droeschl 7012: }
7013:
1.897 wenzelju 7014: ol.LC_primary_menu {
1.934 droeschl 7015: margin: 0;
1.1076 raeburn 7016: padding: 0;
1.807 droeschl 7017: }
7018:
1.852 droeschl 7019: ol#LC_PathBreadcrumbs {
1.911 bisitz 7020: margin: 0;
1.693 droeschl 7021: }
7022:
1.897 wenzelju 7023: ol.LC_primary_menu li {
1.1076 raeburn 7024: color: RGB(80, 80, 80);
7025: vertical-align: middle;
7026: text-align: left;
7027: list-style: none;
1.1205 golterma 7028: position: relative;
1.1076 raeburn 7029: float: left;
1.1205 golterma 7030: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7031: line-height: 1.5em;
1.1076 raeburn 7032: }
7033:
1.1205 golterma 7034: ol.LC_primary_menu li a,
7035: ol.LC_primary_menu li p {
1.1076 raeburn 7036: display: block;
7037: margin: 0;
7038: padding: 0 5px 0 10px;
7039: text-decoration: none;
7040: }
7041:
1.1205 golterma 7042: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7043: display: inline-block;
7044: width: 95%;
7045: text-align: left;
7046: }
7047:
7048: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7049: display: inline-block;
7050: width: 5%;
7051: float: right;
7052: text-align: right;
7053: font-size: 70%;
7054: }
7055:
7056: ol.LC_primary_menu ul {
1.1076 raeburn 7057: display: none;
1.1205 golterma 7058: width: 15em;
1.1076 raeburn 7059: background-color: $data_table_light;
1.1205 golterma 7060: position: absolute;
7061: top: 100%;
1.1076 raeburn 7062: }
7063:
1.1205 golterma 7064: ol.LC_primary_menu ul ul {
7065: left: 100%;
7066: top: 0;
7067: }
7068:
7069: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7070: display: block;
7071: position: absolute;
7072: margin: 0;
7073: padding: 0;
1.1078 raeburn 7074: z-index: 2;
1.1076 raeburn 7075: }
7076:
7077: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7078: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7079: font-size: 90%;
1.911 bisitz 7080: vertical-align: top;
1.1076 raeburn 7081: float: none;
1.1079 raeburn 7082: border-left: 1px solid black;
7083: border-right: 1px solid black;
1.1205 golterma 7084: /* A dark bottom border to visualize different menu options;
7085: overwritten in the create_submenu routine for the last border-bottom of the menu */
7086: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7087: }
7088:
1.1205 golterma 7089: ol.LC_primary_menu li li p:hover {
7090: color:$button_hover;
7091: text-decoration:none;
7092: background-color:$data_table_dark;
1.1076 raeburn 7093: }
7094:
7095: ol.LC_primary_menu li li a:hover {
7096: color:$button_hover;
7097: background-color:$data_table_dark;
1.693 droeschl 7098: }
7099:
1.1205 golterma 7100: /* Font-size equal to the size of the predecessors*/
7101: ol.LC_primary_menu li:hover li li {
7102: font-size: 100%;
7103: }
7104:
1.897 wenzelju 7105: ol.LC_primary_menu li img {
1.911 bisitz 7106: vertical-align: bottom;
1.934 droeschl 7107: height: 1.1em;
1.1077 raeburn 7108: margin: 0.2em 0 0 0;
1.693 droeschl 7109: }
7110:
1.897 wenzelju 7111: ol.LC_primary_menu a {
1.911 bisitz 7112: color: RGB(80, 80, 80);
7113: text-decoration: none;
1.693 droeschl 7114: }
1.795 www 7115:
1.949 droeschl 7116: ol.LC_primary_menu a.LC_new_message {
7117: font-weight:bold;
7118: color: darkred;
7119: }
7120:
1.975 raeburn 7121: ol.LC_docs_parameters {
7122: margin-left: 0;
7123: padding: 0;
7124: list-style: none;
7125: }
7126:
7127: ol.LC_docs_parameters li {
7128: margin: 0;
7129: padding-right: 20px;
7130: display: inline;
7131: }
7132:
1.976 raeburn 7133: ol.LC_docs_parameters li:before {
7134: content: "\\002022 \\0020";
7135: }
7136:
7137: li.LC_docs_parameters_title {
7138: font-weight: bold;
7139: }
7140:
7141: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7142: content: "";
7143: }
7144:
1.897 wenzelju 7145: ul#LC_secondary_menu {
1.1107 raeburn 7146: clear: right;
1.911 bisitz 7147: color: $fontmenu;
7148: background: $tabbg;
7149: list-style: none;
7150: padding: 0;
7151: margin: 0;
7152: width: 100%;
1.995 raeburn 7153: text-align: left;
1.1107 raeburn 7154: float: left;
1.808 droeschl 7155: }
7156:
1.897 wenzelju 7157: ul#LC_secondary_menu li {
1.911 bisitz 7158: font-weight: bold;
7159: line-height: 1.8em;
1.1107 raeburn 7160: border-right: 1px solid black;
7161: float: left;
7162: }
7163:
7164: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7165: background-color: $data_table_light;
7166: }
7167:
7168: ul#LC_secondary_menu li a {
1.911 bisitz 7169: padding: 0 0.8em;
1.1107 raeburn 7170: }
7171:
7172: ul#LC_secondary_menu li ul {
7173: display: none;
7174: }
7175:
7176: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7177: display: block;
7178: position: absolute;
7179: margin: 0;
7180: padding: 0;
7181: list-style:none;
7182: float: none;
7183: background-color: $data_table_light;
7184: z-index: 2;
7185: margin-left: -1px;
7186: }
7187:
7188: ul#LC_secondary_menu li ul li {
7189: font-size: 90%;
7190: vertical-align: top;
7191: border-left: 1px solid black;
1.911 bisitz 7192: border-right: 1px solid black;
1.1119 raeburn 7193: background-color: $data_table_light;
1.1107 raeburn 7194: list-style:none;
7195: float: none;
7196: }
7197:
7198: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7199: background-color: $data_table_dark;
1.807 droeschl 7200: }
7201:
1.847 tempelho 7202: ul.LC_TabContent {
1.911 bisitz 7203: display:block;
7204: background: $sidebg;
7205: border-bottom: solid 1px $lg_border_color;
7206: list-style:none;
1.1020 raeburn 7207: margin: -1px -10px 0 -10px;
1.911 bisitz 7208: padding: 0;
1.693 droeschl 7209: }
7210:
1.795 www 7211: ul.LC_TabContent li,
7212: ul.LC_TabContentBigger li {
1.911 bisitz 7213: float:left;
1.741 harmsja 7214: }
1.795 www 7215:
1.897 wenzelju 7216: ul#LC_secondary_menu li a {
1.911 bisitz 7217: color: $fontmenu;
7218: text-decoration: none;
1.693 droeschl 7219: }
1.795 www 7220:
1.721 harmsja 7221: ul.LC_TabContent {
1.952 onken 7222: min-height:20px;
1.721 harmsja 7223: }
1.795 www 7224:
7225: ul.LC_TabContent li {
1.911 bisitz 7226: vertical-align:middle;
1.959 onken 7227: padding: 0 16px 0 10px;
1.911 bisitz 7228: background-color:$tabbg;
7229: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7230: border-left: solid 1px $font;
1.721 harmsja 7231: }
1.795 www 7232:
1.847 tempelho 7233: ul.LC_TabContent .right {
1.911 bisitz 7234: float:right;
1.847 tempelho 7235: }
7236:
1.911 bisitz 7237: ul.LC_TabContent li a,
7238: ul.LC_TabContent li {
7239: color:rgb(47,47,47);
7240: text-decoration:none;
7241: font-size:95%;
7242: font-weight:bold;
1.952 onken 7243: min-height:20px;
7244: }
7245:
1.959 onken 7246: ul.LC_TabContent li a:hover,
7247: ul.LC_TabContent li a:focus {
1.952 onken 7248: color: $button_hover;
1.959 onken 7249: background:none;
7250: outline:none;
1.952 onken 7251: }
7252:
7253: ul.LC_TabContent li:hover {
7254: color: $button_hover;
7255: cursor:pointer;
1.721 harmsja 7256: }
1.795 www 7257:
1.911 bisitz 7258: ul.LC_TabContent li.active {
1.952 onken 7259: color: $font;
1.911 bisitz 7260: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7261: border-bottom:solid 1px #FFFFFF;
7262: cursor: default;
1.744 ehlerst 7263: }
1.795 www 7264:
1.959 onken 7265: ul.LC_TabContent li.active a {
7266: color:$font;
7267: background:#FFFFFF;
7268: outline: none;
7269: }
1.1047 raeburn 7270:
7271: ul.LC_TabContent li.goback {
7272: float: left;
7273: border-left: none;
7274: }
7275:
1.870 tempelho 7276: #maincoursedoc {
1.911 bisitz 7277: clear:both;
1.870 tempelho 7278: }
7279:
7280: ul.LC_TabContentBigger {
1.911 bisitz 7281: display:block;
7282: list-style:none;
7283: padding: 0;
1.870 tempelho 7284: }
7285:
1.795 www 7286: ul.LC_TabContentBigger li {
1.911 bisitz 7287: vertical-align:bottom;
7288: height: 30px;
7289: font-size:110%;
7290: font-weight:bold;
7291: color: #737373;
1.841 tempelho 7292: }
7293:
1.957 onken 7294: ul.LC_TabContentBigger li.active {
7295: position: relative;
7296: top: 1px;
7297: }
7298:
1.870 tempelho 7299: ul.LC_TabContentBigger li a {
1.911 bisitz 7300: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7301: height: 30px;
7302: line-height: 30px;
7303: text-align: center;
7304: display: block;
7305: text-decoration: none;
1.958 onken 7306: outline: none;
1.741 harmsja 7307: }
1.795 www 7308:
1.870 tempelho 7309: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7310: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7311: color:$font;
1.744 ehlerst 7312: }
1.795 www 7313:
1.870 tempelho 7314: ul.LC_TabContentBigger li b {
1.911 bisitz 7315: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7316: display: block;
7317: float: left;
7318: padding: 0 30px;
1.957 onken 7319: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7320: }
7321:
1.956 onken 7322: ul.LC_TabContentBigger li:hover b {
7323: color:$button_hover;
7324: }
7325:
1.870 tempelho 7326: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7327: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7328: color:$font;
1.957 onken 7329: border: 0;
1.741 harmsja 7330: }
1.693 droeschl 7331:
1.870 tempelho 7332:
1.862 bisitz 7333: ul.LC_CourseBreadcrumbs {
7334: background: $sidebg;
1.1020 raeburn 7335: height: 2em;
1.862 bisitz 7336: padding-left: 10px;
1.1020 raeburn 7337: margin: 0;
1.862 bisitz 7338: list-style-position: inside;
7339: }
7340:
1.911 bisitz 7341: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7342: ol#LC_PathBreadcrumbs {
1.911 bisitz 7343: padding-left: 10px;
7344: margin: 0;
1.933 droeschl 7345: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7346: }
7347:
1.911 bisitz 7348: ol#LC_MenuBreadcrumbs li,
7349: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7350: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7351: display: inline;
1.933 droeschl 7352: white-space: normal;
1.693 droeschl 7353: }
7354:
1.823 bisitz 7355: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7356: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7357: text-decoration: none;
7358: font-size:90%;
1.693 droeschl 7359: }
1.795 www 7360:
1.969 droeschl 7361: ol#LC_MenuBreadcrumbs h1 {
7362: display: inline;
7363: font-size: 90%;
7364: line-height: 2.5em;
7365: margin: 0;
7366: padding: 0;
7367: }
7368:
1.795 www 7369: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7370: text-decoration:none;
7371: font-size:100%;
7372: font-weight:bold;
1.693 droeschl 7373: }
1.795 www 7374:
1.840 bisitz 7375: .LC_Box {
1.911 bisitz 7376: border: solid 1px $lg_border_color;
7377: padding: 0 10px 10px 10px;
1.746 neumanie 7378: }
1.795 www 7379:
1.1020 raeburn 7380: .LC_DocsBox {
7381: border: solid 1px $lg_border_color;
7382: padding: 0 0 10px 10px;
7383: }
7384:
1.795 www 7385: .LC_AboutMe_Image {
1.911 bisitz 7386: float:left;
7387: margin-right:10px;
1.747 neumanie 7388: }
1.795 www 7389:
7390: .LC_Clear_AboutMe_Image {
1.911 bisitz 7391: clear:left;
1.747 neumanie 7392: }
1.795 www 7393:
1.721 harmsja 7394: dl.LC_ListStyleClean dt {
1.911 bisitz 7395: padding-right: 5px;
7396: display: table-header-group;
1.693 droeschl 7397: }
7398:
1.721 harmsja 7399: dl.LC_ListStyleClean dd {
1.911 bisitz 7400: display: table-row;
1.693 droeschl 7401: }
7402:
1.721 harmsja 7403: .LC_ListStyleClean,
7404: .LC_ListStyleSimple,
7405: .LC_ListStyleNormal,
1.795 www 7406: .LC_ListStyleSpecial {
1.911 bisitz 7407: /* display:block; */
7408: list-style-position: inside;
7409: list-style-type: none;
7410: overflow: hidden;
7411: padding: 0;
1.693 droeschl 7412: }
7413:
1.721 harmsja 7414: .LC_ListStyleSimple li,
7415: .LC_ListStyleSimple dd,
7416: .LC_ListStyleNormal li,
7417: .LC_ListStyleNormal dd,
7418: .LC_ListStyleSpecial li,
1.795 www 7419: .LC_ListStyleSpecial dd {
1.911 bisitz 7420: margin: 0;
7421: padding: 5px 5px 5px 10px;
7422: clear: both;
1.693 droeschl 7423: }
7424:
1.721 harmsja 7425: .LC_ListStyleClean li,
7426: .LC_ListStyleClean dd {
1.911 bisitz 7427: padding-top: 0;
7428: padding-bottom: 0;
1.693 droeschl 7429: }
7430:
1.721 harmsja 7431: .LC_ListStyleSimple dd,
1.795 www 7432: .LC_ListStyleSimple li {
1.911 bisitz 7433: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7434: }
7435:
1.721 harmsja 7436: .LC_ListStyleSpecial li,
7437: .LC_ListStyleSpecial dd {
1.911 bisitz 7438: list-style-type: none;
7439: background-color: RGB(220, 220, 220);
7440: margin-bottom: 4px;
1.693 droeschl 7441: }
7442:
1.721 harmsja 7443: table.LC_SimpleTable {
1.911 bisitz 7444: margin:5px;
7445: border:solid 1px $lg_border_color;
1.795 www 7446: }
1.693 droeschl 7447:
1.721 harmsja 7448: table.LC_SimpleTable tr {
1.911 bisitz 7449: padding: 0;
7450: border:solid 1px $lg_border_color;
1.693 droeschl 7451: }
1.795 www 7452:
7453: table.LC_SimpleTable thead {
1.911 bisitz 7454: background:rgb(220,220,220);
1.693 droeschl 7455: }
7456:
1.721 harmsja 7457: div.LC_columnSection {
1.911 bisitz 7458: display: block;
7459: clear: both;
7460: overflow: hidden;
7461: margin: 0;
1.693 droeschl 7462: }
7463:
1.721 harmsja 7464: div.LC_columnSection>* {
1.911 bisitz 7465: float: left;
7466: margin: 10px 20px 10px 0;
7467: overflow:hidden;
1.693 droeschl 7468: }
1.721 harmsja 7469:
1.795 www 7470: table em {
1.911 bisitz 7471: font-weight: bold;
7472: font-style: normal;
1.748 schulted 7473: }
1.795 www 7474:
1.779 bisitz 7475: table.LC_tableBrowseRes,
1.795 www 7476: table.LC_tableOfContent {
1.911 bisitz 7477: border:none;
7478: border-spacing: 1px;
7479: padding: 3px;
7480: background-color: #FFFFFF;
7481: font-size: 90%;
1.753 droeschl 7482: }
1.789 droeschl 7483:
1.911 bisitz 7484: table.LC_tableOfContent {
7485: border-collapse: collapse;
1.789 droeschl 7486: }
7487:
1.771 droeschl 7488: table.LC_tableBrowseRes a,
1.768 schulted 7489: table.LC_tableOfContent a {
1.911 bisitz 7490: background-color: transparent;
7491: text-decoration: none;
1.753 droeschl 7492: }
7493:
1.795 www 7494: table.LC_tableOfContent img {
1.911 bisitz 7495: border: none;
7496: height: 1.3em;
7497: vertical-align: text-bottom;
7498: margin-right: 0.3em;
1.753 droeschl 7499: }
1.757 schulted 7500:
1.795 www 7501: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7502: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7503: }
7504:
1.795 www 7505: a#LC_content_toolbar_everything {
1.911 bisitz 7506: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7507: }
7508:
1.795 www 7509: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7510: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7511: }
7512:
1.795 www 7513: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7514: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7515: }
7516:
1.795 www 7517: a#LC_content_toolbar_changefolder {
1.911 bisitz 7518: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7519: }
7520:
1.795 www 7521: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7522: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7523: }
7524:
1.1043 raeburn 7525: a#LC_content_toolbar_edittoplevel {
7526: background-image:url(/res/adm/pages/edittoplevel.gif);
7527: }
7528:
1.795 www 7529: ul#LC_toolbar li a:hover {
1.911 bisitz 7530: background-position: bottom center;
1.757 schulted 7531: }
7532:
1.795 www 7533: ul#LC_toolbar {
1.911 bisitz 7534: padding: 0;
7535: margin: 2px;
7536: list-style:none;
7537: position:relative;
7538: background-color:white;
1.1082 raeburn 7539: overflow: auto;
1.757 schulted 7540: }
7541:
1.795 www 7542: ul#LC_toolbar li {
1.911 bisitz 7543: border:1px solid white;
7544: padding: 0;
7545: margin: 0;
7546: float: left;
7547: display:inline;
7548: vertical-align:middle;
1.1082 raeburn 7549: white-space: nowrap;
1.911 bisitz 7550: }
1.757 schulted 7551:
1.783 amueller 7552:
1.795 www 7553: a.LC_toolbarItem {
1.911 bisitz 7554: display:block;
7555: padding: 0;
7556: margin: 0;
7557: height: 32px;
7558: width: 32px;
7559: color:white;
7560: border: none;
7561: background-repeat:no-repeat;
7562: background-color:transparent;
1.757 schulted 7563: }
7564:
1.915 droeschl 7565: ul.LC_funclist {
7566: margin: 0;
7567: padding: 0.5em 1em 0.5em 0;
7568: }
7569:
1.933 droeschl 7570: ul.LC_funclist > li:first-child {
7571: font-weight:bold;
7572: margin-left:0.8em;
7573: }
7574:
1.915 droeschl 7575: ul.LC_funclist + ul.LC_funclist {
7576: /*
7577: left border as a seperator if we have more than
7578: one list
7579: */
7580: border-left: 1px solid $sidebg;
7581: /*
7582: this hides the left border behind the border of the
7583: outer box if element is wrapped to the next 'line'
7584: */
7585: margin-left: -1px;
7586: }
7587:
1.843 bisitz 7588: ul.LC_funclist li {
1.915 droeschl 7589: display: inline;
1.782 bisitz 7590: white-space: nowrap;
1.915 droeschl 7591: margin: 0 0 0 25px;
7592: line-height: 150%;
1.782 bisitz 7593: }
7594:
1.974 wenzelju 7595: .LC_hidden {
7596: display: none;
7597: }
7598:
1.1030 www 7599: .LCmodal-overlay {
7600: position:fixed;
7601: top:0;
7602: right:0;
7603: bottom:0;
7604: left:0;
7605: height:100%;
7606: width:100%;
7607: margin:0;
7608: padding:0;
7609: background:#999;
7610: opacity:.75;
7611: filter: alpha(opacity=75);
7612: -moz-opacity: 0.75;
7613: z-index:101;
7614: }
7615:
7616: * html .LCmodal-overlay {
7617: position: absolute;
7618: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7619: }
7620:
7621: .LCmodal-window {
7622: position:fixed;
7623: top:50%;
7624: left:50%;
7625: margin:0;
7626: padding:0;
7627: z-index:102;
7628: }
7629:
7630: * html .LCmodal-window {
7631: position:absolute;
7632: }
7633:
7634: .LCclose-window {
7635: position:absolute;
7636: width:32px;
7637: height:32px;
7638: right:8px;
7639: top:8px;
7640: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7641: text-indent:-99999px;
7642: overflow:hidden;
7643: cursor:pointer;
7644: }
7645:
1.1100 raeburn 7646: /*
7647: styles used by TTH when "Default set of options to pass to tth/m
7648: when converting TeX" in course settings has been set
7649:
7650: option passed: -t
7651:
7652: */
7653:
7654: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7655: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7656: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7657: td div.norm {line-height:normal;}
7658:
7659: /*
7660: option passed -y3
7661: */
7662:
7663: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7664: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7665: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7666:
1.343 albertel 7667: END
7668: }
7669:
1.306 albertel 7670: =pod
7671:
7672: =item * &headtag()
7673:
7674: Returns a uniform footer for LON-CAPA web pages.
7675:
1.307 albertel 7676: Inputs: $title - optional title for the head
7677: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7678: $args - optional arguments
1.319 albertel 7679: force_register - if is true call registerurl so the remote is
7680: informed
1.415 albertel 7681: redirect -> array ref of
7682: 1- seconds before redirect occurs
7683: 2- url to redirect to
7684: 3- whether the side effect should occur
1.315 albertel 7685: (side effect of setting
7686: $env{'internal.head.redirect'} to the url
7687: redirected too)
1.352 albertel 7688: domain -> force to color decorate a page for a specific
7689: domain
7690: function -> force usage of a specific rolish color scheme
7691: bgcolor -> override the default page bgcolor
1.460 albertel 7692: no_auto_mt_title
7693: -> prevent &mt()ing the title arg
1.464 albertel 7694:
1.306 albertel 7695: =cut
7696:
7697: sub headtag {
1.313 albertel 7698: my ($title,$head_extra,$args) = @_;
1.306 albertel 7699:
1.363 albertel 7700: my $function = $args->{'function'} || &get_users_function();
7701: my $domain = $args->{'domain'} || &determinedomain();
7702: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 7703: my $httphost = $args->{'use_absolute'};
1.418 albertel 7704: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7705: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7706: #time(),
1.418 albertel 7707: $env{'environment.color.timestamp'},
1.363 albertel 7708: $function,$domain,$bgcolor);
7709:
1.369 www 7710: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7711:
1.308 albertel 7712: my $result =
7713: '<head>'.
1.1160 raeburn 7714: &font_settings($args);
1.319 albertel 7715:
1.1188 raeburn 7716: my $inhibitprint;
7717: if ($args->{'print_suppress'}) {
7718: $inhibitprint = &print_suppression();
7719: }
1.1064 raeburn 7720:
1.461 albertel 7721: if (!$args->{'frameset'}) {
7722: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7723: }
1.962 droeschl 7724: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7725: $result .= Apache::lonxml::display_title();
1.319 albertel 7726: }
1.436 albertel 7727: if (!$args->{'no_nav_bar'}
7728: && !$args->{'only_body'}
7729: && !$args->{'frameset'}) {
1.1154 raeburn 7730: $result .= &help_menu_js($httphost);
1.1032 www 7731: $result.=&modal_window();
1.1038 www 7732: $result.=&togglebox_script();
1.1034 www 7733: $result.=&wishlist_window();
1.1041 www 7734: $result.=&LCprogressbarUpdate_script();
1.1034 www 7735: } else {
7736: if ($args->{'add_modal'}) {
7737: $result.=&modal_window();
7738: }
7739: if ($args->{'add_wishlist'}) {
7740: $result.=&wishlist_window();
7741: }
1.1038 www 7742: if ($args->{'add_togglebox'}) {
7743: $result.=&togglebox_script();
7744: }
1.1041 www 7745: if ($args->{'add_progressbar'}) {
7746: $result.=&LCprogressbarUpdate_script();
7747: }
1.436 albertel 7748: }
1.314 albertel 7749: if (ref($args->{'redirect'})) {
1.414 albertel 7750: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7751: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7752: if (!$inhibit_continue) {
7753: $env{'internal.head.redirect'} = $url;
7754: }
1.313 albertel 7755: $result.=<<ADDMETA
7756: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7757: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7758: ADDMETA
1.1210 raeburn 7759: } else {
7760: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7761: my $requrl = $env{'request.uri'};
7762: if ($requrl eq '') {
7763: $requrl = $ENV{'REQUEST_URI'};
7764: $requrl =~ s/\?.+$//;
7765: }
7766: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7767: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7768: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7769: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7770: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7771: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7772: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7773: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7774: if ($domdefs{'offloadnow'}{$lonhost}) {
7775: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7776: if (($newserver) && ($newserver ne $lonhost)) {
7777: my $numsec = 5;
7778: my $timeout = $numsec * 1000;
7779: my ($newurl,$locknum,%locks,$msg);
7780: if ($env{'request.role.adv'}) {
7781: ($locknum,%locks) = &Apache::lonnet::get_locks();
7782: }
7783: my $disable_submit = 0;
7784: if ($requrl =~ /$LONCAPA::assess_re/) {
7785: $disable_submit = 1;
7786: }
7787: if ($locknum) {
7788: my @lockinfo = sort(values(%locks));
7789: $msg = &mt('Once the following tasks are complete: ')."\\n".
7790: join(", ",sort(values(%locks)))."\\n".
7791: &mt('your session will be transferred to a different server, after you click "Roles".');
7792: } else {
7793: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7794: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7795: }
7796: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7797: $newurl = '/adm/switchserver?otherserver='.$newserver;
7798: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7799: $newurl .= '&role='.$env{'request.role'};
7800: }
7801: if ($env{'request.symb'}) {
7802: $newurl .= '&symb='.$env{'request.symb'};
7803: } else {
7804: $newurl .= '&origurl='.$requrl;
7805: }
7806: }
1.1222 damieng 7807: &js_escape(\$msg);
1.1210 raeburn 7808: $result.=<<OFFLOAD
7809: <meta http-equiv="pragma" content="no-cache" />
7810: <script type="text/javascript">
1.1215 raeburn 7811: // <![CDATA[
1.1210 raeburn 7812: function LC_Offload_Now() {
7813: var dest = "$newurl";
7814: if (dest != '') {
7815: window.location.href="$newurl";
7816: }
7817: }
1.1214 raeburn 7818: \$(document).ready(function () {
7819: window.alert('$msg');
7820: if ($disable_submit) {
1.1210 raeburn 7821: \$(".LC_hwk_submit").prop("disabled", true);
7822: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 7823: }
7824: setTimeout('LC_Offload_Now()', $timeout);
7825: });
1.1215 raeburn 7826: // ]]>
1.1210 raeburn 7827: </script>
7828: OFFLOAD
7829: }
7830: }
7831: }
7832: }
7833: }
7834: }
1.313 albertel 7835: }
1.306 albertel 7836: if (!defined($title)) {
7837: $title = 'The LearningOnline Network with CAPA';
7838: }
1.460 albertel 7839: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7840: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 7841: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7842: if (!$args->{'frameset'}) {
7843: $result .= ' /';
7844: }
7845: $result .= '>'
1.1064 raeburn 7846: .$inhibitprint
1.414 albertel 7847: .$head_extra;
1.1137 raeburn 7848: if ($env{'browser.mobile'}) {
7849: $result .= '
7850: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7851: <meta name="apple-mobile-web-app-capable" content="yes" />';
7852: }
1.962 droeschl 7853: return $result.'</head>';
1.306 albertel 7854: }
7855:
7856: =pod
7857:
1.340 albertel 7858: =item * &font_settings()
7859:
7860: Returns neccessary <meta> to set the proper encoding
7861:
1.1160 raeburn 7862: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7863:
7864: =cut
7865:
7866: sub font_settings {
1.1160 raeburn 7867: my ($args) = @_;
1.340 albertel 7868: my $headerstring='';
1.1160 raeburn 7869: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7870: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 7871: $headerstring.=
7872: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7873: if (!$args->{'frameset'}) {
7874: $headerstring.= ' /';
7875: }
7876: $headerstring .= '>'."\n";
1.340 albertel 7877: }
7878: return $headerstring;
7879: }
7880:
1.341 albertel 7881: =pod
7882:
1.1064 raeburn 7883: =item * &print_suppression()
7884:
7885: In course context returns css which causes the body to be blank when media="print",
7886: if printout generation is unavailable for the current resource.
7887:
7888: This could be because:
7889:
7890: (a) printstartdate is in the future
7891:
7892: (b) printenddate is in the past
7893:
7894: (c) there is an active exam block with "printout"
7895: functionality blocked
7896:
7897: Users with pav, pfo or evb privileges are exempt.
7898:
7899: Inputs: none
7900:
7901: =cut
7902:
7903:
7904: sub print_suppression {
7905: my $noprint;
7906: if ($env{'request.course.id'}) {
7907: my $scope = $env{'request.course.id'};
7908: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7909: (&Apache::lonnet::allowed('pfo',$scope))) {
7910: return;
7911: }
7912: if ($env{'request.course.sec'} ne '') {
7913: $scope .= "/$env{'request.course.sec'}";
7914: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7915: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7916: return;
1.1064 raeburn 7917: }
7918: }
7919: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7920: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 7921: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 7922: if ($blocked) {
7923: my $checkrole = "cm./$cdom/$cnum";
7924: if ($env{'request.course.sec'} ne '') {
7925: $checkrole .= "/$env{'request.course.sec'}";
7926: }
7927: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7928: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7929: $noprint = 1;
7930: }
7931: }
7932: unless ($noprint) {
7933: my $symb = &Apache::lonnet::symbread();
7934: if ($symb ne '') {
7935: my $navmap = Apache::lonnavmaps::navmap->new();
7936: if (ref($navmap)) {
7937: my $res = $navmap->getBySymb($symb);
7938: if (ref($res)) {
7939: if (!$res->resprintable()) {
7940: $noprint = 1;
7941: }
7942: }
7943: }
7944: }
7945: }
7946: if ($noprint) {
7947: return <<"ENDSTYLE";
7948: <style type="text/css" media="print">
7949: body { display:none }
7950: </style>
7951: ENDSTYLE
7952: }
7953: }
7954: return;
7955: }
7956:
7957: =pod
7958:
1.341 albertel 7959: =item * &xml_begin()
7960:
7961: Returns the needed doctype and <html>
7962:
7963: Inputs: none
7964:
7965: =cut
7966:
7967: sub xml_begin {
1.1168 raeburn 7968: my ($is_frameset) = @_;
1.341 albertel 7969: my $output='';
7970:
7971: if ($env{'browser.mathml'}) {
7972: $output='<?xml version="1.0"?>'
7973: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7974: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7975:
7976: # .'<!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">] >'
7977: .'<!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">'
7978: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7979: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 7980: } elsif ($is_frameset) {
7981: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7982: '<html>'."\n";
1.341 albertel 7983: } else {
1.1168 raeburn 7984: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7985: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7986: }
7987: return $output;
7988: }
1.340 albertel 7989:
7990: =pod
7991:
1.306 albertel 7992: =item * &start_page()
7993:
7994: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7995:
1.648 raeburn 7996: Inputs:
7997:
7998: =over 4
7999:
8000: $title - optional title for the page
8001:
8002: $head_extra - optional extra HTML to incude inside the <head>
8003:
8004: $args - additional optional args supported are:
8005:
8006: =over 8
8007:
8008: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8009: arg on
1.814 bisitz 8010: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8011: add_entries -> additional attributes to add to the <body>
8012: domain -> force to color decorate a page for a
1.317 albertel 8013: specific domain
1.648 raeburn 8014: function -> force usage of a specific rolish color
1.317 albertel 8015: scheme
1.648 raeburn 8016: redirect -> see &headtag()
8017: bgcolor -> override the default page bg color
8018: js_ready -> return a string ready for being used in
1.317 albertel 8019: a javascript writeln
1.648 raeburn 8020: html_encode -> return a string ready for being used in
1.320 albertel 8021: a html attribute
1.648 raeburn 8022: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8023: $forcereg arg
1.648 raeburn 8024: frameset -> if true will start with a <frameset>
1.330 albertel 8025: rather than <body>
1.648 raeburn 8026: skip_phases -> hash ref of
1.338 albertel 8027: head -> skip the <html><head> generation
8028: body -> skip all <body> generation
1.648 raeburn 8029: no_auto_mt_title -> prevent &mt()ing the title arg
8030: inherit_jsmath -> when creating popup window in a page,
8031: should it have jsmath forced on by the
8032: current page
1.867 kalberla 8033: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8034: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 8035: group -> includes the current group, if page is for a
8036: specific group
1.361 albertel 8037:
1.648 raeburn 8038: =back
1.460 albertel 8039:
1.648 raeburn 8040: =back
1.562 albertel 8041:
1.306 albertel 8042: =cut
8043:
8044: sub start_page {
1.309 albertel 8045: my ($title,$head_extra,$args) = @_;
1.318 albertel 8046: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8047:
1.315 albertel 8048: $env{'internal.start_page'}++;
1.1096 raeburn 8049: my ($result,@advtools);
1.964 droeschl 8050:
1.338 albertel 8051: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8052: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8053: }
8054:
8055: if (! exists($args->{'skip_phases'}{'body'}) ) {
8056: if ($args->{'frameset'}) {
8057: my $attr_string = &make_attr_string($args->{'force_register'},
8058: $args->{'add_entries'});
8059: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8060: } else {
8061: $result .=
8062: &bodytag($title,
8063: $args->{'function'}, $args->{'add_entries'},
8064: $args->{'only_body'}, $args->{'domain'},
8065: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8066: $args->{'bgcolor'}, $args,
8067: \@advtools);
1.831 bisitz 8068: }
1.330 albertel 8069: }
1.338 albertel 8070:
1.315 albertel 8071: if ($args->{'js_ready'}) {
1.713 kaisler 8072: $result = &js_ready($result);
1.315 albertel 8073: }
1.320 albertel 8074: if ($args->{'html_encode'}) {
1.713 kaisler 8075: $result = &html_encode($result);
8076: }
8077:
1.813 bisitz 8078: # Preparation for new and consistent functionlist at top of screen
8079: # if ($args->{'functionlist'}) {
8080: # $result .= &build_functionlist();
8081: #}
8082:
1.964 droeschl 8083: # Don't add anything more if only_body wanted or in const space
8084: return $result if $args->{'only_body'}
8085: || $env{'request.state'} eq 'construct';
1.813 bisitz 8086:
8087: #Breadcrumbs
1.758 kaisler 8088: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8089: &Apache::lonhtmlcommon::clear_breadcrumbs();
8090: #if any br links exists, add them to the breadcrumbs
8091: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8092: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8093: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8094: }
8095: }
1.1096 raeburn 8096: # if @advtools array contains items add then to the breadcrumbs
8097: if (@advtools > 0) {
8098: &Apache::lonmenu::advtools_crumbs(@advtools);
8099: }
1.758 kaisler 8100:
8101: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8102: if(exists($args->{'bread_crumbs_component'})){
8103: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
8104: }else{
8105: $result .= &Apache::lonhtmlcommon::breadcrumbs();
8106: }
1.320 albertel 8107: }
1.315 albertel 8108: return $result;
1.306 albertel 8109: }
8110:
8111: sub end_page {
1.315 albertel 8112: my ($args) = @_;
8113: $env{'internal.end_page'}++;
1.330 albertel 8114: my $result;
1.335 albertel 8115: if ($args->{'discussion'}) {
8116: my ($target,$parser);
8117: if (ref($args->{'discussion'})) {
8118: ($target,$parser) =($args->{'discussion'}{'target'},
8119: $args->{'discussion'}{'parser'});
8120: }
8121: $result .= &Apache::lonxml::xmlend($target,$parser);
8122: }
1.330 albertel 8123: if ($args->{'frameset'}) {
8124: $result .= '</frameset>';
8125: } else {
1.635 raeburn 8126: $result .= &endbodytag($args);
1.330 albertel 8127: }
1.1080 raeburn 8128: unless ($args->{'notbody'}) {
8129: $result .= "\n</html>";
8130: }
1.330 albertel 8131:
1.315 albertel 8132: if ($args->{'js_ready'}) {
1.317 albertel 8133: $result = &js_ready($result);
1.315 albertel 8134: }
1.335 albertel 8135:
1.320 albertel 8136: if ($args->{'html_encode'}) {
8137: $result = &html_encode($result);
8138: }
1.335 albertel 8139:
1.315 albertel 8140: return $result;
8141: }
8142:
1.1034 www 8143: sub wishlist_window {
8144: return(<<'ENDWISHLIST');
1.1046 raeburn 8145: <script type="text/javascript">
1.1034 www 8146: // <![CDATA[
8147: // <!-- BEGIN LON-CAPA Internal
8148: function set_wishlistlink(title, path) {
8149: if (!title) {
8150: title = document.title;
8151: title = title.replace(/^LON-CAPA /,'');
8152: }
1.1175 raeburn 8153: title = encodeURIComponent(title);
1.1203 raeburn 8154: title = title.replace("'","\\\'");
1.1034 www 8155: if (!path) {
8156: path = location.pathname;
8157: }
1.1175 raeburn 8158: path = encodeURIComponent(path);
1.1203 raeburn 8159: path = path.replace("'","\\\'");
1.1034 www 8160: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8161: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8162: }
8163: // END LON-CAPA Internal -->
8164: // ]]>
8165: </script>
8166: ENDWISHLIST
8167: }
8168:
1.1030 www 8169: sub modal_window {
8170: return(<<'ENDMODAL');
1.1046 raeburn 8171: <script type="text/javascript">
1.1030 www 8172: // <![CDATA[
8173: // <!-- BEGIN LON-CAPA Internal
8174: var modalWindow = {
8175: parent:"body",
8176: windowId:null,
8177: content:null,
8178: width:null,
8179: height:null,
8180: close:function()
8181: {
8182: $(".LCmodal-window").remove();
8183: $(".LCmodal-overlay").remove();
8184: },
8185: open:function()
8186: {
8187: var modal = "";
8188: modal += "<div class=\"LCmodal-overlay\"></div>";
8189: 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;\">";
8190: modal += this.content;
8191: modal += "</div>";
8192:
8193: $(this.parent).append(modal);
8194:
8195: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8196: $(".LCclose-window").click(function(){modalWindow.close();});
8197: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8198: }
8199: };
1.1140 raeburn 8200: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8201: {
1.1203 raeburn 8202: source = source.replace("'","'");
1.1030 www 8203: modalWindow.windowId = "myModal";
8204: modalWindow.width = width;
8205: modalWindow.height = height;
1.1196 raeburn 8206: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8207: modalWindow.open();
1.1208 raeburn 8208: };
1.1030 www 8209: // END LON-CAPA Internal -->
8210: // ]]>
8211: </script>
8212: ENDMODAL
8213: }
8214:
8215: sub modal_link {
1.1140 raeburn 8216: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8217: unless ($width) { $width=480; }
8218: unless ($height) { $height=400; }
1.1031 www 8219: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8220: unless ($transparency) { $transparency='true'; }
8221:
1.1074 raeburn 8222: my $target_attr;
8223: if (defined($target)) {
8224: $target_attr = 'target="'.$target.'"';
8225: }
8226: return <<"ENDLINK";
1.1140 raeburn 8227: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8228: $linktext</a>
8229: ENDLINK
1.1030 www 8230: }
8231:
1.1032 www 8232: sub modal_adhoc_script {
8233: my ($funcname,$width,$height,$content)=@_;
8234: return (<<ENDADHOC);
1.1046 raeburn 8235: <script type="text/javascript">
1.1032 www 8236: // <![CDATA[
8237: var $funcname = function()
8238: {
8239: modalWindow.windowId = "myModal";
8240: modalWindow.width = $width;
8241: modalWindow.height = $height;
8242: modalWindow.content = '$content';
8243: modalWindow.open();
8244: };
8245: // ]]>
8246: </script>
8247: ENDADHOC
8248: }
8249:
1.1041 www 8250: sub modal_adhoc_inner {
8251: my ($funcname,$width,$height,$content)=@_;
8252: my $innerwidth=$width-20;
8253: $content=&js_ready(
1.1140 raeburn 8254: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8255: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8256: $content.
1.1041 www 8257: &end_scrollbox().
1.1140 raeburn 8258: &end_page()
1.1041 www 8259: );
8260: return &modal_adhoc_script($funcname,$width,$height,$content);
8261: }
8262:
8263: sub modal_adhoc_window {
8264: my ($funcname,$width,$height,$content,$linktext)=@_;
8265: return &modal_adhoc_inner($funcname,$width,$height,$content).
8266: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8267: }
8268:
8269: sub modal_adhoc_launch {
8270: my ($funcname,$width,$height,$content)=@_;
8271: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8272: <script type="text/javascript">
8273: // <![CDATA[
8274: $funcname();
8275: // ]]>
8276: </script>
8277: ENDLAUNCH
8278: }
8279:
8280: sub modal_adhoc_close {
8281: return (<<ENDCLOSE);
8282: <script type="text/javascript">
8283: // <![CDATA[
8284: modalWindow.close();
8285: // ]]>
8286: </script>
8287: ENDCLOSE
8288: }
8289:
1.1038 www 8290: sub togglebox_script {
8291: return(<<ENDTOGGLE);
8292: <script type="text/javascript">
8293: // <![CDATA[
8294: function LCtoggleDisplay(id,hidetext,showtext) {
8295: link = document.getElementById(id + "link").childNodes[0];
8296: with (document.getElementById(id).style) {
8297: if (display == "none" ) {
8298: display = "inline";
8299: link.nodeValue = hidetext;
8300: } else {
8301: display = "none";
8302: link.nodeValue = showtext;
8303: }
8304: }
8305: }
8306: // ]]>
8307: </script>
8308: ENDTOGGLE
8309: }
8310:
1.1039 www 8311: sub start_togglebox {
8312: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8313: unless ($heading) { $heading=''; } else { $heading.=' '; }
8314: unless ($showtext) { $showtext=&mt('show'); }
8315: unless ($hidetext) { $hidetext=&mt('hide'); }
8316: unless ($headerbg) { $headerbg='#FFFFFF'; }
8317: return &start_data_table().
8318: &start_data_table_header_row().
8319: '<td bgcolor="'.$headerbg.'">'.$heading.
8320: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8321: $showtext.'\')">'.$showtext.'</a>]</td>'.
8322: &end_data_table_header_row().
8323: '<tr id="'.$id.'" style="display:none""><td>';
8324: }
8325:
8326: sub end_togglebox {
8327: return '</td></tr>'.&end_data_table();
8328: }
8329:
1.1041 www 8330: sub LCprogressbar_script {
1.1045 www 8331: my ($id)=@_;
1.1041 www 8332: return(<<ENDPROGRESS);
8333: <script type="text/javascript">
8334: // <![CDATA[
1.1045 www 8335: \$('#progressbar$id').progressbar({
1.1041 www 8336: value: 0,
8337: change: function(event, ui) {
8338: var newVal = \$(this).progressbar('option', 'value');
8339: \$('.pblabel', this).text(LCprogressTxt);
8340: }
8341: });
8342: // ]]>
8343: </script>
8344: ENDPROGRESS
8345: }
8346:
8347: sub LCprogressbarUpdate_script {
8348: return(<<ENDPROGRESSUPDATE);
8349: <style type="text/css">
8350: .ui-progressbar { position:relative; }
8351: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8352: </style>
8353: <script type="text/javascript">
8354: // <![CDATA[
1.1045 www 8355: var LCprogressTxt='---';
8356:
8357: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8358: LCprogressTxt=progresstext;
1.1045 www 8359: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8360: }
8361: // ]]>
8362: </script>
8363: ENDPROGRESSUPDATE
8364: }
8365:
1.1042 www 8366: my $LClastpercent;
1.1045 www 8367: my $LCidcnt;
8368: my $LCcurrentid;
1.1042 www 8369:
1.1041 www 8370: sub LCprogressbar {
1.1042 www 8371: my ($r)=(@_);
8372: $LClastpercent=0;
1.1045 www 8373: $LCidcnt++;
8374: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8375: my $starting=&mt('Starting');
8376: my $content=(<<ENDPROGBAR);
1.1045 www 8377: <div id="progressbar$LCcurrentid">
1.1041 www 8378: <span class="pblabel">$starting</span>
8379: </div>
8380: ENDPROGBAR
1.1045 www 8381: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8382: }
8383:
8384: sub LCprogressbarUpdate {
1.1042 www 8385: my ($r,$val,$text)=@_;
8386: unless ($val) {
8387: if ($LClastpercent) {
8388: $val=$LClastpercent;
8389: } else {
8390: $val=0;
8391: }
8392: }
1.1041 www 8393: if ($val<0) { $val=0; }
8394: if ($val>100) { $val=0; }
1.1042 www 8395: $LClastpercent=$val;
1.1041 www 8396: unless ($text) { $text=$val.'%'; }
8397: $text=&js_ready($text);
1.1044 www 8398: &r_print($r,<<ENDUPDATE);
1.1041 www 8399: <script type="text/javascript">
8400: // <![CDATA[
1.1045 www 8401: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8402: // ]]>
8403: </script>
8404: ENDUPDATE
1.1035 www 8405: }
8406:
1.1042 www 8407: sub LCprogressbarClose {
8408: my ($r)=@_;
8409: $LClastpercent=0;
1.1044 www 8410: &r_print($r,<<ENDCLOSE);
1.1042 www 8411: <script type="text/javascript">
8412: // <![CDATA[
1.1045 www 8413: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8414: // ]]>
8415: </script>
8416: ENDCLOSE
1.1044 www 8417: }
8418:
8419: sub r_print {
8420: my ($r,$to_print)=@_;
8421: if ($r) {
8422: $r->print($to_print);
8423: $r->rflush();
8424: } else {
8425: print($to_print);
8426: }
1.1042 www 8427: }
8428:
1.320 albertel 8429: sub html_encode {
8430: my ($result) = @_;
8431:
1.322 albertel 8432: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8433:
8434: return $result;
8435: }
1.1044 www 8436:
1.317 albertel 8437: sub js_ready {
8438: my ($result) = @_;
8439:
1.323 albertel 8440: $result =~ s/[\n\r]/ /xmsg;
8441: $result =~ s/\\/\\\\/xmsg;
8442: $result =~ s/'/\\'/xmsg;
1.372 albertel 8443: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8444:
8445: return $result;
8446: }
8447:
1.315 albertel 8448: sub validate_page {
8449: if ( exists($env{'internal.start_page'})
1.316 albertel 8450: && $env{'internal.start_page'} > 1) {
8451: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8452: $env{'internal.start_page'}.' '.
1.316 albertel 8453: $ENV{'request.filename'});
1.315 albertel 8454: }
8455: if ( exists($env{'internal.end_page'})
1.316 albertel 8456: && $env{'internal.end_page'} > 1) {
8457: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8458: $env{'internal.end_page'}.' '.
1.316 albertel 8459: $env{'request.filename'});
1.315 albertel 8460: }
8461: if ( exists($env{'internal.start_page'})
8462: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8463: &Apache::lonnet::logthis('start_page called without end_page '.
8464: $env{'request.filename'});
1.315 albertel 8465: }
8466: if ( ! exists($env{'internal.start_page'})
8467: && exists($env{'internal.end_page'})) {
1.316 albertel 8468: &Apache::lonnet::logthis('end_page called without start_page'.
8469: $env{'request.filename'});
1.315 albertel 8470: }
1.306 albertel 8471: }
1.315 albertel 8472:
1.996 www 8473:
8474: sub start_scrollbox {
1.1140 raeburn 8475: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8476: unless ($outerwidth) { $outerwidth='520px'; }
8477: unless ($width) { $width='500px'; }
8478: unless ($height) { $height='200px'; }
1.1075 raeburn 8479: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8480: if ($id ne '') {
1.1140 raeburn 8481: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 8482: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8483: }
1.1075 raeburn 8484: if ($bgcolor ne '') {
8485: $tdcol = "background-color: $bgcolor;";
8486: }
1.1137 raeburn 8487: my $nicescroll_js;
8488: if ($env{'browser.mobile'}) {
1.1140 raeburn 8489: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8490: }
8491: return <<"END";
8492: $nicescroll_js
8493:
8494: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
8495: <div style="overflow:auto; width:$width; height:$height;"$div_id>
8496: END
8497: }
8498:
8499: sub end_scrollbox {
8500: return '</div></td></tr></table>';
8501: }
8502:
8503: sub nicescroll_javascript {
8504: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8505: my %options;
8506: if (ref($cursor) eq 'HASH') {
8507: %options = %{$cursor};
8508: }
8509: unless ($options{'railalign'} =~ /^left|right$/) {
8510: $options{'railalign'} = 'left';
8511: }
8512: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8513: my $function = &get_users_function();
8514: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 8515: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 8516: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 8517: }
1.1140 raeburn 8518: }
8519: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8520: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 8521: $options{'cursoropacity'}='1.0';
8522: }
1.1140 raeburn 8523: } else {
8524: $options{'cursoropacity'}='1.0';
8525: }
8526: if ($options{'cursorfixedheight'} eq 'none') {
8527: delete($options{'cursorfixedheight'});
8528: } else {
8529: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8530: }
8531: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8532: delete($options{'railoffset'});
8533: }
8534: my @niceoptions;
8535: while (my($key,$value) = each(%options)) {
8536: if ($value =~ /^\{.+\}$/) {
8537: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 8538: } else {
1.1140 raeburn 8539: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 8540: }
1.1140 raeburn 8541: }
8542: my $nicescroll_js = '
1.1137 raeburn 8543: $(document).ready(
1.1140 raeburn 8544: function() {
8545: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8546: }
1.1137 raeburn 8547: );
8548: ';
1.1140 raeburn 8549: if ($framecheck) {
8550: $nicescroll_js .= '
8551: function expand_div(caller) {
8552: if (top === self) {
8553: document.getElementById("'.$id.'").style.width = "auto";
8554: document.getElementById("'.$id.'").style.height = "auto";
8555: } else {
8556: try {
8557: if (parent.frames) {
8558: if (parent.frames.length > 1) {
8559: var framesrc = parent.frames[1].location.href;
8560: var currsrc = framesrc.replace(/\#.*$/,"");
8561: if ((caller == "search") || (currsrc == "'.$location.'")) {
8562: document.getElementById("'.$id.'").style.width = "auto";
8563: document.getElementById("'.$id.'").style.height = "auto";
8564: }
8565: }
8566: }
8567: } catch (e) {
8568: return;
8569: }
1.1137 raeburn 8570: }
1.1140 raeburn 8571: return;
1.996 www 8572: }
1.1140 raeburn 8573: ';
8574: }
8575: if ($needjsready) {
8576: $nicescroll_js = '
8577: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8578: } else {
8579: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8580: }
8581: return $nicescroll_js;
1.996 www 8582: }
8583:
1.318 albertel 8584: sub simple_error_page {
1.1150 bisitz 8585: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 8586: if (ref($args) eq 'HASH') {
8587: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8588: } else {
8589: $msg = &mt($msg);
8590: }
1.1150 bisitz 8591:
1.318 albertel 8592: my $page =
8593: &Apache::loncommon::start_page($title).
1.1150 bisitz 8594: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8595: &Apache::loncommon::end_page();
8596: if (ref($r)) {
8597: $r->print($page);
1.327 albertel 8598: return;
1.318 albertel 8599: }
8600: return $page;
8601: }
1.347 albertel 8602:
8603: {
1.610 albertel 8604: my @row_count;
1.961 onken 8605:
8606: sub start_data_table_count {
8607: unshift(@row_count, 0);
8608: return;
8609: }
8610:
8611: sub end_data_table_count {
8612: shift(@row_count);
8613: return;
8614: }
8615:
1.347 albertel 8616: sub start_data_table {
1.1018 raeburn 8617: my ($add_class,$id) = @_;
1.422 albertel 8618: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8619: my $table_id;
8620: if (defined($id)) {
8621: $table_id = ' id="'.$id.'"';
8622: }
1.961 onken 8623: &start_data_table_count();
1.1018 raeburn 8624: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8625: }
8626:
8627: sub end_data_table {
1.961 onken 8628: &end_data_table_count();
1.389 albertel 8629: return '</table>'."\n";;
1.347 albertel 8630: }
8631:
8632: sub start_data_table_row {
1.974 wenzelju 8633: my ($add_class, $id) = @_;
1.610 albertel 8634: $row_count[0]++;
8635: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8636: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8637: $id = (' id="'.$id.'"') unless ($id eq '');
8638: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8639: }
1.471 banghart 8640:
8641: sub continue_data_table_row {
1.974 wenzelju 8642: my ($add_class, $id) = @_;
1.610 albertel 8643: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8644: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8645: $id = (' id="'.$id.'"') unless ($id eq '');
8646: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8647: }
1.347 albertel 8648:
8649: sub end_data_table_row {
1.389 albertel 8650: return '</tr>'."\n";;
1.347 albertel 8651: }
1.367 www 8652:
1.421 albertel 8653: sub start_data_table_empty_row {
1.707 bisitz 8654: # $row_count[0]++;
1.421 albertel 8655: return '<tr class="LC_empty_row" >'."\n";;
8656: }
8657:
8658: sub end_data_table_empty_row {
8659: return '</tr>'."\n";;
8660: }
8661:
1.367 www 8662: sub start_data_table_header_row {
1.389 albertel 8663: return '<tr class="LC_header_row">'."\n";;
1.367 www 8664: }
8665:
8666: sub end_data_table_header_row {
1.389 albertel 8667: return '</tr>'."\n";;
1.367 www 8668: }
1.890 droeschl 8669:
8670: sub data_table_caption {
8671: my $caption = shift;
8672: return "<caption class=\"LC_caption\">$caption</caption>";
8673: }
1.347 albertel 8674: }
8675:
1.548 albertel 8676: =pod
8677:
8678: =item * &inhibit_menu_check($arg)
8679:
8680: Checks for a inhibitmenu state and generates output to preserve it
8681:
8682: Inputs: $arg - can be any of
8683: - undef - in which case the return value is a string
8684: to add into arguments list of a uri
8685: - 'input' - in which case the return value is a HTML
8686: <form> <input> field of type hidden to
8687: preserve the value
8688: - a url - in which case the return value is the url with
8689: the neccesary cgi args added to preserve the
8690: inhibitmenu state
8691: - a ref to a url - no return value, but the string is
8692: updated to include the neccessary cgi
8693: args to preserve the inhibitmenu state
8694:
8695: =cut
8696:
8697: sub inhibit_menu_check {
8698: my ($arg) = @_;
8699: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8700: if ($arg eq 'input') {
8701: if ($env{'form.inhibitmenu'}) {
8702: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8703: } else {
8704: return
8705: }
8706: }
8707: if ($env{'form.inhibitmenu'}) {
8708: if (ref($arg)) {
8709: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8710: } elsif ($arg eq '') {
8711: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8712: } else {
8713: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8714: }
8715: }
8716: if (!ref($arg)) {
8717: return $arg;
8718: }
8719: }
8720:
1.251 albertel 8721: ###############################################
1.182 matthew 8722:
8723: =pod
8724:
1.549 albertel 8725: =back
8726:
8727: =head1 User Information Routines
8728:
8729: =over 4
8730:
1.405 albertel 8731: =item * &get_users_function()
1.182 matthew 8732:
8733: Used by &bodytag to determine the current users primary role.
8734: Returns either 'student','coordinator','admin', or 'author'.
8735:
8736: =cut
8737:
8738: ###############################################
8739: sub get_users_function {
1.815 tempelho 8740: my $function = 'norole';
1.818 tempelho 8741: if ($env{'request.role'}=~/^(st)/) {
8742: $function='student';
8743: }
1.907 raeburn 8744: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8745: $function='coordinator';
8746: }
1.258 albertel 8747: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8748: $function='admin';
8749: }
1.826 bisitz 8750: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8751: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8752: $function='author';
8753: }
8754: return $function;
1.54 www 8755: }
1.99 www 8756:
8757: ###############################################
8758:
1.233 raeburn 8759: =pod
8760:
1.821 raeburn 8761: =item * &show_course()
8762:
8763: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8764: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8765:
8766: Inputs:
8767: None
8768:
8769: Outputs:
8770: Scalar: 1 if 'Course' to be used, 0 otherwise.
8771:
8772: =cut
8773:
8774: ###############################################
8775: sub show_course {
8776: my $course = !$env{'user.adv'};
8777: if (!$env{'user.adv'}) {
8778: foreach my $env (keys(%env)) {
8779: next if ($env !~ m/^user\.priv\./);
8780: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8781: $course = 0;
8782: last;
8783: }
8784: }
8785: }
8786: return $course;
8787: }
8788:
8789: ###############################################
8790:
8791: =pod
8792:
1.542 raeburn 8793: =item * &check_user_status()
1.274 raeburn 8794:
8795: Determines current status of supplied role for a
8796: specific user. Roles can be active, previous or future.
8797:
8798: Inputs:
8799: user's domain, user's username, course's domain,
1.375 raeburn 8800: course's number, optional section ID.
1.274 raeburn 8801:
8802: Outputs:
8803: role status: active, previous or future.
8804:
8805: =cut
8806:
8807: sub check_user_status {
1.412 raeburn 8808: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8809: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 8810: my @uroles = keys(%userinfo);
1.274 raeburn 8811: my $srchstr;
8812: my $active_chk = 'none';
1.412 raeburn 8813: my $now = time;
1.274 raeburn 8814: if (@uroles > 0) {
1.908 raeburn 8815: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8816: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8817: } else {
1.412 raeburn 8818: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8819: }
8820: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8821: my $role_end = 0;
8822: my $role_start = 0;
8823: $active_chk = 'active';
1.412 raeburn 8824: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8825: $role_end = $1;
8826: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8827: $role_start = $1;
1.274 raeburn 8828: }
8829: }
8830: if ($role_start > 0) {
1.412 raeburn 8831: if ($now < $role_start) {
1.274 raeburn 8832: $active_chk = 'future';
8833: }
8834: }
8835: if ($role_end > 0) {
1.412 raeburn 8836: if ($now > $role_end) {
1.274 raeburn 8837: $active_chk = 'previous';
8838: }
8839: }
8840: }
8841: }
8842: return $active_chk;
8843: }
8844:
8845: ###############################################
8846:
8847: =pod
8848:
1.405 albertel 8849: =item * &get_sections()
1.233 raeburn 8850:
8851: Determines all the sections for a course including
8852: sections with students and sections containing other roles.
1.419 raeburn 8853: Incoming parameters:
8854:
8855: 1. domain
8856: 2. course number
8857: 3. reference to array containing roles for which sections should
8858: be gathered (optional).
8859: 4. reference to array containing status types for which sections
8860: should be gathered (optional).
8861:
8862: If the third argument is undefined, sections are gathered for any role.
8863: If the fourth argument is undefined, sections are gathered for any status.
8864: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8865:
1.374 raeburn 8866: Returns section hash (keys are section IDs, values are
8867: number of users in each section), subject to the
1.419 raeburn 8868: optional roles filter, optional status filter
1.233 raeburn 8869:
8870: =cut
8871:
8872: ###############################################
8873: sub get_sections {
1.419 raeburn 8874: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8875: if (!defined($cdom) || !defined($cnum)) {
8876: my $cid = $env{'request.course.id'};
8877:
8878: return if (!defined($cid));
8879:
8880: $cdom = $env{'course.'.$cid.'.domain'};
8881: $cnum = $env{'course.'.$cid.'.num'};
8882: }
8883:
8884: my %sectioncount;
1.419 raeburn 8885: my $now = time;
1.240 albertel 8886:
1.1118 raeburn 8887: my $check_students = 1;
8888: my $only_students = 0;
8889: if (ref($possible_roles) eq 'ARRAY') {
8890: if (grep(/^st$/,@{$possible_roles})) {
8891: if (@{$possible_roles} == 1) {
8892: $only_students = 1;
8893: }
8894: } else {
8895: $check_students = 0;
8896: }
8897: }
8898:
8899: if ($check_students) {
1.276 albertel 8900: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8901: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8902: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8903: my $start_index = &Apache::loncoursedata::CL_START();
8904: my $end_index = &Apache::loncoursedata::CL_END();
8905: my $status;
1.366 albertel 8906: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8907: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8908: $data->[$status_index],
8909: $data->[$start_index],
8910: $data->[$end_index]);
8911: if ($stu_status eq 'Active') {
8912: $status = 'active';
8913: } elsif ($end < $now) {
8914: $status = 'previous';
8915: } elsif ($start > $now) {
8916: $status = 'future';
8917: }
8918: if ($section ne '-1' && $section !~ /^\s*$/) {
8919: if ((!defined($possible_status)) || (($status ne '') &&
8920: (grep/^\Q$status\E$/,@{$possible_status}))) {
8921: $sectioncount{$section}++;
8922: }
1.240 albertel 8923: }
8924: }
8925: }
1.1118 raeburn 8926: if ($only_students) {
8927: return %sectioncount;
8928: }
1.240 albertel 8929: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8930: foreach my $user (sort(keys(%courseroles))) {
8931: if ($user !~ /^(\w{2})/) { next; }
8932: my ($role) = ($user =~ /^(\w{2})/);
8933: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8934: my ($section,$status);
1.240 albertel 8935: if ($role eq 'cr' &&
8936: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8937: $section=$1;
8938: }
8939: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8940: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8941: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8942: if ($end == -1 && $start == -1) {
8943: next; #deleted role
8944: }
8945: if (!defined($possible_status)) {
8946: $sectioncount{$section}++;
8947: } else {
8948: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8949: $status = 'active';
8950: } elsif ($end < $now) {
8951: $status = 'future';
8952: } elsif ($start > $now) {
8953: $status = 'previous';
8954: }
8955: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8956: $sectioncount{$section}++;
8957: }
8958: }
1.233 raeburn 8959: }
1.366 albertel 8960: return %sectioncount;
1.233 raeburn 8961: }
8962:
1.274 raeburn 8963: ###############################################
1.294 raeburn 8964:
8965: =pod
1.405 albertel 8966:
8967: =item * &get_course_users()
8968:
1.275 raeburn 8969: Retrieves usernames:domains for users in the specified course
8970: with specific role(s), and access status.
8971:
8972: Incoming parameters:
1.277 albertel 8973: 1. course domain
8974: 2. course number
8975: 3. access status: users must have - either active,
1.275 raeburn 8976: previous, future, or all.
1.277 albertel 8977: 4. reference to array of permissible roles
1.288 raeburn 8978: 5. reference to array of section restrictions (optional)
8979: 6. reference to results object (hash of hashes).
8980: 7. reference to optional userdata hash
1.609 raeburn 8981: 8. reference to optional statushash
1.630 raeburn 8982: 9. flag if privileged users (except those set to unhide in
8983: course settings) should be excluded
1.609 raeburn 8984: Keys of top level results hash are roles.
1.275 raeburn 8985: Keys of inner hashes are username:domain, with
8986: values set to access type.
1.288 raeburn 8987: Optional userdata hash returns an array with arguments in the
8988: same order as loncoursedata::get_classlist() for student data.
8989:
1.609 raeburn 8990: Optional statushash returns
8991:
1.288 raeburn 8992: Entries for end, start, section and status are blank because
8993: of the possibility of multiple values for non-student roles.
8994:
1.275 raeburn 8995: =cut
1.405 albertel 8996:
1.275 raeburn 8997: ###############################################
1.405 albertel 8998:
1.275 raeburn 8999: sub get_course_users {
1.630 raeburn 9000: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9001: my %idx = ();
1.419 raeburn 9002: my %seclists;
1.288 raeburn 9003:
9004: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9005: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9006: $idx{end} = &Apache::loncoursedata::CL_END();
9007: $idx{start} = &Apache::loncoursedata::CL_START();
9008: $idx{id} = &Apache::loncoursedata::CL_ID();
9009: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9010: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9011: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9012:
1.290 albertel 9013: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9014: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9015: my $now = time;
1.277 albertel 9016: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9017: my $match = 0;
1.412 raeburn 9018: my $secmatch = 0;
1.419 raeburn 9019: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9020: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9021: if ($section eq '') {
9022: $section = 'none';
9023: }
1.291 albertel 9024: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9025: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9026: $secmatch = 1;
9027: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9028: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9029: $secmatch = 1;
9030: }
9031: } else {
1.419 raeburn 9032: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9033: $secmatch = 1;
9034: }
1.290 albertel 9035: }
1.412 raeburn 9036: if (!$secmatch) {
9037: next;
9038: }
1.419 raeburn 9039: }
1.275 raeburn 9040: if (defined($$types{'active'})) {
1.288 raeburn 9041: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9042: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9043: $match = 1;
1.275 raeburn 9044: }
9045: }
9046: if (defined($$types{'previous'})) {
1.609 raeburn 9047: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9048: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9049: $match = 1;
1.275 raeburn 9050: }
9051: }
9052: if (defined($$types{'future'})) {
1.609 raeburn 9053: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9054: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9055: $match = 1;
1.275 raeburn 9056: }
9057: }
1.609 raeburn 9058: if ($match) {
9059: push(@{$seclists{$student}},$section);
9060: if (ref($userdata) eq 'HASH') {
9061: $$userdata{$student} = $$classlist{$student};
9062: }
9063: if (ref($statushash) eq 'HASH') {
9064: $statushash->{$student}{'st'}{$section} = $status;
9065: }
1.288 raeburn 9066: }
1.275 raeburn 9067: }
9068: }
1.412 raeburn 9069: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9070: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9071: my $now = time;
1.609 raeburn 9072: my %displaystatus = ( previous => 'Expired',
9073: active => 'Active',
9074: future => 'Future',
9075: );
1.1121 raeburn 9076: my (%nothide,@possdoms);
1.630 raeburn 9077: if ($hidepriv) {
9078: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9079: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9080: if ($user !~ /:/) {
9081: $nothide{join(':',split(/[\@]/,$user))}=1;
9082: } else {
9083: $nothide{$user} = 1;
9084: }
9085: }
1.1121 raeburn 9086: my @possdoms = ($cdom);
9087: if ($coursehash{'checkforpriv'}) {
9088: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9089: }
1.630 raeburn 9090: }
1.439 raeburn 9091: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9092: my $match = 0;
1.412 raeburn 9093: my $secmatch = 0;
1.439 raeburn 9094: my $status;
1.412 raeburn 9095: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9096: $user =~ s/:$//;
1.439 raeburn 9097: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9098: if ($end == -1 || $start == -1) {
9099: next;
9100: }
9101: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9102: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9103: my ($uname,$udom) = split(/:/,$user);
9104: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9105: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9106: $secmatch = 1;
9107: } elsif ($usec eq '') {
1.420 albertel 9108: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9109: $secmatch = 1;
9110: }
9111: } else {
9112: if (grep(/^\Q$usec\E$/,@{$sections})) {
9113: $secmatch = 1;
9114: }
9115: }
9116: if (!$secmatch) {
9117: next;
9118: }
1.288 raeburn 9119: }
1.419 raeburn 9120: if ($usec eq '') {
9121: $usec = 'none';
9122: }
1.275 raeburn 9123: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9124: if ($hidepriv) {
1.1121 raeburn 9125: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9126: (!$nothide{$uname.':'.$udom})) {
9127: next;
9128: }
9129: }
1.503 raeburn 9130: if ($end > 0 && $end < $now) {
1.439 raeburn 9131: $status = 'previous';
9132: } elsif ($start > $now) {
9133: $status = 'future';
9134: } else {
9135: $status = 'active';
9136: }
1.277 albertel 9137: foreach my $type (keys(%{$types})) {
1.275 raeburn 9138: if ($status eq $type) {
1.420 albertel 9139: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9140: push(@{$$users{$role}{$user}},$type);
9141: }
1.288 raeburn 9142: $match = 1;
9143: }
9144: }
1.419 raeburn 9145: if (($match) && (ref($userdata) eq 'HASH')) {
9146: if (!exists($$userdata{$uname.':'.$udom})) {
9147: &get_user_info($udom,$uname,\%idx,$userdata);
9148: }
1.420 albertel 9149: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9150: push(@{$seclists{$uname.':'.$udom}},$usec);
9151: }
1.609 raeburn 9152: if (ref($statushash) eq 'HASH') {
9153: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9154: }
1.275 raeburn 9155: }
9156: }
9157: }
9158: }
1.290 albertel 9159: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9160: if ((defined($cdom)) && (defined($cnum))) {
9161: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9162: if ( defined($csettings{'internal.courseowner'}) ) {
9163: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9164: next if ($owner eq '');
9165: my ($ownername,$ownerdom);
9166: if ($owner =~ /^([^:]+):([^:]+)$/) {
9167: $ownername = $1;
9168: $ownerdom = $2;
9169: } else {
9170: $ownername = $owner;
9171: $ownerdom = $cdom;
9172: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9173: }
9174: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9175: if (defined($userdata) &&
1.609 raeburn 9176: !exists($$userdata{$owner})) {
9177: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9178: if (!grep(/^none$/,@{$seclists{$owner}})) {
9179: push(@{$seclists{$owner}},'none');
9180: }
9181: if (ref($statushash) eq 'HASH') {
9182: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9183: }
1.290 albertel 9184: }
1.279 raeburn 9185: }
9186: }
9187: }
1.419 raeburn 9188: foreach my $user (keys(%seclists)) {
9189: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9190: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9191: }
1.275 raeburn 9192: }
9193: return;
9194: }
9195:
1.288 raeburn 9196: sub get_user_info {
9197: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9198: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9199: &plainname($uname,$udom,'lastname');
1.291 albertel 9200: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9201: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9202: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9203: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9204: return;
9205: }
1.275 raeburn 9206:
1.472 raeburn 9207: ###############################################
9208:
9209: =pod
9210:
9211: =item * &get_user_quota()
9212:
1.1134 raeburn 9213: Retrieves quota assigned for storage of user files.
9214: Default is to report quota for portfolio files.
1.472 raeburn 9215:
9216: Incoming parameters:
9217: 1. user's username
9218: 2. user's domain
1.1134 raeburn 9219: 3. quota name - portfolio, author, or course
1.1136 raeburn 9220: (if no quota name provided, defaults to portfolio).
1.1165 raeburn 9221: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1136 raeburn 9222: course
1.472 raeburn 9223:
9224: Returns:
1.1163 raeburn 9225: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9226: 2. (Optional) Type of setting: custom or default
9227: (individually assigned or default for user's
9228: institutional status).
9229: 3. (Optional) - User's institutional status (e.g., faculty, staff
9230: or student - types as defined in localenroll::inst_usertypes
9231: for user's domain, which determines default quota for user.
9232: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9233:
9234: If a value has been stored in the user's environment,
1.536 raeburn 9235: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9236: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9237:
9238: =cut
9239:
9240: ###############################################
9241:
9242:
9243: sub get_user_quota {
1.1136 raeburn 9244: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9245: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9246: if (!defined($udom)) {
9247: $udom = $env{'user.domain'};
9248: }
9249: if (!defined($uname)) {
9250: $uname = $env{'user.name'};
9251: }
9252: if (($udom eq '' || $uname eq '') ||
9253: ($udom eq 'public') && ($uname eq 'public')) {
9254: $quota = 0;
1.536 raeburn 9255: $quotatype = 'default';
9256: $defquota = 0;
1.472 raeburn 9257: } else {
1.536 raeburn 9258: my $inststatus;
1.1134 raeburn 9259: if ($quotaname eq 'course') {
9260: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9261: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9262: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9263: } else {
9264: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9265: $quota = $cenv{'internal.uploadquota'};
9266: }
1.536 raeburn 9267: } else {
1.1134 raeburn 9268: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9269: if ($quotaname eq 'author') {
9270: $quota = $env{'environment.authorquota'};
9271: } else {
9272: $quota = $env{'environment.portfolioquota'};
9273: }
9274: $inststatus = $env{'environment.inststatus'};
9275: } else {
9276: my %userenv =
9277: &Apache::lonnet::get('environment',['portfolioquota',
9278: 'authorquota','inststatus'],$udom,$uname);
9279: my ($tmp) = keys(%userenv);
9280: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9281: if ($quotaname eq 'author') {
9282: $quota = $userenv{'authorquota'};
9283: } else {
9284: $quota = $userenv{'portfolioquota'};
9285: }
9286: $inststatus = $userenv{'inststatus'};
9287: } else {
9288: undef(%userenv);
9289: }
9290: }
9291: }
9292: if ($quota eq '' || wantarray) {
9293: if ($quotaname eq 'course') {
9294: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 9295: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9296: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1136 raeburn 9297: $defquota = $domdefs{$crstype.'quota'};
9298: }
9299: if ($defquota eq '') {
9300: $defquota = 500;
9301: }
1.1134 raeburn 9302: } else {
9303: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9304: }
9305: if ($quota eq '') {
9306: $quota = $defquota;
9307: $quotatype = 'default';
9308: } else {
9309: $quotatype = 'custom';
9310: }
1.472 raeburn 9311: }
9312: }
1.536 raeburn 9313: if (wantarray) {
9314: return ($quota,$quotatype,$settingstatus,$defquota);
9315: } else {
9316: return $quota;
9317: }
1.472 raeburn 9318: }
9319:
9320: ###############################################
9321:
9322: =pod
9323:
9324: =item * &default_quota()
9325:
1.536 raeburn 9326: Retrieves default quota assigned for storage of user portfolio files,
9327: given an (optional) user's institutional status.
1.472 raeburn 9328:
9329: Incoming parameters:
1.1142 raeburn 9330:
1.472 raeburn 9331: 1. domain
1.536 raeburn 9332: 2. (Optional) institutional status(es). This is a : separated list of
9333: status types (e.g., faculty, staff, student etc.)
9334: which apply to the user for whom the default is being retrieved.
9335: If the institutional status string in undefined, the domain
1.1134 raeburn 9336: default quota will be returned.
9337: 3. quota name - portfolio, author, or course
9338: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9339:
9340: Returns:
1.1142 raeburn 9341:
1.1163 raeburn 9342: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9343: 2. (Optional) institutional type which determined the value of the
9344: default quota.
1.472 raeburn 9345:
9346: If a value has been stored in the domain's configuration db,
9347: it will return that, otherwise it returns 20 (for backwards
9348: compatibility with domains which have not set up a configuration
1.1163 raeburn 9349: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9350:
1.536 raeburn 9351: If the user's status includes multiple types (e.g., staff and student),
9352: the largest default quota which applies to the user determines the
9353: default quota returned.
9354:
1.472 raeburn 9355: =cut
9356:
9357: ###############################################
9358:
9359:
9360: sub default_quota {
1.1134 raeburn 9361: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9362: my ($defquota,$settingstatus);
9363: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9364: ['quotas'],$udom);
1.1134 raeburn 9365: my $key = 'defaultquota';
9366: if ($quotaname eq 'author') {
9367: $key = 'authorquota';
9368: }
1.622 raeburn 9369: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9370: if ($inststatus ne '') {
1.765 raeburn 9371: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9372: foreach my $item (@statuses) {
1.1134 raeburn 9373: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9374: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9375: if ($defquota eq '') {
1.1134 raeburn 9376: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9377: $settingstatus = $item;
1.1134 raeburn 9378: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9379: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9380: $settingstatus = $item;
9381: }
9382: }
1.1134 raeburn 9383: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9384: if ($quotahash{'quotas'}{$item} ne '') {
9385: if ($defquota eq '') {
9386: $defquota = $quotahash{'quotas'}{$item};
9387: $settingstatus = $item;
9388: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9389: $defquota = $quotahash{'quotas'}{$item};
9390: $settingstatus = $item;
9391: }
1.536 raeburn 9392: }
9393: }
9394: }
9395: }
9396: if ($defquota eq '') {
1.1134 raeburn 9397: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9398: $defquota = $quotahash{'quotas'}{$key}{'default'};
9399: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9400: $defquota = $quotahash{'quotas'}{'default'};
9401: }
1.536 raeburn 9402: $settingstatus = 'default';
1.1139 raeburn 9403: if ($defquota eq '') {
9404: if ($quotaname eq 'author') {
9405: $defquota = 500;
9406: }
9407: }
1.536 raeburn 9408: }
9409: } else {
9410: $settingstatus = 'default';
1.1134 raeburn 9411: if ($quotaname eq 'author') {
9412: $defquota = 500;
9413: } else {
9414: $defquota = 20;
9415: }
1.536 raeburn 9416: }
9417: if (wantarray) {
9418: return ($defquota,$settingstatus);
1.472 raeburn 9419: } else {
1.536 raeburn 9420: return $defquota;
1.472 raeburn 9421: }
9422: }
9423:
1.1135 raeburn 9424: ###############################################
9425:
9426: =pod
9427:
1.1136 raeburn 9428: =item * &excess_filesize_warning()
1.1135 raeburn 9429:
9430: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 9431: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 9432: space to be exceeded.
1.1136 raeburn 9433:
9434: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 9435: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 9436:
1.1165 raeburn 9437: Inputs: 7
1.1136 raeburn 9438: 1. username or coursenum
1.1135 raeburn 9439: 2. domain
1.1136 raeburn 9440: 3. context ('author' or 'course')
1.1135 raeburn 9441: 4. filename of file for which action is being requested
9442: 5. filesize (kB) of file
9443: 6. action being taken: copy or upload.
1.1165 raeburn 9444: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1135 raeburn 9445:
9446: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 9447: otherwise return null.
9448:
9449: =back
1.1135 raeburn 9450:
9451: =cut
9452:
1.1136 raeburn 9453: sub excess_filesize_warning {
1.1165 raeburn 9454: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 9455: my $current_disk_usage = 0;
1.1165 raeburn 9456: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 9457: if ($context eq 'author') {
9458: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9459: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9460: } else {
9461: foreach my $subdir ('docs','supplemental') {
9462: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9463: }
9464: }
1.1135 raeburn 9465: $disk_quota = int($disk_quota * 1000);
9466: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 9467: return '<p class="LC_warning">'.
1.1135 raeburn 9468: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 9469: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9470: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 9471: $disk_quota,$current_disk_usage).
9472: '</p>';
9473: }
9474: return;
9475: }
9476:
9477: ###############################################
9478:
9479:
1.1136 raeburn 9480:
9481:
1.384 raeburn 9482: sub get_secgrprole_info {
9483: my ($cdom,$cnum,$needroles,$type) = @_;
9484: my %sections_count = &get_sections($cdom,$cnum);
9485: my @sections = (sort {$a <=> $b} keys(%sections_count));
9486: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9487: my @groups = sort(keys(%curr_groups));
9488: my $allroles = [];
9489: my $rolehash;
9490: my $accesshash = {
9491: active => 'Currently has access',
9492: future => 'Will have future access',
9493: previous => 'Previously had access',
9494: };
9495: if ($needroles) {
9496: $rolehash = {'all' => 'all'};
1.385 albertel 9497: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9498: if (&Apache::lonnet::error(%user_roles)) {
9499: undef(%user_roles);
9500: }
9501: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9502: my ($role)=split(/\:/,$item,2);
9503: if ($role eq 'cr') { next; }
9504: if ($role =~ /^cr/) {
9505: $$rolehash{$role} = (split('/',$role))[3];
9506: } else {
9507: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9508: }
9509: }
9510: foreach my $key (sort(keys(%{$rolehash}))) {
9511: push(@{$allroles},$key);
9512: }
9513: push (@{$allroles},'st');
9514: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9515: }
9516: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9517: }
9518:
1.555 raeburn 9519: sub user_picker {
1.994 raeburn 9520: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9521: my $currdom = $dom;
9522: my %curr_selected = (
9523: srchin => 'dom',
1.580 raeburn 9524: srchby => 'lastname',
1.555 raeburn 9525: );
9526: my $srchterm;
1.625 raeburn 9527: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9528: if ($srch->{'srchby'} ne '') {
9529: $curr_selected{'srchby'} = $srch->{'srchby'};
9530: }
9531: if ($srch->{'srchin'} ne '') {
9532: $curr_selected{'srchin'} = $srch->{'srchin'};
9533: }
9534: if ($srch->{'srchtype'} ne '') {
9535: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9536: }
9537: if ($srch->{'srchdomain'} ne '') {
9538: $currdom = $srch->{'srchdomain'};
9539: }
9540: $srchterm = $srch->{'srchterm'};
9541: }
1.1222 damieng 9542: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9543: 'usr' => 'Search criteria',
1.563 raeburn 9544: 'doma' => 'Domain/institution to search',
1.558 albertel 9545: 'uname' => 'username',
9546: 'lastname' => 'last name',
1.555 raeburn 9547: 'lastfirst' => 'last name, first name',
1.558 albertel 9548: 'crs' => 'in this course',
1.576 raeburn 9549: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9550: 'alc' => 'all LON-CAPA',
1.573 raeburn 9551: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9552: 'exact' => 'is',
9553: 'contains' => 'contains',
1.569 raeburn 9554: 'begins' => 'begins with',
1.1222 damieng 9555: );
9556: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9557: 'youm' => "You must include some text to search for.",
9558: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9559: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9560: 'yomc' => "You must choose a domain when using an institutional directory search.",
9561: 'ymcd' => "You must choose a domain when using a domain search.",
9562: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9563: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9564: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9565: );
1.1222 damieng 9566: &html_escape(\%html_lt);
9567: &js_escape(\%js_lt);
1.563 raeburn 9568: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9569: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9570:
9571: my @srchins = ('crs','dom','alc','instd');
9572:
9573: foreach my $option (@srchins) {
9574: # FIXME 'alc' option unavailable until
9575: # loncreateuser::print_user_query_page()
9576: # has been completed.
9577: next if ($option eq 'alc');
1.880 raeburn 9578: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9579: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9580: if ($curr_selected{'srchin'} eq $option) {
9581: $srchinsel .= '
1.1222 damieng 9582: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9583: } else {
9584: $srchinsel .= '
1.1222 damieng 9585: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9586: }
1.555 raeburn 9587: }
1.563 raeburn 9588: $srchinsel .= "\n </select>\n";
1.555 raeburn 9589:
9590: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9591: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9592: if ($curr_selected{'srchby'} eq $option) {
9593: $srchbysel .= '
1.1222 damieng 9594: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9595: } else {
9596: $srchbysel .= '
1.1222 damieng 9597: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9598: }
9599: }
9600: $srchbysel .= "\n </select>\n";
9601:
9602: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9603: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9604: if ($curr_selected{'srchtype'} eq $option) {
9605: $srchtypesel .= '
1.1222 damieng 9606: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9607: } else {
9608: $srchtypesel .= '
1.1222 damieng 9609: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9610: }
9611: }
9612: $srchtypesel .= "\n </select>\n";
9613:
1.558 albertel 9614: my ($newuserscript,$new_user_create);
1.994 raeburn 9615: my $context_dom = $env{'request.role.domain'};
9616: if ($context eq 'requestcrs') {
9617: if ($env{'form.coursedom'} ne '') {
9618: $context_dom = $env{'form.coursedom'};
9619: }
9620: }
1.556 raeburn 9621: if ($forcenewuser) {
1.576 raeburn 9622: if (ref($srch) eq 'HASH') {
1.994 raeburn 9623: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9624: if ($cancreate) {
9625: $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>';
9626: } else {
1.799 bisitz 9627: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9628: my %usertypetext = (
9629: official => 'institutional',
9630: unofficial => 'non-institutional',
9631: );
1.799 bisitz 9632: $new_user_create = '<p class="LC_warning">'
9633: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9634: .' '
9635: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9636: ,'<a href="'.$helplink.'">','</a>')
9637: .'</p><br />';
1.627 raeburn 9638: }
1.576 raeburn 9639: }
9640: }
9641:
1.556 raeburn 9642: $newuserscript = <<"ENDSCRIPT";
9643:
1.570 raeburn 9644: function setSearch(createnew,callingForm) {
1.556 raeburn 9645: if (createnew == 1) {
1.570 raeburn 9646: for (var i=0; i<callingForm.srchby.length; i++) {
9647: if (callingForm.srchby.options[i].value == 'uname') {
9648: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9649: }
9650: }
1.570 raeburn 9651: for (var i=0; i<callingForm.srchin.length; i++) {
9652: if ( callingForm.srchin.options[i].value == 'dom') {
9653: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9654: }
9655: }
1.570 raeburn 9656: for (var i=0; i<callingForm.srchtype.length; i++) {
9657: if (callingForm.srchtype.options[i].value == 'exact') {
9658: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9659: }
9660: }
1.570 raeburn 9661: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9662: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9663: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9664: }
9665: }
9666: }
9667: }
9668: ENDSCRIPT
1.558 albertel 9669:
1.556 raeburn 9670: }
9671:
1.555 raeburn 9672: my $output = <<"END_BLOCK";
1.556 raeburn 9673: <script type="text/javascript">
1.824 bisitz 9674: // <![CDATA[
1.570 raeburn 9675: function validateEntry(callingForm) {
1.558 albertel 9676:
1.556 raeburn 9677: var checkok = 1;
1.558 albertel 9678: var srchin;
1.570 raeburn 9679: for (var i=0; i<callingForm.srchin.length; i++) {
9680: if ( callingForm.srchin[i].checked ) {
9681: srchin = callingForm.srchin[i].value;
1.558 albertel 9682: }
9683: }
9684:
1.570 raeburn 9685: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9686: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9687: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9688: var srchterm = callingForm.srchterm.value;
9689: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9690: var msg = "";
9691:
9692: if (srchterm == "") {
9693: checkok = 0;
1.1222 damieng 9694: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9695: }
9696:
1.569 raeburn 9697: if (srchtype== 'begins') {
9698: if (srchterm.length < 2) {
9699: checkok = 0;
1.1222 damieng 9700: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9701: }
9702: }
9703:
1.556 raeburn 9704: if (srchtype== 'contains') {
9705: if (srchterm.length < 3) {
9706: checkok = 0;
1.1222 damieng 9707: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 9708: }
9709: }
9710: if (srchin == 'instd') {
9711: if (srchdomain == '') {
9712: checkok = 0;
1.1222 damieng 9713: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 9714: }
9715: }
9716: if (srchin == 'dom') {
9717: if (srchdomain == '') {
9718: checkok = 0;
1.1222 damieng 9719: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 9720: }
9721: }
9722: if (srchby == 'lastfirst') {
9723: if (srchterm.indexOf(",") == -1) {
9724: checkok = 0;
1.1222 damieng 9725: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 9726: }
9727: if (srchterm.indexOf(",") == srchterm.length -1) {
9728: checkok = 0;
1.1222 damieng 9729: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 9730: }
9731: }
9732: if (checkok == 0) {
1.1222 damieng 9733: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 9734: return;
9735: }
9736: if (checkok == 1) {
1.570 raeburn 9737: callingForm.submit();
1.556 raeburn 9738: }
9739: }
9740:
9741: $newuserscript
9742:
1.824 bisitz 9743: // ]]>
1.556 raeburn 9744: </script>
1.558 albertel 9745:
9746: $new_user_create
9747:
1.555 raeburn 9748: END_BLOCK
1.558 albertel 9749:
1.876 raeburn 9750: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 9751: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 9752: $domform.
9753: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 9754: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 9755: $srchbysel.
9756: $srchtypesel.
9757: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9758: $srchinsel.
9759: &Apache::lonhtmlcommon::row_closure(1).
9760: &Apache::lonhtmlcommon::end_pick_box().
9761: '<br />';
1.555 raeburn 9762: return $output;
9763: }
9764:
1.612 raeburn 9765: sub user_rule_check {
1.615 raeburn 9766: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 ! raeburn 9767: my ($response,%inst_response);
1.612 raeburn 9768: if (ref($usershash) eq 'HASH') {
1.1226 ! raeburn 9769: if (keys(%{$usershash}) > 1) {
! 9770: my (%by_username,%by_id,%userdoms);
! 9771: my $checkid;
! 9772: if (ref($checks) eq 'HASH') {
! 9773: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
! 9774: $checkid = 1;
! 9775: }
! 9776: }
! 9777: foreach my $user (keys(%{$usershash})) {
! 9778: my ($uname,$udom) = split(/:/,$user);
! 9779: if ($checkid) {
! 9780: if (ref($usershash->{$user}) eq 'HASH') {
! 9781: if ($usershash->{$user}->{'id'} ne '') {
! 9782: $by_id{$udom}{$usershash->{$user}->{'id'}} = 1;
! 9783: $userdoms{$udom} = 1;
! 9784: }
! 9785: }
! 9786: } else {
! 9787: $by_username{$udom}{$uname} = 1;
! 9788: $userdoms{$udom} = 1;
! 9789: }
! 9790: }
! 9791: foreach my $udom (keys(%userdoms)) {
! 9792: if (!$got_rules->{$udom}) {
! 9793: my %domconfig = &Apache::lonnet::get_dom('configuration',
! 9794: ['usercreation'],$udom);
! 9795: if (ref($domconfig{'usercreation'}) eq 'HASH') {
! 9796: foreach my $item ('username','id') {
! 9797: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
! 9798: $$curr_rules{$udom}{$item} =
! 9799: $domconfig{'usercreation'}{$item.'_rule'};
! 9800: }
! 9801: }
! 9802: }
! 9803: $got_rules->{$udom} = 1;
! 9804: }
1.612 raeburn 9805: }
1.1226 ! raeburn 9806: if ($checkid) {
! 9807: foreach my $udom (keys(%by_id)) {
! 9808: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
! 9809: if ($outcome eq 'ok') {
! 9810: if (ref($results) eq 'HASH') {
! 9811: foreach my $uname (keys(%{$results})) {
! 9812: $inst_response{$uname.':'.$udom} = $outcome;
! 9813: $inst_results->{$uname.':'.$udom} = $results->{$uname};
! 9814: }
! 9815: }
! 9816: }
1.612 raeburn 9817: }
1.615 raeburn 9818: } else {
1.1226 ! raeburn 9819: foreach my $udom (keys(%by_username)) {
! 9820: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
! 9821: if ($outcome eq 'ok') {
! 9822: if (ref($results) eq 'HASH') {
! 9823: foreach my $uname (keys(%{$results})) {
! 9824: $inst_response{$uname.':'.$udom} = $outcome;
! 9825: $inst_results->{$uname.':'.$udom} = $results->{$uname};
! 9826: }
! 9827: }
! 9828: }
! 9829: }
1.612 raeburn 9830: }
1.1226 ! raeburn 9831: } elsif (keys(%{$usershash}) == 1) {
! 9832: my $user = (keys(%{$usershash}))[0];
! 9833: my ($uname,$udom) = split(/:/,$user);
! 9834: if (($udom ne '') && ($uname ne '')) {
! 9835: if (ref($usershash->{$user}) eq 'HASH') {
! 9836: if (ref($checks) eq 'HASH') {
! 9837: if (defined($checks->{'username'})) {
! 9838: ($inst_response{$user},%{$inst_results->{$user}}) =
! 9839: &Apache::lonnet::get_instuser($udom,$uname);
! 9840: } elsif (defined($checks->{'id'})) {
! 9841: if ($usershash->{$user}->{'id'} ne '') {
! 9842: ($inst_response{$user},%{$inst_results->{$user}}) =
! 9843: &Apache::lonnet::get_instuser($udom,undef,
! 9844: $usershash->{$user}->{'id'});
! 9845: } else {
! 9846: ($inst_response{$user},%{$inst_results->{$user}}) =
! 9847: &Apache::lonnet::get_instuser($udom,$uname);
! 9848: }
1.585 raeburn 9849: }
1.1226 ! raeburn 9850: } else {
! 9851: ($inst_response{$user},%{$inst_results->{$user}}) =
! 9852: &Apache::lonnet::get_instuser($udom,$uname);
! 9853: return;
! 9854: }
! 9855: if (!$got_rules->{$udom}) {
! 9856: my %domconfig = &Apache::lonnet::get_dom('configuration',
! 9857: ['usercreation'],$udom);
! 9858: if (ref($domconfig{'usercreation'}) eq 'HASH') {
! 9859: foreach my $item ('username','id') {
! 9860: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
! 9861: $$curr_rules{$udom}{$item} =
! 9862: $domconfig{'usercreation'}{$item.'_rule'};
! 9863: }
! 9864: }
! 9865: }
! 9866: $got_rules->{$udom} = 1;
1.585 raeburn 9867: }
9868: }
1.1226 ! raeburn 9869: } else {
! 9870: return;
! 9871: }
! 9872: } else {
! 9873: return;
! 9874: }
! 9875: foreach my $user (keys(%{$usershash})) {
! 9876: my ($uname,$udom) = split(/:/,$user);
! 9877: next if (($udom eq '') || ($uname eq ''));
! 9878: my $id;
! 9879: if (ref($usershash->{$user})) {
! 9880: $id = $usershash->{$user}->{'id'};
1.585 raeburn 9881: }
1.612 raeburn 9882: foreach my $item (keys(%{$checks})) {
9883: if (ref($$curr_rules{$udom}) eq 'HASH') {
9884: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9885: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 ! raeburn 9886: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
! 9887: $$curr_rules{$udom}{$item});
1.612 raeburn 9888: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9889: if ($rule_check{$rule}) {
9890: $$rulematch{$user}{$item} = $rule;
1.1226 ! raeburn 9891: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 9892: if (ref($inst_results) eq 'HASH') {
9893: if (ref($inst_results->{$user}) eq 'HASH') {
9894: if (keys(%{$inst_results->{$user}}) == 0) {
9895: $$alerts{$item}{$udom}{$uname} = 1;
9896: }
1.612 raeburn 9897: }
9898: }
1.615 raeburn 9899: }
9900: last;
1.585 raeburn 9901: }
9902: }
9903: }
9904: }
9905: }
9906: }
9907: }
9908: }
1.612 raeburn 9909: return;
9910: }
9911:
9912: sub user_rule_formats {
9913: my ($domain,$domdesc,$curr_rules,$check) = @_;
9914: my %text = (
9915: 'username' => 'Usernames',
9916: 'id' => 'IDs',
9917: );
9918: my $output;
9919: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9920: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9921: if (@{$ruleorder} > 0) {
1.1102 raeburn 9922: $output = '<br />'.
9923: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9924: '<span class="LC_cusr_emph">','</span>',$domdesc).
9925: ' <ul>';
1.612 raeburn 9926: foreach my $rule (@{$ruleorder}) {
9927: if (ref($curr_rules) eq 'ARRAY') {
9928: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9929: if (ref($rules->{$rule}) eq 'HASH') {
9930: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9931: $rules->{$rule}{'desc'}.'</li>';
9932: }
9933: }
9934: }
9935: }
9936: $output .= '</ul>';
9937: }
9938: }
9939: return $output;
9940: }
9941:
9942: sub instrule_disallow_msg {
1.615 raeburn 9943: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9944: my $response;
9945: my %text = (
9946: item => 'username',
9947: items => 'usernames',
9948: match => 'matches',
9949: do => 'does',
9950: action => 'a username',
9951: one => 'one',
9952: );
9953: if ($count > 1) {
9954: $text{'item'} = 'usernames';
9955: $text{'match'} ='match';
9956: $text{'do'} = 'do';
9957: $text{'action'} = 'usernames',
9958: $text{'one'} = 'ones';
9959: }
9960: if ($checkitem eq 'id') {
9961: $text{'items'} = 'IDs';
9962: $text{'item'} = 'ID';
9963: $text{'action'} = 'an ID';
1.615 raeburn 9964: if ($count > 1) {
9965: $text{'item'} = 'IDs';
9966: $text{'action'} = 'IDs';
9967: }
1.612 raeburn 9968: }
1.674 bisitz 9969: $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 9970: if ($mode eq 'upload') {
9971: if ($checkitem eq 'username') {
9972: $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'}.");
9973: } elsif ($checkitem eq 'id') {
1.674 bisitz 9974: $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 9975: }
1.669 raeburn 9976: } elsif ($mode eq 'selfcreate') {
9977: if ($checkitem eq 'id') {
9978: $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.");
9979: }
1.615 raeburn 9980: } else {
9981: if ($checkitem eq 'username') {
9982: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9983: } elsif ($checkitem eq 'id') {
9984: $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.");
9985: }
1.612 raeburn 9986: }
9987: return $response;
1.585 raeburn 9988: }
9989:
1.624 raeburn 9990: sub personal_data_fieldtitles {
9991: my %fieldtitles = &Apache::lonlocal::texthash (
9992: id => 'Student/Employee ID',
9993: permanentemail => 'E-mail address',
9994: lastname => 'Last Name',
9995: firstname => 'First Name',
9996: middlename => 'Middle Name',
9997: generation => 'Generation',
9998: gen => 'Generation',
1.765 raeburn 9999: inststatus => 'Affiliation',
1.624 raeburn 10000: );
10001: return %fieldtitles;
10002: }
10003:
1.642 raeburn 10004: sub sorted_inst_types {
10005: my ($dom) = @_;
1.1185 raeburn 10006: my ($usertypes,$order);
10007: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10008: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10009: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10010: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10011: } else {
10012: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10013: }
1.642 raeburn 10014: my $othertitle = &mt('All users');
10015: if ($env{'request.course.id'}) {
1.668 raeburn 10016: $othertitle = &mt('Any users');
1.642 raeburn 10017: }
10018: my @types;
10019: if (ref($order) eq 'ARRAY') {
10020: @types = @{$order};
10021: }
10022: if (@types == 0) {
10023: if (ref($usertypes) eq 'HASH') {
10024: @types = sort(keys(%{$usertypes}));
10025: }
10026: }
10027: if (keys(%{$usertypes}) > 0) {
10028: $othertitle = &mt('Other users');
10029: }
10030: return ($othertitle,$usertypes,\@types);
10031: }
10032:
1.645 raeburn 10033: sub get_institutional_codes {
10034: my ($settings,$allcourses,$LC_code) = @_;
10035: # Get complete list of course sections to update
10036: my @currsections = ();
10037: my @currxlists = ();
10038: my $coursecode = $$settings{'internal.coursecode'};
10039:
10040: if ($$settings{'internal.sectionnums'} ne '') {
10041: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10042: }
10043:
10044: if ($$settings{'internal.crosslistings'} ne '') {
10045: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10046: }
10047:
10048: if (@currxlists > 0) {
10049: foreach (@currxlists) {
10050: if (m/^([^:]+):(\w*)$/) {
10051: unless (grep/^$1$/,@{$allcourses}) {
10052: push @{$allcourses},$1;
10053: $$LC_code{$1} = $2;
10054: }
10055: }
10056: }
10057: }
10058:
10059: if (@currsections > 0) {
10060: foreach (@currsections) {
10061: if (m/^(\w+):(\w*)$/) {
10062: my $sec = $coursecode.$1;
10063: my $lc_sec = $2;
10064: unless (grep/^$sec$/,@{$allcourses}) {
10065: push @{$allcourses},$sec;
10066: $$LC_code{$sec} = $lc_sec;
10067: }
10068: }
10069: }
10070: }
10071: return;
10072: }
10073:
1.971 raeburn 10074: sub get_standard_codeitems {
10075: return ('Year','Semester','Department','Number','Section');
10076: }
10077:
1.112 bowersj2 10078: =pod
10079:
1.780 raeburn 10080: =head1 Slot Helpers
10081:
10082: =over 4
10083:
10084: =item * sorted_slots()
10085:
1.1040 raeburn 10086: Sorts an array of slot names in order of an optional sort key,
10087: default sort is by slot start time (earliest first).
1.780 raeburn 10088:
10089: Inputs:
10090:
10091: =over 4
10092:
10093: slotsarr - Reference to array of unsorted slot names.
10094:
10095: slots - Reference to hash of hash, where outer hash keys are slot names.
10096:
1.1040 raeburn 10097: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10098:
1.549 albertel 10099: =back
10100:
1.780 raeburn 10101: Returns:
10102:
10103: =over 4
10104:
1.1040 raeburn 10105: sorted - An array of slot names sorted by a specified sort key
10106: (default sort key is start time of the slot).
1.780 raeburn 10107:
10108: =back
10109:
10110: =cut
10111:
10112:
10113: sub sorted_slots {
1.1040 raeburn 10114: my ($slotsarr,$slots,$sortkey) = @_;
10115: if ($sortkey eq '') {
10116: $sortkey = 'starttime';
10117: }
1.780 raeburn 10118: my @sorted;
10119: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10120: @sorted =
10121: sort {
10122: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10123: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10124: }
10125: if (ref($slots->{$a})) { return -1;}
10126: if (ref($slots->{$b})) { return 1;}
10127: return 0;
10128: } @{$slotsarr};
10129: }
10130: return @sorted;
10131: }
10132:
1.1040 raeburn 10133: =pod
10134:
10135: =item * get_future_slots()
10136:
10137: Inputs:
10138:
10139: =over 4
10140:
10141: cnum - course number
10142:
10143: cdom - course domain
10144:
10145: now - current UNIX time
10146:
10147: symb - optional symb
10148:
10149: =back
10150:
10151: Returns:
10152:
10153: =over 4
10154:
10155: sorted_reservable - ref to array of student_schedulable slots currently
10156: reservable, ordered by end date of reservation period.
10157:
10158: reservable_now - ref to hash of student_schedulable slots currently
10159: reservable.
10160:
10161: Keys in inner hash are:
10162: (a) symb: either blank or symb to which slot use is restricted.
10163: (b) endreserve: end date of reservation period.
10164:
10165: sorted_future - ref to array of student_schedulable slots reservable in
10166: the future, ordered by start date of reservation period.
10167:
10168: future_reservable - ref to hash of student_schedulable slots reservable
10169: in the future.
10170:
10171: Keys in inner hash are:
10172: (a) symb: either blank or symb to which slot use is restricted.
10173: (b) startreserve: start date of reservation period.
10174:
10175: =back
10176:
10177: =cut
10178:
10179: sub get_future_slots {
10180: my ($cnum,$cdom,$now,$symb) = @_;
10181: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10182: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10183: foreach my $slot (keys(%slots)) {
10184: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10185: if ($symb) {
10186: next if (($slots{$slot}->{'symb'} ne '') &&
10187: ($slots{$slot}->{'symb'} ne $symb));
10188: }
10189: if (($slots{$slot}->{'starttime'} > $now) &&
10190: ($slots{$slot}->{'endtime'} > $now)) {
10191: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10192: my $userallowed = 0;
10193: if ($slots{$slot}->{'allowedsections'}) {
10194: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10195: if (!defined($env{'request.role.sec'})
10196: && grep(/^No section assigned$/,@allowed_sec)) {
10197: $userallowed=1;
10198: } else {
10199: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10200: $userallowed=1;
10201: }
10202: }
10203: unless ($userallowed) {
10204: if (defined($env{'request.course.groups'})) {
10205: my @groups = split(/:/,$env{'request.course.groups'});
10206: foreach my $group (@groups) {
10207: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10208: $userallowed=1;
10209: last;
10210: }
10211: }
10212: }
10213: }
10214: }
10215: if ($slots{$slot}->{'allowedusers'}) {
10216: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10217: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10218: if (grep(/^\Q$user\E$/,@allowed_users)) {
10219: $userallowed = 1;
10220: }
10221: }
10222: next unless($userallowed);
10223: }
10224: my $startreserve = $slots{$slot}->{'startreserve'};
10225: my $endreserve = $slots{$slot}->{'endreserve'};
10226: my $symb = $slots{$slot}->{'symb'};
10227: if (($startreserve < $now) &&
10228: (!$endreserve || $endreserve > $now)) {
10229: my $lastres = $endreserve;
10230: if (!$lastres) {
10231: $lastres = $slots{$slot}->{'starttime'};
10232: }
10233: $reservable_now{$slot} = {
10234: symb => $symb,
10235: endreserve => $lastres
10236: };
10237: } elsif (($startreserve > $now) &&
10238: (!$endreserve || $endreserve > $startreserve)) {
10239: $future_reservable{$slot} = {
10240: symb => $symb,
10241: startreserve => $startreserve
10242: };
10243: }
10244: }
10245: }
10246: my @unsorted_reservable = keys(%reservable_now);
10247: if (@unsorted_reservable > 0) {
10248: @sorted_reservable =
10249: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10250: }
10251: my @unsorted_future = keys(%future_reservable);
10252: if (@unsorted_future > 0) {
10253: @sorted_future =
10254: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10255: }
10256: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10257: }
1.780 raeburn 10258:
10259: =pod
10260:
1.1057 foxr 10261: =back
10262:
1.549 albertel 10263: =head1 HTTP Helpers
10264:
10265: =over 4
10266:
1.648 raeburn 10267: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10268:
1.258 albertel 10269: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10270: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10271: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10272:
10273: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10274: $possible_names is an ref to an array of form element names. As an example:
10275: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10276: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10277:
10278: =cut
1.1 albertel 10279:
1.6 albertel 10280: sub get_unprocessed_cgi {
1.25 albertel 10281: my ($query,$possible_names)= @_;
1.26 matthew 10282: # $Apache::lonxml::debug=1;
1.356 albertel 10283: foreach my $pair (split(/&/,$query)) {
10284: my ($name, $value) = split(/=/,$pair);
1.369 www 10285: $name = &unescape($name);
1.25 albertel 10286: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10287: $value =~ tr/+/ /;
10288: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10289: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10290: }
1.16 harris41 10291: }
1.6 albertel 10292: }
10293:
1.112 bowersj2 10294: =pod
10295:
1.648 raeburn 10296: =item * &cacheheader()
1.112 bowersj2 10297:
10298: returns cache-controlling header code
10299:
10300: =cut
10301:
1.7 albertel 10302: sub cacheheader {
1.258 albertel 10303: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10304: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10305: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10306: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10307: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10308: return $output;
1.7 albertel 10309: }
10310:
1.112 bowersj2 10311: =pod
10312:
1.648 raeburn 10313: =item * &no_cache($r)
1.112 bowersj2 10314:
10315: specifies header code to not have cache
10316:
10317: =cut
10318:
1.9 albertel 10319: sub no_cache {
1.216 albertel 10320: my ($r) = @_;
10321: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10322: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10323: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10324: $r->no_cache(1);
10325: $r->header_out("Expires" => $date);
10326: $r->header_out("Pragma" => "no-cache");
1.123 www 10327: }
10328:
10329: sub content_type {
1.181 albertel 10330: my ($r,$type,$charset) = @_;
1.299 foxr 10331: if ($r) {
10332: # Note that printout.pl calls this with undef for $r.
10333: &no_cache($r);
10334: }
1.258 albertel 10335: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10336: unless ($charset) {
10337: $charset=&Apache::lonlocal::current_encoding;
10338: }
10339: if ($charset) { $type.='; charset='.$charset; }
10340: if ($r) {
10341: $r->content_type($type);
10342: } else {
10343: print("Content-type: $type\n\n");
10344: }
1.9 albertel 10345: }
1.25 albertel 10346:
1.112 bowersj2 10347: =pod
10348:
1.648 raeburn 10349: =item * &add_to_env($name,$value)
1.112 bowersj2 10350:
1.258 albertel 10351: adds $name to the %env hash with value
1.112 bowersj2 10352: $value, if $name already exists, the entry is converted to an array
10353: reference and $value is added to the array.
10354:
10355: =cut
10356:
1.25 albertel 10357: sub add_to_env {
10358: my ($name,$value)=@_;
1.258 albertel 10359: if (defined($env{$name})) {
10360: if (ref($env{$name})) {
1.25 albertel 10361: #already have multiple values
1.258 albertel 10362: push(@{ $env{$name} },$value);
1.25 albertel 10363: } else {
10364: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10365: my $first=$env{$name};
10366: undef($env{$name});
10367: push(@{ $env{$name} },$first,$value);
1.25 albertel 10368: }
10369: } else {
1.258 albertel 10370: $env{$name}=$value;
1.25 albertel 10371: }
1.31 albertel 10372: }
1.149 albertel 10373:
10374: =pod
10375:
1.648 raeburn 10376: =item * &get_env_multiple($name)
1.149 albertel 10377:
1.258 albertel 10378: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10379: values may be defined and end up as an array ref.
10380:
10381: returns an array of values
10382:
10383: =cut
10384:
10385: sub get_env_multiple {
10386: my ($name) = @_;
10387: my @values;
1.258 albertel 10388: if (defined($env{$name})) {
1.149 albertel 10389: # exists is it an array
1.258 albertel 10390: if (ref($env{$name})) {
10391: @values=@{ $env{$name} };
1.149 albertel 10392: } else {
1.258 albertel 10393: $values[0]=$env{$name};
1.149 albertel 10394: }
10395: }
10396: return(@values);
10397: }
10398:
1.660 raeburn 10399: sub ask_for_embedded_content {
10400: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10401: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 10402: %currsubfile,%unused,$rem);
1.1071 raeburn 10403: my $counter = 0;
10404: my $numnew = 0;
1.987 raeburn 10405: my $numremref = 0;
10406: my $numinvalid = 0;
10407: my $numpathchg = 0;
10408: my $numexisting = 0;
1.1071 raeburn 10409: my $numunused = 0;
10410: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 10411: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10412: my $heading = &mt('Upload embedded files');
10413: my $buttontext = &mt('Upload');
10414:
1.1085 raeburn 10415: if ($env{'request.course.id'}) {
1.1123 raeburn 10416: if ($actionurl eq '/adm/dependencies') {
10417: $navmap = Apache::lonnavmaps::navmap->new();
10418: }
10419: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10420: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 10421: }
1.1123 raeburn 10422: if (($actionurl eq '/adm/portfolio') ||
10423: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10424: my $current_path='/';
10425: if ($env{'form.currentpath'}) {
10426: $current_path = $env{'form.currentpath'};
10427: }
10428: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 10429: $udom = $cdom;
10430: $uname = $cnum;
1.984 raeburn 10431: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10432: } else {
10433: $udom = $env{'user.domain'};
10434: $uname = $env{'user.name'};
10435: $url = '/userfiles/portfolio';
10436: }
1.987 raeburn 10437: $toplevel = $url.'/';
1.984 raeburn 10438: $url .= $current_path;
10439: $getpropath = 1;
1.987 raeburn 10440: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10441: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10442: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10443: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10444: $toplevel = $url;
1.984 raeburn 10445: if ($rest ne '') {
1.987 raeburn 10446: $url .= $rest;
10447: }
10448: } elsif ($actionurl eq '/adm/coursedocs') {
10449: if (ref($args) eq 'HASH') {
1.1071 raeburn 10450: $url = $args->{'docs_url'};
10451: $toplevel = $url;
1.1084 raeburn 10452: if ($args->{'context'} eq 'paste') {
10453: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10454: ($path) =
10455: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10456: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10457: $fileloc =~ s{^/}{};
10458: }
1.1071 raeburn 10459: }
1.1084 raeburn 10460: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 10461: if ($env{'request.course.id'} ne '') {
10462: if (ref($args) eq 'HASH') {
10463: $url = $args->{'docs_url'};
10464: $title = $args->{'docs_title'};
1.1126 raeburn 10465: $toplevel = $url;
10466: unless ($toplevel =~ m{^/}) {
10467: $toplevel = "/$url";
10468: }
1.1085 raeburn 10469: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 10470: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10471: $path = $1;
10472: } else {
10473: ($path) =
10474: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10475: }
1.1195 raeburn 10476: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10477: $fileloc = $toplevel;
10478: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10479: my ($udom,$uname,$fname) =
10480: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10481: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10482: } else {
10483: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10484: }
1.1071 raeburn 10485: $fileloc =~ s{^/}{};
10486: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10487: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10488: }
1.987 raeburn 10489: }
1.1123 raeburn 10490: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10491: $udom = $cdom;
10492: $uname = $cnum;
10493: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10494: $toplevel = $url;
10495: $path = $url;
10496: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10497: $fileloc =~ s{^/}{};
1.987 raeburn 10498: }
1.1126 raeburn 10499: foreach my $file (keys(%{$allfiles})) {
10500: my $embed_file;
10501: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10502: $embed_file = $1;
10503: } else {
10504: $embed_file = $file;
10505: }
1.1158 raeburn 10506: my ($absolutepath,$cleaned_file);
10507: if ($embed_file =~ m{^\w+://}) {
10508: $cleaned_file = $embed_file;
1.1147 raeburn 10509: $newfiles{$cleaned_file} = 1;
10510: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10511: } else {
1.1158 raeburn 10512: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10513: if ($embed_file =~ m{^/}) {
10514: $absolutepath = $embed_file;
10515: }
1.1147 raeburn 10516: if ($cleaned_file =~ m{/}) {
10517: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10518: $path = &check_for_traversal($path,$url,$toplevel);
10519: my $item = $fname;
10520: if ($path ne '') {
10521: $item = $path.'/'.$fname;
10522: $subdependencies{$path}{$fname} = 1;
10523: } else {
10524: $dependencies{$item} = 1;
10525: }
10526: if ($absolutepath) {
10527: $mapping{$item} = $absolutepath;
10528: } else {
10529: $mapping{$item} = $embed_file;
10530: }
10531: } else {
10532: $dependencies{$embed_file} = 1;
10533: if ($absolutepath) {
1.1147 raeburn 10534: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10535: } else {
1.1147 raeburn 10536: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10537: }
10538: }
1.984 raeburn 10539: }
10540: }
1.1071 raeburn 10541: my $dirptr = 16384;
1.984 raeburn 10542: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10543: $currsubfile{$path} = {};
1.1123 raeburn 10544: if (($actionurl eq '/adm/portfolio') ||
10545: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10546: my ($sublistref,$listerror) =
10547: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10548: if (ref($sublistref) eq 'ARRAY') {
10549: foreach my $line (@{$sublistref}) {
10550: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10551: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10552: }
1.984 raeburn 10553: }
1.987 raeburn 10554: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10555: if (opendir(my $dir,$url.'/'.$path)) {
10556: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10557: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10558: }
1.1084 raeburn 10559: } elsif (($actionurl eq '/adm/dependencies') ||
10560: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 10561: ($args->{'context'} eq 'paste')) ||
10562: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10563: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 10564: my $dir;
10565: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10566: $dir = $fileloc;
10567: } else {
10568: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10569: }
1.1071 raeburn 10570: if ($dir ne '') {
10571: my ($sublistref,$listerror) =
10572: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10573: if (ref($sublistref) eq 'ARRAY') {
10574: foreach my $line (@{$sublistref}) {
10575: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10576: undef,$mtime)=split(/\&/,$line,12);
10577: unless (($testdir&$dirptr) ||
10578: ($file_name =~ /^\.\.?$/)) {
10579: $currsubfile{$path}{$file_name} = [$size,$mtime];
10580: }
10581: }
10582: }
10583: }
1.984 raeburn 10584: }
10585: }
10586: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10587: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10588: my $item = $path.'/'.$file;
10589: unless ($mapping{$item} eq $item) {
10590: $pathchanges{$item} = 1;
10591: }
10592: $existing{$item} = 1;
10593: $numexisting ++;
10594: } else {
10595: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10596: }
10597: }
1.1071 raeburn 10598: if ($actionurl eq '/adm/dependencies') {
10599: foreach my $path (keys(%currsubfile)) {
10600: if (ref($currsubfile{$path}) eq 'HASH') {
10601: foreach my $file (keys(%{$currsubfile{$path}})) {
10602: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 10603: next if (($rem ne '') &&
10604: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10605: (ref($navmap) &&
10606: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10607: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10608: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10609: $unused{$path.'/'.$file} = 1;
10610: }
10611: }
10612: }
10613: }
10614: }
1.984 raeburn 10615: }
1.987 raeburn 10616: my %currfile;
1.1123 raeburn 10617: if (($actionurl eq '/adm/portfolio') ||
10618: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10619: my ($dirlistref,$listerror) =
10620: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10621: if (ref($dirlistref) eq 'ARRAY') {
10622: foreach my $line (@{$dirlistref}) {
10623: my ($file_name,$rest) = split(/\&/,$line,2);
10624: $currfile{$file_name} = 1;
10625: }
1.984 raeburn 10626: }
1.987 raeburn 10627: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10628: if (opendir(my $dir,$url)) {
1.987 raeburn 10629: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10630: map {$currfile{$_} = 1;} @dir_list;
10631: }
1.1084 raeburn 10632: } elsif (($actionurl eq '/adm/dependencies') ||
10633: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 10634: ($args->{'context'} eq 'paste')) ||
10635: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10636: if ($env{'request.course.id'} ne '') {
10637: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10638: if ($dir ne '') {
10639: my ($dirlistref,$listerror) =
10640: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10641: if (ref($dirlistref) eq 'ARRAY') {
10642: foreach my $line (@{$dirlistref}) {
10643: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10644: $size,undef,$mtime)=split(/\&/,$line,12);
10645: unless (($testdir&$dirptr) ||
10646: ($file_name =~ /^\.\.?$/)) {
10647: $currfile{$file_name} = [$size,$mtime];
10648: }
10649: }
10650: }
10651: }
10652: }
1.984 raeburn 10653: }
10654: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10655: if (exists($currfile{$file})) {
1.987 raeburn 10656: unless ($mapping{$file} eq $file) {
10657: $pathchanges{$file} = 1;
10658: }
10659: $existing{$file} = 1;
10660: $numexisting ++;
10661: } else {
1.984 raeburn 10662: $newfiles{$file} = 1;
10663: }
10664: }
1.1071 raeburn 10665: foreach my $file (keys(%currfile)) {
10666: unless (($file eq $filename) ||
10667: ($file eq $filename.'.bak') ||
10668: ($dependencies{$file})) {
1.1085 raeburn 10669: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 10670: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10671: next if (($rem ne '') &&
10672: (($env{"httpref.$rem".$file} ne '') ||
10673: (ref($navmap) &&
10674: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10675: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10676: ($navmap->getResourceByUrl($rem.$1)))))));
10677: }
1.1085 raeburn 10678: }
1.1071 raeburn 10679: $unused{$file} = 1;
10680: }
10681: }
1.1084 raeburn 10682: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10683: ($args->{'context'} eq 'paste')) {
10684: $counter = scalar(keys(%existing));
10685: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 10686: return ($output,$counter,$numpathchg,\%existing);
10687: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10688: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10689: $counter = scalar(keys(%existing));
10690: $numpathchg = scalar(keys(%pathchanges));
10691: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 10692: }
1.984 raeburn 10693: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10694: if ($actionurl eq '/adm/dependencies') {
10695: next if ($embed_file =~ m{^\w+://});
10696: }
1.660 raeburn 10697: $upload_output .= &start_data_table_row().
1.1123 raeburn 10698: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10699: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10700: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 10701: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10702: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10703: }
1.1123 raeburn 10704: $upload_output .= '</td>';
1.1071 raeburn 10705: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 10706: $upload_output.='<td align="right">'.
10707: '<span class="LC_info LC_fontsize_medium">'.
10708: &mt("URL points to web address").'</span>';
1.987 raeburn 10709: $numremref++;
1.660 raeburn 10710: } elsif ($args->{'error_on_invalid_names'}
10711: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 10712: $upload_output.='<td align="right"><span class="LC_warning">'.
10713: &mt('Invalid characters').'</span>';
1.987 raeburn 10714: $numinvalid++;
1.660 raeburn 10715: } else {
1.1123 raeburn 10716: $upload_output .= '<td>'.
10717: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10718: $embed_file,\%mapping,
1.1071 raeburn 10719: $allfiles,$codebase,'upload');
10720: $counter ++;
10721: $numnew ++;
1.987 raeburn 10722: }
10723: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10724: }
10725: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10726: if ($actionurl eq '/adm/dependencies') {
10727: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10728: $modify_output .= &start_data_table_row().
10729: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10730: '<img src="'.&icon($embed_file).'" border="0" />'.
10731: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10732: '<td>'.$size.'</td>'.
10733: '<td>'.$mtime.'</td>'.
10734: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10735: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10736: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10737: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10738: &embedded_file_element('upload_embedded',$counter,
10739: $embed_file,\%mapping,
10740: $allfiles,$codebase,'modify').
10741: '</div></td>'.
10742: &end_data_table_row()."\n";
10743: $counter ++;
10744: } else {
10745: $upload_output .= &start_data_table_row().
1.1123 raeburn 10746: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10747: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10748: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10749: &Apache::loncommon::end_data_table_row()."\n";
10750: }
10751: }
10752: my $delidx = $counter;
10753: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10754: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10755: $delete_output .= &start_data_table_row().
10756: '<td><img src="'.&icon($oldfile).'" />'.
10757: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10758: '<td>'.$size.'</td>'.
10759: '<td>'.$mtime.'</td>'.
10760: '<td><label><input type="checkbox" name="del_upload_dep" '.
10761: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10762: &embedded_file_element('upload_embedded',$delidx,
10763: $oldfile,\%mapping,$allfiles,
10764: $codebase,'delete').'</td>'.
10765: &end_data_table_row()."\n";
10766: $numunused ++;
10767: $delidx ++;
1.987 raeburn 10768: }
10769: if ($upload_output) {
10770: $upload_output = &start_data_table().
10771: $upload_output.
10772: &end_data_table()."\n";
10773: }
1.1071 raeburn 10774: if ($modify_output) {
10775: $modify_output = &start_data_table().
10776: &start_data_table_header_row().
10777: '<th>'.&mt('File').'</th>'.
10778: '<th>'.&mt('Size (KB)').'</th>'.
10779: '<th>'.&mt('Modified').'</th>'.
10780: '<th>'.&mt('Upload replacement?').'</th>'.
10781: &end_data_table_header_row().
10782: $modify_output.
10783: &end_data_table()."\n";
10784: }
10785: if ($delete_output) {
10786: $delete_output = &start_data_table().
10787: &start_data_table_header_row().
10788: '<th>'.&mt('File').'</th>'.
10789: '<th>'.&mt('Size (KB)').'</th>'.
10790: '<th>'.&mt('Modified').'</th>'.
10791: '<th>'.&mt('Delete?').'</th>'.
10792: &end_data_table_header_row().
10793: $delete_output.
10794: &end_data_table()."\n";
10795: }
1.987 raeburn 10796: my $applies = 0;
10797: if ($numremref) {
10798: $applies ++;
10799: }
10800: if ($numinvalid) {
10801: $applies ++;
10802: }
10803: if ($numexisting) {
10804: $applies ++;
10805: }
1.1071 raeburn 10806: if ($counter || $numunused) {
1.987 raeburn 10807: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10808: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10809: $state.'<h3>'.$heading.'</h3>';
10810: if ($actionurl eq '/adm/dependencies') {
10811: if ($numnew) {
10812: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10813: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10814: $upload_output.'<br />'."\n";
10815: }
10816: if ($numexisting) {
10817: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10818: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10819: $modify_output.'<br />'."\n";
10820: $buttontext = &mt('Save changes');
10821: }
10822: if ($numunused) {
10823: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10824: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10825: $delete_output.'<br />'."\n";
10826: $buttontext = &mt('Save changes');
10827: }
10828: } else {
10829: $output .= $upload_output.'<br />'."\n";
10830: }
10831: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10832: $counter.'" />'."\n";
10833: if ($actionurl eq '/adm/dependencies') {
10834: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10835: $numnew.'" />'."\n";
10836: } elsif ($actionurl eq '') {
1.987 raeburn 10837: $output .= '<input type="hidden" name="phase" value="three" />';
10838: }
10839: } elsif ($applies) {
10840: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10841: if ($applies > 1) {
10842: $output .=
1.1123 raeburn 10843: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10844: if ($numremref) {
10845: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10846: }
10847: if ($numinvalid) {
10848: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10849: }
10850: if ($numexisting) {
10851: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10852: }
10853: $output .= '</ul><br />';
10854: } elsif ($numremref) {
10855: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10856: } elsif ($numinvalid) {
10857: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10858: } elsif ($numexisting) {
10859: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10860: }
10861: $output .= $upload_output.'<br />';
10862: }
10863: my ($pathchange_output,$chgcount);
1.1071 raeburn 10864: $chgcount = $counter;
1.987 raeburn 10865: if (keys(%pathchanges) > 0) {
10866: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10867: if ($counter) {
1.987 raeburn 10868: $output .= &embedded_file_element('pathchange',$chgcount,
10869: $embed_file,\%mapping,
1.1071 raeburn 10870: $allfiles,$codebase,'change');
1.987 raeburn 10871: } else {
10872: $pathchange_output .=
10873: &start_data_table_row().
10874: '<td><input type ="checkbox" name="namechange" value="'.
10875: $chgcount.'" checked="checked" /></td>'.
10876: '<td>'.$mapping{$embed_file}.'</td>'.
10877: '<td>'.$embed_file.
10878: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10879: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10880: '</td>'.&end_data_table_row();
1.660 raeburn 10881: }
1.987 raeburn 10882: $numpathchg ++;
10883: $chgcount ++;
1.660 raeburn 10884: }
10885: }
1.1127 raeburn 10886: if (($counter) || ($numunused)) {
1.987 raeburn 10887: if ($numpathchg) {
10888: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10889: $numpathchg.'" />'."\n";
10890: }
10891: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10892: ($actionurl eq '/adm/imsimport')) {
10893: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10894: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10895: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10896: } elsif ($actionurl eq '/adm/dependencies') {
10897: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10898: }
1.1123 raeburn 10899: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10900: } elsif ($numpathchg) {
10901: my %pathchange = ();
10902: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10903: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10904: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 10905: }
1.987 raeburn 10906: }
1.1071 raeburn 10907: return ($output,$counter,$numpathchg);
1.987 raeburn 10908: }
10909:
1.1147 raeburn 10910: =pod
10911:
10912: =item * clean_path($name)
10913:
10914: Performs clean-up of directories, subdirectories and filename in an
10915: embedded object, referenced in an HTML file which is being uploaded
10916: to a course or portfolio, where
10917: "Upload embedded images/multimedia files if HTML file" checkbox was
10918: checked.
10919:
10920: Clean-up is similar to replacements in lonnet::clean_filename()
10921: except each / between sub-directory and next level is preserved.
10922:
10923: =cut
10924:
10925: sub clean_path {
10926: my ($embed_file) = @_;
10927: $embed_file =~s{^/+}{};
10928: my @contents;
10929: if ($embed_file =~ m{/}) {
10930: @contents = split(/\//,$embed_file);
10931: } else {
10932: @contents = ($embed_file);
10933: }
10934: my $lastidx = scalar(@contents)-1;
10935: for (my $i=0; $i<=$lastidx; $i++) {
10936: $contents[$i]=~s{\\}{/}g;
10937: $contents[$i]=~s/\s+/\_/g;
10938: $contents[$i]=~s{[^/\w\.\-]}{}g;
10939: if ($i == $lastidx) {
10940: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10941: }
10942: }
10943: if ($lastidx > 0) {
10944: return join('/',@contents);
10945: } else {
10946: return $contents[0];
10947: }
10948: }
10949:
1.987 raeburn 10950: sub embedded_file_element {
1.1071 raeburn 10951: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10952: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10953: (ref($codebase) eq 'HASH'));
10954: my $output;
1.1071 raeburn 10955: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10956: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10957: }
10958: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10959: &escape($embed_file).'" />';
10960: unless (($context eq 'upload_embedded') &&
10961: ($mapping->{$embed_file} eq $embed_file)) {
10962: $output .='
10963: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10964: }
10965: my $attrib;
10966: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10967: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10968: }
10969: $output .=
10970: "\n\t\t".
10971: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10972: $attrib.'" />';
10973: if (exists($codebase->{$mapping->{$embed_file}})) {
10974: $output .=
10975: "\n\t\t".
10976: '<input name="codebase_'.$num.'" type="hidden" value="'.
10977: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10978: }
1.987 raeburn 10979: return $output;
1.660 raeburn 10980: }
10981:
1.1071 raeburn 10982: sub get_dependency_details {
10983: my ($currfile,$currsubfile,$embed_file) = @_;
10984: my ($size,$mtime,$showsize,$showmtime);
10985: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10986: if ($embed_file =~ m{/}) {
10987: my ($path,$fname) = split(/\//,$embed_file);
10988: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10989: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10990: }
10991: } else {
10992: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10993: ($size,$mtime) = @{$currfile->{$embed_file}};
10994: }
10995: }
10996: $showsize = $size/1024.0;
10997: $showsize = sprintf("%.1f",$showsize);
10998: if ($mtime > 0) {
10999: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11000: }
11001: }
11002: return ($showsize,$showmtime);
11003: }
11004:
11005: sub ask_embedded_js {
11006: return <<"END";
11007: <script type="text/javascript"">
11008: // <![CDATA[
11009: function toggleBrowse(counter) {
11010: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11011: var fileid = document.getElementById('embedded_item_'+counter);
11012: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11013: if (chkboxid.checked == true) {
11014: uploaddivid.style.display='block';
11015: } else {
11016: uploaddivid.style.display='none';
11017: fileid.value = '';
11018: }
11019: }
11020: // ]]>
11021: </script>
11022:
11023: END
11024: }
11025:
1.661 raeburn 11026: sub upload_embedded {
11027: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11028: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11029: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11030: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11031: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11032: my $orig_uploaded_filename =
11033: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11034: foreach my $type ('orig','ref','attrib','codebase') {
11035: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11036: $env{'form.embedded_'.$type.'_'.$i} =
11037: &unescape($env{'form.embedded_'.$type.'_'.$i});
11038: }
11039: }
1.661 raeburn 11040: my ($path,$fname) =
11041: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11042: # no path, whole string is fname
11043: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11044: $fname = &Apache::lonnet::clean_filename($fname);
11045: # See if there is anything left
11046: next if ($fname eq '');
11047:
11048: # Check if file already exists as a file or directory.
11049: my ($state,$msg);
11050: if ($context eq 'portfolio') {
11051: my $port_path = $dirpath;
11052: if ($group ne '') {
11053: $port_path = "groups/$group/$port_path";
11054: }
1.987 raeburn 11055: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11056: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11057: $dir_root,$port_path,$disk_quota,
11058: $current_disk_usage,$uname,$udom);
11059: if ($state eq 'will_exceed_quota'
1.984 raeburn 11060: || $state eq 'file_locked') {
1.661 raeburn 11061: $output .= $msg;
11062: next;
11063: }
11064: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11065: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11066: if ($state eq 'exists') {
11067: $output .= $msg;
11068: next;
11069: }
11070: }
11071: # Check if extension is valid
11072: if (($fname =~ /\.(\w+)$/) &&
11073: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11074: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11075: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11076: next;
11077: } elsif (($fname =~ /\.(\w+)$/) &&
11078: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11079: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11080: next;
11081: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11082: $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 11083: next;
11084: }
11085: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11086: my $subdir = $path;
11087: $subdir =~ s{/+$}{};
1.661 raeburn 11088: if ($context eq 'portfolio') {
1.984 raeburn 11089: my $result;
11090: if ($state eq 'existingfile') {
11091: $result=
11092: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11093: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11094: } else {
1.984 raeburn 11095: $result=
11096: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11097: $dirpath.
1.1123 raeburn 11098: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11099: if ($result !~ m|^/uploaded/|) {
11100: $output .= '<span class="LC_error">'
11101: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11102: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11103: .'</span><br />';
11104: next;
11105: } else {
1.987 raeburn 11106: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11107: $path.$fname.'</span>').'<br />';
1.984 raeburn 11108: }
1.661 raeburn 11109: }
1.1123 raeburn 11110: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 11111: my $extendedsubdir = $dirpath.'/'.$subdir;
11112: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11113: my $result =
1.1126 raeburn 11114: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11115: if ($result !~ m|^/uploaded/|) {
11116: $output .= '<span class="LC_error">'
11117: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11118: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11119: .'</span><br />';
11120: next;
11121: } else {
11122: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11123: $path.$fname.'</span>').'<br />';
1.1125 raeburn 11124: if ($context eq 'syllabus') {
11125: &Apache::lonnet::make_public_indefinitely($result);
11126: }
1.987 raeburn 11127: }
1.661 raeburn 11128: } else {
11129: # Save the file
11130: my $target = $env{'form.embedded_item_'.$i};
11131: my $fullpath = $dir_root.$dirpath.'/'.$path;
11132: my $dest = $fullpath.$fname;
11133: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11134: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11135: my $count;
11136: my $filepath = $dir_root;
1.1027 raeburn 11137: foreach my $subdir (@parts) {
11138: $filepath .= "/$subdir";
11139: if (!-e $filepath) {
1.661 raeburn 11140: mkdir($filepath,0770);
11141: }
11142: }
11143: my $fh;
11144: if (!open($fh,'>'.$dest)) {
11145: &Apache::lonnet::logthis('Failed to create '.$dest);
11146: $output .= '<span class="LC_error">'.
1.1071 raeburn 11147: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11148: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11149: '</span><br />';
11150: } else {
11151: if (!print $fh $env{'form.embedded_item_'.$i}) {
11152: &Apache::lonnet::logthis('Failed to write to '.$dest);
11153: $output .= '<span class="LC_error">'.
1.1071 raeburn 11154: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11155: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11156: '</span><br />';
11157: } else {
1.987 raeburn 11158: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11159: $url.'</span>').'<br />';
11160: unless ($context eq 'testbank') {
11161: $footer .= &mt('View embedded file: [_1]',
11162: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11163: }
11164: }
11165: close($fh);
11166: }
11167: }
11168: if ($env{'form.embedded_ref_'.$i}) {
11169: $pathchange{$i} = 1;
11170: }
11171: }
11172: if ($output) {
11173: $output = '<p>'.$output.'</p>';
11174: }
11175: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11176: $returnflag = 'ok';
1.1071 raeburn 11177: my $numpathchgs = scalar(keys(%pathchange));
11178: if ($numpathchgs > 0) {
1.987 raeburn 11179: if ($context eq 'portfolio') {
11180: $output .= '<p>'.&mt('or').'</p>';
11181: } elsif ($context eq 'testbank') {
1.1071 raeburn 11182: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11183: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11184: $returnflag = 'modify_orightml';
11185: }
11186: }
1.1071 raeburn 11187: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11188: }
11189:
11190: sub modify_html_form {
11191: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11192: my $end = 0;
11193: my $modifyform;
11194: if ($context eq 'upload_embedded') {
11195: return unless (ref($pathchange) eq 'HASH');
11196: if ($env{'form.number_embedded_items'}) {
11197: $end += $env{'form.number_embedded_items'};
11198: }
11199: if ($env{'form.number_pathchange_items'}) {
11200: $end += $env{'form.number_pathchange_items'};
11201: }
11202: if ($end) {
11203: for (my $i=0; $i<$end; $i++) {
11204: if ($i < $env{'form.number_embedded_items'}) {
11205: next unless($pathchange->{$i});
11206: }
11207: $modifyform .=
11208: &start_data_table_row().
11209: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11210: 'checked="checked" /></td>'.
11211: '<td>'.$env{'form.embedded_ref_'.$i}.
11212: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11213: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11214: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11215: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11216: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11217: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11218: '<td>'.$env{'form.embedded_orig_'.$i}.
11219: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11220: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11221: &end_data_table_row();
1.1071 raeburn 11222: }
1.987 raeburn 11223: }
11224: } else {
11225: $modifyform = $pathchgtable;
11226: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11227: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11228: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11229: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11230: }
11231: }
11232: if ($modifyform) {
1.1071 raeburn 11233: if ($actionurl eq '/adm/dependencies') {
11234: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11235: }
1.987 raeburn 11236: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11237: '<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".
11238: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11239: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11240: '</ol></p>'."\n".'<p>'.
11241: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11242: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11243: &start_data_table()."\n".
11244: &start_data_table_header_row().
11245: '<th>'.&mt('Change?').'</th>'.
11246: '<th>'.&mt('Current reference').'</th>'.
11247: '<th>'.&mt('Required reference').'</th>'.
11248: &end_data_table_header_row()."\n".
11249: $modifyform.
11250: &end_data_table().'<br />'."\n".$hiddenstate.
11251: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11252: '</form>'."\n";
11253: }
11254: return;
11255: }
11256:
11257: sub modify_html_refs {
1.1123 raeburn 11258: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11259: my $container;
11260: if ($context eq 'portfolio') {
11261: $container = $env{'form.container'};
11262: } elsif ($context eq 'coursedoc') {
11263: $container = $env{'form.primaryurl'};
1.1071 raeburn 11264: } elsif ($context eq 'manage_dependencies') {
11265: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11266: $container = "/$container";
1.1123 raeburn 11267: } elsif ($context eq 'syllabus') {
11268: $container = $url;
1.987 raeburn 11269: } else {
1.1027 raeburn 11270: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11271: }
11272: my (%allfiles,%codebase,$output,$content);
11273: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 11274: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11275: if (wantarray) {
11276: return ('',0,0);
11277: } else {
11278: return;
11279: }
11280: }
11281: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11282: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11283: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11284: if (wantarray) {
11285: return ('',0,0);
11286: } else {
11287: return;
11288: }
11289: }
1.987 raeburn 11290: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11291: if ($content eq '-1') {
11292: if (wantarray) {
11293: return ('',0,0);
11294: } else {
11295: return;
11296: }
11297: }
1.987 raeburn 11298: } else {
1.1071 raeburn 11299: unless ($container =~ /^\Q$dir_root\E/) {
11300: if (wantarray) {
11301: return ('',0,0);
11302: } else {
11303: return;
11304: }
11305: }
1.987 raeburn 11306: if (open(my $fh,"<$container")) {
11307: $content = join('', <$fh>);
11308: close($fh);
11309: } else {
1.1071 raeburn 11310: if (wantarray) {
11311: return ('',0,0);
11312: } else {
11313: return;
11314: }
1.987 raeburn 11315: }
11316: }
11317: my ($count,$codebasecount) = (0,0);
11318: my $mm = new File::MMagic;
11319: my $mime_type = $mm->checktype_contents($content);
11320: if ($mime_type eq 'text/html') {
11321: my $parse_result =
11322: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11323: \%codebase,\$content);
11324: if ($parse_result eq 'ok') {
11325: foreach my $i (@changes) {
11326: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11327: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11328: if ($allfiles{$ref}) {
11329: my $newname = $orig;
11330: my ($attrib_regexp,$codebase);
1.1006 raeburn 11331: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11332: if ($attrib_regexp =~ /:/) {
11333: $attrib_regexp =~ s/\:/|/g;
11334: }
11335: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11336: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11337: $count += $numchg;
1.1123 raeburn 11338: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 11339: delete($allfiles{$ref});
1.987 raeburn 11340: }
11341: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11342: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11343: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11344: $codebasecount ++;
11345: }
11346: }
11347: }
1.1123 raeburn 11348: my $skiprewrites;
1.987 raeburn 11349: if ($count || $codebasecount) {
11350: my $saveresult;
1.1071 raeburn 11351: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11352: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11353: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11354: if ($url eq $container) {
11355: my ($fname) = ($container =~ m{/([^/]+)$});
11356: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11357: $count,'<span class="LC_filename">'.
1.1071 raeburn 11358: $fname.'</span>').'</p>';
1.987 raeburn 11359: } else {
11360: $output = '<p class="LC_error">'.
11361: &mt('Error: update failed for: [_1].',
11362: '<span class="LC_filename">'.
11363: $container.'</span>').'</p>';
11364: }
1.1123 raeburn 11365: if ($context eq 'syllabus') {
11366: unless ($saveresult eq 'ok') {
11367: $skiprewrites = 1;
11368: }
11369: }
1.987 raeburn 11370: } else {
11371: if (open(my $fh,">$container")) {
11372: print $fh $content;
11373: close($fh);
11374: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11375: $count,'<span class="LC_filename">'.
11376: $container.'</span>').'</p>';
1.661 raeburn 11377: } else {
1.987 raeburn 11378: $output = '<p class="LC_error">'.
11379: &mt('Error: could not update [_1].',
11380: '<span class="LC_filename">'.
11381: $container.'</span>').'</p>';
1.661 raeburn 11382: }
11383: }
11384: }
1.1123 raeburn 11385: if (($context eq 'syllabus') && (!$skiprewrites)) {
11386: my ($actionurl,$state);
11387: $actionurl = "/public/$udom/$uname/syllabus";
11388: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11389: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11390: \%codebase,
11391: {'context' => 'rewrites',
11392: 'ignore_remote_references' => 1,});
11393: if (ref($mapping) eq 'HASH') {
11394: my $rewrites = 0;
11395: foreach my $key (keys(%{$mapping})) {
11396: next if ($key =~ m{^https?://});
11397: my $ref = $mapping->{$key};
11398: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11399: my $attrib;
11400: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11401: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11402: }
11403: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11404: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11405: $rewrites += $numchg;
11406: }
11407: }
11408: if ($rewrites) {
11409: my $saveresult;
11410: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11411: if ($url eq $container) {
11412: my ($fname) = ($container =~ m{/([^/]+)$});
11413: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11414: $count,'<span class="LC_filename">'.
11415: $fname.'</span>').'</p>';
11416: } else {
11417: $output .= '<p class="LC_error">'.
11418: &mt('Error: could not update links in [_1].',
11419: '<span class="LC_filename">'.
11420: $container.'</span>').'</p>';
11421:
11422: }
11423: }
11424: }
11425: }
1.987 raeburn 11426: } else {
11427: &logthis('Failed to parse '.$container.
11428: ' to modify references: '.$parse_result);
1.661 raeburn 11429: }
11430: }
1.1071 raeburn 11431: if (wantarray) {
11432: return ($output,$count,$codebasecount);
11433: } else {
11434: return $output;
11435: }
1.661 raeburn 11436: }
11437:
11438: sub check_for_existing {
11439: my ($path,$fname,$element) = @_;
11440: my ($state,$msg);
11441: if (-d $path.'/'.$fname) {
11442: $state = 'exists';
11443: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11444: } elsif (-e $path.'/'.$fname) {
11445: $state = 'exists';
11446: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11447: }
11448: if ($state eq 'exists') {
11449: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11450: }
11451: return ($state,$msg);
11452: }
11453:
11454: sub check_for_upload {
11455: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11456: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11457: my $filesize = length($env{'form.'.$element});
11458: if (!$filesize) {
11459: my $msg = '<span class="LC_error">'.
11460: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11461: '<span class="LC_filename">'.$fname.'</span>',
11462: $filesize).'<br />'.
1.1007 raeburn 11463: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11464: '</span>';
11465: return ('zero_bytes',$msg);
11466: }
11467: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11468: my $getpropath = 1;
1.1021 raeburn 11469: my ($dirlistref,$listerror) =
11470: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11471: my $found_file = 0;
11472: my $locked_file = 0;
1.991 raeburn 11473: my @lockers;
11474: my $navmap;
11475: if ($env{'request.course.id'}) {
11476: $navmap = Apache::lonnavmaps::navmap->new();
11477: }
1.1021 raeburn 11478: if (ref($dirlistref) eq 'ARRAY') {
11479: foreach my $line (@{$dirlistref}) {
11480: my ($file_name,$rest)=split(/\&/,$line,2);
11481: if ($file_name eq $fname){
11482: $file_name = $path.$file_name;
11483: if ($group ne '') {
11484: $file_name = $group.$file_name;
11485: }
11486: $found_file = 1;
11487: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11488: foreach my $lock (@lockers) {
11489: if (ref($lock) eq 'ARRAY') {
11490: my ($symb,$crsid) = @{$lock};
11491: if ($crsid eq $env{'request.course.id'}) {
11492: if (ref($navmap)) {
11493: my $res = $navmap->getBySymb($symb);
11494: foreach my $part (@{$res->parts()}) {
11495: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11496: unless (($slot_status == $res->RESERVED) ||
11497: ($slot_status == $res->RESERVED_LOCATION)) {
11498: $locked_file = 1;
11499: }
1.991 raeburn 11500: }
1.1021 raeburn 11501: } else {
11502: $locked_file = 1;
1.991 raeburn 11503: }
11504: } else {
11505: $locked_file = 1;
11506: }
11507: }
1.1021 raeburn 11508: }
11509: } else {
11510: my @info = split(/\&/,$rest);
11511: my $currsize = $info[6]/1000;
11512: if ($currsize < $filesize) {
11513: my $extra = $filesize - $currsize;
11514: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 11515: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11516: &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 11517: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11518: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11519: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11520: return ('will_exceed_quota',$msg);
11521: }
1.984 raeburn 11522: }
11523: }
1.661 raeburn 11524: }
11525: }
11526: }
11527: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 11528: my $msg = '<p class="LC_warning">'.
11529: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 11530: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11531: return ('will_exceed_quota',$msg);
11532: } elsif ($found_file) {
11533: if ($locked_file) {
1.1179 bisitz 11534: my $msg = '<p class="LC_warning">';
1.661 raeburn 11535: $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 11536: $msg .= '</p>';
1.661 raeburn 11537: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11538: return ('file_locked',$msg);
11539: } else {
1.1179 bisitz 11540: my $msg = '<p class="LC_error">';
1.984 raeburn 11541: $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 11542: $msg .= '</p>';
1.984 raeburn 11543: return ('existingfile',$msg);
1.661 raeburn 11544: }
11545: }
11546: }
11547:
1.987 raeburn 11548: sub check_for_traversal {
11549: my ($path,$url,$toplevel) = @_;
11550: my @parts=split(/\//,$path);
11551: my $cleanpath;
11552: my $fullpath = $url;
11553: for (my $i=0;$i<@parts;$i++) {
11554: next if ($parts[$i] eq '.');
11555: if ($parts[$i] eq '..') {
11556: $fullpath =~ s{([^/]+/)$}{};
11557: } else {
11558: $fullpath .= $parts[$i].'/';
11559: }
11560: }
11561: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11562: $cleanpath = $1;
11563: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11564: my $curr_toprel = $1;
11565: my @parts = split(/\//,$curr_toprel);
11566: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11567: my @urlparts = split(/\//,$url_toprel);
11568: my $doubledots;
11569: my $startdiff = -1;
11570: for (my $i=0; $i<@urlparts; $i++) {
11571: if ($startdiff == -1) {
11572: unless ($urlparts[$i] eq $parts[$i]) {
11573: $startdiff = $i;
11574: $doubledots .= '../';
11575: }
11576: } else {
11577: $doubledots .= '../';
11578: }
11579: }
11580: if ($startdiff > -1) {
11581: $cleanpath = $doubledots;
11582: for (my $i=$startdiff; $i<@parts; $i++) {
11583: $cleanpath .= $parts[$i].'/';
11584: }
11585: }
11586: }
11587: $cleanpath =~ s{(/)$}{};
11588: return $cleanpath;
11589: }
1.31 albertel 11590:
1.1053 raeburn 11591: sub is_archive_file {
11592: my ($mimetype) = @_;
11593: if (($mimetype eq 'application/octet-stream') ||
11594: ($mimetype eq 'application/x-stuffit') ||
11595: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11596: return 1;
11597: }
11598: return;
11599: }
11600:
11601: sub decompress_form {
1.1065 raeburn 11602: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11603: my %lt = &Apache::lonlocal::texthash (
11604: this => 'This file is an archive file.',
1.1067 raeburn 11605: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11606: itsc => 'Its contents are as follows:',
1.1053 raeburn 11607: youm => 'You may wish to extract its contents.',
11608: extr => 'Extract contents',
1.1067 raeburn 11609: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11610: proa => 'Process automatically?',
1.1053 raeburn 11611: yes => 'Yes',
11612: no => 'No',
1.1067 raeburn 11613: fold => 'Title for folder containing movie',
11614: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11615: );
1.1065 raeburn 11616: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11617: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11618: my $info = &list_archive_contents($fileloc,\@paths);
11619: if (@paths) {
11620: foreach my $path (@paths) {
11621: $path =~ s{^/}{};
1.1067 raeburn 11622: if ($path =~ m{^([^/]+)/$}) {
11623: $topdir = $1;
11624: }
1.1065 raeburn 11625: if ($path =~ m{^([^/]+)/}) {
11626: $toplevel{$1} = $path;
11627: } else {
11628: $toplevel{$path} = $path;
11629: }
11630: }
11631: }
1.1067 raeburn 11632: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 11633: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11634: "$topdir/media/",
11635: "$topdir/media/$topdir.mp4",
11636: "$topdir/media/FirstFrame.png",
11637: "$topdir/media/player.swf",
11638: "$topdir/media/swfobject.js",
11639: "$topdir/media/expressInstall.swf");
1.1197 raeburn 11640: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 11641: "$topdir/$topdir.mp4",
11642: "$topdir/$topdir\_config.xml",
11643: "$topdir/$topdir\_controller.swf",
11644: "$topdir/$topdir\_embed.css",
11645: "$topdir/$topdir\_First_Frame.png",
11646: "$topdir/$topdir\_player.html",
11647: "$topdir/$topdir\_Thumbnails.png",
11648: "$topdir/playerProductInstall.swf",
11649: "$topdir/scripts/",
11650: "$topdir/scripts/config_xml.js",
11651: "$topdir/scripts/handlebars.js",
11652: "$topdir/scripts/jquery-1.7.1.min.js",
11653: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11654: "$topdir/scripts/modernizr.js",
11655: "$topdir/scripts/player-min.js",
11656: "$topdir/scripts/swfobject.js",
11657: "$topdir/skins/",
11658: "$topdir/skins/configuration_express.xml",
11659: "$topdir/skins/express_show/",
11660: "$topdir/skins/express_show/player-min.css",
11661: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 11662: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11663: "$topdir/$topdir.mp4",
11664: "$topdir/$topdir\_config.xml",
11665: "$topdir/$topdir\_controller.swf",
11666: "$topdir/$topdir\_embed.css",
11667: "$topdir/$topdir\_First_Frame.png",
11668: "$topdir/$topdir\_player.html",
11669: "$topdir/$topdir\_Thumbnails.png",
11670: "$topdir/playerProductInstall.swf",
11671: "$topdir/scripts/",
11672: "$topdir/scripts/config_xml.js",
11673: "$topdir/scripts/techsmith-smart-player.min.js",
11674: "$topdir/skins/",
11675: "$topdir/skins/configuration_express.xml",
11676: "$topdir/skins/express_show/",
11677: "$topdir/skins/express_show/spritesheet.min.css",
11678: "$topdir/skins/express_show/spritesheet.png",
11679: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 11680: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11681: if (@diffs == 0) {
1.1164 raeburn 11682: $is_camtasia = 6;
11683: } else {
1.1197 raeburn 11684: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 11685: if (@diffs == 0) {
11686: $is_camtasia = 8;
1.1197 raeburn 11687: } else {
11688: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11689: if (@diffs == 0) {
11690: $is_camtasia = 8;
11691: }
1.1164 raeburn 11692: }
1.1067 raeburn 11693: }
11694: }
11695: my $output;
11696: if ($is_camtasia) {
11697: $output = <<"ENDCAM";
11698: <script type="text/javascript" language="Javascript">
11699: // <![CDATA[
11700:
11701: function camtasiaToggle() {
11702: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11703: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 11704: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11705: document.getElementById('camtasia_titles').style.display='block';
11706: } else {
11707: document.getElementById('camtasia_titles').style.display='none';
11708: }
11709: }
11710: }
11711: return;
11712: }
11713:
11714: // ]]>
11715: </script>
11716: <p>$lt{'camt'}</p>
11717: ENDCAM
1.1065 raeburn 11718: } else {
1.1067 raeburn 11719: $output = '<p>'.$lt{'this'};
11720: if ($info eq '') {
11721: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11722: } else {
11723: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11724: '<div><pre>'.$info.'</pre></div>';
11725: }
1.1065 raeburn 11726: }
1.1067 raeburn 11727: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11728: my $duplicates;
11729: my $num = 0;
11730: if (ref($dirlist) eq 'ARRAY') {
11731: foreach my $item (@{$dirlist}) {
11732: if (ref($item) eq 'ARRAY') {
11733: if (exists($toplevel{$item->[0]})) {
11734: $duplicates .=
11735: &start_data_table_row().
11736: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11737: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11738: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11739: 'value="1" />'.&mt('Yes').'</label>'.
11740: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11741: '<td>'.$item->[0].'</td>';
11742: if ($item->[2]) {
11743: $duplicates .= '<td>'.&mt('Directory').'</td>';
11744: } else {
11745: $duplicates .= '<td>'.&mt('File').'</td>';
11746: }
11747: $duplicates .= '<td>'.$item->[3].'</td>'.
11748: '<td>'.
11749: &Apache::lonlocal::locallocaltime($item->[4]).
11750: '</td>'.
11751: &end_data_table_row();
11752: $num ++;
11753: }
11754: }
11755: }
11756: }
11757: my $itemcount;
11758: if (@paths > 0) {
11759: $itemcount = scalar(@paths);
11760: } else {
11761: $itemcount = 1;
11762: }
1.1067 raeburn 11763: if ($is_camtasia) {
11764: $output .= $lt{'auto'}.'<br />'.
11765: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 11766: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11767: $lt{'yes'}.'</label> <label>'.
11768: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11769: $lt{'no'}.'</label></span><br />'.
11770: '<div id="camtasia_titles" style="display:block">'.
11771: &Apache::lonhtmlcommon::start_pick_box().
11772: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11773: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11774: &Apache::lonhtmlcommon::row_closure().
11775: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11776: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11777: &Apache::lonhtmlcommon::row_closure(1).
11778: &Apache::lonhtmlcommon::end_pick_box().
11779: '</div>';
11780: }
1.1065 raeburn 11781: $output .=
11782: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11783: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11784: "\n";
1.1065 raeburn 11785: if ($duplicates ne '') {
11786: $output .= '<p><span class="LC_warning">'.
11787: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11788: &start_data_table().
11789: &start_data_table_header_row().
11790: '<th>'.&mt('Overwrite?').'</th>'.
11791: '<th>'.&mt('Name').'</th>'.
11792: '<th>'.&mt('Type').'</th>'.
11793: '<th>'.&mt('Size').'</th>'.
11794: '<th>'.&mt('Last modified').'</th>'.
11795: &end_data_table_header_row().
11796: $duplicates.
11797: &end_data_table().
11798: '</p>';
11799: }
1.1067 raeburn 11800: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11801: if (ref($hiddenelements) eq 'HASH') {
11802: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11803: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11804: }
11805: }
11806: $output .= <<"END";
1.1067 raeburn 11807: <br />
1.1053 raeburn 11808: <input type="submit" name="decompress" value="$lt{'extr'}" />
11809: </form>
11810: $noextract
11811: END
11812: return $output;
11813: }
11814:
1.1065 raeburn 11815: sub decompression_utility {
11816: my ($program) = @_;
11817: my @utilities = ('tar','gunzip','bunzip2','unzip');
11818: my $location;
11819: if (grep(/^\Q$program\E$/,@utilities)) {
11820: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11821: '/usr/sbin/') {
11822: if (-x $dir.$program) {
11823: $location = $dir.$program;
11824: last;
11825: }
11826: }
11827: }
11828: return $location;
11829: }
11830:
11831: sub list_archive_contents {
11832: my ($file,$pathsref) = @_;
11833: my (@cmd,$output);
11834: my $needsregexp;
11835: if ($file =~ /\.zip$/) {
11836: @cmd = (&decompression_utility('unzip'),"-l");
11837: $needsregexp = 1;
11838: } elsif (($file =~ m/\.tar\.gz$/) ||
11839: ($file =~ /\.tgz$/)) {
11840: @cmd = (&decompression_utility('tar'),"-ztf");
11841: } elsif ($file =~ /\.tar\.bz2$/) {
11842: @cmd = (&decompression_utility('tar'),"-jtf");
11843: } elsif ($file =~ m|\.tar$|) {
11844: @cmd = (&decompression_utility('tar'),"-tf");
11845: }
11846: if (@cmd) {
11847: undef($!);
11848: undef($@);
11849: if (open(my $fh,"-|", @cmd, $file)) {
11850: while (my $line = <$fh>) {
11851: $output .= $line;
11852: chomp($line);
11853: my $item;
11854: if ($needsregexp) {
11855: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11856: } else {
11857: $item = $line;
11858: }
11859: if ($item ne '') {
11860: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11861: push(@{$pathsref},$item);
11862: }
11863: }
11864: }
11865: close($fh);
11866: }
11867: }
11868: return $output;
11869: }
11870:
1.1053 raeburn 11871: sub decompress_uploaded_file {
11872: my ($file,$dir) = @_;
11873: &Apache::lonnet::appenv({'cgi.file' => $file});
11874: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11875: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11876: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11877: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11878: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11879: my $decompressed = $env{'cgi.decompressed'};
11880: &Apache::lonnet::delenv('cgi.file');
11881: &Apache::lonnet::delenv('cgi.dir');
11882: &Apache::lonnet::delenv('cgi.decompressed');
11883: return ($decompressed,$result);
11884: }
11885:
1.1055 raeburn 11886: sub process_decompression {
11887: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11888: my ($dir,$error,$warning,$output);
1.1180 raeburn 11889: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 11890: $error = &mt('Filename not a supported archive file type.').
11891: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11892: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11893: } else {
11894: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11895: if ($docuhome eq 'no_host') {
11896: $error = &mt('Could not determine home server for course.');
11897: } else {
11898: my @ids=&Apache::lonnet::current_machine_ids();
11899: my $currdir = "$dir_root/$destination";
11900: if (grep(/^\Q$docuhome\E$/,@ids)) {
11901: $dir = &LONCAPA::propath($docudom,$docuname).
11902: "$dir_root/$destination";
11903: } else {
11904: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11905: "$dir_root/$docudom/$docuname/$destination";
11906: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11907: $error = &mt('Archive file not found.');
11908: }
11909: }
1.1065 raeburn 11910: my (@to_overwrite,@to_skip);
11911: if ($env{'form.archive_overwrite_total'} > 0) {
11912: my $total = $env{'form.archive_overwrite_total'};
11913: for (my $i=0; $i<$total; $i++) {
11914: if ($env{'form.archive_overwrite_'.$i} == 1) {
11915: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11916: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11917: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11918: }
11919: }
11920: }
11921: my $numskip = scalar(@to_skip);
11922: if (($numskip > 0) &&
11923: ($numskip == $env{'form.archive_itemcount'})) {
11924: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11925: } elsif ($dir eq '') {
1.1055 raeburn 11926: $error = &mt('Directory containing archive file unavailable.');
11927: } elsif (!$error) {
1.1065 raeburn 11928: my ($decompressed,$display);
11929: if ($numskip > 0) {
11930: my $tempdir = time.'_'.$$.int(rand(10000));
11931: mkdir("$dir/$tempdir",0755);
11932: system("mv $dir/$file $dir/$tempdir/$file");
11933: ($decompressed,$display) =
11934: &decompress_uploaded_file($file,"$dir/$tempdir");
11935: foreach my $item (@to_skip) {
11936: if (($item ne '') && ($item !~ /\.\./)) {
11937: if (-f "$dir/$tempdir/$item") {
11938: unlink("$dir/$tempdir/$item");
11939: } elsif (-d "$dir/$tempdir/$item") {
11940: system("rm -rf $dir/$tempdir/$item");
11941: }
11942: }
11943: }
11944: system("mv $dir/$tempdir/* $dir");
11945: rmdir("$dir/$tempdir");
11946: } else {
11947: ($decompressed,$display) =
11948: &decompress_uploaded_file($file,$dir);
11949: }
1.1055 raeburn 11950: if ($decompressed eq 'ok') {
1.1065 raeburn 11951: $output = '<p class="LC_info">'.
11952: &mt('Files extracted successfully from archive.').
11953: '</p>'."\n";
1.1055 raeburn 11954: my ($warning,$result,@contents);
11955: my ($newdirlistref,$newlisterror) =
11956: &Apache::lonnet::dirlist($currdir,$docudom,
11957: $docuname,1);
11958: my (%is_dir,%changes,@newitems);
11959: my $dirptr = 16384;
1.1065 raeburn 11960: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11961: foreach my $dir_line (@{$newdirlistref}) {
11962: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11963: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11964: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11965: push(@newitems,$item);
11966: if ($dirptr&$testdir) {
11967: $is_dir{$item} = 1;
11968: }
11969: $changes{$item} = 1;
11970: }
11971: }
11972: }
11973: if (keys(%changes) > 0) {
11974: foreach my $item (sort(@newitems)) {
11975: if ($changes{$item}) {
11976: push(@contents,$item);
11977: }
11978: }
11979: }
11980: if (@contents > 0) {
1.1067 raeburn 11981: my $wantform;
11982: unless ($env{'form.autoextract_camtasia'}) {
11983: $wantform = 1;
11984: }
1.1056 raeburn 11985: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11986: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11987: $currdir,\%is_dir,
11988: \%children,\%parent,
1.1056 raeburn 11989: \@contents,\%dirorder,
11990: \%titles,$wantform);
1.1055 raeburn 11991: if ($datatable ne '') {
11992: $output .= &archive_options_form('decompressed',$datatable,
11993: $count,$hiddenelem);
1.1065 raeburn 11994: my $startcount = 6;
1.1055 raeburn 11995: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11996: \%titles,\%children);
1.1055 raeburn 11997: }
1.1067 raeburn 11998: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 11999: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12000: my %displayed;
12001: my $total = 1;
12002: $env{'form.archive_directory'} = [];
12003: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12004: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12005: $path =~ s{/$}{};
12006: my $item;
12007: if ($path ne '') {
12008: $item = "$path/$titles{$i}";
12009: } else {
12010: $item = $titles{$i};
12011: }
12012: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12013: if ($item eq $contents[0]) {
12014: push(@{$env{'form.archive_directory'}},$i);
12015: $env{'form.archive_'.$i} = 'display';
12016: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12017: $displayed{'folder'} = $i;
1.1164 raeburn 12018: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12019: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12020: $env{'form.archive_'.$i} = 'display';
12021: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12022: $displayed{'web'} = $i;
12023: } else {
1.1164 raeburn 12024: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12025: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12026: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12027: push(@{$env{'form.archive_directory'}},$i);
12028: }
12029: $env{'form.archive_'.$i} = 'dependency';
12030: }
12031: $total ++;
12032: }
12033: for (my $i=1; $i<$total; $i++) {
12034: next if ($i == $displayed{'web'});
12035: next if ($i == $displayed{'folder'});
12036: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12037: }
12038: $env{'form.phase'} = 'decompress_cleanup';
12039: $env{'form.archivedelete'} = 1;
12040: $env{'form.archive_count'} = $total-1;
12041: $output .=
12042: &process_extracted_files('coursedocs',$docudom,
12043: $docuname,$destination,
12044: $dir_root,$hiddenelem);
12045: }
1.1055 raeburn 12046: } else {
12047: $warning = &mt('No new items extracted from archive file.');
12048: }
12049: } else {
12050: $output = $display;
12051: $error = &mt('An error occurred during extraction from the archive file.');
12052: }
12053: }
12054: }
12055: }
12056: if ($error) {
12057: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12058: $error.'</p>'."\n";
12059: }
12060: if ($warning) {
12061: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12062: }
12063: return $output;
12064: }
12065:
12066: sub get_extracted {
1.1056 raeburn 12067: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12068: $titles,$wantform) = @_;
1.1055 raeburn 12069: my $count = 0;
12070: my $depth = 0;
12071: my $datatable;
1.1056 raeburn 12072: my @hierarchy;
1.1055 raeburn 12073: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12074: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12075: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12076: foreach my $item (@{$contents}) {
12077: $count ++;
1.1056 raeburn 12078: @{$dirorder->{$count}} = @hierarchy;
12079: $titles->{$count} = $item;
1.1055 raeburn 12080: &archive_hierarchy($depth,$count,$parent,$children);
12081: if ($wantform) {
12082: $datatable .= &archive_row($is_dir->{$item},$item,
12083: $currdir,$depth,$count);
12084: }
12085: if ($is_dir->{$item}) {
12086: $depth ++;
1.1056 raeburn 12087: push(@hierarchy,$count);
12088: $parent->{$depth} = $count;
1.1055 raeburn 12089: $datatable .=
12090: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12091: \$depth,\$count,\@hierarchy,$dirorder,
12092: $children,$parent,$titles,$wantform);
1.1055 raeburn 12093: $depth --;
1.1056 raeburn 12094: pop(@hierarchy);
1.1055 raeburn 12095: }
12096: }
12097: return ($count,$datatable);
12098: }
12099:
12100: sub recurse_extracted_archive {
1.1056 raeburn 12101: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12102: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12103: my $result='';
1.1056 raeburn 12104: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12105: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12106: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12107: return $result;
12108: }
12109: my $dirptr = 16384;
12110: my ($newdirlistref,$newlisterror) =
12111: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12112: if (ref($newdirlistref) eq 'ARRAY') {
12113: foreach my $dir_line (@{$newdirlistref}) {
12114: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12115: unless ($item =~ /^\.+$/) {
12116: $$count ++;
1.1056 raeburn 12117: @{$dirorder->{$$count}} = @{$hierarchy};
12118: $titles->{$$count} = $item;
1.1055 raeburn 12119: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12120:
1.1055 raeburn 12121: my $is_dir;
12122: if ($dirptr&$testdir) {
12123: $is_dir = 1;
12124: }
12125: if ($wantform) {
12126: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12127: }
12128: if ($is_dir) {
12129: $$depth ++;
1.1056 raeburn 12130: push(@{$hierarchy},$$count);
12131: $parent->{$$depth} = $$count;
1.1055 raeburn 12132: $result .=
12133: &recurse_extracted_archive("$currdir/$item",$docudom,
12134: $docuname,$depth,$count,
1.1056 raeburn 12135: $hierarchy,$dirorder,$children,
12136: $parent,$titles,$wantform);
1.1055 raeburn 12137: $$depth --;
1.1056 raeburn 12138: pop(@{$hierarchy});
1.1055 raeburn 12139: }
12140: }
12141: }
12142: }
12143: return $result;
12144: }
12145:
12146: sub archive_hierarchy {
12147: my ($depth,$count,$parent,$children) =@_;
12148: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12149: if (exists($parent->{$depth})) {
12150: $children->{$parent->{$depth}} .= $count.':';
12151: }
12152: }
12153: return;
12154: }
12155:
12156: sub archive_row {
12157: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12158: my ($name) = ($item =~ m{([^/]+)$});
12159: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12160: 'display' => 'Add as file',
1.1055 raeburn 12161: 'dependency' => 'Include as dependency',
12162: 'discard' => 'Discard',
12163: );
12164: if ($is_dir) {
1.1059 raeburn 12165: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12166: }
1.1056 raeburn 12167: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12168: my $offset = 0;
1.1055 raeburn 12169: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12170: $offset ++;
1.1065 raeburn 12171: if ($action ne 'display') {
12172: $offset ++;
12173: }
1.1055 raeburn 12174: $output .= '<td><span class="LC_nobreak">'.
12175: '<label><input type="radio" name="archive_'.$count.
12176: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12177: my $text = $choices{$action};
12178: if ($is_dir) {
12179: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12180: if ($action eq 'display') {
1.1059 raeburn 12181: $text = &mt('Add as folder');
1.1055 raeburn 12182: }
1.1056 raeburn 12183: } else {
12184: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12185:
12186: }
12187: $output .= ' /> '.$choices{$action}.'</label></span>';
12188: if ($action eq 'dependency') {
12189: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12190: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12191: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12192: '<option value=""></option>'."\n".
12193: '</select>'."\n".
12194: '</div>';
1.1059 raeburn 12195: } elsif ($action eq 'display') {
12196: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12197: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12198: '</div>';
1.1055 raeburn 12199: }
1.1056 raeburn 12200: $output .= '</td>';
1.1055 raeburn 12201: }
12202: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12203: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12204: for (my $i=0; $i<$depth; $i++) {
12205: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12206: }
12207: if ($is_dir) {
12208: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12209: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12210: } else {
12211: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12212: }
12213: $output .= ' '.$name.'</td>'."\n".
12214: &end_data_table_row();
12215: return $output;
12216: }
12217:
12218: sub archive_options_form {
1.1065 raeburn 12219: my ($form,$display,$count,$hiddenelem) = @_;
12220: my %lt = &Apache::lonlocal::texthash(
12221: perm => 'Permanently remove archive file?',
12222: hows => 'How should each extracted item be incorporated in the course?',
12223: cont => 'Content actions for all',
12224: addf => 'Add as folder/file',
12225: incd => 'Include as dependency for a displayed file',
12226: disc => 'Discard',
12227: no => 'No',
12228: yes => 'Yes',
12229: save => 'Save',
12230: );
12231: my $output = <<"END";
12232: <form name="$form" method="post" action="">
12233: <p><span class="LC_nobreak">$lt{'perm'}
12234: <label>
12235: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12236: </label>
12237:
12238: <label>
12239: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12240: </span>
12241: </p>
12242: <input type="hidden" name="phase" value="decompress_cleanup" />
12243: <br />$lt{'hows'}
12244: <div class="LC_columnSection">
12245: <fieldset>
12246: <legend>$lt{'cont'}</legend>
12247: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12248: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12249: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12250: </fieldset>
12251: </div>
12252: END
12253: return $output.
1.1055 raeburn 12254: &start_data_table()."\n".
1.1065 raeburn 12255: $display."\n".
1.1055 raeburn 12256: &end_data_table()."\n".
12257: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12258: $hiddenelem.
1.1065 raeburn 12259: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12260: '</form>';
12261: }
12262:
12263: sub archive_javascript {
1.1056 raeburn 12264: my ($startcount,$numitems,$titles,$children) = @_;
12265: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12266: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12267: my $scripttag = <<START;
12268: <script type="text/javascript">
12269: // <![CDATA[
12270:
12271: function checkAll(form,prefix) {
12272: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12273: for (var i=0; i < form.elements.length; i++) {
12274: var id = form.elements[i].id;
12275: if ((id != '') && (id != undefined)) {
12276: if (idstr.test(id)) {
12277: if (form.elements[i].type == 'radio') {
12278: form.elements[i].checked = true;
1.1056 raeburn 12279: var nostart = i-$startcount;
1.1059 raeburn 12280: var offset = nostart%7;
12281: var count = (nostart-offset)/7;
1.1056 raeburn 12282: dependencyCheck(form,count,offset);
1.1055 raeburn 12283: }
12284: }
12285: }
12286: }
12287: }
12288:
12289: function propagateCheck(form,count) {
12290: if (count > 0) {
1.1059 raeburn 12291: var startelement = $startcount + ((count-1) * 7);
12292: for (var j=1; j<6; j++) {
12293: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12294: var item = startelement + j;
12295: if (form.elements[item].type == 'radio') {
12296: if (form.elements[item].checked) {
12297: containerCheck(form,count,j);
12298: break;
12299: }
1.1055 raeburn 12300: }
12301: }
12302: }
12303: }
12304: }
12305:
12306: numitems = $numitems
1.1056 raeburn 12307: var titles = new Array(numitems);
12308: var parents = new Array(numitems);
1.1055 raeburn 12309: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12310: parents[i] = new Array;
1.1055 raeburn 12311: }
1.1059 raeburn 12312: var maintitle = '$maintitle';
1.1055 raeburn 12313:
12314: START
12315:
1.1056 raeburn 12316: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12317: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12318: for (my $i=0; $i<@contents; $i ++) {
12319: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12320: }
12321: }
12322:
1.1056 raeburn 12323: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12324: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12325: }
12326:
1.1055 raeburn 12327: $scripttag .= <<END;
12328:
12329: function containerCheck(form,count,offset) {
12330: if (count > 0) {
1.1056 raeburn 12331: dependencyCheck(form,count,offset);
1.1059 raeburn 12332: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12333: form.elements[item].checked = true;
12334: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12335: if (parents[count].length > 0) {
12336: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12337: containerCheck(form,parents[count][j],offset);
12338: }
12339: }
12340: }
12341: }
12342: }
12343:
12344: function dependencyCheck(form,count,offset) {
12345: if (count > 0) {
1.1059 raeburn 12346: var chosen = (offset+$startcount)+7*(count-1);
12347: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12348: var currtype = form.elements[depitem].type;
12349: if (form.elements[chosen].value == 'dependency') {
12350: document.getElementById('arc_depon_'+count).style.display='block';
12351: form.elements[depitem].options.length = 0;
12352: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 12353: for (var i=1; i<=numitems; i++) {
12354: if (i == count) {
12355: continue;
12356: }
1.1059 raeburn 12357: var startelement = $startcount + (i-1) * 7;
12358: for (var j=1; j<6; j++) {
12359: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12360: var item = startelement + j;
12361: if (form.elements[item].type == 'radio') {
12362: if (form.elements[item].checked) {
12363: if (form.elements[item].value == 'display') {
12364: var n = form.elements[depitem].options.length;
12365: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12366: }
12367: }
12368: }
12369: }
12370: }
12371: }
12372: } else {
12373: document.getElementById('arc_depon_'+count).style.display='none';
12374: form.elements[depitem].options.length = 0;
12375: form.elements[depitem].options[0] = new Option('Select','',true,true);
12376: }
1.1059 raeburn 12377: titleCheck(form,count,offset);
1.1056 raeburn 12378: }
12379: }
12380:
12381: function propagateSelect(form,count,offset) {
12382: if (count > 0) {
1.1065 raeburn 12383: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12384: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12385: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12386: if (parents[count].length > 0) {
12387: for (var j=0; j<parents[count].length; j++) {
12388: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12389: }
12390: }
12391: }
12392: }
12393: }
1.1056 raeburn 12394:
12395: function containerSelect(form,count,offset,picked) {
12396: if (count > 0) {
1.1065 raeburn 12397: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12398: if (form.elements[item].type == 'radio') {
12399: if (form.elements[item].value == 'dependency') {
12400: if (form.elements[item+1].type == 'select-one') {
12401: for (var i=0; i<form.elements[item+1].options.length; i++) {
12402: if (form.elements[item+1].options[i].value == picked) {
12403: form.elements[item+1].selectedIndex = i;
12404: break;
12405: }
12406: }
12407: }
12408: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12409: if (parents[count].length > 0) {
12410: for (var j=0; j<parents[count].length; j++) {
12411: containerSelect(form,parents[count][j],offset,picked);
12412: }
12413: }
12414: }
12415: }
12416: }
12417: }
12418: }
12419:
1.1059 raeburn 12420: function titleCheck(form,count,offset) {
12421: if (count > 0) {
12422: var chosen = (offset+$startcount)+7*(count-1);
12423: var depitem = $startcount + ((count-1) * 7) + 2;
12424: var currtype = form.elements[depitem].type;
12425: if (form.elements[chosen].value == 'display') {
12426: document.getElementById('arc_title_'+count).style.display='block';
12427: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12428: document.getElementById('archive_title_'+count).value=maintitle;
12429: }
12430: } else {
12431: document.getElementById('arc_title_'+count).style.display='none';
12432: if (currtype == 'text') {
12433: document.getElementById('archive_title_'+count).value='';
12434: }
12435: }
12436: }
12437: return;
12438: }
12439:
1.1055 raeburn 12440: // ]]>
12441: </script>
12442: END
12443: return $scripttag;
12444: }
12445:
12446: sub process_extracted_files {
1.1067 raeburn 12447: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12448: my $numitems = $env{'form.archive_count'};
12449: return unless ($numitems);
12450: my @ids=&Apache::lonnet::current_machine_ids();
12451: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12452: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12453: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12454: if (grep(/^\Q$docuhome\E$/,@ids)) {
12455: $prefix = &LONCAPA::propath($docudom,$docuname);
12456: $pathtocheck = "$dir_root/$destination";
12457: $dir = $dir_root;
12458: $ishome = 1;
12459: } else {
12460: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12461: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
12462: $dir = "$dir_root/$docudom/$docuname";
12463: }
12464: my $currdir = "$dir_root/$destination";
12465: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12466: if ($env{'form.folderpath'}) {
12467: my @items = split('&',$env{'form.folderpath'});
12468: $folders{'0'} = $items[-2];
1.1099 raeburn 12469: if ($env{'form.folderpath'} =~ /\:1$/) {
12470: $containers{'0'}='page';
12471: } else {
12472: $containers{'0'}='sequence';
12473: }
1.1055 raeburn 12474: }
12475: my @archdirs = &get_env_multiple('form.archive_directory');
12476: if ($numitems) {
12477: for (my $i=1; $i<=$numitems; $i++) {
12478: my $path = $env{'form.archive_content_'.$i};
12479: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12480: my $item = $1;
12481: $toplevelitems{$item} = $i;
12482: if (grep(/^\Q$i\E$/,@archdirs)) {
12483: $is_dir{$item} = 1;
12484: }
12485: }
12486: }
12487: }
1.1067 raeburn 12488: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12489: if (keys(%toplevelitems) > 0) {
12490: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12491: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12492: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12493: }
1.1066 raeburn 12494: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12495: if ($numitems) {
12496: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 12497: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12498: my $path = $env{'form.archive_content_'.$i};
12499: if ($path =~ /^\Q$pathtocheck\E/) {
12500: if ($env{'form.archive_'.$i} eq 'discard') {
12501: if ($prefix ne '' && $path ne '') {
12502: if (-e $prefix.$path) {
1.1066 raeburn 12503: if ((@archdirs > 0) &&
12504: (grep(/^\Q$i\E$/,@archdirs))) {
12505: $todeletedir{$prefix.$path} = 1;
12506: } else {
12507: $todelete{$prefix.$path} = 1;
12508: }
1.1055 raeburn 12509: }
12510: }
12511: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12512: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12513: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12514: $docstitle = $env{'form.archive_title_'.$i};
12515: if ($docstitle eq '') {
12516: $docstitle = $title;
12517: }
1.1055 raeburn 12518: $outer = 0;
1.1056 raeburn 12519: if (ref($dirorder{$i}) eq 'ARRAY') {
12520: if (@{$dirorder{$i}} > 0) {
12521: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12522: if ($env{'form.archive_'.$item} eq 'display') {
12523: $outer = $item;
12524: last;
12525: }
12526: }
12527: }
12528: }
12529: my ($errtext,$fatal) =
12530: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12531: '/'.$folders{$outer}.'.'.
12532: $containers{$outer});
12533: next if ($fatal);
12534: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12535: if ($context eq 'coursedocs') {
1.1056 raeburn 12536: $mapinner{$i} = time;
1.1055 raeburn 12537: $folders{$i} = 'default_'.$mapinner{$i};
12538: $containers{$i} = 'sequence';
12539: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12540: $folders{$i}.'.'.$containers{$i};
12541: my $newidx = &LONCAPA::map::getresidx();
12542: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12543: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12544: push(@LONCAPA::map::order,$newidx);
12545: my ($outtext,$errtext) =
12546: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12547: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 12548: '.'.$containers{$outer},1,1);
1.1056 raeburn 12549: $newseqid{$i} = $newidx;
1.1067 raeburn 12550: unless ($errtext) {
12551: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
12552: }
1.1055 raeburn 12553: }
12554: } else {
12555: if ($context eq 'coursedocs') {
12556: my $newidx=&LONCAPA::map::getresidx();
12557: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12558: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12559: $title;
12560: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12561: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
12562: }
12563: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12564: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12565: }
12566: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12567: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 12568: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 12569: unless ($ishome) {
12570: my $fetch = "$newdest{$i}/$title";
12571: $fetch =~ s/^\Q$prefix$dir\E//;
12572: $prompttofetch{$fetch} = 1;
12573: }
1.1055 raeburn 12574: }
12575: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12576: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12577: push(@LONCAPA::map::order, $newidx);
12578: my ($outtext,$errtext)=
12579: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12580: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 12581: '.'.$containers{$outer},1,1);
1.1067 raeburn 12582: unless ($errtext) {
12583: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12584: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
12585: }
12586: }
1.1055 raeburn 12587: }
12588: }
1.1086 raeburn 12589: }
12590: } else {
12591: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12592: }
12593: }
12594: for (my $i=1; $i<=$numitems; $i++) {
12595: next unless ($env{'form.archive_'.$i} eq 'dependency');
12596: my $path = $env{'form.archive_content_'.$i};
12597: if ($path =~ /^\Q$pathtocheck\E/) {
12598: my ($title) = ($path =~ m{/([^/]+)$});
12599: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12600: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12601: if (ref($dirorder{$i}) eq 'ARRAY') {
12602: my ($itemidx,$fullpath,$relpath);
12603: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12604: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12605: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 12606: if ($dirorder{$i}->[$j] eq $container) {
12607: $itemidx = $j;
1.1056 raeburn 12608: }
12609: }
1.1086 raeburn 12610: }
12611: if ($itemidx eq '') {
12612: $itemidx = 0;
12613: }
12614: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12615: if ($mapinner{$referrer{$i}}) {
12616: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12617: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12618: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12619: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12620: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12621: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12622: if (!-e $fullpath) {
12623: mkdir($fullpath,0755);
1.1056 raeburn 12624: }
12625: }
1.1086 raeburn 12626: } else {
12627: last;
1.1056 raeburn 12628: }
1.1086 raeburn 12629: }
12630: }
12631: } elsif ($newdest{$referrer{$i}}) {
12632: $fullpath = $newdest{$referrer{$i}};
12633: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12634: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12635: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12636: last;
12637: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12638: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12639: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12640: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12641: if (!-e $fullpath) {
12642: mkdir($fullpath,0755);
1.1056 raeburn 12643: }
12644: }
1.1086 raeburn 12645: } else {
12646: last;
1.1056 raeburn 12647: }
1.1055 raeburn 12648: }
12649: }
1.1086 raeburn 12650: if ($fullpath ne '') {
12651: if (-e "$prefix$path") {
12652: system("mv $prefix$path $fullpath/$title");
12653: }
12654: if (-e "$fullpath/$title") {
12655: my $showpath;
12656: if ($relpath ne '') {
12657: $showpath = "$relpath/$title";
12658: } else {
12659: $showpath = "/$title";
12660: }
12661: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12662: }
12663: unless ($ishome) {
12664: my $fetch = "$fullpath/$title";
12665: $fetch =~ s/^\Q$prefix$dir\E//;
12666: $prompttofetch{$fetch} = 1;
12667: }
12668: }
1.1055 raeburn 12669: }
1.1086 raeburn 12670: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12671: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12672: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12673: }
12674: } else {
12675: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12676: }
12677: }
12678: if (keys(%todelete)) {
12679: foreach my $key (keys(%todelete)) {
12680: unlink($key);
1.1066 raeburn 12681: }
12682: }
12683: if (keys(%todeletedir)) {
12684: foreach my $key (keys(%todeletedir)) {
12685: rmdir($key);
12686: }
12687: }
12688: foreach my $dir (sort(keys(%is_dir))) {
12689: if (($pathtocheck ne '') && ($dir ne '')) {
12690: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12691: }
12692: }
1.1067 raeburn 12693: if ($result ne '') {
12694: $output .= '<ul>'."\n".
12695: $result."\n".
12696: '</ul>';
12697: }
12698: unless ($ishome) {
12699: my $replicationfail;
12700: foreach my $item (keys(%prompttofetch)) {
12701: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12702: unless ($fetchresult eq 'ok') {
12703: $replicationfail .= '<li>'.$item.'</li>'."\n";
12704: }
12705: }
12706: if ($replicationfail) {
12707: $output .= '<p class="LC_error">'.
12708: &mt('Course home server failed to retrieve:').'<ul>'.
12709: $replicationfail.
12710: '</ul></p>';
12711: }
12712: }
1.1055 raeburn 12713: } else {
12714: $warning = &mt('No items found in archive.');
12715: }
12716: if ($error) {
12717: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12718: $error.'</p>'."\n";
12719: }
12720: if ($warning) {
12721: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12722: }
12723: return $output;
12724: }
12725:
1.1066 raeburn 12726: sub cleanup_empty_dirs {
12727: my ($path) = @_;
12728: if (($path ne '') && (-d $path)) {
12729: if (opendir(my $dirh,$path)) {
12730: my @dircontents = grep(!/^\./,readdir($dirh));
12731: my $numitems = 0;
12732: foreach my $item (@dircontents) {
12733: if (-d "$path/$item") {
1.1111 raeburn 12734: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12735: if (-e "$path/$item") {
12736: $numitems ++;
12737: }
12738: } else {
12739: $numitems ++;
12740: }
12741: }
12742: if ($numitems == 0) {
12743: rmdir($path);
12744: }
12745: closedir($dirh);
12746: }
12747: }
12748: return;
12749: }
12750:
1.41 ng 12751: =pod
1.45 matthew 12752:
1.1162 raeburn 12753: =item * &get_folder_hierarchy()
1.1068 raeburn 12754:
12755: Provides hierarchy of names of folders/sub-folders containing the current
12756: item,
12757:
12758: Inputs: 3
12759: - $navmap - navmaps object
12760:
12761: - $map - url for map (either the trigger itself, or map containing
12762: the resource, which is the trigger).
12763:
12764: - $showitem - 1 => show title for map itself; 0 => do not show.
12765:
12766: Outputs: 1 @pathitems - array of folder/subfolder names.
12767:
12768: =cut
12769:
12770: sub get_folder_hierarchy {
12771: my ($navmap,$map,$showitem) = @_;
12772: my @pathitems;
12773: if (ref($navmap)) {
12774: my $mapres = $navmap->getResourceByUrl($map);
12775: if (ref($mapres)) {
12776: my $pcslist = $mapres->map_hierarchy();
12777: if ($pcslist ne '') {
12778: my @pcs = split(/,/,$pcslist);
12779: foreach my $pc (@pcs) {
12780: if ($pc == 1) {
1.1129 raeburn 12781: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12782: } else {
12783: my $res = $navmap->getByMapPc($pc);
12784: if (ref($res)) {
12785: my $title = $res->compTitle();
12786: $title =~ s/\W+/_/g;
12787: if ($title ne '') {
12788: push(@pathitems,$title);
12789: }
12790: }
12791: }
12792: }
12793: }
1.1071 raeburn 12794: if ($showitem) {
12795: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 12796: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12797: } else {
12798: my $maptitle = $mapres->compTitle();
12799: $maptitle =~ s/\W+/_/g;
12800: if ($maptitle ne '') {
12801: push(@pathitems,$maptitle);
12802: }
1.1068 raeburn 12803: }
12804: }
12805: }
12806: }
12807: return @pathitems;
12808: }
12809:
12810: =pod
12811:
1.1015 raeburn 12812: =item * &get_turnedin_filepath()
12813:
12814: Determines path in a user's portfolio file for storage of files uploaded
12815: to a specific essayresponse or dropbox item.
12816:
12817: Inputs: 3 required + 1 optional.
12818: $symb is symb for resource, $uname and $udom are for current user (required).
12819: $caller is optional (can be "submission", if routine is called when storing
12820: an upoaded file when "Submit Answer" button was pressed).
12821:
12822: Returns array containing $path and $multiresp.
12823: $path is path in portfolio. $multiresp is 1 if this resource contains more
12824: than one file upload item. Callers of routine should append partid as a
12825: subdirectory to $path in cases where $multiresp is 1.
12826:
12827: Called by: homework/essayresponse.pm and homework/structuretags.pm
12828:
12829: =cut
12830:
12831: sub get_turnedin_filepath {
12832: my ($symb,$uname,$udom,$caller) = @_;
12833: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12834: my $turnindir;
12835: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12836: $turnindir = $userhash{'turnindir'};
12837: my ($path,$multiresp);
12838: if ($turnindir eq '') {
12839: if ($caller eq 'submission') {
12840: $turnindir = &mt('turned in');
12841: $turnindir =~ s/\W+/_/g;
12842: my %newhash = (
12843: 'turnindir' => $turnindir,
12844: );
12845: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12846: }
12847: }
12848: if ($turnindir ne '') {
12849: $path = '/'.$turnindir.'/';
12850: my ($multipart,$turnin,@pathitems);
12851: my $navmap = Apache::lonnavmaps::navmap->new();
12852: if (defined($navmap)) {
12853: my $mapres = $navmap->getResourceByUrl($map);
12854: if (ref($mapres)) {
12855: my $pcslist = $mapres->map_hierarchy();
12856: if ($pcslist ne '') {
12857: foreach my $pc (split(/,/,$pcslist)) {
12858: my $res = $navmap->getByMapPc($pc);
12859: if (ref($res)) {
12860: my $title = $res->compTitle();
12861: $title =~ s/\W+/_/g;
12862: if ($title ne '') {
1.1149 raeburn 12863: if (($pc > 1) && (length($title) > 12)) {
12864: $title = substr($title,0,12);
12865: }
1.1015 raeburn 12866: push(@pathitems,$title);
12867: }
12868: }
12869: }
12870: }
12871: my $maptitle = $mapres->compTitle();
12872: $maptitle =~ s/\W+/_/g;
12873: if ($maptitle ne '') {
1.1149 raeburn 12874: if (length($maptitle) > 12) {
12875: $maptitle = substr($maptitle,0,12);
12876: }
1.1015 raeburn 12877: push(@pathitems,$maptitle);
12878: }
12879: unless ($env{'request.state'} eq 'construct') {
12880: my $res = $navmap->getBySymb($symb);
12881: if (ref($res)) {
12882: my $partlist = $res->parts();
12883: my $totaluploads = 0;
12884: if (ref($partlist) eq 'ARRAY') {
12885: foreach my $part (@{$partlist}) {
12886: my @types = $res->responseType($part);
12887: my @ids = $res->responseIds($part);
12888: for (my $i=0; $i < scalar(@ids); $i++) {
12889: if ($types[$i] eq 'essay') {
12890: my $partid = $part.'_'.$ids[$i];
12891: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12892: $totaluploads ++;
12893: }
12894: }
12895: }
12896: }
12897: if ($totaluploads > 1) {
12898: $multiresp = 1;
12899: }
12900: }
12901: }
12902: }
12903: } else {
12904: return;
12905: }
12906: } else {
12907: return;
12908: }
12909: my $restitle=&Apache::lonnet::gettitle($symb);
12910: $restitle =~ s/\W+/_/g;
12911: if ($restitle eq '') {
12912: $restitle = ($resurl =~ m{/[^/]+$});
12913: if ($restitle eq '') {
12914: $restitle = time;
12915: }
12916: }
1.1149 raeburn 12917: if (length($restitle) > 12) {
12918: $restitle = substr($restitle,0,12);
12919: }
1.1015 raeburn 12920: push(@pathitems,$restitle);
12921: $path .= join('/',@pathitems);
12922: }
12923: return ($path,$multiresp);
12924: }
12925:
12926: =pod
12927:
1.464 albertel 12928: =back
1.41 ng 12929:
1.112 bowersj2 12930: =head1 CSV Upload/Handling functions
1.38 albertel 12931:
1.41 ng 12932: =over 4
12933:
1.648 raeburn 12934: =item * &upfile_store($r)
1.41 ng 12935:
12936: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12937: needs $env{'form.upfile'}
1.41 ng 12938: returns $datatoken to be put into hidden field
12939:
12940: =cut
1.31 albertel 12941:
12942: sub upfile_store {
12943: my $r=shift;
1.258 albertel 12944: $env{'form.upfile'}=~s/\r/\n/gs;
12945: $env{'form.upfile'}=~s/\f/\n/gs;
12946: $env{'form.upfile'}=~s/\n+/\n/gs;
12947: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12948:
1.258 albertel 12949: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12950: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12951: {
1.158 raeburn 12952: my $datafile = $r->dir_config('lonDaemons').
12953: '/tmp/'.$datatoken.'.tmp';
12954: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12955: print $fh $env{'form.upfile'};
1.158 raeburn 12956: close($fh);
12957: }
1.31 albertel 12958: }
12959: return $datatoken;
12960: }
12961:
1.56 matthew 12962: =pod
12963:
1.648 raeburn 12964: =item * &load_tmp_file($r)
1.41 ng 12965:
12966: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12967: needs $env{'form.datatoken'},
12968: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12969:
12970: =cut
1.31 albertel 12971:
12972: sub load_tmp_file {
12973: my $r=shift;
12974: my @studentdata=();
12975: {
1.158 raeburn 12976: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12977: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12978: if ( open(my $fh,"<$studentfile") ) {
12979: @studentdata=<$fh>;
12980: close($fh);
12981: }
1.31 albertel 12982: }
1.258 albertel 12983: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12984: }
12985:
1.56 matthew 12986: =pod
12987:
1.648 raeburn 12988: =item * &upfile_record_sep()
1.41 ng 12989:
12990: Separate uploaded file into records
12991: returns array of records,
1.258 albertel 12992: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12993:
12994: =cut
1.31 albertel 12995:
12996: sub upfile_record_sep {
1.258 albertel 12997: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12998: } else {
1.248 albertel 12999: my @records;
1.258 albertel 13000: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13001: if ($line=~/^\s*$/) { next; }
13002: push(@records,$line);
13003: }
13004: return @records;
1.31 albertel 13005: }
13006: }
13007:
1.56 matthew 13008: =pod
13009:
1.648 raeburn 13010: =item * &record_sep($record)
1.41 ng 13011:
1.258 albertel 13012: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13013:
13014: =cut
13015:
1.263 www 13016: sub takeleft {
13017: my $index=shift;
13018: return substr('0000'.$index,-4,4);
13019: }
13020:
1.31 albertel 13021: sub record_sep {
13022: my $record=shift;
13023: my %components=();
1.258 albertel 13024: if ($env{'form.upfiletype'} eq 'xml') {
13025: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13026: my $i=0;
1.356 albertel 13027: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13028: $field=~s/^(\"|\')//;
13029: $field=~s/(\"|\')$//;
1.263 www 13030: $components{&takeleft($i)}=$field;
1.31 albertel 13031: $i++;
13032: }
1.258 albertel 13033: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13034: my $i=0;
1.356 albertel 13035: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13036: $field=~s/^(\"|\')//;
13037: $field=~s/(\"|\')$//;
1.263 www 13038: $components{&takeleft($i)}=$field;
1.31 albertel 13039: $i++;
13040: }
13041: } else {
1.561 www 13042: my $separator=',';
1.480 banghart 13043: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13044: $separator=';';
1.480 banghart 13045: }
1.31 albertel 13046: my $i=0;
1.561 www 13047: # the character we are looking for to indicate the end of a quote or a record
13048: my $looking_for=$separator;
13049: # do not add the characters to the fields
13050: my $ignore=0;
13051: # we just encountered a separator (or the beginning of the record)
13052: my $just_found_separator=1;
13053: # store the field we are working on here
13054: my $field='';
13055: # work our way through all characters in record
13056: foreach my $character ($record=~/(.)/g) {
13057: if ($character eq $looking_for) {
13058: if ($character ne $separator) {
13059: # Found the end of a quote, again looking for separator
13060: $looking_for=$separator;
13061: $ignore=1;
13062: } else {
13063: # Found a separator, store away what we got
13064: $components{&takeleft($i)}=$field;
13065: $i++;
13066: $just_found_separator=1;
13067: $ignore=0;
13068: $field='';
13069: }
13070: next;
13071: }
13072: # single or double quotation marks after a separator indicate beginning of a quote
13073: # we are now looking for the end of the quote and need to ignore separators
13074: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13075: $looking_for=$character;
13076: next;
13077: }
13078: # ignore would be true after we reached the end of a quote
13079: if ($ignore) { next; }
13080: if (($just_found_separator) && ($character=~/\s/)) { next; }
13081: $field.=$character;
13082: $just_found_separator=0;
1.31 albertel 13083: }
1.561 www 13084: # catch the very last entry, since we never encountered the separator
13085: $components{&takeleft($i)}=$field;
1.31 albertel 13086: }
13087: return %components;
13088: }
13089:
1.144 matthew 13090: ######################################################
13091: ######################################################
13092:
1.56 matthew 13093: =pod
13094:
1.648 raeburn 13095: =item * &upfile_select_html()
1.41 ng 13096:
1.144 matthew 13097: Return HTML code to select a file from the users machine and specify
13098: the file type.
1.41 ng 13099:
13100: =cut
13101:
1.144 matthew 13102: ######################################################
13103: ######################################################
1.31 albertel 13104: sub upfile_select_html {
1.144 matthew 13105: my %Types = (
13106: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13107: semisv => &mt('Semicolon separated values'),
1.144 matthew 13108: space => &mt('Space separated'),
13109: tab => &mt('Tabulator separated'),
13110: # xml => &mt('HTML/XML'),
13111: );
13112: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13113: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13114: foreach my $type (sort(keys(%Types))) {
13115: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13116: }
13117: $Str .= "</select>\n";
13118: return $Str;
1.31 albertel 13119: }
13120:
1.301 albertel 13121: sub get_samples {
13122: my ($records,$toget) = @_;
13123: my @samples=({});
13124: my $got=0;
13125: foreach my $rec (@$records) {
13126: my %temp = &record_sep($rec);
13127: if (! grep(/\S/, values(%temp))) { next; }
13128: if (%temp) {
13129: $samples[$got]=\%temp;
13130: $got++;
13131: if ($got == $toget) { last; }
13132: }
13133: }
13134: return \@samples;
13135: }
13136:
1.144 matthew 13137: ######################################################
13138: ######################################################
13139:
1.56 matthew 13140: =pod
13141:
1.648 raeburn 13142: =item * &csv_print_samples($r,$records)
1.41 ng 13143:
13144: Prints a table of sample values from each column uploaded $r is an
13145: Apache Request ref, $records is an arrayref from
13146: &Apache::loncommon::upfile_record_sep
13147:
13148: =cut
13149:
1.144 matthew 13150: ######################################################
13151: ######################################################
1.31 albertel 13152: sub csv_print_samples {
13153: my ($r,$records) = @_;
1.662 bisitz 13154: my $samples = &get_samples($records,5);
1.301 albertel 13155:
1.594 raeburn 13156: $r->print(&mt('Samples').'<br />'.&start_data_table().
13157: &start_data_table_header_row());
1.356 albertel 13158: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13159: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13160: $r->print(&end_data_table_header_row());
1.301 albertel 13161: foreach my $hash (@$samples) {
1.594 raeburn 13162: $r->print(&start_data_table_row());
1.356 albertel 13163: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13164: $r->print('<td>');
1.356 albertel 13165: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13166: $r->print('</td>');
13167: }
1.594 raeburn 13168: $r->print(&end_data_table_row());
1.31 albertel 13169: }
1.594 raeburn 13170: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13171: }
13172:
1.144 matthew 13173: ######################################################
13174: ######################################################
13175:
1.56 matthew 13176: =pod
13177:
1.648 raeburn 13178: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13179:
13180: Prints a table to create associations between values and table columns.
1.144 matthew 13181:
1.41 ng 13182: $r is an Apache Request ref,
13183: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13184: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13185:
13186: =cut
13187:
1.144 matthew 13188: ######################################################
13189: ######################################################
1.31 albertel 13190: sub csv_print_select_table {
13191: my ($r,$records,$d) = @_;
1.301 albertel 13192: my $i=0;
13193: my $samples = &get_samples($records,1);
1.144 matthew 13194: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13195: &start_data_table().&start_data_table_header_row().
1.144 matthew 13196: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13197: '<th>'.&mt('Column').'</th>'.
13198: &end_data_table_header_row()."\n");
1.356 albertel 13199: foreach my $array_ref (@$d) {
13200: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13201: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13202:
1.875 bisitz 13203: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13204: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13205: $r->print('<option value="none"></option>');
1.356 albertel 13206: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13207: $r->print('<option value="'.$sample.'"'.
13208: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13209: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13210: }
1.594 raeburn 13211: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13212: $i++;
13213: }
1.594 raeburn 13214: $r->print(&end_data_table());
1.31 albertel 13215: $i--;
13216: return $i;
13217: }
1.56 matthew 13218:
1.144 matthew 13219: ######################################################
13220: ######################################################
13221:
1.56 matthew 13222: =pod
1.31 albertel 13223:
1.648 raeburn 13224: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13225:
13226: Prints a table of sample values from the upload and can make associate samples to internal names.
13227:
13228: $r is an Apache Request ref,
13229: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13230: $d is an array of 2 element arrays (internal name, displayed name)
13231:
13232: =cut
13233:
1.144 matthew 13234: ######################################################
13235: ######################################################
1.31 albertel 13236: sub csv_samples_select_table {
13237: my ($r,$records,$d) = @_;
13238: my $i=0;
1.144 matthew 13239: #
1.662 bisitz 13240: my $max_samples = 5;
13241: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13242: $r->print(&start_data_table().
13243: &start_data_table_header_row().'<th>'.
13244: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13245: &end_data_table_header_row());
1.301 albertel 13246:
13247: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13248: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13249: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13250: foreach my $option (@$d) {
13251: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13252: $r->print('<option value="'.$value.'"'.
1.253 albertel 13253: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13254: $display.'</option>');
1.31 albertel 13255: }
13256: $r->print('</select></td><td>');
1.662 bisitz 13257: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13258: if (defined($samples->[$line]{$key})) {
13259: $r->print($samples->[$line]{$key}."<br />\n");
13260: }
13261: }
1.594 raeburn 13262: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13263: $i++;
13264: }
1.594 raeburn 13265: $r->print(&end_data_table());
1.31 albertel 13266: $i--;
13267: return($i);
1.115 matthew 13268: }
13269:
1.144 matthew 13270: ######################################################
13271: ######################################################
13272:
1.115 matthew 13273: =pod
13274:
1.648 raeburn 13275: =item * &clean_excel_name($name)
1.115 matthew 13276:
13277: Returns a replacement for $name which does not contain any illegal characters.
13278:
13279: =cut
13280:
1.144 matthew 13281: ######################################################
13282: ######################################################
1.115 matthew 13283: sub clean_excel_name {
13284: my ($name) = @_;
13285: $name =~ s/[:\*\?\/\\]//g;
13286: if (length($name) > 31) {
13287: $name = substr($name,0,31);
13288: }
13289: return $name;
1.25 albertel 13290: }
1.84 albertel 13291:
1.85 albertel 13292: =pod
13293:
1.648 raeburn 13294: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13295:
13296: Returns either 1 or undef
13297:
13298: 1 if the part is to be hidden, undef if it is to be shown
13299:
13300: Arguments are:
13301:
13302: $id the id of the part to be checked
13303: $symb, optional the symb of the resource to check
13304: $udom, optional the domain of the user to check for
13305: $uname, optional the username of the user to check for
13306:
13307: =cut
1.84 albertel 13308:
13309: sub check_if_partid_hidden {
13310: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13311: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13312: $symb,$udom,$uname);
1.141 albertel 13313: my $truth=1;
13314: #if the string starts with !, then the list is the list to show not hide
13315: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13316: my @hiddenlist=split(/,/,$hiddenparts);
13317: foreach my $checkid (@hiddenlist) {
1.141 albertel 13318: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13319: }
1.141 albertel 13320: return !$truth;
1.84 albertel 13321: }
1.127 matthew 13322:
1.138 matthew 13323:
13324: ############################################################
13325: ############################################################
13326:
13327: =pod
13328:
1.157 matthew 13329: =back
13330:
1.138 matthew 13331: =head1 cgi-bin script and graphing routines
13332:
1.157 matthew 13333: =over 4
13334:
1.648 raeburn 13335: =item * &get_cgi_id()
1.138 matthew 13336:
13337: Inputs: none
13338:
13339: Returns an id which can be used to pass environment variables
13340: to various cgi-bin scripts. These environment variables will
13341: be removed from the users environment after a given time by
13342: the routine &Apache::lonnet::transfer_profile_to_env.
13343:
13344: =cut
13345:
13346: ############################################################
13347: ############################################################
1.152 albertel 13348: my $uniq=0;
1.136 matthew 13349: sub get_cgi_id {
1.154 albertel 13350: $uniq=($uniq+1)%100000;
1.280 albertel 13351: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13352: }
13353:
1.127 matthew 13354: ############################################################
13355: ############################################################
13356:
13357: =pod
13358:
1.648 raeburn 13359: =item * &DrawBarGraph()
1.127 matthew 13360:
1.138 matthew 13361: Facilitates the plotting of data in a (stacked) bar graph.
13362: Puts plot definition data into the users environment in order for
13363: graph.png to plot it. Returns an <img> tag for the plot.
13364: The bars on the plot are labeled '1','2',...,'n'.
13365:
13366: Inputs:
13367:
13368: =over 4
13369:
13370: =item $Title: string, the title of the plot
13371:
13372: =item $xlabel: string, text describing the X-axis of the plot
13373:
13374: =item $ylabel: string, text describing the Y-axis of the plot
13375:
13376: =item $Max: scalar, the maximum Y value to use in the plot
13377: If $Max is < any data point, the graph will not be rendered.
13378:
1.140 matthew 13379: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13380: they are plotted. If undefined, default values will be used.
13381:
1.178 matthew 13382: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13383:
1.138 matthew 13384: =item @Values: An array of array references. Each array reference holds data
13385: to be plotted in a stacked bar chart.
13386:
1.239 matthew 13387: =item If the final element of @Values is a hash reference the key/value
13388: pairs will be added to the graph definition.
13389:
1.138 matthew 13390: =back
13391:
13392: Returns:
13393:
13394: An <img> tag which references graph.png and the appropriate identifying
13395: information for the plot.
13396:
1.127 matthew 13397: =cut
13398:
13399: ############################################################
13400: ############################################################
1.134 matthew 13401: sub DrawBarGraph {
1.178 matthew 13402: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13403: #
13404: if (! defined($colors)) {
13405: $colors = ['#33ff00',
13406: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13407: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13408: ];
13409: }
1.228 matthew 13410: my $extra_settings = {};
13411: if (ref($Values[-1]) eq 'HASH') {
13412: $extra_settings = pop(@Values);
13413: }
1.127 matthew 13414: #
1.136 matthew 13415: my $identifier = &get_cgi_id();
13416: my $id = 'cgi.'.$identifier;
1.129 matthew 13417: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13418: return '';
13419: }
1.225 matthew 13420: #
13421: my @Labels;
13422: if (defined($labels)) {
13423: @Labels = @$labels;
13424: } else {
13425: for (my $i=0;$i<@{$Values[0]};$i++) {
13426: push (@Labels,$i+1);
13427: }
13428: }
13429: #
1.129 matthew 13430: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13431: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13432: my %ValuesHash;
13433: my $NumSets=1;
13434: foreach my $array (@Values) {
13435: next if (! ref($array));
1.136 matthew 13436: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13437: join(',',@$array);
1.129 matthew 13438: }
1.127 matthew 13439: #
1.136 matthew 13440: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13441: if ($NumBars < 3) {
13442: $width = 120+$NumBars*32;
1.220 matthew 13443: $xskip = 1;
1.225 matthew 13444: $bar_width = 30;
13445: } elsif ($NumBars < 5) {
13446: $width = 120+$NumBars*20;
13447: $xskip = 1;
13448: $bar_width = 20;
1.220 matthew 13449: } elsif ($NumBars < 10) {
1.136 matthew 13450: $width = 120+$NumBars*15;
13451: $xskip = 1;
13452: $bar_width = 15;
13453: } elsif ($NumBars <= 25) {
13454: $width = 120+$NumBars*11;
13455: $xskip = 5;
13456: $bar_width = 8;
13457: } elsif ($NumBars <= 50) {
13458: $width = 120+$NumBars*8;
13459: $xskip = 5;
13460: $bar_width = 4;
13461: } else {
13462: $width = 120+$NumBars*8;
13463: $xskip = 5;
13464: $bar_width = 4;
13465: }
13466: #
1.137 matthew 13467: $Max = 1 if ($Max < 1);
13468: if ( int($Max) < $Max ) {
13469: $Max++;
13470: $Max = int($Max);
13471: }
1.127 matthew 13472: $Title = '' if (! defined($Title));
13473: $xlabel = '' if (! defined($xlabel));
13474: $ylabel = '' if (! defined($ylabel));
1.369 www 13475: $ValuesHash{$id.'.title'} = &escape($Title);
13476: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13477: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13478: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13479: $ValuesHash{$id.'.NumBars'} = $NumBars;
13480: $ValuesHash{$id.'.NumSets'} = $NumSets;
13481: $ValuesHash{$id.'.PlotType'} = 'bar';
13482: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13483: $ValuesHash{$id.'.height'} = $height;
13484: $ValuesHash{$id.'.width'} = $width;
13485: $ValuesHash{$id.'.xskip'} = $xskip;
13486: $ValuesHash{$id.'.bar_width'} = $bar_width;
13487: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13488: #
1.228 matthew 13489: # Deal with other parameters
13490: while (my ($key,$value) = each(%$extra_settings)) {
13491: $ValuesHash{$id.'.'.$key} = $value;
13492: }
13493: #
1.646 raeburn 13494: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13495: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13496: }
13497:
13498: ############################################################
13499: ############################################################
13500:
13501: =pod
13502:
1.648 raeburn 13503: =item * &DrawXYGraph()
1.137 matthew 13504:
1.138 matthew 13505: Facilitates the plotting of data in an XY graph.
13506: Puts plot definition data into the users environment in order for
13507: graph.png to plot it. Returns an <img> tag for the plot.
13508:
13509: Inputs:
13510:
13511: =over 4
13512:
13513: =item $Title: string, the title of the plot
13514:
13515: =item $xlabel: string, text describing the X-axis of the plot
13516:
13517: =item $ylabel: string, text describing the Y-axis of the plot
13518:
13519: =item $Max: scalar, the maximum Y value to use in the plot
13520: If $Max is < any data point, the graph will not be rendered.
13521:
13522: =item $colors: Array ref containing the hex color codes for the data to be
13523: plotted in. If undefined, default values will be used.
13524:
13525: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13526:
13527: =item $Ydata: Array ref containing Array refs.
1.185 www 13528: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13529:
13530: =item %Values: hash indicating or overriding any default values which are
13531: passed to graph.png.
13532: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13533:
13534: =back
13535:
13536: Returns:
13537:
13538: An <img> tag which references graph.png and the appropriate identifying
13539: information for the plot.
13540:
1.137 matthew 13541: =cut
13542:
13543: ############################################################
13544: ############################################################
13545: sub DrawXYGraph {
13546: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13547: #
13548: # Create the identifier for the graph
13549: my $identifier = &get_cgi_id();
13550: my $id = 'cgi.'.$identifier;
13551: #
13552: $Title = '' if (! defined($Title));
13553: $xlabel = '' if (! defined($xlabel));
13554: $ylabel = '' if (! defined($ylabel));
13555: my %ValuesHash =
13556: (
1.369 www 13557: $id.'.title' => &escape($Title),
13558: $id.'.xlabel' => &escape($xlabel),
13559: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13560: $id.'.y_max_value'=> $Max,
13561: $id.'.labels' => join(',',@$Xlabels),
13562: $id.'.PlotType' => 'XY',
13563: );
13564: #
13565: if (defined($colors) && ref($colors) eq 'ARRAY') {
13566: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13567: }
13568: #
13569: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13570: return '';
13571: }
13572: my $NumSets=1;
1.138 matthew 13573: foreach my $array (@{$Ydata}){
1.137 matthew 13574: next if (! ref($array));
13575: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13576: }
1.138 matthew 13577: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13578: #
13579: # Deal with other parameters
13580: while (my ($key,$value) = each(%Values)) {
13581: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13582: }
13583: #
1.646 raeburn 13584: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13585: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13586: }
13587:
13588: ############################################################
13589: ############################################################
13590:
13591: =pod
13592:
1.648 raeburn 13593: =item * &DrawXYYGraph()
1.138 matthew 13594:
13595: Facilitates the plotting of data in an XY graph with two Y axes.
13596: Puts plot definition data into the users environment in order for
13597: graph.png to plot it. Returns an <img> tag for the plot.
13598:
13599: Inputs:
13600:
13601: =over 4
13602:
13603: =item $Title: string, the title of the plot
13604:
13605: =item $xlabel: string, text describing the X-axis of the plot
13606:
13607: =item $ylabel: string, text describing the Y-axis of the plot
13608:
13609: =item $colors: Array ref containing the hex color codes for the data to be
13610: plotted in. If undefined, default values will be used.
13611:
13612: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13613:
13614: =item $Ydata1: The first data set
13615:
13616: =item $Min1: The minimum value of the left Y-axis
13617:
13618: =item $Max1: The maximum value of the left Y-axis
13619:
13620: =item $Ydata2: The second data set
13621:
13622: =item $Min2: The minimum value of the right Y-axis
13623:
13624: =item $Max2: The maximum value of the left Y-axis
13625:
13626: =item %Values: hash indicating or overriding any default values which are
13627: passed to graph.png.
13628: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13629:
13630: =back
13631:
13632: Returns:
13633:
13634: An <img> tag which references graph.png and the appropriate identifying
13635: information for the plot.
1.136 matthew 13636:
13637: =cut
13638:
13639: ############################################################
13640: ############################################################
1.137 matthew 13641: sub DrawXYYGraph {
13642: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13643: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13644: #
13645: # Create the identifier for the graph
13646: my $identifier = &get_cgi_id();
13647: my $id = 'cgi.'.$identifier;
13648: #
13649: $Title = '' if (! defined($Title));
13650: $xlabel = '' if (! defined($xlabel));
13651: $ylabel = '' if (! defined($ylabel));
13652: my %ValuesHash =
13653: (
1.369 www 13654: $id.'.title' => &escape($Title),
13655: $id.'.xlabel' => &escape($xlabel),
13656: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13657: $id.'.labels' => join(',',@$Xlabels),
13658: $id.'.PlotType' => 'XY',
13659: $id.'.NumSets' => 2,
1.137 matthew 13660: $id.'.two_axes' => 1,
13661: $id.'.y1_max_value' => $Max1,
13662: $id.'.y1_min_value' => $Min1,
13663: $id.'.y2_max_value' => $Max2,
13664: $id.'.y2_min_value' => $Min2,
1.136 matthew 13665: );
13666: #
1.137 matthew 13667: if (defined($colors) && ref($colors) eq 'ARRAY') {
13668: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13669: }
13670: #
13671: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13672: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13673: return '';
13674: }
13675: my $NumSets=1;
1.137 matthew 13676: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13677: next if (! ref($array));
13678: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13679: }
13680: #
13681: # Deal with other parameters
13682: while (my ($key,$value) = each(%Values)) {
13683: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13684: }
13685: #
1.646 raeburn 13686: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13687: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13688: }
13689:
13690: ############################################################
13691: ############################################################
13692:
13693: =pod
13694:
1.157 matthew 13695: =back
13696:
1.139 matthew 13697: =head1 Statistics helper routines?
13698:
13699: Bad place for them but what the hell.
13700:
1.157 matthew 13701: =over 4
13702:
1.648 raeburn 13703: =item * &chartlink()
1.139 matthew 13704:
13705: Returns a link to the chart for a specific student.
13706:
13707: Inputs:
13708:
13709: =over 4
13710:
13711: =item $linktext: The text of the link
13712:
13713: =item $sname: The students username
13714:
13715: =item $sdomain: The students domain
13716:
13717: =back
13718:
1.157 matthew 13719: =back
13720:
1.139 matthew 13721: =cut
13722:
13723: ############################################################
13724: ############################################################
13725: sub chartlink {
13726: my ($linktext, $sname, $sdomain) = @_;
13727: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13728: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13729: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13730: '">'.$linktext.'</a>';
1.153 matthew 13731: }
13732:
13733: #######################################################
13734: #######################################################
13735:
13736: =pod
13737:
13738: =head1 Course Environment Routines
1.157 matthew 13739:
13740: =over 4
1.153 matthew 13741:
1.648 raeburn 13742: =item * &restore_course_settings()
1.153 matthew 13743:
1.648 raeburn 13744: =item * &store_course_settings()
1.153 matthew 13745:
13746: Restores/Store indicated form parameters from the course environment.
13747: Will not overwrite existing values of the form parameters.
13748:
13749: Inputs:
13750: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13751:
13752: a hash ref describing the data to be stored. For example:
13753:
13754: %Save_Parameters = ('Status' => 'scalar',
13755: 'chartoutputmode' => 'scalar',
13756: 'chartoutputdata' => 'scalar',
13757: 'Section' => 'array',
1.373 raeburn 13758: 'Group' => 'array',
1.153 matthew 13759: 'StudentData' => 'array',
13760: 'Maps' => 'array');
13761:
13762: Returns: both routines return nothing
13763:
1.631 raeburn 13764: =back
13765:
1.153 matthew 13766: =cut
13767:
13768: #######################################################
13769: #######################################################
13770: sub store_course_settings {
1.496 albertel 13771: return &store_settings($env{'request.course.id'},@_);
13772: }
13773:
13774: sub store_settings {
1.153 matthew 13775: # save to the environment
13776: # appenv the same items, just to be safe
1.300 albertel 13777: my $udom = $env{'user.domain'};
13778: my $uname = $env{'user.name'};
1.496 albertel 13779: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13780: my %SaveHash;
13781: my %AppHash;
13782: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13783: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13784: my $envname = 'environment.'.$basename;
1.258 albertel 13785: if (exists($env{'form.'.$setting})) {
1.153 matthew 13786: # Save this value away
13787: if ($type eq 'scalar' &&
1.258 albertel 13788: (! exists($env{$envname}) ||
13789: $env{$envname} ne $env{'form.'.$setting})) {
13790: $SaveHash{$basename} = $env{'form.'.$setting};
13791: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13792: } elsif ($type eq 'array') {
13793: my $stored_form;
1.258 albertel 13794: if (ref($env{'form.'.$setting})) {
1.153 matthew 13795: $stored_form = join(',',
13796: map {
1.369 www 13797: &escape($_);
1.258 albertel 13798: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13799: } else {
13800: $stored_form =
1.369 www 13801: &escape($env{'form.'.$setting});
1.153 matthew 13802: }
13803: # Determine if the array contents are the same.
1.258 albertel 13804: if ($stored_form ne $env{$envname}) {
1.153 matthew 13805: $SaveHash{$basename} = $stored_form;
13806: $AppHash{$envname} = $stored_form;
13807: }
13808: }
13809: }
13810: }
13811: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13812: $udom,$uname);
1.153 matthew 13813: if ($put_result !~ /^(ok|delayed)/) {
13814: &Apache::lonnet::logthis('unable to save form parameters, '.
13815: 'got error:'.$put_result);
13816: }
13817: # Make sure these settings stick around in this session, too
1.646 raeburn 13818: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13819: return;
13820: }
13821:
13822: sub restore_course_settings {
1.499 albertel 13823: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13824: }
13825:
13826: sub restore_settings {
13827: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13828: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13829: next if (exists($env{'form.'.$setting}));
1.496 albertel 13830: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13831: '.'.$setting;
1.258 albertel 13832: if (exists($env{$envname})) {
1.153 matthew 13833: if ($type eq 'scalar') {
1.258 albertel 13834: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13835: } elsif ($type eq 'array') {
1.258 albertel 13836: $env{'form.'.$setting} = [
1.153 matthew 13837: map {
1.369 www 13838: &unescape($_);
1.258 albertel 13839: } split(',',$env{$envname})
1.153 matthew 13840: ];
13841: }
13842: }
13843: }
1.127 matthew 13844: }
13845:
1.618 raeburn 13846: #######################################################
13847: #######################################################
13848:
13849: =pod
13850:
13851: =head1 Domain E-mail Routines
13852:
13853: =over 4
13854:
1.648 raeburn 13855: =item * &build_recipient_list()
1.618 raeburn 13856:
1.1144 raeburn 13857: Build recipient lists for following types of e-mail:
1.766 raeburn 13858: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 13859: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13860: module change checking, student/employee ID conflict checks, as
13861: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13862: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13863:
13864: Inputs:
1.619 raeburn 13865: defmail (scalar - email address of default recipient),
1.1144 raeburn 13866: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13867: requestsmail, updatesmail, or idconflictsmail).
13868:
1.619 raeburn 13869: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 13870:
1.619 raeburn 13871: origmail (scalar - email address of recipient from loncapa.conf,
13872: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13873:
1.655 raeburn 13874: Returns: comma separated list of addresses to which to send e-mail.
13875:
13876: =back
1.618 raeburn 13877:
13878: =cut
13879:
13880: ############################################################
13881: ############################################################
13882: sub build_recipient_list {
1.619 raeburn 13883: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13884: my @recipients;
13885: my $otheremails;
13886: my %domconfig =
13887: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13888: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13889: if (exists($domconfig{'contacts'}{$mailing})) {
13890: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13891: my @contacts = ('adminemail','supportemail');
13892: foreach my $item (@contacts) {
13893: if ($domconfig{'contacts'}{$mailing}{$item}) {
13894: my $addr = $domconfig{'contacts'}{$item};
13895: if (!grep(/^\Q$addr\E$/,@recipients)) {
13896: push(@recipients,$addr);
13897: }
1.619 raeburn 13898: }
1.766 raeburn 13899: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13900: }
13901: }
1.766 raeburn 13902: } elsif ($origmail ne '') {
13903: push(@recipients,$origmail);
1.618 raeburn 13904: }
1.619 raeburn 13905: } elsif ($origmail ne '') {
13906: push(@recipients,$origmail);
1.618 raeburn 13907: }
1.688 raeburn 13908: if (defined($defmail)) {
13909: if ($defmail ne '') {
13910: push(@recipients,$defmail);
13911: }
1.618 raeburn 13912: }
13913: if ($otheremails) {
1.619 raeburn 13914: my @others;
13915: if ($otheremails =~ /,/) {
13916: @others = split(/,/,$otheremails);
1.618 raeburn 13917: } else {
1.619 raeburn 13918: push(@others,$otheremails);
13919: }
13920: foreach my $addr (@others) {
13921: if (!grep(/^\Q$addr\E$/,@recipients)) {
13922: push(@recipients,$addr);
13923: }
1.618 raeburn 13924: }
13925: }
1.619 raeburn 13926: my $recipientlist = join(',',@recipients);
1.618 raeburn 13927: return $recipientlist;
13928: }
13929:
1.127 matthew 13930: ############################################################
13931: ############################################################
1.154 albertel 13932:
1.655 raeburn 13933: =pod
13934:
1.1224 musolffc 13935: =over 4
13936:
1.1223 musolffc 13937: =item * &mime_email()
13938:
13939: Sends an email with a possible attachment
13940:
13941: Inputs:
13942:
13943: =over 4
13944:
13945: from - Sender's email address
13946:
13947: to - Email address of recipient
13948:
13949: subject - Subject of email
13950:
13951: body - Body of email
13952:
13953: cc_string - Carbon copy email address
13954:
13955: bcc - Blind carbon copy email address
13956:
13957: type - File type of attachment
13958:
13959: attachment_path - Path of file to be attached
13960:
13961: file_name - Name of file to be attached
13962:
13963: attachment_text - The body of an attachment of type "TEXT"
13964:
13965: =back
13966:
13967: =back
13968:
13969: =cut
13970:
13971: ############################################################
13972: ############################################################
13973:
13974: sub mime_email {
13975: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
13976: $file_name, $attachment_text) = @_;
13977: my $msg = MIME::Lite->new(
13978: From => $from,
13979: To => $to,
13980: Subject => $subject,
13981: Type =>'TEXT',
13982: Data => $body,
13983: );
13984: if ($cc_string ne '') {
13985: $msg->add("Cc" => $cc_string);
13986: }
13987: if ($bcc ne '') {
13988: $msg->add("Bcc" => $bcc);
13989: }
13990: $msg->attr("content-type" => "text/plain");
13991: $msg->attr("content-type.charset" => "UTF-8");
13992: # Attach file if given
13993: if ($attachment_path) {
13994: unless ($file_name) {
13995: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
13996: }
13997: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
13998: $msg->attach(Type => $type,
13999: Path => $attachment_path,
14000: Filename => $file_name
14001: );
14002: # Otherwise attach text if given
14003: } elsif ($attachment_text) {
14004: $msg->attach(Type => 'TEXT',
14005: Data => $attachment_text);
14006: }
14007: # Send it
14008: $msg->send('sendmail');
14009: }
14010:
14011: ############################################################
14012: ############################################################
14013:
14014: =pod
14015:
1.655 raeburn 14016: =head1 Course Catalog Routines
14017:
14018: =over 4
14019:
14020: =item * &gather_categories()
14021:
14022: Converts category definitions - keys of categories hash stored in
14023: coursecategories in configuration.db on the primary library server in a
14024: domain - to an array. Also generates javascript and idx hash used to
14025: generate Domain Coordinator interface for editing Course Categories.
14026:
14027: Inputs:
1.663 raeburn 14028:
1.655 raeburn 14029: categories (reference to hash of category definitions).
1.663 raeburn 14030:
1.655 raeburn 14031: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14032: categories and subcategories).
1.663 raeburn 14033:
1.655 raeburn 14034: idx (reference to hash of counters used in Domain Coordinator interface for
14035: editing Course Categories).
1.663 raeburn 14036:
1.655 raeburn 14037: jsarray (reference to array of categories used to create Javascript arrays for
14038: Domain Coordinator interface for editing Course Categories).
14039:
14040: Returns: nothing
14041:
14042: Side effects: populates cats, idx and jsarray.
14043:
14044: =cut
14045:
14046: sub gather_categories {
14047: my ($categories,$cats,$idx,$jsarray) = @_;
14048: my %counters;
14049: my $num = 0;
14050: foreach my $item (keys(%{$categories})) {
14051: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14052: if ($container eq '' && $depth == 0) {
14053: $cats->[$depth][$categories->{$item}] = $cat;
14054: } else {
14055: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14056: }
14057: my ($escitem,$tail) = split(/:/,$item,2);
14058: if ($counters{$tail} eq '') {
14059: $counters{$tail} = $num;
14060: $num ++;
14061: }
14062: if (ref($idx) eq 'HASH') {
14063: $idx->{$item} = $counters{$tail};
14064: }
14065: if (ref($jsarray) eq 'ARRAY') {
14066: push(@{$jsarray->[$counters{$tail}]},$item);
14067: }
14068: }
14069: return;
14070: }
14071:
14072: =pod
14073:
14074: =item * &extract_categories()
14075:
14076: Used to generate breadcrumb trails for course categories.
14077:
14078: Inputs:
1.663 raeburn 14079:
1.655 raeburn 14080: categories (reference to hash of category definitions).
1.663 raeburn 14081:
1.655 raeburn 14082: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14083: categories and subcategories).
1.663 raeburn 14084:
1.655 raeburn 14085: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14086:
1.655 raeburn 14087: allitems (reference to hash - key is category key
14088: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14089:
1.655 raeburn 14090: idx (reference to hash of counters used in Domain Coordinator interface for
14091: editing Course Categories).
1.663 raeburn 14092:
1.655 raeburn 14093: jsarray (reference to array of categories used to create Javascript arrays for
14094: Domain Coordinator interface for editing Course Categories).
14095:
1.665 raeburn 14096: subcats (reference to hash of arrays containing all subcategories within each
14097: category, -recursive)
14098:
1.655 raeburn 14099: Returns: nothing
14100:
14101: Side effects: populates trails and allitems hash references.
14102:
14103: =cut
14104:
14105: sub extract_categories {
1.665 raeburn 14106: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14107: if (ref($categories) eq 'HASH') {
14108: &gather_categories($categories,$cats,$idx,$jsarray);
14109: if (ref($cats->[0]) eq 'ARRAY') {
14110: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14111: my $name = $cats->[0][$i];
14112: my $item = &escape($name).'::0';
14113: my $trailstr;
14114: if ($name eq 'instcode') {
14115: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14116: } elsif ($name eq 'communities') {
14117: $trailstr = &mt('Communities');
1.655 raeburn 14118: } else {
14119: $trailstr = $name;
14120: }
14121: if ($allitems->{$item} eq '') {
14122: push(@{$trails},$trailstr);
14123: $allitems->{$item} = scalar(@{$trails})-1;
14124: }
14125: my @parents = ($name);
14126: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14127: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14128: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14129: if (ref($subcats) eq 'HASH') {
14130: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14131: }
14132: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14133: }
14134: } else {
14135: if (ref($subcats) eq 'HASH') {
14136: $subcats->{$item} = [];
1.655 raeburn 14137: }
14138: }
14139: }
14140: }
14141: }
14142: return;
14143: }
14144:
14145: =pod
14146:
1.1162 raeburn 14147: =item * &recurse_categories()
1.655 raeburn 14148:
14149: Recursively used to generate breadcrumb trails for course categories.
14150:
14151: Inputs:
1.663 raeburn 14152:
1.655 raeburn 14153: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14154: categories and subcategories).
1.663 raeburn 14155:
1.655 raeburn 14156: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14157:
14158: category (current course category, for which breadcrumb trail is being generated).
14159:
14160: trails (reference to array of breadcrumb trails for each category).
14161:
1.655 raeburn 14162: allitems (reference to hash - key is category key
14163: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14164:
1.655 raeburn 14165: parents (array containing containers directories for current category,
14166: back to top level).
14167:
14168: Returns: nothing
14169:
14170: Side effects: populates trails and allitems hash references
14171:
14172: =cut
14173:
14174: sub recurse_categories {
1.665 raeburn 14175: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14176: my $shallower = $depth - 1;
14177: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14178: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14179: my $name = $cats->[$depth]{$category}[$k];
14180: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14181: my $trailstr = join(' -> ',(@{$parents},$category));
14182: if ($allitems->{$item} eq '') {
14183: push(@{$trails},$trailstr);
14184: $allitems->{$item} = scalar(@{$trails})-1;
14185: }
14186: my $deeper = $depth+1;
14187: push(@{$parents},$category);
1.665 raeburn 14188: if (ref($subcats) eq 'HASH') {
14189: my $subcat = &escape($name).':'.$category.':'.$depth;
14190: for (my $j=@{$parents}; $j>=0; $j--) {
14191: my $higher;
14192: if ($j > 0) {
14193: $higher = &escape($parents->[$j]).':'.
14194: &escape($parents->[$j-1]).':'.$j;
14195: } else {
14196: $higher = &escape($parents->[$j]).'::'.$j;
14197: }
14198: push(@{$subcats->{$higher}},$subcat);
14199: }
14200: }
14201: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14202: $subcats);
1.655 raeburn 14203: pop(@{$parents});
14204: }
14205: } else {
14206: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14207: my $trailstr = join(' -> ',(@{$parents},$category));
14208: if ($allitems->{$item} eq '') {
14209: push(@{$trails},$trailstr);
14210: $allitems->{$item} = scalar(@{$trails})-1;
14211: }
14212: }
14213: return;
14214: }
14215:
1.663 raeburn 14216: =pod
14217:
1.1162 raeburn 14218: =item * &assign_categories_table()
1.663 raeburn 14219:
14220: Create a datatable for display of hierarchical categories in a domain,
14221: with checkboxes to allow a course to be categorized.
14222:
14223: Inputs:
14224:
14225: cathash - reference to hash of categories defined for the domain (from
14226: configuration.db)
14227:
14228: currcat - scalar with an & separated list of categories assigned to a course.
14229:
1.919 raeburn 14230: type - scalar contains course type (Course or Community).
14231:
1.663 raeburn 14232: Returns: $output (markup to be displayed)
14233:
14234: =cut
14235:
14236: sub assign_categories_table {
1.919 raeburn 14237: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 14238: my $output;
14239: if (ref($cathash) eq 'HASH') {
14240: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
14241: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
14242: $maxdepth = scalar(@cats);
14243: if (@cats > 0) {
14244: my $itemcount = 0;
14245: if (ref($cats[0]) eq 'ARRAY') {
14246: my @currcategories;
14247: if ($currcat ne '') {
14248: @currcategories = split('&',$currcat);
14249: }
1.919 raeburn 14250: my $table;
1.663 raeburn 14251: for (my $i=0; $i<@{$cats[0]}; $i++) {
14252: my $parent = $cats[0][$i];
1.919 raeburn 14253: next if ($parent eq 'instcode');
14254: if ($type eq 'Community') {
14255: next unless ($parent eq 'communities');
14256: } else {
14257: next if ($parent eq 'communities');
14258: }
1.663 raeburn 14259: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14260: my $item = &escape($parent).'::0';
14261: my $checked = '';
14262: if (@currcategories > 0) {
14263: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14264: $checked = ' checked="checked"';
1.663 raeburn 14265: }
14266: }
1.919 raeburn 14267: my $parent_title = $parent;
14268: if ($parent eq 'communities') {
14269: $parent_title = &mt('Communities');
14270: }
14271: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14272: '<input type="checkbox" name="usecategory" value="'.
14273: $item.'"'.$checked.' />'.$parent_title.'</span>'.
14274: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14275: my $depth = 1;
14276: push(@path,$parent);
1.919 raeburn 14277: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 14278: pop(@path);
1.919 raeburn 14279: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14280: $itemcount ++;
14281: }
1.919 raeburn 14282: if ($itemcount) {
14283: $output = &Apache::loncommon::start_data_table().
14284: $table.
14285: &Apache::loncommon::end_data_table();
14286: }
1.663 raeburn 14287: }
14288: }
14289: }
14290: return $output;
14291: }
14292:
14293: =pod
14294:
1.1162 raeburn 14295: =item * &assign_category_rows()
1.663 raeburn 14296:
14297: Create a datatable row for display of nested categories in a domain,
14298: with checkboxes to allow a course to be categorized,called recursively.
14299:
14300: Inputs:
14301:
14302: itemcount - track row number for alternating colors
14303:
14304: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14305: categories and subcategories.
14306:
14307: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14308:
14309: parent - parent of current category item
14310:
14311: path - Array containing all categories back up through the hierarchy from the
14312: current category to the top level.
14313:
14314: currcategories - reference to array of current categories assigned to the course
14315:
14316: Returns: $output (markup to be displayed).
14317:
14318: =cut
14319:
14320: sub assign_category_rows {
14321: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
14322: my ($text,$name,$item,$chgstr);
14323: if (ref($cats) eq 'ARRAY') {
14324: my $maxdepth = scalar(@{$cats});
14325: if (ref($cats->[$depth]) eq 'HASH') {
14326: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14327: my $numchildren = @{$cats->[$depth]{$parent}};
14328: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 14329: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14330: for (my $j=0; $j<$numchildren; $j++) {
14331: $name = $cats->[$depth]{$parent}[$j];
14332: $item = &escape($name).':'.&escape($parent).':'.$depth;
14333: my $deeper = $depth+1;
14334: my $checked = '';
14335: if (ref($currcategories) eq 'ARRAY') {
14336: if (@{$currcategories} > 0) {
14337: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14338: $checked = ' checked="checked"';
1.663 raeburn 14339: }
14340: }
14341: }
1.664 raeburn 14342: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14343: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 14344: $item.'"'.$checked.' />'.$name.'</label></span>'.
14345: '<input type="hidden" name="catname" value="'.$name.'" />'.
14346: '</td><td>';
1.663 raeburn 14347: if (ref($path) eq 'ARRAY') {
14348: push(@{$path},$name);
14349: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
14350: pop(@{$path});
14351: }
14352: $text .= '</td></tr>';
14353: }
14354: $text .= '</table></td>';
14355: }
14356: }
14357: }
14358: return $text;
14359: }
14360:
1.1181 raeburn 14361: =pod
14362:
14363: =back
14364:
14365: =cut
14366:
1.655 raeburn 14367: ############################################################
14368: ############################################################
14369:
14370:
1.443 albertel 14371: sub commit_customrole {
1.664 raeburn 14372: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14373: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14374: ($start?', '.&mt('starting').' '.localtime($start):'').
14375: ($end?', ending '.localtime($end):'').': <b>'.
14376: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14377: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14378: '</b><br />';
14379: return $output;
14380: }
14381:
14382: sub commit_standardrole {
1.1116 raeburn 14383: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14384: my ($output,$logmsg,$linefeed);
14385: if ($context eq 'auto') {
14386: $linefeed = "\n";
14387: } else {
14388: $linefeed = "<br />\n";
14389: }
1.443 albertel 14390: if ($three eq 'st') {
1.541 raeburn 14391: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 14392: $one,$two,$sec,$context,$credits);
1.541 raeburn 14393: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14394: ($result eq 'unknown_course') || ($result eq 'refused')) {
14395: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14396: } else {
1.541 raeburn 14397: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14398: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14399: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14400: if ($context eq 'auto') {
14401: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14402: } else {
14403: $output .= '<b>'.$result.'</b>'.$linefeed.
14404: &mt('Add to classlist').': <b>ok</b>';
14405: }
14406: $output .= $linefeed;
1.443 albertel 14407: }
14408: } else {
14409: $output = &mt('Assigning').' '.$three.' in '.$url.
14410: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14411: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14412: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14413: if ($context eq 'auto') {
14414: $output .= $result.$linefeed;
14415: } else {
14416: $output .= '<b>'.$result.'</b>'.$linefeed;
14417: }
1.443 albertel 14418: }
14419: return $output;
14420: }
14421:
14422: sub commit_studentrole {
1.1116 raeburn 14423: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14424: $credits) = @_;
1.626 raeburn 14425: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14426: if ($context eq 'auto') {
14427: $linefeed = "\n";
14428: } else {
14429: $linefeed = '<br />'."\n";
14430: }
1.443 albertel 14431: if (defined($one) && defined($two)) {
14432: my $cid=$one.'_'.$two;
14433: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14434: my $secchange = 0;
14435: my $expire_role_result;
14436: my $modify_section_result;
1.628 raeburn 14437: if ($oldsec ne '-1') {
14438: if ($oldsec ne $sec) {
1.443 albertel 14439: $secchange = 1;
1.628 raeburn 14440: my $now = time;
1.443 albertel 14441: my $uurl='/'.$cid;
14442: $uurl=~s/\_/\//g;
14443: if ($oldsec) {
14444: $uurl.='/'.$oldsec;
14445: }
1.626 raeburn 14446: $oldsecurl = $uurl;
1.628 raeburn 14447: $expire_role_result =
1.652 raeburn 14448: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14449: if ($env{'request.course.sec'} ne '') {
14450: if ($expire_role_result eq 'refused') {
14451: my @roles = ('st');
14452: my @statuses = ('previous');
14453: my @roledoms = ($one);
14454: my $withsec = 1;
14455: my %roleshash =
14456: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14457: \@statuses,\@roles,\@roledoms,$withsec);
14458: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14459: my ($oldstart,$oldend) =
14460: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14461: if ($oldend > 0 && $oldend <= $now) {
14462: $expire_role_result = 'ok';
14463: }
14464: }
14465: }
14466: }
1.443 albertel 14467: $result = $expire_role_result;
14468: }
14469: }
14470: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 14471: $modify_section_result =
14472: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14473: undef,undef,undef,$sec,
14474: $end,$start,'','',$cid,
14475: '',$context,$credits);
1.443 albertel 14476: if ($modify_section_result =~ /^ok/) {
14477: if ($secchange == 1) {
1.628 raeburn 14478: if ($sec eq '') {
14479: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14480: } else {
14481: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14482: }
1.443 albertel 14483: } elsif ($oldsec eq '-1') {
1.628 raeburn 14484: if ($sec eq '') {
14485: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14486: } else {
14487: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14488: }
1.443 albertel 14489: } else {
1.628 raeburn 14490: if ($sec eq '') {
14491: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14492: } else {
14493: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14494: }
1.443 albertel 14495: }
14496: } else {
1.1115 raeburn 14497: if ($secchange) {
1.628 raeburn 14498: $$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;
14499: } else {
14500: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14501: }
1.443 albertel 14502: }
14503: $result = $modify_section_result;
14504: } elsif ($secchange == 1) {
1.628 raeburn 14505: if ($oldsec eq '') {
1.1103 raeburn 14506: $$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 14507: } else {
14508: $$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;
14509: }
1.626 raeburn 14510: if ($expire_role_result eq 'refused') {
14511: my $newsecurl = '/'.$cid;
14512: $newsecurl =~ s/\_/\//g;
14513: if ($sec ne '') {
14514: $newsecurl.='/'.$sec;
14515: }
14516: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14517: if ($sec eq '') {
14518: $$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;
14519: } else {
14520: $$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;
14521: }
14522: }
14523: }
1.443 albertel 14524: }
14525: } else {
1.626 raeburn 14526: $$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 14527: $result = "error: incomplete course id\n";
14528: }
14529: return $result;
14530: }
14531:
1.1108 raeburn 14532: sub show_role_extent {
14533: my ($scope,$context,$role) = @_;
14534: $scope =~ s{^/}{};
14535: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14536: push(@courseroles,'co');
14537: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14538: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14539: $scope =~ s{/}{_};
14540: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14541: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14542: my ($audom,$auname) = split(/\//,$scope);
14543: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14544: &Apache::loncommon::plainname($auname,$audom).'</span>');
14545: } else {
14546: $scope =~ s{/$}{};
14547: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14548: &Apache::lonnet::domain($scope,'description').'</span>');
14549: }
14550: }
14551:
1.443 albertel 14552: ############################################################
14553: ############################################################
14554:
1.566 albertel 14555: sub check_clone {
1.578 raeburn 14556: my ($args,$linefeed) = @_;
1.566 albertel 14557: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14558: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14559: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14560: my $clonemsg;
14561: my $can_clone = 0;
1.944 raeburn 14562: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14563: if ($lctype ne 'community') {
14564: $lctype = 'course';
14565: }
1.566 albertel 14566: if ($clonehome eq 'no_host') {
1.944 raeburn 14567: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14568: $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'});
14569: } else {
14570: $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'});
14571: }
1.566 albertel 14572: } else {
14573: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 14574: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14575: if ($clonedesc{'type'} ne 'Community') {
14576: $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'});
14577: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14578: }
14579: }
1.882 raeburn 14580: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
14581: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 14582: $can_clone = 1;
14583: } else {
1.1221 raeburn 14584: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 14585: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 14586: if ($clonehash{'cloners'} eq '') {
14587: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
14588: if ($domdefs{'canclone'}) {
14589: unless ($domdefs{'canclone'} eq 'none') {
14590: if ($domdefs{'canclone'} eq 'domain') {
14591: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
14592: $can_clone = 1;
14593: }
14594: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14595: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
14596: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
14597: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
14598: $can_clone = 1;
14599: }
14600: }
14601: }
14602: }
1.578 raeburn 14603: } else {
1.1221 raeburn 14604: my @cloners = split(/,/,$clonehash{'cloners'});
14605: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 14606: $can_clone = 1;
1.1221 raeburn 14607: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 14608: $can_clone = 1;
1.1225 raeburn 14609: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
14610: $can_clone = 1;
1.1221 raeburn 14611: }
14612: unless ($can_clone) {
1.1225 raeburn 14613: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14614: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 14615: my (%gotdomdefaults,%gotcodedefaults);
14616: foreach my $cloner (@cloners) {
14617: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
14618: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
14619: my (%codedefaults,@code_order);
14620: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
14621: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
14622: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
14623: }
14624: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
14625: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
14626: }
14627: } else {
14628: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
14629: \%codedefaults,
14630: \@code_order);
14631: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
14632: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
14633: }
14634: if (@code_order > 0) {
14635: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
14636: $cloner,$clonehash{'internal.coursecode'},
14637: $args->{'crscode'})) {
14638: $can_clone = 1;
14639: last;
14640: }
14641: }
14642: }
14643: }
14644: }
1.1225 raeburn 14645: }
14646: }
14647: unless ($can_clone) {
14648: my $ccrole = 'cc';
14649: if ($args->{'crstype'} eq 'Community') {
14650: $ccrole = 'co';
14651: }
14652: my %roleshash =
14653: &Apache::lonnet::get_my_roles($args->{'ccuname'},
14654: $args->{'ccdomain'},
14655: 'userroles',['active'],[$ccrole],
14656: [$args->{'clonedomain'}]);
14657: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
14658: $can_clone = 1;
14659: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
14660: $args->{'ccuname'},$args->{'ccdomain'})) {
14661: $can_clone = 1;
1.1221 raeburn 14662: }
14663: }
14664: unless ($can_clone) {
14665: if ($args->{'crstype'} eq 'Community') {
14666: $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 14667: } else {
1.1221 raeburn 14668: $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'});
14669: }
1.566 albertel 14670: }
1.578 raeburn 14671: }
1.566 albertel 14672: }
14673: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14674: }
14675:
1.444 albertel 14676: sub construct_course {
1.1166 raeburn 14677: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 14678: my $outcome;
1.541 raeburn 14679: my $linefeed = '<br />'."\n";
14680: if ($context eq 'auto') {
14681: $linefeed = "\n";
14682: }
1.566 albertel 14683:
14684: #
14685: # Are we cloning?
14686: #
14687: my ($can_clone, $clonemsg, $cloneid, $clonehome);
14688: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 14689: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 14690: if ($context ne 'auto') {
1.578 raeburn 14691: if ($clonemsg ne '') {
14692: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
14693: }
1.566 albertel 14694: }
14695: $outcome .= $clonemsg.$linefeed;
14696:
14697: if (!$can_clone) {
14698: return (0,$outcome);
14699: }
14700: }
14701:
1.444 albertel 14702: #
14703: # Open course
14704: #
14705: my $crstype = lc($args->{'crstype'});
14706: my %cenv=();
14707: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
14708: $args->{'cdescr'},
14709: $args->{'curl'},
14710: $args->{'course_home'},
14711: $args->{'nonstandard'},
14712: $args->{'crscode'},
14713: $args->{'ccuname'}.':'.
14714: $args->{'ccdomain'},
1.882 raeburn 14715: $args->{'crstype'},
1.885 raeburn 14716: $cnum,$context,$category);
1.444 albertel 14717:
14718: # Note: The testing routines depend on this being output; see
14719: # Utils::Course. This needs to at least be output as a comment
14720: # if anyone ever decides to not show this, and Utils::Course::new
14721: # will need to be suitably modified.
1.541 raeburn 14722: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 14723: if ($$courseid =~ /^error:/) {
14724: return (0,$outcome);
14725: }
14726:
1.444 albertel 14727: #
14728: # Check if created correctly
14729: #
1.479 albertel 14730: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 14731: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 14732: if ($crsuhome eq 'no_host') {
14733: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
14734: return (0,$outcome);
14735: }
1.541 raeburn 14736: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 14737:
1.444 albertel 14738: #
1.566 albertel 14739: # Do the cloning
14740: #
14741: if ($can_clone && $cloneid) {
14742: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14743: if ($context ne 'auto') {
14744: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14745: }
14746: $outcome .= $clonemsg.$linefeed;
14747: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14748: # Copy all files
1.637 www 14749: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14750: # Restore URL
1.566 albertel 14751: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14752: # Restore title
1.566 albertel 14753: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14754: # Restore creation date, creator and creation context.
14755: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14756: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14757: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14758: # Mark as cloned
1.566 albertel 14759: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14760: # Need to clone grading mode
14761: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14762: $cenv{'grading'}=$newenv{'grading'};
14763: # Do not clone these environment entries
14764: &Apache::lonnet::del('environment',
14765: ['default_enrollment_start_date',
14766: 'default_enrollment_end_date',
14767: 'question.email',
14768: 'policy.email',
14769: 'comment.email',
14770: 'pch.users.denied',
1.725 raeburn 14771: 'plc.users.denied',
14772: 'hidefromcat',
1.1121 raeburn 14773: 'checkforpriv',
1.1166 raeburn 14774: 'categories',
14775: 'internal.uniquecode'],
1.638 www 14776: $$crsudom,$$crsunum);
1.1170 raeburn 14777: if ($args->{'textbook'}) {
14778: $cenv{'internal.textbook'} = $args->{'textbook'};
14779: }
1.444 albertel 14780: }
1.566 albertel 14781:
1.444 albertel 14782: #
14783: # Set environment (will override cloned, if existing)
14784: #
14785: my @sections = ();
14786: my @xlists = ();
14787: if ($args->{'crstype'}) {
14788: $cenv{'type'}=$args->{'crstype'};
14789: }
14790: if ($args->{'crsid'}) {
14791: $cenv{'courseid'}=$args->{'crsid'};
14792: }
14793: if ($args->{'crscode'}) {
14794: $cenv{'internal.coursecode'}=$args->{'crscode'};
14795: }
14796: if ($args->{'crsquota'} ne '') {
14797: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14798: } else {
14799: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14800: }
14801: if ($args->{'ccuname'}) {
14802: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14803: ':'.$args->{'ccdomain'};
14804: } else {
14805: $cenv{'internal.courseowner'} = $args->{'curruser'};
14806: }
1.1116 raeburn 14807: if ($args->{'defaultcredits'}) {
14808: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14809: }
1.444 albertel 14810: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14811: if ($args->{'crssections'}) {
14812: $cenv{'internal.sectionnums'} = '';
14813: if ($args->{'crssections'} =~ m/,/) {
14814: @sections = split/,/,$args->{'crssections'};
14815: } else {
14816: $sections[0] = $args->{'crssections'};
14817: }
14818: if (@sections > 0) {
14819: foreach my $item (@sections) {
14820: my ($sec,$gp) = split/:/,$item;
14821: my $class = $args->{'crscode'}.$sec;
14822: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14823: $cenv{'internal.sectionnums'} .= $item.',';
14824: unless ($addcheck eq 'ok') {
14825: push @badclasses, $class;
14826: }
14827: }
14828: $cenv{'internal.sectionnums'} =~ s/,$//;
14829: }
14830: }
14831: # do not hide course coordinator from staff listing,
14832: # even if privileged
14833: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 14834: # add course coordinator's domain to domains to check for privileged users
14835: # if different to course domain
14836: if ($$crsudom ne $args->{'ccdomain'}) {
14837: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14838: }
1.444 albertel 14839: # add crosslistings
14840: if ($args->{'crsxlist'}) {
14841: $cenv{'internal.crosslistings'}='';
14842: if ($args->{'crsxlist'} =~ m/,/) {
14843: @xlists = split/,/,$args->{'crsxlist'};
14844: } else {
14845: $xlists[0] = $args->{'crsxlist'};
14846: }
14847: if (@xlists > 0) {
14848: foreach my $item (@xlists) {
14849: my ($xl,$gp) = split/:/,$item;
14850: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14851: $cenv{'internal.crosslistings'} .= $item.',';
14852: unless ($addcheck eq 'ok') {
14853: push @badclasses, $xl;
14854: }
14855: }
14856: $cenv{'internal.crosslistings'} =~ s/,$//;
14857: }
14858: }
14859: if ($args->{'autoadds'}) {
14860: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14861: }
14862: if ($args->{'autodrops'}) {
14863: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14864: }
14865: # check for notification of enrollment changes
14866: my @notified = ();
14867: if ($args->{'notify_owner'}) {
14868: if ($args->{'ccuname'} ne '') {
14869: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14870: }
14871: }
14872: if ($args->{'notify_dc'}) {
14873: if ($uname ne '') {
1.630 raeburn 14874: push(@notified,$uname.':'.$udom);
1.444 albertel 14875: }
14876: }
14877: if (@notified > 0) {
14878: my $notifylist;
14879: if (@notified > 1) {
14880: $notifylist = join(',',@notified);
14881: } else {
14882: $notifylist = $notified[0];
14883: }
14884: $cenv{'internal.notifylist'} = $notifylist;
14885: }
14886: if (@badclasses > 0) {
14887: my %lt=&Apache::lonlocal::texthash(
14888: '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',
14889: 'dnhr' => 'does not have rights to access enrollment in these classes',
14890: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14891: );
1.541 raeburn 14892: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14893: ' ('.$lt{'adby'}.')';
14894: if ($context eq 'auto') {
14895: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14896: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14897: foreach my $item (@badclasses) {
14898: if ($context eq 'auto') {
14899: $outcome .= " - $item\n";
14900: } else {
14901: $outcome .= "<li>$item</li>\n";
14902: }
14903: }
14904: if ($context eq 'auto') {
14905: $outcome .= $linefeed;
14906: } else {
1.566 albertel 14907: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14908: }
14909: }
1.444 albertel 14910: }
14911: if ($args->{'no_end_date'}) {
14912: $args->{'endaccess'} = 0;
14913: }
14914: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14915: $cenv{'internal.autoend'}=$args->{'enrollend'};
14916: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14917: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14918: if ($args->{'showphotos'}) {
14919: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14920: }
14921: $cenv{'internal.authtype'} = $args->{'authtype'};
14922: $cenv{'internal.autharg'} = $args->{'autharg'};
14923: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14924: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14925: 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');
14926: if ($context eq 'auto') {
14927: $outcome .= $krb_msg;
14928: } else {
1.566 albertel 14929: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14930: }
14931: $outcome .= $linefeed;
1.444 albertel 14932: }
14933: }
14934: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14935: if ($args->{'setpolicy'}) {
14936: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14937: }
14938: if ($args->{'setcontent'}) {
14939: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14940: }
14941: }
14942: if ($args->{'reshome'}) {
14943: $cenv{'reshome'}=$args->{'reshome'}.'/';
14944: $cenv{'reshome'}=~s/\/+$/\//;
14945: }
14946: #
14947: # course has keyed access
14948: #
14949: if ($args->{'setkeys'}) {
14950: $cenv{'keyaccess'}='yes';
14951: }
14952: # if specified, key authority is not course, but user
14953: # only active if keyaccess is yes
14954: if ($args->{'keyauth'}) {
1.487 albertel 14955: my ($user,$domain) = split(':',$args->{'keyauth'});
14956: $user = &LONCAPA::clean_username($user);
14957: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14958: if ($user ne '' && $domain ne '') {
1.487 albertel 14959: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14960: }
14961: }
14962:
1.1166 raeburn 14963: #
1.1167 raeburn 14964: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 14965: #
14966: if ($args->{'uniquecode'}) {
14967: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14968: if ($code) {
14969: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 14970: my %crsinfo =
14971: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
14972: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
14973: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
14974: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
14975: }
1.1166 raeburn 14976: if (ref($coderef)) {
14977: $$coderef = $code;
14978: }
14979: }
14980: }
14981:
1.444 albertel 14982: if ($args->{'disresdis'}) {
14983: $cenv{'pch.roles.denied'}='st';
14984: }
14985: if ($args->{'disablechat'}) {
14986: $cenv{'plc.roles.denied'}='st';
14987: }
14988:
14989: # Record we've not yet viewed the Course Initialization Helper for this
14990: # course
14991: $cenv{'course.helper.not.run'} = 1;
14992: #
14993: # Use new Randomseed
14994: #
14995: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14996: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14997: #
14998: # The encryption code and receipt prefix for this course
14999: #
15000: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15001: $cenv{'internal.encpref'}=100+int(9*rand(99));
15002: #
15003: # By default, use standard grading
15004: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15005:
1.541 raeburn 15006: $outcome .= $linefeed.&mt('Setting environment').': '.
15007: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15008: #
15009: # Open all assignments
15010: #
15011: if ($args->{'openall'}) {
15012: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15013: my %storecontent = ($storeunder => time,
15014: $storeunder.'.type' => 'date_start');
15015:
15016: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15017: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15018: }
15019: #
15020: # Set first page
15021: #
15022: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15023: || ($cloneid)) {
1.445 albertel 15024: use LONCAPA::map;
1.444 albertel 15025: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15026:
15027: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15028: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15029:
1.444 albertel 15030: $outcome .= ($fatal?$errtext:'read ok').' - ';
15031: my $title; my $url;
15032: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15033: $title=&mt('Syllabus');
1.444 albertel 15034: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15035: } else {
1.963 raeburn 15036: $title=&mt('Table of Contents');
1.444 albertel 15037: $url='/adm/navmaps';
15038: }
1.445 albertel 15039:
15040: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15041: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15042:
15043: if ($errtext) { $fatal=2; }
1.541 raeburn 15044: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15045: }
1.566 albertel 15046:
15047: return (1,$outcome);
1.444 albertel 15048: }
15049:
1.1166 raeburn 15050: sub make_unique_code {
15051: my ($cdom,$cnum) = @_;
15052: # get lock on uniquecodes db
15053: my $lockhash = {
15054: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15055: ':'.$env{'user.domain'},
15056: };
15057: my $tries = 0;
15058: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15059: my ($code,$error);
15060:
15061: while (($gotlock ne 'ok') && ($tries<3)) {
15062: $tries ++;
15063: sleep 1;
15064: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15065: }
15066: if ($gotlock eq 'ok') {
15067: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15068: my $gotcode;
15069: my $attempts = 0;
15070: while ((!$gotcode) && ($attempts < 100)) {
15071: $code = &generate_code();
15072: if (!exists($currcodes{$code})) {
15073: $gotcode = 1;
15074: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15075: $error = 'nostore';
15076: }
15077: }
15078: $attempts ++;
15079: }
15080: my @del_lock = ($cnum."\0".'uniquecodes');
15081: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15082: } else {
15083: $error = 'nolock';
15084: }
15085: return ($code,$error);
15086: }
15087:
15088: sub generate_code {
15089: my $code;
15090: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15091: for (my $i=0; $i<6; $i++) {
15092: my $lettnum = int (rand 2);
15093: my $item = '';
15094: if ($lettnum) {
15095: $item = $letts[int( rand(18) )];
15096: } else {
15097: $item = 1+int( rand(8) );
15098: }
15099: $code .= $item;
15100: }
15101: return $code;
15102: }
15103:
1.444 albertel 15104: ############################################################
15105: ############################################################
15106:
1.953 droeschl 15107: #SD
15108: # only Community and Course, or anything else?
1.378 raeburn 15109: sub course_type {
15110: my ($cid) = @_;
15111: if (!defined($cid)) {
15112: $cid = $env{'request.course.id'};
15113: }
1.404 albertel 15114: if (defined($env{'course.'.$cid.'.type'})) {
15115: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15116: } else {
15117: return 'Course';
1.377 raeburn 15118: }
15119: }
1.156 albertel 15120:
1.406 raeburn 15121: sub group_term {
15122: my $crstype = &course_type();
15123: my %names = (
15124: 'Course' => 'group',
1.865 raeburn 15125: 'Community' => 'group',
1.406 raeburn 15126: );
15127: return $names{$crstype};
15128: }
15129:
1.902 raeburn 15130: sub course_types {
1.1165 raeburn 15131: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15132: my %typename = (
15133: official => 'Official course',
15134: unofficial => 'Unofficial course',
15135: community => 'Community',
1.1165 raeburn 15136: textbook => 'Textbook course',
1.902 raeburn 15137: );
15138: return (\@types,\%typename);
15139: }
15140:
1.156 albertel 15141: sub icon {
15142: my ($file)=@_;
1.505 albertel 15143: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15144: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15145: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15146: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15147: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15148: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15149: $curfext.".gif") {
15150: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15151: $curfext.".gif";
15152: }
15153: }
1.249 albertel 15154: return &lonhttpdurl($iconname);
1.154 albertel 15155: }
1.84 albertel 15156:
1.575 albertel 15157: sub lonhttpdurl {
1.692 www 15158: #
15159: # Had been used for "small fry" static images on separate port 8080.
15160: # Modify here if lightweight http functionality desired again.
15161: # Currently eliminated due to increasing firewall issues.
15162: #
1.575 albertel 15163: my ($url)=@_;
1.692 www 15164: return $url;
1.215 albertel 15165: }
15166:
1.213 albertel 15167: sub connection_aborted {
15168: my ($r)=@_;
15169: $r->print(" ");$r->rflush();
15170: my $c = $r->connection;
15171: return $c->aborted();
15172: }
15173:
1.221 foxr 15174: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15175: # strings as 'strings'.
15176: sub escape_single {
1.221 foxr 15177: my ($input) = @_;
1.223 albertel 15178: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15179: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15180: return $input;
15181: }
1.223 albertel 15182:
1.222 foxr 15183: # Same as escape_single, but escape's "'s This
15184: # can be used for "strings"
15185: sub escape_double {
15186: my ($input) = @_;
15187: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15188: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15189: return $input;
15190: }
1.223 albertel 15191:
1.222 foxr 15192: # Escapes the last element of a full URL.
15193: sub escape_url {
15194: my ($url) = @_;
1.238 raeburn 15195: my @urlslices = split(/\//, $url,-1);
1.369 www 15196: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 15197: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15198: }
1.462 albertel 15199:
1.820 raeburn 15200: sub compare_arrays {
15201: my ($arrayref1,$arrayref2) = @_;
15202: my (@difference,%count);
15203: @difference = ();
15204: %count = ();
15205: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15206: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15207: foreach my $element (keys(%count)) {
15208: if ($count{$element} == 1) {
15209: push(@difference,$element);
15210: }
15211: }
15212: }
15213: return @difference;
15214: }
15215:
1.817 bisitz 15216: # -------------------------------------------------------- Initialize user login
1.462 albertel 15217: sub init_user_environment {
1.463 albertel 15218: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15219: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15220:
15221: my $public=($username eq 'public' && $domain eq 'public');
15222:
15223: # See if old ID present, if so, remove
15224:
1.1062 raeburn 15225: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15226: my $now=time;
15227:
15228: if ($public) {
15229: my $max_public=100;
15230: my $oldest;
15231: my $oldest_time=0;
15232: for(my $next=1;$next<=$max_public;$next++) {
15233: if (-e $lonids."/publicuser_$next.id") {
15234: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15235: if ($mtime<$oldest_time || !$oldest_time) {
15236: $oldest_time=$mtime;
15237: $oldest=$next;
15238: }
15239: } else {
15240: $cookie="publicuser_$next";
15241: last;
15242: }
15243: }
15244: if (!$cookie) { $cookie="publicuser_$oldest"; }
15245: } else {
1.463 albertel 15246: # if this isn't a robot, kill any existing non-robot sessions
15247: if (!$args->{'robot'}) {
15248: opendir(DIR,$lonids);
15249: while ($filename=readdir(DIR)) {
15250: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
15251: unlink($lonids.'/'.$filename);
15252: }
1.462 albertel 15253: }
1.463 albertel 15254: closedir(DIR);
1.1204 raeburn 15255: # If there is a undeleted lockfile for the user's paste buffer remove it.
15256: my $namespace = 'nohist_courseeditor';
15257: my $lockingkey = 'paste'."\0".'locked_num';
15258: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15259: $domain,$username);
15260: if (exists($lockhash{$lockingkey})) {
15261: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15262: unless ($delresult eq 'ok') {
15263: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15264: }
15265: }
1.462 albertel 15266: }
15267: # Give them a new cookie
1.463 albertel 15268: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15269: : $now.$$.int(rand(10000)));
1.463 albertel 15270: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15271:
15272: # Initialize roles
15273:
1.1062 raeburn 15274: ($userroles,$firstaccenv,$timerintenv) =
15275: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15276: }
15277: # ------------------------------------ Check browser type and MathML capability
15278:
1.1194 raeburn 15279: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15280: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15281:
15282: # ------------------------------------------------------------- Get environment
15283:
15284: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15285: my ($tmp) = keys(%userenv);
15286: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15287: } else {
15288: undef(%userenv);
15289: }
15290: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15291: $form->{'interface'}=$userenv{'interface'};
15292: }
15293: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15294:
15295: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15296: foreach my $option ('interface','localpath','localres') {
15297: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15298: }
15299: # --------------------------------------------------------- Write first profile
15300:
15301: {
15302: my %initial_env =
15303: ("user.name" => $username,
15304: "user.domain" => $domain,
15305: "user.home" => $authhost,
15306: "browser.type" => $clientbrowser,
15307: "browser.version" => $clientversion,
15308: "browser.mathml" => $clientmathml,
15309: "browser.unicode" => $clientunicode,
15310: "browser.os" => $clientos,
1.1137 raeburn 15311: "browser.mobile" => $clientmobile,
1.1141 raeburn 15312: "browser.info" => $clientinfo,
1.1194 raeburn 15313: "browser.osversion" => $clientosversion,
1.462 albertel 15314: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15315: "request.course.fn" => '',
15316: "request.course.uri" => '',
15317: "request.course.sec" => '',
15318: "request.role" => 'cm',
15319: "request.role.adv" => $env{'user.adv'},
15320: "request.host" => $ENV{'REMOTE_ADDR'},);
15321:
15322: if ($form->{'localpath'}) {
15323: $initial_env{"browser.localpath"} = $form->{'localpath'};
15324: $initial_env{"browser.localres"} = $form->{'localres'};
15325: }
15326:
15327: if ($form->{'interface'}) {
15328: $form->{'interface'}=~s/\W//gs;
15329: $initial_env{"browser.interface"} = $form->{'interface'};
15330: $env{'browser.interface'}=$form->{'interface'};
15331: }
15332:
1.1157 raeburn 15333: if ($form->{'iptoken'}) {
15334: my $lonhost = $r->dir_config('lonHostID');
15335: $initial_env{"user.noloadbalance"} = $lonhost;
15336: $env{'user.noloadbalance'} = $lonhost;
15337: }
15338:
1.981 raeburn 15339: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 15340: my %domdef;
15341: unless ($domain eq 'public') {
15342: %domdef = &Apache::lonnet::get_domain_defaults($domain);
15343: }
1.980 raeburn 15344:
1.1081 raeburn 15345: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 15346: $userenv{'availabletools.'.$tool} =
1.980 raeburn 15347: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15348: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 15349: }
15350:
1.1165 raeburn 15351: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 15352: $userenv{'canrequest.'.$crstype} =
15353: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 15354: 'reload','requestcourses',
15355: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 15356: }
15357:
1.1092 raeburn 15358: $userenv{'canrequest.author'} =
15359: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15360: 'reload','requestauthor',
15361: \%userenv,\%domdef,\%is_adv);
15362: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15363: $domain,$username);
15364: my $reqstatus = $reqauthor{'author_status'};
15365: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15366: if (ref($reqauthor{'author'}) eq 'HASH') {
15367: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15368: $reqauthor{'author'}{'timestamp'};
15369: }
15370: }
15371:
1.462 albertel 15372: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15373:
1.462 albertel 15374: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15375: &GDBM_WRCREAT(),0640)) {
15376: &_add_to_env(\%disk_env,\%initial_env);
15377: &_add_to_env(\%disk_env,\%userenv,'environment.');
15378: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15379: if (ref($firstaccenv) eq 'HASH') {
15380: &_add_to_env(\%disk_env,$firstaccenv);
15381: }
15382: if (ref($timerintenv) eq 'HASH') {
15383: &_add_to_env(\%disk_env,$timerintenv);
15384: }
1.463 albertel 15385: if (ref($args->{'extra_env'})) {
15386: &_add_to_env(\%disk_env,$args->{'extra_env'});
15387: }
1.462 albertel 15388: untie(%disk_env);
15389: } else {
1.705 tempelho 15390: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15391: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15392: return 'error: '.$!;
15393: }
15394: }
15395: $env{'request.role'}='cm';
15396: $env{'request.role.adv'}=$env{'user.adv'};
15397: $env{'browser.type'}=$clientbrowser;
15398:
15399: return $cookie;
15400:
15401: }
15402:
15403: sub _add_to_env {
15404: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15405: if (ref($env_data) eq 'HASH') {
15406: while (my ($key,$value) = each(%$env_data)) {
15407: $idf->{$prefix.$key} = $value;
15408: $env{$prefix.$key} = $value;
15409: }
1.462 albertel 15410: }
15411: }
15412:
1.685 tempelho 15413: # --- Get the symbolic name of a problem and the url
15414: sub get_symb {
15415: my ($request,$silent) = @_;
1.726 raeburn 15416: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15417: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15418: if ($symb eq '') {
15419: if (!$silent) {
1.1071 raeburn 15420: if (ref($request)) {
15421: $request->print("Unable to handle ambiguous references:$url:.");
15422: }
1.685 tempelho 15423: return ();
15424: }
15425: }
15426: &Apache::lonenc::check_decrypt(\$symb);
15427: return ($symb);
15428: }
15429:
15430: # --------------------------------------------------------------Get annotation
15431:
15432: sub get_annotation {
15433: my ($symb,$enc) = @_;
15434:
15435: my $key = $symb;
15436: if (!$enc) {
15437: $key =
15438: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15439: }
15440: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15441: return $annotation{$key};
15442: }
15443:
15444: sub clean_symb {
1.731 raeburn 15445: my ($symb,$delete_enc) = @_;
1.685 tempelho 15446:
15447: &Apache::lonenc::check_decrypt(\$symb);
15448: my $enc = $env{'request.enc'};
1.731 raeburn 15449: if ($delete_enc) {
1.730 raeburn 15450: delete($env{'request.enc'});
15451: }
1.685 tempelho 15452:
15453: return ($symb,$enc);
15454: }
1.462 albertel 15455:
1.1181 raeburn 15456: ############################################################
15457: ############################################################
15458:
15459: =pod
15460:
15461: =head1 Routines for building display used to search for courses
15462:
15463:
15464: =over 4
15465:
15466: =item * &build_filters()
15467:
15468: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 15469: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15470: and quotacheck.pl
15471:
1.1181 raeburn 15472:
15473: Inputs:
15474:
15475: filterlist - anonymous array of fields to include as potential filters
15476:
15477: crstype - course type
15478:
15479: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15480: to pop-open a course selector (will contain "extra element").
15481:
15482: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15483:
15484: filter - anonymous hash of criteria and their values
15485:
15486: action - form action
15487:
15488: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15489:
1.1182 raeburn 15490: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 15491:
15492: cloneruname - username of owner of new course who wants to clone
15493:
15494: clonerudom - domain of owner of new course who wants to clone
15495:
15496: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15497:
15498: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15499:
15500: codedom - domain
15501:
15502: formname - value of form element named "form".
15503:
15504: fixeddom - domain, if fixed.
15505:
15506: prevphase - value to assign to form element named "phase" when going back to the previous screen
15507:
15508: cnameelement - name of form element in form on opener page which will receive title of selected course
15509:
15510: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15511:
15512: cdomelement - name of form element in form on opener page which will receive domain of selected course
15513:
15514: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15515:
15516: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
15517:
15518: clonewarning - warning message about missing information for intended course owner when DC creates a course
15519:
1.1182 raeburn 15520:
1.1181 raeburn 15521: Returns: $output - HTML for display of search criteria, and hidden form elements.
15522:
1.1182 raeburn 15523:
1.1181 raeburn 15524: Side Effects: None
15525:
15526: =cut
15527:
15528: # ---------------------------------------------- search for courses based on last activity etc.
15529:
15530: sub build_filters {
15531: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
15532: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
15533: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
15534: $cnameelement,$cnumelement,$cdomelement,$setroles,
15535: $clonetext,$clonewarning) = @_;
1.1182 raeburn 15536: my ($list,$jscript);
1.1181 raeburn 15537: my $onchange = 'javascript:updateFilters(this)';
15538: my ($domainselectform,$sincefilterform,$createdfilterform,
15539: $ownerdomselectform,$persondomselectform,$instcodeform,
15540: $typeselectform,$instcodetitle);
15541: if ($formname eq '') {
15542: $formname = $caller;
15543: }
15544: foreach my $item (@{$filterlist}) {
15545: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
15546: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
15547: if ($item eq 'domainfilter') {
15548: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
15549: } elsif ($item eq 'coursefilter') {
15550: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
15551: } elsif ($item eq 'ownerfilter') {
15552: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15553: } elsif ($item eq 'ownerdomfilter') {
15554: $filter->{'ownerdomfilter'} =
15555: &LONCAPA::clean_domain($filter->{$item});
15556: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
15557: 'ownerdomfilter',1);
15558: } elsif ($item eq 'personfilter') {
15559: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15560: } elsif ($item eq 'persondomfilter') {
15561: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
15562: 'persondomfilter',1);
15563: } else {
15564: $filter->{$item} =~ s/\W//g;
15565: }
15566: if (!$filter->{$item}) {
15567: $filter->{$item} = '';
15568: }
15569: }
15570: if ($item eq 'domainfilter') {
15571: my $allow_blank = 1;
15572: if ($formname eq 'portform') {
15573: $allow_blank=0;
15574: } elsif ($formname eq 'studentform') {
15575: $allow_blank=0;
15576: }
15577: if ($fixeddom) {
15578: $domainselectform = '<input type="hidden" name="domainfilter"'.
15579: ' value="'.$codedom.'" />'.
15580: &Apache::lonnet::domain($codedom,'description');
15581: } else {
15582: $domainselectform = &select_dom_form($filter->{$item},
15583: 'domainfilter',
15584: $allow_blank,'',$onchange);
15585: }
15586: } else {
15587: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
15588: }
15589: }
15590:
15591: # last course activity filter and selection
15592: $sincefilterform = &timebased_select_form('sincefilter',$filter);
15593:
15594: # course created filter and selection
15595: if (exists($filter->{'createdfilter'})) {
15596: $createdfilterform = &timebased_select_form('createdfilter',$filter);
15597: }
15598:
15599: my %lt = &Apache::lonlocal::texthash(
15600: 'cac' => "$crstype Activity",
15601: 'ccr' => "$crstype Created",
15602: 'cde' => "$crstype Title",
15603: 'cdo' => "$crstype Domain",
15604: 'ins' => 'Institutional Code',
15605: 'inc' => 'Institutional Categorization',
15606: 'cow' => "$crstype Owner/Co-owner",
15607: 'cop' => "$crstype Personnel Includes",
15608: 'cog' => 'Type',
15609: );
15610:
15611: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15612: my $typeval = 'Course';
15613: if ($crstype eq 'Community') {
15614: $typeval = 'Community';
15615: }
15616: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
15617: } else {
15618: $typeselectform = '<select name="type" size="1"';
15619: if ($onchange) {
15620: $typeselectform .= ' onchange="'.$onchange.'"';
15621: }
15622: $typeselectform .= '>'."\n";
15623: foreach my $posstype ('Course','Community') {
15624: $typeselectform.='<option value="'.$posstype.'"'.
15625: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
15626: }
15627: $typeselectform.="</select>";
15628: }
15629:
15630: my ($cloneableonlyform,$cloneabletitle);
15631: if (exists($filter->{'cloneableonly'})) {
15632: my $cloneableon = '';
15633: my $cloneableoff = ' checked="checked"';
15634: if ($filter->{'cloneableonly'}) {
15635: $cloneableon = $cloneableoff;
15636: $cloneableoff = '';
15637: }
15638: $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>';
15639: if ($formname eq 'ccrs') {
1.1187 bisitz 15640: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 15641: } else {
15642: $cloneabletitle = &mt('Cloneable by you');
15643: }
15644: }
15645: my $officialjs;
15646: if ($crstype eq 'Course') {
15647: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 15648: # if (($fixeddom) || ($formname eq 'requestcrs') ||
15649: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
15650: if ($codedom) {
1.1181 raeburn 15651: $officialjs = 1;
15652: ($instcodeform,$jscript,$$numtitlesref) =
15653: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
15654: $officialjs,$codetitlesref);
15655: if ($jscript) {
1.1182 raeburn 15656: $jscript = '<script type="text/javascript">'."\n".
15657: '// <![CDATA['."\n".
15658: $jscript."\n".
15659: '// ]]>'."\n".
15660: '</script>'."\n";
1.1181 raeburn 15661: }
15662: }
15663: if ($instcodeform eq '') {
15664: $instcodeform =
15665: '<input type="text" name="instcodefilter" size="10" value="'.
15666: $list->{'instcodefilter'}.'" />';
15667: $instcodetitle = $lt{'ins'};
15668: } else {
15669: $instcodetitle = $lt{'inc'};
15670: }
15671: if ($fixeddom) {
15672: $instcodetitle .= '<br />('.$codedom.')';
15673: }
15674: }
15675: }
15676: my $output = qq|
15677: <form method="post" name="filterpicker" action="$action">
15678: <input type="hidden" name="form" value="$formname" />
15679: |;
15680: if ($formname eq 'modifycourse') {
15681: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
15682: '<input type="hidden" name="prevphase" value="'.
15683: $prevphase.'" />'."\n";
1.1198 musolffc 15684: } elsif ($formname eq 'quotacheck') {
15685: $output .= qq|
15686: <input type="hidden" name="sortby" value="" />
15687: <input type="hidden" name="sortorder" value="" />
15688: |;
15689: } else {
1.1181 raeburn 15690: my $name_input;
15691: if ($cnameelement ne '') {
15692: $name_input = '<input type="hidden" name="cnameelement" value="'.
15693: $cnameelement.'" />';
15694: }
15695: $output .= qq|
1.1182 raeburn 15696: <input type="hidden" name="cnumelement" value="$cnumelement" />
15697: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 15698: $name_input
15699: $roleelement
15700: $multelement
15701: $typeelement
15702: |;
15703: if ($formname eq 'portform') {
15704: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
15705: }
15706: }
15707: if ($fixeddom) {
15708: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
15709: }
15710: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
15711: if ($sincefilterform) {
15712: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
15713: .$sincefilterform
15714: .&Apache::lonhtmlcommon::row_closure();
15715: }
15716: if ($createdfilterform) {
15717: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
15718: .$createdfilterform
15719: .&Apache::lonhtmlcommon::row_closure();
15720: }
15721: if ($domainselectform) {
15722: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
15723: .$domainselectform
15724: .&Apache::lonhtmlcommon::row_closure();
15725: }
15726: if ($typeselectform) {
15727: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15728: $output .= $typeselectform;
15729: } else {
15730: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
15731: .$typeselectform
15732: .&Apache::lonhtmlcommon::row_closure();
15733: }
15734: }
15735: if ($instcodeform) {
15736: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
15737: .$instcodeform
15738: .&Apache::lonhtmlcommon::row_closure();
15739: }
15740: if (exists($filter->{'ownerfilter'})) {
15741: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
15742: '<table><tr><td>'.&mt('Username').'<br />'.
15743: '<input type="text" name="ownerfilter" size="20" value="'.
15744: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15745: $ownerdomselectform.'</td></tr></table>'.
15746: &Apache::lonhtmlcommon::row_closure();
15747: }
15748: if (exists($filter->{'personfilter'})) {
15749: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
15750: '<table><tr><td>'.&mt('Username').'<br />'.
15751: '<input type="text" name="personfilter" size="20" value="'.
15752: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15753: $persondomselectform.'</td></tr></table>'.
15754: &Apache::lonhtmlcommon::row_closure();
15755: }
15756: if (exists($filter->{'coursefilter'})) {
15757: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15758: .'<input type="text" name="coursefilter" size="25" value="'
15759: .$list->{'coursefilter'}.'" />'
15760: .&Apache::lonhtmlcommon::row_closure();
15761: }
15762: if ($cloneableonlyform) {
15763: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15764: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15765: }
15766: if (exists($filter->{'descriptfilter'})) {
15767: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15768: .'<input type="text" name="descriptfilter" size="40" value="'
15769: .$list->{'descriptfilter'}.'" />'
15770: .&Apache::lonhtmlcommon::row_closure(1);
15771: }
15772: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15773: '<input type="hidden" name="updater" value="" />'."\n".
15774: '<input type="submit" name="gosearch" value="'.
15775: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15776: return $jscript.$clonewarning.$output;
15777: }
15778:
15779: =pod
15780:
15781: =item * &timebased_select_form()
15782:
1.1182 raeburn 15783: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 15784: filter e.g., Course Activity, Course Created, when searching for courses
15785: or communities
15786:
15787: Inputs:
15788:
15789: item - name of form element (sincefilter or createdfilter)
15790:
15791: filter - anonymous hash of criteria and their values
15792:
15793: Returns: HTML for a select box contained a blank, then six time selections,
15794: with value set in incoming form variables currently selected.
15795:
15796: Side Effects: None
15797:
15798: =cut
15799:
15800: sub timebased_select_form {
15801: my ($item,$filter) = @_;
15802: if (ref($filter) eq 'HASH') {
15803: $filter->{$item} =~ s/[^\d-]//g;
15804: if (!$filter->{$item}) { $filter->{$item}=-1; }
15805: return &select_form(
15806: $filter->{$item},
15807: $item,
15808: { '-1' => '',
15809: '86400' => &mt('today'),
15810: '604800' => &mt('last week'),
15811: '2592000' => &mt('last month'),
15812: '7776000' => &mt('last three months'),
15813: '15552000' => &mt('last six months'),
15814: '31104000' => &mt('last year'),
15815: 'select_form_order' =>
15816: ['-1','86400','604800','2592000','7776000',
15817: '15552000','31104000']});
15818: }
15819: }
15820:
15821: =pod
15822:
15823: =item * &js_changer()
15824:
15825: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 15826: when course type or domain is changed, and also to hide 'Searching ...' on
15827: page load completion for page showing search result.
1.1181 raeburn 15828:
15829: Inputs: None
15830:
1.1183 raeburn 15831: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 15832:
15833: Side Effects: None
15834:
15835: =cut
15836:
15837: sub js_changer {
15838: return <<ENDJS;
15839: <script type="text/javascript">
15840: // <![CDATA[
15841: function updateFilters(caller) {
15842: if (typeof(caller) != "undefined") {
15843: document.filterpicker.updater.value = caller.name;
15844: }
15845: document.filterpicker.submit();
15846: }
1.1183 raeburn 15847:
15848: function hideSearching() {
15849: if (document.getElementById('searching')) {
15850: document.getElementById('searching').style.display = 'none';
15851: }
15852: return;
15853: }
15854:
1.1181 raeburn 15855: // ]]>
15856: </script>
15857:
15858: ENDJS
15859: }
15860:
15861: =pod
15862:
1.1182 raeburn 15863: =item * &search_courses()
15864:
15865: Process selected filters form course search form and pass to lonnet::courseiddump
15866: to retrieve a hash for which keys are courseIDs which match the selected filters.
15867:
15868: Inputs:
15869:
15870: dom - domain being searched
15871:
15872: type - course type ('Course' or 'Community' or '.' if any).
15873:
15874: filter - anonymous hash of criteria and their values
15875:
15876: numtitles - for institutional codes - number of categories
15877:
15878: cloneruname - optional username of new course owner
15879:
15880: clonerudom - optional domain of new course owner
15881:
1.1221 raeburn 15882: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 15883: (used when DC is using course creation form)
15884:
15885: codetitles - reference to array of titles of components in institutional codes (official courses).
15886:
1.1221 raeburn 15887: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
15888: (and so can clone automatically)
15889:
15890: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
15891:
15892: reqinstcode - institutional code of new course, where search_courses is used to identify potential
15893: courses to clone
1.1182 raeburn 15894:
15895: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
15896:
15897:
15898: Side Effects: None
15899:
15900: =cut
15901:
15902:
15903: sub search_courses {
1.1221 raeburn 15904: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
15905: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 15906: my (%courses,%showcourses,$cloner);
15907: if (($filter->{'ownerfilter'} ne '') ||
15908: ($filter->{'ownerdomfilter'} ne '')) {
15909: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
15910: $filter->{'ownerdomfilter'};
15911: }
15912: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
15913: if (!$filter->{$item}) {
15914: $filter->{$item}='.';
15915: }
15916: }
15917: my $now = time;
15918: my $timefilter =
15919: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
15920: my ($createdbefore,$createdafter);
15921: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
15922: $createdbefore = $now;
15923: $createdafter = $now-$filter->{'createdfilter'};
15924: }
15925: my ($instcodefilter,$regexpok);
15926: if ($numtitles) {
15927: if ($env{'form.official'} eq 'on') {
15928: $instcodefilter =
15929: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15930: $regexpok = 1;
15931: } elsif ($env{'form.official'} eq 'off') {
15932: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15933: unless ($instcodefilter eq '') {
15934: $regexpok = -1;
15935: }
15936: }
15937: } else {
15938: $instcodefilter = $filter->{'instcodefilter'};
15939: }
15940: if ($instcodefilter eq '') { $instcodefilter = '.'; }
15941: if ($type eq '') { $type = '.'; }
15942:
15943: if (($clonerudom ne '') && ($cloneruname ne '')) {
15944: $cloner = $cloneruname.':'.$clonerudom;
15945: }
15946: %courses = &Apache::lonnet::courseiddump($dom,
15947: $filter->{'descriptfilter'},
15948: $timefilter,
15949: $instcodefilter,
15950: $filter->{'combownerfilter'},
15951: $filter->{'coursefilter'},
15952: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 15953: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 15954: $filter->{'cloneableonly'},
15955: $createdbefore,$createdafter,undef,
1.1221 raeburn 15956: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 15957: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
15958: my $ccrole;
15959: if ($type eq 'Community') {
15960: $ccrole = 'co';
15961: } else {
15962: $ccrole = 'cc';
15963: }
15964: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
15965: $filter->{'persondomfilter'},
15966: 'userroles',undef,
15967: [$ccrole,'in','ad','ep','ta','cr'],
15968: $dom);
15969: foreach my $role (keys(%rolehash)) {
15970: my ($cnum,$cdom,$courserole) = split(':',$role);
15971: my $cid = $cdom.'_'.$cnum;
15972: if (exists($courses{$cid})) {
15973: if (ref($courses{$cid}) eq 'HASH') {
15974: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
15975: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
15976: push (@{$courses{$cid}{roles}},$courserole);
15977: }
15978: } else {
15979: $courses{$cid}{roles} = [$courserole];
15980: }
15981: $showcourses{$cid} = $courses{$cid};
15982: }
15983: }
15984: }
15985: %courses = %showcourses;
15986: }
15987: return %courses;
15988: }
15989:
15990: =pod
15991:
1.1181 raeburn 15992: =back
15993:
1.1207 raeburn 15994: =head1 Routines for version requirements for current course.
15995:
15996: =over 4
15997:
15998: =item * &check_release_required()
15999:
16000: Compares required LON-CAPA version with version on server, and
16001: if required version is newer looks for a server with the required version.
16002:
16003: Looks first at servers in user's owen domain; if none suitable, looks at
16004: servers in course's domain are permitted to host sessions for user's domain.
16005:
16006: Inputs:
16007:
16008: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16009:
16010: $courseid - Course ID of current course
16011:
16012: $rolecode - User's current role in course (for switchserver query string).
16013:
16014: $required - LON-CAPA version needed by course (format: Major.Minor).
16015:
16016:
16017: Returns:
16018:
16019: $switchserver - query string tp append to /adm/switchserver call (if
16020: current server's LON-CAPA version is too old.
16021:
16022: $warning - Message is displayed if no suitable server could be found.
16023:
16024: =cut
16025:
16026: sub check_release_required {
16027: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16028: my ($switchserver,$warning);
16029: if ($required ne '') {
16030: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16031: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16032: if ($reqdmajor ne '' && $reqdminor ne '') {
16033: my $otherserver;
16034: if (($major eq '' && $minor eq '') ||
16035: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16036: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16037: my $switchlcrev =
16038: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16039: $userdomserver);
16040: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16041: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16042: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16043: my $cdom = $env{'course.'.$courseid.'.domain'};
16044: if ($cdom ne $env{'user.domain'}) {
16045: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16046: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16047: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16048: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16049: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16050: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16051: my $canhost =
16052: &Apache::lonnet::can_host_session($env{'user.domain'},
16053: $coursedomserver,
16054: $remoterev,
16055: $udomdefaults{'remotesessions'},
16056: $defdomdefaults{'hostedsessions'});
16057:
16058: if ($canhost) {
16059: $otherserver = $coursedomserver;
16060: } else {
16061: $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.");
16062: }
16063: } else {
16064: $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).");
16065: }
16066: } else {
16067: $otherserver = $userdomserver;
16068: }
16069: }
16070: if ($otherserver ne '') {
16071: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16072: }
16073: }
16074: }
16075: return ($switchserver,$warning);
16076: }
16077:
16078: =pod
16079:
16080: =item * &check_release_result()
16081:
16082: Inputs:
16083:
16084: $switchwarning - Warning message if no suitable server found to host session.
16085:
16086: $switchserver - query string to append to /adm/switchserver containing lonHostID
16087: and current role.
16088:
16089: Returns: HTML to display with information about requirement to switch server.
16090: Either displaying warning with link to Roles/Courses screen or
16091: display link to switchserver.
16092:
1.1181 raeburn 16093: =cut
16094:
1.1207 raeburn 16095: sub check_release_result {
16096: my ($switchwarning,$switchserver) = @_;
16097: my $output = &start_page('Selected course unavailable on this server').
16098: '<p class="LC_warning">';
16099: if ($switchwarning) {
16100: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16101: if (&show_course()) {
16102: $output .= &mt('Display courses');
16103: } else {
16104: $output .= &mt('Display roles');
16105: }
16106: $output .= '</a>';
16107: } elsif ($switchserver) {
16108: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16109: '<br />'.
16110: '<a href="/adm/switchserver?'.$switchserver.'">'.
16111: &mt('Switch Server').
16112: '</a>';
16113: }
16114: $output .= '</p>'.&end_page();
16115: return $output;
16116: }
16117:
16118: =pod
16119:
16120: =item * &needs_coursereinit()
16121:
16122: Determine if course contents stored for user's session needs to be
16123: refreshed, because content has changed since "Big Hash" last tied.
16124:
16125: Check for change is made if time last checked is more than 10 minutes ago
16126: (by default).
16127:
16128: Inputs:
16129:
16130: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16131:
16132: $interval (optional) - Time which may elapse (in s) between last check for content
16133: change in current course. (default: 600 s).
16134:
16135: Returns: an array; first element is:
16136:
16137: =over 4
16138:
16139: 'switch' - if content updates mean user's session
16140: needs to be switched to a server running a newer LON-CAPA version
16141:
16142: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16143: on current server hosting user's session
16144:
16145: '' - if no action required.
16146:
16147: =back
16148:
16149: If first item element is 'switch':
16150:
16151: second item is $switchwarning - Warning message if no suitable server found to host session.
16152:
16153: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16154: and current role.
16155:
16156: otherwise: no other elements returned.
16157:
16158: =back
16159:
16160: =cut
16161:
16162: sub needs_coursereinit {
16163: my ($loncaparev,$interval) = @_;
16164: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16165: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16166: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16167: my $now = time;
16168: if ($interval eq '') {
16169: $interval = 600;
16170: }
16171: if (($now-$env{'request.course.timechecked'})>$interval) {
16172: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16173: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16174: if ($lastchange > $env{'request.course.tied'}) {
16175: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16176: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16177: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16178: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16179: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16180: $curr_reqd_hash{'internal.releaserequired'}});
16181: my ($switchserver,$switchwarning) =
16182: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16183: $curr_reqd_hash{'internal.releaserequired'});
16184: if ($switchwarning ne '' || $switchserver ne '') {
16185: return ('switch',$switchwarning,$switchserver);
16186: }
16187: }
16188: }
16189: return ('update');
16190: }
16191: }
16192: return ();
16193: }
1.1181 raeburn 16194:
1.1083 raeburn 16195: sub update_content_constraints {
16196: my ($cdom,$cnum,$chome,$cid) = @_;
16197: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16198: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16199: my %checkresponsetypes;
16200: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1219 raeburn 16201: my ($item,$name,$value,$valmatch) = split(/:/,$key);
1.1083 raeburn 16202: if ($item eq 'resourcetag') {
16203: if ($name eq 'responsetype') {
16204: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16205: }
16206: }
16207: }
16208: my $navmap = Apache::lonnavmaps::navmap->new();
16209: if (defined($navmap)) {
16210: my %allresponses;
16211: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16212: my %responses = $res->responseTypes();
16213: foreach my $key (keys(%responses)) {
16214: next unless(exists($checkresponsetypes{$key}));
16215: $allresponses{$key} += $responses{$key};
16216: }
16217: }
16218: foreach my $key (keys(%allresponses)) {
16219: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16220: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16221: ($reqdmajor,$reqdminor) = ($major,$minor);
16222: }
16223: }
16224: undef($navmap);
16225: }
16226: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16227: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16228: }
16229: return;
16230: }
16231:
1.1110 raeburn 16232: sub allmaps_incourse {
16233: my ($cdom,$cnum,$chome,$cid) = @_;
16234: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16235: $cid = $env{'request.course.id'};
16236: $cdom = $env{'course.'.$cid.'.domain'};
16237: $cnum = $env{'course.'.$cid.'.num'};
16238: $chome = $env{'course.'.$cid.'.home'};
16239: }
16240: my %allmaps = ();
16241: my $lastchange =
16242: &Apache::lonnet::get_coursechange($cdom,$cnum);
16243: if ($lastchange > $env{'request.course.tied'}) {
16244: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16245: unless ($ferr) {
16246: &update_content_constraints($cdom,$cnum,$chome,$cid);
16247: }
16248: }
16249: my $navmap = Apache::lonnavmaps::navmap->new();
16250: if (defined($navmap)) {
16251: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16252: $allmaps{$res->src()} = 1;
16253: }
16254: }
16255: return \%allmaps;
16256: }
16257:
1.1083 raeburn 16258: sub parse_supplemental_title {
16259: my ($title) = @_;
16260:
16261: my ($foldertitle,$renametitle);
16262: if ($title =~ /&&&/) {
16263: $title = &HTML::Entites::decode($title);
16264: }
16265: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16266: $renametitle=$4;
16267: my ($time,$uname,$udom) = ($1,$2,$3);
16268: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16269: my $name = &plainname($uname,$udom);
16270: $name = &HTML::Entities::encode($name,'"<>&\'');
16271: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16272: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16273: $name.': <br />'.$foldertitle;
16274: }
16275: if (wantarray) {
16276: return ($title,$foldertitle,$renametitle);
16277: }
16278: return $title;
16279: }
16280:
1.1143 raeburn 16281: sub recurse_supplemental {
16282: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16283: if ($suppmap) {
16284: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16285: if ($fatal) {
16286: $errors ++;
16287: } else {
16288: if ($#LONCAPA::map::resources > 0) {
16289: foreach my $res (@LONCAPA::map::resources) {
16290: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16291: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 16292: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16293: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 16294: } else {
16295: $numfiles ++;
16296: }
16297: }
16298: }
16299: }
16300: }
16301: }
16302: return ($numfiles,$errors);
16303: }
16304:
1.1101 raeburn 16305: sub symb_to_docspath {
16306: my ($symb) = @_;
16307: return unless ($symb);
16308: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16309: if ($resurl=~/\.(sequence|page)$/) {
16310: $mapurl=$resurl;
16311: } elsif ($resurl eq 'adm/navmaps') {
16312: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16313: }
16314: my $mapresobj;
16315: my $navmap = Apache::lonnavmaps::navmap->new();
16316: if (ref($navmap)) {
16317: $mapresobj = $navmap->getResourceByUrl($mapurl);
16318: }
16319: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16320: my $type=$2;
16321: my $path;
16322: if (ref($mapresobj)) {
16323: my $pcslist = $mapresobj->map_hierarchy();
16324: if ($pcslist ne '') {
16325: foreach my $pc (split(/,/,$pcslist)) {
16326: next if ($pc <= 1);
16327: my $res = $navmap->getByMapPc($pc);
16328: if (ref($res)) {
16329: my $thisurl = $res->src();
16330: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16331: my $thistitle = $res->title();
16332: $path .= '&'.
16333: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 16334: &escape($thistitle).
1.1101 raeburn 16335: ':'.$res->randompick().
16336: ':'.$res->randomout().
16337: ':'.$res->encrypted().
16338: ':'.$res->randomorder().
16339: ':'.$res->is_page();
16340: }
16341: }
16342: }
16343: $path =~ s/^\&//;
16344: my $maptitle = $mapresobj->title();
16345: if ($mapurl eq 'default') {
1.1129 raeburn 16346: $maptitle = 'Main Content';
1.1101 raeburn 16347: }
16348: $path .= (($path ne '')? '&' : '').
16349: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 16350: &escape($maptitle).
1.1101 raeburn 16351: ':'.$mapresobj->randompick().
16352: ':'.$mapresobj->randomout().
16353: ':'.$mapresobj->encrypted().
16354: ':'.$mapresobj->randomorder().
16355: ':'.$mapresobj->is_page();
16356: } else {
16357: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16358: my $ispage = (($type eq 'page')? 1 : '');
16359: if ($mapurl eq 'default') {
1.1129 raeburn 16360: $maptitle = 'Main Content';
1.1101 raeburn 16361: }
16362: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 16363: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 16364: }
16365: unless ($mapurl eq 'default') {
16366: $path = 'default&'.
1.1146 raeburn 16367: &escape('Main Content').
1.1101 raeburn 16368: ':::::&'.$path;
16369: }
16370: return $path;
16371: }
16372:
1.1094 raeburn 16373: sub captcha_display {
16374: my ($context,$lonhost) = @_;
16375: my ($output,$error);
16376: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 16377: if ($captcha eq 'original') {
1.1094 raeburn 16378: $output = &create_captcha();
16379: unless ($output) {
1.1172 raeburn 16380: $error = 'captcha';
1.1094 raeburn 16381: }
16382: } elsif ($captcha eq 'recaptcha') {
16383: $output = &create_recaptcha($pubkey);
16384: unless ($output) {
1.1172 raeburn 16385: $error = 'recaptcha';
1.1094 raeburn 16386: }
16387: }
1.1176 raeburn 16388: return ($output,$error,$captcha);
1.1094 raeburn 16389: }
16390:
16391: sub captcha_response {
16392: my ($context,$lonhost) = @_;
16393: my ($captcha_chk,$captcha_error);
16394: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 16395: if ($captcha eq 'original') {
1.1094 raeburn 16396: ($captcha_chk,$captcha_error) = &check_captcha();
16397: } elsif ($captcha eq 'recaptcha') {
16398: $captcha_chk = &check_recaptcha($privkey);
16399: } else {
16400: $captcha_chk = 1;
16401: }
16402: return ($captcha_chk,$captcha_error);
16403: }
16404:
16405: sub get_captcha_config {
16406: my ($context,$lonhost) = @_;
1.1095 raeburn 16407: my ($captcha,$pubkey,$privkey,$hashtocheck);
1.1094 raeburn 16408: my $hostname = &Apache::lonnet::hostname($lonhost);
16409: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16410: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 16411: if ($context eq 'usercreation') {
16412: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16413: if (ref($domconfig{$context}) eq 'HASH') {
16414: $hashtocheck = $domconfig{$context}{'cancreate'};
16415: if (ref($hashtocheck) eq 'HASH') {
16416: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16417: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16418: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16419: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16420: }
16421: if ($privkey && $pubkey) {
16422: $captcha = 'recaptcha';
16423: } else {
16424: $captcha = 'original';
16425: }
16426: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16427: $captcha = 'original';
16428: }
1.1094 raeburn 16429: }
1.1095 raeburn 16430: } else {
16431: $captcha = 'captcha';
16432: }
16433: } elsif ($context eq 'login') {
16434: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16435: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16436: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16437: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 16438: if ($privkey && $pubkey) {
16439: $captcha = 'recaptcha';
1.1095 raeburn 16440: } else {
16441: $captcha = 'original';
1.1094 raeburn 16442: }
1.1095 raeburn 16443: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16444: $captcha = 'original';
1.1094 raeburn 16445: }
16446: }
16447: return ($captcha,$pubkey,$privkey);
16448: }
16449:
16450: sub create_captcha {
16451: my %captcha_params = &captcha_settings();
16452: my ($output,$maxtries,$tries) = ('',10,0);
16453: while ($tries < $maxtries) {
16454: $tries ++;
16455: my $captcha = Authen::Captcha->new (
16456: output_folder => $captcha_params{'output_dir'},
16457: data_folder => $captcha_params{'db_dir'},
16458: );
16459: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
16460:
16461: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
16462: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
16463: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 16464: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
16465: '<br />'.
16466: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 16467: last;
16468: }
16469: }
16470: return $output;
16471: }
16472:
16473: sub captcha_settings {
16474: my %captcha_params = (
16475: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
16476: www_output_dir => "/captchaspool",
16477: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16478: numchars => '5',
16479: );
16480: return %captcha_params;
16481: }
16482:
16483: sub check_captcha {
16484: my ($captcha_chk,$captcha_error);
16485: my $code = $env{'form.code'};
16486: my $md5sum = $env{'form.crypt'};
16487: my %captcha_params = &captcha_settings();
16488: my $captcha = Authen::Captcha->new(
16489: output_folder => $captcha_params{'output_dir'},
16490: data_folder => $captcha_params{'db_dir'},
16491: );
1.1109 raeburn 16492: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 16493: my %captcha_hash = (
16494: 0 => 'Code not checked (file error)',
16495: -1 => 'Failed: code expired',
16496: -2 => 'Failed: invalid code (not in database)',
16497: -3 => 'Failed: invalid code (code does not match crypt)',
16498: );
16499: if ($captcha_chk != 1) {
16500: $captcha_error = $captcha_hash{$captcha_chk}
16501: }
16502: return ($captcha_chk,$captcha_error);
16503: }
16504:
16505: sub create_recaptcha {
16506: my ($pubkey) = @_;
1.1153 raeburn 16507: my $use_ssl;
16508: if ($ENV{'SERVER_PORT'} == 443) {
16509: $use_ssl = 1;
16510: }
1.1094 raeburn 16511: my $captcha = Captcha::reCAPTCHA->new;
16512: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1153 raeburn 16513: $captcha->get_html($pubkey,undef,$use_ssl).
1.1213 raeburn 16514: &mt('If the text is hard to read, [_1] will replace them.',
1.1133 raeburn 16515: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1094 raeburn 16516: '<br /><br />';
16517: }
16518:
16519: sub check_recaptcha {
16520: my ($privkey) = @_;
16521: my $captcha_chk;
16522: my $captcha = Captcha::reCAPTCHA->new;
16523: my $captcha_result =
16524: $captcha->check_answer(
16525: $privkey,
16526: $ENV{'REMOTE_ADDR'},
16527: $env{'form.recaptcha_challenge_field'},
16528: $env{'form.recaptcha_response_field'},
16529: );
16530: if ($captcha_result->{is_valid}) {
16531: $captcha_chk = 1;
16532: }
16533: return $captcha_chk;
16534: }
16535:
1.1174 raeburn 16536: sub emailusername_info {
1.1177 raeburn 16537: my @fields = ('firstname','lastname','institution','web','location','officialemail');
1.1174 raeburn 16538: my %titles = &Apache::lonlocal::texthash (
16539: lastname => 'Last Name',
16540: firstname => 'First Name',
16541: institution => 'School/college/university',
16542: location => "School's city, state/province, country",
16543: web => "School's web address",
16544: officialemail => 'E-mail address at institution (if different)',
16545: );
16546: return (\@fields,\%titles);
16547: }
16548:
1.1161 raeburn 16549: sub cleanup_html {
16550: my ($incoming) = @_;
16551: my $outgoing;
16552: if ($incoming ne '') {
16553: $outgoing = $incoming;
16554: $outgoing =~ s/;/;/g;
16555: $outgoing =~ s/\#/#/g;
16556: $outgoing =~ s/\&/&/g;
16557: $outgoing =~ s/</</g;
16558: $outgoing =~ s/>/>/g;
16559: $outgoing =~ s/\(/(/g;
16560: $outgoing =~ s/\)/)/g;
16561: $outgoing =~ s/"/"/g;
16562: $outgoing =~ s/'/'/g;
16563: $outgoing =~ s/\$/$/g;
16564: $outgoing =~ s{/}{/}g;
16565: $outgoing =~ s/=/=/g;
16566: $outgoing =~ s/\\/\/g
16567: }
16568: return $outgoing;
16569: }
16570:
1.1190 musolffc 16571: # Checks for critical messages and returns a redirect url if one exists.
16572: # $interval indicates how often to check for messages.
16573: sub critical_redirect {
16574: my ($interval) = @_;
16575: if ((time-$env{'user.criticalcheck.time'})>$interval) {
16576: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
16577: $env{'user.name'});
16578: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 16579: my $redirecturl;
1.1190 musolffc 16580: if ($what[0]) {
16581: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
16582: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 16583: my $url=&Apache::lonnet::absolute_url().$redirecturl;
16584: return (1, $url);
1.1190 musolffc 16585: }
1.1191 raeburn 16586: }
16587: }
16588: return ();
1.1190 musolffc 16589: }
16590:
1.1174 raeburn 16591: # Use:
16592: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
16593: #
16594: ##################################################
16595: # password associated functions #
16596: ##################################################
16597: sub des_keys {
16598: # Make a new key for DES encryption.
16599: # Each key has two parts which are returned separately.
16600: # Please note: Each key must be passed through the &hex function
16601: # before it is output to the web browser. The hex versions cannot
16602: # be used to decrypt.
16603: my @hexstr=('0','1','2','3','4','5','6','7',
16604: '8','9','a','b','c','d','e','f');
16605: my $lkey='';
16606: for (0..7) {
16607: $lkey.=$hexstr[rand(15)];
16608: }
16609: my $ukey='';
16610: for (0..7) {
16611: $ukey.=$hexstr[rand(15)];
16612: }
16613: return ($lkey,$ukey);
16614: }
16615:
16616: sub des_decrypt {
16617: my ($key,$cyphertext) = @_;
16618: my $keybin=pack("H16",$key);
16619: my $cypher;
16620: if ($Crypt::DES::VERSION>=2.03) {
16621: $cypher=new Crypt::DES $keybin;
16622: } else {
16623: $cypher=new DES $keybin;
16624: }
16625: my $plaintext=
16626: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
16627: $plaintext.=
16628: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
16629: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
16630: return $plaintext;
16631: }
16632:
1.112 bowersj2 16633: 1;
16634: __END__;
1.41 ng 16635:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>